Skip to contentSkip to conversation

use the generic DMA remap allocator for sparc32

PATCH In review Christoph Hellwig 3 participants 8 messages Sep 20, 2021 – Oct 21, 2021 1 message not in the archive SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore
#0 lore raw

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(-)
#1 lore raw

PATCH 1/2 sparc32: remove dma_make_coherent

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.

---
 arch/sparc/kernel/ioport.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)
arch/sparc/kernel/ioport.c +10 -16
index 7ceae24b0ca99..3eb748e862220 100644
@@ -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
Signature · 1 line
2.30.2

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

Re: [PATCH 1/2] sparc32: remove dma_make_coherent

Quoted 8 lines · Sam Ravnborg
Quoted 4 lines · Christoph Hellwig

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.

Quoted 1 line

Would be nice to see it explicitly mentioned.

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

maintainer Tested-by
#4 lore raw

Re: [PATCH 1/2] sparc32: remove dma_make_coherent

Quoted 1 line · Christoph Hellwig

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

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

as well.

Signature · 1 line
Andreas Larsson
#6 lore raw

PATCH 2/2 sparc32: use DMA_DIRECT_REMAP

In reply to Christoph Hellwig

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.

---
 arch/sparc/Kconfig         |  3 ++-
 arch/sparc/kernel/ioport.c | 54 --------------------------------------
 2 files changed, 2 insertions(+), 55 deletions(-)
arch/sparc/Kconfig +2 -1
index b120ed947f50b..66fc08646be5e 100644
@@ -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
arch/sparc/kernel/ioport.c +0 -54

60 lines not on this page · raw message

Signature · 1 line
2.30.2
#8 lore raw
Quoted 11 lines · David Miller

From: Christoph Hellwig <[email protected]>
Date: Mon, 20 Sep 2021 13:31:06 +0200

Quoted 4 lines

Hi Dave,

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

For series:

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