blob: 83d3625f958d509ecfcb131479b72ebfbec95339 [file] [log] [blame]
Dimitris Papastamos0dcdb1a2018-01-19 16:58:29 +00001/*
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>
Dimitris Papastamos914757c2018-03-12 14:47:09 +00009#include <errata_report.h>
Dimitris Papastamos0dcdb1a2018-01-19 16:58:29 +000010#include <runtime_svc.h>
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +000011#include <smccc.h>
12#include <smccc_helpers.h>
Dimitris Papastamos914757c2018-03-12 14:47:09 +000013#include <workaround_cve_2017_5715.h>
Dimitris Papastamos0dcdb1a2018-01-19 16:58:29 +000014
15static int32_t smccc_version(void)
16{
17 return MAKE_SMCCC_VERSION(SMCCC_MAJOR_VERSION, SMCCC_MINOR_VERSION);
18}
19
20static int32_t smccc_arch_features(u_register_t arg)
21{
Dimitris Papastamos914757c2018-03-12 14:47:09 +000022 int ret;
23
Dimitris Papastamos0dcdb1a2018-01-19 16:58:29 +000024 switch (arg) {
25 case SMCCC_VERSION:
26 case SMCCC_ARCH_FEATURES:
27 return SMC_OK;
Dimitris Papastamos0dcdb1a2018-01-19 16:58:29 +000028 case SMCCC_ARCH_WORKAROUND_1:
Dimitris Papastamos914757c2018-03-12 14:47:09 +000029 ret = check_workaround_cve_2017_5715();
30 if (ret == ERRATA_APPLIES)
31 return 0;
32 else if (ret == ERRATA_NOT_APPLIES)
33 return 1;
34 return -1; /* ERRATA_MISSING */
Dimitris Papastamos0dcdb1a2018-01-19 16:58:29 +000035 default:
36 return SMC_UNK;
37 }
38}
39
40/*
41 * Top-level Arm Architectural Service SMC handler.
42 */
Roberto Vargas05712702018-02-12 12:36:17 +000043static uintptr_t arm_arch_svc_smc_handler(uint32_t smc_fid,
Dimitris Papastamos0dcdb1a2018-01-19 16:58:29 +000044 u_register_t x1,
45 u_register_t x2,
46 u_register_t x3,
47 u_register_t x4,
48 void *cookie,
49 void *handle,
50 u_register_t flags)
51{
52 switch (smc_fid) {
53 case SMCCC_VERSION:
54 SMC_RET1(handle, smccc_version());
55 case SMCCC_ARCH_FEATURES:
56 SMC_RET1(handle, smccc_arch_features(x1));
57#if WORKAROUND_CVE_2017_5715
58 case SMCCC_ARCH_WORKAROUND_1:
59 /*
60 * The workaround has already been applied on affected PEs
61 * during entry to EL3. On unaffected PEs, this function
62 * has no effect.
63 */
64 SMC_RET0(handle);
65#endif
66 default:
67 WARN("Unimplemented Arm Architecture Service Call: 0x%x \n",
68 smc_fid);
69 SMC_RET1(handle, SMC_UNK);
70 }
71}
72
73/* Register Standard Service Calls as runtime service */
74DECLARE_RT_SVC(
75 arm_arch_svc,
76 OEN_ARM_START,
77 OEN_ARM_END,
78 SMC_TYPE_FAST,
79 NULL,
80 arm_arch_svc_smc_handler
81);