1 /* $Id: pci.h,v 1.4 2000/02/24 00:13:20 ralf Exp $
3 * This file is subject to the terms and conditions of the GNU General Public
4 * License. See the file "COPYING" in the main directory of this archive
12 /* Can be used to override the logic in pci_scan_bus for skipping
13 already-configured bus numbers - to be used for buggy BIOSes
14 or architectures with incomplete PCI setup by the loader */
16 #define pcibios_assign_all_busses() 0
18 #define PCIBIOS_MIN_IO 0x1000
19 #define PCIBIOS_MIN_MEM 0x10000000
21 extern inline void pcibios_set_master(struct pci_dev
*dev
)
23 /* No special bus mastering setup handling */
26 extern inline void pcibios_penalize_isa_irq(int irq
)
28 /* We don't do dynamic PCI IRQ allocation */
32 * Dynamic DMA mapping stuff.
33 * MIPS has everything mapped statically.
36 #include <linux/config.h>
37 #include <linux/types.h>
38 #include <linux/slab.h>
39 #include <asm/scatterlist.h>
40 #include <linux/string.h>
46 * Allocate and map kernel buffer using consistent mode DMA for a device.
47 * hwdev should be valid struct pci_dev pointer for PCI devices,
48 * NULL for PCI-like buses (ISA, EISA).
49 * Returns non-NULL cpu-view pointer to the buffer if successful and
50 * sets *dma_addrp to the pci side dma address as well, else *dma_addrp
53 extern void *pci_alloc_consistent(struct pci_dev
*hwdev
, size_t size
,
54 dma_addr_t
*dma_handle
);
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.
62 * References to the memory and mappings associated with cpu_addr/dma_addr
63 * past this call are illegal.
65 extern void pci_free_consistent(struct pci_dev
*hwdev
, size_t size
,
66 void *vaddr
, dma_addr_t dma_handle
);
69 * Map a single buffer of the indicated size for DMA in streaming mode.
70 * The 32-bit bus address to use is returned.
72 * Once the device is given the dma address, the device owns this memory
73 * until either pci_unmap_single or pci_dma_sync_single is performed.
75 extern inline dma_addr_t
pci_map_single(struct pci_dev
*hwdev
, void *ptr
,
76 size_t size
, int direction
)
78 if (direction
== PCI_DMA_NONE
)
81 #ifndef CONFIG_COHERENT_IO
82 dma_cache_wback_inv((unsigned long)ptr
, size
);
84 return (bus_to_baddr
[hwdev
->bus
->number
] | __pa(ptr
));
88 * Unmap a single streaming mode DMA translation. The dma_addr and size
89 * must match what was provided for in a previous pci_map_single call. All
90 * other usages are undefined.
92 * After this call, reads by the cpu to the buffer are guarenteed to see
93 * whatever the device wrote there.
95 extern inline void pci_unmap_single(struct pci_dev
*hwdev
, dma_addr_t dma_addr
,
96 size_t size
, int direction
)
98 if (direction
== PCI_DMA_NONE
)
105 * Map a set of buffers described by scatterlist in streaming
106 * mode for DMA. This is the scather-gather version of the
107 * above pci_map_single interface. Here the scatter gather list
108 * elements are each tagged with the appropriate dma address
109 * and length. They are obtained via sg_dma_{address,length}(SG).
111 * NOTE: An implementation may be able to use a smaller number of
112 * DMA address/length pairs than there are SG table elements.
113 * (for example via virtual mapping capabilities)
114 * The routine returns the number of addr/length pairs actually
115 * used, at most nents.
117 * Device ownership issues as mentioned above for pci_map_single are
120 extern inline int pci_map_sg(struct pci_dev
*hwdev
, struct scatterlist
*sg
,
121 int nents
, int direction
)
125 if (direction
== PCI_DMA_NONE
)
128 /* Make sure that gcc doesn't leave the empty loop body. */
129 for (i
= 0; i
< nents
; i
++, sg
++) {
130 #ifndef CONFIG_COHERENT_IO
131 dma_cache_wback_inv((unsigned long)sg
->address
, sg
->length
);
133 sg
->address
= (char *)(bus_to_baddr
[hwdev
->bus
->number
] | __pa(sg
->address
));
140 * Unmap a set of streaming mode DMA translations.
141 * Again, cpu read rules concerning calls here are the same as for
142 * pci_unmap_single() above.
144 extern inline void pci_unmap_sg(struct pci_dev
*hwdev
, struct scatterlist
*sg
,
145 int nents
, int direction
)
147 if (direction
== PCI_DMA_NONE
)
154 * Make physical memory consistent for a single
155 * streaming mode DMA translation after a transfer.
157 * If you perform a pci_map_single() but wish to interrogate the
158 * buffer using the cpu, yet do not wish to teardown the PCI dma
159 * mapping, you must call this function before doing so. At the
160 * next point you give the PCI dma address back to the card, the
161 * device again owns the buffer.
163 extern inline void pci_dma_sync_single(struct pci_dev
*hwdev
,
164 dma_addr_t dma_handle
,
165 size_t size
, int direction
)
167 if (direction
== PCI_DMA_NONE
)
169 #ifndef CONFIG_COHERENT_IO
170 dma_cache_wback_inv((unsigned long)__va(dma_handle
- bus_to_baddr
[hwdev
->bus
->number
]), size
);
175 * Make physical memory consistent for a set of streaming
176 * mode DMA translations after a transfer.
178 * The same as pci_dma_sync_single but for a scatter-gather list,
179 * same rules and usage.
181 extern inline void pci_dma_sync_sg(struct pci_dev
*hwdev
,
182 struct scatterlist
*sg
,
183 int nelems
, int direction
)
185 #ifndef CONFIG_COHERENT_IO
189 if (direction
== PCI_DMA_NONE
)
192 /* Make sure that gcc doesn't leave the empty loop body. */
193 #ifndef CONFIG_COHERENT_IO
194 for (i
= 0; i
< nelems
; i
++, sg
++)
195 dma_cache_wback_inv((unsigned long)sg
->address
, sg
->length
);
200 * These macros should be used after a pci_map_sg call has been done
201 * to get bus addresses of each of the SG entries and their lengths.
202 * You should only work with the number of sg entries pci_map_sg
203 * returns, or alternatively stop on the first sg_dma_len(sg) which
206 #define sg_dma_address(sg) ((unsigned long)((sg)->address))
207 #define sg_dma_len(sg) ((sg)->length)
209 #endif /* __KERNEL__ */
211 #endif /* _ASM_PCI_H */