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