4 * Copyright IBM, Corp. 2007-2008
7 * Anthony Liguori <aliguori@us.ibm.com>
8 * Rusty Russell <rusty@rustcorp.com.au>
10 * This work is licensed under the terms of the GNU GPL, version 2. See
11 * the COPYING file in the top-level directory.
15 #ifndef _QEMU_VIRTIO_BALLOON_H
16 #define _QEMU_VIRTIO_BALLOON_H
18 #include "hw/virtio.h"
19 #include "hw/pci/pci.h"
21 /* from Linux's linux/virtio_balloon.h */
23 /* The ID for virtio_balloon */
24 #define VIRTIO_ID_BALLOON 5
26 /* The feature bitmap for virtio balloon */
27 #define VIRTIO_BALLOON_F_MUST_TELL_HOST 0 /* Tell before reclaiming pages */
28 #define VIRTIO_BALLOON_F_STATS_VQ 1 /* Memory stats virtqueue */
30 /* Size of a PFN in the balloon interface. */
31 #define VIRTIO_BALLOON_PFN_SHIFT 12
33 struct virtio_balloon_config
35 /* Number of pages host wants Guest to give up. */
37 /* Number of pages we've actually got in balloon. */
41 /* Memory Statistics */
42 #define VIRTIO_BALLOON_S_SWAP_IN 0 /* Amount of memory swapped in */
43 #define VIRTIO_BALLOON_S_SWAP_OUT 1 /* Amount of memory swapped out */
44 #define VIRTIO_BALLOON_S_MAJFLT 2 /* Number of major faults */
45 #define VIRTIO_BALLOON_S_MINFLT 3 /* Number of minor faults */
46 #define VIRTIO_BALLOON_S_MEMFREE 4 /* Total amount of free memory */
47 #define VIRTIO_BALLOON_S_MEMTOT 5 /* Total amount of memory */
48 #define VIRTIO_BALLOON_S_NR 6
50 typedef struct VirtIOBalloonStat
{
53 } QEMU_PACKED VirtIOBalloonStat
;
55 typedef struct VirtIOBalloon
{
57 VirtQueue
*ivq
, *dvq
, *svq
;
60 uint64_t stats
[VIRTIO_BALLOON_S_NR
];
61 VirtQueueElement stats_vq_elem
;
62 size_t stats_vq_offset
;
63 QEMUTimer
*stats_timer
;
64 int64_t stats_last_update
;
65 int64_t stats_poll_interval
;