1 /*
2 * Copyright (c) 2024, 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 #include <services/ven_el3_svc.h>
14 #include <tools_share/uuid.h>
15
16 /* vendor-specific EL3 UUID */
17 DEFINE_SVC_UUID2(ven_el3_svc_uid,
18 0xb6011dca, 0x57c4, 0x407e, 0x83, 0xf0,
19 0xa7, 0xed, 0xda, 0xf0, 0xdf, 0x6c);
20
ven_el3_svc_setup(void)21 static int ven_el3_svc_setup(void)
22 {
23 #if USE_DEBUGFS
24 if (debugfs_smc_setup() != 0) {
25 return 1;
26 }
27 #endif /* USE_DEBUGFS */
28
29 #if ENABLE_PMF
30 if (pmf_setup() != 0) {
31 return 1;
32 }
33 #endif /* ENABLE_PMF */
34
35 return 0;
36 }
37
38 /*
39 * This function handles Arm defined vendor-specific EL3 Service Calls.
40 */
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)41 static uintptr_t ven_el3_svc_handler(unsigned int smc_fid,
42 u_register_t x1,
43 u_register_t x2,
44 u_register_t x3,
45 u_register_t x4,
46 void *cookie,
47 void *handle,
48 u_register_t flags)
49 {
50 #if USE_DEBUGFS
51 /*
52 * Dispatch debugfs calls to debugfs SMC handler and return its
53 * return value.
54 */
55 if (is_debugfs_fid(smc_fid)) {
56 return debugfs_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
57 handle, flags);
58 }
59 #endif /* USE_DEBUGFS */
60
61 #if ENABLE_PMF
62
63 /*
64 * Dispatch PMF calls to PMF SMC handler and return its return
65 * value
66 */
67 if (is_pmf_fid(smc_fid)) {
68 return pmf_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
69 handle, flags);
70 }
71
72 #endif /* ENABLE_PMF */
73
74 switch (smc_fid) {
75 case VEN_EL3_SVC_UID:
76 /* Return UID to the caller */
77 SMC_UUID_RET(handle, ven_el3_svc_uid);
78 break;
79 case VEN_EL3_SVC_VERSION:
80 SMC_RET2(handle, VEN_EL3_SVC_VERSION_MAJOR, VEN_EL3_SVC_VERSION_MINOR);
81 break;
82 default:
83 WARN("Unimplemented vendor-specific EL3 Service call: 0x%x\n", smc_fid);
84 SMC_RET1(handle, SMC_UNK);
85 break;
86 }
87 }
88
89 /* Define a runtime service descriptor for fast SMC calls */
90 DECLARE_RT_SVC(
91 ven_el3_svc,
92 OEN_VEN_EL3_START,
93 OEN_VEN_EL3_END,
94 SMC_TYPE_FAST,
95 ven_el3_svc_setup,
96 ven_el3_svc_handler
97 );
98