psci_lib.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (c) 2017-2023, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef PSCI_LIB_H
  7. #define PSCI_LIB_H
  8. #include <common/ep_info.h>
  9. #ifndef __ASSEMBLER__
  10. #include <cdefs.h>
  11. #include <stdint.h>
  12. /*******************************************************************************
  13. * Optional structure populated by the Secure Payload Dispatcher to be given a
  14. * chance to perform any bookkeeping before PSCI executes a power management
  15. * operation. It also allows PSCI to determine certain properties of the SP e.g.
  16. * migrate capability etc.
  17. ******************************************************************************/
  18. typedef struct spd_pm_ops {
  19. void (*svc_on)(u_register_t target_cpu);
  20. int32_t (*svc_off)(u_register_t __unused unused);
  21. void (*svc_suspend)(u_register_t max_off_pwrlvl);
  22. void (*svc_on_finish)(u_register_t __unused unused);
  23. void (*svc_suspend_finish)(u_register_t max_off_pwrlvl);
  24. int32_t (*svc_migrate)(u_register_t from_cpu, u_register_t to_cpu);
  25. int32_t (*svc_migrate_info)(u_register_t *resident_cpu);
  26. void (*svc_system_off)(void);
  27. void (*svc_system_reset)(void);
  28. } spd_pm_ops_t;
  29. /*
  30. * Function prototype for the warmboot entrypoint function which will be
  31. * programmed in the mailbox by the platform.
  32. */
  33. typedef void (*mailbox_entrypoint_t)(void);
  34. /******************************************************************************
  35. * Structure to pass PSCI Library arguments.
  36. *****************************************************************************/
  37. typedef struct psci_lib_args {
  38. /* The version information of PSCI Library Interface */
  39. param_header_t h;
  40. /* The warm boot entrypoint function */
  41. mailbox_entrypoint_t mailbox_ep;
  42. } psci_lib_args_t;
  43. /* Helper macro to set the psci_lib_args_t structure at runtime */
  44. #define SET_PSCI_LIB_ARGS_V1(_p, _entry) do { \
  45. SET_PARAM_HEAD(_p, PARAM_PSCI_LIB_ARGS, VERSION_1, 0); \
  46. (_p)->mailbox_ep = (_entry); \
  47. } while (0)
  48. /* Helper macro to define the psci_lib_args_t statically */
  49. #define DEFINE_STATIC_PSCI_LIB_ARGS_V1(_name, _entry) \
  50. static const psci_lib_args_t (_name) = { \
  51. .h.type = (uint8_t)PARAM_PSCI_LIB_ARGS, \
  52. .h.version = (uint8_t)VERSION_1, \
  53. .h.size = (uint16_t)sizeof(_name), \
  54. .h.attr = 0U, \
  55. .mailbox_ep = (_entry) \
  56. }
  57. /* Helper macro to verify the pointer to psci_lib_args_t structure */
  58. #define VERIFY_PSCI_LIB_ARGS_V1(_p) (((_p) != NULL) \
  59. && ((_p)->h.type == PARAM_PSCI_LIB_ARGS) \
  60. && ((_p)->h.version == VERSION_1) \
  61. && ((_p)->h.size == sizeof(*(_p))) \
  62. && ((_p)->h.attr == 0) \
  63. && ((_p)->mailbox_ep != NULL))
  64. /******************************************************************************
  65. * PSCI Library Interfaces
  66. *****************************************************************************/
  67. u_register_t psci_smc_handler(uint32_t smc_fid,
  68. u_register_t x1,
  69. u_register_t x2,
  70. u_register_t x3,
  71. u_register_t x4,
  72. void *cookie,
  73. void *handle,
  74. u_register_t flags);
  75. int psci_setup(const psci_lib_args_t *lib_args);
  76. int psci_secondaries_brought_up(void);
  77. void psci_warmboot_entrypoint(void);
  78. void psci_register_spd_pm_hook(const spd_pm_ops_t *pm);
  79. void psci_prepare_next_non_secure_ctx(
  80. entry_point_info_t *next_image_info);
  81. int psci_stop_other_cores(unsigned int wait_ms,
  82. void (*stop_func)(u_register_t mpidr));
  83. bool psci_is_last_on_cpu_safe(void);
  84. bool psci_are_all_cpus_on_safe(void);
  85. void psci_pwrdown_cpu(unsigned int power_level);
  86. void psci_do_manage_extensions(void);
  87. #endif /* __ASSEMBLER__ */
  88. #endif /* PSCI_LIB_H */