Skip to content

Commit 2382dc9

Browse files
committed
Merge tag 'dma-mapping-4.16' of git://git.infradead.org/users/hch/dma-mapping
Pull dma mapping updates from Christoph Hellwig: "Except for a runtime warning fix from Christian this is all about consolidation of the generic no-IOMMU code, a well as the glue code for swiotlb. All the code is based on the x86 implementation with hooks to allow all architectures that aren't cache coherent to use it. The x86 conversion itself has been deferred because the x86 maintainers were a little busy in the last months" * tag 'dma-mapping-4.16' of git://git.infradead.org/users/hch/dma-mapping: (57 commits) MAINTAINERS: add the iommu list for swiotlb and xen-swiotlb arm64: use swiotlb_alloc and swiotlb_free arm64: replace ZONE_DMA with ZONE_DMA32 mips: use swiotlb_{alloc,free} mips/netlogic: remove swiotlb support tile: use generic swiotlb_ops tile: replace ZONE_DMA with ZONE_DMA32 unicore32: use generic swiotlb_ops ia64: remove an ifdef around the content of pci-dma.c ia64: clean up swiotlb support ia64: use generic swiotlb_ops ia64: replace ZONE_DMA with ZONE_DMA32 swiotlb: remove various exports swiotlb: refactor coherent buffer allocation swiotlb: refactor coherent buffer freeing swiotlb: wire up ->dma_supported in swiotlb_dma_ops swiotlb: add common swiotlb_map_ops swiotlb: rename swiotlb_free to swiotlb_exit x86: rename swiotlb_dma_ops powerpc: rename swiotlb_dma_ops ...
2 parents 28bc6fb + 04f5653 commit 2382dc9

File tree

119 files changed

+728
-1266
lines changed

Some content is hidden

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

119 files changed

+728
-1266
lines changed

MAINTAINERS

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4343,10 +4343,12 @@ T: git git://git.infradead.org/users/hch/dma-mapping.git
43434343
W: http://git.infradead.org/users/hch/dma-mapping.git
43444344
S: Supported
43454345
F: lib/dma-debug.c
4346-
F: lib/dma-noop.c
4346+
F: lib/dma-direct.c
43474347
F: lib/dma-virt.c
43484348
F: drivers/base/dma-mapping.c
43494349
F: drivers/base/dma-coherent.c
4350+
F: include/asm-generic/dma-mapping.h
4351+
F: include/linux/dma-direct.h
43504352
F: include/linux/dma-mapping.h
43514353

43524354
DME1737 HARDWARE MONITOR DRIVER
@@ -13071,7 +13073,7 @@ F: arch/x86/boot/video*
1307113073

1307213074
SWIOTLB SUBSYSTEM
1307313075
M: Konrad Rzeszutek Wilk <[email protected]>
13074-
13076+
1307513077
T: git git://git.kernel.org/pub/scm/linux/kernel/git/konrad/swiotlb.git
1307613078
S: Supported
1307713079
F: lib/swiotlb.c
@@ -15026,6 +15028,7 @@ F: include/xen/interface/io/vscsiif.h
1502615028
XEN SWIOTLB SUBSYSTEM
1502715029
M: Konrad Rzeszutek Wilk <[email protected]>
1502815030
L: [email protected] (moderated for non-subscribers)
15031+
1502915032
S: Supported
1503015033
F: arch/x86/xen/*swiotlb*
1503115034
F: drivers/xen/*swiotlb*

arch/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,10 @@ config STRICT_MODULE_RWX
938938
and non-text memory will be made non-executable. This provides
939939
protection against certain security exploits (e.g. writing to text)
940940

941+
# select if the architecture provides an asm/dma-direct.h header
942+
config ARCH_HAS_PHYS_TO_DMA
943+
bool
944+
941945
config ARCH_HAS_REFCOUNT
942946
bool
943947
help

arch/alpha/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ config ALPHA_EIGER
209209

210210
config ALPHA_JENSEN
211211
bool "Jensen"
212+
depends on BROKEN
212213
help
213214
DEC PC 150 AXP (aka Jensen): This is a very old Digital system - one
214215
of the first-generation Alpha systems. A number of these systems

arch/arc/Kconfig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,6 @@ config ARCH_PHYS_ADDR_T_64BIT
463463
config ARCH_DMA_ADDR_T_64BIT
464464
bool
465465

466-
config ARC_PLAT_NEEDS_PHYS_TO_DMA
467-
bool
468-
469466
config ARC_KVADDR_SIZE
470467
int "Kernel Virtual Address Space size (MB)"
471468
range 0 512

arch/arc/include/asm/dma-mapping.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@
1111
#ifndef ASM_ARC_DMA_MAPPING_H
1212
#define ASM_ARC_DMA_MAPPING_H
1313

14-
#ifndef CONFIG_ARC_PLAT_NEEDS_PHYS_TO_DMA
15-
#define plat_dma_to_phys(dev, dma_handle) ((phys_addr_t)(dma_handle))
16-
#define plat_phys_to_dma(dev, paddr) ((dma_addr_t)(paddr))
17-
#else
18-
#include <plat/dma.h>
19-
#endif
20-
2114
extern const struct dma_map_ops arc_dma_ops;
2215

2316
static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)

arch/arc/mm/dma.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static void *arc_dma_alloc(struct device *dev, size_t size,
6060
/* This is linear addr (0x8000_0000 based) */
6161
paddr = page_to_phys(page);
6262

