H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 1 | #ifndef _ASM_X86_IO_32_H |
| 2 | #define _ASM_X86_IO_32_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | #include <linux/string.h> |
| 5 | #include <linux/compiler.h> |
| 6 | |
| 7 | /* |
| 8 | * This file contains the definitions for the x86 IO instructions |
| 9 | * inb/inw/inl/outb/outw/outl and the "string versions" of the same |
| 10 | * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing" |
| 11 | * versions of the single-IO instructions (inb_p/inw_p/..). |
| 12 | * |
| 13 | * This file is not meant to be obfuscating: it's just complicated |
| 14 | * to (a) handle it all in a way that makes gcc able to optimize it |
| 15 | * as well as possible and (b) trying to avoid writing the same thing |
| 16 | * over and over again with slight variations and possibly making a |
| 17 | * mistake somewhere. |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * Thanks to James van Artsdalen for a better timing-fix than |
| 22 | * the two short jumps: using outb's to a nonexistent port seems |
| 23 | * to guarantee better timings even on fast machines. |
| 24 | * |
| 25 | * On the other hand, I'd like to be sure of a non-existent port: |
| 26 | * I feel a bit unsafe about using 0x80 (should be safe, though) |
| 27 | * |
| 28 | * Linus |
| 29 | */ |
| 30 | |
| 31 | /* |
| 32 | * Bit simplified and optimized by Jan Hubicka |
| 33 | * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999. |
| 34 | * |
| 35 | * isa_memset_io, isa_memcpy_fromio, isa_memcpy_toio added, |
| 36 | * isa_read[wl] and isa_write[wl] fixed |
| 37 | * - Arnaldo Carvalho de Melo <acme@conectiva.com.br> |
| 38 | */ |
| 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #define XQUAD_PORTIO_BASE 0xfe400000 |
| 41 | #define XQUAD_PORTIO_QUAD 0x40000 /* 256k per quad. */ |
| 42 | |
| 43 | #ifdef __KERNEL__ |
| 44 | |
| 45 | #include <asm-generic/iomap.h> |
| 46 | |
| 47 | #include <linux/vmalloc.h> |
| 48 | |
| 49 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | * Convert a virtual cached pointer to an uncached pointer |
| 51 | */ |
| 52 | #define xlate_dev_kmem_ptr(p) p |
| 53 | |
Andrew Morton | 3c215b6 | 2007-10-17 18:04:39 +0200 | [diff] [blame] | 54 | static inline void |
| 55 | memset_io(volatile void __iomem *addr, unsigned char val, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | { |
Andrew Morton | 3c215b6 | 2007-10-17 18:04:39 +0200 | [diff] [blame] | 57 | memset((void __force *)addr, val, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | } |
Andrew Morton | 3c215b6 | 2007-10-17 18:04:39 +0200 | [diff] [blame] | 59 | |
| 60 | static inline void |
| 61 | memcpy_fromio(void *dst, const volatile void __iomem *src, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { |
Andrew Morton | 3c215b6 | 2007-10-17 18:04:39 +0200 | [diff] [blame] | 63 | __memcpy(dst, (const void __force *)src, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | } |
Andrew Morton | 3c215b6 | 2007-10-17 18:04:39 +0200 | [diff] [blame] | 65 | |
| 66 | static inline void |
| 67 | memcpy_toio(volatile void __iomem *dst, const void *src, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { |
Andrew Morton | 3c215b6 | 2007-10-17 18:04:39 +0200 | [diff] [blame] | 69 | __memcpy((void __force *)dst, src, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | } |
| 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_IO_base ((char __iomem *)(PAGE_OFFSET)) |
| 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | * Cache management |
| 84 | * |
| 85 | * This needed for two cases |
| 86 | * 1. Out of order aware processors |
| 87 | * 2. Accidentally out of order processors (PPro errata #51) |
| 88 | */ |
Joe Perches | dcd215c | 2008-03-23 01:02:22 -0700 | [diff] [blame] | 89 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | #if defined(CONFIG_X86_OOSTORE) || defined(CONFIG_X86_PPRO_FENCE) |
| 91 | |
| 92 | static inline void flush_write_buffers(void) |
| 93 | { |
Joe Perches | dcd215c | 2008-03-23 01:02:22 -0700 | [diff] [blame] | 94 | asm volatile("lock; addl $0,0(%%esp)": : :"memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | #else |
| 98 | |
Ralf Baechle | 622a9ed | 2007-10-16 23:29:42 -0700 | [diff] [blame] | 99 | #define flush_write_buffers() do { } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | #endif |
| 102 | |
| 103 | #endif /* __KERNEL__ */ |
| 104 | |
Rene Herman | b02aae9 | 2008-01-30 13:30:05 +0100 | [diff] [blame] | 105 | extern void native_io_delay(void); |
Rusty Russell | 90a0a06 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 106 | |
Ingo Molnar | 6e7c402 | 2008-01-30 13:30:05 +0100 | [diff] [blame] | 107 | extern int io_delay_type; |
| 108 | extern void io_delay_init(void); |
| 109 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 110 | #if defined(CONFIG_PARAVIRT) |
| 111 | #include <asm/paravirt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | #else |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 113 | |
Joe Perches | dcd215c | 2008-03-23 01:02:22 -0700 | [diff] [blame] | 114 | static inline void slow_down_io(void) |
| 115 | { |
Rusty Russell | 90a0a06 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 116 | native_io_delay(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | #ifdef REALLY_SLOW_IO |
Rusty Russell | 90a0a06 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 118 | native_io_delay(); |
| 119 | native_io_delay(); |
| 120 | native_io_delay(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 124 | #endif |
| 125 | |
Joe Perches | dcd215c | 2008-03-23 01:02:22 -0700 | [diff] [blame] | 126 | #define __BUILDIO(bwl, bw, type) \ |
| 127 | static inline void out##bwl(unsigned type value, int port) \ |
| 128 | { \ |
| 129 | out##bwl##_local(value, port); \ |
| 130 | } \ |
| 131 | \ |
| 132 | static inline unsigned type in##bwl(int port) \ |
| 133 | { \ |
| 134 | return in##bwl##_local(port); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
Joe Perches | dcd215c | 2008-03-23 01:02:22 -0700 | [diff] [blame] | 137 | #define BUILDIO(bwl, bw, type) \ |
| 138 | static inline void out##bwl##_local(unsigned type value, int port) \ |
| 139 | { \ |
| 140 | asm volatile("out" #bwl " %" #bw "0, %w1" \ |
| 141 | : : "a"(value), "Nd"(port)); \ |
| 142 | } \ |
| 143 | \ |
| 144 | static inline unsigned type in##bwl##_local(int port) \ |
| 145 | { \ |
| 146 | unsigned type value; \ |
| 147 | asm volatile("in" #bwl " %w1, %" #bw "0" \ |
| 148 | : "=a"(value) : "Nd"(port)); \ |
| 149 | return value; \ |
| 150 | } \ |
| 151 | \ |
| 152 | static inline void out##bwl##_local_p(unsigned type value, int port) \ |
| 153 | { \ |
| 154 | out##bwl##_local(value, port); \ |
| 155 | slow_down_io(); \ |
| 156 | } \ |
| 157 | \ |
| 158 | static inline unsigned type in##bwl##_local_p(int port) \ |
| 159 | { \ |
| 160 | unsigned type value = in##bwl##_local(port); \ |
| 161 | slow_down_io(); \ |
| 162 | return value; \ |
| 163 | } \ |
| 164 | \ |
| 165 | __BUILDIO(bwl, bw, type) \ |
| 166 | \ |
| 167 | static inline void out##bwl##_p(unsigned type value, int port) \ |
| 168 | { \ |
| 169 | out##bwl(value, port); \ |
| 170 | slow_down_io(); \ |
| 171 | } \ |
| 172 | \ |
| 173 | static inline unsigned type in##bwl##_p(int port) \ |
| 174 | { \ |
| 175 | unsigned type value = in##bwl(port); \ |
| 176 | slow_down_io(); \ |
| 177 | return value; \ |
| 178 | } \ |
| 179 | \ |
| 180 | static inline void outs##bwl(int port, const void *addr, unsigned long count) \ |
| 181 | { \ |
| 182 | asm volatile("rep; outs" #bwl \ |
| 183 | : "+S"(addr), "+c"(count) : "d"(port)); \ |
| 184 | } \ |
| 185 | \ |
| 186 | static inline void ins##bwl(int port, void *addr, unsigned long count) \ |
| 187 | { \ |
| 188 | asm volatile("rep; ins" #bwl \ |
| 189 | : "+D"(addr), "+c"(count) : "d"(port)); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Joe Perches | dcd215c | 2008-03-23 01:02:22 -0700 | [diff] [blame] | 192 | BUILDIO(b, b, char) |
| 193 | BUILDIO(w, w, short) |
| 194 | BUILDIO(l, , int) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 196 | #endif /* _ASM_X86_IO_32_H */ |