Skip to content

Commit

Permalink
feature: 完善设备驱动模型中Device对class的处理,使得能够在class下注册设备
Browse files Browse the repository at this point in the history
目前注册了fbcon设备,但是由于虚拟终端还没写,因此fbcon的到终端以及帧缓冲区的映射还没加上去.
  • Loading branch information
fslongjin committed Dec 19, 2023
1 parent 183ad7b commit f84ec14
Show file tree
Hide file tree
Showing 14 changed files with 609 additions and 36 deletions.
8 changes: 6 additions & 2 deletions kernel/src/driver/base/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ impl dyn Class {
}
}

#[inline(always)]
pub fn class_manager() -> &'static ClassManager {
return &ClassManager;
}
pub struct ClassManager;

impl ClassManager {
Expand All @@ -122,7 +126,7 @@ impl ClassManager {
/// ## 参数
///
/// - `class` - 设备类
pub fn class_register(class: &Arc<dyn Class>) -> Result<(), SystemError> {
pub fn class_register(&self, class: &Arc<dyn Class>) -> Result<(), SystemError> {
let subsystem = class.subsystem();
let subsys = subsystem.subsys();
subsys.set_name(class.name().to_string());
Expand All @@ -143,7 +147,7 @@ impl ClassManager {

/// 注销一个设备类
#[allow(dead_code)]
pub fn class_unregister(class: &Arc<dyn Class>) {
pub fn class_unregister(&self, class: &Arc<dyn Class>) {
let subsystem = class.subsystem();
let subsys = subsystem.subsys();
sysfs_instance().remove_groups(&(subsys.clone() as Arc<dyn KObject>), class.class_groups());
Expand Down
7 changes: 6 additions & 1 deletion kernel/src/driver/base/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{
};

use super::{
class::Class,
device::{
bus::{subsystem_manager, Bus},
driver::Driver,
Expand Down Expand Up @@ -148,7 +149,7 @@ impl Device for CpuSubSystemFakeRootDevice {
}

fn id_table(&self) -> IdTable {
IdTable::new("cpu".to_string(), DeviceNumber::new(0))
IdTable::new("cpu".to_string(), Some(DeviceNumber::new(0)))
}

fn set_bus(&self, bus: Option<Arc<dyn Bus>>) {
Expand Down Expand Up @@ -178,6 +179,10 @@ impl Device for CpuSubSystemFakeRootDevice {
fn state_synced(&self) -> bool {
true
}

fn set_class(&self, _class: Option<Arc<dyn Class>>) {
todo!()
}
}

impl KObject for CpuSubSystemFakeRootDevice {
Expand Down
18 changes: 16 additions & 2 deletions kernel/src/driver/base/device/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use alloc::{string::ToString, sync::Arc};
use crate::{
driver::base::{
device::{
set_sys_dev_block_kset, set_sys_dev_char_kset, sys_dev_kset, DeviceManager,
DEVICES_KSET_INSTANCE, DEVICE_MANAGER, DEV_KSET_INSTANCE,
set_sys_dev_block_kset, set_sys_dev_char_kset, set_sys_devices_virtual_kset,
sys_dev_kset, sys_devices_kset, DeviceManager, DEVICES_KSET_INSTANCE, DEVICE_MANAGER,
DEV_KSET_INSTANCE,
},
kobject::KObject,
kset::KSet,
Expand All @@ -28,6 +29,19 @@ pub fn devices_init() -> Result<(), SystemError> {
}
}

// 创建 `/sys/devices/virtual` 目录
{
let devices_kset = sys_devices_kset();
let virtual_kset = KSet::new("virtual".to_string());
let parent = devices_kset.clone() as Arc<dyn KObject>;
virtual_kset.set_parent(Some(Arc::downgrade(&parent)));

virtual_kset
.register(Some(devices_kset))
.expect("register virtual kset failed");
unsafe { set_sys_devices_virtual_kset(virtual_kset) };
}

// 创建 `/sys/dev` 目录
{
let dev_kset = KSet::new("dev".to_string());
Expand Down
Loading

0 comments on commit f84ec14

Please sign in to comment.