Skip to content

Commit

Permalink
rework crate to allocationless (rust-osdev#131)
Browse files Browse the repository at this point in the history
Rework crate to allocationless

An overall rework of structures to make the crate allocationless.
However, a new feature `allocator_api` has been added in addition
to these changes, which allows use of `PlatformInfo` and some other
allocating structures, by providing a `core::alloc::Allocator` in the
constructor of these types. This allows semantic interfacing with
existing allocation APIs, while also ensuring we aren't using the
`alloc` crate allocation behaviour by default, as it isn't very
extensible for use in bare-metal development contexts.
  • Loading branch information
zdivelbiss authored Oct 31, 2022
1 parent f31466c commit c0e4593
Show file tree
Hide file tree
Showing 12 changed files with 568 additions and 284 deletions.
5 changes: 4 additions & 1 deletion acpi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ license = "MIT/Apache-2.0"
edition = "2018"

[dependencies]
log = "0.4"
bit_field = "0.10"
rsdp = { version = "2", path = "../rsdp" }

[features]
default = ["allocator_api"]
allocator_api = []
2 changes: 1 addition & 1 deletion acpi/src/platform/address.rs → acpi/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub struct GenericAddress {
}

impl GenericAddress {
pub(crate) fn from_raw(raw: RawGenericAddress) -> Result<GenericAddress, AcpiError> {
pub(crate) fn from_raw(raw: RawGenericAddress) -> crate::AcpiResult<GenericAddress> {
let address_space = match raw.address_space {
0x00 => AddressSpace::SystemMemory,
0x01 => AddressSpace::SystemIo,
Expand Down
10 changes: 8 additions & 2 deletions acpi/src/bgrt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{sdt::SdtHeader, AcpiTable};
use crate::{
sdt::{SdtHeader, Signature},
AcpiTable,
};
use bit_field::BitField;

/// The BGRT table contains information about a boot graphic that was displayed
Expand All @@ -15,7 +18,10 @@ pub struct Bgrt {
image_offset_y: u32,
}

impl AcpiTable for Bgrt {
/// ### Safety: Implementation properly represents a valid BGRT.
unsafe impl AcpiTable for Bgrt {
const SIGNATURE: Signature = Signature::BGRT;

fn header(&self) -> &SdtHeader {
&self.header
}
Expand Down
11 changes: 7 additions & 4 deletions acpi/src/fadt.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::{
platform::address::{AccessSize, AddressSpace, GenericAddress, RawGenericAddress},
sdt::{ExtendedField, SdtHeader},
address::{AccessSize, AddressSpace, GenericAddress, RawGenericAddress},
sdt::{ExtendedField, SdtHeader, Signature},
AcpiError,
AcpiTable,
};
use bit_field::BitField;

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PowerProfile {
Unspecified,
Desktop,
Expand Down Expand Up @@ -115,7 +115,10 @@ pub struct Fadt {
hypervisor_vendor_id: ExtendedField<u64, 2>,
}

impl AcpiTable for Fadt {
/// ### Safety: Implementation properly represents a valid FADT.
unsafe impl AcpiTable for Fadt {
const SIGNATURE: Signature = Signature::FADT;

fn header(&self) -> &SdtHeader {
&self.header
}
Expand Down
22 changes: 14 additions & 8 deletions acpi/src/hpet.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
use crate::{platform::address::RawGenericAddress, sdt::SdtHeader, AcpiError, AcpiHandler, AcpiTable, AcpiTables};
use crate::{
address::RawGenericAddress,
sdt::{SdtHeader, Signature},
AcpiError,
AcpiHandler,
AcpiTable,
AcpiTables,
};
use bit_field::BitField;

#[derive(Debug)]
Expand Down Expand Up @@ -28,13 +35,9 @@ impl HpetInfo {
where
H: AcpiHandler,
{
let hpet = unsafe {
tables
.get_sdt::<HpetTable>(crate::sdt::Signature::HPET)?
.ok_or(AcpiError::TableMissing(crate::sdt::Signature::HPET))?
};
let hpet = tables.find_table::<HpetTable>()?;

// Make sure the HPET's in system memory
// Make sure the HPET is in system memory
assert_eq!(hpet.base_address.address_space, 0);

Ok(HpetInfo {
Expand Down Expand Up @@ -86,7 +89,10 @@ pub struct HpetTable {
page_protection_and_oem: u8,
}

impl AcpiTable for HpetTable {
/// ### Safety: Implementation properly represents a valid HPET table.
unsafe impl AcpiTable for HpetTable {
const SIGNATURE: Signature = Signature::HPET;

fn header(&self) -> &SdtHeader {
&self.header
}
Expand Down
Loading

0 comments on commit c0e4593

Please sign in to comment.