aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Roedel <joerg.roedel@amd.com>2008-08-19 10:32:45 -0400
committerIngo Molnar <mingo@elte.hu>2008-08-22 02:34:51 -0400
commit6c505ce3930c6a6b455cda53fab3e88ae44f8221 (patch)
tree5b6254c6589f458ad0af21d7f6fbc998ebfd3714
parentc647c3bb2d16246a87f49035985ddb7c1eb030df (diff)
x86: move dma_*_coherent functions to include file
All the x86 DMA-API functions are defined in asm/dma-mapping.h. This patch moves the dma_*_coherent functions also to this header file because they are now small enough to do so. This is done as a separate patch because it also includes some renaming and restructuring of the dma-mapping.h file. Signed-off-by: Joerg Roedel <joerg.roede@amd.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r--arch/x86/kernel/pci-dma.c49
-rw-r--r--arch/x86/kernel/pci-gart_64.c4
-rw-r--r--include/asm-x86/dma-mapping.h47
3 files changed, 42 insertions, 58 deletions
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index 613332b26e31..0a1408abcc62 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -41,11 +41,12 @@ EXPORT_SYMBOL(bad_dma_address);
41/* Dummy device used for NULL arguments (normally ISA). Better would 41/* Dummy device used for NULL arguments (normally ISA). Better would
42 be probably a smaller DMA mask, but this is bug-to-bug compatible 42 be probably a smaller DMA mask, but this is bug-to-bug compatible
43 to older i386. */ 43 to older i386. */
44struct device fallback_dev = { 44struct device x86_dma_fallback_dev = {
45 .bus_id = "fallback device", 45 .bus_id = "fallback device",
46 .coherent_dma_mask = DMA_32BIT_MASK, 46 .coherent_dma_mask = DMA_32BIT_MASK,
47 .dma_mask = &fallback_dev.coherent_dma_mask, 47 .dma_mask = &x86_dma_fallback_dev.coherent_dma_mask,
48}; 48};
49EXPORT_SYMBOL(x86_dma_fallback_dev);
49 50
50int dma_set_mask(struct device *dev, u64 mask) 51int dma_set_mask(struct device *dev, u64 mask)
51{ 52{
@@ -241,50 +242,6 @@ int dma_supported(struct device *dev, u64 mask)
241} 242}
242EXPORT_SYMBOL(dma_supported); 243EXPORT_SYMBOL(dma_supported);
243 244
244/*
245 * Allocate memory for a coherent mapping.
246 */
247 void *
248dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
249 gfp_t gfp)
250{
251 struct dma_mapping_ops *ops = get_dma_ops(dev);
252 void *memory;
253
254 if (dma_alloc_from_coherent(dev, size, dma_handle, &memory))
255 return memory;
256
257 if (!dev) {
258 dev = &fallback_dev;
259 gfp |= GFP_DMA;
260 }
261
262 if (ops->alloc_coherent)
263 return ops->alloc_coherent(dev, size,
264 dma_handle, gfp);
265 return NULL;
266}
267EXPORT_SYMBOL(dma_alloc_coherent);
268
269/*
270 * Unmap coherent memory.
271 * The caller must ensure that the device has finished accessing the mapping.
272 */
273void dma_free_coherent(struct device *dev, size_t size,
274 void *vaddr, dma_addr_t bus)
275{
276 struct dma_mapping_ops *ops = get_dma_ops(dev);
277
278 WARN_ON(irqs_disabled()); /* for portability */
279
280 if (dma_release_from_coherent(dev, get_order(size), vaddr))
281 return;
282
283 if (ops->free_coherent)
284 ops->free_coherent(dev, size, vaddr, bus);
285}
286EXPORT_SYMBOL(dma_free_coherent);
287
288static int __init pci_iommu_init(void) 245static int __init pci_iommu_init(void)
289{ 246{
290 calgary_iommu_init(); 247 calgary_iommu_init();
diff --git a/arch/x86/kernel/pci-gart_64.c b/arch/x86/kernel/pci-gart_64.c
index ef753e233580..e81df25dc067 100644
--- a/arch/x86/kernel/pci-gart_64.c
+++ b/arch/x86/kernel/pci-gart_64.c
@@ -276,7 +276,7 @@ gart_map_single(struct device *dev, phys_addr_t paddr, size_t size, int dir)
276 unsigned long bus; 276 unsigned long bus;
277 277
278 if (!dev) 278 if (!dev)
279 dev = &fallback_dev; 279 dev = &x86_dma_fallback_dev;
280 280
281 if (!need_iommu(dev, paddr, size)) 281 if (!need_iommu(dev, paddr, size))
282 return paddr; 282 return paddr;
@@ -427,7 +427,7 @@ gart_map_sg(struct device *dev, struct scatterlist *sg, int nents, int dir)
427 return 0; 427 return 0;
428 428
429 if (!dev) 429 if (!dev)
430 dev = &fallback_dev; 430 dev = &x86_dma_fallback_dev;
431 431
432 out = 0; 432 out = 0;
433 start = 0; 433 start = 0;
diff --git a/include/asm-x86/dma-mapping.h b/include/asm-x86/dma-mapping.h
index ad9cd6d49bfc..8e16095d1fa9 100644
--- a/include/asm-x86/dma-mapping.h
+++ b/include/asm-x86/dma-mapping.h
@@ -9,10 +9,11 @@
9#include <linux/scatterlist.h> 9#include <linux/scatterlist.h>
10#include <asm/io.h> 10#include <asm/io.h>
11#include <asm/swiotlb.h> 11#include <asm/swiotlb.h>
12#include <asm-generic/dma-coherent.h>
12 13
13extern dma_addr_t bad_dma_address; 14extern dma_addr_t bad_dma_address;
14extern int iommu_merge; 15extern int iommu_merge;
15extern struct device fallback_dev; 16extern struct device x86_dma_fallback_dev;
16extern int panic_on_overflow; 17extern int panic_on_overflow;
17extern int force_iommu; 18extern int force_iommu;
18 19
@@ -87,13 +88,7 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
87 88
88#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) 89#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
89#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) 90#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
90 91#define dma_is_consistent(d, h) (1)
91void *dma_alloc_coherent(struct device *dev, size_t size,
92 dma_addr_t *dma_handle, gfp_t flag);
93
94void dma_free_coherent(struct device *dev, size_t size,
95 void *vaddr, dma_addr_t dma_handle);
96
97 92
98extern int dma_supported(struct device *hwdev, u64 mask); 93extern int dma_supported(struct device *hwdev, u64 mask);
99extern int dma_set_mask(struct device *dev, u64 mask); 94extern int dma_set_mask(struct device *dev, u64 mask);
@@ -247,7 +242,39 @@ static inline int dma_get_cache_alignment(void)
247 return boot_cpu_data.x86_clflush_size; 242 return boot_cpu_data.x86_clflush_size;
248} 243}
249 244
250#define dma_is_consistent(d, h) (1) 245static inline void *
246dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
247 gfp_t gfp)
248{
249 struct dma_mapping_ops *ops = get_dma_ops(dev);
250 void *memory;
251
252 if (dma_alloc_from_coherent(dev, size, dma_handle, &memory))
253 return memory;
254
255 if (!dev) {
256 dev = &x86_dma_fallback_dev;
257 gfp |= GFP_DMA;
258 }
259
260 if (ops->alloc_coherent)
261 return ops->alloc_coherent(dev, size,
262 dma_handle, gfp);
263 return NULL;
264}
265
266static inline void dma_free_coherent(struct device *dev, size_t size,
267 void *vaddr, dma_addr_t bus)
268{
269 struct dma_mapping_ops *ops = get_dma_ops(dev);
270
271 WARN_ON(irqs_disabled()); /* for portability */
272
273 if (dma_release_from_coherent(dev, get_order(size), vaddr))
274 return;
275
276 if (ops->free_coherent)
277 ops->free_coherent(dev, size, vaddr, bus);
278}
251 279
252#include <asm-generic/dma-coherent.h>
253#endif 280#endif