ads1115 only

Fork of mbed by mbed official

Committer:
Kojto
Date:
Wed Jul 08 11:22:30 2015 +0100
Revision:
102:da0ca467f8b5
Child:
108:34e6b704fe68
Release 102 of the mbed library

Changes:
- new platform: MPS2
- K64f - mac address fix
- Freescale Kinetis - Serial NC handling fix
- Asynch constnes fixes
- startup files .s - change extension to .S
- APPNEARME_MICRONFCBOARD rename to MICRONFCBOARD

Who changed what in which revision?

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