diff --git a/src/arch/aarch64/paging/mod.rs b/src/arch/aarch64/paging/mod.rs index ca73142e25..0245f668c9 100644 --- a/src/arch/aarch64/paging/mod.rs +++ b/src/arch/aarch64/paging/mod.rs @@ -10,7 +10,7 @@ use self::mapper::PageFlushAll; pub use super::CurrentRmmArch as RmmA; pub use rmm::{Arch as RmmArch, Flusher, PageFlags, PhysicalAddress, TableKind, VirtualAddress}; -pub type PageMapper = rmm::PageMapper; +pub type PageMapper = rmm::PageMapper; pub use crate::rmm::KernelMapper; pub mod entry; @@ -21,6 +21,7 @@ pub const ENTRY_COUNT: usize = RmmA::PAGE_ENTRIES; /// Size of pages pub const PAGE_SIZE: usize = RmmA::PAGE_SIZE; +pub const PAGE_MASK: usize = RmmA::PAGE_OFFSET_MASK; /// Setup Memory Access Indirection Register #[cold] diff --git a/src/arch/aarch64/rmm.rs b/src/arch/aarch64/rmm.rs index 51e33ed93d..293e081a26 100644 --- a/src/arch/aarch64/rmm.rs +++ b/src/arch/aarch64/rmm.rs @@ -32,7 +32,7 @@ pub struct BootloaderMemoryEntry { pub kind: BootloaderMemoryKind, } -unsafe fn page_flags(virt: VirtualAddress) -> PageFlags { +unsafe fn page_flags(virt: VirtualAddress) -> PageFlags { use crate::kernel_executable_offsets::*; let virt_addr = virt.data(); @@ -48,7 +48,7 @@ unsafe fn page_flags(virt: VirtualAddress) -> PageFlags { } } -unsafe fn inner( +unsafe fn inner( areas: &'static [MemoryArea], kernel_base: usize, kernel_size_aligned: usize, @@ -60,7 +60,9 @@ unsafe fn inner( acpi_size_aligned: usize, initfs_base: usize, initfs_size_aligned: usize, -) -> BuddyAllocator { +) { + type A = RmmA; + // First, calculate how much memory we have let mut size = 0; for area in areas.iter() { @@ -203,46 +205,7 @@ unsafe fn inner( (offset + (KILOBYTE - 1)) / KILOBYTE ); - BuddyAllocator::::new(bump_allocator).expect("failed to create BuddyAllocator") -} - -// There can only be one allocator (at the moment), so making this a ZST is great! -#[derive(Clone, Copy)] -pub struct LockedAllocator; - -static INNER_ALLOCATOR: Mutex>> = Mutex::new(None); - -impl FrameAllocator for LockedAllocator { - unsafe fn allocate(&mut self, count: FrameCount) -> Option { - if let Some(ref mut allocator) = *INNER_ALLOCATOR.lock() { - allocator.allocate(count) - } else { - None - } - } - - unsafe fn free(&mut self, address: PhysicalAddress, count: FrameCount) { - if let Some(ref mut allocator) = *INNER_ALLOCATOR.lock() { - allocator.free(address, count) - } - } - - unsafe fn usage(&self) -> FrameUsage { - if let Some(ref allocator) = *INNER_ALLOCATOR.lock() { - allocator.usage() - } else { - FrameUsage::new(FrameCount::new(0), FrameCount::new(0)) - } - } -} -impl core::fmt::Debug for LockedAllocator { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match INNER_ALLOCATOR.try_lock().as_deref() { - Some(Some(alloc)) => write!(f, "[locked allocator: {:?}]", unsafe { alloc.usage() }), - Some(None) => write!(f, "[uninitialized lock allocator]"), - None => write!(f, "[failed to lock]"), - } - } + crate::memory::init_mm(bump_allocator); } static AREAS: SyncUnsafeCell<[MemoryArea; 512]> = SyncUnsafeCell::new( @@ -261,8 +224,6 @@ pub fn areas() -> &'static [MemoryArea] { unsafe { &(&*AREAS.get())[..AREA_COUNT.get().read().into()] } } -pub static FRAME_ALLOCATOR: LockedAllocator = LockedAllocator; - const NO_PROCESSOR: usize = !0; static LOCK_OWNER: AtomicUsize = AtomicUsize::new(NO_PROCESSOR); static LOCK_COUNT: AtomicUsize = AtomicUsize::new(0); @@ -313,7 +274,7 @@ impl KernelMapper { unsafe { Self::lock_for_manual_mapper( current_processor, - PageMapper::current(TableKind::Kernel, FRAME_ALLOCATOR), + PageMapper::current(TableKind::Kernel, crate::memory::TheFrameAllocator), ) } } @@ -514,7 +475,7 @@ pub unsafe fn init( } AREA_COUNT.get().write(area_i as u16); - let allocator = inner::( + inner( areas, kernel_base, kernel_size_aligned, @@ -527,5 +488,4 @@ pub unsafe fn init( initfs_base, initfs_size_aligned, ); - *INNER_ALLOCATOR.lock() = Some(allocator); } diff --git a/src/arch/aarch64/start.rs b/src/arch/aarch64/start.rs index d2f64c99e0..2391e76197 100644 --- a/src/arch/aarch64/start.rs +++ b/src/arch/aarch64/start.rs @@ -186,8 +186,6 @@ pub unsafe extern "C" fn kstart(args_ptr: *const KernelArgs) -> ! { // Initialize all of the non-core devices not otherwise needed to complete initialization device::init_noncore(); - crate::memory::init_mm(); - // Stop graphical debug //#[cfg(feature = "graphical_debug")] //graphical_debug::fini(); diff --git a/src/context/memory.rs b/src/context/memory.rs index d0ac4b49d0..d5789547d4 100644 --- a/src/context/memory.rs +++ b/src/context/memory.rs @@ -2117,7 +2117,7 @@ impl Drop for Table { #[cfg(target_arch = "aarch64")] pub fn setup_new_utable() -> Result { let utable = unsafe { - PageMapper::create(TableKind::User, crate::rmm::FRAME_ALLOCATOR) + PageMapper::create(TableKind::User, crate::memory::TheFrameAllocator) .ok_or(Error::new(ENOMEM))? };