Skip to content

Commit

Permalink
feat(driver/net): 将网络设备注册到sysfs, 添加设备类属性文件 (#919)
Browse files Browse the repository at this point in the history
  • Loading branch information
1037827920 authored Sep 11, 2024
1 parent a3571c8 commit 28fe4ad
Show file tree
Hide file tree
Showing 34 changed files with 2,136 additions and 583 deletions.
8 changes: 8 additions & 0 deletions kernel/src/arch/x86_64/driver/rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ impl Device for CmosRtcDevice {
fn bus(&self) -> Option<Weak<dyn Bus>> {
self.inner().device_common.get_bus_weak_or_clear()
}

fn dev_parent(&self) -> Option<Weak<dyn Device>> {
self.inner().device_common.get_parent_weak_or_clear()
}

fn set_dev_parent(&self, parent: Option<Weak<dyn Device>>) {
self.inner().device_common.parent = parent;
}
}

impl KObject for CmosRtcDevice {
Expand Down
46 changes: 24 additions & 22 deletions kernel/src/driver/base/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ use super::{
device::{
bus::{subsystem_manager, Bus},
driver::Driver,
Device, DeviceType, IdTable,
Device, DeviceCommonData, DeviceType, IdTable,
},
kobject::{KObjType, KObject, KObjectState, LockedKObjectState},
kobject::{KObjType, KObject, KObjectCommonData, KObjectState, LockedKObjectState},
kset::KSet,
subsys::SubSysPrivate,
};
Expand Down Expand Up @@ -123,23 +123,17 @@ impl CpuSubSystemFakeRootDevice {

#[derive(Debug)]
struct InnerCpuSubSystemFakeRootDevice {
parent_kobj: Option<Weak<dyn KObject>>,
bus: Option<Weak<dyn Bus>>,
kset: Option<Arc<KSet>>,
kobject_common: KObjectCommonData,
device_common: DeviceCommonData,
name: String,
kern_inode: Option<Arc<KernFSInode>>,
ktype: Option<&'static dyn KObjType>,
}

impl InnerCpuSubSystemFakeRootDevice {
pub fn new() -> Self {
return Self {
parent_kobj: None,
bus: None,
kset: None,
kobject_common: KObjectCommonData::default(),
device_common: DeviceCommonData::default(),
name: "".to_string(),
kern_inode: None,
ktype: None,
};
}
}
Expand All @@ -154,11 +148,11 @@ impl Device for CpuSubSystemFakeRootDevice {
}

fn set_bus(&self, bus: Option<Weak<dyn Bus>>) {
self.inner.write().bus = bus;
self.inner.write().device_common.bus = bus;
}

fn bus(&self) -> Option<Weak<dyn Bus>> {
self.inner.read().bus.clone()
self.inner.read().device_common.bus.clone()
}

fn driver(&self) -> Option<Arc<dyn Driver>> {
Expand Down Expand Up @@ -188,6 +182,14 @@ impl Device for CpuSubSystemFakeRootDevice {
fn set_class(&self, _class: Option<Weak<dyn Class>>) {
todo!()
}

fn dev_parent(&self) -> Option<Weak<dyn Device>> {
self.inner.read().device_common.parent.clone()
}

fn set_dev_parent(&self, dev_parent: Option<Weak<dyn Device>>) {
self.inner.write().device_common.parent = dev_parent;
}
}

impl KObject for CpuSubSystemFakeRootDevice {
Expand All @@ -196,35 +198,35 @@ impl KObject for CpuSubSystemFakeRootDevice {
}

fn set_inode(&self, inode: Option<Arc<KernFSInode>>) {
self.inner.write().kern_inode = inode;
self.inner.write().kobject_common.kern_inode = inode;
}

fn inode(&self) -> Option<Arc<KernFSInode>> {
self.inner.read().kern_inode.clone()
self.inner.read().kobject_common.kern_inode.clone()
}

fn parent(&self) -> Option<Weak<dyn KObject>> {
self.inner.read().parent_kobj.clone()
self.inner.read().kobject_common.parent.clone()
}

fn set_parent(&self, parent: Option<Weak<dyn KObject>>) {
self.inner.write().parent_kobj = parent;
self.inner.write().kobject_common.parent = parent;
}

fn kset(&self) -> Option<Arc<KSet>> {
self.inner.read().kset.clone()
self.inner.read().kobject_common.kset.clone()
}

fn set_kset(&self, kset: Option<Arc<KSet>>) {
self.inner.write().kset = kset;
self.inner.write().kobject_common.kset = kset;
}

fn kobj_type(&self) -> Option<&'static dyn KObjType> {
self.inner.read().ktype
self.inner.read().kobject_common.kobj_type
}

fn set_kobj_type(&self, ktype: Option<&'static dyn KObjType>) {
self.inner.write().ktype = ktype;
self.inner.write().kobject_common.kobj_type = ktype;
}

fn name(&self) -> String {
Expand Down
10 changes: 8 additions & 2 deletions kernel/src/driver/base/device/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,14 @@ impl BusManager {
.ok_or(SystemError::EINVAL)?;
debug!("bus '{}' add driver '{}'", bus.name(), driver.name());

driver.set_kobj_type(Some(&BusDriverKType));
// driver.set_kobj_type(Some(&BusDriverKType));
let kobj = driver.clone() as Arc<dyn KObject>;
KObjectManager::add_kobj(kobj, bus.subsystem().drivers_kset())?;
// KObjectManager::add_kobj(kobj, bus.subsystem().drivers_kset())?;
KObjectManager::init_and_add_kobj(
kobj,
bus.subsystem().drivers_kset(),
Some(&BusDriverKType),
)?;

bus.subsystem().add_driver_to_vec(driver)?;
if bus.subsystem().drivers_autoprobe() {
Expand Down Expand Up @@ -451,6 +456,7 @@ impl BusManager {
}
let bus = bus.unwrap();
if bus.subsystem().drivers_autoprobe() {
log::info!("MT bus '{}' autoprobe driver", bus.name());
device_manager().device_initial_probe(dev).ok();
}
for interface in bus.subsystem().interfaces() {
Expand Down
Loading

0 comments on commit 28fe4ad

Please sign in to comment.