blob: 493ff854555974ab4a90db9667bb77d30837f734 [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
Soren Brinkmann76fcae32016-03-06 20:16:27 -080037/**
38 * pm_context - Structure which contains data for power management
39 * @api_version version of PM API, must match with one on PMU side
40 * @payload payload array used to store received
41 * data from ipi buffer registers
42 */
43static struct {
44 uint32_t api_version;
45 uint32_t payload[PAYLOAD_ARG_CNT];
46} pm_ctx;
47
Siva Durga Prasad Paladuguefd431b2018-04-30 20:12:12 +053048#if ZYNQMP_WDT_RESTART
49/**
50 * trigger_wdt_restart() - Trigger warm restart event to APU cores
51 *
52 * This function triggers SGI for all active APU CPUs. SGI handler then
53 * power down CPU and call system reset.
54 */
55static void trigger_wdt_restart(void)
56{
57 uint32_t core_count = 0;
58 uint32_t core_status[3];
59 uint32_t target_cpu_list = 0;
60 int i;
61
62 for (i = 0; i < 4; i++) {
63 pm_get_node_status(NODE_APU_0 + i, core_status);
64 if (core_status[0] == 1) {
65 core_count++;
66 target_cpu_list |= (1 << i);
67 }
68 }
69
70 spin_lock(&inc_lock);
71 active_cores = core_count;
72 spin_unlock(&inc_lock);
73
74 INFO("Active Cores: %d\n", active_cores);
75
Siva Durga Prasad Paladugu60bfbc92018-09-24 22:51:49 -070076 for (i = PLATFORM_CORE_COUNT - 1; i >= 0; i--) {
77 if (target_cpu_list & (1 << i)) {
78 /* trigger SGI to active cores */
79 plat_ic_raise_el3_sgi(ARM_IRQ_SEC_SGI_7, i);
80 }
81 }
Siva Durga Prasad Paladuguefd431b2018-04-30 20:12:12 +053082}
83
84/**
85 * ttc_fiq_handler() - TTC Handler for timer event
86 * @id number of the highest priority pending interrupt of the type
87 * that this handler was registered for
88 * @flags security state, bit[0]
89 * @handler pointer to 'cpu_context' structure of the current CPU for the
90 * security state specified in the 'flags' parameter
91 * @cookie unused
92 *
93 * Function registered as INTR_TYPE_EL3 interrupt handler
94 *
95 * When WDT event is received in PMU, PMU needs to notify master to do cleanup
96 * if required. PMU sets up timer and starts timer to overflow in zero time upon
97 * WDT event. ATF handles this timer event and takes necessary action required
98 * for warm restart.
99 *
100 * In presence of non-secure software layers (EL1/2) sets the interrupt
101 * at registered entrance in GIC and informs that PMU responsed or demands
102 * action.
103 */
104static uint64_t ttc_fiq_handler(uint32_t id, uint32_t flags, void *handle,
Michal Simek08341b72022-03-09 08:53:20 +0100105 void *cookie)
Siva Durga Prasad Paladuguefd431b2018-04-30 20:12:12 +0530106{
107 INFO("BL31: Got TTC FIQ\n");
108
Siva Durga Prasad Paladugu60bfbc92018-09-24 22:51:49 -0700109 plat_ic_end_of_interrupt(id);
110
Siva Durga Prasad Paladuguefd431b2018-04-30 20:12:12 +0530111 /* Clear TTC interrupt by reading interrupt register */
112 mmio_read_32(TTC3_INTR_REGISTER_1);
113
114 /* Disable the timer interrupts */
115 mmio_write_32(TTC3_INTR_ENABLE_1, 0);
116
117 trigger_wdt_restart();
118
119 return 0;
120}
121
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800122/**
Siva Durga Prasad Paladuguefd431b2018-04-30 20:12:12 +0530123 * zynqmp_sgi7_irq() - Handler for SGI7 IRQ
124 * @id number of the highest priority pending interrupt of the type
125 * that this handler was registered for
126 * @flags security state, bit[0]
127 * @handler pointer to 'cpu_context' structure of the current CPU for the
128 * security state specified in the 'flags' parameter
129 * @cookie unused
130 *
131 * Function registered as INTR_TYPE_EL3 interrupt handler
132 *
133 * On receiving WDT event from PMU, ATF generates SGI7 to all running CPUs.
134 * In response to SGI7 interrupt, each CPUs do clean up if required and last
135 * running CPU calls system restart.
136 */
137static uint64_t __unused __dead2 zynqmp_sgi7_irq(uint32_t id, uint32_t flags,
Michal Simek08341b72022-03-09 08:53:20 +0100138 void *handle, void *cookie)
Siva Durga Prasad Paladuguefd431b2018-04-30 20:12:12 +0530139{
140 int i;
Will Wongcc127952020-11-22 23:45:21 -0800141 uint32_t value;
142
Siva Durga Prasad Paladuguefd431b2018-04-30 20:12:12 +0530143 /* enter wfi and stay there */
144 INFO("Entering wfi\n");
145
146 spin_lock(&inc_lock);
147 active_cores--;
148
149 for (i = 0; i < 4; i++) {
150 mmio_write_32(BASE_GICD_BASE + GICD_CPENDSGIR + 4 * i,
151 0xffffffff);
152 }
153
154 spin_unlock(&inc_lock);
155
156 if (active_cores == 0) {
Will Wongcc127952020-11-22 23:45:21 -0800157 pm_mmio_read(PMU_GLOBAL_GEN_STORAGE4, &value);
158 value = (value & RESTART_SCOPE_MASK) >> RESTART_SCOPE_SHIFT;
159 pm_system_shutdown(PMF_SHUTDOWN_TYPE_RESET, value);
Siva Durga Prasad Paladuguefd431b2018-04-30 20:12:12 +0530160 }
161
162 /* enter wfi and stay there */
163 while (1)
164 wfi();
165}
166
167/**
168 * pm_wdt_restart_setup() - Setup warm restart interrupts
169 *
170 * This function sets up handler for SGI7 and TTC interrupts
171 * used for warm restart.
172 */
173static int pm_wdt_restart_setup(void)
174{
175 int ret;
176
177 /* register IRQ handler for SGI7 */
178 ret = request_intr_type_el3(ARM_IRQ_SEC_SGI_7, zynqmp_sgi7_irq);
179 if (ret) {
180 WARN("BL31: registering SGI7 interrupt failed\n");
181 goto err;
182 }
183
184 ret = request_intr_type_el3(IRQ_TTC3_1, ttc_fiq_handler);
185 if (ret)
186 WARN("BL31: registering TTC3 interrupt failed\n");
187
188err:
189 return ret;
190}
191#endif
192
193/**
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800194 * pm_setup() - PM service setup
195 *
196 * @return On success, the initialization function must return 0.
197 * Any other return value will cause the framework to ignore
198 * the service
199 *
200 * Initialization functions for ZynqMP power management for
201 * communicaton with PMU.
202 *
203 * Called from sip_svc_setup initialization function with the
204 * rt_svc_init signature.
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800205 */
206int pm_setup(void)
207{
Wendy Liang328105c2017-10-03 23:21:11 -0700208 int status, ret;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800209
Wendy Liang328105c2017-10-03 23:21:11 -0700210 status = pm_ipi_init(primary_proc);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800211
Rajan Vaja720fd9d2018-10-05 04:42:57 -0700212 ret = pm_get_api_version(&pm_ctx.api_version);
213 if (pm_ctx.api_version < PM_VERSION) {
214 ERROR("BL31: Platform Management API version error. Expected: "
215 "v%d.%d - Found: v%d.%d\n", PM_VERSION_MAJOR,
216 PM_VERSION_MINOR, pm_ctx.api_version >> 16,
217 pm_ctx.api_version & 0xFFFF);
218 return -EINVAL;
219 }
220
Siva Durga Prasad Paladuguefd431b2018-04-30 20:12:12 +0530221#if ZYNQMP_WDT_RESTART
222 status = pm_wdt_restart_setup();
223 if (status)
224 WARN("BL31: warm-restart setup failed\n");
225#endif
226
Wendy Liang328105c2017-10-03 23:21:11 -0700227 if (status >= 0) {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800228 INFO("BL31: PM Service Init Complete: API v%d.%d\n",
229 PM_VERSION_MAJOR, PM_VERSION_MINOR);
Wendy Liang328105c2017-10-03 23:21:11 -0700230 ret = 0;
231 } else {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800232 INFO("BL31: PM Service Init Failed, Error Code %d!\n", status);
Wendy Liang328105c2017-10-03 23:21:11 -0700233 ret = status;
234 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800235
Siva Durga Prasad Paladugu79f75952018-04-30 19:39:49 +0530236 pm_up = !status;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800237
Wendy Liang328105c2017-10-03 23:21:11 -0700238 return ret;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800239}
240
241/**
242 * pm_smc_handler() - SMC handler for PM-API calls coming from EL1/EL2.
243 * @smc_fid - Function Identifier
244 * @x1 - x4 - Arguments
245 * @cookie - Unused
246 * @handler - Pointer to caller's context structure
247 *
248 * @return - Unused
249 *
250 * Determines that smc_fid is valid and supported PM SMC Function ID from the
251 * list of pm_api_ids, otherwise completes the request with
252 * the unknown SMC Function ID
253 *
254 * The SMC calls for PM service are forwarded from SIP Service SMC handler
255 * function with rt_svc_handle signature
256 */
257uint64_t pm_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3,
Venkatesh Yadav Abbarapu0386e652022-05-24 14:05:57 +0530258 uint64_t x4, const void *cookie, void *handle, uint64_t flags)
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800259{
260 enum pm_ret_status ret;
Ronak Jain52de5942022-01-20 23:11:18 -0800261 uint32_t payload[PAYLOAD_ARG_CNT];
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800262
Ronak Jainf8414672022-05-11 02:48:52 -0700263 uint32_t pm_arg[5];
Ronak Jain52de5942022-01-20 23:11:18 -0800264 uint32_t result[PAYLOAD_ARG_CNT];
265 uint32_t api_id;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800266
267 /* Handle case where PM wasn't initialized properly */
Siva Durga Prasad Paladugu79f75952018-04-30 19:39:49 +0530268 if (!pm_up)
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800269 SMC_RET1(handle, SMC_UNK);
270
271 pm_arg[0] = (uint32_t)x1;
272 pm_arg[1] = (uint32_t)(x1 >> 32);
273 pm_arg[2] = (uint32_t)x2;
274 pm_arg[3] = (uint32_t)(x2 >> 32);
Ronak Jain52de5942022-01-20 23:11:18 -0800275 pm_arg[4] = (uint32_t)x3;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800276
Ronak Jain52de5942022-01-20 23:11:18 -0800277 api_id = smc_fid & FUNCID_NUM_MASK;
278
279 switch (api_id) {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800280 /* PM API Functions */
281 case PM_SELF_SUSPEND:
282 ret = pm_self_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_SUSPEND:
287 ret = pm_req_suspend(pm_arg[0], pm_arg[1], pm_arg[2],
288 pm_arg[3]);
289 SMC_RET1(handle, (uint64_t)ret);
290
291 case PM_REQ_WAKEUP:
Filip Drazic78ba1452017-02-07 12:03:57 +0100292 {
293 /* Use address flag is encoded in the 1st bit of the low-word */
294 unsigned int set_addr = pm_arg[1] & 0x1;
295 uint64_t address = (uint64_t)pm_arg[2] << 32;
296
297 address |= pm_arg[1] & (~0x1);
298 ret = pm_req_wakeup(pm_arg[0], set_addr, address,
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800299 pm_arg[3]);
300 SMC_RET1(handle, (uint64_t)ret);
Filip Drazic78ba1452017-02-07 12:03:57 +0100301 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800302
303 case PM_FORCE_POWERDOWN:
304 ret = pm_force_powerdown(pm_arg[0], pm_arg[1]);
305 SMC_RET1(handle, (uint64_t)ret);
306
307 case PM_ABORT_SUSPEND:
308 ret = pm_abort_suspend(pm_arg[0]);
309 SMC_RET1(handle, (uint64_t)ret);
310
311 case PM_SET_WAKEUP_SOURCE:
312 ret = pm_set_wakeup_source(pm_arg[0], pm_arg[1], pm_arg[2]);
313 SMC_RET1(handle, (uint64_t)ret);
314
315 case PM_SYSTEM_SHUTDOWN:
Soren Brinkmann58fbb9b2016-09-02 09:50:54 -0700316 ret = pm_system_shutdown(pm_arg[0], pm_arg[1]);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800317 SMC_RET1(handle, (uint64_t)ret);
318
319 case PM_REQ_NODE:
320 ret = pm_req_node(pm_arg[0], pm_arg[1], pm_arg[2], pm_arg[3]);
321 SMC_RET1(handle, (uint64_t)ret);
322
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800323 case PM_SET_REQUIREMENT:
324 ret = pm_set_requirement(pm_arg[0], pm_arg[1], pm_arg[2],
325 pm_arg[3]);
326 SMC_RET1(handle, (uint64_t)ret);
327
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800328 case PM_GET_API_VERSION:
329 /* Check is PM API version already verified */
Rajan Vaja720fd9d2018-10-05 04:42:57 -0700330 if (pm_ctx.api_version >= PM_VERSION) {
331 if (!ipi_irq_flag) {
332 /*
333 * Enable IPI IRQ
334 * assume the rich OS is OK to handle callback IRQs now.
335 * Even if we were wrong, it would not enable the IRQ in
336 * the GIC.
337 */
338 pm_ipi_irq_enable(primary_proc);
339 ipi_irq_flag = 1;
340 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800341 SMC_RET1(handle, (uint64_t)PM_RET_SUCCESS |
Rajan Vaja720fd9d2018-10-05 04:42:57 -0700342 ((uint64_t)pm_ctx.api_version << 32));
Soren Brinkmanna1b0a902016-09-30 11:30:21 -0700343 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800344
Nava kishore Manne68d460c2016-08-20 23:18:09 +0530345 case PM_FPGA_LOAD:
346 ret = pm_fpga_load(pm_arg[0], pm_arg[1], pm_arg[2], pm_arg[3]);
347 SMC_RET1(handle, (uint64_t)ret);
348
349 case PM_FPGA_GET_STATUS:
350 {
351 uint32_t value;
352
353 ret = pm_fpga_get_status(&value);
354 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
355 }
356
Siva Durga Prasad Paladugude93d982018-04-30 15:49:27 +0530357 case PM_SECURE_RSA_AES:
358 ret = pm_secure_rsaaes(pm_arg[0], pm_arg[1], pm_arg[2],
359 pm_arg[3]);
360 SMC_RET1(handle, (uint64_t)ret);
361
Rajan Vaja02d18422019-03-04 11:09:39 +0530362 case PM_GET_CALLBACK_DATA:
Tejas Patelf4c3a252020-01-29 22:06:12 -0800363 pm_get_callbackdata(result, ARRAY_SIZE(result));
Rajan Vaja02d18422019-03-04 11:09:39 +0530364 SMC_RET2(handle,
365 (uint64_t)result[0] | ((uint64_t)result[1] << 32),
366 (uint64_t)result[2] | ((uint64_t)result[3] << 32));
Rajan Vaja5529a012018-01-17 02:39:23 -0800367 case PM_IOCTL:
368 {
369 uint32_t value;
370
371 ret = pm_ioctl(pm_arg[0], pm_arg[1], pm_arg[2],
372 pm_arg[3], &value);
373 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
374 }
375
Rajan Vaja35116132018-01-17 02:39:25 -0800376 case PM_QUERY_DATA:
377 {
Jolly Shah69fb5bf2018-02-07 16:25:41 -0800378 uint32_t data[4] = { 0 };
Rajan Vaja35116132018-01-17 02:39:25 -0800379
Rajan Vajacd825682020-11-23 21:33:39 -0800380 pm_query_data(pm_arg[0], pm_arg[1], pm_arg[2],
381 pm_arg[3], data);
Rajan Vaja35116132018-01-17 02:39:25 -0800382 SMC_RET2(handle, (uint64_t)data[0] | ((uint64_t)data[1] << 32),
383 (uint64_t)data[2] | ((uint64_t)data[3] << 32));
384 }
385
386 case PM_CLOCK_ENABLE:
387 ret = pm_clock_enable(pm_arg[0]);
388 SMC_RET1(handle, (uint64_t)ret);
389
390 case PM_CLOCK_DISABLE:
391 ret = pm_clock_disable(pm_arg[0]);
392 SMC_RET1(handle, (uint64_t)ret);
393
394 case PM_CLOCK_GETSTATE:
395 {
396 uint32_t value;
397
398 ret = pm_clock_getstate(pm_arg[0], &value);
399 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
400 }
401
402 case PM_CLOCK_SETDIVIDER:
403 ret = pm_clock_setdivider(pm_arg[0], pm_arg[1]);
404 SMC_RET1(handle, (uint64_t)ret);
405
406 case PM_CLOCK_GETDIVIDER:
407 {
408 uint32_t value;
409
410 ret = pm_clock_getdivider(pm_arg[0], &value);
411 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
412 }
413
414 case PM_CLOCK_SETRATE:
415 ret = pm_clock_setrate(pm_arg[0],
416 ((uint64_t)pm_arg[2]) << 32 | pm_arg[1]);
417
418 SMC_RET1(handle, (uint64_t)ret);
419
420 case PM_CLOCK_GETRATE:
421 {
Ronak Jainf8414672022-05-11 02:48:52 -0700422 uint64_t value = 0;
Rajan Vaja35116132018-01-17 02:39:25 -0800423
424 ret = pm_clock_getrate(pm_arg[0], &value);
Jolly Shah69fb5bf2018-02-07 16:25:41 -0800425 SMC_RET2(handle, (uint64_t)ret |
426 (((uint64_t)value & 0xFFFFFFFFU) << 32U),
427 (value >> 32U) & 0xFFFFFFFFU);
Rajan Vaja35116132018-01-17 02:39:25 -0800428
429 }
430
431 case PM_CLOCK_SETPARENT:
432 ret = pm_clock_setparent(pm_arg[0], pm_arg[1]);
433 SMC_RET1(handle, (uint64_t)ret);
434
435 case PM_CLOCK_GETPARENT:
436 {
437 uint32_t value;
438
439 ret = pm_clock_getparent(pm_arg[0], &value);
440 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
441 }
442
Rajan Vajac7ee23d2018-02-14 23:10:54 -0800443 case PM_GET_TRUSTZONE_VERSION:
444 SMC_RET1(handle, (uint64_t)PM_RET_SUCCESS |
445 ((uint64_t)ZYNQMP_TZ_VERSION << 32));
446
Siva Durga Prasad Paladugu43b23a32018-04-27 16:26:47 +0530447 case PM_SET_SUSPEND_MODE:
448 ret = pm_set_suspend_mode(pm_arg[0]);
449 SMC_RET1(handle, (uint64_t)ret);
450
Siva Durga Prasad Paladuguf3994cc2018-05-01 11:12:55 +0530451 case PM_SECURE_SHA:
452 ret = pm_sha_hash(pm_arg[0], pm_arg[1], pm_arg[2],
453 pm_arg[3]);
454 SMC_RET1(handle, (uint64_t)ret);
455
456 case PM_SECURE_RSA:
457 ret = pm_rsa_core(pm_arg[0], pm_arg[1], pm_arg[2],
458 pm_arg[3]);
459 SMC_RET1(handle, (uint64_t)ret);
460
Siva Durga Prasad Paladugua4ed4b22018-04-30 20:06:58 +0530461 case PM_SECURE_IMAGE:
462 {
Siva Durga Prasad Paladugua4ed4b22018-04-30 20:06:58 +0530463 ret = pm_secure_image(pm_arg[0], pm_arg[1], pm_arg[2],
464 pm_arg[3], &result[0]);
465 SMC_RET2(handle, (uint64_t)ret | ((uint64_t)result[0] << 32),
466 result[1]);
467 }
468
Siva Durga Prasad Paladugu7c6516a2018-09-04 17:41:34 +0530469 case PM_FPGA_READ:
470 {
471 uint32_t value;
472
473 ret = pm_fpga_read(pm_arg[0], pm_arg[1], pm_arg[2], pm_arg[3],
474 &value);
475 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
476 }
477
Siva Durga Prasad Paladugu8bd905b2018-09-04 18:05:50 +0530478 case PM_SECURE_AES:
479 {
480 uint32_t value;
481
482 ret = pm_aes_engine(pm_arg[0], pm_arg[1], &value);
483 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
484 }
485
Jolly Shaha7cc5ee2019-01-02 12:27:00 -0800486 case PM_PLL_SET_PARAMETER:
487 ret = pm_pll_set_parameter(pm_arg[0], pm_arg[1], pm_arg[2]);
488 SMC_RET1(handle, (uint64_t)ret);
489
Jolly Shahcb2f45d2019-01-04 11:28:38 -0800490 case PM_PLL_GET_PARAMETER:
491 {
492 uint32_t value;
493
494 ret = pm_pll_get_parameter(pm_arg[0], pm_arg[1], &value);
495 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value << 32));
496 }
497
Jolly Shah1f0d5852019-01-04 11:32:31 -0800498 case PM_PLL_SET_MODE:
499 ret = pm_pll_set_mode(pm_arg[0], pm_arg[1]);
500 SMC_RET1(handle, (uint64_t)ret);
501
Jolly Shah141421e2019-01-04 11:35:48 -0800502 case PM_PLL_GET_MODE:
503 {
504 uint32_t mode;
505
506 ret = pm_pll_get_mode(pm_arg[0], &mode);
507 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)mode << 32));
508 }
509
Kalyani Akula6ebe4832020-11-22 22:42:10 -0800510 case PM_REGISTER_ACCESS:
511 {
512 uint32_t value;
513
514 ret = pm_register_access(pm_arg[0], pm_arg[1], pm_arg[2],
515 pm_arg[3], &value);
516 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
517 }
518
VNSL Durgadeb1a362020-11-23 04:46:04 -0800519 case PM_EFUSE_ACCESS:
520 {
521 uint32_t value;
522
523 ret = pm_efuse_access(pm_arg[0], pm_arg[1], &value);
524 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
525 }
526
Nava kishore Manne2af6d532022-01-13 13:29:36 +0530527 case PM_FPGA_GET_VERSION:
528 case PM_FPGA_GET_FEATURE_LIST:
529 {
Nava kishore Manne2af6d532022-01-13 13:29:36 +0530530 uint32_t ret_payload[PAYLOAD_ARG_CNT];
531
532 PM_PACK_PAYLOAD5(payload, smc_fid & FUNCID_NUM_MASK,
533 pm_arg[0], pm_arg[1], pm_arg[2], pm_arg[3]);
534 ret = pm_ipi_send_sync(primary_proc, payload, ret_payload, 3U);
535 SMC_RET2(handle, (uint64_t)ret | (uint64_t)ret_payload[0] << 32,
536 (uint64_t)ret_payload[1] | (uint64_t)ret_payload[2] << 32);
537 }
538
Ronak Jain325bad12021-12-21 01:39:59 -0800539 case PM_FEATURE_CHECK:
540 {
Ronak Jainf8414672022-05-11 02:48:52 -0700541 uint32_t version = 0;
Ronak Jain325bad12021-12-21 01:39:59 -0800542 uint32_t bit_mask[2] = {0};
543
544 ret = pm_feature_check(pm_arg[0], &version, bit_mask,
545 ARRAY_SIZE(bit_mask));
546 SMC_RET2(handle, (uint64_t)ret | ((uint64_t)version << 32),
547 (uint64_t)bit_mask[0] | ((uint64_t)bit_mask[1] << 32));
548 }
549
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800550 default:
Ronak Jain52de5942022-01-20 23:11:18 -0800551 /* Send request to the PMU */
552 PM_PACK_PAYLOAD6(payload, api_id, pm_arg[0], pm_arg[1],
553 pm_arg[2], pm_arg[3], pm_arg[4]);
554 ret = pm_ipi_send_sync(primary_proc, payload, result,
555 PAYLOAD_ARG_CNT);
556 SMC_RET2(handle, (uint64_t)ret | ((uint64_t)result[0] << 32),
557 (uint64_t)result[1] | ((uint64_t)result[2] << 32));
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800558 }
559}
Venkatesh Yadav Abbarapu7ace4af2020-11-23 04:26:54 -0800560
561/**
562 * em_smc_handler() - SMC handler for EM-API calls coming from EL1/EL2.
563 * @smc_fid - Function Identifier
564 * @x1 - x4 - Arguments
565 * @cookie - Unused
566 * @handler - Pointer to caller's context structure
567 *
568 * @return - Unused
569 *
570 * Determines that smc_fid is valid and supported EM SMC Function ID from the
571 * list of em_api_ids, otherwise completes the request with
572 * the unknown SMC Function ID
573 *
574 * The SMC calls for EM service are forwarded from SIP Service SMC handler
575 * function with rt_svc_handle signature
576 */
577uint64_t em_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3,
Venkatesh Yadav Abbarapu0386e652022-05-24 14:05:57 +0530578 uint64_t x4, const void *cookie, void *handle, uint64_t flags)
Venkatesh Yadav Abbarapu7ace4af2020-11-23 04:26:54 -0800579{
580 enum pm_ret_status ret;
581
582 switch (smc_fid & FUNCID_NUM_MASK) {
583 /* EM API Functions */
584 case EM_SET_ACTION:
585 {
586 uint32_t value;
587
588 ret = em_set_action(&value);
589 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
590 }
591
592 case EM_REMOVE_ACTION:
593 {
594 uint32_t value;
595
596 ret = em_remove_action(&value);
597 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
598 }
599
600 case EM_SEND_ERRORS:
601 {
602 uint32_t value;
603
604 ret = em_send_errors(&value);
605 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32);
606 }
607
608 default:
609 WARN("Unimplemented EM Service Call: 0x%x\n", smc_fid);
610 SMC_RET1(handle, SMC_UNK);
611 }
612}