enable_mpu.S 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (c) 2021, 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. #include <platform_def.h>
  10. .global enable_mpu_direct_el2
  11. /* void enable_mmu_direct_el2(unsigned int flags) */
  12. func enable_mpu_direct_el2
  13. #if ENABLE_ASSERTIONS
  14. mrs x1, sctlr_el2
  15. tst x1, #SCTLR_M_BIT
  16. ASM_ASSERT(eq)
  17. #endif
  18. mov x7, x0
  19. adrp x0, mmu_cfg_params
  20. add x0, x0, :lo12:mmu_cfg_params
  21. /* (MAIRs are already set up) */
  22. /* TCR */
  23. ldr x2, [x0, #(MMU_CFG_TCR << 3)]
  24. msr tcr_el2, x2
  25. /*
  26. * Ensure all translation table writes have drained into memory, the TLB
  27. * invalidation is complete, and translation register writes are
  28. * committed before enabling the MMU
  29. */
  30. dsb ish
  31. isb
  32. /* Set and clear required fields of SCTLR */
  33. mrs x4, sctlr_el2
  34. mov_imm x5, SCTLR_WXN_BIT | SCTLR_C_BIT | SCTLR_M_BIT
  35. orr x4, x4, x5
  36. /* Additionally, amend SCTLR fields based on flags */
  37. bic x5, x4, #SCTLR_C_BIT
  38. tst x7, #DISABLE_DCACHE
  39. csel x4, x5, x4, ne
  40. msr sctlr_el2, x4
  41. isb
  42. ret
  43. endfunc enable_mpu_direct_el2