blob: 939260aeac98a6013d8e8ba0ab4a88763fec8e22 [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,
Andrzej Pietrasiewiczbaa676f2012-03-27 14:28:18 +020018 dma_addr_t *dma_handle, gfp_t gfp,
19 struct dma_attrs *attrs)
FUJITA Tomonori97d98002009-01-28 21:53:16 +090020{
Yang Hongyange9304382009-04-13 14:40:14 -070021 if (dev->coherent_dma_mask != DMA_BIT_MASK(64))
FUJITA Tomonori97d98002009-01-28 21:53:16 +090022 gfp |= GFP_DMA;
23 return swiotlb_alloc_coherent(dev, size, dma_handle, gfp);
24}
25
Andrzej Pietrasiewiczbaa676f2012-03-27 14:28:18 +020026static void ia64_swiotlb_free_coherent(struct device *dev, size_t size,
27 void *vaddr, dma_addr_t dma_addr,
28 struct dma_attrs *attrs)
29{
30 swiotlb_free_coherent(dev, size, vaddr, dma_addr);
31}
32
FUJITA Tomonori160c1d82009-01-05 23:59:02 +090033struct dma_map_ops swiotlb_dma_ops = {
Andrzej Pietrasiewiczbaa676f2012-03-27 14:28:18 +020034 .alloc = ia64_swiotlb_alloc_coherent,
35 .free = ia64_swiotlb_free_coherent,
FUJITA Tomonori160c1d82009-01-05 23:59:02 +090036 .map_page = swiotlb_map_page,
37 .unmap_page = swiotlb_unmap_page,
38 .map_sg = swiotlb_map_sg_attrs,
39 .unmap_sg = swiotlb_unmap_sg_attrs,
Fenghua Yu62fdd762008-10-17 12:14:13 -070040 .sync_single_for_cpu = swiotlb_sync_single_for_cpu,
41 .sync_single_for_device = swiotlb_sync_single_for_device,
Fenghua Yu62fdd762008-10-17 12:14:13 -070042 .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu,
43 .sync_sg_for_device = swiotlb_sync_sg_for_device,
FUJITA Tomonori160c1d82009-01-05 23:59:02 +090044 .dma_supported = swiotlb_dma_supported,
FUJITA Tomonoric82e4412009-01-05 23:36:11 +090045 .mapping_error = swiotlb_dma_mapping_error,
Fenghua Yu62fdd762008-10-17 12:14:13 -070046};
47
Luck, Tony07716e42009-01-06 10:25:25 -080048void __init swiotlb_dma_init(void)
FUJITA Tomonori4d9b9772009-01-05 23:36:12 +090049{
50 dma_ops = &swiotlb_dma_ops;
FUJITA Tomonoriad32e8c2009-11-10 19:46:19 +090051 swiotlb_init(1);
FUJITA Tomonori4d9b9772009-01-05 23:36:12 +090052}
53
Fenghua Yu62fdd762008-10-17 12:14:13 -070054void __init pci_swiotlb_init(void)
55{
David Woodhouseba6c5482009-08-13 18:18:00 +010056 if (!iommu_detected) {
Fenghua Yu62fdd762008-10-17 12:14:13 -070057#ifdef CONFIG_IA64_GENERIC
58 swiotlb = 1;
59 printk(KERN_INFO "PCI-DMA: Re-initialize machine vector.\n");
60 machvec_init("dig");
FUJITA Tomonoriad32e8c2009-11-10 19:46:19 +090061 swiotlb_init(1);
Fenghua Yu62fdd762008-10-17 12:14:13 -070062 dma_ops = &swiotlb_dma_ops;
63#else
64 panic("Unable to find Intel IOMMU");
65#endif
66 }
67}