Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2022, Xilinx, Inc. All rights reserved. |
Senthil Nathan Thangaraj | 4de8472 | 2025-04-07 20:18:27 -0700 | [diff] [blame] | 3 | * Copyright (c) 2022-2025, Advanced Micro Devices, Inc. All rights reserved. |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 4 | * |
| 5 | * SPDX-License-Identifier: BSD-3-Clause |
| 6 | */ |
| 7 | |
| 8 | #include <assert.h> |
| 9 | |
| 10 | #include <common/debug.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 | |
Jay Buddhabhatti | 10e71e4 | 2023-06-19 05:08:54 -0700 | [diff] [blame] | 17 | #include <drivers/delay_timer.h> |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 18 | #include <plat_private.h> |
| 19 | #include "pm_api_sys.h" |
| 20 | #include "pm_client.h" |
| 21 | #include <pm_common.h> |
Jay Buddhabhatti | 10e71e4 | 2023-06-19 05:08:54 -0700 | [diff] [blame] | 22 | #include "pm_ipi.h" |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 23 | #include "pm_svc_main.h" |
| 24 | #include "versal_net_def.h" |
| 25 | |
| 26 | static uintptr_t versal_net_sec_entry; |
| 27 | |
| 28 | static int32_t versal_net_pwr_domain_on(u_register_t mpidr) |
| 29 | { |
Maheedhar Bollapalli | 6083711 | 2024-10-21 05:41:14 +0000 | [diff] [blame] | 30 | int32_t cpu_id = plat_core_pos_by_mpidr(mpidr); |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 31 | const struct pm_proc *proc; |
Maheedhar Bollapalli | d27a516 | 2024-10-29 03:34:49 +0000 | [diff] [blame] | 32 | int32_t ret = PSCI_E_INTERN_FAIL; |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 33 | |
| 34 | VERBOSE("%s: mpidr: 0x%lx, cpuid: %x\n", |
| 35 | __func__, mpidr, cpu_id); |
| 36 | |
| 37 | if (cpu_id == -1) { |
Maheedhar Bollapalli | d27a516 | 2024-10-29 03:34:49 +0000 | [diff] [blame] | 38 | goto exit_label; |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | proc = pm_get_proc(cpu_id); |
Ronak Jain | 807f41b | 2024-05-08 02:41:13 -0700 | [diff] [blame] | 42 | if (proc == NULL) { |
Maheedhar Bollapalli | d27a516 | 2024-10-29 03:34:49 +0000 | [diff] [blame] | 43 | goto exit_label; |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Maheedhar Bollapalli | ad1553d | 2024-10-14 11:15:53 +0000 | [diff] [blame] | 46 | (void)pm_req_wakeup(proc->node_id, (versal_net_sec_entry & 0xFFFFFFFFU) | 0x1U, |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 47 | versal_net_sec_entry >> 32, 0, 0); |
| 48 | |
| 49 | /* Clear power down request */ |
| 50 | pm_client_wakeup(proc); |
| 51 | |
Maheedhar Bollapalli | d27a516 | 2024-10-29 03:34:49 +0000 | [diff] [blame] | 52 | ret = PSCI_E_SUCCESS; |
| 53 | |
| 54 | exit_label: |
| 55 | return ret; |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 59 | * versal_net_pwr_domain_off() - This function performs actions to turn off |
| 60 | * core. |
| 61 | * @target_state: Targeted state. |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 62 | * |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 63 | */ |
| 64 | static void versal_net_pwr_domain_off(const psci_power_state_t *target_state) |
| 65 | { |
Maheedhar Bollapalli | 828a07a | 2024-10-08 05:50:05 +0000 | [diff] [blame] | 66 | uint32_t ret, fw_api_version, version_type[RET_PAYLOAD_ARG_CNT] = {0U}; |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 67 | uint32_t cpu_id = plat_my_core_pos(); |
| 68 | const struct pm_proc *proc = pm_get_proc(cpu_id); |
| 69 | |
Ronak Jain | 807f41b | 2024-05-08 02:41:13 -0700 | [diff] [blame] | 70 | if (proc == NULL) { |
Maheedhar Bollapalli | d27a516 | 2024-10-29 03:34:49 +0000 | [diff] [blame] | 71 | goto exit_label; |
Michal Simek | b8eca3b | 2024-04-19 12:16:46 +0200 | [diff] [blame] | 72 | } |
| 73 | |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 74 | for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++) { |
| 75 | VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n", |
| 76 | __func__, i, target_state->pwr_domain_state[i]); |
| 77 | } |
| 78 | |
| 79 | /* Prevent interrupts from spuriously waking up this cpu */ |
Jay Buddhabhatti | b7bb1ed | 2023-10-05 21:55:28 -0700 | [diff] [blame] | 80 | plat_arm_gic_cpuif_disable(); |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 81 | |
| 82 | /* |
| 83 | * Send request to PMC to power down the appropriate APU CPU |
| 84 | * core. |
| 85 | * According to PSCI specification, CPU_off function does not |
| 86 | * have resume address and CPU core can only be woken up |
| 87 | * invoking CPU_on function, during which resume address will |
| 88 | * be set. |
| 89 | */ |
Maheedhar Bollapalli | 828a07a | 2024-10-08 05:50:05 +0000 | [diff] [blame] | 90 | ret = pm_feature_check((uint32_t)PM_SELF_SUSPEND, &version_type[0], SECURE_FLAG); |
Maheedhar Bollapalli | 6083711 | 2024-10-21 05:41:14 +0000 | [diff] [blame] | 91 | if (ret == (uint32_t)PM_RET_SUCCESS) { |
Maheedhar Bollapalli | 828a07a | 2024-10-08 05:50:05 +0000 | [diff] [blame] | 92 | fw_api_version = version_type[0] & 0xFFFFU; |
Jay Buddhabhatti | 31488a3 | 2023-09-11 23:50:06 -0700 | [diff] [blame] | 93 | if (fw_api_version >= 3U) { |
| 94 | (void)pm_self_suspend(proc->node_id, MAX_LATENCY, PM_STATE_CPU_OFF, 0, |
| 95 | SECURE_FLAG); |
| 96 | } else { |
| 97 | (void)pm_self_suspend(proc->node_id, MAX_LATENCY, PM_STATE_CPU_IDLE, 0, |
| 98 | SECURE_FLAG); |
| 99 | } |
| 100 | } |
Maheedhar Bollapalli | d27a516 | 2024-10-29 03:34:49 +0000 | [diff] [blame] | 101 | |
| 102 | exit_label: |
| 103 | return; |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Maheedhar Bollapalli | f9617f9 | 2025-02-17 15:52:05 +0530 | [diff] [blame] | 106 | static int32_t versal_net_validate_ns_entrypoint(uint64_t ns_entrypoint) |
| 107 | { |
| 108 | int32_t ret = PSCI_E_SUCCESS; |
| 109 | |
| 110 | if (((ns_entrypoint >= PLAT_DDR_LOWMEM_MAX) && (ns_entrypoint <= PLAT_DDR_HIGHMEM_MAX)) || |
| 111 | ((ns_entrypoint >= BL31_BASE) && (ns_entrypoint <= BL31_LIMIT))) { |
| 112 | ret = PSCI_E_INVALID_ADDRESS; |
| 113 | } |
| 114 | |
| 115 | return ret; |
| 116 | } |
| 117 | |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 118 | /** |
Senthil Nathan Thangaraj | 4de8472 | 2025-04-07 20:18:27 -0700 | [diff] [blame] | 119 | * versal_net_system_reset_scope() - Sends the reset request to firmware for |
| 120 | * the system to reset. |
| 121 | * @scope : scope of reset which could be SYSTEM/SUBSYSTEM/PS-ONLY |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 122 | * |
Senthil Nathan Thangaraj | 4de8472 | 2025-04-07 20:18:27 -0700 | [diff] [blame] | 123 | * Return: |
| 124 | * Does not return if system resets, none if there is a failure. |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 125 | */ |
Senthil Nathan Thangaraj | 4de8472 | 2025-04-07 20:18:27 -0700 | [diff] [blame] | 126 | static void __dead2 versal_net_system_reset_scope(uint32_t scope) |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 127 | { |
Jay Buddhabhatti | 10e71e4 | 2023-06-19 05:08:54 -0700 | [diff] [blame] | 128 | uint32_t ret, timeout = 10000U; |
| 129 | |
| 130 | request_cpu_pwrdwn(); |
| 131 | |
| 132 | /* |
| 133 | * Send the system reset request to the firmware if power down request |
| 134 | * is not received from firmware. |
| 135 | */ |
| 136 | if (!pwrdwn_req_received) { |
| 137 | (void)pm_system_shutdown(XPM_SHUTDOWN_TYPE_RESET, |
Senthil Nathan Thangaraj | 4de8472 | 2025-04-07 20:18:27 -0700 | [diff] [blame] | 138 | scope, SECURE_FLAG); |
Jay Buddhabhatti | 10e71e4 | 2023-06-19 05:08:54 -0700 | [diff] [blame] | 139 | |
| 140 | /* |
| 141 | * Wait for system shutdown request completed and idle callback |
| 142 | * not received. |
| 143 | */ |
| 144 | do { |
| 145 | ret = ipi_mb_enquire_status(primary_proc->ipi->local_ipi_id, |
| 146 | primary_proc->ipi->remote_ipi_id); |
| 147 | udelay(100); |
| 148 | timeout--; |
| 149 | } while ((ret != IPI_MB_STATUS_RECV_PENDING) && (timeout > 0U)); |
| 150 | } |
| 151 | |
| 152 | (void)psci_cpu_off(); |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 153 | |
Maheedhar Bollapalli | 2093b25 | 2024-10-14 06:48:43 +0000 | [diff] [blame] | 154 | while (true) { |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 155 | wfi(); |
| 156 | } |
Senthil Nathan Thangaraj | 4de8472 | 2025-04-07 20:18:27 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | /** |
| 160 | * versal_net_system_reset() - This function sends the reset request to firmware |
| 161 | * for the system to reset in response to SYSTEM_RESET call |
| 162 | * |
| 163 | * Return: |
| 164 | * Does not return if system resets, none if there is a failure. |
| 165 | */ |
| 166 | static void __dead2 versal_net_system_reset(void) |
| 167 | { |
| 168 | /* |
| 169 | * Any platform-specific actions for handling a cold reset |
| 170 | * should be performed here before invoking |
| 171 | * versal_net_system_reset_scope. |
| 172 | */ |
| 173 | versal_net_system_reset_scope(XPM_SHUTDOWN_SUBTYPE_RST_SUBSYSTEM); |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * versal_net_system_reset2() - Handles warm / vendor-specific system reset |
| 178 | * in response to SYSTEM_RESET2 call. |
| 179 | * @is_vendor: Flag indicating if this is a vendor-specific reset |
| 180 | * @reset_type: Type of reset requested |
| 181 | * @cookie: Additional reset data |
| 182 | * |
| 183 | * This function initiates a controlled system reset by requesting it |
| 184 | * through the PM firmware. |
| 185 | * |
| 186 | * Return: |
| 187 | * Does not return if system resets, PSCI_E_INTERN_FAIL |
| 188 | * if there is a failure. |
| 189 | */ |
| 190 | static int versal_net_system_reset2(int is_vendor, int reset_type, u_register_t cookie) |
| 191 | { |
| 192 | if (is_vendor == 0 && reset_type == PSCI_RESET2_SYSTEM_WARM_RESET) { |
| 193 | /* |
| 194 | * Any platform-specific actions for handling a warm reset |
| 195 | * should be performed here before invoking |
| 196 | * versal_net_system_reset_scope. |
| 197 | */ |
| 198 | versal_net_system_reset_scope(XPM_SHUTDOWN_SUBTYPE_RST_SUBSYSTEM); |
| 199 | } else { |
| 200 | /* Vendor specific reset */ |
| 201 | versal_net_system_reset_scope(pm_get_shutdown_scope()); |
| 202 | } |
| 203 | |
| 204 | return PSCI_E_INTERN_FAIL; |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | /** |
| 208 | * versal_net_pwr_domain_suspend() - This function sends request to PMC to suspend |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 209 | * core. |
| 210 | * @target_state: Targeted state. |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 211 | * |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 212 | */ |
| 213 | static void versal_net_pwr_domain_suspend(const psci_power_state_t *target_state) |
| 214 | { |
| 215 | uint32_t state; |
| 216 | uint32_t cpu_id = plat_my_core_pos(); |
| 217 | const struct pm_proc *proc = pm_get_proc(cpu_id); |
| 218 | |
Ronak Jain | 807f41b | 2024-05-08 02:41:13 -0700 | [diff] [blame] | 219 | if (proc == NULL) { |
Maheedhar Bollapalli | d27a516 | 2024-10-29 03:34:49 +0000 | [diff] [blame] | 220 | goto exit_label; |
Michal Simek | b8eca3b | 2024-04-19 12:16:46 +0200 | [diff] [blame] | 221 | } |
| 222 | |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 223 | for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++) { |
| 224 | VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n", |
| 225 | __func__, i, target_state->pwr_domain_state[i]); |
| 226 | } |
| 227 | |
Jay Buddhabhatti | b7bb1ed | 2023-10-05 21:55:28 -0700 | [diff] [blame] | 228 | plat_arm_gic_cpuif_disable(); |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 229 | |
| 230 | if (target_state->pwr_domain_state[1] > PLAT_MAX_RET_STATE) { |
Jay Buddhabhatti | b7bb1ed | 2023-10-05 21:55:28 -0700 | [diff] [blame] | 231 | plat_arm_gic_save(); |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Maheedhar Bollapalli | 71d8e2b | 2024-10-14 04:19:45 +0000 | [diff] [blame] | 234 | state = (target_state->pwr_domain_state[1] > PLAT_MAX_RET_STATE) ? |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 235 | PM_STATE_SUSPEND_TO_RAM : PM_STATE_CPU_IDLE; |
| 236 | |
| 237 | /* Send request to PMC to suspend this core */ |
Maheedhar Bollapalli | ad1553d | 2024-10-14 11:15:53 +0000 | [diff] [blame] | 238 | (void)pm_self_suspend(proc->node_id, MAX_LATENCY, state, versal_net_sec_entry, |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 239 | SECURE_FLAG); |
| 240 | |
| 241 | /* TODO: disable coherency */ |
Maheedhar Bollapalli | d27a516 | 2024-10-29 03:34:49 +0000 | [diff] [blame] | 242 | |
| 243 | exit_label: |
| 244 | return; |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | static void versal_net_pwr_domain_on_finish(const psci_power_state_t *target_state) |
| 248 | { |
| 249 | (void)target_state; |
| 250 | |
| 251 | /* Enable the gic cpu interface */ |
Jay Buddhabhatti | b7bb1ed | 2023-10-05 21:55:28 -0700 | [diff] [blame] | 252 | plat_arm_gic_pcpu_init(); |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 253 | |
| 254 | /* Program the gic per-cpu distributor or re-distributor interface */ |
Jay Buddhabhatti | b7bb1ed | 2023-10-05 21:55:28 -0700 | [diff] [blame] | 255 | plat_arm_gic_cpuif_enable(); |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | /** |
| 259 | * versal_net_pwr_domain_suspend_finish() - This function performs actions to finish |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 260 | * suspend procedure. |
| 261 | * @target_state: Targeted state. |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 262 | * |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 263 | */ |
| 264 | static void versal_net_pwr_domain_suspend_finish(const psci_power_state_t *target_state) |
| 265 | { |
| 266 | uint32_t cpu_id = plat_my_core_pos(); |
| 267 | const struct pm_proc *proc = pm_get_proc(cpu_id); |
| 268 | |
Ronak Jain | 807f41b | 2024-05-08 02:41:13 -0700 | [diff] [blame] | 269 | if (proc == NULL) { |
Maheedhar Bollapalli | d27a516 | 2024-10-29 03:34:49 +0000 | [diff] [blame] | 270 | goto exit_label; |
Michal Simek | b8eca3b | 2024-04-19 12:16:46 +0200 | [diff] [blame] | 271 | } |
| 272 | |
Maheedhar Bollapalli | c59b1df | 2024-10-24 06:02:48 +0000 | [diff] [blame] | 273 | for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++) { |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 274 | VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n", |
| 275 | __func__, i, target_state->pwr_domain_state[i]); |
Maheedhar Bollapalli | c59b1df | 2024-10-24 06:02:48 +0000 | [diff] [blame] | 276 | } |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 277 | |
| 278 | /* Clear the APU power control register for this cpu */ |
| 279 | pm_client_wakeup(proc); |
| 280 | |
| 281 | /* TODO: enable coherency */ |
| 282 | |
| 283 | /* APU was turned off, so restore GIC context */ |
| 284 | if (target_state->pwr_domain_state[1] > PLAT_MAX_RET_STATE) { |
Jay Buddhabhatti | b7bb1ed | 2023-10-05 21:55:28 -0700 | [diff] [blame] | 285 | plat_arm_gic_resume(); |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Jay Buddhabhatti | b7bb1ed | 2023-10-05 21:55:28 -0700 | [diff] [blame] | 288 | plat_arm_gic_cpuif_enable(); |
Maheedhar Bollapalli | d27a516 | 2024-10-29 03:34:49 +0000 | [diff] [blame] | 289 | |
| 290 | exit_label: |
| 291 | return; |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /** |
| 295 | * versal_net_system_off() - This function sends the system off request |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 296 | * to firmware. This function does not return. |
| 297 | * |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 298 | */ |
| 299 | static void __dead2 versal_net_system_off(void) |
| 300 | { |
| 301 | /* Send the power down request to the PMC */ |
Maheedhar Bollapalli | ad1553d | 2024-10-14 11:15:53 +0000 | [diff] [blame] | 302 | (void)pm_system_shutdown(XPM_SHUTDOWN_TYPE_SHUTDOWN, |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 303 | pm_get_shutdown_scope(), SECURE_FLAG); |
| 304 | |
Maheedhar Bollapalli | 2093b25 | 2024-10-14 06:48:43 +0000 | [diff] [blame] | 305 | while (true) { |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 306 | wfi(); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * versal_net_validate_power_state() - This function ensures that the power state |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 312 | * parameter in request is valid. |
| 313 | * @power_state: Power state of core. |
| 314 | * @req_state: Requested state. |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 315 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 316 | * Return: Returns status, either PSCI_E_SUCCESS or reason. |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 317 | * |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 318 | */ |
| 319 | static int32_t versal_net_validate_power_state(unsigned int power_state, |
| 320 | psci_power_state_t *req_state) |
| 321 | { |
Maheedhar Bollapalli | d27a516 | 2024-10-29 03:34:49 +0000 | [diff] [blame] | 322 | int32_t ret = PSCI_E_INVALID_PARAMS; |
| 323 | |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 324 | VERBOSE("%s: power_state: 0x%x\n", __func__, power_state); |
| 325 | |
Maheedhar Bollapalli | 1e1d1b0 | 2024-10-22 06:53:27 +0000 | [diff] [blame] | 326 | uint32_t pstate = psci_get_pstate_type(power_state); |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 327 | |
Maheedhar Bollapalli | 311dce7 | 2024-09-27 05:55:04 +0000 | [diff] [blame] | 328 | assert(req_state != NULL); |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 329 | |
| 330 | /* Sanity check the requested state */ |
| 331 | if (pstate == PSTATE_TYPE_STANDBY) { |
| 332 | req_state->pwr_domain_state[MPIDR_AFFLVL0] = PLAT_MAX_RET_STATE; |
| 333 | } else { |
Jay Buddhabhatti | 6cd94be | 2023-03-22 22:44:16 -0700 | [diff] [blame] | 334 | req_state->pwr_domain_state[MPIDR_AFFLVL0] = PLAT_MAX_OFF_STATE; |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | /* We expect the 'state id' to be zero */ |
Maheedhar Bollapalli | d27a516 | 2024-10-29 03:34:49 +0000 | [diff] [blame] | 338 | if (psci_get_pstate_id(power_state) == 0U) { |
| 339 | ret = PSCI_E_SUCCESS; |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Maheedhar Bollapalli | d27a516 | 2024-10-29 03:34:49 +0000 | [diff] [blame] | 342 | return ret; |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 346 | * versal_net_get_sys_suspend_power_state() - Get power state for system |
| 347 | * suspend. |
| 348 | * @req_state: Requested state. |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 349 | * |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 350 | */ |
| 351 | static void versal_net_get_sys_suspend_power_state(psci_power_state_t *req_state) |
| 352 | { |
Jay Buddhabhatti | 7c5adef | 2022-12-29 21:58:35 -0800 | [diff] [blame] | 353 | uint64_t i; |
| 354 | |
Maheedhar Bollapalli | c59b1df | 2024-10-24 06:02:48 +0000 | [diff] [blame] | 355 | for (i = MPIDR_AFFLVL0; i <= PLAT_MAX_PWR_LVL; i++) { |
Jay Buddhabhatti | 7c5adef | 2022-12-29 21:58:35 -0800 | [diff] [blame] | 356 | req_state->pwr_domain_state[i] = PLAT_MAX_OFF_STATE; |
Maheedhar Bollapalli | c59b1df | 2024-10-24 06:02:48 +0000 | [diff] [blame] | 357 | } |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | static const struct plat_psci_ops versal_net_nopmc_psci_ops = { |
| 361 | .pwr_domain_on = versal_net_pwr_domain_on, |
| 362 | .pwr_domain_off = versal_net_pwr_domain_off, |
| 363 | .pwr_domain_on_finish = versal_net_pwr_domain_on_finish, |
| 364 | .pwr_domain_suspend = versal_net_pwr_domain_suspend, |
| 365 | .pwr_domain_suspend_finish = versal_net_pwr_domain_suspend_finish, |
| 366 | .system_off = versal_net_system_off, |
| 367 | .system_reset = versal_net_system_reset, |
Senthil Nathan Thangaraj | 4de8472 | 2025-04-07 20:18:27 -0700 | [diff] [blame] | 368 | .system_reset2 = versal_net_system_reset2, |
Maheedhar Bollapalli | f9617f9 | 2025-02-17 15:52:05 +0530 | [diff] [blame] | 369 | .validate_ns_entrypoint = versal_net_validate_ns_entrypoint, |
Jay Buddhabhatti | c6daff0 | 2022-09-05 02:56:32 -0700 | [diff] [blame] | 370 | .validate_power_state = versal_net_validate_power_state, |
| 371 | .get_sys_suspend_power_state = versal_net_get_sys_suspend_power_state, |
| 372 | }; |
| 373 | |
| 374 | /******************************************************************************* |
| 375 | * Export the platform specific power ops. |
| 376 | ******************************************************************************/ |
| 377 | int32_t plat_setup_psci_ops(uintptr_t sec_entrypoint, |
| 378 | const struct plat_psci_ops **psci_ops) |
| 379 | { |
| 380 | versal_net_sec_entry = sec_entrypoint; |
| 381 | |
| 382 | VERBOSE("Setting up entry point %lx\n", versal_net_sec_entry); |
| 383 | |
| 384 | *psci_ops = &versal_net_nopmc_psci_ops; |
| 385 | |
| 386 | return 0; |
| 387 | } |
| 388 | |
| 389 | int32_t sip_svc_setup_init(void) |
| 390 | { |
| 391 | return pm_setup(); |
| 392 | } |
| 393 | |
| 394 | uint64_t smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3, uint64_t x4, |
| 395 | void *cookie, void *handle, uint64_t flags) |
| 396 | { |
| 397 | return pm_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags); |
| 398 | } |