Merge git://git.kernel.org/pub/scm/linux/kernel/git/wim/linux-2.6-watchdog
[deliverable/linux.git] / arch / x86 / kernel / pci-swiotlb.c
CommitLineData
17a941d8
MBY
1/* Glue code to lib/swiotlb.c */
2
3#include <linux/pci.h>
4#include <linux/cache.h>
5#include <linux/module.h>
8ce79960
JF
6#include <linux/swiotlb.h>
7#include <linux/bootmem.h>
d6bd3a39
REB
8#include <linux/dma-mapping.h>
9
46a7fa27 10#include <asm/iommu.h>
17a941d8
MBY
11#include <asm/swiotlb.h>
12#include <asm/dma.h>
c116c545
KRW
13#include <asm/xen/swiotlb-xen.h>
14#include <asm/iommu_table.h>
17a941d8 15int swiotlb __read_mostly;
17a941d8 16
03967c52
FT
17static void *x86_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
18 dma_addr_t *dma_handle, gfp_t flags)
19{
20 void *vaddr;
21
22 vaddr = dma_generic_alloc_coherent(hwdev, size, dma_handle, flags);
23 if (vaddr)
24 return vaddr;
25
26 return swiotlb_alloc_coherent(hwdev, size, dma_handle, flags);
27}
28
ff6c6fed 29static struct dma_map_ops swiotlb_dma_ops = {
17a941d8 30 .mapping_error = swiotlb_dma_mapping_error,
03967c52 31 .alloc_coherent = x86_swiotlb_alloc_coherent,
17a941d8 32 .free_coherent = swiotlb_free_coherent,
17a941d8
MBY
33 .sync_single_for_cpu = swiotlb_sync_single_for_cpu,
34 .sync_single_for_device = swiotlb_sync_single_for_device,
17a941d8
MBY
35 .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu,
36 .sync_sg_for_device = swiotlb_sync_sg_for_device,
160c1d8e
FT
37 .map_sg = swiotlb_map_sg_attrs,
38 .unmap_sg = swiotlb_unmap_sg_attrs,
4cf37bb7
FT
39 .map_page = swiotlb_map_page,
40 .unmap_page = swiotlb_unmap_page,
17a941d8
MBY
41 .dma_supported = NULL,
42};
43
b18485e7 44/*
efa631c2 45 * pci_swiotlb_detect_override - set swiotlb to 1 if necessary
b18485e7
FT
46 *
47 * This returns non-zero if we are forced to use swiotlb (by the boot
48 * option).
49 */
efa631c2 50int __init pci_swiotlb_detect_override(void)
17a941d8 51{
273bee27
FT
52 int use_swiotlb = swiotlb | swiotlb_force;
53
efa631c2
KRW
54 if (swiotlb_force)
55 swiotlb = 1;
56
57 return use_swiotlb;
58}
c116c545
KRW
59IOMMU_INIT_FINISH(pci_swiotlb_detect_override,
60 pci_xen_swiotlb_detect,
61 pci_swiotlb_init,
62 pci_swiotlb_late_init);
efa631c2
KRW
63
64/*
65 * if 4GB or more detected (and iommu=off not set) return 1
66 * and set swiotlb to 1.
67 */
68int __init pci_swiotlb_detect_4gb(void)
69{
17a941d8 70 /* don't initialize swiotlb if iommu=off (no_iommu=1) */
cfb80c9e 71#ifdef CONFIG_X86_64
75f1cdf1 72 if (!no_iommu && max_pfn > MAX_DMA32_PFN)
19943b0e 73 swiotlb = 1;
cfb80c9e 74#endif
efa631c2 75 return swiotlb;
186a2502 76}
c116c545
KRW
77IOMMU_INIT(pci_swiotlb_detect_4gb,
78 pci_swiotlb_detect_override,
79 pci_swiotlb_init,
80 pci_swiotlb_late_init);
186a2502
FT
81
82void __init pci_swiotlb_init(void)
83{
17a941d8 84 if (swiotlb) {
ad32e8cb 85 swiotlb_init(0);
17a941d8 86 dma_ops = &swiotlb_dma_ops;
a3b28ee1 87 }
17a941d8 88}
efa631c2
KRW
89
90void __init pci_swiotlb_late_init(void)
91{
92 /* An IOMMU turned us off. */
93 if (!swiotlb)
94 swiotlb_free();
95 else {
96 printk(KERN_INFO "PCI-DMA: "
97 "Using software bounce buffering for IO (SWIOTLB)\n");
98 swiotlb_print_info();
99 }
100}
This page took 0.551392 seconds and 5 git commands to generate.