Blame view
lib/dma-noop.c
1.62 KB
b24413180 License cleanup: ... |
1 |
// SPDX-License-Identifier: GPL-2.0 |
a8463d4b0 dma: Provide simp... |
2 3 4 |
/* * lib/dma-noop.c * |
1eec9e2be lib/dma-noop: Cla... |
5 |
* DMA operations that map to physical addresses without flushing memory. |
a8463d4b0 dma: Provide simp... |
6 7 8 9 10 |
*/ #include <linux/export.h> #include <linux/mm.h> #include <linux/dma-mapping.h> #include <linux/scatterlist.h> |
25f1e1887 dma: Take into ac... |
11 |
#include <linux/pfn.h> |
a8463d4b0 dma: Provide simp... |
12 13 14 |
static void *dma_noop_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t gfp, |
00085f1ef dma-mapping: use ... |
15 |
unsigned long attrs) |
a8463d4b0 dma: Provide simp... |
16 17 18 19 20 |
{ void *ret; ret = (void *)__get_free_pages(gfp, get_order(size)); if (ret) |
25f1e1887 dma: Take into ac... |
21 |
*dma_handle = virt_to_phys(ret) - PFN_PHYS(dev->dma_pfn_offset); |
a8463d4b0 dma: Provide simp... |
22 23 24 25 26 |
return ret; } static void dma_noop_free(struct device *dev, size_t size, void *cpu_addr, dma_addr_t dma_addr, |
00085f1ef dma-mapping: use ... |
27 |
unsigned long attrs) |
a8463d4b0 dma: Provide simp... |
28 29 30 31 32 33 34 |
{ free_pages((unsigned long)cpu_addr, get_order(size)); } static dma_addr_t dma_noop_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, enum dma_data_direction dir, |
00085f1ef dma-mapping: use ... |
35 |
unsigned long attrs) |
a8463d4b0 dma: Provide simp... |
36 |
{ |
25f1e1887 dma: Take into ac... |
37 |
return page_to_phys(page) + offset - PFN_PHYS(dev->dma_pfn_offset); |
a8463d4b0 dma: Provide simp... |
38 39 40 |
} static int dma_noop_map_sg(struct device *dev, struct scatterlist *sgl, int nents, |
00085f1ef dma-mapping: use ... |
41 42 |
enum dma_data_direction dir, unsigned long attrs) |
a8463d4b0 dma: Provide simp... |
43 44 45 46 47 |
{ int i; struct scatterlist *sg; for_each_sg(sgl, sg, nents, i) { |
25f1e1887 dma: Take into ac... |
48 |
dma_addr_t offset = PFN_PHYS(dev->dma_pfn_offset); |
a8463d4b0 dma: Provide simp... |
49 50 51 52 |
void *va; BUG_ON(!sg_page(sg)); va = sg_virt(sg); |
25f1e1887 dma: Take into ac... |
53 |
sg_dma_address(sg) = (dma_addr_t)virt_to_phys(va) - offset; |
a8463d4b0 dma: Provide simp... |
54 55 56 57 58 |
sg_dma_len(sg) = sg->length; } return nents; } |
5299709d0 treewide: Constif... |
59 |
const struct dma_map_ops dma_noop_ops = { |
a8463d4b0 dma: Provide simp... |
60 61 62 63 |
.alloc = dma_noop_alloc, .free = dma_noop_free, .map_page = dma_noop_map_page, .map_sg = dma_noop_map_sg, |
a8463d4b0 dma: Provide simp... |
64 65 66 |
}; EXPORT_SYMBOL(dma_noop_ops); |