Skip to content

Commit

Permalink
feat(virtio-spec): add NotificationData
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Jun 1, 2024
1 parent 24cd07f commit fe57c41
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions virtio-spec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ keywords = ["virtio", "driver", "volatile"]
categories = ["no-std", "no-std::no-alloc"]

[dependencies]
bitfield-struct = "0.6"
bitflags = "2"
endian-num = { version = "0.1", features = ["bitflags", "linux-types"] }
volatile = { version = "0.5.3", features = ["derive"] }
Expand Down
31 changes: 31 additions & 0 deletions virtio-spec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub mod mmio;
pub mod net;
pub mod pci;

use bitfield_struct::bitfield;
pub use endian_num::{be128, be16, be32, be64, le128, le16, le32, le64};

pub use self::features::{FeatureBits, F};
Expand Down Expand Up @@ -73,3 +74,33 @@ virtio_bitflags! {
const DEVICE_NEEDS_RESET = 64;
}
}

/// Notification Data.
#[bitfield(u32, inner = le32, from = le32::from_ne, into = le32::to_ne)]
pub struct NotificationData {
/// VQ number to be notified.
pub vqn: u16,

/// Offset
/// within the ring where the next available ring entry
/// will be written.
/// When [`VIRTIO_F_RING_PACKED`] has not been negotiated this refers to the
/// 15 least significant bits of the available index.
/// When `VIRTIO_F_RING_PACKED` has been negotiated this refers to the offset
/// (in units of descriptor entries)
/// within the descriptor ring where the next available
/// descriptor will be written.
///
/// [`VIRTIO_F_RING_PACKED`]: F::RING_PACKED
#[bits(15)]
pub next_off: u16,

/// Wrap Counter.
/// With [`VIRTIO_F_RING_PACKED`] this is the wrap counter
/// referring to the next available descriptor.
/// Without `VIRTIO_F_RING_PACKED` this is the most significant bit
/// (bit 15) of the available index.
///
/// [`VIRTIO_F_RING_PACKED`]: F::RING_PACKED
pub next_wrap: bool,
}

0 comments on commit fe57c41

Please sign in to comment.