blob: 352d477512ffe500651cb541a68ff6545b8eaa8e [file] [log] [blame]
dp-arm1cebefd2016-09-19 11:21:03 +01001/*
Mikael Olsson461bf7d2023-01-18 18:05:15 +01002 * Copyright (c) 2016-2023, 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>
Raghu Krishnamurthy02244472023-04-09 07:46:28 -070016#if ENABLE_SPMD_LP
17#include <services/el3_spmd_logical_sp.h>
18#endif
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000019#include <tools_share/uuid.h>
20
dp-arm1cebefd2016-09-19 11:21:03 +010021/* ARM SiP Service UUID */
Roberto Vargaseace8f12018-04-26 13:36:53 +010022DEFINE_SVC_UUID2(arm_sip_svc_uid,
23 0x556d75e2, 0x6033, 0xb54b, 0xb5, 0x75,
24 0x62, 0x79, 0xfd, 0x11, 0x37, 0xff);
dp-arm1cebefd2016-09-19 11:21:03 +010025
26static int arm_sip_setup(void)
27{
Ambroise Vincent9660dc12019-07-12 13:47:03 +010028 if (pmf_setup() != 0) {
dp-arm1cebefd2016-09-19 11:21:03 +010029 return 1;
Ambroise Vincent9660dc12019-07-12 13:47:03 +010030 }
31
32#if USE_DEBUGFS
33
34 if (debugfs_smc_setup() != 0) {
35 return 1;
36 }
37
38#endif /* USE_DEBUGFS */
39
Rajasekaran Kalidoss85999a82023-05-08 14:55:13 +020040#if ETHOSN_NPU_DRIVER
Mikael Olsson461bf7d2023-01-18 18:05:15 +010041
42 if (ethosn_smc_setup() != 0) {
43 return 1;
44 }
45
Rajasekaran Kalidoss85999a82023-05-08 14:55:13 +020046#endif /* ETHOSN_NPU_DRIVER */
Mikael Olsson461bf7d2023-01-18 18:05:15 +010047
dp-arm1cebefd2016-09-19 11:21:03 +010048 return 0;
49}
50
51/*
52 * This function handles ARM defined SiP Calls
53 */
54static 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 Viswambharanbc1a9292017-02-16 14:55:15 +000063 int call_count = 0;
64
Mikael Olsson7da66192021-02-12 17:30:22 +010065#if ENABLE_PMF
66
dp-arm1cebefd2016-09-19 11:21:03 +010067 /*
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 Olsson7da66192021-02-12 17:30:22 +010076#endif /* ENABLE_PMF */
77
Ambroise Vincent9660dc12019-07-12 13:47:03 +010078#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 Kalidoss85999a82023-05-08 14:55:13 +020087#if ETHOSN_NPU_DRIVER
Mikael Olsson7da66192021-02-12 17:30:22 +010088
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 Kalidoss85999a82023-05-08 14:55:13 +020094#endif /* ETHOSN_NPU_DRIVER */
Mikael Olsson7da66192021-02-12 17:30:22 +010095
dp-arm1cebefd2016-09-19 11:21:03 +010096 switch (smc_fid) {
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +000097 case ARM_SIP_SVC_EXE_STATE_SWITCH: {
Bence Szépkúti16362c62019-10-24 15:53:23 +020098 /* Execution state can be switched only if EL3 is AArch64 */
99#ifdef __aarch64__
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +0000100 /* Allow calls from non-secure only */
101 if (!is_caller_non_secure(flags))
102 SMC_RET1(handle, STATE_SW_E_DENIED);
103
dp-arm1cebefd2016-09-19 11:21:03 +0100104 /*
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +0000105 * Pointers used in execution state switch are all 32 bits wide
dp-arm1cebefd2016-09-19 11:21:03 +0100106 */
Jeenu Viswambharan210f0a82018-08-02 10:14:12 +0100107 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úti16362c62019-10-24 15:53:23 +0200110#else
111 /* State switch denied */
112 SMC_RET1(handle, STATE_SW_E_DENIED);
113#endif /* __aarch64__ */
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +0000114 }
115
116 case ARM_SIP_SVC_CALL_COUNT:
117 /* PMF calls */
118 call_count += PMF_NUM_SMC_CALLS;
119
Rajasekaran Kalidoss85999a82023-05-08 14:55:13 +0200120#if ETHOSN_NPU_DRIVER
Mikael Olsson7da66192021-02-12 17:30:22 +0100121 /* ETHOSN calls */
122 call_count += ETHOSN_NUM_SMC_CALLS;
Rajasekaran Kalidoss85999a82023-05-08 14:55:13 +0200123#endif /* ETHOSN_NPU_DRIVER */
Mikael Olsson7da66192021-02-12 17:30:22 +0100124
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +0000125 /* State switch call */
126 call_count += 1;
127
128 SMC_RET1(handle, call_count);
dp-arm1cebefd2016-09-19 11:21:03 +0100129
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 Krishnamurthy02244472023-04-09 07:46:28 -0700139#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-arm1cebefd2016-09-19 11:21:03 +0100143 WARN("Unimplemented ARM SiP Service Call: 0x%x \n", smc_fid);
144 SMC_RET1(handle, SMC_UNK);
Raghu Krishnamurthy02244472023-04-09 07:46:28 -0700145#endif
dp-arm1cebefd2016-09-19 11:21:03 +0100146 }
147
148}
149
150
151/* Define a runtime service descriptor for fast SMC calls */
152DECLARE_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);