1 use virtio_drivers::transport::Transport; 2 3 use super::transport_pci::PciTransport; 4 5 pub enum VirtIOTransport { 6 Pci(PciTransport), 7 } 8 9 impl core::fmt::Debug for VirtIOTransport { 10 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 11 match self { 12 VirtIOTransport::Pci(_) => write!(f, "VirtIOTransport::Pci"), 13 } 14 } 15 } 16 17 impl Transport for VirtIOTransport { 18 #[inline(always)] 19 fn finish_init(&mut self) { 20 match self { 21 VirtIOTransport::Pci(transport) => transport.finish_init(), 22 } 23 } 24 25 #[inline(always)] 26 fn device_type(&self) -> virtio_drivers::transport::DeviceType { 27 match self { 28 VirtIOTransport::Pci(transport) => transport.device_type(), 29 } 30 } 31 32 #[inline(always)] 33 fn read_device_features(&mut self) -> u64 { 34 match self { 35 VirtIOTransport::Pci(transport) => transport.read_device_features(), 36 } 37 } 38 39 #[inline(always)] 40 fn write_driver_features(&mut self, driver_features: u64) { 41 match self { 42 VirtIOTransport::Pci(transport) => transport.write_driver_features(driver_features), 43 } 44 } 45 46 #[inline(always)] 47 fn max_queue_size(&mut self, queue: u16) -> u32 { 48 match self { 49 VirtIOTransport::Pci(transport) => transport.max_queue_size(queue), 50 } 51 } 52 53 #[inline(always)] 54 fn notify(&mut self, queue: u16) { 55 match self { 56 VirtIOTransport::Pci(transport) => transport.notify(queue), 57 } 58 } 59 60 #[inline(always)] 61 fn get_status(&self) -> virtio_drivers::transport::DeviceStatus { 62 match self { 63 VirtIOTransport::Pci(transport) => transport.get_status(), 64 } 65 } 66 67 #[inline(always)] 68 fn set_status(&mut self, status: virtio_drivers::transport::DeviceStatus) { 69 match self { 70 VirtIOTransport::Pci(transport) => transport.set_status(status), 71 } 72 } 73 74 #[inline(always)] 75 fn set_guest_page_size(&mut self, guest_page_size: u32) { 76 match self { 77 VirtIOTransport::Pci(transport) => transport.set_guest_page_size(guest_page_size), 78 } 79 } 80 81 #[inline(always)] 82 fn requires_legacy_layout(&self) -> bool { 83 match self { 84 VirtIOTransport::Pci(transport) => transport.requires_legacy_layout(), 85 } 86 } 87 88 #[inline(always)] 89 fn queue_set( 90 &mut self, 91 queue: u16, 92 size: u32, 93 descriptors: virtio_drivers::PhysAddr, 94 driver_area: virtio_drivers::PhysAddr, 95 device_area: virtio_drivers::PhysAddr, 96 ) { 97 match self { 98 VirtIOTransport::Pci(transport) => { 99 transport.queue_set(queue, size, descriptors, driver_area, device_area) 100 } 101 } 102 } 103 104 #[inline(always)] 105 fn queue_unset(&mut self, queue: u16) { 106 match self { 107 VirtIOTransport::Pci(transport) => transport.queue_unset(queue), 108 } 109 } 110 111 #[inline(always)] 112 fn queue_used(&mut self, queue: u16) -> bool { 113 match self { 114 VirtIOTransport::Pci(transport) => transport.queue_used(queue), 115 } 116 } 117 118 #[inline(always)] 119 fn ack_interrupt(&mut self) -> bool { 120 match self { 121 VirtIOTransport::Pci(transport) => transport.ack_interrupt(), 122 } 123 } 124 125 #[inline(always)] 126 fn config_space<T: 'static>(&self) -> virtio_drivers::Result<core::ptr::NonNull<T>> { 127 match self { 128 VirtIOTransport::Pci(transport) => transport.config_space(), 129 } 130 } 131 } 132