diff mbox series

[5.10.y-cip,14/48] dma-mapping: simplify dma_init_coherent_memory

Message ID 20240205124135.14779-15-prabhakar.mahadev-lad.rj@bp.renesas.com (mailing list archive)
State New
Headers show
Series Add support for Renesas RZ/Five RISC-V SoC | expand

Commit Message

Lad Prabhakar Feb. 5, 2024, 12:41 p.m. UTC
From: Christoph Hellwig <hch@lst.de>

commit a6933571f34a9aee843fff2aa4b96949c57d6274 upstream.

Return the allocated dma_coherent_mem structure, set the
use_dma_pfn_offset and print the failure warning inside of
dma_init_coherent_memory instead of leaving that to the callers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Tested-by: Dillon Min <dillon.minfei@gmail.com>
Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
---
 kernel/dma/coherent.c | 78 ++++++++++++++++++-------------------------
 1 file changed, 33 insertions(+), 45 deletions(-)

Comments

Nobuhiro Iwamatsu Feb. 6, 2024, 9:18 a.m. UTC | #1
Hi,

> -----Original Message-----
> From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> Sent: Monday, February 5, 2024 9:41 PM
> To: cip-dev@lists.cip-project.org; iwamatsu nobuhiro(岩松 信洋 ○DITC□
> DIT○OST) <nobuhiro1.iwamatsu@toshiba.co.jp>; Pavel Machek
> <pavel@denx.de>
> Cc: Biju Das <biju.das.jz@bp.renesas.com>
> Subject: [PATCH 5.10.y-cip 14/48] dma-mapping: simplify
> dma_init_coherent_memory
> 
> From: Christoph Hellwig <hch@lst.de>
> 
> commit a6933571f34a9aee843fff2aa4b96949c57d6274 upstream.
> 
> Return the allocated dma_coherent_mem structure, set the
> use_dma_pfn_offset and print the failure warning inside of
> dma_init_coherent_memory instead of leaving that to the callers.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> Tested-by: Dillon Min <dillon.minfei@gmail.com>
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> ---
>  kernel/dma/coherent.c | 78
> ++++++++++++++++++-------------------------
>  1 file changed, 33 insertions(+), 45 deletions(-)
> 

I can not apply this patch cip/Linux-5.10.y-cip.
Could you check this ?

$ git am -s patch.series
Applying: arm64: dts: renesas: rzg2ul-smarc: Move selecting PMOD_SCI0_EN to board DTS
Applying: arm64: dts: renesas: rzg2ul-smarc: Include SoM DTSI into board DTS
Applying: arm64: dts: renesas: r9a07g043: Introduce SOC_PERIPHERAL_IRQ() macro to specify interrupt property
Applying: arm64: dts: renesas: r9a07g043: Update IRQ numbers for SSI channels
Applying: arm64: dts: renesas: r9a07g043: Split out RZ/G2UL SoC specific parts
Applying: cacheinfo: clear cache_leaves(cpu) in free_cache_attributes()
Applying: riscv: Kconfig: Enable cpufreq kconfig menu
Applying: dma-direct: add support for dma_coherent_default_memory
Applying: dma-mapping: allow using the global coherent pool for !ARM
Applying: dma-mapping: simplify dma_init_coherent_memory
error: patch failed: kernel/dma/coherent.c:37
error: kernel/dma/coherent.c: patch does not apply
Patch failed at 0010 dma-mapping: simplify dma_init_coherent_memory
hint: Use 'git am --show-current-patch=diff' to see the failed patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

Best regards,
  Nobuhiro
Lad Prabhakar Feb. 6, 2024, 9:52 a.m. UTC | #2
Hi Nobuhiro, Pavel,

