blob: dbdb778efa055f3a94298105d9eeeba3b9d086a1 [file] [log] [blame]
Fenghua Yu62fdd762008-10-17 12:14:13 -07001/*
2 * Dynamic DMA mapping support.
3 */
4
5#include <linux/types.h>
6#include <linux/mm.h>
7#include <linux/string.h>
8#include <linux/pci.h>
9#include <linux/module.h>
10#include <linux/dmar.h>
11#include <asm/iommu.h>
12#include <asm/machvec.h>
13#include <linux/dma-mapping.h>
14
Fenghua Yu62fdd762008-10-17 12:14:13 -070015#include <asm/system.h>
16
17#ifdef CONFIG_DMAR
18
19#include <linux/kernel.h>
Fenghua Yu62fdd762008-10-17 12:14:13 -070020
21#include <asm/page.h>
22#include <asm/iommu.h>
23
24dma_addr_t bad_dma_address __read_mostly;
25EXPORT_SYMBOL(bad_dma_address);
26
27static int iommu_sac_force __read_mostly;
28
29int no_iommu __read_mostly;
30#ifdef CONFIG_IOMMU_DEBUG
31int force_iommu __read_mostly = 1;
32#else
33int force_iommu __read_mostly;
34#endif
35
36/* Set this to 1 if there is a HW IOMMU in the system */
37int iommu_detected __read_mostly;
38
39/* Dummy device used for NULL arguments (normally ISA). Better would
40 be probably a smaller DMA mask, but this is bug-to-bug compatible
41 to i386. */
42struct device fallback_dev = {
43 .bus_id = "fallback device",
44 .coherent_dma_mask = DMA_32BIT_MASK,
45 .dma_mask = &fallback_dev.coherent_dma_mask,
46};
47
48void __init pci_iommu_alloc(void)
49{
50 /*
51 * The order of these functions is important for
52 * fall-back/fail-over reasons
53 */
54 detect_intel_iommu();
55
56#ifdef CONFIG_SWIOTLB
57 pci_swiotlb_init();
58#endif
59}
60
61static int __init pci_iommu_init(void)
62{
63 if (iommu_detected)
64 intel_iommu_init();
65
66 return 0;
67}
68
69/* Must execute after PCI subsystem */
70fs_initcall(pci_iommu_init);
71
72void pci_iommu_shutdown(void)
73{
74 return;
75}
76
77void __init
78iommu_dma_init(void)
79{
80 return;
81}
82
83struct dma_mapping_ops *dma_ops;
84EXPORT_SYMBOL(dma_ops);
85
86int iommu_dma_supported(struct device *dev, u64 mask)
87{
88 struct dma_mapping_ops *ops = get_dma_ops(dev);
89
Fenghua Yu62fdd762008-10-17 12:14:13 -070090 if (ops->dma_supported_op)
91 return ops->dma_supported_op(dev, mask);
92
93 /* Copied from i386. Doesn't make much sense, because it will
94 only work for pci_alloc_coherent.
95 The caller just has to use GFP_DMA in this case. */
96 if (mask < DMA_24BIT_MASK)
97 return 0;
98
99 /* Tell the device to use SAC when IOMMU force is on. This
100 allows the driver to use cheaper accesses in some cases.
101
102 Problem with this is that if we overflow the IOMMU area and
103 return DAC as fallback address the device may not handle it
104 correctly.
105
106 As a special case some controllers have a 39bit address
107 mode that is as efficient as 32bit (aic79xx). Don't force
108 SAC for these. Assume all masks <= 40 bits are of this
109 type. Normally this doesn't make any difference, but gives
110 more gentle handling of IOMMU overflow. */
111 if (iommu_sac_force && (mask >= DMA_40BIT_MASK)) {
112 dev_info(dev, "Force SAC with mask %lx\n", mask);
113 return 0;
114 }
115
116 return 1;
117}
118EXPORT_SYMBOL(iommu_dma_supported);
119
120#endif