Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 845 lines (694 sloc) 35.194 kb
68396ea @rmustacc Initial commit of d32e8d0b8d9e0ef7cf7ab2e74548982972789dfc from qemu-kvm
rmustacc authored
1 /* Declarations for use by hardware emulation. */
36b02c7 @rmustacc HVM-588 Make sure copyright is updated in kvm-cmd
rmustacc authored
2 /* Copyright 2011 QEMU contributors */
3 /* Portions Copyright 2011 Joyent, Inc. */
68396ea @rmustacc Initial commit of d32e8d0b8d9e0ef7cf7ab2e74548982972789dfc from qemu-kvm
rmustacc authored
4 #ifndef QEMU_HW_H
5 #define QEMU_HW_H
6
7 #include "qemu-common.h"
8
9 #if defined(TARGET_PHYS_ADDR_BITS) && !defined(NEED_CPU_H)
10 #include "cpu-common.h"
11 #endif
12
13 #include "ioport.h"
14 #include "irq.h"
15
16 /* VM Load/Save */
17
18 /* This function writes a chunk of data to a file at the given position.
19 * The pos argument can be ignored if the file is only being used for
20 * streaming. The handler should try to write all of the data it can.
21 */
22 typedef int (QEMUFilePutBufferFunc)(void *opaque, const uint8_t *buf,
23 int64_t pos, int size);
24
25 /* Read a chunk of data from a file at the given position. The pos argument
26 * can be ignored if the file is only be used for streaming. The number of
27 * bytes actually read should be returned.
28 */
29 typedef int (QEMUFileGetBufferFunc)(void *opaque, uint8_t *buf,
30 int64_t pos, int size);
31
32 /* Close a file and return an error code */
33 typedef int (QEMUFileCloseFunc)(void *opaque);
34
35 /* Called to determine if the file has exceeded it's bandwidth allocation. The
36 * bandwidth capping is a soft limit, not a hard limit.
37 */
38 typedef int (QEMUFileRateLimit)(void *opaque);
39
40 /* Called to change the current bandwidth allocation. This function must return
41 * the new actual bandwidth. It should be new_rate if everything goes ok, and
42 * the old rate otherwise
43 */
44 typedef int64_t (QEMUFileSetRateLimit)(void *opaque, int64_t new_rate);
45 typedef int64_t (QEMUFileGetRateLimit)(void *opaque);
46
47 QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
48 QEMUFileGetBufferFunc *get_buffer,
49 QEMUFileCloseFunc *close,
50 QEMUFileRateLimit *rate_limit,
51 QEMUFileSetRateLimit *set_rate_limit,
52 QEMUFileGetRateLimit *get_rate_limit);
53 QEMUFile *qemu_fopen(const char *filename, const char *mode);
54 QEMUFile *qemu_fdopen(int fd, const char *mode);
55 QEMUFile *qemu_fopen_socket(int fd);
56 QEMUFile *qemu_popen(FILE *popen_file, const char *mode);
57 QEMUFile *qemu_popen_cmd(const char *command, const char *mode);
58 int qemu_stdio_fd(QEMUFile *f);
59 void qemu_fflush(QEMUFile *f);
60 int qemu_fclose(QEMUFile *f);
61 void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
62 void qemu_put_byte(QEMUFile *f, int v);
63
64 static inline void qemu_put_ubyte(QEMUFile *f, unsigned int v)
65 {
66 qemu_put_byte(f, (int)v);
67 }
68
69 #define qemu_put_sbyte qemu_put_byte
70
71 void qemu_put_be16(QEMUFile *f, unsigned int v);
72 void qemu_put_be32(QEMUFile *f, unsigned int v);
73 void qemu_put_be64(QEMUFile *f, uint64_t v);
74 int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size);
75 int qemu_get_byte(QEMUFile *f);
76
77 static inline unsigned int qemu_get_ubyte(QEMUFile *f)
78 {
79 return (unsigned int)qemu_get_byte(f);
80 }
81
82 #define qemu_get_sbyte qemu_get_byte
83
84 unsigned int qemu_get_be16(QEMUFile *f);
85 unsigned int qemu_get_be32(QEMUFile *f);
86 uint64_t qemu_get_be64(QEMUFile *f);
87 int qemu_file_rate_limit(QEMUFile *f);
88 int64_t qemu_file_set_rate_limit(QEMUFile *f, int64_t new_rate);
89 int64_t qemu_file_get_rate_limit(QEMUFile *f);
90 int qemu_file_has_error(QEMUFile *f);
91 void qemu_file_set_error(QEMUFile *f);
92
93 /* Try to send any outstanding data. This function is useful when output is
94 * halted due to rate limiting or EAGAIN errors occur as it can be used to
95 * resume output. */
96 void qemu_file_put_notify(QEMUFile *f);
97
98 static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
99 {
100 qemu_put_be64(f, *pv);
101 }
102
103 static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv)
104 {
105 qemu_put_be32(f, *pv);
106 }
107
108 static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv)
109 {
110 qemu_put_be16(f, *pv);
111 }
112
113 static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv)
114 {
115 qemu_put_byte(f, *pv);
116 }
117
118 static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv)
119 {
120 *pv = qemu_get_be64(f);
121 }
122
123 static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv)
124 {
125 *pv = qemu_get_be32(f);
126 }
127
128 static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv)
129 {
130 *pv = qemu_get_be16(f);
131 }
132
133 static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv)
134 {
135 *pv = qemu_get_byte(f);
136 }
137
138 // Signed versions for type safety
139 static inline void qemu_put_sbuffer(QEMUFile *f, const int8_t *buf, int size)
140 {
141 qemu_put_buffer(f, (const uint8_t *)buf, size);
142 }
143
144 static inline void qemu_put_sbe16(QEMUFile *f, int v)
145 {
146 qemu_put_be16(f, (unsigned int)v);
147 }
148
149 static inline void qemu_put_sbe32(QEMUFile *f, int v)
150 {
151 qemu_put_be32(f, (unsigned int)v);
152 }
153
154 static inline void qemu_put_sbe64(QEMUFile *f, int64_t v)
155 {
156 qemu_put_be64(f, (uint64_t)v);
157 }
158
159 static inline size_t qemu_get_sbuffer(QEMUFile *f, int8_t *buf, int size)
160 {
161 return qemu_get_buffer(f, (uint8_t *)buf, size);
162 }
163
164 static inline int qemu_get_sbe16(QEMUFile *f)
165 {
166 return (int)qemu_get_be16(f);
167 }
168
169 static inline int qemu_get_sbe32(QEMUFile *f)
170 {
171 return (int)qemu_get_be32(f);
172 }
173
174 static inline int64_t qemu_get_sbe64(QEMUFile *f)
175 {
176 return (int64_t)qemu_get_be64(f);
177 }
178
179 static inline void qemu_put_s8s(QEMUFile *f, const int8_t *pv)
180 {
181 qemu_put_8s(f, (const uint8_t *)pv);
182 }
183
184 static inline void qemu_put_sbe16s(QEMUFile *f, const int16_t *pv)
185 {
186 qemu_put_be16s(f, (const uint16_t *)pv);
187 }
188
189 static inline void qemu_put_sbe32s(QEMUFile *f, const int32_t *pv)
190 {
191 qemu_put_be32s(f, (const uint32_t *)pv);
192 }
193
194 static inline void qemu_put_sbe64s(QEMUFile *f, const int64_t *pv)
195 {
196 qemu_put_be64s(f, (const uint64_t *)pv);
197 }
198
199 static inline void qemu_get_s8s(QEMUFile *f, int8_t *pv)
200 {
201 qemu_get_8s(f, (uint8_t *)pv);
202 }
203
204 static inline void qemu_get_sbe16s(QEMUFile *f, int16_t *pv)
205 {
206 qemu_get_be16s(f, (uint16_t *)pv);
207 }
208
209 static inline void qemu_get_sbe32s(QEMUFile *f, int32_t *pv)
210 {
211 qemu_get_be32s(f, (uint32_t *)pv);
212 }
213
214 static inline void qemu_get_sbe64s(QEMUFile *f, int64_t *pv)
215 {
216 qemu_get_be64s(f, (uint64_t *)pv);
217 }
218
219 #ifdef NEED_CPU_H
220 #if TARGET_LONG_BITS == 64
221 #define qemu_put_betl qemu_put_be64
222 #define qemu_get_betl qemu_get_be64
223 #define qemu_put_betls qemu_put_be64s
224 #define qemu_get_betls qemu_get_be64s
225 #define qemu_put_sbetl qemu_put_sbe64
226 #define qemu_get_sbetl qemu_get_sbe64
227 #define qemu_put_sbetls qemu_put_sbe64s
228 #define qemu_get_sbetls qemu_get_sbe64s
229 #else
230 #define qemu_put_betl qemu_put_be32
231 #define qemu_get_betl qemu_get_be32
232 #define qemu_put_betls qemu_put_be32s
233 #define qemu_get_betls qemu_get_be32s
234 #define qemu_put_sbetl qemu_put_sbe32
235 #define qemu_get_sbetl qemu_get_sbe32
236 #define qemu_put_sbetls qemu_put_sbe32s
237 #define qemu_get_sbetls qemu_get_sbe32s
238 #endif
239 #endif
240
241 int64_t qemu_ftell(QEMUFile *f);
242 int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence);
243
244 typedef void SaveSetParamsHandler(int blk_enable, int shared, void * opaque);
245 typedef void SaveStateHandler(QEMUFile *f, void *opaque);
246 typedef int SaveLiveStateHandler(Monitor *mon, QEMUFile *f, int stage,
247 void *opaque);
248 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
249
250 int register_savevm(DeviceState *dev,
251 const char *idstr,
252 int instance_id,
253 int version_id,
254 SaveStateHandler *save_state,
255 LoadStateHandler *load_state,
256 void *opaque);
257
258 int register_savevm_live(DeviceState *dev,
259 const char *idstr,
260 int instance_id,
261 int version_id,
262 SaveSetParamsHandler *set_params,
263 SaveLiveStateHandler *save_live_state,
264 SaveStateHandler *save_state,
265 LoadStateHandler *load_state,
266 void *opaque);
267
268 void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque);
269 void register_device_unmigratable(DeviceState *dev, const char *idstr,
270 void *opaque);
271
272 typedef void QEMUResetHandler(void *opaque);
273
274 void qemu_register_reset(QEMUResetHandler *func, void *opaque);
275 void qemu_unregister_reset(QEMUResetHandler *func, void *opaque);
276
277 /* handler to set the boot_device order for a specific type of QEMUMachine */
278 /* return 0 if success */
279 typedef int QEMUBootSetHandler(void *opaque, const char *boot_devices);
280 void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque);
281 int qemu_boot_set(const char *boot_devices);
282
283 typedef struct VMStateInfo VMStateInfo;
284 typedef struct VMStateDescription VMStateDescription;
285
286 struct VMStateInfo {
287 const char *name;
288 int (*get)(QEMUFile *f, void *pv, size_t size);
289 void (*put)(QEMUFile *f, void *pv, size_t size);
290 };
291
292 enum VMStateFlags {
293 VMS_SINGLE = 0x001,
294 VMS_POINTER = 0x002,
295 VMS_ARRAY = 0x004,
296 VMS_STRUCT = 0x008,
297 VMS_VARRAY_INT32 = 0x010, /* Array with size in int32_t field*/
298 VMS_BUFFER = 0x020, /* static sized buffer */
299 VMS_ARRAY_OF_POINTER = 0x040,
300 VMS_VARRAY_UINT16 = 0x080, /* Array with size in uint16_t field */
301 VMS_VBUFFER = 0x100, /* Buffer with size in int32_t field */
302 VMS_MULTIPLY = 0x200, /* multiply "size" field by field_size */
303 };
304
305 typedef struct {
306 const char *name;
307 size_t offset;
308 size_t size;
309 size_t start;
310 int num;
311 size_t num_offset;
312 size_t size_offset;
313 const VMStateInfo *info;
314 enum VMStateFlags flags;
315 const VMStateDescription *vmsd;
316 int version_id;
317 bool (*field_exists)(void *opaque, int version_id);
318 } VMStateField;
319
320 typedef struct VMStateSubsection {
321 const VMStateDescription *vmsd;
322 bool (*needed)(void *opaque);
323 } VMStateSubsection;
324
325 struct VMStateDescription {
326 const char *name;
327 int version_id;
328 int minimum_version_id;
329 int minimum_version_id_old;
330 LoadStateHandler *load_state_old;
331 int (*pre_load)(void *opaque);
332 int (*post_load)(void *opaque, int version_id);
333 void (*pre_save)(void *opaque);
334 VMStateField *fields;
335 const VMStateSubsection *subsections;
336 };
337
338 extern const VMStateInfo vmstate_info_bool;
339
340 extern const VMStateInfo vmstate_info_int8;
341 extern const VMStateInfo vmstate_info_int16;
342 extern const VMStateInfo vmstate_info_int32;
343 extern const VMStateInfo vmstate_info_int64;
344
345 extern const VMStateInfo vmstate_info_uint8_equal;
346 extern const VMStateInfo vmstate_info_uint16_equal;
347 extern const VMStateInfo vmstate_info_int32_equal;
348 extern const VMStateInfo vmstate_info_int32_le;
349
350 extern const VMStateInfo vmstate_info_uint8;
351 extern const VMStateInfo vmstate_info_uint16;
352 extern const VMStateInfo vmstate_info_uint32;
353 extern const VMStateInfo vmstate_info_uint64;
354
fa9a236 @rmustacc HVM-388 Run native kvm with qemu-v0.14.x
rmustacc authored
355 #if defined(__linux__) || defined(__sun__)
68396ea @rmustacc Initial commit of d32e8d0b8d9e0ef7cf7ab2e74548982972789dfc from qemu-kvm
rmustacc authored
356 extern const VMStateInfo vmstate_info_u64;
357 #endif
358
359 extern const VMStateInfo vmstate_info_timer;
360 extern const VMStateInfo vmstate_info_ptimer;
361 extern const VMStateInfo vmstate_info_buffer;
362 extern const VMStateInfo vmstate_info_unused_buffer;
363
364 #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
365 #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
366
367 #define vmstate_offset_value(_state, _field, _type) \
368 (offsetof(_state, _field) + \
369 type_check(_type, typeof_field(_state, _field)))
370
371 #define vmstate_offset_pointer(_state, _field, _type) \
372 (offsetof(_state, _field) + \
373 type_check_pointer(_type, typeof_field(_state, _field)))
374
375 #define vmstate_offset_array(_state, _field, _type, _num) \
376 (offsetof(_state, _field) + \
377 type_check_array(_type, typeof_field(_state, _field), _num))
378
379 #define vmstate_offset_sub_array(_state, _field, _type, _start) \
380 (offsetof(_state, _field[_start]))
381
382 #define vmstate_offset_buffer(_state, _field) \
383 vmstate_offset_array(_state, _field, uint8_t, \
384 sizeof(typeof_field(_state, _field)))
385
386 #define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \
387 .name = (stringify(_field)), \
388 .version_id = (_version), \
389 .field_exists = (_test), \
390 .size = sizeof(_type), \
391 .info = &(_info), \
392 .flags = VMS_SINGLE, \
393 .offset = vmstate_offset_value(_state, _field, _type), \
394 }
395
396 #define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \
397 .name = (stringify(_field)), \
398 .version_id = (_version), \
399 .info = &(_info), \
400 .size = sizeof(_type), \
401 .flags = VMS_SINGLE|VMS_POINTER, \
402 .offset = vmstate_offset_value(_state, _field, _type), \
403 }
404
405 #define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\
406 .name = (stringify(_field)), \
407 .version_id = (_version), \
408 .num = (_num), \
409 .info = &(_info), \
410 .size = sizeof(_type), \
411 .flags = VMS_ARRAY, \
412 .offset = vmstate_offset_array(_state, _field, _type, _num), \
413 }
414
415 #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
416 .name = (stringify(_field)), \
417 .field_exists = (_test), \
418 .num = (_num), \
419 .info = &(_info), \
420 .size = sizeof(_type), \
421 .flags = VMS_ARRAY, \
422 .offset = vmstate_offset_array(_state, _field, _type, _num),\
423 }
424
425 #define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \
426 .name = (stringify(_field)), \
427 .version_id = (_version), \
428 .num = (_num), \
429 .info = &(_info), \
430 .size = sizeof(_type), \
431 .flags = VMS_ARRAY, \
432 .offset = vmstate_offset_sub_array(_state, _field, _type, _start), \
433 }
434
435 #define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\
436 .name = (stringify(_field)), \
437 .version_id = (_version), \
438 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
439 .info = &(_info), \
440 .size = sizeof(_type), \
441 .flags = VMS_VARRAY_INT32|VMS_POINTER, \
442 .offset = vmstate_offset_pointer(_state, _field, _type), \
443 }
444
445 #define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version, _info, _type) {\
446 .name = (stringify(_field)), \
447 .version_id = (_version), \
448 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
449 .info = &(_info), \
450 .size = sizeof(_type), \
451 .flags = VMS_VARRAY_UINT16, \
452 .offset = offsetof(_state, _field), \
453 }
454
455 #define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \
456 .name = (stringify(_field)), \
457 .version_id = (_version), \
458 .field_exists = (_test), \
459 .vmsd = &(_vmsd), \
460 .size = sizeof(_type), \
461 .flags = VMS_STRUCT, \
462 .offset = vmstate_offset_value(_state, _field, _type), \
463 }
464
465 #define VMSTATE_STRUCT_POINTER_TEST(_field, _state, _test, _vmsd, _type) { \
466 .name = (stringify(_field)), \
467 .field_exists = (_test), \
468 .vmsd = &(_vmsd), \
469 .size = sizeof(_type), \
470 .flags = VMS_STRUCT|VMS_POINTER, \
471 .offset = vmstate_offset_value(_state, _field, _type), \
472 }
473
474 #define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) {\
475 .name = (stringify(_field)), \
476 .version_id = (_version), \
477 .num = (_num), \
478 .info = &(_info), \
479 .size = sizeof(_type), \
480 .flags = VMS_ARRAY|VMS_ARRAY_OF_POINTER, \
481 .offset = vmstate_offset_array(_state, _field, _type, _num), \
482 }
483
484 #define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) { \
485 .name = (stringify(_field)), \
486 .num = (_num), \
487 .version_id = (_version), \
488 .vmsd = &(_vmsd), \
489 .size = sizeof(_type), \
490 .flags = VMS_STRUCT|VMS_ARRAY, \
491 .offset = vmstate_offset_array(_state, _field, _type, _num), \
492 }
493
494 #define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, _vmsd, _type) { \
495 .name = (stringify(_field)), \
496 .num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \
497 .version_id = (_version), \
498 .vmsd = &(_vmsd), \
499 .size = sizeof(_type), \
500 .flags = VMS_STRUCT|VMS_VARRAY_INT32, \
501 .offset = offsetof(_state, _field), \
502 }
503
504 #define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \
505 .name = (stringify(_field)), \
506 .version_id = (_version), \
507 .field_exists = (_test), \
508 .size = (_size - _start), \
509 .info = &vmstate_info_buffer, \
510 .flags = VMS_BUFFER, \
511 .offset = vmstate_offset_buffer(_state, _field) + _start, \
512 }
513
514 #define VMSTATE_BUFFER_MULTIPLY(_field, _state, _version, _test, _start, _field_size, _multiply) { \
515 .name = (stringify(_field)), \
516 .version_id = (_version), \
517 .field_exists = (_test), \
518 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\
519 .size = (_multiply), \
520 .info = &vmstate_info_buffer, \
521 .flags = VMS_VBUFFER|VMS_MULTIPLY, \
522 .offset = offsetof(_state, _field), \
523 .start = (_start), \
524 }
525
526 #define VMSTATE_VBUFFER(_field, _state, _version, _test, _start, _field_size) { \
527 .name = (stringify(_field)), \
528 .version_id = (_version), \
529 .field_exists = (_test), \
530 .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\
531 .info = &vmstate_info_buffer, \
532 .flags = VMS_VBUFFER|VMS_POINTER, \
533 .offset = offsetof(_state, _field), \
534 .start = (_start), \
535 }
536
537 #define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _start, _field_size) { \
538 .name = (stringify(_field)), \
539 .version_id = (_version), \
540 .field_exists = (_test), \
541 .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\
542 .info = &vmstate_info_buffer, \
543 .flags = VMS_VBUFFER|VMS_POINTER, \
544 .offset = offsetof(_state, _field), \
545 .start = (_start), \
546 }
547
548 #define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) { \
549 .name = (stringify(_field)), \
550 .version_id = (_version), \
551 .size = (_size), \
552 .info = &(_info), \
553 .flags = VMS_BUFFER, \
554 .offset = offsetof(_state, _field), \
555 }
556
557 #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) { \
558 .name = "unused", \
559 .field_exists = (_test), \
560 .version_id = (_version), \
561 .size = (_size), \
562 .info = &vmstate_info_unused_buffer, \
563 .flags = VMS_BUFFER, \
564 }
565 extern const VMStateDescription vmstate_pci_device;
566
567 #define VMSTATE_PCI_DEVICE(_field, _state) { \
568 .name = (stringify(_field)), \
569 .size = sizeof(PCIDevice), \
570 .vmsd = &vmstate_pci_device, \
571 .flags = VMS_STRUCT, \
572 .offset = vmstate_offset_value(_state, _field, PCIDevice), \
573 }
574
575 extern const VMStateDescription vmstate_pcie_device;
576
577 #define VMSTATE_PCIE_DEVICE(_field, _state) { \
578 .name = (stringify(_field)), \
579 .version_id = 2, \
580 .size = sizeof(PCIDevice), \
581 .vmsd = &vmstate_pcie_device, \
582 .flags = VMS_STRUCT, \
583 .offset = vmstate_offset_value(_state, _field, PCIDevice), \
584 }
585
586 extern const VMStateDescription vmstate_i2c_slave;
587
588 #define VMSTATE_I2C_SLAVE(_field, _state) { \
589 .name = (stringify(_field)), \
590 .size = sizeof(i2c_slave), \
591 .vmsd = &vmstate_i2c_slave, \
592 .flags = VMS_STRUCT, \
593 .offset = vmstate_offset_value(_state, _field, i2c_slave), \
594 }
595
596 extern const VMStateDescription vmstate_usb_device;
597
598 #define VMSTATE_USB_DEVICE(_field, _state) { \
599 .name = (stringify(_field)), \
600 .size = sizeof(USBDevice), \
601 .vmsd = &vmstate_usb_device, \
602 .flags = VMS_STRUCT, \
603 .offset = vmstate_offset_value(_state, _field, USBDevice), \
604 }
605
606 #define vmstate_offset_macaddr(_state, _field) \
607 vmstate_offset_array(_state, _field.a, uint8_t, \
608 sizeof(typeof_field(_state, _field)))
609
610 #define VMSTATE_MACADDR(_field, _state) { \
611 .name = (stringify(_field)), \
612 .size = sizeof(MACAddr), \
613 .info = &vmstate_info_buffer, \
614 .flags = VMS_BUFFER, \
615 .offset = vmstate_offset_macaddr(_state, _field), \
616 }
617
618 /* _f : field name
619 _f_n : num of elements field_name
620 _n : num of elements
621 _s : struct state name
622 _v : version
623 */
624
625 #define VMSTATE_SINGLE(_field, _state, _version, _info, _type) \
626 VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type)
627
628 #define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) \
629 VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type)
630
631 #define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type) \
632 VMSTATE_STRUCT_POINTER_TEST(_field, _state, NULL, _vmsd, _type)
633
634 #define VMSTATE_BOOL_V(_f, _s, _v) \
635 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool)
636
637 #define VMSTATE_INT8_V(_f, _s, _v) \
638 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t)
639 #define VMSTATE_INT16_V(_f, _s, _v) \
640 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t)
641 #define VMSTATE_INT32_V(_f, _s, _v) \
642 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t)
643 #define VMSTATE_INT64_V(_f, _s, _v) \
644 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t)
645
646 #define VMSTATE_UINT8_V(_f, _s, _v) \
647 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t)
648 #define VMSTATE_UINT16_V(_f, _s, _v) \
649 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t)
650 #define VMSTATE_UINT32_V(_f, _s, _v) \
651 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t)
652 #define VMSTATE_UINT64_V(_f, _s, _v) \
653 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t)
654
655 #define VMSTATE_BOOL(_f, _s) \
656 VMSTATE_BOOL_V(_f, _s, 0)
657
658 #define VMSTATE_INT8(_f, _s) \
659 VMSTATE_INT8_V(_f, _s, 0)
660 #define VMSTATE_INT16(_f, _s) \
661 VMSTATE_INT16_V(_f, _s, 0)
662 #define VMSTATE_INT32(_f, _s) \
663 VMSTATE_INT32_V(_f, _s, 0)
664 #define VMSTATE_INT64(_f, _s) \
665 VMSTATE_INT64_V(_f, _s, 0)
666
667 #define VMSTATE_UINT8(_f, _s) \
668 VMSTATE_UINT8_V(_f, _s, 0)
669 #define VMSTATE_UINT16(_f, _s) \
670 VMSTATE_UINT16_V(_f, _s, 0)
671 #define VMSTATE_UINT32(_f, _s) \
672 VMSTATE_UINT32_V(_f, _s, 0)
673 #define VMSTATE_UINT64(_f, _s) \
674 VMSTATE_UINT64_V(_f, _s, 0)
675
676 /* This is needed because on linux __u64 is unsigned long long
677 and on glibc uint64_t is unsigned long on 64 bits */
fa9a236 @rmustacc HVM-388 Run native kvm with qemu-v0.14.x
rmustacc authored
678 #if defined(__linux__)
68396ea @rmustacc Initial commit of d32e8d0b8d9e0ef7cf7ab2e74548982972789dfc from qemu-kvm
rmustacc authored
679 #define VMSTATE_U64_V(_f, _s, _v) \
680 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_u64, __u64)
681 #define VMSTATE_U64(_f, _s) \
682 VMSTATE_U64_V(_f, _s, 0)
fa9a236 @rmustacc HVM-388 Run native kvm with qemu-v0.14.x
rmustacc authored
683 #else
684 #define VMSTATE_U64_V(_f, _s, _v) \
685 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t)
686 #define VMSTATE_U64(_f, _s) \
687 VMSTATE_U64_V(_f, _s, 0)
68396ea @rmustacc Initial commit of d32e8d0b8d9e0ef7cf7ab2e74548982972789dfc from qemu-kvm
rmustacc authored
688 #endif
689
690 #define VMSTATE_UINT8_EQUAL(_f, _s) \
691 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t)
692
693 #define VMSTATE_UINT16_EQUAL(_f, _s) \
694 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint16_equal, uint16_t)
695
696 #define VMSTATE_UINT16_EQUAL_V(_f, _s, _v) \
697 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16_equal, uint16_t)
698
699 #define VMSTATE_INT32_EQUAL(_f, _s) \
700 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t)
701
702 #define VMSTATE_INT32_LE(_f, _s) \
703 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
704
705 #define VMSTATE_UINT16_TEST(_f, _s, _t) \
706 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
707
708 #define VMSTATE_UINT32_TEST(_f, _s, _t) \
709 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)
710
711 #define VMSTATE_TIMER_V(_f, _s, _v) \
712 VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *)
713
714 #define VMSTATE_TIMER(_f, _s) \
715 VMSTATE_TIMER_V(_f, _s, 0)
716
717 #define VMSTATE_TIMER_ARRAY(_f, _s, _n) \
718 VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *)
719
720 #define VMSTATE_PTIMER_V(_f, _s, _v) \
721 VMSTATE_POINTER(_f, _s, _v, vmstate_info_ptimer, ptimer_state *)
722
723 #define VMSTATE_PTIMER(_f, _s) \
724 VMSTATE_PTIMER_V(_f, _s, 0)
725
726 #define VMSTATE_BOOL_ARRAY_V(_f, _s, _n, _v) \
727 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_bool, bool)
728
729 #define VMSTATE_BOOL_ARRAY(_f, _s, _n) \
730 VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0)
731
732 #define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v) \
733 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t)
734
735 #define VMSTATE_UINT16_ARRAY(_f, _s, _n) \
736 VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0)
737
738 #define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v) \
739 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t)
740
741 #define VMSTATE_UINT8_ARRAY(_f, _s, _n) \
742 VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0)
743
744 #define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v) \
745 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t)
746
747 #define VMSTATE_UINT32_ARRAY(_f, _s, _n) \
748 VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
749
750 #define VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v) \
751 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint64, uint64_t)
752
753 #define VMSTATE_UINT64_ARRAY(_f, _s, _n) \
754 VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0)
755
756 #define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v) \
757 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t)
758
759 #define VMSTATE_INT16_ARRAY(_f, _s, _n) \
760 VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0)
761
762 #define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v) \
763 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t)
764
765 #define VMSTATE_INT32_ARRAY(_f, _s, _n) \
766 VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0)
767
768 #define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num) \
769 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t)
770
771 #define VMSTATE_UINT32_ARRAY(_f, _s, _n) \
772 VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
773
774 #define VMSTATE_BUFFER_V(_f, _s, _v) \
775 VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f)))
776
777 #define VMSTATE_BUFFER(_f, _s) \
778 VMSTATE_BUFFER_V(_f, _s, 0)
779
780 #define VMSTATE_PARTIAL_BUFFER(_f, _s, _size) \
781 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, _size)
782
783 #define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \
784 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, _start, sizeof(typeof_field(_s, _f)))
785
786 #define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size) \
787 VMSTATE_VBUFFER(_f, _s, 0, NULL, 0, _size)
788
789 #define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size) \
790 VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, 0, _size)
791
792 #define VMSTATE_SUB_VBUFFER(_f, _s, _start, _size) \
793 VMSTATE_VBUFFER(_f, _s, 0, NULL, _start, _size)
794
795 #define VMSTATE_BUFFER_TEST(_f, _s, _test) \
796 VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f)))
797
798 #define VMSTATE_BUFFER_UNSAFE(_field, _state, _version, _size) \
799 VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, _size)
800
801 #define VMSTATE_UNUSED_V(_v, _size) \
802 VMSTATE_UNUSED_BUFFER(NULL, _v, _size)
803
804 #define VMSTATE_UNUSED(_size) \
805 VMSTATE_UNUSED_V(0, _size)
806
807 #define VMSTATE_UNUSED_TEST(_test, _size) \
808 VMSTATE_UNUSED_BUFFER(_test, 0, _size)
809
810 #ifdef NEED_CPU_H
811 #if TARGET_LONG_BITS == 64
812 #define VMSTATE_UINTTL_V(_f, _s, _v) \
813 VMSTATE_UINT64_V(_f, _s, _v)
814 #define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v) \
815 VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)
816 #else
817 #define VMSTATE_UINTTL_V(_f, _s, _v) \
818 VMSTATE_UINT32_V(_f, _s, _v)
819 #define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v) \
820 VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)
821 #endif
822 #define VMSTATE_UINTTL(_f, _s) \
823 VMSTATE_UINTTL_V(_f, _s, 0)
824 #define VMSTATE_UINTTL_ARRAY(_f, _s, _n) \
825 VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, 0)
826
827 #endif
828
829 #define VMSTATE_END_OF_LIST() \
830 {}
831
832 int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
833 void *opaque, int version_id);
834 void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
835 void *opaque);
836 int vmstate_register(DeviceState *dev, int instance_id,
837 const VMStateDescription *vmsd, void *base);
838 int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
839 const VMStateDescription *vmsd,
840 void *base, int alias_id,
841 int required_for_version);
842 void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd,
843 void *opaque);
844 #endif
Something went wrong with that request. Please try again.