Skip to content

Commit

Permalink
Move platform-dependent values from rmm/ to plat/
Browse files Browse the repository at this point in the history
Signed-off-by: Sangwan Kwon <[email protected]>
  • Loading branch information
bitboom committed Oct 21, 2024
1 parent 9338ccb commit a12a20c
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 49 deletions.
17 changes: 16 additions & 1 deletion plat/fvp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ mod entry;

use aarch64_cpu::registers::*;
use islet_rmm::allocator;
use islet_rmm::config::PlatformMemoryLayout;
use islet_rmm::cpu;

extern "C" {
static __RMM_BASE__: u64;
static __RW_START__: u64;
static __RW_END__: u64;
}

#[no_mangle]
pub unsafe fn main() -> ! {
info!(
Expand All @@ -22,7 +29,15 @@ pub unsafe fn main() -> ! {
CurrentEL.read(CurrentEL::EL) as u8
);

islet_rmm::start(cpu::get_cpu_id());
let layout = unsafe {
PlatformMemoryLayout {
rmm_base: &__RMM_BASE__ as *const u64 as u64,
rw_start: &__RW_START__ as *const u64 as u64,
rw_end: &__RW_END__ as *const u64 as u64,
uart_phys: 0x1c0c_0000,
}
};
islet_rmm::start(cpu::get_cpu_id(), layout);

panic!("failed to run the mainloop");
}
7 changes: 7 additions & 0 deletions rmm/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ pub const STACK_ALIGN: usize = 16;

// TODO: Acquire this address properly.
pub const RMM_SHARED_BUFFER_START: usize = 0xFFBFF000;

pub struct PlatformMemoryLayout {
pub rmm_base: u64,
pub rw_start: u64,
pub rw_end: u64,
pub uart_phys: u64,
}
10 changes: 6 additions & 4 deletions rmm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ extern crate lazy_static;
#[macro_use]
extern crate log;

use crate::config::PlatformMemoryLayout;
use crate::exception::vectors;
#[cfg(feature = "gst_page_table")]
use crate::granule::create_granule_status_table as setup_gst;
use crate::mm::translation::get_page_table;
use crate::mm::translation::{get_page_table, init_page_table};
use crate::monitor::Monitor;
use crate::rmm_el3::setup_el3_ifc;

Expand All @@ -64,8 +65,8 @@ use core::ptr::addr_of;
// model checking harnesses do not use this function, instead
// they use their own entry points marked with #[kani::proof]
// where slightly adjusted `Monitor` is used
pub unsafe fn start(cpu_id: usize) {
setup_mmu_cfg();
pub unsafe fn start(cpu_id: usize, layout: PlatformMemoryLayout) {
setup_mmu_cfg(layout);
setup_el2();
#[cfg(feature = "gst_page_table")]
setup_gst();
Expand Down Expand Up @@ -134,7 +135,7 @@ unsafe fn setup_el2() {
///
/// Failing to meet these requirements can result in system crashes, memory corruption, security
/// vulnerabilities, or other undefined behavior.
unsafe fn setup_mmu_cfg() {
unsafe fn setup_mmu_cfg(layout: PlatformMemoryLayout) {
core::arch::asm!("tlbi alle2is", "dsb ish", "isb",);

// /* Set attributes in the right indices of the MAIR. */
Expand All @@ -159,6 +160,7 @@ unsafe fn setup_mmu_cfg() {

// set the ttbl base address, this is where the memory address translation
// table walk starts
init_page_table(layout);
let ttbl_base = get_page_table();

// Invalidate the local I-cache so that any instructions fetched
Expand Down
83 changes: 39 additions & 44 deletions rmm/src/mm/translation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::page_table::entry::Entry;
use super::page_table::{attr, L1Table};
use crate::config::{PAGE_SIZE, RMM_SHARED_BUFFER_START};
use crate::config::{PlatformMemoryLayout, PAGE_SIZE, RMM_SHARED_BUFFER_START};
use crate::mm::page::BasePageSize;
use crate::mm::page_table::entry::PTDesc;

Expand All @@ -15,12 +15,6 @@ use core::fmt;
use lazy_static::lazy_static;
use spin::mutex::Mutex;

extern "C" {
static __RMM_BASE__: u64;
static __RW_START__: u64;
static __RW_END__: u64;
}

pub struct PageTable {
page_table: &'static Mutex<Inner<'static>>,
}
Expand All @@ -45,10 +39,13 @@ lazy_static! {
static ref RMM_PAGE_TABLE: Mutex<Inner<'static>> = Mutex::new(Inner::new());
}

pub fn get_page_table() -> u64 {
pub fn init_page_table(layout: PlatformMemoryLayout) {
let mut page_table = RMM_PAGE_TABLE.lock();
page_table.fill();
page_table.get_base_address() as u64
page_table.fill(layout);
}

pub fn get_page_table() -> u64 {
RMM_PAGE_TABLE.lock().get_base_address() as u64
}

pub fn drop_page_table() {
Expand Down Expand Up @@ -77,7 +74,7 @@ impl<'a> Inner<'a> {
}
}

fn fill(&mut self) {
fn fill(&mut self, layout: PlatformMemoryLayout) {
if self.dirty {
return;
}
Expand All @@ -86,40 +83,38 @@ impl<'a> Inner<'a> {
let rw_flags = bits_in_reg(PTDesc::AP, attr::permission::RW);
let rmm_flags = bits_in_reg(PTDesc::INDX, attr::mair_idx::RMM_MEM);
let device_flags = bits_in_reg(PTDesc::INDX, attr::mair_idx::DEVICE_MEM);
let base_address = layout.rmm_base;
let rw_start = layout.rw_start;
let ro_size = rw_start - base_address;
let rw_size = layout.rw_end - rw_start;
let uart_phys = layout.uart_phys;
let shared_start = RMM_SHARED_BUFFER_START;
self.set_pages(
VirtAddr::from(base_address),
PhysAddr::from(base_address),
ro_size as usize,
ro_flags | rmm_flags,
);
self.set_pages(
VirtAddr::from(rw_start),
PhysAddr::from(rw_start),
rw_size as usize,
rw_flags | rmm_flags,
);
// UART
self.set_pages(
VirtAddr::from(uart_phys),
PhysAddr::from(uart_phys),
PAGE_SIZE,
rw_flags | device_flags,
);
self.set_pages(
VirtAddr::from(shared_start),
PhysAddr::from(shared_start),
PAGE_SIZE,
rw_flags | rmm_flags,
);

unsafe {
let base_address = &__RMM_BASE__ as *const u64 as u64;
let rw_start = &__RW_START__ as *const u64 as u64;
let ro_size = rw_start - base_address;
let rw_size = &__RW_END__ as *const u64 as u64 - rw_start;
let uart_phys: u64 = 0x1c0c_0000;
let shared_start = RMM_SHARED_BUFFER_START;
self.set_pages(
VirtAddr::from(base_address),
PhysAddr::from(base_address),
ro_size as usize,
ro_flags | rmm_flags,
);
self.set_pages(
VirtAddr::from(rw_start),
PhysAddr::from(rw_start),
rw_size as usize,
rw_flags | rmm_flags,
);
// UART
self.set_pages(
VirtAddr::from(uart_phys),
PhysAddr::from(uart_phys),
PAGE_SIZE,
rw_flags | device_flags,
);
self.set_pages(
VirtAddr::from(shared_start),
PhysAddr::from(shared_start),
PAGE_SIZE,
rw_flags | rmm_flags,
);
}
//TODO Set dirty only if pages are updated, not added
self.dirty = true;
}
Expand Down

0 comments on commit a12a20c

Please sign in to comment.