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/..).
12 #if defined(__ROMCC__)
13 static inline void outb(uint8_t value, uint16_t port)
15 __builtin_outb(value, port);
18 static inline void outw(uint16_t value, uint16_t port)
20 __builtin_outw(value, port);
23 static inline void outl(uint32_t value, uint16_t port)
25 __builtin_outl(value, port);
29 static inline uint8_t inb(uint16_t port)
31 return __builtin_inb(port);
35 static inline uint16_t inw(uint16_t port)
37 return __builtin_inw(port);
40 static inline uint32_t inl(uint16_t port)
42 return __builtin_inl(port);
45 static inline void outb(uint8_t value, uint16_t port)
47 __asm__ __volatile__ ("outb %b0, %w1" : : "a" (value), "Nd" (port));
50 static inline void outw(uint16_t value, uint16_t port)
52 __asm__ __volatile__ ("outw %w0, %w1" : : "a" (value), "Nd" (port));
55 static inline void outl(uint32_t value, uint16_t port)
57 __asm__ __volatile__ ("outl %0, %w1" : : "a" (value), "Nd" (port));
60 static inline uint8_t inb(uint16_t port)
63 __asm__ __volatile__ ("inb %w1, %b0" : "=a"(value) : "Nd" (port));
67 static inline uint16_t inw(uint16_t port)
70 __asm__ __volatile__ ("inw %w1, %w0" : "=a"(value) : "Nd" (port));
74 static inline uint32_t inl(uint16_t port)
77 __asm__ __volatile__ ("inl %w1, %0" : "=a"(value) : "Nd" (port));
80 #endif /* __ROMCC__ */
82 static inline void outsb(uint16_t port, const void *addr, unsigned long count)
84 __asm__ __volatile__ (
86 : "=S" (addr), "=c" (count)
87 : "d"(port), "0"(addr), "1" (count)
91 static inline void outsw(uint16_t port, const void *addr, unsigned long count)
93 __asm__ __volatile__ (
95 : "=S" (addr), "=c" (count)
96 : "d"(port), "0"(addr), "1" (count)
100 static inline void outsl(uint16_t port, const void *addr, unsigned long count)
102 __asm__ __volatile__ (
104 : "=S" (addr), "=c" (count)
105 : "d"(port), "0"(addr), "1" (count)
110 static inline void insb(uint16_t port, void *addr, unsigned long count)
112 __asm__ __volatile__ (
114 : "=D" (addr), "=c" (count)
115 : "d"(port), "0"(addr), "1" (count)
119 static inline void insw(uint16_t port, void *addr, unsigned long count)
121 __asm__ __volatile__ (
123 : "=D" (addr), "=c" (count)
124 : "d"(port), "0"(addr), "1" (count)
128 static inline void insl(uint16_t port, void *addr, unsigned long count)
130 __asm__ __volatile__ (
132 : "=D" (addr), "=c" (count)
133 : "d"(port), "0"(addr), "1" (count)
138 /* XXX XXX XXX This is a story from the evil API from hell XXX XXX XXX
139 * We have different functions for memory access in pre-ram stage and ram
140 * stage. Those in pre-ram stage are called write32 and expect the address
141 * first and the address as a pointer type. Those in ram stage are called
142 * writel and expect the datum first and the address as an integer type.
143 * Until all code is checked and fixed, I'll add both versions here now.
146 static inline void writeb(uint8_t b, volatile void *addr)
148 *(volatile uint8_t *) addr = b;
151 static inline void writew(uint16_t b, volatile void *addr)
153 *(volatile uint16_t *) addr = b;
156 static inline void writel(uint32_t b, volatile void *addr)
158 *(volatile uint32_t *) addr = b;
161 static inline uint8_t readb(const volatile void *addr)
163 return *(volatile uint8_t *) addr;
166 static inline uint16_t readw(const volatile void *addr)
168 return *(volatile uint16_t *) addr;
171 static inline uint32_t readl(const volatile void *addr)
173 return *(volatile uint32_t *) addr;
177 #if !defined(__PRE_RAM__)
178 static inline __attribute__((always_inline)) uint8_t read8(unsigned long addr)
180 return *((volatile uint8_t *)(addr));
183 static inline __attribute__((always_inline)) uint16_t read16(unsigned long addr)
185 return *((volatile uint16_t *)(addr));
188 static inline __attribute__((always_inline)) uint32_t read32(unsigned long addr)
190 return *((volatile uint32_t *)(addr));
193 static inline __attribute__((always_inline)) void write8(unsigned long addr, uint8_t value)
195 *((volatile uint8_t *)(addr)) = value;
198 static inline __attribute__((always_inline)) void write16(unsigned long addr, uint16_t value)
200 *((volatile uint16_t *)(addr)) = value;
203 static inline __attribute__((always_inline)) void write32(unsigned long addr, uint32_t value)
205 *((volatile uint32_t *)(addr)) = value;