xref: /openbmc/linux/arch/arm/xen/mm.c (revision 930beb5a)
1 #include <linux/bootmem.h>
2 #include <linux/gfp.h>
3 #include <linux/export.h>
4 #include <linux/slab.h>
5 #include <linux/types.h>
6 #include <linux/dma-mapping.h>
7 #include <linux/vmalloc.h>
8 #include <linux/swiotlb.h>
9 
10 #include <xen/xen.h>
11 #include <xen/interface/memory.h>
12 #include <xen/swiotlb-xen.h>
13 
14 #include <asm/cacheflush.h>
15 #include <asm/xen/page.h>
16 #include <asm/xen/hypercall.h>
17 #include <asm/xen/interface.h>
18 
19 int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order,
20 				 unsigned int address_bits,
21 				 dma_addr_t *dma_handle)
22 {
23 	if (!xen_initial_domain())
24 		return -EINVAL;
25 
26 	/* we assume that dom0 is mapped 1:1 for now */
27 	*dma_handle = pstart;
28 	return 0;
29 }
30 EXPORT_SYMBOL_GPL(xen_create_contiguous_region);
31 
32 void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order)
33 {
34 	return;
35 }
36 EXPORT_SYMBOL_GPL(xen_destroy_contiguous_region);
37 
38 struct dma_map_ops *xen_dma_ops;
39 EXPORT_SYMBOL_GPL(xen_dma_ops);
40 
41 static struct dma_map_ops xen_swiotlb_dma_ops = {
42 	.mapping_error = xen_swiotlb_dma_mapping_error,
43 	.alloc = xen_swiotlb_alloc_coherent,
44 	.free = xen_swiotlb_free_coherent,
45 	.sync_single_for_cpu = xen_swiotlb_sync_single_for_cpu,
46 	.sync_single_for_device = xen_swiotlb_sync_single_for_device,
47 	.sync_sg_for_cpu = xen_swiotlb_sync_sg_for_cpu,
48 	.sync_sg_for_device = xen_swiotlb_sync_sg_for_device,
49 	.map_sg = xen_swiotlb_map_sg_attrs,
50 	.unmap_sg = xen_swiotlb_unmap_sg_attrs,
51 	.map_page = xen_swiotlb_map_page,
52 	.unmap_page = xen_swiotlb_unmap_page,
53 	.dma_supported = xen_swiotlb_dma_supported,
54 	.set_dma_mask = xen_swiotlb_set_dma_mask,
55 };
56 
57 int __init xen_mm_init(void)
58 {
59 	if (!xen_initial_domain())
60 		return 0;
61 	xen_swiotlb_init(1, false);
62 	xen_dma_ops = &xen_swiotlb_dma_ops;
63 	return 0;
64 }
65 arch_initcall(xen_mm_init);
66