acadia/sys/denali/denali_server.cpp

34 lines
988 B
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
2023-10-25 20:28:28 -07:00
glcr::ErrorCode DenaliServer::HandleRead(const ReadRequest& req,
ReadResponse& resp) {
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(req.device_id()));
ASSIGN_OR_RETURN(Mutex mutex, Mutex::Create());
RET_ERR(mutex.Lock());
2023-10-25 20:28:28 -07:00
DmaReadCommand command(req.lba(), req.size(), mutex);
device->IssueCommand(&command);
// Wait for read operation to complete.
RET_ERR(mutex.Lock());
RET_ERR(mutex.Release());
2023-10-25 20:28:28 -07:00
resp.set_device_id(req.device_id());
resp.set_lba(req.lba());
resp.set_size(req.size());
resp.set_memory(command.GetMemoryRegion());
return glcr::OK;
}