[yellowstone] Add yellowstone server for endpoint registration.
This commit is contained in:
parent
8dcb1ddabd
commit
a46694d0f7
13 changed files with 248 additions and 31 deletions
105
sys/yellowstone/yellowstone_server.cpp
Normal file
105
sys/yellowstone/yellowstone_server.cpp
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
#include "yellowstone_server.h"
|
||||
|
||||
#include <denali/denali.h>
|
||||
#include <glacier/string/string.h>
|
||||
#include <mammoth/debug.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "hw/gpt.h"
|
||||
#include "include/yellowstone.h"
|
||||
|
||||
// FIXME: This linkage was missing :(
|
||||
void* operator new[](uint64_t size) { return malloc(size); }
|
||||
namespace {
|
||||
|
||||
void ServerThreadBootstrap(void* yellowstone) {
|
||||
dbgln("Yellowstone server starting");
|
||||
static_cast<YellowstoneServer*>(yellowstone)->ServerThread();
|
||||
}
|
||||
|
||||
void RegistrationThreadBootstrap(void* yellowstone) {
|
||||
dbgln("Yellowstone registration starting");
|
||||
static_cast<YellowstoneServer*>(yellowstone)->RegistrationThread();
|
||||
}
|
||||
|
||||
glcr::ErrorCode HandleDenaliRegistration(z_cap_t endpoint_cap) {
|
||||
EndpointClient endpoint = EndpointClient::AdoptEndpoint(endpoint_cap);
|
||||
DenaliClient client(endpoint);
|
||||
GptReader reader(client);
|
||||
|
||||
return reader.ParsePartitionTables();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
glcr::ErrorOr<YellowstoneServer> YellowstoneServer::Create() {
|
||||
ASSIGN_OR_RETURN(EndpointServer server, EndpointServer::Create());
|
||||
ASSIGN_OR_RETURN(Port port, Port::Create());
|
||||
return YellowstoneServer(server, port);
|
||||
}
|
||||
|
||||
YellowstoneServer::YellowstoneServer(EndpointServer server, Port port)
|
||||
: server_(server), register_port_(port) {}
|
||||
|
||||
Thread YellowstoneServer::RunServer() {
|
||||
return Thread(ServerThreadBootstrap, this);
|
||||
}
|
||||
|
||||
Thread YellowstoneServer::RunRegistration() {
|
||||
return Thread(RegistrationThreadBootstrap, this);
|
||||
}
|
||||
|
||||
void YellowstoneServer::ServerThread() {
|
||||
while (true) {
|
||||
uint64_t num_bytes = kBufferSize;
|
||||
uint64_t reply_port_cap;
|
||||
// FIXME: Error handling.
|
||||
check(server_.Recieve(&num_bytes, server_buffer_, &reply_port_cap));
|
||||
YellowstoneGetReq* req =
|
||||
reinterpret_cast<YellowstoneGetReq*>(server_buffer_);
|
||||
switch (req->type) {
|
||||
case kYellowstoneGetAhci:
|
||||
dbgln("Yellowstone::GetAHCI");
|
||||
break;
|
||||
case kYellowstoneGetRegistration: {
|
||||
dbgln("Yellowstone::GetRegistration");
|
||||
uint64_t reg_cap;
|
||||
check(register_port_.Duplicate(®_cap));
|
||||
YellowstoneGetRegistrationResp resp;
|
||||
check(ZReplyPortSend(reply_port_cap, sizeof(resp), &resp, 1, ®_cap));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
dbgln("Unknown request type: %x", req->type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void YellowstoneServer::RegistrationThread() {
|
||||
while (true) {
|
||||
uint64_t num_bytes = kBufferSize;
|
||||
z_cap_t endpoint_cap;
|
||||
// FIXME: Better error handling here.
|
||||
check(register_port_.RecvCap(&num_bytes, registration_buffer_,
|
||||
&endpoint_cap));
|
||||
glcr::String name(registration_buffer_);
|
||||
if (name == "denali") {
|
||||
denali_cap_ = endpoint_cap;
|
||||
check(HandleDenaliRegistration(denali_cap_));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (name == "victoriafalls") {
|
||||
victoria_falls_cap_ = endpoint_cap;
|
||||
continue;
|
||||
}
|
||||
|
||||
dbgln("[WARN] Got endpoint cap type:");
|
||||
dbgln(name.cstr());
|
||||
}
|
||||
}
|
||||
|
||||
glcr::ErrorOr<EndpointClient> YellowstoneServer::GetServerClient() {
|
||||
return server_.CreateClient();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue