Statistics
| Branch: | Revision:

root / hw / hw.h @ 47188700

History | View | Annotate | Download (35 kB)

1
/* Declarations for use by hardware emulation.  */
2
#ifndef QEMU_HW_H
3
#define QEMU_HW_H
4

    
5
#include "qemu-common.h"
6

    
7
#if defined(TARGET_PHYS_ADDR_BITS) && !defined(NEED_CPU_H)
8
#include "cpu-common.h"
9
#endif
10

    
11
#include "ioport.h"
12
#include "irq.h"
13

    
14
/* VM Load/Save */
15

    
16
/* This function writes a chunk of data to a file at the given position.
17
 * The pos argument can be ignored if the file is only being used for
18
 * streaming.  The handler should try to write all of the data it can.
19
 */
20
typedef int (QEMUFilePutBufferFunc)(void *opaque, const uint8_t *buf,
21
                                    int64_t pos, int size);
22

    
23
/* Read a chunk of data from a file at the given position.  The pos argument
24
 * can be ignored if the file is only be used for streaming.  The number of
25
 * bytes actually read should be returned.
26
 */
27
typedef int (QEMUFileGetBufferFunc)(void *opaque, uint8_t *buf,
28
                                    int64_t pos, int size);
29

    
30
/* Close a file and return an error code */
31
typedef int (QEMUFileCloseFunc)(void *opaque);
32

    
33
/* Called to determine if the file has exceeded it's bandwidth allocation.  The
34
 * bandwidth capping is a soft limit, not a hard limit.
35
 */
36
typedef int (QEMUFileRateLimit)(void *opaque);
37

    
38
/* Called to change the current bandwidth allocation. This function must return
39
 * the new actual bandwidth. It should be new_rate if everything goes ok, and
40
 * the old rate otherwise
41
 */
42
typedef int64_t (QEMUFileSetRateLimit)(void *opaque, int64_t new_rate);
43
typedef int64_t (QEMUFileGetRateLimit)(void *opaque);
44

    
45
QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
46
                         QEMUFileGetBufferFunc *get_buffer,
47
                         QEMUFileCloseFunc *close,
48
                         QEMUFileRateLimit *rate_limit,
49
                         QEMUFileSetRateLimit *set_rate_limit,
50
                         QEMUFileGetRateLimit *get_rate_limit);
51
QEMUFile *qemu_fopen(const char *filename, const char *mode);
52
QEMUFile *qemu_fdopen(int fd, const char *mode);
53
QEMUFile *qemu_fopen_socket(int fd);
54
QEMUFile *qemu_popen(FILE *popen_file, const char *mode);
55
QEMUFile *qemu_popen_cmd(const char *command, const char *mode);
56
int qemu_stdio_fd(QEMUFile *f);
57
void qemu_fflush(QEMUFile *f);
58
int qemu_fclose(QEMUFile *f);
59
void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
60
void qemu_put_byte(QEMUFile *f, int v);
61

    
62
static inline void qemu_put_ubyte(QEMUFile *f, unsigned int v)
63
{
64
    qemu_put_byte(f, (int)v);
65
}
66

    
67
#define qemu_put_sbyte qemu_put_byte
68

    
69
void qemu_put_be16(QEMUFile *f, unsigned int v);
70
void qemu_put_be32(QEMUFile *f, unsigned int v);
71
void qemu_put_be64(QEMUFile *f, uint64_t v);
72
int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size);
73
int qemu_get_byte(QEMUFile *f);
74

    
75
static inline unsigned int qemu_get_ubyte(QEMUFile *f)
76
{
77
    return (unsigned int)qemu_get_byte(f);
78
}
79

    
80
#define qemu_get_sbyte qemu_get_byte
81

    
82
unsigned int qemu_get_be16(QEMUFile *f);
83
unsigned int qemu_get_be32(QEMUFile *f);
84
uint64_t qemu_get_be64(QEMUFile *f);
85
int qemu_file_rate_limit(QEMUFile *f);
86
int64_t qemu_file_set_rate_limit(QEMUFile *f, int64_t new_rate);
87
int64_t qemu_file_get_rate_limit(QEMUFile *f);
88
int qemu_file_has_error(QEMUFile *f);
89
void qemu_file_set_error(QEMUFile *f);
90

    
91
/* Try to send any outstanding data.  This function is useful when output is
92
 * halted due to rate limiting or EAGAIN errors occur as it can be used to
93
 * resume output. */
