14#if defined(CONFIG_AARCH32_ARMV8_R)
15#define MPU_IR_REGION_Msk (0xFFU)
16#define MPU_IR_REGION_Pos 8U
18#define MPU_RBAR_BASE_Pos 6U
19#define MPU_RBAR_BASE_Msk (0x3FFFFFFFFFFFFFFUL << MPU_RBAR_BASE_Pos)
20#define MPU_RBAR_SH_Pos 3U
21#define MPU_RBAR_SH_Msk (0x3UL << MPU_RBAR_SH_Pos)
22#define MPU_RBAR_AP_Pos 1U
23#define MPU_RBAR_AP_Msk (0x3UL << MPU_RBAR_AP_Pos)
25#define MPU_RBAR_XN_Pos 0U
26#define MPU_RBAR_XN_Msk (0x1UL << MPU_RBAR_XN_Pos)
29#define MPU_RLAR_LIMIT_Pos 6U
30#define MPU_RLAR_LIMIT_Msk (0x3FFFFFFFFFFFFFFUL << MPU_RLAR_LIMIT_Pos)
31#define MPU_RLAR_AttrIndx_Pos 1U
32#define MPU_RLAR_AttrIndx_Msk (0x7UL << MPU_RLAR_AttrIndx_Pos)
33#define MPU_RLAR_EN_Msk (0x1UL)
35#include <cmsis_core.h>
46#define P_RW_U_NA_Msk ((P_RW_U_NA << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk)
52#define P_RW_U_RW_Msk ((P_RW_U_RW << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk)
54#define FULL_ACCESS 0x1
55#define FULL_ACCESS_Msk ((FULL_ACCESS << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk)
58#define P_RO_U_NA_Msk ((P_RO_U_NA << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk)
61#define P_RO_U_RO_Msk ((P_RO_U_RO << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk)
64#define RO_Msk ((RO << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk)
67#define NOT_EXEC MPU_RBAR_XN_Msk
70#define NON_SHAREABLE 0x0
71#define NON_SHAREABLE_Msk \
72 ((NON_SHAREABLE << MPU_RBAR_SH_Pos) & MPU_RBAR_SH_Msk)
73#define OUTER_SHAREABLE 0x2
74#define OUTER_SHAREABLE_Msk \
75 ((OUTER_SHAREABLE << MPU_RBAR_SH_Pos) & MPU_RBAR_SH_Msk)
76#define INNER_SHAREABLE 0x3
77#define INNER_SHAREABLE_Msk \
78 ((INNER_SHAREABLE << MPU_RBAR_SH_Pos) & MPU_RBAR_SH_Msk)
81#define REGION_LIMIT_ADDR(base, size) \
82 (((base & MPU_RBAR_BASE_Msk) + size - 1) & MPU_RLAR_LIMIT_Msk)
85#if defined(CONFIG_AARCH32_ARMV8_R)
104#define DEVICE_nGnRnE 0x0U
105#define DEVICE_nGnRE 0x4U
106#define DEVICE_nGRE 0x8U
107#define DEVICE_GRE 0xCU
111#define R_NON_W_NON 0x0
112#define R_NON_W_ALLOC 0x1
113#define R_ALLOC_W_NON 0x2
114#define R_ALLOC_W_ALLOC 0x3
117#define NORMAL_O_WT_NT 0x80
118#define NORMAL_O_WB_NT 0xC0
119#define NORMAL_O_NON_C 0x40
121#define NORMAL_I_WT_NT 0x08
122#define NORMAL_I_WB_NT 0x0C
123#define NORMAL_I_NON_C 0x04
125#define NORMAL_OUTER_INNER_WRITE_THROUGH_READ_ALLOCATE_NON_TRANS \
126 ((NORMAL_O_WT_NT | (R_ALLOC_W_NON << 4)) \
128 (NORMAL_I_WT_NT | R_ALLOC_W_NON)) \
130#define NORMAL_OUTER_INNER_WRITE_BACK_WRITE_READ_ALLOCATE_NON_TRANS \
131 ((NORMAL_O_WB_NT | (R_ALLOC_W_ALLOC << 4)) \
133 (NORMAL_I_WB_NT | R_ALLOC_W_ALLOC))
135#define NORMAL_OUTER_INNER_NON_CACHEABLE \
136 ((NORMAL_O_NON_C | (R_NON_W_NON << 4)) \
138 (NORMAL_I_NON_C | R_NON_W_NON))
141#define MPU_CACHE_ATTRIBUTES_FLASH \
142 NORMAL_OUTER_INNER_WRITE_THROUGH_READ_ALLOCATE_NON_TRANS
143#define MPU_CACHE_ATTRIBUTES_SRAM \
144 NORMAL_OUTER_INNER_WRITE_BACK_WRITE_READ_ALLOCATE_NON_TRANS
145#define MPU_CACHE_ATTRIBUTES_SRAM_NOCACHE \
146 NORMAL_OUTER_INNER_NON_CACHEABLE
149#define MPU_MAIR_ATTR_FLASH MPU_CACHE_ATTRIBUTES_FLASH
150#define MPU_MAIR_INDEX_FLASH 0
151#define MPU_MAIR_ATTR_SRAM MPU_CACHE_ATTRIBUTES_SRAM
152#define MPU_MAIR_INDEX_SRAM 1
153#define MPU_MAIR_ATTR_SRAM_NOCACHE MPU_CACHE_ATTRIBUTES_SRAM_NOCACHE
154#define MPU_MAIR_INDEX_SRAM_NOCACHE 2
156#if defined(CONFIG_AARCH32_ARMV8_R)
157#define MPU_MAIR_ATTR_DEVICE DEVICE_nGnRnE
158#define MPU_MAIR_INDEX_DEVICE 3
164#define MPU_MAIR_ATTRS \
165 ((MPU_MAIR_ATTR_FLASH << (MPU_MAIR_INDEX_FLASH * 8)) | \
166 (MPU_MAIR_ATTR_SRAM << (MPU_MAIR_INDEX_SRAM * 8)) | \
167 (MPU_MAIR_ATTR_SRAM_NOCACHE << (MPU_MAIR_INDEX_SRAM_NOCACHE * 8)) | \
168 (MPU_MAIR_ATTR_DEVICE << (MPU_MAIR_INDEX_DEVICE * 8)))
174#define MPU_MAIR_ATTRS \
175 (((MPU_MAIR_ATTR_FLASH << MPU_MAIR0_Attr0_Pos) & MPU_MAIR0_Attr0_Msk) | \
176 ((MPU_MAIR_ATTR_SRAM << MPU_MAIR0_Attr1_Pos) & MPU_MAIR0_Attr1_Msk) | \
177 ((MPU_MAIR_ATTR_SRAM_NOCACHE << MPU_MAIR0_Attr2_Pos) & \
178 MPU_MAIR0_Attr2_Msk))
190#if defined(CONFIG_AARCH32_ARMV8_R)
192#define ARM_MPU_REGION_INIT(p_name, p_base, p_size, p_attr) \
195 .attr = p_attr(p_base + p_size), \
198#define REGION_RAM_ATTR(limit) \
201 P_RW_U_NA_Msk | NON_SHAREABLE_Msk, \
203 .mair_idx = MPU_MAIR_INDEX_SRAM, \
204 .r_limit = limit - 1, \
207#define REGION_RAM_TEXT_ATTR(limit) \
209 .rbar = P_RO_U_RO_Msk | NON_SHAREABLE_Msk, \
211 .mair_idx = MPU_MAIR_INDEX_SRAM, \
212 .r_limit = limit - 1, \
215#define REGION_RAM_RO_ATTR(limit) \
218 P_RO_U_RO_Msk | NON_SHAREABLE_Msk, \
220 .mair_idx = MPU_MAIR_INDEX_SRAM, \
221 .r_limit = limit - 1, \
223#define REGION_RAM_NOCACHE_ATTR(limit) \
226 P_RW_U_NA_Msk | NON_SHAREABLE_Msk, \
228 .mair_idx = MPU_MAIR_INDEX_SRAM_NOCACHE, \
229 .r_limit = limit - 1, \
231#if defined(CONFIG_MPU_ALLOW_FLASH_WRITE)
235#define REGION_FLASH_ATTR(limit) \
237 .rbar = P_RW_U_RW_Msk | NON_SHAREABLE_Msk, \
239 .mair_idx = MPU_MAIR_INDEX_FLASH, \
240 .r_limit = limit - 1, \
243#define REGION_FLASH_ATTR(limit) \
245 .rbar = RO_Msk | NON_SHAREABLE_Msk, \
247 .mair_idx = MPU_MAIR_INDEX_FLASH, \
248 .r_limit = limit - 1, \
252#define REGION_DEVICE_ATTR(limit) \
255 .rbar = NOT_EXEC | P_RW_U_NA_Msk | NON_SHAREABLE_Msk, \
257 .mair_idx = MPU_MAIR_INDEX_DEVICE, \
259 .r_limit = limit - 1, \
263#define ARM_MPU_REGION_INIT(p_name, p_base, p_size, p_attr) \
266 .attr = p_attr(p_base, p_size), \
273#define REGION_RAM_ATTR(base, size) \
275 .rbar = IF_ENABLED(CONFIG_XIP, (NOT_EXEC |)) \
276 P_RW_U_NA_Msk | NON_SHAREABLE_Msk, \
278 .mair_idx = MPU_MAIR_INDEX_SRAM, \
279 .r_limit = REGION_LIMIT_ADDR(base, size), \
282#define REGION_RAM_NOCACHE_ATTR(base, size) \
285 P_RW_U_NA_Msk | NON_SHAREABLE_Msk, \
287 .mair_idx = MPU_MAIR_INDEX_SRAM_NOCACHE, \
288 .r_limit = REGION_LIMIT_ADDR(base, size), \
291#if defined(CONFIG_MPU_ALLOW_FLASH_WRITE)
295#define REGION_FLASH_ATTR(base, size) \
297 .rbar = P_RW_U_RW_Msk | NON_SHAREABLE_Msk, \
299 .mair_idx = MPU_MAIR_INDEX_FLASH, \
300 .r_limit = REGION_LIMIT_ADDR(base, size), \
303#define REGION_FLASH_ATTR(base, size) \
305 .rbar = RO_Msk | NON_SHAREABLE_Msk, \
307 .mair_idx = MPU_MAIR_INDEX_FLASH, \
308 .r_limit = REGION_LIMIT_ADDR(base, size), \
343#define K_MEM_PARTITION_P_RW_U_RW ((k_mem_partition_attr_t) \
344 {(P_RW_U_RW_Msk | NOT_EXEC), MPU_MAIR_INDEX_SRAM})
345#define K_MEM_PARTITION_P_RW_U_NA ((k_mem_partition_attr_t) \
346 {(P_RW_U_NA_Msk | NOT_EXEC), MPU_MAIR_INDEX_SRAM})
347#define K_MEM_PARTITION_P_RO_U_RO ((k_mem_partition_attr_t) \
348 {(P_RO_U_RO_Msk | NOT_EXEC), MPU_MAIR_INDEX_SRAM})
349#define K_MEM_PARTITION_P_RO_U_NA ((k_mem_partition_attr_t) \
350 {(P_RO_U_NA_Msk | NOT_EXEC), MPU_MAIR_INDEX_SRAM})
353#define K_MEM_PARTITION_P_RWX_U_RWX ((k_mem_partition_attr_t) \
354 {(P_RW_U_RW_Msk), MPU_MAIR_INDEX_SRAM})
355#define K_MEM_PARTITION_P_RX_U_RX ((k_mem_partition_attr_t) \
356 {(P_RO_U_RO_Msk), MPU_MAIR_INDEX_SRAM})
366#define K_MEM_PARTITION_IS_WRITABLE(attr) \
368 int __is_writable__; \
369 switch (attr.rbar & MPU_RBAR_AP_Msk) { \
370 case P_RW_U_RW_Msk: \
371 case P_RW_U_NA_Msk: \
372 __is_writable__ = 1; \
375 __is_writable__ = 0; \
389#define K_MEM_PARTITION_IS_EXECUTABLE(attr) \
390 (!((attr.rbar) & (NOT_EXEC)))
395#define K_MEM_PARTITION_P_RW_U_RW_NOCACHE ((k_mem_partition_attr_t) \
396 {(P_RW_U_RW_Msk | NOT_EXEC | OUTER_SHAREABLE_Msk), \
397 MPU_MAIR_INDEX_SRAM_NOCACHE})
398#define K_MEM_PARTITION_P_RW_U_NA_NOCACHE ((k_mem_partition_attr_t) \
399 {(P_RW_U_NA_Msk | NOT_EXEC | OUTER_SHAREABLE_Msk), \
400 MPU_MAIR_INDEX_SRAM_NOCACHE})
401#define K_MEM_PARTITION_P_RO_U_RO_NOCACHE ((k_mem_partition_attr_t) \
402 {(P_RO_U_RO_Msk | NOT_EXEC | OUTER_SHAREABLE_Msk), \
403 MPU_MAIR_INDEX_SRAM_NOCACHE})
404#define K_MEM_PARTITION_P_RO_U_NA_NOCACHE ((k_mem_partition_attr_t) \
405 {(P_RO_U_NA_Msk | NOT_EXEC | OUTER_SHAREABLE_Msk), \
406 MPU_MAIR_INDEX_SRAM_NOCACHE})
409#define K_MEM_PARTITION_P_RWX_U_RWX_NOCACHE ((k_mem_partition_attr_t) \
410 {(P_RW_U_RW_Msk | OUTER_SHAREABLE_Msk), MPU_MAIR_INDEX_SRAM_NOCACHE})
411#define K_MEM_PARTITION_P_RX_U_RX_NOCACHE ((k_mem_partition_attr_t) \
412 {(P_RO_U_RO_Msk | OUTER_SHAREABLE_Msk), MPU_MAIR_INDEX_SRAM_NOCACHE})
416#define _ARCH_MEM_PARTITION_ALIGN_CHECK(start, size) \
417 BUILD_ASSERT((size > 0) && ((uint32_t)start % \
418 CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE == 0U) && \
419 ((size) % CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE == 0), \
420 " the start and size of the partition must align " \
421 "with the minimum MPU region size.")
uint32_t k_mem_partition_attr_t
Definition arch.h:346
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Definition arm_mpu_v7m.h:152
uint8_t rbar
Definition arm_mpu_v8.h:316
uint32_t r_limit
Definition arm_mpu_v8.h:320
uint8_t mair_idx
Definition arm_mpu_v8.h:318
uint16_t rbar
Definition arm_mpu_v8.h:327
uint16_t mair_idx
Definition arm_mpu_v8.h:328