blob: b789da14ce7d233c48d40fe7737fc3e0ae5b33fc [file] [log] [blame]
Soren Brinkmann76fcae32016-03-06 20:16:27 -08001/*
Ronak Jain325bad12021-12-21 01:39:59 -08002 * Copyright (c) 2013-2022, 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"
Ronak Jain325bad12021-12-21 01:39:59 -080026#include "pm_defs.h"
Soren Brinkmann76fcae32016-03-06 20:16:27 -080027#include "pm_ipi.h"
Soren Brinkmann76fcae32016-03-06 20:16:27 -080028
Rajan Vaja720fd9d2018-10-05 04:42:57 -070029/* pm_up = !0 - UP, pm_up = 0 - DOWN */
30static int32_t pm_up, ipi_irq_flag;
Soren Brinkmann76fcae32016-03-06 20:16:27 -080031
Siva Durga Prasad Paladuguefd431b2018-04-30 20:12:12 +053032#if ZYNQMP_WDT_RESTART
33static spinlock_t inc_lock;
34static int active_cores = 0;
35#endif
36
37
Soren Brinkmann76fcae32016-03-06 20:16:27 -080038/**
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 */
44static struct {
45 uint32_t api_version;
46 uint32_t payload[PAYLOAD_ARG_CNT];
47} pm_ctx;
48
Siva Durga Prasad Paladuguefd431b2018-04-30 20:12:12 +053049#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 */
56static 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
Siva Durga Prasad Paladugu60bfbc92018-09-24 22:51:49 -070077 for (i = PLATFORM_CORE_COUNT - 1; i >= 0; i--) {
78 if (target_cpu_list & (1 << i)) {
79 /* trigger SGI to active cores */
80 plat_ic_raise_el3_sgi(ARM_IRQ_SEC_SGI_7, i);
81 }
82 }
Siva Durga Prasad Paladuguefd431b2018-04-30 20:12:12 +053083}
84
85/**
86 * ttc_fiq_handler() - TTC Handler for timer event
87 * @id number of the highest priority pending interrupt of the type
88 * that this handler was registered for
89 * @flags security state, bit[0]
90 * @handler pointer to 'cpu_context' structure of the current CPU for the
91 * security state specified in the 'flags' parameter
92 * @cookie unused
93 *
94 * Function registered as INTR_TYPE_EL3 interrupt handler
95 *
96 * When WDT event is received in PMU, PMU needs to notify master to do cleanup
97 * if required. PMU sets up timer and starts timer to overflow in zero time upon
98 * WDT event. ATF handles this timer event and takes necessary action required
99 * for warm restart.
100 *
101 * In presence of non-secure software layers (EL1/2) sets the interrupt
102 * at registered entrance in GIC and informs that PMU responsed or demands
103 * action.
104 */
105static uint64_t ttc_fiq_handler(uint32_t id, uint32_t flags, void *handle,
106 void *cookie)
107{
108 INFO("BL31: Got TTC FIQ\n");
109
Siva Durga Prasad Paladugu60bfbc92018-09-24 22:51:49 -0700110 plat_ic_end_of_interrupt(id);
111
Siva Durga Prasad Paladuguefd431b2018-04-30 20:12:12 +0530112 /* Clear TTC interrupt by reading interrupt register */
113 mmio_read_32(TTC3_INTR_REGISTER_1);
114
115 /* Disable the timer interrupts */
116 mmio_write_32(TTC3_INTR_ENABLE_1, 0);
117
118 trigger_wdt_restart();
119
120 return 0;
121}
122
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800123/**
Siva Durga Prasad Paladuguefd431b2018-04-30 20:12:12 +0530124 * zynqmp_sgi7_irq() - Handler for SGI7 IRQ
125 * @id number of the highest priority pending interrupt of the type
126 * that this handler was registered for
127 * @flags security state, bit[0]
128 * @handler pointer to 'cpu_context' structure of the current CPU for the
129 * security state specified in the 'flags' parameter
130 * @cookie unused
131 *
132 * Function registered as INTR_TYPE_EL3 interrupt handler
133 *
134 * On receiving WDT event from PMU, ATF generates SGI7 to all running CPUs.
135 * In response to SGI7 interrupt, each CPUs do clean up if required and last
136 * running CPU calls system restart.
137 */
138static uint64_t __unused __dead2 zynqmp_sgi7_irq(uint32_t id, uint32_t flags,
139 void *handle, void *cookie)
140{
141 int i;
Will Wongcc127952020-11-22 23:45:21 -0800142 uint32_t value;
143
Siva Durga Prasad Paladuguefd431b2018-04-30 20:12:12 +0530144 /* enter wfi and stay there */
145 INFO("Entering wfi\n");
146
147 spin_lock(&inc_lock);
148 active_cores--;
149
150 for (i = 0; i < 4; i++) {
151 mmio_write_32(BASE_GICD_BASE + GICD_CPENDSGIR + 4 * i,
152 0xffffffff);
153 }
154
155 spin_unlock(&inc_lock);
156
157 if (active_cores == 0) {
Will Wongcc127952020-11-22 23:45:21 -0800158 pm_mmio_read(PMU_GLOBAL_GEN_STORAGE4, &value);
159 value = (value & RESTART_SCOPE_MASK) >> RESTART_SCOPE_SHIFT;
160 pm_system_shutdown(PMF_SHUTDOWN_TYPE_RESET, value);
Siva Durga Prasad Paladuguefd431b2018-04-30 20:12:12 +0530161 }
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;
Ronak Jain52de5942022-01-20 23:11:18 -0800262 uint32_t payload[PAYLOAD_ARG_CNT];
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800263
264 uint32_t pm_arg[4];
Ronak Jain52de5942022-01-20 23:11:18 -0800265 uint32_t result[PAYLOAD_ARG_CNT];
266 uint32_t api_id;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800267
268 /* Handle case where PM wasn't initialized properly */
Siva Durga Prasad Paladugu79f75952018-04-30 19:39:49 +0530269 if (!pm_up)
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800270 SMC_RET1(handle, SMC_UNK);
271
272 pm_arg[0] = (uint32_t)x1;
273 pm_arg[1] = (uint32_t)(x1 >> 32);
274 pm_arg[2] = (uint32_t)x2;
275 pm_arg[3] = (uint32_t)(x2 >> 32);
Ronak Jain52de5942022-01-20 23:11:18 -0800276 pm_arg[4] = (uint32_t)x3;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800277
Ronak Jain52de5942022-01-20 23:11:18 -0800278 api_id = smc_fid & FUNCID_NUM_MASK;
279
280 switch (api_id) {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800281 /* PM API Functions */
282 case PM_SELF_SUSPEND:
283 ret = pm_self_suspend(pm_arg[0], pm_arg[1], pm_arg[2],
284 pm_arg[3]);
285 SMC_RET1(handle, (uint64_t)ret);
286
287 case PM_REQ_SUSPEND:
288 ret = pm_req_suspend(pm_arg[0], pm_arg[1], pm_arg[2],
289 pm_arg[3]);
290 SMC_RET1(handle, (uint64_t)ret);
291
292 case PM_REQ_WAKEUP:
Filip Drazic78ba1452017-02-07 12:03:57 +0100293 {
294 /* Use address flag is encoded in the 1st bit of the low-word */
295 unsigned int set_addr = pm_arg[1] & 0x1;
296 uint64_t address = (uint64_t)pm_arg[2] << 32;
297
298 address |= pm_arg[1] & (~0x1);
299 ret = pm_req_wakeup(pm_arg[0], set_addr, address,
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800300 pm_arg[3]);
301 SMC_RET1(handle, (uint64_t)ret);
Filip Drazic78ba1452017-02-07 12:03:57 +0100302 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800303
304 case PM_FORCE_POWERDOWN:
305 ret = pm_force_powerdown(pm_arg[0], pm_arg[1]);
306 SMC_RET1(handle, (uint64_t)ret);
307
308 case PM_ABORT_SUSPEND:
309 ret = pm_abort_suspend(pm_arg[0]);
310 SMC_RET1(handle, (uint64_t)ret);
311
312 case PM_SET_WAKEUP_SOURCE:
313 ret = pm_set_wakeup_source(pm_arg[0], pm_arg[1], pm_arg[2]);
314 SMC_RET1(handle, (uint64_t)ret);
315
316 case PM_SYSTEM_SHUTDOWN:
Soren Brinkmann58fbb9b2016-09-02 09:50:54 -0700317 ret = pm_system_shutdown(pm_arg[0], pm_arg[1]);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800318 SMC_RET1(handle, (uint64_t)ret);
319
320 case PM_REQ_NODE:
321 ret = pm_req_node(pm_arg[0], pm_arg[1], pm_arg[2], pm_arg[3]);
322 SMC_RET1(handle, (uint64_t)ret);
323
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800324 case PM_SET_REQUIREMENT:
325 ret = pm_set_requirement(pm_arg[0], pm_arg[1], pm_arg[2],
326 pm_arg[3]);
327 SMC_RET1(handle, (uint64_t)ret);
328
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800329 case PM_GET_API_VERSION:
330 /* Check is PM API version already verified */
Rajan Vaja720fd9d2018-10-05 04:42:57 -0700331 if (pm_ctx.api_version >= PM_VERSION) {
332 if (!ipi_irq_flag) {
333 /*
334 * Enable IPI IRQ
335 * assume the rich OS is OK to handle callback IRQs now.
336 * Even if we were wrong, it would not enable the IRQ in
337 * the GIC.
338 */
339 pm_ipi_irq_enable(primary_proc);
340 ipi_irq_flag = 1;
341 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800342 SMC_RET1(handle, (uint64_t)PM_RET_SUCCESS |
Rajan Vaja720fd9d2018-10-05 04:42:57 -0700343 ((uint64_t)pm_ctx.api_version << 32));
Soren Brinkmanna1b0a902016-09-30 11:30:21 -0700344 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800345
Nava kishore Manne68d460c2016-08-20 23:18:09 +0530346 case PM_FPGA_LOAD:
347 ret = pm_fpga_load(pm_arg[0], pm_arg[1], pm_arg[2], pm_arg[3]);
348 SMC_RET1(handle, (uint64_t)ret);
349
350 case PM_FPGA_GET_STATUS:
351 {
352 uint32_t value;
353
354 ret = pm_fpga_get_status(&value);
355 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
356 }
357
Siva Durga Prasad Paladugude93d982018-04-30 15:49:27 +0530358 case PM_SECURE_RSA_AES:
359 ret = pm_secure_rsaaes(pm_arg[0], pm_arg[1], pm_arg[2],
360 pm_arg[3]);
361 SMC_RET1(handle, (uint64_t)ret);
362
Rajan Vaja02d18422019-03-04 11:09:39 +0530363 case PM_GET_CALLBACK_DATA:
Tejas Patelf4c3a252020-01-29 22:06:12 -0800364 pm_get_callbackdata(result, ARRAY_SIZE(result));
Rajan Vaja02d18422019-03-04 11:09:39 +0530365 SMC_RET2(handle,
366 (uint64_t)result[0] | ((uint64_t)result[1] << 32),
367 (uint64_t)result[2] | ((uint64_t)result[3] << 32));
Rajan Vaja5529a012018-01-17 02:39:23 -0800368 case PM_IOCTL:
369 {
370 uint32_t value;
371
372 ret = pm_ioctl(pm_arg[0], pm_arg[1], pm_arg[2],
373 pm_arg[3], &value);
374 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
375 }
376
Rajan Vaja35116132018-01-17 02:39:25 -0800377 case PM_QUERY_DATA:
378 {
Jolly Shah69fb5bf2018-02-07 16:25:41 -0800379 uint32_t data[4] = { 0 };
Rajan Vaja35116132018-01-17 02:39:25 -0800380
Rajan Vajacd825682020-11-23 21:33:39 -0800381 pm_query_data(pm_arg[0], pm_arg[1], pm_arg[2],
382 pm_arg[3], data);
Rajan Vaja35116132018-01-17 02:39:25 -0800383 SMC_RET2(handle, (uint64_t)data[0] | ((uint64_t)data[1] << 32),
384 (uint64_t)data[2] | ((uint64_t)data[3] << 32));
385 }
386
387 case PM_CLOCK_ENABLE:
388 ret = pm_clock_enable(pm_arg[0]);
389 SMC_RET1(handle, (uint64_t)ret);
390
391 case PM_CLOCK_DISABLE:
392 ret = pm_clock_disable(pm_arg[0]);
393 SMC_RET1(handle, (uint64_t)ret);
394
395 case PM_CLOCK_GETSTATE:
396 {
397 uint32_t value;
398
399 ret = pm_clock_getstate(pm_arg[0], &value);
400 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
401 }
402
403 case PM_CLOCK_SETDIVIDER:
404 ret = pm_clock_setdivider(pm_arg[0], pm_arg[1]);
405 SMC_RET1(handle, (uint64_t)ret);
406
407 case PM_CLOCK_GETDIVIDER:
408 {
409 uint32_t value;
410
411 ret = pm_clock_getdivider(pm_arg[0], &value);
412 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
413 }
414
415 case PM_CLOCK_SETRATE:
416 ret = pm_clock_setrate(pm_arg[0],
417 ((uint64_t)pm_arg[2]) << 32 | pm_arg[1]);
418
419 SMC_RET1(handle, (uint64_t)ret);
420
421 case PM_CLOCK_GETRATE:
422 {
423 uint64_t value;
424
425 ret = pm_clock_getrate(pm_arg[0], &value);
Jolly Shah69fb5bf2018-02-07 16:25:41 -0800426 SMC_RET2(handle, (uint64_t)ret |
427 (((uint64_t)value & 0xFFFFFFFFU) << 32U),
428 (value >> 32U) & 0xFFFFFFFFU);
Rajan Vaja35116132018-01-17 02:39:25 -0800429
430 }
431
432 case PM_CLOCK_SETPARENT:
433 ret = pm_clock_setparent(pm_arg[0], pm_arg[1]);
434 SMC_RET1(handle, (uint64_t)ret);
435
436 case PM_CLOCK_GETPARENT:
437 {
438 uint32_t value;
439
440 ret = pm_clock_getparent(pm_arg[0], &value);
441 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
442 }
443
Rajan Vajac7ee23d2018-02-14 23:10:54 -0800444 case PM_GET_TRUSTZONE_VERSION:
445 SMC_RET1(handle, (uint64_t)PM_RET_SUCCESS |
446 ((uint64_t)ZYNQMP_TZ_VERSION << 32));
447
Siva Durga Prasad Paladugu43b23a32018-04-27 16:26:47 +0530448 case PM_SET_SUSPEND_MODE:
449 ret = pm_set_suspend_mode(pm_arg[0]);
450 SMC_RET1(handle, (uint64_t)ret);
451
Siva Durga Prasad Paladuguf3994cc2018-05-01 11:12:55 +0530452 case PM_SECURE_SHA:
453 ret = pm_sha_hash(pm_arg[0], pm_arg[1], pm_arg[2],
454 pm_arg[3]);
455 SMC_RET1(handle, (uint64_t)ret);
456
457 case PM_SECURE_RSA:
458 ret = pm_rsa_core(pm_arg[0], pm_arg[1], pm_arg[2],
459 pm_arg[3]);
460 SMC_RET1(handle, (uint64_t)ret);
461
Siva Durga Prasad Paladugua4ed4b22018-04-30 20:06:58 +0530462 case PM_SECURE_IMAGE:
463 {
Siva Durga Prasad Paladugua4ed4b22018-04-30 20:06:58 +0530464 ret = pm_secure_image(pm_arg[0], pm_arg[1], pm_arg[2],
465 pm_arg[3], &result[0]);
466 SMC_RET2(handle, (uint64_t)ret | ((uint64_t)result[0] << 32),
467 result[1]);
468 }
469
Siva Durga Prasad Paladugu7c6516a2018-09-04 17:41:34 +0530470 case PM_FPGA_READ:
471 {
472 uint32_t value;
473
474 ret = pm_fpga_read(pm_arg[0], pm_arg[1], pm_arg[2], pm_arg[3],
475 &value);
476 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
477 }
478
Siva Durga Prasad Paladugu8bd905b2018-09-04 18:05:50 +0530479 case PM_SECURE_AES:
480 {
481 uint32_t value;
482
483 ret = pm_aes_engine(pm_arg[0], pm_arg[1], &value);
484 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
485 }
486
Jolly Shaha7cc5ee2019-01-02 12:27:00 -0800487 case PM_PLL_SET_PARAMETER:
488 ret = pm_pll_set_parameter(pm_arg[0], pm_arg[1], pm_arg[2]);
489 SMC_RET1(handle, (uint64_t)ret);
490
Jolly Shahcb2f45d2019-01-04 11:28:38 -0800491 case PM_PLL_GET_PARAMETER:
492 {
493 uint32_t value;
494
495 ret = pm_pll_get_parameter(pm_arg[0], pm_arg[1], &value);
496 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value << 32));
497 }
498
Jolly Shah1f0d5852019-01-04 11:32:31 -0800499 case PM_PLL_SET_MODE:
500 ret = pm_pll_set_mode(pm_arg[0], pm_arg[1]);
501 SMC_RET1(handle, (uint64_t)ret);
502
Jolly Shah141421e2019-01-04 11:35:48 -0800503 case PM_PLL_GET_MODE:
504 {
505 uint32_t mode;
506
507 ret = pm_pll_get_mode(pm_arg[0], &mode);
508 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)mode << 32));
509 }
510
Kalyani Akula6ebe4832020-11-22 22:42:10 -0800511 case PM_REGISTER_ACCESS:
512 {
513 uint32_t value;
514
515 ret = pm_register_access(pm_arg[0], pm_arg[1], pm_arg[2],
516 pm_arg[3], &value);
517 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
518 }
519
VNSL Durgadeb1a362020-11-23 04:46:04 -0800520 case PM_EFUSE_ACCESS:
521 {
522 uint32_t value;
523
524 ret = pm_efuse_access(pm_arg[0], pm_arg[1], &value);
525 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
526 }
527
Nava kishore Manne2af6d532022-01-13 13:29:36 +0530528 case PM_FPGA_GET_VERSION:
529 case PM_FPGA_GET_FEATURE_LIST:
530 {
Nava kishore Manne2af6d532022-01-13 13:29:36 +0530531 uint32_t ret_payload[PAYLOAD_ARG_CNT];
532
533 PM_PACK_PAYLOAD5(payload, smc_fid & FUNCID_NUM_MASK,
534 pm_arg[0], pm_arg[1], pm_arg[2], pm_arg[3]);
535 ret = pm_ipi_send_sync(primary_proc, payload, ret_payload, 3U);
536 SMC_RET2(handle, (uint64_t)ret | (uint64_t)ret_payload[0] << 32,
537 (uint64_t)ret_payload[1] | (uint64_t)ret_payload[2] << 32);
538 }
539
Ronak Jain325bad12021-12-21 01:39:59 -0800540 case PM_FEATURE_CHECK:
541 {
542 uint32_t version;
543 uint32_t bit_mask[2] = {0};
544
545 ret = pm_feature_check(pm_arg[0], &version, bit_mask,
546 ARRAY_SIZE(bit_mask));
547 SMC_RET2(handle, (uint64_t)ret | ((uint64_t)version << 32),
548 (uint64_t)bit_mask[0] | ((uint64_t)bit_mask[1] << 32));
549 }
550
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800551 default:
Ronak Jain52de5942022-01-20 23:11:18 -0800552 /* Send request to the PMU */
553 PM_PACK_PAYLOAD6(payload, api_id, pm_arg[0], pm_arg[1],
554 pm_arg[2], pm_arg[3], pm_arg[4]);
555 ret = pm_ipi_send_sync(primary_proc, payload, result,
556 PAYLOAD_ARG_CNT);
557 SMC_RET2(handle, (uint64_t)ret | ((uint64_t)result[0] << 32),
558 (uint64_t)result[1] | ((uint64_t)result[2] << 32));
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800559 }
560}
Venkatesh Yadav Abbarapu7ace4af2020-11-23 04:26:54 -0800561
562/**
563 * em_smc_handler() - SMC handler for EM-API calls coming from EL1/EL2.
564 * @smc_fid - Function Identifier
565 * @x1 - x4 - Arguments
566 * @cookie - Unused
567 * @handler - Pointer to caller's context structure
568 *
569 * @return - Unused
570 *
571 * Determines that smc_fid is valid and supported EM SMC Function ID from the
572 * list of em_api_ids, otherwise completes the request with
573 * the unknown SMC Function ID
574 *
575 * The SMC calls for EM service are forwarded from SIP Service SMC handler
576 * function with rt_svc_handle signature
577 */
578uint64_t em_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3,
579 uint64_t x4, void *cookie, void *handle, uint64_t flags)
580{
581 enum pm_ret_status ret;
582
583 switch (smc_fid & FUNCID_NUM_MASK) {
584 /* EM API Functions */
585 case EM_SET_ACTION:
586 {
587 uint32_t value;
588
589 ret = em_set_action(&value);
590 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
591 }
592
593 case EM_REMOVE_ACTION:
594 {
595 uint32_t value;
596
597 ret = em_remove_action(&value);
598 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
599 }
600
601 case EM_SEND_ERRORS:
602 {
603 uint32_t value;
604
605 ret = em_send_errors(&value);
606 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
607 }
608
609 default:
610 WARN("Unimplemented EM Service Call: 0x%x\n", smc_fid);
611 SMC_RET1(handle, SMC_UNK);
612 }
613}