Compare commits

..

No commits in common. "8f84f8c3ca693180148d9516af16979ab47979f6" and "847d37addc0d7398d1cd474ca6e163ba4f99f5d3" have entirely different histories.

23 changed files with 170 additions and 250 deletions

View File

@ -5,9 +5,6 @@
#include <ztypes.h> #include <ztypes.h>
#include "mammoth/endpoint_client.h" #include "mammoth/endpoint_client.h"
#include "mammoth/request_context.h"
#include "mammoth/response_context.h"
#include "mammoth/thread.h"
class EndpointServer { class EndpointServer {
public: public:
@ -15,22 +12,19 @@ class EndpointServer {
EndpointServer(const EndpointServer&) = delete; EndpointServer(const EndpointServer&) = delete;
EndpointServer& operator=(const EndpointServer&) = delete; EndpointServer& operator=(const EndpointServer&) = delete;
static glcr::ErrorOr<glcr::UniquePtr<EndpointServer>> Create();
static glcr::UniquePtr<EndpointServer> Adopt(z_cap_t endpoint_cap);
glcr::ErrorOr<glcr::UniquePtr<EndpointClient>> CreateClient(); glcr::ErrorOr<glcr::UniquePtr<EndpointClient>> CreateClient();
Thread RunServer(); // FIXME: Release Cap here.
z_cap_t GetCap() { return endpoint_cap_; }
virtual glcr::ErrorCode HandleRequest(RequestContext& request, glcr::ErrorCode Recieve(uint64_t* num_bytes, void* data,
ResponseContext& response) = 0; z_cap_t* reply_port_cap);
protected:
EndpointServer(z_cap_t cap) : endpoint_cap_(cap) {}
private: private:
z_cap_t endpoint_cap_; z_cap_t endpoint_cap_;
static const uint64_t kBufferSize = 1024; EndpointServer(z_cap_t cap) : endpoint_cap_(cap) {}
uint8_t recieve_buffer_[kBufferSize];
friend void EndpointServerThreadBootstrap(void* endpoint_server);
void ServerThread();
}; };

View File

@ -1,32 +0,0 @@
#pragma once
#include <glacier/status/error.h>
#include <stdint.h>
class RequestContext {
public:
RequestContext(void* buffer, uint64_t buffer_length)
: buffer_(buffer), buffer_length_(buffer_length) {
if (buffer_length_ < sizeof(uint64_t)) {
request_id_ = -1;
} else {
request_id_ = *reinterpret_cast<uint64_t*>(buffer);
}
}
uint64_t request_id() { return request_id_; }
template <typename T>
glcr::ErrorCode As(T** arg) {
if (buffer_length_ < sizeof(T)) {
return glcr::INVALID_ARGUMENT;
}
*arg = reinterpret_cast<T*>(buffer_);
return glcr::OK;
}
private:
uint64_t request_id_;
void* buffer_;
uint64_t buffer_length_;
};

View File

@ -1,40 +0,0 @@
#pragma once
#include <glacier/status/error.h>
#include <zcall.h>
#include <ztypes.h>
class ResponseContext {
public:
ResponseContext(z_cap_t reply_port) : reply_port_(reply_port) {}
ResponseContext(ResponseContext&) = delete;
template <typename T>
glcr::ErrorCode WriteStruct(const T& response) {
// FIXME: Here and below probably don't count as written on error.
written_ = true;
return ZReplyPortSend(reply_port_, sizeof(T), &response, 0, nullptr);
}
template <typename T>
glcr::ErrorCode WriteStructWithCap(const T& response, z_cap_t capability) {
written_ = true;
return ZReplyPortSend(reply_port_, sizeof(T), &response, 1, &capability);
}
glcr::ErrorCode WriteError(glcr::ErrorCode code) {
uint64_t response[2]{
static_cast<uint64_t>(-1),
code,
};
written_ = true;
return ZReplyPortSend(reply_port_, sizeof(response), &response, 0, nullptr);
}
bool HasWritten() { return written_; }
private:
z_cap_t reply_port_;
bool written_ = false;
};

View File

@ -1,10 +1,13 @@
#include "mammoth/endpoint_server.h" #include "mammoth/endpoint_server.h"
#include "mammoth/debug.h" glcr::ErrorOr<glcr::UniquePtr<EndpointServer>> EndpointServer::Create() {
uint64_t cap;
RET_ERR(ZEndpointCreate(&cap));
return glcr::UniquePtr<EndpointServer>(new EndpointServer(cap));
}
// Declared as friend in EndpointServer. glcr::UniquePtr<EndpointServer> EndpointServer::Adopt(z_cap_t endpoint_cap) {
void EndpointServerThreadBootstrap(void* endpoint_server) { return glcr::UniquePtr<EndpointServer>(new EndpointServer(endpoint_cap));
reinterpret_cast<EndpointServer*>(endpoint_server)->ServerThread();
} }
glcr::ErrorOr<glcr::UniquePtr<EndpointClient>> EndpointServer::CreateClient() { glcr::ErrorOr<glcr::UniquePtr<EndpointClient>> EndpointServer::CreateClient() {
@ -14,28 +17,7 @@ glcr::ErrorOr<glcr::UniquePtr<EndpointClient>> EndpointServer::CreateClient() {
return EndpointClient::AdoptEndpoint(client_cap); return EndpointClient::AdoptEndpoint(client_cap);
} }
Thread EndpointServer::RunServer() { glcr::ErrorCode EndpointServer::Recieve(uint64_t* num_bytes, void* data,
return Thread(EndpointServerThreadBootstrap, this); z_cap_t* reply_port_cap) {
} return ZEndpointRecv(endpoint_cap_, num_bytes, data, reply_port_cap);
void EndpointServer::ServerThread() {
while (true) {
uint64_t message_size = kBufferSize;
uint64_t reply_port_cap = 0;
glcr::ErrorCode err = ZEndpointRecv(endpoint_cap_, &message_size,
recieve_buffer_, &reply_port_cap);
if (err != glcr::OK) {
dbgln("Error in receive: %x", err);
continue;
}
RequestContext request(recieve_buffer_, message_size);
ResponseContext response(reply_port_cap);
// FIXME: Consider pumping these errors into the response as well.
check(HandleRequest(request, response));
if (!response.HasWritten()) {
dbgln("Returning without having written a response. Req type %x",
request.request_id());
}
}
} }

View File

@ -13,7 +13,6 @@ uint64_t gInitEndpointCap = 0;
uint64_t gBootDenaliVmmoCap = 0; uint64_t gBootDenaliVmmoCap = 0;
uint64_t gBootVictoriaFallsVmmoCap = 0; uint64_t gBootVictoriaFallsVmmoCap = 0;
uint64_t gBootPciVmmoCap = 0;
z_err_t ParseInitPort(uint64_t init_port_cap) { z_err_t ParseInitPort(uint64_t init_port_cap) {
PortServer port = PortServer::AdoptCap(init_port_cap); PortServer port = PortServer::AdoptCap(init_port_cap);
@ -41,10 +40,6 @@ z_err_t ParseInitPort(uint64_t init_port_cap) {
dbgln("received victoria falls"); dbgln("received victoria falls");
gBootVictoriaFallsVmmoCap = init_cap; gBootVictoriaFallsVmmoCap = init_cap;
break; break;
case Z_BOOT_PCI_VMMO:
dbgln("received pci");
gBootPciVmmoCap = init_cap;
break;
default: default:
dbgln("Unexpected init type %x, continuing.", init_sig); dbgln("Unexpected init type %x, continuing.", init_sig);
} }

View File

@ -7,8 +7,8 @@
Command::~Command() {} Command::~Command() {}
DmaReadCommand::DmaReadCommand(uint64_t lba, uint64_t sector_cnt, DmaReadCommand::DmaReadCommand(uint64_t lba, uint64_t sector_cnt,
DmaCallback callback, ResponseContext& response) DmaCallback callback, z_cap_t reply_port)
: response_(response), : reply_port_(reply_port),
lba_(lba), lba_(lba),
sector_cnt_(sector_cnt), sector_cnt_(sector_cnt),
callback_(callback) { callback_(callback) {
@ -50,5 +50,5 @@ void DmaReadCommand::PopulatePrdt(PhysicalRegionDescriptor* prdt) {
prdt[0].byte_count = region_.size(); prdt[0].byte_count = region_.size();
} }
void DmaReadCommand::Callback() { void DmaReadCommand::Callback() {
callback_(response_, lba_, sector_cnt_, region_.cap()); callback_(reply_port_, lba_, sector_cnt_, region_.cap());
} }

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <mammoth/memory_region.h> #include <mammoth/memory_region.h>
#include <mammoth/response_context.h>
#include <stdint.h> #include <stdint.h>
#include "ahci/ahci.h" #include "ahci/ahci.h"
@ -16,9 +15,9 @@ class Command {
class DmaReadCommand : public Command { class DmaReadCommand : public Command {
public: public:
typedef void (*DmaCallback)(ResponseContext&, uint64_t, uint64_t, z_cap_t); typedef void (*DmaCallback)(z_cap_t, uint64_t, uint64_t, z_cap_t);
DmaReadCommand(uint64_t lba, uint64_t sector_cnt, DmaCallback callback, DmaReadCommand(uint64_t lba, uint64_t sector_cnt, DmaCallback callback,
ResponseContext& reply_port); z_cap_t reply_port);
virtual ~DmaReadCommand() override; virtual ~DmaReadCommand() override;
@ -28,7 +27,7 @@ class DmaReadCommand : public Command {
void Callback() override; void Callback() override;
private: private:
ResponseContext& response_; z_cap_t reply_port_;
uint64_t lba_; uint64_t lba_;
uint64_t sector_cnt_; uint64_t sector_cnt_;
DmaCallback callback_; DmaCallback callback_;

View File

@ -6,14 +6,13 @@
glcr::ErrorOr<MappedMemoryRegion> DenaliClient::ReadSectors( glcr::ErrorOr<MappedMemoryRegion> DenaliClient::ReadSectors(
uint64_t device_id, uint64_t lba, uint64_t num_sectors) { uint64_t device_id, uint64_t lba, uint64_t num_sectors) {
DenaliReadRequest read{ DenaliRead read{
.device_id = device_id, .device_id = device_id,
.lba = lba, .lba = lba,
.size = num_sectors, .size = num_sectors,
}; };
auto pair_or = auto pair_or =
endpoint_->CallEndpointGetCap<DenaliReadRequest, DenaliReadResponse>( endpoint_->CallEndpointGetCap<DenaliRead, DenaliReadResponse>(read);
read);
if (!pair_or) { if (!pair_or) {
return pair_or.error(); return pair_or.error();
} }

View File

@ -19,15 +19,14 @@ uint64_t main(uint64_t init_port_cap) {
ASSIGN_OR_RETURN(MappedMemoryRegion ahci_region, stub.GetAhciConfig()); ASSIGN_OR_RETURN(MappedMemoryRegion ahci_region, stub.GetAhciConfig());
ASSIGN_OR_RETURN(auto driver, AhciDriver::Init(ahci_region)); ASSIGN_OR_RETURN(auto driver, AhciDriver::Init(ahci_region));
ASSIGN_OR_RETURN(glcr::UniquePtr<DenaliServer> server, ASSIGN_OR_RETURN(glcr::UniquePtr<EndpointServer> endpoint,
DenaliServer::Create(*driver)); EndpointServer::Create());
ASSIGN_OR_RETURN(glcr::UniquePtr<EndpointClient> client, ASSIGN_OR_RETURN(glcr::UniquePtr<EndpointClient> client,
server->CreateClient()); endpoint->CreateClient());
check(stub.Register("denali", *client)); check(stub.Register("denali", *client));
Thread server_thread = server->RunServer(); DenaliServer server(glcr::Move(endpoint), *driver);
RET_ERR(server.RunServer());
check(server_thread.Join()); // FIXME: Add thread join.
return 0; return 0;
} }

View File

@ -7,57 +7,61 @@
namespace { namespace {
DenaliServer* gServer = nullptr; DenaliServer* gServer = nullptr;
void HandleResponse(ResponseContext& response, uint64_t lba, uint64_t size, void HandleResponse(z_cap_t reply_port, uint64_t lba, uint64_t size,
z_cap_t mem) { z_cap_t mem) {
gServer->HandleResponse(response, lba, size, mem); gServer->HandleResponse(reply_port, lba, size, mem);
} }
} // namespace } // namespace
glcr::ErrorOr<glcr::UniquePtr<DenaliServer>> DenaliServer::Create( DenaliServer::DenaliServer(glcr::UniquePtr<EndpointServer> server,
AhciDriver& driver) { AhciDriver& driver)
z_cap_t cap; : server_(glcr::Move(server)), driver_(driver) {
RET_ERR(ZEndpointCreate(&cap)); gServer = this;
return glcr::UniquePtr<DenaliServer>(new DenaliServer(cap, driver));
} }
glcr::ErrorCode DenaliServer::HandleRequest(RequestContext& request, glcr::ErrorCode DenaliServer::RunServer() {
ResponseContext& response) { while (true) {
switch (request.request_id()) { uint64_t buff_size = kBuffSize;
z_cap_t reply_port;
RET_ERR(server_->Recieve(&buff_size, read_buffer_, &reply_port));
if (buff_size < sizeof(uint64_t)) {
dbgln("Skipping invalid message");
continue;
}
uint64_t type = *reinterpret_cast<uint64_t*>(read_buffer_);
switch (type) {
case Z_INVALID:
dbgln(reinterpret_cast<char*>(read_buffer_));
break;
case DENALI_READ: { case DENALI_READ: {
DenaliReadRequest* req = 0; DenaliRead* read_req = reinterpret_cast<DenaliRead*>(read_buffer_);
glcr::ErrorCode err = request.As<DenaliReadRequest>(&req); uint64_t memcap = 0;
if (err != glcr::OK) { RET_ERR(HandleRead(*read_req, reply_port));
response.WriteError(err);
}
err = HandleRead(req, response);
if (err != glcr::OK) {
response.WriteError(err);
}
break; break;
} }
default: default:
response.WriteError(glcr::UNIMPLEMENTED); dbgln("Invalid message type.");
break; return glcr::UNIMPLEMENTED;
}
} }
return glcr::OK;
} }
glcr::ErrorCode DenaliServer::HandleRead(DenaliReadRequest* request, glcr::ErrorCode DenaliServer::HandleRead(const DenaliRead& read,
ResponseContext& context) { z_cap_t reply_port) {
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(request->device_id)); ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(read.device_id));
device->IssueCommand(new DmaReadCommand(request->lba, request->size, device->IssueCommand(
::HandleResponse, context)); new DmaReadCommand(read.lba, read.size, ::HandleResponse, reply_port));
return glcr::OK; return glcr::OK;
} }
void DenaliServer::HandleResponse(ResponseContext& response, uint64_t lba, void DenaliServer::HandleResponse(z_cap_t reply_port, uint64_t lba,
uint64_t size, z_cap_t mem) { uint64_t size, z_cap_t mem) {
DenaliReadResponse resp{ DenaliReadResponse resp{
.device_id = 0, .device_id = 0,
.lba = lba, .lba = lba,
.size = size, .size = size,
}; };
check(response.WriteStructWithCap<DenaliReadResponse>(resp, mem)); check(ZReplyPortSend(reply_port, sizeof(resp), &resp, 1, &mem));
} }

View File

@ -6,26 +6,21 @@
#include "ahci/ahci_driver.h" #include "ahci/ahci_driver.h"
#include "denali/denali.h" #include "denali/denali.h"
class DenaliServer : public EndpointServer { class DenaliServer {
public: public:
static glcr::ErrorOr<glcr::UniquePtr<DenaliServer>> Create( DenaliServer(glcr::UniquePtr<EndpointServer> server, AhciDriver& driver);
AhciDriver& driver);
void HandleResponse(ResponseContext& response, uint64_t lba, uint64_t size, glcr::ErrorCode RunServer();
void HandleResponse(z_cap_t reply_port, uint64_t lba, uint64_t size,
z_cap_t cap); z_cap_t cap);
virtual glcr::ErrorCode HandleRequest(RequestContext& request,
ResponseContext& response) override;
private: private:
static const uint64_t kBuffSize = 1024; static const uint64_t kBuffSize = 1024;
glcr::UniquePtr<EndpointServer> server_;
uint8_t read_buffer_[kBuffSize]; uint8_t read_buffer_[kBuffSize];
AhciDriver& driver_; AhciDriver& driver_;
DenaliServer(z_cap_t endpoint_cap, AhciDriver& driver) glcr::ErrorCode HandleRead(const DenaliRead& read, z_cap_t reply_port);
: EndpointServer(endpoint_cap), driver_(driver) {}
glcr::ErrorCode HandleRead(DenaliReadRequest* request,
ResponseContext& context);
}; };

View File

@ -5,7 +5,7 @@
#define DENALI_INVALID 0 #define DENALI_INVALID 0
#define DENALI_READ 100 #define DENALI_READ 100
struct DenaliReadRequest { struct DenaliRead {
uint64_t request_type = DENALI_READ; uint64_t request_type = DENALI_READ;
uint64_t device_id; uint64_t device_id;

View File

@ -15,9 +15,13 @@ PciDeviceHeader* PciHeader(uint64_t base, uint64_t bus, uint64_t dev,
} // namespace } // namespace
PciReader::PciReader() { PciReader::PciReader() {
dbgln("Creating PCI obj");
uint64_t vmmo_cap, vmmo_size;
check(ZTempPcieConfigObjectCreate(&vmmo_cap, &vmmo_size));
dbgln("Creating addr space"); dbgln("Creating addr space");
uint64_t vaddr; uint64_t vaddr;
check(ZAddressSpaceMap(gSelfVmasCap, 0, gBootPciVmmoCap, &vaddr)); check(ZAddressSpaceMap(gSelfVmasCap, 0, vmmo_cap, &vaddr));
dbgln("Addr %lx", vaddr); dbgln("Addr %lx", vaddr);
dbgln("Dumping PCI"); dbgln("Dumping PCI");

View File

@ -13,13 +13,13 @@ uint64_t main(uint64_t port_cap) {
check(ParseInitPort(port_cap)); check(ParseInitPort(port_cap));
ASSIGN_OR_RETURN(auto server, YellowstoneServer::Create()); ASSIGN_OR_RETURN(auto server, YellowstoneServer::Create());
Thread registration_thread = server->RunRegistration();
Thread server_thread = server->RunServer(); Thread server_thread = server->RunServer();
Thread registration_thread = server->RunRegistration();
uint64_t vaddr; uint64_t vaddr;
check(ZAddressSpaceMap(gSelfVmasCap, 0, gBootDenaliVmmoCap, &vaddr)); check(ZAddressSpaceMap(gSelfVmasCap, 0, gBootDenaliVmmoCap, &vaddr));
ASSIGN_OR_RETURN(glcr::UniquePtr<EndpointClient> client, ASSIGN_OR_RETURN(glcr::UniquePtr<EndpointClient> client,
server->CreateClient()); server->GetServerClient());
check(SpawnProcessFromElfRegion(vaddr, glcr::Move(client))); check(SpawnProcessFromElfRegion(vaddr, glcr::Move(client)));
check(server_thread.Join()); check(server_thread.Join());

View File

@ -12,6 +12,11 @@
namespace { namespace {
void ServerThreadBootstrap(void* yellowstone) {
dbgln("Yellowstone server starting");
static_cast<YellowstoneServer*>(yellowstone)->ServerThread();
}
void RegistrationThreadBootstrap(void* yellowstone) { void RegistrationThreadBootstrap(void* yellowstone) {
dbgln("Yellowstone registration starting"); dbgln("Yellowstone registration starting");
static_cast<YellowstoneServer*>(yellowstone)->RegistrationThread(); static_cast<YellowstoneServer*>(yellowstone)->RegistrationThread();
@ -35,29 +40,40 @@ glcr::ErrorOr<PartitionInfo> HandleDenaliRegistration(z_cap_t endpoint_cap) {
} // namespace } // namespace
glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> YellowstoneServer::Create() { glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> YellowstoneServer::Create() {
z_cap_t cap; ASSIGN_OR_RETURN(auto server, EndpointServer::Create());
RET_ERR(ZEndpointCreate(&cap));
ASSIGN_OR_RETURN(PortServer port, PortServer::Create()); ASSIGN_OR_RETURN(PortServer port, PortServer::Create());
return glcr::UniquePtr<YellowstoneServer>(new YellowstoneServer(cap, port)); return glcr::UniquePtr<YellowstoneServer>(
new YellowstoneServer(glcr::Move(server), port));
} }
YellowstoneServer::YellowstoneServer(z_cap_t endpoint_cap, PortServer port) YellowstoneServer::YellowstoneServer(glcr::UniquePtr<EndpointServer> server,
: EndpointServer(endpoint_cap), register_port_(port) {} PortServer port)
: server_(glcr::Move(server)), register_port_(port) {}
Thread YellowstoneServer::RunServer() {
return Thread(ServerThreadBootstrap, this);
}
Thread YellowstoneServer::RunRegistration() { Thread YellowstoneServer::RunRegistration() {
return Thread(RegistrationThreadBootstrap, this); return Thread(RegistrationThreadBootstrap, this);
} }
glcr::ErrorCode YellowstoneServer::HandleRequest(RequestContext& request, void YellowstoneServer::ServerThread() {
ResponseContext& response) { while (true) {
switch (request.request_id()) { 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: { case kYellowstoneGetAhci: {
dbgln("Yellowstone::GetAHCI"); dbgln("Yellowstone::GetAHCI");
YellowstoneGetAhciResp resp{ YellowstoneGetAhciResp resp{
.type = kYellowstoneGetAhci, .type = kYellowstoneGetAhci,
.ahci_phys_offset = pci_reader_.GetAhciPhysical(), .ahci_phys_offset = pci_reader_.GetAhciPhysical(),
}; };
RET_ERR(response.WriteStruct<YellowstoneGetAhciResp>(resp)); check(ZReplyPortSend(reply_port_cap, sizeof(resp), &resp, 0, nullptr));
break; break;
} }
case kYellowstoneGetRegistration: { case kYellowstoneGetRegistration: {
@ -68,7 +84,7 @@ glcr::ErrorCode YellowstoneServer::HandleRequest(RequestContext& request,
} }
YellowstoneGetRegistrationResp resp; YellowstoneGetRegistrationResp resp;
uint64_t reg_cap = client_or.value().cap(); uint64_t reg_cap = client_or.value().cap();
RET_ERR(response.WriteStructWithCap(resp, reg_cap)); check(ZReplyPortSend(reply_port_cap, sizeof(resp), &resp, 1, &reg_cap));
break; break;
} }
case kYellowstoneGetDenali: { case kYellowstoneGetDenali: {
@ -80,15 +96,15 @@ glcr::ErrorCode YellowstoneServer::HandleRequest(RequestContext& request,
.device_id = device_id_, .device_id = device_id_,
.lba_offset = lba_offset_, .lba_offset = lba_offset_,
}; };
RET_ERR(response.WriteStructWithCap(resp, new_denali)); check(ZReplyPortSend(reply_port_cap, sizeof(resp), &resp, 1,
&new_denali));
break; break;
} }
default: default:
dbgln("Unknown request type: %x", request.request_id()); dbgln("Unknown request type: %x", req->type);
return glcr::UNIMPLEMENTED;
break; break;
} }
return glcr::OK; }
} }
void YellowstoneServer::RegistrationThread() { void YellowstoneServer::RegistrationThread() {
@ -111,7 +127,7 @@ void YellowstoneServer::RegistrationThread() {
uint64_t vaddr; uint64_t vaddr;
check( check(
ZAddressSpaceMap(gSelfVmasCap, 0, gBootVictoriaFallsVmmoCap, &vaddr)); ZAddressSpaceMap(gSelfVmasCap, 0, gBootVictoriaFallsVmmoCap, &vaddr));
auto client_or = CreateClient(); auto client_or = GetServerClient();
if (!client_or.ok()) { if (!client_or.ok()) {
check(client_or.error()); check(client_or.error());
} }
@ -128,3 +144,8 @@ void YellowstoneServer::RegistrationThread() {
dbgln(name.cstr()); dbgln(name.cstr());
} }
} }
glcr::ErrorOr<glcr::UniquePtr<EndpointClient>>
YellowstoneServer::GetServerClient() {
return server_->CreateClient();
}

View File

@ -8,19 +8,20 @@
#include "hw/pcie.h" #include "hw/pcie.h"
class YellowstoneServer : public EndpointServer { class YellowstoneServer {
public: public:
static glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> Create(); static glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> Create();
Thread RunServer();
Thread RunRegistration(); Thread RunRegistration();
void ServerThread();
void RegistrationThread(); void RegistrationThread();
virtual glcr::ErrorCode HandleRequest(RequestContext& request, glcr::ErrorOr<glcr::UniquePtr<EndpointClient>> GetServerClient();
ResponseContext& response) override;
private: private:
// FIXME: Separate this to its own service. glcr::UniquePtr<EndpointServer> server_;
PortServer register_port_; PortServer register_port_;
static const uint64_t kBufferSize = 128; static const uint64_t kBufferSize = 128;
@ -35,5 +36,5 @@ class YellowstoneServer : public EndpointServer {
PciReader pci_reader_; PciReader pci_reader_;
YellowstoneServer(z_cap_t endpoint_cap, PortServer port); YellowstoneServer(glcr::UniquePtr<EndpointServer> server, PortServer port);
}; };

View File

@ -106,6 +106,7 @@ SYS3(MemoryObjectCreatePhysical, uint64_t, paddr, uint64_t, size, z_cap_t*,
vmmo_cap); vmmo_cap);
SYS3(MemoryObjectCreateContiguous, uint64_t, size, z_cap_t*, vmmo_cap, SYS3(MemoryObjectCreateContiguous, uint64_t, size, z_cap_t*, vmmo_cap,
uint64_t*, paddr); uint64_t*, paddr);
SYS2(TempPcieConfigObjectCreate, z_cap_t*, vmmo_cap, uint64_t*, vmmo_size);
SYS2(ChannelCreate, z_cap_t*, channel1, z_cap_t*, channel2); SYS2(ChannelCreate, z_cap_t*, channel1, z_cap_t*, channel2);
SYS5(ChannelSend, z_cap_t, chan_cap, uint64_t, num_bytes, const void*, data, SYS5(ChannelSend, z_cap_t, chan_cap, uint64_t, num_bytes, const void*, data,

View File

@ -9,4 +9,3 @@ extern uint64_t gInitEndpointCap;
extern uint64_t gBootDenaliVmmoCap; extern uint64_t gBootDenaliVmmoCap;
extern uint64_t gBootVictoriaFallsVmmoCap; extern uint64_t gBootVictoriaFallsVmmoCap;
extern uint64_t gBootPciVmmoCap;

View File

@ -27,6 +27,8 @@ const uint64_t kZionMemoryObjectCreate = 0x30;
const uint64_t kZionMemoryObjectCreatePhysical = 0x31; const uint64_t kZionMemoryObjectCreatePhysical = 0x31;
const uint64_t kZionMemoryObjectCreateContiguous = 0x32; const uint64_t kZionMemoryObjectCreateContiguous = 0x32;
const uint64_t kZionTempPcieConfigObjectCreate = 0x3F;
// IPC Calls // IPC Calls
const uint64_t kZionChannelCreate = 0x40; const uint64_t kZionChannelCreate = 0x40;
const uint64_t kZionChannelSend = 0x41; const uint64_t kZionChannelSend = 0x41;
@ -88,4 +90,3 @@ typedef uint64_t z_cap_t;
#define Z_BOOT_DENALI_VMMO 0x4200'0000 #define Z_BOOT_DENALI_VMMO 0x4200'0000
#define Z_BOOT_VICTORIA_FALLS_VMMO 0x4200'0001 #define Z_BOOT_VICTORIA_FALLS_VMMO 0x4200'0001
#define Z_BOOT_PCI_VMMO 0x4200'0002

View File

@ -3,7 +3,6 @@
#include <glacier/memory/ref_ptr.h> #include <glacier/memory/ref_ptr.h>
#include <glacier/string/string.h> #include <glacier/string/string.h>
#include "boot/acpi.h"
#include "boot/boot_info.h" #include "boot/boot_info.h"
#include "debug/debug.h" #include "debug/debug.h"
#include "include/zcall.h" #include "include/zcall.h"
@ -128,16 +127,6 @@ void WriteInitProgram(glcr::RefPtr<Port> port, glcr::String name, uint64_t id) {
MakeRefCounted<Capability>(prog_vmmo, ZC_READ | ZC_WRITE)); MakeRefCounted<Capability>(prog_vmmo, ZC_READ | ZC_WRITE));
} }
glcr::ErrorCode WritePciVmmo(glcr::RefPtr<Port> port, uint64_t id) {
ASSIGN_OR_RETURN(PcieConfiguration config, GetPciExtendedConfiguration());
auto vmmo =
glcr::MakeRefCounted<FixedMemoryObject>(config.base, config.offset);
port->WriteKernel(id, MakeRefCounted<Capability>(vmmo, ZC_READ | ZC_WRITE));
return glcr::OK;
}
} // namespace } // namespace
void LoadInitProgram() { void LoadInitProgram() {
@ -158,10 +147,6 @@ void LoadInitProgram() {
WriteInitProgram(port, "/sys/denali", Z_BOOT_DENALI_VMMO); WriteInitProgram(port, "/sys/denali", Z_BOOT_DENALI_VMMO);
WriteInitProgram(port, "/sys/victoriafalls", Z_BOOT_VICTORIA_FALLS_VMMO); WriteInitProgram(port, "/sys/victoriafalls", Z_BOOT_VICTORIA_FALLS_VMMO);
if (WritePciVmmo(port, Z_BOOT_PCI_VMMO) != glcr::OK) {
panic("Failed to provide PCI info to init.");
}
// Start process. // Start process.
const limine_file& init_prog = GetInitProgram("/sys/yellowstone"); const limine_file& init_prog = GetInitProgram("/sys/yellowstone");
uint64_t entry = LoadElfProgram( uint64_t entry = LoadElfProgram(

View File

@ -29,3 +29,14 @@ z_err_t MemoryObjectCreateContiguous(ZMemoryObjectCreateContiguousReq* req) {
*req->paddr = paddr; *req->paddr = paddr;
return glcr::OK; return glcr::OK;
} }
z_err_t TempPcieConfigObjectCreate(ZTempPcieConfigObjectCreateReq* req) {
auto& curr_proc = gScheduler->CurrentProcess();
ASSIGN_OR_RETURN(PcieConfiguration config, GetPciExtendedConfiguration());
auto vmmo_ref =
glcr::MakeRefCounted<FixedMemoryObject>(config.base, config.offset);
*req->vmmo_cap = curr_proc.AddNewCapability(
StaticCastRefPtr<MemoryObject>(vmmo_ref), ZC_WRITE);
*req->vmmo_size = config.offset;
return glcr::OK;
}

View File

@ -5,3 +5,4 @@
z_err_t MemoryObjectCreate(ZMemoryObjectCreateReq* req); z_err_t MemoryObjectCreate(ZMemoryObjectCreateReq* req);
z_err_t MemoryObjectCreatePhysical(ZMemoryObjectCreatePhysicalReq* req); z_err_t MemoryObjectCreatePhysical(ZMemoryObjectCreatePhysicalReq* req);
z_err_t MemoryObjectCreateContiguous(ZMemoryObjectCreateContiguousReq* req); z_err_t MemoryObjectCreateContiguous(ZMemoryObjectCreateContiguousReq* req);
z_err_t TempPcieConfigObjectCreate(ZTempPcieConfigObjectCreateReq* req);

View File

@ -63,6 +63,7 @@ extern "C" z_err_t SyscallHandler(uint64_t call_id, void* req) {
CASE(MemoryObjectCreate); CASE(MemoryObjectCreate);
CASE(MemoryObjectCreatePhysical); CASE(MemoryObjectCreatePhysical);
CASE(MemoryObjectCreateContiguous); CASE(MemoryObjectCreateContiguous);
CASE(TempPcieConfigObjectCreate);
// syscall/ipc.h // syscall/ipc.h
CASE(ChannelCreate); CASE(ChannelCreate);
CASE(ChannelSend); CASE(ChannelSend);