root/include/asm-i386/io.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. virt_to_phys
  2. phys_to_virt
  3. readb
  4. readw
  5. readl
  6. writeb
  7. writew
  8. writel

   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  * Change virtual addresses to physical addresses and vv.
  42  * These are trivial on the 1:1 Linux/i386 mapping (but if we ever
  43  * make the kernel segment mapped at 0, we need to do translation
  44  * on the i386 as well)
  45  */
  46 extern inline unsigned long virt_to_phys(void * address)
     /* [previous][next][first][last][top][bottom][index][help] */
  47 {
  48         return (unsigned long) address;
  49 }
  50 
  51 extern inline void * phys_to_virt(unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
  52 {
  53         return (void *) address;
  54 }
  55 
  56 /*
  57  * IO bus memory addresses are also 1:1 with the physical address
  58  */
  59 #define virt_to_bus virt_to_phys
  60 #define bus_to_virt phys_to_virt
  61 
  62 /*
  63  * readX/writeX() are used to access memory mapped devices. On some
  64  * architectures the memory mapped IO stuff needs to be accessed
  65  * differently. On the x86 architecture, we just read/write the
  66  * memory location directly.
  67  */
  68 extern inline unsigned long readb(unsigned long addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  69 { return *(unsigned char *) addr; }
  70 
  71 extern inline unsigned long readw(unsigned long addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  72 { return *(unsigned short *) addr; }
  73 
  74 extern inline unsigned long readl(unsigned long addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  75 { return *(unsigned int *) addr; }
  76 
  77 extern inline void writeb(unsigned char b, unsigned long addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  78 { *(unsigned char *) addr = b; }
  79 
  80 extern inline void writew(unsigned short b, unsigned long addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  81 { *(unsigned short *) addr = b; }
  82 
  83 extern inline void writel(unsigned int b, unsigned long addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  84 { *(unsigned int *) addr = b; }
  85 
  86 #define memset_io(a,b,c)        memset((void *)(a),(b),(c))
  87 #define memcpy_fromio(a,b,c)    memcpy((a),(void *)(b),(c))
  88 #define memcpy_toio(a,b,c)      memcpy((void *)(a),(b),(c))
  89 
  90 /*
  91  * Talk about misusing macros..
  92  */
  93 
  94 #define __OUT1(s,x) \
  95 extern inline void __out##s(unsigned x value, unsigned short port) {
  96 
  97 #define __OUT2(s,s1,s2) \
  98 __asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
  99 
 100 #define __OUT(s,s1,x) \
 101 __OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); } \
 102 __OUT1(s##c,x) __OUT2(s,s1,"") : : "a" (value), "i" (port)); } \
 103 __OUT1(s##_p,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); SLOW_DOWN_IO; } \
 104 __OUT1(s##c_p,x) __OUT2(s,s1,"") : : "a" (value), "i" (port)); SLOW_DOWN_IO; }
 105 
 106 #define __IN1(s) \
 107 extern inline unsigned int __in##s(unsigned short port) { unsigned int _v;
 108 
 109 #define __IN2(s,s1,s2) \
 110 __asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
 111 
 112 #define __IN(s,s1,i...) \
 113 __IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); return _v; } \
 114 __IN1(s##c) __IN2(s,s1,"") : "=a" (_v) : "i" (port) ,##i ); return _v; } \
 115 __IN1(s##_p) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); SLOW_DOWN_IO; return _v; } \
 116 __IN1(s##c_p) __IN2(s,s1,"") : "=a" (_v) : "i" (port) ,##i ); SLOW_DOWN_IO; return _v; }
 117 
 118 #define __INS(s) \
 119 extern inline void ins##s(unsigned short port, void * addr, unsigned long count) \
 120 { __asm__ __volatile__ ("cld ; rep ; ins" #s \
 121 : "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
 122 
 123 #define __OUTS(s) \
 124 extern inline void outs##s(unsigned short port, const void * addr, unsigned long count) \
 125 { __asm__ __volatile__ ("cld ; rep ; outs" #s \
 126 : "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
 127 
 128 __IN(b,"b","0" (0))
 129 __IN(w,"w","0" (0))
 130 __IN(l,"")
 131 
 132 __OUT(b,"b",char)
 133 __OUT(w,"w",short)
 134 __OUT(l,,int)
 135 
 136 __INS(b)
 137 __INS(w)
 138 __INS(l)
 139 
 140 __OUTS(b)
 141 __OUTS(w)
 142 __OUTS(l)
 143 
 144 /*
 145  * Note that due to the way __builtin_constant_p() works, you
 146  *  - can't use it inside a inline function (it will never be true)
 147  *  - you don't have to worry about side effects within the __builtin..
 148  */
 149 #define outb(val,port) \
 150 ((__builtin_constant_p((port)) && (port) < 256) ? \
 151         __outbc((val),(port)) : \
 152         __outb((val),(port)))
 153 
 154 #define inb(port) \
 155 ((__builtin_constant_p((port)) && (port) < 256) ? \
 156         __inbc(port) : \
 157         __inb(port))
 158 
 159 #define outb_p(val,port) \
 160 ((__builtin_constant_p((port)) && (port) < 256) ? \
 161         __outbc_p((val),(port)) : \
 162         __outb_p((val),(port)))
 163 
 164 #define inb_p(port) \
 165 ((__builtin_constant_p((port)) && (port) < 256) ? \
 166         __inbc_p(port) : \
 167         __inb_p(port))
 168 
 169 #define outw(val,port) \
 170 ((__builtin_constant_p((port)) && (port) < 256) ? \
 171         __outwc((val),(port)) : \
 172         __outw((val),(port)))
 173 
 174 #define inw(port) \
 175 ((__builtin_constant_p((port)) && (port) < 256) ? \
 176         __inwc(port) : \
 177         __inw(port))
 178 
 179 #define outw_p(val,port) \
 180 ((__builtin_constant_p((port)) && (port) < 256) ? \
 181         __outwc_p((val),(port)) : \
 182         __outw_p((val),(port)))
 183 
 184 #define inw_p(port) \
 185 ((__builtin_constant_p((port)) && (port) < 256) ? \
 186         __inwc_p(port) : \
 187         __inw_p(port))
 188 
 189 #define outl(val,port) \
 190 ((__builtin_constant_p((port)) && (port) < 256) ? \
 191         __outlc((val),(port)) : \
 192         __outl((val),(port)))
 193 
 194 #define inl(port) \
 195 ((__builtin_constant_p((port)) && (port) < 256) ? \
 196         __inlc(port) : \
 197         __inl(port))
 198 
 199 #define outl_p(val,port) \
 200 ((__builtin_constant_p((port)) && (port) < 256) ? \
 201         __outlc_p((val),(port)) : \
 202         __outl_p((val),(port)))
 203 
 204 #define inl_p(port) \
 205 ((__builtin_constant_p((port)) && (port) < 256) ? \
 206         __inlc_p(port) : \
 207         __inl_p(port))
 208 
 209 #endif

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