Skip to content

Commit 3725949

Browse files
committed
Merge tag 'dma-mapping-5.16' of git://git.infradead.org/users/hch/dma-mapping
Pull dma-mapping updates from Christoph Hellwig: "Just a small set of changes this time. The request dma_direct_alloc cleanups are still under review and haven't made the cut. Summary: - convert sparc32 to the generic dma-direct code - use bitmap_zalloc (Christophe JAILLET)" * tag 'dma-mapping-5.16' of git://git.infradead.org/users/hch/dma-mapping: dma-mapping: use 'bitmap_zalloc()' when applicable sparc32: use DMA_DIRECT_REMAP sparc32: remove dma_make_coherent sparc32: remove the call to dma_make_coherent in arch_dma_free
2 parents 1bdd629 + 9fbd8dc commit 3725949

File tree

3 files changed

+12
-72
lines changed

3 files changed

+12
-72
lines changed

arch/sparc/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ config SPARC32
5353
def_bool !64BIT
5454
select ARCH_32BIT_OFF_T
5555
select ARCH_HAS_SYNC_DMA_FOR_CPU
56-
select GENERIC_ATOMIC64
5756
select CLZ_TAB
57+
select DMA_DIRECT_REMAP
58+
select GENERIC_ATOMIC64
5859
select HAVE_UID16
5960
select OLD_SIGACTION
6061
select ZONE_DMA

arch/sparc/kernel/ioport.c

Lines changed: 8 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,6 @@
5252
#include <asm/io-unit.h>
5353
#include <asm/leon.h>
5454

55-
/* This function must make sure that caches and memory are coherent after DMA
56-
* On LEON systems without cache snooping it flushes the entire D-CACHE.
57-
*/
58-
static inline void dma_make_coherent(unsigned long pa, unsigned long len)
59-
{
60-
if (sparc_cpu_model == sparc_leon) {
61-
if (!sparc_leon3_snooping_enabled())
62-
leon_flush_dcache_all();
63-
}
64-
}
65-
6655
static void __iomem *_sparc_ioremap(struct resource *res, u32 bus, u32 pa, int sz);
6756
static void __iomem *_sparc_alloc_io(unsigned int busno, unsigned long phys,
6857
unsigned long size, char *name);
@@ -311,68 +300,19 @@ arch_initcall(sparc_register_ioport);
311300

312301
#endif /* CONFIG_SBUS */
313302

314-
315-
/* Allocate and map kernel buffer using consistent mode DMA for a device.
316-
* hwdev should be valid struct pci_dev pointer for PCI devices.
317-
*/
318-
void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
319-
gfp_t gfp, unsigned long attrs)
320-
{
321-
unsigned long addr;
322-
void *va;
323-
324-
if (!size || size > 256 * 1024) /* __get_free_pages() limit */
325-
return NULL;
326-
327-
size = PAGE_ALIGN(size);
328-
va = (void *) __get_free_pages(gfp | __GFP_ZERO, get_order(size));
329-
if (!va) {
330-
printk("%s: no %zd pages\n", __func__, size >> PAGE_SHIFT);
331-
return NULL;
332-
}
333-
334-
addr = sparc_dma_alloc_resource(dev, size);
335-
if (!addr)
336-
goto err_nomem;
337-
338-
srmmu_mapiorange(0, virt_to_phys(va), addr, size);
339-
340-
*dma_handle = virt_to_phys(va);
341-
return (void *)addr;
342-
343-
err_nomem:
344-
free_pages((unsigned long)va, get_order(size));
345-
return NULL;
346-
}
347-
348-
/* Free and unmap a consistent DMA buffer.
349-
* cpu_addr is what was returned arch_dma_alloc, size must be the same as what
350-
* was passed into arch_dma_alloc, and likewise dma_addr must be the same as
351-
* what *dma_ndler was set to.
303+
/*
304+
* IIep is write-through, not flushing on cpu to device transfer.
352305
*
353-
* References to the memory and mappings associated with cpu_addr/dma_addr
354-
* past this call are illegal.
306+
* On LEON systems without cache snooping, the entire D-CACHE must be flushed to
307+
* make DMA to cacheable memory coherent.
355308
*/
356-
void arch_dma_free(struct device *dev, size_t size, void *cpu_addr,
357-
dma_addr_t dma_addr, unsigned long attrs)
358-
{
359-
size = PAGE_ALIGN(size);
360-
361-
if (!sparc_dma_free_resource(cpu_addr, size))
362-
return;
363-
364-
dma_make_coherent(dma_addr, size);
365-
srmmu_unmapiorange((unsigned long)cpu_addr, size);
366-
free_pages((unsigned long)phys_to_virt(dma_addr), get_order(size));
367-
}
368-
369-
/* IIep is write-through, not flushing on cpu to device transfer. */
370-
371309
void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size,
372310
enum dma_data_direction dir)
373311
{
374-
if (dir != PCI_DMA_TODEVICE)
375-
dma_make_coherent(paddr, PAGE_ALIGN(size));
312+
if (dir != PCI_DMA_TODEVICE &&
313+
sparc_cpu_model == sparc_leon &&
314+
!sparc_leon3_snooping_enabled())
315+
leon_flush_dcache_all();
376316
}
377317

378318
#ifdef CONFIG_PROC_FS

kernel/dma/coherent.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ static struct dma_coherent_mem *dma_init_coherent_memory(phys_addr_t phys_addr,
4040
{
4141
struct dma_coherent_mem *dma_mem;
4242
int pages = size >> PAGE_SHIFT;
43-
int bitmap_size = BITS_TO_LONGS(pages) * sizeof(long);
4443
void *mem_base;
4544

4645
if (!size)
@@ -53,7 +52,7 @@ static struct dma_coherent_mem *dma_init_coherent_memory(phys_addr_t phys_addr,
5352
dma_mem = kzalloc(sizeof(struct dma_coherent_mem), GFP_KERNEL);
5453
if (!dma_mem)
5554
goto out_unmap_membase;
56-
dma_mem->bitmap = kzalloc(bitmap_size, GFP_KERNEL);
55+
dma_mem->bitmap = bitmap_zalloc(pages, GFP_KERNEL);
5756
if (!dma_mem->bitmap)
5857
goto out_free_dma_mem;
5958

@@ -81,7 +80,7 @@ static void dma_release_coherent_memory(struct dma_coherent_mem *mem)
8180
return;
8281

8382
memunmap(mem->virt_base);
84-
kfree(mem->bitmap);
83+
bitmap_free(mem->bitmap);
8584
kfree(mem);
8685
}
8786

0 commit comments

Comments
 (0)