Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / sh / kernel / dma-nommu.c
blob62b485107eae0fbd5c6dc5fc76f816c42443c88d
1 /*
2 * DMA mapping support for platforms lacking IOMMUs.
4 * Copyright (C) 2009 Paul Mundt
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10 #include <linux/dma-mapping.h>
11 #include <linux/io.h>
12 #include <asm/cacheflush.h>
14 static dma_addr_t nommu_map_page(struct device *dev, struct page *page,
15 unsigned long offset, size_t size,
16 enum dma_data_direction dir,
17 unsigned long attrs)
19 dma_addr_t addr = page_to_phys(page) + offset;
21 WARN_ON(size == 0);
23 if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
24 sh_sync_dma_for_device(page_address(page) + offset, size, dir);
26 return addr;
29 static int nommu_map_sg(struct device *dev, struct scatterlist *sg,
30 int nents, enum dma_data_direction dir,
31 unsigned long attrs)
33 struct scatterlist *s;
34 int i;
36 WARN_ON(nents == 0 || sg[0].length == 0);
38 for_each_sg(sg, s, nents, i) {
39 BUG_ON(!sg_page(s));
41 if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
42 sh_sync_dma_for_device(sg_virt(s), s->length, dir);
44 s->dma_address = sg_phys(s);
45 s->dma_length = s->length;
48 return nents;
51 #ifdef CONFIG_DMA_NONCOHERENT
52 static void nommu_sync_single_for_device(struct device *dev, dma_addr_t addr,
53 size_t size, enum dma_data_direction dir)
55 sh_sync_dma_for_device(phys_to_virt(addr), size, dir);
58 static void nommu_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
59 int nelems, enum dma_data_direction dir)
61 struct scatterlist *s;
62 int i;
64 for_each_sg(sg, s, nelems, i)
65 sh_sync_dma_for_device(sg_virt(s), s->length, dir);
67 #endif
69 const struct dma_map_ops nommu_dma_ops = {
70 .alloc = dma_generic_alloc_coherent,
71 .free = dma_generic_free_coherent,
72 .map_page = nommu_map_page,
73 .map_sg = nommu_map_sg,
74 #ifdef CONFIG_DMA_NONCOHERENT
75 .sync_single_for_device = nommu_sync_single_for_device,
76 .sync_sg_for_device = nommu_sync_sg_for_device,
77 #endif
78 .is_phys = 1,
81 void __init no_iommu_init(void)
83 if (dma_ops)
84 return;
85 dma_ops = &nommu_dma_ops;