Skip to content
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-raw/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Added `HiiConfigAccessProtocol`.
- Added `::octets()` for `Ipv4Address`, `Ipv6Address`, and
`MacAddress` to streamline the API with `core::net`.
- Added `HiiConfigRoutingProtocol`.

## Changed
- **Breaking:** The MSRV is now 1.85.1 and the crate uses the Rust 2024 edition.
Expand Down
48 changes: 48 additions & 0 deletions uefi-raw/src/protocol/hii/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use core::fmt::Debug;

use crate::protocol::device_path::DevicePathProtocol;
use crate::{Char16, Guid, Status, guid};

/// EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL
Expand Down Expand Up @@ -172,3 +173,50 @@ pub struct HiiConfigAccessProtocol {
impl HiiConfigAccessProtocol {
pub const GUID: Guid = guid!("330d4706-f2a0-4e4f-a369-b66fa8d54385");
}

/// EFI_HII_CONFIG_ROUTING_PROTOCOL
#[derive(Debug)]
#[repr(C)]
pub struct HiiConfigRoutingProtocol {
pub extract_config: unsafe extern "efiapi" fn(
this: *const Self,
config_request: *const Char16,
progress: *mut *const Char16,
results: *mut *const Char16,
) -> Status,
pub export_config:
unsafe extern "efiapi" fn(this: *const Self, results: *mut *const Char16) -> Status,
pub route_config: unsafe extern "efiapi" fn(
this: *const Self,
configuration: *const Char16,
progress: *mut *const Char16,
) -> Status,
pub block_to_config: unsafe extern "efiapi" fn(
this: *const Self,
config_request: *const Char16,
block: *const u8,
block_size: usize,
config: *mut *const Char16,
progress: *mut *const Char16,
) -> Status,
pub config_to_block: unsafe extern "efiapi" fn(
this: *const Self,
config_resp: *const Char16,
block: *mut *const u8,
block_size: *mut usize,
progress: *mut *const Char16,
) -> Status,
pub get_alt_cfg: unsafe extern "efiapi" fn(
this: *const Self,
config_resp: *const Char16,
guid: *const Guid,
name: *const Char16,
device_path: *const DevicePathProtocol,
alt_cfg_id: *const Char16,
alt_cfg_resp: *mut *const Char16,
) -> Status,
}

impl HiiConfigRoutingProtocol {
pub const GUID: Guid = guid!("587e72d7-cc50-4f79-8209-ca291fc1a10f");
}
2 changes: 2 additions & 0 deletions uefi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
- Added `proto::hii::config_str::ConfigurationString`.
- Added `proto::acpi::AcpiTable`.
- Added `proto::hii::database::HiiDatabase`.
- Added `proto::hii::config_str::MultiConfigurationStringIter`.
- Added `proto::hii::config_routing::HiiConfigRouting`.

## Changed
- **Breaking:** `boot::stall` now take `core::time::Duration` instead of `usize`.
Expand Down
22 changes: 21 additions & 1 deletion uefi/src/mem/aligned_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use alloc::alloc::{Layout, LayoutError, alloc, dealloc};
use core::error::Error;
use core::fmt;
use core::ptr::NonNull;
use core::{fmt, slice};

/// Helper class to maintain the lifetime of a memory region allocated with a non-standard alignment.
/// Facilitates RAII to properly deallocate when lifetime of the object ends.
Expand Down Expand Up @@ -51,6 +51,18 @@ impl AlignedBuffer {
self.ptr.as_ptr()
}

/// Get the underlying memory region as immutable slice.
#[must_use]
pub const fn as_slice(&mut self) -> &[u8] {
unsafe { slice::from_raw_parts(self.ptr(), self.size()) }
}

/// Get the underlying memory region as mutable slice.
#[must_use]
pub const fn as_slice_mut(&mut self) -> &mut [u8] {
unsafe { slice::from_raw_parts_mut(self.ptr_mut(), self.size()) }
}

/// Get the size of the aligned memory region managed by this instance.
#[must_use]
pub const fn size(&self) -> usize {
Expand All @@ -67,6 +79,14 @@ impl AlignedBuffer {
}
}

/// Fill the aligned memory region with data from the given iterator.
/// If the given iterator is shorter than the buffer, the remaining area will be left untouched.
pub fn copy_from_iter(&mut self, src: impl Iterator<Item = u8>) {
src.take(self.size())
.zip(self.as_slice_mut().iter_mut())
.for_each(|(src, dst)| *dst = src);
}

/// Check the buffer's alignment against the `required_alignment`.
pub fn check_alignment(&self, required_alignment: usize) -> Result<(), AlignmentError> {
//TODO: use bfr.addr() when it's available
Expand Down
38 changes: 38 additions & 0 deletions uefi/src/proto/hii/config_routing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: MIT OR Apache-2.0

//! HII Configuration protocols.

use core::ptr;

use alloc::string::{String, ToString};
use uefi_macros::unsafe_protocol;
use uefi_raw::Char16;
use uefi_raw::protocol::hii::config::HiiConfigRoutingProtocol;

use crate::{CStr16, StatusExt};

/// The HII Configuration Routing Protocol.
///
/// # UEFI Spec Description
///
/// The EFI HII Configuration Routing Protocol manages the movement of configuration
/// data from drivers to configuration applications. It then serves as the single point
/// to receive configuration information from configuration applications, routing the results
/// to the appropriate drivers.
#[derive(Debug)]
#[repr(transparent)]
#[unsafe_protocol(HiiConfigRoutingProtocol::GUID)]
pub struct HiiConfigRouting(HiiConfigRoutingProtocol);
impl HiiConfigRouting {
/// Request the current configuration for the entirety of the current HII database and
/// return the data as string in multi configuration string format.
///
/// Use `super::config_str::MultiConfigurationStringIter` to parse the returned `String`.
pub fn export(&self) -> uefi::Result<String> {
unsafe {
let mut results: *const Char16 = ptr::null();
(self.0.export_config)(&self.0, &mut results)
.to_result_with_val(|| CStr16::from_ptr(results.cast()).to_string())
}
}
}
Loading
Loading