63-
*dma_handle = plat_phys_to_dma(dev, paddr);
63+
*dma_handle = paddr;
6464

6565
/* This is kernel Virtual address (0x7000_0000 based) */
6666
if (need_kvaddr) {
@@ -92,7 +92,7 @@ static void *arc_dma_alloc(struct device *dev, size_t size,
9292
static void arc_dma_free(struct device *dev, size_t size, void *vaddr,
9393
dma_addr_t dma_handle, unsigned long attrs)
9494
{
95-
phys_addr_t paddr = plat_dma_to_phys(dev, dma_handle);
95+
phys_addr_t paddr = dma_handle;
9696
struct page *page = virt_to_page(paddr);
9797
int is_non_coh = 1;
9898

@@ -111,7 +111,7 @@ static int arc_dma_mmap(struct device *dev, struct vm_area_struct *vma,
111111
{
112112
unsigned long user_count = vma_pages(vma);
113113
unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
114-
unsigned long pfn = __phys_to_pfn(plat_dma_to_phys(dev, dma_addr));
114+
unsigned long pfn = __phys_to_pfn(dma_addr);
115115
unsigned long off = vma->vm_pgoff;
116116
int ret = -ENXIO;
117117

@@ -175,7 +175,7 @@ static dma_addr_t arc_dma_map_page(struct device *dev, struct page *page,
175175
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
176176
_dma_cache_sync(paddr, size, dir);
177177

178-
return plat_phys_to_dma(dev, paddr);
178+
return paddr;
179179
}
180180

181181
/*
@@ -190,7 +190,7 @@ static void arc_dma_unmap_page(struct device *dev, dma_addr_t handle,
190190
size_t size, enum dma_data_direction dir,
191191
unsigned long attrs)
192192
{
193-
phys_addr_t paddr = plat_dma_to_phys(dev, handle);
193+
phys_addr_t paddr = handle;
194194

195195
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
196196
_dma_cache_sync(paddr, size, dir);
@@ -224,13 +224,13 @@ static void arc_dma_unmap_sg(struct device *dev, struct scatterlist *sg,
224224
static void arc_dma_sync_single_for_cpu(struct device *dev,
225225
dma_addr_t dma_handle, size_t size, enum dma_data_direction dir)
226226
{
227-
_dma_cache_sync(plat_dma_to_phys(dev, dma_handle), size, DMA_FROM_DEVICE);
227+
_dma_cache_sync(dma_handle, size, DMA_FROM_DEVICE);
228228
}
229229

230230
static void arc_dma_sync_single_for_device(struct device *dev,
231231
dma_addr_t dma_handle, size_t size, enum dma_data_direction dir)
232232
{
233-
_dma_cache_sync(plat_dma_to_phys(dev, dma_handle), size, DMA_TO_DEVICE);
233+
_dma_cache_sync(dma_handle, size, DMA_TO_DEVICE);
234234
}
235235

236236
static void arc_dma_sync_sg_for_cpu(struct device *dev,

arch/arm/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ config ARM
88
select ARCH_HAS_DEVMEM_IS_ALLOWED
99
select ARCH_HAS_ELF_RANDOMIZE
1010
select ARCH_HAS_SET_MEMORY
11+
select ARCH_HAS_PHYS_TO_DMA
1112
select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL
1213
select ARCH_HAS_STRICT_MODULE_RWX if MMU
1314
select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
@@ -24,7 +25,7 @@ config ARM
2425
select CLONE_BACKWARDS
2526
select CPU_PM if (SUSPEND || CPU_IDLE)
2627
select DCACHE_WORD_ACCESS if HAVE_EFFICIENT_UNALIGNED_ACCESS
27-
select DMA_NOOP_OPS if !MMU
28+
select DMA_DIRECT_OPS if !MMU
2829
select EDAC_SUPPORT
2930
select EDAC_ATOMIC_SCRUB
3031
select GENERIC_ALLOCATOR

arch/arm/include/asm/dma-direct.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef ASM_ARM_DMA_DIRECT_H
3+
#define ASM_ARM_DMA_DIRECT_H 1
4+
5+
static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
6+
{
7+
unsigned int offset = paddr & ~PAGE_MASK;
8+
return pfn_to_dma(dev, __phys_to_pfn(paddr)) + offset;
9+
}
10+
11+
static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
12+
{
13+
unsigned int offset = dev_addr & ~PAGE_MASK;
14+
return __pfn_to_phys(dma_to_pfn(dev, dev_addr)) + offset;
15+
}
16+
17+
static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
18+
{
19+
u64 limit, mask;
20+
21+
if (!dev->dma_mask)
22+
return 0;
23+
24+
mask = *dev->dma_mask;
25+
26+
limit = (mask + 1) & ~mask;
27+
if (limit && size > limit)
28+
return 0;
29+
30+
if ((addr | (addr + size - 1)) & ~mask)
31+
return 0;
32+
33+
return 1;
34+
}
35+
36+
#endif /* ASM_ARM_DMA_DIRECT_H */

arch/arm/include/asm/dma-mapping.h

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern const struct dma_map_ops arm_coherent_dma_ops;
1818

1919
static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
2020
{
21-
return IS_ENABLED(CONFIG_MMU) ? &arm_dma_ops : &dma_noop_ops;
21+
return IS_ENABLED(CONFIG_MMU) ? &arm_dma_ops : &dma_direct_ops;
2222
}
2323

2424
#ifdef __arch_page_to_dma
@@ -109,39 +109,6 @@ static inline bool is_device_dma_coherent(struct device *dev)
109109
return dev->archdata.dma_coherent;
110110
}
111111

112-
static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
113-
{
114-
unsigned int offset = paddr & ~PAGE_MASK;
115-
return pfn_to_dma(dev, __phys_to_pfn(paddr)) + offset;
116-
}
117-
118-
static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
119-
{
120-
unsigned int offset = dev_addr & ~PAGE_MASK;
121-
return __pfn_to_phys(dma_to_pfn(dev, dev_addr)) + offset;
122-
}
123-
124-
static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
125-
{
126-
u64 limit, mask;
127-
128-
if (!dev->dma_mask)
129-
return 0;
130-
131-
mask = *dev->dma_mask;
132-
133-
limit = (mask + 1) & ~mask;
134-
if (limit && size > limit)
135-
return 0;
136-
137-
if ((addr | (addr + size - 1)) & ~mask)
138-
return 0;
139-
140-
return 1;
141-
}
142-
143-
static inline void dma_mark_clean(void *addr, size_t size) { }
144-
145112
/**
146113
* arm_dma_alloc - allocate consistent memory for DMA
147114
* @dev: valid struct device pointer, or NULL for ISA and EISA-like devices

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include <linux/export.h>
1313
#include <linux/mm.h>
14-
#include <linux/dma-mapping.h>
14+
#include <linux/dma-direct.h>
1515
#include <linux/scatterlist.h>
1616

1717
#include <asm/cachetype.h>
@@ -22,7 +22,7 @@
2222
#include "dma.h"
2323

2424
/*
25-
* dma_noop_ops is used if
25+
* dma_direct_ops is used if
2626
* - MMU/MPU is off
2727
* - cpu is v7m w/o cache support
2828
* - device is coherent
@@ -39,7 +39,6 @@ static void *arm_nommu_dma_alloc(struct device *dev, size_t size,
3939
unsigned long attrs)
4040

4141
{
42-
const struct dma_map_ops *ops = &dma_noop_ops;
4342
void *ret;
4443

4544
/*
@@ -48,7 +47,7 @@ static void *arm_nommu_dma_alloc(struct device *dev, size_t size,
4847
*/
4948

5049
if (attrs & DMA_ATTR_NON_CONSISTENT)
51-
return ops->alloc(dev, size, dma_handle, gfp, attrs);
50+
return dma_direct_alloc(dev, size, dma_handle, gfp, attrs);
5251

5352
ret = dma_alloc_from_global_coherent(size, dma_handle);
5453

@@ -70,10 +69,8 @@ static void arm_nommu_dma_free(struct device *dev, size_t size,
7069
void *cpu_addr, dma_addr_t dma_addr,
7170
unsigned long attrs)
7271
{
73-
const struct dma_map_ops *ops = &dma_noop_ops;
74-
7572
if (attrs & DMA_ATTR_NON_CONSISTENT) {
76-
ops->free(dev, size, cpu_addr, dma_addr, attrs);
73+
dma_direct_free(dev, size, cpu_addr, dma_addr, attrs);
7774
} else {
7875
int ret = dma_release_from_global_coherent(get_order(size),
7976
cpu_addr);
@@ -213,7 +210,7 @@ EXPORT_SYMBOL(arm_nommu_dma_ops);
213210

214211
static const struct dma_map_ops *arm_nommu_get_dma_map_ops(bool coherent)
215212
{
216-
return coherent ? &dma_noop_ops : &arm_nommu_dma_ops;
213+
return coherent ? &dma_direct_ops : &arm_nommu_dma_ops;
217214
}
218215

219216
void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,

arch/arm64/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ config ARM64
5959
select COMMON_CLK
6060
select CPU_PM if (SUSPEND || CPU_IDLE)
6161
select DCACHE_WORD_ACCESS
62+
select DMA_DIRECT_OPS
6263
select EDAC_SUPPORT
6364
select FRAME_POINTER
6465
select GENERIC_ALLOCATOR
@@ -227,7 +228,7 @@ config GENERIC_CSUM
227228
config GENERIC_CALIBRATE_DELAY
228229
def_bool y
229230

230-
config ZONE_DMA
231+
config ZONE_DMA32
231232
def_bool y
232233

233234
config HAVE_GENERIC_GUP

arch/arm64/include/asm/dma-mapping.h

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -50,40 +50,5 @@ static inline bool is_device_dma_coherent(struct device *dev)
5050
return dev->archdata.dma_coherent;
5151
}
5252

53-
static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
54-
{
55-
dma_addr_t dev_addr = (dma_addr_t)paddr;
56-
57-
return dev_addr - ((dma_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
58-
}
59-
60-
static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
61-
{
62-
phys_addr_t paddr = (phys_addr_t)dev_addr;
63-
64-
return paddr + ((phys_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
65-
}
66-
67-
static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
68-
{
69-
if (!dev->dma_mask)
70-
return false;
71-
72-
return addr + size - 1 <= *dev->dma_mask;
73-
}
74-
75-
static inline void dma_mark_clean(void *addr, size_t size)
76-
{
77-
}
78-
79-
/* Override for dma_max_pfn() */
80-
static inline unsigned long dma_max_pfn(struct device *dev)
81-
{
82-
dma_addr_t dma_max = (dma_addr_t)*dev->dma_mask;
83-
84-
return (ulong)dma_to_phys(dev, dma_max) >> PAGE_SHIFT;
85-
}
86-
#define dma_max_pfn(dev) dma_max_pfn(dev)
87-
8853
#endif /* __KERNEL__ */
8954
#endif /* __ASM_DMA_MAPPING_H */

0 commit comments

Comments
 (0)