Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 71b6be3

Browse files
protocols: Add ACPI Table protocol
1 parent 4ada0f6 commit 71b6be3

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed

‎uefi-raw/src/protocol/acpi.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
3+
use crate::{Guid, Status, guid};
4+
use core::ffi::c_void;
5+
6+
#[derive(Clone, Copy, Debug)]
7+
#[repr(C)]
8+
pub struct AcpiTableProtocol {
9+
pub install_acpi_table: unsafe extern "efiapi" fn(
10+
this: *const Self,
11+
acpi_table_buffer: *const c_void,
12+
acpi_table_size: usize,
13+
table_key: *mut usize,
14+
) -> Status,
15+
pub uninstall_acpi_table:
16+
unsafe extern "efiapi" fn(this: *const Self, table_key: usize) -> Status,
17+
}
18+
19+
impl AcpiTableProtocol {
20+
pub const GUID: Guid = guid!("ffe06bdd-6107-46a6-7bb2-5a9c7ec5275c");
21+
}

‎uefi-raw/src/protocol/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
//!
2424
//! [`GUID`]: crate::Guid
2525
26+
pub mod acpi;
2627
pub mod ata;
2728
pub mod block;
2829
pub mod console;

‎uefi/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Added `proto::hii::config::ConfigKeywordHandler`.
88
- Added `proto::hii::config::HiiConfigAccess`.
99
- Added `proto::hii::config_str::ConfigurationString`.
10+
- Added `proto::acpi::AcpiTable`.
1011

1112
## Changed
1213
- **Breaking:** `boot::stall` now take `core::time::Duration` instead of `usize`.

‎uefi/src/proto/acpi.rs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
3+
//! `AcpiTable` protocol.
4+
5+
use crate::proto::unsafe_protocol;
6+
use crate::{Result, StatusExt};
7+
use core::ffi::c_void;
8+
use core::mem::MaybeUninit;
9+
use uefi_raw::protocol::acpi::AcpiTableProtocol;
10+
11+
/// The AcpiTable protocol.
12+
#[derive(Debug)]
13+
#[repr(transparent)]
14+
#[unsafe_protocol(AcpiTableProtocol::GUID)]
15+
pub struct AcpiTable(AcpiTableProtocol);
16+
17+
impl AcpiTable {
18+
/// Installs an ACPI table into the RSDT/XSDT. Returns a index
19+
/// that may be used by `uninstall_acpi_table` to remove the ACPI
20+
/// table.
21+
///
22+
/// # Safety
23+
///
24+
/// When installing ACI table, the data pointed to by
25+
/// `acpi_table_ptr` must be a pool allocation of type
26+
/// [`ACPI_RECLAIM`] or other type suitable for data handed off to
27+
/// the OS.
28+
///
29+
/// [`ACPI_RECLAIM`]: crate::boot::MemoryType::ACPI_RECLAIM
30+
///
31+
/// # Errors
32+
///
33+
/// * [`Status::INVALID_PARAMETER`]: `acpi_table_ptr` is null; the
34+
/// `acpi_table_size`, and the size field embedded in the ACPI
35+
/// table are not in sync.
36+
///
37+
/// * [`Status::OUT_OF_RESOURCES`]: Insufficient resources
38+
/// exist to complete the request.
39+
///
40+
/// * [`Status::ACCESS_DENIED`]: The table signature matches a
41+
/// table already present in the system and platform policy does
42+
/// not allow duplicate tables of this type.
43+
///
44+
/// [`Status::INVALID_PARAMETER`]: crate::Status::INVALID_PARAMETER
45+
/// [`Status::OUT_OF_RESOURCES`]: crate::Status::OUT_OF_RESOURCES
46+
/// [`Status::ACCESS_DENIED`]: crate::Status::ACCESS_DENIED
47+
pub unsafe fn install_acpi_table(
48+
&self,
49+
acpi_table_ptr: *const c_void,
50+
acpi_table_size: usize,
51+
) -> Result<usize> {
52+
let mut table_key = MaybeUninit::<usize>::uninit();
53+
let status = unsafe {
54+
(self.0.install_acpi_table)(
55+
&self.0 as *const AcpiTableProtocol,
56+
acpi_table_ptr,
57+
acpi_table_size,
58+
table_key.as_mut_ptr(),
59+
)
60+
};
61+
status.to_result_with_val(|| unsafe { table_key.assume_init() })
62+
}
63+
64+
/// Removes an ACPI table from the RSDT/XSDT.
65+
///
66+
/// # Errors
67+
///
68+
/// * [`Status::NOT_FOUND`]: `table_key` does not refer to a
69+
/// valid key for a table entry.
70+
///
71+
/// * [`Status::OUT_OF_RESOURCES`]: Insufficient resources exist
72+
/// to complete the request.
73+
///
74+
/// [`Status::NOT_FOUND`]: crate::Status::NOT_FOUND
75+
/// [`Status::OUT_OF_RESOURCES`]: crate::Status::OUT_OF_RESOURCES
76+
pub fn uninstall_acpi_table(&self, table_key: usize) -> Result {
77+
unsafe { (self.0.uninstall_acpi_table)(&self.0 as *const AcpiTableProtocol, table_key) }
78+
.to_result()
79+
}
80+
}

‎uefi/src/proto/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
//! [`boot`]: crate::boot#accessing-protocols
3232
//! [UEFI protocols]: uefi_raw::protocol
3333
34+
pub mod acpi;
3435
#[cfg(feature = "alloc")]
3536
pub mod ata;
3637
pub mod console;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /