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