1 #ifndef _ASM_IO_H 2 #define _ASM_IO_H 3 4 #include <compiler.h> 5 6 /* 7 * This file contains the definitions for the x86 IO instructions 8 * inb/inw/inl/outb/outw/outl and the "string versions" of the same 9 * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing" 10 * versions of the single-IO instructions (inb_p/inw_p/..). 11 * 12 * This file is not meant to be obfuscating: it's just complicated 13 * to (a) handle it all in a way that makes gcc able to optimize it 14 * as well as possible and (b) trying to avoid writing the same thing 15 * over and over again with slight variations and possibly making a 16 * mistake somewhere. 17 */ 18 19 /* 20 * Thanks to James van Artsdalen for a better timing-fix than 21 * the two short jumps: using outb's to a nonexistent port seems 22 * to guarantee better timings even on fast machines. 23 * 24 * On the other hand, I'd like to be sure of a non-existent port: 25 * I feel a bit unsafe about using 0x80 (should be safe, though) 26 * 27 * Linus 28 */ 29 30 /* 31 * Bit simplified and optimized by Jan Hubicka 32 * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999. 33 * 34 * isa_memset_io, isa_memcpy_fromio, isa_memcpy_toio added, 35 * isa_read[wl] and isa_write[wl] fixed 36 * - Arnaldo Carvalho de Melo <acme@conectiva.com.br> 37 */ 38 39 #define IO_SPACE_LIMIT 0xffff 40 41 #include <asm/types.h> 42 43 44 #ifdef __KERNEL__ 45 46 47 /* 48 * readX/writeX() are used to access memory mapped devices. On some 49 * architectures the memory mapped IO stuff needs to be accessed 50 * differently. On the x86 architecture, we just read/write the 51 * memory location directly. 52 */ 53 54 #define readb(addr) (*(volatile unsigned char *) (addr)) 55 #define readw(addr) (*(volatile unsigned short *) (addr)) 56 #define readl(addr) (*(volatile unsigned int *) (addr)) 57 #define __raw_readb readb 58 #define __raw_readw readw 59 #define __raw_readl readl 60 61 #define writeb(b,addr) (*(volatile unsigned char *) (addr) = (b)) 62 #define writew(b,addr) (*(volatile unsigned short *) (addr) = (b)) 63 #define writel(b,addr) (*(volatile unsigned int *) (addr) = (b)) 64 #define __raw_writeb writeb 65 #define __raw_writew writew 66 #define __raw_writel writel 67 68 #define memset_io(a,b,c) memset((a),(b),(c)) 69 #define memcpy_fromio(a,b,c) memcpy((a),(b),(c)) 70 #define memcpy_toio(a,b,c) memcpy((a),(b),(c)) 71 72 /* 73 * ISA space is 'always mapped' on a typical x86 system, no need to 74 * explicitly ioremap() it. The fact that the ISA IO space is mapped 75 * to PAGE_OFFSET is pure coincidence - it does not mean ISA values 76 * are physical addresses. The following constant pointer can be 77 * used as the IO-area pointer (it can be iounmapped as well, so the 78 * analogy with PCI is quite large): 79 */ 80 #define isa_readb(a) readb((a)) 81 #define isa_readw(a) readw((a)) 82 #define isa_readl(a) readl((a)) 83 #define isa_writeb(b,a) writeb(b,(a)) 84 #define isa_writew(w,a) writew(w,(a)) 85 #define isa_writel(l,a) writel(l,(a)) 86 #define isa_memset_io(a,b,c) memset_io((a),(b),(c)) 87 #define isa_memcpy_fromio(a,b,c) memcpy_fromio((a),(b),(c)) 88 #define isa_memcpy_toio(a,b,c) memcpy_toio((a),(b),(c)) 89 90 91 static inline int check_signature(unsigned long io_addr, 92 const unsigned char *signature, int length) 93 { 94 int retval = 0; 95 do { 96 if (readb(io_addr) != *signature) 97 goto out; 98 io_addr++; 99 signature++; 100 length--; 101 } while (length); 102 retval = 1; 103 out: 104 return retval; 105 } 106 107 /** 108 * isa_check_signature - find BIOS signatures 109 * @io_addr: mmio address to check 110 * @signature: signature block 111 * @length: length of signature 112 * 113 * Perform a signature comparison with the ISA mmio address io_addr. 114 * Returns 1 on a match. 115 * 116 * This function is deprecated. New drivers should use ioremap and 117 * check_signature. 118 */ 119 120 121 static inline int isa_check_signature(unsigned long io_addr, 122 const unsigned char *signature, int length) 123 { 124 int retval = 0; 125 do { 126 if (isa_readb(io_addr) != *signature) 127 goto out; 128 io_addr++; 129 signature++; 130 length--; 131 } while (length); 132 retval = 1; 133 out: 134 return retval; 135 } 136 137 #endif /* __KERNEL__ */ 138 139 #ifdef SLOW_IO_BY_JUMPING 140 #define __SLOW_DOWN_IO "\njmp 1f\n1:\tjmp 1f\n1:" 141 #else 142 #define __SLOW_DOWN_IO "\noutb %%al,$0xed" 143 #endif 144 145 #ifdef REALLY_SLOW_IO 146 #define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO 147 #else 148 #define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO 149 #endif 150 151 152 /* 153 * Talk about misusing macros.. 154 */ 155 #define __OUT1(s,x) \ 156 static inline void out##s(unsigned x value, unsigned short port) { 157 158 #define __OUT2(s,s1,s2) \ 159 __asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1" 160 161 162 #define __OUT(s,s1,x) \ 163 __OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "Nd" (port)); } \ 164 __OUT1(s##_p,x) __OUT2(s,s1,"w") __FULL_SLOW_DOWN_IO : : "a" (value), "Nd" (port));} 165 166 #define __IN1(s) \ 167 static inline RETURN_TYPE in##s(unsigned short port) { RETURN_TYPE _v; 168 169 #define __IN2(s,s1,s2) \ 170 __asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0" 171 172 #define __IN(s,s1,i...) \ 173 __IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "Nd" (port) ,##i ); return _v; } \ 174 __IN1(s##_p) __IN2(s,s1,"w") __FULL_SLOW_DOWN_IO : "=a" (_v) : "Nd" (port) ,##i ); return _v; } 175 176 #define __INS(s) \ 177 static inline void ins##s(unsigned short port, void * addr, unsigned long count) \ 178 { __asm__ __volatile__ ("rep ; ins" #s \ 179 : "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); } 180 181 #define __OUTS(s) \ 182 static inline void outs##s(unsigned short port, const void * addr, unsigned long count) \ 183 { __asm__ __volatile__ ("rep ; outs" #s \ 184 : "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); } 185 186 #define RETURN_TYPE unsigned char 187 __IN(b,"") 188 #undef RETURN_TYPE 189 #define RETURN_TYPE unsigned short 190 __IN(w,"") 191 #undef RETURN_TYPE 192 #define RETURN_TYPE unsigned int 193 __IN(l,"") 194 #undef RETURN_TYPE 195 196 __OUT(b,"b",char) 197 __OUT(w,"w",short) 198 __OUT(l,,int) 199 200 __INS(b) 201 __INS(w) 202 __INS(l) 203 204 __OUTS(b) 205 __OUTS(w) 206 __OUTS(l) 207 208 static inline void sync(void) 209 { 210 } 211 212 /* 213 * Given a physical address and a length, return a virtual address 214 * that can be used to access the memory range with the caching 215 * properties specified by "flags". 216 */ 217 #define MAP_NOCACHE (0) 218 #define MAP_WRCOMBINE (0) 219 #define MAP_WRBACK (0) 220 #define MAP_WRTHROUGH (0) 221 222 static inline void * 223 map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags) 224 { 225 return (void *)(uintptr_t)paddr; 226 } 227 228 /* 229 * Take down a mapping set up by map_physmem(). 230 */ 231 static inline void unmap_physmem(void *vaddr, unsigned long flags) 232 { 233 234 } 235 236 static inline phys_addr_t virt_to_phys(void * vaddr) 237 { 238 return (phys_addr_t)(uintptr_t)(vaddr); 239 } 240 241 /* 242 * TODO: The kernel offers some more advanced versions of barriers, it might 243 * have some advantages to use them instead of the simple one here. 244 */ 245 #define dmb() __asm__ __volatile__ ("" : : : "memory") 246 #define __iormb() dmb() 247 #define __iowmb() dmb() 248 249 #endif 250