Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 1 | /* |
Ravi Patel | 2f34d36 | 2021-04-15 05:55:19 -0700 | [diff] [blame] | 2 | * Copyright (c) 2013-2022, ARM Limited and Contributors. All rights reserved. |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 5 | */ |
| 6 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 7 | #include <assert.h> |
Isla Mitchell | e363146 | 2017-07-14 10:46:32 +0100 | [diff] [blame] | 8 | #include <errno.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | |
| 10 | #include <arch_helpers.h> |
| 11 | #include <common/debug.h> |
| 12 | #include <drivers/arm/gicv2.h> |
| 13 | #include <lib/mmio.h> |
| 14 | #include <lib/psci/psci.h> |
Antonio Nino Diaz | bd7b740 | 2019-01-25 14:30:04 +0000 | [diff] [blame] | 15 | #include <plat/arm/common/plat_arm.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 16 | #include <plat/common/platform.h> |
| 17 | |
Antonio Nino Diaz | bd7b740 | 2019-01-25 14:30:04 +0000 | [diff] [blame] | 18 | #include <plat_private.h> |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 19 | #include "pm_api_sys.h" |
| 20 | #include "pm_client.h" |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 21 | |
| 22 | uintptr_t zynqmp_sec_entry; |
| 23 | |
| 24 | void zynqmp_cpu_standby(plat_local_state_t cpu_state) |
| 25 | { |
| 26 | VERBOSE("%s: cpu_state: 0x%x\n", __func__, cpu_state); |
| 27 | |
| 28 | dsb(); |
| 29 | wfi(); |
| 30 | } |
| 31 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 32 | static int zynqmp_pwr_domain_on(u_register_t mpidr) |
| 33 | { |
| 34 | unsigned int cpu_id = plat_core_pos_by_mpidr(mpidr); |
| 35 | const struct pm_proc *proc; |
Ravi Patel | 2f34d36 | 2021-04-15 05:55:19 -0700 | [diff] [blame] | 36 | uint32_t buff[3]; |
| 37 | enum pm_ret_status ret; |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 38 | |
| 39 | VERBOSE("%s: mpidr: 0x%lx\n", __func__, mpidr); |
| 40 | |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 41 | if (cpu_id == -1) { |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 42 | return PSCI_E_INTERN_FAIL; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 43 | } |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 44 | proc = pm_get_proc(cpu_id); |
Ravi Patel | 2f34d36 | 2021-04-15 05:55:19 -0700 | [diff] [blame] | 45 | |
| 46 | /* Check the APU proc status before wakeup */ |
| 47 | ret = pm_get_node_status(proc->node_id, buff); |
| 48 | if ((ret != PM_RET_SUCCESS) || (buff[0] == PM_PROC_STATE_SUSPENDING)) { |
| 49 | return PSCI_E_INTERN_FAIL; |
| 50 | } |
| 51 | |
Filip Drazic | d7d62ce | 2017-02-07 12:03:56 +0100 | [diff] [blame] | 52 | /* Clear power down request */ |
| 53 | pm_client_wakeup(proc); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 54 | |
| 55 | /* Send request to PMU to wake up selected APU CPU core */ |
Soren Brinkmann | 17aea22 | 2016-05-19 07:20:14 -0700 | [diff] [blame] | 56 | pm_req_wakeup(proc->node_id, 1, zynqmp_sec_entry, REQ_ACK_BLOCKING); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 57 | |
| 58 | return PSCI_E_SUCCESS; |
| 59 | } |
| 60 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 61 | static void zynqmp_pwr_domain_off(const psci_power_state_t *target_state) |
| 62 | { |
| 63 | unsigned int cpu_id = plat_my_core_pos(); |
| 64 | const struct pm_proc *proc = pm_get_proc(cpu_id); |
| 65 | |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 66 | for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++) { |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 67 | VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n", |
| 68 | __func__, i, target_state->pwr_domain_state[i]); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 69 | } |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 70 | |
| 71 | /* Prevent interrupts from spuriously waking up this cpu */ |
| 72 | gicv2_cpuif_disable(); |
| 73 | |
| 74 | /* |
| 75 | * Send request to PMU to power down the appropriate APU CPU |
| 76 | * core. |
| 77 | * According to PSCI specification, CPU_off function does not |
| 78 | * have resume address and CPU core can only be woken up |
| 79 | * invoking CPU_on function, during which resume address will |
| 80 | * be set. |
| 81 | */ |
Filip Drazic | 0bd9d0c | 2016-07-20 17:17:39 +0200 | [diff] [blame] | 82 | pm_self_suspend(proc->node_id, MAX_LATENCY, PM_STATE_CPU_IDLE, 0); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 83 | } |
| 84 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 85 | static void zynqmp_pwr_domain_suspend(const psci_power_state_t *target_state) |
| 86 | { |
Filip Drazic | 0bd9d0c | 2016-07-20 17:17:39 +0200 | [diff] [blame] | 87 | unsigned int state; |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 88 | unsigned int cpu_id = plat_my_core_pos(); |
| 89 | const struct pm_proc *proc = pm_get_proc(cpu_id); |
| 90 | |
| 91 | for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++) |
| 92 | VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n", |
| 93 | __func__, i, target_state->pwr_domain_state[i]); |
| 94 | |
Filip Drazic | 0bd9d0c | 2016-07-20 17:17:39 +0200 | [diff] [blame] | 95 | state = target_state->pwr_domain_state[1] > PLAT_MAX_RET_STATE ? |
| 96 | PM_STATE_SUSPEND_TO_RAM : PM_STATE_CPU_IDLE; |
| 97 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 98 | /* Send request to PMU to suspend this core */ |
Filip Drazic | 0bd9d0c | 2016-07-20 17:17:39 +0200 | [diff] [blame] | 99 | pm_self_suspend(proc->node_id, MAX_LATENCY, state, zynqmp_sec_entry); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 100 | |
| 101 | /* APU is to be turned off */ |
| 102 | if (target_state->pwr_domain_state[1] > PLAT_MAX_RET_STATE) { |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 103 | /* disable coherency */ |
| 104 | plat_arm_interconnect_exit_coherency(); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | static void zynqmp_pwr_domain_on_finish(const psci_power_state_t *target_state) |
| 109 | { |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 110 | for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++) { |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 111 | VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n", |
| 112 | __func__, i, target_state->pwr_domain_state[i]); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 113 | } |
Siva Durga Prasad Paladugu | 60bfbc9 | 2018-09-24 22:51:49 -0700 | [diff] [blame] | 114 | plat_arm_gic_pcpu_init(); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 115 | gicv2_cpuif_enable(); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 116 | } |
| 117 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 118 | static void zynqmp_pwr_domain_suspend_finish(const psci_power_state_t *target_state) |
| 119 | { |
| 120 | unsigned int cpu_id = plat_my_core_pos(); |
| 121 | const struct pm_proc *proc = pm_get_proc(cpu_id); |
| 122 | |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 123 | for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++) { |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 124 | VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n", |
| 125 | __func__, i, target_state->pwr_domain_state[i]); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 126 | } |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 127 | |
| 128 | /* Clear the APU power control register for this cpu */ |
| 129 | pm_client_wakeup(proc); |
| 130 | |
| 131 | /* enable coherency */ |
| 132 | plat_arm_interconnect_enter_coherency(); |
Soren Brinkmann | 3b6ebcb | 2016-02-18 21:16:35 -0800 | [diff] [blame] | 133 | /* APU was turned off */ |
| 134 | if (target_state->pwr_domain_state[1] > PLAT_MAX_RET_STATE) { |
| 135 | plat_arm_gic_init(); |
| 136 | } else { |
| 137 | gicv2_cpuif_enable(); |
| 138 | gicv2_pcpu_distif_init(); |
| 139 | } |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | /******************************************************************************* |
| 143 | * ZynqMP handlers to shutdown/reboot the system |
| 144 | ******************************************************************************/ |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 145 | |
| 146 | static void __dead2 zynqmp_system_off(void) |
| 147 | { |
| 148 | /* disable coherency */ |
| 149 | plat_arm_interconnect_exit_coherency(); |
| 150 | |
| 151 | /* Send the power down request to the PMU */ |
Soren Brinkmann | 58fbb9b | 2016-09-02 09:50:54 -0700 | [diff] [blame] | 152 | pm_system_shutdown(PMF_SHUTDOWN_TYPE_SHUTDOWN, |
Siva Durga Prasad Paladugu | 1f80d3f | 2018-04-30 15:56:10 +0530 | [diff] [blame] | 153 | pm_get_shutdown_scope()); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 154 | |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 155 | while (1) { |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 156 | wfi(); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 157 | } |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 158 | } |
| 159 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 160 | static void __dead2 zynqmp_system_reset(void) |
| 161 | { |
| 162 | /* disable coherency */ |
| 163 | plat_arm_interconnect_exit_coherency(); |
| 164 | |
| 165 | /* Send the system reset request to the PMU */ |
Soren Brinkmann | 58fbb9b | 2016-09-02 09:50:54 -0700 | [diff] [blame] | 166 | pm_system_shutdown(PMF_SHUTDOWN_TYPE_RESET, |
Siva Durga Prasad Paladugu | 1f80d3f | 2018-04-30 15:56:10 +0530 | [diff] [blame] | 167 | pm_get_shutdown_scope()); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 168 | |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 169 | while (1) { |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 170 | wfi(); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 171 | } |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | int zynqmp_validate_power_state(unsigned int power_state, |
| 175 | psci_power_state_t *req_state) |
| 176 | { |
| 177 | VERBOSE("%s: power_state: 0x%x\n", __func__, power_state); |
| 178 | |
Stefan Krsmanovic | 3779c5c | 2016-05-09 18:00:47 +0200 | [diff] [blame] | 179 | int pstate = psci_get_pstate_type(power_state); |
| 180 | |
| 181 | assert(req_state); |
| 182 | |
| 183 | /* Sanity check the requested state */ |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 184 | if (pstate == PSTATE_TYPE_STANDBY) { |
Stefan Krsmanovic | 3779c5c | 2016-05-09 18:00:47 +0200 | [diff] [blame] | 185 | req_state->pwr_domain_state[MPIDR_AFFLVL0] = PLAT_MAX_RET_STATE; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 186 | } else { |
Stefan Krsmanovic | 3779c5c | 2016-05-09 18:00:47 +0200 | [diff] [blame] | 187 | req_state->pwr_domain_state[MPIDR_AFFLVL0] = PLAT_MAX_OFF_STATE; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 188 | } |
Stefan Krsmanovic | 3779c5c | 2016-05-09 18:00:47 +0200 | [diff] [blame] | 189 | /* We expect the 'state id' to be zero */ |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 190 | if (psci_get_pstate_id(power_state)) { |
Stefan Krsmanovic | 3779c5c | 2016-05-09 18:00:47 +0200 | [diff] [blame] | 191 | return PSCI_E_INVALID_PARAMS; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 192 | } |
Stefan Krsmanovic | 3779c5c | 2016-05-09 18:00:47 +0200 | [diff] [blame] | 193 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 194 | return PSCI_E_SUCCESS; |
| 195 | } |
| 196 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 197 | void zynqmp_get_sys_suspend_power_state(psci_power_state_t *req_state) |
| 198 | { |
| 199 | req_state->pwr_domain_state[PSCI_CPU_PWR_LVL] = PLAT_MAX_OFF_STATE; |
| 200 | req_state->pwr_domain_state[1] = PLAT_MAX_OFF_STATE; |
| 201 | } |
| 202 | |
| 203 | /******************************************************************************* |
| 204 | * Export the platform handlers to enable psci to invoke them |
| 205 | ******************************************************************************/ |
| 206 | static const struct plat_psci_ops zynqmp_psci_ops = { |
| 207 | .cpu_standby = zynqmp_cpu_standby, |
| 208 | .pwr_domain_on = zynqmp_pwr_domain_on, |
| 209 | .pwr_domain_off = zynqmp_pwr_domain_off, |
| 210 | .pwr_domain_suspend = zynqmp_pwr_domain_suspend, |
| 211 | .pwr_domain_on_finish = zynqmp_pwr_domain_on_finish, |
| 212 | .pwr_domain_suspend_finish = zynqmp_pwr_domain_suspend_finish, |
| 213 | .system_off = zynqmp_system_off, |
| 214 | .system_reset = zynqmp_system_reset, |
| 215 | .validate_power_state = zynqmp_validate_power_state, |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 216 | .get_sys_suspend_power_state = zynqmp_get_sys_suspend_power_state, |
| 217 | }; |
| 218 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 219 | /******************************************************************************* |
| 220 | * Export the platform specific power ops. |
| 221 | ******************************************************************************/ |
| 222 | int plat_setup_psci_ops(uintptr_t sec_entrypoint, |
| 223 | const struct plat_psci_ops **psci_ops) |
| 224 | { |
| 225 | zynqmp_sec_entry = sec_entrypoint; |
| 226 | |
Siva Durga Prasad Paladugu | 40808bc | 2018-04-30 19:43:03 +0530 | [diff] [blame] | 227 | *psci_ops = &zynqmp_psci_ops; |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 228 | |
| 229 | return 0; |
| 230 | } |