sparclinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* use the generic DMA remap allocator for sparc32
@ 2021-09-20 11:31 Christoph Hellwig
  2021-09-20 11:31 ` [PATCH 1/2] sparc32: remove dma_make_coherent Christoph Hellwig
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Christoph Hellwig @ 2021-09-20 11:31 UTC (permalink / raw)
  To: David S. Miller; +Cc: Andreas Larsson, sparclinux

Hi Dave,

this series switches sparc32 to use the generic dma remap allocator
instead of its own version.

Diffstat:
 Kconfig         |    3 +-
 kernel/ioport.c |   76 +++++---------------------------------------------------
 2 files changed, 10 insertions(+), 69 deletions(-)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/2] sparc32: remove dma_make_coherent
  2021-09-20 11:31 use the generic DMA remap allocator for sparc32 Christoph Hellwig
@ 2021-09-20 11:31 ` Christoph Hellwig
       [not found]   ` <YUixtMGPMLWvv8S9@ravnborg.org>
  2021-09-20 11:31 ` [PATCH 2/2] sparc32: use DMA_DIRECT_REMAP Christoph Hellwig
  2021-09-20 11:34 ` use the generic DMA remap allocator for sparc32 David Miller
  2 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2021-09-20 11:31 UTC (permalink / raw)
  To: David S. Miller; +Cc: Andreas Larsson, sparclinux

LEON only needs snooping when DMA accesses are not seen on the processor
bus.  Given that coherent allocations are mapped uncached this can't
happen for those, so open code the d-cache flushing logic in the only
remaing place that needs it, arch_sync_dma_for_cpu.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/sparc/kernel/ioport.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/arch/sparc/kernel/ioport.c b/arch/sparc/kernel/ioport.c
index 7ceae24b0ca99..3eb748e862220 100644
--- a/arch/sparc/kernel/ioport.c
+++ b/arch/sparc/kernel/ioport.c
@@ -52,17 +52,6 @@
 #include <asm/io-unit.h>
 #include <asm/leon.h>
 
-/* This function must make sure that caches and memory are coherent after DMA
- * On LEON systems without cache snooping it flushes the entire D-CACHE.
- */
-static inline void dma_make_coherent(unsigned long pa, unsigned long len)
-{
-	if (sparc_cpu_model == sparc_leon) {
-		if (!sparc_leon3_snooping_enabled())
-			leon_flush_dcache_all();
-	}
-}
-
 static void __iomem *_sparc_ioremap(struct resource *res, u32 bus, u32 pa, int sz);
 static void __iomem *_sparc_alloc_io(unsigned int busno, unsigned long phys,
     unsigned long size, char *name);
@@ -361,18 +350,23 @@ void arch_dma_free(struct device *dev, size_t size, void *cpu_addr,
 	if (!sparc_dma_free_resource(cpu_addr, size))
 		return;
 
-	dma_make_coherent(dma_addr, size);
 	srmmu_unmapiorange((unsigned long)cpu_addr, size);
 	free_pages((unsigned long)phys_to_virt(dma_addr), get_order(size));
 }
 
-/* IIep is write-through, not flushing on cpu to device transfer. */
-
+/*
+ * IIep is write-through, not flushing on cpu to device transfer.
+ *
+ * On LEON systems without cache snooping, the entire D-CACHE must be flushed to
+ * make DMA to cacheable memory coherent.
+ */
 void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size,
 		enum dma_data_direction dir)
 {
-	if (dir != PCI_DMA_TODEVICE)
-		dma_make_coherent(paddr, PAGE_ALIGN(size));
+	if (dir != PCI_DMA_TODEVICE &&
+	    sparc_cpu_model == sparc_leon &&
+	    !sparc_leon3_snooping_enabled())
+		leon_flush_dcache_all();
 }
 
 #ifdef CONFIG_PROC_FS
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] sparc32: use DMA_DIRECT_REMAP
  2021-09-20 11:31 use the generic DMA remap allocator for sparc32 Christoph Hellwig
  2021-09-20 11:31 ` [PATCH 1/2] sparc32: remove dma_make_coherent Christoph Hellwig
@ 2021-09-20 11:31 ` Christoph Hellwig
  2021-09-20 11:34 ` use the generic DMA remap allocator for sparc32 David Miller
  2 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2021-09-20 11:31 UTC (permalink / raw)
  To: David S. Miller; +Cc: Andreas Larsson, sparclinux

