firmware: Add initial support for Arm FF-A
Subsystems (4)
v3 cover firmware: Add initial support for Arm FF-A
Hi all,
This is just initial implementation to check on the idea of providing in-kernel support for Arm FF-A specification. Complete driver support is still work in progress, I am posting to early feedback and merge basic support ASAP.
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 secure partition.
--
Regards,
Sudeep
[1] https://developer.arm.com/documentation/den0077/latest
v2->v3:
- Dropped hypervisor partitions and userspace support as it is no longer in the list of requirements
- Moved away from ioctl style interface for in-kernel users as there is no need to keep in sync with userspace anymore
- Some kerneldoc fixes as pointed out in earlier reviews
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 (7):
dt-bindings: Arm: Add Firmware Framework for Armv8-A (FF-A) binding
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: Add support for MEM_* interfaces
.../devicetree/bindings/arm/arm,ffa.yaml | 58 ++ 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 | 179 +++++ drivers/firmware/arm_ffa/common.h | 32 + drivers/firmware/arm_ffa/driver.c | 660 ++++++++++++++++++ drivers/firmware/arm_ffa/smccc.c | 54 ++ include/linux/arm-smccc.h | 50 ++ include/linux/arm_ffa.h | 270 +++++++ 13 files changed, 1358 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/arm,ffa.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/smccc.c create mode 100644 include/linux/arm_ffa.h
--
2.25.1
PATCH v3 1/7 dt-bindings: Arm: Add Firmware Framework for Armv8-A (FF-A) binding
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 binding to provide the list of partitions that kernel drivers may need to access.
--- .../devicetree/bindings/arm/arm,ffa.yaml | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/arm,ffa.yaml
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
Rob Herring
maintainerRe: [PATCH v3 1/7] dt-bindings: Arm: Add Firmware Framework for Armv8-A (FF-A) binding
Quoted 54 lines · Sudeep Holla
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 binding to provide the list of partitions that kernel drivers may need to access.
Signed-off-by Sudeep Holla <[email protected]>--- .../devicetree/bindings/arm/arm,ffa.yaml | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/arm,ffa.yamlDocumentation/devicetree/bindings/arm/arm,ffa.yaml new file +35
-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 +
Documentation/devicetree/bindings/arm/arm,ffa.yaml line 45
Quoted 10 lines
Documentation/devicetree/bindings/arm/arm,ffa.yaml new file +10
-0+ 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
UUIDs are actually a known thing in json-schema with 'format: uuid'. The meta-schema will probably reject that, so we'll need to add support to dtschema. Maybe it should be a new definition to reference.
Documentation/devicetree/bindings/arm/arm,ffa.yaml line 58
Quoted 13 lines
Documentation/devicetree/bindings/arm/arm,ffa.yaml new file +13
-0+ +additionalProperties: false + +examples: + - | + ffa { + compatible = "arm,ffa-1.0"; + + ffa_partition0 { + compatible = "arm,ffa-1.0-partition"; + uuid = "12345678-9abc-def0-1234-56789abcdef0"; + }; + };
This could all be simplified down to just a single property:
arm,ffa-partitions = "12345678-9abc-def0-1234-56789abcdef0",
"12345678-9abc-def0-1234-56789abcdef1" "12345678-9abc-def0-1234-56789abcdef2";
Obviously, that's not extensible, but do we need it to be?
Rob
Re: [PATCH v3 1/7] dt-bindings: Arm: Add Firmware Framework for Armv8-A (FF-A) binding
Quoted 61 lines · Rob Herring
Quoted 60 lines · Sudeep Holla
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 binding to provide the list of partitions that kernel drivers may need to access.
Signed-off-by Sudeep Holla <[email protected]>--- .../devicetree/bindings/arm/arm,ffa.yaml | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/arm,ffa.yamlDocumentation/devicetree/bindings/arm/arm,ffa.yaml new file +41
-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'
Quoted 9 lines
Documentation/devicetree/bindings/arm/arm,ffa.yaml line 45
Quoted 4 lines
Documentation/devicetree/bindings/arm/arm,ffa.yaml new file +4
-0+ description: | + The 128-bit UUID [2] of the service implemented by this partition. + + [2] https://tools.ietf.org/html/rfc4122UUIDs are actually a known thing in json-schema with 'format: uuid'. The meta-schema will probably reject that, so we'll need to add support to dtschema. Maybe it should be a new definition to reference.
Ah OK, I will try that and ask for help if I am stuck as I am still trying to learn these, not there yet 😄
Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/arm/arm,ffa.yaml new file +7
-0+ +additionalProperties: false + +examples: + - | + ffa { + compatible = "arm,ffa-1.0";
Quoted 9 lines
Documentation/devicetree/bindings/arm/arm,ffa.yaml line 58
Quoted 6 lines
Documentation/devicetree/bindings/arm/arm,ffa.yaml new file +6
-0+ + ffa_partition0 { + compatible = "arm,ffa-1.0-partition"; + uuid = "12345678-9abc-def0-1234-56789abcdef0"; + }; + };This could all be simplified down to just a single property:
Thanks for the suggestion, I would love this to force spec authors to stop relying on DT and add whatever needed in future to the spec as part of discovery APIs.
Quoted 6 lines
arm,ffa-partitions = "12345678-9abc-def0-1234-56789abcdef0",
"12345678-9abc-def0-1234-56789abcdef1" "12345678-9abc-def0-1234-56789abcdef2";Obviously, that's not extensible, but do we need it to be?
I prefer if we don't, but I will run this through spec authors so that they are aware of what we will do in DT which means they *have* to incorporate any future needs into the spec discovery apis.
Ah I forgot the spec author is cc-ed. @Achin please shout if you see issues with this approach.
--
Regards,
Sudeep
Re: [PATCH v3 1/7] dt-bindings: Arm: Add Firmware Framework for Armv8-A (FF-A) binding
Quoted 100 lines · Sudeep Holla
Quoted 61 lines · Rob Herring
Quoted 60 lines · Sudeep Holla
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 binding to provide the list of partitions that kernel drivers may need to access.
Signed-off-by Sudeep Holla <[email protected]>--- .../devicetree/bindings/arm/arm,ffa.yaml | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/arm,ffa.yamlDocumentation/devicetree/bindings/arm/arm,ffa.yaml new file +41
-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'Quoted 9 lines
Documentation/devicetree/bindings/arm/arm,ffa.yaml line 45
Quoted 4 lines
Documentation/devicetree/bindings/arm/arm,ffa.yaml new file +4
-0+ description: | + The 128-bit UUID [2] of the service implemented by this partition. + + [2] https://tools.ietf.org/html/rfc4122UUIDs are actually a known thing in json-schema with 'format: uuid'. The meta-schema will probably reject that, so we'll need to add support to dtschema. Maybe it should be a new definition to reference.
Ah OK, I will try that and ask for help if I am stuck as I am still trying to learn these, not there yet 😄
Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/arm/arm,ffa.yaml new file +7
-0+ +additionalProperties: false + +examples: + - | + ffa { + compatible = "arm,ffa-1.0";Quoted 9 lines
Documentation/devicetree/bindings/arm/arm,ffa.yaml line 58
Quoted 6 lines
Documentation/devicetree/bindings/arm/arm,ffa.yaml new file +6
-0+ + ffa_partition0 { + compatible = "arm,ffa-1.0-partition"; + uuid = "12345678-9abc-def0-1234-56789abcdef0"; + }; + };This could all be simplified down to just a single property:
Thanks for the suggestion, I would love this to force spec authors to stop relying on DT and add whatever needed in future to the spec as part of discovery APIs.
Quoted 4 lines
arm,ffa-partitions = "12345678-9abc-def0-1234-56789abcdef0",
"12345678-9abc-def0-1234-56789abcdef1" "12345678-9abc-def0-1234-56789abcdef2";
Quoted 6 lines
Quoted 2 lines
Obviously, that's not extensible, but do we need it to be?
I prefer if we don't, but I will run this through spec authors so that they are aware of what we will do in DT which means they *have* to incorporate any future needs into the spec discovery apis.
Speaking of discovery apis, doesn't the FF-A spec already have that? Or am I missing something?
Cheers,
Jens
Quoted 7 lines
Ah I forgot the spec author is cc-ed. @Achin please shout if you see issues with this approach.
--
Regards,
Sudeep
Re: [PATCH v3 1/7] dt-bindings: Arm: Add Firmware Framework for Armv8-A (FF-A) binding
In reply to Sudeep HollaQuoted 100 lines · Sudeep Holla
Quoted 61 lines · Rob Herring
Quoted 60 lines · Sudeep Holla
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 binding to provide the list of partitions that kernel drivers may need to access.
Signed-off-by Sudeep Holla <[email protected]>--- .../devicetree/bindings/arm/arm,ffa.yaml | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/arm,ffa.yamlDocumentation/devicetree/bindings/arm/arm,ffa.yaml new file +41
-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'Quoted 9 lines
Documentation/devicetree/bindings/arm/arm,ffa.yaml line 45
Quoted 4 lines
Documentation/devicetree/bindings/arm/arm,ffa.yaml new file +4
-0+ description: | + The 128-bit UUID [2] of the service implemented by this partition. + + [2] https://tools.ietf.org/html/rfc4122UUIDs are actually a known thing in json-schema with 'format: uuid'. The meta-schema will probably reject that, so we'll need to add support to dtschema. Maybe it should be a new definition to reference.
Ah OK, I will try that and ask for help if I am stuck as I am still trying to learn these, not there yet 😄
Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/arm/arm,ffa.yaml new file +7
-0+ +additionalProperties: false + +examples: + - | + ffa { + compatible = "arm,ffa-1.0";Quoted 9 lines
Documentation/devicetree/bindings/arm/arm,ffa.yaml line 58
Quoted 6 lines
Documentation/devicetree/bindings/arm/arm,ffa.yaml new file +6
-0+ + ffa_partition0 { + compatible = "arm,ffa-1.0-partition"; + uuid = "12345678-9abc-def0-1234-56789abcdef0"; + }; + };This could all be simplified down to just a single property:
Thanks for the suggestion, I would love this to force spec authors to stop relying on DT and add whatever needed in future to the spec as part of discovery APIs.
Quoted 4 lines
arm,ffa-partitions = "12345678-9abc-def0-1234-56789abcdef0",
"12345678-9abc-def0-1234-56789abcdef1" "12345678-9abc-def0-1234-56789abcdef2";
Quoted 7 lines
Quoted 2 lines
Obviously, that's not extensible, but do we need it to be?
I prefer if we don't, but I will run this through spec authors so that they are aware of what we will do in DT which means they *have* to incorporate any future needs into the spec discovery apis.
OK we found some usecase which may require separate nodes. I am sure they could be alternative solution even with above style of array of UUID strings.
If you remember use of SMC/HVC as SCMI transport[1], it just provides one way(a2p) communication. P2A is not possible with that, i.e platform notifications to OSPM is not possible. FFA aims to replace native SMC/HVC transport there to provide bi-directional support. For such usecase, where one partition running SCMI server might provide multiple channels for SCMI communication and we may need to provide the link using phandle or something in DT.
Let me know your thoughts on those.
--
Regards,
Sudeep
PATCH v3 2/7 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
PATCH v3 3/7 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 such 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.
--- 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 | 187 ++++++++++++++++++++++++++++++ include/linux/arm_ffa.h | 87 ++++++++++++++ 6 files changed, 296 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 +187 -0
187 lines not on this page · raw message
include/linux/arm_ffa.h new file +87 -0
87 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 4/7 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 | 294 ++++++++++++++++++++++++++++++ 4 files changed, 324 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
@@ -167,21 +167,13 @@ bool ffa_device_is_valid(struct ffa_device *ffa_dev)return valid; } -static int __init arm_ffa_bus_init (void ) +int __init arm_ffa_bus_init (void ) {return bus_register (&ffa_bus_type); } -module_init (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); } - -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 +294 -0
294 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 5/7 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 · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v3 6/7 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/common.h | 2 + drivers/firmware/arm_ffa/driver.c | 186 ++++++++++++++++++++++++++++++ include/linux/arm_ffa.h | 36 +++++- 3 files changed, 223 insertions(+), 1 deletion(-)
drivers/firmware/arm_ffa/common.h +2 -0
@@ -6,6 +6,7 @@#ifndef _FFA_COMMON_H#define _FFA_COMMON_H +#include <linux/arm_ffa.h> #include <linux/arm-smccc.h> #include <linux/err.h>
@@ -17,6 +18,7 @@ typedef ffa_res_tint __init arm_ffa_bus_init (void ); void __exit arm_ffa_bus_exit(void); +bool ffa_device_is_valid (struct ffa_device *ffa_dev);#ifdef CONFIG_ARM_FFA_SMCCC int __init ffa_transport_init (ffa_fn **invoke_ffa_fn);
drivers/firmware/arm_ffa/driver.c +186 -0
222 lines not on this page · raw message
include/linux/arm_ffa.h +35 -1
@@ -6,7 +6,6 @@#ifndef _LINUX_ARM_FFA_H#define _LINUX_ARM_FFA_H -#include <linux/cdev.h> #include <linux/device.h> #include <linux/module.h> #include <linux/types.h>
@@ -47,6 +46,7 @@ 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
@@ -66,6 +66,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) \
@@ -84,4 +88,34 @@ static inline void ffa_driver_unregister(struct ffa_driver *driver) {}#define module_ffa_driver (__ffa_driver) \ module_driver(__ffa_driver, ffa_register, ffa_unregister) +/* FFA transport related */ +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_send_direct_data { +unsigned long data0; +unsigned long data1; +unsigned long data2; +unsigned long data3; +unsigned long data4; +}; + +struct ffa_dev_ops { +u32 (*api_version_get)(void ); +u16 (*partition_id_get)(struct ffa_device *dev); +int (*partition_info_get)(const char *uuid_str, +struct ffa_partition_info *buffer); +int (*sync_send_receive)(struct ffa_device *dev,u16 ep, +struct ffa_send_direct_data *data); +}; +#endif /* _LINUX_ARM_FFA_H */
Signature · 1 line
2.25.1
Re: [PATCH v3 6/7] firmware: arm_ffa: Setup in-kernel users of FFA partitions
Hi Sudeep,
Some comments below.
Quoted 196 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/common.h | 2 + drivers/firmware/arm_ffa/driver.c | 186 ++++++++++++++++++++++++++++++ include/linux/arm_ffa.h | 36 +++++- 3 files changed, 223 insertions(+), 1 deletion(-)drivers/firmware/arm_ffa/common.h +2
-0@@ -6,6 +6,7 @@#ifndef _FFA_COMMON_H#define _FFA_COMMON_H +#include <linux/arm_ffa.h> #include <linux/arm-smccc.h> #include <linux/err.h> @@ -17,6 +18,7 @@ typedef ffa_res_tint __init arm_ffa_bus_init (void ); void __exit arm_ffa_bus_exit(void); +bool ffa_device_is_valid (struct ffa_device *ffa_dev);#ifdef CONFIG_ARM_FFA_SMCCC int __init ffa_transport_init (ffa_fn **invoke_ffa_fn);drivers/firmware/arm_ffa/driver.c +129
-0@@ -24,9 +24,13 @@#include <linux/arm_ffa.h> #include <linux/bitfield.h> +#include <linux/device.h> #include <linux/io.h> +#include <linux/kernel.h> #include <linux/module.h> +#include <linux/of.h> #include <linux/slab.h> +#include <linux/uuid.h> #include "common.h" @@ -179,6 +183,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;@@ -203,6 +221,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) {@@ -218,9 +280,125 @@ 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 u32 ffa_api_version_get (void ) +{ +return drv_info->version; +} + +static u16 ffa_partition_id_get (struct ffa_device *dev) +{ +return dev->vm_id; +} + +static int ffa_partition_info_get (const char *uuid_str, +struct ffa_partition_info *buffer) +{ +if (ffa_partition_probe (uuid_str, buffer) ==1 ) +return 0 ; + +return -ENOENT ; +} + +static int ffa_sync_send_receive (struct ffa_device *dev,u16 ep, +struct ffa_send_direct_data *data) +{ +return ffa_msg_send_direct_req (dev->vm_id, ep, data); +} + +static const struct ffa_dev_ops ffa_ops = { + .api_version_get = ffa_api_version_get, + .partition_id_get = ffa_partition_id_get, + .partition_info_get = ffa_partition_info_get, + .sync_send_receive = ffa_sync_send_receive, +}; + +const struct ffa_dev_ops *ffa_dev_ops_get (struct ffa_device *dev) +{ +if (ffa_device_is_valid (dev)) +return &ffa_ops; + +return NULL ; +} +EXPORT_SYMBOL_GPL (ffa_dev_ops_get); +
drivers/firmware/arm_ffa/driver.c static int ffa_id_get(u16 *vm_id) · line 359
Quoted 10 lines
drivers/firmware/arm_ffa/driver.c +10
-0+int ffa_setup_partitions (struct device_node *np) +{ +int ret; +struct device_node *child; +struct ffa_device *ffa_dev; +struct ffa_partition_info pbuf; +const char *p_uuid, *pfx ="Ignoring FFA partition" ; +uuid_t uuid =UUID_INIT (0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ); + +for_each_child_of_node (np, child) {
The spec says:
– If the Nil UUID is specified at the Non-secure virtual FF-A instance, the Hypervisor must provide information for partitions resident in both security states.
Doesn't that make this redundant?
Quoted 11 lines
drivers/firmware/arm_ffa/driver.c +11
-0+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 ; + } +
drivers/firmware/arm_ffa/driver.c static int ffa_id_get(u16 *vm_id) · line 380
Quoted 10 lines
drivers/firmware/arm_ffa/driver.c +10
-0+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 ) {
If ret is > 1 we're in deep trouble as we have a buffer overrun on the stack.
Cheers,
Jens
Quoted 108 lines
drivers/firmware/arm_ffa/driver.c +26
-0+pr_err ("%s: %s partition info probe failed\n" , + pfx, p_uuid); +return -EINVAL ; + } + + ffa_dev =ffa_device_register (p_uuid, pbuf.id); +if (!ffa_dev) { +pr_err ("%s: failed to register %s\n" , pfx, p_uuid); +continue ; + } + +ffa_dev_set_drvdata (ffa_dev, drv_info); + } + +return 0 ; +} +static int __init ffa_init (void ) {int ret; +struct device_node *np; ret =arm_ffa_bus_init ();if (ret)@@ -267,6 +445,14 @@ static int __init ffa_init(void)mutex_init (&drv_info->rx_lock);mutex_init (&drv_info->tx_lock); +/* Set up all the partitions */ + np =of_find_compatible_node (NULL ,NULL ,"arm,ffa-1.0" ); +if (!np) +return 0 ; + +ffa_setup_partitions (np); +of_node_put (np); +return 0 ; free_pages:if (drv_info->tx_buffer)include/linux/arm_ffa.h +35
-1@@ -6,7 +6,6 @@#ifndef _LINUX_ARM_FFA_H#define _LINUX_ARM_FFA_H -#include <linux/cdev.h> #include <linux/device.h> #include <linux/module.h> #include <linux/types.h> @@ -47,6 +46,7 @@ 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@@ -66,6 +66,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) \@@ -84,4 +88,34 @@ static inline void ffa_driver_unregister(struct ffa_driver *driver) {}#define module_ffa_driver (__ffa_driver) \ module_driver(__ffa_driver, ffa_register, ffa_unregister) +/* FFA transport related */ +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_send_direct_data { +unsigned long data0; +unsigned long data1; +unsigned long data2; +unsigned long data3; +unsigned long data4; +}; + +struct ffa_dev_ops { +u32 (*api_version_get)(void ); +u16 (*partition_id_get)(struct ffa_device *dev); +int (*partition_info_get)(const char *uuid_str, +struct ffa_partition_info *buffer); +int (*sync_send_receive)(struct ffa_device *dev,u16 ep, +struct ffa_send_direct_data *data); +}; +#endif /* _LINUX_ARM_FFA_H */ Signature · 1 line
2.25.1
Re: [PATCH v3 6/7] firmware: arm_ffa: Setup in-kernel users of FFA partitions
Quoted 5 lines · Jens Wiklander
Hi Sudeep,
Some comments below.
On Fri, Dec 04, 2020 at 12:11:36PM +0000, Sudeep Holla wrote:
[...]
Quoted 8 lines
Quoted 8 lines
drivers/firmware/arm_ffa/driver.c +8
-0+ +int ffa_setup_partitions (struct device_node *np) +{ +int ret; +struct device_node *child; +struct ffa_device *ffa_dev; +struct ffa_partition_info pbuf; +const char *p_uuid, *pfx ="Ignoring FFA partition" ;
Quoted 9 lines
drivers/firmware/arm_ffa/driver.c static int ffa_id_get(u16 *vm_id) · line 359
Quoted 3 lines
drivers/firmware/arm_ffa/driver.c +3
-0+uuid_t uuid =UUID_INIT (0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ); + +for_each_child_of_node (np, child) {The spec says:
– If the Nil UUID is specified at the Non-secure virtual FF-A instance, the Hypervisor must provide information for partitions resident in both security states.
That was my initial understanding of the specification. However I was told it is designed mostly for Non-Secure Hypervisor for getting the list of secure partitions and help in allocation of non-secure partition/endpoint IDs. This has been topic of discussion recently.
Quoted 2 lines
Doesn't that make this redundant?
Not exactly. One main reason why the discovery API (get partition info) is not much useful here in this context is that it lacks UUID and hence not much of use unless you know UUID. The result we get for Nil UUID needs to be mapped to UUID and I can't think of anyway to do so outside the scope of the spec. I have raised it but not sure if there is a strong requirement to add it.
Similarly, I would have like 32 vs 64 bit capable partition info from there ideally, but we are here now.
Signature · 2 lines
Regards, Sudeep
Re: [PATCH v3 6/7] firmware: arm_ffa: Setup in-kernel users of FFA partitions
In reply to Sudeep HollaHi Sudeep,
Some more comments below.
Quoted 188 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/common.h | 2 + drivers/firmware/arm_ffa/driver.c | 186 ++++++++++++++++++++++++++++++ include/linux/arm_ffa.h | 36 +++++- 3 files changed, 223 insertions(+), 1 deletion(-)drivers/firmware/arm_ffa/common.h +2
-0@@ -6,6 +6,7 @@#ifndef _FFA_COMMON_H#define _FFA_COMMON_H +#include <linux/arm_ffa.h> #include <linux/arm-smccc.h> #include <linux/err.h> @@ -17,6 +18,7 @@ typedef ffa_res_tint __init arm_ffa_bus_init (void ); void __exit arm_ffa_bus_exit(void); +bool ffa_device_is_valid (struct ffa_device *ffa_dev);#ifdef CONFIG_ARM_FFA_SMCCC int __init ffa_transport_init (ffa_fn **invoke_ffa_fn);drivers/firmware/arm_ffa/driver.c +120
-0@@ -24,9 +24,13 @@#include <linux/arm_ffa.h> #include <linux/bitfield.h> +#include <linux/device.h> #include <linux/io.h> +#include <linux/kernel.h> #include <linux/module.h> +#include <linux/of.h> #include <linux/slab.h> +#include <linux/uuid.h> #include "common.h" @@ -179,6 +183,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;@@ -203,6 +221,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) {@@ -218,9 +280,125 @@ 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 u32 ffa_api_version_get (void ) +{ +return drv_info->version; +} + +static u16 ffa_partition_id_get (struct ffa_device *dev) +{ +return dev->vm_id; +} + +static int ffa_partition_info_get (const char *uuid_str, +struct ffa_partition_info *buffer) +{ +if (ffa_partition_probe (uuid_str, buffer) ==1 ) +return 0 ; + +return -ENOENT ; +} + +static int ffa_sync_send_receive (struct ffa_device *dev,u16 ep, +struct ffa_send_direct_data *data) +{ +return ffa_msg_send_direct_req (dev->vm_id, ep, data); +} + +static const struct ffa_dev_ops ffa_ops = { + .api_version_get = ffa_api_version_get, + .partition_id_get = ffa_partition_id_get, + .partition_info_get = ffa_partition_info_get, + .sync_send_receive = ffa_sync_send_receive, +}; +
drivers/firmware/arm_ffa/driver.c static int ffa_id_get(u16 *vm_id) · line 350
Quoted 10 lines
drivers/firmware/arm_ffa/driver.c +10
-0+const struct ffa_dev_ops *ffa_dev_ops_get (struct ffa_device *dev) +{ +if (ffa_device_is_valid (dev)) +return &ffa_ops; + +return NULL ; +} +EXPORT_SYMBOL_GPL (ffa_dev_ops_get); + +int ffa_setup_partitions (struct device_node *np)
This function is only used internally and the return value is ignored. Maybe make it static void instead?
drivers/firmware/arm_ffa/driver.c static int ffa_id_get(u16 *vm_id) · line 359
Quoted 9 lines
drivers/firmware/arm_ffa/driver.c +9
-0+{ +int ret; +struct device_node *child; +struct ffa_device *ffa_dev; +struct ffa_partition_info pbuf; +const char *p_uuid, *pfx ="Ignoring FFA partition" ; +uuid_t uuid =UUID_INIT (0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ); + +for_each_child_of_node (np, child) {
of_node_put() should only be called on child in case we're leaving the loop early. for_each_child_of_node() takes care of the other case.
Quoted 105 lines
drivers/firmware/arm_ffa/driver.c +47
-0+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 ; + } + + ffa_dev =ffa_device_register (p_uuid, pbuf.id); +if (!ffa_dev) { +pr_err ("%s: failed to register %s\n" , pfx, p_uuid); +continue ; + } + +ffa_dev_set_drvdata (ffa_dev, drv_info); + } + +return 0 ; +} +static int __init ffa_init (void ) {int ret; +struct device_node *np; ret =arm_ffa_bus_init ();if (ret)@@ -267,6 +445,14 @@ static int __init ffa_init(void)mutex_init (&drv_info->rx_lock);mutex_init (&drv_info->tx_lock); +/* Set up all the partitions */ + np =of_find_compatible_node (NULL ,NULL ,"arm,ffa-1.0" ); +if (!np) +return 0 ; + +ffa_setup_partitions (np); +of_node_put (np); +return 0 ; free_pages:if (drv_info->tx_buffer)include/linux/arm_ffa.h +15
-1@@ -6,7 +6,6 @@#ifndef _LINUX_ARM_FFA_H#define _LINUX_ARM_FFA_H -#include <linux/cdev.h> #include <linux/device.h> #include <linux/module.h> #include <linux/types.h> @@ -47,6 +46,7 @@ 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@@ -66,6 +66,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) \@@ -84,4 +88,34 @@ static inline void ffa_driver_unregister(struct ffa_driver *driver) {}#define module_ffa_driver (__ffa_driver) \ module_driver(__ffa_driver, ffa_register, ffa_unregister) +/* FFA transport related */ +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)
include/linux/arm_ffa.h static inline void ffa_driver_unregister(struct ffa_driver *driver) {} · line 110
Quoted 10 lines
include/linux/arm_ffa.h +10
-0+u32 properties; +}; + +struct ffa_send_direct_data { +unsigned long data0; +unsigned long data1; +unsigned long data2; +unsigned long data3; +unsigned long data4; +};
A comment describing which register index these maps to would be helpful.
include/linux/arm_ffa.h static inline void ffa_driver_unregister(struct ffa_driver *driver) {} · line 118
Quoted 8 lines
include/linux/arm_ffa.h +8
-0+ +struct ffa_dev_ops { +u32 (*api_version_get)(void ); +u16 (*partition_id_get)(struct ffa_device *dev); +int (*partition_info_get)(const char *uuid_str, +struct ffa_partition_info *buffer); +int (*sync_send_receive)(struct ffa_device *dev,u16 ep, +struct ffa_send_direct_data *data);
ep can be read directly from dev->vm_id
We may need a way to indicate if we're to use the 32bit or 64bit calling convention. OP-TEE depends on being able to use 32bit calls here.
Cheers,
Jens
Quoted 6 lines
include/linux/arm_ffa.h +2
-1+}; +#endif /* _LINUX_ARM_FFA_H */ --2.25.1
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v3 6/7] firmware: arm_ffa: Setup in-kernel users of FFA partitions
One more comment below.
Quoted 117 lines · Jens Wiklander
Hi Sudeep,
Some more comments below.
Quoted 111 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/common.h | 2 + drivers/firmware/arm_ffa/driver.c | 186 ++++++++++++++++++++++++++++++ include/linux/arm_ffa.h | 36 +++++- 3 files changed, 223 insertions(+), 1 deletion(-)drivers/firmware/arm_ffa/common.h +2
-0@@ -6,6 +6,7 @@#ifndef _FFA_COMMON_H#define _FFA_COMMON_H +#include <linux/arm_ffa.h> #include <linux/arm-smccc.h> #include <linux/err.h> @@ -17,6 +18,7 @@ typedef ffa_res_tint __init arm_ffa_bus_init (void ); void __exit arm_ffa_bus_exit(void); +bool ffa_device_is_valid (struct ffa_device *ffa_dev);#ifdef CONFIG_ARM_FFA_SMCCC int __init ffa_transport_init (ffa_fn **invoke_ffa_fn);drivers/firmware/arm_ffa/driver.c +50
-0@@ -24,9 +24,13 @@#include <linux/arm_ffa.h> #include <linux/bitfield.h> +#include <linux/device.h> #include <linux/io.h> +#include <linux/kernel.h> #include <linux/module.h> +#include <linux/of.h> #include <linux/slab.h> +#include <linux/uuid.h> #include "common.h" @@ -179,6 +183,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;@@ -203,6 +221,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 }; +
Quoted 8 lines
drivers/firmware/arm_ffa/driver.c static int ffa_rxtx_unmap(u16 vm_id) · line 263
Quoted 8 lines
drivers/firmware/arm_ffa/driver.c +8
-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);
Wrong byte order?
According to section 5.3 of the SMCCC, UUIDs are returned as a single 128-bit value using the SMC32 calling convention. This value is mapped to argument registers x0-x3 on AArch64 (resp. r0-r3 on AArch32). x0 for example shall hold bytes 0 to 3, with byte 0 in the low-order bits.
Cheers,
Jens
Quoted 233 lines
Quoted 69 lines
drivers/firmware/arm_ffa/driver.c +62
-0+ +return count; +} +#define VM_ID_MASK GENMASK(15, 0)static int ffa_id_get (u16 *vm_id) {@@ -218,9 +280,125 @@ 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 u32 ffa_api_version_get (void ) +{ +return drv_info->version; +} + +static u16 ffa_partition_id_get (struct ffa_device *dev) +{ +return dev->vm_id; +} + +static int ffa_partition_info_get (const char *uuid_str, +struct ffa_partition_info *buffer) +{ +if (ffa_partition_probe (uuid_str, buffer) ==1 ) +return 0 ; + +return -ENOENT ; +} + +static int ffa_sync_send_receive (struct ffa_device *dev,u16 ep, +struct ffa_send_direct_data *data) +{ +return ffa_msg_send_direct_req (dev->vm_id, ep, data); +} + +static const struct ffa_dev_ops ffa_ops = { + .api_version_get = ffa_api_version_get, + .partition_id_get = ffa_partition_id_get, + .partition_info_get = ffa_partition_info_get, + .sync_send_receive = ffa_sync_send_receive, +}; +drivers/firmware/arm_ffa/driver.c static int ffa_id_get(u16 *vm_id) · line 350
Quoted 10 lines
drivers/firmware/arm_ffa/driver.c +10
-0+const struct ffa_dev_ops *ffa_dev_ops_get (struct ffa_device *dev) +{ +if (ffa_device_is_valid (dev)) +return &ffa_ops; + +return NULL ; +} +EXPORT_SYMBOL_GPL (ffa_dev_ops_get); + +int ffa_setup_partitions (struct device_node *np)This function is only used internally and the return value is ignored. Maybe make it static void instead?
drivers/firmware/arm_ffa/driver.c static int ffa_id_get(u16 *vm_id) · line 359
Quoted 9 lines
drivers/firmware/arm_ffa/driver.c +9
-0+{ +int ret; +struct device_node *child; +struct ffa_device *ffa_dev; +struct ffa_partition_info pbuf; +const char *p_uuid, *pfx ="Ignoring FFA partition" ; +uuid_t uuid =UUID_INIT (0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ); + +for_each_child_of_node (np, child) {
of_node_put()should only be called on child in case we're leaving the loop early.for_each_child_of_node()takes care of the other case.Quoted 105 lines
drivers/firmware/arm_ffa/driver.c +47
-0+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 ; + } + + ffa_dev =ffa_device_register (p_uuid, pbuf.id); +if (!ffa_dev) { +pr_err ("%s: failed to register %s\n" , pfx, p_uuid); +continue ; + } + +ffa_dev_set_drvdata (ffa_dev, drv_info); + } + +return 0 ; +} +static int __init ffa_init (void ) {int ret; +struct device_node *np; ret =arm_ffa_bus_init ();if (ret)@@ -267,6 +445,14 @@ static int __init ffa_init(void)mutex_init (&drv_info->rx_lock);mutex_init (&drv_info->tx_lock); +/* Set up all the partitions */ + np =of_find_compatible_node (NULL ,NULL ,"arm,ffa-1.0" ); +if (!np) +return 0 ; + +ffa_setup_partitions (np); +of_node_put (np); +return 0 ; free_pages:if (drv_info->tx_buffer)include/linux/arm_ffa.h +15
-1@@ -6,7 +6,6 @@#ifndef _LINUX_ARM_FFA_H#define _LINUX_ARM_FFA_H -#include <linux/cdev.h> #include <linux/device.h> #include <linux/module.h> #include <linux/types.h> @@ -47,6 +46,7 @@ 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@@ -66,6 +66,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) \@@ -84,4 +88,34 @@ static inline void ffa_driver_unregister(struct ffa_driver *driver) {}#define module_ffa_driver (__ffa_driver) \ module_driver(__ffa_driver, ffa_register, ffa_unregister) +/* FFA transport related */ +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)include/linux/arm_ffa.h static inline void ffa_driver_unregister(struct ffa_driver *driver) {} · line 110
Quoted 10 lines
include/linux/arm_ffa.h +10
-0+u32 properties; +}; + +struct ffa_send_direct_data { +unsigned long data0; +unsigned long data1; +unsigned long data2; +unsigned long data3; +unsigned long data4; +};A comment describing which register index these maps to would be helpful.
include/linux/arm_ffa.h static inline void ffa_driver_unregister(struct ffa_driver *driver) {} · line 118
Quoted 8 lines
include/linux/arm_ffa.h +8
-0+ +struct ffa_dev_ops { +u32 (*api_version_get)(void ); +u16 (*partition_id_get)(struct ffa_device *dev); +int (*partition_info_get)(const char *uuid_str, +struct ffa_partition_info *buffer); +int (*sync_send_receive)(struct ffa_device *dev,u16 ep, +struct ffa_send_direct_data *data);ep can be read directly from
dev->vm_id
We may need a way to indicate if we're to use the 32bit or 64bit calling convention. OP-TEE depends on being able to use 32bit calls here.Cheers,
JensQuoted 6 lines
include/linux/arm_ffa.h +2
-1+}; +#endif /* _LINUX_ARM_FFA_H */ --2.25.1
Re: [PATCH v3 6/7] firmware: arm_ffa: Setup in-kernel users of FFA partitions
Quoted 127 lines · Jens Wiklander
One more comment below.
Quoted 123 lines · Jens Wiklander
Hi Sudeep,
Some more comments below.
Quoted 117 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/common.h | 2 + drivers/firmware/arm_ffa/driver.c | 186 ++++++++++++++++++++++++++++++ include/linux/arm_ffa.h | 36 +++++- 3 files changed, 223 insertions(+), 1 deletion(-)drivers/firmware/arm_ffa/common.h +2
-0@@ -6,6 +6,7 @@#ifndef _FFA_COMMON_H#define _FFA_COMMON_H +#include <linux/arm_ffa.h> #include <linux/arm-smccc.h> #include <linux/err.h> @@ -17,6 +18,7 @@ typedef ffa_res_tint __init arm_ffa_bus_init (void ); void __exit arm_ffa_bus_exit(void); +bool ffa_device_is_valid (struct ffa_device *ffa_dev);#ifdef CONFIG_ARM_FFA_SMCCC int __init ffa_transport_init (ffa_fn **invoke_ffa_fn);drivers/firmware/arm_ffa/driver.c +56
-0@@ -24,9 +24,13 @@#include <linux/arm_ffa.h> #include <linux/bitfield.h> +#include <linux/device.h> #include <linux/io.h> +#include <linux/kernel.h> #include <linux/module.h> +#include <linux/of.h> #include <linux/slab.h> +#include <linux/uuid.h> #include "common.h" @@ -179,6 +183,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;@@ -203,6 +221,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);
Quoted 9 lines
Quoted 2 lines
drivers/firmware/arm_ffa/driver.c static int ffa_rxtx_unmap(u16 vm_id) · line 263
Quoted 2 lines
drivers/firmware/arm_ffa/driver.c +2
-0+ count =__ffa_partition_info_get (uuid0_4[0 ], uuid0_4[1 ], uuid0_4[2 ], + uuid0_4[3 ], &buffer);Wrong byte order?
According to section 5.3 of the SMCCC, UUIDs are returned as a single 128-bit value using the SMC32 calling convention. This value is mapped to argument registers x0-x3 on AArch64 (resp. r0-r3 on AArch32). x0 for example shall hold bytes 0 to 3, with byte 0 in the low-order bits.
I need to spend some time to understand the concern here. Initially I agreed with your analysis and then a quick review make be realise it is all OK. I need to check if my understanding is correct again. I thought I will take example and check here itself.
UUID: "fd02c9da-306c-48c7-a49c-bbd827ae86ee"
UUID[0] UUID[1] UUID[2] UUID[3] (referring uuid0_4 above)dac902fd c7486c30 d8bb9ca4 ee86ae27
It seems correct as per SMCCC convention to me, or am I missing something obvious ?
--
Regards,
Sudeep
Re: [PATCH v3 6/7] firmware: arm_ffa: Setup in-kernel users of FFA partitions
On Wed, Jan 13, 2021 at 10:44 AM Sudeep Holla <[email protected]> wrote:
[...]
Quoted 28 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
drivers/firmware/arm_ffa/driver.c +13
-0+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);Quoted 9 lines
Quoted 2 lines
drivers/firmware/arm_ffa/driver.c static int ffa_rxtx_unmap(u16 vm_id) · line 263
Quoted 2 lines
drivers/firmware/arm_ffa/driver.c +2
-0+ count =__ffa_partition_info_get (uuid0_4[0 ], uuid0_4[1 ], uuid0_4[2 ], + uuid0_4[3 ], &buffer);Wrong byte order?
According to section 5.3 of the SMCCC, UUIDs are returned as a single 128-bit value using the SMC32 calling convention. This value is mapped to argument registers x0-x3 on AArch64 (resp. r0-r3 on AArch32). x0 for example shall hold bytes 0 to 3, with byte 0 in the low-order bits.I need to spend some time to understand the concern here. Initially I agreed with your analysis and then a quick review make be realise it is all OK. I need to check if my understanding is correct again. I thought I will take example and check here itself.
Quoted 7 lines
UUID: "fd02c9da-306c-48c7-a49c-bbd827ae86ee"
UUID[0] UUID[1] UUID[2] UUID[3] (referring
uuid0_4above)dac902fdc7486c30d8bb9ca4ee86ae27It seems correct as per SMCCC convention to me, or am I missing something obvious ?
In this example I'd expect the first register to hold 0xfd02c9da regardless of the byte order of the machine. If there is a different byte order in the receiver it will still be received as 0xfd02c9da. That's how I've understood the specification.
Cheers,
Jens
Re: [PATCH v3 6/7] firmware: arm_ffa: Setup in-kernel users of FFA partitions
Quoted 31 lines · Jens Wiklander
On Wed, Jan 13, 2021 at 10:44 AM Sudeep Holla <[email protected]> wrote:
[...]Quoted 29 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
drivers/firmware/arm_ffa/driver.c +13
-0+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);Quoted 9 lines
Quoted 2 lines
drivers/firmware/arm_ffa/driver.c static int ffa_rxtx_unmap(u16 vm_id) · line 263
Quoted 2 lines
drivers/firmware/arm_ffa/driver.c +2
-0+ count =__ffa_partition_info_get (uuid0_4[0 ], uuid0_4[1 ], uuid0_4[2 ], + uuid0_4[3 ], &buffer);Wrong byte order?
According to section 5.3 of the SMCCC, UUIDs are returned as a single 128-bit value using the SMC32 calling convention. This value is mapped to argument registers x0-x3 on AArch64 (resp. r0-r3 on AArch32). x0 for example shall hold bytes 0 to 3, with byte 0 in the low-order bits.I need to spend some time to understand the concern here. Initially I agreed with your analysis and then a quick review make be realise it is all OK. I need to check if my understanding is correct again. I thought I will take example and check here itself.
UUID: "fd02c9da-306c-48c7-a49c-bbd827ae86ee"
IIUC this maps to (as per RFC4122).
fd02c9da = time_low (bytes 0-3)306c48c7 = time_mid & time_hi_and_version (bytes 4-7)a49cbbd8 = clock_seq_hi_and_reserved, clock_seq_low and bytes/octets 0-1 of node (bytes 8-11) 27ae86ee = bytes 2-5 of node (bytes 12-15)
SMCCC says:
w0 : bytes 0-3 with byte 0 in the lower order bits. w1 : bytes 4-7 with byte 4 in the lower order bits. w2 : bytes 8-11 with byte 8 in the lower order bits. w3 : bytes 12-15 with byte 12 in the lower order bits.
This should amount to:
w0 = dac902fd
w1 = c7486c30
w2 = d8bb9ca4
w3 = ee86ae27
So, even though RFC4122 uses big-endian i.e network byte order. The UUID is encoded as little-endian as per the SMCCC.
What do you reckon?
cheers,
Achin
Quoted 16 lines
Quoted 6 lines
UUID[0] UUID[1] UUID[2] UUID[3] (referring
uuid0_4above)dac902fdc7486c30d8bb9ca4ee86ae27It seems correct as per SMCCC convention to me, or am I missing something obvious ?
In this example I'd expect the first register to hold
0xfd02c9daregardless of the byte order of the machine. If there is a different byte order in the receiver it will still be received as0xfd02c9da. That's how I've understood the specification.Cheers,
Jens
Re: [PATCH v3 6/7] firmware: arm_ffa: Setup in-kernel users of FFA partitions
Quoted 54 lines · Achin Gupta
Quoted 31 lines · Jens Wiklander
On Wed, Jan 13, 2021 at 10:44 AM Sudeep Holla <[email protected]> wrote:
[...]Quoted 29 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
drivers/firmware/arm_ffa/driver.c +13
-0+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);Quoted 9 lines
Quoted 2 lines
drivers/firmware/arm_ffa/driver.c static int ffa_rxtx_unmap(u16 vm_id) · line 263
Quoted 2 lines
drivers/firmware/arm_ffa/driver.c +2
-0+ count =__ffa_partition_info_get (uuid0_4[0 ], uuid0_4[1 ], uuid0_4[2 ], + uuid0_4[3 ], &buffer);Wrong byte order?
According to section 5.3 of the SMCCC, UUIDs are returned as a single 128-bit value using the SMC32 calling convention. This value is mapped to argument registers x0-x3 on AArch64 (resp. r0-r3 on AArch32). x0 for example shall hold bytes 0 to 3, with byte 0 in the low-order bits.I need to spend some time to understand the concern here. Initially I agreed with your analysis and then a quick review make be realise it is all OK. I need to check if my understanding is correct again. I thought I will take example and check here itself.
UUID: "fd02c9da-306c-48c7-a49c-bbd827ae86ee"
IIUC this maps to (as per RFC4122).
fd02c9da=time_low(bytes 0-3)306c48c7=time_mid&time_hi_and_version(bytes 4-7)a49cbbd8=clock_seq_hi_and_reserved,clock_seq_lowand bytes/octets 0-1 of node (bytes 8-11)27ae86ee= bytes 2-5 of node (bytes 12-15)SMCCC says:
w0 : bytes 0-3 with byte 0 in the lower order bits. w1 : bytes 4-7 with byte 4 in the lower order bits. w2 : bytes 8-11 with byte 8 in the lower order bits. w3 : bytes 12-15 with byte 12 in the lower order bits.
This should amount to:
w0 =
dac902fd
w1 =c7486c30
w2 =d8bb9ca4
w3 =ee86ae27
Quoted 5 lines
So, even though RFC4122 uses big-endian i.e network byte order. The UUID is encoded as little-endian as per the SMCCC.
What do you reckon?
Thank Achin, that matches my understanding too. I spent some time looking at RFC4122[1] and concluded what we have is fine.
@Jens, one thing to note, I am not claiming to support this driver with big-endian kernel. I plan to take that up once we settle with basic support.
Quoted 7 lines
cheers,
AchinQuoted 4 lines
Quoted 4 lines
UUID[0] UUID[1] UUID[2] UUID[3] (referring
uuid0_4above)dac902fdc7486c30d8bb9ca4ee86ae27
Matches w0-w3 above, thanks for detailed explanation
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
It seems correct as per SMCCC convention to me, or am I missing something obvious ?
In this example I'd expect the first register to hold
0xfd02c9daregardless of the byte order of the machine. If there is a different byte order in the receiver it will still be received as0xfd02c9da. That's how I've understood the specification.
Signature · 4 lines
Regards, Sudeep [1] https://tools.ietf.org/html/rfc4122
Re: [PATCH v3 6/7] firmware: arm_ffa: Setup in-kernel users of FFA partitions
Quoted 56 lines · Sudeep Holla
Quoted 54 lines · Achin Gupta
Quoted 31 lines · Jens Wiklander
On Wed, Jan 13, 2021 at 10:44 AM Sudeep Holla <[email protected]> wrote:
[...]Quoted 29 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
(quoted diff) +13
-0+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);Quoted 9 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ count = __ffa_partition_info_get(uuid0_4[0], uuid0_4[1], uuid0_4[2], + uuid0_4[3], &buffer);Wrong byte order?
According to section 5.3 of the SMCCC, UUIDs are returned as a single 128-bit value using the SMC32 calling convention. This value is mapped to argument registers x0-x3 on AArch64 (resp. r0-r3 on AArch32). x0 for example shall hold bytes 0 to 3, with byte 0 in the low-order bits.I need to spend some time to understand the concern here. Initially I agreed with your analysis and then a quick review make be realise it is all OK. I need to check if my understanding is correct again. I thought I will take example and check here itself.
UUID: "fd02c9da-306c-48c7-a49c-bbd827ae86ee"
IIUC this maps to (as per RFC4122).
fd02c9da=time_low(bytes 0-3)306c48c7=time_mid&time_hi_and_version(bytes 4-7)a49cbbd8=clock_seq_hi_and_reserved,clock_seq_lowand bytes/octets 0-1 of node (bytes 8-11)27ae86ee= bytes 2-5 of node (bytes 12-15)SMCCC says:
w0 : bytes 0-3 with byte 0 in the lower order bits. w1 : bytes 4-7 with byte 4 in the lower order bits. w2 : bytes 8-11 with byte 8 in the lower order bits. w3 : bytes 12-15 with byte 12 in the lower order bits.
This should amount to:
w0 =
dac902fd
w1 =c7486c30
w2 =d8bb9ca4
w3 =ee86ae27
Quoted 8 lines
Quoted 5 lines
So, even though RFC4122 uses big-endian i.e network byte order. The UUID is encoded as little-endian as per the SMCCC.
What do you reckon?
Thank Achin, that matches my understanding too. I spent some time looking at RFC4122[1] and concluded what we have is fine.
Thanks for the analysis.
Quoted 3 lines
@Jens, one thing to note, I am not claiming to support this driver with big-endian kernel. I plan to take that up once we settle with basic support.
No worries, the OP-TEE driver doesn't support that either.
Cheers,
Jens
Quoted 25 lines
Quoted 8 lines
cheers,
AchinQuoted 4 lines
Quoted 4 lines
UUID[0] UUID[1] UUID[2] UUID[3] (referring
uuid0_4above)dac902fdc7486c30d8bb9ca4ee86ae27Matches w0-w3 above, thanks for detailed explanation
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
It seems correct as per SMCCC convention to me, or am I missing something obvious ?
In this example I'd expect the first register to hold
0xfd02c9daregardless of the byte order of the machine. If there is a different byte order in the receiver it will still be received as0xfd02c9da. That's how I've understood the specification.--
Regards,
Sudeep
Re: [PATCH v3 6/7] firmware: arm_ffa: Setup in-kernel users of FFA partitions
In reply to Jens Wiklander(sorry for late reply)
Quoted 1 line · Jens Wiklander
On Fri, Dec 4, 2020 at 1:11 PM Sudeep Holla <[email protected]> wrote:
[...]
Agreed on all the comments, so have just removed those context.
Quoted 3 lines
We may need a way to indicate if we're to use the 32bit or 64bit calling convention. OP-TEE depends on being able to use 32bit calls here.
I assume it would be OP-TEE indicating it would like to use 32-bit. I am thinking of API from the driver would be like:
int (*32bit_mode_only_set)(struct ffa_device *dev);
Let me know if that works for you. FF-A driver has no other way to evaluate that and I really don't like that in DT 😉
--
Regards,
Sudeep
Re: [PATCH v3 6/7] firmware: arm_ffa: Setup in-kernel users of FFA partitions
Quoted 13 lines · Sudeep Holla
(sorry for late reply)
Quoted 1 line · Jens Wiklander
On Fri, Dec 4, 2020 at 1:11 PM Sudeep Holla <[email protected]> wrote:
[...]
Agreed on all the comments, so have just removed those context.
Quoted 3 lines
We may need a way to indicate if we're to use the 32bit or 64bit calling convention. OP-TEE depends on being able to use 32bit calls here.
Quoted 7 lines
I assume it would be OP-TEE indicating it would like to use 32-bit. I am thinking of API from the driver would be like:
int (*32bit_mode_only_set)(struct
ffa_device*dev);Let me know if that works for you. FF-A driver has no other way to evaluate that and I really don't like that in DT 😉
That should work for OP-TEE.
Thanks,
Jens
PATCH v3 7/7 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 | 180 ++++++++++++++++++++++++++++++ include/linux/arm_ffa.h | 149 +++++++++++++++++++++++++ 2 files changed, 329 insertions(+)
drivers/firmware/arm_ffa/driver.c +180 -0
@@ -28,7 +28,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/uuid.h>
@@ -306,6 +308,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 ; +} +static u32 ffa_api_version_get (void ) {return drv_info->version;
@@ -331,11 +504,18 @@ static int ffa_sync_send_receive(struct ffa_device *dev, u16 ep,return ffa_msg_send_direct_req (dev->vm_id, ep, data); } +static int ffa_memory_share (struct ffa_mem_ops_args *args) +{ +return ffa_memory_ops (FFA_FN_NATIVE (MEM_SHARE ), args); +} +static const struct ffa_dev_ops ffa_ops = { .api_version_get = ffa_api_version_get, .partition_id_get = ffa_partition_id_get, .partition_info_get = ffa_partition_info_get, .sync_send_receive = ffa_sync_send_receive, + .memory_reclaim = ffa_memory_reclaim, + .memory_share = ffa_memory_share, };const struct ffa_dev_ops *ffa_dev_ops_get (struct ffa_device *dev)
include/linux/arm_ffa.h +149 -0
161 lines not on this page · raw message
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v3 7/7] firmware: arm_ffa: Add support for MEM_* interfaces
Quoted 37 lines · Sudeep Holla
Most of the MEM_* APIs share the same parameters, so they can be generalised. Currently only
MEM_SHAREis implemented and the user space interface for that is not added yet.Signed-off-by Sudeep Holla <[email protected]>--- drivers/firmware/arm_ffa/driver.c | 180 ++++++++++++++++++++++++++++++ include/linux/arm_ffa.h | 149 +++++++++++++++++++++++++ 2 files changed, 329 insertions(+)drivers/firmware/arm_ffa/driver.c +10
-0@@ -28,7 +28,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/uuid.h> @@ -306,6 +308,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 )
drivers/firmware/arm_ffa/driver.c static int ffa_msg_send_direct_req(u16 src_id, u16 dst_id, · line 328
Quoted 10 lines
drivers/firmware/arm_ffa/driver.c +10
-0+ 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);
ret.a2 are the lower 32bit and ret.a3 the higher 32bits according to 5.10.2 Memory region handle
Quoted 48 lines
drivers/firmware/arm_ffa/driver.c +48
-0+ +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)
drivers/firmware/arm_ffa/driver.c static int ffa_msg_send_direct_req(u16 src_id, u16 dst_id, · line 386
Quoted 10 lines
drivers/firmware/arm_ffa/driver.c +10
-0+{ +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 ;
This must be zero following the same logic as for addr, see 11.3 FFA_MEM_SHARE
Quoted 260 lines
drivers/firmware/arm_ffa/driver.c +102
-0+ + 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 ; +} +static u32 ffa_api_version_get (void ) {return drv_info->version;@@ -331,11 +504,18 @@ static int ffa_sync_send_receive(struct ffa_device *dev, u16 ep,return ffa_msg_send_direct_req (dev->vm_id, ep, data); } +static int ffa_memory_share (struct ffa_mem_ops_args *args) +{ +return ffa_memory_ops (FFA_FN_NATIVE (MEM_SHARE ), args); +} +static const struct ffa_dev_ops ffa_ops = { .api_version_get = ffa_api_version_get, .partition_id_get = ffa_partition_id_get, .partition_info_get = ffa_partition_info_get, .sync_send_receive = ffa_sync_send_receive, + .memory_reclaim = ffa_memory_reclaim, + .memory_share = ffa_memory_share, };const struct ffa_dev_ops *ffa_dev_ops_get (struct ffa_device *dev)include/linux/arm_ffa.h +135
-0@@ -109,6 +109,153 @@ struct ffa_send_direct_data {unsigned long data4; }; +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) \
include/linux/arm_ffa.h struct ffa_send_direct_data { · line 256
Quoted 10 lines
include/linux/arm_ffa.h +10
-0+ (COMPOSITE_OFFSET(x) + CONSTITUENTS_OFFSET(y)) + +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;
It seems a bit inconvenient with a pointer instead of a value here.
Cheers,
Jens
Quoted 15 lines
include/linux/arm_ffa.h +4
-1+}; +struct ffa_dev_ops {u32 (*api_version_get)(void );u16 (*partition_id_get)(struct ffa_device *dev);@@ -116,6 +263,8 @@ struct ffa_dev_ops { struct ffa_partition_info *buffer);int (*sync_send_receive)(struct ffa_device *dev,u16 ep,struct ffa_send_direct_data *data); +int (*memory_reclaim)(u64 g_handle,u32 flags); + int (*memory_share)(struct ffa_mem_ops_args *args); };#endif /* _LINUX_ARM_FFA_H */ --
Quoted 2 lines
2.25.1
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel