]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
dma-mapping: make dma_atomic_pool_init self-contained
authorChristoph Hellwig <hch@lst.de>
Sat, 3 Aug 2019 09:42:15 +0000 (12:42 +0300)
committerChristoph Hellwig <hch@lst.de>
Thu, 29 Aug 2019 14:43:33 +0000 (16:43 +0200)
The memory allocated for the atomic pool needs to have the same
mapping attributes that we use for remapping, so use
pgprot_dmacoherent instead of open coding it.  Also deduct a
suitable zone to allocate the memory from based on the presence
of the DMA zones.

Signed-off-by: Christoph Hellwig <hch@lst.de>
arch/arc/mm/dma.c
arch/arm64/mm/dma-mapping.c
arch/csky/mm/dma-mapping.c
arch/nds32/kernel/dma.c
include/linux/dma-mapping.h
kernel/dma/remap.c

index 62c210e7ee4cdc5046b422d819a997e03134652f..ff4a5752f8cc3ae35be139608adb5f7920e110f8 100644 (file)
@@ -104,9 +104,3 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
        dev_info(dev, "use %sncoherent DMA ops\n",
                 dev->dma_coherent ? "" : "non");
 }
-
-static int __init atomic_pool_init(void)
-{
-       return dma_atomic_pool_init(GFP_KERNEL, pgprot_noncached(PAGE_KERNEL));
-}
-postcore_initcall(atomic_pool_init);
index 676efcda51e6bd24e912defbd1e2b136104d63ff..a1d05f669f67343a5e2e44cfcf43d922d1db8a4b 100644 (file)
@@ -28,12 +28,6 @@ void arch_dma_prep_coherent(struct page *page, size_t size)
        __dma_flush_area(page_address(page), size);
 }
 
-static int __init arm64_dma_init(void)
-{
-       return dma_atomic_pool_init(GFP_DMA32, __pgprot(PROT_NORMAL_NC));
-}
-arch_initcall(arm64_dma_init);
-
 #ifdef CONFIG_IOMMU_DMA
 void arch_teardown_dma_ops(struct device *dev)
 {
index 80783bb71c5cb8395b3c8baee713b310af89a396..602a60d47a9419175f59c9a9c83fe4955248b07f 100644 (file)
 #include <linux/version.h>
 #include <asm/cache.h>
 
-static int __init atomic_pool_init(void)
-{
-       return dma_atomic_pool_init(GFP_KERNEL, pgprot_noncached(PAGE_KERNEL));
-}
-postcore_initcall(atomic_pool_init);
-
 void arch_dma_prep_coherent(struct page *page, size_t size)
 {
        if (PageHighMem(page)) {
index 490e3720d69442c7cdc0fe9a0706b5d23ab64e67..4206d4b6c8cef40adfe7f59957e64012521fb35e 100644 (file)
@@ -80,9 +80,3 @@ void arch_dma_prep_coherent(struct page *page, size_t size)
 {
        cache_op(page_to_phys(page), size, cpu_dma_wbinval_range);
 }
-
-static int __init atomic_pool_init(void)
-{
-       return dma_atomic_pool_init(GFP_KERNEL, pgprot_noncached(PAGE_KERNEL));
-}
-postcore_initcall(atomic_pool_init);
index f7d1eea32c78b21ee9e1f02d20d8dd22ec35cc01..48ebe8295987ec941c38b35c287809e2c1f76cca 100644 (file)
@@ -624,7 +624,6 @@ void *dma_common_pages_remap(struct page **pages, size_t size,
                        const void *caller);
 void dma_common_free_remap(void *cpu_addr, size_t size, unsigned long vm_flags);
 
-int __init dma_atomic_pool_init(gfp_t gfp, pgprot_t prot);
 bool dma_in_atomic_pool(void *start, size_t size);
 void *dma_alloc_from_pool(size_t size, struct page **ret_page, gfp_t flags);
 bool dma_free_from_pool(void *start, size_t size);
index ffe78f0b2fe47c442330ee8de67cb11e230b0ae0..838123f796393c5226fdd5688aae4a3caac6a6bf 100644 (file)
@@ -105,7 +105,16 @@ static int __init early_coherent_pool(char *p)
 }
 early_param("coherent_pool", early_coherent_pool);
 
-int __init dma_atomic_pool_init(gfp_t gfp, pgprot_t prot)
+static gfp_t dma_atomic_pool_gfp(void)
+{
+       if (IS_ENABLED(CONFIG_ZONE_DMA))
+               return GFP_DMA;
+       if (IS_ENABLED(CONFIG_ZONE_DMA32))
+               return GFP_DMA32;
+       return GFP_KERNEL;
+}
+
+static int __init dma_atomic_pool_init(void)
 {
        unsigned int pool_size_order = get_order(atomic_pool_size);
        unsigned long nr_pages = atomic_pool_size >> PAGE_SHIFT;
@@ -117,7 +126,7 @@ int __init dma_atomic_pool_init(gfp_t gfp, pgprot_t prot)
                page = dma_alloc_from_contiguous(NULL, nr_pages,
                                                 pool_size_order, false);
        else
-               page = alloc_pages(gfp, pool_size_order);
+               page = alloc_pages(dma_atomic_pool_gfp(), pool_size_order);
        if (!page)
                goto out;
 
@@ -128,7 +137,8 @@ int __init dma_atomic_pool_init(gfp_t gfp, pgprot_t prot)
                goto free_page;
 
        addr = dma_common_contiguous_remap(page, atomic_pool_size, VM_USERMAP,
-                                          prot, __builtin_return_address(0));
+                                          pgprot_dmacoherent(PAGE_KERNEL),
+                                          __builtin_return_address(0));
        if (!addr)
                goto destroy_genpool;
 
@@ -155,6 +165,7 @@ int __init dma_atomic_pool_init(gfp_t gfp, pgprot_t prot)
                atomic_pool_size / 1024);
        return -ENOMEM;
 }
+postcore_initcall(dma_atomic_pool_init);
 
 bool dma_in_atomic_pool(void *start, size_t size)
 {