blob: 6089cf6ac8ba23300038c977746122f52427ad63 [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 Papastamos570c06a2018-04-06 15:29:34 +010013#include <wa_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{
22 switch (arg) {
23 case SMCCC_VERSION:
24 case SMCCC_ARCH_FEATURES:
25 return SMC_OK;
Dimitris Papastamos6d1f4992018-03-28 12:06:40 +010026#if WORKAROUND_CVE_2017_5715
Dimitris Papastamos0dcdb1a2018-01-19 16:58:29 +000027 case SMCCC_ARCH_WORKAROUND_1:
Dimitris Papastamos570c06a2018-04-06 15:29:34 +010028 if (check_wa_cve_2017_5715() == ERRATA_NOT_APPLIES)
Dimitris Papastamos914757c2018-03-12 14:47:09 +000029 return 1;
Dimitris Papastamos6d1f4992018-03-28 12:06:40 +010030 return 0; /* ERRATA_APPLIES || ERRATA_MISSING */
31#endif
Dimitris Papastamose6625ec2018-04-05 14:38:26 +010032#if WORKAROUND_CVE_2018_3639
33 case SMCCC_ARCH_WORKAROUND_2:
34 return SMCCC_ARCH_NOT_REQUIRED;
35#endif
Dimitris Papastamos0dcdb1a2018-01-19 16:58:29 +000036 default:
37 return SMC_UNK;
38 }
39}
40
41/*
42 * Top-level Arm Architectural Service SMC handler.
43 */
Roberto Vargas05712702018-02-12 12:36:17 +000044static uintptr_t arm_arch_svc_smc_handler(uint32_t smc_fid,
Dimitris Papastamos0dcdb1a2018-01-19 16:58:29 +000045 u_register_t x1,
46 u_register_t x2,
47 u_register_t x3,
48 u_register_t x4,
49 void *cookie,
50 void *handle,
51 u_register_t flags)
52{
53 switch (smc_fid) {
54 case SMCCC_VERSION:
55 SMC_RET1(handle, smccc_version());
56 case SMCCC_ARCH_FEATURES:
57 SMC_RET1(handle, smccc_arch_features(x1));
58#if WORKAROUND_CVE_2017_5715
59 case SMCCC_ARCH_WORKAROUND_1:
60 /*
61 * The workaround has already been applied on affected PEs
62 * during entry to EL3. On unaffected PEs, this function
63 * has no effect.
64 */
65 SMC_RET0(handle);
66#endif
Dimitris Papastamose6625ec2018-04-05 14:38:26 +010067#if WORKAROUND_CVE_2018_3639
68 case SMCCC_ARCH_WORKAROUND_2:
69 /*
70 * The workaround has already been applied on affected PEs
71 * requiring dynamic mitigation during entry to EL3.
72 * On unaffected or statically mitigated PEs, this function
73 * has no effect.
74 */
75 SMC_RET0(handle);
76#endif
Dimitris Papastamos0dcdb1a2018-01-19 16:58:29 +000077 default:
78 WARN("Unimplemented Arm Architecture Service Call: 0x%x \n",
79 smc_fid);
80 SMC_RET1(handle, SMC_UNK);
81 }
82}
83
84/* Register Standard Service Calls as runtime service */
85DECLARE_RT_SVC(
86 arm_arch_svc,
87 OEN_ARM_START,
88 OEN_ARM_END,
89 SMC_TYPE_FAST,
90 NULL,
91 arm_arch_svc_smc_handler
92);