.

Dependents:   RTC

Committer:
jhon309
Date:
Thu Aug 13 00:20:09 2015 +0000
Revision:
0:88e313c910d0
RTC Example

Who changed what in which revision?

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