import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / include / asm-i386 / pci.h
1 #ifndef __i386_PCI_H
2 #define __i386_PCI_H
3
4 #include <linux/config.h>
5
6 #ifdef __KERNEL__
7
8 /* Can be used to override the logic in pci_scan_bus for skipping
9    already-configured bus numbers - to be used for buggy BIOSes
10    or architectures with incomplete PCI setup by the loader */
11
12 #ifdef CONFIG_PCI
13 extern unsigned int pcibios_assign_all_busses(void);
14 #else
15 #define pcibios_assign_all_busses()     0
16 #endif
17 #define pcibios_scan_all_fns()          0
18
19 extern unsigned long pci_mem_start;
20 #define PCIBIOS_MIN_IO          0x1000
21 #define PCIBIOS_MIN_MEM         (pci_mem_start)
22
23 void pcibios_config_init(void);
24 struct pci_bus * pcibios_scan_root(int bus);
25 extern int (*pci_config_read)(int seg, int bus, int dev, int fn, int reg, int len, u32 *value);
26 extern int (*pci_config_write)(int seg, int bus, int dev, int fn, int reg, int len, u32 value);
27
28 void pcibios_set_master(struct pci_dev *dev);
29 void pcibios_penalize_isa_irq(int irq);
30 struct irq_routing_table *pcibios_get_irq_routing_table(void);
31 int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);
32
33 /* Dynamic DMA mapping stuff.
34  * i386 has everything mapped statically.
35  */
36
37 #include <linux/types.h>
38 #include <linux/slab.h>
39 #include <asm/scatterlist.h>
40 #include <linux/string.h>
41 #include <asm/io.h>
42
43 struct pci_dev;
44
45 /* The PCI address space does equal the physical memory
46  * address space.  The networking and block device layers use
47  * this boolean for bounce buffer decisions.
48  */
49 #define PCI_DMA_BUS_IS_PHYS     (1)
50
51 /* Allocate and map kernel buffer using consistent mode DMA for a device.
52  * hwdev should be valid struct pci_dev pointer for PCI devices,
53  * NULL for PCI-like buses (ISA, EISA).
54  * Returns non-NULL cpu-view pointer to the buffer if successful and
55  * sets *dma_addrp to the pci side dma address as well, else *dma_addrp
56  * is undefined.
57  */
58 extern void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
59                                   dma_addr_t *dma_handle);
60
61 /* Free and unmap a consistent DMA buffer.
62  * cpu_addr is what was returned from pci_alloc_consistent,
63  * size must be the same as what as passed into pci_alloc_consistent,
64  * and likewise dma_addr must be the same as what *dma_addrp was set to.
65  *
66  * References to the memory and mappings associated with cpu_addr/dma_addr
67  * past this call are illegal.
68  */
69 extern void pci_free_consistent(struct pci_dev *hwdev, size_t size,
70                                 void *vaddr, dma_addr_t dma_handle);
71
72 /* Map a single buffer of the indicated size for DMA in streaming mode.
73  * The 32-bit bus address to use is returned.
74  *
75  * Once the device is given the dma address, the device owns this memory
76  * until either pci_unmap_single or pci_dma_sync_single is performed.
77  */
78 static inline dma_addr_t pci_map_single(struct pci_dev *hwdev, void *ptr,
79                                         size_t size, int direction)
80 {
81         if (direction == PCI_DMA_NONE)
82                 out_of_line_bug();
83         flush_write_buffers();
84         return virt_to_bus(ptr);
85 }
86
87 /* Unmap a single streaming mode DMA translation.  The dma_addr and size
88  * must match what was provided for in a previous pci_map_single call.  All
89  * other usages are undefined.
90  *
91  * After this call, reads by the cpu to the buffer are guarenteed to see
92  * whatever the device wrote there.
93  */
94 static inline void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr,
95                                     size_t size, int direction)
96 {
97         if (direction == PCI_DMA_NONE)
98                 out_of_line_bug();
99         /* Nothing to do */
100 }
101
102 /*
103  * pci_{map,unmap}_single_page maps a kernel page to a dma_addr_t. identical
104  * to pci_map_single, but takes a struct page instead of a virtual address
105  */
106 static inline dma_addr_t pci_map_page(struct pci_dev *hwdev, struct page *page,
107                                       unsigned long offset, size_t size, int direction)
108 {
109         if (direction == PCI_DMA_NONE)
110                 out_of_line_bug();
111
112         return ((dma_addr_t)(page - mem_map) *
113                 (dma_addr_t) PAGE_SIZE +
114                 (dma_addr_t) offset);
115 }
116
117 static inline void pci_unmap_page(struct pci_dev *hwdev, dma_addr_t dma_address,
118                                   size_t size, int direction)
119 {
120         if (direction == PCI_DMA_NONE)
121                 out_of_line_bug();
122         /* Nothing to do */
123 }
124
125 /* pci_unmap_{page,single} is a nop so... */
126 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)
127 #define DECLARE_PCI_UNMAP_LEN(LEN_NAME)
128 #define pci_unmap_addr(PTR, ADDR_NAME)          (0)
129 #define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) do { } while (0)
130 #define pci_unmap_len(PTR, LEN_NAME)            (0)
131 #define pci_unmap_len_set(PTR, LEN_NAME, VAL)   do { } while (0)
132
133 /* Map a set of buffers described by scatterlist in streaming
134  * mode for DMA.  This is the scather-gather version of the
135  * above pci_map_single interface.  Here the scatter gather list
136  * elements are each tagged with the appropriate dma address
137  * and length.  They are obtained via sg_dma_{address,length}(SG).
138  *
139  * NOTE: An implementation may be able to use a smaller number of
140  *       DMA address/length pairs than there are SG table elements.
141  *       (for example via virtual mapping capabilities)
142  *       The routine returns the number of addr/length pairs actually
143  *       used, at most nents.
144  *
145  * Device ownership issues as mentioned above for pci_map_single are
146  * the same here.
147  */
148 static inline int pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg,
149                              int nents, int direction)
150 {
151         int i;
152
153         if (direction == PCI_DMA_NONE)
154                 out_of_line_bug();
155  
156         /*
157          * temporary 2.4 hack
158          */
159         for (i = 0; i < nents; i++ ) {
160                 if (sg[i].address && sg[i].page)
161                         out_of_line_bug();
162                 else if (!sg[i].address && !sg[i].page)
163                         out_of_line_bug();
164  
165                 if (sg[i].address)
166                         sg[i].dma_address = virt_to_bus(sg[i].address);
167                 else
168                         sg[i].dma_address = page_to_bus(sg[i].page) + sg[i].offset;
169         }
170  
171         flush_write_buffers();
172         return nents;
173 }
174
175 /* Unmap a set of streaming mode DMA translations.
176  * Again, cpu read rules concerning calls here are the same as for
177  * pci_unmap_single() above.
178  */
179 static inline void pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg,
180                                 int nents, int direction)
181 {
182         if (direction == PCI_DMA_NONE)
183                 out_of_line_bug();
184         /* Nothing to do */
185 }
186
187 /* Make physical memory consistent for a single
188  * streaming mode DMA translation after a transfer.
189  *
190  * If you perform a pci_map_single() but wish to interrogate the
191  * buffer using the cpu, yet do not wish to teardown the PCI dma
192  * mapping, you must call this function before doing so.  At the
193  * next point you give the PCI dma address back to the card, the
194  * device again owns the buffer.
195  */
196 static inline void pci_dma_sync_single(struct pci_dev *hwdev,
197                                        dma_addr_t dma_handle,
198                                        size_t size, int direction)
199 {
200         if (direction == PCI_DMA_NONE)
201                 out_of_line_bug();
202         flush_write_buffers();
203 }
204
205 /* Make physical memory consistent for a set of streaming
206  * mode DMA translations after a transfer.
207  *
208  * The same as pci_dma_sync_single but for a scatter-gather list,
209  * same rules and usage.
210  */
211 static inline void pci_dma_sync_sg(struct pci_dev *hwdev,
212                                    struct scatterlist *sg,
213                                    int nelems, int direction)
214 {
215         if (direction == PCI_DMA_NONE)
216                 out_of_line_bug();
217         flush_write_buffers();
218 }
219
220 /* Return whether the given PCI device DMA address mask can
221  * be supported properly.  For example, if your device can
222  * only drive the low 24-bits during PCI bus mastering, then
223  * you would pass 0x00ffffff as the mask to this function.
224  */
225 static inline int pci_dma_supported(struct pci_dev *hwdev, u64 mask)
226 {
227         /*
228          * we fall back to GFP_DMA when the mask isn't all 1s,
229          * so we can't guarantee allocations that must be
230          * within a tighter range than GFP_DMA..
231          */
232         if(mask < 0x00ffffff)
233                 return 0;
234
235         return 1;
236 }
237
238 /* This is always fine. */
239 #define pci_dac_dma_supported(pci_dev, mask)    (1)
240
241 static __inline__ dma64_addr_t
242 pci_dac_page_to_dma(struct pci_dev *pdev, struct page *page, unsigned long offset, int direction)
243 {
244         return ((dma64_addr_t) page_to_bus(page) +
245                 (dma64_addr_t) offset);
246 }
247
248 static __inline__ struct page *
249 pci_dac_dma_to_page(struct pci_dev *pdev, dma64_addr_t dma_addr)
250 {
251         unsigned long poff = (dma_addr >> PAGE_SHIFT);
252
253         return mem_map + poff;
254 }
255
256 static __inline__ unsigned long
257 pci_dac_dma_to_offset(struct pci_dev *pdev, dma64_addr_t dma_addr)
258 {
259         return (dma_addr & ~PAGE_MASK);
260 }
261
262 static __inline__ void
263 pci_dac_dma_sync_single(struct pci_dev *pdev, dma64_addr_t dma_addr, size_t len, int direction)
264 {
265         flush_write_buffers();
266 }
267
268 /* These macros should be used after a pci_map_sg call has been done
269  * to get bus addresses of each of the SG entries and their lengths.
270  * You should only work with the number of sg entries pci_map_sg
271  * returns.
272  */
273 #define sg_dma_address(sg)      ((sg)->dma_address)
274 #define sg_dma_len(sg)          ((sg)->length)
275
276 /* Return the index of the PCI controller for device. */
277 static inline int pci_controller_num(struct pci_dev *dev)
278 {
279         return 0;
280 }
281
282 #define HAVE_PCI_MMAP
283 extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
284                                enum pci_mmap_state mmap_state, int write_combine);
285
286 #endif /* __KERNEL__ */
287
288 #endif /* __i386_PCI_H */