Skip to content

Commit 9e3a25d

Browse files
committed
Merge tag 'dma-mapping-5.3' of git://git.infradead.org/users/hch/dma-mapping
Pull dma-mapping updates from Christoph Hellwig: - move the USB special case that bounced DMA through a device bar into the USB code instead of handling it in the common DMA code (Laurentiu Tudor and Fredrik Noring) - don't dip into the global CMA pool for single page allocations (Nicolin Chen) - fix a crash when allocating memory for the atomic pool failed during boot (Florian Fainelli) - move support for MIPS-style uncached segments to the common code and use that for MIPS and nios2 (me) - make support for DMA_ATTR_NON_CONSISTENT and DMA_ATTR_NO_KERNEL_MAPPING generic (me) - convert nds32 to the generic remapping allocator (me) * tag 'dma-mapping-5.3' of git://git.infradead.org/users/hch/dma-mapping: (29 commits) dma-mapping: mark dma_alloc_need_uncached as __always_inline MIPS: only select ARCH_HAS_UNCACHED_SEGMENT for non-coherent platforms usb: host: Fix excessive alignment restriction for local memory allocations lib/genalloc.c: Add algorithm, align and zeroed family of DMA allocators nios2: use the generic uncached segment support in dma-direct nds32: use the generic remapping allocator for coherent DMA allocations arc: use the generic remapping allocator for coherent DMA allocations dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code dma-direct: handle DMA_ATTR_NON_CONSISTENT in common code dma-mapping: add a dma_alloc_need_uncached helper openrisc: remove the partial DMA_ATTR_NON_CONSISTENT support arc: remove the partial DMA_ATTR_NON_CONSISTENT support arm-nommu: remove the partial DMA_ATTR_NON_CONSISTENT support ARM: dma-mapping: allow larger DMA mask than supported dma-mapping: truncate dma masks to what dma_addr_t can hold iommu/dma: Apply dma_{alloc,free}_contiguous functions dma-remap: Avoid de-referencing NULL atomic_pool MIPS: use the generic uncached segment support in dma-direct dma-direct: provide generic support for uncached kernel segments au1100fb: fix DMA API abuse ...
2 parents 9787aed + 15ffe5e commit 9e3a25d

41 files changed

Lines changed: 515 additions & 654 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎arch/Kconfig‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,14 @@ config ARCH_HAS_SET_MEMORY
260260
config ARCH_HAS_SET_DIRECT_MAP
261261
bool
262262

263+
#
264+
# Select if arch has an uncached kernel segment and provides the
265+
# uncached_kernel_address / cached_kernel_address symbols to use it
266+
#
267+
config ARCH_HAS_UNCACHED_SEGMENT
268+
select ARCH_HAS_DMA_PREP_COHERENT
269+
bool
270+
263271
# Select if arch init_task must go in the __init_task_data section
264272
config ARCH_TASK_STRUCT_ON_STACK
265273
bool

‎arch/arc/Kconfig‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ config ARC
77
def_bool y
88
select ARC_TIMERS
99
select ARCH_HAS_DMA_COHERENT_TO_PFN
10+
select ARCH_HAS_DMA_PREP_COHERENT
1011
select ARCH_HAS_PTE_SPECIAL
1112
select ARCH_HAS_SETUP_DMA_OPS
1213
select ARCH_HAS_SYNC_DMA_FOR_CPU
@@ -16,6 +17,7 @@ config ARC
1617
select BUILDTIME_EXTABLE_SORT
1718
select CLONE_BACKWARDS
1819
select COMMON_CLK
20+
select DMA_DIRECT_REMAP
1921
select GENERIC_ATOMIC64 if !ISA_ARCV2 || !(ARC_HAS_LL64 && ARC_HAS_LLSC)
2022
select GENERIC_CLOCKEVENTS
2123
select GENERIC_FIND_FIRST_BIT

‎arch/arc/mm/dma.c‎

Lines changed: 10 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,15 @@
88
#include <asm/cacheflush.h>
99