> -----Original Message-----
> From: nobuhiro1.iwamatsu@toshiba.co.jp <nobuhiro1.iwamatsu@toshiba.co.jp>
> Sent: Tuesday, February 6, 2024 9:19 AM
> To: Prabhakar Mahadev Lad <prabhakar.mahadev-lad.rj@bp.renesas.com>; cip-dev@lists.cip-project.org;
> pavel@denx.de
> Cc: Biju Das <biju.das.jz@bp.renesas.com>
> Subject: RE: [PATCH 5.10.y-cip 14/48] dma-mapping: simplify dma_init_coherent_memory
> 
> Hi,
> 
> > -----Original Message-----
> > From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> > Sent: Monday, February 5, 2024 9:41 PM
> > To: cip-dev@lists.cip-project.org; iwamatsu nobuhiro(岩松 信洋 ○DITC□
> > DIT○OST) <nobuhiro1.iwamatsu@toshiba.co.jp>; Pavel Machek
> > <pavel@denx.de>
> > Cc: Biju Das <biju.das.jz@bp.renesas.com>
> > Subject: [PATCH 5.10.y-cip 14/48] dma-mapping: simplify
> > dma_init_coherent_memory
> >
> > From: Christoph Hellwig <hch@lst.de>
> >
> > commit a6933571f34a9aee843fff2aa4b96949c57d6274 upstream.
> >
> > Return the allocated dma_coherent_mem structure, set the
> > use_dma_pfn_offset and print the failure warning inside of
> > dma_init_coherent_memory instead of leaving that to the callers.
> >
> > Signed-off-by: Christoph Hellwig <hch@lst.de>
> > Tested-by: Dillon Min <dillon.minfei@gmail.com>
> > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> > ---
> >  kernel/dma/coherent.c | 78
> > ++++++++++++++++++-------------------------
> >  1 file changed, 33 insertions(+), 45 deletions(-)
> >
> 
> I can not apply this patch cip/Linux-5.10.y-cip.
> Could you check this ?
> 
> $ git am -s patch.series
> Applying: arm64: dts: renesas: rzg2ul-smarc: Move selecting PMOD_SCI0_EN to board DTS
> Applying: arm64: dts: renesas: rzg2ul-smarc: Include SoM DTSI into board DTS
> Applying: arm64: dts: renesas: r9a07g043: Introduce SOC_PERIPHERAL_IRQ() macro to specify interrupt
> property
> Applying: arm64: dts: renesas: r9a07g043: Update IRQ numbers for SSI channels
> Applying: arm64: dts: renesas: r9a07g043: Split out RZ/G2UL SoC specific parts
> Applying: cacheinfo: clear cache_leaves(cpu) in free_cache_attributes()
> Applying: riscv: Kconfig: Enable cpufreq kconfig menu
> Applying: dma-direct: add support for dma_coherent_default_memory
> Applying: dma-mapping: allow using the global coherent pool for !ARM
> Applying: dma-mapping: simplify dma_init_coherent_memory
> error: patch failed: kernel/dma/coherent.c:37
> error: kernel/dma/coherent.c: patch does not apply Patch failed at 0010 dma-mapping: simplify
> dma_init_coherent_memory
> hint: Use 'git am --show-current-patch=diff' to see the failed patch When you have resolved this
> problem, run "git am --continue".
> If you prefer to skip this patch, run "git am --skip" instead.
> To restore the original branch and stop patching, run "git am --abort".
> 
My patch series was based on v5.10.208-cip43, I'll rebase and send the v2 soon after testing.

Cheers,
Prabhakar
Pavel Machek Feb. 6, 2024, 10:12 a.m. UTC | #3
Hi!

> > I can not apply this patch cip/Linux-5.10.y-cip.
> > Could you check this ?
> > 
> > $ git am -s patch.series
> > Applying: arm64: dts: renesas: rzg2ul-smarc: Move selecting PMOD_SCI0_EN to board DTS
> > Applying: arm64: dts: renesas: rzg2ul-smarc: Include SoM DTSI into board DTS
> > Applying: arm64: dts: renesas: r9a07g043: Introduce SOC_PERIPHERAL_IRQ() macro to specify interrupt
> > property
> > Applying: arm64: dts: renesas: r9a07g043: Update IRQ numbers for SSI channels
> > Applying: arm64: dts: renesas: r9a07g043: Split out RZ/G2UL SoC specific parts
> > Applying: cacheinfo: clear cache_leaves(cpu) in free_cache_attributes()
> > Applying: riscv: Kconfig: Enable cpufreq kconfig menu
> > Applying: dma-direct: add support for dma_coherent_default_memory
> > Applying: dma-mapping: allow using the global coherent pool for !ARM
> > Applying: dma-mapping: simplify dma_init_coherent_memory
> > error: patch failed: kernel/dma/coherent.c:37
> > error: kernel/dma/coherent.c: patch does not apply Patch failed at 0010 dma-mapping: simplify
> > dma_init_coherent_memory
> > hint: Use 'git am --show-current-patch=diff' to see the failed patch When you have resolved this
> > problem, run "git am --continue".
> > If you prefer to skip this patch, run "git am --skip" instead.
> > To restore the original branch and stop patching, run "git am --abort".
> > 
> My patch series was based on v5.10.208-cip43, I'll rebase and send the v2 soon after testing.

