2023-06-22 02:19:16 -07:00
|
|
|
#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"
|
|
|
|
|
|
|
|
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());
|
2023-06-26 08:41:44 -07:00
|
|
|
ASSIGN_OR_RETURN(PortServer port, PortServer::Create());
|
2023-06-22 02:19:16 -07:00
|
|
|
return YellowstoneServer(server, port);
|
|
|
|
}
|
|
|
|
|
2023-06-26 08:41:44 -07:00
|
|
|
YellowstoneServer::YellowstoneServer(EndpointServer server, PortServer port)
|
2023-06-22 02:19:16 -07:00
|
|
|
: 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");
|
2023-06-26 08:59:28 -07:00
|
|
|
auto client_or = register_port_.CreateClient();
|
|
|
|
if (!client_or.ok()) {
|
|
|
|
check(client_or.error());
|
|
|
|
}
|
2023-06-22 02:19:16 -07:00
|
|
|
YellowstoneGetRegistrationResp resp;
|
2023-06-26 08:59:28 -07:00
|
|
|
uint64_t reg_cap = client_or.value().cap();
|
2023-06-22 02:19:16 -07:00
|
|
|
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();
|
|
|
|
}
|