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) {
|
2023-06-26 11:54:36 -07:00
|
|
|
GptReader reader(glcr::UniquePtr<DenaliClient>(
|
|
|
|
new DenaliClient(EndpointClient::AdoptEndpoint(endpoint_cap))));
|
2023-06-22 02:19:16 -07:00
|
|
|
|
|
|
|
return reader.ParsePartitionTables();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2023-06-26 11:38:17 -07:00
|
|
|
glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> YellowstoneServer::Create() {
|
|
|
|
ASSIGN_OR_RETURN(auto server, EndpointServer::Create());
|
2023-06-26 08:41:44 -07:00
|
|
|
ASSIGN_OR_RETURN(PortServer port, PortServer::Create());
|
2023-06-26 11:38:17 -07:00
|
|
|
return glcr::UniquePtr<YellowstoneServer>(
|
|
|
|
new YellowstoneServer(glcr::Move(server), port));
|
2023-06-22 02:19:16 -07:00
|
|
|
}
|
|
|
|
|
2023-06-26 11:38:17 -07:00
|
|
|
YellowstoneServer::YellowstoneServer(glcr::UniquePtr<EndpointServer> server,
|
|
|
|
PortServer port)
|
|
|
|
: server_(glcr::Move(server)), register_port_(port) {}
|
2023-06-22 02:19:16 -07:00
|
|
|
|
|
|
|
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.
|
2023-06-26 11:38:17 -07:00
|
|
|
check(server_->Recieve(&num_bytes, server_buffer_, &reply_port_cap));
|
2023-06-22 02:19:16 -07:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-26 11:54:36 -07:00
|
|
|
glcr::ErrorOr<glcr::UniquePtr<EndpointClient>>
|
|
|
|
YellowstoneServer::GetServerClient() {
|
2023-06-26 11:38:17 -07:00
|
|
|
return server_->CreateClient();
|
2023-06-22 02:19:16 -07:00
|
|
|
}
|