That's a bad coincidence. Hopefully we won't have too many conflicts
in that code in future, as it looks a bit tricky.

Best regards,
								Pavel
Lad Prabhakar Feb. 6, 2024, 11:42 a.m. UTC | #4
Hi Pavel,

> -----Original Message-----
> From: Pavel Machek <pavel@denx.de>
> Sent: Tuesday, February 6, 2024 10:13 AM
> To: Prabhakar Mahadev Lad <prabhakar.mahadev-lad.rj@bp.renesas.com>
> Cc: nobuhiro1.iwamatsu@toshiba.co.jp; cip-dev@lists.cip-project.org; pavel@denx.de; Biju Das
> <biju.das.jz@bp.renesas.com>
> Subject: Re: [PATCH 5.10.y-cip 14/48] dma-mapping: simplify dma_init_coherent_memory
> 
> Hi!
> 
> > > I can not apply this patch cip/Linux-5.10.y-cip.
> > > Could you check this ?
> > >
> > > $ git am -s patch.series
> > > Applying: arm64: dts: renesas: rzg2ul-smarc: Move selecting
> > > PMOD_SCI0_EN to board DTS
> > > Applying: arm64: dts: renesas: rzg2ul-smarc: Include SoM DTSI into
> > > board DTS
> > > Applying: arm64: dts: renesas: r9a07g043: Introduce
> > > SOC_PERIPHERAL_IRQ() macro to specify interrupt property
> > > Applying: arm64: dts: renesas: r9a07g043: Update IRQ numbers for SSI
> > > channels
> > > Applying: arm64: dts: renesas: r9a07g043: Split out RZ/G2UL SoC
> > > specific parts
> > > Applying: cacheinfo: clear cache_leaves(cpu) in
> > > free_cache_attributes()
> > > Applying: riscv: Kconfig: Enable cpufreq kconfig menu
> > > Applying: dma-direct: add support for dma_coherent_default_memory
> > > Applying: dma-mapping: allow using the global coherent pool for !ARM
> > > Applying: dma-mapping: simplify dma_init_coherent_memory
> > > error: patch failed: kernel/dma/coherent.c:37
> > > error: kernel/dma/coherent.c: patch does not apply Patch failed at
> > > 0010 dma-mapping: simplify dma_init_coherent_memory
> > > hint: Use 'git am --show-current-patch=diff' to see the failed patch
> > > When you have resolved this problem, run "git am --continue".
> > > If you prefer to skip this patch, run "git am --skip" instead.
> > > To restore the original branch and stop patching, run "git am --abort".
> > >
> > My patch series was based on v5.10.208-cip43, I'll rebase and send the v2 soon after testing.
> 
> That's a bad coincidence. Hopefully we won't have too many conflicts in that code in future, as it
> looks a bit tricky.
> 
Agreed. Ive rebased the patches and kicked off the tests all seems to be OK. Ill send a v2.

Cheers,
Prabhakar

> Best regards,
> 								Pavel
> --
> DENX Software Engineering GmbH,        Managing Director: Erika Unter
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
diff mbox series

Patch

diff --git a/kernel/dma/coherent.c b/kernel/dma/coherent.c
index d97edd70d353..9610ed291f29 100644
--- a/kernel/dma/coherent.c
+++ b/kernel/dma/coherent.c
@@ -37,51 +37,44 @@  static inline dma_addr_t dma_get_device_base(struct device *dev,
 	return mem->device_base;
 }
 
