From b7456d5bccc3a76d1b73496c56a995af772f8652 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 4 Apr 2026 21:53:34 +0200 Subject: [PATCH] Avoid PHYS_OFFSET in dtb/serial.rs --- src/devices/uart_pl011.rs | 1 - src/dtb/mod.rs | 6 ++++-- src/dtb/serial.rs | 3 ++- src/main.rs | 1 + 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/devices/uart_pl011.rs b/src/devices/uart_pl011.rs index 5cadffa026..ba4cceb0ad 100644 --- a/src/devices/uart_pl011.rs +++ b/src/devices/uart_pl011.rs @@ -93,7 +93,6 @@ bitflags! { } } -#[allow(dead_code)] pub struct SerialPort { base: usize, data_reg: u8, diff --git a/src/dtb/mod.rs b/src/dtb/mod.rs index b1cf9745de..e8f4944e99 100644 --- a/src/dtb/mod.rs +++ b/src/dtb/mod.rs @@ -11,6 +11,7 @@ use fdt::{ standard_nodes::MemoryRegion, Fdt, }; +use rmm::PhysicalAddress; use spin::once::Once; /// Represents the in-memory DTB (DeviceTree) binary. @@ -146,6 +147,7 @@ pub fn register_dev_memory_ranges(dt: &Fdt) { } } +// FIXME return PhysicalAddress pub fn get_mmio_address(fdt: &Fdt, _device: &FdtNode, region: &MemoryRegion) -> Option { /* DT spec 2.3.8 "ranges": * The ranges property provides a means of defining a mapping or translation between @@ -206,7 +208,7 @@ pub fn get_interrupt(fdt: &Fdt, node: &FdtNode, idx: usize) -> Option { } } -pub fn diag_uart_range<'a>(dtb: &'a Fdt) -> Option<(usize, usize, bool, bool, &'a str)> { +pub fn diag_uart_range<'a>(dtb: &'a Fdt) -> Option<(PhysicalAddress, usize, bool, bool, &'a str)> { let stdout_path = dtb.chosen().stdout()?; let uart_node = stdout_path.node(); let skip_init = uart_node.property("skip-init").is_some(); @@ -220,7 +222,7 @@ pub fn diag_uart_range<'a>(dtb: &'a Fdt) -> Option<(usize, usize, bool, bool, &' let address = get_mmio_address(dtb, &uart_node, &memory)?; Some(( - address, + PhysicalAddress::new(address), memory.size?, skip_init, cts_event_walkaround, diff --git a/src/dtb/serial.rs b/src/dtb/serial.rs index 655ccaf5e5..83a569d0ef 100644 --- a/src/dtb/serial.rs +++ b/src/dtb/serial.rs @@ -5,6 +5,7 @@ use syscall::Mmio; use crate::{ devices::{serial::SerialKind, uart_16550, uart_pl011}, dtb::diag_uart_range, + memory::{RmmA, RmmArch}, }; pub static COM1: Mutex = Mutex::new(SerialKind::NotPresent); @@ -18,7 +19,7 @@ pub unsafe fn init_early(dtb: &Fdt) { } if let Some((phys, size, skip_init, cts, compatible)) = diag_uart_range(dtb) { - let virt = crate::PHYS_OFFSET + phys; + let virt = RmmA::phys_to_virt(phys).data(); let serial_opt = if compatible.contains("arm,pl011") { let mut serial_port = uart_pl011::SerialPort::new(virt, cts); if !skip_init { diff --git a/src/main.rs b/src/main.rs index ca28693e3a..3f52f442fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,6 +40,7 @@ mod macros; mod arch; use crate::arch::*; /// Offset of physmap +#[cfg_attr(any(target_arch = "x86", target_arch = "x86_64"), expect(dead_code))] const PHYS_OFFSET: usize = ::PHYS_OFFSET; /// Heap allocators