xref: /DragonOS/kernel/src/driver/base/class.rs (revision 06d5e247267cb65b84a80f219853ccd0f384b16e)
1 use alloc::{string::ToString, sync::Arc};
2 
3 use crate::syscall::SystemError;
4 
5 use super::kset::KSet;
6 
7 /// `/sys/class`的kset
8 static mut CLASS_KSET_INSTANCE: Option<Arc<KSet>> = None;
9 
10 #[inline(always)]
11 #[allow(dead_code)]
12 pub fn sys_class_kset() -> Arc<KSet> {
13     unsafe { CLASS_KSET_INSTANCE.clone().unwrap() }
14 }
15 
16 /// 初始化`/sys/class`的kset
17 pub(super) fn classes_init() -> Result<(), SystemError> {
18     let class_kset = KSet::new("class".to_string());
19     class_kset
20         .register(None)
21         .expect("register class kset failed");
22     unsafe {
23         CLASS_KSET_INSTANCE = Some(class_kset);
24     }
25     return Ok(());
26 }
27