1 /* $Id: pci.h,v 1.4 2000/02/24 00:13:20 ralf Exp $
2 *
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
5 * for more details.
6 */
7 #ifndef _ASM_PCI_H
8 #define _ASM_PCI_H
9
10 #ifdef __KERNEL__
11
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 */
15
16 #define pcibios_assign_all_busses() 0
17
18 #define PCIBIOS_MIN_IO 0x1000
19 #define PCIBIOS_MIN_MEM 0x10000000
20
21 extern inline void pcibios_set_master(struct pci_dev *dev)
22 {
23 /* No special bus mastering setup handling */
24 }
25
26 extern inline void pcibios_penalize_isa_irq(int irq)
27 {
28 /* We don't do dynamic PCI IRQ allocation */
29 }
30
31 /*
32 * Dynamic DMA mapping stuff.
33 * MIPS has everything mapped statically.
34 */
35
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>
41 #include <asm/io.h>
42
43 struct pci_dev;
44
45 /*
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
51 * is undefined.
52 */
53 extern void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
54 dma_addr_t *dma_handle);
55
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 /*
69 * Map a single buffer of the indicated size for DMA in streaming mode.
70 * The 32-bit bus address to use is returned.
71 *
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.
74 */
75 extern inline dma_addr_t pci_map_single(struct pci_dev *hwdev, void *ptr,
76 size_t size, int direction)
77 {
78 if (direction == PCI_DMA_NONE)
79 BUG();
80
81 #ifndef CONFIG_COHERENT_IO
82 dma_cache_wback_inv((unsigned long)ptr, size);
83 #endif
84 return (bus_to_baddr[hwdev->bus->number] | __pa(ptr));
85 }
86
87 /*
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.
91 *
92 * After this call, reads by the cpu to the buffer are guarenteed to see
93 * whatever the device wrote there.
94 */
95 extern inline void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr,
96 size_t size, int direction)
97 {
98 if (direction == PCI_DMA_NONE)
99 BUG();
100
101 /* Nothing to do */
102 }
103
104 /*
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).
110 *
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.
116 *
117 * Device ownership issues as mentioned above for pci_map_single are
118 * the same here.
119 */
120 extern inline int pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg,
121 int nents, int direction)
122 {
123 int i;
124
125 if (direction == PCI_DMA_NONE)
126 BUG();
127
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);
132 #endif
133 sg->address = (char *)(bus_to_baddr[hwdev->bus->number] | __pa(sg->address));
134 }
135
136 return nents;
137 }
138
139 /*
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.
143 */
144 extern inline void pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg,
145 int nents, int direction)
146 {
147 if (direction == PCI_DMA_NONE)
148 BUG();
149
150 /* Nothing to do */
151 }
152
153 /*
154 * Make physical memory consistent for a single
155 * streaming mode DMA translation after a transfer.
156 *
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.
162 */
163 extern inline void pci_dma_sync_single(struct pci_dev *hwdev,
164 dma_addr_t dma_handle,
165 size_t size, int direction)
166 {
167 if (direction == PCI_DMA_NONE)
168 BUG();
169 #ifndef CONFIG_COHERENT_IO
170 dma_cache_wback_inv((unsigned long)__va(dma_handle - bus_to_baddr[hwdev->bus->number]), size);
171 #endif
172 }
173
174 /*
175 * Make physical memory consistent for a set of streaming
176 * mode DMA translations after a transfer.
177 *
178 * The same as pci_dma_sync_single but for a scatter-gather list,
179 * same rules and usage.
180 */
181 extern inline void pci_dma_sync_sg(struct pci_dev *hwdev,
182 struct scatterlist *sg,
183 int nelems, int direction)
184 {
185 #ifndef CONFIG_COHERENT_IO
186 int i;
187 #endif
188
189 if (direction == PCI_DMA_NONE)
190 BUG();
191
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);
196 #endif
197 }
198
199 /*
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
204 * is 0.
205 */
206 #define sg_dma_address(sg) ((unsigned long)((sg)->address))
207 #define sg_dma_len(sg) ((sg)->length)
208
209 #endif /* __KERNEL__ */
210
211 #endif /* _ASM_PCI_H */
212
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.