psci.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-09-09 GuEe-GUI The first version
  9. */
  10. #ifndef __PSCI_H__
  11. #define __PSCI_H__
  12. #include <stdint.h>
  13. /*
  14. * Non-Confidential PSCI 1.0 release (30 January 2015), and errata fix for PSCI 0.2, unsupport PSCI 0.1
  15. */
  16. #define PSCI_VER_0_2 0x00000002
  17. #define PSCI_METHOD_SMC 3
  18. #define PSCI_METHOD_HVC 2
  19. /* PSCI 0.2 interface */
  20. #define PSCI_0_2_FN_BASE 0x84000000
  21. #define PSCI_0_2_FN(n) (PSCI_0_2_FN_BASE + (n))
  22. #define PSCI_0_2_FN_END 0x8400001F
  23. #define PSCI_0_2_FN64_BASE 0xC4000000
  24. #define PSCI_0_2_FN64(n) (PSCI_0_2_FN64_BASE + (n))
  25. #define PSCI_0_2_FN64_END 0xC400001F
  26. #define PSCI_0_2_FN_PSCI_VERSION PSCI_0_2_FN(0)
  27. #define PSCI_0_2_FN_CPU_SUSPEND PSCI_0_2_FN(1)
  28. #define PSCI_0_2_FN_CPU_OFF PSCI_0_2_FN(2)
  29. #define PSCI_0_2_FN_CPU_ON PSCI_0_2_FN(3)
  30. #define PSCI_0_2_FN_AFFINITY_INFO PSCI_0_2_FN(4)
  31. #define PSCI_0_2_FN_MIGRATE PSCI_0_2_FN(5)
  32. #define PSCI_0_2_FN_MIGRATE_INFO_TYPE PSCI_0_2_FN(6)
  33. #define PSCI_0_2_FN_MIGRATE_INFO_UP_CPU PSCI_0_2_FN(7)
  34. #define PSCI_0_2_FN_SYSTEM_OFF PSCI_0_2_FN(8)
  35. #define PSCI_0_2_FN_SYSTEM_RESET PSCI_0_2_FN(9)
  36. #define PSCI_0_2_FN64_CPU_SUSPEND PSCI_0_2_FN64(1)
  37. #define PSCI_0_2_FN64_CPU_ON PSCI_0_2_FN64(3)
  38. #define PSCI_0_2_FN64_AFFINITY_INFO PSCI_0_2_FN64(4)
  39. #define PSCI_0_2_FN64_MIGRATE PSCI_0_2_FN64(5)
  40. #define PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU PSCI_0_2_FN64(7)
  41. /* PSCI 1.0 interface */
  42. #define PSCI_1_0_FN_PSCI_FEATURES PSCI_0_2_FN(10)
  43. #define PSCI_1_0_FN_CPU_FREEZE PSCI_0_2_FN(11)
  44. #define PSCI_1_0_FN_CPU_DEFAULT_SUSPEND PSCI_0_2_FN(12)
  45. #define PSCI_1_0_FN_NODE_HW_STATE PSCI_0_2_FN(13)
  46. #define PSCI_1_0_FN_SYSTEM_SUSPEND PSCI_0_2_FN(14)
  47. #define PSCI_1_0_FN_SET_SUSPEND_MODE PSCI_0_2_FN(15)
  48. #define PSCI_1_0_FN_STAT_RESIDENCY PSCI_0_2_FN(16)
  49. #define PSCI_1_0_FN_STAT_COUNT PSCI_0_2_FN(17)
  50. #define PSCI_1_0_FN64_CPU_DEFAULT_SUSPEND PSCI_0_2_FN64(12)
  51. #define PSCI_1_0_FN64_NODE_HW_STATE PSCI_0_2_FN64(13)
  52. #define PSCI_1_0_FN64_SYSTEM_SUSPEND PSCI_0_2_FN64(14)
  53. #define PSCI_1_0_FN64_STAT_RESIDENCY PSCI_0_2_FN64(16)
  54. #define PSCI_1_0_FN64_STAT_COUNT PSCI_0_2_FN64(17)
  55. /* 1KB stack per core */
  56. #define PSCI_STACK_SHIFT 10
  57. #define PSCI_STACK_SIZE (1 << PSCI_STACK_SHIFT)
  58. /* PSCI affinity level state returned by AFFINITY_INFO */
  59. #define PSCI_AFFINITY_LEVEL_ON 0
  60. #define PSCI_AFFINITY_LEVEL_OFF 1
  61. #define PSCI_AFFINITY_LEVEL_ON_PENDING 2
  62. /*
  63. * PSCI power state
  64. * power_level:
  65. * Level 0: cores
  66. * Level 1: clusters
  67. * Level 2: system
  68. * state_type:
  69. * value 0: standby or retention state
  70. * value 1: powerdown state(entry and context_id is valid)
  71. * state_id:
  72. * StateID
  73. */
  74. #define PSCI_POWER_STATE(power_level, state_type, state_id) \
  75. ( \
  76. ((power_level) << 24) | \
  77. ((state_type) << 16) | \
  78. ((state_id) << 24) \
  79. )
  80. /*
  81. * For system, cluster, core
  82. * 0: run
  83. * 1: standby(only core)
  84. * 2: retention
  85. * 3: powerdown
  86. */
  87. #define PSCI_POWER_STATE_ID(state_id_power_level, system, cluster, core) \
  88. ( \
  89. ((state_id_power_level) << 12) | \
  90. ((system) << 8) | \
  91. ((cluster) << 4) | \
  92. (core) \
  93. )
  94. #define PSCI_RET_SUCCESS 0
  95. #define PSCI_RET_NOT_SUPPORTED (-1)
  96. #define PSCI_RET_INVALID_PARAMETERS (-2)
  97. #define PSCI_RET_DENIED (-3)
  98. #define PSCI_RET_ALREADY_ON (-4)
  99. #define PSCI_RET_ON_PENDING (-5)
  100. #define PSCI_RET_INTERNAL_FAILURE (-6)
  101. #define PSCI_RET_NOT_PRESENT (-7)
  102. #define PSCI_RET_DISABLED (-8)
  103. #define PSCI_RET_INVALID_ADDRESS (-9)
  104. void arm_psci_init(uint64_t method, uint64_t *platform_shutdown_args, uint64_t *platform_reboot_args);
  105. uint32_t arm_psci_get_version();
  106. uint32_t arm_psci_get_affinity_info(uint64_t target_affinity, uint64_t lowest_affinity_level);
  107. uint32_t arm_psci_get_feature(uint32_t psci_func_id);
  108. uint32_t arm_psci_cpu_off(uint64_t state);
  109. uint32_t arm_psci_cpu_on(uint64_t mpid, uint64_t entry);
  110. uint32_t arm_psci_cpu_suspend(uint32_t power_state, uint64_t entry);
  111. void arm_psci_system_off();
  112. void arm_psci_system_reboot();
  113. #endif /*__PSCI_H__*/