CPU Architecture Armv8 Memory Protection Unit (MPU) API
Module: CPU Architecture API
Structures
Name |
|
|---|---|
struct |
Arch_MpuArmv8_RegionType |
Types
Name |
|
|---|---|
typedef uint32_t |
Arch_MpuArmv8_AccessPermType |
typedef uint32_t |
Arch_MpuArmv8_ShareabilityType |
Functions
Name |
|
|---|---|
int32_t |
Arch_MpuArmv8_El2ConfigMemoryAttributes(const uint8_t * attributeArrPtr, uint8_t numAttributes) |
int32_t |
Arch_MpuArmv8_El2ConfigRegions(const Arch_MpuArmv8_RegionType * regionArrPtr, uint32_t numRegions) |
void |
Arch_MpuArmv8_El2Enable(bool enableBackgroundRegion) |
void |
Arch_MpuArmv8_El2Disable(void ) |
int32_t |
Arch_MpuArmv8_ConfigMemoryAttributes(const uint8_t * attributeArrPtr, uint8_t numAttributes) |
int32_t |
Arch_MpuArmv8_ConfigRegions(const Arch_MpuArmv8_RegionType * regionArrPtr, uint32_t numRegions) |
void |
Arch_MpuArmv8_Enable(bool enableBackgroundRegion) |
void |
Arch_MpuArmv8_Disable(void ) |
Defines
Name |
|
|---|---|
Arch_MpuArmv8_El1ConfigMemoryAttributes(attributeArrPtr, numAttributes) |
|
Arch_MpuArmv8_El1ConfigRegions(regionArrPtr, numRegions) |
|
Arch_MpuArmv8_El1Enable(enableBackgroundRegion) |
|
Arch_MpuArmv8_El1Disable() |
|
ARCH_MPU_ARMV8_ERROR_NONE |
|
ARCH_MPU_ARMV8_ERROR_INVALID_INSTANCE |
|
ARCH_MPU_ARMV8_ERROR_INVALID_PARAMS |
|
ARCH_MPU_ARMV8_ERROR_UNSUPPORTED_FEATURE |
|
ARCH_MPU_ARMV8_ERROR_UNALIGNED_ADDRESS |
|
ARCH_MPU_ARMV8_ERROR_INVALID_REGION_SIZE |
|
ARCH_MPU_ARMV8_ERROR_INVALID_ACCESS_PERM |
|
ARCH_MPU_ARMV8_ERROR_INVALID_SHAREABILITY |
|
ARCH_MPU_ARMV8_ERROR_INVALID_MEM_ATTR_IDX |
|
ARCH_MPU_ARMV8_ERROR_INVALID_NUM_REGIONS |
|
ARCH_MPU_ARMV8_MAIR_DEVICE |
|
ARCH_MPU_ARMV8_MAIR_OUTER_WT_TRANSIENT |
|
ARCH_MPU_ARMV8_MAIR_OUTER_NON_CACHEABLE |
|
ARCH_MPU_ARMV8_MAIR_OUTER_WB_TRANSIENT |
|
ARCH_MPU_ARMV8_MAIR_OUTER_WT_NON_TRANSIENT |
|
ARCH_MPU_ARMV8_MAIR_OUTER_WB_NON_TRANSIENT |
|
ARCH_MPU_ARMV8_MAIR_DEVICE_NGNRNE |
|
ARCH_MPU_ARMV8_MAIR_DEVICE_NGNRE |
|
ARCH_MPU_ARMV8_MAIR_DEVICE_NGRE |
|
ARCH_MPU_ARMV8_MAIR_DEVICE_GRE |
|
ARCH_MPU_ARMV8_MAIR_INNER_WT_TRANSIENT |
|
ARCH_MPU_ARMV8_MAIR_INNER_NON_CACHEABLE |
|
ARCH_MPU_ARMV8_MAIR_INNER_WB_TRANSIENT |
|
ARCH_MPU_ARMV8_MAIR_INNER_WT_NON_TRANSIENT |
|
ARCH_MPU_ARMV8_MAIR_INNER_WB_NON_TRANSIENT |
|
ARCH_MPU_ARMV8_MAIR_OUTER_ALLOC_WRITE |
|
ARCH_MPU_ARMV8_MAIR_OUTER_ALLOC_READ |
|
ARCH_MPU_ARMV8_MAIR_OUTER_ALLOC_READ_WRITE |
|
ARCH_MPU_ARMV8_MAIR_INNER_ALLOC_WRITE |
|
ARCH_MPU_ARMV8_MAIR_INNER_ALLOC_READ |
|
ARCH_MPU_ARMV8_MAIR_INNER_ALLOC_READ_WRITE |
|
ARCH_MPU_ARMV8_MEMORY_PERIPHERALS |
|
ARCH_MPU_ARMV8_MEMORY_CACHED |
|
ARCH_MPU_ARMV8_MEMORY_NON_CACHED |
|
ARCH_MPU_ARMV8_ACCESS_PERM_RW_PRIV |
|
ARCH_MPU_ARMV8_ACCESS_PERM_RW_ANY |
|
ARCH_MPU_ARMV8_ACCESS_PERM_RO_PRIV |
|
ARCH_MPU_ARMV8_ACCESS_PERM_RO_ANY |
|
ARCH_MPU_ARMV8_EL2_ACCESS_PERM_RW_EL2 |
|
ARCH_MPU_ARMV8_EL2_ACCESS_PERM_RW_ANY |
|
ARCH_MPU_ARMV8_EL2_ACCESS_PERM_RO_EL2 |
|
ARCH_MPU_ARMV8_EL2_ACCESS_PERM_RO_ANY |
|
ARCH_MPU_ARMV8_SHAREABILITY_NONE |
|
ARCH_MPU_ARMV8_SHAREABILITY_OUTER |
|
ARCH_MPU_ARMV8_SHAREABILITY_INNER |
|
ARCH_MPU_ARMV8_ACCESS_PERM_MAX |
Detailed Description
This includes APIs for initializing, configuring and enabling Armv8 Protected Memory System Architecture (PMSAv8) Memory Protection Unit (MPU).
Notes,
Arch_MpuArmv8_ConfigMemoryAttributes can be used to setup various memory attributes to be used for the MPU regions.
Various defines under [Arch_MpuArmv8_MairType] can be used to form the MAIR attribute value. Also [Arch_MpuArmv8_PredefinedMemoryType] can be used directly for common memory types.
Each attribute value is 8-bits wide and up to 8 attributes can be defined. Example usage:
uint8_t attributesArr[4] = {
ARCH_MPU_ARMV8_MEMORY_PERIPHERALS, // Attr indx 0
ARCH_MPU_ARMV8_MEMORY_NON_CACHED, // Attr indx 1
ARCH_MPU_ARMV8_MEMORY_CACHED, // Attr indx 2
// Attr indx 3: Normal, Outer Write-Back Transient Read Write alloc,
// Inner Write-Back Transient Read Write alloc
(ARCH_MPU_ARMV8_MAIR_OUTER_WB_TRANSIENT | ARCH_MPU_ARMV8_MAIR_OUTER_ALLOC_READ_WRITE) |
(ARCH_MPU_ARMV8_MAIR_INNER_WB_TRANSIENT | ARCH_MPU_ARMV8_MAIR_INNER_ALLOC_READ_WRITE)
};
Arch_MpuArmv8_ConfigMemoryAttributes(attributesArr, 4U);
For cacheable transient memory types, either or both Read/Write allocation policy bits should be used. Otherwise, undesired side effects may occur.
Arch_MpuArmv8_ConfigRegions can be used to configure multiple MPU regions by providing an array of region configurations of type Arch_MpuArmv8_RegionType
Arch_MpuArmv8_RegionType::MemoryAttrIndx corresponds to the attributes index that was pre-configured via Arch_MpuArmv8_ConfigMemoryAttributes
A region is a contiguous range of addresses starting at a base address, extending up to and including a limit address. The region can not overlap other regions.
CPU architecture specific notes,
R52,
Uses Armv8-R PMSAv8-32 Memory protection units:-
EL1-controlled MPU (protection regions for accesses from EL1 and from EL0)
EL2-controlled MPU (protection regions for accesses from EL2. Also for accesses from EL1 and from EL0, if virtualization is enabled)
The region base address should be aligned on a 64-byte boundary. The minimum size for a region is 64 bytes and the size should be a multiple of 64-bytes.
The write behavior for the data cache is always write-through whatever the region attribute is write-back or write-through
TCMs always behave as Non-cacheable Non-shareable Normal memory. This is irrespective of the memory type attributes defined in the MPU.
User mode (not-privileged) refers to EL0.
Following APIs should be used only from a privileged mode. This is due to access restrictions in User mode to read/modify various MPU system registers.
Following APIs should be used only from EL2. This is due to access restrictions in EL0/EL1 to read/modify various Hyp MPU system registers.
M33,
Uses Armv8-M PMSAv8 Memory protection unit
The region base address should be aligned on a 32-byte boundary. The minimum size for a region is 32 bytes and the size should be a multiple of 32-bytes.
EL2 specific APIs are not supported and typedefs are NA.
Usage of the APIs will cause linking errors.
All APIs should be used only from privileged mode.
This is due to MPU register access restrictions - Privileged access only.
Types Documentation
typedef Arch_MpuArmv8_AccessPermType
typedef uint32_t Arch_MpuArmv8_AccessPermType;
Access permission attribute for MPU regions See [Arch_MpuArmv8_AccessPermType_] or [Arch_MpuArmv8_El2AccessPermType_] (for EL2-controlled MPU regions) for list of possible values.
Functions Documentation
function Arch_MpuArmv8_El2ConfigMemoryAttributes
int32_t Arch_MpuArmv8_El2ConfigMemoryAttributes(
const uint8_t * attributeArrPtr,
uint8_t numAttributes
)
Configure memory attribute values for EL2-controlled MPU.
Parameters:
attributeArrPtr Pointer to array containing HMAIR attribute values.
numAttributes Number of attribute entries in the array.
Return: [Arch_MpuArmv8_ErrorType]
Programs the HMAIR registers with the provided array of attribute values.
function Arch_MpuArmv8_El2ConfigRegions
int32_t Arch_MpuArmv8_El2ConfigRegions(
const Arch_MpuArmv8_RegionType * regionArrPtr,
uint32_t numRegions
)
Configure EL2-controlled MPU regions.
Parameters:
regionArrPtr Pointer to array of EL2 region configuration structures.
numRegions Number of regions to configure.
Return: [Arch_MpuArmv8_ErrorType]
Programs all EL2-controlled MPU regions using the provided array of region configuration structures.
function Arch_MpuArmv8_El2Enable
void Arch_MpuArmv8_El2Enable(
bool enableBackgroundRegion
)
Enable the EL2-controlled MPU.
Parameters:
enableBackgroundRegion Flag to enable background region (default memory map for EL2 access)
function Arch_MpuArmv8_El2Disable
void Arch_MpuArmv8_El2Disable(
void
)
Disable the EL2-controlled MPU.
function Arch_MpuArmv8_ConfigMemoryAttributes
int32_t Arch_MpuArmv8_ConfigMemoryAttributes(
const uint8_t * attributeArrPtr,
uint8_t numAttributes
)
Configure memory attribute values.
Parameters:
attributeArrPtr Pointer to array containing MAIR attribute values.
numAttributes Number of attribute entries in the array.
Return: [Arch_MpuArmv8_ErrorType]
Programs the MAIR registers with the provided array of attribute values.
function Arch_MpuArmv8_ConfigRegions
int32_t Arch_MpuArmv8_ConfigRegions(
const Arch_MpuArmv8_RegionType * regionArrPtr,
uint32_t numRegions
)
Configure MPU regions.
Parameters:
regionArrPtr Pointer to array of region configuration structures.
numRegions Number of regions to configure.
Return: [Arch_MpuArmv8_ErrorType]
Precondition: Arch_MpuArmv8_ConfigMemoryAttributes
Programs all MPU regions using the provided array of region configuration structures.
function Arch_MpuArmv8_Enable
void Arch_MpuArmv8_Enable(
bool enableBackgroundRegion
)
Enable the MPU.
Parameters:
enableBackgroundRegion Flag to enable background region (default memory map for privileged access)
function Arch_MpuArmv8_Disable
void Arch_MpuArmv8_Disable(
void
)
Disable the MPU.
Macros Documentation
define Arch_MpuArmv8_El1ConfigMemoryAttributes
#define Arch_MpuArmv8_El1ConfigMemoryAttributes(
attributeArrPtr,
numAttributes
)
Arch_MpuArmv8_ConfigMemoryAttributes((attributeArrPtr), (numAttributes))
Configure memory attribute values for EL1-controlled MPU.
Parameters:
attributeArrPtr Pointer to array containing MAIR attribute values.
numAttributes Number of attribute entries in the array.
Return: [Arch_MpuArmv8_ErrorType]
Programs the MAIR registers with the provided array of attribute values.
define Arch_MpuArmv8_El1ConfigRegions
#define Arch_MpuArmv8_El1ConfigRegions(
regionArrPtr,
numRegions
)
Arch_MpuArmv8_ConfigRegions((regionArrPtr), (numRegions))
Configure MPU regions for EL1-controlled MPU.
Parameters:
regionArrPtr Pointer to array of EL1 region configuration structures.
numRegions Number of regions to configure.
Return: [Arch_MpuArmv8_ErrorType]
Programs all EL1-controlled MPU regions using the provided array of region configuration structures.
define Arch_MpuArmv8_El1Enable
#define Arch_MpuArmv8_El1Enable(
enableBackgroundRegion
)
Arch_MpuArmv8_Enable((enableBackgroundRegion))
Enable the EL1-controlled MPU.
Parameters:
enableBackgroundRegion Flag to enable background region (default memory map for EL1 access)
define Arch_MpuArmv8_El1Disable
#define Arch_MpuArmv8_El1Disable(
)
Arch_MpuArmv8_Disable()
Disable the EL1-controlled MPU.
define ARCH_MPU_ARMV8_ERROR_NONE
#define ARCH_MPU_ARMV8_ERROR_NONE (0)
No error.
define ARCH_MPU_ARMV8_ERROR_INVALID_INSTANCE
#define ARCH_MPU_ARMV8_ERROR_INVALID_INSTANCE (1)
Invalid instance.
define ARCH_MPU_ARMV8_ERROR_INVALID_PARAMS
#define ARCH_MPU_ARMV8_ERROR_INVALID_PARAMS (2)
Invalid params.
define ARCH_MPU_ARMV8_ERROR_UNSUPPORTED_FEATURE
#define ARCH_MPU_ARMV8_ERROR_UNSUPPORTED_FEATURE (3)
Feature not supported by underlying architecture.
define ARCH_MPU_ARMV8_ERROR_UNALIGNED_ADDRESS
#define ARCH_MPU_ARMV8_ERROR_UNALIGNED_ADDRESS (4)
Address alignment requirements not met.
define ARCH_MPU_ARMV8_ERROR_INVALID_REGION_SIZE
#define ARCH_MPU_ARMV8_ERROR_INVALID_REGION_SIZE (5)
Invalid region size.
define ARCH_MPU_ARMV8_ERROR_INVALID_ACCESS_PERM
#define ARCH_MPU_ARMV8_ERROR_INVALID_ACCESS_PERM (6)
Invalid access permission.
define ARCH_MPU_ARMV8_ERROR_INVALID_MEM_ATTR_IDX
#define ARCH_MPU_ARMV8_ERROR_INVALID_MEM_ATTR_IDX (8)
Invalid mem attribute index.
define ARCH_MPU_ARMV8_ERROR_INVALID_NUM_REGIONS
#define ARCH_MPU_ARMV8_ERROR_INVALID_NUM_REGIONS (9)
Invalid no. of regions.
define ARCH_MPU_ARMV8_MAIR_DEVICE
#define ARCH_MPU_ARMV8_MAIR_DEVICE (uint32_t)((uint32_t)0x0U << 4U)
(0b0000) Device
define ARCH_MPU_ARMV8_MAIR_OUTER_WT_TRANSIENT
#define ARCH_MPU_ARMV8_MAIR_OUTER_WT_TRANSIENT (uint32_t)((uint32_t)0x0U << 4U)
(0b00RW) Normal Outer Write-Through transient (RW != 00)
define ARCH_MPU_ARMV8_MAIR_OUTER_NON_CACHEABLE
#define ARCH_MPU_ARMV8_MAIR_OUTER_NON_CACHEABLE (uint32_t)((uint32_t)0x4U << 4U)
(0b0100) Normal Outer Non-Cacheable
define ARCH_MPU_ARMV8_MAIR_OUTER_WB_TRANSIENT
#define ARCH_MPU_ARMV8_MAIR_OUTER_WB_TRANSIENT (uint32_t)((uint32_t)0x4U << 4U)
(0b01RW) Normal Outer Write-Back transient (RW != 00)
define ARCH_MPU_ARMV8_MAIR_OUTER_WT_NON_TRANSIENT
#define ARCH_MPU_ARMV8_MAIR_OUTER_WT_NON_TRANSIENT (uint32_t)((uint32_t)0x8U << 4U)
(0b10RW) Normal Outer Write-Through non-transient
define ARCH_MPU_ARMV8_MAIR_OUTER_WB_NON_TRANSIENT
#define ARCH_MPU_ARMV8_MAIR_OUTER_WB_NON_TRANSIENT (uint32_t)((uint32_t)0xCU << 4U)
(0b11RW) Normal Outer Write-Back non-transient
define ARCH_MPU_ARMV8_MAIR_DEVICE_NGNRNE
#define ARCH_MPU_ARMV8_MAIR_DEVICE_NGNRNE (uint32_t)((uint32_t)0x0U << 2U)
(0b00) Device-nGnRnE memory
define ARCH_MPU_ARMV8_MAIR_DEVICE_NGNRE
#define ARCH_MPU_ARMV8_MAIR_DEVICE_NGNRE (uint32_t)((uint32_t)0x1U << 2U)
(0b01) Device-nGnRE memory
define ARCH_MPU_ARMV8_MAIR_DEVICE_NGRE
#define ARCH_MPU_ARMV8_MAIR_DEVICE_NGRE (uint32_t)((uint32_t)0x2U << 2U)
(0b10) Device-nGRE memory
define ARCH_MPU_ARMV8_MAIR_DEVICE_GRE
#define ARCH_MPU_ARMV8_MAIR_DEVICE_GRE (uint32_t)((uint32_t)0x3U << 2U)
(0b11) Device-GRE memory
define ARCH_MPU_ARMV8_MAIR_INNER_WT_TRANSIENT
#define ARCH_MPU_ARMV8_MAIR_INNER_WT_TRANSIENT (0x0U)
(0b00RW) Normal Inner Write-Through transient (RW != 00)
define ARCH_MPU_ARMV8_MAIR_INNER_NON_CACHEABLE
#define ARCH_MPU_ARMV8_MAIR_INNER_NON_CACHEABLE (0x4U)
(0b0100) Normal Inner Non-Cacheable
define ARCH_MPU_ARMV8_MAIR_INNER_WB_TRANSIENT
#define ARCH_MPU_ARMV8_MAIR_INNER_WB_TRANSIENT (0x4U)
(0b01RW) Normal Inner Write-Back transient (RW != 00)
define ARCH_MPU_ARMV8_MAIR_INNER_WT_NON_TRANSIENT
#define ARCH_MPU_ARMV8_MAIR_INNER_WT_NON_TRANSIENT (0x8U)
(0b10RW) Normal Inner Write-Through non-transient
define ARCH_MPU_ARMV8_MAIR_INNER_WB_NON_TRANSIENT
#define ARCH_MPU_ARMV8_MAIR_INNER_WB_NON_TRANSIENT (0xCU)
(0b11RW) Normal Inner Write-Back non-transient
define ARCH_MPU_ARMV8_MAIR_OUTER_ALLOC_WRITE
#define ARCH_MPU_ARMV8_MAIR_OUTER_ALLOC_WRITE (uint32_t)((uint32_t)0x1U << 4U)
(0b01) Write allocate only (R=0, W=1)
define ARCH_MPU_ARMV8_MAIR_OUTER_ALLOC_READ
#define ARCH_MPU_ARMV8_MAIR_OUTER_ALLOC_READ (uint32_t)((uint32_t)0x2U << 4U)
(0b10) Read allocate only (R=1, W=0)
define ARCH_MPU_ARMV8_MAIR_OUTER_ALLOC_READ_WRITE
#define ARCH_MPU_ARMV8_MAIR_OUTER_ALLOC_READ_WRITE (uint32_t)((uint32_t)0x3U << 4U)
(0b11) Read/Write allocate (R=1, W=1)
define ARCH_MPU_ARMV8_MAIR_INNER_ALLOC_WRITE
#define ARCH_MPU_ARMV8_MAIR_INNER_ALLOC_WRITE (0x1U)
(0b01) Write allocate only (R=0, W=1)
define ARCH_MPU_ARMV8_MAIR_INNER_ALLOC_READ
#define ARCH_MPU_ARMV8_MAIR_INNER_ALLOC_READ (0x2U)
(0b10) Read allocate only (R=1, W=0)
define ARCH_MPU_ARMV8_MAIR_INNER_ALLOC_READ_WRITE
#define ARCH_MPU_ARMV8_MAIR_INNER_ALLOC_READ_WRITE (0x3U)
(0b11) Read/Write allocate (R=1, W=1)
define ARCH_MPU_ARMV8_MEMORY_PERIPHERALS
#define ARCH_MPU_ARMV8_MEMORY_PERIPHERALS (ARCH_MPU_ARMV8_MAIR_DEVICE | ARCH_MPU_ARMV8_MAIR_DEVICE_NGNRNE)
Peripheral MMRs.
define ARCH_MPU_ARMV8_MEMORY_CACHED
#define ARCH_MPU_ARMV8_MEMORY_CACHED (ARCH_MPU_ARMV8_MAIR_OUTER_WB_NON_TRANSIENT | ARCH_MPU_ARMV8_MAIR_OUTER_ALLOC_READ_WRITE) | \
(ARCH_MPU_ARMV8_MAIR_INNER_WB_NON_TRANSIENT | ARCH_MPU_ARMV8_MAIR_INNER_ALLOC_READ_WRITE)
Cached Memory.
define ARCH_MPU_ARMV8_MEMORY_NON_CACHED
#define ARCH_MPU_ARMV8_MEMORY_NON_CACHED (ARCH_MPU_ARMV8_MAIR_OUTER_NON_CACHEABLE | ARCH_MPU_ARMV8_MAIR_INNER_NON_CACHEABLE)
Non-cached Memory.
define ARCH_MPU_ARMV8_ACCESS_PERM_RW_PRIV
#define ARCH_MPU_ARMV8_ACCESS_PERM_RW_PRIV (0x0U)
(0b00) Read/write by privileged code only
define ARCH_MPU_ARMV8_ACCESS_PERM_RW_ANY
#define ARCH_MPU_ARMV8_ACCESS_PERM_RW_ANY (0x1U)
(0b01) Read/write by any privilege level
define ARCH_MPU_ARMV8_ACCESS_PERM_RO_PRIV
#define ARCH_MPU_ARMV8_ACCESS_PERM_RO_PRIV (0x2U)
(0b10) Read-only by privileged code only
define ARCH_MPU_ARMV8_ACCESS_PERM_RO_ANY
#define ARCH_MPU_ARMV8_ACCESS_PERM_RO_ANY (0x3U)
(0b11) Read-only by any privilege level
define ARCH_MPU_ARMV8_EL2_ACCESS_PERM_RW_EL2
#define ARCH_MPU_ARMV8_EL2_ACCESS_PERM_RW_EL2 (0x0U)
(0b00) Read/write at EL2, no access at EL1 or EL0
define ARCH_MPU_ARMV8_EL2_ACCESS_PERM_RW_ANY
#define ARCH_MPU_ARMV8_EL2_ACCESS_PERM_RW_ANY (0x1U)
(0b01) Read/write at EL2, EL1 and EL0
define ARCH_MPU_ARMV8_EL2_ACCESS_PERM_RO_EL2
#define ARCH_MPU_ARMV8_EL2_ACCESS_PERM_RO_EL2 (0x2U)
(0b10) Read-only at EL2, no access at EL1 or EL0
define ARCH_MPU_ARMV8_EL2_ACCESS_PERM_RO_ANY
#define ARCH_MPU_ARMV8_EL2_ACCESS_PERM_RO_ANY (0x3U)
(0b11) Read-only at EL2, EL1 and EL0
define ARCH_MPU_ARMV8_ACCESS_PERM_MAX
#define ARCH_MPU_ARMV8_ACCESS_PERM_MAX (0x3U)
Max value for Arch_MpuArmv8_AccessPermType.