pci-swiotlb.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. static void *x86_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
  13. dma_addr_t *dma_handle, gfp_t flags)
  14. {
  15. void *vaddr;
  16. vaddr = dma_generic_alloc_coherent(hwdev, size, dma_handle, flags);
  17. if (vaddr)
  18. return vaddr;
  19. return swiotlb_alloc_coherent(hwdev, size, dma_handle, flags);
  20. }
  21. static struct dma_map_ops swiotlb_dma_ops = {
  22. .mapping_error = swiotlb_dma_mapping_error,
  23. .alloc_coherent = x86_swiotlb_alloc_coherent,
  24. .free_coherent = swiotlb_free_coherent,
  25. .sync_single_for_cpu = swiotlb_sync_single_for_cpu,
  26. .sync_single_for_device = swiotlb_sync_single_for_device,
  27. .sync_single_range_for_cpu = swiotlb_sync_single_range_for_cpu,
  28. .sync_single_range_for_device = swiotlb_sync_single_range_for_device,
  29. .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu,
  30. .sync_sg_for_device = swiotlb_sync_sg_for_device,
  31. .map_sg = swiotlb_map_sg_attrs,
  32. .unmap_sg = swiotlb_unmap_sg_attrs,
  33. .map_page = swiotlb_map_page,
  34. .unmap_page = swiotlb_unmap_page,
  35. .dma_supported = NULL,
  36. };
  37. void __init pci_swiotlb_init(void)
  38. {
  39. /* don't initialize swiotlb if iommu=off (no_iommu=1) */
  40. #ifdef CONFIG_X86_64
  41. if ((!iommu_detected && !no_iommu && max_pfn > MAX_DMA32_PFN))
  42. swiotlb = 1;
  43. #endif
  44. if (swiotlb_force)
  45. swiotlb = 1;
  46. if (swiotlb) {
  47. printk(KERN_INFO "PCI-DMA: Using software bounce buffering for IO (SWIOTLB)\n");
  48. swiotlb_init();
  49. dma_ops = &swiotlb_dma_ops;
  50. }
  51. }