Tejas Patel | 354fe57 | 2018-12-14 00:55:37 -0800 | [diff] [blame] | 1 | /* |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 2 | * Copyright (c) 2019-2022, Xilinx, Inc. All rights reserved. |
Tejas Patel | 354fe57 | 2018-12-14 00:55:37 -0800 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * Top-level SMC handler for Versal power management calls and |
| 9 | * IPI setup functions for communication with PMC. |
| 10 | */ |
| 11 | |
| 12 | #include <errno.h> |
| 13 | #include <plat_private.h> |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 14 | #include <stdbool.h> |
| 15 | #include <common/runtime_svc.h> |
Shubhrajyoti Datta | abf6122 | 2021-03-17 23:01:17 +0530 | [diff] [blame] | 16 | #include <plat/common/platform.h> |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 17 | #include "pm_api_sys.h" |
Tejas Patel | 354fe57 | 2018-12-14 00:55:37 -0800 | [diff] [blame] | 18 | #include "pm_client.h" |
| 19 | #include "pm_ipi.h" |
Venkatesh Yadav Abbarapu | aa4898a | 2021-03-31 03:07:40 -0600 | [diff] [blame] | 20 | #include <drivers/arm/gicv3.h> |
| 21 | |
| 22 | #define XSCUGIC_SGIR_EL1_INITID_SHIFT 24U |
Abhyuday Godhasara | edc38ae | 2021-08-04 23:58:46 -0700 | [diff] [blame] | 23 | #define INVALID_SGI 0xFFU |
Venkatesh Yadav Abbarapu | aa4898a | 2021-03-31 03:07:40 -0600 | [diff] [blame] | 24 | DEFINE_RENAME_SYSREG_RW_FUNCS(icc_asgi1r_el1, S3_0_C12_C11_6) |
Tejas Patel | 354fe57 | 2018-12-14 00:55:37 -0800 | [diff] [blame] | 25 | |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 26 | /* pm_up = true - UP, pm_up = false - DOWN */ |
| 27 | static bool pm_up; |
Abhyuday Godhasara | edc38ae | 2021-08-04 23:58:46 -0700 | [diff] [blame] | 28 | static unsigned int sgi = (unsigned int)INVALID_SGI; |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 29 | |
Shubhrajyoti Datta | abf6122 | 2021-03-17 23:01:17 +0530 | [diff] [blame] | 30 | static uint64_t ipi_fiq_handler(uint32_t id, uint32_t flags, void *handle, |
| 31 | void *cookie) |
| 32 | { |
Abhyuday Godhasara | edc38ae | 2021-08-04 23:58:46 -0700 | [diff] [blame] | 33 | unsigned int cpu; |
Venkatesh Yadav Abbarapu | aa4898a | 2021-03-31 03:07:40 -0600 | [diff] [blame] | 34 | unsigned int reg; |
| 35 | |
Shubhrajyoti Datta | abf6122 | 2021-03-17 23:01:17 +0530 | [diff] [blame] | 36 | (void)plat_ic_acknowledge_interrupt(); |
Abhyuday Godhasara | edc38ae | 2021-08-04 23:58:46 -0700 | [diff] [blame] | 37 | cpu = plat_my_core_pos() + 1U; |
Venkatesh Yadav Abbarapu | aa4898a | 2021-03-31 03:07:40 -0600 | [diff] [blame] | 38 | |
Abhyuday Godhasara | edc38ae | 2021-08-04 23:58:46 -0700 | [diff] [blame] | 39 | if ((unsigned int)sgi != (unsigned int)INVALID_SGI) { |
| 40 | reg = (cpu | ((unsigned int)sgi << (unsigned int)XSCUGIC_SGIR_EL1_INITID_SHIFT)); |
Venkatesh Yadav Abbarapu | aa4898a | 2021-03-31 03:07:40 -0600 | [diff] [blame] | 41 | write_icc_asgi1r_el1(reg); |
| 42 | } |
Shubhrajyoti Datta | abf6122 | 2021-03-17 23:01:17 +0530 | [diff] [blame] | 43 | |
| 44 | /* Clear FIQ */ |
| 45 | plat_ic_end_of_interrupt(id); |
| 46 | |
Venkatesh Yadav Abbarapu | aa4898a | 2021-03-31 03:07:40 -0600 | [diff] [blame] | 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * pm_register_sgi() - PM register the IPI interrupt |
| 52 | * |
| 53 | * @sgi - SGI number to be used for communication. |
| 54 | * @return On success, the initialization function must return 0. |
| 55 | * Any other return value will cause the framework to ignore |
| 56 | * the service |
| 57 | * |
| 58 | * Update the SGI number to be used. |
| 59 | * |
| 60 | */ |
| 61 | int pm_register_sgi(unsigned int sgi_num) |
| 62 | { |
Abhyuday Godhasara | edc38ae | 2021-08-04 23:58:46 -0700 | [diff] [blame] | 63 | if ((unsigned int)sgi != (unsigned int)INVALID_SGI) { |
Venkatesh Yadav Abbarapu | aa4898a | 2021-03-31 03:07:40 -0600 | [diff] [blame] | 64 | return -EBUSY; |
| 65 | } |
| 66 | |
| 67 | if (sgi_num >= GICV3_MAX_SGI_TARGETS) { |
| 68 | return -EINVAL; |
| 69 | } |
| 70 | |
Abhyuday Godhasara | edc38ae | 2021-08-04 23:58:46 -0700 | [diff] [blame] | 71 | sgi = (unsigned int)sgi_num; |
Shubhrajyoti Datta | abf6122 | 2021-03-17 23:01:17 +0530 | [diff] [blame] | 72 | return 0; |
| 73 | } |
| 74 | |
Tejas Patel | 354fe57 | 2018-12-14 00:55:37 -0800 | [diff] [blame] | 75 | /** |
| 76 | * pm_setup() - PM service setup |
| 77 | * |
| 78 | * @return On success, the initialization function must return 0. |
| 79 | * Any other return value will cause the framework to ignore |
| 80 | * the service |
| 81 | * |
| 82 | * Initialization functions for Versal power management for |
| 83 | * communicaton with PMC. |
| 84 | * |
| 85 | * Called from sip_svc_setup initialization function with the |
| 86 | * rt_svc_init signature. |
| 87 | */ |
| 88 | int pm_setup(void) |
| 89 | { |
| 90 | int status, ret = 0; |
| 91 | |
| 92 | status = pm_ipi_init(primary_proc); |
| 93 | |
| 94 | if (status < 0) { |
| 95 | INFO("BL31: PM Service Init Failed, Error Code %d!\n", status); |
| 96 | ret = status; |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 97 | } else { |
| 98 | pm_up = true; |
Tejas Patel | 354fe57 | 2018-12-14 00:55:37 -0800 | [diff] [blame] | 99 | } |
| 100 | |
Shubhrajyoti Datta | abf6122 | 2021-03-17 23:01:17 +0530 | [diff] [blame] | 101 | /* |
| 102 | * Enable IPI IRQ |
| 103 | * assume the rich OS is OK to handle callback IRQs now. |
| 104 | * Even if we were wrong, it would not enable the IRQ in |
| 105 | * the GIC. |
| 106 | */ |
| 107 | pm_ipi_irq_enable(primary_proc); |
| 108 | |
| 109 | ret = request_intr_type_el3(PLAT_VERSAL_IPI_IRQ, ipi_fiq_handler); |
Abhyuday Godhasara | 4487794 | 2021-08-05 02:59:26 -0700 | [diff] [blame] | 110 | if (ret != 0) { |
Shubhrajyoti Datta | abf6122 | 2021-03-17 23:01:17 +0530 | [diff] [blame] | 111 | WARN("BL31: registering IPI interrupt failed\n"); |
| 112 | } |
Tejas Patel | 354fe57 | 2018-12-14 00:55:37 -0800 | [diff] [blame] | 113 | return ret; |
| 114 | } |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 115 | |
| 116 | /** |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 117 | * eemi_for_compatibility() - EEMI calls handler for deprecated calls |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 118 | * |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 119 | * @return - If EEMI API found then, uintptr_t type address, else 0 |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 120 | * |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 121 | * Some EEMI API's use case needs to be changed in Linux driver, so they |
| 122 | * can take advantage of common EEMI handler in TF-A. As of now the old |
| 123 | * implementation of these APIs are required to maintain backward compatibility |
| 124 | * until their use case in linux driver changes. |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 125 | */ |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 126 | static uintptr_t eemi_for_compatibility(uint32_t api_id, uint32_t *pm_arg, |
| 127 | void *handle, uint32_t security_flag) |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 128 | { |
| 129 | enum pm_ret_status ret; |
| 130 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 131 | switch (api_id) { |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 132 | |
Tejas Patel | 9141f44 | 2019-01-10 03:03:48 -0800 | [diff] [blame] | 133 | case PM_IOCTL: |
| 134 | { |
| 135 | uint32_t value; |
| 136 | |
| 137 | ret = pm_api_ioctl(pm_arg[0], pm_arg[1], pm_arg[2], |
Venkatesh Yadav Abbarapu | 4b23339 | 2021-10-20 22:11:53 -0600 | [diff] [blame] | 138 | pm_arg[3], pm_arg[4], |
| 139 | &value, security_flag); |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 140 | if (ret == PM_RET_ERROR_NOTSUPPORTED) |
| 141 | return (uintptr_t)0; |
| 142 | |
| 143 | SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32); |
Tejas Patel | 9141f44 | 2019-01-10 03:03:48 -0800 | [diff] [blame] | 144 | } |
| 145 | |
Tejas Patel | a3e34ad | 2019-02-01 17:25:19 +0530 | [diff] [blame] | 146 | case PM_QUERY_DATA: |
| 147 | { |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 148 | uint32_t data[PAYLOAD_ARG_CNT] = { 0 }; |
Tejas Patel | a3e34ad | 2019-02-01 17:25:19 +0530 | [diff] [blame] | 149 | |
| 150 | ret = pm_query_data(pm_arg[0], pm_arg[1], pm_arg[2], |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 151 | pm_arg[3], data, security_flag); |
Rajan Vaja | 030620d | 2020-11-23 04:13:54 -0800 | [diff] [blame] | 152 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 153 | SMC_RET2(handle, (uint64_t)ret | ((uint64_t)data[0] << 32), |
| 154 | (uint64_t)data[1] | ((uint64_t)data[2] << 32)); |
Rajan Vaja | 030620d | 2020-11-23 04:13:54 -0800 | [diff] [blame] | 155 | } |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 156 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 157 | case PM_FEATURE_CHECK: |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 158 | { |
Ronak Jain | 70d1c58 | 2022-02-04 00:42:55 -0800 | [diff] [blame] | 159 | uint32_t result[PAYLOAD_ARG_CNT] = {0U}; |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 160 | |
Ronak Jain | 70d1c58 | 2022-02-04 00:42:55 -0800 | [diff] [blame] | 161 | ret = pm_feature_check(pm_arg[0], result, security_flag); |
| 162 | SMC_RET2(handle, (uint64_t)ret | ((uint64_t)result[0] << 32), |
| 163 | (uint64_t)result[1] | ((uint64_t)result[2] << 32)); |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 164 | } |
| 165 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 166 | case PM_LOAD_PDI: |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 167 | { |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 168 | ret = pm_load_pdi(pm_arg[0], pm_arg[1], pm_arg[2], |
| 169 | security_flag); |
| 170 | SMC_RET1(handle, (uint64_t)ret); |
| 171 | } |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 172 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 173 | default: |
| 174 | return (uintptr_t)0; |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 175 | } |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 176 | } |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 177 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 178 | /** |
| 179 | * eemi_psci_debugfs_handler() - EEMI API invoked from PSCI |
| 180 | * |
| 181 | * These EEMI APIs performs CPU specific power management tasks. |
| 182 | * These EEMI APIs are invoked either from PSCI or from debugfs in kernel. |
| 183 | * These calls require CPU specific processing before sending IPI request to |
| 184 | * Platform Management Controller. For example enable/disable CPU specific |
| 185 | * interrupts. This requires separate handler for these calls and may not be |
| 186 | * handled using common eemi handler |
| 187 | */ |
| 188 | static uintptr_t eemi_psci_debugfs_handler(uint32_t api_id, uint32_t *pm_arg, |
| 189 | void *handle, uint32_t security_flag) |
| 190 | { |
| 191 | enum pm_ret_status ret; |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 192 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 193 | switch (api_id) { |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 194 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 195 | case PM_SELF_SUSPEND: |
| 196 | ret = pm_self_suspend(pm_arg[0], pm_arg[1], pm_arg[2], |
| 197 | pm_arg[3], security_flag); |
| 198 | SMC_RET1(handle, (uint64_t)ret); |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 199 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 200 | case PM_FORCE_POWERDOWN: |
| 201 | ret = pm_force_powerdown(pm_arg[0], pm_arg[1], security_flag); |
| 202 | SMC_RET1(handle, (uint64_t)ret); |
Tejas Patel | 84275bf | 2020-09-01 04:43:53 -0700 | [diff] [blame] | 203 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 204 | case PM_REQ_SUSPEND: |
| 205 | ret = pm_req_suspend(pm_arg[0], pm_arg[1], pm_arg[2], |
| 206 | pm_arg[3], security_flag); |
| 207 | SMC_RET1(handle, (uint64_t)ret); |
Tejas Patel | 84275bf | 2020-09-01 04:43:53 -0700 | [diff] [blame] | 208 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 209 | case PM_ABORT_SUSPEND: |
| 210 | ret = pm_abort_suspend(pm_arg[0], security_flag); |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 211 | SMC_RET1(handle, (uint64_t)ret); |
| 212 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 213 | case PM_SYSTEM_SHUTDOWN: |
| 214 | ret = pm_system_shutdown(pm_arg[0], pm_arg[1], security_flag); |
| 215 | SMC_RET1(handle, (uint64_t)ret); |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 216 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 217 | default: |
| 218 | return (uintptr_t)0; |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 219 | } |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 220 | } |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 221 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 222 | /** |
| 223 | * TF_A_specific_handler() - SMC handler for TF-A specific functionality |
| 224 | * |
| 225 | * These EEMI calls performs functionality that does not require |
| 226 | * IPI transaction. The handler ends in TF-A and returns requested data to |
| 227 | * kernel from TF-A |
| 228 | */ |
| 229 | static uintptr_t TF_A_specific_handler(uint32_t api_id, uint32_t *pm_arg, |
| 230 | void *handle, uint32_t security_flag) |
| 231 | { |
| 232 | switch (api_id) { |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 233 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 234 | case PM_GET_CALLBACK_DATA: |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 235 | { |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 236 | uint32_t result[4] = {0}; |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 237 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 238 | pm_get_callbackdata(result, ARRAY_SIZE(result), security_flag); |
| 239 | SMC_RET2(handle, |
| 240 | (uint64_t)result[0] | ((uint64_t)result[1] << 32), |
| 241 | (uint64_t)result[2] | ((uint64_t)result[3] << 32)); |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 242 | } |
| 243 | |
Tejas Patel | 044001d | 2019-01-21 17:56:48 +0530 | [diff] [blame] | 244 | case PM_GET_TRUSTZONE_VERSION: |
| 245 | SMC_RET1(handle, (uint64_t)PM_RET_SUCCESS | |
| 246 | ((uint64_t)VERSAL_TZ_VERSION << 32)); |
| 247 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 248 | default: |
| 249 | return (uintptr_t)0; |
Ravi Patel | bd4aa5a | 2019-08-12 03:17:54 -0700 | [diff] [blame] | 250 | } |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 251 | } |
Ravi Patel | bd4aa5a | 2019-08-12 03:17:54 -0700 | [diff] [blame] | 252 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 253 | /** |
| 254 | * eemi_handler() - Prepare EEMI payload and perform IPI transaction |
| 255 | * |
| 256 | * EEMI - Embedded Energy Management Interface is Xilinx proprietary protocol |
| 257 | * to allow communication between power management controller and different |
| 258 | * processing clusters. |
| 259 | * |
| 260 | * This handler prepares EEMI protocol payload received from kernel and performs |
| 261 | * IPI transaction. |
| 262 | */ |
| 263 | static uintptr_t eemi_handler(uint32_t api_id, uint32_t *pm_arg, |
| 264 | void *handle, uint32_t security_flag) |
| 265 | { |
| 266 | enum pm_ret_status ret; |
| 267 | uint32_t buf[PAYLOAD_ARG_CNT] = {0}; |
Ravi Patel | 22b0b49 | 2019-03-06 12:34:46 +0530 | [diff] [blame] | 268 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 269 | ret = pm_handle_eemi_call(security_flag, api_id, pm_arg[0], pm_arg[1], |
| 270 | pm_arg[2], pm_arg[3], pm_arg[4], |
| 271 | (uint64_t *)buf); |
| 272 | /* |
| 273 | * Two IOCTLs, to get clock name and pinctrl name of pm_query_data API |
| 274 | * receives 5 words of respoonse from firmware. Currently linux driver can |
| 275 | * receive only 4 words from TF-A. So, this needs to be handled separately |
| 276 | * than other eemi calls. |
| 277 | */ |
| 278 | if (api_id == PM_QUERY_DATA) { |
| 279 | if ((pm_arg[0] == XPM_QID_CLOCK_GET_NAME || |
| 280 | pm_arg[0] == XPM_QID_PINCTRL_GET_FUNCTION_NAME) && |
| 281 | ret == PM_RET_SUCCESS) { |
| 282 | SMC_RET2(handle, (uint64_t)buf[0] | ((uint64_t)buf[1] << 32), |
| 283 | (uint64_t)buf[2] | ((uint64_t)buf[3] << 32)); |
| 284 | } |
Ravi Patel | 22b0b49 | 2019-03-06 12:34:46 +0530 | [diff] [blame] | 285 | } |
| 286 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 287 | SMC_RET2(handle, (uint64_t)ret | ((uint64_t)buf[0] << 32), |
| 288 | (uint64_t)buf[1] | ((uint64_t)buf[2] << 32)); |
| 289 | } |
Jolly Shah | ed05a71 | 2019-03-22 05:33:39 +0530 | [diff] [blame] | 290 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 291 | /** |
| 292 | * pm_smc_handler() - SMC handler for PM-API calls coming from EL1/EL2. |
| 293 | * @smc_fid - Function Identifier |
| 294 | * @x1 - x4 - SMC64 Arguments from kernel |
Venkatesh Yadav Abbarapu | 4b23339 | 2021-10-20 22:11:53 -0600 | [diff] [blame] | 295 | * x3 (upper 32-bits) and x4 are Unused |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 296 | * @cookie - Unused |
| 297 | * @handler - Pointer to caller's context structure |
| 298 | * |
| 299 | * @return - Unused |
| 300 | * |
| 301 | * Determines that smc_fid is valid and supported PM SMC Function ID from the |
| 302 | * list of pm_api_ids, otherwise completes the request with |
| 303 | * the unknown SMC Function ID |
| 304 | * |
| 305 | * The SMC calls for PM service are forwarded from SIP Service SMC handler |
| 306 | * function with rt_svc_handle signature |
| 307 | */ |
| 308 | uint64_t pm_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3, |
| 309 | uint64_t x4, void *cookie, void *handle, uint64_t flags) |
| 310 | { |
| 311 | uintptr_t ret; |
| 312 | uint32_t pm_arg[PAYLOAD_ARG_CNT] = {0}; |
| 313 | uint32_t security_flag = SECURE_FLAG; |
| 314 | uint32_t api_id; |
Saeed Nowshadi | 2294b42 | 2019-06-03 10:22:35 -0700 | [diff] [blame] | 315 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 316 | /* Handle case where PM wasn't initialized properly */ |
| 317 | if (!pm_up) |
| 318 | SMC_RET1(handle, SMC_UNK); |
Saeed Nowshadi | 2294b42 | 2019-06-03 10:22:35 -0700 | [diff] [blame] | 319 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 320 | /* |
| 321 | * Mark BIT24 payload (i.e 1st bit of pm_arg[3] ) as non-secure (1) |
| 322 | * if smc called is non secure |
| 323 | */ |
| 324 | if (is_caller_non_secure(flags)) { |
| 325 | security_flag = NON_SECURE_FLAG; |
Tejas Patel | 5c154e1 | 2020-11-25 01:53:12 -0800 | [diff] [blame] | 326 | } |
| 327 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 328 | pm_arg[0] = (uint32_t)x1; |
| 329 | pm_arg[1] = (uint32_t)(x1 >> 32); |
| 330 | pm_arg[2] = (uint32_t)x2; |
| 331 | pm_arg[3] = (uint32_t)(x2 >> 32); |
Venkatesh Yadav Abbarapu | 4b23339 | 2021-10-20 22:11:53 -0600 | [diff] [blame] | 332 | pm_arg[4] = (uint32_t)x3; |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 333 | (void)(x4); |
| 334 | api_id = smc_fid & FUNCID_NUM_MASK; |
Tejas Patel | 4201555 | 2020-11-25 01:56:57 -0800 | [diff] [blame] | 335 | |
Tanmay Shah | ff34daa | 2021-08-09 11:00:41 -0700 | [diff] [blame] | 336 | ret = eemi_for_compatibility(api_id, pm_arg, handle, security_flag); |
| 337 | if (ret != (uintptr_t)0) |
| 338 | return ret; |
| 339 | |
| 340 | ret = eemi_psci_debugfs_handler(api_id, pm_arg, handle, flags); |
| 341 | if (ret != (uintptr_t)0) |
| 342 | return ret; |
| 343 | |
| 344 | ret = TF_A_specific_handler(api_id, pm_arg, handle, security_flag); |
| 345 | if (ret != (uintptr_t)0) |
| 346 | return ret; |
| 347 | |
| 348 | ret = eemi_handler(api_id, pm_arg, handle, security_flag); |
| 349 | |
| 350 | return ret; |
Tejas Patel | 59c608a | 2019-01-09 04:10:29 -0800 | [diff] [blame] | 351 | } |