pci-dma.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #include <linux/dma-mapping.h>
  2. #include <linux/dmar.h>
  3. #include <linux/bootmem.h>
  4. #include <asm/proto.h>
  5. #include <asm/dma.h>
  6. #include <asm/gart.h>
  7. #include <asm/calgary.h>
  8. const struct dma_mapping_ops *dma_ops;
  9. EXPORT_SYMBOL(dma_ops);
  10. #ifdef CONFIG_IOMMU_DEBUG
  11. int panic_on_overflow __read_mostly = 1;
  12. int force_iommu __read_mostly = 1;
  13. #else
  14. int panic_on_overflow __read_mostly = 0;
  15. int force_iommu __read_mostly = 0;
  16. #endif
  17. int dma_set_mask(struct device *dev, u64 mask)
  18. {
  19. if (!dev->dma_mask || !dma_supported(dev, mask))
  20. return -EIO;
  21. *dev->dma_mask = mask;
  22. return 0;
  23. }
  24. EXPORT_SYMBOL(dma_set_mask);
  25. #ifdef CONFIG_X86_64
  26. static __initdata void *dma32_bootmem_ptr;
  27. static unsigned long dma32_bootmem_size __initdata = (128ULL<<20);
  28. static int __init parse_dma32_size_opt(char *p)
  29. {
  30. if (!p)
  31. return -EINVAL;
  32. dma32_bootmem_size = memparse(p, &p);
  33. return 0;
  34. }
  35. early_param("dma32_size", parse_dma32_size_opt);
  36. void __init dma32_reserve_bootmem(void)
  37. {
  38. unsigned long size, align;
  39. if (end_pfn <= MAX_DMA32_PFN)
  40. return;
  41. align = 64ULL<<20;
  42. size = round_up(dma32_bootmem_size, align);
  43. dma32_bootmem_ptr = __alloc_bootmem_nopanic(size, align,
  44. __pa(MAX_DMA_ADDRESS));
  45. if (dma32_bootmem_ptr)
  46. dma32_bootmem_size = size;
  47. else
  48. dma32_bootmem_size = 0;
  49. }
  50. static void __init dma32_free_bootmem(void)
  51. {
  52. int node;
  53. if (end_pfn <= MAX_DMA32_PFN)
  54. return;
  55. if (!dma32_bootmem_ptr)
  56. return;
  57. for_each_online_node(node)
  58. free_bootmem_node(NODE_DATA(node), __pa(dma32_bootmem_ptr),
  59. dma32_bootmem_size);
  60. dma32_bootmem_ptr = NULL;
  61. dma32_bootmem_size = 0;
  62. }
  63. void __init pci_iommu_alloc(void)
  64. {
  65. /* free the range so iommu could get some range less than 4G */
  66. dma32_free_bootmem();
  67. /*
  68. * The order of these functions is important for
  69. * fall-back/fail-over reasons
  70. */
  71. #ifdef CONFIG_GART_IOMMU
  72. gart_iommu_hole_init();
  73. #endif
  74. #ifdef CONFIG_CALGARY_IOMMU
  75. detect_calgary();
  76. #endif
  77. detect_intel_iommu();
  78. #ifdef CONFIG_SWIOTLB
  79. pci_swiotlb_init();
  80. #endif
  81. }
  82. #endif
  83. static int __init pci_iommu_init(void)
  84. {
  85. #ifdef CONFIG_CALGARY_IOMMU
  86. calgary_iommu_init();
  87. #endif
  88. intel_iommu_init();
  89. #ifdef CONFIG_GART_IOMMU
  90. gart_iommu_init();
  91. #endif
  92. no_iommu_init();
  93. return 0;
  94. }
  95. void pci_iommu_shutdown(void)
  96. {
  97. gart_iommu_shutdown();
  98. }
  99. /* Must execute after PCI subsystem */
  100. fs_initcall(pci_iommu_init);