5de73d37f7da4aa40c444f89dcfba2811bf3511c
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0450-dma-direct-turn-ARCH_ZONE_DMA_BITS-into-a-variable.patch
1 From 78b03f0aef9f67c4db700ba5dc56e2c8f562d181 Mon Sep 17 00:00:00 2001
2 From: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
3 Date: Mon, 14 Oct 2019 20:31:03 +0200
4 Subject: [PATCH] dma/direct: turn ARCH_ZONE_DMA_BITS into a variable
5
6 commit 8b5369ea580964dbc982781bfb9fb93459fc5e8d upstream.
7
8 Some architectures, notably ARM, are interested in tweaking this
9 depending on their runtime DMA addressing limitations.
10
11 Acked-by: Christoph Hellwig <hch@lst.de>
12 Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
13 Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
14 ---
15 arch/arm64/include/asm/page.h | 2 --
16 arch/arm64/mm/init.c | 9 +++++++--
17 arch/powerpc/include/asm/page.h | 9 ---------
18 arch/powerpc/mm/mem.c | 20 +++++++++++++++-----
19 arch/s390/include/asm/page.h | 2 --
20 arch/s390/mm/init.c | 1 +
21 include/linux/dma-direct.h | 2 ++
22 kernel/dma/direct.c | 13 ++++++-------
23 8 files changed, 31 insertions(+), 27 deletions(-)
24
25 --- a/arch/arm64/include/asm/page.h
26 +++ b/arch/arm64/include/asm/page.h
27 @@ -38,6 +38,4 @@ extern int pfn_valid(unsigned long);
28
29 #include <asm-generic/getorder.h>
30
31 -#define ARCH_ZONE_DMA_BITS 30
32 -
33 #endif
34 --- a/arch/arm64/mm/init.c
35 +++ b/arch/arm64/mm/init.c
36 @@ -20,6 +20,7 @@
37 #include <linux/sort.h>
38 #include <linux/of.h>
39 #include <linux/of_fdt.h>
40 +#include <linux/dma-direct.h>
41 #include <linux/dma-mapping.h>
42 #include <linux/dma-contiguous.h>
43 #include <linux/efi.h>
44 @@ -41,6 +42,8 @@
45 #include <asm/tlb.h>
46 #include <asm/alternative.h>
47
48 +#define ARM64_ZONE_DMA_BITS 30
49 +
50 /*
51 * We need to be able to catch inadvertent references to memstart_addr
52 * that occur (potentially in generic code) before arm64_memblock_init()
53 @@ -440,8 +443,10 @@ void __init arm64_memblock_init(void)
54
55 early_init_fdt_scan_reserved_mem();
56
57 - if (IS_ENABLED(CONFIG_ZONE_DMA))
58 - arm64_dma_phys_limit = max_zone_phys(ARCH_ZONE_DMA_BITS);
59 + if (IS_ENABLED(CONFIG_ZONE_DMA)) {
60 + zone_dma_bits = ARM64_ZONE_DMA_BITS;
61 + arm64_dma_phys_limit = max_zone_phys(ARM64_ZONE_DMA_BITS);
62 + }
63
64 if (IS_ENABLED(CONFIG_ZONE_DMA32))
65 arm64_dma32_phys_limit = max_zone_phys(32);
66 --- a/arch/powerpc/include/asm/page.h
67 +++ b/arch/powerpc/include/asm/page.h
68 @@ -334,13 +334,4 @@ struct vm_area_struct;
69 #endif /* __ASSEMBLY__ */
70 #include <asm/slice.h>
71
72 -/*
73 - * Allow 30-bit DMA for very limited Broadcom wifi chips on many powerbooks.
74 - */
75 -#ifdef CONFIG_PPC32
76 -#define ARCH_ZONE_DMA_BITS 30
77 -#else
78 -#define ARCH_ZONE_DMA_BITS 31
79 -#endif
80 -
81 #endif /* _ASM_POWERPC_PAGE_H */
82 --- a/arch/powerpc/mm/mem.c
83 +++ b/arch/powerpc/mm/mem.c
84 @@ -31,6 +31,7 @@
85 #include <linux/slab.h>
86 #include <linux/vmalloc.h>
87 #include <linux/memremap.h>
88 +#include <linux/dma-direct.h>
89
90 #include <asm/pgalloc.h>
91 #include <asm/prom.h>
92 @@ -223,10 +224,10 @@ static int __init mark_nonram_nosave(voi
93 * everything else. GFP_DMA32 page allocations automatically fall back to
94 * ZONE_DMA.
95 *
96 - * By using 31-bit unconditionally, we can exploit ARCH_ZONE_DMA_BITS to
97 - * inform the generic DMA mapping code. 32-bit only devices (if not handled
98 - * by an IOMMU anyway) will take a first dip into ZONE_NORMAL and get
99 - * otherwise served by ZONE_DMA.
100 + * By using 31-bit unconditionally, we can exploit zone_dma_bits to inform the
101 + * generic DMA mapping code. 32-bit only devices (if not handled by an IOMMU
102 + * anyway) will take a first dip into ZONE_NORMAL and get otherwise served by
103 + * ZONE_DMA.
104 */
105 static unsigned long max_zone_pfns[MAX_NR_ZONES];
106
107 @@ -259,9 +260,18 @@ void __init paging_init(void)
108 printk(KERN_DEBUG "Memory hole size: %ldMB\n",
109 (long int)((top_of_ram - total_ram) >> 20));
110
111 + /*
112 + * Allow 30-bit DMA for very limited Broadcom wifi chips on many
113 + * powerbooks.
114 + */
115 + if (IS_ENABLED(CONFIG_PPC32))
116 + zone_dma_bits = 30;
117 + else
118 + zone_dma_bits = 31;
119 +
120 #ifdef CONFIG_ZONE_DMA
121 max_zone_pfns[ZONE_DMA] = min(max_low_pfn,
122 - 1UL << (ARCH_ZONE_DMA_BITS - PAGE_SHIFT));
123 + 1UL << (zone_dma_bits - PAGE_SHIFT));
124 #endif
125 max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
126 #ifdef CONFIG_HIGHMEM
127 --- a/arch/s390/include/asm/page.h
128 +++ b/arch/s390/include/asm/page.h
129 @@ -179,8 +179,6 @@ static inline int devmem_is_allowed(unsi
130 #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | \
131 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
132
133 -#define ARCH_ZONE_DMA_BITS 31
134 -
135 #include <asm-generic/memory_model.h>
136 #include <asm-generic/getorder.h>
137
138 --- a/arch/s390/mm/init.c
139 +++ b/arch/s390/mm/init.c
140 @@ -118,6 +118,7 @@ void __init paging_init(void)
141
142 sparse_memory_present_with_active_regions(MAX_NUMNODES);
143 sparse_init();
144 + zone_dma_bits = 31;
145 memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
146 max_zone_pfns[ZONE_DMA] = PFN_DOWN(MAX_DMA_ADDRESS);
147 max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
148 --- a/include/linux/dma-direct.h
149 +++ b/include/linux/dma-direct.h
150 @@ -8,6 +8,8 @@
151
152 static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr);
153
154 +extern unsigned int zone_dma_bits;
155 +
156 #ifdef CONFIG_ARCH_HAS_PHYS_TO_DMA
157 #include <asm/dma-direct.h>
158 #else
159 --- a/kernel/dma/direct.c
160 +++ b/kernel/dma/direct.c
161 @@ -16,12 +16,11 @@
162 #include <linux/swiotlb.h>
163
164 /*
165 - * Most architectures use ZONE_DMA for the first 16 Megabytes, but
166 - * some use it for entirely different regions:
167 + * Most architectures use ZONE_DMA for the first 16 Megabytes, but some use it
168 + * it for entirely different regions. In that case the arch code needs to
169 + * override the variable below for dma-direct to work properly.
170 */
171 -#ifndef ARCH_ZONE_DMA_BITS
172 -#define ARCH_ZONE_DMA_BITS 24
173 -#endif
174 +unsigned int zone_dma_bits __ro_after_init = 24;
175
176 static void report_addr(struct device *dev, dma_addr_t dma_addr, size_t size)
177 {
178 @@ -69,7 +68,7 @@ static gfp_t __dma_direct_optimal_gfp_ma
179 * Note that GFP_DMA32 and GFP_DMA are no ops without the corresponding
180 * zones.
181 */
182 - if (*phys_mask <= DMA_BIT_MASK(ARCH_ZONE_DMA_BITS))
183 + if (*phys_mask <= DMA_BIT_MASK(zone_dma_bits))
184 return GFP_DMA;
185 if (*phys_mask <= DMA_BIT_MASK(32))
186 return GFP_DMA32;
187 @@ -395,7 +394,7 @@ int dma_direct_supported(struct device *
188 u64 min_mask;
189
190 if (IS_ENABLED(CONFIG_ZONE_DMA))
191 - min_mask = DMA_BIT_MASK(ARCH_ZONE_DMA_BITS);
192 + min_mask = DMA_BIT_MASK(zone_dma_bits);
193 else
194 min_mask = DMA_BIT_MASK(30);
195