From patchwork Fri Dec 4 12:11:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 337756 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp350393jai; Fri, 4 Dec 2020 04:14:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJyuOnEnLsHqzXNUH9BFvdQnYuI9OQlgxvz0IKFbJqcoG1RAetHoAbOTuqjVl+NFiHc2/bu+ X-Received: by 2002:a50:d8c8:: with SMTP id y8mr7056445edj.82.1607084056686; Fri, 04 Dec 2020 04:14:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607084056; cv=none; d=google.com; s=arc-20160816; b=V2AS9+1YTOBou2VelVJNhPnkm1t97eXC5eQgVh/Ck9G5FNUM0oPYg5I0e/fPtMIZ5A 2IPxeP4bV1FyhAV+VEYEwBrQB/NC1Yxqr12c2MeT4AfhL/ec/wT1M8RdE4ydKiq9e9r4 OTLKLrhYncDZ/45unELWYa8+Y+osYCM54B0dqzYoDYu3e8GCTvwncwqZ52/XTNQY4sss CACLIRmK5OCkF9ii7cO0Hob25YYMZQg2iCgxJczxf+Im4JSk0KCs51AaEIko9re1Ufru 5BEdtcULD+hh2gnCqAXaUKNDDwu0h/DcrFJEpWTF8m4h9/rr4P7Eq7C6NLztgYl+XOrP Ujjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=UyejfkN5SiHDYCywlZUFXYw8rQedIBBRb2o13kM4ZlA=; b=kgsoWG3wQh+al76e0qjqTLSOyBgkvVfQNMn/6PqKCWVNAqgHkDD+3HrOzJmIVPXlrP pV5iFpxWDOb9jhGLXAioKKpM+pubqL3oC3rDogi9xw1nWfVuYgj2/eeChxuQ9pY8WEqj Badr2UhifU8VpE25+rZrddhiWCDvkj2dXGN742ak2a+8qdaAV8FosyXuQuyvlMmPCwLT 37k+WmbWWnXsdzu+Aqf5Vpv+9LjZGSkfWqnKLHFOCiSZclF50B65b/TvM1S1u2P7fiyx ydDk2Zu7PgLWCnxN4/g9OmQyadpDniZ8DuhuRD3eKfqRGO8swBS+25w1xPlbF1OBFEa1 4dmQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u11si2810868edr.4.2020.12.04.04.14.16; Fri, 04 Dec 2020 04:14:16 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388125AbgLDMNS (ORCPT + 6 others); Fri, 4 Dec 2020 07:13:18 -0500 Received: from foss.arm.com ([217.140.110.172]:33200 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388119AbgLDMNS (ORCPT ); Fri, 4 Dec 2020 07:13:18 -0500 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 7C7421478; Fri, 4 Dec 2020 04:11:52 -0800 (PST) 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 2B0A43F575; Fri, 4 Dec 2020 04:11:51 -0800 (PST) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Cc: Sudeep Holla , Trilok Soni , arve@android.com, Andrew Walbran , David Hartley , Achin Gupta , Jens Wiklander , Arunachalam Ganapathy Subject: [PATCH v3 5/7] firmware: arm_ffa: Add support for SMCCC as transport to FFA driver Date: Fri, 4 Dec 2020 12:11:35 +0000 Message-Id: <20201204121137.2966778-6-sudeep.holla@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201204121137.2966778-1-sudeep.holla@arm.com> References: <20201204121137.2966778-1-sudeep.holla@arm.com> MIME-Version: 1.0 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 specific 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 | 3 +- drivers/firmware/arm_ffa/common.h | 4 +++ drivers/firmware/arm_ffa/smccc.c | 54 +++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 drivers/firmware/arm_ffa/smccc.c -- 2.25.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 82d0d35c5324..9d9f37523200 100644 --- a/drivers/firmware/arm_ffa/Makefile +++ b/drivers/firmware/arm_ffa/Makefile @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only ffa-bus-y = bus.o ffa-driver-y = driver.o -ffa-module-objs := $(ffa-bus-y) $(ffa-driver-y) +ffa-transport-$(CONFIG_ARM_FFA_SMCCC) += smccc.o +ffa-module-objs := $(ffa-bus-y) $(ffa-driver-y) $(ffa-transport-y) obj-$(CONFIG_ARM_FFA_TRANSPORT) = ffa-module.o diff --git a/drivers/firmware/arm_ffa/common.h b/drivers/firmware/arm_ffa/common.h index fc6948efe9f3..d019348bf67d 100644 --- a/drivers/firmware/arm_ffa/common.h +++ b/drivers/firmware/arm_ffa/common.h @@ -18,9 +18,13 @@ typedef ffa_res_t int __init arm_ffa_bus_init(void); void __exit arm_ffa_bus_exit(void); +#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; +}