Skip to content

uefi-raw: hii: Add Database Protocol #1510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions uefi-raw/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Added `DriverBindingProtocol`.
- Added `FirmwareVolume2Protocol`.
- Added `FirmwareVolumeBlock2Protocol`.
- Added `HiiDatabaseProtocol`.


# uefi-raw - 0.9.0 (2024-10-23)
Expand Down
98 changes: 98 additions & 0 deletions uefi-raw/src/protocol/hii/database.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
//! Bindings for HII Database Protocol

use super::{HiiHandle, HiiPackageHeader, HiiPackageListHeader, KeyDescriptor};
use crate::{guid, Guid, Handle, Status};

/// EFI_HII_KEYBOARD_LAYOUT
#[derive(Debug)]
#[repr(C)]
pub struct HiiKeyboardLayout {
pub layout_length: u16,
pub guid: Guid,
pub layout_descriptor_string_offset: u32,
pub descriptor_count: u8,
pub descriptors: [KeyDescriptor; 0],
}

newtype_enum! {
/// EFI_HII_DATABASE_NOTIFY_TYPE
pub enum HiiDatabaseNotifyType: usize => {
NEW_PACK = 1 << 0,
REMOVE_PACK = 1 << 1,
EXPORT_PACK = 1 << 2,
ADD_PACK = 1 << 3,
}
}

/// EFI_HII_DATABASE_NOTIFY
pub type HiiDatabaseNotifyFn = unsafe extern "efiapi" fn(
package_type: u8,
package_guid: *const Guid,
package: *const HiiPackageHeader,
handle: HiiHandle,
notify_type: HiiDatabaseNotifyType,
) -> Status;

/// EFI_HII_DATABASE_PROTOCOL
#[derive(Debug)]
#[repr(C)]
pub struct HiiDatabaseProtocol {
pub new_package_list: unsafe extern "efiapi" fn(
this: *const Self,
package_list: *const HiiPackageListHeader,
driver_handle: Handle,
handle: *mut HiiHandle,
) -> Status,
pub remove_package_list:
unsafe extern "efiapi" fn(this: *const Self, handle: HiiHandle) -> Status,
pub update_package_list: unsafe extern "efiapi" fn(
this: *const Self,
handle: HiiHandle,
package_list: *const HiiPackageListHeader,
) -> Status,
pub list_package_lists: unsafe extern "efiapi" fn(
this: *const Self,
package_type: u8,
package_guid: *const Guid,
handle_buffer_length: *mut usize,
handle: *mut HiiHandle,
) -> Status,
pub export_package_lists: unsafe extern "efiapi" fn(
this: *const Self,
handle: HiiHandle,
buffer_size: *mut usize,
buffer: *mut HiiPackageListHeader,
) -> Status,
pub register_package_notify: unsafe extern "efiapi" fn(
this: *const Self,
package_type: u8,
package_guid: *const Guid,
package_notify_fn: HiiDatabaseNotifyFn,
notify_type: HiiDatabaseNotifyType,
notify_handle: *mut Handle,
) -> Status,
pub unregister_package_notify:
unsafe extern "efiapi" fn(this: *const Self, notification_handle: Handle) -> Status,
pub find_keyboard_layouts: unsafe extern "efiapi" fn(
this: *const Self,
key_guid_buffer_length: *mut u16,
key_guid_buffer: *mut Guid,
) -> Status,
pub get_keyboard_layout: unsafe extern "efiapi" fn(
this: *const Self,
key_guid: *const Guid,
leyboard_layout_length: *mut u16,
keyboard_layout: *mut HiiKeyboardLayout,
) -> Status,
pub set_keyboard_layout:
unsafe extern "efiapi" fn(this: *const Self, key_guid: *const Guid) -> Status,
pub get_package_list_handle: unsafe extern "efiapi" fn(
this: *const Self,
package_list_handle: HiiHandle,
driver_handle: *mut Handle,
) -> Status,
}

impl HiiDatabaseProtocol {
pub const GUID: Guid = guid!("ef9fc172-a1b2-4693-b327-6d32fc416042");
}
206 changes: 206 additions & 0 deletions uefi-raw/src/protocol/hii/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
//! HII Protocols

pub mod database;

use crate::{Char16, Guid};

pub type HiiHandle = *mut core::ffi::c_void;

/// EFI_HII_PACKAGE_HEADER
#[derive(Debug)]
#[repr(C)]
pub struct HiiPackageHeader {
pub length_and_type: u32,
pub data: [u8; 0],
}

/// EFI_HII_PACKAGE_LIST_HEADER
#[derive(Debug)]
#[repr(C)]
pub struct HiiPackageListHeader {
pub package_list_guid: Guid,
pub package_length: u32,
}

