master
h 79 lines 2.02 KB
Raw
1 /*
2 * Virtio Support
3 *
4 * Copyright IBM, Corp. 2007-2008
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 * Rusty Russell <rusty@rustcorp.com.au>
9 *
10 * This work is licensed under the terms of the GNU GPL, version 2. See
11 * the COPYING file in the top-level directory.
12 *
13 */
14
15 #ifndef QEMU_VIRTIO_BALLOON_H
16 #define QEMU_VIRTIO_BALLOON_H
17
18 #include "standard-headers/linux/virtio_balloon.h"
19 #include "hw/core/resettable.h"
20 #include "hw/virtio/virtio.h"
21 #include "system/iothread.h"
22 #include "qom/object.h"
23
24 #define TYPE_VIRTIO_BALLOON "virtio-balloon-device"
25 OBJECT_DECLARE_SIMPLE_TYPE(VirtIOBalloon, VIRTIO_BALLOON)
26
27 #define VIRTIO_BALLOON_FREE_PAGE_HINT_CMD_ID_MIN 0x80000000
28
29 typedef struct virtio_balloon_stat VirtIOBalloonStat;
30
31 typedef struct virtio_balloon_stat_modern {
32 uint16_t tag;
33 uint8_t reserved[6];
34 uint64_t val;
35 } VirtIOBalloonStatModern;
36
37 enum virtio_balloon_free_page_hint_status {
38 FREE_PAGE_HINT_S_STOP = 0,
39 FREE_PAGE_HINT_S_REQUESTED = 1,
40 FREE_PAGE_HINT_S_START = 2,
41 FREE_PAGE_HINT_S_DONE = 3,
42 };
43
44 struct VirtIOBalloon {
45 VirtIODevice parent_obj;
46 VirtQueue *ivq, *dvq, *svq, *free_page_vq, *reporting_vq;
47 uint32_t free_page_hint_status;
48 uint32_t num_pages;
49 uint32_t actual;
50 uint32_t free_page_hint_cmd_id;
51 uint64_t stats[VIRTIO_BALLOON_S_NR];
52 VirtQueueElement *stats_vq_elem;
53 size_t stats_vq_offset;
54 QEMUTimer *stats_timer;
55 IOThread *iothread;
56 QEMUBH *free_page_bh;
57 /*
58 * Lock to synchronize threads to access the free page reporting related
59 * fields (e.g. free_page_hint_status).
60 */
61 QemuMutex free_page_lock;
62 QemuCond free_page_cond;
63 /*
64 * Set to block iothread to continue reading free page hints as the VM is
65 * stopped.
66 */
67 bool block_iothread;
68 NotifierWithReturn free_page_hint_notify;
69 int64_t stats_last_update;
70 int64_t stats_poll_interval;
71 uint32_t host_features;
72
73 uint32_t poison_val;
74
75 /* State of the resettable container */
76 ResettableState reset_state;
77 };
78
79 #endif