mpam.c 894 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright (c) 2018-2023, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stdbool.h>
  7. #include <arch.h>
  8. #include <arch_features.h>
  9. #include <arch_helpers.h>
  10. #include <lib/extensions/mpam.h>
  11. void mpam_enable_per_world(per_world_context_t *per_world_ctx)
  12. {
  13. u_register_t mpam3_el3;
  14. /*
  15. * Enable MPAM, and disable trapping to EL3 when lower ELs access their
  16. * own MPAM registers
  17. */
  18. mpam3_el3 = per_world_ctx->ctx_mpam3_el3;
  19. mpam3_el3 = (mpam3_el3 | MPAM3_EL3_MPAMEN_BIT) &
  20. ~(MPAM3_EL3_TRAPLOWER_BIT);
  21. per_world_ctx->ctx_mpam3_el3 = mpam3_el3;
  22. }
  23. /*
  24. * If EL2 is implemented but unused, disable trapping to EL2 when lower ELs
  25. * access their own MPAM registers.
  26. */
  27. void mpam_init_el2_unused(void)
  28. {
  29. write_mpam2_el2(0ULL);
  30. if ((read_mpamidr_el1() & MPAMIDR_HAS_HCR_BIT) != 0U) {
  31. write_mpamhcr_el2(0ULL);
  32. }
  33. }