94
void qemu_file_put_notify(QEMUFile *f);
95

    
96
static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
97
{
98
    qemu_put_be64(f, *pv);
99
}
100

    
101
static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv)
102
{
103
    qemu_put_be32(f, *pv);
104
}
105

    
106
static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv)
107
{
108
    qemu_put_be16(f, *pv);
109
}
110

    
111
static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv)
112
{
113
    qemu_put_byte(f, *pv);
114
}
115

    
116
static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv)
117
{
118
    *pv = qemu_get_be64(f);
119
}
120

    
121
static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv)
122
{
123
    *pv = qemu_get_be32(f);
124
}
125

    
126
static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv)
127
{
128
    *pv = qemu_get_be16(f);
129
}
130

    
131
static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv)
132
{
133
    *pv = qemu_get_byte(f);
134
}
135

    
136
// Signed versions for type safety
137
static inline void qemu_put_sbuffer(QEMUFile *f, const int8_t *buf, int size)
138
{
139
    qemu_put_buffer(f, (const uint8_t *)buf, size);
140
}
141

    
142
static inline void qemu_put_sbe16(QEMUFile *f, int v)
143
{
144
    qemu_put_be16(f, (unsigned int)v);
145
}
146

    
147
static inline void qemu_put_sbe32(QEMUFile *f, int v)
148
{
149
    qemu_put_be32(f, (unsigned int)v);
150
}
151

    
152
static inline void qemu_put_sbe64(QEMUFile *f, int64_t v)
153
{
154
    qemu_put_be64(f, (uint64_t)v);
155
}
156

    
157
static inline size_t qemu_get_sbuffer(QEMUFile *f, int8_t *buf, int size)
158
{
159
    return qemu_get_buffer(f, (uint8_t *)buf, size);
160
}
161

    
162
static inline int qemu_get_sbe16(QEMUFile *f)
163
{
164
    return (int)qemu_get_be16(f);
165
}
166

    
167
static inline int qemu_get_sbe32(QEMUFile *f)
168
{
169
    return (int)qemu_get_be32(f);
170
}
171

    
172
static inline int64_t qemu_get_sbe64(QEMUFile *f)
173
{
174
    return (int64_t)qemu_get_be64(f);
175
}
176

    
177
static inline void qemu_put_s8s(QEMUFile *f, const int8_t *pv)
178
{
179
    qemu_put_8s(f, (const uint8_t *)pv);
180
}
181

    
182
static inline void qemu_put_sbe16s(QEMUFile *f, const int16_t *pv)
183
{
184
    qemu_put_be16s(f, (const uint16_t *)pv);
185
}
186

    
187
static inline void qemu_put_sbe32s(QEMUFile *f, const int32_t *pv)
188
{
189
    qemu_put_be32s(f, (const uint32_t *)pv);
190
}
191

    
192
static inline void qemu_put_sbe64s(QEMUFile *f, const int64_t *pv)
193
{
194
    qemu_put_be64s(f, (const uint64_t *)pv);
195
}
196

    
197
static inline void qemu_get_s8s(QEMUFile *f, int8_t *pv)
198
{
199
    qemu_get_8s(f, (uint8_t *)pv);
200
}
201

    
202
static inline void qemu_get_sbe16s(QEMUFile *f, int16_t *pv)
203
{
204
    qemu_get_be16s(f, (uint16_t *)pv);
205
}
206

    
207
static inline void qemu_get_sbe32s(QEMUFile *f, int32_t *pv)
208
{
209
    qemu_get_be32s(f, (uint32_t *)pv);
210
}
211

    
212
static inline void qemu_get_sbe64s(QEMUFile *f, int64_t *pv)
213
{
214
    qemu_get_be64s(f, (uint64_t *)pv);
215
}
216

    
217
#ifdef NEED_CPU_H
218
#if TARGET_LONG_BITS == 64
219
#define qemu_put_betl qemu_put_be64
220
#define qemu_get_betl qemu_get_be64
221
#define qemu_put_betls qemu_put_be64s
222
#define qemu_get_betls qemu_get_be64s
223
#define qemu_put_sbetl qemu_put_sbe64
224
#define qemu_get_sbetl qemu_get_sbe64
225
#define qemu_put_sbetls qemu_put_sbe64s
226
#define qemu_get_sbetls qemu_get_sbe64s
227
#else
228
#define qemu_put_betl qemu_put_be32
229
#define qemu_get_betl qemu_get_be32
230
#define qemu_put_betls qemu_put_be32s
231
#define qemu_get_betls qemu_get_be32s
232
#define qemu_put_sbetl qemu_put_sbe32
233
#define qemu_get_sbetl qemu_get_sbe32
234
#define qemu_put_sbetls qemu_put_sbe32s
235
#define qemu_get_sbetls qemu_get_sbe32s
236
#endif
237
#endif
238

    
239
int64_t qemu_ftell(QEMUFile *f);
240
int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence);
241

    
242
typedef void SaveSetParamsHandler(int blk_enable, int shared, void * opaque);
243
typedef void SaveStateHandler(QEMUFile *f, void *opaque);
244
typedef int SaveLiveStateHandler(Monitor *mon, QEMUFile *f, int stage,
245
                                 void *opaque);
