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