tlkd_pm.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
  3. * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #include <assert.h>
  8. #include <arch_helpers.h>
  9. #include <bl32/payloads/tlk.h>
  10. #include <common/bl_common.h>
  11. #include <common/debug.h>
  12. #include <lib/el3_runtime/context_mgmt.h>
  13. #include <lib/psci/psci.h>
  14. #include "tlkd_private.h"
  15. extern tlk_context_t tlk_ctx;
  16. #define MPIDR_CPU0 0x80000000
  17. /*******************************************************************************
  18. * Return the type of payload TLKD is dealing with. Report the current
  19. * resident cpu (mpidr format) if it is a UP/UP migratable payload.
  20. ******************************************************************************/
  21. static int32_t cpu_migrate_info(u_register_t *resident_cpu)
  22. {
  23. /* the payload runs only on CPU0 */
  24. *resident_cpu = MPIDR_CPU0;
  25. /* Uniprocessor, not migrate capable payload */
  26. return PSCI_TOS_NOT_UP_MIG_CAP;
  27. }
  28. /*******************************************************************************
  29. * This cpu is being suspended. Inform TLK of the SYSTEM_SUSPEND event, so
  30. * that it can pass this information to its Trusted Apps.
  31. ******************************************************************************/
  32. static void cpu_suspend_handler(u_register_t suspend_level)
  33. {
  34. gp_regs_t *gp_regs;
  35. int cpu = read_mpidr() & MPIDR_CPU_MASK;
  36. int32_t rc = 0;
  37. /*
  38. * TLK runs only on CPU0 and suspends its Trusted Apps during
  39. * SYSTEM_SUSPEND. It has no role to play during CPU_SUSPEND.
  40. */
  41. if ((cpu != 0) || (suspend_level != PLAT_MAX_PWR_LVL))
  42. return;
  43. /* pass system suspend event to TLK */
  44. gp_regs = get_gpregs_ctx(&tlk_ctx.cpu_ctx);
  45. write_ctx_reg(gp_regs, CTX_GPREG_X0, TLK_SYSTEM_SUSPEND);
  46. /* Program the entry point and enter TLK */
  47. rc = tlkd_synchronous_sp_entry(&tlk_ctx);
  48. /*
  49. * Read the response from TLK. A non-zero return means that
  50. * something went wrong while communicating with it.
  51. */
  52. if (rc != 0)
  53. panic();
  54. }
  55. /*******************************************************************************
  56. * This cpu is being resumed. Inform TLK of the SYSTEM_SUSPEND exit, so
  57. * that it can pass this information to its Trusted Apps.
  58. ******************************************************************************/
  59. static void cpu_resume_handler(u_register_t suspend_level)
  60. {
  61. gp_regs_t *gp_regs;
  62. int cpu = read_mpidr() & MPIDR_CPU_MASK;
  63. int32_t rc = 0;
  64. /*
  65. * TLK runs only on CPU0 and resumes its Trusted Apps during
  66. * SYSTEM_SUSPEND exit. It has no role to play during CPU_SUSPEND
  67. * exit.
  68. */
  69. if ((cpu != 0) || (suspend_level != PLAT_MAX_PWR_LVL))
  70. return;
  71. /* pass system resume event to TLK */
  72. gp_regs = get_gpregs_ctx(&tlk_ctx.cpu_ctx);
  73. write_ctx_reg(gp_regs, CTX_GPREG_X0, TLK_SYSTEM_RESUME);
  74. /* Program the entry point and enter TLK */
  75. rc = tlkd_synchronous_sp_entry(&tlk_ctx);
  76. /*
  77. * Read the response from TLK. A non-zero return means that
  78. * something went wrong while communicating with it.
  79. */
  80. if (rc != 0)
  81. panic();
  82. }
  83. /*******************************************************************************
  84. * Structure populated by the Dispatcher to be given a chance to perform any
  85. * bookkeeping before PSCI executes a power mgmt. operation.
  86. ******************************************************************************/
  87. const spd_pm_ops_t tlkd_pm_ops = {
  88. .svc_migrate_info = cpu_migrate_info,
  89. .svc_suspend = cpu_suspend_handler,
  90. .svc_suspend_finish = cpu_resume_handler,
  91. };