Skip to content

Add RuntimeServices::query_variable_info #396

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

Merged
merged 1 commit into from
Mar 31, 2022
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Added `FileHandle::into_directory` and `FileHandle::into_regular_file`.
- Added `TimeParams`, `Time::invalid`, and `Time::is_invalid`.
- Added `RuntimeServices::query_variable_info` and `VariableStorageInfo`.

### Changed

Expand Down
50 changes: 50 additions & 0 deletions src/table/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ pub struct RuntimeServices {
data_size: usize,
data: *const u8,
) -> !,

// UEFI 2.0 Capsule Services.
update_capsule: usize,
query_capsule_capabilities: usize,

// Miscellaneous UEFI 2.0 Service.
query_variable_info: unsafe extern "efiapi" fn(
attributes: VariableAttributes,
maximum_variable_storage_size: *mut u64,
remaining_variable_storage_size: *mut u64,
maximum_variable_size: *mut u64,
) -> Status,
}

impl RuntimeServices {
Expand Down Expand Up @@ -227,6 +239,26 @@ impl RuntimeServices {
}
}

/// Get information about UEFI variable storage space for the type
/// of variable specified in `attributes`.
///
/// See [`VariableStorageInfo`] for details of the information returned.
pub fn query_variable_info(
&self,
attributes: VariableAttributes,
) -> Result<VariableStorageInfo> {
let mut info = VariableStorageInfo::default();
unsafe {
(self.query_variable_info)(
attributes,
&mut info.maximum_variable_storage_size,
&mut info.remaining_variable_storage_size,
&mut info.maximum_variable_size,
)
.into_with_val(|| info)
}
}

/// Resets the computer.
pub fn reset(&self, rt: ResetType, status: Status, data: Option<&[u8]>) -> ! {
let (size, data) = match data {
Expand Down Expand Up @@ -619,6 +651,24 @@ impl fmt::Display for VariableKey {
}
}

/// Information about UEFI variable storage space returned by
/// [`RuntimeServices::query_variable_info`]. Note that the data here is
/// limited to a specific type of variable (as specified by the
/// `attributes` argument to `query_variable_info`).
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct VariableStorageInfo {
/// Maximum size in bytes of the storage space available for
/// variables of the specified type.
pub maximum_variable_storage_size: u64,

/// Remaining size in bytes of the storage space available for
/// variables of the specified type.
pub remaining_variable_storage_size: u64,

/// Maximum size of an individual variable of the specified type.
pub maximum_variable_size: u64,
}

/// The type of system reset.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[repr(u32)]
Expand Down
14 changes: 14 additions & 0 deletions uefi-test-runner/src/runtime/vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ fn test_variables(rt: &RuntimeServices) {
}
}

fn test_variable_info(rt: &RuntimeServices) {
info!(
"Storage for non-volatile variabls: {:?}",
rt.query_variable_info(VariableAttributes::NON_VOLATILE),
);
info!(
"Storage for volatile runtime variables: {:?}",
rt.query_variable_info(
VariableAttributes::BOOTSERVICE_ACCESS | VariableAttributes::RUNTIME_ACCESS
),
);
}

pub fn test(rt: &RuntimeServices) {
test_variables(rt);
test_variable_info(rt);
}