mod.rs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. use core::fmt::Debug;
  13. use alloc::sync::Arc;
  14. use crate::filesystem::vfs::IndexNode;
  15. use self::base::{
  16. device::{driver::DriverError, Device, DevicePrivateData, DeviceResource, IdTable},
  17. platform::CompatibleTable,
  18. };
  19. pub trait Driver: Sync + Send + Debug {
  20. fn as_any_ref(&'static self) -> &'static dyn core::any::Any;
  21. //对于不需要匹配,在系统初始化的时候就生成的设备,例如 PlatformBus 就不需要匹配表
  22. /// @brief: 获取驱动匹配表
  23. /// @parameter: None
  24. /// @return: 驱动匹配表
  25. fn compatible_table(&self) -> CompatibleTable {
  26. //TODO 要完善每个 CompatibleTable ,将来要把这个默认实现删除
  27. return CompatibleTable::new(vec!["unknown"]);
  28. }
  29. /// @brief 添加可支持的设备
  30. /// @parameter: device 新增的匹配项
  31. fn append_compatible_table(&self, _device: &CompatibleTable) -> Result<(), DriverError> {
  32. Err(DriverError::UnsupportedOperation)
  33. }
  34. /// @brief 探测设备
  35. /// @param data 设备初始拥有的基本信息
  36. fn probe(&self, data: &DevicePrivateData) -> Result<(), DriverError>;
  37. /// @brief 加载设备,包括检查资源可用性,和注册到相应的管理器中。
  38. /// @param data 设备初始拥有的信息
  39. /// @param resource 设备可能申请的资源(或者像伪设备不需要就为None)
  40. fn load(
  41. &self,
  42. data: DevicePrivateData,
  43. resource: Option<DeviceResource>,
  44. ) -> Result<Arc<dyn Device>, DriverError>;
  45. /// @brief: 获取驱动标识符
  46. /// @parameter: None
  47. /// @return: 该驱动驱动唯一标识符
  48. fn id_table(&self) -> IdTable;
  49. // 考虑到很多驱动并不需要存储在系统中,只需要当工具人就可以了,因此 SysINode 是可选的
  50. /// @brief: 设置驱动的sys information
  51. /// @parameter id_table: 驱动标识符,用于唯一标识该驱动
  52. /// @return: 驱动实例
  53. fn set_sys_info(&self, sys_info: Option<Arc<dyn IndexNode>>);
  54. /// @brief: 获取驱动的sys information
  55. /// @parameter id_table: 驱动标识符,用于唯一标识该驱动
  56. /// @return: 驱动实例
  57. fn sys_info(&self) -> Option<Arc<dyn IndexNode>>;
  58. }