Skip to content

Commit 6331744

Browse files
committed
acpi: don't gate allocator_api on a feature
1 parent b5bb2a5 commit 6331744

File tree

6 files changed

+53
-71
lines changed

6 files changed

+53
-71
lines changed

acpi/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ bitflags = "2.5.0"
1515
log = "0.4.20"
1616

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

acpi/src/lib.rs

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@
5353
*/
5454

5555
#![no_std]
56-
#![deny(unsafe_op_in_unsafe_fn)]
57-
#![cfg_attr(feature = "allocator_api", feature(allocator_api))]
56+
#![feature(allocator_api)]
5857

5958
#[cfg_attr(test, macro_use)]
6059
#[cfg(test)]
@@ -69,35 +68,28 @@ pub mod fadt;
6968
pub mod handler;
7069
pub mod hpet;
7170
pub mod madt;
71+
pub mod managed_slice;
7272
pub mod mcfg;
73+
pub mod platform;
7374
pub mod rsdp;
7475
pub mod sdt;
7576
pub mod spcr;
7677

77-
#[cfg(feature = "allocator_api")]
78-
mod managed_slice;
79-
#[cfg(feature = "allocator_api")]
80-
pub use managed_slice::*;
81-
82-
#[cfg(feature = "allocator_api")]
83-
pub mod platform;
84-
#[cfg(feature = "allocator_api")]
85-
pub use crate::platform::{interrupt::InterruptModel, PlatformInfo};
86-
87-
#[cfg(feature = "allocator_api")]
88-
pub use crate::mcfg::PciConfigRegions;
89-
78+
pub use crate::{
79+
mcfg::PciConfigRegions,
80+
platform::{interrupt::InterruptModel, PlatformInfo},
81+
};
9082
pub use fadt::PowerProfile;
9183
pub use handler::{AcpiHandler, PhysicalMapping};
9284
pub use hpet::HpetInfo;
9385
pub use madt::MadtError;
9486

9587
use crate::sdt::{SdtHeader, Signature};
96-
use core::mem;
88+
use core::{alloc::Allocator, mem};
9789
use rsdp::Rsdp;
9890

9991
/// Result type used by error-returning functions.
100-
pub type AcpiResult<T> = core::result::Result<T, AcpiError>;
92+
pub type AcpiResult<T> = Result<T, AcpiError>;
10193

10294
/// All types representing ACPI tables should implement this trait.
10395
///
@@ -179,13 +171,9 @@ macro_rules! read_root_table {
179171
}};
180172
}
181173

182-
/// Type capable of enumerating the existing ACPI tables on the system.
183-
///
184-
///
185-
/// ### Implementation Note
186-
///
187-
/// When using the `allocator_api`±`alloc` features, [`PlatformInfo::new()`] or [`PlatformInfo::new_in()`] provide
188-
/// a much cleaner API for enumerating ACPI structures once an `AcpiTables` has been constructed.
174+
/// `AcpiTables` represents all of the enumerable ACPI tables on the system, and is the main type
175+
/// to construct and use from the crate. `PlatformInfo` provides a higher-level interface to some
176+
/// of the data contained in the tables, and may be easier to use for common use-cases.
189177
#[derive(Debug)]
190178
pub struct AcpiTables<H: AcpiHandler> {
191179
mapping: PhysicalMapping<H, SdtHeader>,
@@ -376,12 +364,11 @@ where
376364
PlatformInfo::new(self)
377365
}
378366

379-
/// Convenience method for contructing a [`PlatformInfo`]. This is one of the first things you should usually do
367+
/// Construct a [`PlatformInfo`]. This is one of the first things you should usually do
380368
/// with an `AcpiTables`, and allows to collect helpful information about the platform from the ACPI tables.
381-
#[cfg(feature = "allocator_api")]
382369
pub fn platform_info_in<A>(&self, allocator: A) -> AcpiResult<PlatformInfo<A>>
383370
where
384-
A: core::alloc::Allocator + Clone,
371+
A: Allocator + Clone,
385372
{
386373
PlatformInfo::new_in(self, allocator)
387374
}

acpi/src/madt.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
use crate::{
2+
managed_slice::ManagedSlice,
3+
platform::{
4+
interrupt::{InterruptModel, Polarity, TriggerMode},
5+
ProcessorInfo,
6+
},
27
sdt::{ExtendedField, SdtHeader, Signature},
38
AcpiError,
9+
AcpiResult,
410
AcpiTable,
511
};
612
use bit_field::BitField;
713
use core::{
14+
alloc::Allocator,
815
marker::{PhantomData, PhantomPinned},
916
mem,
1017
pin::Pin,
1118
};
1219

