1 use alloc::sync::Arc; 2 use log::debug; 3 use system_error::SystemError; 4 use unified_init::macros::unified_init; 5 6 use crate::{ 7 driver::base::{ 8 device::{device_manager, Device}, 9 kobject::KObject, 10 platform::{ 11 platform_device::{platform_device_manager, PlatformDevice}, 12 platform_driver::{platform_driver_manager, PlatformDriver}, 13 }, 14 }, 15 init::initcall::INITCALL_DEVICE, 16 }; 17 18 use self::{ 19 i8042_device::I8042PlatformDevice, i8042_driver::I8042Driver, i8042_ports::I8042AuxPort, 20 }; 21 22 use super::serio_device::{serio_device_manager, SerioDevice}; 23 24 pub mod i8042_device; 25 pub mod i8042_driver; 26 pub mod i8042_ports; 27 28 static mut I8042_PLATFORM_DEVICE: Option<Arc<I8042PlatformDevice>> = None; 29 30 pub fn i8042_platform_device() -> Arc<I8042PlatformDevice> { 31 unsafe { I8042_PLATFORM_DEVICE.clone().unwrap() } 32 } 33 34 // TODO: https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/input/serio/i8042.c#1612 35 #[unified_init(INITCALL_DEVICE)] 36 pub fn i8042_init() -> Result<(), SystemError> { 37 debug!("i8042 initializing..."); 38 let i8042_device = Arc::new(I8042PlatformDevice::new()); 39 device_manager().device_default_initialize(&(i8042_device.clone() as Arc<dyn Device>)); 40 platform_device_manager().device_add(i8042_device.clone() as Arc<dyn PlatformDevice>)?; 41 unsafe { 42 I8042_PLATFORM_DEVICE = Some(i8042_device); 43 } 44 45 let i8042_driver = I8042Driver::new(); 46 platform_driver_manager().register(i8042_driver.clone() as Arc<dyn PlatformDriver>)?; 47 Ok(()) 48 } 49 50 /// TODO: https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/input/serio/i8042.c#441 51 #[allow(dead_code)] 52 pub fn i8042_start(_serio: &Arc<dyn SerioDevice>) -> Result<(), SystemError> { 53 todo!("i8042_start") 54 } 55 56 /// TODO: https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/input/serio/i8042.c#471 57 #[allow(dead_code)] 58 pub fn i8042_stop(_serio: &Arc<dyn SerioDevice>) -> Result<(), SystemError> { 59 todo!("i8042_stop") 60 } 61 62 /// # 函数的功能 63 /// 创建i8042 Aux设备 64 /// 65 /// 参考: https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/input/serio/i8042.c#i8042_setup_aux 66 pub fn i8042_setup_aux() -> Result<(), SystemError> { 67 let aux_port = Arc::new(I8042AuxPort::new()); 68 aux_port.set_parent(Some(Arc::downgrade( 69 &(i8042_platform_device() as Arc<dyn KObject>), 70 ))); 71 serio_device_manager().register_port(aux_port.clone() as Arc<dyn SerioDevice>)?; 72 73 #[cfg(target_arch = "x86_64")] 74 crate::driver::input::ps2_mouse::ps_mouse_device::rs_ps2_mouse_device_init( 75 aux_port.clone() as Arc<dyn KObject> 76 )?; 77 Ok(()) 78 } 79