Skip to main content

Module ahci

Module ahci 

Source
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 registers
  • PORT_SLOT0_DONE[n] : set by IRQ handler when slot-0 completes
  • PORT_SLOT0_ERROR[n]: set by IRQ handler when a task-file error fires
  • PORT_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Β§

AhciController
AhciPort πŸ”’
PendingAsyncReadCompletion πŸ”’

EnumsΒ§

AhciError

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 inside handle_interrupt() via Box::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.