xref: /DragonOS/kernel/src/driver/virtio/mod.rs (revision e32effb1507773d32c216d9e77b963786e275c06)
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_pci;
13 #[allow(clippy::module_inception)]
14 pub mod virtio;
15 pub mod virtio_impl;
16 
17 /// virtio 设备厂商ID
18 pub const VIRTIO_VENDOR_ID: u16 = 0x1af4;
19 
20 pub trait VirtIODevice: Device {
21     fn handle_irq(&self, _irq: IrqNumber) -> Result<IrqReturn, SystemError>;
22 
23     fn dev_id(&self) -> &Arc<DeviceId>;
24 
25     fn set_device_name(&self, name: String);
26 
27     fn device_name(&self) -> String;
28 
29     fn set_virtio_device_index(&self, index: VirtIODeviceIndex);
30 
31     fn virtio_device_index(&self) -> Option<VirtIODeviceIndex>;
32 
33     /// virtio 设备类型
34     fn device_type_id(&self) -> u32;
35 
36     /// virtio 设备厂商
37     fn vendor(&self) -> u32;
38 }
39 
40 pub trait VirtIODriver: Driver {
41     fn probe(&self, device: &Arc<dyn VirtIODevice>) -> Result<(), SystemError>;
42 }
43 
44 int_like!(VirtIODeviceIndex, usize);
45