[yellowstone] Add a way to retrieve to denali client from yellowstone

This commit is contained in:
Drew Galbraith 2023-07-05 16:03:20 -07:00
parent b83385dfa6
commit 29d9923f5a
10 changed files with 99 additions and 7 deletions

View file

@ -3,6 +3,8 @@
#include <denali/denali.h>
#include <glacier/string/string.h>
#include <mammoth/debug.h>
#include <mammoth/init.h>
#include <mammoth/process.h>
#include <stdlib.h>
#include "hw/gpt.h"
@ -20,11 +22,19 @@ void RegistrationThreadBootstrap(void* yellowstone) {
static_cast<YellowstoneServer*>(yellowstone)->RegistrationThread();
}
glcr::ErrorCode HandleDenaliRegistration(z_cap_t endpoint_cap) {
struct PartitionInfo {
uint64_t device_id;
uint64_t partition_lba;
};
glcr::ErrorOr<PartitionInfo> HandleDenaliRegistration(z_cap_t endpoint_cap) {
GptReader reader(glcr::UniquePtr<DenaliClient>(
new DenaliClient(EndpointClient::AdoptEndpoint(endpoint_cap))));
return reader.ParsePartitionTables();
RET_ERR(reader.ParsePartitionTables());
return PartitionInfo{.device_id = 0,
.partition_lba = reader.GetPrimaryPartitionLba()};
}
} // namespace
@ -77,6 +87,18 @@ void YellowstoneServer::ServerThread() {
check(ZReplyPortSend(reply_port_cap, sizeof(resp), &resp, 1, &reg_cap));
break;
}
case kYellowstoneGetDenali: {
dbgln("Yellowstone::GetDenali");
z_cap_t new_denali;
check(ZCapDuplicate(denali_cap_, &new_denali));
YellowstoneGetDenaliResp resp{
.type = kYellowstoneGetDenali,
.device_id = device_id_,
.lba_offset = lba_offset_,
};
check(ZReplyPortSend(reply_port_cap, sizeof(resp), &resp, 1,
&new_denali));
}
default:
dbgln("Unknown request type: %x", req->type);
break;
@ -94,7 +116,21 @@ void YellowstoneServer::RegistrationThread() {
glcr::String name(registration_buffer_);
if (name == "denali") {
denali_cap_ = endpoint_cap;
check(HandleDenaliRegistration(denali_cap_));
auto part_info_or = HandleDenaliRegistration(denali_cap_);
if (!part_info_or.ok()) {
check(part_info_or.error());
}
device_id_ = part_info_or.value().device_id;
lba_offset_ = part_info_or.value().partition_lba;
uint64_t vaddr;
check(
ZAddressSpaceMap(gSelfVmasCap, 0, gBootVictoriaFallsVmmoCap, &vaddr));
auto client_or = GetServerClient();
if (!client_or.ok()) {
check(client_or.error());
}
check(SpawnProcessFromElfRegion(vaddr, glcr::Move(client_or.value())));
continue;
}