Skip to content

Commit 3f148d6

Browse files
CkovMkfabiobaltieri
authored andcommitted
arch: arm: mmu: generate mmu region entry from devicetree
Many peripherals have multiple instances, whether each of them are enabled are not known. Adding all available instances into "mmu_regions" array may not be the best choice. This commit adds a macro to generate mmu region entry in "mmu_regions" from devicetree. Used with "DT_FOREACH_STATUS_OKAY_VARGS", it generates mmu region entry for all nodes enabled and compatiable to a certain driver. Signed-off-by: Chekhov Ma <[email protected]>
1 parent dc6e7aa commit 3f148d6

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

include/zephyr/arch/arm/mmu/arm_mmu.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,45 @@
6767
#define MMU_REGION_FLAT_ENTRY(name, adr, sz, attrs) \
6868
MMU_REGION_ENTRY(name, adr, adr, sz, attrs)
6969

70+
/*
71+
* @brief Auto generate mmu region entry for node_id
72+
*
73+
* Example usage:
74+
*
75+
* @code{.c}
76+
* DT_FOREACH_STATUS_OKAY_VARGS(nxp_imx_gpio,
77+
* MMU_REGION_DT_FLAT_ENTRY,
78+
* (MT_DEVICE_nGnRnE | MT_P_RW_U_NA | MT_NS))
79+
* @endcode
80+
*
81+
* @note Since devicetree_generated.h does not include
82+
* node_id##_P_reg_FOREACH_PROP_ELEM* definitions,
83+
* we can't automate dts node with multiple reg
84+
* entries.
85+
*/
86+
#define MMU_REGION_DT_FLAT_ENTRY(node_id, attrs) \
87+
MMU_REGION_FLAT_ENTRY(DT_NODE_FULL_NAME(node_id), \
88+
DT_REG_ADDR(node_id), \
89+
DT_REG_SIZE(node_id), \
90+
attrs),
91+
92+
/*
93+
* @brief Auto generate mmu region entry for status = "okay"
94+
* nodes compatible to a driver
95+
*
96+
* Example usage:
97+
*
98+
* @code{.c}
99+
* MMU_REGION_DT_COMPAT_FOREACH_FLAT_ENTRY(nxp_imx_gpio,
100+
* (MT_DEVICE_nGnRnE | MT_P_RW_U_NA | MT_NS))
101+
* @endcode
102+
*
103+
* @note This is a wrapper of @ref MMU_REGION_DT_FLAT_ENTRY
104+
*/
105+
#define MMU_REGION_DT_COMPAT_FOREACH_FLAT_ENTRY(compat, attr) \
106+
DT_FOREACH_STATUS_OKAY_VARGS(compat, \
107+
MMU_REGION_DT_FLAT_ENTRY, attr)
108+
70109
/* Region definition data structure */
71110
struct arm_mmu_region {
72111
/* Region Base Physical Address */

include/zephyr/arch/arm64/arm_mmu.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,45 @@ struct arm_mmu_ptables {
207207
#define MMU_REGION_FLAT_ENTRY(name, adr, sz, attrs) \
208208
MMU_REGION_ENTRY(name, adr, adr, sz, attrs)
209209

210+
/*
211+
* @brief Auto generate mmu region entry for node_id
212+
*
213+
* Example usage:
214+
*
215+
* @code{.c}
216+
* DT_FOREACH_STATUS_OKAY_VARGS(nxp_imx_gpio,
217+
* MMU_REGION_DT_FLAT_ENTRY,
218+
* (MT_DEVICE_nGnRnE | MT_P_RW_U_NA | MT_NS))
219+
* @endcode
220+
*
221+
* @note Since devicetree_generated.h does not include
222+
* node_id##_P_reg_FOREACH_PROP_ELEM* definitions,
223+
* we can't automate dts node with multiple reg
224+
* entries.
225+
*/
226+
#define MMU_REGION_DT_FLAT_ENTRY(node_id, attrs) \
227+
MMU_REGION_FLAT_ENTRY(DT_NODE_FULL_NAME(node_id), \
228+
DT_REG_ADDR(node_id), \
229+
DT_REG_SIZE(node_id), \
230+
attrs),
231+
232+
/*
233+
* @brief Auto generate mmu region entry for status = "okay"
234+
* nodes compatible to a driver
235+
*
236+
* Example usage:
237+
*
238+
* @code{.c}
239+
* MMU_REGION_DT_COMPAT_FOREACH_FLAT_ENTRY(nxp_imx_gpio,
240+
* (MT_DEVICE_nGnRnE | MT_P_RW_U_NA | MT_NS))
241+
* @endcode
242+
*
243+
* @note This is a wrapper of @ref MMU_REGION_DT_FLAT_ENTRY
244+
*/
245+
#define MMU_REGION_DT_COMPAT_FOREACH_FLAT_ENTRY(compat, attr) \
246+
DT_FOREACH_STATUS_OKAY_VARGS(compat, \
247+
MMU_REGION_DT_FLAT_ENTRY, attr)
248+
210249
/* Kernel macros for memory attribution
211250
* (access permissions and cache-ability).
212251
*

0 commit comments

Comments
 (0)