dma/direct: turn ARCH_ZONE_DMA_BITS into a variable
authorNicolas Saenz Julienne <nsaenzjulienne@suse.de>
Mon, 14 Oct 2019 18:31:03 +0000 (20:31 +0200)
committerCatalin Marinas <catalin.marinas@arm.com>
Fri, 1 Nov 2019 09:41:18 +0000 (09:41 +0000)
Some architectures, notably ARM, are interested in tweaking this
depending on their runtime DMA addressing limitations.

Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
arch/arm64/include/asm/page.h
arch/arm64/mm/init.c
arch/powerpc/include/asm/page.h
arch/powerpc/mm/mem.c
arch/s390/include/asm/page.h
arch/s390/mm/init.c
include/linux/dma-direct.h
kernel/dma/direct.c

index 7b8c98830101e8a864e20cd3ada05dd71626b216..d39ddb258a04958ffdd72906dc77b4bd02484ea9 100644 (file)
@@ -38,6 +38,4 @@ extern int pfn_valid(unsigned long);
 
 #include <asm-generic/getorder.h>
 
-#define ARCH_ZONE_DMA_BITS 30
-
 #endif
index 39fc69873b1813884f48858246a6475e3e26861e..35f27b839101e495bd3de199dffbcfe79ae762f2 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/sort.h>
 #include <linux/of.h>
 #include <linux/of_fdt.h>
+#include <linux/dma-direct.h>
 #include <linux/dma-mapping.h>
 #include <linux/dma-contiguous.h>
 #include <linux/efi.h>
@@ -41,6 +42,8 @@
 #include <asm/tlb.h>
 #include <asm/alternative.h>
 
+#define ARM64_ZONE_DMA_BITS    30
+
 /*
  * We need to be able to catch inadvertent references to memstart_addr
  * that occur (potentially in generic code) before arm64_memblock_init()
@@ -440,8 +443,10 @@ void __init arm64_memblock_init(void)
 
        early_init_fdt_scan_reserved_mem();
 
-       if (IS_ENABLED(CONFIG_ZONE_DMA))
-               arm64_dma_phys_limit = max_zone_phys(ARCH_ZONE_DMA_BITS);
+       if (IS_ENABLED(CONFIG_ZONE_DMA)) {
+               zone_dma_bits = ARM64_ZONE_DMA_BITS;
+               arm64_dma_phys_limit = max_zone_phys(ARM64_ZONE_DMA_BITS);
+       }
 
        if (IS_ENABLED(CONFIG_ZONE_DMA32))
                arm64_dma32_phys_limit = max_zone_phys(32);
index c8bb14ff47135d7913c2392f10ff5b96d2c2a19d..f6c562acc3f850d0754e65c52384d3166689424d 100644 (file)
@@ -329,13 +329,4 @@ struct vm_area_struct;
 #endif /* __ASSEMBLY__ */
 #include <asm/slice.h>
 
-/*
- * Allow 30-bit DMA for very limited Broadcom wifi chips on many powerbooks.
- */
-#ifdef CONFIG_PPC32
-#define ARCH_ZONE_DMA_BITS 30
-#else
-#define ARCH_ZONE_DMA_BITS 31
-#endif
-
 #endif /* _ASM_POWERPC_PAGE_H */
index be941d382c8d10d036a46210ac5e1e69e6907505..c95b7fe9f298bab69f502b58a8e4d82589eccf4c 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 #include <linux/memremap.h>
+#include <linux/dma-direct.h>
 
 #include <asm/pgalloc.h>
 #include <asm/prom.h>
@@ -201,10 +202,10 @@ static int __init mark_nonram_nosave(void)
  * everything else. GFP_DMA32 page allocations automatically fall back to
  * ZONE_DMA.
  *
- * By using 31-bit unconditionally, we can exploit ARCH_ZONE_DMA_BITS to
- * inform the generic DMA mapping code.  32-bit only devices (if not handled
- * by an IOMMU anyway) will take a first dip into ZONE_NORMAL and get
- * otherwise served by ZONE_DMA.
+ * By using 31-bit unconditionally, we can exploit zone_dma_bits to inform the
+ * generic DMA mapping code.  32-bit only devices (if not handled by an IOMMU
+ * anyway) will take a first dip into ZONE_NORMAL and get otherwise served by
+ * ZONE_DMA.
  */
 static unsigned long max_zone_pfns[MAX_NR_ZONES];
 
