blob: 91443361cb67288678ec785b619b0d531236c093 [file] [log] [blame]
Glauber Costa459121c92008-04-08 13:20:43 -03001#include <linux/dma-mapping.h>
Glauber Costacb5867a2008-04-08 13:20:51 -03002#include <linux/dmar.h>
Glauber Costa116890d2008-04-08 13:20:54 -03003#include <linux/bootmem.h>
Glauber Costacb5867a2008-04-08 13:20:51 -03004
Glauber Costa116890d2008-04-08 13:20:54 -03005#include <asm/proto.h>
6#include <asm/dma.h>
Glauber Costacb5867a2008-04-08 13:20:51 -03007#include <asm/gart.h>
8#include <asm/calgary.h>
Glauber Costa459121c92008-04-08 13:20:43 -03009
Glauber Costa85c246e2008-04-08 13:20:50 -030010const struct dma_mapping_ops *dma_ops;
11EXPORT_SYMBOL(dma_ops);
12
Glauber Costaf9c258d2008-04-08 13:20:52 -030013#ifdef CONFIG_IOMMU_DEBUG
14int panic_on_overflow __read_mostly = 1;
15int force_iommu __read_mostly = 1;
16#else
17int panic_on_overflow __read_mostly = 0;
18int force_iommu __read_mostly = 0;
19#endif
20
Glauber Costa459121c92008-04-08 13:20:43 -030021int dma_set_mask(struct device *dev, u64 mask)
22{
23 if (!dev->dma_mask || !dma_supported(dev, mask))
24 return -EIO;
25
26 *dev->dma_mask = mask;
27
28 return 0;
29}
30EXPORT_SYMBOL(dma_set_mask);
31
Glauber Costa116890d2008-04-08 13:20:54 -030032#ifdef CONFIG_X86_64
33static __initdata void *dma32_bootmem_ptr;
34static unsigned long dma32_bootmem_size __initdata = (128ULL<<20);
35
36static int __init parse_dma32_size_opt(char *p)
37{
38 if (!p)
39 return -EINVAL;
40 dma32_bootmem_size = memparse(p, &p);
41 return 0;
42}
43early_param("dma32_size", parse_dma32_size_opt);
44
45void __init dma32_reserve_bootmem(void)
46{
47 unsigned long size, align;
48 if (end_pfn <= MAX_DMA32_PFN)
49 return;
50
51 align = 64ULL<<20;
52 size = round_up(dma32_bootmem_size, align);
53 dma32_bootmem_ptr = __alloc_bootmem_nopanic(size, align,
54 __pa(MAX_DMA_ADDRESS));
55 if (dma32_bootmem_ptr)
56 dma32_bootmem_size = size;
57 else
58 dma32_bootmem_size = 0;
59}
60static void __init dma32_free_bootmem(void)
61{
62 int node;
63
64 if (end_pfn <= MAX_DMA32_PFN)
65 return;
66
67 if (!dma32_bootmem_ptr)
68 return;
69
70 for_each_online_node(node)
71 free_bootmem_node(NODE_DATA(node), __pa(dma32_bootmem_ptr),
72 dma32_bootmem_size);
73
74 dma32_bootmem_ptr = NULL;
75 dma32_bootmem_size = 0;
76}
77
78void __init pci_iommu_alloc(void)
79{
80 /* free the range so iommu could get some range less than 4G */
81 dma32_free_bootmem();
82 /*
83 * The order of these functions is important for
84 * fall-back/fail-over reasons
85 */
86#ifdef CONFIG_GART_IOMMU
87 gart_iommu_hole_init();
88#endif
89
90#ifdef CONFIG_CALGARY_IOMMU
91 detect_calgary();
92#endif
93
94 detect_intel_iommu();
95
96#ifdef CONFIG_SWIOTLB
97 pci_swiotlb_init();
98#endif
99}
100#endif
101
Glauber Costacb5867a2008-04-08 13:20:51 -0300102static int __init pci_iommu_init(void)
103{
104#ifdef CONFIG_CALGARY_IOMMU
105 calgary_iommu_init();
106#endif
Glauber Costa459121c92008-04-08 13:20:43 -0300107
Glauber Costacb5867a2008-04-08 13:20:51 -0300108 intel_iommu_init();
109
110#ifdef CONFIG_GART_IOMMU
111 gart_iommu_init();
112#endif
113
114 no_iommu_init();
115 return 0;
116}
117
118void pci_iommu_shutdown(void)
119{
120 gart_iommu_shutdown();
121}
122/* Must execute after PCI subsystem */
123fs_initcall(pci_iommu_init);