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 | 914757c | 2018-03-12 14:47:09 +0000 | [diff] [blame] | 13 | #include <workaround_cve_2017_5715.h> |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 14 | |
| 15 | static int32_t smccc_version(void) |
| 16 | { |
| 17 | return MAKE_SMCCC_VERSION(SMCCC_MAJOR_VERSION, SMCCC_MINOR_VERSION); |
| 18 | } |
| 19 | |
| 20 | static 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 Papastamos | 6d1f499 | 2018-03-28 12:06:40 +0100 | [diff] [blame] | 26 | #if WORKAROUND_CVE_2017_5715 |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 27 | case SMCCC_ARCH_WORKAROUND_1: |
Dimitris Papastamos | 6d1f499 | 2018-03-28 12:06:40 +0100 | [diff] [blame] | 28 | if (check_workaround_cve_2017_5715() == ERRATA_NOT_APPLIES) |
Dimitris Papastamos | 914757c | 2018-03-12 14:47:09 +0000 | [diff] [blame] | 29 | return 1; |
Dimitris Papastamos | 6d1f499 | 2018-03-28 12:06:40 +0100 | [diff] [blame] | 30 | return 0; /* ERRATA_APPLIES || ERRATA_MISSING */ |
| 31 | #endif |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 32 | default: |
| 33 | return SMC_UNK; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | /* |
| 38 | * Top-level Arm Architectural Service SMC handler. |
| 39 | */ |
Roberto Vargas | 0571270 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 40 | static uintptr_t arm_arch_svc_smc_handler(uint32_t smc_fid, |
Dimitris Papastamos | 0dcdb1a | 2018-01-19 16:58:29 +0000 | [diff] [blame] | 41 | u_register_t x1, |
| 42 | u_register_t x2, |
| 43 | u_register_t x3, |
| 44 | u_register_t x4, |
| 45 | void *cookie, |
| 46 | void *handle, |
| 47 | u_register_t flags) |
| 48 | { |
| 49 | switch (smc_fid) { |
| 50 | case SMCCC_VERSION: |
| 51 | SMC_RET1(handle, smccc_version()); |
| 52 | case SMCCC_ARCH_FEATURES: |
| 53 | SMC_RET1(handle, smccc_arch_features(x1)); |
| 54 | #if WORKAROUND_CVE_2017_5715 |
| 55 | case SMCCC_ARCH_WORKAROUND_1: |
| 56 | /* |
| 57 | * The workaround has already been applied on affected PEs |
| 58 | * during entry to EL3. On unaffected PEs, this function |
| 59 | * has no effect. |
| 60 | */ |
| 61 | SMC_RET0(handle); |
| 62 | #endif |
| 63 | default: |
| 64 | WARN("Unimplemented Arm Architecture Service Call: 0x%x \n", |
| 65 | smc_fid); |
| 66 | SMC_RET1(handle, SMC_UNK); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /* Register Standard Service Calls as runtime service */ |
| 71 | DECLARE_RT_SVC( |
| 72 | arm_arch_svc, |
| 73 | OEN_ARM_START, |
| 74 | OEN_ARM_END, |
| 75 | SMC_TYPE_FAST, |
| 76 | NULL, |
| 77 | arm_arch_svc_smc_handler |
| 78 | ); |