DHT11
TARGET_NUCLEO_F072RB/core_ca_mmu.h@0:c52df770855b, 2015-08-13 (annotated)
- Committer:
- jhon309
- Date:
- Thu Aug 13 00:21:57 2015 +0000
- Revision:
- 0:c52df770855b
DHT11
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jhon309 | 0:c52df770855b | 1 | ;/**************************************************************************//** |
jhon309 | 0:c52df770855b | 2 | ; * @file core_ca_mmu.h |
jhon309 | 0:c52df770855b | 3 | ; * @brief MMU Startup File for |
jhon309 | 0:c52df770855b | 4 | ; * VE_A9_MP Device Series |
jhon309 | 0:c52df770855b | 5 | ; * @version V1.01 |
jhon309 | 0:c52df770855b | 6 | ; * @date 25 March 2013 |
jhon309 | 0:c52df770855b | 7 | ; * |
jhon309 | 0:c52df770855b | 8 | ; * @note |
jhon309 | 0:c52df770855b | 9 | ; * |
jhon309 | 0:c52df770855b | 10 | ; ******************************************************************************/ |
jhon309 | 0:c52df770855b | 11 | ;/* Copyright (c) 2012 ARM LIMITED |
jhon309 | 0:c52df770855b | 12 | ; |
jhon309 | 0:c52df770855b | 13 | ; All rights reserved. |
jhon309 | 0:c52df770855b | 14 | ; Redistribution and use in source and binary forms, with or without |
jhon309 | 0:c52df770855b | 15 | ; modification, are permitted provided that the following conditions are met: |
jhon309 | 0:c52df770855b | 16 | ; - Redistributions of source code must retain the above copyright |
jhon309 | 0:c52df770855b | 17 | ; notice, this list of conditions and the following disclaimer. |
jhon309 | 0:c52df770855b | 18 | ; - Redistributions in binary form must reproduce the above copyright |
jhon309 | 0:c52df770855b | 19 | ; notice, this list of conditions and the following disclaimer in the |
jhon309 | 0:c52df770855b | 20 | ; documentation and/or other materials provided with the distribution. |
jhon309 | 0:c52df770855b | 21 | ; - Neither the name of ARM nor the names of its contributors may be used |
jhon309 | 0:c52df770855b | 22 | ; to endorse or promote products derived from this software without |
jhon309 | 0:c52df770855b | 23 | ; specific prior written permission. |
jhon309 | 0:c52df770855b | 24 | ; * |
jhon309 | 0:c52df770855b | 25 | ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
jhon309 | 0:c52df770855b | 26 | ; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
jhon309 | 0:c52df770855b | 27 | ; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
jhon309 | 0:c52df770855b | 28 | ; ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE |
jhon309 | 0:c52df770855b | 29 | ; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
jhon309 | 0:c52df770855b | 30 | ; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
jhon309 | 0:c52df770855b | 31 | ; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
jhon309 | 0:c52df770855b | 32 | ; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
jhon309 | 0:c52df770855b | 33 | ; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
jhon309 | 0:c52df770855b | 34 | ; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
jhon309 | 0:c52df770855b | 35 | ; POSSIBILITY OF SUCH DAMAGE. |
jhon309 | 0:c52df770855b | 36 | ; ---------------------------------------------------------------------------*/ |
jhon309 | 0:c52df770855b | 37 | |
jhon309 | 0:c52df770855b | 38 | #ifdef __cplusplus |
jhon309 | 0:c52df770855b | 39 | extern "C" { |
jhon309 | 0:c52df770855b | 40 | #endif |
jhon309 | 0:c52df770855b | 41 | |
jhon309 | 0:c52df770855b | 42 | #ifndef _MMU_FUNC_H |
jhon309 | 0:c52df770855b | 43 | #define _MMU_FUNC_H |
jhon309 | 0:c52df770855b | 44 | |
jhon309 | 0:c52df770855b | 45 | #define SECTION_DESCRIPTOR (0x2) |
jhon309 | 0:c52df770855b | 46 | #define SECTION_MASK (0xFFFFFFFC) |
jhon309 | 0:c52df770855b | 47 | |
jhon309 | 0:c52df770855b | 48 | #define SECTION_TEXCB_MASK (0xFFFF8FF3) |
jhon309 | 0:c52df770855b | 49 | #define SECTION_B_SHIFT (2) |
jhon309 | 0:c52df770855b | 50 | #define SECTION_C_SHIFT (3) |
jhon309 | 0:c52df770855b | 51 | #define SECTION_TEX0_SHIFT (12) |
jhon309 | 0:c52df770855b | 52 | #define SECTION_TEX1_SHIFT (13) |
jhon309 | 0:c52df770855b | 53 | #define SECTION_TEX2_SHIFT (14) |
jhon309 | 0:c52df770855b | 54 | |
jhon309 | 0:c52df770855b | 55 | #define SECTION_XN_MASK (0xFFFFFFEF) |
jhon309 | 0:c52df770855b | 56 | #define SECTION_XN_SHIFT (4) |
jhon309 | 0:c52df770855b | 57 | |
jhon309 | 0:c52df770855b | 58 | #define SECTION_DOMAIN_MASK (0xFFFFFE1F) |
jhon309 | 0:c52df770855b | 59 | #define SECTION_DOMAIN_SHIFT (5) |
jhon309 | 0:c52df770855b | 60 | |
jhon309 | 0:c52df770855b | 61 | #define SECTION_P_MASK (0xFFFFFDFF) |
jhon309 | 0:c52df770855b | 62 | #define SECTION_P_SHIFT (9) |
jhon309 | 0:c52df770855b | 63 | |
jhon309 | 0:c52df770855b | 64 | #define SECTION_AP_MASK (0xFFFF73FF) |
jhon309 | 0:c52df770855b | 65 | #define SECTION_AP_SHIFT (10) |
jhon309 | 0:c52df770855b | 66 | #define SECTION_AP2_SHIFT (15) |
jhon309 | 0:c52df770855b | 67 | |
jhon309 | 0:c52df770855b | 68 | #define SECTION_S_MASK (0xFFFEFFFF) |
jhon309 | 0:c52df770855b | 69 | #define SECTION_S_SHIFT (16) |
jhon309 | 0:c52df770855b | 70 | |
jhon309 | 0:c52df770855b | 71 | #define SECTION_NG_MASK (0xFFFDFFFF) |
jhon309 | 0:c52df770855b | 72 | #define SECTION_NG_SHIFT (17) |
jhon309 | 0:c52df770855b | 73 | |
jhon309 | 0:c52df770855b | 74 | #define SECTION_NS_MASK (0xFFF7FFFF) |
jhon309 | 0:c52df770855b | 75 | #define SECTION_NS_SHIFT (19) |
jhon309 | 0:c52df770855b | 76 | |
jhon309 | 0:c52df770855b | 77 | |
jhon309 | 0:c52df770855b | 78 | #define PAGE_L1_DESCRIPTOR (0x1) |
jhon309 | 0:c52df770855b | 79 | #define PAGE_L1_MASK (0xFFFFFFFC) |
jhon309 | 0:c52df770855b | 80 | |
jhon309 | 0:c52df770855b | 81 | #define PAGE_L2_4K_DESC (0x2) |
jhon309 | 0:c52df770855b | 82 | #define PAGE_L2_4K_MASK (0xFFFFFFFD) |
jhon309 | 0:c52df770855b | 83 | |
jhon309 | 0:c52df770855b | 84 | #define PAGE_L2_64K_DESC (0x1) |
jhon309 | 0:c52df770855b | 85 | #define PAGE_L2_64K_MASK (0xFFFFFFFC) |
jhon309 | 0:c52df770855b | 86 | |
jhon309 | 0:c52df770855b | 87 | #define PAGE_4K_TEXCB_MASK (0xFFFFFE33) |
jhon309 | 0:c52df770855b | 88 | #define PAGE_4K_B_SHIFT (2) |
jhon309 | 0:c52df770855b | 89 | #define PAGE_4K_C_SHIFT (3) |
jhon309 | 0:c52df770855b | 90 | #define PAGE_4K_TEX0_SHIFT (6) |
jhon309 | 0:c52df770855b | 91 | #define PAGE_4K_TEX1_SHIFT (7) |
jhon309 | 0:c52df770855b | 92 | #define PAGE_4K_TEX2_SHIFT (8) |
jhon309 | 0:c52df770855b | 93 | |
jhon309 | 0:c52df770855b | 94 | #define PAGE_64K_TEXCB_MASK (0xFFFF8FF3) |
jhon309 | 0:c52df770855b | 95 | #define PAGE_64K_B_SHIFT (2) |
jhon309 | 0:c52df770855b | 96 | #define PAGE_64K_C_SHIFT (3) |
jhon309 | 0:c52df770855b | 97 | #define PAGE_64K_TEX0_SHIFT (12) |
jhon309 | 0:c52df770855b | 98 | #define PAGE_64K_TEX1_SHIFT (13) |
jhon309 | 0:c52df770855b | 99 | #define PAGE_64K_TEX2_SHIFT (14) |
jhon309 | 0:c52df770855b | 100 | |
jhon309 | 0:c52df770855b | 101 | #define PAGE_TEXCB_MASK (0xFFFF8FF3) |
jhon309 | 0:c52df770855b | 102 | #define PAGE_B_SHIFT (2) |
jhon309 | 0:c52df770855b | 103 | #define PAGE_C_SHIFT (3) |
jhon309 | 0:c52df770855b | 104 | #define PAGE_TEX_SHIFT (12) |
jhon309 | 0:c52df770855b | 105 | |
jhon309 | 0:c52df770855b | 106 | #define PAGE_XN_4K_MASK (0xFFFFFFFE) |
jhon309 | 0:c52df770855b | 107 | #define PAGE_XN_4K_SHIFT (0) |
jhon309 | 0:c52df770855b | 108 | #define PAGE_XN_64K_MASK (0xFFFF7FFF) |
jhon309 | 0:c52df770855b | 109 | #define PAGE_XN_64K_SHIFT (15) |
jhon309 | 0:c52df770855b | 110 | |
jhon309 | 0:c52df770855b | 111 | |
jhon309 | 0:c52df770855b | 112 | #define PAGE_DOMAIN_MASK (0xFFFFFE1F) |
jhon309 | 0:c52df770855b | 113 | #define PAGE_DOMAIN_SHIFT (5) |
jhon309 | 0:c52df770855b | 114 | |
jhon309 | 0:c52df770855b | 115 | #define PAGE_P_MASK (0xFFFFFDFF) |
jhon309 | 0:c52df770855b | 116 | #define PAGE_P_SHIFT (9) |
jhon309 | 0:c52df770855b | 117 | |
jhon309 | 0:c52df770855b | 118 | #define PAGE_AP_MASK (0xFFFFFDCF) |
jhon309 | 0:c52df770855b | 119 | #define PAGE_AP_SHIFT (4) |
jhon309 | 0:c52df770855b | 120 | #define PAGE_AP2_SHIFT (9) |
jhon309 | 0:c52df770855b | 121 | |
jhon309 | 0:c52df770855b | 122 | #define PAGE_S_MASK (0xFFFFFBFF) |
jhon309 | 0:c52df770855b | 123 | #define PAGE_S_SHIFT (10) |
jhon309 | 0:c52df770855b | 124 | |
jhon309 | 0:c52df770855b | 125 | #define PAGE_NG_MASK (0xFFFFF7FF) |
jhon309 | 0:c52df770855b | 126 | #define PAGE_NG_SHIFT (11) |
jhon309 | 0:c52df770855b | 127 | |
jhon309 | 0:c52df770855b | 128 | #define PAGE_NS_MASK (0xFFFFFFF7) |
jhon309 | 0:c52df770855b | 129 | #define PAGE_NS_SHIFT (3) |
jhon309 | 0:c52df770855b | 130 | |
jhon309 | 0:c52df770855b | 131 | #define OFFSET_1M (0x00100000) |
jhon309 | 0:c52df770855b | 132 | #define OFFSET_64K (0x00010000) |
jhon309 | 0:c52df770855b | 133 | #define OFFSET_4K (0x00001000) |
jhon309 | 0:c52df770855b | 134 | |
jhon309 | 0:c52df770855b | 135 | #define DESCRIPTOR_FAULT (0x00000000) |
jhon309 | 0:c52df770855b | 136 | |
jhon309 | 0:c52df770855b | 137 | /* ########################### MMU Function Access ########################### */ |
jhon309 | 0:c52df770855b | 138 | /** \ingroup MMU_FunctionInterface |
jhon309 | 0:c52df770855b | 139 | \defgroup MMU_Functions MMU Functions Interface |
jhon309 | 0:c52df770855b | 140 | @{ |
jhon309 | 0:c52df770855b | 141 | */ |
jhon309 | 0:c52df770855b | 142 | |
jhon309 | 0:c52df770855b | 143 | /* Attributes enumerations */ |
jhon309 | 0:c52df770855b | 144 | |
jhon309 | 0:c52df770855b | 145 | /* Region size attributes */ |
jhon309 | 0:c52df770855b | 146 | typedef enum |
jhon309 | 0:c52df770855b | 147 | { |
jhon309 | 0:c52df770855b | 148 | SECTION, |
jhon309 | 0:c52df770855b | 149 | PAGE_4k, |
jhon309 | 0:c52df770855b | 150 | PAGE_64k, |
jhon309 | 0:c52df770855b | 151 | } mmu_region_size_Type; |
jhon309 | 0:c52df770855b | 152 | |
jhon309 | 0:c52df770855b | 153 | /* Region type attributes */ |
jhon309 | 0:c52df770855b | 154 | typedef enum |
jhon309 | 0:c52df770855b | 155 | { |
jhon309 | 0:c52df770855b | 156 | NORMAL, |
jhon309 | 0:c52df770855b | 157 | DEVICE, |
jhon309 | 0:c52df770855b | 158 | SHARED_DEVICE, |
jhon309 | 0:c52df770855b | 159 | NON_SHARED_DEVICE, |
jhon309 | 0:c52df770855b | 160 | STRONGLY_ORDERED |
jhon309 | 0:c52df770855b | 161 | } mmu_memory_Type; |
jhon309 | 0:c52df770855b | 162 | |
jhon309 | 0:c52df770855b | 163 | /* Region cacheability attributes */ |
jhon309 | 0:c52df770855b | 164 | typedef enum |
jhon309 | 0:c52df770855b | 165 | { |
jhon309 | 0:c52df770855b | 166 | NON_CACHEABLE, |
jhon309 | 0:c52df770855b | 167 | WB_WA, |
jhon309 | 0:c52df770855b | 168 | WT, |
jhon309 | 0:c52df770855b | 169 | WB_NO_WA, |
jhon309 | 0:c52df770855b | 170 | } mmu_cacheability_Type; |
jhon309 | 0:c52df770855b | 171 | |
jhon309 | 0:c52df770855b | 172 | /* Region parity check attributes */ |
jhon309 | 0:c52df770855b | 173 | typedef enum |
jhon309 | 0:c52df770855b | 174 | { |
jhon309 | 0:c52df770855b | 175 | ECC_DISABLED, |
jhon309 | 0:c52df770855b | 176 | ECC_ENABLED, |
jhon309 | 0:c52df770855b | 177 | } mmu_ecc_check_Type; |
jhon309 | 0:c52df770855b | 178 | |
jhon309 | 0:c52df770855b | 179 | /* Region execution attributes */ |
jhon309 | 0:c52df770855b | 180 | typedef enum |
jhon309 | 0:c52df770855b | 181 | { |
jhon309 | 0:c52df770855b | 182 | EXECUTE, |
jhon309 | 0:c52df770855b | 183 | NON_EXECUTE, |
jhon309 | 0:c52df770855b | 184 | } mmu_execute_Type; |
jhon309 | 0:c52df770855b | 185 | |
jhon309 | 0:c52df770855b | 186 | /* Region global attributes */ |
jhon309 | 0:c52df770855b | 187 | typedef enum |
jhon309 | 0:c52df770855b | 188 | { |
jhon309 | 0:c52df770855b | 189 | GLOBAL, |
jhon309 | 0:c52df770855b | 190 | NON_GLOBAL, |
jhon309 | 0:c52df770855b | 191 | } mmu_global_Type; |
jhon309 | 0:c52df770855b | 192 | |
jhon309 | 0:c52df770855b | 193 | /* Region shareability attributes */ |
jhon309 | 0:c52df770855b | 194 | typedef enum |
jhon309 | 0:c52df770855b | 195 | { |
jhon309 | 0:c52df770855b | 196 | NON_SHARED, |
jhon309 | 0:c52df770855b | 197 | SHARED, |
jhon309 | 0:c52df770855b | 198 | } mmu_shared_Type; |
jhon309 | 0:c52df770855b | 199 | |
jhon309 | 0:c52df770855b | 200 | /* Region security attributes */ |
jhon309 | 0:c52df770855b | 201 | typedef enum |
jhon309 | 0:c52df770855b | 202 | { |
jhon309 | 0:c52df770855b | 203 | SECURE, |
jhon309 | 0:c52df770855b | 204 | NON_SECURE, |
jhon309 | 0:c52df770855b | 205 | } mmu_secure_Type; |
jhon309 | 0:c52df770855b | 206 | |
jhon309 | 0:c52df770855b | 207 | /* Region access attributes */ |
jhon309 | 0:c52df770855b | 208 | typedef enum |
jhon309 | 0:c52df770855b | 209 | { |
jhon309 | 0:c52df770855b | 210 | NO_ACCESS, |
jhon309 | 0:c52df770855b | 211 | RW, |
jhon309 | 0:c52df770855b | 212 | READ, |
jhon309 | 0:c52df770855b | 213 | } mmu_access_Type; |
jhon309 | 0:c52df770855b | 214 | |
jhon309 | 0:c52df770855b | 215 | /* Memory Region definition */ |
jhon309 | 0:c52df770855b | 216 | typedef struct RegionStruct { |
jhon309 | 0:c52df770855b | 217 | mmu_region_size_Type rg_t; |
jhon309 | 0:c52df770855b | 218 | mmu_memory_Type mem_t; |
jhon309 | 0:c52df770855b | 219 | uint8_t domain; |
jhon309 | 0:c52df770855b | 220 | mmu_cacheability_Type inner_norm_t; |
jhon309 | 0:c52df770855b | 221 | mmu_cacheability_Type outer_norm_t; |
jhon309 | 0:c52df770855b | 222 | mmu_ecc_check_Type e_t; |
jhon309 | 0:c52df770855b | 223 | mmu_execute_Type xn_t; |
jhon309 | 0:c52df770855b | 224 | mmu_global_Type g_t; |
jhon309 | 0:c52df770855b | 225 | mmu_secure_Type sec_t; |
jhon309 | 0:c52df770855b | 226 | mmu_access_Type priv_t; |
jhon309 | 0:c52df770855b | 227 | mmu_access_Type user_t; |
jhon309 | 0:c52df770855b | 228 | mmu_shared_Type sh_t; |
jhon309 | 0:c52df770855b | 229 | |
jhon309 | 0:c52df770855b | 230 | } mmu_region_attributes_Type; |
jhon309 | 0:c52df770855b | 231 | |
jhon309 | 0:c52df770855b | 232 | /** \brief Set section execution-never attribute |
jhon309 | 0:c52df770855b | 233 | |
jhon309 | 0:c52df770855b | 234 | The function sets section execution-never attribute |
jhon309 | 0:c52df770855b | 235 | |
jhon309 | 0:c52df770855b | 236 | \param [out] descriptor_l1 L1 descriptor. |
jhon309 | 0:c52df770855b | 237 | \param [in] xn Section execution-never attribute : EXECUTE , NON_EXECUTE. |
jhon309 | 0:c52df770855b | 238 | |
jhon309 | 0:c52df770855b | 239 | \return 0 |
jhon309 | 0:c52df770855b | 240 | */ |
jhon309 | 0:c52df770855b | 241 | __STATIC_INLINE int __xn_section(uint32_t *descriptor_l1, mmu_execute_Type xn) |
jhon309 | 0:c52df770855b | 242 | { |
jhon309 | 0:c52df770855b | 243 | *descriptor_l1 &= SECTION_XN_MASK; |
jhon309 | 0:c52df770855b | 244 | *descriptor_l1 |= ((xn & 0x1) << SECTION_XN_SHIFT); |
jhon309 | 0:c52df770855b | 245 | return 0; |
jhon309 | 0:c52df770855b | 246 | } |
jhon309 | 0:c52df770855b | 247 | |
jhon309 | 0:c52df770855b | 248 | /** \brief Set section domain |
jhon309 | 0:c52df770855b | 249 | |
jhon309 | 0:c52df770855b | 250 | The function sets section domain |
jhon309 | 0:c52df770855b | 251 | |
jhon309 | 0:c52df770855b | 252 | \param [out] descriptor_l1 L1 descriptor. |
jhon309 | 0:c52df770855b | 253 | \param [in] domain Section domain |
jhon309 | 0:c52df770855b | 254 | |
jhon309 | 0:c52df770855b | 255 | \return 0 |
jhon309 | 0:c52df770855b | 256 | */ |
jhon309 | 0:c52df770855b | 257 | __STATIC_INLINE int __domain_section(uint32_t *descriptor_l1, uint8_t domain) |
jhon309 | 0:c52df770855b | 258 | { |
jhon309 | 0:c52df770855b | 259 | *descriptor_l1 &= SECTION_DOMAIN_MASK; |
jhon309 | 0:c52df770855b | 260 | *descriptor_l1 |= ((domain & 0xF) << SECTION_DOMAIN_SHIFT); |
jhon309 | 0:c52df770855b | 261 | return 0; |
jhon309 | 0:c52df770855b | 262 | } |
jhon309 | 0:c52df770855b | 263 | |
jhon309 | 0:c52df770855b | 264 | /** \brief Set section parity check |
jhon309 | 0:c52df770855b | 265 | |
jhon309 | 0:c52df770855b | 266 | The function sets section parity check |
jhon309 | 0:c52df770855b | 267 | |
jhon309 | 0:c52df770855b | 268 | \param [out] descriptor_l1 L1 descriptor. |
jhon309 | 0:c52df770855b | 269 | \param [in] p_bit Parity check: ECC_DISABLED, ECC_ENABLED |
jhon309 | 0:c52df770855b | 270 | |
jhon309 | 0:c52df770855b | 271 | \return 0 |
jhon309 | 0:c52df770855b | 272 | */ |
jhon309 | 0:c52df770855b | 273 | __STATIC_INLINE int __p_section(uint32_t *descriptor_l1, mmu_ecc_check_Type p_bit) |
jhon309 | 0:c52df770855b | 274 | { |
jhon309 | 0:c52df770855b | 275 | *descriptor_l1 &= SECTION_P_MASK; |
jhon309 | 0:c52df770855b | 276 | *descriptor_l1 |= ((p_bit & 0x1) << SECTION_P_SHIFT); |
jhon309 | 0:c52df770855b | 277 | return 0; |
jhon309 | 0:c52df770855b | 278 | } |
jhon309 | 0:c52df770855b | 279 | |
jhon309 | 0:c52df770855b | 280 | /** \brief Set section access privileges |
jhon309 | 0:c52df770855b | 281 | |
jhon309 | 0:c52df770855b | 282 | The function sets section access privileges |
jhon309 | 0:c52df770855b | 283 | |
jhon309 | 0:c52df770855b | 284 | \param [out] descriptor_l1 L1 descriptor. |
jhon309 | 0:c52df770855b | 285 | \param [in] user User Level Access: NO_ACCESS, RW, READ |
jhon309 | 0:c52df770855b | 286 | \param [in] priv Privilege Level Access: NO_ACCESS, RW, READ |
jhon309 | 0:c52df770855b | 287 | \param [in] afe Access flag enable |
jhon309 | 0:c52df770855b | 288 | |
jhon309 | 0:c52df770855b | 289 | \return 0 |
jhon309 | 0:c52df770855b | 290 | */ |
jhon309 | 0:c52df770855b | 291 | __STATIC_INLINE int __ap_section(uint32_t *descriptor_l1, mmu_access_Type user, mmu_access_Type priv, uint32_t afe) |
jhon309 | 0:c52df770855b | 292 | { |
jhon309 | 0:c52df770855b | 293 | uint32_t ap = 0; |
jhon309 | 0:c52df770855b | 294 | |
jhon309 | 0:c52df770855b | 295 | if (afe == 0) { //full access |
jhon309 | 0:c52df770855b | 296 | if ((priv == NO_ACCESS) && (user == NO_ACCESS)) { ap = 0x0; } |
jhon309 | 0:c52df770855b | 297 | else if ((priv == RW) && (user == NO_ACCESS)) { ap = 0x1; } |
jhon309 | 0:c52df770855b | 298 | else if ((priv == RW) && (user == READ)) { ap = 0x2; } |
jhon309 | 0:c52df770855b | 299 | else if ((priv == RW) && (user == RW)) { ap = 0x3; } |
jhon309 | 0:c52df770855b | 300 | else if ((priv == READ) && (user == NO_ACCESS)) { ap = 0x5; } |
jhon309 | 0:c52df770855b | 301 | else if ((priv == READ) && (user == READ)) { ap = 0x6; } |
jhon309 | 0:c52df770855b | 302 | } |
jhon309 | 0:c52df770855b | 303 | |
jhon309 | 0:c52df770855b | 304 | else { //Simplified access |
jhon309 | 0:c52df770855b | 305 | if ((priv == RW) && (user == NO_ACCESS)) { ap = 0x1; } |
jhon309 | 0:c52df770855b | 306 | else if ((priv == RW) && (user == RW)) { ap = 0x3; } |
jhon309 | 0:c52df770855b | 307 | else if ((priv == READ) && (user == NO_ACCESS)) { ap = 0x5; } |
jhon309 | 0:c52df770855b | 308 | else if ((priv == READ) && (user == READ)) { ap = 0x7; } |
jhon309 | 0:c52df770855b | 309 | } |
jhon309 | 0:c52df770855b | 310 | |
jhon309 | 0:c52df770855b | 311 | *descriptor_l1 &= SECTION_AP_MASK; |
jhon309 | 0:c52df770855b | 312 | *descriptor_l1 |= (ap & 0x3) << SECTION_AP_SHIFT; |
jhon309 | 0:c52df770855b | 313 | *descriptor_l1 |= ((ap & 0x4)>>2) << SECTION_AP2_SHIFT; |
jhon309 | 0:c52df770855b | 314 | |
jhon309 | 0:c52df770855b | 315 | return 0; |
jhon309 | 0:c52df770855b | 316 | } |
jhon309 | 0:c52df770855b | 317 | |
jhon309 | 0:c52df770855b | 318 | /** \brief Set section shareability |
jhon309 | 0:c52df770855b | 319 | |
jhon309 | 0:c52df770855b | 320 | The function sets section shareability |
jhon309 | 0:c52df770855b | 321 | |
jhon309 | 0:c52df770855b | 322 | \param [out] descriptor_l1 L1 descriptor. |
jhon309 | 0:c52df770855b | 323 | \param [in] s_bit Section shareability: NON_SHARED, SHARED |
jhon309 | 0:c52df770855b | 324 | |
jhon309 | 0:c52df770855b | 325 | \return 0 |
jhon309 | 0:c52df770855b | 326 | */ |
jhon309 | 0:c52df770855b | 327 | __STATIC_INLINE int __shared_section(uint32_t *descriptor_l1, mmu_shared_Type s_bit) |
jhon309 | 0:c52df770855b | 328 | { |
jhon309 | 0:c52df770855b | 329 | *descriptor_l1 &= SECTION_S_MASK; |
jhon309 | 0:c52df770855b | 330 | *descriptor_l1 |= ((s_bit & 0x1) << SECTION_S_SHIFT); |
jhon309 | 0:c52df770855b | 331 | return 0; |
jhon309 | 0:c52df770855b | 332 | } |
jhon309 | 0:c52df770855b | 333 | |
jhon309 | 0:c52df770855b | 334 | /** \brief Set section Global attribute |
jhon309 | 0:c52df770855b | 335 | |
jhon309 | 0:c52df770855b | 336 | The function sets section Global attribute |
jhon309 | 0:c52df770855b | 337 | |
jhon309 | 0:c52df770855b | 338 | \param [out] descriptor_l1 L1 descriptor. |
jhon309 | 0:c52df770855b | 339 | \param [in] g_bit Section attribute: GLOBAL, NON_GLOBAL |
jhon309 | 0:c52df770855b | 340 | |
jhon309 | 0:c52df770855b | 341 | \return 0 |
jhon309 | 0:c52df770855b | 342 | */ |
jhon309 | 0:c52df770855b | 343 | __STATIC_INLINE int __global_section(uint32_t *descriptor_l1, mmu_global_Type g_bit) |
jhon309 | 0:c52df770855b | 344 | { |
jhon309 | 0:c52df770855b | 345 | *descriptor_l1 &= SECTION_NG_MASK; |
jhon309 | 0:c52df770855b | 346 | *descriptor_l1 |= ((g_bit & 0x1) << SECTION_NG_SHIFT); |
jhon309 | 0:c52df770855b | 347 | return 0; |
jhon309 | 0:c52df770855b | 348 | } |
jhon309 | 0:c52df770855b | 349 | |
jhon309 | 0:c52df770855b | 350 | /** \brief Set section Security attribute |
jhon309 | 0:c52df770855b | 351 | |
jhon309 | 0:c52df770855b | 352 | The function sets section Global attribute |
jhon309 | 0:c52df770855b | 353 | |
jhon309 | 0:c52df770855b | 354 | \param [out] descriptor_l1 L1 descriptor. |
jhon309 | 0:c52df770855b | 355 | \param [in] s_bit Section Security attribute: SECURE, NON_SECURE |
jhon309 | 0:c52df770855b | 356 | |
jhon309 | 0:c52df770855b | 357 | \return 0 |
jhon309 | 0:c52df770855b | 358 | */ |
jhon309 | 0:c52df770855b | 359 | __STATIC_INLINE int __secure_section(uint32_t *descriptor_l1, mmu_secure_Type s_bit) |
jhon309 | 0:c52df770855b | 360 | { |
jhon309 | 0:c52df770855b | 361 | *descriptor_l1 &= SECTION_NS_MASK; |
jhon309 | 0:c52df770855b | 362 | *descriptor_l1 |= ((s_bit & 0x1) << SECTION_NS_SHIFT); |
jhon309 | 0:c52df770855b | 363 | return 0; |
jhon309 | 0:c52df770855b | 364 | } |
jhon309 | 0:c52df770855b | 365 | |
jhon309 | 0:c52df770855b | 366 | /* Page 4k or 64k */ |
jhon309 | 0:c52df770855b | 367 | /** \brief Set 4k/64k page execution-never attribute |
jhon309 | 0:c52df770855b | 368 | |
jhon309 | 0:c52df770855b | 369 | The function sets 4k/64k page execution-never attribute |
jhon309 | 0:c52df770855b | 370 | |
jhon309 | 0:c52df770855b | 371 | \param [out] descriptor_l2 L2 descriptor. |
jhon309 | 0:c52df770855b | 372 | \param [in] xn Page execution-never attribute : EXECUTE , NON_EXECUTE. |
jhon309 | 0:c52df770855b | 373 | \param [in] page Page size: PAGE_4k, PAGE_64k, |
jhon309 | 0:c52df770855b | 374 | |
jhon309 | 0:c52df770855b | 375 | \return 0 |
jhon309 | 0:c52df770855b | 376 | */ |
jhon309 | 0:c52df770855b | 377 | __STATIC_INLINE int __xn_page(uint32_t *descriptor_l2, mmu_execute_Type xn, mmu_region_size_Type page) |
jhon309 | 0:c52df770855b | 378 | { |
jhon309 | 0:c52df770855b | 379 | if (page == PAGE_4k) |
jhon309 | 0:c52df770855b | 380 | { |
jhon309 | 0:c52df770855b | 381 | *descriptor_l2 &= PAGE_XN_4K_MASK; |
jhon309 | 0:c52df770855b | 382 | *descriptor_l2 |= ((xn & 0x1) << PAGE_XN_4K_SHIFT); |
jhon309 | 0:c52df770855b | 383 | } |
jhon309 | 0:c52df770855b | 384 | else |
jhon309 | 0:c52df770855b | 385 | { |
jhon309 | 0:c52df770855b | 386 | *descriptor_l2 &= PAGE_XN_64K_MASK; |
jhon309 | 0:c52df770855b | 387 | *descriptor_l2 |= ((xn & 0x1) << PAGE_XN_64K_SHIFT); |
jhon309 | 0:c52df770855b | 388 | } |
jhon309 | 0:c52df770855b | 389 | return 0; |
jhon309 | 0:c52df770855b | 390 | } |
jhon309 | 0:c52df770855b | 391 | |
jhon309 | 0:c52df770855b | 392 | /** \brief Set 4k/64k page domain |
jhon309 | 0:c52df770855b | 393 | |
jhon309 | 0:c52df770855b | 394 | The function sets 4k/64k page domain |
jhon309 | 0:c52df770855b | 395 | |
jhon309 | 0:c52df770855b | 396 | \param [out] descriptor_l1 L1 descriptor. |
jhon309 | 0:c52df770855b | 397 | \param [in] domain Page domain |
jhon309 | 0:c52df770855b | 398 | |
jhon309 | 0:c52df770855b | 399 | \return 0 |
jhon309 | 0:c52df770855b | 400 | */ |
jhon309 | 0:c52df770855b | 401 | __STATIC_INLINE int __domain_page(uint32_t *descriptor_l1, uint8_t domain) |
jhon309 | 0:c52df770855b | 402 | { |
jhon309 | 0:c52df770855b | 403 | *descriptor_l1 &= PAGE_DOMAIN_MASK; |
jhon309 | 0:c52df770855b | 404 | *descriptor_l1 |= ((domain & 0xf) << PAGE_DOMAIN_SHIFT); |
jhon309 | 0:c52df770855b | 405 | return 0; |
jhon309 | 0:c52df770855b | 406 | } |
jhon309 | 0:c52df770855b | 407 | |
jhon309 | 0:c52df770855b | 408 | /** \brief Set 4k/64k page parity check |
jhon309 | 0:c52df770855b | 409 | |
jhon309 | 0:c52df770855b | 410 | The function sets 4k/64k page parity check |
jhon309 | 0:c52df770855b | 411 | |
jhon309 | 0:c52df770855b | 412 | \param [out] descriptor_l1 L1 descriptor. |
jhon309 | 0:c52df770855b | 413 | \param [in] p_bit Parity check: ECC_DISABLED, ECC_ENABLED |
jhon309 | 0:c52df770855b | 414 | |
jhon309 | 0:c52df770855b | 415 | \return 0 |
jhon309 | 0:c52df770855b | 416 | */ |
jhon309 | 0:c52df770855b | 417 | __STATIC_INLINE int __p_page(uint32_t *descriptor_l1, mmu_ecc_check_Type p_bit) |
jhon309 | 0:c52df770855b | 418 | { |
jhon309 | 0:c52df770855b | 419 | *descriptor_l1 &= SECTION_P_MASK; |
jhon309 | 0:c52df770855b | 420 | *descriptor_l1 |= ((p_bit & 0x1) << SECTION_P_SHIFT); |
jhon309 | 0:c52df770855b | 421 | return 0; |
jhon309 | 0:c52df770855b | 422 | } |
jhon309 | 0:c52df770855b | 423 | |
jhon309 | 0:c52df770855b | 424 | /** \brief Set 4k/64k page access privileges |
jhon309 | 0:c52df770855b | 425 | |
jhon309 | 0:c52df770855b | 426 | The function sets 4k/64k page access privileges |
jhon309 | 0:c52df770855b | 427 | |
jhon309 | 0:c52df770855b | 428 | \param [out] descriptor_l2 L2 descriptor. |
jhon309 | 0:c52df770855b | 429 | \param [in] user User Level Access: NO_ACCESS, RW, READ |
jhon309 | 0:c52df770855b | 430 | \param [in] priv Privilege Level Access: NO_ACCESS, RW, READ |
jhon309 | 0:c52df770855b | 431 | \param [in] afe Access flag enable |
jhon309 | 0:c52df770855b | 432 | |
jhon309 | 0:c52df770855b | 433 | \return 0 |
jhon309 | 0:c52df770855b | 434 | */ |
jhon309 | 0:c52df770855b | 435 | __STATIC_INLINE int __ap_page(uint32_t *descriptor_l2, mmu_access_Type user, mmu_access_Type priv, uint32_t afe) |
jhon309 | 0:c52df770855b | 436 | { |
jhon309 | 0:c52df770855b | 437 | uint32_t ap = 0; |
jhon309 | 0:c52df770855b | 438 | |
jhon309 | 0:c52df770855b | 439 | if (afe == 0) { //full access |
jhon309 | 0:c52df770855b | 440 | if ((priv == NO_ACCESS) && (user == NO_ACCESS)) { ap = 0x0; } |
jhon309 | 0:c52df770855b | 441 | else if ((priv == RW) && (user == NO_ACCESS)) { ap = 0x1; } |
jhon309 | 0:c52df770855b | 442 | else if ((priv == RW) && (user == READ)) { ap = 0x2; } |
jhon309 | 0:c52df770855b | 443 | else if ((priv == RW) && (user == RW)) { ap = 0x3; } |
jhon309 | 0:c52df770855b | 444 | else if ((priv == READ) && (user == NO_ACCESS)) { ap = 0x5; } |
jhon309 | 0:c52df770855b | 445 | else if ((priv == READ) && (user == READ)) { ap = 0x6; } |
jhon309 | 0:c52df770855b | 446 | } |
jhon309 | 0:c52df770855b | 447 | |
jhon309 | 0:c52df770855b | 448 | else { //Simplified access |
jhon309 | 0:c52df770855b | 449 | if ((priv == RW) && (user == NO_ACCESS)) { ap = 0x1; } |
jhon309 | 0:c52df770855b | 450 | else if ((priv == RW) && (user == RW)) { ap = 0x3; } |
jhon309 | 0:c52df770855b | 451 | else if ((priv == READ) && (user == NO_ACCESS)) { ap = 0x5; } |
jhon309 | 0:c52df770855b | 452 | else if ((priv == READ) && (user == READ)) { ap = 0x7; } |
jhon309 | 0:c52df770855b | 453 | } |
jhon309 | 0:c52df770855b | 454 | |
jhon309 | 0:c52df770855b | 455 | *descriptor_l2 &= PAGE_AP_MASK; |
jhon309 | 0:c52df770855b | 456 | *descriptor_l2 |= (ap & 0x3) << PAGE_AP_SHIFT; |
jhon309 | 0:c52df770855b | 457 | *descriptor_l2 |= ((ap & 0x4)>>2) << PAGE_AP2_SHIFT; |
jhon309 | 0:c52df770855b | 458 | |
jhon309 | 0:c52df770855b | 459 | return 0; |
jhon309 | 0:c52df770855b | 460 | } |
jhon309 | 0:c52df770855b | 461 | |
jhon309 | 0:c52df770855b | 462 | /** \brief Set 4k/64k page shareability |
jhon309 | 0:c52df770855b | 463 | |
jhon309 | 0:c52df770855b | 464 | The function sets 4k/64k page shareability |
jhon309 | 0:c52df770855b | 465 | |
jhon309 | 0:c52df770855b | 466 | \param [out] descriptor_l2 L2 descriptor. |
jhon309 | 0:c52df770855b | 467 | \param [in] s_bit 4k/64k page shareability: NON_SHARED, SHARED |
jhon309 | 0:c52df770855b | 468 | |
jhon309 | 0:c52df770855b | 469 | \return 0 |
jhon309 | 0:c52df770855b | 470 | */ |
jhon309 | 0:c52df770855b | 471 | __STATIC_INLINE int __shared_page(uint32_t *descriptor_l2, mmu_shared_Type s_bit) |
jhon309 | 0:c52df770855b | 472 | { |
jhon309 | 0:c52df770855b | 473 | *descriptor_l2 &= PAGE_S_MASK; |
jhon309 | 0:c52df770855b | 474 | *descriptor_l2 |= ((s_bit & 0x1) << PAGE_S_SHIFT); |
jhon309 | 0:c52df770855b | 475 | return 0; |
jhon309 | 0:c52df770855b | 476 | } |
jhon309 | 0:c52df770855b | 477 | |
jhon309 | 0:c52df770855b | 478 | /** \brief Set 4k/64k page Global attribute |
jhon309 | 0:c52df770855b | 479 | |
jhon309 | 0:c52df770855b | 480 | The function sets 4k/64k page Global attribute |
jhon309 | 0:c52df770855b | 481 | |
jhon309 | 0:c52df770855b | 482 | \param [out] descriptor_l2 L2 descriptor. |
jhon309 | 0:c52df770855b | 483 | \param [in] g_bit 4k/64k page attribute: GLOBAL, NON_GLOBAL |
jhon309 | 0:c52df770855b | 484 | |
jhon309 | 0:c52df770855b | 485 | \return 0 |
jhon309 | 0:c52df770855b | 486 | */ |
jhon309 | 0:c52df770855b | 487 | __STATIC_INLINE int __global_page(uint32_t *descriptor_l2, mmu_global_Type g_bit) |
jhon309 | 0:c52df770855b | 488 | { |
jhon309 | 0:c52df770855b | 489 | *descriptor_l2 &= PAGE_NG_MASK; |
jhon309 | 0:c52df770855b | 490 | *descriptor_l2 |= ((g_bit & 0x1) << PAGE_NG_SHIFT); |
jhon309 | 0:c52df770855b | 491 | return 0; |
jhon309 | 0:c52df770855b | 492 | } |
jhon309 | 0:c52df770855b | 493 | |
jhon309 | 0:c52df770855b | 494 | /** \brief Set 4k/64k page Security attribute |
jhon309 | 0:c52df770855b | 495 | |
jhon309 | 0:c52df770855b | 496 | The function sets 4k/64k page Global attribute |
jhon309 | 0:c52df770855b | 497 | |
jhon309 | 0:c52df770855b | 498 | \param [out] descriptor_l1 L1 descriptor. |
jhon309 | 0:c52df770855b | 499 | \param [in] s_bit 4k/64k page Security attribute: SECURE, NON_SECURE |
jhon309 | 0:c52df770855b | 500 | |
jhon309 | 0:c52df770855b | 501 | \return 0 |
jhon309 | 0:c52df770855b | 502 | */ |
jhon309 | 0:c52df770855b | 503 | __STATIC_INLINE int __secure_page(uint32_t *descriptor_l1, mmu_secure_Type s_bit) |
jhon309 | 0:c52df770855b | 504 | { |
jhon309 | 0:c52df770855b | 505 | *descriptor_l1 &= PAGE_NS_MASK; |
jhon309 | 0:c52df770855b | 506 | *descriptor_l1 |= ((s_bit & 0x1) << PAGE_NS_SHIFT); |
jhon309 | 0:c52df770855b | 507 | return 0; |
jhon309 | 0:c52df770855b | 508 | } |
jhon309 | 0:c52df770855b | 509 | |
jhon309 | 0:c52df770855b | 510 | |
jhon309 | 0:c52df770855b | 511 | /** \brief Set Section memory attributes |
jhon309 | 0:c52df770855b | 512 | |
jhon309 | 0:c52df770855b | 513 | The function sets section memory attributes |
jhon309 | 0:c52df770855b | 514 | |
jhon309 | 0:c52df770855b | 515 | \param [out] descriptor_l1 L1 descriptor. |
jhon309 | 0:c52df770855b | 516 | \param [in] mem Section memory type: NORMAL, DEVICE, SHARED_DEVICE, NON_SHARED_DEVICE, STRONGLY_ORDERED |
jhon309 | 0:c52df770855b | 517 | \param [in] outer Outer cacheability: NON_CACHEABLE, WB_WA, WT, WB_NO_WA, |
jhon309 | 0:c52df770855b | 518 | \param [in] inner Inner cacheability: NON_CACHEABLE, WB_WA, WT, WB_NO_WA, |
jhon309 | 0:c52df770855b | 519 | |
jhon309 | 0:c52df770855b | 520 | \return 0 |
jhon309 | 0:c52df770855b | 521 | */ |
jhon309 | 0:c52df770855b | 522 | __STATIC_INLINE int __memory_section(uint32_t *descriptor_l1, mmu_memory_Type mem, mmu_cacheability_Type outer, mmu_cacheability_Type inner) |
jhon309 | 0:c52df770855b | 523 | { |
jhon309 | 0:c52df770855b | 524 | *descriptor_l1 &= SECTION_TEXCB_MASK; |
jhon309 | 0:c52df770855b | 525 | |
jhon309 | 0:c52df770855b | 526 | if (STRONGLY_ORDERED == mem) |
jhon309 | 0:c52df770855b | 527 | { |
jhon309 | 0:c52df770855b | 528 | return 0; |
jhon309 | 0:c52df770855b | 529 | } |
jhon309 | 0:c52df770855b | 530 | else if (SHARED_DEVICE == mem) |
jhon309 | 0:c52df770855b | 531 | { |
jhon309 | 0:c52df770855b | 532 | *descriptor_l1 |= (1 << SECTION_B_SHIFT); |
jhon309 | 0:c52df770855b | 533 | } |
jhon309 | 0:c52df770855b | 534 | else if (NON_SHARED_DEVICE == mem) |
jhon309 | 0:c52df770855b | 535 | { |
jhon309 | 0:c52df770855b | 536 | *descriptor_l1 |= (1 << SECTION_TEX1_SHIFT); |
jhon309 | 0:c52df770855b | 537 | } |
jhon309 | 0:c52df770855b | 538 | else if (NORMAL == mem) |
jhon309 | 0:c52df770855b | 539 | { |
jhon309 | 0:c52df770855b | 540 | *descriptor_l1 |= 1 << SECTION_TEX2_SHIFT; |
jhon309 | 0:c52df770855b | 541 | switch(inner) |
jhon309 | 0:c52df770855b | 542 | { |
jhon309 | 0:c52df770855b | 543 | case NON_CACHEABLE: |
jhon309 | 0:c52df770855b | 544 | break; |
jhon309 | 0:c52df770855b | 545 | case WB_WA: |
jhon309 | 0:c52df770855b | 546 | *descriptor_l1 |= (1 << SECTION_B_SHIFT); |
jhon309 | 0:c52df770855b | 547 | break; |
jhon309 | 0:c52df770855b | 548 | case WT: |
jhon309 | 0:c52df770855b | 549 | *descriptor_l1 |= 1 << SECTION_C_SHIFT; |
jhon309 | 0:c52df770855b | 550 | break; |
jhon309 | 0:c52df770855b | 551 | case WB_NO_WA: |
jhon309 | 0:c52df770855b | 552 | *descriptor_l1 |= (1 << SECTION_B_SHIFT) | (1 << SECTION_C_SHIFT); |
jhon309 | 0:c52df770855b | 553 | break; |
jhon309 | 0:c52df770855b | 554 | } |
jhon309 | 0:c52df770855b | 555 | switch(outer) |
jhon309 | 0:c52df770855b | 556 | { |
jhon309 | 0:c52df770855b | 557 | case NON_CACHEABLE: |
jhon309 | 0:c52df770855b | 558 | break; |
jhon309 | 0:c52df770855b | 559 | case WB_WA: |
jhon309 | 0:c52df770855b | 560 | *descriptor_l1 |= (1 << SECTION_TEX0_SHIFT); |
jhon309 | 0:c52df770855b | 561 | break; |
jhon309 | 0:c52df770855b | 562 | case WT: |
jhon309 | 0:c52df770855b | 563 | *descriptor_l1 |= 1 << SECTION_TEX1_SHIFT; |
jhon309 | 0:c52df770855b | 564 | break; |
jhon309 | 0:c52df770855b | 565 | case WB_NO_WA: |
jhon309 | 0:c52df770855b | 566 | *descriptor_l1 |= (1 << SECTION_TEX0_SHIFT) | (1 << SECTION_TEX0_SHIFT); |
jhon309 | 0:c52df770855b | 567 | break; |
jhon309 | 0:c52df770855b | 568 | } |
jhon309 | 0:c52df770855b | 569 | } |
jhon309 | 0:c52df770855b | 570 | |
jhon309 | 0:c52df770855b | 571 | return 0; |
jhon309 | 0:c52df770855b | 572 | } |
jhon309 | 0:c52df770855b | 573 | |
jhon309 | 0:c52df770855b | 574 | /** \brief Set 4k/64k page memory attributes |
jhon309 | 0:c52df770855b | 575 | |
jhon309 | 0:c52df770855b | 576 | The function sets 4k/64k page memory attributes |
jhon309 | 0:c52df770855b | 577 | |
jhon309 | 0:c52df770855b | 578 | \param [out] descriptor_l2 L2 descriptor. |
jhon309 | 0:c52df770855b | 579 | \param [in] mem 4k/64k page memory type: NORMAL, DEVICE, SHARED_DEVICE, NON_SHARED_DEVICE, STRONGLY_ORDERED |
jhon309 | 0:c52df770855b | 580 | \param [in] outer Outer cacheability: NON_CACHEABLE, WB_WA, WT, WB_NO_WA, |
jhon309 | 0:c52df770855b | 581 | \param [in] inner Inner cacheability: NON_CACHEABLE, WB_WA, WT, WB_NO_WA, |
jhon309 | 0:c52df770855b | 582 | |
jhon309 | 0:c52df770855b | 583 | \return 0 |
jhon309 | 0:c52df770855b | 584 | */ |
jhon309 | 0:c52df770855b | 585 | __STATIC_INLINE int __memory_page(uint32_t *descriptor_l2, mmu_memory_Type mem, mmu_cacheability_Type outer, mmu_cacheability_Type inner, mmu_region_size_Type page) |
jhon309 | 0:c52df770855b | 586 | { |
jhon309 | 0:c52df770855b | 587 | *descriptor_l2 &= PAGE_4K_TEXCB_MASK; |
jhon309 | 0:c52df770855b | 588 | |
jhon309 | 0:c52df770855b | 589 | if (page == PAGE_64k) |
jhon309 | 0:c52df770855b | 590 | { |
jhon309 | 0:c52df770855b | 591 | //same as section |
jhon309 | 0:c52df770855b | 592 | __memory_section(descriptor_l2, mem, outer, inner); |
jhon309 | 0:c52df770855b | 593 | } |
jhon309 | 0:c52df770855b | 594 | else |
jhon309 | 0:c52df770855b | 595 | { |
jhon309 | 0:c52df770855b | 596 | if (STRONGLY_ORDERED == mem) |
jhon309 | 0:c52df770855b | 597 | { |
jhon309 | 0:c52df770855b | 598 | return 0; |
jhon309 | 0:c52df770855b | 599 | } |
jhon309 | 0:c52df770855b | 600 | else if (SHARED_DEVICE == mem) |
jhon309 | 0:c52df770855b | 601 | { |
jhon309 | 0:c52df770855b | 602 | *descriptor_l2 |= (1 << PAGE_4K_B_SHIFT); |
jhon309 | 0:c52df770855b | 603 | } |
jhon309 | 0:c52df770855b | 604 | else if (NON_SHARED_DEVICE == mem) |
jhon309 | 0:c52df770855b | 605 | { |
jhon309 | 0:c52df770855b | 606 | *descriptor_l2 |= (1 << PAGE_4K_TEX1_SHIFT); |
jhon309 | 0:c52df770855b | 607 | } |
jhon309 | 0:c52df770855b | 608 | else if (NORMAL == mem) |
jhon309 | 0:c52df770855b | 609 | { |
jhon309 | 0:c52df770855b | 610 | *descriptor_l2 |= 1 << PAGE_4K_TEX2_SHIFT; |
jhon309 | 0:c52df770855b | 611 | switch(inner) |
jhon309 | 0:c52df770855b | 612 | { |
jhon309 | 0:c52df770855b | 613 | case NON_CACHEABLE: |
jhon309 | 0:c52df770855b | 614 | break; |
jhon309 | 0:c52df770855b | 615 | case WB_WA: |
jhon309 | 0:c52df770855b | 616 | *descriptor_l2 |= (1 << PAGE_4K_B_SHIFT); |
jhon309 | 0:c52df770855b | 617 | break; |
jhon309 | 0:c52df770855b | 618 | case WT: |
jhon309 | 0:c52df770855b | 619 | *descriptor_l2 |= 1 << PAGE_4K_C_SHIFT; |
jhon309 | 0:c52df770855b | 620 | break; |
jhon309 | 0:c52df770855b | 621 | case WB_NO_WA: |
jhon309 | 0:c52df770855b | 622 | *descriptor_l2 |= (1 << PAGE_4K_B_SHIFT) | (1 << PAGE_4K_C_SHIFT); |
jhon309 | 0:c52df770855b | 623 | break; |
jhon309 | 0:c52df770855b | 624 | } |
jhon309 | 0:c52df770855b | 625 | switch(outer) |
jhon309 | 0:c52df770855b | 626 | { |
jhon309 | 0:c52df770855b | 627 | case NON_CACHEABLE: |
jhon309 | 0:c52df770855b | 628 | break; |
jhon309 | 0:c52df770855b | 629 | case WB_WA: |
jhon309 | 0:c52df770855b | 630 | *descriptor_l2 |= (1 << PAGE_4K_TEX0_SHIFT); |
jhon309 | 0:c52df770855b | 631 | break; |
jhon309 | 0:c52df770855b | 632 | case WT: |
jhon309 | 0:c52df770855b | 633 | *descriptor_l2 |= 1 << PAGE_4K_TEX1_SHIFT; |
jhon309 | 0:c52df770855b | 634 | break; |
jhon309 | 0:c52df770855b | 635 | case WB_NO_WA: |
jhon309 | 0:c52df770855b | 636 | *descriptor_l2 |= (1 << PAGE_4K_TEX0_SHIFT) | (1 << PAGE_4K_TEX0_SHIFT); |
jhon309 | 0:c52df770855b | 637 | break; |
jhon309 | 0:c52df770855b | 638 | } |
jhon309 | 0:c52df770855b | 639 | } |
jhon309 | 0:c52df770855b | 640 | } |
jhon309 | 0:c52df770855b | 641 | |
jhon309 | 0:c52df770855b | 642 | return 0; |
jhon309 | 0:c52df770855b | 643 | } |
jhon309 | 0:c52df770855b | 644 | |
jhon309 | 0:c52df770855b | 645 | /** \brief Create a L1 section descriptor |
jhon309 | 0:c52df770855b | 646 | |
jhon309 | 0:c52df770855b | 647 | The function creates a section descriptor. |
jhon309 | 0:c52df770855b | 648 | |
jhon309 | 0:c52df770855b | 649 | Assumptions: |
jhon309 | 0:c52df770855b | 650 | - 16MB super sections not suported |
jhon309 | 0:c52df770855b | 651 | - TEX remap disabled, so memory type and attributes are described directly by bits in the descriptor |
jhon309 | 0:c52df770855b | 652 | - Functions always return 0 |
jhon309 | 0:c52df770855b | 653 | |
jhon309 | 0:c52df770855b | 654 | \param [out] descriptor L1 descriptor |
jhon309 | 0:c52df770855b | 655 | \param [out] descriptor2 L2 descriptor |
jhon309 | 0:c52df770855b | 656 | \param [in] reg Section attributes |
jhon309 | 0:c52df770855b | 657 | |
jhon309 | 0:c52df770855b | 658 | \return 0 |
jhon309 | 0:c52df770855b | 659 | */ |
jhon309 | 0:c52df770855b | 660 | __STATIC_INLINE int __get_section_descriptor(uint32_t *descriptor, mmu_region_attributes_Type reg) |
jhon309 | 0:c52df770855b | 661 | { |
jhon309 | 0:c52df770855b | 662 | *descriptor = 0; |
jhon309 | 0:c52df770855b | 663 | |
jhon309 | 0:c52df770855b | 664 | __memory_section(descriptor, reg.mem_t, reg.outer_norm_t, reg.inner_norm_t); |
jhon309 | 0:c52df770855b | 665 | __xn_section(descriptor,reg.xn_t); |
jhon309 | 0:c52df770855b | 666 | __domain_section(descriptor, reg.domain); |
jhon309 | 0:c52df770855b | 667 | __p_section(descriptor, reg.e_t); |
jhon309 | 0:c52df770855b | 668 | __ap_section(descriptor, reg.priv_t, reg.user_t, 1); |
jhon309 | 0:c52df770855b | 669 | __shared_section(descriptor,reg.sh_t); |
jhon309 | 0:c52df770855b | 670 | __global_section(descriptor,reg.g_t); |
jhon309 | 0:c52df770855b | 671 | __secure_section(descriptor,reg.sec_t); |
jhon309 | 0:c52df770855b | 672 | *descriptor &= SECTION_MASK; |
jhon309 | 0:c52df770855b | 673 | *descriptor |= SECTION_DESCRIPTOR; |
jhon309 | 0:c52df770855b | 674 | |
jhon309 | 0:c52df770855b | 675 | return 0; |
jhon309 | 0:c52df770855b | 676 | |
jhon309 | 0:c52df770855b | 677 | } |
jhon309 | 0:c52df770855b | 678 | |
jhon309 | 0:c52df770855b | 679 | |
jhon309 | 0:c52df770855b | 680 | /** \brief Create a L1 and L2 4k/64k page descriptor |
jhon309 | 0:c52df770855b | 681 | |
jhon309 | 0:c52df770855b | 682 | The function creates a 4k/64k page descriptor. |
jhon309 | 0:c52df770855b | 683 | Assumptions: |
jhon309 | 0:c52df770855b | 684 | - TEX remap disabled, so memory type and attributes are described directly by bits in the descriptor |
jhon309 | 0:c52df770855b | 685 | - Functions always return 0 |
jhon309 | 0:c52df770855b | 686 | |
jhon309 | 0:c52df770855b | 687 | \param [out] descriptor L1 descriptor |
jhon309 | 0:c52df770855b | 688 | \param [out] descriptor2 L2 descriptor |
jhon309 | 0:c52df770855b | 689 | \param [in] reg 4k/64k page attributes |
jhon309 | 0:c52df770855b | 690 | |
jhon309 | 0:c52df770855b | 691 | \return 0 |
jhon309 | 0:c52df770855b | 692 | */ |
jhon309 | 0:c52df770855b | 693 | __STATIC_INLINE int __get_page_descriptor(uint32_t *descriptor, uint32_t *descriptor2, mmu_region_attributes_Type reg) |
jhon309 | 0:c52df770855b | 694 | { |
jhon309 | 0:c52df770855b | 695 | *descriptor = 0; |
jhon309 | 0:c52df770855b | 696 | *descriptor2 = 0; |
jhon309 | 0:c52df770855b | 697 | |
jhon309 | 0:c52df770855b | 698 | switch (reg.rg_t) |
jhon309 | 0:c52df770855b | 699 | { |
jhon309 | 0:c52df770855b | 700 | case PAGE_4k: |
jhon309 | 0:c52df770855b | 701 | __memory_page(descriptor2, reg.mem_t, reg.outer_norm_t, reg.inner_norm_t, PAGE_4k); |
jhon309 | 0:c52df770855b | 702 | __xn_page(descriptor2, reg.xn_t, PAGE_4k); |
jhon309 | 0:c52df770855b | 703 | __domain_page(descriptor, reg.domain); |
jhon309 | 0:c52df770855b | 704 | __p_page(descriptor, reg.e_t); |
jhon309 | 0:c52df770855b | 705 | __ap_page(descriptor2, reg.priv_t, reg.user_t, 1); |
jhon309 | 0:c52df770855b | 706 | __shared_page(descriptor2,reg.sh_t); |
jhon309 | 0:c52df770855b | 707 | __global_page(descriptor2,reg.g_t); |
jhon309 | 0:c52df770855b | 708 | __secure_page(descriptor,reg.sec_t); |
jhon309 | 0:c52df770855b | 709 | *descriptor &= PAGE_L1_MASK; |
jhon309 | 0:c52df770855b | 710 | *descriptor |= PAGE_L1_DESCRIPTOR; |
jhon309 | 0:c52df770855b | 711 | *descriptor2 &= PAGE_L2_4K_MASK; |
jhon309 | 0:c52df770855b | 712 | *descriptor2 |= PAGE_L2_4K_DESC; |
jhon309 | 0:c52df770855b | 713 | break; |
jhon309 | 0:c52df770855b | 714 | |
jhon309 | 0:c52df770855b | 715 | case PAGE_64k: |
jhon309 | 0:c52df770855b | 716 | __memory_page(descriptor2, reg.mem_t, reg.outer_norm_t, reg.inner_norm_t, PAGE_64k); |
jhon309 | 0:c52df770855b | 717 | __xn_page(descriptor2, reg.xn_t, PAGE_64k); |
jhon309 | 0:c52df770855b | 718 | __domain_page(descriptor, reg.domain); |
jhon309 | 0:c52df770855b | 719 | __p_page(descriptor, reg.e_t); |
jhon309 | 0:c52df770855b | 720 | __ap_page(descriptor2, reg.priv_t, reg.user_t, 1); |
jhon309 | 0:c52df770855b | 721 | __shared_page(descriptor2,reg.sh_t); |
jhon309 | 0:c52df770855b | 722 | __global_page(descriptor2,reg.g_t); |
jhon309 | 0:c52df770855b | 723 | __secure_page(descriptor,reg.sec_t); |
jhon309 | 0:c52df770855b | 724 | *descriptor &= PAGE_L1_MASK; |
jhon309 | 0:c52df770855b | 725 | *descriptor |= PAGE_L1_DESCRIPTOR; |
jhon309 | 0:c52df770855b | 726 | *descriptor2 &= PAGE_L2_64K_MASK; |
jhon309 | 0:c52df770855b | 727 | *descriptor2 |= PAGE_L2_64K_DESC; |
jhon309 | 0:c52df770855b | 728 | break; |
jhon309 | 0:c52df770855b | 729 | |
jhon309 | 0:c52df770855b | 730 | case SECTION: |
jhon309 | 0:c52df770855b | 731 | //error |
jhon309 | 0:c52df770855b | 732 | break; |
jhon309 | 0:c52df770855b | 733 | |
jhon309 | 0:c52df770855b | 734 | } |
jhon309 | 0:c52df770855b | 735 | |
jhon309 | 0:c52df770855b | 736 | return 0; |
jhon309 | 0:c52df770855b | 737 | |
jhon309 | 0:c52df770855b | 738 | } |
jhon309 | 0:c52df770855b | 739 | |
jhon309 | 0:c52df770855b | 740 | /** \brief Create a 1MB Section |
jhon309 | 0:c52df770855b | 741 | |
jhon309 | 0:c52df770855b | 742 | \param [in] ttb Translation table base address |
jhon309 | 0:c52df770855b | 743 | \param [in] base_address Section base address |
jhon309 | 0:c52df770855b | 744 | \param [in] count Number of sections to create |
jhon309 | 0:c52df770855b | 745 | \param [in] descriptor_l1 L1 descriptor (region attributes) |
jhon309 | 0:c52df770855b | 746 | |
jhon309 | 0:c52df770855b | 747 | */ |
jhon309 | 0:c52df770855b | 748 | __STATIC_INLINE void __TTSection(uint32_t *ttb, uint32_t base_address, uint32_t count, uint32_t descriptor_l1) |
jhon309 | 0:c52df770855b | 749 | { |
jhon309 | 0:c52df770855b | 750 | uint32_t offset; |
jhon309 | 0:c52df770855b | 751 | uint32_t entry; |
jhon309 | 0:c52df770855b | 752 | uint32_t i; |
jhon309 | 0:c52df770855b | 753 | |
jhon309 | 0:c52df770855b | 754 | offset = base_address >> 20; |
jhon309 | 0:c52df770855b | 755 | entry = (base_address & 0xFFF00000) | descriptor_l1; |
jhon309 | 0:c52df770855b | 756 | |
jhon309 | 0:c52df770855b | 757 | //4 bytes aligned |
jhon309 | 0:c52df770855b | 758 | ttb = ttb + offset; |
jhon309 | 0:c52df770855b | 759 | |
jhon309 | 0:c52df770855b | 760 | for (i = 0; i < count; i++ ) |
jhon309 | 0:c52df770855b | 761 | { |
jhon309 | 0:c52df770855b | 762 | //4 bytes aligned |
jhon309 | 0:c52df770855b | 763 | *ttb++ = entry; |
jhon309 | 0:c52df770855b | 764 | entry += OFFSET_1M; |
jhon309 | 0:c52df770855b | 765 | } |
jhon309 | 0:c52df770855b | 766 | } |
jhon309 | 0:c52df770855b | 767 | |
jhon309 | 0:c52df770855b | 768 | /** \brief Create a 4k page entry |
jhon309 | 0:c52df770855b | 769 | |
jhon309 | 0:c52df770855b | 770 | \param [in] ttb L1 table base address |
jhon309 | 0:c52df770855b | 771 | \param [in] base_address 4k base address |
jhon309 | 0:c52df770855b | 772 | \param [in] count Number of 4k pages to create |
jhon309 | 0:c52df770855b | 773 | \param [in] descriptor_l1 L1 descriptor (region attributes) |
jhon309 | 0:c52df770855b | 774 | \param [in] ttb_l2 L2 table base address |
jhon309 | 0:c52df770855b | 775 | \param [in] descriptor_l2 L2 descriptor (region attributes) |
jhon309 | 0:c52df770855b | 776 | |
jhon309 | 0:c52df770855b | 777 | */ |
jhon309 | 0:c52df770855b | 778 | __STATIC_INLINE void __TTPage_4k(uint32_t *ttb, uint32_t base_address, uint32_t count, uint32_t descriptor_l1, uint32_t *ttb_l2, uint32_t descriptor_l2 ) |
jhon309 | 0:c52df770855b | 779 | { |
jhon309 | 0:c52df770855b | 780 | |
jhon309 | 0:c52df770855b | 781 | uint32_t offset, offset2; |
jhon309 | 0:c52df770855b | 782 | uint32_t entry, entry2; |
jhon309 | 0:c52df770855b | 783 | uint32_t i; |
jhon309 | 0:c52df770855b | 784 | |
jhon309 | 0:c52df770855b | 785 | |
jhon309 | 0:c52df770855b | 786 | offset = base_address >> 20; |
jhon309 | 0:c52df770855b | 787 | entry = ((int)ttb_l2 & 0xFFFFFC00) | descriptor_l1; |
jhon309 | 0:c52df770855b | 788 | |
jhon309 | 0:c52df770855b | 789 | //4 bytes aligned |
jhon309 | 0:c52df770855b | 790 | ttb += offset; |
jhon309 | 0:c52df770855b | 791 | //create l1_entry |
jhon309 | 0:c52df770855b | 792 | *ttb = entry; |
jhon309 | 0:c52df770855b | 793 | |
jhon309 | 0:c52df770855b | 794 | offset2 = (base_address & 0xff000) >> 12; |
jhon309 | 0:c52df770855b | 795 | ttb_l2 += offset2; |
jhon309 | 0:c52df770855b | 796 | entry2 = (base_address & 0xFFFFF000) | descriptor_l2; |
jhon309 | 0:c52df770855b | 797 | for (i = 0; i < count; i++ ) |
jhon309 | 0:c52df770855b | 798 | { |
jhon309 | 0:c52df770855b | 799 | //4 bytes aligned |
jhon309 | 0:c52df770855b | 800 | *ttb_l2++ = entry2; |
jhon309 | 0:c52df770855b | 801 | entry2 += OFFSET_4K; |
jhon309 | 0:c52df770855b | 802 | } |
jhon309 | 0:c52df770855b | 803 | } |
jhon309 | 0:c52df770855b | 804 | |
jhon309 | 0:c52df770855b | 805 | /** \brief Create a 64k page entry |
jhon309 | 0:c52df770855b | 806 | |
jhon309 | 0:c52df770855b | 807 | \param [in] ttb L1 table base address |
jhon309 | 0:c52df770855b | 808 | \param [in] base_address 64k base address |
jhon309 | 0:c52df770855b | 809 | \param [in] count Number of 64k pages to create |
jhon309 | 0:c52df770855b | 810 | \param [in] descriptor_l1 L1 descriptor (region attributes) |
jhon309 | 0:c52df770855b | 811 | \param [in] ttb_l2 L2 table base address |
jhon309 | 0:c52df770855b | 812 | \param [in] descriptor_l2 L2 descriptor (region attributes) |
jhon309 | 0:c52df770855b | 813 | |
jhon309 | 0:c52df770855b | 814 | */ |
jhon309 | 0:c52df770855b | 815 | __STATIC_INLINE void __TTPage_64k(uint32_t *ttb, uint32_t base_address, uint32_t count, uint32_t descriptor_l1, uint32_t *ttb_l2, uint32_t descriptor_l2 ) |
jhon309 | 0:c52df770855b | 816 | { |
jhon309 | 0:c52df770855b | 817 | uint32_t offset, offset2; |
jhon309 | 0:c52df770855b | 818 | uint32_t entry, entry2; |
jhon309 | 0:c52df770855b | 819 | uint32_t i,j; |
jhon309 | 0:c52df770855b | 820 | |
jhon309 | 0:c52df770855b | 821 | |
jhon309 | 0:c52df770855b | 822 | offset = base_address >> 20; |
jhon309 | 0:c52df770855b | 823 | entry = ((int)ttb_l2 & 0xFFFFFC00) | descriptor_l1; |
jhon309 | 0:c52df770855b | 824 | |
jhon309 | 0:c52df770855b | 825 | //4 bytes aligned |
jhon309 | 0:c52df770855b | 826 | ttb += offset; |
jhon309 | 0:c52df770855b | 827 | //create l1_entry |
jhon309 | 0:c52df770855b | 828 | *ttb = entry; |
jhon309 | 0:c52df770855b | 829 | |
jhon309 | 0:c52df770855b | 830 | offset2 = (base_address & 0xff000) >> 12; |
jhon309 | 0:c52df770855b | 831 | ttb_l2 += offset2; |
jhon309 | 0:c52df770855b | 832 | entry2 = (base_address & 0xFFFF0000) | descriptor_l2; |
jhon309 | 0:c52df770855b | 833 | for (i = 0; i < count; i++ ) |
jhon309 | 0:c52df770855b | 834 | { |
jhon309 | 0:c52df770855b | 835 | //create 16 entries |
jhon309 | 0:c52df770855b | 836 | for (j = 0; j < 16; j++) |
jhon309 | 0:c52df770855b | 837 | //4 bytes aligned |
jhon309 | 0:c52df770855b | 838 | *ttb_l2++ = entry2; |
jhon309 | 0:c52df770855b | 839 | entry2 += OFFSET_64K; |
jhon309 | 0:c52df770855b | 840 | } |
jhon309 | 0:c52df770855b | 841 | } |
jhon309 | 0:c52df770855b | 842 | |
jhon309 | 0:c52df770855b | 843 | /*@} end of MMU_Functions */ |
jhon309 | 0:c52df770855b | 844 | #endif |
jhon309 | 0:c52df770855b | 845 | |
jhon309 | 0:c52df770855b | 846 | #ifdef __cplusplus |
jhon309 | 0:c52df770855b | 847 | } |
jhon309 | 0:c52df770855b | 848 | #endif |