blob: 18e9381ae0caceea109d714040501bc6de43a4bd [file] [log] [blame]
dp-arm1cebefd2016-09-19 11:21:03 +01001/*
Govindraj Raja79cd7a02024-03-07 15:24:19 -06002 * Copyright (c) 2016-2024, Arm Limited and Contributors. All rights reserved.
dp-arm1cebefd2016-09-19 11:21:03 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
dp-arm1cebefd2016-09-19 11:21:03 +01005 */
6
dp-arm1cebefd2016-09-19 11:21:03 +01007#include <stdint.h>
dp-arm1cebefd2016-09-19 11:21:03 +01008
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009#include <common/debug.h>
10#include <common/runtime_svc.h>
Mikael Olsson7da66192021-02-12 17:30:22 +010011#include <drivers/arm/ethosn.h>
Ambroise Vincent9660dc12019-07-12 13:47:03 +010012#include <lib/debugfs.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013#include <lib/pmf/pmf.h>
Antonio Nino Diazbd7b7402019-01-25 14:30:04 +000014#include <plat/arm/common/arm_sip_svc.h>
15#include <plat/arm/common/plat_arm.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000016#include <tools_share/uuid.h>
17
dp-arm1cebefd2016-09-19 11:21:03 +010018/* ARM SiP Service UUID */
Roberto Vargaseace8f12018-04-26 13:36:53 +010019DEFINE_SVC_UUID2(arm_sip_svc_uid,
20 0x556d75e2, 0x6033, 0xb54b, 0xb5, 0x75,
21 0x62, 0x79, 0xfd, 0x11, 0x37, 0xff);
dp-arm1cebefd2016-09-19 11:21:03 +010022
23static int arm_sip_setup(void)
24{
Govindraj Rajacd29ad52024-04-15 12:42:13 -050025#if ENABLE_PMF
Ambroise Vincent9660dc12019-07-12 13:47:03 +010026 if (pmf_setup() != 0) {
dp-arm1cebefd2016-09-19 11:21:03 +010027 return 1;
Ambroise Vincent9660dc12019-07-12 13:47:03 +010028 }
Govindraj Rajacd29ad52024-04-15 12:42:13 -050029#endif /* ENABLE_PMF */
Ambroise Vincent9660dc12019-07-12 13:47:03 +010030
31#if USE_DEBUGFS
32
33 if (debugfs_smc_setup() != 0) {
34 return 1;
35 }
36
37#endif /* USE_DEBUGFS */
38
Rajasekaran Kalidoss85999a82023-05-08 14:55:13 +020039#if ETHOSN_NPU_DRIVER
Mikael Olsson461bf7d2023-01-18 18:05:15 +010040
41 if (ethosn_smc_setup() != 0) {
42 return 1;
43 }
44
Rajasekaran Kalidoss85999a82023-05-08 14:55:13 +020045#endif /* ETHOSN_NPU_DRIVER */
Mikael Olsson461bf7d2023-01-18 18:05:15 +010046
dp-arm1cebefd2016-09-19 11:21:03 +010047 return 0;
48}
49
50/*
51 * This function handles ARM defined SiP Calls
52 */
53static uintptr_t arm_sip_handler(unsigned int smc_fid,
54 u_register_t x1,
55 u_register_t x2,
56 u_register_t x3,
57 u_register_t x4,
58 void *cookie,
59 void *handle,
60 u_register_t flags)
61{
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +000062 int call_count = 0;
63
Mikael Olsson7da66192021-02-12 17:30:22 +010064#if ENABLE_PMF
dp-arm1cebefd2016-09-19 11:21:03 +010065 /*
66 * Dispatch PMF calls to PMF SMC handler and return its return
67 * value
68 */
Govindraj Rajacd29ad52024-04-15 12:42:13 -050069 if (is_pmf_fid_deprecated(smc_fid)) {
70 NOTICE("PMF Interface usage from arm-sip range is deprecated. \
71 Please migrate smc call to Vendor-specific el3 range.\n");
dp-arm1cebefd2016-09-19 11:21:03 +010072 return pmf_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
73 handle, flags);
74 }
75
Mikael Olsson7da66192021-02-12 17:30:22 +010076#endif /* ENABLE_PMF */
77
Ambroise Vincent9660dc12019-07-12 13:47:03 +010078#if USE_DEBUGFS
Govindraj Raja79cd7a02024-03-07 15:24:19 -060079 if (is_debugfs_fid_deprecated(smc_fid)) {
80 NOTICE("Debugfs Interface usage from arm-sip range is deprecated. \
81 Please migrate smc call to vendor-specific el3 range.\n");
Ambroise Vincent9660dc12019-07-12 13:47:03 +010082 return debugfs_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
83 handle, flags);
84 }
85
86#endif /* USE_DEBUGFS */
87
Rajasekaran Kalidoss85999a82023-05-08 14:55:13 +020088#if ETHOSN_NPU_DRIVER
Mikael Olsson7da66192021-02-12 17:30:22 +010089
90 if (is_ethosn_fid(smc_fid)) {
91 return ethosn_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
92 handle, flags);
93 }
94
Rajasekaran Kalidoss85999a82023-05-08 14:55:13 +020095#endif /* ETHOSN_NPU_DRIVER */
Mikael Olsson7da66192021-02-12 17:30:22 +010096
dp-arm1cebefd2016-09-19 11:21:03 +010097 switch (smc_fid) {
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +000098 case ARM_SIP_SVC_EXE_STATE_SWITCH: {
Bence Szépkúti16362c62019-10-24 15:53:23 +020099 /* Execution state can be switched only if EL3 is AArch64 */
100#ifdef __aarch64__
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +0000101 /* Allow calls from non-secure only */
102 if (!is_caller_non_secure(flags))
103 SMC_RET1(handle, STATE_SW_E_DENIED);
104
dp-arm1cebefd2016-09-19 11:21:03 +0100105 /*
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +0000106 * Pointers used in execution state switch are all 32 bits wide
dp-arm1cebefd2016-09-19 11:21:03 +0100107 */
Jeenu Viswambharan210f0a82018-08-02 10:14:12 +0100108 return (uintptr_t) arm_execution_state_switch(smc_fid,
109 (uint32_t) x1, (uint32_t) x2, (uint32_t) x3,
110 (uint32_t) x4, handle);
Bence Szépkúti16362c62019-10-24 15:53:23 +0200111#else
112 /* State switch denied */
113 SMC_RET1(handle, STATE_SW_E_DENIED);
114#endif /* __aarch64__ */
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +0000115 }
116
117 case ARM_SIP_SVC_CALL_COUNT:
118 /* PMF calls */
119 call_count += PMF_NUM_SMC_CALLS;
120
Rajasekaran Kalidoss85999a82023-05-08 14:55:13 +0200121#if ETHOSN_NPU_DRIVER
Mikael Olsson7da66192021-02-12 17:30:22 +0100122 /* ETHOSN calls */
123 call_count += ETHOSN_NUM_SMC_CALLS;
Rajasekaran Kalidoss85999a82023-05-08 14:55:13 +0200124#endif /* ETHOSN_NPU_DRIVER */
Mikael Olsson7da66192021-02-12 17:30:22 +0100125
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +0000126 /* State switch call */
127 call_count += 1;
128
129 SMC_RET1(handle, call_count);
dp-arm1cebefd2016-09-19 11:21:03 +0100130
131 case ARM_SIP_SVC_UID:
132 /* Return UID to the caller */
133 SMC_UUID_RET(handle, arm_sip_svc_uid);
134
135 case ARM_SIP_SVC_VERSION:
136 /* Return the version of current implementation */
137 SMC_RET2(handle, ARM_SIP_SVC_VERSION_MAJOR, ARM_SIP_SVC_VERSION_MINOR);
138
139 default:
Madhukar Pappireddycc307102023-09-09 23:02:34 -0500140 break;
dp-arm1cebefd2016-09-19 11:21:03 +0100141 }
142
Madhukar Pappireddycc307102023-09-09 23:02:34 -0500143 /*
144 * Fall back to allow Arm platform specific handler.
145 * TODO: Refactor needed to move out generic handlers from this file and
146 * only keep Arm Platform specific handlers here.
147 */
148 return plat_arm_sip_handler(smc_fid, x1, x2, x3, x4,
149 cookie, handle, flags);
dp-arm1cebefd2016-09-19 11:21:03 +0100150}
151
152
153/* Define a runtime service descriptor for fast SMC calls */
154DECLARE_RT_SVC(
155 arm_sip_svc,
156 OEN_SIP_START,
157 OEN_SIP_END,
158 SMC_TYPE_FAST,
159 arm_sip_setup,
160 arm_sip_handler
161);