1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Dummy DMA ops that always fail.
4 */
5 #include <linux/dma-map-ops.h>
6
dma_dummy_mmap(struct device * dev,struct vm_area_struct * vma,void * cpu_addr,dma_addr_t dma_addr,size_t size,unsigned long attrs)7 static int dma_dummy_mmap(struct device *dev, struct vm_area_struct *vma,
8 void *cpu_addr, dma_addr_t dma_addr, size_t size,
9 unsigned long attrs)
10 {
11 return -ENXIO;
12 }
13
dma_dummy_map_page(struct device * dev,struct page * page,unsigned long offset,size_t size,enum dma_data_direction dir,unsigned long attrs)14 static dma_addr_t dma_dummy_map_page(struct device *dev, struct page *page,
15 unsigned long offset, size_t size, enum dma_data_direction dir,
16 unsigned long attrs)
17 {
18 return DMA_MAPPING_ERROR;
19 }
dma_dummy_unmap_page(struct device * dev,dma_addr_t dma_handle,size_t size,enum dma_data_direction dir,unsigned long attrs)20 static void dma_dummy_unmap_page(struct device *dev, dma_addr_t dma_handle,
21 size_t size, enum dma_data_direction dir, unsigned long attrs)
22 {
23 /*
24 * Dummy ops doesn't support map_page, so unmap_page should never be
25 * called.
26 */
27 WARN_ON_ONCE(true);
28 }
29
dma_dummy_map_sg(struct device * dev,struct scatterlist * sgl,int nelems,enum dma_data_direction dir,unsigned long attrs)30 static int dma_dummy_map_sg(struct device *dev, struct scatterlist *sgl,
31 int nelems, enum dma_data_direction dir,
32 unsigned long attrs)
33 {
34 return -EINVAL;
35 }
36
dma_dummy_unmap_sg(struct device * dev,struct scatterlist * sgl,int nelems,enum dma_data_direction dir,unsigned long attrs)37 static void dma_dummy_unmap_sg(struct device *dev, struct scatterlist *sgl,
38 int nelems, enum dma_data_direction dir,
39 unsigned long attrs)
40 {
41 /*
42 * Dummy ops doesn't support map_sg, so unmap_sg should never be called.
43 */
44 WARN_ON_ONCE(true);
45 }
46
dma_dummy_supported(struct device * hwdev,u64 mask)47 static int dma_dummy_supported(struct device *hwdev, u64 mask)
48 {
49 return 0;
50 }
51
52 const struct dma_map_ops dma_dummy_ops = {
53 .mmap = dma_dummy_mmap,
54 .map_page = dma_dummy_map_page,
55 .unmap_page = dma_dummy_unmap_page,
56 .map_sg = dma_dummy_map_sg,
57 .unmap_sg = dma_dummy_unmap_sg,
58 .dma_supported = dma_dummy_supported,
59 };
60