Skip to content

Commit 96848f4

Browse files
committed
uefi-raw: Add bindings for more HII protocols
Add bindings for the following UEFI 2.11 protocols: - Font (EFI_HII_FONT_PROTOCOL) - Font Ex (EFI_HII_FONT_EX_PROTOCOL) - String (EFI_HII_STRING_PROTOCOL) - Image (EFI_HII_IMAGE_PROTOCOL) - Image Ex (EFI_HII_IMAGE_EX_PROTOCOL) Ref: UEFI 2.11: 34 HII Protocols Signed-off-by: Tim Crawford <tcrawford@system76.com>
1 parent 2fc1b45 commit 96848f4

File tree

6 files changed

+438
-4
lines changed

6 files changed

+438
-4
lines changed

uefi-raw/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Added
44

5+
- Added `HiiFontProtocol`, `HiiFontExProtocol`.
6+
- Added `HiiImageProtocol`, `HiiImageExProtocol`.
7+
- Added `HiiStringProtocol`.
8+
59
## Changed
610

711

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
use core::fmt::Debug;
66

7+
use super::{FormId, QuestionId, StringId};
78
use crate::protocol::device_path::DevicePathProtocol;
89
use crate::{Boolean, Char16, Guid, Status, guid, newtype_enum};
910

@@ -141,10 +142,6 @@ impl core::fmt::Debug for IfrTypeValue {
141142
}
142143
}
143144

