⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

AhciPort

Struct AhciPort 

Source
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: u8

Port number (0-31).

§port_mmio_base: usize

Base address for this port’s MMIO registers.

§device_type: AhciDeviceType

Device type detected on this port.

§state: PortState

Current port state.

§num_cmd_slots: u8

Number of command slots supported by the HBA.

§ncq_supported: bool

Whether NCQ is supported by the HBA.

§total_sectors: u64

Total sectors reported by IDENTIFY DEVICE (0 until identified).

§sector_size: usize

Sector size in bytes (default 512).

Implementations§

Source§

impl AhciPort

Source

pub fn new( port_num: u8, hba_mmio_base: usize, num_cmd_slots: u8, ncq_supported: bool, ) -> Self

Create a new port descriptor.

Source

pub fn detect_device(&mut self)

Detect whether a device is present on this port.

Source

pub fn stop_cmd(&self) -> Result<(), KernelError>

Stop the port command engine (clear ST and FRE, wait for CR and FR to clear).

Source

pub fn start_cmd(&self)

Start the port command engine (set FRE then ST).

Source

pub fn clear_serr(&self)

Clear the port SERR register (write-1-to-clear all bits).

Source

pub fn clear_interrupt_status(&self)

Clear the port interrupt status register.

Source

pub fn wait_ready(&self) -> Result<(), KernelError>

Wait for the port to become not busy (TFD BSY and DRQ clear).

Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl Clone for AhciPort

Source§

fn clone(&self) -> AhciPort

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AhciPort

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for AhciPort

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 T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.