arm_arch_svc_setup.c 4.08 KB
Newer Older
1
/*
johpow01's avatar
johpow01 committed
2
 * Copyright (c) 2018-2021, ARM Limited and Contributors. All rights reserved.
3
4
5
6
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

7
8
9
10
11
12
13
#include <common/debug.h>
#include <common/runtime_svc.h>
#include <lib/cpus/errata_report.h>
#include <lib/cpus/wa_cve_2017_5715.h>
#include <lib/cpus/wa_cve_2018_3639.h>
#include <lib/smccc.h>
#include <services/arm_arch_svc.h>
johpow01's avatar
johpow01 committed
14
15
#include <services/rmi_svc.h>
#include <services/rmmd_svc.h>
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
16
#include <smccc_helpers.h>
17
#include <plat/common/platform.h>
18

johpow01's avatar
johpow01 committed
19
20
21
22
23
24
25
26
#if ENABLE_RME
/* Setup Arm architecture Services */
static int32_t arm_arch_svc_setup(void)
{
	return rmmd_setup();
}
#endif

27
28
29
30
31
static int32_t smccc_version(void)
{
	return MAKE_SMCCC_VERSION(SMCCC_MAJOR_VERSION, SMCCC_MINOR_VERSION);
}

32
static int32_t smccc_arch_features(u_register_t arg1)
33
{
34
	switch (arg1) {
35
36
	case SMCCC_VERSION:
	case SMCCC_ARCH_FEATURES:
37
		return SMC_ARCH_CALL_SUCCESS;
38
	case SMCCC_ARCH_SOC_ID:
39
		return plat_is_smccc_feature_available(arg1);
40
#if WORKAROUND_CVE_2017_5715
41
	case SMCCC_ARCH_WORKAROUND_1:
42
		if (check_wa_cve_2017_5715() == ERRATA_NOT_APPLIES)
43
			return 1;
44
		return 0; /* ERRATA_APPLIES || ERRATA_MISSING */
45
#endif
46

47
#if WORKAROUND_CVE_2018_3639
48
	case SMCCC_ARCH_WORKAROUND_2: {
49
#if DYNAMIC_WORKAROUND_CVE_2018_3639
50
51
52
53
54
55
56
		unsigned long long ssbs;

		/*
		 * Firmware doesn't have to carry out dynamic workaround if the
		 * PE implements architectural Speculation Store Bypass Safe
		 * (SSBS) feature.
		 */
57
		ssbs = (read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_SSBS_SHIFT) &
58
59
60
61
62
63
64
65
66
			ID_AA64PFR1_EL1_SSBS_MASK;

		/*
		 * If architectural SSBS is available on this PE, no firmware
		 * mitigation via SMCCC_ARCH_WORKAROUND_2 is required.
		 */
		if (ssbs != SSBS_UNAVAILABLE)
			return 1;

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
		/*
		 * On a platform where at least one CPU requires
		 * dynamic mitigation but others are either unaffected
		 * or permanently mitigated, report the latter as not
		 * needing dynamic mitigation.
		 */
		if (wa_cve_2018_3639_get_disable_ptr() == NULL)
			return 1;
		/*
		 * If we get here, this CPU requires dynamic mitigation
		 * so report it as such.
		 */
		return 0;
#else
		/* Either the CPUs are unaffected or permanently mitigated */
82
		return SMC_ARCH_CALL_NOT_REQUIRED;
83
#endif
84
	}
85
#endif
86
87
88

	/* Fallthrough */

89
90
91
92
93
	default:
		return SMC_UNK;
	}
}

94
95
96
97
98
99
100
101
102
103
104
105
106
/* return soc revision or soc version on success otherwise
 * return invalid parameter */
static int32_t smccc_arch_id(u_register_t arg1)
{
	if (arg1 == SMCCC_GET_SOC_REVISION) {
		return plat_get_soc_revision();
	}
	if (arg1 == SMCCC_GET_SOC_VERSION) {
		return plat_get_soc_version();
	}
	return SMC_ARCH_CALL_INVAL_PARAM;
}

107
108
109
/*
 * Top-level Arm Architectural Service SMC handler.
 */
110
static uintptr_t arm_arch_svc_smc_handler(uint32_t smc_fid,
111
112
113
114
115
116
117
118
119
120
121
122
	u_register_t x1,
	u_register_t x2,
	u_register_t x3,
	u_register_t x4,
	void *cookie,
	void *handle,
	u_register_t flags)
{
	switch (smc_fid) {
	case SMCCC_VERSION:
		SMC_RET1(handle, smccc_version());
	case SMCCC_ARCH_FEATURES:
123
124
125
		SMC_RET1(handle, smccc_arch_features(x1));
	case SMCCC_ARCH_SOC_ID:
		SMC_RET1(handle, smccc_arch_id(x1));
126
127
128
129
130
131
132
133
#if WORKAROUND_CVE_2017_5715
	case SMCCC_ARCH_WORKAROUND_1:
		/*
		 * The workaround has already been applied on affected PEs
		 * during entry to EL3.  On unaffected PEs, this function
		 * has no effect.
		 */
		SMC_RET0(handle);
134
135
136
137
138
139
140
141
142
143
#endif
#if WORKAROUND_CVE_2018_3639
	case SMCCC_ARCH_WORKAROUND_2:
		/*
		 * The workaround has already been applied on affected PEs
		 * requiring dynamic mitigation during entry to EL3.
		 * On unaffected or statically mitigated PEs, this function
		 * has no effect.
		 */
		SMC_RET0(handle);
144
145
#endif
	default:
johpow01's avatar
johpow01 committed
146
147
148
149
150
151
152
153
154
155
#if ENABLE_RME
		/*
		 * RMI functions are allocated from the Arch service range. Call
		 * the RMM dispatcher to handle RMI calls.
		 */
		if (is_rmi_fid(smc_fid)) {
			return rmmd_rmi_handler(smc_fid, x1, x2, x3, x4, cookie,
						handle, flags);
		}
#endif
156
157
158
159
160
161
162
163
164
165
166
167
		WARN("Unimplemented Arm Architecture Service Call: 0x%x \n",
			smc_fid);
		SMC_RET1(handle, SMC_UNK);
	}
}

/* Register Standard Service Calls as runtime service */
DECLARE_RT_SVC(
		arm_arch_svc,
		OEN_ARM_START,
		OEN_ARM_END,
		SMC_TYPE_FAST,
johpow01's avatar
johpow01 committed
168
169
170
#if ENABLE_RME
		arm_arch_svc_setup,
#else
171
		NULL,
johpow01's avatar
johpow01 committed
172
#endif
173
174
		arm_arch_svc_smc_handler
);