1 #ifndef __ASM_SH_DMA_MAPPING_H
2 #define __ASM_SH_DMA_MAPPING_H
4 #include <linux/config.h>
6 #include <linux/device.h>
7 #include <asm/scatterlist.h>
10 /* arch/sh/mm/consistent.c */
11 extern void *consistent_alloc(int gfp, size_t size, dma_addr_t *handle);
12 extern void consistent_free(void *vaddr, size_t size);
13 extern void consistent_sync(void *vaddr, size_t size, int direction);
15 #ifdef CONFIG_SH_DREAMCAST
17 extern struct bus_type pci_bus_type;
18 extern void *__pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
19 dma_addr_t *dma_handle);
20 extern void __pci_free_consistent(struct pci_dev *hwdev, size_t size,
21 void *vaddr, dma_addr_t dma_handle);
24 #define dma_supported(dev, mask) (1)
26 static inline int dma_set_mask(struct device *dev, u64 mask)
28 if (!dev->dma_mask || !dma_supported(dev, mask))
31 *dev->dma_mask = mask;
36 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
37 dma_addr_t *dma_handle, int flag)
40 * Some platforms have special pci_alloc_consistent() implementations,
41 * in these instances we can't use the generic consistent_alloc().
43 #ifdef CONFIG_SH_DREAMCAST
44 if (dev && dev->bus == &pci_bus_type)
45 return __pci_alloc_consistent(NULL, size, dma_handle);
48 return consistent_alloc(flag, size, dma_handle);
51 static inline void dma_free_coherent(struct device *dev, size_t size,
52 void *vaddr, dma_addr_t dma_handle)
55 * Same note as above applies to pci_free_consistent()..
57 #ifdef CONFIG_SH_DREAMCAST
58 if (dev && dev->bus == &pci_bus_type) {
59 __pci_free_consistent(NULL, size, vaddr, dma_handle);
64 consistent_free(vaddr, size);
67 static inline void dma_cache_sync(void *vaddr, size_t size,
68 enum dma_data_direction dir)
70 consistent_sync(vaddr, size, (int)dir);
73 static inline dma_addr_t dma_map_single(struct device *dev,
74 void *ptr, size_t size,
75 enum dma_data_direction dir)
77 #if defined(CONFIG_PCI) && !defined(CONFIG_SH_PCIDMA_NONCOHERENT)
78 if (dev->bus == &pci_bus_type)
79 return virt_to_bus(ptr);
81 dma_cache_sync(ptr, size, dir);
83 return virt_to_bus(ptr);
86 #define dma_unmap_single(dev, addr, size, dir) do { } while (0)
88 static inline int dma_map_sg(struct device *dev, struct scatterlist *sg,
89 int nents, enum dma_data_direction dir)
93 for (i = 0; i < nents; i++) {
94 #if !defined(CONFIG_PCI) || defined(CONFIG_SH_PCIDMA_NONCOHERENT)
95 dma_cache_sync(page_address(sg[i].page) + sg[i].offset,
98 sg[i].dma_address = page_to_phys(sg[i].page) + sg[i].offset;
104 #define dma_unmap_sg(dev, sg, nents, dir) do { } while (0)
106 static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
107 unsigned long offset, size_t size,
108 enum dma_data_direction dir)
110 return dma_map_single(dev, page_address(page) + offset, size, dir);
113 static inline void dma_unmap_page(struct device *dev, dma_addr_t dma_address,
114 size_t size, enum dma_data_direction dir)
116 dma_unmap_single(dev, dma_address, size, dir);
119 static inline void dma_sync_single(struct device *dev, dma_addr_t dma_handle,
120 size_t size, enum dma_data_direction dir)
122 #if defined(CONFIG_PCI) && !defined(CONFIG_SH_PCIDMA_NONCOHERENT)
123 if (dev->bus == &pci_bus_type)
126 dma_cache_sync(bus_to_virt(dma_handle), size, dir);
129 static inline void dma_sync_single_range(struct device *dev,
130 dma_addr_t dma_handle,
131 unsigned long offset, size_t size,
132 enum dma_data_direction dir)
134 #if defined(CONFIG_PCI) && !defined(CONFIG_SH_PCIDMA_NONCOHERENT)
135 if (dev->bus == &pci_bus_type)
138 dma_cache_sync(bus_to_virt(dma_handle) + offset, size, dir);
141 static inline void dma_sync_sg(struct device *dev, struct scatterlist *sg,
142 int nelems, enum dma_data_direction dir)
146 for (i = 0; i < nelems; i++) {
147 #if !defined(CONFIG_PCI) || defined(CONFIG_SH_PCIDMA_NONCOHERENT)
148 dma_cache_sync(page_address(sg[i].page) + sg[i].offset,
151 sg[i].dma_address = page_to_phys(sg[i].page) + sg[i].offset;
155 static inline int dma_get_cache_alignment(void)
158 * Each processor family will define its own L1_CACHE_SHIFT,
159 * L1_CACHE_BYTES wraps to this, so this is always safe.
161 return L1_CACHE_BYTES;
164 #endif /* __ASM_SH_DMA_MAPPING_H */