This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / include / asm-sh64 / dma-mapping.h
1 #ifndef __ASM_SH_DMA_MAPPING_H
2 #define __ASM_SH_DMA_MAPPING_H
3
4 #include <linux/config.h>
5 #include <linux/mm.h>
6 #include <linux/device.h>
7 #include <asm/scatterlist.h>
8 #include <asm/io.h>
9
10 struct pci_dev;
11 extern void *consistent_alloc(struct pci_dev *hwdev, size_t size,
12                                     dma_addr_t *dma_handle);
13 extern void consistent_free(struct pci_dev *hwdev, size_t size,
14                                   void *vaddr, dma_addr_t dma_handle);
15
16 #define dma_supported(dev, mask)        (1)
17
18 static inline int dma_set_mask(struct device *dev, u64 mask)
19 {
20         if (!dev->dma_mask || !dma_supported(dev, mask))
21                 return -EIO;
22
23         *dev->dma_mask = mask;
24
25         return 0;
26 }
27
28 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
29                          dma_addr_t *dma_handle, int flag)
30 {
31         return consistent_alloc(NULL, size, dma_handle);
32 }
33
34 static inline void dma_free_coherent(struct device *dev, size_t size,
35                        void *vaddr, dma_addr_t dma_handle)
36 {
37         consistent_free(NULL, size, vaddr, dma_handle);
38 }
39
40 static inline void dma_cache_sync(void *vaddr, size_t size,
41                                   enum dma_data_direction dir)
42 {
43         dma_cache_wback_inv((unsigned long)vaddr, size);
44 }
45
46 static inline dma_addr_t dma_map_single(struct device *dev,
47                                         void *ptr, size_t size,
48                                         enum dma_data_direction dir)
49 {
50 #if defined(CONFIG_PCI) && !defined(CONFIG_SH_PCIDMA_NONCOHERENT)
51         if (dev->bus == &pci_bus_type)
52                 return virt_to_bus(ptr);
53 #endif
54         dma_cache_sync(ptr, size, dir);
55
56         return virt_to_bus(ptr);
57 }
58
59 #define dma_unmap_single(dev, addr, size, dir)  do { } while (0)
60
61 static inline int dma_map_sg(struct device *dev, struct scatterlist *sg,
62                              int nents, enum dma_data_direction dir)
63 {
64         int i;
65
66         for (i = 0; i < nents; i++) {
67 #if !defined(CONFIG_PCI) || defined(CONFIG_SH_PCIDMA_NONCOHERENT)
68                 dma_cache_sync(page_address(sg[i].page) + sg[i].offset,
69                                sg[i].length, dir);
70 #endif
71                 sg[i].dma_address = page_to_phys(sg[i].page) + sg[i].offset;
72         }
73
74         return nents;
75 }
76
77 #define dma_unmap_sg(dev, sg, nents, dir)       do { } while (0)
78
79 static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
80                                       unsigned long offset, size_t size,
81                                       enum dma_data_direction dir)
82 {
83         return dma_map_single(dev, page_address(page) + offset, size, dir);
84 }
85
86 static inline void dma_unmap_page(struct device *dev, dma_addr_t dma_address,
87                                   size_t size, enum dma_data_direction dir)
88 {
89         dma_unmap_single(dev, dma_address, size, dir);
90 }
91
92 static inline void dma_sync_single(struct device *dev, dma_addr_t dma_handle,
93                                    size_t size, enum dma_data_direction dir)
94 {
95 #if defined(CONFIG_PCI) && !defined(CONFIG_SH_PCIDMA_NONCOHERENT)
96         if (dev->bus == &pci_bus_type)
97                 return;
98 #endif
99         dma_cache_sync(bus_to_virt(dma_handle), size, dir);
100 }
101
102 static inline void dma_sync_single_range(struct device *dev,
103                                          dma_addr_t dma_handle,
104                                          unsigned long offset, size_t size,
105                                          enum dma_data_direction dir)
106 {
107 #if defined(CONFIG_PCI) && !defined(CONFIG_SH_PCIDMA_NONCOHERENT)
108         if (dev->bus == &pci_bus_type)
109                 return;
110 #endif
111         dma_cache_sync(bus_to_virt(dma_handle) + offset, size, dir);
112 }
113
114 static inline void dma_sync_sg(struct device *dev, struct scatterlist *sg,
115                                int nelems, enum dma_data_direction dir)
116 {
117         int i;
118
119         for (i = 0; i < nelems; i++) {
120 #if !defined(CONFIG_PCI) || defined(CONFIG_SH_PCIDMA_NONCOHERENT)
121                 dma_cache_sync(page_address(sg[i].page) + sg[i].offset,
122                                sg[i].length, dir);
123 #endif
124                 sg[i].dma_address = page_to_phys(sg[i].page) + sg[i].offset;
125         }
126 }
127
128 static inline void dma_sync_single_for_cpu(struct device *dev,
129                                            dma_addr_t dma_handle, size_t size,
130                                            enum dma_data_direction dir)
131         __attribute__ ((alias("dma_sync_single")));
132
133 static inline void dma_sync_single_for_device(struct device *dev,
134                                            dma_addr_t dma_handle, size_t size,
135                                            enum dma_data_direction dir)
136         __attribute__ ((alias("dma_sync_single")));
137
138 static inline void dma_sync_sg_for_cpu(struct device *dev,
139                                        struct scatterlist *sg, int nelems,
140                                        enum dma_data_direction dir)
141         __attribute__ ((alias("dma_sync_sg")));
142
143 static inline void dma_sync_sg_for_device(struct device *dev,
144                                        struct scatterlist *sg, int nelems,
145                                        enum dma_data_direction dir)
146         __attribute__ ((alias("dma_sync_sg")));
147
148 static inline int dma_get_cache_alignment(void)
149 {
150         /*
151          * Each processor family will define its own L1_CACHE_SHIFT,
152          * L1_CACHE_BYTES wraps to this, so this is always safe.
153          */
154         return L1_CACHE_BYTES;
155 }
156
157 static inline int dma_mapping_error(dma_addr_t dma_addr)
158 {
159         return dma_addr == 0;
160 }
161
162 #endif /* __ASM_SH_DMA_MAPPING_H */
163