pci-swiotlb-xen.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #include <asm/xen/swiotlb-xen.h>
  9. #ifdef CONFIG_X86_64
  10. #include <asm/iommu.h>
  11. #include <asm/dma.h>
  12. #endif
  13. #include <linux/export.h>
  14. int xen_swiotlb __read_mostly;
  15. /*
  16. * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
  17. *
  18. * This returns non-zero if we are forced to use xen_swiotlb (by the boot
  19. * option).
  20. */
  21. int __init pci_xen_swiotlb_detect(void)
  22. {
  23. if (!xen_pv_domain())
  24. return 0;
  25. /* If running as PV guest, either iommu=soft, or swiotlb=force will
  26. * activate this IOMMU. If running as PV privileged, activate it
  27. * irregardless.
  28. */
  29. if (xen_initial_domain() || swiotlb || swiotlb_force == SWIOTLB_FORCE)
  30. xen_swiotlb = 1;
  31. /* If we are running under Xen, we MUST disable the native SWIOTLB.
  32. * Don't worry about swiotlb_force flag activating the native, as
  33. * the 'swiotlb' flag is the only one turning it on. */
  34. swiotlb = 0;
  35. #ifdef CONFIG_X86_64
  36. /* pci_swiotlb_detect_4gb turns on native SWIOTLB if no_iommu == 0
  37. * (so no iommu=X command line over-writes).
  38. * Considering that PV guests do not want the *native SWIOTLB* but
  39. * only Xen SWIOTLB it is not useful to us so set no_iommu=1 here.
  40. */
  41. if (max_pfn > MAX_DMA32_PFN)
  42. no_iommu = 1;
  43. #endif
  44. return xen_swiotlb;
  45. }
  46. void __init pci_xen_swiotlb_init(void)
  47. {
  48. if (xen_swiotlb) {
  49. xen_swiotlb_init(1, true /* early */);
  50. dma_ops = &xen_swiotlb_dma_ops;
  51. #ifdef CONFIG_PCI
  52. /* Make sure ACS will be enabled */
  53. pci_request_acs();
  54. #endif
  55. }
  56. }
  57. int pci_xen_swiotlb_init_late(void)
  58. {
  59. int rc;
  60. if (xen_swiotlb)
  61. return 0;
  62. rc = xen_swiotlb_init(1, false /* late */);
  63. if (rc)
  64. return rc;
  65. dma_ops = &xen_swiotlb_dma_ops;
  66. #ifdef CONFIG_PCI
  67. /* Make sure ACS will be enabled */
  68. pci_request_acs();
  69. #endif
  70. return 0;
  71. }
  72. EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late);
  73. IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
  74. NULL,
  75. pci_xen_swiotlb_init,
  76. NULL);