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-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()));
|
2023-06-16 01:31:23 -07:00
|
|
|
|
2023-11-19 20:42:38 -08:00
|
|
|
uint64_t paddr;
|
|
|
|
OwnedMemoryRegion region =
|
|
|
|
OwnedMemoryRegion::ContiguousPhysical(req.size() * 512, &paddr);
|
2023-11-15 09:47:32 -08:00
|
|
|
|
2023-11-22 10:56:07 -08:00
|
|
|
DmaReadCommand command(req.lba(), req.size(), paddr);
|
2023-10-25 19:39:09 -07:00
|
|
|
device->IssueCommand(&command);
|
2023-06-16 01:31:23 -07:00
|
|
|
|
2023-11-22 10:56:07 -08:00
|
|
|
command.WaitComplete();
|
2023-10-25 20:28:28 -07:00
|
|
|
|
|
|
|
resp.set_device_id(req.device_id());
|
|
|
|
resp.set_size(req.size());
|
2023-11-19 20:42:38 -08:00
|
|
|
resp.set_memory(region.DuplicateCap());
|
2023-11-15 09:47:32 -08:00
|
|
|
return glcr::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
glcr::ErrorCode DenaliServer::HandleReadMany(const ReadManyRequest& req,
|
|
|
|
ReadResponse& resp) {
|
|
|
|
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(req.device_id()));
|
|
|
|
|
2023-11-19 20:42:38 -08:00
|
|
|
uint64_t region_paddr;
|
|
|
|
OwnedMemoryRegion region = OwnedMemoryRegion::ContiguousPhysical(
|
|
|
|
req.lba().size() * 512, ®ion_paddr);
|
2023-11-15 09:47:32 -08:00
|
|
|
|
|
|
|
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;
|
2023-11-19 20:42:38 -08:00
|
|
|
uint64_t paddr = region_paddr + curr_run_start * 512;
|
2023-11-22 10:56:07 -08:00
|
|
|
DmaReadCommand command(lba, size, paddr);
|
2023-11-15 09:47:32 -08:00
|
|
|
device->IssueCommand(&command);
|
2023-11-22 10:56:07 -08:00
|
|
|
command.WaitComplete();
|
2023-11-15 09:47:32 -08:00
|
|
|
|
|
|
|
curr_run_start = i + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.set_device_id(req.device_id());
|
|
|
|
resp.set_size(req.lba().size());
|
2023-11-19 20:42:38 -08:00
|
|
|
resp.set_memory(region.DuplicateCap());
|
2023-10-25 20:28:28 -07:00
|
|
|
return glcr::OK;
|
2023-06-16 01:31:23 -07:00
|
|
|
}
|