xref: /rk3399_ARM-atf/services/el3/ven_el3_svc.c (revision 273b898388adde0d7cc858fab6774b1da61caa0f)
1de6b79d8SGovindraj Raja /*
2de6b79d8SGovindraj Raja  * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
3de6b79d8SGovindraj Raja  *
4de6b79d8SGovindraj Raja  * SPDX-License-Identifier: BSD-3-Clause
5de6b79d8SGovindraj Raja  */
6de6b79d8SGovindraj Raja 
7de6b79d8SGovindraj Raja #include <stdint.h>
8de6b79d8SGovindraj Raja 
9de6b79d8SGovindraj Raja #include <common/debug.h>
10de6b79d8SGovindraj Raja #include <common/runtime_svc.h>
11*273b8983SGovindraj Raja #include <lib/debugfs.h>
12de6b79d8SGovindraj Raja #include <services/ven_el3_svc.h>
13de6b79d8SGovindraj Raja #include <tools_share/uuid.h>
14de6b79d8SGovindraj Raja 
15de6b79d8SGovindraj Raja /* vendor-specific EL3 UUID */
16de6b79d8SGovindraj Raja DEFINE_SVC_UUID2(ven_el3_svc_uid,
17de6b79d8SGovindraj Raja 	0xb6011dca, 0x57c4, 0x407e, 0x83, 0xf0,
18de6b79d8SGovindraj Raja 	0xa7, 0xed, 0xda, 0xf0, 0xdf, 0x6c);
19de6b79d8SGovindraj Raja 
20de6b79d8SGovindraj Raja static int ven_el3_svc_setup(void)
21de6b79d8SGovindraj Raja {
22*273b8983SGovindraj Raja #if USE_DEBUGFS
23*273b8983SGovindraj Raja 	if (debugfs_smc_setup() != 0) {
24*273b8983SGovindraj Raja 		return 1;
25*273b8983SGovindraj Raja 	}
26*273b8983SGovindraj Raja #endif /* USE_DEBUGFS */
27*273b8983SGovindraj Raja 
28de6b79d8SGovindraj Raja 	return 0;
29de6b79d8SGovindraj Raja }
30de6b79d8SGovindraj Raja 
31de6b79d8SGovindraj Raja /*
32de6b79d8SGovindraj Raja  * This function handles Arm defined vendor-specific EL3 Service Calls.
33de6b79d8SGovindraj Raja  */
34de6b79d8SGovindraj Raja static uintptr_t ven_el3_svc_handler(unsigned int smc_fid,
35de6b79d8SGovindraj Raja 			u_register_t x1,
36de6b79d8SGovindraj Raja 			u_register_t x2,
37de6b79d8SGovindraj Raja 			u_register_t x3,
38de6b79d8SGovindraj Raja 			u_register_t x4,
39de6b79d8SGovindraj Raja 			void *cookie,
40de6b79d8SGovindraj Raja 			void *handle,
41de6b79d8SGovindraj Raja 			u_register_t flags)
42de6b79d8SGovindraj Raja {
43*273b8983SGovindraj Raja #if USE_DEBUGFS
44*273b8983SGovindraj Raja 	/*
45*273b8983SGovindraj Raja 	 * Dispatch debugfs calls to debugfs SMC handler and return its
46*273b8983SGovindraj Raja 	 * return value.
47*273b8983SGovindraj Raja 	 */
48*273b8983SGovindraj Raja 	if (is_debugfs_fid(smc_fid)) {
49*273b8983SGovindraj Raja 		return debugfs_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
50*273b8983SGovindraj Raja 			handle, flags);
51*273b8983SGovindraj Raja 	}
52*273b8983SGovindraj Raja #endif /* USE_DEBUGFS */
53*273b8983SGovindraj Raja 
54de6b79d8SGovindraj Raja 	switch (smc_fid) {
55de6b79d8SGovindraj Raja 	case VEN_EL3_SVC_UID:
56de6b79d8SGovindraj Raja 		/* Return UID to the caller */
57de6b79d8SGovindraj Raja 		SMC_UUID_RET(handle, ven_el3_svc_uid);
58de6b79d8SGovindraj Raja 		break;
59de6b79d8SGovindraj Raja 	case VEN_EL3_SVC_VERSION:
60de6b79d8SGovindraj Raja 		SMC_RET2(handle, VEN_EL3_SVC_VERSION_MAJOR, VEN_EL3_SVC_VERSION_MINOR);
61de6b79d8SGovindraj Raja 		break;
62de6b79d8SGovindraj Raja 	default:
63*273b8983SGovindraj Raja 		WARN("Unimplemented vendor-specific EL3 Service call: 0x%x\n", smc_fid);
64de6b79d8SGovindraj Raja 		SMC_RET1(handle, SMC_UNK);
65de6b79d8SGovindraj Raja 		break;
66de6b79d8SGovindraj Raja 	}
67de6b79d8SGovindraj Raja }
68de6b79d8SGovindraj Raja 
69de6b79d8SGovindraj Raja /* Define a runtime service descriptor for fast SMC calls */
70de6b79d8SGovindraj Raja DECLARE_RT_SVC(
71de6b79d8SGovindraj Raja 	ven_el3_svc,
72de6b79d8SGovindraj Raja 	OEN_VEN_EL3_START,
73de6b79d8SGovindraj Raja 	OEN_VEN_EL3_END,
74de6b79d8SGovindraj Raja 	SMC_TYPE_FAST,
75de6b79d8SGovindraj Raja 	ven_el3_svc_setup,
76de6b79d8SGovindraj Raja 	ven_el3_svc_handler
77de6b79d8SGovindraj Raja );
78