blob: 6456c78411b2dba34a15b76b17aaf4e2892d4730 [file] [log] [blame]
dp-arm1cebefd2016-09-19 11:21:03 +01001/*
Mikael Olsson7da66192021-02-12 17:30:22 +01002 * Copyright (c) 2016-2019,2021, 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{
Ambroise Vincent9660dc12019-07-12 13:47:03 +010025 if (pmf_setup() != 0) {
dp-arm1cebefd2016-09-19 11:21:03 +010026 return 1;
Ambroise Vincent9660dc12019-07-12 13:47:03 +010027 }
28
29#if USE_DEBUGFS
30
31 if (debugfs_smc_setup() != 0) {
32 return 1;
33 }
34
35#endif /* USE_DEBUGFS */
36
dp-arm1cebefd2016-09-19 11:21:03 +010037 return 0;
38}
39
40/*
41 * This function handles ARM defined SiP Calls
42 */
43static uintptr_t arm_sip_handler(unsigned int smc_fid,
44 u_register_t x1,
45 u_register_t x2,
46 u_register_t x3,
47 u_register_t x4,
48 void *cookie,
49 void *handle,
50 u_register_t flags)
51{
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +000052 int call_count = 0;
53
Mikael Olsson7da66192021-02-12 17:30:22 +010054#if ENABLE_PMF
55
dp-arm1cebefd2016-09-19 11:21:03 +010056 /*
57 * Dispatch PMF calls to PMF SMC handler and return its return
58 * value
59 */
60 if (is_pmf_fid(smc_fid)) {
61 return pmf_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
62 handle, flags);
63 }
64
Mikael Olsson7da66192021-02-12 17:30:22 +010065#endif /* ENABLE_PMF */
66
Ambroise Vincent9660dc12019-07-12 13:47:03 +010067#if USE_DEBUGFS
68
69 if (is_debugfs_fid(smc_fid)) {
70 return debugfs_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
71 handle, flags);
72 }
73
74#endif /* USE_DEBUGFS */
75
Mikael Olsson7da66192021-02-12 17:30:22 +010076#if ARM_ETHOSN_NPU_DRIVER
77
78 if (is_ethosn_fid(smc_fid)) {
79 return ethosn_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
80 handle, flags);
81 }
82
83#endif /* ARM_ETHOSN_NPU_DRIVER */
84
dp-arm1cebefd2016-09-19 11:21:03 +010085 switch (smc_fid) {
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +000086 case ARM_SIP_SVC_EXE_STATE_SWITCH: {
Bence Szépkúti16362c62019-10-24 15:53:23 +020087 /* Execution state can be switched only if EL3 is AArch64 */
88#ifdef __aarch64__
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +000089 /* Allow calls from non-secure only */
90 if (!is_caller_non_secure(flags))
91 SMC_RET1(handle, STATE_SW_E_DENIED);
92
dp-arm1cebefd2016-09-19 11:21:03 +010093 /*
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +000094 * Pointers used in execution state switch are all 32 bits wide
dp-arm1cebefd2016-09-19 11:21:03 +010095 */
Jeenu Viswambharan210f0a82018-08-02 10:14:12 +010096 return (uintptr_t) arm_execution_state_switch(smc_fid,
97 (uint32_t) x1, (uint32_t) x2, (uint32_t) x3,
98 (uint32_t) x4, handle);
Bence Szépkúti16362c62019-10-24 15:53:23 +020099#else
100 /* State switch denied */
101 SMC_RET1(handle, STATE_SW_E_DENIED);
102#endif /* __aarch64__ */
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +0000103 }
104
105 case ARM_SIP_SVC_CALL_COUNT:
106 /* PMF calls */
107 call_count += PMF_NUM_SMC_CALLS;
108
Mikael Olsson7da66192021-02-12 17:30:22 +0100109#if ARM_ETHOSN_NPU_DRIVER
110 /* ETHOSN calls */
111 call_count += ETHOSN_NUM_SMC_CALLS;
112#endif /* ARM_ETHOSN_NPU_DRIVER */
113
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +0000114 /* State switch call */
115 call_count += 1;
116
117 SMC_RET1(handle, call_count);
dp-arm1cebefd2016-09-19 11:21:03 +0100118
119 case ARM_SIP_SVC_UID:
120 /* Return UID to the caller */
121 SMC_UUID_RET(handle, arm_sip_svc_uid);
122
123 case ARM_SIP_SVC_VERSION:
124 /* Return the version of current implementation */
125 SMC_RET2(handle, ARM_SIP_SVC_VERSION_MAJOR, ARM_SIP_SVC_VERSION_MINOR);
126
127 default:
128 WARN("Unimplemented ARM SiP Service Call: 0x%x \n", smc_fid);
129 SMC_RET1(handle, SMC_UNK);
130 }
131
132}
133
134
135/* Define a runtime service descriptor for fast SMC calls */
136DECLARE_RT_SVC(
137 arm_sip_svc,
138 OEN_SIP_START,
139 OEN_SIP_END,
140 SMC_TYPE_FAST,
141 arm_sip_setup,
142 arm_sip_handler
143);