PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)

Dependents:   Sensitive

Fork of PokittoLib by Jonne Valola

Committer:
spinal
Date:
Wed Oct 18 14:47:54 2017 +0000
Revision:
15:0bbe8f6fae32
Parent:
6:ea7377f3d1af
direct lcd stuff used by sensitive

Who changed what in which revision?

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