From patchwork Tue Apr 21 16:38:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 11501951 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 04243112C for ; Tue, 21 Apr 2020 16:39:52 +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 D28F2206E9 for ; Tue, 21 Apr 2020 16:39: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="M0G00dek"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="WPDNYXWH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D28F2206E9 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=u+y8U9v2reft2wRQqmixgRxvdeKfZUoygFcMbLtYf58=; b=M0G00dekilxO7/U2Fem76hmVjO CZpyoPmq58ZB3gq0HZgddSg+l7g9S6vhe/KO+4E8U684te8gwZs6aTXdvfam0jL1QIqThgjv9OO9O PYXJqVC+O1LtjBY8YEupxWIRDaJanEIsNTHjDY5O35qLoq25y/vKWVUa7CYOLmuntKEJCEY98S6lb P2wlOF5dpatFv4mk7cOP8aXQE7mKJ6oBopD2ADZq5WAwTGGXrFezujeSXSXE9jGDjXN1yBeU9x28k 9faV9+vmhTdeNfqbQ4YURJquJByvhjjGP0Do4LwoSlBeQoJIK92eiKhiOFqb1mGdonLmgfp1M1wv2 Br9Y8UvQ==; 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 1jQvw3-00043G-Ht; Tue, 21 Apr 2020 16:39:47 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQvvV-0003eK-Dy for linux-arm-kernel@lists.infradead.org; Tue, 21 Apr 2020 16:39:15 +0000 Received: by mail-wm1-x341.google.com with SMTP id u16so4449080wmc.5 for ; Tue, 21 Apr 2020 09:39:12 -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=Eau4GvxiE24fkjahKYUDr8wNyO0rsEsKQPM3KHizj2U=; b=WPDNYXWHvKnOfuQzNmWQPcVY9jDjXiU04u1rf3MwOZEu24fKR/yXuH+tD3Ta0ev3A8 zUCVQFKGbfae1+Pj8aiZZb22Zw7S1jdvBO6pKXhfZSEb1FqPqvUto2gJPwkqShp1pSL2 9eDRxZ6qsauWGlpyY7WyTvEzbvNfUCk5DwPzoHAZcwyKISN/xc0rmXWDSzMaDxn9JUFU A3JFRPdZtaB+p0MoifPrB3HrAFpghDSIU7aRSBlUCaPSjBBMm2VZ7dNXXVcHLvvvf8Y1 lbBnEcJLvUPYbU1MhG6OI1aUrpIBQ0nKHgJS2GRV9vLslLRyoUACQftjkrONj7qYpeZm o4XA== 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=Eau4GvxiE24fkjahKYUDr8wNyO0rsEsKQPM3KHizj2U=; b=IFPCm/J+444/OdfzHj1D7UgdIRim1VrlnHA1tCt3yId6gwYDTWzm29bgOXdS7yNR5O +UP8pVV3o4pzmUOi53XGtccPWHp9iDDlDENiNO4W7+M3eHy8lyFSLPZpF293qU2isi/h zsW9EEf9liLSsgnZVUZvgF40WBnZM1+DjVomiICS/JxuhlRZx7Wr5e5yYmSy4QCMXWEX vx2ATW3MkhjEhxuvFLwRw1S7T3sGt05JN3KnwqcqpiXDC4s4LYbga/JD8Vh0aLpYyjYC dvDfZ6qLIz71bFYsPxVw5Eml6IILxPOB/dbMtRkbylg2jzzUixeL/4Ix60HbdmFbIJFU Xisg== X-Gm-Message-State: AGi0PubDJbnmo5rfYJHOdkwnTocsQS/RtQ50GO+AQYZGJBU2CKqIMCWh PEdLZncOaEIO8E7DO2QxN5XyfA== X-Google-Smtp-Source: APiQypK69N12gmzyYPuZBpL/0+jjBf+e8I52SRG0ZBfH6+Ap2vUEVMf5dGHKOWTOq+X4f7TZhEK4TA== X-Received: by 2002:a1c:23d4:: with SMTP id j203mr6127018wmj.49.1587487151475; Tue, 21 Apr 2020 09:39:11 -0700 (PDT) Received: from lmecxl0524.lme.st.com (2a01cb058702ff00947c0d9b78b8fa1e.ipv6.abo.wanadoo.fr. [2a01:cb05:8702:ff00:947c:d9b:78b8:fa1e]) by smtp.gmail.com with ESMTPSA id q143sm4389055wme.31.2020.04.21.09.39.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 09:39:10 -0700 (PDT) From: Etienne Carriere To: linux-kernel@vger.kernel.org Subject: [RFC PATCH v2 1/6] firmware: helper functions for SMCCC v1.0 invocation conduit Date: Tue, 21 Apr 2020 18:38:06 +0200 Message-Id: <20200421163811.22720-2-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200421163811.22720-1-etienne.carriere@linaro.org> References: <20200421163811.22720-1-etienne.carriere@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200421_093913_467155_80AE30BA X-CRM114-Status: GOOD ( 20.65 ) 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:341 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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 based on existing arm_smccc_1_1_*() helpers but for drivers that interact with a firmware supporting Arm SMCCC specification v1.0 but not v1.1. This change allows devices not defining a SMCCC conduit method to leverage the conduit defined by early initialized PSCI generic driver when secure firmware does not support SMCCC v1.1. This change allows devices to ensure consistency of the conduit used among drivers defining a conduit method. Indeed, at runtime, all devices are expected to use the very same SMCCC invocation conduit: HVC or SMC. Signed-off-by: Etienne Carriere --- drivers/firmware/Makefile | 1 + drivers/firmware/arm_smccc_conduit.c | 148 +++++++++++++++++++++++++++ include/linux/arm-smccc.h | 106 +++++++++++++++++++ 3 files changed, 255 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..fd402fec89dd --- /dev/null +++ b/drivers/firmware/arm_smccc_conduit.c @@ -0,0 +1,148 @@ +// 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..2da2b4bd3985 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 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 "method" + * 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 "method" + * 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 conduit) +{ + return -ENXIO; +} + +static inline int devm_arm_smccc_1_0_set_conduit(struct device *dev) +{ + return -ENXIO; +} + +static inline int of_arm_smccc_1_0_set_conduit(struct device_node *np) +{ + return -ENXIO; +} +#endif /* CONFIG_HAVE_ARM_SMCCC */ #endif /*__ASSEMBLY__*/ #endif /*__LINUX_ARM_SMCCC_H*/ From patchwork Tue Apr 21 16:38:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 11501953 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 4060713B2 for ; Tue, 21 Apr 2020 16:40:21 +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 0C225206F4 for ; Tue, 21 Apr 2020 16:40:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="CrVwQFXh"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="wVPOFqok" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C225206F4 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=rzgMxc09z2X7aWlGW6K2UeGUgVhvoiKN79ldVGkxRFA=; b=CrVwQFXhbmyx51lQQlAcK9djb0 7CcH+IWZ/c3AY1Gw1xA00ThwhIKm5az73kCR8oodgK8vQdeZmjzGr0HdNhr3NuKVK3rBbZk9jjYwu LIYWicMoGTyKLIcCg4oFuaEf+3os/tQEW/6Vi1KWLR/5dmhbKhjvZxFilvgvoloPH0RC2cYZ46D0S qzq5zsfxlJfV23kkHezYa5rwXnjtZM/AZHH21YgkMyT+tF4wHAlol0l1RUMrLdXbCNOO627dPykgt pPHT+rpgYZVCmW5dbCzz3/6nWdAckbblnL7FaZOLZgDclRmA7kVDwUvUWbfb/Xp9tPXrW2OfeIa6u OhrHGf0A==; 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 1jQvwS-0005AB-OC; Tue, 21 Apr 2020 16:40:12 +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 1jQvvW-0003ef-1g for linux-arm-kernel@lists.infradead.org; Tue, 21 Apr 2020 16:39:15 +0000 Received: by mail-wr1-x442.google.com with SMTP id b11so17172055wrs.6 for ; Tue, 21 Apr 2020 09:39:13 -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=T4RV+W5A0WTJfrEJC2MWNCKclGhSBwoQ8rtDkcyUPgc=; b=wVPOFqokqQHtu5wiekfE2ea3FnkoODS0MoRFNeU6Cy8cLP/Gka9g3IOQyGPya52nKW dtHlqR1XERO8CxEXPHnzUq8rNDxWO+sQbF1SJ5fgyxwTtDagIWKtuEXoaBR6CRTISQUi Bmb81B7Zff+oZFfXP+cA4vI6jYlBN3fuJrKlTipGYZcQVIi5rXCcNAH971uPVW5808p1 mkB5w4uWieapIl3w53xy1k+78Inex2fsGyWiE0/cCZ+zS7wh3zOWMDo3SbKJ3CttXl/U RJnXtJwvEJ7fkSeUEVCpkYuRGEnEj7U90BONzq4y2yLFy8mbtjoTrTY5u87++tbqf1sj Fzxw== 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=T4RV+W5A0WTJfrEJC2MWNCKclGhSBwoQ8rtDkcyUPgc=; b=UhSMBBvZNci7NWDmlPNmXwJ2gvniTh1ABrM9qg7p+kOyrkgr+P6qYK5kvtwyL8J/eL Wo9ZBQOKxSv3Bw8tBCMquWU5EsHzhEfJ63roKlNFrEeeOQeWZJSX622UbSvv/0uBimdU 2qnpKhIFumUPD4gcfNriJet4/ePAvyrTfEcVxesH22XmrOhAtEpzafOTvRgl02nkxdlY oGbnYdwSziaSEKFa9qfCF4HtusCslcZ7468vU+avrwN8XYBoH9fvulU9vI9vsVRsrHyD cyzOU/RBkOHLdwqIXZk0MmBWlFjlbH1mBYthSOBy+OO3XSuO1jaf+QcHvNuph07QdPfT Ss5w== X-Gm-Message-State: AGi0PubghsESp6JRJpzGMZIBSqp5rrIfrYsT6iDEwI1Nm55SJ9WXK+U/ TFSUagD+aBUyKy0VpdyvNNIeFg== X-Google-Smtp-Source: APiQypJB4EHuOBE2fjZUyPlp6XB8p0fICrWtA3qUbKT84ynEufetpvCrJ1PQHxE7SnDYkjlldnfmbw== X-Received: by 2002:a5d:66ce:: with SMTP id k14mr26717757wrw.73.1587487152764; Tue, 21 Apr 2020 09:39:12 -0700 (PDT) Received: from lmecxl0524.lme.st.com (2a01cb058702ff00947c0d9b78b8fa1e.ipv6.abo.wanadoo.fr. [2a01:cb05:8702:ff00:947c:d9b:78b8:fa1e]) by smtp.gmail.com with ESMTPSA id q143sm4389055wme.31.2020.04.21.09.39.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 09:39:12 -0700 (PDT) From: Etienne Carriere To: linux-kernel@vger.kernel.org Subject: [RFC PATCH v2 2/6] firmware: psci: set SMCCC v1.0 conduit and use helpers functions Date: Tue, 21 Apr 2020 18:38:07 +0200 Message-Id: <20200421163811.22720-3-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200421163811.22720-1-etienne.carriere@linaro.org> References: <20200421163811.22720-1-etienne.carriere@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200421_093914_103510_EA261275 X-CRM114-Status: GOOD ( 14.38 ) 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_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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 for SMCCC 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 Tue Apr 21 16:38:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 11501955 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 54D3F13B2 for ; Tue, 21 Apr 2020 16:40:33 +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 30C23206E9 for ; Tue, 21 Apr 2020 16:40:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="hL4MRwVX"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="vOVyM4Zh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 30C23206E9 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=ToOXzPgsGrCQhEZ7449JmVUfxSvVS9jqnLoDDbzqSoQ=; b=hL4MRwVXLI3EAxGMiFof+6YujX 2GXoin+rjgwSDwdHNazBuGZr5eTM2txxDOQJPXqtQhYQ/6tmhH5l9mICkWy8hFh5oCAiBdoFXInla 8bGg7YORVqW5nw1rlfSdkTbjJGrk9y9klCDgacgGna94vzQhZ2NEGJo6x8MXP9n5cvmt7Lm6Ok4S1 E4JSbu4z5IcaxuYUiy+gPKdW8WQI204cb7NX/mq/x9M02TRXPYLSto/Cgf+li3hffaNv5XwA8dmmy 8/SA/CezmisGFG3N3ZlcOOm1Ggr9UntoCgtDjhlZTrO7D9I4XC6+hcYo8FV10RdZoZgqbNB4skVgz v93zBYiQ==; 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 1jQvwg-0006tI-Ij; Tue, 21 Apr 2020 16:40:26 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQvvX-0003fR-E9 for linux-arm-kernel@lists.infradead.org; Tue, 21 Apr 2020 16:39:17 +0000 Received: by mail-wm1-x342.google.com with SMTP id e26so4281349wmk.5 for ; Tue, 21 Apr 2020 09:39:15 -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=eNMW0723PRTk8SHiVowiqXotmpYrzhuUlH7clt9K0M4=; b=vOVyM4ZhNMPbc1/jcM5e96H2h6ACrZJBl0g5HozhzJCNQdqCV2hiBp8dhDJbPntQXT Yf+EZUxPInG4zWowEWt5iRLJdqREC5TrgxzY11jEXkoqRtQcfeIvpIOmhyYkrUv84D3P a3IuOhsMfVmvUk7+/65QQUV0Rv1MHi+b8mDT6K6y2bD05qROshuLEZOgRQBpSM6SvH0B K7Irpxn+s4RCFyJO1I9w8RekmnMDWbtIyHaNuxq6EWwdv1sphZkMZSNtl/FkTd2CTZqn TkX9BK4Wx98oOTZiAK4ANvDJ9JrzNrQL4YpzUizLcGexhAKCu5AzopsgZv932S3e7NRm KGig== 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=eNMW0723PRTk8SHiVowiqXotmpYrzhuUlH7clt9K0M4=; b=HxxKfOzj3g7eymtlzSnBAyaULG3celD3tjyIyJ9KLbBBwp0Pn8w9IDdlswfeaZSDED OAHRd/bAL2qyYwxFjV+aTpIiqAedWXMsNwU8wC4vOdZlRME+IapQ+umjgyIoMip/XlVT YX10+fz0s9vtULtlO7KBfal18GDJC2yukbCbiMChga9EXmYUNkG8LHOgI7eZHsSY1Wm4 8DOuVyV17zOI+ZSZp5Jh5DbieNndCQAdz43sMuaimXdfw3Iy7KNUDur7fYxpZE9JMg7K vgiMYNhb53MkStqBtDHXz2wxvQzO0Og4GmbBmpgthDWqRI6UW2fE0fGRZmA38g9wdtpy FWRQ== X-Gm-Message-State: AGi0PuYwZ4UA/Z5vMHIs44z8YBG5MfXguHIdxtmEOQE6QJzd8oH3RIo6 LaKMv8BdlPf/gHkEbuyO5xHUwA== X-Google-Smtp-Source: APiQypJbAFp4oFhCH7gC6OJ8uPpIm2eG7o9NA/Qwy2WOXRcDAKfuF5xrPsRLCBOLf647bj6qrOnNnw== X-Received: by 2002:a7b:c1da:: with SMTP id a26mr5446790wmj.125.1587487154078; Tue, 21 Apr 2020 09:39:14 -0700 (PDT) Received: from lmecxl0524.lme.st.com (2a01cb058702ff00947c0d9b78b8fa1e.ipv6.abo.wanadoo.fr. [2a01:cb05:8702:ff00:947c:d9b:78b8:fa1e]) by smtp.gmail.com with ESMTPSA id q143sm4389055wme.31.2020.04.21.09.39.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 09:39:13 -0700 (PDT) From: Etienne Carriere To: linux-kernel@vger.kernel.org Subject: [RFC PATCH v2 3/6] tee: optee: use SMCCC v1.0 helper functions Date: Tue, 21 Apr 2020 18:38:08 +0200 Message-Id: <20200421163811.22720-4-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200421163811.22720-1-etienne.carriere@linaro.org> References: <20200421163811.22720-1-etienne.carriere@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200421_093915_472685_5018F9DD X-CRM114-Status: GOOD ( 17.57 ) 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:342 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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 functions. No functional change but initialization traces that are changed from pr_*() traces the device dev_*() traces and info level 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 Tue Apr 21 16:38:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 11501957 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 5E610112C for ; Tue, 21 Apr 2020 16:40:50 +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 3A813206D5 for ; Tue, 21 Apr 2020 16:40:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="HmkdFzs6"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="cOoLwi1n" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3A813206D5 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=3Cp9AsRVlkiRnCCpdHJR+8VVyTtZQsMD4L4BxfAMuLc=; b=HmkdFzs6+52JDdAksYnKyBt1KL YrKANcgkQ3StTvUdjfcYSg0iyNFDa7bV2/Ekzmtpr0dxYWF09dlQKcArv4ZkjlUG4NF1R0oF6Bz2G ZlLCJuZByzsuyJSUOPX5S26yia4QSyrywqdSrpJf3kIeqDl4b2VUs+PiTJ0Of8+YIipsmHqozjaTy 1POXk5X3JwCXeH2ov9a4rwoirswLJfDN+CQOc1N7zmM/QIfTMhMSogRip9ftJjgplt+HDuCAF9Onp 5GAi2kr+aDhrVyWKpyJvBVcKBfR8D/aj2EzpX7J/9XDvlNyfWR2M1J7fSYh1C6jGUX2NtQ1gpbS3I fgvjMRHw==; 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 1jQvww-00078M-LW; Tue, 21 Apr 2020 16:40:42 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQvvY-0003g0-O8 for linux-arm-kernel@lists.infradead.org; Tue, 21 Apr 2020 16:39:18 +0000 Received: by mail-wr1-x441.google.com with SMTP id u13so17200722wrp.3 for ; Tue, 21 Apr 2020 09:39:16 -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=XETYSm4uP7bMLvF3XXve3QfqSUan+bhGi6fMh9AIGS0=; b=cOoLwi1nBGkaJzbd6hFSTZUSFb6exxh61seT1TfNMjcSgFd8lo7YN7qz/tpO60L9/M Enc6SKK9s4eyB7pqhh4z8hIffoHVMO9dwt0fi/08ZFN/VSl8Lzpg/90FDl3f/VFiyfAF c4EH2nDejCuYKUj6Hv0OpMGKkubaIBo+fW2VVsrCciiZ9X8fBOgkxz1B+N2ifBQUFup+ 8Mb1yCg+IGBYHMqLTiO1kZDWCKsNLDM9FySXnJ9W88g387XLIkXzjDfSiXwNTZpF8WB8 S/73ElPfyZCiN9FkiyxCEcdepela8wHg29ck/wY27zvDZjjGIxCqeUYxq4+64Uy4xO4b JqMg== 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=XETYSm4uP7bMLvF3XXve3QfqSUan+bhGi6fMh9AIGS0=; b=bg9hT0J5fpZItL/PkL4X/dhFJp41qfjdplSotc4w2ctUzmyEDq3QVU8BctUFj+n+3d kV4gEO7sKysQmrqDixP3FputxXQV4e+L9f7/n2sk9HB4GxOQIWirAe0laTyJ3pgiBZVA 1MvYnpsVWjro8GX0N0/vVgtUrU7Nh/tKeFK8akehYFbCTqVb4cVlmBZHGXtelWK3N0E+ ekfKNJl7wsP/z+FaqgnANdD05cA0PxgrFm62tj/hevUYRuhOmE50pv5zAiapuo0ZzWHj qVRV848XjyqWwwqtVdP6pIMb4dapetMmxRN9F1mxFqxiAl1Tm0Ns72P5zePdky9M1VG9 2SVA== X-Gm-Message-State: AGi0PualyYw5gw9sDO87bPpagxspVHNlCx7tFsC0VjOp/2SKXYnWWdn2 C3eBaJoKzR5/uJs1gvVoV79R2g== X-Google-Smtp-Source: APiQypI7JT3311pD+psUEN7y085u4go8Aun9MwUBdg5ZI7jJih77ao3oeCj84EnxhEfJUsEA84dO3g== X-Received: by 2002:a5d:4109:: with SMTP id l9mr24048869wrp.300.1587487155355; Tue, 21 Apr 2020 09:39:15 -0700 (PDT) Received: from lmecxl0524.lme.st.com (2a01cb058702ff00947c0d9b78b8fa1e.ipv6.abo.wanadoo.fr. [2a01:cb05:8702:ff00:947c:d9b:78b8:fa1e]) by smtp.gmail.com with ESMTPSA id q143sm4389055wme.31.2020.04.21.09.39.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 09:39:14 -0700 (PDT) From: Etienne Carriere To: linux-kernel@vger.kernel.org Subject: [RFC PATCH v2 4/6] firmware: arm_sdei: use SMCCC v1.0 helper functions Date: Tue, 21 Apr 2020 18:38:09 +0200 Message-Id: <20200421163811.22720-5-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200421163811.22720-1-etienne.carriere@linaro.org> References: <20200421163811.22720-1-etienne.carriere@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200421_093916_804507_BEC07F46 X-CRM114-Status: GOOD ( 18.24 ) 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:441 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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. Main functional change is that Arm SDEI firmware driver can find appropriate SMCCC conduit if it does not define one but another device as the PSCI firmware driver has set the kernel conduit for SMCCC calls. Other functional changes are the trace messages emitted at device probe time that are 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 Tue Apr 21 16:38:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 11501959 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 7A93413B2 for ; Tue, 21 Apr 2020 16:41:10 +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 C21E2206D5 for ; Tue, 21 Apr 2020 16:41:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="klV1u5ee"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="xOgAT3c2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C21E2206D5 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=6p+qtlNFjmicIdK+k7D462UukXINM9aa+bMQNWaSev4=; b=klV1u5eevSgveDsHme+fWg5XlV tP7p/NbM8IL6ZvJxQmWu+Y97ZuB23Is5uwnvJBJ0wbxS4/uajYl6jUa9LCGXwLwzbZajiifx1F5my zH3CZuAZzzdKyP0qlCJmXXqtCHAnvqoHAb7IG+jm9/yzmGUfw9jlvi5xRSNWSjmf1Sj8xbOHTlmLd X3b0PGpxSnqWMErnzLW4TbAYIRxlrlYKc7Kl4FuGXUhYQZWYF5kmiSvr4QhG++o1aKrQnrfMgWZEI xRo/vHA9eT+7WIjZXU4oP9mgaWEfltJfC5VjCKC6qslG0yv9FeKSD3IeJPHJ+4WhMNbwAWeIaYJrB 2MLh3KRA==; 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 1jQvxH-0007PT-1j; Tue, 21 Apr 2020 16:41:03 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQvvZ-0003hX-RU for linux-arm-kernel@lists.infradead.org; Tue, 21 Apr 2020 16:39:19 +0000 Received: by mail-wm1-x341.google.com with SMTP id r26so4487405wmh.0 for ; Tue, 21 Apr 2020 09:39:17 -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=sKTMTyV6o0e+hE/bx04wYYAqYgApZOSrkknoj7MN0Vo=; b=xOgAT3c2LG/MUAXQCPRvCO5Eh6W+IH4Eqt7fpuFUCGa5jMRs2/QhIj3UPqzvYa99XR TvdJ7L+d1mDnCn8wz6rdUt5QVHKWT8FuEhHBrIifnRZIRBLR/kMoDNV3f+Fm8r73S8z9 Vjc3lcdTBG4IUUzpSrGPSzN51l+w0IGhsFDTrQAUk4Uh90m4gsfxG9Y3yXCzp5vjryew e3152pIIocOb1rajAAy/xHNLb8YLYB0x/e1mxxa2yhAft5lHSj6dq6L1sqsQLpqlkQ48 MF2ztXPSoG1A7tYcPjHw2YVaHzq0uAF7BUycI/xlKW9ApiLyTL5dmVclvwnGnveXO7BK Vq3w== 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=sKTMTyV6o0e+hE/bx04wYYAqYgApZOSrkknoj7MN0Vo=; b=m5uK17Jx0i8f/VEIfQtP03o6gZOH4TamddxYVnG5WyBA8HKbovhbseg+IbUlkRujkb 4Gjuq4gdDkEseVsQ20H61SggOd07BmlfbBSnFm0eRI3+MNSRw2maZlbTO8GnqSRmDWkY jWrD101fRXcF9js1CM2AP6eQG+Jz8ULI6ye5dLhjnZBeptVFMlIVlgUExqVvWyvXAi/M HBR89E/XOjdW8VmEsHe6VKSH4OlAQcxJ6/uO9SxBrlsaB2ZAPzKmFJUjN69n5dkolz/J WQkeJQhJMXTbV3c8YdGTYeVBHrIGggdkgovl6Ox4/tf1VAfW44nxKYWMicayR2KaIUd9 pR7w== X-Gm-Message-State: AGi0PuaDDRts885CPoU9Dl4kX3pZ/T2wBDgzsXu3tmvhAhL6f8wZ6um1 3CWS3Qi6erwoIeZpiWGiKVHt3g== X-Google-Smtp-Source: APiQypKWuem6B271D6t/BnwUQw22yIwGDbkhfre7hmxMRMdRAg7cCIsRTM2j44+gqqZxkZ5Lbv4cpw== X-Received: by 2002:a7b:c941:: with SMTP id i1mr5346795wml.132.1587487156496; Tue, 21 Apr 2020 09:39:16 -0700 (PDT) Received: from lmecxl0524.lme.st.com (2a01cb058702ff00947c0d9b78b8fa1e.ipv6.abo.wanadoo.fr. [2a01:cb05:8702:ff00:947c:d9b:78b8:fa1e]) by smtp.gmail.com with ESMTPSA id q143sm4389055wme.31.2020.04.21.09.39.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 09:39:16 -0700 (PDT) From: Etienne Carriere To: linux-kernel@vger.kernel.org Subject: [RFC PATCH v2 5/6] firmware: stratix10: use SMCCC v1.0 helper functions Date: Tue, 21 Apr 2020 18:38:10 +0200 Message-Id: <20200421163811.22720-6-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200421163811.22720-1-etienne.carriere@linaro.org> References: <20200421163811.22720-1-etienne.carriere@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200421_093917_905307_B8A31399 X-CRM114-Status: GOOD ( 14.56 ) 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:341 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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 functions. Main functional change is that SMCCC conduit for the device is ensured to be consistent with the method used by PSCI firmware if the later is enabled. 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..484f87e14ae0 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_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 Tue Apr 21 16:38:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 11501961 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 33084112C for ; Tue, 21 Apr 2020 16:41:39 +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 0DC93206D5 for ; Tue, 21 Apr 2020 16:41:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="lTYZ6xCr"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="YsY5Mtcy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0DC93206D5 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=N2hNcgGRmHtlAJaGu9W+Mydh22mZGcGp7PtrEj/8Sz0=; b=lTYZ6xCr4z4ViFD0tRKNPEzEVp klDyTH8IGSGq1OIrcOhieQpMZPz59ug8m6WZwqkYURPbPORP/HSSaLTMqZFGKNRJr4vb11Y8SYXhs hIXXn0O09EpPhKS0lQmjXMtf7ZQnC0m5T7W58d1KC8N2DIVYnu8t5T5gSZXvxeNVWsevGWpdgzRID 5YPKyg1dJ0XF7MRLgpHma4h10NavQShQRtaFI0nyRzoMAjUSvUwqQksQ+SZ6Mj1ElkYTLER+8lYZH q4TuA/5ZtETyRjZY4JuRUJh3tQNOOvJT54oLRS3wrMp4Bs0dKgDJYLFbRzQ6oevlaY1LWGYUebuHZ VTX9YcAQ==; 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 1jQvxk-0007p1-G9; Tue, 21 Apr 2020 16:41:32 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQvvb-0003j2-77 for linux-arm-kernel@lists.infradead.org; Tue, 21 Apr 2020 16:39:21 +0000 Received: by mail-wm1-x341.google.com with SMTP id 188so4307938wmc.2 for ; Tue, 21 Apr 2020 09:39:19 -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=FwFO/u2aeUUzfosuhBTWahZc0BcOCP6Dfva7x951Kew=; b=YsY5MtcynhLjmd4f5oPMFhzDUUL//yZqTVSXr/da17ytsjb18WOt73a2TR/vR9Xx7P gppN9LpWP/YEV7OBFcP72H8yYBpKq7lI4GH3eM22Tvobvce4BUEIAbwVjrmDRHMkwMxt X+TRM4z001H2b8vQaCwc1UeAtvot0XhM3DmrY7dGZv+jhxr1DvK329tt5RvM4tkHx+CZ xXLa71dgImb57W+R1nncyaP/3JdyAH88ME/y/unJ4vMQPpO3PX/iTUdIgc2sOo58iO0Z mDwgQEoZecgYjYm8SizcoapcKNC2MGwkE8QCGvZK79GBiFlU9LWQ0SHGdmt5QTBM6IAd /6bA== 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=FwFO/u2aeUUzfosuhBTWahZc0BcOCP6Dfva7x951Kew=; b=nAQjoKhZv3rjgvytSso7p6302TK/rXctOFMbgsLhJB8gsNetGz9bXbxfZJ1Qusb0C0 bhS+KWwNba/LSGGnxpCmJjc49DTXcyN5U06H7pI1hNX4/lOnqMHomleiXAQGxF1YO38s 3nnm3Q0/CDlW0q0Y9pj2ia9Ga3GxyOmab/oNLLOgSequ/H9jZX/q85qgg0IBxsQ0AdMZ 5VSfEX12SWXd7hJB2vCfSsoThUtBe2elXJ57Csy+nvVQL2UmQpIT2+nzWB5RB54QzjTm tAEbqT4It8hLv8Rd1qu86rCUKcTkucvFsSM91ajv/QGqKR+A6XBSnjXEhRJIJiT2twti qB5A== X-Gm-Message-State: AGi0PuY1DbaKhf1AQIyVWJ9HyKFUbFn6NVdZQdS7ccjX45xIFsFia+ep /9bZN1JHRIDZzJ9sU0lIJW4ocw== X-Google-Smtp-Source: APiQypIxKMzeiiJWPN1V8wijRp5361DgD4XkoZLFBW75v7EUbfB74QMNUxM0q98bebRI/tDk5G6hzA== X-Received: by 2002:a1c:b38b:: with SMTP id c133mr5628173wmf.24.1587487157942; Tue, 21 Apr 2020 09:39:17 -0700 (PDT) Received: from lmecxl0524.lme.st.com (2a01cb058702ff00947c0d9b78b8fa1e.ipv6.abo.wanadoo.fr. [2a01:cb05:8702:ff00:947c:d9b:78b8:fa1e]) by smtp.gmail.com with ESMTPSA id q143sm4389055wme.31.2020.04.21.09.39.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 09:39:17 -0700 (PDT) From: Etienne Carriere To: linux-kernel@vger.kernel.org Subject: [RFC PATCH v2 6/6] firmware: zynqmp: use SMCCC v1.0 helper functions Date: Tue, 21 Apr 2020 18:38:11 +0200 Message-Id: <20200421163811.22720-7-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200421163811.22720-1-etienne.carriere@linaro.org> References: <20200421163811.22720-1-etienne.carriere@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200421_093919_375801_28451208 X-CRM114-Status: GOOD ( 13.91 ) 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:341 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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. 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 in case the later is enabled. Another functional change is an additional info level 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..f2172978ed4d 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_1_0_set_conduit(dev); if (ret) return ret;