pci-swiotlb-xen.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Glue code to lib/swiotlb-xen.c */
  2. #include <linux/dma-mapping.h>
  3. #include <xen/swiotlb-xen.h>
  4. #include <asm/xen/hypervisor.h>
  5. #include <xen/xen.h>
  6. #include <asm/iommu_table.h>
  7. int xen_swiotlb __read_mostly;
  8. static struct dma_map_ops xen_swiotlb_dma_ops = {
  9. .mapping_error = xen_swiotlb_dma_mapping_error,
  10. .alloc_coherent = xen_swiotlb_alloc_coherent,
  11. .free_coherent = xen_swiotlb_free_coherent,
  12. .sync_single_for_cpu = xen_swiotlb_sync_single_for_cpu,
  13. .sync_single_for_device = xen_swiotlb_sync_single_for_device,
  14. .sync_sg_for_cpu = xen_swiotlb_sync_sg_for_cpu,
  15. .sync_sg_for_device = xen_swiotlb_sync_sg_for_device,
  16. .map_sg = xen_swiotlb_map_sg_attrs,
  17. .unmap_sg = xen_swiotlb_unmap_sg_attrs,
  18. .map_page = xen_swiotlb_map_page,
  19. .unmap_page = xen_swiotlb_unmap_page,
  20. .dma_supported = xen_swiotlb_dma_supported,
  21. };
  22. /*
  23. * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
  24. *
  25. * This returns non-zero if we are forced to use xen_swiotlb (by the boot
  26. * option).
  27. */
  28. int __init pci_xen_swiotlb_detect(void)
  29. {
  30. /* If running as PV guest, either iommu=soft, or swiotlb=force will
  31. * activate this IOMMU. If running as PV privileged, activate it
  32. * irregardlesss.
  33. */
  34. if ((xen_initial_domain() || swiotlb || swiotlb_force) &&
  35. (xen_pv_domain()))
  36. xen_swiotlb = 1;
  37. /* If we are running under Xen, we MUST disable the native SWIOTLB.
  38. * Don't worry about swiotlb_force flag activating the native, as
  39. * the 'swiotlb' flag is the only one turning it on. */
  40. if (xen_pv_domain())
  41. swiotlb = 0;
  42. return xen_swiotlb;
  43. }
  44. void __init pci_xen_swiotlb_init(void)
  45. {
  46. if (xen_swiotlb) {
  47. xen_swiotlb_init(1);
  48. dma_ops = &xen_swiotlb_dma_ops;
  49. }
  50. }
  51. IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
  52. 0,
  53. pci_xen_swiotlb_init,
  54. 0);