Skip to content

Commit 6f51f51

Browse files
committed
Merge branch 'for-linus-for-3.6-rc1' of git://git.linaro.org/people/mszyprowski/linux-dma-mapping
Pull DMA-mapping updates from Marek Szyprowski: "Those patches are continuation of my earlier work. They contains extensions to DMA-mapping framework to remove limitation of the current ARM implementation (like limited total size of DMA coherent/write combine buffers), improve performance of buffer sharing between devices (attributes to skip cpu cache operations or creation of additional kernel mapping for some specific use cases) as well as some unification of the common code for dma_mmap_attrs() and dma_mmap_coherent() functions. All extensions have been implemented and tested for ARM architecture." * 'for-linus-for-3.6-rc1' of git://git.linaro.org/people/mszyprowski/linux-dma-mapping: ARM: dma-mapping: add support for DMA_ATTR_SKIP_CPU_SYNC attribute common: DMA-mapping: add DMA_ATTR_SKIP_CPU_SYNC attribute ARM: dma-mapping: add support for dma_get_sgtable() common: dma-mapping: introduce dma_get_sgtable() function ARM: dma-mapping: add support for DMA_ATTR_NO_KERNEL_MAPPING attribute common: DMA-mapping: add DMA_ATTR_NO_KERNEL_MAPPING attribute common: dma-mapping: add support for generic dma_mmap_* calls ARM: dma-mapping: fix error path for memory allocation failure ARM: dma-mapping: add more sanity checks in arm_dma_mmap() ARM: dma-mapping: remove custom consistent dma region mm: vmalloc: use const void * for caller argument scatterlist: add sg_alloc_table_from_pages function
2 parents 76159c2 + 97ef952 commit 6f51f51

20 files changed

Lines changed: 505 additions & 390 deletions

File tree

‎Documentation/DMA-attributes.txt‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,45 @@ DMA_ATTR_NON_CONSISTENT lets the platform to choose to return either
4949
consistent or non-consistent memory as it sees fit. By using this API,
5050
you are guaranteeing to the platform that you have all the correct and
5151
necessary sync points for this memory in the driver.
52+
53+
DMA_ATTR_NO_KERNEL_MAPPING
54+
--------------------------
55+
56+
DMA_ATTR_NO_KERNEL_MAPPING lets the platform to avoid creating a kernel
57+
virtual mapping for the allocated buffer. On some architectures creating
58+
such mapping is non-trivial task and consumes very limited resources
59+
(like kernel virtual address space or dma consistent address space).
60+
Buffers allocated with this attribute can be only passed to user space
61+
by calling dma_mmap_attrs(). By using this API, you are guaranteeing
62+
that you won't dereference the pointer returned by dma_alloc_attr(). You
63+
can threat it as a cookie that must be passed to dma_mmap_attrs() and
64+
dma_free_attrs(). Make sure that both of these also get this attribute
65+
set on each call.
66+
67+
Since it is optional for platforms to implement
68+
DMA_ATTR_NO_KERNEL_MAPPING, those that do not will simply ignore the
69+
attribute and exhibit default behavior.
70+
71+
DMA_ATTR_SKIP_CPU_SYNC
72+
----------------------
73+
74+
By default dma_map_{single,page,sg} functions family transfer a given
75+
buffer from CPU domain to device domain. Some advanced use cases might
76+
require sharing a buffer between more than one device. This requires
77+
having a mapping created separately for each device and is usually
78+
performed by calling dma_map_{single,page,sg} function more than once
79+
for the given buffer with device pointer to each device taking part in
80+
the buffer sharing. The first call transfers a buffer from 'CPU' domain
81+
to 'device' domain, what synchronizes CPU caches for the given region
82+
(usually it means that the cache has been flushed or invalidated
83+
depending on the dma direction). However, next calls to
84+
dma_map_{single,page,sg}() for other devices will perform exactly the
85+
same sychronization operation on the CPU cache. CPU cache sychronization
86+
might be a time consuming operation, especially if the buffers are
87+
large, so it is highly recommended to avoid it if possible.
88+
DMA_ATTR_SKIP_CPU_SYNC allows platform code to skip synchronization of
89+
the CPU cache for the given buffer assuming that it has been already
90+
transferred to 'device' domain. This attribute can be also used for
91+
dma_unmap_{single,page,sg} functions family to force buffer to stay in
92+
device domain after releasing a mapping for it. Use this attribute with
93+
care!

