1 // SPDX-License-Identifier: GPL-2.0
3 /* Glue code to lib/swiotlb-xen.c */
5 #include <linux/dma-map-ops.h>
7 #include <xen/swiotlb-xen.h>
9 #include <asm/xen/hypervisor.h>
11 #include <asm/iommu_table.h>
14 #include <asm/xen/swiotlb-xen.h>
16 #include <asm/iommu.h>
19 #include <linux/export.h>
21 int xen_swiotlb __read_mostly;
24 * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
26 * This returns non-zero if we are forced to use xen_swiotlb (by the boot
29 int __init pci_xen_swiotlb_detect(void)
35 /* If running as PV guest, either iommu=soft, or swiotlb=force will
36 * activate this IOMMU. If running as PV privileged, activate it
39 if (xen_initial_domain() || swiotlb || swiotlb_force == SWIOTLB_FORCE)
42 /* If we are running under Xen, we MUST disable the native SWIOTLB.
43 * Don't worry about swiotlb_force flag activating the native, as
44 * the 'swiotlb' flag is the only one turning it on. */
48 /* pci_swiotlb_detect_4gb turns on native SWIOTLB if no_iommu == 0
49 * (so no iommu=X command line over-writes).
50 * Considering that PV guests do not want the *native SWIOTLB* but
51 * only Xen SWIOTLB it is not useful to us so set no_iommu=1 here.
53 if (max_pfn > MAX_DMA32_PFN)
59 void __init pci_xen_swiotlb_init(void)
62 xen_swiotlb_init_early();
63 dma_ops = &xen_swiotlb_dma_ops;
66 /* Make sure ACS will be enabled */
72 int pci_xen_swiotlb_init_late(void)
79 rc = xen_swiotlb_init();
83 dma_ops = &xen_swiotlb_dma_ops;
85 /* Make sure ACS will be enabled */
91 EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
93 IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,