xref: /rk3399_ARM-atf/services/el3/ven_el3_svc.c (revision f69f551269f1d126877889a1cab27cc1692316ea)
1de6b79d8SGovindraj Raja /*
2*f69f5512SNandan J  * Copyright (c) 2024-2025, 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>
11273b8983SGovindraj Raja #include <lib/debugfs.h>
12f7679d43SGovindraj Raja #include <lib/pmf/pmf.h>
13*f69f5512SNandan J #if PLAT_ARM_ACS_SMC_HANDLER
14*f69f5512SNandan J #include <plat/arm/common/plat_acs_smc_handler.h>
15*f69f5512SNandan J #endif /* PLAT_ARM_ACS_SMC_HANDLER */
16de6b79d8SGovindraj Raja #include <services/ven_el3_svc.h>
17de6b79d8SGovindraj Raja #include <tools_share/uuid.h>
18de6b79d8SGovindraj Raja 
19de6b79d8SGovindraj Raja /* vendor-specific EL3 UUID */
20de6b79d8SGovindraj Raja DEFINE_SVC_UUID2(ven_el3_svc_uid,
21de6b79d8SGovindraj Raja 	0xb6011dca, 0x57c4, 0x407e, 0x83, 0xf0,
22de6b79d8SGovindraj Raja 	0xa7, 0xed, 0xda, 0xf0, 0xdf, 0x6c);
23de6b79d8SGovindraj Raja 
24de6b79d8SGovindraj Raja static int ven_el3_svc_setup(void)
25de6b79d8SGovindraj Raja {
26273b8983SGovindraj Raja #if USE_DEBUGFS
27273b8983SGovindraj Raja 	if (debugfs_smc_setup() != 0) {
28273b8983SGovindraj Raja 		return 1;
29273b8983SGovindraj Raja 	}
30273b8983SGovindraj Raja #endif /* USE_DEBUGFS */
31273b8983SGovindraj Raja 
32f7679d43SGovindraj Raja #if ENABLE_PMF
33f7679d43SGovindraj Raja 	if (pmf_setup() != 0) {
34f7679d43SGovindraj Raja 		return 1;
35f7679d43SGovindraj Raja 	}
36f7679d43SGovindraj Raja #endif /* ENABLE_PMF */
37f7679d43SGovindraj Raja 
38de6b79d8SGovindraj Raja 	return 0;
39de6b79d8SGovindraj Raja }
40de6b79d8SGovindraj Raja 
41de6b79d8SGovindraj Raja /*
42de6b79d8SGovindraj Raja  * This function handles Arm defined vendor-specific EL3 Service Calls.
43de6b79d8SGovindraj Raja  */
44de6b79d8SGovindraj Raja static uintptr_t ven_el3_svc_handler(unsigned int smc_fid,
45de6b79d8SGovindraj Raja 			u_register_t x1,
46de6b79d8SGovindraj Raja 			u_register_t x2,
47de6b79d8SGovindraj Raja 			u_register_t x3,
48de6b79d8SGovindraj Raja 			u_register_t x4,
49de6b79d8SGovindraj Raja 			void *cookie,
50de6b79d8SGovindraj Raja 			void *handle,
51de6b79d8SGovindraj Raja 			u_register_t flags)
52de6b79d8SGovindraj Raja {
53273b8983SGovindraj Raja #if USE_DEBUGFS
54273b8983SGovindraj Raja 	/*
55273b8983SGovindraj Raja 	 * Dispatch debugfs calls to debugfs SMC handler and return its
56273b8983SGovindraj Raja 	 * return value.
57273b8983SGovindraj Raja 	 */
58273b8983SGovindraj Raja 	if (is_debugfs_fid(smc_fid)) {
59273b8983SGovindraj Raja 		return debugfs_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
60273b8983SGovindraj Raja 			handle, flags);
61273b8983SGovindraj Raja 	}
62273b8983SGovindraj Raja #endif /* USE_DEBUGFS */
63273b8983SGovindraj Raja 
64f7679d43SGovindraj Raja #if ENABLE_PMF
65f7679d43SGovindraj Raja 
66f7679d43SGovindraj Raja 	/*
67f7679d43SGovindraj Raja 	 * Dispatch PMF calls to PMF SMC handler and return its return
68f7679d43SGovindraj Raja 	 * value
69f7679d43SGovindraj Raja 	 */
70f7679d43SGovindraj Raja 	if (is_pmf_fid(smc_fid)) {
71f7679d43SGovindraj Raja 		return pmf_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
72f7679d43SGovindraj Raja 				handle, flags);
73f7679d43SGovindraj Raja 	}
74f7679d43SGovindraj Raja 
75f7679d43SGovindraj Raja #endif /* ENABLE_PMF */
76f7679d43SGovindraj Raja 
77*f69f5512SNandan J #if PLAT_ARM_ACS_SMC_HANDLER
78*f69f5512SNandan J 	/*
79*f69f5512SNandan J 	 * Dispatch ACS calls to ACS SMC handler and return its return value
80*f69f5512SNandan J 	 */
81*f69f5512SNandan J 	if (is_acs_fid(smc_fid)) {
82*f69f5512SNandan J 		return plat_arm_acs_smc_handler(smc_fid, x1, x2, x3, x4, handle);
83*f69f5512SNandan J 	}
84*f69f5512SNandan J #endif /* PLAT_ARM_ACS_SMC_HANDLER */
85*f69f5512SNandan J 
86de6b79d8SGovindraj Raja 	switch (smc_fid) {
87de6b79d8SGovindraj Raja 	case VEN_EL3_SVC_UID:
88de6b79d8SGovindraj Raja 		/* Return UID to the caller */
89de6b79d8SGovindraj Raja 		SMC_UUID_RET(handle, ven_el3_svc_uid);
90de6b79d8SGovindraj Raja 		break;
91de6b79d8SGovindraj Raja 	case VEN_EL3_SVC_VERSION:
92de6b79d8SGovindraj Raja 		SMC_RET2(handle, VEN_EL3_SVC_VERSION_MAJOR, VEN_EL3_SVC_VERSION_MINOR);
93de6b79d8SGovindraj Raja 		break;
94de6b79d8SGovindraj Raja 	default:
95273b8983SGovindraj Raja 		WARN("Unimplemented vendor-specific EL3 Service call: 0x%x\n", smc_fid);
96de6b79d8SGovindraj Raja 		SMC_RET1(handle, SMC_UNK);
97de6b79d8SGovindraj Raja 		break;
98de6b79d8SGovindraj Raja 	}
99de6b79d8SGovindraj Raja }
100de6b79d8SGovindraj Raja 
101de6b79d8SGovindraj Raja /* Define a runtime service descriptor for fast SMC calls */
102de6b79d8SGovindraj Raja DECLARE_RT_SVC(
103de6b79d8SGovindraj Raja 	ven_el3_svc,
104de6b79d8SGovindraj Raja 	OEN_VEN_EL3_START,
105de6b79d8SGovindraj Raja 	OEN_VEN_EL3_END,
106de6b79d8SGovindraj Raja 	SMC_TYPE_FAST,
107de6b79d8SGovindraj Raja 	ven_el3_svc_setup,
108de6b79d8SGovindraj Raja 	ven_el3_svc_handler
109de6b79d8SGovindraj Raja );
110