pci-swiotlb.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* Glue code to lib/swiotlb.c */
  2. #include <linux/pci.h>
  3. #include <linux/cache.h>
  4. #include <linux/module.h>
  5. #include <linux/swiotlb.h>
  6. #include <linux/bootmem.h>
  7. #include <linux/dma-mapping.h>
  8. #include <asm/iommu.h>
  9. #include <asm/swiotlb.h>
  10. #include <asm/dma.h>
  11. int swiotlb __read_mostly;
  12. dma_addr_t swiotlb_phys_to_bus(struct device *hwdev, phys_addr_t paddr)
  13. {
  14. return paddr;
  15. }
  16. phys_addr_t swiotlb_bus_to_phys(struct device *hwdev, dma_addr_t baddr)
  17. {
  18. return baddr;
  19. }
  20. int __weak swiotlb_arch_range_needs_mapping(phys_addr_t paddr, size_t size)
  21. {
  22. return 0;
  23. }
  24. static void *x86_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
  25. dma_addr_t *dma_handle, gfp_t flags)
  26. {
  27. void *vaddr;
  28. vaddr = dma_generic_alloc_coherent(hwdev, size, dma_handle, flags);
  29. if (vaddr)
  30. return vaddr;
  31. return swiotlb_alloc_coherent(hwdev, size, dma_handle, flags);
  32. }
  33. static struct dma_map_ops swiotlb_dma_ops = {
  34. .mapping_error = swiotlb_dma_mapping_error,
  35. .alloc_coherent = x86_swiotlb_alloc_coherent,
  36. .free_coherent = swiotlb_free_coherent,
  37. .sync_single_for_cpu = swiotlb_sync_single_for_cpu,
  38. .sync_single_for_device = swiotlb_sync_single_for_device,
  39. .sync_single_range_for_cpu = swiotlb_sync_single_range_for_cpu,
  40. .sync_single_range_for_device = swiotlb_sync_single_range_for_device,
  41. .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu,
  42. .sync_sg_for_device = swiotlb_sync_sg_for_device,
  43. .map_sg = swiotlb_map_sg_attrs,
  44. .unmap_sg = swiotlb_unmap_sg_attrs,
  45. .map_page = swiotlb_map_page,
  46. .unmap_page = swiotlb_unmap_page,
  47. .dma_supported = NULL,
  48. };
  49. void __init pci_swiotlb_init(void)
  50. {
  51. /* don't initialize swiotlb if iommu=off (no_iommu=1) */
  52. #ifdef CONFIG_X86_64
  53. if ((!iommu_detected && !no_iommu && max_pfn > MAX_DMA32_PFN) ||
  54. iommu_pass_through)
  55. swiotlb = 1;
  56. #endif
  57. if (swiotlb_force)
  58. swiotlb = 1;
  59. if (swiotlb) {
  60. printk(KERN_INFO "PCI-DMA: Using software bounce buffering for IO (SWIOTLB)\n");
  61. swiotlb_init();
  62. dma_ops = &swiotlb_dma_ops;
  63. }
  64. }