1 // SPDX-License-Identifier: GPL-2.0
3 * DMA operations that map to virtual addresses without flushing memory.
5 #include <linux/export.h>
7 #include <linux/dma-mapping.h>
8 #include <linux/scatterlist.h>
10 static void *dma_virt_alloc(struct device
*dev
, size_t size
,
11 dma_addr_t
*dma_handle
, gfp_t gfp
,
16 ret
= (void *)__get_free_pages(gfp
, get_order(size
));
18 *dma_handle
= (uintptr_t)ret
;
22 static void dma_virt_free(struct device
*dev
, size_t size
,
23 void *cpu_addr
, dma_addr_t dma_addr
,
26 free_pages((unsigned long)cpu_addr
, get_order(size
));
29 static dma_addr_t
dma_virt_map_page(struct device
*dev
, struct page
*page
,
30 unsigned long offset
, size_t size
,
31 enum dma_data_direction dir
,
34 return (uintptr_t)(page_address(page
) + offset
);
37 static int dma_virt_map_sg(struct device
*dev
, struct scatterlist
*sgl
,
38 int nents
, enum dma_data_direction dir
,
42 struct scatterlist
*sg
;
44 for_each_sg(sgl
, sg
, nents
, i
) {
46 sg_dma_address(sg
) = (uintptr_t)sg_virt(sg
);
47 sg_dma_len(sg
) = sg
->length
;
53 const struct dma_map_ops dma_virt_ops
= {
54 .alloc
= dma_virt_alloc
,
55 .free
= dma_virt_free
,
56 .map_page
= dma_virt_map_page
,
57 .map_sg
= dma_virt_map_sg
,
59 EXPORT_SYMBOL(dma_virt_ops
);