blob: 85e43da56868bc62b720b9e6a88f284603096887 [file] [log] [blame]
Paolo Bonzini701a8f72012-01-13 17:07:20 +01001/*
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 */
Markus Armbruster175de522016-06-29 15:29:06 +020026
Paolo Bonzini701a8f72012-01-13 17:07:20 +010027#ifndef QEMU_VMSTATE_H
Markus Armbruster175de522016-06-29 15:29:06 +020028#define QEMU_VMSTATE_H
Paolo Bonzini701a8f72012-01-13 17:07:20 +010029
Markus Armbruster17b74b92016-05-04 18:49:17 +020030#include "migration/qjson.h"
Paolo Bonzinifd7f0d62013-02-04 10:57:50 +010031
Paolo Bonzini701a8f72012-01-13 17:07:20 +010032typedef struct VMStateInfo VMStateInfo;
33typedef struct VMStateDescription VMStateDescription;
Jianjun Duan2c21ee72017-01-19 11:00:50 -080034typedef struct VMStateField VMStateField;
Paolo Bonzini701a8f72012-01-13 17:07:20 +010035
Jianjun Duan2c21ee72017-01-19 11:00:50 -080036/* VMStateInfo allows customized migration of objects that don't fit in
37 * any category in VMStateFlags. Additional information is always passed
38 * into get and put in terms of field and vmdesc parameters. However
39 * these two parameters should only be used in cases when customized
40 * handling is needed, such as QTAILQ. For primitive data types such as
41 * integer, field and vmdesc parameters should be ignored inside get/put.
42 */
Paolo Bonzini701a8f72012-01-13 17:07:20 +010043struct VMStateInfo {
44 const char *name;
Jianjun Duan2c21ee72017-01-19 11:00:50 -080045 int (*get)(QEMUFile *f, void *pv, size_t size, VMStateField *field);
46 int (*put)(QEMUFile *f, void *pv, size_t size, VMStateField *field,
47 QJSON *vmdesc);
Paolo Bonzini701a8f72012-01-13 17:07:20 +010048};
49
50enum VMStateFlags {
Sascha Silbe8da5ef52016-02-26 09:18:13 +010051 /* Ignored */
Paolo Bonzini701a8f72012-01-13 17:07:20 +010052 VMS_SINGLE = 0x001,
Sascha Silbe8da5ef52016-02-26 09:18:13 +010053
54 /* The struct member at opaque + VMStateField.offset is a pointer
55 * to the actual field (e.g. struct a { uint8_t *b;
56 * }). Dereference the pointer before using it as basis for
57 * further pointer arithmetic (see e.g. VMS_ARRAY). Does not
58 * affect the meaning of VMStateField.num_offset or
59 * VMStateField.size_offset; see VMS_VARRAY* and VMS_VBUFFER for
60 * those. */
Paolo Bonzini701a8f72012-01-13 17:07:20 +010061 VMS_POINTER = 0x002,
Sascha Silbe8da5ef52016-02-26 09:18:13 +010062
63 /* The field is an array of fixed size. VMStateField.num contains
64 * the number of entries in the array. The size of each entry is
65 * given by VMStateField.size and / or opaque +
66 * VMStateField.size_offset; see VMS_VBUFFER and
67 * VMS_MULTIPLY. Each array entry will be processed individually
68 * (VMStateField.info.get()/put() if VMS_STRUCT is not set,
69 * recursion into VMStateField.vmsd if VMS_STRUCT is set). May not
70 * be combined with VMS_VARRAY*. */
Paolo Bonzini701a8f72012-01-13 17:07:20 +010071 VMS_ARRAY = 0x004,
Sascha Silbe8da5ef52016-02-26 09:18:13 +010072
73 /* The field is itself a struct, containing one or more
74 * fields. Recurse into VMStateField.vmsd. Most useful in
75 * combination with VMS_ARRAY / VMS_VARRAY*, recursing into each
76 * array entry. */
Paolo Bonzini701a8f72012-01-13 17:07:20 +010077 VMS_STRUCT = 0x008,
Sascha Silbe8da5ef52016-02-26 09:18:13 +010078
79 /* The field is an array of variable size. The int32_t at opaque +
80 * VMStateField.num_offset contains the number of entries in the
81 * array. See the VMS_ARRAY description regarding array handling
82 * in general. May not be combined with VMS_ARRAY or any other
83 * VMS_VARRAY*. */
84 VMS_VARRAY_INT32 = 0x010,
85
86 /* Ignored */
87 VMS_BUFFER = 0x020,
88
89 /* The field is a (fixed-size or variable-size) array of pointers
90 * (e.g. struct a { uint8_t *b[]; }). Dereference each array entry
91 * before using it. Note: Does not imply any one of VMS_ARRAY /
92 * VMS_VARRAY*; these need to be set explicitly. */
Paolo Bonzini701a8f72012-01-13 17:07:20 +010093 VMS_ARRAY_OF_POINTER = 0x040,
Sascha Silbe8da5ef52016-02-26 09:18:13 +010094
95 /* The field is an array of variable size. The uint16_t at opaque
96 * + VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS)
97 * contains the number of entries in the array. See the VMS_ARRAY
98 * description regarding array handling in general. May not be
99 * combined with VMS_ARRAY or any other VMS_VARRAY*. */
100 VMS_VARRAY_UINT16 = 0x080,
101
102 /* The size of the individual entries (a single array entry if
103 * VMS_ARRAY or any of VMS_VARRAY* are set, or the field itself if
104 * neither is set) is variable (i.e. not known at compile-time),
105 * but the same for all entries. Use the int32_t at opaque +
106 * VMStateField.size_offset (subject to VMS_MULTIPLY) to determine
107 * the size of each (and every) entry. */
108 VMS_VBUFFER = 0x100,
109
110 /* Multiply the entry size given by the int32_t at opaque +
111 * VMStateField.size_offset (see VMS_VBUFFER description) with
112 * VMStateField.size to determine the number of bytes to be
113 * allocated. Only valid in combination with VMS_VBUFFER. */
114 VMS_MULTIPLY = 0x200,
115
116 /* The field is an array of variable size. The uint8_t at opaque +
117 * VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS)
118 * contains the number of entries in the array. See the VMS_ARRAY
119 * description regarding array handling in general. May not be
120 * combined with VMS_ARRAY or any other VMS_VARRAY*. */
121 VMS_VARRAY_UINT8 = 0x400,
122
123 /* The field is an array of variable size. The uint32_t at opaque
124 * + VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS)
125 * contains the number of entries in the array. See the VMS_ARRAY
126 * description regarding array handling in general. May not be
127 * combined with VMS_ARRAY or any other VMS_VARRAY*. */
128 VMS_VARRAY_UINT32 = 0x800,
129
130 /* Fail loading the serialised VM state if this field is missing
131 * from the input. */
132 VMS_MUST_EXIST = 0x1000,
133
134 /* When loading serialised VM state, allocate memory for the
135 * (entire) field. Only valid in combination with
136 * VMS_POINTER. Note: Not all combinations with other flags are
137 * currently supported, e.g. VMS_ALLOC|VMS_ARRAY_OF_POINTER won't
138 * cause the individual entries to be allocated. */
139 VMS_ALLOC = 0x2000,
140
141 /* Multiply the number of entries given by the integer at opaque +
142 * VMStateField.num_offset (see VMS_VARRAY*) with VMStateField.num
143 * to determine the number of entries in the array. Only valid in
144 * combination with one of VMS_VARRAY*. */
145 VMS_MULTIPLY_ELEMENTS = 0x4000,
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100146};
147
Peter Xuf37bc032017-01-06 12:06:12 +0800148typedef enum {
149 MIG_PRI_DEFAULT = 0,
Peter Xu8cdcf3c2017-01-06 12:06:13 +0800150 MIG_PRI_IOMMU, /* Must happen before PCI devices */
Eric Auger252a7a62017-06-13 14:57:01 +0100151 MIG_PRI_GICV3_ITS, /* Must happen before PCI devices */
152 MIG_PRI_GICV3, /* Must happen before the ITS */
Peter Xuf37bc032017-01-06 12:06:12 +0800153 MIG_PRI_MAX,
154} MigrationPriority;
155
Jianjun Duan2c21ee72017-01-19 11:00:50 -0800156struct VMStateField {
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100157 const char *name;
Halil Pasicd2164ad2017-06-23 16:48:23 +0200158 const char *err_hint;
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100159 size_t offset;
160 size_t size;
161 size_t start;
162 int num;
163 size_t num_offset;
164 size_t size_offset;
165 const VMStateInfo *info;
166 enum VMStateFlags flags;
167 const VMStateDescription *vmsd;
168 int version_id;
169 bool (*field_exists)(void *opaque, int version_id);
Jianjun Duan2c21ee72017-01-19 11:00:50 -0800170};
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100171
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100172struct VMStateDescription {
173 const char *name;
174 int unmigratable;
175 int version_id;
176 int minimum_version_id;
177 int minimum_version_id_old;
Peter Xuf37bc032017-01-06 12:06:12 +0800178 MigrationPriority priority;
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100179 LoadStateHandler *load_state_old;
180 int (*pre_load)(void *opaque);
181 int (*post_load)(void *opaque, int version_id);
182 void (*pre_save)(void *opaque);
Juan Quintela5cd8cad2014-09-23 14:09:54 +0200183 bool (*needed)(void *opaque);
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100184 VMStateField *fields;
Juan Quintela5cd8cad2014-09-23 14:09:54 +0200185 const VMStateDescription **subsections;
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100186};
187
Andreas Färberc71c3e92013-02-18 17:56:20 +0100188extern const VMStateDescription vmstate_dummy;
Andreas Färberc71c3e92013-02-18 17:56:20 +0100189
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100190extern const VMStateInfo vmstate_info_bool;
191
192extern const VMStateInfo vmstate_info_int8;
193extern const VMStateInfo vmstate_info_int16;
194extern const VMStateInfo vmstate_info_int32;
195extern const VMStateInfo vmstate_info_int64;
196
197extern const VMStateInfo vmstate_info_uint8_equal;
198extern const VMStateInfo vmstate_info_uint16_equal;
199extern const VMStateInfo vmstate_info_int32_equal;
200extern const VMStateInfo vmstate_info_uint32_equal;
David Gibsone344b8a2013-03-12 14:06:00 +1100201extern const VMStateInfo vmstate_info_uint64_equal;
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100202extern const VMStateInfo vmstate_info_int32_le;
203
204extern const VMStateInfo vmstate_info_uint8;
205extern const VMStateInfo vmstate_info_uint16;
206extern const VMStateInfo vmstate_info_uint32;
207extern const VMStateInfo vmstate_info_uint64;
208
Halil Pasic07d4e692017-02-22 17:01:17 +0100209/** Put this in the stream when migrating a null pointer.*/
210#define VMS_NULLPTR_MARKER (0x30U) /* '0' */
211extern const VMStateInfo vmstate_info_nullptr;
212
David Gibson213945e2013-03-12 14:06:02 +1100213extern const VMStateInfo vmstate_info_float64;
Juan Quintela55174742016-01-11 12:40:21 +0000214extern const VMStateInfo vmstate_info_cpudouble;
David Gibson213945e2013-03-12 14:06:02 +1100215
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100216extern const VMStateInfo vmstate_info_timer;
217extern const VMStateInfo vmstate_info_buffer;
218extern const VMStateInfo vmstate_info_unused_buffer;
Dr. David Alan Gilbertbcf45132017-02-03 16:06:49 +0000219extern const VMStateInfo vmstate_info_tmp;
Peter Maydell08e99e22012-10-30 07:45:12 +0000220extern const VMStateInfo vmstate_info_bitmap;
Jianjun Duan94869d52017-01-19 11:00:51 -0800221extern const VMStateInfo vmstate_info_qtailq;
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100222
Peter Maydellbd7f92e2013-04-05 16:17:59 +0100223#define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100224#define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
225#define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
226
227#define vmstate_offset_value(_state, _field, _type) \
228 (offsetof(_state, _field) + \
229 type_check(_type, typeof_field(_state, _field)))
230
231#define vmstate_offset_pointer(_state, _field, _type) \
232 (offsetof(_state, _field) + \
233 type_check_pointer(_type, typeof_field(_state, _field)))
234
235#define vmstate_offset_array(_state, _field, _type, _num) \
236 (offsetof(_state, _field) + \
237 type_check_array(_type, typeof_field(_state, _field), _num))
238
Peter Maydellbd7f92e2013-04-05 16:17:59 +0100239#define vmstate_offset_2darray(_state, _field, _type, _n1, _n2) \
240 (offsetof(_state, _field) + \
241 type_check_2darray(_type, typeof_field(_state, _field), _n1, _n2))
242
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100243#define vmstate_offset_sub_array(_state, _field, _type, _start) \
Paolo Bonziniea987c22015-01-07 15:12:13 +0100244 vmstate_offset_value(_state, _field[_start], _type)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100245
246#define vmstate_offset_buffer(_state, _field) \
247 vmstate_offset_array(_state, _field, uint8_t, \
248 sizeof(typeof_field(_state, _field)))
249
250#define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \
251 .name = (stringify(_field)), \
252 .version_id = (_version), \
253 .field_exists = (_test), \
254 .size = sizeof(_type), \
255 .info = &(_info), \
256 .flags = VMS_SINGLE, \
257 .offset = vmstate_offset_value(_state, _field, _type), \
258}
259
Halil Pasicd2164ad2017-06-23 16:48:23 +0200260#define VMSTATE_SINGLE_FULL(_field, _state, _test, _version, _info, \
261 _type, _err_hint) { \
262 .name = (stringify(_field)), \
263 .err_hint = (_err_hint), \
264 .version_id = (_version), \
265 .field_exists = (_test), \
266 .size = sizeof(_type), \
267 .info = &(_info), \
268 .flags = VMS_SINGLE, \
269 .offset = vmstate_offset_value(_state, _field, _type), \
270}
271
Michael S. Tsirkin4082f082014-04-03 19:50:35 +0300272/* Validate state using a boolean predicate. */
273#define VMSTATE_VALIDATE(_name, _test) { \
274 .name = (_name), \
275 .field_exists = (_test), \
276 .flags = VMS_ARRAY | VMS_MUST_EXIST, \
277 .num = 0, /* 0 elements: no data, only run _test */ \
278}
279
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100280#define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \
281 .name = (stringify(_field)), \
282 .version_id = (_version), \
283 .info = &(_info), \
284 .size = sizeof(_type), \
285 .flags = VMS_SINGLE|VMS_POINTER, \
286 .offset = vmstate_offset_value(_state, _field, _type), \
287}
288
289#define VMSTATE_POINTER_TEST(_field, _state, _test, _info, _type) { \
290 .name = (stringify(_field)), \
291 .info = &(_info), \
292 .field_exists = (_test), \
293 .size = sizeof(_type), \
294 .flags = VMS_SINGLE|VMS_POINTER, \
295 .offset = vmstate_offset_value(_state, _field, _type), \
296}
297
298#define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\
299 .name = (stringify(_field)), \
300 .version_id = (_version), \
301 .num = (_num), \
302 .info = &(_info), \
303 .size = sizeof(_type), \
304 .flags = VMS_ARRAY, \
305 .offset = vmstate_offset_array(_state, _field, _type, _num), \
306}
307
Peter Maydellbd7f92e2013-04-05 16:17:59 +0100308#define VMSTATE_2DARRAY(_field, _state, _n1, _n2, _version, _info, _type) { \
309 .name = (stringify(_field)), \
310 .version_id = (_version), \
311 .num = (_n1) * (_n2), \
312 .info = &(_info), \
313 .size = sizeof(_type), \
314 .flags = VMS_ARRAY, \
315 .offset = vmstate_offset_2darray(_state, _field, _type, _n1, _n2), \
316}
317
Juan Quintelab47d3af2016-01-11 12:40:22 +0000318#define VMSTATE_VARRAY_MULTIPLY(_field, _state, _field_num, _multiply, _info, _type) { \
319 .name = (stringify(_field)), \
320 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
321 .num = (_multiply), \
322 .info = &(_info), \
323 .size = sizeof(_type), \
324 .flags = VMS_VARRAY_UINT32|VMS_MULTIPLY_ELEMENTS, \
325 .offset = offsetof(_state, _field), \
326}
327
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100328#define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
329 .name = (stringify(_field)), \
330 .field_exists = (_test), \
331 .num = (_num), \
332 .info = &(_info), \
333 .size = sizeof(_type), \
334 .flags = VMS_ARRAY, \
335 .offset = vmstate_offset_array(_state, _field, _type, _num),\
336}
337
338#define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \
339 .name = (stringify(_field)), \
340 .version_id = (_version), \
341 .num = (_num), \
342 .info = &(_info), \
343 .size = sizeof(_type), \
344 .flags = VMS_ARRAY, \
345 .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \
346}
347
348#define VMSTATE_ARRAY_INT32_UNSAFE(_field, _state, _field_num, _info, _type) {\
349 .name = (stringify(_field)), \
350 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
351 .info = &(_info), \
352 .size = sizeof(_type), \
353 .flags = VMS_VARRAY_INT32, \
354 .offset = offsetof(_state, _field), \
355}
356
357#define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\
358 .name = (stringify(_field)), \
359 .version_id = (_version), \
360 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
361 .info = &(_info), \
362 .size = sizeof(_type), \
363 .flags = VMS_VARRAY_INT32|VMS_POINTER, \
364 .offset = vmstate_offset_pointer(_state, _field, _type), \
365}
366
367#define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info, _type) {\
368 .name = (stringify(_field)), \
369 .version_id = (_version), \
370 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
371 .info = &(_info), \
372 .size = sizeof(_type), \
373 .flags = VMS_VARRAY_UINT32|VMS_POINTER, \
374 .offset = vmstate_offset_pointer(_state, _field, _type), \
375}
376
Alexey Kardashevskiy705124e2016-06-01 18:57:32 +1000377#define VMSTATE_VARRAY_UINT32_ALLOC(_field, _state, _field_num, _version, _info, _type) {\
378 .name = (stringify(_field)), \
379 .version_id = (_version), \
380 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
381 .info = &(_info), \
382 .size = sizeof(_type), \
383 .flags = VMS_VARRAY_UINT32|VMS_POINTER|VMS_ALLOC, \
384 .offset = vmstate_offset_pointer(_state, _field, _type), \
385}
386
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100387#define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version, _info, _type) {\
388 .name = (stringify(_field)), \
389 .version_id = (_version), \
390 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
391 .info = &(_info), \
392 .size = sizeof(_type), \
393 .flags = VMS_VARRAY_UINT16, \
394 .offset = offsetof(_state, _field), \
395}
396
397#define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \
398 .name = (stringify(_field)), \
399 .version_id = (_version), \
400 .field_exists = (_test), \
401 .vmsd = &(_vmsd), \
402 .size = sizeof(_type), \
403 .flags = VMS_STRUCT, \
404 .offset = vmstate_offset_value(_state, _field, _type), \
405}
406
Alexey Kardashevskiy71024002013-09-04 14:35:26 +1000407#define VMSTATE_STRUCT_POINTER_V(_field, _state, _version, _vmsd, _type) { \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100408 .name = (stringify(_field)), \
Alexey Kardashevskiy71024002013-09-04 14:35:26 +1000409 .version_id = (_version), \
410 .vmsd = &(_vmsd), \
Peter Maydell20bcf732014-01-01 21:56:57 +0000411 .size = sizeof(_type *), \
Alexey Kardashevskiy71024002013-09-04 14:35:26 +1000412 .flags = VMS_STRUCT|VMS_POINTER, \
Peter Maydell20bcf732014-01-01 21:56:57 +0000413 .offset = vmstate_offset_pointer(_state, _field, _type), \
Alexey Kardashevskiy71024002013-09-04 14:35:26 +1000414}
415
416#define VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, _version, _vmsd, _type) { \
417 .name = (stringify(_field)), \
418 .version_id = (_version), \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100419 .field_exists = (_test), \
420 .vmsd = &(_vmsd), \
Peter Maydell20bcf732014-01-01 21:56:57 +0000421 .size = sizeof(_type *), \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100422 .flags = VMS_STRUCT|VMS_POINTER, \
Peter Maydell20bcf732014-01-01 21:56:57 +0000423 .offset = vmstate_offset_pointer(_state, _field, _type), \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100424}
425
426#define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) {\
427 .name = (stringify(_field)), \
428 .version_id = (_version), \
429 .num = (_num), \
430 .info = &(_info), \
431 .size = sizeof(_type), \
432 .flags = VMS_ARRAY|VMS_ARRAY_OF_POINTER, \
433 .offset = vmstate_offset_array(_state, _field, _type, _num), \
434}
435
Peter Maydella1f05e72013-12-17 19:42:37 +0000436#define VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(_f, _s, _n, _v, _vmsd, _type) { \
437 .name = (stringify(_f)), \
438 .version_id = (_v), \
439 .num = (_n), \
440 .vmsd = &(_vmsd), \
441 .size = sizeof(_type *), \
442 .flags = VMS_ARRAY|VMS_STRUCT|VMS_ARRAY_OF_POINTER, \
443 .offset = vmstate_offset_array(_s, _f, _type*, _n), \
444}
445
Paolo Bonzinia03c3e92014-10-24 10:18:38 +0200446#define VMSTATE_STRUCT_SUB_ARRAY(_field, _state, _start, _num, _version, _vmsd, _type) { \
447 .name = (stringify(_field)), \
448 .version_id = (_version), \
449 .num = (_num), \
450 .vmsd = &(_vmsd), \
451 .size = sizeof(_type), \
452 .flags = VMS_STRUCT|VMS_ARRAY, \
453 .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \
454}
455
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100456#define VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, _test, _version, _vmsd, _type) { \
457 .name = (stringify(_field)), \
458 .num = (_num), \
459 .field_exists = (_test), \
460 .version_id = (_version), \
461 .vmsd = &(_vmsd), \
462 .size = sizeof(_type), \
463 .flags = VMS_STRUCT|VMS_ARRAY, \
464 .offset = vmstate_offset_array(_state, _field, _type, _num),\
465}
466
Stafford Horneb75c9582017-04-16 19:43:23 +0900467#define VMSTATE_STRUCT_2DARRAY_TEST(_field, _state, _n1, _n2, _test, \
468 _version, _vmsd, _type) { \
469 .name = (stringify(_field)), \
470 .num = (_n1) * (_n2), \
471 .field_exists = (_test), \
472 .version_id = (_version), \
473 .vmsd = &(_vmsd), \
474 .size = sizeof(_type), \
475 .flags = VMS_STRUCT | VMS_ARRAY, \
476 .offset = vmstate_offset_2darray(_state, _field, _type, \
477 _n1, _n2), \
478}
479
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100480#define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, _vmsd, _type) { \
481 .name = (stringify(_field)), \
482 .num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \
483 .version_id = (_version), \
484 .vmsd = &(_vmsd), \
485 .size = sizeof(_type), \
486 .flags = VMS_STRUCT|VMS_VARRAY_UINT8, \
487 .offset = offsetof(_state, _field), \
488}
489
Dr. David Alan Gilbert3e996cc2016-01-29 13:18:56 +0000490/* a variable length array (i.e. _type *_field) but we know the
491 * length
492 */
493#define VMSTATE_STRUCT_VARRAY_POINTER_KNOWN(_field, _state, _num, _version, _vmsd, _type) { \
494 .name = (stringify(_field)), \
495 .num = (_num), \
496 .version_id = (_version), \
497 .vmsd = &(_vmsd), \
498 .size = sizeof(_type), \
499 .flags = VMS_STRUCT|VMS_ARRAY|VMS_POINTER, \
500 .offset = offsetof(_state, _field), \
501}
502
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100503#define VMSTATE_STRUCT_VARRAY_POINTER_INT32(_field, _state, _field_num, _vmsd, _type) { \
504 .name = (stringify(_field)), \
505 .version_id = 0, \
506 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
507 .size = sizeof(_type), \
508 .vmsd = &(_vmsd), \
509 .flags = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \
510 .offset = vmstate_offset_pointer(_state, _field, _type), \
511}
512
David Gibson8474a9d2013-03-12 14:06:03 +1100513#define VMSTATE_STRUCT_VARRAY_POINTER_UINT32(_field, _state, _field_num, _vmsd, _type) { \
514 .name = (stringify(_field)), \
515 .version_id = 0, \
516 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
517 .size = sizeof(_type), \
518 .vmsd = &(_vmsd), \
519 .flags = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \
520 .offset = vmstate_offset_pointer(_state, _field, _type), \
521}
522
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100523#define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, _vmsd, _type) { \
524 .name = (stringify(_field)), \
525 .version_id = 0, \
526 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
527 .size = sizeof(_type), \
528 .vmsd = &(_vmsd), \
529 .flags = VMS_POINTER | VMS_VARRAY_UINT16 | VMS_STRUCT, \
530 .offset = vmstate_offset_pointer(_state, _field, _type), \
531}
532
533#define VMSTATE_STRUCT_VARRAY_INT32(_field, _state, _field_num, _version, _vmsd, _type) { \
534 .name = (stringify(_field)), \
535 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
536 .version_id = (_version), \
537 .vmsd = &(_vmsd), \
538 .size = sizeof(_type), \
539 .flags = VMS_STRUCT|VMS_VARRAY_INT32, \
540 .offset = offsetof(_state, _field), \
541}
542
543#define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version, _vmsd, _type) { \
544 .name = (stringify(_field)), \
545 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t), \
546 .version_id = (_version), \
547 .vmsd = &(_vmsd), \
548 .size = sizeof(_type), \
549 .flags = VMS_STRUCT|VMS_VARRAY_UINT32, \
550 .offset = offsetof(_state, _field), \
551}
552
Alexey Kardashevskiyf32935e2014-05-30 19:34:19 +1000553#define VMSTATE_STRUCT_VARRAY_ALLOC(_field, _state, _field_num, _version, _vmsd, _type) {\
554 .name = (stringify(_field)), \
555 .version_id = (_version), \
556 .vmsd = &(_vmsd), \
557 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
558 .size = sizeof(_type), \
559 .flags = VMS_STRUCT|VMS_VARRAY_INT32|VMS_ALLOC|VMS_POINTER, \
560 .offset = vmstate_offset_pointer(_state, _field, _type), \
561}
562
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100563#define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \
564 .name = (stringify(_field)), \
565 .version_id = (_version), \
566 .field_exists = (_test), \
567 .size = (_size - _start), \
568 .info = &vmstate_info_buffer, \
569 .flags = VMS_BUFFER, \
570 .offset = vmstate_offset_buffer(_state, _field) + _start, \
571}
572
Halil Pasic59046ec2017-02-03 18:52:17 +0100573#define VMSTATE_VBUFFER_MULTIPLY(_field, _state, _version, _test, \
574 _field_size, _multiply) { \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100575 .name = (stringify(_field)), \
576 .version_id = (_version), \
577 .field_exists = (_test), \
578 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\
579 .size = (_multiply), \
580 .info = &vmstate_info_buffer, \
David Gibson377e2cb2013-03-12 14:06:04 +1100581 .flags = VMS_VBUFFER|VMS_POINTER|VMS_MULTIPLY, \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100582 .offset = offsetof(_state, _field), \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100583}
584
Halil Pasic59046ec2017-02-03 18:52:17 +0100585#define VMSTATE_VBUFFER(_field, _state, _version, _test, _field_size) { \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100586 .name = (stringify(_field)), \
587 .version_id = (_version), \
588 .field_exists = (_test), \
589 .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\
590 .info = &vmstate_info_buffer, \
591 .flags = VMS_VBUFFER|VMS_POINTER, \
592 .offset = offsetof(_state, _field), \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100593}
594
Halil Pasic59046ec2017-02-03 18:52:17 +0100595#define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _field_size) { \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100596 .name = (stringify(_field)), \
597 .version_id = (_version), \
598 .field_exists = (_test), \
599 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\
600 .info = &vmstate_info_buffer, \
601 .flags = VMS_VBUFFER|VMS_POINTER, \
602 .offset = offsetof(_state, _field), \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100603}
604
Halil Pasic59046ec2017-02-03 18:52:17 +0100605#define VMSTATE_VBUFFER_ALLOC_UINT32(_field, _state, _version, \
606 _test, _field_size) { \
Alexey Kardashevskiy94ed7062014-10-02 19:56:02 +1000607 .name = (stringify(_field)), \
608 .version_id = (_version), \
609 .field_exists = (_test), \
610 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\
611 .info = &vmstate_info_buffer, \
612 .flags = VMS_VBUFFER|VMS_POINTER|VMS_ALLOC, \
613 .offset = offsetof(_state, _field), \
Alexey Kardashevskiy94ed7062014-10-02 19:56:02 +1000614}
615
Laszlo Ersek9df0b0e2015-06-19 04:40:08 +0200616#define VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, _test, _version, _info, _size) { \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100617 .name = (stringify(_field)), \
618 .version_id = (_version), \
Laszlo Ersek9df0b0e2015-06-19 04:40:08 +0200619 .field_exists = (_test), \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100620 .size = (_size), \
621 .info = &(_info), \
622 .flags = VMS_BUFFER, \
623 .offset = offsetof(_state, _field), \
624}
625
Igor Mitsyanko80705682013-04-05 16:17:58 +0100626#define VMSTATE_BUFFER_POINTER_UNSAFE(_field, _state, _version, _size) { \
627 .name = (stringify(_field)), \
628 .version_id = (_version), \
629 .size = (_size), \
630 .info = &vmstate_info_buffer, \
631 .flags = VMS_BUFFER|VMS_POINTER, \
632 .offset = offsetof(_state, _field), \
633}
634
Dr. David Alan Gilbertbcf45132017-02-03 16:06:49 +0000635/* Allocate a temporary of type 'tmp_type', set tmp->parent to _state
636 * and execute the vmsd on the temporary. Note that we're working with
637 * the whole of _state here, not a field within it.
638 * We compile time check that:
639 * That _tmp_type contains a 'parent' member that's a pointer to the
640 * '_state' type
641 * That the pointer is right at the start of _tmp_type.
642 */
643#define VMSTATE_WITH_TMP(_state, _tmp_type, _vmsd) { \
644 .name = "tmp", \
645 .size = sizeof(_tmp_type) + \
646 QEMU_BUILD_BUG_ON_ZERO(offsetof(_tmp_type, parent) != 0) + \
647 type_check_pointer(_state, \
648 typeof_field(_tmp_type, parent)), \
649 .vmsd = &(_vmsd), \
650 .info = &vmstate_info_tmp, \
651}
652
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100653#define VMSTATE_UNUSED_BUFFER(_test, _version, _size) { \
654 .name = "unused", \
655 .field_exists = (_test), \
656 .version_id = (_version), \
657 .size = (_size), \
658 .info = &vmstate_info_unused_buffer, \
659 .flags = VMS_BUFFER, \
660}
661
Dr. David Alan Gilbertb5b5c562017-02-03 16:06:48 +0000662/* Discard size * field_num bytes, where field_num is a uint32 member */
663#define VMSTATE_UNUSED_VARRAY_UINT32(_state, _test, _version, _field_num, _size) {\
664 .name = "unused", \
665 .field_exists = (_test), \
666 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
667 .version_id = (_version), \
668 .size = (_size), \
669 .info = &vmstate_info_unused_buffer, \
670 .flags = VMS_VARRAY_UINT32 | VMS_BUFFER, \
671}
672
Peter Maydell08e99e22012-10-30 07:45:12 +0000673/* _field_size should be a int32_t field in the _state struct giving the
674 * size of the bitmap _field in bits.
675 */
676#define VMSTATE_BITMAP(_field, _state, _version, _field_size) { \
677 .name = (stringify(_field)), \
678 .version_id = (_version), \
679 .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\
680 .info = &vmstate_info_bitmap, \
681 .flags = VMS_VBUFFER|VMS_POINTER, \
682 .offset = offsetof(_state, _field), \
683}
684
Jianjun Duan94869d52017-01-19 11:00:51 -0800685/* For migrating a QTAILQ.
686 * Target QTAILQ needs be properly initialized.
687 * _type: type of QTAILQ element
688 * _next: name of QTAILQ entry field in QTAILQ element
689 * _vmsd: VMSD for QTAILQ element
690 * size: size of QTAILQ element
691 * start: offset of QTAILQ entry in QTAILQ element
692 */
693#define VMSTATE_QTAILQ_V(_field, _state, _version, _vmsd, _type, _next) \
694{ \
695 .name = (stringify(_field)), \
696 .version_id = (_version), \
697 .vmsd = &(_vmsd), \
698 .size = sizeof(_type), \
699 .info = &vmstate_info_qtailq, \
700 .offset = offsetof(_state, _field), \
701 .start = offsetof(_type, _next), \
702}
703
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100704/* _f : field name
705 _f_n : num of elements field_name
706 _n : num of elements
707 _s : struct state name
708 _v : version
709*/
710
711#define VMSTATE_SINGLE(_field, _state, _version, _info, _type) \
712 VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type)
713
714#define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) \
715 VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type)
716
717#define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type) \
Alexey Kardashevskiy71024002013-09-04 14:35:26 +1000718 VMSTATE_STRUCT_POINTER_V(_field, _state, 0, _vmsd, _type)
719
720#define VMSTATE_STRUCT_POINTER_TEST(_field, _state, _test, _vmsd, _type) \
721 VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, 0, _vmsd, _type)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100722
723#define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) \
724 VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version, \
725 _vmsd, _type)
726
Stafford Horneb75c9582017-04-16 19:43:23 +0900727#define VMSTATE_STRUCT_2DARRAY(_field, _state, _n1, _n2, _version, \
728 _vmsd, _type) \
729 VMSTATE_STRUCT_2DARRAY_TEST(_field, _state, _n1, _n2, NULL, \
730 _version, _vmsd, _type)
731
Laszlo Ersek9df0b0e2015-06-19 04:40:08 +0200732#define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) \
733 VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, NULL, _version, _info, \
734 _size)
735
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100736#define VMSTATE_BOOL_V(_f, _s, _v) \
737 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool)
738
739#define VMSTATE_INT8_V(_f, _s, _v) \
740 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t)
741#define VMSTATE_INT16_V(_f, _s, _v) \
742 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t)
743#define VMSTATE_INT32_V(_f, _s, _v) \
744 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t)
745#define VMSTATE_INT64_V(_f, _s, _v) \
746 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t)
747
748#define VMSTATE_UINT8_V(_f, _s, _v) \
749 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t)
750#define VMSTATE_UINT16_V(_f, _s, _v) \
751 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t)
752#define VMSTATE_UINT32_V(_f, _s, _v) \
753 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t)
754#define VMSTATE_UINT64_V(_f, _s, _v) \
755 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t)
756
757#define VMSTATE_BOOL(_f, _s) \
758 VMSTATE_BOOL_V(_f, _s, 0)
759
760#define VMSTATE_INT8(_f, _s) \
761 VMSTATE_INT8_V(_f, _s, 0)
762#define VMSTATE_INT16(_f, _s) \
763 VMSTATE_INT16_V(_f, _s, 0)
764#define VMSTATE_INT32(_f, _s) \
765 VMSTATE_INT32_V(_f, _s, 0)
766#define VMSTATE_INT64(_f, _s) \
767 VMSTATE_INT64_V(_f, _s, 0)
768
769#define VMSTATE_UINT8(_f, _s) \
770 VMSTATE_UINT8_V(_f, _s, 0)
771#define VMSTATE_UINT16(_f, _s) \
772 VMSTATE_UINT16_V(_f, _s, 0)
773#define VMSTATE_UINT32(_f, _s) \
774 VMSTATE_UINT32_V(_f, _s, 0)
775#define VMSTATE_UINT64(_f, _s) \
776 VMSTATE_UINT64_V(_f, _s, 0)
777
Halil Pasicd2164ad2017-06-23 16:48:23 +0200778#define VMSTATE_UINT8_EQUAL(_f, _s, _err_hint) \
779 VMSTATE_SINGLE_FULL(_f, _s, 0, 0, \
780 vmstate_info_uint8_equal, uint8_t, _err_hint)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100781
Halil Pasicd2164ad2017-06-23 16:48:23 +0200782#define VMSTATE_UINT16_EQUAL(_f, _s, _err_hint) \
783 VMSTATE_SINGLE_FULL(_f, _s, 0, 0, \
784 vmstate_info_uint16_equal, uint16_t, _err_hint)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100785
Halil Pasicd2164ad2017-06-23 16:48:23 +0200786#define VMSTATE_UINT16_EQUAL_V(_f, _s, _v, _err_hint) \
787 VMSTATE_SINGLE_FULL(_f, _s, 0, _v, \
788 vmstate_info_uint16_equal, uint16_t, _err_hint)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100789
Halil Pasicd2164ad2017-06-23 16:48:23 +0200790#define VMSTATE_INT32_EQUAL(_f, _s, _err_hint) \
791 VMSTATE_SINGLE_FULL(_f, _s, 0, 0, \
792 vmstate_info_int32_equal, int32_t, _err_hint)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100793
Halil Pasicd2164ad2017-06-23 16:48:23 +0200794#define VMSTATE_UINT32_EQUAL_V(_f, _s, _v, _err_hint) \
795 VMSTATE_SINGLE_FULL(_f, _s, 0, _v, \
796 vmstate_info_uint32_equal, uint32_t, _err_hint)
David Gibsond58f5592013-03-12 14:06:01 +1100797
Halil Pasicd2164ad2017-06-23 16:48:23 +0200798#define VMSTATE_UINT32_EQUAL(_f, _s, _err_hint) \
799 VMSTATE_UINT32_EQUAL_V(_f, _s, 0, _err_hint)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100800
Halil Pasicd2164ad2017-06-23 16:48:23 +0200801#define VMSTATE_UINT64_EQUAL_V(_f, _s, _v, _err_hint) \
802 VMSTATE_SINGLE_FULL(_f, _s, 0, _v, \
803 vmstate_info_uint64_equal, uint64_t, _err_hint)
David Gibsone344b8a2013-03-12 14:06:00 +1100804
Halil Pasicd2164ad2017-06-23 16:48:23 +0200805#define VMSTATE_UINT64_EQUAL(_f, _s, _err_hint) \
806 VMSTATE_UINT64_EQUAL_V(_f, _s, 0, _err_hint)
David Gibsone344b8a2013-03-12 14:06:00 +1100807
Michael S. Tsirkin34764362014-04-03 19:52:21 +0300808#define VMSTATE_INT32_POSITIVE_LE(_f, _s) \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100809 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
810
David Gibson87774a42015-02-06 14:55:46 +1100811#define VMSTATE_INT8_TEST(_f, _s, _t) \
812 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int8, int8_t)
813
814#define VMSTATE_INT16_TEST(_f, _s, _t) \
815 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int16, int16_t)
816
817#define VMSTATE_INT32_TEST(_f, _s, _t) \
818 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int32, int32_t)
819
820#define VMSTATE_INT64_TEST(_f, _s, _t) \
821 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int64, int64_t)
822
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100823#define VMSTATE_UINT8_TEST(_f, _s, _t) \
824 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t)
825
826#define VMSTATE_UINT16_TEST(_f, _s, _t) \
827 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
828
829#define VMSTATE_UINT32_TEST(_f, _s, _t) \
830 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)
831
David Gibson87774a42015-02-06 14:55:46 +1100832#define VMSTATE_UINT64_TEST(_f, _s, _t) \
833 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint64, uint64_t)
834
David Gibson213945e2013-03-12 14:06:02 +1100835
836#define VMSTATE_FLOAT64_V(_f, _s, _v) \
837 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_float64, float64)
838
839#define VMSTATE_FLOAT64(_f, _s) \
840 VMSTATE_FLOAT64_V(_f, _s, 0)
841
Paolo Bonzinie7206772015-01-08 10:18:59 +0100842#define VMSTATE_TIMER_PTR_TEST(_f, _s, _test) \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100843 VMSTATE_POINTER_TEST(_f, _s, _test, vmstate_info_timer, QEMUTimer *)
844
Paolo Bonzinie7206772015-01-08 10:18:59 +0100845#define VMSTATE_TIMER_PTR_V(_f, _s, _v) \
Paolo Bonzini02815182012-08-02 18:04:08 +0200846 VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *)
847
Paolo Bonzinie7206772015-01-08 10:18:59 +0100848#define VMSTATE_TIMER_PTR(_f, _s) \
849 VMSTATE_TIMER_PTR_V(_f, _s, 0)
850
851#define VMSTATE_TIMER_PTR_ARRAY(_f, _s, _n) \
852 VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *)
853
854#define VMSTATE_TIMER_TEST(_f, _s, _test) \
855 VMSTATE_SINGLE_TEST(_f, _s, _test, 0, vmstate_info_timer, QEMUTimer)
856
857#define VMSTATE_TIMER_V(_f, _s, _v) \
858 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_timer, QEMUTimer)
859
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100860#define VMSTATE_TIMER(_f, _s) \
Paolo Bonzini02815182012-08-02 18:04:08 +0200861 VMSTATE_TIMER_V(_f, _s, 0)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100862
863#define VMSTATE_TIMER_ARRAY(_f, _s, _n) \
Paolo Bonzinie7206772015-01-08 10:18:59 +0100864 VMSTATE_ARRAY(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100865
866#define VMSTATE_BOOL_ARRAY_V(_f, _s, _n, _v) \
867 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_bool, bool)
868
869#define VMSTATE_BOOL_ARRAY(_f, _s, _n) \
870 VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0)
871
872#define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v) \
873 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t)
874
Peter Maydellbd7f92e2013-04-05 16:17:59 +0100875#define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v) \
876 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t)
877
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100878#define VMSTATE_UINT16_ARRAY(_f, _s, _n) \
879 VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0)
880
Peter Maydellbd7f92e2013-04-05 16:17:59 +0100881#define VMSTATE_UINT16_2DARRAY(_f, _s, _n1, _n2) \
882 VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, 0)
883
884#define VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, _v) \
885 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint8, uint8_t)
886
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100887#define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v) \
888 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t)
889
890#define VMSTATE_UINT8_ARRAY(_f, _s, _n) \
891 VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0)
892
Fam Zheng2e323f02014-03-06 16:26:02 +0800893#define VMSTATE_UINT8_SUB_ARRAY(_f, _s, _start, _num) \
894 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint8, uint8_t)
895
Peter Maydellbd7f92e2013-04-05 16:17:59 +0100896#define VMSTATE_UINT8_2DARRAY(_f, _s, _n1, _n2) \
897 VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, 0)
898
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100899#define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v) \
900 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t)
901
Christoffer Dalla1b1d272013-09-20 20:35:06 +0100902#define VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, _v) \
903 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint32, uint32_t)
904
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100905#define VMSTATE_UINT32_ARRAY(_f, _s, _n) \
906 VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
907
Christoffer Dalla1b1d272013-09-20 20:35:06 +0100908#define VMSTATE_UINT32_2DARRAY(_f, _s, _n1, _n2) \
909 VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, 0)
910
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100911#define VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v) \
912 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint64, uint64_t)
913
914#define VMSTATE_UINT64_ARRAY(_f, _s, _n) \
915 VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0)
916
Peter Maydell04716bc2016-06-17 15:23:45 +0100917#define VMSTATE_UINT64_2DARRAY(_f, _s, _n1, _n2) \
918 VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, 0)
919
920#define VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, _v) \
921 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint64, uint64_t)
922
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100923#define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v) \
924 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t)
925
926#define VMSTATE_INT16_ARRAY(_f, _s, _n) \
927 VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0)
928
929#define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v) \
930 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t)
931
932#define VMSTATE_INT32_ARRAY(_f, _s, _n) \
933 VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0)
934
935#define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num) \
936 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t)
937
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100938#define VMSTATE_INT64_ARRAY_V(_f, _s, _n, _v) \
939 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int64, int64_t)
940
941#define VMSTATE_INT64_ARRAY(_f, _s, _n) \
942 VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0)
943
David Gibson213945e2013-03-12 14:06:02 +1100944#define VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, _v) \
945 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_float64, float64)
946
947#define VMSTATE_FLOAT64_ARRAY(_f, _s, _n) \
948 VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, 0)
949
Juan Quintela55174742016-01-11 12:40:21 +0000950#define VMSTATE_CPUDOUBLE_ARRAY_V(_f, _s, _n, _v) \
951 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_cpudouble, CPU_DoubleU)
952
953#define VMSTATE_CPUDOUBLE_ARRAY(_f, _s, _n) \
954 VMSTATE_CPUDOUBLE_ARRAY_V(_f, _s, _n, 0)
955
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100956#define VMSTATE_BUFFER_V(_f, _s, _v) \
957 VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f)))
958
959#define VMSTATE_BUFFER(_f, _s) \
960 VMSTATE_BUFFER_V(_f, _s, 0)
961
962#define VMSTATE_PARTIAL_BUFFER(_f, _s, _size) \
963 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, _size)
964
Paolo Bonzinicc966772016-06-20 16:32:39 +0200965#define VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, _v) \
966 VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, _start, sizeof(typeof_field(_s, _f)))
967
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100968#define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \
Paolo Bonzinicc966772016-06-20 16:32:39 +0200969 VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, 0)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100970
971#define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size) \
Halil Pasic59046ec2017-02-03 18:52:17 +0100972 VMSTATE_VBUFFER(_f, _s, 0, NULL, _size)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100973
974#define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size) \
Halil Pasic59046ec2017-02-03 18:52:17 +0100975 VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, _size)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100976
977#define VMSTATE_BUFFER_TEST(_f, _s, _test) \
978 VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f)))
979
980#define VMSTATE_BUFFER_UNSAFE(_field, _state, _version, _size) \
981 VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, _size)
982
983#define VMSTATE_UNUSED_V(_v, _size) \
984 VMSTATE_UNUSED_BUFFER(NULL, _v, _size)
985
986#define VMSTATE_UNUSED(_size) \
987 VMSTATE_UNUSED_V(0, _size)
988
989#define VMSTATE_UNUSED_TEST(_test, _size) \
990 VMSTATE_UNUSED_BUFFER(_test, 0, _size)
991
992#define VMSTATE_END_OF_LIST() \
993 {}
994
995int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
996 void *opaque, int version_id);
997void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
Alexander Graf8118f092015-01-22 15:01:39 +0100998 void *opaque, QJSON *vmdesc);
Andreas Färberd7650ea2013-02-18 21:41:59 +0100999
Juan Quinteladf896152014-10-15 09:39:14 +02001000bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque);
1001
Dr. David Alan Gilbert581f08b2017-02-02 12:59:55 +00001002/* Returns: 0 on success, -1 on failure */
Paolo Bonzini701a8f72012-01-13 17:07:20 +01001003int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
1004 const VMStateDescription *vmsd,
1005 void *base, int alias_id,
Dr. David Alan Gilbertbc5c4f22017-02-02 12:59:54 +00001006 int required_for_version,
1007 Error **errp);
Andreas Färberd7650ea2013-02-18 21:41:59 +01001008
Dr. David Alan Gilbert581f08b2017-02-02 12:59:55 +00001009/* Returns: 0 on success, -1 on failure */
Andreas Färberd7650ea2013-02-18 21:41:59 +01001010static inline int vmstate_register(DeviceState *dev, int instance_id,
1011 const VMStateDescription *vmsd,
1012 void *opaque)
1013{
1014 return vmstate_register_with_alias_id(dev, instance_id, vmsd,
Dr. David Alan Gilbertbc5c4f22017-02-02 12:59:54 +00001015 opaque, -1, 0, NULL);
Andreas Färberd7650ea2013-02-18 21:41:59 +01001016}
1017
Paolo Bonzini701a8f72012-01-13 17:07:20 +01001018void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd,
1019 void *opaque);
1020
1021struct MemoryRegion;
1022void vmstate_register_ram(struct MemoryRegion *memory, DeviceState *dev);
1023void vmstate_unregister_ram(struct MemoryRegion *memory, DeviceState *dev);
1024void vmstate_register_ram_global(struct MemoryRegion *memory);
1025
Juan Quintela1bfe5f02017-04-17 14:57:54 +02001026bool vmstate_check_only_migratable(const VMStateDescription *vmsd);
1027
Paolo Bonzini701a8f72012-01-13 17:07:20 +01001028#endif