[PATCH V10 01/10] dt-bindings: remoteproc: convert imx rproc bindings to json-schema

2021-02-15 Thread peng . fan
From: Peng Fan 

Convert the imx rproc binding to DT schema format using json-schema.

Signed-off-by: Peng Fan 
---
 .../bindings/remoteproc/fsl,imx-rproc.yaml| 60 +++
 .../bindings/remoteproc/imx-rproc.txt | 33 --
 2 files changed, 60 insertions(+), 33 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
 delete mode 100644 Documentation/devicetree/bindings/remoteproc/imx-rproc.txt

diff --git a/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml 
b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
new file mode 100644
index ..8427d0f6e471
--- /dev/null
+++ b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
@@ -0,0 +1,60 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/remoteproc/fsl,imx-rproc.yaml#;
+$schema: "http://devicetree.org/meta-schemas/core.yaml#;
+
+title: NXP iMX6SX/iMX7D Co-Processor Bindings
+
+description:
+  This binding provides support for ARM Cortex M4 Co-processor found on some 
NXP iMX SoCs.
+
+maintainers:
+  - Peng Fan 
+
+properties:
+  compatible:
+enum:
+  - fsl,imx7d-cm4
+  - fsl,imx6sx-cm4
+
+  clocks:
+maxItems: 1
+
+  syscon:
+$ref: /schemas/types.yaml#/definitions/phandle
+description:
+  Phandle to syscon block which provide access to System Reset Controller
+
+  memory-region:
+description:
+  If present, a phandle for a reserved memory area that used for vdev 
buffer,
+  resource table, vring region and others used by remote processor.
+minItems: 1
+
+required:
+  - compatible
+  - clocks
+  - syscon
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+m4_reserved_sysmem1: cm4@8000 {
+  reg = <0x8000 0x8>;
+};
+
+m4_reserved_sysmem2: cm4@8100 {
+  reg = <0x8100 0x8>;
+};
+
+imx7d-cm4 {
+  compatible   = "fsl,imx7d-cm4";
+  memory-region= <_reserved_sysmem1>, <_reserved_sysmem2>;
+  syscon   = <>;
+  clocks   = < IMX7D_ARM_M4_ROOT_CLK>;
+};
+
+...
diff --git a/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt 
b/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt
deleted file mode 100644
index fbcefd965dc4..
--- a/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-NXP iMX6SX/iMX7D Co-Processor Bindings
-
-
-This binding provides support for ARM Cortex M4 Co-processor found on some
-NXP iMX SoCs.
-
-Required properties:
-- compatible   Should be one of:
-   "fsl,imx7d-cm4"
-   "fsl,imx6sx-cm4"
-- clocks   Clock for co-processor (See: 
../clock/clock-bindings.txt)
-- syscon   Phandle to syscon block which provide access to
-   System Reset Controller
-
-Optional properties:
-- memory-regionlist of phandels to the reserved memory regions.
-   (See: ../reserved-memory/reserved-memory.txt)
-
-Example:
-   m4_reserved_sysmem1: cm4@8000 {
-   reg = <0x8000 0x8>;
-   };
-
-   m4_reserved_sysmem2: cm4@8100 {
-   reg = <0x8100 0x8>;
-   };
-
-   imx7d-cm4 {
-   compatible  = "fsl,imx7d-cm4";
-   memory-region   = <_reserved_sysmem1>, 
<_reserved_sysmem2>;
-   syscon  = <>;
-   clocks  = < IMX7D_ARM_M4_ROOT_CLK>;
-   };
-- 
2.30.0



[PATCH V10 04/10] remoteproc: add is_iomem to da_to_va

2021-02-15 Thread peng . fan
From: Peng Fan 

Introduce an extra parameter is_iomem to da_to_va, then the caller
could take the memory as normal memory or io mapped memory.

Reviewed-by: Bjorn Andersson 
Reviewed-by: Mathieu Poirier 
Reported-by: kernel test robot 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c |  2 +-
 drivers/remoteproc/ingenic_rproc.c |  2 +-
 drivers/remoteproc/keystone_remoteproc.c   |  2 +-
 drivers/remoteproc/mtk_scp.c   |  6 +++---
 drivers/remoteproc/omap_remoteproc.c   |  2 +-
 drivers/remoteproc/pru_rproc.c |  2 +-
 drivers/remoteproc/qcom_q6v5_adsp.c|  2 +-
 drivers/remoteproc/qcom_q6v5_pas.c |  2 +-
 drivers/remoteproc/qcom_q6v5_wcss.c|  2 +-
 drivers/remoteproc/qcom_wcnss.c|  2 +-
 drivers/remoteproc/remoteproc_core.c   |  7 +--
 drivers/remoteproc/remoteproc_coredump.c   |  8 ++--
 drivers/remoteproc/remoteproc_debugfs.c|  2 +-
 drivers/remoteproc/remoteproc_elf_loader.c | 21 +++--
 drivers/remoteproc/remoteproc_internal.h   |  2 +-
 drivers/remoteproc/st_slim_rproc.c |  2 +-
 drivers/remoteproc/ti_k3_dsp_remoteproc.c  |  2 +-
 drivers/remoteproc/ti_k3_r5_remoteproc.c   |  2 +-
 drivers/remoteproc/wkup_m3_rproc.c |  2 +-
 include/linux/remoteproc.h |  2 +-
 20 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 8957ed271d20..6603e00bb6f4 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -208,7 +208,7 @@ static int imx_rproc_da_to_sys(struct imx_rproc *priv, u64 
da,
return -ENOENT;
 }
 
-static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool 
*is_iomem)
 {
struct imx_rproc *priv = rproc->priv;
void *va = NULL;
diff --git a/drivers/remoteproc/ingenic_rproc.c 
b/drivers/remoteproc/ingenic_rproc.c
index e2618c36eaab..a356738160a4 100644
--- a/drivers/remoteproc/ingenic_rproc.c
+++ b/drivers/remoteproc/ingenic_rproc.c
@@ -121,7 +121,7 @@ static void ingenic_rproc_kick(struct rproc *rproc, int 
vqid)
writel(vqid, vpu->aux_base + REG_CORE_MSG);
 }
 
-static void *ingenic_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *ingenic_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, 
bool *is_iomem)
 {
struct vpu *vpu = rproc->priv;
void __iomem *va = NULL;
diff --git a/drivers/remoteproc/keystone_remoteproc.c 
b/drivers/remoteproc/keystone_remoteproc.c
index cd266163a65f..54781f553f4e 100644
--- a/drivers/remoteproc/keystone_remoteproc.c
+++ b/drivers/remoteproc/keystone_remoteproc.c
@@ -246,7 +246,7 @@ static void keystone_rproc_kick(struct rproc *rproc, int 
vqid)
  * can be used either by the remoteproc core for loading (when using kernel
  * remoteproc loader), or by any rpmsg bus drivers.
  */
-static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, 
bool *is_iomem)
 {
struct keystone_rproc *ksproc = rproc->priv;
void __iomem *va = NULL;
diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c
index ce727598c41c..9679cc26895e 100644
--- a/drivers/remoteproc/mtk_scp.c
+++ b/drivers/remoteproc/mtk_scp.c
@@ -272,7 +272,7 @@ static int scp_elf_load_segments(struct rproc *rproc, const 
struct firmware *fw)
}
 
/* grab the kernel address for this device address */
-   ptr = (void __iomem *)rproc_da_to_va(rproc, da, memsz);
+   ptr = (void __iomem *)rproc_da_to_va(rproc, da, memsz, NULL);
if (!ptr) {
dev_err(dev, "bad phdr da 0x%x mem 0x%x\n", da, memsz);
ret = -EINVAL;
@@ -509,7 +509,7 @@ static void *mt8192_scp_da_to_va(struct mtk_scp *scp, u64 
da, size_t len)
return NULL;
 }
 
