ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[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; eieio" : "=m" (*addr) : "r" (val));
251 }
252
253 static inline int in_le16(volatile unsigned short *addr)
254 {
255         int ret;
256
257         __asm__ __volatile__("lhbrx %0,0,%1; twi 0,%0,0; isync" :
258                              "=r" (ret) : "r" (addr), "m" (*addr));
259         return ret;
260 }
261
262 static inline int in_be16(volatile unsigned short *addr)
263 {
264         int ret;
265
266         __asm__ __volatile__("lhz%U1%X1 %0,%1; twi 0,%0,0; isync" :
267                              "=r" (ret) : "m" (*addr));
268         return ret;
269 }
270
271 static inline void out_le16(volatile unsigned short *addr, int val)
272 {
273         __asm__ __volatile__("sthbrx %1,0,%2; eieio" : "=m" (*addr) :
274                               "r" (val), "r" (addr));
275 }
276
277 static inline void out_be16(volatile unsigned short *addr, int val)
278 {
279         __asm__ __volatile__("sth%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
280 }
281
282 static inline unsigned in_le32(volatile unsigned *addr)
283 {
284         unsigned ret;
285
286         __asm__ __volatile__("lwbrx %0,0,%1; twi 0,%0,0; isync" :
287                              "=r" (ret) : "r" (addr), "m" (*addr));
288         return ret;
289 }
290
291 static inline unsigned in_be32(volatile unsigned *addr)
292 {
293         unsigned ret;
294
295         __asm__ __volatile__("lwz%U1%X1 %0,%1; twi 0,%0,0; isync" :
296                              "=r" (ret) : "m" (*addr));
297         return ret;
298 }
299
300 static inline void out_le32(volatile unsigned *addr, int val)
301 {
302         __asm__ __volatile__("stwbrx %1,0,%2; eieio" : "=m" (*addr) :
303                              "r" (val), "r" (addr));
304 }
305
306 static inline void out_be32(volatile unsigned *addr, int val)
307 {
308         __asm__ __volatile__("stw%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
309 }
310
311 static inline unsigned long in_le64(volatile unsigned long *addr)
312 {
313         unsigned long tmp, ret;
314
315         __asm__ __volatile__(
316                              "ld %1,0(%2)\n"
317                              "twi 0,%1,0\n"
318                              "isync\n"
319                              "rldimi %0,%1,5*8,1*8\n"
320                              "rldimi %0,%1,3*8,2*8\n"
321                              "rldimi %0,%1,1*8,3*8\n"
322                              "rldimi %0,%1,7*8,4*8\n"
323                              "rldicl %1,%1,32,0\n"
324                              "rlwimi %0,%1,8,8,31\n"
325                              "rlwimi %0,%1,24,16,23\n"
326                              : "=r" (ret), "=r" (tmp) : "b" (addr) , "m" (*addr));
327         return ret;
328 }
329
330 static inline unsigned long in_be64(volatile unsigned long *addr)
331 {
332         unsigned long ret;
333
334         __asm__ __volatile__("ld %0,0(%1); twi 0,%0,0; isync" :
335                              "=r" (ret) : "m" (*addr));
336         return ret;
337 }
338
339 static inline void out_le64(volatile unsigned long *addr, int val)
340 {
341         unsigned long tmp;
342
343         __asm__ __volatile__(
344                              "rldimi %0,%1,5*8,1*8\n"
345                              "rldimi %0,%1,3*8,2*8\n"
346                              "rldimi %0,%1,1*8,3*8\n"
347                              "rldimi %0,%1,7*8,4*8\n"
348                              "rldicl %1,%1,32,0\n"
349                              "rlwimi %0,%1,8,8,31\n"
350                              "rlwimi %0,%1,24,16,23\n"
351                              "std %0,0(%2)\n"
352                              "eieio\n"
353                              : "=r" (tmp) : "r" (val), "b" (addr) , "m" (*addr));
354 }
355
356 static inline void out_be64(volatile unsigned long *addr, int val)
357 {
358         __asm__ __volatile__("std %1,0(%0); eieio" : "=m" (*addr) : "r" (val));
359 }
360
361 #ifndef CONFIG_PPC_ISERIES 
362 #include <asm/eeh.h>
363 #endif
364
365 #ifdef __KERNEL__
366
367 /**
368  *      check_signature         -       find BIOS signatures
369  *      @io_addr: mmio address to check
370  *      @signature:  signature block
371  *      @length: length of signature
372  *
373  *      Perform a signature comparison with the mmio address io_addr. This
374  *      address should have been obtained by ioremap.
375  *      Returns 1 on a match.
376  */
377 static inline int check_signature(unsigned long io_addr,
378         const unsigned char *signature, int length)
379 {
380         int retval = 0;
381 #ifndef CONFIG_PPC_ISERIES 
382         do {
383                 if (readb(io_addr) != *signature)
384                         goto out;
385                 io_addr++;
386                 signature++;
387                 length--;
388         } while (length);
389         retval = 1;
390 out:
391 #endif
392         return retval;
393 }
394
395 /* Nothing to do */
396
397 #define dma_cache_inv(_start,_size)             do { } while (0)
398 #define dma_cache_wback(_start,_size)           do { } while (0)
399 #define dma_cache_wback_inv(_start,_size)       do { } while (0)
400
401 #endif /* __KERNEL__ */
402
403 #endif /* _PPC64_IO_H */