VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/Etherboot-src/arch/i386/include/io.h@ 1

Last change on this file since 1 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 KB
Line 
1#ifndef ETHERBOOT_IO_H
2#define ETHERBOOT_IO_H
3
4
5/* Amount of relocation etherboot is experiencing */
6extern unsigned long virt_offset;
7
8/* Don't require identity mapped physical memory,
9 * osloader.c is the only valid user at the moment.
10 */
11static inline unsigned long virt_to_phys(volatile const void *virt_addr)
12{
13 return ((unsigned long)virt_addr) + virt_offset;
14}
15
16static inline void *phys_to_virt(unsigned long phys_addr)
17{
18 return (void *)(phys_addr - virt_offset);
19}
20
21/* virt_to_bus converts an addresss inside of etherboot [_start, _end]
22 * into a memory access cards can use.
23 */
24#define virt_to_bus virt_to_phys
25
26
27/* bus_to_virt reverses virt_to_bus, the address must be output
28 * from virt_to_bus to be valid. This function does not work on
29 * all bus addresses.
30 */
31#define bus_to_virt phys_to_virt
32
33/* ioremap converts a random 32bit bus address into something
34 * etherboot can access.
35 */
36static inline void *ioremap(unsigned long bus_addr, unsigned long length __unused)
37{
38 return bus_to_virt(bus_addr);
39}
40
41/* iounmap cleans up anything ioremap had to setup */
42static inline void iounmap(void *virt_addr __unused)
43{
44 return;
45}
46
47/*
48 * This file contains the definitions for the x86 IO instructions
49 * inb/inw/inl/outb/outw/outl and the "string versions" of the same
50 * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
51 * versions of the single-IO instructions (inb_p/inw_p/..).
52 *
53 * This file is not meant to be obfuscating: it's just complicated
54 * to (a) handle it all in a way that makes gcc able to optimize it
55 * as well as possible and (b) trying to avoid writing the same thing
56 * over and over again with slight variations and possibly making a
57 * mistake somewhere.
58 */
59
60/*
61 * Thanks to James van Artsdalen for a better timing-fix than
62 * the two short jumps: using outb's to a nonexistent port seems
63 * to guarantee better timings even on fast machines.
64 *
65 * On the other hand, I'd like to be sure of a non-existent port:
66 * I feel a bit unsafe about using 0x80 (should be safe, though)
67 *
68 * Linus
69 */
70
71#ifdef SLOW_IO_BY_JUMPING
72#define __SLOW_DOWN_IO __asm__ __volatile__("jmp 1f\n1:\tjmp 1f\n1:")
73#else
74#define __SLOW_DOWN_IO __asm__ __volatile__("outb %al,$0x80")
75#endif
76
77#ifdef REALLY_SLOW_IO
78#define SLOW_DOWN_IO { __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; }
79#else
80#define SLOW_DOWN_IO __SLOW_DOWN_IO
81#endif
82
83/*
84 * readX/writeX() are used to access memory mapped devices. On some
85 * architectures the memory mapped IO stuff needs to be accessed
86 * differently. On the x86 architecture, we just read/write the
87 * memory location directly.
88 */
89#define readb(addr) (*(volatile unsigned char *) (addr))
90#define readw(addr) (*(volatile unsigned short *) (addr))
91#define readl(addr) (*(volatile unsigned int *) (addr))
92
93#define writeb(b,addr) ((*(volatile unsigned char *) (addr)) = (b))
94#define writew(b,addr) ((*(volatile unsigned short *) (addr)) = (b))
95#define writel(b,addr) ((*(volatile unsigned int *) (addr)) = (b))
96
97#define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
98#define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
99
100/*
101 * Force strict CPU ordering.
102 * And yes, this is required on UP too when we're talking
103 * to devices.
104 *
105 * For now, "wmb()" doesn't actually do anything, as all
106 * Intel CPU's follow what Intel calls a *Processor Order*,
107 * in which all writes are seen in the program order even
108 * outside the CPU.
109 *
110 * I expect future Intel CPU's to have a weaker ordering,
111 * but I'd also expect them to finally get their act together
112 * and add some real memory barriers if so.
113 *
114 * Some non intel clones support out of order store. wmb() ceases to be a
115 * nop for these.
116 */
117
118#define mb() __asm__ __volatile__ ("lock; addl $0,0(%%esp)": : :"memory")
119#define rmb() mb()
120#define wmb() mb();
121
122
123/*
124 * Talk about misusing macros..
125 */
126
127#define __OUT1(s,x) \
128extern void __out##s(unsigned x value, unsigned short port); \
129extern inline void __out##s(unsigned x value, unsigned short port) {
130
131#define __OUT2(s,s1,s2) \
132__asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
133
134#define __OUT(s,s1,x) \
135__OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); } \
136__OUT1(s##c,x) __OUT2(s,s1,"") : : "a" (value), "id" (port)); } \
137__OUT1(s##_p,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); SLOW_DOWN_IO; } \
138__OUT1(s##c_p,x) __OUT2(s,s1,"") : : "a" (value), "id" (port)); SLOW_DOWN_IO; }
139
140#define __IN1(s,x) \
141extern unsigned x __in##s(unsigned short port); \
142extern inline unsigned x __in##s(unsigned short port) { unsigned x _v;
143
144#define __IN2(s,s1,s2) \
145__asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
146
147#define __IN(s,s1,x,i...) \
148__IN1(s,x) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); return _v; } \
149__IN1(s##c,x) __IN2(s,s1,"") : "=a" (_v) : "id" (port) ,##i ); return _v; } \
150__IN1(s##_p,x) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); SLOW_DOWN_IO; return _v; } \
151__IN1(s##c_p,x) __IN2(s,s1,"") : "=a" (_v) : "id" (port) ,##i ); SLOW_DOWN_IO; return _v; }
152
153#define __INS(s) \
154extern void ins##s(unsigned short port, void * addr, unsigned long count); \
155extern inline void ins##s(unsigned short port, void * addr, unsigned long count) \
156{ __asm__ __volatile__ ("cld ; rep ; ins" #s \
157: "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
158
159#define __OUTS(s) \
160extern void outs##s(unsigned short port, const void * addr, unsigned long count); \
161extern inline void outs##s(unsigned short port, const void * addr, unsigned long count) \
162{ __asm__ __volatile__ ("cld ; rep ; outs" #s \
163: "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
164
165__IN(b,"", char)
166__IN(w,"",short)
167__IN(l,"", long)
168
169__OUT(b,"b",char)
170__OUT(w,"w",short)
171__OUT(l,,int)
172
173__INS(b)
174__INS(w)
175__INS(l)
176
177__OUTS(b)
178__OUTS(w)
179__OUTS(l)
180
181/*
182 * Note that due to the way __builtin_constant_p() works, you
183 * - can't use it inside a inline function (it will never be true)
184 * - you don't have to worry about side effects within the __builtin..
185 */
186#define outb(val,port) \
187((__builtin_constant_p((port)) && (port) < 256) ? \
188 __outbc((val),(port)) : \
189 __outb((val),(port)))
190
191#define inb(port) \
192((__builtin_constant_p((port)) && (port) < 256) ? \
193 __inbc(port) : \
194 __inb(port))
195
196#define outb_p(val,port) \
197((__builtin_constant_p((port)) && (port) < 256) ? \
198 __outbc_p((val),(port)) : \
199 __outb_p((val),(port)))
200
201#define inb_p(port) \
202((__builtin_constant_p((port)) && (port) < 256) ? \
203 __inbc_p(port) : \
204 __inb_p(port))
205
206#define outw(val,port) \
207((__builtin_constant_p((port)) && (port) < 256) ? \
208 __outwc((val),(port)) : \
209 __outw((val),(port)))
210
211#define inw(port) \
212((__builtin_constant_p((port)) && (port) < 256) ? \
213 __inwc(port) : \
214 __inw(port))
215
216#define outw_p(val,port) \
217((__builtin_constant_p((port)) && (port) < 256) ? \
218 __outwc_p((val),(port)) : \
219 __outw_p((val),(port)))
220
221#define inw_p(port) \
222((__builtin_constant_p((port)) && (port) < 256) ? \
223 __inwc_p(port) : \
224 __inw_p(port))
225
226#define outl(val,port) \
227((__builtin_constant_p((port)) && (port) < 256) ? \
228 __outlc((val),(port)) : \
229 __outl((val),(port)))
230
231#define inl(port) \
232((__builtin_constant_p((port)) && (port) < 256) ? \
233 __inlc(port) : \
234 __inl(port))
235
236#define outl_p(val,port) \
237((__builtin_constant_p((port)) && (port) < 256) ? \
238 __outlc_p((val),(port)) : \
239 __outl_p((val),(port)))
240
241#define inl_p(port) \
242((__builtin_constant_p((port)) && (port) < 256) ? \
243 __inlc_p(port) : \
244 __inl_p(port))
245
246#endif /* ETHERBOOT_IO_H */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette