1 use alloc::{string::String, sync::Arc}; 2 use system_error::SystemError; 3 4 use crate::exception::{irqdesc::IrqReturn, IrqNumber}; 5 6 use super::base::device::{driver::Driver, Device, DeviceId}; 7 8 pub(super) mod irq; 9 pub mod mmio; 10 pub mod sysfs; 11 pub mod transport; 12 pub mod transport_mmio; 13 pub mod transport_pci; 14 #[allow(clippy::module_inception)] 15 pub mod virtio; 16 pub mod virtio_impl; 17 18 /// virtio 设备厂商ID 19 pub const VIRTIO_VENDOR_ID: u16 = 0x1af4; 20 21 #[allow(dead_code)] 22 pub trait VirtIODevice: Device { 23 fn handle_irq(&self, _irq: IrqNumber) -> Result<IrqReturn, SystemError>; 24 25 fn dev_id(&self) -> &Arc<DeviceId>; 26 27 fn set_device_name(&self, name: String); 28 29 fn device_name(&self) -> String; 30 31 fn set_virtio_device_index(&self, index: VirtIODeviceIndex); 32 33 fn virtio_device_index(&self) -> Option<VirtIODeviceIndex>; 34 35 /// virtio 设备类型 36 fn device_type_id(&self) -> u32; 37 38 /// virtio 设备厂商 39 fn vendor(&self) -> u32; 40 41 /// virtio设备的中断号 42 fn irq(&self) -> Option<IrqNumber>; 43 44 fn set_irq_number(&self, _irq: IrqNumber) -> Result<(), SystemError> { 45 Err(SystemError::ENOSYS) 46 } 47 } 48 49 pub trait VirtIODriver: Driver { 50 fn probe(&self, device: &Arc<dyn VirtIODevice>) -> Result<(), SystemError>; 51 } 52 53 int_like!(VirtIODeviceIndex, usize); 54