7 /* virt_to_bus converts an addresss inside of etherboot [_start, _end]
8 * into a memory access cards can use.
10 #define virt_to_bus virt_to_phys
13 /* bus_to_virt reverses virt_to_bus, the address must be output
14 * from virt_to_bus to be valid. This function does not work on
17 #define bus_to_virt phys_to_virt
19 /* ioremap converts a random 32bit bus address into something
20 * etherboot can access.
22 static inline void *ioremap(unsigned long bus_addr, unsigned long length __unused)
24 return bus_to_virt(bus_addr);
27 /* iounmap cleans up anything ioremap had to setup */
28 static inline void iounmap(void *virt_addr __unused)
34 * This file contains the definitions for the x86 IO instructions
35 * inb/inw/inl/outb/outw/outl and the "string versions" of the same
36 * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
37 * versions of the single-IO instructions (inb_p/inw_p/..).
39 * This file is not meant to be obfuscating: it's just complicated
40 * to (a) handle it all in a way that makes gcc able to optimize it
41 * as well as possible and (b) trying to avoid writing the same thing
42 * over and over again with slight variations and possibly making a
47 * Thanks to James van Artsdalen for a better timing-fix than
48 * the two short jumps: using outb's to a nonexistent port seems
49 * to guarantee better timings even on fast machines.
51 * On the other hand, I'd like to be sure of a non-existent port:
52 * I feel a bit unsafe about using 0x80 (should be safe, though)
57 #ifdef SLOW_IO_BY_JUMPING
58 #define __SLOW_DOWN_IO __asm__ __volatile__("jmp 1f\n1:\tjmp 1f\n1:")
60 #define __SLOW_DOWN_IO __asm__ __volatile__("outb %al,$0x80")
64 #define SLOW_DOWN_IO { __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; }
66 #define SLOW_DOWN_IO __SLOW_DOWN_IO
70 * readX/writeX() are used to access memory mapped devices. On some
71 * architectures the memory mapped IO stuff needs to be accessed
72 * differently. On the x86 architecture, we just read/write the
73 * memory location directly.
75 #define readb(addr) (*(volatile unsigned char *) (addr))
76 #define readw(addr) (*(volatile unsigned short *) (addr))
77 #define readl(addr) (*(volatile unsigned int *) (addr))
79 #define writeb(b,addr) ((*(volatile unsigned char *) (addr)) = (b))
80 #define writew(b,addr) ((*(volatile unsigned short *) (addr)) = (b))
81 #define writel(b,addr) ((*(volatile unsigned int *) (addr)) = (b))
83 #define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
84 #define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
87 * Force strict CPU ordering.
88 * And yes, this is required on UP too when we're talking
91 * For now, "wmb()" doesn't actually do anything, as all
92 * Intel CPU's follow what Intel calls a *Processor Order*,
93 * in which all writes are seen in the program order even
96 * I expect future Intel CPU's to have a weaker ordering,
97 * but I'd also expect them to finally get their act together
98 * and add some real memory barriers if so.
100 * Some non intel clones support out of order store. wmb() ceases to be a
104 #define mb() __asm__ __volatile__ ("lock; addl $0,0(%%esp)": : :"memory")
110 * Talk about misusing macros..
113 #define __OUT1(s,x) \
114 extern void __out##s(unsigned x value, unsigned short port); \
115 extern inline void __out##s(unsigned x value, unsigned short port) {
117 #define __OUT2(s,s1,s2) \
118 __asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
120 #define __OUT(s,s1,x) \
121 __OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); } \
122 __OUT1(s##c,x) __OUT2(s,s1,"") : : "a" (value), "id" (port)); } \
123 __OUT1(s##_p,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); SLOW_DOWN_IO; } \
124 __OUT1(s##c_p,x) __OUT2(s,s1,"") : : "a" (value), "id" (port)); SLOW_DOWN_IO; }
127 extern unsigned x __in##s(unsigned short port); \
128 extern inline unsigned x __in##s(unsigned short port) { unsigned x _v;
130 #define __IN2(s,s1,s2) \
131 __asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
133 #define __IN(s,s1,x,i...) \
134 __IN1(s,x) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); return _v; } \
135 __IN1(s##c,x) __IN2(s,s1,"") : "=a" (_v) : "id" (port) ,##i ); return _v; } \
136 __IN1(s##_p,x) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); SLOW_DOWN_IO; return _v; } \
137 __IN1(s##c_p,x) __IN2(s,s1,"") : "=a" (_v) : "id" (port) ,##i ); SLOW_DOWN_IO; return _v; }
140 extern void ins##s(unsigned short port, void * addr, unsigned long count); \
141 extern inline void ins##s(unsigned short port, void * addr, unsigned long count) \
142 { __asm__ __volatile__ ("cld ; rep ; ins" #s \
143 : "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
146 extern void outs##s(unsigned short port, const void * addr, unsigned long count); \
147 extern inline void outs##s(unsigned short port, const void * addr, unsigned long count) \
148 { __asm__ __volatile__ ("cld ; rep ; outs" #s \
149 : "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
168 * Note that due to the way __builtin_constant_p() works, you
169 * - can't use it inside a inline function (it will never be true)
170 * - you don't have to worry about side effects within the __builtin..
172 #define outb(val,port) \
173 ((__builtin_constant_p((port)) && (port) < 256) ? \
174 __outbc((val),(port)) : \
175 __outb((val),(port)))
178 ((__builtin_constant_p((port)) && (port) < 256) ? \
182 #define outb_p(val,port) \
183 ((__builtin_constant_p((port)) && (port) < 256) ? \
184 __outbc_p((val),(port)) : \
185 __outb_p((val),(port)))
187 #define inb_p(port) \
188 ((__builtin_constant_p((port)) && (port) < 256) ? \
192 #define outw(val,port) \
193 ((__builtin_constant_p((port)) && (port) < 256) ? \
194 __outwc((val),(port)) : \
195 __outw((val),(port)))
198 ((__builtin_constant_p((port)) && (port) < 256) ? \
202 #define outw_p(val,port) \
203 ((__builtin_constant_p((port)) && (port) < 256) ? \
204 __outwc_p((val),(port)) : \
205 __outw_p((val),(port)))
207 #define inw_p(port) \
208 ((__builtin_constant_p((port)) && (port) < 256) ? \
212 #define outl(val,port) \
213 ((__builtin_constant_p((port)) && (port) < 256) ? \
214 __outlc((val),(port)) : \
215 __outl((val),(port)))
218 ((__builtin_constant_p((port)) && (port) < 256) ? \
222 #define outl_p(val,port) \
223 ((__builtin_constant_p((port)) && (port) < 256) ? \
224 __outlc_p((val),(port)) : \
225 __outl_p((val),(port)))
227 #define inl_p(port) \
228 ((__builtin_constant_p((port)) && (port) < 256) ? \
232 #endif /* ETHERBOOT_IO_H */