Add constants for fast path resume copying
[coreboot.git] / src / arch / x86 / include / arch / io.h
1 #ifndef _ASM_IO_H
2 #define _ASM_IO_H
3
4 #include <stdint.h>
5
6 /*
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).
10  */
11 #if defined(__ROMCC__)
12 static inline void outb(uint8_t value, uint16_t port)
13 {
14         __builtin_outb(value, port);
15 }
16
17 static inline void outw(uint16_t value, uint16_t port)
18 {
19         __builtin_outw(value, port);
20 }
21
22 static inline void outl(uint32_t value, uint16_t port)
23 {
24         __builtin_outl(value, port);
25 }
26
27
28 static inline uint8_t inb(uint16_t port)
29 {
30         return __builtin_inb(port);
31 }
32
33
34 static inline uint16_t inw(uint16_t port)
35 {
36         return __builtin_inw(port);
37 }
38
39 static inline uint32_t inl(uint16_t port)
40 {
41         return __builtin_inl(port);
42 }
43 #else
44 static inline void outb(uint8_t value, uint16_t port)
45 {
46         __asm__ __volatile__ ("outb %b0, %w1" : : "a" (value), "Nd" (port));
47 }
48
49 static inline void outw(uint16_t value, uint16_t port)
50 {
51         __asm__ __volatile__ ("outw %w0, %w1" : : "a" (value), "Nd" (port));
52 }
53
54 static inline void outl(uint32_t value, uint16_t port)
55 {
56         __asm__ __volatile__ ("outl %0, %w1" : : "a" (value), "Nd" (port));
57 }
58
59 static inline uint8_t inb(uint16_t port)
60 {
61         uint8_t value;
62         __asm__ __volatile__ ("inb %w1, %b0" : "=a"(value) : "Nd" (port));
63         return value;
64 }
65
66 static inline uint16_t inw(uint16_t port)
67 {
68         uint16_t value;
69         __asm__ __volatile__ ("inw %w1, %w0" : "=a"(value) : "Nd" (port));
70         return value;
71 }
72
73 static inline uint32_t inl(uint16_t port)
74 {
75         uint32_t value;
76         __asm__ __volatile__ ("inl %w1, %0" : "=a"(value) : "Nd" (port));
77         return value;
78 }
79 #endif /* __ROMCC__ */
80
81 static inline void outsb(uint16_t port, const void *addr, unsigned long count)
82 {
83         __asm__ __volatile__ (
84                 "cld ; rep ; outsb "
85                 : "=S" (addr), "=c" (count)
86                 : "d"(port), "0"(addr), "1" (count)
87                 );
88 }
89
90 static inline void outsw(uint16_t port, const void *addr, unsigned long count)
91 {
92         __asm__ __volatile__ (
93                 "cld ; rep ; outsw "
94                 : "=S" (addr), "=c" (count)
95                 : "d"(port), "0"(addr), "1" (count)
96                 );
97 }
98
99 static inline void outsl(uint16_t port, const void *addr, unsigned long count)
100 {
101         __asm__ __volatile__ (
102                 "cld ; rep ; outsl "
103                 : "=S" (addr), "=c" (count)
104                 : "d"(port), "0"(addr), "1" (count)
105                 );
106 }
107
108
109 static inline void insb(uint16_t port, void *addr, unsigned long count)
110 {
111         __asm__ __volatile__ (
112                 "cld ; rep ; insb "
113                 : "=D" (addr), "=c" (count)
114                 : "d"(port), "0"(addr), "1" (count)
115                 );
116 }
117
118 static inline void insw(uint16_t port, void *addr, unsigned long count)
119 {
120         __asm__ __volatile__ (
121                 "cld ; rep ; insw "
122                 : "=D" (addr), "=c" (count)
123                 : "d"(port), "0"(addr), "1" (count)
124                 );
125 }
126
127 static inline void insl(uint16_t port, void *addr, unsigned long count)
128 {
129         __asm__ __volatile__ (
130                 "cld ; rep ; insl "
131                 : "=D" (addr), "=c" (count)
132                 : "d"(port), "0"(addr), "1" (count)
133                 );
134 }
135
136 static inline __attribute__((always_inline)) uint8_t read8(unsigned long addr)
137 {
138         return *((volatile uint8_t *)(addr));
139 }
140
141 static inline __attribute__((always_inline)) uint16_t read16(unsigned long addr)
142 {
143         return *((volatile uint16_t *)(addr));
144 }
145
146 static inline __attribute__((always_inline)) uint32_t read32(unsigned long addr)
147 {
148         return *((volatile uint32_t *)(addr));
149 }
150
151 static inline __attribute__((always_inline)) void write8(unsigned long addr, uint8_t value)
152 {
153         *((volatile uint8_t *)(addr)) = value;
154 }
155
156 static inline __attribute__((always_inline)) void write16(unsigned long addr, uint16_t value)
157 {
158         *((volatile uint16_t *)(addr)) = value;
159 }
160
161 static inline __attribute__((always_inline)) void write32(unsigned long addr, uint32_t value)
162 {
163         *((volatile uint32_t *)(addr)) = value;
164 }
165
166 #endif
167