ia64/xen-unstable

view linux-2.4-xen-sparse/include/asm-xen/pci.h @ 6538:84ee014ebd41

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