refactor: ByteOffset newtype for window/register/ring offsets; named virtio-gpu cmd fields
This commit is contained in:
@@ -1,26 +1,28 @@
|
||||
use types::address::ByteOffset;
|
||||
|
||||
pub trait MmioAccess {
|
||||
fn read(&self, offset: usize) -> u32;
|
||||
fn write(&self, offset: usize, val: u32);
|
||||
fn read(&self, offset: ByteOffset) -> u32;
|
||||
fn write(&self, offset: ByteOffset, val: u32);
|
||||
}
|
||||
|
||||
pub const MAGIC: u32 = 0x74726976;
|
||||
|
||||
pub const REG_MAGIC: usize = 0x000;
|
||||
pub const REG_VERSION: usize = 0x004;
|
||||
pub const REG_DEVICE_ID: usize = 0x008;
|
||||
pub const REG_STATUS: usize = 0x070;
|
||||
pub const REG_GUEST_PAGE_SIZE: usize = 0x028;
|
||||
pub const REG_FEATURES_SEL: usize = 0x014;
|
||||
pub const REG_FEATURES: usize = 0x010;
|
||||
pub const REG_DRIVER_FEATURES_SEL: usize = 0x024;
|
||||
pub const REG_DRIVER_FEATURES: usize = 0x020;
|
||||
pub const REG_QUEUE_SEL: usize = 0x030;
|
||||
pub const REG_QUEUE_NUM_MAX: usize = 0x034;
|
||||
pub const REG_QUEUE_NUM: usize = 0x038;
|
||||
pub const REG_QUEUE_PFN: usize = 0x040;
|
||||
pub const REG_QUEUE_NOTIFY: usize = 0x050;
|
||||
pub const REG_INTERRUPT_STATUS: usize = 0x060;
|
||||
pub const REG_INTERRUPT_ACK: usize = 0x064;
|
||||
pub const REG_MAGIC: ByteOffset = ByteOffset::new(0x000);
|
||||
pub const REG_VERSION: ByteOffset = ByteOffset::new(0x004);
|
||||
pub const REG_DEVICE_ID: ByteOffset = ByteOffset::new(0x008);
|
||||
pub const REG_STATUS: ByteOffset = ByteOffset::new(0x070);
|
||||
pub const REG_GUEST_PAGE_SIZE: ByteOffset = ByteOffset::new(0x028);
|
||||
pub const REG_FEATURES_SEL: ByteOffset = ByteOffset::new(0x014);
|
||||
pub const REG_FEATURES: ByteOffset = ByteOffset::new(0x010);
|
||||
pub const REG_DRIVER_FEATURES_SEL: ByteOffset = ByteOffset::new(0x024);
|
||||
pub const REG_DRIVER_FEATURES: ByteOffset = ByteOffset::new(0x020);
|
||||
pub const REG_QUEUE_SEL: ByteOffset = ByteOffset::new(0x030);
|
||||
pub const REG_QUEUE_NUM_MAX: ByteOffset = ByteOffset::new(0x034);
|
||||
pub const REG_QUEUE_NUM: ByteOffset = ByteOffset::new(0x038);
|
||||
pub const REG_QUEUE_PFN: ByteOffset = ByteOffset::new(0x040);
|
||||
pub const REG_QUEUE_NOTIFY: ByteOffset = ByteOffset::new(0x050);
|
||||
pub const REG_INTERRUPT_STATUS: ByteOffset = ByteOffset::new(0x060);
|
||||
pub const REG_INTERRUPT_ACK: ByteOffset = ByteOffset::new(0x064);
|
||||
|
||||
pub const STATUS_ACK: u32 = 1;
|
||||
pub const STATUS_DRIVER: u32 = 2;
|
||||
@@ -42,11 +44,11 @@ impl Registers {
|
||||
}
|
||||
|
||||
impl MmioAccess for Registers {
|
||||
fn read(&self, offset: usize) -> u32 {
|
||||
fn read(&self, offset: ByteOffset) -> u32 {
|
||||
self.0.read(offset)
|
||||
}
|
||||
|
||||
fn write(&self, offset: usize, val: u32) {
|
||||
fn write(&self, offset: ByteOffset, val: u32) {
|
||||
self.0.write(offset, val)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user