diff --git a/src/acpi/mod.rs b/src/acpi/mod.rs index fd1e88b948..b3a9d541d5 100644 --- a/src/acpi/mod.rs +++ b/src/acpi/mod.rs @@ -6,6 +6,7 @@ use core::ptr::NonNull; use alloc::{boxed::Box, string::String, vec::Vec}; use hashbrown::HashMap; +use rmm::{BumpAllocator, FrameAllocator, PageMapper}; use spin::{Once, RwLock}; use crate::{ @@ -31,7 +32,11 @@ mod spcr; pub mod srat; mod xsdt; -unsafe fn map_linearly(addr: PhysicalAddress, len: usize, mapper: &mut crate::memory::PageMapper) { +unsafe fn map_linearly( + addr: PhysicalAddress, + len: usize, + mapper: &mut PageMapper, +) { unsafe { let base = PhysicalAddress::new(crate::memory::round_down_pages(addr.data())); let aligned_len = crate::memory::round_up_pages(len + (addr.data() - base.data())); @@ -48,7 +53,10 @@ unsafe fn map_linearly(addr: PhysicalAddress, len: usize, mapper: &mut crate::me } } -pub fn get_sdt(sdt_address: PhysicalAddress, mapper: &mut KernelMapper) -> &'static Sdt { +pub fn get_sdt( + sdt_address: PhysicalAddress, + mapper: &mut PageMapper, +) -> &'static Sdt { let sdt; unsafe { @@ -91,16 +99,20 @@ impl Rxsdt for RxsdtEnum { pub static RXSDT_ENUM: Once = Once::new(); -/// Initialses the global `RXSDT_ENUM` if RSDT or XSDT was found and maps the SDT pages. -/// It does not perform any allocations -pub unsafe fn init_before_mem(already_supplied_rsdp: Option>) { +/// Initialises the global `RXSDT_ENUM` if RSDT or XSDT was found and maps the SDT pages. +/// +/// It does not use `TheFrameAllocator` nor does it heap-allocate. +pub unsafe fn init_before_mem( + already_supplied_rsdp: Option>, + mapper: &mut PageMapper>, +) { unsafe { // Search for RSDP let rsdp_opt = Rsdp::get_rsdp(already_supplied_rsdp); if let Some(rsdp) = rsdp_opt { debug!("SDT address: {:#x}", rsdp.sdt_address().data()); - let rxsdt = get_sdt(rsdp.sdt_address(), &mut KernelMapper::lock_rw()); + let rxsdt = get_sdt(rsdp.sdt_address(), mapper); let rxsdt = if let Some(rsdt) = Rsdt::new(rxsdt) { let mut initialized = false; @@ -137,7 +149,7 @@ pub unsafe fn init_before_mem(already_supplied_rsdp: Option>) { // TODO: Don't touch ACPI tables in kernel? for sdt in rxsdt.iter() { - get_sdt(sdt, &mut KernelMapper::lock_rw()); + get_sdt(sdt, mapper); } } else { error!("NO RSDP FOUND"); diff --git a/src/arch/aarch64/start.rs b/src/arch/aarch64/start.rs index 3fdc9ab3f8..68e6ff37d7 100644 --- a/src/arch/aarch64/start.rs +++ b/src/arch/aarch64/start.rs @@ -100,13 +100,14 @@ unsafe extern "C" fn start(args_ptr: *const KernelArgs) -> ! { // Initialize paging paging::init(); + let mut mapper = rmm::PageMapper::current(rmm::TableKind::Kernel, bump_allocator); #[cfg(feature = "acpi")] { use crate::acpi; - acpi::init_before_mem(args.acpi_rsdp()); + acpi::init_before_mem(args.acpi_rsdp(), &mut mapper); } - crate::memory::init_mm(bump_allocator); + crate::memory::init_mm(mapper.allocator_mut()); crate::arch::misc::init(crate::cpu_set::LogicalCpuId::new(0)); diff --git a/src/arch/riscv64/start.rs b/src/arch/riscv64/start.rs index 3fca90f023..146fb37540 100644 --- a/src/arch/riscv64/start.rs +++ b/src/arch/riscv64/start.rs @@ -105,7 +105,7 @@ unsafe extern "C" fn start(args_ptr: *const KernelArgs) -> ! { } // Initialize RMM - let bump_allocator = crate::startup::memory::init(&args, None, None); + let mut bump_allocator = crate::startup::memory::init(&args, None, None); let boot_hart_id = get_boot_hart_id(args.env()).expect("Didn't get boot HART id from bootloader"); @@ -114,7 +114,7 @@ unsafe extern "C" fn start(args_ptr: *const KernelArgs) -> ! { paging::init(); - crate::memory::init_mm(bump_allocator); + crate::memory::init_mm(&mut bump_allocator); crate::arch::misc::init(crate::cpu_set::LogicalCpuId::new(0)); diff --git a/src/arch/x86_shared/start.rs b/src/arch/x86_shared/start.rs index 295c273501..a18491d7e1 100644 --- a/src/arch/x86_shared/start.rs +++ b/src/arch/x86_shared/start.rs @@ -4,6 +4,8 @@ //! defined in other files inside of the `arch` module use core::{arch::naked_asm, cell::SyncUnsafeCell, mem::offset_of}; +use rmm::PageMapper; + use crate::{ allocator, arch::{device, gdt, idt, interrupt, paging}, @@ -112,13 +114,14 @@ unsafe extern "C" fn start(args_ptr: *const KernelArgs, stack_end: usize) -> ! { // Initialize paging paging::init(); + let mut mapper = PageMapper::current(rmm::TableKind::Kernel, bump_allocator); if cfg!(feature = "acpi") { - crate::acpi::init_before_mem(args.acpi_rsdp()); + crate::acpi::init_before_mem(args.acpi_rsdp(), &mut mapper); } - numa::init(&mut bump_allocator); + numa::init(mapper.allocator_mut()); - crate::memory::init_mm(bump_allocator); + crate::memory::init_mm(mapper.allocator_mut()); #[cfg(target_arch = "x86_64")] crate::arch::alternative::early_init(true); diff --git a/src/memory/mod.rs b/src/memory/mod.rs index f1a50524cf..39891bc9fb 100644 --- a/src/memory/mod.rs +++ b/src/memory/mod.rs @@ -549,7 +549,7 @@ const _: () = { }; #[cold] -fn init_sections(mut allocator: BumpAllocator) { +fn init_sections(mut allocator: &mut BumpAllocator) { let number_of_memory_regions = numa::number_of_memory_regions(); let (free_areas, offset_into_first_free_area) = allocator.free_areas(); @@ -958,7 +958,7 @@ fn init_sections(mut allocator: BumpAllocator) { } #[cold] -pub fn init_mm(allocator: BumpAllocator) { +pub fn init_mm(allocator: &mut BumpAllocator) { init_sections(allocator); unsafe {