newtype_enum! {
/// EFI_KEY: A physical key on a keyboard.
pub enum Key: u32 => {
LCTRL = 0,
A0 = 1,
LALT = 2,
SPACEBAR = 3,
A2 = 4,
A3 = 5,
A4 = 6,
RCTRL = 7,
LEFT_ARROW = 8,
DOWN_ARROW = 9,
RIGHT_ARROW = 10,
ZERO = 11,
PERIOD = 12,
ENTER = 13,
LSHIFT = 14,
B0 = 15,
B1 = 16,
B2 = 17,
B3 = 18,
B4 = 19,
B5 = 20,
B6 = 21,
B7 = 22,
B8 = 23,
B9 = 24,
B10 = 25,
RSHIFT = 26,
UP_ARROW = 27,
ONE = 28,
TWO = 29,
THREE = 30,
CAPS_LOCK = 31,
C1 = 32,
C2 = 33,
C3 = 34,
C4 = 35,
C5 = 36,
C6 = 37,
C7 = 38,
C8 = 39,
C9 = 40,
C10 = 41,
C11 = 42,
C12 = 43,
FOUR = 44,
FIVE = 45,
SIX = 46,
PLUS = 47,
TAB = 48,
D1 = 49,
D2 = 50,
D3 = 51,
D4 = 52,
D5 = 53,
D6 = 54,
D7 = 55,
D8 = 56,
D9 = 57,
D10 = 58,
D11 = 59,
D12 = 60,
D13 = 61,
DEL = 62,
END = 63,
PG_DN = 64,
SEVEN = 65,
EIGHT = 66,
NINE = 67,
E0 = 68,
E1 = 69,
E2 = 70,
E3 = 71,
E4 = 72,
E5 = 73,
E6 = 74,
E7 = 75,
E8 = 76,
E9 = 77,
E10 = 78,
E11 = 79,
E12 = 80,
BACK_SPACE = 81,
INS = 82,
HOME = 83,
PG_UP = 84,
NLCK = 85,
SLASH = 86,
ASTERISK = 87,
MINUS = 88,
ESC = 89,
F1 = 90,
F2 = 91,
F3 = 92,
F4 = 93,
F5 = 94,
F6 = 95,
F7 = 96,
F8 = 97,
F9 = 98,
F10 = 99,
F11 = 100,
F12 = 101,
PRINT = 102,
SLCK = 103,
PAUSE = 104,
INTL0 = 105,
INTL1 = 106,
INTL2 = 107,
INTL3 = 108,
INTL4 = 109,
INTL5 = 110,
INTL6 = 111,
INTL7 = 112,
INTL8 = 113,
INTL9 = 114,
}
}

// NOTE: This has no associated type in UEFI; They are all top-level defines.
newtype_enum! {
/// Key modifier values
pub enum Modifier: u16 => {
NULL = 0x0000,
LEFT_CONTROL = 0x0001,
RIGHT_CONTROL = 0x0002,
LEFT_ALT = 0x0003,
RIGHT_ALT = 0x0004,
ALT_GR = 0x0005,
INSERT = 0x0006,
DELETE = 0x0007,
PAGE_DOWN = 0x0008,
PAGE_UP = 0x0009,
HOME = 0x000A,
END = 0x000B,
LEFT_SHIFT = 0x000C,
RIGHT_SHIFT = 0x000D,
CAPS_LOCK = 0x000E,
NUM_LOCK = 0x000F,
LEFT_ARROW = 0x0010,
RIGHT_ARROW = 0x0011,
DOWN_ARROW = 0x0012,
UP_ARROW = 0x0013,
NS_KEY = 0x0014,
NS_KEY_DEPENDENCY = 0x0015,
FUNCTION_KEY_ONE = 0x0016,
FUNCTION_KEY_TWO = 0x0017,
FUNCTION_KEY_THREE = 0x0018,
FUNCTION_KEY_FOUR = 0x0019,
FUNCTION_KEY_FIVE = 0x001A,
FUNCTION_KEY_SIX = 0x001B,
FUNCTION_KEY_SEVEN = 0x001C,
FUNCTION_KEY_EIGHT = 0x001D,
FUNCTION_KEY_NINE = 0x001E,
FUNCTION_KEY_TEN = 0x001F,
FUNCTION_KEY_ELEVEN = 0x0020,
FUNCTION_KEY_TWELVE = 0x0021,
PRINT = 0x0022,
SYS_REQUEST = 0x0023,
SCROLL_LOCK = 0x0024,
PAUSE = 0x0025,
BREAK = 0x0026,
LEFT_LOGO = 0x0027,
RIGHT_LOGO = 0x0028,
MENU = 0x0029,
}
}

/// EFI_KEY_DESCRIPTOR
#[derive(Debug)]
#[repr(C)]
pub struct KeyDescriptor {
pub key: Key,
pub unicode: Char16,
pub shifted_unicode: Char16,
pub alt_gr_unicode: Char16,
pub shifted_alt_gr_unicode: Char16,
pub modifier: u16,
pub affected_attribute: u16,
}
1 change: 1 addition & 0 deletions uefi-raw/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod disk;
pub mod driver;
pub mod file_system;
pub mod firmware_volume;
pub mod hii;
pub mod loaded_image;
pub mod media;
pub mod memory_protection;
Expand Down
Loading