2010-02-09 19:30:55 +00:00
|
|
|
/* Glue code to lib/swiotlb-xen.c */
|
|
|
|
|
|
|
|
#include <linux/dma-mapping.h>
|
2010-08-19 17:34:58 +00:00
|
|
|
#include <linux/pci.h>
|
2010-02-09 19:30:55 +00:00
|
|
|
#include <xen/swiotlb-xen.h>
|
|
|
|
|
|
|
|
#include <asm/xen/hypervisor.h>
|
|
|
|
#include <xen/xen.h>
|
2010-08-26 17:58:01 +00:00
|
|
|
#include <asm/iommu_table.h>
|
2010-02-09 19:30:55 +00:00
|
|
|
|
2012-09-23 00:01:16 +00:00
|
|
|
|
2012-08-21 18:49:34 +00:00
|
|
|
#include <asm/xen/swiotlb-xen.h>
|
2012-07-28 00:16:00 +00:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
#include <asm/iommu.h>
|
|
|
|
#include <asm/dma.h>
|
|
|
|
#endif
|
2012-08-23 18:36:15 +00:00
|
|
|
#include <linux/export.h>
|
2012-09-23 00:01:16 +00:00
|
|
|
|
2010-02-09 19:30:55 +00:00
|
|
|
int xen_swiotlb __read_mostly;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
|
|
|
|
*
|
|
|
|
* This returns non-zero if we are forced to use xen_swiotlb (by the boot
|
|
|
|
* option).
|
|
|
|
*/
|
|
|
|
int __init pci_xen_swiotlb_detect(void)
|
|
|
|
{
|
|
|
|
|
2012-07-28 00:10:58 +00:00
|
|
|
if (!xen_pv_domain())
|
|
|
|
return 0;
|
|
|
|
|
2010-02-09 19:30:55 +00:00
|
|
|
/* If running as PV guest, either iommu=soft, or swiotlb=force will
|
|
|
|
* activate this IOMMU. If running as PV privileged, activate it
|
2011-05-10 08:16:21 +00:00
|
|
|
* irregardless.
|
2010-02-09 19:30:55 +00:00
|
|
|
*/
|
2016-12-16 13:28:41 +00:00
|
|
|
if (xen_initial_domain() || swiotlb || swiotlb_force == SWIOTLB_FORCE)
|
2010-02-09 19:30:55 +00:00
|
|
|
xen_swiotlb = 1;
|
|
|
|
|
|
|
|
/* If we are running under Xen, we MUST disable the native SWIOTLB.
|
|
|
|
* Don't worry about swiotlb_force flag activating the native, as
|
|
|
|
* the 'swiotlb' flag is the only one turning it on. */
|
2012-07-28 00:10:58 +00:00
|
|
|
swiotlb = 0;
|
2010-02-09 19:30:55 +00:00
|
|
|
|
2012-07-28 00:16:00 +00:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
/* pci_swiotlb_detect_4gb turns on native SWIOTLB if no_iommu == 0
|
|
|
|
* (so no iommu=X command line over-writes).
|
|
|
|
* Considering that PV guests do not want the *native SWIOTLB* but
|
|
|
|
* only Xen SWIOTLB it is not useful to us so set no_iommu=1 here.
|
|
|
|
*/
|
|
|
|
if (max_pfn > MAX_DMA32_PFN)
|
|
|
|
no_iommu = 1;
|
|
|
|
#endif
|
2010-02-09 19:30:55 +00:00
|
|
|
return xen_swiotlb;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __init pci_xen_swiotlb_init(void)
|
|
|
|
{
|
|
|
|
if (xen_swiotlb) {
|
2012-08-23 18:36:15 +00:00
|
|
|
xen_swiotlb_init(1, true /* early */);
|
2010-02-09 19:30:55 +00:00
|
|
|
dma_ops = &xen_swiotlb_dma_ops;
|
2010-08-19 17:34:58 +00:00
|
|
|
|
2013-11-04 18:11:54 +00:00
|
|
|
#ifdef CONFIG_PCI
|
2010-08-19 17:34:58 +00:00
|
|
|
/* Make sure ACS will be enabled */
|
|
|
|
pci_request_acs();
|
2013-11-04 18:11:54 +00:00
|
|
|
#endif
|
2010-02-09 19:30:55 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-23 18:36:15 +00:00
|
|
|
|
|
|
|
int pci_xen_swiotlb_init_late(void)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (xen_swiotlb)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
rc = xen_swiotlb_init(1, false /* late */);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
dma_ops = &xen_swiotlb_dma_ops;
|
2013-11-04 18:11:54 +00:00
|
|
|
#ifdef CONFIG_PCI
|
2012-08-23 18:36:15 +00:00
|
|
|
/* Make sure ACS will be enabled */
|
|
|
|
pci_request_acs();
|
2013-11-04 18:11:54 +00:00
|
|
|
#endif
|
2012-08-23 18:36:15 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
|
|
|
|
|
2010-08-26 17:58:01 +00:00
|
|
|
IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
|
2012-08-13 15:00:08 +00:00
|
|
|
NULL,
|
2010-08-26 17:58:01 +00:00
|
|
|
pci_xen_swiotlb_init,
|
2012-08-13 15:00:08 +00:00
|
|
|
NULL);
|