1 use alloc::{ 2 string::{String, ToString}, 3 sync::{Arc, Weak}, 4 }; 5 6 use crate::{ 7 driver::base::{device::bus::Bus, kobject::KObject, subsys::SubSysPrivate}, 8 filesystem::{ 9 sysfs::{Attribute, AttributeGroup}, 10 vfs::syscall::ModeType, 11 }, 12 }; 13 14 #[derive(Debug)] 15 pub struct PlatformBus { 16 private: SubSysPrivate, 17 } 18 19 impl PlatformBus { 20 pub fn new() -> Arc<Self> { 21 let w: Weak<Self> = Weak::new(); 22 let private = SubSysPrivate::new("platform".to_string(), w, &[]); 23 let bus = Arc::new(Self { private }); 24 bus.subsystem() 25 .set_bus(Arc::downgrade(&(bus.clone() as Arc<dyn Bus>))); 26 27 return bus; 28 } 29 } 30 31 impl Bus for PlatformBus { 32 fn name(&self) -> String { 33 return "platform".to_string(); 34 } 35 36 fn dev_name(&self) -> String { 37 return self.name(); 38 } 39 40 fn dev_groups(&self) -> &'static [&'static dyn AttributeGroup] { 41 return &[&PlatformDeviceAttrGroup]; 42 } 43 44 fn subsystem(&self) -> &SubSysPrivate { 45 return &self.private; 46 } 47 } 48 49 #[derive(Debug)] 50 pub struct PlatformDeviceAttrGroup; 51 52 impl AttributeGroup for PlatformDeviceAttrGroup { 53 fn name(&self) -> Option<&str> { 54 None 55 } 56 57 fn attrs(&self) -> &[&'static dyn Attribute] { 58 // todo: https://opengrok.ringotek.cn/xref/linux-6.1.9/drivers/base/platform.c?r=&mo=38425&fi=1511#1311 59 return &[]; 60 } 61 62 fn is_visible(&self, _kobj: Arc<dyn KObject>, attr: &dyn Attribute) -> Option<ModeType> { 63 return Some(attr.mode()); 64 } 65 } 66