Skip to content

Commit 932bae5

Browse files
committed
acpi: add alloc feature for easy use of the global allocator
Most people won't care much about the "new" `allocator_api` work, so add `new` methods that just use the globally-set allocator too.
1 parent c86972d commit 932bae5

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

acpi/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ log = "0.4"
1515
rsdp = { version = "2", path = "../rsdp" }
1616

1717
[features]
18-
default = ["allocator_api"]
18+
default = ["allocator_api", "alloc"]
1919
allocator_api = []
20+
alloc = ["allocator_api"]

acpi/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! the `aml` crate, which is the (much less complete) AML parser used to parse the DSDT and SSDTs. These crates
88
//! are separate because some kernels may want to detect the static tables, but delay AML parsing to a later stage.
99
//!
10+
//! TODO: make this correct re alloc features
1011
//! This crate requires `alloc` to make heap allocations. If you are trying to find the RSDP in an environment that
1112
//! does not have a heap (e.g. a bootloader), you can use the `rsdp` crate. The types from that crate are
1213
//! compatible with `acpi`.
@@ -55,6 +56,9 @@
5556
#[cfg(test)]
5657
extern crate std;
5758

59+
#[cfg(feature = "alloc")]
60+
extern crate alloc;
61+
5862
pub mod address;
5963
pub mod bgrt;
6064
pub mod fadt;
@@ -318,6 +322,16 @@ where
318322
SsdtIterator { tables_phys_ptrs: self.tables_phys_ptrs(), handler: self.handler.clone() }
319323
}
320324

325+
/// Convenience method for contructing a [`PlatformInfo`](crate::platform::PlatformInfo). This is one of the
326+
/// first things you should usually do with an `AcpiTables`, and allows to collect helpful information about
327+
/// the platform from the ACPI tables.
328+
///
329+
/// Like `platform_info_in`, but uses the global allocator.
330+
#[cfg(feature = "alloc")]
331+
pub fn platform_info(&self) -> AcpiResult<PlatformInfo<alloc::alloc::Global>> {
332+
PlatformInfo::new_in(self, alloc::alloc::Global)
333+
}
334+
321335
/// Convenience method for contructing a [`PlatformInfo`](crate::platform::PlatformInfo). This is one of the
322336
/// first things you should usually do with an `AcpiTables`, and allows to collect helpful information about
323337
/// the platform from the ACPI tables.

acpi/src/managed_slice.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ where
3333
}
3434
}
3535

36+
#[cfg(feature = "alloc")]
37+
impl<'a, T> ManagedSlice<'a, T, alloc::alloc::Global> {
38+
pub fn new(len: usize) -> AcpiResult<Self> {
39+
Self::new_in(len, alloc::alloc::Global)
40+
}
41+
}
42+
3643
impl<'a, T, A> Drop for ManagedSlice<'a, T, A>
3744
where
3845
A: Allocator,

acpi/src/mcfg.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ where
1717
regions: crate::ManagedSlice<'a, McfgEntry, A>,
1818
}
1919

20+
#[cfg(feature = "alloc")]
21+
impl<'a> PciConfigRegions<'a, alloc::alloc::Global> {
22+
pub fn new<H>(tables: &crate::AcpiTables<H>) -> crate::AcpiResult<PciConfigRegions<'a, alloc::alloc::Global>>
23+
where
24+
H: crate::AcpiHandler,
25+
{
26+
Self::new_in(tables, alloc::alloc::Global)
27+
}
28+
}
29+
2030
#[cfg(feature = "allocator_api")]
2131
impl<'a, A> PciConfigRegions<'a, A>
2232
where

0 commit comments

Comments
 (0)