pci-swiotlb.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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_sg_for_cpu = swiotlb_sync_sg_for_cpu,
  28. .sync_sg_for_device = swiotlb_sync_sg_for_device,
  29. .map_sg = swiotlb_map_sg_attrs,
  30. .unmap_sg = swiotlb_unmap_sg_attrs,
  31. .map_page = swiotlb_map_page,
  32. .unmap_page = swiotlb_unmap_page,
  33. .dma_supported = NULL,
  34. };
  35. /*
  36. * pci_swiotlb_detect_override - set swiotlb to 1 if necessary
  37. *
  38. * This returns non-zero if we are forced to use swiotlb (by the boot
  39. * option).
  40. */
  41. int __init pci_swiotlb_detect_override(void)
  42. {
  43. int use_swiotlb = swiotlb | swiotlb_force;
  44. if (swiotlb_force)
  45. swiotlb = 1;
  46. return use_swiotlb;
  47. }
  48. /*
  49. * if 4GB or more detected (and iommu=off not set) return 1
  50. * and set swiotlb to 1.
  51. */
  52. int __init pci_swiotlb_detect_4gb(void)
  53. {
  54. /* don't initialize swiotlb if iommu=off (no_iommu=1) */
  55. #ifdef CONFIG_X86_64
  56. if (!no_iommu && max_pfn > MAX_DMA32_PFN)
  57. swiotlb = 1;
  58. #endif
  59. return swiotlb;
  60. }
  61. void __init pci_swiotlb_init(void)
  62. {
  63. if (swiotlb) {
  64. swiotlb_init(0);
  65. dma_ops = &swiotlb_dma_ops;
  66. }
  67. }
  68. void __init pci_swiotlb_late_init(void)
  69. {
  70. /* An IOMMU turned us off. */
  71. if (!swiotlb)
  72. swiotlb_free();
  73. else {
  74. printk(KERN_INFO "PCI-DMA: "
  75. "Using software bounce buffering for IO (SWIOTLB)\n");
  76. swiotlb_print_info();
  77. }
  78. }