246
typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
247

    
248
int register_savevm(DeviceState *dev,
249
                    const char *idstr,
250
                    int instance_id,
251
                    int version_id,
252
                    SaveStateHandler *save_state,
253
                    LoadStateHandler *load_state,
254
                    void *opaque);
255

    
256
int register_savevm_live(DeviceState *dev,
257
                         const char *idstr,
258
                         int instance_id,
259
                         int version_id,
260
                         SaveSetParamsHandler *set_params,
261
                         SaveLiveStateHandler *save_live_state,
262
                         SaveStateHandler *save_state,
263
                         LoadStateHandler *load_state,
264
                         void *opaque);
265

    
266
void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque);
267
void register_device_unmigratable(DeviceState *dev, const char *idstr,
268
                                                                void *opaque);
269

    
270
typedef void QEMUResetHandler(void *opaque);
271

    
272
void qemu_register_reset(QEMUResetHandler *func, void *opaque);
273
void qemu_unregister_reset(QEMUResetHandler *func, void *opaque);
274

    
275
/* handler to set the boot_device order for a specific type of QEMUMachine */
276
/* return 0 if success */
277
typedef int QEMUBootSetHandler(void *opaque, const char *boot_devices);
278
void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque);
279
int qemu_boot_set(const char *boot_devices);
280

    
281
typedef struct VMStateInfo VMStateInfo;
282
typedef struct VMStateDescription VMStateDescription;
283

    
284
struct VMStateInfo {
285
    const char *name;
286
    int (*get)(QEMUFile *f, void *pv, size_t size);
287
    void (*put)(QEMUFile *f, void *pv, size_t size);
288
};
289

    
290
enum VMStateFlags {
291
    VMS_SINGLE           = 0x001,
292
    VMS_POINTER          = 0x002,
293
    VMS_ARRAY            = 0x004,
294
    VMS_STRUCT           = 0x008,
295
    VMS_VARRAY_INT32     = 0x010,  /* Array with size in int32_t field*/
296
    VMS_BUFFER           = 0x020,  /* static sized buffer */
297
    VMS_ARRAY_OF_POINTER = 0x040,
298
    VMS_VARRAY_UINT16    = 0x080,  /* Array with size in uint16_t field */
299
    VMS_VBUFFER          = 0x100,  /* Buffer with size in int32_t field */
300
    VMS_MULTIPLY         = 0x200,  /* multiply "size" field by field_size */
301
};
302

    
303
typedef struct {
304
    const char *name;
305
    size_t offset;
306
    size_t size;
307
    size_t start;
308
    int num;
309
    size_t num_offset;
310
    size_t size_offset;
311
    const VMStateInfo *info;
312
    enum VMStateFlags flags;
313
    const VMStateDescription *vmsd;
314
    int version_id;
315
    bool (*field_exists)(void *opaque, int version_id);
316
} VMStateField;
317

    
318
typedef struct VMStateSubsection {
319
    const VMStateDescription *vmsd;
320
    bool (*needed)(void *opaque);
321
} VMStateSubsection;
322

    
323
struct VMStateDescription {
324
    const char *name;
325
    int version_id;
326
    int minimum_version_id;
327
    int minimum_version_id_old;
328
    LoadStateHandler *load_state_old;
329
    int (*pre_load)(void *opaque);
330
    int (*post_load)(void *opaque, int version_id);
331
    void (*pre_save)(void *opaque);
332
    VMStateField *fields;
333
    const VMStateSubsection *subsections;
334
};
335

    
336
extern const VMStateInfo vmstate_info_bool;
337

    
338
extern const VMStateInfo vmstate_info_int8;
339
extern const VMStateInfo vmstate_info_int16;
340
extern const VMStateInfo vmstate_info_int32;
341
extern const VMStateInfo vmstate_info_int64;
342

    
343
extern const VMStateInfo vmstate_info_uint8_equal;
344
extern const VMStateInfo vmstate_info_uint16_equal;
345
extern const VMStateInfo vmstate_info_int32_equal;
346
extern const VMStateInfo vmstate_info_int32_le;
347

    
348
extern const VMStateInfo vmstate_info_uint8;
349
extern const VMStateInfo vmstate_info_uint16;
350
extern const VMStateInfo vmstate_info_uint32;
351
extern const VMStateInfo vmstate_info_uint64;
352

    
353
extern const VMStateInfo vmstate_info_timer;
354
extern const VMStateInfo vmstate_info_ptimer;
355
extern const VMStateInfo vmstate_info_buffer;
356
extern const VMStateInfo vmstate_info_unused_buffer;
357

    
358
#define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
359
#define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
360

    
361
#define vmstate_offset_value(_state, _field, _type)                  \
362
    (offsetof(_state, _field) +                                      \
363
     type_check(_type, typeof_field(_state, _field)))
