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