blob: 49824c70d293f5781105ec84ea07c497e077fdb7 [file] [log] [blame]
Soren Brinkmann76fcae32016-03-06 20:16:27 -08001/*
Rajan Vaja02d18422019-03-04 11:09:39 +05302 * Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved.
Soren Brinkmann76fcae32016-03-06 20:16:27 -08003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Soren Brinkmann76fcae32016-03-06 20:16:27 -08005 */
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>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013
14#include <common/runtime_svc.h>
15#if ZYNQMP_WDT_RESTART
16#include <arch_helpers.h>
17#include <drivers/arm/gicv2.h>
18#include <lib/mmio.h>
19#include <lib/spinlock.h>
20#include <plat/common/platform.h>
21#endif
22
Jolly Shah0bfd7002019-01-08 11:10:47 -080023#include <plat_private.h>
Soren Brinkmann76fcae32016-03-06 20:16:27 -080024#include "pm_api_sys.h"
25#include "pm_client.h"
26#include "pm_ipi.h"
Soren Brinkmann76fcae32016-03-06 20:16:27 -080027
Rajan Vaja02d18422019-03-04 11:09:39 +053028#define PM_GET_CALLBACK_DATA 0xa01
Siva Durga Prasad Paladugu43b23a32018-04-27 16:26:47 +053029#define PM_SET_SUSPEND_MODE 0xa02
Rajan Vajac7ee23d2018-02-14 23:10:54 -080030#define PM_GET_TRUSTZONE_VERSION 0xa03
Soren Brinkmann84f0af42016-09-30 14:24:25 -070031
Rajan Vaja720fd9d2018-10-05 04:42:57 -070032/* pm_up = !0 - UP, pm_up = 0 - DOWN */
33static int32_t pm_up, ipi_irq_flag;
Soren Brinkmann76fcae32016-03-06 20:16:27 -080034
Siva Durga Prasad Paladuguefd431b2018-04-30 20:12:12 +053035#if ZYNQMP_WDT_RESTART
36static spinlock_t inc_lock;
37static int active_cores = 0;
38#endif
39
40
Soren Brinkmann76fcae32016-03-06 20:16:27 -080041/**
42 * pm_context - Structure which contains data for power management
43 * @api_version version of PM API, must match with one on PMU side
44 * @payload payload array used to store received
45 * data from ipi buffer registers
46 */
47static struct {
48 uint32_t api_version;
49 uint32_t payload[PAYLOAD_ARG_CNT];
50} pm_ctx;
51
Siva Durga Prasad Paladuguefd431b2018-04-30 20:12:12 +053052#if ZYNQMP_WDT_RESTART
53/**
54 * trigger_wdt_restart() - Trigger warm restart event to APU cores
55 *
56 * This function triggers SGI for all active APU CPUs. SGI handler then
57 * power down CPU and call system reset.
58 */
59static void trigger_wdt_restart(void)
60{
61 uint32_t core_count = 0;
62 uint32_t core_status[3];
63 uint32_t target_cpu_list = 0;
64 int i;
65
66 for (i = 0; i < 4; i++) {
67 pm_get_node_status(NODE_APU_0 + i, core_status);
68 if (core_status[0] == 1) {
69 core_count++;
70 target_cpu_list |= (1 << i);
71 }
72 }
73
74 spin_lock(&inc_lock);
75 active_cores = core_count;
76 spin_unlock(&inc_lock);
77
78 INFO("Active Cores: %d\n", active_cores);
79
Siva Durga Prasad Paladugu60bfbc92018-09-24 22:51:49 -070080 for (i = PLATFORM_CORE_COUNT - 1; i >= 0; i--) {
81 if (target_cpu_list & (1 << i)) {
82 /* trigger SGI to active cores */
83 plat_ic_raise_el3_sgi(ARM_IRQ_SEC_SGI_7, i);
84 }
85 }
Siva Durga Prasad Paladuguefd431b2018-04-30 20:12:12 +053086}
87
88/**
89 * ttc_fiq_handler() - TTC Handler for timer event
90 * @id number of the highest priority pending interrupt of the type
91 * that this handler was registered for
92 * @flags security state, bit[0]
93 * @handler pointer to 'cpu_context' structure of the current CPU for the
94 * security state specified in the 'flags' parameter
95 * @cookie unused
96 *
97 * Function registered as INTR_TYPE_EL3 interrupt handler
98 *
99 * When WDT event is received in PMU, PMU needs to notify master to do cleanup
100 * if required. PMU sets up timer and starts timer to overflow in zero time upon
101 * WDT event. ATF handles this timer event and takes necessary action required
102 * for warm restart.
103 *
104 * In presence of non-secure software layers (EL1/2) sets the interrupt
105 * at registered entrance in GIC and informs that PMU responsed or demands
106 * action.
107 */
108static uint64_t ttc_fiq_handler(uint32_t id, uint32_t flags, void *handle,
109 void *cookie)
110{
111 INFO("BL31: Got TTC FIQ\n");
112
Siva Durga Prasad Paladugu60bfbc92018-09-24 22:51:49 -0700113 plat_ic_end_of_interrupt(id);
114
Siva Durga Prasad Paladuguefd431b2018-04-30 20:12:12 +0530115 /* Clear TTC interrupt by reading interrupt register */
116 mmio_read_32(TTC3_INTR_REGISTER_1);
117
118 /* Disable the timer interrupts */
119 mmio_write_32(TTC3_INTR_ENABLE_1, 0);
120
121 trigger_wdt_restart();
122
123 return 0;
124}
125
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800126/**
Siva Durga Prasad Paladuguefd431b2018-04-30 20:12:12 +0530127 * zynqmp_sgi7_irq() - Handler for SGI7 IRQ
128 * @id number of the highest priority pending interrupt of the type
129 * that this handler was registered for
130 * @flags security state, bit[0]
131 * @handler pointer to 'cpu_context' structure of the current CPU for the
132 * security state specified in the 'flags' parameter
133 * @cookie unused
134 *
135 * Function registered as INTR_TYPE_EL3 interrupt handler
136 *
137 * On receiving WDT event from PMU, ATF generates SGI7 to all running CPUs.
138 * In response to SGI7 interrupt, each CPUs do clean up if required and last
139 * running CPU calls system restart.
140 */
141static uint64_t __unused __dead2 zynqmp_sgi7_irq(uint32_t id, uint32_t flags,
142 void *handle, void *cookie)
143{
144 int i;
145 /* enter wfi and stay there */
146 INFO("Entering wfi\n");
147
148 spin_lock(&inc_lock);
149 active_cores--;
150
151 for (i = 0; i < 4; i++) {
152 mmio_write_32(BASE_GICD_BASE + GICD_CPENDSGIR + 4 * i,
153 0xffffffff);
154 }
155
156 spin_unlock(&inc_lock);
157
158 if (active_cores == 0) {
159 pm_system_shutdown(PMF_SHUTDOWN_TYPE_RESET,
160 PMF_SHUTDOWN_SUBTYPE_SUBSYSTEM);
161 }
162
163 /* enter wfi and stay there */
164 while (1)
165 wfi();
166}
167
168/**
169 * pm_wdt_restart_setup() - Setup warm restart interrupts
170 *
171 * This function sets up handler for SGI7 and TTC interrupts
172 * used for warm restart.
173 */
174static int pm_wdt_restart_setup(void)
175{
176 int ret;
177
178 /* register IRQ handler for SGI7 */
179 ret = request_intr_type_el3(ARM_IRQ_SEC_SGI_7, zynqmp_sgi7_irq);
180 if (ret) {
181 WARN("BL31: registering SGI7 interrupt failed\n");
182 goto err;
183 }
184
185 ret = request_intr_type_el3(IRQ_TTC3_1, ttc_fiq_handler);
186 if (ret)
187 WARN("BL31: registering TTC3 interrupt failed\n");
188
189err:
190 return ret;
191}
192#endif
193
194/**
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800195 * pm_setup() - PM service setup
196 *
197 * @return On success, the initialization function must return 0.
198 * Any other return value will cause the framework to ignore
199 * the service
200 *
201 * Initialization functions for ZynqMP power management for
202 * communicaton with PMU.
203 *
204 * Called from sip_svc_setup initialization function with the
205 * rt_svc_init signature.
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800206 */
207int pm_setup(void)
208{
Wendy Liang328105c2017-10-03 23:21:11 -0700209 int status, ret;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800210
Wendy Liang328105c2017-10-03 23:21:11 -0700211 status = pm_ipi_init(primary_proc);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800212
Rajan Vaja720fd9d2018-10-05 04:42:57 -0700213 ret = pm_get_api_version(&pm_ctx.api_version);
214 if (pm_ctx.api_version < PM_VERSION) {
215 ERROR("BL31: Platform Management API version error. Expected: "
216 "v%d.%d - Found: v%d.%d\n", PM_VERSION_MAJOR,
217 PM_VERSION_MINOR, pm_ctx.api_version >> 16,
218 pm_ctx.api_version & 0xFFFF);
219 return -EINVAL;
220 }
221
Siva Durga Prasad Paladuguefd431b2018-04-30 20:12:12 +0530222#if ZYNQMP_WDT_RESTART
223 status = pm_wdt_restart_setup();
224 if (status)
225 WARN("BL31: warm-restart setup failed\n");
226#endif
227
Wendy Liang328105c2017-10-03 23:21:11 -0700228 if (status >= 0) {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800229 INFO("BL31: PM Service Init Complete: API v%d.%d\n",
230 PM_VERSION_MAJOR, PM_VERSION_MINOR);
Wendy Liang328105c2017-10-03 23:21:11 -0700231 ret = 0;
232 } else {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800233 INFO("BL31: PM Service Init Failed, Error Code %d!\n", status);
Wendy Liang328105c2017-10-03 23:21:11 -0700234 ret = status;
235 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800236
Siva Durga Prasad Paladugu79f75952018-04-30 19:39:49 +0530237 pm_up = !status;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800238
Wendy Liang328105c2017-10-03 23:21:11 -0700239 return ret;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800240}
241
242/**
243 * pm_smc_handler() - SMC handler for PM-API calls coming from EL1/EL2.
244 * @smc_fid - Function Identifier
245 * @x1 - x4 - Arguments
246 * @cookie - Unused
247 * @handler - Pointer to caller's context structure
248 *
249 * @return - Unused
250 *
251 * Determines that smc_fid is valid and supported PM SMC Function ID from the
252 * list of pm_api_ids, otherwise completes the request with
253 * the unknown SMC Function ID
254 *
255 * The SMC calls for PM service are forwarded from SIP Service SMC handler
256 * function with rt_svc_handle signature
257 */
258uint64_t pm_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3,
259 uint64_t x4, void *cookie, void *handle, uint64_t flags)
260{
261 enum pm_ret_status ret;
262
263 uint32_t pm_arg[4];
264
265 /* Handle case where PM wasn't initialized properly */
Siva Durga Prasad Paladugu79f75952018-04-30 19:39:49 +0530266 if (!pm_up)
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800267 SMC_RET1(handle, SMC_UNK);
268
269 pm_arg[0] = (uint32_t)x1;
270 pm_arg[1] = (uint32_t)(x1 >> 32);
271 pm_arg[2] = (uint32_t)x2;
272 pm_arg[3] = (uint32_t)(x2 >> 32);
273
274 switch (smc_fid & FUNCID_NUM_MASK) {
275 /* PM API Functions */
276 case PM_SELF_SUSPEND:
277 ret = pm_self_suspend(pm_arg[0], pm_arg[1], pm_arg[2],
278 pm_arg[3]);
279 SMC_RET1(handle, (uint64_t)ret);
280
281 case PM_REQ_SUSPEND:
282 ret = pm_req_suspend(pm_arg[0], pm_arg[1], pm_arg[2],
283 pm_arg[3]);
284 SMC_RET1(handle, (uint64_t)ret);
285
286 case PM_REQ_WAKEUP:
Filip Drazic78ba1452017-02-07 12:03:57 +0100287 {
288 /* Use address flag is encoded in the 1st bit of the low-word */
289 unsigned int set_addr = pm_arg[1] & 0x1;
290 uint64_t address = (uint64_t)pm_arg[2] << 32;
291
292 address |= pm_arg[1] & (~0x1);
293 ret = pm_req_wakeup(pm_arg[0], set_addr, address,
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800294 pm_arg[3]);
295 SMC_RET1(handle, (uint64_t)ret);
Filip Drazic78ba1452017-02-07 12:03:57 +0100296 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800297
298 case PM_FORCE_POWERDOWN:
299 ret = pm_force_powerdown(pm_arg[0], pm_arg[1]);
300 SMC_RET1(handle, (uint64_t)ret);
301
302 case PM_ABORT_SUSPEND:
303 ret = pm_abort_suspend(pm_arg[0]);
304 SMC_RET1(handle, (uint64_t)ret);
305
306 case PM_SET_WAKEUP_SOURCE:
307 ret = pm_set_wakeup_source(pm_arg[0], pm_arg[1], pm_arg[2]);
308 SMC_RET1(handle, (uint64_t)ret);
309
310 case PM_SYSTEM_SHUTDOWN:
Soren Brinkmann58fbb9b2016-09-02 09:50:54 -0700311 ret = pm_system_shutdown(pm_arg[0], pm_arg[1]);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800312 SMC_RET1(handle, (uint64_t)ret);
313
314 case PM_REQ_NODE:
315 ret = pm_req_node(pm_arg[0], pm_arg[1], pm_arg[2], pm_arg[3]);
316 SMC_RET1(handle, (uint64_t)ret);
317
318 case PM_RELEASE_NODE:
319 ret = pm_release_node(pm_arg[0]);
320 SMC_RET1(handle, (uint64_t)ret);
321
322 case PM_SET_REQUIREMENT:
323 ret = pm_set_requirement(pm_arg[0], pm_arg[1], pm_arg[2],
324 pm_arg[3]);
325 SMC_RET1(handle, (uint64_t)ret);
326
327 case PM_SET_MAX_LATENCY:
328 ret = pm_set_max_latency(pm_arg[0], pm_arg[1]);
329 SMC_RET1(handle, (uint64_t)ret);
330
331 case PM_GET_API_VERSION:
332 /* Check is PM API version already verified */
Rajan Vaja720fd9d2018-10-05 04:42:57 -0700333 if (pm_ctx.api_version >= PM_VERSION) {
334 if (!ipi_irq_flag) {
335 /*
336 * Enable IPI IRQ
337 * assume the rich OS is OK to handle callback IRQs now.
338 * Even if we were wrong, it would not enable the IRQ in
339 * the GIC.
340 */
341 pm_ipi_irq_enable(primary_proc);
342 ipi_irq_flag = 1;
343 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800344 SMC_RET1(handle, (uint64_t)PM_RET_SUCCESS |
Rajan Vaja720fd9d2018-10-05 04:42:57 -0700345 ((uint64_t)pm_ctx.api_version << 32));
Soren Brinkmanna1b0a902016-09-30 11:30:21 -0700346 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800347
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800348 case PM_SET_CONFIGURATION:
349 ret = pm_set_configuration(pm_arg[0]);
350 SMC_RET1(handle, (uint64_t)ret);
351
Filip Drazicf2ddd912017-03-15 11:50:47 +0100352 case PM_INIT_FINALIZE:
353 ret = pm_init_finalize();
354 SMC_RET1(handle, (uint64_t)ret);
355
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800356 case PM_GET_NODE_STATUS:
Anes Hadziahmetagic1caf88e2017-01-27 18:42:44 +0100357 {
358 uint32_t buff[3];
359
360 ret = pm_get_node_status(pm_arg[0], buff);
361 SMC_RET2(handle, (uint64_t)ret | ((uint64_t)buff[0] << 32),
362 (uint64_t)buff[1] | ((uint64_t)buff[2] << 32));
363 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800364
365 case PM_GET_OP_CHARACTERISTIC:
Anes Hadziahmetagic92aee012016-05-12 16:17:30 +0200366 {
367 uint32_t result;
368
369 ret = pm_get_op_characteristic(pm_arg[0], pm_arg[1], &result);
370 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)result << 32));
371 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800372
373 case PM_REGISTER_NOTIFIER:
374 ret = pm_register_notifier(pm_arg[0], pm_arg[1], pm_arg[2],
375 pm_arg[3]);
376 SMC_RET1(handle, (uint64_t)ret);
377
378 case PM_RESET_ASSERT:
379 ret = pm_reset_assert(pm_arg[0], pm_arg[1]);
380 SMC_RET1(handle, (uint64_t)ret);
381
382 case PM_RESET_GET_STATUS:
383 {
384 uint32_t reset_status;
385
386 ret = pm_reset_get_status(pm_arg[0], &reset_status);
387 SMC_RET1(handle, (uint64_t)ret |
388 ((uint64_t)reset_status << 32));
389 }
390
391 /* PM memory access functions */
392 case PM_MMIO_WRITE:
393 ret = pm_mmio_write(pm_arg[0], pm_arg[1], pm_arg[2]);
394 SMC_RET1(handle, (uint64_t)ret);
395
396 case PM_MMIO_READ:
397 {
398 uint32_t value;
399
400 ret = pm_mmio_read(pm_arg[0], &value);
401 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
402 }
Nava kishore Manne68d460c2016-08-20 23:18:09 +0530403
404 case PM_FPGA_LOAD:
405 ret = pm_fpga_load(pm_arg[0], pm_arg[1], pm_arg[2], pm_arg[3]);
406 SMC_RET1(handle, (uint64_t)ret);
407
408 case PM_FPGA_GET_STATUS:
409 {
410 uint32_t value;
411
412 ret = pm_fpga_get_status(&value);
413 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
414 }
415
Siva Durga Prasad Paladugu16427d12016-08-24 11:45:47 +0530416 case PM_GET_CHIPID:
Soren Brinkmanncb366812016-09-22 12:21:11 -0700417 {
418 uint32_t result[2];
419
420 ret = pm_get_chipid(result);
421 SMC_RET2(handle, (uint64_t)ret | ((uint64_t)result[0] << 32),
422 result[1]);
423 }
Siva Durga Prasad Paladugu16427d12016-08-24 11:45:47 +0530424
Siva Durga Prasad Paladugude93d982018-04-30 15:49:27 +0530425 case PM_SECURE_RSA_AES:
426 ret = pm_secure_rsaaes(pm_arg[0], pm_arg[1], pm_arg[2],
427 pm_arg[3]);
428 SMC_RET1(handle, (uint64_t)ret);
429
Rajan Vaja02d18422019-03-04 11:09:39 +0530430 case PM_GET_CALLBACK_DATA:
431 {
432 uint32_t result[4] = {0};
433
Tejas Patelf4c3a252020-01-29 22:06:12 -0800434 pm_get_callbackdata(result, ARRAY_SIZE(result));
Rajan Vaja02d18422019-03-04 11:09:39 +0530435 SMC_RET2(handle,
436 (uint64_t)result[0] | ((uint64_t)result[1] << 32),
437 (uint64_t)result[2] | ((uint64_t)result[3] << 32));
438 }
439
Rajan Vaja83687612018-01-17 02:39:20 -0800440 case PM_PINCTRL_REQUEST:
441 ret = pm_pinctrl_request(pm_arg[0]);
442 SMC_RET1(handle, (uint64_t)ret);
443
444 case PM_PINCTRL_RELEASE:
445 ret = pm_pinctrl_release(pm_arg[0]);
446 SMC_RET1(handle, (uint64_t)ret);
447
448 case PM_PINCTRL_GET_FUNCTION:
449 {
Jolly Shah69fb5bf2018-02-07 16:25:41 -0800450 uint32_t value = 0;
Rajan Vaja83687612018-01-17 02:39:20 -0800451
452 ret = pm_pinctrl_get_function(pm_arg[0], &value);
453 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
454 }
455
456 case PM_PINCTRL_SET_FUNCTION:
457 ret = pm_pinctrl_set_function(pm_arg[0], pm_arg[1]);
458 SMC_RET1(handle, (uint64_t)ret);
459
460 case PM_PINCTRL_CONFIG_PARAM_GET:
461 {
462 uint32_t value;
463
464 ret = pm_pinctrl_get_config(pm_arg[0], pm_arg[1], &value);
465 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
466 }
467
468 case PM_PINCTRL_CONFIG_PARAM_SET:
469 ret = pm_pinctrl_set_config(pm_arg[0], pm_arg[1], pm_arg[2]);
470 SMC_RET1(handle, (uint64_t)ret);
471
Rajan Vaja5529a012018-01-17 02:39:23 -0800472 case PM_IOCTL:
473 {
474 uint32_t value;
475
476 ret = pm_ioctl(pm_arg[0], pm_arg[1], pm_arg[2],
477 pm_arg[3], &value);
478 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
479 }
480
Rajan Vaja35116132018-01-17 02:39:25 -0800481 case PM_QUERY_DATA:
482 {
Jolly Shah69fb5bf2018-02-07 16:25:41 -0800483 uint32_t data[4] = { 0 };
Rajan Vaja35116132018-01-17 02:39:25 -0800484
Rajan Vajacd825682020-11-23 21:33:39 -0800485 pm_query_data(pm_arg[0], pm_arg[1], pm_arg[2],
486 pm_arg[3], data);
Rajan Vaja35116132018-01-17 02:39:25 -0800487 SMC_RET2(handle, (uint64_t)data[0] | ((uint64_t)data[1] << 32),
488 (uint64_t)data[2] | ((uint64_t)data[3] << 32));
489 }
490
491 case PM_CLOCK_ENABLE:
492 ret = pm_clock_enable(pm_arg[0]);
493 SMC_RET1(handle, (uint64_t)ret);
494
495 case PM_CLOCK_DISABLE:
496 ret = pm_clock_disable(pm_arg[0]);
497 SMC_RET1(handle, (uint64_t)ret);
498
499 case PM_CLOCK_GETSTATE:
500 {
501 uint32_t value;
502
503 ret = pm_clock_getstate(pm_arg[0], &value);
504 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
505 }
506
507 case PM_CLOCK_SETDIVIDER:
508 ret = pm_clock_setdivider(pm_arg[0], pm_arg[1]);
509 SMC_RET1(handle, (uint64_t)ret);
510
511 case PM_CLOCK_GETDIVIDER:
512 {
513 uint32_t value;
514
515 ret = pm_clock_getdivider(pm_arg[0], &value);
516 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
517 }
518
519 case PM_CLOCK_SETRATE:
520 ret = pm_clock_setrate(pm_arg[0],
521 ((uint64_t)pm_arg[2]) << 32 | pm_arg[1]);
522
523 SMC_RET1(handle, (uint64_t)ret);
524
525 case PM_CLOCK_GETRATE:
526 {
527 uint64_t value;
528
529 ret = pm_clock_getrate(pm_arg[0], &value);
Jolly Shah69fb5bf2018-02-07 16:25:41 -0800530 SMC_RET2(handle, (uint64_t)ret |
531 (((uint64_t)value & 0xFFFFFFFFU) << 32U),
532 (value >> 32U) & 0xFFFFFFFFU);
Rajan Vaja35116132018-01-17 02:39:25 -0800533
534 }
535
536 case PM_CLOCK_SETPARENT:
537 ret = pm_clock_setparent(pm_arg[0], pm_arg[1]);
538 SMC_RET1(handle, (uint64_t)ret);
539
540 case PM_CLOCK_GETPARENT:
541 {
542 uint32_t value;
543
544 ret = pm_clock_getparent(pm_arg[0], &value);
545 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
546 }
547
Rajan Vajac7ee23d2018-02-14 23:10:54 -0800548 case PM_GET_TRUSTZONE_VERSION:
549 SMC_RET1(handle, (uint64_t)PM_RET_SUCCESS |
550 ((uint64_t)ZYNQMP_TZ_VERSION << 32));
551
Siva Durga Prasad Paladugu43b23a32018-04-27 16:26:47 +0530552 case PM_SET_SUSPEND_MODE:
553 ret = pm_set_suspend_mode(pm_arg[0]);
554 SMC_RET1(handle, (uint64_t)ret);
555
Siva Durga Prasad Paladuguf3994cc2018-05-01 11:12:55 +0530556 case PM_SECURE_SHA:
557 ret = pm_sha_hash(pm_arg[0], pm_arg[1], pm_arg[2],
558 pm_arg[3]);
559 SMC_RET1(handle, (uint64_t)ret);
560
561 case PM_SECURE_RSA:
562 ret = pm_rsa_core(pm_arg[0], pm_arg[1], pm_arg[2],
563 pm_arg[3]);
564 SMC_RET1(handle, (uint64_t)ret);
565
Siva Durga Prasad Paladugua4ed4b22018-04-30 20:06:58 +0530566 case PM_SECURE_IMAGE:
567 {
568 uint32_t result[2];
569
570 ret = pm_secure_image(pm_arg[0], pm_arg[1], pm_arg[2],
571 pm_arg[3], &result[0]);
572 SMC_RET2(handle, (uint64_t)ret | ((uint64_t)result[0] << 32),
573 result[1]);
574 }
575
Siva Durga Prasad Paladugu7c6516a2018-09-04 17:41:34 +0530576 case PM_FPGA_READ:
577 {
578 uint32_t value;
579
580 ret = pm_fpga_read(pm_arg[0], pm_arg[1], pm_arg[2], pm_arg[3],
581 &value);
582 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
583 }
584
Siva Durga Prasad Paladugu8bd905b2018-09-04 18:05:50 +0530585 case PM_SECURE_AES:
586 {
587 uint32_t value;
588
589 ret = pm_aes_engine(pm_arg[0], pm_arg[1], &value);
590 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
591 }
592
Jolly Shaha7cc5ee2019-01-02 12:27:00 -0800593 case PM_PLL_SET_PARAMETER:
594 ret = pm_pll_set_parameter(pm_arg[0], pm_arg[1], pm_arg[2]);
595 SMC_RET1(handle, (uint64_t)ret);
596
Jolly Shahcb2f45d2019-01-04 11:28:38 -0800597 case PM_PLL_GET_PARAMETER:
598 {
599 uint32_t value;
600
601 ret = pm_pll_get_parameter(pm_arg[0], pm_arg[1], &value);
602 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value << 32));
603 }
604
Jolly Shah1f0d5852019-01-04 11:32:31 -0800605 case PM_PLL_SET_MODE:
606 ret = pm_pll_set_mode(pm_arg[0], pm_arg[1]);
607 SMC_RET1(handle, (uint64_t)ret);
608
Jolly Shah141421e2019-01-04 11:35:48 -0800609 case PM_PLL_GET_MODE:
610 {
611 uint32_t mode;
612
613 ret = pm_pll_get_mode(pm_arg[0], &mode);
614 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)mode << 32));
615 }
616
Kalyani Akula6ebe4832020-11-22 22:42:10 -0800617 case PM_REGISTER_ACCESS:
618 {
619 uint32_t value;
620
621 ret = pm_register_access(pm_arg[0], pm_arg[1], pm_arg[2],
622 pm_arg[3], &value);
623 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
624 }
625
VNSL Durgadeb1a362020-11-23 04:46:04 -0800626 case PM_EFUSE_ACCESS:
627 {
628 uint32_t value;
629
630 ret = pm_efuse_access(pm_arg[0], pm_arg[1], &value);
631 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
632 }
633
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800634 default:
635 WARN("Unimplemented PM Service Call: 0x%x\n", smc_fid);
636 SMC_RET1(handle, SMC_UNK);
637 }
638}
Venkatesh Yadav Abbarapu7ace4af2020-11-23 04:26:54 -0800639
640/**
641 * em_smc_handler() - SMC handler for EM-API calls coming from EL1/EL2.
642 * @smc_fid - Function Identifier
643 * @x1 - x4 - Arguments
644 * @cookie - Unused
645 * @handler - Pointer to caller's context structure
646 *
647 * @return - Unused
648 *
649 * Determines that smc_fid is valid and supported EM SMC Function ID from the
650 * list of em_api_ids, otherwise completes the request with
651 * the unknown SMC Function ID
652 *
653 * The SMC calls for EM service are forwarded from SIP Service SMC handler
654 * function with rt_svc_handle signature
655 */
656uint64_t em_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3,
657 uint64_t x4, void *cookie, void *handle, uint64_t flags)
658{
659 enum pm_ret_status ret;
660
661 switch (smc_fid & FUNCID_NUM_MASK) {
662 /* EM API Functions */
663 case EM_SET_ACTION:
664 {
665 uint32_t value;
666
667 ret = em_set_action(&value);
668 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
669 }
670
671 case EM_REMOVE_ACTION:
672 {
673 uint32_t value;
674
675 ret = em_remove_action(&value);
676 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
677 }
678
679 case EM_SEND_ERRORS:
680 {
681 uint32_t value;
682
683 ret = em_send_errors(&value);
684 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
685 }
686
687 default:
688 WARN("Unimplemented EM Service Call: 0x%x\n", smc_fid);
689 SMC_RET1(handle, SMC_UNK);
690 }
691}