uefi_raw/protocol/console/
serial.rs1use crate::{guid, Guid, Status};
4use bitflags::bitflags;
5
6bitflags! {
7 #[repr(transparent)]
11 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
12 pub struct ControlBits: u32 {
13 const CLEAR_TO_SEND = 0x10;
15 const DATA_SET_READY = 0x20;
17 const RING_INDICATE = 0x40;
19 const CARRIER_DETECT = 0x80;
21 const INPUT_BUFFER_EMPTY = 0x100;
23 const OUTPUT_BUFFER_EMPTY = 0x200;
25
26 const DATA_TERMINAL_READY = 0x1;
28 const REQUEST_TO_SEND = 0x2;
30 const HARDWARE_LOOPBACK_ENABLE = 0x1000;
32 const SOFTWARE_LOOPBACK_ENABLE = 0x2000;
34 const HARDWARE_FLOW_CONTROL_ENABLE = 0x4000;
36
37 const SETTABLE =
41 ControlBits::DATA_TERMINAL_READY.bits()
42 | ControlBits::REQUEST_TO_SEND.bits()
43 | ControlBits::HARDWARE_LOOPBACK_ENABLE.bits()
44 | ControlBits::SOFTWARE_LOOPBACK_ENABLE.bits()
45 | ControlBits::HARDWARE_FLOW_CONTROL_ENABLE.bits();
46 }
47}
48
49#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
61#[repr(C)]
62pub struct SerialIoMode {
63 pub control_mask: ControlBits,
65 pub timeout: u32,
68 pub baud_rate: u64,
70 pub receive_fifo_depth: u32,
72 pub data_bits: u32,
74 pub parity: Parity,
76 pub stop_bits: StopBits,
78}
79
80#[derive(Debug)]
81#[repr(C)]
82pub struct SerialIoProtocol {
83 pub revision: u32,
84 pub reset: unsafe extern "efiapi" fn(*mut Self) -> Status,
85 pub set_attributes: unsafe extern "efiapi" fn(
86 *const Self,
87 baud_rate: u64,
88 receive_fifo_depth: u32,
89 timeout: u32,
90 parity: Parity,
91 data_bits: u8,
92 stop_bits_type: StopBits,
93 ) -> Status,
94 pub set_control_bits: unsafe extern "efiapi" fn(*mut Self, ControlBits) -> Status,
95 pub get_control_bits: unsafe extern "efiapi" fn(*const Self, *mut ControlBits) -> Status,
96 pub write: unsafe extern "efiapi" fn(*mut Self, *mut usize, *const u8) -> Status,
97 pub read: unsafe extern "efiapi" fn(*mut Self, *mut usize, *mut u8) -> Status,
98 pub mode: *const SerialIoMode,
99}
100
101impl SerialIoProtocol {
102 pub const GUID: Guid = guid!("bb25cf6f-f1d4-11d2-9a0c-0090273fc1fd");
103 pub const REVISION: u32 = 0x00010000;
104 pub const REVISION1P1: u32 = 0x00010001;
105}
106
107newtype_enum! {
108 pub enum Parity: u32 => {
110 DEFAULT = 0,
112 NONE = 1,
114 EVEN = 2,
116 ODD = 3,
118 MARK = 4,
120 SPACE = 5,
122 }
123}
124
125newtype_enum! {
126 pub enum StopBits: u32 => {
128 DEFAULT = 0,
130 ONE = 1,
132 ONE_FIVE = 2,
134 TWO = 3,
136 }
137}