.. | .. |
---|
7 | 7 | #include <linux/mm.h> |
---|
8 | 8 | #include <linux/pci.h> |
---|
9 | 9 | #include <linux/gfp.h> |
---|
10 | | -#include <linux/bootmem.h> |
---|
| 10 | +#include <linux/memblock.h> |
---|
11 | 11 | #include <linux/export.h> |
---|
12 | 12 | #include <linux/scatterlist.h> |
---|
13 | 13 | #include <linux/log2.h> |
---|
14 | | -#include <linux/dma-mapping.h> |
---|
| 14 | +#include <linux/dma-map-ops.h> |
---|
15 | 15 | #include <linux/iommu-helper.h> |
---|
16 | 16 | |
---|
17 | 17 | #include <asm/io.h> |
---|
.. | .. |
---|
74 | 74 | |
---|
75 | 75 | #ifdef CONFIG_DISCONTIGMEM |
---|
76 | 76 | |
---|
77 | | - arena = alloc_bootmem_node(NODE_DATA(nid), sizeof(*arena)); |
---|
| 77 | + arena = memblock_alloc_node(sizeof(*arena), align, nid); |
---|
78 | 78 | if (!NODE_DATA(nid) || !arena) { |
---|
79 | 79 | printk("%s: couldn't allocate arena from node %d\n" |
---|
80 | 80 | " falling back to system-wide allocation\n", |
---|
81 | 81 | __func__, nid); |
---|
82 | | - arena = alloc_bootmem(sizeof(*arena)); |
---|
| 82 | + arena = memblock_alloc(sizeof(*arena), SMP_CACHE_BYTES); |
---|
| 83 | + if (!arena) |
---|
| 84 | + panic("%s: Failed to allocate %zu bytes\n", __func__, |
---|
| 85 | + sizeof(*arena)); |
---|
83 | 86 | } |
---|
84 | 87 | |
---|
85 | | - arena->ptes = __alloc_bootmem_node(NODE_DATA(nid), mem_size, align, 0); |
---|
| 88 | + arena->ptes = memblock_alloc_node(sizeof(*arena), align, nid); |
---|
86 | 89 | if (!NODE_DATA(nid) || !arena->ptes) { |
---|
87 | 90 | printk("%s: couldn't allocate arena ptes from node %d\n" |
---|
88 | 91 | " falling back to system-wide allocation\n", |
---|
89 | 92 | __func__, nid); |
---|
90 | | - arena->ptes = __alloc_bootmem(mem_size, align, 0); |
---|
| 93 | + arena->ptes = memblock_alloc(mem_size, align); |
---|
| 94 | + if (!arena->ptes) |
---|
| 95 | + panic("%s: Failed to allocate %lu bytes align=0x%lx\n", |
---|
| 96 | + __func__, mem_size, align); |
---|
91 | 97 | } |
---|
92 | 98 | |
---|
93 | 99 | #else /* CONFIG_DISCONTIGMEM */ |
---|
94 | 100 | |
---|
95 | | - arena = alloc_bootmem(sizeof(*arena)); |
---|
96 | | - arena->ptes = __alloc_bootmem(mem_size, align, 0); |
---|
| 101 | + arena = memblock_alloc(sizeof(*arena), SMP_CACHE_BYTES); |
---|
| 102 | + if (!arena) |
---|
| 103 | + panic("%s: Failed to allocate %zu bytes\n", __func__, |
---|
| 104 | + sizeof(*arena)); |
---|
| 105 | + arena->ptes = memblock_alloc(mem_size, align); |
---|
| 106 | + if (!arena->ptes) |
---|
| 107 | + panic("%s: Failed to allocate %lu bytes align=0x%lx\n", |
---|
| 108 | + __func__, mem_size, align); |
---|
97 | 109 | |
---|
98 | 110 | #endif /* CONFIG_DISCONTIGMEM */ |
---|
99 | 111 | |
---|
.. | .. |
---|
129 | 141 | unsigned long boundary_size; |
---|
130 | 142 | |
---|
131 | 143 | base = arena->dma_base >> PAGE_SHIFT; |
---|
132 | | - if (dev) { |
---|
133 | | - boundary_size = dma_get_seg_boundary(dev) + 1; |
---|
134 | | - boundary_size >>= PAGE_SHIFT; |
---|
135 | | - } else { |
---|
136 | | - boundary_size = 1UL << (32 - PAGE_SHIFT); |
---|
137 | | - } |
---|
| 144 | + boundary_size = dma_get_seg_boundary_nr_pages(dev, PAGE_SHIFT); |
---|
138 | 145 | |
---|
139 | 146 | /* Search forward for the first mask-aligned sequence of N free ptes */ |
---|
140 | 147 | ptes = arena->ptes; |
---|
.. | .. |
---|
237 | 244 | ok = 0; |
---|
238 | 245 | |
---|
239 | 246 | /* If both conditions above are met, we are fine. */ |
---|
240 | | - DBGA("pci_dac_dma_supported %s from %pf\n", |
---|
| 247 | + DBGA("pci_dac_dma_supported %s from %ps\n", |
---|
241 | 248 | ok ? "yes" : "no", __builtin_return_address(0)); |
---|
242 | 249 | |
---|
243 | 250 | return ok; |
---|
.. | .. |
---|
269 | 276 | && paddr + size <= __direct_map_size) { |
---|
270 | 277 | ret = paddr + __direct_map_base; |
---|
271 | 278 | |
---|
272 | | - DBGA2("pci_map_single: [%p,%zx] -> direct %llx from %pf\n", |
---|
| 279 | + DBGA2("pci_map_single: [%p,%zx] -> direct %llx from %ps\n", |
---|
273 | 280 | cpu_addr, size, ret, __builtin_return_address(0)); |
---|
274 | 281 | |
---|
275 | 282 | return ret; |
---|
.. | .. |
---|
280 | 287 | if (dac_allowed) { |
---|
281 | 288 | ret = paddr + alpha_mv.pci_dac_offset; |
---|
282 | 289 | |
---|
283 | | - DBGA2("pci_map_single: [%p,%zx] -> DAC %llx from %pf\n", |
---|
| 290 | + DBGA2("pci_map_single: [%p,%zx] -> DAC %llx from %ps\n", |
---|
284 | 291 | cpu_addr, size, ret, __builtin_return_address(0)); |
---|
285 | 292 | |
---|
286 | 293 | return ret; |
---|
.. | .. |
---|
291 | 298 | use direct_map above, it now must be considered an error. */ |
---|
292 | 299 | if (! alpha_mv.mv_pci_tbi) { |
---|
293 | 300 | printk_once(KERN_WARNING "pci_map_single: no HW sg\n"); |
---|
294 | | - return 0; |
---|
| 301 | + return DMA_MAPPING_ERROR; |
---|
295 | 302 | } |
---|
296 | 303 | |
---|
297 | 304 | arena = hose->sg_pci; |
---|
.. | .. |
---|
307 | 314 | if (dma_ofs < 0) { |
---|
308 | 315 | printk(KERN_WARNING "pci_map_single failed: " |
---|
309 | 316 | "could not allocate dma page tables\n"); |
---|
310 | | - return 0; |
---|
| 317 | + return DMA_MAPPING_ERROR; |
---|
311 | 318 | } |
---|
312 | 319 | |
---|
313 | 320 | paddr &= PAGE_MASK; |
---|
.. | .. |
---|
317 | 324 | ret = arena->dma_base + dma_ofs * PAGE_SIZE; |
---|
318 | 325 | ret += (unsigned long)cpu_addr & ~PAGE_MASK; |
---|
319 | 326 | |
---|
320 | | - DBGA2("pci_map_single: [%p,%zx] np %ld -> sg %llx from %pf\n", |
---|
| 327 | + DBGA2("pci_map_single: [%p,%zx] np %ld -> sg %llx from %ps\n", |
---|
321 | 328 | cpu_addr, size, npages, ret, __builtin_return_address(0)); |
---|
322 | 329 | |
---|
323 | 330 | return ret; |
---|
.. | .. |
---|
384 | 391 | && dma_addr < __direct_map_base + __direct_map_size) { |
---|
385 | 392 | /* Nothing to do. */ |
---|
386 | 393 | |
---|
387 | | - DBGA2("pci_unmap_single: direct [%llx,%zx] from %pf\n", |
---|
| 394 | + DBGA2("pci_unmap_single: direct [%llx,%zx] from %ps\n", |
---|
388 | 395 | dma_addr, size, __builtin_return_address(0)); |
---|
389 | 396 | |
---|
390 | 397 | return; |
---|
391 | 398 | } |
---|
392 | 399 | |
---|
393 | 400 | if (dma_addr > 0xffffffff) { |
---|
394 | | - DBGA2("pci64_unmap_single: DAC [%llx,%zx] from %pf\n", |
---|
| 401 | + DBGA2("pci64_unmap_single: DAC [%llx,%zx] from %ps\n", |
---|
395 | 402 | dma_addr, size, __builtin_return_address(0)); |
---|
396 | 403 | return; |
---|
397 | 404 | } |
---|
.. | .. |
---|
423 | 430 | |
---|
424 | 431 | spin_unlock_irqrestore(&arena->lock, flags); |
---|
425 | 432 | |
---|
426 | | - DBGA2("pci_unmap_single: sg [%llx,%zx] np %ld from %pf\n", |
---|
| 433 | + DBGA2("pci_unmap_single: sg [%llx,%zx] np %ld from %ps\n", |
---|
427 | 434 | dma_addr, size, npages, __builtin_return_address(0)); |
---|
428 | 435 | } |
---|
429 | 436 | |
---|
.. | .. |
---|
443 | 450 | gfp &= ~GFP_DMA; |
---|
444 | 451 | |
---|
445 | 452 | try_again: |
---|
446 | | - cpu_addr = (void *)__get_free_pages(gfp, order); |
---|
| 453 | + cpu_addr = (void *)__get_free_pages(gfp | __GFP_ZERO, order); |
---|
447 | 454 | if (! cpu_addr) { |
---|
448 | 455 | printk(KERN_INFO "pci_alloc_consistent: " |
---|
449 | | - "get_free_pages failed from %pf\n", |
---|
| 456 | + "get_free_pages failed from %ps\n", |
---|
450 | 457 | __builtin_return_address(0)); |
---|
451 | 458 | /* ??? Really atomic allocation? Otherwise we could play |
---|
452 | 459 | with vmalloc and sg if we can't find contiguous memory. */ |
---|
.. | .. |
---|
455 | 462 | memset(cpu_addr, 0, size); |
---|
456 | 463 | |
---|
457 | 464 | *dma_addrp = pci_map_single_1(pdev, cpu_addr, size, 0); |
---|
458 | | - if (*dma_addrp == 0) { |
---|
| 465 | + if (*dma_addrp == DMA_MAPPING_ERROR) { |
---|
459 | 466 | free_pages((unsigned long)cpu_addr, order); |
---|
460 | 467 | if (alpha_mv.mv_pci_tbi || (gfp & GFP_DMA)) |
---|
461 | 468 | return NULL; |
---|
.. | .. |
---|
465 | 472 | goto try_again; |
---|
466 | 473 | } |
---|
467 | 474 | |
---|
468 | | - DBGA2("pci_alloc_consistent: %zx -> [%p,%llx] from %pf\n", |
---|
| 475 | + DBGA2("pci_alloc_consistent: %zx -> [%p,%llx] from %ps\n", |
---|
469 | 476 | size, cpu_addr, *dma_addrp, __builtin_return_address(0)); |
---|
470 | 477 | |
---|
471 | 478 | return cpu_addr; |
---|
.. | .. |
---|
485 | 492 | pci_unmap_single(pdev, dma_addr, size, PCI_DMA_BIDIRECTIONAL); |
---|
486 | 493 | free_pages((unsigned long)cpu_addr, get_order(size)); |
---|
487 | 494 | |
---|
488 | | - DBGA2("pci_free_consistent: [%llx,%zx] from %pf\n", |
---|
| 495 | + DBGA2("pci_free_consistent: [%llx,%zx] from %ps\n", |
---|
489 | 496 | dma_addr, size, __builtin_return_address(0)); |
---|
490 | 497 | } |
---|
491 | 498 | |
---|
.. | .. |
---|
626 | 633 | |
---|
627 | 634 | while (sg+1 < end && (int) sg[1].dma_address == -1) { |
---|
628 | 635 | size += sg[1].length; |
---|
629 | | - sg++; |
---|
| 636 | + sg = sg_next(sg); |
---|
630 | 637 | } |
---|
631 | 638 | |
---|
632 | 639 | npages = iommu_num_pages(paddr, size, PAGE_SIZE); |
---|
.. | .. |
---|
671 | 678 | sg->dma_address |
---|
672 | 679 | = pci_map_single_1(pdev, SG_ENT_VIRT_ADDRESS(sg), |
---|
673 | 680 | sg->length, dac_allowed); |
---|
674 | | - return sg->dma_address != 0; |
---|
| 681 | + return sg->dma_address != DMA_MAPPING_ERROR; |
---|
675 | 682 | } |
---|
676 | 683 | |
---|
677 | 684 | start = sg; |
---|
.. | .. |
---|
935 | 942 | return 0; |
---|
936 | 943 | } |
---|
937 | 944 | |
---|
938 | | -static int alpha_pci_mapping_error(struct device *dev, dma_addr_t dma_addr) |
---|
939 | | -{ |
---|
940 | | - return dma_addr == 0; |
---|
941 | | -} |
---|
942 | | - |
---|
943 | 945 | const struct dma_map_ops alpha_pci_ops = { |
---|
944 | 946 | .alloc = alpha_pci_alloc_coherent, |
---|
945 | 947 | .free = alpha_pci_free_coherent, |
---|
.. | .. |
---|
947 | 949 | .unmap_page = alpha_pci_unmap_page, |
---|
948 | 950 | .map_sg = alpha_pci_map_sg, |
---|
949 | 951 | .unmap_sg = alpha_pci_unmap_sg, |
---|
950 | | - .mapping_error = alpha_pci_mapping_error, |
---|
951 | 952 | .dma_supported = alpha_pci_supported, |
---|
| 953 | + .mmap = dma_common_mmap, |
---|
| 954 | + .get_sgtable = dma_common_get_sgtable, |
---|
| 955 | + .alloc_pages = dma_common_alloc_pages, |
---|
| 956 | + .free_pages = dma_common_free_pages, |
---|
952 | 957 | }; |
---|
953 | 958 | EXPORT_SYMBOL(alpha_pci_ops); |
---|