2010-02-10 03:30:55 +08:00
|
|
|
/* Glue code to lib/swiotlb-xen.c */
|
|
|
|
|
|
|
|
#include <linux/dma-mapping.h>
|
2010-08-20 01:34:58 +08:00
|
|
|
#include <linux/pci.h>
|
2010-02-10 03:30:55 +08:00
|
|
|
#include <xen/swiotlb-xen.h>
|
|
|
|
|
|
|
|
#include <asm/xen/hypervisor.h>
|
|
|
|
#include <xen/xen.h>
|
2010-08-27 01:58:01 +08:00
|
|
|
#include <asm/iommu_table.h>
|
2010-02-10 03:30:55 +08:00
|
|
|
|
2012-09-23 08:01:16 +08:00
|
|
|
|
2012-08-22 02:49:34 +08:00
|
|
|
#include <asm/xen/swiotlb-xen.h>
|
2012-07-28 08:16:00 +08:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
#include <asm/iommu.h>
|
|
|
|
#include <asm/dma.h>
|
|
|
|
#endif
|
2012-08-24 02:36:15 +08:00
|
|
|
#include <linux/export.h>
|
2012-09-23 08:01:16 +08:00
|
|
|
|
2010-02-10 03:30:55 +08:00
|
|
|
int xen_swiotlb __read_mostly;
|
|
|
|
|
|
|
|
static struct dma_map_ops xen_swiotlb_dma_ops = {
|
2012-03-27 20:28:18 +08:00
|
|
|
.alloc = xen_swiotlb_alloc_coherent,
|
|
|
|
.free = xen_swiotlb_free_coherent,
|
2010-02-10 03:30:55 +08:00
|
|
|
.sync_single_for_cpu = xen_swiotlb_sync_single_for_cpu,
|
|
|
|
.sync_single_for_device = xen_swiotlb_sync_single_for_device,
|
|
|
|
.sync_sg_for_cpu = xen_swiotlb_sync_sg_for_cpu,
|
|
|
|
.sync_sg_for_device = xen_swiotlb_sync_sg_for_device,
|
|
|
|
.map_sg = xen_swiotlb_map_sg_attrs,
|
|
|
|
.unmap_sg = xen_swiotlb_unmap_sg_attrs,
|
|
|
|
.map_page = xen_swiotlb_map_page,
|
|
|
|
.unmap_page = xen_swiotlb_unmap_page,
|
|
|
|
.dma_supported = xen_swiotlb_dma_supported,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 08:10:58 +08:00
|
|
|
if (!xen_pv_domain())
|
|
|
|
return 0;
|
|
|
|
|
2010-02-10 03:30:55 +08: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 16:16:21 +08:00
|
|
|
* irregardless.
|
2010-02-10 03:30:55 +08:00
|
|
|
*/
|
2016-12-16 21:28:41 +08:00
|
|
|
if (xen_initial_domain() || swiotlb || swiotlb_force == SWIOTLB_FORCE)
|
2010-02-10 03:30:55 +08: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 08:10:58 +08:00
|
|
|
swiotlb = 0;
|
2010-02-10 03:30:55 +08:00
|
|
|
|
2012-07-28 08:16:00 +08: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-10 03:30:55 +08:00
|
|
|
return xen_swiotlb;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __init pci_xen_swiotlb_init(void)
|
|
|
|
{
|
|
|
|
if (xen_swiotlb) {
|
2012-08-24 02:36:15 +08:00
|
|
|
xen_swiotlb_init(1, true /* early */);
|
2010-02-10 03:30:55 +08:00
|
|
|
dma_ops = &xen_swiotlb_dma_ops;
|
2010-08-20 01:34:58 +08:00
|
|
|
|
2013-11-05 02:11:54 +08:00
|
|
|
#ifdef CONFIG_PCI
|
2010-08-20 01:34:58 +08:00
|
|
|
/* Make sure ACS will be enabled */
|
|
|
|
pci_request_acs();
|
2013-11-05 02:11:54 +08:00
|
|
|
#endif
|
2010-02-10 03:30:55 +08:00
|
|
|
}
|
|
|
|
}
|
2012-08-24 02:36:15 +08: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-05 02:11:54 +08:00
|
|
|
#ifdef CONFIG_PCI
|
2012-08-24 02:36:15 +08:00
|
|
|
/* Make sure ACS will be enabled */
|
|
|
|
pci_request_acs();
|
2013-11-05 02:11:54 +08:00
|
|
|
#endif
|
2012-08-24 02:36:15 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
|
|
|
|
|
2010-08-27 01:58:01 +08:00
|
|
|
IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
|
2012-08-13 23:00:08 +08:00
|
|
|
NULL,
|
2010-08-27 01:58:01 +08:00
|
|
|
pci_xen_swiotlb_init,
|
2012-08-13 23:00:08 +08:00
|
|
|
NULL);
|