pci-swiotlb-xen.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Glue code to lib/swiotlb-xen.c */
  2. #include <linux/dma-mapping.h>
  3. #include <linux/pci.h>
  4. #include <xen/swiotlb-xen.h>
  5. #include <asm/xen/hypervisor.h>
  6. #include <xen/xen.h>
  7. #include <asm/iommu_table.h>
  8. #ifdef CONFIG_X86_64
  9. #include <asm/iommu.h>
  10. #include <asm/dma.h>
  11. #endif
  12. int xen_swiotlb __read_mostly;
  13. static struct dma_map_ops xen_swiotlb_dma_ops = {
  14. .mapping_error = xen_swiotlb_dma_mapping_error,
  15. .alloc = xen_swiotlb_alloc_coherent,
  16. .free = xen_swiotlb_free_coherent,
  17. .sync_single_for_cpu = xen_swiotlb_sync_single_for_cpu,
  18. .sync_single_for_device = xen_swiotlb_sync_single_for_device,
  19. .sync_sg_for_cpu = xen_swiotlb_sync_sg_for_cpu,
  20. .sync_sg_for_device = xen_swiotlb_sync_sg_for_device,
  21. .map_sg = xen_swiotlb_map_sg_attrs,
  22. .unmap_sg = xen_swiotlb_unmap_sg_attrs,
  23. .map_page = xen_swiotlb_map_page,
  24. .unmap_page = xen_swiotlb_unmap_page,
  25. .dma_supported = xen_swiotlb_dma_supported,
  26. };
  27. /*
  28. * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
  29. *
  30. * This returns non-zero if we are forced to use xen_swiotlb (by the boot
  31. * option).
  32. */
  33. int __init pci_xen_swiotlb_detect(void)
  34. {
  35. if (!xen_pv_domain())
  36. return 0;
  37. /* If running as PV guest, either iommu=soft, or swiotlb=force will
  38. * activate this IOMMU. If running as PV privileged, activate it
  39. * irregardless.
  40. */
  41. if ((xen_initial_domain() || swiotlb || swiotlb_force))
  42. xen_swiotlb = 1;
  43. /* If we are running under Xen, we MUST disable the native SWIOTLB.
  44. * Don't worry about swiotlb_force flag activating the native, as
  45. * the 'swiotlb' flag is the only one turning it on. */
  46. swiotlb = 0;
  47. #ifdef CONFIG_X86_64
  48. /* pci_swiotlb_detect_4gb turns on native SWIOTLB if no_iommu == 0
  49. * (so no iommu=X command line over-writes).
  50. * Considering that PV guests do not want the *native SWIOTLB* but
  51. * only Xen SWIOTLB it is not useful to us so set no_iommu=1 here.
  52. */
  53. if (max_pfn > MAX_DMA32_PFN)
  54. no_iommu = 1;
  55. #endif
  56. return xen_swiotlb;
  57. }
  58. void __init pci_xen_swiotlb_init(void)
  59. {
  60. if (xen_swiotlb) {
  61. xen_swiotlb_init(1);
  62. dma_ops = &xen_swiotlb_dma_ops;
  63. /* Make sure ACS will be enabled */
  64. pci_request_acs();
  65. }
  66. }
  67. IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
  68. 0,
  69. pci_xen_swiotlb_init,
  70. 0);