Home | History | Annotate | Download | only in netboot
      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 
     28 #ifdef	SLOW_IO_BY_JUMPING
     29 #define __SLOW_DOWN_IO __asm__ __volatile__("jmp 1f\n1:\tjmp 1f\n1:")
     30 #else
     31 #define __SLOW_DOWN_IO __asm__ __volatile__("outb %al,$0x80")
     32 #endif
     33 
     34 #ifdef	REALLY_SLOW_IO
     35 #define SLOW_DOWN_IO { __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; }
     36 #else
     37 #define SLOW_DOWN_IO __SLOW_DOWN_IO
     38 #endif
     39 
     40 /*
     41  * readX/writeX() are used to access memory mapped devices. On some
     42  * architectures the memory mapped IO stuff needs to be accessed
     43  * differently. On the x86 architecture, we just read/write the
     44  * memory location directly.
     45  */
     46 #define readb(addr) (*(volatile unsigned char *) (addr))
     47 #define readw(addr) (*(volatile unsigned short *) (addr))
     48 #define readl(addr) (*(volatile unsigned int *) (addr))
     49 
     50 #define writeb(b,addr) ((*(volatile unsigned char *) (addr)) = (b))
     51 #define writew(b,addr) ((*(volatile unsigned short *) (addr)) = (b))
     52 #define writel(b,addr) ((*(volatile unsigned int *) (addr)) = (b))
     53 
     54 #define memset_io(a,b,c)	memset((void *)(a),(b),(c))
     55 #define memcpy_fromio(a,b,c)	memcpy((a),(void *)(b),(c))
     56 #define memcpy_toio(a,b,c)	memcpy((void *)(a),(b),(c))
     57 
     58 /*
     59  * Again, i386 does not require mem IO specific function.
     60  */
     61 
     62 #define eth_io_copy_and_sum(a,b,c,d)	eth_copy_and_sum((a),(void *)(b),(c),(d))
     63 
     64 /*
     65  * Talk about misusing macros..
     66  */
     67 
     68 #define __OUT1(s,x) \
     69 extern void __out##s(unsigned x value, unsigned short port); \
     70 extern inline void __out##s(unsigned x value, unsigned short port) {
     71 
     72 #define __OUT2(s,s1,s2) \
     73 __asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
     74 
     75 #define __OUT(s,s1,x) \
     76 __OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); } \
     77 __OUT1(s##c,x) __OUT2(s,s1,"") : : "a" (value), "id" (port)); } \
     78 __OUT1(s##_p,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); SLOW_DOWN_IO; } \
     79 __OUT1(s##c_p,x) __OUT2(s,s1,"") : : "a" (value), "id" (port)); SLOW_DOWN_IO; }
     80 
     81 #define __IN1(s,x) \
     82 extern unsigned x __in##s(unsigned short port); \
     83 extern inline unsigned x __in##s(unsigned short port) { unsigned x _v;
     84 
     85 #define __IN2(s,s1,s2) \
     86 __asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
     87 
     88 #define __IN(s,s1,x,i...) \
     89 __IN1(s,x) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); return _v; } \
     90 __IN1(s##c,x) __IN2(s,s1,"") : "=a" (_v) : "id" (port) ,##i ); return _v; } \
     91 __IN1(s##_p,x) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); SLOW_DOWN_IO; return _v; } \
     92 __IN1(s##c_p,x) __IN2(s,s1,"") : "=a" (_v) : "id" (port) ,##i ); SLOW_DOWN_IO; return _v; }
     93 
     94 #define __INS(s) \
     95 extern void ins##s(unsigned short port, void * addr, unsigned long count); \
     96 extern inline void ins##s(unsigned short port, void * addr, unsigned long count) \
     97 { __asm__ __volatile__ ("cld ; rep ; ins" #s \
     98 : "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
     99 
    100 #define __OUTS(s) \
    101 extern void outs##s(unsigned short port, const void * addr, unsigned long  count); \
    102 extern inline void outs##s(unsigned short port, const void * addr, unsigned long count) \
    103 { __asm__ __volatile__ ("cld ; rep ; outs" #s \
    104 : "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
    105 
    106 __IN(b,"", char)
    107 __IN(w,"",short)
    108 __IN(l,"", long)
    109 
    110 __OUT(b,"b",char)
    111 __OUT(w,"w",short)
    112 __OUT(l,,int)
    113 
    114 __INS(b)
    115 __INS(w)
    116 __INS(l)
    117 
    118 __OUTS(b)
    119 __OUTS(w)
    120 __OUTS(l)
    121 
    122 /*
    123  * Note that due to the way __builtin_constant_p() works, you
    124  *  - can't use it inside a inline function (it will never be true)
    125  *  - you don't have to worry about side effects within the __builtin..
    126  */
    127 #define outb(val,port) \
    128 ((__builtin_constant_p((port)) && (port) < 256) ? \
    129 	__outbc((val),(port)) : \
    130 	__outb((val),(port)))
    131 
    132 #define inb(port) \
    133 ((__builtin_constant_p((port)) && (port) < 256) ? \
    134 	__inbc(port) : \
    135 	__inb(port))
    136 
    137 #define outb_p(val,port) \
    138 ((__builtin_constant_p((port)) && (port) < 256) ? \
    139 	__outbc_p((val),(port)) : \
    140 	__outb_p((val),(port)))
    141 
    142 #define inb_p(port) \
    143 ((__builtin_constant_p((port)) && (port) < 256) ? \
    144 	__inbc_p(port) : \
    145 	__inb_p(port))
    146 
    147 #define outw(val,port) \
    148 ((__builtin_constant_p((port)) && (port) < 256) ? \
    149 	__outwc((val),(port)) : \
    150 	__outw((val),(port)))
    151 
    152 #define inw(port) \
    153 ((__builtin_constant_p((port)) && (port) < 256) ? \
    154 	__inwc(port) : \
    155 	__inw(port))
    156 
    157 #define outw_p(val,port) \
    158 ((__builtin_constant_p((port)) && (port) < 256) ? \
    159 	__outwc_p((val),(port)) : \
    160 	__outw_p((val),(port)))
    161 
    162 #define inw_p(port) \
    163 ((__builtin_constant_p((port)) && (port) < 256) ? \
    164 	__inwc_p(port) : \
    165 	__inw_p(port))
    166 
    167 #define outl(val,port) \
    168 ((__builtin_constant_p((port)) && (port) < 256) ? \
    169 	__outlc((val),(port)) : \
    170 	__outl((val),(port)))
    171 
    172 #define inl(port) \
    173 ((__builtin_constant_p((port)) && (port) < 256) ? \
    174 	__inlc(port) : \
    175 	__inl(port))
    176 
    177 #define outl_p(val,port) \
    178 ((__builtin_constant_p((port)) && (port) < 256) ? \
    179 	__outlc_p((val),(port)) : \
    180 	__outl_p((val),(port)))
    181 
    182 #define inl_p(port) \
    183 ((__builtin_constant_p((port)) && (port) < 256) ? \
    184 	__inlc_p(port) : \
    185 	__inl_p(port))
    186 
    187 #endif
    188