From patchwork Sat Aug 29 17:09:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 248712 Delivered-To: patch@linaro.org Received: by 2002:a92:5b9c:0:0:0:0:0 with SMTP id c28csp2036519ilg; Sat, 29 Aug 2020 10:09:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQD8ONdah7HlKSfGM9uwMYLNnVVj66+uFyp782aiZ/4rKDoTW/PVSrGi5Ky/eSrtUjjvT9 X-Received: by 2002:a50:baa2:: with SMTP id x31mr4217144ede.330.1598720983701; Sat, 29 Aug 2020 10:09:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598720983; cv=none; d=google.com; s=arc-20160816; b=fFn08uzaKt94rYEVjWCgGfhebhZHIh6a0J3cj64Wm09WldESvB7jn7vul8rj9EHlrZ +Il0Xq9V2qxiFvTGQY0aS6GW4jZMNDBnjottjAWYxe+T8HeMsaAHWA8y3Pd1J8gOnS34 4hfcZlE8ru4MPZun32s0R92z/LmnqfRELBRuZcOp/wTqV4BQlQ0ZVs83wLmu3gEtfbwd DaJ7f+PTZHjpc2yvrJw1ElSiptZZPe8wn95fIqNwjPcAYrLuiYWH7CdA39uQozvCe4Zg o92ZSkCL/fRdv9vMeHWkPaDQfZCgopNNN7J9iFRirVEqaoOOOJDtTUzA2M67vaM6NR3B y1BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=YS45i5rS1zi9yAF6f/keE5LumxRlaU7YQuvk4gcY80o=; b=VkLxGFl45jR80512CWUg6F7yuZ3Sbkcmtx1PjiDzftcot+7RXwJ583AmvcJVmk0lwm EuWYxJ3pi/5SFQxObKAjvISX3lHlJNalyazxMdVopQTM0UqwN6CBeiXUxd9DlivnvnpC Rp1JMfZfMjaCXxf+ARHr3fM3dhtSoSPwDuKjlMQAwdcffQVAejbBG8xFWBAksawWxn8s hxCcHdqCOg7G1jFshDq9Sm7Vn8Bx4GZ/1eH40x7mAFH+6lSbDiyvdJ4IMxIyn1NFcd09 UU4dFQKbWtSn8Qy2X84gW43nxXgJzgoqPPaD2b+NEgpzZndHIXbRkUiAGwcwEm2oU26w 3wVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d22si1952640edz.234.2020.08.29.10.09.43; Sat, 29 Aug 2020 10:09:43 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728452AbgH2RJm (ORCPT + 6 others); Sat, 29 Aug 2020 13:09:42 -0400 Received: from foss.arm.com ([217.140.110.172]:45100 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728471AbgH2RJl (ORCPT ); Sat, 29 Aug 2020 13:09:41 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6C0A7101E; Sat, 29 Aug 2020 10:09:40 -0700 (PDT) Received: from usa.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6CCBA3F71F; Sat, 29 Aug 2020 10:09:39 -0700 (PDT) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Cc: Sudeep Holla , kernel-team@android.com, Will Deacon , tsoni@quicinc.com, pratikp@quicinc.com Subject: [PATCH 7/9] firmware: arm_ffa: Add support for SMCCC as transport to FFA driver Date: Sat, 29 Aug 2020 18:09:21 +0100 Message-Id: <20200829170923.29949-8-sudeep.holla@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200829170923.29949-1-sudeep.holla@arm.com> References: <20200829170923.29949-1-sudeep.holla@arm.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org There are requests to keep the transport separate in order to allow other possible transports like virtio. So let us keep the SMCCC transport specifi routines abstracted. It is kept simple for now. Once we add another transport, we can develop better abstraction. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/Kconfig | 5 +++ drivers/firmware/arm_ffa/Makefile | 1 + drivers/firmware/arm_ffa/common.h | 4 +++ drivers/firmware/arm_ffa/smccc.c | 54 +++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 drivers/firmware/arm_ffa/smccc.c -- 2.17.1 diff --git a/drivers/firmware/arm_ffa/Kconfig b/drivers/firmware/arm_ffa/Kconfig index 261a3660650a..5e3ae5cf82e8 100644 --- a/drivers/firmware/arm_ffa/Kconfig +++ b/drivers/firmware/arm_ffa/Kconfig @@ -14,3 +14,8 @@ config ARM_FFA_TRANSPORT This driver provides interface for all the client drivers making use of the features offered by ARM FF-A. + +config ARM_FFA_SMCCC + bool + default ARM_FFA_TRANSPORT + depends on ARM64 && HAVE_ARM_SMCCC_DISCOVERY diff --git a/drivers/firmware/arm_ffa/Makefile b/drivers/firmware/arm_ffa/Makefile index 1a9bd2bf8752..1aaac512384c 100644 --- a/drivers/firmware/arm_ffa/Makefile +++ b/drivers/firmware/arm_ffa/Makefile @@ -2,3 +2,4 @@ obj-$(CONFIG_ARM_FFA_TRANSPORT) = ffa-bus.o ffa-driver.o ffa-bus-y = bus.o ffa-driver-y = driver.o +ffa-driver-$(CONFIG_ARM_FFA_SMCCC) += smccc.o diff --git a/drivers/firmware/arm_ffa/common.h b/drivers/firmware/arm_ffa/common.h index 720c8425dfd6..10ac3f363f52 100644 --- a/drivers/firmware/arm_ffa/common.h +++ b/drivers/firmware/arm_ffa/common.h @@ -15,9 +15,13 @@ typedef ffa_res_t (ffa_fn)(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long); +#ifdef CONFIG_ARM_FFA_SMCCC +int __init ffa_transport_init(ffa_fn **invoke_ffa_fn); +#else static inline int __init ffa_transport_init(ffa_fn **invoke_ffa_fn) { return -EOPNOTSUPP; } +#endif #endif /* _FFA_COMMON_H */ diff --git a/drivers/firmware/arm_ffa/smccc.c b/drivers/firmware/arm_ffa/smccc.c new file mode 100644 index 000000000000..b93d281d2399 --- /dev/null +++ b/drivers/firmware/arm_ffa/smccc.c @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2020 ARM Ltd. + */ + +#include + +#include "common.h" + +static struct arm_smccc_v1_2_res +__arm_ffa_fn_smc(unsigned long function_id, unsigned long arg0, + unsigned long arg1, unsigned long arg2, unsigned long arg3, + unsigned long arg4, unsigned long arg5, unsigned long arg6) +{ + struct arm_smccc_v1_2_res res; + + arm_smccc_v1_2_smc(function_id, arg0, arg1, arg2, arg3, arg4, arg5, + arg6, &res); + + return res; +} + +static struct arm_smccc_v1_2_res +__arm_ffa_fn_hvc(unsigned long function_id, unsigned long arg0, + unsigned long arg1, unsigned long arg2, unsigned long arg3, + unsigned long arg4, unsigned long arg5, unsigned long arg6) +{ + struct arm_smccc_v1_2_res res; + + arm_smccc_v1_2_hvc(function_id, arg0, arg1, arg2, arg3, arg4, arg5, + arg6, &res); + return res; +} + +int __init ffa_transport_init(ffa_fn **invoke_ffa_fn) +{ + enum arm_smccc_conduit conduit; + + if (arm_smccc_get_version() < ARM_SMCCC_VERSION_1_2) + return -EOPNOTSUPP; + + conduit = arm_smccc_1_1_get_conduit(); + if (conduit == SMCCC_CONDUIT_NONE) { + pr_err("%s: invalid SMCCC conduit\n", __func__); + return -EOPNOTSUPP; + } + + if (conduit == SMCCC_CONDUIT_SMC) + *invoke_ffa_fn = __arm_ffa_fn_smc; + else + *invoke_ffa_fn = __arm_ffa_fn_hvc; + + return 0; +}