Skip to content

Commit

Permalink
add virtio queue struct and flag
Browse files Browse the repository at this point in the history
  • Loading branch information
yodalee committed May 2, 2023
1 parent 6a636dd commit f97da1f
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/virtio/queue.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::header::VirtioHeader;
use super::Error;
use bitflags::bitflags;

pub const MAX_QUEUE_SIZE: usize = 32768;

Expand Down Expand Up @@ -29,3 +30,58 @@ impl VirtioQueue {
Ok(Self { idx, size })
}
}

struct Descriptor {
/// Address
addr: u64,
/// Length
len: u32,
/// The flags
flags: DescriptorFlag,
/// Next field if flags & NEXT
next: u16,
}

bitflags! {
pub struct DescriptorFlag: u16 {
/// Marks a buffer as continuing via the next field.
const NEXT = 1;
/// Marks a buffer as device write-only.
const WRITE = 2;
/// The buffer contains a list of buffer descriptors.
const INDIRECT = 4;
}
}

struct AvailRing {
flags: AvailRingFlag,
idx: u16,
ring: [u16; 32],
used_event: u16,
}

bitflags! {
pub struct AvailRingFlag: u16 {
const NO_INTERRUPT = 1;
}
}

struct UsedRing {
flags: UsedRingFlag,
idx: u16,
used_ring: [UsedElem; 32],
avail_event: u16,
}

struct UsedElem {
/// Index of start of used descriptor chain.
id: u32,
/// Total length of the descriptor chain which was used
len: u32,
}

bitflags! {
pub struct UsedRingFlag: u16 {
const NO_NOTIFY = 1;
}
}

0 comments on commit f97da1f

Please sign in to comment.