pci-swiotlb.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Glue code to lib/swiotlb.c */
  2. #include <linux/pci.h>
  3. #include <linux/gfp.h>
  4. #include <linux/cache.h>
  5. #include <linux/module.h>
  6. #include <linux/dma-mapping.h>
  7. #include <asm/swiotlb.h>
  8. #include <asm/dma.h>
  9. #include <asm/iommu.h>
  10. #include <asm/machvec.h>
  11. int swiotlb __read_mostly;
  12. EXPORT_SYMBOL(swiotlb);
  13. static void *ia64_swiotlb_alloc_coherent(struct device *dev, size_t size,
  14. dma_addr_t *dma_handle, gfp_t gfp,
  15. struct dma_attrs *attrs)
  16. {
  17. if (dev->coherent_dma_mask != DMA_BIT_MASK(64))
  18. gfp |= GFP_DMA;
  19. return swiotlb_alloc_coherent(dev, size, dma_handle, gfp);
  20. }
  21. static void ia64_swiotlb_free_coherent(struct device *dev, size_t size,
  22. void *vaddr, dma_addr_t dma_addr,
  23. struct dma_attrs *attrs)
  24. {
  25. swiotlb_free_coherent(dev, size, vaddr, dma_addr);
  26. }
  27. struct dma_map_ops swiotlb_dma_ops = {
  28. .alloc = ia64_swiotlb_alloc_coherent,
  29. .free = ia64_swiotlb_free_coherent,
  30. .map_page = swiotlb_map_page,
  31. .unmap_page = swiotlb_unmap_page,
  32. .map_sg = swiotlb_map_sg_attrs,
  33. .unmap_sg = swiotlb_unmap_sg_attrs,
  34. .sync_single_for_cpu = swiotlb_sync_single_for_cpu,
  35. .sync_single_for_device = swiotlb_sync_single_for_device,
  36. .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu,
  37. .sync_sg_for_device = swiotlb_sync_sg_for_device,
  38. .dma_supported = swiotlb_dma_supported,
  39. .mapping_error = swiotlb_dma_mapping_error,
  40. };
  41. void __init swiotlb_dma_init(void)
  42. {
  43. dma_ops = &swiotlb_dma_ops;
  44. swiotlb_init(1);
  45. }
  46. void __init pci_swiotlb_init(void)
  47. {
  48. if (!iommu_detected) {
  49. #ifdef CONFIG_IA64_GENERIC
  50. swiotlb = 1;
  51. printk(KERN_INFO "PCI-DMA: Re-initialize machine vector.\n");
  52. machvec_init("dig");
  53. swiotlb_init(1);
  54. dma_ops = &swiotlb_dma_ops;
  55. #else
  56. panic("Unable to find Intel IOMMU");
  57. #endif
  58. }
  59. }