Skip to content

Commit 5478027

Browse files
committed
Expose MSI-X configuration
1 parent 3fc66fa commit 5478027

File tree

10 files changed

+115
-1
lines changed

10 files changed

+115
-1
lines changed

src/device/blk.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,16 @@ impl<H: Hal, T: Transport> VirtIOBlk<H, T> {
378378
pub fn virt_queue_size(&self) -> u16 {
379379
QUEUE_SIZE
380380
}
381+
382+
/// Get the underlying transport.
383+
pub fn transport(&self) -> &T {
384+
&self.transport
385+
}
386+
387+
/// Get the underlying transport.
388+
pub fn transport_mut(&mut self) -> &mut T {
389+
&mut self.transport
390+
}
381391
}
382392

383393
impl<H: Hal, T: Transport> Drop for VirtIOBlk<H, T> {

src/device/console.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,16 @@ impl<H: Hal, T: Transport> VirtIOConsole<H, T> {
246246
Err(Error::Unsupported)
247247
}
248248
}
249+
250+
/// Get the underlying transport.
251+
pub fn transport(&self) -> &T {
252+
&self.transport
253+
}
254+
255+
/// Get the underlying transport.
256+
pub fn transport_mut(&mut self) -> &mut T {
257+
&mut self.transport
258+
}
249259
}
250260

251261
impl<H: Hal, T: Transport> Write for VirtIOConsole<H, T> {

src/device/gpu.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@ impl<H: Hal, T: Transport> VirtIOGpu<H, T> {
181181
Ok(())
182182
}
183183

184+
/// Get the underlying transport.
185+
pub fn transport(&self) -> &T {
186+
&self.transport
187+
}
188+
189+
/// Get the underlying transport.
190+
pub fn transport_mut(&mut self) -> &mut T {
191+
&mut self.transport
192+
}
193+
184194
/// Send a request to the device and block for a response.
185195
fn request<Req: IntoBytes + Immutable, Rsp: FromBytes>(&mut self, req: Req) -> Result<Rsp> {
186196
req.write_to_prefix(&mut self.queue_buf_send).unwrap();

src/device/input.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ impl<H: Hal, T: Transport> VirtIOInput<H, T> {
196196
Err(Error::IoError)
197197
}
198198
}
199+
200+
/// Get the underlying transport.
201+
pub fn transport(&self) -> &T {
202+
&self.transport
203+
}
204+
205+
/// Get the underlying transport.
206+
pub fn transport_mut(&mut self) -> &mut T {
207+
&mut self.transport
208+
}
199209
}
200210

201211
// SAFETY: The config space can be accessed from any thread.

src/device/net/dev.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,14 @@ impl<H: Hal, T: Transport, const QUEUE_SIZE: usize> VirtIONet<H, T, QUEUE_SIZE>
122122
pub fn send(&mut self, tx_buf: TxBuffer) -> Result {
123123
self.inner.send(tx_buf.packet())
124124
}
125+
126+
/// Get the underlying transport.
127+
pub fn transport(&self) -> &T {
128+
self.inner.transport()
129+
}
130+
131+
/// Get the underlying transport.
132+
pub fn transport_mut(&mut self) -> &mut T {
133+
self.inner.transport_mut()
134+
}
125135
}

src/device/net/dev_raw.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,16 @@ impl<H: Hal, T: Transport, const QUEUE_SIZE: usize> VirtIONetRaw<H, T, QUEUE_SIZ
266266
// SAFETY: This `rx_buf` is the same one passed to `receive_begin`.
267267
unsafe { self.receive_complete(token, rx_buf) }
268268
}
269+
270+
/// Get the underlying transport.
271+
pub fn transport(&self) -> &T {
272+
&self.transport
273+
}
274+
275+
/// Get the underlying transport.
276+
pub fn transport_mut(&mut self) -> &mut T {
277+
&mut self.transport
278+
}
269279
}
270280

271281
impl<H: Hal, T: Transport, const QUEUE_SIZE: usize> Drop for VirtIONetRaw<H, T, QUEUE_SIZE> {

src/device/rng.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ impl<H: Hal, T: Transport> VirtIORng<H, T> {
4949
pub fn ack_interrupt(&mut self) -> bool {
5050
self.transport.ack_interrupt()
5151
}
52+
53+
/// Get the underlying transport.
54+
pub fn transport(&self) -> &T {
55+
&self.transport
56+
}
57+
58+
/// Get the underlying transport.
59+
pub fn transport_mut(&mut self) -> &mut T {
60+
&mut self.transport
61+
}
5262
}
5363

5464
impl<H: Hal, T: Transport> Drop for VirtIORng<H, T> {

src/device/socket/vsock.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,16 @@ impl<H: Hal, T: Transport, const RX_BUFFER_SIZE: usize> VirtIOSocket<H, T, RX_BU
424424
Ok(())
425425
}
426426

427+
/// Get the underlying transport.
428+
pub fn transport(&self) -> &T {
429+
&self.transport
430+
}
431+
432+
/// Get the underlying transport.
433+
pub fn transport_mut(&mut self) -> &mut T {
434+
&mut self.transport
435+
}
436+
427437
fn send_packet_to_tx_queue(&mut self, header: &VirtioVsockHdr, buffer: &[u8]) -> Result {
428438
let _len = if buffer.is_empty() {
429439
self.tx

src/device/sound.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,16 @@ impl<H: Hal, T: Transport> VirtIOSound<H, T> {
726726
}
727727
})
728728
}
729+
730+
/// Get the underlying transport.
731+
pub fn transport(&self) -> &T {
732+
&self.transport
733+
}
734+
735+
/// Get the underlying transport.
736+
pub fn transport_mut(&mut self) -> &mut T {
737+
&mut self.transport
738+
}
729739
}
730740

731741
/// The status of the PCM stream.

src/transport/pci.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,30 @@ impl Transport for PciTransport {
366366
}
367367
}
368368

369+
impl PciTransport {
370+
/// Get the MSI-X vector for config.
371+
pub fn get_config_msix_vector(&self) -> u16 {
372+
field_shared!(self.common_cfg, config_msix_vector).read()
373+
}
374+
375+
/// Set the MSI-X vector for config.
376+
pub fn set_config_msix_vector(&mut self, vector: u16) {
377+
field!(self.common_cfg, config_msix_vector).write(vector);
378+
}
379+
380+
/// Get the MSI-X vector for a queue.
381+
pub fn get_queue_msix_vector(&mut self, queue: u16) -> u16 {
382+
field!(self.common_cfg, queue_select).write(queue);
383+
field_shared!(self.common_cfg, queue_msix_vector).read()
384+
}
385+
386+
/// Set the MSI-X vector for a queue.
387+
pub fn set_queue_msix_vector(&mut self, queue: u16, vector: u16) {
388+
field!(self.common_cfg, queue_select).write(queue);
389+
field!(self.common_cfg, queue_msix_vector).write(vector);
390+
}
391+
}
392+
369393
// SAFETY: MMIO can be done from any thread or CPU core.
370394
unsafe impl Send for PciTransport {}
371395

@@ -388,7 +412,7 @@ pub(crate) struct CommonCfg {
388412
pub device_feature: ReadPure<u32>,
389413
pub driver_feature_select: ReadPureWrite<u32>,
390414
pub driver_feature: ReadPureWrite<u32>,
391-
pub msix_config: ReadPureWrite<u16>,
415+
pub config_msix_vector: ReadPureWrite<u16>,
392416
pub num_queues: ReadPure<u16>,
393417
pub device_status: ReadPureWrite<u8>,
394418
pub config_generation: ReadPure<u8>,

0 commit comments

Comments
 (0)