Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / openbios / include / arch / sparc32 / io.h
1 #ifndef _ASM_IO_H
2 #define _ASM_IO_H
3
4 #include "asm/types.h"
5
6 extern unsigned int va_shift; // Set in entry.S
7
8 // Defined in ldscript
9 extern char _start, _data, _stack, _estack, _end, _vmem, _evmem, _iomem;
10
11 // XXX check use and merge
12 #define phys_to_virt(phys) ((void *) ((unsigned long) (phys)))
13 #define virt_to_phys(virt) ((unsigned long) (virt))
14
15 #ifndef BOOTSTRAP
16
17 #ifndef _IO_BASE
18 #define _IO_BASE        0
19 #endif
20
21 /*
22  * The insw/outsw/insl/outsl macros don't do byte-swapping.
23  * They are only used in practice for transferring buffers which
24  * are arrays of bytes, and byte-swapping is not appropriate in
25  * that case.  - paulus
26  */
27 #define insw(port, buf, ns)     _insw_ns((uint16_t *)((port)+_IO_BASE), (buf), (ns))
28 #define outsw(port, buf, ns)    _outsw_ns((uint16_t *)((port)+_IO_BASE), (buf), (ns))
29
30 #define inb(port)               in_8((uint8_t *)((port)+_IO_BASE))
31 #define outb(val, port)         out_8((uint8_t *)((port)+_IO_BASE), (val))
32 #define inw(port)               in_le16((uint16_t *)((port)+_IO_BASE))
33 #define outw(val, port)         out_le16((uint16_t *)((port)+_IO_BASE), (val))
34 #define inl(port)               in_le32((uint32_t *)((port)+_IO_BASE))
35 #define outl(val, port)         out_le32((uint32_t *)((port)+_IO_BASE), (val))
36
37 /*
38  * 8, 16 and 32 bit, big and little endian I/O operations, with barrier.
39  */
40 static inline int in_8(volatile unsigned char *addr)
41 {
42     int ret;
43
44     __asm__ __volatile__("ldub [%1], %0\n\t"
45                          "stbar\n\t"
46                          :"=r"(ret):"r"(addr):"memory");
47
48     return ret;
49 }
50
51 static inline void out_8(volatile unsigned char *addr, int val)
52 {
53     __asm__ __volatile__("stb %0, [%1]\n\t"
54                          "stbar\n\t"
55                          : : "r"(val), "r"(addr):"memory");
56 }
57
58 static inline int in_le16(volatile unsigned short *addr)
59 {
60     int ret;
61
62     // XXX
63     __asm__ __volatile__("lduh [%1], %0\n\t"
64                          "stbar\n\t"
65                          :"=r"(ret):"r"(addr):"memory");
66
67     return ret;
68 }
69
70 static inline int in_be16(volatile unsigned short *addr)
71 {
72     int ret;
73
74     __asm__ __volatile__("lduh [%1], %0\n\t"
75                          "stbar\n\t"
76                          :"=r"(ret):"r"(addr):"memory");
77
78     return ret;
79 }
80
81 static inline void out_le16(volatile unsigned short *addr, int val)
82 {
83     // XXX
84     __asm__ __volatile__("sth %0, [%1]\n\t"
85                          "stbar\n\t"
86                          : : "r"(val), "r"(addr):"memory");
87 }
88
89 static inline void out_be16(volatile unsigned short *addr, int val)
90 {
91     __asm__ __volatile__("sth %0, [%1]\n\t"
92                          "stbar\n\t"
93                          : : "r"(val), "r"(addr):"memory");
94 }
95
96 static inline unsigned in_le32(volatile unsigned *addr)
97 {
98     unsigned ret;
99
100     // XXX
101     __asm__ __volatile__("ld [%1], %0\n\t"
102                          "stbar\n\t"
103                          :"=r"(ret):"r"(addr):"memory");
104
105     return ret;
106 }
107
108 static inline unsigned in_be32(volatile unsigned *addr)
109 {
110     unsigned ret;
111
112     __asm__ __volatile__("ld [%1], %0\n\t"
113                          "stbar\n\t"
114                          :"=r"(ret):"r"(addr):"memory");
115
116     return ret;
117 }
118
119 static inline void out_le32(volatile unsigned *addr, int val)
120 {
121     // XXX
122     __asm__ __volatile__("st %0, [%1]\n\t"
123                          "stbar\n\t"
124                          : : "r"(val), "r"(addr):"memory");
125 }
126
127 static inline void out_be32(volatile unsigned *addr, int val)
128 {
129     __asm__ __volatile__("st %0, [%1]\n\t"
130                          "stbar\n\t"
131                          : : "r"(val), "r"(addr):"memory");
132 }
133
134 static inline void _insw_ns(volatile uint16_t * port, void *buf, int ns)
135 {
136         uint16_t *b = (uint16_t *) buf;
137
138         while (ns > 0) {
139                 *b++ = in_le16(port);
140                 ns--;
141         }
142 }
143
144 static inline void _outsw_ns(volatile uint16_t * port, const void *buf,
145                              int ns)
146 {
147         uint16_t *b = (uint16_t *) buf;
148
149         while (ns > 0) {
150                 out_le16(port, *b++);
151                 ns--;
152         }
153 }
154
155 static inline void _insw(volatile uint16_t * port, void *buf, int ns)
156 {
157         uint16_t *b = (uint16_t *) buf;
158
159         while (ns > 0) {
160                 *b++ = in_be16(port);
161                 ns--;
162         }
163 }
164
165 static inline void _outsw(volatile uint16_t * port, const void *buf,
166                           int ns)
167 {
168         uint16_t *b = (uint16_t *) buf;
169
170         while (ns > 0) {
171                 out_be16(port, *b++);
172                 ns--;
173         }
174 }
175 #else /* BOOTSTRAP */
176 #ifdef FCOMPILER
177 #define inb(reg) ((u8)0xff)
178 #define inw(reg) ((u16)0xffff)
179 #define inl(reg) ((u32)0xffffffff)
180 #define outb(reg, val) do{} while(0)
181 #define outw(reg, val) do{} while(0)
182 #define outl(reg, val) do{} while(0)
183 #else
184 extern u8 inb(u32 reg);
185 extern u16 inw(u32 reg);
186 extern u32 inl(u32 reg);
187 extern void insw(u32 reg, void *addr, unsigned long count);
188 extern void outb(u32 reg, u8 val);
189 extern void outw(u32 reg, u16 val);
190 extern void outl(u32 reg, u32 val);
191 extern void outsw(u32 reg, const void *addr, unsigned long count);
192 #endif
193 #endif
194
195 #if defined(CONFIG_QEMU)
196 #define FW_CFG_ARCH_DEPTH        (FW_CFG_ARCH_LOCAL + 0x00)
197 #define FW_CFG_ARCH_WIDTH        (FW_CFG_ARCH_LOCAL + 0x01)
198 #define FW_CFG_ARCH_HEIGHT       (FW_CFG_ARCH_LOCAL + 0x02)
199 #endif
200
201 #endif /* _ASM_IO_H */