Statistics
| Branch: | Revision:

root / qemu-common.h @ bc20ba98

History | View | Annotate | Download (8.3 kB)

1 faf07963 pbrook
/* Common header file that is included by all of qemu.  */
2 faf07963 pbrook
#ifndef QEMU_COMMON_H
3 faf07963 pbrook
#define QEMU_COMMON_H
4 faf07963 pbrook
5 beb6f0de Kevin Wolf
#include "config-host.h"
6 beb6f0de Kevin Wolf
7 a5e50b26 malc
#define QEMU_NORETURN __attribute__ ((__noreturn__))
8 747bbdf7 Blue Swirl
#ifdef CONFIG_GCC_ATTRIBUTE_WARN_UNUSED_RESULT
9 747bbdf7 Blue Swirl
#define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
10 747bbdf7 Blue Swirl
#else
11 747bbdf7 Blue Swirl
#define QEMU_WARN_UNUSED_RESULT
12 747bbdf7 Blue Swirl
#endif
13 7d99a001 blueswir1
14 24ebf5f3 Paolo Bonzini
#define QEMU_BUILD_BUG_ON(x) typedef char __build_bug_on__##__LINE__[(x)?-1:1];
15 24ebf5f3 Paolo Bonzini
16 29e922b6 Blue Swirl
typedef struct QEMUTimer QEMUTimer;
17 29e922b6 Blue Swirl
typedef struct QEMUFile QEMUFile;
18 29e922b6 Blue Swirl
typedef struct QEMUBH QEMUBH;
19 92a16d7a Blue Swirl
typedef struct DeviceState DeviceState;
20 29e922b6 Blue Swirl
21 a5e50b26 malc
/* Hack around the mess dyngen-exec.h causes: We need QEMU_NORETURN in files that
22 7d99a001 blueswir1
   cannot include the following headers without conflicts. This condition has
23 7d99a001 blueswir1
   to be removed once dyngen is gone. */
24 7d99a001 blueswir1
#ifndef __DYNGEN_EXEC_H__
25 7d99a001 blueswir1
26 faf07963 pbrook
/* we put basic includes here to avoid repeating them in device drivers */
27 faf07963 pbrook
#include <stdlib.h>
28 faf07963 pbrook
#include <stdio.h>
29 faf07963 pbrook
#include <stdarg.h>
30 11165820 Paul Brook
#include <stdbool.h>
31 faf07963 pbrook
#include <string.h>
32 c8906845 balrog
#include <strings.h>
33 faf07963 pbrook
#include <inttypes.h>
34 faf07963 pbrook
#include <limits.h>
35 faf07963 pbrook
#include <time.h>
36 faf07963 pbrook
#include <ctype.h>
37 faf07963 pbrook
#include <errno.h>
38 faf07963 pbrook
#include <unistd.h>
39 faf07963 pbrook
#include <fcntl.h>
40 faf07963 pbrook
#include <sys/stat.h>
41 55616505 Paul Brook
#include <assert.h>
42 faf07963 pbrook
43 faf07963 pbrook
#ifndef O_LARGEFILE
44 faf07963 pbrook
#define O_LARGEFILE 0
45 faf07963 pbrook
#endif
46 faf07963 pbrook
#ifndef O_BINARY
47 faf07963 pbrook
#define O_BINARY 0
48 faf07963 pbrook
#endif
49 0e74e66b Juan Quintela
#ifndef MAP_ANONYMOUS
50 0e74e66b Juan Quintela
#define MAP_ANONYMOUS MAP_ANON
51 0e74e66b Juan Quintela
#endif
52 faf07963 pbrook
#ifndef ENOMEDIUM
53 faf07963 pbrook
#define ENOMEDIUM ENODEV
54 faf07963 pbrook
#endif
55 4c955388 Anthony Liguori
#if !defined(ENOTSUP)
56 2880bc32 Juan Quintela
#define ENOTSUP 4096
57 2880bc32 Juan Quintela
#endif
58 faf07963 pbrook
59 6114fdb0 Juan Quintela
#ifndef CONFIG_IOVEC
60 6114fdb0 Juan Quintela
#define CONFIG_IOVEC
61 bf9298b9 aliguori
struct iovec {
62 bf9298b9 aliguori
    void *iov_base;
63 bf9298b9 aliguori
    size_t iov_len;
64 bf9298b9 aliguori
};
65 e2a305fb Christoph Hellwig
/*
66 e2a305fb Christoph Hellwig
 * Use the same value as Linux for now.
67 e2a305fb Christoph Hellwig
 */
