root/include/asm/io.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 #ifndef _ASM_IO_H
   2 #define _ASM_IO_H
   3 
   4 /*
   5  * Thanks to James van Artsdalen for a better timing-fix than
   6  * the two short jumps: using outb's to a nonexistent port seems
   7  * to guarantee better timings even on fast machines.
   8  *
   9  * On the other hand, I'd like to be sure of a non-existent port:
  10  * I feel a bit unsafe about using 0x80 (should be safe, though)
  11  *
  12  *              Linus
  13  */
  14 
  15 #ifdef SLOW_IO_BY_JUMPING
  16 #define __SLOW_DOWN_IO __asm__ __volatile__("jmp 1f\n1:\tjmp 1f\n1:")
  17 #else
  18 #define __SLOW_DOWN_IO __asm__ __volatile__("outb %al,$0x80")
  19 #endif
  20 
  21 #ifdef REALLY_SLOW_IO
  22 #define SLOW_DOWN_IO { __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; }
  23 #else
  24 #define SLOW_DOWN_IO __SLOW_DOWN_IO
  25 #endif
  26 
  27 /*
  28  * Talk about misusing macros..
  29  */
  30 
  31 #define __OUT1(s,x) \
  32 extern inline void __out##s(unsigned x value, unsigned short port) {
  33 
  34 #define __OUT2(s,s1,s2) \
  35 __asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
  36 
  37 #define __OUT(s,s1,x) \
  38 __OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); } \
  39 __OUT1(s##c,x) __OUT2(s,s1,"") : : "a" (value), "i" (port)); } \
  40 __OUT1(s##_p,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); SLOW_DOWN_IO; } \
  41 __OUT1(s##c_p,x) __OUT2(s,s1,"") : : "a" (value), "i" (port)); SLOW_DOWN_IO; }
  42 
  43 #define __IN1(s) \
  44 extern inline unsigned int __in##s(unsigned short port) { unsigned int _v;
  45 
  46 #define __IN2(s,s1,s2) \
  47 __asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
  48 
  49 #define __IN(s,s1,i...) \
  50 __IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); return _v; } \
  51 __IN1(s##c) __IN2(s,s1,"") : "=a" (_v) : "i" (port) ,##i ); return _v; } \
  52 __IN1(s##_p) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); SLOW_DOWN_IO; return _v; } \
  53 __IN1(s##c_p) __IN2(s,s1,"") : "=a" (_v) : "i" (port) ,##i ); SLOW_DOWN_IO; return _v; }
  54 
  55 #define __INS(s) \
  56 extern inline void ins##s(unsigned short port, void * addr, unsigned long count) \
  57 { __asm__ __volatile__ ("cld ; rep ; ins" #s \
  58 : "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
  59 
  60 #define __OUTS(s) \
  61 extern inline void outs##s(unsigned short port, const void * addr, unsigned long count) \
  62 { __asm__ __volatile__ ("cld ; rep ; outs" #s \
  63 : "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
  64 
  65 __IN(b,"b","0" (0))
  66 __IN(w,"w","0" (0))
  67 __IN(l,"")
  68 
  69 __OUT(b,"b",char)
  70 __OUT(w,"w",short)
  71 __OUT(l,,int)
  72 
  73 __INS(b)
  74 __INS(w)
  75 __INS(l)
  76 
  77 __OUTS(b)
  78 __OUTS(w)
  79 __OUTS(l)
  80 
  81 /*
  82  * Note that due to the way __builtin_constant_p() works, you
  83  *  - can't use it inside a inline function (it will never be true)
  84  *  - you don't have to worry about side effects within the __builtin..
  85  */
  86 #define outb(val,port) \
  87 ((__builtin_constant_p((port)) && (port) < 256) ? \
  88         __outbc((val),(port)) : \
  89         __outb((val),(port)))
  90 
  91 #define inb(port) \
  92 ((__builtin_constant_p((port)) && (port) < 256) ? \
  93         __inbc(port) : \
  94         __inb(port))
  95 
  96 #define outb_p(val,port) \
  97 ((__builtin_constant_p((port)) && (port) < 256) ? \
  98         __outbc_p((val),(port)) : \
  99         __outb_p((val),(port)))
 100 
 101 #define inb_p(port) \
 102 ((__builtin_constant_p((port)) && (port) < 256) ? \
 103         __inbc_p(port) : \
 104         __inb_p(port))
 105 
 106 #define outw(val,port) \
 107 ((__builtin_constant_p((port)) && (port) < 256) ? \
 108         __outwc((val),(port)) : \
 109         __outw((val),(port)))
 110 
 111 #define inw(port) \
 112 ((__builtin_constant_p((port)) && (port) < 256) ? \
 113         __inwc(port) : \
 114         __inw(port))
 115 
 116 #define outw_p(val,port) \
 117 ((__builtin_constant_p((port)) && (port) < 256) ? \
 118         __outwc_p((val),(port)) : \
 119         __outw_p((val),(port)))
 120 
 121 #define inw_p(port) \
 122 ((__builtin_constant_p((port)) && (port) < 256) ? \
 123         __inwc_p(port) : \
 124         __inw_p(port))
 125 
 126 #define outl(val,port) \
 127 ((__builtin_constant_p((port)) && (port) < 256) ? \
 128         __outlc((val),(port)) : \
 129         __outl((val),(port)))
 130 
 131 #define inl(port) \
 132 ((__builtin_constant_p((port)) && (port) < 256) ? \
 133         __inlc(port) : \
 134         __inl(port))
 135 
 136 #define outl_p(val,port) \
 137 ((__builtin_constant_p((port)) && (port) < 256) ? \
 138         __outlc_p((val),(port)) : \
 139         __outl_p((val),(port)))
 140 
 141 #define inl_p(port) \
 142 ((__builtin_constant_p((port)) && (port) < 256) ? \
 143         __inlc_p(port) : \
 144         __inl_p(port))
 145 
 146 #endif

/* [previous][next][first][last][top][bottom][index][help] */