1 /* Declarations for use by hardware emulation. */
5 #include "qemu-common.h"
7 #if defined(TARGET_PHYS_ADDR_BITS) && !defined(NEED_CPU_H)
8 #include "cpu-common.h"
16 /* This function writes a chunk of data to a file at the given position.
17 * The pos argument can be ignored if the file is only being used for
18 * streaming. The handler should try to write all of the data it can.
20 typedef int (QEMUFilePutBufferFunc
)(void *opaque
, const uint8_t *buf
,
21 int64_t pos
, int size
);
23 /* Read a chunk of data from a file at the given position. The pos argument
24 * can be ignored if the file is only be used for streaming. The number of
25 * bytes actually read should be returned.
27 typedef int (QEMUFileGetBufferFunc
)(void *opaque
, uint8_t *buf
,
28 int64_t pos
, int size
);
32 * Return negative error number on error, 0 or positive value on success.
34 * The meaning of return value on success depends on the specific back-end being
37 typedef int (QEMUFileCloseFunc
)(void *opaque
);
39 /* Called to determine if the file has exceeded it's bandwidth allocation. The
40 * bandwidth capping is a soft limit, not a hard limit.
42 typedef int (QEMUFileRateLimit
)(void *opaque
);
44 /* Called to change the current bandwidth allocation. This function must return
45 * the new actual bandwidth. It should be new_rate if everything goes ok, and
46 * the old rate otherwise
48 typedef int64_t (QEMUFileSetRateLimit
)(void *opaque
, int64_t new_rate
);
49 typedef int64_t (QEMUFileGetRateLimit
)(void *opaque
);
51 QEMUFile
*qemu_fopen_ops(void *opaque
, QEMUFilePutBufferFunc
*put_buffer
,
52 QEMUFileGetBufferFunc
*get_buffer
,
53 QEMUFileCloseFunc
*close
,
54 QEMUFileRateLimit
*rate_limit
,
55 QEMUFileSetRateLimit
*set_rate_limit
,
56 QEMUFileGetRateLimit
*get_rate_limit
);
57 QEMUFile
*qemu_fopen(const char *filename
, const char *mode
);
58 QEMUFile
*qemu_fdopen(int fd
, const char *mode
);
59 QEMUFile
*qemu_fopen_socket(int fd
);
60 QEMUFile
*qemu_popen(FILE *popen_file
, const char *mode
);
61 QEMUFile
*qemu_popen_cmd(const char *command
, const char *mode
);
62 int qemu_stdio_fd(QEMUFile
*f
);
63 void qemu_fflush(QEMUFile
*f
);
64 int qemu_fclose(QEMUFile
*f
);
65 void qemu_put_buffer(QEMUFile
*f
, const uint8_t *buf
, int size
);
66 void qemu_put_byte(QEMUFile
*f
, int v
);
68 static inline void qemu_put_ubyte(QEMUFile
*f
, unsigned int v
)
70 qemu_put_byte(f
, (int)v
);
73 #define qemu_put_sbyte qemu_put_byte
75 void qemu_put_be16(QEMUFile
*f
, unsigned int v
);
76 void qemu_put_be32(QEMUFile
*f
, unsigned int v
);
77 void qemu_put_be64(QEMUFile
*f
, uint64_t v
);
78 int qemu_get_buffer(QEMUFile
*f
, uint8_t *buf
, int size
);
79 int qemu_get_byte(QEMUFile
*f
);
81 static inline unsigned int qemu_get_ubyte(QEMUFile
*f
)
83 return (unsigned int)qemu_get_byte(f
);
86 #define qemu_get_sbyte qemu_get_byte
88 unsigned int qemu_get_be16(QEMUFile
*f
);
89 unsigned int qemu_get_be32(QEMUFile
*f
);
90 uint64_t qemu_get_be64(QEMUFile
*f
);
91 int qemu_file_rate_limit(QEMUFile
*f
);
92 int64_t qemu_file_set_rate_limit(QEMUFile
*f
, int64_t new_rate
);
93 int64_t qemu_file_get_rate_limit(QEMUFile
*f
);
94 int qemu_file_get_error(QEMUFile
*f
);
95 void qemu_file_set_error(QEMUFile
*f
, int error
);
97 /* Try to send any outstanding data. This function is useful when output is
98 * halted due to rate limiting or EAGAIN errors occur as it can be used to
100 void qemu_file_put_notify(QEMUFile
*f
);
102 static inline void qemu_put_be64s(QEMUFile
*f
, const uint64_t *pv
)
104 qemu_put_be64(f
, *pv
);
107 static inline void qemu_put_be32s(QEMUFile
*f
, const uint32_t *pv
)
109 qemu_put_be32(f
, *pv
);
112 static inline void qemu_put_be16s(QEMUFile
*f
, const uint16_t *pv
)
114 qemu_put_be16(f
, *pv
);
117 static inline void qemu_put_8s(QEMUFile
*f
, const uint8_t *pv
)
119 qemu_put_byte(f
, *pv
);
122 static inline void qemu_get_be64s(QEMUFile
*f
, uint64_t *pv
)
124 *pv
= qemu_get_be64(f
);
127 static inline void qemu_get_be32s(QEMUFile
*f
, uint32_t *pv
)
129 *pv
= qemu_get_be32(f
);
132 static inline void qemu_get_be16s(QEMUFile
*f
, uint16_t *pv
)
134 *pv
= qemu_get_be16(f
);
137 static inline void qemu_get_8s(QEMUFile
*f
, uint8_t *pv
)
139 *pv
= qemu_get_byte(f
);
142 // Signed versions for type safety
143 static inline void qemu_put_sbuffer(QEMUFile
*f
, const int8_t *buf
, int size
)
145 qemu_put_buffer(f
, (const uint8_t *)buf
, size
);
148 static inline void qemu_put_sbe16(QEMUFile
*f
, int v
)
150 qemu_put_be16(f
, (unsigned int)v
);
153 static inline void qemu_put_sbe32(QEMUFile
*f
, int v
)
155 qemu_put_be32(f
, (unsigned int)v
);
158 static inline void qemu_put_sbe64(QEMUFile
*f
, int64_t v
)
160 qemu_put_be64(f
, (uint64_t)v
);
163 static inline size_t qemu_get_sbuffer(QEMUFile
*f
, int8_t *buf
, int size
)
165 return qemu_get_buffer(f
, (uint8_t *)buf
, size
);
168 static inline int qemu_get_sbe16(QEMUFile
*f
)
170 return (int)qemu_get_be16(f
);
173 static inline int qemu_get_sbe32(QEMUFile
*f
)
175 return (int)qemu_get_be32(f
);
178 static inline int64_t qemu_get_sbe64(QEMUFile
*f
)
180 return (int64_t)qemu_get_be64(f
);
183 static inline void qemu_put_s8s(QEMUFile
*f
, const int8_t *pv
)
185 qemu_put_8s(f
, (const uint8_t *)pv
);
188 static inline void qemu_put_sbe16s(QEMUFile
*f
, const int16_t *pv
)
190 qemu_put_be16s(f
, (const uint16_t *)pv
);
193 static inline void qemu_put_sbe32s(QEMUFile
*f
, const int32_t *pv
)
195 qemu_put_be32s(f
, (const uint32_t *)pv
);
198 static inline void qemu_put_sbe64s(QEMUFile
*f
, const int64_t *pv
)
200 qemu_put_be64s(f
, (const uint64_t *)pv
);
203 static inline void qemu_get_s8s(QEMUFile
*f
, int8_t *pv
)
205 qemu_get_8s(f
, (uint8_t *)pv
);
208 static inline void qemu_get_sbe16s(QEMUFile
*f
, int16_t *pv
)
210 qemu_get_be16s(f
, (uint16_t *)pv
);
213 static inline void qemu_get_sbe32s(QEMUFile
*f
, int32_t *pv
)
215 qemu_get_be32s(f
, (uint32_t *)pv
);
218 static inline void qemu_get_sbe64s(QEMUFile
*f
, int64_t *pv
)
220 qemu_get_be64s(f
, (uint64_t *)pv
);
224 #if TARGET_LONG_BITS == 64
225 #define qemu_put_betl qemu_put_be64
226 #define qemu_get_betl qemu_get_be64
227 #define qemu_put_betls qemu_put_be64s
228 #define qemu_get_betls qemu_get_be64s
229 #define qemu_put_sbetl qemu_put_sbe64
230 #define qemu_get_sbetl qemu_get_sbe64
231 #define qemu_put_sbetls qemu_put_sbe64s
232 #define qemu_get_sbetls qemu_get_sbe64s
234 #define qemu_put_betl qemu_put_be32
235 #define qemu_get_betl qemu_get_be32
236 #define qemu_put_betls qemu_put_be32s
237 #define qemu_get_betls qemu_get_be32s
238 #define qemu_put_sbetl qemu_put_sbe32
239 #define qemu_get_sbetl qemu_get_sbe32
240 #define qemu_put_sbetls qemu_put_sbe32s
241 #define qemu_get_sbetls qemu_get_sbe32s
245 int64_t qemu_ftell(QEMUFile
*f
);
246 int64_t qemu_fseek(QEMUFile
*f
, int64_t pos
, int whence
);
248 typedef void SaveSetParamsHandler(int blk_enable
, int shared
, void * opaque
);
249 typedef void SaveStateHandler(QEMUFile
*f
, void *opaque
);
250 typedef int SaveLiveStateHandler(Monitor
*mon
, QEMUFile
*f
, int stage
,
252 typedef int LoadStateHandler(QEMUFile
*f
, void *opaque
, int version_id
);
254 int register_savevm(DeviceState
*dev
,
258 SaveStateHandler
*save_state
,
259 LoadStateHandler
*load_state
,
262 int register_savevm_live(DeviceState
*dev
,
266 SaveSetParamsHandler
*set_params
,
267 SaveLiveStateHandler
*save_live_state
,
268 SaveStateHandler
*save_state
,
269 LoadStateHandler
*load_state
,
272 void unregister_savevm(DeviceState
*dev
, const char *idstr
, void *opaque
);
273 void register_device_unmigratable(DeviceState
*dev
, const char *idstr
,
276 typedef void QEMUResetHandler(void *opaque
);
278 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
);
279 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
);
281 /* handler to set the boot_device order for a specific type of QEMUMachine */
282 /* return 0 if success */
283 typedef int QEMUBootSetHandler(void *opaque
, const char *boot_devices
);
284 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
);
285 int qemu_boot_set(const char *boot_devices
);
287 typedef struct VMStateInfo VMStateInfo
;
288 typedef struct VMStateDescription VMStateDescription
;
292 int (*get
)(QEMUFile
*f
, void *pv
, size_t size
);
293 void (*put
)(QEMUFile
*f
, void *pv
, size_t size
);
301 VMS_VARRAY_INT32
= 0x010, /* Array with size in int32_t field*/
302 VMS_BUFFER
= 0x020, /* static sized buffer */
303 VMS_ARRAY_OF_POINTER
= 0x040,
304 VMS_VARRAY_UINT16
= 0x080, /* Array with size in uint16_t field */
305 VMS_VBUFFER
= 0x100, /* Buffer with size in int32_t field */
306 VMS_MULTIPLY
= 0x200, /* multiply "size" field by field_size */
307 VMS_VARRAY_UINT8
= 0x400, /* Array with size in uint8_t field*/
308 VMS_VARRAY_UINT32
= 0x800, /* Array with size in uint32_t field*/
319 const VMStateInfo
*info
;
320 enum VMStateFlags flags
;
321 const VMStateDescription
*vmsd
;
323 bool (*field_exists
)(void *opaque
, int version_id
);
326 typedef struct VMStateSubsection
{
327 const VMStateDescription
*vmsd
;
328 bool (*needed
)(void *opaque
);
331 struct VMStateDescription
{
335 int minimum_version_id
;
336 int minimum_version_id_old
;
337 LoadStateHandler
*load_state_old
;
338 int (*pre_load
)(void *opaque
);
339 int (*post_load
)(void *opaque
, int version_id
);
340 void (*pre_save
)(void *opaque
);
341 VMStateField
*fields
;
342 const VMStateSubsection
*subsections
;
345 extern const VMStateInfo vmstate_info_bool
;
347 extern const VMStateInfo vmstate_info_int8
;
348 extern const VMStateInfo vmstate_info_int16
;
349 extern const VMStateInfo vmstate_info_int32
;
350 extern const VMStateInfo vmstate_info_int64
;
352 extern const VMStateInfo vmstate_info_uint8_equal
;
353 extern const VMStateInfo vmstate_info_uint16_equal
;
354 extern const VMStateInfo vmstate_info_int32_equal
;
355 extern const VMStateInfo vmstate_info_uint32_equal
;
356 extern const VMStateInfo vmstate_info_int32_le
;
358 extern const VMStateInfo vmstate_info_uint8
;
359 extern const VMStateInfo vmstate_info_uint16
;
360 extern const VMStateInfo vmstate_info_uint32
;
361 extern const VMStateInfo vmstate_info_uint64
;
363 extern const VMStateInfo vmstate_info_timer
;
364 extern const VMStateInfo vmstate_info_ptimer
;
365 extern const VMStateInfo vmstate_info_buffer
;
366 extern const VMStateInfo vmstate_info_unused_buffer
;
368 #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
369 #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
371 #define vmstate_offset_value(_state, _field, _type) \
372 (offsetof(_state, _field) + \
373 type_check(_type, typeof_field(_state, _field)))
375 #define vmstate_offset_pointer(_state, _field, _type) \
376 (offsetof(_state, _field) + \
377 type_check_pointer(_type, typeof_field(_state, _field)))
379 #define vmstate_offset_array(_state, _field, _type, _num) \
380 (offsetof(_state, _field) + \
381 type_check_array(_type, typeof_field(_state, _field), _num))
383 #define vmstate_offset_sub_array(_state, _field, _type, _start) \
384 (offsetof(_state, _field[_start]))
386 #define vmstate_offset_buffer(_state, _field) \
387 vmstate_offset_array(_state, _field, uint8_t, \
388 sizeof(typeof_field(_state, _field)))
390 #define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \
391 .name = (stringify(_field)), \
392 .version_id = (_version), \
393 .field_exists = (_test), \
394 .size = sizeof(_type), \
396 .flags = VMS_SINGLE, \
397 .offset = vmstate_offset_value(_state, _field, _type), \
400 #define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \
401 .name = (stringify(_field)), \
402 .version_id = (_version), \
404 .size = sizeof(_type), \
405 .flags = VMS_SINGLE|VMS_POINTER, \
406 .offset = vmstate_offset_value(_state, _field, _type), \
409 #define VMSTATE_POINTER_TEST(_field, _state, _test, _info, _type) { \
410 .name = (stringify(_field)), \
412 .field_exists = (_test), \
413 .size = sizeof(_type), \
414 .flags = VMS_SINGLE|VMS_POINTER, \
415 .offset = vmstate_offset_value(_state, _field, _type), \
418 #define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\
419 .name = (stringify(_field)), \
420 .version_id = (_version), \
423 .size = sizeof(_type), \
424 .flags = VMS_ARRAY, \
425 .offset = vmstate_offset_array(_state, _field, _type, _num), \
428 #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
429 .name = (stringify(_field)), \
430 .field_exists = (_test), \
433 .size = sizeof(_type), \
434 .flags = VMS_ARRAY, \
435 .offset = vmstate_offset_array(_state, _field, _type, _num),\
438 #define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \
439 .name = (stringify(_field)), \
440 .version_id = (_version), \
443 .size = sizeof(_type), \
444 .flags = VMS_ARRAY, \
445 .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \
448 #define VMSTATE_ARRAY_INT32_UNSAFE(_field, _state, _field_num, _info, _type) {\
449 .name = (stringify(_field)), \
450 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
452 .size = sizeof(_type), \
453 .flags = VMS_VARRAY_INT32, \
454 .offset = offsetof(_state, _field), \
457 #define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\
458 .name = (stringify(_field)), \
459 .version_id = (_version), \
460 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
462 .size = sizeof(_type), \
463 .flags = VMS_VARRAY_INT32|VMS_POINTER, \
464 .offset = vmstate_offset_pointer(_state, _field, _type), \
467 #define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info, _type) {\
468 .name = (stringify(_field)), \
469 .version_id = (_version), \
470 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
472 .size = sizeof(_type), \
473 .flags = VMS_VARRAY_UINT32|VMS_POINTER, \
474 .offset = vmstate_offset_pointer(_state, _field, _type), \
477 #define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version, _info, _type) {\
478 .name = (stringify(_field)), \
479 .version_id = (_version), \
480 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
482 .size = sizeof(_type), \
483 .flags = VMS_VARRAY_UINT16, \
484 .offset = offsetof(_state, _field), \
487 #define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \
488 .name = (stringify(_field)), \
489 .version_id = (_version), \
490 .field_exists = (_test), \
492 .size = sizeof(_type), \
493 .flags = VMS_STRUCT, \
494 .offset = vmstate_offset_value(_state, _field, _type), \
497 #define VMSTATE_STRUCT_POINTER_TEST(_field, _state, _test, _vmsd, _type) { \
498 .name = (stringify(_field)), \
499 .field_exists = (_test), \
501 .size = sizeof(_type), \
502 .flags = VMS_STRUCT|VMS_POINTER, \
503 .offset = vmstate_offset_value(_state, _field, _type), \
506 #define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) {\
507 .name = (stringify(_field)), \
508 .version_id = (_version), \
511 .size = sizeof(_type), \
512 .flags = VMS_ARRAY|VMS_ARRAY_OF_POINTER, \
513 .offset = vmstate_offset_array(_state, _field, _type, _num), \
516 #define VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, _test, _version, _vmsd, _type) { \
517 .name = (stringify(_field)), \
519 .field_exists = (_test), \
520 .version_id = (_version), \
522 .size = sizeof(_type), \
523 .flags = VMS_STRUCT|VMS_ARRAY, \
524 .offset = vmstate_offset_array(_state, _field, _type, _num),\
527 #define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, _vmsd, _type) { \
528 .name = (stringify(_field)), \
529 .num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \
530 .version_id = (_version), \
532 .size = sizeof(_type), \
533 .flags = VMS_STRUCT|VMS_VARRAY_UINT8, \
534 .offset = offsetof(_state, _field), \
537 #define VMSTATE_STRUCT_VARRAY_POINTER_INT32(_field, _state, _field_num, _vmsd, _type) { \
538 .name = (stringify(_field)), \
540 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
541 .size = sizeof(_type), \
543 .flags = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \
544 .offset = vmstate_offset_pointer(_state, _field, _type), \
547 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, _vmsd, _type) { \
548 .name = (stringify(_field)), \
550 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
551 .size = sizeof(_type), \
553 .flags = VMS_POINTER | VMS_VARRAY_UINT16 | VMS_STRUCT, \
554 .offset = vmstate_offset_pointer(_state, _field, _type), \
557 #define VMSTATE_STRUCT_VARRAY_INT32(_field, _state, _field_num, _version, _vmsd, _type) { \
558 .name = (stringify(_field)), \
559 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
560 .version_id = (_version), \
562 .size = sizeof(_type), \
563 .flags = VMS_STRUCT|VMS_VARRAY_INT32, \
564 .offset = offsetof(_state, _field), \
567 #define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version, _vmsd, _type) { \
568 .name = (stringify(_field)), \
569 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t), \
570 .version_id = (_version), \
572 .size = sizeof(_type), \
573 .flags = VMS_STRUCT|VMS_VARRAY_UINT32, \
574 .offset = offsetof(_state, _field), \
577 #define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \
578 .name = (stringify(_field)), \
579 .version_id = (_version), \
580 .field_exists = (_test), \
581 .size = (_size - _start), \
582 .info = &vmstate_info_buffer, \
583 .flags = VMS_BUFFER, \
584 .offset = vmstate_offset_buffer(_state, _field) + _start, \
587 #define VMSTATE_BUFFER_MULTIPLY(_field, _state, _version, _test, _start, _field_size, _multiply) { \
588 .name = (stringify(_field)), \
589 .version_id = (_version), \
590 .field_exists = (_test), \
591 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\
592 .size = (_multiply), \
593 .info = &vmstate_info_buffer, \
594 .flags = VMS_VBUFFER|VMS_MULTIPLY, \
595 .offset = offsetof(_state, _field), \
599 #define VMSTATE_VBUFFER(_field, _state, _version, _test, _start, _field_size) { \
600 .name = (stringify(_field)), \
601 .version_id = (_version), \
602 .field_exists = (_test), \
603 .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\
604 .info = &vmstate_info_buffer, \
605 .flags = VMS_VBUFFER|VMS_POINTER, \
606 .offset = offsetof(_state, _field), \
610 #define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _start, _field_size) { \
611 .name = (stringify(_field)), \
612 .version_id = (_version), \
613 .field_exists = (_test), \
614 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\
615 .info = &vmstate_info_buffer, \
616 .flags = VMS_VBUFFER|VMS_POINTER, \
617 .offset = offsetof(_state, _field), \
621 #define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) { \
622 .name = (stringify(_field)), \
623 .version_id = (_version), \
626 .flags = VMS_BUFFER, \
627 .offset = offsetof(_state, _field), \
630 #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) { \
632 .field_exists = (_test), \
633 .version_id = (_version), \
635 .info = &vmstate_info_unused_buffer, \
636 .flags = VMS_BUFFER, \
638 extern const VMStateDescription vmstate_pci_device
;
640 #define VMSTATE_PCI_DEVICE(_field, _state) { \
641 .name = (stringify(_field)), \
642 .size = sizeof(PCIDevice), \
643 .vmsd = &vmstate_pci_device, \
644 .flags = VMS_STRUCT, \
645 .offset = vmstate_offset_value(_state, _field, PCIDevice), \
648 #define VMSTATE_PCI_DEVICE_POINTER(_field, _state) { \
649 .name = (stringify(_field)), \
650 .size = sizeof(PCIDevice), \
651 .vmsd = &vmstate_pci_device, \
652 .flags = VMS_STRUCT|VMS_POINTER, \
653 .offset = vmstate_offset_pointer(_state, _field, PCIDevice), \
656 extern const VMStateDescription vmstate_pcie_device
;
658 #define VMSTATE_PCIE_DEVICE(_field, _state) { \
659 .name = (stringify(_field)), \
661 .size = sizeof(PCIDevice), \
662 .vmsd = &vmstate_pcie_device, \
663 .flags = VMS_STRUCT, \
664 .offset = vmstate_offset_value(_state, _field, PCIDevice), \
667 extern const VMStateDescription vmstate_i2c_slave
;
669 #define VMSTATE_I2C_SLAVE(_field, _state) { \
670 .name = (stringify(_field)), \
671 .size = sizeof(i2c_slave), \
672 .vmsd = &vmstate_i2c_slave, \
673 .flags = VMS_STRUCT, \
674 .offset = vmstate_offset_value(_state, _field, i2c_slave), \
677 extern const VMStateDescription vmstate_usb_device
;
679 #define VMSTATE_USB_DEVICE(_field, _state) { \
680 .name = (stringify(_field)), \
681 .size = sizeof(USBDevice), \
682 .vmsd = &vmstate_usb_device, \
683 .flags = VMS_STRUCT, \
684 .offset = vmstate_offset_value(_state, _field, USBDevice), \
687 #define vmstate_offset_macaddr(_state, _field) \
688 vmstate_offset_array(_state, _field.a, uint8_t, \
689 sizeof(typeof_field(_state, _field)))
691 #define VMSTATE_MACADDR(_field, _state) { \
692 .name = (stringify(_field)), \
693 .size = sizeof(MACAddr), \
694 .info = &vmstate_info_buffer, \
695 .flags = VMS_BUFFER, \
696 .offset = vmstate_offset_macaddr(_state, _field), \
699 extern const VMStateDescription vmstate_ptimer
;
701 #define VMSTATE_PTIMER(_field, _state) { \
702 .name = (stringify(_field)), \
704 .vmsd = &vmstate_ptimer, \
705 .size = sizeof(ptimer_state *), \
706 .flags = VMS_STRUCT|VMS_POINTER, \
707 .offset = vmstate_offset_pointer(_state, _field, ptimer_state), \
710 extern const VMStateDescription vmstate_hid_keyboard_device
;
712 #define VMSTATE_HID_KEYBOARD_DEVICE(_field, _state) { \
713 .name = (stringify(_field)), \
714 .size = sizeof(HIDState), \
715 .vmsd = &vmstate_hid_keyboard_device, \
716 .flags = VMS_STRUCT, \
717 .offset = vmstate_offset_value(_state, _field, HIDState), \
720 extern const VMStateDescription vmstate_hid_ptr_device
;
722 #define VMSTATE_HID_POINTER_DEVICE(_field, _state) { \
723 .name = (stringify(_field)), \
724 .size = sizeof(HIDState), \
725 .vmsd = &vmstate_hid_ptr_device, \
726 .flags = VMS_STRUCT, \
727 .offset = vmstate_offset_value(_state, _field, HIDState), \
731 _f_n : num of elements field_name
733 _s : struct state name
737 #define VMSTATE_SINGLE(_field, _state, _version, _info, _type) \
738 VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type)
740 #define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) \
741 VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type)
743 #define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type) \
744 VMSTATE_STRUCT_POINTER_TEST(_field, _state, NULL, _vmsd, _type)
746 #define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) \
747 VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version, \
750 #define VMSTATE_BOOL_V(_f, _s, _v) \
751 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool)
753 #define VMSTATE_INT8_V(_f, _s, _v) \
754 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t)
755 #define VMSTATE_INT16_V(_f, _s, _v) \
756 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t)
757 #define VMSTATE_INT32_V(_f, _s, _v) \
758 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t)
759 #define VMSTATE_INT64_V(_f, _s, _v) \
760 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t)
762 #define VMSTATE_UINT8_V(_f, _s, _v) \
763 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t)
764 #define VMSTATE_UINT16_V(_f, _s, _v) \
765 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t)
766 #define VMSTATE_UINT32_V(_f, _s, _v) \
767 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t)
768 #define VMSTATE_UINT64_V(_f, _s, _v) \
769 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t)
771 #define VMSTATE_BOOL(_f, _s) \
772 VMSTATE_BOOL_V(_f, _s, 0)
774 #define VMSTATE_INT8(_f, _s) \
775 VMSTATE_INT8_V(_f, _s, 0)
776 #define VMSTATE_INT16(_f, _s) \
777 VMSTATE_INT16_V(_f, _s, 0)
778 #define VMSTATE_INT32(_f, _s) \
779 VMSTATE_INT32_V(_f, _s, 0)
780 #define VMSTATE_INT64(_f, _s) \
781 VMSTATE_INT64_V(_f, _s, 0)
783 #define VMSTATE_UINT8(_f, _s) \
784 VMSTATE_UINT8_V(_f, _s, 0)
785 #define VMSTATE_UINT16(_f, _s) \
786 VMSTATE_UINT16_V(_f, _s, 0)
787 #define VMSTATE_UINT32(_f, _s) \
788 VMSTATE_UINT32_V(_f, _s, 0)
789 #define VMSTATE_UINT64(_f, _s) \
790 VMSTATE_UINT64_V(_f, _s, 0)
792 #define VMSTATE_UINT8_EQUAL(_f, _s) \
793 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t)
795 #define VMSTATE_UINT16_EQUAL(_f, _s) \
796 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint16_equal, uint16_t)
798 #define VMSTATE_UINT16_EQUAL_V(_f, _s, _v) \
799 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16_equal, uint16_t)
801 #define VMSTATE_INT32_EQUAL(_f, _s) \
802 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t)
804 #define VMSTATE_UINT32_EQUAL(_f, _s) \
805 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint32_equal, uint32_t)
807 #define VMSTATE_INT32_LE(_f, _s) \
808 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
810 #define VMSTATE_UINT8_TEST(_f, _s, _t) \
811 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t)
813 #define VMSTATE_UINT16_TEST(_f, _s, _t) \
814 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
816 #define VMSTATE_UINT32_TEST(_f, _s, _t) \
817 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)
819 #define VMSTATE_TIMER_TEST(_f, _s, _test) \
820 VMSTATE_POINTER_TEST(_f, _s, _test, vmstate_info_timer, QEMUTimer *)
822 #define VMSTATE_TIMER(_f, _s) \
823 VMSTATE_TIMER_TEST(_f, _s, NULL)
825 #define VMSTATE_TIMER_ARRAY(_f, _s, _n) \
826 VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *)
828 #define VMSTATE_BOOL_ARRAY_V(_f, _s, _n, _v) \
829 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_bool, bool)
831 #define VMSTATE_BOOL_ARRAY(_f, _s, _n) \
832 VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0)
834 #define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v) \
835 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t)
837 #define VMSTATE_UINT16_ARRAY(_f, _s, _n) \
838 VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0)
840 #define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v) \
841 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t)
843 #define VMSTATE_UINT8_ARRAY(_f, _s, _n) \
844 VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0)
846 #define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v) \
847 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t)
849 #define VMSTATE_UINT32_ARRAY(_f, _s, _n) \
850 VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
852 #define VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v) \
853 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint64, uint64_t)
855 #define VMSTATE_UINT64_ARRAY(_f, _s, _n) \
856 VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0)
858 #define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v) \
859 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t)
861 #define VMSTATE_INT16_ARRAY(_f, _s, _n) \
862 VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0)
864 #define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v) \
865 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t)
867 #define VMSTATE_INT32_ARRAY(_f, _s, _n) \
868 VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0)
870 #define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num) \
871 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t)
873 #define VMSTATE_UINT32_ARRAY(_f, _s, _n) \
874 VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
876 #define VMSTATE_INT64_ARRAY_V(_f, _s, _n, _v) \
877 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int64, int64_t)
879 #define VMSTATE_INT64_ARRAY(_f, _s, _n) \
880 VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0)
882 #define VMSTATE_BUFFER_V(_f, _s, _v) \
883 VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f)))
885 #define VMSTATE_BUFFER(_f, _s) \
886 VMSTATE_BUFFER_V(_f, _s, 0)
888 #define VMSTATE_PARTIAL_BUFFER(_f, _s, _size) \
889 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, _size)
891 #define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \
892 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, _start, sizeof(typeof_field(_s, _f)))
894 #define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size) \
895 VMSTATE_VBUFFER(_f, _s, 0, NULL, 0, _size)
897 #define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size) \
898 VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, 0, _size)
900 #define VMSTATE_SUB_VBUFFER(_f, _s, _start, _size) \
901 VMSTATE_VBUFFER(_f, _s, 0, NULL, _start, _size)
903 #define VMSTATE_BUFFER_TEST(_f, _s, _test) \
904 VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f)))
906 #define VMSTATE_BUFFER_UNSAFE(_field, _state, _version, _size) \
907 VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, _size)
909 #define VMSTATE_UNUSED_V(_v, _size) \
910 VMSTATE_UNUSED_BUFFER(NULL, _v, _size)
912 #define VMSTATE_UNUSED(_size) \
913 VMSTATE_UNUSED_V(0, _size)
915 #define VMSTATE_UNUSED_TEST(_test, _size) \
916 VMSTATE_UNUSED_BUFFER(_test, 0, _size)
919 #if TARGET_LONG_BITS == 64
920 #define VMSTATE_UINTTL_V(_f, _s, _v) \
921 VMSTATE_UINT64_V(_f, _s, _v)
922 #define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v) \
923 VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)
925 #define VMSTATE_UINTTL_V(_f, _s, _v) \
926 VMSTATE_UINT32_V(_f, _s, _v)
927 #define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v) \
928 VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)
930 #define VMSTATE_UINTTL(_f, _s) \
931 VMSTATE_UINTTL_V(_f, _s, 0)
932 #define VMSTATE_UINTTL_ARRAY(_f, _s, _n) \
933 VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, 0)
937 #define VMSTATE_END_OF_LIST() \
940 int vmstate_load_state(QEMUFile
*f
, const VMStateDescription
*vmsd
,
941 void *opaque
, int version_id
);
942 void vmstate_save_state(QEMUFile
*f
, const VMStateDescription
*vmsd
,
944 int vmstate_register(DeviceState
*dev
, int instance_id
,
945 const VMStateDescription
*vmsd
, void *base
);
946 int vmstate_register_with_alias_id(DeviceState
*dev
, int instance_id
,
947 const VMStateDescription
*vmsd
,
948 void *base
, int alias_id
,
949 int required_for_version
);
950 void vmstate_unregister(DeviceState
*dev
, const VMStateDescription
*vmsd
,
953 void vmstate_register_ram(struct MemoryRegion
*memory
, DeviceState
*dev
);
954 void vmstate_unregister_ram(struct MemoryRegion
*memory
, DeviceState
*dev
);
955 void vmstate_register_ram_global(struct MemoryRegion
*memory
);