From fb4391c8ece2accc11e179de77e8e0da1546035d Mon Sep 17 00:00:00 2001 From: kettenis Date: Sun, 10 Oct 2021 16:20:37 +0000 Subject: [PATCH] Apparently it is possible for firmware to indicate that SMCCC_VERSION is implemented but have that call return NOT_SUPPORTED. Makes no sense, but the SMCCC standard documents this and tells us to treat this as v1.0. Change the code accordingly. Turn a few checks that should always be true into KASSERTs to keep the control flow simple. ok patrick@ --- sys/dev/fdt/psci.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/sys/dev/fdt/psci.c b/sys/dev/fdt/psci.c index f0e37c50880..26c328f47eb 100644 --- a/sys/dev/fdt/psci.c +++ b/sys/dev/fdt/psci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: psci.c,v 1.8 2018/05/23 09:12:34 kettenis Exp $ */ +/* $OpenBSD: psci.c,v 1.9 2021/10/10 16:20:37 kettenis Exp $ */ /* * Copyright (c) 2016 Jonathan Gray @@ -208,11 +208,15 @@ int32_t smccc_version(void) { struct psci_softc *sc = psci_sc; + int32_t version; - if (sc && sc->sc_callfn) - return (*sc->sc_callfn)(SMCCC_VERSION, 0, 0, 0); + KASSERT(sc && sc->sc_callfn); + version = (*sc->sc_callfn)(SMCCC_VERSION, 0, 0, 0); + if (version != PSCI_NOT_SUPPORTED) + return version; - return PSCI_NOT_SUPPORTED; + /* Treat NOT_SUPPORTED as 1.0 */ + return 0x10000; } int32_t @@ -220,10 +224,8 @@ smccc_arch_features(uint32_t arch_func_id) { struct psci_softc *sc = psci_sc; - if (sc && sc->sc_callfn) - return (*sc->sc_callfn)(SMCCC_ARCH_FEATURES, arch_func_id, 0, 0); - - return PSCI_NOT_SUPPORTED; + KASSERT(sc && sc->sc_callfn); + return (*sc->sc_callfn)(SMCCC_ARCH_FEATURES, arch_func_id, 0, 0); } uint32_t -- 2.20.1