Expand description
AHCI (Advanced Host Controller Interface) driver : AHCI spec 1.3.1
PCI: class=0x01 (Mass Storage), subclass=0x06 (SATA), prog_if=0x01 MMIO base: BAR5 (ABAR)
Per-port memory layout (packed into one 4 KB page): [0x000..0x3FF] Command List (1024 B, 32 Γ 32-byte headers) [0x400..0x4FF] FIS receive (256 B) [0x500..0x5FF] Command table (128 B header + 1 Γ 16-byte PRDT)
Β§IRQ-driven completion (DRV-02 v2)
When a task context exists (current_task_id() is Some), commands are
completed via interrupt + WaitQueue::wait_until() so the issuing task
blocks without busy-spinning. During early boot (no task yet) the legacy
polling path is used as a fallback.
Per-port statics (indexed by port_num 0..32) are used so the IRQ handler
can signal completion without acquiring any slow lock:
PORT_VIRT[n]: MMIO virtual address of port n registersPORT_SLOT0_DONE[n]: set by IRQ handler when slot-0 completesPORT_SLOT0_ERROR[n]: set by IRQ handler when a task-file error firesPORT_WQ[n]: WaitQueue; issuing task blocks here
Re-exportsΒ§
use crate::dma::DmaBuffer;πuse crate::hardware::pci_client as pci;πuse crate::hardware::pci_client::ProbeCriteria;πuse crate::memory;πuse crate::memory::phys_to_virt;πuse crate::memory::UserSliceRead;πuse crate::memory::UserSliceWrite;πuse crate::sync::SpinLock;πuse crate::sync::WaitQueue;πuse alloc::boxed::Box;πuse alloc::vec::Vec;πuse core::ptr;πuse core::sync::atomic::AtomicBool;πuse core::sync::atomic::AtomicU32;πuse core::sync::atomic::AtomicU64;πuse core::sync::atomic::AtomicU8;πuse core::sync::atomic::Ordering;πpub use super::virtio_block::BlockDevice;pub use super::virtio_block::BlockError;pub use super::virtio_block::SECTOR_SIZE;
StructsΒ§
EnumsΒ§
ConstantsΒ§
- ATA_
FLUSH_ πCACHE_ EXT - ATA_
IDENTIFY π - ATA_
READ_ πDMA_ EXT - ATA_
WRITE_ πDMA_ EXT - CLB_OFF π
- CMDH_
CTBA π - CMDH_
CTBAU π - CMDH_
FLAGS π - CMDH_
PRDTL π - CMD_CR π
- CMD_FR π
- CMD_FRE π
- CMD_ST π
- CTAB_
CFIS π - CTAB_
OFF π - CTAB_
PRDT π - EFAULT π
- FB_OFF π
- FIS_CMD π
- FIS_
CNT_ πHI - FIS_
CNT_ πLO - FIS_
C_ πBIT - FIS_
DEVICE π - FIS_
FLAGS π - FIS_
LBA0 π - FIS_
LBA1 π - FIS_
LBA2 π - FIS_
LBA3 π - FIS_
LBA4 π - FIS_
LBA5 π - FIS_
LBA_ πMODE - FIS_
TYPE π - FIS_
TYPE_ πH2D - GHC_AE π
- GHC_HR π
- GHC_IE π
- HBA_GHC π
- HBA_IS π
- HBA_PI π
- PORT_CI π
- PORT_
CLB π - PORT_
CLBU π - PORT_
CMD π - PORT_FB π
- PORT_
FBU π - PORT_IE π
- PORT_IS π
- PORT_
SERR π - PORT_
SIG π - PORT_
SSTS π - PORT_
TFD π - PXIE_
DHRE π - PXIE_
TFEE π - PXIS_
TFES π - SIG_
SATA π - SSTS_
DET_ πCOMM - SSTS_
DET_ πMASK - TFD_BSY π
- TFD_DRQ π
StaticsΒ§
- AHCI_
ABAR_ πVIRT - AHCI ABAR virtual address : written once during init, read by IRQ handler.
- AHCI_
IRQ_ LINE - PCI interrupt line used by this controller.
- AHCI_
PROBED π - Set once the bus has been scanned, whether or not a controller was found.
- AHCI_
PTR π - Leaked-Box pointer to the AHCI controller (valid for βstatic).
- PENDING_
ASYNC_ πREAD_ COMPLETIONS - PORT_
ASYNC_ πACTIVE - Whether an async operation is in-flight on this portβs slot 0.
- PORT_
ASYNC_ πBUF_ VADDR - User virtual address where read data must be copied (0 = write op).
- PORT_
ASYNC_ πDMA_ PTR - Raw pointer to a leaked
Box<DmaBuffer>held until IRQ completion. 0 means no buffer. Freed insidehandle_interrupt()viaBox::from_raw(). - PORT_
ASYNC_ πIS_ WRITE - Whether the in-flight async command is a write operation.
- PORT_
ASYNC_ πLEN - Number of bytes transferred.
- PORT_
ASYNC_ πRING_ ID - Ring id to push the completion CQE into (0 = no async pending).
- PORT_
ASYNC_ πUSER_ DATA - User-data token echoed in the completion CQE.
- PORT_
SLOT0_ πDONE - Per-port slot-0 completion flags : set by IRQ handler, cleared by consumer.
- PORT_
SLOT0_ πERROR - Per-port slot-0 error flags : set by IRQ handler on task-file error.
- PORT_
VIRT π - Per-port MMIO virtual addresses : written once during init.
- PORT_WQ π
- Per-port wait queues : tasks block here while waiting for IRQ completion.
FunctionsΒ§
- discard_
deferred_ πasync_ read_ completions - flush_
deferred_ πasync_ read_ completions - get_
device - Return a reference to the first usable AHCI controller, if any.
- handle_
interrupt - Called from the IDT AHCI IRQ handler.
- init
- Scan the PCI bus for an AHCI controller and initialise it.
- issue_
and_ πawait_ slot0 - Issues the command already staged in slot 0 and waits for completion.
- port_
enable_ πirq - Enable interrupts for a port (DHRE = DMA completion, TFEE = errors).
- port_
rebase π - Rebase port: assign our CLB/FB buffers then start the port.
- port_
start π - Performs the port start operation.
- port_
stop π - Performs the port stop operation.
- rd32 π β
- Performs the rd32 operation.
- submit_
async_ πcmd - Submit a command asynchronously ; returns immediately without blocking.
- submit_
async_ πstorage_ op - Public entry point called from
async_io::dispatch. - submit_
cmd π - Performs the submit cmd operation.
- submit_
flush π - Issues
FLUSH CACHE EXT(0xEA) and waits for the device acknowledgement. - wr32 π β
- Performs the wr32 operation.