From patchwork Sun Apr 19 15:05:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 11497551 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 09E386CA for ; Sun, 19 Apr 2020 15:05:55 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CD9E721973 for ; Sun, 19 Apr 2020 15:05:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="L3vh/Y/x"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="lw3YZBs2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CD9E721973 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=dTMKdNd5m4KnDe9lAg100GL9nElirM92Qe2zinjfCPw=; b=L3vh/Y/xyFvk3tRDmp1XgSgYgf 0s+O6jV+MTMrAMu9ZtrGRUQg5zt6JX3MGHFm6rK9d8UKvimG7sQV2oJ8R8QTtdR4C9O/TS0t0w3WL dk/C6jfHUnU2omvcb6BHAqzhldr1z7K2JM4GSSbjfscO8MzxwfKnZjHkmWH45N1Cq9h9jImPJ5LmL AUNUUGYSb6oyU5JPPnG+JdKPXJfzjr6j91AgFPse/my2rQ4nEM5TFqUHwsXaTaXzhrvJe2I5DJBdA 30AkbG5VoJQiHGeoHxeOuhX0/SawQEAMCMaMfJKdko4KyDAT9w6cc1wV9tdbtWMJ8LylrbgSivhxE KHRxY/Kw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQBW0-0007ok-TK; Sun, 19 Apr 2020 15:05:48 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQBVp-0007ec-IE for linux-arm-kernel@lists.infradead.org; Sun, 19 Apr 2020 15:05:39 +0000 Received: by mail-wr1-x443.google.com with SMTP id g13so6816583wrb.8 for ; Sun, 19 Apr 2020 08:05:37 -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; bh=tJyu1goMDawsMnyU0ATkWtgXzvVpCCNTMOr5sgRr7ks=; b=lw3YZBs2+CzmIxZI4c3R3pem5y/CkiFmzRnZyNY7Bnf7YgR7rv3/tEW4U3QCw1cJuR JAjxjhIrSd8BHtGQgYGVXEaVIbTEoh7lNMbD58r+pHlObobJUZav5O+Cc3o+oU8uOkZ9 yCTEEIslPZ7vsAwTxVuFMRbUHWG97mC0EGITQ1XgSy6q7nBXtrCeRTXgSSO/JXmk0soZ sLZiVluJA6lsFDi0v2Vd05a16Rt68tWfwT+RvNzxYItfV07ZvnAYk+r/nmOFIQSGWylk MzjN+ra5yIZUYPtsdejrSqk2POYyQZKivf0qnn13HKiB6zvPW2ZcN7iMvJYdysovuunm LFPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tJyu1goMDawsMnyU0ATkWtgXzvVpCCNTMOr5sgRr7ks=; b=KVc9ZJwRZ02oo9gg773zCqNwrqDIz0o7acOZmKIh3E4sKZMLtJHJrmZfxc+jbRAEBC mL9WwbOY2utS7AwvDOoggimAh96vDvZcwIaqAyOD0vubBCB6Ar+M3Ad0ugsitGy17fyb AiaFoSpEIEN7kePLBPBXJN/2dMeKQ//gMYO1WU0ERC1RGvDKBvzGJrHkkO8Eohaxsikv luLofnYwxaUjWjNewQ2Qaxqr8bScDygH66qYbIrC+zYBZDhxFoOnWlbn/zb15seyZOhS qMTt3BLmMuseVdtj96ZP9kpitsSeskJYqobGljI9/2YO3D7xmLTXxqBKzOzBc3ze0uUW PO6A== X-Gm-Message-State: AGi0PuaQiJxpY0l0uhNU/t7yyzu0bxGw6xHUxtNypZw3OoUplXkCH+VB XM4oS3HK38rAcPcUEEQPAhpFeQ== X-Google-Smtp-Source: APiQypJBj7hPW2geuzSFyXnoAMnke+GfIXWdXk6/g0HHLzsza5OPiJnU8GrVfqyYrFIcoUaY+qYCbg== X-Received: by 2002:a5d:6946:: with SMTP id r6mr6894861wrw.291.1587308736034; Sun, 19 Apr 2020 08:05:36 -0700 (PDT) Received: from lmecxl0524.home (2a01cb058702ff00947c0d9b78b8fa1e.ipv6.abo.wanadoo.fr. [2a01:cb05:8702:ff00:947c:d9b:78b8:fa1e]) by smtp.gmail.com with ESMTPSA id w12sm25948635wrk.56.2020.04.19.08.05.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Apr 2020 08:05:35 -0700 (PDT) From: Etienne Carriere To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/6] firmware: helper functions for SMCCC v1.0 invocation conduit Date: Sun, 19 Apr 2020 17:05:25 +0200 Message-Id: <20200419150530.20508-2-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200419150530.20508-1-etienne.carriere@linaro.org> References: <20200419150530.20508-1-etienne.carriere@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200419_080537_599053_5B899FBC X-CRM114-Status: GOOD ( 19.54 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:443 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, lorenzo.pieralisi@arm.com, michal.simek@xilinx.com, tee-dev@lists.linaro.org, Etienne Carriere , james.morse@arm.com, sudeep.holla@arm.com, richard.gong@linux.intel.com, jens.wiklander@linaro.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Introduce invocation helper functions for driver that interact with firmware supporting Arm SMCCC v1.0 specification based on existing arm_smccc_1_1_*() helpers. The new functions suit device where secure world supports SMCCC v1.0 but not v1.1. This change allows devices to ensure consistency of the conduit used among drivers defining a conduit method as at runtime all devices are expected to use the very same SMCCC invocation conduit. Signed-off-by: Etienne Carriere --- drivers/firmware/Makefile | 1 + drivers/firmware/arm_smccc_conduit.c | 147 +++++++++++++++++++++++++++ include/linux/arm-smccc.h | 106 +++++++++++++++++++ 3 files changed, 254 insertions(+) create mode 100644 drivers/firmware/arm_smccc_conduit.c diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile index e9fb838af4df..5a4a72a06346 100644 --- a/drivers/firmware/Makefile +++ b/drivers/firmware/Makefile @@ -5,6 +5,7 @@ obj-$(CONFIG_ARM_SCPI_PROTOCOL) += arm_scpi.o obj-$(CONFIG_ARM_SCPI_POWER_DOMAIN) += scpi_pm_domain.o obj-$(CONFIG_ARM_SDE_INTERFACE) += arm_sdei.o +obj-$(CONFIG_HAVE_ARM_SMCCC) += arm_smccc_conduit.o obj-$(CONFIG_DMI) += dmi_scan.o obj-$(CONFIG_DMI_SYSFS) += dmi-sysfs.o obj-$(CONFIG_EDD) += edd.o diff --git a/drivers/firmware/arm_smccc_conduit.c b/drivers/firmware/arm_smccc_conduit.c new file mode 100644 index 000000000000..37b90e92a4b3 --- /dev/null +++ b/drivers/firmware/arm_smccc_conduit.c @@ -0,0 +1,147 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2020, Linaro Limited + */ + +#include +#include +#include + +static enum arm_smccc_conduit arm_smccc_1_0_conduit = SMCCC_CONDUIT_NONE; + +/* Helpers for nice trace when called outside a device instance */ +#define PRINT_INFO(dev, ...) \ + do { \ + if (dev) \ + dev_info(dev, __VA_ARGS__); \ + else \ + pr_info(__VA_ARGS__); \ + } while (0) + +#define PRINT_WARN(dev, ...) \ + do { \ + if (dev) \ + dev_warn(dev, __VA_ARGS__); \ + else \ + pr_warn(__VA_ARGS__); \ + } while (0) + +#define PRINT_ERROR(dev, ...) \ + do { \ + if (dev) \ + dev_err(dev, __VA_ARGS__); \ + else \ + pr_err(__VA_ARGS__); \ + } while (0) + +static const char *conduit_str(enum arm_smccc_conduit conduit) +{ + static const char hvc_str[] = "HVC"; + static const char smc_str[] = "SMC"; + static const char unknown[] = "unknown"; + + switch (conduit) { + case SMCCC_CONDUIT_HVC: + return hvc_str; + case SMCCC_CONDUIT_SMC: + return smc_str; + default: + return unknown; + } +} + +static int set_conduit(struct device *dev, enum arm_smccc_conduit conduit) +{ + switch (conduit) { + case SMCCC_CONDUIT_HVC: + case SMCCC_CONDUIT_SMC: + break; + default: + return -EINVAL; + } + + if (arm_smccc_1_0_conduit == SMCCC_CONDUIT_NONE) { + arm_smccc_1_0_conduit = conduit; + return 0; + } + + if (conduit == arm_smccc_1_0_conduit) + return 0; + + PRINT_ERROR(dev, "inconsistent conduits %u (%s) vs %u (%s)\n", + conduit, conduit_str(conduit), + arm_smccc_1_0_conduit, conduit_str(arm_smccc_1_0_conduit)); + + return -EINVAL; +} + +static enum arm_smccc_conduit method_to_conduit(const char *method) +{ + if (!strcmp("hvc", method)) + return SMCCC_CONDUIT_HVC; + else if (!strcmp("smc", method)) + return SMCCC_CONDUIT_SMC; + else + return SMCCC_CONDUIT_NONE; +} + +static int set_conduit_from_node(struct device *dev, struct device_node *np) +{ + const char *method; + + PRINT_INFO(dev, "probing for conduit method from DT.\n"); + + if (!np) + return -EINVAL; + + if (!of_property_read_string(np, "method", &method)) { + enum arm_smccc_conduit dev_conduit = method_to_conduit(method); + + if (dev_conduit == SMCCC_CONDUIT_NONE) { + PRINT_WARN(dev, "invalid \"method\" property \"%s\"\n", + method); + return -EINVAL; + } + + return set_conduit(dev, dev_conduit); + } + + if (arm_smccc_1_0_conduit != SMCCC_CONDUIT_NONE) + return 0; + + PRINT_WARN(dev, "missing \"method\" property\n"); + return -ENXIO; +} + +int devm_arm_smccc_1_0_set_conduit(struct device *dev) +{ + if (!dev || !dev->of_node) + return -EINVAL; + + return set_conduit_from_node(dev, dev->of_node); +} +EXPORT_SYMBOL_GPL(devm_arm_smccc_1_0_set_conduit); + +int of_arm_smccc_1_0_set_conduit(struct device_node *np) +{ + if (!np) + return -EINVAL; + + return set_conduit_from_node(NULL, np); +} +EXPORT_SYMBOL_GPL(of_arm_smccc_1_0_set_conduit); + +int arm_smccc_1_0_set_conduit(enum arm_smccc_conduit conduit) +{ + if (set_conduit(NULL, conduit)) + return -EINVAL; + + return 0; +} +EXPORT_SYMBOL_GPL(arm_smccc_1_0_set_conduit); + +enum arm_smccc_conduit arm_smccc_1_0_get_conduit(void) +{ + return arm_smccc_1_0_conduit; +} +EXPORT_SYMBOL_GPL(arm_smccc_1_0_get_conduit); diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h index 59494df0f55b..4f5f17b00a6b 100644 --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -377,5 +377,111 @@ asmlinkage void __arm_smccc_hvc(unsigned long a0, unsigned long a1, ARM_SMCCC_OWNER_STANDARD_HYP, \ 0x21) +/* SMCCC v1.0 compliant invocation helpers */ + +/* + * Like arm_smccc_1_0* but always returns SMCCC_RET_NOT_SUPPORTED. + * Used when the SMCCC conduit is not defined. The empty asm statement + * avoids compiler warnings about unused variables. + */ +#define __fail_smccc_1_0(...) \ + do { \ + __declare_args(7, __VA_ARGS__); \ + asm ("" __constraints(7)); \ + ___res->a0 = SMCCC_RET_NOT_SUPPORTED; \ + } while (0) + +/* + * arm_smccc_1_0_invoke() - make an SMCCC v1.0 compliant call + * + * This is a macro taking eight source arguments and an return structure. + * It uses the SMCCC conduit registered during driver(s) initialization. + * + * @a0-a7: arguments passed in registers 0 to 7 + * @res: result values from registers 0 to 3 + * + * This macro will make either an HVC call or an SMC call depending on the + * specified SMCCC conduit. If no valid conduit is available then -1 + * (SMCCC_RET_NOT_SUPPORTED) is returned in @res.a0. + * + * The return value provides the conduit that was used. + */ +#define arm_smccc_1_0_invoke(...) ({ \ + enum arm_smccc_conduit conduit = arm_smccc_1_0_get_conduit(); \ + switch (conduit) { \ + case SMCCC_CONDUIT_HVC: \ + arm_smccc_hvc(__VA_ARGS__); \ + break; \ + case SMCCC_CONDUIT_SMC: \ + arm_smccc_smc(__VA_ARGS__); \ + break; \ + default: \ + __fail_smccc_1_0(__VA_ARGS__); \ + conduit = SMCCC_CONDUIT_NONE; \ + } \ + conduit; \ + }) + +struct device; +struct device_node; + +#ifdef CONFIG_HAVE_ARM_SMCCC +/** + * arm_smccc_1_0_get_conduit() - Return registered SMCCC conduit + */ +enum arm_smccc_conduit arm_smccc_1_0_get_conduit(void); + +/** + * arm_smccc_1_0_set_conduit - Register SMCCC invocation conduit + * @conduit: conduit to register + * + * Return 0 on success and -EINVAL on failure. + */ +int arm_smccc_1_0_set_conduit(enum arm_smccc_conduit); + +/** + * devm_arm_smccc_1_0_set_conduit() - Set SMCCC v1.0 conduit if found in device + * @dev: Device instance + * + * Set the SMCCC invocation conduit based on device node if it has a "methhod" + * property that defines the SMCCC conduit to be used. If it has not, check a + * conduit is already registered. + * + * Return 0 on success, -ENXIO if no conduit found, -EINVAL otherwise. + */ +int devm_arm_smccc_1_0_set_conduit(struct device *dev); + +/** + * of_arm_smccc_1_0_set_conduit() - Set SMCCC v1.0 conduit if found in FDT node + * @np: Node instance + * + * Set the SMCCC invocation conduit based on device node if it has a "methhod" + * property that defines the SMCCC conduit to be used. If it has not, check a + * conduit is already registered. + * + * Return 0 on success, -ENXIO if no conduit found, -EINVAL otherwise. + */ +int of_arm_smccc_1_0_set_conduit(struct device_node *np); +#else +static inline enum arm_smccc_conduit arm_smccc_1_0_get_conduit(void) +{ + return SMCCC_CONDUIT_NONE; +} + +static inline int arm_smccc_1_0_set_conduit(enum arm_smccc_conduit); +{ + return -EINVAL; +} + +static inline int devm_arm_smccc_1_0_set_conduit(struct device *dev); +{ + return -EINVAL; +} + +static inline int of_arm_smccc_1_0_set_conduit(struct device_node *np); +{ + return -EINVAL; +} +#endif /* CONFIG_HAVE_ARM_SMCCC */ #endif /*__ASSEMBLY__*/ #endif /*__LINUX_ARM_SMCCC_H*/ From patchwork Sun Apr 19 15:05:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 11497555 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D388B81 for ; Sun, 19 Apr 2020 15:06:35 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A2C7121973 for ; Sun, 19 Apr 2020 15:06:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="siriqlsT"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="r1YrTjRd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A2C7121973 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=pZQ0dd6pnEYVXSIQdIL5rbeh3Y4PPgEpIfECInmUHRE=; b=siriqlsTFEVRvt3gCjdEV4ilZr Sl/BdUHWJATOzys5xbXtNVMKqPF7vf40N8nmx4VuXBZNPo+QhA//uUz3TSCA/7Vx97iBRCFK4strt kDwz8p8dwuo8/W5msdQj0VbE3Nnj1Mm5GqrSP6hGey8JtPZPMAhUXP7HumwZ+kAtSBmK5/Rf88ZTt U8rfoB0NFp650yO/U8N2wydNzgg254mMPF8BMF02eyy7Qh/Ie9IQo6Egowam7tvHxXpLuK4P87q6K 1ld6VSGJzYfJFKBXhtYjqkIXpSnSVZJHvZl1VjWP5/ussx/Anvtze4xvQaY6POqZe8jzPyEhJrpd5 UZujDb0A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQBWf-0008QF-9H; Sun, 19 Apr 2020 15:06:29 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQBWE-00084Y-Eo for linux-arm-kernel@lists.infradead.org; Sun, 19 Apr 2020 15:06:06 +0000 Received: by mail-wr1-x444.google.com with SMTP id d17so8816460wrg.11 for ; Sun, 19 Apr 2020 08:06:01 -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; bh=5I4MSLTJOBl1Jn2nKk55DTzP4h3HxHPJ2YS3y5/mux8=; b=r1YrTjRdErGiKY88e0TcKF3hYB6y0VZNENz9otldapbrRE/o41dcwt/0a256WYmYeN XBk+pGCJNEb5GalhEY0/t1CNfs/n3S4rOu3PhmeMla02s/V5kjv0KPTC28KS7fGcgHHg Odx52ZNrQmpt8uAu11elsrzgEsbhklPsr6CkakUAH2zDlpIH2q+6rmeNygFOxel5nA8q 8RYv7pxgUx5GfXsUc7VKqUeSRVvCEawdyye7hdMrNaGJGn+elhofSKrmWFMlx33FXder goxz6LQkMOqr22IjN2voIIsTUiuCAX3lDqsGfK+taIr9ArWV+zG0gfixaedq7pWwcPWj +KCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5I4MSLTJOBl1Jn2nKk55DTzP4h3HxHPJ2YS3y5/mux8=; b=e79DeRzp2Ra93j9GxZE7n+YTg3q1vxgHXkJksyZgzIOfxLiVgOJOSUPEFQu+RsZLDt z7D6DQS/ypAjybDfoD3jKi0sOd1+75/cvkTYDj7D3h+ga7MB6HSf3fYTr3IHyc26oZ7h EL+EQm+MaOXmUx9S/HXX/XOpSAwicIe7qEaH4RMSBpdD/TUYa46lT809SBH27RzNCIhL 1xthtKU3QADrkZ7fHKuOaDwfaSKdEspziNc73EPf5BDBTThAPlmY6g+qiVvFauARcBTq JW+oipv/QRn6Yj5VJLRThaPTwVFP96V71CqBXmgLWaS8E0ZWZDWwu95XCm+yQ2W9Y4xi y+Bg== X-Gm-Message-State: AGi0PuYxja8oRfXALQrpzwahrYvlPfDw6Dvge+aoEvCC2qAjwZuCHe17 xaA2zSORN6q1WJHIMIOCu/67Cw== X-Google-Smtp-Source: APiQypJQZkht5jaZb1/UjrEqkxLSRTN/YHe1uN80L6ohNNQHDpqFwI7mFtgWoDuegY/ylULabpEmnQ== X-Received: by 2002:adf:fe45:: with SMTP id m5mr14927300wrs.124.1587308760428; Sun, 19 Apr 2020 08:06:00 -0700 (PDT) Received: from lmecxl0524.home (2a01cb058702ff00947c0d9b78b8fa1e.ipv6.abo.wanadoo.fr. [2a01:cb05:8702:ff00:947c:d9b:78b8:fa1e]) by smtp.gmail.com with ESMTPSA id w12sm25948635wrk.56.2020.04.19.08.05.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Apr 2020 08:05:59 -0700 (PDT) From: Etienne Carriere To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 2/6] firmware: psci: set SMCCC v1.0 conduit and use helpers functions Date: Sun, 19 Apr 2020 17:05:26 +0200 Message-Id: <20200419150530.20508-3-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200419150530.20508-1-etienne.carriere@linaro.org> References: <20200419150530.20508-1-etienne.carriere@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200419_080602_500274_74BDF446 X-CRM114-Status: GOOD ( 14.01 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:444 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, lorenzo.pieralisi@arm.com, michal.simek@xilinx.com, tee-dev@lists.linaro.org, Etienne Carriere , james.morse@arm.com, sudeep.holla@arm.com, richard.gong@linux.intel.com, jens.wiklander@linaro.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Change PSCI driver to use SMCCC v1.0 helper functions. As PSCI device is initialized before other devices, it sets the SMCCC conduit used to SMCCC v1.0 compliant calls and other devices can rely on it. No functional change in the PSCI device itself. Signed-off-by: Etienne Carriere --- drivers/firmware/psci/psci.c | 60 +++++------------------------------- include/linux/psci.h | 1 - 2 files changed, 8 insertions(+), 53 deletions(-) diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index 2937d44b5df4..00bb205cad7c 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -53,7 +53,6 @@ bool psci_tos_resident_on(int cpu) } struct psci_operations psci_ops = { - .conduit = SMCCC_CONDUIT_NONE, .smccc_version = SMCCC_VERSION_1_0, }; @@ -62,13 +61,9 @@ enum arm_smccc_conduit arm_smccc_1_1_get_conduit(void) if (psci_ops.smccc_version < SMCCC_VERSION_1_1) return SMCCC_CONDUIT_NONE; - return psci_ops.conduit; + return arm_smccc_1_0_get_conduit(); } -typedef unsigned long (psci_fn)(unsigned long, unsigned long, - unsigned long, unsigned long); -static psci_fn *invoke_psci_fn; - enum psci_function { PSCI_FN_CPU_SUSPEND, PSCI_FN_CPU_ON, @@ -120,23 +115,14 @@ bool psci_power_state_is_valid(u32 state) return !(state & ~valid_mask); } -static unsigned long __invoke_psci_fn_hvc(unsigned long function_id, - unsigned long arg0, unsigned long arg1, - unsigned long arg2) +static unsigned long invoke_psci_fn(unsigned long function_id, + unsigned long arg0, unsigned long arg1, + unsigned long arg2) { struct arm_smccc_res res; - arm_smccc_hvc(function_id, arg0, arg1, arg2, 0, 0, 0, 0, &res); - return res.a0; -} + arm_smccc_1_0_invoke(function_id, arg0, arg1, arg2, 0, 0, 0, 0, &res); -static unsigned long __invoke_psci_fn_smc(unsigned long function_id, - unsigned long arg0, unsigned long arg1, - unsigned long arg2) -{ - struct arm_smccc_res res; - - arm_smccc_smc(function_id, arg0, arg1, arg2, 0, 0, 0, 0, &res); return res.a0; } @@ -229,41 +215,11 @@ static unsigned long psci_migrate_info_up_cpu(void) 0, 0, 0); } -static void set_conduit(enum arm_smccc_conduit conduit) -{ - switch (conduit) { - case SMCCC_CONDUIT_HVC: - invoke_psci_fn = __invoke_psci_fn_hvc; - break; - case SMCCC_CONDUIT_SMC: - invoke_psci_fn = __invoke_psci_fn_smc; - break; - default: - WARN(1, "Unexpected PSCI conduit %d\n", conduit); - } - - psci_ops.conduit = conduit; -} - static int get_set_conduit_method(struct device_node *np) { - const char *method; - - pr_info("probing for conduit method from DT.\n"); - - if (of_property_read_string(np, "method", &method)) { - pr_warn("missing \"method\" property\n"); + if (of_arm_smccc_1_0_set_conduit(np)) return -ENXIO; - } - if (!strcmp("hvc", method)) { - set_conduit(SMCCC_CONDUIT_HVC); - } else if (!strcmp("smc", method)) { - set_conduit(SMCCC_CONDUIT_SMC); - } else { - pr_warn("invalid \"method\" property: %s\n", method); - return -EINVAL; - } return 0; } @@ -605,9 +561,9 @@ int __init psci_acpi_init(void) pr_info("probing for conduit method from ACPI.\n"); if (acpi_psci_use_hvc()) - set_conduit(SMCCC_CONDUIT_HVC); + arm_smccc_1_0_set_conduit(SMCCC_CONDUIT_HVC); else - set_conduit(SMCCC_CONDUIT_SMC); + arm_smccc_1_0_set_conduit(SMCCC_CONDUIT_SMC); return psci_probe(); } diff --git a/include/linux/psci.h b/include/linux/psci.h index a67712b73b6c..9de579a1d237 100644 --- a/include/linux/psci.h +++ b/include/linux/psci.h @@ -35,7 +35,6 @@ struct psci_operations { int (*affinity_info)(unsigned long target_affinity, unsigned long lowest_affinity_level); int (*migrate_info_type)(void); - enum arm_smccc_conduit conduit; enum smccc_version smccc_version; }; From patchwork Sun Apr 19 15:05:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 11497553 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 85CF581 for ; Sun, 19 Apr 2020 15:06:16 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 51C19214D8 for ; Sun, 19 Apr 2020 15:06:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="OJ5xExCo"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="FAsKztdL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 51C19214D8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ClokqcA5H4Iob25pNoWurz500JIG/TOR8ooE0lip8uU=; b=OJ5xExColJtU8cikgkePQNn0be +45IsxgHK8ha2Ly4KAvja9+c4x3McVacRk1cMZo+9QZ69nY9bgCtQzj5MPykRw1eZW+j/LLaRFna9 y4W+LmCT8SeNm4tHspoEXXz0HY9j5RaGYtZvRCfDaNU+NvNALiD8FzHKYy0NgB9hDaPKS4K22dfpE fCc8mKwmiAdGp+8Nnu2Y+yfOh3ImDMNuaf7C6BWEP2jUPNhzWLOkynLNBor+RQXyF0UQ7ruVeWkpT qcv+8ktuvFvSjI2MN+NpDRTEX62JjigX0/PrdAJz4uIyCsDA1gqJv+D+sTXAevMu/ESKfDFk8VLgE 1fdJ/A2g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQBWM-0008Bd-Gd; Sun, 19 Apr 2020 15:06:10 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQBWF-00086R-E5 for linux-arm-kernel@lists.infradead.org; Sun, 19 Apr 2020 15:06:06 +0000 Received: by mail-wr1-x442.google.com with SMTP id g13so6817489wrb.8 for ; Sun, 19 Apr 2020 08:06:03 -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; bh=ObSDf1aLj5u4GmmbiRGYRUxXBmWBTKTJj89dIRLXbuQ=; b=FAsKztdL6snh1BvfjbKlo3DppwMhfJGyfvYsvsLDgMAglmASIZERqy/cdA3zJg6Puw 3HTyEoaVdE6Aa1WsXVffBrI3qn+8dIcyobWayRxzZlgfefMyN2a8IWQITohU4VAeYwBw gfCtxfPIGieg2Lh5DvpL9MjAjK2qX0I6Mh5BosntHrUQnST2aCbFysOypsis+dwXkRRk 3fCEpbPZ0aBHf1S0EZx+fb0TnsSh+TaW4t3lBjmFGDDZ0FL7jVcsG/dKPKn4pKFXQBcA T5xZLNbD+nsAoCij2bXT5aaNR373Kr2DrpKwYvPilMJ0UnJoVar/VTx2xatPYLebPqR+ 773g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ObSDf1aLj5u4GmmbiRGYRUxXBmWBTKTJj89dIRLXbuQ=; b=crF4VHM5BHemooLzQW058NmeRruCdnHHlBVkt5P8n19iXF2VkzmUWYx8azC1Wcxlny ke3ujIfSvqkLatQVQ98tRivVyA47Gair3N7A2KD6to40+kwQ64xCmYFR0PFSo+7EpXit 9mnlKGTjIJOcb7VH1FgBLne9Du+/0OQRGOhFfxM23Z9fL4ujR/qz4ASaHoNx1PieLqlE WKAUtE3/QiXE3yJzLhTztGuhtfpUZmhr/egNbIYkQ5WabP99CxmpW9F+jUDO5V7/qIs/ oTZ2VrMWXUTOhmmovyiqyX2X/AMS0XIk+FQI1E3OyV5GU3HzHtyVCbP9sWCHDyeAU9IQ ITtA== X-Gm-Message-State: AGi0PuYt/wm48+nXj6/aPdRT9ThkKXy+LrWLsXUZSLZiFDpA+mgtgEcZ GnEJfSnoAPZtLltmOtS4Cs+4LA== X-Google-Smtp-Source: APiQypLkrRiQ4l9Ag27jWuqY2Firc1AQu0LIYqJNeNMNzAN9BhPzlQzcaNCc7h6b2/CA98LcZcj1WQ== X-Received: by 2002:a5d:6647:: with SMTP id f7mr14854178wrw.41.1587308762199; Sun, 19 Apr 2020 08:06:02 -0700 (PDT) Received: from lmecxl0524.home (2a01cb058702ff00947c0d9b78b8fa1e.ipv6.abo.wanadoo.fr. [2a01:cb05:8702:ff00:947c:d9b:78b8:fa1e]) by smtp.gmail.com with ESMTPSA id w12sm25948635wrk.56.2020.04.19.08.06.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Apr 2020 08:06:01 -0700 (PDT) From: Etienne Carriere To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 3/6] tee: optee: use SMCCC v1.0 helper functions Date: Sun, 19 Apr 2020 17:05:27 +0200 Message-Id: <20200419150530.20508-4-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200419150530.20508-1-etienne.carriere@linaro.org> References: <20200419150530.20508-1-etienne.carriere@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200419_080603_494114_7961109D X-CRM114-Status: GOOD ( 17.09 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:442 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, lorenzo.pieralisi@arm.com, michal.simek@xilinx.com, tee-dev@lists.linaro.org, Etienne Carriere , james.morse@arm.com, sudeep.holla@arm.com, richard.gong@linux.intel.com, jens.wiklander@linaro.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Change OP-TEE driver to use SMCCC v1.0 helper function. No functional change but initialization traces that are changed from pr_*() traces the device dev_*() traces and info trace "probing for conduit method." being replaced with trace "probing for conduit method from DT." Signed-off-by: Etienne Carriere --- drivers/tee/optee/call.c | 14 ++--- drivers/tee/optee/core.c | 85 ++++++++----------------------- drivers/tee/optee/optee_private.h | 4 +- 3 files changed, 30 insertions(+), 73 deletions(-) diff --git a/drivers/tee/optee/call.c b/drivers/tee/optee/call.c index cf2367ba08d6..706e7814a401 100644 --- a/drivers/tee/optee/call.c +++ b/drivers/tee/optee/call.c @@ -137,9 +137,9 @@ u32 optee_do_call_with_arg(struct tee_context *ctx, phys_addr_t parg) while (true) { struct arm_smccc_res res; - optee->invoke_fn(param.a0, param.a1, param.a2, param.a3, - param.a4, param.a5, param.a6, param.a7, - &res); + arm_smccc_1_0_invoke(param.a0, param.a1, param.a2, param.a3, + param.a4, param.a5, param.a6, param.a7, + &res); if (res.a0 == OPTEE_SMC_RETURN_ETHREAD_LIMIT) { /* @@ -395,8 +395,8 @@ void optee_enable_shm_cache(struct optee *optee) while (true) { struct arm_smccc_res res; - optee->invoke_fn(OPTEE_SMC_ENABLE_SHM_CACHE, 0, 0, 0, 0, 0, 0, - 0, &res); + arm_smccc_1_0_invoke(OPTEE_SMC_ENABLE_SHM_CACHE, + 0, 0, 0, 0, 0, 0, 0, &res); if (res.a0 == OPTEE_SMC_RETURN_OK) break; optee_cq_wait_for_completion(&optee->call_queue, &w); @@ -421,8 +421,8 @@ void optee_disable_shm_cache(struct optee *optee) struct optee_smc_disable_shm_cache_result result; } res; - optee->invoke_fn(OPTEE_SMC_DISABLE_SHM_CACHE, 0, 0, 0, 0, 0, 0, - 0, &res.smccc); + arm_smccc_1_0_invoke(OPTEE_SMC_DISABLE_SHM_CACHE, + 0, 0, 0, 0, 0, 0, 0, &res.smccc); if (res.result.status == OPTEE_SMC_RETURN_ENOTAVAIL) break; /* All shm's freed */ if (res.result.status == OPTEE_SMC_RETURN_OK) { diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index 99698b8a3a74..f3bc657d1e97 100644 --- a/drivers/tee/optee/core.c +++ b/drivers/tee/optee/core.c @@ -335,11 +335,11 @@ static const struct tee_desc optee_supp_desc = { .flags = TEE_DESC_PRIVILEGED, }; -static bool optee_msg_api_uid_is_optee_api(optee_invoke_fn *invoke_fn) +static bool optee_msg_api_uid_is_optee_api(void) { struct arm_smccc_res res; - invoke_fn(OPTEE_SMC_CALLS_UID, 0, 0, 0, 0, 0, 0, 0, &res); + arm_smccc_1_0_invoke(OPTEE_SMC_CALLS_UID, 0, 0, 0, 0, 0, 0, 0, &res); if (res.a0 == OPTEE_MSG_UID_0 && res.a1 == OPTEE_MSG_UID_1 && res.a2 == OPTEE_MSG_UID_2 && res.a3 == OPTEE_MSG_UID_3) @@ -347,7 +347,7 @@ static bool optee_msg_api_uid_is_optee_api(optee_invoke_fn *invoke_fn) return false; } -static void optee_msg_get_os_revision(optee_invoke_fn *invoke_fn) +static void optee_msg_get_os_revision(void) { union { struct arm_smccc_res smccc; @@ -358,8 +358,8 @@ static void optee_msg_get_os_revision(optee_invoke_fn *invoke_fn) } }; - invoke_fn(OPTEE_SMC_CALL_GET_OS_REVISION, 0, 0, 0, 0, 0, 0, 0, - &res.smccc); + arm_smccc_1_0_invoke(OPTEE_SMC_CALL_GET_OS_REVISION, + 0, 0, 0, 0, 0, 0, 0, &res.smccc); if (res.result.build_id) pr_info("revision %lu.%lu (%08lx)", res.result.major, @@ -368,14 +368,15 @@ static void optee_msg_get_os_revision(optee_invoke_fn *invoke_fn) pr_info("revision %lu.%lu", res.result.major, res.result.minor); } -static bool optee_msg_api_revision_is_compatible(optee_invoke_fn *invoke_fn) +static bool optee_msg_api_revision_is_compatible(void) { union { struct arm_smccc_res smccc; struct optee_smc_calls_revision_result result; } res; - invoke_fn(OPTEE_SMC_CALLS_REVISION, 0, 0, 0, 0, 0, 0, 0, &res.smccc); + arm_smccc_1_0_invoke(OPTEE_SMC_CALLS_REVISION, + 0, 0, 0, 0, 0, 0, 0, &res.smccc); if (res.result.major == OPTEE_MSG_REVISION_MAJOR && (int)res.result.minor >= OPTEE_MSG_REVISION_MINOR) @@ -383,8 +384,7 @@ static bool optee_msg_api_revision_is_compatible(optee_invoke_fn *invoke_fn) return false; } -static bool optee_msg_exchange_capabilities(optee_invoke_fn *invoke_fn, - u32 *sec_caps) +static bool optee_msg_exchange_capabilities(u32 *sec_caps) { union { struct arm_smccc_res smccc; @@ -400,8 +400,8 @@ static bool optee_msg_exchange_capabilities(optee_invoke_fn *invoke_fn, if (!IS_ENABLED(CONFIG_SMP) || nr_cpu_ids == 1) a1 |= OPTEE_SMC_NSEC_CAP_UNIPROCESSOR; - invoke_fn(OPTEE_SMC_EXCHANGE_CAPABILITIES, a1, 0, 0, 0, 0, 0, 0, - &res.smccc); + arm_smccc_1_0_invoke(OPTEE_SMC_EXCHANGE_CAPABILITIES, a1, + 0, 0, 0, 0, 0, 0, &res.smccc); if (res.result.status != OPTEE_SMC_RETURN_OK) return false; @@ -437,8 +437,7 @@ static struct tee_shm_pool *optee_config_dyn_shm(void) return rc; } -static struct tee_shm_pool * -optee_config_shm_memremap(optee_invoke_fn *invoke_fn, void **memremaped_shm) +static struct tee_shm_pool *optee_config_shm_memremap(void **memremaped_shm) { union { struct arm_smccc_res smccc; @@ -455,7 +454,8 @@ optee_config_shm_memremap(optee_invoke_fn *invoke_fn, void **memremaped_shm) void *rc; const int sz = OPTEE_SHM_NUM_PRIV_PAGES * PAGE_SIZE; - invoke_fn(OPTEE_SMC_GET_SHM_CONFIG, 0, 0, 0, 0, 0, 0, 0, &res.smccc); + arm_smccc_1_0_invoke(OPTEE_SMC_GET_SHM_CONFIG, + 0, 0, 0, 0, 0, 0, 0, &res.smccc); if (res.result.status != OPTEE_SMC_RETURN_OK) { pr_err("static shm service not available\n"); return ERR_PTR(-ENOENT); @@ -515,45 +515,6 @@ optee_config_shm_memremap(optee_invoke_fn *invoke_fn, void **memremaped_shm) return rc; } -/* Simple wrapper functions to be able to use a function pointer */ -static void optee_smccc_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 void optee_smccc_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 optee_invoke_fn *get_invoke_func(struct device *dev) -{ - const char *method; - - pr_info("probing for conduit method.\n"); - - if (device_property_read_string(dev, "method", &method)) { - pr_warn("missing \"method\" property\n"); - return ERR_PTR(-ENXIO); - } - - if (!strcmp("hvc", method)) - return optee_smccc_hvc; - else if (!strcmp("smc", method)) - return optee_smccc_smc; - - pr_warn("invalid \"method\" property: %s\n", method); - return ERR_PTR(-EINVAL); -} - static int optee_remove(struct platform_device *pdev) { struct optee *optee = platform_get_drvdata(pdev); @@ -586,7 +547,6 @@ static int optee_remove(struct platform_device *pdev) static int optee_probe(struct platform_device *pdev) { - optee_invoke_fn *invoke_fn; struct tee_shm_pool *pool = ERR_PTR(-EINVAL); struct optee *optee = NULL; void *memremaped_shm = NULL; @@ -594,23 +554,23 @@ static int optee_probe(struct platform_device *pdev) u32 sec_caps; int rc; - invoke_fn = get_invoke_func(&pdev->dev); - if (IS_ERR(invoke_fn)) - return PTR_ERR(invoke_fn); + rc = devm_arm_smccc_1_0_set_conduit(&pdev->dev); + if (rc) + return rc; - if (!optee_msg_api_uid_is_optee_api(invoke_fn)) { + if (!optee_msg_api_uid_is_optee_api()) { pr_warn("api uid mismatch\n"); return -EINVAL; } - optee_msg_get_os_revision(invoke_fn); + optee_msg_get_os_revision(); - if (!optee_msg_api_revision_is_compatible(invoke_fn)) { + if (!optee_msg_api_revision_is_compatible()) { pr_warn("api revision mismatch\n"); return -EINVAL; } - if (!optee_msg_exchange_capabilities(invoke_fn, &sec_caps)) { + if (!optee_msg_exchange_capabilities(&sec_caps)) { pr_warn("capabilities mismatch\n"); return -EINVAL; } @@ -625,7 +585,7 @@ static int optee_probe(struct platform_device *pdev) * If dynamic shared memory is not available or failed - try static one */ if (IS_ERR(pool) && (sec_caps & OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM)) - pool = optee_config_shm_memremap(invoke_fn, &memremaped_shm); + pool = optee_config_shm_memremap(&memremaped_shm); if (IS_ERR(pool)) return PTR_ERR(pool); @@ -636,7 +596,6 @@ static int optee_probe(struct platform_device *pdev) goto err; } - optee->invoke_fn = invoke_fn; optee->sec_caps = sec_caps; teedev = tee_device_alloc(&optee_desc, NULL, pool, optee); diff --git a/drivers/tee/optee/optee_private.h b/drivers/tee/optee/optee_private.h index d9c5037b4e03..e186e318e157 100644 --- a/drivers/tee/optee/optee_private.h +++ b/drivers/tee/optee/optee_private.h @@ -69,8 +69,7 @@ struct optee_supp { * struct optee - main service struct * @supp_teedev: supplicant device * @teedev: client device - * @invoke_fn: function to issue smc or hvc - * @call_queue: queue of threads waiting to call @invoke_fn + * @call_queue: queue of threads waiting to invoke secure world * @wait_queue: queue of threads from secure world waiting for a * secure world sync object * @supp: supplicant synchronization struct for RPC to supplicant @@ -82,7 +81,6 @@ struct optee_supp { struct optee { struct tee_device *supp_teedev; struct tee_device *teedev; - optee_invoke_fn *invoke_fn; struct optee_call_queue call_queue; struct optee_wait_queue wait_queue; struct optee_supp supp; From patchwork Sun Apr 19 15:05:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 11497557 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF49C81 for ; Sun, 19 Apr 2020 15:06:51 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 75B32214D8 for ; Sun, 19 Apr 2020 15:06:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="stn9CWr8"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="dOChkGBX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 75B32214D8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=GSj9JtK7Cp7RXbWIAwlQUWQCtG/fvbV+bHwNJ3SJDYY=; b=stn9CWr8CWdF5kQlC7XNVJvG7+ Yl3MolJBbtt7yaWn49LziLh1aHy9CUqXPSKHg5gt4Y81w4wfE1L8M8hcnzMzcgrW2bZHDfZNruV18 uUoj38cMkLXvZ1gB/NokqCHvXG52jcj6GQOet/zF1GR95A9zCs4JW9u8ghik0D4iDAbfkAfc4yW4r 6QbHSL3UYIvG0arJtMxXCHhIA+Y39RJXkXCFwo5ibwUrYQaFSyRJJfm5ZwfppDCqZsGtXooUtZq2z 6nQxDjLNfJ9jp73R7LJqgsHpUFAN9m9PARtQ3eQhyFnPONtvs7OmiTEeBIipsnkt9MfnRD4/Qfkjy 6gMOySLA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQBWx-0000HR-Pz; Sun, 19 Apr 2020 15:06:47 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQBWH-00087x-T2 for linux-arm-kernel@lists.infradead.org; Sun, 19 Apr 2020 15:06:08 +0000 Received: by mail-wm1-x344.google.com with SMTP id h2so8017978wmb.4 for ; Sun, 19 Apr 2020 08:06:05 -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; bh=mgJBrbN8ENQqYlA1aIDPfUqg5Ku3KzLaL/T3CN2BzCg=; b=dOChkGBXatBUuviw+VQ7NlxwgSe4bulYhXcZnUSRbQzSkY8v2IGYGkp1F67pAW+lHn +rKzTGQtt+p0ef5si0UK/1SZ/FtgfisWJ8S8N8YGxJ24TYQfFLmRCmLzG3mO084ovSeM /QDwzKFejEYNo8+nvKgNBtbLY1L2w45Tzed+My5voD0yFEofKWUG8PJ9mj6rqp87sAXA 62LqvCOcn8WBuw6jKOXQ3Dlq6jt6+JC5/4eHv8qlE0djHyL1qoUIK26hitN9stHGipmw kJCVk25HCUAoW2+tZVyzZcDalsZwQN4EjYQjDPtS+wbQqXJwkbqs7WBRL2fvSmIebLpY Em5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mgJBrbN8ENQqYlA1aIDPfUqg5Ku3KzLaL/T3CN2BzCg=; b=aK4BMC/q1ANBPp1YL/b3x5e8YTqmytxU1Kj2TnO3KULfKzNilR54ZCWYFw3wWyWNm5 lc2pz9Me5+opDdNS/+RgMvEN5P4R0yyeuLimQcrUmPT8aQXWLBMS4abKTOBwgUN8iBJR eg0YFcynqmDGO52qCEPGmZPyHhbCCq/iQalzA7PT/BDcb5zFTNxYg8g7e3tl34TKpacr rymc+jbBi3LRlEBisfbcG+ArPWLJX7waOW9aRBHjxPd2goyfoY9dWCSOeLns6oehAqMm bHeSIFu6qeIB9pn/WLo3Ycwg8MxoBmqKV8Vzs2UZ75srNmszwyAjVsxY22HXw2yLKXqr P66Q== X-Gm-Message-State: AGi0Pua7IOJQPs0tO0BcJh+5FCzAgYtgxW7zyPZl9hxDhx2Jf4OQFifT N7HiEVtl91YxcEt6IWz1SOdLcA== X-Google-Smtp-Source: APiQypIHYS79qS6Ym7/zsAfw92yZoAhc0D6OXdVNJBvmovHjD1VVezpW6nATF5ItbotHjroDPpo0ng== X-Received: by 2002:a7b:ca54:: with SMTP id m20mr12078369wml.45.1587308763884; Sun, 19 Apr 2020 08:06:03 -0700 (PDT) Received: from lmecxl0524.home (2a01cb058702ff00947c0d9b78b8fa1e.ipv6.abo.wanadoo.fr. [2a01:cb05:8702:ff00:947c:d9b:78b8:fa1e]) by smtp.gmail.com with ESMTPSA id w12sm25948635wrk.56.2020.04.19.08.06.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Apr 2020 08:06:03 -0700 (PDT) From: Etienne Carriere To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 4/6] firmware: arm_sdei: use SMCCC v1.0 helper functions Date: Sun, 19 Apr 2020 17:05:28 +0200 Message-Id: <20200419150530.20508-5-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200419150530.20508-1-etienne.carriere@linaro.org> References: <20200419150530.20508-1-etienne.carriere@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200419_080605_998506_5BABD5C0 X-CRM114-Status: GOOD ( 17.51 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:344 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, lorenzo.pieralisi@arm.com, michal.simek@xilinx.com, tee-dev@lists.linaro.org, Etienne Carriere , james.morse@arm.com, sudeep.holla@arm.com, richard.gong@linux.intel.com, jens.wiklander@linaro.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Change Arm SDEI firmware driver to use SMCCC v1.0 helper functions. Functional changes are Arm SDEI firmware driver can find appropriate set conduit if it does not define one but another device has set the kernel conduit for SMCCC calls. Other functional changes are the trace messages emitted at device probe time that now dev_*() traces instead of pr_*() traces. Signed-off-by: Etienne Carriere --- drivers/firmware/arm_sdei.c | 79 +++++++++++++------------------------ 1 file changed, 27 insertions(+), 52 deletions(-) diff --git a/drivers/firmware/arm_sdei.c b/drivers/firmware/arm_sdei.c index 334c8be0c11f..92f8077e0bde 100644 --- a/drivers/firmware/arm_sdei.c +++ b/drivers/firmware/arm_sdei.c @@ -34,12 +34,9 @@ #include /* - * The call to use to reach the firmware. + * The SMCCC cnduit for the call to use to reach the firmware. */ -static asmlinkage void (*sdei_firmware_call)(unsigned long function_id, - unsigned long arg0, unsigned long arg1, - unsigned long arg2, unsigned long arg3, - unsigned long arg4, struct arm_smccc_res *res); +static enum arm_smccc_conduit sdei_firmware_call_conduit; /* entry point from firmware to arch asm code */ static unsigned long sdei_entry_point; @@ -144,14 +141,14 @@ static int invoke_sdei_fn(unsigned long function_id, unsigned long arg0, int err = 0; struct arm_smccc_res res; - if (sdei_firmware_call) { + if (sdei_firmware_call_conduit != SMCCC_CONDUIT_NONE) { sdei_firmware_call(function_id, arg0, arg1, arg2, arg3, arg4, &res); if (sdei_is_err(&res)) err = sdei_to_linux_errno(res.a0); } else { /* - * !sdei_firmware_call means we failed to probe or called + * No SMCCC conduit means we failed to probe or called * sdei_mark_interface_broken(). -EIO is not an error returned * by sdei_to_linux_errno() and is used to suppress messages * from this driver. @@ -364,7 +361,7 @@ static void sdei_mark_interface_broken(void) { pr_err("disabling SDEI firmware interface\n"); on_each_cpu(&_ipi_mask_cpu, NULL, true); - sdei_firmware_call = NULL; + sdei_firmware_call_conduit = SMCCC_CONDUIT_NONE; } static int sdei_platform_reset(void) @@ -874,23 +871,19 @@ static struct notifier_block sdei_reboot_nb = { .notifier_call = sdei_reboot_notifier, }; -static void sdei_smccc_smc(unsigned long function_id, - unsigned long arg0, unsigned long arg1, - unsigned long arg2, unsigned long arg3, - unsigned long arg4, struct arm_smccc_res *res) -{ - arm_smccc_smc(function_id, arg0, arg1, arg2, arg3, arg4, 0, 0, res); -} -NOKPROBE_SYMBOL(sdei_smccc_smc); -static void sdei_smccc_hvc(unsigned long function_id, - unsigned long arg0, unsigned long arg1, - unsigned long arg2, unsigned long arg3, - unsigned long arg4, struct arm_smccc_res *res) +static asmlinkage void sdei_firmware_call(unsigned long function_id, + unsigned long arg0, + unsigned long arg1, + unsigned long arg2, + unsigned long arg3, + unsigned long arg4, + struct arm_smccc_res *res) { - arm_smccc_hvc(function_id, arg0, arg1, arg2, arg3, arg4, 0, 0, res); + arm_smccc_1_0_invoke(function_id, arg0, arg1, arg2, arg3, arg4, + 0, 0, res); } -NOKPROBE_SYMBOL(sdei_smccc_hvc); +NOKPROBE_SYMBOL(sdei_firmware_call); int sdei_register_ghes(struct ghes *ghes, sdei_event_callback *normal_cb, sdei_event_callback *critical_cb) @@ -959,48 +952,30 @@ int sdei_unregister_ghes(struct ghes *ghes) return err; } -static int sdei_get_conduit(struct platform_device *pdev) +static enum arm_smccc_conduit sdei_get_conduit(struct platform_device *pdev) { - const char *method; - struct device_node *np = pdev->dev.of_node; - - sdei_firmware_call = NULL; - if (np) { - if (of_property_read_string(np, "method", &method)) { - pr_warn("missing \"method\" property\n"); - return SMCCC_CONDUIT_NONE; - } - - if (!strcmp("hvc", method)) { - sdei_firmware_call = &sdei_smccc_hvc; - return SMCCC_CONDUIT_HVC; - } else if (!strcmp("smc", method)) { - sdei_firmware_call = &sdei_smccc_smc; - return SMCCC_CONDUIT_SMC; - } - - pr_warn("invalid \"method\" property: %s\n", method); + if (pdev->dev.of_node) { + devm_arm_smccc_1_0_set_conduit(pdev->dev); } else if (IS_ENABLED(CONFIG_ACPI) && !acpi_disabled) { - if (acpi_psci_use_hvc()) { - sdei_firmware_call = &sdei_smccc_hvc; - return SMCCC_CONDUIT_HVC; - } else { - sdei_firmware_call = &sdei_smccc_smc; - return SMCCC_CONDUIT_SMC; - } + if (acpi_psci_use_hvc()) + arm_smccc_1_0_set_conduit(SMCCC_CONDUIT_HVC); + else + arm_smccc_1_0_set_conduit(SMCCC_CONDUIT_SMC); } - return SMCCC_CONDUIT_NONE; + sdei_firmware_call_conduit = arm_smccc_1_0_get_conduit(); + + return sdei_firmware_call_conduit; } static int sdei_probe(struct platform_device *pdev) { int err; u64 ver = 0; - int conduit; + enum arm_smccc_conduit conduit; conduit = sdei_get_conduit(pdev); - if (!sdei_firmware_call) + if (conduit == SMCCC_CONDUIT_NONE) return 0; err = sdei_api_get_version(&ver); From patchwork Sun Apr 19 15:05:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 11497559 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 67CCA81 for ; Sun, 19 Apr 2020 15:07:12 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 30E31214D8 for ; Sun, 19 Apr 2020 15:07:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="c2kWgVf/"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="bSUZ3FZ/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 30E31214D8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=O+hQWYz3hG6RSN9k1X+/lHz5HvwdjEpKP06pcP/2QeI=; b=c2kWgVf/uP9cTpD4BnDh2ytTaJ +LTUPuB2c454SYvz+/e/ToGMUy/ZbFbWVF7iOmohX9efei7inpTzTuIr+Sd3JXnoovC8fq27YpCFb JHYz9T9sinWBN2ldUDfpibPAuq5qr8AvMFCVKqWFYiTs5vG5nGjYOdRmociWOh3wRhZ++FELqbLNc lbeojNAl1CfgepuIsr+Dxn2RxsczxEcu3ervzCBIJsWx6S3ccx25xeLkG0DcSR+B7ynjSTuEQKzT8 zmgoDb7SxIt5A175Xl5lhikQmVuQxiotEYXT7XuhbPnoJBbJHQ1vEGcVspQZzDzFgErmxuKVpvs+1 UjyB6kwg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQBXF-0000Xa-Gc; Sun, 19 Apr 2020 15:07:05 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQBWJ-00089M-7w for linux-arm-kernel@lists.infradead.org; Sun, 19 Apr 2020 15:06:13 +0000 Received: by mail-wr1-x442.google.com with SMTP id j2so8831750wrs.9 for ; Sun, 19 Apr 2020 08:06:07 -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; bh=PlXCkAj7SQ4UkWuPcToquaH1G9B7ruGi30ZWGX4XAOI=; b=bSUZ3FZ/E0Yll9mMB7lRuIpfWOJ2UjnTn9Y5kylSnIcCBmpx/1nfXbMiCD57DgznMV kmSKROR6KdG6ukdsKOjv6ygoc05kmCMtgbG4HLY9LlKG4AYF836ilgTkc1YmVI3FHUjG fZaQzKjN5hXLG5S55dPB4vSgIy713coGDKRGk7VCi4miffBi8/SOMAd4IBZvUESUWaio 3IzvdC6MbiwnUjFwnMfLg+eyVRYFnFgA0bGKJcuaJHWUhO1UT1IBSqOcXflq+MpR2tAU m+8qYq6KqGr30MvoZsQVzyb+az+TKHWLOdz2thY9pjPPbZh4tGfeUu3xJaCtBHXwhdMA UEsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PlXCkAj7SQ4UkWuPcToquaH1G9B7ruGi30ZWGX4XAOI=; b=tbPx8DcjKcDMGSWZvcSk0F7686dv5foBLwun2a8c4d6g/IVzB1f0cmBzmOUnNfQ0hX RF0LbBAt1JxG3f+wXOZUd2N8Qmdjs6P2qMOb4/+5BUO+v4+eAzK6oii/p8i4Nc8ALLkO oUA4fJpRKPWfNHNW53OWnO5BVh3yplkgyFDuLABrAOkg1Yyyo59LpgRHjMf03v3Qqi06 umJ8ssuSiGWpSx8mrB4i+2FSDy6uutMpofER1jEwYmyaxJ3KYUtQpdgYkj6Cok4UOFVS e0EwmyzdJnHQp2FpMJBX0RM1IMcYletoB6vTG1wreEHm3DWIpOcKP9iYKz3ISiZUMxX2 UOMA== X-Gm-Message-State: AGi0PuaNMOpZKLb+WBVOZ1lElIj0IUrqPW18t03A2arv5f7yPA16Ca4r L24cTCJasV7v0ULFxENIZ33dlw== X-Google-Smtp-Source: APiQypK4xdmIs7kwsa7WCAqQXbtAO2TeUQmMZY0x3pN8rCZP9NcFL0C2FPOU1tjGn0zBRSXgyKLwpQ== X-Received: by 2002:adf:c109:: with SMTP id r9mr13905434wre.265.1587308765612; Sun, 19 Apr 2020 08:06:05 -0700 (PDT) Received: from lmecxl0524.home (2a01cb058702ff00947c0d9b78b8fa1e.ipv6.abo.wanadoo.fr. [2a01:cb05:8702:ff00:947c:d9b:78b8:fa1e]) by smtp.gmail.com with ESMTPSA id w12sm25948635wrk.56.2020.04.19.08.06.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Apr 2020 08:06:05 -0700 (PDT) From: Etienne Carriere To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 5/6] firmware: stratix10: use SMCCC v1.0 helper functions Date: Sun, 19 Apr 2020 17:05:29 +0200 Message-Id: <20200419150530.20508-6-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200419150530.20508-1-etienne.carriere@linaro.org> References: <20200419150530.20508-1-etienne.carriere@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200419_080607_353711_6A97B74B X-CRM114-Status: GOOD ( 13.89 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:442 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, lorenzo.pieralisi@arm.com, michal.simek@xilinx.com, tee-dev@lists.linaro.org, Etienne Carriere , james.morse@arm.com, sudeep.holla@arm.com, richard.gong@linux.intel.com, jens.wiklander@linaro.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Change Stratix 10 firmware driver to use SMCCC v1.0 helper function. Main functional change is that SMCCC conduit for the device is ensured being consistent with the method used by PSCI firmware. Another functional change is a additional info trace in the device probed sequence: "probing for conduit method from DT.". Signed-off-by: Etienne Carriere --- drivers/firmware/stratix10-svc.c | 97 +++----------------------------- 1 file changed, 9 insertions(+), 88 deletions(-) diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-svc.c index d5f0769f3761..132f05f2bcc8 100644 --- a/drivers/firmware/stratix10-svc.c +++ b/drivers/firmware/stratix10-svc.c @@ -41,10 +41,6 @@ /* stratix10 service layer clients */ #define STRATIX10_RSU "stratix10-rsu" -typedef void (svc_invoke_fn)(unsigned long, unsigned long, unsigned long, - unsigned long, unsigned long, unsigned long, - unsigned long, unsigned long, - struct arm_smccc_res *); struct stratix10_svc_chan; /** @@ -60,7 +56,6 @@ struct stratix10_svc { * @sync_complete: state for a completion * @addr: physical address of shared memory block * @size: size of shared memory block - * @invoke_fn: function to issue secure monitor or hypervisor call * * This struct is used to save physical address and size of shared memory * block. The shared memory blocked is allocated by secure monitor software @@ -73,7 +68,6 @@ struct stratix10_svc_sh_memory { struct completion sync_complete; unsigned long addr; unsigned long size; - svc_invoke_fn *invoke_fn; }; /** @@ -126,7 +120,6 @@ struct stratix10_svc_data { * @svc_fifo: a queue for storing service message data * @complete_status: state for completion * @svc_fifo_lock: protect access to service message data queue - * @invoke_fn: function to issue secure monitor call or hypervisor call * * This struct is used to create communication channels for service clients, to * handle secure monitor or hypervisor call. @@ -142,7 +135,6 @@ struct stratix10_svc_controller { struct kfifo svc_fifo; struct completion complete_status; spinlock_t svc_fifo_lock; - svc_invoke_fn *invoke_fn; }; /** @@ -206,8 +198,8 @@ static void svc_thread_cmd_data_claim(struct stratix10_svc_controller *ctrl, pr_debug("%s: claim back the submitted buffer\n", __func__); do { - ctrl->invoke_fn(INTEL_SIP_SMC_FPGA_CONFIG_COMPLETED_WRITE, - 0, 0, 0, 0, 0, 0, 0, &res); + arm_smccc_1_0_invoke(INTEL_SIP_SMC_FPGA_CONFIG_COMPLETED_WRITE, + 0, 0, 0, 0, 0, 0, 0, &res); if (res.a0 == INTEL_SIP_SMC_STATUS_OK) { if (!res.a1) { @@ -256,8 +248,8 @@ static void svc_thread_cmd_config_status(struct stratix10_svc_controller *ctrl, count_in_sec = FPGA_CONFIG_STATUS_TIMEOUT_SEC; while (count_in_sec) { - ctrl->invoke_fn(INTEL_SIP_SMC_FPGA_CONFIG_ISDONE, - 0, 0, 0, 0, 0, 0, 0, &res); + arm_smccc_1_0_invoke(INTEL_SIP_SMC_FPGA_CONFIG_ISDONE, + 0, 0, 0, 0, 0, 0, 0, &res); if ((res.a0 == INTEL_SIP_SMC_STATUS_OK) || (res.a0 == INTEL_SIP_SMC_FPGA_CONFIG_STATUS_ERROR)) break; @@ -420,7 +412,7 @@ static int svc_normal_to_secure_thread(void *data) __func__, (unsigned int)a0, (unsigned int)a1); pr_debug(" a2=0x%016x\n", (unsigned int)a2); - ctrl->invoke_fn(a0, a1, a2, 0, 0, 0, 0, 0, &res); + arm_smccc_1_0_invoke(a0, a1, a2, 0, 0, 0, 0, 0, &res); pr_debug("%s: after SMC call -- res.a0=0x%016x", __func__, (unsigned int)res.a0); @@ -540,8 +532,8 @@ static int svc_normal_to_secure_shm_thread(void *data) struct arm_smccc_res res; /* SMC or HVC call to get shared memory info from secure world */ - sh_mem->invoke_fn(INTEL_SIP_SMC_FPGA_CONFIG_GET_MEM, - 0, 0, 0, 0, 0, 0, 0, &res); + arm_smccc_1_0_invoke(INTEL_SIP_SMC_FPGA_CONFIG_GET_MEM, + 0, 0, 0, 0, 0, 0, 0, &res); if (res.a0 == INTEL_SIP_SMC_STATUS_OK) { sh_mem->addr = res.a1; sh_mem->size = res.a2; @@ -661,73 +653,6 @@ svc_create_memory_pool(struct platform_device *pdev, return genpool; } -/** - * svc_smccc_smc() - secure monitor call between normal and secure world - * @a0: argument passed in registers 0 - * @a1: argument passed in registers 1 - * @a2: argument passed in registers 2 - * @a3: argument passed in registers 3 - * @a4: argument passed in registers 4 - * @a5: argument passed in registers 5 - * @a6: argument passed in registers 6 - * @a7: argument passed in registers 7 - * @res: result values from register 0 to 3 - */ -static void svc_smccc_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); -} - -/** - * svc_smccc_hvc() - hypervisor call between normal and secure world - * @a0: argument passed in registers 0 - * @a1: argument passed in registers 1 - * @a2: argument passed in registers 2 - * @a3: argument passed in registers 3 - * @a4: argument passed in registers 4 - * @a5: argument passed in registers 5 - * @a6: argument passed in registers 6 - * @a7: argument passed in registers 7 - * @res: result values from register 0 to 3 - */ -static void svc_smccc_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); -} - -/** - * get_invoke_func() - invoke SMC or HVC call - * @dev: pointer to device - * - * Return: function pointer to svc_smccc_smc or svc_smccc_hvc. - */ -static svc_invoke_fn *get_invoke_func(struct device *dev) -{ - const char *method; - - if (of_property_read_string(dev->of_node, "method", &method)) { - dev_warn(dev, "missing \"method\" property\n"); - return ERR_PTR(-ENXIO); - } - - if (!strcmp(method, "smc")) - return svc_smccc_smc; - if (!strcmp(method, "hvc")) - return svc_smccc_hvc; - - dev_warn(dev, "invalid \"method\" property: %s\n", method); - - return ERR_PTR(-EINVAL); -} - /** * stratix10_svc_request_channel_byname() - request a service channel * @client: pointer to service client @@ -979,20 +904,17 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev) struct stratix10_svc_sh_memory *sh_memory; struct stratix10_svc *svc; - svc_invoke_fn *invoke_fn; size_t fifo_size; int ret; - /* get SMC or HVC function */ - invoke_fn = get_invoke_func(dev); - if (IS_ERR(invoke_fn)) + /* get SMC or HVC conduit */ + if (arm_smccc_1_0_set_device_conduit(&pdev->dev)) return -EINVAL; sh_memory = devm_kzalloc(dev, sizeof(*sh_memory), GFP_KERNEL); if (!sh_memory) return -ENOMEM; - sh_memory->invoke_fn = invoke_fn; ret = svc_get_sh_memory(pdev, sh_memory); if (ret) return ret; @@ -1017,7 +939,6 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev) controller->chans = chans; controller->genpool = genpool; controller->task = NULL; - controller->invoke_fn = invoke_fn; init_completion(&controller->complete_status); fifo_size = sizeof(struct stratix10_svc_data) * SVC_NUM_DATA_IN_FIFO; From patchwork Sun Apr 19 15:05:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 11497561 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF2446CA for ; Sun, 19 Apr 2020 15:07:29 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 76657214D8 for ; Sun, 19 Apr 2020 15:07:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="pxTxfuIn"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="FOV0ezYf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 76657214D8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=G6+JjLChu3+BZFu9nTqcJZx+lbIP23OVF/2rn+QuKLQ=; b=pxTxfuInjGH7ktxRc1XLkQvodj YNKx08+gfhlZxZiBwbSZwiCPuGui0rMvfVJredOGYx/oGEOLZz8fj8XCbLZMNR1Jf9E0dKfDDdGZ8 X4408nYShWxHu77yW4VzI3JBWUfNVfZiGz46+a5hCee5HoRS9VjI9rdevsrbwRjgR6yLMbTrz4w8t BHvQ7V/bsXT0w992qCzpybn/3SZ+DUSI/Yhiyi1uLuZbp/b0qRu2vL8N8Dki5nnoEEOQtkO+kUDKT RvegFrD4YrkTbaDOH/+mgYy+U+AZGVds3o/mJxaHrJRnRg5HntQ6VtxnTj/O9BdLf8liF9ECAaMcG lxjfCGiw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQBXX-0000mM-M0; Sun, 19 Apr 2020 15:07:23 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQBWK-0008Ap-E2 for linux-arm-kernel@lists.infradead.org; Sun, 19 Apr 2020 15:06:13 +0000 Received: by mail-wr1-x443.google.com with SMTP id i10so8824164wrv.10 for ; Sun, 19 Apr 2020 08:06:08 -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; bh=Y6PiqSVV9dpQAqOqd+uh/E8t5jyLRFjga9Ph1jhDag8=; b=FOV0ezYfjjl9Ks/imkXxFXr8IJNLzQ7xwIGz5OftsX4B5vGc3mutSwNxF4+k3rruRx mhqwouVVHCQI1zzVmlFUnANaD5qlC/XcxHZSsnK73DRZB0w9NxY2FaqPuas2f6beqtfW A9CSX+/O2lSNUzKnyhoT1mv005X/uD9AUhN+DV5GvIUDbI95k44IJI/15/3fsJAjTbLz ewBDortR1gTg2CD5bBHvWce5gplQNHJav2f9TaH44ROQVb6RIvVqCJFiK0KIohrswMpd gDk4tQs7rm4reCvV4J4hoDnnKX8cT2y7vnTW57C3dVB2iwIa9zJZm5aM2YsKvQHJ0jJN OiPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Y6PiqSVV9dpQAqOqd+uh/E8t5jyLRFjga9Ph1jhDag8=; b=UE9rsSzYMjuwgzh/wDpQgTB54Vd3Nxs/wFPP4+9xig2GOn0mbzINBNbl6CXkzpbzeY yWmJRfa2RgQAAz8N1gzNxbvQ9UnfoaPt2lYwrC/224MJ6L/WtRkZr7Pr8qV1nN98jiT6 Fw32dGR43uo5UVauI29RW+eX3syC9isnhVstV402YZPSTWOH7RVNXFcwTmUStKo8irTa NmNgFQJc3Wyn2SBcqRNzCwTJ8HYTh1Z65DFyx2bUe6Tjgc2cwUWYdbHQyGpMqWIkO5u4 JILUt/A385QmKgdNEabzvh7yZv885L0om111bn2wUI9I5JMvPJ3rcy11P9bNBurB13mG zwZg== X-Gm-Message-State: AGi0PuYOKiMXojNzGZd/cEZIVzISeZBWw3lg+yOf0R5nK+oVUMQ6diyh 8+dJFkgec7J+kwfh90FJVAzylw== X-Google-Smtp-Source: APiQypI3G+DRojbxMZCQ/3C6Vsl76B2MCQNsmSARPJUTNIz3W6+yGt8+Kwu0fi2IVqFrot5M1S+9Lw== X-Received: by 2002:a5d:4306:: with SMTP id h6mr13372859wrq.234.1587308767273; Sun, 19 Apr 2020 08:06:07 -0700 (PDT) Received: from lmecxl0524.home (2a01cb058702ff00947c0d9b78b8fa1e.ipv6.abo.wanadoo.fr. [2a01:cb05:8702:ff00:947c:d9b:78b8:fa1e]) by smtp.gmail.com with ESMTPSA id w12sm25948635wrk.56.2020.04.19.08.06.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Apr 2020 08:06:06 -0700 (PDT) From: Etienne Carriere To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 6/6] firmware: zynqmp: use SMCCC v1.0 helper functions Date: Sun, 19 Apr 2020 17:05:30 +0200 Message-Id: <20200419150530.20508-7-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200419150530.20508-1-etienne.carriere@linaro.org> References: <20200419150530.20508-1-etienne.carriere@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200419_080608_491970_403BCEFF X-CRM114-Status: GOOD ( 13.60 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:443 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, lorenzo.pieralisi@arm.com, michal.simek@xilinx.com, tee-dev@lists.linaro.org, Etienne Carriere , james.morse@arm.com, sudeep.holla@arm.com, richard.gong@linux.intel.com, jens.wiklander@linaro.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Change Xilinx Zynmp driver to use Arm SMCCC v1.0 helper functions and ensure platform consistency on SMCCC conduit method. Main functional change is that SMCCC conduit method for ZynqMP firmware must be consistent with conduit methods registered by PSCI device that is early probed. Another functional change is an addition info trace emitted by the device probe sequence: "probing for conduit method from DT.". Signed-off-by: Etienne Carriere --- drivers/firmware/xilinx/zynqmp.c | 87 ++++---------------------------- 1 file changed, 9 insertions(+), 78 deletions(-) diff --git a/drivers/firmware/xilinx/zynqmp.c b/drivers/firmware/xilinx/zynqmp.c index 41b65164a367..1fdc468c9204 100644 --- a/drivers/firmware/xilinx/zynqmp.c +++ b/drivers/firmware/xilinx/zynqmp.c @@ -63,51 +63,11 @@ static int zynqmp_pm_ret_code(u32 ret_status) } } -static noinline int do_fw_call_fail(u64 arg0, u64 arg1, u64 arg2, - u32 *ret_payload) -{ - return -ENODEV; -} - -/* - * PM function call wrapper - * Invoke do_fw_call_smc or do_fw_call_hvc, depending on the configuration - */ -static int (*do_fw_call)(u64, u64, u64, u32 *ret_payload) = do_fw_call_fail; - -/** - * do_fw_call_smc() - Call system-level platform management layer (SMC) - * @arg0: Argument 0 to SMC call - * @arg1: Argument 1 to SMC call - * @arg2: Argument 2 to SMC call - * @ret_payload: Returned value array - * - * Invoke platform management function via SMC call (no hypervisor present). - * - * Return: Returns status, either success or error+reason - */ -static noinline int do_fw_call_smc(u64 arg0, u64 arg1, u64 arg2, - u32 *ret_payload) -{ - struct arm_smccc_res res; - - arm_smccc_smc(arg0, arg1, arg2, 0, 0, 0, 0, 0, &res); - - if (ret_payload) { - ret_payload[0] = lower_32_bits(res.a0); - ret_payload[1] = upper_32_bits(res.a0); - ret_payload[2] = lower_32_bits(res.a1); - ret_payload[3] = upper_32_bits(res.a1); - } - - return zynqmp_pm_ret_code((enum pm_ret_status)res.a0); -} - /** - * do_fw_call_hvc() - Call system-level platform management layer (HVC) - * @arg0: Argument 0 to HVC call - * @arg1: Argument 1 to HVC call - * @arg2: Argument 2 to HVC call + * do_fw_call() - Call system-level platform management layer + * @arg0: Argument 0 to HVC/SMC call + * @arg1: Argument 1 to HVC/SMC call + * @arg2: Argument 2 to HVC/SMC call * @ret_payload: Returned value array * * Invoke platform management function via HVC @@ -116,12 +76,13 @@ static noinline int do_fw_call_smc(u64 arg0, u64 arg1, u64 arg2, * * Return: Returns status, either success or error+reason */ -static noinline int do_fw_call_hvc(u64 arg0, u64 arg1, u64 arg2, - u32 *ret_payload) +static noinline int do_fw_call(u64 arg0, u64 arg1, u64 arg2, u32 *ret_payload) { struct arm_smccc_res res; - arm_smccc_hvc(arg0, arg1, arg2, 0, 0, 0, 0, 0, &res); + if (arm_smccc_1_0_invoke(arg0, arg1, arg2, 0, 0, 0, 0, 0, &res) == + SMCCC_CONDUIT_NONE) + return -ENODEV; if (ret_payload) { ret_payload[0] = lower_32_bits(res.a0); @@ -287,36 +248,6 @@ static int zynqmp_pm_get_trustzone_version(u32 *version) return ret; } -/** - * get_set_conduit_method() - Choose SMC or HVC based communication - * @np: Pointer to the device_node structure - * - * Use SMC or HVC-based functions to communicate with EL2/EL3. - * - * Return: Returns 0 on success or error code - */ -static int get_set_conduit_method(struct device_node *np) -{ - const char *method; - - if (of_property_read_string(np, "method", &method)) { - pr_warn("%s missing \"method\" property\n", __func__); - return -ENXIO; - } - - if (!strcmp("hvc", method)) { - do_fw_call = do_fw_call_hvc; - } else if (!strcmp("smc", method)) { - do_fw_call = do_fw_call_smc; - } else { - pr_warn("%s Invalid \"method\" property: %s\n", - __func__, method); - return -EINVAL; - } - - return 0; -} - /** * zynqmp_pm_query_data() - Get query data from firmware * @qdata: Variable to the zynqmp_pm_query_data structure @@ -790,7 +721,7 @@ static int zynqmp_firmware_probe(struct platform_device *pdev) } of_node_put(np); - ret = get_set_conduit_method(dev->of_node); + ret = devm_arm_smccc_set_conduit(dev); if (ret) return ret;