-static int dma_init_coherent_memory(phys_addr_t phys_addr,
-		dma_addr_t device_addr, size_t size,
-		struct dma_coherent_mem **mem)
+static struct dma_coherent_mem *dma_init_coherent_memory(phys_addr_t phys_addr,
+		dma_addr_t device_addr, size_t size, bool use_dma_pfn_offset)
 {
-	struct dma_coherent_mem *dma_mem = NULL;
-	void *mem_base = NULL;
+	struct dma_coherent_mem *dma_mem;
 	int pages = size >> PAGE_SHIFT;
 	int bitmap_size = BITS_TO_LONGS(pages) * sizeof(long);
-	int ret;
+	void *mem_base;
 
-	if (!size) {
-		ret = -EINVAL;
-		goto out;
-	}
+	if (!size)
+		return ERR_PTR(-EINVAL);
 
 	mem_base = memremap(phys_addr, size, MEMREMAP_WC);
-	if (!mem_base) {
-		ret = -EINVAL;
-		goto out;
-	}
+	if (!mem_base)
+		return ERR_PTR(-EINVAL);
+
 	dma_mem = kzalloc(sizeof(struct dma_coherent_mem), GFP_KERNEL);
-	if (!dma_mem) {
-		ret = -ENOMEM;
-		goto out;
-	}
+	if (!dma_mem)
+		goto out_unmap_membase;
 	dma_mem->bitmap = kzalloc(bitmap_size, GFP_KERNEL);
-	if (!dma_mem->bitmap) {
-		ret = -ENOMEM;
-		goto out;
-	}
+	if (!dma_mem->bitmap)
+		goto out_free_dma_mem;
 
 	dma_mem->virt_base = mem_base;
 	dma_mem->device_base = device_addr;
 	dma_mem->pfn_base = PFN_DOWN(phys_addr);
 	dma_mem->size = pages;
+	dma_mem->use_dev_dma_pfn_offset = use_dma_pfn_offset;
 	spin_lock_init(&dma_mem->spinlock);
 
-	*mem = dma_mem;
-	return 0;
+	return dma_mem;
 
-out:
+out_free_dma_mem:
 	kfree(dma_mem);
-	if (mem_base)
-		memunmap(mem_base);
-	return ret;
+out_unmap_membase:
+	memunmap(mem_base);
+	pr_err("Reserved memory: failed to init DMA memory pool at %pa, size %zd MiB\n",
+		&phys_addr, size / SZ_1M);
+	return ERR_PTR(-ENOMEM);
 }
 
 static void dma_release_coherent_memory(struct dma_coherent_mem *mem)
@@ -130,9 +123,9 @@  int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
 	struct dma_coherent_mem *mem;
 	int ret;
 
-	ret = dma_init_coherent_memory(phys_addr, device_addr, size, &mem);
-	if (ret)
-		return ret;
+	mem = dma_init_coherent_memory(phys_addr, device_addr, size, false);
+	if (IS_ERR(mem))
+		return PTR_ERR(mem);
 
 	ret = dma_assign_coherent_memory(dev, mem);
 	if (ret)
@@ -319,21 +312,16 @@  static struct reserved_mem *dma_reserved_default_memory __initdata;
 
 static int rmem_dma_device_init(struct reserved_mem *rmem, struct device *dev)
 {
-	struct dma_coherent_mem *mem = rmem->priv;
-	int ret;
-
-	if (!mem) {
-		ret = dma_init_coherent_memory(rmem->base, rmem->base,
-					       rmem->size, &mem);
-		if (ret) {
-			pr_err("Reserved memory: failed to init DMA memory pool at %pa, size %ld MiB\n",
-				&rmem->base, (unsigned long)rmem->size / SZ_1M);
-			return ret;
-		}
+	if (!rmem->priv) {
+		struct dma_coherent_mem *mem;
+
+		mem = dma_init_coherent_memory(rmem->base, rmem->base,
+					       rmem->size, true);
+		if (IS_ERR(mem))
+			return PTR_ERR(mem);
+		rmem->priv = mem;
 	}
-	mem->use_dev_dma_pfn_offset = true;
-	rmem->priv = mem;
-	dma_assign_coherent_memory(dev, mem);
+	dma_assign_coherent_memory(dev, rmem->priv);
 	return 0;
 }