68 e2a305fb Christoph Hellwig
#define IOV_MAX                1024
69 331dadde blueswir1
#else
70 331dadde blueswir1
#include <sys/uio.h>
71 bf9298b9 aliguori
#endif
72 bf9298b9 aliguori
73 faf07963 pbrook
#ifdef _WIN32
74 faf07963 pbrook
#define fsync _commit
75 faf07963 pbrook
#define lseek _lseeki64
76 faf07963 pbrook
extern int qemu_ftruncate64(int, int64_t);
77 faf07963 pbrook
#define ftruncate qemu_ftruncate64
78 faf07963 pbrook
79 faf07963 pbrook
static inline char *realpath(const char *path, char *resolved_path)
80 faf07963 pbrook
{
81 faf07963 pbrook
    _fullpath(resolved_path, path, _MAX_PATH);
82 faf07963 pbrook
    return resolved_path;
83 faf07963 pbrook
}
84 faf07963 pbrook
85 faf07963 pbrook
#define PRId64 "I64d"
86 faf07963 pbrook
#define PRIx64 "I64x"
87 faf07963 pbrook
#define PRIu64 "I64u"
88 faf07963 pbrook
#define PRIo64 "I64o"
89 faf07963 pbrook
#endif
90 faf07963 pbrook
91 faf07963 pbrook
/* FIXME: Remove NEED_CPU_H.  */
92 faf07963 pbrook
#ifndef NEED_CPU_H
93 faf07963 pbrook
94 faf07963 pbrook
#include <setjmp.h>
95 faf07963 pbrook
#include "osdep.h"
96 faf07963 pbrook
#include "bswap.h"
97 faf07963 pbrook
98 faf07963 pbrook
#else
99 faf07963 pbrook
100 faf07963 pbrook
#include "cpu.h"
101 faf07963 pbrook
102 faf07963 pbrook
#endif /* !defined(NEED_CPU_H) */
103 faf07963 pbrook
104 faf07963 pbrook
/* bottom halves */
105 faf07963 pbrook
typedef void QEMUBHFunc(void *opaque);
106 faf07963 pbrook
107 9a1e9481 Kevin Wolf
void async_context_push(void);
108 9a1e9481 Kevin Wolf
void async_context_pop(void);
109 9a1e9481 Kevin Wolf
int get_async_context_id(void);
110 9a1e9481 Kevin Wolf
111 faf07963 pbrook
QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque);
112 faf07963 pbrook
void qemu_bh_schedule(QEMUBH *bh);
113 80d3580b aliguori
/* Bottom halfs that are scheduled from a bottom half handler are instantly
114 80d3580b aliguori
 * invoked.  This can create an infinite loop if a bottom half handler
115 80d3580b aliguori
 * schedules itself.  qemu_bh_schedule_idle() avoids this infinite loop by
116 80d3580b aliguori
 * ensuring that the bottom half isn't executed until the next main loop
117 80d3580b aliguori
 * iteration.
118 80d3580b aliguori
 */
