dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 1 | /* |
Mikael Olsson | 461bf7d | 2023-01-18 18:05:15 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016-2023, ARM Limited and Contributors. All rights reserved. |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 7 | #include <stdint.h> |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 8 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | #include <common/debug.h> |
| 10 | #include <common/runtime_svc.h> |
Mikael Olsson | 7da6619 | 2021-02-12 17:30:22 +0100 | [diff] [blame] | 11 | #include <drivers/arm/ethosn.h> |
Ambroise Vincent | 9660dc1 | 2019-07-12 13:47:03 +0100 | [diff] [blame] | 12 | #include <lib/debugfs.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 13 | #include <lib/pmf/pmf.h> |
Antonio Nino Diaz | bd7b740 | 2019-01-25 14:30:04 +0000 | [diff] [blame] | 14 | #include <plat/arm/common/arm_sip_svc.h> |
| 15 | #include <plat/arm/common/plat_arm.h> |
Raghu Krishnamurthy | 0224447 | 2023-04-09 07:46:28 -0700 | [diff] [blame] | 16 | #if ENABLE_SPMD_LP |
| 17 | #include <services/el3_spmd_logical_sp.h> |
| 18 | #endif |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 19 | #include <tools_share/uuid.h> |
| 20 | |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 21 | /* ARM SiP Service UUID */ |
Roberto Vargas | eace8f1 | 2018-04-26 13:36:53 +0100 | [diff] [blame] | 22 | DEFINE_SVC_UUID2(arm_sip_svc_uid, |
| 23 | 0x556d75e2, 0x6033, 0xb54b, 0xb5, 0x75, |
| 24 | 0x62, 0x79, 0xfd, 0x11, 0x37, 0xff); |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 25 | |
| 26 | static int arm_sip_setup(void) |
| 27 | { |
Ambroise Vincent | 9660dc1 | 2019-07-12 13:47:03 +0100 | [diff] [blame] | 28 | if (pmf_setup() != 0) { |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 29 | return 1; |
Ambroise Vincent | 9660dc1 | 2019-07-12 13:47:03 +0100 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | #if USE_DEBUGFS |
| 33 | |
| 34 | if (debugfs_smc_setup() != 0) { |
| 35 | return 1; |
| 36 | } |
| 37 | |
| 38 | #endif /* USE_DEBUGFS */ |
| 39 | |
Rajasekaran Kalidoss | 85999a8 | 2023-05-08 14:55:13 +0200 | [diff] [blame] | 40 | #if ETHOSN_NPU_DRIVER |
Mikael Olsson | 461bf7d | 2023-01-18 18:05:15 +0100 | [diff] [blame] | 41 | |
| 42 | if (ethosn_smc_setup() != 0) { |
| 43 | return 1; |
| 44 | } |
| 45 | |
Rajasekaran Kalidoss | 85999a8 | 2023-05-08 14:55:13 +0200 | [diff] [blame] | 46 | #endif /* ETHOSN_NPU_DRIVER */ |
Mikael Olsson | 461bf7d | 2023-01-18 18:05:15 +0100 | [diff] [blame] | 47 | |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | /* |
| 52 | * This function handles ARM defined SiP Calls |
| 53 | */ |
| 54 | static uintptr_t arm_sip_handler(unsigned int smc_fid, |
| 55 | u_register_t x1, |
| 56 | u_register_t x2, |
| 57 | u_register_t x3, |
| 58 | u_register_t x4, |
| 59 | void *cookie, |
| 60 | void *handle, |
| 61 | u_register_t flags) |
| 62 | { |
Jeenu Viswambharan | bc1a929 | 2017-02-16 14:55:15 +0000 | [diff] [blame] | 63 | int call_count = 0; |
| 64 | |
Mikael Olsson | 7da6619 | 2021-02-12 17:30:22 +0100 | [diff] [blame] | 65 | #if ENABLE_PMF |
| 66 | |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 67 | /* |
| 68 | * Dispatch PMF calls to PMF SMC handler and return its return |
| 69 | * value |
| 70 | */ |
| 71 | if (is_pmf_fid(smc_fid)) { |
| 72 | return pmf_smc_handler(smc_fid, x1, x2, x3, x4, cookie, |
| 73 | handle, flags); |
| 74 | } |
| 75 | |
Mikael Olsson | 7da6619 | 2021-02-12 17:30:22 +0100 | [diff] [blame] | 76 | #endif /* ENABLE_PMF */ |
| 77 | |
Ambroise Vincent | 9660dc1 | 2019-07-12 13:47:03 +0100 | [diff] [blame] | 78 | #if USE_DEBUGFS |
| 79 | |
| 80 | if (is_debugfs_fid(smc_fid)) { |
| 81 | return debugfs_smc_handler(smc_fid, x1, x2, x3, x4, cookie, |
| 82 | handle, flags); |
| 83 | } |
| 84 | |
| 85 | #endif /* USE_DEBUGFS */ |
| 86 | |
Rajasekaran Kalidoss | 85999a8 | 2023-05-08 14:55:13 +0200 | [diff] [blame] | 87 | #if ETHOSN_NPU_DRIVER |
Mikael Olsson | 7da6619 | 2021-02-12 17:30:22 +0100 | [diff] [blame] | 88 | |
| 89 | if (is_ethosn_fid(smc_fid)) { |
| 90 | return ethosn_smc_handler(smc_fid, x1, x2, x3, x4, cookie, |
| 91 | handle, flags); |
| 92 | } |
| 93 | |
Rajasekaran Kalidoss | 85999a8 | 2023-05-08 14:55:13 +0200 | [diff] [blame] | 94 | #endif /* ETHOSN_NPU_DRIVER */ |
Mikael Olsson | 7da6619 | 2021-02-12 17:30:22 +0100 | [diff] [blame] | 95 | |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 96 | switch (smc_fid) { |
Jeenu Viswambharan | bc1a929 | 2017-02-16 14:55:15 +0000 | [diff] [blame] | 97 | case ARM_SIP_SVC_EXE_STATE_SWITCH: { |
Bence Szépkúti | 16362c6 | 2019-10-24 15:53:23 +0200 | [diff] [blame] | 98 | /* Execution state can be switched only if EL3 is AArch64 */ |
| 99 | #ifdef __aarch64__ |
Jeenu Viswambharan | bc1a929 | 2017-02-16 14:55:15 +0000 | [diff] [blame] | 100 | /* Allow calls from non-secure only */ |
| 101 | if (!is_caller_non_secure(flags)) |
| 102 | SMC_RET1(handle, STATE_SW_E_DENIED); |
| 103 | |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 104 | /* |
Jeenu Viswambharan | bc1a929 | 2017-02-16 14:55:15 +0000 | [diff] [blame] | 105 | * Pointers used in execution state switch are all 32 bits wide |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 106 | */ |
Jeenu Viswambharan | 210f0a8 | 2018-08-02 10:14:12 +0100 | [diff] [blame] | 107 | return (uintptr_t) arm_execution_state_switch(smc_fid, |
| 108 | (uint32_t) x1, (uint32_t) x2, (uint32_t) x3, |
| 109 | (uint32_t) x4, handle); |
Bence Szépkúti | 16362c6 | 2019-10-24 15:53:23 +0200 | [diff] [blame] | 110 | #else |
| 111 | /* State switch denied */ |
| 112 | SMC_RET1(handle, STATE_SW_E_DENIED); |
| 113 | #endif /* __aarch64__ */ |
Jeenu Viswambharan | bc1a929 | 2017-02-16 14:55:15 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | case ARM_SIP_SVC_CALL_COUNT: |
| 117 | /* PMF calls */ |
| 118 | call_count += PMF_NUM_SMC_CALLS; |
| 119 | |
Rajasekaran Kalidoss | 85999a8 | 2023-05-08 14:55:13 +0200 | [diff] [blame] | 120 | #if ETHOSN_NPU_DRIVER |
Mikael Olsson | 7da6619 | 2021-02-12 17:30:22 +0100 | [diff] [blame] | 121 | /* ETHOSN calls */ |
| 122 | call_count += ETHOSN_NUM_SMC_CALLS; |
Rajasekaran Kalidoss | 85999a8 | 2023-05-08 14:55:13 +0200 | [diff] [blame] | 123 | #endif /* ETHOSN_NPU_DRIVER */ |
Mikael Olsson | 7da6619 | 2021-02-12 17:30:22 +0100 | [diff] [blame] | 124 | |
Jeenu Viswambharan | bc1a929 | 2017-02-16 14:55:15 +0000 | [diff] [blame] | 125 | /* State switch call */ |
| 126 | call_count += 1; |
| 127 | |
| 128 | SMC_RET1(handle, call_count); |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 129 | |
| 130 | case ARM_SIP_SVC_UID: |
| 131 | /* Return UID to the caller */ |
| 132 | SMC_UUID_RET(handle, arm_sip_svc_uid); |
| 133 | |
| 134 | case ARM_SIP_SVC_VERSION: |
| 135 | /* Return the version of current implementation */ |
| 136 | SMC_RET2(handle, ARM_SIP_SVC_VERSION_MAJOR, ARM_SIP_SVC_VERSION_MINOR); |
| 137 | |
| 138 | default: |
Raghu Krishnamurthy | 0224447 | 2023-04-09 07:46:28 -0700 | [diff] [blame] | 139 | #if ENABLE_SPMD_LP |
| 140 | return plat_spmd_logical_sp_smc_handler(smc_fid, x1, x2, x3, x4, |
| 141 | cookie, handle, flags); |
| 142 | #else |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 143 | WARN("Unimplemented ARM SiP Service Call: 0x%x \n", smc_fid); |
| 144 | SMC_RET1(handle, SMC_UNK); |
Raghu Krishnamurthy | 0224447 | 2023-04-09 07:46:28 -0700 | [diff] [blame] | 145 | #endif |
dp-arm | 1cebefd | 2016-09-19 11:21:03 +0100 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | } |
| 149 | |
| 150 | |
| 151 | /* Define a runtime service descriptor for fast SMC calls */ |
| 152 | DECLARE_RT_SVC( |
| 153 | arm_sip_svc, |
| 154 | OEN_SIP_START, |
| 155 | OEN_SIP_END, |
| 156 | SMC_TYPE_FAST, |
| 157 | arm_sip_setup, |
| 158 | arm_sip_handler |
| 159 | ); |