Annotation of Gnu-Mach/linux/src/include/asm-i386/io.h, revision 1.1.1.2

1.1       root        1: #ifndef _ASM_IO_H
                      2: #define _ASM_IO_H
                      3: 
                      4: /*
                      5:  * This file contains the definitions for the x86 IO instructions
                      6:  * inb/inw/inl/outb/outw/outl and the "string versions" of the same
                      7:  * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
                      8:  * versions of the single-IO instructions (inb_p/inw_p/..).
                      9:  *
                     10:  * This file is not meant to be obfuscating: it's just complicated
                     11:  * to (a) handle it all in a way that makes gcc able to optimize it
                     12:  * as well as possible and (b) trying to avoid writing the same thing
                     13:  * over and over again with slight variations and possibly making a
                     14:  * mistake somewhere.
                     15:  */
                     16: 
                     17: /*
                     18:  * Thanks to James van Artsdalen for a better timing-fix than
                     19:  * the two short jumps: using outb's to a nonexistent port seems
                     20:  * to guarantee better timings even on fast machines.
                     21:  *
                     22:  * On the other hand, I'd like to be sure of a non-existent port:
                     23:  * I feel a bit unsafe about using 0x80 (should be safe, though)
                     24:  *
                     25:  *             Linus
                     26:  */
                     27: 
1.1.1.2 ! root       28: #include <machine/vm_param.h>
        !            29: 
