]> git.proxmox.com Git - mirror_qemu.git/blame - qemu-common.h
hw/nand: Writing to NAND can only clear bits
[mirror_qemu.git] / qemu-common.h
CommitLineData
faf07963
PB
1/* Common header file that is included by all of qemu. */
2#ifndef QEMU_COMMON_H
3#define QEMU_COMMON_H
4
5c026320 5#include "compiler.h"
beb6f0de
KW
6#include "config-host.h"
7
332ae28d
PB
8#if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(__hppa__) || defined(__ia64__)
9#define WORDS_ALIGNED
10#endif
11
082b5557 12#define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
24ebf5f3 13
29e922b6
BS
14typedef struct QEMUTimer QEMUTimer;
15typedef struct QEMUFile QEMUFile;
16typedef struct QEMUBH QEMUBH;
92a16d7a 17typedef struct DeviceState DeviceState;
29e922b6 18
316378e4
JK
19struct Monitor;
20typedef struct Monitor Monitor;
21
faf07963
PB
22/* we put basic includes here to avoid repeating them in device drivers */
23#include <stdlib.h>
24#include <stdio.h>
25#include <stdarg.h>
11165820 26#include <stdbool.h>
faf07963 27#include <string.h>
c8906845 28#include <strings.h>
faf07963
PB
29#include <inttypes.h>
30#include <limits.h>
31#include <time.h>
32#include <ctype.h>
33#include <errno.h>
34#include <unistd.h>
35#include <fcntl.h>
36#include <sys/stat.h>
dcfd0865 37#include <sys/time.h>
55616505 38#include <assert.h>
86f69a92 39#include <signal.h>
faf07963 40
082b5557
BS
41#ifdef _WIN32
42#include "qemu-os-win32.h"
43#endif
44
45#ifdef CONFIG_POSIX
46#include "qemu-os-posix.h"
47#endif
48
faf07963
PB
49#ifndef O_LARGEFILE
50#define O_LARGEFILE 0
51#endif
52#ifndef O_BINARY
53#define O_BINARY 0
54#endif
0e74e66b
JQ
55#ifndef MAP_ANONYMOUS
56#define MAP_ANONYMOUS MAP_ANON
57#endif
faf07963
PB
58#ifndef ENOMEDIUM
59#define ENOMEDIUM ENODEV
60#endif
4c955388 61#if !defined(ENOTSUP)
2880bc32
JQ
62#define ENOTSUP 4096
63#endif
3c9405a0
GH
64#ifndef TIME_MAX
65#define TIME_MAX LONG_MAX
66#endif
faf07963 67
6114fdb0
JQ
68#ifndef CONFIG_IOVEC
69#define CONFIG_IOVEC
bf9298b9
AL
70struct iovec {
71 void *iov_base;
72 size_t iov_len;
73};
e2a305fb
CH
74/*
75 * Use the same value as Linux for now.
76 */
77#define IOV_MAX 1024
331dadde
BS
78#else
79#include <sys/uio.h>
bf9298b9
AL
80#endif
81
f868445a
SW
82typedef int (*fprintf_function)(FILE *f, const char *fmt, ...)
83 GCC_FMT_ATTR(2, 3);
84
faf07963 85#ifdef _WIN32
faf07963
PB
86#define fsync _commit
87#define lseek _lseeki64
64b85a8f 88int qemu_ftruncate64(int, int64_t);
faf07963
PB
89#define ftruncate qemu_ftruncate64
90
faf07963
PB
91static inline char *realpath(const char *path, char *resolved_path)
92{
93 _fullpath(resolved_path, path, _MAX_PATH);
94 return resolved_path;
95}
faf07963
PB
96#endif
97
98/* FIXME: Remove NEED_CPU_H. */
99#ifndef NEED_CPU_H
100
faf07963
PB
101#include "osdep.h"
102#include "bswap.h"
103
104#else
105
106#include "cpu.h"
107
108#endif /* !defined(NEED_CPU_H) */
109
3bbbee18
AF
110/* main function, renamed */
111#if defined(CONFIG_COCOA)
112int qemu_main(int argc, char **argv, char **envp);
113#endif
114
faf07963 115/* bottom halves */
faf07963
PB
116typedef void QEMUBHFunc(void *opaque);
117
9a1e9481
KW
118void async_context_push(void);
119void async_context_pop(void);
120int get_async_context_id(void);
121
faf07963
PB
122QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque);
123void qemu_bh_schedule(QEMUBH *bh);
80d3580b
AL
124/* Bottom halfs that are scheduled from a bottom half handler are instantly
125 * invoked. This can create an infinite loop if a bottom half handler
126 * schedules itself. qemu_bh_schedule_idle() avoids this infinite loop by
127 * ensuring that the bottom half isn't executed until the next main loop
128 * iteration.
129 */
1b435b10 130void qemu_bh_schedule_idle(QEMUBH *bh);
faf07963
PB
131void qemu_bh_cancel(QEMUBH *bh);
132void qemu_bh_delete(QEMUBH *bh);
133int qemu_bh_poll(void);
4f999d05 134void qemu_bh_update_timeout(int *timeout);
faf07963 135
f6503059
AZ
136void qemu_get_timedate(struct tm *tm, int offset);
137int qemu_timedate_diff(struct tm *tm);
138
faf07963
PB
139/* cutils.c */
140void pstrcpy(char *buf, int buf_size, const char *str);
141char *pstrcat(char *buf, int buf_size, const char *s);
142int strstart(const char *str, const char *val, const char **ptr);
143int stristart(const char *str, const char *val, const char **ptr);
d43277c5 144int qemu_strnlen(const char *s, int max_len);
faf07963 145time_t mktimegm(struct tm *tm);
ad46db9a 146int qemu_fls(int i);
6f1953c4 147int qemu_fdatasync(int fd);
db1a4972 148int fcntl_setfl(int fd, int flag);
d8427002 149
d7142456
JS
150/*
151 * strtosz() suffixes used to specify the default treatment of an
152 * argument passed to strtosz() without an explicit suffix.
153 * These should be defined using upper case characters in the range
154 * A-Z, as strtosz() will use qemu_toupper() on the given argument
155 * prior to comparison.
156 */
d8427002
JS
157#define STRTOSZ_DEFSUFFIX_TB 'T'
158#define STRTOSZ_DEFSUFFIX_GB 'G'
159#define STRTOSZ_DEFSUFFIX_MB 'M'
160#define STRTOSZ_DEFSUFFIX_KB 'K'
161#define STRTOSZ_DEFSUFFIX_B 'B'
70b4f4bb
JS
162int64_t strtosz(const char *nptr, char **end);
163int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix);
faf07963 164
37022086
BS
165/* path.c */
166void init_paths(const char *prefix);
167const char *path(const char *pathname);
168
cd390083
BS
169#define qemu_isalnum(c) isalnum((unsigned char)(c))
170#define qemu_isalpha(c) isalpha((unsigned char)(c))
171#define qemu_iscntrl(c) iscntrl((unsigned char)(c))
172#define qemu_isdigit(c) isdigit((unsigned char)(c))
173#define qemu_isgraph(c) isgraph((unsigned char)(c))
174#define qemu_islower(c) islower((unsigned char)(c))
175#define qemu_isprint(c) isprint((unsigned char)(c))
176#define qemu_ispunct(c) ispunct((unsigned char)(c))
177#define qemu_isspace(c) isspace((unsigned char)(c))
178#define qemu_isupper(c) isupper((unsigned char)(c))
179#define qemu_isxdigit(c) isxdigit((unsigned char)(c))
180#define qemu_tolower(c) tolower((unsigned char)(c))
181#define qemu_toupper(c) toupper((unsigned char)(c))
182#define qemu_isascii(c) isascii((unsigned char)(c))
183#define qemu_toascii(c) toascii((unsigned char)(c))
184
b152aa84 185void *qemu_oom_check(void *ptr);
ca10f867 186void *qemu_malloc(size_t size);
2137b4cc 187void *qemu_realloc(void *ptr, size_t size);
ca10f867
AJ
188void *qemu_mallocz(size_t size);
189void qemu_free(void *ptr);
190char *qemu_strdup(const char *str);
ac4b0d0c 191char *qemu_strndup(const char *str, size_t size);
ca10f867 192
d549db5a
GC
193void qemu_mutex_lock_iothread(void);
194void qemu_mutex_unlock_iothread(void);
195
40ff6d7e 196int qemu_open(const char *name, int flags, ...);
7c7c0629
JQ
197ssize_t qemu_write_full(int fd, const void *buf, size_t count)
198 QEMU_WARN_UNUSED_RESULT;
40ff6d7e
KW
199void qemu_set_cloexec(int fd);
200
201#ifndef _WIN32
4d54ec78 202int qemu_add_child_watch(pid_t pid);
f3dfda61 203int qemu_eventfd(int pipefd[2]);
40ff6d7e
KW
204int qemu_pipe(int pipefd[2]);
205#endif
206
00aa0040
BS
207#ifdef _WIN32
208#define qemu_recv(sockfd, buf, len, flags) recv(sockfd, (void *)buf, len, flags)
209#else
210#define qemu_recv(sockfd, buf, len, flags) recv(sockfd, buf, len, flags)
211#endif
212
87ecb68b
PB
213/* Error handling. */
214
e5924d89 215void QEMU_NORETURN hw_error(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
87ecb68b
PB
216
217/* IO callbacks. */
218typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
7b27a769 219typedef int IOCanReadHandler(void *opaque);
87ecb68b
PB
220typedef void IOHandler(void *opaque);
221
02981419
PB
222void qemu_iohandler_fill(int *pnfds, fd_set *readfds, fd_set *writefds, fd_set *xfds);
223void qemu_iohandler_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds, int rc);
224
87ecb68b
PB
225struct ParallelIOArg {
226 void *buffer;
227 int count;
228};
229
230typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
231
232/* A load of opaque types so that device init declarations don't have to
233 pull in all the real definitions. */
234typedef struct NICInfo NICInfo;
1ae26a18 235typedef struct HCIInfo HCIInfo;
87ecb68b
PB
236typedef struct AudioState AudioState;
237typedef struct BlockDriverState BlockDriverState;
2446333c 238typedef struct DriveInfo DriveInfo;
87ecb68b 239typedef struct DisplayState DisplayState;
7d957bd8
AL
240typedef struct DisplayChangeListener DisplayChangeListener;
241typedef struct DisplaySurface DisplaySurface;
7b5d76da 242typedef struct DisplayAllocator DisplayAllocator;
7d957bd8 243typedef struct PixelFormat PixelFormat;
87ecb68b 244typedef struct TextConsole TextConsole;
c60e08d9 245typedef TextConsole QEMUConsole;
87ecb68b 246typedef struct CharDriverState CharDriverState;
76d32cba 247typedef struct MACAddr MACAddr;
87ecb68b 248typedef struct VLANState VLANState;
f7105843 249typedef struct VLANClientState VLANClientState;
87ecb68b
PB
250typedef struct i2c_bus i2c_bus;
251typedef struct i2c_slave i2c_slave;
252typedef struct SMBusDevice SMBusDevice;
fb47a2e9
IY
253typedef struct PCIHostState PCIHostState;
254typedef struct PCIExpressHost PCIExpressHost;
87ecb68b
PB
255typedef struct PCIBus PCIBus;
256typedef struct PCIDevice PCIDevice;
0428527c 257typedef struct PCIExpressDevice PCIExpressDevice;
68f79994 258typedef struct PCIBridge PCIBridge;
34e65944
IY
259typedef struct PCIEAERMsg PCIEAERMsg;
260typedef struct PCIEAERLog PCIEAERLog;
261typedef struct PCIEAERErr PCIEAERErr;
bc20ba98
IY
262typedef struct PCIEPort PCIEPort;
263typedef struct PCIESlot PCIESlot;
87ecb68b
PB
264typedef struct SerialState SerialState;
265typedef struct IRQState *qemu_irq;
bc24a225
PB
266typedef struct PCMCIACardState PCMCIACardState;
267typedef struct MouseTransformInfo MouseTransformInfo;
268typedef struct uWireSlave uWireSlave;
269typedef struct I2SCodec I2SCodec;
90d37239 270typedef struct SSIBus SSIBus;
2292b339 271typedef struct EventNotifier EventNotifier;
2be24aaa 272typedef struct VirtIODevice VirtIODevice;
87ecb68b 273
186993ee
MT
274typedef uint64_t pcibus_t;
275
d2053c3c
BS
276void cpu_exec_init_all(unsigned long tb_size);
277
b3c7724c
PB
278/* CPU save/load. */
279void cpu_save(QEMUFile *f, void *opaque);
280int cpu_load(QEMUFile *f, void *opaque, int version_id);
281
9e472e10
AL
282/* Force QEMU to stop what it's doing and service IO */
283void qemu_service_io(void);
284
d9f75a4e
AL
285/* Force QEMU to process pending events */
286void qemu_notify_event(void);
287
8edac960
AL
288/* Unblock cpu */
289void qemu_cpu_kick(void *env);
46d62fac 290void qemu_cpu_kick_self(void);
b7680cb6 291int qemu_cpu_is_self(void *env);
ab33fcda 292bool all_cpu_threads_idle(void);
8edac960 293
e82bcec2
MT
294/* work queue */
295struct qemu_work_item {
296 struct qemu_work_item *next;
297 void (*func)(void *data);
298 void *data;
299 int done;
300};
301
0bf46a40
AL
302#ifdef CONFIG_USER_ONLY
303#define qemu_init_vcpu(env) do { } while (0)
304#else
305void qemu_init_vcpu(void *env);
306#endif
307
44e3ee8a
AL
308typedef struct QEMUIOVector {
309 struct iovec *iov;
310 int niov;
311 int nalloc;
249aa745 312 size_t size;
44e3ee8a
AL
313} QEMUIOVector;
314
315void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint);
522584a5 316void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov);
44e3ee8a 317void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len);
b8a83a4f
KW
318void qemu_iovec_copy(QEMUIOVector *dst, QEMUIOVector *src, uint64_t skip,
319 size_t size);
40b4f539 320void qemu_iovec_concat(QEMUIOVector *dst, QEMUIOVector *src, size_t size);
44e3ee8a 321void qemu_iovec_destroy(QEMUIOVector *qiov);
be959463 322void qemu_iovec_reset(QEMUIOVector *qiov);
44e3ee8a 323void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf);
249aa745 324void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count);
b8a83a4f 325void qemu_iovec_memset(QEMUIOVector *qiov, int c, size_t count);
e0d9c6f9
CT
326void qemu_iovec_memset_skip(QEMUIOVector *qiov, int c, size_t count,
327 size_t skip);
44e3ee8a 328
6b837bc4
JS
329void qemu_progress_init(int enabled, float min_skip);
330void qemu_progress_end(void);
3bfe4dbf 331void qemu_progress_print(float delta, int max);
6b837bc4 332
082b5557
BS
333#define QEMU_FILE_TYPE_BIOS 0
334#define QEMU_FILE_TYPE_KEYMAP 1
335char *qemu_find_file(int type, const char *name);
336
337/* OS specific functions */
338void os_setup_early_signal_handling(void);
339char *os_find_datadir(const char *argv0);
340void os_parse_cmd_args(int index, const char *optarg);
341void os_pidfile_error(void);
342
abd0c6bd
PB
343/* Convert a byte between binary and BCD. */
344static inline uint8_t to_bcd(uint8_t val)
345{
346 return ((val / 10) << 4) | (val % 10);
347}
348
349static inline uint8_t from_bcd(uint8_t val)
350{
351 return ((val >> 4) * 10) + (val & 0x0f);
352}
353
338b922e 354/* compute with 96 bit intermediate result: (a*b)/c */
355static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)
356{
357 union {
358 uint64_t ll;
359 struct {
360#ifdef HOST_WORDS_BIGENDIAN
361 uint32_t high, low;
362#else
363 uint32_t low, high;
364#endif
365 } l;
366 } u, res;
367 uint64_t rl, rh;
368
369 u.ll = a;
370 rl = (uint64_t)u.l.low * (uint64_t)b;
371 rh = (uint64_t)u.l.high * (uint64_t)b;
372 rh += (rl >> 32);
373 res.l.high = rh / c;
374 res.l.low = (((rh % c) << 32) + (rl & 0xffffffff)) / c;
375 return res.ll;
376}
377
0bfe3ca5
AL
378#include "module.h"
379
faf07963 380#endif