1 pub mod serial;
2 
3 use crate::{guid, Char16, Event, Guid, PhysicalAddress, Status};
4 use bitflags::bitflags;
5 use core::ptr;
6 
7 bitflags! {
8     /// Absolute pointer device attributes.
9     #[repr(transparent)]
10     #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
11     pub struct AbsolutePointerModeAttributes: u32 {
12         /// If set, this device supports an alternate button input.
13         const SUPPORTS_ALT_ACTIVE = 1;
14 
15         /// If set, this device returns pressure data in
16         /// [`AbsolutePointerStatus::current_z`].
17         const SUPPORTS_PRESSURE_AS_Z = 2;
18     }
19 }
20 
21 #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
22 #[repr(C)]
23 pub struct AbsolutePointerMode {
24     pub absolute_min_x: u64,
25     pub absolute_min_y: u64,
26     pub absolute_min_z: u64,
27     pub absolute_max_x: u64,
28     pub absolute_max_y: u64,
29     pub absolute_max_z: u64,
30     pub attributes: AbsolutePointerModeAttributes,
31 }
32 
33 #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
34 #[repr(C)]
35 pub struct AbsolutePointerState {
36     pub current_x: u64,
37     pub current_y: u64,
38     pub current_z: u64,
39     pub active_buttons: u32,
40 }
41 
42 #[derive(Debug)]
43 #[repr(C)]
44 pub struct AbsolutePointerProtocol {
45     pub reset: unsafe extern "efiapi" fn(this: *mut Self, extended_verification: u8) -> Status,
46     pub get_state:
47         unsafe extern "efiapi" fn(this: *const Self, state: *mut AbsolutePointerState) -> Status,
48     pub wait_for_input: Event,
49     pub mode: *mut AbsolutePointerMode,
50 }
51 
52 impl AbsolutePointerProtocol {
53     pub const GUID: Guid = guid!("8d59d32b-c655-4ae9-9b15-f25904992a43");
54 }
55 
56 #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
57 #[repr(C)]
58 pub struct InputKey {
59     pub scan_code: u16,
60     pub unicode_char: Char16,
61 }
62 
63 #[derive(Debug)]
64 #[repr(C)]
65 pub struct SimpleTextInputProtocol {
66     pub reset: unsafe extern "efiapi" fn(this: *mut Self, extended_verification: bool) -> Status,
67     pub read_key_stroke: unsafe extern "efiapi" fn(this: *mut Self, key: *mut InputKey) -> Status,
68     pub wait_for_key: Event,
69 }
70 
71 impl SimpleTextInputProtocol {
72     pub const GUID: Guid = guid!("387477c1-69c7-11d2-8e39-00a0c969723b");
73 }
74 
75 #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
76 #[repr(C)]
77 pub struct SimpleTextOutputMode {
78     pub max_mode: i32,
79     pub mode: i32,
80     pub attribute: i32,
81     pub cursor_column: i32,
82     pub cursor_row: i32,
83     pub cursor_visible: bool,
84 }
85 
86 #[derive(Debug)]
87 #[repr(C)]
88 pub struct SimpleTextOutputProtocol {
89     pub reset: unsafe extern "efiapi" fn(this: *mut Self, extended: bool) -> Status,
90     pub output_string: unsafe extern "efiapi" fn(this: *mut Self, string: *const Char16) -> Status,
91     pub test_string: unsafe extern "efiapi" fn(this: *mut Self, string: *const Char16) -> Status,
92     pub query_mode: unsafe extern "efiapi" fn(
93         this: *mut Self,
94         mode: usize,
95         columns: *mut usize,
96         rows: *mut usize,
97     ) -> Status,
98     pub set_mode: unsafe extern "efiapi" fn(this: *mut Self, mode: usize) -> Status,
99     pub set_attribute: unsafe extern "efiapi" fn(this: *mut Self, attribute: usize) -> Status,
100     pub clear_screen: unsafe extern "efiapi" fn(this: *mut Self) -> Status,
101     pub set_cursor_position:
102         unsafe extern "efiapi" fn(this: *mut Self, column: usize, row: usize) -> Status,
103     pub enable_cursor: unsafe extern "efiapi" fn(this: *mut Self, visible: bool) -> Status,
104     pub mode: *mut SimpleTextOutputMode,
105 }
106 
107 impl SimpleTextOutputProtocol {
108     pub const GUID: Guid = guid!("387477c2-69c7-11d2-8e39-00a0c969723b");
109 }
110 
111 #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
112 #[repr(C)]
113 pub struct SimplePointerMode {
114     pub resolution_x: u64,
115     pub resolution_y: u64,
116     pub resolution_z: u64,
117     pub left_button: u8,
118     pub right_button: u8,
119 }
120 
121 #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
122 #[repr(C)]
123 pub struct SimplePointerState {
124     pub relative_movement_x: i32,
125     pub relative_movement_y: i32,
126     pub relative_movement_z: i32,
127     pub left_button: u8,
128     pub right_button: u8,
129 }
130 
131 #[derive(Debug)]
132 #[repr(C)]
133 pub struct SimplePointerProtocol {
134     pub reset: unsafe extern "efiapi" fn(
135         this: *mut SimplePointerProtocol,
136         extended_verification: bool,
137     ) -> Status,
138     pub get_state: unsafe extern "efiapi" fn(
139         this: *mut SimplePointerProtocol,
140         state: *mut SimplePointerState,
141     ) -> Status,
142     pub wait_for_input: Event,
143     pub mode: *const SimplePointerMode,
144 }
145 
146 impl SimplePointerProtocol {
147     pub const GUID: Guid = guid!("31878c87-0b75-11d5-9a4f-0090273fc14d");
148 }
149 
150 #[derive(Debug)]
151 #[repr(C)]
152 pub struct GraphicsOutputProtocol {
153     pub query_mode: unsafe extern "efiapi" fn(
154         *const Self,
155         mode_number: u32,
156         size_of_info: *mut usize,
157         info: *mut *const GraphicsOutputModeInformation,
158     ) -> Status,
159     pub set_mode: unsafe extern "efiapi" fn(*mut Self, mode_number: u32) -> Status,
160     pub blt: unsafe extern "efiapi" fn(
161         *mut Self,
162         blt_buffer: *mut GraphicsOutputBltPixel,
163         blt_operation: GraphicsOutputBltOperation,
164         source_x: usize,
165         source_y: usize,
166         destination_x: usize,
167         destination_y: usize,
168         width: usize,
169         height: usize,
170         delta: usize,
171     ) -> Status,
172     pub mode: *mut GraphicsOutputProtocolMode,
173 }
174 
175 impl GraphicsOutputProtocol {
176     pub const GUID: Guid = guid!("9042a9de-23dc-4a38-96fb-7aded080516a");
177 }
178 
179 #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
180 #[repr(C)]
181 pub struct GraphicsOutputProtocolMode {
182     pub max_mode: u32,
183     pub mode: u32,
184     pub info: *mut GraphicsOutputModeInformation,
185     pub size_of_info: usize,
186     pub frame_buffer_base: PhysicalAddress,
187     pub frame_buffer_size: usize,
188 }
189 
190 impl Default for GraphicsOutputProtocolMode {
default() -> Self191     fn default() -> Self {
192         Self {
193             max_mode: 0,
194             mode: 0,
195             info: ptr::null_mut(),
196             size_of_info: 0,
197             frame_buffer_base: 0,
198             frame_buffer_size: 0,
199         }
200     }
201 }
202 
203 #[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
204 #[repr(C)]
205 pub struct GraphicsOutputModeInformation {
206     pub version: u32,
207     pub horizontal_resolution: u32,
208     pub vertical_resolution: u32,
209     pub pixel_format: GraphicsPixelFormat,
210     pub pixel_information: PixelBitmask,
211     pub pixels_per_scan_line: u32,
212 }
213 
214 /// Bitmask used to indicate which bits of a pixel represent a given color.
215 #[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
216 #[repr(C)]
217 pub struct PixelBitmask {
218     /// The bits indicating the red channel.
219     pub red: u32,
220 
221     /// The bits indicating the green channel.
222     pub green: u32,
223 
224     /// The bits indicating the blue channel.
225     pub blue: u32,
226 
227     /// The reserved bits, which are ignored by the video hardware.
228     pub reserved: u32,
229 }
230 
231 newtype_enum! {
232     #[derive(Default)]
233     pub enum GraphicsPixelFormat: u32 => {
234         PIXEL_RED_GREEN_BLUE_RESERVED_8_BIT_PER_COLOR = 0,
235         PIXEL_BLUE_GREEN_RED_RESERVED_8_BIT_PER_COLOR = 1,
236         PIXEL_BIT_MASK = 2,
237         PIXEL_BLT_ONLY = 3,
238         PIXEL_FORMAT_MAX = 4,
239     }
240 }
241 
242 #[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
243 #[repr(C)]
244 pub struct GraphicsOutputBltPixel {
245     pub blue: u8,
246     pub green: u8,
247     pub red: u8,
248     pub reserved: u8,
249 }
250 
251 newtype_enum! {
252     #[derive(Default)]
253     pub enum GraphicsOutputBltOperation: u32 => {
254         BLT_VIDEO_FILL = 0,
255         BLT_VIDEO_TO_BLT_BUFFER = 1,
256         BLT_BUFFER_TO_VIDEO = 2,
257         BLT_VIDEO_TO_VIDEO = 3,
258         GRAPHICS_OUTPUT_BLT_OPERATION_MAX = 4,
259     }
260 }
261