Arrested for multiple offences of header file inclusion.
[linux-2.6/linux-mips.git] / arch / mips / mm / dma-coherent.c
blobf6b3c722230c216c3d03d21ecc3be73d5ca0bef5
1 /*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
6 * Copyright (C) 2000 Ani Joshi <ajoshi@unixbox.com>
7 * Copyright (C) 2000, 2001 Ralf Baechle <ralf@gnu.org>
8 * swiped from i386, and cloned for MIPS by Geert, polished by Ralf.
9 */
10 #include <linux/config.h>
11 #include <linux/types.h>
12 #include <linux/dma-mapping.h>
13 #include <linux/mm.h>
14 #include <linux/module.h>
15 #include <linux/string.h>
17 #include <asm/cache.h>
18 #include <asm/io.h>
20 void *dma_alloc_noncoherent(struct device *dev, size_t size,
21 dma_addr_t * dma_handle, gfp_t gfp)
23 void *ret;
24 /* ignore region specifiers */
25 gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);
27 if (dev == NULL || (dev->coherent_dma_mask < 0xffffffff))
28 gfp |= GFP_DMA;
29 ret = (void *) __get_free_pages(gfp, get_order(size));
31 if (ret != NULL) {
32 memset(ret, 0, size);
33 *dma_handle = virt_to_phys(ret);
36 return ret;
39 EXPORT_SYMBOL(dma_alloc_noncoherent);
41 void *dma_alloc_coherent(struct device *dev, size_t size,
42 dma_addr_t * dma_handle, gfp_t gfp)
43 __attribute__((alias("dma_alloc_noncoherent")));
45 EXPORT_SYMBOL(dma_alloc_coherent);
47 void dma_free_noncoherent(struct device *dev, size_t size, void *vaddr,
48 dma_addr_t dma_handle)
50 unsigned long addr = (unsigned long) vaddr;
52 free_pages(addr, get_order(size));
55 EXPORT_SYMBOL(dma_free_noncoherent);
57 void dma_free_coherent(struct device *dev, size_t size, void *vaddr,
58 dma_addr_t dma_handle) __attribute__((alias("dma_free_noncoherent")));
60 EXPORT_SYMBOL(dma_free_coherent);
62 dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
63 enum dma_data_direction direction)
65 BUG_ON(direction == DMA_NONE);
67 return __pa(ptr);
70 EXPORT_SYMBOL(dma_map_single);
72 void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
73 enum dma_data_direction direction)
75 BUG_ON(direction == DMA_NONE);
78 EXPORT_SYMBOL(dma_unmap_single);
80 int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
81 enum dma_data_direction direction)
83 int i;
85 BUG_ON(direction == DMA_NONE);
87 for (i = 0; i < nents; i++, sg++) {
88 sg->dma_address = (dma_addr_t)page_to_phys(sg->page) + sg->offset;
91 return nents;
94 EXPORT_SYMBOL(dma_map_sg);
96 dma_addr_t dma_map_page(struct device *dev, struct page *page,
97 unsigned long offset, size_t size, enum dma_data_direction direction)
99 BUG_ON(direction == DMA_NONE);
101 return page_to_phys(page) + offset;
104 EXPORT_SYMBOL(dma_map_page);
106 void dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
107 enum dma_data_direction direction)
109 BUG_ON(direction == DMA_NONE);
112 EXPORT_SYMBOL(dma_unmap_page);
114 void dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
115 enum dma_data_direction direction)
117 BUG_ON(direction == DMA_NONE);
120 EXPORT_SYMBOL(dma_unmap_sg);
122 void dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
123 size_t size, enum dma_data_direction direction)
125 BUG_ON(direction == DMA_NONE);
128 EXPORT_SYMBOL(dma_sync_single_for_cpu);
130 void dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
131 size_t size, enum dma_data_direction direction)
133 BUG_ON(direction == DMA_NONE);
136 EXPORT_SYMBOL(dma_sync_single_for_device);
138 void dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
139 unsigned long offset, size_t size,
140 enum dma_data_direction direction)
142 BUG_ON(direction == DMA_NONE);
145 EXPORT_SYMBOL(dma_sync_single_range_for_cpu);
147 void dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
148 unsigned long offset, size_t size,
149 enum dma_data_direction direction)
151 BUG_ON(direction == DMA_NONE);
154 EXPORT_SYMBOL(dma_sync_single_range_for_device);
156 void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
157 enum dma_data_direction direction)
159 BUG_ON(direction == DMA_NONE);
162 EXPORT_SYMBOL(dma_sync_sg_for_cpu);
164 void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems,
165 enum dma_data_direction direction)
167 BUG_ON(direction == DMA_NONE);
170 EXPORT_SYMBOL(dma_sync_sg_for_device);
172 int dma_mapping_error(dma_addr_t dma_addr)
174 return 0;
177 EXPORT_SYMBOL(dma_mapping_error);
179 int dma_supported(struct device *dev, u64 mask)
182 * we fall back to GFP_DMA when the mask isn't all 1s,
183 * so we can't guarantee allocations that must be
184 * within a tighter range than GFP_DMA..
186 if (mask < 0x00ffffff)
187 return 0;
189 return 1;
192 EXPORT_SYMBOL(dma_supported);
194 int dma_is_consistent(dma_addr_t dma_addr)
196 return 1;
199 EXPORT_SYMBOL(dma_is_consistent);
201 void dma_cache_sync(void *vaddr, size_t size,
202 enum dma_data_direction direction)
204 BUG_ON(direction == DMA_NONE);
207 EXPORT_SYMBOL(dma_cache_sync);
209 /* The DAC routines are a PCIism.. */
211 #ifdef CONFIG_PCI
213 #include <linux/pci.h>
215 dma64_addr_t pci_dac_page_to_dma(struct pci_dev *pdev,
216 struct page *page, unsigned long offset, int direction)
218 return (dma64_addr_t)page_to_phys(page) + offset;
221 EXPORT_SYMBOL(pci_dac_page_to_dma);
223 struct page *pci_dac_dma_to_page(struct pci_dev *pdev,
224 dma64_addr_t dma_addr)
226 return mem_map + (dma_addr >> PAGE_SHIFT);
229 EXPORT_SYMBOL(pci_dac_dma_to_page);
231 unsigned long pci_dac_dma_to_offset(struct pci_dev *pdev,
232 dma64_addr_t dma_addr)
234 return dma_addr & ~PAGE_MASK;
237 EXPORT_SYMBOL(pci_dac_dma_to_offset);
239 void pci_dac_dma_sync_single_for_cpu(struct pci_dev *pdev,
240 dma64_addr_t dma_addr, size_t len, int direction)
242 BUG_ON(direction == PCI_DMA_NONE);
245 EXPORT_SYMBOL(pci_dac_dma_sync_single_for_cpu);
247 void pci_dac_dma_sync_single_for_device(struct pci_dev *pdev,
248 dma64_addr_t dma_addr, size_t len, int direction)
250 BUG_ON(direction == PCI_DMA_NONE);
253 EXPORT_SYMBOL(pci_dac_dma_sync_single_for_device);
255 #endif /* CONFIG_PCI */