Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'for-next/zone-dma' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux into dma-mapping-for-next

Pull in a stable branch from the arm64 tree that adds the zone_dma_bits
variable to avoid creating hard to resolve conflicts with that addition.

+107 -66
+4
arch/arm64/Kconfig
··· 265 265 config GENERIC_CALIBRATE_DELAY 266 266 def_bool y 267 267 268 + config ZONE_DMA 269 + bool "Support DMA zone" if EXPERT 270 + default y 271 + 268 272 config ZONE_DMA32 269 273 bool "Support DMA32 zone" if EXPERT 270 274 default y
+53 -24
arch/arm64/mm/init.c
··· 20 20 #include <linux/sort.h> 21 21 #include <linux/of.h> 22 22 #include <linux/of_fdt.h> 23 + #include <linux/dma-direct.h> 23 24 #include <linux/dma-mapping.h> 24 25 #include <linux/dma-contiguous.h> 25 26 #include <linux/efi.h> ··· 42 41 #include <asm/tlb.h> 43 42 #include <asm/alternative.h> 44 43 44 + #define ARM64_ZONE_DMA_BITS 30 45 + 45 46 /* 46 47 * We need to be able to catch inadvertent references to memstart_addr 47 48 * that occur (potentially in generic code) before arm64_memblock_init() ··· 59 56 struct page *vmemmap __ro_after_init; 60 57 EXPORT_SYMBOL(vmemmap); 61 58 59 + /* 60 + * We create both ZONE_DMA and ZONE_DMA32. ZONE_DMA covers the first 1G of 61 + * memory as some devices, namely the Raspberry Pi 4, have peripherals with 62 + * this limited view of the memory. ZONE_DMA32 will cover the rest of the 32 63 + * bit addressable memory area. 64 + */ 62 65 phys_addr_t arm64_dma_phys_limit __ro_after_init; 66 + static phys_addr_t arm64_dma32_phys_limit __ro_after_init; 63 67 64 68 #ifdef CONFIG_KEXEC_CORE 65 69 /* ··· 91 81 92 82 if (crash_base == 0) { 93 83 /* Current arm64 boot protocol requires 2MB alignment */ 94 - crash_base = memblock_find_in_range(0, ARCH_LOW_ADDRESS_LIMIT, 84 + crash_base = memblock_find_in_range(0, arm64_dma32_phys_limit, 95 85 crash_size, SZ_2M); 96 86 if (crash_base == 0) { 97 87 pr_warn("cannot allocate crashkernel (size:0x%llx)\n", ··· 179 169 { 180 170 } 181 171 #endif /* CONFIG_CRASH_DUMP */ 172 + 182 173 /* 183 - * Return the maximum physical address for ZONE_DMA32 (DMA_BIT_MASK(32)). It 184 - * currently assumes that for memory starting above 4G, 32-bit devices will 185 - * use a DMA offset. 174 + * Return the maximum physical address for a zone with a given address size 175 + * limit. It currently assumes that for memory starting above 4G, 32-bit 176 + * devices will use a DMA offset. 186 177 */ 187 - static phys_addr_t __init max_zone_dma_phys(void) 178 + static phys_addr_t __init max_zone_phys(unsigned int zone_bits) 188 179 { 189 - phys_addr_t offset = memblock_start_of_DRAM() & GENMASK_ULL(63, 32); 190 - return min(offset + (1ULL << 32), memblock_end_of_DRAM()); 180 + phys_addr_t offset = memblock_start_of_DRAM() & GENMASK_ULL(63, zone_bits); 181 + return min(offset + (1ULL << zone_bits), memblock_end_of_DRAM()); 191 182 } 192 183 193 184 #ifdef CONFIG_NUMA ··· 197 186 { 198 187 unsigned long max_zone_pfns[MAX_NR_ZONES] = {0}; 199 188 189 + #ifdef CONFIG_ZONE_DMA 190 + max_zone_pfns[ZONE_DMA] = PFN_DOWN(arm64_dma_phys_limit); 191 + #endif 200 192 #ifdef CONFIG_ZONE_DMA32 201 - max_zone_pfns[ZONE_DMA32] = PFN_DOWN(max_zone_dma_phys()); 193 + max_zone_pfns[ZONE_DMA32] = PFN_DOWN(arm64_dma32_phys_limit); 202 194 #endif 203 195 max_zone_pfns[ZONE_NORMAL] = max; 204 196 ··· 214 200 { 215 201 struct memblock_region *reg; 216 202 unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES]; 217 - unsigned long max_dma = min; 203 + unsigned long max_dma32 = min; 204 + unsigned long __maybe_unused max_dma = min; 218 205 219 206 memset(zone_size, 0, sizeof(zone_size)); 220 207 221 - /* 4GB maximum for 32-bit only capable devices */ 222 - #ifdef CONFIG_ZONE_DMA32 208 + #ifdef CONFIG_ZONE_DMA 223 209 max_dma = PFN_DOWN(arm64_dma_phys_limit); 224 - zone_size[ZONE_DMA32] = max_dma - min; 210 + zone_size[ZONE_DMA] = max_dma - min; 211 + max_dma32 = max_dma; 225 212 #endif 226 - zone_size[ZONE_NORMAL] = max - max_dma; 213 + #ifdef CONFIG_ZONE_DMA32 214 + max_dma32 = PFN_DOWN(arm64_dma32_phys_limit); 215 + zone_size[ZONE_DMA32] = max_dma32 - max_dma; 216 + #endif 217 + zone_size[ZONE_NORMAL] = max - max_dma32; 227 218 228 219 memcpy(zhole_size, zone_size, sizeof(zhole_size)); 229 220 ··· 238 219 239 220 if (start >= max) 240 221 continue; 241 - 242 - #ifdef CONFIG_ZONE_DMA32 222 + #ifdef CONFIG_ZONE_DMA 243 223 if (start < max_dma) { 244 - unsigned long dma_end = min(end, max_dma); 245 - zhole_size[ZONE_DMA32] -= dma_end - start; 224 + unsigned long dma_end = min_not_zero(end, max_dma); 225 + zhole_size[ZONE_DMA] -= dma_end - start; 246 226 } 247 227 #endif 248 - if (end > max_dma) { 228 + #ifdef CONFIG_ZONE_DMA32 229 + if (start < max_dma32) { 230 + unsigned long dma32_end = min(end, max_dma32); 231 + unsigned long dma32_start = max(start, max_dma); 232 + zhole_size[ZONE_DMA32] -= dma32_end - dma32_start; 233 + } 234 + #endif 235 + if (end > max_dma32) { 249 236 unsigned long normal_end = min(end, max); 250 - unsigned long normal_start = max(start, max_dma); 237 + unsigned long normal_start = max(start, max_dma32); 251 238 zhole_size[ZONE_NORMAL] -= normal_end - normal_start; 252 239 } 253 240 } ··· 443 418 444 419 early_init_fdt_scan_reserved_mem(); 445 420 446 - /* 4GB maximum for 32-bit only capable devices */ 421 + if (IS_ENABLED(CONFIG_ZONE_DMA)) { 422 + zone_dma_bits = ARM64_ZONE_DMA_BITS; 423 + arm64_dma_phys_limit = max_zone_phys(ARM64_ZONE_DMA_BITS); 424 + } 425 + 447 426 if (IS_ENABLED(CONFIG_ZONE_DMA32)) 448 - arm64_dma_phys_limit = max_zone_dma_phys(); 427 + arm64_dma32_phys_limit = max_zone_phys(32); 449 428 else 450 - arm64_dma_phys_limit = PHYS_MASK + 1; 429 + arm64_dma32_phys_limit = PHYS_MASK + 1; 451 430 452 431 reserve_crashkernel(); 453 432 ··· 459 430 460 431 high_memory = __va(memblock_end_of_DRAM() - 1) + 1; 461 432 462 - dma_contiguous_reserve(arm64_dma_phys_limit); 433 + dma_contiguous_reserve(arm64_dma32_phys_limit); 463 434 } 464 435 465 436 void __init bootmem_init(void) ··· 563 534 void __init mem_init(void) 564 535 { 565 536 if (swiotlb_force == SWIOTLB_FORCE || 566 - max_pfn > (arm64_dma_phys_limit >> PAGE_SHIFT)) 537 + max_pfn > PFN_DOWN(arm64_dma_phys_limit ? : arm64_dma32_phys_limit)) 567 538 swiotlb_init(1); 568 539 else 569 540 swiotlb_force = SWIOTLB_NO_FORCE;
-9
arch/powerpc/include/asm/page.h
··· 329 329 #endif /* __ASSEMBLY__ */ 330 330 #include <asm/slice.h> 331 331 332 - /* 333 - * Allow 30-bit DMA for very limited Broadcom wifi chips on many powerbooks. 334 - */ 335 - #ifdef CONFIG_PPC32 336 - #define ARCH_ZONE_DMA_BITS 30 337 - #else 338 - #define ARCH_ZONE_DMA_BITS 31 339 - #endif 340 - 341 332 #endif /* _ASM_POWERPC_PAGE_H */
+15 -5
arch/powerpc/mm/mem.c
··· 31 31 #include <linux/slab.h> 32 32 #include <linux/vmalloc.h> 33 33 #include <linux/memremap.h> 34 + #include <linux/dma-direct.h> 34 35 35 36 #include <asm/pgalloc.h> 36 37 #include <asm/prom.h> ··· 202 201 * everything else. GFP_DMA32 page allocations automatically fall back to 203 202 * ZONE_DMA. 204 203 * 205 - * By using 31-bit unconditionally, we can exploit ARCH_ZONE_DMA_BITS to 206 - * inform the generic DMA mapping code. 32-bit only devices (if not handled 207 - * by an IOMMU anyway) will take a first dip into ZONE_NORMAL and get 208 - * otherwise served by ZONE_DMA. 204 + * By using 31-bit unconditionally, we can exploit zone_dma_bits to inform the 205 + * generic DMA mapping code. 32-bit only devices (if not handled by an IOMMU 206 + * anyway) will take a first dip into ZONE_NORMAL and get otherwise served by 207 + * ZONE_DMA. 209 208 */ 210 209 static unsigned long max_zone_pfns[MAX_NR_ZONES]; 211 210 ··· 238 237 printk(KERN_DEBUG "Memory hole size: %ldMB\n", 239 238 (long int)((top_of_ram - total_ram) >> 20)); 240 239 240 + /* 241 + * Allow 30-bit DMA for very limited Broadcom wifi chips on many 242 + * powerbooks. 243 + */ 244 + if (IS_ENABLED(CONFIG_PPC32)) 245 + zone_dma_bits = 30; 246 + else 247 + zone_dma_bits = 31; 248 + 241 249 #ifdef CONFIG_ZONE_DMA 242 250 max_zone_pfns[ZONE_DMA] = min(max_low_pfn, 243 - 1UL << (ARCH_ZONE_DMA_BITS - PAGE_SHIFT)); 251 + 1UL << (zone_dma_bits - PAGE_SHIFT)); 244 252 #endif 245 253 max_zone_pfns[ZONE_NORMAL] = max_low_pfn; 246 254 #ifdef CONFIG_HIGHMEM
-2
arch/s390/include/asm/page.h
··· 177 177 #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | \ 178 178 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) 179 179 180 - #define ARCH_ZONE_DMA_BITS 31 181 - 182 180 #include <asm-generic/memory_model.h> 183 181 #include <asm-generic/getorder.h> 184 182
+1
arch/s390/mm/init.c
··· 118 118 119 119 sparse_memory_present_with_active_regions(MAX_NUMNODES); 120 120 sparse_init(); 121 + zone_dma_bits = 31; 121 122 memset(max_zone_pfns, 0, sizeof(max_zone_pfns)); 122 123 max_zone_pfns[ZONE_DMA] = PFN_DOWN(MAX_DMA_ADDRESS); 123 124 max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
+2
include/linux/dma-direct.h
··· 6 6 #include <linux/memblock.h> /* for min_low_pfn */ 7 7 #include <linux/mem_encrypt.h> 8 8 9 + extern unsigned int zone_dma_bits; 10 + 9 11 #ifdef CONFIG_ARCH_HAS_PHYS_TO_DMA 10 12 #include <asm/dma-direct.h> 11 13 #else
+26 -19
include/linux/mmzone.h
··· 359 359 #endif /* !__GENERATING_BOUNDS.H */ 360 360 361 361 enum zone_type { 362 - #ifdef CONFIG_ZONE_DMA 363 362 /* 364 - * ZONE_DMA is used when there are devices that are not able 365 - * to do DMA to all of addressable memory (ZONE_NORMAL). Then we 366 - * carve out the portion of memory that is needed for these devices. 367 - * The range is arch specific. 363 + * ZONE_DMA and ZONE_DMA32 are used when there are peripherals not able 364 + * to DMA to all of the addressable memory (ZONE_NORMAL). 365 + * On architectures where this area covers the whole 32 bit address 366 + * space ZONE_DMA32 is used. ZONE_DMA is left for the ones with smaller 367 + * DMA addressing constraints. This distinction is important as a 32bit 368 + * DMA mask is assumed when ZONE_DMA32 is defined. Some 64-bit 369 + * platforms may need both zones as they support peripherals with 370 + * different DMA addressing limitations. 368 371 * 369 - * Some examples 372 + * Some examples: 370 373 * 371 - * Architecture Limit 372 - * --------------------------- 373 - * parisc, ia64, sparc <4G 374 - * s390, powerpc <2G 375 - * arm Various 376 - * alpha Unlimited or 0-16MB. 374 + * - i386 and x86_64 have a fixed 16M ZONE_DMA and ZONE_DMA32 for the 375 + * rest of the lower 4G. 377 376 * 378 - * i386, x86_64 and multiple other arches 379 - * <16M. 377 + * - arm only uses ZONE_DMA, the size, up to 4G, may vary depending on 378 + * the specific device. 379 + * 380 + * - arm64 has a fixed 1G ZONE_DMA and ZONE_DMA32 for the rest of the 381 + * lower 4G. 382 + * 383 + * - powerpc only uses ZONE_DMA, the size, up to 2G, may vary 384 + * depending on the specific device. 385 + * 386 + * - s390 uses ZONE_DMA fixed to the lower 2G. 387 + * 388 + * - ia64 and riscv only use ZONE_DMA32. 389 + * 390 + * - parisc uses neither. 380 391 */ 392 + #ifdef CONFIG_ZONE_DMA 381 393 ZONE_DMA, 382 394 #endif 383 395 #ifdef CONFIG_ZONE_DMA32 384 - /* 385 - * x86_64 needs two ZONE_DMAs because it supports devices that are 386 - * only able to do DMA to the lower 16M but also 32 bit devices that 387 - * can only do DMA areas below 4G. 388 - */ 389 396 ZONE_DMA32, 390 397 #endif 391 398 /*
+6 -7
kernel/dma/direct.c
··· 17 17 #include <linux/swiotlb.h> 18 18 19 19 /* 20 - * Most architectures use ZONE_DMA for the first 16 Megabytes, but 21 - * some use it for entirely different regions: 20 + * Most architectures use ZONE_DMA for the first 16 Megabytes, but some use it 21 + * it for entirely different regions. In that case the arch code needs to 22 + * override the variable below for dma-direct to work properly. 22 23 */ 23 - #ifndef ARCH_ZONE_DMA_BITS 24 - #define ARCH_ZONE_DMA_BITS 24 25 - #endif 24 + unsigned int zone_dma_bits __ro_after_init = 24; 26 25 27 26 static void report_addr(struct device *dev, dma_addr_t dma_addr, size_t size) 28 27 { ··· 75 76 * Note that GFP_DMA32 and GFP_DMA are no ops without the corresponding 76 77 * zones. 77 78 */ 78 - if (*phys_mask <= DMA_BIT_MASK(ARCH_ZONE_DMA_BITS)) 79 + if (*phys_mask <= DMA_BIT_MASK(zone_dma_bits)) 79 80 return GFP_DMA; 80 81 if (*phys_mask <= DMA_BIT_MASK(32)) 81 82 return GFP_DMA32; ··· 484 485 u64 min_mask; 485 486 486 487 if (IS_ENABLED(CONFIG_ZONE_DMA)) 487 - min_mask = DMA_BIT_MASK(ARCH_ZONE_DMA_BITS); 488 + min_mask = DMA_BIT_MASK(zone_dma_bits); 488 489 else 489 490 min_mask = DMA_BIT_MASK(32); 490 491