pub struct AhciPort {
pub port_num: u8,
pub port_mmio_base: usize,
pub device_type: AhciDeviceType,
pub state: PortState,
pub num_cmd_slots: u8,
pub ncq_supported: bool,
pub total_sectors: u64,
pub sector_size: usize,
}Expand description
Represents a single AHCI port with its state and device info.
Fields§
§port_num: u8Port number (0-31).
port_mmio_base: usizeBase address for this port’s MMIO registers.
device_type: AhciDeviceTypeDevice type detected on this port.
state: PortStateCurrent port state.
num_cmd_slots: u8Number of command slots supported by the HBA.
ncq_supported: boolWhether NCQ is supported by the HBA.
total_sectors: u64Total sectors reported by IDENTIFY DEVICE (0 until identified).
sector_size: usizeSector size in bytes (default 512).
Implementations§
Source§impl AhciPort
impl AhciPort
Sourcepub fn new(
port_num: u8,
hba_mmio_base: usize,
num_cmd_slots: u8,
ncq_supported: bool,
) -> Self
pub fn new( port_num: u8, hba_mmio_base: usize, num_cmd_slots: u8, ncq_supported: bool, ) -> Self
Create a new port descriptor.
Sourcepub fn detect_device(&mut self)
pub fn detect_device(&mut self)
Detect whether a device is present on this port.
Sourcepub fn stop_cmd(&self) -> Result<(), KernelError>
pub fn stop_cmd(&self) -> Result<(), KernelError>
Stop the port command engine (clear ST and FRE, wait for CR and FR to clear).
Sourcepub fn clear_serr(&self)
pub fn clear_serr(&self)
Clear the port SERR register (write-1-to-clear all bits).
Sourcepub fn clear_interrupt_status(&self)
pub fn clear_interrupt_status(&self)
Clear the port interrupt status register.
Sourcepub fn wait_ready(&self) -> Result<(), KernelError>
pub fn wait_ready(&self) -> Result<(), KernelError>
Wait for the port to become not busy (TFD BSY and DRQ clear).
Sourcepub fn find_free_slot(&self) -> Result<u8, KernelError>
pub fn find_free_slot(&self) -> Result<u8, KernelError>
Find a free command slot.
Returns the slot index (0-based), or an error if all slots are occupied.
Sourcepub fn issue_command_and_wait(&self, slot: u8) -> Result<(), KernelError>
pub fn issue_command_and_wait(&self, slot: u8) -> Result<(), KernelError>
Issue a command in the given slot and wait for completion.
Sets the corresponding bit in PORT_CI and polls until it clears or an error is detected in PORT_TFD.
Sourcepub fn build_read_dma_ext(
&self,
lba: u64,
sector_count: u16,
buffer_phys: u64,
) -> (CommandHeader, CommandTableHeader, PrdtEntry)
pub fn build_read_dma_ext( &self, lba: u64, sector_count: u16, buffer_phys: u64, ) -> (CommandHeader, CommandTableHeader, PrdtEntry)
Build and issue a READ DMA EXT command.
lba: Starting logical block address.
sector_count: Number of sectors to read (1-65535, 0 means 65536).
buffer_phys: Physical address of the destination buffer.
This prepares the FIS, command header, PRDT, and issues the command. In a production system, the command list and command tables would be allocated from DMA-capable memory; here we describe the operation structurally.
Sourcepub fn build_write_dma_ext(
&self,
lba: u64,
sector_count: u16,
buffer_phys: u64,
) -> (CommandHeader, CommandTableHeader, PrdtEntry)
pub fn build_write_dma_ext( &self, lba: u64, sector_count: u16, buffer_phys: u64, ) -> (CommandHeader, CommandTableHeader, PrdtEntry)
Build and issue a WRITE DMA EXT command.
lba: Starting logical block address.
sector_count: Number of sectors to write.
buffer_phys: Physical address of the source buffer.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AhciPort
impl RefUnwindSafe for AhciPort
impl Send for AhciPort
impl Sync for AhciPort
impl Unpin for AhciPort
impl UnwindSafe for AhciPort
Blanket Implementations§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)