Jeenu Viswambharan | 58e8148 | 2018-04-27 15:06:57 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <asm_macros.S> |
| 8 | #include <assert_macros.S> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | #include <lib/xlat_tables/xlat_tables_v2.h> |
Jeenu Viswambharan | 58e8148 | 2018-04-27 15:06:57 +0100 | [diff] [blame] | 10 | |
| 11 | .global enable_mmu_direct_el1 |
Antonio Nino Diaz | 128de8d | 2018-08-07 19:59:49 +0100 | [diff] [blame] | 12 | .global enable_mmu_direct_el2 |
Jeenu Viswambharan | 58e8148 | 2018-04-27 15:06:57 +0100 | [diff] [blame] | 13 | .global enable_mmu_direct_el3 |
| 14 | |
| 15 | /* Macros to read and write to system register for a given EL. */ |
| 16 | .macro _msr reg_name, el, gp_reg |
| 17 | msr \reg_name\()_el\()\el, \gp_reg |
| 18 | .endm |
| 19 | |
| 20 | .macro _mrs gp_reg, reg_name, el |
| 21 | mrs \gp_reg, \reg_name\()_el\()\el |
| 22 | .endm |
| 23 | |
Antonio Nino Diaz | 128de8d | 2018-08-07 19:59:49 +0100 | [diff] [blame] | 24 | .macro tlbi_invalidate_all el |
| 25 | .if \el == 1 |
| 26 | TLB_INVALIDATE(vmalle1) |
| 27 | .elseif \el == 2 |
| 28 | TLB_INVALIDATE(alle2) |
| 29 | .elseif \el == 3 |
| 30 | TLB_INVALIDATE(alle3) |
| 31 | .else |
| 32 | .error "EL must be 1, 2 or 3" |
| 33 | .endif |
| 34 | .endm |
| 35 | |
| 36 | /* void enable_mmu_direct_el<x>(unsigned int flags) */ |
Jeenu Viswambharan | 58e8148 | 2018-04-27 15:06:57 +0100 | [diff] [blame] | 37 | .macro define_mmu_enable_func el |
| 38 | func enable_mmu_direct_\()el\el |
| 39 | #if ENABLE_ASSERTIONS |
| 40 | _mrs x1, sctlr, \el |
| 41 | tst x1, #SCTLR_M_BIT |
| 42 | ASM_ASSERT(eq) |
| 43 | #endif |
Antonio Nino Diaz | 128de8d | 2018-08-07 19:59:49 +0100 | [diff] [blame] | 44 | /* Invalidate all TLB entries */ |
| 45 | tlbi_invalidate_all \el |
Jeenu Viswambharan | 58e8148 | 2018-04-27 15:06:57 +0100 | [diff] [blame] | 46 | |
| 47 | mov x7, x0 |
Soby Mathew | fcaf1bd | 2018-10-12 16:40:28 +0100 | [diff] [blame] | 48 | adrp x0, mmu_cfg_params |
| 49 | add x0, x0, :lo12:mmu_cfg_params |
Jeenu Viswambharan | 58e8148 | 2018-04-27 15:06:57 +0100 | [diff] [blame] | 50 | |
| 51 | /* MAIR */ |
Antonio Nino Diaz | 668d9ee | 2018-07-12 15:44:42 +0100 | [diff] [blame] | 52 | ldr x1, [x0, #(MMU_CFG_MAIR << 3)] |
Jeenu Viswambharan | 58e8148 | 2018-04-27 15:06:57 +0100 | [diff] [blame] | 53 | _msr mair, \el, x1 |
| 54 | |
| 55 | /* TCR */ |
Antonio Nino Diaz | 668d9ee | 2018-07-12 15:44:42 +0100 | [diff] [blame] | 56 | ldr x2, [x0, #(MMU_CFG_TCR << 3)] |
Jeenu Viswambharan | 58e8148 | 2018-04-27 15:06:57 +0100 | [diff] [blame] | 57 | _msr tcr, \el, x2 |
| 58 | |
| 59 | /* TTBR */ |
Antonio Nino Diaz | 668d9ee | 2018-07-12 15:44:42 +0100 | [diff] [blame] | 60 | ldr x3, [x0, #(MMU_CFG_TTBR0 << 3)] |
Jeenu Viswambharan | 58e8148 | 2018-04-27 15:06:57 +0100 | [diff] [blame] | 61 | _msr ttbr0, \el, x3 |
| 62 | |
| 63 | /* |
| 64 | * Ensure all translation table writes have drained into memory, the TLB |
| 65 | * invalidation is complete, and translation register writes are |
| 66 | * committed before enabling the MMU |
| 67 | */ |
| 68 | dsb ish |
| 69 | isb |
| 70 | |
| 71 | /* Set and clear required fields of SCTLR */ |
| 72 | _mrs x4, sctlr, \el |
| 73 | mov_imm x5, SCTLR_WXN_BIT | SCTLR_C_BIT | SCTLR_M_BIT |
| 74 | orr x4, x4, x5 |
| 75 | |
| 76 | /* Additionally, amend SCTLR fields based on flags */ |
| 77 | bic x5, x4, #SCTLR_C_BIT |
| 78 | tst x7, #DISABLE_DCACHE |
| 79 | csel x4, x5, x4, ne |
| 80 | |
| 81 | _msr sctlr, \el, x4 |
| 82 | isb |
| 83 | |
| 84 | ret |
| 85 | endfunc enable_mmu_direct_\()el\el |
| 86 | .endm |
| 87 | |
| 88 | /* |
Antonio Nino Diaz | 32958ce | 2019-01-25 13:12:07 +0000 | [diff] [blame] | 89 | * Define MMU-enabling functions for EL1, EL2 and EL3: |
Jeenu Viswambharan | 58e8148 | 2018-04-27 15:06:57 +0100 | [diff] [blame] | 90 | * |
| 91 | * enable_mmu_direct_el1 |
Antonio Nino Diaz | 32958ce | 2019-01-25 13:12:07 +0000 | [diff] [blame] | 92 | * enable_mmu_direct_el2 |
Jeenu Viswambharan | 58e8148 | 2018-04-27 15:06:57 +0100 | [diff] [blame] | 93 | * enable_mmu_direct_el3 |
| 94 | */ |
| 95 | define_mmu_enable_func 1 |
Antonio Nino Diaz | 128de8d | 2018-08-07 19:59:49 +0100 | [diff] [blame] | 96 | define_mmu_enable_func 2 |
Jeenu Viswambharan | 58e8148 | 2018-04-27 15:06:57 +0100 | [diff] [blame] | 97 | define_mmu_enable_func 3 |