xlat_mpu_arch.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) 2021-2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <stdbool.h>
  8. #include <stdint.h>
  9. #include "../xlat_mpu_private.h"
  10. #include <arch.h>
  11. #include <arch_features.h>
  12. #include <lib/cassert.h>
  13. #include <lib/utils_def.h>
  14. #include <lib/xlat_tables/xlat_tables_v2.h>
  15. #include <fvp_r_arch_helpers.h>
  16. #warning "xlat_mpu library is currently experimental and its API may change in future."
  17. #if ENABLE_ASSERTIONS
  18. /*
  19. * Return minimum virtual address space size supported by the architecture
  20. */
  21. uintptr_t xlat_get_min_virt_addr_space_size(void)
  22. {
  23. uintptr_t ret;
  24. if (is_feat_ttst_present()) {
  25. ret = MIN_VIRT_ADDR_SPACE_SIZE_TTST;
  26. } else {
  27. ret = MIN_VIRT_ADDR_SPACE_SIZE;
  28. }
  29. return ret;
  30. }
  31. #endif /* ENABLE_ASSERTIONS*/
  32. bool is_mpu_enabled_ctx(const xlat_ctx_t *ctx)
  33. {
  34. if (ctx->xlat_regime == EL1_EL0_REGIME) {
  35. assert(xlat_arch_current_el() >= 1U);
  36. return (read_sctlr_el1() & SCTLR_M_BIT) != 0U;
  37. } else {
  38. assert(xlat_arch_current_el() >= 2U);
  39. return (read_sctlr_el2() & SCTLR_M_BIT) != 0U;
  40. }
  41. }
  42. bool is_dcache_enabled(void)
  43. {
  44. unsigned int el = get_current_el();
  45. if (el == 1U) {
  46. return (read_sctlr_el1() & SCTLR_C_BIT) != 0U;
  47. } else { /* must be EL2 */
  48. return (read_sctlr_el2() & SCTLR_C_BIT) != 0U;
  49. }
  50. }
  51. unsigned int xlat_arch_current_el(void)
  52. {
  53. unsigned int el = (unsigned int)GET_EL(read_CurrentEl());
  54. assert(el > 0U);
  55. return el;
  56. }