xref: /rk3399_ARM-atf/services/arm_arch_svc/arm_arch_svc_setup.c (revision 73a9605197ba04aaf02d436a2a4ad56e695b426c)
1 /*
2  * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <arm_arch_svc.h>
8 #include <debug.h>
9 #include <runtime_svc.h>
10 #include <smcc.h>
11 #include <smcc_helpers.h>
12 
13 static int32_t smccc_version(void)
14 {
15 	return MAKE_SMCCC_VERSION(SMCCC_MAJOR_VERSION, SMCCC_MINOR_VERSION);
16 }
17 
18 static int32_t smccc_arch_features(u_register_t arg)
19 {
20 	switch (arg) {
21 	case SMCCC_VERSION:
22 	case SMCCC_ARCH_FEATURES:
23 		return SMC_OK;
24 #if WORKAROUND_CVE_2017_5715
25 	case SMCCC_ARCH_WORKAROUND_1:
26 		return SMC_OK;
27 #endif
28 	default:
29 		return SMC_UNK;
30 	}
31 }
32 
33 /*
34  * Top-level Arm Architectural Service SMC handler.
35  */
36 static uintptr_t arm_arch_svc_smc_handler(uint32_t smc_fid,
37 	u_register_t x1,
38 	u_register_t x2,
39 	u_register_t x3,
40 	u_register_t x4,
41 	void *cookie,
42 	void *handle,
43 	u_register_t flags)
44 {
45 	switch (smc_fid) {
46 	case SMCCC_VERSION:
47 		SMC_RET1(handle, smccc_version());
48 	case SMCCC_ARCH_FEATURES:
49 		SMC_RET1(handle, smccc_arch_features(x1));
50 #if WORKAROUND_CVE_2017_5715
51 	case SMCCC_ARCH_WORKAROUND_1:
52 		/*
53 		 * The workaround has already been applied on affected PEs
54 		 * during entry to EL3.  On unaffected PEs, this function
55 		 * has no effect.
56 		 */
57 		SMC_RET0(handle);
58 #endif
59 	default:
60 		WARN("Unimplemented Arm Architecture Service Call: 0x%x \n",
61 			smc_fid);
62 		SMC_RET1(handle, SMC_UNK);
63 	}
64 }
65 
66 /* Register Standard Service Calls as runtime service */
67 DECLARE_RT_SVC(
68 		arm_arch_svc,
69 		OEN_ARM_START,
70 		OEN_ARM_END,
71 		SMC_TYPE_FAST,
72 		NULL,
73 		arm_arch_svc_smc_handler
74 );
75