1*9993c0fcSR0ronoa use alloc::{ 2*9993c0fcSR0ronoa string::{String, ToString}, 3*9993c0fcSR0ronoa sync::{Arc, Weak}, 4*9993c0fcSR0ronoa }; 5*9993c0fcSR0ronoa 6*9993c0fcSR0ronoa use crate::{ 7*9993c0fcSR0ronoa driver::base::{ 8*9993c0fcSR0ronoa class::Class, 9*9993c0fcSR0ronoa device::{bus::Bus, driver::Driver, Device, DeviceState, DeviceType, IdTable}, 10*9993c0fcSR0ronoa kobject::{KObjType, KObject, KObjectState, LockedKObjectState}, 11*9993c0fcSR0ronoa kset::KSet, 12*9993c0fcSR0ronoa platform::{platform_device::PlatformDevice, CompatibleTable}, 13*9993c0fcSR0ronoa }, 14*9993c0fcSR0ronoa filesystem::kernfs::KernFSInode, 15*9993c0fcSR0ronoa libs::{ 16*9993c0fcSR0ronoa rwlock::{RwLockReadGuard, RwLockWriteGuard}, 17*9993c0fcSR0ronoa spinlock::SpinLock, 18*9993c0fcSR0ronoa }, 19*9993c0fcSR0ronoa }; 20*9993c0fcSR0ronoa 21*9993c0fcSR0ronoa #[derive(Debug)] 22*9993c0fcSR0ronoa #[cast_to([sync] Device)] 23*9993c0fcSR0ronoa #[cast_to([sync] PlatformDevice)] 24*9993c0fcSR0ronoa pub struct I8042PlatformDevice { 25*9993c0fcSR0ronoa inner: SpinLock<InnerI8042PlatformDevice>, 26*9993c0fcSR0ronoa kobj_state: LockedKObjectState, 27*9993c0fcSR0ronoa } 28*9993c0fcSR0ronoa 29*9993c0fcSR0ronoa impl I8042PlatformDevice { 30*9993c0fcSR0ronoa pub const NAME: &'static str = "i8042"; 31*9993c0fcSR0ronoa pub fn new() -> Self { 32*9993c0fcSR0ronoa return Self { 33*9993c0fcSR0ronoa inner: SpinLock::new(InnerI8042PlatformDevice { 34*9993c0fcSR0ronoa bus: None, 35*9993c0fcSR0ronoa class: None, 36*9993c0fcSR0ronoa driver: None, 37*9993c0fcSR0ronoa kern_inode: None, 38*9993c0fcSR0ronoa parent: None, 39*9993c0fcSR0ronoa kset: None, 40*9993c0fcSR0ronoa kobj_type: None, 41*9993c0fcSR0ronoa device_state: DeviceState::NotInitialized, 42*9993c0fcSR0ronoa pdev_id: 0, 43*9993c0fcSR0ronoa pdev_id_auto: false, 44*9993c0fcSR0ronoa }), 45*9993c0fcSR0ronoa kobj_state: LockedKObjectState::new(None), 46*9993c0fcSR0ronoa }; 47*9993c0fcSR0ronoa } 48*9993c0fcSR0ronoa } 49*9993c0fcSR0ronoa 50*9993c0fcSR0ronoa #[derive(Debug)] 51*9993c0fcSR0ronoa pub struct InnerI8042PlatformDevice { 52*9993c0fcSR0ronoa bus: Option<Weak<dyn Bus>>, 53*9993c0fcSR0ronoa class: Option<Arc<dyn Class>>, 54*9993c0fcSR0ronoa driver: Option<Weak<dyn Driver>>, 55*9993c0fcSR0ronoa kern_inode: Option<Arc<KernFSInode>>, 56*9993c0fcSR0ronoa parent: Option<Weak<dyn KObject>>, 57*9993c0fcSR0ronoa kset: Option<Arc<KSet>>, 58*9993c0fcSR0ronoa kobj_type: Option<&'static dyn KObjType>, 59*9993c0fcSR0ronoa device_state: DeviceState, 60*9993c0fcSR0ronoa pdev_id: i32, 61*9993c0fcSR0ronoa pdev_id_auto: bool, 62*9993c0fcSR0ronoa } 63*9993c0fcSR0ronoa 64*9993c0fcSR0ronoa impl Device for I8042PlatformDevice { 65*9993c0fcSR0ronoa fn dev_type(&self) -> DeviceType { 66*9993c0fcSR0ronoa DeviceType::Char 67*9993c0fcSR0ronoa } 68*9993c0fcSR0ronoa 69*9993c0fcSR0ronoa fn id_table(&self) -> IdTable { 70*9993c0fcSR0ronoa IdTable::new(self.name(), None) 71*9993c0fcSR0ronoa } 72*9993c0fcSR0ronoa 73*9993c0fcSR0ronoa fn bus(&self) -> Option<Weak<dyn Bus>> { 74*9993c0fcSR0ronoa self.inner.lock().bus.clone() 75*9993c0fcSR0ronoa } 76*9993c0fcSR0ronoa 77*9993c0fcSR0ronoa fn set_bus(&self, bus: Option<Weak<dyn Bus>>) { 78*9993c0fcSR0ronoa self.inner.lock().bus = bus; 79*9993c0fcSR0ronoa } 80*9993c0fcSR0ronoa 81*9993c0fcSR0ronoa fn set_class(&self, class: Option<Arc<dyn Class>>) { 82*9993c0fcSR0ronoa self.inner.lock().class = class; 83*9993c0fcSR0ronoa } 84*9993c0fcSR0ronoa 85*9993c0fcSR0ronoa fn driver(&self) -> Option<Arc<dyn Driver>> { 86*9993c0fcSR0ronoa self.inner.lock().driver.clone()?.upgrade() 87*9993c0fcSR0ronoa } 88*9993c0fcSR0ronoa 89*9993c0fcSR0ronoa fn set_driver(&self, driver: Option<Weak<dyn Driver>>) { 90*9993c0fcSR0ronoa self.inner.lock().driver = driver; 91*9993c0fcSR0ronoa } 92*9993c0fcSR0ronoa 93*9993c0fcSR0ronoa fn is_dead(&self) -> bool { 94*9993c0fcSR0ronoa false 95*9993c0fcSR0ronoa } 96*9993c0fcSR0ronoa 97*9993c0fcSR0ronoa fn can_match(&self) -> bool { 98*9993c0fcSR0ronoa true 99*9993c0fcSR0ronoa } 100*9993c0fcSR0ronoa 101*9993c0fcSR0ronoa fn set_can_match(&self, _can_match: bool) {} 102*9993c0fcSR0ronoa 103*9993c0fcSR0ronoa fn state_synced(&self) -> bool { 104*9993c0fcSR0ronoa true 105*9993c0fcSR0ronoa } 106*9993c0fcSR0ronoa } 107*9993c0fcSR0ronoa 108*9993c0fcSR0ronoa impl KObject for I8042PlatformDevice { 109*9993c0fcSR0ronoa fn as_any_ref(&self) -> &dyn core::any::Any { 110*9993c0fcSR0ronoa self 111*9993c0fcSR0ronoa } 112*9993c0fcSR0ronoa 113*9993c0fcSR0ronoa fn set_inode(&self, inode: Option<Arc<KernFSInode>>) { 114*9993c0fcSR0ronoa self.inner.lock().kern_inode = inode; 115*9993c0fcSR0ronoa } 116*9993c0fcSR0ronoa 117*9993c0fcSR0ronoa fn inode(&self) -> Option<Arc<KernFSInode>> { 118*9993c0fcSR0ronoa self.inner.lock().kern_inode.clone() 119*9993c0fcSR0ronoa } 120*9993c0fcSR0ronoa 121*9993c0fcSR0ronoa fn parent(&self) -> Option<Weak<dyn KObject>> { 122*9993c0fcSR0ronoa self.inner.lock().parent.clone() 123*9993c0fcSR0ronoa } 124*9993c0fcSR0ronoa 125*9993c0fcSR0ronoa fn set_parent(&self, parent: Option<Weak<dyn KObject>>) { 126*9993c0fcSR0ronoa self.inner.lock().parent = parent; 127*9993c0fcSR0ronoa } 128*9993c0fcSR0ronoa 129*9993c0fcSR0ronoa fn kset(&self) -> Option<Arc<KSet>> { 130*9993c0fcSR0ronoa self.inner.lock().kset.clone() 131*9993c0fcSR0ronoa } 132*9993c0fcSR0ronoa 133*9993c0fcSR0ronoa fn set_kset(&self, kset: Option<Arc<KSet>>) { 134*9993c0fcSR0ronoa self.inner.lock().kset = kset; 135*9993c0fcSR0ronoa } 136*9993c0fcSR0ronoa 137*9993c0fcSR0ronoa fn kobj_type(&self) -> Option<&'static dyn KObjType> { 138*9993c0fcSR0ronoa self.inner.lock().kobj_type 139*9993c0fcSR0ronoa } 140*9993c0fcSR0ronoa 141*9993c0fcSR0ronoa fn set_kobj_type(&self, ktype: Option<&'static dyn KObjType>) { 142*9993c0fcSR0ronoa self.inner.lock().kobj_type = ktype; 143*9993c0fcSR0ronoa } 144*9993c0fcSR0ronoa 145*9993c0fcSR0ronoa fn name(&self) -> String { 146*9993c0fcSR0ronoa Self::NAME.to_string() 147*9993c0fcSR0ronoa } 148*9993c0fcSR0ronoa 149*9993c0fcSR0ronoa fn set_name(&self, _name: String) { 150*9993c0fcSR0ronoa // do nothing 151*9993c0fcSR0ronoa } 152*9993c0fcSR0ronoa 153*9993c0fcSR0ronoa fn kobj_state(&self) -> RwLockReadGuard<KObjectState> { 154*9993c0fcSR0ronoa self.kobj_state.read() 155*9993c0fcSR0ronoa } 156*9993c0fcSR0ronoa 157*9993c0fcSR0ronoa fn kobj_state_mut(&self) -> RwLockWriteGuard<KObjectState> { 158*9993c0fcSR0ronoa self.kobj_state.write() 159*9993c0fcSR0ronoa } 160*9993c0fcSR0ronoa 161*9993c0fcSR0ronoa fn set_kobj_state(&self, state: KObjectState) { 162*9993c0fcSR0ronoa *self.kobj_state.write() = state; 163*9993c0fcSR0ronoa } 164*9993c0fcSR0ronoa } 165*9993c0fcSR0ronoa 166*9993c0fcSR0ronoa impl PlatformDevice for I8042PlatformDevice { 167*9993c0fcSR0ronoa fn pdev_name(&self) -> &str { 168*9993c0fcSR0ronoa Self::NAME 169*9993c0fcSR0ronoa } 170*9993c0fcSR0ronoa 171*9993c0fcSR0ronoa fn set_pdev_id(&self, id: i32) { 172*9993c0fcSR0ronoa self.inner.lock().pdev_id = id; 173*9993c0fcSR0ronoa } 174*9993c0fcSR0ronoa 175*9993c0fcSR0ronoa fn set_pdev_id_auto(&self, id_auto: bool) { 176*9993c0fcSR0ronoa self.inner.lock().pdev_id_auto = id_auto; 177*9993c0fcSR0ronoa } 178*9993c0fcSR0ronoa 179*9993c0fcSR0ronoa fn compatible_table(&self) -> CompatibleTable { 180*9993c0fcSR0ronoa todo!() 181*9993c0fcSR0ronoa } 182*9993c0fcSR0ronoa 183*9993c0fcSR0ronoa fn is_initialized(&self) -> bool { 184*9993c0fcSR0ronoa self.inner.lock().device_state == DeviceState::Initialized 185*9993c0fcSR0ronoa } 186*9993c0fcSR0ronoa 187*9993c0fcSR0ronoa fn set_state(&self, set_state: DeviceState) { 188*9993c0fcSR0ronoa self.inner.lock().device_state = set_state; 189*9993c0fcSR0ronoa } 190*9993c0fcSR0ronoa } 191