2023-06-22 02:19:16 -07:00
|
|
|
#include "yellowstone_server.h"
|
|
|
|
|
2023-10-25 20:28:28 -07:00
|
|
|
#include <denali/denali.yunq.client.h>
|
2023-06-22 02:19:16 -07:00
|
|
|
#include <glacier/string/string.h>
|
2023-11-22 14:39:27 -08:00
|
|
|
#include <mammoth/util/debug.h>
|
|
|
|
#include <mammoth/util/init.h>
|
|
|
|
#include <mammoth/util/memory_region.h>
|
2023-06-22 02:19:16 -07:00
|
|
|
#include <stdlib.h>
|
2023-11-22 13:41:14 -08:00
|
|
|
#include <zcall.h>
|
2023-06-22 02:19:16 -07:00
|
|
|
|
|
|
|
#include "hw/gpt.h"
|
2023-08-01 17:46:26 -07:00
|
|
|
#include "hw/pcie.h"
|
2023-06-22 02:19:16 -07:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2023-07-05 16:03:20 -07:00
|
|
|
struct PartitionInfo {
|
|
|
|
uint64_t device_id;
|
|
|
|
uint64_t partition_lba;
|
|
|
|
};
|
|
|
|
|
|
|
|
glcr::ErrorOr<PartitionInfo> HandleDenaliRegistration(z_cap_t endpoint_cap) {
|
2023-10-25 20:28:28 -07:00
|
|
|
GptReader reader(
|
|
|
|
glcr::UniquePtr<DenaliClient>(new DenaliClient(endpoint_cap)));
|
2023-06-22 02:19:16 -07:00
|
|
|
|
2023-07-05 16:03:20 -07:00
|
|
|
RET_ERR(reader.ParsePartitionTables());
|
|
|
|
|
|
|
|
return PartitionInfo{.device_id = 0,
|
|
|
|
.partition_lba = reader.GetPrimaryPartitionLba()};
|
2023-06-22 02:19:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2023-06-26 11:38:17 -07:00
|
|
|
glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> YellowstoneServer::Create() {
|
2023-10-25 19:08:00 -07:00
|
|
|
z_cap_t endpoint_cap;
|
|
|
|
RET_ERR(ZEndpointCreate(&endpoint_cap));
|
|
|
|
|
2023-11-22 13:30:59 -08:00
|
|
|
return glcr::UniquePtr<YellowstoneServer>(
|
|
|
|
new YellowstoneServer(endpoint_cap));
|
2023-06-22 02:19:16 -07:00
|
|
|
}
|
|
|
|
|
2023-11-22 13:30:59 -08:00
|
|
|
YellowstoneServer::YellowstoneServer(z_cap_t endpoint_cap)
|
|
|
|
: YellowstoneServerBase(endpoint_cap) {}
|
2023-06-22 02:19:16 -07:00
|
|
|
|
2023-10-24 18:24:26 -07:00
|
|
|
glcr::ErrorCode YellowstoneServer::HandleGetAhciInfo(const Empty&,
|
|
|
|
AhciInfo& info) {
|
|
|
|
info.set_ahci_region(pci_reader_.GetAhciVmmo());
|
|
|
|
info.set_region_length(kPcieConfigurationSize);
|
|
|
|
return glcr::OK;
|
|
|
|
}
|
|
|
|
|
2023-11-09 11:33:32 -08:00
|
|
|
glcr::ErrorCode YellowstoneServer::HandleGetFramebufferInfo(
|
|
|
|
const Empty&, FramebufferInfo& info) {
|
|
|
|
// FIXME: Don't do this for each request.
|
2023-11-19 20:33:15 -08:00
|
|
|
OwnedMemoryRegion region =
|
|
|
|
OwnedMemoryRegion::FromCapability(gBootFramebufferVmmoCap);
|
2023-11-09 11:33:32 -08:00
|
|
|
ZFramebufferInfo* fb = reinterpret_cast<ZFramebufferInfo*>(region.vaddr());
|
|
|
|
|
|
|
|
info.set_address_phys(fb->address_phys);
|
|
|
|
info.set_width(fb->width);
|
|
|
|
info.set_height(fb->height);
|
|
|
|
info.set_pitch(fb->pitch);
|
|
|
|
info.set_bpp(fb->bpp);
|
|
|
|
info.set_memory_model(fb->memory_model);
|
|
|
|
info.set_red_mask_size(fb->red_mask_size);
|
|
|
|
info.set_red_mask_shift(fb->red_mask_shift);
|
|
|
|
info.set_green_mask_size(fb->green_mask_size);
|
|
|
|
info.set_green_mask_shift(fb->green_mask_shift);
|
|
|
|
info.set_blue_mask_size(fb->blue_mask_size);
|
|
|
|
info.set_blue_mask_shift(fb->blue_mask_shift);
|
|
|
|
|
|
|
|
return glcr::OK;
|
|
|
|
}
|
|
|
|
|
2023-10-24 18:24:26 -07:00
|
|
|
glcr::ErrorCode YellowstoneServer::HandleGetDenali(const Empty&,
|
|
|
|
DenaliInfo& info) {
|
2023-11-21 19:14:02 -08:00
|
|
|
if (!endpoint_map_.Contains("denali")) {
|
|
|
|
return glcr::NOT_FOUND;
|
|
|
|
}
|
2023-10-24 18:24:26 -07:00
|
|
|
z_cap_t new_denali;
|
2023-11-21 19:14:02 -08:00
|
|
|
check(ZCapDuplicate(endpoint_map_.at("denali"), kZionPerm_All, &new_denali));
|
2023-10-24 18:24:26 -07:00
|
|
|
info.set_denali_endpoint(new_denali);
|
|
|
|
info.set_device_id(device_id_);
|
|
|
|
info.set_lba_offset(lba_offset_);
|
|
|
|
return glcr::OK;
|
|
|
|
}
|
2023-07-05 16:03:20 -07:00
|
|
|
|
2023-10-24 23:42:34 -07:00
|
|
|
glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint(
|
|
|
|
const RegisterEndpointRequest& req, Empty&) {
|
2023-11-19 19:14:37 -08:00
|
|
|
dbgln("Registering {}.", req.endpoint_name().view());
|
2023-11-21 19:14:02 -08:00
|
|
|
check(endpoint_map_.Insert(req.endpoint_name(), req.endpoint_capability()));
|
2023-10-24 23:42:34 -07:00
|
|
|
if (req.endpoint_name() == "denali") {
|
2023-11-21 19:14:02 -08:00
|
|
|
auto part_info_or = HandleDenaliRegistration(req.endpoint_capability());
|
2023-10-24 23:42:34 -07:00
|
|
|
if (!part_info_or.ok()) {
|
|
|
|
check(part_info_or.error());
|
2023-06-22 02:19:16 -07:00
|
|
|
}
|
2023-10-24 23:42:34 -07:00
|
|
|
device_id_ = part_info_or.value().device_id;
|
|
|
|
lba_offset_ = part_info_or.value().partition_lba;
|
|
|
|
|
2023-11-22 13:30:59 -08:00
|
|
|
has_denali_semaphore_.Signal();
|
2023-10-24 23:42:34 -07:00
|
|
|
} else if (req.endpoint_name() == "victoriafalls") {
|
2023-11-02 19:28:27 -07:00
|
|
|
// FIXME: Probably make a separate copy for use within yellowstone vs
|
|
|
|
// transmit to other processes.
|
2023-11-21 19:14:02 -08:00
|
|
|
vfs_client_ = glcr::MakeShared<VFSClient>(req.endpoint_capability());
|
2023-11-22 13:30:59 -08:00
|
|
|
has_victoriafalls_semaphore_.Signal();
|
2023-10-24 23:42:34 -07:00
|
|
|
} else {
|
2023-11-03 02:48:21 -07:00
|
|
|
dbgln("[WARN] Got endpoint cap type: {}", req.endpoint_name().cstr());
|
2023-06-22 02:19:16 -07:00
|
|
|
}
|
2023-10-24 23:42:34 -07:00
|
|
|
return glcr::OK;
|
2023-06-22 02:19:16 -07:00
|
|
|
}
|
2023-10-25 19:08:00 -07:00
|
|
|
|
2023-11-21 19:14:02 -08:00
|
|
|
glcr::ErrorCode YellowstoneServer::HandleGetEndpoint(
|
|
|
|
const GetEndpointRequest& req, Endpoint& resp) {
|
|
|
|
if (!endpoint_map_.Contains(req.endpoint_name())) {
|
|
|
|
return glcr::NOT_FOUND;
|
|
|
|
}
|
|
|
|
z_cap_t cap = endpoint_map_.at(req.endpoint_name());
|
|
|
|
z_cap_t new_cap;
|
|
|
|
check(ZCapDuplicate(cap, kZionPerm_All, &new_cap));
|
|
|
|
resp.set_endpoint(new_cap);
|
|
|
|
return glcr::OK;
|
|
|
|
}
|
|
|
|
|
2023-11-22 13:30:59 -08:00
|
|
|
void YellowstoneServer::WaitDenaliRegistered() { has_denali_semaphore_.Wait(); }
|
2023-11-02 18:55:05 -07:00
|
|
|
|
2023-11-22 13:30:59 -08:00
|
|
|
void YellowstoneServer::WaitVictoriaFallsRegistered() {
|
|
|
|
has_victoriafalls_semaphore_.Wait();
|
2023-11-02 18:55:05 -07:00
|
|
|
}
|
2023-11-02 19:28:27 -07:00
|
|
|
|
|
|
|
glcr::SharedPtr<VFSClient> YellowstoneServer::GetVFSClient() {
|
|
|
|
return vfs_client_;
|
|
|
|
}
|