x86, ia64: convert to use generic dma_map_ops struct
[linux-2.6.git] / arch / ia64 / kernel / pci-swiotlb.c
1 /* Glue code to lib/swiotlb.c */
2
3 #include <linux/pci.h>
4 #include <linux/cache.h>
5 #include <linux/module.h>
6 #include <linux/dma-mapping.h>
7
8 #include <asm/swiotlb.h>
9 #include <asm/dma.h>
10 #include <asm/iommu.h>
11 #include <asm/machvec.h>
12
13 int swiotlb __read_mostly;
14 EXPORT_SYMBOL(swiotlb);
15
16 /* Set this to 1 if there is a HW IOMMU in the system */
17 int iommu_detected __read_mostly;
18
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)
23 {
24         return swiotlb_map_single_attrs(dev, page_address(page) + offset, size,
25                                         dir, attrs);
26 }
27
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)
31 {
32         swiotlb_unmap_single_attrs(dev, dma_handle, size, dir, attrs);
33 }
34
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,
50 };
51
52 void swiotlb_dma_init(void)
53 {
54         dma_ops = &swiotlb_dma_ops;
55         swiotlb_init();
56 }
57
58 void __init pci_swiotlb_init(void)
59 {
60         if (!iommu_detected) {
61 #ifdef CONFIG_IA64_GENERIC
62                 swiotlb = 1;
63                 printk(KERN_INFO "PCI-DMA: Re-initialize machine vector.\n");
64                 machvec_init("dig");
65                 swiotlb_init();
66                 dma_ops = &swiotlb_dma_ops;
67 #else
68                 panic("Unable to find Intel IOMMU");
69 #endif
70         }
71 }