2 releases
0.1.1 | Apr 26, 2021 |
---|---|
0.1.0 | Sep 26, 2020 |
#2243 in Embedded development
44 downloads per month
36KB
367 lines
RusPiRo MMU API
The crate provides the API to configure and maintain the Raspberry Pi Memory Management Unit (MMU). It allows to maintain the EL2 and EL1 configuration settings.
Usage
To use this crate simply add the dependency to your Cargo.toml
file:
[dependencies]
ruspiro-mmu = "0.1.1"
The initial setup of the MMU should be called only once during the boot sequence of the Raspberry Pi. This initial setup requires the memory region of the Raspberry Pi that is used by the GPU/VideoCore to be known.
use ruspiro_mmu::*;
fn entry_point(core: u32) {
unsafe {
mmu::initialize(core, 0xDEAD_0000, 0xBEEF);
}
}
With the MMU configured and active a physical memory region can be mapped to a new virtual one with specific memory attributes, different from the initial settings like so:
// just an arbitrary address for demonstration purposes
let phys_address = 0xDEADBEEF as *mut u8;
// the virtual address is of type *mut u8
let virtual_address = unsafe {
mmu::map_memory(phys_address, 1024,
( TTLB_BLOCKPAGE::AF::SET
| TTLB_BLOCKPAGE::SH::INNER
| TTLB_BLOCKPAGE::MEMATTR::MAIR3
| TTLB_BLOCKPAGE::TYPE::BLOCK
).raw_value()
)
};
Please note that the current virtual memory mapping is implemented on block level only. This means the smallest mapped memory region is 2MB in size regardless of the size given to the map_memory
function. Therefore the memory attributes passed to the mapping requires to be a BLOCK
entry. Passing the direct TTLB flags to the memory map function is error prone and will be replaced in upcoming releases with proper pre-defined constants to reflect the memory attribute settings and combinations that are useful.
License
Licensed under Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) or MIT (LICENSE-MIT or http://opensource.org/licenses/MIT)) at your choice.
Dependencies
~84KB