Skip to content

Commit 58bca4a

Browse files
committed
Merge branch 'for-linus' of git://git.linaro.org/people/mszyprowski/linux-dma-mapping
Pull DMA mapping branch from Marek Szyprowski: "Short summary for the whole series: A few limitations have been identified in the current dma-mapping design and its implementations for various architectures. There exist more than one function for allocating and freeing the buffers: currently these 3 are used dma_{alloc, free}_coherent, dma_{alloc,free}_writecombine, dma_{alloc,free}_noncoherent. For most of the systems these calls are almost equivalent and can be interchanged. For others, especially the truly non-coherent ones (like ARM), the difference can be easily noticed in overall driver performance. Sadly not all architectures provide implementations for all of them, so the drivers might need to be adapted and cannot be easily shared between different architectures. The provided patches unify all these functions and hide the differences under the already existing dma attributes concept. The thread with more references is available here: http://www.spinics.net/lists/linux-sh/msg09777.html These patches are also a prerequisite for unifying DMA-mapping implementation on ARM architecture with the common one provided by dma_map_ops structure and extending it with IOMMU support. More information is available in the following thread: http://thread.gmane.org/gmane.linux.kernel.cross-arch/12819 More works on dma-mapping framework are planned, especially in the area of buffer sharing and managing the shared mappings (together with the recently introduced dma_buf interface: commit d15bd7e "dma-buf: Introduce dma buffer sharing mechanism"). The patches in the current set introduce a new alloc/free methods (with support for memory attributes) in dma_map_ops structure, which will later replace dma_alloc_coherent and dma_alloc_writecombine functions." People finally started piping up with support for merging this, so I'm merging it as the last of the pending stuff from the merge window. Looks like pohmelfs is going to wait for 3.5 and more external support for merging. * 'for-linus' of git://git.linaro.org/people/mszyprowski/linux-dma-mapping: common: DMA-mapping: add NON-CONSISTENT attribute common: DMA-mapping: add WRITE_COMBINE attribute common: dma-mapping: introduce mmap method common: dma-mapping: remove old alloc_coherent and free_coherent methods Hexagon: adapt for dma_map_ops changes Unicore32: adapt for dma_map_ops changes Microblaze: adapt for dma_map_ops changes SH: adapt for dma_map_ops changes Alpha: adapt for dma_map_ops changes SPARC: adapt for dma_map_ops changes PowerPC: adapt for dma_map_ops changes MIPS: adapt for dma_map_ops changes X86 & IA64: adapt for dma_map_ops changes common: dma-mapping: introduce generic alloc() and free() methods
2 parents 64ebe98 + 64d70fe commit 58bca4a

45 files changed

Lines changed: 354 additions & 198 deletions

File tree

Some content is hidden

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

‎Documentation/DMA-attributes.txt‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,21 @@ may be weakly ordered, that is that reads and writes may pass each other.
3131
Since it is optional for platforms to implement DMA_ATTR_WEAK_ORDERING,
3232
those that do not will simply ignore the attribute and exhibit default
3333
behavior.
34+
35+
DMA_ATTR_WRITE_COMBINE
36+
----------------------
37+
38+
DMA_ATTR_WRITE_COMBINE specifies that writes to the mapping may be
39+
buffered to improve performance.
40+
41+
Since it is optional for platforms to implement DMA_ATTR_WRITE_COMBINE,
42+
those that do not will simply ignore the attribute and exhibit default
43+
behavior.
44+
45+
DMA_ATTR_NON_CONSISTENT
46+
-----------------------
47+
48+
DMA_ATTR_NON_CONSISTENT lets the platform to choose to return either
49+
consistent or non-consistent memory as it sees fit. By using this API,
50+
you are guaranteeing to the platform that you have all the correct and
51+
necessary sync points for this memory in the driver.

‎arch/alpha/include/asm/dma-mapping.h‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,22 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
1212

1313
#include <asm-generic/dma-mapping-common.h>
1414

15-
static inline void *dma_alloc_coherent(struct device *dev, size_t size,
16-
dma_addr_t *dma_handle, gfp_t gfp)
15+
#define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
16+
17+
static inline void *dma_alloc_attrs(struct device *dev, size_t size,
18+
dma_addr_t *dma_handle, gfp_t gfp,
19+
struct dma_attrs *attrs)
1720
{
18-
return get_dma_ops(dev)->alloc_coherent(dev, size, dma_handle, gfp);
21+
return get_dma_ops(dev)->alloc(dev, size, dma_handle, gfp, attrs);
1922
}
2023

