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 */ 37*da054c64SPaolo Bonzini #define VIRTIO_BALLOON_F_FREE_PAGE_HINT 3 /* VQ to report free pages */ 38*da054c64SPaolo Bonzini #define VIRTIO_BALLOON_F_PAGE_POISON 4 /* Guest is using page poisoning */ 399fbe302bSMichael S. Tsirkin 409fbe302bSMichael S. Tsirkin /* Size of a PFN in the balloon interface. */ 419fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_PFN_SHIFT 12 429fbe302bSMichael S. Tsirkin 43*da054c64SPaolo Bonzini #define VIRTIO_BALLOON_CMD_ID_STOP 0 44*da054c64SPaolo Bonzini #define VIRTIO_BALLOON_CMD_ID_DONE 1 459fbe302bSMichael S. Tsirkin struct virtio_balloon_config { 469fbe302bSMichael S. Tsirkin /* Number of pages host wants Guest to give up. */ 479fbe302bSMichael S. Tsirkin uint32_t num_pages; 489fbe302bSMichael S. Tsirkin /* Number of pages we've actually got in balloon. */ 499fbe302bSMichael S. Tsirkin uint32_t actual; 50*da054c64SPaolo Bonzini /* Free page report command id, readonly by guest */ 51*da054c64SPaolo Bonzini uint32_t free_page_report_cmd_id; 52*da054c64SPaolo Bonzini /* Stores PAGE_POISON if page poisoning is in use */ 53*da054c64SPaolo Bonzini uint32_t poison_val; 549fbe302bSMichael S. Tsirkin }; 559fbe302bSMichael S. Tsirkin 569fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_SWAP_IN 0 /* Amount of memory swapped in */ 579fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_SWAP_OUT 1 /* Amount of memory swapped out */ 589fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_MAJFLT 2 /* Number of major faults */ 599fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_MINFLT 3 /* Number of minor faults */ 609fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_MEMFREE 4 /* Total amount of free memory */ 619fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_MEMTOT 5 /* Total amount of memory */ 62b89485a5SPaolo Bonzini #define VIRTIO_BALLOON_S_AVAIL 6 /* Available memory as in /proc */ 63bf1e7140STomáš Golembiovský #define VIRTIO_BALLOON_S_CACHES 7 /* Disk caches */ 64b7b12644SJonathan Helman #define VIRTIO_BALLOON_S_HTLB_PGALLOC 8 /* Hugetlb page allocations */ 65b7b12644SJonathan Helman #define VIRTIO_BALLOON_S_HTLB_PGFAIL 9 /* Hugetlb page allocation failures */ 66b7b12644SJonathan Helman #define VIRTIO_BALLOON_S_NR 10 679fbe302bSMichael S. Tsirkin 6865a6d8ddSPeter Maydell #define VIRTIO_BALLOON_S_NAMES_WITH_PREFIX(VIRTIO_BALLOON_S_NAMES_prefix) { \ 6965a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "swap-in", \ 7065a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "swap-out", \ 7165a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "major-faults", \ 7265a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "minor-faults", \ 7365a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "free-memory", \ 7465a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "total-memory", \ 7565a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "available-memory", \ 7665a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "disk-caches", \ 7765a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "hugetlb-allocations", \ 7865a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "hugetlb-failures" \ 7965a6d8ddSPeter Maydell } 8065a6d8ddSPeter Maydell 8165a6d8ddSPeter Maydell #define VIRTIO_BALLOON_S_NAMES VIRTIO_BALLOON_S_NAMES_WITH_PREFIX("") 8265a6d8ddSPeter Maydell 837a52ce8aSCornelia Huck /* 847a52ce8aSCornelia Huck * Memory statistics structure. 857a52ce8aSCornelia Huck * Driver fills an array of these structures and passes to device. 867a52ce8aSCornelia Huck * 877a52ce8aSCornelia Huck * NOTE: fields are laid out in a way that would make compiler add padding 887a52ce8aSCornelia Huck * between and after fields, so we have to use compiler-specific attributes to 897a52ce8aSCornelia Huck * pack it, to disable this padding. This also often causes compiler to 907a52ce8aSCornelia Huck * generate suboptimal code. 917a52ce8aSCornelia Huck * 927a52ce8aSCornelia Huck * We maintain this statistics structure format for backwards compatibility, 937a52ce8aSCornelia Huck * but don't follow this example. 947a52ce8aSCornelia Huck * 957a52ce8aSCornelia Huck * If implementing a similar structure, do something like the below instead: 967a52ce8aSCornelia Huck * struct virtio_balloon_stat { 977a52ce8aSCornelia Huck * __virtio16 tag; 987a52ce8aSCornelia Huck * uint8_t reserved[6]; 997a52ce8aSCornelia Huck * __virtio64 val; 1007a52ce8aSCornelia Huck * }; 1017a52ce8aSCornelia Huck * 1027a52ce8aSCornelia Huck * In other words, add explicit reserved fields to align field and 1037a52ce8aSCornelia Huck * structure boundaries at field size, avoiding compiler padding 1047a52ce8aSCornelia Huck * without the packed attribute. 1057a52ce8aSCornelia Huck */ 1069fbe302bSMichael S. Tsirkin struct virtio_balloon_stat { 1077a52ce8aSCornelia Huck __virtio16 tag; 1087a52ce8aSCornelia Huck __virtio64 val; 1099fbe302bSMichael S. Tsirkin } QEMU_PACKED; 1109fbe302bSMichael S. Tsirkin 1119fbe302bSMichael S. Tsirkin #endif /* _LINUX_VIRTIO_BALLOON_H */ 112