Skip to main content

uefi_raw/protocol/
console.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3pub mod serial;
4
5use crate::{Boolean, Char16, Event, Guid, PhysicalAddress, Status, guid, newtype_enum};
6use bitflags::bitflags;
7use core::{ffi, ptr};
8
9bitflags! {
10    /// Absolute pointer device attributes.
11    #[repr(transparent)]
12    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
13    pub struct AbsolutePointerModeAttributes: u32 {
14        /// If set, this device supports an alternate button input.
15        const SUPPORTS_ALT_ACTIVE = 1;
16
17        /// If set, this device returns pressure data in
18        /// [`AbsolutePointerStatus::current_z`].
19        const SUPPORTS_PRESSURE_AS_Z = 2;
20    }
21}
22
23#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
24#[repr(C)]
25pub struct AbsolutePointerMode {
26    pub absolute_min_x: u64,
27    pub absolute_min_y: u64,
28    pub absolute_min_z: u64,
29    pub absolute_max_x: u64,
30    pub absolute_max_y: u64,
31    pub absolute_max_z: u64,
32    pub attributes: AbsolutePointerModeAttributes,
33}
34
35#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
36#[repr(C)]
37pub struct AbsolutePointerState {
38    pub current_x: u64,
39    pub current_y: u64,
40    pub current_z: u64,
41    pub active_buttons: u32,
42}
43
44#[derive(Debug)]
45#[repr(C)]
46pub struct AbsolutePointerProtocol {
47    pub reset: unsafe extern "efiapi" fn(this: *mut Self, extended_verification: Boolean) -> Status,
48    pub get_state:
49        unsafe extern "efiapi" fn(this: *mut Self, state: *mut AbsolutePointerState) -> Status,
50    pub wait_for_input: Event,
51    pub mode: *const AbsolutePointerMode,
52}
53
54impl AbsolutePointerProtocol {
55    pub const GUID: Guid = guid!("8d59d32b-c655-4ae9-9b15-f25904992a43");
56}
57
58#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
59#[repr(C)]
60pub struct InputKey {
61    pub scan_code: u16,
62    pub unicode_char: Char16,
63}
64
65#[derive(Debug)]
66#[repr(C)]
67pub struct SimpleTextInputProtocol {
68    pub reset: unsafe extern "efiapi" fn(this: *mut Self, extended_verification: Boolean) -> Status,
69    pub read_key_stroke: unsafe extern "efiapi" fn(this: *mut Self, key: *mut InputKey) -> Status,
70    pub wait_for_key: Event,
71}
72
73impl SimpleTextInputProtocol {
74    pub const GUID: Guid = guid!("387477c1-69c7-11d2-8e39-00a0c969723b");
75}
76
77#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
78#[repr(C)]
79pub struct KeyData {
80    pub key: InputKey,
81    pub key_state: KeyState,
82}
83
84#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
85#[repr(C)]
86pub struct KeyState {
87    pub key_shift_state: KeyShiftState,
88    pub key_toggle_state: KeyToggleState,
89}
90
91bitflags! {
92    #[repr(transparent)]
93    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
94    pub struct KeyShiftState: u32 {
95        const VALID               = 0x8000_0000;
96        const RIGHT_SHIFT         = 0x0000_0001;
97        const LEFT_SHIFT          = 0x0000_0002;
98        const RIGHT_CONTROL       = 0x0000_0004;
99        const LEFT_CONTROL        = 0x0000_0008;
100        const RIGHT_ALT           = 0x0000_0010;
101        const LEFT_ALT            = 0x0000_0020;
102        const RIGHT_LOGO          = 0x0000_0040;
103        const LEFT_LOGO           = 0x0000_0080;
104        const MENU_KEY            = 0x0000_0100;
105        const SYS_REQ             = 0x0000_0200;
106    }
107}
108
109bitflags! {
110    #[repr(transparent)]
111    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
112    pub struct KeyToggleState: u8 {
113        const SCROLL_LOCK_ACTIVE = 0x01;
114        const NUM_LOCK_ACTIVE = 0x02;
115        const CAPS_LOCK_ACTIVE = 0x04;
116        const EXPOSED = 0x40;
117        const VALID = 0x80;
118    }
119}
120
121pub type KeyNotifyFn = unsafe extern "efiapi" fn(key_data: *const KeyData) -> Status;
122
123#[derive(Debug)]
124#[repr(C)]
125pub struct SimpleTextInputExProtocol {
126    pub reset: unsafe extern "efiapi" fn(this: *mut Self, extended_verification: Boolean) -> Status,
127    pub read_key_stroke_ex: unsafe extern "efiapi" fn(this: *mut Self, key: *mut KeyData) -> Status,
128    pub wait_for_key_ex: Event,
129    pub set_state:
130        unsafe extern "efiapi" fn(this: *mut Self, state: *const KeyToggleState) -> Status,
131    pub register_key_notify: unsafe extern "efiapi" fn(
132        this: *mut Self,
133        key_data: *const KeyData,
134        notification_fn: KeyNotifyFn,
135        notify_handle: *mut *mut ffi::c_void,
136    ) -> Status,
137    pub unregister_key_notify:
138        unsafe extern "efiapi" fn(this: *mut Self, notify_handle: *mut ffi::c_void) -> Status,
139}
140
141impl SimpleTextInputExProtocol {
142    pub const GUID: Guid = guid!("dd9e7534-7762-4698-8c14-f58517a625aa");
143}
144
145#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
146#[repr(C)]
147pub struct SimpleTextOutputMode {
148    pub max_mode: i32,
149    pub mode: i32,
150    pub attribute: i32,
151    pub cursor_column: i32,
152    pub cursor_row: i32,
153    pub cursor_visible: Boolean,
154}
155
156#[derive(Debug)]
157#[repr(C)]
158pub struct SimpleTextOutputProtocol {
159    pub reset: unsafe extern "efiapi" fn(this: *mut Self, extended: Boolean) -> Status,
160    pub output_string: unsafe extern "efiapi" fn(this: *mut Self, string: *const Char16) -> Status,
161    pub test_string: unsafe extern "efiapi" fn(this: *mut Self, string: *const Char16) -> Status,
162    pub query_mode: unsafe extern "efiapi" fn(
163        this: *const Self,
164        mode: usize,
165        columns: *mut usize,
166        rows: *mut usize,
167    ) -> Status,
168    pub set_mode: unsafe extern "efiapi" fn(this: *mut Self, mode: usize) -> Status,
169    pub set_attribute: unsafe extern "efiapi" fn(this: *mut Self, attribute: usize) -> Status,
170    pub clear_screen: unsafe extern "efiapi" fn(this: *mut Self) -> Status,
171    pub set_cursor_position:
172        unsafe extern "efiapi" fn(this: *mut Self, column: usize, row: usize) -> Status,
173    pub enable_cursor: unsafe extern "efiapi" fn(this: *mut Self, visible: Boolean) -> Status,
174    pub mode: *const SimpleTextOutputMode,
175}
176
177impl SimpleTextOutputProtocol {
178    pub const GUID: Guid = guid!("387477c2-69c7-11d2-8e39-00a0c969723b");
179}
180
181#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
182#[repr(C)]
183pub struct SimplePointerMode {
184    pub resolution_x: u64,
185    pub resolution_y: u64,
186    pub resolution_z: u64,
187    pub left_button: Boolean,
188    pub right_button: Boolean,
189}
190
191#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
192#[repr(C)]
193pub struct SimplePointerState {
194    pub relative_movement_x: i32,
195    pub relative_movement_y: i32,
196    pub relative_movement_z: i32,
197    pub left_button: Boolean,
198    pub right_button: Boolean,
199}
200
201#[derive(Debug)]
202#[repr(C)]
203pub struct SimplePointerProtocol {
204    pub reset: unsafe extern "efiapi" fn(this: *mut Self, extended_verification: Boolean) -> Status,
205    pub get_state:
206        unsafe extern "efiapi" fn(this: *mut Self, state: *mut SimplePointerState) -> Status,
207    pub wait_for_input: Event,
208    pub mode: *const SimplePointerMode,
209}
210
211impl SimplePointerProtocol {
212    pub const GUID: Guid = guid!("31878c87-0b75-11d5-9a4f-0090273fc14d");
213}
214
215#[derive(Debug)]
216#[repr(C)]
217pub struct GraphicsOutputProtocol {
218    pub query_mode: unsafe extern "efiapi" fn(
219        *const Self,
220        mode_number: u32,
221        size_of_info: *mut usize,
222        info: *mut *mut GraphicsOutputModeInformation,
223    ) -> Status,
224    pub set_mode: unsafe extern "efiapi" fn(*mut Self, mode_number: u32) -> Status,
225    pub blt: unsafe extern "efiapi" fn(
226        *mut Self,
227        // Depending on `blt_operation`, this is an IN parameter (readable)
228        // or an OUT parameter (writable).
229        blt_buffer: *mut GraphicsOutputBltPixel,
230        blt_operation: GraphicsOutputBltOperation,
231        source_x: usize,
232        source_y: usize,
233        destination_x: usize,
234        destination_y: usize,
235        width: usize,
236        height: usize,
237        delta: usize,
238    ) -> Status,
239    pub mode: *const GraphicsOutputProtocolMode,
240}
241
242impl GraphicsOutputProtocol {
243    pub const GUID: Guid = guid!("9042a9de-23dc-4a38-96fb-7aded080516a");
244}
245
246#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
247#[repr(C)]
248pub struct GraphicsOutputProtocolMode {
249    pub max_mode: u32,
250    pub mode: u32,
251    pub info: *const GraphicsOutputModeInformation,
252    pub size_of_info: usize,
253    pub frame_buffer_base: PhysicalAddress,
254    pub frame_buffer_size: usize,
255}
256
257impl Default for GraphicsOutputProtocolMode {
258    fn default() -> Self {
259        Self {
260            max_mode: 0,
261            mode: 0,
262            info: ptr::null_mut(),
263            size_of_info: 0,
264            frame_buffer_base: 0,
265            frame_buffer_size: 0,
266        }
267    }
268}
269
270#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
271#[repr(C)]
272pub struct GraphicsOutputModeInformation {
273    pub version: u32,
274    pub horizontal_resolution: u32,
275    pub vertical_resolution: u32,
276    pub pixel_format: GraphicsPixelFormat,
277    pub pixel_information: PixelBitmask,
278    pub pixels_per_scan_line: u32,
279}
280
281/// Bitmask used to indicate which bits of a pixel represent a given color.
282#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
283#[repr(C)]
284pub struct PixelBitmask {
285    /// The bits indicating the red channel.
286    pub red: u32,
287
288    /// The bits indicating the green channel.
289    pub green: u32,
290
291    /// The bits indicating the blue channel.
292    pub blue: u32,
293
294    /// The reserved bits, which are ignored by the video hardware.
295    pub reserved: u32,
296}
297
298newtype_enum! {
299    #[derive(Default)]
300    pub enum GraphicsPixelFormat: u32 => {
301        PIXEL_RED_GREEN_BLUE_RESERVED_8_BIT_PER_COLOR = 0,
302        PIXEL_BLUE_GREEN_RED_RESERVED_8_BIT_PER_COLOR = 1,
303        PIXEL_BIT_MASK = 2,
304        PIXEL_BLT_ONLY = 3,
305        PIXEL_FORMAT_MAX = 4,
306    }
307}
308
309#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
310#[repr(C)]
311pub struct GraphicsOutputBltPixel {
312    pub blue: u8,
313    pub green: u8,
314    pub red: u8,
315    pub reserved: u8,
316}
317
318newtype_enum! {
319    #[derive(Default)]
320    pub enum GraphicsOutputBltOperation: u32 => {
321        BLT_VIDEO_FILL = 0,
322        BLT_VIDEO_TO_BLT_BUFFER = 1,
323        BLT_BUFFER_TO_VIDEO = 2,
324        BLT_VIDEO_TO_VIDEO = 3,
325        GRAPHICS_OUTPUT_BLT_OPERATION_MAX = 4,
326    }
327}
328
329#[derive(Clone, Debug, Eq, PartialEq)]
330#[repr(C)]
331pub struct EdidDiscoveredProtocol {
332    pub size_of_edid: u32,
333    pub edid: *const u8,
334}
335
336impl EdidDiscoveredProtocol {
337    pub const GUID: Guid = guid!("1c0c34f6-d380-41fa-a049-8ad06c1a66aa");
338}