Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
Dan Handley | b226a4d | 2014-05-16 14:08:45 +0100 | [diff] [blame] | 31 | #include <arch.h> |
| 32 | #include <arch_helpers.h> |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 33 | #include <assert.h> |
Vikram Kanigiri | 725b133 | 2015-03-04 10:34:27 +0000 | [diff] [blame] | 34 | #include <bl_common.h> |
Lin Ma | 741a382 | 2014-06-27 16:56:30 -0700 | [diff] [blame] | 35 | #include <cassert.h> |
Dan Handley | ed6ff95 | 2014-05-14 17:44:19 +0100 | [diff] [blame] | 36 | #include <platform_def.h> |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 37 | #include <string.h> |
| 38 | #include <xlat_tables.h> |
| 39 | |
| 40 | |
| 41 | #ifndef DEBUG_XLAT_TABLE |
| 42 | #define DEBUG_XLAT_TABLE 0 |
| 43 | #endif |
| 44 | |
| 45 | #if DEBUG_XLAT_TABLE |
| 46 | #define debug_print(...) printf(__VA_ARGS__) |
| 47 | #else |
| 48 | #define debug_print(...) ((void)0) |
| 49 | #endif |
| 50 | |
Lin Ma | 741a382 | 2014-06-27 16:56:30 -0700 | [diff] [blame] | 51 | CASSERT(ADDR_SPACE_SIZE > 0, assert_valid_addr_space_size); |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 52 | |
| 53 | #define UNSET_DESC ~0ul |
| 54 | |
| 55 | #define NUM_L1_ENTRIES (ADDR_SPACE_SIZE >> L1_XLAT_ADDRESS_SHIFT) |
| 56 | |
Dan Handley | b226a4d | 2014-05-16 14:08:45 +0100 | [diff] [blame] | 57 | static uint64_t l1_xlation_table[NUM_L1_ENTRIES] |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 58 | __aligned(NUM_L1_ENTRIES * sizeof(uint64_t)); |
| 59 | |
| 60 | static uint64_t xlat_tables[MAX_XLAT_TABLES][XLAT_TABLE_ENTRIES] |
| 61 | __aligned(XLAT_TABLE_SIZE) __attribute__((section("xlat_table"))); |
| 62 | |
| 63 | static unsigned next_xlat; |
Lin Ma | 741a382 | 2014-06-27 16:56:30 -0700 | [diff] [blame] | 64 | static unsigned long max_pa; |
| 65 | static unsigned long max_va; |
| 66 | static unsigned long tcr_ps_bits; |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 67 | |
| 68 | /* |
| 69 | * Array of all memory regions stored in order of ascending base address. |
| 70 | * The list is terminated by the first entry with size == 0. |
| 71 | */ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 72 | static mmap_region_t mmap[MAX_MMAP_REGIONS + 1]; |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 73 | |
| 74 | |
| 75 | static void print_mmap(void) |
| 76 | { |
| 77 | #if DEBUG_XLAT_TABLE |
| 78 | debug_print("mmap:\n"); |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 79 | mmap_region_t *mm = mmap; |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 80 | while (mm->size) { |
Lin Ma | 1359236 | 2014-06-02 11:45:36 -0700 | [diff] [blame] | 81 | debug_print(" %010lx %010lx %10lx %x\n", mm->base_va, |
| 82 | mm->base_pa, mm->size, mm->attr); |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 83 | ++mm; |
| 84 | }; |
| 85 | debug_print("\n"); |
| 86 | #endif |
| 87 | } |
| 88 | |
Lin Ma | 1359236 | 2014-06-02 11:45:36 -0700 | [diff] [blame] | 89 | void mmap_add_region(unsigned long base_pa, unsigned long base_va, |
| 90 | unsigned long size, unsigned attr) |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 91 | { |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 92 | mmap_region_t *mm = mmap; |
Vikram Kanigiri | 725b133 | 2015-03-04 10:34:27 +0000 | [diff] [blame] | 93 | mmap_region_t *mm_last = mm + ARRAY_SIZE(mmap) - 1; |
Lin Ma | 741a382 | 2014-06-27 16:56:30 -0700 | [diff] [blame] | 94 | unsigned long pa_end = base_pa + size - 1; |
| 95 | unsigned long va_end = base_va + size - 1; |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 96 | |
Lin Ma | 1359236 | 2014-06-02 11:45:36 -0700 | [diff] [blame] | 97 | assert(IS_PAGE_ALIGNED(base_pa)); |
| 98 | assert(IS_PAGE_ALIGNED(base_va)); |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 99 | assert(IS_PAGE_ALIGNED(size)); |
| 100 | |
| 101 | if (!size) |
| 102 | return; |
| 103 | |
| 104 | /* Find correct place in mmap to insert new region */ |
Lin Ma | 1359236 | 2014-06-02 11:45:36 -0700 | [diff] [blame] | 105 | while (mm->base_va < base_va && mm->size) |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 106 | ++mm; |
| 107 | |
| 108 | /* Make room for new region by moving other regions up by one place */ |
| 109 | memmove(mm + 1, mm, (uintptr_t)mm_last - (uintptr_t)mm); |
| 110 | |
| 111 | /* Check we haven't lost the empty sentinal from the end of the array */ |
| 112 | assert(mm_last->size == 0); |
| 113 | |
Lin Ma | 1359236 | 2014-06-02 11:45:36 -0700 | [diff] [blame] | 114 | mm->base_pa = base_pa; |
| 115 | mm->base_va = base_va; |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 116 | mm->size = size; |
| 117 | mm->attr = attr; |
Lin Ma | 741a382 | 2014-06-27 16:56:30 -0700 | [diff] [blame] | 118 | |
| 119 | if (pa_end > max_pa) |
| 120 | max_pa = pa_end; |
| 121 | if (va_end > max_va) |
| 122 | max_va = va_end; |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 125 | void mmap_add(const mmap_region_t *mm) |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 126 | { |
| 127 | while (mm->size) { |
Lin Ma | 1359236 | 2014-06-02 11:45:36 -0700 | [diff] [blame] | 128 | mmap_add_region(mm->base_pa, mm->base_va, mm->size, mm->attr); |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 129 | ++mm; |
| 130 | } |
| 131 | } |
| 132 | |
Lin Ma | 1359236 | 2014-06-02 11:45:36 -0700 | [diff] [blame] | 133 | static unsigned long mmap_desc(unsigned attr, unsigned long addr_pa, |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 134 | unsigned level) |
| 135 | { |
Lin Ma | 1359236 | 2014-06-02 11:45:36 -0700 | [diff] [blame] | 136 | unsigned long desc = addr_pa; |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 137 | |
| 138 | desc |= level == 3 ? TABLE_DESC : BLOCK_DESC; |
| 139 | |
| 140 | desc |= attr & MT_NS ? LOWER_ATTRS(NS) : 0; |
| 141 | |
| 142 | desc |= attr & MT_RW ? LOWER_ATTRS(AP_RW) : LOWER_ATTRS(AP_RO); |
| 143 | |
| 144 | desc |= LOWER_ATTRS(ACCESS_FLAG); |
| 145 | |
| 146 | if (attr & MT_MEMORY) { |
| 147 | desc |= LOWER_ATTRS(ATTR_IWBWA_OWBWA_NTR_INDEX | ISH); |
| 148 | if (attr & MT_RW) |
| 149 | desc |= UPPER_ATTRS(XN); |
| 150 | } else { |
| 151 | desc |= LOWER_ATTRS(ATTR_DEVICE_INDEX | OSH); |
| 152 | desc |= UPPER_ATTRS(XN); |
| 153 | } |
| 154 | |
| 155 | debug_print(attr & MT_MEMORY ? "MEM" : "DEV"); |
| 156 | debug_print(attr & MT_RW ? "-RW" : "-RO"); |
| 157 | debug_print(attr & MT_NS ? "-NS" : "-S"); |
| 158 | |
| 159 | return desc; |
| 160 | } |
| 161 | |
Lin Ma | 1359236 | 2014-06-02 11:45:36 -0700 | [diff] [blame] | 162 | static int mmap_region_attr(mmap_region_t *mm, unsigned long base_va, |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 163 | unsigned long size) |
| 164 | { |
| 165 | int attr = mm->attr; |
| 166 | |
| 167 | for (;;) { |
| 168 | ++mm; |
| 169 | |
| 170 | if (!mm->size) |
| 171 | return attr; /* Reached end of list */ |
| 172 | |
Lin Ma | 1359236 | 2014-06-02 11:45:36 -0700 | [diff] [blame] | 173 | if (mm->base_va >= base_va + size) |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 174 | return attr; /* Next region is after area so end */ |
| 175 | |
Lin Ma | 1359236 | 2014-06-02 11:45:36 -0700 | [diff] [blame] | 176 | if (mm->base_va + mm->size <= base_va) |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 177 | continue; /* Next region has already been overtaken */ |
| 178 | |
| 179 | if ((mm->attr & attr) == attr) |
| 180 | continue; /* Region doesn't override attribs so skip */ |
| 181 | |
| 182 | attr &= mm->attr; |
| 183 | |
Lin Ma | 1359236 | 2014-06-02 11:45:36 -0700 | [diff] [blame] | 184 | if (mm->base_va > base_va || |
| 185 | mm->base_va + mm->size < base_va + size) |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 186 | return -1; /* Region doesn't fully cover our area */ |
| 187 | } |
| 188 | } |
| 189 | |
Lin Ma | 1359236 | 2014-06-02 11:45:36 -0700 | [diff] [blame] | 190 | static mmap_region_t *init_xlation_table(mmap_region_t *mm, |
| 191 | unsigned long base_va, |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 192 | unsigned long *table, unsigned level) |
| 193 | { |
| 194 | unsigned level_size_shift = L1_XLAT_ADDRESS_SHIFT - (level - 1) * |
| 195 | XLAT_TABLE_ENTRIES_SHIFT; |
| 196 | unsigned level_size = 1 << level_size_shift; |
Lin Ma | 0b9d59f | 2014-05-20 11:25:55 -0700 | [diff] [blame] | 197 | unsigned long level_index_mask = XLAT_TABLE_ENTRIES_MASK << level_size_shift; |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 198 | |
| 199 | assert(level <= 3); |
| 200 | |
| 201 | debug_print("New xlat table:\n"); |
| 202 | |
| 203 | do { |
| 204 | unsigned long desc = UNSET_DESC; |
| 205 | |
Lin Ma | 1359236 | 2014-06-02 11:45:36 -0700 | [diff] [blame] | 206 | if (mm->base_va + mm->size <= base_va) { |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 207 | /* Area now after the region so skip it */ |
| 208 | ++mm; |
| 209 | continue; |
| 210 | } |
| 211 | |
Lin Ma | 1359236 | 2014-06-02 11:45:36 -0700 | [diff] [blame] | 212 | debug_print(" %010lx %8lx " + 6 - 2 * level, base_va, |
| 213 | level_size); |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 214 | |
Lin Ma | 1359236 | 2014-06-02 11:45:36 -0700 | [diff] [blame] | 215 | if (mm->base_va >= base_va + level_size) { |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 216 | /* Next region is after area so nothing to map yet */ |
| 217 | desc = INVALID_DESC; |
Lin Ma | 1359236 | 2014-06-02 11:45:36 -0700 | [diff] [blame] | 218 | } else if (mm->base_va <= base_va && mm->base_va + mm->size >= |
| 219 | base_va + level_size) { |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 220 | /* Next region covers all of area */ |
Lin Ma | 1359236 | 2014-06-02 11:45:36 -0700 | [diff] [blame] | 221 | int attr = mmap_region_attr(mm, base_va, level_size); |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 222 | if (attr >= 0) |
Lin Ma | 1359236 | 2014-06-02 11:45:36 -0700 | [diff] [blame] | 223 | desc = mmap_desc(attr, |
| 224 | base_va - mm->base_va + mm->base_pa, |
| 225 | level); |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 226 | } |
| 227 | /* else Next region only partially covers area, so need */ |
| 228 | |
| 229 | if (desc == UNSET_DESC) { |
| 230 | /* Area not covered by a region so need finer table */ |
| 231 | unsigned long *new_table = xlat_tables[next_xlat++]; |
| 232 | assert(next_xlat <= MAX_XLAT_TABLES); |
| 233 | desc = TABLE_DESC | (unsigned long)new_table; |
| 234 | |
| 235 | /* Recurse to fill in new table */ |
Lin Ma | 1359236 | 2014-06-02 11:45:36 -0700 | [diff] [blame] | 236 | mm = init_xlation_table(mm, base_va, |
| 237 | new_table, level+1); |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | debug_print("\n"); |
| 241 | |
| 242 | *table++ = desc; |
Lin Ma | 1359236 | 2014-06-02 11:45:36 -0700 | [diff] [blame] | 243 | base_va += level_size; |
| 244 | } while (mm->size && (base_va & level_index_mask)); |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 245 | |
| 246 | return mm; |
| 247 | } |
| 248 | |
Lin Ma | 741a382 | 2014-06-27 16:56:30 -0700 | [diff] [blame] | 249 | static unsigned int calc_physical_addr_size_bits(unsigned long max_addr) |
| 250 | { |
| 251 | /* Physical address can't exceed 48 bits */ |
| 252 | assert((max_addr & ADDR_MASK_48_TO_63) == 0); |
| 253 | |
| 254 | /* 48 bits address */ |
| 255 | if (max_addr & ADDR_MASK_44_TO_47) |
| 256 | return TCR_PS_BITS_256TB; |
| 257 | |
| 258 | /* 44 bits address */ |
| 259 | if (max_addr & ADDR_MASK_42_TO_43) |
| 260 | return TCR_PS_BITS_16TB; |
| 261 | |
| 262 | /* 42 bits address */ |
| 263 | if (max_addr & ADDR_MASK_40_TO_41) |
| 264 | return TCR_PS_BITS_4TB; |
| 265 | |
| 266 | /* 40 bits address */ |
| 267 | if (max_addr & ADDR_MASK_36_TO_39) |
| 268 | return TCR_PS_BITS_1TB; |
| 269 | |
| 270 | /* 36 bits address */ |
| 271 | if (max_addr & ADDR_MASK_32_TO_35) |
| 272 | return TCR_PS_BITS_64GB; |
| 273 | |
| 274 | return TCR_PS_BITS_4GB; |
| 275 | } |
| 276 | |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 277 | void init_xlat_tables(void) |
| 278 | { |
| 279 | print_mmap(); |
| 280 | init_xlation_table(mmap, 0, l1_xlation_table, 1); |
Lin Ma | 741a382 | 2014-06-27 16:56:30 -0700 | [diff] [blame] | 281 | tcr_ps_bits = calc_physical_addr_size_bits(max_pa); |
| 282 | assert(max_va < ADDR_SPACE_SIZE); |
Jon Medhurst | bb1fe20 | 2014-01-24 15:41:33 +0000 | [diff] [blame] | 283 | } |
Dan Handley | b226a4d | 2014-05-16 14:08:45 +0100 | [diff] [blame] | 284 | |
| 285 | /******************************************************************************* |
| 286 | * Macro generating the code for the function enabling the MMU in the given |
| 287 | * exception level, assuming that the pagetables have already been created. |
| 288 | * |
| 289 | * _el: Exception level at which the function will run |
| 290 | * _tcr_extra: Extra bits to set in the TCR register. This mask will |
| 291 | * be OR'ed with the default TCR value. |
| 292 | * _tlbi_fct: Function to invalidate the TLBs at the current |
| 293 | * exception level |
| 294 | ******************************************************************************/ |
| 295 | #define DEFINE_ENABLE_MMU_EL(_el, _tcr_extra, _tlbi_fct) \ |
Achin Gupta | e998254 | 2014-06-26 08:59:07 +0100 | [diff] [blame] | 296 | void enable_mmu_el##_el(uint32_t flags) \ |
Dan Handley | b226a4d | 2014-05-16 14:08:45 +0100 | [diff] [blame] | 297 | { \ |
| 298 | uint64_t mair, tcr, ttbr; \ |
| 299 | uint32_t sctlr; \ |
| 300 | \ |
| 301 | assert(IS_IN_EL(_el)); \ |
| 302 | assert((read_sctlr_el##_el() & SCTLR_M_BIT) == 0); \ |
| 303 | \ |
| 304 | /* Set attributes in the right indices of the MAIR */ \ |
| 305 | mair = MAIR_ATTR_SET(ATTR_DEVICE, ATTR_DEVICE_INDEX); \ |
| 306 | mair |= MAIR_ATTR_SET(ATTR_IWBWA_OWBWA_NTR, \ |
| 307 | ATTR_IWBWA_OWBWA_NTR_INDEX); \ |
| 308 | write_mair_el##_el(mair); \ |
| 309 | \ |
| 310 | /* Invalidate TLBs at the current exception level */ \ |
| 311 | _tlbi_fct(); \ |
| 312 | \ |
| 313 | /* Set TCR bits as well. */ \ |
| 314 | /* Inner & outer WBWA & shareable + T0SZ = 32 */ \ |
| 315 | tcr = TCR_SH_INNER_SHAREABLE | TCR_RGN_OUTER_WBA | \ |
Lin Ma | 741a382 | 2014-06-27 16:56:30 -0700 | [diff] [blame] | 316 | TCR_RGN_INNER_WBA | \ |
| 317 | (64 - __builtin_ctzl(ADDR_SPACE_SIZE)); \ |
Dan Handley | b226a4d | 2014-05-16 14:08:45 +0100 | [diff] [blame] | 318 | tcr |= _tcr_extra; \ |
| 319 | write_tcr_el##_el(tcr); \ |
| 320 | \ |
| 321 | /* Set TTBR bits as well */ \ |
| 322 | ttbr = (uint64_t) l1_xlation_table; \ |
| 323 | write_ttbr0_el##_el(ttbr); \ |
| 324 | \ |
| 325 | /* Ensure all translation table writes have drained */ \ |
| 326 | /* into memory, the TLB invalidation is complete, */ \ |
| 327 | /* and translation register writes are committed */ \ |
| 328 | /* before enabling the MMU */ \ |
| 329 | dsb(); \ |
| 330 | isb(); \ |
| 331 | \ |
| 332 | sctlr = read_sctlr_el##_el(); \ |
Achin Gupta | 9f09835 | 2014-07-18 18:38:28 +0100 | [diff] [blame] | 333 | sctlr |= SCTLR_WXN_BIT | SCTLR_M_BIT; \ |
Achin Gupta | e998254 | 2014-06-26 08:59:07 +0100 | [diff] [blame] | 334 | \ |
| 335 | if (flags & DISABLE_DCACHE) \ |
| 336 | sctlr &= ~SCTLR_C_BIT; \ |
| 337 | else \ |
| 338 | sctlr |= SCTLR_C_BIT; \ |
| 339 | \ |
Dan Handley | b226a4d | 2014-05-16 14:08:45 +0100 | [diff] [blame] | 340 | write_sctlr_el##_el(sctlr); \ |
| 341 | \ |
| 342 | /* Ensure the MMU enable takes effect immediately */ \ |
| 343 | isb(); \ |
| 344 | } |
| 345 | |
| 346 | /* Define EL1 and EL3 variants of the function enabling the MMU */ |
Lin Ma | 741a382 | 2014-06-27 16:56:30 -0700 | [diff] [blame] | 347 | DEFINE_ENABLE_MMU_EL(1, |
| 348 | (tcr_ps_bits << TCR_EL1_IPS_SHIFT), |
| 349 | tlbivmalle1) |
| 350 | DEFINE_ENABLE_MMU_EL(3, |
| 351 | TCR_EL3_RES1 | (tcr_ps_bits << TCR_EL3_PS_SHIFT), |
| 352 | tlbialle3) |