diff --git a/uefi/CHANGELOG.md b/uefi/CHANGELOG.md index 397aa4672..7e7fcfd98 100644 --- a/uefi/CHANGELOG.md +++ b/uefi/CHANGELOG.md @@ -7,6 +7,7 @@ - Added `proto::hii::config::ConfigKeywordHandler`. - Added `proto::hii::config::HiiConfigAccess`. - Added `proto::hii::config_str::ConfigurationString`. +- Added `proto::hii::database::HiiDatabase`. ## Changed - **Breaking:** `boot::stall` now take `core::time::Duration` instead of `usize`. diff --git a/uefi/src/proto/hii/database.rs b/uefi/src/proto/hii/database.rs new file mode 100644 index 000000000..8c1688132 --- /dev/null +++ b/uefi/src/proto/hii/database.rs @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 + +//! HII Database protocol. + +use alloc::boxed::Box; +use uefi_macros::unsafe_protocol; +use uefi_raw::protocol::hii::database::HiiDatabaseProtocol; + +use crate::mem::make_boxed; +use crate::{Error, StatusExt}; + +/// The HII Configuration Access Protocol. +/// +/// This protocol grants access to the HII database definition available in every UEFI firmware. +/// This database contains internationalized strings, as well as a description of all +/// supported BIOS settings, together with their logic (e.g.: option A blocks option B if value is `true`). +/// +/// # UEFI Spec Description +/// +/// Database manager for HII-related data structures. +#[derive(Debug)] +#[repr(transparent)] +#[unsafe_protocol(HiiDatabaseProtocol::GUID)] +pub struct HiiDatabase(HiiDatabaseProtocol); + +impl HiiDatabase { + /// Export all package lists as raw byte buffer. + pub fn export_all_raw(&self) -> crate::Result> { + fn fetch_data_fn<'a>( + proto: &HiiDatabase, + buf: &'a mut [u8], + ) -> Result<&'a mut [u8], Error>> { + unsafe { + let mut size = buf.len(); + let status = { + (proto.0.export_package_lists)( + &proto.0, + core::ptr::null_mut(), + &mut size, + buf.as_mut_ptr().cast(), + ) + }; + status.to_result_with_err(|_| Some(size)).map(|_| buf) + } + } + + #[cfg(not(feature = "unstable"))] + let buf = make_boxed::<[u8], _>(|buf| fetch_data_fn(self, buf))?; + + #[cfg(feature = "unstable")] + let buf = make_boxed::<[u8], _, _>(|buf| fetch_data_fn(self, buf), alloc::alloc::Global)?; + + Ok(buf) + } +} diff --git a/uefi/src/proto/hii/mod.rs b/uefi/src/proto/hii/mod.rs index bdece1069..c7ab0dfbf 100644 --- a/uefi/src/proto/hii/mod.rs +++ b/uefi/src/proto/hii/mod.rs @@ -5,3 +5,5 @@ pub mod config; #[cfg(feature = "alloc")] pub mod config_str; +#[cfg(feature = "alloc")] +pub mod database;