119 1b435b10 aliguori
void qemu_bh_schedule_idle(QEMUBH *bh);
120 faf07963 pbrook
void qemu_bh_cancel(QEMUBH *bh);
121 faf07963 pbrook
void qemu_bh_delete(QEMUBH *bh);
122 faf07963 pbrook
int qemu_bh_poll(void);
123 4f999d05 Kevin Wolf
void qemu_bh_update_timeout(int *timeout);
124 faf07963 pbrook
125 87ecb68b pbrook
uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
126 87ecb68b pbrook
127 f6503059 balrog
void qemu_get_timedate(struct tm *tm, int offset);
128 f6503059 balrog
int qemu_timedate_diff(struct tm *tm);
129 f6503059 balrog
130 faf07963 pbrook
/* cutils.c */
131 faf07963 pbrook
void pstrcpy(char *buf, int buf_size, const char *str);
132 faf07963 pbrook
char *pstrcat(char *buf, int buf_size, const char *s);
133 faf07963 pbrook
int strstart(const char *str, const char *val, const char **ptr);
134 faf07963 pbrook
int stristart(const char *str, const char *val, const char **ptr);
135 d43277c5 Blue Swirl
int qemu_strnlen(const char *s, int max_len);
136 faf07963 pbrook
time_t mktimegm(struct tm *tm);
137 ad46db9a blueswir1
int qemu_fls(int i);
138 6f1953c4 Christoph Hellwig
int qemu_fdatasync(int fd);
139 db1a4972 Paolo Bonzini
int fcntl_setfl(int fd, int flag);
140 faf07963 pbrook
141 37022086 Blue Swirl
/* path.c */
142 37022086 Blue Swirl
void init_paths(const char *prefix);
143 37022086 Blue Swirl
const char *path(const char *pathname);
144 37022086 Blue Swirl
145 cd390083 blueswir1
#define qemu_isalnum(c)                isalnum((unsigned char)(c))
146 cd390083 blueswir1
#define qemu_isalpha(c)                isalpha((unsigned char)(c))
147 cd390083 blueswir1
#define qemu_iscntrl(c)                iscntrl((unsigned char)(c))
148 cd390083 blueswir1
#define qemu_isdigit(c)                isdigit((unsigned char)(c))
149 cd390083 blueswir1
#define qemu_isgraph(c)                isgraph((unsigned char)(c))
150 cd390083 blueswir1
#define qemu_islower(c)                islower((unsigned char)(c))
151 cd390083 blueswir1
#define qemu_isprint(c)                isprint((unsigned char)(c))
152 cd390083 blueswir1
#define qemu_ispunct(c)                ispunct((unsigned char)(c))
153 cd390083 blueswir1
#define qemu_isspace(c)                isspace((unsigned char)(c))
154 cd390083 blueswir1
#define qemu_isupper(c)                isupper((unsigned char)(c))
155 cd390083 blueswir1
#define qemu_isxdigit(c)        isxdigit((unsigned char)(c))
156 cd390083 blueswir1
#define qemu_tolower(c)                tolower((unsigned char)(c))
157 cd390083 blueswir1
#define qemu_toupper(c)                toupper((unsigned char)(c))
158 cd390083 blueswir1
#define qemu_isascii(c)                isascii((unsigned char)(c))
159 cd390083 blueswir1
#define qemu_toascii(c)                toascii((unsigned char)(c))
160 cd390083 blueswir1
161 ca10f867 aurel32
void *qemu_malloc(size_t size);
162 2137b4cc ths
void *qemu_realloc(void *ptr, size_t size);
163 ca10f867 aurel32
void *qemu_mallocz(size_t size);
164 ca10f867 aurel32
void qemu_free(void *ptr);
165 ca10f867 aurel32
char *qemu_strdup(const char *str);
166 ac4b0d0c balrog
char *qemu_strndup(const char *str, size_t size);
167 ca10f867 aurel32
168 d549db5a Glauber Costa
void qemu_mutex_lock_iothread(void);
169 d549db5a Glauber Costa
void qemu_mutex_unlock_iothread(void);
170 d549db5a Glauber Costa
171 40ff6d7e Kevin Wolf
int qemu_open(const char *name, int flags, ...);
172 7c7c0629 Juan Quintela
ssize_t qemu_write_full(int fd, const void *buf, size_t count)
173 7c7c0629 Juan Quintela
    QEMU_WARN_UNUSED_RESULT;
174 40ff6d7e Kevin Wolf
void qemu_set_cloexec(int fd);
175 40ff6d7e Kevin Wolf
176 40ff6d7e Kevin Wolf
#ifndef _WIN32
177 f3dfda61 Paolo Bonzini
int qemu_eventfd(int pipefd[2]);
178 40ff6d7e Kevin Wolf
int qemu_pipe(int pipefd[2]);
179 40ff6d7e Kevin Wolf
#endif
180 40ff6d7e Kevin Wolf
181 87ecb68b pbrook
/* Error handling.  */
182 87ecb68b pbrook
183 a5e50b26 malc
void QEMU_NORETURN hw_error(const char *fmt, ...)
184 7d99a001 blueswir1
    __attribute__ ((__format__ (__printf__, 1, 2)));
