19fbe302bSMichael S. Tsirkin #ifndef _LINUX_VIRTIO_BALLOON_H
29fbe302bSMichael S. Tsirkin #define _LINUX_VIRTIO_BALLOON_H
39fbe302bSMichael S. Tsirkin /* This header is BSD licensed so anyone can use the definitions to implement
49fbe302bSMichael S. Tsirkin  * compatible drivers/servers.
59fbe302bSMichael S. Tsirkin  *
69fbe302bSMichael S. Tsirkin  * Redistribution and use in source and binary forms, with or without
79fbe302bSMichael S. Tsirkin  * modification, are permitted provided that the following conditions
89fbe302bSMichael S. Tsirkin  * are met:
99fbe302bSMichael S. Tsirkin  * 1. Redistributions of source code must retain the above copyright
109fbe302bSMichael S. Tsirkin  *    notice, this list of conditions and the following disclaimer.
119fbe302bSMichael S. Tsirkin  * 2. Redistributions in binary form must reproduce the above copyright
129fbe302bSMichael S. Tsirkin  *    notice, this list of conditions and the following disclaimer in the
139fbe302bSMichael S. Tsirkin  *    documentation and/or other materials provided with the distribution.
149fbe302bSMichael S. Tsirkin  * 3. Neither the name of IBM nor the names of its contributors
159fbe302bSMichael S. Tsirkin  *    may be used to endorse or promote products derived from this software
169fbe302bSMichael S. Tsirkin  *    without specific prior written permission.
179fbe302bSMichael S. Tsirkin  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
189fbe302bSMichael S. Tsirkin  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199fbe302bSMichael S. Tsirkin  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
209fbe302bSMichael S. Tsirkin  * ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
219fbe302bSMichael S. Tsirkin  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
229fbe302bSMichael S. Tsirkin  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
239fbe302bSMichael S. Tsirkin  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
249fbe302bSMichael S. Tsirkin  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
259fbe302bSMichael S. Tsirkin  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
269fbe302bSMichael S. Tsirkin  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
279fbe302bSMichael S. Tsirkin  * SUCH DAMAGE. */
287a52ce8aSCornelia Huck #include "standard-headers/linux/types.h"
2925b8b39bSAlexey Kardashevskiy #include "standard-headers/linux/virtio_types.h"
309fbe302bSMichael S. Tsirkin #include "standard-headers/linux/virtio_ids.h"
319fbe302bSMichael S. Tsirkin #include "standard-headers/linux/virtio_config.h"
329fbe302bSMichael S. Tsirkin 
339fbe302bSMichael S. Tsirkin /* The feature bitmap for virtio balloon */
349fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_F_MUST_TELL_HOST	0 /* Tell before reclaiming pages */
359fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_F_STATS_VQ	1 /* Memory Stats virtqueue */
369fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_F_DEFLATE_ON_OOM	2 /* Deflate balloon on OOM */
379fbe302bSMichael S. Tsirkin 
389fbe302bSMichael S. Tsirkin /* Size of a PFN in the balloon interface. */
399fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_PFN_SHIFT 12
409fbe302bSMichael S. Tsirkin 
419fbe302bSMichael S. Tsirkin struct virtio_balloon_config {
429fbe302bSMichael S. Tsirkin 	/* Number of pages host wants Guest to give up. */
439fbe302bSMichael S. Tsirkin 	uint32_t num_pages;
449fbe302bSMichael S. Tsirkin 	/* Number of pages we've actually got in balloon. */
459fbe302bSMichael S. Tsirkin 	uint32_t actual;
469fbe302bSMichael S. Tsirkin };
479fbe302bSMichael S. Tsirkin 
489fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_SWAP_IN  0   /* Amount of memory swapped in */
499fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_SWAP_OUT 1   /* Amount of memory swapped out */
509fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_MAJFLT   2   /* Number of major faults */
519fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_MINFLT   3   /* Number of minor faults */
529fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_MEMFREE  4   /* Total amount of free memory */
539fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_MEMTOT   5   /* Total amount of memory */
54b89485a5SPaolo Bonzini #define VIRTIO_BALLOON_S_AVAIL    6   /* Available memory as in /proc */
55bf1e7140STomáš Golembiovský #define VIRTIO_BALLOON_S_CACHES   7   /* Disk caches */
56b7b12644SJonathan Helman #define VIRTIO_BALLOON_S_HTLB_PGALLOC  8  /* Hugetlb page allocations */
57b7b12644SJonathan Helman #define VIRTIO_BALLOON_S_HTLB_PGFAIL   9  /* Hugetlb page allocation failures */
58b7b12644SJonathan Helman #define VIRTIO_BALLOON_S_NR       10
599fbe302bSMichael S. Tsirkin 
60*65a6d8ddSPeter Maydell #define VIRTIO_BALLOON_S_NAMES_WITH_PREFIX(VIRTIO_BALLOON_S_NAMES_prefix) { \
61*65a6d8ddSPeter Maydell 	VIRTIO_BALLOON_S_NAMES_prefix "swap-in", \
62*65a6d8ddSPeter Maydell 	VIRTIO_BALLOON_S_NAMES_prefix "swap-out", \
63*65a6d8ddSPeter Maydell 	VIRTIO_BALLOON_S_NAMES_prefix "major-faults", \
64*65a6d8ddSPeter Maydell 	VIRTIO_BALLOON_S_NAMES_prefix "minor-faults", \
65*65a6d8ddSPeter Maydell 	VIRTIO_BALLOON_S_NAMES_prefix "free-memory", \
66*65a6d8ddSPeter Maydell 	VIRTIO_BALLOON_S_NAMES_prefix "total-memory", \
67*65a6d8ddSPeter Maydell 	VIRTIO_BALLOON_S_NAMES_prefix "available-memory", \
68*65a6d8ddSPeter Maydell 	VIRTIO_BALLOON_S_NAMES_prefix "disk-caches", \
69*65a6d8ddSPeter Maydell 	VIRTIO_BALLOON_S_NAMES_prefix "hugetlb-allocations", \
70*65a6d8ddSPeter Maydell 	VIRTIO_BALLOON_S_NAMES_prefix "hugetlb-failures" \
71*65a6d8ddSPeter Maydell }
72*65a6d8ddSPeter Maydell 
73*65a6d8ddSPeter Maydell #define VIRTIO_BALLOON_S_NAMES VIRTIO_BALLOON_S_NAMES_WITH_PREFIX("")
74*65a6d8ddSPeter Maydell 
757a52ce8aSCornelia Huck /*
767a52ce8aSCornelia Huck  * Memory statistics structure.
777a52ce8aSCornelia Huck  * Driver fills an array of these structures and passes to device.
787a52ce8aSCornelia Huck  *
797a52ce8aSCornelia Huck  * NOTE: fields are laid out in a way that would make compiler add padding
807a52ce8aSCornelia Huck  * between and after fields, so we have to use compiler-specific attributes to
817a52ce8aSCornelia Huck  * pack it, to disable this padding. This also often causes compiler to
827a52ce8aSCornelia Huck  * generate suboptimal code.
837a52ce8aSCornelia Huck  *
847a52ce8aSCornelia Huck  * We maintain this statistics structure format for backwards compatibility,
857a52ce8aSCornelia Huck  * but don't follow this example.
867a52ce8aSCornelia Huck  *
877a52ce8aSCornelia Huck  * If implementing a similar structure, do something like the below instead:
887a52ce8aSCornelia Huck  *     struct virtio_balloon_stat {
897a52ce8aSCornelia Huck  *         __virtio16 tag;
907a52ce8aSCornelia Huck  *         uint8_t reserved[6];
917a52ce8aSCornelia Huck  *         __virtio64 val;
927a52ce8aSCornelia Huck  *     };
937a52ce8aSCornelia Huck  *
947a52ce8aSCornelia Huck  * In other words, add explicit reserved fields to align field and
957a52ce8aSCornelia Huck  * structure boundaries at field size, avoiding compiler padding
967a52ce8aSCornelia Huck  * without the packed attribute.
977a52ce8aSCornelia Huck  */
989fbe302bSMichael S. Tsirkin struct virtio_balloon_stat {
997a52ce8aSCornelia Huck 	__virtio16 tag;
1007a52ce8aSCornelia Huck 	__virtio64 val;
1019fbe302bSMichael S. Tsirkin } QEMU_PACKED;
1029fbe302bSMichael S. Tsirkin 
1039fbe302bSMichael S. Tsirkin #endif /* _LINUX_VIRTIO_BALLOON_H */
104