axg_pm.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Copyright (c) 2020, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch_helpers.h>
  7. #include <assert.h>
  8. #include <common/debug.h>
  9. #include <drivers/arm/gicv2.h>
  10. #include <drivers/console.h>
  11. #include <errno.h>
  12. #include <lib/mmio.h>
  13. #include <lib/psci/psci.h>
  14. #include <plat/common/platform.h>
  15. #include <platform_def.h>
  16. #include "aml_private.h"
  17. #define SCPI_POWER_ON 0
  18. #define SCPI_POWER_RETENTION 1
  19. #define SCPI_POWER_OFF 3
  20. #define SCPI_SYSTEM_SHUTDOWN 0
  21. #define SCPI_SYSTEM_REBOOT 1
  22. static uintptr_t axg_sec_entrypoint;
  23. static void axg_pm_set_reset_addr(u_register_t mpidr, uint64_t value)
  24. {
  25. unsigned int core = plat_calc_core_pos(mpidr);
  26. uintptr_t cpu_mailbox_addr = AML_PSCI_MAILBOX_BASE + (core << 4);
  27. mmio_write_64(cpu_mailbox_addr, value);
  28. }
  29. static void axg_pm_reset(u_register_t mpidr, uint32_t value)
  30. {
  31. unsigned int core = plat_calc_core_pos(mpidr);
  32. uintptr_t cpu_mailbox_addr = AML_PSCI_MAILBOX_BASE + (core << 4) + 8;
  33. mmio_write_32(cpu_mailbox_addr, value);
  34. }
  35. static void __dead2 axg_system_reset(void)
  36. {
  37. u_register_t mpidr = read_mpidr_el1();
  38. int ret;
  39. INFO("BL31: PSCI_SYSTEM_RESET\n");
  40. ret = aml_scpi_sys_power_state(SCPI_SYSTEM_REBOOT);
  41. if (ret != 0) {
  42. ERROR("BL31: PSCI_SYSTEM_RESET: SCP error: %i\n", ret);
  43. panic();
  44. }
  45. axg_pm_reset(mpidr, 0);
  46. wfi();
  47. ERROR("BL31: PSCI_SYSTEM_RESET: Operation not handled\n");
  48. panic();
  49. }
  50. static void __dead2 axg_system_off(void)
  51. {
  52. u_register_t mpidr = read_mpidr_el1();
  53. int ret;
  54. INFO("BL31: PSCI_SYSTEM_OFF\n");
  55. ret = aml_scpi_sys_power_state(SCPI_SYSTEM_SHUTDOWN);
  56. if (ret != 0) {
  57. ERROR("BL31: PSCI_SYSTEM_OFF: SCP error %i\n", ret);
  58. panic();
  59. }
  60. axg_pm_set_reset_addr(mpidr, 0);
  61. axg_pm_reset(mpidr, 0);
  62. dmbsy();
  63. wfi();
  64. ERROR("BL31: PSCI_SYSTEM_OFF: Operation not handled\n");
  65. panic();
  66. }
  67. static int32_t axg_pwr_domain_on(u_register_t mpidr)
  68. {
  69. axg_pm_set_reset_addr(mpidr, axg_sec_entrypoint);
  70. aml_scpi_set_css_power_state(mpidr,
  71. SCPI_POWER_ON, SCPI_POWER_ON, SCPI_POWER_ON);
  72. dmbsy();
  73. sev();
  74. return PSCI_E_SUCCESS;
  75. }
  76. static void axg_pwr_domain_on_finish(const psci_power_state_t *target_state)
  77. {
  78. assert(target_state->pwr_domain_state[MPIDR_AFFLVL0] ==
  79. PLAT_LOCAL_STATE_OFF);
  80. gicv2_pcpu_distif_init();
  81. gicv2_cpuif_enable();
  82. axg_pm_set_reset_addr(read_mpidr_el1(), 0);
  83. }
  84. static void axg_pwr_domain_off(const psci_power_state_t *target_state)
  85. {
  86. u_register_t mpidr = read_mpidr_el1();
  87. uint32_t system_state = SCPI_POWER_ON;
  88. uint32_t cluster_state = SCPI_POWER_ON;
  89. assert(target_state->pwr_domain_state[MPIDR_AFFLVL0] ==
  90. PLAT_LOCAL_STATE_OFF);
  91. axg_pm_reset(mpidr, -1);
  92. gicv2_cpuif_disable();
  93. if (target_state->pwr_domain_state[MPIDR_AFFLVL2] ==
  94. PLAT_LOCAL_STATE_OFF)
  95. system_state = SCPI_POWER_OFF;
  96. if (target_state->pwr_domain_state[MPIDR_AFFLVL1] ==
  97. PLAT_LOCAL_STATE_OFF)
  98. cluster_state = SCPI_POWER_OFF;
  99. aml_scpi_set_css_power_state(mpidr,
  100. SCPI_POWER_OFF, cluster_state,
  101. system_state);
  102. }
  103. static void __dead2 axg_pwr_domain_pwr_down_wfi(const psci_power_state_t
  104. *target_state)
  105. {
  106. dsbsy();
  107. axg_pm_reset(read_mpidr_el1(), 0);
  108. for (;;)
  109. wfi();
  110. }
  111. /*******************************************************************************
  112. * Platform handlers and setup function.
  113. ******************************************************************************/
  114. static const plat_psci_ops_t axg_ops = {
  115. .pwr_domain_on = axg_pwr_domain_on,
  116. .pwr_domain_on_finish = axg_pwr_domain_on_finish,
  117. .pwr_domain_off = axg_pwr_domain_off,
  118. .pwr_domain_pwr_down_wfi = axg_pwr_domain_pwr_down_wfi,
  119. .system_off = axg_system_off,
  120. .system_reset = axg_system_reset
  121. };
  122. int plat_setup_psci_ops(uintptr_t sec_entrypoint,
  123. const plat_psci_ops_t **psci_ops)
  124. {
  125. axg_sec_entrypoint = sec_entrypoint;
  126. *psci_ops = &axg_ops;
  127. return 0;
  128. }