aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / vendor / uefi / src / proto / acpi.rs
| 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 | // SAFETY: The memory is valid. |
| 53 | let status = unsafe { |
| 54 | (self.0.install_acpi_table)(&self.0, acpi_table_ptr, acpi_table_size, &mut table_key) |
| 55 | }; |
| 56 | status.to_result_with_val(|| table_key) |
| 57 | } |
| 58 | |
| 59 | /// Removes an ACPI table from the RSDT/XSDT. |
| 60 | /// |
| 61 | /// # Errors |
| 62 | /// |
| 63 | /// * [`Status::NOT_FOUND`]: `table_key` does not refer to a |
| 64 | /// valid key for a table entry. |
| 65 | /// |
| 66 | /// * [`Status::OUT_OF_RESOURCES`]: Insufficient resources exist |
| 67 | /// to complete the request. |
| 68 | /// |
| 69 | /// [`Status::NOT_FOUND`]: crate::Status::NOT_FOUND |
| 70 | /// [`Status::OUT_OF_RESOURCES`]: crate::Status::OUT_OF_RESOURCES |
| 71 | pub fn uninstall_acpi_table(&self, table_key: usize) -> Result { |
| 72 | // SAFETY: The memory is valid. |
| 73 | unsafe { (self.0.uninstall_acpi_table)(&self.0, table_key) }.to_result() |
| 74 | } |
| 75 | } |