diff options
Diffstat (limited to 'arch/microblaze/include/asm/dma-mapping.h')
-rw-r--r-- | arch/microblaze/include/asm/dma-mapping.h | 155 |
1 files changed, 154 insertions, 1 deletions
diff --git a/arch/microblaze/include/asm/dma-mapping.h b/arch/microblaze/include/asm/dma-mapping.h index d00e40099165..096fa96ee736 100644 --- a/arch/microblaze/include/asm/dma-mapping.h +++ b/arch/microblaze/include/asm/dma-mapping.h | |||
@@ -1 +1,154 @@ | |||
1 | #include <asm-generic/dma-mapping-broken.h> | 1 | /* |
2 | * Implements the generic device dma API for microblaze and the pci | ||
3 | * | ||
4 | * Copyright (C) 2009-2010 Michal Simek <monstr@monstr.eu> | ||
5 | * Copyright (C) 2009-2010 PetaLogix | ||
6 | * | ||
7 | * This file is subject to the terms and conditions of the GNU General | ||
8 | * Public License. See the file COPYING in the main directory of this | ||
9 | * archive for more details. | ||
10 | * | ||
11 | * This file is base on powerpc and x86 dma-mapping.h versions | ||
12 | * Copyright (C) 2004 IBM | ||
13 | */ | ||
14 | |||
15 | #ifndef _ASM_MICROBLAZE_DMA_MAPPING_H | ||
16 | #define _ASM_MICROBLAZE_DMA_MAPPING_H | ||
17 | |||
18 | /* | ||
19 | * See Documentation/PCI/PCI-DMA-mapping.txt and | ||
20 | * Documentation/DMA-API.txt for documentation. | ||
21 | */ | ||
22 | |||
23 | #include <linux/types.h> | ||
24 | #include <linux/cache.h> | ||
25 | #include <linux/mm.h> | ||
26 | #include <linux/scatterlist.h> | ||
27 | #include <linux/dma-debug.h> | ||
28 | #include <linux/dma-attrs.h> | ||
29 | #include <asm/io.h> | ||
30 | #include <asm-generic/dma-coherent.h> | ||
31 | |||
32 | #define DMA_ERROR_CODE (~(dma_addr_t)0x0) | ||
33 | |||
34 | #define __dma_alloc_coherent(dev, gfp, size, handle) NULL | ||
35 | #define __dma_free_coherent(size, addr) ((void)0) | ||
36 | #define __dma_sync(addr, size, rw) ((void)0) | ||
37 | #define __dma_sync_page(pg, off, sz, rw) ((void)0) | ||
38 | |||
39 | static inline unsigned long device_to_mask(struct device *dev) | ||
40 | { | ||
41 | if (dev->dma_mask && *dev->dma_mask) | ||
42 | return *dev->dma_mask; | ||
43 | /* Assume devices without mask can take 32 bit addresses */ | ||
44 | return 0xfffffffful; | ||
45 | } | ||
46 | |||
47 | extern struct dma_map_ops *dma_ops; | ||
48 | |||
49 | /* | ||
50 | * Available generic sets of operations | ||
51 | */ | ||
52 | extern struct dma_map_ops dma_direct_ops; | ||
53 | |||
54 | static inline struct dma_map_ops *get_dma_ops(struct device *dev) | ||
55 | { | ||
56 | /* We don't handle the NULL dev case for ISA for now. We could | ||
57 | * do it via an out of line call but it is not needed for now. The | ||
58 | * only ISA DMA device we support is the floppy and we have a hack | ||
59 | * in the floppy driver directly to get a device for us. | ||
60 | */ | ||
61 | if (unlikely(!dev) || !dev->archdata.dma_ops) | ||
62 | return NULL; | ||
63 | |||
64 | return dev->archdata.dma_ops; | ||
65 | } | ||
66 | |||
67 | static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops) | ||
68 | { | ||
69 | dev->archdata.dma_ops = ops; | ||
70 | } | ||
71 | |||
72 | static inline int dma_supported(struct device *dev, u64 mask) | ||
73 | { | ||
74 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
75 | |||
76 | if (unlikely(!ops)) | ||
77 | return 0; | ||
78 | if (!ops->dma_supported) | ||
79 | return 1; | ||
80 | return ops->dma_supported(dev, mask); | ||
81 | } | ||
82 | |||
83 | #ifdef CONFIG_PCI | ||
84 | /* We have our own implementation of pci_set_dma_mask() */ | ||
85 | #define HAVE_ARCH_PCI_SET_DMA_MASK | ||
86 | |||
87 | #endif | ||
88 | |||
89 | static inline int dma_set_mask(struct device *dev, u64 dma_mask) | ||
90 | { | ||
91 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
92 | |||
93 | if (unlikely(ops == NULL)) | ||
94 | return -EIO; | ||
95 | if (ops->set_dma_mask) | ||
96 | return ops->set_dma_mask(dev, dma_mask); | ||
97 | if (!dev->dma_mask || !dma_supported(dev, dma_mask)) | ||
98 | return -EIO; | ||
99 | *dev->dma_mask = dma_mask; | ||
100 | return 0; | ||
101 | } | ||
102 | |||
103 | #include <asm-generic/dma-mapping-common.h> | ||
104 | |||
105 | static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) | ||
106 | { | ||
107 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
108 | if (ops->mapping_error) | ||
109 | return ops->mapping_error(dev, dma_addr); | ||
110 | |||
111 | return (dma_addr == DMA_ERROR_CODE); | ||
112 | } | ||
113 | |||
114 | #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) | ||
115 | #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) | ||
116 | #define dma_is_consistent(d, h) (1) | ||
117 | |||
118 | static inline void *dma_alloc_coherent(struct device *dev, size_t size, | ||
119 | dma_addr_t *dma_handle, gfp_t flag) | ||
120 | { | ||
121 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
122 | void *memory; | ||
123 | |||
124 | BUG_ON(!ops); | ||
125 | |||
126 | memory = ops->alloc_coherent(dev, size, dma_handle, flag); | ||
127 | |||
128 | debug_dma_alloc_coherent(dev, size, *dma_handle, memory); | ||
129 | return memory; | ||
130 | } | ||
131 | |||
132 | static inline void dma_free_coherent(struct device *dev, size_t size, | ||
133 | void *cpu_addr, dma_addr_t dma_handle) | ||
134 | { | ||
135 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
136 | |||
137 | BUG_ON(!ops); | ||
138 | debug_dma_free_coherent(dev, size, cpu_addr, dma_handle); | ||
139 | ops->free_coherent(dev, size, cpu_addr, dma_handle); | ||
140 | } | ||
141 | |||
142 | static inline int dma_get_cache_alignment(void) | ||
143 | { | ||
144 | return L1_CACHE_BYTES; | ||
145 | } | ||
146 | |||
147 | static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size, | ||
148 | enum dma_data_direction direction) | ||
149 | { | ||
150 | BUG_ON(direction == DMA_NONE); | ||
151 | __dma_sync(vaddr, size, (int)direction); | ||
152 | } | ||
153 | |||
154 | #endif /* _ASM_MICROBLAZE_DMA_MAPPING_H */ | ||