Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 1 | /* |
Rajan Vaja | 8368761 | 2018-01-17 02:39:20 -0800 | [diff] [blame] | 2 | * Copyright (c) 2013-2018, 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 | |
| 7 | /* |
| 8 | * Top-level SMC handler for ZynqMP power management calls and |
| 9 | * IPI setup functions for communication with PMU. |
| 10 | */ |
| 11 | |
| 12 | #include <errno.h> |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 13 | #include <runtime_svc.h> |
Isla Mitchell | e363146 | 2017-07-14 10:46:32 +0100 | [diff] [blame] | 14 | #include "../zynqmp_private.h" |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 15 | #include "pm_api_sys.h" |
| 16 | #include "pm_client.h" |
| 17 | #include "pm_ipi.h" |
Siva Durga Prasad Paladugu | efd431b | 2018-04-30 20:12:12 +0530 | [diff] [blame] | 18 | #if ZYNQMP_WDT_RESTART |
| 19 | #include <arch_helpers.h> |
| 20 | #include <gicv2.h> |
| 21 | #include <mmio.h> |
| 22 | #include <platform.h> |
| 23 | #include <spinlock.h> |
| 24 | #endif |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 25 | |
Siva Durga Prasad Paladugu | 43b23a3 | 2018-04-27 16:26:47 +0530 | [diff] [blame] | 26 | #define PM_SET_SUSPEND_MODE 0xa02 |
Rajan Vaja | c7ee23d | 2018-02-14 23:10:54 -0800 | [diff] [blame] | 27 | #define PM_GET_TRUSTZONE_VERSION 0xa03 |
Soren Brinkmann | 84f0af4 | 2016-09-30 14:24:25 -0700 | [diff] [blame] | 28 | |
Siva Durga Prasad Paladugu | 79f7595 | 2018-04-30 19:39:49 +0530 | [diff] [blame] | 29 | /* !0 - UP, 0 - DOWN */ |
| 30 | static int32_t pm_up = 0; |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 31 | |
Siva Durga Prasad Paladugu | efd431b | 2018-04-30 20:12:12 +0530 | [diff] [blame] | 32 | #if ZYNQMP_WDT_RESTART |
| 33 | static spinlock_t inc_lock; |
| 34 | static int active_cores = 0; |
| 35 | #endif |
| 36 | |
| 37 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 38 | /** |
| 39 | * pm_context - Structure which contains data for power management |
| 40 | * @api_version version of PM API, must match with one on PMU side |
| 41 | * @payload payload array used to store received |
| 42 | * data from ipi buffer registers |
| 43 | */ |
| 44 | static struct { |
| 45 | uint32_t api_version; |
| 46 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 47 | } pm_ctx; |
| 48 | |
Siva Durga Prasad Paladugu | efd431b | 2018-04-30 20:12:12 +0530 | [diff] [blame] | 49 | #if ZYNQMP_WDT_RESTART |
| 50 | /** |
| 51 | * trigger_wdt_restart() - Trigger warm restart event to APU cores |
| 52 | * |
| 53 | * This function triggers SGI for all active APU CPUs. SGI handler then |
| 54 | * power down CPU and call system reset. |
| 55 | */ |
| 56 | static void trigger_wdt_restart(void) |
| 57 | { |
| 58 | uint32_t core_count = 0; |
| 59 | uint32_t core_status[3]; |
| 60 | uint32_t target_cpu_list = 0; |
| 61 | int i; |
| 62 | |
| 63 | for (i = 0; i < 4; i++) { |
| 64 | pm_get_node_status(NODE_APU_0 + i, core_status); |
| 65 | if (core_status[0] == 1) { |
| 66 | core_count++; |
| 67 | target_cpu_list |= (1 << i); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | spin_lock(&inc_lock); |
| 72 | active_cores = core_count; |
| 73 | spin_unlock(&inc_lock); |
| 74 | |
| 75 | INFO("Active Cores: %d\n", active_cores); |
| 76 | |
| 77 | /* trigger SGI to active cores */ |
| 78 | gicv2_raise_sgi(ARM_IRQ_SEC_SGI_7, target_cpu_list); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * ttc_fiq_handler() - TTC Handler for timer event |
| 83 | * @id number of the highest priority pending interrupt of the type |
| 84 | * that this handler was registered for |
| 85 | * @flags security state, bit[0] |
| 86 | * @handler pointer to 'cpu_context' structure of the current CPU for the |
| 87 | * security state specified in the 'flags' parameter |
| 88 | * @cookie unused |
| 89 | * |
| 90 | * Function registered as INTR_TYPE_EL3 interrupt handler |
| 91 | * |
| 92 | * When WDT event is received in PMU, PMU needs to notify master to do cleanup |
| 93 | * if required. PMU sets up timer and starts timer to overflow in zero time upon |
| 94 | * WDT event. ATF handles this timer event and takes necessary action required |
| 95 | * for warm restart. |
| 96 | * |
| 97 | * In presence of non-secure software layers (EL1/2) sets the interrupt |
| 98 | * at registered entrance in GIC and informs that PMU responsed or demands |
| 99 | * action. |
| 100 | */ |
| 101 | static uint64_t ttc_fiq_handler(uint32_t id, uint32_t flags, void *handle, |
| 102 | void *cookie) |
| 103 | { |
| 104 | INFO("BL31: Got TTC FIQ\n"); |
| 105 | |
| 106 | /* Clear TTC interrupt by reading interrupt register */ |
| 107 | mmio_read_32(TTC3_INTR_REGISTER_1); |
| 108 | |
| 109 | /* Disable the timer interrupts */ |
| 110 | mmio_write_32(TTC3_INTR_ENABLE_1, 0); |
| 111 | |
| 112 | trigger_wdt_restart(); |
| 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 117 | /** |
Siva Durga Prasad Paladugu | efd431b | 2018-04-30 20:12:12 +0530 | [diff] [blame] | 118 | * zynqmp_sgi7_irq() - Handler for SGI7 IRQ |
| 119 | * @id number of the highest priority pending interrupt of the type |
| 120 | * that this handler was registered for |
| 121 | * @flags security state, bit[0] |
| 122 | * @handler pointer to 'cpu_context' structure of the current CPU for the |
| 123 | * security state specified in the 'flags' parameter |
| 124 | * @cookie unused |
| 125 | * |
| 126 | * Function registered as INTR_TYPE_EL3 interrupt handler |
| 127 | * |
| 128 | * On receiving WDT event from PMU, ATF generates SGI7 to all running CPUs. |
| 129 | * In response to SGI7 interrupt, each CPUs do clean up if required and last |
| 130 | * running CPU calls system restart. |
| 131 | */ |
| 132 | static uint64_t __unused __dead2 zynqmp_sgi7_irq(uint32_t id, uint32_t flags, |
| 133 | void *handle, void *cookie) |
| 134 | { |
| 135 | int i; |
| 136 | /* enter wfi and stay there */ |
| 137 | INFO("Entering wfi\n"); |
| 138 | |
| 139 | spin_lock(&inc_lock); |
| 140 | active_cores--; |
| 141 | |
| 142 | for (i = 0; i < 4; i++) { |
| 143 | mmio_write_32(BASE_GICD_BASE + GICD_CPENDSGIR + 4 * i, |
| 144 | 0xffffffff); |
| 145 | } |
| 146 | |
| 147 | spin_unlock(&inc_lock); |
| 148 | |
| 149 | if (active_cores == 0) { |
| 150 | pm_system_shutdown(PMF_SHUTDOWN_TYPE_RESET, |
| 151 | PMF_SHUTDOWN_SUBTYPE_SUBSYSTEM); |
| 152 | } |
| 153 | |
| 154 | /* enter wfi and stay there */ |
| 155 | while (1) |
| 156 | wfi(); |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * pm_wdt_restart_setup() - Setup warm restart interrupts |
| 161 | * |
| 162 | * This function sets up handler for SGI7 and TTC interrupts |
| 163 | * used for warm restart. |
| 164 | */ |
| 165 | static int pm_wdt_restart_setup(void) |
| 166 | { |
| 167 | int ret; |
| 168 | |
| 169 | /* register IRQ handler for SGI7 */ |
| 170 | ret = request_intr_type_el3(ARM_IRQ_SEC_SGI_7, zynqmp_sgi7_irq); |
| 171 | if (ret) { |
| 172 | WARN("BL31: registering SGI7 interrupt failed\n"); |
| 173 | goto err; |
| 174 | } |
| 175 | |
| 176 | ret = request_intr_type_el3(IRQ_TTC3_1, ttc_fiq_handler); |
| 177 | if (ret) |
| 178 | WARN("BL31: registering TTC3 interrupt failed\n"); |
| 179 | |
| 180 | err: |
| 181 | return ret; |
| 182 | } |
| 183 | #endif |
| 184 | |
| 185 | /** |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 186 | * pm_setup() - PM service setup |
| 187 | * |
| 188 | * @return On success, the initialization function must return 0. |
| 189 | * Any other return value will cause the framework to ignore |
| 190 | * the service |
| 191 | * |
| 192 | * Initialization functions for ZynqMP power management for |
| 193 | * communicaton with PMU. |
| 194 | * |
| 195 | * Called from sip_svc_setup initialization function with the |
| 196 | * rt_svc_init signature. |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 197 | */ |
| 198 | int pm_setup(void) |
| 199 | { |
Wendy Liang | 328105c | 2017-10-03 23:21:11 -0700 | [diff] [blame] | 200 | int status, ret; |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 201 | |
Wendy Liang | 328105c | 2017-10-03 23:21:11 -0700 | [diff] [blame] | 202 | status = pm_ipi_init(primary_proc); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 203 | |
Siva Durga Prasad Paladugu | efd431b | 2018-04-30 20:12:12 +0530 | [diff] [blame] | 204 | #if ZYNQMP_WDT_RESTART |
| 205 | status = pm_wdt_restart_setup(); |
| 206 | if (status) |
| 207 | WARN("BL31: warm-restart setup failed\n"); |
| 208 | #endif |
| 209 | |
Wendy Liang | 328105c | 2017-10-03 23:21:11 -0700 | [diff] [blame] | 210 | if (status >= 0) { |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 211 | INFO("BL31: PM Service Init Complete: API v%d.%d\n", |
| 212 | PM_VERSION_MAJOR, PM_VERSION_MINOR); |
Wendy Liang | 328105c | 2017-10-03 23:21:11 -0700 | [diff] [blame] | 213 | ret = 0; |
| 214 | } else { |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 215 | INFO("BL31: PM Service Init Failed, Error Code %d!\n", status); |
Wendy Liang | 328105c | 2017-10-03 23:21:11 -0700 | [diff] [blame] | 216 | ret = status; |
| 217 | } |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 218 | |
Siva Durga Prasad Paladugu | 79f7595 | 2018-04-30 19:39:49 +0530 | [diff] [blame] | 219 | pm_up = !status; |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 220 | |
Wendy Liang | 328105c | 2017-10-03 23:21:11 -0700 | [diff] [blame] | 221 | return ret; |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | /** |
| 225 | * pm_smc_handler() - SMC handler for PM-API calls coming from EL1/EL2. |
| 226 | * @smc_fid - Function Identifier |
| 227 | * @x1 - x4 - Arguments |
| 228 | * @cookie - Unused |
| 229 | * @handler - Pointer to caller's context structure |
| 230 | * |
| 231 | * @return - Unused |
| 232 | * |
| 233 | * Determines that smc_fid is valid and supported PM SMC Function ID from the |
| 234 | * list of pm_api_ids, otherwise completes the request with |
| 235 | * the unknown SMC Function ID |
| 236 | * |
| 237 | * The SMC calls for PM service are forwarded from SIP Service SMC handler |
| 238 | * function with rt_svc_handle signature |
| 239 | */ |
| 240 | uint64_t pm_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3, |
| 241 | uint64_t x4, void *cookie, void *handle, uint64_t flags) |
| 242 | { |
| 243 | enum pm_ret_status ret; |
| 244 | |
| 245 | uint32_t pm_arg[4]; |
| 246 | |
| 247 | /* Handle case where PM wasn't initialized properly */ |
Siva Durga Prasad Paladugu | 79f7595 | 2018-04-30 19:39:49 +0530 | [diff] [blame] | 248 | if (!pm_up) |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 249 | SMC_RET1(handle, SMC_UNK); |
| 250 | |
| 251 | pm_arg[0] = (uint32_t)x1; |
| 252 | pm_arg[1] = (uint32_t)(x1 >> 32); |
| 253 | pm_arg[2] = (uint32_t)x2; |
| 254 | pm_arg[3] = (uint32_t)(x2 >> 32); |
| 255 | |
| 256 | switch (smc_fid & FUNCID_NUM_MASK) { |
| 257 | /* PM API Functions */ |
| 258 | case PM_SELF_SUSPEND: |
| 259 | ret = pm_self_suspend(pm_arg[0], pm_arg[1], pm_arg[2], |
| 260 | pm_arg[3]); |
| 261 | SMC_RET1(handle, (uint64_t)ret); |
| 262 | |
| 263 | case PM_REQ_SUSPEND: |
| 264 | ret = pm_req_suspend(pm_arg[0], pm_arg[1], pm_arg[2], |
| 265 | pm_arg[3]); |
| 266 | SMC_RET1(handle, (uint64_t)ret); |
| 267 | |
| 268 | case PM_REQ_WAKEUP: |
Filip Drazic | 78ba145 | 2017-02-07 12:03:57 +0100 | [diff] [blame] | 269 | { |
| 270 | /* Use address flag is encoded in the 1st bit of the low-word */ |
| 271 | unsigned int set_addr = pm_arg[1] & 0x1; |
| 272 | uint64_t address = (uint64_t)pm_arg[2] << 32; |
| 273 | |
| 274 | address |= pm_arg[1] & (~0x1); |
| 275 | ret = pm_req_wakeup(pm_arg[0], set_addr, address, |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 276 | pm_arg[3]); |
| 277 | SMC_RET1(handle, (uint64_t)ret); |
Filip Drazic | 78ba145 | 2017-02-07 12:03:57 +0100 | [diff] [blame] | 278 | } |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 279 | |
| 280 | case PM_FORCE_POWERDOWN: |
| 281 | ret = pm_force_powerdown(pm_arg[0], pm_arg[1]); |
| 282 | SMC_RET1(handle, (uint64_t)ret); |
| 283 | |
| 284 | case PM_ABORT_SUSPEND: |
| 285 | ret = pm_abort_suspend(pm_arg[0]); |
| 286 | SMC_RET1(handle, (uint64_t)ret); |
| 287 | |
| 288 | case PM_SET_WAKEUP_SOURCE: |
| 289 | ret = pm_set_wakeup_source(pm_arg[0], pm_arg[1], pm_arg[2]); |
| 290 | SMC_RET1(handle, (uint64_t)ret); |
| 291 | |
| 292 | case PM_SYSTEM_SHUTDOWN: |
Soren Brinkmann | 58fbb9b | 2016-09-02 09:50:54 -0700 | [diff] [blame] | 293 | ret = pm_system_shutdown(pm_arg[0], pm_arg[1]); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 294 | SMC_RET1(handle, (uint64_t)ret); |
| 295 | |
| 296 | case PM_REQ_NODE: |
| 297 | ret = pm_req_node(pm_arg[0], pm_arg[1], pm_arg[2], pm_arg[3]); |
| 298 | SMC_RET1(handle, (uint64_t)ret); |
| 299 | |
| 300 | case PM_RELEASE_NODE: |
| 301 | ret = pm_release_node(pm_arg[0]); |
| 302 | SMC_RET1(handle, (uint64_t)ret); |
| 303 | |
| 304 | case PM_SET_REQUIREMENT: |
| 305 | ret = pm_set_requirement(pm_arg[0], pm_arg[1], pm_arg[2], |
| 306 | pm_arg[3]); |
| 307 | SMC_RET1(handle, (uint64_t)ret); |
| 308 | |
| 309 | case PM_SET_MAX_LATENCY: |
| 310 | ret = pm_set_max_latency(pm_arg[0], pm_arg[1]); |
| 311 | SMC_RET1(handle, (uint64_t)ret); |
| 312 | |
| 313 | case PM_GET_API_VERSION: |
| 314 | /* Check is PM API version already verified */ |
Soren Brinkmann | a1b0a90 | 2016-09-30 11:30:21 -0700 | [diff] [blame] | 315 | if (pm_ctx.api_version == PM_VERSION) { |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 316 | SMC_RET1(handle, (uint64_t)PM_RET_SUCCESS | |
| 317 | ((uint64_t)PM_VERSION << 32)); |
Soren Brinkmann | a1b0a90 | 2016-09-30 11:30:21 -0700 | [diff] [blame] | 318 | } |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 319 | |
| 320 | ret = pm_get_api_version(&pm_ctx.api_version); |
Soren Brinkmann | a1b0a90 | 2016-09-30 11:30:21 -0700 | [diff] [blame] | 321 | /* |
| 322 | * Enable IPI IRQ |
| 323 | * assume the rich OS is OK to handle callback IRQs now. |
| 324 | * Even if we were wrong, it would not enable the IRQ in |
| 325 | * the GIC. |
| 326 | */ |
Wendy Liang | 328105c | 2017-10-03 23:21:11 -0700 | [diff] [blame] | 327 | pm_ipi_irq_enable(primary_proc); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 328 | SMC_RET1(handle, (uint64_t)ret | |
| 329 | ((uint64_t)pm_ctx.api_version << 32)); |
| 330 | |
| 331 | case PM_SET_CONFIGURATION: |
| 332 | ret = pm_set_configuration(pm_arg[0]); |
| 333 | SMC_RET1(handle, (uint64_t)ret); |
| 334 | |
Filip Drazic | f2ddd91 | 2017-03-15 11:50:47 +0100 | [diff] [blame] | 335 | case PM_INIT_FINALIZE: |
| 336 | ret = pm_init_finalize(); |
| 337 | SMC_RET1(handle, (uint64_t)ret); |
| 338 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 339 | case PM_GET_NODE_STATUS: |
Anes Hadziahmetagic | 1caf88e | 2017-01-27 18:42:44 +0100 | [diff] [blame] | 340 | { |
| 341 | uint32_t buff[3]; |
| 342 | |
| 343 | ret = pm_get_node_status(pm_arg[0], buff); |
| 344 | SMC_RET2(handle, (uint64_t)ret | ((uint64_t)buff[0] << 32), |
| 345 | (uint64_t)buff[1] | ((uint64_t)buff[2] << 32)); |
| 346 | } |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 347 | |
| 348 | case PM_GET_OP_CHARACTERISTIC: |
Anes Hadziahmetagic | 92aee01 | 2016-05-12 16:17:30 +0200 | [diff] [blame] | 349 | { |
| 350 | uint32_t result; |
| 351 | |
| 352 | ret = pm_get_op_characteristic(pm_arg[0], pm_arg[1], &result); |
| 353 | SMC_RET1(handle, (uint64_t)ret | ((uint64_t)result << 32)); |
| 354 | } |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 355 | |
| 356 | case PM_REGISTER_NOTIFIER: |
| 357 | ret = pm_register_notifier(pm_arg[0], pm_arg[1], pm_arg[2], |
| 358 | pm_arg[3]); |
| 359 | SMC_RET1(handle, (uint64_t)ret); |
| 360 | |
| 361 | case PM_RESET_ASSERT: |
| 362 | ret = pm_reset_assert(pm_arg[0], pm_arg[1]); |
| 363 | SMC_RET1(handle, (uint64_t)ret); |
| 364 | |
| 365 | case PM_RESET_GET_STATUS: |
| 366 | { |
| 367 | uint32_t reset_status; |
| 368 | |
| 369 | ret = pm_reset_get_status(pm_arg[0], &reset_status); |
| 370 | SMC_RET1(handle, (uint64_t)ret | |
| 371 | ((uint64_t)reset_status << 32)); |
| 372 | } |
| 373 | |
| 374 | /* PM memory access functions */ |
| 375 | case PM_MMIO_WRITE: |
| 376 | ret = pm_mmio_write(pm_arg[0], pm_arg[1], pm_arg[2]); |
| 377 | SMC_RET1(handle, (uint64_t)ret); |
| 378 | |
| 379 | case PM_MMIO_READ: |
| 380 | { |
| 381 | uint32_t value; |
| 382 | |
| 383 | ret = pm_mmio_read(pm_arg[0], &value); |
| 384 | SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32); |
| 385 | } |
Nava kishore Manne | 68d460c | 2016-08-20 23:18:09 +0530 | [diff] [blame] | 386 | |
| 387 | case PM_FPGA_LOAD: |
| 388 | ret = pm_fpga_load(pm_arg[0], pm_arg[1], pm_arg[2], pm_arg[3]); |
| 389 | SMC_RET1(handle, (uint64_t)ret); |
| 390 | |
| 391 | case PM_FPGA_GET_STATUS: |
| 392 | { |
| 393 | uint32_t value; |
| 394 | |
| 395 | ret = pm_fpga_get_status(&value); |
| 396 | SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32); |
| 397 | } |
| 398 | |
Siva Durga Prasad Paladugu | 16427d1 | 2016-08-24 11:45:47 +0530 | [diff] [blame] | 399 | case PM_GET_CHIPID: |
Soren Brinkmann | cb36681 | 2016-09-22 12:21:11 -0700 | [diff] [blame] | 400 | { |
| 401 | uint32_t result[2]; |
| 402 | |
| 403 | ret = pm_get_chipid(result); |
| 404 | SMC_RET2(handle, (uint64_t)ret | ((uint64_t)result[0] << 32), |
| 405 | result[1]); |
| 406 | } |
Siva Durga Prasad Paladugu | 16427d1 | 2016-08-24 11:45:47 +0530 | [diff] [blame] | 407 | |
Siva Durga Prasad Paladugu | de93d98 | 2018-04-30 15:49:27 +0530 | [diff] [blame] | 408 | case PM_SECURE_RSA_AES: |
| 409 | ret = pm_secure_rsaaes(pm_arg[0], pm_arg[1], pm_arg[2], |
| 410 | pm_arg[3]); |
| 411 | SMC_RET1(handle, (uint64_t)ret); |
| 412 | |
Rajan Vaja | 8368761 | 2018-01-17 02:39:20 -0800 | [diff] [blame] | 413 | case PM_PINCTRL_REQUEST: |
| 414 | ret = pm_pinctrl_request(pm_arg[0]); |
| 415 | SMC_RET1(handle, (uint64_t)ret); |
| 416 | |
| 417 | case PM_PINCTRL_RELEASE: |
| 418 | ret = pm_pinctrl_release(pm_arg[0]); |
| 419 | SMC_RET1(handle, (uint64_t)ret); |
| 420 | |
| 421 | case PM_PINCTRL_GET_FUNCTION: |
| 422 | { |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 423 | uint32_t value = 0; |
Rajan Vaja | 8368761 | 2018-01-17 02:39:20 -0800 | [diff] [blame] | 424 | |
| 425 | ret = pm_pinctrl_get_function(pm_arg[0], &value); |
| 426 | SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32); |
| 427 | } |
| 428 | |
| 429 | case PM_PINCTRL_SET_FUNCTION: |
| 430 | ret = pm_pinctrl_set_function(pm_arg[0], pm_arg[1]); |
| 431 | SMC_RET1(handle, (uint64_t)ret); |
| 432 | |
| 433 | case PM_PINCTRL_CONFIG_PARAM_GET: |
| 434 | { |
| 435 | uint32_t value; |
| 436 | |
| 437 | ret = pm_pinctrl_get_config(pm_arg[0], pm_arg[1], &value); |
| 438 | SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32); |
| 439 | } |
| 440 | |
| 441 | case PM_PINCTRL_CONFIG_PARAM_SET: |
| 442 | ret = pm_pinctrl_set_config(pm_arg[0], pm_arg[1], pm_arg[2]); |
| 443 | SMC_RET1(handle, (uint64_t)ret); |
| 444 | |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 445 | case PM_IOCTL: |
| 446 | { |
| 447 | uint32_t value; |
| 448 | |
| 449 | ret = pm_ioctl(pm_arg[0], pm_arg[1], pm_arg[2], |
| 450 | pm_arg[3], &value); |
| 451 | SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32); |
| 452 | } |
| 453 | |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 454 | case PM_QUERY_DATA: |
| 455 | { |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 456 | uint32_t data[4] = { 0 }; |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 457 | |
| 458 | ret = pm_query_data(pm_arg[0], pm_arg[1], pm_arg[2], |
| 459 | pm_arg[3], data); |
| 460 | SMC_RET2(handle, (uint64_t)data[0] | ((uint64_t)data[1] << 32), |
| 461 | (uint64_t)data[2] | ((uint64_t)data[3] << 32)); |
| 462 | } |
| 463 | |
| 464 | case PM_CLOCK_ENABLE: |
| 465 | ret = pm_clock_enable(pm_arg[0]); |
| 466 | SMC_RET1(handle, (uint64_t)ret); |
| 467 | |
| 468 | case PM_CLOCK_DISABLE: |
| 469 | ret = pm_clock_disable(pm_arg[0]); |
| 470 | SMC_RET1(handle, (uint64_t)ret); |
| 471 | |
| 472 | case PM_CLOCK_GETSTATE: |
| 473 | { |
| 474 | uint32_t value; |
| 475 | |
| 476 | ret = pm_clock_getstate(pm_arg[0], &value); |
| 477 | SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32); |
| 478 | } |
| 479 | |
| 480 | case PM_CLOCK_SETDIVIDER: |
| 481 | ret = pm_clock_setdivider(pm_arg[0], pm_arg[1]); |
| 482 | SMC_RET1(handle, (uint64_t)ret); |
| 483 | |
| 484 | case PM_CLOCK_GETDIVIDER: |
| 485 | { |
| 486 | uint32_t value; |
| 487 | |
| 488 | ret = pm_clock_getdivider(pm_arg[0], &value); |
| 489 | SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32); |
| 490 | } |
| 491 | |
| 492 | case PM_CLOCK_SETRATE: |
| 493 | ret = pm_clock_setrate(pm_arg[0], |
| 494 | ((uint64_t)pm_arg[2]) << 32 | pm_arg[1]); |
| 495 | |
| 496 | SMC_RET1(handle, (uint64_t)ret); |
| 497 | |
| 498 | case PM_CLOCK_GETRATE: |
| 499 | { |
| 500 | uint64_t value; |
| 501 | |
| 502 | ret = pm_clock_getrate(pm_arg[0], &value); |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 503 | SMC_RET2(handle, (uint64_t)ret | |
| 504 | (((uint64_t)value & 0xFFFFFFFFU) << 32U), |
| 505 | (value >> 32U) & 0xFFFFFFFFU); |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 506 | |
| 507 | } |
| 508 | |
| 509 | case PM_CLOCK_SETPARENT: |
| 510 | ret = pm_clock_setparent(pm_arg[0], pm_arg[1]); |
| 511 | SMC_RET1(handle, (uint64_t)ret); |
| 512 | |
| 513 | case PM_CLOCK_GETPARENT: |
| 514 | { |
| 515 | uint32_t value; |
| 516 | |
| 517 | ret = pm_clock_getparent(pm_arg[0], &value); |
| 518 | SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32); |
| 519 | } |
| 520 | |
Rajan Vaja | c7ee23d | 2018-02-14 23:10:54 -0800 | [diff] [blame] | 521 | case PM_GET_TRUSTZONE_VERSION: |
| 522 | SMC_RET1(handle, (uint64_t)PM_RET_SUCCESS | |
| 523 | ((uint64_t)ZYNQMP_TZ_VERSION << 32)); |
| 524 | |
Siva Durga Prasad Paladugu | 43b23a3 | 2018-04-27 16:26:47 +0530 | [diff] [blame] | 525 | case PM_SET_SUSPEND_MODE: |
| 526 | ret = pm_set_suspend_mode(pm_arg[0]); |
| 527 | SMC_RET1(handle, (uint64_t)ret); |
| 528 | |
Siva Durga Prasad Paladugu | f3994cc | 2018-05-01 11:12:55 +0530 | [diff] [blame] | 529 | case PM_SECURE_SHA: |
| 530 | ret = pm_sha_hash(pm_arg[0], pm_arg[1], pm_arg[2], |
| 531 | pm_arg[3]); |
| 532 | SMC_RET1(handle, (uint64_t)ret); |
| 533 | |
| 534 | case PM_SECURE_RSA: |
| 535 | ret = pm_rsa_core(pm_arg[0], pm_arg[1], pm_arg[2], |
| 536 | pm_arg[3]); |
| 537 | SMC_RET1(handle, (uint64_t)ret); |
| 538 | |
Siva Durga Prasad Paladugu | a4ed4b2 | 2018-04-30 20:06:58 +0530 | [diff] [blame] | 539 | case PM_SECURE_IMAGE: |
| 540 | { |
| 541 | uint32_t result[2]; |
| 542 | |
| 543 | ret = pm_secure_image(pm_arg[0], pm_arg[1], pm_arg[2], |
| 544 | pm_arg[3], &result[0]); |
| 545 | SMC_RET2(handle, (uint64_t)ret | ((uint64_t)result[0] << 32), |
| 546 | result[1]); |
| 547 | } |
| 548 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 549 | default: |
| 550 | WARN("Unimplemented PM Service Call: 0x%x\n", smc_fid); |
| 551 | SMC_RET1(handle, SMC_UNK); |
| 552 | } |
| 553 | } |