Statistics
| Branch: | Revision:

root / qemu-common.h @ 6fb6d245

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