2023-06-15 16:20:29 -07:00
|
|
|
#include "denali_server.h"
|
|
|
|
|
2023-06-26 11:38:17 -07:00
|
|
|
#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>
|
|
|
|
|
2023-08-01 15:52:08 -07:00
|
|
|
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-16 01:31:23 -07:00
|
|
|
}
|
2023-06-15 16:20:29 -07:00
|
|
|
|
2023-08-01 15:52:08 -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
|
|
|
}
|
2023-08-01 15:52:08 -07:00
|
|
|
break;
|
2023-06-15 16:20:29 -07:00
|
|
|
}
|
2023-08-01 15:52:08 -07:00
|
|
|
default:
|
|
|
|
response.WriteError(glcr::UNIMPLEMENTED);
|
|
|
|
break;
|
2023-06-15 16:20:29 -07:00
|
|
|
}
|
2023-08-01 15:52:08 -07:00
|
|
|
return glcr::OK;
|
2023-06-15 16:20:29 -07:00
|
|
|
}
|
|
|
|
|
2023-08-01 15:52:08 -07:00
|
|
|
glcr::ErrorCode DenaliServer::HandleRead(DenaliReadRequest* request,
|
|
|
|
ResponseContext& context) {
|
|
|
|
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(request->device_id));
|
2023-10-25 19:39:09 -07:00
|
|
|
ASSIGN_OR_RETURN(Mutex mutex, Mutex::Create());
|
|
|
|
RET_ERR(mutex.Lock());
|
2023-06-16 01:31:23 -07:00
|
|
|
|
2023-10-25 19:39:09 -07:00
|
|
|
DmaReadCommand command(request->lba, request->size, mutex, context);
|
|
|
|
device->IssueCommand(&command);
|
2023-06-16 01:31:23 -07:00
|
|
|
|
2023-10-25 19:39:09 -07:00
|
|
|
// Wait for read operation to complete.
|
|
|
|
RET_ERR(mutex.Lock());
|
|
|
|
RET_ERR(mutex.Release());
|
2023-06-16 01:31:23 -07:00
|
|
|
DenaliReadResponse resp{
|
2023-10-25 19:39:09 -07:00
|
|
|
.device_id = request->device_id,
|
|
|
|
.lba = request->lba,
|
|
|
|
.size = request->size,
|
2023-06-16 01:31:23 -07:00
|
|
|
};
|
2023-10-25 19:39:09 -07:00
|
|
|
return context.WriteStructWithCap<DenaliReadResponse>(
|
|
|
|
resp, command.GetMemoryRegion());
|
2023-06-16 01:31:23 -07:00
|
|
|
}
|