ARM: convert dma-mapping to asm-generic API
PATCH 1/2 ARM: convert dma-mapping to asm-generic API
This converts ARM to use the asm-generic/dma-mapping-common API for the DMA API. As a side effect, this also allows us to take advantage of DMA API debugging (CONFIG_DMA_API_DEBUG).
We have dma_map_ops for normal, non-coherent architectures, fully coherent architectures and architectures that require dmabounce support. A dma_ops field is added to struct dev_archdata so platforms using an ACP can override the dma operations for that device to be fully coherent e.g.
struct device *my_coherent_device; my_coherent_device->dev_archdata.dma_ops = &coherent_dma_ops;
---
Note: this patch also requires "ARM: dmabounce: fix partial sync in dma_sync_single_* API" from FUJITA Tomonori:
http://www.spinics.net/lists/netdev/msg126826.html
which allows us to do fuzzy matching of the buffers when using dmabounce.
arch/arm/Kconfig | 2 + arch/arm/common/dmabounce.c | 157 ++++++++++++++++---------- arch/arm/include/asm/device.h | 5 +- arch/arm/include/asm/dma-mapping.h | 221 ++++-------------------------------- arch/arm/mm/dma-mapping.c | 220 +++++++++++++++++++++++------------ 5 files changed, 270 insertions(+), 335 deletions(-)
arch/arm/Kconfig +2 -0
@@ -16,6 +16,8 @@ config ARM select HAVE_DYNAMIC_FTRACE if (!XIP_KERNEL) select HAVE_FUNCTION_GRAPH_TRACER if (!THUMB2_KERNEL) select HAVE_GENERIC_DMA_COHERENT + select HAVE_DMA_ATTRS + select HAVE_DMA_API_DEBUG select HAVE_KERNEL_GZIP select HAVE_KERNEL_LZO select HAVE_KERNEL_LZMA
arch/arm/common/dmabounce.c +99 -58
225 lines not on this page · raw message
arch/arm/include/asm/device.h +4 -1
@@ -6,10 +6,13 @@#ifndef ASMARM_DEVICE_H #define ASMARM_DEVICE_H +struct dma_map_ops ; +struct dev_archdata {#ifdef CONFIG_DMABOUNCE -struct dmabounce_device_info *dmabounce; +struct dmabounce_device_info *dmabounce;#endif +struct dma_map_ops *dma_ops; }; struct pdev_archdata {
arch/arm/include/asm/dma-mapping.h +20 -201
265 lines not on this page · raw message
arch/arm/mm/dma-mapping.c +145 -75
273 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH 2/2 ARM: use cached memory in dma_alloc_coherent() if possible
For fully coherent architectures or systems using the ARM ACP to provide coherency to individual device, use cached memory as the coherent backing rather than noncached or simply bufferable memory.
--- arch/arm/mm/dma-mapping.c | 30 ++++++++++++++++++++++++++++++ 1 files changed, 30 insertions(+), 0 deletions(-)
arch/arm/mm/dma-mapping.c +30 -0
@@ -579,6 +579,34 @@ int coherent_map_sg(struct device *dev, struct scatterlist *sg, int nents, }/* +* For fully coherent systems/devices we can use normal, cached memory so just +* get some free pages. +*/ +static void *coherent_alloc (struct device *dev,size_t size, +dma_addr_t *dma_handle,gfp_t gfp) +{ +void *ret; +u64 mask =get_coherent_dma_mask (dev); + +if (!dev || mask >=0xffffffffUL ) + gfp &= ~GFP_DMA ; + + ret = (void *)__get_free_pages (gfp,get_order (size)); +if (ret) { +memset (ret,0 , size); + *dma_handle =virt_to_phys (ret); + } + +return ret; +} + +static void coherent_free (struct device *dev,size_t size,void *virt, +dma_addr_t dma_handle) +{ +free_pages ((unsigned long )dma_handle,get_order (size)); +} + +/* * Coherent DMA ops. These can either be used for the whole system * automatically if arch_is_coherent() is true or on a per device basis if the * device is connected to the ACP port to provide coherency for that device.
@@ -586,6 +614,8 @@ int coherent_map_sg(struct device *dev, struct scatterlist *sg, int nents,* dev->archdata.dma_ops */ struct dma_map_ops coherent_dma_ops = { + .alloc_coherent = coherent_alloc, + .free_coherent = coherent_free, .map_page = coherent_map_page, .map_sg = coherent_map_sg, };
Signature · 1 line
1.7.2.3
PATCH 2/2 ARM: use cached memory in dma_alloc_coherent() if possible
Quoted 3 lines · Jamie Iles
For fully coherent architectures or systems using the ARM ACP to provide coherency to individual device, use cached memory as the coherent backing rather than noncached or simply bufferable memory.
As has already been covered by Catalin, as far as we know, no one uses the ACP yet. Do you have a system which does?
PATCH 2/2 ARM: use cached memory in dma_alloc_coherent() if possible
Quoted 7 lines · Russell King - ARM Linux
Quoted 3 lines · Jamie Iles
For fully coherent architectures or systems using the ARM ACP to provide coherency to individual device, use cached memory as the coherent backing rather than noncached or simply bufferable memory.
As has already been covered by Catalin, as far as we know, no one uses the ACP yet. Do you have a system which does?
No, not yet. I was looking at this to see what the impact would be if we did though with regards to the CPU side of things for future devices and thought someone else may find it useful.
Jamie
PATCH 2/2 ARM: use cached memory in dma_alloc_coherent() if possible
In reply to Russell King - ARM LinuxQuoted 7 lines · Russell King - ARM Linux
Quoted 3 lines · Jamie Iles
For fully coherent architectures or systems using the ARM ACP to provide coherency to individual device, use cached memory as the coherent backing rather than noncached or simply bufferable memory.
As has already been covered by Catalin, as far as we know, no one uses the ACP yet. ?Do you have a system which does?
I'm not sure there is any publicly available system yet. This may be present in future systems, though only a few peripherals would probably be connected to the ACP (like an HD LCD controller). So I don't think we'll get a completely coherent system and a better approach may be to add per-device DMA operations.
Signature · 1 line
Catalin
PATCH 2/2 ARM: use cached memory in dma_alloc_coherent() if possible
Quoted 7 lines · Catalin Marinas
Quoted 5 lines · Russell King - ARM Linux
Quoted 3 lines · Jamie Iles
For fully coherent architectures or systems using the ARM ACP to provide coherency to individual device, use cached memory as the coherent backing rather than noncached or simply bufferable memory.
Quoted 8 lines
Quoted 2 lines
As has already been covered by Catalin, as far as we know, no one uses the ACP yet. ?Do you have a system which does?
I'm not sure there is any publicly available system yet. This may be present in future systems, though only a few peripherals would probably be connected to the ACP (like an HD LCD controller). So I don't think we'll get a completely coherent system and a better approach may be to add per-device DMA operations.
Ok, we may not get new systems that are fully coherent but we have ixp23xx that is fully coherent and the ARM DMA API as it is already checks for this with the arch_is_coherent().
You can do per-device DMA operations with the first patch by defining the operations in struct device::archdata::dma_ops. If all you need is something that initializes scatterlists then you can use the coherent_dma_ops struct.
Jamie
PATCH 1/2 ARM: convert dma-mapping to asm-generic API
In reply to Jamie IlesQuoted 7 lines · Jamie Iles
Note: this patch also requires "ARM: dmabounce: fix partial sync in dma_sync_single_* API" from FUJITA Tomonori:
http://www.spinics.net/lists/netdev/msg126826.htmlwhich allows us to do fuzzy matching of the buffers when using dmabounce.
Which I've already said no to.
I don't believe that the direction taken there is anywhere near the right one - the approach we have (implementing the whole buffer sync in terms of the partial buffer sync) is the far more logical, simpler and safer way, and doesn't lead to the possibility of two partially overlapping mappings causing the wrong one to be operated upon.
The debug code doesn't check for overlapping mappings in any way, so we can't say that they never occur.
With the way that the DMA API has gone, I view the "generic" stuff as a disaster.
PATCH 1/2 ARM: convert dma-mapping to asm-generic API
Quoted 10 lines · Russell King - ARM Linux
Quoted 7 lines · Jamie Iles
Note: this patch also requires "ARM: dmabounce: fix partial sync in dma_sync_single_* API" from FUJITA Tomonori:
http://www.spinics.net/lists/netdev/msg126826.htmlwhich allows us to do fuzzy matching of the buffers when using dmabounce.
Which I've already said no to.
Ok, perhaps I missed some other posts. From that thread the only objections I found were to do with the indentation style and they were fixed up.
Quoted 11 lines
I don't believe that the direction taken there is anywhere near the right one - the approach we have (implementing the whole buffer sync in terms of the partial buffer sync) is the far more logical, simpler and safer way, and doesn't lead to the possibility of two partially overlapping mappings causing the wrong one to be operated upon.
The debug code doesn't check for overlapping mappings in any way, so we can't say that they never occur.
With the way that the DMA API has gone, I view the "generic" stuff as a disaster.
Ok I can't disagree with that. I've had a look at some of the other arches and I can't see an obvious reason why we couldn't change the generic implementation to do the sync in the way you describe. Perhaps I'll have a look at that after the holidays.
With regards to the API debug, any objections to adding the necessary calls into the existing ARM implementation? Perhaps it'll catch some misuses of the API.
Jamie
PATCH 1/2 ARM: convert dma-mapping to asm-generic API
Quoted 10 lines · Jamie Iles
Quoted 9 lines · Russell King - ARM Linux
I don't believe that the direction taken there is anywhere near the right one - the approach we have (implementing the whole buffer sync in terms of the partial buffer sync) is the far more logical, simpler and safer way, and doesn't lead to the possibility of two partially overlapping mappings causing the wrong one to be operated upon.
The debug code doesn't check for overlapping mappings in any way, so we can't say that they never occur.
Quoted 7 lines
Quoted 2 lines
With the way that the DMA API has gone, I view the "generic" stuff as a disaster.
Ok I can't disagree with that. I've had a look at some of the other arches and I can't see an obvious reason why we couldn't change the generic implementation to do the sync in the way you describe. Perhaps I'll have a look at that after the holidays.
As an alternative, how about we add sync_single_range_for_{cpu,device}() methods to struct dma_map_ops and if they aren't populated, fall back to the non-range variants with an offset of 0? Then for ARM we can specify the _range_* versions and we don't need the fuzziness in the dmabounce code. Or is this just not worth doing and keeping the ARM version specific?
Jamie
PATCH 1/2 ARM: convert dma-mapping to asm-generic API
In reply to Jamie IlesQuoted 24 lines · On Tue, 21 Dec 2010 11:01:35 +0000 Jamie Iles <[email protected]> wrote:
Quoted 10 lines · Russell King - ARM Linux
Quoted 7 lines · Jamie Iles
Note: this patch also requires "ARM: dmabounce: fix partial sync in dma_sync_single_* API" from FUJITA Tomonori:
http://www.spinics.net/lists/netdev/msg126826.htmlwhich allows us to do fuzzy matching of the buffers when using dmabounce.
Which I've already said no to.
Ok, perhaps I missed some other posts. From that thread the only objections I found were to do with the indentation style and they were fixed up.
Quoted 9 lines
I don't believe that the direction taken there is anywhere near the right one - the approach we have (implementing the whole buffer sync in terms of the partial buffer sync) is the far more logical, simpler and safer way, and doesn't lead to the possibility of two partially overlapping mappings causing the wrong one to be operated upon.
The debug code doesn't check for overlapping mappings in any way, so we can't say that they never occur.
Quoted 7 lines
Quoted 2 lines
With the way that the DMA API has gone, I view the "generic" stuff as a disaster.
Ok I can't disagree with that. I've had a look at some of the other arches and I can't see an obvious reason why we couldn't change the generic implementation to do the sync in the way you describe. Perhaps I'll have a look at that after the holidays.
You need to examine all the network drivers and fix some of them.
PATCH 1/2 ARM: convert dma-mapping to asm-generic API
In reply to Jamie IlesQuoted 4 lines · On Tuesday 21 December 2010 11:20:01 Jamie Iles wrote:
This converts ARM to use the asm-generic/dma-mapping-common API for the DMA API. As a side effect, this also allows us to take advantage of DMA API debugging (
CONFIG_DMA_API_DEBUG).
Quoted 8 lines
We have
dma_map_opsfor normal, non-coherent architectures, fully coherent architectures and architectures that require dmabounce support. Adma_opsfield is added to structdev_archdataso platforms using an ACP can override the dma operations for that device to be fully coherent e.g.struct device *my_coherent_device; my_coherent_device->dev_archdata.dma_ops = &coherent_dma_ops;
I think what's more important here is the ability to use an IOMMU on some devices while other devices are mapped statically.
I believe at the moment, at least MSM and OMAP support an IOMMU, but we don't provide support for that in the DMA mapping interface yet.
Arnd
PATCH 1/2 ARM: convert dma-mapping to asm-generic API
Quoted 19 lines · Arnd Bergmann
Quoted 4 lines · On Tuesday 21 December 2010 11:20:01 Jamie Iles wrote:
This converts ARM to use the asm-generic/dma-mapping-common API for the DMA API. As a side effect, this also allows us to take advantage of DMA API debugging (
CONFIG_DMA_API_DEBUG).Quoted 8 lines
We have
dma_map_opsfor normal, non-coherent architectures, fully coherent architectures and architectures that require dmabounce support. Adma_opsfield is added to structdev_archdataso platforms using an ACP can override the dma operations for that device to be fully coherent e.g.struct device *my_coherent_device; my_coherent_device->dev_archdata.dma_ops = &coherent_dma_ops;I think what's more important here is the ability to use an IOMMU on some devices while other devices are mapped statically.
I believe at the moment, at least MSM and OMAP support an IOMMU, but we don't provide support for that in the DMA mapping interface yet.
PATCH 1/2 ARM: convert dma-mapping to asm-generic API
Quoted 7 lines · On Tuesday 21 December 2010 11:59:46 Russell King - ARM Linux wrote:
From what I understand on OMAP, they need to control the device address, physical address and (sometimes) CPU virtual address that an IOMMU mapping is created for. If they did add support for their IOMMUs to the DMA API, the DMA API will be buried beneath their IOMMU layer.
The OMAP devices with IOMMUs are hardly generic drivers in any case - they tend to be there for their on-board DSP stuff.
What you describe is certainly true for the DSP interfaces, since they share data structures in memory between the ARM and DSP cores.
My understanding of OMAP (probably more limited than yours) is that they have lots of those IOMMUs all over the place though, so it would just be a matter of time before someone needs them for something else.
The obvious use case for an IOMMU is to extend the addressable memory a device gets, which will come up when someone combines a Cortex-A15 core with more than 4GB of RAM and devices that only have a 32 bit address bus.
Arnd