blob: 526e21538d8bb8cff69f2a466419cc3b84f2c298 [file] [log] [blame]
Soren Brinkmann76fcae32016-03-06 20:16:27 -08001/*
Michal Simek2a47faa2023-04-14 08:43:51 +02002 * Copyright (c) 2013-2022, Arm Limited and Contributors. All rights reserved.
Michal Simekb8eca3b2024-04-19 12:16:46 +02003 * Copyright (c) 2022-2024, Advanced Micro Devices, Inc. All rights reserved.
Soren Brinkmann76fcae32016-03-06 20:16:27 -08004 *
dp-armfa3cf0b2017-05-03 09:38:09 +01005 * SPDX-License-Identifier: BSD-3-Clause
Soren Brinkmann76fcae32016-03-06 20:16:27 -08006 */
7
Soren Brinkmann76fcae32016-03-06 20:16:27 -08008#include <assert.h>
Isla Mitchelle3631462017-07-14 10:46:32 +01009#include <errno.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010
11#include <arch_helpers.h>
12#include <common/debug.h>
13#include <drivers/arm/gicv2.h>
14#include <lib/mmio.h>
15#include <lib/psci/psci.h>
Antonio Nino Diazbd7b7402019-01-25 14:30:04 +000016#include <plat/arm/common/plat_arm.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000017#include <plat/common/platform.h>
18
Antonio Nino Diazbd7b7402019-01-25 14:30:04 +000019#include <plat_private.h>
Soren Brinkmann76fcae32016-03-06 20:16:27 -080020#include "pm_client.h"
Jay Buddhabhatti26e138a2022-12-21 23:03:35 -080021#include "zynqmp_pm_api_sys.h"
Soren Brinkmann76fcae32016-03-06 20:16:27 -080022
Venkatesh Yadav Abbarapuc9505352022-05-16 17:29:04 +053023static uintptr_t zynqmp_sec_entry;
Soren Brinkmann76fcae32016-03-06 20:16:27 -080024
Venkatesh Yadav Abbarapuc9505352022-05-16 17:29:04 +053025static void zynqmp_cpu_standby(plat_local_state_t cpu_state)
Soren Brinkmann76fcae32016-03-06 20:16:27 -080026{
27 VERBOSE("%s: cpu_state: 0x%x\n", __func__, cpu_state);
28
29 dsb();
30 wfi();
31}
32
Venkatesh Yadav Abbarapue7c45382022-05-19 14:49:49 +053033static int32_t zynqmp_pwr_domain_on(u_register_t mpidr)
Soren Brinkmann76fcae32016-03-06 20:16:27 -080034{
Venkatesh Yadav Abbarapue7c45382022-05-19 14:49:49 +053035 uint32_t cpu_id = plat_core_pos_by_mpidr(mpidr);
Soren Brinkmann76fcae32016-03-06 20:16:27 -080036 const struct pm_proc *proc;
Ravi Patel2f34d362021-04-15 05:55:19 -070037 uint32_t buff[3];
38 enum pm_ret_status ret;
Soren Brinkmann76fcae32016-03-06 20:16:27 -080039
40 VERBOSE("%s: mpidr: 0x%lx\n", __func__, mpidr);
41
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +053042 if (cpu_id == -1) {
Soren Brinkmann76fcae32016-03-06 20:16:27 -080043 return PSCI_E_INTERN_FAIL;
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +053044 }
Michal Simekb8eca3b2024-04-19 12:16:46 +020045
Soren Brinkmann76fcae32016-03-06 20:16:27 -080046 proc = pm_get_proc(cpu_id);
Ronak Jain807f41b2024-05-08 02:41:13 -070047 if (proc == NULL) {
Michal Simekb8eca3b2024-04-19 12:16:46 +020048 return PSCI_E_INTERN_FAIL;
49 }
Ravi Patel2f34d362021-04-15 05:55:19 -070050
51 /* Check the APU proc status before wakeup */
52 ret = pm_get_node_status(proc->node_id, buff);
53 if ((ret != PM_RET_SUCCESS) || (buff[0] == PM_PROC_STATE_SUSPENDING)) {
54 return PSCI_E_INTERN_FAIL;
55 }
56
Filip Drazicd7d62ce2017-02-07 12:03:56 +010057 /* Clear power down request */
58 pm_client_wakeup(proc);
Soren Brinkmann76fcae32016-03-06 20:16:27 -080059
60 /* Send request to PMU to wake up selected APU CPU core */
Soren Brinkmann17aea222016-05-19 07:20:14 -070061 pm_req_wakeup(proc->node_id, 1, zynqmp_sec_entry, REQ_ACK_BLOCKING);
Soren Brinkmann76fcae32016-03-06 20:16:27 -080062
63 return PSCI_E_SUCCESS;
64}
65
Soren Brinkmann76fcae32016-03-06 20:16:27 -080066static void zynqmp_pwr_domain_off(const psci_power_state_t *target_state)
67{
Venkatesh Yadav Abbarapue7c45382022-05-19 14:49:49 +053068 uint32_t cpu_id = plat_my_core_pos();
Soren Brinkmann76fcae32016-03-06 20:16:27 -080069 const struct pm_proc *proc = pm_get_proc(cpu_id);
70
Ronak Jain807f41b2024-05-08 02:41:13 -070071 if (proc == NULL) {
Michal Simekb8eca3b2024-04-19 12:16:46 +020072 return;
73 }
74
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +053075 for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++) {
Soren Brinkmann76fcae32016-03-06 20:16:27 -080076 VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n",
77 __func__, i, target_state->pwr_domain_state[i]);
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +053078 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -080079
80 /* Prevent interrupts from spuriously waking up this cpu */
81 gicv2_cpuif_disable();
82
83 /*
84 * Send request to PMU to power down the appropriate APU CPU
85 * core.
86 * According to PSCI specification, CPU_off function does not
87 * have resume address and CPU core can only be woken up
88 * invoking CPU_on function, during which resume address will
89 * be set.
90 */
Filip Drazic0bd9d0c2016-07-20 17:17:39 +020091 pm_self_suspend(proc->node_id, MAX_LATENCY, PM_STATE_CPU_IDLE, 0);
Soren Brinkmann76fcae32016-03-06 20:16:27 -080092}
93
Soren Brinkmann76fcae32016-03-06 20:16:27 -080094static void zynqmp_pwr_domain_suspend(const psci_power_state_t *target_state)
95{
Venkatesh Yadav Abbarapue7c45382022-05-19 14:49:49 +053096 uint32_t state;
97 uint32_t cpu_id = plat_my_core_pos();
Soren Brinkmann76fcae32016-03-06 20:16:27 -080098 const struct pm_proc *proc = pm_get_proc(cpu_id);
99
Ronak Jain807f41b2024-05-08 02:41:13 -0700100 if (proc == NULL) {
Michal Simekb8eca3b2024-04-19 12:16:46 +0200101 return;
102 }
103
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800104 for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++)
105 VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n",
106 __func__, i, target_state->pwr_domain_state[i]);
107
Maheedhar Bollapalli44385b72024-04-22 12:37:53 +0530108 state = (target_state->pwr_domain_state[1] > PLAT_MAX_RET_STATE) ?
Filip Drazic0bd9d0c2016-07-20 17:17:39 +0200109 PM_STATE_SUSPEND_TO_RAM : PM_STATE_CPU_IDLE;
110
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800111 /* Send request to PMU to suspend this core */
Filip Drazic0bd9d0c2016-07-20 17:17:39 +0200112 pm_self_suspend(proc->node_id, MAX_LATENCY, state, zynqmp_sec_entry);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800113
114 /* APU is to be turned off */
115 if (target_state->pwr_domain_state[1] > PLAT_MAX_RET_STATE) {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800116 /* disable coherency */
117 plat_arm_interconnect_exit_coherency();
118 }
119}
120
121static void zynqmp_pwr_domain_on_finish(const psci_power_state_t *target_state)
122{
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530123 for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++) {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800124 VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n",
125 __func__, i, target_state->pwr_domain_state[i]);
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530126 }
Siva Durga Prasad Paladugu60bfbc92018-09-24 22:51:49 -0700127 plat_arm_gic_pcpu_init();
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800128 gicv2_cpuif_enable();
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800129}
130
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800131static void zynqmp_pwr_domain_suspend_finish(const psci_power_state_t *target_state)
132{
Venkatesh Yadav Abbarapue7c45382022-05-19 14:49:49 +0530133 uint32_t cpu_id = plat_my_core_pos();
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800134 const struct pm_proc *proc = pm_get_proc(cpu_id);
135
Ronak Jain807f41b2024-05-08 02:41:13 -0700136 if (proc == NULL) {
Michal Simekb8eca3b2024-04-19 12:16:46 +0200137 return;
138 }
139
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530140 for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++) {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800141 VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n",
142 __func__, i, target_state->pwr_domain_state[i]);
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530143 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800144
145 /* Clear the APU power control register for this cpu */
146 pm_client_wakeup(proc);
147
148 /* enable coherency */
149 plat_arm_interconnect_enter_coherency();
Soren Brinkmann3b6ebcb2016-02-18 21:16:35 -0800150 /* APU was turned off */
151 if (target_state->pwr_domain_state[1] > PLAT_MAX_RET_STATE) {
152 plat_arm_gic_init();
153 } else {
154 gicv2_cpuif_enable();
155 gicv2_pcpu_distif_init();
156 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800157}
158
159/*******************************************************************************
160 * ZynqMP handlers to shutdown/reboot the system
161 ******************************************************************************/
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800162
163static void __dead2 zynqmp_system_off(void)
164{
165 /* disable coherency */
166 plat_arm_interconnect_exit_coherency();
167
168 /* Send the power down request to the PMU */
Soren Brinkmann58fbb9b2016-09-02 09:50:54 -0700169 pm_system_shutdown(PMF_SHUTDOWN_TYPE_SHUTDOWN,
Siva Durga Prasad Paladugu1f80d3f2018-04-30 15:56:10 +0530170 pm_get_shutdown_scope());
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800171
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530172 while (1) {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800173 wfi();
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530174 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800175}
176
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800177static void __dead2 zynqmp_system_reset(void)
178{
179 /* disable coherency */
180 plat_arm_interconnect_exit_coherency();
181
182 /* Send the system reset request to the PMU */
Soren Brinkmann58fbb9b2016-09-02 09:50:54 -0700183 pm_system_shutdown(PMF_SHUTDOWN_TYPE_RESET,
Siva Durga Prasad Paladugu1f80d3f2018-04-30 15:56:10 +0530184 pm_get_shutdown_scope());
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800185
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530186 while (1) {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800187 wfi();
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530188 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800189}
190
Venkatesh Yadav Abbarapue7c45382022-05-19 14:49:49 +0530191static int32_t zynqmp_validate_power_state(uint32_t power_state,
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800192 psci_power_state_t *req_state)
193{
194 VERBOSE("%s: power_state: 0x%x\n", __func__, power_state);
195
Venkatesh Yadav Abbarapua2ca35d2022-07-04 11:40:27 +0530196 uint32_t pstate = psci_get_pstate_type(power_state);
Stefan Krsmanovic3779c5c2016-05-09 18:00:47 +0200197
198 assert(req_state);
199
200 /* Sanity check the requested state */
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530201 if (pstate == PSTATE_TYPE_STANDBY) {
Stefan Krsmanovic3779c5c2016-05-09 18:00:47 +0200202 req_state->pwr_domain_state[MPIDR_AFFLVL0] = PLAT_MAX_RET_STATE;
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530203 } else {
Stefan Krsmanovic3779c5c2016-05-09 18:00:47 +0200204 req_state->pwr_domain_state[MPIDR_AFFLVL0] = PLAT_MAX_OFF_STATE;
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530205 }
Stefan Krsmanovic3779c5c2016-05-09 18:00:47 +0200206 /* We expect the 'state id' to be zero */
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530207 if (psci_get_pstate_id(power_state)) {
Stefan Krsmanovic3779c5c2016-05-09 18:00:47 +0200208 return PSCI_E_INVALID_PARAMS;
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530209 }
Stefan Krsmanovic3779c5c2016-05-09 18:00:47 +0200210
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800211 return PSCI_E_SUCCESS;
212}
213
Venkatesh Yadav Abbarapuc9505352022-05-16 17:29:04 +0530214static void zynqmp_get_sys_suspend_power_state(psci_power_state_t *req_state)
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800215{
216 req_state->pwr_domain_state[PSCI_CPU_PWR_LVL] = PLAT_MAX_OFF_STATE;
217 req_state->pwr_domain_state[1] = PLAT_MAX_OFF_STATE;
218}
219
220/*******************************************************************************
221 * Export the platform handlers to enable psci to invoke them
222 ******************************************************************************/
223static const struct plat_psci_ops zynqmp_psci_ops = {
224 .cpu_standby = zynqmp_cpu_standby,
225 .pwr_domain_on = zynqmp_pwr_domain_on,
226 .pwr_domain_off = zynqmp_pwr_domain_off,
227 .pwr_domain_suspend = zynqmp_pwr_domain_suspend,
228 .pwr_domain_on_finish = zynqmp_pwr_domain_on_finish,
229 .pwr_domain_suspend_finish = zynqmp_pwr_domain_suspend_finish,
230 .system_off = zynqmp_system_off,
231 .system_reset = zynqmp_system_reset,
232 .validate_power_state = zynqmp_validate_power_state,
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800233 .get_sys_suspend_power_state = zynqmp_get_sys_suspend_power_state,
234};
235
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800236/*******************************************************************************
237 * Export the platform specific power ops.
238 ******************************************************************************/
239int plat_setup_psci_ops(uintptr_t sec_entrypoint,
240 const struct plat_psci_ops **psci_ops)
241{
242 zynqmp_sec_entry = sec_entrypoint;
243
Siva Durga Prasad Paladugu40808bc2018-04-30 19:43:03 +0530244 *psci_ops = &zynqmp_psci_ops;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800245
246 return 0;
247}