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