Skip to content

Commit b7a7d1c

Browse files
committed
Merge tag 'dma-mapping-5.1' of git://git.infradead.org/users/hch/dma-mapping
Pull DMA mapping updates from Christoph Hellwig: - add debugfs support for dumping dma-debug information (Corentin Labbe) - Kconfig cleanups (Andy Shevchenko and me) - debugfs cleanups (Greg Kroah-Hartman) - improve dma_map_resource and use it in the media code - arch_setup_dma_ops / arch_teardown_dma_ops cleanups - various small cleanups and improvements for the per-device coherent allocator - make the DMA mask an upper bound and don't fail "too large" dma mask in the remaning two architectures - this will allow big driver cleanups in the following merge windows * tag 'dma-mapping-5.1' of git://git.infradead.org/users/hch/dma-mapping: (21 commits) Documentation/DMA-API-HOWTO: update dma_mask sections sparc64/pci_sun4v: allow large DMA masks sparc64/iommu: allow large DMA masks sparc64: refactor the ali DMA quirk ccio: allow large DMA masks dma-mapping: remove the DMA_MEMORY_EXCLUSIVE flag dma-mapping: remove dma_mark_declared_memory_occupied dma-mapping: move CONFIG_DMA_CMA to kernel/dma/Kconfig dma-mapping: improve selection of dma_declare_coherent availability dma-mapping: remove an incorrect __iommem annotation of: select OF_RESERVED_MEM automatically device.h: dma_mem is only needed for HAVE_GENERIC_DMA_COHERENT mfd/sm501: depend on HAS_DMA dma-mapping: add a kconfig symbol for arch_teardown_dma_ops availability dma-mapping: add a kconfig symbol for arch_setup_dma_ops availability dma-mapping: move debug configuration options to kernel/dma dma-debug: add dumping facility via debugfs dma: debug: no need to check return value of debugfs_create functions videobuf2: replace a layering violation with dma_map_resource dma-mapping: don't BUG when calling dma_map_resource on RAM ...
2 parents 065b6c4 + 9eb9e96 commit b7a7d1c

File tree

47 files changed

+341
-542
lines changed

Some content is hidden

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

47 files changed

+341
-542
lines changed

Documentation/DMA-API-HOWTO.txt

Lines changed: 41 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -146,114 +146,75 @@ What about block I/O and networking buffers? The block I/O and
146146
networking subsystems make sure that the buffers they use are valid
147147
for you to DMA from/to.
148148

149-
DMA addressing limitations
149+
DMA addressing capabilities
150150
==========================
151151

152-
Does your device have any DMA addressing limitations? For example, is
153-
your device only capable of driving the low order 24-bits of address?
154-
If so, you need to inform the kernel of this fact.
152+
By default, the kernel assumes that your device can address 32-bits of DMA
153+
addressing. For a 64-bit capable device, this needs to be increased, and for
154+
a device with limitations, it needs to be decreased.
155155

156-
By default, the kernel assumes that your device can address the full
157-
32-bits. For a 64-bit capable device, this needs to be increased.
158-
And for a device with limitations, as discussed in the previous
159-
paragraph, it needs to be decreased.
156+
Special note about PCI: PCI-X specification requires PCI-X devices to support
157+
64-bit addressing (DAC) for all transactions. And at least one platform (SGI
158+
SN2) requires 64-bit consistent allocations to operate correctly when the IO
159+
bus is in PCI-X mode.
160160

161-
Special note about PCI: PCI-X specification requires PCI-X devices to
162-
support 64-bit addressing (DAC) for all transactions. And at least
163-
one platform (SGI SN2) requires 64-bit consistent allocations to
164-
operate correctly when the IO bus is in PCI-X mode.
161+
For correct operation, you must set the DMA mask to inform the kernel about
162+
your devices DMA addressing capabilities.
165163

