I2C_EEPROM

Committer:
jhon309
Date:
Thu Aug 13 00:23:16 2015 +0000
Revision:
0:ac8863619623
I2C

Who changed what in which revision?

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