364

    
365
#define vmstate_offset_pointer(_state, _field, _type)                \
366
    (offsetof(_state, _field) +                                      \
367
     type_check_pointer(_type, typeof_field(_state, _field)))
368

    
369
#define vmstate_offset_array(_state, _field, _type, _num)            \
370
    (offsetof(_state, _field) +                                      \
371
     type_check_array(_type, typeof_field(_state, _field), _num))
372

    
373
#define vmstate_offset_sub_array(_state, _field, _type, _start)      \
374
    (offsetof(_state, _field[_start]))
375

    
376
#define vmstate_offset_buffer(_state, _field)                        \
377
    vmstate_offset_array(_state, _field, uint8_t,                    \
378
                         sizeof(typeof_field(_state, _field)))
379

    
380
#define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \
381
    .name         = (stringify(_field)),                             \
382
    .version_id   = (_version),                                      \
383
    .field_exists = (_test),                                         \
384
    .size         = sizeof(_type),                                   \
385
    .info         = &(_info),                                        \
386
    .flags        = VMS_SINGLE,                                      \
387
    .offset       = vmstate_offset_value(_state, _field, _type),     \
388
}
389

    
390
#define VMSTATE_POINTER(_field, _state, _version, _info, _type) {    \
391
    .name       = (stringify(_field)),                               \
392
    .version_id = (_version),                                        \
393
    .info       = &(_info),                                          \
394
    .size       = sizeof(_type),                                     \
395
    .flags      = VMS_SINGLE|VMS_POINTER,                            \
396
    .offset     = vmstate_offset_value(_state, _field, _type),       \
397
}
398

    
399
#define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\
400
    .name       = (stringify(_field)),                               \
401
    .version_id = (_version),                                        \
402
    .num        = (_num),                                            \
403
    .info       = &(_info),                                          \
404
    .size       = sizeof(_type),                                     \
405
    .flags      = VMS_ARRAY,                                         \
406
    .offset     = vmstate_offset_array(_state, _field, _type, _num), \
407
}
408

    
409
#define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
410
    .name         = (stringify(_field)),                              \
411
    .field_exists = (_test),                                          \
412
    .num          = (_num),                                           \
413
    .info         = &(_info),                                         \
414
    .size         = sizeof(_type),                                    \
415
    .flags        = VMS_ARRAY,                                        \
416
    .offset       = vmstate_offset_array(_state, _field, _type, _num),\
417
}
418

    
419
#define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \
420
    .name       = (stringify(_field)),                               \
421
    .version_id = (_version),                                        \
422
    .num        = (_num),                                            \
423
    .info       = &(_info),                                          \
424
    .size       = sizeof(_type),                                     \
425
    .flags      = VMS_ARRAY,                                         \
426
    .offset     = vmstate_offset_sub_array(_state, _field, _type, _start), \
427
}
428

    
429
#define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\
430
    .name       = (stringify(_field)),                               \
431
    .version_id = (_version),                                        \
432
    .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
433
    .info       = &(_info),                                          \
434
    .size       = sizeof(_type),                                     \
435
    .flags      = VMS_VARRAY_INT32|VMS_POINTER,                      \
436
    .offset     = vmstate_offset_pointer(_state, _field, _type),     \
437
}
438

    
439
#define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version, _info, _type) {\
440
    .name       = (stringify(_field)),                               \
441
    .version_id = (_version),                                        \
442
    .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
