From 25e1adb80b706034d36ce3a5051e8dcc3ba76bb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 8 May 2024 16:27:36 +0200 Subject: [PATCH] refactor(aarch64): migrate to free-list crate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/arch/aarch64/mm/physicalmem.rs | 37 ++++++++++++++------------ src/arch/aarch64/mm/virtualmem.rs | 42 ++++++++++++++++++------------ src/mm/mod.rs | 2 +- 3 files changed, 47 insertions(+), 34 deletions(-) diff --git a/src/arch/aarch64/mm/physicalmem.rs b/src/arch/aarch64/mm/physicalmem.rs index ea59141b2b..8d8d958996 100644 --- a/src/arch/aarch64/mm/physicalmem.rs +++ b/src/arch/aarch64/mm/physicalmem.rs @@ -1,15 +1,14 @@ -use core::alloc::AllocError; use core::sync::atomic::{AtomicUsize, Ordering}; +use free_list::{AllocError, FreeList, PageLayout, PageRange}; use hermit_sync::InterruptTicketMutex; use crate::arch::aarch64::kernel::get_limit; use crate::arch::aarch64::mm::paging::{BasePageSize, PageSize}; use crate::arch::aarch64::mm::PhysAddr; use crate::mm; -use crate::mm::freelist::{FreeList, FreeListEntry}; -static PHYSICAL_FREE_LIST: InterruptTicketMutex = +static PHYSICAL_FREE_LIST: InterruptTicketMutex> = InterruptTicketMutex::new(FreeList::new()); static TOTAL_MEMORY: AtomicUsize = AtomicUsize::new(0); @@ -19,15 +18,14 @@ fn detect_from_limits() -> Result<(), ()> { return Err(()); } - let entry = FreeListEntry { - start: mm::kernel_end_address().as_usize(), - end: limit, - }; + let range = PageRange::new(mm::kernel_end_address().as_usize(), limit).unwrap(); TOTAL_MEMORY.store( limit - mm::kernel_end_address().as_usize(), Ordering::SeqCst, ); - PHYSICAL_FREE_LIST.lock().push(entry); + unsafe { + PHYSICAL_FREE_LIST.lock().deallocate(range).unwrap(); + } Ok(()) } @@ -52,10 +50,13 @@ pub fn allocate(size: usize) -> Result { BasePageSize::SIZE ); + let layout = PageLayout::from_size(size).unwrap(); + Ok(PhysAddr( PHYSICAL_FREE_LIST .lock() - .allocate(size, None)? + .allocate(layout)? + .start() .try_into() .unwrap(), )) @@ -77,10 +78,13 @@ pub fn allocate_aligned(size: usize, align: usize) -> Result = +static KERNEL_FREE_LIST: InterruptTicketMutex> = InterruptTicketMutex::new(FreeList::new()); /// End of the virtual memory address space reserved for kernel memory (4 GiB). @@ -15,11 +13,14 @@ static KERNEL_FREE_LIST: InterruptTicketMutex = const KERNEL_VIRTUAL_MEMORY_END: VirtAddr = VirtAddr(0x1_0000_0000); pub fn init() { - let entry = FreeListEntry { - start: mm::kernel_end_address().as_usize(), - end: KERNEL_VIRTUAL_MEMORY_END.as_usize(), - }; - KERNEL_FREE_LIST.lock().push(entry); + let range = PageRange::new( + mm::kernel_end_address().as_usize(), + KERNEL_VIRTUAL_MEMORY_END.as_usize(), + ) + .unwrap(); + unsafe { + KERNEL_FREE_LIST.lock().deallocate(range).unwrap(); + } } pub fn allocate(size: usize) -> Result { @@ -32,10 +33,13 @@ pub fn allocate(size: usize) -> Result { BasePageSize::SIZE ); + let layout = PageLayout::from_size(size).unwrap(); + Ok(VirtAddr( KERNEL_FREE_LIST .lock() - .allocate(size, None)? + .allocate(layout)? + .start() .try_into() .unwrap(), )) @@ -57,10 +61,13 @@ pub fn allocate_aligned(size: usize, align: usize) -> Result