aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-x86_64
diff options
context:
space:
mode:
authorMuli Ben-Yehuda <mulix@mulix.org>2006-01-11 16:44:42 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-01-11 22:04:55 -0500
commit17a941d854a3f7b0bb916fdeee4c9ffdcc19d8d3 (patch)
treeb6b3b55318336adf769bf57141a01a9defbbb202 /include/asm-x86_64
parent8a6fdd3e912e0ce6f723431d66baf704bf8a1d26 (diff)
[PATCH] x86_64: Use function pointers to call DMA mapping functions
AK: I hacked Muli's original patch a lot and there were a lot of changes - all bugs are probably to blame on me now. There were also some changes in the fall back behaviour for swiotlb - in particular it doesn't try to use GFP_DMA now anymore. Also all DMA mapping operations use the same core dma_alloc_coherent code with proper fallbacks now. And various other changes and cleanups. Known problems: iommu=force swiotlb=force together breaks needs more testing. This patch cleans up x86_64's DMA mapping dispatching code. Right now we have three possible IOMMU types: AGP GART, swiotlb and nommu, and in the future we will also have Xen's x86_64 swiotlb and other HW IOMMUs for x86_64. In order to support all of them cleanly, this patch: - introduces a struct dma_mapping_ops with function pointers for each of the DMA mapping operations of gart (AMD HW IOMMU), swiotlb (software IOMMU) and nommu (no IOMMU). - gets rid of: if (swiotlb) return swiotlb_xxx(); - PCI_DMA_BUS_IS_PHYS is now checked against the dma_ops being set This makes swiotlb faster by avoiding double copying in some cases. Signed-Off-By: Muli Ben-Yehuda <mulix@mulix.org> Signed-Off-By: Jon D. Mason <jdmason@us.ibm.com> Signed-off-by: Andi Kleen <ak@suse.de> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'include/asm-x86_64')
-rw-r--r--include/asm-x86_64/dma-mapping.h221
-rw-r--r--include/asm-x86_64/gart-mapping.h16
-rw-r--r--include/asm-x86_64/pci.h11
-rw-r--r--include/asm-x86_64/proto.h11
-rw-r--r--include/asm-x86_64/swiotlb.h16
5 files changed, 163 insertions, 112 deletions
diff --git a/include/asm-x86_64/dma-mapping.h b/include/asm-x86_64/dma-mapping.h
index 36d16dfbac88..49a81a66516e 100644
--- a/include/asm-x86_64/dma-mapping.h
+++ b/include/asm-x86_64/dma-mapping.h
@@ -12,155 +12,176 @@
12#include <asm/io.h> 12#include <asm/io.h>
13#include <asm/swiotlb.h> 13#include <asm/swiotlb.h>
14 14
15extern dma_addr_t bad_dma_address; 15struct dma_mapping_ops {
16#define dma_mapping_error(x) \ 16 int (*mapping_error)(dma_addr_t dma_addr);
17 (swiotlb ? swiotlb_dma_mapping_error(x) : ((x) == bad_dma_address)) 17 void* (*alloc_coherent)(struct device *dev, size_t size,
18 18 dma_addr_t *dma_handle, gfp_t gfp);
19void *dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, 19 void (*free_coherent)(struct device *dev, size_t size,
20 gfp_t gfp); 20 void *vaddr, dma_addr_t dma_handle);
21void dma_free_coherent(struct device *dev, size_t size, void *vaddr, 21 dma_addr_t (*map_single)(struct device *hwdev, void *ptr,
22 dma_addr_t dma_handle); 22 size_t size, int direction);
23 /* like map_single, but doesn't check the device mask */
24 dma_addr_t (*map_simple)(struct device *hwdev, char *ptr,
25 size_t size, int direction);
26 void (*unmap_single)(struct device *dev, dma_addr_t addr,
27 size_t size, int direction);
28 void (*sync_single_for_cpu)(struct device *hwdev,
29 dma_addr_t dma_handle, size_t size,
30 int direction);
31 void (*sync_single_for_device)(struct device *hwdev,
32 dma_addr_t dma_handle, size_t size,
33 int direction);
34 void (*sync_single_range_for_cpu)(struct device *hwdev,
35 dma_addr_t dma_handle, unsigned long offset,
36 size_t size, int direction);
37 void (*sync_single_range_for_device)(struct device *hwdev,
38 dma_addr_t dma_handle, unsigned long offset,
39 size_t size, int direction);
40 void (*sync_sg_for_cpu)(struct device *hwdev,
41 struct scatterlist *sg, int nelems,
42 int direction);
43 void (*sync_sg_for_device)(struct device *hwdev,
44 struct scatterlist *sg, int nelems,
45 int direction);
46 int (*map_sg)(struct device *hwdev, struct scatterlist *sg,
47 int nents, int direction);
48 void (*unmap_sg)(struct device *hwdev,
49 struct scatterlist *sg, int nents,
50 int direction);
51 int (*dma_supported)(struct device *hwdev, u64 mask);
52 int is_phys;
53};
23 54
24#ifdef CONFIG_GART_IOMMU 55extern dma_addr_t bad_dma_address;
56extern struct dma_mapping_ops* dma_ops;
57extern int iommu_merge;
25 58
26extern dma_addr_t dma_map_single(struct device *hwdev, void *ptr, size_t size, 59static inline int dma_mapping_error(dma_addr_t dma_addr)
27 int direction); 60{
28extern void dma_unmap_single(struct device *dev, dma_addr_t addr,size_t size, 61 if (dma_ops->mapping_error)
29 int direction); 62 return dma_ops->mapping_error(dma_addr);
30 63
31#else 64 return (dma_addr == bad_dma_address);
65}
32 66
33/* No IOMMU */ 67extern void *dma_alloc_coherent(struct device *dev, size_t size,
68 dma_addr_t *dma_handle, gfp_t gfp);
69extern void dma_free_coherent(struct device *dev, size_t size, void *vaddr,
70 dma_addr_t dma_handle);
34 71
35static inline dma_addr_t dma_map_single(struct device *hwdev, void *ptr, 72static inline dma_addr_t
36 size_t size, int direction) 73dma_map_single(struct device *hwdev, void *ptr, size_t size,
74 int direction)
37{ 75{
38 dma_addr_t addr; 76 return dma_ops->map_single(hwdev, ptr, size, direction);
39
40 if (direction == DMA_NONE)
41 out_of_line_bug();
42 addr = virt_to_bus(ptr);
43
44 if ((addr+size) & ~*hwdev->dma_mask)
45 out_of_line_bug();
46 return addr;
47} 77}
48 78
49static inline void dma_unmap_single(struct device *hwdev, dma_addr_t dma_addr, 79static inline void
50 size_t size, int direction) 80dma_unmap_single(struct device *dev, dma_addr_t addr,size_t size,
81 int direction)
51{ 82{
52 if (direction == DMA_NONE) 83 dma_ops->unmap_single(dev, addr, size, direction);
53 out_of_line_bug();
54 /* Nothing to do */
55} 84}
56 85
57#endif
58
59#define dma_map_page(dev,page,offset,size,dir) \ 86#define dma_map_page(dev,page,offset,size,dir) \
60 dma_map_single((dev), page_address(page)+(offset), (size), (dir)) 87 dma_map_single((dev), page_address(page)+(offset), (size), (dir))
61 88
62static inline void dma_sync_single_for_cpu(struct device *hwdev, 89#define dma_unmap_page dma_unmap_single
63 dma_addr_t dma_handle,
64 size_t size, int direction)
65{
66 if (direction == DMA_NONE)
67 out_of_line_bug();
68
69 if (swiotlb)
70 return swiotlb_sync_single_for_cpu(hwdev,dma_handle,size,direction);
71 90
91static inline void
92dma_sync_single_for_cpu(struct device *hwdev, dma_addr_t dma_handle,
93 size_t size, int direction)
94{
95 if (dma_ops->sync_single_for_cpu)
96 dma_ops->sync_single_for_cpu(hwdev, dma_handle, size,
97 direction);
72 flush_write_buffers(); 98 flush_write_buffers();
73} 99}
74 100
75static inline void dma_sync_single_for_device(struct device *hwdev, 101static inline void
76 dma_addr_t dma_handle, 102dma_sync_single_for_device(struct device *hwdev, dma_addr_t dma_handle,
77 size_t size, int direction) 103 size_t size, int direction)
78{ 104{
79 if (direction == DMA_NONE) 105 if (dma_ops->sync_single_for_device)
80 out_of_line_bug(); 106 dma_ops->sync_single_for_device(hwdev, dma_handle, size,
81 107 direction);
82 if (swiotlb)
83 return swiotlb_sync_single_for_device(hwdev,dma_handle,size,direction);
84
85 flush_write_buffers(); 108 flush_write_buffers();
86} 109}
87 110
88static inline void dma_sync_single_range_for_cpu(struct device *hwdev, 111static inline void
89 dma_addr_t dma_handle, 112dma_sync_single_range_for_cpu(struct device *hwdev, dma_addr_t dma_handle,
90 unsigned long offset, 113 unsigned long offset, size_t size, int direction)
91 size_t size, int direction)
92{ 114{
93 if (direction == DMA_NONE) 115 if (dma_ops->sync_single_range_for_cpu) {
94 out_of_line_bug(); 116 dma_ops->sync_single_range_for_cpu(hwdev, dma_handle, offset, size, direction);
95 117 }
96 if (swiotlb)
97 return swiotlb_sync_single_range_for_cpu(hwdev,dma_handle,offset,size,direction);
98 118
99 flush_write_buffers(); 119 flush_write_buffers();
100} 120}
101 121
102static inline void dma_sync_single_range_for_device(struct device *hwdev, 122static inline void
103 dma_addr_t dma_handle, 123dma_sync_single_range_for_device(struct device *hwdev, dma_addr_t dma_handle,
104 unsigned long offset, 124 unsigned long offset, size_t size, int direction)
105 size_t size, int direction)
106{ 125{
107 if (direction == DMA_NONE) 126 if (dma_ops->sync_single_range_for_device)
108 out_of_line_bug(); 127 dma_ops->sync_single_range_for_device(hwdev, dma_handle,
109 128 offset, size, direction);
110 if (swiotlb)
111 return swiotlb_sync_single_range_for_device(hwdev,dma_handle,offset,size,direction);
112 129
113 flush_write_buffers(); 130 flush_write_buffers();
114} 131}
115 132
116static inline void dma_sync_sg_for_cpu(struct device *hwdev, 133static inline void
117 struct scatterlist *sg, 134dma_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg,
118 int nelems, int direction) 135 int nelems, int direction)
119{ 136{
120 if (direction == DMA_NONE) 137 if (dma_ops->sync_sg_for_cpu)
121 out_of_line_bug(); 138 dma_ops->sync_sg_for_cpu(hwdev, sg, nelems, direction);
122
123 if (swiotlb)
124 return swiotlb_sync_sg_for_cpu(hwdev,sg,nelems,direction);
125
126 flush_write_buffers(); 139 flush_write_buffers();
127} 140}
128 141
129static inline void dma_sync_sg_for_device(struct device *hwdev, 142static inline void
130 struct scatterlist *sg, 143dma_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
131 int nelems, int direction) 144 int nelems, int direction)
132{ 145{
133 if (direction == DMA_NONE) 146 if (dma_ops->sync_sg_for_device) {
134 out_of_line_bug(); 147 dma_ops->sync_sg_for_device(hwdev, sg, nelems, direction);
135 148 }
136 if (swiotlb)
137 return swiotlb_sync_sg_for_device(hwdev,sg,nelems,direction);
138 149
139 flush_write_buffers(); 150 flush_write_buffers();
140} 151}
141 152
142extern int dma_map_sg(struct device *hwdev, struct scatterlist *sg, 153static inline int
143 int nents, int direction); 154dma_map_sg(struct device *hwdev, struct scatterlist *sg, int nents, int direction)
144extern void dma_unmap_sg(struct device *hwdev, struct scatterlist *sg, 155{
145 int nents, int direction); 156 return dma_ops->map_sg(hwdev, sg, nents, direction);
157}
146 158
147#define dma_unmap_page dma_unmap_single 159static inline void
160dma_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents,
161 int direction)
162{
163 dma_ops->unmap_sg(hwdev, sg, nents, direction);
164}
148 165
149extern int dma_supported(struct device *hwdev, u64 mask); 166extern int dma_supported(struct device *hwdev, u64 mask);
150extern int dma_get_cache_alignment(void);
151#define dma_is_consistent(h) 1
152 167
153static inline int dma_set_mask(struct device *dev, u64 mask) 168/* same for gart, swiotlb, and nommu */
169static inline int dma_get_cache_alignment(void)
154{ 170{
155 if (!dev->dma_mask || !dma_supported(dev, mask)) 171 return boot_cpu_data.x86_clflush_size;
156 return -EIO;
157 *dev->dma_mask = mask;
158 return 0;
159} 172}
160 173
161static inline void dma_cache_sync(void *vaddr, size_t size, enum dma_data_direction dir) 174#define dma_is_consistent(h) 1
175
176extern int dma_set_mask(struct device *dev, u64 mask);
177
178static inline void
179dma_cache_sync(void *vaddr, size_t size, enum dma_data_direction dir)
162{ 180{
163 flush_write_buffers(); 181 flush_write_buffers();
164} 182}
165 183
166#endif 184extern struct device fallback_dev;
185extern int panic_on_overflow;
186
187#endif /* _X8664_DMA_MAPPING_H */
diff --git a/include/asm-x86_64/gart-mapping.h b/include/asm-x86_64/gart-mapping.h
new file mode 100644
index 000000000000..ada497b0b55b
--- /dev/null
+++ b/include/asm-x86_64/gart-mapping.h
@@ -0,0 +1,16 @@
1#ifndef _X8664_GART_MAPPING_H
2#define _X8664_GART_MAPPING_H 1
3
4#include <linux/types.h>
5#include <asm/types.h>
6
7struct device;
8
9extern void*
10gart_alloc_coherent(struct device *dev, size_t size,
11 dma_addr_t *dma_handle, gfp_t gfp);
12
13extern int
14gart_dma_supported(struct device *hwdev, u64 mask);
15
16#endif /* _X8664_GART_MAPPING_H */
diff --git a/include/asm-x86_64/pci.h b/include/asm-x86_64/pci.h
index eeb3088a1c9e..fd03e15d7ea6 100644
--- a/include/asm-x86_64/pci.h
+++ b/include/asm-x86_64/pci.h
@@ -42,18 +42,20 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);
42#include <asm/scatterlist.h> 42#include <asm/scatterlist.h>
43#include <linux/string.h> 43#include <linux/string.h>
44#include <asm/page.h> 44#include <asm/page.h>
45#include <linux/dma-mapping.h> /* for have_iommu */
45 46
46extern int iommu_setup(char *opt); 47extern int iommu_setup(char *opt);
47 48
48#ifdef CONFIG_GART_IOMMU
49/* The PCI address space does equal the physical memory 49/* The PCI address space does equal the physical memory
50 * address space. The networking and block device layers use 50 * address space. The networking and block device layers use
51 * this boolean for bounce buffer decisions 51 * this boolean for bounce buffer decisions
52 * 52 *
53 * On AMD64 it mostly equals, but we set it to zero to tell some subsystems 53 * On AMD64 it mostly equals, but we set it to zero if a hardware
54 * that an IOMMU is available. 54 * IOMMU (gart) of sotware IOMMU (swiotlb) is available.
55 */ 55 */
56#define PCI_DMA_BUS_IS_PHYS (no_iommu ? 1 : 0) 56#define PCI_DMA_BUS_IS_PHYS (dma_ops->is_phys)
57
58#ifdef CONFIG_GART_IOMMU
57 59
58/* 60/*
59 * x86-64 always supports DAC, but sometimes it is useful to force 61 * x86-64 always supports DAC, but sometimes it is useful to force
@@ -79,7 +81,6 @@ extern int iommu_sac_force;
79#else 81#else
80/* No IOMMU */ 82/* No IOMMU */
81 83
82#define PCI_DMA_BUS_IS_PHYS 1
83#define pci_dac_dma_supported(pci_dev, mask) 1 84#define pci_dac_dma_supported(pci_dev, mask) 1
84 85
85#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) 86#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)
diff --git a/include/asm-x86_64/proto.h b/include/asm-x86_64/proto.h
index 34501086afef..113e8a235b27 100644
--- a/include/asm-x86_64/proto.h
+++ b/include/asm-x86_64/proto.h
@@ -92,7 +92,9 @@ extern void check_efer(void);
92extern int unhandled_signal(struct task_struct *tsk, int sig); 92extern int unhandled_signal(struct task_struct *tsk, int sig);
93 93
94extern void select_idle_routine(const struct cpuinfo_x86 *c); 94extern void select_idle_routine(const struct cpuinfo_x86 *c);
95extern void swiotlb_init(void); 95
96extern void gart_parse_options(char *);
97extern void __init no_iommu_init(void);
96 98
97extern unsigned long table_start, table_end; 99extern unsigned long table_start, table_end;
98 100
@@ -106,12 +108,17 @@ extern int skip_ioapic_setup;
106extern int acpi_ht; 108extern int acpi_ht;
107extern int acpi_disabled; 109extern int acpi_disabled;
108 110
111#ifdef CONFIG_GART_IOMMU
109extern int fallback_aper_order; 112extern int fallback_aper_order;
110extern int fallback_aper_force; 113extern int fallback_aper_force;
111extern int iommu_aperture; 114extern int iommu_aperture;
112extern int iommu_aperture_disabled;
113extern int iommu_aperture_allowed; 115extern int iommu_aperture_allowed;
116extern int iommu_aperture_disabled;
114extern int fix_aperture; 117extern int fix_aperture;
118#else
119#define iommu_aperture 0
120#define iommu_aperture_allowed 0
121#endif
115extern int force_iommu; 122extern int force_iommu;
116 123
117extern int reboot_force; 124extern int reboot_force;
diff --git a/include/asm-x86_64/swiotlb.h b/include/asm-x86_64/swiotlb.h
index dddf1b218681..60757efd1353 100644
--- a/include/asm-x86_64/swiotlb.h
+++ b/include/asm-x86_64/swiotlb.h
@@ -3,10 +3,14 @@
3 3
4#include <linux/config.h> 4#include <linux/config.h>
5 5
6#include <asm/dma-mapping.h>
7
6/* SWIOTLB interface */ 8/* SWIOTLB interface */
7 9
8extern dma_addr_t swiotlb_map_single(struct device *hwdev, void *ptr, size_t size, 10extern dma_addr_t swiotlb_map_single(struct device *hwdev, void *ptr,
9 int dir); 11 size_t size, int dir);
12extern void *swiotlb_alloc_coherent(struct device *hwdev, size_t size,
13 dma_addr_t *dma_handle, gfp_t flags);
10extern void swiotlb_unmap_single(struct device *hwdev, dma_addr_t dev_addr, 14extern void swiotlb_unmap_single(struct device *hwdev, dma_addr_t dev_addr,
11 size_t size, int dir); 15 size_t size, int dir);
12extern void swiotlb_sync_single_for_cpu(struct device *hwdev, 16extern void swiotlb_sync_single_for_cpu(struct device *hwdev,
@@ -34,10 +38,10 @@ extern int swiotlb_map_sg(struct device *hwdev, struct scatterlist *sg,
34extern void swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sg, 38extern void swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sg,
35 int nents, int direction); 39 int nents, int direction);
36extern int swiotlb_dma_mapping_error(dma_addr_t dma_addr); 40extern int swiotlb_dma_mapping_error(dma_addr_t dma_addr);
37extern void *swiotlb_alloc_coherent (struct device *hwdev, size_t size,
38 dma_addr_t *dma_handle, gfp_t flags);
39extern void swiotlb_free_coherent (struct device *hwdev, size_t size, 41extern void swiotlb_free_coherent (struct device *hwdev, size_t size,
40 void *vaddr, dma_addr_t dma_handle); 42 void *vaddr, dma_addr_t dma_handle);
43extern int swiotlb_dma_supported(struct device *hwdev, u64 mask);
44extern void swiotlb_init(void);
41 45
42#ifdef CONFIG_SWIOTLB 46#ifdef CONFIG_SWIOTLB
43extern int swiotlb; 47extern int swiotlb;
@@ -45,4 +49,6 @@ extern int swiotlb;
45#define swiotlb 0 49#define swiotlb 0
46#endif 50#endif
47 51
48#endif 52extern void pci_swiotlb_init(void);
53
54#endif /* _ASM_SWTIOLB_H */