Skip to content

Commit 974053e

Browse files
committed
Add (partial) safe protocol implementation for EFI_HII_DATABASE_PROTOCOL
This only grants access to the HII-database's raw buffer for now.
1 parent a4b852f commit 974053e

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

uefi/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Added `proto::hii::config::ConfigKeywordHandler`.
88
- Added `proto::hii::config::HiiConfigAccess`.
99
- Added `proto::hii::config_str::ConfigurationString`.
10+
- Added `proto::hii::database::HiiDatabase`.
1011

1112
## Changed
1213
- **Breaking:** `boot::stall` now take `core::time::Duration` instead of `usize`.

uefi/src/proto/hii/database.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
3+
//! HII Database protocol.
4+
5+
use alloc::vec::Vec;
6+
use uefi_macros::unsafe_protocol;
7+
use uefi_raw::{Status, protocol::hii::database::HiiDatabaseProtocol};
8+
9+
use crate::StatusExt;
10+
11+
/// The HII Configuration Access Protocol.
12+
///
13+
/// # UEFI Spec Description
14+
///
15+
/// Database manager for HII-related data structures.
16+
#[derive(Debug)]
17+
#[repr(transparent)]
18+
#[unsafe_protocol(HiiDatabaseProtocol::GUID)]
19+
pub struct HiiDatabase(HiiDatabaseProtocol);
20+
21+
impl HiiDatabase {
22+
/// Export all package lists as raw byte buffer.
23+
#[must_use]
24+
pub fn export_all_raw(&self) -> crate::Result<Vec<u8>> {
25+
// call the function with a buffer_size of 0 first, so it will fail with
26+
// BUFFER_TOO_SMALL to tell us what size is required.
27+
let mut buffer_size = 0;
28+
unsafe {
29+
let result = (self.0.export_package_lists)(
30+
&self.0,
31+
core::ptr::null_mut(),
32+
&mut buffer_size,
33+
core::ptr::null_mut(),
34+
);
35+
assert_eq!(result, Status::BUFFER_TOO_SMALL);
36+
}
37+
38+
// allocate buffer with the requested size and call the method again
39+
let mut buffer = Vec::with_capacity(buffer_size);
40+
buffer.resize(buffer_size, 0u8);
41+
unsafe {
42+
(self.0.export_package_lists)(
43+
&self.0,
44+
core::ptr::null_mut(),
45+
&mut buffer_size,
46+
buffer.as_mut_ptr().cast(),
47+
)
48+
.to_result_with_val(|| buffer)
49+
}
50+
}
51+
}

uefi/src/proto/hii/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
pub mod config;
66
#[cfg(feature = "alloc")]
77
pub mod config_str;
8+
#[cfg(feature = "alloc")]
9+
pub mod database;

0 commit comments

Comments
 (0)