Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 1 | /* |
Zelalem Aweke | 13dc8f1 | 2021-07-09 14:20:03 -0500 | [diff] [blame] | 2 | * Copyright (c) 2018-2021, ARM Limited and Contributors. All rights reserved. |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 7 | #include <common/debug.h> |
| 8 | #include <common/runtime_svc.h> |
| 9 | #include <lib/cpus/errata_report.h> |
| 10 | #include <lib/cpus/wa_cve_2017_5715.h> |
| 11 | #include <lib/cpus/wa_cve_2018_3639.h> |
| 12 | #include <lib/smccc.h> |
| 13 | #include <services/arm_arch_svc.h> |
Zelalem Aweke | 13dc8f1 | 2021-07-09 14:20:03 -0500 | [diff] [blame] | 14 | #include <services/rmi_svc.h> |
| 15 | #include <services/rmmd_svc.h> |
Antonio Nino Diaz | 3c817f4 | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 16 | #include <smccc_helpers.h> |
Manish V Badarkhe | f809c6e | 2020-02-22 08:43:00 +0000 | [diff] [blame] | 17 | #include <plat/common/platform.h> |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 18 | |
Zelalem Aweke | 13dc8f1 | 2021-07-09 14:20:03 -0500 | [diff] [blame] | 19 | #if ENABLE_RME |
| 20 | /* Setup Arm architecture Services */ |
| 21 | static int32_t arm_arch_svc_setup(void) |
| 22 | { |
| 23 | return rmmd_setup(); |
| 24 | } |
| 25 | #endif |
| 26 | |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 27 | static int32_t smccc_version(void) |
| 28 | { |
| 29 | return MAKE_SMCCC_VERSION(SMCCC_MAJOR_VERSION, SMCCC_MINOR_VERSION); |
| 30 | } |
| 31 | |
Manish V Badarkhe | 709bc37 | 2020-04-28 13:25:56 +0100 | [diff] [blame] | 32 | static int32_t smccc_arch_features(u_register_t arg1) |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 33 | { |
Manish V Badarkhe | f809c6e | 2020-02-22 08:43:00 +0000 | [diff] [blame] | 34 | switch (arg1) { |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 35 | case SMCCC_VERSION: |
| 36 | case SMCCC_ARCH_FEATURES: |
Manish V Badarkhe | 80f13ee | 2020-07-23 20:23:01 +0100 | [diff] [blame] | 37 | return SMC_ARCH_CALL_SUCCESS; |
Manish V Badarkhe | f809c6e | 2020-02-22 08:43:00 +0000 | [diff] [blame] | 38 | case SMCCC_ARCH_SOC_ID: |
Manish V Badarkhe | 80f13ee | 2020-07-23 20:23:01 +0100 | [diff] [blame] | 39 | return plat_is_smccc_feature_available(arg1); |
Dimitris Papastamos | 6d1f499 | 2018-03-28 12:06:40 +0100 | [diff] [blame] | 40 | #if WORKAROUND_CVE_2017_5715 |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 41 | case SMCCC_ARCH_WORKAROUND_1: |
Dimitris Papastamos | 570c06a | 2018-04-06 15:29:34 +0100 | [diff] [blame] | 42 | if (check_wa_cve_2017_5715() == ERRATA_NOT_APPLIES) |
Dimitris Papastamos | 914757c | 2018-03-12 14:47:09 +0000 | [diff] [blame] | 43 | return 1; |
Dimitris Papastamos | 6d1f499 | 2018-03-28 12:06:40 +0100 | [diff] [blame] | 44 | return 0; /* ERRATA_APPLIES || ERRATA_MISSING */ |
| 45 | #endif |
Jeenu Viswambharan | aa00aff | 2018-11-15 11:38:03 +0000 | [diff] [blame] | 46 | |
Dimitris Papastamos | e6625ec | 2018-04-05 14:38:26 +0100 | [diff] [blame] | 47 | #if WORKAROUND_CVE_2018_3639 |
Jeenu Viswambharan | aa00aff | 2018-11-15 11:38:03 +0000 | [diff] [blame] | 48 | case SMCCC_ARCH_WORKAROUND_2: { |
Dimitris Papastamos | ba51d9e | 2018-05-16 11:36:14 +0100 | [diff] [blame] | 49 | #if DYNAMIC_WORKAROUND_CVE_2018_3639 |
Jeenu Viswambharan | aa00aff | 2018-11-15 11:38:03 +0000 | [diff] [blame] | 50 | unsigned long long ssbs; |
| 51 | |
| 52 | /* |
| 53 | * Firmware doesn't have to carry out dynamic workaround if the |
| 54 | * PE implements architectural Speculation Store Bypass Safe |
| 55 | * (SSBS) feature. |
| 56 | */ |
Dimitris Papastamos | b091eb9 | 2019-02-27 11:46:48 +0000 | [diff] [blame] | 57 | ssbs = (read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_SSBS_SHIFT) & |
Jeenu Viswambharan | aa00aff | 2018-11-15 11:38:03 +0000 | [diff] [blame] | 58 | ID_AA64PFR1_EL1_SSBS_MASK; |
| 59 | |
| 60 | /* |
| 61 | * If architectural SSBS is available on this PE, no firmware |
| 62 | * mitigation via SMCCC_ARCH_WORKAROUND_2 is required. |
| 63 | */ |
| 64 | if (ssbs != SSBS_UNAVAILABLE) |
| 65 | return 1; |
| 66 | |
Dimitris Papastamos | ba51d9e | 2018-05-16 11:36:14 +0100 | [diff] [blame] | 67 | /* |
| 68 | * On a platform where at least one CPU requires |
| 69 | * dynamic mitigation but others are either unaffected |
| 70 | * or permanently mitigated, report the latter as not |
| 71 | * needing dynamic mitigation. |
| 72 | */ |
| 73 | if (wa_cve_2018_3639_get_disable_ptr() == NULL) |
| 74 | return 1; |
| 75 | /* |
| 76 | * If we get here, this CPU requires dynamic mitigation |
| 77 | * so report it as such. |
| 78 | */ |
| 79 | return 0; |
| 80 | #else |
| 81 | /* Either the CPUs are unaffected or permanently mitigated */ |
Manish V Badarkhe | 1333517 | 2020-02-19 13:36:50 +0000 | [diff] [blame] | 82 | return SMC_ARCH_CALL_NOT_REQUIRED; |
Dimitris Papastamos | e6625ec | 2018-04-05 14:38:26 +0100 | [diff] [blame] | 83 | #endif |
Jeenu Viswambharan | aa00aff | 2018-11-15 11:38:03 +0000 | [diff] [blame] | 84 | } |
Dimitris Papastamos | ba51d9e | 2018-05-16 11:36:14 +0100 | [diff] [blame] | 85 | #endif |
Jeenu Viswambharan | aa00aff | 2018-11-15 11:38:03 +0000 | [diff] [blame] | 86 | |
| 87 | /* Fallthrough */ |
| 88 | |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 89 | default: |
| 90 | return SMC_UNK; |
| 91 | } |
Manish V Badarkhe | 709bc37 | 2020-04-28 13:25:56 +0100 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /* return soc revision or soc version on success otherwise |
| 95 | * return invalid parameter */ |
| 96 | static int32_t smccc_arch_id(u_register_t arg1) |
| 97 | { |
| 98 | if (arg1 == SMCCC_GET_SOC_REVISION) { |
| 99 | return plat_get_soc_revision(); |
| 100 | } |
| 101 | if (arg1 == SMCCC_GET_SOC_VERSION) { |
| 102 | return plat_get_soc_version(); |
| 103 | } |
| 104 | return SMC_ARCH_CALL_INVAL_PARAM; |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /* |
| 108 | * Top-level Arm Architectural Service SMC handler. |
| 109 | */ |
Roberto Vargas | 0571270 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 110 | static uintptr_t arm_arch_svc_smc_handler(uint32_t smc_fid, |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 111 | u_register_t x1, |
| 112 | u_register_t x2, |
| 113 | u_register_t x3, |
| 114 | u_register_t x4, |
| 115 | void *cookie, |
| 116 | void *handle, |
| 117 | u_register_t flags) |
| 118 | { |
| 119 | switch (smc_fid) { |
| 120 | case SMCCC_VERSION: |
| 121 | SMC_RET1(handle, smccc_version()); |
| 122 | case SMCCC_ARCH_FEATURES: |
Manish V Badarkhe | 709bc37 | 2020-04-28 13:25:56 +0100 | [diff] [blame] | 123 | SMC_RET1(handle, smccc_arch_features(x1)); |
| 124 | case SMCCC_ARCH_SOC_ID: |
| 125 | SMC_RET1(handle, smccc_arch_id(x1)); |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 126 | #if WORKAROUND_CVE_2017_5715 |
| 127 | case SMCCC_ARCH_WORKAROUND_1: |
| 128 | /* |
| 129 | * The workaround has already been applied on affected PEs |
| 130 | * during entry to EL3. On unaffected PEs, this function |
| 131 | * has no effect. |
| 132 | */ |
| 133 | SMC_RET0(handle); |
| 134 | #endif |
Dimitris Papastamos | e6625ec | 2018-04-05 14:38:26 +0100 | [diff] [blame] | 135 | #if WORKAROUND_CVE_2018_3639 |
| 136 | case SMCCC_ARCH_WORKAROUND_2: |
| 137 | /* |
| 138 | * The workaround has already been applied on affected PEs |
| 139 | * requiring dynamic mitigation during entry to EL3. |
| 140 | * On unaffected or statically mitigated PEs, this function |
| 141 | * has no effect. |
| 142 | */ |
| 143 | SMC_RET0(handle); |
| 144 | #endif |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 145 | default: |
Zelalem Aweke | 13dc8f1 | 2021-07-09 14:20:03 -0500 | [diff] [blame] | 146 | #if ENABLE_RME |
| 147 | /* |
| 148 | * RMI functions are allocated from the Arch service range. Call |
| 149 | * the RMM dispatcher to handle RMI calls. |
| 150 | */ |
| 151 | if (is_rmi_fid(smc_fid)) { |
| 152 | return rmmd_rmi_handler(smc_fid, x1, x2, x3, x4, cookie, |
| 153 | handle, flags); |
| 154 | } |
| 155 | #endif |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 156 | WARN("Unimplemented Arm Architecture Service Call: 0x%x \n", |
| 157 | smc_fid); |
| 158 | SMC_RET1(handle, SMC_UNK); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /* Register Standard Service Calls as runtime service */ |
| 163 | DECLARE_RT_SVC( |
| 164 | arm_arch_svc, |
| 165 | OEN_ARM_START, |
| 166 | OEN_ARM_END, |
| 167 | SMC_TYPE_FAST, |
Zelalem Aweke | 13dc8f1 | 2021-07-09 14:20:03 -0500 | [diff] [blame] | 168 | #if ENABLE_RME |
| 169 | arm_arch_svc_setup, |
| 170 | #else |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 171 | NULL, |
Zelalem Aweke | 13dc8f1 | 2021-07-09 14:20:03 -0500 | [diff] [blame] | 172 | #endif |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 173 | arm_arch_svc_smc_handler |
| 174 | ); |