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-11-22 14:39:27 -08:00
|
|
|
#include <mammoth/util/debug.h>
|
2023-06-15 16:20:29 -07:00
|
|
|
#include <zcall.h>
|
|
|
|
|
2023-08-01 15:52:08 -07:00
|
|
|
glcr::ErrorOr<glcr::UniquePtr<DenaliServer>> DenaliServer::Create(
|
2023-12-07 22:33:29 -08:00
|
|
|
AhciController& driver) {
|
2023-08-01 15:52:08 -07:00
|
|
|
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-12-01 10:23:54 -08:00
|
|
|
glcr::Status DenaliServer::HandleRead(const ReadRequest& req,
|
|
|
|
ReadResponse& resp) {
|
2023-12-08 14:30:08 -08:00
|
|
|
ASSIGN_OR_RETURN(AhciPort * 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;
|
2024-01-11 21:32:08 -08:00
|
|
|
mmth::OwnedMemoryRegion region = mmth::OwnedMemoryRegion::ContiguousPhysical(
|
|
|
|
req.block().size() * 512, &paddr);
|
2023-11-15 09:47:32 -08:00
|
|
|
|
2024-01-11 21:32:08 -08:00
|
|
|
ASSIGN_OR_RETURN(
|
|
|
|
auto semaphore,
|
|
|
|
device->IssueRead(req.block().lba(), req.block().size(), paddr));
|
2023-12-08 14:43:29 -08:00
|
|
|
semaphore->Wait();
|
2023-10-25 20:28:28 -07:00
|
|
|
|
|
|
|
resp.set_device_id(req.device_id());
|
2024-01-11 21:32:08 -08:00
|
|
|
resp.set_size(req.block().size());
|
2023-11-19 20:42:38 -08:00
|
|
|
resp.set_memory(region.DuplicateCap());
|
2023-12-01 10:23:54 -08:00
|
|
|
return glcr::Status::Ok();
|
2023-11-15 09:47:32 -08:00
|
|
|
}
|
|
|
|
|
2023-12-01 10:23:54 -08:00
|
|
|
glcr::Status DenaliServer::HandleReadMany(const ReadManyRequest& req,
|
|
|
|
ReadResponse& resp) {
|
2023-12-08 14:30:08 -08:00
|
|
|
ASSIGN_OR_RETURN(AhciPort * device, driver_.GetDevice(req.device_id()));
|
2023-11-15 09:47:32 -08:00
|
|
|
|
2023-11-22 12:17:56 -08:00
|
|
|
uint64_t sector_cnt = 0;
|
2024-01-11 22:09:42 -08:00
|
|
|
for (auto& block : req.blocks()) {
|
|
|
|
sector_cnt += block.size();
|
2023-11-22 12:17:56 -08:00
|
|
|
}
|
2023-11-19 20:42:38 -08:00
|
|
|
uint64_t region_paddr;
|
2023-11-22 14:59:41 -08:00
|
|
|
mmth::OwnedMemoryRegion region = mmth::OwnedMemoryRegion::ContiguousPhysical(
|
|
|
|
sector_cnt * 512, ®ion_paddr);
|
2023-11-22 12:17:56 -08:00
|
|
|
|
2024-01-11 22:09:42 -08:00
|
|
|
for (auto& block : req.blocks()) {
|
|
|
|
ASSIGN_OR_RETURN(
|
|
|
|
auto semaphore,
|
|
|
|
device->IssueRead(block.lba(), block.size(), region_paddr));
|
2023-12-08 14:43:29 -08:00
|
|
|
semaphore->Wait();
|
2023-11-15 09:47:32 -08:00
|
|
|
|
2024-01-11 22:09:42 -08:00
|
|
|
region_paddr += block.size() * 512;
|
2023-11-15 09:47:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
resp.set_device_id(req.device_id());
|
2023-11-22 12:17:56 -08:00
|
|
|
resp.set_size(sector_cnt);
|
2023-11-19 20:42:38 -08:00
|
|
|
resp.set_memory(region.DuplicateCap());
|
2023-12-01 10:23:54 -08:00
|
|
|
return glcr::Status::Ok();
|
2023-06-16 01:31:23 -07:00
|
|
|
}
|