spapr: convert to memory API
[qemu.git] / hw / hw.h
bloba124da9c262732cba6b02fdc9fc36241c9ebb9e9
1 /* Declarations for use by hardware emulation. */
2 #ifndef QEMU_HW_H
3 #define QEMU_HW_H
5 #include "qemu-common.h"
7 #if defined(TARGET_PHYS_ADDR_BITS) && !defined(NEED_CPU_H)
8 #include "cpu-common.h"
9 #endif
11 #include "ioport.h"
12 #include "irq.h"
14 /* VM Load/Save */
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);
30 /* Close a file and return an error code */
31 typedef int (QEMUFileCloseFunc)(void *opaque);
33 /* Called to determine if the file has exceeded it's bandwidth allocation. The
34 * bandwidth capping is a soft limit, not a hard limit.
36 typedef int (QEMUFileRateLimit)(void *opaque);
38 /* Called to change the current bandwidth allocation. This function must return
39 * the new actual bandwidth. It should be new_rate if everything goes ok, and
40 * the old rate otherwise
42 typedef int64_t (QEMUFileSetRateLimit)(void *opaque, int64_t new_rate);
43 typedef int64_t (QEMUFileGetRateLimit)(void *opaque);
45 QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
46 QEMUFileGetBufferFunc *get_buffer,
47 QEMUFileCloseFunc *close,
48 QEMUFileRateLimit *rate_limit,
49 QEMUFileSetRateLimit *set_rate_limit,
50 QEMUFileGetRateLimit *get_rate_limit);
51 QEMUFile *qemu_fopen(const char *filename, const char *mode);
52 QEMUFile *qemu_fdopen(int fd, const char *mode);
53 QEMUFile *qemu_fopen_socket(int fd);
54 QEMUFile *qemu_popen(FILE *popen_file, const char *mode);
55 QEMUFile *qemu_popen_cmd(const char *command, const char *mode);
56 int qemu_stdio_fd(QEMUFile *f);
57 void qemu_fflush(QEMUFile *f);
58 int qemu_fclose(QEMUFile *f);
59 void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
60 void qemu_put_byte(QEMUFile *f, int v);
62 static inline void qemu_put_ubyte(QEMUFile *f, unsigned int v)
64 qemu_put_byte(f, (int)v);
67 #define qemu_put_sbyte qemu_put_byte
69 void qemu_put_be16(QEMUFile *f, unsigned int v);
70 void qemu_put_be32(QEMUFile *f, unsigned int v);
71 void qemu_put_be64(QEMUFile *f, uint64_t v);
72 int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size);
73 int qemu_get_byte(QEMUFile *f);
75 static inline unsigned int qemu_get_ubyte(QEMUFile *f)
77 return (unsigned int)qemu_get_byte(f);
80 #define qemu_get_sbyte qemu_get_byte
82 unsigned int qemu_get_be16(QEMUFile *f);
83 unsigned int qemu_get_be32(QEMUFile *f);
84 uint64_t qemu_get_be64(QEMUFile *f);
85 int qemu_file_rate_limit(QEMUFile *f);
86 int64_t qemu_file_set_rate_limit(QEMUFile *f, int64_t new_rate);
87 int64_t qemu_file_get_rate_limit(QEMUFile *f);
88 int qemu_file_has_error(QEMUFile *f);
89 void qemu_file_set_error(QEMUFile *f);
91 /* Try to send any outstanding data. This function is useful when output is
92 * halted due to rate limiting or EAGAIN errors occur as it can be used to
93 * resume output. */
94 void qemu_file_put_notify(QEMUFile *f);
96 static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
98 qemu_put_be64(f, *pv);
101 static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv)
103 qemu_put_be32(f, *pv);
106 static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv)
108 qemu_put_be16(f, *pv);
111 static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv)
113 qemu_put_byte(f, *pv);
116 static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv)
118 *pv = qemu_get_be64(f);
121 static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv)
123 *pv = qemu_get_be32(f);
126 static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv)
128 *pv = qemu_get_be16(f);
131 static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv)
133 *pv = qemu_get_byte(f);
136 // Signed versions for type safety
137 static inline void qemu_put_sbuffer(QEMUFile *f, const int8_t *buf, int size)
139 qemu_put_buffer(f, (const uint8_t *)buf, size);
142 static inline void qemu_put_sbe16(QEMUFile *f, int v)
144 qemu_put_be16(f, (unsigned int)v);
147 static inline void qemu_put_sbe32(QEMUFile *f, int v)
149 qemu_put_be32(f, (unsigned int)v);
152 static inline void qemu_put_sbe64(QEMUFile *f, int64_t v)
154 qemu_put_be64(f, (uint64_t)v);
157 static inline size_t qemu_get_sbuffer(QEMUFile *f, int8_t *buf, int size)
159 return qemu_get_buffer(f, (uint8_t *)buf, size);
162 static inline int qemu_get_sbe16(QEMUFile *f)
164 return (int)qemu_get_be16(f);
167 static inline int qemu_get_sbe32(QEMUFile *f)
169 return (int)qemu_get_be32(f);
172 static inline int64_t qemu_get_sbe64(QEMUFile *f)
174 return (int64_t)qemu_get_be64(f);
177 static inline void qemu_put_s8s(QEMUFile *f, const int8_t *pv)
179 qemu_put_8s(f, (const uint8_t *)pv);
182 static inline void qemu_put_sbe16s(QEMUFile *f, const int16_t *pv)
184 qemu_put_be16s(f, (const uint16_t *)pv);
187 static inline void qemu_put_sbe32s(QEMUFile *f, const int32_t *pv)
189 qemu_put_be32s(f, (const uint32_t *)pv);
192 static inline void qemu_put_sbe64s(QEMUFile *f, const int64_t *pv)
194 qemu_put_be64s(f, (const uint64_t *)pv);
197 static inline void qemu_get_s8s(QEMUFile *f, int8_t *pv)
199 qemu_get_8s(f, (uint8_t *)pv);
202 static inline void qemu_get_sbe16s(QEMUFile *f, int16_t *pv)
204 qemu_get_be16s(f, (uint16_t *)pv);
207 static inline void qemu_get_sbe32s(QEMUFile *f, int32_t *pv)
209 qemu_get_be32s(f, (uint32_t *)pv);
212 static inline void qemu_get_sbe64s(QEMUFile *f, int64_t *pv)
214 qemu_get_be64s(f, (uint64_t *)pv);
217 #ifdef NEED_CPU_H
218 #if TARGET_LONG_BITS == 64
219 #define qemu_put_betl qemu_put_be64
220 #define qemu_get_betl qemu_get_be64
221 #define qemu_put_betls qemu_put_be64s
222 #define qemu_get_betls qemu_get_be64s
223 #define qemu_put_sbetl qemu_put_sbe64
224 #define qemu_get_sbetl qemu_get_sbe64
225 #define qemu_put_sbetls qemu_put_sbe64s
226 #define qemu_get_sbetls qemu_get_sbe64s
227 #else
228 #define qemu_put_betl qemu_put_be32
229 #define qemu_get_betl qemu_get_be32
230 #define qemu_put_betls qemu_put_be32s
231 #define qemu_get_betls qemu_get_be32s
232 #define qemu_put_sbetl qemu_put_sbe32
233 #define qemu_get_sbetl qemu_get_sbe32
234 #define qemu_put_sbetls qemu_put_sbe32s
235 #define qemu_get_sbetls qemu_get_sbe32s
236 #endif
237 #endif
239 int64_t qemu_ftell(QEMUFile *f);
240 int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence);
242 typedef void SaveSetParamsHandler(int blk_enable, int shared, void * opaque);
243 typedef void SaveStateHandler(QEMUFile *f, void *opaque);
244 typedef int SaveLiveStateHandler(Monitor *mon, QEMUFile *f, int stage,
245 void *opaque);
246 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
248 int register_savevm(DeviceState *dev,
249 const char *idstr,
250 int instance_id,
251 int version_id,
252 SaveStateHandler *save_state,
253 LoadStateHandler *load_state,
254 void *opaque);
256 int register_savevm_live(DeviceState *dev,
257 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);
266 void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque);
267 void register_device_unmigratable(DeviceState *dev, const char *idstr,
268 void *opaque);
270 typedef void QEMUResetHandler(void *opaque);
272 void qemu_register_reset(QEMUResetHandler *func, void *opaque);
273 void qemu_unregister_reset(QEMUResetHandler *func, void *opaque);
275 /* handler to set the boot_device order for a specific type of QEMUMachine */
276 /* return 0 if success */
277 typedef int QEMUBootSetHandler(void *opaque, const char *boot_devices);
278 void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque);
279 int qemu_boot_set(const char *boot_devices);
281 typedef struct VMStateInfo VMStateInfo;
282 typedef struct VMStateDescription VMStateDescription;
284 struct VMStateInfo {
285 const char *name;
286 int (*get)(QEMUFile *f, void *pv, size_t size);
287 void (*put)(QEMUFile *f, void *pv, size_t size);
290 enum VMStateFlags {
291 VMS_SINGLE = 0x001,
292 VMS_POINTER = 0x002,
293 VMS_ARRAY = 0x004,
294 VMS_STRUCT = 0x008,
295 VMS_VARRAY_INT32 = 0x010, /* Array with size in int32_t field*/
296 VMS_BUFFER = 0x020, /* static sized buffer */
297 VMS_ARRAY_OF_POINTER = 0x040,
298 VMS_VARRAY_UINT16 = 0x080, /* Array with size in uint16_t field */
299 VMS_VBUFFER = 0x100, /* Buffer with size in int32_t field */
300 VMS_MULTIPLY = 0x200, /* multiply "size" field by field_size */
301 VMS_VARRAY_UINT8 = 0x400, /* Array with size in uint8_t field*/
302 VMS_VARRAY_UINT32 = 0x800, /* Array with size in uint32_t field*/
305 typedef struct {
306 const char *name;
307 size_t offset;
308 size_t size;
309 size_t start;
310 int num;
311 size_t num_offset;
312 size_t size_offset;
313 const VMStateInfo *info;
314 enum VMStateFlags flags;
315 const VMStateDescription *vmsd;
316 int version_id;
317 bool (*field_exists)(void *opaque, int version_id);
318 } VMStateField;
320 typedef struct VMStateSubsection {
321 const VMStateDescription *vmsd;
322 bool (*needed)(void *opaque);
323 } VMStateSubsection;
325 struct VMStateDescription {
326 const char *name;
327 int unmigratable;
328 int version_id;
329 int minimum_version_id;
330 int minimum_version_id_old;
331 LoadStateHandler *load_state_old;
332 int (*pre_load)(void *opaque);
333 int (*post_load)(void *opaque, int version_id);
334 void (*pre_save)(void *opaque);
335 VMStateField *fields;
336 const VMStateSubsection *subsections;
339 extern const VMStateInfo vmstate_info_bool;
341 extern const VMStateInfo vmstate_info_int8;
342 extern const VMStateInfo vmstate_info_int16;
343 extern const VMStateInfo vmstate_info_int32;
344 extern const VMStateInfo vmstate_info_int64;
346 extern const VMStateInfo vmstate_info_uint8_equal;
347 extern const VMStateInfo vmstate_info_uint16_equal;
348 extern const VMStateInfo vmstate_info_int32_equal;
349 extern const VMStateInfo vmstate_info_uint32_equal;
350 extern const VMStateInfo vmstate_info_int32_le;
352 extern const VMStateInfo vmstate_info_uint8;
353 extern const VMStateInfo vmstate_info_uint16;
354 extern const VMStateInfo vmstate_info_uint32;
355 extern const VMStateInfo vmstate_info_uint64;
357 extern const VMStateInfo vmstate_info_timer;
358 extern const VMStateInfo vmstate_info_ptimer;
359 extern const VMStateInfo vmstate_info_buffer;
360 extern const VMStateInfo vmstate_info_unused_buffer;
362 #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
363 #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
365 #define vmstate_offset_value(_state, _field, _type) \
366 (offsetof(_state, _field) + \
367 type_check(_type, typeof_field(_state, _field)))
369 #define vmstate_offset_pointer(_state, _field, _type) \
370 (offsetof(_state, _field) + \
371 type_check_pointer(_type, typeof_field(_state, _field)))
373 #define vmstate_offset_array(_state, _field, _type, _num) \
374 (offsetof(_state, _field) + \
375 type_check_array(_type, typeof_field(_state, _field), _num))
377 #define vmstate_offset_sub_array(_state, _field, _type, _start) \
378 (offsetof(_state, _field[_start]))
380 #define vmstate_offset_buffer(_state, _field) \
381 vmstate_offset_array(_state, _field, uint8_t, \
382 sizeof(typeof_field(_state, _field)))
384 #define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \
385 .name = (stringify(_field)), \
386 .version_id = (_version), \
387 .field_exists = (_test), \
388 .size = sizeof(_type), \
389 .info = &(_info), \
390 .flags = VMS_SINGLE, \
391 .offset = vmstate_offset_value(_state, _field, _type), \
394 #define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \
395 .name = (stringify(_field)), \
396 .version_id = (_version), \
397 .info = &(_info), \
398 .size = sizeof(_type), \
399 .flags = VMS_SINGLE|VMS_POINTER, \
400 .offset = vmstate_offset_value(_state, _field, _type), \
403 #define VMSTATE_POINTER_TEST(_field, _state, _test, _info, _type) { \
404 .name = (stringify(_field)), \
405 .info = &(_info), \
406 .field_exists = (_test), \
407 .size = sizeof(_type), \
408 .flags = VMS_SINGLE|VMS_POINTER, \
409 .offset = vmstate_offset_value(_state, _field, _type), \
412 #define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\
413 .name = (stringify(_field)), \
414 .version_id = (_version), \
415 .num = (_num), \
416 .info = &(_info), \
417 .size = sizeof(_type), \
418 .flags = VMS_ARRAY, \
419 .offset = vmstate_offset_array(_state, _field, _type, _num), \
422 #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
423 .name = (stringify(_field)), \
424 .field_exists = (_test), \
425 .num = (_num), \
426 .info = &(_info), \
427 .size = sizeof(_type), \
428 .flags = VMS_ARRAY, \
429 .offset = vmstate_offset_array(_state, _field, _type, _num),\
432 #define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \
433 .name = (stringify(_field)), \
434 .version_id = (_version), \
435 .num = (_num), \
436 .info = &(_info), \
437 .size = sizeof(_type), \
438 .flags = VMS_ARRAY, \
439 .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \
442 #define VMSTATE_ARRAY_INT32_UNSAFE(_field, _state, _field_num, _info, _type) {\
443 .name = (stringify(_field)), \
444 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
445 .info = &(_info), \
446 .size = sizeof(_type), \
447 .flags = VMS_VARRAY_INT32, \
448 .offset = offsetof(_state, _field), \
451 #define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\
452 .name = (stringify(_field)), \
453 .version_id = (_version), \
454 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
455 .info = &(_info), \
456 .size = sizeof(_type), \
457 .flags = VMS_VARRAY_INT32|VMS_POINTER, \
458 .offset = vmstate_offset_pointer(_state, _field, _type), \
461 #define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info, _type) {\
462 .name = (stringify(_field)), \
463 .version_id = (_version), \
464 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
465 .info = &(_info), \
466 .size = sizeof(_type), \
467 .flags = VMS_VARRAY_UINT32|VMS_POINTER, \
468 .offset = vmstate_offset_pointer(_state, _field, _type), \
471 #define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version, _info, _type) {\
472 .name = (stringify(_field)), \
473 .version_id = (_version), \
474 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
475 .info = &(_info), \
476 .size = sizeof(_type), \
477 .flags = VMS_VARRAY_UINT16, \
478 .offset = offsetof(_state, _field), \
481 #define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \
482 .name = (stringify(_field)), \
483 .version_id = (_version), \
484 .field_exists = (_test), \
485 .vmsd = &(_vmsd), \
486 .size = sizeof(_type), \
487 .flags = VMS_STRUCT, \
488 .offset = vmstate_offset_value(_state, _field, _type), \
491 #define VMSTATE_STRUCT_POINTER_TEST(_field, _state, _test, _vmsd, _type) { \
492 .name = (stringify(_field)), \
493 .field_exists = (_test), \
494 .vmsd = &(_vmsd), \
495 .size = sizeof(_type), \
496 .flags = VMS_STRUCT|VMS_POINTER, \
497 .offset = vmstate_offset_value(_state, _field, _type), \
500 #define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) {\
501 .name = (stringify(_field)), \
502 .version_id = (_version), \
503 .num = (_num), \
504 .info = &(_info), \
505 .size = sizeof(_type), \
506 .flags = VMS_ARRAY|VMS_ARRAY_OF_POINTER, \
507 .offset = vmstate_offset_array(_state, _field, _type, _num), \
510 #define VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, _test, _version, _vmsd, _type) { \
511 .name = (stringify(_field)), \
512 .num = (_num), \
513 .field_exists = (_test), \
514 .version_id = (_version), \
515 .vmsd = &(_vmsd), \
516 .size = sizeof(_type), \
517 .flags = VMS_STRUCT|VMS_ARRAY, \
518 .offset = vmstate_offset_array(_state, _field, _type, _num),\
521 #define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, _vmsd, _type) { \
522 .name = (stringify(_field)), \
523 .num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \
524 .version_id = (_version), \
525 .vmsd = &(_vmsd), \
526 .size = sizeof(_type), \
527 .flags = VMS_STRUCT|VMS_VARRAY_UINT8, \
528 .offset = offsetof(_state, _field), \
531 #define VMSTATE_STRUCT_VARRAY_POINTER_INT32(_field, _state, _field_num, _vmsd, _type) { \
532 .name = (stringify(_field)), \
533 .version_id = 0, \
534 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
535 .size = sizeof(_type), \
536 .vmsd = &(_vmsd), \
537 .flags = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \
538 .offset = vmstate_offset_pointer(_state, _field, _type), \
541 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, _vmsd, _type) { \
542 .name = (stringify(_field)), \
543 .version_id = 0, \
544 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
545 .size = sizeof(_type), \
546 .vmsd = &(_vmsd), \
547 .flags = VMS_POINTER | VMS_VARRAY_UINT16 | VMS_STRUCT, \
548 .offset = vmstate_offset_pointer(_state, _field, _type), \
551 #define VMSTATE_STRUCT_VARRAY_INT32(_field, _state, _field_num, _version, _vmsd, _type) { \
552 .name = (stringify(_field)), \
553 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
554 .version_id = (_version), \
555 .vmsd = &(_vmsd), \
556 .size = sizeof(_type), \
557 .flags = VMS_STRUCT|VMS_VARRAY_INT32, \
558 .offset = offsetof(_state, _field), \
561 #define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version, _vmsd, _type) { \
562 .name = (stringify(_field)), \
563 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t), \
564 .version_id = (_version), \
565 .vmsd = &(_vmsd), \
566 .size = sizeof(_type), \
567 .flags = VMS_STRUCT|VMS_VARRAY_UINT32, \
568 .offset = offsetof(_state, _field), \
571 #define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \
572 .name = (stringify(_field)), \
573 .version_id = (_version), \
574 .field_exists = (_test), \
575 .size = (_size - _start), \
576 .info = &vmstate_info_buffer, \
577 .flags = VMS_BUFFER, \
578 .offset = vmstate_offset_buffer(_state, _field) + _start, \
581 #define VMSTATE_BUFFER_MULTIPLY(_field, _state, _version, _test, _start, _field_size, _multiply) { \
582 .name = (stringify(_field)), \
583 .version_id = (_version), \
584 .field_exists = (_test), \
585 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\
586 .size = (_multiply), \
587 .info = &vmstate_info_buffer, \
588 .flags = VMS_VBUFFER|VMS_MULTIPLY, \
589 .offset = offsetof(_state, _field), \
590 .start = (_start), \
593 #define VMSTATE_VBUFFER(_field, _state, _version, _test, _start, _field_size) { \
594 .name = (stringify(_field)), \
595 .version_id = (_version), \
596 .field_exists = (_test), \
597 .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\
598 .info = &vmstate_info_buffer, \
599 .flags = VMS_VBUFFER|VMS_POINTER, \
600 .offset = offsetof(_state, _field), \
601 .start = (_start), \
604 #define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _start, _field_size) { \
605 .name = (stringify(_field)), \
606 .version_id = (_version), \
607 .field_exists = (_test), \
608 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\
609 .info = &vmstate_info_buffer, \
610 .flags = VMS_VBUFFER|VMS_POINTER, \
611 .offset = offsetof(_state, _field), \
612 .start = (_start), \
615 #define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) { \
616 .name = (stringify(_field)), \
617 .version_id = (_version), \
618 .size = (_size), \
619 .info = &(_info), \
620 .flags = VMS_BUFFER, \
621 .offset = offsetof(_state, _field), \
624 #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) { \
625 .name = "unused", \
626 .field_exists = (_test), \
627 .version_id = (_version), \
628 .size = (_size), \
629 .info = &vmstate_info_unused_buffer, \
630 .flags = VMS_BUFFER, \
632 extern const VMStateDescription vmstate_pci_device;
634 #define VMSTATE_PCI_DEVICE(_field, _state) { \
635 .name = (stringify(_field)), \
636 .size = sizeof(PCIDevice), \
637 .vmsd = &vmstate_pci_device, \
638 .flags = VMS_STRUCT, \
639 .offset = vmstate_offset_value(_state, _field, PCIDevice), \
642 #define VMSTATE_PCI_DEVICE_POINTER(_field, _state) { \
643 .name = (stringify(_field)), \
644 .size = sizeof(PCIDevice), \
645 .vmsd = &vmstate_pci_device, \
646 .flags = VMS_STRUCT|VMS_POINTER, \
647 .offset = vmstate_offset_pointer(_state, _field, PCIDevice), \
650 extern const VMStateDescription vmstate_pcie_device;
652 #define VMSTATE_PCIE_DEVICE(_field, _state) { \
653 .name = (stringify(_field)), \
654 .version_id = 2, \
655 .size = sizeof(PCIDevice), \
656 .vmsd = &vmstate_pcie_device, \
657 .flags = VMS_STRUCT, \
658 .offset = vmstate_offset_value(_state, _field, PCIDevice), \
661 extern const VMStateDescription vmstate_i2c_slave;
663 #define VMSTATE_I2C_SLAVE(_field, _state) { \
664 .name = (stringify(_field)), \
665 .size = sizeof(i2c_slave), \
666 .vmsd = &vmstate_i2c_slave, \
667 .flags = VMS_STRUCT, \
668 .offset = vmstate_offset_value(_state, _field, i2c_slave), \
671 extern const VMStateDescription vmstate_usb_device;
673 #define VMSTATE_USB_DEVICE(_field, _state) { \
674 .name = (stringify(_field)), \
675 .size = sizeof(USBDevice), \
676 .vmsd = &vmstate_usb_device, \
677 .flags = VMS_STRUCT, \
678 .offset = vmstate_offset_value(_state, _field, USBDevice), \
681 #define vmstate_offset_macaddr(_state, _field) \
682 vmstate_offset_array(_state, _field.a, uint8_t, \
683 sizeof(typeof_field(_state, _field)))
685 #define VMSTATE_MACADDR(_field, _state) { \
686 .name = (stringify(_field)), \
687 .size = sizeof(MACAddr), \
688 .info = &vmstate_info_buffer, \
689 .flags = VMS_BUFFER, \
690 .offset = vmstate_offset_macaddr(_state, _field), \
693 extern const VMStateDescription vmstate_ptimer;
695 #define VMSTATE_PTIMER(_field, _state) { \
696 .name = (stringify(_field)), \
697 .version_id = (1), \
698 .vmsd = &vmstate_ptimer, \
699 .size = sizeof(ptimer_state *), \
700 .flags = VMS_STRUCT|VMS_POINTER, \
701 .offset = vmstate_offset_pointer(_state, _field, ptimer_state), \
704 extern const VMStateDescription vmstate_hid_keyboard_device;
706 #define VMSTATE_HID_KEYBOARD_DEVICE(_field, _state) { \
707 .name = (stringify(_field)), \
708 .size = sizeof(HIDState), \
709 .vmsd = &vmstate_hid_keyboard_device, \
710 .flags = VMS_STRUCT, \
711 .offset = vmstate_offset_value(_state, _field, HIDState), \
714 extern const VMStateDescription vmstate_hid_ptr_device;
716 #define VMSTATE_HID_POINTER_DEVICE(_field, _state) { \
717 .name = (stringify(_field)), \
718 .size = sizeof(HIDState), \
719 .vmsd = &vmstate_hid_ptr_device, \
720 .flags = VMS_STRUCT, \
721 .offset = vmstate_offset_value(_state, _field, HIDState), \
724 /* _f : field name
725 _f_n : num of elements field_name
726 _n : num of elements
727 _s : struct state name
728 _v : version
731 #define VMSTATE_SINGLE(_field, _state, _version, _info, _type) \
732 VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type)
734 #define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) \
735 VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type)
737 #define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type) \
738 VMSTATE_STRUCT_POINTER_TEST(_field, _state, NULL, _vmsd, _type)
740 #define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) \
741 VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version, \
742 _vmsd, _type)
744 #define VMSTATE_BOOL_V(_f, _s, _v) \
745 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool)
747 #define VMSTATE_INT8_V(_f, _s, _v) \
748 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t)
749 #define VMSTATE_INT16_V(_f, _s, _v) \
750 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t)
751 #define VMSTATE_INT32_V(_f, _s, _v) \
752 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t)
753 #define VMSTATE_INT64_V(_f, _s, _v) \
754 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t)
756 #define VMSTATE_UINT8_V(_f, _s, _v) \
757 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t)
758 #define VMSTATE_UINT16_V(_f, _s, _v) \
759 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t)
760 #define VMSTATE_UINT32_V(_f, _s, _v) \
761 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t)
762 #define VMSTATE_UINT64_V(_f, _s, _v) \
763 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t)
765 #define VMSTATE_BOOL(_f, _s) \
766 VMSTATE_BOOL_V(_f, _s, 0)
768 #define VMSTATE_INT8(_f, _s) \
769 VMSTATE_INT8_V(_f, _s, 0)
770 #define VMSTATE_INT16(_f, _s) \
771 VMSTATE_INT16_V(_f, _s, 0)
772 #define VMSTATE_INT32(_f, _s) \
773 VMSTATE_INT32_V(_f, _s, 0)
774 #define VMSTATE_INT64(_f, _s) \
775 VMSTATE_INT64_V(_f, _s, 0)
777 #define VMSTATE_UINT8(_f, _s) \
778 VMSTATE_UINT8_V(_f, _s, 0)
779 #define VMSTATE_UINT16(_f, _s) \
780 VMSTATE_UINT16_V(_f, _s, 0)
781 #define VMSTATE_UINT32(_f, _s) \
782 VMSTATE_UINT32_V(_f, _s, 0)
783 #define VMSTATE_UINT64(_f, _s) \
784 VMSTATE_UINT64_V(_f, _s, 0)
786 #define VMSTATE_UINT8_EQUAL(_f, _s) \
787 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t)
789 #define VMSTATE_UINT16_EQUAL(_f, _s) \
790 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint16_equal, uint16_t)
792 #define VMSTATE_UINT16_EQUAL_V(_f, _s, _v) \
793 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16_equal, uint16_t)
795 #define VMSTATE_INT32_EQUAL(_f, _s) \
796 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t)
798 #define VMSTATE_UINT32_EQUAL(_f, _s) \
799 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint32_equal, uint32_t)
801 #define VMSTATE_INT32_LE(_f, _s) \
802 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
804 #define VMSTATE_UINT8_TEST(_f, _s, _t) \
805 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t)
807 #define VMSTATE_UINT16_TEST(_f, _s, _t) \
808 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
810 #define VMSTATE_UINT32_TEST(_f, _s, _t) \
811 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)
813 #define VMSTATE_TIMER_TEST(_f, _s, _test) \
814 VMSTATE_POINTER_TEST(_f, _s, _test, vmstate_info_timer, QEMUTimer *)
816 #define VMSTATE_TIMER(_f, _s) \
817 VMSTATE_TIMER_TEST(_f, _s, NULL)
819 #define VMSTATE_TIMER_ARRAY(_f, _s, _n) \
820 VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *)
822 #define VMSTATE_BOOL_ARRAY_V(_f, _s, _n, _v) \
823 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_bool, bool)
825 #define VMSTATE_BOOL_ARRAY(_f, _s, _n) \
826 VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0)
828 #define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v) \
829 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t)
831 #define VMSTATE_UINT16_ARRAY(_f, _s, _n) \
832 VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0)
834 #define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v) \
835 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t)
837 #define VMSTATE_UINT8_ARRAY(_f, _s, _n) \
838 VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0)
840 #define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v) \
841 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t)
843 #define VMSTATE_UINT32_ARRAY(_f, _s, _n) \
844 VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
846 #define VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v) \
847 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint64, uint64_t)
849 #define VMSTATE_UINT64_ARRAY(_f, _s, _n) \
850 VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0)
852 #define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v) \
853 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t)
855 #define VMSTATE_INT16_ARRAY(_f, _s, _n) \
856 VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0)
858 #define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v) \
859 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t)
861 #define VMSTATE_INT32_ARRAY(_f, _s, _n) \
862 VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0)
864 #define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num) \
865 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t)
867 #define VMSTATE_UINT32_ARRAY(_f, _s, _n) \
868 VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
870 #define VMSTATE_INT64_ARRAY_V(_f, _s, _n, _v) \
871 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int64, int64_t)
873 #define VMSTATE_INT64_ARRAY(_f, _s, _n) \
874 VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0)
876 #define VMSTATE_BUFFER_V(_f, _s, _v) \
877 VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f)))
879 #define VMSTATE_BUFFER(_f, _s) \
880 VMSTATE_BUFFER_V(_f, _s, 0)
882 #define VMSTATE_PARTIAL_BUFFER(_f, _s, _size) \
883 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, _size)
885 #define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \
886 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, _start, sizeof(typeof_field(_s, _f)))
888 #define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size) \
889 VMSTATE_VBUFFER(_f, _s, 0, NULL, 0, _size)
891 #define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size) \
892 VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, 0, _size)
894 #define VMSTATE_SUB_VBUFFER(_f, _s, _start, _size) \
895 VMSTATE_VBUFFER(_f, _s, 0, NULL, _start, _size)
897 #define VMSTATE_BUFFER_TEST(_f, _s, _test) \
898 VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f)))
900 #define VMSTATE_BUFFER_UNSAFE(_field, _state, _version, _size) \
901 VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, _size)
903 #define VMSTATE_UNUSED_V(_v, _size) \
904 VMSTATE_UNUSED_BUFFER(NULL, _v, _size)
906 #define VMSTATE_UNUSED(_size) \
907 VMSTATE_UNUSED_V(0, _size)
909 #define VMSTATE_UNUSED_TEST(_test, _size) \
910 VMSTATE_UNUSED_BUFFER(_test, 0, _size)
912 #ifdef NEED_CPU_H
913 #if TARGET_LONG_BITS == 64
914 #define VMSTATE_UINTTL_V(_f, _s, _v) \
915 VMSTATE_UINT64_V(_f, _s, _v)
916 #define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v) \
917 VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)
918 #else
919 #define VMSTATE_UINTTL_V(_f, _s, _v) \
920 VMSTATE_UINT32_V(_f, _s, _v)
921 #define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v) \
922 VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)
923 #endif
924 #define VMSTATE_UINTTL(_f, _s) \
925 VMSTATE_UINTTL_V(_f, _s, 0)
926 #define VMSTATE_UINTTL_ARRAY(_f, _s, _n) \
927 VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, 0)
929 #endif
931 #define VMSTATE_END_OF_LIST() \
934 int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
935 void *opaque, int version_id);
936 void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
937 void *opaque);
938 int vmstate_register(DeviceState *dev, int instance_id,
939 const VMStateDescription *vmsd, void *base);
940 int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
941 const VMStateDescription *vmsd,
942 void *base, int alias_id,
943 int required_for_version);
944 void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd,
945 void *opaque);
946 #endif