13-
#[cfg(feature = "allocator_api")]
14-
use crate::{
15-
platform::{
16-
interrupt::{InterruptModel, Polarity, TriggerMode},
17-
ProcessorInfo,
18-
},
19-
AcpiResult,
20-
};
21-
2220
#[derive(Debug)]
2321
pub enum MadtError {
2422
UnexpectedEntry,
@@ -69,13 +67,12 @@ impl Madt {
6967
Err(AcpiError::InvalidMadt(MadtError::UnexpectedEntry))
7068
}
7169

72-
#[cfg(feature = "allocator_api")]
7370
pub fn parse_interrupt_model_in<A>(
7471
self: Pin<&Self>,
7572
allocator: A,
7673
) -> AcpiResult<(InterruptModel<A>, Option<ProcessorInfo<A>>)>
7774
where
78-
A: core::alloc::Allocator + Clone,
75+
A: Allocator + Clone,
7976
{
8077
/*
8178
* We first do a pass through the MADT to determine which interrupt model is being used.
@@ -114,13 +111,12 @@ impl Madt {
114111
Ok((InterruptModel::Unknown, None))
115112
}
116113

117-
#[cfg(feature = "allocator_api")]
118114
fn parse_apic_model_in<A>(
119115
self: Pin<&Self>,
120116
allocator: A,
121117
) -> AcpiResult<(InterruptModel<A>, Option<ProcessorInfo<A>>)>
122118
where
123-
A: core::alloc::Allocator + Clone,
119+
A: Allocator + Clone,
124120
{
125121
use crate::platform::{
126122
interrupt::{
@@ -157,12 +153,11 @@ impl Madt {
157153
}
158154
}
159155

160-
let mut io_apics = crate::ManagedSlice::new_in(io_apic_count, allocator.clone())?;
161-
let mut interrupt_source_overrides = crate::ManagedSlice::new_in(iso_count, allocator.clone())?;
162-
let mut nmi_sources = crate::ManagedSlice::new_in(nmi_source_count, allocator.clone())?;
163-
let mut local_apic_nmi_lines = crate::ManagedSlice::new_in(local_nmi_line_count, allocator.clone())?;
164-
let mut application_processors =
165-
crate::ManagedSlice::new_in(processor_count.saturating_sub(1), allocator)?; // Subtract one for the BSP
156+
let mut io_apics = ManagedSlice::new_in(io_apic_count, allocator.clone())?;
157+
let mut interrupt_source_overrides = ManagedSlice::new_in(iso_count, allocator.clone())?;
158+
let mut nmi_sources = ManagedSlice::new_in(nmi_source_count, allocator.clone())?;
159+
let mut local_apic_nmi_lines = ManagedSlice::new_in(local_nmi_line_count, allocator.clone())?;
160+
let mut application_processors = ManagedSlice::new_in(processor_count.saturating_sub(1), allocator)?; // Subtract one for the BSP
166161
let mut boot_processor = None;
167162

168163
io_apic_count = 0;
@@ -678,20 +673,19 @@ pub struct MultiprocessorWakeupMailbox {
678673
pub reserved_for_firmware: [u64; 256],
679674
}
680675

681-
#[cfg(feature = "allocator_api")]
682-
fn parse_mps_inti_flags(flags: u16) -> crate::AcpiResult<(Polarity, TriggerMode)> {
676+
fn parse_mps_inti_flags(flags: u16) -> AcpiResult<(Polarity, TriggerMode)> {
683677
let polarity = match flags.get_bits(0..2) {
684678
0b00 => Polarity::SameAsBus,
685679
0b01 => Polarity::ActiveHigh,
686680
0b11 => Polarity::ActiveLow,
687-
_ => return Err(crate::AcpiError::InvalidMadt(MadtError::MpsIntiInvalidPolarity)),
681+
_ => return Err(AcpiError::InvalidMadt(MadtError::MpsIntiInvalidPolarity)),
688682
};
689683

690684
let trigger_mode = match flags.get_bits(2..4) {
691685
0b00 => TriggerMode::SameAsBus,
692686
0b01 => TriggerMode::Edge,
693687
0b11 => TriggerMode::Level,
694-
_ => return Err(crate::AcpiError::InvalidMadt(MadtError::MpsIntiInvalidTriggerMode)),
688+
_ => return Err(AcpiError::InvalidMadt(MadtError::MpsIntiInvalidTriggerMode)),
695689
};
696690

697691
Ok((polarity, trigger_mode))

acpi/src/mcfg.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,47 @@
11
use crate::{
2+
managed_slice::ManagedSlice,
23
sdt::{SdtHeader, Signature},
4+
AcpiHandler,
5+
AcpiResult,
36
AcpiTable,
7+
AcpiTables,
48
};
5-
use core::{mem, slice};
9+
use core::{alloc::Allocator, fmt, mem, ops::RangeInclusive, slice};
610

711
/// Describes a set of regions of physical memory used to access the PCIe configuration space. A
812
/// region is created for each entry in the MCFG. Given the segment group, bus, device number, and
913
/// function of a PCIe device, the `physical_address` method on this will give you the physical
1014
/// address of the start of that device function's configuration space (each function has 4096
1115
/// bytes of configuration space in PCIe).
12-
#[cfg(feature = "allocator_api")]
1316
pub struct PciConfigRegions<A>
1417
where
15-
A: core::alloc::Allocator,
18+
A: Allocator,
1619
{
17-
regions: crate::ManagedSlice<McfgEntry, A>,
20+
regions: ManagedSlice<McfgEntry, A>,
1821
}
1922

2023
#[cfg(feature = "alloc")]
2124
impl<'a> PciConfigRegions<alloc::alloc::Global> {
22-
pub fn new<H>(tables: &crate::AcpiTables<H>) -> crate::AcpiResult<PciConfigRegions<alloc::alloc::Global>>
25+
pub fn new<H>(tables: &AcpiTables<H>) -> AcpiResult<PciConfigRegions<alloc::alloc::Global>>
2326
where
24-
H: crate::AcpiHandler,
27+
H: AcpiHandler,
2528
{
2629
Self::new_in(tables, alloc::alloc::Global)
2730
}
2831
}
2932

30-
#[cfg(feature = "allocator_api")]
3133
impl<A> PciConfigRegions<A>
3234
where
33-
A: core::alloc::Allocator,
35+
A: Allocator,
3436
{
35-
pub fn new_in<H>(tables: &crate::AcpiTables<H>, allocator: A) -> crate::AcpiResult<PciConfigRegions<A>>
37+
pub fn new_in<H>(tables: &AcpiTables<H>, allocator: A) -> AcpiResult<PciConfigRegions<A>>
3638
where
37-
H: crate::AcpiHandler,
39+
H: AcpiHandler,
3840
{
3941
let mcfg = tables.find_table::<Mcfg>()?;
4042
let mcfg_entries = mcfg.entries();
4143

42-
let mut regions = crate::ManagedSlice::new_in(mcfg_entries.len(), allocator)?;
44+
let mut regions = ManagedSlice::new_in(mcfg_entries.len(), allocator)?;
4345
regions.copy_from_slice(mcfg_entries);
4446

4547
Ok(Self { regions })
@@ -74,7 +76,7 @@ where
7476
/// Configuration entry describing a valid bus range for the given PCI segment group.
7577
pub struct PciConfigEntry {
7678
pub segment_group: u16,
77-
pub bus_range: core::ops::RangeInclusive<u8>,
79+
pub bus_range: RangeInclusive<u8>,
7880
pub physical_address: usize,
7981
}
8082

@@ -121,8 +123,8 @@ impl Mcfg {
121123
pub fn entries(&self) -> &[McfgEntry] {
122124
let length = self.header.length as usize - mem::size_of::<Mcfg>();
123125

124-
// Intentionally round down in case length isn't an exact multiple of McfgEntry size
125-
// (see rust-osdev/acpi#58)
126+
// Intentionally round down in case length isn't an exact multiple of McfgEntry size - this
127+
// has been observed on real hardware (see rust-osdev/acpi#58)
126128
let num_entries = length / mem::size_of::<McfgEntry>();
127129

128130
unsafe {
@@ -132,8 +134,8 @@ impl Mcfg {
132134
}
133135
}
134136

135-
impl core::fmt::Debug for Mcfg {
136-
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
137+
impl fmt::Debug for Mcfg {
138+
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
137139
formatter.debug_struct("Mcfg").field("header", &self.header).field("entries", &self.entries()).finish()
138140
}
139141
}

acpi/src/platform/interrupt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::ManagedSlice;
1+
use crate::managed_slice::ManagedSlice;
22
use core::alloc::Allocator;
33

44
#[derive(Debug, Clone, Copy)]

acpi/src/platform/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use crate::{
44
address::GenericAddress,
55
fadt::Fadt,
66
madt::{Madt, MadtError, MpProtectedModeWakeupCommand, MultiprocessorWakeupMailbox},
7+
managed_slice::ManagedSlice,
78
AcpiError,
89
AcpiHandler,
910
AcpiResult,
1011
AcpiTables,
11-
ManagedSlice,
1212
PowerProfile,
1313
};
1414
use core::{alloc::Allocator, mem, ptr};

0 commit comments

Comments
 (0)