Memory Protection Unit (MPU)
Introduction
The Memory Protection Unit (MPU) is a component provided by Arm and is used to provide hardware protection by software definition. The SDK provides the mpu_region_config struct to set the region memory attribute of MPU.
The following table lists the member variables of the mpu_region_config struct.
Member variable name |
Type |
Description |
---|---|---|
region_base |
uint32_t |
MPU region base address, 32 bytes aligned |
region_size |
uint32_t |
MPU region size, 32 bytes aligned |
xn |
uint8_t |
Execute Never attribute
|
ap |
uint8_t |
Access permissions
|
sh |
uint8_t |
Shareability of Normal memory
|
attr_idx |
uint8_t |
Memory attribute indirect index This parameter can be a value of 0 ~ 7, with detailed attributes defined in mpu_init() and customizable. The typical definition is as follows:
|
MPU APIs
Items |
Description |
---|---|
Introduction |
Initialize MPU region memory attribute to typical value |
Parameters |
None |
Return |
None |
Items |
Description |
---|---|
Introduction |
Change MPU region memory attribute |
Parameters |
|
Return |
None |
Items |
Description |
---|---|
Introduction |
Configure MPU region memory attribute. |
Parameters |
|
Return |
None |
Items |
Description |
---|---|
Introduction |
Free MPU entry |
Parameters |
MPU entry index:
|
Return |
None |
Items |
Description |
---|---|
Introduction |
Allocate a free MPU entry |
Parameters |
None |
Return |
MPU entry index:
|
Items |
Description |
---|---|
Introduction |
Initialize MPU region memory attribute to typical value |
Parameters |
None |
Return |
None |
Items |
Description |
---|---|
Introduction |
Change MPU region memory attribute |
Parameters |
|
Return |
None |
Items |
Description |
---|---|
Introduction |
Configure MPU region memory attribute. |
Parameters |
|
Return |
None |
Items |
Description |
---|---|
Introduction |
Free MPU entry |
Parameters |
MPU entry index:
|
Return |
None |
Items |
Description |
---|---|
Introduction |
Allocate a free MPU entry |
Parameters |
None |
Return |
MPU entry index:
|
Items |
Description |
---|---|
Introduction |
Initialize MPU region memory attribute to typical value |
Parameters |
None |
Return |
None |
Items |
Description |
---|---|
Introduction |
Change MPU region memory attribute |
Parameters |
|
Return |
None |
Items |
Description |
---|---|
Introduction |
Configure MPU region memory attribute. |
Parameters |
|
Return |
None |
Items |
Description |
---|---|
Introduction |
Free MPU entry |
Parameters |
MPU entry index:
|
Return |
None |
Items |
Description |
---|---|
Introduction |
Allocate a free MPU entry |
Parameters |
None |
Return |
MPU entry index:
|
Items |
Description |
---|---|
Introduction |
Initialize MPU region memory attribute to typical value |
Parameters |
None |
Return |
None |
Items |
Description |
---|---|
Introduction |
Change MPU region memory attribute |
Parameters |
|
Return |
None |
Items |
Description |
---|---|
Introduction |
Configure MPU region memory attribute. |
Parameters |
|
Return |
None |
Items |
Description |
---|---|
Introduction |
Free MPU entry |
Parameters |
MPU entry index:
|
Return |
None |
Items |
Description |
---|---|
Introduction |
Allocate a free MPU entry |
Parameters |
None |
Return |
MPU entry index:
|
Usage
Follow these steps to set an MPU region:
Define new variable and struct
Define a variable to store MPU entry index
Define a struct mpu_region_config to store the region memory attribute
Call
mpu_entry_alloc()
to allocate a free MPU entrySet the struct for region memory attribute
Call
mpu_region_cfg()
to configure MPU region memory attribute
Note
For KR4, a physical memory protection (PMP) unit is implemented, but the code in SDK does not use PMP to provide access privileges control. Refer to RISC-V privileged architecture proposal for the physical memory protection scheme to set PMP when access privileges control is needed.