patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / include / asm-ppc64 / io.h
1 #ifndef _PPC64_IO_H
2 #define _PPC64_IO_H
3
4 /* 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version
8  * 2 of the License, or (at your option) any later version.
9  */
10
11 #include <linux/config.h>
12 #include <asm/page.h>
13 #include <asm/byteorder.h>
14 #ifdef CONFIG_PPC_ISERIES 
15 #include <asm/iSeries/iSeries_io.h>
16 #endif  
17 #include <asm/memory.h>
18 #include <asm/delay.h>
19
20 #define __ide_mm_insw(p, a, c) _insw_ns((volatile u16 *)(p), (a), (c))
21 #define __ide_mm_insl(p, a, c) _insl_ns((volatile u32 *)(p), (a), (c))
22 #define __ide_mm_outsw(p, a, c) _outsw_ns((volatile u16 *)(p), (a), (c))
23 #define __ide_mm_outsl(p, a, c) _outsl_ns((volatile u32 *)(p), (a), (c))
24
25
26 #define SIO_CONFIG_RA   0x398
27 #define SIO_CONFIG_RD   0x399
28
29 #define SLOW_DOWN_IO
30
31 extern unsigned long isa_io_base;
32 extern unsigned long pci_io_base;
33
34 #ifdef CONFIG_PPC_ISERIES
35 /* __raw_* accessors aren't supported on iSeries */
36 #define __raw_readb(addr)       { BUG(); 0; }
37 #define __raw_readw(addr)       { BUG(); 0; }
38 #define __raw_readl(addr)       { BUG(); 0; }
39 #define __raw_readq(addr)       { BUG(); 0; }
40 #define __raw_writeb(v, addr)   { BUG(); 0; }
41 #define __raw_writew(v, addr)   { BUG(); 0; }
42 #define __raw_writel(v, addr)   { BUG(); 0; }
43 #define __raw_writeq(v, addr)   { BUG(); 0; }
44 #define readb(addr)             iSeries_Read_Byte((void*)(addr))  
45 #define readw(addr)             iSeries_Read_Word((void*)(addr))  
46 #define readl(addr)             iSeries_Read_Long((void*)(addr))
47 #define writeb(data, addr)      iSeries_Write_Byte(data,((void*)(addr)))
48 #define writew(data, addr)      iSeries_Write_Word(data,((void*)(addr)))
49 #define writel(data, addr)      iSeries_Write_Long(data,((void*)(addr)))
50 #define memset_io(a,b,c)        iSeries_memset_io((void *)(a),(b),(c))
51 #define memcpy_fromio(a,b,c)    iSeries_memcpy_fromio((void *)(a), (void *)(b), (c))
52 #define memcpy_toio(a,b,c)      iSeries_memcpy_toio((void *)(a), (void *)(b), (c))
53 #define inb(addr)               readb(((unsigned long)(addr)))  
54 #define inw(addr)               readw(((unsigned long)(addr)))  
55 #define inl(addr)               readl(((unsigned long)(addr)))
56 #define outb(data,addr)         writeb(data,((unsigned long)(addr)))  
57 #define outw(data,addr)         writew(data,((unsigned long)(addr)))  
58 #define outl(data,addr)         writel(data,((unsigned long)(addr)))
59 /*
60  * The *_ns versions below don't do byte-swapping.
61  * Neither do the standard versions now, these are just here
62  * for older code.
63  */
64 #define insw_ns(port, buf, ns)  _insw_ns((u16 *)((port)+pci_io_base), (buf), (ns))
65 #define insl_ns(port, buf, nl)  _insl_ns((u32 *)((port)+pci_io_base), (buf), (nl))
66 #else
67 #define __raw_readb(addr)       (*(volatile unsigned char *)(addr))
68 #define __raw_readw(addr)       (*(volatile unsigned short *)(addr))
69 #define __raw_readl(addr)       (*(volatile unsigned int *)(addr))
70 #define __raw_readq(addr)       (*(volatile unsigned long *)(addr))
71 #define __raw_writeb(v, addr)   (*(volatile unsigned char *)(addr) = (v))
72 #define __raw_writew(v, addr)   (*(volatile unsigned short *)(addr) = (v))
73 #define __raw_writel(v, addr)   (*(volatile unsigned int *)(addr) = (v))
74 #define __raw_writeq(v, addr)   (*(volatile unsigned long *)(addr) = (v))
75 #define readb(addr)             eeh_readb((void*)(addr))  
76 #define readw(addr)             eeh_readw((void*)(addr))  
77 #define readl(addr)             eeh_readl((void*)(addr))
78 #define readq(addr)             eeh_readq((void*)(addr))
79 #define writeb(data, addr)      eeh_writeb((data), ((void*)(addr)))
80 #define writew(data, addr)      eeh_writew((data), ((void*)(addr)))
81 #define writel(data, addr)      eeh_writel((data), ((void*)(addr)))
82 #define writeq(data, addr)      eeh_writeq((data), ((void*)(addr)))
83 #define memset_io(a,b,c)        eeh_memset_io((void *)(a),(b),(c))
84 #define memcpy_fromio(a,b,c)    eeh_memcpy_fromio((a),(void *)(b),(c))
85 #define memcpy_toio(a,b,c)      eeh_memcpy_toio((void *)(a),(b),(c))
86 #define inb(port)               eeh_inb((unsigned long)port)
87 #define outb(val, port)         eeh_outb(val, (unsigned long)port)
88 #define inw(port)               eeh_inw((unsigned long)port)
89 #define outw(val, port)         eeh_outw(val, (unsigned long)port)
90 #define inl(port)               eeh_inl((unsigned long)port)
91 #define outl(val, port)         eeh_outl(val, (unsigned long)port)
92
93 /*
94  * The insw/outsw/insl/outsl macros don't do byte-swapping.
95  * They are only used in practice for transferring buffers which
96  * are arrays of bytes, and byte-swapping is not appropriate in
97  * that case.  - paulus */
98 #define insb(port, buf, ns)     eeh_insb((port), (buf), (ns))
99 #define insw(port, buf, ns)     eeh_insw_ns((port), (buf), (ns))
100 #define insl(port, buf, nl)     eeh_insl_ns((port), (buf), (nl))
101 #define insw_ns(port, buf, ns)  eeh_insw_ns((port), (buf), (ns))
102 #define insl_ns(port, buf, nl)  eeh_insl_ns((port), (buf), (nl))
103
104 #define outsb(port, buf, ns)  _outsb((u8 *)((port)+pci_io_base), (buf), (ns))
105 #define outsw(port, buf, ns)  _outsw_ns((u16 *)((port)+pci_io_base), (buf), (ns))
106 #define outsl(port, buf, nl)  _outsl_ns((u32 *)((port)+pci_io_base), (buf), (nl))
107
108 #endif
109
110 #define readb_relaxed(addr) readb(addr)
111 #define readw_relaxed(addr) readw(addr)
112 #define readl_relaxed(addr) readl(addr)
113 #define readq_relaxed(addr) readq(addr)
114
115 extern void _insb(volatile u8 *port, void *buf, int ns);
116 extern void _outsb(volatile u8 *port, const void *buf, int ns);
117 extern void _insw(volatile u16 *port, void *buf, int ns);
118 extern void _outsw(volatile u16 *port, const void *buf, int ns);
119 extern void _insl(volatile u32 *port, void *buf, int nl);
120 extern void _outsl(volatile u32 *port, const void *buf, int nl);
121 extern void _insw_ns(volatile u16 *port, void *buf, int ns);
122 extern void _outsw_ns(volatile u16 *port, const void *buf, int ns);
123 extern void _insl_ns(volatile u32 *port, void *buf, int nl);
124 extern void _outsl_ns(volatile u32 *port, const void *buf, int nl);
125
126 /*
127  * output pause versions need a delay at least for the
128  * w83c105 ide controller in a p610.
129  */
130 #define inb_p(port)             inb(port)
131 #define outb_p(val, port)       (udelay(1), outb((val), (port)))
132 #define inw_p(port)             inw(port)
133 #define outw_p(val, port)       (udelay(1), outw((val), (port)))
134 #define inl_p(port)             inl(port)
135 #define outl_p(val, port)       (udelay(1), outl((val), (port)))
136
137 /*
138  * The *_ns versions below don't do byte-swapping.
139  * Neither do the standard versions now, these are just here
140  * for older code.
141  */
142 #define outsw_ns(port, buf, ns) _outsw_ns((u16 *)((port)+pci_io_base), (buf), (ns))
143 #define outsl_ns(port, buf, nl) _outsl_ns((u32 *)((port)+pci_io_base), (buf), (nl))
144
145
146 #define IO_SPACE_LIMIT ~(0UL)
147
148
149 #ifdef __KERNEL__
150 extern int __ioremap_explicit(unsigned long p_addr, unsigned long v_addr,
151                               unsigned long size, unsigned long flags);
152 extern void *__ioremap(unsigned long address, unsigned long size,
153                        unsigned long flags);
154
155 /**
156  * ioremap     -   map bus memory into CPU space
157  * @address:   bus address of the memory
158  * @size:      size of the resource to map
159  *
160  * ioremap performs a platform specific sequence of operations to
161  * make bus memory CPU accessible via the readb/readw/readl/writeb/
162  * writew/writel functions and the other mmio helpers. The returned
163  * address is not guaranteed to be usable directly as a virtual
164  * address.
165  */
166 extern void *ioremap(unsigned long address, unsigned long size);
167
168 #define ioremap_nocache(addr, size)     ioremap((addr), (size))
169 extern int iounmap_explicit(void *addr, unsigned long size);
170 extern void iounmap(void *addr);
171 extern void * reserve_phb_iospace(unsigned long size);
172
173 /**
174  *      virt_to_phys    -       map virtual addresses to physical
175  *      @address: address to remap
176  *
177  *      The returned physical address is the physical (CPU) mapping for
178  *      the memory address given. It is only valid to use this function on
179  *      addresses directly mapped or allocated via kmalloc.
180  *
181  *      This function does not give bus mappings for DMA transfers. In
182  *      almost all conceivable cases a device driver should not be using
183  *      this function
184  */
185 static inline unsigned long virt_to_phys(volatile void * address)
186 {
187         return __pa((unsigned long)address);
188 }
189
190 /**
191  *      phys_to_virt    -       map physical address to virtual
192  *      @address: address to remap
193  *
194  *      The returned virtual address is a current CPU mapping for
195  *      the memory address given. It is only valid to use this function on
196  *      addresses that have a kernel mapping
197  *
198  *      This function does not handle bus mappings for DMA transfers. In
199  *      almost all conceivable cases a device driver should not be using
200  *      this function
201  */
202 static inline void * phys_to_virt(unsigned long address)
203 {
204         return (void *)__va(address);
205 }
206
207 /*
208  * Change "struct page" to physical address.
209  */
210 #define page_to_phys(page)      (page_to_pfn(page) << PAGE_SHIFT)
211
212 /* We do NOT want virtual merging, it would put too much pressure on
213  * our iommu allocator. Instead, we want drivers to be smart enough
214  * to coalesce sglists that happen to have been mapped in a contiguous
215  * way by the iommu
216  */
217 #define BIO_VMERGE_BOUNDARY     0
218
219 #endif /* __KERNEL__ */
220
221 static inline void iosync(void)
222 {
223         __asm__ __volatile__ ("sync" : : : "memory");
224 }
225
226 /* Enforce in-order execution of data I/O. 
227  * No distinction between read/write on PPC; use eieio for all three.
228  */
229 #define iobarrier_rw() eieio()
230 #define iobarrier_r()  eieio()
231 #define iobarrier_w()  eieio()
232
233 /*
234  * 8, 16 and 32 bit, big and little endian I/O operations, with barrier.
235  * These routines do not perform EEH-related I/O address translation,
236  * and should not be used directly by device drivers.  Use inb/readb
237  * instead.
238  */
239 static inline int in_8(volatile unsigned char *addr)
240 {
241         int ret;
242
243         __asm__ __volatile__("lbz%U1%X1 %0,%1; twi 0,%0,0; isync"
244                              : "=r" (ret) : "m" (*addr));
245         return ret;
246 }
247
248 static inline void out_8(volatile unsigned char *addr, int val)
249 {
250         __asm__ __volatile__("stb%U0%X0 %1,%0; sync"
251                              : "=m" (*addr) : "r" (val));
252 }
253
254 static inline int in_le16(volatile unsigned short *addr)
255 {
256         int ret;
257
258         __asm__ __volatile__("lhbrx %0,0,%1; twi 0,%0,0; isync"
259                              : "=r" (ret) : "r" (addr), "m" (*addr));
260         return ret;
261 }
262
263 static inline int in_be16(volatile unsigned short *addr)
264 {
265         int ret;
266
267         __asm__ __volatile__("lhz%U1%X1 %0,%1; twi 0,%0,0; isync"
268                              : "=r" (ret) : "m" (*addr));
269         return ret;
270 }
271
272 static inline void out_le16(volatile unsigned short *addr, int val)
273 {
274         __asm__ __volatile__("sthbrx %1,0,%2; sync"
275                              : "=m" (*addr) : "r" (val), "r" (addr));
276 }
277
278 static inline void out_be16(volatile unsigned short *addr, int val)
279 {
280         __asm__ __volatile__("sth%U0%X0 %1,%0; sync"
281                              : "=m" (*addr) : "r" (val));
282 }
283
284 static inline unsigned in_le32(volatile unsigned *addr)
285 {
286         unsigned ret;
287
288         __asm__ __volatile__("lwbrx %0,0,%1; twi 0,%0,0; isync"
289                              : "=r" (ret) : "r" (addr), "m" (*addr));
290         return ret;
291 }
292
293 static inline unsigned in_be32(volatile unsigned *addr)
294 {
295         unsigned ret;
296
297         __asm__ __volatile__("lwz%U1%X1 %0,%1; twi 0,%0,0; isync"
298                              : "=r" (ret) : "m" (*addr));
299         return ret;
300 }
301
302 static inline void out_le32(volatile unsigned *addr, int val)
303 {
304         __asm__ __volatile__("stwbrx %1,0,%2; sync" : "=m" (*addr)
305                              : "r" (val), "r" (addr));
306 }
307
308 static inline void out_be32(volatile unsigned *addr, int val)
309 {
310         __asm__ __volatile__("stw%U0%X0 %1,%0; sync"
311                              : "=m" (*addr) : "r" (val));
312 }
313
314 static inline unsigned long in_le64(volatile unsigned long *addr)
315 {
316         unsigned long tmp, ret;
317
318         __asm__ __volatile__(
319                              "ld %1,0(%2)\n"
320                              "twi 0,%1,0\n"
321                              "isync\n"
322                              "rldimi %0,%1,5*8,1*8\n"
323                              "rldimi %0,%1,3*8,2*8\n"
324                              "rldimi %0,%1,1*8,3*8\n"
325                              "rldimi %0,%1,7*8,4*8\n"
326                              "rldicl %1,%1,32,0\n"
327                              "rlwimi %0,%1,8,8,31\n"
328                              "rlwimi %0,%1,24,16,23\n"
329                              : "=r" (ret) , "=r" (tmp) : "b" (addr) , "m" (*addr));
330         return ret;
331 }
332
333 static inline unsigned long in_be64(volatile unsigned long *addr)
334 {
335         unsigned long ret;
336
337         __asm__ __volatile__("ld %0,0(%1); twi 0,%0,0; isync"
338                              : "=r" (ret) : "m" (*addr));
339         return ret;
340 }
341
342 static inline void out_le64(volatile unsigned long *addr, unsigned long val)
343 {
344         unsigned long tmp;
345
346         __asm__ __volatile__(
347                              "rldimi %0,%1,5*8,1*8\n"
348                              "rldimi %0,%1,3*8,2*8\n"
349                              "rldimi %0,%1,1*8,3*8\n"
350                              "rldimi %0,%1,7*8,4*8\n"
351                              "rldicl %1,%1,32,0\n"
352                              "rlwimi %0,%1,8,8,31\n"
353                              "rlwimi %0,%1,24,16,23\n"
354                              "std %0,0(%3)\n"
355                              "sync"
356                              : "=&r" (tmp) , "=&r" (val) : "1" (val) , "b" (addr) , "m" (*addr));
357 }
358
359 static inline void out_be64(volatile unsigned long *addr, unsigned long val)
360 {
361         __asm__ __volatile__("std%U0%X0 %1,%0; sync" : "=m" (*addr) : "r" (val));
362 }
363
364 #ifndef CONFIG_PPC_ISERIES 
365 #include <asm/eeh.h>
366 #endif
367
368 #ifdef __KERNEL__
369
370 /**
371  *      check_signature         -       find BIOS signatures
372  *      @io_addr: mmio address to check
373  *      @signature:  signature block
374  *      @length: length of signature
375  *
376  *      Perform a signature comparison with the mmio address io_addr. This
377  *      address should have been obtained by ioremap.
378  *      Returns 1 on a match.
379  */
380 static inline int check_signature(unsigned long io_addr,
381         const unsigned char *signature, int length)
382 {
383         int retval = 0;
384 #ifndef CONFIG_PPC_ISERIES 
385         do {
386                 if (readb(io_addr) != *signature)
387                         goto out;
388                 io_addr++;
389                 signature++;
390                 length--;
391         } while (length);
392         retval = 1;
393 out:
394 #endif
395         return retval;
396 }
397
398 /* Nothing to do */
399
400 #define dma_cache_inv(_start,_size)             do { } while (0)
401 #define dma_cache_wback(_start,_size)           do { } while (0)
402 #define dma_cache_wback_inv(_start,_size)       do { } while (0)
403
404 #endif /* __KERNEL__ */
405
406 #endif /* _PPC64_IO_H */