From b95c736825f30995f594db648bfa8e6b1d412fd2 Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Mon, 27 Nov 2023 08:06:04 -0800 Subject: [PATCH] [Yellowstone] Use yunq native empty requests and responses for service. --- sys/denali/denali.cpp | 5 +- sys/teton/teton.cpp | 2 +- sys/victoriafalls/victoriafalls.cpp | 5 +- sys/voyageurs/voyageurs.cpp | 3 +- .../lib/yellowstone/yellowstone.yunq | 12 ++-- .../yellowstone/yellowstone.yunq.client.cpp | 49 ++++++++++--- .../lib/yellowstone/yellowstone.yunq.client.h | 18 +++-- .../lib/yellowstone/yellowstone.yunq.cpp | 33 --------- .../lib/yellowstone/yellowstone.yunq.h | 17 ----- .../yellowstone/yellowstone.yunq.server.cpp | 70 ++++++++++++++----- .../lib/yellowstone/yellowstone.yunq.server.h | 18 +++-- sys/yellowstone/yellowstone_server.cpp | 10 ++- sys/yellowstone/yellowstone_server.h | 11 ++- 13 files changed, 140 insertions(+), 113 deletions(-) diff --git a/sys/denali/denali.cpp b/sys/denali/denali.cpp index 8baa337..bb5fc61 100644 --- a/sys/denali/denali.cpp +++ b/sys/denali/denali.cpp @@ -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; diff --git a/sys/teton/teton.cpp b/sys/teton/teton.cpp index fb56e1c..f807806 100644 --- a/sys/teton/teton.cpp +++ b/sys/teton/teton.cpp @@ -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()); diff --git a/sys/victoriafalls/victoriafalls.cpp b/sys/victoriafalls/victoriafalls.cpp index 79090f6..49f76a5 100644 --- a/sys/victoriafalls/victoriafalls.cpp +++ b/sys/victoriafalls/victoriafalls.cpp @@ -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()); diff --git a/sys/voyageurs/voyageurs.cpp b/sys/voyageurs/voyageurs.cpp index 6ef4b30..bf9362d 100644 --- a/sys/voyageurs/voyageurs.cpp +++ b/sys/voyageurs/voyageurs.cpp @@ -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()); diff --git a/sys/yellowstone/lib/yellowstone/yellowstone.yunq b/sys/yellowstone/lib/yellowstone/yellowstone.yunq index e6c1680..25dd9d2 100644 --- a/sys/yellowstone/lib/yellowstone/yellowstone.yunq +++ b/sys/yellowstone/lib/yellowstone/yellowstone.yunq @@ -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; } diff --git a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.client.cpp b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.client.cpp index 1c2f74f..2a016c5 100644 --- a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.client.cpp +++ b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.client.cpp @@ -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(8, 0); cap_buffer_.Reset(); + uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_); + + buffer_.WriteAt(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(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(8, 1); cap_buffer_.Reset(); + uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_); + + buffer_.WriteAt(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(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(8, 2); cap_buffer_.Reset(); - uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_); + + uint64_t length = 0; + + buffer_.WriteAt(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(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(8, 3); cap_buffer_.Reset(); - uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_); + + uint64_t length = 0; + + buffer_.WriteAt(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(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(8, 4); cap_buffer_.Reset(); - uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_); + + uint64_t length = 0; + + buffer_.WriteAt(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(8)); + response.ParseFromBytes(buffer_, 16, cap_buffer_); + return glcr::OK; } diff --git a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.client.h b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.client.h index a03f375..1d8dfaa 100644 --- a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.client.h +++ b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.client.h @@ -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_; diff --git a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.cpp b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.cpp index c3394cb..bdd21d9 100644 --- a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.cpp +++ b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.cpp @@ -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); } diff --git a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.h b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.h index d9ebc14..2ad9d3e 100644 --- a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.h +++ b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.h @@ -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() {} diff --git a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.server.cpp b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.server.cpp index f84bce4..c5f4a0e 100644 --- a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.server.cpp +++ b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.server.cpp @@ -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: { diff --git a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.server.h b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.server.h index e44fe2b..c5b8f3b 100644 --- a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.server.h +++ b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.server.h @@ -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: diff --git a/sys/yellowstone/yellowstone_server.cpp b/sys/yellowstone/yellowstone_server.cpp index 1b4fcae..ed7ccd1 100644 --- a/sys/yellowstone/yellowstone_server.cpp +++ b/sys/yellowstone/yellowstone_server.cpp @@ -41,15 +41,14 @@ glcr::ErrorOr> 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") { diff --git a/sys/yellowstone/yellowstone_server.h b/sys/yellowstone/yellowstone_server.h index 6447fa6..3eca509 100644 --- a/sys/yellowstone/yellowstone_server.h +++ b/sys/yellowstone/yellowstone_server.h @@ -14,12 +14,11 @@ class YellowstoneServer : public YellowstoneServerBase { public: static glcr::ErrorOr> 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;