xref: /openbmc/qemu/include/migration/vmstate.h (revision 1559e0d4)
1 /*
2  * QEMU migration/snapshot declarations
3  *
4  * Copyright (c) 2009-2011 Red Hat, Inc.
5  *
6  * Original author: Juan Quintela <quintela@redhat.com>
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  * THE SOFTWARE.
25  */
26 #ifndef QEMU_VMSTATE_H
27 #define QEMU_VMSTATE_H 1
28 
29 #include <migration/qemu-file.h>
30 
31 typedef void SaveStateHandler(QEMUFile *f, void *opaque);
32 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
33 
34 typedef struct SaveVMHandlers {
35     void (*set_params)(const MigrationParams *params, void * opaque);
36     SaveStateHandler *save_state;
37     int (*save_live_setup)(QEMUFile *f, void *opaque);
38     int (*save_live_iterate)(QEMUFile *f, void *opaque);
39     int (*save_live_complete)(QEMUFile *f, void *opaque);
40     uint64_t (*save_live_pending)(QEMUFile *f, void *opaque, uint64_t max_size);
41     void (*cancel)(void *opaque);
42     LoadStateHandler *load_state;
43     bool (*is_active)(void *opaque);
44 } SaveVMHandlers;
45 
46 int register_savevm(DeviceState *dev,
47                     const char *idstr,
48                     int instance_id,
49                     int version_id,
50                     SaveStateHandler *save_state,
51                     LoadStateHandler *load_state,
52                     void *opaque);
53 
54 int register_savevm_live(DeviceState *dev,
55                          const char *idstr,
56                          int instance_id,
57                          int version_id,
58                          SaveVMHandlers *ops,
59                          void *opaque);
60 
61 void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque);
62 void register_device_unmigratable(DeviceState *dev, const char *idstr,
63                                                                 void *opaque);
64 
65 
66 typedef struct VMStateInfo VMStateInfo;
67 typedef struct VMStateDescription VMStateDescription;
68 
69 struct VMStateInfo {
70     const char *name;
71     int (*get)(QEMUFile *f, void *pv, size_t size);
72     void (*put)(QEMUFile *f, void *pv, size_t size);
73 };
74 
75 enum VMStateFlags {
76     VMS_SINGLE           = 0x001,
77     VMS_POINTER          = 0x002,
78     VMS_ARRAY            = 0x004,
79     VMS_STRUCT           = 0x008,
80     VMS_VARRAY_INT32     = 0x010,  /* Array with size in int32_t field*/
81     VMS_BUFFER           = 0x020,  /* static sized buffer */
82     VMS_ARRAY_OF_POINTER = 0x040,
83     VMS_VARRAY_UINT16    = 0x080,  /* Array with size in uint16_t field */
84     VMS_VBUFFER          = 0x100,  /* Buffer with size in int32_t field */
85     VMS_MULTIPLY         = 0x200,  /* multiply "size" field by field_size */
86     VMS_VARRAY_UINT8     = 0x400,  /* Array with size in uint8_t field*/
87     VMS_VARRAY_UINT32    = 0x800,  /* Array with size in uint32_t field*/
88 };
89 
90 typedef struct {
91     const char *name;
92     size_t offset;
93     size_t size;
94     size_t start;
95     int num;
96     size_t num_offset;
97     size_t size_offset;
98     const VMStateInfo *info;
99     enum VMStateFlags flags;
100     const VMStateDescription *vmsd;
101     int version_id;
102     bool (*field_exists)(void *opaque, int version_id);
103 } VMStateField;
104 
105 typedef struct VMStateSubsection {
106     const VMStateDescription *vmsd;
107     bool (*needed)(void *opaque);
108 } VMStateSubsection;
109 
110 struct VMStateDescription {
111     const char *name;
112     int unmigratable;
113     int version_id;
114     int minimum_version_id;
115     int minimum_version_id_old;
116     LoadStateHandler *load_state_old;
117     int (*pre_load)(void *opaque);
118     int (*post_load)(void *opaque, int version_id);
119     void (*pre_save)(void *opaque);
120     VMStateField *fields;
121     const VMStateSubsection *subsections;
122 };
123 
124 extern const VMStateInfo vmstate_info_bool;
125 
126 extern const VMStateInfo vmstate_info_int8;
127 extern const VMStateInfo vmstate_info_int16;
128 extern const VMStateInfo vmstate_info_int32;
129 extern const VMStateInfo vmstate_info_int64;
130 
131 extern const VMStateInfo vmstate_info_uint8_equal;
132 extern const VMStateInfo vmstate_info_uint16_equal;
133 extern const VMStateInfo vmstate_info_int32_equal;
134 extern const VMStateInfo vmstate_info_uint32_equal;
135 extern const VMStateInfo vmstate_info_int32_le;
136 
137 extern const VMStateInfo vmstate_info_uint8;
138 extern const VMStateInfo vmstate_info_uint16;
139 extern const VMStateInfo vmstate_info_uint32;
140 extern const VMStateInfo vmstate_info_uint64;
141 
142 extern const VMStateInfo vmstate_info_timer;
143 extern const VMStateInfo vmstate_info_buffer;
144 extern const VMStateInfo vmstate_info_unused_buffer;
145 extern const VMStateInfo vmstate_info_bitmap;
146 
147 #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
148 #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
149 
150 #define vmstate_offset_value(_state, _field, _type)                  \
151     (offsetof(_state, _field) +                                      \
152      type_check(_type, typeof_field(_state, _field)))
153 
154 #define vmstate_offset_pointer(_state, _field, _type)                \
155     (offsetof(_state, _field) +                                      \
156      type_check_pointer(_type, typeof_field(_state, _field)))
157 
158 #define vmstate_offset_array(_state, _field, _type, _num)            \
159     (offsetof(_state, _field) +                                      \
160      type_check_array(_type, typeof_field(_state, _field), _num))
161 
162 #define vmstate_offset_sub_array(_state, _field, _type, _start)      \
163     (offsetof(_state, _field[_start]))
164 
165 #define vmstate_offset_buffer(_state, _field)                        \
166     vmstate_offset_array(_state, _field, uint8_t,                    \
167                          sizeof(typeof_field(_state, _field)))
168 
169 #define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \
170     .name         = (stringify(_field)),                             \
171     .version_id   = (_version),                                      \
172     .field_exists = (_test),                                         \
173     .size         = sizeof(_type),                                   \
174     .info         = &(_info),                                        \
175     .flags        = VMS_SINGLE,                                      \
176     .offset       = vmstate_offset_value(_state, _field, _type),     \
177 }
178 
179 #define VMSTATE_POINTER(_field, _state, _version, _info, _type) {    \
180     .name       = (stringify(_field)),                               \
181     .version_id = (_version),                                        \
182     .info       = &(_info),                                          \
183     .size       = sizeof(_type),                                     \
184     .flags      = VMS_SINGLE|VMS_POINTER,                            \
185     .offset     = vmstate_offset_value(_state, _field, _type),       \
186 }
187 
188 #define VMSTATE_POINTER_TEST(_field, _state, _test, _info, _type) {  \
189     .name       = (stringify(_field)),                               \
190     .info       = &(_info),                                          \
191     .field_exists = (_test),                                         \
192     .size       = sizeof(_type),                                     \
193     .flags      = VMS_SINGLE|VMS_POINTER,                            \
194     .offset     = vmstate_offset_value(_state, _field, _type),       \
195 }
196 
197 #define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\
198     .name       = (stringify(_field)),                               \
199     .version_id = (_version),                                        \
200     .num        = (_num),                                            \
201     .info       = &(_info),                                          \
202     .size       = sizeof(_type),                                     \
203     .flags      = VMS_ARRAY,                                         \
204     .offset     = vmstate_offset_array(_state, _field, _type, _num), \
205 }
206 
207 #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
208     .name         = (stringify(_field)),                              \
209     .field_exists = (_test),                                          \
210     .num          = (_num),                                           \
211     .info         = &(_info),                                         \
212     .size         = sizeof(_type),                                    \
213     .flags        = VMS_ARRAY,                                        \
214     .offset       = vmstate_offset_array(_state, _field, _type, _num),\
215 }
216 
217 #define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \
218     .name       = (stringify(_field)),                               \
219     .version_id = (_version),                                        \
220     .num        = (_num),                                            \
221     .info       = &(_info),                                          \
222     .size       = sizeof(_type),                                     \
223     .flags      = VMS_ARRAY,                                         \
224     .offset     = vmstate_offset_sub_array(_state, _field, _type, _start), \
225 }
226 
227 #define VMSTATE_ARRAY_INT32_UNSAFE(_field, _state, _field_num, _info, _type) {\
228     .name       = (stringify(_field)),                               \
229     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
230     .info       = &(_info),                                          \
231     .size       = sizeof(_type),                                     \
232     .flags      = VMS_VARRAY_INT32,                                  \
233     .offset     = offsetof(_state, _field),                          \
234 }
235 
236 #define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\
237     .name       = (stringify(_field)),                               \
238     .version_id = (_version),                                        \
239     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
240     .info       = &(_info),                                          \
241     .size       = sizeof(_type),                                     \
242     .flags      = VMS_VARRAY_INT32|VMS_POINTER,                      \
243     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
244 }
245 
246 #define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info, _type) {\
247     .name       = (stringify(_field)),                               \
248     .version_id = (_version),                                        \
249     .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
250     .info       = &(_info),                                          \
251     .size       = sizeof(_type),                                     \
252     .flags      = VMS_VARRAY_UINT32|VMS_POINTER,                     \
253     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
254 }
255 
256 #define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version, _info, _type) {\
257     .name       = (stringify(_field)),                               \
258     .version_id = (_version),                                        \
259     .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
260     .info       = &(_info),                                          \
261     .size       = sizeof(_type),                                     \
262     .flags      = VMS_VARRAY_UINT16,                                 \
263     .offset     = offsetof(_state, _field),                          \
264 }
265 
266 #define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \
267     .name         = (stringify(_field)),                             \
268     .version_id   = (_version),                                      \
269     .field_exists = (_test),                                         \
270     .vmsd         = &(_vmsd),                                        \
271     .size         = sizeof(_type),                                   \
272     .flags        = VMS_STRUCT,                                      \
273     .offset       = vmstate_offset_value(_state, _field, _type),     \
274 }
275 
276 #define VMSTATE_STRUCT_POINTER_TEST(_field, _state, _test, _vmsd, _type) { \
277     .name         = (stringify(_field)),                             \
278     .field_exists = (_test),                                         \
279     .vmsd         = &(_vmsd),                                        \
280     .size         = sizeof(_type),                                   \
281     .flags        = VMS_STRUCT|VMS_POINTER,                          \
282     .offset       = vmstate_offset_value(_state, _field, _type),     \
283 }
284 
285 #define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) {\
286     .name       = (stringify(_field)),                               \
287     .version_id = (_version),                                        \
288     .num        = (_num),                                            \
289     .info       = &(_info),                                          \
290     .size       = sizeof(_type),                                     \
291     .flags      = VMS_ARRAY|VMS_ARRAY_OF_POINTER,                    \
292     .offset     = vmstate_offset_array(_state, _field, _type, _num), \
293 }
294 
295 #define VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, _test, _version, _vmsd, _type) { \
296     .name         = (stringify(_field)),                             \
297     .num          = (_num),                                          \
298     .field_exists = (_test),                                         \
299     .version_id   = (_version),                                      \
300     .vmsd         = &(_vmsd),                                        \
301     .size         = sizeof(_type),                                   \
302     .flags        = VMS_STRUCT|VMS_ARRAY,                            \
303     .offset       = vmstate_offset_array(_state, _field, _type, _num),\
304 }
305 
306 #define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, _vmsd, _type) { \
307     .name       = (stringify(_field)),                               \
308     .num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \
309     .version_id = (_version),                                        \
310     .vmsd       = &(_vmsd),                                          \
311     .size       = sizeof(_type),                                     \
312     .flags      = VMS_STRUCT|VMS_VARRAY_UINT8,                       \
313     .offset     = offsetof(_state, _field),                          \
314 }
315 
316 #define VMSTATE_STRUCT_VARRAY_POINTER_INT32(_field, _state, _field_num, _vmsd, _type) { \
317     .name       = (stringify(_field)),                               \
318     .version_id = 0,                                                 \
319     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
320     .size       = sizeof(_type),                                     \
321     .vmsd       = &(_vmsd),                                          \
322     .flags      = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT,       \
323     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
324 }
325 
326 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, _vmsd, _type) { \
327     .name       = (stringify(_field)),                               \
328     .version_id = 0,                                                 \
329     .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
330     .size       = sizeof(_type),                                     \
331     .vmsd       = &(_vmsd),                                          \
332     .flags      = VMS_POINTER | VMS_VARRAY_UINT16 | VMS_STRUCT,      \
333     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
334 }
335 
336 #define VMSTATE_STRUCT_VARRAY_INT32(_field, _state, _field_num, _version, _vmsd, _type) { \
337     .name       = (stringify(_field)),                               \
338     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
339     .version_id = (_version),                                        \
340     .vmsd       = &(_vmsd),                                          \
341     .size       = sizeof(_type),                                     \
342     .flags      = VMS_STRUCT|VMS_VARRAY_INT32,                       \
343     .offset     = offsetof(_state, _field),                          \
344 }
345 
346 #define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version, _vmsd, _type) { \
347     .name       = (stringify(_field)),                               \
348     .num_offset = vmstate_offset_value(_state, _field_num, uint32_t), \
349     .version_id = (_version),                                        \
350     .vmsd       = &(_vmsd),                                          \
351     .size       = sizeof(_type),                                     \
352     .flags      = VMS_STRUCT|VMS_VARRAY_UINT32,                      \
353     .offset     = offsetof(_state, _field),                          \
354 }
355 
356 #define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \
357     .name         = (stringify(_field)),                             \
358     .version_id   = (_version),                                      \
359     .field_exists = (_test),                                         \
360     .size         = (_size - _start),                                \
361     .info         = &vmstate_info_buffer,                            \
362     .flags        = VMS_BUFFER,                                      \
363     .offset       = vmstate_offset_buffer(_state, _field) + _start,  \
364 }
365 
366 #define VMSTATE_BUFFER_MULTIPLY(_field, _state, _version, _test, _start, _field_size, _multiply) { \
367     .name         = (stringify(_field)),                             \
368     .version_id   = (_version),                                      \
369     .field_exists = (_test),                                         \
370     .size_offset  = vmstate_offset_value(_state, _field_size, uint32_t),\
371     .size         = (_multiply),                                      \
372     .info         = &vmstate_info_buffer,                            \
373     .flags        = VMS_VBUFFER|VMS_MULTIPLY,                        \
374     .offset       = offsetof(_state, _field),                        \
375     .start        = (_start),                                        \
376 }
377 
378 #define VMSTATE_VBUFFER(_field, _state, _version, _test, _start, _field_size) { \
379     .name         = (stringify(_field)),                             \
380     .version_id   = (_version),                                      \
381     .field_exists = (_test),                                         \
382     .size_offset  = vmstate_offset_value(_state, _field_size, int32_t),\
383     .info         = &vmstate_info_buffer,                            \
384     .flags        = VMS_VBUFFER|VMS_POINTER,                         \
385     .offset       = offsetof(_state, _field),                        \
386     .start        = (_start),                                        \
387 }
388 
389 #define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _start, _field_size) { \
390     .name         = (stringify(_field)),                             \
391     .version_id   = (_version),                                      \
392     .field_exists = (_test),                                         \
393     .size_offset  = vmstate_offset_value(_state, _field_size, uint32_t),\
394     .info         = &vmstate_info_buffer,                            \
395     .flags        = VMS_VBUFFER|VMS_POINTER,                         \
396     .offset       = offsetof(_state, _field),                        \
397     .start        = (_start),                                        \
398 }
399 
400 #define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) { \
401     .name       = (stringify(_field)),                               \
402     .version_id = (_version),                                        \
403     .size       = (_size),                                           \
404     .info       = &(_info),                                          \
405     .flags      = VMS_BUFFER,                                        \
406     .offset     = offsetof(_state, _field),                          \
407 }
408 
409 #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) {              \
410     .name         = "unused",                                        \
411     .field_exists = (_test),                                         \
412     .version_id   = (_version),                                      \
413     .size         = (_size),                                         \
414     .info         = &vmstate_info_unused_buffer,                     \
415     .flags        = VMS_BUFFER,                                      \
416 }
417 
418 /* _field_size should be a int32_t field in the _state struct giving the
419  * size of the bitmap _field in bits.
420  */
421 #define VMSTATE_BITMAP(_field, _state, _version, _field_size) {      \
422     .name         = (stringify(_field)),                             \
423     .version_id   = (_version),                                      \
424     .size_offset  = vmstate_offset_value(_state, _field_size, int32_t),\
425     .info         = &vmstate_info_bitmap,                            \
426     .flags        = VMS_VBUFFER|VMS_POINTER,                         \
427     .offset       = offsetof(_state, _field),                        \
428 }
429 
430 /* _f : field name
431    _f_n : num of elements field_name
432    _n : num of elements
433    _s : struct state name
434    _v : version
435 */
436 
437 #define VMSTATE_SINGLE(_field, _state, _version, _info, _type)        \
438     VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type)
439 
440 #define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type)        \
441     VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type)
442 
443 #define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type)          \
444     VMSTATE_STRUCT_POINTER_TEST(_field, _state, NULL, _vmsd, _type)
445 
446 #define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) \
447     VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version,   \
448             _vmsd, _type)
449 
450 #define VMSTATE_BOOL_V(_f, _s, _v)                                    \
451     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool)
452 
453 #define VMSTATE_INT8_V(_f, _s, _v)                                    \
454     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t)
455 #define VMSTATE_INT16_V(_f, _s, _v)                                   \
456     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t)
457 #define VMSTATE_INT32_V(_f, _s, _v)                                   \
458     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t)
459 #define VMSTATE_INT64_V(_f, _s, _v)                                   \
460     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t)
461 
462 #define VMSTATE_UINT8_V(_f, _s, _v)                                   \
463     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t)
464 #define VMSTATE_UINT16_V(_f, _s, _v)                                  \
465     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t)
466 #define VMSTATE_UINT32_V(_f, _s, _v)                                  \
467     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t)
468 #define VMSTATE_UINT64_V(_f, _s, _v)                                  \
469     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t)
470 
471 #define VMSTATE_BOOL(_f, _s)                                          \
472     VMSTATE_BOOL_V(_f, _s, 0)
473 
474 #define VMSTATE_INT8(_f, _s)                                          \
475     VMSTATE_INT8_V(_f, _s, 0)
476 #define VMSTATE_INT16(_f, _s)                                         \
477     VMSTATE_INT16_V(_f, _s, 0)
478 #define VMSTATE_INT32(_f, _s)                                         \
479     VMSTATE_INT32_V(_f, _s, 0)
480 #define VMSTATE_INT64(_f, _s)                                         \
481     VMSTATE_INT64_V(_f, _s, 0)
482 
483 #define VMSTATE_UINT8(_f, _s)                                         \
484     VMSTATE_UINT8_V(_f, _s, 0)
485 #define VMSTATE_UINT16(_f, _s)                                        \
486     VMSTATE_UINT16_V(_f, _s, 0)
487 #define VMSTATE_UINT32(_f, _s)                                        \
488     VMSTATE_UINT32_V(_f, _s, 0)
489 #define VMSTATE_UINT64(_f, _s)                                        \
490     VMSTATE_UINT64_V(_f, _s, 0)
491 
492 #define VMSTATE_UINT8_EQUAL(_f, _s)                                   \
493     VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t)
494 
495 #define VMSTATE_UINT16_EQUAL(_f, _s)                                  \
496     VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint16_equal, uint16_t)
497 
498 #define VMSTATE_UINT16_EQUAL_V(_f, _s, _v)                            \
499     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16_equal, uint16_t)
500 
501 #define VMSTATE_INT32_EQUAL(_f, _s)                                   \
502     VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t)
503 
504 #define VMSTATE_UINT32_EQUAL(_f, _s)                                   \
505     VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint32_equal, uint32_t)
506 
507 #define VMSTATE_INT32_LE(_f, _s)                                   \
508     VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
509 
510 #define VMSTATE_UINT8_TEST(_f, _s, _t)                               \
511     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t)
512 
513 #define VMSTATE_UINT16_TEST(_f, _s, _t)                               \
514     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
515 
516 #define VMSTATE_UINT32_TEST(_f, _s, _t)                                  \
517     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)
518 
519 #define VMSTATE_TIMER_TEST(_f, _s, _test)                             \
520     VMSTATE_POINTER_TEST(_f, _s, _test, vmstate_info_timer, QEMUTimer *)
521 
522 #define VMSTATE_TIMER_V(_f, _s, _v)                                   \
523     VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *)
524 
525 #define VMSTATE_TIMER(_f, _s)                                         \
526     VMSTATE_TIMER_V(_f, _s, 0)
527 
528 #define VMSTATE_TIMER_ARRAY(_f, _s, _n)                              \
529     VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *)
530 
531 #define VMSTATE_BOOL_ARRAY_V(_f, _s, _n, _v)                         \
532     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_bool, bool)
533 
534 #define VMSTATE_BOOL_ARRAY(_f, _s, _n)                               \
535     VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0)
536 
537 #define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v)                         \
538     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t)
539 
540 #define VMSTATE_UINT16_ARRAY(_f, _s, _n)                               \
541     VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0)
542 
543 #define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v)                         \
544     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t)
545 
546 #define VMSTATE_UINT8_ARRAY(_f, _s, _n)                               \
547     VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0)
548 
549 #define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)                        \
550     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t)
551 
552 #define VMSTATE_UINT32_ARRAY(_f, _s, _n)                              \
553     VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
554 
555 #define VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)                        \
556     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint64, uint64_t)
557 
558 #define VMSTATE_UINT64_ARRAY(_f, _s, _n)                              \
559     VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0)
560 
561 #define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v)                         \
562     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t)
563 
564 #define VMSTATE_INT16_ARRAY(_f, _s, _n)                               \
565     VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0)
566 
567 #define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v)                         \
568     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t)
569 
570 #define VMSTATE_INT32_ARRAY(_f, _s, _n)                               \
571     VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0)
572 
573 #define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num)                \
574     VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t)
575 
576 #define VMSTATE_UINT32_ARRAY(_f, _s, _n)                              \
577     VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
578 
579 #define VMSTATE_INT64_ARRAY_V(_f, _s, _n, _v)                         \
580     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int64, int64_t)
581 
582 #define VMSTATE_INT64_ARRAY(_f, _s, _n)                               \
583     VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0)
584 
585 #define VMSTATE_BUFFER_V(_f, _s, _v)                                  \
586     VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f)))
587 
588 #define VMSTATE_BUFFER(_f, _s)                                        \
589     VMSTATE_BUFFER_V(_f, _s, 0)
590 
591 #define VMSTATE_PARTIAL_BUFFER(_f, _s, _size)                         \
592     VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, _size)
593 
594 #define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \
595     VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, _start, sizeof(typeof_field(_s, _f)))
596 
597 #define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size)                        \
598     VMSTATE_VBUFFER(_f, _s, 0, NULL, 0, _size)
599 
600 #define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size)                        \
601     VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, 0, _size)
602 
603 #define VMSTATE_SUB_VBUFFER(_f, _s, _start, _size)                    \
604     VMSTATE_VBUFFER(_f, _s, 0, NULL, _start, _size)
605 
606 #define VMSTATE_BUFFER_TEST(_f, _s, _test)                            \
607     VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f)))
608 
609 #define VMSTATE_BUFFER_UNSAFE(_field, _state, _version, _size)        \
610     VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, _size)
611 
612 #define VMSTATE_UNUSED_V(_v, _size)                                   \
613     VMSTATE_UNUSED_BUFFER(NULL, _v, _size)
614 
615 #define VMSTATE_UNUSED(_size)                                         \
616     VMSTATE_UNUSED_V(0, _size)
617 
618 #define VMSTATE_UNUSED_TEST(_test, _size)                             \
619     VMSTATE_UNUSED_BUFFER(_test, 0, _size)
620 
621 #define VMSTATE_END_OF_LIST()                                         \
622     {}
623 
624 int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
625                        void *opaque, int version_id);
626 void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
627                         void *opaque);
628 int vmstate_register(DeviceState *dev, int instance_id,
629                      const VMStateDescription *vmsd, void *base);
630 int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
631                                    const VMStateDescription *vmsd,
632                                    void *base, int alias_id,
633                                    int required_for_version);
634 void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd,
635                         void *opaque);
636 
637 struct MemoryRegion;
638 void vmstate_register_ram(struct MemoryRegion *memory, DeviceState *dev);
639 void vmstate_unregister_ram(struct MemoryRegion *memory, DeviceState *dev);
640 void vmstate_register_ram_global(struct MemoryRegion *memory);
641 
642 #endif
643