Skip to content

Commit 754c780

Browse files
committed
Merge branch 'for-v3.18' of git://git.linaro.org/people/mszyprowski/linux-dma-mapping
Pull dma-mapping update from Marek Szyprowski: "Provide the dma write coherent api (available previously on ARM architecture) for all other architectures, which use dma_ops-based dma mapping implementation. This lets one to use the same code in the device drivers regardless of the selected architecture" * 'for-v3.18' of git://git.linaro.org/people/mszyprowski/linux-dma-mapping: dma-mapping: Provide write-combine allocations s390: Implement dma_{alloc,free}_attrs()
2 parents 40c4326 + b4bbb10 commit 754c780

5 files changed

Lines changed: 48 additions & 38 deletions

File tree

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -265,22 +265,6 @@ extern int arm_dma_mmap(struct device *dev, struct vm_area_struct *vma,
265265
void *cpu_addr, dma_addr_t dma_addr, size_t size,
266266
struct dma_attrs *attrs);
267267

268-
static inline void *dma_alloc_writecombine(struct device *dev, size_t size,
269-
dma_addr_t *dma_handle, gfp_t flag)
270-
{
271-
DEFINE_DMA_ATTRS(attrs);
272-
dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs);
273-
return dma_alloc_attrs(dev, size, dma_handle, flag, &attrs);
274-
}
275-
276-
static inline void dma_free_writecombine(struct device *dev, size_t size,
277-
void *cpu_addr, dma_addr_t dma_handle)
278-
{
279-
DEFINE_DMA_ATTRS(attrs);
280-
dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs);
281-
return dma_free_attrs(dev, size, cpu_addr, dma_handle, &attrs);
282-
}
283-
284268
/*
285269
* This can be called during early boot to increase the size of the atomic
286270
* coherent DMA pool above the default value of 256KiB. It must be called

‎arch/s390/Kconfig‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,8 @@ config QDIO
496496

497497
menuconfig PCI
498498
bool "PCI support"
499-
default n
500499
depends on 64BIT
500+
select HAVE_DMA_ATTRS
501501
select PCI_MSI
502502
help
503503
Enable PCI support.
@@ -544,9 +544,6 @@ config HAS_DMA
544544
config NEED_SG_DMA_LENGTH
545545
def_bool PCI
546546

547-
config HAVE_DMA_ATTRS
548-
def_bool PCI
549-
550547
config NEED_DMA_MAP_STATE
551548
def_bool PCI
552549

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,35 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
5656
return dma_addr == DMA_ERROR_CODE;
5757
}
5858

59-
static inline void *dma_alloc_coherent(struct device *dev, size_t size,
60-
dma_addr_t *dma_handle, gfp_t flag)
59+
#define dma_alloc_coherent(d, s, h, f) dma_alloc_attrs(d, s, h, f, NULL)
60+
61+
static inline void *dma_alloc_attrs(struct device *dev, size_t size,
62+
dma_addr_t *dma_handle, gfp_t flags,
63+
struct dma_attrs *attrs)
6164
{
6265
struct dma_map_ops *ops = get_dma_ops(dev);
63-
void *ret;
66+
void *cpu_addr;
67+
68+
BUG_ON(!ops);
6469

65-
ret = ops->alloc(dev, size, dma_handle, flag, NULL);
66-
debug_dma_alloc_coherent(dev, size, *dma_handle, ret);
67-
return ret;
70+
cpu_addr = ops->alloc(dev, size, dma_handle, flags, attrs);
71+
debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr);
72+
73+
return cpu_addr;
6874
}
6975

70-
static inline void dma_free_coherent(struct device *dev, size_t size,
71-
void *cpu_addr, dma_addr_t dma_handle)
76+
#define dma_free_coherent(d, s, c, h) dma_free_attrs(d, s, c, h, NULL)
77+
78+
static inline void dma_free_attrs(struct device *dev, size_t size,
79+
void *cpu_addr, dma_addr_t dma_handle,
80+
struct dma_attrs *attrs)
7281
{
73-
struct dma_map_ops *dma_ops = get_dma_ops(dev);
82+
struct dma_map_ops *ops = get_dma_ops(dev);
83+
84+
BUG_ON(!ops);
7485

7586
debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
76-
dma_ops->free(dev, size, cpu_addr, dma_handle, NULL);
87+
ops->free(dev, size, cpu_addr, dma_handle, attrs);
7788
}
7889

7990
#endif /* _ASM_S390_DMA_MAPPING_H */

‎include/asm-generic/dma-mapping-common.h‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,6 @@ dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma, void *cpu_addr,
214214

215215
#define dma_mmap_coherent(d, v, c, h, s) dma_mmap_attrs(d, v, c, h, s, NULL)
216216

217-
static inline int dma_mmap_writecombine(struct device *dev, struct vm_area_struct *vma,
218-
void *cpu_addr, dma_addr_t dma_addr, size_t size)
219-
{
220-
DEFINE_DMA_ATTRS(attrs);
221-
dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs);
222-
return dma_mmap_attrs(dev, vma, cpu_addr, dma_addr, size, &attrs);
223-
}
224-
225217
int
226218
dma_common_get_sgtable(struct device *dev, struct sg_table *sgt,
227219
void *cpu_addr, dma_addr_t dma_addr, size_t size);

‎include/linux/dma-mapping.h‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,32 @@ struct dma_attrs;
263263
#define dma_unmap_sg_attrs(dev, sgl, nents, dir, attrs) \
264264
dma_unmap_sg(dev, sgl, nents, dir)
265265

266+
#else
267+
static inline void *dma_alloc_writecombine(struct device *dev, size_t size,
268+
dma_addr_t *dma_addr, gfp_t gfp)
269+
{
270+
DEFINE_DMA_ATTRS(attrs);
271+
dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs);
272+
return dma_alloc_attrs(dev, size, dma_addr, gfp, &attrs);
273+
}
274+
275+
static inline void dma_free_writecombine(struct device *dev, size_t size,
276+
void *cpu_addr, dma_addr_t dma_addr)
277+
{
278+
DEFINE_DMA_ATTRS(attrs);
279+
dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs);
280+
return dma_free_attrs(dev, size, cpu_addr, dma_addr, &attrs);
281+
}
282+
283+
static inline int dma_mmap_writecombine(struct device *dev,
284+
struct vm_area_struct *vma,
285+
void *cpu_addr, dma_addr_t dma_addr,
286+
size_t size)
287+
{
288+
DEFINE_DMA_ATTRS(attrs);
289+
dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs);
290+
return dma_mmap_attrs(dev, vma, cpu_addr, dma_addr, size, &attrs);
291+
}
266292
#endif /* CONFIG_HAVE_DMA_ATTRS */
267293

268294
#ifdef CONFIG_NEED_DMA_MAP_STATE

0 commit comments

Comments
 (0)