Use cfg! rather than #[cfg] for ACPI enabling

This commit is contained in:
bjorn3
2026-04-04 13:49:07 +02:00
parent 49d005b450
commit 62f220b1b9
10 changed files with 32 additions and 51 deletions
-2
View File
@@ -205,10 +205,8 @@ pub fn get_sdt_signature(sdt: &'static Sdt) -> SdtSignature {
pub struct Acpi {
pub hpet: RwLock<Option<Hpet>>,
pub next_ctx: RwLock<u64>,
}
pub static ACPI_TABLE: Acpi = Acpi {
hpet: RwLock::new(None),
next_ctx: RwLock::new(0),
};
+3 -9
View File
@@ -3,16 +3,13 @@ use core::{cell::SyncUnsafeCell, fmt, ptr};
use alloc::vec::Vec;
use spin::Mutex;
#[cfg(feature = "acpi")]
use super::{local_apic::ApicId, pic};
use crate::{
acpi::madt::{self, Madt, MadtEntry, MadtIntSrcOverride, MadtIoApic},
arch::{cpuid::cpuid, interrupt::irq},
memory::{map_device_memory, PhysicalAddress},
};
use crate::arch::{cpuid::cpuid, interrupt::irq};
use super::{local_apic::ApicId, pic};
pub struct IoApicRegs {
pointer: *const u32,
}
@@ -232,7 +229,6 @@ pub fn src_overrides() -> &'static [Override] {
.map_or(&[], |vector| &vector[..])
}
#[cfg(feature = "acpi")]
pub unsafe fn handle_ioapic(madt_ioapic: &'static MadtIoApic) {
unsafe {
// map the I/O APIC registers
@@ -250,7 +246,6 @@ pub unsafe fn handle_ioapic(madt_ioapic: &'static MadtIoApic) {
(*IOAPICS.get()).get_or_insert_with(Vec::new).push(ioapic);
}
}
#[cfg(feature = "acpi")]
pub unsafe fn handle_src_override(src_override: &'static MadtIntSrcOverride) {
unsafe {
let flags = src_override.flags;
@@ -295,8 +290,7 @@ pub unsafe fn init() {
)); // TODO: remove unwraps
// search the madt for all IOAPICs.
#[cfg(feature = "acpi")]
{
if cfg!(feature = "acpi") {
let madt: &'static Madt = match madt::madt() {
Some(m) => m,
// TODO: Parse MP tables too.
+4 -7
View File
@@ -1,7 +1,6 @@
use core::cell::Cell;
pub mod cpu;
#[cfg(feature = "acpi")]
pub mod hpet;
pub mod ioapic;
pub mod local_apic;
@@ -28,8 +27,11 @@ pub unsafe fn init_after_acpi() {
//ioapic::init(mapper);
}
#[cfg(feature = "acpi")]
unsafe fn init_hpet() -> bool {
if cfg!(not(feature = "acpi")) {
return false;
}
unsafe {
use crate::acpi::ACPI_TABLE;
match *ACPI_TABLE.hpet.write() {
@@ -46,11 +48,6 @@ unsafe fn init_hpet() -> bool {
}
}
#[cfg(not(feature = "acpi"))]
unsafe fn init_hpet() -> bool {
false
}
pub unsafe fn init_noncore() {
unsafe {
debug!("Initializing system timer");
+2 -6
View File
@@ -4,9 +4,6 @@
//! defined in other files inside of the `arch` module
use core::{arch::naked_asm, cell::SyncUnsafeCell, mem::offset_of};
#[cfg(feature = "acpi")]
use crate::acpi;
use crate::{
allocator, cpu_set::LogicalCpuId, device, devices::graphical_debug, gdt, idt, interrupt,
paging, startup::KernelArgs,
@@ -131,9 +128,8 @@ unsafe extern "C" fn start(args_ptr: *const KernelArgs, stack_end: usize) -> ! {
device::init();
// Read ACPI tables, starts APs
#[cfg(feature = "acpi")]
{
acpi::init(args.acpi_rsdp());
if cfg!(feature = "acpi") {
crate::acpi::init(args.acpi_rsdp());
device::init_after_acpi();
}
+7 -5
View File
@@ -1,9 +1,9 @@
#[cfg(feature = "acpi")]
use crate::{context, scheme::acpi, time};
use crate::{
context,
scheme::acpi,
sync::CleanLockToken,
syscall::io::{Io, Pio},
time,
};
pub unsafe fn kreset() -> ! {
@@ -58,8 +58,11 @@ pub unsafe fn emergency_reset() -> ! {
}
}
#[cfg(feature = "acpi")]
fn userspace_acpi_shutdown(token: &mut CleanLockToken) {
if cfg!(not(feature = "acpi")) {
return;
}
info!("Notifying any potential ACPI driver");
// Tell whatever driver that handles ACPI, that it should enter the S5 state (i.e.
// shutdown).
@@ -93,7 +96,6 @@ pub unsafe fn kstop(token: &mut CleanLockToken) -> ! {
unsafe {
info!("Running kstop()");
#[cfg(feature = "acpi")]
userspace_acpi_shutdown(token);
// Magic shutdown code for bochs and qemu (older versions).
+4 -6
View File
@@ -1,9 +1,6 @@
use super::device::{hpet, pit};
use crate::sync::CleanLockToken;
#[cfg(feature = "acpi")]
use super::device::hpet;
use super::device::pit;
pub fn monotonic_absolute(token: &mut CleanLockToken) -> u128 {
// The paravirtualized TSC is already guaranteed to be monotonic, and thus doesn't need to be
// readjusted.
@@ -16,8 +13,9 @@ pub fn monotonic_absolute(token: &mut CleanLockToken) -> u128 {
offset + hpet_or_pit()
}
fn hpet_or_pit() -> u128 {
#[cfg(feature = "acpi")]
if let Some(ref hpet) = *crate::acpi::ACPI_TABLE.hpet.read() {
if cfg!(feature = "acpi")
&& let Some(ref hpet) = *crate::acpi::ACPI_TABLE.hpet.read()
{
//TODO: handle rollover?
//TODO: improve performance
-1
View File
@@ -46,7 +46,6 @@ const PHYS_OFFSET: usize = <arch::CurrentRmmArch as ::rmm::Arch>::PHYS_OFFSET;
mod allocator;
/// ACPI table parsing
#[cfg(feature = "acpi")]
#[allow(dead_code)] // TODO
mod acpi;
+6 -4
View File
@@ -102,8 +102,10 @@ pub struct IrqScheme;
impl IrqScheme {
pub fn init() {
#[cfg(all(feature = "acpi", any(target_arch = "x86", target_arch = "x86_64")))]
let cpus = {
let cpus = if cfg!(all(
feature = "acpi",
any(target_arch = "x86", target_arch = "x86_64")
)) {
use crate::acpi::madt::*;
match madt() {
@@ -119,9 +121,9 @@ impl IrqScheme {
vec![0]
}
}
} else {
vec![0]
};
#[cfg(not(all(feature = "acpi", any(target_arch = "x86", target_arch = "x86_64"))))]
let cpus = vec![0];
CPUS.call_once(|| cpus);
}
+6 -10
View File
@@ -35,7 +35,6 @@ use crate::{
syscall::usercopy::{UserSliceRo, UserSliceRw, UserSliceWo},
};
#[cfg(feature = "acpi")]
use self::acpi::AcpiScheme;
#[cfg(dtb)]
use self::dtb::DtbScheme;
@@ -54,7 +53,6 @@ use self::{
};
/// When compiled with the "acpi" feature - `acpi:` - allows drivers to read a limited set of ACPI tables.
#[cfg(feature = "acpi")]
pub mod acpi;
#[cfg(dtb)]
pub mod dtb;
@@ -156,8 +154,9 @@ fn init_schemes() -> RwLock<L1, HashMap<SchemeId, Handle>> {
use GlobalSchemes::*;
insert_globals(&[Debug, Event, Memory, Pipe, Serio, Irq, Time, Sys, Proc]);
#[cfg(feature = "acpi")]
insert_globals(&[Acpi]);
if cfg!(feature = "acpi") {
insert_globals(&[Acpi]);
}
#[cfg(dtb)]
insert_globals(&[Dtb]);
@@ -418,7 +417,6 @@ pub const ALL_KERNEL_SCHEMES: &[GlobalSchemes] = &[
GlobalSchemes::Time,
GlobalSchemes::Sys,
GlobalSchemes::Proc,
#[cfg(feature = "acpi")]
GlobalSchemes::Acpi,
#[cfg(dtb)]
GlobalSchemes::Dtb,
@@ -446,12 +444,11 @@ impl SchemeExt for GlobalSchemes {
Self::Time => &TimeScheme,
Self::Sys => &SysScheme,
Self::Proc => &ProcScheme,
#[cfg(feature = "acpi")]
Self::Acpi => &AcpiScheme,
#[cfg(dtb)]
Self::Dtb => &DtbScheme,
#[cfg(not(all(feature = "acpi", dtb)))]
_ => panic!("Unknown global scheme"),
#[cfg(not(dtb))]
Self::Dtb => panic!("Unknown global scheme"),
}
}
fn scheme_id(self) -> SchemeId {
@@ -461,8 +458,7 @@ impl SchemeExt for GlobalSchemes {
#[cold]
pub fn init_globals() {
#[cfg(feature = "acpi")]
{
if cfg!(feature = "acpi") {
AcpiScheme::init();
}
#[cfg(dtb)]
-1
View File
@@ -84,7 +84,6 @@ impl KernelArgs {
}
}
#[cfg(feature = "acpi")]
pub(crate) fn acpi_rsdp(&self) -> Option<*const u8> {
if self.hwdesc_base != 0 {
let data = unsafe {