x86/speculation/mds: Fix documentation typo
[linux/fpc-iii.git] / lib / dma-virt.c
blob8e61a02ef9ca06cb2aabfaef7484a44f31610ef1
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * lib/dma-virt.c
5 * DMA operations that map to virtual addresses without flushing memory.
6 */
7 #include <linux/export.h>
8 #include <linux/mm.h>
9 #include <linux/dma-mapping.h>
10 #include <linux/scatterlist.h>
12 static void *dma_virt_alloc(struct device *dev, size_t size,
13 dma_addr_t *dma_handle, gfp_t gfp,
14 unsigned long attrs)
16 void *ret;
18 ret = (void *)__get_free_pages(gfp, get_order(size));
19 if (ret)
20 *dma_handle = (uintptr_t)ret;
21 return ret;
24 static void dma_virt_free(struct device *dev, size_t size,
25 void *cpu_addr, dma_addr_t dma_addr,
26 unsigned long attrs)
28 free_pages((unsigned long)cpu_addr, get_order(size));
31 static dma_addr_t dma_virt_map_page(struct device *dev, struct page *page,
32 unsigned long offset, size_t size,
33 enum dma_data_direction dir,
34 unsigned long attrs)
36 return (uintptr_t)(page_address(page) + offset);
39 static int dma_virt_map_sg(struct device *dev, struct scatterlist *sgl,
40 int nents, enum dma_data_direction dir,
41 unsigned long attrs)
43 int i;
44 struct scatterlist *sg;
46 for_each_sg(sgl, sg, nents, i) {
47 BUG_ON(!sg_page(sg));
48 sg_dma_address(sg) = (uintptr_t)sg_virt(sg);
49 sg_dma_len(sg) = sg->length;
52 return nents;
55 const struct dma_map_ops dma_virt_ops = {
56 .alloc = dma_virt_alloc,
57 .free = dma_virt_free,
58 .map_page = dma_virt_map_page,
59 .map_sg = dma_virt_map_sg,
61 EXPORT_SYMBOL(dma_virt_ops);