firmware: Add initial support for Arm FF-A
Subsystems (4)
v5 cover firmware: Add initial support for Arm FF-A
Hi all,
This is very basic implementation for in-kernel support for Arm FF-A specification.
iArm 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. This is currently tested with OPTEE(with changes to OPTEE driver adding FFA as transport)
The series can be fetched from [2]
--
Regards,
Sudeep
[1] https://developer.arm.com/documentation/den0077/latest
[2] git://git.kerniel.org/pub/scm/linux/kernel/git/sudeep.holla/linux.git v5.12/v5_ffa
v4->v5:
- Fixed couple of comments in DT bindings
- Moved to use native version of RXTX_MAP call, fixed vm_id param to RXTX_UNMAP, dropped couple of unused confusingly named macros (can be added back with correct name when we need to use them)
v3->v4:
- Added support to allow partitions to set 32bit only mode
- Addressed all the comments from Jens Wiklander
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 | 57 ++ 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 | 181 +++++ drivers/firmware/arm_ffa/common.h | 32 + drivers/firmware/arm_ffa/driver.c | 672 ++++++++++++++++++ drivers/firmware/arm_ffa/smccc.c | 54 ++ include/linux/arm-smccc.h | 50 ++ include/linux/arm_ffa.h | 266 +++++++ 13 files changed, 1367 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
Signature · 1 line
2.25.1
PATCH v5 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 | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/arm,ffa.yaml
Documentation/devicetree/bindings/arm/arm,ffa.yaml new file +57 -0
@@ -0,0 +1,57 @@ +# 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: + 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-partition-0 { + compatible = "arm,ffa-1.0-partition"; + uuid = "12345678-9abc-def0-1234-56789abcdef0"; + }; + };
Signature · 1 line
2.25.1
Re: [PATCH v5 1/7] dt-bindings: Arm: Add Firmware Framework for Armv8-A (FF-A) binding
Hi Sudeep,
Apologies for catching up late on this patch-set.
Quoted 5 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.
Wouldn't we be able to implement auto-discovery of ffa partitions? I think enumeration of ffa partitions on FFA bus should be quite similar to enumeration of TAs on TEE bus (see [1]). Otherwise we need to put these redundant DT entries for every ffa partition which IMHO would bloat up device trees for every platform.
-Sumit
Quoted 80 lines
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 | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/arm,ffa.yamlDocumentation/devicetree/bindings/arm/arm,ffa.yaml new file +57
-1@@ -0,0 +1,57 @@ +# 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: + 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-partition-0 { + compatible = "arm,ffa-1.0-partition"; + uuid = "12345678-9abc-def0-1234-56789abcdef0"; + }; + }; --2.25.1
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 1/7] dt-bindings: Arm: Add Firmware Framework for Armv8-A (FF-A) binding
Quoted 11 lines · Sumit Garg
Hi Sudeep,
Apologies for catching up late on this patch-set.
Quoted 5 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.
Quoted 6 lines
Wouldn't we be able to implement auto-discovery of ffa partitions? I think enumeration of ffa partitions on FFA bus should be quite similar to enumeration of TAs on TEE bus (see [1]). Otherwise we need to put these redundant DT entries for every ffa partition which IMHO would bloat up device trees for every platform.
Any suggestions on how to ? Clearly spec doesn't have that provision, I had raised this point in the past. Jens has similar concern and he did ask the same[1]. As I replied to him in that thread[2].
I am open to suggestion on how to auto-discover, currently as I see spec doesn't support it.
--
Regards,
Sudeep
[1] https://lore.kernel.org/linux-arm-kernel/20201216134659.GA4146223@jade/
[2] https://lore.kernel.org/linux-arm-kernel/20210113092236.pnabzaufzuzwprmw@bogus/
Re: [PATCH v5 1/7] dt-bindings: Arm: Add Firmware Framework for Armv8-A (FF-A) binding
Quoted 20 lines · Sudeep Holla
Quoted 11 lines · Sumit Garg
Hi Sudeep,
Apologies for catching up late on this patch-set.
Quoted 5 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.
Quoted 6 lines
Wouldn't we be able to implement auto-discovery of ffa partitions? I think enumeration of ffa partitions on FFA bus should be quite similar to enumeration of TAs on TEE bus (see [1]). Otherwise we need to put these redundant DT entries for every ffa partition which IMHO would bloat up device trees for every platform.
Quoted 7 lines
Any suggestions on how to ? Clearly spec doesn't have that provision, I had raised this point in the past. Jens has similar concern and he did ask the same[1]. As I replied to him in that thread[2].
I am open to suggestion on how to auto-discover, currently as I see spec doesn't support it.
Thanks for sharing links to prior discussions and I can see that currently spec doesn't support it. But from an implementation perspective, I can't find any reason that we can't support auto-discover. Have a look at below proposed simple FFA ABI:
FFA_LIST_PARTITIONS
- No input params.
- Returns an array of secure partition UUIDs to which this non-secure virtual/physical FF-A instance is allowed to communicate with.
I think with auto-discovery, one of the major benefits is that if the OEM is using a common platform to cater to multiple use-cases which rely on different secure partitions then OEM doesn't have to bother about shipping separate DTs.
-Sumit
Quoted 6 lines
--
Regards,
Sudeep[1] https://lore.kernel.org/linux-arm-kernel/20201216134659.GA4146223@jade/
[2] https://lore.kernel.org/linux-arm-kernel/20210113092236.pnabzaufzuzwprmw@bogus/
Rob Herring
maintainerRe: [PATCH v5 1/7] dt-bindings: Arm: Add Firmware Framework for Armv8-A (FF-A) binding
Quoted 36 lines · Sumit Garg
Quoted 20 lines · Sudeep Holla
Quoted 11 lines · Sumit Garg
Hi Sudeep,
Apologies for catching up late on this patch-set.
Quoted 5 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.
Quoted 6 lines
Wouldn't we be able to implement auto-discovery of ffa partitions? I think enumeration of ffa partitions on FFA bus should be quite similar to enumeration of TAs on TEE bus (see [1]). Otherwise we need to put these redundant DT entries for every ffa partition which IMHO would bloat up device trees for every platform.
Quoted 7 lines
Any suggestions on how to ? Clearly spec doesn't have that provision, I had raised this point in the past. Jens has similar concern and he did ask the same[1]. As I replied to him in that thread[2].
I am open to suggestion on how to auto-discover, currently as I see spec doesn't support it.
Thanks for sharing links to prior discussions and I can see that currently spec doesn't support it. But from an implementation perspective, I can't find any reason that we can't support auto-discover. Have a look at below proposed simple FFA ABI:
FFA_LIST_PARTITIONS
Quoted 8 lines
- No input params.
- Returns an array of secure partition UUIDs to which this non-secure virtual/physical FF-A instance is allowed to communicate with.I think with auto-discovery, one of the major benefits is that if the OEM is using a common platform to cater to multiple use-cases which rely on different secure partitions then OEM doesn't have to bother about shipping separate DTs.
+1
DT should not be the dumping ground for everything forgotten to be made discoverable. There's not much we can do about h/w, but firmware is different and can be changed. In other threads (e.g. PCI config space SMC calls), fixing in firmware is the proposed answer. So let's do that here.
Maybe if there are implementations shipping and changing is too late (yet not too late to use a new binding), then I'd feel differently. But being in a spec or not alone is not enough reason alone to accept this. It's obvious the spec did not have wide enough review.
Rob
Re: [PATCH v5 1/7] dt-bindings: Arm: Add Firmware Framework for Armv8-A (FF-A) binding
Hi Rob,
Quoted 54 lines · Rob Herring
Quoted 36 lines · Sumit Garg
Quoted 20 lines · Sudeep Holla
Quoted 11 lines · Sumit Garg
Hi Sudeep,
Apologies for catching up late on this patch-set.
Quoted 5 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.
Quoted 6 lines
Wouldn't we be able to implement auto-discovery of ffa partitions? I think enumeration of ffa partitions on FFA bus should be quite similar to enumeration of TAs on TEE bus (see [1]). Otherwise we need to put these redundant DT entries for every ffa partition which IMHO would bloat up device trees for every platform.
Quoted 7 lines
Any suggestions on how to ? Clearly spec doesn't have that provision, I had raised this point in the past. Jens has similar concern and he did ask the same[1]. As I replied to him in that thread[2].
I am open to suggestion on how to auto-discover, currently as I see spec doesn't support it.
Thanks for sharing links to prior discussions and I can see that currently spec doesn't support it. But from an implementation perspective, I can't find any reason that we can't support auto-discover. Have a look at below proposed simple FFA ABI:
FFA_LIST_PARTITIONSQuoted 8 lines
- No input params.
- Returns an array of secure partition UUIDs to which this non-secure virtual/physical FF-A instance is allowed to communicate with.I think with auto-discovery, one of the major benefits is that if the OEM is using a common platform to cater to multiple use-cases which rely on different secure partitions then OEM doesn't have to bother about shipping separate DTs.
+1
DT should not be the dumping ground for everything forgotten to be made discoverable. There's not much we can do about h/w, but firmware is different and can be changed. In other threads (e.g. PCI config space SMC calls), fixing in firmware is the proposed answer. So let's do that here.
Quoted 4 lines
Maybe if there are implementations shipping and changing is too late (yet not too late to use a new binding), then I'd feel differently. But being in a spec or not alone is not enough reason alone to accept this. It's obvious the spec did not have wide enough review.
The v1.0 specification (released almost one year back) was reviewed by a few Trusted OS vendors amongst other partners. Nobody provided feedback that a FFA_LIST_PARTITIONS like discovery mechanism is a gating factor. Hindsight is a wonderful thing! The ability of discover UUIDs of partitions would indeed be a very useful thing and this will be added to the next version of the specification. I think it is worth providing some background in any case.
The usage model envisioned was that a partition would export services that would be identified by a UUID. An FF-A client that wants to use these services would query their presence by specifying this UUID. The FF-A discovery ABI returns a 16-bit ID of the partition that implements the services. This ID is more user-friendly and space efficient than a 16 byte UUID for register and shared memory based IPC between the client and the server.
For example, OP-TEE would have a UUID to represent the TEE service. The OP-TEE driver would ask the FF-A driver if there is a partition with a UUID that provides OP-TEE's TEE service.
The assumption was that a client must identify the service(s) it wants to access to be able to use FF-A ABIs to talk to the partition that implements them. This was more important than a discovery mechanism where the client says: I don't know what I want but please list all the UUIDs of all partitions in the system. I will then see if I can find anything that I like.
In this model, it was not envisioned that the FF-A driver would carry the UUIDs of services that its clients could want to access. The client would know the UUID and the FF-A driver would return the properties of the partition and its ID to enable further communication.
We did envision the need for the FF-A driver to know the IDs of all the partitions in the system and their properties e.g. number of vCPUs etc. The FFA_PARTITION_INFO_GET ABI when invoked with a NULL UUID returns this information. It is a bit like "grep *.*".
The implementation choice to have an FF-A bus with partitions as devices on it was made after the specification was released. This was not obvious at all at the time of writing the specification. Clearly, in this model the FF-A driver needs to the know the UUIDs. But this does not change the fact that the clients of the FF-A driver still need to know the UUID of the services they are interested in.
For v1.0 we are left with no choice but to carry them in the DT. This will be addressed in v1.1. I see this as a case where implementation choices drive the evolution of a specification.
I hope you can understand that it was a bit difficult to foresee this usage model for v1.0 when specification and implementation are temporally separated.
I also think that this issue is different from the cluster **** the PCIe ECAM SMC discussion is.
I do hope this helps clarify the situation to some extent. Please let me know if you need any more info or if I have missed anything. Also, apologies for not getting back sooner as I was on holiday.
cheers,
Achin
PATCH v5 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(+)
Hi Will/Catalin,
I seemed to have missed you on these patches. I realised only when I was collecting Acks to get this series merged. The change here is simple, it would be good if you can review and ack if you are OK with it so that I can get the serier merged via ARM SoC.
arch/arm64/kernel/asm-offsets.c +4 -0
@@ -132,6 +132,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
Mark Rutland
maintainerRe: [PATCH v5 2/7] arm64: smccc: Add support for SMCCCv1.2 input/output registers
Hi Sudeep,
Quoted 9 lines · Sudeep Holla
SMCCC v1.2 allows x8-x17 to be used as parameter registers and x4—x17 to be used as result registers in SMC64/HVC64. Arm Firmware Framework for Armv8-A specification makes use of x0-x7 as parameter and result registers.
Current SMCCC interface in the kernel just use x0-x7 as parameter and x0-x3 as result registers. Let us add new interface to support x0-x7 as parameter and result registers. This can be extended to include x8-x17 when there are users for the same.
Michael Kelley is also looking at using SMCCCv1.2, and on his HyperV thread I'd suggested we should deal with the whole set of SMCCCv1.2 registers now to avoid future churn in this area (using struct both for the arguments and return values).
How painful would it be to extend this patch to do that?
Thanks,
Mark.
Quoted 132 lines
Tested-by Jens Wiklander <[email protected]>Cc Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Signed-off-by Sudeep Holla <[email protected]>--- arch/arm64/kernel/asm-offsets.c | 4 +++ arch/arm64/kernel/smccc-call.S | 22 +++++++++++++++ include/linux/arm-smccc.h | 50 +++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+)Hi Will/Catalin,
I seemed to have missed you on these patches. I realised only when I was collecting Acks to get this series merged. The change here is simple, it would be good if you can review and ack if you are OK with it so that I can get the serier merged via ARM SoC.
arch/arm64/kernel/asm-offsets.c +4
-0@@ -132,6 +132,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@@ -186,6 +186,56 @@ struct arm_smccc_res {unsigned long a3; }; +#ifdef CONFIG_ARM64 +/* TODO Need to implement for ARM too */ +/** +* struct arm_smccc_v1_2_res - Result from SMC/HVC call +* @a0-a7 result values from registers 0 to 7 +*/ +struct arm_smccc_v1_2_res { +unsigned long a0; +unsigned long a1; +unsigned long a2; +unsigned long a3; +unsigned long a4; +unsigned long a5; +unsigned long a6; +unsigned long a7; +}; + +/** +* arm_smccc_v1_2_hvc() - make HVC calls +* @a0-a7: arguments passed in registers 0 to 7 +* @res: result values from registers 0 to 7 +* +* This function is used to make HVC calls following SMC Calling Convention +* v1.2 or above. The content of the supplied param are copied to registers +* 0 to 7 prior to the HVC instruction. The return values are updated with +* the content from register 0 to 7 on return from the HVC instruction. +*/ +asmlinkage +void arm_smccc_v1_2_hvc(unsigned long a0, unsigned long a1, unsigned long a2, +unsigned long a3,unsigned long a4,unsigned long a5, +unsigned long a6,unsigned long a7, +struct arm_smccc_v1_2_res *res); + +/** +* arm_smccc_v1_2_smc() - make SMC calls +* @a0-a7: arguments passed in registers 0 to 7 +* @res: result values from registers 0 to 7 +* +* This function is used to make SMC calls following SMC Calling Convention +* v1.2 or above. The content of the supplied param are copied to registers +* 0 to 7 prior to the SMC instruction. The return values are updated with +* the content from register 0 to 7 on return from the SMC instruction. +*/ +asmlinkage +void arm_smccc_v1_2_smc(unsigned long a0, unsigned long a1, unsigned long a2, +unsigned long a3,unsigned long a4,unsigned long a5, +unsigned long a6,unsigned long a7, +struct arm_smccc_v1_2_res *res); +#endif +/** * struct arm_smccc_quirk - Contains quirk information * @id: quirk identification Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Mark Rutland
maintainerRe: [PATCH v5 2/7] arm64: smccc: Add support for SMCCCv1.2 input/output registers
Quoted 13 lines · Mark Rutland
Hi Sudeep,
Quoted 9 lines · Sudeep Holla
SMCCC v1.2 allows x8-x17 to be used as parameter registers and x4—x17 to be used as result registers in SMC64/HVC64. Arm Firmware Framework for Armv8-A specification makes use of x0-x7 as parameter and result registers.
Current SMCCC interface in the kernel just use x0-x7 as parameter and x0-x3 as result registers. Let us add new interface to support x0-x7 as parameter and result registers. This can be extended to include x8-x17 when there are users for the same.
Quoted 6 lines
Michael Kelley is also looking at using SMCCCv1.2, and on his HyperV thread I'd suggested we should deal with the whole set of SMCCCv1.2 registers now to avoid future churn in this area (using struct both for the arguments and return values).
How painful would it be to extend this patch to do that?
I *think* the major change with this would be making the interfaces:
void arm_smccc_1_2_{hvc,smc}(struct arm_smccc_1_2_args *args,
struct arm_smccc_1_2_res *res);
... and callers manipulating the structs directly, with arm64 having more fields, e.g.
// arm64
struct arm_smccc_1_2_args {
unsigned long a1;
...
unsigned long a17;
}struct arm_smccc_1_2_res {
unsigned long a0;
...
unsigned long a17;
}// arm
struct arm_smccc_1_2_args {
unsigned long a1;
...
unsigned long a7;
}struct arm_smccc_1_2_res {
unsigned long a0;
...
unsigned long a7;
}I think that can be hidden in the FF-A wrappers, so that doesn't need to be what FF-A drivers see. Does that sound plausible, or is that painful?
Quoted 1 line
Quoted 1 line
+
DEFINE(ARM_SMCCC_V1_2_RES_X0_OFFS, offsetof(struct arm_smccc_v1_2_res, a0));
As a general nit, for consistency with the existing arm_smccc_1_1 code, could we please drop the 'V' in these names, and use ARM_SMCCC_1_2 or arm_smccc_1_2 ?
FWIW, other than the above comments, this all looks good to me
Thanks,
Mark.
Quoted 104 lines
Quoted 99 lines
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@@ -186,6 +186,56 @@ struct arm_smccc_res {unsigned long a3; }; +#ifdef CONFIG_ARM64 +/* TODO Need to implement for ARM too */ +/** +* struct arm_smccc_v1_2_res - Result from SMC/HVC call +* @a0-a7 result values from registers 0 to 7 +*/ +struct arm_smccc_v1_2_res { +unsigned long a0; +unsigned long a1; +unsigned long a2; +unsigned long a3; +unsigned long a4; +unsigned long a5; +unsigned long a6; +unsigned long a7; +}; + +/** +* arm_smccc_v1_2_hvc() - make HVC calls +* @a0-a7: arguments passed in registers 0 to 7 +* @res: result values from registers 0 to 7 +* +* This function is used to make HVC calls following SMC Calling Convention +* v1.2 or above. The content of the supplied param are copied to registers +* 0 to 7 prior to the HVC instruction. The return values are updated with +* the content from register 0 to 7 on return from the HVC instruction. +*/ +asmlinkage +void arm_smccc_v1_2_hvc(unsigned long a0, unsigned long a1, unsigned long a2, +unsigned long a3,unsigned long a4,unsigned long a5, +unsigned long a6,unsigned long a7, +struct arm_smccc_v1_2_res *res); + +/** +* arm_smccc_v1_2_smc() - make SMC calls +* @a0-a7: arguments passed in registers 0 to 7 +* @res: result values from registers 0 to 7 +* +* This function is used to make SMC calls following SMC Calling Convention +* v1.2 or above. The content of the supplied param are copied to registers +* 0 to 7 prior to the SMC instruction. The return values are updated with +* the content from register 0 to 7 on return from the SMC instruction. +*/ +asmlinkage +void arm_smccc_v1_2_smc(unsigned long a0, unsigned long a1, unsigned long a2, +unsigned long a3,unsigned long a4,unsigned long a5, +unsigned long a6,unsigned long a7, +struct arm_smccc_v1_2_res *res); +#endif +/** * struct arm_smccc_quirk - Contains quirk information * @id: quirk identification Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 2/7] arm64: smccc: Add support for SMCCCv1.2 input/output registers
Quoted 49 lines · Mark Rutland
Quoted 13 lines · Mark Rutland
Hi Sudeep,
Quoted 9 lines · Sudeep Holla
SMCCC v1.2 allows x8-x17 to be used as parameter registers and x4—x17 to be used as result registers in SMC64/HVC64. Arm Firmware Framework for Armv8-A specification makes use of x0-x7 as parameter and result registers.
Current SMCCC interface in the kernel just use x0-x7 as parameter and x0-x3 as result registers. Let us add new interface to support x0-x7 as parameter and result registers. This can be extended to include x8-x17 when there are users for the same.
Quoted 6 lines
Michael Kelley is also looking at using SMCCCv1.2, and on his HyperV thread I'd suggested we should deal with the whole set of SMCCCv1.2 registers now to avoid future churn in this area (using struct both for the arguments and return values).
How painful would it be to extend this patch to do that?
I *think* the major change with this would be making the interfaces:
void arm_smccc_1_2_{hvc,smc}(struct
arm_smccc_1_2_args*args,struct arm_smccc_1_2_res *res);... and callers manipulating the structs directly, with arm64 having more fields, e.g.
// arm64
struct arm_smccc_1_2_args { unsigned long a1; ... unsigned long a17; }struct arm_smccc_1_2_res { unsigned long a0; ... unsigned long a17; }// arm
struct arm_smccc_1_2_args { unsigned long a1; ... unsigned long a7; }
Quoted 9 lines
struct arm_smccc_1_2_res { unsigned long a0; ... unsigned long a7; }I think that can be hidden in the FF-A wrappers, so that doesn't need to be what FF-A drivers see. Does that sound plausible, or is that painful?
Sounds possible, will give it a try.
Quoted 6 lines
Quoted 1 line
Quoted 1 line
+
DEFINE(ARM_SMCCC_V1_2_RES_X0_OFFS, offsetof(struct arm_smccc_v1_2_res, a0));As a general nit, for consistency with the existing
arm_smccc_1_1code, could we please drop the 'V' in these names, and useARM_SMCCC_1_2orarm_smccc_1_2?
Sure, makes sense.
Quoted 2 lines
FWIW, other than the above comments, this all looks good to me
Thanks.
--
Regards,
Sudeep
RE: [PATCH v5 2/7] arm64: smccc: Add support for SMCCCv1.2 input/output registers
From: Sudeep Holla <[email protected]> Sent: Friday, March 26, 2021 5:51 AM
Quoted 73 lines · Mark Rutland
Quoted 49 lines · Mark Rutland
Quoted 13 lines
Hi Sudeep,
Quoted 9 lines · Sudeep Holla
SMCCC v1.2 allows x8-x17 to be used as parameter registers and x4—x17 to be used as result registers in SMC64/HVC64. Arm Firmware Framework for Armv8-A specification makes use of x0-x7 as parameter and result registers.
Current SMCCC interface in the kernel just use x0-x7 as parameter and x0-x3 as result registers. Let us add new interface to support x0-x7 as parameter and result registers. This can be extended to include x8-x17 when there are users for the same.
Quoted 6 lines
Michael Kelley is also looking at using SMCCCv1.2, and on his HyperV thread I'd suggested we should deal with the whole set of SMCCCv1.2 registers now to avoid future churn in this area (using struct both for the arguments and return values).
How painful would it be to extend this patch to do that?
I *think* the major change with this would be making the interfaces:
void arm_smccc_1_2_{hvc,smc}(struct
arm_smccc_1_2_args*args,struct arm_smccc_1_2_res *res);... and callers manipulating the structs directly, with arm64 having more fields, e.g.
// arm64
struct arm_smccc_1_2_args { unsigned long a1; ... unsigned long a17; }struct arm_smccc_1_2_res { unsigned long a0; ... unsigned long a17; }// arm
struct arm_smccc_1_2_args { unsigned long a1; ... unsigned long a7; }Quoted 9 lines
struct arm_smccc_1_2_res { unsigned long a0; ... unsigned long a7; }I think that can be hidden in the FF-A wrappers, so that doesn't need to be what FF-A drivers see. Does that sound plausible, or is that painful?
Sounds possible, will give it a try.
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ DEFINE(ARM_SMCCC_V1_2_RES_X0_OFFS, offsetof(struct
arm_smccc_v1_2_res, a0));Quoted 5 lines
As a general nit, for consistency with the existing
arm_smccc_1_1code, could we please drop the 'V' in these names, and useARM_SMCCC_1_2orarm_smccc_1_2?Sure, makes sense.
Quoted 8 lines
Quoted 2 lines
FWIW, other than the above comments, this all looks good to me
Thanks.
--
Regards,
Sudeep
Sudeep -- let me know when you have a new version available. I can test it for use with Hyper-V.
Michael
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v5 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 | 91 +++++++++++++++ 6 files changed, 300 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 +91 -0
91 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v5 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 | 14 +- drivers/firmware/arm_ffa/common.h | 26 +++ drivers/firmware/arm_ffa/driver.c | 300 ++++++++++++++++++++++++++++++ 4 files changed, 332 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 +4 -10
@@ -13,6 +13,8 @@#include <linux/slab.h> #include <linux/types.h> +#include "common.h" +static int ffa_device_match (struct device *dev,struct device_driver *drv) {const struct ffa_device_id *id_table;
@@ -167,21 +169,13 @@ void ffa_device_unregister(struct ffa_device *ffa_dev) }EXPORT_SYMBOL_GPL (ffa_device_unregister); -static int __init arm_ffa_bus_init (void ) +int __init arm_ffa_bus_init (void ) {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 +300 -0
300 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v5 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 · 1 line
2.25.1
PATCH v5 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 | 188 ++++++++++++++++++++++++++++++ include/linux/arm_ffa.h | 38 +++++- 3 files changed, 227 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 +188 -0
224 lines not on this page · raw message
include/linux/arm_ffa.h +37 -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>
@@ -15,6 +14,7 @@/* FFA Bus/Device/Driver related */ struct ffa_device {int vm_id; +bool mode_32bit;uuid_t uuid;struct device dev; };
@@ -48,6 +48,7 @@ int ffa_driver_register(struct ffa_driver *driver, struct module *owner, const char *mod_name);void ffa_driver_unregister (struct ffa_driver *driver);bool ffa_device_is_valid (struct ffa_device *ffa_dev); +const struct ffa_dev_ops *ffa_dev_ops_get (struct ffa_device *dev);#else static inline
@@ -70,6 +71,10 @@ static inline void ffa_driver_unregister(struct ffa_driver *driver) {}static inline bool ffa_device_is_valid (struct ffa_device *ffa_dev) {return false; } +const struct ffa_dev_ops *ffa_dev_ops_get (struct ffa_device *dev) +{ +return NULL ; +}#endif /* CONFIG_ARM_FFA_TRANSPORT */ #define ffa_register (driver) \
@@ -88,4 +93,35 @@ bool ffa_device_is_valid(struct ffa_device *ffa_dev) { return false; }#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; +}; + +/* For use with FFA_MSG_SEND_DIRECT_{REQ,RESP} which pass data via registers */ +struct ffa_send_direct_data { +unsigned long data0;/* w3/x3 */ +unsigned long data1;/* w4/x4 */ +unsigned long data2;/* w5/x5 */ +unsigned long data3;/* w6/x6 */ +unsigned long data4;/* w7/x7 */ +}; + +struct ffa_dev_ops { +u32 (*api_version_get)(void ); +int (*partition_info_get)(const char *uuid_str, +struct ffa_partition_info *buffer); +void (*mode_32bit_set)(struct ffa_device *dev); +int (*sync_send_receive)(struct ffa_device *dev, +struct ffa_send_direct_data *data); +}; +#endif /* _LINUX_ARM_FFA_H */
Signature · 1 line
2.25.1
RE: [PATCH v5 6/7] firmware: arm_ffa: Setup in-kernel users of FFA partitions
Hi Sudeep,
Quoted 32 lines
-----Original Message-----
From: Sudeep Holla <[email protected]>
Sent: 25 March 2021 14:33
To: [email protected]; [email protected]
Cc: Sudeep Holla <[email protected]>; Trilok Soni <[email protected]>; [email protected]; Andrew Walbran <[email protected]>; David Hartley <[email protected]>; Achin Gupta <[email protected]>; Jens Wiklander <[email protected]>; Arunachalam Ganapathy <[email protected]>; Marc Bonnici <[email protected]>
Subject: [PATCH v5 6/7] firmware:arm_ffa: Setup in-kernel users of FFA partitionsParse 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.
Reviewed-by Jens Wiklander <[email protected]>Tested-by Jens Wiklander <[email protected]>Signed-off-by Sudeep Holla <[email protected]>--- drivers/firmware/arm_ffa/common.h | 2 + drivers/firmware/arm_ffa/driver.c | 188 ++++++++++++++++++++++++++++++ include/linux/arm_ffa.h | 38 +++++- 3 files changed, 227 insertions(+), 1 deletion(-)
[snip]
Quoted 26 lines
+static int ffa_msg_send_direct_req(u16
src_id, u16dst_id, boolmode_32bit,(quoted diff) +2
-0+ struct ffa_send_direct_data *data) { + u32 req_id, resp_id, src_dst_ids = PACK_TARGET_INFO(src_id,
dst_id);drivers/firmware/arm_ffa/driver.c +11
-0+ffa_res_t ret; + +if (mode_32bit) { + req_id =FFA_MSG_SEND_DIRECT_REQ ; + resp_id =FFA_MSG_SEND_DIRECT_RESP ; + }else { + req_id =FFA_FN_NATIVE (MSG_SEND_DIRECT_REQ ); + resp_id =FFA_FN_NATIVE (MSG_SEND_DIRECT_RESP ); + } + + ret = invoke_ffa_fn(req_id, src_dst_ids, 0, data->data0, data-Quoted 1 line
data1,
drivers/firmware/arm_ffa/driver.c +8
-0+ 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 == resp_id) {
drivers/firmware/arm_ffa/driver.c static int ffa_id_get(u16 *vm_id) · line 323
Quoted 10 lines
drivers/firmware/arm_ffa/driver.c +10
-0+ data->data0 = ret.a3; + data->data1 = ret.a4; + data->data2 = ret.a5; + data->data3 = ret.a6; + data->data4 = ret.a7; + } + +return 0 ; +} +
If the returned function ID is not FFA_ERROR but still not what we're expecting here we should return an error to the calling code rather than success.
Kind Regards
Marc Bonnici
PATCH v5 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 | 184 ++++++++++++++++++++++++++++++ include/linux/arm_ffa.h | 139 ++++++++++++++++++++++ 2 files changed, 323 insertions(+)
drivers/firmware/arm_ffa/driver.c +184 -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>
@@ -321,6 +323,177 @@ static int ffa_msg_send_direct_req(u16 src_id, u16 dst_id, bool mode_32bit,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.a2, ret.a3); + +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, buf_sz =0 , num_entries =sg_nents (args->sg); + + 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); + buf_sz = max_fragsize /FFA_PAGE_SIZE ; + } + + 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;
@@ -346,11 +519,22 @@ static int ffa_sync_send_receive(struct ffa_device *dev, dev->mode_32bit, data); } +static int +ffa_memory_share (struct ffa_device *dev,struct ffa_mem_ops_args *args) +{ +if (dev->mode_32bit) +return ffa_memory_ops (FFA_MEM_SHARE , 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_info_get = ffa_partition_info_get, .mode_32bit_set = ffa_mode_32bit_set, .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 +139 -0
151 lines not on this page · raw message
Signature · 1 line
2.25.1