[Yellowstone] Use yunq native empty requests and responses for service.

This commit is contained in:
Drew Galbraith 2023-11-27 08:06:04 -08:00
parent cc4b5bd811
commit b95c736825
13 changed files with 140 additions and 113 deletions

View File

@ -11,9 +11,8 @@ uint64_t main(uint64_t init_port_cap) {
check(ParseInitPort(init_port_cap));
YellowstoneClient stub(gInitEndpointCap);
Empty empty;
AhciInfo ahci;
RET_ERR(stub.GetAhciInfo(empty, ahci));
RET_ERR(stub.GetAhciInfo(ahci));
mmth::OwnedMemoryRegion ahci_region =
mmth::OwnedMemoryRegion::FromCapability(ahci.ahci_region());
ASSIGN_OR_RETURN(auto driver, AhciDriver::Init(glcr::Move(ahci_region)));
@ -28,7 +27,7 @@ uint64_t main(uint64_t init_port_cap) {
RegisterEndpointRequest req;
req.set_endpoint_name("denali");
req.set_endpoint_capability(client.Capability());
check(stub.RegisterEndpoint(req, empty));
check(stub.RegisterEndpoint(req));
check(server_thread.Join());
return 0;

View File

@ -18,7 +18,7 @@ uint64_t main(uint64_t init_port) {
YellowstoneClient client(gInitEndpointCap);
FramebufferInfo framebuffer;
RET_ERR(client.GetFramebufferInfo({}, framebuffer));
RET_ERR(client.GetFramebufferInfo(framebuffer));
dbgln("FB addr {x}, bpp {}, width {} , height {}, pitch {}",
framebuffer.address_phys(), framebuffer.bpp(), framebuffer.width(),
framebuffer.height(), framebuffer.pitch());

View File

@ -11,9 +11,8 @@ uint64_t main(uint64_t init_cap) {
dbgln("VFs Started");
YellowstoneClient yellowstone(gInitEndpointCap);
Empty empty;
DenaliInfo denali_info;
RET_ERR(yellowstone.GetDenali(empty, denali_info));
RET_ERR(yellowstone.GetDenali(denali_info));
ASSIGN_OR_RETURN(Ext2Driver ext2, Ext2Driver::Init(denali_info));
ASSIGN_OR_RETURN(auto server, VFSServer::Create(ext2));
@ -24,7 +23,7 @@ uint64_t main(uint64_t init_cap) {
req.set_endpoint_name("victoriafalls");
ASSIGN_OR_RETURN(auto client, server->CreateClient());
req.set_endpoint_capability(client.Capability());
check(yellowstone.RegisterEndpoint(req, empty));
check(yellowstone.RegisterEndpoint(req));
RET_ERR(server_thread.Join());

View File

@ -27,8 +27,7 @@ uint64_t main(uint64_t init_port) {
req.set_endpoint_name("voyageurs");
ASSIGN_OR_RETURN(VoyageursClient client, server->CreateClient());
req.set_endpoint_capability(client.Capability());
Empty empty;
check(yellowstone.RegisterEndpoint(req, empty));
check(yellowstone.RegisterEndpoint(req));
check(server_thread.Join());
check(keyboard_thread.Join());

View File

@ -1,9 +1,9 @@
interface Yellowstone {
method RegisterEndpoint(RegisterEndpointRequest) -> (Empty);
method RegisterEndpoint(RegisterEndpointRequest) -> ();
method GetEndpoint(GetEndpointRequest) -> (Endpoint);
method GetAhciInfo(Empty) -> (AhciInfo);
method GetFramebufferInfo(Empty) -> (FramebufferInfo);
method GetDenali(Empty) -> (DenaliInfo);
method GetAhciInfo() -> (AhciInfo);
method GetFramebufferInfo() -> (FramebufferInfo);
method GetDenali() -> (DenaliInfo);
}
message RegisterEndpointRequest {
@ -11,10 +11,6 @@ message RegisterEndpointRequest {
capability endpoint_capability;
}
message Empty {
}
message GetEndpointRequest {
string endpoint_name;
}

View File

@ -8,7 +8,9 @@
glcr::ErrorCode YellowstoneClient::RegisterEndpoint(const RegisterEndpointRequest& request, Empty& response) {
glcr::ErrorCode YellowstoneClient::RegisterEndpoint(const RegisterEndpointRequest& request) {
uint64_t buffer_size = kBufferSize;
uint64_t cap_size = kCapBufferSize;
@ -17,7 +19,10 @@ glcr::ErrorCode YellowstoneClient::RegisterEndpoint(const RegisterEndpointReques
buffer_.WriteAt<uint64_t>(8, 0);
cap_buffer_.Reset();
uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_);
buffer_.WriteAt<uint32_t>(4, 16 + length);
z_cap_t reply_port_cap;
@ -33,14 +38,16 @@ glcr::ErrorCode YellowstoneClient::RegisterEndpoint(const RegisterEndpointReques
// Check Response Code.
RET_ERR(buffer_.At<uint64_t>(8));
response.ParseFromBytes(buffer_, 16, cap_buffer_);
return glcr::OK;
}
glcr::ErrorCode YellowstoneClient::GetEndpoint(const GetEndpointRequest& request, Endpoint& response) {
uint64_t buffer_size = kBufferSize;
uint64_t cap_size = kCapBufferSize;
@ -49,7 +56,10 @@ glcr::ErrorCode YellowstoneClient::GetEndpoint(const GetEndpointRequest& request
buffer_.WriteAt<uint64_t>(8, 1);
cap_buffer_.Reset();
uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_);
buffer_.WriteAt<uint32_t>(4, 16 + length);
z_cap_t reply_port_cap;
@ -65,14 +75,18 @@ glcr::ErrorCode YellowstoneClient::GetEndpoint(const GetEndpointRequest& request
// Check Response Code.
RET_ERR(buffer_.At<uint64_t>(8));
response.ParseFromBytes(buffer_, 16, cap_buffer_);
return glcr::OK;
}
glcr::ErrorCode YellowstoneClient::GetAhciInfo(const Empty& request, AhciInfo& response) {
glcr::ErrorCode YellowstoneClient::GetAhciInfo(AhciInfo& response) {
uint64_t buffer_size = kBufferSize;
uint64_t cap_size = kCapBufferSize;
@ -81,7 +95,10 @@ glcr::ErrorCode YellowstoneClient::GetAhciInfo(const Empty& request, AhciInfo& r
buffer_.WriteAt<uint64_t>(8, 2);
cap_buffer_.Reset();
uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_);
uint64_t length = 0;
buffer_.WriteAt<uint32_t>(4, 16 + length);
z_cap_t reply_port_cap;
@ -97,14 +114,18 @@ glcr::ErrorCode YellowstoneClient::GetAhciInfo(const Empty& request, AhciInfo& r
// Check Response Code.
RET_ERR(buffer_.At<uint64_t>(8));
response.ParseFromBytes(buffer_, 16, cap_buffer_);
return glcr::OK;
}
glcr::ErrorCode YellowstoneClient::GetFramebufferInfo(const Empty& request, FramebufferInfo& response) {
glcr::ErrorCode YellowstoneClient::GetFramebufferInfo(FramebufferInfo& response) {
uint64_t buffer_size = kBufferSize;
uint64_t cap_size = kCapBufferSize;
@ -113,7 +134,10 @@ glcr::ErrorCode YellowstoneClient::GetFramebufferInfo(const Empty& request, Fram
buffer_.WriteAt<uint64_t>(8, 3);
cap_buffer_.Reset();
uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_);
uint64_t length = 0;
buffer_.WriteAt<uint32_t>(4, 16 + length);
z_cap_t reply_port_cap;
@ -129,14 +153,18 @@ glcr::ErrorCode YellowstoneClient::GetFramebufferInfo(const Empty& request, Fram
// Check Response Code.
RET_ERR(buffer_.At<uint64_t>(8));
response.ParseFromBytes(buffer_, 16, cap_buffer_);
return glcr::OK;
}
glcr::ErrorCode YellowstoneClient::GetDenali(const Empty& request, DenaliInfo& response) {
glcr::ErrorCode YellowstoneClient::GetDenali(DenaliInfo& response) {
uint64_t buffer_size = kBufferSize;
uint64_t cap_size = kCapBufferSize;
@ -145,7 +173,10 @@ glcr::ErrorCode YellowstoneClient::GetDenali(const Empty& request, DenaliInfo& r
buffer_.WriteAt<uint64_t>(8, 4);
cap_buffer_.Reset();
uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_);
uint64_t length = 0;
buffer_.WriteAt<uint32_t>(4, 16 + length);
z_cap_t reply_port_cap;
@ -161,8 +192,10 @@ glcr::ErrorCode YellowstoneClient::GetDenali(const Empty& request, DenaliInfo& r
// Check Response Code.
RET_ERR(buffer_.At<uint64_t>(8));
response.ParseFromBytes(buffer_, 16, cap_buffer_);
return glcr::OK;
}

View File

@ -17,15 +17,25 @@ class YellowstoneClient {
z_cap_t Capability() { return endpoint_; }
[[nodiscard]] glcr::ErrorCode RegisterEndpoint(const RegisterEndpointRequest& request, Empty& response);
[[nodiscard]] glcr::ErrorCode RegisterEndpoint(const RegisterEndpointRequest& request);
[[nodiscard]] glcr::ErrorCode GetEndpoint(const GetEndpointRequest& request, Endpoint& response);
[[nodiscard]] glcr::ErrorCode GetAhciInfo(const Empty& request, AhciInfo& response);
[[nodiscard]] glcr::ErrorCode GetAhciInfo(AhciInfo& response);
[[nodiscard]] glcr::ErrorCode GetFramebufferInfo(const Empty& request, FramebufferInfo& response);
[[nodiscard]] glcr::ErrorCode GetFramebufferInfo(FramebufferInfo& response);
[[nodiscard]] glcr::ErrorCode GetDenali(const Empty& request, DenaliInfo& response);
[[nodiscard]] glcr::ErrorCode GetDenali(DenaliInfo& response);
private:
z_cap_t endpoint_;

View File

@ -101,39 +101,6 @@ uint64_t RegisterEndpointRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint
return next_extension;
}
void Empty::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
ParseFromBytesInternal(bytes, offset);
}
void Empty::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
ParseFromBytesInternal(bytes, offset);
}
void Empty::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
CheckHeader(bytes);
}
uint64_t Empty::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
uint32_t next_extension = header_size + 8 * 0;
const uint32_t core_size = next_extension;
// The next extension pointer is the length of the message.
WriteHeader(bytes, offset, core_size, next_extension);
return next_extension;
}
uint64_t Empty::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
uint32_t next_extension = header_size + 8 * 0;
const uint32_t core_size = next_extension;
uint64_t next_cap = 0;
// The next extension pointer is the length of the message.
WriteHeader(bytes, offset, core_size, next_extension);
return next_extension;
}
void GetEndpointRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
ParseFromBytesInternal(bytes, offset);
}

View File

@ -29,23 +29,6 @@ class RegisterEndpointRequest {
// Parses everything except for caps.
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
};
class Empty {
public:
Empty() {}
// Delete copy and move until implemented.
Empty(const Empty&) = delete;
Empty(Empty&&) = delete;
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
private:
// Parses everything except for caps.
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
};
class GetEndpointRequest {
public:
GetEndpointRequest() {}

View File

@ -87,58 +87,92 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req
switch(method_select) {
case 0: {
RegisterEndpointRequest yunq_request;
Empty yunq_response;
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
RET_ERR(HandleRegisterEndpoint(yunq_request, yunq_response));
resp_length = yunq_response.SerializeToBytes(response, kHeaderSize, resp_caps);
RET_ERR(HandleRegisterEndpoint(yunq_request));
resp_length = 0;
break;
}
case 1: {
GetEndpointRequest yunq_request;
Endpoint yunq_response;
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
Endpoint yunq_response;
RET_ERR(HandleGetEndpoint(yunq_request, yunq_response));
resp_length = yunq_response.SerializeToBytes(response, kHeaderSize, resp_caps);
break;
}
case 2: {
Empty yunq_request;
AhciInfo yunq_response;
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
RET_ERR(HandleGetAhciInfo(yunq_request, yunq_response));
RET_ERR(HandleGetAhciInfo(yunq_response));
resp_length = yunq_response.SerializeToBytes(response, kHeaderSize, resp_caps);
break;
}
case 3: {
Empty yunq_request;
FramebufferInfo yunq_response;
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
RET_ERR(HandleGetFramebufferInfo(yunq_request, yunq_response));
RET_ERR(HandleGetFramebufferInfo(yunq_response));
resp_length = yunq_response.SerializeToBytes(response, kHeaderSize, resp_caps);
break;
}
case 4: {
Empty yunq_request;
DenaliInfo yunq_response;
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
RET_ERR(HandleGetDenali(yunq_request, yunq_response));
RET_ERR(HandleGetDenali(yunq_response));
resp_length = yunq_response.SerializeToBytes(response, kHeaderSize, resp_caps);
break;
}
default: {

View File

@ -21,15 +21,25 @@ class YellowstoneServerBase {
[[nodiscard]] Thread RunServer();
[[nodiscard]] virtual glcr::ErrorCode HandleRegisterEndpoint(const RegisterEndpointRequest&, Empty&) = 0;
[[nodiscard]] virtual glcr::ErrorCode HandleRegisterEndpoint(const RegisterEndpointRequest&) = 0;
[[nodiscard]] virtual glcr::ErrorCode HandleGetEndpoint(const GetEndpointRequest&, Endpoint&) = 0;
[[nodiscard]] virtual glcr::ErrorCode HandleGetAhciInfo(const Empty&, AhciInfo&) = 0;
[[nodiscard]] virtual glcr::ErrorCode HandleGetFramebufferInfo(const Empty&, FramebufferInfo&) = 0;
[[nodiscard]] virtual glcr::ErrorCode HandleGetDenali(const Empty&, DenaliInfo&) = 0;
[[nodiscard]] virtual glcr::ErrorCode HandleGetAhciInfo(AhciInfo&) = 0;
[[nodiscard]] virtual glcr::ErrorCode HandleGetFramebufferInfo(FramebufferInfo&) = 0;
[[nodiscard]] virtual glcr::ErrorCode HandleGetDenali(DenaliInfo&) = 0;
private:

View File

@ -41,15 +41,14 @@ glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> YellowstoneServer::Create() {
YellowstoneServer::YellowstoneServer(z_cap_t endpoint_cap)
: YellowstoneServerBase(endpoint_cap) {}
glcr::ErrorCode YellowstoneServer::HandleGetAhciInfo(const Empty&,
AhciInfo& info) {
glcr::ErrorCode YellowstoneServer::HandleGetAhciInfo(AhciInfo& info) {
info.set_ahci_region(pci_reader_.GetAhciVmmo());
info.set_region_length(kPcieConfigurationSize);
return glcr::OK;
}
glcr::ErrorCode YellowstoneServer::HandleGetFramebufferInfo(
const Empty&, FramebufferInfo& info) {
FramebufferInfo& info) {
// FIXME: Don't do this for each request.
mmth::OwnedMemoryRegion region =
mmth::OwnedMemoryRegion::FromCapability(gBootFramebufferVmmoCap);
@ -71,8 +70,7 @@ glcr::ErrorCode YellowstoneServer::HandleGetFramebufferInfo(
return glcr::OK;
}
glcr::ErrorCode YellowstoneServer::HandleGetDenali(const Empty&,
DenaliInfo& info) {
glcr::ErrorCode YellowstoneServer::HandleGetDenali(DenaliInfo& info) {
if (!endpoint_map_.Contains("denali")) {
return glcr::NOT_FOUND;
}
@ -85,7 +83,7 @@ glcr::ErrorCode YellowstoneServer::HandleGetDenali(const Empty&,
}
glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint(
const RegisterEndpointRequest& req, Empty&) {
const RegisterEndpointRequest& req) {
dbgln("Registering {}.", req.endpoint_name().view());
check(endpoint_map_.Insert(req.endpoint_name(), req.endpoint_capability()));
if (req.endpoint_name() == "denali") {

View File

@ -14,12 +14,11 @@ class YellowstoneServer : public YellowstoneServerBase {
public:
static glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> Create();
glcr::ErrorCode HandleGetAhciInfo(const Empty&, AhciInfo&) override;
glcr::ErrorCode HandleGetFramebufferInfo(const Empty&,
FramebufferInfo&) override;
glcr::ErrorCode HandleGetDenali(const Empty&, DenaliInfo&) override;
glcr::ErrorCode HandleRegisterEndpoint(const RegisterEndpointRequest&,
Empty&) override;
glcr::ErrorCode HandleGetAhciInfo(AhciInfo&) override;
glcr::ErrorCode HandleGetFramebufferInfo(FramebufferInfo&) override;
glcr::ErrorCode HandleGetDenali(DenaliInfo&) override;
glcr::ErrorCode HandleRegisterEndpoint(
const RegisterEndpointRequest&) override;
glcr::ErrorCode HandleGetEndpoint(const GetEndpointRequest&,
Endpoint&) override;