blob: 573f02c39a00295adb4edbbb1a2666e9e1e33da7 [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 Tomonori97d98002009-01-28 21:53:16 +090016static void *ia64_swiotlb_alloc_coherent(struct device *dev, size_t size,
17 dma_addr_t *dma_handle, gfp_t gfp)
18{
19 if (dev->coherent_dma_mask != DMA_64BIT_MASK)
20 gfp |= GFP_DMA;
21 return swiotlb_alloc_coherent(dev, size, dma_handle, gfp);
22}
23
FUJITA Tomonori160c1d82009-01-05 23:59:02 +090024struct dma_map_ops swiotlb_dma_ops = {
FUJITA Tomonori97d98002009-01-28 21:53:16 +090025 .alloc_coherent = ia64_swiotlb_alloc_coherent,
Fenghua Yu62fdd762008-10-17 12:14:13 -070026 .free_coherent = swiotlb_free_coherent,
FUJITA Tomonori160c1d82009-01-05 23:59:02 +090027 .map_page = swiotlb_map_page,
28 .unmap_page = swiotlb_unmap_page,
29 .map_sg = swiotlb_map_sg_attrs,
30 .unmap_sg = swiotlb_unmap_sg_attrs,
Fenghua Yu62fdd762008-10-17 12:14:13 -070031 .sync_single_for_cpu = swiotlb_sync_single_for_cpu,
32 .sync_single_for_device = swiotlb_sync_single_for_device,
33 .sync_single_range_for_cpu = swiotlb_sync_single_range_for_cpu,
34 .sync_single_range_for_device = swiotlb_sync_single_range_for_device,
35 .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu,
36 .sync_sg_for_device = swiotlb_sync_sg_for_device,
FUJITA Tomonori160c1d82009-01-05 23:59:02 +090037 .dma_supported = swiotlb_dma_supported,
FUJITA Tomonoric82e4412009-01-05 23:36:11 +090038 .mapping_error = swiotlb_dma_mapping_error,
Fenghua Yu62fdd762008-10-17 12:14:13 -070039};
40
Luck, Tony07716e42009-01-06 10:25:25 -080041void __init swiotlb_dma_init(void)
FUJITA Tomonori4d9b9772009-01-05 23:36:12 +090042{
43 dma_ops = &swiotlb_dma_ops;
44 swiotlb_init();
45}
46
Fenghua Yu62fdd762008-10-17 12:14:13 -070047void __init pci_swiotlb_init(void)
48{
49 if (!iommu_detected) {
50#ifdef CONFIG_IA64_GENERIC
51 swiotlb = 1;
52 printk(KERN_INFO "PCI-DMA: Re-initialize machine vector.\n");
53 machvec_init("dig");
54 swiotlb_init();
55 dma_ops = &swiotlb_dma_ops;
56#else
57 panic("Unable to find Intel IOMMU");
58#endif
59 }
60}