#include "denali_server.h" #include #include #include #include glcr::ErrorOr> DenaliServer::Create( AhciDriver& driver) { z_cap_t cap; RET_ERR(ZEndpointCreate(&cap)); return glcr::UniquePtr(new DenaliServer(cap, driver)); } 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()); MappedMemoryRegion region = MappedMemoryRegion::ContiguousPhysical(req.size() * 512); DmaReadCommand command(req.lba(), req.size(), region.paddr(), mutex); device->IssueCommand(&command); // Wait for read operation to complete. RET_ERR(mutex.Lock()); RET_ERR(mutex.Release()); resp.set_device_id(req.device_id()); resp.set_size(req.size()); resp.set_memory(region.cap()); return glcr::OK; } glcr::ErrorCode DenaliServer::HandleReadMany(const ReadManyRequest& req, ReadResponse& resp) { ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(req.device_id())); ASSIGN_OR_RETURN(Mutex mutex, Mutex::Create()); RET_ERR(mutex.Lock()); MappedMemoryRegion region = MappedMemoryRegion::ContiguousPhysical(req.lba().size() * 512); auto& vec = req.lba(); uint64_t curr_run_start = 0; for (uint64_t i = 0; i < vec.size(); i++) { if (i + 1 < vec.size() && vec.at(i) + 1 == vec.at(i + 1)) { continue; } uint64_t lba = vec.at(curr_run_start); uint64_t size = (i - curr_run_start) + 1; uint64_t paddr = region.paddr() + curr_run_start * 512; DmaReadCommand command(lba, size, paddr, mutex); device->IssueCommand(&command); // Wait for read operation to complete. RET_ERR(mutex.Lock()); curr_run_start = i + 1; } resp.set_device_id(req.device_id()); resp.set_size(req.lba().size()); resp.set_memory(region.cap()); return glcr::OK; }