pci-swiotlb.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. void *swiotlb_alloc(unsigned order, unsigned long nslabs)
  13. {
  14. return (void *)__get_free_pages(GFP_DMA | __GFP_NOWARN, order);
  15. }
  16. dma_addr_t swiotlb_phys_to_bus(struct device *hwdev, phys_addr_t paddr)
  17. {
  18. return paddr;
  19. }
  20. phys_addr_t swiotlb_bus_to_phys(struct device *hwdev, dma_addr_t baddr)
  21. {
  22. return baddr;
  23. }
  24. int __weak swiotlb_arch_range_needs_mapping(phys_addr_t paddr, size_t size)
  25. {
  26. return 0;
  27. }
  28. static void *x86_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
  29. dma_addr_t *dma_handle, gfp_t flags)
  30. {
  31. void *vaddr;
  32. vaddr = dma_generic_alloc_coherent(hwdev, size, dma_handle, flags);
  33. if (vaddr)
  34. return vaddr;
  35. return swiotlb_alloc_coherent(hwdev, size, dma_handle, flags);
  36. }
  37. static struct dma_map_ops swiotlb_dma_ops = {
  38. .mapping_error = swiotlb_dma_mapping_error,
  39. .alloc_coherent = x86_swiotlb_alloc_coherent,
  40. .free_coherent = swiotlb_free_coherent,
  41. .sync_single_for_cpu = swiotlb_sync_single_for_cpu,
  42. .sync_single_for_device = swiotlb_sync_single_for_device,
  43. .sync_single_range_for_cpu = swiotlb_sync_single_range_for_cpu,
  44. .sync_single_range_for_device = swiotlb_sync_single_range_for_device,
  45. .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu,
  46. .sync_sg_for_device = swiotlb_sync_sg_for_device,
  47. .map_sg = swiotlb_map_sg_attrs,
  48. .unmap_sg = swiotlb_unmap_sg_attrs,
  49. .map_page = swiotlb_map_page,
  50. .unmap_page = swiotlb_unmap_page,
  51. .dma_supported = NULL,
  52. };
  53. void __init pci_swiotlb_init(void)
  54. {
  55. /* don't initialize swiotlb if iommu=off (no_iommu=1) */
  56. #ifdef CONFIG_X86_64
  57. if ((!iommu_detected && !no_iommu && max_pfn > MAX_DMA32_PFN) ||
  58. iommu_pass_through)
  59. swiotlb = 1;
  60. #endif
  61. if (swiotlb_force)
  62. swiotlb = 1;
  63. if (swiotlb) {
  64. printk(KERN_INFO "PCI-DMA: Using software bounce buffering for IO (SWIOTLB)\n");
  65. swiotlb_init();
  66. dma_ops = &swiotlb_dma_ops;
  67. }
  68. }