@@ -237,9 +238,18 @@ void __init paging_init(void)
        printk(KERN_DEBUG "Memory hole size: %ldMB\n",
               (long int)((top_of_ram - total_ram) >> 20));
 
+       /*
+        * Allow 30-bit DMA for very limited Broadcom wifi chips on many
+        * powerbooks.
+        */
+       if (IS_ENABLED(CONFIG_PPC32))
+               zone_dma_bits = 30;
+       else
+               zone_dma_bits = 31;
+
 #ifdef CONFIG_ZONE_DMA
        max_zone_pfns[ZONE_DMA] = min(max_low_pfn,
-                                     1UL << (ARCH_ZONE_DMA_BITS - PAGE_SHIFT));
+                                     1UL << (zone_dma_bits - PAGE_SHIFT));
 #endif
        max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
 #ifdef CONFIG_HIGHMEM
index 823578c6b9e2c15b2081a69647cc0c488b12c297..a4d38092530abacb2295a3fe08589a8a3b1f7844 100644 (file)
@@ -177,8 +177,6 @@ static inline int devmem_is_allowed(unsigned long pfn)
 #define VM_DATA_DEFAULT_FLAGS  (VM_READ | VM_WRITE | \
                                 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
 
-#define ARCH_ZONE_DMA_BITS     31
-
 #include <asm-generic/memory_model.h>
 #include <asm-generic/getorder.h>
 
index a124f19f7b3cc48879d2fc2111be1b27c7b1761b..f0ce2222056592fdd0941b43918f610c2ee958cb 100644 (file)
@@ -118,6 +118,7 @@ void __init paging_init(void)
 
        sparse_memory_present_with_active_regions(MAX_NUMNODES);
        sparse_init();
+       zone_dma_bits = 31;
        memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
        max_zone_pfns[ZONE_DMA] = PFN_DOWN(MAX_DMA_ADDRESS);
        max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
index adf993a3bd58010de6db1c6e39c85ea2f085818d..d03af3605460fef629801df5f91df0e6d4d8b242 100644 (file)
@@ -5,6 +5,8 @@
 #include <linux/dma-mapping.h>
 #include <linux/mem_encrypt.h>
 
+extern unsigned int zone_dma_bits;
+
 #ifdef CONFIG_ARCH_HAS_PHYS_TO_DMA
 #include <asm/dma-direct.h>
 #else
index 8402b29c280f560ae18420f9a99fc3f614c40293..0b67c04e531b0f0d69854806de400179473cc4f8 100644 (file)
 #include <linux/swiotlb.h>
 
 /*
- * Most architectures use ZONE_DMA for the first 16 Megabytes, but
- * some use it for entirely different regions:
+ * Most architectures use ZONE_DMA for the first 16 Megabytes, but some use it
+ * it for entirely different regions. In that case the arch code needs to
+ * override the variable below for dma-direct to work properly.
  */
-#ifndef ARCH_ZONE_DMA_BITS
-#define ARCH_ZONE_DMA_BITS 24
-#endif
+unsigned int zone_dma_bits __ro_after_init = 24;
 
 static void report_addr(struct device *dev, dma_addr_t dma_addr, size_t size)
 {
@@ -69,7 +68,7 @@ static gfp_t __dma_direct_optimal_gfp_mask(struct device *dev, u64 dma_mask,
         * Note that GFP_DMA32 and GFP_DMA are no ops without the corresponding
         * zones.
         */
-       if (*phys_mask <= DMA_BIT_MASK(ARCH_ZONE_DMA_BITS))
+       if (*phys_mask <= DMA_BIT_MASK(zone_dma_bits))
                return GFP_DMA;
        if (*phys_mask <= DMA_BIT_MASK(32))
                return GFP_DMA32;
@@ -395,7 +394,7 @@ int dma_direct_supported(struct device *dev, u64 mask)
        u64 min_mask;
 
        if (IS_ENABLED(CONFIG_ZONE_DMA))
-               min_mask = DMA_BIT_MASK(ARCH_ZONE_DMA_BITS);
+               min_mask = DMA_BIT_MASK(zone_dma_bits);
        else
                min_mask = DMA_BIT_MASK(32);