ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / asm-x86_64 / pci.h
1 #ifndef __x8664_PCI_H
2 #define __x8664_PCI_H
3
4 #include <linux/config.h>
5 #include <asm/io.h>
6
7 #ifdef __KERNEL__
8
9 #include <linux/mm.h> /* for struct page */
10
11 /* Can be used to override the logic in pci_scan_bus for skipping
12    already-configured bus numbers - to be used for buggy BIOSes
13    or architectures with incomplete PCI setup by the loader */
14
15 #ifdef CONFIG_PCI
16 extern unsigned int pcibios_assign_all_busses(void);
17 #else
18 #define pcibios_assign_all_busses()     0
19 #endif
20 #define pcibios_scan_all_fns(a, b)      0
21
22 extern int no_iommu, force_iommu;
23
24 extern unsigned long pci_mem_start;
25 #define PCIBIOS_MIN_IO          0x1000
26 #define PCIBIOS_MIN_MEM         (pci_mem_start)
27
28 #define PCIBIOS_MIN_CARDBUS_IO  0x4000
29
30 void pcibios_config_init(void);
31 struct pci_bus * pcibios_scan_root(int bus);
32 extern int (*pci_config_read)(int seg, int bus, int dev, int fn, int reg, int len, u32 *value);
33 extern int (*pci_config_write)(int seg, int bus, int dev, int fn, int reg, int len, u32 value);
34
35 void pcibios_set_master(struct pci_dev *dev);
36 void pcibios_penalize_isa_irq(int irq);
37 struct irq_routing_table *pcibios_get_irq_routing_table(void);
38 int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);
39
40 #include <linux/types.h>
41 #include <linux/slab.h>
42 #include <asm/scatterlist.h>
43 #include <linux/string.h>
44 #include <asm/io.h>
45 #include <asm/page.h>
46
47 struct pci_dev;
48
49 extern int iommu_setup(char *opt);
50
51 extern dma_addr_t bad_dma_address;
52 #define pci_dma_mapping_error(x) ((x) == bad_dma_address)
53
54 /* Allocate and map kernel buffer using consistent mode DMA for a device.
55  * hwdev should be valid struct pci_dev pointer for PCI devices,
56  * NULL for PCI-like buses (ISA, EISA).
57  * Returns non-NULL cpu-view pointer to the buffer if successful and
58  * sets *dma_addrp to the pci side dma address as well, else *dma_addrp
59  * is undefined.
60  */
61 extern void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
62                                   dma_addr_t *dma_handle);
63
64 /* Free and unmap a consistent DMA buffer.
65  * cpu_addr is what was returned from pci_alloc_consistent,
66  * size must be the same as what as passed into pci_alloc_consistent,
67  * and likewise dma_addr must be the same as what *dma_addrp was set to.
68  *
69  * References to the memory and mappings associated with cpu_addr/dma_addr
70  * past this call are illegal.
71  */
72 extern void pci_free_consistent(struct pci_dev *hwdev, size_t size,
73                                 void *vaddr, dma_addr_t dma_handle);
74
75 #ifdef CONFIG_SWIOTLB
76 extern int swiotlb; 
77 extern dma_addr_t swiotlb_map_single (struct device *hwdev, void *ptr, size_t size, 
78                                       int dir);
79 extern void swiotlb_unmap_single (struct device *hwdev, dma_addr_t dev_addr,
80                                   size_t size, int dir);
81 extern void swiotlb_sync_single_for_cpu (struct device *hwdev,
82                                          dma_addr_t dev_addr,
83                                          size_t size, int dir);
84 extern void swiotlb_sync_single_for_device (struct device *hwdev,
85                                             dma_addr_t dev_addr,
86                                             size_t size, int dir);
87 extern void swiotlb_sync_sg_for_cpu (struct device *hwdev,
88                                      struct scatterlist *sg, int nelems,
89                                      int dir);
90 extern void swiotlb_sync_sg_for_device (struct device *hwdev,
91                                         struct scatterlist *sg, int nelems,
92                                         int dir);
93 extern int swiotlb_map_sg(struct device *hwdev, struct scatterlist *sg,
94                       int nents, int direction);
95 extern void swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sg,
96                          int nents, int direction);
97
98 #endif
99
100 #ifdef CONFIG_GART_IOMMU
101
102 /* Map a single buffer of the indicated size for DMA in streaming mode.
103  * The 32-bit bus address to use is returned.
104  *
105  * Once the device is given the dma address, the device owns this memory
106  * until either pci_unmap_single or pci_dma_sync_single_for_cpu is performed.
107  */
108 extern dma_addr_t pci_map_single(struct pci_dev *hwdev, void *ptr, size_t size, 
109                                  int direction);
110
111
112 void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t addr,
113                                    size_t size, int direction);
114
115 /*
116  * pci_{map,unmap}_single_page maps a kernel page to a dma_addr_t. identical
117  * to pci_map_single, but takes a struct page instead of a virtual address
118  */
119
120 #define pci_map_page(dev,page,offset,size,dir) \
121         pci_map_single((dev), page_address(page)+(offset), (size), (dir)) 
122
123 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)       \
124         dma_addr_t ADDR_NAME;
125 #define DECLARE_PCI_UNMAP_LEN(LEN_NAME)         \
126         __u32 LEN_NAME;
127 #define pci_unmap_addr(PTR, ADDR_NAME)                  \
128         ((PTR)->ADDR_NAME)
129 #define pci_unmap_addr_set(PTR, ADDR_NAME, VAL)         \
130         (((PTR)->ADDR_NAME) = (VAL))
131 #define pci_unmap_len(PTR, LEN_NAME)                    \
132         ((PTR)->LEN_NAME)
133 #define pci_unmap_len_set(PTR, LEN_NAME, VAL)           \
134         (((PTR)->LEN_NAME) = (VAL))
135
136 static inline void pci_dma_sync_single_for_cpu(struct pci_dev *hwdev,
137                                                dma_addr_t dma_handle,
138                                                size_t size, int direction)
139 {
140         BUG_ON(direction == PCI_DMA_NONE); 
141
142 #ifdef CONFIG_SWIOTLB
143         if (swiotlb)
144                 return swiotlb_sync_single_for_cpu(&hwdev->dev,dma_handle,size,direction);
145 #endif
146
147         flush_write_buffers();
148
149
150 static inline void pci_dma_sync_single_for_device(struct pci_dev *hwdev,
151                                                   dma_addr_t dma_handle,
152                                                   size_t size, int direction)
153 {
154         BUG_ON(direction == PCI_DMA_NONE);
155
156 #ifdef CONFIG_SWIOTLB
157         if (swiotlb)
158                 return swiotlb_sync_single_for_device(&hwdev->dev,dma_handle,size,direction);
159 #endif
160
161         flush_write_buffers();
162 }
163
164 static inline void pci_dma_sync_sg_for_cpu(struct pci_dev *hwdev,
165                                            struct scatterlist *sg,
166                                            int nelems, int direction)
167 {
168         BUG_ON(direction == PCI_DMA_NONE);
169
170 #ifdef CONFIG_SWIOTLB
171         if (swiotlb)
172                 return swiotlb_sync_sg_for_cpu(&hwdev->dev,sg,nelems,direction);
173 #endif
174         flush_write_buffers();
175 }
176
177 static inline void pci_dma_sync_sg_for_device(struct pci_dev *hwdev,
178                                               struct scatterlist *sg,
179                                               int nelems, int direction)
180
181         BUG_ON(direction == PCI_DMA_NONE); 
182
183 #ifdef CONFIG_SWIOTLB
184         if (swiotlb)
185                 return swiotlb_sync_sg_for_device(&hwdev->dev,sg,nelems,direction);
186 #endif
187         flush_write_buffers();
188
189
190 /* The PCI address space does equal the physical memory
191  * address space.  The networking and block device layers use
192  * this boolean for bounce buffer decisions
193  *
194  * On AMD64 it mostly equals, but we set it to zero to tell some subsystems
195  * that an IOMMU is available.
196  */
197 #define PCI_DMA_BUS_IS_PHYS     (no_iommu ? 1 : 0) 
198
199 /* We lie slightly when the IOMMU is forced to get the device to 
200    use SAC instead of DAC. */
201 #define pci_dac_dma_supported(pci_dev, mask)    (force_iommu ? 0 : 1)
202
203 #else
204 static inline dma_addr_t pci_map_single(struct pci_dev *hwdev, void *ptr,
205                                         size_t size, int direction)
206 {
207         dma_addr_t addr; 
208
209         if (direction == PCI_DMA_NONE)
210                 out_of_line_bug();      
211         addr = virt_to_bus(ptr); 
212
213         /* 
214          * This is gross, but what should I do.
215          * Unfortunately drivers do not test the return value of this.
216  */
217         if ((addr+size) & ~hwdev->dma_mask) 
218                 out_of_line_bug(); 
219         return addr;
220 }
221
222 static inline void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr,
223                                     size_t size, int direction)
224 {
225         if (direction == PCI_DMA_NONE)
226                 out_of_line_bug();
227         /* Nothing to do */
228 }
229
230 static inline dma_addr_t pci_map_page(struct pci_dev *hwdev, struct page *page,
231                                       unsigned long offset, size_t size, int direction)
232 {
233         dma_addr_t addr;
234         if (direction == PCI_DMA_NONE)
235                 out_of_line_bug();      
236         addr = page_to_pfn(page) * PAGE_SIZE + offset;
237         if ((addr+size) & ~hwdev->dma_mask) 
238                 out_of_line_bug();
239         return addr;
240 }
241
242 /* pci_unmap_{page,single} is a nop so... */
243 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)
244 #define DECLARE_PCI_UNMAP_LEN(LEN_NAME)
245 #define pci_unmap_addr(PTR, ADDR_NAME)          (0)
246 #define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) do { } while (0)
247 #define pci_unmap_len(PTR, LEN_NAME)            (0)
248 #define pci_unmap_len_set(PTR, LEN_NAME, VAL)   do { } while (0)
249
250 /* Make physical memory consistent for a single
251  * streaming mode DMA translation after a transfer.
252  *
253  * If you perform a pci_map_single() but wish to interrogate the
254  * buffer using the cpu, yet do not wish to teardown the PCI dma
255  * mapping, you must call this function before doing so.  At the
256  * next point you give the PCI dma address back to the card, you
257  * must first perform a pci_dma_sync_for_device, and then the
258  * device again owns the buffer.
259  */
260 static inline void pci_dma_sync_single_for_cpu(struct pci_dev *hwdev,
261                                                dma_addr_t dma_handle,
262                                                size_t size, int direction)
263 {
264         if (direction == PCI_DMA_NONE)
265                 out_of_line_bug();
266 }
267
268 static inline void pci_dma_sync_single_for_device(struct pci_dev *hwdev,
269                                                   dma_addr_t dma_handle,
270                                                   size_t size, int direction)
271 {
272         if (direction == PCI_DMA_NONE)
273                 out_of_line_bug();
274         flush_write_buffers();
275 }
276
277 /* Make physical memory consistent for a set of streaming
278  * mode DMA translations after a transfer.
279  *
280  * The same as pci_dma_sync_single_* but for a scatter-gather list,
281  * same rules and usage.
282  */
283 static inline void pci_dma_sync_sg_for_cpu(struct pci_dev *hwdev,
284                                            struct scatterlist *sg,
285                                            int nelems, int direction)
286 {
287         if (direction == PCI_DMA_NONE)
288                 out_of_line_bug();
289 }
290
291 static inline void pci_dma_sync_sg_for_device(struct pci_dev *hwdev,
292                                               struct scatterlist *sg,
293                                               int nelems, int direction)
294 {
295         if (direction == PCI_DMA_NONE)
296                 out_of_line_bug();
297         flush_write_buffers();
298 }
299
300 #define PCI_DMA_BUS_IS_PHYS     1
301
302 #define pci_dac_dma_supported(pci_dev, mask)    1
303 #endif
304
305 extern int pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg,
306                       int nents, int direction);
307 extern void pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg,
308                          int nents, int direction);
309
310 #define pci_unmap_page pci_unmap_single
311
312 /* Return whether the given PCI device DMA address mask can
313  * be supported properly.  For example, if your device can
314  * only drive the low 24-bits during PCI bus mastering, then
315  * you would pass 0x00ffffff as the mask to this function.
316  */
317 extern int pci_dma_supported(struct pci_dev *hwdev, u64 mask);
318
319 static inline dma64_addr_t
320 pci_dac_page_to_dma(struct pci_dev *pdev, struct page *page, unsigned long offset, int direction)
321 {
322         return ((dma64_addr_t) page_to_phys(page) +
323                 (dma64_addr_t) offset);
324 }
325
326 static inline struct page *
327 pci_dac_dma_to_page(struct pci_dev *pdev, dma64_addr_t dma_addr)
328 {
329         return virt_to_page(__va(dma_addr));    
330 }
331
332 static inline unsigned long
333 pci_dac_dma_to_offset(struct pci_dev *pdev, dma64_addr_t dma_addr)
334 {
335         return (dma_addr & ~PAGE_MASK);
336 }
337
338 static inline void
339 pci_dac_dma_sync_single_for_cpu(struct pci_dev *pdev, dma64_addr_t dma_addr, size_t len, int direction)
340 {
341 }
342
343 static inline void
344 pci_dac_dma_sync_single_for_device(struct pci_dev *pdev, dma64_addr_t dma_addr, size_t len, int direction)
345 {
346         flush_write_buffers();
347 }
348
349 #define HAVE_PCI_MMAP
350 extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
351                                enum pci_mmap_state mmap_state, int write_combine);
352
353 static inline void pcibios_add_platform_entries(struct pci_dev *dev)
354 {
355 }
356
357 #endif /* __KERNEL__ */
358
359 /* generic pci stuff */
360 #ifdef CONFIG_PCI
361 #include <asm-generic/pci.h>
362 #include <linux/dma-mapping.h>
363 #endif
364
365 #endif /* __x8664_PCI_H */