Use the generic dma remapping allocator instead of open coding it.
This also avoids setting up page tables from irq context which is
generally dangerous and uses the atomic pool instead.

Note that this changes the kernel virtual address at which the
dma coherent memory is mapped from the DVMA_VADDR region to the general
vmalloc pool.  I could not find any indication that this matters
for the hardware.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/sparc/Kconfig         |  3 ++-
 arch/sparc/kernel/ioport.c | 54 --------------------------------------
 2 files changed, 2 insertions(+), 55 deletions(-)

diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index b120ed947f50b..66fc08646be5e 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -53,8 +53,9 @@ config SPARC32
 	def_bool !64BIT
 	select ARCH_32BIT_OFF_T
 	select ARCH_HAS_SYNC_DMA_FOR_CPU
-	select GENERIC_ATOMIC64
 	select CLZ_TAB
+	select DMA_DIRECT_REMAP
+	select GENERIC_ATOMIC64
 	select HAVE_UID16
 	select OLD_SIGACTION
 	select ZONE_DMA
diff --git a/arch/sparc/kernel/ioport.c b/arch/sparc/kernel/ioport.c
index 3eb748e862220..57a72c46eddb0 100644
--- a/arch/sparc/kernel/ioport.c
+++ b/arch/sparc/kernel/ioport.c
@@ -300,60 +300,6 @@ arch_initcall(sparc_register_ioport);
 
 #endif /* CONFIG_SBUS */
 
