root / qemu-common.h @ 46d62fac
History | View | Annotate | Download (10.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 | faf07963 | pbrook | /* we put basic includes here to avoid repeating them in device drivers */
|
22 | faf07963 | pbrook | #include <stdlib.h> |
23 | faf07963 | pbrook | #include <stdio.h> |
24 | faf07963 | pbrook | #include <stdarg.h> |
25 | 11165820 | Paul Brook | #include <stdbool.h> |
26 | faf07963 | pbrook | #include <string.h> |
27 | c8906845 | balrog | #include <strings.h> |
28 | faf07963 | pbrook | #include <inttypes.h> |
29 | faf07963 | pbrook | #include <limits.h> |
30 | faf07963 | pbrook | #include <time.h> |
31 | faf07963 | pbrook | #include <ctype.h> |
32 | faf07963 | pbrook | #include <errno.h> |
33 | faf07963 | pbrook | #include <unistd.h> |
34 | faf07963 | pbrook | #include <fcntl.h> |
35 | faf07963 | pbrook | #include <sys/stat.h> |
36 | 55616505 | Paul Brook | #include <assert.h> |
37 | faf07963 | pbrook | |
38 | faf07963 | pbrook | #ifndef O_LARGEFILE
|
39 | faf07963 | pbrook | #define O_LARGEFILE 0 |
40 | faf07963 | pbrook | #endif
|
41 | faf07963 | pbrook | #ifndef O_BINARY
|
42 | faf07963 | pbrook | #define O_BINARY 0 |
43 | faf07963 | pbrook | #endif
|
44 | 0e74e66b | Juan Quintela | #ifndef MAP_ANONYMOUS
|
45 | 0e74e66b | Juan Quintela | #define MAP_ANONYMOUS MAP_ANON
|
46 | 0e74e66b | Juan Quintela | #endif
|
47 | faf07963 | pbrook | #ifndef ENOMEDIUM
|
48 | faf07963 | pbrook | #define ENOMEDIUM ENODEV
|
49 | faf07963 | pbrook | #endif
|
50 | 4c955388 | Anthony Liguori | #if !defined(ENOTSUP)
|
51 | 2880bc32 | Juan Quintela | #define ENOTSUP 4096 |
52 | 2880bc32 | Juan Quintela | #endif
|
53 | 3c9405a0 | Gerd Hoffmann | #ifndef TIME_MAX
|
54 | 3c9405a0 | Gerd Hoffmann | #define TIME_MAX LONG_MAX
|
55 | 3c9405a0 | Gerd Hoffmann | #endif
|
56 | faf07963 | pbrook | |
57 | 6114fdb0 | Juan Quintela | #ifndef CONFIG_IOVEC
|
58 | 6114fdb0 | Juan Quintela | #define CONFIG_IOVEC
|
59 | bf9298b9 | aliguori | struct iovec {
|
60 | bf9298b9 | aliguori | void *iov_base;
|
61 | bf9298b9 | aliguori | size_t iov_len; |
62 | bf9298b9 | aliguori | }; |
63 | e2a305fb | Christoph Hellwig | /*
|
64 | e2a305fb | Christoph Hellwig | * Use the same value as Linux for now.
|
65 | e2a305fb | Christoph Hellwig | */
|
66 | e2a305fb | Christoph Hellwig | #define IOV_MAX 1024 |
67 | 331dadde | blueswir1 | #else
|
68 | 331dadde | blueswir1 | #include <sys/uio.h> |
69 | bf9298b9 | aliguori | #endif
|
70 | bf9298b9 | aliguori | |
71 | 9c9e7d51 | Stefan Weil | #if defined __GNUC__
|
72 | 9c9e7d51 | Stefan Weil | # if (__GNUC__ < 4) || \ |
73 | 9c9e7d51 | Stefan Weil | defined(__GNUC_MINOR__) && (__GNUC__ == 4) && (__GNUC_MINOR__ < 4) |
74 | 9c9e7d51 | Stefan Weil | /* gcc versions before 4.4.x don't support gnu_printf, so use printf. */
|
75 | 9c9e7d51 | Stefan Weil | # define GCC_ATTR __attribute__((__unused__, format(printf, 1, 2))) |
76 | 9c9e7d51 | Stefan Weil | # define GCC_FMT_ATTR(n, m) __attribute__((format(printf, n, m)))
|
77 | 9c9e7d51 | Stefan Weil | # else
|
78 | 9c9e7d51 | Stefan Weil | /* Use gnu_printf when supported (qemu uses standard format strings). */
|
79 | 9c9e7d51 | Stefan Weil | # define GCC_ATTR __attribute__((__unused__, format(gnu_printf, 1, 2))) |
80 | 9c9e7d51 | Stefan Weil | # define GCC_FMT_ATTR(n, m) __attribute__((format(gnu_printf, n, m)))
|
81 | 9c9e7d51 | Stefan Weil | # endif
|
82 | 9c9e7d51 | Stefan Weil | #else
|
83 | 9c9e7d51 | Stefan Weil | #define GCC_ATTR /**/ |
84 | 9c9e7d51 | Stefan Weil | #define GCC_FMT_ATTR(n, m)
|
85 | 9c9e7d51 | Stefan Weil | #endif
|
86 | 9c9e7d51 | Stefan Weil | |
87 | f868445a | Stefan Weil | typedef int (*fprintf_function)(FILE *f, const char *fmt, ...) |
88 | f868445a | Stefan Weil | GCC_FMT_ATTR(2, 3); |
89 | f868445a | Stefan Weil | |
90 | faf07963 | pbrook | #ifdef _WIN32
|
91 | faf07963 | pbrook | #define fsync _commit
|
92 | faf07963 | pbrook | #define lseek _lseeki64
|
93 | 64b85a8f | Blue Swirl | int qemu_ftruncate64(int, int64_t); |
94 | faf07963 | pbrook | #define ftruncate qemu_ftruncate64
|
95 | faf07963 | pbrook | |
96 | faf07963 | pbrook | static inline char *realpath(const char *path, char *resolved_path) |
97 | faf07963 | pbrook | { |
98 | faf07963 | pbrook | _fullpath(resolved_path, path, _MAX_PATH); |
99 | faf07963 | pbrook | return resolved_path;
|
100 | faf07963 | pbrook | } |
101 | faf07963 | pbrook | |
102 | faf07963 | pbrook | #define PRId64 "I64d" |
103 | faf07963 | pbrook | #define PRIx64 "I64x" |
104 | faf07963 | pbrook | #define PRIu64 "I64u" |
105 | faf07963 | pbrook | #define PRIo64 "I64o" |
106 | faf07963 | pbrook | #endif
|
107 | faf07963 | pbrook | |
108 | faf07963 | pbrook | /* FIXME: Remove NEED_CPU_H. */
|
109 | faf07963 | pbrook | #ifndef NEED_CPU_H
|
110 | faf07963 | pbrook | |
111 | faf07963 | pbrook | #include <setjmp.h> |
112 | faf07963 | pbrook | #include "osdep.h" |
113 | faf07963 | pbrook | #include "bswap.h" |
114 | faf07963 | pbrook | |
115 | faf07963 | pbrook | #else
|
116 | faf07963 | pbrook | |
117 | faf07963 | pbrook | #include "cpu.h" |
118 | faf07963 | pbrook | |
119 | faf07963 | pbrook | #endif /* !defined(NEED_CPU_H) */ |
120 | faf07963 | pbrook | |
121 | faf07963 | pbrook | /* bottom halves */
|
122 | faf07963 | pbrook | typedef void QEMUBHFunc(void *opaque); |
123 | faf07963 | pbrook | |
124 | 9a1e9481 | Kevin Wolf | void async_context_push(void); |
125 | 9a1e9481 | Kevin Wolf | void async_context_pop(void); |
126 | 9a1e9481 | Kevin Wolf | int get_async_context_id(void); |
127 | 9a1e9481 | Kevin Wolf | |
128 | faf07963 | pbrook | QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque);
|
129 | faf07963 | pbrook | void qemu_bh_schedule(QEMUBH *bh);
|
130 | 80d3580b | aliguori | /* Bottom halfs that are scheduled from a bottom half handler are instantly
|
131 | 80d3580b | aliguori | * invoked. This can create an infinite loop if a bottom half handler
|
132 | 80d3580b | aliguori | * schedules itself. qemu_bh_schedule_idle() avoids this infinite loop by
|
133 | 80d3580b | aliguori | * ensuring that the bottom half isn't executed until the next main loop
|
134 | 80d3580b | aliguori | * iteration.
|
135 | 80d3580b | aliguori | */
|
136 | 1b435b10 | aliguori | void qemu_bh_schedule_idle(QEMUBH *bh);
|
137 | faf07963 | pbrook | void qemu_bh_cancel(QEMUBH *bh);
|
138 | faf07963 | pbrook | void qemu_bh_delete(QEMUBH *bh);
|
139 | faf07963 | pbrook | int qemu_bh_poll(void); |
140 | 4f999d05 | Kevin Wolf | void qemu_bh_update_timeout(int *timeout); |
141 | faf07963 | pbrook | |
142 | f6503059 | balrog | void qemu_get_timedate(struct tm *tm, int offset); |
143 | f6503059 | balrog | int qemu_timedate_diff(struct tm *tm); |
144 | f6503059 | balrog | |
145 | faf07963 | pbrook | /* cutils.c */
|
146 | faf07963 | pbrook | void pstrcpy(char *buf, int buf_size, const char *str); |
147 | faf07963 | pbrook | char *pstrcat(char *buf, int buf_size, const char *s); |
148 | faf07963 | pbrook | int strstart(const char *str, const char *val, const char **ptr); |
149 | faf07963 | pbrook | int stristart(const char *str, const char *val, const char **ptr); |
150 | d43277c5 | Blue Swirl | int qemu_strnlen(const char *s, int max_len); |
151 | faf07963 | pbrook | time_t mktimegm(struct tm *tm);
|
152 | ad46db9a | blueswir1 | int qemu_fls(int i); |
153 | 6f1953c4 | Christoph Hellwig | int qemu_fdatasync(int fd); |
154 | db1a4972 | Paolo Bonzini | int fcntl_setfl(int fd, int flag); |
155 | d8427002 | Jes Sorensen | |
156 | d7142456 | Jes Sorensen | /*
|
157 | d7142456 | Jes Sorensen | * strtosz() suffixes used to specify the default treatment of an
|
158 | d7142456 | Jes Sorensen | * argument passed to strtosz() without an explicit suffix.
|
159 | d7142456 | Jes Sorensen | * These should be defined using upper case characters in the range
|
160 | d7142456 | Jes Sorensen | * A-Z, as strtosz() will use qemu_toupper() on the given argument
|
161 | d7142456 | Jes Sorensen | * prior to comparison.
|
162 | d7142456 | Jes Sorensen | */
|
163 | d8427002 | Jes Sorensen | #define STRTOSZ_DEFSUFFIX_TB 'T' |
164 | d8427002 | Jes Sorensen | #define STRTOSZ_DEFSUFFIX_GB 'G' |
165 | d8427002 | Jes Sorensen | #define STRTOSZ_DEFSUFFIX_MB 'M' |
166 | d8427002 | Jes Sorensen | #define STRTOSZ_DEFSUFFIX_KB 'K' |
167 | d8427002 | Jes Sorensen | #define STRTOSZ_DEFSUFFIX_B 'B' |
168 | 70b4f4bb | Jes Sorensen | int64_t strtosz(const char *nptr, char **end); |
169 | 70b4f4bb | Jes Sorensen | int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix); |
170 | faf07963 | pbrook | |
171 | 37022086 | Blue Swirl | /* path.c */
|
172 | 37022086 | Blue Swirl | void init_paths(const char *prefix); |
173 | 37022086 | Blue Swirl | const char *path(const char *pathname); |
174 | 37022086 | Blue Swirl | |
175 | cd390083 | blueswir1 | #define qemu_isalnum(c) isalnum((unsigned char)(c)) |
176 | cd390083 | blueswir1 | #define qemu_isalpha(c) isalpha((unsigned char)(c)) |
177 | cd390083 | blueswir1 | #define qemu_iscntrl(c) iscntrl((unsigned char)(c)) |
178 | cd390083 | blueswir1 | #define qemu_isdigit(c) isdigit((unsigned char)(c)) |
179 | cd390083 | blueswir1 | #define qemu_isgraph(c) isgraph((unsigned char)(c)) |
180 | cd390083 | blueswir1 | #define qemu_islower(c) islower((unsigned char)(c)) |
181 | cd390083 | blueswir1 | #define qemu_isprint(c) isprint((unsigned char)(c)) |
182 | cd390083 | blueswir1 | #define qemu_ispunct(c) ispunct((unsigned char)(c)) |
183 | cd390083 | blueswir1 | #define qemu_isspace(c) isspace((unsigned char)(c)) |
184 | cd390083 | blueswir1 | #define qemu_isupper(c) isupper((unsigned char)(c)) |
185 | cd390083 | blueswir1 | #define qemu_isxdigit(c) isxdigit((unsigned char)(c)) |
186 | cd390083 | blueswir1 | #define qemu_tolower(c) tolower((unsigned char)(c)) |
187 | cd390083 | blueswir1 | #define qemu_toupper(c) toupper((unsigned char)(c)) |
188 | cd390083 | blueswir1 | #define qemu_isascii(c) isascii((unsigned char)(c)) |
189 | cd390083 | blueswir1 | #define qemu_toascii(c) toascii((unsigned char)(c)) |
190 | cd390083 | blueswir1 | |
191 | dc786bc9 | Jes Sorensen | #ifdef _WIN32
|
192 | dc786bc9 | Jes Sorensen | /* ffs() in oslib-win32.c for WIN32, strings.h for the rest of the world */
|
193 | dc786bc9 | Jes Sorensen | int ffs(int i); |
194 | dc786bc9 | Jes Sorensen | #endif
|
195 | dc786bc9 | Jes Sorensen | |
196 | b152aa84 | Jes Sorensen | void *qemu_oom_check(void *ptr); |
197 | ca10f867 | aurel32 | void *qemu_malloc(size_t size);
|
198 | 2137b4cc | ths | void *qemu_realloc(void *ptr, size_t size); |
199 | ca10f867 | aurel32 | void *qemu_mallocz(size_t size);
|
200 | ca10f867 | aurel32 | void qemu_free(void *ptr); |
201 | ca10f867 | aurel32 | char *qemu_strdup(const char *str); |
202 | ac4b0d0c | balrog | char *qemu_strndup(const char *str, size_t size); |
203 | ca10f867 | aurel32 | |
204 | d549db5a | Glauber Costa | void qemu_mutex_lock_iothread(void); |
205 | d549db5a | Glauber Costa | void qemu_mutex_unlock_iothread(void); |
206 | d549db5a | Glauber Costa | |
207 | 40ff6d7e | Kevin Wolf | int qemu_open(const char *name, int flags, ...); |
208 | 7c7c0629 | Juan Quintela | ssize_t qemu_write_full(int fd, const void *buf, size_t count) |
209 | 7c7c0629 | Juan Quintela | QEMU_WARN_UNUSED_RESULT; |
210 | 40ff6d7e | Kevin Wolf | void qemu_set_cloexec(int fd); |
211 | 40ff6d7e | Kevin Wolf | |
212 | 40ff6d7e | Kevin Wolf | #ifndef _WIN32
|
213 | f3dfda61 | Paolo Bonzini | int qemu_eventfd(int pipefd[2]); |
214 | 40ff6d7e | Kevin Wolf | int qemu_pipe(int pipefd[2]); |
215 | 40ff6d7e | Kevin Wolf | #endif
|
216 | 40ff6d7e | Kevin Wolf | |
217 | 87ecb68b | pbrook | /* Error handling. */
|
218 | 87ecb68b | pbrook | |
219 | e5924d89 | Stefan Weil | void QEMU_NORETURN hw_error(const char *fmt, ...) GCC_FMT_ATTR(1, 2); |
220 | 87ecb68b | pbrook | |
221 | 87ecb68b | pbrook | /* IO callbacks. */
|
222 | 87ecb68b | pbrook | typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size); |
223 | 7b27a769 | Juan Quintela | typedef int IOCanReadHandler(void *opaque); |
224 | 87ecb68b | pbrook | typedef void IOHandler(void *opaque); |
225 | 87ecb68b | pbrook | |
226 | 87ecb68b | pbrook | struct ParallelIOArg {
|
227 | 87ecb68b | pbrook | void *buffer;
|
228 | 87ecb68b | pbrook | int count;
|
229 | 87ecb68b | pbrook | }; |
230 | 87ecb68b | pbrook | |
231 | 87ecb68b | pbrook | typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size); |
232 | 87ecb68b | pbrook | |
233 | 87ecb68b | pbrook | /* A load of opaque types so that device init declarations don't have to
|
234 | 87ecb68b | pbrook | pull in all the real definitions. */
|
235 | 87ecb68b | pbrook | typedef struct NICInfo NICInfo; |
236 | 1ae26a18 | balrog | typedef struct HCIInfo HCIInfo; |
237 | 87ecb68b | pbrook | typedef struct AudioState AudioState; |
238 | 87ecb68b | pbrook | typedef struct BlockDriverState BlockDriverState; |
239 | 2446333c | Blue Swirl | typedef struct DriveInfo DriveInfo; |
240 | 87ecb68b | pbrook | typedef struct DisplayState DisplayState; |
241 | 7d957bd8 | aliguori | typedef struct DisplayChangeListener DisplayChangeListener; |
242 | 7d957bd8 | aliguori | typedef struct DisplaySurface DisplaySurface; |
243 | 7b5d76da | aliguori | typedef struct DisplayAllocator DisplayAllocator; |
244 | 7d957bd8 | aliguori | typedef struct PixelFormat PixelFormat; |
245 | 87ecb68b | pbrook | typedef struct TextConsole TextConsole; |
246 | c60e08d9 | pbrook | typedef TextConsole QEMUConsole;
|
247 | 87ecb68b | pbrook | typedef struct CharDriverState CharDriverState; |
248 | 76d32cba | Gerd Hoffmann | typedef struct MACAddr MACAddr; |
249 | 87ecb68b | pbrook | typedef struct VLANState VLANState; |
250 | f7105843 | Mark McLoughlin | typedef struct VLANClientState VLANClientState; |
251 | 87ecb68b | pbrook | typedef struct i2c_bus i2c_bus; |
252 | 87ecb68b | pbrook | typedef struct i2c_slave i2c_slave; |
253 | 87ecb68b | pbrook | typedef struct SMBusDevice SMBusDevice; |
254 | fb47a2e9 | Isaku Yamahata | typedef struct PCIHostState PCIHostState; |
255 | fb47a2e9 | Isaku Yamahata | typedef struct PCIExpressHost PCIExpressHost; |
256 | 87ecb68b | pbrook | typedef struct PCIBus PCIBus; |
257 | 87ecb68b | pbrook | typedef struct PCIDevice PCIDevice; |
258 | 0428527c | Isaku Yamahata | typedef struct PCIExpressDevice PCIExpressDevice; |
259 | 68f79994 | Isaku Yamahata | typedef struct PCIBridge PCIBridge; |
260 | 34e65944 | Isaku Yamahata | typedef struct PCIEAERMsg PCIEAERMsg; |
261 | 34e65944 | Isaku Yamahata | typedef struct PCIEAERLog PCIEAERLog; |
262 | 34e65944 | Isaku Yamahata | typedef struct PCIEAERErr PCIEAERErr; |
263 | bc20ba98 | Isaku Yamahata | typedef struct PCIEPort PCIEPort; |
264 | bc20ba98 | Isaku Yamahata | typedef struct PCIESlot PCIESlot; |
265 | 87ecb68b | pbrook | typedef struct SerialState SerialState; |
266 | 87ecb68b | pbrook | typedef struct IRQState *qemu_irq; |
267 | bc24a225 | Paul Brook | typedef struct PCMCIACardState PCMCIACardState; |
268 | bc24a225 | Paul Brook | typedef struct MouseTransformInfo MouseTransformInfo; |
269 | bc24a225 | Paul Brook | typedef struct uWireSlave uWireSlave; |
270 | bc24a225 | Paul Brook | typedef struct I2SCodec I2SCodec; |
271 | 90d37239 | Paul Brook | typedef struct SSIBus SSIBus; |
272 | 2292b339 | Michael S. Tsirkin | typedef struct EventNotifier EventNotifier; |
273 | 2be24aaa | Michael S. Tsirkin | typedef struct VirtIODevice VirtIODevice; |
274 | 87ecb68b | pbrook | |
275 | 186993ee | Michael S. Tsirkin | typedef uint64_t pcibus_t;
|
276 | 186993ee | Michael S. Tsirkin | |
277 | d2053c3c | Blue Swirl | void cpu_exec_init_all(unsigned long tb_size); |
278 | d2053c3c | Blue Swirl | |
279 | b3c7724c | pbrook | /* CPU save/load. */
|
280 | b3c7724c | pbrook | void cpu_save(QEMUFile *f, void *opaque); |
281 | b3c7724c | pbrook | int cpu_load(QEMUFile *f, void *opaque, int version_id); |
282 | b3c7724c | pbrook | |
283 | 9e472e10 | aliguori | /* Force QEMU to stop what it's doing and service IO */
|
284 | 9e472e10 | aliguori | void qemu_service_io(void); |
285 | 9e472e10 | aliguori | |
286 | d9f75a4e | aliguori | /* Force QEMU to process pending events */
|
287 | d9f75a4e | aliguori | void qemu_notify_event(void); |
288 | d9f75a4e | aliguori | |
289 | 8edac960 | aliguori | /* Unblock cpu */
|
290 | 8edac960 | aliguori | void qemu_cpu_kick(void *env); |
291 | 46d62fac | Jan Kiszka | void qemu_cpu_kick_self(void); |
292 | 8edac960 | aliguori | int qemu_cpu_self(void *env); |
293 | 8edac960 | aliguori | |
294 | e82bcec2 | Marcelo Tosatti | /* work queue */
|
295 | e82bcec2 | Marcelo Tosatti | struct qemu_work_item {
|
296 | e82bcec2 | Marcelo Tosatti | struct qemu_work_item *next;
|
297 | e82bcec2 | Marcelo Tosatti | void (*func)(void *data); |
298 | e82bcec2 | Marcelo Tosatti | void *data;
|
299 | e82bcec2 | Marcelo Tosatti | int done;
|
300 | e82bcec2 | Marcelo Tosatti | }; |
301 | e82bcec2 | Marcelo Tosatti | |
302 | 0bf46a40 | aliguori | #ifdef CONFIG_USER_ONLY
|
303 | 0bf46a40 | aliguori | #define qemu_init_vcpu(env) do { } while (0) |
304 | 0bf46a40 | aliguori | #else
|
305 | 0bf46a40 | aliguori | void qemu_init_vcpu(void *env); |
306 | 0bf46a40 | aliguori | #endif
|
307 | 0bf46a40 | aliguori | |
308 | 44e3ee8a | aliguori | typedef struct QEMUIOVector { |
309 | 44e3ee8a | aliguori | struct iovec *iov;
|
310 | 44e3ee8a | aliguori | int niov;
|
311 | 44e3ee8a | aliguori | int nalloc;
|
312 | 249aa745 | aliguori | size_t size; |
313 | 44e3ee8a | aliguori | } QEMUIOVector; |
314 | 44e3ee8a | aliguori | |
315 | 44e3ee8a | aliguori | void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint); |
316 | 522584a5 | aliguori | void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov); |
317 | 44e3ee8a | aliguori | void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len); |
318 | b8a83a4f | Kevin Wolf | void qemu_iovec_copy(QEMUIOVector *dst, QEMUIOVector *src, uint64_t skip,
|
319 | b8a83a4f | Kevin Wolf | size_t size); |
320 | 40b4f539 | Kevin Wolf | void qemu_iovec_concat(QEMUIOVector *dst, QEMUIOVector *src, size_t size);
|
321 | 44e3ee8a | aliguori | void qemu_iovec_destroy(QEMUIOVector *qiov);
|
322 | be959463 | aliguori | void qemu_iovec_reset(QEMUIOVector *qiov);
|
323 | 44e3ee8a | aliguori | void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf); |
324 | 249aa745 | aliguori | void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count); |
325 | b8a83a4f | Kevin Wolf | void qemu_iovec_memset(QEMUIOVector *qiov, int c, size_t count); |
326 | 44e3ee8a | aliguori | |
327 | 376253ec | aliguori | struct Monitor;
|
328 | 376253ec | aliguori | typedef struct Monitor Monitor; |
329 | 376253ec | aliguori | |
330 | abd0c6bd | Paul Brook | /* Convert a byte between binary and BCD. */
|
331 | abd0c6bd | Paul Brook | static inline uint8_t to_bcd(uint8_t val) |
332 | abd0c6bd | Paul Brook | { |
333 | abd0c6bd | Paul Brook | return ((val / 10) << 4) | (val % 10); |
334 | abd0c6bd | Paul Brook | } |
335 | abd0c6bd | Paul Brook | |
336 | abd0c6bd | Paul Brook | static inline uint8_t from_bcd(uint8_t val) |
337 | abd0c6bd | Paul Brook | { |
338 | abd0c6bd | Paul Brook | return ((val >> 4) * 10) + (val & 0x0f); |
339 | abd0c6bd | Paul Brook | } |
340 | abd0c6bd | Paul Brook | |
341 | 338b922e | malc | /* compute with 96 bit intermediate result: (a*b)/c */
|
342 | 338b922e | malc | static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) |
343 | 338b922e | malc | { |
344 | 338b922e | malc | union {
|
345 | 338b922e | malc | uint64_t ll; |
346 | 338b922e | malc | struct {
|
347 | 338b922e | malc | #ifdef HOST_WORDS_BIGENDIAN
|
348 | 338b922e | malc | uint32_t high, low; |
349 | 338b922e | malc | #else
|
350 | 338b922e | malc | uint32_t low, high; |
351 | 338b922e | malc | #endif
|
352 | 338b922e | malc | } l; |
353 | 338b922e | malc | } u, res; |
354 | 338b922e | malc | uint64_t rl, rh; |
355 | 338b922e | malc | |
356 | 338b922e | malc | u.ll = a; |
357 | 338b922e | malc | rl = (uint64_t)u.l.low * (uint64_t)b; |
358 | 338b922e | malc | rh = (uint64_t)u.l.high * (uint64_t)b; |
359 | 338b922e | malc | rh += (rl >> 32);
|
360 | 338b922e | malc | res.l.high = rh / c; |
361 | 338b922e | malc | res.l.low = (((rh % c) << 32) + (rl & 0xffffffff)) / c; |
362 | 338b922e | malc | return res.ll;
|
363 | 338b922e | malc | } |
364 | 338b922e | malc | |
365 | 0bfe3ca5 | Anthony Liguori | #include "module.h" |
366 | 0bfe3ca5 | Anthony Liguori | |
367 | faf07963 | pbrook | #endif |