Merge tag 'sched-urgent-2020-12-27' of git://git.kernel.org/pub/scm/linux/kernel...
[linux/fpc-iii.git] / arch / x86 / xen / pci-swiotlb-xen.c
blob19ae3e4fe4e98e5d0e2ffb40dffb6464b3741b0e
1 // SPDX-License-Identifier: GPL-2.0
3 /* Glue code to lib/swiotlb-xen.c */
5 #include <linux/dma-map-ops.h>
6 #include <linux/pci.h>
7 #include <xen/swiotlb-xen.h>
9 #include <asm/xen/hypervisor.h>
10 #include <xen/xen.h>
11 #include <asm/iommu_table.h>
14 #include <asm/xen/swiotlb-xen.h>
15 #ifdef CONFIG_X86_64
16 #include <asm/iommu.h>
17 #include <asm/dma.h>
18 #endif
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
27 * option).
29 int __init pci_xen_swiotlb_detect(void)
32 if (!xen_pv_domain())
33 return 0;
35 /* If running as PV guest, either iommu=soft, or swiotlb=force will
36 * activate this IOMMU. If running as PV privileged, activate it
37 * irregardless.
39 if (xen_initial_domain() || swiotlb || swiotlb_force == SWIOTLB_FORCE)
40 xen_swiotlb = 1;
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. */
45 swiotlb = 0;
47 #ifdef CONFIG_X86_64
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)
54 no_iommu = 1;
55 #endif
56 return xen_swiotlb;
59 void __init pci_xen_swiotlb_init(void)
61 if (xen_swiotlb) {
62 xen_swiotlb_init(1, true /* early */);
63 dma_ops = &xen_swiotlb_dma_ops;
65 #ifdef CONFIG_PCI
66 /* Make sure ACS will be enabled */
67 pci_request_acs();
68 #endif
72 int pci_xen_swiotlb_init_late(void)
74 int rc;
76 if (xen_swiotlb)
77 return 0;
79 rc = xen_swiotlb_init(1, false /* late */);
80 if (rc)
81 return rc;
83 dma_ops = &xen_swiotlb_dma_ops;
84 #ifdef CONFIG_PCI
85 /* Make sure ACS will be enabled */
86 pci_request_acs();
87 #endif
89 return 0;
91 EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
93 IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
94 NULL,
95 pci_xen_swiotlb_init,
96 NULL);