fvp_r_context_mgmt.c 1.7 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 <arch_helpers.h>
  7. /************************************************************
  8. * For R-class everything is in secure world.
  9. * Prepare the CPU system registers for first entry into EL1
  10. ************************************************************/
  11. void cm_prepare_el2_exit(void)
  12. {
  13. uint64_t hcr_el2 = 0U;
  14. /*
  15. * The use of ARMv8.3 pointer authentication (PAuth) is governed
  16. * by fields in HCR_EL2, which trigger a 'trap to EL2' if not
  17. * enabled. This register initialized at boot up, update PAuth
  18. * bits.
  19. *
  20. * HCR_API_BIT: Set to one to disable traps to EL2 if lower ELs
  21. * access PAuth registers
  22. *
  23. * HCR_APK_BIT: Set to one to disable traps to EL2 if lower ELs
  24. * access PAuth instructions
  25. */
  26. hcr_el2 = read_hcr_el2();
  27. write_hcr_el2(hcr_el2 | HCR_API_BIT | HCR_APK_BIT);
  28. /*
  29. * Initialise CNTHCTL_EL2. All fields are architecturally UNKNOWN
  30. * on reset and are set to zero except for field(s) listed below.
  31. *
  32. * CNTHCTL_EL2.EL1PCEN: Set to one to disable traps to EL2
  33. * if lower ELs accesses to the physical timer registers.
  34. *
  35. * CNTHCTL_EL2.EL1PCTEN: Set to one to disable traps to EL2
  36. * if lower ELs access to the physical counter registers.
  37. */
  38. write_cnthctl_el2(CNTHCTL_RESET_VAL | EL1PCEN_BIT | EL1PCTEN_BIT);
  39. /*
  40. * On Armv8-R, the EL1&0 memory system architecture is configurable
  41. * as a VMSA or PMSA. All the fields architecturally UNKNOWN on reset
  42. * and are set to zero except for field listed below.
  43. *
  44. * VCTR_EL2.MSA: Set to one to ensure the VMSA is enabled so that
  45. * rich OS can boot.
  46. */
  47. write_vtcr_el2(VTCR_RESET_VAL | VTCR_EL2_MSA);
  48. }