-
-/* Allocate and map kernel buffer using consistent mode DMA for a device.
- * hwdev should be valid struct pci_dev pointer for PCI devices.
- */
-void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
-		gfp_t gfp, unsigned long attrs)
-{
-	unsigned long addr;
-	void *va;
-
-	if (!size || size > 256 * 1024)	/* __get_free_pages() limit */
-		return NULL;
-
-	size = PAGE_ALIGN(size);
-	va = (void *) __get_free_pages(gfp | __GFP_ZERO, get_order(size));
-	if (!va) {
-		printk("%s: no %zd pages\n", __func__, size >> PAGE_SHIFT);
-		return NULL;
-	}
-
-	addr = sparc_dma_alloc_resource(dev, size);
-	if (!addr)
-		goto err_nomem;
-
-	srmmu_mapiorange(0, virt_to_phys(va), addr, size);
-
-	*dma_handle = virt_to_phys(va);
-	return (void *)addr;
-
-err_nomem:
-	free_pages((unsigned long)va, get_order(size));
-	return NULL;
-}
-
-/* Free and unmap a consistent DMA buffer.
- * cpu_addr is what was returned arch_dma_alloc, size must be the same as what
- * was passed into arch_dma_alloc, and likewise dma_addr must be the same as
- * what *dma_ndler was set to.
- *
- * References to the memory and mappings associated with cpu_addr/dma_addr
- * past this call are illegal.
- */
-void arch_dma_free(struct device *dev, size_t size, void *cpu_addr,
-		dma_addr_t dma_addr, unsigned long attrs)
-{
-	size = PAGE_ALIGN(size);
-
-	if (!sparc_dma_free_resource(cpu_addr, size))
-		return;
-
-	srmmu_unmapiorange((unsigned long)cpu_addr, size);
-	free_pages((unsigned long)phys_to_virt(dma_addr), get_order(size));
-}
-
 /*
  * IIep is write-through, not flushing on cpu to device transfer.
  *
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: use the generic DMA remap allocator for sparc32
  2021-09-20 11:31 use the generic DMA remap allocator for sparc32 Christoph Hellwig
  2021-09-20 11:31 ` [PATCH 1/2] sparc32: remove dma_make_coherent Christoph Hellwig
  2021-09-20 11:31 ` [PATCH 2/2] sparc32: use DMA_DIRECT_REMAP Christoph Hellwig
@ 2021-09-20 11:34 ` David Miller
  2021-09-21  7:36   ` Christoph Hellwig
  2 siblings, 1 reply; 8+ messages in thread
From: David Miller @ 2021-09-20 11:34 UTC (permalink / raw)
  To: hch; +Cc: andreas, sparclinux

From: Christoph Hellwig <hch@lst.de>
Date: Mon, 20 Sep 2021 13:31:06 +0200

> Hi Dave,
> 
> this series switches sparc32 to use the generic dma remap allocator
> instead of its own version.

For series:

Acked-by: David S. Miller <davem@davemloft.net>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: use the generic DMA remap allocator for sparc32
  2021-09-20 11:34 ` use the generic DMA remap allocator for sparc32 David Miller
@ 2021-09-21  7:36   ` Christoph Hellwig
  0 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2021-09-21  7:36 UTC (permalink / raw)
  To: David Miller; +Cc: hch, andreas, sparclinux

On Mon, Sep 20, 2021 at 12:34:32PM +0100, David Miller wrote:
> From: Christoph Hellwig <hch@lst.de>
> Date: Mon, 20 Sep 2021 13:31:06 +0200
> 
> > Hi Dave,
> > 
> > this series switches sparc32 to use the generic dma remap allocator
> > instead of its own version.
> 
> For series:
> 
> Acked-by: David S. Miller <davem@davemloft.net>

Does this mean you'd prefer them to go through the dma-mapping tree
and not the sparc tree?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] sparc32: remove dma_make_coherent
       [not found]   ` <YUixtMGPMLWvv8S9@ravnborg.org>
@ 2021-09-21  7:41     ` Christoph Hellwig
  2021-09-21 11:32       ` Andreas Larsson
  2021-10-21 11:09     ` Christoph Hellwig
  1 sibling, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2021-09-21  7:41 UTC (permalink / raw)
  To: Sam Ravnborg
  Cc: Christoph Hellwig, David S. Miller, Andreas Larsson, sparclinux

On Mon, Sep 20, 2021 at 06:07:16PM +0200, Sam Ravnborg wrote:
> On Mon, Sep 20, 2021 at 01:31:07PM +0200, Christoph Hellwig wrote:
> > LEON only needs snooping when DMA accesses are not seen on the processor
> > bus.  Given that coherent allocations are mapped uncached this can't
> > happen for those, so open code the d-cache flushing logic in the only
> > remaing place that needs it, arch_sync_dma_for_cpu.

> I do not see this change explicitly explained in the changelog.
> Is this not one of the "only remaining place that needs it"?

Yes.  Two callers, one needs it, one doesn't.

> Would be nice to see it explicitly mentioned.

Ok.  I'll respin with a more detailed commit log.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] sparc32: remove dma_make_coherent
  2021-09-21  7:41     ` Christoph Hellwig
@ 2021-09-21 11:32       ` Andreas Larsson
  0 siblings, 0 replies; 8+ messages in thread
From: Andreas Larsson @ 2021-09-21 11:32 UTC (permalink / raw)
  To: Christoph Hellwig, Sam Ravnborg; +Cc: David S. Miller, sparclinux

On 2021-09-21 09:41, Christoph Hellwig wrote:
> Ok.  I'll respin with a more detailed commit log.

These two patches works fine for me, so you can add a

Tested-by: Andreas Larsson <andreas@gaisler.com>

as well.

-- 
Andreas Larsson


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] sparc32: remove dma_make_coherent
       [not found]   ` <YUixtMGPMLWvv8S9@ravnborg.org>
  2021-09-21  7:41     ` Christoph Hellwig
@ 2021-10-21 11:09     ` Christoph Hellwig
  1 sibling, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2021-10-21 11:09 UTC (permalink / raw)
  To: Sam Ravnborg
  Cc: Christoph Hellwig, David S. Miller, Andreas Larsson, sparclinux

I've now commited this series to the dma-mapping tree, with the first
patch split into two so that is more obvious:

http://git.infradead.org/users/hch/dma-mapping.git/shortlog/refs/heads/for-next

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-10-21 11:09 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-20 11:31 use the generic DMA remap allocator for sparc32 Christoph Hellwig
2021-09-20 11:31 ` [PATCH 1/2] sparc32: remove dma_make_coherent Christoph Hellwig
     [not found]   ` <YUixtMGPMLWvv8S9@ravnborg.org>
2021-09-21  7:41     ` Christoph Hellwig
2021-09-21 11:32       ` Andreas Larsson
2021-10-21 11:09     ` Christoph Hellwig
2021-09-20 11:31 ` [PATCH 2/2] sparc32: use DMA_DIRECT_REMAP Christoph Hellwig
2021-09-20 11:34 ` use the generic DMA remap allocator for sparc32 David Miller
2021-09-21  7:36   ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).