21-
static inline void dma_free_coherent(struct device *dev, size_t size,
22-
void *vaddr, dma_addr_t dma_handle)
24+
#define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
25+
26+
static inline void dma_free_attrs(struct device *dev, size_t size,
27+
void *vaddr, dma_addr_t dma_handle,
28+
struct dma_attrs *attrs)
2329
{
24-
get_dma_ops(dev)->free_coherent(dev, size, vaddr, dma_handle);
30+
get_dma_ops(dev)->free(dev, size, vaddr, dma_handle, attrs);
2531
}
2632

2733
static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)

‎arch/alpha/kernel/pci-noop.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ sys_pciconfig_write(unsigned long bus, unsigned long dfn,
108108
}
109109

110110
static void *alpha_noop_alloc_coherent(struct device *dev, size_t size,
111-
dma_addr_t *dma_handle, gfp_t gfp)
111+
dma_addr_t *dma_handle, gfp_t gfp,
112+
struct dma_attrs *attrs)
112113
{
113114
void *ret;
114115

@@ -123,7 +124,8 @@ static void *alpha_noop_alloc_coherent(struct device *dev, size_t size,
123124
}
124125

125126
static void alpha_noop_free_coherent(struct device *dev, size_t size,
126-
void *cpu_addr, dma_addr_t dma_addr)
127+
void *cpu_addr, dma_addr_t dma_addr,
128+
struct dma_attrs *attrs)
127129
{
128130
free_pages((unsigned long)cpu_addr, get_order(size));
129131
}
@@ -174,8 +176,8 @@ static int alpha_noop_set_mask(struct device *dev, u64 mask)
174176
}
175177

