Skip to content

Commit

Permalink
bootinfo: Include reference to memory layout
Browse files Browse the repository at this point in the history
By including a reference to the memory layout in the Info trait we can
remove the need to hardcode the memory layout in the EFI execution code
making it more portable.

Signed-off-by: Rob Bradford <[email protected]>
  • Loading branch information
rbradford committed Mar 11, 2023
1 parent e679965 commit 3351c1d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/bootinfo.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions src/coreboot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64> {
Expand Down
8 changes: 1 addition & 7 deletions src/efi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 16 additions & 2 deletions src/fdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>,
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<u64>, kernel_load_addr: u64) -> Self {
pub fn new(
ptr: *const u8,
acpi_rsdp_addr: Option<u64>,
kernel_load_addr: u64,
memory_layout: &'static [MemoryDescriptor],
) -> Self {
let fdt = unsafe {
match Fdt::from_ptr(ptr) {
Ok(fdt) => fdt,
Expand All @@ -28,6 +37,7 @@ impl StartInfo<'_> {
fdt,
acpi_rsdp_addr,
kernel_load_addr,
memory_layout,
}
}

Expand Down Expand Up @@ -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
}
}
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]) {
Expand Down
4 changes: 4 additions & 0 deletions src/pvh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 3351c1d

Please sign in to comment.