Skip to content

Commit

Permalink
feat(virtio-spec): add mmio::InterruptStatus
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed May 29, 2024
1 parent 6d8c840 commit 01a16bd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
28 changes: 17 additions & 11 deletions virtio-spec/src/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,10 @@ device_register_impl! {
///
/// Reading from this register returns a bit mask of events that
/// caused the device interrupt to be asserted.
/// The following events are possible:
///
/// - Used Buffer Notification
/// - bit 0 - the interrupt was asserted
/// because the device has used a buffer
/// in at least one of the active virtual queues.
/// - Configuration Change Notification
/// - bit 1 - the interrupt was
/// asserted because the configuration of the device has changed.
#[doc(alias = "InterruptStatus")]
#[offset(0x060)]
#[access(ReadOnly)]
interrupt_status: le32,
interrupt_status: InterruptStatus,

/// Interrupt acknowledge
///
Expand All @@ -294,7 +285,7 @@ device_register_impl! {
#[doc(alias = "InterruptACK")]
#[offset(0x064)]
#[access(WriteOnly)]
interrupt_ack: le32,
interrupt_ack: InterruptStatus,

/// Device status
///
Expand Down Expand Up @@ -528,3 +519,18 @@ impl_wide_field_access! {
shm_base: shm_base_low, shm_base_high;
}
}

virtio_bitflags! {
/// Interrupt Status
pub struct InterruptStatus: u8 {
/// Used Buffer Notification
///
/// The interrupt was asserted because the device has used a buffer in at least one of the active virtual queues.
const USED_BUFFER_NOTIFICATION = 1 << 0;

/// Configuration Change Notification
///
/// The interrupt was asserted because the configuration of the device has changed.
const CONFIGURATION_CHANGE_NOTIFICATION = 1 << 1;
}
}
13 changes: 13 additions & 0 deletions virtio-spec/src/volatile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use core::marker::PhantomData;
use volatile::access::{Readable, Writable};
use volatile::VolatilePtr;

use crate::mmio::InterruptStatus;
use crate::{be32, be64, le16, le32, le64, DeviceStatus};

/// A wide volatile pointer for 64-bit fields.
Expand Down Expand Up @@ -272,7 +273,18 @@ impl OveralignedField<le32> for DeviceStatus {
}
}

impl OveralignedField<le32> for InterruptStatus {
fn from_field(field: le32) -> Self {
Self::from_bits_retain(u8::from_field(field))
}

fn into_field(self) -> le32 {
self.bits().into_field()
}
}

mod private {
use crate::mmio::InterruptStatus;
use crate::{le16, le32, DeviceStatus};

pub trait Sealed<T> {}
Expand All @@ -281,4 +293,5 @@ mod private {
impl Sealed<le32> for u8 {}
impl Sealed<le32> for le16 {}
impl Sealed<le32> for DeviceStatus {}
impl Sealed<le32> for InterruptStatus {}
}

0 comments on commit 01a16bd

Please sign in to comment.