Implement read_many for denali.

This commit is contained in:
Drew Galbraith 2025-02-01 14:09:28 -08:00
parent 5ec05f9a88
commit 49c3ff8499
2 changed files with 36 additions and 3 deletions

View File

@ -285,6 +285,16 @@ impl Command {
})
}
pub fn read_manual(lba: u64, lba_count: u16, paddr: u64) -> Self {
Self {
command: SataCommand::DmaReadExt,
lba,
sector_cnt: lba_count,
paddr: paddr,
memory_region: None,
}
}
pub fn release_mem_cap(&mut self) -> u64 {
self.memory_region.take().unwrap().release()
}

View File

@ -1,5 +1,5 @@
use alloc::sync::Arc;
use mammoth::zion::ZError;
use mammoth::{syscall, zion::ZError};
use crate::{
ahci::{AhciController, Command},
@ -32,7 +32,30 @@ impl AsyncDenaliServerHandler for DenaliServerImpl {
})
}
async fn read_many(&self, _req: ReadManyRequest) -> Result<ReadResponse, ZError> {
Err(ZError::UNIMPLEMENTED)
async fn read_many(&self, req: ReadManyRequest) -> Result<ReadResponse, ZError> {
let total_sector_cnt = req.blocks.iter().map(|b| b.size).sum();
// FIXME: Don't hardcode this.
let sector_size = 512;
let (mem_cap, mut paddr) =
syscall::memory_object_contiguous_physical(sector_size * total_sector_cnt)?;
for block in req.blocks {
let command = Command::read_manual(block.lba, block.size as u16, paddr);
// TODO: We should actually be able to read all of these in parallel.
self.ahci_controller
.issue_command(req.device_id as usize, &command)
.await;
paddr += block.size * sector_size;
}
Ok(ReadResponse {
device_id: req.device_id,
size: total_sector_cnt,
memory: mem_cap.release(),
})
}
}