176178
struct dma_map_ops alpha_noop_ops = {
177-
.alloc_coherent = alpha_noop_alloc_coherent,
178-
.free_coherent = alpha_noop_free_coherent,
179+
.alloc = alpha_noop_alloc_coherent,
180+
.free = alpha_noop_free_coherent,
179181
.map_page = alpha_noop_map_page,
180182
.map_sg = alpha_noop_map_sg,
181183
.mapping_error = alpha_noop_mapping_error,

‎arch/alpha/kernel/pci_iommu.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ static void alpha_pci_unmap_page(struct device *dev, dma_addr_t dma_addr,
434434
else DMA_ADDRP is undefined. */
435435

436436
static void *alpha_pci_alloc_coherent(struct device *dev, size_t size,
437-
dma_addr_t *dma_addrp, gfp_t gfp)
437+
dma_addr_t *dma_addrp, gfp_t gfp,
438+
struct dma_attrs *attrs)
438439
{
439440
struct pci_dev *pdev = alpha_gendev_to_pci(dev);
440441
void *cpu_addr;
@@ -478,7 +479,8 @@ static void *alpha_pci_alloc_coherent(struct device *dev, size_t size,
478479
DMA_ADDR past this call are illegal. */
479480

480481
static void alpha_pci_free_coherent(struct device *dev, size_t size,
481-
void *cpu_addr, dma_addr_t dma_addr)
482+
void *cpu_addr, dma_addr_t dma_addr,
483+
struct dma_attrs *attrs)
482484
{
483485
struct pci_dev *pdev = alpha_gendev_to_pci(dev);
484486
pci_unmap_single(pdev, dma_addr, size, PCI_DMA_BIDIRECTIONAL);
@@ -952,8 +954,8 @@ static int alpha_pci_set_mask(struct device *dev, u64 mask)
952954
}
953955

954956
struct dma_map_ops alpha_pci_ops = {
955-
.alloc_coherent = alpha_pci_alloc_coherent,
956-
.free_coherent = alpha_pci_free_coherent,
957+
.alloc = alpha_pci_alloc_coherent,
958+
.free = alpha_pci_free_coherent,
957959
.map_page = alpha_pci_map_page,
958960
.unmap_page = alpha_pci_unmap_page,
959961
.map_sg = alpha_pci_map_sg,

‎arch/hexagon/include/asm/dma-mapping.h‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,29 +71,35 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
7171
return (dma_addr == bad_dma_address);
7272
}
7373

74-
static inline void *dma_alloc_coherent(struct device *dev, size_t size,
75-
dma_addr_t *dma_handle, gfp_t flag)
74+
#define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
75+
76+
static inline void *dma_alloc_attrs(struct device *dev, size_t size,
77+
dma_addr_t *dma_handle, gfp_t flag,
78+
struct dma_attrs *attrs)
7679
{
7780
void *ret;
7881
struct dma_map_ops *ops = get_dma_ops(dev);
7982

8083
BUG_ON(!dma_ops);
8184

82-
ret = ops->alloc_coherent(dev, size, dma_handle, flag);
85+
ret = ops->alloc(dev, size, dma_handle, flag, attrs);
8386

8487
debug_dma_alloc_coherent(dev, size, *dma_handle, ret);
8588

8689
return ret;
8790
}
8891

89-
static inline void dma_free_coherent(struct device *dev, size_t size,
90-
void *cpu_addr, dma_addr_t dma_handle)
92+
#define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
93+
94+
static inline void dma_free_attrs(struct device *dev, size_t size,
95+
void *cpu_addr, dma_addr_t dma_handle,
96+
struct dma_attrs *attrs)
9197
{
9298
struct dma_map_ops *dma_ops = get_dma_ops(dev);
9399

94100
BUG_ON(!dma_ops);
95101

96-
dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
102+
dma_ops->free(dev, size, cpu_addr, dma_handle, attrs);
97103

98104
debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
99105
}

‎arch/hexagon/kernel/dma.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ static struct gen_pool *coherent_pool;
5454
/* Allocates from a pool of uncached memory that was reserved at boot time */
5555

5656
void *hexagon_dma_alloc_coherent(struct device *dev, size_t size,
57-
dma_addr_t *dma_addr, gfp_t flag)
57+
dma_addr_t *dma_addr, gfp_t flag,
58+
struct dma_attrs *attrs)
5859
{
5960
void *ret;
6061

@@ -81,7 +82,7 @@ void *hexagon_dma_alloc_coherent(struct device *dev, size_t size,
8182
}
8283

8384
static void hexagon_free_coherent(struct device *dev, size_t size, void *vaddr,
84-
dma_addr_t dma_addr)
85+
dma_addr_t dma_addr, struct dma_attrs *attrs)
8586
{
8687
gen_pool_free(coherent_pool, (unsigned long) vaddr, size);
8788
}
@@ -202,8 +203,8 @@ static void hexagon_sync_single_for_device(struct device *dev,
202203
}
203204

204205
struct dma_map_ops hexagon_dma_ops = {
205-
.alloc_coherent = hexagon_dma_alloc_coherent,
206-
.free_coherent = hexagon_free_coherent,
206+
.alloc = hexagon_dma_alloc_coherent,
207+
.free = hexagon_free_coherent,
207208
.map_sg = hexagon_map_sg,
208209
.map_page = hexagon_map_page,
209210
.sync_single_for_cpu = hexagon_sync_single_for_cpu,

‎arch/ia64/hp/common/sba_iommu.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,8 @@ void sba_unmap_single_attrs(struct device *dev, dma_addr_t iova, size_t size,
11291129
* See Documentation/DMA-API-HOWTO.txt
11301130
*/
11311131
static void *
1132-
sba_alloc_coherent (struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t flags)
1132+
sba_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
1133+
gfp_t flags, struct dma_attrs *attrs)
11331134
{
11341135
struct ioc *ioc;
11351136
void *addr;
@@ -1191,8 +1192,8 @@ sba_alloc_coherent (struct device *dev, size_t size, dma_addr_t *dma_handle, gfp
11911192
*
11921193
* See Documentation/DMA-API-HOWTO.txt
11931194
*/
1194-
static void sba_free_coherent (struct device *dev, size_t size, void *vaddr,
1195-
dma_addr_t dma_handle)
1195+
static void sba_free_coherent(struct device *dev, size_t size, void *vaddr,
1196+
dma_addr_t dma_handle, struct dma_attrs *attrs)
11961197
{
11971198
sba_unmap_single_attrs(dev, dma_handle, size, 0, NULL);
11981199
free_pages((unsigned long) vaddr, get_order(size));
@@ -2212,8 +2213,8 @@ sba_page_override(char *str)
22122213
__setup("sbapagesize=",sba_page_override);
22132214

22142215
struct dma_map_ops sba_dma_ops = {
2215-
.alloc_coherent = sba_alloc_coherent,
2216-
.free_coherent = sba_free_coherent,
2216+
.alloc = sba_alloc_coherent,
2217+
.free = sba_free_coherent,
22172218
.map_page = sba_map_page,
22182219
.unmap_page = sba_unmap_page,
22192220
.map_sg = sba_map_sg_attrs,

‎arch/ia64/include/asm/dma-mapping.h‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,29 @@ extern void machvec_dma_sync_single(struct device *, dma_addr_t, size_t,
2323
extern void machvec_dma_sync_sg(struct device *, struct scatterlist *, int,
2424
enum dma_data_direction);
2525

26-
static inline void *dma_alloc_coherent(struct device *dev, size_t size,
27-
dma_addr_t *daddr, gfp_t gfp)
26+
#define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
27+
28+
static inline void *dma_alloc_attrs(struct device *dev, size_t size,
29+
dma_addr_t *daddr, gfp_t gfp,
30+
struct dma_attrs *attrs)
2831
{
2932
struct dma_map_ops *ops = platform_dma_get_ops(dev);
3033
void *caddr;
3134

32-
caddr = ops->alloc_coherent(dev, size, daddr, gfp);
35+
caddr = ops->alloc(dev, size, daddr, gfp, attrs);
3336
debug_dma_alloc_coherent(dev, size, *daddr, caddr);
3437
return caddr;
3538
}
3639

37-
static inline void dma_free_coherent(struct device *dev, size_t size,
38-
void *caddr, dma_addr_t daddr)
40+
#define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
41+
42+
static inline void dma_free_attrs(struct device *dev, size_t size,
43+
void *caddr, dma_addr_t daddr,
44+
struct dma_attrs *attrs)
3945
{
4046
struct dma_map_ops *ops = platform_dma_get_ops(dev);
4147
debug_dma_free_coherent(dev, size, caddr, daddr);
42-
ops->free_coherent(dev, size, caddr, daddr);
48+
ops->free(dev, size, caddr, daddr, attrs);
4349
}
4450

4551
#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)

‎arch/ia64/kernel/pci-swiotlb.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,24 @@ int swiotlb __read_mostly;
1515
EXPORT_SYMBOL(swiotlb);
1616

1717
static void *ia64_swiotlb_alloc_coherent(struct device *dev, size_t size,
18-
dma_addr_t *dma_handle, gfp_t gfp)
18+
dma_addr_t *dma_handle, gfp_t gfp,
19+
struct dma_attrs *attrs)
1920
{
2021
if (dev->coherent_dma_mask != DMA_BIT_MASK(64))
2122
gfp |= GFP_DMA;
2223
return swiotlb_alloc_coherent(dev, size, dma_handle, gfp);
2324
}
2425

26+
static void ia64_swiotlb_free_coherent(struct device *dev, size_t size,
27+
void *vaddr, dma_addr_t dma_addr,
28+
struct dma_attrs *attrs)
29+
{
30+
swiotlb_free_coherent(dev, size, vaddr, dma_addr);
31+
}
32+
2533
struct dma_map_ops swiotlb_dma_ops = {
26-
.alloc_coherent = ia64_swiotlb_alloc_coherent,
27-
.free_coherent = swiotlb_free_coherent,
34+
.alloc = ia64_swiotlb_alloc_coherent,
35+
.free = ia64_swiotlb_free_coherent,
2836
.map_page = swiotlb_map_page,
2937
.unmap_page = swiotlb_unmap_page,
3038
.map_sg = swiotlb_map_sg_attrs,

‎arch/ia64/sn/pci/pci_dma.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ EXPORT_SYMBOL(sn_dma_set_mask);
7676
* more information.
7777
*/
7878
static void *sn_dma_alloc_coherent(struct device *dev, size_t size,
79-
dma_addr_t * dma_handle, gfp_t flags)
79+
dma_addr_t * dma_handle, gfp_t flags,
80+
struct dma_attrs *attrs)
8081
{
8182
void *cpuaddr;
8283
unsigned long phys_addr;
@@ -137,7 +138,7 @@ static void *sn_dma_alloc_coherent(struct device *dev, size_t size,
137138
* any associated IOMMU mappings.
138139
*/
139140
static void sn_dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
140-
dma_addr_t dma_handle)
141+
dma_addr_t dma_handle, struct dma_attrs *attrs)
141142
{
142143
struct pci_dev *pdev = to_pci_dev(dev);
143144
struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev);
@@ -466,8 +467,8 @@ int sn_pci_legacy_write(struct pci_bus *bus, u16 port, u32 val, u8 size)
466467
}
467468

468469
static struct dma_map_ops sn_dma_ops = {
469-
.alloc_coherent = sn_dma_alloc_coherent,
470-
.free_coherent = sn_dma_free_coherent,
470+
.alloc = sn_dma_alloc_coherent,
471+
.free = sn_dma_free_coherent,
471472
.map_page = sn_dma_map_page,
472473
.unmap_page = sn_dma_unmap_page,
473474
.map_sg = sn_dma_map_sg,

0 commit comments

Comments
 (0)