blob: 6bf8f66786bdd81728467418a624ab18c51ed015 [file] [log] [blame]
Fenghua Yu62fdd762008-10-17 12:14:13 -07001/* 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
13int swiotlb __read_mostly;
14EXPORT_SYMBOL(swiotlb);
15
FUJITA Tomonoric82e4412009-01-05 23:36:11 +090016/* Set this to 1 if there is a HW IOMMU in the system */
17int iommu_detected __read_mostly;
18
FUJITA Tomonori160c1d82009-01-05 23:59:02 +090019static 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
28static 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
35struct dma_map_ops swiotlb_dma_ops = {
Fenghua Yu62fdd762008-10-17 12:14:13 -070036 .alloc_coherent = swiotlb_alloc_coherent,
37 .free_coherent = swiotlb_free_coherent,
FUJITA Tomonori160c1d82009-01-05 23:59:02 +090038 .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,
Fenghua Yu62fdd762008-10-17 12:14:13 -070042 .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,
FUJITA Tomonori160c1d82009-01-05 23:59:02 +090048 .dma_supported = swiotlb_dma_supported,
FUJITA Tomonoric82e4412009-01-05 23:36:11 +090049 .mapping_error = swiotlb_dma_mapping_error,
Fenghua Yu62fdd762008-10-17 12:14:13 -070050};
51
FUJITA Tomonori4d9b9772009-01-05 23:36:12 +090052void swiotlb_dma_init(void)
53{
54 dma_ops = &swiotlb_dma_ops;
55 swiotlb_init();
56}
57
Fenghua Yu62fdd762008-10-17 12:14:13 -070058void __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}