diff --git a/src/device/blk.rs b/src/device/blk.rs index f3aa3054..a718c383 100644 --- a/src/device/blk.rs +++ b/src/device/blk.rs @@ -378,6 +378,16 @@ impl VirtIOBlk { pub fn virt_queue_size(&self) -> u16 { QUEUE_SIZE } + + /// Get the underlying transport. + pub fn transport(&self) -> &T { + &self.transport + } + + /// Get the underlying transport. + pub fn transport_mut(&mut self) -> &mut T { + &mut self.transport + } } impl Drop for VirtIOBlk { diff --git a/src/device/console.rs b/src/device/console.rs index 4ee54bd0..d591e643 100644 --- a/src/device/console.rs +++ b/src/device/console.rs @@ -246,6 +246,16 @@ impl VirtIOConsole { Err(Error::Unsupported) } } + + /// Get the underlying transport. + pub fn transport(&self) -> &T { + &self.transport + } + + /// Get the underlying transport. + pub fn transport_mut(&mut self) -> &mut T { + &mut self.transport + } } impl Write for VirtIOConsole { diff --git a/src/device/gpu.rs b/src/device/gpu.rs index 707a6c60..738a18d7 100644 --- a/src/device/gpu.rs +++ b/src/device/gpu.rs @@ -181,6 +181,16 @@ impl VirtIOGpu { Ok(()) } + /// Get the underlying transport. + pub fn transport(&self) -> &T { + &self.transport + } + + /// Get the underlying transport. + pub fn transport_mut(&mut self) -> &mut T { + &mut self.transport + } + /// Send a request to the device and block for a response. fn request(&mut self, req: Req) -> Result { req.write_to_prefix(&mut self.queue_buf_send).unwrap(); diff --git a/src/device/input.rs b/src/device/input.rs index 69171699..4fab4237 100644 --- a/src/device/input.rs +++ b/src/device/input.rs @@ -196,6 +196,16 @@ impl VirtIOInput { Err(Error::IoError) } } + + /// Get the underlying transport. + pub fn transport(&self) -> &T { + &self.transport + } + + /// Get the underlying transport. + pub fn transport_mut(&mut self) -> &mut T { + &mut self.transport + } } // SAFETY: The config space can be accessed from any thread. diff --git a/src/device/net/dev.rs b/src/device/net/dev.rs index 287b2a55..838a0d5d 100644 --- a/src/device/net/dev.rs +++ b/src/device/net/dev.rs @@ -122,4 +122,14 @@ impl VirtIONet pub fn send(&mut self, tx_buf: TxBuffer) -> Result { self.inner.send(tx_buf.packet()) } + + /// Get the underlying transport. + pub fn transport(&self) -> &T { + self.inner.transport() + } + + /// Get the underlying transport. + pub fn transport_mut(&mut self) -> &mut T { + self.inner.transport_mut() + } } diff --git a/src/device/net/dev_raw.rs b/src/device/net/dev_raw.rs index c85c7ea3..d9438355 100644 --- a/src/device/net/dev_raw.rs +++ b/src/device/net/dev_raw.rs @@ -266,6 +266,16 @@ impl VirtIONetRaw &T { + &self.transport + } + + /// Get the underlying transport. + pub fn transport_mut(&mut self) -> &mut T { + &mut self.transport + } } impl Drop for VirtIONetRaw { diff --git a/src/device/rng.rs b/src/device/rng.rs index 3ced8a2f..063ff1ae 100644 --- a/src/device/rng.rs +++ b/src/device/rng.rs @@ -49,6 +49,16 @@ impl VirtIORng { pub fn ack_interrupt(&mut self) -> bool { self.transport.ack_interrupt() } + + /// Get the underlying transport. + pub fn transport(&self) -> &T { + &self.transport + } + + /// Get the underlying transport. + pub fn transport_mut(&mut self) -> &mut T { + &mut self.transport + } } impl Drop for VirtIORng { diff --git a/src/device/socket/vsock.rs b/src/device/socket/vsock.rs index 53e8634b..fe6e4ee5 100644 --- a/src/device/socket/vsock.rs +++ b/src/device/socket/vsock.rs @@ -424,6 +424,16 @@ impl VirtIOSocket &T { + &self.transport + } + + /// Get the underlying transport. + pub fn transport_mut(&mut self) -> &mut T { + &mut self.transport + } + fn send_packet_to_tx_queue(&mut self, header: &VirtioVsockHdr, buffer: &[u8]) -> Result { let _len = if buffer.is_empty() { self.tx diff --git a/src/device/sound.rs b/src/device/sound.rs index 5b4c641b..27545405 100644 --- a/src/device/sound.rs +++ b/src/device/sound.rs @@ -726,6 +726,16 @@ impl VirtIOSound { } }) } + + /// Get the underlying transport. + pub fn transport(&self) -> &T { + &self.transport + } + + /// Get the underlying transport. + pub fn transport_mut(&mut self) -> &mut T { + &mut self.transport + } } /// The status of the PCM stream. diff --git a/src/transport/pci.rs b/src/transport/pci.rs index 1b323999..7c33177c 100644 --- a/src/transport/pci.rs +++ b/src/transport/pci.rs @@ -366,6 +366,30 @@ impl Transport for PciTransport { } } +impl PciTransport { + /// Get the MSI-X vector for config. + pub fn get_config_msix_vector(&self) -> u16 { + field_shared!(self.common_cfg, config_msix_vector).read() + } + + /// Set the MSI-X vector for config. + pub fn set_config_msix_vector(&mut self, vector: u16) { + field!(self.common_cfg, config_msix_vector).write(vector); + } + + /// Get the MSI-X vector for a queue. + pub fn get_queue_msix_vector(&mut self, queue: u16) -> u16 { + field!(self.common_cfg, queue_select).write(queue); + field_shared!(self.common_cfg, queue_msix_vector).read() + } + + /// Set the MSI-X vector for a queue. + pub fn set_queue_msix_vector(&mut self, queue: u16, vector: u16) { + field!(self.common_cfg, queue_select).write(queue); + field!(self.common_cfg, queue_msix_vector).write(vector); + } +} + // SAFETY: MMIO can be done from any thread or CPU core. unsafe impl Send for PciTransport {} @@ -388,7 +412,7 @@ pub(crate) struct CommonCfg { pub device_feature: ReadPure, pub driver_feature_select: ReadPureWrite, pub driver_feature: ReadPureWrite, - pub msix_config: ReadPureWrite, + pub config_msix_vector: ReadPureWrite, pub num_queues: ReadPure, pub device_status: ReadPureWrite, pub config_generation: ReadPure,