Run denali server thread.
This commit is contained in:
parent
10e536acab
commit
a5cdd23f0b
7 changed files with 104 additions and 19 deletions
|
|
@ -9,6 +9,7 @@ use alloc::boxed::Box;
|
|||
use alloc::sync::Arc;
|
||||
use mammoth::cap::Capability;
|
||||
use mammoth::sync::Mutex;
|
||||
use mammoth::syscall;
|
||||
use mammoth::{mem, thread};
|
||||
|
||||
use mammoth::{mem::MemoryRegion, zion::ZError};
|
||||
|
|
@ -141,10 +142,12 @@ impl AhciController {
|
|||
for port in self.ports.iter().flatten() {
|
||||
let sig = port.get_signature();
|
||||
if sig == 0x101 {
|
||||
let command = Command::identify()?;
|
||||
let mut command = Command::identify()?;
|
||||
mammoth::debug!("IDENT!");
|
||||
port.issue_command(&command)?.await;
|
||||
let ident = command.memory_region.slice::<u16>();
|
||||
let memory_region =
|
||||
MemoryRegion::from_cap(Capability::take(command.release_mem_cap()))?;
|
||||
let ident = memory_region.slice::<u16>();
|
||||
let new_sector_size = if ident[106] & (1 << 12) != 0 {
|
||||
ident[117] as u32 | ((ident[118] as u32) << 16)
|
||||
} else {
|
||||
|
|
@ -170,6 +173,18 @@ impl AhciController {
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn issue_command(&self, port_num: usize, command: &Command) -> Result<(), ZError> {
|
||||
assert!(port_num < 32);
|
||||
|
||||
self.ports[port_num]
|
||||
.as_ref()
|
||||
.ok_or(ZError::INVALID_ARGUMENT)?
|
||||
.issue_command(command)?
|
||||
.await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn spawn_irq_thread(controller: Arc<AhciController>) -> thread::JoinHandle {
|
||||
|
|
@ -202,11 +217,11 @@ enum CommandStatus {
|
|||
|
||||
struct CommandFuture {
|
||||
status: Arc<Mutex<CommandStatus>>,
|
||||
trigger: Box<dyn Fn() + Sync>,
|
||||
trigger: Box<dyn Fn() + Sync + Send>,
|
||||
}
|
||||
|
||||
impl CommandFuture {
|
||||
fn new(status: Arc<Mutex<CommandStatus>>, trigger: Box<dyn Fn() + Sync>) -> Self {
|
||||
fn new(status: Arc<Mutex<CommandStatus>>, trigger: Box<dyn Fn() + Sync + Send>) -> Self {
|
||||
Self { status, trigger }
|
||||
}
|
||||
}
|
||||
|
|
@ -236,28 +251,44 @@ impl Future for CommandFuture {
|
|||
}
|
||||
}
|
||||
|
||||
struct Command {
|
||||
pub struct Command {
|
||||
command: SataCommand,
|
||||
lba: u64,
|
||||
sector_cnt: u16,
|
||||
paddr: u64,
|
||||
|
||||
#[allow(dead_code)] // We need to own this even if we never access it.
|
||||
memory_region: MemoryRegion,
|
||||
memory_region: Option<Capability>,
|
||||
}
|
||||
|
||||
impl Command {
|
||||
pub fn identify() -> Result<Self, ZError> {
|
||||
let (memory_region, paddr) = MemoryRegion::contiguous_physical(512)?;
|
||||
let (memory_region, paddr) = syscall::memory_object_contiguous_physical(512)?;
|
||||
|
||||
Ok(Self {
|
||||
command: SataCommand::IdentifyDevice,
|
||||
lba: 0,
|
||||
sector_cnt: 1,
|
||||
paddr,
|
||||
memory_region,
|
||||
memory_region: Some(memory_region),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn read(lba: u64, lba_count: u16) -> Result<Self, ZError> {
|
||||
let (memory_region, paddr) =
|
||||
syscall::memory_object_contiguous_physical(512 * (lba_count as u64))?;
|
||||
|
||||
Ok(Self {
|
||||
command: SataCommand::DmaReadExt,
|
||||
lba,
|
||||
sector_cnt: lba_count,
|
||||
paddr,
|
||||
memory_region: Some(memory_region),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn release_mem_cap(&mut self) -> u64 {
|
||||
self.memory_region.take().unwrap().release()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Command> for HostToDeviceRegisterFis {
|
||||
|
|
|
|||
|
|
@ -6,3 +6,4 @@ mod port;
|
|||
pub use controller::identify_ports;
|
||||
pub use controller::spawn_irq_thread;
|
||||
pub use controller::AhciController;
|
||||
pub use controller::Command;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue