The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Fri May 26 12:30:20 2017 +0100
Revision:
143:86740a56073b
Parent:
122:f9eeca106725
Release 143 of the mbed library.

Who changed what in which revision?

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