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