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