Break up vl.h.
[qemu] / qemu-common.h
1 /* Common header file that is included by all of qemu.  */
2 #ifndef QEMU_COMMON_H
3 #define QEMU_COMMON_H
4
5 /* we put basic includes here to avoid repeating them in device drivers */
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <stdarg.h>
9 #include <string.h>
10 #include <inttypes.h>
11 #include <limits.h>
12 #include <time.h>
13 #include <ctype.h>
14 #include <errno.h>
15 #include <unistd.h>
16 #include <fcntl.h>
17 #include <sys/stat.h>
18
19 #ifndef O_LARGEFILE
20 #define O_LARGEFILE 0
21 #endif
22 #ifndef O_BINARY
23 #define O_BINARY 0
24 #endif
25
26 #ifndef ENOMEDIUM
27 #define ENOMEDIUM ENODEV
28 #endif
29
30 #ifdef _WIN32
31 #include <windows.h>
32 #define fsync _commit
33 #define lseek _lseeki64
34 #define ENOTSUP 4096
35 extern int qemu_ftruncate64(int, int64_t);
36 #define ftruncate qemu_ftruncate64
37
38
39 static inline char *realpath(const char *path, char *resolved_path)
40 {
41     _fullpath(resolved_path, path, _MAX_PATH);
42     return resolved_path;
43 }
44
45 #define PRId64 "I64d"
46 #define PRIx64 "I64x"
47 #define PRIu64 "I64u"
48 #define PRIo64 "I64o"
49 #endif
50
51 /* FIXME: Remove NEED_CPU_H.  */
52 #ifndef NEED_CPU_H
53
54 #include "config-host.h"
55 #include <setjmp.h>
56 #include "osdep.h"
57 #include "bswap.h"
58
59 #else
60
61 #include "cpu.h"
62
63 #endif /* !defined(NEED_CPU_H) */
64
65 #ifndef glue
66 #define xglue(x, y) x ## y
67 #define glue(x, y) xglue(x, y)
68 #define stringify(s)    tostring(s)
69 #define tostring(s)     #s
70 #endif
71
72 #ifndef likely
73 #if __GNUC__ < 3
74 #define __builtin_expect(x, n) (x)
75 #endif
76
77 #define likely(x)   __builtin_expect(!!(x), 1)
78 #define unlikely(x)   __builtin_expect(!!(x), 0)
79 #endif
80
81 #ifndef MIN
82 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
83 #endif
84 #ifndef MAX
85 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
86 #endif
87
88 #ifndef always_inline
89 #if (__GNUC__ < 3) || defined(__APPLE__)
90 #define always_inline inline
91 #else
92 #define always_inline __attribute__ (( always_inline )) inline
93 #endif
94 #endif
95
96 /* bottom halves */
97 typedef struct QEMUBH QEMUBH;
98
99 typedef void QEMUBHFunc(void *opaque);
100
101 QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque);
102 void qemu_bh_schedule(QEMUBH *bh);
103 void qemu_bh_cancel(QEMUBH *bh);
104 void qemu_bh_delete(QEMUBH *bh);
105 int qemu_bh_poll(void);
106
107 uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
108
109 /* cutils.c */
110 void pstrcpy(char *buf, int buf_size, const char *str);
111 char *pstrcat(char *buf, int buf_size, const char *s);
112 int strstart(const char *str, const char *val, const char **ptr);
113 int stristart(const char *str, const char *val, const char **ptr);
114 time_t mktimegm(struct tm *tm);
115
116 /* Error handling.  */
117
118 void hw_error(const char *fmt, ...)
119     __attribute__ ((__format__ (__printf__, 1, 2)))
120     __attribute__ ((__noreturn__));
121
122 /* IO callbacks.  */
123 typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
124 typedef int IOCanRWHandler(void *opaque);
125 typedef void IOHandler(void *opaque);
126
127 struct ParallelIOArg {
128     void *buffer;
129     int count;
130 };
131
132 typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
133
134 /* A load of opaque types so that device init declarations don't have to
135    pull in all the real definitions.  */
136 typedef struct NICInfo NICInfo;
137 typedef struct AudioState AudioState;
138 typedef struct BlockDriverState BlockDriverState;
139 typedef struct DisplayState DisplayState;
140 typedef struct TextConsole TextConsole;
141 typedef struct CharDriverState CharDriverState;
142 typedef struct VLANState VLANState;
143 typedef struct QEMUFile QEMUFile;
144 typedef struct i2c_bus i2c_bus;
145 typedef struct i2c_slave i2c_slave;
146 typedef struct SMBusDevice SMBusDevice;
147 typedef struct QEMUTimer QEMUTimer;
148 typedef struct PCIBus PCIBus;
149 typedef struct PCIDevice PCIDevice;
150 typedef struct SerialState SerialState;
151 typedef struct IRQState *qemu_irq;
152 struct pcmcia_card_s;
153
154 #endif