pci-dma.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Dynamic DMA mapping support.
  3. */
  4. #include <linux/types.h>
  5. #include <linux/mm.h>
  6. #include <linux/string.h>
  7. #include <linux/pci.h>
  8. #include <linux/module.h>
  9. #include <linux/dmar.h>
  10. #include <asm/iommu.h>
  11. #include <asm/machvec.h>
  12. #include <linux/dma-mapping.h>
  13. #ifdef CONFIG_INTEL_IOMMU
  14. #include <linux/kernel.h>
  15. #include <asm/page.h>
  16. dma_addr_t bad_dma_address __read_mostly;
  17. EXPORT_SYMBOL(bad_dma_address);
  18. static int iommu_sac_force __read_mostly;
  19. int no_iommu __read_mostly;
  20. #ifdef CONFIG_IOMMU_DEBUG
  21. int force_iommu __read_mostly = 1;
  22. #else
  23. int force_iommu __read_mostly;
  24. #endif
  25. int iommu_pass_through;
  26. extern struct dma_map_ops intel_dma_ops;
  27. static int __init pci_iommu_init(void)
  28. {
  29. if (iommu_detected)
  30. intel_iommu_init();
  31. return 0;
  32. }
  33. /* Must execute after PCI subsystem */
  34. fs_initcall(pci_iommu_init);
  35. void pci_iommu_shutdown(void)
  36. {
  37. return;
  38. }
  39. void __init
  40. iommu_dma_init(void)
  41. {
  42. return;
  43. }
  44. int iommu_dma_supported(struct device *dev, u64 mask)
  45. {
  46. /* Copied from i386. Doesn't make much sense, because it will
  47. only work for pci_alloc_coherent.
  48. The caller just has to use GFP_DMA in this case. */
  49. if (mask < DMA_BIT_MASK(24))
  50. return 0;
  51. /* Tell the device to use SAC when IOMMU force is on. This
  52. allows the driver to use cheaper accesses in some cases.
  53. Problem with this is that if we overflow the IOMMU area and
  54. return DAC as fallback address the device may not handle it
  55. correctly.
  56. As a special case some controllers have a 39bit address
  57. mode that is as efficient as 32bit (aic79xx). Don't force
  58. SAC for these. Assume all masks <= 40 bits are of this
  59. type. Normally this doesn't make any difference, but gives
  60. more gentle handling of IOMMU overflow. */
  61. if (iommu_sac_force && (mask >= DMA_BIT_MASK(40))) {
  62. dev_info(dev, "Force SAC with mask %llx\n", mask);
  63. return 0;
  64. }
  65. return 1;
  66. }
  67. EXPORT_SYMBOL(iommu_dma_supported);
  68. void __init pci_iommu_alloc(void)
  69. {
  70. dma_ops = &intel_dma_ops;
  71. dma_ops->sync_single_for_cpu = machvec_dma_sync_single;
  72. dma_ops->sync_sg_for_cpu = machvec_dma_sync_sg;
  73. dma_ops->sync_single_for_device = machvec_dma_sync_single;
  74. dma_ops->sync_sg_for_device = machvec_dma_sync_sg;
  75. dma_ops->dma_supported = iommu_dma_supported;
  76. /*
  77. * The order of these functions is important for
  78. * fall-back/fail-over reasons
  79. */
  80. detect_intel_iommu();
  81. #ifdef CONFIG_SWIOTLB
  82. pci_swiotlb_init();
  83. #endif
  84. }
  85. #endif