axdevice_base 0.7.0

Basic traits and structures for emulated devices in ArceOS hypervisor.
Documentation
//! Strongly typed interrupt endpoint identifiers.

/// Trigger semantics of one wired interrupt input.
pub type InterruptTrigger = axvm_types::InterruptTriggerMode;

/// Identifies an interrupt controller within one virtual machine.
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct InterruptControllerId(usize);

impl InterruptControllerId {
    /// Creates a controller identifier from its VM-local numeric value.
    pub const fn new(value: usize) -> Self {
        Self(value)
    }

    /// Returns the VM-local numeric value.
    pub const fn value(self) -> usize {
        self.0
    }
}

/// Identifies one hardware input on an interrupt controller.
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct ControllerInputId(usize);

impl ControllerInputId {
    /// Creates a controller-input identifier.
    pub const fn new(value: usize) -> Self {
        Self(value)
    }

    /// Returns the controller-local hardware input number.
    pub const fn value(self) -> usize {
        self.0
    }
}

/// Identifies one physical interrupt in the host interrupt namespace.
///
/// A [`HostIrqId`] must never be used as a guest controller input without an
/// explicit platform mapping.
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct HostIrqId(usize);

impl HostIrqId {
    /// Creates a host IRQ identifier.
    pub const fn new(value: usize) -> Self {
        Self(value)
    }

    /// Returns the host interrupt-domain number.
    pub const fn value(self) -> usize {
        self.0
    }
}

/// Identifies one ITS instance within a virtual machine.
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct ItsId(u32);

impl ItsId {
    /// Creates an ITS identifier.
    pub const fn new(value: u32) -> Self {
        Self(value)
    }

    /// Returns the VM-local ITS number.
    pub const fn value(self) -> u32 {
        self.0
    }
}

/// Identifies one LPI in a virtual interrupt controller.
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct LpiId(u32);

impl LpiId {
    /// Creates an LPI identifier.
    pub const fn new(value: u32) -> Self {
        Self(value)
    }

    /// Returns the guest-visible LPI INTID.
    pub const fn value(self) -> u32 {
        self.0
    }
}

/// Declares whether multiple independently owned sources may use one wired
/// controller input.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum InterruptSharing {
    /// Exactly one planned source may own the controller input.
    Exclusive,
    /// Multiple planned sources may share the input using wired-OR semantics.
    Shared,
}

/// Identifies one device connection to a controller input.
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct InterruptSourceId(u64);

impl InterruptSourceId {
    pub(crate) const fn new(value: u64) -> Self {
        Self(value)
    }

    /// Returns the input-local source number.
    pub const fn value(self) -> u64 {
        self.0
    }
}

/// Identifies an MSI-producing device in a message interrupt domain.
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct MsiDeviceId(u32);

impl MsiDeviceId {
    /// Creates an MSI device identifier.
    pub const fn new(value: u32) -> Self {
        Self(value)
    }

    /// Returns the controller-local device number.
    pub const fn value(self) -> u32 {
        self.0
    }
}

/// Identifies an event generated by an MSI-producing device.
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct MsiEventId(u32);

impl MsiEventId {
    /// Creates an MSI event identifier.
    pub const fn new(value: u32) -> Self {
        Self(value)
    }

    /// Returns the device-local event number.
    pub const fn value(self) -> u32 {
        self.0
    }
}

/// Pinpoints the interrupt endpoint involved in an operation.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum InterruptEndpoint {
    /// The operation concerns the controller as a whole.
    Controller(InterruptControllerId),
    /// The operation concerns a wired controller input.
    Wired {
        /// Controller owning the input.
        controller: InterruptControllerId,
        /// Controller-local input number.
        input: ControllerInputId,
    },
    /// The operation concerns an MSI device event.
    Message {
        /// Controller receiving the message.
        controller: InterruptControllerId,
        /// ITS instance receiving the message.
        its: ItsId,
        /// MSI-producing device.
        device: MsiDeviceId,
        /// Device-local event.
        event: MsiEventId,
        /// Planner-reserved LPI associated with the event.
        lpi: LpiId,
    },
}