xlat_mpu_context.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <common/debug.h>
  8. #include "lib/xlat_mpu/xlat_mpu.h"
  9. #include <lib/xlat_tables/xlat_tables_defs.h>
  10. #include <lib/xlat_tables/xlat_tables_v2.h>
  11. #include "xlat_mpu_private.h"
  12. #include <fvp_r_arch_helpers.h>
  13. #include <platform_def.h>
  14. #warning "xlat_mpu library is currently experimental and its API may change in future."
  15. /*
  16. * MMU configuration register values for the active translation context. Used
  17. * from the MMU assembly helpers.
  18. */
  19. uint64_t mmu_cfg_params[MMU_CFG_PARAM_MAX];
  20. /*
  21. * Allocate and initialise the default translation context for the BL image
  22. * currently executing.
  23. */
  24. REGISTER_XLAT_CONTEXT(tf, MAX_MMAP_REGIONS, MAX_XLAT_TABLES,
  25. PLAT_VIRT_ADDR_SPACE_SIZE, PLAT_PHY_ADDR_SPACE_SIZE);
  26. void mmap_add(const mmap_region_t *mm)
  27. {
  28. mmap_add_ctx(&tf_xlat_ctx, mm);
  29. }
  30. void __init init_xlat_tables(void)
  31. {
  32. assert(tf_xlat_ctx.xlat_regime == EL_REGIME_INVALID);
  33. unsigned int current_el = xlat_arch_current_el();
  34. if (current_el == 1U) {
  35. tf_xlat_ctx.xlat_regime = EL1_EL0_REGIME;
  36. } else {
  37. assert(current_el == 2U);
  38. tf_xlat_ctx.xlat_regime = EL2_REGIME;
  39. }
  40. /* Note: If EL3 is supported in future v8-R64, add EL3 assignment */
  41. init_xlat_tables_ctx(&tf_xlat_ctx);
  42. }
  43. int xlat_get_mem_attributes(uintptr_t base_va, uint32_t *attr)
  44. {
  45. return xlat_get_mem_attributes_ctx(&tf_xlat_ctx, base_va, attr);
  46. }
  47. void enable_mpu_el2(unsigned int flags)
  48. {
  49. /* EL2 is strictly MPU on v8-R64, so no need for setup_mpu_cfg() */
  50. enable_mpu_direct_el2(flags);
  51. }