1.1       root       30: #ifdef SLOW_IO_BY_JUMPING
                     31: #define __SLOW_DOWN_IO __asm__ __volatile__("jmp 1f\n1:\tjmp 1f\n1:")
                     32: #else
                     33: #define __SLOW_DOWN_IO __asm__ __volatile__("outb %al,$0x80")
                     34: #endif
                     35: 
                     36: #ifdef REALLY_SLOW_IO
                     37: #define SLOW_DOWN_IO { __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; }
                     38: #else
                     39: #define SLOW_DOWN_IO __SLOW_DOWN_IO
                     40: #endif
                     41: 
                     42: /*
                     43:  * Change virtual addresses to physical addresses and vv.
                     44:  * These are trivial on the 1:1 Linux/i386 mapping (but if we ever
                     45:  * make the kernel segment mapped at 0, we need to do translation
                     46:  * on the i386 as well)
                     47:  */
                     48: extern inline unsigned long virt_to_phys(volatile void * address)
                     49: {
1.1.1.2 ! root       50:        return (unsigned long) _kvtophys(address);
1.1       root       51: }
                     52: 
                     53: extern inline void * phys_to_virt(unsigned long address)
                     54: {
1.1.1.2 ! root       55:        return (void *) phystokv(address);
1.1       root       56: }
                     57: 
                     58: /*
                     59:  * IO bus memory addresses are also 1:1 with the physical address
                     60:  */
                     61: #define virt_to_bus virt_to_phys
                     62: #define bus_to_virt phys_to_virt
                     63: 
                     64: /*
                     65:  * readX/writeX() are used to access memory mapped devices. On some
                     66:  * architectures the memory mapped IO stuff needs to be accessed
                     67:  * differently. On the x86 architecture, we just read/write the
                     68:  * memory location directly.
                     69:  */
                     70: #define readb(addr) (*(volatile unsigned char *) (addr))
                     71: #define readw(addr) (*(volatile unsigned short *) (addr))
                     72: #define readl(addr) (*(volatile unsigned int *) (addr))
                     73: 
                     74: #define writeb(b,addr) ((*(volatile unsigned char *) (addr)) = (b))
                     75: #define writew(b,addr) ((*(volatile unsigned short *) (addr)) = (b))
                     76: #define writel(b,addr) ((*(volatile unsigned int *) (addr)) = (b))
                     77: 
                     78: #define memset_io(a,b,c)       memset((void *)(a),(b),(c))
                     79: #define memcpy_fromio(a,b,c)   memcpy((a),(void *)(b),(c))
                     80: #define memcpy_toio(a,b,c)     memcpy((void *)(a),(b),(c))
                     81: 
                     82: /*
                     83:  * Again, i386 does not require mem IO specific function.
                     84:  */
                     85: 
                     86: #define eth_io_copy_and_sum(a,b,c,d)   eth_copy_and_sum((a),(void *)(b),(c),(d))
                     87: 
                     88: /*
                     89:  * Talk about misusing macros..
                     90:  */
                     91: 
                     92: #define __OUT1(s,x) \
                     93: extern inline void __out##s(unsigned x value, unsigned short port) {
                     94: 
                     95: #define __OUT2(s,s1,s2) \
                     96: __asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
                     97: 
                     98: #define __OUT(s,s1,x) \
                     99: __OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); } \
                    100: __OUT1(s##c,x) __OUT2(s,s1,"") : : "a" (value), "id" (port)); } \
                    101: __OUT1(s##_p,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); SLOW_DOWN_IO; } \
                    102: __OUT1(s##c_p,x) __OUT2(s,s1,"") : : "a" (value), "id" (port)); SLOW_DOWN_IO; }
                    103: 
                    104: #define __IN1(s) \
                    105: extern inline RETURN_TYPE __in##s(unsigned short port) { RETURN_TYPE _v;
                    106: 
                    107: #define __IN2(s,s1,s2) \
                    108: __asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
                    109: 
                    110: #define __IN(s,s1,i...) \
                    111: __IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); return _v; } \
                    112: __IN1(s##c) __IN2(s,s1,"") : "=a" (_v) : "id" (port) ,##i ); return _v; } \
                    113: __IN1(s##_p) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); SLOW_DOWN_IO; return _v; } \
                    114: __IN1(s##c_p) __IN2(s,s1,"") : "=a" (_v) : "id" (port) ,##i ); SLOW_DOWN_IO; return _v; }
                    115: 
                    116: #define __INS(s) \
                    117: extern inline void ins##s(unsigned short port, void * addr, unsigned long count) \
                    118: { __asm__ __volatile__ ("cld ; rep ; ins" #s \
                    119: : "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
                    120: 
                    121: #define __OUTS(s) \
                    122: extern inline void outs##s(unsigned short port, const void * addr, unsigned long count) \
                    123: { __asm__ __volatile__ ("cld ; rep ; outs" #s \
                    124: : "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
                    125: 
                    126: #define RETURN_TYPE unsigned char
                    127: /* __IN(b,"b","0" (0)) */
                    128: __IN(b,"")
                    129: #undef RETURN_TYPE
                    130: #define RETURN_TYPE unsigned short
                    131: /* __IN(w,"w","0" (0)) */
                    132: __IN(w,"")
                    133: #undef RETURN_TYPE
                    134: #define RETURN_TYPE unsigned int
                    135: __IN(l,"")
                    136: #undef RETURN_TYPE
                    137: 
                    138: __OUT(b,"b",char)
                    139: __OUT(w,"w",short)
                    140: __OUT(l,,int)
                    141: 
                    142: __INS(b)
                    143: __INS(w)
                    144: __INS(l)
                    145: 
                    146: __OUTS(b)
                    147: __OUTS(w)
                    148: __OUTS(l)
                    149: 
                    150: /*
                    151:  * Note that due to the way __builtin_constant_p() works, you
                    152:  *  - can't use it inside a inline function (it will never be true)
                    153:  *  - you don't have to worry about side effects within the __builtin..
                    154:  */
                    155: #define outb(val,port) \
                    156: ((__builtin_constant_p((port)) && (port) < 256) ? \
                    157:        __outbc((val),(port)) : \
                    158:        __outb((val),(port)))
                    159: 
                    160: #define inb(port) \
                    161: ((__builtin_constant_p((port)) && (port) < 256) ? \
                    162:        __inbc(port) : \
                    163:        __inb(port))
                    164: 
                    165: #define outb_p(val,port) \
                    166: ((__builtin_constant_p((port)) && (port) < 256) ? \
                    167:        __outbc_p((val),(port)) : \
                    168:        __outb_p((val),(port)))
                    169: 
                    170: #define inb_p(port) \
                    171: ((__builtin_constant_p((port)) && (port) < 256) ? \
                    172:        __inbc_p(port) : \
                    173:        __inb_p(port))
                    174: 
                    175: #define outw(val,port) \
                    176: ((__builtin_constant_p((port)) && (port) < 256) ? \
                    177:        __outwc((val),(port)) : \
                    178:        __outw((val),(port)))
                    179: 
                    180: #define inw(port) \
                    181: ((__builtin_constant_p((port)) && (port) < 256) ? \
                    182:        __inwc(port) : \
                    183:        __inw(port))
                    184: 
                    185: #define outw_p(val,port) \
                    186: ((__builtin_constant_p((port)) && (port) < 256) ? \
                    187:        __outwc_p((val),(port)) : \
                    188:        __outw_p((val),(port)))
                    189: 
                    190: #define inw_p(port) \
                    191: ((__builtin_constant_p((port)) && (port) < 256) ? \
                    192:        __inwc_p(port) : \
                    193:        __inw_p(port))
                    194: 
                    195: #define outl(val,port) \
                    196: ((__builtin_constant_p((port)) && (port) < 256) ? \
                    197:        __outlc((val),(port)) : \
                    198:        __outl((val),(port)))
                    199: 
                    200: #define inl(port) \
                    201: ((__builtin_constant_p((port)) && (port) < 256) ? \
                    202:        __inlc(port) : \
                    203:        __inl(port))
                    204: 
                    205: #define outl_p(val,port) \
                    206: ((__builtin_constant_p((port)) && (port) < 256) ? \
                    207:        __outlc_p((val),(port)) : \
                    208:        __outl_p((val),(port)))
                    209: 
                    210: #define inl_p(port) \
                    211: ((__builtin_constant_p((port)) && (port) < 256) ? \
                    212:        __inlc_p(port) : \
                    213:        __inl_p(port))
                    214: 
                    215: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.