musicpal: use qdev properties for configuration.
[qemu/mdroth.git] / qemu-common.h
blob768e749feb14f3046f4aed84e21c31303fc97af1
1 /* Common header file that is included by all of qemu. */
2 #ifndef QEMU_COMMON_H
3 #define QEMU_COMMON_H
5 #define QEMU_NORETURN __attribute__ ((__noreturn__))
6 #ifdef CONFIG_GCC_ATTRIBUTE_WARN_UNUSED_RESULT
7 #define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
8 #else
9 #define QEMU_WARN_UNUSED_RESULT
10 #endif
12 /* Hack around the mess dyngen-exec.h causes: We need QEMU_NORETURN in files that
13 cannot include the following headers without conflicts. This condition has
14 to be removed once dyngen is gone. */
15 #ifndef __DYNGEN_EXEC_H__
17 /* we put basic includes here to avoid repeating them in device drivers */
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <stdarg.h>
21 #include <string.h>
22 #include <strings.h>
23 #include <inttypes.h>
24 #include <limits.h>
25 #include <time.h>
26 #include <ctype.h>
27 #include <errno.h>
28 #include <unistd.h>
29 #include <fcntl.h>
30 #include <sys/stat.h>
31 #include <assert.h>
32 #include "config-host.h"
34 #ifndef O_LARGEFILE
35 #define O_LARGEFILE 0
36 #endif
37 #ifndef O_BINARY
38 #define O_BINARY 0
39 #endif
40 #ifndef MAP_ANONYMOUS
41 #define MAP_ANONYMOUS MAP_ANON
42 #endif
43 #ifndef ENOMEDIUM
44 #define ENOMEDIUM ENODEV
45 #endif
46 #if !defined(ENOTSUP)
47 #define ENOTSUP 4096
48 #endif
50 #ifndef CONFIG_IOVEC
51 #define CONFIG_IOVEC
52 struct iovec {
53 void *iov_base;
54 size_t iov_len;
56 #else
57 #include <sys/uio.h>
58 #endif
60 #ifdef _WIN32
61 #define fsync _commit
62 #define lseek _lseeki64
63 extern int qemu_ftruncate64(int, int64_t);
64 #define ftruncate qemu_ftruncate64
66 static inline char *realpath(const char *path, char *resolved_path)
68 _fullpath(resolved_path, path, _MAX_PATH);
69 return resolved_path;
72 #define PRId64 "I64d"
73 #define PRIx64 "I64x"
74 #define PRIu64 "I64u"
75 #define PRIo64 "I64o"
76 #endif
78 /* FIXME: Remove NEED_CPU_H. */
79 #ifndef NEED_CPU_H
81 #include <setjmp.h>
82 #include "osdep.h"
83 #include "bswap.h"
85 #else
87 #include "cpu.h"
89 #endif /* !defined(NEED_CPU_H) */
91 /* bottom halves */
92 typedef struct QEMUBH QEMUBH;
94 typedef void QEMUBHFunc(void *opaque);
96 QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque);
97 void qemu_bh_schedule(QEMUBH *bh);
98 /* Bottom halfs that are scheduled from a bottom half handler are instantly
99 * invoked. This can create an infinite loop if a bottom half handler
100 * schedules itself. qemu_bh_schedule_idle() avoids this infinite loop by
101 * ensuring that the bottom half isn't executed until the next main loop
102 * iteration.
104 void qemu_bh_schedule_idle(QEMUBH *bh);
105 void qemu_bh_cancel(QEMUBH *bh);
106 void qemu_bh_delete(QEMUBH *bh);
107 int qemu_bh_poll(void);
109 uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
111 void qemu_get_timedate(struct tm *tm, int offset);
112 int qemu_timedate_diff(struct tm *tm);
114 /* cutils.c */
115 void pstrcpy(char *buf, int buf_size, const char *str);
116 char *pstrcat(char *buf, int buf_size, const char *s);
117 int strstart(const char *str, const char *val, const char **ptr);
118 int stristart(const char *str, const char *val, const char **ptr);
119 int qemu_strnlen(const char *s, int max_len);
120 time_t mktimegm(struct tm *tm);
121 int qemu_fls(int i);
122 int qemu_fdatasync(int fd);
124 /* path.c */
125 void init_paths(const char *prefix);
126 const char *path(const char *pathname);
128 #define qemu_isalnum(c) isalnum((unsigned char)(c))
129 #define qemu_isalpha(c) isalpha((unsigned char)(c))
130 #define qemu_iscntrl(c) iscntrl((unsigned char)(c))
131 #define qemu_isdigit(c) isdigit((unsigned char)(c))
132 #define qemu_isgraph(c) isgraph((unsigned char)(c))
133 #define qemu_islower(c) islower((unsigned char)(c))
134 #define qemu_isprint(c) isprint((unsigned char)(c))
135 #define qemu_ispunct(c) ispunct((unsigned char)(c))
136 #define qemu_isspace(c) isspace((unsigned char)(c))
137 #define qemu_isupper(c) isupper((unsigned char)(c))
138 #define qemu_isxdigit(c) isxdigit((unsigned char)(c))
139 #define qemu_tolower(c) tolower((unsigned char)(c))
140 #define qemu_toupper(c) toupper((unsigned char)(c))
141 #define qemu_isascii(c) isascii((unsigned char)(c))
142 #define qemu_toascii(c) toascii((unsigned char)(c))
144 void *qemu_malloc(size_t size);
145 void *qemu_realloc(void *ptr, size_t size);
146 void *qemu_mallocz(size_t size);
147 void qemu_free(void *ptr);
148 char *qemu_strdup(const char *str);
149 char *qemu_strndup(const char *str, size_t size);
151 void *get_mmap_addr(unsigned long size);
154 void qemu_mutex_lock_iothread(void);
155 void qemu_mutex_unlock_iothread(void);
157 /* Error handling. */
159 void QEMU_NORETURN hw_error(const char *fmt, ...)
160 __attribute__ ((__format__ (__printf__, 1, 2)));
162 /* IO callbacks. */
163 typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
164 typedef int IOCanRWHandler(void *opaque);
165 typedef void IOHandler(void *opaque);
167 struct ParallelIOArg {
168 void *buffer;
169 int count;
172 typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
174 /* A load of opaque types so that device init declarations don't have to
175 pull in all the real definitions. */
176 typedef struct NICInfo NICInfo;
177 typedef struct HCIInfo HCIInfo;
178 typedef struct AudioState AudioState;
179 typedef struct BlockDriverState BlockDriverState;
180 typedef struct DisplayState DisplayState;
181 typedef struct DisplayChangeListener DisplayChangeListener;
182 typedef struct DisplaySurface DisplaySurface;
183 typedef struct DisplayAllocator DisplayAllocator;
184 typedef struct PixelFormat PixelFormat;
185 typedef struct TextConsole TextConsole;
186 typedef TextConsole QEMUConsole;
187 typedef struct CharDriverState CharDriverState;
188 typedef struct MACAddr MACAddr;
189 typedef struct VLANState VLANState;
190 typedef struct VLANClientState VLANClientState;
191 typedef struct QEMUFile QEMUFile;
192 typedef struct i2c_bus i2c_bus;
193 typedef struct i2c_slave i2c_slave;
194 typedef struct SMBusDevice SMBusDevice;
195 typedef struct QEMUTimer QEMUTimer;
196 typedef struct PCIBus PCIBus;
197 typedef struct PCIDevice PCIDevice;
198 typedef struct SerialState SerialState;
199 typedef struct IRQState *qemu_irq;
200 typedef struct PCMCIACardState PCMCIACardState;
201 typedef struct MouseTransformInfo MouseTransformInfo;
202 typedef struct uWireSlave uWireSlave;
203 typedef struct I2SCodec I2SCodec;
204 typedef struct DeviceState DeviceState;
205 typedef struct SSIBus SSIBus;
207 /* CPU save/load. */
208 void cpu_save(QEMUFile *f, void *opaque);
209 int cpu_load(QEMUFile *f, void *opaque, int version_id);
211 /* Force QEMU to stop what it's doing and service IO */
212 void qemu_service_io(void);
214 /* Force QEMU to process pending events */
215 void qemu_notify_event(void);
217 /* Unblock cpu */
218 void qemu_cpu_kick(void *env);
219 int qemu_cpu_self(void *env);
221 #ifdef CONFIG_USER_ONLY
222 #define qemu_init_vcpu(env) do { } while (0)
223 #else
224 void qemu_init_vcpu(void *env);
225 #endif
227 typedef struct QEMUIOVector {
228 struct iovec *iov;
229 int niov;
230 int nalloc;
231 size_t size;
232 } QEMUIOVector;
234 void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint);
235 void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov);
236 void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len);
237 void qemu_iovec_concat(QEMUIOVector *dst, QEMUIOVector *src, size_t size);
238 void qemu_iovec_destroy(QEMUIOVector *qiov);
239 void qemu_iovec_reset(QEMUIOVector *qiov);
240 void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf);
241 void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count);
243 struct Monitor;
244 typedef struct Monitor Monitor;
246 #include "module.h"
248 #endif /* dyngen-exec.h hack */
250 #endif