also update spec file ...
[linux-flexiantxendom0-3.2.10.git] / include / asm-mips64 / io.h
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 1994, 1995 Waldorf GmbH
7  * Copyright (C) 1994 - 2000 Ralf Baechle
8  * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
9  */
10 #ifndef _ASM_IO_H
11 #define _ASM_IO_H
12
13 #include <linux/config.h>
14 #include <asm/addrspace.h>
15 #include <asm/page.h>
16 #include <asm/byteorder.h>
17
18 #ifdef CONFIG_DECSTATION
19 #include <asm/dec/io.h>
20 #endif
21
22 #ifdef CONFIG_MIPS_ATLAS
23 #include <asm/mips-boards/io.h>
24 #endif
25
26 #ifdef CONFIG_MIPS_MALTA
27 #include <asm/mips-boards/io.h>
28 #endif
29
30 #ifdef CONFIG_MIPS_SEAD
31 #include <asm/mips-boards/io.h>
32 #endif
33
34 #ifdef CONFIG_SGI_IP22
35 #include <asm/sgi/io.h>
36 #endif
37
38 #ifdef CONFIG_SGI_IP27
39 #include <asm/sn/io.h>
40 #endif
41
42 #ifdef CONFIG_SGI_IP32
43 #include <asm/ip32/io.h>
44 #endif
45
46 #ifdef CONFIG_SIBYTE_SB1xxx_SOC
47 #include <asm/sibyte/io.h>
48 #endif
49
50 #ifdef CONFIG_SNI_RM200_PCI
51 #include <asm/sni.h>
52 #endif
53
54 #ifdef CONFIG_SGI_IP27
55 extern unsigned long bus_to_baddr[256];
56
57 #define bus_to_baddr(bus, addr) (bus_to_baddr[(bus)->number] + (addr))
58 #define baddr_to_bus(bus, addr) ((addr) - bus_to_baddr[(bus)->number])
59 #else
60 #define bus_to_baddr(bus, addr) (addr)
61 #define baddr_to_bus(bus, addr) (addr)
62 #endif
63
64 /*
65  * Slowdown I/O port space accesses for antique hardware.
66  */
67 #undef CONF_SLOWDOWN_IO
68
69 /*
70  * Sane hardware offers swapping of I/O space accesses in hardware; less
71  * sane hardware forces software to fiddle with this ...
72  */
73 #if defined(CONFIG_SWAP_IO_SPACE) && defined(__MIPSEB__)
74
75 #define __ioswab8(x) (x)
76
77 #ifdef CONFIG_SGI_IP22
78 /*
79  * IP22 seems braindead enough to swap 16bits values in hardware, but
80  * not 32bits.  Go figure... Can't tell without documentation.
81  */
82 #define __ioswab16(x) (x)
83 #else
84 #define __ioswab16(x) swab16(x)
85 #endif
86 #define __ioswab32(x) swab32(x)
87
88 #else
89
90 #define __ioswab8(x) (x)
91 #define __ioswab16(x) (x)
92 #define __ioswab32(x) (x)
93
94 #endif
95
96 /*
97  * Change "struct page" to physical address.
98  */
99 #define page_to_phys(page)      ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT)
100
101 /*
102  * ioremap     -   map bus memory into CPU space
103  * @offset:    bus address of the memory
104  * @size:      size of the resource to map
105  *
106  * ioremap performs a platform specific sequence of operations to
107  * make bus memory CPU accessible via the readb/readw/readl/writeb/
108  * writew/writel functions and the other mmio helpers. The returned
109  * address is not guaranteed to be usable directly as a virtual
110  * address.
111  */
112 static inline void * ioremap(unsigned long offset, unsigned long size)
113 {
114         return (void *) (IO_SPACE_BASE | offset);
115 }
116
117 /*
118  * ioremap_nocache     -   map bus memory into CPU space
119  * @offset:    bus address of the memory
120  * @size:      size of the resource to map
121  *
122  * ioremap_nocache performs a platform specific sequence of operations to
123  * make bus memory CPU accessible via the readb/readw/readl/writeb/
124  * writew/writel functions and the other mmio helpers. The returned
125  * address is not guaranteed to be usable directly as a virtual
126  * address.
127  *
128  * This version of ioremap ensures that the memory is marked uncachable
129  * on the CPU as well as honouring existing caching rules from things like
130  * the PCI bus. Note that there are other caches and buffers on many
131  * busses. In paticular driver authors should read up on PCI writes
132  *
133  * It's useful if some control registers are in such an area and
134  * write combining or read caching is not desirable:
135  */
136 static inline void * ioremap_nocache (unsigned long offset, unsigned long size)
137 {
138         return (void *) (IO_SPACE_BASE | offset);
139 }
140
141 static inline void iounmap(void *addr)
142 {
143 }
144
145 #define readb(addr)             (*(volatile unsigned char *)(addr))
146 #define readw(addr)             __ioswab16((*(volatile unsigned short *)(addr)))
147 #define readl(addr)             __ioswab32((*(volatile unsigned int *)(addr)))
148
149 #define __raw_readb(addr)       (*(volatile unsigned char *)(addr))
150 #define __raw_readw(addr)       (*(volatile unsigned short *)(addr))
151 #define __raw_readl(addr)       (*(volatile unsigned int *)(addr))
152
153 #define writeb(b,addr) ((*(volatile unsigned char *)(addr)) = (__ioswab8(b)))
154 #define writew(b,addr) ((*(volatile unsigned short *)(addr)) = (__ioswab16(b)))
155 #define writel(b,addr) ((*(volatile unsigned int *)(addr)) = (__ioswab32(b)))
156
157 #define __raw_writeb(b,addr)    ((*(volatile unsigned char *)(addr)) = (b))
158 #define __raw_writew(w,addr)    ((*(volatile unsigned short *)(addr)) = (w))
159 #define __raw_writel(l,addr)    ((*(volatile unsigned int *)(addr)) = (l))
160
161 #define memset_io(a,b,c)        memset((void *)(a),(b),(c))
162 #define memcpy_fromio(a,b,c)    memcpy((a),(void *)(b),(c))
163 #define memcpy_toio(a,b,c)      memcpy((void *)(a),(b),(c))
164
165 /* The ISA versions are supplied by system specific code */
166
167 /*
168  * On MIPS I/O ports are memory mapped, so we access them using normal
169  * load/store instructions. mips_io_port_base is the virtual address to
170  * which all ports are being mapped.  For sake of efficiency some code
171  * assumes that this is an address that can be loaded with a single lui
172  * instruction, so the lower 16 bits must be zero.  Should be true on
173  * on any sane architecture; generic code does not use this assumption.
174  */
175 extern const unsigned long mips_io_port_base;
176
177 #define set_io_port_base(base)  \
178         do { * (unsigned long *) &mips_io_port_base = (base); } while (0)
179
180 #define __SLOW_DOWN_IO \
181         __asm__ __volatile__( \
182                 "sb\t$0,0x80(%0)" \
183                 : : "r" (mips_io_port_base));
184
185 #ifdef CONF_SLOWDOWN_IO
186 #ifdef REALLY_SLOW_IO
187 #define SLOW_DOWN_IO { __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; }
188 #else
189 #define SLOW_DOWN_IO __SLOW_DOWN_IO
190 #endif
191 #else
192 #define SLOW_DOWN_IO
193 #endif
194
195 /*
196  *     virt_to_phys    -       map virtual addresses to physical
197  *     @address: address to remap
198  *
199  *     The returned physical address is the physical (CPU) mapping for
200  *     the memory address given. It is only valid to use this function on
201  *     addresses directly mapped or allocated via kmalloc.
202  *
203  *     This function does not give bus mappings for DMA transfers. In
204  *     almost all conceivable cases a device driver should not be using
205  *     this function
206  */
207 static inline unsigned long virt_to_phys(volatile void * address)
208 {
209         return (unsigned long)address - PAGE_OFFSET;
210 }
211
212 /*
213  *     phys_to_virt    -       map physical address to virtual
214  *     @address: address to remap
215  *
216  *     The returned virtual address is a current CPU mapping for
217  *     the memory address given. It is only valid to use this function on
218  *     addresses that have a kernel mapping
219  *
220  *     This function does not handle bus mappings for DMA transfers. In
221  *     almost all conceivable cases a device driver should not be using
222  *     this function
223  */
224 static inline void * phys_to_virt(unsigned long address)
225 {
226         return (void *)(address + PAGE_OFFSET);
227 }
228
229 /*
230  * ISA I/O bus memory addresses are 1:1 with the physical address.
231  */
232 static inline unsigned long isa_virt_to_bus(volatile void * address)
233 {
234         return PHYSADDR(address);
235 }
236
237 static inline void * isa_bus_to_virt(unsigned long address)
238 {
239         return (void *)KSEG0ADDR(address);
240 }
241
242 /*
243  * However PCI ones are not necessarily 1:1 and therefore these interfaces
244  * are forbidden in portable PCI drivers.
245  *
246  * Allow them for x86 for legacy drivers, though.
247  */
248 #define virt_to_bus virt_to_phys
249 #define bus_to_virt phys_to_virt
250
251 /* This is too simpleminded for more sophisticated than dumb hardware ...  */
252 #define page_to_bus page_to_phys
253
254 /*
255  * isa_slot_offset is the address where E(ISA) busaddress 0 is mapped
256  * for the processor.  This implies the assumption that there is only
257  * one of these busses.
258  */
259 extern unsigned long isa_slot_offset;
260
261 /*
262  * ISA space is 'always mapped' on currently supported MIPS systems, no need
263  * to explicitly ioremap() it. The fact that the ISA IO space is mapped
264  * to PAGE_OFFSET is pure coincidence - it does not mean ISA values
265  * are physical addresses. The following constant pointer can be
266  * used as the IO-area pointer (it can be iounmapped as well, so the
267  * analogy with PCI is quite large):
268  */
269 #define __ISA_IO_base ((char *)(isa_slot_offset))
270
271 #define isa_readb(a) readb(__ISA_IO_base + (a))
272 #define isa_readw(a) readw(__ISA_IO_base + (a))
273 #define isa_readl(a) readl(__ISA_IO_base + (a))
274 #define isa_writeb(b,a) writeb(b,__ISA_IO_base + (a))
275 #define isa_writew(w,a) writew(w,__ISA_IO_base + (a))
276 #define isa_writel(l,a) writel(l,__ISA_IO_base + (a))
277 #define isa_memset_io(a,b,c)            memset_io(__ISA_IO_base + (a),(b),(c))
278 #define isa_memcpy_fromio(a,b,c)        memcpy_fromio((a),__ISA_IO_base + (b),(c))
279 #define isa_memcpy_toio(a,b,c)          memcpy_toio(__ISA_IO_base + (a),(b),(c))
280
281 /*
282  * We don't have csum_partial_copy_fromio() yet, so we cheat here and
283  * just copy it. The net code will then do the checksum later.
284  */
285 #define eth_io_copy_and_sum(skb,src,len,unused) memcpy_fromio((skb)->data,(src),(len))
286
287 /**
288  *     check_signature         -       find BIOS signatures
289  *     @io_addr: mmio address to check
290  *     @signature:  signature block
291  *     @length: length of signature
292  *
293  *     Perform a signature comparison with the mmio address io_addr. This
294  *     address should have been obtained by ioremap.
295  *     Returns 1 on a match.
296  */
297 static inline int check_signature(unsigned long io_addr,
298         const unsigned char *signature, int length)
299 {
300         int retval = 0;
301         do {
302                 if (readb(io_addr) != *signature)
303                         goto out;
304                 io_addr++;
305                 signature++;
306                 length--;
307         } while (length);
308         retval = 1;
309 out:
310         return retval;
311 }
312
313 /*
314  *     isa_check_signature             -       find BIOS signatures
315  *     @io_addr: mmio address to check
316  *     @signature:  signature block
317  *     @length: length of signature
318  *
319  *     Perform a signature comparison with the ISA mmio address io_addr.
320  *     Returns 1 on a match.
321  *
322  *     This function is deprecated. New drivers should use ioremap and
323  *     check_signature.
324  */
325 #define isa_check_signature(io, s, l)   check_signature(i,s,l)
326
327 #define outb(val,port)                                                  \
328 do {                                                                    \
329         *(volatile u8 *)(mips_io_port_base + (port)) = __ioswab8(val);  \
330 } while(0)
331
332 #define outw(val,port)                                                  \
333 do {                                                                    \
334         *(volatile u16 *)(mips_io_port_base + (port)) = __ioswab16(val);\
335 } while(0)
336
337 #define outl(val,port)                                                  \
338 do {                                                                    \
339         *(volatile u32 *)(mips_io_port_base + (port)) = __ioswab32(val);\
340 } while(0)
341
342 #define outb_p(val,port)                                                \
343 do {                                                                    \
344         *(volatile u8 *)(mips_io_port_base + (port)) = __ioswab8(val);  \
345         SLOW_DOWN_IO;                                                   \
346 } while(0)
347
348 #define outw_p(val,port)                                                \
349 do {                                                                    \
350         *(volatile u16 *)(mips_io_port_base + (port)) = __ioswab16(val);\
351         SLOW_DOWN_IO;                                                   \
352 } while(0)
353
354 #define outl_p(val,port)                                                \
355 do {                                                                    \
356         *(volatile u32 *)(mips_io_port_base + (port)) = __ioswab32(val);\
357         SLOW_DOWN_IO;                                                   \
358 } while(0)
359
360 static inline unsigned char inb(unsigned long port)
361 {
362         return __ioswab8(*(volatile u8 *)(mips_io_port_base + port));
363 }
364
365 static inline unsigned short inw(unsigned long port)
366 {
367         return __ioswab16(*(volatile u16 *)(mips_io_port_base + port));
368 }
369
370 static inline unsigned int inl(unsigned long port)
371 {
372         return __ioswab32(*(volatile u32 *)(mips_io_port_base + port));
373 }
374
375 static inline unsigned char inb_p(unsigned long port)
376 {
377         u8 __val;
378
379         __val = *(volatile u8 *)(mips_io_port_base + port);
380         SLOW_DOWN_IO;
381
382         return __ioswab8(__val);
383 }
384
385 static inline unsigned short inw_p(unsigned long port)
386 {
387         u16 __val;
388
389         __val = *(volatile u16 *)(mips_io_port_base + port);
390         SLOW_DOWN_IO;
391
392         return __ioswab16(__val);
393 }
394
395 static inline unsigned int inl_p(unsigned long port)
396 {
397         u32 __val;
398
399         __val = *(volatile u32 *)(mips_io_port_base + port);
400         SLOW_DOWN_IO;
401         return __ioswab32(__val);
402 }
403
404 static inline void outsb(unsigned long port, void *addr, unsigned int count)
405 {
406         while (count--) {
407                 outb(*(u8 *)addr, port);
408                 addr++;
409         }
410 }
411
412 static inline void insb(unsigned long port, void *addr, unsigned int count)
413 {
414         while (count--) {
415                 *(u8 *)addr = inb(port);
416                 addr++;
417         }
418 }
419
420 static inline void outsw(unsigned long port, void *addr, unsigned int count)
421 {
422         while (count--) {
423                 outw(*(u16 *)addr, port);
424                 addr += 2;
425         }
426 }
427
428 static inline void insw(unsigned long port, void *addr, unsigned int count)
429 {
430         while (count--) {
431                 *(u16 *)addr = inw(port);
432                 addr += 2;
433         }
434 }
435
436 static inline void outsl(unsigned long port, void *addr, unsigned int count)
437 {
438         while (count--) {
439                 outl(*(u32 *)addr, port);
440                 addr += 4;
441         }
442 }
443
444 static inline void insl(unsigned long port, void *addr, unsigned int count)
445 {
446         while (count--) {
447                 *(u32 *)addr = inl(port);
448                 addr += 4;
449         }
450 }
451
452 /*
453  * The caches on some architectures aren't dma-coherent and have need to
454  * handle this in software.  There are three types of operations that
455  * can be applied to dma buffers.
456  *
457  *  - dma_cache_wback_inv(start, size) makes caches and coherent by
458  *    writing the content of the caches back to memory, if necessary.
459  *    The function also invalidates the affected part of the caches as
460  *    necessary before DMA transfers from outside to memory.
461  *  - dma_cache_wback(start, size) makes caches and coherent by
462  *    writing the content of the caches back to memory, if necessary.
463  *    The function also invalidates the affected part of the caches as
464  *    necessary before DMA transfers from outside to memory.
465  *  - dma_cache_inv(start, size) invalidates the affected parts of the
466  *    caches.  Dirty lines of the caches may be written back or simply
467  *    be discarded.  This operation is necessary before dma operations
468  *    to the memory.
469  */
470 #ifdef CONFIG_NONCOHERENT_IO
471
472 extern void (*_dma_cache_wback_inv)(unsigned long start, unsigned long size);
473 extern void (*_dma_cache_wback)(unsigned long start, unsigned long size);
474 extern void (*_dma_cache_inv)(unsigned long start, unsigned long size);
475
476 #define dma_cache_wback_inv(start,size) _dma_cache_wback_inv(start,size)
477 #define dma_cache_wback(start,size)     _dma_cache_wback(start,size)
478 #define dma_cache_inv(start,size)       _dma_cache_inv(start,size)
479
480 #else /* Sane hardware */
481
482 #define dma_cache_wback_inv(start,size) \
483         do { (void) (start); (void) (size); } while (0)
484 #define dma_cache_wback(start,size)     \
485         do { (void) (start); (void) (size); } while (0)
486 #define dma_cache_inv(start,size)       \
487         do { (void) (start); (void) (size); } while (0)
488
489 #endif /* CONFIG_NONCOHERENT_IO */
490
491 #endif /* _ASM_IO_H */