Skip to content

Add (partial) safe protocol implementation for EFI_HII_DATABASE_PROTOCOL #1719

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
55 changes: 55 additions & 0 deletions uefi/src/proto/hii/database.rs
Original file line number Diff line number Diff line change
@@ -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<Box<[u8]>> {
fn fetch_data_fn<'a>(
proto: &HiiDatabase,
buf: &'a mut [u8],
) -> Result<&'a mut [u8], Error<Option<usize>>> {
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)
}
}
2 changes: 2 additions & 0 deletions uefi/src/proto/hii/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
pub mod config;
#[cfg(feature = "alloc")]
pub mod config_str;
#[cfg(feature = "alloc")]
pub mod database;
Loading