arm_arch_svc_setup.c 1.69 KB
Newer Older
1
2
3
4
5
6
7
8
/*
 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <arm_arch_svc.h>
#include <debug.h>
9
#include <errata_report.h>
10
#include <runtime_svc.h>
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
11
12
#include <smccc.h>
#include <smccc_helpers.h>
13
#include <workaround_cve_2017_5715.h>
14
15
16
17
18
19
20
21

static int32_t smccc_version(void)
{
	return MAKE_SMCCC_VERSION(SMCCC_MAJOR_VERSION, SMCCC_MINOR_VERSION);
}

static int32_t smccc_arch_features(u_register_t arg)
{
22
23
	int ret;

24
25
26
27
28
	switch (arg) {
	case SMCCC_VERSION:
	case SMCCC_ARCH_FEATURES:
		return SMC_OK;
	case SMCCC_ARCH_WORKAROUND_1:
29
30
31
32
33
34
		ret = check_workaround_cve_2017_5715();
		if (ret == ERRATA_APPLIES)
			return 0;
		else if (ret == ERRATA_NOT_APPLIES)
			return 1;
		return -1; /* ERRATA_MISSING */
35
36
37
38
39
40
41
42
	default:
		return SMC_UNK;
	}
}

/*
 * Top-level Arm Architectural Service SMC handler.
 */
43
static uintptr_t arm_arch_svc_smc_handler(uint32_t smc_fid,
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
	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:
		SMC_RET1(handle, smccc_arch_features(x1));
#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);
#endif
	default:
		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,
		NULL,
		arm_arch_svc_smc_handler
);