You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
3.3 KiB
Rust
89 lines
3.3 KiB
Rust
5 years ago
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||
5 years ago
|
//
|
||
4 years ago
|
// Copyright (c) 2018-2020 Andre Richter <andre.o.richter@gmail.com>
|
||
5 years ago
|
|
||
4 years ago
|
//! BSP Memory Management Unit.
|
||
5 years ago
|
|
||
4 years ago
|
use super::map as memory_map;
|
||
4 years ago
|
use crate::memory::mmu::*;
|
||
5 years ago
|
use core::ops::RangeInclusive;
|
||
|
|
||
5 years ago
|
//--------------------------------------------------------------------------------------------------
|
||
4 years ago
|
// Public Definitions
|
||
5 years ago
|
//--------------------------------------------------------------------------------------------------
|
||
|
|
||
4 years ago
|
const NUM_MEM_RANGES: usize = 3;
|
||
5 years ago
|
|
||
4 years ago
|
/// The virtual memory layout.
|
||
|
///
|
||
|
/// The layout must contain only special ranges, aka anything that is _not_ normal cacheable DRAM.
|
||
|
/// It is agnostic of the paging granularity that the architecture's MMU will use.
|
||
5 years ago
|
pub static LAYOUT: KernelVirtualLayout<{ NUM_MEM_RANGES }> = KernelVirtualLayout::new(
|
||
4 years ago
|
memory_map::END_INCLUSIVE,
|
||
5 years ago
|
[
|
||
4 years ago
|
TranslationDescriptor {
|
||
5 years ago
|
name: "Kernel code and RO data",
|
||
4 years ago
|
virtual_range: ro_range_inclusive,
|
||
|
physical_range_translation: Translation::Identity,
|
||
5 years ago
|
attribute_fields: AttributeFields {
|
||
|
mem_attributes: MemAttributes::CacheableDRAM,
|
||
|
acc_perms: AccessPermissions::ReadOnly,
|
||
|
execute_never: false,
|
||
|
},
|
||
|
},
|
||
4 years ago
|
TranslationDescriptor {
|
||
5 years ago
|
name: "Remapped Device MMIO",
|
||
4 years ago
|
virtual_range: remapped_mmio_range_inclusive,
|
||
4 years ago
|
physical_range_translation: Translation::Offset(memory_map::mmio::START + 0x20_0000),
|
||
5 years ago
|
attribute_fields: AttributeFields {
|
||
|
mem_attributes: MemAttributes::Device,
|
||
|
acc_perms: AccessPermissions::ReadWrite,
|
||
|
execute_never: true,
|
||
|
},
|
||
|
},
|
||
4 years ago
|
TranslationDescriptor {
|
||
5 years ago
|
name: "Device MMIO",
|
||
4 years ago
|
virtual_range: mmio_range_inclusive,
|
||
|
physical_range_translation: Translation::Identity,
|
||
5 years ago
|
attribute_fields: AttributeFields {
|
||
|
mem_attributes: MemAttributes::Device,
|
||
|
acc_perms: AccessPermissions::ReadWrite,
|
||
|
execute_never: true,
|
||
|
},
|
||
|
},
|
||
|
],
|
||
|
);
|
||
4 years ago
|
|
||
4 years ago
|
//--------------------------------------------------------------------------------------------------
|
||
|
// Private Code
|
||
|
//--------------------------------------------------------------------------------------------------
|
||
|
|
||
|
fn ro_range_inclusive() -> RangeInclusive<usize> {
|
||
|
// Notice the subtraction to turn the exclusive end into an inclusive end.
|
||
|
#[allow(clippy::range_minus_one)]
|
||
|
RangeInclusive::new(super::ro_start(), super::ro_end() - 1)
|
||
|
}
|
||
|
|
||
|
fn remapped_mmio_range_inclusive() -> RangeInclusive<usize> {
|
||
|
// The last 64 KiB slot in the first 512 MiB
|
||
|
RangeInclusive::new(0x1FFF_0000, 0x1FFF_FFFF)
|
||
|
}
|
||
|
|
||
|
fn mmio_range_inclusive() -> RangeInclusive<usize> {
|
||
4 years ago
|
RangeInclusive::new(memory_map::mmio::START, memory_map::mmio::END_INCLUSIVE)
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
//--------------------------------------------------------------------------------------------------
|
||
|
// Public Code
|
||
|
//--------------------------------------------------------------------------------------------------
|
||
|
|
||
|
/// Return the address space size in bytes.
|
||
|
pub const fn addr_space_size() -> usize {
|
||
4 years ago
|
memory_map::END_INCLUSIVE + 1
|
||
4 years ago
|
}
|
||
|
|
||
|
/// Return a reference to the virtual memory layout.
|
||
|
pub fn virt_mem_layout() -> &'static KernelVirtualLayout<{ NUM_MEM_RANGES }> {
|
||
|
&LAYOUT
|
||
|
}
|