m68k: Use the generic dma coherent remap allocator

This switches m68k to using common code for the DMA allocations,
including potential use of the CMA allocator if configured.
Also add a comment where the existing behavior seems to be lacking.

Switching to the generic code enables DMA allocations from atomic
context, which is required by the DMA API documentation, and also
adds various other minor features drivers start relying upon.  It
also makes sure we have a tested code base for all architectures
that require uncached pte bits for coherent DMA allocations.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
This commit is contained in:
Christoph Hellwig 2019-06-25 11:01:34 +02:00 committed by Geert Uytterhoeven
parent f67d667213
commit 34dc63a5fb
2 changed files with 10 additions and 48 deletions

View File

@ -3,10 +3,12 @@ config M68K
bool bool
default y default y
select ARCH_32BIT_OFF_T select ARCH_32BIT_OFF_T
select ARCH_HAS_DMA_MMAP_PGPROT if MMU && !COLDFIRE
select ARCH_HAS_SYNC_DMA_FOR_DEVICE if HAS_DMA select ARCH_HAS_SYNC_DMA_FOR_DEVICE if HAS_DMA
select ARCH_MIGHT_HAVE_PC_PARPORT if ISA select ARCH_MIGHT_HAVE_PC_PARPORT if ISA
select ARCH_NO_COHERENT_DMA_MMAP if !MMU select ARCH_NO_COHERENT_DMA_MMAP if !MMU
select ARCH_NO_PREEMPT if !COLDFIRE select ARCH_NO_PREEMPT if !COLDFIRE
select DMA_DIRECT_REMAP if HAS_DMA && MMU && !COLDFIRE
select HAVE_IDE select HAVE_IDE
select HAVE_AOUT if MMU select HAVE_AOUT if MMU
select HAVE_DEBUG_BUGVERBOSE select HAVE_DEBUG_BUGVERBOSE

View File

@ -18,57 +18,17 @@
#include <asm/pgalloc.h> #include <asm/pgalloc.h>
#if defined(CONFIG_MMU) && !defined(CONFIG_COLDFIRE) #if defined(CONFIG_MMU) && !defined(CONFIG_COLDFIRE)
pgprot_t arch_dma_mmap_pgprot(struct device *dev, pgprot_t prot,
void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, unsigned long attrs)
gfp_t flag, unsigned long attrs)
{ {
struct page *page, **map; if (CPU_IS_040_OR_060) {
pgprot_t pgprot; pgprot_val(prot) &= ~_PAGE_CACHE040;
void *addr; pgprot_val(prot) |= _PAGE_GLOBAL040 | _PAGE_NOCACHE_S;
int i, order; } else {
pgprot_val(prot) |= _PAGE_NOCACHE030;
pr_debug("dma_alloc_coherent: %d,%x\n", size, flag);
size = PAGE_ALIGN(size);
order = get_order(size);
page = alloc_pages(flag | __GFP_ZERO, order);
if (!page)
return NULL;
*handle = page_to_phys(page);
map = kmalloc(sizeof(struct page *) << order, flag & ~__GFP_DMA);
if (!map) {
__free_pages(page, order);
return NULL;
} }
split_page(page, order); return prot;
order = 1 << order;
size >>= PAGE_SHIFT;
map[0] = page;
for (i = 1; i < size; i++)
map[i] = page + i;
for (; i < order; i++)
__free_page(page + i);
pgprot = __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_DIRTY);
if (CPU_IS_040_OR_060)
pgprot_val(pgprot) |= _PAGE_GLOBAL040 | _PAGE_NOCACHE_S;
else
pgprot_val(pgprot) |= _PAGE_NOCACHE030;
addr = vmap(map, size, VM_MAP, pgprot);
kfree(map);
return addr;
} }
void arch_dma_free(struct device *dev, size_t size, void *addr,
dma_addr_t handle, unsigned long attrs)
{
pr_debug("dma_free_coherent: %p, %x\n", addr, handle);
vfree(addr);
}
#else #else
#include <asm/cacheflush.h> #include <asm/cacheflush.h>