bl31_context_mgmt.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) 2013-2021, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <bl31/bl31.h>
  8. #include <common/bl_common.h>
  9. #include <context.h>
  10. #include <lib/el3_runtime/context_mgmt.h>
  11. #include <lib/el3_runtime/cpu_data.h>
  12. /*******************************************************************************
  13. * This function returns a pointer to the most recent 'cpu_context' structure
  14. * for the calling CPU that was set as the context for the specified security
  15. * state. NULL is returned if no such structure has been specified.
  16. ******************************************************************************/
  17. void *cm_get_context(uint32_t security_state)
  18. {
  19. assert(sec_state_is_valid(security_state));
  20. return get_cpu_data(cpu_context[get_cpu_context_index(security_state)]);
  21. }
  22. /*******************************************************************************
  23. * This function sets the pointer to the current 'cpu_context' structure for the
  24. * specified security state for the calling CPU
  25. ******************************************************************************/
  26. void cm_set_context(void *context, uint32_t security_state)
  27. {
  28. assert(sec_state_is_valid(security_state));
  29. set_cpu_data(cpu_context[get_cpu_context_index(security_state)],
  30. context);
  31. }
  32. /*******************************************************************************
  33. * This function returns a pointer to the most recent 'cpu_context' structure
  34. * for the CPU identified by `cpu_idx` that was set as the context for the
  35. * specified security state. NULL is returned if no such structure has been
  36. * specified.
  37. ******************************************************************************/
  38. void *cm_get_context_by_index(unsigned int cpu_idx,
  39. unsigned int security_state)
  40. {
  41. assert(sec_state_is_valid(security_state));
  42. return get_cpu_data_by_index(cpu_idx,
  43. cpu_context[get_cpu_context_index(security_state)]);
  44. }
  45. /*******************************************************************************
  46. * This function sets the pointer to the current 'cpu_context' structure for the
  47. * specified security state for the CPU identified by CPU index.
  48. ******************************************************************************/
  49. void cm_set_context_by_index(unsigned int cpu_idx, void *context,
  50. unsigned int security_state)
  51. {
  52. assert(sec_state_is_valid(security_state));
  53. set_cpu_data_by_index(cpu_idx,
  54. cpu_context[get_cpu_context_index(security_state)],
  55. context);
  56. }