Linux 4.19-rc7
[linux-2.6/btrfs-unstable.git] / arch / x86 / xen / pci-swiotlb-xen.c
blob37c6056a7bba013e14386e69bed7cdf25faad510
1 /* Glue code to lib/swiotlb-xen.c */
3 #include <linux/dma-mapping.h>
4 #include <linux/pci.h>
5 #include <xen/swiotlb-xen.h>
7 #include <asm/xen/hypervisor.h>
8 #include <xen/xen.h>
9 #include <asm/iommu_table.h>
12 #include <asm/xen/swiotlb-xen.h>
13 #ifdef CONFIG_X86_64
14 #include <asm/iommu.h>
15 #include <asm/dma.h>
16 #endif
17 #include <linux/export.h>
19 int xen_swiotlb __read_mostly;
22 * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
24 * This returns non-zero if we are forced to use xen_swiotlb (by the boot
25 * option).
27 int __init pci_xen_swiotlb_detect(void)
30 if (!xen_pv_domain())
31 return 0;
33 /* If running as PV guest, either iommu=soft, or swiotlb=force will
34 * activate this IOMMU. If running as PV privileged, activate it
35 * irregardless.
37 if (xen_initial_domain() || swiotlb || swiotlb_force == SWIOTLB_FORCE)
38 xen_swiotlb = 1;
40 /* If we are running under Xen, we MUST disable the native SWIOTLB.
41 * Don't worry about swiotlb_force flag activating the native, as
42 * the 'swiotlb' flag is the only one turning it on. */
43 swiotlb = 0;
45 #ifdef CONFIG_X86_64
46 /* pci_swiotlb_detect_4gb turns on native SWIOTLB if no_iommu == 0
47 * (so no iommu=X command line over-writes).
48 * Considering that PV guests do not want the *native SWIOTLB* but
49 * only Xen SWIOTLB it is not useful to us so set no_iommu=1 here.
51 if (max_pfn > MAX_DMA32_PFN)
52 no_iommu = 1;
53 #endif
54 return xen_swiotlb;
57 void __init pci_xen_swiotlb_init(void)
59 if (xen_swiotlb) {
60 xen_swiotlb_init(1, true /* early */);
61 dma_ops = &xen_swiotlb_dma_ops;
63 #ifdef CONFIG_PCI
64 /* Make sure ACS will be enabled */
65 pci_request_acs();
66 #endif
70 int pci_xen_swiotlb_init_late(void)
72 int rc;
74 if (xen_swiotlb)
75 return 0;
77 rc = xen_swiotlb_init(1, false /* late */);
78 if (rc)
79 return rc;
81 dma_ops = &xen_swiotlb_dma_ops;
82 #ifdef CONFIG_PCI
83 /* Make sure ACS will be enabled */
84 pci_request_acs();
85 #endif
87 return 0;
89 EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
91 IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
92 NULL,
93 pci_xen_swiotlb_init,
94 NULL);