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> |
| 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 | |
| 13 | int swiotlb __read_mostly; |
| 14 | EXPORT_SYMBOL(swiotlb); |
| 15 | |
FUJITA Tomonori | c82e441 | 2009-01-05 23:36:11 +0900 | [diff] [blame] | 16 | /* Set this to 1 if there is a HW IOMMU in the system */ |
| 17 | int iommu_detected __read_mostly; |
| 18 | |
FUJITA Tomonori | 160c1d8 | 2009-01-05 23:59:02 +0900 | [diff] [blame^] | 19 | static dma_addr_t swiotlb_map_page(struct device *dev, struct page *page, |
| 20 | unsigned long offset, size_t size, |
| 21 | enum dma_data_direction dir, |
| 22 | struct dma_attrs *attrs) |
| 23 | { |
| 24 | return swiotlb_map_single_attrs(dev, page_address(page) + offset, size, |
| 25 | dir, attrs); |
| 26 | } |
| 27 | |
| 28 | static void swiotlb_unmap_page(struct device *dev, dma_addr_t dma_handle, |
| 29 | size_t size, enum dma_data_direction dir, |
| 30 | struct dma_attrs *attrs) |
| 31 | { |
| 32 | swiotlb_unmap_single_attrs(dev, dma_handle, size, dir, attrs); |
| 33 | } |
| 34 | |
| 35 | struct dma_map_ops swiotlb_dma_ops = { |
Fenghua Yu | 62fdd76 | 2008-10-17 12:14:13 -0700 | [diff] [blame] | 36 | .alloc_coherent = swiotlb_alloc_coherent, |
| 37 | .free_coherent = swiotlb_free_coherent, |
FUJITA Tomonori | 160c1d8 | 2009-01-05 23:59:02 +0900 | [diff] [blame^] | 38 | .map_page = swiotlb_map_page, |
| 39 | .unmap_page = swiotlb_unmap_page, |
| 40 | .map_sg = swiotlb_map_sg_attrs, |
| 41 | .unmap_sg = swiotlb_unmap_sg_attrs, |
Fenghua Yu | 62fdd76 | 2008-10-17 12:14:13 -0700 | [diff] [blame] | 42 | .sync_single_for_cpu = swiotlb_sync_single_for_cpu, |
| 43 | .sync_single_for_device = swiotlb_sync_single_for_device, |
| 44 | .sync_single_range_for_cpu = swiotlb_sync_single_range_for_cpu, |
| 45 | .sync_single_range_for_device = swiotlb_sync_single_range_for_device, |
| 46 | .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu, |
| 47 | .sync_sg_for_device = swiotlb_sync_sg_for_device, |
FUJITA Tomonori | 160c1d8 | 2009-01-05 23:59:02 +0900 | [diff] [blame^] | 48 | .dma_supported = swiotlb_dma_supported, |
FUJITA Tomonori | c82e441 | 2009-01-05 23:36:11 +0900 | [diff] [blame] | 49 | .mapping_error = swiotlb_dma_mapping_error, |
Fenghua Yu | 62fdd76 | 2008-10-17 12:14:13 -0700 | [diff] [blame] | 50 | }; |
| 51 | |
FUJITA Tomonori | 4d9b977 | 2009-01-05 23:36:12 +0900 | [diff] [blame] | 52 | void swiotlb_dma_init(void) |
| 53 | { |
| 54 | dma_ops = &swiotlb_dma_ops; |
| 55 | swiotlb_init(); |
| 56 | } |
| 57 | |
Fenghua Yu | 62fdd76 | 2008-10-17 12:14:13 -0700 | [diff] [blame] | 58 | void __init pci_swiotlb_init(void) |
| 59 | { |
| 60 | if (!iommu_detected) { |
| 61 | #ifdef CONFIG_IA64_GENERIC |
| 62 | swiotlb = 1; |
| 63 | printk(KERN_INFO "PCI-DMA: Re-initialize machine vector.\n"); |
| 64 | machvec_init("dig"); |
| 65 | swiotlb_init(); |
| 66 | dma_ops = &swiotlb_dma_ops; |
| 67 | #else |
| 68 | panic("Unable to find Intel IOMMU"); |
| 69 | #endif |
| 70 | } |
| 71 | } |