166-
For correct operation, you must interrogate the kernel in your device
167-
probe routine to see if the DMA controller on the machine can properly
168-
support the DMA addressing limitation your device has. It is good
169-
style to do this even if your device holds the default setting,
170-
because this shows that you did think about these issues wrt. your
171-
device.
172-
173-
The query is performed via a call to dma_set_mask_and_coherent()::
164+
This is performed via a call to dma_set_mask_and_coherent()::
174165

175166
int dma_set_mask_and_coherent(struct device *dev, u64 mask);
176167

177-
which will query the mask for both streaming and coherent APIs together.
178-
If you have some special requirements, then the following two separate
179-
queries can be used instead:
168+
which will set the mask for both streaming and coherent APIs together. If you
169+
have some special requirements, then the following two separate calls can be
170+
used instead:
180171

181-
The query for streaming mappings is performed via a call to
172+
The setup for streaming mappings is performed via a call to
182173
dma_set_mask()::
183174

184175
int dma_set_mask(struct device *dev, u64 mask);
185176

186-
The query for consistent allocations is performed via a call
177+
The setup for consistent allocations is performed via a call
187178
to dma_set_coherent_mask()::
188179

189180
int dma_set_coherent_mask(struct device *dev, u64 mask);
190181

191-
Here, dev is a pointer to the device struct of your device, and mask
192-
is a bit mask describing which bits of an address your device
193-
supports. It returns zero if your card can perform DMA properly on
194-
the machine given the address mask you provided. In general, the
195-
device struct of your device is embedded in the bus-specific device
196-
struct of your device. For example, &pdev->dev is a pointer to the
197-
device struct of a PCI device (pdev is a pointer to the PCI device
198-
struct of your device).
182+
Here, dev is a pointer to the device struct of your device, and mask is a bit
183+
mask describing which bits of an address your device supports. Often the
184+
device struct of your device is embedded in the bus-specific device struct of
185+
your device. For example, &pdev->dev is a pointer to the device struct of a
186+
PCI device (pdev is a pointer to the PCI device struct of your device).
199187

200-
If it returns non-zero, your device cannot perform DMA properly on
201-
this platform, and attempting to do so will result in undefined
202-
behavior. You must either use a different mask, or not use DMA.
188+
These calls usually return zero to indicated your device can perform DMA
189+
properly on the machine given the address mask you provided, but they might
190+
return an error if the mask is too small to be supportable on the given
191+
system. If it returns non-zero, your device cannot perform DMA properly on
192+
this platform, and attempting to do so will result in undefined behavior.
193+
You must not use DMA on this device unless the dma_set_mask family of
194+
functions has returned success.
203195

204-
This means that in the failure case, you have three options:
196+
This means that in the failure case, you have two options:
205197

206-
1) Use another DMA mask, if possible (see below).
207-
2) Use some non-DMA mode for data transfer, if possible.
208-
3) Ignore this device and do not initialize it.
198+
1) Use some non-DMA mode for data transfer, if possible.
199+
2) Ignore this device and do not initialize it.
209200

210-
It is recommended that your driver print a kernel KERN_WARNING message
211-
when you end up performing either #2 or #3. In this manner, if a user
212-
of your driver reports that performance is bad or that the device is not
213-
even detected, you can ask them for the kernel messages to find out
214-
exactly why.
201+
It is recommended that your driver print a kernel KERN_WARNING message when
202+
setting the DMA mask fails. In this manner, if a user of your driver reports
203+
that performance is bad or that the device is not even detected, you can ask
204+
them for the kernel messages to find out exactly why.
215205

216-
The standard 32-bit addressing device would do something like this::
206+
The standard 64-bit addressing device would do something like this::
217207

218-
if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32))) {
208+
if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64))) {
219209
dev_warn(dev, "mydev: No suitable DMA available\n");
220210
goto ignore_this_device;
221211
}
222212

