firmware: Add initial support for Arm FF-A
Subsystems (4)
v2 cover firmware: Add initial support for Arm FF-A
Hi all,
Let me start stating this is just initial implementation to check on the idea of providing more in-kernel and userspace support. Lot of things are still work in progress, I am posting just to get the early feedback before building lot of things on this idea. Consider this more as RFC though not tagged explicity(just to avoid it being ignored :))
Arm Firmware Framework for Armv8-A specification[1] describes a software architecture that provides mechanism to utilise the virtualization extension to isolate software images and describes interfaces that standardize communication between the various software images. This includes communication between images in the Secure and Normal world.
The main idea here is to create FFA device to establish any communication with a partition(secure or normal world VM).
If it is a partition managed by hypervisor, then we will register chardev associated with each of those partition FFA device.
/dev/arm_ffa:
e3a48fa5-dc54-4a8b-898b-bdc4dfeeb7b8
49f65057-d002-4ae2-b4ee-d31c7940a13d
For in-kernel usage(mostly communication with secure partitions), only in-kernel APIs are accessible(no userspace). There may be a need to provide userspace access instead of in-kernel, it is not yet support in this series as we need way to identify those and I am not sure if that belong to DT.
--
Regards,
Sudeep
[1] https://developer.arm.com/documentation/den0077/latest
v1->v2:
- Moved userspace code to a separate unit, will move to separate module. Still working on minimizing initcall dependencies and exported functions to reuse some of the code.
- Fixed couple of minor issues pointed out
- Dropped ASYNC send message as I haven't been able to test
Sudeep Holla (8):
dt-bindings: Arm: Extend FF-A binding to support in-kernel usage of
partitions
arm64: smccc: Add support for SMCCCv1.2 input/output registers
firmware: arm_ffa: Add initial FFA bus support for device enumeration
firmware: arm_ffa: Add initial Arm FFA driver support
firmware: arm_ffa: Add support for SMCCC as transport to FFA driver
firmware: arm_ffa: Setup in-kernel users of FFA partitions
firmware: arm_ffa: Setup and register all the KVM managed partitions
firmware: arm_ffa: Add support for MEM_* interfaces
Will Deacon (1):
dt-bindings: Arm: Add Firmware Framework for Armv8-A (FF-A) binding
.../devicetree/bindings/arm/arm,ffa-hyp.yaml | 102 +++ .../devicetree/bindings/arm/arm,ffa.yaml | 58 ++ .../reserved-memory/arm,ffa-memory.yaml | 71 ++ arch/arm64/kernel/asm-offsets.c | 4 + arch/arm64/kernel/smccc-call.S | 22 + drivers/firmware/Kconfig | 1 + drivers/firmware/Makefile | 1 + drivers/firmware/arm_ffa/Kconfig | 21 + drivers/firmware/arm_ffa/Makefile | 6 + drivers/firmware/arm_ffa/bus.c | 199 +++++ drivers/firmware/arm_ffa/common.h | 35 + drivers/firmware/arm_ffa/driver.c | 737 ++++++++++++++++++ drivers/firmware/arm_ffa/hyp_partitions.c | 132 ++++ drivers/firmware/arm_ffa/smccc.c | 54 ++ include/linux/arm-smccc.h | 50 ++ include/linux/arm_ffa.h | 310 ++++++++ include/uapi/linux/arm_ffa.h | 67 ++ 17 files changed, 1870 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/arm,ffa-hyp.yaml create mode 100644 Documentation/devicetree/bindings/arm/arm,ffa.yaml create mode 100644 Documentation/devicetree/bindings/reserved-memory/arm,ffa-memory.yaml 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 drivers/firmware/arm_ffa/common.h create mode 100644 drivers/firmware/arm_ffa/driver.c create mode 100644 drivers/firmware/arm_ffa/hyp_partitions.c create mode 100644 drivers/firmware/arm_ffa/smccc.c create mode 100644 include/linux/arm_ffa.h create mode 100644 include/uapi/linux/arm_ffa.h
--
2.25.1
PATCH v2 1/9 dt-bindings: Arm: Add Firmware Framework for Armv8-A (FF-A) binding
From: Will Deacon <[email protected]>
Add devicetree bindings for a FF-A-compliant hypervisor, its partitions and their memory regions. The naming is ludicrous but also not by fault.
(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)
--- .../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
Documentation/devicetree/bindings/arm/arm,ffa-hyp.yaml new file +102 -0
@@ -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 <[email protected]> + +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>; + }; + };
Documentation/devicetree/bindings/reserved-memory/arm,ffa-memory.yaml new file +71 -0
71 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 2/9 dt-bindings: Arm: Extend FF-A binding to support in-kernel usage of partitions
In reply to Sudeep HollaSince 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.
--- .../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
Documentation/devicetree/bindings/arm/arm,ffa.yaml new file +58 -0
@@ -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 <[email protected]> + +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"; + }; + };
Signature · 1 line
2.25.1
PATCH v2 3/9 arm64: smccc: Add support for SMCCCv1.2 input/output registers
In reply to Sudeep HollaSMCCC 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.
--- 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(+)
arch/arm64/kernel/asm-offsets.c +4 -0
@@ -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));
arch/arm64/kernel/smccc-call.S +22 -0
@@ -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)
include/linux/arm-smccc.h +50 -0
56 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v2 3/9] arm64: smccc: Add support for SMCCCv1.2 input/output registers
Quoted 68 lines · Sudeep Holla
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 <[email protected]>--- 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(+)arch/arm64/kernel/asm-offsets.c +4
-0@@ -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));arch/arm64/kernel/smccc-call.S +22
-0@@ -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)include/linux/arm-smccc.h +0
-0
include/linux/arm-smccc.h struct arm_smccc_res { · line 162
Quoted 8 lines
include/linux/arm-smccc.h +5
-0@@ -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
Should this be a0-a7?
Quoted 11 lines
include/linux/arm-smccc.h +11
-0+*/ +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; +};
include/linux/arm-smccc.h struct arm_smccc_res { · line 183
Quoted 10 lines
include/linux/arm-smccc.h +10
-0+ +/** +* 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.
s/SMC/HVC/ in several places above.
Quoted 30 lines
include/linux/arm-smccc.h +24
-1+*/ +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 -- 2.25.1
PATCH v2 4/9 firmware: arm_ffa: Add initial FFA bus support for device enumeration
In reply to Sudeep HollaThe 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.
--- 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
drivers/firmware/Kconfig +1 -0
@@ -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"
drivers/firmware/Makefile +1 -0
@@ -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/
drivers/firmware/arm_ffa/Kconfig new file +16 -0
@@ -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.
drivers/firmware/arm_ffa/Makefile new file +4 -0
@@ -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
drivers/firmware/arm_ffa/bus.c new file +205 -0
205 lines not on this page · raw message
include/linux/arm_ffa.h new file +81 -0
81 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 5/9 firmware: arm_ffa: Add initial Arm FFA driver support
In reply to Sudeep HollaThis 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.
--- 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
drivers/firmware/arm_ffa/Makefile +2 -1
@@ -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
drivers/firmware/arm_ffa/bus.c +2 -10
@@ -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 <[email protected]>" ); -MODULE_DESCRIPTION ("Arm FF-A bus driver" ); -MODULE_LICENSE ("GPL v2" );
drivers/firmware/arm_ffa/common.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020 ARM Ltd. +*/ + +#ifndef _FFA_COMMON_H +#define _FFA_COMMON_H + +#include <linux/arm-smccc.h> +#include <linux/err.h> + +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 */
drivers/firmware/arm_ffa/driver.c new file +219 -0
219 lines not on this page · raw message
include/linux/arm_ffa.h +77 -0
83 lines not on this page · raw message
Signature · 1 line
2.25.1
kernel test robot
build botRe: [PATCH v2 5/9] firmware: arm_ffa: Add initial Arm FFA driver support
I love your patch! Perhaps something to improve:
Hi Sudeep,
I love your patch! Perhaps something to improve:
[auto build test WARNING on robh/for-next]
[also build test WARNING on arm/for-next keystone/next rockchip/for-next shawnguo/for-next soc/for-next linus/master v5.10-rc2 next-20201103] [cannot apply to arm64/for-next/core at91/at91-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Sudeep-Holla/firmware-Add-initial-support-for-Arm-FF-A/20201104-014609 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next config: arm64-allyesconfig (attached as .config) compiler: aarch64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/3604e1c131c1930e7ec4670535f5bd06b3354189
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Sudeep-Holla/firmware-Add-initial-support-for-Arm-FF-A/20201104-014609 git checkout 3604e1c131c1930e7ec4670535f5bd06b3354189
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/firmware/arm_ffa/bus.c:173:12: warning: no previous prototype for 'arm_ffa_bus_init' [-Wmissing-prototypes]
173 | int __init arm_ffa_bus_init(void)
| ^~~~~~~~~~~~~~~~
>> drivers/firmware/arm_ffa/bus.c:192:13: warning: no previous prototype for 'arm_ffa_bus_exit' [-Wmissing-prototypes]
192 | void __exit arm_ffa_bus_exit(void)
| ^~~~~~~~~~~~~~~~vim +/arm_ffa_bus_init +173 drivers/firmware/arm_ffa/bus.c
172
> 173 int __init arm_ffa_bus_init(void)
174 {
175 int ret;
176
177 ret = alloc_chrdev_region(&ffa_devt, 0, FFA_MAX_CDEVS, DEVICE_NAME);
178 if (ret) {
179 pr_err("failed to allocate char dev region\n");
180 return ret;
181 }
182
183 ret = bus_register(&ffa_bus_type);
184 if (ret) {
185 pr_err("ffa bus register failed (%d)\n", ret);
186 unregister_chrdev_region(ffa_devt, FFA_MAX_CDEVS);
187 }
188
189 return ret;
190 }
191
> 192 void __exit arm_ffa_bus_exit(void)---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH v2 6/9 firmware: arm_ffa: Add support for SMCCC as transport to FFA driver
In reply to Sudeep HollaThere 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.
--- 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
drivers/firmware/arm_ffa/Kconfig +5 -0
@@ -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
drivers/firmware/arm_ffa/Makefile +2 -1
@@ -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
drivers/firmware/arm_ffa/common.h +4 -0
@@ -18,9 +18,13 @@ typedef ffa_res_tint __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 */
drivers/firmware/arm_ffa/smccc.c new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 7/9 firmware: arm_ffa: Setup in-kernel users of FFA partitions
In reply to Sudeep HollaParse 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.
--- 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
drivers/firmware/arm_ffa/bus.c +2 -0
@@ -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;
drivers/firmware/arm_ffa/driver.c +281 -0
326 lines not on this page · raw message
include/linux/arm_ffa.h +15 -0
@@ -11,6 +11,7 @@#include <linux/module.h> #include <linux/types.h> #include <linux/uuid.h> +#include <uapi/linux/arm_ffa.h> #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) \
include/uapi/linux/arm_ffa.h new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v2 7/9] firmware: arm_ffa: Setup in-kernel users of FFA partitions
Hi Sudeep,
Quoted 397 lines · Sudeep Holla
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 <[email protected]>--- 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.hdrivers/firmware/arm_ffa/bus.c +2
-0@@ -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;drivers/firmware/arm_ffa/driver.c +281
-0@@ -24,9 +24,16 @@#include <linux/arm_ffa.h> #include <linux/bitfield.h> +#include <linux/device.h> +#include <linux/fs.h> #include <linux/io.h> +#include <linux/kernel.h> #include <linux/module.h> +#include <linux/of.h> #include <linux/slab.h> +#include <linux/uaccess.h> +#include <linux/uuid.h> +#include <uapi/linux/arm_ffa.h> #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 );include/linux/arm_ffa.h +4
-0@@ -11,6 +11,7 @@#include <linux/module.h> #include <linux/types.h> #include <linux/uuid.h> +#include <uapi/linux/arm_ffa.h> #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)
include/linux/arm_ffa.h struct ffa_driver { · line 124
Quoted 8 lines
include/linux/arm_ffa.h +5
-0@@ -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); +};
I assume that all interaction with a SP is done via ffa_ops->ioctl(). For example the ffa_msg_send_direct_req() function is then called via:
struct ffa_send_recv_sync arg = { .endpoint_id = xxx, .data = yyy }; rc = ffa_ops->ioctl(ffa_dev, FFA_SEND_RECEIVE_SYNC, &arg);
That isn't too hard to use, but is a bit inconvenient and less safe compared to a plain:
rc = ffa_ops->send_recieve_sync(ffa_dev, xxx, yyy);
I don't see any big win in then next patch with ffa_ioctl() either. That function must still do some actions specific for each ioctl id. So I'm a bit curious about the design choice.
Cheers,
Jens
Quoted 87 lines
include/linux/arm_ffa.h +6
-0+#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) \include/uapi/linux/arm_ffa.h new file +56
-0@@ -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 <linux/types.h> +#include <linux/ioctl.h> + +#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*/ Signature · 1 line
2.25.1
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v2 7/9] firmware: arm_ffa: Setup in-kernel users of FFA partitions
Quoted 2 lines · Jens Wiklander
Hi Sudeep,
[...]
Quoted 11 lines
include/linux/arm_ffa.h struct ffa_driver { · line 124
Quoted 9 lines
include/linux/arm_ffa.h +5
-0@@ -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); +};I assume that all interaction with a SP is done via
ffa_ops->ioctl().
Yes that was the idea.
Quoted 4 lines
For example the
ffa_msg_send_direct_req()function is then called via:
structffa_send_recv_syncarg = { .endpoint_id = xxx, .data = yyy }; rc =ffa_ops->ioctl(ffa_dev, FFA_SEND_RECEIVE_SYNC, &arg);
Correct.
Quoted 4 lines
That isn't too hard to use, but is a bit inconvenient and less safe compared to a plain:
rc =ffa_ops->send_recieve_sync(ffa_dev, xxx, yyy);
Agreed.
Quoted 4 lines
I don't see any big win in then next patch with
ffa_ioctl()either. That function must still do some actions specific for each ioctl id. So I'm a bit curious about the design choice.
Initial idea was to keep both in-kernel and user-space interface inline. Also the assumption was that expect few old/legacy usecases, the userspace is the way forward. While that is still ideal, but things have changed since the main user of userspace interface(pKVM) is no longer using FFA. I will change the interface as you mention above. I was also more inclined towards that after dropping userspace. Good timing though, I was about to post revised version dropping userspace. I will modify the interface something on lines of your suggestion.
--
Regards,
Sudeep
PATCH v2 8/9 firmware: arm_ffa: Setup and register all the KVM managed partitions
In reply to Sudeep HollaParse 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.
--- 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
drivers/firmware/arm_ffa/Makefile +1 -1
@@ -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
drivers/firmware/arm_ffa/common.h +5 -0
@@ -8,6 +8,7 @@#include <linux/arm-smccc.h> #include <linux/err.h> +#include <linux/fs.h> 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);
drivers/firmware/arm_ffa/driver.c +27 -0
@@ -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)
drivers/firmware/arm_ffa/hyp_partitions.c new file +132 -0
132 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 9/9 firmware: arm_ffa: Add support for MEM_* interfaces
In reply to Sudeep HollaMost 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.
--- 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(+)
drivers/firmware/arm_ffa/driver.c +210 -0
@@ -29,7 +29,9 @@#include <linux/io.h> #include <linux/kernel.h> #include <linux/module.h> +#include <linux/mm.h> #include <linux/of.h> +#include <linux/scatterlist.h> #include <linux/slab.h> #include <linux/uaccess.h> #include <linux/uuid.h>
@@ -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 ; }
include/linux/arm_ffa.h +137 -0
143 lines not on this page · raw message
include/uapi/linux/arm_ffa.h +11 -0
@@ -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*/
Signature · 1 line
2.25.1
kernel test robot
build botRe: [PATCH v2 9/9] firmware: arm_ffa: Add support for MEM_* interfaces
I love your patch! Yet something to improve:
Hi Sudeep,
I love your patch! Yet something to improve:
[auto build test ERROR on robh/for-next]
[also build test ERROR on arm/for-next keystone/next rockchip/for-next shawnguo/for-next soc/for-next linus/master v5.10-rc2 next-20201103] [cannot apply to arm64/for-next/core linux-rpi/for-rpi-next at91/at91-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Sudeep-Holla/firmware-Add-initial-support-for-Arm-FF-A/20201104-014609 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next config: x86_64-randconfig-a005-20201103 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/2e8f3c2680d2f574b4e4efcce5dfd75912527386 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Sudeep-Holla/firmware-Add-initial-support-for-Arm-FF-A/20201104-014609 git checkout 2e8f3c2680d2f574b4e4efcce5dfd75912527386 # save the attached .config to linux build tree make W=1 ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from <command-line>:32:
>> ./usr/include/linux/arm_ffa.h:51:2: error: unknown type name 'bool'
51 | bool use_txbuf;
| ^~~~
>> ./usr/include/linux/arm_ffa.h:52:2: error: unknown type name 'u64'
52 | u64 tag;
| ^~~
>> ./usr/include/linux/arm_ffa.h:53:2: error: unknown type name 'u32'
53 | u32 flags;
| ^~~
./usr/include/linux/arm_ffa.h:55:2: error: unknown type name 'u32'
55 | u32 nattrs;
| ^~~
./usr/include/linux/arm_ffa.h:57:2: error: unknown type name 'u64'
57 | u64 *g_handle;
| ^~~---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Hi Sudeep,
Quoted 22 lines · Sudeep Holla
Hi all,
Let me start stating this is just initial implementation to check on the idea of providing more in-kernel and userspace support. Lot of things are still work in progress, I am posting just to get the early feedback before building lot of things on this idea. Consider this more as RFC though not tagged explicity(just to avoid it being ignored :))
Arm Firmware Framework for Armv8-A specification[1] describes a software architecture that provides mechanism to utilise the virtualization extension to isolate software images and describes interfaces that standardize communication between the various software images. This includes communication between images in the Secure and Normal world.
The main idea here is to create FFA device to establish any communication with a partition(secure or normal world VM).
If it is a partition managed by hypervisor, then we will register chardev associated with each of those partition FFA device.
/dev/arm_ffa:
Quoted 8 lines
e3a48fa5-dc54-4a8b-898b-bdc4dfeeb7b8
49f65057-d002-4ae2-b4ee-d31c7940a13dFor in-kernel usage(mostly communication with secure partitions), only in-kernel APIs are accessible(no userspace). There may be a need to provide userspace access instead of in-kernel, it is not yet support in this series as we need way to identify those and I am not sure if that belong to DT.
With unfiltered VM to VM commnication from user space there's no easy way for two VMs to exchange privileged information that excludes user space. Perhaps access to the FFA device is considered privileged and enough for all purposes.
If I've understood it correctly is VM to SP communication only allowed via kernel mode in the VM. The communication with OP-TEE depends on this with the recent commit c5b4312bea5d ("tee: optee: Add support for session login client UUID generation").
Cheers,
Jens
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 34 lines · Jens Wiklander
Hi Sudeep,
Quoted 22 lines · Sudeep Holla
Hi all,
Let me start stating this is just initial implementation to check on the idea of providing more in-kernel and userspace support. Lot of things are still work in progress, I am posting just to get the early feedback before building lot of things on this idea. Consider this more as RFC though not tagged explicity(just to avoid it being ignored :))
Arm Firmware Framework for Armv8-A specification[1] describes a software architecture that provides mechanism to utilise the virtualization extension to isolate software images and describes interfaces that standardize communication between the various software images. This includes communication between images in the Secure and Normal world.
The main idea here is to create FFA device to establish any communication with a partition(secure or normal world VM).
If it is a partition managed by hypervisor, then we will register chardev associated with each of those partition FFA device.
/dev/arm_ffa:Quoted 8 lines
e3a48fa5-dc54-4a8b-898b-bdc4dfeeb7b8
49f65057-d002-4ae2-b4ee-d31c7940a13dFor in-kernel usage(mostly communication with secure partitions), only in-kernel APIs are accessible(no userspace). There may be a need to provide userspace access instead of in-kernel, it is not yet support in this series as we need way to identify those and I am not sure if that belong to DT.
Quoted 3 lines
With unfiltered VM to VM commnication from user space there's no easy way for two VMs to exchange privileged information that excludes user space.
Though this usercase is dropped now, it was targeted for VMM and may be it was not an issue there.
Quoted 3 lines
Perhaps access to the FFA device is considered privileged and enough for all purposes.
I don't know TBH.
Quoted 2 lines
If I've understood it correctly is VM to SP communication only allowed via kernel mode in the VM.
Correct.
Quoted 4 lines
The communication with OP-TEE depends on this with the recent commit
c5b4312bea5d("tee: optee: Add support for session login client UUID generation").
OK, thanks for the info.
Signature · 2 lines
Regards, Sudeep