1
2
3
4
5
6
7#include <linux/dma-mapping.h>
8#include <linux/kernel.h>
9#include <linux/scatterlist.h>
10#include <linux/module.h>
11#include <asm/pgalloc.h>
12
13static void *dma_alloc(struct device *dev, size_t size,
14 dma_addr_t *dma_handle, gfp_t gfp,
15 unsigned long attrs)
16{
17 void *ret;
18
19
20 gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);
21
22 if (dev == NULL || (*dev->dma_mask < 0xffffffff))
23 gfp |= GFP_DMA;
24 ret = (void *)__get_free_pages(gfp, get_order(size));
25
26 if (ret != NULL) {
27 memset(ret, 0, size);
28 *dma_handle = virt_to_phys(ret);
29 }
30 return ret;
31}
32
33static void dma_free(struct device *dev, size_t size,
34 void *vaddr, dma_addr_t dma_handle,
35 unsigned long attrs)
36
37{
38 free_pages((unsigned long)vaddr, get_order(size));
39}
40
41static dma_addr_t map_page(struct device *dev, struct page *page,
42 unsigned long offset, size_t size,
43 enum dma_data_direction direction,
44 unsigned long attrs)
45{
46 return page_to_phys(page) + offset;
47}
48
49static int map_sg(struct device *dev, struct scatterlist *sgl,
50 int nents, enum dma_data_direction direction,
51 unsigned long attrs)
52{
53 struct scatterlist *sg;
54 int i;
55
56 for_each_sg(sgl, sg, nents, i) {
57 sg->dma_address = sg_phys(sg);
58 }
59
60 return nents;
61}
62
63const struct dma_map_ops h8300_dma_map_ops = {
64 .alloc = dma_alloc,
65 .free = dma_free,
66 .map_page = map_page,
67 .map_sg = map_sg,
68};
69EXPORT_SYMBOL(h8300_dma_map_ops);
70