|
| 1 | +// SPDX-License-Identifier: MIT OR Apache-2.0 |
| 2 | + |
| 3 | +//! HII Database protocol. |
| 4 | +
|
| 5 | +use alloc::boxed::Box; |
| 6 | +use uefi_macros::unsafe_protocol; |
| 7 | +use uefi_raw::protocol::hii::database::HiiDatabaseProtocol; |
| 8 | + |
| 9 | +use crate::mem::make_boxed; |
| 10 | +use crate::{Error, StatusExt}; |
| 11 | + |
| 12 | +/// The HII Configuration Access Protocol. |
| 13 | +/// |
| 14 | +/// This protocol grants access to the HII database definition available in every UEFI firmware. |
| 15 | +/// This database contains internationalized strings, as well as a description of all |
| 16 | +/// supported BIOS settings, together with their logic (e.g.: option A blocks option B if value is `true`). |
| 17 | +/// |
| 18 | +/// # UEFI Spec Description |
| 19 | +/// |
| 20 | +/// Database manager for HII-related data structures. |
| 21 | +#[derive(Debug)] |
| 22 | +#[repr(transparent)] |
| 23 | +#[unsafe_protocol(HiiDatabaseProtocol::GUID)] |
| 24 | +pub struct HiiDatabase(HiiDatabaseProtocol); |
| 25 | + |
| 26 | +impl HiiDatabase { |
| 27 | + /// Export all package lists as raw byte buffer. |
| 28 | + pub fn export_all_raw(&self) -> crate::Result<Box<[u8]>> { |
| 29 | + fn fetch_data_fn<'a>( |
| 30 | + proto: &HiiDatabase, |
| 31 | + buf: &'a mut [u8], |
| 32 | + ) -> Result<&'a mut [u8], Error<Option<usize>>> { |
| 33 | + unsafe { |
| 34 | + let mut size = buf.len(); |
| 35 | + let status = { |
| 36 | + (proto.0.export_package_lists)( |
| 37 | + &proto.0, |
| 38 | + core::ptr::null_mut(), |
| 39 | + &mut size, |
| 40 | + buf.as_mut_ptr().cast(), |
| 41 | + ) |
| 42 | + }; |
| 43 | + status.to_result_with_err(|_| Some(size)).map(|_| buf) |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + #[cfg(not(feature = "unstable"))] |
| 48 | + let buf = make_boxed::<[u8], _>(|buf| fetch_data_fn(self, buf))?; |
| 49 | + |
| 50 | + #[cfg(feature = "unstable")] |
| 51 | + let buf = make_boxed::<[u8], _, _>(|buf| fetch_data_fn(self, buf), alloc::alloc::Global)?; |
| 52 | + |
| 53 | + Ok(buf) |
| 54 | + } |
| 55 | +} |
0 commit comments