root / hw / hw.h @ 11fe0e6e
History | View | Annotate | Download (30 kB)
1 |
/* Declarations for use by hardware emulation. */
|
---|---|
2 |
#ifndef QEMU_HW_H
|
3 |
#define QEMU_HW_H
|
4 |
|
5 |
#include "qemu-common.h" |
6 |
|
7 |
#if defined(TARGET_PHYS_ADDR_BITS) && !defined(NEED_CPU_H)
|
8 |
#include "targphys.h" |
9 |
#include "poison.h" |
10 |
#include "cpu-common.h" |
11 |
#endif
|
12 |
|
13 |
#include <stdbool.h> |
14 |
#include "ioport.h" |
15 |
#include "irq.h" |
16 |
|
17 |
/* VM Load/Save */
|
18 |
|
19 |
/* This function writes a chunk of data to a file at the given position.
|
20 |
* The pos argument can be ignored if the file is only being used for
|
21 |
* streaming. The handler should try to write all of the data it can.
|
22 |
*/
|
23 |
typedef int (QEMUFilePutBufferFunc)(void *opaque, const uint8_t *buf, |
24 |
int64_t pos, int size);
|
25 |
|
26 |
/* Read a chunk of data from a file at the given position. The pos argument
|
27 |
* can be ignored if the file is only be used for streaming. The number of
|
28 |
* bytes actually read should be returned.
|
29 |
*/
|
30 |
typedef int (QEMUFileGetBufferFunc)(void *opaque, uint8_t *buf, |
31 |
int64_t pos, int size);
|
32 |
|
33 |
/* Close a file and return an error code */
|
34 |
typedef int (QEMUFileCloseFunc)(void *opaque); |
35 |
|
36 |
/* Called to determine if the file has exceeded it's bandwidth allocation. The
|
37 |
* bandwidth capping is a soft limit, not a hard limit.
|
38 |
*/
|
39 |
typedef int (QEMUFileRateLimit)(void *opaque); |
40 |
|
41 |
/* Called to change the current bandwidth allocation. This function must return
|
42 |
* the new actual bandwidth. It should be new_rate if everything goes ok, and
|
43 |
* the old rate otherwise
|
44 |
*/
|
45 |
typedef size_t (QEMUFileSetRateLimit)(void *opaque, size_t new_rate); |
46 |
typedef size_t (QEMUFileGetRateLimit)(void *opaque); |
47 |
|
48 |
QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
|
49 |
QEMUFileGetBufferFunc *get_buffer, |
50 |
QEMUFileCloseFunc *close, |
51 |
QEMUFileRateLimit *rate_limit, |
52 |
QEMUFileSetRateLimit *set_rate_limit, |
53 |
QEMUFileGetRateLimit *get_rate_limit); |
54 |
QEMUFile *qemu_fopen(const char *filename, const char *mode); |
55 |
QEMUFile *qemu_fdopen(int fd, const char *mode); |
56 |
QEMUFile *qemu_fopen_socket(int fd);
|
57 |
QEMUFile *qemu_popen(FILE *popen_file, const char *mode); |
58 |
QEMUFile *qemu_popen_cmd(const char *command, const char *mode); |
59 |
int qemu_stdio_fd(QEMUFile *f);
|
60 |
void qemu_fflush(QEMUFile *f);
|
61 |
int qemu_fclose(QEMUFile *f);
|
62 |
void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size); |
63 |
void qemu_put_byte(QEMUFile *f, int v); |
64 |
|
65 |
static inline void qemu_put_ubyte(QEMUFile *f, unsigned int v) |
66 |
{ |
67 |
qemu_put_byte(f, (int)v);
|
68 |
} |
69 |
|
70 |
#define qemu_put_sbyte qemu_put_byte
|
71 |
|
72 |
void qemu_put_be16(QEMUFile *f, unsigned int v); |
73 |
void qemu_put_be32(QEMUFile *f, unsigned int v); |
74 |
void qemu_put_be64(QEMUFile *f, uint64_t v);
|
75 |
int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size); |
76 |
int qemu_get_byte(QEMUFile *f);
|
77 |
|
78 |
static inline unsigned int qemu_get_ubyte(QEMUFile *f) |
79 |
{ |
80 |
return (unsigned int)qemu_get_byte(f); |
81 |
} |
82 |
|
83 |
#define qemu_get_sbyte qemu_get_byte
|
84 |
|
85 |
unsigned int qemu_get_be16(QEMUFile *f); |
86 |
unsigned int qemu_get_be32(QEMUFile *f); |
87 |
uint64_t qemu_get_be64(QEMUFile *f); |
88 |
int qemu_file_rate_limit(QEMUFile *f);
|
89 |
size_t qemu_file_set_rate_limit(QEMUFile *f, size_t new_rate); |
90 |
size_t qemu_file_get_rate_limit(QEMUFile *f); |
91 |
int qemu_file_has_error(QEMUFile *f);
|
92 |
void qemu_file_set_error(QEMUFile *f);
|
93 |
|
94 |
/* Try to send any outstanding data. This function is useful when output is
|
95 |
* halted due to rate limiting or EAGAIN errors occur as it can be used to
|
96 |
* resume output. */
|
97 |
void qemu_file_put_notify(QEMUFile *f);
|
98 |
|
99 |
static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv) |
100 |
{ |
101 |
qemu_put_be64(f, *pv); |
102 |
} |
103 |
|
104 |
static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv) |
105 |
{ |
106 |
qemu_put_be32(f, *pv); |
107 |
} |
108 |
|
109 |
static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv) |
110 |
{ |
111 |
qemu_put_be16(f, *pv); |
112 |
} |
113 |
|
114 |
static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv) |
115 |
{ |
116 |
qemu_put_byte(f, *pv); |
117 |
} |
118 |
|
119 |
static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv) |
120 |
{ |
121 |
*pv = qemu_get_be64(f); |
122 |
} |
123 |
|
124 |
static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv) |
125 |
{ |
126 |
*pv = qemu_get_be32(f); |
127 |
} |
128 |
|
129 |
static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv) |
130 |
{ |
131 |
*pv = qemu_get_be16(f); |
132 |
} |
133 |
|
134 |
static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv) |
135 |
{ |
136 |
*pv = qemu_get_byte(f); |
137 |
} |
138 |
|
139 |
// Signed versions for type safety
|
140 |
static inline void qemu_put_sbuffer(QEMUFile *f, const int8_t *buf, int size) |
141 |
{ |
142 |
qemu_put_buffer(f, (const uint8_t *)buf, size);
|
143 |
} |
144 |
|
145 |
static inline void qemu_put_sbe16(QEMUFile *f, int v) |
146 |
{ |
147 |
qemu_put_be16(f, (unsigned int)v); |
148 |
} |
149 |
|
150 |
static inline void qemu_put_sbe32(QEMUFile *f, int v) |
151 |
{ |
152 |
qemu_put_be32(f, (unsigned int)v); |
153 |
} |
154 |
|
155 |
static inline void qemu_put_sbe64(QEMUFile *f, int64_t v) |
156 |
{ |
157 |
qemu_put_be64(f, (uint64_t)v); |
158 |
} |
159 |
|
160 |
static inline size_t qemu_get_sbuffer(QEMUFile *f, int8_t *buf, int size) |
161 |
{ |
162 |
return qemu_get_buffer(f, (uint8_t *)buf, size);
|
163 |
} |
164 |
|
165 |
static inline int qemu_get_sbe16(QEMUFile *f) |
166 |
{ |
167 |
return (int)qemu_get_be16(f); |
168 |
} |
169 |
|
170 |
static inline int qemu_get_sbe32(QEMUFile *f) |
171 |
{ |
172 |
return (int)qemu_get_be32(f); |
173 |
} |
174 |
|
175 |
static inline int64_t qemu_get_sbe64(QEMUFile *f) |
176 |
{ |
177 |
return (int64_t)qemu_get_be64(f);
|
178 |
} |
179 |
|
180 |
static inline void qemu_put_s8s(QEMUFile *f, const int8_t *pv) |
181 |
{ |
182 |
qemu_put_8s(f, (const uint8_t *)pv);
|
183 |
} |
184 |
|
185 |
static inline void qemu_put_sbe16s(QEMUFile *f, const int16_t *pv) |
186 |
{ |
187 |
qemu_put_be16s(f, (const uint16_t *)pv);
|
188 |
} |
189 |
|
190 |
static inline void qemu_put_sbe32s(QEMUFile *f, const int32_t *pv) |
191 |
{ |
192 |
qemu_put_be32s(f, (const uint32_t *)pv);
|
193 |
} |
194 |
|
195 |
static inline void qemu_put_sbe64s(QEMUFile *f, const int64_t *pv) |
196 |
{ |
197 |
qemu_put_be64s(f, (const uint64_t *)pv);
|
198 |
} |
199 |
|
200 |
static inline void qemu_get_s8s(QEMUFile *f, int8_t *pv) |
201 |
{ |
202 |
qemu_get_8s(f, (uint8_t *)pv); |
203 |
} |
204 |
|
205 |
static inline void qemu_get_sbe16s(QEMUFile *f, int16_t *pv) |
206 |
{ |
207 |
qemu_get_be16s(f, (uint16_t *)pv); |
208 |
} |
209 |
|
210 |
static inline void qemu_get_sbe32s(QEMUFile *f, int32_t *pv) |
211 |
{ |
212 |
qemu_get_be32s(f, (uint32_t *)pv); |
213 |
} |
214 |
|
215 |
static inline void qemu_get_sbe64s(QEMUFile *f, int64_t *pv) |
216 |
{ |
217 |
qemu_get_be64s(f, (uint64_t *)pv); |
218 |
} |
219 |
|
220 |
#ifdef NEED_CPU_H
|
221 |
#if TARGET_LONG_BITS == 64 |
222 |
#define qemu_put_betl qemu_put_be64
|
223 |
#define qemu_get_betl qemu_get_be64
|
224 |
#define qemu_put_betls qemu_put_be64s
|
225 |
#define qemu_get_betls qemu_get_be64s
|
226 |
#define qemu_put_sbetl qemu_put_sbe64
|
227 |
#define qemu_get_sbetl qemu_get_sbe64
|
228 |
#define qemu_put_sbetls qemu_put_sbe64s
|
229 |
#define qemu_get_sbetls qemu_get_sbe64s
|
230 |
#else
|
231 |
#define qemu_put_betl qemu_put_be32
|
232 |
#define qemu_get_betl qemu_get_be32
|
233 |
#define qemu_put_betls qemu_put_be32s
|
234 |
#define qemu_get_betls qemu_get_be32s
|
235 |
#define qemu_put_sbetl qemu_put_sbe32
|
236 |
#define qemu_get_sbetl qemu_get_sbe32
|
237 |
#define qemu_put_sbetls qemu_put_sbe32s
|
238 |
#define qemu_get_sbetls qemu_get_sbe32s
|
239 |
#endif
|
240 |
#endif
|
241 |
|
242 |
int64_t qemu_ftell(QEMUFile *f); |
243 |
int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence);
|
244 |
|
245 |
typedef void SaveSetParamsHandler(int blk_enable, int shared, void * opaque); |
246 |
typedef void SaveStateHandler(QEMUFile *f, void *opaque); |
247 |
typedef int SaveLiveStateHandler(QEMUFile *f, int stage, void *opaque); |
248 |
typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id); |
249 |
|
250 |
int register_savevm(const char *idstr, |
251 |
int instance_id,
|
252 |
int version_id,
|
253 |
SaveStateHandler *save_state, |
254 |
LoadStateHandler *load_state, |
255 |
void *opaque);
|
256 |
|
257 |
int register_savevm_live(const char *idstr, |
258 |
int instance_id,
|
259 |
int version_id,
|
260 |
SaveSetParamsHandler *set_params, |
261 |
SaveLiveStateHandler *save_live_state, |
262 |
SaveStateHandler *save_state, |
263 |
LoadStateHandler *load_state, |
264 |
void *opaque);
|
265 |
|
266 |
void unregister_savevm(const char *idstr, void *opaque); |
267 |
|
268 |
typedef void QEMUResetHandler(void *opaque); |
269 |
|
270 |
void qemu_register_reset(QEMUResetHandler *func, void *opaque); |
271 |
void qemu_unregister_reset(QEMUResetHandler *func, void *opaque); |
272 |
|
273 |
/* handler to set the boot_device order for a specific type of QEMUMachine */
|
274 |
/* return 0 if success */
|
275 |
typedef int QEMUBootSetHandler(void *opaque, const char *boot_devices); |
276 |
void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque); |
277 |
int qemu_boot_set(const char *boot_devices); |
278 |
|
279 |
typedef struct VMStateInfo VMStateInfo; |
280 |
typedef struct VMStateDescription VMStateDescription; |
281 |
|
282 |
struct VMStateInfo {
|
283 |
const char *name; |
284 |
int (*get)(QEMUFile *f, void *pv, size_t size); |
285 |
void (*put)(QEMUFile *f, void *pv, size_t size); |
286 |
}; |
287 |
|
288 |
enum VMStateFlags {
|
289 |
VMS_SINGLE = 0x001,
|
290 |
VMS_POINTER = 0x002,
|
291 |
VMS_ARRAY = 0x004,
|
292 |
VMS_STRUCT = 0x008,
|
293 |
VMS_VARRAY_INT32 = 0x010, /* Array with size in int32_t field*/ |
294 |
VMS_BUFFER = 0x020, /* static sized buffer */ |
295 |
VMS_ARRAY_OF_POINTER = 0x040,
|
296 |
VMS_VARRAY_UINT16 = 0x080, /* Array with size in uint16_t field */ |
297 |
VMS_VBUFFER = 0x100, /* Buffer with size in int32_t field */ |
298 |
}; |
299 |
|
300 |
typedef struct { |
301 |
const char *name; |
302 |
size_t offset; |
303 |
size_t size; |
304 |
size_t start; |
305 |
int num;
|
306 |
size_t num_offset; |
307 |
size_t size_offset; |
308 |
const VMStateInfo *info;
|
309 |
enum VMStateFlags flags;
|
310 |
const VMStateDescription *vmsd;
|
311 |
int version_id;
|
312 |
bool (*field_exists)(void *opaque, int version_id); |
313 |
} VMStateField; |
314 |
|
315 |
struct VMStateDescription {
|
316 |
const char *name; |
317 |
int version_id;
|
318 |
int minimum_version_id;
|
319 |
int minimum_version_id_old;
|
320 |
LoadStateHandler *load_state_old; |
321 |
int (*pre_load)(void *opaque); |
322 |
int (*post_load)(void *opaque, int version_id); |
323 |
void (*pre_save)(void *opaque); |
324 |
void (*post_save)(void *opaque); |
325 |
VMStateField *fields; |
326 |
}; |
327 |
|
328 |
extern const VMStateInfo vmstate_info_int8; |
329 |
extern const VMStateInfo vmstate_info_int16; |
330 |
extern const VMStateInfo vmstate_info_int32; |
331 |
extern const VMStateInfo vmstate_info_int64; |
332 |
|
333 |
extern const VMStateInfo vmstate_info_uint8_equal; |
334 |
extern const VMStateInfo vmstate_info_uint16_equal; |
335 |
extern const VMStateInfo vmstate_info_int32_equal; |
336 |
extern const VMStateInfo vmstate_info_int32_le; |
337 |
|
338 |
extern const VMStateInfo vmstate_info_uint8; |
339 |
extern const VMStateInfo vmstate_info_uint16; |
340 |
extern const VMStateInfo vmstate_info_uint32; |
341 |
extern const VMStateInfo vmstate_info_uint64; |
342 |
|
343 |
extern const VMStateInfo vmstate_info_timer; |
344 |
extern const VMStateInfo vmstate_info_ptimer; |
345 |
extern const VMStateInfo vmstate_info_buffer; |
346 |
extern const VMStateInfo vmstate_info_unused_buffer; |
347 |
|
348 |
#define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0) |
349 |
#define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0) |
350 |
|
351 |
#define vmstate_offset_value(_state, _field, _type) \
|
352 |
(offsetof(_state, _field) + \ |
353 |
type_check(_type, typeof_field(_state, _field))) |
354 |
|
355 |
#define vmstate_offset_pointer(_state, _field, _type) \
|
356 |
(offsetof(_state, _field) + \ |
357 |
type_check_pointer(_type, typeof_field(_state, _field))) |
358 |
|
359 |
#define vmstate_offset_array(_state, _field, _type, _num) \
|
360 |
(offsetof(_state, _field) + \ |
361 |
type_check_array(_type, typeof_field(_state, _field), _num)) |
362 |
|
363 |
#define vmstate_offset_sub_array(_state, _field, _type, _start) \
|
364 |
(offsetof(_state, _field[_start])) |
365 |
|
366 |
#define vmstate_offset_buffer(_state, _field) \
|
367 |
vmstate_offset_array(_state, _field, uint8_t, \ |
368 |
sizeof(typeof_field(_state, _field)))
|
369 |
|
370 |
#define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \
|
371 |
.name = (stringify(_field)), \ |
372 |
.version_id = (_version), \ |
373 |
.field_exists = (_test), \ |
374 |
.size = sizeof(_type), \
|
375 |
.info = &(_info), \ |
376 |
.flags = VMS_SINGLE, \ |
377 |
.offset = vmstate_offset_value(_state, _field, _type), \ |
378 |
} |
379 |
|
380 |
#define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \
|
381 |
.name = (stringify(_field)), \ |
382 |
.version_id = (_version), \ |
383 |
.info = &(_info), \ |
384 |
.size = sizeof(_type), \
|
385 |
.flags = VMS_SINGLE|VMS_POINTER, \ |
386 |
.offset = vmstate_offset_value(_state, _field, _type), \ |
387 |
} |
388 |
|
389 |
#define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\
|
390 |
.name = (stringify(_field)), \ |
391 |
.version_id = (_version), \ |
392 |
.num = (_num), \ |
393 |
.info = &(_info), \ |
394 |
.size = sizeof(_type), \
|
395 |
.flags = VMS_ARRAY, \ |
396 |
.offset = vmstate_offset_array(_state, _field, _type, _num), \ |
397 |
} |
398 |
|
399 |
#define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
|
400 |
.name = (stringify(_field)), \ |
401 |
.field_exists = (_test), \ |
402 |
.num = (_num), \ |
403 |
.info = &(_info), \ |
404 |
.size = sizeof(_type), \
|
405 |
.flags = VMS_ARRAY, \ |
406 |
.offset = vmstate_offset_array(_state, _field, _type, _num),\ |
407 |
} |
408 |
|
409 |
#define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \
|
410 |
.name = (stringify(_field)), \ |
411 |
.version_id = (_version), \ |
412 |
.num = (_num), \ |
413 |
.info = &(_info), \ |
414 |
.size = sizeof(_type), \
|
415 |
.flags = VMS_ARRAY, \ |
416 |
.offset = vmstate_offset_sub_array(_state, _field, _type, _start), \ |
417 |
} |
418 |
|
419 |
#define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\
|
420 |
.name = (stringify(_field)), \ |
421 |
.version_id = (_version), \ |
422 |
.num_offset = vmstate_offset_value(_state, _field_num, int32_t), \ |
423 |
.info = &(_info), \ |
424 |
.size = sizeof(_type), \
|
425 |
.flags = VMS_VARRAY_INT32|VMS_POINTER, \ |
426 |
.offset = vmstate_offset_pointer(_state, _field, _type), \ |
427 |
} |
428 |
|
429 |
#define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version, _info, _type) {\
|
430 |
.name = (stringify(_field)), \ |
431 |
.version_id = (_version), \ |
432 |
.num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\ |
433 |
.info = &(_info), \ |
434 |
.size = sizeof(_type), \
|
435 |
.flags = VMS_VARRAY_UINT16, \ |
436 |
.offset = offsetof(_state, _field), \ |
437 |
} |
438 |
|
439 |
#define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \
|
440 |
.name = (stringify(_field)), \ |
441 |
.version_id = (_version), \ |
442 |
.field_exists = (_test), \ |
443 |
.vmsd = &(_vmsd), \ |
444 |
.size = sizeof(_type), \
|
445 |
.flags = VMS_STRUCT, \ |
446 |
.offset = vmstate_offset_value(_state, _field, _type), \ |
447 |
} |
448 |
|
449 |
#define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type) { \
|
450 |
.name = (stringify(_field)), \ |
451 |
.vmsd = &(_vmsd), \ |
452 |
.size = sizeof(_type), \
|
453 |
.flags = VMS_STRUCT|VMS_POINTER, \ |
454 |
.offset = vmstate_offset_value(_state, _field, _type), \ |
455 |
} |
456 |
|
457 |
#define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) {\
|
458 |
.name = (stringify(_field)), \ |
459 |
.version_id = (_version), \ |
460 |
.num = (_num), \ |
461 |
.info = &(_info), \ |
462 |
.size = sizeof(_type), \
|
463 |
.flags = VMS_ARRAY|VMS_ARRAY_OF_POINTER, \ |
464 |
.offset = vmstate_offset_array(_state, _field, _type, _num), \ |
465 |
} |
466 |
|
467 |
#define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) { \
|
468 |
.name = (stringify(_field)), \ |
469 |
.num = (_num), \ |
470 |
.version_id = (_version), \ |
471 |
.vmsd = &(_vmsd), \ |
472 |
.size = sizeof(_type), \
|
473 |
.flags = VMS_STRUCT|VMS_ARRAY, \ |
474 |
.offset = vmstate_offset_array(_state, _field, _type, _num), \ |
475 |
} |
476 |
|
477 |
#define VMSTATE_STRUCT_ARRAY_SIZE_UINT8(_field, _state, _field__num, _version, _vmsd, _type) { \
|
478 |
.name = (stringify(_field)), \ |
479 |
.num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \ |
480 |
.version_id = (_version), \ |
481 |
.vmsd = &(_vmsd), \ |
482 |
.size = sizeof(_type), \
|
483 |
.flags = VMS_STRUCT|VMS_ARRAY, \ |
484 |
.offset = vmstate_offset_array(_state, _field, _type, _num), \ |
485 |
} |
486 |
|
487 |
#define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \
|
488 |
.name = (stringify(_field)), \ |
489 |
.version_id = (_version), \ |
490 |
.field_exists = (_test), \ |
491 |
.size = (_size - _start), \ |
492 |
.info = &vmstate_info_buffer, \ |
493 |
.flags = VMS_BUFFER, \ |
494 |
.offset = vmstate_offset_buffer(_state, _field) + _start, \ |
495 |
} |
496 |
|
497 |
#define VMSTATE_VBUFFER(_field, _state, _version, _test, _start, _field_size) { \
|
498 |
.name = (stringify(_field)), \ |
499 |
.version_id = (_version), \ |
500 |
.field_exists = (_test), \ |
501 |
.size_offset = vmstate_offset_value(_state, _field_size, int32_t),\ |
502 |
.info = &vmstate_info_buffer, \ |
503 |
.flags = VMS_VBUFFER|VMS_POINTER, \ |
504 |
.offset = offsetof(_state, _field), \ |
505 |
.start = (_start), \ |
506 |
} |
507 |
|
508 |
#define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) { \
|
509 |
.name = (stringify(_field)), \ |
510 |
.version_id = (_version), \ |
511 |
.size = (_size), \ |
512 |
.info = &(_info), \ |
513 |
.flags = VMS_BUFFER, \ |
514 |
.offset = offsetof(_state, _field), \ |
515 |
} |
516 |
|
517 |
#define VMSTATE_UNUSED_BUFFER(_test, _version, _size) { \
|
518 |
.name = "unused", \
|
519 |
.field_exists = (_test), \ |
520 |
.version_id = (_version), \ |
521 |
.size = (_size), \ |
522 |
.info = &vmstate_info_unused_buffer, \ |
523 |
.flags = VMS_BUFFER, \ |
524 |
} |
525 |
extern const VMStateDescription vmstate_pci_device; |
526 |
|
527 |
#define VMSTATE_PCI_DEVICE(_field, _state) { \
|
528 |
.name = (stringify(_field)), \ |
529 |
.size = sizeof(PCIDevice), \
|
530 |
.vmsd = &vmstate_pci_device, \ |
531 |
.flags = VMS_STRUCT, \ |
532 |
.offset = vmstate_offset_value(_state, _field, PCIDevice), \ |
533 |
} |
534 |
|
535 |
extern const VMStateDescription vmstate_pcie_device; |
536 |
|
537 |
#define VMSTATE_PCIE_DEVICE(_field, _state) { \
|
538 |
.name = (stringify(_field)), \ |
539 |
.version_id = 2, \
|
540 |
.size = sizeof(PCIDevice), \
|
541 |
.vmsd = &vmstate_pcie_device, \ |
542 |
.flags = VMS_STRUCT, \ |
543 |
.offset = vmstate_offset_value(_state, _field, PCIDevice), \ |
544 |
} |
545 |
|
546 |
extern const VMStateDescription vmstate_i2c_slave; |
547 |
|
548 |
#define VMSTATE_I2C_SLAVE(_field, _state) { \
|
549 |
.name = (stringify(_field)), \ |
550 |
.size = sizeof(i2c_slave), \
|
551 |
.vmsd = &vmstate_i2c_slave, \ |
552 |
.flags = VMS_STRUCT, \ |
553 |
.offset = vmstate_offset_value(_state, _field, i2c_slave), \ |
554 |
} |
555 |
|
556 |
#define vmstate_offset_macaddr(_state, _field) \
|
557 |
vmstate_offset_array(_state, _field.a, uint8_t, \ |
558 |
sizeof(typeof_field(_state, _field)))
|
559 |
|
560 |
#define VMSTATE_MACADDR(_field, _state) { \
|
561 |
.name = (stringify(_field)), \ |
562 |
.size = sizeof(MACAddr), \
|
563 |
.info = &vmstate_info_buffer, \ |
564 |
.flags = VMS_BUFFER, \ |
565 |
.offset = vmstate_offset_macaddr(_state, _field), \ |
566 |
} |
567 |
|
568 |
/* _f : field name
|
569 |
_f_n : num of elements field_name
|
570 |
_n : num of elements
|
571 |
_s : struct state name
|
572 |
_v : version
|
573 |
*/
|
574 |
|
575 |
#define VMSTATE_SINGLE(_field, _state, _version, _info, _type) \
|
576 |
VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type)
|
577 |
|
578 |
#define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) \
|
579 |
VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type)
|
580 |
|
581 |
#define VMSTATE_INT8_V(_f, _s, _v) \
|
582 |
VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t) |
583 |
#define VMSTATE_INT16_V(_f, _s, _v) \
|
584 |
VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t) |
585 |
#define VMSTATE_INT32_V(_f, _s, _v) \
|
586 |
VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t) |
587 |
#define VMSTATE_INT64_V(_f, _s, _v) \
|
588 |
VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t) |
589 |
|
590 |
#define VMSTATE_UINT8_V(_f, _s, _v) \
|
591 |
VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t) |
592 |
#define VMSTATE_UINT16_V(_f, _s, _v) \
|
593 |
VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t) |
594 |
#define VMSTATE_UINT32_V(_f, _s, _v) \
|
595 |
VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t) |
596 |
#define VMSTATE_UINT64_V(_f, _s, _v) \
|
597 |
VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t) |
598 |
|
599 |
#define VMSTATE_INT8(_f, _s) \
|
600 |
VMSTATE_INT8_V(_f, _s, 0)
|
601 |
#define VMSTATE_INT16(_f, _s) \
|
602 |
VMSTATE_INT16_V(_f, _s, 0)
|
603 |
#define VMSTATE_INT32(_f, _s) \
|
604 |
VMSTATE_INT32_V(_f, _s, 0)
|
605 |
#define VMSTATE_INT64(_f, _s) \
|
606 |
VMSTATE_INT64_V(_f, _s, 0)
|
607 |
|
608 |
#define VMSTATE_UINT8(_f, _s) \
|
609 |
VMSTATE_UINT8_V(_f, _s, 0)
|
610 |
#define VMSTATE_UINT16(_f, _s) \
|
611 |
VMSTATE_UINT16_V(_f, _s, 0)
|
612 |
#define VMSTATE_UINT32(_f, _s) \
|
613 |
VMSTATE_UINT32_V(_f, _s, 0)
|
614 |
#define VMSTATE_UINT64(_f, _s) \
|
615 |
VMSTATE_UINT64_V(_f, _s, 0)
|
616 |
|
617 |
#define VMSTATE_UINT8_EQUAL(_f, _s) \
|
618 |
VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t)
|
619 |
|
620 |
#define VMSTATE_UINT16_EQUAL(_f, _s) \
|
621 |
VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint16_equal, uint16_t)
|
622 |
|
623 |
#define VMSTATE_UINT16_EQUAL_V(_f, _s, _v) \
|
624 |
VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16_equal, uint16_t) |
625 |
|
626 |
#define VMSTATE_INT32_EQUAL(_f, _s) \
|
627 |
VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t)
|
628 |
|
629 |
#define VMSTATE_INT32_LE(_f, _s) \
|
630 |
VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
|
631 |
|
632 |
#define VMSTATE_UINT32_TEST(_f, _s, _t) \
|
633 |
VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)
|
634 |
|
635 |
#define VMSTATE_TIMER_V(_f, _s, _v) \
|
636 |
VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *) |
637 |
|
638 |
#define VMSTATE_TIMER(_f, _s) \
|
639 |
VMSTATE_TIMER_V(_f, _s, 0)
|
640 |
|
641 |
#define VMSTATE_TIMER_ARRAY(_f, _s, _n) \
|
642 |
VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *)
|
643 |
|
644 |
#define VMSTATE_PTIMER_V(_f, _s, _v) \
|
645 |
VMSTATE_POINTER(_f, _s, _v, vmstate_info_ptimer, ptimer_state *) |
646 |
|
647 |
#define VMSTATE_PTIMER(_f, _s) \
|
648 |
VMSTATE_PTIMER_V(_f, _s, 0)
|
649 |
|
650 |
#define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v) \
|
651 |
VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t) |
652 |
|
653 |
#define VMSTATE_UINT16_ARRAY(_f, _s, _n) \
|
654 |
VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0)
|
655 |
|
656 |
#define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v) \
|
657 |
VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t) |
658 |
|
659 |
#define VMSTATE_UINT8_ARRAY(_f, _s, _n) \
|
660 |
VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0)
|
661 |
|
662 |
#define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v) \
|
663 |
VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t) |
664 |
|
665 |
#define VMSTATE_UINT32_ARRAY(_f, _s, _n) \
|
666 |
VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
|
667 |
|
668 |
#define VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v) \
|
669 |
VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint64, uint64_t) |
670 |
|
671 |
#define VMSTATE_UINT64_ARRAY(_f, _s, _n) \
|
672 |
VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0)
|
673 |
|
674 |
#define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v) \
|
675 |
VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t) |
676 |
|
677 |
#define VMSTATE_INT16_ARRAY(_f, _s, _n) \
|
678 |
VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0)
|
679 |
|
680 |
#define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v) \
|
681 |
VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t) |
682 |
|
683 |
#define VMSTATE_INT32_ARRAY(_f, _s, _n) \
|
684 |
VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0)
|
685 |
|
686 |
#define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num) \
|
687 |
VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t)
|
688 |
|
689 |
#define VMSTATE_UINT32_ARRAY(_f, _s, _n) \
|
690 |
VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
|
691 |
|
692 |
#define VMSTATE_BUFFER_V(_f, _s, _v) \
|
693 |
VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f))) |
694 |
|
695 |
#define VMSTATE_BUFFER(_f, _s) \
|
696 |
VMSTATE_BUFFER_V(_f, _s, 0)
|
697 |
|
698 |
#define VMSTATE_PARTIAL_BUFFER(_f, _s, _size) \
|
699 |
VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, _size) |
700 |
|
701 |
#define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \
|
702 |
VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, _start, sizeof(typeof_field(_s, _f))) |
703 |
|
704 |
#define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size) \
|
705 |
VMSTATE_VBUFFER(_f, _s, 0, NULL, 0, _size) |
706 |
|
707 |
#define VMSTATE_SUB_VBUFFER(_f, _s, _start, _size) \
|
708 |
VMSTATE_VBUFFER(_f, _s, 0, NULL, _start, _size) |
709 |
|
710 |
#define VMSTATE_BUFFER_TEST(_f, _s, _test) \
|
711 |
VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f))) |
712 |
|
713 |
#define VMSTATE_BUFFER_UNSAFE(_field, _state, _version, _size) \
|
714 |
VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, _size) |
715 |
|
716 |
#define VMSTATE_UNUSED_V(_v, _size) \
|
717 |
VMSTATE_UNUSED_BUFFER(NULL, _v, _size)
|
718 |
|
719 |
#define VMSTATE_UNUSED(_size) \
|
720 |
VMSTATE_UNUSED_V(0, _size)
|
721 |
|
722 |
#define VMSTATE_UNUSED_TEST(_test, _size) \
|
723 |
VMSTATE_UNUSED_BUFFER(_test, 0, _size)
|
724 |
|
725 |
#ifdef NEED_CPU_H
|
726 |
#if TARGET_LONG_BITS == 64 |
727 |
#define VMSTATE_UINTTL_V(_f, _s, _v) \
|
728 |
VMSTATE_UINT64_V(_f, _s, _v) |
729 |
#define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v) \
|
730 |
VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v) |
731 |
#else
|
732 |
#define VMSTATE_UINTTL_V(_f, _s, _v) \
|
733 |
VMSTATE_UINT32_V(_f, _s, _v) |
734 |
#define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v) \
|
735 |
VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v) |
736 |
#endif
|
737 |
#define VMSTATE_UINTTL(_f, _s) \
|
738 |
VMSTATE_UINTTL_V(_f, _s, 0)
|
739 |
#define VMSTATE_UINTTL_ARRAY(_f, _s, _n) \
|
740 |
VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, 0)
|
741 |
|
742 |
#endif
|
743 |
|
744 |
#define VMSTATE_END_OF_LIST() \
|
745 |
{} |
746 |
|
747 |
extern int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, |
748 |
void *opaque, int version_id); |
749 |
extern void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, |
750 |
void *opaque);
|
751 |
extern int vmstate_register(int instance_id, const VMStateDescription *vmsd, |
752 |
void *base);
|
753 |
void vmstate_unregister(const VMStateDescription *vmsd, void *opaque); |
754 |
#endif
|