added a lot of printk output to ease writing of emulator
[linux-2.4.21-pre4.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 SIO_CONFIG_RA   0x398
21 #define SIO_CONFIG_RD   0x399
22
23 #define SLOW_DOWN_IO
24 /* Define this if you want to see virt_to_* messages */
25 #undef __IO_DEBUG
26
27 extern unsigned long isa_io_base;
28 extern unsigned long isa_mem_base;
29 extern unsigned long pci_io_base;
30 extern unsigned long pci_dram_offset;
31 extern int have_print;
32 #define _IO_BASE        isa_io_base
33 #define _ISA_MEM_BASE   isa_mem_base
34 #define PCI_DRAM_OFFSET pci_dram_offset
35
36 #ifdef CONFIG_PPC_ISERIES
37 #define readb(addr)             iSeries_Read_Byte((void*)(addr))  
38 #define readw(addr)             iSeries_Read_Word((void*)(addr))  
39 #define readl(addr)             iSeries_Read_Long((void*)(addr))
40 #define writeb(data, addr)      iSeries_Write_Byte(data,((void*)(addr)))
41 #define writew(data, addr)      iSeries_Write_Word(data,((void*)(addr)))
42 #define writel(data, addr)      iSeries_Write_Long(data,((void*)(addr)))
43 #define memset_io(a,b,c)        iSeries_memset_io((void *)(a),(b),(c))
44 #define memcpy_fromio(a,b,c)    iSeries_memcpy_fromio((void *)(a), (void *)(b), (c))
45 #define memcpy_toio(a,b,c)      iSeries_memcpy_toio((void *)(a), (void *)(b), (c))
46 #define inb(addr)               readb(((unsigned long)(addr)))  
47 #define inw(addr)               readw(((unsigned long)(addr)))  
48 #define inl(addr)               readl(((unsigned long)(addr)))
49 #define outb(data,addr)         writeb(data,((unsigned long)(addr)))  
50 #define outw(data,addr)         writew(data,((unsigned long)(addr)))  
51 #define outl(data,addr)         writel(data,((unsigned long)(addr)))
52 #else
53 #define readb(addr)             eeh_readb((void*)(addr))  
54 #define readw(addr)             eeh_readw((void*)(addr))  
55 #define readl(addr)             eeh_readl((void*)(addr))
56 #define writeb(data, addr)      eeh_writeb((data), ((void*)(addr)))
57 #define writew(data, addr)      eeh_writew((data), ((void*)(addr)))
58 #define writel(data, addr)      eeh_writel((data), ((void*)(addr)))
59 #define memset_io(a,b,c)        eeh_memset_io((void *)(a),(b),(c))
60 #define memcpy_fromio(a,b,c)    eeh_memcpy_fromio((a),(void *)(b),(c))
61 #define memcpy_toio(a,b,c)      eeh_memcpy_toio((void *)(a),(b),(c))
62 #define inb(port)               eeh_inb((unsigned long)port)
63 #define outb(val, port)         eeh_outb(val, (unsigned long)port)
64 #define inw(port)               eeh_inw((unsigned long)port)
65 #define outw(val, port)         eeh_outw(val, (unsigned long)port)
66 #define inl(port)               eeh_inl((unsigned long)port)
67 #define outl(val, port)         eeh_outl(val, (unsigned long)port)
68
69 /*
70  * The insw/outsw/insl/outsl macros don't do byte-swapping.
71  * They are only used in practice for transferring buffers which
72  * are arrays of bytes, and byte-swapping is not appropriate in
73  * that case.  - paulus */
74 #define insb(port, buf, ns)     _insb((u8 *)((port)+pci_io_base), (buf), (ns))
75 #define outsb(port, buf, ns)    _outsb((u8 *)((port)+pci_io_base), (buf), (ns))
76 #define insw(port, buf, ns)     _insw_ns((u16 *)((port)+pci_io_base), (buf), (ns))
77 #define outsw(port, buf, ns)    _outsw_ns((u16 *)((port)+pci_io_base), (buf), (ns))
78 #define insl(port, buf, nl)     _insl_ns((u32 *)((port)+pci_io_base), (buf), (nl))
79 #define outsl(port, buf, nl)    _outsl_ns((u32 *)((port)+pci_io_base), (buf), (nl))
80 #endif
81
82 extern void _insb(volatile u8 *port, void *buf, int ns);
83 extern void _outsb(volatile u8 *port, const void *buf, int ns);
84 extern void _insw(volatile u16 *port, void *buf, int ns);
85 extern void _outsw(volatile u16 *port, const void *buf, int ns);
86 extern void _insl(volatile u32 *port, void *buf, int nl);
87 extern void _outsl(volatile u32 *port, const void *buf, int nl);
88 extern void _insw_ns(volatile u16 *port, void *buf, int ns);
89 extern void _outsw_ns(volatile u16 *port, const void *buf, int ns);
90 extern void _insl_ns(volatile u32 *port, void *buf, int nl);
91 extern void _outsl_ns(volatile u32 *port, const void *buf, int nl);
92
93 /*
94  * output pause versions need a delay at least for the
95  * w83c105 ide controller in a p610.
96  */
97 #define inb_p(port)             inb(port)
98 #define outb_p(val, port)       (udelay(1), outb((val), (port)))
99 #define inw_p(port)             inw(port)
100 #define outw_p(val, port)       (udelay(1), outw((val), (port)))
101 #define inl_p(port)             inl(port)
102 #define outl_p(val, port)       (udelay(1), outl((val, (port)))
103
104 /*
105  * The *_ns versions below don't do byte-swapping.
106  * Neither do the standard versions now, these are just here
107  * for older code.
108  */
109 #define insw_ns(port, buf, ns)  _insw_ns((u16 *)((port)+pci_io_base), (buf), (ns))
110 #define outsw_ns(port, buf, ns) _outsw_ns((u16 *)((port)+pci_io_base), (buf), (ns))
111 #define insl_ns(port, buf, nl)  _insl_ns((u32 *)((port)+pci_io_base), (buf), (nl))
112 #define outsl_ns(port, buf, nl) _outsl_ns((u32 *)((port)+pci_io_base), (buf), (nl))
113
114
115 #define IO_SPACE_LIMIT ~(0UL)
116 #define MEM_SPACE_LIMIT ~(0UL)
117
118
119 #ifdef __KERNEL__
120 /*
121  * Map in an area of physical address space, for accessing
122  * I/O devices etc.
123  */
124 extern void *__ioremap(unsigned long address, unsigned long size,
125                        unsigned long flags);
126 extern void *ioremap(unsigned long address, unsigned long size);
127 #define ioremap_nocache(addr, size)     ioremap((addr), (size))
128 extern void iounmap(void *addr);
129
130 /*
131  * Change virtual addresses to physical addresses and vv, for
132  * addresses in the area where the kernel has the RAM mapped.
133  */
134 static inline unsigned long virt_to_phys(volatile void * address)
135 {
136 #ifdef __IO_DEBUG
137         printk("virt_to_phys: 0x%08lx -> 0x%08lx\n", 
138                         (unsigned long) address,
139                         __pa((unsigned long)address));
140 #endif
141         return __pa((unsigned long)address);
142 }
143
144 static inline void * phys_to_virt(unsigned long address)
145 {
146 #ifdef __IO_DEBUG
147         printk("phys_to_virt: 0x%08lx -> 0x%08lx\n", address, __va(address));
148 #endif
149         return (void *) __va(address);
150 }
151
152 /*
153  * Change "struct page" to physical address.
154  */
155 #define page_to_phys(page)      ((page - mem_map) << PAGE_SHIFT)
156
157
158 #endif /* __KERNEL__ */
159
160 static inline void iosync(void)
161 {
162         __asm__ __volatile__ ("sync" : : : "memory");
163 }
164
165 /* Enforce in-order execution of data I/O. 
166  * No distinction between read/write on PPC; use eieio for all three.
167  */
168 #define iobarrier_rw() eieio()
169 #define iobarrier_r()  eieio()
170 #define iobarrier_w()  eieio()
171
172 /*
173  * 8, 16 and 32 bit, big and little endian I/O operations, with barrier.
174  * Until we can validate all required device drivers are weakc safe, an
175  * excess of syncs before the MMIO operations will make things work.  On 
176  * sstar, sync time is << than mmio time, so this should not be a big impact.
177  */
178 static inline int in_8(volatile unsigned char *addr)
179 {
180         int ret;
181
182         __asm__ __volatile__("sync; lbz%U1%X1 %0,%1; sync" : "=r" (ret) : "m" (*addr));
183         return ret;
184 }
185
186 static inline void out_8(volatile unsigned char *addr, int val)
187 {
188         __asm__ __volatile__("sync; stb%U0%X0 %1,%0; sync" : "=m" (*addr) : "r" (val));
189 }
190
191 static inline int in_le16(volatile unsigned short *addr)
192 {
193         int ret;
194
195         __asm__ __volatile__("sync; lhbrx %0,0,%1; sync" : "=r" (ret) :
196                               "r" (addr), "m" (*addr));
197         return ret;
198 }
199
200 static inline int in_be16(volatile unsigned short *addr)
201 {
202         int ret;
203
204         __asm__ __volatile__("sync; lhz%U1%X1 %0,%1; sync" : "=r" (ret) : "m" (*addr));
205         return ret;
206 }
207
208 static inline void out_le16(volatile unsigned short *addr, int val)
209 {
210         __asm__ __volatile__("sync; sthbrx %1,0,%2; sync" : "=m" (*addr) :
211                               "r" (val), "r" (addr));
212 }
213
214 static inline void out_be16(volatile unsigned short *addr, int val)
215 {
216         __asm__ __volatile__("sync; sth%U0%X0 %1,%0; sync" : "=m" (*addr) : "r" (val));
217 }
218
219 static inline unsigned in_le32(volatile unsigned *addr)
220 {
221         unsigned ret;
222
223         __asm__ __volatile__("sync; lwbrx %0,0,%1; sync" : "=r" (ret) :
224                              "r" (addr), "m" (*addr));
225         return ret;
226 }
227
228 static inline unsigned in_be32(volatile unsigned *addr)
229 {
230         unsigned ret;
231
232         __asm__ __volatile__("sync; lwz%U1%X1 %0,%1; sync" : "=r" (ret) : "m" (*addr));
233         return ret;
234 }
235
236 static inline void out_le32(volatile unsigned *addr, int val)
237 {
238         __asm__ __volatile__("sync; stwbrx %1,0,%2; sync" : "=m" (*addr) :
239                              "r" (val), "r" (addr));
240 }
241
242 static inline void out_be32(volatile unsigned *addr, int val)
243 {
244         __asm__ __volatile__("sync; stw%U0%X0 %1,%0; sync" : "=m" (*addr) : "r" (val));
245 }
246
247 #ifndef CONFIG_PPC_ISERIES 
248 #include <asm/eeh.h>
249 #endif
250
251 #ifdef __KERNEL__
252 static inline int check_signature(unsigned long io_addr,
253         const unsigned char *signature, int length)
254 {
255         int retval = 0;
256 #ifndef CONFIG_PPC_ISERIES 
257         do {
258                 if (readb(io_addr) != *signature)
259                         goto out;
260                 io_addr++;
261                 signature++;
262                 length--;
263         } while (length);
264         retval = 1;
265 out:
266 #endif
267         return retval;
268 }
269
270 /* Nothing to do */
271
272 #define dma_cache_inv(_start,_size)             do { } while (0)
273 #define dma_cache_wback(_start,_size)           do { } while (0)
274 #define dma_cache_wback_inv(_start,_size)       do { } while (0)
275
276 #endif /* __KERNEL__ */
277
278 #endif /* _PPC64_IO_H */