443
    .info       = &(_info),                                          \
444
    .size       = sizeof(_type),                                     \
445
    .flags      = VMS_VARRAY_UINT16,                                 \
446
    .offset     = offsetof(_state, _field),                          \
447
}
448

    
449
#define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \
450
    .name         = (stringify(_field)),                             \
451
    .version_id   = (_version),                                      \
452
    .field_exists = (_test),                                         \
453
    .vmsd         = &(_vmsd),                                        \
454
    .size         = sizeof(_type),                                   \
455
    .flags        = VMS_STRUCT,                                      \
456
    .offset       = vmstate_offset_value(_state, _field, _type),     \
457
}
458

    
459
#define VMSTATE_STRUCT_POINTER_TEST(_field, _state, _test, _vmsd, _type) { \
460
    .name         = (stringify(_field)),                             \
461
    .field_exists = (_test),                                         \
462
    .vmsd         = &(_vmsd),                                        \
463
    .size         = sizeof(_type),                                   \
464
    .flags        = VMS_STRUCT|VMS_POINTER,                          \
465
    .offset       = vmstate_offset_value(_state, _field, _type),     \
466
}
467

    
468
#define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) {\
469
    .name       = (stringify(_field)),                               \
470
    .version_id = (_version),                                        \
471
    .num        = (_num),                                            \
472
    .info       = &(_info),                                          \
473
    .size       = sizeof(_type),                                     \
474
    .flags      = VMS_ARRAY|VMS_ARRAY_OF_POINTER,                    \
475
    .offset     = vmstate_offset_array(_state, _field, _type, _num), \
476
}
477

    
478
#define VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, _test, _version, _vmsd, _type) { \
479
    .name         = (stringify(_field)),                             \
480
    .num          = (_num),                                          \
481
    .field_exists = (_test),                                         \
482
    .version_id   = (_version),                                      \
483
    .vmsd         = &(_vmsd),                                        \
484
    .size         = sizeof(_type),                                   \
485
    .flags        = VMS_STRUCT|VMS_ARRAY,                            \
486
    .offset       = vmstate_offset_array(_state, _field, _type, _num),\
487
}
488

    
489
#define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, _vmsd, _type) { \
490
    .name       = (stringify(_field)),                               \
491
    .num_offset = vmstate_offset_value(_state, _field_num, uint8_t),  \
492
    .version_id = (_version),                                        \
493
    .vmsd       = &(_vmsd),                                          \
494
    .size       = sizeof(_type),                                     \
495
    .flags      = VMS_STRUCT|VMS_VARRAY_INT32,                       \
496
    .offset     = offsetof(_state, _field),                          \
497
}
498

    
499
#define VMSTATE_STRUCT_VARRAY_POINTER_INT32(_field, _state, _field_num, _vmsd, _type) { \
500
    .name       = (stringify(_field)),                               \
501
    .version_id = 0,                                                 \
502
    .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
503
    .size       = sizeof(_type),                                     \
504
    .vmsd       = &(_vmsd),                                          \
505
    .flags      = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT,       \
506
    .offset     = vmstate_offset_pointer(_state, _field, _type),     \
507
}
508

    
509
#define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, _vmsd, _type) { \
510
    .name       = (stringify(_field)),                               \
511
    .version_id = 0,                                                 \
512
    .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
513
    .size       = sizeof(_type),                                     \
514
    .vmsd       = &(_vmsd),                                          \
515
    .flags      = VMS_POINTER | VMS_VARRAY_UINT16 | VMS_STRUCT,      \
516
    .offset     = vmstate_offset_pointer(_state, _field, _type),     \
517
}
518

    
519
#define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) { \
520
    .name         = (stringify(_field)),                             \
521
    .version_id   = (_version),                                      \
522
    .field_exists = (_test),                                         \
523
    .size         = (_size - _start),                                \
524
    .info         = &vmstate_info_buffer,                            \
525
    .flags        = VMS_BUFFER,                                      \
526
    .offset       = vmstate_offset_buffer(_state, _field) + _start,  \
527
}
528

    
529
#define VMSTATE_BUFFER_MULTIPLY(_field, _state, _version, _test, _start, _field_size, _multiply) { \
530
    .name         = (stringify(_field)),                             \
531
    .version_id   = (_version),                                      \
532
    .field_exists = (_test),                                         \
533
    .size_offset  = vmstate_offset_value(_state, _field_size, uint32_t),\
534
    .size         = (_multiply),                                      \
