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

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

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

Committer:
<>
Date:
Wed Apr 12 16:07:08 2017 +0100
Revision:
140:97feb9bacc10
Parent:
111:4336505e4b1c
Release 140 of the mbed library

Ports for Upcoming Targets

3841: Add nRf52840 target https://github.com/ARMmbed/mbed-os/pull/3841
3992: Introducing UBLOX_C030 platform. https://github.com/ARMmbed/mbed-os/pull/3992

Fixes and Changes

3951: [NUCLEO_F303ZE] Correct ARDUINO pin https://github.com/ARMmbed/mbed-os/pull/3951
4021: Fixing a macro to detect when RTOS was in use for the NRF52840_DK https://github.com/ARMmbed/mbed-os/pull/4021
3979: KW24D: Add missing SPI defines and Arduino connector definitions https://github.com/ARMmbed/mbed-os/pull/3979
3990: UBLOX_C027: construct a ticker-based wait, rather than calling wait_ms(), in the https://github.com/ARMmbed/mbed-os/pull/3990
4003: Fixed OBOE in async serial tx for NRF52 target, fixes #4002 https://github.com/ARMmbed/mbed-os/pull/4003
4012: STM32: Correct I2C master error handling https://github.com/ARMmbed/mbed-os/pull/4012
4020: NUCLEO_L011K4 remove unsupported tool chain files https://github.com/ARMmbed/mbed-os/pull/4020
4065: K66F: Move bss section to m_data_2 Section https://github.com/ARMmbed/mbed-os/pull/4065
4014: Issue 3763: Reduce heap allocation in the GCC linker file https://github.com/ARMmbed/mbed-os/pull/4014
4030: [STM32L0] reduce IAR heap and stack size for small targets https://github.com/ARMmbed/mbed-os/pull/4030
4109: NUCLEO_L476RG : minor serial pin update https://github.com/ARMmbed/mbed-os/pull/4109
3982: Ticker - kl25z bugfix for handling events in the past https://github.com/ARMmbed/mbed-os/pull/3982

Who changed what in which revision?

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