2023-06-15 16:20:29 -07:00
|
|
|
#include "denali_server.h"
|
|
|
|
|
2023-06-21 18:28:54 -07:00
|
|
|
#include <glacier/status/error.h>
|
2023-06-15 16:20:29 -07:00
|
|
|
#include <mammoth/debug.h>
|
|
|
|
#include <zcall.h>
|
|
|
|
|
2023-06-16 01:31:23 -07:00
|
|
|
namespace {
|
|
|
|
DenaliServer* gServer = nullptr;
|
2023-06-21 23:14:42 -07:00
|
|
|
void HandleResponse(z_cap_t reply_port, uint64_t lba, uint64_t size,
|
|
|
|
z_cap_t mem) {
|
|
|
|
gServer->HandleResponse(reply_port, lba, size, mem);
|
2023-06-16 01:31:23 -07:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2023-06-21 23:14:42 -07:00
|
|
|
DenaliServer::DenaliServer(EndpointServer server, AhciDriver& driver)
|
|
|
|
: server_(server), driver_(driver) {
|
2023-06-16 01:31:23 -07:00
|
|
|
gServer = this;
|
|
|
|
}
|
2023-06-15 16:20:29 -07:00
|
|
|
|
2023-06-21 18:38:11 -07:00
|
|
|
glcr::ErrorCode DenaliServer::RunServer() {
|
2023-06-15 16:20:29 -07:00
|
|
|
while (true) {
|
|
|
|
uint64_t buff_size = kBuffSize;
|
2023-06-21 23:14:42 -07:00
|
|
|
z_cap_t reply_port;
|
|
|
|
RET_ERR(server_.Recieve(&buff_size, read_buffer_, &reply_port));
|
2023-06-17 02:01:21 -07:00
|
|
|
if (buff_size < sizeof(uint64_t)) {
|
|
|
|
dbgln("Skipping invalid message");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
uint64_t type = *reinterpret_cast<uint64_t*>(read_buffer_);
|
2023-06-15 16:20:29 -07:00
|
|
|
switch (type) {
|
|
|
|
case Z_INVALID:
|
|
|
|
dbgln(reinterpret_cast<char*>(read_buffer_));
|
|
|
|
break;
|
|
|
|
case DENALI_READ: {
|
|
|
|
DenaliRead* read_req = reinterpret_cast<DenaliRead*>(read_buffer_);
|
|
|
|
uint64_t memcap = 0;
|
2023-06-21 23:14:42 -07:00
|
|
|
RET_ERR(HandleRead(*read_req, reply_port));
|
2023-06-15 16:20:29 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
dbgln("Invalid message type.");
|
2023-06-21 18:28:54 -07:00
|
|
|
return glcr::UNIMPLEMENTED;
|
2023-06-15 16:20:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-21 23:14:42 -07:00
|
|
|
glcr::ErrorCode DenaliServer::HandleRead(const DenaliRead& read,
|
|
|
|
z_cap_t reply_port) {
|
2023-06-21 18:38:11 -07:00
|
|
|
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(read.device_id));
|
2023-06-16 01:31:23 -07:00
|
|
|
|
|
|
|
device->IssueCommand(
|
2023-06-21 23:14:42 -07:00
|
|
|
new DmaReadCommand(read.lba, read.size, ::HandleResponse, reply_port));
|
2023-06-15 16:20:29 -07:00
|
|
|
|
2023-06-21 18:28:54 -07:00
|
|
|
return glcr::OK;
|
2023-06-15 16:20:29 -07:00
|
|
|
}
|
2023-06-16 01:31:23 -07:00
|
|
|
|
2023-06-21 23:14:42 -07:00
|
|
|
void DenaliServer::HandleResponse(z_cap_t reply_port, uint64_t lba,
|
|
|
|
uint64_t size, z_cap_t mem) {
|
2023-06-16 01:31:23 -07:00
|
|
|
DenaliReadResponse resp{
|
|
|
|
.device_id = 0,
|
|
|
|
.lba = lba,
|
|
|
|
.size = size,
|
|
|
|
};
|
2023-06-21 23:14:42 -07:00
|
|
|
check(ZReplyPortSend(reply_port, sizeof(resp), &resp, 1, &mem));
|
2023-06-16 01:31:23 -07:00
|
|
|
}
|