]> nv-tegra.nvidia Code Review - linux-2.6.git/blob - arch/x86/kernel/pci-dma.c
x86: move pci fixup to pci-dma.c
[linux-2.6.git] / arch / x86 / kernel / pci-dma.c
1 #include <linux/dma-mapping.h>
2 #include <linux/dmar.h>
3 #include <linux/bootmem.h>
4 #include <linux/pci.h>
5
6 #include <asm/proto.h>
7 #include <asm/dma.h>
8 #include <asm/gart.h>
9 #include <asm/calgary.h>
10
11 int forbid_dac __read_mostly;
12 EXPORT_SYMBOL(forbid_dac);
13
14 const struct dma_mapping_ops *dma_ops;
15 EXPORT_SYMBOL(dma_ops);
16
17 #ifdef CONFIG_IOMMU_DEBUG
18 int panic_on_overflow __read_mostly = 1;
19 int force_iommu __read_mostly = 1;
20 #else
21 int panic_on_overflow __read_mostly = 0;
22 int force_iommu __read_mostly = 0;
23 #endif
24
25 int dma_set_mask(struct device *dev, u64 mask)
26 {
27         if (!dev->dma_mask || !dma_supported(dev, mask))
28                 return -EIO;
29
30         *dev->dma_mask = mask;
31
32         return 0;
33 }
34 EXPORT_SYMBOL(dma_set_mask);
35
36 #ifdef CONFIG_X86_64
37 static __initdata void *dma32_bootmem_ptr;
38 static unsigned long dma32_bootmem_size __initdata = (128ULL<<20);
39
40 static int __init parse_dma32_size_opt(char *p)
41 {
42         if (!p)
43                 return -EINVAL;
44         dma32_bootmem_size = memparse(p, &p);
45         return 0;
46 }
47 early_param("dma32_size", parse_dma32_size_opt);
48
49 void __init dma32_reserve_bootmem(void)
50 {
51         unsigned long size, align;
52         if (end_pfn <= MAX_DMA32_PFN)
53                 return;
54
55         align = 64ULL<<20;
56         size = round_up(dma32_bootmem_size, align);
57         dma32_bootmem_ptr = __alloc_bootmem_nopanic(size, align,
58                                  __pa(MAX_DMA_ADDRESS));
59         if (dma32_bootmem_ptr)
60                 dma32_bootmem_size = size;
61         else
62                 dma32_bootmem_size = 0;
63 }
64 static void __init dma32_free_bootmem(void)
65 {
66         int node;
67
68         if (end_pfn <= MAX_DMA32_PFN)
69                 return;
70
71         if (!dma32_bootmem_ptr)
72                 return;
73
74         for_each_online_node(node)
75                 free_bootmem_node(NODE_DATA(node), __pa(dma32_bootmem_ptr),
76                                   dma32_bootmem_size);
77
78         dma32_bootmem_ptr = NULL;
79         dma32_bootmem_size = 0;
80 }
81
82 void __init pci_iommu_alloc(void)
83 {
84         /* free the range so iommu could get some range less than 4G */
85         dma32_free_bootmem();
86         /*
87          * The order of these functions is important for
88          * fall-back/fail-over reasons
89          */
90 #ifdef CONFIG_GART_IOMMU
91         gart_iommu_hole_init();
92 #endif
93
94 #ifdef CONFIG_CALGARY_IOMMU
95         detect_calgary();
96 #endif
97
98         detect_intel_iommu();
99
100 #ifdef CONFIG_SWIOTLB
101         pci_swiotlb_init();
102 #endif
103 }
104 #endif
105
106 static int __init pci_iommu_init(void)
107 {
108 #ifdef CONFIG_CALGARY_IOMMU
109         calgary_iommu_init();
110 #endif
111
112         intel_iommu_init();
113
114 #ifdef CONFIG_GART_IOMMU
115         gart_iommu_init();
116 #endif
117
118         no_iommu_init();
119         return 0;
120 }
121
122 void pci_iommu_shutdown(void)
123 {
124         gart_iommu_shutdown();
125 }
126 /* Must execute after PCI subsystem */
127 fs_initcall(pci_iommu_init);
128
129 #ifdef CONFIG_PCI
130 /* Many VIA bridges seem to corrupt data for DAC. Disable it here */
131
132 static __devinit void via_no_dac(struct pci_dev *dev)
133 {
134         if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI && forbid_dac == 0) {
135                 printk(KERN_INFO "PCI: VIA PCI bridge detected."
136                                  "Disabling DAC.\n");
137                 forbid_dac = 1;
138         }
139 }
140 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_ANY_ID, via_no_dac);
141 #endif