535
    .info         = &vmstate_info_buffer,                            \
536
    .flags        = VMS_VBUFFER|VMS_MULTIPLY,                        \
537
    .offset       = offsetof(_state, _field),                        \
538
    .start        = (_start),                                        \
539
}
540

    
541
#define VMSTATE_VBUFFER(_field, _state, _version, _test, _start, _field_size) { \
542
    .name         = (stringify(_field)),                             \
543
    .version_id   = (_version),                                      \
544
    .field_exists = (_test),                                         \
545
    .size_offset  = vmstate_offset_value(_state, _field_size, int32_t),\
546
    .info         = &vmstate_info_buffer,                            \
547
    .flags        = VMS_VBUFFER|VMS_POINTER,                         \
548
    .offset       = offsetof(_state, _field),                        \
549
    .start        = (_start),                                        \
550
}
551

    
552
#define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _start, _field_size) { \
553
    .name         = (stringify(_field)),                             \
554
    .version_id   = (_version),                                      \
555
    .field_exists = (_test),                                         \
556
    .size_offset  = vmstate_offset_value(_state, _field_size, uint32_t),\
557
    .info         = &vmstate_info_buffer,                            \
558
    .flags        = VMS_VBUFFER|VMS_POINTER,                         \
559
    .offset       = offsetof(_state, _field),                        \
560
    .start        = (_start),                                        \
561
}
562

    
563
#define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) { \
564
    .name       = (stringify(_field)),                               \
565
    .version_id = (_version),                                        \
566
    .size       = (_size),                                           \
567
    .info       = &(_info),                                          \
568
    .flags      = VMS_BUFFER,                                        \
569
    .offset     = offsetof(_state, _field),                          \
570
}
571

    
572
#define VMSTATE_UNUSED_BUFFER(_test, _version, _size) {              \
573
    .name         = "unused",                                        \
574
    .field_exists = (_test),                                         \
575
    .version_id   = (_version),                                      \
576
    .size         = (_size),                                         \
577
    .info         = &vmstate_info_unused_buffer,                     \
578
    .flags        = VMS_BUFFER,                                      \
579
}
580
extern const VMStateDescription vmstate_pci_device;
581

    
582
#define VMSTATE_PCI_DEVICE(_field, _state) {                         \
583
    .name       = (stringify(_field)),                               \
584
    .size       = sizeof(PCIDevice),                                 \
585
    .vmsd       = &vmstate_pci_device,                               \
586
    .flags      = VMS_STRUCT,                                        \
587
    .offset     = vmstate_offset_value(_state, _field, PCIDevice),   \
588
}
589

    
590
extern const VMStateDescription vmstate_pcie_device;
591

    
592
#define VMSTATE_PCIE_DEVICE(_field, _state) {                        \
593
    .name       = (stringify(_field)),                               \
594
    .version_id = 2,                                                 \
595
    .size       = sizeof(PCIDevice),                                 \
596
    .vmsd       = &vmstate_pcie_device,                              \
597
    .flags      = VMS_STRUCT,                                        \
598
    .offset     = vmstate_offset_value(_state, _field, PCIDevice),   \
599
}
600

    
601
extern const VMStateDescription vmstate_i2c_slave;
602

    
603
#define VMSTATE_I2C_SLAVE(_field, _state) {                          \
604
    .name       = (stringify(_field)),                               \
605
    .size       = sizeof(i2c_slave),                                 \
606
    .vmsd       = &vmstate_i2c_slave,                                \
607
    .flags      = VMS_STRUCT,                                        \
608
    .offset     = vmstate_offset_value(_state, _field, i2c_slave),   \
609
}
610

    
611
extern const VMStateDescription vmstate_usb_device;
612

    
613
#define VMSTATE_USB_DEVICE(_field, _state) {                         \
614
    .name       = (stringify(_field)),                               \
615
    .size       = sizeof(USBDevice),                                 \
616
    .vmsd       = &vmstate_usb_device,                               \
617
    .flags      = VMS_STRUCT,                                        \
618
    .offset     = vmstate_offset_value(_state, _field, USBDevice),   \
619
}
620

    
621
#define vmstate_offset_macaddr(_state, _field)                       \
622
    vmstate_offset_array(_state, _field.a, uint8_t,                \
623
                         sizeof(typeof_field(_state, _field)))
624

    
625
#define VMSTATE_MACADDR(_field, _state) {                            \
626
    .name       = (stringify(_field)),                               \
627
    .size       = sizeof(MACAddr),                                   \