1010
/*
11-
* ARCH specific callbacks for generic noncoherent DMA ops (dma/noncoherent.c)
11+
* ARCH specific callbacks for generic noncoherent DMA ops
1212
* - hardware IOC not available (or "dma-coherent" not set for device in DT)
1313
* - But still handle both coherent and non-coherent requests from caller
1414
*
1515
* For DMA coherent hardware (IOC) generic code suffices
1616
*/
17-
void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
18-
gfp_t gfp, unsigned long attrs)
19-
{
20-
unsigned long order = get_order(size);
21-
struct page *page;
22-
phys_addr_t paddr;
23-
void *kvaddr;
24-
bool need_coh = !(attrs & DMA_ATTR_NON_CONSISTENT);
25-
26-
/*
27-
* __GFP_HIGHMEM flag is cleared by upper layer functions
28-
* (in include/linux/dma-mapping.h) so we should never get a
29-
* __GFP_HIGHMEM here.
30-
*/
31-
BUG_ON(gfp & __GFP_HIGHMEM);
32-
33-
page = alloc_pages(gfp | __GFP_ZERO, order);
34-
if (!page)
35-
return NULL;
36-
37-
/* This is linear addr (0x8000_0000 based) */
38-
paddr = page_to_phys(page);
39-
40-
*dma_handle = paddr;
41-
42-
/*
43-
* A coherent buffer needs MMU mapping to enforce non-cachability.
44-
* kvaddr is kernel Virtual address (0x7000_0000 based).
45-
*/
46-
if (need_coh) {
47-
kvaddr = ioremap_nocache(paddr, size);
48-
if (kvaddr == NULL) {
49-
__free_pages(page, order);
50-
return NULL;
51-
}
52-
} else {
53-
kvaddr = (void *)(u32)paddr;
54-
}
5517

18+
void arch_dma_prep_coherent(struct page *page, size_t size)
19+
{
5620
/*
5721
* Evict any existing L1 and/or L2 lines for the backing page
5822
* in case it was used earlier as a normal "cached" page.
@@ -63,28 +27,7 @@ void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
6327
* Currently flush_cache_vmap nukes the L1 cache completely which
6428
* will be optimized as a separate commit
6529
*/
66-
if (need_coh)
67-
dma_cache_wback_inv(paddr, size);
68-
69-
return kvaddr;
70-
}
71-
72-
void arch_dma_free(struct device *dev, size_t size, void *vaddr,
73-
dma_addr_t dma_handle, unsigned long attrs)
74-
{
75-
phys_addr_t paddr = dma_handle;
76-
struct page *page = virt_to_page(paddr);
77-
78-
if (!(attrs & DMA_ATTR_NON_CONSISTENT))
79-
iounmap((void __force __iomem *)vaddr);
80-
81-
__free_pages(page, get_order(size));
82-
}
83-
84-
long arch_dma_coherent_to_pfn(struct device *dev, void *cpu_addr,
85-
dma_addr_t dma_addr)
86-
{
87-
return __phys_to_pfn(dma_addr);
30+
dma_cache_wback_inv(page_to_phys(page), size);
8831
}
8932

9033
/*
@@ -161,3 +104,9 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
161104
dev_info(dev, "use %sncoherent DMA ops\n",
162105
dev->dma_coherent ? "" : "non");
163106
}
107+
108+
static int __init atomic_pool_init(void)
109+
{
110+
return dma_atomic_pool_init(GFP_KERNEL, pgprot_noncached(PAGE_KERNEL));
111+
}
112+
postcore_initcall(atomic_pool_init);

‎arch/arm/mm/dma-mapping-nommu.c‎

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,7 @@ static void *arm_nommu_dma_alloc(struct device *dev, size_t size,
3535
unsigned long attrs)
3636

3737
{
38-
void *ret;
39-
40-
/*
41-
* Try generic allocator first if we are advertised that
42-
* consistency is not required.
43-
*/
44-
45-
if (attrs & DMA_ATTR_NON_CONSISTENT)
46-
return dma_direct_alloc_pages(dev, size, dma_handle, gfp,
47-
attrs);
48-
49-
ret = dma_alloc_from_global_coherent(size, dma_handle);
38+
void *ret = dma_alloc_from_global_coherent(size, dma_handle);
5039

5140
/*
5241
* dma_alloc_from_global_coherent() may fail because:
@@ -66,16 +55,9 @@ static void arm_nommu_dma_free(struct device *dev, size_t size,
6655
void *cpu_addr, dma_addr_t dma_addr,
6756
unsigned long attrs)
6857
{
69-
if (attrs & DMA_ATTR_NON_CONSISTENT) {
70-
dma_direct_free_pages(dev, size, cpu_addr, dma_addr, attrs);
71-
} else {
72-
int ret = dma_release_from_global_coherent(get_order(size),
73-
cpu_addr);
74-
75-
WARN_ON_ONCE(ret == 0);
76-
}
58+
int ret = dma_release_from_global_coherent(get_order(size), cpu_addr);
7759

78-
return;
60+
WARN_ON_ONCE(ret == 0);
7961
}
8062

8163
static int arm_nommu_dma_mmap(struct device *dev, struct vm_area_struct *vma,

‎arch/arm/mm/dma-mapping.c‎

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -216,25 +216,7 @@ EXPORT_SYMBOL(arm_coherent_dma_ops);
216216

217217
static int __dma_supported(struct device *dev, u64 mask, bool warn)
218218
{
219-
unsigned long max_dma_pfn;
220-
221-
/*
222-
* If the mask allows for more memory than we can address,
223-
* and we actually have that much memory, then we must
224-
* indicate that DMA to this device is not supported.
225-
*/
226-
if (sizeof(mask) != sizeof(dma_addr_t) &&
227-
mask > (dma_addr_t)~0 &&
228-
dma_to_pfn(dev, ~0) < max_pfn - 1) {
229-
if (warn) {
230-
dev_warn(dev, "Coherent DMA mask %#llx is larger than dma_addr_t allows\n",
231-
mask);
232-
dev_warn(dev, "Driver did not use or check the return value from dma_set_coherent_mask()?\n");
233-
}
234-
return 0;
235-
}
236-
237-
max_dma_pfn = min(max_pfn, arm_dma_pfn_limit);
219+
unsigned long max_dma_pfn = min(max_pfn, arm_dma_pfn_limit);
238220

239221
/*
240222
* Translate the device's DMA mask to a PFN limit. This

‎arch/mips/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,7 @@ config DMA_NONCOHERENT
11211121
bool
11221122
select ARCH_HAS_DMA_MMAP_PGPROT
11231123
select ARCH_HAS_SYNC_DMA_FOR_DEVICE
1124+
select ARCH_HAS_UNCACHED_SEGMENT
11241125
select NEED_DMA_MAP_STATE
11251126
select ARCH_HAS_DMA_COHERENT_TO_PFN
11261127
select DMA_NONCOHERENT_CACHE_SYNC

‎arch/mips/include/asm/page.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,6 @@ extern bool __virt_addr_valid(const volatile void *kaddr);
258258
((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
259259
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
260260

261-
#define UNCAC_ADDR(addr) (UNCAC_BASE + __pa(addr))
262-
#define CAC_ADDR(addr) ((unsigned long)__va((addr) - UNCAC_BASE))
263-
264261
#include <asm-generic/memory_model.h>
265262
#include <asm-generic/getorder.h>
266263

‎arch/mips/jazz/jazzdma.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -575,19 +575,13 @@ static void *jazz_dma_alloc(struct device *dev, size_t size,
575575
return NULL;
576576
}
577577

578-
if (!(attrs & DMA_ATTR_NON_CONSISTENT)) {
579-
dma_cache_wback_inv((unsigned long)ret, size);
580-
ret = (void *)UNCAC_ADDR(ret);
581-
}
582578
return ret;
583579
}
584580

585581
static void jazz_dma_free(struct device *dev, size_t size, void *vaddr,
586582
dma_addr_t dma_handle, unsigned long attrs)
587583
{
588584
vdma_free(dma_handle);
589-
if (!(attrs & DMA_ATTR_NON_CONSISTENT))
590-
vaddr = (void *)CAC_ADDR((unsigned long)vaddr);
591585
dma_direct_free_pages(dev, size, vaddr, dma_handle, attrs);
592586
}
593587

‎arch/mips/mm/cache.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ void (*_dma_cache_wback_inv)(unsigned long start, unsigned long size);
6262
void (*_dma_cache_wback)(unsigned long start, unsigned long size);
6363
void (*_dma_cache_inv)(unsigned long start, unsigned long size);
6464

65-
EXPORT_SYMBOL(_dma_cache_wback_inv);
66-
6765
#endif /* CONFIG_DMA_NONCOHERENT */
6866

6967
/*

‎arch/mips/mm/dma-noncoherent.c‎

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,33 +44,25 @@ static inline bool cpu_needs_post_dma_flush(struct device *dev)
4444
}
4545
}
4646

47-
void *arch_dma_alloc(struct device *dev, size_t size,
48-
dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs)
47+
void arch_dma_prep_coherent(struct page *page, size_t size)
4948
{
50-
void *ret;
51-
52-
ret = dma_direct_alloc_pages(dev, size, dma_handle, gfp, attrs);
53-
if (ret && !(attrs & DMA_ATTR_NON_CONSISTENT)) {
54-
dma_cache_wback_inv((unsigned long) ret, size);
55-
ret = (void *)UNCAC_ADDR(ret);
56-
}
49+
dma_cache_wback_inv((unsigned long)page_address(page), size);
50+
}
5751

58-
return ret;
52+
void *uncached_kernel_address(void *addr)
53+
{
54+
return (void *)(__pa(addr) + UNCAC_BASE);
5955
}
6056

61-
void arch_dma_free(struct device *dev, size_t size, void *cpu_addr,
62-
dma_addr_t dma_addr, unsigned long attrs)
57+
void *cached_kernel_address(void *addr)
6358
{
64-
if (!(attrs & DMA_ATTR_NON_CONSISTENT))
65-
cpu_addr = (void *)CAC_ADDR((unsigned long)cpu_addr);
66-
dma_direct_free_pages(dev, size, cpu_addr, dma_addr, attrs);
59+
return __va(addr) - UNCAC_BASE;
6760
}
6861

6962
long arch_dma_coherent_to_pfn(struct device *dev, void *cpu_addr,
7063
dma_addr_t dma_addr)
7164
{
72-
unsigned long addr = CAC_ADDR((unsigned long)cpu_addr);
73-
return page_to_pfn(virt_to_page((void *)addr));
65+
return page_to_pfn(virt_to_page(cached_kernel_address(cpu_addr)));
7466
}
7567

7668
pgprot_t arch_dma_mmap_pgprot(struct device *dev, pgprot_t prot,

0 commit comments

Comments
 (0)