diff options
author | David Daney <ddaney@caviumnetworks.com> | 2010-10-01 16:27:32 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2010-10-29 14:08:31 -0400 |
commit | 48e1fd5a81416a037f5a48120bf281102f2584e2 (patch) | |
tree | c5c4bd344f50493bb1d1c36d485300e9061c5aa2 /arch/mips/include/asm | |
parent | 43e4f7ae4b4a96b5e84f6e1592d2e9353138e88c (diff) |
MIPS: Convert DMA to use dma-mapping-common.h
Use asm-generic/dma-mapping-common.h to handle all DMA mapping operations
and establish a default get_dma_ops() that forwards all operations to the
existing code.
Augment dev_archdata to carry a pointer to the struct dma_map_ops, allowing
DMA operations to be overridden on a per device basis. Currently this is
never filled in, so the default dma_map_ops are used. A follow-on patch
sets this for Octeon PCI devices.
Also initialize the dma_debug system as it is now used if it is configured.
Includes fixes by Kevin Cernekee <cernekee@gmail.com>.
Signed-off-by: David Daney <ddaney@caviumnetworks.com>
Patchwork: http://patchwork.linux-mips.org/patch/1637/
Patchwork: http://patchwork.linux-mips.org/patch/1678/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips/include/asm')
-rw-r--r-- | arch/mips/include/asm/device.h | 15 | ||||
-rw-r--r-- | arch/mips/include/asm/dma-mapping.h | 96 | ||||
-rw-r--r-- | arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h | 2 | ||||
-rw-r--r-- | arch/mips/include/asm/mach-ip27/dma-coherence.h | 3 | ||||
-rw-r--r-- | arch/mips/include/asm/mach-ip32/dma-coherence.h | 3 | ||||
-rw-r--r-- | arch/mips/include/asm/mach-jazz/dma-coherence.h | 3 |
6 files changed, 79 insertions, 43 deletions
diff --git a/arch/mips/include/asm/device.h b/arch/mips/include/asm/device.h index 06746c5e8099..c94fafba9e62 100644 --- a/arch/mips/include/asm/device.h +++ b/arch/mips/include/asm/device.h | |||
@@ -3,4 +3,17 @@ | |||
3 | * | 3 | * |
4 | * This file is released under the GPLv2 | 4 | * This file is released under the GPLv2 |
5 | */ | 5 | */ |
6 | #include <asm-generic/device.h> | 6 | #ifndef _ASM_MIPS_DEVICE_H |
7 | #define _ASM_MIPS_DEVICE_H | ||
8 | |||
9 | struct dma_map_ops; | ||
10 | |||
11 | struct dev_archdata { | ||
12 | /* DMA operations on that device */ | ||
13 | struct dma_map_ops *dma_ops; | ||
14 | }; | ||
15 | |||
16 | struct pdev_archdata { | ||
17 | }; | ||
18 | |||
19 | #endif /* _ASM_MIPS_DEVICE_H*/ | ||
diff --git a/arch/mips/include/asm/dma-mapping.h b/arch/mips/include/asm/dma-mapping.h index 18fbf7af8e93..655f849bd08d 100644 --- a/arch/mips/include/asm/dma-mapping.h +++ b/arch/mips/include/asm/dma-mapping.h | |||
@@ -5,51 +5,41 @@ | |||
5 | #include <asm/cache.h> | 5 | #include <asm/cache.h> |
6 | #include <asm-generic/dma-coherent.h> | 6 | #include <asm-generic/dma-coherent.h> |
7 | 7 | ||
8 | void *dma_alloc_noncoherent(struct device *dev, size_t size, | 8 | #include <dma-coherence.h> |
9 | dma_addr_t *dma_handle, gfp_t flag); | ||
10 | 9 | ||
11 | void dma_free_noncoherent(struct device *dev, size_t size, | 10 | extern struct dma_map_ops *mips_dma_map_ops; |
12 | void *vaddr, dma_addr_t dma_handle); | ||
13 | 11 | ||
14 | void *dma_alloc_coherent(struct device *dev, size_t size, | 12 | static inline struct dma_map_ops *get_dma_ops(struct device *dev) |
15 | dma_addr_t *dma_handle, gfp_t flag); | 13 | { |
14 | if (dev && dev->archdata.dma_ops) | ||
15 | return dev->archdata.dma_ops; | ||
16 | else | ||
17 | return mips_dma_map_ops; | ||
18 | } | ||
16 | 19 | ||
17 | void dma_free_coherent(struct device *dev, size_t size, | 20 | static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size) |
18 | void *vaddr, dma_addr_t dma_handle); | 21 | { |
22 | if (!dev->dma_mask) | ||
23 | return 0; | ||
19 | 24 | ||
20 | extern dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size, | 25 | return addr + size <= *dev->dma_mask; |
21 | enum dma_data_direction direction); | 26 | } |
22 | extern void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, | 27 | |
23 | size_t size, enum dma_data_direction direction); | 28 | static inline void dma_mark_clean(void *addr, size_t size) {} |
24 | extern int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, | 29 | |
25 | enum dma_data_direction direction); | 30 | #include <asm-generic/dma-mapping-common.h> |
26 | extern dma_addr_t dma_map_page(struct device *dev, struct page *page, | 31 | |
27 | unsigned long offset, size_t size, enum dma_data_direction direction); | 32 | static inline int dma_supported(struct device *dev, u64 mask) |
28 | |||
29 | static inline void dma_unmap_page(struct device *dev, dma_addr_t dma_address, | ||
30 | size_t size, enum dma_data_direction direction) | ||
31 | { | 33 | { |
32 | dma_unmap_single(dev, dma_address, size, direction); | 34 | struct dma_map_ops *ops = get_dma_ops(dev); |
35 | return ops->dma_supported(dev, mask); | ||
33 | } | 36 | } |
34 | 37 | ||
35 | extern void dma_unmap_sg(struct device *dev, struct scatterlist *sg, | 38 | static inline int dma_mapping_error(struct device *dev, u64 mask) |
36 | int nhwentries, enum dma_data_direction direction); | 39 | { |
37 | extern void dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, | 40 | struct dma_map_ops *ops = get_dma_ops(dev); |
38 | size_t size, enum dma_data_direction direction); | 41 | return ops->mapping_error(dev, mask); |
39 | extern void dma_sync_single_for_device(struct device *dev, | 42 | } |
40 | dma_addr_t dma_handle, size_t size, enum dma_data_direction direction); | ||
41 | extern void dma_sync_single_range_for_cpu(struct device *dev, | ||
42 | dma_addr_t dma_handle, unsigned long offset, size_t size, | ||
43 | enum dma_data_direction direction); | ||
44 | extern void dma_sync_single_range_for_device(struct device *dev, | ||
45 | dma_addr_t dma_handle, unsigned long offset, size_t size, | ||
46 | enum dma_data_direction direction); | ||
47 | extern void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, | ||
48 | int nelems, enum dma_data_direction direction); | ||
49 | extern void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, | ||
50 | int nelems, enum dma_data_direction direction); | ||
51 | extern int dma_mapping_error(struct device *dev, dma_addr_t dma_addr); | ||
52 | extern int dma_supported(struct device *dev, u64 mask); | ||
53 | 43 | ||
54 | static inline int | 44 | static inline int |
55 | dma_set_mask(struct device *dev, u64 mask) | 45 | dma_set_mask(struct device *dev, u64 mask) |
@@ -65,4 +55,34 @@ dma_set_mask(struct device *dev, u64 mask) | |||
65 | extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size, | 55 | extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size, |
66 | enum dma_data_direction direction); | 56 | enum dma_data_direction direction); |
67 | 57 | ||
58 | static inline void *dma_alloc_coherent(struct device *dev, size_t size, | ||
59 | dma_addr_t *dma_handle, gfp_t gfp) | ||
60 | { | ||
61 | void *ret; | ||
62 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
63 | |||
64 | ret = ops->alloc_coherent(dev, size, dma_handle, gfp); | ||
65 | |||
66 | debug_dma_alloc_coherent(dev, size, *dma_handle, ret); | ||
67 | |||
68 | return ret; | ||
69 | } | ||
70 | |||
71 | static inline void dma_free_coherent(struct device *dev, size_t size, | ||
72 | void *vaddr, dma_addr_t dma_handle) | ||
73 | { | ||
74 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
75 | |||
76 | ops->free_coherent(dev, size, vaddr, dma_handle); | ||
77 | |||
78 | debug_dma_free_coherent(dev, size, vaddr, dma_handle); | ||
79 | } | ||
80 | |||
81 | |||
82 | void *dma_alloc_noncoherent(struct device *dev, size_t size, | ||
83 | dma_addr_t *dma_handle, gfp_t flag); | ||
84 | |||
85 | void dma_free_noncoherent(struct device *dev, size_t size, | ||
86 | void *vaddr, dma_addr_t dma_handle); | ||
87 | |||
68 | #endif /* _ASM_DMA_MAPPING_H */ | 88 | #endif /* _ASM_DMA_MAPPING_H */ |
diff --git a/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h b/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h index 17d579471ec4..f768f6fe712e 100644 --- a/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h +++ b/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h | |||
@@ -27,7 +27,7 @@ static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr, | |||
27 | static inline dma_addr_t plat_map_dma_mem_page(struct device *dev, | 27 | static inline dma_addr_t plat_map_dma_mem_page(struct device *dev, |
28 | struct page *page) | 28 | struct page *page) |
29 | { | 29 | { |
30 | return octeon_map_dma_mem(dev, page_address(page), PAGE_SIZE); | 30 | BUG(); |
31 | } | 31 | } |
32 | 32 | ||
33 | static inline unsigned long plat_dma_addr_to_phys(struct device *dev, | 33 | static inline unsigned long plat_dma_addr_to_phys(struct device *dev, |
diff --git a/arch/mips/include/asm/mach-ip27/dma-coherence.h b/arch/mips/include/asm/mach-ip27/dma-coherence.h index 7aa5ef9c19bc..016d0989b141 100644 --- a/arch/mips/include/asm/mach-ip27/dma-coherence.h +++ b/arch/mips/include/asm/mach-ip27/dma-coherence.h | |||
@@ -26,7 +26,8 @@ static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr, | |||
26 | return pa; | 26 | return pa; |
27 | } | 27 | } |
28 | 28 | ||
29 | static inline dma_addr_t plat_map_dma_mem_page(struct device *dev, struct page *page) | 29 | static inline dma_addr_t plat_map_dma_mem_page(struct device *dev, |
30 | struct page *page) | ||
30 | { | 31 | { |
31 | dma_addr_t pa = dev_to_baddr(dev, page_to_phys(page)); | 32 | dma_addr_t pa = dev_to_baddr(dev, page_to_phys(page)); |
32 | 33 | ||
diff --git a/arch/mips/include/asm/mach-ip32/dma-coherence.h b/arch/mips/include/asm/mach-ip32/dma-coherence.h index 55123fc0b2f0..c8fb5aacf50a 100644 --- a/arch/mips/include/asm/mach-ip32/dma-coherence.h +++ b/arch/mips/include/asm/mach-ip32/dma-coherence.h | |||
@@ -37,7 +37,8 @@ static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr, | |||
37 | return pa; | 37 | return pa; |
38 | } | 38 | } |
39 | 39 | ||
40 | static inline dma_addr_t plat_map_dma_mem_page(struct device *dev, struct page *page) | 40 | static inline dma_addr_t plat_map_dma_mem_page(struct device *dev, |
41 | struct page *page) | ||
41 | { | 42 | { |
42 | dma_addr_t pa; | 43 | dma_addr_t pa; |
43 | 44 | ||
diff --git a/arch/mips/include/asm/mach-jazz/dma-coherence.h b/arch/mips/include/asm/mach-jazz/dma-coherence.h index 2a10920473ec..302101b54acb 100644 --- a/arch/mips/include/asm/mach-jazz/dma-coherence.h +++ b/arch/mips/include/asm/mach-jazz/dma-coherence.h | |||
@@ -17,7 +17,8 @@ static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr, size_t | |||
17 | return vdma_alloc(virt_to_phys(addr), size); | 17 | return vdma_alloc(virt_to_phys(addr), size); |
18 | } | 18 | } |
19 | 19 | ||
20 | static inline dma_addr_t plat_map_dma_mem_page(struct device *dev, struct page *page) | 20 | static inline dma_addr_t plat_map_dma_mem_page(struct device *dev, |
21 | struct page *page) | ||
21 | { | 22 | { |
22 | return vdma_alloc(page_to_phys(page), PAGE_SIZE); | 23 | return vdma_alloc(page_to_phys(page), PAGE_SIZE); |
23 | } | 24 | } |