628
    .info       = &vmstate_info_buffer,                              \
629
    .flags      = VMS_BUFFER,                                        \
630
    .offset     = vmstate_offset_macaddr(_state, _field),            \
631
}
632

    
633
/* _f : field name
634
   _f_n : num of elements field_name
635
   _n : num of elements
636
   _s : struct state name
637
   _v : version
638
*/
639

    
640
#define VMSTATE_SINGLE(_field, _state, _version, _info, _type)        \
641
    VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type)
642

    
643
#define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type)        \
644
    VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type)
645

    
646
#define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type)          \
647
    VMSTATE_STRUCT_POINTER_TEST(_field, _state, NULL, _vmsd, _type)
648

    
649
#define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) \
650
    VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version,   \
651
            _vmsd, _type)
652

    
653
#define VMSTATE_BOOL_V(_f, _s, _v)                                    \
654
    VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool)
655

    
656
#define VMSTATE_INT8_V(_f, _s, _v)                                    \
657
    VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t)
658
#define VMSTATE_INT16_V(_f, _s, _v)                                   \
659
    VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t)
660
#define VMSTATE_INT32_V(_f, _s, _v)                                   \
661
    VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t)
662
#define VMSTATE_INT64_V(_f, _s, _v)                                   \
663
    VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t)
664

    
665
#define VMSTATE_UINT8_V(_f, _s, _v)                                   \
666
    VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t)
667
#define VMSTATE_UINT16_V(_f, _s, _v)                                  \
668
    VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t)
669
#define VMSTATE_UINT32_V(_f, _s, _v)                                  \
670
    VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t)
671
#define VMSTATE_UINT64_V(_f, _s, _v)                                  \
672
    VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t)
673

    
674
#define VMSTATE_BOOL(_f, _s)                                          \
675
    VMSTATE_BOOL_V(_f, _s, 0)
676

    
677
#define VMSTATE_INT8(_f, _s)                                          \
678
    VMSTATE_INT8_V(_f, _s, 0)
679
#define VMSTATE_INT16(_f, _s)                                         \
680
    VMSTATE_INT16_V(_f, _s, 0)
681
#define VMSTATE_INT32(_f, _s)                                         \
682
    VMSTATE_INT32_V(_f, _s, 0)
683
#define VMSTATE_INT64(_f, _s)                                         \
684
    VMSTATE_INT64_V(_f, _s, 0)
685

    
686
#define VMSTATE_UINT8(_f, _s)                                         \
687
    VMSTATE_UINT8_V(_f, _s, 0)
688
#define VMSTATE_UINT16(_f, _s)                                        \
689
    VMSTATE_UINT16_V(_f, _s, 0)
690
#define VMSTATE_UINT32(_f, _s)                                        \
691
    VMSTATE_UINT32_V(_f, _s, 0)
692
#define VMSTATE_UINT64(_f, _s)                                        \
693
    VMSTATE_UINT64_V(_f, _s, 0)
694

    
695
#define VMSTATE_UINT8_EQUAL(_f, _s)                                   \
696
    VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t)
697

    
698
#define VMSTATE_UINT16_EQUAL(_f, _s)                                  \
699
    VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint16_equal, uint16_t)
700

    
701
#define VMSTATE_UINT16_EQUAL_V(_f, _s, _v)                            \
702
    VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16_equal, uint16_t)
703

    
704
#define VMSTATE_INT32_EQUAL(_f, _s)                                   \
705
    VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t)
706

    
707
#define VMSTATE_INT32_LE(_f, _s)                                   \
708
    VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
709

    
710
#define VMSTATE_UINT16_TEST(_f, _s, _t)                               \
711
    VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
712

    
713
#define VMSTATE_UINT32_TEST(_f, _s, _t)                                  \
714
    VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)
715

    
716
#define VMSTATE_TIMER_V(_f, _s, _v)                                   \
717
    VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *)
718

    
719
#define VMSTATE_TIMER(_f, _s)                                         \
720
    VMSTATE_TIMER_V(_f, _s, 0)
721

    
722
#define VMSTATE_TIMER_ARRAY(_f, _s, _n)                              \
723
    VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *)
724

    
725
#define VMSTATE_PTIMER_V(_f, _s, _v)                                  \
726
    VMSTATE_POINTER(_f, _s, _v, vmstate_info_ptimer, ptimer_state *)
727

    
728
#define VMSTATE_PTIMER(_f, _s)                                        \
729
    VMSTATE_PTIMER_V(_f, _s, 0)
