enable_mmu.S 2.1 KB

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