Skip to content

Commit f1cea56

Browse files
committed
uefi-raw: hii: Add Database Protocol
Ref: UEFI 2.11: 34.8 Database Protocol Signed-off-by: Tim Crawford <[email protected]>
1 parent 21fabff commit f1cea56

File tree

4 files changed

+304
-0
lines changed

4 files changed

+304
-0
lines changed

uefi-raw/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Added `DriverBindingProtocol`.
88
- Added `FirmwareVolume2Protocol`.
99
- Added `FirmwareVolumeBlock2Protocol`.
10+
- Added `HiiDatabaseProtocol`.
1011

1112

1213
# uefi-raw - 0.9.0 (2024-10-23)

uefi-raw/src/protocol/hii/database.rs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//! Bindings for HII Database Protocol
2+
3+
use super::{HiiPackageHeader, HiiPackageListHeader, KeyDescriptor};
4+
use crate::{guid, Guid, Handle, Status};
5+
6+
/// EFI_HII_KEYBOARD_LAYOUT
7+
#[derive(Debug)]
8+
#[repr(C)]
9+
pub struct HiiKeyboardLayout {
10+
pub layout_length: u16,
11+
pub guid: Guid,
12+
pub layout_descriptor_string_offset: u32,
13+
pub descriptor_count: u8,
14+
pub descriptors: [KeyDescriptor; 0],
15+
}
16+
17+
newtype_enum! {
18+
/// EFI_HII_DATABASE_NOTIFY_TYPE
19+
pub enum HiiDatabaseNotifyType: usize => {
20+
NEW_PACK = 1 << 0,
21+
REMOVE_PACK = 1 << 1,
22+
EXPORT_PACK = 1 << 2,
23+
ADD_PACK = 1 << 3,
24+
}
25+
}
26+
27+
/// EFI_HII_DATABASE_NOTIFY
28+
pub type HiiDatabaseNotifyFn = unsafe extern "efiapi" fn(
29+
package_type: u8,
30+
package_guid: *const Guid,
31+
package: *const HiiPackageHeader,
32+
handle: Handle,
33+
notify_type: HiiDatabaseNotifyType,
34+
) -> Status;
35+
36+
/// EFI_HII_DATABASE_PROTOCOL
37+
#[derive(Debug)]
38+
#[repr(C)]
39+
pub struct HiiDatabaseProtocol {
40+
pub new_package_list: unsafe extern "efiapi" fn(
41+
this: *const Self,
42+
package_list: *const HiiPackageListHeader,
43+
driver_handle: Handle,
44+
handle: *mut Handle,
45+
) -> Status,
46+
pub remove_package_list: unsafe extern "efiapi" fn(this: *const Self, handle: Handle) -> Status,
47+
pub update_package_list: unsafe extern "efiapi" fn(
48+
this: *const Self,
49+
handle: Handle,
50+
package_list: *const HiiPackageListHeader,
51+
) -> Status,
52+
pub list_package_lists: unsafe extern "efiapi" fn(
53+
this: *const Self,
54+
package_type: u8,
55+
package_guid: *const Guid,
56+
handle_buffer_length: *mut usize,
57+
handle: *mut Handle,
58+
) -> Status,
59+
pub export_package_lists: unsafe extern "efiapi" fn(
60+
this: *const Self,
61+
handle: Handle,
62+
buffer_size: *mut usize,
63+
buffer: *mut HiiPackageListHeader,
64+
) -> Status,
65+
pub register_package_notify: unsafe extern "efiapi" fn(
66+
this: *const Self,
67+
package_type: u8,
68+
package_guid: *const Guid,
69+
package_notify_fn: HiiDatabaseNotifyFn,
70+
notify_type: HiiDatabaseNotifyType,
71+
notify_handle: *mut Handle,
72+
) -> Status,
73+
pub unregister_package_notify:
74+
unsafe extern "efiapi" fn(this: *const Self, notification_handle: Handle) -> Status,
75+
pub find_keyboard_layouts: unsafe extern "efiapi" fn(
76+
this: *const Self,
77+
key_guid_buffer_length: *mut u16,
78+
key_guid_buffer: *mut Guid,
79+
) -> Status,
80+
pub get_keyboard_layout: unsafe extern "efiapi" fn(
81+
this: *const Self,
82+
key_guid: *const Guid,
83+
leyboard_layout_length: *mut u16,
84+
keyboard_layout: *mut HiiKeyboardLayout,
85+
) -> Status,
86+
pub set_keyboard_layout:
87+
unsafe extern "efiapi" fn(this: *const Self, key_guid: *const Guid) -> Status,
88+
pub get_package_list_handle: unsafe extern "efiapi" fn(
89+
this: *const Self,
90+
package_list_handle: Handle,
91+
driver_handle: *mut Handle,
92+
) -> Status,
93+
}
94+
95+
impl HiiDatabaseProtocol {
96+
pub const GUID: Guid = guid!("ef9fc172-a1b2-4693-b327-6d32fc416042");
97+
}

