1*a03c4f9dSLoGin use core::fmt::Debug; 2*a03c4f9dSLoGin 3*a03c4f9dSLoGin use alloc::sync::Arc; 4*a03c4f9dSLoGin 5*a03c4f9dSLoGin use crate::driver::base::device::driver::Driver; 6*a03c4f9dSLoGin 7*a03c4f9dSLoGin use super::tty_device::TtyDevice; 8*a03c4f9dSLoGin 9*a03c4f9dSLoGin /// TTY 驱动 10*a03c4f9dSLoGin /// 11*a03c4f9dSLoGin /// 12*a03c4f9dSLoGin /// 参考 https://opengrok.ringotek.cn/xref/linux-6.1.9/include/linux/tty_driver.h#434 13*a03c4f9dSLoGin pub trait TtyDriver: Debug + Send + Sync + Driver { 14*a03c4f9dSLoGin fn driver_name(&self) -> &str; 15*a03c4f9dSLoGin fn dev_name(&self) -> &str; 16*a03c4f9dSLoGin 17*a03c4f9dSLoGin fn metadata(&self) -> &TtyDriverMetadata; 18*a03c4f9dSLoGin 19*a03c4f9dSLoGin fn other(&self) -> Option<&Arc<dyn TtyDriver>>; 20*a03c4f9dSLoGin 21*a03c4f9dSLoGin fn ttys(&self) -> &[Arc<TtyDevice>]; 22*a03c4f9dSLoGin 23*a03c4f9dSLoGin fn tty_ops(&self) -> Option<&'static dyn TtyDriverOperations> { 24*a03c4f9dSLoGin None 25*a03c4f9dSLoGin } 26*a03c4f9dSLoGin } 27*a03c4f9dSLoGin 28*a03c4f9dSLoGin #[derive(Debug, Clone, Copy)] 29*a03c4f9dSLoGin #[allow(dead_code)] 30*a03c4f9dSLoGin pub struct TtyDriverMetadata { 31*a03c4f9dSLoGin /// name of the driver used in /proc/tty 32*a03c4f9dSLoGin driver_name: &'static str, 33*a03c4f9dSLoGin /// used for constructing /dev node name 34*a03c4f9dSLoGin dev_name: &'static str, 35*a03c4f9dSLoGin /// used as a number base for constructing /dev node name 36*a03c4f9dSLoGin name_base: i32, 37*a03c4f9dSLoGin /// major /dev device number (zero for autoassignment) 38*a03c4f9dSLoGin major: i32, 39*a03c4f9dSLoGin /// the first minor /dev device number 40*a03c4f9dSLoGin minor_start: i32, 41*a03c4f9dSLoGin drv_type: TtyDriverType, 42*a03c4f9dSLoGin subtype: TtyDriverSubtype, 43*a03c4f9dSLoGin } 44*a03c4f9dSLoGin 45*a03c4f9dSLoGin /// https://opengrok.ringotek.cn/xref/linux-6.1.9/include/linux/tty_driver.h#411 46*a03c4f9dSLoGin #[derive(Debug, Clone, Copy)] 47*a03c4f9dSLoGin pub enum TtyDriverType {} 48*a03c4f9dSLoGin 49*a03c4f9dSLoGin /// https://opengrok.ringotek.cn/xref/linux-6.1.9/include/linux/tty_driver.h#412 50*a03c4f9dSLoGin #[derive(Debug, Clone, Copy)] 51*a03c4f9dSLoGin pub enum TtyDriverSubtype {} 52*a03c4f9dSLoGin 53*a03c4f9dSLoGin bitflags! { 54*a03c4f9dSLoGin /// https://opengrok.ringotek.cn/xref/linux-6.1.9/include/linux/tty_driver.h?fi=SERIAL_TYPE_NORMAL#492 55*a03c4f9dSLoGin pub struct TtyDriverFlags: u64 { 56*a03c4f9dSLoGin 57*a03c4f9dSLoGin } 58*a03c4f9dSLoGin } 59*a03c4f9dSLoGin 60*a03c4f9dSLoGin /// 参考 https://opengrok.ringotek.cn/xref/linux-6.1.9/include/linux/tty_driver.h#350 61*a03c4f9dSLoGin pub trait TtyDriverOperations {} 62