Merge tag 'devprop-4.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael...
[linux-2.6-block.git] / arch / x86 / xen / pci-swiotlb-xen.c
CommitLineData
bbbe5738
KRW
1/* Glue code to lib/swiotlb-xen.c */
2
3#include <linux/dma-mapping.h>
74226b8c 4#include <linux/pci.h>
bbbe5738
KRW
5#include <xen/swiotlb-xen.h>
6
7#include <asm/xen/hypervisor.h>
8#include <xen/xen.h>
5cb3a267 9#include <asm/iommu_table.h>
bbbe5738 10
a5f95155 11
b8b0f559 12#include <asm/xen/swiotlb-xen.h>
fc2341df
KRW
13#ifdef CONFIG_X86_64
14#include <asm/iommu.h>
15#include <asm/dma.h>
16#endif
b8277600 17#include <linux/export.h>
a5f95155 18
bbbe5738
KRW
19int xen_swiotlb __read_mostly;
20
bbbe5738
KRW
21/*
22 * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
23 *
24 * This returns non-zero if we are forced to use xen_swiotlb (by the boot
25 * option).
26 */
27int __init pci_xen_swiotlb_detect(void)
28{
29
988f0e24
KRW
30 if (!xen_pv_domain())
31 return 0;
32
bbbe5738
KRW
33 /* If running as PV guest, either iommu=soft, or swiotlb=force will
34 * activate this IOMMU. If running as PV privileged, activate it
70f23fd6 35 * irregardless.
bbbe5738 36 */
ae7871be 37 if (xen_initial_domain() || swiotlb || swiotlb_force == SWIOTLB_FORCE)
bbbe5738
KRW
38 xen_swiotlb = 1;
39
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. */
988f0e24 43 swiotlb = 0;
bbbe5738 44
fc2341df
KRW
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.
50 */
51 if (max_pfn > MAX_DMA32_PFN)
52 no_iommu = 1;
53#endif
bbbe5738
KRW
54 return xen_swiotlb;
55}
56
57void __init pci_xen_swiotlb_init(void)
58{
59 if (xen_swiotlb) {
b8277600 60 xen_swiotlb_init(1, true /* early */);
bbbe5738 61 dma_ops = &xen_swiotlb_dma_ops;
74226b8c 62
92c0fd17 63#ifdef CONFIG_PCI
74226b8c
KRW
64 /* Make sure ACS will be enabled */
65 pci_request_acs();
92c0fd17 66#endif
bbbe5738
KRW
67 }
68}
b8277600
KRW
69
70int pci_xen_swiotlb_init_late(void)
71{
72 int rc;
73
74 if (xen_swiotlb)
75 return 0;
76
77 rc = xen_swiotlb_init(1, false /* late */);
78 if (rc)
79 return rc;
80
81 dma_ops = &xen_swiotlb_dma_ops;
92c0fd17 82#ifdef CONFIG_PCI
b8277600
KRW
83 /* Make sure ACS will be enabled */
84 pci_request_acs();
92c0fd17 85#endif
b8277600
KRW
86
87 return 0;
88}
89EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
90
5cb3a267 91IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
6d7083ee 92 NULL,
5cb3a267 93 pci_xen_swiotlb_init,
6d7083ee 94 NULL);