pci-dma.c 2.6 KB

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