-static void *scp_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *scp_da_to_va(struct rproc *rproc, u64 da, size_t len, bool 
*is_iomem)
 {
struct mtk_scp *scp = (struct mtk_scp *)rproc->priv;
 
@@ -627,7 +627,7 @@ void *scp_mapping_dm_addr(struct mtk_scp *scp, u32 mem_addr)
 {
void *ptr;
 
-   ptr = scp_da_to_va(scp->rproc, mem_addr, 0);
+   ptr = scp_da_to_va(scp->rproc, mem_addr, 0, NULL);
if (!ptr)
return ERR_PTR(-EINVAL);
 
diff --git a/drivers/remoteproc/omap_remoteproc.c 
b/drivers/remoteproc/omap_remoteproc.c
index d94b7391bf9d..43531caa1959 100644
--- a/drivers/remoteproc/omap_remoteproc.c
+++ b/drivers/remoteproc/omap_remoteproc.c
@@ -728,7 +728,7 @@ static int omap_rproc_stop(struct rproc *rproc)
  * Return: translated virtual address in kernel memory space on success,
  * or NULL on failure.
  */
-static void *omap_rproc_da_to

[PATCH V10 03/10] remoteproc: introduce is_iomem to rproc_mem_entry

2021-02-15 Thread peng . fan
From: Peng Fan 

Introduce is_iomem to indicate this piece memory is iomem or not.

Reviewed-by: Bjorn Andersson 
Signed-off-by: Peng Fan 
Reviewed-by: Mathieu Poirier 
---
 include/linux/remoteproc.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index f28ee75d1005..a5f6d2d9cde2 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -315,6 +315,7 @@ struct rproc;
 /**
  * struct rproc_mem_entry - memory entry descriptor
  * @va:virtual address
+ * @is_iomem: io memory
  * @dma: dma address
  * @len: length, in bytes
  * @da: device address
@@ -329,6 +330,7 @@ struct rproc;
  */
 struct rproc_mem_entry {
void *va;
+   bool is_iomem;
dma_addr_t dma;
size_t len;
u32 da;
-- 
2.30.0



[PATCH V10 02/10] dt-bindings: remoteproc: imx_rproc: add i.MX8MQ/M support

2021-02-15 Thread peng . fan
From: Peng Fan 

Add i.MX8MQ/M support, also include mailbox for rpmsg/virtio usage.

Signed-off-by: Peng Fan 
---
 .../bindings/remoteproc/fsl,imx-rproc.yaml| 51 ++-
 1 file changed, 50 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml 
b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
index 8427d0f6e471..f87e98d98413 100644
--- a/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
+++ b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
@@ -4,7 +4,7 @@
 $id: "http://devicetree.org/schemas/remoteproc/fsl,imx-rproc.yaml#;
 $schema: "http://devicetree.org/meta-schemas/core.yaml#;
 
-title: NXP iMX6SX/iMX7D Co-Processor Bindings
+title: NXP i.MX Co-Processor Bindings
 
 description:
   This binding provides support for ARM Cortex M4 Co-processor found on some 
NXP iMX SoCs.
@@ -15,6 +15,8 @@ maintainers:
 properties:
   compatible:
 enum:
+  - fsl,imx8mq-cm4
+  - fsl,imx8mm-cm4
   - fsl,imx7d-cm4
   - fsl,imx6sx-cm4
 
@@ -26,6 +28,20 @@ properties:
 description:
   Phandle to syscon block which provide access to System Reset Controller
 
+  mbox-names:
+items:
+  - const: tx
+  - const: rx
+  - const: rxdb
+
+  mboxes:
+description:
+  This property is required only if the rpmsg/virtio functionality is used.
+  List of < type channel> - 1 channel for TX, 1 channel for RX, 1 
channel for RXDB.
+  (see mailbox/fsl,mu.yaml)
+minItems: 1
+maxItems: 3
+
   memory-region:
 description:
   If present, a phandle for a reserved memory area that used for vdev 
buffer,
@@ -57,4 +73,37 @@ examples:
   clocks   = < IMX7D_ARM_M4_ROOT_CLK>;
 };
 
+  - |
+#include 
+rsc_table: rsc_table@550ff000 {
+  no-map;
+  reg = <0x550ff000 0x1000>;
+};
+
+vdev0vring0: vdev0vring0@5500 {
+  no-map;
+  reg = <0x5500 0x8000>;
+};
+
+vdev0vring1: vdev0vring1@55008000 {
+  reg = <0x55008000 0x8000>;
+  no-map;
+};
+
+vdev0buffer: vdev0buffer@5540 {
+  compatible = "shared-dma-pool";
+  reg = <0x5540 0x10>;
+  no-map;
+};
+
+imx8mm-cm4 {
+  compatible = "fsl,imx8mm-cm4";
+  clocks = < IMX8MM_CLK_M4_DIV>;
+  mbox-names = "tx", "rx", "rxdb";
+  mboxes = < 0 1
+ 1 1
+ 3 1>;
+  memory-region = <>, <>, <>, 
<_table>;
+  syscon = <>;
+};
 ...
-- 
2.30.0



[PATCH V10 00/10] remoteproc: imx_rproc: support iMX8MQ/M

2021-02-15 Thread peng . fan
From: Peng Fan 

V11:
 Per Rob's comments, fix memory-region in patch 1/10
 Rebased on top of Linux-next

V10:
 Per Rob's comments, fix patch 1/10

V9:
 Per Mathieu's comments,
   update the tile of yaml in patch 2/10
   update the Kconfig and MODULE_DESCRIPTION, I merge this change in patch 8/10,
   since this is a minor change, I still keep Mathieu's R-b tag. If any 
objection, I could remove.
   Add R-b tag in Patch 10/10

 Rob, please help review patch 1/10 and 2/10

V8:
 Address sparse warning in patch 4/10 reported by kernel test robot

V7:
 Add R-b tag from Mathieu
 vdevbuffer->vdev0buffer in patch 1/10, 7/10
 correct err msg and shutdown seq per Mathieu's comments in patch 10/10
 Hope this version is ok to be merged.
 
V6:
 Add R-b tag from Mathieu
 Convert imx-rproc.txt to yaml and add dt-bindings support for i.MX8MQ/M, patch 
1/10 2/10
 No other changes.

V5:
 Apply on Linux next
 Add V5 subject prefix
 Add R-b tag from Bjorn for 1/8, 2/8, 3/8
 
https://patchwork.kernel.org/project/linux-remoteproc/cover/20201229033019.25899-1-peng@nxp.com/

V4:
 According to Bjorn's comments, add is_iomem for da to va usage
 1/8, 2/8 is new patch
 3/8, follow Bjorn's comments to correct/update the err msg.
 6/8, new patch
 8/8, use dev_err_probe to simplify code, use queue_work instead 
schedule_delayed_work

V3:
 Since I was quite busy in the past days, V3 is late
 Rebased on Linux-next
 Add R-b tags
 1/7: Add R-b tag of Mathieu, add comments
 4/7: Typo fix
 5/7: Add R-b tag of Mathieu, drop index Per Mathieu's comments
 6/7: Add R-b tag of Mathieu
 7/7: Add comment for vqid << 16, drop unneeded timeout settings of mailbox
  Use queue_work instead of schedule_delayed_work
  free mbox channels when remove
 https://lkml.org/lkml/2020/12/4/82

V2:
 Rebased on linux-next
 Dropped early boot feature to make patchset simple.
 Drop rsc-da
 
https://patchwork.kernel.org/project/linux-remoteproc/cover/20200927064131.24101-1-peng@nxp.com/

V1:
 https://patchwork.kernel.org/cover/11682461/

This patchset is to support i.MX8MQ/M coproc.
The early boot feature was dropped to make the patchset small in V2.

Since i.MX specific TCM memory requirement, add elf platform hook.
Several patches have got reviewed by Oleksij and Mathieu in v1.


Peng Fan (10):
  dt-bindings: remoteproc: convert imx rproc bindings to json-schema
  dt-bindings: remoteproc: imx_rproc: add i.MX8MQ/M support
  remoteproc: introduce is_iomem to rproc_mem_entry
  remoteproc: add is_iomem to da_to_va
  remoteproc: imx_rproc: correct err message
  remoteproc: imx_rproc: use devm_ioremap
  remoteproc: imx_rproc: add i.MX specific parse fw hook
  remoteproc: imx_rproc: support i.MX8MQ/M
  remoteproc: imx_rproc: ignore mapping vdev regions
  remoteproc: imx_proc: enable virtio/mailbox

 .../bindings/remoteproc/fsl,imx-rproc.yaml| 109 
 .../bindings/remoteproc/imx-rproc.txt |  33 ---
 drivers/remoteproc/Kconfig|   6 +-
 drivers/remoteproc/imx_rproc.c| 262 +-
 drivers/remoteproc/ingenic_rproc.c|   2 +-
 drivers/remoteproc/keystone_remoteproc.c  |   2 +-
 drivers/remoteproc/mtk_scp.c  |   6 +-
 drivers/remoteproc/omap_remoteproc.c  |   2 +-
 drivers/remoteproc/pru_rproc.c|   2 +-
 drivers/remoteproc/qcom_q6v5_adsp.c   |   2 +-
 drivers/remoteproc/qcom_q6v5_pas.c|   2 +-
 drivers/remoteproc/qcom_q6v5_wcss.c   |   2 +-
 drivers/remoteproc/qcom_wcnss.c   |   2 +-
 drivers/remoteproc/remoteproc_core.c  |   7 +-
 drivers/remoteproc/remoteproc_coredump.c  |   8 +-
 drivers/remoteproc/remoteproc_debugfs.c   |   2 +-
 drivers/remoteproc/remoteproc_elf_loader.c|  21 +-
 drivers/remoteproc/remoteproc_internal.h  |   2 +-
 drivers/remoteproc/st_slim_rproc.c|   2 +-
 drivers/remoteproc/ti_k3_dsp_remoteproc.c |   2 +-
 drivers/remoteproc/ti_k3_r5_remoteproc.c  |   2 +-
 drivers/remoteproc/wkup_m3_rproc.c|   2 +-
 include/linux/remoteproc.h|   4 +-
 23 files changed, 412 insertions(+), 72 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
 delete mode 100644 Documentation/devicetree/bindings/remoteproc/imx-rproc.txt

-- 
2.30.0



RE: [PATCH V10 01/10] dt-bindings: remoteproc: convert imx rproc bindings to json-schema

2021-02-13 Thread Peng Fan
> Subject: Re: [PATCH V10 01/10] dt-bindings: remoteproc: convert imx rproc
> bindings to json-schema
> 
> On Mon, Feb 08, 2021 at 04:56:02PM +0800, peng@oss.nxp.com wrote:
> > From: Peng Fan 
> >
> > Convert the imx rproc binding to DT schema format using json-schema.
> >
> > Signed-off-by: Peng Fan 
> > ---
> >  .../bindings/remoteproc/fsl,imx-rproc.yaml| 59
> +++
> >  .../bindings/remoteproc/imx-rproc.txt | 33 ---
> >  2 files changed, 59 insertions(+), 33 deletions(-)  create mode
> > 100644 Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
> >  delete mode 100644
> > Documentation/devicetree/bindings/remoteproc/imx-rproc.txt
> >
> > diff --git
> > a/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
> > b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
> > new file mode 100644
> > index ..5e906fa6a39d
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
> > @@ -0,0 +1,59 @@
> > +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) %YAML 1.2
> > +---
> > +$id:
> "https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fdevice
> tree.org%2Fschemas%2Fremoteproc%2Ffsl%2Cimx-rproc.yaml%23dat
> a=04%7C01%7Cpeng.fan%40nxp.com%7Cd1b06ffd889240a45f8308d8cdea93
> 40%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C6374857546682
> 06133%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2l
> uMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000sdata=jTnFLISLpjJN
> vV4euhlqUvnj9YMk9YoDZWoxQi97kdc%3Dreserved=0"
> > +$schema:
> "https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fdevice
> tree.org%2Fmeta-schemas%2Fcore.yaml%23data=04%7C01%7Cpeng.f
> an%40nxp.com%7Cd1b06ffd889240a45f8308d8cdea9340%7C686ea1d3bc2b
> 4c6fa92cd99c5c301635%7C0%7C0%7C637485754668206133%7CUnknown
> %7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1ha
> WwiLCJXVCI6Mn0%3D%7C1000sdata=98u0FLfvAhOiYoT7Vvbqg6yW5
> wVEmLVrhLvCz83VRiM%3Dreserved=0"
> > +
> > +title: NXP iMX6SX/iMX7D Co-Processor Bindings
> > +
> > +description:
> > +  This binding provides support for ARM Cortex M4 Co-processor found on
> some NXP iMX SoCs.
> > +
> > +maintainers:
> > +  - Peng Fan 
> > +
> > +properties:
> > +  compatible:
> > +enum:
> > +  - fsl,imx7d-cm4
> > +  - fsl,imx6sx-cm4
> > +
> > +  clocks:
> > +maxItems: 1
> > +
> > +  syscon:
> > +$ref: /schemas/types.yaml#/definitions/phandle
> > +description:
> > +  Phandle to syscon block which provide access to System Reset
> > + Controller
> > +
> > +  memory-region:
> > +description:
> > +  If present, a phandle for a reserved memory area that used for
> vdev buffer,
> > +  resource table, vring region and others used by remote processor.
> 
> You need to define what each one is as a schema. How does the driver know
> which one is the vring region for example? Minimally, it's:
> 
> items:
>   - description: ...
>   - description: ...
>   - description: ...
> 
> But if what's present is variable, then it gets more complicated. If the OS 
> side
> doesn't need to know what each region is, then you can do just:
> 
> minItems: N
> maxItems: M

I'll use minItems: 1, no maxItems.

Thanks,
Peng.

> 
> Rob
> 
> 
> 
> > +
> > +required:
> > +  - compatible
> > +  - clocks
> > +  - syscon
> > +
> > +additionalProperties: false
> > +
> > +examples:
> > +  - |
> > +#include 
> > +m4_reserved_sysmem1: cm4@8000 {
> > +  reg = <0x8000 0x8>;
> > +};
> > +
> > +m4_reserved_sysmem2: cm4@8100 {
> > +  reg = <0x8100 0x8>;
> > +};
> > +
> > +imx7d-cm4 {
> > +  compatible   = "fsl,imx7d-cm4";
> > +  memory-region= <_reserved_sysmem1>,
> <_reserved_sysmem2>;
> > +  syscon   = <>;
> > +  clocks   = < IMX7D_ARM_M4_ROOT_CLK>;
> > +};
> > +
> > +...
> > diff --git
> > a/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt
> > b/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt
> > deleted file mode 100644
> > index fbcefd965dc4..
> > --- a/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt
> > +++ /dev/null
> > @@ -1,33 +0,0 @@
> > -NXP iMX6SX/iMX7D Co-Processor Bindings
> > --

[PATCH V10 09/10] remoteproc: imx_rproc: ignore mapping vdev regions

2021-02-08 Thread peng . fan
From: Peng Fan 

vdev regions are vdev0vring0, vdev0vring1, vdevbuffer and similar.
They are handled by remoteproc common code, no need to map in imx
rproc driver.

Signed-off-by: Peng Fan 
Reviewed-by: Mathieu Poirier 
---
 drivers/remoteproc/imx_rproc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 0124ebf69838..3685bbd135b0 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -417,6 +417,9 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
struct resource res;
 
node = of_parse_phandle(np, "memory-region", a);
+   /* Not map vdev region */
+   if (!strcmp(node->name, "vdev"))
+   continue;
err = of_address_to_resource(node, 0, );
if (err) {
dev_err(dev, "unable to resolve memory region\n");
-- 
2.30.0



[PATCH V10 10/10] remoteproc: imx_proc: enable virtio/mailbox

2021-02-08 Thread peng . fan
From: Peng Fan 

Use virtio/mailbox to build connection between Remote Proccessors
and Linux. Add work queue to handle incoming messages.

Reviewed-by: Richard Zhu 
Reviewed-by: Mathieu Poirier 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c | 116 -
 1 file changed, 113 insertions(+), 3 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 3685bbd135b0..90471790bb24 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -15,6 +16,9 @@
 #include 
 #include 
 #include 
+#include 
+
+#include "remoteproc_internal.h"
 
 #define IMX7D_SRC_SCR  0x0C
 #define IMX7D_ENABLE_M4BIT(3)
@@ -86,6 +90,11 @@ struct imx_rproc {
const struct imx_rproc_dcfg *dcfg;
struct imx_rproc_memmem[IMX7D_RPROC_MEM_MAX];
struct clk  *clk;
+   struct mbox_client  cl;
+   struct mbox_chan*tx_ch;
+   struct mbox_chan*rx_ch;
+   struct work_struct  rproc_work;
+   struct workqueue_struct *workqueue;
 };
 
 static const struct imx_rproc_att imx_rproc_att_imx8mq[] = {
@@ -366,9 +375,33 @@ static int imx_rproc_parse_fw(struct rproc *rproc, const 
struct firmware *fw)
return 0;
 }
 
+static void imx_rproc_kick(struct rproc *rproc, int vqid)
+{
+   struct imx_rproc *priv = rproc->priv;
+   int err;
+   __u32 mmsg;
+
+   if (!priv->tx_ch) {
+   dev_err(priv->dev, "No initialized mbox tx channel\n");
+   return;
+   }
+
+   /*
+* Send the index of the triggered virtqueue as the mu payload.
+* Let remote processor know which virtqueue is used.
+*/
+   mmsg = vqid << 16;
+
+   err = mbox_send_message(priv->tx_ch, (void *));
+   if (err < 0)
+   dev_err(priv->dev, "%s: failed (%d, err:%d)\n",
+   __func__, vqid, err);
+}
+
 static const struct rproc_ops imx_rproc_ops = {
.start  = imx_rproc_start,
.stop   = imx_rproc_stop,
+   .kick   = imx_rproc_kick,
.da_to_va   = imx_rproc_da_to_va,
.load   = rproc_elf_load_segments,
.parse_fw   = imx_rproc_parse_fw,
@@ -444,6 +477,66 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
return 0;
 }
 
+static void imx_rproc_vq_work(struct work_struct *work)
+{
+   struct imx_rproc *priv = container_of(work, struct imx_rproc,
+ rproc_work);
+
+   rproc_vq_interrupt(priv->rproc, 0);
+   rproc_vq_interrupt(priv->rproc, 1);
+}
+
+static void imx_rproc_rx_callback(struct mbox_client *cl, void *msg)
+{
+   struct rproc *rproc = dev_get_drvdata(cl->dev);
+   struct imx_rproc *priv = rproc->priv;
+
+   queue_work(priv->workqueue, >rproc_work);
+}
+
+static int imx_rproc_xtr_mbox_init(struct rproc *rproc)
+{
+   struct imx_rproc *priv = rproc->priv;
+   struct device *dev = priv->dev;
+   struct mbox_client *cl;
+   int ret;
+
+   if (!of_get_property(dev->of_node, "mbox-names", NULL))
+   return 0;
+
+   cl = >cl;
+   cl->dev = dev;
+   cl->tx_block = true;
+   cl->tx_tout = 100;
+   cl->knows_txdone = false;
+   cl->rx_callback = imx_rproc_rx_callback;
+
+   priv->tx_ch = mbox_request_channel_byname(cl, "tx");
+   if (IS_ERR(priv->tx_ch)) {
+   ret = PTR_ERR(priv->tx_ch);
+   return dev_err_probe(cl->dev, ret,
+"failed to request tx mailbox channel: 
%d\n", ret);
+   }
+
+   priv->rx_ch = mbox_request_channel_byname(cl, "rx");
+   if (IS_ERR(priv->rx_ch)) {
+   mbox_free_channel(priv->tx_ch);
+   ret = PTR_ERR(priv->rx_ch);
+   return dev_err_probe(cl->dev, ret,
+"failed to request rx mailbox channel: 
%d\n", ret);
+   }
+
+   return 0;
+}
+
+static void imx_rproc_free_mbox(struct rproc *rproc)
+{
+   struct imx_rproc *priv = rproc->priv;
+
+   mbox_free_channel(priv->tx_ch);
+   mbox_free_channel(priv->rx_ch);
+}
+
 static int imx_rproc_probe(struct platform_device *pdev)
 {
struct device *dev = >dev;
@@ -481,18 +574,28 @@ static int imx_rproc_probe(struct platform_device *pdev)
priv->dev = dev;
 
dev_set_drvdata(dev, rproc);
+   priv->workqueue = create_workqueue(dev_name(dev));
+   if (!priv->workqueue) {
+   dev_err(dev, "cannot create workqueue\n");
+  

[PATCH V10 07/10] remoteproc: imx_rproc: add i.MX specific parse fw hook

2021-02-08 Thread peng . fan
From: Peng Fan 

The hook is used to parse memory-regions and load resource table
from the address the remote processor published.

Reviewed-by: Richard Zhu 
Reviewed-by: Mathieu Poirier 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c | 93 ++
 1 file changed, 93 insertions(+)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 47fc1d06be6a..5ae1f5209548 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -241,10 +242,102 @@ static void *imx_rproc_da_to_va(struct rproc *rproc, u64 
da, size_t len, bool *i
return va;
 }
 
+static int imx_rproc_mem_alloc(struct rproc *rproc,
+  struct rproc_mem_entry *mem)
+{
+   struct device *dev = rproc->dev.parent;
+   void *va;
+
+   dev_dbg(dev, "map memory: %p+%zx\n", >dma, mem->len);
+   va = ioremap_wc(mem->dma, mem->len);
+   if (IS_ERR_OR_NULL(va)) {
+   dev_err(dev, "Unable to map memory region: %p+%zx\n",
+   >dma, mem->len);
+   return -ENOMEM;
+   }
+
+   /* Update memory entry va */
+   mem->va = va;
+
+   return 0;
+}
+
+static int imx_rproc_mem_release(struct rproc *rproc,
+struct rproc_mem_entry *mem)
+{
+   dev_dbg(rproc->dev.parent, "unmap memory: %pa\n", >dma);
+   iounmap(mem->va);
+
+   return 0;
+}
+
+static int imx_rproc_parse_memory_regions(struct rproc *rproc)
+{
+   struct imx_rproc *priv = rproc->priv;
+   struct device_node *np = priv->dev->of_node;
+   struct of_phandle_iterator it;
+   struct rproc_mem_entry *mem;
+   struct reserved_mem *rmem;
+   u32 da;
+
+   /* Register associated reserved memory regions */
+   of_phandle_iterator_init(, np, "memory-region", NULL, 0);
+   while (of_phandle_iterator_next() == 0) {
+   /*
+* Ignore the first memory region which will be used vdev 
buffer.
+* No need to do extra handlings, rproc_add_virtio_dev will 
handle it.
+*/
+   if (!strcmp(it.node->name, "vdev0buffer"))
+   continue;
+
+   rmem = of_reserved_mem_lookup(it.node);
+   if (!rmem) {
+   dev_err(priv->dev, "unable to acquire memory-region\n");
+   return -EINVAL;
+   }
+
+   /* No need to translate pa to da, i.MX use same map */
+   da = rmem->base;
+
+   /* Register memory region */
+   mem = rproc_mem_entry_init(priv->dev, NULL, 
(dma_addr_t)rmem->base, rmem->size, da,
+  imx_rproc_mem_alloc, 
imx_rproc_mem_release,
+  it.node->name);
+
+   if (mem)
+   rproc_coredump_add_segment(rproc, da, rmem->size);
+   else
+   return -ENOMEM;
+
+   rproc_add_carveout(rproc, mem);
+   }
+
+   return  0;
+}
+
+static int imx_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
+{
+   int ret = imx_rproc_parse_memory_regions(rproc);
+
+   if (ret)
+   return ret;
+
+   ret = rproc_elf_load_rsc_table(rproc, fw);
+   if (ret)
+   dev_info(>dev, "No resource table in elf\n");
+
+   return 0;
+}
+
 static const struct rproc_ops imx_rproc_ops = {
.start  = imx_rproc_start,
.stop   = imx_rproc_stop,
.da_to_va   = imx_rproc_da_to_va,
+   .load   = rproc_elf_load_segments,
+   .parse_fw   = imx_rproc_parse_fw,
+   .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table,
+   .sanity_check   = rproc_elf_sanity_check,
+   .get_boot_addr  = rproc_elf_get_boot_addr,
 };
 
 static int imx_rproc_addr_init(struct imx_rproc *priv,
-- 
2.30.0



[PATCH V10 06/10] remoteproc: imx_rproc: use devm_ioremap

2021-02-08 Thread peng . fan
From: Peng Fan 

We might need to map an region multiple times, becaue the region might
be shared between remote processors, such i.MX8QM with dual M4 cores.
So use devm_ioremap, not devm_ioremap_resource.

Reviewed-by: Oleksij Rempel 
Reviewed-by: Richard Zhu 
Signed-off-by: Peng Fan 
Reviewed-by: Mathieu Poirier 
---
 drivers/remoteproc/imx_rproc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 2a093cea4997..47fc1d06be6a 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -296,7 +296,8 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
if (b >= IMX7D_RPROC_MEM_MAX)
break;
 
-   priv->mem[b].cpu_addr = devm_ioremap_resource(>dev, );
+   /* Not use resource version, because we might share region */
+   priv->mem[b].cpu_addr = devm_ioremap(>dev, res.start, 
resource_size());
if (IS_ERR(priv->mem[b].cpu_addr)) {
dev_err(dev, "failed to remap %pr\n", );
err = PTR_ERR(priv->mem[b].cpu_addr);
-- 
2.30.0



[PATCH V10 08/10] remoteproc: imx_rproc: support i.MX8MQ/M

2021-02-08 Thread peng . fan
From: Peng Fan 

Add i.MX8MQ dev/sys addr map and configuration data structure
i.MX8MM share i.MX8MQ settings.

Reviewed-by: Richard Zhu 
Reviewed-by: Mathieu Poirier 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/Kconfig |  6 ++---
 drivers/remoteproc/imx_rproc.c | 41 +-
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
index 9e7efe542f69..86d99229e8ab 100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -24,11 +24,11 @@ config REMOTEPROC_CDEV
  It's safe to say N if you don't want to use this interface.
 
 config IMX_REMOTEPROC
-   tristate "IMX6/7 remoteproc support"
+   tristate "i.MX remoteproc support"
depends on ARCH_MXC
help
- Say y here to support iMX's remote processors (Cortex M4
- on iMX7D) via the remote processor framework.
+ Say y here to support iMX's remote processors via the remote
+ processor framework.
 
  It's safe to say N here.
 
diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 5ae1f5209548..0124ebf69838 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -88,6 +88,34 @@ struct imx_rproc {
struct clk  *clk;
 };
 
+static const struct imx_rproc_att imx_rproc_att_imx8mq[] = {
+   /* dev addr , sys addr  , size  , flags */
+   /* TCML - alias */
+   { 0x, 0x007e, 0x0002, 0 },
+   /* OCRAM_S */
+   { 0x0018, 0x0018, 0x8000, 0 },
+   /* OCRAM */
+   { 0x0090, 0x0090, 0x0002, 0 },
+   /* OCRAM */
+   { 0x0092, 0x0092, 0x0002, 0 },
+   /* QSPI Code - alias */
+   { 0x0800, 0x0800, 0x0800, 0 },
+   /* DDR (Code) - alias */
+   { 0x1000, 0x8000, 0x0FFE, 0 },
+   /* TCML */
+   { 0x1FFE, 0x007E, 0x0002, ATT_OWN },
+   /* TCMU */
+   { 0x2000, 0x0080, 0x0002, ATT_OWN },
+   /* OCRAM_S */
+   { 0x2018, 0x0018, 0x8000, ATT_OWN },
+   /* OCRAM */
+   { 0x2020, 0x0090, 0x0002, ATT_OWN },
+   /* OCRAM */
+   { 0x2022, 0x0092, 0x0002, ATT_OWN },
+   /* DDR (Data) */
+   { 0x4000, 0x4000, 0x8000, 0 },
+};
+
 static const struct imx_rproc_att imx_rproc_att_imx7d[] = {
/* dev addr , sys addr  , size  , flags */
/* OCRAM_S (M4 Boot code) - alias */
@@ -138,6 +166,15 @@ static const struct imx_rproc_att imx_rproc_att_imx6sx[] = 
{
{ 0x8000, 0x8000, 0x6000, 0 },
 };
 
+static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mq = {
+   .src_reg= IMX7D_SRC_SCR,
+   .src_mask   = IMX7D_M4_RST_MASK,
+   .src_start  = IMX7D_M4_START,
+   .src_stop   = IMX7D_M4_STOP,
+   .att= imx_rproc_att_imx8mq,
+   .att_size   = ARRAY_SIZE(imx_rproc_att_imx8mq),
+};
+
 static const struct imx_rproc_dcfg imx_rproc_cfg_imx7d = {
.src_reg= IMX7D_SRC_SCR,
.src_mask   = IMX7D_M4_RST_MASK,
@@ -496,6 +533,8 @@ static int imx_rproc_remove(struct platform_device *pdev)
 static const struct of_device_id imx_rproc_of_match[] = {
{ .compatible = "fsl,imx7d-cm4", .data = _rproc_cfg_imx7d },
{ .compatible = "fsl,imx6sx-cm4", .data = _rproc_cfg_imx6sx },
+   { .compatible = "fsl,imx8mq-cm4", .data = _rproc_cfg_imx8mq },
+   { .compatible = "fsl,imx8mm-cm4", .data = _rproc_cfg_imx8mq },
{},
 };
 MODULE_DEVICE_TABLE(of, imx_rproc_of_match);
@@ -512,5 +551,5 @@ static struct platform_driver imx_rproc_driver = {
 module_platform_driver(imx_rproc_driver);
 
 MODULE_LICENSE("GPL v2");
-MODULE_DESCRIPTION("IMX6SX/7D remote processor control driver");
+MODULE_DESCRIPTION("i.MX remote processor control driver");
 MODULE_AUTHOR("Oleksij Rempel ");
-- 
2.30.0



[PATCH V10 05/10] remoteproc: imx_rproc: correct err message

2021-02-08 Thread peng . fan
From: Peng Fan 

It is using devm_ioremap, so not devm_ioremap_resource. Correct
the error message and print out sa/size.

Reviewed-by: Bjorn Andersson 
Reviewed-by: Mathieu Poirier 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 6603e00bb6f4..2a093cea4997 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -268,7 +268,7 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
priv->mem[b].cpu_addr = devm_ioremap(>dev,
 att->sa, att->size);
if (!priv->mem[b].cpu_addr) {
-   dev_err(dev, "devm_ioremap_resource failed\n");
+   dev_err(dev, "failed to remap %#x bytes from %#x\n", 
att->size, att->sa);
return -ENOMEM;
}
priv->mem[b].sys_addr = att->sa;
@@ -298,7 +298,7 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
 
priv->mem[b].cpu_addr = devm_ioremap_resource(>dev, );
if (IS_ERR(priv->mem[b].cpu_addr)) {
-   dev_err(dev, "devm_ioremap_resource failed\n");
+   dev_err(dev, "failed to remap %pr\n", );
err = PTR_ERR(priv->mem[b].cpu_addr);
return err;
}
-- 
2.30.0



[PATCH V10 04/10] remoteproc: add is_iomem to da_to_va

2021-02-08 Thread peng . fan
From: Peng Fan 

Introduce an extra parameter is_iomem to da_to_va, then the caller
could take the memory as normal memory or io mapped memory.

Reviewed-by: Bjorn Andersson 
Reviewed-by: Mathieu Poirier 
Reported-by: kernel test robot 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c |  2 +-
 drivers/remoteproc/ingenic_rproc.c |  2 +-
 drivers/remoteproc/keystone_remoteproc.c   |  2 +-
 drivers/remoteproc/mtk_scp.c   |  6 +++---
 drivers/remoteproc/omap_remoteproc.c   |  2 +-
 drivers/remoteproc/pru_rproc.c |  2 +-
 drivers/remoteproc/qcom_q6v5_adsp.c|  2 +-
 drivers/remoteproc/qcom_q6v5_pas.c |  2 +-
 drivers/remoteproc/qcom_q6v5_wcss.c|  2 +-
 drivers/remoteproc/qcom_wcnss.c|  2 +-
 drivers/remoteproc/remoteproc_core.c   |  7 +--
 drivers/remoteproc/remoteproc_coredump.c   |  8 ++--
 drivers/remoteproc/remoteproc_debugfs.c|  2 +-
 drivers/remoteproc/remoteproc_elf_loader.c | 21 +++--
 drivers/remoteproc/remoteproc_internal.h   |  2 +-
 drivers/remoteproc/st_slim_rproc.c |  2 +-
 drivers/remoteproc/ti_k3_dsp_remoteproc.c  |  2 +-
 drivers/remoteproc/ti_k3_r5_remoteproc.c   |  2 +-
 drivers/remoteproc/wkup_m3_rproc.c |  2 +-
 include/linux/remoteproc.h |  2 +-
 20 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 8957ed271d20..6603e00bb6f4 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -208,7 +208,7 @@ static int imx_rproc_da_to_sys(struct imx_rproc *priv, u64 
da,
return -ENOENT;
 }
 
-static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool 
*is_iomem)
 {
struct imx_rproc *priv = rproc->priv;
void *va = NULL;
diff --git a/drivers/remoteproc/ingenic_rproc.c 
b/drivers/remoteproc/ingenic_rproc.c
index 26e19e6143b7..bb5049295576 100644
--- a/drivers/remoteproc/ingenic_rproc.c
+++ b/drivers/remoteproc/ingenic_rproc.c
@@ -116,7 +116,7 @@ static void ingenic_rproc_kick(struct rproc *rproc, int 
vqid)
writel(vqid, vpu->aux_base + REG_CORE_MSG);
 }
 
-static void *ingenic_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *ingenic_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, 
bool *is_iomem)
 {
struct vpu *vpu = rproc->priv;
void __iomem *va = NULL;
diff --git a/drivers/remoteproc/keystone_remoteproc.c 
b/drivers/remoteproc/keystone_remoteproc.c
index cd266163a65f..54781f553f4e 100644
--- a/drivers/remoteproc/keystone_remoteproc.c
+++ b/drivers/remoteproc/keystone_remoteproc.c
@@ -246,7 +246,7 @@ static void keystone_rproc_kick(struct rproc *rproc, int 
vqid)
  * can be used either by the remoteproc core for loading (when using kernel
  * remoteproc loader), or by any rpmsg bus drivers.
  */
-static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, 
bool *is_iomem)
 {
struct keystone_rproc *ksproc = rproc->priv;
void __iomem *va = NULL;
diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c
index e0c235690361..535175f013e4 100644
--- a/drivers/remoteproc/mtk_scp.c
+++ b/drivers/remoteproc/mtk_scp.c
@@ -270,7 +270,7 @@ static int scp_elf_load_segments(struct rproc *rproc, const 
struct firmware *fw)
}
 
/* grab the kernel address for this device address */
-   ptr = (void __iomem *)rproc_da_to_va(rproc, da, memsz);
+   ptr = (void __iomem *)rproc_da_to_va(rproc, da, memsz, NULL);
if (!ptr) {
dev_err(dev, "bad phdr da 0x%x mem 0x%x\n", da, memsz);
ret = -EINVAL;
@@ -458,7 +458,7 @@ static int scp_start(struct rproc *rproc)
return ret;
 }
 
-static void *scp_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *scp_da_to_va(struct rproc *rproc, u64 da, size_t len, bool 
*is_iomem)
 {
struct mtk_scp *scp = (struct mtk_scp *)rproc->priv;
int offset;
@@ -587,7 +587,7 @@ void *scp_mapping_dm_addr(struct mtk_scp *scp, u32 mem_addr)
 {
void *ptr;
 
-   ptr = scp_da_to_va(scp->rproc, mem_addr, 0);
+   ptr = scp_da_to_va(scp->rproc, mem_addr, 0, NULL);
if (!ptr)
return ERR_PTR(-EINVAL);
 
diff --git a/drivers/remoteproc/omap_remoteproc.c 
b/drivers/remoteproc/omap_remoteproc.c
index d94b7391bf9d..43531caa1959 100644
--- a/drivers/remoteproc/omap_remoteproc.c
+++ b/drivers/remoteproc/omap_remoteproc.c
@@ -728,7 +728,7 @@ static int omap_rproc_stop(struct rproc *rproc)
  * Return: translated virtual address in kernel memory space on success,
  * or NULL on failure.
  */
-static void *omap_rproc_da_to_va(struct r

[PATCH V10 03/10] remoteproc: introduce is_iomem to rproc_mem_entry

2021-02-08 Thread peng . fan
From: Peng Fan 

Introduce is_iomem to indicate this piece memory is iomem or not.

Reviewed-by: Bjorn Andersson 
Signed-off-by: Peng Fan 
Reviewed-by: Mathieu Poirier 
---
 include/linux/remoteproc.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index f28ee75d1005..a5f6d2d9cde2 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -315,6 +315,7 @@ struct rproc;
 /**
  * struct rproc_mem_entry - memory entry descriptor
  * @va:virtual address
+ * @is_iomem: io memory
  * @dma: dma address
  * @len: length, in bytes
  * @da: device address
@@ -329,6 +330,7 @@ struct rproc;
  */
 struct rproc_mem_entry {
void *va;
+   bool is_iomem;
dma_addr_t dma;
size_t len;
u32 da;
-- 
2.30.0



[PATCH V10 02/10] dt-bindings: remoteproc: imx_rproc: add i.MX8MQ/M support

2021-02-08 Thread peng . fan
From: Peng Fan 

Add i.MX8MQ/M support, also include mailbox for rpmsg/virtio usage.

Signed-off-by: Peng Fan 
---
 .../bindings/remoteproc/fsl,imx-rproc.yaml| 51 ++-
 1 file changed, 50 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml 
b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
index 5e906fa6a39d..d692077c65cf 100644
--- a/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
+++ b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
@@ -4,7 +4,7 @@
 $id: "http://devicetree.org/schemas/remoteproc/fsl,imx-rproc.yaml#;
 $schema: "http://devicetree.org/meta-schemas/core.yaml#;
 
-title: NXP iMX6SX/iMX7D Co-Processor Bindings
+title: NXP i.MX Co-Processor Bindings
 
 description:
   This binding provides support for ARM Cortex M4 Co-processor found on some 
NXP iMX SoCs.
@@ -15,6 +15,8 @@ maintainers:
 properties:
   compatible:
 enum:
+  - fsl,imx8mq-cm4
+  - fsl,imx8mm-cm4
   - fsl,imx7d-cm4
   - fsl,imx6sx-cm4
 
@@ -26,6 +28,20 @@ properties:
 description:
   Phandle to syscon block which provide access to System Reset Controller
 
+  mbox-names:
+items:
+  - const: tx
+  - const: rx
+  - const: rxdb
+
+  mboxes:
+description:
+  This property is required only if the rpmsg/virtio functionality is used.
+  List of < type channel> - 1 channel for TX, 1 channel for RX, 1 
channel for RXDB.
+  (see mailbox/fsl,mu.yaml)
+minItems: 1
+maxItems: 3
+
   memory-region:
 description:
   If present, a phandle for a reserved memory area that used for vdev 
buffer,
@@ -56,4 +72,37 @@ examples:
   clocks   = < IMX7D_ARM_M4_ROOT_CLK>;
 };
 
+  - |
+#include 
+rsc_table: rsc_table@550ff000 {
+  no-map;
+  reg = <0x550ff000 0x1000>;
+};
+
+vdev0vring0: vdev0vring0@5500 {
+  no-map;
+  reg = <0x5500 0x8000>;
+};
+
+vdev0vring1: vdev0vring1@55008000 {
+  reg = <0x55008000 0x8000>;
+  no-map;
+};
+
+vdev0buffer: vdev0buffer@5540 {
+  compatible = "shared-dma-pool";
+  reg = <0x5540 0x10>;
+  no-map;
+};
+
+imx8mm-cm4 {
+  compatible = "fsl,imx8mm-cm4";
+  clocks = < IMX8MM_CLK_M4_DIV>;
+  mbox-names = "tx", "rx", "rxdb";
+  mboxes = < 0 1
+ 1 1
+ 3 1>;
+  memory-region = <>, <>, <>, 
<_table>;
+  syscon = <>;
+};
 ...
-- 
2.30.0



[PATCH V10 01/10] dt-bindings: remoteproc: convert imx rproc bindings to json-schema

2021-02-08 Thread peng . fan
From: Peng Fan 

Convert the imx rproc binding to DT schema format using json-schema.

Signed-off-by: Peng Fan 
---
 .../bindings/remoteproc/fsl,imx-rproc.yaml| 59 +++
 .../bindings/remoteproc/imx-rproc.txt | 33 ---
 2 files changed, 59 insertions(+), 33 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
 delete mode 100644 Documentation/devicetree/bindings/remoteproc/imx-rproc.txt

diff --git a/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml 
b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
new file mode 100644
index ..5e906fa6a39d
--- /dev/null
+++ b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/remoteproc/fsl,imx-rproc.yaml#;
+$schema: "http://devicetree.org/meta-schemas/core.yaml#;
+
+title: NXP iMX6SX/iMX7D Co-Processor Bindings
+
+description:
+  This binding provides support for ARM Cortex M4 Co-processor found on some 
NXP iMX SoCs.
+
+maintainers:
+  - Peng Fan 
+
+properties:
+  compatible:
+enum:
+  - fsl,imx7d-cm4
+  - fsl,imx6sx-cm4
+
+  clocks:
+maxItems: 1
+
+  syscon:
+$ref: /schemas/types.yaml#/definitions/phandle
+description:
+  Phandle to syscon block which provide access to System Reset Controller
+
+  memory-region:
+description:
+  If present, a phandle for a reserved memory area that used for vdev 
buffer,
+  resource table, vring region and others used by remote processor.
+
+required:
+  - compatible
+  - clocks
+  - syscon
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+m4_reserved_sysmem1: cm4@8000 {
+  reg = <0x8000 0x8>;
+};
+
+m4_reserved_sysmem2: cm4@8100 {
+  reg = <0x8100 0x8>;
+};
+
+imx7d-cm4 {
+  compatible   = "fsl,imx7d-cm4";
+  memory-region= <_reserved_sysmem1>, <_reserved_sysmem2>;
+  syscon   = <>;
+  clocks   = < IMX7D_ARM_M4_ROOT_CLK>;
+};
+
+...
diff --git a/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt 
b/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt
deleted file mode 100644
index fbcefd965dc4..
--- a/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-NXP iMX6SX/iMX7D Co-Processor Bindings
-
-
-This binding provides support for ARM Cortex M4 Co-processor found on some
-NXP iMX SoCs.
-
-Required properties:
-- compatible   Should be one of:
-   "fsl,imx7d-cm4"
-   "fsl,imx6sx-cm4"
-- clocks   Clock for co-processor (See: 
../clock/clock-bindings.txt)
-- syscon   Phandle to syscon block which provide access to
-   System Reset Controller
-
-Optional properties:
-- memory-regionlist of phandels to the reserved memory regions.
-   (See: ../reserved-memory/reserved-memory.txt)
-
-Example:
-   m4_reserved_sysmem1: cm4@8000 {
-   reg = <0x8000 0x8>;
-   };
-
-   m4_reserved_sysmem2: cm4@8100 {
-   reg = <0x8100 0x8>;
-   };
-
-   imx7d-cm4 {
-   compatible  = "fsl,imx7d-cm4";
-   memory-region   = <_reserved_sysmem1>, 
<_reserved_sysmem2>;
-   syscon  = <>;
-   clocks  = < IMX7D_ARM_M4_ROOT_CLK>;
-   };
-- 
2.30.0



[PATCH V10 00/10] remoteproc: imx_rproc: support iMX8MQ/M

2021-02-08 Thread peng . fan
From: Peng Fan 

V10:
 Per Rob's comments, fix patch 1/10

V9:
 Per Mathieu's comments,
   update the tile of yaml in patch 2/10
   update the Kconfig and MODULE_DESCRIPTION, I merge this change in patch 8/10,
   since this is a minor change, I still keep Mathieu's R-b tag. If any 
objection, I could remove.
   Add R-b tag in Patch 10/10

 Rob, please help review patch 1/10 and 2/10

V8:
 Address sparse warning in patch 4/10 reported by kernel test robot

V7:
 Add R-b tag from Mathieu
 vdevbuffer->vdev0buffer in patch 1/10, 7/10
 correct err msg and shutdown seq per Mathieu's comments in patch 10/10
 Hope this version is ok to be merged.
 
V6:
 Add R-b tag from Mathieu
 Convert imx-rproc.txt to yaml and add dt-bindings support for i.MX8MQ/M, patch 
1/10 2/10
 No other changes.

V5:
 Apply on Linux next
 Add V5 subject prefix
 Add R-b tag from Bjorn for 1/8, 2/8, 3/8
 
https://patchwork.kernel.org/project/linux-remoteproc/cover/20201229033019.25899-1-peng@nxp.com/

V4:
 According to Bjorn's comments, add is_iomem for da to va usage
 1/8, 2/8 is new patch
 3/8, follow Bjorn's comments to correct/update the err msg.
 6/8, new patch
 8/8, use dev_err_probe to simplify code, use queue_work instead 
schedule_delayed_work

V3:
 Since I was quite busy in the past days, V3 is late
 Rebased on Linux-next
 Add R-b tags
 1/7: Add R-b tag of Mathieu, add comments
 4/7: Typo fix
 5/7: Add R-b tag of Mathieu, drop index Per Mathieu's comments
 6/7: Add R-b tag of Mathieu
 7/7: Add comment for vqid << 16, drop unneeded timeout settings of mailbox
  Use queue_work instead of schedule_delayed_work
  free mbox channels when remove
 https://lkml.org/lkml/2020/12/4/82

V2:
 Rebased on linux-next
 Dropped early boot feature to make patchset simple.
 Drop rsc-da
 
https://patchwork.kernel.org/project/linux-remoteproc/cover/20200927064131.24101-1-peng@nxp.com/

V1:
 https://patchwork.kernel.org/cover/11682461/

This patchset is to support i.MX8MQ/M coproc.
The early boot feature was dropped to make the patchset small in V2.

Since i.MX specific TCM memory requirement, add elf platform hook.
Several patches have got reviewed by Oleksij and Mathieu in v1.


Peng Fan (10):
  dt-bindings: remoteproc: convert imx rproc bindings to json-schema
  dt-bindings: remoteproc: imx_rproc: add i.MX8MQ/M support
  remoteproc: introduce is_iomem to rproc_mem_entry
  remoteproc: add is_iomem to da_to_va
  remoteproc: imx_rproc: correct err message
  remoteproc: imx_rproc: use devm_ioremap
  remoteproc: imx_rproc: add i.MX specific parse fw hook
  remoteproc: imx_rproc: support i.MX8MQ/M
  remoteproc: imx_rproc: ignore mapping vdev regions
  remoteproc: imx_proc: enable virtio/mailbox

 .../bindings/remoteproc/fsl,imx-rproc.yaml| 108 
 .../bindings/remoteproc/imx-rproc.txt |  33 ---
 drivers/remoteproc/Kconfig|   6 +-
 drivers/remoteproc/imx_rproc.c| 262 +-
 drivers/remoteproc/ingenic_rproc.c|   2 +-
 drivers/remoteproc/keystone_remoteproc.c  |   2 +-
 drivers/remoteproc/mtk_scp.c  |   6 +-
 drivers/remoteproc/omap_remoteproc.c  |   2 +-
 drivers/remoteproc/pru_rproc.c|   2 +-
 drivers/remoteproc/qcom_q6v5_adsp.c   |   2 +-
 drivers/remoteproc/qcom_q6v5_pas.c|   2 +-
 drivers/remoteproc/qcom_q6v5_wcss.c   |   2 +-
 drivers/remoteproc/qcom_wcnss.c   |   2 +-
 drivers/remoteproc/remoteproc_core.c  |   7 +-
 drivers/remoteproc/remoteproc_coredump.c  |   8 +-
 drivers/remoteproc/remoteproc_debugfs.c   |   2 +-
 drivers/remoteproc/remoteproc_elf_loader.c|  21 +-
 drivers/remoteproc/remoteproc_internal.h  |   2 +-
 drivers/remoteproc/st_slim_rproc.c|   2 +-
 drivers/remoteproc/ti_k3_dsp_remoteproc.c |   2 +-
 drivers/remoteproc/ti_k3_r5_remoteproc.c  |   2 +-
 drivers/remoteproc/wkup_m3_rproc.c|   2 +-
 include/linux/remoteproc.h|   4 +-
 23 files changed, 411 insertions(+), 72 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
 delete mode 100644 Documentation/devicetree/bindings/remoteproc/imx-rproc.txt

-- 
2.30.0



RE: [PATCH V2 0/4] imx esdhc dt/driver update

2021-02-07 Thread Peng Fan
> Subject: [PATCH V2 0/4] imx esdhc dt/driver update

Gentle ping..

Thanks,
Peng.

> 
> From: Peng Fan 
> 
> Patch V2:
>  patch 1, 2, 3 is new
>  patch 4 is not changed
> 
> Peng Fan (4):
>   dt-bindings: mmc: fsl-imx-esdhc: add pinctrl bindings
>   dt-bindings: mmc: fsl-imx-esdhc: add clock bindings
>   arm64: dts: imx8qxp: correct usdhc clock-names sequence
>   mmc: sdhci-esdhc-imx: validate pinctrl before use it
> 
>  .../bindings/mmc/fsl-imx-esdhc.yaml   | 36
> +++
>  arch/arm64/boot/dts/freescale/imx8qxp.dtsi| 18 +-
>  drivers/mmc/host/sdhci-esdhc-imx.c|  2 +-
>  3 files changed, 46 insertions(+), 10 deletions(-)
> 
> --
> 2.28.0



RE: [PATCH V9 01/10] dt-bindings: remoteproc: convert imx rproc bindings to json-schema

2021-01-26 Thread Peng Fan
Hi Rob,

> Subject: [PATCH V9 01/10] dt-bindings: remoteproc: convert imx rproc
> bindings to json-schema

Do you have time to give a look and including
https://patchwork.kernel.org/project/linux-remoteproc/
patch/1611191015-22584-3-git-send-email-peng@nxp.com/

If could get your R-b or A-b tag, we could have the whole patchset
merge into remoteproc tree.

Thanks,
Peng.

> 
> From: Peng Fan 
> 
> Convert the imx rproc binding to DT schema format using json-schema.
> 
> Signed-off-by: Peng Fan 
> ---
>  .../bindings/remoteproc/fsl,imx-rproc.yaml| 59 +++
>  .../bindings/remoteproc/imx-rproc.txt | 33 ---
>  2 files changed, 59 insertions(+), 33 deletions(-)  create mode 100644
> Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
>  delete mode 100644
> Documentation/devicetree/bindings/remoteproc/imx-rproc.txt
> 
> diff --git
> a/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
> b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
> new file mode 100644
> index ..bce6ccfe1538
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
> @@ -0,0 +1,59 @@
> +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) %YAML 1.2
> +---
> +$id: "http://devicetree.org/schemas/remoteproc/fsl,imx-rproc.yaml#;
> +$schema: "http://devicetree.org/meta-schemas/core.yaml#;
> +
> +title: NXP iMX6SX/iMX7D Co-Processor Bindings
> +
> +description:
> +  This binding provides support for ARM Cortex M4 Co-processor found on
> some NXP iMX SoCs.
> +
> +maintainers:
> +  - Peng Fan 
> +
> +properties:
> +  compatible:
> +enum:
> +  - fsl,imx7d-cm4
> +  - fsl,imx6sx-cm4
> +
> +  clocks:
> +description:
> +  Clock for co-processor (See ../clock/clock-bindings.txt)
> +
> +  syscon:
> +description:
> +  Phandle to syscon block which provide access to System Reset
> + Controller
> +
> +  memory-region:
> +description:
> +  list of phandels to the reserved memory regions.
> +  (see ../reserved-memory/reserved-memory.txt)
> +
> +required:
> +  - compatible
> +  - clocks
> +  - syscon
> +
> +additionalProperties: false
> +
> +examples:
> +  - |
> +#include 
> +m4_reserved_sysmem1: cm4@8000 {
> +  reg = <0x8000 0x8>;
> +};
> +
> +m4_reserved_sysmem2: cm4@8100 {
> +  reg = <0x8100 0x8>;
> +};
> +
> +imx7d-cm4 {
> +  compatible = "fsl,imx7d-cm4";
> +  memory-region  = <_reserved_sysmem1>,
> <_reserved_sysmem2>;
> +  syscon = <>;
> +  clocks = < IMX7D_ARM_M4_ROOT_CLK>;
> +};
> +
> +...
> diff --git a/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt
> b/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt
> deleted file mode 100644
> index fbcefd965dc4..
> --- a/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt
> +++ /dev/null
> @@ -1,33 +0,0 @@
> -NXP iMX6SX/iMX7D Co-Processor Bindings
> -
> -
> -This binding provides support for ARM Cortex M4 Co-processor found on
> some -NXP iMX SoCs.
> -
> -Required properties:
> -- compatible Should be one of:
> - "fsl,imx7d-cm4"
> - "fsl,imx6sx-cm4"
> -- clocks Clock for co-processor (See: 
> ../clock/clock-bindings.txt)
> -- syscon Phandle to syscon block which provide access to
> - System Reset Controller
> -
> -Optional properties:
> -- memory-region  list of phandels to the reserved memory regions.
> - (See: ../reserved-memory/reserved-memory.txt)
> -
> -Example:
> - m4_reserved_sysmem1: cm4@8000 {
> - reg = <0x8000 0x8>;
> - };
> -
> - m4_reserved_sysmem2: cm4@8100 {
> - reg = <0x8100 0x8>;
> - };
> -
> - imx7d-cm4 {
> - compatible  = "fsl,imx7d-cm4";
> - memory-region   = <_reserved_sysmem1>,
> <_reserved_sysmem2>;
> - syscon  = <>;
> - clocks  = < IMX7D_ARM_M4_ROOT_CLK>;
> - };
> --
> 2.28.0



RE: [PATCH V2 2/4] dt-bindings: mmc: fsl-imx-esdhc: add clock bindings

2021-01-21 Thread Peng Fan
Hi Rob,

> Subject: Re: [PATCH V2 2/4] dt-bindings: mmc: fsl-imx-esdhc: add clock
> bindings
> 
> On Thu, 21 Jan 2021 11:09:51 +0800, peng@nxp.com wrote:
> > From: Peng Fan 
> >
> > Add clock bindings for fsl-imx-esdhc yaml
> >
> > Signed-off-by: Peng Fan 
> > ---
> >  .../devicetree/bindings/mmc/fsl-imx-esdhc.yaml| 11
> +++
> >  1 file changed, 11 insertions(+)
> >
> 
> My bot found errors running 'make dt_binding_check' on your patch:

Patch 3/4 addresses the dts, actually I think it is the dts not use correct
clock order.

Thanks,
Peng.

> 
> yamllint warnings/errors:
> 
> dtschema/dtc warnings/errors:
> /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/clock
> /imx8qxp-lpcg.example.dt.yaml: mmc@5b01: clock-names:1: 'ahb' was
> expected
>   From schema:
> /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mmc
> /fsl-imx-esdhc.yaml
> /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/clock
> /imx8qxp-lpcg.example.dt.yaml: mmc@5b01: clock-names:2: 'per' was
> expected
>   From schema:
> /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mmc
> /fsl-imx-esdhc.yaml
> 
> See
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatch
> work.ozlabs.org%2Fpatch%2F1429619data=04%7C01%7Cpeng.fan%40
> nxp.com%7Cc543c002a0b54348d48408d8be25ec0b%7C686ea1d3bc2b4c6fa
> 92cd99c5c301635%7C0%7C0%7C637468417375412086%7CUnknown%7CT
> WFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLC
> JXVCI6Mn0%3D%7C1000sdata=cISWAn3kYIoqvxr39Mu5NL6rwkebmk
> VN1drRi%2BDNwAs%3Dreserved=0
> 
> This check can fail if there are any dependencies. The base for a patch series
> is generally the most recent rc1.
> 
> If you already ran 'make dt_binding_check' and didn't see the above error(s),
> then make sure 'yamllint' is installed and dt-schema is up to
> date:
> 
> pip3 install dtschema --upgrade
> 
> Please check and re-submit.



[PATCH V2 2/4] dt-bindings: mmc: fsl-imx-esdhc: add clock bindings

2021-01-20 Thread peng . fan
From: Peng Fan 

Add clock bindings for fsl-imx-esdhc yaml

Signed-off-by: Peng Fan 
---
 .../devicetree/bindings/mmc/fsl-imx-esdhc.yaml| 11 +++
 1 file changed, 11 insertions(+)

diff --git a/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.yaml 
b/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.yaml
index f91e97cd7d4e..c42a3880abf0 100644
--- a/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.yaml
+++ b/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.yaml
@@ -103,6 +103,17 @@ properties:
   Only eMMC HS400 mode need to take care of this property.
 default: 0
 
+  clocks:
+maxItems: 3
+description:
+  Handle clocks for the sdhc controller.
+
+  clock-names:
+items:
+  - const: ipg
+  - const: ahb
+  - const: per
+
   pinctrl-0:
 minItems: 1
 maxItems: 2
-- 
2.28.0



[PATCH V2 3/4] arm64: dts: imx8qxp: correct usdhc clock-names sequence

2021-01-20 Thread peng . fan
From: Peng Fan 

Per dt-bindings, the clock-names sequence should be ipg ahb per to pass
dtbs_check.

Signed-off-by: Peng Fan 
---
 arch/arm64/boot/dts/freescale/imx8qxp.dtsi | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/arch/arm64/boot/dts/freescale/imx8qxp.dtsi 
b/arch/arm64/boot/dts/freescale/imx8qxp.dtsi
index e46faac1fe71..1d522de7b017 100644
--- a/arch/arm64/boot/dts/freescale/imx8qxp.dtsi
+++ b/arch/arm64/boot/dts/freescale/imx8qxp.dtsi
@@ -366,9 +366,9 @@ usdhc1: mmc@5b01 {
interrupts = ;
reg = <0x5b01 0x1>;
clocks = <_lpcg IMX_CONN_LPCG_SDHC0_IPG_CLK>,
-<_lpcg IMX_CONN_LPCG_SDHC0_PER_CLK>,
-<_lpcg IMX_CONN_LPCG_SDHC0_HCLK>;
-   clock-names = "ipg", "per", "ahb";
+<_lpcg IMX_CONN_LPCG_SDHC0_HCLK>,
+<_lpcg IMX_CONN_LPCG_SDHC0_PER_CLK>;
+   clock-names = "ipg", "ahb", "per";
power-domains = < IMX_SC_R_SDHC_0>;
status = "disabled";
};
@@ -378,9 +378,9 @@ usdhc2: mmc@5b02 {
interrupts = ;
reg = <0x5b02 0x1>;
clocks = <_lpcg IMX_CONN_LPCG_SDHC1_IPG_CLK>,
-<_lpcg IMX_CONN_LPCG_SDHC1_PER_CLK>,
-<_lpcg IMX_CONN_LPCG_SDHC1_HCLK>;
-   clock-names = "ipg", "per", "ahb";
+<_lpcg IMX_CONN_LPCG_SDHC1_HCLK>,
+<_lpcg IMX_CONN_LPCG_SDHC1_PER_CLK>;
+   clock-names = "ipg", "ahb", "per";
power-domains = < IMX_SC_R_SDHC_1>;
fsl,tuning-start-tap = <20>;
fsl,tuning-step= <2>;
@@ -392,9 +392,9 @@ usdhc3: mmc@5b03 {
interrupts = ;
reg = <0x5b03 0x1>;
clocks = <_lpcg IMX_CONN_LPCG_SDHC2_IPG_CLK>,
-<_lpcg IMX_CONN_LPCG_SDHC2_PER_CLK>,
-<_lpcg IMX_CONN_LPCG_SDHC2_HCLK>;
-   clock-names = "ipg", "per", "ahb";
+<_lpcg IMX_CONN_LPCG_SDHC2_HCLK>,
+<_lpcg IMX_CONN_LPCG_SDHC2_PER_CLK>;
+   clock-names = "ipg", "ahb", "per";
power-domains = < IMX_SC_R_SDHC_2>;
status = "disabled";
};
-- 
2.28.0



[PATCH V2 1/4] dt-bindings: mmc: fsl-imx-esdhc: add pinctrl bindings

2021-01-20 Thread peng . fan
From: Peng Fan 

Add pinctrl bindings for fsl-imx-esdhc yaml

Signed-off-by: Peng Fan 
---
 .../bindings/mmc/fsl-imx-esdhc.yaml   | 25 +++
 1 file changed, 25 insertions(+)

diff --git a/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.yaml 
b/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.yaml
index 802c9df23752..f91e97cd7d4e 100644
--- a/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.yaml
+++ b/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.yaml
@@ -103,6 +103,31 @@ properties:
   Only eMMC HS400 mode need to take care of this property.
 default: 0
 
+  pinctrl-0:
+minItems: 1
+maxItems: 2
+
+  pinctrl-1:
+minItems: 1
+maxItems: 2
+
+  pinctrl-2:
+minItems: 1
+maxItems: 2
+
+  pinctrl-3:
+minItems: 1
+maxItems: 2
+
+  pinctrl-names:
+minItems: 1
+maxItems: 4
+items:
+  - const: default
+  - const: state_100mhz
+  - const: state_200mhz
+  - const: sleep
+
 required:
   - compatible
   - reg
-- 
2.28.0



[PATCH V2 4/4] mmc: sdhci-esdhc-imx: validate pinctrl before use it

2021-01-20 Thread peng . fan
From: Peng Fan 

When imx_data->pinctrl is not a valid pointer, pinctrl_lookup_state
will trigger kernel panic.

When we boot Dual OS on Jailhouse hypervisor, we let the 1st Linux to
configure pinmux ready for the 2nd OS, so the 2nd OS not have pinctrl
settings.

Similar to this commit b62eee9f804e ("mmc: sdhci-esdhc-imx: no fail when no 
pinctrl available").

Reviewed-by: Bough Chen 
Reviewed-by: Alice Guo 
Signed-off-by: Peng Fan 
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index 16ed19f47939..11d3a2244b36 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -1488,7 +1488,7 @@ sdhci_esdhc_imx_probe_dt(struct platform_device *pdev,
 
mmc_of_parse_voltage(np, >ocr_mask);
 
-   if (esdhc_is_usdhc(imx_data)) {
+   if (esdhc_is_usdhc(imx_data) && !IS_ERR(imx_data->pinctrl)) {
imx_data->pins_100mhz = pinctrl_lookup_state(imx_data->pinctrl,
ESDHC_PINCTRL_STATE_100MHZ);
imx_data->pins_200mhz = pinctrl_lookup_state(imx_data->pinctrl,
-- 
2.28.0



[PATCH V2 0/4] imx esdhc dt/driver update

2021-01-20 Thread peng . fan
From: Peng Fan 

Patch V2:
 patch 1, 2, 3 is new
 patch 4 is not changed

Peng Fan (4):
  dt-bindings: mmc: fsl-imx-esdhc: add pinctrl bindings
  dt-bindings: mmc: fsl-imx-esdhc: add clock bindings
  arm64: dts: imx8qxp: correct usdhc clock-names sequence
  mmc: sdhci-esdhc-imx: validate pinctrl before use it

 .../bindings/mmc/fsl-imx-esdhc.yaml   | 36 +++
 arch/arm64/boot/dts/freescale/imx8qxp.dtsi| 18 +-
 drivers/mmc/host/sdhci-esdhc-imx.c|  2 +-
 3 files changed, 46 insertions(+), 10 deletions(-)

-- 
2.28.0



RE: [PATCH V8 10/10] remoteproc: imx_proc: enable virtio/mailbox

2021-01-20 Thread Peng Fan
> Subject: Re: [PATCH V8 10/10] remoteproc: imx_proc: enable virtio/mailbox
> 
> On Tue, Jan 19, 2021 at 03:35:11PM +0800, peng@nxp.com wrote:
> > From: Peng Fan 
> >
> > Use virtio/mailbox to build connection between Remote Proccessors and
> > Linux. Add work queue to handle incoming messages.
> >
> > Reviewed-by: Richard Zhu 
> > Signed-off-by: Peng Fan 
> > ---
> >  drivers/remoteproc/imx_rproc.c | 116
> > -
> >  1 file changed, 113 insertions(+), 3 deletions(-)
> 
> Reviewed-by: Mathieu Poirier 
> 
> I will pickup this set when Rob has reviewed the DT bindings.  In the mean
> time you might want to fix the title section in the the .yaml file, the 
> Kconfig
> and the MODULE_DESCRIPTION and add a reference to i.MX8.

Thanks for your reviewing efforts.

I have updated patch 2, 8 in v9 to address the issue you mentioned.

Thanks,
Peng.

> 
> Thanks,
> Mathieu
> 
> >
> > diff --git a/drivers/remoteproc/imx_rproc.c
> > b/drivers/remoteproc/imx_rproc.c index 54ac143ba033..c16a91f8e410
> > 100644
> > --- a/drivers/remoteproc/imx_rproc.c
> > +++ b/drivers/remoteproc/imx_rproc.c
> > @@ -7,6 +7,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -15,6 +16,9 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> > +
> > +#include "remoteproc_internal.h"
> >
> >  #define IMX7D_SRC_SCR  0x0C
> >  #define IMX7D_ENABLE_M4BIT(3)
> > @@ -86,6 +90,11 @@ struct imx_rproc {
> > const struct imx_rproc_dcfg *dcfg;
> > struct imx_rproc_memmem[IMX7D_RPROC_MEM_MAX];
> > struct clk  *clk;
> > +   struct mbox_client  cl;
> > +   struct mbox_chan*tx_ch;
> > +   struct mbox_chan*rx_ch;
> > +   struct work_struct  rproc_work;
> > +   struct workqueue_struct *workqueue;
> >  };
> >
> >  static const struct imx_rproc_att imx_rproc_att_imx8mq[] = { @@
> > -366,9 +375,33 @@ static int imx_rproc_parse_fw(struct rproc *rproc,
> const struct firmware *fw)
> > return 0;
> >  }
> >
> > +static void imx_rproc_kick(struct rproc *rproc, int vqid) {
> > +   struct imx_rproc *priv = rproc->priv;
> > +   int err;
> > +   __u32 mmsg;
> > +
> > +   if (!priv->tx_ch) {
> > +   dev_err(priv->dev, "No initialized mbox tx channel\n");
> > +   return;
> > +   }
> > +
> > +   /*
> > +* Send the index of the triggered virtqueue as the mu payload.
> > +* Let remote processor know which virtqueue is used.
> > +*/
> > +   mmsg = vqid << 16;
> > +
> > +   err = mbox_send_message(priv->tx_ch, (void *));
> > +   if (err < 0)
> > +   dev_err(priv->dev, "%s: failed (%d, err:%d)\n",
> > +   __func__, vqid, err);
> > +}
> > +
> >  static const struct rproc_ops imx_rproc_ops = {
> > .start  = imx_rproc_start,
> > .stop   = imx_rproc_stop,
> > +   .kick   = imx_rproc_kick,
> > .da_to_va   = imx_rproc_da_to_va,
> > .load   = rproc_elf_load_segments,
> > .parse_fw   = imx_rproc_parse_fw,
> > @@ -444,6 +477,66 @@ static int imx_rproc_addr_init(struct imx_rproc
> *priv,
> > return 0;
> >  }
> >
> > +static void imx_rproc_vq_work(struct work_struct *work) {
> > +   struct imx_rproc *priv = container_of(work, struct imx_rproc,
> > + rproc_work);
> > +
> > +   rproc_vq_interrupt(priv->rproc, 0);
> > +   rproc_vq_interrupt(priv->rproc, 1);
> > +}
> > +
> > +static void imx_rproc_rx_callback(struct mbox_client *cl, void *msg)
> > +{
> > +   struct rproc *rproc = dev_get_drvdata(cl->dev);
> > +   struct imx_rproc *priv = rproc->priv;
> > +
> > +   queue_work(priv->workqueue, >rproc_work); }
> > +
> > +static int imx_rproc_xtr_mbox_init(struct rproc *rproc) {
> > +   struct imx_rproc *priv = rproc->priv;
> > +   struct device *dev = priv->dev;
> > +   struct mbox_client *cl;
> > +   int ret;
> > +
> > +   if (!of_get_property(dev->of_node, "mbox-names", NULL))
> > +   return 0;
> > +
> > +   cl = >cl;
> > +   cl->dev = dev;
> > +   cl->tx_block = true;

[PATCH V9 09/10] remoteproc: imx_rproc: ignore mapping vdev regions

2021-01-20 Thread peng . fan
From: Peng Fan 

vdev regions are vdev0vring0, vdev0vring1, vdevbuffer and similar.
They are handled by remoteproc common code, no need to map in imx
rproc driver.

Signed-off-by: Peng Fan 
Reviewed-by: Mathieu Poirier 
---
 drivers/remoteproc/imx_rproc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 0124ebf69838..3685bbd135b0 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -417,6 +417,9 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
struct resource res;
 
node = of_parse_phandle(np, "memory-region", a);
+   /* Not map vdev region */
+   if (!strcmp(node->name, "vdev"))
+   continue;
err = of_address_to_resource(node, 0, );
if (err) {
dev_err(dev, "unable to resolve memory region\n");
-- 
2.28.0



[PATCH V9 08/10] remoteproc: imx_rproc: support i.MX8MQ/M

2021-01-20 Thread peng . fan
From: Peng Fan 

Add i.MX8MQ dev/sys addr map and configuration data structure
i.MX8MM share i.MX8MQ settings.

Reviewed-by: Richard Zhu 
Reviewed-by: Mathieu Poirier 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/Kconfig |  6 ++---
 drivers/remoteproc/imx_rproc.c | 41 +-
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
index 9e7efe542f69..86d99229e8ab 100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -24,11 +24,11 @@ config REMOTEPROC_CDEV
  It's safe to say N if you don't want to use this interface.
 
 config IMX_REMOTEPROC
-   tristate "IMX6/7 remoteproc support"
+   tristate "i.MX remoteproc support"
depends on ARCH_MXC
help
- Say y here to support iMX's remote processors (Cortex M4
- on iMX7D) via the remote processor framework.
+ Say y here to support iMX's remote processors via the remote
+ processor framework.
 
  It's safe to say N here.
 
diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 5ae1f5209548..0124ebf69838 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -88,6 +88,34 @@ struct imx_rproc {
struct clk  *clk;
 };
 
+static const struct imx_rproc_att imx_rproc_att_imx8mq[] = {
+   /* dev addr , sys addr  , size  , flags */
+   /* TCML - alias */
+   { 0x, 0x007e, 0x0002, 0 },
+   /* OCRAM_S */
+   { 0x0018, 0x0018, 0x8000, 0 },
+   /* OCRAM */
+   { 0x0090, 0x0090, 0x0002, 0 },
+   /* OCRAM */
+   { 0x0092, 0x0092, 0x0002, 0 },
+   /* QSPI Code - alias */
+   { 0x0800, 0x0800, 0x0800, 0 },
+   /* DDR (Code) - alias */
+   { 0x1000, 0x8000, 0x0FFE, 0 },
+   /* TCML */
+   { 0x1FFE, 0x007E, 0x0002, ATT_OWN },
+   /* TCMU */
+   { 0x2000, 0x0080, 0x0002, ATT_OWN },
+   /* OCRAM_S */
+   { 0x2018, 0x0018, 0x8000, ATT_OWN },
+   /* OCRAM */
+   { 0x2020, 0x0090, 0x0002, ATT_OWN },
+   /* OCRAM */
+   { 0x2022, 0x0092, 0x0002, ATT_OWN },
+   /* DDR (Data) */
+   { 0x4000, 0x4000, 0x8000, 0 },
+};
+
 static const struct imx_rproc_att imx_rproc_att_imx7d[] = {
/* dev addr , sys addr  , size  , flags */
/* OCRAM_S (M4 Boot code) - alias */
@@ -138,6 +166,15 @@ static const struct imx_rproc_att imx_rproc_att_imx6sx[] = 
{
{ 0x8000, 0x8000, 0x6000, 0 },
 };
 
+static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mq = {
+   .src_reg= IMX7D_SRC_SCR,
+   .src_mask   = IMX7D_M4_RST_MASK,
+   .src_start  = IMX7D_M4_START,
+   .src_stop   = IMX7D_M4_STOP,
+   .att= imx_rproc_att_imx8mq,
+   .att_size   = ARRAY_SIZE(imx_rproc_att_imx8mq),
+};
+
 static const struct imx_rproc_dcfg imx_rproc_cfg_imx7d = {
.src_reg= IMX7D_SRC_SCR,
.src_mask   = IMX7D_M4_RST_MASK,
@@ -496,6 +533,8 @@ static int imx_rproc_remove(struct platform_device *pdev)
 static const struct of_device_id imx_rproc_of_match[] = {
{ .compatible = "fsl,imx7d-cm4", .data = _rproc_cfg_imx7d },
{ .compatible = "fsl,imx6sx-cm4", .data = _rproc_cfg_imx6sx },
+   { .compatible = "fsl,imx8mq-cm4", .data = _rproc_cfg_imx8mq },
+   { .compatible = "fsl,imx8mm-cm4", .data = _rproc_cfg_imx8mq },
{},
 };
 MODULE_DEVICE_TABLE(of, imx_rproc_of_match);
@@ -512,5 +551,5 @@ static struct platform_driver imx_rproc_driver = {
 module_platform_driver(imx_rproc_driver);
 
 MODULE_LICENSE("GPL v2");
-MODULE_DESCRIPTION("IMX6SX/7D remote processor control driver");
+MODULE_DESCRIPTION("i.MX remote processor control driver");
 MODULE_AUTHOR("Oleksij Rempel ");
-- 
2.28.0



[PATCH V9 07/10] remoteproc: imx_rproc: add i.MX specific parse fw hook

2021-01-20 Thread peng . fan
From: Peng Fan 

The hook is used to parse memory-regions and load resource table
from the address the remote processor published.

Reviewed-by: Richard Zhu 
Reviewed-by: Mathieu Poirier 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c | 93 ++
 1 file changed, 93 insertions(+)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 47fc1d06be6a..5ae1f5209548 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -241,10 +242,102 @@ static void *imx_rproc_da_to_va(struct rproc *rproc, u64 
da, size_t len, bool *i
return va;
 }
 
+static int imx_rproc_mem_alloc(struct rproc *rproc,
+  struct rproc_mem_entry *mem)
+{
+   struct device *dev = rproc->dev.parent;
+   void *va;
+
+   dev_dbg(dev, "map memory: %p+%zx\n", >dma, mem->len);
+   va = ioremap_wc(mem->dma, mem->len);
+   if (IS_ERR_OR_NULL(va)) {
+   dev_err(dev, "Unable to map memory region: %p+%zx\n",
+   >dma, mem->len);
+   return -ENOMEM;
+   }
+
+   /* Update memory entry va */
+   mem->va = va;
+
+   return 0;
+}
+
+static int imx_rproc_mem_release(struct rproc *rproc,
+struct rproc_mem_entry *mem)
+{
+   dev_dbg(rproc->dev.parent, "unmap memory: %pa\n", >dma);
+   iounmap(mem->va);
+
+   return 0;
+}
+
+static int imx_rproc_parse_memory_regions(struct rproc *rproc)
+{
+   struct imx_rproc *priv = rproc->priv;
+   struct device_node *np = priv->dev->of_node;
+   struct of_phandle_iterator it;
+   struct rproc_mem_entry *mem;
+   struct reserved_mem *rmem;
+   u32 da;
+
+   /* Register associated reserved memory regions */
+   of_phandle_iterator_init(, np, "memory-region", NULL, 0);
+   while (of_phandle_iterator_next() == 0) {
+   /*
+* Ignore the first memory region which will be used vdev 
buffer.
+* No need to do extra handlings, rproc_add_virtio_dev will 
handle it.
+*/
+   if (!strcmp(it.node->name, "vdev0buffer"))
+   continue;
+
+   rmem = of_reserved_mem_lookup(it.node);
+   if (!rmem) {
+   dev_err(priv->dev, "unable to acquire memory-region\n");
+   return -EINVAL;
+   }
+
+   /* No need to translate pa to da, i.MX use same map */
+   da = rmem->base;
+
+   /* Register memory region */
+   mem = rproc_mem_entry_init(priv->dev, NULL, 
(dma_addr_t)rmem->base, rmem->size, da,
+  imx_rproc_mem_alloc, 
imx_rproc_mem_release,
+  it.node->name);
+
+   if (mem)
+   rproc_coredump_add_segment(rproc, da, rmem->size);
+   else
+   return -ENOMEM;
+
+   rproc_add_carveout(rproc, mem);
+   }
+
+   return  0;
+}
+
+static int imx_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
+{
+   int ret = imx_rproc_parse_memory_regions(rproc);
+
+   if (ret)
+   return ret;
+
+   ret = rproc_elf_load_rsc_table(rproc, fw);
+   if (ret)
+   dev_info(>dev, "No resource table in elf\n");
+
+   return 0;
+}
+
 static const struct rproc_ops imx_rproc_ops = {
.start  = imx_rproc_start,
.stop   = imx_rproc_stop,
.da_to_va   = imx_rproc_da_to_va,
+   .load   = rproc_elf_load_segments,
+   .parse_fw   = imx_rproc_parse_fw,
+   .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table,
+   .sanity_check   = rproc_elf_sanity_check,
+   .get_boot_addr  = rproc_elf_get_boot_addr,
 };
 
 static int imx_rproc_addr_init(struct imx_rproc *priv,
-- 
2.28.0



[PATCH V9 03/10] remoteproc: introduce is_iomem to rproc_mem_entry

2021-01-20 Thread peng . fan
From: Peng Fan 

Introduce is_iomem to indicate this piece memory is iomem or not.

Reviewed-by: Bjorn Andersson 
Signed-off-by: Peng Fan 
Reviewed-by: Mathieu Poirier 
---
 include/linux/remoteproc.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index f28ee75d1005..a5f6d2d9cde2 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -315,6 +315,7 @@ struct rproc;
 /**
  * struct rproc_mem_entry - memory entry descriptor
  * @va:virtual address
+ * @is_iomem: io memory
  * @dma: dma address
  * @len: length, in bytes
  * @da: device address
@@ -329,6 +330,7 @@ struct rproc;
  */
 struct rproc_mem_entry {
void *va;
+   bool is_iomem;
dma_addr_t dma;
size_t len;
u32 da;
-- 
2.28.0



[PATCH V9 06/10] remoteproc: imx_rproc: use devm_ioremap

2021-01-20 Thread peng . fan
From: Peng Fan 

We might need to map an region multiple times, becaue the region might
be shared between remote processors, such i.MX8QM with dual M4 cores.
So use devm_ioremap, not devm_ioremap_resource.

Reviewed-by: Oleksij Rempel 
Reviewed-by: Richard Zhu 
Signed-off-by: Peng Fan 
Reviewed-by: Mathieu Poirier 
---
 drivers/remoteproc/imx_rproc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 2a093cea4997..47fc1d06be6a 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -296,7 +296,8 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
if (b >= IMX7D_RPROC_MEM_MAX)
break;
 
-   priv->mem[b].cpu_addr = devm_ioremap_resource(>dev, );
+   /* Not use resource version, because we might share region */
+   priv->mem[b].cpu_addr = devm_ioremap(>dev, res.start, 
resource_size());
if (IS_ERR(priv->mem[b].cpu_addr)) {
dev_err(dev, "failed to remap %pr\n", );
err = PTR_ERR(priv->mem[b].cpu_addr);
-- 
2.28.0



[PATCH V9 10/10] remoteproc: imx_proc: enable virtio/mailbox

2021-01-20 Thread peng . fan
From: Peng Fan 

Use virtio/mailbox to build connection between Remote Proccessors
and Linux. Add work queue to handle incoming messages.

Reviewed-by: Richard Zhu 
Reviewed-by: Mathieu Poirier 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c | 116 -
 1 file changed, 113 insertions(+), 3 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 3685bbd135b0..90471790bb24 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -15,6 +16,9 @@
 #include 
 #include 
 #include 
+#include 
+
+#include "remoteproc_internal.h"
 
 #define IMX7D_SRC_SCR  0x0C
 #define IMX7D_ENABLE_M4BIT(3)
@@ -86,6 +90,11 @@ struct imx_rproc {
const struct imx_rproc_dcfg *dcfg;
struct imx_rproc_memmem[IMX7D_RPROC_MEM_MAX];
struct clk  *clk;
+   struct mbox_client  cl;
+   struct mbox_chan*tx_ch;
+   struct mbox_chan*rx_ch;
+   struct work_struct  rproc_work;
+   struct workqueue_struct *workqueue;
 };
 
 static const struct imx_rproc_att imx_rproc_att_imx8mq[] = {
@@ -366,9 +375,33 @@ static int imx_rproc_parse_fw(struct rproc *rproc, const 
struct firmware *fw)
return 0;
 }
 
+static void imx_rproc_kick(struct rproc *rproc, int vqid)
+{
+   struct imx_rproc *priv = rproc->priv;
+   int err;
+   __u32 mmsg;
+
+   if (!priv->tx_ch) {
+   dev_err(priv->dev, "No initialized mbox tx channel\n");
+   return;
+   }
+
+   /*
+* Send the index of the triggered virtqueue as the mu payload.
+* Let remote processor know which virtqueue is used.
+*/
+   mmsg = vqid << 16;
+
+   err = mbox_send_message(priv->tx_ch, (void *));
+   if (err < 0)
+   dev_err(priv->dev, "%s: failed (%d, err:%d)\n",
+   __func__, vqid, err);
+}
+
 static const struct rproc_ops imx_rproc_ops = {
.start  = imx_rproc_start,
.stop   = imx_rproc_stop,
+   .kick   = imx_rproc_kick,
.da_to_va   = imx_rproc_da_to_va,
.load   = rproc_elf_load_segments,
.parse_fw   = imx_rproc_parse_fw,
@@ -444,6 +477,66 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
return 0;
 }
 
+static void imx_rproc_vq_work(struct work_struct *work)
+{
+   struct imx_rproc *priv = container_of(work, struct imx_rproc,
+ rproc_work);
+
+   rproc_vq_interrupt(priv->rproc, 0);
+   rproc_vq_interrupt(priv->rproc, 1);
+}
+
+static void imx_rproc_rx_callback(struct mbox_client *cl, void *msg)
+{
+   struct rproc *rproc = dev_get_drvdata(cl->dev);
+   struct imx_rproc *priv = rproc->priv;
+
+   queue_work(priv->workqueue, >rproc_work);
+}
+
+static int imx_rproc_xtr_mbox_init(struct rproc *rproc)
+{
+   struct imx_rproc *priv = rproc->priv;
+   struct device *dev = priv->dev;
+   struct mbox_client *cl;
+   int ret;
+
+   if (!of_get_property(dev->of_node, "mbox-names", NULL))
+   return 0;
+
+   cl = >cl;
+   cl->dev = dev;
+   cl->tx_block = true;
+   cl->tx_tout = 100;
+   cl->knows_txdone = false;
+   cl->rx_callback = imx_rproc_rx_callback;
+
+   priv->tx_ch = mbox_request_channel_byname(cl, "tx");
+   if (IS_ERR(priv->tx_ch)) {
+   ret = PTR_ERR(priv->tx_ch);
+   return dev_err_probe(cl->dev, ret,
+"failed to request tx mailbox channel: 
%d\n", ret);
+   }
+
+   priv->rx_ch = mbox_request_channel_byname(cl, "rx");
+   if (IS_ERR(priv->rx_ch)) {
+   mbox_free_channel(priv->tx_ch);
+   ret = PTR_ERR(priv->rx_ch);
+   return dev_err_probe(cl->dev, ret,
+"failed to request rx mailbox channel: 
%d\n", ret);
+   }
+
+   return 0;
+}
+
+static void imx_rproc_free_mbox(struct rproc *rproc)
+{
+   struct imx_rproc *priv = rproc->priv;
+
+   mbox_free_channel(priv->tx_ch);
+   mbox_free_channel(priv->rx_ch);
+}
+
 static int imx_rproc_probe(struct platform_device *pdev)
 {
struct device *dev = >dev;
@@ -481,18 +574,28 @@ static int imx_rproc_probe(struct platform_device *pdev)
priv->dev = dev;
 
dev_set_drvdata(dev, rproc);
+   priv->workqueue = create_workqueue(dev_name(dev));
+   if (!priv->workqueue) {
+   dev_err(dev, "cannot create workqueue\n");
+  

[PATCH V9 02/10] dt-bindings: remoteproc: imx_rproc: add i.MX8MQ/M support

2021-01-20 Thread peng . fan
From: Peng Fan 

Add i.MX8MQ/M support, also include mailbox for rpmsg/virtio usage.

Signed-off-by: Peng Fan 
---
 .../bindings/remoteproc/fsl,imx-rproc.yaml| 51 ++-
 1 file changed, 50 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml 
b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
index bce6ccfe1538..7ae0fca24403 100644
--- a/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
+++ b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
@@ -4,7 +4,7 @@
 $id: "http://devicetree.org/schemas/remoteproc/fsl,imx-rproc.yaml#;
 $schema: "http://devicetree.org/meta-schemas/core.yaml#;
 
-title: NXP iMX6SX/iMX7D Co-Processor Bindings
+title: NXP i.MX Co-Processor Bindings
 
 description:
   This binding provides support for ARM Cortex M4 Co-processor found on some 
NXP iMX SoCs.
@@ -15,6 +15,8 @@ maintainers:
 properties:
   compatible:
 enum:
+  - fsl,imx8mq-cm4
+  - fsl,imx8mm-cm4
   - fsl,imx7d-cm4
   - fsl,imx6sx-cm4
 
@@ -26,6 +28,20 @@ properties:
 description:
   Phandle to syscon block which provide access to System Reset Controller
 
+  mbox-names:
+items:
+  - const: tx
+  - const: rx
+  - const: rxdb
+
+  mboxes:
+description:
+  This property is required only if the rpmsg/virtio functionality is used.
+  List of < type channel> - 1 channel for TX, 1 channel for RX, 1 
channel for RXDB.
+  (see mailbox/fsl,mu.yaml)
+minItems: 1
+maxItems: 3
+
   memory-region:
 description:
   list of phandels to the reserved memory regions.
@@ -56,4 +72,37 @@ examples:
   clocks   = < IMX7D_ARM_M4_ROOT_CLK>;
 };
 
+  - |
+#include 
+rsc_table: rsc_table@550ff000 {
+  no-map;
+  reg = <0x550ff000 0x1000>;
+};
+
+vdev0vring0: vdev0vring0@5500 {
+  no-map;
+  reg = <0x5500 0x8000>;
+};
+
+vdev0vring1: vdev0vring1@55008000 {
+  reg = <0x55008000 0x8000>;
+  no-map;
+};
+
+vdev0buffer: vdev0buffer@5540 {
+  compatible = "shared-dma-pool";
+  reg = <0x5540 0x10>;
+  no-map;
+};
+
+imx8mm-cm4 {
+  compatible = "fsl,imx8mm-cm4";
+  clocks = < IMX8MM_CLK_M4_DIV>;
+  mbox-names = "tx", "rx", "rxdb";
+  mboxes = < 0 1
+ 1 1
+ 3 1>;
+  memory-region = <>, <>, <>, 
<_table>;
+  syscon = <>;
+};
 ...
-- 
2.28.0



[PATCH V9 05/10] remoteproc: imx_rproc: correct err message

2021-01-20 Thread peng . fan
From: Peng Fan 

It is using devm_ioremap, so not devm_ioremap_resource. Correct
the error message and print out sa/size.

Reviewed-by: Bjorn Andersson 
Reviewed-by: Mathieu Poirier 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 6603e00bb6f4..2a093cea4997 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -268,7 +268,7 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
priv->mem[b].cpu_addr = devm_ioremap(>dev,
 att->sa, att->size);
if (!priv->mem[b].cpu_addr) {
-   dev_err(dev, "devm_ioremap_resource failed\n");
+   dev_err(dev, "failed to remap %#x bytes from %#x\n", 
att->size, att->sa);
return -ENOMEM;
}
priv->mem[b].sys_addr = att->sa;
@@ -298,7 +298,7 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
 
priv->mem[b].cpu_addr = devm_ioremap_resource(>dev, );
if (IS_ERR(priv->mem[b].cpu_addr)) {
-   dev_err(dev, "devm_ioremap_resource failed\n");
+   dev_err(dev, "failed to remap %pr\n", );
err = PTR_ERR(priv->mem[b].cpu_addr);
return err;
}
-- 
2.28.0



[PATCH V9 01/10] dt-bindings: remoteproc: convert imx rproc bindings to json-schema

2021-01-20 Thread peng . fan
From: Peng Fan 

Convert the imx rproc binding to DT schema format using json-schema.

Signed-off-by: Peng Fan 
---
 .../bindings/remoteproc/fsl,imx-rproc.yaml| 59 +++
 .../bindings/remoteproc/imx-rproc.txt | 33 ---
 2 files changed, 59 insertions(+), 33 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
 delete mode 100644 Documentation/devicetree/bindings/remoteproc/imx-rproc.txt

diff --git a/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml 
b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
new file mode 100644
index ..bce6ccfe1538
--- /dev/null
+++ b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/remoteproc/fsl,imx-rproc.yaml#;
+$schema: "http://devicetree.org/meta-schemas/core.yaml#;
+
+title: NXP iMX6SX/iMX7D Co-Processor Bindings
+
+description:
+  This binding provides support for ARM Cortex M4 Co-processor found on some 
NXP iMX SoCs.
+
+maintainers:
+  - Peng Fan 
+
+properties:
+  compatible:
+enum:
+  - fsl,imx7d-cm4
+  - fsl,imx6sx-cm4
+
+  clocks:
+description:
+  Clock for co-processor (See ../clock/clock-bindings.txt)
+
+  syscon:
+description:
+  Phandle to syscon block which provide access to System Reset Controller
+
+  memory-region:
+description:
+  list of phandels to the reserved memory regions.
+  (see ../reserved-memory/reserved-memory.txt)
+
+required:
+  - compatible
+  - clocks
+  - syscon
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+m4_reserved_sysmem1: cm4@8000 {
+  reg = <0x8000 0x8>;
+};
+
+m4_reserved_sysmem2: cm4@8100 {
+  reg = <0x8100 0x8>;
+};
+
+imx7d-cm4 {
+  compatible   = "fsl,imx7d-cm4";
+  memory-region= <_reserved_sysmem1>, <_reserved_sysmem2>;
+  syscon   = <>;
+  clocks   = < IMX7D_ARM_M4_ROOT_CLK>;
+};
+
+...
diff --git a/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt 
b/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt
deleted file mode 100644
index fbcefd965dc4..
--- a/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-NXP iMX6SX/iMX7D Co-Processor Bindings
-
-
-This binding provides support for ARM Cortex M4 Co-processor found on some
-NXP iMX SoCs.
-
-Required properties:
-- compatible   Should be one of:
-   "fsl,imx7d-cm4"
-   "fsl,imx6sx-cm4"
-- clocks   Clock for co-processor (See: 
../clock/clock-bindings.txt)
-- syscon   Phandle to syscon block which provide access to
-   System Reset Controller
-
-Optional properties:
-- memory-regionlist of phandels to the reserved memory regions.
-   (See: ../reserved-memory/reserved-memory.txt)
-
-Example:
-   m4_reserved_sysmem1: cm4@8000 {
-   reg = <0x8000 0x8>;
-   };
-
-   m4_reserved_sysmem2: cm4@8100 {
-   reg = <0x8100 0x8>;
-   };
-
-   imx7d-cm4 {
-   compatible  = "fsl,imx7d-cm4";
-   memory-region   = <_reserved_sysmem1>, 
<_reserved_sysmem2>;
-   syscon  = <>;
-   clocks  = < IMX7D_ARM_M4_ROOT_CLK>;
-   };
-- 
2.28.0



[PATCH V9 04/10] remoteproc: add is_iomem to da_to_va

2021-01-20 Thread peng . fan
From: Peng Fan 

Introduce an extra parameter is_iomem to da_to_va, then the caller
could take the memory as normal memory or io mapped memory.

Reviewed-by: Bjorn Andersson 
Reviewed-by: Mathieu Poirier 
Reported-by: kernel test robot 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c |  2 +-
 drivers/remoteproc/ingenic_rproc.c |  2 +-
 drivers/remoteproc/keystone_remoteproc.c   |  2 +-
 drivers/remoteproc/mtk_scp.c   |  6 +++---
 drivers/remoteproc/omap_remoteproc.c   |  2 +-
 drivers/remoteproc/pru_rproc.c |  2 +-
 drivers/remoteproc/qcom_q6v5_adsp.c|  2 +-
 drivers/remoteproc/qcom_q6v5_pas.c |  2 +-
 drivers/remoteproc/qcom_q6v5_wcss.c|  2 +-
 drivers/remoteproc/qcom_wcnss.c|  2 +-
 drivers/remoteproc/remoteproc_core.c   |  7 +--
 drivers/remoteproc/remoteproc_coredump.c   |  8 ++--
 drivers/remoteproc/remoteproc_debugfs.c|  2 +-
 drivers/remoteproc/remoteproc_elf_loader.c | 21 +++--
 drivers/remoteproc/remoteproc_internal.h   |  2 +-
 drivers/remoteproc/st_slim_rproc.c |  2 +-
 drivers/remoteproc/ti_k3_dsp_remoteproc.c  |  2 +-
 drivers/remoteproc/ti_k3_r5_remoteproc.c   |  2 +-
 drivers/remoteproc/wkup_m3_rproc.c |  2 +-
 include/linux/remoteproc.h |  2 +-
 20 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 8957ed271d20..6603e00bb6f4 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -208,7 +208,7 @@ static int imx_rproc_da_to_sys(struct imx_rproc *priv, u64 
da,
return -ENOENT;
 }
 
-static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool 
*is_iomem)
 {
struct imx_rproc *priv = rproc->priv;
void *va = NULL;
diff --git a/drivers/remoteproc/ingenic_rproc.c 
b/drivers/remoteproc/ingenic_rproc.c
index 26e19e6143b7..bb5049295576 100644
--- a/drivers/remoteproc/ingenic_rproc.c
+++ b/drivers/remoteproc/ingenic_rproc.c
@@ -116,7 +116,7 @@ static void ingenic_rproc_kick(struct rproc *rproc, int 
vqid)
writel(vqid, vpu->aux_base + REG_CORE_MSG);
 }
 
-static void *ingenic_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *ingenic_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, 
bool *is_iomem)
 {
struct vpu *vpu = rproc->priv;
void __iomem *va = NULL;
diff --git a/drivers/remoteproc/keystone_remoteproc.c 
b/drivers/remoteproc/keystone_remoteproc.c
index cd266163a65f..54781f553f4e 100644
--- a/drivers/remoteproc/keystone_remoteproc.c
+++ b/drivers/remoteproc/keystone_remoteproc.c
@@ -246,7 +246,7 @@ static void keystone_rproc_kick(struct rproc *rproc, int 
vqid)
  * can be used either by the remoteproc core for loading (when using kernel
  * remoteproc loader), or by any rpmsg bus drivers.
  */
-static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, 
bool *is_iomem)
 {
struct keystone_rproc *ksproc = rproc->priv;
void __iomem *va = NULL;
diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c
index e0c235690361..535175f013e4 100644
--- a/drivers/remoteproc/mtk_scp.c
+++ b/drivers/remoteproc/mtk_scp.c
@@ -270,7 +270,7 @@ static int scp_elf_load_segments(struct rproc *rproc, const 
struct firmware *fw)
}
 
/* grab the kernel address for this device address */
-   ptr = (void __iomem *)rproc_da_to_va(rproc, da, memsz);
+   ptr = (void __iomem *)rproc_da_to_va(rproc, da, memsz, NULL);
if (!ptr) {
dev_err(dev, "bad phdr da 0x%x mem 0x%x\n", da, memsz);
ret = -EINVAL;
@@ -458,7 +458,7 @@ static int scp_start(struct rproc *rproc)
return ret;
 }
 
-static void *scp_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *scp_da_to_va(struct rproc *rproc, u64 da, size_t len, bool 
*is_iomem)
 {
struct mtk_scp *scp = (struct mtk_scp *)rproc->priv;
int offset;
@@ -587,7 +587,7 @@ void *scp_mapping_dm_addr(struct mtk_scp *scp, u32 mem_addr)
 {
void *ptr;
 
-   ptr = scp_da_to_va(scp->rproc, mem_addr, 0);
+   ptr = scp_da_to_va(scp->rproc, mem_addr, 0, NULL);
if (!ptr)
return ERR_PTR(-EINVAL);
 
diff --git a/drivers/remoteproc/omap_remoteproc.c 
b/drivers/remoteproc/omap_remoteproc.c
index d94b7391bf9d..43531caa1959 100644
--- a/drivers/remoteproc/omap_remoteproc.c
+++ b/drivers/remoteproc/omap_remoteproc.c
@@ -728,7 +728,7 @@ static int omap_rproc_stop(struct rproc *rproc)
  * Return: translated virtual address in kernel memory space on success,
  * or NULL on failure.
  */
-static void *omap_rproc_da_to_va(struct r

[PATCH V9 00/10] remoteproc: imx_rproc: support iMX8MQ/M

2021-01-20 Thread peng . fan
From: Peng Fan 

V9:
 Per Mathieu's comments,
   update the tile of yaml in patch 2/10
   update the Kconfig and MODULE_DESCRIPTION, I merge this change in patch 8/10,
   since this is a minor change, I still keep Mathieu's R-b tag. If any 
objection, I could remove.
   Add R-b tag in Patch 10/10

 Rob, please help review patch 1/10 and 2/10

V8:
 Address sparse warning in patch 4/10 reported by kernel test robot

V7:
 Add R-b tag from Mathieu
 vdevbuffer->vdev0buffer in patch 1/10, 7/10
 correct err msg and shutdown seq per Mathieu's comments in patch 10/10
 Hope this version is ok to be merged.
 
V6:
 Add R-b tag from Mathieu
 Convert imx-rproc.txt to yaml and add dt-bindings support for i.MX8MQ/M, patch 
1/10 2/10
 No other changes.

V5:
 Apply on Linux next
 Add V5 subject prefix
 Add R-b tag from Bjorn for 1/8, 2/8, 3/8
 
https://patchwork.kernel.org/project/linux-remoteproc/cover/20201229033019.25899-1-peng@nxp.com/

V4:
 According to Bjorn's comments, add is_iomem for da to va usage
 1/8, 2/8 is new patch
 3/8, follow Bjorn's comments to correct/update the err msg.
 6/8, new patch
 8/8, use dev_err_probe to simplify code, use queue_work instead 
schedule_delayed_work

V3:
 Since I was quite busy in the past days, V3 is late
 Rebased on Linux-next
 Add R-b tags
 1/7: Add R-b tag of Mathieu, add comments
 4/7: Typo fix
 5/7: Add R-b tag of Mathieu, drop index Per Mathieu's comments
 6/7: Add R-b tag of Mathieu
 7/7: Add comment for vqid << 16, drop unneeded timeout settings of mailbox
  Use queue_work instead of schedule_delayed_work
  free mbox channels when remove
 https://lkml.org/lkml/2020/12/4/82

V2:
 Rebased on linux-next
 Dropped early boot feature to make patchset simple.
 Drop rsc-da
 
https://patchwork.kernel.org/project/linux-remoteproc/cover/20200927064131.24101-1-peng@nxp.com/

V1:
 https://patchwork.kernel.org/cover/11682461/

This patchset is to support i.MX8MQ/M coproc.
The early boot feature was dropped to make the patchset small in V2.

Since i.MX specific TCM memory requirement, add elf platform hook.
Several patches have got reviewed by Oleksij and Mathieu in v1.


Peng Fan (10):
  dt-bindings: remoteproc: convert imx rproc bindings to json-schema
  dt-bindings: remoteproc: imx_rproc: add i.MX8MQ/M support
  remoteproc: introduce is_iomem to rproc_mem_entry
  remoteproc: add is_iomem to da_to_va
  remoteproc: imx_rproc: correct err message
  remoteproc: imx_rproc: use devm_ioremap
  remoteproc: imx_rproc: add i.MX specific parse fw hook
  remoteproc: imx_rproc: support i.MX8MQ/M
  remoteproc: imx_rproc: ignore mapping vdev regions
  remoteproc: imx_proc: enable virtio/mailbox

 .../bindings/remoteproc/fsl,imx-rproc.yaml| 108 
 .../bindings/remoteproc/imx-rproc.txt |  33 ---
 drivers/remoteproc/Kconfig|   6 +-
 drivers/remoteproc/imx_rproc.c| 262 +-
 drivers/remoteproc/ingenic_rproc.c|   2 +-
 drivers/remoteproc/keystone_remoteproc.c  |   2 +-
 drivers/remoteproc/mtk_scp.c  |   6 +-
 drivers/remoteproc/omap_remoteproc.c  |   2 +-
 drivers/remoteproc/pru_rproc.c|   2 +-
 drivers/remoteproc/qcom_q6v5_adsp.c   |   2 +-
 drivers/remoteproc/qcom_q6v5_pas.c|   2 +-
 drivers/remoteproc/qcom_q6v5_wcss.c   |   2 +-
 drivers/remoteproc/qcom_wcnss.c   |   2 +-
 drivers/remoteproc/remoteproc_core.c  |   7 +-
 drivers/remoteproc/remoteproc_coredump.c  |   8 +-
 drivers/remoteproc/remoteproc_debugfs.c   |   2 +-
 drivers/remoteproc/remoteproc_elf_loader.c|  21 +-
 drivers/remoteproc/remoteproc_internal.h  |   2 +-
 drivers/remoteproc/st_slim_rproc.c|   2 +-
 drivers/remoteproc/ti_k3_dsp_remoteproc.c |   2 +-
 drivers/remoteproc/ti_k3_r5_remoteproc.c  |   2 +-
 drivers/remoteproc/wkup_m3_rproc.c|   2 +-
 include/linux/remoteproc.h|   4 +-
 23 files changed, 411 insertions(+), 72 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
 delete mode 100644 Documentation/devicetree/bindings/remoteproc/imx-rproc.txt

-- 
2.28.0



[PATCH V8 00/10] remoteproc: imx_rproc: support iMX8MQ/M

2021-01-18 Thread peng . fan
From: Peng Fan 

V8:
 Address sparse warning in patch 4/10 reported by kernel test robot

V7:
 Add R-b tag from Mathieu
 vdevbuffer->vdev0buffer in patch 1/10, 7/10
 correct err msg and shutdown seq per Mathieu's comments in patch 10/10
 Hope this version is ok to be merged.
 
V6:
 Add R-b tag from Mathieu
 Convert imx-rproc.txt to yaml and add dt-bindings support for i.MX8MQ/M, patch 
1/10 2/10
 No other changes.

V5:
 Apply on Linux next
 Add V5 subject prefix
 Add R-b tag from Bjorn for 1/8, 2/8, 3/8
 
https://patchwork.kernel.org/project/linux-remoteproc/cover/20201229033019.25899-1-peng@nxp.com/

V4:
 According to Bjorn's comments, add is_iomem for da to va usage
 1/8, 2/8 is new patch
 3/8, follow Bjorn's comments to correct/update the err msg.
 6/8, new patch
 8/8, use dev_err_probe to simplify code, use queue_work instead 
schedule_delayed_work

V3:
 Since I was quite busy in the past days, V3 is late
 Rebased on Linux-next
 Add R-b tags
 1/7: Add R-b tag of Mathieu, add comments
 4/7: Typo fix
 5/7: Add R-b tag of Mathieu, drop index Per Mathieu's comments
 6/7: Add R-b tag of Mathieu
 7/7: Add comment for vqid << 16, drop unneeded timeout settings of mailbox
  Use queue_work instead of schedule_delayed_work
  free mbox channels when remove
 https://lkml.org/lkml/2020/12/4/82

V2:
 Rebased on linux-next
 Dropped early boot feature to make patchset simple.
 Drop rsc-da
 
https://patchwork.kernel.org/project/linux-remoteproc/cover/20200927064131.24101-1-peng@nxp.com/

V1:
 https://patchwork.kernel.org/cover/11682461/

This patchset is to support i.MX8MQ/M coproc.
The early boot feature was dropped to make the patchset small in V2.

Since i.MX specific TCM memory requirement, add elf platform hook.
Several patches have got reviewed by Oleksij and Mathieu in v1.




Peng Fan (10):
  dt-bindings: remoteproc: convert imx rproc bindings to json-schema
  dt-bindings: remoteproc: imx_rproc: add i.MX8MQ/M support
  remoteproc: introduce is_iomem to rproc_mem_entry
  remoteproc: add is_iomem to da_to_va
  remoteproc: imx_rproc: correct err message
  remoteproc: imx_rproc: use devm_ioremap
  remoteproc: imx_rproc: add i.MX specific parse fw hook
  remoteproc: imx_rproc: support i.MX8MQ/M
  remoteproc: imx_rproc: ignore mapping vdev regions
  remoteproc: imx_proc: enable virtio/mailbox

 .../bindings/remoteproc/fsl,imx-rproc.yaml| 108 
 .../bindings/remoteproc/imx-rproc.txt |  33 ---
 drivers/remoteproc/imx_rproc.c| 260 +-
 drivers/remoteproc/ingenic_rproc.c|   2 +-
 drivers/remoteproc/keystone_remoteproc.c  |   2 +-
 drivers/remoteproc/mtk_scp.c  |   6 +-
 drivers/remoteproc/omap_remoteproc.c  |   2 +-
 drivers/remoteproc/pru_rproc.c|   2 +-
 drivers/remoteproc/qcom_q6v5_adsp.c   |   2 +-
 drivers/remoteproc/qcom_q6v5_pas.c|   2 +-
 drivers/remoteproc/qcom_q6v5_wcss.c   |   2 +-
 drivers/remoteproc/qcom_wcnss.c   |   2 +-
 drivers/remoteproc/remoteproc_core.c  |   7 +-
 drivers/remoteproc/remoteproc_coredump.c  |   8 +-
 drivers/remoteproc/remoteproc_debugfs.c   |   2 +-
 drivers/remoteproc/remoteproc_elf_loader.c|  21 +-
 drivers/remoteproc/remoteproc_internal.h  |   2 +-
 drivers/remoteproc/st_slim_rproc.c|   2 +-
 drivers/remoteproc/ti_k3_dsp_remoteproc.c |   2 +-
 drivers/remoteproc/ti_k3_r5_remoteproc.c  |   2 +-
 drivers/remoteproc/wkup_m3_rproc.c|   2 +-
 include/linux/remoteproc.h|   4 +-
 22 files changed, 407 insertions(+), 68 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
 delete mode 100644 Documentation/devicetree/bindings/remoteproc/imx-rproc.txt

-- 
2.28.0



[PATCH V8 06/10] remoteproc: imx_rproc: use devm_ioremap

2021-01-18 Thread peng . fan
From: Peng Fan 

We might need to map an region multiple times, becaue the region might
be shared between remote processors, such i.MX8QM with dual M4 cores.
So use devm_ioremap, not devm_ioremap_resource.

Reviewed-by: Oleksij Rempel 
Reviewed-by: Richard Zhu 
Signed-off-by: Peng Fan 
Reviewed-by: Mathieu Poirier 
---
 drivers/remoteproc/imx_rproc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 2a093cea4997..47fc1d06be6a 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -296,7 +296,8 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
if (b >= IMX7D_RPROC_MEM_MAX)
break;
 
-   priv->mem[b].cpu_addr = devm_ioremap_resource(>dev, );
+   /* Not use resource version, because we might share region */
+   priv->mem[b].cpu_addr = devm_ioremap(>dev, res.start, 
resource_size());
if (IS_ERR(priv->mem[b].cpu_addr)) {
dev_err(dev, "failed to remap %pr\n", );
err = PTR_ERR(priv->mem[b].cpu_addr);
-- 
2.28.0



[PATCH V8 03/10] remoteproc: introduce is_iomem to rproc_mem_entry

2021-01-18 Thread peng . fan
From: Peng Fan 

Introduce is_iomem to indicate this piece memory is iomem or not.

Reviewed-by: Bjorn Andersson 
Signed-off-by: Peng Fan 
Reviewed-by: Mathieu Poirier 
---
 include/linux/remoteproc.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index f28ee75d1005..a5f6d2d9cde2 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -315,6 +315,7 @@ struct rproc;
 /**
  * struct rproc_mem_entry - memory entry descriptor
  * @va:virtual address
+ * @is_iomem: io memory
  * @dma: dma address
  * @len: length, in bytes
  * @da: device address
@@ -329,6 +330,7 @@ struct rproc;
  */
 struct rproc_mem_entry {
void *va;
+   bool is_iomem;
dma_addr_t dma;
size_t len;
u32 da;
-- 
2.28.0



[PATCH V8 07/10] remoteproc: imx_rproc: add i.MX specific parse fw hook

2021-01-18 Thread peng . fan
From: Peng Fan 

The hook is used to parse memory-regions and load resource table
from the address the remote processor published.

Reviewed-by: Richard Zhu 
Reviewed-by: Mathieu Poirier 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c | 93 ++
 1 file changed, 93 insertions(+)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 47fc1d06be6a..5ae1f5209548 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -241,10 +242,102 @@ static void *imx_rproc_da_to_va(struct rproc *rproc, u64 
da, size_t len, bool *i
return va;
 }
 
+static int imx_rproc_mem_alloc(struct rproc *rproc,
+  struct rproc_mem_entry *mem)
+{
+   struct device *dev = rproc->dev.parent;
+   void *va;
+
+   dev_dbg(dev, "map memory: %p+%zx\n", >dma, mem->len);
+   va = ioremap_wc(mem->dma, mem->len);
+   if (IS_ERR_OR_NULL(va)) {
+   dev_err(dev, "Unable to map memory region: %p+%zx\n",
+   >dma, mem->len);
+   return -ENOMEM;
+   }
+
+   /* Update memory entry va */
+   mem->va = va;
+
+   return 0;
+}
+
+static int imx_rproc_mem_release(struct rproc *rproc,
+struct rproc_mem_entry *mem)
+{
+   dev_dbg(rproc->dev.parent, "unmap memory: %pa\n", >dma);
+   iounmap(mem->va);
+
+   return 0;
+}
+
+static int imx_rproc_parse_memory_regions(struct rproc *rproc)
+{
+   struct imx_rproc *priv = rproc->priv;
+   struct device_node *np = priv->dev->of_node;
+   struct of_phandle_iterator it;
+   struct rproc_mem_entry *mem;
+   struct reserved_mem *rmem;
+   u32 da;
+
+   /* Register associated reserved memory regions */
+   of_phandle_iterator_init(, np, "memory-region", NULL, 0);
+   while (of_phandle_iterator_next() == 0) {
+   /*
+* Ignore the first memory region which will be used vdev 
buffer.
+* No need to do extra handlings, rproc_add_virtio_dev will 
handle it.
+*/
+   if (!strcmp(it.node->name, "vdev0buffer"))
+   continue;
+
+   rmem = of_reserved_mem_lookup(it.node);
+   if (!rmem) {
+   dev_err(priv->dev, "unable to acquire memory-region\n");
+   return -EINVAL;
+   }
+
+   /* No need to translate pa to da, i.MX use same map */
+   da = rmem->base;
+
+   /* Register memory region */
+   mem = rproc_mem_entry_init(priv->dev, NULL, 
(dma_addr_t)rmem->base, rmem->size, da,
+  imx_rproc_mem_alloc, 
imx_rproc_mem_release,
+  it.node->name);
+
+   if (mem)
+   rproc_coredump_add_segment(rproc, da, rmem->size);
+   else
+   return -ENOMEM;
+
+   rproc_add_carveout(rproc, mem);
+   }
+
+   return  0;
+}
+
+static int imx_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
+{
+   int ret = imx_rproc_parse_memory_regions(rproc);
+
+   if (ret)
+   return ret;
+
+   ret = rproc_elf_load_rsc_table(rproc, fw);
+   if (ret)
+   dev_info(>dev, "No resource table in elf\n");
+
+   return 0;
+}
+
 static const struct rproc_ops imx_rproc_ops = {
.start  = imx_rproc_start,
.stop   = imx_rproc_stop,
.da_to_va   = imx_rproc_da_to_va,
+   .load   = rproc_elf_load_segments,
+   .parse_fw   = imx_rproc_parse_fw,
+   .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table,
+   .sanity_check   = rproc_elf_sanity_check,
+   .get_boot_addr  = rproc_elf_get_boot_addr,
 };
 
 static int imx_rproc_addr_init(struct imx_rproc *priv,
-- 
2.28.0



[PATCH V8 08/10] remoteproc: imx_rproc: support i.MX8MQ/M

2021-01-18 Thread peng . fan
From: Peng Fan 

Add i.MX8MQ dev/sys addr map and configuration data structure
i.MX8MM share i.MX8MQ settings.

Reviewed-by: Richard Zhu 
Signed-off-by: Peng Fan 
Reviewed-by: Mathieu Poirier 
---
 drivers/remoteproc/imx_rproc.c | 39 ++
 1 file changed, 39 insertions(+)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 5ae1f5209548..fa01e64cc791 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -88,6 +88,34 @@ struct imx_rproc {
struct clk  *clk;
 };
 
+static const struct imx_rproc_att imx_rproc_att_imx8mq[] = {
+   /* dev addr , sys addr  , size  , flags */
+   /* TCML - alias */
+   { 0x, 0x007e, 0x0002, 0 },
+   /* OCRAM_S */
+   { 0x0018, 0x0018, 0x8000, 0 },
+   /* OCRAM */
+   { 0x0090, 0x0090, 0x0002, 0 },
+   /* OCRAM */
+   { 0x0092, 0x0092, 0x0002, 0 },
+   /* QSPI Code - alias */
+   { 0x0800, 0x0800, 0x0800, 0 },
+   /* DDR (Code) - alias */
+   { 0x1000, 0x8000, 0x0FFE, 0 },
+   /* TCML */
+   { 0x1FFE, 0x007E, 0x0002, ATT_OWN },
+   /* TCMU */
+   { 0x2000, 0x0080, 0x0002, ATT_OWN },
+   /* OCRAM_S */
+   { 0x2018, 0x0018, 0x8000, ATT_OWN },
+   /* OCRAM */
+   { 0x2020, 0x0090, 0x0002, ATT_OWN },
+   /* OCRAM */
+   { 0x2022, 0x0092, 0x0002, ATT_OWN },
+   /* DDR (Data) */
+   { 0x4000, 0x4000, 0x8000, 0 },
+};
+
 static const struct imx_rproc_att imx_rproc_att_imx7d[] = {
/* dev addr , sys addr  , size  , flags */
/* OCRAM_S (M4 Boot code) - alias */
@@ -138,6 +166,15 @@ static const struct imx_rproc_att imx_rproc_att_imx6sx[] = 
{
{ 0x8000, 0x8000, 0x6000, 0 },
 };
 
+static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mq = {
+   .src_reg= IMX7D_SRC_SCR,
+   .src_mask   = IMX7D_M4_RST_MASK,
+   .src_start  = IMX7D_M4_START,
+   .src_stop   = IMX7D_M4_STOP,
+   .att= imx_rproc_att_imx8mq,
+   .att_size   = ARRAY_SIZE(imx_rproc_att_imx8mq),
+};
+
 static const struct imx_rproc_dcfg imx_rproc_cfg_imx7d = {
.src_reg= IMX7D_SRC_SCR,
.src_mask   = IMX7D_M4_RST_MASK,
@@ -496,6 +533,8 @@ static int imx_rproc_remove(struct platform_device *pdev)
 static const struct of_device_id imx_rproc_of_match[] = {
{ .compatible = "fsl,imx7d-cm4", .data = _rproc_cfg_imx7d },
{ .compatible = "fsl,imx6sx-cm4", .data = _rproc_cfg_imx6sx },
+   { .compatible = "fsl,imx8mq-cm4", .data = _rproc_cfg_imx8mq },
+   { .compatible = "fsl,imx8mm-cm4", .data = _rproc_cfg_imx8mq },
{},
 };
 MODULE_DEVICE_TABLE(of, imx_rproc_of_match);
-- 
2.28.0



[PATCH V8 09/10] remoteproc: imx_rproc: ignore mapping vdev regions

2021-01-18 Thread peng . fan
From: Peng Fan 

vdev regions are vdev0vring0, vdev0vring1, vdevbuffer and similar.
They are handled by remoteproc common code, no need to map in imx
rproc driver.

Signed-off-by: Peng Fan 
Reviewed-by: Mathieu Poirier 
---
 drivers/remoteproc/imx_rproc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index fa01e64cc791..54ac143ba033 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -417,6 +417,9 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
struct resource res;
 
node = of_parse_phandle(np, "memory-region", a);
+   /* Not map vdev region */
+   if (!strcmp(node->name, "vdev"))
+   continue;
err = of_address_to_resource(node, 0, );
if (err) {
dev_err(dev, "unable to resolve memory region\n");
-- 
2.28.0



[PATCH V8 10/10] remoteproc: imx_proc: enable virtio/mailbox

2021-01-18 Thread peng . fan
From: Peng Fan 

Use virtio/mailbox to build connection between Remote Proccessors
and Linux. Add work queue to handle incoming messages.

Reviewed-by: Richard Zhu 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c | 116 -
 1 file changed, 113 insertions(+), 3 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 54ac143ba033..c16a91f8e410 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -15,6 +16,9 @@
 #include 
 #include 
 #include 
+#include 
+
+#include "remoteproc_internal.h"
 
 #define IMX7D_SRC_SCR  0x0C
 #define IMX7D_ENABLE_M4BIT(3)
@@ -86,6 +90,11 @@ struct imx_rproc {
const struct imx_rproc_dcfg *dcfg;
struct imx_rproc_memmem[IMX7D_RPROC_MEM_MAX];
struct clk  *clk;
+   struct mbox_client  cl;
+   struct mbox_chan*tx_ch;
+   struct mbox_chan*rx_ch;
+   struct work_struct  rproc_work;
+   struct workqueue_struct *workqueue;
 };
 
 static const struct imx_rproc_att imx_rproc_att_imx8mq[] = {
@@ -366,9 +375,33 @@ static int imx_rproc_parse_fw(struct rproc *rproc, const 
struct firmware *fw)
return 0;
 }
 
+static void imx_rproc_kick(struct rproc *rproc, int vqid)
+{
+   struct imx_rproc *priv = rproc->priv;
+   int err;
+   __u32 mmsg;
+
+   if (!priv->tx_ch) {
+   dev_err(priv->dev, "No initialized mbox tx channel\n");
+   return;
+   }
+
+   /*
+* Send the index of the triggered virtqueue as the mu payload.
+* Let remote processor know which virtqueue is used.
+*/
+   mmsg = vqid << 16;
+
+   err = mbox_send_message(priv->tx_ch, (void *));
+   if (err < 0)
+   dev_err(priv->dev, "%s: failed (%d, err:%d)\n",
+   __func__, vqid, err);
+}
+
 static const struct rproc_ops imx_rproc_ops = {
.start  = imx_rproc_start,
.stop   = imx_rproc_stop,
+   .kick   = imx_rproc_kick,
.da_to_va   = imx_rproc_da_to_va,
.load   = rproc_elf_load_segments,
.parse_fw   = imx_rproc_parse_fw,
@@ -444,6 +477,66 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
return 0;
 }
 
+static void imx_rproc_vq_work(struct work_struct *work)
+{
+   struct imx_rproc *priv = container_of(work, struct imx_rproc,
+ rproc_work);
+
+   rproc_vq_interrupt(priv->rproc, 0);
+   rproc_vq_interrupt(priv->rproc, 1);
+}
+
+static void imx_rproc_rx_callback(struct mbox_client *cl, void *msg)
+{
+   struct rproc *rproc = dev_get_drvdata(cl->dev);
+   struct imx_rproc *priv = rproc->priv;
+
+   queue_work(priv->workqueue, >rproc_work);
+}
+
+static int imx_rproc_xtr_mbox_init(struct rproc *rproc)
+{
+   struct imx_rproc *priv = rproc->priv;
+   struct device *dev = priv->dev;
+   struct mbox_client *cl;
+   int ret;
+
+   if (!of_get_property(dev->of_node, "mbox-names", NULL))
+   return 0;
+
+   cl = >cl;
+   cl->dev = dev;
+   cl->tx_block = true;
+   cl->tx_tout = 100;
+   cl->knows_txdone = false;
+   cl->rx_callback = imx_rproc_rx_callback;
+
+   priv->tx_ch = mbox_request_channel_byname(cl, "tx");
+   if (IS_ERR(priv->tx_ch)) {
+   ret = PTR_ERR(priv->tx_ch);
+   return dev_err_probe(cl->dev, ret,
+"failed to request tx mailbox channel: 
%d\n", ret);
+   }
+
+   priv->rx_ch = mbox_request_channel_byname(cl, "rx");
+   if (IS_ERR(priv->rx_ch)) {
+   mbox_free_channel(priv->tx_ch);
+   ret = PTR_ERR(priv->rx_ch);
+   return dev_err_probe(cl->dev, ret,
+"failed to request rx mailbox channel: 
%d\n", ret);
+   }
+
+   return 0;
+}
+
+static void imx_rproc_free_mbox(struct rproc *rproc)
+{
+   struct imx_rproc *priv = rproc->priv;
+
+   mbox_free_channel(priv->tx_ch);
+   mbox_free_channel(priv->rx_ch);
+}
+
 static int imx_rproc_probe(struct platform_device *pdev)
 {
struct device *dev = >dev;
@@ -481,18 +574,28 @@ static int imx_rproc_probe(struct platform_device *pdev)
priv->dev = dev;
 
dev_set_drvdata(dev, rproc);
+   priv->workqueue = create_workqueue(dev_name(dev));
+   if (!priv->workqueue) {
+   dev_err(dev, "cannot create workqueue\n");
+   ret = -ENOMEM;
+ 

[PATCH V8 05/10] remoteproc: imx_rproc: correct err message

2021-01-18 Thread peng . fan
From: Peng Fan 

It is using devm_ioremap, so not devm_ioremap_resource. Correct
the error message and print out sa/size.

Reviewed-by: Bjorn Andersson 
Reviewed-by: Mathieu Poirier 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 6603e00bb6f4..2a093cea4997 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -268,7 +268,7 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
priv->mem[b].cpu_addr = devm_ioremap(>dev,
 att->sa, att->size);
if (!priv->mem[b].cpu_addr) {
-   dev_err(dev, "devm_ioremap_resource failed\n");
+   dev_err(dev, "failed to remap %#x bytes from %#x\n", 
att->size, att->sa);
return -ENOMEM;
}
priv->mem[b].sys_addr = att->sa;
@@ -298,7 +298,7 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
 
priv->mem[b].cpu_addr = devm_ioremap_resource(>dev, );
if (IS_ERR(priv->mem[b].cpu_addr)) {
-   dev_err(dev, "devm_ioremap_resource failed\n");
+   dev_err(dev, "failed to remap %pr\n", );
err = PTR_ERR(priv->mem[b].cpu_addr);
return err;
}
-- 
2.28.0



[PATCH V8 02/10] dt-bindings: remoteproc: imx_rproc: add i.MX8MQ/M support

2021-01-18 Thread peng . fan
From: Peng Fan 

Add i.MX8MQ/M support, also include mailbox for rpmsg/virtio usage.

Signed-off-by: Peng Fan 
---
 .../bindings/remoteproc/fsl,imx-rproc.yaml| 49 +++
 1 file changed, 49 insertions(+)

diff --git a/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml 
b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
index bce6ccfe1538..b0d600baa161 100644
--- a/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
+++ b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
@@ -15,6 +15,8 @@ maintainers:
 properties:
   compatible:
 enum:
+  - fsl,imx8mq-cm4
+  - fsl,imx8mm-cm4
   - fsl,imx7d-cm4
   - fsl,imx6sx-cm4
 
@@ -26,6 +28,20 @@ properties:
 description:
   Phandle to syscon block which provide access to System Reset Controller
 
+  mbox-names:
+items:
+  - const: tx
+  - const: rx
+  - const: rxdb
+
+  mboxes:
+description:
+  This property is required only if the rpmsg/virtio functionality is used.
+  List of < type channel> - 1 channel for TX, 1 channel for RX, 1 
channel for RXDB.
+  (see mailbox/fsl,mu.yaml)
+minItems: 1
+maxItems: 3
+
   memory-region:
 description:
   list of phandels to the reserved memory regions.
@@ -56,4 +72,37 @@ examples:
   clocks   = < IMX7D_ARM_M4_ROOT_CLK>;
 };
 
+  - |
+#include 
+rsc_table: rsc_table@550ff000 {
+  no-map;
+  reg = <0x550ff000 0x1000>;
+};
+
+vdev0vring0: vdev0vring0@5500 {
+  no-map;
+  reg = <0x5500 0x8000>;
+};
+
+vdev0vring1: vdev0vring1@55008000 {
+  reg = <0x55008000 0x8000>;
+  no-map;
+};
+
+vdev0buffer: vdev0buffer@5540 {
+  compatible = "shared-dma-pool";
+  reg = <0x5540 0x10>;
+  no-map;
+};
+
+imx8mm-cm4 {
+  compatible = "fsl,imx8mm-cm4";
+  clocks = < IMX8MM_CLK_M4_DIV>;
+  mbox-names = "tx", "rx", "rxdb";
+  mboxes = < 0 1
+ 1 1
+ 3 1>;
+  memory-region = <>, <>, <>, 
<_table>;
+  syscon = <>;
+};
 ...
-- 
2.28.0



[PATCH V8 04/10] remoteproc: add is_iomem to da_to_va

2021-01-18 Thread peng . fan
From: Peng Fan 

Introduce an extra parameter is_iomem to da_to_va, then the caller
could take the memory as normal memory or io mapped memory.

Reviewed-by: Bjorn Andersson 
Reviewed-by: Mathieu Poirier 
Reported-by: kernel test robot 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c |  2 +-
 drivers/remoteproc/ingenic_rproc.c |  2 +-
 drivers/remoteproc/keystone_remoteproc.c   |  2 +-
 drivers/remoteproc/mtk_scp.c   |  6 +++---
 drivers/remoteproc/omap_remoteproc.c   |  2 +-
 drivers/remoteproc/pru_rproc.c |  2 +-
 drivers/remoteproc/qcom_q6v5_adsp.c|  2 +-
 drivers/remoteproc/qcom_q6v5_pas.c |  2 +-
 drivers/remoteproc/qcom_q6v5_wcss.c|  2 +-
 drivers/remoteproc/qcom_wcnss.c|  2 +-
 drivers/remoteproc/remoteproc_core.c   |  7 +--
 drivers/remoteproc/remoteproc_coredump.c   |  8 ++--
 drivers/remoteproc/remoteproc_debugfs.c|  2 +-
 drivers/remoteproc/remoteproc_elf_loader.c | 21 +++--
 drivers/remoteproc/remoteproc_internal.h   |  2 +-
 drivers/remoteproc/st_slim_rproc.c |  2 +-
 drivers/remoteproc/ti_k3_dsp_remoteproc.c  |  2 +-
 drivers/remoteproc/ti_k3_r5_remoteproc.c   |  2 +-
 drivers/remoteproc/wkup_m3_rproc.c |  2 +-
 include/linux/remoteproc.h |  2 +-
 20 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 8957ed271d20..6603e00bb6f4 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -208,7 +208,7 @@ static int imx_rproc_da_to_sys(struct imx_rproc *priv, u64 
da,
return -ENOENT;
 }
 
-static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool 
*is_iomem)
 {
struct imx_rproc *priv = rproc->priv;
void *va = NULL;
diff --git a/drivers/remoteproc/ingenic_rproc.c 
b/drivers/remoteproc/ingenic_rproc.c
index 26e19e6143b7..bb5049295576 100644
--- a/drivers/remoteproc/ingenic_rproc.c
+++ b/drivers/remoteproc/ingenic_rproc.c
@@ -116,7 +116,7 @@ static void ingenic_rproc_kick(struct rproc *rproc, int 
vqid)
writel(vqid, vpu->aux_base + REG_CORE_MSG);
 }
 
-static void *ingenic_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *ingenic_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, 
bool *is_iomem)
 {
struct vpu *vpu = rproc->priv;
void __iomem *va = NULL;
diff --git a/drivers/remoteproc/keystone_remoteproc.c 
b/drivers/remoteproc/keystone_remoteproc.c
index cd266163a65f..54781f553f4e 100644
--- a/drivers/remoteproc/keystone_remoteproc.c
+++ b/drivers/remoteproc/keystone_remoteproc.c
@@ -246,7 +246,7 @@ static void keystone_rproc_kick(struct rproc *rproc, int 
vqid)
  * can be used either by the remoteproc core for loading (when using kernel
  * remoteproc loader), or by any rpmsg bus drivers.
  */
-static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, 
bool *is_iomem)
 {
struct keystone_rproc *ksproc = rproc->priv;
void __iomem *va = NULL;
diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c
index e0c235690361..535175f013e4 100644
--- a/drivers/remoteproc/mtk_scp.c
+++ b/drivers/remoteproc/mtk_scp.c
@@ -270,7 +270,7 @@ static int scp_elf_load_segments(struct rproc *rproc, const 
struct firmware *fw)
}
 
/* grab the kernel address for this device address */
-   ptr = (void __iomem *)rproc_da_to_va(rproc, da, memsz);
+   ptr = (void __iomem *)rproc_da_to_va(rproc, da, memsz, NULL);
if (!ptr) {
dev_err(dev, "bad phdr da 0x%x mem 0x%x\n", da, memsz);
ret = -EINVAL;
@@ -458,7 +458,7 @@ static int scp_start(struct rproc *rproc)
return ret;
 }
 
-static void *scp_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *scp_da_to_va(struct rproc *rproc, u64 da, size_t len, bool 
*is_iomem)
 {
struct mtk_scp *scp = (struct mtk_scp *)rproc->priv;
int offset;
@@ -587,7 +587,7 @@ void *scp_mapping_dm_addr(struct mtk_scp *scp, u32 mem_addr)
 {
void *ptr;
 
-   ptr = scp_da_to_va(scp->rproc, mem_addr, 0);
+   ptr = scp_da_to_va(scp->rproc, mem_addr, 0, NULL);
if (!ptr)
return ERR_PTR(-EINVAL);
 
diff --git a/drivers/remoteproc/omap_remoteproc.c 
b/drivers/remoteproc/omap_remoteproc.c
index d94b7391bf9d..43531caa1959 100644
--- a/drivers/remoteproc/omap_remoteproc.c
+++ b/drivers/remoteproc/omap_remoteproc.c
@@ -728,7 +728,7 @@ static int omap_rproc_stop(struct rproc *rproc)
  * Return: translated virtual address in kernel memory space on success,
  * or NULL on failure.
  */
-static void *omap_rproc_da_to_va(struct r

[PATCH V8 01/10] dt-bindings: remoteproc: convert imx rproc bindings to json-schema

2021-01-18 Thread peng . fan
From: Peng Fan 

Convert the imx rproc binding to DT schema format using json-schema.

Signed-off-by: Peng Fan 
---
 .../bindings/remoteproc/fsl,imx-rproc.yaml| 59 +++
 .../bindings/remoteproc/imx-rproc.txt | 33 ---
 2 files changed, 59 insertions(+), 33 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
 delete mode 100644 Documentation/devicetree/bindings/remoteproc/imx-rproc.txt

diff --git a/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml 
b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
new file mode 100644
index ..bce6ccfe1538
--- /dev/null
+++ b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/remoteproc/fsl,imx-rproc.yaml#;
+$schema: "http://devicetree.org/meta-schemas/core.yaml#;
+
+title: NXP iMX6SX/iMX7D Co-Processor Bindings
+
+description:
+  This binding provides support for ARM Cortex M4 Co-processor found on some 
NXP iMX SoCs.
+
+maintainers:
+  - Peng Fan 
+
+properties:
+  compatible:
+enum:
+  - fsl,imx7d-cm4
+  - fsl,imx6sx-cm4
+
+  clocks:
+description:
+  Clock for co-processor (See ../clock/clock-bindings.txt)
+
+  syscon:
+description:
+  Phandle to syscon block which provide access to System Reset Controller
+
+  memory-region:
+description:
+  list of phandels to the reserved memory regions.
+  (see ../reserved-memory/reserved-memory.txt)
+
+required:
+  - compatible
+  - clocks
+  - syscon
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+m4_reserved_sysmem1: cm4@8000 {
+  reg = <0x8000 0x8>;
+};
+
+m4_reserved_sysmem2: cm4@8100 {
+  reg = <0x8100 0x8>;
+};
+
+imx7d-cm4 {
+  compatible   = "fsl,imx7d-cm4";
+  memory-region= <_reserved_sysmem1>, <_reserved_sysmem2>;
+  syscon   = <>;
+  clocks   = < IMX7D_ARM_M4_ROOT_CLK>;
+};
+
+...
diff --git a/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt 
b/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt
deleted file mode 100644
index fbcefd965dc4..
--- a/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-NXP iMX6SX/iMX7D Co-Processor Bindings
-
-
-This binding provides support for ARM Cortex M4 Co-processor found on some
-NXP iMX SoCs.
-
-Required properties:
-- compatible   Should be one of:
-   "fsl,imx7d-cm4"
-   "fsl,imx6sx-cm4"
-- clocks   Clock for co-processor (See: 
../clock/clock-bindings.txt)
-- syscon   Phandle to syscon block which provide access to
-   System Reset Controller
-
-Optional properties:
-- memory-regionlist of phandels to the reserved memory regions.
-   (See: ../reserved-memory/reserved-memory.txt)
-
-Example:
-   m4_reserved_sysmem1: cm4@8000 {
-   reg = <0x8000 0x8>;
-   };
-
-   m4_reserved_sysmem2: cm4@8100 {
-   reg = <0x8100 0x8>;
-   };
-
-   imx7d-cm4 {
-   compatible  = "fsl,imx7d-cm4";
-   memory-region   = <_reserved_sysmem1>, 
<_reserved_sysmem2>;
-   syscon  = <>;
-   clocks  = < IMX7D_ARM_M4_ROOT_CLK>;
-   };
-- 
2.28.0



[PATCH V7 05/10] remoteproc: imx_rproc: correct err message

2021-01-18 Thread peng . fan
From: Peng Fan 

It is using devm_ioremap, so not devm_ioremap_resource. Correct
the error message and print out sa/size.

Reviewed-by: Bjorn Andersson 
Reviewed-by: Mathieu Poirier 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 6603e00bb6f4..2a093cea4997 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -268,7 +268,7 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
priv->mem[b].cpu_addr = devm_ioremap(>dev,
 att->sa, att->size);
if (!priv->mem[b].cpu_addr) {
-   dev_err(dev, "devm_ioremap_resource failed\n");
+   dev_err(dev, "failed to remap %#x bytes from %#x\n", 
att->size, att->sa);
return -ENOMEM;
}
priv->mem[b].sys_addr = att->sa;
@@ -298,7 +298,7 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
 
priv->mem[b].cpu_addr = devm_ioremap_resource(>dev, );
if (IS_ERR(priv->mem[b].cpu_addr)) {
-   dev_err(dev, "devm_ioremap_resource failed\n");
+   dev_err(dev, "failed to remap %pr\n", );
err = PTR_ERR(priv->mem[b].cpu_addr);
return err;
}
-- 
2.28.0



[PATCH V7 07/10] remoteproc: imx_rproc: add i.MX specific parse fw hook

2021-01-18 Thread peng . fan
From: Peng Fan 

The hook is used to parse memory-regions and load resource table
from the address the remote processor published.

Reviewed-by: Richard Zhu 
Reviewed-by: Mathieu Poirier 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c | 93 ++
 1 file changed, 93 insertions(+)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 47fc1d06be6a..5ae1f5209548 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -241,10 +242,102 @@ static void *imx_rproc_da_to_va(struct rproc *rproc, u64 
da, size_t len, bool *i
return va;
 }
 
+static int imx_rproc_mem_alloc(struct rproc *rproc,
+  struct rproc_mem_entry *mem)
+{
+   struct device *dev = rproc->dev.parent;
+   void *va;
+
+   dev_dbg(dev, "map memory: %p+%zx\n", >dma, mem->len);
+   va = ioremap_wc(mem->dma, mem->len);
+   if (IS_ERR_OR_NULL(va)) {
+   dev_err(dev, "Unable to map memory region: %p+%zx\n",
+   >dma, mem->len);
+   return -ENOMEM;
+   }
+
+   /* Update memory entry va */
+   mem->va = va;
+
+   return 0;
+}
+
+static int imx_rproc_mem_release(struct rproc *rproc,
+struct rproc_mem_entry *mem)
+{
+   dev_dbg(rproc->dev.parent, "unmap memory: %pa\n", >dma);
+   iounmap(mem->va);
+
+   return 0;
+}
+
+static int imx_rproc_parse_memory_regions(struct rproc *rproc)
+{
+   struct imx_rproc *priv = rproc->priv;
+   struct device_node *np = priv->dev->of_node;
+   struct of_phandle_iterator it;
+   struct rproc_mem_entry *mem;
+   struct reserved_mem *rmem;
+   u32 da;
+
+   /* Register associated reserved memory regions */
+   of_phandle_iterator_init(, np, "memory-region", NULL, 0);
+   while (of_phandle_iterator_next() == 0) {
+   /*
+* Ignore the first memory region which will be used vdev 
buffer.
+* No need to do extra handlings, rproc_add_virtio_dev will 
handle it.
+*/
+   if (!strcmp(it.node->name, "vdev0buffer"))
+   continue;
+
+   rmem = of_reserved_mem_lookup(it.node);
+   if (!rmem) {
+   dev_err(priv->dev, "unable to acquire memory-region\n");
+   return -EINVAL;
+   }
+
+   /* No need to translate pa to da, i.MX use same map */
+   da = rmem->base;
+
+   /* Register memory region */
+   mem = rproc_mem_entry_init(priv->dev, NULL, 
(dma_addr_t)rmem->base, rmem->size, da,
+  imx_rproc_mem_alloc, 
imx_rproc_mem_release,
+  it.node->name);
+
+   if (mem)
+   rproc_coredump_add_segment(rproc, da, rmem->size);
+   else
+   return -ENOMEM;
+
+   rproc_add_carveout(rproc, mem);
+   }
+
+   return  0;
+}
+
+static int imx_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
+{
+   int ret = imx_rproc_parse_memory_regions(rproc);
+
+   if (ret)
+   return ret;
+
+   ret = rproc_elf_load_rsc_table(rproc, fw);
+   if (ret)
+   dev_info(>dev, "No resource table in elf\n");
+
+   return 0;
+}
+
 static const struct rproc_ops imx_rproc_ops = {
.start  = imx_rproc_start,
.stop   = imx_rproc_stop,
.da_to_va   = imx_rproc_da_to_va,
+   .load   = rproc_elf_load_segments,
+   .parse_fw   = imx_rproc_parse_fw,
+   .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table,
+   .sanity_check   = rproc_elf_sanity_check,
+   .get_boot_addr  = rproc_elf_get_boot_addr,
 };
 
 static int imx_rproc_addr_init(struct imx_rproc *priv,
-- 
2.28.0



[PATCH V7 09/10] remoteproc: imx_rproc: ignore mapping vdev regions

2021-01-18 Thread peng . fan
From: Peng Fan 

vdev regions are vdev0vring0, vdev0vring1, vdevbuffer and similar.
They are handled by remoteproc common code, no need to map in imx
rproc driver.

Signed-off-by: Peng Fan 
Reviewed-by: Mathieu Poirier 
---
 drivers/remoteproc/imx_rproc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index fa01e64cc791..54ac143ba033 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -417,6 +417,9 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
struct resource res;
 
node = of_parse_phandle(np, "memory-region", a);
+   /* Not map vdev region */
+   if (!strcmp(node->name, "vdev"))
+   continue;
err = of_address_to_resource(node, 0, );
if (err) {
dev_err(dev, "unable to resolve memory region\n");
-- 
2.28.0



[PATCH V7 04/10] remoteproc: add is_iomem to da_to_va

2021-01-18 Thread peng . fan
From: Peng Fan 

Introduce an extra parameter is_iomem to da_to_va, then the caller
could take the memory as normal memory or io mapped memory.

Reviewed-by: Bjorn Andersson 
Signed-off-by: Peng Fan 
Reviewed-by: Mathieu Poirier 
---
 drivers/remoteproc/imx_rproc.c |  2 +-
 drivers/remoteproc/ingenic_rproc.c |  2 +-
 drivers/remoteproc/keystone_remoteproc.c   |  2 +-
 drivers/remoteproc/mtk_scp.c   |  6 +++---
 drivers/remoteproc/omap_remoteproc.c   |  2 +-
 drivers/remoteproc/pru_rproc.c |  2 +-
 drivers/remoteproc/qcom_q6v5_adsp.c|  2 +-
 drivers/remoteproc/qcom_q6v5_pas.c |  2 +-
 drivers/remoteproc/qcom_q6v5_wcss.c|  2 +-
 drivers/remoteproc/qcom_wcnss.c|  2 +-
 drivers/remoteproc/remoteproc_core.c   |  7 +--
 drivers/remoteproc/remoteproc_coredump.c   |  8 ++--
 drivers/remoteproc/remoteproc_debugfs.c|  2 +-
 drivers/remoteproc/remoteproc_elf_loader.c | 21 +++--
 drivers/remoteproc/remoteproc_internal.h   |  2 +-
 drivers/remoteproc/st_slim_rproc.c |  2 +-
 drivers/remoteproc/ti_k3_dsp_remoteproc.c  |  2 +-
 drivers/remoteproc/ti_k3_r5_remoteproc.c   |  2 +-
 drivers/remoteproc/wkup_m3_rproc.c |  2 +-
 include/linux/remoteproc.h |  2 +-
 20 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 8957ed271d20..6603e00bb6f4 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -208,7 +208,7 @@ static int imx_rproc_da_to_sys(struct imx_rproc *priv, u64 
da,
return -ENOENT;
 }
 
-static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool 
*is_iomem)
 {
struct imx_rproc *priv = rproc->priv;
void *va = NULL;
diff --git a/drivers/remoteproc/ingenic_rproc.c 
b/drivers/remoteproc/ingenic_rproc.c
index 26e19e6143b7..bb5049295576 100644
--- a/drivers/remoteproc/ingenic_rproc.c
+++ b/drivers/remoteproc/ingenic_rproc.c
@@ -116,7 +116,7 @@ static void ingenic_rproc_kick(struct rproc *rproc, int 
vqid)
writel(vqid, vpu->aux_base + REG_CORE_MSG);
 }
 
-static void *ingenic_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *ingenic_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, 
bool *is_iomem)
 {
struct vpu *vpu = rproc->priv;
void __iomem *va = NULL;
diff --git a/drivers/remoteproc/keystone_remoteproc.c 
b/drivers/remoteproc/keystone_remoteproc.c
index cd266163a65f..54781f553f4e 100644
--- a/drivers/remoteproc/keystone_remoteproc.c
+++ b/drivers/remoteproc/keystone_remoteproc.c
@@ -246,7 +246,7 @@ static void keystone_rproc_kick(struct rproc *rproc, int 
vqid)
  * can be used either by the remoteproc core for loading (when using kernel
  * remoteproc loader), or by any rpmsg bus drivers.
  */
-static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, 
bool *is_iomem)
 {
struct keystone_rproc *ksproc = rproc->priv;
void __iomem *va = NULL;
diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c
index e0c235690361..535175f013e4 100644
--- a/drivers/remoteproc/mtk_scp.c
+++ b/drivers/remoteproc/mtk_scp.c
@@ -270,7 +270,7 @@ static int scp_elf_load_segments(struct rproc *rproc, const 
struct firmware *fw)
}
 
/* grab the kernel address for this device address */
-   ptr = (void __iomem *)rproc_da_to_va(rproc, da, memsz);
+   ptr = (void __iomem *)rproc_da_to_va(rproc, da, memsz, NULL);
if (!ptr) {
dev_err(dev, "bad phdr da 0x%x mem 0x%x\n", da, memsz);
ret = -EINVAL;
@@ -458,7 +458,7 @@ static int scp_start(struct rproc *rproc)
return ret;
 }
 
-static void *scp_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *scp_da_to_va(struct rproc *rproc, u64 da, size_t len, bool 
*is_iomem)
 {
struct mtk_scp *scp = (struct mtk_scp *)rproc->priv;
int offset;
@@ -587,7 +587,7 @@ void *scp_mapping_dm_addr(struct mtk_scp *scp, u32 mem_addr)
 {
void *ptr;
 
-   ptr = scp_da_to_va(scp->rproc, mem_addr, 0);
+   ptr = scp_da_to_va(scp->rproc, mem_addr, 0, NULL);
if (!ptr)
return ERR_PTR(-EINVAL);
 
diff --git a/drivers/remoteproc/omap_remoteproc.c 
b/drivers/remoteproc/omap_remoteproc.c
index d94b7391bf9d..43531caa1959 100644
--- a/drivers/remoteproc/omap_remoteproc.c
+++ b/drivers/remoteproc/omap_remoteproc.c
@@ -728,7 +728,7 @@ static int omap_rproc_stop(struct rproc *rproc)
  * Return: translated virtual address in kernel memory space on success,
  * or NULL on failure.
  */
-static void *omap_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+s

[PATCH V7 02/10] dt-bindings: remoteproc: imx_rproc: add i.MX8MQ/M support

2021-01-18 Thread peng . fan
From: Peng Fan 

Add i.MX8MQ/M support, also include mailbox for rpmsg/virtio usage.

Signed-off-by: Peng Fan 
---
 .../bindings/remoteproc/fsl,imx-rproc.yaml| 49 +++
 1 file changed, 49 insertions(+)

diff --git a/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml 
b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
index bce6ccfe1538..b0d600baa161 100644
--- a/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
+++ b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
@@ -15,6 +15,8 @@ maintainers:
 properties:
   compatible:
 enum:
+  - fsl,imx8mq-cm4
+  - fsl,imx8mm-cm4
   - fsl,imx7d-cm4
   - fsl,imx6sx-cm4
 
@@ -26,6 +28,20 @@ properties:
 description:
   Phandle to syscon block which provide access to System Reset Controller
 
+  mbox-names:
+items:
+  - const: tx
+  - const: rx
+  - const: rxdb
+
+  mboxes:
+description:
+  This property is required only if the rpmsg/virtio functionality is used.
+  List of < type channel> - 1 channel for TX, 1 channel for RX, 1 
channel for RXDB.
+  (see mailbox/fsl,mu.yaml)
+minItems: 1
+maxItems: 3
+
   memory-region:
 description:
   list of phandels to the reserved memory regions.
@@ -56,4 +72,37 @@ examples:
   clocks   = < IMX7D_ARM_M4_ROOT_CLK>;
 };
 
+  - |
+#include 
+rsc_table: rsc_table@550ff000 {
+  no-map;
+  reg = <0x550ff000 0x1000>;
+};
+
+vdev0vring0: vdev0vring0@5500 {
+  no-map;
+  reg = <0x5500 0x8000>;
+};
+
+vdev0vring1: vdev0vring1@55008000 {
+  reg = <0x55008000 0x8000>;
+  no-map;
+};
+
+vdev0buffer: vdev0buffer@5540 {
+  compatible = "shared-dma-pool";
+  reg = <0x5540 0x10>;
+  no-map;
+};
+
+imx8mm-cm4 {
+  compatible = "fsl,imx8mm-cm4";
+  clocks = < IMX8MM_CLK_M4_DIV>;
+  mbox-names = "tx", "rx", "rxdb";
+  mboxes = < 0 1
+ 1 1
+ 3 1>;
+  memory-region = <>, <>, <>, 
<_table>;
+  syscon = <>;
+};
 ...
-- 
2.28.0



[PATCH V7 10/10] remoteproc: imx_proc: enable virtio/mailbox

2021-01-18 Thread peng . fan
From: Peng Fan 

Use virtio/mailbox to build connection between Remote Proccessors
and Linux. Add work queue to handle incoming messages.

Reviewed-by: Richard Zhu 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c | 116 -
 1 file changed, 113 insertions(+), 3 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 54ac143ba033..c16a91f8e410 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -15,6 +16,9 @@
 #include 
 #include 
 #include 
+#include 
+
+#include "remoteproc_internal.h"
 
 #define IMX7D_SRC_SCR  0x0C
 #define IMX7D_ENABLE_M4BIT(3)
@@ -86,6 +90,11 @@ struct imx_rproc {
const struct imx_rproc_dcfg *dcfg;
struct imx_rproc_memmem[IMX7D_RPROC_MEM_MAX];
struct clk  *clk;
+   struct mbox_client  cl;
+   struct mbox_chan*tx_ch;
+   struct mbox_chan*rx_ch;
+   struct work_struct  rproc_work;
+   struct workqueue_struct *workqueue;
 };
 
 static const struct imx_rproc_att imx_rproc_att_imx8mq[] = {
@@ -366,9 +375,33 @@ static int imx_rproc_parse_fw(struct rproc *rproc, const 
struct firmware *fw)
return 0;
 }
 
+static void imx_rproc_kick(struct rproc *rproc, int vqid)
+{
+   struct imx_rproc *priv = rproc->priv;
+   int err;
+   __u32 mmsg;
+
+   if (!priv->tx_ch) {
+   dev_err(priv->dev, "No initialized mbox tx channel\n");
+   return;
+   }
+
+   /*
+* Send the index of the triggered virtqueue as the mu payload.
+* Let remote processor know which virtqueue is used.
+*/
+   mmsg = vqid << 16;
+
+   err = mbox_send_message(priv->tx_ch, (void *));
+   if (err < 0)
+   dev_err(priv->dev, "%s: failed (%d, err:%d)\n",
+   __func__, vqid, err);
+}
+
 static const struct rproc_ops imx_rproc_ops = {
.start  = imx_rproc_start,
.stop   = imx_rproc_stop,
+   .kick   = imx_rproc_kick,
.da_to_va   = imx_rproc_da_to_va,
.load   = rproc_elf_load_segments,
.parse_fw   = imx_rproc_parse_fw,
@@ -444,6 +477,66 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
return 0;
 }
 
+static void imx_rproc_vq_work(struct work_struct *work)
+{
+   struct imx_rproc *priv = container_of(work, struct imx_rproc,
+ rproc_work);
+
+   rproc_vq_interrupt(priv->rproc, 0);
+   rproc_vq_interrupt(priv->rproc, 1);
+}
+
+static void imx_rproc_rx_callback(struct mbox_client *cl, void *msg)
+{
+   struct rproc *rproc = dev_get_drvdata(cl->dev);
+   struct imx_rproc *priv = rproc->priv;
+
+   queue_work(priv->workqueue, >rproc_work);
+}
+
+static int imx_rproc_xtr_mbox_init(struct rproc *rproc)
+{
+   struct imx_rproc *priv = rproc->priv;
+   struct device *dev = priv->dev;
+   struct mbox_client *cl;
+   int ret;
+
+   if (!of_get_property(dev->of_node, "mbox-names", NULL))
+   return 0;
+
+   cl = >cl;
+   cl->dev = dev;
+   cl->tx_block = true;
+   cl->tx_tout = 100;
+   cl->knows_txdone = false;
+   cl->rx_callback = imx_rproc_rx_callback;
+
+   priv->tx_ch = mbox_request_channel_byname(cl, "tx");
+   if (IS_ERR(priv->tx_ch)) {
+   ret = PTR_ERR(priv->tx_ch);
+   return dev_err_probe(cl->dev, ret,
+"failed to request tx mailbox channel: 
%d\n", ret);
+   }
+
+   priv->rx_ch = mbox_request_channel_byname(cl, "rx");
+   if (IS_ERR(priv->rx_ch)) {
+   mbox_free_channel(priv->tx_ch);
+   ret = PTR_ERR(priv->rx_ch);
+   return dev_err_probe(cl->dev, ret,
+"failed to request rx mailbox channel: 
%d\n", ret);
+   }
+
+   return 0;
+}
+
+static void imx_rproc_free_mbox(struct rproc *rproc)
+{
+   struct imx_rproc *priv = rproc->priv;
+
+   mbox_free_channel(priv->tx_ch);
+   mbox_free_channel(priv->rx_ch);
+}
+
 static int imx_rproc_probe(struct platform_device *pdev)
 {
struct device *dev = >dev;
@@ -481,18 +574,28 @@ static int imx_rproc_probe(struct platform_device *pdev)
priv->dev = dev;
 
dev_set_drvdata(dev, rproc);
+   priv->workqueue = create_workqueue(dev_name(dev));
+   if (!priv->workqueue) {
+   dev_err(dev, "cannot create workqueue\n");
+   ret = -ENOMEM;
+ 

[PATCH V7 08/10] remoteproc: imx_rproc: support i.MX8MQ/M

2021-01-18 Thread peng . fan
From: Peng Fan 

Add i.MX8MQ dev/sys addr map and configuration data structure
i.MX8MM share i.MX8MQ settings.

Reviewed-by: Richard Zhu 
Signed-off-by: Peng Fan 
Reviewed-by: Mathieu Poirier 
---
 drivers/remoteproc/imx_rproc.c | 39 ++
 1 file changed, 39 insertions(+)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 5ae1f5209548..fa01e64cc791 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -88,6 +88,34 @@ struct imx_rproc {
struct clk  *clk;
 };
 
+static const struct imx_rproc_att imx_rproc_att_imx8mq[] = {
+   /* dev addr , sys addr  , size  , flags */
+   /* TCML - alias */
+   { 0x, 0x007e, 0x0002, 0 },
+   /* OCRAM_S */
+   { 0x0018, 0x0018, 0x8000, 0 },
+   /* OCRAM */
+   { 0x0090, 0x0090, 0x0002, 0 },
+   /* OCRAM */
+   { 0x0092, 0x0092, 0x0002, 0 },
+   /* QSPI Code - alias */
+   { 0x0800, 0x0800, 0x0800, 0 },
+   /* DDR (Code) - alias */
+   { 0x1000, 0x8000, 0x0FFE, 0 },
+   /* TCML */
+   { 0x1FFE, 0x007E, 0x0002, ATT_OWN },
+   /* TCMU */
+   { 0x2000, 0x0080, 0x0002, ATT_OWN },
+   /* OCRAM_S */
+   { 0x2018, 0x0018, 0x8000, ATT_OWN },
+   /* OCRAM */
+   { 0x2020, 0x0090, 0x0002, ATT_OWN },
+   /* OCRAM */
+   { 0x2022, 0x0092, 0x0002, ATT_OWN },
+   /* DDR (Data) */
+   { 0x4000, 0x4000, 0x8000, 0 },
+};
+
 static const struct imx_rproc_att imx_rproc_att_imx7d[] = {
/* dev addr , sys addr  , size  , flags */
/* OCRAM_S (M4 Boot code) - alias */
@@ -138,6 +166,15 @@ static const struct imx_rproc_att imx_rproc_att_imx6sx[] = 
{
{ 0x8000, 0x8000, 0x6000, 0 },
 };
 
+static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mq = {
+   .src_reg= IMX7D_SRC_SCR,
+   .src_mask   = IMX7D_M4_RST_MASK,
+   .src_start  = IMX7D_M4_START,
+   .src_stop   = IMX7D_M4_STOP,
+   .att= imx_rproc_att_imx8mq,
+   .att_size   = ARRAY_SIZE(imx_rproc_att_imx8mq),
+};
+
 static const struct imx_rproc_dcfg imx_rproc_cfg_imx7d = {
.src_reg= IMX7D_SRC_SCR,
.src_mask   = IMX7D_M4_RST_MASK,
@@ -496,6 +533,8 @@ static int imx_rproc_remove(struct platform_device *pdev)
 static const struct of_device_id imx_rproc_of_match[] = {
{ .compatible = "fsl,imx7d-cm4", .data = _rproc_cfg_imx7d },
{ .compatible = "fsl,imx6sx-cm4", .data = _rproc_cfg_imx6sx },
+   { .compatible = "fsl,imx8mq-cm4", .data = _rproc_cfg_imx8mq },
+   { .compatible = "fsl,imx8mm-cm4", .data = _rproc_cfg_imx8mq },
{},
 };
 MODULE_DEVICE_TABLE(of, imx_rproc_of_match);
-- 
2.28.0



[PATCH V7 03/10] remoteproc: introduce is_iomem to rproc_mem_entry

2021-01-18 Thread peng . fan
From: Peng Fan 

Introduce is_iomem to indicate this piece memory is iomem or not.

Reviewed-by: Bjorn Andersson 
Signed-off-by: Peng Fan 
Reviewed-by: Mathieu Poirier 
---
 include/linux/remoteproc.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index f28ee75d1005..a5f6d2d9cde2 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -315,6 +315,7 @@ struct rproc;
 /**
  * struct rproc_mem_entry - memory entry descriptor
  * @va:virtual address
+ * @is_iomem: io memory
  * @dma: dma address
  * @len: length, in bytes
  * @da: device address
@@ -329,6 +330,7 @@ struct rproc;
  */
 struct rproc_mem_entry {
void *va;
+   bool is_iomem;
dma_addr_t dma;
size_t len;
u32 da;
-- 
2.28.0



[PATCH V7 06/10] remoteproc: imx_rproc: use devm_ioremap

2021-01-18 Thread peng . fan
From: Peng Fan 

We might need to map an region multiple times, becaue the region might
be shared between remote processors, such i.MX8QM with dual M4 cores.
So use devm_ioremap, not devm_ioremap_resource.

Reviewed-by: Oleksij Rempel 
Reviewed-by: Richard Zhu 
Signed-off-by: Peng Fan 
Reviewed-by: Mathieu Poirier 
---
 drivers/remoteproc/imx_rproc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 2a093cea4997..47fc1d06be6a 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -296,7 +296,8 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
if (b >= IMX7D_RPROC_MEM_MAX)
break;
 
-   priv->mem[b].cpu_addr = devm_ioremap_resource(>dev, );
+   /* Not use resource version, because we might share region */
+   priv->mem[b].cpu_addr = devm_ioremap(>dev, res.start, 
resource_size());
if (IS_ERR(priv->mem[b].cpu_addr)) {
dev_err(dev, "failed to remap %pr\n", );
err = PTR_ERR(priv->mem[b].cpu_addr);
-- 
2.28.0



[PATCH V7 01/10] dt-bindings: remoteproc: convert imx rproc bindings to json-schema

2021-01-18 Thread peng . fan
From: Peng Fan 

Convert the imx rproc binding to DT schema format using json-schema.

Signed-off-by: Peng Fan 
---
 .../bindings/remoteproc/fsl,imx-rproc.yaml| 59 +++
 .../bindings/remoteproc/imx-rproc.txt | 33 ---
 2 files changed, 59 insertions(+), 33 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
 delete mode 100644 Documentation/devicetree/bindings/remoteproc/imx-rproc.txt

diff --git a/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml 
b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
new file mode 100644
index ..bce6ccfe1538
--- /dev/null
+++ b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/remoteproc/fsl,imx-rproc.yaml#;
+$schema: "http://devicetree.org/meta-schemas/core.yaml#;
+
+title: NXP iMX6SX/iMX7D Co-Processor Bindings
+
+description:
+  This binding provides support for ARM Cortex M4 Co-processor found on some 
NXP iMX SoCs.
+
+maintainers:
+  - Peng Fan 
+
+properties:
+  compatible:
+enum:
+  - fsl,imx7d-cm4
+  - fsl,imx6sx-cm4
+
+  clocks:
+description:
+  Clock for co-processor (See ../clock/clock-bindings.txt)
+
+  syscon:
+description:
+  Phandle to syscon block which provide access to System Reset Controller
+
+  memory-region:
+description:
+  list of phandels to the reserved memory regions.
+  (see ../reserved-memory/reserved-memory.txt)
+
+required:
+  - compatible
+  - clocks
+  - syscon
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+m4_reserved_sysmem1: cm4@8000 {
+  reg = <0x8000 0x8>;
+};
+
+m4_reserved_sysmem2: cm4@8100 {
+  reg = <0x8100 0x8>;
+};
+
+imx7d-cm4 {
+  compatible   = "fsl,imx7d-cm4";
+  memory-region= <_reserved_sysmem1>, <_reserved_sysmem2>;
+  syscon   = <>;
+  clocks   = < IMX7D_ARM_M4_ROOT_CLK>;
+};
+
+...
diff --git a/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt 
b/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt
deleted file mode 100644
index fbcefd965dc4..
--- a/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-NXP iMX6SX/iMX7D Co-Processor Bindings
-
-
-This binding provides support for ARM Cortex M4 Co-processor found on some
-NXP iMX SoCs.
-
-Required properties:
-- compatible   Should be one of:
-   "fsl,imx7d-cm4"
-   "fsl,imx6sx-cm4"
-- clocks   Clock for co-processor (See: 
../clock/clock-bindings.txt)
-- syscon   Phandle to syscon block which provide access to
-   System Reset Controller
-
-Optional properties:
-- memory-regionlist of phandels to the reserved memory regions.
-   (See: ../reserved-memory/reserved-memory.txt)
-
-Example:
-   m4_reserved_sysmem1: cm4@8000 {
-   reg = <0x8000 0x8>;
-   };
-
-   m4_reserved_sysmem2: cm4@8100 {
-   reg = <0x8100 0x8>;
-   };
-
-   imx7d-cm4 {
-   compatible  = "fsl,imx7d-cm4";
-   memory-region   = <_reserved_sysmem1>, 
<_reserved_sysmem2>;
-   syscon  = <>;
-   clocks  = < IMX7D_ARM_M4_ROOT_CLK>;
-   };
-- 
2.28.0



[PATCH V7 00/10] remoteproc: imx_rproc: support iMX8MQ/M

2021-01-18 Thread peng . fan
From: Peng Fan 

V7:
 Add R-b tag from Mathieu
 vdevbuffer->vdev0buffer in patch 1/10, 7/10
 correct err msg and shutdown seq per Mathieu's comments in patch 10/10
 Hope this version is ok to be merged.
 
V6:
 Add R-b tag from Mathieu
 Convert imx-rproc.txt to yaml and add dt-bindings support for i.MX8MQ/M, patch 
1/10 2/10
 No other changes.

V5:
 Apply on Linux next
 Add V5 subject prefix
 Add R-b tag from Bjorn for 1/8, 2/8, 3/8
 
https://patchwork.kernel.org/project/linux-remoteproc/cover/20201229033019.25899-1-peng@nxp.com/

V4:
 According to Bjorn's comments, add is_iomem for da to va usage
 1/8, 2/8 is new patch
 3/8, follow Bjorn's comments to correct/update the err msg.
 6/8, new patch
 8/8, use dev_err_probe to simplify code, use queue_work instead 
schedule_delayed_work

V3:
 Since I was quite busy in the past days, V3 is late
 Rebased on Linux-next
 Add R-b tags
 1/7: Add R-b tag of Mathieu, add comments
 4/7: Typo fix
 5/7: Add R-b tag of Mathieu, drop index Per Mathieu's comments
 6/7: Add R-b tag of Mathieu
 7/7: Add comment for vqid << 16, drop unneeded timeout settings of mailbox
  Use queue_work instead of schedule_delayed_work
  free mbox channels when remove
 https://lkml.org/lkml/2020/12/4/82

V2:
 Rebased on linux-next
 Dropped early boot feature to make patchset simple.
 Drop rsc-da
 
https://patchwork.kernel.org/project/linux-remoteproc/cover/20200927064131.24101-1-peng@nxp.com/

V1:
 https://patchwork.kernel.org/cover/11682461/

This patchset is to support i.MX8MQ/M coproc.
The early boot feature was dropped to make the patchset small in V2.

Since i.MX specific TCM memory requirement, add elf platform hook.
Several patches have got reviewed by Oleksij and Mathieu in v1.




Peng Fan (10):
  dt-bindings: remoteproc: convert imx rproc bindings to json-schema
  dt-bindings: remoteproc: imx_rproc: add i.MX8MQ/M support
  remoteproc: introduce is_iomem to rproc_mem_entry
  remoteproc: add is_iomem to da_to_va
  remoteproc: imx_rproc: correct err message
  remoteproc: imx_rproc: use devm_ioremap
  remoteproc: imx_rproc: add i.MX specific parse fw hook
  remoteproc: imx_rproc: support i.MX8MQ/M
  remoteproc: imx_rproc: ignore mapping vdev regions
  remoteproc: imx_proc: enable virtio/mailbox

 .../bindings/remoteproc/fsl,imx-rproc.yaml| 108 
 .../bindings/remoteproc/imx-rproc.txt |  33 ---
 drivers/remoteproc/imx_rproc.c| 260 +-
 drivers/remoteproc/ingenic_rproc.c|   2 +-
 drivers/remoteproc/keystone_remoteproc.c  |   2 +-
 drivers/remoteproc/mtk_scp.c  |   6 +-
 drivers/remoteproc/omap_remoteproc.c  |   2 +-
 drivers/remoteproc/pru_rproc.c|   2 +-
 drivers/remoteproc/qcom_q6v5_adsp.c   |   2 +-
 drivers/remoteproc/qcom_q6v5_pas.c|   2 +-
 drivers/remoteproc/qcom_q6v5_wcss.c   |   2 +-
 drivers/remoteproc/qcom_wcnss.c   |   2 +-
 drivers/remoteproc/remoteproc_core.c  |   7 +-
 drivers/remoteproc/remoteproc_coredump.c  |   8 +-
 drivers/remoteproc/remoteproc_debugfs.c   |   2 +-
 drivers/remoteproc/remoteproc_elf_loader.c|  21 +-
 drivers/remoteproc/remoteproc_internal.h  |   2 +-
 drivers/remoteproc/st_slim_rproc.c|   2 +-
 drivers/remoteproc/ti_k3_dsp_remoteproc.c |   2 +-
 drivers/remoteproc/ti_k3_r5_remoteproc.c  |   2 +-
 drivers/remoteproc/wkup_m3_rproc.c|   2 +-
 include/linux/remoteproc.h|   4 +-
 22 files changed, 407 insertions(+), 68 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
 delete mode 100644 Documentation/devicetree/bindings/remoteproc/imx-rproc.txt

-- 
2.28.0



RE: [PATCH V5 7/8] remoteproc: imx_rproc: ignore mapping vdev regions

2021-01-14 Thread Peng Fan
> Subject: Re: [PATCH V5 7/8] remoteproc: imx_rproc: ignore mapping vdev
> regions
> 
> On Thu, Jan 14, 2021 at 09:52:13AM +0000, Peng Fan wrote:
> > > Subject: Re: [PATCH V5 7/8] remoteproc: imx_rproc: ignore mapping
> > > vdev regions
> > >
> > > On Wed, Jan 13, 2021 at 02:19:32AM +, Peng Fan wrote:
> > > > > Subject: Re: [PATCH V5 7/8] remoteproc: imx_rproc: ignore
> > > > > mapping vdev regions
> > > > >
> > > > > On Tue, Jan 12, 2021 at 09:41:12AM +, Peng Fan wrote:
> > > > > > > Subject: Re: [PATCH V5 7/8] remoteproc: imx_rproc: ignore
> > > > > > > mapping vdev regions
> > > > > > >
> > > > > > > On Tue, Dec 29, 2020 at 11:30:18AM +0800, peng@nxp.com
> > > wrote:
> > > > > > > > From: Peng Fan 
> > > > > > > >
> > > > > > > > vdev regions are vdev0vring0, vdev0vring1, vdevbuffer and
> similar.
> > > > > > > > They are handled by remoteproc common code, no need to map
> > > > > > > > in imx rproc driver.
> > > > > > > >
> > > > > > > > Signed-off-by: Peng Fan 
> > > > > > > > ---
> > > > > > > >  drivers/remoteproc/imx_rproc.c | 3 +++
> > > > > > > >  1 file changed, 3 insertions(+)
> > > > > > > >
> > > > > > > > diff --git a/drivers/remoteproc/imx_rproc.c
> > > > > > > > b/drivers/remoteproc/imx_rproc.c index
> > > > > > > > f80428afb8a7..e62a53ee128e
> > > > > > > > 100644
> > > > > > > > --- a/drivers/remoteproc/imx_rproc.c
> > > > > > > > +++ b/drivers/remoteproc/imx_rproc.c
> > > > > > > > @@ -417,6 +417,9 @@ static int imx_rproc_addr_init(struct
> > > > > > > > imx_rproc
> > > > > > > *priv,
> > > > > > > > struct resource res;
> > > > > > > >
> > > > > > > > node = of_parse_phandle(np, "memory-region", a);
> > > > > > > > +   /* Not map vdev region */
> > > > > > > > +   if (!strcmp(node->name, "vdev"))
> > > > > > > > +   continue;
> > > > > > >
> > > > > > > I am very confused and because I don't see an example for
> > > > > > > the DT in the bindings document I have to guess what is going on.
> > > > > >
> > > > > > V6 will include the DT yaml.
> > > > > >
> > > > > > >
> > > > > > > So I am guessing that you have laid out the memory regions
> > > > > > > for the vrings and the vdev0buffer in the DT "memory-region".
> > > > > >
> > > > > > The dts part will be similar as following:
> > > > > >
> > > > > > +#include 
> > > > > > +rsc_table: rsc_table@550ff000 {
> > > > > > +  no-map;
> > > > > > +  reg = <0x550ff000 0x1000>;
> > > > > > +};
> > > > > > +
> > > > > > +vdev0vring0: vdev0vring0@5500 {
> > > > > > +  no-map;
> > > > > > +  reg = <0x5500 0x8000>;
> > > > > > +};
> > > > > > +
> > > > > > +vdev0vring1: vdev0vring1@55008000 {
> > > > > > +  reg = <0x55008000 0x8000>;
> > > > > > +  no-map;
> > > > > > +};
> > > > > > +
> > > > > > +vdevbuffer: vdevbuffer@5540 {
> > > > > > +  compatible = "shared-dma-pool";
> > > > > > +  reg = <0x5540 0x10>;
> > > > > > +  no-map;
> > > > > > +};
> > > > > > +
> > > > > > +imx8mm-cm4 {
> > > > > > +  compatible = "fsl,imx8mm-cm4";
> > > > > > +  clocks = < IMX8MM_CLK_M4_DIV>;
> > > > > > +  mbox-names = "tx", "rx", "rxdb";
> > > > > > +  mboxes = < 0 1
> > > > > > + 1 1
> >

RE: [PATCH V6 07/10] remoteproc: imx_rproc: add i.MX specific parse fw hook

2021-01-14 Thread Peng Fan
> Subject: Re: [PATCH V6 07/10] remoteproc: imx_rproc: add i.MX specific
> parse fw hook
> 
> On Tue, Jan 12, 2021 at 05:39:16PM +0800, peng@nxp.com wrote:
> > From: Peng Fan 
> >
> > The hook is used to parse memory-regions and load resource table from
> > the address the remote processor published.
> >
> > Signed-off-by: Peng Fan 
> > Reviewed-by: Richard Zhu 
> > Reviewed-by: Mathieu Poirier 
> > ---
> >  drivers/remoteproc/imx_rproc.c | 93
> > ++
> >  1 file changed, 93 insertions(+)
> >
> > diff --git a/drivers/remoteproc/imx_rproc.c
> > b/drivers/remoteproc/imx_rproc.c index 47fc1d06be6a..3c0075dc1787
> > 100644
> > --- a/drivers/remoteproc/imx_rproc.c
> > +++ b/drivers/remoteproc/imx_rproc.c
> > @@ -10,6 +10,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -241,10 +242,102 @@ static void *imx_rproc_da_to_va(struct rproc
> *rproc, u64 da, size_t len, bool *i
> > return va;
> >  }
> >
> > +static int imx_rproc_mem_alloc(struct rproc *rproc,
> > +  struct rproc_mem_entry *mem) {
> > +   struct device *dev = rproc->dev.parent;
> > +   void *va;
> > +
> > +   dev_dbg(dev, "map memory: %p+%zx\n", >dma, mem->len);
> > +   va = ioremap_wc(mem->dma, mem->len);
> > +   if (IS_ERR_OR_NULL(va)) {
> > +   dev_err(dev, "Unable to map memory region: %p+%zx\n",
> > +   >dma, mem->len);
> > +   return -ENOMEM;
> > +   }
> > +
> > +   /* Update memory entry va */
> > +   mem->va = va;
> > +
> > +   return 0;
> > +}
> > +
> > +static int imx_rproc_mem_release(struct rproc *rproc,
> > +struct rproc_mem_entry *mem)
> > +{
> > +   dev_dbg(rproc->dev.parent, "unmap memory: %pa\n", >dma);
> > +   iounmap(mem->va);
> > +
> > +   return 0;
> > +}
> > +
> > +static int imx_rproc_parse_memory_regions(struct rproc *rproc) {
> > +   struct imx_rproc *priv = rproc->priv;
> > +   struct device_node *np = priv->dev->of_node;
> > +   struct of_phandle_iterator it;
> > +   struct rproc_mem_entry *mem;
> > +   struct reserved_mem *rmem;
> > +   u32 da;
> > +
> > +   /* Register associated reserved memory regions */
> > +   of_phandle_iterator_init(, np, "memory-region", NULL, 0);
> > +   while (of_phandle_iterator_next() == 0) {
> > +   /*
> > +* Ignore the first memory region which will be used vdev 
> > buffer.
> > +* No need to do extra handlings, rproc_add_virtio_dev will 
> > handle
> it.
> > +*/
> > +   if (!strcmp(it.node->name, "vdevbuffer"))
> 
> Because you are doing a V8, please use "vdev0buffer" and make the change in
> the .yaml file.

V7, I have not post out V7 yet.

Seems I forgot the change this to vdev0buffer, I recalled you have same comments
before.

Thanks,
Peng.

> 
> > +   continue;
> > +
> > +   rmem = of_reserved_mem_lookup(it.node);
> > +   if (!rmem) {
> > +   dev_err(priv->dev, "unable to acquire memory-region\n");
> > +   return -EINVAL;
> > +   }
> > +
> > +   /* No need to translate pa to da, i.MX use same map */
> > +   da = rmem->base;
> > +
> > +   /* Register memory region */
> > +   mem = rproc_mem_entry_init(priv->dev, NULL,
> (dma_addr_t)rmem->base, rmem->size, da,
> > +  imx_rproc_mem_alloc, 
> > imx_rproc_mem_release,
> > +  it.node->name);
> > +
> > +   if (mem)
> > +   rproc_coredump_add_segment(rproc, da, rmem->size);
> > +   else
> > +   return -ENOMEM;
> > +
> > +   rproc_add_carveout(rproc, mem);
> > +   }
> > +
> > +   return  0;
> > +}
> > +
> > +static int imx_rproc_parse_fw(struct rproc *rproc, const struct
> > +firmware *fw) {
> > +   int ret = imx_rproc_parse_memory_regions(rproc);
> > +
> > +   if (ret)
> > +   return ret;
> > +
> > +   ret = rproc_elf_load_rsc_table(rproc, fw);
> > +   if (ret)
> > +   dev_info(>dev, "No resource table in elf\n");
> > +
> > +   return 0;
> > +}
> > +
> >  static const struct rproc_ops imx_rproc_ops = {
> > .start  = imx_rproc_start,
> > .stop   = imx_rproc_stop,
> > .da_to_va   = imx_rproc_da_to_va,
> > +   .load   = rproc_elf_load_segments,
> > +   .parse_fw   = imx_rproc_parse_fw,
> > +   .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table,
> > +   .sanity_check   = rproc_elf_sanity_check,
> > +   .get_boot_addr  = rproc_elf_get_boot_addr,
> >  };
> >
> >  static int imx_rproc_addr_init(struct imx_rproc *priv,
> > --
> > 2.28.0
> >


RE: [PATCH V6 10/10] remoteproc: imx_proc: enable virtio/mailbox

2021-01-14 Thread Peng Fan
> Subject: Re: [PATCH V6 10/10] remoteproc: imx_proc: enable virtio/mailbox
> 
> On Tue, Jan 12, 2021 at 05:39:19PM +0800, peng@nxp.com wrote:
> > From: Peng Fan 
> >
> > Use virtio/mailbox to build connection between Remote Proccessors and
> > Linux. Add work queue to handle incoming messages.
> >
> > Reviewed-by: Richard Zhu 
> > Signed-off-by: Peng Fan 
> > ---
> >  drivers/remoteproc/imx_rproc.c | 115
> > -
> >  1 file changed, 112 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/remoteproc/imx_rproc.c
> > b/drivers/remoteproc/imx_rproc.c index e62a53ee128e..812b077f1282
> > 100644
> > --- a/drivers/remoteproc/imx_rproc.c
> > +++ b/drivers/remoteproc/imx_rproc.c
> > @@ -7,6 +7,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -15,6 +16,9 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> > +
> > +#include "remoteproc_internal.h"
> >
> >  #define IMX7D_SRC_SCR  0x0C
> >  #define IMX7D_ENABLE_M4BIT(3)
> > @@ -86,6 +90,11 @@ struct imx_rproc {
> > const struct imx_rproc_dcfg *dcfg;
> > struct imx_rproc_memmem[IMX7D_RPROC_MEM_MAX];
> > struct clk  *clk;
> > +   struct mbox_client  cl;
> > +   struct mbox_chan*tx_ch;
> > +   struct mbox_chan*rx_ch;
> > +   struct work_struct  rproc_work;
> > +   struct workqueue_struct *workqueue;
> >  };
> >
> >  static const struct imx_rproc_att imx_rproc_att_imx8mq[] = { @@
> > -366,9 +375,33 @@ static int imx_rproc_parse_fw(struct rproc *rproc,
> const struct firmware *fw)
> > return 0;
> >  }
> >
> > +static void imx_rproc_kick(struct rproc *rproc, int vqid) {
> > +   struct imx_rproc *priv = rproc->priv;
> > +   int err;
> > +   __u32 mmsg;
> > +
> > +   if (!priv->tx_ch) {
> > +   dev_err(priv->dev, "No initialized mbox tx channel\n");
> > +   return;
> > +   }
> > +
> > +   /*
> > +* Send the index of the triggered virtqueue as the mu payload.
> > +* Let remote processor know which virtqueue is used.
> > +*/
> > +   mmsg = vqid << 16;
> > +
> > +   err = mbox_send_message(priv->tx_ch, (void *));
> > +   if (err < 0)
> > +   dev_err(priv->dev, "%s: failed (%d, err:%d)\n",
> > +   __func__, vqid, err);
> > +}
> > +
> >  static const struct rproc_ops imx_rproc_ops = {
> > .start  = imx_rproc_start,
> > .stop   = imx_rproc_stop,
> > +   .kick   = imx_rproc_kick,
> > .da_to_va   = imx_rproc_da_to_va,
> > .load   = rproc_elf_load_segments,
> > .parse_fw   = imx_rproc_parse_fw,
> > @@ -444,6 +477,65 @@ static int imx_rproc_addr_init(struct imx_rproc
> *priv,
> > return 0;
> >  }
> >
> > +static void imx_rproc_vq_work(struct work_struct *work) {
> > +   struct imx_rproc *priv = container_of(work, struct imx_rproc,
> > + rproc_work);
> > +
> > +   rproc_vq_interrupt(priv->rproc, 0);
> > +   rproc_vq_interrupt(priv->rproc, 1);
> > +}
> > +
> > +static void imx_rproc_rx_callback(struct mbox_client *cl, void *msg)
> > +{
> > +   struct rproc *rproc = dev_get_drvdata(cl->dev);
> > +   struct imx_rproc *priv = rproc->priv;
> > +
> > +   queue_work(priv->workqueue, >rproc_work); }
> > +
> > +static int imx_rproc_xtr_mbox_init(struct rproc *rproc) {
> > +   struct imx_rproc *priv = rproc->priv;
> > +   struct device *dev = priv->dev;
> > +   struct mbox_client *cl;
> > +   int ret;
> > +
> > +   if (!of_get_property(dev->of_node, "mbox-names", NULL))
> > +   return 0;
> > +
> > +   cl = >cl;
> > +   cl->dev = dev;
> > +   cl->tx_block = true;
> > +   cl->tx_tout = 100;
> > +   cl->knows_txdone = false;
> > +   cl->rx_callback = imx_rproc_rx_callback;
> > +
> > +   priv->tx_ch = mbox_request_channel_byname(cl, "tx");
> > +   if (IS_ERR(priv->tx_ch)) {
> > +   ret = PTR_ERR(priv->tx_ch);
> > +   return dev_err_probe(cl->dev, PTR_ERR(priv->tx_ch),
> > +

[PATCH] arm64: dts: imx8mq: use_dt_domains for pci node

2021-01-14 Thread Peng Fan (OSS)
From: Peng Fan 

We are using Jailhouse Hypervsior which has virtual pci node that
use dt domains. so also use dt domains for pci node, this will avoid
conflict with Jailhouse Hypervisor to trigger the following error:
  pr_err("Inconsistent \"linux,pci-domain\" property in DT\n");

Reviewed-by: Richard Zhu 
Signed-off-by: Peng Fan 
---
 arch/arm64/boot/dts/freescale/imx8mq.dtsi | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm64/boot/dts/freescale/imx8mq.dtsi 
b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
index a841a023e8e0..ac37cc86ad39 100644
--- a/arch/arm64/boot/dts/freescale/imx8mq.dtsi
+++ b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
@@ -1315,6 +1315,7 @@ pcie0: pcie@3380 {
<0 0 0 3  GIC_SPI 123 
IRQ_TYPE_LEVEL_HIGH>,
<0 0 0 4  GIC_SPI 122 
IRQ_TYPE_LEVEL_HIGH>;
fsl,max-link-speed = <2>;
+   linux,pci-domain = <0>;
power-domains = <_pcie>;
resets = < IMX8MQ_RESET_PCIEPHY>,
 < IMX8MQ_RESET_PCIE_CTRL_APPS_EN>,
@@ -1344,6 +1345,7 @@ pcie1: pcie@33c0 {
<0 0 0 3  GIC_SPI 75 
IRQ_TYPE_LEVEL_HIGH>,
<0 0 0 4  GIC_SPI 74 
IRQ_TYPE_LEVEL_HIGH>;
fsl,max-link-speed = <2>;
+   linux,pci-domain = <1>;
power-domains = <_pcie>;
resets = < IMX8MQ_RESET_PCIEPHY2>,
 < IMX8MQ_RESET_PCIE2_CTRL_APPS_EN>,
-- 
2.28.0



[PATCH] mmc: sdhci-esdhc-imx: validate pinctrl before use it

2021-01-14 Thread Peng Fan (OSS)
From: Peng Fan 

When imx_data->pinctrl is not a valid pointer, pinctrl_lookup_state
will trigger kernel panic.

When we boot Dual OS on Jailhouse hypervisor, we let the 1st Linux to
configure pinmux ready for the 2nd OS, so the 2nd OS not have pinctrl
settings.

Similar to this commit b62eee9f804e ("mmc: sdhci-esdhc-imx: no fail when no 
pinctrl available").

Reviewed-by: Bough Chen 
Reviewed-by: Alice Guo 
Signed-off-by: Peng Fan 
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c 
b/drivers/mmc/host/sdhci-esdhc-imx.c
index 16ed19f47939..11d3a2244b36 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -1488,7 +1488,7 @@ sdhci_esdhc_imx_probe_dt(struct platform_device *pdev,
 
mmc_of_parse_voltage(np, >ocr_mask);
 
-   if (esdhc_is_usdhc(imx_data)) {
+   if (esdhc_is_usdhc(imx_data) && !IS_ERR(imx_data->pinctrl)) {
imx_data->pins_100mhz = pinctrl_lookup_state(imx_data->pinctrl,
ESDHC_PINCTRL_STATE_100MHZ);
imx_data->pins_200mhz = pinctrl_lookup_state(imx_data->pinctrl,
-- 
2.28.0



RE: [PATCH V5 7/8] remoteproc: imx_rproc: ignore mapping vdev regions

2021-01-14 Thread Peng Fan
> Subject: Re: [PATCH V5 7/8] remoteproc: imx_rproc: ignore mapping vdev
> regions
> 
> On Wed, Jan 13, 2021 at 02:19:32AM +0000, Peng Fan wrote:
> > > Subject: Re: [PATCH V5 7/8] remoteproc: imx_rproc: ignore mapping
> > > vdev regions
> > >
> > > On Tue, Jan 12, 2021 at 09:41:12AM +, Peng Fan wrote:
> > > > > Subject: Re: [PATCH V5 7/8] remoteproc: imx_rproc: ignore
> > > > > mapping vdev regions
> > > > >
> > > > > On Tue, Dec 29, 2020 at 11:30:18AM +0800, peng@nxp.com
> wrote:
> > > > > > From: Peng Fan 
> > > > > >
> > > > > > vdev regions are vdev0vring0, vdev0vring1, vdevbuffer and similar.
> > > > > > They are handled by remoteproc common code, no need to map in
> > > > > > imx rproc driver.
> > > > > >
> > > > > > Signed-off-by: Peng Fan 
> > > > > > ---
> > > > > >  drivers/remoteproc/imx_rproc.c | 3 +++
> > > > > >  1 file changed, 3 insertions(+)
> > > > > >
> > > > > > diff --git a/drivers/remoteproc/imx_rproc.c
> > > > > > b/drivers/remoteproc/imx_rproc.c index
> > > > > > f80428afb8a7..e62a53ee128e
> > > > > > 100644
> > > > > > --- a/drivers/remoteproc/imx_rproc.c
> > > > > > +++ b/drivers/remoteproc/imx_rproc.c
> > > > > > @@ -417,6 +417,9 @@ static int imx_rproc_addr_init(struct
> > > > > > imx_rproc
> > > > > *priv,
> > > > > > struct resource res;
> > > > > >
> > > > > > node = of_parse_phandle(np, "memory-region", a);
> > > > > > +   /* Not map vdev region */
> > > > > > +   if (!strcmp(node->name, "vdev"))
> > > > > > +   continue;
> > > > >
> > > > > I am very confused and because I don't see an example for the DT
> > > > > in the bindings document I have to guess what is going on.
> > > >
> > > > V6 will include the DT yaml.
> > > >
> > > > >
> > > > > So I am guessing that you have laid out the memory regions for
> > > > > the vrings and the vdev0buffer in the DT "memory-region".
> > > >
> > > > The dts part will be similar as following:
> > > >
> > > > +#include 
> > > > +rsc_table: rsc_table@550ff000 {
> > > > +  no-map;
> > > > +  reg = <0x550ff000 0x1000>;
> > > > +};
> > > > +
> > > > +vdev0vring0: vdev0vring0@5500 {
> > > > +  no-map;
> > > > +  reg = <0x5500 0x8000>;
> > > > +};
> > > > +
> > > > +vdev0vring1: vdev0vring1@55008000 {
> > > > +  reg = <0x55008000 0x8000>;
> > > > +  no-map;
> > > > +};
> > > > +
> > > > +vdevbuffer: vdevbuffer@5540 {
> > > > +  compatible = "shared-dma-pool";
> > > > +  reg = <0x5540 0x10>;
> > > > +  no-map;
> > > > +};
> > > > +
> > > > +imx8mm-cm4 {
> > > > +  compatible = "fsl,imx8mm-cm4";
> > > > +  clocks = < IMX8MM_CLK_M4_DIV>;
> > > > +  mbox-names = "tx", "rx", "rxdb";
> > > > +  mboxes = < 0 1
> > > > + 1 1
> > > > + 3 1>;
> > > > +  memory-region = <>, <>,
> > > > + <>,
> > > <_table>;
> > > > +  syscon = <>;
> > > > +};
> > > >
> > > > >
> > > > > For the vrings I don't see the allocation of a carveout, which
> > > > > means that you will take the memory out of the DMA pool and the
> > > > > reserve memory will be wasted.
> > > >
> > > > imx_rproc_parse_memory_regions will alloc carveout.
> > >
> > > They _will_ but for now they don't and as such there a discrepancy
> > > between the bindings and the code that was published in V6.  At this
> > > point you can either drop the vrings in the DT or send another
> > > revision with the carveouts allocated.  I would definitely prefer
> > > the latter bec

RE: [PATCH V5 7/8] remoteproc: imx_rproc: ignore mapping vdev regions

2021-01-12 Thread Peng Fan
> Subject: Re: [PATCH V5 7/8] remoteproc: imx_rproc: ignore mapping vdev
> regions
> 
> On Tue, Jan 12, 2021 at 09:41:12AM +0000, Peng Fan wrote:
> > > Subject: Re: [PATCH V5 7/8] remoteproc: imx_rproc: ignore mapping
> > > vdev regions
> > >
> > > On Tue, Dec 29, 2020 at 11:30:18AM +0800, peng@nxp.com wrote:
> > > > From: Peng Fan 
> > > >
> > > > vdev regions are vdev0vring0, vdev0vring1, vdevbuffer and similar.
> > > > They are handled by remoteproc common code, no need to map in imx
> > > > rproc driver.
> > > >
> > > > Signed-off-by: Peng Fan 
> > > > ---
> > > >  drivers/remoteproc/imx_rproc.c | 3 +++
> > > >  1 file changed, 3 insertions(+)
> > > >
> > > > diff --git a/drivers/remoteproc/imx_rproc.c
> > > > b/drivers/remoteproc/imx_rproc.c index f80428afb8a7..e62a53ee128e
> > > > 100644
> > > > --- a/drivers/remoteproc/imx_rproc.c
> > > > +++ b/drivers/remoteproc/imx_rproc.c
> > > > @@ -417,6 +417,9 @@ static int imx_rproc_addr_init(struct
> > > > imx_rproc
> > > *priv,
> > > > struct resource res;
> > > >
> > > > node = of_parse_phandle(np, "memory-region", a);
> > > > +   /* Not map vdev region */
> > > > +   if (!strcmp(node->name, "vdev"))
> > > > +   continue;
> > >
> > > I am very confused and because I don't see an example for the DT in
> > > the bindings document I have to guess what is going on.
> >
> > V6 will include the DT yaml.
> >
> > >
> > > So I am guessing that you have laid out the memory regions for the
> > > vrings and the vdev0buffer in the DT "memory-region".
> >
> > The dts part will be similar as following:
> >
> > +#include 
> > +rsc_table: rsc_table@550ff000 {
> > +  no-map;
> > +  reg = <0x550ff000 0x1000>;
> > +};
> > +
> > +vdev0vring0: vdev0vring0@5500 {
> > +  no-map;
> > +  reg = <0x5500 0x8000>;
> > +};
> > +
> > +vdev0vring1: vdev0vring1@55008000 {
> > +  reg = <0x55008000 0x8000>;
> > +  no-map;
> > +};
> > +
> > +vdevbuffer: vdevbuffer@5540 {
> > +  compatible = "shared-dma-pool";
> > +  reg = <0x5540 0x10>;
> > +  no-map;
> > +};
> > +
> > +imx8mm-cm4 {
> > +  compatible = "fsl,imx8mm-cm4";
> > +  clocks = < IMX8MM_CLK_M4_DIV>;
> > +  mbox-names = "tx", "rx", "rxdb";
> > +  mboxes = < 0 1
> > + 1 1
> > + 3 1>;
> > +  memory-region = <>, <>, <>,
> <_table>;
> > +  syscon = <>;
> > +};
> >
> > >
> > > For the vrings I don't see the allocation of a carveout, which means
> > > that you will take the memory out of the DMA pool and the reserve
> > > memory will be wasted.
> >
> > imx_rproc_parse_memory_regions will alloc carveout.
> 
> They _will_ but for now they don't and as such there a discrepancy between
> the bindings and the code that was published in V6.  At this point you can
> either drop the vrings in the DT or send another revision with the carveouts
> allocated.  I would definitely prefer the latter because it wouldn't involve 
> yet
> another modification of the bindings.

You mean I drop patch v5 7/8 and send v7, right?

Or are there other changes that I need to do?

Thanks,
Peng.

> 
> >
> > >
> > > For the vdev0buffer, what you have will work *only* if that entry is
> > > the first one in the list of memory regions, as we agreed here [2].
> >
> > Yes. I agree and follow this rule from then.
> >
> > Thanks,
> > Peng.
> >
> > >
> > > [1].
> > > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fel
> > > ixir.b
> > >
> ootlin.com%2Flinux%2Fv5.11-rc3%2Fsource%2Fdrivers%2Fremoteproc%2Fre
> > >
> moteproc_core.c%23L321data=04%7C01%7Cpeng.fan%40nxp.com%7
> > >
> C581784529b1646b9d34b08d8b67ae8c7%7C686ea1d3bc2b4c6fa92cd99c5c
> > >
> 301635%7C0%7C0%7C637459986311799770%7CUnknown%7CTWFpbGZsb3
> > >
> d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0
> > > %3D%7C1000sdata=Qur6YiTWlak0ZRnrUZRzawfoO38EBrAItqZm66
> b4
> > > m20%3Dreserved=0
> > > [2].
> > > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpa
> > > tch
> > >
> work.kernel.org%2Fproject%2Flinux-remoteproc%2Fpatch%2F202007221315
> > >
> 43.7024-1-peng.fan%40nxp.com%2Fdata=04%7C01%7Cpeng.fan%40n
> > >
> xp.com%7C581784529b1646b9d34b08d8b67ae8c7%7C686ea1d3bc2b4c6fa9
> > >
> 2cd99c5c301635%7C0%7C0%7C637459986311799770%7CUnknown%7CTW
> > >
> FpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJX
> > >
> VCI6Mn0%3D%7C1000sdata=b%2F8muWtb3yxKIsnXmKmRGYYV33%2
> > > FHjwA6a8x58geY7eE%3Dreserved=0
> > >
> > > > err = of_address_to_resource(node, 0, );
> > > > if (err) {
> > > > dev_err(dev, "unable to resolve memory 
> > > > region\n");
> > > > --
> > > > 2.28.0
> > > >


[PATCH V6 10/10] remoteproc: imx_proc: enable virtio/mailbox

2021-01-12 Thread peng . fan
From: Peng Fan 

Use virtio/mailbox to build connection between Remote Proccessors
and Linux. Add work queue to handle incoming messages.

Reviewed-by: Richard Zhu 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c | 115 -
 1 file changed, 112 insertions(+), 3 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index e62a53ee128e..812b077f1282 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -15,6 +16,9 @@
 #include 
 #include 
 #include 
+#include 
+
+#include "remoteproc_internal.h"
 
 #define IMX7D_SRC_SCR  0x0C
 #define IMX7D_ENABLE_M4BIT(3)
@@ -86,6 +90,11 @@ struct imx_rproc {
const struct imx_rproc_dcfg *dcfg;
struct imx_rproc_memmem[IMX7D_RPROC_MEM_MAX];
struct clk  *clk;
+   struct mbox_client  cl;
+   struct mbox_chan*tx_ch;
+   struct mbox_chan*rx_ch;
+   struct work_struct  rproc_work;
+   struct workqueue_struct *workqueue;
 };
 
 static const struct imx_rproc_att imx_rproc_att_imx8mq[] = {
@@ -366,9 +375,33 @@ static int imx_rproc_parse_fw(struct rproc *rproc, const 
struct firmware *fw)
return 0;
 }
 
+static void imx_rproc_kick(struct rproc *rproc, int vqid)
+{
+   struct imx_rproc *priv = rproc->priv;
+   int err;
+   __u32 mmsg;
+
+   if (!priv->tx_ch) {
+   dev_err(priv->dev, "No initialized mbox tx channel\n");
+   return;
+   }
+
+   /*
+* Send the index of the triggered virtqueue as the mu payload.
+* Let remote processor know which virtqueue is used.
+*/
+   mmsg = vqid << 16;
+
+   err = mbox_send_message(priv->tx_ch, (void *));
+   if (err < 0)
+   dev_err(priv->dev, "%s: failed (%d, err:%d)\n",
+   __func__, vqid, err);
+}
+
 static const struct rproc_ops imx_rproc_ops = {
.start  = imx_rproc_start,
.stop   = imx_rproc_stop,
+   .kick   = imx_rproc_kick,
.da_to_va   = imx_rproc_da_to_va,
.load   = rproc_elf_load_segments,
.parse_fw   = imx_rproc_parse_fw,
@@ -444,6 +477,65 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
return 0;
 }
 
+static void imx_rproc_vq_work(struct work_struct *work)
+{
+   struct imx_rproc *priv = container_of(work, struct imx_rproc,
+ rproc_work);
+
+   rproc_vq_interrupt(priv->rproc, 0);
+   rproc_vq_interrupt(priv->rproc, 1);
+}
+
+static void imx_rproc_rx_callback(struct mbox_client *cl, void *msg)
+{
+   struct rproc *rproc = dev_get_drvdata(cl->dev);
+   struct imx_rproc *priv = rproc->priv;
+
+   queue_work(priv->workqueue, >rproc_work);
+}
+
+static int imx_rproc_xtr_mbox_init(struct rproc *rproc)
+{
+   struct imx_rproc *priv = rproc->priv;
+   struct device *dev = priv->dev;
+   struct mbox_client *cl;
+   int ret;
+
+   if (!of_get_property(dev->of_node, "mbox-names", NULL))
+   return 0;
+
+   cl = >cl;
+   cl->dev = dev;
+   cl->tx_block = true;
+   cl->tx_tout = 100;
+   cl->knows_txdone = false;
+   cl->rx_callback = imx_rproc_rx_callback;
+
+   priv->tx_ch = mbox_request_channel_byname(cl, "tx");
+   if (IS_ERR(priv->tx_ch)) {
+   ret = PTR_ERR(priv->tx_ch);
+   return dev_err_probe(cl->dev, PTR_ERR(priv->tx_ch),
+"failed to request tx mailbox channel: 
%d\n", ret);
+   }
+
+   priv->rx_ch = mbox_request_channel_byname(cl, "rx");
+   if (IS_ERR(priv->rx_ch)) {
+   mbox_free_channel(priv->tx_ch);
+   return dev_err_probe(cl->dev, PTR_ERR(priv->rx_ch),
+"failed to request mbox tx chan\n");
+   }
+
+   return 0;
+}
+
+static void imx_rproc_free_mbox(struct rproc *rproc)
+{
+   struct imx_rproc *priv = rproc->priv;
+
+   mbox_free_channel(priv->tx_ch);
+   mbox_free_channel(priv->rx_ch);
+}
+
 static int imx_rproc_probe(struct platform_device *pdev)
 {
struct device *dev = >dev;
@@ -481,18 +573,28 @@ static int imx_rproc_probe(struct platform_device *pdev)
priv->dev = dev;
 
dev_set_drvdata(dev, rproc);
+   priv->workqueue = create_workqueue(dev_name(dev));
+   if (!priv->workqueue) {
+   dev_err(dev, "cannot create workqueue\n");
+   ret = -ENOMEM;
+   goto err_put_rproc;
+  

[PATCH V6 08/10] remoteproc: imx_rproc: support i.MX8MQ/M

2021-01-12 Thread peng . fan
From: Peng Fan 

Add i.MX8MQ dev/sys addr map and configuration data structure
i.MX8MM share i.MX8MQ settings.

Reviewed-by: Richard Zhu 
Signed-off-by: Peng Fan 
Reviewed-by: Mathieu Poirier 
---
 drivers/remoteproc/imx_rproc.c | 39 ++
 1 file changed, 39 insertions(+)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 3c0075dc1787..f80428afb8a7 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -88,6 +88,34 @@ struct imx_rproc {
struct clk  *clk;
 };
 
+static const struct imx_rproc_att imx_rproc_att_imx8mq[] = {
+   /* dev addr , sys addr  , size  , flags */
+   /* TCML - alias */
+   { 0x, 0x007e, 0x0002, 0 },
+   /* OCRAM_S */
+   { 0x0018, 0x0018, 0x8000, 0 },
+   /* OCRAM */
+   { 0x0090, 0x0090, 0x0002, 0 },
+   /* OCRAM */
+   { 0x0092, 0x0092, 0x0002, 0 },
+   /* QSPI Code - alias */
+   { 0x0800, 0x0800, 0x0800, 0 },
+   /* DDR (Code) - alias */
+   { 0x1000, 0x8000, 0x0FFE, 0 },
+   /* TCML */
+   { 0x1FFE, 0x007E, 0x0002, ATT_OWN },
+   /* TCMU */
+   { 0x2000, 0x0080, 0x0002, ATT_OWN },
+   /* OCRAM_S */
+   { 0x2018, 0x0018, 0x8000, ATT_OWN },
+   /* OCRAM */
+   { 0x2020, 0x0090, 0x0002, ATT_OWN },
+   /* OCRAM */
+   { 0x2022, 0x0092, 0x0002, ATT_OWN },
+   /* DDR (Data) */
+   { 0x4000, 0x4000, 0x8000, 0 },
+};
+
 static const struct imx_rproc_att imx_rproc_att_imx7d[] = {
/* dev addr , sys addr  , size  , flags */
/* OCRAM_S (M4 Boot code) - alias */
@@ -138,6 +166,15 @@ static const struct imx_rproc_att imx_rproc_att_imx6sx[] = 
{
{ 0x8000, 0x8000, 0x6000, 0 },
 };
 
+static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mq = {
+   .src_reg= IMX7D_SRC_SCR,
+   .src_mask   = IMX7D_M4_RST_MASK,
+   .src_start  = IMX7D_M4_START,
+   .src_stop   = IMX7D_M4_STOP,
+   .att= imx_rproc_att_imx8mq,
+   .att_size   = ARRAY_SIZE(imx_rproc_att_imx8mq),
+};
+
 static const struct imx_rproc_dcfg imx_rproc_cfg_imx7d = {
.src_reg= IMX7D_SRC_SCR,
.src_mask   = IMX7D_M4_RST_MASK,
@@ -496,6 +533,8 @@ static int imx_rproc_remove(struct platform_device *pdev)
 static const struct of_device_id imx_rproc_of_match[] = {
{ .compatible = "fsl,imx7d-cm4", .data = _rproc_cfg_imx7d },
{ .compatible = "fsl,imx6sx-cm4", .data = _rproc_cfg_imx6sx },
+   { .compatible = "fsl,imx8mq-cm4", .data = _rproc_cfg_imx8mq },
+   { .compatible = "fsl,imx8mm-cm4", .data = _rproc_cfg_imx8mq },
{},
 };
 MODULE_DEVICE_TABLE(of, imx_rproc_of_match);
-- 
2.28.0



[PATCH V6 09/10] remoteproc: imx_rproc: ignore mapping vdev regions

2021-01-12 Thread peng . fan
From: Peng Fan 

vdev regions are vdev0vring0, vdev0vring1, vdevbuffer and similar.
They are handled by remoteproc common code, no need to map in imx
rproc driver.

Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index f80428afb8a7..e62a53ee128e 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -417,6 +417,9 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
struct resource res;
 
node = of_parse_phandle(np, "memory-region", a);
+   /* Not map vdev region */
+   if (!strcmp(node->name, "vdev"))
+   continue;
err = of_address_to_resource(node, 0, );
if (err) {
dev_err(dev, "unable to resolve memory region\n");
-- 
2.28.0



[PATCH V6 06/10] remoteproc: imx_rproc: use devm_ioremap

2021-01-12 Thread peng . fan
From: Peng Fan 

We might need to map an region multiple times, becaue the region might
be shared between remote processors, such i.MX8QM with dual M4 cores.
So use devm_ioremap, not devm_ioremap_resource.

Reviewed-by: Oleksij Rempel 
Reviewed-by: Richard Zhu 
Signed-off-by: Peng Fan 
Reviewed-by: Mathieu Poirier 
---
 drivers/remoteproc/imx_rproc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 2a093cea4997..47fc1d06be6a 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -296,7 +296,8 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
if (b >= IMX7D_RPROC_MEM_MAX)
break;
 
-   priv->mem[b].cpu_addr = devm_ioremap_resource(>dev, );
+   /* Not use resource version, because we might share region */
+   priv->mem[b].cpu_addr = devm_ioremap(>dev, res.start, 
resource_size());
if (IS_ERR(priv->mem[b].cpu_addr)) {
dev_err(dev, "failed to remap %pr\n", );
err = PTR_ERR(priv->mem[b].cpu_addr);
-- 
2.28.0



[PATCH V6 02/10] dt-bindings: remoteproc: imx_rproc: add i.MX8MQ/M support

2021-01-12 Thread peng . fan
From: Peng Fan 

Add i.MX8MQ/M support, also include mailbox for rpmsg/virtio usage.

Signed-off-by: Peng Fan 
---
 .../bindings/remoteproc/fsl,imx-rproc.yaml| 49 +++
 1 file changed, 49 insertions(+)

diff --git a/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml 
b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
index bce6ccfe1538..0b534ce227af 100644
--- a/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
+++ b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
@@ -15,6 +15,8 @@ maintainers:
 properties:
   compatible:
 enum:
+  - fsl,imx8mq-cm4
+  - fsl,imx8mm-cm4
   - fsl,imx7d-cm4
   - fsl,imx6sx-cm4
 
@@ -26,6 +28,20 @@ properties:
 description:
   Phandle to syscon block which provide access to System Reset Controller
 
+  mbox-names:
+items:
+  - const: tx
+  - const: rx
+  - const: rxdb
+
+  mboxes:
+description:
+  This property is required only if the rpmsg/virtio functionality is used.
+  List of < type channel> - 1 channel for TX, 1 channel for RX, 1 
channel for RXDB.
+  (see mailbox/fsl,mu.yaml)
+minItems: 1
+maxItems: 3
+
   memory-region:
 description:
   list of phandels to the reserved memory regions.
@@ -56,4 +72,37 @@ examples:
   clocks   = < IMX7D_ARM_M4_ROOT_CLK>;
 };
 
+  - |
+#include 
+rsc_table: rsc_table@550ff000 {
+  no-map;
+  reg = <0x550ff000 0x1000>;
+};
+
+vdev0vring0: vdev0vring0@5500 {
+  no-map;
+  reg = <0x5500 0x8000>;
+};
+
+vdev0vring1: vdev0vring1@55008000 {
+  reg = <0x55008000 0x8000>;
+  no-map;
+};
+
+vdevbuffer: vdevbuffer@5540 {
+  compatible = "shared-dma-pool";
+  reg = <0x5540 0x10>;
+  no-map;
+};
+
+imx8mm-cm4 {
+  compatible = "fsl,imx8mm-cm4";
+  clocks = < IMX8MM_CLK_M4_DIV>;
+  mbox-names = "tx", "rx", "rxdb";
+  mboxes = < 0 1
+ 1 1
+ 3 1>;
+  memory-region = <>, <>, <>, 
<_table>;
+  syscon = <>;
+};
 ...
-- 
2.28.0



[PATCH V6 01/10] dt-bindings: remoteproc: convert imx rproc bindings to json-schema

2021-01-12 Thread peng . fan
From: Peng Fan 

Convert the imx rproc binding to DT schema format using json-schema.

Signed-off-by: Peng Fan 
---
 .../bindings/remoteproc/fsl,imx-rproc.yaml| 59 +++
 .../bindings/remoteproc/imx-rproc.txt | 33 ---
 2 files changed, 59 insertions(+), 33 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
 delete mode 100644 Documentation/devicetree/bindings/remoteproc/imx-rproc.txt

diff --git a/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml 
b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
new file mode 100644
index ..bce6ccfe1538
--- /dev/null
+++ b/Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/remoteproc/fsl,imx-rproc.yaml#;
+$schema: "http://devicetree.org/meta-schemas/core.yaml#;
+
+title: NXP iMX6SX/iMX7D Co-Processor Bindings
+
+description:
+  This binding provides support for ARM Cortex M4 Co-processor found on some 
NXP iMX SoCs.
+
+maintainers:
+  - Peng Fan 
+
+properties:
+  compatible:
+enum:
+  - fsl,imx7d-cm4
+  - fsl,imx6sx-cm4
+
+  clocks:
+description:
+  Clock for co-processor (See ../clock/clock-bindings.txt)
+
+  syscon:
+description:
+  Phandle to syscon block which provide access to System Reset Controller
+
+  memory-region:
+description:
+  list of phandels to the reserved memory regions.
+  (see ../reserved-memory/reserved-memory.txt)
+
+required:
+  - compatible
+  - clocks
+  - syscon
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+m4_reserved_sysmem1: cm4@8000 {
+  reg = <0x8000 0x8>;
+};
+
+m4_reserved_sysmem2: cm4@8100 {
+  reg = <0x8100 0x8>;
+};
+
+imx7d-cm4 {
+  compatible   = "fsl,imx7d-cm4";
+  memory-region= <_reserved_sysmem1>, <_reserved_sysmem2>;
+  syscon   = <>;
+  clocks   = < IMX7D_ARM_M4_ROOT_CLK>;
+};
+
+...
diff --git a/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt 
b/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt
deleted file mode 100644
index fbcefd965dc4..
--- a/Documentation/devicetree/bindings/remoteproc/imx-rproc.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-NXP iMX6SX/iMX7D Co-Processor Bindings
-
-
-This binding provides support for ARM Cortex M4 Co-processor found on some
-NXP iMX SoCs.
-
-Required properties:
-- compatible   Should be one of:
-   "fsl,imx7d-cm4"
-   "fsl,imx6sx-cm4"
-- clocks   Clock for co-processor (See: 
../clock/clock-bindings.txt)
-- syscon   Phandle to syscon block which provide access to
-   System Reset Controller
-
-Optional properties:
-- memory-regionlist of phandels to the reserved memory regions.
-   (See: ../reserved-memory/reserved-memory.txt)
-
-Example:
-   m4_reserved_sysmem1: cm4@8000 {
-   reg = <0x8000 0x8>;
-   };
-
-   m4_reserved_sysmem2: cm4@8100 {
-   reg = <0x8100 0x8>;
-   };
-
-   imx7d-cm4 {
-   compatible  = "fsl,imx7d-cm4";
-   memory-region   = <_reserved_sysmem1>, 
<_reserved_sysmem2>;
-   syscon  = <>;
-   clocks  = < IMX7D_ARM_M4_ROOT_CLK>;
-   };
-- 
2.28.0



[PATCH V6 07/10] remoteproc: imx_rproc: add i.MX specific parse fw hook

2021-01-12 Thread peng . fan
From: Peng Fan 

The hook is used to parse memory-regions and load resource table
from the address the remote processor published.

Signed-off-by: Peng Fan 
Reviewed-by: Richard Zhu 
Reviewed-by: Mathieu Poirier 
---
 drivers/remoteproc/imx_rproc.c | 93 ++
 1 file changed, 93 insertions(+)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 47fc1d06be6a..3c0075dc1787 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -241,10 +242,102 @@ static void *imx_rproc_da_to_va(struct rproc *rproc, u64 
da, size_t len, bool *i
return va;
 }
 
+static int imx_rproc_mem_alloc(struct rproc *rproc,
+  struct rproc_mem_entry *mem)
+{
+   struct device *dev = rproc->dev.parent;
+   void *va;
+
+   dev_dbg(dev, "map memory: %p+%zx\n", >dma, mem->len);
+   va = ioremap_wc(mem->dma, mem->len);
+   if (IS_ERR_OR_NULL(va)) {
+   dev_err(dev, "Unable to map memory region: %p+%zx\n",
+   >dma, mem->len);
+   return -ENOMEM;
+   }
+
+   /* Update memory entry va */
+   mem->va = va;
+
+   return 0;
+}
+
+static int imx_rproc_mem_release(struct rproc *rproc,
+struct rproc_mem_entry *mem)
+{
+   dev_dbg(rproc->dev.parent, "unmap memory: %pa\n", >dma);
+   iounmap(mem->va);
+
+   return 0;
+}
+
+static int imx_rproc_parse_memory_regions(struct rproc *rproc)
+{
+   struct imx_rproc *priv = rproc->priv;
+   struct device_node *np = priv->dev->of_node;
+   struct of_phandle_iterator it;
+   struct rproc_mem_entry *mem;
+   struct reserved_mem *rmem;
+   u32 da;
+
+   /* Register associated reserved memory regions */
+   of_phandle_iterator_init(, np, "memory-region", NULL, 0);
+   while (of_phandle_iterator_next() == 0) {
+   /*
+* Ignore the first memory region which will be used vdev 
buffer.
+* No need to do extra handlings, rproc_add_virtio_dev will 
handle it.
+*/
+   if (!strcmp(it.node->name, "vdevbuffer"))
+   continue;
+
+   rmem = of_reserved_mem_lookup(it.node);
+   if (!rmem) {
+   dev_err(priv->dev, "unable to acquire memory-region\n");
+   return -EINVAL;
+   }
+
+   /* No need to translate pa to da, i.MX use same map */
+   da = rmem->base;
+
+   /* Register memory region */
+   mem = rproc_mem_entry_init(priv->dev, NULL, 
(dma_addr_t)rmem->base, rmem->size, da,
+  imx_rproc_mem_alloc, 
imx_rproc_mem_release,
+  it.node->name);
+
+   if (mem)
+   rproc_coredump_add_segment(rproc, da, rmem->size);
+   else
+   return -ENOMEM;
+
+   rproc_add_carveout(rproc, mem);
+   }
+
+   return  0;
+}
+
+static int imx_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
+{
+   int ret = imx_rproc_parse_memory_regions(rproc);
+
+   if (ret)
+   return ret;
+
+   ret = rproc_elf_load_rsc_table(rproc, fw);
+   if (ret)
+   dev_info(>dev, "No resource table in elf\n");
+
+   return 0;
+}
+
 static const struct rproc_ops imx_rproc_ops = {
.start  = imx_rproc_start,
.stop   = imx_rproc_stop,
.da_to_va   = imx_rproc_da_to_va,
+   .load   = rproc_elf_load_segments,
+   .parse_fw   = imx_rproc_parse_fw,
+   .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table,
+   .sanity_check   = rproc_elf_sanity_check,
+   .get_boot_addr  = rproc_elf_get_boot_addr,
 };
 
 static int imx_rproc_addr_init(struct imx_rproc *priv,
-- 
2.28.0



[PATCH V6 03/10] remoteproc: introduce is_iomem to rproc_mem_entry

2021-01-12 Thread peng . fan
From: Peng Fan 

Introduce is_iomem to indicate this piece memory is iomem or not.

Reviewed-by: Bjorn Andersson 
Signed-off-by: Peng Fan 
Reviewed-by: Mathieu Poirier 
---
 include/linux/remoteproc.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index f28ee75d1005..a5f6d2d9cde2 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -315,6 +315,7 @@ struct rproc;
 /**
  * struct rproc_mem_entry - memory entry descriptor
  * @va:virtual address
+ * @is_iomem: io memory
  * @dma: dma address
  * @len: length, in bytes
  * @da: device address
@@ -329,6 +330,7 @@ struct rproc;
  */
 struct rproc_mem_entry {
void *va;
+   bool is_iomem;
dma_addr_t dma;
size_t len;
u32 da;
-- 
2.28.0



[PATCH V6 05/10] remoteproc: imx_rproc: correct err message

2021-01-12 Thread peng . fan
From: Peng Fan 

It is using devm_ioremap, so not devm_ioremap_resource. Correct
the error message and print out sa/size.

Reviewed-by: Bjorn Andersson 
Signed-off-by: Peng Fan 
Reviewed-by: Mathieu Poirier 
Reviewed-by: Mathieu Poirier 
---
 drivers/remoteproc/imx_rproc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 6603e00bb6f4..2a093cea4997 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -268,7 +268,7 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
priv->mem[b].cpu_addr = devm_ioremap(>dev,
 att->sa, att->size);
if (!priv->mem[b].cpu_addr) {
-   dev_err(dev, "devm_ioremap_resource failed\n");
+   dev_err(dev, "failed to remap %#x bytes from %#x\n", 
att->size, att->sa);
return -ENOMEM;
}
priv->mem[b].sys_addr = att->sa;
@@ -298,7 +298,7 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
 
priv->mem[b].cpu_addr = devm_ioremap_resource(>dev, );
if (IS_ERR(priv->mem[b].cpu_addr)) {
-   dev_err(dev, "devm_ioremap_resource failed\n");
+   dev_err(dev, "failed to remap %pr\n", );
err = PTR_ERR(priv->mem[b].cpu_addr);
return err;
}
-- 
2.28.0



[PATCH V6 04/10] remoteproc: add is_iomem to da_to_va

2021-01-12 Thread peng . fan
From: Peng Fan 

Introduce an extra parameter is_iomem to da_to_va, then the caller
could take the memory as normal memory or io mapped memory.

Reviewed-by: Bjorn Andersson 
Signed-off-by: Peng Fan 
Reported-by: kernel test robot 
Reported-by: kernel test robot 
Reviewed-by: Mathieu Poirier 
---
 drivers/remoteproc/imx_rproc.c |  2 +-
 drivers/remoteproc/ingenic_rproc.c |  2 +-
 drivers/remoteproc/keystone_remoteproc.c   |  2 +-
 drivers/remoteproc/mtk_scp.c   |  6 +++---
 drivers/remoteproc/omap_remoteproc.c   |  2 +-
 drivers/remoteproc/pru_rproc.c |  2 +-
 drivers/remoteproc/qcom_q6v5_adsp.c|  2 +-
 drivers/remoteproc/qcom_q6v5_pas.c |  2 +-
 drivers/remoteproc/qcom_q6v5_wcss.c|  2 +-
 drivers/remoteproc/qcom_wcnss.c|  2 +-
 drivers/remoteproc/remoteproc_core.c   |  7 +--
 drivers/remoteproc/remoteproc_coredump.c   |  8 ++--
 drivers/remoteproc/remoteproc_debugfs.c|  2 +-
 drivers/remoteproc/remoteproc_elf_loader.c | 21 +++--
 drivers/remoteproc/remoteproc_internal.h   |  2 +-
 drivers/remoteproc/st_slim_rproc.c |  2 +-
 drivers/remoteproc/ti_k3_dsp_remoteproc.c  |  2 +-
 drivers/remoteproc/ti_k3_r5_remoteproc.c   |  2 +-
 drivers/remoteproc/wkup_m3_rproc.c |  2 +-
 include/linux/remoteproc.h |  2 +-
 20 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 8957ed271d20..6603e00bb6f4 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -208,7 +208,7 @@ static int imx_rproc_da_to_sys(struct imx_rproc *priv, u64 
da,
return -ENOENT;
 }
 
-static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool 
*is_iomem)
 {
struct imx_rproc *priv = rproc->priv;
void *va = NULL;
diff --git a/drivers/remoteproc/ingenic_rproc.c 
b/drivers/remoteproc/ingenic_rproc.c
index 26e19e6143b7..bb5049295576 100644
--- a/drivers/remoteproc/ingenic_rproc.c
+++ b/drivers/remoteproc/ingenic_rproc.c
@@ -116,7 +116,7 @@ static void ingenic_rproc_kick(struct rproc *rproc, int 
vqid)
writel(vqid, vpu->aux_base + REG_CORE_MSG);
 }
 
-static void *ingenic_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *ingenic_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, 
bool *is_iomem)
 {
struct vpu *vpu = rproc->priv;
void __iomem *va = NULL;
diff --git a/drivers/remoteproc/keystone_remoteproc.c 
b/drivers/remoteproc/keystone_remoteproc.c
index cd266163a65f..54781f553f4e 100644
--- a/drivers/remoteproc/keystone_remoteproc.c
+++ b/drivers/remoteproc/keystone_remoteproc.c
@@ -246,7 +246,7 @@ static void keystone_rproc_kick(struct rproc *rproc, int 
vqid)
  * can be used either by the remoteproc core for loading (when using kernel
  * remoteproc loader), or by any rpmsg bus drivers.
  */
-static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, 
bool *is_iomem)
 {
struct keystone_rproc *ksproc = rproc->priv;
void __iomem *va = NULL;
diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c
index e0c235690361..535175f013e4 100644
--- a/drivers/remoteproc/mtk_scp.c
+++ b/drivers/remoteproc/mtk_scp.c
@@ -270,7 +270,7 @@ static int scp_elf_load_segments(struct rproc *rproc, const 
struct firmware *fw)
}
 
/* grab the kernel address for this device address */
-   ptr = (void __iomem *)rproc_da_to_va(rproc, da, memsz);
+   ptr = (void __iomem *)rproc_da_to_va(rproc, da, memsz, NULL);
if (!ptr) {
dev_err(dev, "bad phdr da 0x%x mem 0x%x\n", da, memsz);
ret = -EINVAL;
@@ -458,7 +458,7 @@ static int scp_start(struct rproc *rproc)
return ret;
 }
 
-static void *scp_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *scp_da_to_va(struct rproc *rproc, u64 da, size_t len, bool 
*is_iomem)
 {
struct mtk_scp *scp = (struct mtk_scp *)rproc->priv;
int offset;
@@ -587,7 +587,7 @@ void *scp_mapping_dm_addr(struct mtk_scp *scp, u32 mem_addr)
 {
void *ptr;
 
-   ptr = scp_da_to_va(scp->rproc, mem_addr, 0);
+   ptr = scp_da_to_va(scp->rproc, mem_addr, 0, NULL);
if (!ptr)
return ERR_PTR(-EINVAL);
 
diff --git a/drivers/remoteproc/omap_remoteproc.c 
b/drivers/remoteproc/omap_remoteproc.c
index d94b7391bf9d..43531caa1959 100644
--- a/drivers/remoteproc/omap_remoteproc.c
+++ b/drivers/remoteproc/omap_remoteproc.c
@@ -728,7 +728,7 @@ static int omap_rproc_stop(struct rproc *rproc)
  * Return: translated virtual address in kernel memory space on success,
  * or NULL on failure.
  */
-static void *o

[PATCH V6 00/10] remoteproc: imx_rproc: support iMX8MQ/M

2021-01-12 Thread peng . fan
From: Peng Fan 

V6:
 Add R-b tag from Mathieu
 Convert imx-rproc.txt to yaml and add dt-bindings support for i.MX8MQ/M, patch 
1/10 2/10
 No other changes.

V5:
 Apply on Linux next
 Add V5 subject prefix
 Add R-b tag from Bjorn for 1/8, 2/8, 3/8
 
https://patchwork.kernel.org/project/linux-remoteproc/cover/20201229033019.25899-1-peng@nxp.com/

V4:
 According to Bjorn's comments, add is_iomem for da to va usage
 1/8, 2/8 is new patch
 3/8, follow Bjorn's comments to correct/update the err msg.
 6/8, new patch
 8/8, use dev_err_probe to simplify code, use queue_work instead 
schedule_delayed_work

V3:
 Since I was quite busy in the past days, V3 is late
 Rebased on Linux-next
 Add R-b tags
 1/7: Add R-b tag of Mathieu, add comments
 4/7: Typo fix
 5/7: Add R-b tag of Mathieu, drop index Per Mathieu's comments
 6/7: Add R-b tag of Mathieu
 7/7: Add comment for vqid << 16, drop unneeded timeout settings of mailbox
  Use queue_work instead of schedule_delayed_work
  free mbox channels when remove
 https://lkml.org/lkml/2020/12/4/82

V2:
 Rebased on linux-next
 Dropped early boot feature to make patchset simple.
 Drop rsc-da
 
https://patchwork.kernel.org/project/linux-remoteproc/cover/20200927064131.24101-1-peng@nxp.com/

V1:
 https://patchwork.kernel.org/cover/11682461/

This patchset is to support i.MX8MQ/M coproc.
The early boot feature was dropped to make the patchset small in V2.

Since i.MX specific TCM memory requirement, add elf platform hook.
Several patches have got reviewed by Oleksij and Mathieu in v1.


Peng Fan (10):
  dt-bindings: remoteproc: convert imx rproc bindings to json-schema
  dt-bindings: remoteproc: imx_rproc: add i.MX8MQ/M support
  remoteproc: introduce is_iomem to rproc_mem_entry
  remoteproc: add is_iomem to da_to_va
  remoteproc: imx_rproc: correct err message
  remoteproc: imx_rproc: use devm_ioremap
  remoteproc: imx_rproc: add i.MX specific parse fw hook
  remoteproc: imx_rproc: support i.MX8MQ/M
  remoteproc: imx_rproc: ignore mapping vdev regions
  remoteproc: imx_proc: enable virtio/mailbox

 .../bindings/remoteproc/fsl,imx-rproc.yaml| 108 
 .../bindings/remoteproc/imx-rproc.txt |  33 ---
 drivers/remoteproc/imx_rproc.c| 259 +-
 drivers/remoteproc/ingenic_rproc.c|   2 +-
 drivers/remoteproc/keystone_remoteproc.c  |   2 +-
 drivers/remoteproc/mtk_scp.c  |   6 +-
 drivers/remoteproc/omap_remoteproc.c  |   2 +-
 drivers/remoteproc/pru_rproc.c|   2 +-
 drivers/remoteproc/qcom_q6v5_adsp.c   |   2 +-
 drivers/remoteproc/qcom_q6v5_pas.c|   2 +-
 drivers/remoteproc/qcom_q6v5_wcss.c   |   2 +-
 drivers/remoteproc/qcom_wcnss.c   |   2 +-
 drivers/remoteproc/remoteproc_core.c  |   7 +-
 drivers/remoteproc/remoteproc_coredump.c  |   8 +-
 drivers/remoteproc/remoteproc_debugfs.c   |   2 +-
 drivers/remoteproc/remoteproc_elf_loader.c|  21 +-
 drivers/remoteproc/remoteproc_internal.h  |   2 +-
 drivers/remoteproc/st_slim_rproc.c|   2 +-
 drivers/remoteproc/ti_k3_dsp_remoteproc.c |   2 +-
 drivers/remoteproc/ti_k3_r5_remoteproc.c  |   2 +-
 drivers/remoteproc/wkup_m3_rproc.c|   2 +-
 include/linux/remoteproc.h|   4 +-
 22 files changed, 406 insertions(+), 68 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml
 delete mode 100644 Documentation/devicetree/bindings/remoteproc/imx-rproc.txt

-- 
2.28.0



RE: [PATCH V5 7/8] remoteproc: imx_rproc: ignore mapping vdev regions

2021-01-12 Thread Peng Fan
> Subject: Re: [PATCH V5 7/8] remoteproc: imx_rproc: ignore mapping vdev
> regions
> 
> On Tue, Dec 29, 2020 at 11:30:18AM +0800, peng@nxp.com wrote:
> > From: Peng Fan 
> >
> > vdev regions are vdev0vring0, vdev0vring1, vdevbuffer and similar.
> > They are handled by remoteproc common code, no need to map in imx
> > rproc driver.
> >
> > Signed-off-by: Peng Fan 
> > ---
> >  drivers/remoteproc/imx_rproc.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/remoteproc/imx_rproc.c
> > b/drivers/remoteproc/imx_rproc.c index f80428afb8a7..e62a53ee128e
> > 100644
> > --- a/drivers/remoteproc/imx_rproc.c
> > +++ b/drivers/remoteproc/imx_rproc.c
> > @@ -417,6 +417,9 @@ static int imx_rproc_addr_init(struct imx_rproc
> *priv,
> > struct resource res;
> >
> > node = of_parse_phandle(np, "memory-region", a);
> > +   /* Not map vdev region */
> > +   if (!strcmp(node->name, "vdev"))
> > +   continue;
> 
> I am very confused and because I don't see an example for the DT in the
> bindings document I have to guess what is going on.

V6 will include the DT yaml.

> 
> So I am guessing that you have laid out the memory regions for the vrings and
> the vdev0buffer in the DT "memory-region".

The dts part will be similar as following:

+#include 
+rsc_table: rsc_table@550ff000 {
+  no-map;
+  reg = <0x550ff000 0x1000>;
+};
+
+vdev0vring0: vdev0vring0@5500 {
+  no-map;
+  reg = <0x5500 0x8000>;
+};
+
+vdev0vring1: vdev0vring1@55008000 {
+  reg = <0x55008000 0x8000>;
+  no-map;
+};
+
+vdevbuffer: vdevbuffer@5540 {
+  compatible = "shared-dma-pool";
+  reg = <0x5540 0x10>;
+  no-map;
+};
+
+imx8mm-cm4 {
+  compatible = "fsl,imx8mm-cm4";
+  clocks = < IMX8MM_CLK_M4_DIV>;
+  mbox-names = "tx", "rx", "rxdb";
+  mboxes = < 0 1
+ 1 1
+ 3 1>;
+  memory-region = <>, <>, <>, 
<_table>;
+  syscon = <>;
+};

> 
> For the vrings I don't see the allocation of a carveout, which means that you
> will take the memory out of the DMA pool and the reserve memory will be
> wasted.

imx_rproc_parse_memory_regions will alloc carveout.

> 
> For the vdev0buffer, what you have will work *only* if that entry is the first
> one in the list of memory regions, as we agreed here [2].

Yes. I agree and follow this rule from then.

Thanks,
Peng.

> 
> [1].
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Felixir.b
> ootlin.com%2Flinux%2Fv5.11-rc3%2Fsource%2Fdrivers%2Fremoteproc%2Fre
> moteproc_core.c%23L321data=04%7C01%7Cpeng.fan%40nxp.com%7
> C581784529b1646b9d34b08d8b67ae8c7%7C686ea1d3bc2b4c6fa92cd99c5c
> 301635%7C0%7C0%7C637459986311799770%7CUnknown%7CTWFpbGZsb3
> d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0
> %3D%7C1000sdata=Qur6YiTWlak0ZRnrUZRzawfoO38EBrAItqZm66b4
> m20%3Dreserved=0
> [2].
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatch
> work.kernel.org%2Fproject%2Flinux-remoteproc%2Fpatch%2F202007221315
> 43.7024-1-peng.fan%40nxp.com%2Fdata=04%7C01%7Cpeng.fan%40n
> xp.com%7C581784529b1646b9d34b08d8b67ae8c7%7C686ea1d3bc2b4c6fa9
> 2cd99c5c301635%7C0%7C0%7C637459986311799770%7CUnknown%7CTW
> FpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJX
> VCI6Mn0%3D%7C1000sdata=b%2F8muWtb3yxKIsnXmKmRGYYV33%2
> FHjwA6a8x58geY7eE%3Dreserved=0
> 
> > err = of_address_to_resource(node, 0, );
> > if (err) {
> > dev_err(dev, "unable to resolve memory region\n");
> > --
> > 2.28.0
> >


RE: [PATCH 2/4] arm64: dts: imx8mn: add spba bus node

2020-12-29 Thread Peng Fan
> Subject: Re: [PATCH 2/4] arm64: dts: imx8mn: add spba bus node
> 
> On Tue, Dec 29, 2020 at 06:26:41AM -0600, Adam Ford wrote:
> > On Tue, Dec 29, 2020 at 6:15 AM  wrote:
> > >
> > > From: Peng Fan 
> > >
> > > According to RM, there is a spba bus inside aips3 and aips1, add it.
> > >
> > > Signed-off-by: Peng Fan 
> > > ---
> > >  arch/arm64/boot/dts/freescale/imx8mm.dtsi | 362
> > > +++---
> > >  1 file changed, 189 insertions(+), 173 deletions(-)
> > >
> > > diff --git a/arch/arm64/boot/dts/freescale/imx8mm.dtsi
> > > b/arch/arm64/boot/dts/freescale/imx8mm.dtsi
> > > index c824f2615fe8..91f85b8cee9a 100644
> > > --- a/arch/arm64/boot/dts/freescale/imx8mm.dtsi
> > > +++ b/arch/arm64/boot/dts/freescale/imx8mm.dtsi
> > > @@ -269,117 +269,125 @@ aips1: bus@3000 {
> > > #size-cells = <1>;
> > > ranges = <0x3000 0x3000
> 0x40>;
> > >
> > > -   sai1: sai@3001 {
> > > -   #sound-dai-cells = <0>;
> > > -   compatible = "fsl,imx8mm-sai",
> "fsl,imx8mq-sai";
> > > -   reg = <0x3001 0x1>;
> > > -   interrupts =  IRQ_TYPE_LEVEL_HIGH>;
> > > -   clocks = <
> IMX8MM_CLK_SAI1_IPG>,
> > > -<
> IMX8MM_CLK_SAI1_ROOT>,
> > > -<
> IMX8MM_CLK_DUMMY>, < IMX8MM_CLK_DUMMY>;
> > > -   clock-names = "bus", "mclk1",
> "mclk2", "mclk3";
> > > -   dmas = < 0 2 0>, <
> 1 2 0>;
> > > -   dma-names = "rx", "tx";
> > > -   status = "disabled";
> > > -   };
> > > +   bus@3000 {
> >
> > There is already a bus@3000 (aips1), and I think the system
> > doesn't like it when there are multiple busses with the same name.
> >
> > There was some discussion on fixing the 8mn [1], but it doesn't look
> > like it went anywhere.
> >
> > I am guessing the Mini will need something similar to the nano.
> >
> > [1] -
> > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatc
> >
> hwork.kernel.org%2Fproject%2Flinux-arm-kernel%2Fpatch%2F1607324004-1
> 29
> >
> 60-1-git-send-email-shengjiu.wang%40nxp.com%2Fdata=04%7C01%7
> Cpeng
> > .fan%40nxp.com%7C970d320f3ef7413296ed08d8ac1486f9%7C686ea1d3bc
> 2b4c6fa9
> >
> 2cd99c5c301635%7C0%7C0%7C637448551481206715%7CUnknown%7CTW
> FpbGZsb3d8ey
> >
> JWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D
> %7C200
> >
> 0sdata=xKgYHCDyitbUyTPKVuwQV%2FCoJvepCbdBJ1MD9vP%2B6MY
> %3Dres
> > erved=0
> 
> Several replies from S.j. Wang are missing from LKML (and maybe
> patchwork?) but we reached a conclusion:

Thanks for the pointing, I'll give a look. If S.J take it, I'll leave it to S.J.

Thanks,
Peng. 

> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.ke
> rnel.org%2Flinux-arm-kernel%2F20201208090601.GA8347%40kozik-lap%2F&
> amp;data=04%7C01%7Cpeng.fan%40nxp.com%7C970d320f3ef7413296ed08
> d8ac1486f9%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C63744
> 8551481206715%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiL
> CJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000sdata=nk
> t0J5RtzA%2B29nK4aPnd434FNQV8MUZ%2F8Aq64o6hl6I%3Dreserved
> =0
> 
> Either you do some remapping of address space or just rename the "bus"
> nodes (e.g. generic bus-1 or a specific spba-bus).
> 
> Best regards,
> Krzysztof


RE: [PATCH 3/4] arm64: dts: imx8mn: add spba bus node

2020-12-29 Thread Peng Fan
> Subject: Re: [PATCH 3/4] arm64: dts: imx8mn: add spba bus node
> 
> On Tue, Dec 29, 2020 at 08:00:44PM +0800, peng@nxp.com wrote:
> > From: Peng Fan 
> >
> > According to RM, there is a spba bus inside aips3 and aips1, add it.
> 
> This does not look like matching contents of commit.

Posted in a rush. Forgot to squash commits.

Thanks,
Peng.

> 
> Best regards,
> Krzysztof
> 
> 
> >
> > Signed-off-by: Peng Fan 
> > ---
> >  arch/arm64/boot/dts/freescale/imx8mn.dtsi | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/arm64/boot/dts/freescale/imx8mn.dtsi
> b/arch/arm64/boot/dts/freescale/imx8mn.dtsi
> > index 73602832ccaa..033fa90570ff 100644
> > --- a/arch/arm64/boot/dts/freescale/imx8mn.dtsi
> > +++ b/arch/arm64/boot/dts/freescale/imx8mn.dtsi
> > @@ -749,7 +749,7 @@ uart2: serial@3089 {
> > clock-names = "ipg", "per";
> > status = "disabled";
> > };
> > -   }
> > +   };
> >
> > crypto: crypto@3090 {
> > compatible = "fsl,sec-v4.0";
> > --
> > 2.28.0
> >


[PATCH 4/4] arm64: dts: imx8mq: add spba bus node

2020-12-29 Thread peng . fan
From: Peng Fan 

According to RM, there is a spba bus inside aips3 and aips1, add it.

Signed-off-by: Peng Fan 
---
 arch/arm64/boot/dts/freescale/imx8mq.dtsi | 386 +++---
 1 file changed, 201 insertions(+), 185 deletions(-)

diff --git a/arch/arm64/boot/dts/freescale/imx8mq.dtsi 
b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
index a841a023e8e0..d043d8474314 100644
--- a/arch/arm64/boot/dts/freescale/imx8mq.dtsi
+++ b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
@@ -299,60 +299,68 @@ bus@3000 { /* AIPS1 */
#size-cells = <1>;
ranges = <0x3000 0x3000 0x40>;
 
-   sai1: sai@3001 {
-   #sound-dai-cells = <0>;
-   compatible = "fsl,imx8mq-sai";
-   reg = <0x3001 0x1>;
-   interrupts = ;
-   clocks = < IMX8MQ_CLK_SAI1_IPG>,
-< IMX8MQ_CLK_SAI1_ROOT>,
-< IMX8MQ_CLK_DUMMY>, < 
IMX8MQ_CLK_DUMMY>;
-   clock-names = "bus", "mclk1", "mclk2", "mclk3";
-   dmas = < 8 24 0>, < 9 24 0>;
-   dma-names = "rx", "tx";
-   status = "disabled";
-   };
+   bus@3000 {
+   compatible = "fsl,spba-bus", "simple-bus";
+   #address-cells = <1>;
+   #size-cells = <1>;
+   reg = <0x3000 0x10>;
+   ranges;
+
+   sai1: sai@3001 {
+   #sound-dai-cells = <0>;
+   compatible = "fsl,imx8mq-sai";
+   reg = <0x3001 0x1>;
+   interrupts = ;
+   clocks = < IMX8MQ_CLK_SAI1_IPG>,
+< IMX8MQ_CLK_SAI1_ROOT>,
+< IMX8MQ_CLK_DUMMY>, < 
IMX8MQ_CLK_DUMMY>;
+   clock-names = "bus", "mclk1", "mclk2", 
"mclk3";
+   dmas = < 8 24 0>, < 9 24 0>;
+   dma-names = "rx", "tx";
+   status = "disabled";
+   };
 
-   sai6: sai@3003 {
-   #sound-dai-cells = <0>;
-   compatible = "fsl,imx8mq-sai";
-   reg = <0x3003 0x1>;
-   interrupts = ;
-   clocks = < IMX8MQ_CLK_SAI6_IPG>,
-< IMX8MQ_CLK_SAI6_ROOT>,
-< IMX8MQ_CLK_DUMMY>, < 
IMX8MQ_CLK_DUMMY>;
-   clock-names = "bus", "mclk1", "mclk2", "mclk3";
-   dmas = < 4 24 0>, < 5 24 0>;
-   dma-names = "rx", "tx";
-   status = "disabled";
-   };
+   sai6: sai@3003 {
+   #sound-dai-cells = <0>;
+   compatible = "fsl,imx8mq-sai";
+   reg = <0x3003 0x1>;
+   interrupts = ;
+   clocks = < IMX8MQ_CLK_SAI6_IPG>,
+< IMX8MQ_CLK_SAI6_ROOT>,
+< IMX8MQ_CLK_DUMMY>, < 
IMX8MQ_CLK_DUMMY>;
+   clock-names = "bus", "mclk1", "mclk2", 
"mclk3";
+   dmas = < 4 24 0>, < 5 24 0>;
+   dma-names = "rx", "tx";
+   status = "disabled";
+   };
 
-   sai5: sai@3004 {
-   #sound-dai-cells = <0>;
-   compatible = "fsl,imx8mq-sa

[PATCH 3/4] arm64: dts: imx8mn: add spba bus node

2020-12-29 Thread peng . fan
From: Peng Fan 

According to RM, there is a spba bus inside aips3 and aips1, add it.

Signed-off-by: Peng Fan 
---
 arch/arm64/boot/dts/freescale/imx8mn.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/freescale/imx8mn.dtsi 
b/arch/arm64/boot/dts/freescale/imx8mn.dtsi
index 73602832ccaa..033fa90570ff 100644
--- a/arch/arm64/boot/dts/freescale/imx8mn.dtsi
+++ b/arch/arm64/boot/dts/freescale/imx8mn.dtsi
@@ -749,7 +749,7 @@ uart2: serial@3089 {
clock-names = "ipg", "per";
status = "disabled";
};
-   }
+   };
 
crypto: crypto@3090 {
compatible = "fsl,sec-v4.0";
-- 
2.28.0



[PATCH 1/4] arm64: dts: imx8mn: add spba bus node of aips3

2020-12-29 Thread peng . fan
From: Peng Fan 

There is a spba bus inside aips3 space, add it.

Signed-off-by: Peng Fan 
---
 arch/arm64/boot/dts/freescale/imx8mn.dtsi | 148 --
 1 file changed, 78 insertions(+), 70 deletions(-)

diff --git a/arch/arm64/boot/dts/freescale/imx8mn.dtsi 
b/arch/arm64/boot/dts/freescale/imx8mn.dtsi
index ee1790230490..73602832ccaa 100644
--- a/arch/arm64/boot/dts/freescale/imx8mn.dtsi
+++ b/arch/arm64/boot/dts/freescale/imx8mn.dtsi
@@ -253,7 +253,7 @@ aips1: bus@3000 {
#size-cells = <1>;
ranges;
 
-   spba: bus@3000 {
+   spba1: bus@3000 {
compatible = "fsl,spba-bus", "simple-bus";
#address-cells = <1>;
#size-cells = <1>;
@@ -667,81 +667,89 @@ aips3: bus@3080 {
#size-cells = <1>;
ranges;
 
-   ecspi1: spi@3082 {
-   compatible = "fsl,imx8mn-ecspi", 
"fsl,imx51-ecspi";
+   spba2: bus@3080 {
+   compatible = "fsl,spba-bus", "simple-bus";
#address-cells = <1>;
-   #size-cells = <0>;
-   reg = <0x3082 0x1>;
-   interrupts = ;
-   clocks = < IMX8MN_CLK_ECSPI1_ROOT>,
-< IMX8MN_CLK_ECSPI1_ROOT>;
-   clock-names = "ipg", "per";
-   dmas = < 0 7 1>, < 1 7 2>;
-   dma-names = "rx", "tx";
-   status = "disabled";
-   };
+   #size-cells = <1>;
+   reg = <0x3080 0x10>;
+   ranges;
 
-   ecspi2: spi@3083 {
-   compatible = "fsl,imx8mn-ecspi", 
"fsl,imx51-ecspi";
-   #address-cells = <1>;
-   #size-cells = <0>;
-   reg = <0x3083 0x1>;
-   interrupts = ;
-   clocks = < IMX8MN_CLK_ECSPI2_ROOT>,
-< IMX8MN_CLK_ECSPI2_ROOT>;
-   clock-names = "ipg", "per";
-   dmas = < 2 7 1>, < 3 7 2>;
-   dma-names = "rx", "tx";
-   status = "disabled";
-   };
+   ecspi1: spi@3082 {
+   compatible = "fsl,imx8mn-ecspi", 
"fsl,imx51-ecspi";
+   #address-cells = <1>;
+   #size-cells = <0>;
+   reg = <0x3082 0x1>;
+   interrupts = ;
+   clocks = < IMX8MN_CLK_ECSPI1_ROOT>,
+< IMX8MN_CLK_ECSPI1_ROOT>;
+   clock-names = "ipg", "per";
+   dmas = < 0 7 1>, < 1 7 2>;
+   dma-names = "rx", "tx";
+   status = "disabled";
+   };
 
-   ecspi3: spi@3084 {
-   compatible = "fsl,imx8mn-ecspi", 
"fsl,imx51-ecspi";
-   #address-cells = <1>;
-   #size-cells = <0>;
-   reg = <0x3084 0x1>;
-   interrupts = ;
-   clocks = < IMX8MN_CLK_ECSPI3_ROOT>,
-< IMX8MN_CLK_ECSPI3_ROOT>;
-   clock-names = "ipg", "per";
-   dmas = < 4 7 1>, < 5 7 2>;
-   dma-names = "rx", "tx";
-   status = "disabled";
-   };
+   ecspi2: spi@3083 {
+   compatible = "fsl,imx8mn-ecspi", 
"fsl,imx

[PATCH 2/4] arm64: dts: imx8mn: add spba bus node

2020-12-29 Thread peng . fan
From: Peng Fan 

According to RM, there is a spba bus inside aips3 and aips1, add it.

Signed-off-by: Peng Fan 
---
 arch/arm64/boot/dts/freescale/imx8mm.dtsi | 362 +++---
 1 file changed, 189 insertions(+), 173 deletions(-)

diff --git a/arch/arm64/boot/dts/freescale/imx8mm.dtsi 
b/arch/arm64/boot/dts/freescale/imx8mm.dtsi
index c824f2615fe8..91f85b8cee9a 100644
--- a/arch/arm64/boot/dts/freescale/imx8mm.dtsi
+++ b/arch/arm64/boot/dts/freescale/imx8mm.dtsi
@@ -269,117 +269,125 @@ aips1: bus@3000 {
#size-cells = <1>;
ranges = <0x3000 0x3000 0x40>;
 
-   sai1: sai@3001 {
-   #sound-dai-cells = <0>;
-   compatible = "fsl,imx8mm-sai", "fsl,imx8mq-sai";
-   reg = <0x3001 0x1>;
-   interrupts = ;
-   clocks = < IMX8MM_CLK_SAI1_IPG>,
-< IMX8MM_CLK_SAI1_ROOT>,
-< IMX8MM_CLK_DUMMY>, < 
IMX8MM_CLK_DUMMY>;
-   clock-names = "bus", "mclk1", "mclk2", "mclk3";
-   dmas = < 0 2 0>, < 1 2 0>;
-   dma-names = "rx", "tx";
-   status = "disabled";
-   };
+   bus@3000 {
+   compatible = "fsl,spba-bus", "simple-bus";
+   #address-cells = <1>;
+   #size-cells = <1>;
+   reg = <0x3000 0x10>;
+   ranges;
+
+   sai1: sai@3001 {
+   #sound-dai-cells = <0>;
+   compatible = "fsl,imx8mm-sai", 
"fsl,imx8mq-sai";
+   reg = <0x3001 0x1>;
+   interrupts = ;
+   clocks = < IMX8MM_CLK_SAI1_IPG>,
+< IMX8MM_CLK_SAI1_ROOT>,
+< IMX8MM_CLK_DUMMY>, < 
IMX8MM_CLK_DUMMY>;
+   clock-names = "bus", "mclk1", "mclk2", 
"mclk3";
+   dmas = < 0 2 0>, < 1 2 0>;
+   dma-names = "rx", "tx";
+   status = "disabled";
+   };
 
-   sai2: sai@3002 {
-   #sound-dai-cells = <0>;
-   compatible = "fsl,imx8mm-sai", "fsl,imx8mq-sai";
-   reg = <0x3002 0x1>;
-   interrupts = ;
-   clocks = < IMX8MM_CLK_SAI2_IPG>,
-   < IMX8MM_CLK_SAI2_ROOT>,
-   < IMX8MM_CLK_DUMMY>, < 
IMX8MM_CLK_DUMMY>;
-   clock-names = "bus", "mclk1", "mclk2", "mclk3";
-   dmas = < 2 2 0>, < 3 2 0>;
-   dma-names = "rx", "tx";
-   status = "disabled";
-   };
+   sai2: sai@3002 {
+   #sound-dai-cells = <0>;
+   compatible = "fsl,imx8mm-sai", 
"fsl,imx8mq-sai";
+   reg = <0x3002 0x1>;
+   interrupts = ;
+   clocks = < IMX8MM_CLK_SAI2_IPG>,
+   < IMX8MM_CLK_SAI2_ROOT>,
+   < IMX8MM_CLK_DUMMY>, < 
IMX8MM_CLK_DUMMY>;
+   clock-names = "bus", "mclk1", "mclk2", 
"mclk3";
+   dmas = < 2 2 0>, < 3 2 0>;
+   dma-names = "rx", "tx";
+   status = "disabled";
+   };
 
-   sai3: sai@3003 {
-   #sound-dai-cells 

[PATCH 0/4] arm64: dts: imx8m: add spda bus

2020-12-29 Thread peng . fan
From: Peng Fan 

There is spba bus in aips1 and aips3, each spba bus has some
peripherals inside, add the spba bus node

Peng Fan (4):
  arm64: dts: imx8mn: add spba bus node of aips3
  arm64: dts: imx8mn: add spba bus node
  arm64: dts: imx8mn: add spba bus node
  arm64: dts: imx8mq: add spba bus node

 arch/arm64/boot/dts/freescale/imx8mm.dtsi | 362 ++--
 arch/arm64/boot/dts/freescale/imx8mn.dtsi | 146 
 arch/arm64/boot/dts/freescale/imx8mq.dtsi | 386 +++---
 3 files changed, 467 insertions(+), 427 deletions(-)

-- 
2.28.0



[PATCH V5 6/8] remoteproc: imx_rproc: support i.MX8MQ/M

2020-12-28 Thread peng . fan
From: Peng Fan 

Add i.MX8MQ dev/sys addr map and configuration data structure
i.MX8MM share i.MX8MQ settings.

Reviewed-by: Richard Zhu 
Signed-off-by: Peng Fan 
Reviewed-by: Mathieu Poirier 
---
 drivers/remoteproc/imx_rproc.c | 39 ++
 1 file changed, 39 insertions(+)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 3c0075dc1787..f80428afb8a7 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -88,6 +88,34 @@ struct imx_rproc {
struct clk  *clk;
 };
 
+static const struct imx_rproc_att imx_rproc_att_imx8mq[] = {
+   /* dev addr , sys addr  , size  , flags */
+   /* TCML - alias */
+   { 0x, 0x007e, 0x0002, 0 },
+   /* OCRAM_S */
+   { 0x0018, 0x0018, 0x8000, 0 },
+   /* OCRAM */
+   { 0x0090, 0x0090, 0x0002, 0 },
+   /* OCRAM */
+   { 0x0092, 0x0092, 0x0002, 0 },
+   /* QSPI Code - alias */
+   { 0x0800, 0x0800, 0x0800, 0 },
+   /* DDR (Code) - alias */
+   { 0x1000, 0x8000, 0x0FFE, 0 },
+   /* TCML */
+   { 0x1FFE, 0x007E, 0x0002, ATT_OWN },
+   /* TCMU */
+   { 0x2000, 0x0080, 0x0002, ATT_OWN },
+   /* OCRAM_S */
+   { 0x2018, 0x0018, 0x8000, ATT_OWN },
+   /* OCRAM */
+   { 0x2020, 0x0090, 0x0002, ATT_OWN },
+   /* OCRAM */
+   { 0x2022, 0x0092, 0x0002, ATT_OWN },
+   /* DDR (Data) */
+   { 0x4000, 0x4000, 0x8000, 0 },
+};
+
 static const struct imx_rproc_att imx_rproc_att_imx7d[] = {
/* dev addr , sys addr  , size  , flags */
/* OCRAM_S (M4 Boot code) - alias */
@@ -138,6 +166,15 @@ static const struct imx_rproc_att imx_rproc_att_imx6sx[] = 
{
{ 0x8000, 0x8000, 0x6000, 0 },
 };
 
+static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mq = {
+   .src_reg= IMX7D_SRC_SCR,
+   .src_mask   = IMX7D_M4_RST_MASK,
+   .src_start  = IMX7D_M4_START,
+   .src_stop   = IMX7D_M4_STOP,
+   .att= imx_rproc_att_imx8mq,
+   .att_size   = ARRAY_SIZE(imx_rproc_att_imx8mq),
+};
+
 static const struct imx_rproc_dcfg imx_rproc_cfg_imx7d = {
.src_reg= IMX7D_SRC_SCR,
.src_mask   = IMX7D_M4_RST_MASK,
@@ -496,6 +533,8 @@ static int imx_rproc_remove(struct platform_device *pdev)
 static const struct of_device_id imx_rproc_of_match[] = {
{ .compatible = "fsl,imx7d-cm4", .data = _rproc_cfg_imx7d },
{ .compatible = "fsl,imx6sx-cm4", .data = _rproc_cfg_imx6sx },
+   { .compatible = "fsl,imx8mq-cm4", .data = _rproc_cfg_imx8mq },
+   { .compatible = "fsl,imx8mm-cm4", .data = _rproc_cfg_imx8mq },
{},
 };
 MODULE_DEVICE_TABLE(of, imx_rproc_of_match);
-- 
2.28.0



[PATCH V5 8/8] remoteproc: imx_proc: enable virtio/mailbox

2020-12-28 Thread peng . fan
From: Peng Fan 

Use virtio/mailbox to build connection between Remote Proccessors
and Linux. Add work queue to handle incoming messages.

Reviewed-by: Richard Zhu 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c | 115 -
 1 file changed, 112 insertions(+), 3 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index e62a53ee128e..812b077f1282 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -15,6 +16,9 @@
 #include 
 #include 
 #include 
+#include 
+
+#include "remoteproc_internal.h"
 
 #define IMX7D_SRC_SCR  0x0C
 #define IMX7D_ENABLE_M4BIT(3)
@@ -86,6 +90,11 @@ struct imx_rproc {
const struct imx_rproc_dcfg *dcfg;
struct imx_rproc_memmem[IMX7D_RPROC_MEM_MAX];
struct clk  *clk;
+   struct mbox_client  cl;
+   struct mbox_chan*tx_ch;
+   struct mbox_chan*rx_ch;
+   struct work_struct  rproc_work;
+   struct workqueue_struct *workqueue;
 };
 
 static const struct imx_rproc_att imx_rproc_att_imx8mq[] = {
@@ -366,9 +375,33 @@ static int imx_rproc_parse_fw(struct rproc *rproc, const 
struct firmware *fw)
return 0;
 }
 
+static void imx_rproc_kick(struct rproc *rproc, int vqid)
+{
+   struct imx_rproc *priv = rproc->priv;
+   int err;
+   __u32 mmsg;
+
+   if (!priv->tx_ch) {
+   dev_err(priv->dev, "No initialized mbox tx channel\n");
+   return;
+   }
+
+   /*
+* Send the index of the triggered virtqueue as the mu payload.
+* Let remote processor know which virtqueue is used.
+*/
+   mmsg = vqid << 16;
+
+   err = mbox_send_message(priv->tx_ch, (void *));
+   if (err < 0)
+   dev_err(priv->dev, "%s: failed (%d, err:%d)\n",
+   __func__, vqid, err);
+}
+
 static const struct rproc_ops imx_rproc_ops = {
.start  = imx_rproc_start,
.stop   = imx_rproc_stop,
+   .kick   = imx_rproc_kick,
.da_to_va   = imx_rproc_da_to_va,
.load   = rproc_elf_load_segments,
.parse_fw   = imx_rproc_parse_fw,
@@ -444,6 +477,65 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
return 0;
 }
 
+static void imx_rproc_vq_work(struct work_struct *work)
+{
+   struct imx_rproc *priv = container_of(work, struct imx_rproc,
+ rproc_work);
+
+   rproc_vq_interrupt(priv->rproc, 0);
+   rproc_vq_interrupt(priv->rproc, 1);
+}
+
+static void imx_rproc_rx_callback(struct mbox_client *cl, void *msg)
+{
+   struct rproc *rproc = dev_get_drvdata(cl->dev);
+   struct imx_rproc *priv = rproc->priv;
+
+   queue_work(priv->workqueue, >rproc_work);
+}
+
+static int imx_rproc_xtr_mbox_init(struct rproc *rproc)
+{
+   struct imx_rproc *priv = rproc->priv;
+   struct device *dev = priv->dev;
+   struct mbox_client *cl;
+   int ret;
+
+   if (!of_get_property(dev->of_node, "mbox-names", NULL))
+   return 0;
+
+   cl = >cl;
+   cl->dev = dev;
+   cl->tx_block = true;
+   cl->tx_tout = 100;
+   cl->knows_txdone = false;
+   cl->rx_callback = imx_rproc_rx_callback;
+
+   priv->tx_ch = mbox_request_channel_byname(cl, "tx");
+   if (IS_ERR(priv->tx_ch)) {
+   ret = PTR_ERR(priv->tx_ch);
+   return dev_err_probe(cl->dev, PTR_ERR(priv->tx_ch),
+"failed to request tx mailbox channel: 
%d\n", ret);
+   }
+
+   priv->rx_ch = mbox_request_channel_byname(cl, "rx");
+   if (IS_ERR(priv->rx_ch)) {
+   mbox_free_channel(priv->tx_ch);
+   return dev_err_probe(cl->dev, PTR_ERR(priv->rx_ch),
+"failed to request mbox tx chan\n");
+   }
+
+   return 0;
+}
+
+static void imx_rproc_free_mbox(struct rproc *rproc)
+{
+   struct imx_rproc *priv = rproc->priv;
+
+   mbox_free_channel(priv->tx_ch);
+   mbox_free_channel(priv->rx_ch);
+}
+
 static int imx_rproc_probe(struct platform_device *pdev)
 {
struct device *dev = >dev;
@@ -481,18 +573,28 @@ static int imx_rproc_probe(struct platform_device *pdev)
priv->dev = dev;
 
dev_set_drvdata(dev, rproc);
+   priv->workqueue = create_workqueue(dev_name(dev));
+   if (!priv->workqueue) {
+   dev_err(dev, "cannot create workqueue\n");
+   ret = -ENOMEM;
+   goto err_put_rproc;
+  

[PATCH V5 5/8] remoteproc: imx_rproc: add i.MX specific parse fw hook

2020-12-28 Thread peng . fan
From: Peng Fan 

The hook is used to parse memory-regions and load resource table
from the address the remote processor published.

Signed-off-by: Peng Fan 
Reviewed-by: Richard Zhu 
Reviewed-by: Mathieu Poirier 
---
 drivers/remoteproc/imx_rproc.c | 93 ++
 1 file changed, 93 insertions(+)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 47fc1d06be6a..3c0075dc1787 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -241,10 +242,102 @@ static void *imx_rproc_da_to_va(struct rproc *rproc, u64 
da, size_t len, bool *i
return va;
 }
 
+static int imx_rproc_mem_alloc(struct rproc *rproc,
+  struct rproc_mem_entry *mem)
+{
+   struct device *dev = rproc->dev.parent;
+   void *va;
+
+   dev_dbg(dev, "map memory: %p+%zx\n", >dma, mem->len);
+   va = ioremap_wc(mem->dma, mem->len);
+   if (IS_ERR_OR_NULL(va)) {
+   dev_err(dev, "Unable to map memory region: %p+%zx\n",
+   >dma, mem->len);
+   return -ENOMEM;
+   }
+
+   /* Update memory entry va */
+   mem->va = va;
+
+   return 0;
+}
+
+static int imx_rproc_mem_release(struct rproc *rproc,
+struct rproc_mem_entry *mem)
+{
+   dev_dbg(rproc->dev.parent, "unmap memory: %pa\n", >dma);
+   iounmap(mem->va);
+
+   return 0;
+}
+
+static int imx_rproc_parse_memory_regions(struct rproc *rproc)
+{
+   struct imx_rproc *priv = rproc->priv;
+   struct device_node *np = priv->dev->of_node;
+   struct of_phandle_iterator it;
+   struct rproc_mem_entry *mem;
+   struct reserved_mem *rmem;
+   u32 da;
+
+   /* Register associated reserved memory regions */
+   of_phandle_iterator_init(, np, "memory-region", NULL, 0);
+   while (of_phandle_iterator_next() == 0) {
+   /*
+* Ignore the first memory region which will be used vdev 
buffer.
+* No need to do extra handlings, rproc_add_virtio_dev will 
handle it.
+*/
+   if (!strcmp(it.node->name, "vdevbuffer"))
+   continue;
+
+   rmem = of_reserved_mem_lookup(it.node);
+   if (!rmem) {
+   dev_err(priv->dev, "unable to acquire memory-region\n");
+   return -EINVAL;
+   }
+
+   /* No need to translate pa to da, i.MX use same map */
+   da = rmem->base;
+
+   /* Register memory region */
+   mem = rproc_mem_entry_init(priv->dev, NULL, 
(dma_addr_t)rmem->base, rmem->size, da,
+  imx_rproc_mem_alloc, 
imx_rproc_mem_release,
+  it.node->name);
+
+   if (mem)
+   rproc_coredump_add_segment(rproc, da, rmem->size);
+   else
+   return -ENOMEM;
+
+   rproc_add_carveout(rproc, mem);
+   }
+
+   return  0;
+}
+
+static int imx_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
+{
+   int ret = imx_rproc_parse_memory_regions(rproc);
+
+   if (ret)
+   return ret;
+
+   ret = rproc_elf_load_rsc_table(rproc, fw);
+   if (ret)
+   dev_info(>dev, "No resource table in elf\n");
+
+   return 0;
+}
+
 static const struct rproc_ops imx_rproc_ops = {
.start  = imx_rproc_start,
.stop   = imx_rproc_stop,
.da_to_va   = imx_rproc_da_to_va,
+   .load   = rproc_elf_load_segments,
+   .parse_fw   = imx_rproc_parse_fw,
+   .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table,
+   .sanity_check   = rproc_elf_sanity_check,
+   .get_boot_addr  = rproc_elf_get_boot_addr,
 };
 
 static int imx_rproc_addr_init(struct imx_rproc *priv,
-- 
2.28.0



[PATCH V5 2/8] remoteproc: add is_iomem to da_to_va

2020-12-28 Thread peng . fan
From: Peng Fan 

Introduce an extra parameter is_iomem to da_to_va, then the caller
could take the memory as normal memory or io mapped memory.

Reviewed-by: Bjorn Andersson 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c |  2 +-
 drivers/remoteproc/ingenic_rproc.c |  2 +-
 drivers/remoteproc/keystone_remoteproc.c   |  2 +-
 drivers/remoteproc/mtk_scp.c   |  6 +++---
 drivers/remoteproc/omap_remoteproc.c   |  2 +-
 drivers/remoteproc/pru_rproc.c |  2 +-
 drivers/remoteproc/qcom_q6v5_adsp.c|  2 +-
 drivers/remoteproc/qcom_q6v5_pas.c |  2 +-
 drivers/remoteproc/qcom_q6v5_wcss.c|  2 +-
 drivers/remoteproc/qcom_wcnss.c|  2 +-
 drivers/remoteproc/remoteproc_core.c   |  7 +--
 drivers/remoteproc/remoteproc_coredump.c   |  8 ++--
 drivers/remoteproc/remoteproc_debugfs.c|  2 +-
 drivers/remoteproc/remoteproc_elf_loader.c | 21 +++--
 drivers/remoteproc/remoteproc_internal.h   |  2 +-
 drivers/remoteproc/st_slim_rproc.c |  2 +-
 drivers/remoteproc/ti_k3_dsp_remoteproc.c  |  2 +-
 drivers/remoteproc/ti_k3_r5_remoteproc.c   |  2 +-
 drivers/remoteproc/wkup_m3_rproc.c |  2 +-
 include/linux/remoteproc.h |  2 +-
 20 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 8957ed271d20..6603e00bb6f4 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -208,7 +208,7 @@ static int imx_rproc_da_to_sys(struct imx_rproc *priv, u64 
da,
return -ENOENT;
 }
 
-static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool 
*is_iomem)
 {
struct imx_rproc *priv = rproc->priv;
void *va = NULL;
diff --git a/drivers/remoteproc/ingenic_rproc.c 
b/drivers/remoteproc/ingenic_rproc.c
index 26e19e6143b7..bb5049295576 100644
--- a/drivers/remoteproc/ingenic_rproc.c
+++ b/drivers/remoteproc/ingenic_rproc.c
@@ -116,7 +116,7 @@ static void ingenic_rproc_kick(struct rproc *rproc, int 
vqid)
writel(vqid, vpu->aux_base + REG_CORE_MSG);
 }
 
-static void *ingenic_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *ingenic_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, 
bool *is_iomem)
 {
struct vpu *vpu = rproc->priv;
void __iomem *va = NULL;
diff --git a/drivers/remoteproc/keystone_remoteproc.c 
b/drivers/remoteproc/keystone_remoteproc.c
index cd266163a65f..54781f553f4e 100644
--- a/drivers/remoteproc/keystone_remoteproc.c
+++ b/drivers/remoteproc/keystone_remoteproc.c
@@ -246,7 +246,7 @@ static void keystone_rproc_kick(struct rproc *rproc, int 
vqid)
  * can be used either by the remoteproc core for loading (when using kernel
  * remoteproc loader), or by any rpmsg bus drivers.
  */
-static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, 
bool *is_iomem)
 {
struct keystone_rproc *ksproc = rproc->priv;
void __iomem *va = NULL;
diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c
index e0c235690361..535175f013e4 100644
--- a/drivers/remoteproc/mtk_scp.c
+++ b/drivers/remoteproc/mtk_scp.c
@@ -270,7 +270,7 @@ static int scp_elf_load_segments(struct rproc *rproc, const 
struct firmware *fw)
}
 
/* grab the kernel address for this device address */
-   ptr = (void __iomem *)rproc_da_to_va(rproc, da, memsz);
+   ptr = (void __iomem *)rproc_da_to_va(rproc, da, memsz, NULL);
if (!ptr) {
dev_err(dev, "bad phdr da 0x%x mem 0x%x\n", da, memsz);
ret = -EINVAL;
@@ -458,7 +458,7 @@ static int scp_start(struct rproc *rproc)
return ret;
 }
 
-static void *scp_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *scp_da_to_va(struct rproc *rproc, u64 da, size_t len, bool 
*is_iomem)
 {
struct mtk_scp *scp = (struct mtk_scp *)rproc->priv;
int offset;
@@ -587,7 +587,7 @@ void *scp_mapping_dm_addr(struct mtk_scp *scp, u32 mem_addr)
 {
void *ptr;
 
-   ptr = scp_da_to_va(scp->rproc, mem_addr, 0);
+   ptr = scp_da_to_va(scp->rproc, mem_addr, 0, NULL);
if (!ptr)
return ERR_PTR(-EINVAL);
 
diff --git a/drivers/remoteproc/omap_remoteproc.c 
b/drivers/remoteproc/omap_remoteproc.c
index d94b7391bf9d..43531caa1959 100644
--- a/drivers/remoteproc/omap_remoteproc.c
+++ b/drivers/remoteproc/omap_remoteproc.c
@@ -728,7 +728,7 @@ static int omap_rproc_stop(struct rproc *rproc)
  * Return: translated virtual address in kernel memory space on success,
  * or NULL on failure.
  */
-static void *omap_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *omap_rproc_da_to

[PATCH V5 4/8] remoteproc: imx_rproc: use devm_ioremap

2020-12-28 Thread peng . fan
From: Peng Fan 

We might need to map an region multiple times, becaue the region might
be shared between remote processors, such i.MX8QM with dual M4 cores.
So use devm_ioremap, not devm_ioremap_resource.

Reviewed-by: Oleksij Rempel 
Reviewed-by: Richard Zhu 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 2a093cea4997..47fc1d06be6a 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -296,7 +296,8 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
if (b >= IMX7D_RPROC_MEM_MAX)
break;
 
-   priv->mem[b].cpu_addr = devm_ioremap_resource(>dev, );
+   /* Not use resource version, because we might share region */
+   priv->mem[b].cpu_addr = devm_ioremap(>dev, res.start, 
resource_size());
if (IS_ERR(priv->mem[b].cpu_addr)) {
dev_err(dev, "failed to remap %pr\n", );
err = PTR_ERR(priv->mem[b].cpu_addr);
-- 
2.28.0



[PATCH V5 3/8] remoteproc: imx_rproc: correct err message

2020-12-28 Thread peng . fan
From: Peng Fan 

It is using devm_ioremap, so not devm_ioremap_resource. Correct
the error message and print out sa/size.

Reviewed-by: Bjorn Andersson 
Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 6603e00bb6f4..2a093cea4997 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -268,7 +268,7 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
priv->mem[b].cpu_addr = devm_ioremap(>dev,
 att->sa, att->size);
if (!priv->mem[b].cpu_addr) {
-   dev_err(dev, "devm_ioremap_resource failed\n");
+   dev_err(dev, "failed to remap %#x bytes from %#x\n", 
att->size, att->sa);
return -ENOMEM;
}
priv->mem[b].sys_addr = att->sa;
@@ -298,7 +298,7 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
 
priv->mem[b].cpu_addr = devm_ioremap_resource(>dev, );
if (IS_ERR(priv->mem[b].cpu_addr)) {
-   dev_err(dev, "devm_ioremap_resource failed\n");
+   dev_err(dev, "failed to remap %pr\n", );
err = PTR_ERR(priv->mem[b].cpu_addr);
return err;
}
-- 
2.28.0



[PATCH V5 7/8] remoteproc: imx_rproc: ignore mapping vdev regions

2020-12-28 Thread peng . fan
From: Peng Fan 

vdev regions are vdev0vring0, vdev0vring1, vdevbuffer and similar.
They are handled by remoteproc common code, no need to map in imx
rproc driver.

Signed-off-by: Peng Fan 
---
 drivers/remoteproc/imx_rproc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index f80428afb8a7..e62a53ee128e 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -417,6 +417,9 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
struct resource res;
 
node = of_parse_phandle(np, "memory-region", a);
+   /* Not map vdev region */
+   if (!strcmp(node->name, "vdev"))
+   continue;
err = of_address_to_resource(node, 0, );
if (err) {
dev_err(dev, "unable to resolve memory region\n");
-- 
2.28.0



[PATCH V5 1/8] remoteproc: introduce is_iomem to rproc_mem_entry

2020-12-28 Thread peng . fan
From: Peng Fan 

Introduce is_iomem to indicate this piece memory is iomem or not.

Reviewed-by: Bjorn Andersson 
Signed-off-by: Peng Fan 
---
 include/linux/remoteproc.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index f28ee75d1005..a5f6d2d9cde2 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -315,6 +315,7 @@ struct rproc;
 /**
  * struct rproc_mem_entry - memory entry descriptor
  * @va:virtual address
+ * @is_iomem: io memory
  * @dma: dma address
  * @len: length, in bytes
  * @da: device address
@@ -329,6 +330,7 @@ struct rproc;
  */
 struct rproc_mem_entry {
void *va;
+   bool is_iomem;
dma_addr_t dma;
size_t len;
u32 da;
-- 
2.28.0



[PATCH V5 0/8] remoteproc: imx_rproc: support iMX8MQ/M

2020-12-28 Thread peng . fan
From: Peng Fan 

V5:
 Apply on Linux next
 Add V5 subject prefix
 Add R-b tag from Bjorn for 1/8, 2/8, 3/8

V4:
 According to Bjorn's comments, add is_iomem for da to va usage
 1/8, 2/8 is new patch
 3/8, follow Bjorn's comments to correct/update the err msg.
 6/8, new patch
 8/8, use dev_err_probe to simplify code, use queue_work instead 
schedule_delayed_work

V3:
 Since I was quite busy in the past days, V3 is late
 Rebased on Linux-next
 Add R-b tags
 1/7: Add R-b tag of Mathieu, add comments
 4/7: Typo fix
 5/7: Add R-b tag of Mathieu, drop index Per Mathieu's comments
 6/7: Add R-b tag of Mathieu
 7/7: Add comment for vqid << 16, drop unneeded timeout settings of mailbox
  Use queue_work instead of schedule_delayed_work
  free mbox channels when remove
 https://lkml.org/lkml/2020/12/4/82

V2:
 Rebased on linux-next
 Dropped early boot feature to make patchset simple.
 Drop rsc-da
 
https://patchwork.kernel.org/project/linux-remoteproc/cover/20200927064131.24101-1-peng@nxp.com/

V1:
 https://patchwork.kernel.org/cover/11682461/

This patchset is to support i.MX8MQ/M coproc.
The early boot feature was dropped to make the patchset small in V2.

Since i.MX specific TCM memory requirement, add elf platform hook.
Several patches have got reviewed by Oleksij and Mathieu in v1.

Peng Fan (8):
  remoteproc: introduce is_iomem to rproc_mem_entry
  remoteproc: add is_iomem to da_to_va
  remoteproc: imx_rproc: correct err message
  remoteproc: imx_rproc: use devm_ioremap
  remoteproc: imx_rproc: add i.MX specific parse fw hook
  remoteproc: imx_rproc: support i.MX8MQ/M
  remoteproc: imx_rproc: ignore mapping vdev regions
  remoteproc: imx_proc: enable virtio/mailbox

 drivers/remoteproc/imx_rproc.c | 259 -
 drivers/remoteproc/ingenic_rproc.c |   2 +-
 drivers/remoteproc/keystone_remoteproc.c   |   2 +-
 drivers/remoteproc/mtk_scp.c   |   6 +-
 drivers/remoteproc/omap_remoteproc.c   |   2 +-
 drivers/remoteproc/pru_rproc.c |   2 +-
 drivers/remoteproc/qcom_q6v5_adsp.c|   2 +-
 drivers/remoteproc/qcom_q6v5_pas.c |   2 +-
 drivers/remoteproc/qcom_q6v5_wcss.c|   2 +-
 drivers/remoteproc/qcom_wcnss.c|   2 +-
 drivers/remoteproc/remoteproc_core.c   |   7 +-
 drivers/remoteproc/remoteproc_coredump.c   |   8 +-
 drivers/remoteproc/remoteproc_debugfs.c|   2 +-
 drivers/remoteproc/remoteproc_elf_loader.c |  21 +-
 drivers/remoteproc/remoteproc_internal.h   |   2 +-
 drivers/remoteproc/st_slim_rproc.c |   2 +-
 drivers/remoteproc/ti_k3_dsp_remoteproc.c  |   2 +-
 drivers/remoteproc/ti_k3_r5_remoteproc.c   |   2 +-
 drivers/remoteproc/wkup_m3_rproc.c |   2 +-
 include/linux/remoteproc.h |   4 +-
 20 files changed, 298 insertions(+), 35 deletions(-)

-- 
2.28.0



RE: [PATCH 0/8] remoteproc: imx_rproc: support iMX8MQ/M

2020-12-21 Thread Peng Fan
Hi Bjorn,

> Subject: [PATCH 0/8] remoteproc: imx_rproc: support iMX8MQ/M

I forgot to add subject-prefix V4 when format-patch.
Do you need to send out v5? or you could take this v4 version if it
is ok for you?

Thanks,
Peng.

> 
> From: Peng Fan 
> 
> V4:
>  According to Bjorn's comments, add is_iomem for da to va usage  1/8, 2/8
> is new patch  3/8, follow Bjorn's comments to correct/update the err msg.
>  6/8, new patch
>  8/8, use dev_err_probe to simplify code, use queue_work instead
> schedule_delayed_work
>  https://lkml.org/lkml/2020/12/4/82
> 
> V3:
>  Since I was quite busy in the past days, V3 is late  Rebased on Linux-next
> Add R-b tags
>  1/7: Add R-b tag of Mathieu, add comments
>  4/7: Typo fix
>  5/7: Add R-b tag of Mathieu, drop index Per Mathieu's comments
>  6/7: Add R-b tag of Mathieu
>  7/7: Add comment for vqid << 16, drop unneeded timeout settings of
> mailbox
>   Use queue_work instead of schedule_delayed_work
>   free mbox channels when remove
> 
> V2:
>  Rebased on linux-next
>  Dropped early boot feature to make patchset simple.
>  Drop rsc-da
> 
> https://patchwork.kernel.org/project/linux-remoteproc/cover/20200927064
> 131.24101-1-peng@nxp.com/
> 
> V1:
>  https://patchwork.kernel.org/cover/11682461/
> 
> This patchset is to support i.MX8MQ/M coproc.
> The early boot feature was dropped to make the patchset small in V2.
> 
> Since i.MX specific TCM memory requirement, add elf platform hook.
> Several patches have got reviewed by Oleksij and Mathieu in v1.
> 
> Peng Fan (8):
>   remoteproc: introduce is_iomem to rproc_mem_entry
>   remoteproc: add is_iomem to da_to_va
>   remoteproc: imx_rproc: correct err message
>   remoteproc: imx_rproc: use devm_ioremap
>   remoteproc: imx_rproc: add i.MX specific parse fw hook
>   remoteproc: imx_rproc: support i.MX8MQ/M
>   remoteproc: imx_rproc: ignore mapping vdev regions
>   remoteproc: imx_proc: enable virtio/mailbox
> 
>  drivers/remoteproc/imx_rproc.c | 259
> -
>  drivers/remoteproc/ingenic_rproc.c |   2 +-
>  drivers/remoteproc/keystone_remoteproc.c   |   2 +-
>  drivers/remoteproc/mtk_scp.c   |   6 +-
>  drivers/remoteproc/omap_remoteproc.c   |   2 +-
>  drivers/remoteproc/pru_rproc.c |   2 +-
>  drivers/remoteproc/qcom_q6v5_adsp.c|   2 +-
>  drivers/remoteproc/qcom_q6v5_pas.c |   2 +-
>  drivers/remoteproc/qcom_q6v5_wcss.c|   2 +-
>  drivers/remoteproc/qcom_wcnss.c|   2 +-
>  drivers/remoteproc/remoteproc_core.c   |   7 +-
>  drivers/remoteproc/remoteproc_coredump.c   |   8 +-
>  drivers/remoteproc/remoteproc_debugfs.c|   2 +-
>  drivers/remoteproc/remoteproc_elf_loader.c |  21 +-
>  drivers/remoteproc/remoteproc_internal.h   |   2 +-
>  drivers/remoteproc/st_slim_rproc.c |   2 +-
>  drivers/remoteproc/ti_k3_dsp_remoteproc.c  |   2 +-
>  drivers/remoteproc/ti_k3_r5_remoteproc.c   |   2 +-
>  drivers/remoteproc/wkup_m3_rproc.c |   2 +-
>  include/linux/remoteproc.h |   4 +-
>  20 files changed, 298 insertions(+), 35 deletions(-)
> 
> --
> 2.28.0



[PATCH 4/8] remoteproc: imx_rproc: use devm_ioremap

2020-12-21 Thread Peng Fan (OSS)
From: Peng Fan 

We might need to map an region multiple times, becaue the region might
be shared between remote processors, such i.MX8QM with dual M4 cores.
So use devm_ioremap, not devm_ioremap_resource.

Reviewed-by: Oleksij Rempel 
Reviewed-by: Richard Zhu 
Signed-off-by: Peng Fan 
---

V4:
 None

 drivers/remoteproc/imx_rproc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index fab772b02c9f..3915c7f5ac47 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -296,7 +296,8 @@ static int imx_rproc_addr_init(struct imx_rproc *priv,
if (b >= IMX7D_RPROC_MEM_MAX)
break;
 
-   priv->mem[b].cpu_addr = devm_ioremap_resource(>dev, );
+   /* Not use resource version, because we might share region */
+   priv->mem[b].cpu_addr = devm_ioremap(>dev, res.start, 
resource_size());
if (IS_ERR(priv->mem[b].cpu_addr)) {
dev_err(dev, "failed to remap %pr \n", );
err = PTR_ERR(priv->mem[b].cpu_addr);
-- 
2.28.0



[PATCH 0/8] remoteproc: imx_rproc: support iMX8MQ/M

2020-12-21 Thread Peng Fan (OSS)
From: Peng Fan 

V4:
 According to Bjorn's comments, add is_iomem for da to va usage
 1/8, 2/8 is new patch
 3/8, follow Bjorn's comments to correct/update the err msg.
 6/8, new patch
 8/8, use dev_err_probe to simplify code, use queue_work instead 
schedule_delayed_work
 https://lkml.org/lkml/2020/12/4/82

V3:
 Since I was quite busy in the past days, V3 is late
 Rebased on Linux-next
 Add R-b tags
 1/7: Add R-b tag of Mathieu, add comments
 4/7: Typo fix
 5/7: Add R-b tag of Mathieu, drop index Per Mathieu's comments
 6/7: Add R-b tag of Mathieu
 7/7: Add comment for vqid << 16, drop unneeded timeout settings of mailbox
  Use queue_work instead of schedule_delayed_work
  free mbox channels when remove

V2:
 Rebased on linux-next
 Dropped early boot feature to make patchset simple.
 Drop rsc-da
 
https://patchwork.kernel.org/project/linux-remoteproc/cover/20200927064131.24101-1-peng@nxp.com/

V1:
 https://patchwork.kernel.org/cover/11682461/

This patchset is to support i.MX8MQ/M coproc.
The early boot feature was dropped to make the patchset small in V2.

Since i.MX specific TCM memory requirement, add elf platform hook.
Several patches have got reviewed by Oleksij and Mathieu in v1.

Peng Fan (8):
  remoteproc: introduce is_iomem to rproc_mem_entry
  remoteproc: add is_iomem to da_to_va
  remoteproc: imx_rproc: correct err message
  remoteproc: imx_rproc: use devm_ioremap
  remoteproc: imx_rproc: add i.MX specific parse fw hook
  remoteproc: imx_rproc: support i.MX8MQ/M
  remoteproc: imx_rproc: ignore mapping vdev regions
  remoteproc: imx_proc: enable virtio/mailbox

 drivers/remoteproc/imx_rproc.c | 259 -
 drivers/remoteproc/ingenic_rproc.c |   2 +-
 drivers/remoteproc/keystone_remoteproc.c   |   2 +-
 drivers/remoteproc/mtk_scp.c   |   6 +-
 drivers/remoteproc/omap_remoteproc.c   |   2 +-
 drivers/remoteproc/pru_rproc.c |   2 +-
 drivers/remoteproc/qcom_q6v5_adsp.c|   2 +-
 drivers/remoteproc/qcom_q6v5_pas.c |   2 +-
 drivers/remoteproc/qcom_q6v5_wcss.c|   2 +-
 drivers/remoteproc/qcom_wcnss.c|   2 +-
 drivers/remoteproc/remoteproc_core.c   |   7 +-
 drivers/remoteproc/remoteproc_coredump.c   |   8 +-
 drivers/remoteproc/remoteproc_debugfs.c|   2 +-
 drivers/remoteproc/remoteproc_elf_loader.c |  21 +-
 drivers/remoteproc/remoteproc_internal.h   |   2 +-
 drivers/remoteproc/st_slim_rproc.c |   2 +-
 drivers/remoteproc/ti_k3_dsp_remoteproc.c  |   2 +-
 drivers/remoteproc/ti_k3_r5_remoteproc.c   |   2 +-
 drivers/remoteproc/wkup_m3_rproc.c |   2 +-
 include/linux/remoteproc.h |   4 +-
 20 files changed, 298 insertions(+), 35 deletions(-)

-- 
2.28.0



[PATCH 1/8] remoteproc: introduce is_iomem to rproc_mem_entry

2020-12-21 Thread Peng Fan (OSS)
From: Peng Fan 

Introduce is_iomem to indicate this piece memory is iomem or not.

Signed-off-by: Peng Fan 
---

V4:
 New patch

 include/linux/remoteproc.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index f28ee75d1005..a5f6d2d9cde2 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -315,6 +315,7 @@ struct rproc;
 /**
  * struct rproc_mem_entry - memory entry descriptor
  * @va:virtual address
+ * @is_iomem: io memory
  * @dma: dma address
  * @len: length, in bytes
  * @da: device address
@@ -329,6 +330,7 @@ struct rproc;
  */
 struct rproc_mem_entry {
void *va;
+   bool is_iomem;
dma_addr_t dma;
size_t len;
u32 da;
-- 
2.28.0



[PATCH 5/8] remoteproc: imx_rproc: add i.MX specific parse fw hook

2020-12-21 Thread Peng Fan (OSS)
From: Peng Fan 

The hook is used to parse memory-regions and load resource table
from the address the remote processor published.

Signed-off-by: Peng Fan 
Reviewed-by: Richard Zhu 
Reviewed-by: Mathieu Poirier 
---

V4:
 None

 drivers/remoteproc/imx_rproc.c | 93 ++
 1 file changed, 93 insertions(+)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 3915c7f5ac47..f7ca7e7954ee 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -241,10 +242,102 @@ static void *imx_rproc_da_to_va(struct rproc *rproc, u64 
da, size_t len, bool *i
return va;
 }
 
+static int imx_rproc_mem_alloc(struct rproc *rproc,
+  struct rproc_mem_entry *mem)
+{
+   struct device *dev = rproc->dev.parent;
+   void *va;
+
+   dev_dbg(dev, "map memory: %p+%zx\n", >dma, mem->len);
+   va = ioremap_wc(mem->dma, mem->len);
+   if (IS_ERR_OR_NULL(va)) {
+   dev_err(dev, "Unable to map memory region: %p+%zx\n",
+   >dma, mem->len);
+   return -ENOMEM;
+   }
+
+   /* Update memory entry va */
+   mem->va = va;
+
+   return 0;
+}
+
+static int imx_rproc_mem_release(struct rproc *rproc,
+struct rproc_mem_entry *mem)
+{
+   dev_dbg(rproc->dev.parent, "unmap memory: %pa\n", >dma);
+   iounmap(mem->va);
+
+   return 0;
+}
+
+static int imx_rproc_parse_memory_regions(struct rproc *rproc)
+{
+   struct imx_rproc *priv = rproc->priv;
+   struct device_node *np = priv->dev->of_node;
+   struct of_phandle_iterator it;
+   struct rproc_mem_entry *mem;
+   struct reserved_mem *rmem;
+   u32 da;
+
+   /* Register associated reserved memory regions */
+   of_phandle_iterator_init(, np, "memory-region", NULL, 0);
+   while (of_phandle_iterator_next() == 0) {
+   /*
+* Ignore the first memory region which will be used vdev 
buffer.
+* No need to do extra handlings, rproc_add_virtio_dev will 
handle it.
+*/
+   if (!strcmp(it.node->name, "vdevbuffer"))
+   continue;
+
+   rmem = of_reserved_mem_lookup(it.node);
+   if (!rmem) {
+   dev_err(priv->dev, "unable to acquire memory-region\n");
+   return -EINVAL;
+   }
+
+   /* No need to translate pa to da, i.MX use same map */
+   da = rmem->base;
+
+   /* Register memory region */
+   mem = rproc_mem_entry_init(priv->dev, NULL, 
(dma_addr_t)rmem->base, rmem->size, da,
+  imx_rproc_mem_alloc, 
imx_rproc_mem_release,
+  it.node->name);
+
+   if (mem)
+   rproc_coredump_add_segment(rproc, da, rmem->size);
+   else
+   return -ENOMEM;
+
+   rproc_add_carveout(rproc, mem);
+   }
+
+   return  0;
+}
+
+static int imx_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
+{
+   int ret = imx_rproc_parse_memory_regions(rproc);
+
+   if (ret)
+   return ret;
+
+   ret = rproc_elf_load_rsc_table(rproc, fw);
+   if (ret)
+   dev_info(>dev, "No resource table in elf\n");
+
+   return 0;
+}
+
 static const struct rproc_ops imx_rproc_ops = {
.start  = imx_rproc_start,
.stop   = imx_rproc_stop,
.da_to_va   = imx_rproc_da_to_va,
+   .load   = rproc_elf_load_segments,
+   .parse_fw   = imx_rproc_parse_fw,
+   .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table,
+   .sanity_check   = rproc_elf_sanity_check,
+   .get_boot_addr  = rproc_elf_get_boot_addr,
 };
 
 static int imx_rproc_addr_init(struct imx_rproc *priv,
-- 
2.28.0



[PATCH 2/8] remoteproc: add is_iomem to da_to_va

2020-12-21 Thread Peng Fan (OSS)
From: Peng Fan 

Introduce an extra parameter is_iomem to da_to_va, then the caller
could take the memory as normal memory or io mapped memory.

Signed-off-by: Peng Fan 
---

V4:
 New patch

 drivers/remoteproc/imx_rproc.c |  2 +-
 drivers/remoteproc/ingenic_rproc.c |  2 +-
 drivers/remoteproc/keystone_remoteproc.c   |  2 +-
 drivers/remoteproc/mtk_scp.c   |  6 +++---
 drivers/remoteproc/omap_remoteproc.c   |  2 +-
 drivers/remoteproc/pru_rproc.c |  2 +-
 drivers/remoteproc/qcom_q6v5_adsp.c|  2 +-
 drivers/remoteproc/qcom_q6v5_pas.c |  2 +-
 drivers/remoteproc/qcom_q6v5_wcss.c|  2 +-
 drivers/remoteproc/qcom_wcnss.c|  2 +-
 drivers/remoteproc/remoteproc_core.c   |  7 +--
 drivers/remoteproc/remoteproc_coredump.c   |  8 ++--
 drivers/remoteproc/remoteproc_debugfs.c|  2 +-
 drivers/remoteproc/remoteproc_elf_loader.c | 21 +++--
 drivers/remoteproc/remoteproc_internal.h   |  2 +-
 drivers/remoteproc/st_slim_rproc.c |  2 +-
 drivers/remoteproc/ti_k3_dsp_remoteproc.c  |  2 +-
 drivers/remoteproc/ti_k3_r5_remoteproc.c   |  2 +-
 drivers/remoteproc/wkup_m3_rproc.c |  2 +-
 include/linux/remoteproc.h |  2 +-
 20 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 8957ed271d20..6603e00bb6f4 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -208,7 +208,7 @@ static int imx_rproc_da_to_sys(struct imx_rproc *priv, u64 
da,
return -ENOENT;
 }
 
-static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool 
*is_iomem)
 {
struct imx_rproc *priv = rproc->priv;
void *va = NULL;
diff --git a/drivers/remoteproc/ingenic_rproc.c 
b/drivers/remoteproc/ingenic_rproc.c
index 26e19e6143b7..bb5049295576 100644
--- a/drivers/remoteproc/ingenic_rproc.c
+++ b/drivers/remoteproc/ingenic_rproc.c
@@ -116,7 +116,7 @@ static void ingenic_rproc_kick(struct rproc *rproc, int 
vqid)
writel(vqid, vpu->aux_base + REG_CORE_MSG);
 }
 
-static void *ingenic_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *ingenic_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, 
bool *is_iomem)
 {
struct vpu *vpu = rproc->priv;
void __iomem *va = NULL;
diff --git a/drivers/remoteproc/keystone_remoteproc.c 
b/drivers/remoteproc/keystone_remoteproc.c
index cd266163a65f..54781f553f4e 100644
--- a/drivers/remoteproc/keystone_remoteproc.c
+++ b/drivers/remoteproc/keystone_remoteproc.c
@@ -246,7 +246,7 @@ static void keystone_rproc_kick(struct rproc *rproc, int 
vqid)
  * can be used either by the remoteproc core for loading (when using kernel
  * remoteproc loader), or by any rpmsg bus drivers.
  */
-static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, 
bool *is_iomem)
 {
struct keystone_rproc *ksproc = rproc->priv;
void __iomem *va = NULL;
diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c
index e0c235690361..535175f013e4 100644
--- a/drivers/remoteproc/mtk_scp.c
+++ b/drivers/remoteproc/mtk_scp.c
@@ -270,7 +270,7 @@ static int scp_elf_load_segments(struct rproc *rproc, const 
struct firmware *fw)
}
 
/* grab the kernel address for this device address */
-   ptr = (void __iomem *)rproc_da_to_va(rproc, da, memsz);
+   ptr = (void __iomem *)rproc_da_to_va(rproc, da, memsz, NULL);
if (!ptr) {
dev_err(dev, "bad phdr da 0x%x mem 0x%x\n", da, memsz);
ret = -EINVAL;
@@ -458,7 +458,7 @@ static int scp_start(struct rproc *rproc)
return ret;
 }
 
-static void *scp_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *scp_da_to_va(struct rproc *rproc, u64 da, size_t len, bool 
*is_iomem)
 {
struct mtk_scp *scp = (struct mtk_scp *)rproc->priv;
int offset;
@@ -587,7 +587,7 @@ void *scp_mapping_dm_addr(struct mtk_scp *scp, u32 mem_addr)
 {
void *ptr;
 
-   ptr = scp_da_to_va(scp->rproc, mem_addr, 0);
+   ptr = scp_da_to_va(scp->rproc, mem_addr, 0, NULL);
if (!ptr)
return ERR_PTR(-EINVAL);
 
diff --git a/drivers/remoteproc/omap_remoteproc.c 
b/drivers/remoteproc/omap_remoteproc.c
index d94b7391bf9d..43531caa1959 100644
--- a/drivers/remoteproc/omap_remoteproc.c
+++ b/drivers/remoteproc/omap_remoteproc.c
@@ -728,7 +728,7 @@ static int omap_rproc_stop(struct rproc *rproc)
  * Return: translated virtual address in kernel memory space on success,
  * or NULL on failure.
  */
-static void *omap_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len)
+static void *omap_rproc_da_to_va(struct rproc *

<    1   2   3   4   5   6   7   8   9   10   >