pci-dma.c 2.8 KB

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