ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / asm-ppc / pci.h
1 #ifndef __PPC_PCI_H
2 #define __PPC_PCI_H
3 #ifdef __KERNEL__
4
5 #include <linux/types.h>
6 #include <linux/slab.h>
7 #include <linux/string.h>
8 #include <linux/mm.h>
9 #include <asm/scatterlist.h>
10 #include <asm/io.h>
11 #include <asm/pci-bridge.h>
12
13 struct pci_dev;
14
15 /* Values for the `which' argument to sys_pciconfig_iobase syscall.  */
16 #define IOBASE_BRIDGE_NUMBER    0
17 #define IOBASE_MEMORY           1
18 #define IOBASE_IO               2
19 #define IOBASE_ISA_IO           3
20 #define IOBASE_ISA_MEM          4
21
22 /*
23  * Set this to 1 if you want the kernel to re-assign all PCI
24  * bus numbers
25  */
26 extern int pci_assign_all_busses;
27
28 #define pcibios_assign_all_busses()     (pci_assign_all_busses)
29 #define pcibios_scan_all_fns(a, b)      0
30
31 #define PCIBIOS_MIN_IO          0x1000
32 #define PCIBIOS_MIN_MEM         0x10000000
33
34 extern inline void pcibios_set_master(struct pci_dev *dev)
35 {
36         /* No special bus mastering setup handling */
37 }
38
39 extern inline void pcibios_penalize_isa_irq(int irq)
40 {
41         /* We don't do dynamic PCI IRQ allocation */
42 }
43
44 extern unsigned long pci_resource_to_bus(struct pci_dev *pdev, struct resource *res);
45
46 /*
47  * The PCI bus bridge can translate addresses issued by the processor(s)
48  * into a different address on the PCI bus.  On 32-bit cpus, we assume
49  * this mapping is 1-1, but on 64-bit systems it often isn't.
50  *
51  * Obsolete ! Drivers should now use pci_resource_to_bus
52  */
53 extern unsigned long phys_to_bus(unsigned long pa);
54 extern unsigned long pci_phys_to_bus(unsigned long pa, int busnr);
55 extern unsigned long pci_bus_to_phys(unsigned int ba, int busnr);
56
57 /*
58  * Dynamic DMA Mapping stuff
59  * Originally stolen from i386 by ajoshi and updated by paulus
60  * Non-consistent cache support by Dan Malek
61  */
62
63 /* The PCI address space does equal the physical memory
64  * address space.  The networking and block device layers use
65  * this boolean for bounce buffer decisions.
66  */
67 #define PCI_DMA_BUS_IS_PHYS     (1)
68
69 /* Allocate and map kernel buffer using consistent mode DMA for a device.
70  * hwdev should be valid struct pci_dev pointer for PCI devices,
71  * NULL for PCI-like buses (ISA, EISA).
72  * Returns non-NULL cpu-view pointer to the buffer if successful and
73  * sets *dma_addrp to the pci side dma address as well, else *dma_addrp
74  * is undefined.
75  */
76 extern void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
77                                   dma_addr_t *dma_handle);
78
79 /* Free and unmap a consistent DMA buffer.
80  * cpu_addr is what was returned from pci_alloc_consistent,
81  * size must be the same as what as passed into pci_alloc_consistent,
82  * and likewise dma_addr must be the same as what *dma_addrp was set to.
83  *
84  * References to the memory and mappings associated with cpu_addr/dma_addr
85  * past this call are illegal.
86  */
87 extern void pci_free_consistent(struct pci_dev *hwdev, size_t size,
88                                 void *vaddr, dma_addr_t dma_handle);
89
90 /* Map a single buffer of the indicated size for DMA in streaming mode.
91  * The 32-bit bus address to use is returned.
92  *
93  * Once the device is given the dma address, the device owns this memory
94  * until either pci_unmap_single or pci_dma_sync_single_for_cpu is performed.
95  */
96 static inline dma_addr_t pci_map_single(struct pci_dev *hwdev, void *ptr,
97                                         size_t size, int direction)
98 {
99         BUG_ON(direction == PCI_DMA_NONE);
100
101         consistent_sync(ptr, size, direction);
102
103         return virt_to_bus(ptr);
104 }
105
106 static inline void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr,
107                                     size_t size, int direction)
108 {
109         BUG_ON(direction == PCI_DMA_NONE);
110         /* nothing to do */
111 }
112
113 /* pci_unmap_{page,single} is a nop so... */
114 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)
115 #define DECLARE_PCI_UNMAP_LEN(LEN_NAME)
116 #define pci_unmap_addr(PTR, ADDR_NAME)          (0)
117 #define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) do { } while (0)
118 #define pci_unmap_len(PTR, LEN_NAME)            (0)
119 #define pci_unmap_len_set(PTR, LEN_NAME, VAL)   do { } while (0)
120
121 /*
122  * pci_{map,unmap}_single_page maps a kernel page to a dma_addr_t. identical
123  * to pci_map_single, but takes a struct page instead of a virtual address
124  */
125 static inline dma_addr_t pci_map_page(struct pci_dev *hwdev, struct page *page,
126                                       unsigned long offset, size_t size,
127                                       int direction)
128 {
129         BUG_ON(direction == PCI_DMA_NONE);
130         consistent_sync_page(page, offset, size, direction);
131         return (page - mem_map) * PAGE_SIZE + PCI_DRAM_OFFSET + offset;
132 }
133
134 static inline void pci_unmap_page(struct pci_dev *hwdev, dma_addr_t dma_address,
135                                   size_t size, int direction)
136 {
137         BUG_ON(direction == PCI_DMA_NONE);
138         /* Nothing to do */
139 }
140
141 /* Map a set of buffers described by scatterlist in streaming
142  * mode for DMA.  This is the scather-gather version of the
143  * above pci_map_single interface.  Here the scatter gather list
144  * elements are each tagged with the appropriate dma address
145  * and length.  They are obtained via sg_dma_{address,length}(SG).
146  *
147  * NOTE: An implementation may be able to use a smaller number of
148  *       DMA address/length pairs than there are SG table elements.
149  *       (for example via virtual mapping capabilities)
150  *       The routine returns the number of addr/length pairs actually
151  *       used, at most nents.
152  *
153  * Device ownership issues as mentioned above for pci_map_single are
154  * the same here.
155  */
156 static inline int pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg,
157                              int nents, int direction)
158 {
159         int i;
160
161         BUG_ON(direction == PCI_DMA_NONE);
162
163         /*
164          * temporary 2.4 hack
165          */
166         for (i = 0; i < nents; i++, sg++) {
167                 BUG_ON(!sg->page);
168                 consistent_sync_page(sg->page, sg->offset,
169                                      sg->length, direction);
170                 sg->dma_address = page_to_bus(sg->page) + sg->offset;
171         }
172
173         return nents;
174 }
175
176 /* Unmap a set of streaming mode DMA translations.
177  * Again, cpu read rules concerning calls here are the same as for
178  * pci_unmap_single() above.
179  */
180 static inline void pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg,
181                                 int nents, int direction)
182 {
183         BUG_ON(direction == PCI_DMA_NONE);
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, you
194  * must first perform a pci_dma_sync_for_device, and then the device
195  * again owns the buffer.
196  */
197 static inline void pci_dma_sync_single_for_cpu(struct pci_dev *hwdev,
198                                                dma_addr_t dma_handle,
199                                                size_t size, int direction)
200 {
201         BUG_ON(direction == PCI_DMA_NONE);
202
203         consistent_sync(bus_to_virt(dma_handle), size, direction);
204 }
205
206 static inline void pci_dma_sync_single_for_device(struct pci_dev *hwdev,
207                                                   dma_addr_t dma_handle,
208                                                   size_t size, int direction)
209 {
210         BUG_ON(direction == PCI_DMA_NONE);
211
212         consistent_sync(bus_to_virt(dma_handle), size, direction);
213 }
214
215 /* Make physical memory consistent for a set of streaming
216  * mode DMA translations after a transfer.
217  *
218  * The same as pci_dma_sync_single_for_* but for a scatter-gather list,
219  * same rules and usage.
220  */
221 static inline void pci_dma_sync_sg_for_cpu(struct pci_dev *hwdev,
222                                            struct scatterlist *sg,
223                                            int nelems, int direction)
224 {
225         int i;
226
227         BUG_ON(direction == PCI_DMA_NONE);
228
229         for (i = 0; i < nelems; i++, sg++)
230                 consistent_sync_page(sg->page, sg->offset,
231                                      sg->length, direction);
232 }
233
234 static inline void pci_dma_sync_sg_for_device(struct pci_dev *hwdev,
235                                               struct scatterlist *sg,
236                                               int nelems, int direction)
237 {
238         int i;
239
240         BUG_ON(direction == PCI_DMA_NONE);
241
242         for (i = 0; i < nelems; i++, sg++)
243                 consistent_sync_page(sg->page, sg->offset,
244                                      sg->length, direction);
245 }
246
247 /* Return whether the given PCI device DMA address mask can
248  * be supported properly.  For example, if your device can
249  * only drive the low 24-bits during PCI bus mastering, then
250  * you would pass 0x00ffffff as the mask to this function.
251  */
252 static inline int pci_dma_supported(struct pci_dev *hwdev, u64 mask)
253 {
254         return 1;
255 }
256
257 /*
258  * At present there are very few 32-bit PPC machines that can have
259  * memory above the 4GB point, and we don't support that.
260  */
261 #define pci_dac_dma_supported(pci_dev, mask)    (0)
262
263 static inline dma64_addr_t
264 pci_dac_page_to_dma(struct pci_dev *pdev, struct page *page, unsigned long offset, int direction)
265 {
266         return (dma64_addr_t) page_to_bus(page) + offset;
267 }
268
269 static inline struct page *
270 pci_dac_dma_to_page(struct pci_dev *pdev, dma64_addr_t dma_addr)
271 {
272         return mem_map + (unsigned long)(dma_addr >> PAGE_SHIFT);
273 }
274
275 static inline unsigned long
276 pci_dac_dma_to_offset(struct pci_dev *pdev, dma64_addr_t dma_addr)
277 {
278         return (dma_addr & ~PAGE_MASK);
279 }
280
281 static inline void
282 pci_dac_dma_sync_single_for_cpu(struct pci_dev *pdev, dma64_addr_t dma_addr, size_t len, int direction)
283 {
284         /* Nothing to do. */
285 }
286
287 static inline void
288 pci_dac_dma_sync_single_for_device(struct pci_dev *pdev, dma64_addr_t dma_addr, size_t len, int direction)
289 {
290         /* Nothing to do. */
291 }
292
293 static inline int pci_dma_mapping_error(dma_addr_t dma_addr)
294 {
295         return 0;
296 }
297
298 /* Return the index of the PCI controller for device PDEV. */
299 #define pci_domain_nr(bus) ((struct pci_controller *)(bus)->sysdata)->index
300
301 /* Set the name of the bus as it appears in /proc/bus/pci */
302 static inline int pci_name_bus(char *name, struct pci_bus *bus)
303 {
304         sprintf(name, "%02x", bus->number);
305         return 0;
306 }
307
308 /* Map a range of PCI memory or I/O space for a device into user space */
309 int pci_mmap_page_range(struct pci_dev *pdev, struct vm_area_struct *vma,
310                         enum pci_mmap_state mmap_state, int write_combine);
311
312 /* Tell drivers/pci/proc.c that we have pci_mmap_page_range() */
313 #define HAVE_PCI_MMAP   1
314
315 extern void
316 pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
317                         struct resource *res);
318
319 extern void pcibios_add_platform_entries(struct pci_dev *dev);
320
321 #endif  /* __KERNEL__ */
322
323 #endif /* __PPC_PCI_H */