blob: 490da7f4b8d0dd8e29abf7ddd2e11b01fe19f196 [file] [log] [blame]
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +01001/* Glue code to lib/swiotlb.c */
2
3#include <linux/pci.h>
4#include <linux/cache.h>
5#include <linux/module.h>
Rolf Eike Beerd6bd3a32006-09-29 01:59:48 -07006#include <linux/dma-mapping.h>
7
Joerg Roedel395624f2007-10-24 12:49:47 +02008#include <asm/gart.h>
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +01009#include <asm/swiotlb.h>
10#include <asm/dma.h>
11
12int swiotlb __read_mostly;
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010013
Ingo Molnar2be62142008-04-19 19:19:56 +020014static dma_addr_t
15swiotlb_map_single_phys(struct device *hwdev, phys_addr_t paddr, size_t size,
16 int direction)
17{
18 return swiotlb_map_single(hwdev, phys_to_virt(paddr), size, direction);
19}
20
Stephen Hemmingere6584502007-05-02 19:27:06 +020021const struct dma_mapping_ops swiotlb_dma_ops = {
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010022 .mapping_error = swiotlb_dma_mapping_error,
23 .alloc_coherent = swiotlb_alloc_coherent,
24 .free_coherent = swiotlb_free_coherent,
Ingo Molnar2be62142008-04-19 19:19:56 +020025 .map_single = swiotlb_map_single_phys,
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010026 .unmap_single = swiotlb_unmap_single,
27 .sync_single_for_cpu = swiotlb_sync_single_for_cpu,
28 .sync_single_for_device = swiotlb_sync_single_for_device,
29 .sync_single_range_for_cpu = swiotlb_sync_single_range_for_cpu,
30 .sync_single_range_for_device = swiotlb_sync_single_range_for_device,
31 .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu,
32 .sync_sg_for_device = swiotlb_sync_sg_for_device,
33 .map_sg = swiotlb_map_sg,
34 .unmap_sg = swiotlb_unmap_sg,
35 .dma_supported = NULL,
36};
37
Jan Beulich563aaf02007-02-05 18:51:25 -080038void __init pci_swiotlb_init(void)
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010039{
40 /* don't initialize swiotlb if iommu=off (no_iommu=1) */
Andi Kleen65f87d82006-07-29 21:42:49 +020041 if (!iommu_detected && !no_iommu && end_pfn > MAX_DMA32_PFN)
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010042 swiotlb = 1;
Andi Kleen65f87d82006-07-29 21:42:49 +020043 if (swiotlb_force)
44 swiotlb = 1;
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010045 if (swiotlb) {
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010046 printk(KERN_INFO "PCI-DMA: Using software bounce buffering for IO (SWIOTLB)\n");
Jon Mason5b7b6442006-02-03 21:51:59 +010047 swiotlb_init();
Muli Ben-Yehuda17a941d2006-01-11 22:44:42 +010048 dma_ops = &swiotlb_dma_ops;
49 }
50}