|
PebbleOS
|
Memory Protection Unit regions. More...
Data Structures | |
| struct | MpuRegion |
| MPU region, described by its real base and size. More... | |
Enumerations | |
| enum | MpuCachePolicy { MpuCachePolicy_NotCacheable , MpuCachePolicy_WriteThrough , MpuCachePolicy_WriteBackWriteAllocate , MpuCachePolicy_WriteBackNoWriteAllocate } |
| Cache policy of a region. More... | |
| enum | MpuPermissions { MpuPermissions_NoAccess , MpuPermissions_PrivRW , MpuPermissions_PrivRW_UserRO , MpuPermissions_PrivRW_UserRW , MpuPermissions_PrivRO , MpuPermissions_PrivRO_UserRO , MpuPermissionsCount } |
| Access permissions of a region. More... | |
Functions | |
| void | mpu_enable (void) |
| Enable the MPU. | |
| void | mpu_disable (void) |
| Disable the MPU. | |
| void | mpu_set_region (const MpuRegion *region) |
| Program a region. | |
| MpuRegion | mpu_get_region (int region_num) |
| Read back a programmed region. | |
| void | mpu_get_register_settings (const MpuRegion *region, uint32_t *base_address_reg, uint32_t *attributes_reg) |
| Compute the register values for a region without programming it. | |
| bool | mpu_memory_is_cachable (const void *addr) |
| Check whether an address may be cached. | |
| void | mpu_init_region_from_region (MpuRegion *copy, const MpuRegion *from, bool allow_user_access) |
| Copy a privileged read/write region, optionally granting unprivileged access. | |
Memory Protection Unit regions.
Backends exist for ARMv7-M and ARMv8-M. Regions are described by their real base and size; the backend derives the hardware encoding.
| struct MpuRegion |
MPU region, described by its real base and size.
The ARMv7-M backend rounds the region up to a power-of-two block and computes the subregion mask; the ARMv8-M backend programs the limit register directly.
| Data Fields | ||
|---|---|---|
| uintptr_t | base_address | Base address, 32-byte aligned. |
| MpuCachePolicy | cache_policy | Cache policy. |
| bool | enabled: 1 | Region is enabled. |
| bool | executable: 1 |
Allow instruction fetch (XN=0). Defaults to non-executable. Flash, app RAM, worker RAM and any code relocated to RAM must opt in. |
| MpuPermissions | permissions | Access permissions. |
| uint8_t | region_num: 4 | Region number, 0 to 15. |
| uint32_t | size | Size in bytes. |
| enum MpuCachePolicy |
| enum MpuPermissions |
Access permissions of a region.
The backends map these to the hardware AP encoding (3 bits on ARMv7-M, 2 bits on ARMv8-M). The two-bit ARMv8-M field cannot express two of them precisely:
| void mpu_disable | ( | void | ) |
Disable the MPU.
| void mpu_enable | ( | void | ) |
Enable the MPU.
The default memory map stays enabled as a background region for privileged code.
| MpuRegion mpu_get_region | ( | int | region_num | ) |
Read back a programmed region.
| region_num | Region number. |
| void mpu_get_register_settings | ( | const MpuRegion * | region, |
| uint32_t * | base_address_reg, | ||
| uint32_t * | attributes_reg | ||
| ) |
Compute the register values for a region without programming it.
| region | Region to encode. | |
| [out] | base_address_reg | Value for the RBAR register. |
| [out] | attributes_reg | Value for the RASR (ARMv7-M) or RLAR (ARMv8-M) register. |
| void mpu_init_region_from_region | ( | MpuRegion * | copy, |
| const MpuRegion * | from, | ||
| bool | allow_user_access | ||
| ) |
Copy a privileged read/write region, optionally granting unprivileged access.
Used to switch app and worker RAM regions on task switches.
| [out] | copy | Destination region. |
| from | Source region; must be MpuPermissions_PrivRW. | |
| allow_user_access | Grant unprivileged read/write access in copy. |
| bool mpu_memory_is_cachable | ( | const void * | addr | ) |
Check whether an address may be cached.
Only SRAM is considered cacheable, and only while the data cache is enabled.
| addr | Address to check. |
addr is cacheable. | void mpu_set_region | ( | const MpuRegion * | region | ) |
Program a region.
| region | Region to program, in slot MpuRegion::region_num. |