223-
Another common scenario is a 64-bit capable device. The approach here
224-
is to try for 64-bit addressing, but back down to a 32-bit mask that
225-
should not fail. The kernel may fail the 64-bit mask not because the
226-
platform is not capable of 64-bit addressing. Rather, it may fail in
227-
this case simply because 32-bit addressing is done more efficiently
228-
than 64-bit addressing. For example, Sparc64 PCI SAC addressing is
229-
more efficient than DAC addressing.
230-
231-
Here is how you would handle a 64-bit capable device which can drive
232-
all 64-bits when accessing streaming DMA::
233-
234-
int using_dac;
213+
If the device only supports 32-bit addressing for descriptors in the
214+
coherent allocations, but supports full 64-bits for streaming mappings
215+
it would look like this:
235216

236-
if (!dma_set_mask(dev, DMA_BIT_MASK(64))) {
237-
using_dac = 1;
238-
} else if (!dma_set_mask(dev, DMA_BIT_MASK(32))) {
239-
using_dac = 0;
240-
} else {
241-
dev_warn(dev, "mydev: No suitable DMA available\n");
242-
goto ignore_this_device;
243-
}
244-
245-
If a card is capable of using 64-bit consistent allocations as well,
246-
the case would look like this::
247-
248-
int using_dac, consistent_using_dac;
249-
250-
if (!dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64))) {
251-
using_dac = 1;
252-
consistent_using_dac = 1;
253-
} else if (!dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32))) {
254-
using_dac = 0;
255-
consistent_using_dac = 0;
256-
} else {
217+
if (dma_set_mask(dev, DMA_BIT_MASK(64))) {
257218
dev_warn(dev, "mydev: No suitable DMA available\n");
258219
goto ignore_this_device;
259220
}

Documentation/DMA-API.txt

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,7 @@ boundaries when doing this.
566566

567567
int
568568
dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
569-
dma_addr_t device_addr, size_t size, int
570-
flags)
569+
dma_addr_t device_addr, size_t size);
571570

572571
Declare region of memory to be handed out by dma_alloc_coherent() when
573572
it's asked for coherent memory for this device.
@@ -581,12 +580,6 @@ dma_addr_t in dma_alloc_coherent()).
581580

582581
size is the size of the area (must be multiples of PAGE_SIZE).
583582

584-
flags can be ORed together and are:
585-
586-
- DMA_MEMORY_EXCLUSIVE - only allocate memory from the declared regions.
587-
Do not allow dma_alloc_coherent() to fall back to system memory when
588-
it's out of memory in the declared region.
589-
590583
As a simplification for the platforms, only *one* such region of
591584
memory may be declared per device.
592585

@@ -605,23 +598,6 @@ unconditionally having removed all the required structures. It is the
605598
driver's job to ensure that no parts of this memory region are
606599
currently in use.
607600

608-
::
609-
610-
void *
611-
dma_mark_declared_memory_occupied(struct device *dev,
612-
dma_addr_t device_addr, size_t size)
613-
614-
This is used to occupy specific regions of the declared space
615-
(dma_alloc_coherent() will hand out the first free region it finds).
616-
617-
device_addr is the *device* address of the region requested.
618-
619-
size is the size (and should be a page-sized multiple).
620-
621-
The return value will be either a pointer to the processor virtual
622-
address of the memory, or an error (via PTR_ERR()) if any part of the
623-
region is occupied.
624-
625601
Part III - Debug drivers use of the DMA-API
626602
-------------------------------------------
627603

@@ -696,6 +672,9 @@ dma-api/disabled This read-only file contains the character 'Y'
696672
happen when it runs out of memory or if it was
697673
disabled at boot time
698674

675+
dma-api/dump This read-only file contains current DMA
676+
mappings.
677+
699678
dma-api/error_count This file is read-only and shows the total
700679
numbers of errors found.
701680

