xref: /DragonOS/kernel/src/driver/mod.rs (revision 06d5e247267cb65b84a80f219853ccd0f384b16e)
1 pub mod acpi;
2 pub mod base;
3 pub mod disk;
4 pub mod keyboard;
5 pub mod net;
6 pub mod pci;
7 pub mod timers;
8 pub mod tty;
9 pub mod uart;
10 pub mod video;
11 pub mod virtio;
12 
13 use core::fmt::Debug;
14 
15 use alloc::sync::Arc;
16 
17 use self::base::{
18     device::{driver::DriverError, Device, DevicePrivateData, DeviceResource, IdTable},
19     kobject::KObject,
20     platform::CompatibleTable,
21 };
22 pub trait Driver: Sync + Send + Debug + KObject {
23     /// @brief: 获取驱动匹配表
24     /// @parameter: None
25     /// @return: 驱动匹配表
26     /// 对于不需要匹配,在系统初始化的时候就生成的设备,例如 PlatformBus 就不需要匹配表
27     fn compatible_table(&self) -> CompatibleTable {
28         //TODO 要完善每个 CompatibleTable ,将来要把这个默认实现删除
29         return CompatibleTable::new(vec!["unknown"]);
30     }
31 
32     /// @brief 添加可支持的设备
33     /// @parameter: device 新增的匹配项
34     fn append_compatible_table(&self, _device: &CompatibleTable) -> Result<(), DriverError> {
35         Err(DriverError::UnsupportedOperation)
36     }
37 
38     /// @brief 探测设备
39     /// @param data 设备初始拥有的基本信息
40     fn probe(&self, data: &DevicePrivateData) -> Result<(), DriverError>;
41 
42     /// @brief 加载设备,包括检查资源可用性,和注册到相应的管理器中。
43     /// @param data 设备初始拥有的信息
44     /// @param resource 设备可能申请的资源(或者像伪设备不需要就为None)
45     fn load(
46         &self,
47         data: DevicePrivateData,
48         resource: Option<DeviceResource>,
49     ) -> Result<Arc<dyn Device>, DriverError>;
50 
51     /// @brief: 获取驱动标识符
52     /// @parameter: None
53     /// @return: 该驱动驱动唯一标识符
54     fn id_table(&self) -> IdTable;
55 }
56