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