arch/arc/Kconfig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ config ARC
1111
select ARC_TIMERS
1212
select ARCH_HAS_DMA_COHERENT_TO_PFN
1313
select ARCH_HAS_PTE_SPECIAL
14+
select ARCH_HAS_SETUP_DMA_OPS
1415
select ARCH_HAS_SYNC_DMA_FOR_CPU
1516
select ARCH_HAS_SYNC_DMA_FOR_DEVICE
1617
select ARCH_SUPPORTS_ATOMIC_RMW if ARC_HAS_LLSC
@@ -31,7 +32,6 @@ config ARC
3132
select HAVE_ARCH_TRACEHOOK
3233
select HAVE_DEBUG_STACKOVERFLOW
3334
select HAVE_FUTEX_CMPXCHG if FUTEX
34-
select HAVE_GENERIC_DMA_COHERENT
3535
select HAVE_IOREMAP_PROT
3636
select HAVE_KERNEL_GZIP
3737
select HAVE_KERNEL_LZMA
@@ -45,7 +45,6 @@ config ARC
4545
select MODULES_USE_ELF_RELA
4646
select OF
4747
select OF_EARLY_FLATTREE
48-
select OF_RESERVED_MEM
4948
select PCI_SYSCALL if PCI
5049
select PERF_USE_VMALLOC if ARC_CACHE_VIPT_ALIASING
5150

arch/arc/include/asm/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ generic-y += bugs.h
33
generic-y += compat.h
44
generic-y += device.h
55
generic-y += div64.h
6+
generic-y += dma-mapping.h
67
generic-y += emergency-restart.h
78
generic-y += extable.h
89
generic-y += ftrace.h

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

Lines changed: 0 additions & 13 deletions
This file was deleted.

arch/arm/Kconfig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ config ARM
1313
select ARCH_HAS_MEMBARRIER_SYNC_CORE
1414
select ARCH_HAS_PTE_SPECIAL if ARM_LPAE
1515
select ARCH_HAS_PHYS_TO_DMA
16+
select ARCH_HAS_SETUP_DMA_OPS
1617
select ARCH_HAS_SET_MEMORY
1718
select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL
1819
select ARCH_HAS_STRICT_MODULE_RWX if MMU
20+
select ARCH_HAS_TEARDOWN_DMA_OPS if MMU
1921
select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
2022
select ARCH_HAVE_CUSTOM_GPIO_H
2123
select ARCH_HAS_GCOV_PROFILE_ALL
@@ -31,6 +33,7 @@ config ARM
3133
select CLONE_BACKWARDS
3234
select CPU_PM if SUSPEND || CPU_IDLE
3335
select DCACHE_WORD_ACCESS if HAVE_EFFICIENT_UNALIGNED_ACCESS
36+
select DMA_DECLARE_COHERENT
3437
select DMA_REMAP if MMU
3538
select EDAC_SUPPORT
3639
select EDAC_ATOMIC_SCRUB
@@ -73,7 +76,6 @@ config ARM
7376
select HAVE_FUNCTION_GRAPH_TRACER if !THUMB2_KERNEL
7477
select HAVE_FUNCTION_TRACER if !XIP_KERNEL
7578
select HAVE_GCC_PLUGINS
76-
select HAVE_GENERIC_DMA_COHERENT
7779
select HAVE_HW_BREAKPOINT if PERF_EVENTS && (CPU_V6 || CPU_V6K || CPU_V7)
7880
select HAVE_IDE if PCI || ISA || PCMCIA
7981
select HAVE_IRQ_TIME_ACCOUNTING
@@ -102,7 +104,6 @@ config ARM
102104
select MODULES_USE_ELF_REL
103105
select NEED_DMA_MAP_STATE
104106
select OF_EARLY_FLATTREE if OF
105-
select OF_RESERVED_MEM if OF
106107
select OLD_SIGACTION
107108
select OLD_SIGSUSPEND3
108109
select PCI_SYSCALL if PCI

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,6 @@ static inline unsigned long dma_max_pfn(struct device *dev)
9696
}
9797
#define dma_max_pfn(dev) dma_max_pfn(dev)
9898

