blob: 3095654f9ab394839b9ae52509b5ec786c9f7837 [file] [log] [blame]
Fenghua Yu62fdd762008-10-17 12:14:13 -07001/* Glue code to lib/swiotlb.c */
2
3#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09004#include <linux/gfp.h>
Fenghua Yu62fdd762008-10-17 12:14:13 -07005#include <linux/cache.h>
6#include <linux/module.h>
7#include <linux/dma-mapping.h>
8
9#include <asm/swiotlb.h>
10#include <asm/dma.h>
11#include <asm/iommu.h>
12#include <asm/machvec.h>
13
14int swiotlb __read_mostly;
15EXPORT_SYMBOL(swiotlb);
16
FUJITA Tomonori97d98002009-01-28 21:53:16 +090017static void *ia64_swiotlb_alloc_coherent(struct device *dev, size_t size,
18 dma_addr_t *dma_handle, gfp_t gfp)
19{
Yang Hongyange9304382009-04-13 14:40:14 -070020 if (dev->coherent_dma_mask != DMA_BIT_MASK(64))
FUJITA Tomonori97d98002009-01-28 21:53:16 +090021 gfp |= GFP_DMA;
22 return swiotlb_alloc_coherent(dev, size, dma_handle, gfp);
23}
24
FUJITA Tomonori160c1d82009-01-05 23:59:02 +090025struct dma_map_ops swiotlb_dma_ops = {
FUJITA Tomonori97d98002009-01-28 21:53:16 +090026 .alloc_coherent = ia64_swiotlb_alloc_coherent,
Fenghua Yu62fdd762008-10-17 12:14:13 -070027 .free_coherent = swiotlb_free_coherent,
FUJITA Tomonori160c1d82009-01-05 23:59:02 +090028 .map_page = swiotlb_map_page,
29 .unmap_page = swiotlb_unmap_page,
30 .map_sg = swiotlb_map_sg_attrs,
31 .unmap_sg = swiotlb_unmap_sg_attrs,
Fenghua Yu62fdd762008-10-17 12:14:13 -070032 .sync_single_for_cpu = swiotlb_sync_single_for_cpu,
33 .sync_single_for_device = swiotlb_sync_single_for_device,
34 .sync_single_range_for_cpu = swiotlb_sync_single_range_for_cpu,
35 .sync_single_range_for_device = swiotlb_sync_single_range_for_device,
36 .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu,
37 .sync_sg_for_device = swiotlb_sync_sg_for_device,
FUJITA Tomonori160c1d82009-01-05 23:59:02 +090038 .dma_supported = swiotlb_dma_supported,
FUJITA Tomonoric82e4412009-01-05 23:36:11 +090039 .mapping_error = swiotlb_dma_mapping_error,
Fenghua Yu62fdd762008-10-17 12:14:13 -070040};
41
Luck, Tony07716e42009-01-06 10:25:25 -080042void __init swiotlb_dma_init(void)
FUJITA Tomonori4d9b9772009-01-05 23:36:12 +090043{
44 dma_ops = &swiotlb_dma_ops;
FUJITA Tomonoriad32e8c2009-11-10 19:46:19 +090045 swiotlb_init(1);
FUJITA Tomonori4d9b9772009-01-05 23:36:12 +090046}
47
Fenghua Yu62fdd762008-10-17 12:14:13 -070048void __init pci_swiotlb_init(void)
49{
David Woodhouseba6c5482009-08-13 18:18:00 +010050 if (!iommu_detected) {
Fenghua Yu62fdd762008-10-17 12:14:13 -070051#ifdef CONFIG_IA64_GENERIC
52 swiotlb = 1;
53 printk(KERN_INFO "PCI-DMA: Re-initialize machine vector.\n");
54 machvec_init("dig");
FUJITA Tomonoriad32e8c2009-11-10 19:46:19 +090055 swiotlb_init(1);
Fenghua Yu62fdd762008-10-17 12:14:13 -070056 dma_ops = &swiotlb_dma_ops;
57#else
58 panic("Unable to find Intel IOMMU");
59#endif
60 }
61}