144-
pub type QuestionId = u16;
145-
pub type FormId = u16;
146-
pub type StringId = u16;
147-
148145
/// EFI_HII_CONFIG_ACCESS_PROTOCOL
149146
#[derive(Debug)]
150147
#[repr(C)]

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

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
3+
//! Bindings for HII Font protocols and data types
4+
5+
use super::{HiiHandle, StringId};
6+
use crate::protocol::console::GraphicsOutputBltPixel;
7+
use crate::protocol::hii::image::ImageOutput;
8+
use crate::{Char8, Char16, Guid, Status, guid};
9+
10+
pub type FontHandle = *mut core::ffi::c_void;
11+
12+
#[derive(Debug)]
13+
#[repr(C)]
14+
pub struct HiiGlyphInfo {
15+
pub width: u16,
16+
pub height: u16,
17+
pub offset_x: i16,
18+
pub offset_y: i16,
19+
pub advance_x: i16,
20+
}
21+
22+
bitflags::bitflags! {
23+
/// EFI_FONT_INFO_MASK
24+
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
25+
#[repr(transparent)]
26+
pub struct FontInfoMask: u32 {
27+
const SYS_FONT = 1 << 0;
28+
const SYS_SIZE = 1 << 1;
29+
const SYS_STYLE = 1 << 2;
30+
const SYS_FORE_COLOR = 1 << 4;
31+
const SYS_BACK_COLOR = 1 << 5;
32+
const RESIZE = 1 << 12;
33+
const RESTYLE = 1 << 13;
34+
const ANY_FONT = 1 << 16;
35+
const ANY_SIZE = 1 << 17;
36+
const ANY_STYLE = 1 << 18;
37+
}
38+
}
39+
40+
bitflags::bitflags! {
41+
/// EFI_HII_FONT_STYLE
42+
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
43+
#[repr(transparent)]
44+
pub struct HiiFontStyle: u32 {
45+
const NORMAL = 0;
46+
const BOLD = 1 << 0;
47+
const ITALIC = 1 << 1;
48+
const EMBOSS = 1 << 16;
49+
const OUTLINE = 1 << 17;
50+
const SHADOW = 1 << 18;
51+
const UNDERLINE = 1 << 19;
52+
const DBL_UNDER = 1 << 20;
53+
}
54+
}
55+
56+
/// EFI_FONT_INFO
57+
#[derive(Debug)]
58+
#[repr(C)]
59+
pub struct FontInfo {
60+
pub font_style: HiiFontStyle,
61+
pub font_size: u16,
62+
pub font_name: [Char16; 0],
63+
}
64+
65+
/// EFI_FONT_DISPLAY_INFO
66+
#[derive(Debug)]
67+
#[repr(C)]
68+
pub struct FontDisplayInfo {
69+
pub foreground_color: GraphicsOutputBltPixel,
70+
pub background_color: GraphicsOutputBltPixel,
71+
pub font_mask_info: FontInfoMask,
72+
pub font_info: FontInfo,
73+
}
74+
75+
bitflags::bitflags! {
76+
/// EFI_HII_OUT_FLAGS
77+
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
78+
#[repr(transparent)]
79+
pub struct HiiOutFlags: u32 {
80+
const CLIP = 1 << 0;
81+
const WRAP = 1 << 1;
82+
const CLIP_CLEAN_Y = 1 << 2;
83+
const CLIP_CLEAN_X = 1 << 3;
84+
const TRANSPARENT = 1 << 4;
85+
const IGNORE_IF_NO_GLYPH = 1 << 5;
86+
const IGNORE_LINE_BREAK = 1 << 6;
87+
const DIRECT_TO_SCREEN = 1 << 7;
88+
}
89+
}
90+
91+
/// EFI_HII_ROW_INFO
92+
#[derive(Debug)]
93+
#[repr(C)]
94+
pub struct HiiRowInfo {
95+
pub start_index: usize,
96+
pub end_index: usize,
97+
pub line_height: usize,
98+
pub line_width: usize,
99+
pub baseline_offset: usize,
100+
}
101+
102+
/// EFI_HII_FONT_PROTOCOL
103+
#[derive(Debug)]
104+
#[repr(C)]
105+
pub struct HiiFontProtocol {
106+
pub string_to_image: unsafe extern "efiapi" fn(
107+
this: *const Self,
108+
flags: HiiOutFlags,
109+
string: *const Char16,
110+
string_info: *const FontDisplayInfo,
111+
blt: *mut *mut ImageOutput,
112+
blt_x: usize,
113+
blt_y: usize,
114+
row_info_array: *mut *mut HiiRowInfo,
115+
row_info_array_size: *mut usize,
116+
column_info_array: *mut usize,
117+
) -> Status,
118+
pub string_id_to_image: unsafe extern "efiapi" fn(
119+
this: *const Self,
120+
flags: HiiOutFlags,
121+
package_list: HiiHandle,
122+
string_id: StringId,
123+
language: *const Char8,
124+
string_info: *const FontDisplayInfo,
125+
blt: *mut *mut ImageOutput,
126+
blt_x: usize,
127+
blt_y: usize,
128+
row_info_array: *mut *mut HiiRowInfo,
129+
row_info_array_size: *mut usize,
130+
column_info_array: *mut usize,
131+
) -> Status,
132+
pub get_glyph: unsafe extern "efiapi" fn(
133+
this: *const Self,
134+
char: Char16,
135+
string_info: *const FontDisplayInfo,
136+
blt: *mut *mut ImageOutput,
137+
baseline: *mut usize,
138+
) -> Status,
139+
pub get_font_info: unsafe extern "efiapi" fn(
140+
this: *const Self,
141+
font_handle: *mut FontHandle,
142+
string_info_in: *const FontDisplayInfo,
143+
string_info_out: *mut *mut FontDisplayInfo,
144+
string: *const Char16,
145+
) -> Status,
146+
}
147+
148+
impl HiiFontProtocol {
149+
pub const GUID: Guid = guid!("e9ca4775-8657-47fc-97e7-7ed65a084324");
150+
}
151+
152+
// NOTE: This protocol is declared in the UEFI spec, but not defined in edk2.
153+
/// EFI_HII_FONT_EX_PROTOCOL
154+
#[derive(Debug)]
155+
#[repr(C)]
156+
pub struct HiiFontExProtocol {
157+
pub string_to_image_ex: unsafe extern "efiapi" fn(
158+
this: *const Self,
159+
flags: HiiOutFlags,
160+
string: *const Char16,
161+
string_info: *const FontDisplayInfo,
162+
blt: *mut *mut ImageOutput,
163+
blt_x: usize,
164+
blt_y: usize,
165+
row_info_array: *mut *mut HiiRowInfo,
166+
row_info_array_size: *mut usize,
167+
column_info_array: *mut usize,
168+
) -> Status,
169+
pub string_id_to_image_ex: unsafe extern "efiapi" fn(
170+
this: *const Self,
171+
flags: HiiOutFlags,
172+
package_list: HiiHandle,
173+
string_id: StringId,
174+
language: *const Char8,
175+
string_info: *const FontDisplayInfo,
176+
blt: *mut *mut ImageOutput,
177+
blt_x: usize,
178+
blt_y: usize,
179+
row_info_array: *mut *mut HiiRowInfo,
180+
row_info_array_size: *mut usize,
181+
column_info_array: *mut usize,
182+
) -> Status,
183+
pub get_glyph_ex: unsafe extern "efiapi" fn(
184+
this: *const Self,
185+
char: Char16,
186+
string_info: *const FontDisplayInfo,
187+
blt: *mut *mut ImageOutput,
188+
baseline: *mut usize,
189+
) -> Status,
190+
pub get_font_info_ex: unsafe extern "efiapi" fn(
191+
this: *const Self,
192+
font_handle: *mut FontHandle,
193+
string_info_in: *const FontDisplayInfo,
194+
string_info_out: *mut *mut FontDisplayInfo,
195+
string: *const Char16,
196+
) -> Status,
197+
pub get_glyph_info: unsafe extern "efiapi" fn(
198+
this: *const Self,
199+
char: Char16,
200+
font_display_info: *const FontDisplayInfo,
201+
glyph_info: *mut HiiGlyphInfo,
202+
) -> Status,
203+
}
204+
205+
impl HiiFontExProtocol {
206+
pub const GUID: Guid = guid!("849e6875-db35-4df8-b41e-c8f33718073f");
207+
}

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

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
3+
//! Bindings for HII Image protocols and data types
4+
5+
use super::{HiiHandle, ImageId};
6+
use crate::protocol::console::{GraphicsOutputBltPixel, GraphicsOutputProtocol};
7+
use crate::{Guid, Status, guid};
8+
use core::fmt;
9+
10+
bitflags::bitflags! {
11+
/// EFI_HII_DRAW_FLAGS
12+
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
13+
#[repr(transparent)]
14+
pub struct HiiDrawFlags: u32 {
15+
const DEFAULT = 0;
16+
const CLIP = 1 << 0;
17+
const FORCE_TRANS = 1 << 4;
18+
const FORCE_OPAQUE = 1 << 5;
19+
const TRANSPARENT = Self::FORCE_TRANS.bits() | Self::FORCE_OPAQUE.bits();
20+
const DIRECT_TO_SCREEN = 1 << 7;
21+
}
22+
}
23+
24+
/// EFI_IMAGE_INPUT
25+
#[derive(Debug)]
26+
#[repr(C)]
27+
pub struct ImageInput {
28+
pub flags: u32,
29+
pub width: u16,
30+
pub height: u16,
31+
pub bitmap: *const GraphicsOutputBltPixel,
32+
}
33+
34+
#[repr(C)]
35+
pub union ImageOutputDest {
36+
pub bitmap: *mut GraphicsOutputBltPixel,
37+
pub screen: *mut GraphicsOutputProtocol,
38+
}
39+
40+
impl fmt::Debug for ImageOutputDest {
41+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
42+
// This is a union type, so we can't access the internal data.
43+
f.debug_struct("ImageOutputDest").finish()
44+
}
45+
}
46+
47+
impl Default for ImageOutputDest {
48+
fn default() -> Self {
49+
Self {
50+
bitmap: core::ptr::null_mut(),
51+
}
52+
}
53+
}
54+
55+
/// EFI_IMAGE_OUTPUT
56+
#[derive(Debug)]
57+
#[repr(C)]
58+
pub struct ImageOutput {
59+
pub width: u16,
60+
pub height: u16,
61+
pub image: ImageOutputDest,
62+
}
63+
64+
/// EFI_HII_IMAGE_PROTOCOL
65+
#[derive(Debug)]
66+
#[repr(C)]
67+
pub struct HiiImageProtocol {
68+
pub new_image: unsafe extern "efiapi" fn(
69+
this: *const Self,
70+
package_list: HiiHandle,
71+
image_id: *mut ImageId,
72+
image: *const ImageInput,
73+
) -> Status,
74+
pub get_image: unsafe extern "efiapi" fn(
75+
this: *const Self,
76+
package_list: HiiHandle,
77+
image_id: ImageId,
78+
image: *mut ImageInput,
79+
) -> Status,
80+
pub set_image: unsafe extern "efiapi" fn(
81+
this: *const Self,
82+
package_list: HiiHandle,
83+
image_id: ImageId,
84+
image: *const ImageInput,
85+
) -> Status,
86+
pub draw_image: unsafe extern "efiapi" fn(
87+
this: *const Self,
88+
flags: HiiDrawFlags,
89+
image: *const ImageInput,
90+
blt: *mut *mut ImageOutput,
91+
blt_x: usize,
92+
blt_y: usize,
93+
) -> Status,
94+
pub draw_image_id: unsafe extern "efiapi" fn(
95+
this: *const Self,
96+
flags: HiiDrawFlags,
97+
package_list: HiiHandle,
98+
image_id: ImageId,
99+
blt: *mut *mut ImageOutput,
100+
blt_x: usize,
101+
blt_y: usize,
102+
) -> Status,
103+
}
104+
105+
impl HiiImageProtocol {
106+
pub const GUID: Guid = guid!("31a6406a-6bdf-4e46-b2a2-ebaa89c40920");
107+
}
108+
109+
/// EFI_HII_IMAGE_EX_PROTOCOL
110+
#[derive(Debug)]
111+
#[repr(C)]
112+
pub struct HiiImageExProtocol {
113+
// NOTE: UEFI 2.11 declares `image` as an inout value; edk2 declares it as
114+
// an input-only value, matching the non-extended protocol version.
115+
pub new_image_ex: unsafe extern "efiapi" fn(
116+
this: *const Self,
117+
package_list: HiiHandle,
118+
image_id: *mut ImageId,
119+
image: *const ImageInput,
120+
) -> Status,
121+
pub get_image_ex: unsafe extern "efiapi" fn(
122+
this: *const Self,
123+
package_list: HiiHandle,
124+
image_id: ImageId,
125+
image: *mut ImageInput,
126+
) -> Status,
127+
pub set_image_ex: unsafe extern "efiapi" fn(
128+
this: *const Self,
129+
package_list: HiiHandle,
130+
image_id: ImageId,
131+
image: *const ImageInput,
132+
) -> Status,
133+
pub draw_image_ex: unsafe extern "efiapi" fn(
134+
this: *const Self,
135+
flags: HiiDrawFlags,
136+
image: *const ImageInput,
137+
blt: *mut *mut ImageOutput,
138+
blt_x: usize,
139+
blt_y: usize,
140+
) -> Status,
141+
pub draw_image_id_ex: unsafe extern "efiapi" fn(
142+
this: *const Self,
143+
flags: HiiDrawFlags,
144+
package_list: HiiHandle,
145+
image_id: ImageId,
146+
blt: *mut *mut ImageOutput,
147+
blt_x: usize,
148+
blt_y: usize,
149+
) -> Status,
150+
pub get_image_info: unsafe extern "efiapi" fn(
151+
this: *const Self,
152+
package_list: HiiHandle,
153+
image_id: ImageId,
154+
image: *mut ImageOutput,
155+
) -> Status,
156+
}
157+
158+
impl HiiImageExProtocol {
159+
pub const GUID: Guid = guid!("1a1241e6-8f19-41a9-bc0e-e8ef39e06546");
160+
}

0 commit comments

Comments
 (0)