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