1
2
3
4
5
6
7
8
9
10
11
12#include <linux/types.h>
13#include <linux/slab.h>
14#include <linux/dma-mapping.h>
15#include <linux/list.h>
16#include <linux/pci.h>
17#include <linux/highmem.h>
18#include <linux/scatterlist.h>
19#include <asm/io.h>
20
21void *dma_alloc_coherent(struct device *hwdev, size_t size, dma_addr_t *dma_handle, gfp_t gfp)
22{
23 void *ret;
24
25 ret = consistent_alloc(gfp, size, dma_handle);
26 if (ret)
27 memset(ret, 0, size);
28
29 return ret;
30}
31
32EXPORT_SYMBOL(dma_alloc_coherent);
33
34void dma_free_coherent(struct device *hwdev, size_t size, void *vaddr, dma_addr_t dma_handle)
35{
36 consistent_free(vaddr);
37}
38
39EXPORT_SYMBOL(dma_free_coherent);
40
41
42
43
44
45
46
47
48dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
49 enum dma_data_direction direction)
50{
51 BUG_ON(direction == DMA_NONE);
52
53 frv_cache_wback_inv((unsigned long) ptr, (unsigned long) ptr + size);
54
55 return virt_to_bus(ptr);
56}
57
58EXPORT_SYMBOL(dma_map_single);
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
77 enum dma_data_direction direction)
78{
79 unsigned long dampr2;
80 void *vaddr;
81 int i;
82
83 BUG_ON(direction == DMA_NONE);
84
85 dampr2 = __get_DAMPR(2);
86
87 for (i = 0; i < nents; i++) {
88 vaddr = kmap_atomic(sg_page(&sg[i]), __KM_CACHE);
89
90 frv_dcache_writeback((unsigned long) vaddr,
91 (unsigned long) vaddr + PAGE_SIZE);
92
93 }
94
95 kunmap_atomic(vaddr, __KM_CACHE);
96 if (dampr2) {
97 __set_DAMPR(2, dampr2);
98 __set_IAMPR(2, dampr2);
99 }
100
101 return nents;
102}
103
104EXPORT_SYMBOL(dma_map_sg);
105
106
107
108
109
110
111
112
113dma_addr_t dma_map_page(struct device *dev, struct page *page, unsigned long offset,
114 size_t size, enum dma_data_direction direction)
115{
116 BUG_ON(direction == DMA_NONE);
117 flush_dcache_page(page);
118 return (dma_addr_t) page_to_phys(page) + offset;
119}
120
121EXPORT_SYMBOL(dma_map_page);
122