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  * 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  * Talk about misusing macros..
  42  */
  43 
  44 #define __OUT1(s,x) \
  45 extern inline void __out##s(unsigned x value, unsigned short port) {
  46 
  47 #define __OUT2(s,s1,s2) \
  48 __asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
  49 
  50 #define __OUT(s,s1,x) \
  51 __OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); } \
  52 __OUT1(s##c,x) __OUT2(s,s1,"") : : "a" (value), "i" (port)); } \
  53 __OUT1(s##_p,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); SLOW_DOWN_IO; } \
  54 __OUT1(s##c_p,x) __OUT2(s,s1,"") : : "a" (value), "i" (port)); SLOW_DOWN_IO; }
  55 
  56 #define __IN1(s) \
  57 extern inline unsigned int __in##s(unsigned short port) { unsigned int _v;
  58 
  59 #define __IN2(s,s1,s2) \
  60 __asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
  61 
  62 #define __IN(s,s1,i...) \
  63 __IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); return _v; } \
  64 __IN1(s##c) __IN2(s,s1,"") : "=a" (_v) : "i" (port) ,##i ); return _v; } \
  65 __IN1(s##_p) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); SLOW_DOWN_IO; return _v; } \
  66 __IN1(s##c_p) __IN2(s,s1,"") : "=a" (_v) : "i" (port) ,##i ); SLOW_DOWN_IO; return _v; }
  67 
  68 #define __INS(s) \
  69 extern inline void ins##s(unsigned short port, void * addr, unsigned long count) \
  70 { __asm__ __volatile__ ("cld ; rep ; ins" #s \
  71 : "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
  72 
  73 #define __OUTS(s) \
  74 extern inline void outs##s(unsigned short port, const void * addr, unsigned long count) \
  75 { __asm__ __volatile__ ("cld ; rep ; outs" #s \
  76 : "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
  77 
  78 __IN(b,"b","0" (0))
  79 __IN(w,"w","0" (0))
  80 __IN(l,"")
  81 
  82 __OUT(b,"b",char)
  83 __OUT(w,"w",short)
  84 __OUT(l,,int)
  85 
  86 __INS(b)
  87 __INS(w)
  88 __INS(l)
  89 
  90 __OUTS(b)
  91 __OUTS(w)
  92 __OUTS(l)
  93 
  94 /*
  95  * Note that due to the way __builtin_constant_p() works, you
  96  *  - can't use it inside a inline function (it will never be true)
  97  *  - you don't have to worry about side effects within the __builtin..
  98  */
  99 #define outb(val,port) \
 100 ((__builtin_constant_p((port)) && (port) < 256) ? \
 101         __outbc((val),(port)) : \
 102         __outb((val),(port)))
 103 
 104 #define inb(port) \
 105 ((__builtin_constant_p((port)) && (port) < 256) ? \
 106         __inbc(port) : \
 107         __inb(port))
 108 
 109 #define outb_p(val,port) \
 110 ((__builtin_constant_p((port)) && (port) < 256) ? \
 111         __outbc_p((val),(port)) : \
 112         __outb_p((val),(port)))
 113 
 114 #define inb_p(port) \
 115 ((__builtin_constant_p((port)) && (port) < 256) ? \
 116         __inbc_p(port) : \
 117         __inb_p(port))
 118 
 119 #define outw(val,port) \
 120 ((__builtin_constant_p((port)) && (port) < 256) ? \
 121         __outwc((val),(port)) : \
 122         __outw((val),(port)))
 123 
 124 #define inw(port) \
 125 ((__builtin_constant_p((port)) && (port) < 256) ? \
 126         __inwc(port) : \
 127         __inw(port))
 128 
 129 #define outw_p(val,port) \
 130 ((__builtin_constant_p((port)) && (port) < 256) ? \
 131         __outwc_p((val),(port)) : \
 132         __outw_p((val),(port)))
 133 
 134 #define inw_p(port) \
 135 ((__builtin_constant_p((port)) && (port) < 256) ? \
 136         __inwc_p(port) : \
 137         __inw_p(port))
 138 
 139 #define outl(val,port) \
 140 ((__builtin_constant_p((port)) && (port) < 256) ? \
 141         __outlc((val),(port)) : \
 142         __outl((val),(port)))
 143 
 144 #define inl(port) \
 145 ((__builtin_constant_p((port)) && (port) < 256) ? \
 146         __inlc(port) : \
 147         __inl(port))
 148 
 149 #define outl_p(val,port) \
 150 ((__builtin_constant_p((port)) && (port) < 256) ? \
 151         __outlc_p((val),(port)) : \
 152         __outl_p((val),(port)))
 153 
 154 #define inl_p(port) \
 155 ((__builtin_constant_p((port)) && (port) < 256) ? \
 156         __inlc_p(port) : \
 157         __inl_p(port))
 158 
 159 #endif

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