Merge branch 'packaging' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek...
[pandora-kernel.git] / arch / x86 / xen / pci-swiotlb-xen.c
1 /* Glue code to lib/swiotlb-xen.c */
2
3 #include <linux/dma-mapping.h>
4 #include <xen/swiotlb-xen.h>
5
6 #include <asm/xen/hypervisor.h>
7 #include <xen/xen.h>
8 #include <asm/iommu_table.h>
9
10 int xen_swiotlb __read_mostly;
11
12 static struct dma_map_ops xen_swiotlb_dma_ops = {
13         .mapping_error = xen_swiotlb_dma_mapping_error,
14         .alloc_coherent = xen_swiotlb_alloc_coherent,
15         .free_coherent = xen_swiotlb_free_coherent,
16         .sync_single_for_cpu = xen_swiotlb_sync_single_for_cpu,
17         .sync_single_for_device = xen_swiotlb_sync_single_for_device,
18         .sync_sg_for_cpu = xen_swiotlb_sync_sg_for_cpu,
19         .sync_sg_for_device = xen_swiotlb_sync_sg_for_device,
20         .map_sg = xen_swiotlb_map_sg_attrs,
21         .unmap_sg = xen_swiotlb_unmap_sg_attrs,
22         .map_page = xen_swiotlb_map_page,
23         .unmap_page = xen_swiotlb_unmap_page,
24         .dma_supported = xen_swiotlb_dma_supported,
25 };
26
27 /*
28  * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
29  *
30  * This returns non-zero if we are forced to use xen_swiotlb (by the boot
31  * option).
32  */
33 int __init pci_xen_swiotlb_detect(void)
34 {
35
36         /* If running as PV guest, either iommu=soft, or swiotlb=force will
37          * activate this IOMMU. If running as PV privileged, activate it
38          * irregardlesss.
39          */
40         if ((xen_initial_domain() || swiotlb || swiotlb_force) &&
41             (xen_pv_domain()))
42                 xen_swiotlb = 1;
43
44         /* If we are running under Xen, we MUST disable the native SWIOTLB.
45          * Don't worry about swiotlb_force flag activating the native, as
46          * the 'swiotlb' flag is the only one turning it on. */
47         if (xen_pv_domain())
48                 swiotlb = 0;
49
50         return xen_swiotlb;
51 }
52
53 void __init pci_xen_swiotlb_init(void)
54 {
55         if (xen_swiotlb) {
56                 xen_swiotlb_init(1);
57                 dma_ops = &xen_swiotlb_dma_ops;
58         }
59 }
60 IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
61                   0,
62                   pci_xen_swiotlb_init,
63                   0);