mtd: nand: sunxi: prevent a small memory leak
[linux/fpc-iii.git] / lib / dma-noop.c
blob72145646857eec5fe0fb757e65c2cf835016e324
1 /*
2 * lib/dma-noop.c
4 * Simple DMA noop-ops that map 1:1 with memory
5 */
6 #include <linux/export.h>
7 #include <linux/mm.h>
8 #include <linux/dma-mapping.h>
9 #include <linux/scatterlist.h>
11 static void *dma_noop_alloc(struct device *dev, size_t size,
12 dma_addr_t *dma_handle, gfp_t gfp,
13 struct dma_attrs *attrs)
15 void *ret;
17 ret = (void *)__get_free_pages(gfp, get_order(size));
18 if (ret)
19 *dma_handle = virt_to_phys(ret);
20 return ret;
23 static void dma_noop_free(struct device *dev, size_t size,
24 void *cpu_addr, dma_addr_t dma_addr,
25 struct dma_attrs *attrs)
27 free_pages((unsigned long)cpu_addr, get_order(size));
30 static dma_addr_t dma_noop_map_page(struct device *dev, struct page *page,
31 unsigned long offset, size_t size,
32 enum dma_data_direction dir,
33 struct dma_attrs *attrs)
35 return page_to_phys(page) + offset;
38 static int dma_noop_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
39 enum dma_data_direction dir, struct dma_attrs *attrs)
41 int i;
42 struct scatterlist *sg;
44 for_each_sg(sgl, sg, nents, i) {
45 void *va;
47 BUG_ON(!sg_page(sg));
48 va = sg_virt(sg);
49 sg_dma_address(sg) = (dma_addr_t)virt_to_phys(va);
50 sg_dma_len(sg) = sg->length;
53 return nents;
56 static int dma_noop_mapping_error(struct device *dev, dma_addr_t dma_addr)
58 return 0;
61 static int dma_noop_supported(struct device *dev, u64 mask)
63 return 1;
66 struct dma_map_ops dma_noop_ops = {
67 .alloc = dma_noop_alloc,
68 .free = dma_noop_free,
69 .map_page = dma_noop_map_page,
70 .map_sg = dma_noop_map_sg,
71 .mapping_error = dma_noop_mapping_error,
72 .dma_supported = dma_noop_supported,
75 EXPORT_SYMBOL(dma_noop_ops);