| Fenghua Yu | 62fdd76 | 2008-10-17 12:14:13 -0700 | [diff] [blame] | 1 | /* Glue code to lib/swiotlb.c */ | 
|  | 2 |  | 
|  | 3 | #include <linux/pci.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 4 | #include <linux/gfp.h> | 
| Fenghua Yu | 62fdd76 | 2008-10-17 12:14:13 -0700 | [diff] [blame] | 5 | #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 |  | 
|  | 14 | int swiotlb __read_mostly; | 
|  | 15 | EXPORT_SYMBOL(swiotlb); | 
|  | 16 |  | 
| FUJITA Tomonori | 97d9800 | 2009-01-28 21:53:16 +0900 | [diff] [blame] | 17 | static void *ia64_swiotlb_alloc_coherent(struct device *dev, size_t size, | 
| Andrzej Pietrasiewicz | baa676f | 2012-03-27 14:28:18 +0200 | [diff] [blame] | 18 | dma_addr_t *dma_handle, gfp_t gfp, | 
|  | 19 | struct dma_attrs *attrs) | 
| FUJITA Tomonori | 97d9800 | 2009-01-28 21:53:16 +0900 | [diff] [blame] | 20 | { | 
| Yang Hongyang | e930438 | 2009-04-13 14:40:14 -0700 | [diff] [blame] | 21 | if (dev->coherent_dma_mask != DMA_BIT_MASK(64)) | 
| FUJITA Tomonori | 97d9800 | 2009-01-28 21:53:16 +0900 | [diff] [blame] | 22 | gfp |= GFP_DMA; | 
|  | 23 | return swiotlb_alloc_coherent(dev, size, dma_handle, gfp); | 
|  | 24 | } | 
|  | 25 |  | 
| Andrzej Pietrasiewicz | baa676f | 2012-03-27 14:28:18 +0200 | [diff] [blame] | 26 | static 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 Tomonori | 160c1d8 | 2009-01-05 23:59:02 +0900 | [diff] [blame] | 33 | struct dma_map_ops swiotlb_dma_ops = { | 
| Andrzej Pietrasiewicz | baa676f | 2012-03-27 14:28:18 +0200 | [diff] [blame] | 34 | .alloc = ia64_swiotlb_alloc_coherent, | 
|  | 35 | .free = ia64_swiotlb_free_coherent, | 
| FUJITA Tomonori | 160c1d8 | 2009-01-05 23:59:02 +0900 | [diff] [blame] | 36 | .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 Yu | 62fdd76 | 2008-10-17 12:14:13 -0700 | [diff] [blame] | 40 | .sync_single_for_cpu = swiotlb_sync_single_for_cpu, | 
|  | 41 | .sync_single_for_device = swiotlb_sync_single_for_device, | 
| Fenghua Yu | 62fdd76 | 2008-10-17 12:14:13 -0700 | [diff] [blame] | 42 | .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu, | 
|  | 43 | .sync_sg_for_device = swiotlb_sync_sg_for_device, | 
| FUJITA Tomonori | 160c1d8 | 2009-01-05 23:59:02 +0900 | [diff] [blame] | 44 | .dma_supported = swiotlb_dma_supported, | 
| FUJITA Tomonori | c82e441 | 2009-01-05 23:36:11 +0900 | [diff] [blame] | 45 | .mapping_error = swiotlb_dma_mapping_error, | 
| Fenghua Yu | 62fdd76 | 2008-10-17 12:14:13 -0700 | [diff] [blame] | 46 | }; | 
|  | 47 |  | 
| Luck, Tony | 07716e4 | 2009-01-06 10:25:25 -0800 | [diff] [blame] | 48 | void __init swiotlb_dma_init(void) | 
| FUJITA Tomonori | 4d9b977 | 2009-01-05 23:36:12 +0900 | [diff] [blame] | 49 | { | 
|  | 50 | dma_ops = &swiotlb_dma_ops; | 
| FUJITA Tomonori | ad32e8c | 2009-11-10 19:46:19 +0900 | [diff] [blame] | 51 | swiotlb_init(1); | 
| FUJITA Tomonori | 4d9b977 | 2009-01-05 23:36:12 +0900 | [diff] [blame] | 52 | } | 
|  | 53 |  | 
| Fenghua Yu | 62fdd76 | 2008-10-17 12:14:13 -0700 | [diff] [blame] | 54 | void __init pci_swiotlb_init(void) | 
|  | 55 | { | 
| David Woodhouse | ba6c548 | 2009-08-13 18:18:00 +0100 | [diff] [blame] | 56 | if (!iommu_detected) { | 
| Fenghua Yu | 62fdd76 | 2008-10-17 12:14:13 -0700 | [diff] [blame] | 57 | #ifdef CONFIG_IA64_GENERIC | 
|  | 58 | swiotlb = 1; | 
|  | 59 | printk(KERN_INFO "PCI-DMA: Re-initialize machine vector.\n"); | 
|  | 60 | machvec_init("dig"); | 
| FUJITA Tomonori | ad32e8c | 2009-11-10 19:46:19 +0900 | [diff] [blame] | 61 | swiotlb_init(1); | 
| Fenghua Yu | 62fdd76 | 2008-10-17 12:14:13 -0700 | [diff] [blame] | 62 | dma_ops = &swiotlb_dma_ops; | 
|  | 63 | #else | 
|  | 64 | panic("Unable to find Intel IOMMU"); | 
|  | 65 | #endif | 
|  | 66 | } | 
|  | 67 | } |