root / hw / hw.h @ 75f76531
History | View | Annotate | Download (7.1 kB)
1 | 87ecb68b | pbrook | /* Declarations for use by hardware emulation. */
|
---|---|---|---|
2 | 87ecb68b | pbrook | #ifndef QEMU_HW_H
|
3 | 87ecb68b | pbrook | #define QEMU_HW_H
|
4 | 87ecb68b | pbrook | |
5 | 87ecb68b | pbrook | #include "qemu-common.h" |
6 | 87ecb68b | pbrook | #include "irq.h" |
7 | 87ecb68b | pbrook | |
8 | 87ecb68b | pbrook | /* VM Load/Save */
|
9 | 87ecb68b | pbrook | |
10 | 5dafc53f | aliguori | /* This function writes a chunk of data to a file at the given position.
|
11 | 5dafc53f | aliguori | * The pos argument can be ignored if the file is only being used for
|
12 | 5dafc53f | aliguori | * streaming. The handler should try to write all of the data it can.
|
13 | 5dafc53f | aliguori | */
|
14 | 871d2f07 | aliguori | typedef int (QEMUFilePutBufferFunc)(void *opaque, const uint8_t *buf, |
15 | 871d2f07 | aliguori | int64_t pos, int size);
|
16 | 5dafc53f | aliguori | |
17 | 5dafc53f | aliguori | /* Read a chunk of data from a file at the given position. The pos argument
|
18 | 5dafc53f | aliguori | * can be ignored if the file is only be used for streaming. The number of
|
19 | 5dafc53f | aliguori | * bytes actually read should be returned.
|
20 | 5dafc53f | aliguori | */
|
21 | 5dafc53f | aliguori | typedef int (QEMUFileGetBufferFunc)(void *opaque, uint8_t *buf, |
22 | 5dafc53f | aliguori | int64_t pos, int size);
|
23 | 5dafc53f | aliguori | |
24 | 5dafc53f | aliguori | /* Close a file and return an error code */
|
25 | 5dafc53f | aliguori | typedef int (QEMUFileCloseFunc)(void *opaque); |
26 | 5dafc53f | aliguori | |
27 | 5dafc53f | aliguori | /* Called to determine if the file has exceeded it's bandwidth allocation. The
|
28 | 5dafc53f | aliguori | * bandwidth capping is a soft limit, not a hard limit.
|
29 | 5dafc53f | aliguori | */
|
30 | 5dafc53f | aliguori | typedef int (QEMUFileRateLimit)(void *opaque); |
31 | 5dafc53f | aliguori | |
32 | 5dafc53f | aliguori | QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
|
33 | 5dafc53f | aliguori | QEMUFileGetBufferFunc *get_buffer, |
34 | 5dafc53f | aliguori | QEMUFileCloseFunc *close, |
35 | 5dafc53f | aliguori | QEMUFileRateLimit *rate_limit); |
36 | 87ecb68b | pbrook | QEMUFile *qemu_fopen(const char *filename, const char *mode); |
37 | c1d36665 | aliguori | QEMUFile *qemu_fopen_socket(int fd);
|
38 | 065e2813 | aliguori | QEMUFile *qemu_popen(FILE *popen_file, const char *mode); |
39 | 065e2813 | aliguori | QEMUFile *qemu_popen_cmd(const char *command, const char *mode); |
40 | 87ecb68b | pbrook | void qemu_fflush(QEMUFile *f);
|
41 | 5dafc53f | aliguori | int qemu_fclose(QEMUFile *f);
|
42 | 2ca83a8d | blueswir1 | void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size); |
43 | 2ca83a8d | blueswir1 | void qemu_put_byte(QEMUFile *f, int v); |
44 | b6c4f71f | blueswir1 | |
45 | b6c4f71f | blueswir1 | static inline void qemu_put_ubyte(QEMUFile *f, unsigned int v) |
46 | b6c4f71f | blueswir1 | { |
47 | b6c4f71f | blueswir1 | qemu_put_byte(f, (int)v);
|
48 | b6c4f71f | blueswir1 | } |
49 | b6c4f71f | blueswir1 | |
50 | b6c4f71f | blueswir1 | #define qemu_put_sbyte qemu_put_byte
|
51 | b6c4f71f | blueswir1 | |
52 | 2ca83a8d | blueswir1 | void qemu_put_be16(QEMUFile *f, unsigned int v); |
53 | 2ca83a8d | blueswir1 | void qemu_put_be32(QEMUFile *f, unsigned int v); |
54 | 87ecb68b | pbrook | void qemu_put_be64(QEMUFile *f, uint64_t v);
|
55 | 2ca83a8d | blueswir1 | int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size); |
56 | 2ca83a8d | blueswir1 | int qemu_get_byte(QEMUFile *f);
|
57 | b6c4f71f | blueswir1 | |
58 | b6c4f71f | blueswir1 | static inline unsigned int qemu_get_ubyte(QEMUFile *f) |
59 | b6c4f71f | blueswir1 | { |
60 | b6c4f71f | blueswir1 | return (unsigned int)qemu_get_byte(f); |
61 | b6c4f71f | blueswir1 | } |
62 | b6c4f71f | blueswir1 | |
63 | b6c4f71f | blueswir1 | #define qemu_get_sbyte qemu_get_byte
|
64 | b6c4f71f | blueswir1 | |
65 | 2ca83a8d | blueswir1 | unsigned int qemu_get_be16(QEMUFile *f); |
66 | 2ca83a8d | blueswir1 | unsigned int qemu_get_be32(QEMUFile *f); |
67 | 87ecb68b | pbrook | uint64_t qemu_get_be64(QEMUFile *f); |
68 | 5dafc53f | aliguori | int qemu_file_rate_limit(QEMUFile *f);
|
69 | 871d2f07 | aliguori | int qemu_file_has_error(QEMUFile *f);
|
70 | 5dafc53f | aliguori | |
71 | 5dafc53f | aliguori | /* Try to send any outstanding data. This function is useful when output is
|
72 | 5dafc53f | aliguori | * halted due to rate limiting or EAGAIN errors occur as it can be used to
|
73 | 5dafc53f | aliguori | * resume output. */
|
74 | 5dafc53f | aliguori | void qemu_file_put_notify(QEMUFile *f);
|
75 | 87ecb68b | pbrook | |
76 | 87ecb68b | pbrook | static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv) |
77 | 87ecb68b | pbrook | { |
78 | 87ecb68b | pbrook | qemu_put_be64(f, *pv); |
79 | 87ecb68b | pbrook | } |
80 | 87ecb68b | pbrook | |
81 | 87ecb68b | pbrook | static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv) |
82 | 87ecb68b | pbrook | { |
83 | 87ecb68b | pbrook | qemu_put_be32(f, *pv); |
84 | 87ecb68b | pbrook | } |
85 | 87ecb68b | pbrook | |
86 | 87ecb68b | pbrook | static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv) |
87 | 87ecb68b | pbrook | { |
88 | 87ecb68b | pbrook | qemu_put_be16(f, *pv); |
89 | 87ecb68b | pbrook | } |
90 | 87ecb68b | pbrook | |
91 | 87ecb68b | pbrook | static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv) |
92 | 87ecb68b | pbrook | { |
93 | 87ecb68b | pbrook | qemu_put_byte(f, *pv); |
94 | 87ecb68b | pbrook | } |
95 | 87ecb68b | pbrook | |
96 | 87ecb68b | pbrook | static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv) |
97 | 87ecb68b | pbrook | { |
98 | 87ecb68b | pbrook | *pv = qemu_get_be64(f); |
99 | 87ecb68b | pbrook | } |
100 | 87ecb68b | pbrook | |
101 | 87ecb68b | pbrook | static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv) |
102 | 87ecb68b | pbrook | { |
103 | 87ecb68b | pbrook | *pv = qemu_get_be32(f); |
104 | 87ecb68b | pbrook | } |
105 | 87ecb68b | pbrook | |
106 | 87ecb68b | pbrook | static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv) |
107 | 87ecb68b | pbrook | { |
108 | 87ecb68b | pbrook | *pv = qemu_get_be16(f); |
109 | 87ecb68b | pbrook | } |
110 | 87ecb68b | pbrook | |
111 | 87ecb68b | pbrook | static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv) |
112 | 87ecb68b | pbrook | { |
113 | 87ecb68b | pbrook | *pv = qemu_get_byte(f); |
114 | 87ecb68b | pbrook | } |
115 | 87ecb68b | pbrook | |
116 | b6c4f71f | blueswir1 | // Signed versions for type safety
|
117 | b6c4f71f | blueswir1 | static inline void qemu_put_sbuffer(QEMUFile *f, const int8_t *buf, int size) |
118 | b6c4f71f | blueswir1 | { |
119 | b6c4f71f | blueswir1 | qemu_put_buffer(f, (const uint8_t *)buf, size);
|
120 | b6c4f71f | blueswir1 | } |
121 | b6c4f71f | blueswir1 | |
122 | b6c4f71f | blueswir1 | static inline void qemu_put_sbe16(QEMUFile *f, int v) |
123 | b6c4f71f | blueswir1 | { |
124 | b6c4f71f | blueswir1 | qemu_put_be16(f, (unsigned int)v); |
125 | b6c4f71f | blueswir1 | } |
126 | b6c4f71f | blueswir1 | |
127 | b6c4f71f | blueswir1 | static inline void qemu_put_sbe32(QEMUFile *f, int v) |
128 | b6c4f71f | blueswir1 | { |
129 | b6c4f71f | blueswir1 | qemu_put_be32(f, (unsigned int)v); |
130 | b6c4f71f | blueswir1 | } |
131 | b6c4f71f | blueswir1 | |
132 | b6c4f71f | blueswir1 | static inline void qemu_put_sbe64(QEMUFile *f, int64_t v) |
133 | b6c4f71f | blueswir1 | { |
134 | b6c4f71f | blueswir1 | qemu_put_be64(f, (uint64_t)v); |
135 | b6c4f71f | blueswir1 | } |
136 | b6c4f71f | blueswir1 | |
137 | b6c4f71f | blueswir1 | static inline size_t qemu_get_sbuffer(QEMUFile *f, int8_t *buf, int size) |
138 | b6c4f71f | blueswir1 | { |
139 | b6c4f71f | blueswir1 | return qemu_get_buffer(f, (uint8_t *)buf, size);
|
140 | b6c4f71f | blueswir1 | } |
141 | b6c4f71f | blueswir1 | |
142 | b6c4f71f | blueswir1 | static inline int qemu_get_sbe16(QEMUFile *f) |
143 | b6c4f71f | blueswir1 | { |
144 | b6c4f71f | blueswir1 | return (int)qemu_get_be16(f); |
145 | b6c4f71f | blueswir1 | } |
146 | b6c4f71f | blueswir1 | |
147 | b6c4f71f | blueswir1 | static inline int qemu_get_sbe32(QEMUFile *f) |
148 | b6c4f71f | blueswir1 | { |
149 | b6c4f71f | blueswir1 | return (int)qemu_get_be32(f); |
150 | b6c4f71f | blueswir1 | } |
151 | b6c4f71f | blueswir1 | |
152 | b6c4f71f | blueswir1 | static inline int64_t qemu_get_sbe64(QEMUFile *f) |
153 | b6c4f71f | blueswir1 | { |
154 | b6c4f71f | blueswir1 | return (int64_t)qemu_get_be64(f);
|
155 | b6c4f71f | blueswir1 | } |
156 | b6c4f71f | blueswir1 | |
157 | b6c4f71f | blueswir1 | static inline void qemu_put_s8s(QEMUFile *f, const int8_t *pv) |
158 | b6c4f71f | blueswir1 | { |
159 | b6c4f71f | blueswir1 | qemu_put_8s(f, (const uint8_t *)pv);
|
160 | b6c4f71f | blueswir1 | } |
161 | b6c4f71f | blueswir1 | |
162 | b6c4f71f | blueswir1 | static inline void qemu_put_sbe16s(QEMUFile *f, const int16_t *pv) |
163 | b6c4f71f | blueswir1 | { |
164 | b6c4f71f | blueswir1 | qemu_put_be16s(f, (const uint16_t *)pv);
|
165 | b6c4f71f | blueswir1 | } |
166 | b6c4f71f | blueswir1 | |
167 | b6c4f71f | blueswir1 | static inline void qemu_put_sbe32s(QEMUFile *f, const int32_t *pv) |
168 | b6c4f71f | blueswir1 | { |
169 | b6c4f71f | blueswir1 | qemu_put_be32s(f, (const uint32_t *)pv);
|
170 | b6c4f71f | blueswir1 | } |
171 | b6c4f71f | blueswir1 | |
172 | b6c4f71f | blueswir1 | static inline void qemu_put_sbe64s(QEMUFile *f, const int64_t *pv) |
173 | b6c4f71f | blueswir1 | { |
174 | b6c4f71f | blueswir1 | qemu_put_be64s(f, (const uint64_t *)pv);
|
175 | b6c4f71f | blueswir1 | } |
176 | b6c4f71f | blueswir1 | |
177 | b6c4f71f | blueswir1 | static inline void qemu_get_s8s(QEMUFile *f, int8_t *pv) |
178 | b6c4f71f | blueswir1 | { |
179 | b6c4f71f | blueswir1 | qemu_get_8s(f, (uint8_t *)pv); |
180 | b6c4f71f | blueswir1 | } |
181 | b6c4f71f | blueswir1 | |
182 | b6c4f71f | blueswir1 | static inline void qemu_get_sbe16s(QEMUFile *f, int16_t *pv) |
183 | b6c4f71f | blueswir1 | { |
184 | b6c4f71f | blueswir1 | qemu_get_be16s(f, (uint16_t *)pv); |
185 | b6c4f71f | blueswir1 | } |
186 | b6c4f71f | blueswir1 | |
187 | b6c4f71f | blueswir1 | static inline void qemu_get_sbe32s(QEMUFile *f, int32_t *pv) |
188 | b6c4f71f | blueswir1 | { |
189 | b6c4f71f | blueswir1 | qemu_get_be32s(f, (uint32_t *)pv); |
190 | b6c4f71f | blueswir1 | } |
191 | b6c4f71f | blueswir1 | |
192 | b6c4f71f | blueswir1 | static inline void qemu_get_sbe64s(QEMUFile *f, int64_t *pv) |
193 | b6c4f71f | blueswir1 | { |
194 | b6c4f71f | blueswir1 | qemu_get_be64s(f, (uint64_t *)pv); |
195 | b6c4f71f | blueswir1 | } |
196 | b6c4f71f | blueswir1 | |
197 | 87ecb68b | pbrook | #ifdef NEED_CPU_H
|
198 | 87ecb68b | pbrook | #if TARGET_LONG_BITS == 64 |
199 | 87ecb68b | pbrook | #define qemu_put_betl qemu_put_be64
|
200 | 87ecb68b | pbrook | #define qemu_get_betl qemu_get_be64
|
201 | 87ecb68b | pbrook | #define qemu_put_betls qemu_put_be64s
|
202 | 87ecb68b | pbrook | #define qemu_get_betls qemu_get_be64s
|
203 | b6c4f71f | blueswir1 | #define qemu_put_sbetl qemu_put_sbe64
|
204 | b6c4f71f | blueswir1 | #define qemu_get_sbetl qemu_get_sbe64
|
205 | b6c4f71f | blueswir1 | #define qemu_put_sbetls qemu_put_sbe64s
|
206 | b6c4f71f | blueswir1 | #define qemu_get_sbetls qemu_get_sbe64s
|
207 | 87ecb68b | pbrook | #else
|
208 | 87ecb68b | pbrook | #define qemu_put_betl qemu_put_be32
|
209 | 87ecb68b | pbrook | #define qemu_get_betl qemu_get_be32
|
210 | 87ecb68b | pbrook | #define qemu_put_betls qemu_put_be32s
|
211 | 87ecb68b | pbrook | #define qemu_get_betls qemu_get_be32s
|
212 | b6c4f71f | blueswir1 | #define qemu_put_sbetl qemu_put_sbe32
|
213 | b6c4f71f | blueswir1 | #define qemu_get_sbetl qemu_get_sbe32
|
214 | b6c4f71f | blueswir1 | #define qemu_put_sbetls qemu_put_sbe32s
|
215 | b6c4f71f | blueswir1 | #define qemu_get_sbetls qemu_get_sbe32s
|
216 | 87ecb68b | pbrook | #endif
|
217 | 87ecb68b | pbrook | #endif
|
218 | 87ecb68b | pbrook | |
219 | 87ecb68b | pbrook | int64_t qemu_ftell(QEMUFile *f); |
220 | 87ecb68b | pbrook | int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence);
|
221 | 87ecb68b | pbrook | |
222 | 87ecb68b | pbrook | typedef void SaveStateHandler(QEMUFile *f, void *opaque); |
223 | 9366f418 | aliguori | typedef int SaveLiveStateHandler(QEMUFile *f, int stage, void *opaque); |
224 | 87ecb68b | pbrook | typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id); |
225 | 87ecb68b | pbrook | |
226 | 87ecb68b | pbrook | int register_savevm(const char *idstr, |
227 | 87ecb68b | pbrook | int instance_id,
|
228 | 87ecb68b | pbrook | int version_id,
|
229 | 87ecb68b | pbrook | SaveStateHandler *save_state, |
230 | 87ecb68b | pbrook | LoadStateHandler *load_state, |
231 | 87ecb68b | pbrook | void *opaque);
|
232 | 87ecb68b | pbrook | |
233 | 9366f418 | aliguori | int register_savevm_live(const char *idstr, |
234 | 9366f418 | aliguori | int instance_id,
|
235 | 9366f418 | aliguori | int version_id,
|
236 | 9366f418 | aliguori | SaveLiveStateHandler *save_live_state, |
237 | 9366f418 | aliguori | SaveStateHandler *save_state, |
238 | 9366f418 | aliguori | LoadStateHandler *load_state, |
239 | 9366f418 | aliguori | void *opaque);
|
240 | 9366f418 | aliguori | |
241 | 87ecb68b | pbrook | typedef void QEMUResetHandler(void *opaque); |
242 | 87ecb68b | pbrook | |
243 | 87ecb68b | pbrook | void qemu_register_reset(QEMUResetHandler *func, void *opaque); |
244 | 87ecb68b | pbrook | |
245 | 0ecdffbb | aurel32 | /* handler to set the boot_device for a specific type of QEMUMachine */
|
246 | 0ecdffbb | aurel32 | /* return 0 if success */
|
247 | 3b4366de | blueswir1 | typedef int QEMUBootSetHandler(void *opaque, const char *boot_device); |
248 | 3b4366de | blueswir1 | void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque); |
249 | 0ecdffbb | aurel32 | |
250 | 87ecb68b | pbrook | /* These should really be in isa.h, but are here to make pc.h happy. */
|
251 | 87ecb68b | pbrook | typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data); |
252 | 87ecb68b | pbrook | typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address); |
253 | 87ecb68b | pbrook | |
254 | 87ecb68b | pbrook | #endif |