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>
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);
16 #define dma_supported(dev, mask) (1)
18 static inline int dma_set_mask(struct device *dev, u64 mask)
20 if (!dev->dma_mask || !dma_supported(dev, mask))
23 *dev->dma_mask = mask;
28 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
29 dma_addr_t *dma_handle, int flag)
31 return consistent_alloc(NULL, size, dma_handle);
34 static inline void dma_free_coherent(struct device *dev, size_t size,
35 void *vaddr, dma_addr_t dma_handle)
37 consistent_free(NULL, size, vaddr, dma_handle);
40 static inline void dma_cache_sync(void *vaddr, size_t size,
41 enum dma_data_direction dir)
43 dma_cache_wback_inv((unsigned long)vaddr, size);
46 static inline dma_addr_t dma_map_single(struct device *dev,
47 void *ptr, size_t size,
48 enum dma_data_direction dir)
50 #if defined(CONFIG_PCI) && !defined(CONFIG_SH_PCIDMA_NONCOHERENT)
51 if (dev->bus == &pci_bus_type)
52 return virt_to_bus(ptr);
54 dma_cache_sync(ptr, size, dir);
56 return virt_to_bus(ptr);
59 #define dma_unmap_single(dev, addr, size, dir) do { } while (0)
61 static inline int dma_map_sg(struct device *dev, struct scatterlist *sg,
62 int nents, enum dma_data_direction dir)
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,
71 sg[i].dma_address = page_to_phys(sg[i].page) + sg[i].offset;
77 #define dma_unmap_sg(dev, sg, nents, dir) do { } while (0)
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)
83 return dma_map_single(dev, page_address(page) + offset, size, dir);
86 static inline void dma_unmap_page(struct device *dev, dma_addr_t dma_address,
87 size_t size, enum dma_data_direction dir)
89 dma_unmap_single(dev, dma_address, size, dir);
92 static inline void dma_sync_single(struct device *dev, dma_addr_t dma_handle,
93 size_t size, enum dma_data_direction dir)
95 #if defined(CONFIG_PCI) && !defined(CONFIG_SH_PCIDMA_NONCOHERENT)
96 if (dev->bus == &pci_bus_type)
99 dma_cache_sync(bus_to_virt(dma_handle), size, dir);
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)
107 #if defined(CONFIG_PCI) && !defined(CONFIG_SH_PCIDMA_NONCOHERENT)
108 if (dev->bus == &pci_bus_type)
111 dma_cache_sync(bus_to_virt(dma_handle) + offset, size, dir);
114 static inline void dma_sync_sg(struct device *dev, struct scatterlist *sg,
115 int nelems, enum dma_data_direction dir)
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,
124 sg[i].dma_address = page_to_phys(sg[i].page) + sg[i].offset;
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")));
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")));
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")));
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")));
148 static inline int dma_get_cache_alignment(void)
151 * Each processor family will define its own L1_CACHE_SHIFT,
152 * L1_CACHE_BYTES wraps to this, so this is always safe.
154 return L1_CACHE_BYTES;
157 static inline int dma_mapping_error(dma_addr_t dma_addr)
159 return dma_addr == 0;
162 #endif /* __ASM_SH_DMA_MAPPING_H */