plat_psci.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * Copyright (c) 2018-2020, Arm Limited and Contributors. All rights reserved.
  3. * Copyright (c) 2021-2022, Xilinx, Inc. All rights reserved.
  4. * Copyright (c) 2022-2023, Advanced Micro Devices, Inc. All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #include <assert.h>
  9. #include <common/debug.h>
  10. #include <common/runtime_svc.h>
  11. #include <lib/mmio.h>
  12. #include <lib/psci/psci.h>
  13. #include <plat/arm/common/plat_arm.h>
  14. #include <plat/common/platform.h>
  15. #include <plat_arm.h>
  16. #include <plat_private.h>
  17. #include <pm_defs.h>
  18. #define PM_RET_ERROR_NOFEATURE U(19)
  19. static uintptr_t versal_net_sec_entry;
  20. static void zynqmp_cpu_standby(plat_local_state_t cpu_state)
  21. {
  22. dsb();
  23. wfi();
  24. }
  25. static int32_t zynqmp_nopmu_pwr_domain_on(u_register_t mpidr)
  26. {
  27. uint32_t cpu_id = plat_core_pos_by_mpidr(mpidr);
  28. uint32_t cpu = cpu_id % PLATFORM_CORE_COUNT_PER_CLUSTER;
  29. uint32_t cluster = cpu_id / PLATFORM_CORE_COUNT_PER_CLUSTER;
  30. uintptr_t apu_cluster_base = 0, apu_pcli_base, apu_pcli_cluster = 0;
  31. uintptr_t rst_apu_cluster = PSX_CRF + RST_APU0_OFFSET + (cluster * 0x4);
  32. VERBOSE("%s: mpidr: 0x%lx, cpuid: %x, cpu: %x, cluster: %x\n",
  33. __func__, mpidr, cpu_id, cpu, cluster);
  34. if (cpu_id == -1) {
  35. return PSCI_E_INTERN_FAIL;
  36. }
  37. if (platform_id == VERSAL_NET_SPP && cluster > 1) {
  38. panic();
  39. }
  40. if (cluster > 3) {
  41. panic();
  42. }
  43. apu_pcli_cluster = APU_PCLI + APU_PCLI_CLUSTER_OFFSET + (cluster * APU_PCLI_CLUSTER_STEP);
  44. apu_cluster_base = APU_CLUSTER0 + (cluster * APU_CLUSTER_STEP);
  45. /* Enable clock */
  46. mmio_setbits_32(PSX_CRF + ACPU0_CLK_CTRL + (cluster * 0x4), ACPU_CLK_CTRL_CLKACT);
  47. /* Enable cluster states */
  48. mmio_setbits_32(apu_pcli_cluster + PCLI_PSTATE_OFFSET, PCLI_PSTATE_VAL_SET);
  49. mmio_setbits_32(apu_pcli_cluster + PCLI_PREQ_OFFSET, PREQ_CHANGE_REQUEST);
  50. /* assert core reset */
  51. mmio_setbits_32(rst_apu_cluster, ((RST_APU_COLD_RESET|RST_APU_WARN_RESET) << cpu));
  52. /* program RVBAR */
  53. mmio_write_32(apu_cluster_base + APU_RVBAR_L_0 + (cpu << 3),
  54. (uint32_t)versal_net_sec_entry);
  55. mmio_write_32(apu_cluster_base + APU_RVBAR_H_0 + (cpu << 3),
  56. versal_net_sec_entry >> 32);
  57. /* de-assert core reset */
  58. mmio_clrbits_32(rst_apu_cluster, ((RST_APU_COLD_RESET|RST_APU_WARN_RESET) << cpu));
  59. /* clear cluster resets */
  60. mmio_clrbits_32(rst_apu_cluster, RST_APU_CLUSTER_WARM_RESET);
  61. mmio_clrbits_32(rst_apu_cluster, RST_APU_CLUSTER_COLD_RESET);
  62. apu_pcli_base = APU_PCLI + (APU_PCLI_CPU_STEP * cpu) +
  63. (APU_PCLI_CLUSTER_CPU_STEP * cluster);
  64. mmio_write_32(apu_pcli_base + PCLI_PSTATE_OFFSET, PCLI_PSTATE_VAL_CLEAR);
  65. mmio_write_32(apu_pcli_base + PCLI_PREQ_OFFSET, PREQ_CHANGE_REQUEST);
  66. return PSCI_E_SUCCESS;
  67. }
  68. static void zynqmp_nopmu_pwr_domain_off(const psci_power_state_t *target_state)
  69. {
  70. }
  71. static void __dead2 zynqmp_nopmu_system_reset(void)
  72. {
  73. while (1)
  74. wfi();
  75. }
  76. static int32_t zynqmp_validate_ns_entrypoint(uint64_t ns_entrypoint)
  77. {
  78. return PSCI_E_SUCCESS;
  79. }
  80. static void zynqmp_pwr_domain_suspend(const psci_power_state_t *target_state)
  81. {
  82. }
  83. static void zynqmp_pwr_domain_on_finish(const psci_power_state_t *target_state)
  84. {
  85. plat_arm_gic_pcpu_init();
  86. plat_arm_gic_cpuif_enable();
  87. }
  88. static void zynqmp_pwr_domain_suspend_finish(const psci_power_state_t *target_state)
  89. {
  90. }
  91. static void __dead2 zynqmp_system_off(void)
  92. {
  93. while (1)
  94. wfi();
  95. }
  96. static int32_t zynqmp_validate_power_state(uint32_t power_state, psci_power_state_t *req_state)
  97. {
  98. return PSCI_E_SUCCESS;
  99. }
  100. static void zynqmp_get_sys_suspend_power_state(psci_power_state_t *req_state)
  101. {
  102. req_state->pwr_domain_state[PSCI_CPU_PWR_LVL] = PLAT_MAX_OFF_STATE;
  103. req_state->pwr_domain_state[1] = PLAT_MAX_OFF_STATE;
  104. }
  105. static const struct plat_psci_ops versal_net_nopmc_psci_ops = {
  106. .cpu_standby = zynqmp_cpu_standby,
  107. .pwr_domain_on = zynqmp_nopmu_pwr_domain_on,
  108. .pwr_domain_off = zynqmp_nopmu_pwr_domain_off,
  109. .system_reset = zynqmp_nopmu_system_reset,
  110. .validate_ns_entrypoint = zynqmp_validate_ns_entrypoint,
  111. .pwr_domain_suspend = zynqmp_pwr_domain_suspend,
  112. .pwr_domain_on_finish = zynqmp_pwr_domain_on_finish,
  113. .pwr_domain_suspend_finish = zynqmp_pwr_domain_suspend_finish,
  114. .system_off = zynqmp_system_off,
  115. .validate_power_state = zynqmp_validate_power_state,
  116. .get_sys_suspend_power_state = zynqmp_get_sys_suspend_power_state,
  117. };
  118. /*******************************************************************************
  119. * Export the platform specific power ops.
  120. ******************************************************************************/
  121. int32_t plat_setup_psci_ops(uintptr_t sec_entrypoint,
  122. const struct plat_psci_ops **psci_ops)
  123. {
  124. versal_net_sec_entry = sec_entrypoint;
  125. VERBOSE("Setting up entry point %lx\n", versal_net_sec_entry);
  126. *psci_ops = &versal_net_nopmc_psci_ops;
  127. return 0;
  128. }
  129. int sip_svc_setup_init(void)
  130. {
  131. return 0;
  132. }
  133. static int32_t no_pm_ioctl(uint32_t device_id, uint32_t ioctl_id,
  134. uint32_t arg1, uint32_t arg2)
  135. {
  136. VERBOSE("%s: ioctl_id: %x, arg1: %x\n", __func__, ioctl_id, arg1);
  137. if (ioctl_id == IOCTL_OSPI_MUX_SELECT) {
  138. mmio_write_32(SLCR_OSPI_QSPI_IOU_AXI_MUX_SEL, arg1);
  139. return 0;
  140. }
  141. return PM_RET_ERROR_NOFEATURE;
  142. }
  143. static uint64_t no_pm_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3,
  144. uint64_t x4, void *cookie, void *handle, uint64_t flags)
  145. {
  146. int32_t ret;
  147. uint32_t arg[4], api_id;
  148. arg[0] = (uint32_t)x1;
  149. arg[1] = (uint32_t)(x1 >> 32);
  150. arg[2] = (uint32_t)x2;
  151. arg[3] = (uint32_t)(x2 >> 32);
  152. api_id = smc_fid & FUNCID_NUM_MASK;
  153. VERBOSE("%s: smc_fid: %x, api_id=0x%x\n", __func__, smc_fid, api_id);
  154. switch (api_id) {
  155. case PM_IOCTL:
  156. {
  157. ret = no_pm_ioctl(arg[0], arg[1], arg[2], arg[3]);
  158. SMC_RET1(handle, (uint64_t)ret);
  159. }
  160. case PM_GET_CHIPID:
  161. {
  162. uint32_t idcode, version;
  163. idcode = mmio_read_32(PMC_TAP);
  164. version = mmio_read_32(PMC_TAP_VERSION);
  165. SMC_RET2(handle, ((uint64_t)idcode << 32), version);
  166. }
  167. default:
  168. WARN("Unimplemented PM Service Call: 0x%x\n", smc_fid);
  169. SMC_RET1(handle, SMC_UNK);
  170. }
  171. }
  172. uint64_t smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3, uint64_t x4,
  173. void *cookie, void *handle, uint64_t flags)
  174. {
  175. return no_pm_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags);
  176. }