185 87ecb68b pbrook
186 87ecb68b pbrook
/* IO callbacks.  */
187 87ecb68b pbrook
typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
188 7b27a769 Juan Quintela
typedef int IOCanReadHandler(void *opaque);
189 87ecb68b pbrook
typedef void IOHandler(void *opaque);
190 87ecb68b pbrook
191 87ecb68b pbrook
struct ParallelIOArg {
192 87ecb68b pbrook
    void *buffer;
193 87ecb68b pbrook
    int count;
194 87ecb68b pbrook
};
195 87ecb68b pbrook
196 87ecb68b pbrook
typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
197 87ecb68b pbrook
198 87ecb68b pbrook
/* A load of opaque types so that device init declarations don't have to
199 87ecb68b pbrook
   pull in all the real definitions.  */
200 87ecb68b pbrook
typedef struct NICInfo NICInfo;
201 1ae26a18 balrog
typedef struct HCIInfo HCIInfo;
202 87ecb68b pbrook
typedef struct AudioState AudioState;
203 87ecb68b pbrook
typedef struct BlockDriverState BlockDriverState;
204 87ecb68b pbrook
typedef struct DisplayState DisplayState;
205 7d957bd8 aliguori
typedef struct DisplayChangeListener DisplayChangeListener;
206 7d957bd8 aliguori
typedef struct DisplaySurface DisplaySurface;
207 7b5d76da aliguori
typedef struct DisplayAllocator DisplayAllocator;
208 7d957bd8 aliguori
typedef struct PixelFormat PixelFormat;
209 87ecb68b pbrook
typedef struct TextConsole TextConsole;
210 c60e08d9 pbrook
typedef TextConsole QEMUConsole;
211 87ecb68b pbrook
typedef struct CharDriverState CharDriverState;
212 76d32cba Gerd Hoffmann
typedef struct MACAddr MACAddr;
213 87ecb68b pbrook
typedef struct VLANState VLANState;
214 f7105843 Mark McLoughlin
typedef struct VLANClientState VLANClientState;
215 87ecb68b pbrook
typedef struct i2c_bus i2c_bus;
216 87ecb68b pbrook
typedef struct i2c_slave i2c_slave;
217 87ecb68b pbrook
typedef struct SMBusDevice SMBusDevice;
218 fb47a2e9 Isaku Yamahata
typedef struct PCIHostState PCIHostState;
219 fb47a2e9 Isaku Yamahata
typedef struct PCIExpressHost PCIExpressHost;
220 87ecb68b pbrook
typedef struct PCIBus PCIBus;
221 87ecb68b pbrook
typedef struct PCIDevice PCIDevice;
222 0428527c Isaku Yamahata
typedef struct PCIExpressDevice PCIExpressDevice;
223 68f79994 Isaku Yamahata
typedef struct PCIBridge PCIBridge;
224 bc20ba98 Isaku Yamahata
typedef struct PCIEPort PCIEPort;
225 bc20ba98 Isaku Yamahata
typedef struct PCIESlot PCIESlot;
226 87ecb68b pbrook
typedef struct SerialState SerialState;
227 87ecb68b pbrook
typedef struct IRQState *qemu_irq;
228 bc24a225 Paul Brook
typedef struct PCMCIACardState PCMCIACardState;
229 bc24a225 Paul Brook
typedef struct MouseTransformInfo MouseTransformInfo;
230 bc24a225 Paul Brook
typedef struct uWireSlave uWireSlave;
231 bc24a225 Paul Brook
typedef struct I2SCodec I2SCodec;
232 90d37239 Paul Brook
typedef struct SSIBus SSIBus;
233 2292b339 Michael S. Tsirkin
typedef struct EventNotifier EventNotifier;
234 2be24aaa Michael S. Tsirkin
typedef struct VirtIODevice VirtIODevice;
235 87ecb68b pbrook
236 186993ee Michael S. Tsirkin
typedef uint64_t pcibus_t;
237 186993ee Michael S. Tsirkin
238 d2053c3c Blue Swirl
void cpu_exec_init_all(unsigned long tb_size);
239 d2053c3c Blue Swirl
240 b3c7724c pbrook
/* CPU save/load.  */
241 b3c7724c pbrook
void cpu_save(QEMUFile *f, void *opaque);
242 b3c7724c pbrook
int cpu_load(QEMUFile *f, void *opaque, int version_id);
243 b3c7724c pbrook
244 9e472e10 aliguori
/* Force QEMU to stop what it's doing and service IO */
245 9e472e10 aliguori
void qemu_service_io(void);
246 9e472e10 aliguori
247 d9f75a4e aliguori
/* Force QEMU to process pending events */
248 d9f75a4e aliguori
void qemu_notify_event(void);
249 d9f75a4e aliguori
250 8edac960 aliguori
/* Unblock cpu */
251 8edac960 aliguori
void qemu_cpu_kick(void *env);
252 8edac960 aliguori
int qemu_cpu_self(void *env);
253 8edac960 aliguori
254 e82bcec2 Marcelo Tosatti
/* work queue */
255 e82bcec2 Marcelo Tosatti
struct qemu_work_item {
256 e82bcec2 Marcelo Tosatti
    struct qemu_work_item *next;
257 e82bcec2 Marcelo Tosatti
    void (*func)(void *data);
258 e82bcec2 Marcelo Tosatti
    void *data;
259 e82bcec2 Marcelo Tosatti
    int done;
260 e82bcec2 Marcelo Tosatti
};
261 e82bcec2 Marcelo Tosatti
262 0bf46a40 aliguori
#ifdef CONFIG_USER_ONLY
263 0bf46a40 aliguori
#define qemu_init_vcpu(env) do { } while (0)
264 0bf46a40 aliguori
#else
265 0bf46a40 aliguori
void qemu_init_vcpu(void *env);
266 0bf46a40 aliguori
#endif
267 0bf46a40 aliguori
268 44e3ee8a aliguori
typedef struct QEMUIOVector {
269 44e3ee8a aliguori
    struct iovec *iov;
270 44e3ee8a aliguori
    int niov;
271 44e3ee8a aliguori
    int nalloc;
272 249aa745 aliguori
    size_t size;
273 44e3ee8a aliguori
} QEMUIOVector;
274 44e3ee8a aliguori
275 44e3ee8a aliguori
void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint);
276 522584a5 aliguori
void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov);
277 44e3ee8a aliguori
void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len);
278 40b4f539 Kevin Wolf
void qemu_iovec_concat(QEMUIOVector *dst, QEMUIOVector *src, size_t size);
279 44e3ee8a aliguori
void qemu_iovec_destroy(QEMUIOVector *qiov);
280 be959463 aliguori
void qemu_iovec_reset(QEMUIOVector *qiov);
281 44e3ee8a aliguori
void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf);
282 249aa745 aliguori
void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count);
283 44e3ee8a aliguori
284 376253ec aliguori
struct Monitor;
285 376253ec aliguori
typedef struct Monitor Monitor;
286 376253ec aliguori
287 abd0c6bd Paul Brook
/* Convert a byte between binary and BCD.  */
288 abd0c6bd Paul Brook
static inline uint8_t to_bcd(uint8_t val)
289 abd0c6bd Paul Brook
{
290 abd0c6bd Paul Brook
    return ((val / 10) << 4) | (val % 10);
291 abd0c6bd Paul Brook
}
292 abd0c6bd Paul Brook
293 abd0c6bd Paul Brook
static inline uint8_t from_bcd(uint8_t val)
294 abd0c6bd Paul Brook
{
295 abd0c6bd Paul Brook
    return ((val >> 4) * 10) + (val & 0x0f);
296 abd0c6bd Paul Brook
}
297 abd0c6bd Paul Brook
298 0bfe3ca5 Anthony Liguori
#include "module.h"
299 0bfe3ca5 Anthony Liguori
300 7d99a001 blueswir1
#endif /* dyngen-exec.h hack */
301 7d99a001 blueswir1
302 faf07963 pbrook
#endif