| Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 1 | /* Glue code to lib/swiotlb.c */ | 
 | 2 |  | 
 | 3 | #include <linux/pci.h> | 
 | 4 | #include <linux/cache.h> | 
 | 5 | #include <linux/module.h> | 
| Jeremy Fitzhardinge | 8ce7996 | 2008-12-16 12:17:35 -0800 | [diff] [blame] | 6 | #include <linux/swiotlb.h> | 
 | 7 | #include <linux/bootmem.h> | 
| Rolf Eike Beer | d6bd3a3 | 2006-09-29 01:59:48 -0700 | [diff] [blame] | 8 | #include <linux/dma-mapping.h> | 
 | 9 |  | 
| FUJITA Tomonori | 46a7fa2 | 2008-07-11 10:23:42 +0900 | [diff] [blame] | 10 | #include <asm/iommu.h> | 
| Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 11 | #include <asm/swiotlb.h> | 
 | 12 | #include <asm/dma.h> | 
 | 13 |  | 
 | 14 | int swiotlb __read_mostly; | 
| Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 15 |  | 
| FUJITA Tomonori | 03967c5 | 2008-10-23 23:14:29 +0900 | [diff] [blame] | 16 | static void *x86_swiotlb_alloc_coherent(struct device *hwdev, size_t size, | 
 | 17 | 					dma_addr_t *dma_handle, gfp_t flags) | 
 | 18 | { | 
 | 19 | 	void *vaddr; | 
 | 20 |  | 
 | 21 | 	vaddr = dma_generic_alloc_coherent(hwdev, size, dma_handle, flags); | 
 | 22 | 	if (vaddr) | 
 | 23 | 		return vaddr; | 
 | 24 |  | 
 | 25 | 	return swiotlb_alloc_coherent(hwdev, size, dma_handle, flags); | 
 | 26 | } | 
 | 27 |  | 
| Jaswinder Singh Rajput | ff6c6fe | 2009-04-12 23:24:21 +0530 | [diff] [blame] | 28 | static struct dma_map_ops swiotlb_dma_ops = { | 
| Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 29 | 	.mapping_error = swiotlb_dma_mapping_error, | 
| FUJITA Tomonori | 03967c5 | 2008-10-23 23:14:29 +0900 | [diff] [blame] | 30 | 	.alloc_coherent = x86_swiotlb_alloc_coherent, | 
| Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 31 | 	.free_coherent = swiotlb_free_coherent, | 
| Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 32 | 	.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 Tomonori | 160c1d8 | 2009-01-05 23:59:02 +0900 | [diff] [blame] | 38 | 	.map_sg = swiotlb_map_sg_attrs, | 
 | 39 | 	.unmap_sg = swiotlb_unmap_sg_attrs, | 
| FUJITA Tomonori | 4cf37bb | 2009-01-05 23:47:22 +0900 | [diff] [blame] | 40 | 	.map_page = swiotlb_map_page, | 
 | 41 | 	.unmap_page = swiotlb_unmap_page, | 
| Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 42 | 	.dma_supported = NULL, | 
 | 43 | }; | 
 | 44 |  | 
| Jan Beulich | 563aaf0 | 2007-02-05 18:51:25 -0800 | [diff] [blame] | 45 | void __init pci_swiotlb_init(void) | 
| Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 46 | { | 
 | 47 | 	/* don't initialize swiotlb if iommu=off (no_iommu=1) */ | 
| Jeremy Fitzhardinge | cfb80c9 | 2008-12-16 12:17:36 -0800 | [diff] [blame] | 48 | #ifdef CONFIG_X86_64 | 
| Fenghua Yu | 4ed0d3e | 2009-04-24 17:30:20 -0700 | [diff] [blame] | 49 | 	if ((!iommu_detected && !no_iommu && max_pfn > MAX_DMA32_PFN) || | 
 | 50 | 		iommu_pass_through) | 
| Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 51 | 	       swiotlb = 1; | 
| Jeremy Fitzhardinge | cfb80c9 | 2008-12-16 12:17:36 -0800 | [diff] [blame] | 52 | #endif | 
| Andi Kleen | 65f87d8 | 2006-07-29 21:42:49 +0200 | [diff] [blame] | 53 | 	if (swiotlb_force) | 
 | 54 | 		swiotlb = 1; | 
| Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 55 | 	if (swiotlb) { | 
| Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 56 | 		printk(KERN_INFO "PCI-DMA: Using software bounce buffering for IO (SWIOTLB)\n"); | 
| Jon Mason | 5b7b644 | 2006-02-03 21:51:59 +0100 | [diff] [blame] | 57 | 		swiotlb_init(); | 
| Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 58 | 		dma_ops = &swiotlb_dma_ops; | 
 | 59 | 	} | 
 | 60 | } |