Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 1 | /* |
| 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 Papastamos | 914757c | 2018-03-12 14:47:09 +0000 | [diff] [blame] | 9 | #include <errata_report.h> |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 10 | #include <runtime_svc.h> |
Antonio Nino Diaz | 3c817f4 | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 11 | #include <smccc.h> |
| 12 | #include <smccc_helpers.h> |
Dimitris Papastamos | 570c06a | 2018-04-06 15:29:34 +0100 | [diff] [blame] | 13 | #include <wa_cve_2017_5715.h> |
Dimitris Papastamos | ba51d9e | 2018-05-16 11:36:14 +0100 | [diff] [blame] | 14 | #include <wa_cve_2018_3639.h> |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 15 | |
| 16 | static int32_t smccc_version(void) |
| 17 | { |
| 18 | return MAKE_SMCCC_VERSION(SMCCC_MAJOR_VERSION, SMCCC_MINOR_VERSION); |
| 19 | } |
| 20 | |
| 21 | static int32_t smccc_arch_features(u_register_t arg) |
| 22 | { |
| 23 | switch (arg) { |
| 24 | case SMCCC_VERSION: |
| 25 | case SMCCC_ARCH_FEATURES: |
| 26 | return SMC_OK; |
Dimitris Papastamos | 6d1f499 | 2018-03-28 12:06:40 +0100 | [diff] [blame] | 27 | #if WORKAROUND_CVE_2017_5715 |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 28 | case SMCCC_ARCH_WORKAROUND_1: |
Dimitris Papastamos | 570c06a | 2018-04-06 15:29:34 +0100 | [diff] [blame] | 29 | if (check_wa_cve_2017_5715() == ERRATA_NOT_APPLIES) |
Dimitris Papastamos | 914757c | 2018-03-12 14:47:09 +0000 | [diff] [blame] | 30 | return 1; |
Dimitris Papastamos | 6d1f499 | 2018-03-28 12:06:40 +0100 | [diff] [blame] | 31 | return 0; /* ERRATA_APPLIES || ERRATA_MISSING */ |
| 32 | #endif |
Dimitris Papastamos | e6625ec | 2018-04-05 14:38:26 +0100 | [diff] [blame] | 33 | #if WORKAROUND_CVE_2018_3639 |
| 34 | case SMCCC_ARCH_WORKAROUND_2: |
Dimitris Papastamos | ba51d9e | 2018-05-16 11:36:14 +0100 | [diff] [blame] | 35 | #if DYNAMIC_WORKAROUND_CVE_2018_3639 |
| 36 | /* |
| 37 | * On a platform where at least one CPU requires |
| 38 | * dynamic mitigation but others are either unaffected |
| 39 | * or permanently mitigated, report the latter as not |
| 40 | * needing dynamic mitigation. |
| 41 | */ |
| 42 | if (wa_cve_2018_3639_get_disable_ptr() == NULL) |
| 43 | return 1; |
| 44 | /* |
| 45 | * If we get here, this CPU requires dynamic mitigation |
| 46 | * so report it as such. |
| 47 | */ |
| 48 | return 0; |
| 49 | #else |
| 50 | /* Either the CPUs are unaffected or permanently mitigated */ |
Dimitris Papastamos | e6625ec | 2018-04-05 14:38:26 +0100 | [diff] [blame] | 51 | return SMCCC_ARCH_NOT_REQUIRED; |
| 52 | #endif |
Dimitris Papastamos | ba51d9e | 2018-05-16 11:36:14 +0100 | [diff] [blame] | 53 | #endif |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 54 | default: |
| 55 | return SMC_UNK; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | /* |
| 60 | * Top-level Arm Architectural Service SMC handler. |
| 61 | */ |
Roberto Vargas | 0571270 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 62 | static uintptr_t arm_arch_svc_smc_handler(uint32_t smc_fid, |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 63 | u_register_t x1, |
| 64 | u_register_t x2, |
| 65 | u_register_t x3, |
| 66 | u_register_t x4, |
| 67 | void *cookie, |
| 68 | void *handle, |
| 69 | u_register_t flags) |
| 70 | { |
| 71 | switch (smc_fid) { |
| 72 | case SMCCC_VERSION: |
| 73 | SMC_RET1(handle, smccc_version()); |
| 74 | case SMCCC_ARCH_FEATURES: |
| 75 | SMC_RET1(handle, smccc_arch_features(x1)); |
| 76 | #if WORKAROUND_CVE_2017_5715 |
| 77 | case SMCCC_ARCH_WORKAROUND_1: |
| 78 | /* |
| 79 | * The workaround has already been applied on affected PEs |
| 80 | * during entry to EL3. On unaffected PEs, this function |
| 81 | * has no effect. |
| 82 | */ |
| 83 | SMC_RET0(handle); |
| 84 | #endif |
Dimitris Papastamos | e6625ec | 2018-04-05 14:38:26 +0100 | [diff] [blame] | 85 | #if WORKAROUND_CVE_2018_3639 |
| 86 | case SMCCC_ARCH_WORKAROUND_2: |
| 87 | /* |
| 88 | * The workaround has already been applied on affected PEs |
| 89 | * requiring dynamic mitigation during entry to EL3. |
| 90 | * On unaffected or statically mitigated PEs, this function |
| 91 | * has no effect. |
| 92 | */ |
| 93 | SMC_RET0(handle); |
| 94 | #endif |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 95 | default: |
| 96 | WARN("Unimplemented Arm Architecture Service Call: 0x%x \n", |
| 97 | smc_fid); |
| 98 | SMC_RET1(handle, SMC_UNK); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | /* Register Standard Service Calls as runtime service */ |
| 103 | DECLARE_RT_SVC( |
| 104 | arm_arch_svc, |
| 105 | OEN_ARM_START, |
| 106 | OEN_ARM_END, |
| 107 | SMC_TYPE_FAST, |
| 108 | NULL, |
| 109 | arm_arch_svc_smc_handler |
| 110 | ); |