Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions src/arch/aarch64/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ use core::arch::global_asm;
use core::sync::atomic::{AtomicPtr, AtomicU32, Ordering};
use core::{ptr, str};

use memory_addresses::PhysAddr;

pub(crate) use self::interrupts::wakeup_core;
pub(crate) use self::processor::set_oneshot_timer;
use crate::arch::aarch64::kernel::core_local::*;
Expand All @@ -45,14 +43,6 @@ pub fn is_uhyve_with_pci() -> bool {
false
}

pub fn get_ram_address() -> PhysAddr {
PhysAddr::new(env::boot_info().hardware_info.phys_addr_range.start)
}

pub fn get_limit() -> usize {
env::boot_info().hardware_info.phys_addr_range.end as usize
}

#[cfg(feature = "smp")]
pub fn get_possible_cpus() -> u32 {
let fdt = env::fdt().unwrap();
Expand Down
4 changes: 0 additions & 4 deletions src/arch/aarch64/mm/paging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use align_address::Align;
use free_list::PageLayout;
use memory_addresses::{PhysAddr, VirtAddr};

use crate::env::get_ram_address;
use crate::mm::{FrameAlloc, PageRangeAllocator};

/// Pointer to the root page table (called "Level 0" in ARM terminology).
Expand Down Expand Up @@ -708,9 +707,6 @@ pub fn unmap<S: PageSize>(virtual_address: VirtAddr, count: usize) {
}

pub unsafe fn init() {
let ram_start = get_ram_address();
info!("RAM starts at physical address {ram_start:p}");

// determine physical address size
let id_aa64mmfr0_el1 = ID_AA64MMFR0_EL1.extract();

Expand Down
10 changes: 0 additions & 10 deletions src/arch/riscv64/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use core::ptr;
use core::sync::atomic::{AtomicPtr, AtomicU32, AtomicU64, Ordering};

use free_list::PageLayout;
use memory_addresses::PhysAddr;
use riscv::register::sstatus;

pub(crate) use self::processor::{set_oneshot_timer, wakeup_core};
Expand Down Expand Up @@ -45,15 +44,6 @@ pub fn is_uhyve_with_pci() -> bool {
false
}

pub fn get_ram_address() -> PhysAddr {
PhysAddr::new(env::boot_info().hardware_info.phys_addr_range.start)
}

pub fn get_limit() -> usize {
(env::boot_info().hardware_info.phys_addr_range.end
- env::boot_info().hardware_info.phys_addr_range.start) as usize
}

#[cfg(feature = "smp")]
pub fn get_possible_cpus() -> u32 {
NUM_CPUS.load(Ordering::Relaxed)
Expand Down
7 changes: 1 addition & 6 deletions src/arch/x86_64/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use core::slice;
use core::sync::atomic::{AtomicPtr, AtomicU32, Ordering};

use hermit_entry::boot_info::{PlatformInfo, RawBootInfo};
use memory_addresses::PhysAddr;
use x86_64::registers::control::{Cr0, Cr4};

pub(crate) use self::apic::{set_oneshot_timer, wakeup_core};
Expand Down Expand Up @@ -39,10 +38,6 @@ pub(crate) mod systemtime;
#[cfg(feature = "vga")]
pub mod vga;

pub fn get_ram_address() -> PhysAddr {
PhysAddr::new(env::boot_info().hardware_info.phys_addr_range.start)
}

#[cfg(feature = "smp")]
pub fn get_possible_cpus() -> u32 {
use core::cmp;
Expand Down Expand Up @@ -226,7 +221,7 @@ where

use align_address::Align;
use free_list::PageLayout;
use memory_addresses::VirtAddr;
use memory_addresses::{PhysAddr, VirtAddr};
use x86_64::structures::paging::{PageSize, Size4KiB as BasePageSize};

use crate::arch::x86_64::mm::paging::{self, PageTableEntryFlags, PageTableEntryFlagsExt};
Expand Down
9 changes: 8 additions & 1 deletion src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use hashbrown::HashMap;
use hashbrown::hash_map::Iter;
use hermit_entry::boot_info::{BootInfo, PlatformInfo, RawBootInfo};
use hermit_sync::OnceCell;
use memory_addresses::PhysAddr;

use crate::arch::kernel;
pub(crate) use crate::arch::kernel::get_ram_address;

static BOOT_INFO: OnceCell<BootInfo> = OnceCell::new();

Expand Down Expand Up @@ -60,6 +60,13 @@ pub fn fdt() -> Option<Fdt<'static>> {
})
}

pub(crate) fn get_ram_address() -> Option<PhysAddr> {
let fdt = fdt()?;
let memory = fdt.memory();
let ptr = memory.regions().next()?.starting_address;
Some(ptr.expose_provenance().into())
}

/// Returns the RSDP physical address if available.
#[cfg(all(target_arch = "x86_64", feature = "acpi"))]
pub fn rsdp() -> Option<core::num::NonZero<usize>> {
Expand Down
4 changes: 2 additions & 2 deletions src/mm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ pub(crate) fn init() {
// On UEFI, the given memory is guaranteed free memory and the kernel is located before the given memory
reserved_space
} else {
(kernel_addr_range.end.as_u64() - env::get_ram_address().as_u64() + reserved_space as u64)
as usize
(kernel_addr_range.end.as_u64() - env::get_ram_address().unwrap().as_u64()
+ reserved_space as u64) as usize
};
info!("Minimum memory size: {} MiB", min_mem >> 20);
let avail_mem = total_mem
Expand Down
37 changes: 2 additions & 35 deletions src/mm/physicalmem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,29 +201,6 @@ impl PageRangeExt for PageRange {
}
}

#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
unsafe fn detect_from_limits() -> Result<(), ()> {
let limit = crate::arch::kernel::get_limit();
if limit == 0 {
return Err(());
}

#[cfg(target_arch = "riscv64")]
let ram_address = crate::arch::kernel::get_ram_address().as_usize();
#[cfg(target_arch = "aarch64")]
let ram_address = 0;

let range =
PageRange::new(super::kernel_end_address().as_usize(), ram_address + limit).unwrap();
unsafe {
PHYSICAL_FREE_LIST.lock().deallocate(range).unwrap();
map_frame_range(range);
}
TOTAL_MEMORY.fetch_add(range.len().get(), Ordering::Relaxed);

Ok(())
}

unsafe fn init() {
if env::is_uefi() && DeviceAlloc.phys_offset() != VirtAddr::zero() {
let start = DeviceAlloc.phys_offset();
Expand All @@ -232,17 +209,7 @@ unsafe fn init() {
paging::unmap::<HugePageSize>(start, count);
}

if unsafe { detect_from_fdt().is_ok() } {
return;
}

cfg_select! {
any(target_arch = "aarch64", target_arch = "riscv64") => {
error!("Could not detect physical memory from FDT");
unsafe { detect_from_limits().unwrap(); }
}
_ => {
panic!("Could not detect physical memory from FDT");
}
unsafe {
detect_from_fdt().unwrap();
}
}
Loading