| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#include <common/debug.h> |
| 8 |
#include <common/runtime_svc.h> |
| 9 |
#include <lib/cpus/errata.h> |
| 10 |
#include <lib/cpus/wa_cve_2017_5715.h> |
| 11 |
#include <lib/cpus/wa_cve_2018_3639.h> |
| 12 |
#include <lib/cpus/wa_cve_2022_23960.h> |
| 13 |
#include <lib/smccc.h> |
| 14 |
#include <services/arm_arch_svc.h> |
| 15 |
#include <smccc_helpers.h> |
| 16 |
#include <plat/common/platform.h> |
| 17 |
|
| 18 |
static int32_t smccc_version(void) |
| 19 |
{ |
| 20 |
return MAKE_SMCCC_VERSION(SMCCC_MAJOR_VERSION, SMCCC_MINOR_VERSION); |
| 21 |
} |
| 22 |
|
| 23 |
static int32_t smccc_arch_features(u_register_t arg1) |
| 24 |
{ |
| 25 |
switch (arg1) { |
| 26 |
case SMCCC_VERSION: |
| 27 |
case SMCCC_ARCH_FEATURES: |
| 28 |
return SMC_ARCH_CALL_SUCCESS; |
| 29 |
case SMCCC_ARCH_SOC_ID: |
| 30 |
return plat_is_smccc_feature_available(arg1); |
| 31 |
#ifdef __aarch64__ |
| 32 |
|
| 33 |
#if WORKAROUND_CVE_2017_5715 |
| 34 |
case SMCCC_ARCH_WORKAROUND_1: |
| 35 |
if (check_wa_cve_2017_5715() == ERRATA_NOT_APPLIES) |
| 36 |
return 1; |
| 37 |
return 0; |
| 38 |
#endif |
| 39 |
|
| 40 |
#if WORKAROUND_CVE_2018_3639 |
| 41 |
case SMCCC_ARCH_WORKAROUND_2: { |
| 42 |
#if DYNAMIC_WORKAROUND_CVE_2018_3639 |
| 43 |
unsigned long long ssbs; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
ssbs = (read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_SSBS_SHIFT) & |
| 51 |
ID_AA64PFR1_EL1_SSBS_MASK; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
if (ssbs != SSBS_NOT_IMPLEMENTED) |
| 58 |
return 1; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
if (wa_cve_2018_3639_get_disable_ptr() == NULL) |
| 67 |
return 1; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
return 0; |
| 73 |
#else |
| 74 |
|
| 75 |
return SMC_ARCH_CALL_NOT_REQUIRED; |
| 76 |
#endif |
| 77 |
} |
| 78 |
#endif |
| 79 |
|
| 80 |
#if (WORKAROUND_CVE_2022_23960 || WORKAROUND_CVE_2017_5715) |
| 81 |
case SMCCC_ARCH_WORKAROUND_3: |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
if ((check_smccc_arch_wa3_applies() == ERRATA_NOT_APPLIES) && |
| 88 |
(check_wa_cve_2017_5715() == ERRATA_NOT_APPLIES)) { |
| 89 |
return 1; |
| 90 |
} |
| 91 |
return 0; |
| 92 |
#endif |
| 93 |
|
| 94 |
#if WORKAROUND_CVE_2024_7881 |
| 95 |
case SMCCC_ARCH_WORKAROUND_4: |
| 96 |
if (check_wa_cve_2024_7881() != ERRATA_APPLIES) { |
| 97 |
return SMC_ARCH_CALL_NOT_SUPPORTED; |
| 98 |
} |
| 99 |
return 0; |
| 100 |
#endif |
| 101 |
|
| 102 |
#endif |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
default: |
| 107 |
return SMC_UNK; |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
static int32_t smccc_arch_id(u_register_t arg1) |
| 114 |
{ |
| 115 |
if (arg1 == SMCCC_GET_SOC_REVISION) { |
| 116 |
return plat_get_soc_revision(); |
| 117 |
} |
| 118 |
if (arg1 == SMCCC_GET_SOC_VERSION) { |
| 119 |
return plat_get_soc_version(); |
| 120 |
} |
| 121 |
return SMC_ARCH_CALL_INVAL_PARAM; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
static uintptr_t arm_arch_svc_smc_handler(uint32_t smc_fid, |
| 128 |
u_register_t x1, |
| 129 |
u_register_t x2, |
| 130 |
u_register_t x3, |
| 131 |
u_register_t x4, |
| 132 |
void *cookie, |
| 133 |
void *handle, |
| 134 |
u_register_t flags) |
| 135 |
{ |
| 136 |
switch (smc_fid) { |
| 137 |
case SMCCC_VERSION: |
| 138 |
SMC_RET1(handle, smccc_version()); |
| 139 |
case SMCCC_ARCH_FEATURES: |
| 140 |
SMC_RET1(handle, smccc_arch_features(x1)); |
| 141 |
case SMCCC_ARCH_SOC_ID: |
| 142 |
SMC_RET1(handle, smccc_arch_id(x1)); |
| 143 |
#ifdef __aarch64__ |
| 144 |
#if WORKAROUND_CVE_2017_5715 |
| 145 |
case SMCCC_ARCH_WORKAROUND_1: |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
SMC_RET0(handle); |
| 152 |
#endif |
| 153 |
#if WORKAROUND_CVE_2018_3639 |
| 154 |
case SMCCC_ARCH_WORKAROUND_2: |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
SMC_RET0(handle); |
| 162 |
#endif |
| 163 |
#if (WORKAROUND_CVE_2022_23960 || WORKAROUND_CVE_2017_5715) |
| 164 |
case SMCCC_ARCH_WORKAROUND_3: |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
SMC_RET0(handle); |
| 171 |
#endif |
| 172 |
#if WORKAROUND_CVE_2024_7881 |
| 173 |
case SMCCC_ARCH_WORKAROUND_4: |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
SMC_RET0(handle); |
| 180 |
#endif |
| 181 |
#endif |
| 182 |
default: |
| 183 |
WARN("Unimplemented Arm Architecture Service Call: 0x%x \n", |
| 184 |
smc_fid); |
| 185 |
SMC_RET1(handle, SMC_UNK); |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
DECLARE_RT_SVC( |
| 191 |
arm_arch_svc, |
| 192 |
OEN_ARM_START, |
| 193 |
OEN_ARM_END, |
| 194 |
SMC_TYPE_FAST, |
| 195 |
NULL, |
| 196 |
arm_arch_svc_smc_handler |
| 197 |
); |