blob: 61bef3ef5c0078ff81953760b348726ccbb2bced [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
Paolo Bonzini701a8f72012-01-13 17:07:20 +010030typedef struct VMStateInfo VMStateInfo;
31typedef struct VMStateDescription VMStateDescription;
Jianjun Duan2c21ee72017-01-19 11:00:50 -080032typedef struct VMStateField VMStateField;
Paolo Bonzini701a8f72012-01-13 17:07:20 +010033
Jianjun Duan2c21ee72017-01-19 11:00:50 -080034/* VMStateInfo allows customized migration of objects that don't fit in
35 * any category in VMStateFlags. Additional information is always passed
36 * into get and put in terms of field and vmdesc parameters. However
37 * these two parameters should only be used in cases when customized
38 * handling is needed, such as QTAILQ. For primitive data types such as
39 * integer, field and vmdesc parameters should be ignored inside get/put.
40 */
Paolo Bonzini701a8f72012-01-13 17:07:20 +010041struct VMStateInfo {
42 const char *name;
Marc-André Lureau03fee662018-11-14 17:29:30 +040043 int (*get)(QEMUFile *f, void *pv, size_t size, const VMStateField *field);
44 int (*put)(QEMUFile *f, void *pv, size_t size, const VMStateField *field,
Jianjun Duan2c21ee72017-01-19 11:00:50 -080045 QJSON *vmdesc);
Paolo Bonzini701a8f72012-01-13 17:07:20 +010046};
47
48enum VMStateFlags {
Sascha Silbe8da5ef52016-02-26 09:18:13 +010049 /* Ignored */
Paolo Bonzini701a8f72012-01-13 17:07:20 +010050 VMS_SINGLE = 0x001,
Sascha Silbe8da5ef52016-02-26 09:18:13 +010051
52 /* The struct member at opaque + VMStateField.offset is a pointer
53 * to the actual field (e.g. struct a { uint8_t *b;
54 * }). Dereference the pointer before using it as basis for
55 * further pointer arithmetic (see e.g. VMS_ARRAY). Does not
56 * affect the meaning of VMStateField.num_offset or
57 * VMStateField.size_offset; see VMS_VARRAY* and VMS_VBUFFER for
58 * those. */
Paolo Bonzini701a8f72012-01-13 17:07:20 +010059 VMS_POINTER = 0x002,
Sascha Silbe8da5ef52016-02-26 09:18:13 +010060
61 /* The field is an array of fixed size. VMStateField.num contains
62 * the number of entries in the array. The size of each entry is
63 * given by VMStateField.size and / or opaque +
64 * VMStateField.size_offset; see VMS_VBUFFER and
65 * VMS_MULTIPLY. Each array entry will be processed individually
66 * (VMStateField.info.get()/put() if VMS_STRUCT is not set,
67 * recursion into VMStateField.vmsd if VMS_STRUCT is set). May not
68 * be combined with VMS_VARRAY*. */
Paolo Bonzini701a8f72012-01-13 17:07:20 +010069 VMS_ARRAY = 0x004,
Sascha Silbe8da5ef52016-02-26 09:18:13 +010070
71 /* The field is itself a struct, containing one or more
72 * fields. Recurse into VMStateField.vmsd. Most useful in
73 * combination with VMS_ARRAY / VMS_VARRAY*, recursing into each
74 * array entry. */
Paolo Bonzini701a8f72012-01-13 17:07:20 +010075 VMS_STRUCT = 0x008,
Sascha Silbe8da5ef52016-02-26 09:18:13 +010076
77 /* The field is an array of variable size. The int32_t at opaque +
78 * VMStateField.num_offset contains the number of entries in the
79 * array. See the VMS_ARRAY description regarding array handling
80 * in general. May not be combined with VMS_ARRAY or any other
81 * VMS_VARRAY*. */
82 VMS_VARRAY_INT32 = 0x010,
83
84 /* Ignored */
85 VMS_BUFFER = 0x020,
86
87 /* The field is a (fixed-size or variable-size) array of pointers
88 * (e.g. struct a { uint8_t *b[]; }). Dereference each array entry
89 * before using it. Note: Does not imply any one of VMS_ARRAY /
90 * VMS_VARRAY*; these need to be set explicitly. */
Paolo Bonzini701a8f72012-01-13 17:07:20 +010091 VMS_ARRAY_OF_POINTER = 0x040,
Sascha Silbe8da5ef52016-02-26 09:18:13 +010092
93 /* The field is an array of variable size. The uint16_t at opaque
94 * + VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS)
95 * contains the number of entries in the array. See the VMS_ARRAY
96 * description regarding array handling in general. May not be
97 * combined with VMS_ARRAY or any other VMS_VARRAY*. */
98 VMS_VARRAY_UINT16 = 0x080,
99
100 /* The size of the individual entries (a single array entry if
101 * VMS_ARRAY or any of VMS_VARRAY* are set, or the field itself if
102 * neither is set) is variable (i.e. not known at compile-time),
103 * but the same for all entries. Use the int32_t at opaque +
104 * VMStateField.size_offset (subject to VMS_MULTIPLY) to determine
105 * the size of each (and every) entry. */
106 VMS_VBUFFER = 0x100,
107
108 /* Multiply the entry size given by the int32_t at opaque +
109 * VMStateField.size_offset (see VMS_VBUFFER description) with
110 * VMStateField.size to determine the number of bytes to be
111 * allocated. Only valid in combination with VMS_VBUFFER. */
112 VMS_MULTIPLY = 0x200,
113
114 /* The field is an array of variable size. The uint8_t at opaque +
115 * VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS)
116 * contains the number of entries in the array. See the VMS_ARRAY
117 * description regarding array handling in general. May not be
118 * combined with VMS_ARRAY or any other VMS_VARRAY*. */
119 VMS_VARRAY_UINT8 = 0x400,
120
121 /* The field is an array of variable size. The uint32_t at opaque
122 * + VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS)
123 * contains the number of entries in the array. See the VMS_ARRAY
124 * description regarding array handling in general. May not be
125 * combined with VMS_ARRAY or any other VMS_VARRAY*. */
126 VMS_VARRAY_UINT32 = 0x800,
127
128 /* Fail loading the serialised VM state if this field is missing
129 * from the input. */
130 VMS_MUST_EXIST = 0x1000,
131
132 /* When loading serialised VM state, allocate memory for the
133 * (entire) field. Only valid in combination with
134 * VMS_POINTER. Note: Not all combinations with other flags are
135 * currently supported, e.g. VMS_ALLOC|VMS_ARRAY_OF_POINTER won't
136 * cause the individual entries to be allocated. */
137 VMS_ALLOC = 0x2000,
138
139 /* Multiply the number of entries given by the integer at opaque +
140 * VMStateField.num_offset (see VMS_VARRAY*) with VMStateField.num
141 * to determine the number of entries in the array. Only valid in
142 * combination with one of VMS_VARRAY*. */
143 VMS_MULTIPLY_ELEMENTS = 0x4000,
Corey Minyard2dc66602018-04-25 10:27:30 -0500144
145 /* A structure field that is like VMS_STRUCT, but uses
146 * VMStateField.struct_version_id to tell which version of the
147 * structure we are referencing to use. */
148 VMS_VSTRUCT = 0x8000,
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100149};
150
Peter Xuf37bc032017-01-06 12:06:12 +0800151typedef enum {
152 MIG_PRI_DEFAULT = 0,
Peter Xu8cdcf3c2017-01-06 12:06:13 +0800153 MIG_PRI_IOMMU, /* Must happen before PCI devices */
Peter Xu9d6b9db2018-02-06 15:39:33 +0800154 MIG_PRI_PCI_BUS, /* Must happen before IOMMU */
Eric Auger252a7a62017-06-13 14:57:01 +0100155 MIG_PRI_GICV3_ITS, /* Must happen before PCI devices */
156 MIG_PRI_GICV3, /* Must happen before the ITS */
Peter Xuf37bc032017-01-06 12:06:12 +0800157 MIG_PRI_MAX,
158} MigrationPriority;
159
Jianjun Duan2c21ee72017-01-19 11:00:50 -0800160struct VMStateField {
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100161 const char *name;
Halil Pasicd2164ad2017-06-23 16:48:23 +0200162 const char *err_hint;
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100163 size_t offset;
164 size_t size;
165 size_t start;
166 int num;
167 size_t num_offset;
168 size_t size_offset;
169 const VMStateInfo *info;
170 enum VMStateFlags flags;
171 const VMStateDescription *vmsd;
172 int version_id;
Corey Minyard2dc66602018-04-25 10:27:30 -0500173 int struct_version_id;
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100174 bool (*field_exists)(void *opaque, int version_id);
Jianjun Duan2c21ee72017-01-19 11:00:50 -0800175};
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100176
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100177struct VMStateDescription {
178 const char *name;
179 int unmigratable;
180 int version_id;
181 int minimum_version_id;
182 int minimum_version_id_old;
Peter Xuf37bc032017-01-06 12:06:12 +0800183 MigrationPriority priority;
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100184 LoadStateHandler *load_state_old;
185 int (*pre_load)(void *opaque);
186 int (*post_load)(void *opaque, int version_id);
Dr. David Alan Gilbert44b1ff32017-09-25 12:29:12 +0100187 int (*pre_save)(void *opaque);
Juan Quintela5cd8cad2014-09-23 14:09:54 +0200188 bool (*needed)(void *opaque);
Marc-André Lureau03fee662018-11-14 17:29:30 +0400189 const VMStateField *fields;
Juan Quintela5cd8cad2014-09-23 14:09:54 +0200190 const VMStateDescription **subsections;
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100191};
192
Andreas Färberc71c3e92013-02-18 17:56:20 +0100193extern const VMStateDescription vmstate_dummy;
Andreas Färberc71c3e92013-02-18 17:56:20 +0100194
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100195extern const VMStateInfo vmstate_info_bool;
196
197extern const VMStateInfo vmstate_info_int8;
198extern const VMStateInfo vmstate_info_int16;
199extern const VMStateInfo vmstate_info_int32;
200extern const VMStateInfo vmstate_info_int64;
201
202extern const VMStateInfo vmstate_info_uint8_equal;
203extern const VMStateInfo vmstate_info_uint16_equal;
204extern const VMStateInfo vmstate_info_int32_equal;
205extern const VMStateInfo vmstate_info_uint32_equal;
David Gibsone344b8a2013-03-12 14:06:00 +1100206extern const VMStateInfo vmstate_info_uint64_equal;
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100207extern const VMStateInfo vmstate_info_int32_le;
208
209extern const VMStateInfo vmstate_info_uint8;
210extern const VMStateInfo vmstate_info_uint16;
211extern const VMStateInfo vmstate_info_uint32;
212extern const VMStateInfo vmstate_info_uint64;
213
Halil Pasic07d4e692017-02-22 17:01:17 +0100214/** Put this in the stream when migrating a null pointer.*/
215#define VMS_NULLPTR_MARKER (0x30U) /* '0' */
216extern const VMStateInfo vmstate_info_nullptr;
217
David Gibson213945e2013-03-12 14:06:02 +1100218extern const VMStateInfo vmstate_info_float64;
Juan Quintela55174742016-01-11 12:40:21 +0000219extern const VMStateInfo vmstate_info_cpudouble;
David Gibson213945e2013-03-12 14:06:02 +1100220
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100221extern const VMStateInfo vmstate_info_timer;
222extern const VMStateInfo vmstate_info_buffer;
223extern const VMStateInfo vmstate_info_unused_buffer;
Dr. David Alan Gilbertbcf45132017-02-03 16:06:49 +0000224extern const VMStateInfo vmstate_info_tmp;
Peter Maydell08e99e22012-10-30 07:45:12 +0000225extern const VMStateInfo vmstate_info_bitmap;
Jianjun Duan94869d52017-01-19 11:00:51 -0800226extern const VMStateInfo vmstate_info_qtailq;
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100227
Peter Maydellbd7f92e2013-04-05 16:17:59 +0100228#define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100229#define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
230#define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
231
232#define vmstate_offset_value(_state, _field, _type) \
233 (offsetof(_state, _field) + \
234 type_check(_type, typeof_field(_state, _field)))
235
236#define vmstate_offset_pointer(_state, _field, _type) \
237 (offsetof(_state, _field) + \
238 type_check_pointer(_type, typeof_field(_state, _field)))
239
240#define vmstate_offset_array(_state, _field, _type, _num) \
241 (offsetof(_state, _field) + \
242 type_check_array(_type, typeof_field(_state, _field), _num))
243
Peter Maydellbd7f92e2013-04-05 16:17:59 +0100244#define vmstate_offset_2darray(_state, _field, _type, _n1, _n2) \
245 (offsetof(_state, _field) + \
246 type_check_2darray(_type, typeof_field(_state, _field), _n1, _n2))
247
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100248#define vmstate_offset_sub_array(_state, _field, _type, _start) \
Paolo Bonziniea987c22015-01-07 15:12:13 +0100249 vmstate_offset_value(_state, _field[_start], _type)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100250
251#define vmstate_offset_buffer(_state, _field) \
252 vmstate_offset_array(_state, _field, uint8_t, \
253 sizeof(typeof_field(_state, _field)))
254
Corey Minyard2dc66602018-04-25 10:27:30 -0500255/* In the macros below, if there is a _version, that means the macro's
256 * field will be processed only if the version being received is >=
257 * the _version specified. In general, if you add a new field, you
258 * would increment the structure's version and put that version
259 * number into the new field so it would only be processed with the
260 * new version.
261 *
262 * In particular, for VMSTATE_STRUCT() and friends the _version does
263 * *NOT* pick the version of the sub-structure. It works just as
264 * specified above. The version of the top-level structure received
265 * is passed down to all sub-structures. This means that the
266 * sub-structures must have version that are compatible with all the
267 * structures that use them.
268 *
269 * If you want to specify the version of the sub-structure, use
270 * VMSTATE_VSTRUCT(), which allows the specific sub-structure version
271 * to be directly specified.
272 */
273
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100274#define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \
275 .name = (stringify(_field)), \
276 .version_id = (_version), \
277 .field_exists = (_test), \
278 .size = sizeof(_type), \
279 .info = &(_info), \
280 .flags = VMS_SINGLE, \
281 .offset = vmstate_offset_value(_state, _field, _type), \
282}
283
Halil Pasicd2164ad2017-06-23 16:48:23 +0200284#define VMSTATE_SINGLE_FULL(_field, _state, _test, _version, _info, \
285 _type, _err_hint) { \
286 .name = (stringify(_field)), \
287 .err_hint = (_err_hint), \
288 .version_id = (_version), \
289 .field_exists = (_test), \
290 .size = sizeof(_type), \
291 .info = &(_info), \
292 .flags = VMS_SINGLE, \
293 .offset = vmstate_offset_value(_state, _field, _type), \
294}
295
Michael S. Tsirkin4082f082014-04-03 19:50:35 +0300296/* Validate state using a boolean predicate. */
297#define VMSTATE_VALIDATE(_name, _test) { \
298 .name = (_name), \
299 .field_exists = (_test), \
300 .flags = VMS_ARRAY | VMS_MUST_EXIST, \
301 .num = 0, /* 0 elements: no data, only run _test */ \
302}
303
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100304#define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \
305 .name = (stringify(_field)), \
306 .version_id = (_version), \
307 .info = &(_info), \
308 .size = sizeof(_type), \
309 .flags = VMS_SINGLE|VMS_POINTER, \
310 .offset = vmstate_offset_value(_state, _field, _type), \
311}
312
313#define VMSTATE_POINTER_TEST(_field, _state, _test, _info, _type) { \
314 .name = (stringify(_field)), \
315 .info = &(_info), \
316 .field_exists = (_test), \
317 .size = sizeof(_type), \
318 .flags = VMS_SINGLE|VMS_POINTER, \
319 .offset = vmstate_offset_value(_state, _field, _type), \
320}
321
322#define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\
323 .name = (stringify(_field)), \
324 .version_id = (_version), \
325 .num = (_num), \
326 .info = &(_info), \
327 .size = sizeof(_type), \
328 .flags = VMS_ARRAY, \
329 .offset = vmstate_offset_array(_state, _field, _type, _num), \
330}
331
Peter Maydellbd7f92e2013-04-05 16:17:59 +0100332#define VMSTATE_2DARRAY(_field, _state, _n1, _n2, _version, _info, _type) { \
333 .name = (stringify(_field)), \
334 .version_id = (_version), \
335 .num = (_n1) * (_n2), \
336 .info = &(_info), \
337 .size = sizeof(_type), \
338 .flags = VMS_ARRAY, \
339 .offset = vmstate_offset_2darray(_state, _field, _type, _n1, _n2), \
340}
341
Juan Quintelab47d3af2016-01-11 12:40:22 +0000342#define VMSTATE_VARRAY_MULTIPLY(_field, _state, _field_num, _multiply, _info, _type) { \
343 .name = (stringify(_field)), \
344 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
345 .num = (_multiply), \
346 .info = &(_info), \
347 .size = sizeof(_type), \
348 .flags = VMS_VARRAY_UINT32|VMS_MULTIPLY_ELEMENTS, \
349 .offset = offsetof(_state, _field), \
350}
351
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100352#define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
353 .name = (stringify(_field)), \
354 .field_exists = (_test), \
355 .num = (_num), \
356 .info = &(_info), \
357 .size = sizeof(_type), \
358 .flags = VMS_ARRAY, \
359 .offset = vmstate_offset_array(_state, _field, _type, _num),\
360}
361
362#define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \
363 .name = (stringify(_field)), \
364 .version_id = (_version), \
365 .num = (_num), \
366 .info = &(_info), \
367 .size = sizeof(_type), \
368 .flags = VMS_ARRAY, \
369 .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \
370}
371
372#define VMSTATE_ARRAY_INT32_UNSAFE(_field, _state, _field_num, _info, _type) {\
373 .name = (stringify(_field)), \
374 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
375 .info = &(_info), \
376 .size = sizeof(_type), \
377 .flags = VMS_VARRAY_INT32, \
378 .offset = offsetof(_state, _field), \
379}
380
381#define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\
382 .name = (stringify(_field)), \
383 .version_id = (_version), \
384 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
385 .info = &(_info), \
386 .size = sizeof(_type), \
387 .flags = VMS_VARRAY_INT32|VMS_POINTER, \
388 .offset = vmstate_offset_pointer(_state, _field, _type), \
389}
390
391#define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info, _type) {\
392 .name = (stringify(_field)), \
393 .version_id = (_version), \
394 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
395 .info = &(_info), \
396 .size = sizeof(_type), \
397 .flags = VMS_VARRAY_UINT32|VMS_POINTER, \
398 .offset = vmstate_offset_pointer(_state, _field, _type), \
399}
400
Alexey Kardashevskiy705124e2016-06-01 18:57:32 +1000401#define VMSTATE_VARRAY_UINT32_ALLOC(_field, _state, _field_num, _version, _info, _type) {\
402 .name = (stringify(_field)), \
403 .version_id = (_version), \
404 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
405 .info = &(_info), \
406 .size = sizeof(_type), \
407 .flags = VMS_VARRAY_UINT32|VMS_POINTER|VMS_ALLOC, \
408 .offset = vmstate_offset_pointer(_state, _field, _type), \
409}
410
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100411#define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version, _info, _type) {\
412 .name = (stringify(_field)), \
413 .version_id = (_version), \
414 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
415 .info = &(_info), \
416 .size = sizeof(_type), \
417 .flags = VMS_VARRAY_UINT16, \
418 .offset = offsetof(_state, _field), \
419}
420
Corey Minyard2dc66602018-04-25 10:27:30 -0500421#define VMSTATE_VSTRUCT_TEST(_field, _state, _test, _version, _vmsd, _type, _struct_version) { \
422 .name = (stringify(_field)), \
423 .version_id = (_version), \
424 .struct_version_id = (_struct_version), \
425 .field_exists = (_test), \
426 .vmsd = &(_vmsd), \
427 .size = sizeof(_type), \
428 .flags = VMS_VSTRUCT, \
429 .offset = vmstate_offset_value(_state, _field, _type), \
430}
431
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100432#define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \
433 .name = (stringify(_field)), \
434 .version_id = (_version), \
435 .field_exists = (_test), \
436 .vmsd = &(_vmsd), \
437 .size = sizeof(_type), \
438 .flags = VMS_STRUCT, \
439 .offset = vmstate_offset_value(_state, _field, _type), \
440}
441
Alexey Kardashevskiy71024002013-09-04 14:35:26 +1000442#define VMSTATE_STRUCT_POINTER_V(_field, _state, _version, _vmsd, _type) { \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100443 .name = (stringify(_field)), \
Alexey Kardashevskiy71024002013-09-04 14:35:26 +1000444 .version_id = (_version), \
445 .vmsd = &(_vmsd), \
Peter Maydell20bcf732014-01-01 21:56:57 +0000446 .size = sizeof(_type *), \
Alexey Kardashevskiy71024002013-09-04 14:35:26 +1000447 .flags = VMS_STRUCT|VMS_POINTER, \
Peter Maydell20bcf732014-01-01 21:56:57 +0000448 .offset = vmstate_offset_pointer(_state, _field, _type), \
Alexey Kardashevskiy71024002013-09-04 14:35:26 +1000449}
450
451#define VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, _version, _vmsd, _type) { \
452 .name = (stringify(_field)), \
453 .version_id = (_version), \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100454 .field_exists = (_test), \
455 .vmsd = &(_vmsd), \
Peter Maydell20bcf732014-01-01 21:56:57 +0000456 .size = sizeof(_type *), \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100457 .flags = VMS_STRUCT|VMS_POINTER, \
Peter Maydell20bcf732014-01-01 21:56:57 +0000458 .offset = vmstate_offset_pointer(_state, _field, _type), \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100459}
460
461#define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) {\
462 .name = (stringify(_field)), \
463 .version_id = (_version), \
464 .num = (_num), \
465 .info = &(_info), \
466 .size = sizeof(_type), \
467 .flags = VMS_ARRAY|VMS_ARRAY_OF_POINTER, \
468 .offset = vmstate_offset_array(_state, _field, _type, _num), \
469}
470
Peter Maydella1f05e72013-12-17 19:42:37 +0000471#define VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(_f, _s, _n, _v, _vmsd, _type) { \
472 .name = (stringify(_f)), \
473 .version_id = (_v), \
474 .num = (_n), \
475 .vmsd = &(_vmsd), \
476 .size = sizeof(_type *), \
477 .flags = VMS_ARRAY|VMS_STRUCT|VMS_ARRAY_OF_POINTER, \
478 .offset = vmstate_offset_array(_s, _f, _type*, _n), \
479}
480
Paolo Bonzinia03c3e92014-10-24 10:18:38 +0200481#define VMSTATE_STRUCT_SUB_ARRAY(_field, _state, _start, _num, _version, _vmsd, _type) { \
482 .name = (stringify(_field)), \
483 .version_id = (_version), \
484 .num = (_num), \
485 .vmsd = &(_vmsd), \
486 .size = sizeof(_type), \
487 .flags = VMS_STRUCT|VMS_ARRAY, \
488 .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \
489}
490
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100491#define VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, _test, _version, _vmsd, _type) { \
492 .name = (stringify(_field)), \
493 .num = (_num), \
494 .field_exists = (_test), \
495 .version_id = (_version), \
496 .vmsd = &(_vmsd), \
497 .size = sizeof(_type), \
498 .flags = VMS_STRUCT|VMS_ARRAY, \
499 .offset = vmstate_offset_array(_state, _field, _type, _num),\
500}
501
Stafford Horneb75c9582017-04-16 19:43:23 +0900502#define VMSTATE_STRUCT_2DARRAY_TEST(_field, _state, _n1, _n2, _test, \
503 _version, _vmsd, _type) { \
504 .name = (stringify(_field)), \
505 .num = (_n1) * (_n2), \
506 .field_exists = (_test), \
507 .version_id = (_version), \
508 .vmsd = &(_vmsd), \
509 .size = sizeof(_type), \
510 .flags = VMS_STRUCT | VMS_ARRAY, \
511 .offset = vmstate_offset_2darray(_state, _field, _type, \
512 _n1, _n2), \
513}
514
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100515#define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, _vmsd, _type) { \
516 .name = (stringify(_field)), \
517 .num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \
518 .version_id = (_version), \
519 .vmsd = &(_vmsd), \
520 .size = sizeof(_type), \
521 .flags = VMS_STRUCT|VMS_VARRAY_UINT8, \
522 .offset = offsetof(_state, _field), \
523}
524
Dr. David Alan Gilbert3e996cc2016-01-29 13:18:56 +0000525/* a variable length array (i.e. _type *_field) but we know the
526 * length
527 */
528#define VMSTATE_STRUCT_VARRAY_POINTER_KNOWN(_field, _state, _num, _version, _vmsd, _type) { \
529 .name = (stringify(_field)), \
530 .num = (_num), \
531 .version_id = (_version), \
532 .vmsd = &(_vmsd), \
533 .size = sizeof(_type), \
534 .flags = VMS_STRUCT|VMS_ARRAY|VMS_POINTER, \
535 .offset = offsetof(_state, _field), \
536}
537
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100538#define VMSTATE_STRUCT_VARRAY_POINTER_INT32(_field, _state, _field_num, _vmsd, _type) { \
539 .name = (stringify(_field)), \
540 .version_id = 0, \
541 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
542 .size = sizeof(_type), \
543 .vmsd = &(_vmsd), \
544 .flags = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \
545 .offset = vmstate_offset_pointer(_state, _field, _type), \
546}
547
David Gibson8474a9d2013-03-12 14:06:03 +1100548#define VMSTATE_STRUCT_VARRAY_POINTER_UINT32(_field, _state, _field_num, _vmsd, _type) { \
549 .name = (stringify(_field)), \
550 .version_id = 0, \
551 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
552 .size = sizeof(_type), \
553 .vmsd = &(_vmsd), \
554 .flags = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \
555 .offset = vmstate_offset_pointer(_state, _field, _type), \
556}
557
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100558#define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, _vmsd, _type) { \
559 .name = (stringify(_field)), \
560 .version_id = 0, \
561 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
562 .size = sizeof(_type), \
563 .vmsd = &(_vmsd), \
564 .flags = VMS_POINTER | VMS_VARRAY_UINT16 | VMS_STRUCT, \
565 .offset = vmstate_offset_pointer(_state, _field, _type), \
566}
567
568#define VMSTATE_STRUCT_VARRAY_INT32(_field, _state, _field_num, _version, _vmsd, _type) { \
569 .name = (stringify(_field)), \
570 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
571 .version_id = (_version), \
572 .vmsd = &(_vmsd), \
573 .size = sizeof(_type), \
574 .flags = VMS_STRUCT|VMS_VARRAY_INT32, \
575 .offset = offsetof(_state, _field), \
576}
577
578#define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version, _vmsd, _type) { \
579 .name = (stringify(_field)), \
580 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t), \
581 .version_id = (_version), \
582 .vmsd = &(_vmsd), \
583 .size = sizeof(_type), \
584 .flags = VMS_STRUCT|VMS_VARRAY_UINT32, \
585 .offset = offsetof(_state, _field), \
586}
587
Alexey Kardashevskiyf32935e2014-05-30 19:34:19 +1000588#define VMSTATE_STRUCT_VARRAY_ALLOC(_field, _state, _field_num, _version, _vmsd, _type) {\
589 .name = (stringify(_field)), \
590 .version_id = (_version), \
591 .vmsd = &(_vmsd), \
592 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
593 .size = sizeof(_type), \
594 .flags = VMS_STRUCT|VMS_VARRAY_INT32|VMS_ALLOC|VMS_POINTER, \
595 .offset = vmstate_offset_pointer(_state, _field, _type), \
596}
597
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100598#define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \
599 .name = (stringify(_field)), \
600 .version_id = (_version), \
601 .field_exists = (_test), \
602 .size = (_size - _start), \
603 .info = &vmstate_info_buffer, \
604 .flags = VMS_BUFFER, \
605 .offset = vmstate_offset_buffer(_state, _field) + _start, \
606}
607
Halil Pasic59046ec2017-02-03 18:52:17 +0100608#define VMSTATE_VBUFFER_MULTIPLY(_field, _state, _version, _test, \
609 _field_size, _multiply) { \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100610 .name = (stringify(_field)), \
611 .version_id = (_version), \
612 .field_exists = (_test), \
613 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\
614 .size = (_multiply), \
615 .info = &vmstate_info_buffer, \
David Gibson377e2cb2013-03-12 14:06:04 +1100616 .flags = VMS_VBUFFER|VMS_POINTER|VMS_MULTIPLY, \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100617 .offset = offsetof(_state, _field), \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100618}
619
Halil Pasic59046ec2017-02-03 18:52:17 +0100620#define VMSTATE_VBUFFER(_field, _state, _version, _test, _field_size) { \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100621 .name = (stringify(_field)), \
622 .version_id = (_version), \
623 .field_exists = (_test), \
624 .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\
625 .info = &vmstate_info_buffer, \
626 .flags = VMS_VBUFFER|VMS_POINTER, \
627 .offset = offsetof(_state, _field), \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100628}
629
Halil Pasic59046ec2017-02-03 18:52:17 +0100630#define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _field_size) { \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100631 .name = (stringify(_field)), \
632 .version_id = (_version), \
633 .field_exists = (_test), \
634 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\
635 .info = &vmstate_info_buffer, \
636 .flags = VMS_VBUFFER|VMS_POINTER, \
637 .offset = offsetof(_state, _field), \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100638}
639
Halil Pasic59046ec2017-02-03 18:52:17 +0100640#define VMSTATE_VBUFFER_ALLOC_UINT32(_field, _state, _version, \
641 _test, _field_size) { \
Alexey Kardashevskiy94ed7062014-10-02 19:56:02 +1000642 .name = (stringify(_field)), \
643 .version_id = (_version), \
644 .field_exists = (_test), \
645 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\
646 .info = &vmstate_info_buffer, \
647 .flags = VMS_VBUFFER|VMS_POINTER|VMS_ALLOC, \
648 .offset = offsetof(_state, _field), \
Alexey Kardashevskiy94ed7062014-10-02 19:56:02 +1000649}
650
Laszlo Ersek9df0b0e2015-06-19 04:40:08 +0200651#define VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, _test, _version, _info, _size) { \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100652 .name = (stringify(_field)), \
653 .version_id = (_version), \
Laszlo Ersek9df0b0e2015-06-19 04:40:08 +0200654 .field_exists = (_test), \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100655 .size = (_size), \
656 .info = &(_info), \
657 .flags = VMS_BUFFER, \
658 .offset = offsetof(_state, _field), \
659}
660
Igor Mitsyanko80705682013-04-05 16:17:58 +0100661#define VMSTATE_BUFFER_POINTER_UNSAFE(_field, _state, _version, _size) { \
662 .name = (stringify(_field)), \
663 .version_id = (_version), \
664 .size = (_size), \
665 .info = &vmstate_info_buffer, \
666 .flags = VMS_BUFFER|VMS_POINTER, \
667 .offset = offsetof(_state, _field), \
668}
669
Dr. David Alan Gilbertbcf45132017-02-03 16:06:49 +0000670/* Allocate a temporary of type 'tmp_type', set tmp->parent to _state
671 * and execute the vmsd on the temporary. Note that we're working with
672 * the whole of _state here, not a field within it.
673 * We compile time check that:
674 * That _tmp_type contains a 'parent' member that's a pointer to the
675 * '_state' type
676 * That the pointer is right at the start of _tmp_type.
677 */
678#define VMSTATE_WITH_TMP(_state, _tmp_type, _vmsd) { \
679 .name = "tmp", \
680 .size = sizeof(_tmp_type) + \
681 QEMU_BUILD_BUG_ON_ZERO(offsetof(_tmp_type, parent) != 0) + \
682 type_check_pointer(_state, \
683 typeof_field(_tmp_type, parent)), \
684 .vmsd = &(_vmsd), \
685 .info = &vmstate_info_tmp, \
686}
687
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100688#define VMSTATE_UNUSED_BUFFER(_test, _version, _size) { \
689 .name = "unused", \
690 .field_exists = (_test), \
691 .version_id = (_version), \
692 .size = (_size), \
693 .info = &vmstate_info_unused_buffer, \
694 .flags = VMS_BUFFER, \
695}
696
Dr. David Alan Gilbertb5b5c562017-02-03 16:06:48 +0000697/* Discard size * field_num bytes, where field_num is a uint32 member */
698#define VMSTATE_UNUSED_VARRAY_UINT32(_state, _test, _version, _field_num, _size) {\
699 .name = "unused", \
700 .field_exists = (_test), \
701 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
702 .version_id = (_version), \
703 .size = (_size), \
704 .info = &vmstate_info_unused_buffer, \
705 .flags = VMS_VARRAY_UINT32 | VMS_BUFFER, \
706}
707
Peter Maydell08e99e22012-10-30 07:45:12 +0000708/* _field_size should be a int32_t field in the _state struct giving the
709 * size of the bitmap _field in bits.
710 */
711#define VMSTATE_BITMAP(_field, _state, _version, _field_size) { \
712 .name = (stringify(_field)), \
713 .version_id = (_version), \
714 .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\
715 .info = &vmstate_info_bitmap, \
716 .flags = VMS_VBUFFER|VMS_POINTER, \
717 .offset = offsetof(_state, _field), \
718}
719
Jianjun Duan94869d52017-01-19 11:00:51 -0800720/* For migrating a QTAILQ.
721 * Target QTAILQ needs be properly initialized.
722 * _type: type of QTAILQ element
723 * _next: name of QTAILQ entry field in QTAILQ element
724 * _vmsd: VMSD for QTAILQ element
725 * size: size of QTAILQ element
726 * start: offset of QTAILQ entry in QTAILQ element
727 */
728#define VMSTATE_QTAILQ_V(_field, _state, _version, _vmsd, _type, _next) \
729{ \
730 .name = (stringify(_field)), \
731 .version_id = (_version), \
732 .vmsd = &(_vmsd), \
733 .size = sizeof(_type), \
734 .info = &vmstate_info_qtailq, \
735 .offset = offsetof(_state, _field), \
736 .start = offsetof(_type, _next), \
737}
738
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100739/* _f : field name
740 _f_n : num of elements field_name
741 _n : num of elements
742 _s : struct state name
743 _v : version
744*/
745
746#define VMSTATE_SINGLE(_field, _state, _version, _info, _type) \
747 VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type)
748
Corey Minyard2dc66602018-04-25 10:27:30 -0500749#define VMSTATE_VSTRUCT(_field, _state, _vmsd, _type, _struct_version)\
750 VMSTATE_VSTRUCT_TEST(_field, _state, NULL, 0, _vmsd, _type, _struct_version)
751
752#define VMSTATE_VSTRUCT_V(_field, _state, _version, _vmsd, _type, _struct_version) \
753 VMSTATE_VSTRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type, \
754 _struct_version)
755
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100756#define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) \
757 VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type)
758
759#define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type) \
Alexey Kardashevskiy71024002013-09-04 14:35:26 +1000760 VMSTATE_STRUCT_POINTER_V(_field, _state, 0, _vmsd, _type)
761
762#define VMSTATE_STRUCT_POINTER_TEST(_field, _state, _test, _vmsd, _type) \
763 VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, 0, _vmsd, _type)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100764
765#define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) \
766 VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version, \
767 _vmsd, _type)
768
Stafford Horneb75c9582017-04-16 19:43:23 +0900769#define VMSTATE_STRUCT_2DARRAY(_field, _state, _n1, _n2, _version, \
770 _vmsd, _type) \
771 VMSTATE_STRUCT_2DARRAY_TEST(_field, _state, _n1, _n2, NULL, \
772 _version, _vmsd, _type)
773
Laszlo Ersek9df0b0e2015-06-19 04:40:08 +0200774#define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) \
775 VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, NULL, _version, _info, \
776 _size)
777
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100778#define VMSTATE_BOOL_V(_f, _s, _v) \
779 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool)
780
781#define VMSTATE_INT8_V(_f, _s, _v) \
782 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t)
783#define VMSTATE_INT16_V(_f, _s, _v) \
784 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t)
785#define VMSTATE_INT32_V(_f, _s, _v) \
786 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t)
787#define VMSTATE_INT64_V(_f, _s, _v) \
788 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t)
789
790#define VMSTATE_UINT8_V(_f, _s, _v) \
791 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t)
792#define VMSTATE_UINT16_V(_f, _s, _v) \
793 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t)
794#define VMSTATE_UINT32_V(_f, _s, _v) \
795 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t)
796#define VMSTATE_UINT64_V(_f, _s, _v) \
797 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t)
798
799#define VMSTATE_BOOL(_f, _s) \
800 VMSTATE_BOOL_V(_f, _s, 0)
801
802#define VMSTATE_INT8(_f, _s) \
803 VMSTATE_INT8_V(_f, _s, 0)
804#define VMSTATE_INT16(_f, _s) \
805 VMSTATE_INT16_V(_f, _s, 0)
806#define VMSTATE_INT32(_f, _s) \
807 VMSTATE_INT32_V(_f, _s, 0)
808#define VMSTATE_INT64(_f, _s) \
809 VMSTATE_INT64_V(_f, _s, 0)
810
811#define VMSTATE_UINT8(_f, _s) \
812 VMSTATE_UINT8_V(_f, _s, 0)
813#define VMSTATE_UINT16(_f, _s) \
814 VMSTATE_UINT16_V(_f, _s, 0)
815#define VMSTATE_UINT32(_f, _s) \
816 VMSTATE_UINT32_V(_f, _s, 0)
817#define VMSTATE_UINT64(_f, _s) \
818 VMSTATE_UINT64_V(_f, _s, 0)
819
Halil Pasicd2164ad2017-06-23 16:48:23 +0200820#define VMSTATE_UINT8_EQUAL(_f, _s, _err_hint) \
821 VMSTATE_SINGLE_FULL(_f, _s, 0, 0, \
822 vmstate_info_uint8_equal, uint8_t, _err_hint)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100823
Halil Pasicd2164ad2017-06-23 16:48:23 +0200824#define VMSTATE_UINT16_EQUAL(_f, _s, _err_hint) \
825 VMSTATE_SINGLE_FULL(_f, _s, 0, 0, \
826 vmstate_info_uint16_equal, uint16_t, _err_hint)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100827
Halil Pasicd2164ad2017-06-23 16:48:23 +0200828#define VMSTATE_UINT16_EQUAL_V(_f, _s, _v, _err_hint) \
829 VMSTATE_SINGLE_FULL(_f, _s, 0, _v, \
830 vmstate_info_uint16_equal, uint16_t, _err_hint)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100831
Halil Pasicd2164ad2017-06-23 16:48:23 +0200832#define VMSTATE_INT32_EQUAL(_f, _s, _err_hint) \
833 VMSTATE_SINGLE_FULL(_f, _s, 0, 0, \
834 vmstate_info_int32_equal, int32_t, _err_hint)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100835
Halil Pasicd2164ad2017-06-23 16:48:23 +0200836#define VMSTATE_UINT32_EQUAL_V(_f, _s, _v, _err_hint) \
837 VMSTATE_SINGLE_FULL(_f, _s, 0, _v, \
838 vmstate_info_uint32_equal, uint32_t, _err_hint)
David Gibsond58f5592013-03-12 14:06:01 +1100839
Halil Pasicd2164ad2017-06-23 16:48:23 +0200840#define VMSTATE_UINT32_EQUAL(_f, _s, _err_hint) \
841 VMSTATE_UINT32_EQUAL_V(_f, _s, 0, _err_hint)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100842
Halil Pasicd2164ad2017-06-23 16:48:23 +0200843#define VMSTATE_UINT64_EQUAL_V(_f, _s, _v, _err_hint) \
844 VMSTATE_SINGLE_FULL(_f, _s, 0, _v, \
845 vmstate_info_uint64_equal, uint64_t, _err_hint)
David Gibsone344b8a2013-03-12 14:06:00 +1100846
Halil Pasicd2164ad2017-06-23 16:48:23 +0200847#define VMSTATE_UINT64_EQUAL(_f, _s, _err_hint) \
848 VMSTATE_UINT64_EQUAL_V(_f, _s, 0, _err_hint)
David Gibsone344b8a2013-03-12 14:06:00 +1100849
Michael S. Tsirkin34764362014-04-03 19:52:21 +0300850#define VMSTATE_INT32_POSITIVE_LE(_f, _s) \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100851 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
852
David Gibson87774a42015-02-06 14:55:46 +1100853#define VMSTATE_INT8_TEST(_f, _s, _t) \
854 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int8, int8_t)
855
856#define VMSTATE_INT16_TEST(_f, _s, _t) \
857 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int16, int16_t)
858
859#define VMSTATE_INT32_TEST(_f, _s, _t) \
860 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int32, int32_t)
861
862#define VMSTATE_INT64_TEST(_f, _s, _t) \
863 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int64, int64_t)
864
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100865#define VMSTATE_UINT8_TEST(_f, _s, _t) \
866 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t)
867
868#define VMSTATE_UINT16_TEST(_f, _s, _t) \
869 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
870
871#define VMSTATE_UINT32_TEST(_f, _s, _t) \
872 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)
873
David Gibson87774a42015-02-06 14:55:46 +1100874#define VMSTATE_UINT64_TEST(_f, _s, _t) \
875 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint64, uint64_t)
876
David Gibson213945e2013-03-12 14:06:02 +1100877
878#define VMSTATE_FLOAT64_V(_f, _s, _v) \
879 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_float64, float64)
880
881#define VMSTATE_FLOAT64(_f, _s) \
882 VMSTATE_FLOAT64_V(_f, _s, 0)
883
Paolo Bonzinie7206772015-01-08 10:18:59 +0100884#define VMSTATE_TIMER_PTR_TEST(_f, _s, _test) \
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100885 VMSTATE_POINTER_TEST(_f, _s, _test, vmstate_info_timer, QEMUTimer *)
886
Paolo Bonzinie7206772015-01-08 10:18:59 +0100887#define VMSTATE_TIMER_PTR_V(_f, _s, _v) \
Paolo Bonzini02815182012-08-02 18:04:08 +0200888 VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *)
889
Paolo Bonzinie7206772015-01-08 10:18:59 +0100890#define VMSTATE_TIMER_PTR(_f, _s) \
891 VMSTATE_TIMER_PTR_V(_f, _s, 0)
892
893#define VMSTATE_TIMER_PTR_ARRAY(_f, _s, _n) \
894 VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *)
895
896#define VMSTATE_TIMER_TEST(_f, _s, _test) \
897 VMSTATE_SINGLE_TEST(_f, _s, _test, 0, vmstate_info_timer, QEMUTimer)
898
899#define VMSTATE_TIMER_V(_f, _s, _v) \
900 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_timer, QEMUTimer)
901
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100902#define VMSTATE_TIMER(_f, _s) \
Paolo Bonzini02815182012-08-02 18:04:08 +0200903 VMSTATE_TIMER_V(_f, _s, 0)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100904
905#define VMSTATE_TIMER_ARRAY(_f, _s, _n) \
Paolo Bonzinie7206772015-01-08 10:18:59 +0100906 VMSTATE_ARRAY(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer)
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100907
908#define VMSTATE_BOOL_ARRAY_V(_f, _s, _n, _v) \
909 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_bool, bool)
910
911#define VMSTATE_BOOL_ARRAY(_f, _s, _n) \
912 VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0)
913
Peter Maydelle0a37e22018-05-31 14:50:53 +0100914#define VMSTATE_BOOL_SUB_ARRAY(_f, _s, _start, _num) \
915 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_bool, bool)
916
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100917#define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v) \
918 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t)
919
Peter Maydellbd7f92e2013-04-05 16:17:59 +0100920#define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v) \
921 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t)
922
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100923#define VMSTATE_UINT16_ARRAY(_f, _s, _n) \
924 VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0)
925
Luc Michelb77473a2018-08-14 17:17:20 +0100926#define VMSTATE_UINT16_SUB_ARRAY(_f, _s, _start, _num) \
927 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint16, uint16_t)
928
Peter Maydellbd7f92e2013-04-05 16:17:59 +0100929#define VMSTATE_UINT16_2DARRAY(_f, _s, _n1, _n2) \
930 VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, 0)
931
932#define VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, _v) \
933 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint8, uint8_t)
934
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100935#define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v) \
936 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t)
937
938#define VMSTATE_UINT8_ARRAY(_f, _s, _n) \
939 VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0)
940
Fam Zheng2e323f02014-03-06 16:26:02 +0800941#define VMSTATE_UINT8_SUB_ARRAY(_f, _s, _start, _num) \
942 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint8, uint8_t)
943
Peter Maydellbd7f92e2013-04-05 16:17:59 +0100944#define VMSTATE_UINT8_2DARRAY(_f, _s, _n1, _n2) \
945 VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, 0)
946
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100947#define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v) \
948 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t)
949
Christoffer Dalla1b1d272013-09-20 20:35:06 +0100950#define VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, _v) \
951 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint32, uint32_t)
952
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100953#define VMSTATE_UINT32_ARRAY(_f, _s, _n) \
954 VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
955
Richard Hendersona006f122018-01-25 11:45:29 +0000956#define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num) \
957 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t)
958
Christoffer Dalla1b1d272013-09-20 20:35:06 +0100959#define VMSTATE_UINT32_2DARRAY(_f, _s, _n1, _n2) \
960 VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, 0)
961
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100962#define VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v) \
963 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint64, uint64_t)
964
965#define VMSTATE_UINT64_ARRAY(_f, _s, _n) \
966 VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0)
967
Richard Hendersona006f122018-01-25 11:45:29 +0000968#define VMSTATE_UINT64_SUB_ARRAY(_f, _s, _start, _num) \
969 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint64, uint64_t)
970
Peter Maydell04716bc2016-06-17 15:23:45 +0100971#define VMSTATE_UINT64_2DARRAY(_f, _s, _n1, _n2) \
972 VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, 0)
973
974#define VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, _v) \
975 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint64, uint64_t)
976
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100977#define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v) \
978 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t)
979
980#define VMSTATE_INT16_ARRAY(_f, _s, _n) \
981 VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0)
982
983#define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v) \
984 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t)
985
986#define VMSTATE_INT32_ARRAY(_f, _s, _n) \
987 VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0)
988
Paolo Bonzini701a8f72012-01-13 17:07:20 +0100989#define VMSTATE_INT64_ARRAY_V(_f, _s, _n, _v) \
990 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int64, int64_t)
991
992#define VMSTATE_INT64_ARRAY(_f, _s, _n) \
993 VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0)
994
David Gibson213945e2013-03-12 14:06:02 +1100995#define VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, _v) \
996 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_float64, float64)
997
998#define VMSTATE_FLOAT64_ARRAY(_f, _s, _n) \
999 VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, 0)
1000
Juan Quintela55174742016-01-11 12:40:21 +00001001#define VMSTATE_CPUDOUBLE_ARRAY_V(_f, _s, _n, _v) \
1002 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_cpudouble, CPU_DoubleU)
1003
1004#define VMSTATE_CPUDOUBLE_ARRAY(_f, _s, _n) \
1005 VMSTATE_CPUDOUBLE_ARRAY_V(_f, _s, _n, 0)
1006
Paolo Bonzini701a8f72012-01-13 17:07:20 +01001007#define VMSTATE_BUFFER_V(_f, _s, _v) \
1008 VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f)))
1009
1010#define VMSTATE_BUFFER(_f, _s) \
1011 VMSTATE_BUFFER_V(_f, _s, 0)
1012
1013#define VMSTATE_PARTIAL_BUFFER(_f, _s, _size) \
1014 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, _size)
1015
Paolo Bonzinicc966772016-06-20 16:32:39 +02001016#define VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, _v) \
1017 VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, _start, sizeof(typeof_field(_s, _f)))
1018
Paolo Bonzini701a8f72012-01-13 17:07:20 +01001019#define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \
Paolo Bonzinicc966772016-06-20 16:32:39 +02001020 VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, 0)
Paolo Bonzini701a8f72012-01-13 17:07:20 +01001021
1022#define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size) \
Halil Pasic59046ec2017-02-03 18:52:17 +01001023 VMSTATE_VBUFFER(_f, _s, 0, NULL, _size)
Paolo Bonzini701a8f72012-01-13 17:07:20 +01001024
1025#define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size) \
Halil Pasic59046ec2017-02-03 18:52:17 +01001026 VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, _size)
Paolo Bonzini701a8f72012-01-13 17:07:20 +01001027
1028#define VMSTATE_BUFFER_TEST(_f, _s, _test) \
1029 VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f)))
1030
1031#define VMSTATE_BUFFER_UNSAFE(_field, _state, _version, _size) \
1032 VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, _size)
1033
1034#define VMSTATE_UNUSED_V(_v, _size) \
1035 VMSTATE_UNUSED_BUFFER(NULL, _v, _size)
1036
1037#define VMSTATE_UNUSED(_size) \
1038 VMSTATE_UNUSED_V(0, _size)
1039
1040#define VMSTATE_UNUSED_TEST(_test, _size) \
1041 VMSTATE_UNUSED_BUFFER(_test, 0, _size)
1042
1043#define VMSTATE_END_OF_LIST() \
1044 {}
1045
1046int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
1047 void *opaque, int version_id);
Dr. David Alan Gilbert551dbd02017-09-25 12:29:13 +01001048int vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
1049 void *opaque, QJSON *vmdesc);
Corey Minyard2dc66602018-04-25 10:27:30 -05001050int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
1051 void *opaque, QJSON *vmdesc, int version_id);
Andreas Färberd7650ea2013-02-18 21:41:59 +01001052
Juan Quinteladf896152014-10-15 09:39:14 +02001053bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque);
1054
Dr. David Alan Gilbert581f08b2017-02-02 12:59:55 +00001055/* Returns: 0 on success, -1 on failure */
Paolo Bonzini701a8f72012-01-13 17:07:20 +01001056int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
1057 const VMStateDescription *vmsd,
1058 void *base, int alias_id,
Dr. David Alan Gilbertbc5c4f22017-02-02 12:59:54 +00001059 int required_for_version,
1060 Error **errp);
Andreas Färberd7650ea2013-02-18 21:41:59 +01001061
Dr. David Alan Gilbert581f08b2017-02-02 12:59:55 +00001062/* Returns: 0 on success, -1 on failure */
Andreas Färberd7650ea2013-02-18 21:41:59 +01001063static inline int vmstate_register(DeviceState *dev, int instance_id,
1064 const VMStateDescription *vmsd,
1065 void *opaque)
1066{
1067 return vmstate_register_with_alias_id(dev, instance_id, vmsd,
Dr. David Alan Gilbertbc5c4f22017-02-02 12:59:54 +00001068 opaque, -1, 0, NULL);
Andreas Färberd7650ea2013-02-18 21:41:59 +01001069}
1070
Paolo Bonzini701a8f72012-01-13 17:07:20 +01001071void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd,
1072 void *opaque);
1073
1074struct MemoryRegion;
1075void vmstate_register_ram(struct MemoryRegion *memory, DeviceState *dev);
1076void vmstate_unregister_ram(struct MemoryRegion *memory, DeviceState *dev);
1077void vmstate_register_ram_global(struct MemoryRegion *memory);
1078
Juan Quintela1bfe5f02017-04-17 14:57:54 +02001079bool vmstate_check_only_migratable(const VMStateDescription *vmsd);
1080
Paolo Bonzini701a8f72012-01-13 17:07:20 +01001081#endif