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