1 /*
2 * Copyright (c) 2024-2025, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #include <stdint.h>
8
9 #include <common/debug.h>
10 #include <common/runtime_svc.h>
11 #include <lib/debugfs.h>
12 #include <lib/pmf/pmf.h>
13 #if PLAT_ARM_ACS_SMC_HANDLER
14 #include <plat/arm/common/plat_acs_smc_handler.h>
15 #endif /* PLAT_ARM_ACS_SMC_HANDLER */
16 #include <services/spm_mm_svc.h>
17 #include <services/ven_el3_svc.h>
18 #include <tools_share/uuid.h>
19
20 /* vendor-specific EL3 UUID */
21 DEFINE_SVC_UUID2(ven_el3_svc_uid,
22 0xb6011dca, 0x57c4, 0x407e, 0x83, 0xf0,
23 0xa7, 0xed, 0xda, 0xf0, 0xdf, 0x6c);
24
ven_el3_svc_setup(void)25 static int ven_el3_svc_setup(void)
26 {
27 #if USE_DEBUGFS
28 if (debugfs_smc_setup() != 0) {
29 return 1;
30 }
31 #endif /* USE_DEBUGFS */
32
33 #if ENABLE_PMF
34 if (pmf_setup() != 0) {
35 return 1;
36 }
37 #endif /* ENABLE_PMF */
38
39 return 0;
40 }
41
42 /*
43 * This function handles Arm defined vendor-specific EL3 Service Calls.
44 */
ven_el3_svc_handler(unsigned int smc_fid,u_register_t x1,u_register_t x2,u_register_t x3,u_register_t x4,void * cookie,void * handle,u_register_t flags)45 static uintptr_t ven_el3_svc_handler(unsigned int smc_fid,
46 u_register_t x1,
47 u_register_t x2,
48 u_register_t x3,
49 u_register_t x4,
50 void *cookie,
51 void *handle,
52 u_register_t flags)
53 {
54 #if USE_DEBUGFS
55 /*
56 * Dispatch debugfs calls to debugfs SMC handler and return its
57 * return value.
58 */
59 if (is_debugfs_fid(smc_fid)) {
60 return debugfs_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
61 handle, flags);
62 }
63 #endif /* USE_DEBUGFS */
64
65 #if ENABLE_PMF
66
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
76 #endif /* ENABLE_PMF */
77
78 #if PLAT_ARM_ACS_SMC_HANDLER
79 /*
80 * Dispatch ACS calls to ACS SMC handler and return its return value
81 */
82 if (is_acs_fid(smc_fid)) {
83 return plat_arm_acs_smc_handler(smc_fid, x1, x2, x3, x4, handle);
84 }
85 #endif /* PLAT_ARM_ACS_SMC_HANDLER */
86
87 switch (smc_fid) {
88 case VEN_EL3_SVC_UID:
89 /* Return UID to the caller */
90 SMC_UUID_RET(handle, ven_el3_svc_uid);
91 break;
92 case VEN_EL3_SVC_VERSION:
93 SMC_RET2(handle, VEN_EL3_SVC_VERSION_MAJOR, VEN_EL3_SVC_VERSION_MINOR);
94 break;
95 #if SPM_MM
96 /*
97 * Handle TPM start SMC as mentioned in TCG ACPI specification.
98 */
99 case TPM_START_SMC_32:
100 case TPM_START_SMC_64:
101 return spm_mm_tpm_start_handler(smc_fid, x1, x2, x3, x4, cookie,
102 handle, flags);
103 break;
104 #endif
105 default:
106 WARN("Unimplemented vendor-specific EL3 Service call: 0x%x\n", smc_fid);
107 SMC_RET1(handle, SMC_UNK);
108 break;
109 }
110 }
111
112 /* Define a runtime service descriptor for fast SMC calls */
113 DECLARE_RT_SVC(
114 ven_el3_svc,
115 OEN_VEN_EL3_START,
116 OEN_VEN_EL3_END,
117 SMC_TYPE_FAST,
118 ven_el3_svc_setup,
119 ven_el3_svc_handler
120 );
121