diff options
| author | Will Deacon <will.deacon@arm.com> | 2014-08-27 10:49:10 -0400 |
|---|---|---|
| committer | Will Deacon <will.deacon@arm.com> | 2014-12-01 11:50:32 -0500 |
| commit | a3a60f81ee6f8fa65a57fa186b395bcd1f1bb097 (patch) | |
| tree | fb9f47c0b0f9065916242bfa76864d5b72825b8f | |
| parent | 1cd076bf67793942ed921b766f7d461de2ebc0a2 (diff) | |
dma-mapping: replace set_arch_dma_coherent_ops with arch_setup_dma_ops
set_arch_dma_coherent_ops is called from of_dma_configure in order to
swizzle the architectural dma-mapping functions over to a cache-coherent
implementation. This is currently implemented only for ARM.
In anticipation of re-using this mechanism for IOMMU-backed dma-mapping
ops too, this patch replaces the function with a broader
arch_setup_dma_ops callback which will be extended in future.
Acked-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Tested-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
| -rw-r--r-- | arch/arm/include/asm/dma-mapping.h | 8 | ||||
| -rw-r--r-- | drivers/of/platform.c | 31 | ||||
| -rw-r--r-- | include/linux/dma-mapping.h | 7 |
3 files changed, 19 insertions, 27 deletions
diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h index 85738b200023..dc3420e77758 100644 --- a/arch/arm/include/asm/dma-mapping.h +++ b/arch/arm/include/asm/dma-mapping.h | |||
| @@ -121,12 +121,12 @@ static inline unsigned long dma_max_pfn(struct device *dev) | |||
| 121 | } | 121 | } |
| 122 | #define dma_max_pfn(dev) dma_max_pfn(dev) | 122 | #define dma_max_pfn(dev) dma_max_pfn(dev) |
| 123 | 123 | ||
| 124 | static inline int set_arch_dma_coherent_ops(struct device *dev) | 124 | static inline void arch_setup_dma_ops(struct device *dev, bool coherent) |
| 125 | { | 125 | { |
| 126 | set_dma_ops(dev, &arm_coherent_dma_ops); | 126 | if (coherent) |
| 127 | return 0; | 127 | set_dma_ops(dev, &arm_coherent_dma_ops); |
| 128 | } | 128 | } |
| 129 | #define set_arch_dma_coherent_ops(dev) set_arch_dma_coherent_ops(dev) | 129 | #define arch_setup_dma_ops arch_setup_dma_ops |
| 130 | 130 | ||
| 131 | static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr) | 131 | static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr) |
| 132 | { | 132 | { |
diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 3b64d0bf5bba..ff1f4e9afccb 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c | |||
| @@ -164,6 +164,8 @@ static void of_dma_configure(struct device *dev) | |||
| 164 | { | 164 | { |
| 165 | u64 dma_addr, paddr, size; | 165 | u64 dma_addr, paddr, size; |
| 166 | int ret; | 166 | int ret; |
| 167 | bool coherent; | ||
| 168 | unsigned long offset; | ||
| 167 | 169 | ||
| 168 | /* | 170 | /* |
| 169 | * Set default dma-mask to 32 bit. Drivers are expected to setup | 171 | * Set default dma-mask to 32 bit. Drivers are expected to setup |
| @@ -178,28 +180,21 @@ static void of_dma_configure(struct device *dev) | |||
| 178 | if (!dev->dma_mask) | 180 | if (!dev->dma_mask) |
| 179 | dev->dma_mask = &dev->coherent_dma_mask; | 181 | dev->dma_mask = &dev->coherent_dma_mask; |
| 180 | 182 | ||
| 181 | /* | ||
| 182 | * if dma-coherent property exist, call arch hook to setup | ||
| 183 | * dma coherent operations. | ||
| 184 | */ | ||
| 185 | if (of_dma_is_coherent(dev->of_node)) { | ||
| 186 | set_arch_dma_coherent_ops(dev); | ||
| 187 | dev_dbg(dev, "device is dma coherent\n"); | ||
| 188 | } | ||
| 189 | |||
| 190 | /* | ||
| 191 | * if dma-ranges property doesn't exist - just return else | ||
| 192 | * setup the dma offset | ||
| 193 | */ | ||
| 194 | ret = of_dma_get_range(dev->of_node, &dma_addr, &paddr, &size); | 183 | ret = of_dma_get_range(dev->of_node, &dma_addr, &paddr, &size); |
| 195 | if (ret < 0) { | 184 | if (ret < 0) { |
| 196 | dev_dbg(dev, "no dma range information to setup\n"); | 185 | dma_addr = offset = 0; |
| 197 | return; | 186 | size = dev->coherent_dma_mask; |
| 187 | } else { | ||
| 188 | offset = PFN_DOWN(paddr - dma_addr); | ||
| 189 | dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", dev->dma_pfn_offset); | ||
| 198 | } | 190 | } |
| 191 | dev->dma_pfn_offset = offset; | ||
| 192 | |||
| 193 | coherent = of_dma_is_coherent(dev->of_node); | ||
| 194 | dev_dbg(dev, "device is%sdma coherent\n", | ||
| 195 | coherent ? " " : " not "); | ||
| 199 | 196 | ||
| 200 | /* DMA ranges found. Calculate and set dma_pfn_offset */ | 197 | arch_setup_dma_ops(dev, coherent); |
| 201 | dev->dma_pfn_offset = PFN_DOWN(paddr - dma_addr); | ||
| 202 | dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", dev->dma_pfn_offset); | ||
| 203 | } | 198 | } |
| 204 | 199 | ||
| 205 | /** | 200 | /** |
diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index d5d388160f42..8a1560f95d4a 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h | |||
| @@ -129,11 +129,8 @@ static inline int dma_coerce_mask_and_coherent(struct device *dev, u64 mask) | |||
| 129 | 129 | ||
| 130 | extern u64 dma_get_required_mask(struct device *dev); | 130 | extern u64 dma_get_required_mask(struct device *dev); |
| 131 | 131 | ||
| 132 | #ifndef set_arch_dma_coherent_ops | 132 | #ifndef arch_setup_dma_ops |
| 133 | static inline int set_arch_dma_coherent_ops(struct device *dev) | 133 | static inline void arch_setup_dma_ops(struct device *dev, bool coherent) { } |
| 134 | { | ||
| 135 | return 0; | ||
| 136 | } | ||
| 137 | #endif | 134 | #endif |
| 138 | 135 | ||
| 139 | static inline unsigned int dma_get_max_seg_size(struct device *dev) | 136 | static inline unsigned int dma_get_max_seg_size(struct device *dev) |
