cris: convert to dma_map_ops
[deliverable/linux.git] / arch / cris / arch-v32 / drivers / pci / dma.c
1 /*
2 * Dynamic DMA mapping support.
3 *
4 * On cris there is no hardware dynamic DMA address translation,
5 * so consistent alloc/free are merely page allocation/freeing.
6 * The rest of the dynamic DMA mapping interface is implemented
7 * in asm/pci.h.
8 *
9 * Borrowed from i386.
10 */
11
12 #include <linux/types.h>
13 #include <linux/mm.h>
14 #include <linux/string.h>
15 #include <linux/pci.h>
16 #include <linux/gfp.h>
17 #include <asm/io.h>
18
19 static void *v32_dma_alloc(struct device *dev, size_t size,
20 dma_addr_t *dma_handle, gfp_t gfp, struct dma_attrs *attrs)
21 {
22 void *ret;
23
24 /* ignore region specifiers */
25 gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);
26
27 if (dev == NULL || (dev->coherent_dma_mask < 0xffffffff))
28 gfp |= GFP_DMA;
29
30 ret = (void *)__get_free_pages(gfp, get_order(size));
31
32 if (ret != NULL) {
33 memset(ret, 0, size);
34 *dma_handle = virt_to_phys(ret);
35 }
36 return ret;
37 }
38
39 static void v32_dma_free(struct device *dev, size_t size, void *vaddr,
40 dma_addr_t dma_handle, struct dma_attrs *attrs)
41 {
42 free_pages((unsigned long)vaddr, get_order(size));
43 }
44
45 static inline dma_addr_t v32_dma_map_page(struct device *dev,
46 struct page *page, unsigned long offset, size_t size,
47 enum dma_data_direction direction,
48 struct dma_attrs *attrs)
49 {
50 return page_to_phys(page) + offset;
51 }
52
53 static inline int v32_dma_map_sg(struct device *dev, struct scatterlist *sg,
54 int nents, enum dma_data_direction direction,
55 struct dma_attrs *attrs)
56 {
57 printk("Map sg\n");
58 return nents;
59 }
60
61 static inline int v32_dma_supported(struct device *dev, u64 mask)
62 {
63 /*
64 * we fall back to GFP_DMA when the mask isn't all 1s,
65 * so we can't guarantee allocations that must be
66 * within a tighter range than GFP_DMA..
67 */
68 if (mask < 0x00ffffff)
69 return 0;
70 return 1;
71 }
72
73 struct dma_map_ops v32_dma_ops = {
74 .alloc = v32_dma_alloc,
75 .free = v32_dma_free,
76 .map_page = v32_dma_map_page,
77 .map_sg = v32_dma_map_sg,
78 .dma_supported = v32_dma_supported,
79 };
80 EXPORT_SYMBOL(v32_dma_ops);
This page took 0.03166 seconds and 5 git commands to generate.