730

    
731
#define VMSTATE_BOOL_ARRAY_V(_f, _s, _n, _v)                         \
732
    VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_bool, bool)
733

    
734
#define VMSTATE_BOOL_ARRAY(_f, _s, _n)                               \
735
    VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0)
736

    
737
#define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v)                         \
738
    VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t)
739

    
740
#define VMSTATE_UINT16_ARRAY(_f, _s, _n)                               \
741
    VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0)
742

    
743
#define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v)                         \
744
    VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t)
745

    
746
#define VMSTATE_UINT8_ARRAY(_f, _s, _n)                               \
747
    VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0)
748

    
749
#define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)                        \
750
    VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t)
751

    
752
#define VMSTATE_UINT32_ARRAY(_f, _s, _n)                              \
753
    VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
754

    
755
#define VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)                        \
756
    VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint64, uint64_t)
757

    
758
#define VMSTATE_UINT64_ARRAY(_f, _s, _n)                              \
759
    VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0)
760

    
761
#define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v)                         \
762
    VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t)
763

    
764
#define VMSTATE_INT16_ARRAY(_f, _s, _n)                               \
765
    VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0)
766

    
767
#define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v)                         \
768
    VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t)
769

    
770
#define VMSTATE_INT32_ARRAY(_f, _s, _n)                               \
771
    VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0)
772

    
773
#define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num)                \
774
    VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t)
775

    
776
#define VMSTATE_UINT32_ARRAY(_f, _s, _n)                              \
777
    VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
778

    
779
#define VMSTATE_BUFFER_V(_f, _s, _v)                                  \
780
    VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f)))
781

    
782
#define VMSTATE_BUFFER(_f, _s)                                        \
783
    VMSTATE_BUFFER_V(_f, _s, 0)
784

    
785
#define VMSTATE_PARTIAL_BUFFER(_f, _s, _size)                         \
786
    VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, _size)
787

    
788
#define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \
789
    VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, _start, sizeof(typeof_field(_s, _f)))
790

    
791
#define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size)                        \
792
    VMSTATE_VBUFFER(_f, _s, 0, NULL, 0, _size)
793

    
794
#define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size)                        \
795
    VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, 0, _size)
796

    
797
#define VMSTATE_SUB_VBUFFER(_f, _s, _start, _size)                    \
798
    VMSTATE_VBUFFER(_f, _s, 0, NULL, _start, _size)
799

    
800
#define VMSTATE_BUFFER_TEST(_f, _s, _test)                            \
801
    VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f)))
802

    
803
#define VMSTATE_BUFFER_UNSAFE(_field, _state, _version, _size)        \
804
    VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, _size)
805

    
806
#define VMSTATE_UNUSED_V(_v, _size)                                   \
807
    VMSTATE_UNUSED_BUFFER(NULL, _v, _size)
808

    
809
#define VMSTATE_UNUSED(_size)                                         \
810
    VMSTATE_UNUSED_V(0, _size)
811

    
812
#define VMSTATE_UNUSED_TEST(_test, _size)                             \
813
    VMSTATE_UNUSED_BUFFER(_test, 0, _size)
814

    
815
#ifdef NEED_CPU_H
816
#if TARGET_LONG_BITS == 64
817
#define VMSTATE_UINTTL_V(_f, _s, _v)                                  \
818
    VMSTATE_UINT64_V(_f, _s, _v)
819
#define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v)                        \
820
    VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)
821
#else
822
#define VMSTATE_UINTTL_V(_f, _s, _v)                                  \
823
    VMSTATE_UINT32_V(_f, _s, _v)
824
#define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v)                        \
825
    VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)
826
#endif
827
#define VMSTATE_UINTTL(_f, _s)                                        \
828
    VMSTATE_UINTTL_V(_f, _s, 0)
829
#define VMSTATE_UINTTL_ARRAY(_f, _s, _n)                              \
830
    VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, 0)
831

    
832
#endif
833

    
834
#define VMSTATE_END_OF_LIST()                                         \
835
    {}
836

    
837
int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
838
                       void *opaque, int version_id);
839
void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
840
                        void *opaque);
841
int vmstate_register(DeviceState *dev, int instance_id,
842
                     const VMStateDescription *vmsd, void *base);
843
int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
844
                                   const VMStateDescription *vmsd,
845
                                   void *base, int alias_id,
846
                                   int required_for_version);
847
void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd,
848
                        void *opaque);
849
#endif