Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
arm_mmu.h
Go to the documentation of this file.
1/*
2 * ARMv7 MMU support
3 *
4 * Copyright (c) 2021 Weidmueller Interface GmbH & Co. KG
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef ZEPHYR_INCLUDE_ARCH_ARM_MMU_ARM_MMU_H_
9#define ZEPHYR_INCLUDE_ARCH_ARM_MMU_ARM_MMU_H_
10
11#ifndef _ASMLANGUAGE
12
13#include <stdbool.h>
14#include <stdint.h>
15#include <stdlib.h>
16
17/*
18 * Comp.:
19 * ARM Architecture Reference Manual, ARMv7-A and ARMv7-R edition,
20 * ARM document ID DDI0406C Rev. d, March 2018
21 * Memory type definitions:
22 * Table B3-10, chap. B3.8.2, p. B3-1363f.
23 * Outer / inner cache attributes for cacheable memory:
24 * Table B3-11, chap. B3.8.2, p. B3-1364
25 */
26
27/*
28 * The following definitions are used when specifying a memory
29 * range to be mapped at boot time using the MMU_REGION_ENTRY
30 * macro.
31 */
32#define MT_STRONGLY_ORDERED BIT(0)
33#define MT_DEVICE BIT(1)
34#define MT_NORMAL BIT(2)
35#define MT_MASK 0x7
36
37#define MPERM_R BIT(3)
38#define MPERM_W BIT(4)
39#define MPERM_X BIT(5)
40#define MPERM_UNPRIVILEGED BIT(6)
41
42#define MATTR_NON_SECURE BIT(7)
43#define MATTR_NON_GLOBAL BIT(8)
44#define MATTR_SHARED BIT(9)
45#define MATTR_CACHE_OUTER_WB_WA BIT(10)
46#define MATTR_CACHE_OUTER_WT_nWA BIT(11)
47#define MATTR_CACHE_OUTER_WB_nWA BIT(12)
48#define MATTR_CACHE_INNER_WB_WA BIT(13)
49#define MATTR_CACHE_INNER_WT_nWA BIT(14)
50#define MATTR_CACHE_INNER_WB_nWA BIT(15)
51
52#define MATTR_MAY_MAP_L1_SECTION BIT(16)
53
54/*
55 * The following macros are used for adding constant entries
56 * mmu_regions array of the mmu_config struct. Use MMU_REGION_ENTRY
57 * for the specification of mappings whose PA and VA differ,
58 * the use of MMU_REGION_FLAT_ENTRY always results in an identity
59 * mapping, which are used for the mappings of the Zephyr image's
60 * code and data.
61 */
62#define MMU_REGION_ENTRY(_name, _base_pa, _base_va, _size, _attrs) \
63 {\
64 .name = _name, \
65 .base_pa = _base_pa, \
66 .base_va = _base_va, \
67 .size = _size, \
68 .attrs = _attrs, \
69 }
70
71#define MMU_REGION_FLAT_ENTRY(name, adr, sz, attrs) \
72 MMU_REGION_ENTRY(name, adr, adr, sz, attrs)
73
74/*
75 * @brief Auto generate mmu region entry for node_id
76 *
77 * Example usage:
78 *
79 * @code{.c}
80 * DT_FOREACH_STATUS_OKAY_VARGS(nxp_imx_gpio,
81 * MMU_REGION_DT_FLAT_ENTRY,
82 * (MT_DEVICE_nGnRnE | MT_P_RW_U_NA | MT_NS))
83 * @endcode
84 *
85 * @note Since devicetree_generated.h does not include
86 * node_id##_P_reg_FOREACH_PROP_ELEM* definitions,
87 * we can't automate dts node with multiple reg
88 * entries.
89 */
90#define MMU_REGION_DT_FLAT_ENTRY(node_id, attrs) \
91 MMU_REGION_FLAT_ENTRY(DT_NODE_FULL_NAME(node_id), \
92 DT_REG_ADDR(node_id), \
93 DT_REG_SIZE(node_id), \
94 attrs),
95
96/*
97 * @brief Auto generate mmu region entry for status = "okay"
98 * nodes compatible to a driver
99 *
100 * Example usage:
101 *
102 * @code{.c}
103 * MMU_REGION_DT_COMPAT_FOREACH_FLAT_ENTRY(nxp_imx_gpio,
104 * (MT_DEVICE_nGnRnE | MT_P_RW_U_NA | MT_NS))
105 * @endcode
106 *
107 * @note This is a wrapper of @ref MMU_REGION_DT_FLAT_ENTRY
108 */
109#define MMU_REGION_DT_COMPAT_FOREACH_FLAT_ENTRY(compat, attr) \
110 DT_FOREACH_STATUS_OKAY_VARGS(compat, \
111 MMU_REGION_DT_FLAT_ENTRY, attr)
112
113/* Region definition data structure */
115 /* Region Base Physical Address */
117 /* Region Base Virtual Address */
119 /* Region size */
120 size_t size;
121 /* Region Name */
122 const char *name;
123 /* Region Attributes */
125};
126
127/* MMU configuration data structure */
129 /* Number of regions */
131 /* Regions */
133};
134
135/*
136 * Reference to the MMU configuration.
137 *
138 * This struct is defined and populated for each SoC (in the SoC definition),
139 * and holds the build-time configuration information for the fixed MMU
140 * regions enabled during kernel initialization.
141 */
142extern const struct arm_mmu_config mmu_config;
143
144int z_arm_mmu_init(bool is_primary_core);
145
146#endif /* _ASMLANGUAGE */
147
148#endif /* ZEPHYR_INCLUDE_ARCH_ARM_MMU_ARM_MMU_H_ */
const struct arm_mmu_config mmu_config
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
Definition arm_mmu.h:128
const struct arm_mmu_region * mmu_regions
Definition arm_mmu.h:132
uint32_t num_regions
Definition arm_mmu.h:130
Definition arm_mmu.h:114
uintptr_t base_va
Definition arm_mmu.h:118
size_t size
Definition arm_mmu.h:120
uintptr_t base_pa
Definition arm_mmu.h:116
const char * name
Definition arm_mmu.h:122
uint32_t attrs
Definition arm_mmu.h:124