acadia/sys/denali/denali_server.cpp

60 lines
1.8 KiB
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>
#include <mammoth/util/debug.h>
2023-06-15 16:20:29 -07:00
#include <zcall.h>
glcr::ErrorOr<glcr::UniquePtr<DenaliServer>> DenaliServer::Create(
AhciController& 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-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()));
uint64_t paddr;
mmth::OwnedMemoryRegion region = mmth::OwnedMemoryRegion::ContiguousPhysical(
req.block().size() * 512, &paddr);
ASSIGN_OR_RETURN(
auto semaphore,
device->IssueRead(req.block().lba(), req.block().size(), paddr));
semaphore->Wait();
2023-10-25 20:28:28 -07:00
resp.set_device_id(req.device_id());
resp.set_size(req.block().size());
resp.set_memory(region.DuplicateCap());
2023-12-01 10:23:54 -08:00
return glcr::Status::Ok();
}
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()));
uint64_t sector_cnt = 0;
for (auto& block : req.blocks()) {
sector_cnt += block.size();
}
uint64_t region_paddr;
mmth::OwnedMemoryRegion region = mmth::OwnedMemoryRegion::ContiguousPhysical(
sector_cnt * 512, &region_paddr);
for (auto& block : req.blocks()) {
ASSIGN_OR_RETURN(
auto semaphore,
device->IssueRead(block.lba(), block.size(), region_paddr));
semaphore->Wait();
region_paddr += block.size() * 512;
}
resp.set_device_id(req.device_id());
resp.set_size(sector_cnt);
resp.set_memory(region.DuplicateCap());
2023-12-01 10:23:54 -08:00
return glcr::Status::Ok();
}