5299709d0a
Most dma_map_ops structures are never modified. Constify these structures such that these can be write-protected. This patch has been generated as follows: git grep -l 'struct dma_map_ops' | xargs -d\\n sed -i \ -e 's/struct dma_map_ops/const struct dma_map_ops/g' \ -e 's/const struct dma_map_ops {/struct dma_map_ops {/g' \ -e 's/^const struct dma_map_ops;$/struct dma_map_ops;/' \ -e 's/const const struct dma_map_ops /const struct dma_map_ops /g'; sed -i -e 's/const \(struct dma_map_ops intel_dma_ops\)/\1/' \ $(git grep -l 'struct dma_map_ops intel_dma_ops'); sed -i -e 's/const \(struct dma_map_ops dma_iommu_ops\)/\1/' \ $(git grep -l 'struct dma_map_ops' | grep ^arch/powerpc); sed -i -e '/^struct vmd_dev {$/,/^};$/ s/const \(struct dma_map_ops[[:blank:]]dma_ops;\)/\1/' \ -e '/^static void vmd_setup_dma_ops/,/^}$/ s/const \(struct dma_map_ops \*dest\)/\1/' \ -e 's/const \(struct dma_map_ops \*dest = \&vmd->dma_ops\)/\1/' \ drivers/pci/host/*.c sed -i -e '/^void __init pci_iommu_alloc(void)$/,/^}$/ s/dma_ops->/intel_dma_ops./' arch/ia64/kernel/pci-dma.c sed -i -e 's/static const struct dma_map_ops sn_dma_ops/static struct dma_map_ops sn_dma_ops/' arch/ia64/sn/pci/pci_dma.c sed -i -e 's/(const struct dma_map_ops \*)//' drivers/misc/mic/bus/vop_bus.c Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Juergen Gross <jgross@suse.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: linux-arch@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Russell King <linux@armlinux.org.uk> Cc: x86@kernel.org Signed-off-by: Doug Ledford <dledford@redhat.com>
109 lines
2.6 KiB
C
109 lines
2.6 KiB
C
/* Glue code to lib/swiotlb-xen.c */
|
|
|
|
#include <linux/dma-mapping.h>
|
|
#include <linux/pci.h>
|
|
#include <xen/swiotlb-xen.h>
|
|
|
|
#include <asm/xen/hypervisor.h>
|
|
#include <xen/xen.h>
|
|
#include <asm/iommu_table.h>
|
|
|
|
|
|
#include <asm/xen/swiotlb-xen.h>
|
|
#ifdef CONFIG_X86_64
|
|
#include <asm/iommu.h>
|
|
#include <asm/dma.h>
|
|
#endif
|
|
#include <linux/export.h>
|
|
|
|
int xen_swiotlb __read_mostly;
|
|
|
|
static const struct dma_map_ops xen_swiotlb_dma_ops = {
|
|
.alloc = xen_swiotlb_alloc_coherent,
|
|
.free = xen_swiotlb_free_coherent,
|
|
.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)
|
|
{
|
|
|
|
if (!xen_pv_domain())
|
|
return 0;
|
|
|
|
/* If running as PV guest, either iommu=soft, or swiotlb=force will
|
|
* activate this IOMMU. If running as PV privileged, activate it
|
|
* irregardless.
|
|
*/
|
|
if (xen_initial_domain() || swiotlb || swiotlb_force == SWIOTLB_FORCE)
|
|
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. */
|
|
swiotlb = 0;
|
|
|
|
#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
|
|
return xen_swiotlb;
|
|
}
|
|
|
|
void __init pci_xen_swiotlb_init(void)
|
|
{
|
|
if (xen_swiotlb) {
|
|
xen_swiotlb_init(1, true /* early */);
|
|
dma_ops = &xen_swiotlb_dma_ops;
|
|
|
|
#ifdef CONFIG_PCI
|
|
/* Make sure ACS will be enabled */
|
|
pci_request_acs();
|
|
#endif
|
|
}
|
|
}
|
|
|
|
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;
|
|
#ifdef CONFIG_PCI
|
|
/* Make sure ACS will be enabled */
|
|
pci_request_acs();
|
|
#endif
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
|
|
|
|
IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
|
|
NULL,
|
|
pci_xen_swiotlb_init,
|
|
NULL);
|