From 60d054519e2b15f7d1646c300b8ffe5948fbd296 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Tue, 6 Jul 2021 16:06:57 +0000 Subject: [PATCH] pci: vfio: Extend Vfio trait to handle region read/write This allows the config code to be implemented in terms of that primitive. Signed-off-by: Rob Bradford --- pci/src/vfio.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/pci/src/vfio.rs b/pci/src/vfio.rs index 5d77f96db..59877e679 100644 --- a/pci/src/vfio.rs +++ b/pci/src/vfio.rs @@ -269,11 +269,19 @@ pub(crate) trait Vfio { self.write_config(offset, &data) } - fn read_config(&self, _offset: u32, _data: &mut [u8]) { + fn read_config(&self, offset: u32, data: &mut [u8]) { + self.region_read(VFIO_PCI_CONFIG_REGION_INDEX, offset.into(), data.as_mut()); + } + + fn write_config(&self, offset: u32, data: &[u8]) { + self.region_write(VFIO_PCI_CONFIG_REGION_INDEX, offset.into(), data) + } + + fn region_read(&self, _index: u32, _offset: u64, _data: &mut [u8]) { unimplemented!() } - fn write_config(&self, _offset: u32, _data: &[u8]) { + fn region_write(&self, _index: u32, _offset: u64, _data: &[u8]) { unimplemented!() } } @@ -289,14 +297,12 @@ impl VfioDeviceWrapper { } impl Vfio for VfioDeviceWrapper { - fn read_config(&self, offset: u32, data: &mut [u8]) { - self.device - .region_read(VFIO_PCI_CONFIG_REGION_INDEX, data.as_mut(), offset.into()); + fn region_read(&self, index: u32, offset: u64, data: &mut [u8]) { + self.device.region_read(index, data, offset) } - fn write_config(&self, offset: u32, data: &[u8]) { - self.device - .region_write(VFIO_PCI_CONFIG_REGION_INDEX, &data, offset.into()) + fn region_write(&self, index: u32, offset: u64, data: &[u8]) { + self.device.region_write(index, data, offset) } }