Use RmmA::phys_to_virt instead of PHYS_OFFSET in the acpi code

This commit is contained in:
bjorn3
2026-04-04 13:33:26 +02:00
parent 2fba663274
commit 49d005b450
7 changed files with 35 additions and 27 deletions
+5 -5
View File
@@ -69,11 +69,11 @@ pub(super) fn init(madt: Madt) {
let cpu_id = LogicalCpuId::next();
// Allocate a stack
let stack_start = allocate_p2frame(4)
.expect("no more frames in acpi stack_start")
.base()
.data()
+ crate::PHYS_OFFSET;
let stack_start = RmmA::phys_to_virt(
allocate_p2frame(4)
.expect("no more frames in acpi stack_start")
.base(),
).data();
let stack_end = stack_start + (PAGE_SIZE << 4);
let pcr_ptr = crate::arch::gdt::allocate_and_init_pcr(cpu_id, stack_end);
+7 -9
View File
@@ -39,19 +39,17 @@ unsafe fn map_linearly(addr: PhysicalAddress, len: usize, mapper: &mut crate::me
}
}
pub fn get_sdt(sdt_address: usize, mapper: &mut KernelMapper<true>) -> &'static Sdt {
let physaddr = PhysicalAddress::new(sdt_address);
pub fn get_sdt(sdt_address: PhysicalAddress, mapper: &mut KernelMapper<true>) -> &'static Sdt {
let sdt;
unsafe {
const SDT_SIZE: usize = core::mem::size_of::<Sdt>();
map_linearly(physaddr, SDT_SIZE, mapper);
map_linearly(sdt_address, SDT_SIZE, mapper);
sdt = &*(RmmA::phys_to_virt(physaddr).data() as *const Sdt);
sdt = &*(RmmA::phys_to_virt(sdt_address).data() as *const Sdt);
map_linearly(
physaddr.add(SDT_SIZE),
sdt_address.add(SDT_SIZE),
sdt.length as usize - SDT_SIZE,
mapper,
);
@@ -74,7 +72,7 @@ pub enum RxsdtEnum {
Xsdt(Xsdt),
}
impl Rxsdt for RxsdtEnum {
fn iter(&self) -> Box<dyn Iterator<Item = usize>> {
fn iter(&self) -> Box<dyn Iterator<Item = PhysicalAddress>> {
match self {
Self::Rsdt(rsdt) => <Rsdt as Rxsdt>::iter(rsdt),
Self::Xsdt(xsdt) => <Xsdt as Rxsdt>::iter(xsdt),
@@ -96,7 +94,7 @@ pub unsafe fn init(already_supplied_rsdp: Option<*const u8>) {
let rsdp_opt = Rsdp::get_rsdp(already_supplied_rsdp);
if let Some(rsdp) = rsdp_opt {
debug!("SDT address: {:#x}", rsdp.sdt_address());
debug!("SDT address: {:#x}", rsdp.sdt_address().data());
let rxsdt = get_sdt(rsdp.sdt_address(), &mut KernelMapper::lock_rw());
let rxsdt = if let Some(rsdt) = Rsdt::new(rxsdt) {
@@ -138,7 +136,7 @@ pub unsafe fn init(already_supplied_rsdp: Option<*const u8>) {
}
for sdt_address in rxsdt.iter() {
let sdt = &*((sdt_address + crate::PHYS_OFFSET) as *const Sdt);
let sdt = &*(RmmA::phys_to_virt(sdt_address).data() as *const Sdt);
let signature = get_sdt_signature(sdt);
if let Some(ref mut ptrs) = *(SDT_POINTERS.write()) {
+5 -3
View File
@@ -1,3 +1,5 @@
use rmm::PhysicalAddress;
/// RSDP
#[derive(Copy, Clone, Debug)]
#[repr(C, packed)]
@@ -24,11 +26,11 @@ impl Rsdp {
}
/// Get the RSDT or XSDT address
pub fn sdt_address(&self) -> usize {
if self.revision >= 2 {
pub fn sdt_address(&self) -> PhysicalAddress {
PhysicalAddress::new(if self.revision >= 2 {
self.xsdt_address as usize
} else {
self.rsdt_address as usize
}
})
}
}
+4 -3
View File
@@ -1,5 +1,6 @@
use alloc::boxed::Box;
use core::{convert::TryFrom, mem};
use rmm::PhysicalAddress;
use super::{rxsdt::Rxsdt, sdt::Sdt};
@@ -23,7 +24,7 @@ impl Rsdt {
}
impl Rxsdt for Rsdt {
fn iter(&self) -> Box<dyn Iterator<Item = usize>> {
fn iter(&self) -> Box<dyn Iterator<Item = PhysicalAddress>> {
Box::new(RsdtIter { sdt: self.0, i: 0 })
}
}
@@ -34,7 +35,7 @@ pub struct RsdtIter {
}
impl Iterator for RsdtIter {
type Item = usize;
type Item = PhysicalAddress;
fn next(&mut self) -> Option<Self::Item> {
if self.i < self.sdt.data_len() / mem::size_of::<u32>() {
let item = unsafe {
@@ -43,7 +44,7 @@ impl Iterator for RsdtIter {
.read_unaligned()
};
self.i += 1;
Some(item as usize)
Some(PhysicalAddress::new(item as usize))
} else {
None
}
+2 -1
View File
@@ -1,5 +1,6 @@
use alloc::boxed::Box;
use rmm::PhysicalAddress;
pub trait Rxsdt {
fn iter(&self) -> Box<dyn Iterator<Item = usize>>;
fn iter(&self) -> Box<dyn Iterator<Item = PhysicalAddress>>;
}
+4 -3
View File
@@ -1,5 +1,6 @@
use alloc::boxed::Box;
use core::{convert::TryFrom, mem};
use rmm::PhysicalAddress;
use super::{rxsdt::Rxsdt, sdt::Sdt};
@@ -23,7 +24,7 @@ impl Xsdt {
}
impl Rxsdt for Xsdt {
fn iter(&self) -> Box<dyn Iterator<Item = usize>> {
fn iter(&self) -> Box<dyn Iterator<Item = PhysicalAddress>> {
Box::new(XsdtIter { sdt: self.0, i: 0 })
}
}
@@ -34,14 +35,14 @@ pub struct XsdtIter {
}
impl Iterator for XsdtIter {
type Item = usize;
type Item = PhysicalAddress;
fn next(&mut self) -> Option<Self::Item> {
if self.i < self.sdt.data_len() / mem::size_of::<u64>() {
let item = unsafe {
core::ptr::read_unaligned((self.sdt.data_address() as *const u64).add(self.i))
};
self.i += 1;
Some(item as usize)
Some(PhysicalAddress::new(item as usize))
} else {
None
}
+8 -3
View File
@@ -1,5 +1,7 @@
use core::slice;
use crate::memory::{PhysicalAddress, RmmA, RmmArch};
pub mod memory;
#[repr(C, packed(8))]
@@ -75,7 +77,8 @@ impl KernelArgs {
pub(crate) fn env(&self) -> &'static [u8] {
unsafe {
slice::from_raw_parts(
(crate::PHYS_OFFSET + self.env_base as usize) as *const u8,
RmmA::phys_to_virt(PhysicalAddress::new(self.env_base as usize)).data()
as *const u8,
self.env_size as usize,
)
}
@@ -86,7 +89,8 @@ impl KernelArgs {
if self.hwdesc_base != 0 {
let data = unsafe {
slice::from_raw_parts(
(crate::PHYS_OFFSET + self.hwdesc_base as usize) as *const u8,
RmmA::phys_to_virt(PhysicalAddress::new(self.hwdesc_base as usize)).data()
as *const u8,
self.hwdesc_size as usize,
)
};
@@ -105,7 +109,8 @@ impl KernelArgs {
if self.hwdesc_base != 0 {
let data = unsafe {
slice::from_raw_parts(
(crate::PHYS_OFFSET + self.hwdesc_base as usize) as *const u8,
RmmA::phys_to_virt(PhysicalAddress::new(self.hwdesc_base as usize)).data()
as *const u8,
self.hwdesc_size as usize,
)
};