git: 0c333f8c6e6a - main - psci: Support the arm64 Errata ABI
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 24 Jan 2025 12:11:55 UTC
The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=0c333f8c6e6abee331b12a7dbadfe077dbaf79c8 commit 0c333f8c6e6abee331b12a7dbadfe077dbaf79c8 Author: Andrew Turner <andrew@FreeBSD.org> AuthorDate: 2025-01-24 11:42:59 +0000 Commit: Andrew Turner <andrew@FreeBSD.org> CommitDate: 2025-01-24 12:09:28 +0000 psci: Support the arm64 Errata ABI Add support for the Arm Errata Management Firmware Interface (Errata ABI) [1]. This provides an interface for the kernel to query the status of an erratum workaround. Some errata may be mitigated depending on the other hardware in a SoC, e.g. Cortex-A78 erratum 2712571 is not affected in systems that use an Arm interconnect. As there may not be a way for the kernel to know if this is the case then it would have to implement the workaround even when not needed. There are other cases where the needed workaround is implemented in firmware and if not implemented then the kernel may decide to not use a feature. In this case we can query the firmware before deciding if we should use a feature or now. There is a known issue with some firmware implementations of the Errata ABI that incorrectly returns a status indicating the erratum is fully mitigated by the firmware, however there is a kernel component needed, e.g. Neoverse-N1 erratum 1542419. To handle this case we tell the caller there is some workaround implemented in the firmware and it can decide how to handle it. If this is fixed in a way we can detect we can add a new erratum status value to indicate this. [1] https://developer.arm.com/documentation/den0100/latest/ Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D48055 --- sys/conf/files.arm64 | 1 + sys/dev/psci/smccc_errata.c | 138 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) diff --git a/sys/conf/files.arm64 b/sys/conf/files.arm64 index c095bae42996..64c8acfcdb9a 100644 --- a/sys/conf/files.arm64 +++ b/sys/conf/files.arm64 @@ -421,6 +421,7 @@ dev/pci/pci_dw_if.m optional pci fdt dev/psci/psci.c standard dev/psci/smccc_arm64.S standard +dev/psci/smccc_errata.c standard dev/psci/smccc_trng.c standard dev/psci/smccc.c standard diff --git a/sys/dev/psci/smccc_errata.c b/sys/dev/psci/smccc_errata.c new file mode 100644 index 000000000000..db6b0a588a86 --- /dev/null +++ b/sys/dev/psci/smccc_errata.c @@ -0,0 +1,138 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Arm Ltd + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * A driver for the Arm Errata Management Firmware Interface (Errata ABI). + * This queries into the SMCCC firmware for the status of errata using the + * interface documented in den0100 [1]. + * + * [1] https://developer.arm.com/documentation/den0100/latest + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/bus.h> +#include <sys/eventhandler.h> +#include <sys/kernel.h> +#include <sys/malloc.h> +#include <sys/module.h> +#include <sys/random.h> + +#include <dev/psci/psci.h> +#include <dev/psci/smccc.h> + +#include <machine/cpu_feat.h> + +#define ERRATA_HIGHER_EL_MITIGATION 3 +#define ERRATA_NOT_AFFECTED 2 +#define ERRATA_AFFECTED 1 + +#define EM_VERSION SMCCC_FUNC_ID(SMCCC_FAST_CALL, \ + SMCCC_32BIT_CALL, SMCCC_STD_SECURE_SERVICE_CALLS, 0xf0u) +#define EM_VERSION_MIN 0x10000L +#define EM_FEATURES SMCCC_FUNC_ID(SMCCC_FAST_CALL, \ + SMCCC_32BIT_CALL, SMCCC_STD_SECURE_SERVICE_CALLS, 0xf1u) +#define EM_CPU_ERRATUM_FEATURES SMCCC_FUNC_ID(SMCCC_FAST_CALL, \ + SMCCC_32BIT_CALL, SMCCC_STD_SECURE_SERVICE_CALLS, 0xf2u) + +static device_identify_t errata_identify; +static device_probe_t errata_probe; +static device_attach_t errata_attach; +static cpu_feat_errata errata_cpu_feat_errata_check(const struct cpu_feat *, + u_int); + +static void +errata_identify(driver_t *driver, device_t parent) +{ + int32_t version; + + if (smccc_get_version() < SMCCC_MAKE_VERSION(1, 1)) + return; + + /* Check we have Errata 1.0 or later */ + version = psci_call(EM_VERSION, 0, 0, 0); + if (version < EM_VERSION_MIN) + return; + + if (BUS_ADD_CHILD(parent, 0, "errata", -1) == NULL) + device_printf(parent, "add errata child failed\n"); +} + +static int +errata_probe(device_t dev) +{ + device_set_desc(dev, "Arm SMCCC Errata Management"); + return (BUS_PROBE_NOWILDCARD); +} + +static int +errata_attach(device_t dev) +{ + /* Check for EM_CPU_ERRATUM_FEATURES. It's mandatory, so should exist */ + if (arm_smccc_invoke(EM_FEATURES, EM_CPU_ERRATUM_FEATURES, NULL) < 0) { + device_printf(dev, + "EM_CPU_ERRATUM_FEATURES is not implemented\n"); + return (ENXIO); + } + + cpu_feat_register_errata_check(errata_cpu_feat_errata_check); + + return (0); +} + +static cpu_feat_errata +errata_cpu_feat_errata_check(const struct cpu_feat *feat __unused, u_int errata_id) +{ + struct arm_smccc_res res; + + switch(arm_smccc_invoke(EM_CPU_ERRATUM_FEATURES, errata_id, 0, &res)) { + default: + return (ERRATA_UNKNOWN); + case ERRATA_NOT_AFFECTED: + return (ERRATA_NONE); + case ERRATA_AFFECTED: + return (ERRATA_AFFECTED); + case ERRATA_HIGHER_EL_MITIGATION: + return (ERRATA_FW_MITIGAION); + } +} + +static device_method_t errata_methods[] = { + DEVMETHOD(device_identify, errata_identify), + DEVMETHOD(device_probe, errata_probe), + DEVMETHOD(device_attach, errata_attach), + + DEVMETHOD_END +}; + +static driver_t errata_driver = { + "errata", + errata_methods, + 0 +}; + +DRIVER_MODULE(errata, smccc, errata_driver, 0, 0);