1*06d5e247SLoGin use super::Device; 2*06d5e247SLoGin use crate::syscall::SystemError; 3*06d5e247SLoGin use alloc::sync::Arc; 40663027bSTingHuang use core::fmt::Debug; 52a7d773dSTingHuang 62a7d773dSTingHuang /// @brief: Driver error 72a7d773dSTingHuang #[allow(dead_code)] 878bf93f0SYJwu2023 #[derive(Debug, PartialEq, Eq, Clone, Copy)] 92a7d773dSTingHuang pub enum DriverError { 10b087521eSChiichen ProbeError, // 探测设备失败(该驱动不能初始化这个设备) 11b087521eSChiichen RegisterError, // 设备注册失败 12b087521eSChiichen AllocateResourceError, // 获取设备所需资源失败 13b087521eSChiichen UnsupportedOperation, // 不支持的操作 14b087521eSChiichen UnInitialized, // 未初始化 152a7d773dSTingHuang } 162a7d773dSTingHuang 17e0de0fd6STingHuang impl Into<SystemError> for DriverError { 18e0de0fd6STingHuang fn into(self) -> SystemError { 19e0de0fd6STingHuang match self { 20b087521eSChiichen DriverError::ProbeError => SystemError::ENODEV, 21b087521eSChiichen DriverError::RegisterError => SystemError::ENODEV, 22b087521eSChiichen DriverError::AllocateResourceError => SystemError::EIO, 23b087521eSChiichen DriverError::UnsupportedOperation => SystemError::EIO, 24b087521eSChiichen DriverError::UnInitialized => SystemError::ENODEV, 25e0de0fd6STingHuang } 26e0de0fd6STingHuang } 27e0de0fd6STingHuang } 28e0de0fd6STingHuang 29*06d5e247SLoGin #[inline(always)] 30*06d5e247SLoGin pub fn driver_manager() -> &'static DriverManager { 31*06d5e247SLoGin &DriverManager 32e0de0fd6STingHuang } 33e0de0fd6STingHuang 34e0de0fd6STingHuang /// @brief: 驱动管理器 35e0de0fd6STingHuang #[derive(Debug, Clone)] 36*06d5e247SLoGin pub struct DriverManager; 37e0de0fd6STingHuang 38e0de0fd6STingHuang impl DriverManager { 39*06d5e247SLoGin /// 参考: https://opengrok.ringotek.cn/xref/linux-6.1.9/drivers/base/dd.c#434 40*06d5e247SLoGin pub fn driver_sysfs_add(&self, _dev: &Arc<dyn Device>) -> Result<(), SystemError> { 41*06d5e247SLoGin todo!("DriverManager::driver_sysfs_add()"); 42e0de0fd6STingHuang } 43e0de0fd6STingHuang } 44