99-
#define arch_setup_dma_ops arch_setup_dma_ops
100-
extern void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
101-
const struct iommu_ops *iommu, bool coherent);
102-
103-
#ifdef CONFIG_MMU
104-
#define arch_teardown_dma_ops arch_teardown_dma_ops
105-
extern void arch_teardown_dma_ops(struct device *dev);
106-
#endif
107-
10899
/* do not use this function in a driver */
109100
static inline bool is_device_dma_coherent(struct device *dev)
110101
{

arch/arm/mach-imx/mach-imx27_visstrim_m10.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,7 @@ static void __init visstrim_analog_camera_init(void)
258258
return;
259259

260260
dma_declare_coherent_memory(&pdev->dev, mx2_camera_base,
261-
mx2_camera_base, MX2_CAMERA_BUF_SIZE,
262-
DMA_MEMORY_EXCLUSIVE);
261+
mx2_camera_base, MX2_CAMERA_BUF_SIZE);
263262
}
264263

265264
static void __init visstrim_reserve(void)
@@ -445,8 +444,7 @@ static void __init visstrim_coda_init(void)
445444
dma_declare_coherent_memory(&pdev->dev,
446445
mx2_camera_base + MX2_CAMERA_BUF_SIZE,
447446
mx2_camera_base + MX2_CAMERA_BUF_SIZE,
448-
MX2_CAMERA_BUF_SIZE,
449-
DMA_MEMORY_EXCLUSIVE);
447+
MX2_CAMERA_BUF_SIZE);
450448
}
451449

452450
/* DMA deinterlace */
@@ -465,8 +463,7 @@ static void __init visstrim_deinterlace_init(void)
465463
dma_declare_coherent_memory(&pdev->dev,
466464
mx2_camera_base + 2 * MX2_CAMERA_BUF_SIZE,
467465
mx2_camera_base + 2 * MX2_CAMERA_BUF_SIZE,
468-
MX2_CAMERA_BUF_SIZE,
469-
DMA_MEMORY_EXCLUSIVE);
466+
MX2_CAMERA_BUF_SIZE);
470467
}
471468

472469
/* Emma-PrP for format conversion */
@@ -485,8 +482,7 @@ static void __init visstrim_emmaprp_init(void)
485482
*/
486483
ret = dma_declare_coherent_memory(&pdev->dev,
487484
mx2_camera_base, mx2_camera_base,
488-
MX2_CAMERA_BUF_SIZE,
489-
DMA_MEMORY_EXCLUSIVE);
485+
MX2_CAMERA_BUF_SIZE);
490486
if (ret)
491487
pr_err("Failed to declare memory for emmaprp\n");
492488
}

arch/arm/mach-imx/mach-mx31moboard.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,7 @@ static int __init mx31moboard_init_cam(void)
475475

476476
ret = dma_declare_coherent_memory(&pdev->dev,
477477
mx3_camera_base, mx3_camera_base,
478-
MX3_CAMERA_BUF_SIZE,
479-
DMA_MEMORY_EXCLUSIVE);
478+
MX3_CAMERA_BUF_SIZE);
480479
if (ret)
481480
goto err;
482481

arch/arm/mm/dma-mapping.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ const struct dma_map_ops arm_dma_ops = {
188188
.unmap_page = arm_dma_unmap_page,
189189
.map_sg = arm_dma_map_sg,
190190
.unmap_sg = arm_dma_unmap_sg,
191+
.map_resource = dma_direct_map_resource,
191192
.sync_single_for_cpu = arm_dma_sync_single_for_cpu,
192193
.sync_single_for_device = arm_dma_sync_single_for_device,
193194
.sync_sg_for_cpu = arm_dma_sync_sg_for_cpu,
@@ -211,6 +212,7 @@ const struct dma_map_ops arm_coherent_dma_ops = {
211212
.get_sgtable = arm_dma_get_sgtable,
212213
.map_page = arm_coherent_dma_map_page,
213214
.map_sg = arm_dma_map_sg,
215+
.map_resource = dma_direct_map_resource,
214216
.dma_supported = arm_dma_supported,
215217
};
216218
EXPORT_SYMBOL(arm_coherent_dma_ops);

0 commit comments

Comments
 (0)