TI K3 M4F support on AM64x and AM62x SoCs
Subsystems (2)
v3 cover TI K3 M4F support on AM64x and AM62x SoCs
The following series introduces K3 M4F remoteproc driver support for AM64x and AM62x SoC families. These SoCs have a ARM Cortex M4F core in the MCU voltage domain. For safety oriented applications, this core is operated independently with out any IPC to other cores on the SoC. However, for non safety applications, some customers use it as a remote processor and so linux remote proc support is extended to the M4F core.
See AM64x Technical Reference Manual (SPRUIM2C – SEPTEMBER 2021) for further details: https://www.ti.com/lit/pdf/SPRUIM2
This series was originally submitted by Hari in Jan 2022. Review comments were made, however I've been unable to find any further submissions. I have tried to contact the author and have received no reply. As we are interested in using this functionality, we have decided to pick this up and see if we can get it merged.
Hari Nagalla (1):
dt-bindings: remoteproc: k3-m4f: Add bindings for K3 AM64x SoCs
Martyn Welch (2):
remoteproc: k4: Split out functions common with M4 driver
remoteproc: k4-m4: Add a remoteproc driver for M4F subsystem
.../bindings/remoteproc/ti,k3-m4f-rproc.yaml | 158 ++++++ drivers/remoteproc/Kconfig | 13 + drivers/remoteproc/Makefile | 3 +- drivers/remoteproc/ti_k3_common.c | 375 +++++++++++++ drivers/remoteproc/ti_k3_common.h | 107 ++++ drivers/remoteproc/ti_k3_dsp_remoteproc.c | 462 +--------------- drivers/remoteproc/ti_k3_m4_remoteproc.c | 491 ++++++++++++++++++ 7 files changed, 1174 insertions(+), 435 deletions(-) create mode 100644 Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml create mode 100644 drivers/remoteproc/ti_k3_common.c create mode 100644 drivers/remoteproc/ti_k3_common.h create mode 100644 drivers/remoteproc/ti_k3_m4_remoteproc.c
Signature · 1 line
2.39.1
PATCH v3 1/3 dt-bindings: remoteproc: k3-m4f: Add bindings for K3 AM64x SoCs
From: Hari Nagalla <[email protected]>
K3 AM64x SoC has a Cortex M4F subsystem in the MCU voltage domain. The remote processor's life cycle management and IPC mechanisms are similar across the R5F and M4F cores from remote processor driver point of view. However, there are subtle differences in image loading and starting the M4F subsystems.
The YAML binding document provides the various node properties to be configured by the consumers of the M4F subsystem.
---
Changes since v1:
- Spelling corrections
- Corrected to pass DT checks
Changes since v2:
- Missed spelling correction to commit message
Note: The only review comment that I don't see directly addressed is the
lack of description of ti,sci, ti,sci-dev-id and ti,sci-proc-ids. A reference has been added to /schemas/arm/keystone/ti,k3-sci-common.yaml# where they are described. I believe this is the correct approach, please advise if that is not the case.
.../bindings/remoteproc/ti,k3-m4f-rproc.yaml | 158 ++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +158 -0
@@ -0,0 +1,158 @@ +# SPDX-License-Identifier: (GPL-2.0-only or BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/remoteproc/ti,k3-m4f-rproc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: TI K3 M4F processor subsystems + +maintainers: + - Hari Nagalla <[email protected]> + +description: | + Some K3 family SoCs have Arm Cortex M4F cores. AM64x is a SoC in K3 + family with a M4F core. Typically safety oriented applications may use + the M4F core in isolation without an IPC. Where as some industrial and + home automation applications, may use the M4F core as a remote processor + with IPC communications. + +$ref: /schemas/arm/keystone/ti,k3-sci-common.yaml# + +properties: + $nodename: + pattern: "^m4fss(@.*)?" + + compatible: + enum: + - ti,am64-m4fss + + power-domains: + description: | + Should contain a phandle to a PM domain provider node and an args + specifier containing the M4FSS device id value. + maxItems: 1 + + "#address-cells": + const: 2 + + "#size-cells": + const: 2 + + reg: + items: + - description: Address and Size of the IRAM internal memory region + - description: Address and Size of the DRAM internal memory region + + reg-names: + items: + - const: iram + - const: dram + + resets: + description: | + Should contain the phandle to the reset controller node managing the + local resets for this device, and a reset specifier. + maxItems: 1 + + firmware-name: + description: | + Should contain the name of the default firmware image + file located on the firmware search path + + mboxes: + description: | + OMAP Mailbox specifier denoting the sub-mailbox, to be used for + communication with the remote processor. This property should match + with the sub-mailbox node used in the firmware image. + maxItems: 1 + + memory-region: + description: | + phandle to the reserved memory nodes to be associated with the + remoteproc device. There should be at least two reserved memory nodes + defined. The reserved memory nodes should be carveout nodes, and + should be defined with a "no-map" property as per the bindings in + Documentation/devicetree/bindings/reserved-memory/reserved-memory.yaml + minItems: 2 + maxItems: 8 + items: + - description: region used for dynamic DMA allocations like vrings and + vring buffers + - description: region reserved for firmware image sections + additionalItems: true + +required: + - compatible + - reg + - reg-names + - ti,sci + - ti,sci-dev-id + - ti,sci-proc-ids + - resets + - firmware-name + - mboxes + - memory-region + +unevaluatedProperties: false + +examples: + - | + reserved-memory { + #address-cells = <2>; + #size-cells = <2>; + + mcu_m4fss_dma_memory_region: m4f-dma-memory@9cb00000 { + compatible = "shared-dma-pool"; + reg = <0x00 0x9cb00000 0x00 0x100000>; + no-map; + }; + + mcu_m4fss_memory_region: m4f-memory@9cc00000 { + compatible = "shared-dma-pool"; + reg = <0x00 0x9cc00000 0x00 0xe00000>; + no-map; + }; + }; + + soc { + #address-cells = <2>; + #size-cells = <2>; + + mailbox0_cluster0: mailbox-0 { + #mbox-cells = <1>; + + mbox_m4_0: mbox-m4-0 { + ti,mbox-rx = <0 0 0>; + ti,mbox-tx = <1 0 0>; + }; + }; + + bus@f0000 { + compatible = "simple-bus"; + #address-cells = <2>; + #size-cells = <2>; + ranges = <0x00 0x04000000 0x00 0x04000000 0x00 0x01ff1400>; + + bus@4000000 { + compatible = "simple-bus"; + #address-cells = <2>; + #size-cells = <2>; + ranges = <0x00 0x04000000 0x00 0x04000000 0x00 0x01ff1400>; + + mcu_m4fss: m4fss@5000000 { + compatible = "ti,am64-m4fss"; + reg = <0x00 0x5000000 0x00 0x30000>, + <0x00 0x5040000 0x00 0x10000>; + reg-names = "iram", "dram"; + ti,sci = <&dmsc>; + ti,sci-dev-id = <9>; + ti,sci-proc-ids = <0x18 0xff>; + resets = <&k3_reset 9 1>; + firmware-name = "am62-mcu-m4f0_0-fw"; + mboxes = <&mailbox0_cluster0 &mbox_m4_0>; + memory-region = <&mcu_m4fss_dma_memory_region>, + <&mcu_m4fss_memory_region>; + }; + }; + }; + };
Signature · 1 line
2.39.1
Re: [PATCH v3 1/3] dt-bindings: remoteproc: k3-m4f: Add bindings for K3 AM64x SoCs
Quoted 1 line · Martyn Welch
From: Hari Nagalla <[email protected]>
Subject: drop second/last, redundant "bindings for". The "dt-bindings" prefix is already stating that these are bindings.
Quoted 52 lines
K3 AM64x SoC has a Cortex M4F subsystem in the MCU voltage domain. The remote processor's life cycle management and IPC mechanisms are similar across the R5F and M4F cores from remote processor driver point of view. However, there are subtle differences in image loading and starting the M4F subsystems.
The YAML binding document provides the various node properties to be configured by the consumers of the M4F subsystem.
Signed-off-by Hari Nagalla <[email protected]>[Martyn Welch: Amended as per review comments and to pass DT tests]Signed-off-by Martyn Welch <[email protected]>---
Changes since v1:
- Spelling corrections
- Corrected to pass DT checksChanges since v2:
- Missed spelling correction to commit messageNote: The only review comment that I don't see directly addressed is the
lack of description ofti,sci,ti,sci-dev-idandti,sci-proc-ids. A reference has been added to/schemas/arm/keystone/ti,k3-sci-common.yaml#where they are described. I believe this is the correct approach, please advise if that is not the case..../bindings/remoteproc/ti,k3-m4f-rproc.yaml | 158 ++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yamlDocumentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +13
-0@@ -0,0 +1,158 @@ +# SPDX-License-Identifier: (GPL-2.0-only or BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/remoteproc/ti,k3-m4f-rproc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: TI K3 M4F processor subsystems + +maintainers: + - Hari Nagalla <[email protected]> + +description: | + Some K3 family SoCs have Arm Cortex M4F cores. AM64x is a SoC in K3
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml line 23
Quoted 10 lines
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +10
-0+ family with a M4F core. Typically safety oriented applications may use + the M4F core in isolation without an IPC. Where as some industrial and + home automation applications, may use the M4F core as a remote processor + with IPC communications. + +$ref: /schemas/arm/keystone/ti,k3-sci-common.yaml# + +properties: + $nodename: + pattern: "^m4fss(@.*)?"
Drop. It's not a generic name. Also we do not enforce names in device schemas.
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml line 32
Quoted 9 lines
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +9
-0+ + compatible: + enum: + - ti,am64-m4fss + + power-domains: + description: | + Should contain a phandle to a PM domain provider node and an args + specifier containing the M4FSS device id value.
Drop description, especially that the args depend on provider, not consumer.
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml line 43
Quoted 11 lines
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +11
-0+ maxItems: 1 + + "#address-cells": + const: 2 + + "#size-cells": + const: 2 + + reg: + items: + - description: Address and Size of the IRAM internal memory region
Just "IRAM internal memory region"
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml line 54
Quoted 11 lines
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +11
-0+ - description: Address and Size of the DRAM internal memory region + + reg-names: + items: + - const: iram + - const: dram + + resets: + description: | + Should contain the phandle to the reset controller node managing the + local resets for this device, and a reset specifier.
Drop description.
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml line 60
Quoted 6 lines
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +6
-0+ maxItems: 1 + + firmware-name: + description: | + Should contain the name of the default firmware image + file located on the firmware search path
This description is basically duplicating the name... say something useful or shorten it (e.g. "Should contain" is really redundant). You also need $ref because we do not have the type defined anywhere.
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml line 64
Quoted 4 lines
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +4
-0+ + mboxes: + description: | + OMAP Mailbox specifier denoting the sub-mailbox, to be used for
OMAP?
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml
Quoted 9 lines
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +9
-0+ communication with the remote processor. This property should match + with the sub-mailbox node used in the firmware image. + maxItems: 1 + + memory-region: + description: | + phandle to the reserved memory nodes to be associated with the + remoteproc device. There should be at least two reserved memory nodes + defined.
Don't repeat constraints in free form text.
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml line 82
Quoted 10 lines
The reserved memory nodes should be carveout nodes, and
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +9
-0+ should be defined with a "no-map" property as per the bindings in + Documentation/devicetree/bindings/reserved-memory/reserved-memory.yaml + minItems: 2 + maxItems: 8 + items: + - description: region used for dynamic DMA allocations like vrings and + vring buffers + - description: region reserved for firmware image sections + additionalItems: true
And what is the purpose of the rest of reserved nodes?
Quoted 36 lines
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +36
-0+ +required: + - compatible + - reg + - reg-names + - ti,sci + - ti,sci-dev-id + - ti,sci-proc-ids + - resets + - firmware-name + - mboxes + - memory-region + +unevaluatedProperties: false + +examples: + - | + reserved-memory { + #address-cells = <2>; + #size-cells = <2>; + + mcu_m4fss_dma_memory_region: m4f-dma-memory@9cb00000 { + compatible = "shared-dma-pool"; + reg = <0x00 0x9cb00000 0x00 0x100000>; + no-map; + }; + + mcu_m4fss_memory_region: m4f-memory@9cc00000 { + compatible = "shared-dma-pool"; + reg = <0x00 0x9cc00000 0x00 0xe00000>; + no-map; + }; + }; + + soc { + #address-cells = <2>;
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml line 128
Quoted 10 lines
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +10
-0+ #size-cells = <2>; + + mailbox0_cluster0: mailbox-0 { + #mbox-cells = <1>; + + mbox_m4_0: mbox-m4-0 { + ti,mbox-rx = <0 0 0>; + ti,mbox-tx = <1 0 0>; + }; + };
Does not look related to this binding... or is it somehow very specific and needs showing?
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml line 134
Quoted 6 lines
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +6
-0+ + bus@f0000 { + compatible = "simple-bus"; + #address-cells = <2>; + #size-cells = <2>; + ranges = <0x00 0x04000000 0x00 0x04000000 0x00 0x01ff1400>;
Why another bus? You already have soc in example, why more nodes?
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml
Quoted 2 lines
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +2
-0+ + bus@4000000 {
And one more bus?
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml line 142
Quoted 6 lines
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +6
-0+ compatible = "simple-bus"; + #address-cells = <2>; + #size-cells = <2>; + ranges = <0x00 0x04000000 0x00 0x04000000 0x00 0x01ff1400>; + + mcu_m4fss: m4fss@5000000 {
Generic node name. Qualcomm uses remoteproc.
Quoted 6 lines
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +6
-0+ compatible = "ti,am64-m4fss"; + reg = <0x00 0x5000000 0x00 0x30000>, + <0x00 0x5040000 0x00 0x10000>; + reg-names = "iram", "dram"; + ti,sci = <&dmsc>; + ti,sci-dev-id = <9>;
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml line 158
Quoted 10 lines
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +10
-0+ ti,sci-proc-ids = <0x18 0xff>; + resets = <&k3_reset 9 1>; + firmware-name = "am62-mcu-m4f0_0-fw"; + mboxes = <&mailbox0_cluster0 &mbox_m4_0>; + memory-region = <&mcu_m4fss_dma_memory_region>, + <&mcu_m4fss_memory_region>; + }; + }; + }; + };
Best regards,
Krzysztof
Re: [PATCH v3 1/3] dt-bindings: remoteproc: k3-m4f: Add bindings for K3 AM64x SoCs
Quoted 10 lines · Krzysztof Kozlowski
Quoted 5 lines · Martyn Welch
+
+ mboxes:
+ description: |
+ OMAP Mailbox specifier denoting the sub-mailbox, to be used forOMAP?
This device uses a mailbox compatible with the OMAP Mailbox, as defined in Documentation/devicetree/bindings/mailbox/ti,omap-mailbox.yaml.
I note that documents title reads "TI OMAP2+ and K3 Mailbox devices". I'll drop the "OMAP" here.
Quoted 29 lines
Quoted 4 lines
+ communication with the remote processor. This property should match
+ with the sub-mailbox node used in the firmware image. + maxItems: 1Quoted 8 lines
+
+ memory-region:
+ description: |
+ phandle to the reserved memory nodes to be associated with the
+ remoteproc device. There should be at least two reserved memory nodes
+ defined.Don't repeat constraints in free form text.
Quoted 5 lines
The reserved memory nodes should be carveout nodes, and + should be defined with a "no-map" property as per the bindings in
+Documentation/devicetree/bindings/reserved-memory/reserved-memory.yamlQuoted 8 lines
+ minItems: 2
+ maxItems: 8
+ items:
+ - description: region used for dynamic DMA allocations like vrings and
+ vring buffers
+ - description: region reserved for firmware image sections + additionalItems: true
Quoted 2 lines
And what is the purpose of the rest of reserved nodes?
Up to 8 regions can be specified with their purpose determined by the firmware running on the M4F core. The suggestion (and the implementation in the example firmware) is to use the first 2 regions as defined above for remoteproc with the others available to be used for other purposes if necessary. The address translation module used can cope with up to 8 regions.
Quoted 1 line
Martyn
Re: [PATCH v3 1/3] dt-bindings: remoteproc: k3-m4f: Add bindings for K3 AM64x SoCs
Quoted 50 lines · Martyn Welch
Quoted 10 lines · Krzysztof Kozlowski
Quoted 5 lines · Martyn Welch
+
+ mboxes:
+ description: |
+ OMAP Mailbox specifier denoting the sub-mailbox, to be used forOMAP?
This device uses a mailbox compatible with the OMAP Mailbox, as defined in
Documentation/devicetree/bindings/mailbox/ti,omap-mailbox.yaml.I note that documents title reads "TI OMAP2+ and K3 Mailbox devices". I'll drop the "OMAP" here.
Quoted 29 lines
Quoted 4 lines
+ communication with the remote processor. This property should match
+ with the sub-mailbox node used in the firmware image. + maxItems: 1Quoted 8 lines
+
+ memory-region:
+ description: |
+ phandle to the reserved memory nodes to be associated with the
+ remoteproc device. There should be at least two reserved memory nodes
+ defined.Don't repeat constraints in free form text.
Quoted 5 lines
The reserved memory nodes should be carveout nodes, and + should be defined with a "no-map" property as per the bindings in
+Documentation/devicetree/bindings/reserved-memory/reserved-memory.yamlQuoted 8 lines
+ minItems: 2
+ maxItems: 8
+ items:
+ - description: region used for dynamic DMA allocations like vrings and
+ vring buffers
+ - description: region reserved for firmware image sections + additionalItems: trueQuoted 2 lines
And what is the purpose of the rest of reserved nodes?
Quoted 6 lines
Up to 8 regions can be specified with their purpose determined by the firmware running on the M4F core. The suggestion (and the implementation in the example firmware) is to use the first 2 regions as defined above for remoteproc with the others available to be used for other purposes if necessary. The address translation module used can cope with up to 8 regions.
Then mention the rest is just dedicated to the firmware and it's purpose depends on the firmware.
Best regards,
Krzysztof
Mathieu Poirier
maintainerRe: [PATCH v3 1/3] dt-bindings: remoteproc: k3-m4f: Add bindings for K3 AM64x SoCs
In reply to Martyn WelchHi Martyn,
Due to the size of this patch my comments will likely span a few days. I will clearly let you know when I am done reviewing your submission.
Quoted 8 lines · Martyn Welch
From: Hari Nagalla <[email protected]>
K3 AM64x SoC has a Cortex M4F subsystem in the MCU voltage domain. The remote processor's life cycle management and IPC mechanisms are similar across the R5F and M4F cores from remote processor driver point of view. However, there are subtle differences in image loading and starting the M4F subsystems.
Quoted 5 lines
The YAML binding document provides the various node properties to be configured by the consumers of the M4F subsystem.
Signed-off-by Hari Nagalla <[email protected]>[Martyn Welch: Amended as per review comments and to pass DT tests]
This isn't needed. Since you are taking over this patchset it is expected you will make modifications.
Quoted 28 lines
Signed-off-by Martyn Welch <[email protected]>---
Changes since v1:
- Spelling corrections
- Corrected to pass DT checksChanges since v2:
- Missed spelling correction to commit messageNote: The only review comment that I don't see directly addressed is the
lack of description ofti,sci,ti,sci-dev-idandti,sci-proc-ids. A reference has been added to/schemas/arm/keystone/ti,k3-sci-common.yaml#where they are described. I believe this is the correct approach, please advise if that is not the case..../bindings/remoteproc/ti,k3-m4f-rproc.yaml | 158 ++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yamlDocumentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +1
-0@@ -0,0 +1,158 @@ +# SPDX-License-Identifier: (GPL-2.0-only or BSD-2-Clause)
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml line 11
Quoted 10 lines
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +10
-0+%YAML 1.2 +--- +$id: http://devicetree.org/schemas/remoteproc/ti,k3-m4f-rproc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: TI K3 M4F processor subsystems + +maintainers: + - Hari Nagalla <[email protected]> +
Hari did not finish upstreaming this set. As such I doubt he intents to maintain it and I suppose it is the same for you since you didn't add your name either. You can add my name there.
Quoted 72 lines
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +72
-0+description: | + Some K3 family SoCs have Arm Cortex M4F cores. AM64x is a SoC in K3 + family with a M4F core. Typically safety oriented applications may use + the M4F core in isolation without an IPC. Where as some industrial and + home automation applications, may use the M4F core as a remote processor + with IPC communications. + +$ref: /schemas/arm/keystone/ti,k3-sci-common.yaml# + +properties: + $nodename: + pattern: "^m4fss(@.*)?" + + compatible: + enum: + - ti,am64-m4fss + + power-domains: + description: | + Should contain a phandle to a PM domain provider node and an args + specifier containing the M4FSS device id value. + maxItems: 1 + + "#address-cells": + const: 2 + + "#size-cells": + const: 2 + + reg: + items: + - description: Address and Size of the IRAM internal memory region + - description: Address and Size of the DRAM internal memory region + + reg-names: + items: + - const: iram + - const: dram + + resets: + description: | + Should contain the phandle to the reset controller node managing the + local resets for this device, and a reset specifier. + maxItems: 1 + + firmware-name: + description: | + Should contain the name of the default firmware image + file located on the firmware search path + + mboxes: + description: | + OMAP Mailbox specifier denoting the sub-mailbox, to be used for + communication with the remote processor. This property should match + with the sub-mailbox node used in the firmware image. + maxItems: 1 + + memory-region: + description: | + phandle to the reserved memory nodes to be associated with the + remoteproc device. There should be at least two reserved memory nodes + defined. The reserved memory nodes should be carveout nodes, and + should be defined with a "no-map" property as per the bindings in + Documentation/devicetree/bindings/reserved-memory/reserved-memory.yaml + minItems: 2 + maxItems: 8 + items: + - description: region used for dynamic DMA allocations like vrings and + vring buffers + - description: region reserved for firmware image sections + additionalItems: true +
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml line 93
Quoted 10 lines
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +10
-0+required: + - compatible + - reg + - reg-names + - ti,sci + - ti,sci-dev-id + - ti,sci-proc-ids + - resets + - firmware-name + - mboxes
The 'mboxes' property is marked as required but the description section above clearly state the M4F can operate without IPC.
Quoted 49 lines
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +49
-0+ - memory-region + +unevaluatedProperties: false + +examples: + - | + reserved-memory { + #address-cells = <2>; + #size-cells = <2>; + + mcu_m4fss_dma_memory_region: m4f-dma-memory@9cb00000 { + compatible = "shared-dma-pool"; + reg = <0x00 0x9cb00000 0x00 0x100000>; + no-map; + }; + + mcu_m4fss_memory_region: m4f-memory@9cc00000 { + compatible = "shared-dma-pool"; + reg = <0x00 0x9cc00000 0x00 0xe00000>; + no-map; + }; + }; + + soc { + #address-cells = <2>; + #size-cells = <2>; + + mailbox0_cluster0: mailbox-0 { + #mbox-cells = <1>; + + mbox_m4_0: mbox-m4-0 { + ti,mbox-rx = <0 0 0>; + ti,mbox-tx = <1 0 0>; + }; + }; + + bus@f0000 { + compatible = "simple-bus"; + #address-cells = <2>; + #size-cells = <2>; + ranges = <0x00 0x04000000 0x00 0x04000000 0x00 0x01ff1400>; + + bus@4000000 { + compatible = "simple-bus"; + #address-cells = <2>; + #size-cells = <2>; + ranges = <0x00 0x04000000 0x00 0x04000000 0x00 0x01ff1400>; + + mcu_m4fss: m4fss@5000000 {
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml line 152
Quoted 10 lines
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +10
-0+ compatible = "ti,am64-m4fss"; + reg = <0x00 0x5000000 0x00 0x30000>, + <0x00 0x5040000 0x00 0x10000>; + reg-names = "iram", "dram"; + ti,sci = <&dmsc>; + ti,sci-dev-id = <9>; + ti,sci-proc-ids = <0x18 0xff>; + resets = <&k3_reset 9 1>; + firmware-name = "am62-mcu-m4f0_0-fw"; + mboxes = <&mailbox0_cluster0 &mbox_m4_0>;
This doesn't look right since mbox_m4_0 is defined within mailbox0_cluster0.
Quoted 9 lines
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +6
-0+ memory-region = <&mcu_m4fss_dma_memory_region>, + <&mcu_m4fss_memory_region>; + }; + }; + }; + };Signature · 1 line
2.39.1
Re: [PATCH v3 1/3] dt-bindings: remoteproc: k3-m4f: Add bindings for K3 AM64x SoCs
Quoted 10 lines · Mathieu Poirier
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml line 93
Quoted 10 lines
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +10
-0+required: + - compatible + - reg + - reg-names + - ti,sci + - ti,sci-dev-id + - ti,sci-proc-ids + - resets + - firmware-name + - mboxes
Quoted 3 lines
The 'mboxes' property is marked as required but the description section above clearly state the M4F can operate without IPC.
Well, when the M4F is used as a safety processor it is typically booted from SBL/u-boot and may isolate the MCU domain from main domain/A53 to function in higher safety level. In these scenarios there is no remote proc handling of M4F life cycle management (LCM) and IPC. But, on the other hand, when the M4F is used as a non safety processor its LCM is handled by remote proc(main domain) and mailboxes for IPC are required.
Mathieu Poirier
maintainerRe: [PATCH v3 1/3] dt-bindings: remoteproc: k3-m4f: Add bindings for K3 AM64x SoCs
Quoted 14 lines · Hari Nagalla
Quoted 10 lines · Mathieu Poirier
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml line 93
Quoted 10 lines
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +10
-0+required: + - compatible + - reg + - reg-names + - ti,sci + - ti,sci-dev-id + - ti,sci-proc-ids + - resets + - firmware-name + - mboxesQuoted 3 lines
The 'mboxes' property is marked as required but the description section above clearly state the M4F can operate without IPC.
Quoted 6 lines
Well, when the M4F is used as a safety processor it is typically booted from SBL/u-boot and may isolate the MCU domain from main domain/A53 to function in higher safety level. In these scenarios there is no remote proc handling of M4F life cycle management (LCM) and IPC. But, on the other hand, when the M4F is used as a non safety processor its LCM is handled by remote proc(main domain) and mailboxes for IPC are required.
Well, what you wrote above is pretty much explained verbatim in the "description" section of the bindings. Mailboxes are optional and as such should not be found under the "required" section.
Re: [PATCH v3 1/3] dt-bindings: remoteproc: k3-m4f: Add bindings for K3 AM64x SoCs
Quoted 28 lines · Mathieu Poirier
Quoted 15 lines · Hari Nagalla
Quoted 10 lines · Mathieu Poirier
Quoted 10 lines
+required:
+ - compatible
+ - reg
+ - reg-names
+ - ti,sci
+ - ti,sci-dev-id
+ - ti,sci-proc-ids
+ - resets
+ - firmware-name
+ - mboxesQuoted 4 lines
The 'mboxes' property is marked as required but the description section above
clearly state the M4F can operate without IPC.Quoted 11 lines
Well, when the M4F is used as a safety processor it is typically booted from
SBL/u-boot and may isolate the MCU domain from main domain/A53 to function
in higher safety level. In these scenarios there is no remote proc handling
of M4F life cycle management (LCM) and IPC. But, on the other hand, when the
M4F is used as a non safety processor its LCM is handled by remote proc(main
domain) and mailboxes for IPC are required.
Quoted 5 lines
Well, what you wrote above is pretty much explained verbatim in the "description" section of the bindings. Mailboxes are optional and as such
should not be found under the "required" section.
Which means the memory regions are also optional as in the isolated case they're be no communications with the main domain.
Martyn
Re: [PATCH v3 1/3] dt-bindings: remoteproc: k3-m4f: Add bindings for K3 AM64x SoCs
In reply to Mathieu PoirierQuoted 54 lines · Mathieu Poirier
Quoted 52 lines · Martyn Welch
Documentation/devicetree/bindings/remoteproc/ti,k3-m4f-rproc.yaml new file +37
-0+examples: + - | + reserved-memory { + #address-cells = <2>; + #size-cells = <2>; + + mcu_m4fss_dma_memory_region: m4f-dma-memory@9cb00000 { + compatible = "shared-dma-pool"; + reg = <0x00 0x9cb00000 0x00 0x100000>; + no-map; + }; + + mcu_m4fss_memory_region: m4f-memory@9cc00000 { + compatible = "shared-dma-pool"; + reg = <0x00 0x9cc00000 0x00 0xe00000>; + no-map; + }; + }; + + soc { + #address-cells = <2>; + #size-cells = <2>; + + mailbox0_cluster0: mailbox-0 { + #mbox-cells = <1>; + + mbox_m4_0: mbox-m4-0 { + ti,mbox-rx = <0 0 0>; + ti,mbox-tx = <1 0 0>; + }; + }; + + bus@f0000 { + compatible = "simple-bus"; + #address-cells = <2>; + #size-cells = <2>; + ranges = <0x00 0x04000000 0x00 0x04000000 0x00
0x01ff1400>;
+
+ bus@4000000 {
+ compatible = "simple-bus";
+ #address-cells = <2>;
+ #size-cells = <2>;
+ ranges = <0x000x040000000x000x040000000x000x01ff1400>;
+
+mcu_m4fss: m4fss@5000000 {
+ compatible = "ti,am64-m4fss";
+ reg = <0x000x50000000x000x30000>, + <0x000x50400000x000x10000>; + reg-names = "iram", "dram";
+ ti,sci = <&dmsc>;
Quoted 9 lines
Quoted 5 lines
+ ti,sci-dev-id = <9>;
+ ti,sci-proc-ids = <0x180xff>; + resets = <&k3_reset9 1>;
+ firmware-name = "am62-mcu-m4f0_0-fw"; + mboxes = <&mailbox0_cluster0&mbox_m4_0>;This doesn't look right since
mbox_m4_0is defined withinmailbox0_cluster0.
Looking at other users of the omap mailboxes (and not wanting to spend ages trawling back through the mailing list archives to try and work out why it's specified the way it is) it seems that this is the way that these mailboxes are specified.
For instance in arch/arm/boot/dts/omap4-l4.dtsi, the mailbox is defined:
mailbox: mailbox@0 {
compatible = "ti,omap4-mailbox";
reg = <0x0 0x200>;
interrupts = <GIC_SPI 26 IRQ_TYPE_LEVEL_HIGH>;
#mbox-cells = <1>;
ti,mbox-num-users = <3>;
ti,mbox-num-fifos = <8>;
mbox_ipu: mbox-ipu {
ti,mbox-tx = <0 0 0>;
ti,mbox-rx = <1 0 0>;
};
mbox_dsp: mbox-dsp {
ti,mbox-tx = <3 0 0>;
ti,mbox-rx = <2 0 0>;
};
};It's users in arch/arm/boot/dts/omap4.dtsi:
dsp: dsp {
...
mboxes = <&mailbox &mbox_dsp>;
...
};
ipu: ipu@55020000 {
...
mboxes = <&mailbox &mbox_ipu>;
...
};Quoted 10 lines
Quoted 10 lines
+ memory-region = <
&mcu_m4fss_dma_memory_region>,
+ <&mcu_m4fss_memory_region>; + };
+ };
+ };
+ };Signature · 1 line
2.39.1
PATCH v3 2/3 remoteproc: k4: Split out functions common with M4 driver
In reply to Martyn WelchIn the next commit we will be adding the M4F driver which shares a lot of commonality with the DSP driver. Split this shared functionality out so that it can be used by both drivers.
---
Changes since v2:
- New patch (reordered refactoring from v2)
drivers/remoteproc/Makefile | 2 +- drivers/remoteproc/ti_k3_common.c | 375 ++++++++++++++++++ drivers/remoteproc/ti_k3_common.h | 102 +++++ drivers/remoteproc/ti_k3_dsp_remoteproc.c | 462 ++-------------------- 4 files changed, 506 insertions(+), 435 deletions(-) create mode 100644 drivers/remoteproc/ti_k3_common.c create mode 100644 drivers/remoteproc/ti_k3_common.h
drivers/remoteproc/Makefile +1 -1
@@ -36,6 +36,6 @@ obj-$(CONFIG_RCAR_REMOTEPROC) += rcar_rproc.o obj-$(CONFIG_ST_REMOTEPROC) += st_remoteproc.o obj-$(CONFIG_ST_SLIM_REMOTEPROC) += st_slim_rproc.o obj-$(CONFIG_STM32_RPROC) += stm32_rproc.o -obj-$(CONFIG_TI_K3_DSP_REMOTEPROC) += ti_k3_dsp_remoteproc.o +obj-$(CONFIG_TI_K3_DSP_REMOTEPROC) += ti_k3_dsp_remoteproc.o ti_k3_common.o obj-$(CONFIG_TI_K3_R5_REMOTEPROC) += ti_k3_r5_remoteproc.o obj-$(CONFIG_XLNX_R5_REMOTEPROC) += xlnx_r5_remoteproc.o
drivers/remoteproc/ti_k3_common.c new file +375 -0
375 lines not on this page · raw message
drivers/remoteproc/ti_k3_common.h new file +102 -0
102 lines not on this page · raw message
drivers/remoteproc/ti_k3_dsp_remoteproc.c +28 -434
615 lines not on this page · raw message
Signature · 1 line
2.39.1
Mathieu Poirier
maintainerRe: [PATCH v3 2/3] remoteproc: k4: Split out functions common with M4 driver
Quoted 10 lines · Martyn Welch
In the next commit we will be adding the M4F driver which shares a lot of commonality with the DSP driver. Split this shared functionality out so that it can be used by both drivers.
Signed-off-by Martyn Welch <[email protected]>---
Changes since v2:
- New patch (reordered refactoring from v2)
Quoted 8 lines
drivers/remoteproc/Makefile | 2 +- drivers/remoteproc/ti_k3_common.c | 375 ++++++++++++++++++ drivers/remoteproc/ti_k3_common.h | 102 +++++ drivers/remoteproc/ti_k3_dsp_remoteproc.c | 462 ++-------------------- 4 files changed, 506 insertions(+), 435 deletions(-) create mode 100644 drivers/remoteproc/ti_k3_common.c create mode 100644 drivers/remoteproc/ti_k3_common.h
This patch gives me GPL checkpatch warning and doesn't apply to rproc-next.
Quoted 55 lines
drivers/remoteproc/Makefile +1
-1@@ -36,6 +36,6 @@ obj-$(CONFIG_RCAR_REMOTEPROC) += rcar_rproc.o obj-$(CONFIG_ST_REMOTEPROC) += st_remoteproc.o obj-$(CONFIG_ST_SLIM_REMOTEPROC) += st_slim_rproc.o obj-$(CONFIG_STM32_RPROC) += stm32_rproc.o -obj-$(CONFIG_TI_K3_DSP_REMOTEPROC) += ti_k3_dsp_remoteproc.o +obj-$(CONFIG_TI_K3_DSP_REMOTEPROC) += ti_k3_dsp_remoteproc.o ti_k3_common.o obj-$(CONFIG_TI_K3_R5_REMOTEPROC) += ti_k3_r5_remoteproc.o obj-$(CONFIG_XLNX_R5_REMOTEPROC) += xlnx_r5_remoteproc.odrivers/remoteproc/ti_k3_common.c new file +37
-0@@ -0,0 +1,375 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* TI K3 Remote Processor(s) driver common code +* +* Refactored from ti_k3_dsp_remoteproc.c. +* +* ti_k3_dsp_remoteproc.c: +* Copyright (C) 2018-2022 Texas Instruments Incorporated - https://www.ti.com/ +* Suman Anna <[email protected]> +*/ + +#include <linux/io.h> +#include <linux/mailbox_client.h> +#include <linux/module.h> +#include <linux/of_device.h> +#include <linux/of_reserved_mem.h> +#include <linux/omap-mailbox.h> +#include <linux/platform_device.h> +#include <linux/remoteproc.h> +#include <linux/reset.h> +#include <linux/slab.h> + +#include "omap_remoteproc.h" +#include "remoteproc_internal.h" +#include "ti_sci_proc.h" +#include "ti_k3_common.h" + +/* +* Kick the remote processor to notify about pending unprocessed messages. +* The vqid usage is not used and is inconsequential, as the kick is performed +* through a simulated GPIO (a bit in an IPC interrupt-triggering register), +* the remote processor is expected to process both its Tx and Rx virtqueues. +*/ +void k3_rproc_kick (struct rproc *rproc,int vqid) +{ +struct k3_rproc *kproc = rproc->priv; +struct device *dev = rproc->dev.parent;
drivers/remoteproc/ti_k3_common.c line 47
Quoted 10 lines
drivers/remoteproc/ti_k3_common.c new file +10
-0+mbox_msg_t msg = (mbox_msg_t )vqid; +int ret; + +/* send the index of the triggered virtqueue in the mailbox payload */ + ret =mbox_send_message (kproc->mbox, (void *)msg); +if (ret <0 ) +dev_err (dev,"failed to send mailbox message, status = %d\n" , + ret); +} +EXPORT_SYMBOL_GPL (k3_rproc_kick);
As far as I can tell there is no need to export this symbol, nor any of the other ones in this new file. Otherwise this patch is doing the right thing and does it the right way.
More comment to follow tomorrow or later this week.
Thanks,
Mathieu
Quoted 1,077 lines
drivers/remoteproc/ti_k3_common.c new file +328
-0+ +/* Put the remote processor into reset */ +int k3_rproc_reset (struct k3_rproc *kproc) +{ +struct device *dev = kproc->dev; +int ret; + + ret =reset_control_assert (kproc->reset); +if (ret) { +dev_err (dev,"local-reset assert failed, ret = %d\n" , ret); +return ret; + } + +if (kproc->data->uses_lreset) +return ret; + + ret = kproc->ti_sci->ops.dev_ops.put_device (kproc->ti_sci, + kproc->ti_sci_id); +if (ret) { +dev_err (dev,"module-reset assert failed, ret = %d\n" , ret); +if (reset_control_deassert (kproc->reset)) +dev_warn (dev,"local-reset deassert back failed\n" ); + } + +return ret; +} +EXPORT_SYMBOL_GPL (k3_rproc_reset); + +/* Release the remote processor from reset */ +int k3_rproc_release (struct k3_rproc *kproc) +{ +struct device *dev = kproc->dev; +int ret; + +if (kproc->data->uses_lreset) + goto lreset; + + ret = kproc->ti_sci->ops.dev_ops.get_device (kproc->ti_sci, + kproc->ti_sci_id); +if (ret) { +dev_err (dev,"module-reset deassert failed, ret = %d\n" , ret); +return ret; + } + +lreset: + ret =reset_control_deassert (kproc->reset); +if (ret) { +dev_err (dev,"local-reset deassert failed, ret = %d\n" , ret); +if (kproc->ti_sci->ops.dev_ops.put_device (kproc->ti_sci, + kproc->ti_sci_id)) +dev_warn (dev,"module-reset assert back failed\n" ); + } + +return ret; +} +EXPORT_SYMBOL_GPL (k3_rproc_release); + +/* +* This function implements the .get_loaded_rsc_table() callback and is used +* to provide the resource table for a booted remote processor in IPC-only +* mode. The remote processor firmwares follow a design-by-contract approach +* and are expected to have the resource table at the base of the DDR region +* reserved for firmware usage. This provides flexibility for the remote +* processor to be booted by different bootloaders that may or may not have the +* ability to publish the resource table address and size through a DT +* property. +*/ +struct resource_table *k3_get_loaded_rsc_table (struct rproc *rproc, +size_t *rsc_table_sz) +{ +struct k3_rproc *kproc = rproc->priv; +struct device *dev = kproc->dev; + +if (!kproc->rmem[0 ].cpu_addr) { +dev_err (dev,"memory-region #1 does not exist, loaded rsc table can't be found" ); +return ERR_PTR (-ENOMEM ); + } + +/* +* NOTE: The resource table size is currently hard-coded to a maximum +* of 256 bytes. The most common resource table usage for K3 firmwares +* is to only have the vdev resource entry and an optional trace entry. +* The exact size could be computed based on resource table address, but +* the hard-coded value suffices to support the IPC-only mode. +*/ + *rsc_table_sz =256 ; +return (struct resource_table *)kproc->rmem[0 ].cpu_addr; +} +EXPORT_SYMBOL_GPL (k3_get_loaded_rsc_table); + +/* +* Custom function to translate a remote processor device address (internal +* RAMs only) to a kernel virtual address. The remote processors can access +* their RAMs at either an internal address visible only from a remote +* processor, or at the SoC-level bus address. Both these addresses need to be +* looked through for translation. The translated addresses can be used either +* by the remoteproc core for loading (when using kernel remoteproc loader), or +* by any rpmsg bus drivers. +*/ +void *k3_rproc_da_to_va (struct rproc *rproc,u64 da,size_t len,bool *is_iomem) +{ +struct k3_rproc *kproc = rproc->priv; +void __iomem *va =NULL ; +phys_addr_t bus_addr; +u32 dev_addr, offset; +size_t size; +int i; + +if (len ==0 ) +return NULL ; + +for (i =0 ; i < kproc->num_mems; i++) { + bus_addr = kproc->mem[i].bus_addr; + dev_addr = kproc->mem[i].dev_addr; + size = kproc->mem[i].size; + +if (da <KEYSTONE_RPROC_LOCAL_ADDRESS_MASK ) { +/* handle remote-view addresses */ +if (da >= dev_addr && + ((da + len) <= (dev_addr + size))) { + offset = da - dev_addr; + va = kproc->mem[i].cpu_addr + offset; +return (__force void *)va; + } + }else { +/* handle SoC-view addresses */ +if (da >= bus_addr && + (da + len) <= (bus_addr + size)) { + offset = da - bus_addr; + va = kproc->mem[i].cpu_addr + offset; +return (__force void *)va; + } + } + } + +/* handle static DDR reserved memory regions */ +for (i =0 ; i < kproc->num_rmems; i++) { + dev_addr = kproc->rmem[i].dev_addr; + size = kproc->rmem[i].size; + +if (da >= dev_addr && ((da + len) <= (dev_addr + size))) { + offset = da - dev_addr; + va = kproc->rmem[i].cpu_addr + offset; +return (__force void *)va; + } + } + +return NULL ; +} +EXPORT_SYMBOL_GPL (k3_rproc_da_to_va); + +int k3_rproc_of_get_memories (struct platform_device *pdev, +struct k3_rproc *kproc) +{ +const struct k3_rproc_dev_data *data = kproc->data; +struct device *dev = &pdev->dev; +struct resource *res; +int num_mems =0 ; +int i; + + num_mems = kproc->data->num_mems; + kproc->mem =devm_kcalloc (kproc->dev, num_mems, +sizeof (*kproc->mem),GFP_KERNEL ); +if (!kproc->mem) +return -ENOMEM ; + +for (i =0 ; i < num_mems; i++) { + res =platform_get_resource_byname (pdev,IORESOURCE_MEM , + data->mems[i].name); +if (!res) { +dev_err (dev,"found no memory resource for %s\n" , + data->mems[i].name); +return -EINVAL ; + } +if (!devm_request_mem_region (dev, res->start, +resource_size (res), +dev_name (dev))) { +dev_err (dev,"could not request %s region for resource\n" , + data->mems[i].name); +return -EBUSY ; + } + + kproc->mem[i].cpu_addr =devm_ioremap_wc (dev, res->start, +resource_size (res)); +if (!kproc->mem[i].cpu_addr) { +dev_err (dev,"failed to map %s memory\n" , + data->mems[i].name); +return -ENOMEM ; + } + kproc->mem[i].bus_addr = res->start; + kproc->mem[i].dev_addr = data->mems[i].dev_addr; + kproc->mem[i].size =resource_size (res); + +dev_dbg (dev,"memory %8s: bus addr %pa size 0x%zx va %pK da 0x%x\n" , + data->mems[i].name, &kproc->mem[i].bus_addr, + kproc->mem[i].size, kproc->mem[i].cpu_addr, + kproc->mem[i].dev_addr); + } + kproc->num_mems = num_mems; + +return 0 ; +} +EXPORT_SYMBOL_GPL (k3_rproc_of_get_memories); + +int k3_reserved_mem_init (struct k3_rproc *kproc) +{ +struct device *dev = kproc->dev; +struct device_node *np = dev->of_node; +struct device_node *rmem_np; +struct reserved_mem *rmem; +int num_rmems; +int ret, i; + + num_rmems =of_property_count_elems_of_size (np,"memory-region" , +sizeof (phandle)); +if (num_rmems <=0 ) { +dev_err (dev,"device does not reserved memory regions, ret = %d\n" , + num_rmems); +return -EINVAL ; + } +if (num_rmems <2 ) { +dev_err (dev,"device needs at least two memory regions to be defined, num = %d\n" , + num_rmems); +return -EINVAL ; + } + +/* use reserved memory region 0 for vring DMA allocations */ + ret =of_reserved_mem_device_init_by_idx (dev, np,0 ); +if (ret) { +dev_err (dev,"device cannot initialize DMA pool, ret = %d\n" , + ret); +return ret; + } + + num_rmems--; + kproc->rmem =kcalloc (num_rmems,sizeof (*kproc->rmem),GFP_KERNEL ); +if (!kproc->rmem) { + ret = -ENOMEM ; + goto release_rmem; + } + +/* use remaining reserved memory regions for static carveouts */ +for (i =0 ; i < num_rmems; i++) { + rmem_np =of_parse_phandle (np,"memory-region" , i +1 ); +if (!rmem_np) { + ret = -EINVAL ; + goto unmap_rmem; + } + + rmem =of_reserved_mem_lookup (rmem_np); +if (!rmem) { +of_node_put (rmem_np); + ret = -EINVAL ; + goto unmap_rmem; + } +of_node_put (rmem_np); + + kproc->rmem[i].bus_addr = rmem->base; +/* 64-bit address regions currently not supported */ + kproc->rmem[i].dev_addr = (u32 )rmem->base; + kproc->rmem[i].size = rmem->size; + kproc->rmem[i].cpu_addr =ioremap_wc (rmem->base, rmem->size); +if (!kproc->rmem[i].cpu_addr) { +dev_err (dev,"failed to map reserved memory#%d at %pa of size %pa\n" , + i +1 , &rmem->base, &rmem->size); + ret = -ENOMEM ; + goto unmap_rmem; + } + +dev_dbg (dev,"reserved memory%d: bus addr %pa size 0x%zx va %pK da 0x%x\n" , + i +1 , &kproc->rmem[i].bus_addr, + kproc->rmem[i].size, kproc->rmem[i].cpu_addr, + kproc->rmem[i].dev_addr); + } + kproc->num_rmems = num_rmems; + +return 0 ; + +unmap_rmem: +for (i--; i >=0 ; i--) +iounmap (kproc->rmem[i].cpu_addr); +kfree (kproc->rmem); +release_rmem: +of_reserved_mem_device_release (kproc->dev); +return ret; +} +EXPORT_SYMBOL_GPL (k3_reserved_mem_init); + +void k3_reserved_mem_exit (struct k3_rproc *kproc) +{ +int i; + +for (i =0 ; i < kproc->num_rmems; i++) +iounmap (kproc->rmem[i].cpu_addr); +kfree (kproc->rmem); + +of_reserved_mem_device_release (kproc->dev); +} +EXPORT_SYMBOL_GPL (k3_reserved_mem_exit); + +struct ti_sci_proc *k3_rproc_of_get_tsp (struct device *dev, +const struct ti_sci_handle *sci) +{ +struct ti_sci_proc *tsp; +u32 temp[2 ]; +int ret; + + ret =of_property_read_u32_array (dev->of_node,"ti,sci-proc-ids" , + temp,2 ); +if (ret <0 ) +return ERR_PTR (ret); + + tsp =kzalloc (sizeof (*tsp),GFP_KERNEL ); +if (!tsp) +return ERR_PTR (-ENOMEM ); + + tsp->dev = dev; + tsp->sci = sci; + tsp->ops = &sci->ops.proc_ops; + tsp->proc_id = temp[0 ]; + tsp->host_id = temp[1 ]; + +return tsp; +} +EXPORT_SYMBOL_GPL (k3_rproc_of_get_tsp); + +MODULE_LICENSE ("GPL v2" ); +MODULE_DESCRIPTION ("TI K3 common Remoteproc support" );drivers/remoteproc/ti_k3_common.h new file +102
-0@@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* TI K3 Remote Processor(s) driver common code +* +* Refactored from ti_k3_dsp_remoteproc.c. +* +* ti_k3_dsp_remoteproc.c: +* Copyright (C) 2018-2022 Texas Instruments Incorporated - https://www.ti.com/ +* Suman Anna <[email protected]> +*/ + +#ifndef REMOTEPROC_TI_K3_COMMON_H +#define REMOTEPROC_TI_K3_COMMON_H + +#define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1) + +/** +* struct k3_rproc_mem - internal memory structure +* @cpu_addr: MPU virtual address of the memory region +* @bus_addr: Bus address used to access the memory region +* @dev_addr: Device address of the memory region from DSP view +* @size: Size of the memory region +*/ +struct k3_rproc_mem { +void __iomem *cpu_addr; +phys_addr_t bus_addr; +u32 dev_addr; +size_t size; +}; + +/** +* struct k3_rproc_mem_data - memory definitions for a DSP +* @name: name for this memory entry +* @dev_addr: device address for the memory entry +*/ +struct k3_rproc_mem_data { +const char *name; +const u32 dev_addr; +}; + +/** +* struct k3_rproc_dev_data - device data structure for a DSP +* @mems: pointer to memory definitions for a DSP +* @num_mems: number of memory regions in @mems +* @boot_align_addr: boot vector address alignment granularity +* @uses_lreset: flag to denote the need for local reset management +*/ +struct k3_rproc_dev_data { +const struct k3_rproc_mem_data *mems; +u32 num_mems; +u32 boot_align_addr; +bool uses_lreset; +}; + +/** +* struct k3_rproc - k3 remote processor driver structure +* @dev: cached device pointer +* @rproc: remoteproc device handle +* @mem: internal memory regions data +* @num_mems: number of internal memory regions +* @rmem: reserved memory regions data +* @num_rmems: number of reserved memory regions +* @reset: reset control handle +* @data: pointer to device data +* @tsp: TI-SCI processor control handle +* @ti_sci: TI-SCI handle +* @ti_sci_id: TI-SCI device identifier +* @mbox: mailbox channel handle +* @client: mailbox client to request the mailbox channel +* @ipc_only: flag to indicate IPC-only mode +*/ +struct k3_rproc { +struct device *dev; +struct rproc *rproc; +struct k3_rproc_mem *mem; +int num_mems; +struct k3_rproc_mem *rmem; +int num_rmems; +struct reset_control *reset; +const struct k3_rproc_dev_data *data; +struct ti_sci_proc *tsp; +const struct ti_sci_handle *ti_sci; +u32 ti_sci_id; +struct mbox_chan *mbox; +struct mbox_client client; +}; + +void k3_rproc_kick (struct rproc *rproc,int vqid); +int k3_rproc_reset (struct k3_rproc *kproc); +int k3_rproc_release (struct k3_rproc *kproc); +struct resource_table *k3_get_loaded_rsc_table (struct rproc *rproc, +size_t *rsc_table_sz); +void *k3_rproc_da_to_va (struct rproc *rproc,u64 da,size_t len, +bool *is_iomem); +int k3_rproc_of_get_memories (struct platform_device *pdev, +struct k3_rproc *kproc); +int k3_reserved_mem_init (struct k3_rproc *kproc); +void k3_reserved_mem_exit (struct k3_rproc *kproc); +struct ti_sci_proc *k3_rproc_of_get_tsp (struct device *dev, +const struct ti_sci_handle *sci); + +#endif /* REMOTEPROC_TI_K3_COMMON_H */ drivers/remoteproc/ti_k3_dsp_remoteproc.c +28
-434@@ -20,78 +20,7 @@#include "omap_remoteproc.h" #include "remoteproc_internal.h" #include "ti_sci_proc.h" - -#define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1) - -/** -* struct k3_dsp_mem - internal memory structure -* @cpu_addr: MPU virtual address of the memory region -* @bus_addr: Bus address used to access the memory region -* @dev_addr: Device address of the memory region from DSP view -* @size: Size of the memory region -*/ -struct k3_dsp_mem { -void __iomem *cpu_addr; -phys_addr_t bus_addr; -u32 dev_addr; -size_t size; -}; - -/** -* struct k3_dsp_mem_data - memory definitions for a DSP -* @name: name for this memory entry -* @dev_addr: device address for the memory entry -*/ -struct k3_dsp_mem_data { -const char *name; -const u32 dev_addr; -}; - -/** -* struct k3_dsp_dev_data - device data structure for a DSP -* @mems: pointer to memory definitions for a DSP -* @num_mems: number of memory regions in @mems -* @boot_align_addr: boot vector address alignment granularity -* @uses_lreset: flag to denote the need for local reset management -*/ -struct k3_dsp_dev_data { -const struct k3_dsp_mem_data *mems; -u32 num_mems; -u32 boot_align_addr; -bool uses_lreset; -}; - -/** -* struct k3_dsp_rproc - k3 DSP remote processor driver structure -* @dev: cached device pointer -* @rproc: remoteproc device handle -* @mem: internal memory regions data -* @num_mems: number of internal memory regions -* @rmem: reserved memory regions data -* @num_rmems: number of reserved memory regions -* @reset: reset control handle -* @data: pointer to DSP-specific device data -* @tsp: TI-SCI processor control handle -* @ti_sci: TI-SCI handle -* @ti_sci_id: TI-SCI device identifier -* @mbox: mailbox channel handle -* @client: mailbox client to request the mailbox channel -*/ -struct k3_dsp_rproc { -struct device *dev; -struct rproc *rproc; -struct k3_dsp_mem *mem; -int num_mems; -struct k3_dsp_mem *rmem; -int num_rmems; -struct reset_control *reset; -const struct k3_dsp_dev_data *data; -struct ti_sci_proc *tsp; -const struct ti_sci_handle *ti_sci; -u32 ti_sci_id; -struct mbox_chan *mbox; -struct mbox_client client; -}; +#include "ti_k3_common.h" /** * k3_dsp_rproc_mbox_callback() - inbound mailbox message handler @@ -109,7 +38,7 @@ struct k3_dsp_rproc {*/ static void k3_dsp_rproc_mbox_callback (struct mbox_client *client,void *data) { - struct k3_dsp_rproc *kproc = container_of(client, struct k3_dsp_rproc, + struct k3_rproc *kproc = container_of(client, struct k3_rproc, client);struct device *dev = kproc->rproc->dev.parent;const char *name = kproc->rproc->name;@@ -142,83 +71,9 @@ static void k3_dsp_rproc_mbox_callback(struct mbox_client *client, void *data) } } -/* -* Kick the remote processor to notify about pending unprocessed messages. -* The vqid usage is not used and is inconsequential, as the kick is performed -* through a simulated GPIO (a bit in an IPC interrupt-triggering register), -* the remote processor is expected to process both its Tx and Rx virtqueues. -*/ -static void k3_dsp_rproc_kick (struct rproc *rproc,int vqid) -{ -struct k3_dsp_rproc *kproc = rproc->priv; -struct device *dev = rproc->dev.parent; -mbox_msg_t msg = (mbox_msg_t )vqid; -int ret; - -/* send the index of the triggered virtqueue in the mailbox payload */ - ret =mbox_send_message (kproc->mbox, (void *)msg); -if (ret <0 ) -dev_err (dev,"failed to send mailbox message, status = %d\n" , - ret); -} - -/* Put the DSP processor into reset */ -static int k3_dsp_rproc_reset (struct k3_dsp_rproc *kproc) -{ -struct device *dev = kproc->dev; -int ret; - - ret =reset_control_assert (kproc->reset); -if (ret) { -dev_err (dev,"local-reset assert failed, ret = %d\n" , ret); -return ret; - } - -if (kproc->data->uses_lreset) -return ret; - - ret = kproc->ti_sci->ops.dev_ops.put_device (kproc->ti_sci, - kproc->ti_sci_id); -if (ret) { -dev_err (dev,"module-reset assert failed, ret = %d\n" , ret); -if (reset_control_deassert (kproc->reset)) -dev_warn (dev,"local-reset deassert back failed\n" ); - } - -return ret; -} - -/* Release the DSP processor from reset */ -static int k3_dsp_rproc_release (struct k3_dsp_rproc *kproc) -{ -struct device *dev = kproc->dev; -int ret; - -if (kproc->data->uses_lreset) - goto lreset; - - ret = kproc->ti_sci->ops.dev_ops.get_device (kproc->ti_sci, - kproc->ti_sci_id); -if (ret) { -dev_err (dev,"module-reset deassert failed, ret = %d\n" , ret); -return ret; - } - -lreset: - ret =reset_control_deassert (kproc->reset); -if (ret) { -dev_err (dev,"local-reset deassert failed, ret = %d\n" , ret); -if (kproc->ti_sci->ops.dev_ops.put_device (kproc->ti_sci, - kproc->ti_sci_id)) -dev_warn (dev,"module-reset assert back failed\n" ); - } - -return ret; -} -static int k3_dsp_rproc_request_mbox (struct rproc *rproc) { -struct k3_dsp_rproc *kproc = rproc->priv; +struct k3_rproc *kproc = rproc->priv;struct mbox_client *client = &kproc->client;struct device *dev = kproc->dev;int ret;@@ -253,6 +108,7 @@ static int k3_dsp_rproc_request_mbox(struct rproc *rproc)return 0 ; } +/* * The C66x DSP cores have a local reset that affects only the CPU, and a * generic module reset that powers on the device and allows the DSP internal @@ -265,7 +121,7 @@ static int k3_dsp_rproc_request_mbox(struct rproc *rproc)*/ static int k3_dsp_rproc_prepare (struct rproc *rproc) { -struct k3_dsp_rproc *kproc = rproc->priv; +struct k3_rproc *kproc = rproc->priv;struct device *dev = kproc->dev;int ret;@@ -289,7 +145,7 @@ static int k3_dsp_rproc_prepare(struct rproc *rproc)*/ static int k3_dsp_rproc_unprepare (struct rproc *rproc) { -struct k3_dsp_rproc *kproc = rproc->priv; +struct k3_rproc *kproc = rproc->priv;struct device *dev = kproc->dev;int ret;@@ -310,7 +166,7 @@ static int k3_dsp_rproc_unprepare(struct rproc *rproc)*/ static int k3_dsp_rproc_start (struct rproc *rproc) { -struct k3_dsp_rproc *kproc = rproc->priv; +struct k3_rproc *kproc = rproc->priv;struct device *dev = kproc->dev;u32 boot_addr;int ret;@@ -332,7 +188,7 @@ static int k3_dsp_rproc_start(struct rproc *rproc)if (ret) goto put_mbox; - ret =k3_dsp_rproc_release (kproc); + ret =k3_rproc_release (kproc);if (ret) goto put_mbox;@@ -351,11 +207,11 @@ static int k3_dsp_rproc_start(struct rproc *rproc)*/ static int k3_dsp_rproc_stop (struct rproc *rproc) { -struct k3_dsp_rproc *kproc = rproc->priv; +struct k3_rproc *kproc = rproc->priv;mbox_free_channel (kproc->mbox); -k3_dsp_rproc_reset (kproc); +k3_rproc_reset (kproc);return 0 ; }@@ -370,7 +226,7 @@ static int k3_dsp_rproc_stop(struct rproc *rproc)*/ static int k3_dsp_rproc_attach (struct rproc *rproc) { -struct k3_dsp_rproc *kproc = rproc->priv; +struct k3_rproc *kproc = rproc->priv;struct device *dev = kproc->dev;int ret;@@ -392,7 +248,7 @@ static int k3_dsp_rproc_attach(struct rproc *rproc)*/ static int k3_dsp_rproc_detach (struct rproc *rproc) { -struct k3_dsp_rproc *kproc = rproc->priv; +struct k3_rproc *kproc = rproc->priv;struct device *dev = kproc->dev;mbox_free_channel (kproc->mbox);@@ -400,282 +256,20 @@ static int k3_dsp_rproc_detach(struct rproc *rproc)return 0 ; } -/* -* This function implements the .get_loaded_rsc_table() callback and is used -* to provide the resource table for a booted DSP in IPC-only mode. The K3 DSP -* firmwares follow a design-by-contract approach and are expected to have the -* resource table at the base of the DDR region reserved for firmware usage. -* This provides flexibility for the remote processor to be booted by different -* bootloaders that may or may not have the ability to publish the resource table -* address and size through a DT property. This callback is invoked only in -* IPC-only mode. -*/ -static struct resource_table *k3_dsp_get_loaded_rsc_table (struct rproc *rproc, -size_t *rsc_table_sz) -{ -struct k3_dsp_rproc *kproc = rproc->priv; -struct device *dev = kproc->dev; - -if (!kproc->rmem[0 ].cpu_addr) { -dev_err (dev,"memory-region #1 does not exist, loaded rsc table can't be found" ); -return ERR_PTR (-ENOMEM ); - } - -/* -* NOTE: The resource table size is currently hard-coded to a maximum -* of 256 bytes. The most common resource table usage for K3 firmwares -* is to only have the vdev resource entry and an optional trace entry. -* The exact size could be computed based on resource table address, but -* the hard-coded value suffices to support the IPC-only mode. -*/ - *rsc_table_sz =256 ; -return (struct resource_table *)kproc->rmem[0 ].cpu_addr; -} - -/* -* Custom function to translate a DSP device address (internal RAMs only) to a -* kernel virtual address. The DSPs can access their RAMs at either an internal -* address visible only from a DSP, or at the SoC-level bus address. Both these -* addresses need to be looked through for translation. The translated addresses -* can be used either by the remoteproc core for loading (when using kernel -* remoteproc loader), or by any rpmsg bus drivers. -*/ -static void *k3_dsp_rproc_da_to_va (struct rproc *rproc,u64 da,size_t len,bool *is_iomem) -{ -struct k3_dsp_rproc *kproc = rproc->priv; -void __iomem *va =NULL ; -phys_addr_t bus_addr; -u32 dev_addr, offset; -size_t size; -int i; - -if (len ==0 ) -return NULL ; - -for (i =0 ; i < kproc->num_mems; i++) { - bus_addr = kproc->mem[i].bus_addr; - dev_addr = kproc->mem[i].dev_addr; - size = kproc->mem[i].size; - -if (da <KEYSTONE_RPROC_LOCAL_ADDRESS_MASK ) { -/* handle DSP-view addresses */ -if (da >= dev_addr && - ((da + len) <= (dev_addr + size))) { - offset = da - dev_addr; - va = kproc->mem[i].cpu_addr + offset; -return (__force void *)va; - } - }else { -/* handle SoC-view addresses */ -if (da >= bus_addr && - (da + len) <= (bus_addr + size)) { - offset = da - bus_addr; - va = kproc->mem[i].cpu_addr + offset; -return (__force void *)va; - } - } - } - -/* handle static DDR reserved memory regions */ -for (i =0 ; i < kproc->num_rmems; i++) { - dev_addr = kproc->rmem[i].dev_addr; - size = kproc->rmem[i].size; - -if (da >= dev_addr && ((da + len) <= (dev_addr + size))) { - offset = da - dev_addr; - va = kproc->rmem[i].cpu_addr + offset; -return (__force void *)va; - } - } - -return NULL ; -}static const struct rproc_ops k3_dsp_rproc_ops = { .start = k3_dsp_rproc_start, .stop = k3_dsp_rproc_stop, - .kick = k3_dsp_rproc_kick, - .da_to_va = k3_dsp_rproc_da_to_va, + .kick = k3_rproc_kick, + .da_to_va = k3_rproc_da_to_va, }; -static int k3_dsp_rproc_of_get_memories (struct platform_device *pdev, -struct k3_dsp_rproc *kproc) -{ -const struct k3_dsp_dev_data *data = kproc->data; -struct device *dev = &pdev->dev; -struct resource *res; -int num_mems =0 ; -int i; - - num_mems = kproc->data->num_mems; - kproc->mem =devm_kcalloc (kproc->dev, num_mems, -sizeof (*kproc->mem),GFP_KERNEL ); -if (!kproc->mem) -return -ENOMEM ; - -for (i =0 ; i < num_mems; i++) { - res =platform_get_resource_byname (pdev,IORESOURCE_MEM , - data->mems[i].name); -if (!res) { -dev_err (dev,"found no memory resource for %s\n" , - data->mems[i].name); -return -EINVAL ; - } -if (!devm_request_mem_region (dev, res->start, -resource_size (res), -dev_name (dev))) { -dev_err (dev,"could not request %s region for resource\n" , - data->mems[i].name); -return -EBUSY ; - } - - kproc->mem[i].cpu_addr =devm_ioremap_wc (dev, res->start, -resource_size (res)); -if (!kproc->mem[i].cpu_addr) { -dev_err (dev,"failed to map %s memory\n" , - data->mems[i].name); -return -ENOMEM ; - } - kproc->mem[i].bus_addr = res->start; - kproc->mem[i].dev_addr = data->mems[i].dev_addr; - kproc->mem[i].size =resource_size (res); - -dev_dbg (dev,"memory %8s: bus addr %pa size 0x%zx va %pK da 0x%x\n" , - data->mems[i].name, &kproc->mem[i].bus_addr, - kproc->mem[i].size, kproc->mem[i].cpu_addr, - kproc->mem[i].dev_addr); - } - kproc->num_mems = num_mems; - -return 0 ; -} - -static int k3_dsp_reserved_mem_init (struct k3_dsp_rproc *kproc) -{ -struct device *dev = kproc->dev; -struct device_node *np = dev->of_node; -struct device_node *rmem_np; -struct reserved_mem *rmem; -int num_rmems; -int ret, i; - - num_rmems =of_property_count_elems_of_size (np,"memory-region" , -sizeof (phandle)); -if (num_rmems <=0 ) { -dev_err (dev,"device does not reserved memory regions, ret = %d\n" , - num_rmems); -return -EINVAL ; - } -if (num_rmems <2 ) { -dev_err (dev,"device needs at least two memory regions to be defined, num = %d\n" , - num_rmems); -return -EINVAL ; - } - -/* use reserved memory region 0 for vring DMA allocations */ - ret =of_reserved_mem_device_init_by_idx (dev, np,0 ); -if (ret) { -dev_err (dev,"device cannot initialize DMA pool, ret = %d\n" , - ret); -return ret; - } - - num_rmems--; - kproc->rmem =kcalloc (num_rmems,sizeof (*kproc->rmem),GFP_KERNEL ); -if (!kproc->rmem) { - ret = -ENOMEM ; - goto release_rmem; - } - -/* use remaining reserved memory regions for static carveouts */ -for (i =0 ; i < num_rmems; i++) { - rmem_np =of_parse_phandle (np,"memory-region" , i +1 ); -if (!rmem_np) { - ret = -EINVAL ; - goto unmap_rmem; - } - - rmem =of_reserved_mem_lookup (rmem_np); -if (!rmem) { -of_node_put (rmem_np); - ret = -EINVAL ; - goto unmap_rmem; - } -of_node_put (rmem_np); - - kproc->rmem[i].bus_addr = rmem->base; -/* 64-bit address regions currently not supported */ - kproc->rmem[i].dev_addr = (u32 )rmem->base; - kproc->rmem[i].size = rmem->size; - kproc->rmem[i].cpu_addr =ioremap_wc (rmem->base, rmem->size); -if (!kproc->rmem[i].cpu_addr) { -dev_err (dev,"failed to map reserved memory#%d at %pa of size %pa\n" , - i +1 , &rmem->base, &rmem->size); - ret = -ENOMEM ; - goto unmap_rmem; - } - -dev_dbg (dev,"reserved memory%d: bus addr %pa size 0x%zx va %pK da 0x%x\n" , - i +1 , &kproc->rmem[i].bus_addr, - kproc->rmem[i].size, kproc->rmem[i].cpu_addr, - kproc->rmem[i].dev_addr); - } - kproc->num_rmems = num_rmems; - -return 0 ; - -unmap_rmem: -for (i--; i >=0 ; i--) -iounmap (kproc->rmem[i].cpu_addr); -kfree (kproc->rmem); -release_rmem: -of_reserved_mem_device_release (kproc->dev); -return ret; -} - -static void k3_dsp_reserved_mem_exit (struct k3_dsp_rproc *kproc) -{ -int i; - -for (i =0 ; i < kproc->num_rmems; i++) -iounmap (kproc->rmem[i].cpu_addr); -kfree (kproc->rmem); - -of_reserved_mem_device_release (kproc->dev); -} - -static -struct ti_sci_proc *k3_dsp_rproc_of_get_tsp (struct device *dev, -const struct ti_sci_handle *sci) -{ -struct ti_sci_proc *tsp; -u32 temp[2 ]; -int ret; - - ret =of_property_read_u32_array (dev->of_node,"ti,sci-proc-ids" , - temp,2 ); -if (ret <0 ) -return ERR_PTR (ret); - - tsp =kzalloc (sizeof (*tsp),GFP_KERNEL ); -if (!tsp) -return ERR_PTR (-ENOMEM ); - - tsp->dev = dev; - tsp->sci = sci; - tsp->ops = &sci->ops.proc_ops; - tsp->proc_id = temp[0 ]; - tsp->host_id = temp[1 ]; - -return tsp; -} -static int k3_dsp_rproc_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;struct device_node *np = dev->of_node; -const struct k3_dsp_dev_data *data; -struct k3_dsp_rproc *kproc; +const struct k3_rproc_dev_data *data; +struct k3_rproc *kproc;struct rproc *rproc;const char *fw_name;bool p_state = false;@@ -733,7 +327,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) goto put_sci; } - kproc->tsp =k3_dsp_rproc_of_get_tsp (dev, kproc->ti_sci); + kproc->tsp =k3_rproc_of_get_tsp (dev, kproc->ti_sci);if (IS_ERR (kproc->tsp)) {dev_err (dev,"failed to construct ti-sci proc control, ret = %d\n" , ret);@@ -747,11 +341,11 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) goto free_tsp; } - ret =k3_dsp_rproc_of_get_memories (pdev, kproc); + ret =k3_rproc_of_get_memories (pdev, kproc);if (ret) goto release_tsp; - ret =k3_dsp_reserved_mem_init (kproc); + ret =k3_reserved_mem_init (kproc);if (ret) {dev_err (dev,"reserved memory init failed, ret = %d\n" , ret); goto release_tsp;@@ -776,7 +370,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) rproc->ops->stop =NULL ; rproc->ops->attach = k3_dsp_rproc_attach; rproc->ops->detach = k3_dsp_rproc_detach; - rproc->ops->get_loaded_rsc_table = k3_dsp_get_loaded_rsc_table; + rproc->ops->get_loaded_rsc_table = k3_get_loaded_rsc_table; }else {dev_info (dev,"configured DSP for remoteproc mode\n" );/* @@ -792,7 +386,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) goto release_mem; }else if (ret ==0 ) {dev_warn (dev,"local reset is deasserted for device\n" ); -k3_dsp_rproc_reset (kproc); +k3_rproc_reset (kproc); } } }@@ -809,7 +403,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)return 0 ; release_mem: -k3_dsp_reserved_mem_exit (kproc); +k3_reserved_mem_exit (kproc); release_tsp: ret1 =ti_sci_proc_release (kproc->tsp);if (ret1)@@ -827,7 +421,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)static int k3_dsp_rproc_remove (struct platform_device *pdev) { -struct k3_dsp_rproc *kproc =platform_get_drvdata (pdev); +struct k3_rproc *kproc =platform_get_drvdata (pdev);struct rproc *rproc = kproc->rproc;struct device *dev = &pdev->dev;int ret;@@ -852,32 +446,32 @@ static int k3_dsp_rproc_remove(struct platform_device *pdev)if (ret)dev_err (dev,"failed to put ti_sci handle, ret = %d\n" , ret); -k3_dsp_reserved_mem_exit (kproc); +k3_reserved_mem_exit (kproc);rproc_free (kproc->rproc);return 0 ; } -static const struct k3_dsp_mem_data c66_mems[] = { +static const struct k3_rproc_mem_data c66_mems[] = { { .name ="l2sram" , .dev_addr =0x800000 }, { .name ="l1pram" , .dev_addr =0xe00000 }, { .name ="l1dram" , .dev_addr =0xf00000 }, };/* C71x cores only have a L1P Cache, there are no L1P SRAMs */ -static const struct k3_dsp_mem_data c71_mems[] = { +static const struct k3_rproc_mem_data c71_mems[] = { { .name ="l2sram" , .dev_addr =0x800000 }, { .name ="l1dram" , .dev_addr =0xe00000 }, }; -static const struct k3_dsp_dev_data c66_data = { +static const struct k3_rproc_dev_data c66_data = { .mems = c66_mems, .num_mems =ARRAY_SIZE (c66_mems), .boot_align_addr =SZ_1K , .uses_lreset = true, }; -static const struct k3_dsp_dev_data c71_data = { +static const struct k3_rproc_dev_data c71_data = { .mems = c71_mems, .num_mems =ARRAY_SIZE (c71_mems), .boot_align_addr =SZ_2M ,Signature · 1 line
2.39.1
Re: [PATCH v3 2/3] remoteproc: k4: Split out functions common with M4 driver
In reply to Martyn WelchQuoted 11 lines · Martyn Welch
+ * @ti_sci_id: TI-SCI device identifier
+ * @mbox: mailbox channel handle
+ * @client: mailbox client to request the mailbox channel
+ * @ipc_only: flag to indicate IPC-only mode
+ */drivers/remoteproc/ti_k3_common.h new file +6
-0+struct k3_rproc { +struct device *dev; +struct rproc *rproc; +struct k3_rproc_mem *mem; +int num_mems; +struct k3_rproc_mem *rmem;
drivers/remoteproc/ti_k3_common.h line 87
Quoted 10 lines
drivers/remoteproc/ti_k3_common.h new file +10
-0+int num_rmems; +struct reset_control *reset; +const struct k3_rproc_dev_data *data; +struct ti_sci_proc *tsp; +const struct ti_sci_handle *ti_sci; +u32 ti_sci_id; +struct mbox_chan *mbox; +struct mbox_client client; +}; +
"ipc_only" mode element is missing in the structure.
Re: [PATCH v3 2/3] remoteproc: k4: Split out functions common with M4 driver
Quoted 15 lines · Hari Nagalla
Quoted 14 lines · Martyn Welch
+ * @ti_sci_id: TI-SCI device identifier
+ * @mbox: mailbox channel handle
+ * @client: mailbox client to request the mailbox channel
+ * @ipc_only: flag to indicate IPC-only mode
+ */
+structk3_rproc{
+ struct device *dev;
+ struct rproc *rproc;
+ structk3_rproc_mem*mem;
+ intnum_mems;
+ structk3_rproc_mem*rmem;
+ intnum_rmems;
+ structreset_control*reset;
+ const structk3_rproc_dev_data*data;
Quoted 8 lines
Review
Quoted 7 lines
+ struct
ti_sci_proc*tsp;
+ const structti_sci_handle*ti_sci;
+ u32ti_sci_id;
+ structmbox_chan*mbox;
+ structmbox_clientclient;(quoted diff) +2
-0+}; +"
ipc_only" mode element is missing in the structure.
That's added with the M4F driver in the next patch - it's not part of the structure in the DSP driver.
Re: [PATCH v3 2/3] remoteproc: k4: Split out functions common with M4 driver
Il 10/03/23 10:46, Martyn Welch ha scritto:
Quoted 25 lines · Hari Nagalla
Quoted 15 lines · Martyn Welch
Quoted 14 lines
+ * @ti_sci_id: TI-SCI device identifier
+ * @mbox: mailbox channel handle
+ * @client: mailbox client to request the mailbox channel
+ * @ipc_only: flag to indicate IPC-only mode
+ */
+structk3_rproc{
+ struct device *dev;
+ struct rproc *rproc;
+ structk3_rproc_mem*mem;
+ intnum_mems;
+ structk3_rproc_mem*rmem;
+ intnum_rmems;
+ structreset_control*reset;
+ const structk3_rproc_dev_data*data;Quoted 8 lines
Review
Quoted 7 lines
+ struct
ti_sci_proc*tsp;
+ const structti_sci_handle*ti_sci;
+ u32ti_sci_id;
+ structmbox_chan*mbox;
+ structmbox_clientclient;(quoted diff) +2
-0+}; +"
ipc_only" mode element is missing in the structure.
Quoted 2 lines
That's added with the M4F driver in the next patch - it's not part of the structure in the DSP driver.
Martyn, I get that it's added later, but the point here is that you are documenting something that is missing! :-)
You should add the kerneldoc for @ipc_only: xxxx when you actually introduce the new element... otherwise, this commit alone would trigger a kerneldoc warning.
Cheers,
Angelo
Re: [PATCH v3 2/3] remoteproc: k4: Split out functions common with M4 driver
Quoted 30 lines · AngeloGioacchino Del Regno
Il 10/03/23 10:46, Martyn Welch ha scritto:
Quoted 25 lines · Hari Nagalla
Quoted 15 lines · Martyn Welch
Quoted 14 lines
+ * @ti_sci_id: TI-SCI device identifier
+ * @mbox: mailbox channel handle
+ * @client: mailbox client to request the mailbox channel
+ * @ipc_only: flag to indicate IPC-only mode
+ */
+structk3_rproc{
+ struct device *dev;
+ struct rproc *rproc;
+ structk3_rproc_mem*mem;
+ intnum_mems;
+ structk3_rproc_mem*rmem;
+ intnum_rmems;
+ structreset_control*reset;
+ const structk3_rproc_dev_data*data;Quoted 8 lines
Review
Quoted 7 lines
+ struct
ti_sci_proc*tsp;
+ const structti_sci_handle*ti_sci;
+ u32ti_sci_id;
+ structmbox_chan*mbox;
+ structmbox_clientclient;(quoted diff) +2
-0+}; +"
ipc_only" mode element is missing in the structure.Quoted 3 lines
That's added with the M4F driver in the next patch - it's not part of
the structure in the DSP driver.
Quoted 9 lines
Martyn, I get that it's added later, but the point here is that you are
documenting something that is missing! :-)You should add the kerneldoc for @ipc_only: xxxx when you actually introduce
the new element... otherwise, this commit alone would trigger a kerneldoc warning.
Ah! Thanks. I'd missed that I'd left the comment in there. Yep, that needs to be added in the next patch rather than here... :-)
Martyn
Quoted 2 lines
Cheers,
Angelo
PATCH v3 3/3 remoteproc: k4-m4: Add a remoteproc driver for M4F subsystem
In reply to Martyn WelchThe AM62x and AM64x SoCs of the TI K3 family has a Cortex M4F core in the MCU domain. This core is typically used for safety applications in a stand alone mode. However, some application (non safety related) may want to use the M4F core as a generic remote processor with IPC to the host processor. The M4F core has internal IRAM and DRAM memories and are exposed to the system bus for code and data loading.
A remote processor driver is added to support this subsystem, including being able to load and boot the M4F core. Loading includes to M4F internal memories and to any predefined external code/data memory. The carveouts for external contiguous memory is defined in the M4F device node and should match with the external memory declarations in the M4F image binary. The M4F subsystem has two resets. One reset is for the entire subsystem i.e including the internal memories and ther other, a local reset is only for the M4F processing core. When loading the image, the driver first releases the subsystem reset, loads the firmware image and then releases the local reset to let the M4F processing core run.
---
Changes since v1:
- Addressed minor review comments (refactoring completed in separate patch)
Changes since v2:
- Refactoring completed first, thus smaller change
Note: The only review comment that I don't see directly addressed regards
the copyright date. I have no knowledge of whether this driver was written in 2021 or 2022. The R5 and DSP drivers have copyright date ranges from 2017 and 2018 respectively, so it seems plausible the development of this driver was carried out during 2021 (given that it was originally submitted upstream in Jan 2022).
drivers/remoteproc/Kconfig | 13 + drivers/remoteproc/Makefile | 1 + drivers/remoteproc/ti_k3_common.h | 7 +- drivers/remoteproc/ti_k3_m4_remoteproc.c | 491 +++++++++++++++++++++++ 4 files changed, 511 insertions(+), 1 deletion(-) create mode 100644 drivers/remoteproc/ti_k3_m4_remoteproc.c
drivers/remoteproc/Kconfig +13 -0
@@ -339,6 +339,19 @@ config TI_K3_DSP_REMOTEPROC It's safe to say N here if you're not interested in utilizing the DSP slave processors. +config TI_K3_M4_REMOTEPROC + tristate "TI K3 M4 remoteproc support" + depends on ARCH_K3 + select MAILBOX + select OMAP2PLUS_MBOX + help + Say m here to support TI's M4 remote processor subsystems + on various TI K3 family of SoCs through the remote processor + framework. + + It's safe to say N here if you're not interested in utilizing + a remote processor. + config TI_K3_R5_REMOTEPROC tristate "TI K3 R5 remoteproc support" depends on ARCH_K3
drivers/remoteproc/Makefile +1 -0
@@ -37,5 +37,6 @@ obj-$(CONFIG_ST_REMOTEPROC) += st_remoteproc.o obj-$(CONFIG_ST_SLIM_REMOTEPROC) += st_slim_rproc.o obj-$(CONFIG_STM32_RPROC) += stm32_rproc.o obj-$(CONFIG_TI_K3_DSP_REMOTEPROC) += ti_k3_dsp_remoteproc.o ti_k3_common.o +obj-$(CONFIG_TI_K3_M4_REMOTEPROC) += ti_k3_m4_remoteproc.o ti_k3_common.o obj-$(CONFIG_TI_K3_R5_REMOTEPROC) += ti_k3_r5_remoteproc.o obj-$(CONFIG_XLNX_R5_REMOTEPROC) += xlnx_r5_remoteproc.o
drivers/remoteproc/ti_k3_common.h +6 -1
@@ -2,11 +2,15 @@/* * TI K3 Remote Processor(s) driver common code * -* Refactored from ti_k3_dsp_remoteproc.c. +* Refactored from ti_k3_dsp_remoteproc.c and ti_k3_m4_remoteproc.c. * * ti_k3_dsp_remoteproc.c: * Copyright (C) 2018-2022 Texas Instruments Incorporated - https://www.ti.com/ * Suman Anna <[email protected]> +* +* ti_k3_m4_remoteproc.c: +* Copyright (C) 2021 Texas Instruments Incorporated - https://www.ti.com/ +* Hari Nagalla <[email protected]> */ #ifndef REMOTEPROC_TI_K3_COMMON_H
@@ -83,6 +87,7 @@ struct k3_rproc {u32 ti_sci_id;struct mbox_chan *mbox;struct mbox_client client; +bool ipc_only; };void k3_rproc_kick (struct rproc *rproc,int vqid);
drivers/remoteproc/ti_k3_m4_remoteproc.c new file +491 -0
491 lines not on this page · raw message
Signature · 1 line
2.39.1
Mathieu Poirier
maintainerRe: [PATCH v3 3/3] remoteproc: k4-m4: Add a remoteproc driver for M4F subsystem
Quoted 1 line · Martyn Welch
The AM62x and AM64x SoCs of the TI K3 family has a Cortex M4F core in
s/"a Cortex M4F core"/"a Cortex M4F core"
Quoted 9 lines
the MCU domain. This core is typically used for safety applications in a stand alone mode. However, some application (non safety related) may want to use the M4F core as a generic remote processor with IPC to the host processor. The M4F core has internal IRAM and DRAM memories and are exposed to the system bus for code and data loading.
A remote processor driver is added to support this subsystem, including being able to load and boot the M4F core. Loading includes to M4F internal memories and to any predefined external code/data memory. The
Here "and to" doesn't make sense - please refactor.
Quoted 4 lines
carveouts for external contiguous memory is defined in the M4F device node and should match with the external memory declarations in the M4F image binary. The M4F subsystem has two resets. One reset is for the entire subsystem i.e including the internal memories and ther other, a
s/ther/the
Quoted 6 lines
local reset is only for the M4F processing core. When loading the image, the driver first releases the subsystem reset, loads the firmware image and then releases the local reset to let the M4F processing core run.
Signed-off-by Hari Nagalla <[email protected]>[Martyn Welch: Modified to use common code refactored from DSP driver]
Same comment as before
Quoted 10 lines
Signed-off-by Martyn Welch <[email protected]>---
Changes since v1:
- Addressed minor review comments (refactoring completed in separate patch)Changes since v2:
- Refactoring completed first, thus smaller change
Quoted 7 lines
Note: The only review comment that I don't see directly addressed regards
the copyright date. I have no knowledge of whether this driver was written in 2021 or 2022. The R5 and DSP drivers have copyright date ranges from 2017 and 2018 respectively, so it seems plausible the development of this driver was carried out during 2021 (given that it was originally submitted upstream in Jan 2022).
I think what you have below is just fine. Hari can advise if he thinks otherwise.
Quoted 122 lines
drivers/remoteproc/Kconfig | 13 + drivers/remoteproc/Makefile | 1 + drivers/remoteproc/ti_k3_common.h | 7 +- drivers/remoteproc/ti_k3_m4_remoteproc.c | 491 +++++++++++++++++++++++ 4 files changed, 511 insertions(+), 1 deletion(-) create mode 100644 drivers/remoteproc/ti_k3_m4_remoteproc.cdrivers/remoteproc/Kconfig +13
-0@@ -339,6 +339,19 @@ config TI_K3_DSP_REMOTEPROC It's safe to say N here if you're not interested in utilizing the DSP slave processors. +config TI_K3_M4_REMOTEPROC + tristate "TI K3 M4 remoteproc support" + depends on ARCH_K3 + select MAILBOX + select OMAP2PLUS_MBOX + help + Say m here to support TI's M4 remote processor subsystems + on various TI K3 family of SoCs through the remote processor + framework. + + It's safe to say N here if you're not interested in utilizing + a remote processor. + config TI_K3_R5_REMOTEPROC tristate "TI K3 R5 remoteproc support" depends on ARCH_K3drivers/remoteproc/Makefile +1
-0@@ -37,5 +37,6 @@ obj-$(CONFIG_ST_REMOTEPROC) += st_remoteproc.o obj-$(CONFIG_ST_SLIM_REMOTEPROC) += st_slim_rproc.o obj-$(CONFIG_STM32_RPROC) += stm32_rproc.o obj-$(CONFIG_TI_K3_DSP_REMOTEPROC) += ti_k3_dsp_remoteproc.o ti_k3_common.o +obj-$(CONFIG_TI_K3_M4_REMOTEPROC) += ti_k3_m4_remoteproc.o ti_k3_common.o obj-$(CONFIG_TI_K3_R5_REMOTEPROC) += ti_k3_r5_remoteproc.o obj-$(CONFIG_XLNX_R5_REMOTEPROC) += xlnx_r5_remoteproc.odrivers/remoteproc/ti_k3_common.h +6
-1@@ -2,11 +2,15 @@/* * TI K3 Remote Processor(s) driver common code * -* Refactored from ti_k3_dsp_remoteproc.c. +* Refactored from ti_k3_dsp_remoteproc.c and ti_k3_m4_remoteproc.c. * * ti_k3_dsp_remoteproc.c: * Copyright (C) 2018-2022 Texas Instruments Incorporated - https://www.ti.com/ * Suman Anna <[email protected]> +* +* ti_k3_m4_remoteproc.c: +* Copyright (C) 2021 Texas Instruments Incorporated - https://www.ti.com/ +* Hari Nagalla <[email protected]> */ #ifndef REMOTEPROC_TI_K3_COMMON_H @@ -83,6 +87,7 @@ struct k3_rproc {u32 ti_sci_id;struct mbox_chan *mbox;struct mbox_client client; +bool ipc_only; };void k3_rproc_kick (struct rproc *rproc,int vqid);drivers/remoteproc/ti_k3_m4_remoteproc.c new file +45
-0@@ -0,0 +1,491 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* TI K3 Cortex-M4 Remote Processor(s) driver +* +* Copyright (C) 2021 Texas Instruments Incorporated - https://www.ti.com/ +* Hari Nagalla <[email protected]> +*/ + +#include <linux/io.h> +#include <linux/mailbox_client.h> +#include <linux/module.h> +#include <linux/of_device.h> +#include <linux/of_reserved_mem.h> +#include <linux/omap-mailbox.h> +#include <linux/platform_device.h> +#include <linux/remoteproc.h> +#include <linux/reset.h> +#include <linux/slab.h> + +#include "omap_remoteproc.h" +#include "remoteproc_internal.h" +#include "ti_sci_proc.h" +#include "ti_k3_common.h" + +/** +* k3_m4_rproc_mbox_callback() - inbound mailbox message handler +* @client: mailbox client pointer used for requesting the mailbox channel +* @data: mailbox payload +* +* This handler is invoked by the OMAP mailbox driver whenever a mailbox +* message is received. Usually, the mailbox payload simply contains +* the index of the virtqueue that is kicked by the remote processor, +* and we let remoteproc core handle it. +* +* In addition to virtqueue indices, we also have some out-of-band values +* that indicate different events. Those values are deliberately very +* large so they don't coincide with virtqueue indices. +*/ +static void k3_m4_rproc_mbox_callback (struct mbox_client *client,void *data) +{ + struct k3_rproc *kproc = container_of(client, struct k3_rproc, + client); +struct device *dev = kproc->rproc->dev.parent; +const char *name = kproc->rproc->name; +u32 msg =omap_mbox_message (data);
drivers/remoteproc/ti_k3_m4_remoteproc.c line 55
Quoted 10 lines
drivers/remoteproc/ti_k3_m4_remoteproc.c new file +10
-0+ +dev_dbg (dev,"mbox msg: 0x%x\n" , msg); + +switch (msg) { +case RP_MBOX_CRASH : +/* +* remoteproc detected an exception, but error recovery is not +* supported. So, just log this for now +*/ +dev_err (dev,"K3 M4 rproc %s crashed\n" , name);
We have rproc->name here and that should be sufficient for users to know which remote processor has crashed without having to specify the "M4" part. The same applies to the "DSP" in k3_dsp_rproc_mbox_callback(). Other than this the functions are the same and could be shared.
Quoted 18 lines
drivers/remoteproc/ti_k3_m4_remoteproc.c new file +18
-0+break ; +case RP_MBOX_ECHO_REPLY : +dev_info (dev,"received echo reply from %s\n" , name); +break ; +default : +/* silently handle all other valid messages */ +if (msg >=RP_MBOX_READY && msg <RP_MBOX_END_MSG ) +return ; +if (msg > kproc->rproc->max_notifyid) { +dev_dbg (dev,"dropping unknown message 0x%x" , msg); +return ; + } +/* msg contains the index of the triggered vring */ +if (rproc_vq_interrupt (kproc->rproc, msg) ==IRQ_NONE ) +dev_dbg (dev,"no message was found in vqid %d\n" , msg); + } +} +
drivers/remoteproc/ti_k3_m4_remoteproc.c line 83
Quoted 10 lines
drivers/remoteproc/ti_k3_m4_remoteproc.c new file +10
-0+static int k3_m4_rproc_request_mbox (struct rproc *rproc) +{ +struct k3_rproc *kproc = rproc->priv; +struct mbox_client *client = &kproc->client; +struct device *dev = kproc->dev; +int ret; + + client->dev = dev; + client->tx_done =NULL ; + client->rx_callback = k3_m4_rproc_mbox_callback;
Same comment as above, i.e if k3_m4_rproc_mbox_callback() becomes generic than k3_rproc_request_mbox() can be shared by both drivers.
Quoted 37 lines
drivers/remoteproc/ti_k3_m4_remoteproc.c new file +37
-0+ client->tx_block = false; + client->knows_txdone = false; + + kproc->mbox =mbox_request_channel (client,0 ); +if (IS_ERR (kproc->mbox)) { + ret = -EBUSY ; +dev_err (dev,"mbox_request_channel failed: %ld\n" , +PTR_ERR (kproc->mbox)); +return ret; + } + +/* +* Ping the remote processor, this is only for sanity-sake for now; +* there is no functional effect whatsoever. +* +* Note that the reply will _not_ arrive immediately: this message +* will wait in the mailbox fifo until the remote processor is booted. +*/ + ret =mbox_send_message (kproc->mbox, (void *)RP_MBOX_ECHO_REQUEST ); +if (ret <0 ) { +dev_err (dev,"mbox_send_message failed: %d\n" , ret); +mbox_free_channel (kproc->mbox); +return ret; + } + +return 0 ; +} + +/* +* The M4F cores have a local reset that affects only the CPU, and a +* generic module reset that powers on the device and allows the M4 internal +* memories to be accessed while the local reset is asserted. This function is +* used to release the global reset on M4F to allow loading into the M4F +* internal RAMs. The .prepare() ops is invoked by remoteproc core before any +* firmware loading, and is followed by the .start() ops after loading to +* actually let the M4F core run. +*/
drivers/remoteproc/ti_k3_m4_remoteproc.c line 130
Quoted 10 lines
drivers/remoteproc/ti_k3_m4_remoteproc.c new file +10
-0+static int k3_m4_rproc_prepare (struct rproc *rproc) +{ +struct k3_rproc *kproc = rproc->priv; +struct device *dev = kproc->dev; +int ret; + +/* IPC-only mode does not require the core to be released from reset */ +if (kproc->ipc_only) +return 0 ; +
See my comment below
Quoted 18 lines
drivers/remoteproc/ti_k3_m4_remoteproc.c new file +18
-0+ ret = kproc->ti_sci->ops.dev_ops.get_device (kproc->ti_sci, + kproc->ti_sci_id); +if (ret) +dev_err (dev,"module-reset deassert failed, cannot enable internal RAM loading, ret = %d\n" , + ret); + +return ret; +} + +/* +* This function implements the .unprepare() ops and performs the complimentary +* operations to that of the .prepare() ops. The function is used to assert the +* global reset on applicable M4F cores. This completes the second portion of +* powering down the M4F cores. The cores themselves are only halted in the +* .stop() callback through the local reset, and the .unprepare() ops is invoked +* by the remoteproc core after the remoteproc is stopped to balance the global +* reset. +*/
drivers/remoteproc/ti_k3_m4_remoteproc.c line 158
Quoted 10 lines
drivers/remoteproc/ti_k3_m4_remoteproc.c new file +10
-0+static int k3_m4_rproc_unprepare (struct rproc *rproc) +{ +struct k3_rproc *kproc = rproc->priv; +struct device *dev = kproc->dev; +int ret; + +/* do not put back the cores into reset in IPC-only mode */ +if (kproc->ipc_only) +return 0 ; +
Same
Quoted 17 lines
drivers/remoteproc/ti_k3_m4_remoteproc.c new file +17
-0+ ret = kproc->ti_sci->ops.dev_ops.put_device (kproc->ti_sci, + kproc->ti_sci_id); +if (ret) +dev_err (dev,"module-reset assert failed, ret = %d\n" , ret); + +return ret; +} + +/* +* Power up the M4F remote processor. +* +* This function will be invoked only after the firmware for this rproc +* was loaded, parsed successfully, and all of its resource requirements +* were met. +*/ +static int k3_m4_rproc_start (struct rproc *rproc) +{
drivers/remoteproc/ti_k3_m4_remoteproc.c line 185
Quoted 10 lines
drivers/remoteproc/ti_k3_m4_remoteproc.c new file +10
-0+struct k3_rproc *kproc = rproc->priv; +struct device *dev = kproc->dev; +u32 boot_addr; +int ret; + +if (kproc->ipc_only) { +dev_err (dev,"%s cannot be invoked in IPC-only mode\n" , + __func__); +return -EINVAL ; + }
The above is not needed if k3_m4_rproc_ops is fixed in probe() to enact the right operations based on the operating mode, as it is done in k3_dsp_rproc_probe(). That way prepare(), unprepare(), start(), stop(), attach() and detach() can be shared by both drivers.
Quoted 48 lines
drivers/remoteproc/ti_k3_m4_remoteproc.c new file +48
-0+ + ret =k3_m4_rproc_request_mbox (rproc); +if (ret) +return ret; + + boot_addr = rproc->bootaddr; + ret =k3_rproc_release (kproc); +if (ret) + goto put_mbox; + +return 0 ; + +put_mbox: +mbox_free_channel (kproc->mbox); +return ret; +} + +/* +* Stop the M4 remote processor. +* +* This function puts the M4 processor into reset, and finishes processing +* of any pending messages. +*/ +static int k3_m4_rproc_stop (struct rproc *rproc) +{ +struct k3_rproc *kproc = rproc->priv; +struct device *dev = kproc->dev; + +if (kproc->ipc_only) { +dev_err (dev,"%s cannot be invoked in IPC-only mode\n" , + __func__); +return -EINVAL ; + } + +mbox_free_channel (kproc->mbox); + +k3_rproc_reset (kproc); + +return 0 ; +} + +/* +* Attach to a running M4 remote processor (IPC-only mode) +* +* This rproc attach callback only needs to request the mailbox, the remote +* processor is already booted, so there is no need to issue any TI-SCI +* commands to boot the M4 core. +*/
drivers/remoteproc/ti_k3_m4_remoteproc.c line 243
Quoted 10 lines
drivers/remoteproc/ti_k3_m4_remoteproc.c new file +10
-0+static int k3_m4_rproc_attach (struct rproc *rproc) +{ +struct k3_rproc *kproc = rproc->priv; +struct device *dev = kproc->dev; +int ret; + +if (!kproc->ipc_only || rproc->state !=RPROC_DETACHED ) { +dev_err (dev,"M4 is expected to be in IPC-only mode and RPROC_DETACHED state\n" ); +return -EINVAL ; + }
Checking for RPROC_DETACHED is not required since it is already done in the core.
drivers/remoteproc/ti_k3_m4_remoteproc.c line 249
Quoted 6 lines
drivers/remoteproc/ti_k3_m4_remoteproc.c new file +6
-0+ + ret =k3_m4_rproc_request_mbox (rproc); +if (ret) +return ret; + +dev_err (dev,"M4 initialized in IPC-only mode\n" );
Move this to dev_info()
Quoted 12 lines
drivers/remoteproc/ti_k3_m4_remoteproc.c new file +12
-0+return 0 ; +} + +/* +* Detach from a running M4 remote processor (IPC-only mode) +* +* This rproc detach callback performs the opposite operation to attach callback +* and only needs to release the mailbox, the M4 core is not stopped and will +* be left to continue to run its booted firmware. +*/ +static int k3_m4_rproc_detach (struct rproc *rproc) +{
drivers/remoteproc/ti_k3_m4_remoteproc.c line 271
Quoted 10 lines
drivers/remoteproc/ti_k3_m4_remoteproc.c new file +10
-0+struct k3_rproc *kproc = rproc->priv; +struct device *dev = kproc->dev; + +if (!kproc->ipc_only || rproc->state !=RPROC_ATTACHED ) { +dev_err (dev,"M4 is expected to be in IPC-only mode and RPROC_ATTACHED state\n" ); +return -EINVAL ; + } + +mbox_free_channel (kproc->mbox); +dev_err (dev,"M4 deinitialized in IPC-only mode\n" );
Same
drivers/remoteproc/ti_k3_m4_remoteproc.c line 130
Quoted 5 lines
drivers/remoteproc/ti_k3_m4_remoteproc.c new file +5
-0+return 0 ; +} + + +
Extra new lines.
Quoted 99 lines
drivers/remoteproc/ti_k3_m4_remoteproc.c new file +99
-0+static const struct rproc_ops k3_m4_rproc_ops = { + .start = k3_m4_rproc_start, + .stop = k3_m4_rproc_stop, + .attach = k3_m4_rproc_attach, + .detach = k3_m4_rproc_detach, + .kick = k3_rproc_kick, + .da_to_va = k3_rproc_da_to_va, + .get_loaded_rsc_table = k3_get_loaded_rsc_table, +}; + +static int k3_m4_rproc_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct device_node *np = dev->of_node; +const struct k3_rproc_dev_data *data; +struct k3_rproc *kproc; +struct rproc *rproc; +const char *fw_name; +bool r_state = false; +bool p_state = false; +int ret =0 ; +int ret1; + + data =of_device_get_match_data (dev); +if (!data) +return -ENODEV ; + + ret =rproc_of_parse_firmware (dev,0 , &fw_name); +if (ret) { +dev_err (dev,"failed to parse firmware-name property, ret = %d\n" , + ret); +return ret; + } + + rproc =rproc_alloc (dev,dev_name (dev), &k3_m4_rproc_ops, fw_name, +sizeof (*kproc)); +if (!rproc) +return -ENOMEM ; + + rproc->has_iommu = false; + rproc->recovery_disabled = true; +if (data->uses_lreset) { + rproc->ops->prepare = k3_m4_rproc_prepare; + rproc->ops->unprepare = k3_m4_rproc_unprepare; + } + kproc = rproc->priv; + kproc->rproc = rproc; + kproc->dev = dev; + kproc->data = data; + + kproc->ti_sci =ti_sci_get_by_phandle (np,"ti,sci" ); +if (IS_ERR (kproc->ti_sci)) { + ret =PTR_ERR (kproc->ti_sci); +if (ret != -EPROBE_DEFER ) { +dev_err (dev,"failed to get ti-sci handle, ret = %d\n" , + ret); + } + kproc->ti_sci =NULL ; + goto free_rproc; + } + + ret =of_property_read_u32 (np,"ti,sci-dev-id" , &kproc->ti_sci_id); +if (ret) { +dev_err (dev,"missing 'ti,sci-dev-id' property\n" ); + goto put_sci; + } + + kproc->reset =devm_reset_control_get_exclusive (dev,NULL ); +if (IS_ERR (kproc->reset)) { + ret =PTR_ERR (kproc->reset); +dev_err (dev,"failed to get reset, status = %d\n" , ret); + goto put_sci; + } + + kproc->tsp =k3_rproc_of_get_tsp (dev, kproc->ti_sci); +if (IS_ERR (kproc->tsp)) { +dev_err (dev,"failed to construct ti-sci proc control, ret = %d\n" , + ret); + ret =PTR_ERR (kproc->tsp); + goto put_sci; + } + + ret =ti_sci_proc_request (kproc->tsp); +if (ret <0 ) { +dev_err (dev,"ti_sci_proc_request failed, ret = %d\n" , ret); + goto free_tsp; + } + + ret =k3_rproc_of_get_memories (pdev, kproc); +if (ret) + goto release_tsp; + + ret =k3_reserved_mem_init (kproc); +if (ret) { +dev_err (dev,"reserved memory init failed, ret = %d\n" , ret); + goto release_tsp; + } + + ret = kproc->ti_sci->ops.dev_ops.is_on(kproc->ti_sci, kproc->ti_sci_id,
drivers/remoteproc/ti_k3_m4_remoteproc.c line 385
Quoted 10 lines
drivers/remoteproc/ti_k3_m4_remoteproc.c new file +10
-0+ &r_state, &p_state); +if (ret) { +dev_err (dev,"failed to get initial state, mode cannot be determined, ret = %d\n" , + ret); + goto release_mem; + } + +/* configure devices for either remoteproc or IPC-only mode */ +if (p_state) { +dev_err (dev,"configured M4 for IPC-only mode\n" );
Change this to dev_info()
drivers/remoteproc/ti_k3_m4_remoteproc.c line 389
Quoted 4 lines
drivers/remoteproc/ti_k3_m4_remoteproc.c new file +4
-0+ rproc->state =RPROC_DETACHED ; + kproc->ipc_only = true; + }else { +dev_err (dev,"configured M4 for remoteproc mode\n" );
Same here
I am done reviewing this set.
Thanks,
Mathieu
Quoted 105 lines
drivers/remoteproc/ti_k3_m4_remoteproc.c new file +102
-0+/* +* ensure the M4 local reset is asserted to ensure the core +* doesn't execute bogus code in .prepare() when the module +* reset is released. +*/ +if (data->uses_lreset) { + ret =reset_control_status (kproc->reset); +if (ret <0 ) { +dev_err (dev,"failed to get reset status, status = %d\n" , + ret); + goto release_mem; + }else if (ret ==0 ) { +dev_warn (dev,"local reset is deasserted for device\n" ); +k3_rproc_reset (kproc); + } + } + } + + ret =rproc_add (rproc); +if (ret) { +dev_err (dev,"failed to add register device with remoteproc core, status = %d\n" , + ret); + goto release_mem; + } + +platform_set_drvdata (pdev, kproc); + +return 0 ; + +release_mem: +k3_reserved_mem_exit (kproc); +release_tsp: + ret1 =ti_sci_proc_release (kproc->tsp); +if (ret1) +dev_err (dev,"failed to release proc, ret = %d\n" , ret1); +free_tsp: +kfree (kproc->tsp); +put_sci: + ret1 =ti_sci_put_handle (kproc->ti_sci); +if (ret1) +dev_err (dev,"failed to put ti_sci handle, ret = %d\n" , ret1); +free_rproc: +rproc_free (rproc); +return ret; +} + +static int k3_m4_rproc_remove (struct platform_device *pdev) +{ +struct k3_rproc *kproc =platform_get_drvdata (pdev); +struct device *dev = &pdev->dev; +int ret; + +rproc_del (kproc->rproc); + + ret =ti_sci_proc_release (kproc->tsp); +if (ret) +dev_err (dev,"failed to release proc, ret = %d\n" , ret); + +kfree (kproc->tsp); + + ret =ti_sci_put_handle (kproc->ti_sci); +if (ret) +dev_err (dev,"failed to put ti_sci handle, ret = %d\n" , ret); + +k3_reserved_mem_exit (kproc); +rproc_free (kproc->rproc); + +return 0 ; +} + +static const struct k3_rproc_mem_data am64_m4_mems[] = { + { .name ="iram" , .dev_addr =0x0 }, + { .name ="dram" , .dev_addr =0x30000 }, +}; + +static const struct k3_rproc_dev_data am64_m4_data = { + .mems = am64_m4_mems, + .num_mems =ARRAY_SIZE (am64_m4_mems), + .boot_align_addr =SZ_1K , + .uses_lreset = true, +}; + +static const struct of_device_id k3_m4_of_match[] = { + { .compatible ="ti,am64-m4fss" , .data = &am64_m4_data, }, + {/* sentinel */ }, +}; +MODULE_DEVICE_TABLE (of, k3_m4_of_match); + +static struct platform_driver k3_m4_rproc_driver = { + .probe = k3_m4_rproc_probe, + .remove = k3_m4_rproc_remove, + .driver = { + .name ="k3-m4-rproc" , + .of_match_table = k3_m4_of_match, + }, +}; + +module_platform_driver (k3_m4_rproc_driver); + +MODULE_AUTHOR ("Hari Nagalla <[email protected]>" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_DESCRIPTION ("TI K3 M4 Remoteproc driver" );Signature · 1 line
2.39.1