‎Documentation/kernel-parameters.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
526526

527527
coherent_pool=nn[KMG] [ARM,KNL]
528528
Sets the size of memory pool for coherent, atomic dma
529-
allocations if Contiguous Memory Allocator (CMA) is used.
529+
allocations, by default set to 256K.
530530

531531
code_bytes [X86] How many bytes of object code to print
532532
in an oops report.

‎arch/arm/common/dmabounce.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ static struct dma_map_ops dmabounce_ops = {
452452
.alloc = arm_dma_alloc,
453453
.free = arm_dma_free,
454454
.mmap = arm_dma_mmap,
455+
.get_sgtable = arm_dma_get_sgtable,
455456
.map_page = dmabounce_map_page,
456457
.unmap_page = dmabounce_unmap_page,
457458
.sync_single_for_cpu = dmabounce_sync_for_cpu,

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

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,6 @@ extern int arm_dma_mmap(struct device *dev, struct vm_area_struct *vma,
186186
void *cpu_addr, dma_addr_t dma_addr, size_t size,
187187
struct dma_attrs *attrs);
188188

189-
#define dma_mmap_coherent(d, v, c, h, s) dma_mmap_attrs(d, v, c, h, s, NULL)
190-
191-
static inline int dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma,
192-
void *cpu_addr, dma_addr_t dma_addr,
193-
size_t size, struct dma_attrs *attrs)
194-
{
195-
struct dma_map_ops *ops = get_dma_ops(dev);
196-
BUG_ON(!ops);
197-
return ops->mmap(dev, vma, cpu_addr, dma_addr, size, attrs);
198-
}
199-
200189
static inline void *dma_alloc_writecombine(struct device *dev, size_t size,
201190
dma_addr_t *dma_handle, gfp_t flag)
202191
{
@@ -213,20 +202,12 @@ static inline void dma_free_writecombine(struct device *dev, size_t size,
213202
return dma_free_attrs(dev, size, cpu_addr, dma_handle, &attrs);
214203
}
215204

216-
static inline int dma_mmap_writecombine(struct device *dev, struct vm_area_struct *vma,
217-
void *cpu_addr, dma_addr_t dma_addr, size_t size)
218-
{
219-
DEFINE_DMA_ATTRS(attrs);
220-
dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs);
221-
return dma_mmap_attrs(dev, vma, cpu_addr, dma_addr, size, &attrs);
222-
}
223-
224205
/*
225206
* This can be called during boot to increase the size of the consistent
226207
* DMA region above it's default value of 2MB. It must be called before the
227208
* memory allocator is initialised, i.e. before any core_initcall.
228209
*/
229-
extern void __init init_consistent_dma_size(unsigned long size);
210+
static inline void init_consistent_dma_size(unsigned long size) { }
230211

231212
/*
232213
* For SA-1111, IXP425, and ADI systems the dma-mapping functions are "magic"
@@ -280,6 +261,9 @@ extern void arm_dma_sync_sg_for_cpu(struct device *, struct scatterlist *, int,
280261
enum dma_data_direction);
281262
extern void arm_dma_sync_sg_for_device(struct device *, struct scatterlist *, int,
282263
enum dma_data_direction);
264+
extern int arm_dma_get_sgtable(struct device *dev, struct sg_table *sgt,
265+
void *cpu_addr, dma_addr_t dma_addr, size_t size,
266+
struct dma_attrs *attrs);
283267

284268
#endif /* __KERNEL__ */
285269
#endif

0 commit comments

Comments
 (0)