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 */
55*bf1e7140STomáš Golembiovský #define VIRTIO_BALLOON_S_CACHES   7   /* Disk caches */
56*bf1e7140STomáš Golembiovský #define VIRTIO_BALLOON_S_NR       8
579fbe302bSMichael S. Tsirkin 
587a52ce8aSCornelia Huck /*
597a52ce8aSCornelia Huck  * Memory statistics structure.
607a52ce8aSCornelia Huck  * Driver fills an array of these structures and passes to device.
617a52ce8aSCornelia Huck  *
627a52ce8aSCornelia Huck  * NOTE: fields are laid out in a way that would make compiler add padding
637a52ce8aSCornelia Huck  * between and after fields, so we have to use compiler-specific attributes to
647a52ce8aSCornelia Huck  * pack it, to disable this padding. This also often causes compiler to
657a52ce8aSCornelia Huck  * generate suboptimal code.
667a52ce8aSCornelia Huck  *
677a52ce8aSCornelia Huck  * We maintain this statistics structure format for backwards compatibility,
687a52ce8aSCornelia Huck  * but don't follow this example.
697a52ce8aSCornelia Huck  *
707a52ce8aSCornelia Huck  * If implementing a similar structure, do something like the below instead:
717a52ce8aSCornelia Huck  *     struct virtio_balloon_stat {
727a52ce8aSCornelia Huck  *         __virtio16 tag;
737a52ce8aSCornelia Huck  *         uint8_t reserved[6];
747a52ce8aSCornelia Huck  *         __virtio64 val;
757a52ce8aSCornelia Huck  *     };
767a52ce8aSCornelia Huck  *
777a52ce8aSCornelia Huck  * In other words, add explicit reserved fields to align field and
787a52ce8aSCornelia Huck  * structure boundaries at field size, avoiding compiler padding
797a52ce8aSCornelia Huck  * without the packed attribute.
807a52ce8aSCornelia Huck  */
819fbe302bSMichael S. Tsirkin struct virtio_balloon_stat {
827a52ce8aSCornelia Huck 	__virtio16 tag;
837a52ce8aSCornelia Huck 	__virtio64 val;
849fbe302bSMichael S. Tsirkin } QEMU_PACKED;
859fbe302bSMichael S. Tsirkin 
869fbe302bSMichael S. Tsirkin #endif /* _LINUX_VIRTIO_BALLOON_H */
87