Skip to content

Commit dc86148

Browse files
committed
device/acpi: More correctness fixes
1 parent 79d1924 commit dc86148

3 files changed

Lines changed: 22 additions & 13 deletions

File tree

kernel/src/arch/x86_64/system/acpi.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ impl PortIoAccess {
102102
unsafe {
103103
asm::write32(
104104
0xCF8,
105-
(addr.bus as u32) << 16
106-
| (addr.slot as u32) << 11
107-
| (addr.function as u32) << 8
108-
| (offset & 0xFC)
109-
| 1 << 31,
105+
1 << 31
106+
| (addr.bus as u32) << 16
107+
| (addr.slot as u32 & 0x1F) << 11
108+
| (addr.function as u32 & 0x7) << 8
109+
| (offset & 0xFC),
110110
);
111111
}
112112
}

kernel/src/device/acpi/mcfg.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use crate::{
77
};
88
use alloc::{boxed::Box, vec::Vec};
99
use uacpi_sys::{
10-
UACPI_STATUS_OK, acpi_mcfg, acpi_mcfg_allocation, acpi_sdt_hdr, uacpi_table,
11-
uacpi_table_find_by_signature, uacpi_table_unref,
10+
UACPI_STATUS_OK, acpi_mcfg, acpi_mcfg_allocation, uacpi_table, uacpi_table_find_by_signature,
11+
uacpi_table_unref,
1212
};
1313

1414
#[task(
@@ -30,7 +30,7 @@ pub fn MCFG_STAGE() {
3030
let mcfg_ptr = table.__bindgen_anon_1.ptr as *const uacpi_sys::acpi_mcfg;
3131
let mcfg = mcfg_ptr.read_unaligned();
3232

33-
let entry_count = (mcfg.hdr.length as usize - size_of::<acpi_sdt_hdr>())
33+
let entry_count = (mcfg.hdr.length as usize).saturating_sub(size_of::<acpi_mcfg>())
3434
/ size_of::<acpi_mcfg_allocation>();
3535

3636
let mut accesses = Vec::new();

kernel/src/device/acpi/mod.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,24 @@ mod uacpi;
88
static RSDP_ADDRESS: Once<PhysAddr> = Once::new();
99

1010
#[task(
11-
name = "device.acpi.tables",
11+
name = "device.acpi.root",
1212
depends = [crate::memory::MEMORY_STAGE],
1313
)]
14-
pub fn TABLES_STAGE() {
14+
pub fn ACPI_ROOT() -> bool {
1515
match BootInfo::get().rsdp_addr {
16-
Some(rsdp) => unsafe { RSDP_ADDRESS.init(rsdp) },
17-
None => panic!("No RSDP available, unable to initialize the ACPI subsystem!"),
18-
};
16+
Some(x) => {
17+
unsafe { RSDP_ADDRESS.init(x) };
18+
true
19+
}
20+
None => false,
21+
}
22+
}
1923

24+
#[task(
25+
name = "device.acpi.tables",
26+
depends = [ACPI_ROOT],
27+
)]
28+
pub fn TABLES_STAGE() {
2029
// Get an early table window so we can initialize e.g. HPET and MADT.
2130
let early_mem = Box::leak(Box::<[u8]>::new_uninit_slice(4096));
2231

0 commit comments

Comments
 (0)