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
6 changes: 3 additions & 3 deletions src/arch/aarch64/kernel/interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::drivers::mmio::get_interrupt_handlers;
use crate::drivers::pci::get_interrupt_handlers;
use crate::drivers::{InterruptHandlerQueue, InterruptLine};
use crate::kernel::serial::handle_uart_interrupt;
use crate::mm::virtualmem::KERNEL_FREE_LIST;
use crate::mm::{PageAlloc, PageRangeAllocator};
use crate::scheduler::{self, CoreId};
use crate::{core_id, core_scheduler, env};

Expand Down Expand Up @@ -313,7 +313,7 @@ pub(crate) fn init() {
);

let layout = PageLayout::from_size_align(gicd_size.try_into().unwrap(), 0x10000).unwrap();
let page_range = KERNEL_FREE_LIST.lock().allocate(layout).unwrap();
let page_range = PageAlloc::allocate(layout).unwrap();
let gicd_address = VirtAddr::from(page_range.start());
debug!("Mapping GIC Distributor interface to virtual address {gicd_address:p}");

Expand All @@ -327,7 +327,7 @@ pub(crate) fn init() {
);

let layout = PageLayout::from_size_align(gicr_size.try_into().unwrap(), 0x10000).unwrap();
let page_range = KERNEL_FREE_LIST.lock().allocate(layout).unwrap();
let page_range = PageAlloc::allocate(layout).unwrap();
let gicr_address = VirtAddr::from(page_range.start());
debug!("Mapping generic interrupt controller to virtual address {gicr_address:p}");
paging::map::<BasePageSize>(
Expand Down
4 changes: 2 additions & 2 deletions src/arch/aarch64/kernel/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use pci_types::{
use crate::arch::aarch64::kernel::interrupts::GIC;
use crate::arch::aarch64::mm::paging::{self, BasePageSize, PageSize, PageTableEntryFlags};
use crate::drivers::pci::{PCI_DEVICES, PciDevice};
use crate::mm::virtualmem::KERNEL_FREE_LIST;
use crate::mm::{PageAlloc, PageRangeAllocator};
use crate::{core_id, env};

const PCI_MAX_DEVICE_NUMBER: u8 = 32;
Expand Down Expand Up @@ -225,7 +225,7 @@ pub fn init() {
let size = u64::try_from(reg.size.unwrap()).unwrap();

let layout = PageLayout::from_size_align(size.try_into().unwrap(), 0x1000_0000).unwrap();
let page_range = KERNEL_FREE_LIST.lock().allocate(layout).unwrap();
let page_range = PageAlloc::allocate(layout).unwrap();
let pci_address = VirtAddr::from(page_range.start());
info!(
"Mapping PCI Enhanced Configuration Space interface to virtual address {pci_address:p} (size {size:#X})"
Expand Down
13 changes: 5 additions & 8 deletions src/arch/aarch64/kernel/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use memory_addresses::arch::aarch64::{PhysAddr, VirtAddr};
use crate::arch::aarch64::kernel::CURRENT_STACK_ADDRESS;
use crate::arch::aarch64::kernel::core_local::core_scheduler;
use crate::arch::aarch64::mm::paging::{BasePageSize, PageSize, PageTableEntryFlags};
use crate::mm::physicalmem::PHYSICAL_FREE_LIST;
use crate::mm::virtualmem::KERNEL_FREE_LIST;
use crate::mm::{FrameAlloc, PageAlloc, PageRangeAllocator};
#[cfg(target_os = "none")]
use crate::scheduler::PerCoreSchedulerExt;
use crate::scheduler::task::{Task, TaskFrame};
Expand Down Expand Up @@ -128,12 +127,10 @@ impl TaskStacks {
};
let total_size = user_stack_size + DEFAULT_STACK_SIZE;
let layout = PageLayout::from_size(total_size + 3 * BasePageSize::SIZE as usize).unwrap();
let page_range = KERNEL_FREE_LIST.lock().allocate(layout).unwrap();
let page_range = PageAlloc::allocate(layout).unwrap();
let virt_addr = VirtAddr::from(page_range.start());
let frame_layout = PageLayout::from_size(total_size).unwrap();
let frame_range = PHYSICAL_FREE_LIST
.lock()
.allocate(frame_layout)
let frame_range = FrameAlloc::allocate(frame_layout)
.expect("Failed to allocate Physical Memory for TaskStacks");
let phys_addr = PhysAddr::from(frame_range.start());

Expand Down Expand Up @@ -238,14 +235,14 @@ impl Drop for TaskStacks {
)
.unwrap();
unsafe {
KERNEL_FREE_LIST.lock().deallocate(range).unwrap();
PageAlloc::deallocate(range);
}

let range =
PageRange::from_start_len(stacks.phys_addr.as_usize(), stacks.total_size)
.unwrap();
unsafe {
PHYSICAL_FREE_LIST.lock().deallocate(range).unwrap();
FrameAlloc::deallocate(range);
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/arch/aarch64/kernel/systemtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use time::OffsetDateTime;

use crate::arch::aarch64::mm::paging::{self, BasePageSize, PageSize, PageTableEntryFlags};
use crate::env;
use crate::mm::virtualmem;
use crate::mm::virtualmem::KERNEL_FREE_LIST;
use crate::mm::{PageAlloc, PageRangeAllocator};

static PL031_ADDRESS: OnceCell<VirtAddr> = OnceCell::new();
static BOOT_TIME: OnceCell<u64> = OnceCell::new();
Expand Down Expand Up @@ -66,7 +65,7 @@ pub fn init() {
debug!("Found RTC at {addr:p} (size {size:#X})");

let layout = PageLayout::from_size(size.try_into().unwrap()).unwrap();
let page_range = KERNEL_FREE_LIST.lock().allocate(layout).unwrap();
let page_range = PageAlloc::allocate(layout).unwrap();
let pl031_address = VirtAddr::from(page_range.start());
PL031_ADDRESS.set(pl031_address).unwrap();
debug!("Mapping RTC to virtual address {pl031_address:p}");
Expand Down
14 changes: 9 additions & 5 deletions src/arch/aarch64/mm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
pub mod paging;

pub fn init() {
use crate::mm::{FrameAlloc, PageAlloc, PageRangeAllocator};

pub unsafe fn init() {
unsafe {
paging::init();
}
crate::mm::physicalmem::init();
crate::mm::virtualmem::init();
unsafe {
FrameAlloc::init();
}
unsafe {
PageAlloc::init();
}
}

pub fn init_page_tables() {}
11 changes: 4 additions & 7 deletions src/arch/aarch64/mm/paging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use memory_addresses::{PhysAddr, VirtAddr};

use crate::arch::aarch64::kernel::{get_base_address, get_image_size, get_ram_address, processor};
use crate::env::is_uhyve;
use crate::mm::physicalmem;
use crate::mm::physicalmem::PHYSICAL_FREE_LIST;
use crate::mm::{FrameAlloc, PageRangeAllocator};
use crate::{KERNEL_STACK_SIZE, mm, scheduler};

/// Pointer to the root page table (called "Level 0" in ARM terminology).
Expand Down Expand Up @@ -497,10 +496,8 @@ where
if !self.entries[index].is_present() {
// Allocate a single 4 KiB page for the new entry and mark it as a valid, writable subtable.
let frame_layout = PageLayout::from_size(BasePageSize::SIZE as usize).unwrap();
let frame_range = PHYSICAL_FREE_LIST
.lock()
.allocate(frame_layout)
.expect("Unable to allocate physical memory");
let frame_range =
FrameAlloc::allocate(frame_layout).expect("Unable to allocate physical memory");
let physical_address = PhysAddr::from(frame_range.start());
self.entries[index].set(
physical_address,
Expand Down Expand Up @@ -669,7 +666,7 @@ pub fn map_heap<S: PageSize>(virt_addr: VirtAddr, nr_pages: usize) -> Result<(),
let size = (nr_pages - map_counter) * S::SIZE as usize;
for i in (S::SIZE as usize..=size).rev().step_by(S::SIZE as usize) {
let layout = PageLayout::from_size_align(i, S::SIZE as usize).unwrap();
let frame_range = PHYSICAL_FREE_LIST.lock().allocate(layout);
let frame_range = FrameAlloc::allocate(layout);

if let Ok(frame_range) = frame_range {
let phys_addr = PhysAddr::from(frame_range.start());
Expand Down
7 changes: 2 additions & 5 deletions src/arch/riscv64/kernel/devicetree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,13 @@ pub fn init_drivers() {
if cfg!(debug_assertions) {
use free_list::PageRange;

use crate::mm::physicalmem::PHYSICAL_FREE_LIST;
use crate::mm::{FrameAlloc, PageRangeAllocator};

let start = virtio_region.starting_address.addr();
let len = virtio_region.size.unwrap();
let frame_range = PageRange::from_start_len(start, len).unwrap();

PHYSICAL_FREE_LIST
.lock()
.allocate_at(frame_range)
.unwrap_err();
FrameAlloc::allocate_at(frame_range).unwrap_err();
}

match id {
Expand Down
6 changes: 2 additions & 4 deletions src/arch/riscv64/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::arch::riscv64::kernel::processor::lsb;
use crate::config::KERNEL_STACK_SIZE;
use crate::env;
use crate::init_cell::InitCell;
use crate::mm::physicalmem::PHYSICAL_FREE_LIST;
use crate::mm::{FrameAlloc, PageRangeAllocator};

// Used to store information about available harts. The index of the hart in the vector
// represents its CpuId and does not need to match its hart_id
Expand Down Expand Up @@ -162,9 +162,7 @@ pub fn boot_next_processor() {
{
debug!("Allocating stack for hard_id {next_hart_id}");
let frame_layout = PageLayout::from_size(KERNEL_STACK_SIZE).unwrap();
let frame_range = PHYSICAL_FREE_LIST
.lock()
.allocate(frame_layout)
let frame_range = FrameAlloc::allocate(frame_layout)
.expect("Failed to allocate boot stack for new core");
let stack = PhysAddr::from(frame_range.start());
CURRENT_STACK_ADDRESS.store(stack.as_usize() as _, Ordering::Relaxed);
Expand Down
13 changes: 5 additions & 8 deletions src/arch/riscv64/kernel/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use memory_addresses::{PhysAddr, VirtAddr};
use crate::arch::riscv64::kernel::core_local::core_scheduler;
use crate::arch::riscv64::kernel::processor::set_oneshot_timer;
use crate::arch::riscv64::mm::paging::{BasePageSize, PageSize, PageTableEntryFlags};
use crate::mm::physicalmem::PHYSICAL_FREE_LIST;
use crate::mm::virtualmem::KERNEL_FREE_LIST;
use crate::mm::{FrameAlloc, PageAlloc, PageRangeAllocator};
use crate::scheduler::task::{Task, TaskFrame};
use crate::{DEFAULT_STACK_SIZE, KERNEL_STACK_SIZE};

Expand Down Expand Up @@ -112,12 +111,10 @@ impl TaskStacks {
};
let total_size = user_stack_size + DEFAULT_STACK_SIZE + KERNEL_STACK_SIZE;
let layout = PageLayout::from_size(total_size + 4 * BasePageSize::SIZE as usize).unwrap();
let page_range = KERNEL_FREE_LIST.lock().allocate(layout).unwrap();
let page_range = PageAlloc::allocate(layout).unwrap();
let virt_addr = VirtAddr::from(page_range.start());
let frame_layout = PageLayout::from_size(total_size).unwrap();
let frame_range = PHYSICAL_FREE_LIST
.lock()
.allocate(frame_layout)
let frame_range = FrameAlloc::allocate(frame_layout)
.expect("Failed to allocate Physical Memory for TaskStacks");
let phys_addr = PhysAddr::from(frame_range.start());

Expand Down Expand Up @@ -255,14 +252,14 @@ impl Drop for TaskStacks {
)
.unwrap();
unsafe {
KERNEL_FREE_LIST.lock().deallocate(range).unwrap();
PageAlloc::deallocate(range);
}

let range =
PageRange::from_start_len(stacks.phys_addr.as_usize(), stacks.total_size)
.unwrap();
unsafe {
PHYSICAL_FREE_LIST.lock().deallocate(range).unwrap();
FrameAlloc::deallocate(range);
}
}
}
Expand Down
15 changes: 11 additions & 4 deletions src/arch/riscv64/mm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
pub mod paging;

pub use self::paging::init_page_tables;
use crate::mm::{FrameAlloc, PageAlloc, PageRangeAllocator};

pub fn init() {
crate::mm::physicalmem::init();
crate::mm::virtualmem::init();
pub unsafe fn init() {
unsafe {
FrameAlloc::init();
}
unsafe {
PageAlloc::init();
}
unsafe {
self::paging::init_page_tables();
}
}
11 changes: 4 additions & 7 deletions src/arch/riscv64/mm/paging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use riscv::asm::sfence_vma;
use riscv::register::satp;
use riscv::register::satp::Satp;

use crate::mm::physicalmem::PHYSICAL_FREE_LIST;
use crate::mm::{FrameAlloc, PageRangeAllocator};

static ROOT_PAGETABLE: SpinMutex<PageTable<L2Table>> = SpinMutex::new(PageTable::new());

Expand Down Expand Up @@ -435,7 +435,7 @@ where
if !self.entries[index].is_present() {
// Allocate a single 4 KiB page for the new entry and mark it as a valid, writable subtable.
let frame_layout = PageLayout::from_size(BasePageSize::SIZE as usize).unwrap();
let frame_range = PHYSICAL_FREE_LIST.lock().allocate(frame_layout).unwrap();
let frame_range = FrameAlloc::allocate(frame_layout).unwrap();
let new_entry = PhysAddr::from(frame_range.start());
self.entries[index].set(new_entry, PageTableEntryFlags::BLANK);

Expand Down Expand Up @@ -614,10 +614,7 @@ pub fn map_heap<S: PageSize>(virt_addr: VirtAddr, count: usize) -> Result<(), us

for (map_counter, virt_addr) in virt_addrs.enumerate() {
let layout = PageLayout::from_size_align(S::SIZE as usize, S::SIZE as usize).unwrap();
let frame_range = PHYSICAL_FREE_LIST
.lock()
.allocate(layout)
.map_err(|_| map_counter)?;
let frame_range = FrameAlloc::allocate(layout).map_err(|_| map_counter)?;
let phys_addr = PhysAddr::from(frame_range.start());
map::<S>(virt_addr, phys_addr, 1, flags);
}
Expand Down Expand Up @@ -651,7 +648,7 @@ pub fn identity_map<S: PageSize>(phys_addr: PhysAddr) {
.map_pages(range, PhysAddr::new(first_page.address().as_u64()), flags);
}

pub fn init_page_tables() {
pub unsafe fn init_page_tables() {
// FIXME: This is not sound, since we are ignoring races with the hardware.
unsafe {
satp::write(Satp::from_bits(
Expand Down
10 changes: 5 additions & 5 deletions src/arch/x86_64/kernel/acpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::arch::x86_64::mm::paging::{
BasePageSize, PageSize, PageTableEntryFlags, PageTableEntryFlagsExt,
};
use crate::env;
use crate::mm::virtualmem::KERNEL_FREE_LIST;
use crate::mm::{PageAlloc, PageRangeAllocator};

/// Memory at this physical address is supposed to contain a pointer to the Extended BIOS Data Area (EBDA).
const EBDA_PTR_LOCATION: PhysAddr = PhysAddr::new(0x0000_040e);
Expand Down Expand Up @@ -137,7 +137,7 @@ impl AcpiTable<'_> {
let physical_map_address = physical_address.align_down(BasePageSize::SIZE);
let offset = (physical_address - physical_map_address) as usize;
let layout = PageLayout::from_size(allocated_length).unwrap();
let page_range = KERNEL_FREE_LIST.lock().allocate(layout).unwrap();
let page_range = PageAlloc::allocate(layout).unwrap();
let mut virtual_address = VirtAddr::from(page_range.start());
paging::map::<BasePageSize>(virtual_address, physical_map_address, count, flags);

Expand All @@ -150,14 +150,14 @@ impl AcpiTable<'_> {
let range =
PageRange::from_start_len(virtual_address.as_usize(), allocated_length).unwrap();
unsafe {
KERNEL_FREE_LIST.lock().deallocate(range).unwrap();
PageAlloc::deallocate(range);
}

allocated_length = (table_length + offset).align_up(BasePageSize::SIZE as usize);
count = allocated_length / BasePageSize::SIZE as usize;

let layout = PageLayout::from_size(allocated_length).unwrap();
let page_range = KERNEL_FREE_LIST.lock().allocate(layout).unwrap();
let page_range = PageAlloc::allocate(layout).unwrap();
virtual_address = VirtAddr::from(page_range.start());
paging::map::<BasePageSize>(virtual_address, physical_map_address, count, flags);

Expand Down Expand Up @@ -194,7 +194,7 @@ impl Drop for AcpiTable<'_> {
)
.unwrap();
unsafe {
KERNEL_FREE_LIST.lock().deallocate(range).unwrap();
PageAlloc::deallocate(range);
}
}
}
Expand Down
Loading
Loading