25#define P_RW_U_NA_Msk ((P_RW_U_NA << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk)
31#define P_RW_U_RW_Msk ((P_RW_U_RW << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk)
33#define FULL_ACCESS 0x1
34#define FULL_ACCESS_Msk ((FULL_ACCESS << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk)
37#define P_RO_U_NA_Msk ((P_RO_U_NA << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk)
40#define P_RO_U_RO_Msk ((P_RO_U_RO << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk)
43#define RO_Msk ((RO << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk)
46#define NOT_EXEC MPU_RBAR_XN_Msk
49#define NON_SHAREABLE 0x0
50#define NON_SHAREABLE_Msk \
51 ((NON_SHAREABLE << MPU_RBAR_SH_Pos) & MPU_RBAR_SH_Msk)
52#define OUTER_SHAREABLE 0x2
53#define OUTER_SHAREABLE_Msk \
54 ((OUTER_SHAREABLE << MPU_RBAR_SH_Pos) & MPU_RBAR_SH_Msk)
55#define INNER_SHAREABLE 0x3
56#define INNER_SHAREABLE_Msk \
57 ((INNER_SHAREABLE << MPU_RBAR_SH_Pos) & MPU_RBAR_SH_Msk)
60#define REGION_LIMIT_ADDR(base, size) \
61 (((base & MPU_RBAR_BASE_Msk) + size - 1) & MPU_RLAR_LIMIT_Msk)
67#define R_NON_W_NON 0x0
68#define R_NON_W_ALLOC 0x1
69#define R_ALLOC_W_NON 0x2
70#define R_ALLOC_W_ALLOC 0x3
73#define NORMAL_O_WT_NT 0x80
74#define NORMAL_O_WB_NT 0xC0
75#define NORMAL_O_NON_C 0x40
77#define NORMAL_I_WT_NT 0x08
78#define NORMAL_I_WB_NT 0x0C
79#define NORMAL_I_NON_C 0x04
81#define NORMAL_OUTER_INNER_WRITE_THROUGH_READ_ALLOCATE_NON_TRANS \
82 ((NORMAL_O_WT_NT | (R_ALLOC_W_NON << 4)) \
84 (NORMAL_I_WT_NT | R_ALLOC_W_NON)) \
86#define NORMAL_OUTER_INNER_WRITE_BACK_WRITE_READ_ALLOCATE_NON_TRANS \
87 ((NORMAL_O_WB_NT | (R_ALLOC_W_ALLOC << 4)) \
89 (NORMAL_I_WB_NT | R_ALLOC_W_ALLOC))
91#define NORMAL_OUTER_INNER_NON_CACHEABLE \
92 ((NORMAL_O_NON_C | (R_NON_W_NON << 4)) \
94 (NORMAL_I_NON_C | R_NON_W_NON))
97#define MPU_CACHE_ATTRIBUTES_FLASH \
98 NORMAL_OUTER_INNER_WRITE_THROUGH_READ_ALLOCATE_NON_TRANS
99#define MPU_CACHE_ATTRIBUTES_SRAM \
100 NORMAL_OUTER_INNER_WRITE_BACK_WRITE_READ_ALLOCATE_NON_TRANS
101#define MPU_CACHE_ATTRIBUTES_SRAM_NOCACHE \
102 NORMAL_OUTER_INNER_NON_CACHEABLE
105#define MPU_MAIR_ATTR_FLASH MPU_CACHE_ATTRIBUTES_FLASH
106#define MPU_MAIR_INDEX_FLASH 0
107#define MPU_MAIR_ATTR_SRAM MPU_CACHE_ATTRIBUTES_SRAM
108#define MPU_MAIR_INDEX_SRAM 1
109#define MPU_MAIR_ATTR_SRAM_NOCACHE MPU_CACHE_ATTRIBUTES_SRAM_NOCACHE
110#define MPU_MAIR_INDEX_SRAM_NOCACHE 2
121#define REGION_RAM_ATTR(base, size) \
124 P_RW_U_NA_Msk | NON_SHAREABLE_Msk, \
126 .mair_idx = MPU_MAIR_INDEX_SRAM, \
127 .r_limit = REGION_LIMIT_ADDR(base, size), \
130#if defined(CONFIG_MPU_ALLOW_FLASH_WRITE)
134#define REGION_FLASH_ATTR(base, size) \
136 .rbar = P_RW_U_RW_Msk | NON_SHAREABLE_Msk, \
138 .mair_idx = MPU_MAIR_INDEX_FLASH, \
139 .r_limit = REGION_LIMIT_ADDR(base, size), \
142#define REGION_FLASH_ATTR(base, size) \
144 .rbar = RO_Msk | NON_SHAREABLE_Msk, \
146 .mair_idx = MPU_MAIR_INDEX_FLASH, \
147 .r_limit = REGION_LIMIT_ADDR(base, size), \
181#define K_MEM_PARTITION_P_RW_U_RW ((k_mem_partition_attr_t) \
182 {(P_RW_U_RW_Msk | NOT_EXEC), MPU_MAIR_INDEX_SRAM})
183#define K_MEM_PARTITION_P_RW_U_NA ((k_mem_partition_attr_t) \
184 {(P_RW_U_NA_Msk | NOT_EXEC), MPU_MAIR_INDEX_SRAM})
185#define K_MEM_PARTITION_P_RO_U_RO ((k_mem_partition_attr_t) \
186 {(P_RO_U_RO_Msk | NOT_EXEC), MPU_MAIR_INDEX_SRAM})
187#define K_MEM_PARTITION_P_RO_U_NA ((k_mem_partition_attr_t) \
188 {(P_RO_U_NA_Msk | NOT_EXEC), MPU_MAIR_INDEX_SRAM})
191#define K_MEM_PARTITION_P_RWX_U_RWX ((k_mem_partition_attr_t) \
192 {(P_RW_U_RW_Msk), MPU_MAIR_INDEX_SRAM})
193#define K_MEM_PARTITION_P_RX_U_RX ((k_mem_partition_attr_t) \
194 {(P_RO_U_RO_Msk), MPU_MAIR_INDEX_SRAM})
204#define K_MEM_PARTITION_IS_WRITABLE(attr) \
206 int __is_writable__; \
207 switch (attr.rbar & MPU_RBAR_AP_Msk) { \
208 case P_RW_U_RW_Msk: \
209 case P_RW_U_NA_Msk: \
210 __is_writable__ = 1; \
213 __is_writable__ = 0; \
227#define K_MEM_PARTITION_IS_EXECUTABLE(attr) \
228 (!((attr.rbar) & (NOT_EXEC)))
233#define K_MEM_PARTITION_P_RW_U_RW_NOCACHE ((k_mem_partition_attr_t) \
234 {(P_RW_U_RW_Msk | NOT_EXEC | OUTER_SHAREABLE_Msk), \
235 MPU_MAIR_INDEX_SRAM_NOCACHE})
236#define K_MEM_PARTITION_P_RW_U_NA_NOCACHE ((k_mem_partition_attr_t) \
237 {(P_RW_U_NA_Msk | NOT_EXEC | OUTER_SHAREABLE_Msk), \
238 MPU_MAIR_INDEX_SRAM_NOCACHE})
239#define K_MEM_PARTITION_P_RO_U_RO_NOCACHE ((k_mem_partition_attr_t) \
240 {(P_RO_U_RO_Msk | NOT_EXEC | OUTER_SHAREABLE_Msk), \
241 MPU_MAIR_INDEX_SRAM_NOCACHE})
242#define K_MEM_PARTITION_P_RO_U_NA_NOCACHE ((k_mem_partition_attr_t) \
243 {(P_RO_U_NA_Msk | NOT_EXEC | OUTER_SHAREABLE_Msk), \
244 MPU_MAIR_INDEX_SRAM_NOCACHE})
247#define K_MEM_PARTITION_P_RWX_U_RWX_NOCACHE ((k_mem_partition_attr_t) \
248 {(P_RW_U_RW_Msk | OUTER_SHAREABLE_Msk), MPU_MAIR_INDEX_SRAM_NOCACHE})
249#define K_MEM_PARTITION_P_RX_U_RX_NOCACHE ((k_mem_partition_attr_t) \
250 {(P_RO_U_RO_Msk | OUTER_SHAREABLE_Msk), MPU_MAIR_INDEX_SRAM_NOCACHE})
254#define _ARCH_MEM_PARTITION_ALIGN_CHECK(start, size) \
255 BUILD_ASSERT((size > 0) && ((uint32_t)start % \
256 CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE == 0U) && \
257 ((size) % CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE == 0), \
258 " the start and size of the partition must align " \
259 "with the minimum MPU region size.")
uint32_t k_mem_partition_attr_t
Definition: arch.h:267
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59
Definition: arm_mpu_v7m.h:141
uint8_t rbar
Definition: arm_mpu_v8m.h:154
uint32_t r_limit
Definition: arm_mpu_v8m.h:158
uint8_t mair_idx
Definition: arm_mpu_v8m.h:156
uint16_t rbar
Definition: arm_mpu_v8m.h:165
uint16_t mair_idx
Definition: arm_mpu_v8m.h:166