From patchwork Wed Jun 1 08:27:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 577783 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:8f0c:0:0:0:0 with SMTP id mq12csp358517mab; Wed, 1 Jun 2022 01:28:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+axpjHmubmYBUf8oWEpTPP5/HqehTYp+Nz1q9B8kbdRccSo4NWb3uDujjn/AaqqaTWodv X-Received: by 2002:a92:d143:0:b0:2d3:8250:343d with SMTP id t3-20020a92d143000000b002d38250343dmr12534678ilg.249.1654072086722; Wed, 01 Jun 2022 01:28:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654072086; cv=none; d=google.com; s=arc-20160816; b=CYGubGZSdcx0aI9bjCixu6m2WJs6iMDSrweproJxKlfD8OkYxNbdllMojY2xsNxtCf zzDjitqcRi99Jn1V6wE6BwWLWr+hnlbK9L+f2uWFoMgK6e/aQtJ419mXLOe943M+TIaj GtTc3wHIEUSQFA45N/J1Esakl+IBVx0fLywi3awKMUb+hnS//P+L4x1MK+G0DojzRdH8 GBPFfmXAgdnb41Or45PM0gi+/9FBUO0HT2Kc61qlNJFSFCK8pvDyMiqJXjNhQLSOHB/b RnqG/PRfn4meTL9jyDH48jo4FPmMtwOt7u8+gJPhnVR3KS+3jMAPmAMsrCtVewW94x7J ctaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dc0PB113VvuojqFAr6i5Jpj8dScoyfXOnqOFH73bCus=; b=OPU/hOXckGhRDDwdy6VTuuY/orYTi+Fhhk7L92kSP8zAKEhnb/4E0Zb4j6BOB/MHqU fbF7vKK35+br6XrhCKFB15eaSgwHEoNuq2a5lOvfAt2Wc2IjVlC3r1QkuoNH6esmmVD5 z78h+C+y/+u6fbQAsZYtIMBQR9gRZQnvp9qipUGGef4eSe2tUOohxvvMmBe4PNzfp/bm ChITHIcvPXZdFtXdwt6EdBzALm/hInm4xcG9LwYFV1V5XZWgnoPRXxqWDzuja6I70Fm0 4QhZwK4yLygs7Ab0nW7Kg/yBIGyjkm6lfuX3fDsrmh1Mt56Nuw5SZ+4fQvcRxXiSiGof 1w+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BQXDCRaQ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id r2-20020a5d9b82000000b00665789c8ad0si888398iom.55.2022.06.01.01.28.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 01:28:06 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BQXDCRaQ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C0D598424E; Wed, 1 Jun 2022 10:27:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="BQXDCRaQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 92956805FE; Wed, 1 Jun 2022 10:27:46 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E065E83EF9 for ; Wed, 1 Jun 2022 10:27:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=etienne.carriere@linaro.org Received: by mail-wr1-x42d.google.com with SMTP id e2so1280491wrc.1 for ; Wed, 01 Jun 2022 01:27:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dc0PB113VvuojqFAr6i5Jpj8dScoyfXOnqOFH73bCus=; b=BQXDCRaQ2AqKPOL7RqtrMbR8aK/X74ySXLCOXYXatIAO5X86l5Adyc66bI9wsCBE2Z CDK72KLLMETZPYcwyYThvVYoxphuUaB7Ert9XcAWoyJpz6TL6L6SsoaTfpPQZcFULld1 5D/L10eaMS/UCuQL7E8T4infAKo83tTtqYrXQqEwdV95PCtEd5vzQkt9WDNDHOhi3RNq MxZFfNnkPg8zO/FYAmibI8QAqNQeerAzXamy6k7YN2sFLByQ7DgaLawTX9+favLiCkYw bkNcf4Zno/uWf9H9ONnZag4OhUdOwZenqtHZnSwexv1vIZSA8lZc6mzNLFVeYAWB+va9 PKug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dc0PB113VvuojqFAr6i5Jpj8dScoyfXOnqOFH73bCus=; b=IsOZedR94L+4zIJjY3Mqr8kkyBUoLNp2zNps4j1IamVlTHcSCM1RawE3dulUHohy+J ngnqzVmAPdSbd+RPoIC6S+feSYhyAho/mk2qD85pHl4wRsB78/bPnEYRGo8Kw5hqBBju ItjwExOxHAIg337GTFFGsc8LajrYFrgYAVFWlmDgBJhsTnQAq3RtnMLXNtRtOaKGm1Lx NJ4RJ87IZywLwqiABKmukix2ZloiJUhnIjDRH1pQFibZicsIRzXnGDD6ySfNNPWADMov SNojlnJOkhwGd7DvsO07Dn+MRIPEahjYB5PmWj5Myu3SIhGu+yM0ETXMFLlK7/TNLny8 hD2w== X-Gm-Message-State: AOAM532lhZFTMq6M2MnuXxR+Z9qO6dKiy4MfN2zIXbe9DnxL8/FWFB5Q Hb5IKAy5AhLdc1Ft5HDrUZBh4Oe2MmMFww== X-Received: by 2002:a05:6000:18a8:b0:20e:654f:a004 with SMTP id b8-20020a05600018a800b0020e654fa004mr52255010wri.672.1654072060059; Wed, 01 Jun 2022 01:27:40 -0700 (PDT) Received: from lmecxl1178.lme.st.com ([2a04:cec0:117a:a94e:2216:1d3f:505:2dfb]) by smtp.gmail.com with ESMTPSA id i6-20020a05600c290600b00397470a8226sm1166140wmd.15.2022.06.01.01.27.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 01:27:39 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Etienne Carriere Subject: [PATCH 3/4] firmware: psci: bind arm smccc features when discovered Date: Wed, 1 Jun 2022 10:27:33 +0200 Message-Id: <20220601082734.301474-3-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220601082734.301474-1-etienne.carriere@linaro.org> References: <20220601082734.301474-1-etienne.carriere@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Use PSCI device to query Arm SMCCC v1.1 support from secure monitor and if so, bind drivers for the SMCCC features that monitor supports. Drivers willing to be bound from Arm SMCCC features discovery can use macro ARM_SMCCC_FEATURE_DRIVER() to register to smccc feature discovery, providing target driver name and a callback function that returns whether or not the SMCCC feature is supported by the system. Signed-off-by: Etienne Carriere --- drivers/firmware/Kconfig | 8 ++++ drivers/firmware/psci.c | 81 ++++++++++++++++++++++++++++++++++++++- include/linux/arm-smccc.h | 16 ++++++++ include/linux/psci.h | 14 +++++++ 4 files changed, 118 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index ef958b3a7a..f10d1aaf4b 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -37,4 +37,12 @@ config ZYNQMP_FIRMWARE Say yes to enable ZynqMP firmware interface driver. If in doubt, say N. +config ARM_SMCCC_FEATURES + bool "Arm SMCCC features discovery" + depends on ARM_PSCI_FW + help + Discover Arm SMCCC features for which a U-Boot driver is defined. When enabled, + the PSCI driver is always probed and binds dirvers registered to the Arm SMCCC + services if any and reported as supported by the SMCCC firmware. + source "drivers/firmware/scmi/Kconfig" diff --git a/drivers/firmware/psci.c b/drivers/firmware/psci.c index f845ba67f8..ef3e983646 100644 --- a/drivers/firmware/psci.c +++ b/drivers/firmware/psci.c @@ -11,9 +11,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -95,6 +97,76 @@ static bool psci_is_system_reset2_supported(void) return false; } +static void smccc_invoke_hvc(unsigned long a0, unsigned long a1, + unsigned long a2, unsigned long a3, + unsigned long a4, unsigned long a5, + unsigned long a6, unsigned long a7, + struct arm_smccc_res *res) +{ + arm_smccc_hvc(a0, a1, a2, a3, a4, a5, a6, a7, res); +} + +static void smccc_invoke_smc(unsigned long a0, unsigned long a1, + unsigned long a2, unsigned long a3, + unsigned long a4, unsigned long a5, + unsigned long a6, unsigned long a7, + struct arm_smccc_res *res) +{ + arm_smccc_smc(a0, a1, a2, a3, a4, a5, a6, a7, res); +} + +static int bind_smccc_features(struct udevice *dev, int psci_method) +{ + struct psci_plat_data *pdata = dev_get_plat(dev); + struct arm_smccc_feature *feature; + size_t feature_cnt, n; + + if (!IS_ENABLED(CONFIG_ARM_SMCCC_FEATURES)) + return 0; + + /* + * SMCCC features discovery invoke SMCCC standard function ID + * ARM_SMCCC_ARCH_FEATURES but this sequence requires that this + * standard ARM_SMCCC_ARCH_FEATURES function ID itself is supported. + * It is queried here with invoking PSCI_FEATURES known available + * from PSCI 1.0. + */ + if (!device_is_compatible(dev, "arm,psci-1.0") || + PSCI_VERSION_MAJOR(psci_0_2_get_version()) == 0) + return 0; + + if (request_psci_features(ARM_SMCCC_ARCH_FEATURES) == + PSCI_RET_NOT_SUPPORTED) + return 0; + + if (psci_method == PSCI_METHOD_HVC) + pdata->invoke_fn = smccc_invoke_hvc; + else + pdata->invoke_fn = smccc_invoke_smc; + + feature_cnt = ll_entry_count(struct arm_smccc_feature, arm_smccc_feature); + feature = ll_entry_start(struct arm_smccc_feature, arm_smccc_feature); + + for (n = 0; n < feature_cnt; n++, feature++) { + const char *drv_name = feature->driver_name; + struct udevice *dev2; + int ret; + + if (!feature->is_supported || !feature->is_supported(pdata->invoke_fn)) + continue; + + ret = device_bind_driver(dev, drv_name, drv_name, &dev2); + if (ret) { + pr_warn("%s was not bound: %d, ignore\n", drv_name, ret); + continue; + } + + dev_set_parent_plat(dev2, dev_get_plat(dev)); + } + + return 0; +} + static int psci_bind(struct udevice *dev) { /* No SYSTEM_RESET support for PSCI 0.1 */ @@ -109,6 +181,10 @@ static int psci_bind(struct udevice *dev) pr_debug("PSCI System Reset was not bound.\n"); } + /* From PSCI v1.0 onward we can discover services through ARM_SMCCC_FEATURE */ + if (IS_ENABLED(CONFIG_ARM_SMCCC_FEATURES) && device_is_compatible(dev, "arm,psci-1.0")) + dev_or_flags(dev, DM_FLAG_PROBE_AFTER_BIND); + return 0; } @@ -136,7 +212,7 @@ static int psci_probe(struct udevice *dev) return -EINVAL; } - return 0; + return bind_smccc_features(dev, psci_method); } /** @@ -240,4 +316,7 @@ U_BOOT_DRIVER(psci) = { .of_match = psci_of_match, .bind = psci_bind, .probe = psci_probe, +#ifdef CONFIG_ARM_SMCCC_FEATURES + .plat_auto = sizeof(struct psci_plat_data), +#endif }; diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h index 94a20c9793..e1d09884a1 100644 --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -83,6 +83,22 @@ struct arm_smccc_quirk { } state; }; +/** + * struct arm_smccc_feature - Driver registration data for discoverable feature + * @driver_name: name of the driver relate to the SMCCC feature + * @is_supported: callback to test if SMCCC feature is supported + */ +struct arm_smccc_feature { + const char *driver_name; + bool (*is_supported)(void (*invoke_fn)(unsigned long a0, unsigned long a1, unsigned long a2, + unsigned long a3, unsigned long a4, unsigned long a5, + unsigned long a6, unsigned long a7, + struct arm_smccc_res *res)); +}; + +#define ARM_SMCCC_FEATURE_DRIVER(__name) \ + ll_entry_declare(struct arm_smccc_feature, __name, arm_smccc_feature) + /** * __arm_smccc_smc() - make SMC calls * @a0-a7: arguments passed in registers 0 to 7 diff --git a/include/linux/psci.h b/include/linux/psci.h index c78c1079a8..03e4186343 100644 --- a/include/linux/psci.h +++ b/include/linux/psci.h @@ -11,6 +11,8 @@ #ifndef _UAPI_LINUX_PSCI_H #define _UAPI_LINUX_PSCI_H +#include + /* * PSCI v0.1 interface * @@ -115,6 +117,18 @@ #define PSCI_RET_DISABLED -8 #define PSCI_RET_INVALID_ADDRESS -9 +/** + * struct psci_plat_data - PSCI driver platform data + * @method: Selected invocation conduit + */ +struct psci_plat_data { + void (*invoke_fn)(unsigned long arg0, unsigned long arg1, + unsigned long arg2, unsigned long arg3, + unsigned long arg4, unsigned long arg5, + unsigned long arg6, unsigned long arg7, + struct arm_smccc_res *res); +}; + #ifdef CONFIG_ARM_PSCI_FW unsigned long invoke_psci_fn(unsigned long a0, unsigned long a1, unsigned long a2, unsigned long a3);