uefi-raw/src/protocol/hii/mod.rs

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
//! HII Protocols
2+
3+
pub mod database;
4+
5+
use crate::{Char16, Guid};
6+
7+
/// EFI_HII_PACKAGE_HEADER
8+
#[derive(Debug)]
9+
#[repr(C)]
10+
pub struct HiiPackageHeader {
11+
pub length_and_type: u32,
12+
pub data: [u8; 0],
13+
}
14+
15+
/// EFI_HII_PACKAGE_LIST_HEADER
16+
#[derive(Debug)]
17+
#[repr(C)]
18+
pub struct HiiPackageListHeader {
19+
pub package_list_guid: Guid,
20+
pub package_length: u32,
21+
}
22+
23+
// NOTE: UEFI does not define the values for any keys.
24+
newtype_enum! {
25+
/// EFI_KEY: A physical key on a keyboard.
26+
pub enum Key: u32 => {
27+
LCTRL = 0,
28+
A0 = 1,
29+
LALT = 2,
30+
SPACEBAR = 3,
31+
A2 = 4,
32+
A3 = 5,
33+
A4 = 6,
34+
RCTRL = 7,
35+
LEFT_ARROW = 8,
36+
DOWN_ARROW = 9,
37+
RIGHT_ARROW = 10,
38+
ZERO = 11,
39+
PERIOD = 12,
40+
ENTER = 13,
41+
LSHIFT = 14,
42+
B0 = 15,
43+
B1 = 16,
44+
B2 = 17,
45+
B3 = 18,
46+
B4 = 19,
47+
B5 = 20,
48+
B6 = 21,
49+
B7 = 22,
50+
B8 = 23,
51+
B9 = 24,
52+
B10 = 25,
53+
RSHIFT = 26,
54+
UP_ARROW = 27,
55+
ONE = 28,
56+
TWO = 29,
57+
THREE = 30,
58+
CAPS_LOCK = 31,
59+
C1 = 32,
60+
C2 = 33,
61+
C3 = 34,
62+
C4 = 35,
63+
C5 = 36,
64+
C6 = 37,
65+
C7 = 38,
66+
C8 = 39,
67+
C9 = 40,
68+
C10 = 41,
69+
C11 = 42,
70+
C12 = 43,
71+
FOUR = 44,
72+
FIVE = 45,
73+
SIX = 46,
74+
PLUS = 47,
75+
TAB = 48,
76+
D1 = 49,
77+
D2 = 50,
78+
D3 = 51,
79+
D4 = 52,
80+
D5 = 53,
81+
D6 = 54,
82+
D7 = 55,
83+
D8 = 56,
84+
D9 = 57,
85+
D10 = 58,
86+
D11 = 59,
87+
D12 = 60,
88+
D13 = 61,
89+
DEL = 62,
90+
END = 63,
91+
PG_DN = 64,
92+
SEVEN = 65,
93+
EIGHT = 66,
94+
NINE = 67,
95+
E0 = 68,
96+
E1 = 69,
97+
E2 = 70,
98+
E3 = 71,
99+
E4 = 72,
100+
E5 = 73,
101+
E6 = 74,
102+
E7 = 75,
103+
E8 = 76,
104+
E9 = 77,
105+
E10 = 78,
106+
E11 = 79,
107+
E12 = 80,
108+
BACK_SPACE = 81,
109+
INS = 82,
110+
HOME = 83,
111+
PG_UP = 84,
112+
NLCK = 85,
113+
SLASH = 86,
114+
ASTERISK = 87,
115+
MINUS = 88,
116+
ESC = 89,
117+
F1 = 90,
118+
F2 = 91,
119+
F3 = 92,
120+
F4 = 93,
121+
F5 = 94,
122+
F6 = 95,
123+
F7 = 96,
124+
F8 = 97,
125+
F9 = 98,
126+
F10 = 99,
127+
F11 = 100,
128+
F12 = 101,
129+
PRINT = 102,
130+
SLCK = 103,
131+
PAUSE = 104,
132+
INTL0 = 105,
133+
INTL1 = 106,
134+
INTL2 = 107,
135+
INTL3 = 108,
136+
INTL4 = 109,
137+
INTL5 = 110,
138+
INTL6 = 111,
139+
INTL7 = 112,
140+
INTL8 = 113,
141+
INTL9 = 114,
142+
}
143+
}
144+
145+
// NOTE: This has no associated type in UEFI; They are all top-level defines.
146+
newtype_enum! {
147+
/// Key modifier values
148+
pub enum Modifier: u16 => {
149+
NULL = 0x0000,
150+
LEFT_CONTROL = 0x0001,
151+
RIGHT_CONTROL = 0x0002,
152+
LEFT_ALT = 0x0003,
153+
RIGHT_ALT = 0x0004,
154+
ALT_GR = 0x0005,
155+
INSERT = 0x0006,
156+
DELETE = 0x0007,
157+
PAGE_DOWN = 0x0008,
158+
PAGE_UP = 0x0009,
159+
HOME = 0x000A,
160+
END = 0x000B,
161+
LEFT_SHIFT = 0x000C,
162+
RIGHT_SHIFT = 0x000D,
163+
CAPS_LOCK = 0x000E,
164+
NUM_LOCK = 0x000F,
165+
LEFT_ARROW = 0x0010,
166+
RIGHT_ARROW = 0x0011,
167+
DOWN_ARROW = 0x0012,
168+
UP_ARROW = 0x0013,
169+
NS_KEY = 0x0014,
170+
NS_KEY_DEPENDENCY = 0x0015,
171+
FUNCTION_KEY_ONE = 0x0016,
172+
FUNCTION_KEY_TWO = 0x0017,
173+
FUNCTION_KEY_THREE = 0x0018,
174+
FUNCTION_KEY_FOUR = 0x0019,
175+
FUNCTION_KEY_FIVE = 0x001A,
176+
FUNCTION_KEY_SIX = 0x001B,
177+
FUNCTION_KEY_SEVEN = 0x001C,
178+
FUNCTION_KEY_EIGHT = 0x001D,
179+
FUNCTION_KEY_NINE = 0x001E,
180+
FUNCTION_KEY_TEN = 0x001F,
181+
FUNCTION_KEY_ELEVEN = 0x0020,
182+
FUNCTION_KEY_TWELVE = 0x0021,
183+
PRINT = 0x0022,
184+
SYS_REQUEST = 0x0023,
185+
SCROLL_LOCK = 0x0024,
186+
PAUSE = 0x0025,
187+
BREAK = 0x0026,
188+
LEFT_LOGO = 0x0027,
189+
RIGHT_LOGO = 0x0028,
190+
MENU = 0x0029,
191+
}
192+
}
193+
194+
/// EFI_KEY_DESCRIPTOR
195+
#[derive(Debug)]
196+
#[repr(C)]
197+
pub struct KeyDescriptor {
198+
pub key: Key,
199+
pub unicode: Char16,
200+
pub shifted_unicode: Char16,
201+
pub alt_gr_unicode: Char16,
202+
pub shifted_alt_gr_unicode: Char16,
203+
pub modifier: u16,
204+
pub affected_attribute: u16,
205+
}

uefi-raw/src/protocol/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub mod disk;
1111
pub mod driver;
1212
pub mod file_system;
1313
pub mod firmware_volume;
14+
pub mod hii;
1415
pub mod loaded_image;
1516
pub mod media;
1617
pub mod memory_protection;

0 commit comments

Comments
 (0)