diff --git a/src/bootinfo.rs b/src/bootinfo.rs index f948c361..92ca4bbd 100644 --- a/src/bootinfo.rs +++ b/src/bootinfo.rs @@ -1,6 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright (C) 2022 Akira Moroo +use crate::layout::MemoryDescriptor; + // Common data needed for all boot paths pub trait Info { // Name of for this boot protocol @@ -20,6 +22,8 @@ pub trait Info { fn entry(&self, idx: usize) -> MemoryEntry; // Where to load kernel fn kernel_load_addr(&self) -> u64; + // Reference to memory layout + fn memory_layout(&self) -> &'static [MemoryDescriptor]; } pub struct MemoryEntry { diff --git a/src/coreboot.rs b/src/coreboot.rs index 70920942..252048b3 100644 --- a/src/coreboot.rs +++ b/src/coreboot.rs @@ -114,6 +114,9 @@ impl Info for StartInfo { fn kernel_load_addr(&self) -> u64 { crate::arch::x86_64::layout::KERNEL_START } + fn memory_layout(&self) -> &'static [crate::layout::MemoryDescriptor] { + &crate::arch::x86_64::layout::MEM_LAYOUT[..] + } } fn find_header(start: u64, len: usize) -> Option { diff --git a/src/efi/mod.rs b/src/efi/mod.rs index 311ae548..f0da752c 100644 --- a/src/efi/mod.rs +++ b/src/efi/mod.rs @@ -936,13 +936,7 @@ fn populate_allocator(info: &dyn bootinfo::Info, image_address: u64, image_size: } } - #[cfg(target_arch = "aarch64")] - use crate::arch::aarch64::layout::MEM_LAYOUT; - - #[cfg(target_arch = "x86_64")] - use crate::arch::x86_64::layout::MEM_LAYOUT; - - for descriptor in MEM_LAYOUT { + for descriptor in info.memory_layout() { let memory_type = match descriptor.attribute { layout::MemoryAttribute::Code => efi::RUNTIME_SERVICES_CODE, layout::MemoryAttribute::Data => efi::RUNTIME_SERVICES_DATA, diff --git a/src/fdt.rs b/src/fdt.rs index 21b37e7c..da8cf8f4 100644 --- a/src/fdt.rs +++ b/src/fdt.rs @@ -3,17 +3,26 @@ use fdt::Fdt; -use crate::bootinfo::{EntryType, Info, MemoryEntry}; +use crate::{ + bootinfo::{EntryType, Info, MemoryEntry}, + layout::MemoryDescriptor, +}; pub struct StartInfo<'a> { acpi_rsdp_addr: Option, fdt_addr: u64, fdt: Fdt<'a>, kernel_load_addr: u64, + memory_layout: &'static [MemoryDescriptor], } impl StartInfo<'_> { - pub fn new(ptr: *const u8, acpi_rsdp_addr: Option, kernel_load_addr: u64) -> Self { + pub fn new( + ptr: *const u8, + acpi_rsdp_addr: Option, + kernel_load_addr: u64, + memory_layout: &'static [MemoryDescriptor], + ) -> Self { let fdt = unsafe { match Fdt::from_ptr(ptr) { Ok(fdt) => fdt, @@ -28,6 +37,7 @@ impl StartInfo<'_> { fdt, acpi_rsdp_addr, kernel_load_addr, + memory_layout, } } @@ -80,4 +90,8 @@ impl Info for StartInfo<'_> { fn kernel_load_addr(&self) -> u64 { self.kernel_load_addr } + + fn memory_layout(&self) -> &'static [MemoryDescriptor] { + self.memory_layout + } } diff --git a/src/main.rs b/src/main.rs index 0407b6de..b22d68be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -172,6 +172,7 @@ pub extern "C" fn rust64_start(x0: *const u8) -> ! { x0, Some(arch::aarch64::layout::map::dram::ACPI_START as u64), arch::aarch64::layout::map::dram::KERNEL_START as u64, + &crate::arch::aarch64::layout::MEM_LAYOUT[..], ); if let Some((base, length)) = info.find_compatible_region(&["pci-host-ecam-generic"]) { diff --git a/src/pvh.rs b/src/pvh.rs index 9e47f574..5cd4fa65 100644 --- a/src/pvh.rs +++ b/src/pvh.rs @@ -3,6 +3,7 @@ use core::mem::size_of; use crate::{ bootinfo::{EntryType, Info, MemoryEntry}, common, + layout::MemoryDescriptor, }; // Structures from xen/include/public/arch-x86/hvm/start_info.h @@ -66,6 +67,9 @@ impl Info for StartInfo { fn kernel_load_addr(&self) -> u64 { crate::arch::x86_64::layout::KERNEL_START } + fn memory_layout(&self) -> &'static [MemoryDescriptor] { + &crate::arch::x86_64::layout::MEM_LAYOUT[..] + } } // The PVH Boot Protocol starts at the 32-bit entrypoint to our firmware.