use the generic DMA direct remap code on powerpc
Hi powerpc maintainers,
this patch convers powerpc to use the generic dma remapping code for the uncached coherent allocation on non-coherent CPUs.
Christophe Leroy tested a slightly earlier version on ppc8xx.
Note that I plan to move the need for the arch to call dma_atomic_pool_init in this cycle, so either this needs to go in through the dma-mapping tree (or a shared stable branch with it), or we will need a small manual fixup in linux-next and when Linus merged the later of the two pull requests.
PATCH 1/1 powerpc: use the generic dma coherent remap allocator
This switches to using common code for the DMA allocations, including potential use of the CMA allocator if configured.
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 on tested code base for all architectures that require uncached pte bits for coherent DMA allocations.
Another advantage is that consistent memory allocations now share the general vmalloc pool instead of needing an explicit careout from it.
--- arch/powerpc/Kconfig | 12 - arch/powerpc/include/asm/book3s/32/pgtable.h | 12 +- arch/powerpc/include/asm/nohash/32/pgtable.h | 12 +- arch/powerpc/mm/dma-noncoherent.c | 318 +------------------ arch/powerpc/mm/mem.c | 4 - arch/powerpc/mm/ptdump/ptdump.c | 9 - arch/powerpc/platforms/Kconfig.cputype | 2 + 7 files changed, 17 insertions(+), 352 deletions(-)
arch/powerpc/Kconfig +0 -12
@@ -1139,18 +1139,6 @@ config TASK_SIZE default "0x80000000" if PPC_8xx default "0xc0000000" -config CONSISTENT_SIZE_BOOL - bool "Set custom consistent memory pool size" - depends on ADVANCED_OPTIONS && NOT_COHERENT_CACHE - help - This option allows you to set the size of the - consistent memory pool. This pool of virtual memory - is used to make consistent memory allocations. - -config CONSISTENT_SIZE - hex "Size of consistent memory pool" if CONSISTENT_SIZE_BOOL - default "0x00200000" if NOT_COHERENT_CACHE - config PIN_TLB bool "Pinned Kernel TLBs (860 ONLY)" depends on ADVANCED_OPTIONS && PPC_8xx && \
arch/powerpc/include/asm/book3s/32/pgtable.h +3 -9
@@ -148,21 +148,15 @@ int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot);*/ #include <asm/fixmap.h> -#ifdef CONFIG_HIGHMEM -#define KVIRT_TOP PKMAP_BASE -#else -#define KVIRT_TOP FIXADDR_START -#endif -/* * ioremap_bot starts at that address. Early ioremaps move down from there, * until mem_init() at which point this becomes the top of the vmalloc * and ioremap space */ -#ifdef CONFIG_NOT_COHERENT_CACHE -#define IOREMAP_TOP ((KVIRT_TOP - CONFIG_CONSISTENT_SIZE) & PAGE_MASK) +#ifdef CONFIG_HIGHMEM +#define IOREMAP_TOP PKMAP_BASE#else -#define IOREMAP_TOP KVIRT_TOP +#define IOREMAP_TOP FIXADDR_START#endif /*
arch/powerpc/include/asm/nohash/32/pgtable.h +3 -9
@@ -78,21 +78,15 @@ int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot);*/ #include <asm/fixmap.h> -#ifdef CONFIG_HIGHMEM -#define KVIRT_TOP PKMAP_BASE -#else -#define KVIRT_TOP FIXADDR_START -#endif -/* * ioremap_bot starts at that address. Early ioremaps move down from there, * until mem_init() at which point this becomes the top of the vmalloc * and ioremap space */ -#ifdef CONFIG_NOT_COHERENT_CACHE -#define IOREMAP_TOP ((KVIRT_TOP - CONFIG_CONSISTENT_SIZE) & PAGE_MASK) +#ifdef CONFIG_HIGHMEM +#define IOREMAP_TOP PKMAP_BASE#else -#define IOREMAP_TOP KVIRT_TOP +#define IOREMAP_TOP FIXADDR_START#endif /*
arch/powerpc/mm/dma-noncoherent.c +9 -309
342 lines not on this page · raw message
arch/powerpc/mm/mem.c +0 -4
@@ -302,10 +302,6 @@ void __init mem_init(void)pr_info (" * 0x%08lx..0x%08lx : highmem PTEs\n" ,PKMAP_BASE ,PKMAP_ADDR (LAST_PKMAP ));#endif /* CONFIG_HIGHMEM */ -#ifdef CONFIG_NOT_COHERENT_CACHE -pr_info (" * 0x%08lx..0x%08lx : consistent mem\n" , -IOREMAP_TOP ,IOREMAP_TOP +CONFIG_CONSISTENT_SIZE ); -#endif /* CONFIG_NOT_COHERENT_CACHE */ pr_info (" * 0x%08lx..0x%08lx : early ioremap\n" , ioremap_bot,IOREMAP_TOP ); pr_info(" * 0x%08lx..0x%08lx : vmalloc & ioremap\n",
arch/powerpc/mm/ptdump/ptdump.c +0 -9
@@ -88,10 +88,6 @@ static struct addr_marker address_markers[] = { #else { 0, "Early I/O remap start" }, { 0, "Early I/O remap end" }, -#ifdef CONFIG_NOT_COHERENT_CACHE - { 0, "Consistent mem start" }, - { 0, "Consistent mem end" }, -#endif #ifdef CONFIG_HIGHMEM { 0, "Highmem PTEs start" }, { 0, "Highmem PTEs end" },
@@ -341,11 +337,6 @@ static void populate_markers(void)#else /* !CONFIG_PPC64 */ address_markers[i++].start_address = ioremap_bot; address_markers[i++].start_address =IOREMAP_TOP ; -#ifdef CONFIG_NOT_COHERENT_CACHE - address_markers[i++].start_address =IOREMAP_TOP ; - address_markers[i++].start_address =IOREMAP_TOP + -CONFIG_CONSISTENT_SIZE ; -#endif #ifdef CONFIG_HIGHMEM address_markers[i++].start_address =PKMAP_BASE ; address_markers[i++].start_address =PKMAP_ADDR (LAST_PKMAP );
arch/powerpc/platforms/Kconfig.cputype +2 -0
@@ -450,8 +450,10 @@ config NOT_COHERENT_CACHE depends on 4xx || PPC_8xx || E200 || PPC_MPC512x || \ GAMECUBE_COMMON || AMIGAONE select ARCH_HAS_DMA_COHERENT_TO_PFN + select ARCH_HAS_DMA_PREP_COHERENT select ARCH_HAS_SYNC_DMA_FOR_DEVICE select ARCH_HAS_SYNC_DMA_FOR_CPU + select DMA_DIRECT_REMAP default n if PPC_47x default y
Signature · 1 line
2.20.1
Re: [PATCH] powerpc: use the generic dma coherent remap allocator
Le 14/08/2019 à 15:22, Christoph Hellwig a écrit :
Quoted 24 lines
This switches to using common code for the DMA allocations, including potential use of the CMA allocator if configured.
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 on tested code base for all architectures that require uncached pte bits for coherent DMA allocations.
Another advantage is that consistent memory allocations now share the general vmalloc pool instead of needing an explicit careout from it.
Signed-off-by Christoph Hellwig <[email protected]>--- arch/powerpc/Kconfig | 12 - arch/powerpc/include/asm/book3s/32/pgtable.h | 12 +- arch/powerpc/include/asm/nohash/32/pgtable.h | 12 +- arch/powerpc/mm/dma-noncoherent.c | 318 +------------------ arch/powerpc/mm/mem.c | 4 - arch/powerpc/mm/ptdump/ptdump.c | 9 - arch/powerpc/platforms/Kconfig.cputype | 2 + 7 files changed, 17 insertions(+), 352 deletions(-)
[...]
Quoted 4 lines
arch/powerpc/mm/dma-noncoherent.c +0
-0
[...]
Quoted 33 lines
arch/powerpc/mm/dma-noncoherent.c +9
-17@@ -408,23 +116,15 @@ void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr,__dma_sync_page (paddr, size, dir); } -/* -* Return the PFN for a given cpu virtual address returned by arch_dma_alloc. -*/ -long arch_dma_coherent_to_pfn (struct device *dev,void *vaddr, -dma_addr_t dma_addr) +void arch_dma_prep_coherent (struct page *page,size_t size) { -/* This should always be populated, so we don't test every -* level. If that fails, we'll have a nice crash which -* will be as good as a BUG_ON() -*/ -unsigned long cpu_addr = (unsigned long )vaddr; -pgd_t *pgd =pgd_offset_k (cpu_addr); -pud_t *pud =pud_offset (pgd, cpu_addr); -pmd_t *pmd =pmd_offset (pud, cpu_addr); -pte_t *ptep =pte_offset_kernel (pmd, cpu_addr); +unsigned long kaddr = (unsigned long )page_address (page); -if (pte_none (*ptep) || !pte_present (*ptep)) -return 0 ; -return pte_pfn (*ptep); +flush_dcache_range (kaddr, kaddr + size); +} + +static int __init atomic_pool_init (void ) +{ +return dma_atomic_pool_init (GFP_KERNEL ,pgprot_noncached (PAGE_KERNEL )); } +postcore_initcall (atomic_pool_init);
[...]
arch/powerpc/platforms/Kconfig.cputype config NOT_COHERENT_CACHE · line 452
Quoted 8 lines
arch/powerpc/platforms/Kconfig.cputype +0
-0@@ -450,8 +450,10 @@ config NOT_COHERENT_CACHE depends on 4xx || PPC_8xx || E200 || PPC_MPC512x || \ GAMECUBE_COMMON || AMIGAONE select ARCH_HAS_DMA_COHERENT_TO_PFN
You drop arch_dma_coherent_to_pfn(), it's surprising to see ARCH_HAS_DMA_COHERENT_TO_PFN remains. At first I thought I'd get a build failure.
After looking more, I see there is a arch_dma_coherent_to_pfn() defined in kernel/dma/remap.c when DMA_DIRECT_REMAP is selected.
I think the naming is not really consistant and should be fixed some how, because that's misleading to have an arch_something() being common to all.
Christophe
Quoted 8 lines
arch/powerpc/platforms/Kconfig.cputype +2
-0+ select ARCH_HAS_DMA_PREP_COHERENT select ARCH_HAS_SYNC_DMA_FOR_DEVICE select ARCH_HAS_SYNC_DMA_FOR_CPU + select DMA_DIRECT_REMAP default n if PPC_47x default y
Re: [PATCH] powerpc: use the generic dma coherent remap allocator
Quoted 12 lines · Christophe Leroy
arch/powerpc/platforms/Kconfig.cputype config NOT_COHERENT_CACHE · line 452
Quoted 7 lines
index
56a7c814160d..afe71b89dec3100644arch/powerpc/platforms/Kconfig.cputype +0
-0@@ -450,8 +450,10 @@ config NOT_COHERENT_CACHE depends on 4xx || PPC_8xx || E200 || PPC_MPC512x || \ GAMECUBE_COMMON || AMIGAONE select ARCH_HAS_DMA_COHERENT_TO_PFNYou drop
arch_dma_coherent_to_pfn(), it's surprising to seeARCH_HAS_DMA_COHERENT_TO_PFNremains. At first I thought I'd get a build failure.
Quoted 5 lines
After looking more, I see there is a
arch_dma_coherent_to_pfn()defined inkernel/dma/remap.cwhenDMA_DIRECT_REMAPis selected.I think the naming is not really consistant and should be fixed some how, because that's misleading to have an
arch_something()being common to all.
I actually have patches in the queue kill arch_dma_coherent_to_pfn off entirely, as we can always just get back to the physical address and thus pfn from the dma address using dma_to_phys for dma-direct.
But there is a huge review backlog for my outstanding dma patcheset, so it might take a bit until it is posted.
Re: [PATCH] powerpc: use the generic dma coherent remap allocator
In reply to Christoph HellwigLe 14/08/2019 à 15:22, Christoph Hellwig a écrit :
Quoted 9 lines
This switches to using common code for the DMA allocations, including potential use of the CMA allocator if configured.
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 on tested code base for all architectures that require uncached pte bits for coherent DMA allocations.
Quoted 5 lines
Another advantage is that consistent memory allocations now share the general vmalloc pool instead of needing an explicit careout from it.
Signed-off-by Christoph Hellwig <[email protected]>
Quoted 10 lines
--- arch/powerpc/Kconfig | 12 - arch/powerpc/include/asm/book3s/32/pgtable.h | 12 +- arch/powerpc/include/asm/nohash/32/pgtable.h | 12 +- arch/powerpc/mm/dma-noncoherent.c | 318 +------------------ arch/powerpc/mm/mem.c | 4 - arch/powerpc/mm/ptdump/ptdump.c | 9 - arch/powerpc/platforms/Kconfig.cputype | 2 + 7 files changed, 17 insertions(+), 352 deletions(-)
Re: [PATCH] powerpc: use the generic dma coherent remap allocator
In reply to Christoph HellwigMichael,
do oyu plan to pick this up? Otherwise I'd love to pick it up through the dma-mapping tree as that would avoid one trivial conflict with another pending patch.
Michael Ellerman
reviewerRe: [PATCH] powerpc: use the generic dma coherent remap allocator
Quoted 5 lines · Christoph Hellwig
Michael,
do oyu plan to pick this up? Otherwise I'd love to pick it up through the dma-mapping tree as that would avoid one trivial conflict with another pending patch.
It conflicts a bit with the ioremap changes I already have in next.
And it would be good for it to get some testing on my machines here. So I guess I'd rather it went via the powerpc tree?
cheers
Re: [PATCH] powerpc: use the generic dma coherent remap allocator
Quoted 11 lines · Michael Ellerman
Quoted 5 lines · Christoph Hellwig
Michael,
do oyu plan to pick this up? Otherwise I'd love to pick it up through the dma-mapping tree as that would avoid one trivial conflict with another pending patch.
It conflicts a bit with the ioremap changes I already have in next.
And it would be good for it to get some testing on my machines here. So I guess I'd rather it went via the powerpc tree?
Sure, feel free to queue it up through the ppc tree. I am about to queue up a patch to move the dma_atomic_pool_init call to common code, so as linux-next / Linus fixup we'll have to eventually remove atomic_pool_init() again.
Michael Ellerman
reviewerRe: [PATCH] powerpc: use the generic dma coherent remap allocator
Quoted 10 lines · Christoph Hellwig
Quoted 9 lines · Michael Ellerman
Quoted 5 lines · Christoph Hellwig
Michael,
do oyu plan to pick this up? Otherwise I'd love to pick it up through the dma-mapping tree as that would avoid one trivial conflict with another pending patch.
It conflicts a bit with the ioremap changes I already have in next.
Quoted 7 lines
Quoted 2 lines
And it would be good for it to get some testing on my machines here. So I guess I'd rather it went via the powerpc tree?
Sure, feel free to queue it up through the ppc tree. I am about to queue up a patch to move the
dma_atomic_pool_initcall to common code, so as linux-next / Linus fixup we'll have to eventually removeatomic_pool_init()again.
OK.
cheers
Michael Ellerman
AppliedRe: [PATCH] powerpc: use the generic dma coherent remap allocator
In reply to Christoph HellwigQuoted 9 lines · Christoph Hellwig
This switches to using common code for the DMA allocations, including potential use of the CMA allocator if configured.
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 on tested code base for all architectures that require uncached pte bits for coherent DMA allocations.
Quoted 5 lines
Another advantage is that consistent memory allocations now share the general vmalloc pool instead of needing an explicit careout from it.
Signed-off-by Christoph Hellwig <[email protected]>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/f2902a2fb40c589b886d21518ef8a1ee87f76b0c
cheers