pci-dma.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. #include <asm/system.h>
  14. #ifdef CONFIG_DMAR
  15. #include <linux/kernel.h>
  16. #include <asm/page.h>
  17. dma_addr_t bad_dma_address __read_mostly;
  18. EXPORT_SYMBOL(bad_dma_address);
  19. static int iommu_sac_force __read_mostly;
  20. int no_iommu __read_mostly;
  21. #ifdef CONFIG_IOMMU_DEBUG
  22. int force_iommu __read_mostly = 1;
  23. #else
  24. int force_iommu __read_mostly;
  25. #endif
  26. /* Dummy device used for NULL arguments (normally ISA). Better would
  27. be probably a smaller DMA mask, but this is bug-to-bug compatible
  28. to i386. */
  29. struct device fallback_dev = {
  30. .init_name = "fallback device",
  31. .coherent_dma_mask = DMA_BIT_MASK(32),
  32. .dma_mask = &fallback_dev.coherent_dma_mask,
  33. };
  34. extern struct dma_map_ops intel_dma_ops;
  35. static int __init pci_iommu_init(void)
  36. {
  37. if (iommu_detected)
  38. intel_iommu_init();
  39. return 0;
  40. }
  41. /* Must execute after PCI subsystem */
  42. fs_initcall(pci_iommu_init);
  43. void pci_iommu_shutdown(void)
  44. {
  45. return;
  46. }
  47. void __init
  48. iommu_dma_init(void)
  49. {
  50. return;
  51. }
  52. int iommu_dma_supported(struct device *dev, u64 mask)
  53. {
  54. struct dma_map_ops *ops = platform_dma_get_ops(dev);
  55. if (ops->dma_supported)
  56. return ops->dma_supported(dev, mask);
  57. /* Copied from i386. Doesn't make much sense, because it will
  58. only work for pci_alloc_coherent.
  59. The caller just has to use GFP_DMA in this case. */
  60. if (mask < DMA_BIT_MASK(24))
  61. return 0;
  62. /* Tell the device to use SAC when IOMMU force is on. This
  63. allows the driver to use cheaper accesses in some cases.
  64. Problem with this is that if we overflow the IOMMU area and
  65. return DAC as fallback address the device may not handle it
  66. correctly.
  67. As a special case some controllers have a 39bit address
  68. mode that is as efficient as 32bit (aic79xx). Don't force
  69. SAC for these. Assume all masks <= 40 bits are of this
  70. type. Normally this doesn't make any difference, but gives
  71. more gentle handling of IOMMU overflow. */
  72. if (iommu_sac_force && (mask >= DMA_BIT_MASK(40))) {
  73. dev_info(dev, "Force SAC with mask %lx\n", mask);
  74. return 0;
  75. }
  76. return 1;
  77. }
  78. EXPORT_SYMBOL(iommu_dma_supported);
  79. void __init pci_iommu_alloc(void)
  80. {
  81. dma_ops = &intel_dma_ops;
  82. dma_ops->sync_single_for_cpu = machvec_dma_sync_single;
  83. dma_ops->sync_sg_for_cpu = machvec_dma_sync_sg;
  84. dma_ops->sync_single_for_device = machvec_dma_sync_single;
  85. dma_ops->sync_sg_for_device = machvec_dma_sync_sg;
  86. dma_ops->dma_supported = iommu_dma_supported;
  87. /*
  88. * The order of these functions is important for
  89. * fall-back/fail-over reasons
  90. */
  91. detect_intel_iommu();
  92. #ifdef CONFIG_SWIOTLB
  93. pci_swiotlb_init();
  94. #endif
  95. }
  96. #endif