1 /* Glue code to lib/swiotlb.c */
4 #include <linux/cache.h>
5 #include <linux/module.h>
6 #include <linux/dma-mapping.h>
8 #include <asm/swiotlb.h>
10 #include <asm/iommu.h>
11 #include <asm/machvec.h>
13 int swiotlb __read_mostly;
14 EXPORT_SYMBOL(swiotlb);
16 /* Set this to 1 if there is a HW IOMMU in the system */
17 int iommu_detected __read_mostly;
19 static dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
20 unsigned long offset, size_t size,
21 enum dma_data_direction dir,
22 struct dma_attrs *attrs)
24 return swiotlb_map_single_attrs(dev, page_address(page) + offset, size,
28 static void swiotlb_unmap_page(struct device *dev, dma_addr_t dma_handle,
29 size_t size, enum dma_data_direction dir,
30 struct dma_attrs *attrs)
32 swiotlb_unmap_single_attrs(dev, dma_handle, size, dir, attrs);
35 struct dma_map_ops swiotlb_dma_ops = {
36 .alloc_coherent = swiotlb_alloc_coherent,
37 .free_coherent = swiotlb_free_coherent,
38 .map_page = swiotlb_map_page,
39 .unmap_page = swiotlb_unmap_page,
40 .map_sg = swiotlb_map_sg_attrs,
41 .unmap_sg = swiotlb_unmap_sg_attrs,
42 .sync_single_for_cpu = swiotlb_sync_single_for_cpu,
43 .sync_single_for_device = swiotlb_sync_single_for_device,
44 .sync_single_range_for_cpu = swiotlb_sync_single_range_for_cpu,
45 .sync_single_range_for_device = swiotlb_sync_single_range_for_device,
46 .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu,
47 .sync_sg_for_device = swiotlb_sync_sg_for_device,
48 .dma_supported = swiotlb_dma_supported,
49 .mapping_error = swiotlb_dma_mapping_error,
52 void swiotlb_dma_init(void)
54 dma_ops = &swiotlb_dma_ops;
58 void __init pci_swiotlb_init(void)
60 if (!iommu_detected) {
61 #ifdef CONFIG_IA64_GENERIC
63 printk(KERN_INFO "PCI-DMA: Re-initialize machine vector.\n");
66 dma_ops = &swiotlb_dma_ops;
68 panic("Unable to find Intel IOMMU");