Move MAIR_EL1 initialization to rmm
Rmm needs to know the exact MAIR_EL1 configuration to produce the correct bits in the page table.
This commit is contained in:
@@ -106,6 +106,20 @@ bitflags::bitflags! {
|
||||
}
|
||||
}
|
||||
|
||||
/// Setup Memory Access Indirection Register
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
#[inline(always)]
|
||||
pub unsafe fn init_mair() {
|
||||
unsafe {
|
||||
let val: u64 = 0
|
||||
| 0x00 << 16 // DEVICE_MEMORY;
|
||||
| 0x44 << 8 // NORMAL_UNCACHED_MEMORY;
|
||||
| 0xff; // NORMAL_WRITEBACK_MEMORY
|
||||
|
||||
asm!("msr mair_el1, {}", in(reg) val);
|
||||
}
|
||||
}
|
||||
|
||||
const _: () = {
|
||||
assert!(AArch64Arch::PAGE_SIZE == 4096);
|
||||
assert!(AArch64Arch::PAGE_OFFSET_MASK == 0xFFF);
|
||||
|
||||
@@ -4,14 +4,6 @@
|
||||
|
||||
use core::arch::asm;
|
||||
|
||||
bitflags! {
|
||||
pub struct MairEl1: u64 {
|
||||
const DEVICE_MEMORY = 0x00 << 16;
|
||||
const NORMAL_UNCACHED_MEMORY = 0x44 << 8;
|
||||
const NORMAL_WRITEBACK_MEMORY = 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn ttbr0_el1() -> u64 {
|
||||
unsafe {
|
||||
let ret: u64;
|
||||
@@ -40,20 +32,6 @@ pub unsafe fn ttbr1_el1_write(val: u64) {
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn mair_el1() -> MairEl1 {
|
||||
unsafe {
|
||||
let ret: u64;
|
||||
asm!("mrs {}, mair_el1", out(reg) ret);
|
||||
MairEl1::from_bits_truncate(ret)
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn mair_el1_write(val: MairEl1) {
|
||||
unsafe {
|
||||
asm!("msr mair_el1, {}", in(reg) val.bits());
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn tpidr_el0() -> u64 {
|
||||
unsafe {
|
||||
let ret: u64;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
//! # Paging
|
||||
//! Some code was borrowed from [Phil Opp's Blog](http://os.phil-opp.com/modifying-page-tables.html)
|
||||
|
||||
use crate::device::cpu::registers::control_regs;
|
||||
|
||||
pub use super::CurrentRmmArch as RmmA;
|
||||
pub use rmm::{
|
||||
aarch64::EntryFlags, Arch as RmmArch, PageFlags, PhysicalAddress, TableKind, VirtualAddress,
|
||||
@@ -16,25 +14,11 @@ pub mod mapper;
|
||||
pub const PAGE_SIZE: usize = RmmA::PAGE_SIZE;
|
||||
pub const PAGE_MASK: usize = RmmA::PAGE_OFFSET_MASK;
|
||||
|
||||
/// Setup Memory Access Indirection Register
|
||||
#[cold]
|
||||
unsafe fn init_mair() {
|
||||
unsafe {
|
||||
let mut val: control_regs::MairEl1 = control_regs::mair_el1();
|
||||
|
||||
val.insert(control_regs::MairEl1::DEVICE_MEMORY);
|
||||
val.insert(control_regs::MairEl1::NORMAL_UNCACHED_MEMORY);
|
||||
val.insert(control_regs::MairEl1::NORMAL_WRITEBACK_MEMORY);
|
||||
|
||||
control_regs::mair_el1_write(val);
|
||||
}
|
||||
}
|
||||
|
||||
/// Initialize MAIR
|
||||
#[cold]
|
||||
pub unsafe fn init() {
|
||||
unsafe {
|
||||
init_mair();
|
||||
rmm::aarch64::init_mair();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user