xref: /DragonOS/kernel/src/driver/virtio/mod.rs (revision 352ee04918f4585ad4f8a896ca6e18b1ef7d7934)
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 pub trait VirtIODevice: Device {
22     fn handle_irq(&self, _irq: IrqNumber) -> Result<IrqReturn, SystemError>;
23 
24     fn dev_id(&self) -> &Arc<DeviceId>;
25 
26     fn set_device_name(&self, name: String);
27 
28     fn device_name(&self) -> String;
29 
30     fn set_virtio_device_index(&self, index: VirtIODeviceIndex);
31 
32     fn virtio_device_index(&self) -> Option<VirtIODeviceIndex>;
33 
34     /// virtio 设备类型
35     fn device_type_id(&self) -> u32;
36 
37     /// virtio 设备厂商
38     fn vendor(&self) -> u32;
39 
40     /// virtio设备的中断号
41     fn irq(&self) -> Option<IrqNumber>;
42 
43     fn set_irq_number(&self, _irq: IrqNumber) -> Result<(), SystemError> {
44         Err(SystemError::ENOSYS)
45     }
46 }
47 
48 pub trait VirtIODriver: Driver {
49     fn probe(&self, device: &Arc<dyn VirtIODevice>) -> Result<(), SystemError>;
50 }
51 
52 int_like!(VirtIODeviceIndex, usize);
53