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 */ 37da054c64SPaolo Bonzini #define VIRTIO_BALLOON_F_FREE_PAGE_HINT 3 /* VQ to report free pages */ 38da054c64SPaolo Bonzini #define VIRTIO_BALLOON_F_PAGE_POISON 4 /* Guest is using page poisoning */ 39*dc6f8d45SCornelia Huck #define VIRTIO_BALLOON_F_REPORTING 5 /* Page reporting virtqueue */ 409fbe302bSMichael S. Tsirkin 419fbe302bSMichael S. Tsirkin /* Size of a PFN in the balloon interface. */ 429fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_PFN_SHIFT 12 439fbe302bSMichael S. Tsirkin 44da054c64SPaolo Bonzini #define VIRTIO_BALLOON_CMD_ID_STOP 0 45da054c64SPaolo Bonzini #define VIRTIO_BALLOON_CMD_ID_DONE 1 469fbe302bSMichael S. Tsirkin struct virtio_balloon_config { 479fbe302bSMichael S. Tsirkin /* Number of pages host wants Guest to give up. */ 489fbe302bSMichael S. Tsirkin uint32_t num_pages; 499fbe302bSMichael S. Tsirkin /* Number of pages we've actually got in balloon. */ 509fbe302bSMichael S. Tsirkin uint32_t actual; 51*dc6f8d45SCornelia Huck /* 52*dc6f8d45SCornelia Huck * Free page hint command id, readonly by guest. 53*dc6f8d45SCornelia Huck * Was previously named free_page_report_cmd_id so we 54*dc6f8d45SCornelia Huck * need to carry that name for legacy support. 55*dc6f8d45SCornelia Huck */ 56*dc6f8d45SCornelia Huck union { 57*dc6f8d45SCornelia Huck uint32_t free_page_hint_cmd_id; 58*dc6f8d45SCornelia Huck uint32_t free_page_report_cmd_id; /* deprecated */ 59*dc6f8d45SCornelia Huck }; 60da054c64SPaolo Bonzini /* Stores PAGE_POISON if page poisoning is in use */ 61da054c64SPaolo Bonzini uint32_t poison_val; 629fbe302bSMichael S. Tsirkin }; 639fbe302bSMichael S. Tsirkin 649fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_SWAP_IN 0 /* Amount of memory swapped in */ 659fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_SWAP_OUT 1 /* Amount of memory swapped out */ 669fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_MAJFLT 2 /* Number of major faults */ 679fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_MINFLT 3 /* Number of minor faults */ 689fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_MEMFREE 4 /* Total amount of free memory */ 699fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_MEMTOT 5 /* Total amount of memory */ 70b89485a5SPaolo Bonzini #define VIRTIO_BALLOON_S_AVAIL 6 /* Available memory as in /proc */ 71bf1e7140STomáš Golembiovský #define VIRTIO_BALLOON_S_CACHES 7 /* Disk caches */ 72b7b12644SJonathan Helman #define VIRTIO_BALLOON_S_HTLB_PGALLOC 8 /* Hugetlb page allocations */ 73b7b12644SJonathan Helman #define VIRTIO_BALLOON_S_HTLB_PGFAIL 9 /* Hugetlb page allocation failures */ 74b7b12644SJonathan Helman #define VIRTIO_BALLOON_S_NR 10 759fbe302bSMichael S. Tsirkin 7665a6d8ddSPeter Maydell #define VIRTIO_BALLOON_S_NAMES_WITH_PREFIX(VIRTIO_BALLOON_S_NAMES_prefix) { \ 7765a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "swap-in", \ 7865a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "swap-out", \ 7965a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "major-faults", \ 8065a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "minor-faults", \ 8165a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "free-memory", \ 8265a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "total-memory", \ 8365a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "available-memory", \ 8465a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "disk-caches", \ 8565a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "hugetlb-allocations", \ 8665a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "hugetlb-failures" \ 8765a6d8ddSPeter Maydell } 8865a6d8ddSPeter Maydell 8965a6d8ddSPeter Maydell #define VIRTIO_BALLOON_S_NAMES VIRTIO_BALLOON_S_NAMES_WITH_PREFIX("") 9065a6d8ddSPeter Maydell 917a52ce8aSCornelia Huck /* 927a52ce8aSCornelia Huck * Memory statistics structure. 937a52ce8aSCornelia Huck * Driver fills an array of these structures and passes to device. 947a52ce8aSCornelia Huck * 957a52ce8aSCornelia Huck * NOTE: fields are laid out in a way that would make compiler add padding 967a52ce8aSCornelia Huck * between and after fields, so we have to use compiler-specific attributes to 977a52ce8aSCornelia Huck * pack it, to disable this padding. This also often causes compiler to 987a52ce8aSCornelia Huck * generate suboptimal code. 997a52ce8aSCornelia Huck * 1007a52ce8aSCornelia Huck * We maintain this statistics structure format for backwards compatibility, 1017a52ce8aSCornelia Huck * but don't follow this example. 1027a52ce8aSCornelia Huck * 1037a52ce8aSCornelia Huck * If implementing a similar structure, do something like the below instead: 1047a52ce8aSCornelia Huck * struct virtio_balloon_stat { 1057a52ce8aSCornelia Huck * __virtio16 tag; 1067a52ce8aSCornelia Huck * uint8_t reserved[6]; 1077a52ce8aSCornelia Huck * __virtio64 val; 1087a52ce8aSCornelia Huck * }; 1097a52ce8aSCornelia Huck * 1107a52ce8aSCornelia Huck * In other words, add explicit reserved fields to align field and 1117a52ce8aSCornelia Huck * structure boundaries at field size, avoiding compiler padding 1127a52ce8aSCornelia Huck * without the packed attribute. 1137a52ce8aSCornelia Huck */ 1149fbe302bSMichael S. Tsirkin struct virtio_balloon_stat { 1157a52ce8aSCornelia Huck __virtio16 tag; 1167a52ce8aSCornelia Huck __virtio64 val; 1179fbe302bSMichael S. Tsirkin } QEMU_PACKED; 1189fbe302bSMichael S. Tsirkin 1199fbe302bSMichael S. Tsirkin #endif /* _LINUX_VIRTIO_BALLOON_H */ 120