acadia/sys/denali/denali_server.cpp

57 lines
1.6 KiB
C++
Raw Normal View History

2023-06-15 16:20:29 -07:00
#include "denali_server.h"
#include <glacier/memory/move.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>
glcr::ErrorOr<glcr::UniquePtr<DenaliServer>> DenaliServer::Create(
AhciDriver& driver) {
z_cap_t cap;
RET_ERR(ZEndpointCreate(&cap));
return glcr::UniquePtr<DenaliServer>(new DenaliServer(cap, driver));
}
2023-06-15 16:20:29 -07:00
glcr::ErrorCode DenaliServer::HandleRequest(RequestContext& request,
ResponseContext& response) {
switch (request.request_id()) {
case DENALI_READ: {
DenaliReadRequest* req = 0;
glcr::ErrorCode err = request.As<DenaliReadRequest>(&req);
if (err != glcr::OK) {
response.WriteError(err);
}
err = HandleRead(req, response);
if (err != glcr::OK) {
response.WriteError(err);
2023-06-15 16:20:29 -07:00
}
break;
2023-06-15 16:20:29 -07:00
}
default:
response.WriteError(glcr::UNIMPLEMENTED);
break;
2023-06-15 16:20:29 -07:00
}
return glcr::OK;
2023-06-15 16:20:29 -07:00
}
glcr::ErrorCode DenaliServer::HandleRead(DenaliReadRequest* request,
ResponseContext& context) {
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(request->device_id));
ASSIGN_OR_RETURN(Mutex mutex, Mutex::Create());
RET_ERR(mutex.Lock());
DmaReadCommand command(request->lba, request->size, mutex, context);
device->IssueCommand(&command);
// Wait for read operation to complete.
RET_ERR(mutex.Lock());
RET_ERR(mutex.Release());
DenaliReadResponse resp{
.device_id = request->device_id,
.lba = request->lba,
.size = request->size,
};
return context.WriteStructWithCap<DenaliReadResponse>(
resp, command.GetMemoryRegion());
}