xref: /openbmc/qemu/include/migration/vmstate.h (revision 14a650ec)
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 #ifndef CONFIG_USER_ONLY
30 #include <migration/qemu-file.h>
31 #endif
32 
33 typedef void SaveStateHandler(QEMUFile *f, void *opaque);
34 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
35 
36 typedef struct SaveVMHandlers {
37     /* This runs inside the iothread lock.  */
38     void (*set_params)(const MigrationParams *params, void * opaque);
39     SaveStateHandler *save_state;
40 
41     void (*cancel)(void *opaque);
42     int (*save_live_complete)(QEMUFile *f, void *opaque);
43 
44     /* This runs both outside and inside the iothread lock.  */
45     bool (*is_active)(void *opaque);
46 
47     /* This runs outside the iothread lock in the migration case, and
48      * within the lock in the savevm case.  The callback had better only
49      * use data that is local to the migration thread or protected
50      * by other locks.
51      */
52     int (*save_live_iterate)(QEMUFile *f, void *opaque);
53 
54     /* This runs outside the iothread lock!  */
55     int (*save_live_setup)(QEMUFile *f, void *opaque);
56     uint64_t (*save_live_pending)(QEMUFile *f, void *opaque, uint64_t max_size);
57 
58     LoadStateHandler *load_state;
59 } SaveVMHandlers;
60 
61 int register_savevm(DeviceState *dev,
62                     const char *idstr,
63                     int instance_id,
64                     int version_id,
65                     SaveStateHandler *save_state,
66                     LoadStateHandler *load_state,
67                     void *opaque);
68 
69 int register_savevm_live(DeviceState *dev,
70                          const char *idstr,
71                          int instance_id,
72                          int version_id,
73                          SaveVMHandlers *ops,
74                          void *opaque);
75 
76 void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque);
77 void register_device_unmigratable(DeviceState *dev, const char *idstr,
78                                                                 void *opaque);
79 
80 
81 typedef struct VMStateInfo VMStateInfo;
82 typedef struct VMStateDescription VMStateDescription;
83 
84 struct VMStateInfo {
85     const char *name;
86     int (*get)(QEMUFile *f, void *pv, size_t size);
87     void (*put)(QEMUFile *f, void *pv, size_t size);
88 };
89 
90 enum VMStateFlags {
91     VMS_SINGLE           = 0x001,
92     VMS_POINTER          = 0x002,
93     VMS_ARRAY            = 0x004,
94     VMS_STRUCT           = 0x008,
95     VMS_VARRAY_INT32     = 0x010,  /* Array with size in int32_t field*/
96     VMS_BUFFER           = 0x020,  /* static sized buffer */
97     VMS_ARRAY_OF_POINTER = 0x040,
98     VMS_VARRAY_UINT16    = 0x080,  /* Array with size in uint16_t field */
99     VMS_VBUFFER          = 0x100,  /* Buffer with size in int32_t field */
100     VMS_MULTIPLY         = 0x200,  /* multiply "size" field by field_size */
101     VMS_VARRAY_UINT8     = 0x400,  /* Array with size in uint8_t field*/
102     VMS_VARRAY_UINT32    = 0x800,  /* Array with size in uint32_t field*/
103 };
104 
105 typedef struct {
106     const char *name;
107     size_t offset;
108     size_t size;
109     size_t start;
110     int num;
111     size_t num_offset;
112     size_t size_offset;
113     const VMStateInfo *info;
114     enum VMStateFlags flags;
115     const VMStateDescription *vmsd;
116     int version_id;
117     bool (*field_exists)(void *opaque, int version_id);
118 } VMStateField;
119 
120 typedef struct VMStateSubsection {
121     const VMStateDescription *vmsd;
122     bool (*needed)(void *opaque);
123 } VMStateSubsection;
124 
125 struct VMStateDescription {
126     const char *name;
127     int unmigratable;
128     int version_id;
129     int minimum_version_id;
130     int minimum_version_id_old;
131     LoadStateHandler *load_state_old;
132     int (*pre_load)(void *opaque);
133     int (*post_load)(void *opaque, int version_id);
134     void (*pre_save)(void *opaque);
135     VMStateField *fields;
136     const VMStateSubsection *subsections;
137 };
138 
139 #ifdef CONFIG_USER_ONLY
140 extern const VMStateDescription vmstate_dummy;
141 #endif
142 
143 extern const VMStateInfo vmstate_info_bool;
144 
145 extern const VMStateInfo vmstate_info_int8;
146 extern const VMStateInfo vmstate_info_int16;
147 extern const VMStateInfo vmstate_info_int32;
148 extern const VMStateInfo vmstate_info_int64;
149 
150 extern const VMStateInfo vmstate_info_uint8_equal;
151 extern const VMStateInfo vmstate_info_uint16_equal;
152 extern const VMStateInfo vmstate_info_int32_equal;
153 extern const VMStateInfo vmstate_info_uint32_equal;
154 extern const VMStateInfo vmstate_info_uint64_equal;
155 extern const VMStateInfo vmstate_info_int32_le;
156 
157 extern const VMStateInfo vmstate_info_uint8;
158 extern const VMStateInfo vmstate_info_uint16;
159 extern const VMStateInfo vmstate_info_uint32;
160 extern const VMStateInfo vmstate_info_uint64;
161 
162 extern const VMStateInfo vmstate_info_float64;
163 
164 extern const VMStateInfo vmstate_info_timer;
165 extern const VMStateInfo vmstate_info_buffer;
166 extern const VMStateInfo vmstate_info_unused_buffer;
167 extern const VMStateInfo vmstate_info_bitmap;
168 
169 #define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0)
170 #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
171 #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
172 
173 #define vmstate_offset_value(_state, _field, _type)                  \
174     (offsetof(_state, _field) +                                      \
175      type_check(_type, typeof_field(_state, _field)))
176 
177 #define vmstate_offset_pointer(_state, _field, _type)                \
178     (offsetof(_state, _field) +                                      \
179      type_check_pointer(_type, typeof_field(_state, _field)))
180 
181 #define vmstate_offset_array(_state, _field, _type, _num)            \
182     (offsetof(_state, _field) +                                      \
183      type_check_array(_type, typeof_field(_state, _field), _num))
184 
185 #define vmstate_offset_2darray(_state, _field, _type, _n1, _n2)      \
186     (offsetof(_state, _field) +                                      \
187      type_check_2darray(_type, typeof_field(_state, _field), _n1, _n2))
188 
189 #define vmstate_offset_sub_array(_state, _field, _type, _start)      \
190     (offsetof(_state, _field[_start]))
191 
192 #define vmstate_offset_buffer(_state, _field)                        \
193     vmstate_offset_array(_state, _field, uint8_t,                    \
194                          sizeof(typeof_field(_state, _field)))
195 
196 #define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \
197     .name         = (stringify(_field)),                             \
198     .version_id   = (_version),                                      \
199     .field_exists = (_test),                                         \
200     .size         = sizeof(_type),                                   \
201     .info         = &(_info),                                        \
202     .flags        = VMS_SINGLE,                                      \
203     .offset       = vmstate_offset_value(_state, _field, _type),     \
204 }
205 
206 #define VMSTATE_POINTER(_field, _state, _version, _info, _type) {    \
207     .name       = (stringify(_field)),                               \
208     .version_id = (_version),                                        \
209     .info       = &(_info),                                          \
210     .size       = sizeof(_type),                                     \
211     .flags      = VMS_SINGLE|VMS_POINTER,                            \
212     .offset     = vmstate_offset_value(_state, _field, _type),       \
213 }
214 
215 #define VMSTATE_POINTER_TEST(_field, _state, _test, _info, _type) {  \
216     .name       = (stringify(_field)),                               \
217     .info       = &(_info),                                          \
218     .field_exists = (_test),                                         \
219     .size       = sizeof(_type),                                     \
220     .flags      = VMS_SINGLE|VMS_POINTER,                            \
221     .offset     = vmstate_offset_value(_state, _field, _type),       \
222 }
223 
224 #define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\
225     .name       = (stringify(_field)),                               \
226     .version_id = (_version),                                        \
227     .num        = (_num),                                            \
228     .info       = &(_info),                                          \
229     .size       = sizeof(_type),                                     \
230     .flags      = VMS_ARRAY,                                         \
231     .offset     = vmstate_offset_array(_state, _field, _type, _num), \
232 }
233 
234 #define VMSTATE_2DARRAY(_field, _state, _n1, _n2, _version, _info, _type) { \
235     .name       = (stringify(_field)),                                      \
236     .version_id = (_version),                                               \
237     .num        = (_n1) * (_n2),                                            \
238     .info       = &(_info),                                                 \
239     .size       = sizeof(_type),                                            \
240     .flags      = VMS_ARRAY,                                                \
241     .offset     = vmstate_offset_2darray(_state, _field, _type, _n1, _n2),  \
242 }
243 
244 #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
245     .name         = (stringify(_field)),                              \
246     .field_exists = (_test),                                          \
247     .num          = (_num),                                           \
248     .info         = &(_info),                                         \
249     .size         = sizeof(_type),                                    \
250     .flags        = VMS_ARRAY,                                        \
251     .offset       = vmstate_offset_array(_state, _field, _type, _num),\
252 }
253 
254 #define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \
255     .name       = (stringify(_field)),                               \
256     .version_id = (_version),                                        \
257     .num        = (_num),                                            \
258     .info       = &(_info),                                          \
259     .size       = sizeof(_type),                                     \
260     .flags      = VMS_ARRAY,                                         \
261     .offset     = vmstate_offset_sub_array(_state, _field, _type, _start), \
262 }
263 
264 #define VMSTATE_ARRAY_INT32_UNSAFE(_field, _state, _field_num, _info, _type) {\
265     .name       = (stringify(_field)),                               \
266     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
267     .info       = &(_info),                                          \
268     .size       = sizeof(_type),                                     \
269     .flags      = VMS_VARRAY_INT32,                                  \
270     .offset     = offsetof(_state, _field),                          \
271 }
272 
273 #define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\
274     .name       = (stringify(_field)),                               \
275     .version_id = (_version),                                        \
276     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
277     .info       = &(_info),                                          \
278     .size       = sizeof(_type),                                     \
279     .flags      = VMS_VARRAY_INT32|VMS_POINTER,                      \
280     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
281 }
282 
283 #define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info, _type) {\
284     .name       = (stringify(_field)),                               \
285     .version_id = (_version),                                        \
286     .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
287     .info       = &(_info),                                          \
288     .size       = sizeof(_type),                                     \
289     .flags      = VMS_VARRAY_UINT32|VMS_POINTER,                     \
290     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
291 }
292 
293 #define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version, _info, _type) {\
294     .name       = (stringify(_field)),                               \
295     .version_id = (_version),                                        \
296     .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
297     .info       = &(_info),                                          \
298     .size       = sizeof(_type),                                     \
299     .flags      = VMS_VARRAY_UINT16,                                 \
300     .offset     = offsetof(_state, _field),                          \
301 }
302 
303 #define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \
304     .name         = (stringify(_field)),                             \
305     .version_id   = (_version),                                      \
306     .field_exists = (_test),                                         \
307     .vmsd         = &(_vmsd),                                        \
308     .size         = sizeof(_type),                                   \
309     .flags        = VMS_STRUCT,                                      \
310     .offset       = vmstate_offset_value(_state, _field, _type),     \
311 }
312 
313 #define VMSTATE_STRUCT_POINTER_V(_field, _state, _version, _vmsd, _type) { \
314     .name         = (stringify(_field)),                             \
315     .version_id   = (_version),                                        \
316     .vmsd         = &(_vmsd),                                        \
317     .size         = sizeof(_type),                                   \
318     .flags        = VMS_STRUCT|VMS_POINTER,                          \
319     .offset       = vmstate_offset_value(_state, _field, _type),     \
320 }
321 
322 #define VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, _version, _vmsd, _type) { \
323     .name         = (stringify(_field)),                             \
324     .version_id   = (_version),                                        \
325     .field_exists = (_test),                                         \
326     .vmsd         = &(_vmsd),                                        \
327     .size         = sizeof(_type),                                   \
328     .flags        = VMS_STRUCT|VMS_POINTER,                          \
329     .offset       = vmstate_offset_value(_state, _field, _type),     \
330 }
331 
332 #define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) {\
333     .name       = (stringify(_field)),                               \
334     .version_id = (_version),                                        \
335     .num        = (_num),                                            \
336     .info       = &(_info),                                          \
337     .size       = sizeof(_type),                                     \
338     .flags      = VMS_ARRAY|VMS_ARRAY_OF_POINTER,                    \
339     .offset     = vmstate_offset_array(_state, _field, _type, _num), \
340 }
341 
342 #define VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, _test, _version, _vmsd, _type) { \
343     .name         = (stringify(_field)),                             \
344     .num          = (_num),                                          \
345     .field_exists = (_test),                                         \
346     .version_id   = (_version),                                      \
347     .vmsd         = &(_vmsd),                                        \
348     .size         = sizeof(_type),                                   \
349     .flags        = VMS_STRUCT|VMS_ARRAY,                            \
350     .offset       = vmstate_offset_array(_state, _field, _type, _num),\
351 }
352 
353 #define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, _vmsd, _type) { \
354     .name       = (stringify(_field)),                               \
355     .num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \
356     .version_id = (_version),                                        \
357     .vmsd       = &(_vmsd),                                          \
358     .size       = sizeof(_type),                                     \
359     .flags      = VMS_STRUCT|VMS_VARRAY_UINT8,                       \
360     .offset     = offsetof(_state, _field),                          \
361 }
362 
363 #define VMSTATE_STRUCT_VARRAY_POINTER_INT32(_field, _state, _field_num, _vmsd, _type) { \
364     .name       = (stringify(_field)),                               \
365     .version_id = 0,                                                 \
366     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
367     .size       = sizeof(_type),                                     \
368     .vmsd       = &(_vmsd),                                          \
369     .flags      = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT,       \
370     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
371 }
372 
373 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT32(_field, _state, _field_num, _vmsd, _type) { \
374     .name       = (stringify(_field)),                               \
375     .version_id = 0,                                                 \
376     .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
377     .size       = sizeof(_type),                                     \
378     .vmsd       = &(_vmsd),                                          \
379     .flags      = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT,       \
380     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
381 }
382 
383 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, _vmsd, _type) { \
384     .name       = (stringify(_field)),                               \
385     .version_id = 0,                                                 \
386     .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
387     .size       = sizeof(_type),                                     \
388     .vmsd       = &(_vmsd),                                          \
389     .flags      = VMS_POINTER | VMS_VARRAY_UINT16 | VMS_STRUCT,      \
390     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
391 }
392 
393 #define VMSTATE_STRUCT_VARRAY_INT32(_field, _state, _field_num, _version, _vmsd, _type) { \
394     .name       = (stringify(_field)),                               \
395     .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
396     .version_id = (_version),                                        \
397     .vmsd       = &(_vmsd),                                          \
398     .size       = sizeof(_type),                                     \
399     .flags      = VMS_STRUCT|VMS_VARRAY_INT32,                       \
400     .offset     = offsetof(_state, _field),                          \
401 }
402 
403 #define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version, _vmsd, _type) { \
404     .name       = (stringify(_field)),                               \
405     .num_offset = vmstate_offset_value(_state, _field_num, uint32_t), \
406     .version_id = (_version),                                        \
407     .vmsd       = &(_vmsd),                                          \
408     .size       = sizeof(_type),                                     \
409     .flags      = VMS_STRUCT|VMS_VARRAY_UINT32,                      \
410     .offset     = offsetof(_state, _field),                          \
411 }
412 
413 #define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \
414     .name         = (stringify(_field)),                             \
415     .version_id   = (_version),                                      \
416     .field_exists = (_test),                                         \
417     .size         = (_size - _start),                                \
418     .info         = &vmstate_info_buffer,                            \
419     .flags        = VMS_BUFFER,                                      \
420     .offset       = vmstate_offset_buffer(_state, _field) + _start,  \
421 }
422 
423 #define VMSTATE_VBUFFER_MULTIPLY(_field, _state, _version, _test, _start, _field_size, _multiply) { \
424     .name         = (stringify(_field)),                             \
425     .version_id   = (_version),                                      \
426     .field_exists = (_test),                                         \
427     .size_offset  = vmstate_offset_value(_state, _field_size, uint32_t),\
428     .size         = (_multiply),                                      \
429     .info         = &vmstate_info_buffer,                            \
430     .flags        = VMS_VBUFFER|VMS_POINTER|VMS_MULTIPLY,            \
431     .offset       = offsetof(_state, _field),                        \
432     .start        = (_start),                                        \
433 }
434 
435 #define VMSTATE_VBUFFER(_field, _state, _version, _test, _start, _field_size) { \
436     .name         = (stringify(_field)),                             \
437     .version_id   = (_version),                                      \
438     .field_exists = (_test),                                         \
439     .size_offset  = vmstate_offset_value(_state, _field_size, int32_t),\
440     .info         = &vmstate_info_buffer,                            \
441     .flags        = VMS_VBUFFER|VMS_POINTER,                         \
442     .offset       = offsetof(_state, _field),                        \
443     .start        = (_start),                                        \
444 }
445 
446 #define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _start, _field_size) { \
447     .name         = (stringify(_field)),                             \
448     .version_id   = (_version),                                      \
449     .field_exists = (_test),                                         \
450     .size_offset  = vmstate_offset_value(_state, _field_size, uint32_t),\
451     .info         = &vmstate_info_buffer,                            \
452     .flags        = VMS_VBUFFER|VMS_POINTER,                         \
453     .offset       = offsetof(_state, _field),                        \
454     .start        = (_start),                                        \
455 }
456 
457 #define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) { \
458     .name       = (stringify(_field)),                               \
459     .version_id = (_version),                                        \
460     .size       = (_size),                                           \
461     .info       = &(_info),                                          \
462     .flags      = VMS_BUFFER,                                        \
463     .offset     = offsetof(_state, _field),                          \
464 }
465 
466 #define VMSTATE_BUFFER_POINTER_UNSAFE(_field, _state, _version, _size) { \
467     .name       = (stringify(_field)),                               \
468     .version_id = (_version),                                        \
469     .size       = (_size),                                           \
470     .info       = &vmstate_info_buffer,                              \
471     .flags      = VMS_BUFFER|VMS_POINTER,                            \
472     .offset     = offsetof(_state, _field),                          \
473 }
474 
475 #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) {              \
476     .name         = "unused",                                        \
477     .field_exists = (_test),                                         \
478     .version_id   = (_version),                                      \
479     .size         = (_size),                                         \
480     .info         = &vmstate_info_unused_buffer,                     \
481     .flags        = VMS_BUFFER,                                      \
482 }
483 
484 /* _field_size should be a int32_t field in the _state struct giving the
485  * size of the bitmap _field in bits.
486  */
487 #define VMSTATE_BITMAP(_field, _state, _version, _field_size) {      \
488     .name         = (stringify(_field)),                             \
489     .version_id   = (_version),                                      \
490     .size_offset  = vmstate_offset_value(_state, _field_size, int32_t),\
491     .info         = &vmstate_info_bitmap,                            \
492     .flags        = VMS_VBUFFER|VMS_POINTER,                         \
493     .offset       = offsetof(_state, _field),                        \
494 }
495 
496 /* _f : field name
497    _f_n : num of elements field_name
498    _n : num of elements
499    _s : struct state name
500    _v : version
501 */
502 
503 #define VMSTATE_SINGLE(_field, _state, _version, _info, _type)        \
504     VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type)
505 
506 #define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type)        \
507     VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type)
508 
509 #define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type)          \
510     VMSTATE_STRUCT_POINTER_V(_field, _state, 0, _vmsd, _type)
511 
512 #define VMSTATE_STRUCT_POINTER_TEST(_field, _state, _test, _vmsd, _type)     \
513     VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, 0, _vmsd, _type)
514 
515 #define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) \
516     VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version,   \
517             _vmsd, _type)
518 
519 #define VMSTATE_BOOL_V(_f, _s, _v)                                    \
520     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool)
521 
522 #define VMSTATE_INT8_V(_f, _s, _v)                                    \
523     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t)
524 #define VMSTATE_INT16_V(_f, _s, _v)                                   \
525     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t)
526 #define VMSTATE_INT32_V(_f, _s, _v)                                   \
527     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t)
528 #define VMSTATE_INT64_V(_f, _s, _v)                                   \
529     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t)
530 
531 #define VMSTATE_UINT8_V(_f, _s, _v)                                   \
532     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t)
533 #define VMSTATE_UINT16_V(_f, _s, _v)                                  \
534     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t)
535 #define VMSTATE_UINT32_V(_f, _s, _v)                                  \
536     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t)
537 #define VMSTATE_UINT64_V(_f, _s, _v)                                  \
538     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t)
539 
540 #define VMSTATE_BOOL(_f, _s)                                          \
541     VMSTATE_BOOL_V(_f, _s, 0)
542 
543 #define VMSTATE_INT8(_f, _s)                                          \
544     VMSTATE_INT8_V(_f, _s, 0)
545 #define VMSTATE_INT16(_f, _s)                                         \
546     VMSTATE_INT16_V(_f, _s, 0)
547 #define VMSTATE_INT32(_f, _s)                                         \
548     VMSTATE_INT32_V(_f, _s, 0)
549 #define VMSTATE_INT64(_f, _s)                                         \
550     VMSTATE_INT64_V(_f, _s, 0)
551 
552 #define VMSTATE_UINT8(_f, _s)                                         \
553     VMSTATE_UINT8_V(_f, _s, 0)
554 #define VMSTATE_UINT16(_f, _s)                                        \
555     VMSTATE_UINT16_V(_f, _s, 0)
556 #define VMSTATE_UINT32(_f, _s)                                        \
557     VMSTATE_UINT32_V(_f, _s, 0)
558 #define VMSTATE_UINT64(_f, _s)                                        \
559     VMSTATE_UINT64_V(_f, _s, 0)
560 
561 #define VMSTATE_UINT8_EQUAL(_f, _s)                                   \
562     VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t)
563 
564 #define VMSTATE_UINT16_EQUAL(_f, _s)                                  \
565     VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint16_equal, uint16_t)
566 
567 #define VMSTATE_UINT16_EQUAL_V(_f, _s, _v)                            \
568     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16_equal, uint16_t)
569 
570 #define VMSTATE_INT32_EQUAL(_f, _s)                                   \
571     VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t)
572 
573 #define VMSTATE_UINT32_EQUAL_V(_f, _s, _v)                            \
574     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32_equal, uint32_t)
575 
576 #define VMSTATE_UINT32_EQUAL(_f, _s)                                  \
577     VMSTATE_UINT32_EQUAL_V(_f, _s, 0)
578 
579 #define VMSTATE_UINT64_EQUAL_V(_f, _s, _v)                            \
580     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64_equal, uint64_t)
581 
582 #define VMSTATE_UINT64_EQUAL(_f, _s)                                  \
583     VMSTATE_UINT64_EQUAL_V(_f, _s, 0)
584 
585 #define VMSTATE_INT32_LE(_f, _s)                                   \
586     VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
587 
588 #define VMSTATE_UINT8_TEST(_f, _s, _t)                               \
589     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t)
590 
591 #define VMSTATE_UINT16_TEST(_f, _s, _t)                               \
592     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
593 
594 #define VMSTATE_UINT32_TEST(_f, _s, _t)                                  \
595     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)
596 
597 
598 #define VMSTATE_FLOAT64_V(_f, _s, _v)                                 \
599     VMSTATE_SINGLE(_f, _s, _v, vmstate_info_float64, float64)
600 
601 #define VMSTATE_FLOAT64(_f, _s)                                       \
602     VMSTATE_FLOAT64_V(_f, _s, 0)
603 
604 #define VMSTATE_TIMER_TEST(_f, _s, _test)                             \
605     VMSTATE_POINTER_TEST(_f, _s, _test, vmstate_info_timer, QEMUTimer *)
606 
607 #define VMSTATE_TIMER_V(_f, _s, _v)                                   \
608     VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *)
609 
610 #define VMSTATE_TIMER(_f, _s)                                         \
611     VMSTATE_TIMER_V(_f, _s, 0)
612 
613 #define VMSTATE_TIMER_ARRAY(_f, _s, _n)                              \
614     VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *)
615 
616 #define VMSTATE_BOOL_ARRAY_V(_f, _s, _n, _v)                         \
617     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_bool, bool)
618 
619 #define VMSTATE_BOOL_ARRAY(_f, _s, _n)                               \
620     VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0)
621 
622 #define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v)                         \
623     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t)
624 
625 #define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v)                \
626     VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t)
627 
628 #define VMSTATE_UINT16_ARRAY(_f, _s, _n)                               \
629     VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0)
630 
631 #define VMSTATE_UINT16_2DARRAY(_f, _s, _n1, _n2)                      \
632     VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, 0)
633 
634 #define VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, _v)                 \
635     VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint8, uint8_t)
636 
637 #define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v)                         \
638     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t)
639 
640 #define VMSTATE_UINT8_ARRAY(_f, _s, _n)                               \
641     VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0)
642 
643 #define VMSTATE_UINT8_2DARRAY(_f, _s, _n1, _n2)                       \
644     VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, 0)
645 
646 #define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)                        \
647     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t)
648 
649 #define VMSTATE_UINT32_ARRAY(_f, _s, _n)                              \
650     VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
651 
652 #define VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)                        \
653     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint64, uint64_t)
654 
655 #define VMSTATE_UINT64_ARRAY(_f, _s, _n)                              \
656     VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0)
657 
658 #define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v)                         \
659     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t)
660 
661 #define VMSTATE_INT16_ARRAY(_f, _s, _n)                               \
662     VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0)
663 
664 #define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v)                         \
665     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t)
666 
667 #define VMSTATE_INT32_ARRAY(_f, _s, _n)                               \
668     VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0)
669 
670 #define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num)                \
671     VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t)
672 
673 #define VMSTATE_UINT32_ARRAY(_f, _s, _n)                              \
674     VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
675 
676 #define VMSTATE_INT64_ARRAY_V(_f, _s, _n, _v)                         \
677     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int64, int64_t)
678 
679 #define VMSTATE_INT64_ARRAY(_f, _s, _n)                               \
680     VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0)
681 
682 #define VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, _v)                       \
683     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_float64, float64)
684 
685 #define VMSTATE_FLOAT64_ARRAY(_f, _s, _n)                             \
686     VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, 0)
687 
688 #define VMSTATE_BUFFER_V(_f, _s, _v)                                  \
689     VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f)))
690 
691 #define VMSTATE_BUFFER(_f, _s)                                        \
692     VMSTATE_BUFFER_V(_f, _s, 0)
693 
694 #define VMSTATE_PARTIAL_BUFFER(_f, _s, _size)                         \
695     VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, _size)
696 
697 #define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \
698     VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, _start, sizeof(typeof_field(_s, _f)))
699 
700 #define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size)                        \
701     VMSTATE_VBUFFER(_f, _s, 0, NULL, 0, _size)
702 
703 #define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size)                        \
704     VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, 0, _size)
705 
706 #define VMSTATE_SUB_VBUFFER(_f, _s, _start, _size)                    \
707     VMSTATE_VBUFFER(_f, _s, 0, NULL, _start, _size)
708 
709 #define VMSTATE_BUFFER_TEST(_f, _s, _test)                            \
710     VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f)))
711 
712 #define VMSTATE_BUFFER_UNSAFE(_field, _state, _version, _size)        \
713     VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, _size)
714 
715 #define VMSTATE_UNUSED_V(_v, _size)                                   \
716     VMSTATE_UNUSED_BUFFER(NULL, _v, _size)
717 
718 #define VMSTATE_UNUSED(_size)                                         \
719     VMSTATE_UNUSED_V(0, _size)
720 
721 #define VMSTATE_UNUSED_TEST(_test, _size)                             \
722     VMSTATE_UNUSED_BUFFER(_test, 0, _size)
723 
724 #define VMSTATE_END_OF_LIST()                                         \
725     {}
726 
727 int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
728                        void *opaque, int version_id);
729 void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
730                         void *opaque);
731 
732 int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
733                                    const VMStateDescription *vmsd,
734                                    void *base, int alias_id,
735                                    int required_for_version);
736 
737 static inline int vmstate_register(DeviceState *dev, int instance_id,
738                                    const VMStateDescription *vmsd,
739                                    void *opaque)
740 {
741     return vmstate_register_with_alias_id(dev, instance_id, vmsd,
742                                           opaque, -1, 0);
743 }
744 
745 void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd,
746                         void *opaque);
747 
748 struct MemoryRegion;
749 void vmstate_register_ram(struct MemoryRegion *memory, DeviceState *dev);
750 void vmstate_unregister_ram(struct MemoryRegion *memory, DeviceState *dev);
751 void vmstate_register_ram_global(struct MemoryRegion *memory);
752 
753 #endif
754