import of upstream 2.4.34.4 from kernel.org
[linux-2.4.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 extern dma_addr_t bad_dma_address;
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()          0
21
22 extern unsigned long pci_mem_start;
23 #define PCIBIOS_MIN_IO          0x1000
24 #define PCIBIOS_MIN_MEM         (pci_mem_start)
25
26 void pcibios_config_init(void);
27 struct pci_bus * pcibios_scan_root(int bus);
28 extern int (*pci_config_read)(int seg, int bus, int dev, int fn, int reg, int len, u32 *value);
29 extern int (*pci_config_write)(int seg, int bus, int dev, int fn, int reg, int len, u32 value);
30
31 void pcibios_set_master(struct pci_dev *dev);
32 void pcibios_penalize_isa_irq(int irq);
33 struct irq_routing_table *pcibios_get_irq_routing_table(void);
34 int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);
35
36 #include <linux/types.h>
37 #include <linux/slab.h>
38 #include <asm/scatterlist.h>
39 #include <linux/string.h>
40 #include <asm/io.h>
41 #include <asm/page.h>
42 #include <asm/mmzone.h>
43
44 struct pci_dev;
45 extern int force_mmu;
46
47 /* Allocate and map kernel buffer using consistent mode DMA for a device.
48  * hwdev should be valid struct pci_dev pointer for PCI devices,
49  * NULL for PCI-like buses (ISA, EISA).
50  * Returns non-NULL cpu-view pointer to the buffer if successful and
51  * sets *dma_addrp to the pci side dma address as well, else *dma_addrp
52  * is undefined.
53  */
54 extern void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
55                                   dma_addr_t *dma_handle);
56
57 /* Free and unmap a consistent DMA buffer.
58  * cpu_addr is what was returned from pci_alloc_consistent,
59  * size must be the same as what as passed into pci_alloc_consistent,
60  * and likewise dma_addr must be the same as what *dma_addrp was set to.
61  *
62  * References to the memory and mappings associated with cpu_addr/dma_addr
63  * past this call are illegal.
64  */
65 extern void pci_free_consistent(struct pci_dev *hwdev, size_t size,
66                                 void *vaddr, dma_addr_t dma_handle);
67
68 extern int swiotlb; 
69
70 #ifdef CONFIG_SWIOTLB
71 extern dma_addr_t swiotlb_map_single (struct pci_dev *hwdev, void *ptr, size_t size, 
72                                      int dir);
73 extern void swiotlb_unmap_single (struct pci_dev *hwdev, dma_addr_t dev_addr,
74                                  size_t size, int dir);
75 extern void swiotlb_sync_single (struct pci_dev *hwdev, dma_addr_t dev_addr, 
76                                 size_t size, int dir);
77 extern void swiotlb_sync_sg (struct pci_dev *hwdev, struct scatterlist *sg, int nelems, 
78                             int dir);
79 #endif
80
81 #ifdef CONFIG_GART_IOMMU
82
83 /* Map a single buffer of the indicated size for DMA in streaming mode.
84  * The 32-bit bus address to use is returned.
85  *
86  * Once the device is given the dma address, the device owns this memory
87  * until either pci_unmap_single or pci_dma_sync_single is performed.
88  */
89 extern dma_addr_t pci_map_single(struct pci_dev *hwdev, void *ptr,
90                                  size_t size, int direction);
91
92
93 void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t addr,
94                                    size_t size, int direction);
95
96 /*
97  * pci_{map,unmap}_single_page maps a kernel page to a dma_addr_t. identical
98  * to pci_map_single, but takes a struct page instead of a virtual address
99  */
100
101 #define pci_map_page(dev,page,offset,size,dir) \
102         pci_map_single((dev), page_address(page)+(offset), (size), (dir)) 
103
104 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)       \
105         dma_addr_t ADDR_NAME;
106 #define DECLARE_PCI_UNMAP_LEN(LEN_NAME)         \
107         __u32 LEN_NAME;
108 #define pci_unmap_addr(PTR, ADDR_NAME)                  \
109         ((PTR)->ADDR_NAME)
110 #define pci_unmap_addr_set(PTR, ADDR_NAME, VAL)         \
111         (((PTR)->ADDR_NAME) = (VAL))
112 #define pci_unmap_len(PTR, LEN_NAME)                    \
113         ((PTR)->LEN_NAME)
114 #define pci_unmap_len_set(PTR, LEN_NAME, VAL)           \
115         (((PTR)->LEN_NAME) = (VAL))
116
117 static inline void pci_dma_sync_single(struct pci_dev *hwdev, 
118                                        dma_addr_t dma_handle,
119                                        size_t size, int direction)
120 {
121 #ifdef CONFIG_SWIOTLB
122        if (swiotlb)
123                return swiotlb_sync_single(hwdev,dma_handle,size,direction);
124 #endif
125         BUG_ON(direction == PCI_DMA_NONE); 
126
127
128 static inline void pci_dma_sync_sg(struct pci_dev *hwdev, 
129                                    struct scatterlist *sg,
130                                    int nelems, int direction)
131
132         BUG_ON(direction == PCI_DMA_NONE); 
133 #ifdef CONFIG_SWIOTLB
134        if (swiotlb)
135                return swiotlb_sync_sg(hwdev,sg,nelems,direction);
136 #endif
137
138
139 /* The PCI address space does equal the physical memory
140  * address space.  The networking and block device layers use
141  * this boolean for bounce buffer decisions.
142  */
143 #define PCI_DMA_BUS_IS_PHYS     (0)
144
145
146 #else
147 static inline dma_addr_t pci_map_single(struct pci_dev *hwdev, void *ptr,
148                                         size_t size, int direction)
149 {
150         dma_addr_t addr; 
151
152         if (direction == PCI_DMA_NONE)
153                 out_of_line_bug();      
154         addr = virt_to_bus(ptr); 
155
156         /* 
157          * This is gross, but what should I do.
158          * Unfortunately drivers do not test the return value of this.
159          */
160         if ((addr+size) & ~hwdev->dma_mask) 
161                 out_of_line_bug(); 
162         return addr;
163 }
164
165 static inline void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr,
166                                     size_t size, int direction)
167 {
168         if (direction == PCI_DMA_NONE)
169                 out_of_line_bug();
170         /* Nothing to do */
171 }
172
173 static inline dma_addr_t pci_map_page(struct pci_dev *hwdev, struct page *page,
174                                       unsigned long offset, size_t size, int direction)
175 {
176         dma_addr_t addr;
177         if (direction == PCI_DMA_NONE)
178                 out_of_line_bug();      
179         addr = page_to_pfn(page) * PAGE_SIZE + offset;
180         if ((addr+size) & ~hwdev->dma_mask) 
181                 out_of_line_bug();
182         return addr;
183 }
184
185 /* pci_unmap_{page,single} is a nop so... */
186 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)
187 #define DECLARE_PCI_UNMAP_LEN(LEN_NAME)
188 #define pci_unmap_addr(PTR, ADDR_NAME)          (0)
189 #define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) do { } while (0)
190 #define pci_unmap_len(PTR, LEN_NAME)            (0)
191 #define pci_unmap_len_set(PTR, LEN_NAME, VAL)   do { } while (0)
192         
193 /* Make physical memory consistent for a single
194  * streaming mode DMA translation after a transfer.
195  *
196  * If you perform a pci_map_single() but wish to interrogate the
197  * buffer using the cpu, yet do not wish to teardown the PCI dma
198  * mapping, you must call this function before doing so.  At the
199  * next point you give the PCI dma address back to the card, the
200  * device again owns the buffer.
201  */
202 static inline void pci_dma_sync_single(struct pci_dev *hwdev,
203                                        dma_addr_t dma_handle,
204                                        size_t size, int direction)
205 {
206         if (direction == PCI_DMA_NONE)
207                 out_of_line_bug();
208         flush_write_buffers();
209 }
210
211 /* Make physical memory consistent for a set of streaming
212  * mode DMA translations after a transfer.
213  *
214  * The same as pci_dma_sync_single but for a scatter-gather list,
215  * same rules and usage.
216  */
217 static inline void pci_dma_sync_sg(struct pci_dev *hwdev,
218                                    struct scatterlist *sg,
219                                    int nelems, int direction)
220 {
221         if (direction == PCI_DMA_NONE)
222                 out_of_line_bug();
223         flush_write_buffers();
224 }
225
226 #define PCI_DMA_BUS_IS_PHYS     1
227
228 #endif
229
230 extern int pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg,
231                       int nents, int direction);
232 extern void pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg,
233                          int nents, int direction);
234
235 #define pci_unmap_page pci_unmap_single
236
237 /* Return whether the given PCI device DMA address mask can
238  * be supported properly.  For example, if your device can
239  * only drive the low 24-bits during PCI bus mastering, then
240  * you would pass 0x00ffffff as the mask to this function.
241  */
242 static inline int pci_dma_supported(struct pci_dev *hwdev, u64 mask)
243 {
244         /*
245          * we fall back to GFP_DMA when the mask isn't all 1s,
246          * so we can't guarantee allocations that must be
247          * within a tighter range than GFP_DMA..
248          */
249         if(mask < 0x00ffffff)
250                 return 0;
251
252         return 1;
253 }
254
255 /* This is always fine. */
256 #define pci_dac_dma_supported(pci_dev, mask)    (1)
257
258 static __inline__ dma64_addr_t
259 pci_dac_page_to_dma(struct pci_dev *pdev, struct page *page, unsigned long offset, int direction)
260 {
261         return ((dma64_addr_t) page_to_bus(page) +
262                 (dma64_addr_t) offset);
263 }
264
265 static __inline__ struct page *
266 pci_dac_dma_to_page(struct pci_dev *pdev, dma64_addr_t dma_addr)
267 {
268         return pfn_to_page(phys_to_pfn(dma_addr)); 
269 }
270
271 static __inline__ unsigned long
272 pci_dac_dma_to_offset(struct pci_dev *pdev, dma64_addr_t dma_addr)
273 {
274         return (dma_addr & ~PAGE_MASK);
275 }
276
277 static __inline__ void
278 pci_dac_dma_sync_single(struct pci_dev *pdev, dma64_addr_t dma_addr, size_t len, int direction)
279 {
280         flush_write_buffers();
281 }
282
283 /* These macros should be used after a pci_map_sg call has been done
284  * to get bus addresses of each of the SG entries and their lengths.
285  * You should only work with the number of sg entries pci_map_sg
286  * returns.
287  */
288 #define sg_dma_address(sg)      ((sg)->dma_address)
289 #define sg_dma_len(sg)          ((sg)->length)
290
291 /* Return the index of the PCI controller for device. */
292 static inline int pci_controller_num(struct pci_dev *dev)
293 {
294         return 0;
295 }
296
297 #define HAVE_PCI_MMAP
298 extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
299                                enum pci_mmap_state mmap_state, int write_combine);
300
301 #endif /* __KERNEL__ */
302
303 #endif /* __x8664_PCI_H */