From patchwork Tue Nov 3 17:43:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 314484 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB0FDC388F7 for ; Tue, 3 Nov 2020 17:44:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5917621D91 for ; Tue, 3 Nov 2020 17:44:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728697AbgKCRoA (ORCPT ); Tue, 3 Nov 2020 12:44:00 -0500 Received: from foss.arm.com ([217.140.110.172]:53032 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727901AbgKCRoA (ORCPT ); Tue, 3 Nov 2020 12:44:00 -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 DA929147A; Tue, 3 Nov 2020 09:43:59 -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 31E0E3F718; Tue, 3 Nov 2020 09:43:58 -0800 (PST) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Cc: Sudeep Holla , Trilok Soni , Trilok Soni , arve@android.com, Andrew Walbran , David Hartley , Achin Gupta , Android Kernel Team , Fuad Tabba , Will Deacon , Rob Herring Subject: [PATCH v2 1/9] dt-bindings: Arm: Add Firmware Framework for Armv8-A (FF-A) binding Date: Tue, 3 Nov 2020 17:43:42 +0000 Message-Id: <20201103174350.991593-2-sudeep.holla@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103174350.991593-1-sudeep.holla@arm.com> References: <20201103174350.991593-1-sudeep.holla@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Will Deacon Add devicetree bindings for a FF-A-compliant hypervisor, its partitions and their memory regions. The naming is ludicrous but also not by fault. Cc: Rob Herring Signed-off-by: Will Deacon (sudeep.holla: Dropped PSA from name and elsewhere as it seem to have disappeared mysteriously just before the final release, renamed arm,ffa.yaml as arm,ffa-hyp.yaml) Signed-off-by: Sudeep Holla --- .../devicetree/bindings/arm/arm,ffa-hyp.yaml | 102 ++++++++++++++++++ .../reserved-memory/arm,ffa-memory.yaml | 71 ++++++++++++ 2 files changed, 173 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/arm,ffa-hyp.yaml create mode 100644 Documentation/devicetree/bindings/reserved-memory/arm,ffa-memory.yaml Hi Rob, Sorry I haven't waited for the discussion on the previous version to conclude and posting new version to re-trigger (more) discussion on the series. Regards, Sudeep diff --git a/Documentation/devicetree/bindings/arm/arm,ffa-hyp.yaml b/Documentation/devicetree/bindings/arm/arm,ffa-hyp.yaml new file mode 100644 index 000000000000..054e36d317ff --- /dev/null +++ b/Documentation/devicetree/bindings/arm/arm,ffa-hyp.yaml @@ -0,0 +1,102 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/arm/arm,ffa-hyp.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Arm Firmware Framework for Arm v8-A + +maintainers: + - Will Deacon + +description: | + Firmware frameworks implementing partition setup according to the FF-A + specification defined by ARM document number ARM DEN 0077A ("Arm Firmware + Framework for Arm v8-A") [0] must provide a "manifest and image" for each + partition to the "partition manager" so that the partition execution contexts + can be initialised. + + In the case of a virtual FFA instance, the manifest and image details can be + passed to the hypervisor (e.g. Linux KVM) using this binding. + + [0] https://developer.arm.com/docs/den0077/latest + +properties: + $nodename: + const: ffa_hyp + + compatible: + oneOf: + - const: arm,ffa-1.0-hypervisor + + memory-region: + $ref: '/schemas/types.yaml#/definitions/phandle' + description: | + A phandle to the reserved memory region [1] to be used by the hypervisor. + The reserved memory region must be compatible with + "arm,ffa-1.0-hypervisor-memory-region". + + [1] Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt + +patternProperties: + "^ffa_partition[0-9]+$": + type: object + description: One or more child nodes, each describing an FFA partition. + properties: + $nodename: + const: ffa_partition + + compatible: + oneOf: + - const: arm,ffa-1.0-partition + + uuid: + $ref: '/schemas/types.yaml#definitions/string' + description: | + The 128-bit UUID [2] of the service implemented by this partition. + + [2] https://tools.ietf.org/html/rfc4122 + + nr-exec-ctxs: + $ref: '/schemas/types.yaml#/definitions/uint32' + description: | + The number of virtual CPUs to instantiate for this partition. + + exec-state: + description: The execution state in which to execute the partition. + oneOf: + - const: "AArch64" + - const: "AArch32" + + entry-point: + $ref: '/schemas/types.yaml#/definitions/uint32-matrix' + description: | + The entry address of the partition specified as an Intermediate + Physical Address (IPA) encoded according to the '#address-cells' + property. + + memory-region: + $ref: '/schemas/types.yaml#/definitions/phandle-array' + description: | + A list of phandles to FFA reserved memory regions [3] for this + partition. + + [3] Documentation/devicetree/bindings/reserved-memory/arm,ffa-memory.yaml + +additionalProperties: false + +examples: + - | + ffa_hyp { + compatible = "arm,ffa-1.0-hypervisor"; + memory-region = <&ffa_hyp_reserved>; + + ffa_partition0 { + compatible = "arm,ffa-1.0-partition"; + uuid = "12345678-9abc-def0-1234-56789abcdef0"; + nr-exec-ctxs = <2>; + exec-state = "AArch64"; + entry-point = <0x80000>; + memory-region = <&ffa_reserved0 &ffa_reserved1>; + }; + }; diff --git a/Documentation/devicetree/bindings/reserved-memory/arm,ffa-memory.yaml b/Documentation/devicetree/bindings/reserved-memory/arm,ffa-memory.yaml new file mode 100644 index 000000000000..5335e07abcfc --- /dev/null +++ b/Documentation/devicetree/bindings/reserved-memory/arm,ffa-memory.yaml @@ -0,0 +1,71 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/reserved-memory/arm,ffa-memory.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Memory Region for Arm Firmware Framework for Arm v8-A + +maintainers: + - Will Deacon + +description: | + This binding allows a FF-A implementation to describe the normal memory + regions of a partition [1] to a hypervisor according to [2]. + + The physical address range reserved for the partition can be specified as a + static allocation using the 'reg' property or as a dynamic allocation using + the 'size' property. If both properties are omitted, then the hypervisor can + allocate physical memory for the partition however it sees fit. + + [1] Documentation/devicetree/bindings/arm/arm,ffa.yaml + [2] Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt + +properties: + $nodename: + pattern: "^ffa_mem(@[0-9a-f]+)?$" + + compatible: + oneOf: + - const: arm,ffa-1.0-partition-memory-region + + ipa-range: + $ref: '/schemas/types.yaml#/definitions/uint32-matrix' + description: | + The Intermediate Physical Address (IPA) range (encoded in the same way as + a 'reg' property) at which to map the physical memory. If the IPA range is + larger than the physical memory region then the region is mapped starting + at the base of the IPA range. + + read-only: + type: boolean + description: | + (static allocation only) The memory region has been pre-populated + by the firmware framework and must be mapped without write permission + at stage 2. + + non-executable: + type: boolean + description: | + The memory region must be mapped without execute permission at stage 2. + + +required: + - compatible + +# The "reserved-memory" binding defines additional properties. +additionalProperties: true + +examples: + - | + reserved-memory { + #address-cells = <2>; + #size-cells = <2>; + + ffa_reserved0: ffa_mem@100000000 { + compatible = "arm,ffa-1.0-partition-memory-region"; + reg = <0x1 0x0 0x0 0x04000000>; // 64M @ 1GB + ipa-range = <0x0 0x0 0x0 0x04000000>; // 64M @ 0x0 + read-only; + }; + }; From patchwork Tue Nov 3 17:43:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 320439 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp4779546ilc; Tue, 3 Nov 2020 09:44:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJzupRWfXOFW1Ne4qCQ/DfsqnSNeS2ZP+i1CgCA/fAMoljDoQ7ValdeDn8lj4JtdmIYIc8SG X-Received: by 2002:a05:6402:553:: with SMTP id i19mr4699599edx.194.1604425443187; Tue, 03 Nov 2020 09:44:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604425443; cv=none; d=google.com; s=arc-20160816; b=qlwl1rvCyw/pcTF+NWddqRV5oA9UXMgtwJa5O7TJaqTd0v6sHGJy162iQujC9X6oIF mH8Rnrkgp4kg/xhT6hNL0Oco1jFzJCW5h+YwoHxKiebPH9JL1edQLK4E6+ivIVbh7J8r DzqoT4+Oj22QUfgmUhiGDROoDo5Bsls9KgloaxYlrI8ysBfhwzFjpjzGVDYYUKz8Glii pgAeEA/krLw3Fm052alc6C0uex/7ceQXypMq/yDmC70HU1QPl0CECZb7wW6qJP66Hcbv VlXCsFjtWHPTr62xZ4GYfKlxxMzQ4PNgyoixX6MoUlTzbKkKc52DECC4TBKxcjzOYA4j FNZA== 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=SwbUfelIQzTEubt8UFnSbvOlelPNqtNUh85th9TO9HA=; b=dacpnKxPE79knuoOVg5MC5xmVN4yMEh5R1YZl/E0iw5Ea8RmbkaQjtHkwtVPnWtUHE msuBOaozlfxU1WaL3qWxWLwSC+qxAA2O1H6krvLTP9SkZuJAzcf+djhkKcpGUQkpFEDe 4FD2C09bBKZ+cQO3zWnjiECmn8ClLY5H4eGSQNrKtHaMmbhLGeiXwAwmnK2Nu7qITpfJ TwQaaB5+FUPEWRhVliGHTVuh6xsqYUPc5t9GyxJdMnFY7VlXj3SW8q1gs4kR9VaIocgP JYpgkJwuAAKDEn3I0Cqfjtj8NeNfk9AulYYR2scbSfQznhHLGUWjuYhSSY467G5siMT1 KLdg== 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 n13si13469090eda.416.2020.11.03.09.44.03; Tue, 03 Nov 2020 09:44:03 -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 S1729073AbgKCRoC (ORCPT + 6 others); Tue, 3 Nov 2020 12:44:02 -0500 Received: from foss.arm.com ([217.140.110.172]:53048 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727901AbgKCRoC (ORCPT ); Tue, 3 Nov 2020 12:44:02 -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 A12301474; Tue, 3 Nov 2020 09:44:01 -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 1C1783F718; Tue, 3 Nov 2020 09:44:00 -0800 (PST) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Cc: Sudeep Holla , Trilok Soni , Trilok Soni , arve@android.com, Andrew Walbran , David Hartley , Achin Gupta , Android Kernel Team , Fuad Tabba , Rob Herring Subject: [PATCH v2 2/9] dt-bindings: Arm: Extend FF-A binding to support in-kernel usage of partitions Date: Tue, 3 Nov 2020 17:43:43 +0000 Message-Id: <20201103174350.991593-3-sudeep.holla@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103174350.991593-1-sudeep.holla@arm.com> References: <20201103174350.991593-1-sudeep.holla@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Since the FF-A v1.0 specification doesn't list the UUID of all the partitions in the discovery API, we need to specify the UUID of the partitions that need to be accessed by drivers within the kernel. This extends the binding to provide the list of partitions that kernel drivers may need to access and are not part of the partitions managed by the hypervisor. Cc: Rob Herring Signed-off-by: Sudeep Holla --- .../devicetree/bindings/arm/arm,ffa.yaml | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/arm,ffa.yaml Hi, I struggled to keep both these(arm,ffa and arm,ffa-hyp) in the single yaml file. I couldn't understand the errors and couldn't find an example that has something similar. I will continue to explore, just posting as separate for now to continue discussions. Regards, Sudeep -- 2.25.1 diff --git a/Documentation/devicetree/bindings/arm/arm,ffa.yaml b/Documentation/devicetree/bindings/arm/arm,ffa.yaml new file mode 100644 index 000000000000..a014a5801c34 --- /dev/null +++ b/Documentation/devicetree/bindings/arm/arm,ffa.yaml @@ -0,0 +1,58 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/arm/arm,ffa.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Arm Firmware Framework for Arm v8-A (in-kernel users) + +maintainers: + - Sudeep Holla + +description: | + Firmware frameworks implementing partition according to the FF-A + specification defined by ARM document number ARM DEN 0077A ("Arm Firmware + Framework for Arm v8-A") [0], providing services to be used by other + partitions. + + [0] https://developer.arm.com/docs/den0077/latest + +properties: + $nodename: + const: ffa + + compatible: + oneOf: + - const: arm,ffa-1.0 + +patternProperties: + "^ffa_partition[0-9]+$": + type: object + description: One or more child nodes, each describing an FFA partition. + properties: + $nodename: + const: ffa_partition + + compatible: + oneOf: + - const: arm,ffa-1.0-partition + + uuid: + $ref: '/schemas/types.yaml#definitions/string' + description: | + The 128-bit UUID [2] of the service implemented by this partition. + + [2] https://tools.ietf.org/html/rfc4122 + +additionalProperties: false + +examples: + - | + ffa { + compatible = "arm,ffa-1.0"; + + ffa_partition0 { + compatible = "arm,ffa-1.0-partition"; + uuid = "12345678-9abc-def0-1234-56789abcdef0"; + }; + }; From patchwork Tue Nov 3 17:43:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 314483 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18AAEC2D0A3 for ; Tue, 3 Nov 2020 17:44:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE55D20773 for ; Tue, 3 Nov 2020 17:44:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729072AbgKCRoE (ORCPT ); Tue, 3 Nov 2020 12:44:04 -0500 Received: from foss.arm.com ([217.140.110.172]:53064 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727901AbgKCRoD (ORCPT ); Tue, 3 Nov 2020 12:44:03 -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 4C8C61480; Tue, 3 Nov 2020 09:44:03 -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 D5BFC3F718; Tue, 3 Nov 2020 09:44:01 -0800 (PST) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Cc: Sudeep Holla , Trilok Soni , Trilok Soni , arve@android.com, Andrew Walbran , David Hartley , Achin Gupta , Android Kernel Team , Fuad Tabba Subject: [PATCH v2 3/9] arm64: smccc: Add support for SMCCCv1.2 input/output registers Date: Tue, 3 Nov 2020 17:43:44 +0000 Message-Id: <20201103174350.991593-4-sudeep.holla@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103174350.991593-1-sudeep.holla@arm.com> References: <20201103174350.991593-1-sudeep.holla@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org SMCCC v1.2 allows x8-x17 to be used as parameter registers and x4—x17 to be used as result registers in SMC64/HVC64. Arm Firmware Framework for Armv8-A specification makes use of x0-x7 as parameter and result registers. Current SMCCC interface in the kernel just use x0-x7 as parameter and x0-x3 as result registers. Let us add new interface to support x0-x7 as parameter and result registers. This can be extended to include x8-x17 when there are users for the same. Signed-off-by: Sudeep Holla --- arch/arm64/kernel/asm-offsets.c | 4 +++ arch/arm64/kernel/smccc-call.S | 22 +++++++++++++++ include/linux/arm-smccc.h | 50 +++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c index 7d32fc959b1a..32bcc25337ce 100644 --- a/arch/arm64/kernel/asm-offsets.c +++ b/arch/arm64/kernel/asm-offsets.c @@ -122,6 +122,10 @@ int main(void) DEFINE(ARM_SMCCC_RES_X2_OFFS, offsetof(struct arm_smccc_res, a2)); DEFINE(ARM_SMCCC_QUIRK_ID_OFFS, offsetof(struct arm_smccc_quirk, id)); DEFINE(ARM_SMCCC_QUIRK_STATE_OFFS, offsetof(struct arm_smccc_quirk, state)); + DEFINE(ARM_SMCCC_V1_2_RES_X0_OFFS, offsetof(struct arm_smccc_v1_2_res, a0)); + DEFINE(ARM_SMCCC_V1_2_RES_X2_OFFS, offsetof(struct arm_smccc_v1_2_res, a2)); + DEFINE(ARM_SMCCC_V1_2_RES_X4_OFFS, offsetof(struct arm_smccc_v1_2_res, a4)); + DEFINE(ARM_SMCCC_V1_2_RES_X6_OFFS, offsetof(struct arm_smccc_v1_2_res, a6)); BLANK(); DEFINE(HIBERN_PBE_ORIG, offsetof(struct pbe, orig_address)); DEFINE(HIBERN_PBE_ADDR, offsetof(struct pbe, address)); diff --git a/arch/arm64/kernel/smccc-call.S b/arch/arm64/kernel/smccc-call.S index d62447964ed9..0ea15c1742f3 100644 --- a/arch/arm64/kernel/smccc-call.S +++ b/arch/arm64/kernel/smccc-call.S @@ -43,3 +43,25 @@ SYM_FUNC_START(__arm_smccc_hvc) SMCCC hvc SYM_FUNC_END(__arm_smccc_hvc) EXPORT_SYMBOL(__arm_smccc_hvc) + + .macro SMCCC_v1_2 instr + .cfi_startproc + \instr #0 + ldr x8, [sp] + stp x0, x1, [x8, #ARM_SMCCC_V1_2_RES_X0_OFFS] + stp x2, x3, [x8, #ARM_SMCCC_V1_2_RES_X2_OFFS] + stp x4, x5, [x8, #ARM_SMCCC_V1_2_RES_X4_OFFS] + stp x6, x7, [x8, #ARM_SMCCC_V1_2_RES_X6_OFFS] + ret + .cfi_endproc +.endm + +SYM_FUNC_START(arm_smccc_v1_2_hvc) + SMCCC_v1_2 hvc +SYM_FUNC_END(arm_smccc_v1_2_hvc) +EXPORT_SYMBOL(arm_smccc_v1_2_hvc) + +SYM_FUNC_START(arm_smccc_v1_2_smc) + SMCCC_v1_2 smc +SYM_FUNC_END(arm_smccc_v1_2_smc) +EXPORT_SYMBOL(arm_smccc_v1_2_smc) diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h index f860645f6512..aed27214c88f 100644 --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -155,6 +155,56 @@ struct arm_smccc_res { unsigned long a3; }; +#ifdef CONFIG_ARM64 +/* TODO Need to implement for ARM too */ +/** + * struct arm_smccc_v1_2_res - Result from SMC/HVC call + * @a0-a3 result values from registers 0 to 3 + */ +struct arm_smccc_v1_2_res { + unsigned long a0; + unsigned long a1; + unsigned long a2; + unsigned long a3; + unsigned long a4; + unsigned long a5; + unsigned long a6; + unsigned long a7; +}; + +/** + * arm_smccc_v1_2_hvc() - make HVC calls + * @a0-a7: arguments passed in registers 0 to 7 + * @res: result values from registers 0 to 7 + * + * This function is used to make SMC calls following SMC Calling Convention + * v1.2 or above. The content of the supplied param are copied to registers + * 0 to 7 prior to the SMC instruction. The return values are updated with + * the content from register 0 to 7 on return from the SMC instruction. + */ +asmlinkage +void arm_smccc_v1_2_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_v1_2_res *res); + +/** + * arm_smccc_v1_2_smc() - make SMC calls + * @a0-a7: arguments passed in registers 0 to 7 + * @res: result values from registers 0 to 7 + * + * This function is used to make SMC calls following SMC Calling Convention + * v1.2 or above. The content of the supplied param are copied to registers + * 0 to 7 prior to the SMC instruction. The return values are updated with + * the content from register 0 to 7 on return from the SMC instruction. + */ +asmlinkage +void arm_smccc_v1_2_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_v1_2_res *res); +#endif + /** * struct arm_smccc_quirk - Contains quirk information * @id: quirk identification From patchwork Tue Nov 3 17:43:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 320441 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp4779595ilc; Tue, 3 Nov 2020 09:44:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJwDUBPQDKPXlzkbRlRn1HMZmcyqC4TMSr9HIsBSu2vl6FERkyxGXKstlOETB/EDYeoB6JaT X-Received: by 2002:a17:906:d1c3:: with SMTP id bs3mr20166027ejb.246.1604425446780; Tue, 03 Nov 2020 09:44:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604425446; cv=none; d=google.com; s=arc-20160816; b=d198YbK7PlNQJtn4DYK9x7T4y67f8J7/th7WyEtveas6SPhA1SP8p4QUp2ls8pHJIC jsQ564lj1HYwdWtqpLrOB2MR6EeK25e8ttlQT6SAc4dAmkkq2uePVD+MDjl5Myg1g2yW jQpkjjRLhQYRRGj5ruTNNzQNxxhqRe+HSTNiLOk99PkCe8hpBgAU/SiFoN0fX3IKtbe6 VpGp3NKykYADR/O+zicJKjm5AM1cqrH6NAiWyJ83BqwDEpBjVfYlab8bULj0WBqxETMP UbAh3U3KAJfqP7G/j18wAopdmg/lusHrx+pGZBwkMV9kWw1djok0TCAaq0iSpuvvYR0q mMkA== 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=Zvo6OYkn/I6r7RzsAIriKWaNRBamFj3XFYpJiqYsWfI=; b=NRL0nl3MqKjCKXBMsSroDaj8tF61vOgmiQGZvSEJkMybNkctNe6b8oRiZfIkaVS3P2 r7RvkIcE9tDLMNMLcqu07s8JnYp8DqYApC506bk3ZpwBGVfFkYXSjXxk+2nKqAcSWLyb k+0SvDkpzKXgt/bP5CTnQOVr30E4RrCd/f6dgblqHKNBJX0Gf4Qz2zSOzwQzJzzW7KiX /DAKy0Oxy+wgAx90FU+qKDfgQSZgjX7r/6exW8j3GfWN5BB+3iSrGYmecOhMWiBkE33A 8gptmNAPDb2lJwnY9C0QLSp8SGFCB976siXaif3z0qU0uVCJjNc8leg+JYRr+6JMBtL9 3+zQ== 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 n13si13469090eda.416.2020.11.03.09.44.06; Tue, 03 Nov 2020 09:44:06 -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 S1729059AbgKCRoF (ORCPT + 6 others); Tue, 3 Nov 2020 12:44:05 -0500 Received: from foss.arm.com ([217.140.110.172]:53082 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727901AbgKCRoF (ORCPT ); Tue, 3 Nov 2020 12:44:05 -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 ED74214F6; Tue, 3 Nov 2020 09:44:04 -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 8137A3F718; Tue, 3 Nov 2020 09:44:03 -0800 (PST) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Cc: Sudeep Holla , Trilok Soni , Trilok Soni , arve@android.com, Andrew Walbran , David Hartley , Achin Gupta , Android Kernel Team , Fuad Tabba Subject: [PATCH v2 4/9] firmware: arm_ffa: Add initial FFA bus support for device enumeration Date: Tue, 3 Nov 2020 17:43:45 +0000 Message-Id: <20201103174350.991593-5-sudeep.holla@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103174350.991593-1-sudeep.holla@arm.com> References: <20201103174350.991593-1-sudeep.holla@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The Arm FF for Armv8-A specification has concept of endpoints or partitions. In the Normal world, a partition could be a VM when the Virtualization extension is enabled or the kernel itself. In order to handle multiple partitions, we can create a FFA device for each partition on a dedicated FFA bus. Similarly, different drivers requiring FFA transport can be registered on the same bus. We can match the device and drivers using UUID. This is mostly for the in-kernel users with FFA drivers. However, to support usage of FFA transport from user-space, there is also a provision to create character device interface for the same. Signed-off-by: Sudeep Holla --- drivers/firmware/Kconfig | 1 + drivers/firmware/Makefile | 1 + drivers/firmware/arm_ffa/Kconfig | 16 +++ drivers/firmware/arm_ffa/Makefile | 4 + drivers/firmware/arm_ffa/bus.c | 205 ++++++++++++++++++++++++++++++ include/linux/arm_ffa.h | 81 ++++++++++++ 6 files changed, 308 insertions(+) create mode 100644 drivers/firmware/arm_ffa/Kconfig create mode 100644 drivers/firmware/arm_ffa/Makefile create mode 100644 drivers/firmware/arm_ffa/bus.c create mode 100644 include/linux/arm_ffa.h -- 2.25.1 diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index 3315e3c21586..be9056226a07 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -295,6 +295,7 @@ config TURRIS_MOX_RWTM other manufacturing data and also utilize the Entropy Bit Generator for hardware random number generation. +source "drivers/firmware/arm_ffa/Kconfig" source "drivers/firmware/broadcom/Kconfig" source "drivers/firmware/google/Kconfig" source "drivers/firmware/efi/Kconfig" diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile index 5e013b6a3692..546ac8e7f6d0 100644 --- a/drivers/firmware/Makefile +++ b/drivers/firmware/Makefile @@ -22,6 +22,7 @@ obj-$(CONFIG_TI_SCI_PROTOCOL) += ti_sci.o obj-$(CONFIG_TRUSTED_FOUNDATIONS) += trusted_foundations.o obj-$(CONFIG_TURRIS_MOX_RWTM) += turris-mox-rwtm.o +obj-y += arm_ffa/ obj-y += arm_scmi/ obj-y += broadcom/ obj-y += meson/ diff --git a/drivers/firmware/arm_ffa/Kconfig b/drivers/firmware/arm_ffa/Kconfig new file mode 100644 index 000000000000..261a3660650a --- /dev/null +++ b/drivers/firmware/arm_ffa/Kconfig @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0-only +config ARM_FFA_TRANSPORT + tristate "Arm Firmware Framework for Armv8-A" + depends on OF + depends on ARM64 + default n + help + This Firmware Framework(FF) for Arm A-profile processors describes + interfaces that standardize communication between the various + software images which includes communication between images in + the Secure world and Normal world. It also leverages the + virtualization extension to isolate software images provided + by an ecosystem of vendors from each other. + + This driver provides interface for all the client drivers making + use of the features offered by ARM FF-A. diff --git a/drivers/firmware/arm_ffa/Makefile b/drivers/firmware/arm_ffa/Makefile new file mode 100644 index 000000000000..bfe4323a8784 --- /dev/null +++ b/drivers/firmware/arm_ffa/Makefile @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only +ffa-bus-y = bus.o +ffa-module-objs := $(ffa-bus-y) +obj-$(CONFIG_ARM_FFA_TRANSPORT) = ffa-module.o diff --git a/drivers/firmware/arm_ffa/bus.c b/drivers/firmware/arm_ffa/bus.c new file mode 100644 index 000000000000..5d7102419e6c --- /dev/null +++ b/drivers/firmware/arm_ffa/bus.c @@ -0,0 +1,205 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2020 ARM Ltd. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include + +#define DEVICE_NAME "arm_ffa" +#define FFA_MAX_CDEVS 32 + +static DEFINE_IDA(ffa_dev_id); +static dev_t ffa_devt; + +static int ffa_device_match(struct device *dev, struct device_driver *drv) +{ + const struct ffa_device_id *id_table; + struct ffa_device *ffa_dev; + + id_table = to_ffa_driver(drv)->id_table; + ffa_dev = to_ffa_dev(dev); + + while (!uuid_is_null(&id_table->uuid)) { + if (uuid_equal(&ffa_dev->uuid, &id_table->uuid)) + return 1; + id_table++; + } + + return 0; +} + +static int ffa_device_probe(struct device *dev) +{ + struct ffa_driver *ffa_drv = to_ffa_driver(dev->driver); + struct ffa_device *ffa_dev = to_ffa_dev(dev); + + if (!ffa_device_match(dev, dev->driver)) + return -ENODEV; + + return ffa_drv->probe(ffa_dev); +} + +static int ffa_device_uevent(struct device *dev, struct kobj_uevent_env *env) +{ + uuid_t *dev_id = &to_ffa_dev(dev)->uuid; + + return add_uevent_var(env, "MODALIAS=arm_ffa:%pUb", dev_id); +} + +struct bus_type ffa_bus_type = { + .name = "arm_ffa", + .match = ffa_device_match, + .probe = ffa_device_probe, + .uevent = ffa_device_uevent, +}; +EXPORT_SYMBOL_GPL(ffa_bus_type); + +int ffa_driver_register(struct ffa_driver *driver, struct module *owner, + const char *mod_name) +{ + int ret; + + driver->driver.bus = &ffa_bus_type; + driver->driver.name = driver->name; + driver->driver.owner = owner; + driver->driver.mod_name = mod_name; + + ret = driver_register(&driver->driver); + if (!ret) + pr_debug("registered new ffa driver %s\n", driver->name); + + return ret; +} +EXPORT_SYMBOL_GPL(ffa_driver_register); + +void ffa_driver_unregister(struct ffa_driver *driver) +{ + driver_unregister(&driver->driver); +} +EXPORT_SYMBOL_GPL(ffa_driver_unregister); + +static void ffa_release_device(struct device *dev) +{ + struct ffa_device *ffa_dev = to_ffa_dev(dev); + + kfree(ffa_dev); +} + +static int __ffa_devices_unregister(struct device *dev, void *data) +{ + ffa_release_device(dev); + + return 0; +} + +static void ffa_devices_unregister(void) +{ + bus_for_each_dev(&ffa_bus_type, NULL, NULL, + __ffa_devices_unregister); +} + +static char * +ffa_devnode(struct device *dev, umode_t *mode, kuid_t *uid, kgid_t *gid) +{ + return kasprintf(GFP_KERNEL, DEVICE_NAME "/%s", dev_name(dev)); +} + +static struct device_type ffa_dev_type = { + .devnode = ffa_devnode, +}; + +int ffa_device_register(struct ffa_device *ffa_dev) +{ + int ret; + struct cdev *cdev; + struct device *dev; + + if (!ffa_dev) + return -EINVAL; + + dev = &ffa_dev->dev; + cdev = &ffa_dev->cdev; + + dev->bus = &ffa_bus_type; + dev->type = &ffa_dev_type; + dev->release = ffa_release_device; + + device_initialize(dev); + + if (cdev->ops) { + ret = ida_simple_get(&ffa_dev_id, 0, FFA_MAX_CDEVS, GFP_KERNEL); + if (ret < 0) { + put_device(dev); + return ret; + } + + dev->devt = MKDEV(MAJOR(ffa_devt), ret); + + cdev->owner = cdev->ops->owner; + } + + ret = cdev_device_add(cdev, dev); + if (ret) { + dev_err(dev, "unable to cdev_device_add() %s, major %d, minor %d, err=%d\n", + dev_name(dev), MAJOR(dev->devt), MINOR(dev->devt), + ret); + put_device(dev); + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(ffa_device_register); + +void ffa_device_unregister(struct ffa_device *ffa_dev) +{ + if (!ffa_dev) + return; + + cdev_device_del(&ffa_dev->cdev, &ffa_dev->dev); + + put_device(&ffa_dev->dev); +} +EXPORT_SYMBOL_GPL(ffa_device_unregister); + +static int __init arm_ffa_bus_init(void) +{ + int ret; + + ret = alloc_chrdev_region(&ffa_devt, 0, FFA_MAX_CDEVS, DEVICE_NAME); + if (ret) { + pr_err("failed to allocate char dev region\n"); + return ret; + } + + ret = bus_register(&ffa_bus_type); + if (ret) { + pr_err("ffa bus register failed (%d)\n", ret); + unregister_chrdev_region(ffa_devt, FFA_MAX_CDEVS); + } + + return ret; +} +subsys_initcall(arm_ffa_bus_init); + +static void __exit arm_ffa_bus_exit(void) +{ + ffa_devices_unregister(); + bus_unregister(&ffa_bus_type); + unregister_chrdev_region(ffa_devt, FFA_MAX_CDEVS); +} + +module_exit(arm_ffa_bus_exit); + +MODULE_ALIAS("arm-ffa-bus"); +MODULE_AUTHOR("Sudeep Holla "); +MODULE_DESCRIPTION("Arm FF-A bus driver"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h new file mode 100644 index 000000000000..2fe16176149f --- /dev/null +++ b/include/linux/arm_ffa.h @@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2020 ARM Ltd. + */ + +#ifndef _LINUX_ARM_FFA_H +#define _LINUX_ARM_FFA_H + +#include +#include +#include +#include +#include + +struct ffa_device { + u32 vm_id; + uuid_t uuid; + struct device dev; + struct cdev cdev; +}; + +#define to_ffa_dev(d) container_of(d, struct ffa_device, dev) + +struct ffa_device_id { + uuid_t uuid; +}; + +struct ffa_driver { + const char *name; + int (*probe)(struct ffa_device *sdev); + void (*remove)(struct ffa_device *sdev); + const struct ffa_device_id *id_table; + + struct device_driver driver; +}; + +#define to_ffa_driver(d) container_of(d, struct ffa_driver, driver) + +#if IS_REACHABLE(CONFIG_ARM_FFA_TRANSPORT) +int ffa_device_register(struct ffa_device *ffa_dev); +void ffa_device_unregister(struct ffa_device *ffa_dev); +int ffa_driver_register(struct ffa_driver *driver, struct module *owner, + const char *mod_name); +void ffa_driver_unregister(struct ffa_driver *driver); + +#else +static inline int ffa_device_register(struct ffa_device *ffa_dev) +{ + return -EINVAL; +} + +static inline void ffa_device_unregister(struct ffa_device *dev) {} + +static inline int +ffa_driver_register(struct ffa_driver *driver, struct module *owner, + const char *mod_name) +{ + return -EINVAL; +} + +static inline void ffa_driver_unregister(struct ffa_driver *driver) {} + +#endif /* CONFIG_ARM_FFA_TRANSPORT */ + +#define ffa_register(driver) \ + ffa_driver_register(driver, THIS_MODULE, KBUILD_MODNAME) +#define ffa_unregister(driver) \ + ffa_driver_unregister(driver) + +/** + * module_ffa_driver() - Helper macro for registering a psa_ffa driver + * @__ffa_driver: ffa_driver structure + * + * Helper macro for psa_ffa drivers to set up proper module init / exit + * functions. Replaces module_init() and module_exit() and keeps people from + * printing pointless things to the kernel log when their driver is loaded. + */ +#define module_ffa_driver(__ffa_driver) \ + module_driver(__ffa_driver, ffa_register, ffa_unregister) + +#endif /* _LINUX_ARM_FFA_H */ From patchwork Tue Nov 3 17:43:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 314482 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AF7DC2D0A3 for ; Tue, 3 Nov 2020 17:44:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 421B921D91 for ; Tue, 3 Nov 2020 17:44:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729075AbgKCRoH (ORCPT ); Tue, 3 Nov 2020 12:44:07 -0500 Received: from foss.arm.com ([217.140.110.172]:53088 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727901AbgKCRoH (ORCPT ); Tue, 3 Nov 2020 12:44:07 -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 AE8BA1474; Tue, 3 Nov 2020 09:44:06 -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 2C6CC3F718; Tue, 3 Nov 2020 09:44:05 -0800 (PST) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Cc: Sudeep Holla , Trilok Soni , Trilok Soni , arve@android.com, Andrew Walbran , David Hartley , Achin Gupta , Android Kernel Team , Fuad Tabba Subject: [PATCH v2 5/9] firmware: arm_ffa: Add initial Arm FFA driver support Date: Tue, 3 Nov 2020 17:43:46 +0000 Message-Id: <20201103174350.991593-6-sudeep.holla@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103174350.991593-1-sudeep.holla@arm.com> References: <20201103174350.991593-1-sudeep.holla@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This just add a basic driver that sets up the transport(e.g. SMCCC), checks the FFA version implemented, get the partition ID for self and sets up the Tx/Rx buffers for communication. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/Makefile | 3 +- drivers/firmware/arm_ffa/bus.c | 12 +- drivers/firmware/arm_ffa/common.h | 26 ++++ drivers/firmware/arm_ffa/driver.c | 219 ++++++++++++++++++++++++++++++ include/linux/arm_ffa.h | 77 +++++++++++ 5 files changed, 326 insertions(+), 11 deletions(-) create mode 100644 drivers/firmware/arm_ffa/common.h create mode 100644 drivers/firmware/arm_ffa/driver.c diff --git a/drivers/firmware/arm_ffa/Makefile b/drivers/firmware/arm_ffa/Makefile index bfe4323a8784..82d0d35c5324 100644 --- a/drivers/firmware/arm_ffa/Makefile +++ b/drivers/firmware/arm_ffa/Makefile @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only ffa-bus-y = bus.o -ffa-module-objs := $(ffa-bus-y) +ffa-driver-y = driver.o +ffa-module-objs := $(ffa-bus-y) $(ffa-driver-y) obj-$(CONFIG_ARM_FFA_TRANSPORT) = ffa-module.o diff --git a/drivers/firmware/arm_ffa/bus.c b/drivers/firmware/arm_ffa/bus.c index 5d7102419e6c..2dbcf356bd8b 100644 --- a/drivers/firmware/arm_ffa/bus.c +++ b/drivers/firmware/arm_ffa/bus.c @@ -170,7 +170,7 @@ void ffa_device_unregister(struct ffa_device *ffa_dev) } EXPORT_SYMBOL_GPL(ffa_device_unregister); -static int __init arm_ffa_bus_init(void) +int __init arm_ffa_bus_init(void) { int ret; @@ -188,18 +188,10 @@ static int __init arm_ffa_bus_init(void) return ret; } -subsys_initcall(arm_ffa_bus_init); -static void __exit arm_ffa_bus_exit(void) +void __exit arm_ffa_bus_exit(void) { ffa_devices_unregister(); bus_unregister(&ffa_bus_type); unregister_chrdev_region(ffa_devt, FFA_MAX_CDEVS); } - -module_exit(arm_ffa_bus_exit); - -MODULE_ALIAS("arm-ffa-bus"); -MODULE_AUTHOR("Sudeep Holla "); -MODULE_DESCRIPTION("Arm FF-A bus driver"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/firmware/arm_ffa/common.h b/drivers/firmware/arm_ffa/common.h new file mode 100644 index 000000000000..fc6948efe9f3 --- /dev/null +++ b/drivers/firmware/arm_ffa/common.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2020 ARM Ltd. + */ + +#ifndef _FFA_COMMON_H +#define _FFA_COMMON_H + +#include +#include + +typedef struct arm_smccc_v1_2_res ffa_res_t; + +typedef ffa_res_t +(ffa_fn)(unsigned long, unsigned long, unsigned long, unsigned long, + unsigned long, unsigned long, unsigned long, unsigned long); + +int __init arm_ffa_bus_init(void); +void __exit arm_ffa_bus_exit(void); + +static inline int __init ffa_transport_init(ffa_fn **invoke_ffa_fn) +{ + return -EOPNOTSUPP; +} + +#endif /* _FFA_COMMON_H */ diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c new file mode 100644 index 000000000000..1c4a5e5095b5 --- /dev/null +++ b/drivers/firmware/arm_ffa/driver.c @@ -0,0 +1,219 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Arm Firmware Framework for ARMv8-A(FFA) interface driver + * + * The Arm FFA specification[1] describes a software architecture to + * leverages the virtualization extension to isolate software images + * provided by an ecosystem of vendors from each other and describes + * interfaces that standardize communication between the various software + * images including communication between images in the Secure world and + * Normal world. Any Hypervisor could use the FFA interfaces to enable + * communication between VMs it manages. + * + * The Hypervisor a.k.a Partition managers in FFA terminology can assign + * system resources(Memory regions, Devices, CPU cycles) to the partitions + * and manage isolation amongst them. + * + * [1] https://developer.arm.com/docs/den0077/latest + * + * Copyright (C) 2020 Arm Ltd. + */ + +#define DRIVER_NAME "ARM FF-A" +#define pr_fmt(fmt) DRIVER_NAME ": " fmt + +#include +#include +#include +#include +#include + +#include "common.h" + +#define FFA_DRIVER_VERSION FFA_VERSION_1_0 + +#define SENDER_ID_MASK GENMASK(31, 16) +#define RECEIVER_ID_MASK GENMASK(15, 0) +#define SENDER_ID(x) (u16)(FIELD_GET(SENDER_ID_MASK, (x))) +#define RECEIVER_ID(x) (u16)(FIELD_GET(RECEIVER_ID_MASK, (x))) +#define PACK_TARGET_INFO(s, r) \ + (FIELD_PREP(SENDER_ID_MASK, (s)) | FIELD_PREP(RECEIVER_ID_MASK, (r))) + +/** + * FF-A specification mentions explicitly about '4K pages'. This should + * not be confused with the kernel PAGE_SIZE, which is the translation + * granule kernel is configured and may be one among 4K, 16K and 64K. + */ +#define FFA_PAGE_SIZE SZ_4K +/* Keeping RX TX buffer size as 64K for now */ +#define RXTX_BUFFER_SIZE SZ_64K + +static ffa_fn *invoke_ffa_fn; + +static const int ffa_linux_errmap[] = { + /* better than switch case as long as return value is continuous */ + 0, /* FFA_RET_SUCCESS */ + -EOPNOTSUPP, /* FFA_RET_NOT_SUPPORTED */ + -EINVAL, /* FFA_RET_INVALID_PARAMETERS */ + -ENOMEM, /* FFA_RET_NO_MEMORY */ + -EBUSY, /* FFA_RET_BUSY */ + -EINTR, /* FFA_RET_INTERRUPTED */ + -EACCES, /* FFA_RET_DENIED */ + -EAGAIN, /* FFA_RET_RETRY */ + -ECANCELED, /* FFA_RET_ABORTED */ +}; + +static inline int ffa_to_linux_errno(int errno) +{ + if (errno < FFA_RET_SUCCESS && errno >= -ARRAY_SIZE(ffa_linux_errmap)) + return ffa_linux_errmap[-errno]; + return -EINVAL; +} + +struct ffa_drv_info { + u32 version; + u16 vm_id; + struct mutex rx_lock; /* lock to protect Rx buffer */ + struct mutex tx_lock; /* lock to protect Tx buffer */ + void *rx_buffer; + void *tx_buffer; +}; + +static struct ffa_drv_info *drv_info; + +static int ffa_version_check(u32 *version) +{ + ffa_res_t ver; + + ver = invoke_ffa_fn(FFA_VERSION, FFA_DRIVER_VERSION, 0, 0, 0, 0, 0, 0); + + if (ver.a0 == FFA_RET_NOT_SUPPORTED) { + pr_info("FFA_VERSION returned not supported\n"); + return -EOPNOTSUPP; + } + + if (ver.a0 < FFA_MIN_VERSION || ver.a0 > FFA_DRIVER_VERSION) { + pr_err("Incompatible version %d.%d found\n", + MAJOR_VERSION(ver.a0), MINOR_VERSION(ver.a0)); + return -EINVAL; + } + + *version = ver.a0; + pr_info("Version %d.%d found\n", MAJOR_VERSION(ver.a0), + MINOR_VERSION(ver.a0)); + return 0; +} + +static int ffa_rxtx_map(phys_addr_t tx_buf, phys_addr_t rx_buf, u32 pg_cnt) +{ + ffa_res_t ret; + + ret = invoke_ffa_fn(FFA_RXTX_MAP, tx_buf, rx_buf, pg_cnt, 0, 0, 0, 0); + + if (ret.a0 == FFA_ERROR) + return ffa_to_linux_errno((int)ret.a2); + + return 0; +} + +static int ffa_rxtx_unmap(u16 vm_id) +{ + ffa_res_t ret; + + ret = invoke_ffa_fn(FFA_RXTX_UNMAP, vm_id, 0, 0, 0, 0, 0, 0); + + if (ret.a0 == FFA_ERROR) + return ffa_to_linux_errno((int)ret.a2); + + return 0; +} + +#define VM_ID_MASK GENMASK(15, 0) +static int ffa_id_get(u16 *vm_id) +{ + ffa_res_t id; + + id = invoke_ffa_fn(FFA_ID_GET, 0, 0, 0, 0, 0, 0, 0); + + if (id.a0 == FFA_ERROR) + return ffa_to_linux_errno((int)id.a2); + + *vm_id = FIELD_GET(VM_ID_MASK, (id.a2)); + + return 0; +} + +static int __init ffa_init(void) +{ + int ret; + + ret = arm_ffa_bus_init(); + if (ret) + return ret; + + ret = ffa_transport_init(&invoke_ffa_fn); + if (ret) + return ret; + + drv_info = kzalloc(sizeof(*drv_info), GFP_KERNEL); + if (!drv_info) + return -ENOMEM; + + ret = ffa_version_check(&drv_info->version); + if (ret) + goto free_drv_info; + + if (ffa_id_get(&drv_info->vm_id)) { + pr_err("failed to obtain VM id for self\n"); + ret = -ENODEV; + goto free_drv_info; + } + + drv_info->rx_buffer = alloc_pages_exact(RXTX_BUFFER_SIZE, GFP_KERNEL); + if (!drv_info->rx_buffer) { + ret = -ENOMEM; + goto free_pages; + } + + drv_info->tx_buffer = alloc_pages_exact(RXTX_BUFFER_SIZE, GFP_KERNEL); + if (!drv_info->tx_buffer) { + ret = -ENOMEM; + goto free_pages; + } + + ret = ffa_rxtx_map(virt_to_phys(drv_info->tx_buffer), + virt_to_phys(drv_info->rx_buffer), + RXTX_BUFFER_SIZE / FFA_PAGE_SIZE); + if (ret) { + pr_err("failed to register FFA RxTx buffers\n"); + goto free_pages; + } + + mutex_init(&drv_info->rx_lock); + mutex_init(&drv_info->tx_lock); + + return 0; +free_pages: + if (drv_info->tx_buffer) + free_pages_exact(drv_info->tx_buffer, RXTX_BUFFER_SIZE); + free_pages_exact(drv_info->rx_buffer, RXTX_BUFFER_SIZE); +free_drv_info: + kfree(drv_info); + return ret; +} +module_init(ffa_init); + +static void __exit ffa_exit(void) +{ + ffa_rxtx_unmap(drv_info->vm_id); + free_pages_exact(drv_info->tx_buffer, RXTX_BUFFER_SIZE); + free_pages_exact(drv_info->rx_buffer, RXTX_BUFFER_SIZE); + kfree(drv_info); + arm_ffa_bus_exit(); +} +module_exit(ffa_exit); + +MODULE_ALIAS("arm-ffa"); +MODULE_AUTHOR("Sudeep Holla "); +MODULE_DESCRIPTION("Arm FF-A interface driver"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h index 2fe16176149f..6185d0d12f15 100644 --- a/include/linux/arm_ffa.h +++ b/include/linux/arm_ffa.h @@ -12,6 +12,83 @@ #include #include +#define FFA_SMC(calling_convention, func_num) \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, (calling_convention), \ + ARM_SMCCC_OWNER_STANDARD, (func_num)) + +#define FFA_SMC_32(func_num) FFA_SMC(ARM_SMCCC_SMC_32, (func_num)) +#define FFA_SMC_64(func_num) FFA_SMC(ARM_SMCCC_SMC_64, (func_num)) + +#define FFA_ERROR FFA_SMC_32(0x60) +#define FFA_SUCCESS FFA_SMC_32(0x61) +#define FFA_INTERRUPT FFA_SMC_32(0x62) +#define FFA_VERSION FFA_SMC_32(0x63) +#define FFA_FEATURES FFA_SMC_32(0x64) +#define FFA_RX_RELEASE FFA_SMC_32(0x65) +#define FFA_RXTX_MAP FFA_SMC_32(0x66) +#define FFA_RXTX_UNMAP FFA_SMC_32(0x67) +#define FFA_PARTITION_INFO_GET FFA_SMC_32(0x68) +#define FFA_ID_GET FFA_SMC_32(0x69) +#define FFA_MSG_POLL FFA_SMC_32(0x6A) +#define FFA_MSG_WAIT FFA_SMC_32(0x6B) +#define FFA_YIELD FFA_SMC_32(0x6C) +#define FFA_RUN FFA_SMC_32(0x6D) +#define FFA_MSG_SEND FFA_SMC_32(0x6E) +#define FFA_MSG_SEND_DIRECT_REQ FFA_SMC_32(0x6F) +#define FFA_FN64_MSG_SEND_DIRECT_REQ FFA_SMC_64(0x6F) +#define FFA_MSG_SEND_DIRECT_RESP FFA_SMC_32(0x70) +#define FFA_FN64_MSG_SEND_DIRECT_RESP FFA_SMC_64(0x70) +#define FFA_MEM_DONATE FFA_SMC_32(0x71) +#define FFA_FN64_MEM_DONATE FFA_SMC_32(0x71) +#define FFA_MEM_LEND FFA_SMC_32(0x72) +#define FFA_FN64_MEM_LEND FFA_SMC_32(0x72) +#define FFA_MEM_SHARE FFA_SMC_32(0x73) +#define FFA_FN64_MEM_SHARE FFA_SMC_64(0x73) +#define FFA_MEM_RETRIEVE_REQ FFA_SMC_32(0x74) +#define FFA_FN64_MEM_RETRIEVE_REQ FFA_SMC_64(0x74) +#define FFA_MEM_RETRIEVE_RESP FFA_SMC_32(0x75) +#define FFA_MEM_RELINQUISH FFA_SMC_32(0x76) +#define FFA_MEM_RECLAIM FFA_SMC_32(0x77) +#define FFA_MEM_OP_PAUSE FFA_SMC_32(0x78) +#define FFA_MEM_OP_RESUME FFA_SMC_32(0x79) +#define FFA_MEM_FRAG_RX FFA_SMC_32(0x7A) +#define FFA_MEM_FRAG_TX FFA_SMC_32(0x7B) +#define FFA_NORMAL_WORLD_RESUME FFA_SMC_32(0x7C) + +/* + * For some calls it is necessary to use SMC64 to pass or return 64-bit values. + * For such calls FFA_FN_NATIVE(name) will choose the appropriate + * (native-width) function ID. + */ +#ifdef CONFIG_64BIT +#define FFA_FN_NATIVE(name) FFA_FN64_##name +#else +#define FFA_FN_NATIVE(name) FFA_##name +#endif + +/* FFA error codes. */ +#define FFA_RET_SUCCESS (0) +#define FFA_RET_NOT_SUPPORTED (-1) +#define FFA_RET_INVALID_PARAMETERS (-2) +#define FFA_RET_NO_MEMORY (-3) +#define FFA_RET_BUSY (-4) +#define FFA_RET_INTERRUPTED (-5) +#define FFA_RET_DENIED (-6) +#define FFA_RET_RETRY (-7) +#define FFA_RET_ABORTED (-8) + +#define MAJOR_VERSION_MASK GENMASK(30, 16) +#define MINOR_VERSION_MASK GENMASK(15, 0) +#define MAJOR_VERSION(x) (u16)(FIELD_GET(MAJOR_VERSION_MASK, (x))) +#define MINOR_VERSION(x) (u16)(FIELD_GET(MINOR_VERSION_MASK, (x))) +#define PACK_VERSION_INFO(major, minor) \ + (FIELD_PREP(MAJOR_VERSION_MASK, (major)) | \ + FIELD_PREP(MINOR_VERSION_MASK, (minor))) +#define FFA_VERSION_1_0 PACK_VERSION_INFO(1, 0) +#define FFA_MIN_VERSION FFA_VERSION_1_0 + +/* FFA Device/Bus related */ + struct ffa_device { u32 vm_id; uuid_t uuid; From patchwork Tue Nov 3 17:43:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 320443 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp4779640ilc; Tue, 3 Nov 2020 09:44:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJwftfzsHOCcpuuf/bDOrcRZlpRjSuBp+FcAj3YRgy3P0X2syhiAQTe5D7oO0uxupFID4gsd X-Received: by 2002:a17:906:b841:: with SMTP id ga1mr20984494ejb.29.1604425449968; Tue, 03 Nov 2020 09:44:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604425449; cv=none; d=google.com; s=arc-20160816; b=FamdO7FXiHFqfq28fgWXbWQtQ7Ecgx9z9VSW+U5+APZ2wQvig/yF+yByaxQKDX5zBO ezsu+xhZonh1eh5eXVK+jgP23oBIBOCuMn/JLWg+jAJYS8f/KmCIQ243g8CoUxtY8DUM YSSnNt5z62QUPUmc01Trlwgw2DNFUSjNFxkqU2kAldEUt8mYiK/BZ/XNw3eh1ZhbZ7kH i14XZixz3e9NK9d4k8rxnYL5C6DCHBPembYUuIUUBXdlaDskjFojVUA8vFsqZEDMts/2 0BpNS81PDz9dVn63eZWgYSZnIfyfAOvy8kPECYNGP6RoddEOcOuAEp/K8YukE1VsmDx8 C/+Q== 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=MGVR+Qi13ExKEDSuTWzfXeXtet7sGYQpbhR4lWndFim5wtNylFM2CeEptTsBBQ3Dzw y+6FTb7vqi9iDBGeN6P+FEKajxFJEvuLocnT19ak+OqKJAZpGQzzojiPvcABUxAftVzT z6k2VtN+YXIRttc81IGJ6QR8VSKzCvcqslpsFXwto0FEcVAkV3YKDdwHfCCvx3G4cKFs dzQ4Q00RbGgGRJKEDoSNb7ZbOKlpKI4wk09iyEfbTjrJdDNYUY8UjZn9AJcbc1G5Y1i2 Ksk/sOTOkKWG63Ee7kUgkk7n3U9GBljFLuVpiCZpnEEMhhNEMDbsw8H6cWfjn75psv3D SYOg== 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 n13si13469090eda.416.2020.11.03.09.44.09; Tue, 03 Nov 2020 09:44:09 -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 S1729017AbgKCRoJ (ORCPT + 6 others); Tue, 3 Nov 2020 12:44:09 -0500 Received: from foss.arm.com ([217.140.110.172]:53102 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727901AbgKCRoI (ORCPT ); Tue, 3 Nov 2020 12:44:08 -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 64029147A; Tue, 3 Nov 2020 09:44:08 -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 E77273F718; Tue, 3 Nov 2020 09:44:06 -0800 (PST) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Cc: Sudeep Holla , Trilok Soni , Trilok Soni , arve@android.com, Andrew Walbran , David Hartley , Achin Gupta , Android Kernel Team , Fuad Tabba Subject: [PATCH v2 6/9] firmware: arm_ffa: Add support for SMCCC as transport to FFA driver Date: Tue, 3 Nov 2020 17:43:47 +0000 Message-Id: <20201103174350.991593-7-sudeep.holla@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103174350.991593-1-sudeep.holla@arm.com> References: <20201103174350.991593-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; +} From patchwork Tue Nov 3 17:43:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 314481 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CFF1C388F7 for ; Tue, 3 Nov 2020 17:44:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B13CA21D91 for ; Tue, 3 Nov 2020 17:44:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729037AbgKCRoL (ORCPT ); Tue, 3 Nov 2020 12:44:11 -0500 Received: from foss.arm.com ([217.140.110.172]:53126 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727901AbgKCRoL (ORCPT ); Tue, 3 Nov 2020 12:44:11 -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 17B2B1480; Tue, 3 Nov 2020 09:44:10 -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 98F043F718; Tue, 3 Nov 2020 09:44:08 -0800 (PST) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Cc: Sudeep Holla , Trilok Soni , Trilok Soni , arve@android.com, Andrew Walbran , David Hartley , Achin Gupta , Android Kernel Team , Fuad Tabba Subject: [PATCH v2 7/9] firmware: arm_ffa: Setup in-kernel users of FFA partitions Date: Tue, 3 Nov 2020 17:43:48 +0000 Message-Id: <20201103174350.991593-8-sudeep.holla@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103174350.991593-1-sudeep.holla@arm.com> References: <20201103174350.991593-1-sudeep.holla@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Parse the FFA nodes from the device-tree and register all the partitions whose services will be used in the kernel. In order to also enable in-kernel users of FFA interface, let us add simple set of operations for such devices. The in-kernel users are registered without the character device interface. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/bus.c | 2 + drivers/firmware/arm_ffa/driver.c | 281 ++++++++++++++++++++++++++++++ include/linux/arm_ffa.h | 15 ++ include/uapi/linux/arm_ffa.h | 56 ++++++ 4 files changed, 354 insertions(+) create mode 100644 include/uapi/linux/arm_ffa.h diff --git a/drivers/firmware/arm_ffa/bus.c b/drivers/firmware/arm_ffa/bus.c index 2dbcf356bd8b..de4f8b54271a 100644 --- a/drivers/firmware/arm_ffa/bus.c +++ b/drivers/firmware/arm_ffa/bus.c @@ -90,6 +90,7 @@ static void ffa_release_device(struct device *dev) { struct ffa_device *ffa_dev = to_ffa_dev(dev); + mutex_destroy(&ffa_dev->mutex); kfree(ffa_dev); } @@ -127,6 +128,7 @@ int ffa_device_register(struct ffa_device *ffa_dev) dev = &ffa_dev->dev; cdev = &ffa_dev->cdev; + mutex_init(&ffa_dev->mutex); dev->bus = &ffa_bus_type; dev->type = &ffa_dev_type; diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 1c4a5e5095b5..2e5fa56fffb7 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -24,9 +24,16 @@ #include #include +#include +#include #include +#include #include +#include #include +#include +#include +#include #include "common.h" @@ -48,6 +55,13 @@ /* Keeping RX TX buffer size as 64K for now */ #define RXTX_BUFFER_SIZE SZ_64K +#define list_to_ffa_dev(n) container_of(n, struct ffa_device, node) + +/* List of all FFA devices active in system */ +static LIST_HEAD(ffa_devs_list); +/* Protection for the entire list */ +static DEFINE_MUTEX(ffa_devs_list_mutex); + static ffa_fn *invoke_ffa_fn; static const int ffa_linux_errmap[] = { @@ -104,6 +118,20 @@ static int ffa_version_check(u32 *version) return 0; } +static int ffa_rx_release(void) +{ + ffa_res_t ret; + + ret = invoke_ffa_fn(FFA_RX_RELEASE, 0, 0, 0, 0, 0, 0, 0); + + if (ret.a0 == FFA_ERROR) + return ffa_to_linux_errno((int)ret.a2); + + /* check for ret.a0 == FFA_RX_RELEASE ? */ + + return 0; +} + static int ffa_rxtx_map(phys_addr_t tx_buf, phys_addr_t rx_buf, u32 pg_cnt) { ffa_res_t ret; @@ -128,6 +156,50 @@ static int ffa_rxtx_unmap(u16 vm_id) return 0; } +static int ffa_partition_info_get(u32 uuid0, u32 uuid1, u32 uuid2, u32 uuid3, + struct ffa_partition_info **buffer) +{ + int count; + ffa_res_t partition_info; + + mutex_lock(&drv_info->rx_lock); + partition_info = invoke_ffa_fn(FFA_PARTITION_INFO_GET, uuid0, uuid1, + uuid2, uuid3, 0, 0, 0); + + if (partition_info.a0 == FFA_ERROR) + return ffa_to_linux_errno((int)partition_info.a2); + + count = partition_info.a2; + + if (buffer) + memcpy(*buffer, drv_info->rx_buffer, sizeof(*buffer) * count); + + ffa_rx_release(); + + mutex_unlock(&drv_info->rx_lock); + + return count; +} + +static int ffa_partition_probe(const char *uuid_str, + struct ffa_partition_info *buffer) +{ + int count; + uuid_t uuid; + u32 uuid0_4[4] = { 0 }; + + if (uuid_parse(uuid_str, &uuid)) { + pr_err("invalid uuid (%s)\n", uuid_str); + return -ENODEV; + } + + export_uuid((u8 *)uuid0_4, &uuid); + count = ffa_partition_info_get(uuid0_4[0], uuid0_4[1], uuid0_4[2], + uuid0_4[3], &buffer); + + return count; +} + #define VM_ID_MASK GENMASK(15, 0) static int ffa_id_get(u16 *vm_id) { @@ -143,6 +215,205 @@ static int ffa_id_get(u16 *vm_id) return 0; } +static int ffa_msg_send_direct_req(u16 src_id, u16 dst_id, + struct ffa_send_direct_data *data) +{ + u32 src_dst_ids = PACK_TARGET_INFO(src_id, dst_id); + ffa_res_t ret; + + ret = invoke_ffa_fn(FFA_FN_NATIVE(MSG_SEND_DIRECT_REQ), src_dst_ids, 0, + data->data0, data->data1, data->data2, + data->data3, data->data4); + + while (ret.a0 == FFA_INTERRUPT) + ret = invoke_ffa_fn(FFA_RUN, ret.a1, 0, 0, 0, 0, 0, 0); + if (ret.a0 == FFA_ERROR) + return ffa_to_linux_errno((int)ret.a2); + + if (ret.a0 == FFA_FN_NATIVE(MSG_SEND_DIRECT_RESP)) { + data->data0 = ret.a3; + data->data1 = ret.a4; + data->data2 = ret.a5; + data->data3 = ret.a6; + data->data4 = ret.a7; + } + + return 0; +} + +static void ffa_device_get(struct ffa_device *ffa_dev) +{ + mutex_lock(&ffa_dev->mutex); + ffa_dev->num_users++; + mutex_unlock(&ffa_dev->mutex); +} + +static void ffa_device_put(struct ffa_device *ffa_dev) +{ + mutex_lock(&ffa_dev->mutex); + ffa_dev->num_users--; + mutex_unlock(&ffa_dev->mutex); +} + +static const struct ffa_dev_ops ffa_ops; + +const struct ffa_dev_ops *ffa_dev_ops_get(struct ffa_device *dev) +{ + struct list_head *p; + const struct ffa_dev_ops *ops = NULL; + + if (uuid_is_null(&dev->uuid)) + return NULL; + + mutex_lock(&ffa_devs_list_mutex); + + list_for_each(p, &ffa_devs_list) { + struct ffa_device *tmp_dev; + + tmp_dev = list_to_ffa_dev(p); + + if (uuid_equal(&tmp_dev->uuid, &dev->uuid)) { + ops = &ffa_ops; + break; + } + } + + mutex_unlock(&ffa_devs_list_mutex); + + return ops; +} + +static int ffa_dev_open(struct ffa_device *ffa_dev) +{ + ffa_device_get(ffa_dev); + + return 0; +} + +static int ffa_dev_close(struct ffa_device *ffa_dev) +{ + ffa_device_put(ffa_dev); + + return 0; +} + +static long +ffa_dev_ioctl(struct ffa_device *ffa_dev, unsigned int ioctl, void *arg) +{ + long r = -EINVAL; + + switch (ioctl) { + case FFA_GET_API_VERSION: + return drv_info->version; + case FFA_GET_PARTITION_ID: + return ffa_dev->vm_id; + case FFA_GET_PARTITION_INFO: { + struct ffa_part_info *pinfo = arg; + + if (ffa_partition_probe(pinfo->uuid_str, &pinfo->info) != 1) + r = -E2BIG; + break; + } + case FFA_SEND_RECEIVE_SYNC: { + struct ffa_send_recv_sync *kdata = arg; + + r = ffa_msg_send_direct_req(ffa_dev->vm_id, kdata->endpoint_id, + &kdata->data); + break; + } + default: + r = -EINVAL; + } + + return r; +} + +static const struct ffa_dev_ops ffa_ops = { + .open = ffa_dev_open, + .close = ffa_dev_close, + .ioctl = ffa_dev_ioctl, +}; + +static int ffa_device_alloc_register(const char *name, u16 vm_id, uuid_t *uuid, + const struct file_operations *fops) +{ + int ret; + struct ffa_device *ffa_dev; + + ffa_dev = kzalloc(sizeof(*ffa_dev), GFP_KERNEL); + if (!ffa_dev) + return -ENOMEM; + + ffa_dev->vm_id = vm_id; + if (uuid) + uuid_copy(&ffa_dev->uuid, uuid); + + dev_set_name(&ffa_dev->dev, name); + dev_set_drvdata(&ffa_dev->dev, drv_info); + cdev_init(&ffa_dev->cdev, fops); + + ret = ffa_device_register(ffa_dev); + if (ret) + return ret; + + mutex_lock(&ffa_devs_list_mutex); + list_add_tail(&ffa_dev->node, &ffa_devs_list); + mutex_unlock(&ffa_devs_list_mutex); + + return 0; +} + +int ffa_setup_partitions(const char *compatible, + const struct file_operations *fops) +{ + int ret; + struct ffa_partition_info pbuf; + struct device_node *child, *parent; + const char *p_uuid, *pfx = "Ignoring FFA partition"; + uuid_t uuid = UUID_INIT(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + + parent = of_find_compatible_node(NULL, NULL, compatible); + if (!parent) + return 0; + + for_each_child_of_node(parent, child) { + if (!of_device_is_compatible(child, "arm,ffa-1.0-partition")) { + of_node_put(child); + continue; + } + + if (of_property_read_string(child, "uuid", &p_uuid)) { + pr_err("%s: failed to parse \"uuid\" property\n", pfx); + of_node_put(child); + continue; + } + + of_node_put(child); + + if (uuid_parse(p_uuid, &uuid)) { + pr_err("%s: invalid \"uuid\" property (%s)\n", + pfx, p_uuid); + continue; + } + + ret = ffa_partition_probe(p_uuid, &pbuf); + if (ret != 1) { + pr_err("%s: %s partition info probe failed\n", + pfx, p_uuid); + return -EINVAL; + } + + ret = ffa_device_alloc_register(p_uuid, pbuf.id, &uuid, fops); + if (ret) { + pr_err("%s: failed to register %s\n", pfx, p_uuid); + continue; + } + } + + of_node_put(parent); + return 0; +} + static int __init ffa_init(void) { int ret; @@ -192,6 +463,9 @@ static int __init ffa_init(void) mutex_init(&drv_info->rx_lock); mutex_init(&drv_info->tx_lock); + /* Set up all the partitions which have in-kernel drivers */ + ffa_setup_partitions("arm,ffa-1.0", NULL); + return 0; free_pages: if (drv_info->tx_buffer) @@ -205,6 +479,13 @@ module_init(ffa_init); static void __exit ffa_exit(void) { + struct list_head *p; + + mutex_lock(&ffa_devs_list_mutex); + list_for_each(p, &ffa_devs_list) + ffa_device_unregister(list_to_ffa_dev(p)); + mutex_unlock(&ffa_devs_list_mutex); + ffa_rxtx_unmap(drv_info->vm_id); free_pages_exact(drv_info->tx_buffer, RXTX_BUFFER_SIZE); free_pages_exact(drv_info->rx_buffer, RXTX_BUFFER_SIZE); diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h index 6185d0d12f15..719ef02fe42d 100644 --- a/include/linux/arm_ffa.h +++ b/include/linux/arm_ffa.h @@ -11,6 +11,7 @@ #include #include #include +#include #define FFA_SMC(calling_convention, func_num) \ ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, (calling_convention), \ @@ -94,6 +95,9 @@ struct ffa_device { uuid_t uuid; struct device dev; struct cdev cdev; + size_t num_users; + struct mutex mutex; /* protects num_users */ + struct list_head node; }; #define to_ffa_dev(d) container_of(d, struct ffa_device, dev) @@ -113,12 +117,19 @@ struct ffa_driver { #define to_ffa_driver(d) container_of(d, struct ffa_driver, driver) +struct ffa_dev_ops { + int (*open)(struct ffa_device *dev); + int (*close)(struct ffa_device *dev); + long (*ioctl)(struct ffa_device *dev, unsigned int ioctl, void *arg); +}; + #if IS_REACHABLE(CONFIG_ARM_FFA_TRANSPORT) int ffa_device_register(struct ffa_device *ffa_dev); void ffa_device_unregister(struct ffa_device *ffa_dev); int ffa_driver_register(struct ffa_driver *driver, struct module *owner, const char *mod_name); void ffa_driver_unregister(struct ffa_driver *driver); +const struct ffa_dev_ops *ffa_dev_ops_get(struct ffa_device *dev); #else static inline int ffa_device_register(struct ffa_device *ffa_dev) @@ -137,6 +148,10 @@ ffa_driver_register(struct ffa_driver *driver, struct module *owner, static inline void ffa_driver_unregister(struct ffa_driver *driver) {} +const struct ffa_dev_ops *ffa_dev_ops_get(struct ffa_device *dev) +{ + return NULL; +} #endif /* CONFIG_ARM_FFA_TRANSPORT */ #define ffa_register(driver) \ diff --git a/include/uapi/linux/arm_ffa.h b/include/uapi/linux/arm_ffa.h new file mode 100644 index 000000000000..88ddddb4742f --- /dev/null +++ b/include/uapi/linux/arm_ffa.h @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Copyright (C) 2020 Arm Ltd. + */ + +#ifndef _UAPI_LINUX_ARM_FFA_H +#define _UAPI_LINUX_ARM_FFA_H + +#include +#include + +#define FFA_BASE 0xFF + +struct ffa_partition_info { + __u16 id; + __u16 exec_ctxt; +/* partition supports receipt of direct requests */ +#define FFA_PARTITION_DIRECT_RECV BIT(0) +/* partition can send direct requests. */ +#define FFA_PARTITION_DIRECT_SEND BIT(1) +/* partition can send and receive indirect messages. */ +#define FFA_PARTITION_INDIRECT_MSG BIT(2) + __u32 properties; +}; + +struct ffa_part_info { + char uuid_str[36]; + struct ffa_partition_info info; +}; + +struct ffa_send_direct_data { + unsigned long data0; + unsigned long data1; + unsigned long data2; + unsigned long data3; + unsigned long data4; +}; + +struct ffa_send_recv_sync { + __u16 endpoint_id; + struct ffa_send_direct_data data; +}; + +struct ffa_send_recv_async { + __u16 endpoint_id; + int length; + char buffer[]; +}; + +#define FFA_GET_API_VERSION _IO(FFA_BASE, 0x00) +#define FFA_GET_PARTITION_ID _IO(FFA_BASE, 0x01) +#define FFA_GET_PARTITION_INFO _IOWR(FFA_BASE, 0x02, struct ffa_part_info) +#define FFA_SEND_RECEIVE_SYNC _IOWR(FFA_BASE, 0x03, struct ffa_send_recv_sync) +#define FFA_SEND_RECEIVE_ASYNC _IOW(FFA_BASE, 0x04, struct ffa_send_recv_async) + +#endif /*_UAPI_LINUX_ARM_FFA_H*/ From patchwork Tue Nov 3 17:43:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 320445 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp4779681ilc; Tue, 3 Nov 2020 09:44:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJyGVxSZcxBEsjaScaRaPxSvObdaAgZPr8wLpMZ1ez4KrWE8Cd58+p6WaLQt0LLllM4eecCc X-Received: by 2002:a17:906:1614:: with SMTP id m20mr20851206ejd.258.1604425453525; Tue, 03 Nov 2020 09:44:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604425453; cv=none; d=google.com; s=arc-20160816; b=lNb+u6Js34F55ZD1g9iCvWJsMPc6x5YX7d9Lz4Us2p9zymwFuN/XB5O9AqNKmtdM9J TZDNpHYpGZubVam/gTp73M9WEjgAIW2Vli+QOCn30T/FJD3kHYiIyWlaewlIN/u4y9OV HzJZeK6nKfCywN1gb0opsO5yv8VRxckLIlX77NCAhK22aK0p1GbsrG6NWXGq1KhbAssV o8z34FLOOgcvyGq8FVAG99DLFwCPBezuGAtVdhz9krGzXhehe+vdWrr1nZuLeU7HRC32 T6hCcSTbXdp75AhVAmepzQJRUaGlQ6qNz9JvIXV142VqREekh9Bk7M4GNpVnuhbySlGt eWUg== 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=vATmPs7/ha+iR/67R95LtMISq2ytqo/PIyLFrnAorqo=; b=Qi7bCqHx+NbdL7V2ta3V/RhYDAIYh2gifS9/TZ9hfwxbMDSzwDW0NzDlEdNNRxrAD8 sCsMF6HW/N1xI9ePcs79e/i1zjzaNX0CTg4XB85xCaFMF8wIg8JMdFVavDSetQnUuIkg 9x2i3X5pLNSxC+mVIw4Weeu1MVw4OOZeeOXW7/2dDdN885EQnenbdxP5bg3epGPlu+3C ajPWCiKMa80VysAeBOezG3tHxAeJitK9RBZKz1Ddord85Bo68QX3ic7CmeLhskp8i/Jf MmGvkYpuoj81i08sFPYeW2yyD9n/uziIcgQZUhDExueEMyBaRrPFjWlbS5v3iWiax1wC cXQQ== 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 n13si13469090eda.416.2020.11.03.09.44.13; Tue, 03 Nov 2020 09:44:13 -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 S1729069AbgKCRoM (ORCPT + 6 others); Tue, 3 Nov 2020 12:44:12 -0500 Received: from foss.arm.com ([217.140.110.172]:53138 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727901AbgKCRoM (ORCPT ); Tue, 3 Nov 2020 12:44:12 -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 BC9B91500; Tue, 3 Nov 2020 09:44:11 -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 4CA483F718; Tue, 3 Nov 2020 09:44:10 -0800 (PST) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Cc: Sudeep Holla , Trilok Soni , Trilok Soni , arve@android.com, Andrew Walbran , David Hartley , Achin Gupta , Android Kernel Team , Fuad Tabba Subject: [PATCH v2 8/9] firmware: arm_ffa: Setup and register all the KVM managed partitions Date: Tue, 3 Nov 2020 17:43:49 +0000 Message-Id: <20201103174350.991593-9-sudeep.holla@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103174350.991593-1-sudeep.holla@arm.com> References: <20201103174350.991593-1-sudeep.holla@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Parse the FFA nodes from the device-tree and register all the partitions managed by the KVM hypervisor. All the partitions including the host(self) are registered as the character device with a set of file operations. Most of the interface will concentrated in the ioctl. For now, we have a tiny set of initial ioctls implemented. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/Makefile | 2 +- drivers/firmware/arm_ffa/common.h | 5 + drivers/firmware/arm_ffa/driver.c | 27 +++++ drivers/firmware/arm_ffa/hyp_partitions.c | 132 ++++++++++++++++++++++ 4 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 drivers/firmware/arm_ffa/hyp_partitions.c -- 2.25.1 diff --git a/drivers/firmware/arm_ffa/Makefile b/drivers/firmware/arm_ffa/Makefile index 9d9f37523200..eac280c27cac 100644 --- a/drivers/firmware/arm_ffa/Makefile +++ b/drivers/firmware/arm_ffa/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only ffa-bus-y = bus.o -ffa-driver-y = driver.o +ffa-driver-y = driver.o hyp_partitions.o 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 d019348bf67d..12bb960deb09 100644 --- a/drivers/firmware/arm_ffa/common.h +++ b/drivers/firmware/arm_ffa/common.h @@ -8,6 +8,7 @@ #include #include +#include typedef struct arm_smccc_v1_2_res ffa_res_t; @@ -15,8 +16,12 @@ typedef ffa_res_t (ffa_fn)(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long); +int __init ffa_hyp_partitions_init(void); int __init arm_ffa_bus_init(void); void __exit arm_ffa_bus_exit(void); +struct ffa_device *ffa_device_get_from_minor(int minor); +int ffa_setup_partitions(const char *compatible, + const struct file_operations *fops); #ifdef CONFIG_ARM_FFA_SMCCC int __init ffa_transport_init(ffa_fn **invoke_ffa_fn); diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 2e5fa56fffb7..0aa3e4d02896 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -241,6 +241,31 @@ static int ffa_msg_send_direct_req(u16 src_id, u16 dst_id, return 0; } +struct ffa_device *ffa_device_get_from_minor(int minor) +{ + struct list_head *p; + struct ffa_device *ffa_dev = NULL; + + mutex_lock(&ffa_devs_list_mutex); + + list_for_each(p, &ffa_devs_list) { + struct device *dev; + struct ffa_device *tmp_dev; + + tmp_dev = list_to_ffa_dev(p); + dev = &tmp_dev->dev; + + if (minor == MINOR(dev->devt)) { + ffa_dev = tmp_dev; + break; + } + } + + mutex_unlock(&ffa_devs_list_mutex); + + return ffa_dev; +} + static void ffa_device_get(struct ffa_device *ffa_dev) { mutex_lock(&ffa_dev->mutex); @@ -466,6 +491,8 @@ static int __init ffa_init(void) /* Set up all the partitions which have in-kernel drivers */ ffa_setup_partitions("arm,ffa-1.0", NULL); + ffa_hyp_partitions_init(); + return 0; free_pages: if (drv_info->tx_buffer) diff --git a/drivers/firmware/arm_ffa/hyp_partitions.c b/drivers/firmware/arm_ffa/hyp_partitions.c new file mode 100644 index 000000000000..985f66d4322b --- /dev/null +++ b/drivers/firmware/arm_ffa/hyp_partitions.c @@ -0,0 +1,132 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Arm Firmware Framework for ARMv8-A(FFA) userspace interface + * + * Copyright (C) 2020 Arm Ltd. + */ + +#define pr_fmt(fmt) "ARM FF-A USER : " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "common.h" + +struct ffa_dev_data { + struct ffa_device *dev; + const struct ffa_dev_ops *ops; +}; + +static int ffa_open(struct inode *inode, struct file *filp) +{ + struct ffa_dev_data *ffa_data; + + ffa_data = kzalloc(sizeof(*ffa_data), GFP_KERNEL); + if (!ffa_data) + return -ENOMEM; + + ffa_data->dev = ffa_device_get_from_minor(iminor(inode)); + if (!ffa_data->dev) { + kfree(ffa_data); + return -EINVAL; + } + + ffa_data->ops = ffa_dev_ops_get(ffa_data->dev); + if (!ffa_data->ops) { + kfree(ffa_data); + return -EINVAL; + } + + ffa_data->ops->open(ffa_data->dev); + + filp->private_data = ffa_data; + + return 0; +} + +static int ffa_release(struct inode *inode, struct file *filp) +{ + struct ffa_dev_data *ffa_data = filp->private_data; + + ffa_data->ops->close(ffa_data->dev); + + filp->private_data = NULL; + kfree(ffa_data); + + return 0; +} + +static long ffa_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) +{ + long r = -EINVAL; + void __user *argp = (void __user *)arg; + struct ffa_dev_data *ffa_data = filp->private_data; + struct ffa_device *ffa_dev = ffa_data->dev; + + switch (ioctl) { + case FFA_GET_API_VERSION: + case FFA_GET_PARTITION_ID: + if (arg) + return r; + return ffa_data->ops->ioctl(ffa_dev, ioctl, NULL); + case FFA_GET_PARTITION_INFO: { + struct ffa_part_info __user *pinfo = argp; + struct ffa_part_info info; + unsigned int count; + + r = -EFAULT; + if (copy_from_user(&info, pinfo, sizeof(info))) + break; + count = ffa_data->ops->ioctl(ffa_dev, ioctl, &info); + if (count > 1) { + r = -E2BIG; + break; + } + r = -EFAULT; + if (copy_to_user(pinfo, &info, sizeof(info))) + break; + r = 0; + break; + } + case FFA_SEND_RECEIVE_SYNC: { + struct ffa_send_recv_sync __user *udata = argp; + struct ffa_send_recv_sync kdata; + + r = -EFAULT; + if (copy_from_user(&kdata, udata, sizeof(kdata))) + break; + r = ffa_data->ops->ioctl(ffa_dev, ioctl, &kdata); + if (r) + break; + if (copy_to_user(udata, &kdata, sizeof(kdata))) + break; + break; + } + default: + r = -EINVAL; + } + return r; +} + +static const struct file_operations ffa_fops = { + .owner = THIS_MODULE, + .open = ffa_open, + .release = ffa_release, + .unlocked_ioctl = ffa_ioctl, + .llseek = noop_llseek, +}; + +int __init ffa_hyp_partitions_init(void) +{ + /* Set up all the partitions that KVM hypervisor maintains */ + ffa_setup_partitions("arm,ffa-1.0-hypervisor", &ffa_fops); + + return 0; +} From patchwork Tue Nov 3 17:43:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 314480 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4C94C2D0A3 for ; Tue, 3 Nov 2020 17:44:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 693C021D91 for ; Tue, 3 Nov 2020 17:44:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729077AbgKCRoP (ORCPT ); Tue, 3 Nov 2020 12:44:15 -0500 Received: from foss.arm.com ([217.140.110.172]:53158 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727901AbgKCRoO (ORCPT ); Tue, 3 Nov 2020 12:44:14 -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 758301509; Tue, 3 Nov 2020 09:44:13 -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 F3D533F718; Tue, 3 Nov 2020 09:44:11 -0800 (PST) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Cc: Sudeep Holla , Trilok Soni , Trilok Soni , arve@android.com, Andrew Walbran , David Hartley , Achin Gupta , Android Kernel Team , Fuad Tabba Subject: [PATCH v2 9/9] firmware: arm_ffa: Add support for MEM_* interfaces Date: Tue, 3 Nov 2020 17:43:50 +0000 Message-Id: <20201103174350.991593-10-sudeep.holla@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103174350.991593-1-sudeep.holla@arm.com> References: <20201103174350.991593-1-sudeep.holla@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Most of the MEM_* APIs share the same parameters, so they can be generalised. Currently only MEM_SHARE is implemented and the user space interface for that is not added yet. Signed-off-by: Sudeep Holla Reported-by: kernel test robot --- drivers/firmware/arm_ffa/driver.c | 210 ++++++++++++++++++++++++++++++ include/linux/arm_ffa.h | 137 +++++++++++++++++++ include/uapi/linux/arm_ffa.h | 11 ++ 3 files changed, 358 insertions(+) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 0aa3e4d02896..6e838f2e15cb 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -29,7 +29,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -118,6 +120,18 @@ static int ffa_version_check(u32 *version) return 0; } +static int ffa_features(u32 func_id) +{ + ffa_res_t ret; + + ret = invoke_ffa_fn(FFA_FEATURES, func_id, 0, 0, 0, 0, 0, 0); + + if (ret.a0 == FFA_ERROR) + return ffa_to_linux_errno((int)ret.a2); + + return ret.a2; +} + static int ffa_rx_release(void) { ffa_res_t ret; @@ -215,6 +229,25 @@ static int ffa_id_get(u16 *vm_id) return 0; } +static int ffa_msg_send(u16 src_id, u16 dst_id, void *buf, u32 len) +{ + ffa_res_t ret; + u32 src_dst_ids = PACK_TARGET_INFO(src_id, dst_id); + + mutex_lock(&drv_info->tx_lock); + + memcpy(drv_info->tx_buffer, buf, len); + + ret = invoke_ffa_fn(FFA_MSG_SEND, src_dst_ids, 0, len, 0, 0, 0, 0); + + mutex_unlock(&drv_info->tx_lock); + + if (ret.a0 == FFA_ERROR) + return ffa_to_linux_errno((int)ret.a2); + + return 0; +} + static int ffa_msg_send_direct_req(u16 src_id, u16 dst_id, struct ffa_send_direct_data *data) { @@ -241,6 +274,177 @@ static int ffa_msg_send_direct_req(u16 src_id, u16 dst_id, return 0; } +static int ffa_mem_first_frag(u32 func_id, phys_addr_t buf, u32 buf_sz, + u32 frag_len, u32 len, u64 *handle) +{ + ffa_res_t ret; + + ret = invoke_ffa_fn(func_id, len, frag_len, buf, buf_sz, 0, 0, 0); + + while (ret.a0 == FFA_MEM_OP_PAUSE) + ret = invoke_ffa_fn(FFA_MEM_OP_RESUME, ret.a1, ret.a2, + 0, 0, 0, 0, 0); + if (ret.a0 == FFA_ERROR) + return ffa_to_linux_errno((int)ret.a2); + + if (ret.a0 != FFA_SUCCESS) + return -EOPNOTSUPP; + + if (handle) + *handle = PACK_HANDLE(ret.a3, ret.a2); + + return frag_len; +} + +static int ffa_mem_next_frag(u64 handle, u32 frag_len) +{ + ffa_res_t ret; + + ret = invoke_ffa_fn(FFA_MEM_FRAG_TX, HANDLE_LOW(handle), + HANDLE_HIGH(handle), frag_len, 0, 0, 0, 0); + + while (ret.a0 == FFA_MEM_OP_PAUSE) + ret = invoke_ffa_fn(FFA_MEM_OP_RESUME, ret.a1, ret.a2, + 0, 0, 0, 0, 0); + if (ret.a0 == FFA_ERROR) + return ffa_to_linux_errno((int)ret.a2); + + if (ret.a0 != FFA_MEM_FRAG_RX) + return -EOPNOTSUPP; + + return ret.a3; +} + +static int +ffa_transmit_fragment(u32 func_id, phys_addr_t buf, u32 buf_sz, u32 frag_len, + u32 len, u64 *handle, bool first) +{ + if (!first) + return ffa_mem_next_frag(*handle, frag_len); + + return ffa_mem_first_frag(func_id, buf, buf_sz, frag_len, + len, handle); +} + +static u32 ffa_get_num_pages_sg(struct scatterlist *sg) +{ + u32 num_pages = 0; + + do { + num_pages += sg->length / FFA_PAGE_SIZE; + } while ((sg = sg_next(sg))); + + return num_pages; +} + +static int +ffa_setup_and_transmit(u32 func_id, void *buffer, u32 max_fragsize, + struct ffa_mem_ops_args *args) +{ + int rc = 0; + bool first = true; + phys_addr_t addr = 0; + struct ffa_composite_mem_region *composite; + struct ffa_mem_region_addr_range *constituents; + struct ffa_mem_region_attributes *ep_mem_access; + struct ffa_mem_region *mem_region = buffer; + u32 idx, frag_len, length, num_entries = sg_nents(args->sg); + u32 buf_sz = max_fragsize / FFA_PAGE_SIZE; + + mem_region->tag = args->tag; + mem_region->flags = args->flags; + mem_region->sender_id = drv_info->vm_id; + mem_region->attributes = FFA_MEM_NORMAL | FFA_MEM_WRITE_BACK | + FFA_MEM_INNER_SHAREABLE; + ep_mem_access = &mem_region->ep_mem_access[0]; + + for (idx = 0; idx < args->nattrs; idx++, ep_mem_access++) { + ep_mem_access->receiver = args->attrs[idx].receiver; + ep_mem_access->attrs = args->attrs[idx].attrs; + ep_mem_access->composite_off = COMPOSITE_OFFSET(args->nattrs); + } + mem_region->ep_count = args->nattrs; + + composite = buffer + COMPOSITE_OFFSET(args->nattrs); + composite->total_pg_cnt = ffa_get_num_pages_sg(args->sg); + composite->addr_range_cnt = num_entries; + + length = COMPOSITE_CONSTITUENTS_OFFSET(args->nattrs, num_entries); + frag_len = COMPOSITE_CONSTITUENTS_OFFSET(args->nattrs, 0); + if (frag_len > max_fragsize) + return -ENXIO; + + if (!args->use_txbuf) + addr = virt_to_phys(buffer); + + constituents = buffer + frag_len; + idx = 0; + do { + if (frag_len == max_fragsize) { + rc = ffa_transmit_fragment(func_id, addr, buf_sz, + frag_len, length, + args->g_handle, first); + if (rc < 0) + return -ENXIO; + + first = false; + idx = 0; + frag_len = 0; + constituents = buffer; + } + + if ((void *)constituents - buffer > max_fragsize) { + pr_err("Memory Region Fragment > Tx Buffer size\n"); + return -EFAULT; + } + + constituents->address = sg_phys(args->sg); + constituents->pg_cnt = args->sg->length / FFA_PAGE_SIZE; + constituents++; + frag_len += sizeof(struct ffa_mem_region_addr_range); + } while ((args->sg = sg_next(args->sg))); + + return ffa_transmit_fragment(func_id, addr, buf_sz, frag_len, + length, args->g_handle, first); +} + +static int ffa_memory_ops(u32 func_id, struct ffa_mem_ops_args *args) +{ + int ret; + void *buffer; + + if (!args->use_txbuf) { + buffer = alloc_pages_exact(RXTX_BUFFER_SIZE, GFP_KERNEL); + if (!buffer) + return -ENOMEM; + } else { + buffer = drv_info->tx_buffer; + mutex_lock(&drv_info->tx_lock); + } + + ret = ffa_setup_and_transmit(func_id, buffer, RXTX_BUFFER_SIZE, args); + + if (args->use_txbuf) + mutex_unlock(&drv_info->tx_lock); + else + free_pages_exact(buffer, RXTX_BUFFER_SIZE); + + return ret < 0 ? ret : 0; +} + +static int ffa_memory_reclaim(u64 g_handle, u32 flags) +{ + ffa_res_t ret; + + ret = invoke_ffa_fn(FFA_MEM_RECLAIM, HANDLE_LOW(g_handle), + HANDLE_HIGH(g_handle), flags, 0, 0, 0, 0); + + if (ret.a0 == FFA_ERROR) + return ffa_to_linux_errno((int)ret.a2); + + return 0; +} + struct ffa_device *ffa_device_get_from_minor(int minor) { struct list_head *p; @@ -346,6 +550,12 @@ ffa_dev_ioctl(struct ffa_device *ffa_dev, unsigned int ioctl, void *arg) &kdata->data); break; } + case FFA_SHARE_MEMORY: { + struct ffa_mem_ops_args *kdata = arg; + + r = ffa_memory_ops(FFA_MEM_SHARE, kdata); + break; + } default: r = -EINVAL; } diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h index 719ef02fe42d..12765a7926fc 100644 --- a/include/linux/arm_ffa.h +++ b/include/linux/arm_ffa.h @@ -88,6 +88,143 @@ #define FFA_VERSION_1_0 PACK_VERSION_INFO(1, 0) #define FFA_MIN_VERSION FFA_VERSION_1_0 +struct ffa_mem_region_addr_range { + /* The base IPA of the constituent memory region, aligned to 4 kiB */ + u64 address; + /* The number of 4 kiB pages in the constituent memory region. */ + u32 pg_cnt; + u32 reserved; +}; + +struct ffa_composite_mem_region { + /* + * The total number of 4 kiB pages included in this memory region. This + * must be equal to the sum of page counts specified in each + * `struct ffa_mem_region_addr_range`. + */ + u32 total_pg_cnt; + /* The number of constituents included in this memory region range */ + u32 addr_range_cnt; + u64 reserved; + /** An array of `addr_range_cnt` memory region constituents. */ + struct ffa_mem_region_addr_range constituents[]; +}; + +struct ffa_mem_region_attributes { + /* The ID of the VM to which the memory is being given or shared. */ + u16 receiver; + /* + * The permissions with which the memory region should be mapped in the + * receiver's page table. + */ +#define FFA_MEM_EXEC BIT(3) +#define FFA_MEM_NO_EXEC BIT(2) +#define FFA_MEM_RW BIT(1) +#define FFA_MEM_RO BIT(0) + u8 attrs; + /* + * Flags used during FFA_MEM_RETRIEVE_REQ and FFA_MEM_RETRIEVE_RESP + * for memory regions with multiple borrowers. + */ +#define FFA_MEM_RETRIEVE_SELF_BORROWER BIT(0) + u8 flag; + u32 composite_off; + /* + * Offset in bytes from the start of the outer `ffa_memory_region` to + * an `struct ffa_mem_region_addr_range`. + */ + u64 reserved; +}; + +struct ffa_mem_region { + /* The ID of the VM/owner which originally sent the memory region */ + u16 sender_id; +#define FFA_MEM_NORMAL BIT(5) +#define FFA_MEM_DEVICE BIT(4) + +#define FFA_MEM_WRITE_BACK (3 << 2) +#define FFA_MEM_NON_CACHEABLE (1 << 2) + +#define FFA_DEV_nGnRnE (0 << 2) +#define FFA_DEV_nGnRE (1 << 2) +#define FFA_DEV_nGRE (2 << 2) +#define FFA_DEV_GRE (3 << 2) + +#define FFA_MEM_NON_SHAREABLE (0) +#define FFA_MEM_OUTER_SHAREABLE (2) +#define FFA_MEM_INNER_SHAREABLE (3) + u8 attributes; + u8 reserved_0; +/* + * Clear memory region contents after unmapping it from the sender and + * before mapping it for any receiver. + */ +#define FFA_MEM_CLEAR BIT(0) +/* + * Whether the hypervisor may time slice the memory sharing or retrieval + * operation. + */ +#define FFA_TIME_SLICE_ENABLE BIT(1) + +/* + * Whether the hypervisor should clear the memory region before the receiver + * relinquishes it or is aborted. + */ +#define FFA_MEM_CLEAR_BEFORE_RELINQUISH BIT(0) +/* + * Whether the hypervisor should clear the memory region after the receiver + * relinquishes it or is aborted. + */ +#define FFA_MEM_CLEAR_AFTER_RELINQUISH BIT(2) + +#define FFA_MEM_RETRIEVE_TYPE_IN_RESP (0 << 3) +#define FFA_MEM_RETRIEVE_TYPE_SHARE (1 << 3) +#define FFA_MEM_RETRIEVE_TYPE_LEND (2 << 3) +#define FFA_MEM_RETRIEVE_TYPE_DONATE (3 << 3) + +#define FFA_MEM_RETRIEVE_ADDR_ALIGN_HINT BIT(9) +#define FFA_MEM_RETRIEVE_ADDR_ALIGN(x) ((x) << 5) + /* Flags to control behaviour of the transaction. */ + u32 flags; +#define HANDLE_LOW_MASK GENMASK_ULL(31, 0) +#define HANDLE_HIGH_MASK GENMASK_ULL(63, 32) +#define HANDLE_LOW(x) (u32)(FIELD_GET(HANDLE_LOW_MASK, (x))) +#define HANDLE_HIGH(x) (u32)(FIELD_GET(HANDLE_HIGH_MASK, (x))) + +#define PACK_HANDLE(l, h) \ + (FIELD_PREP(HANDLE_LOW_MASK, (l)) | FIELD_PREP(HANDLE_HIGH_MASK, (h))) + /* + * A globally-unique ID assigned by the hypervisor for a region + * of memory being sent between VMs. + */ + u64 handle; + /* + * An implementation defined value associated with the receiver and the + * memory region. + */ + u64 tag; + u32 reserved_1; + /* + * The number of `ffa_mem_region_attributes` entries included in this + * transaction. + */ + u32 ep_count; + /* + * An array of endpoint memory access descriptors. + * Each one specifies a memory region offset, an endpoint and the + * attributes with which this memory region should be mapped in that + * endpoint's page table. + */ + struct ffa_mem_region_attributes ep_mem_access[]; +}; + +#define COMPOSITE_OFFSET(x) \ + (offsetof(struct ffa_mem_region, ep_mem_access[x])) +#define CONSTITUENTS_OFFSET(x) \ + (offsetof(struct ffa_composite_mem_region, constituents[x])) +#define COMPOSITE_CONSTITUENTS_OFFSET(x, y) \ + (COMPOSITE_OFFSET(x) + CONSTITUENTS_OFFSET(y)) + /* FFA Device/Bus related */ struct ffa_device { diff --git a/include/uapi/linux/arm_ffa.h b/include/uapi/linux/arm_ffa.h index 88ddddb4742f..be2cbf01e51c 100644 --- a/include/uapi/linux/arm_ffa.h +++ b/include/uapi/linux/arm_ffa.h @@ -47,10 +47,21 @@ struct ffa_send_recv_async { char buffer[]; }; +struct ffa_mem_ops_args { + bool use_txbuf; + u64 tag; + u32 flags; + struct ffa_mem_region_attributes *attrs; + u32 nattrs; + struct scatterlist *sg; + u64 *g_handle; +}; + #define FFA_GET_API_VERSION _IO(FFA_BASE, 0x00) #define FFA_GET_PARTITION_ID _IO(FFA_BASE, 0x01) #define FFA_GET_PARTITION_INFO _IOWR(FFA_BASE, 0x02, struct ffa_part_info) #define FFA_SEND_RECEIVE_SYNC _IOWR(FFA_BASE, 0x03, struct ffa_send_recv_sync) #define FFA_SEND_RECEIVE_ASYNC _IOW(FFA_BASE, 0x04, struct ffa_send_recv_async) +#define FFA_SHARE_MEMORY _IOW(FFA_BASE, 0x05, struct ffa_mem_ops_args) #endif /*_UAPI_LINUX_ARM_FFA_H*/