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