1*95fbc42eSDiederik de Groot /*- 2*95fbc42eSDiederik de Groot * SPDX-License-Identifier: BSD-3-Clause 3*95fbc42eSDiederik de Groot * 4*95fbc42eSDiederik de Groot * This header is BSD licensed so anyone can use the definitions to implement 5*95fbc42eSDiederik de Groot * compatible drivers/servers. 6*95fbc42eSDiederik de Groot * 7*95fbc42eSDiederik de Groot * Redistribution and use in source and binary forms, with or without 8*95fbc42eSDiederik de Groot * modification, are permitted provided that the following conditions 9*95fbc42eSDiederik de Groot * are met: 10*95fbc42eSDiederik de Groot * 1. Redistributions of source code must retain the above copyright 11*95fbc42eSDiederik de Groot * notice, this list of conditions and the following disclaimer. 12*95fbc42eSDiederik de Groot * 2. Redistributions in binary form must reproduce the above copyright 13*95fbc42eSDiederik de Groot * notice, this list of conditions and the following disclaimer in the 14*95fbc42eSDiederik de Groot * documentation and/or other materials provided with the distribution. 15*95fbc42eSDiederik de Groot * 3. Neither the name of IBM nor the names of its contributors 16*95fbc42eSDiederik de Groot * may be used to endorse or promote products derived from this software 17*95fbc42eSDiederik de Groot * without specific prior written permission. 18*95fbc42eSDiederik de Groot * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19*95fbc42eSDiederik de Groot * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20*95fbc42eSDiederik de Groot * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21*95fbc42eSDiederik de Groot * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE 22*95fbc42eSDiederik de Groot * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23*95fbc42eSDiederik de Groot * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24*95fbc42eSDiederik de Groot * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25*95fbc42eSDiederik de Groot * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26*95fbc42eSDiederik de Groot * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27*95fbc42eSDiederik de Groot * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28*95fbc42eSDiederik de Groot * SUCH DAMAGE. 29*95fbc42eSDiederik de Groot * 30*95fbc42eSDiederik de Groot * $FreeBSD: head/sys/dev/virtio/balloon/virtio_balloon.h 326022 2017-11-20 19:36:21Z pfg $ 31*95fbc42eSDiederik de Groot */ 32*95fbc42eSDiederik de Groot /* 33*95fbc42eSDiederik de Groot * Copyright (c) 2018 The DragonFly Project. All rights reserved. 34*95fbc42eSDiederik de Groot * 35*95fbc42eSDiederik de Groot * This code is derived from software contributed to The DragonFly Project 36*95fbc42eSDiederik de Groot * by Diederik de Groot <info@talon.nl> 37*95fbc42eSDiederik de Groot * 38*95fbc42eSDiederik de Groot * Redistribution and use in source and binary forms, with or without 39*95fbc42eSDiederik de Groot * modification, are permitted provided that the following conditions 40*95fbc42eSDiederik de Groot * are met: 41*95fbc42eSDiederik de Groot * 42*95fbc42eSDiederik de Groot * 1. Redistributions of source code must retain the above copyright 43*95fbc42eSDiederik de Groot * notice, this list of conditions and the following disclaimer. 44*95fbc42eSDiederik de Groot * 2. Redistributions in binary form must reproduce the above copyright 45*95fbc42eSDiederik de Groot * notice, this list of conditions and the following disclaimer in 46*95fbc42eSDiederik de Groot * the documentation and/or other materials provided with the 47*95fbc42eSDiederik de Groot * distribution. 48*95fbc42eSDiederik de Groot * 3. Neither the name of The DragonFly Project nor the names of its 49*95fbc42eSDiederik de Groot * contributors may be used to endorse or promote products derived 50*95fbc42eSDiederik de Groot * from this software without specific, prior written permission. 51*95fbc42eSDiederik de Groot * 52*95fbc42eSDiederik de Groot * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 53*95fbc42eSDiederik de Groot * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 54*95fbc42eSDiederik de Groot * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 55*95fbc42eSDiederik de Groot * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 56*95fbc42eSDiederik de Groot * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 57*95fbc42eSDiederik de Groot * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 58*95fbc42eSDiederik de Groot * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 59*95fbc42eSDiederik de Groot * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 60*95fbc42eSDiederik de Groot * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 61*95fbc42eSDiederik de Groot * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 62*95fbc42eSDiederik de Groot * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 63*95fbc42eSDiederik de Groot * SUCH DAMAGE. 64*95fbc42eSDiederik de Groot */ 65*95fbc42eSDiederik de Groot 66*95fbc42eSDiederik de Groot /* Driver for VirtIO memory balloon devices. */ 67*95fbc42eSDiederik de Groot 68*95fbc42eSDiederik de Groot #ifndef _VIRTIO_BALLOON_H 69*95fbc42eSDiederik de Groot #define _VIRTIO_BALLOON_H 70*95fbc42eSDiederik de Groot 71*95fbc42eSDiederik de Groot /* Feature bits. */ 72*95fbc42eSDiederik de Groot #define VIRTIO_BALLOON_F_MUST_TELL_HOST 0x1 /* Tell before reclaiming pages */ 73*95fbc42eSDiederik de Groot #define VIRTIO_BALLOON_F_STATS_VQ 0x2 /* Memory stats virtqueue */ 74*95fbc42eSDiederik de Groot #define VIRTIO_BALLOON_F_DEFLATE_ON_OOM 0x3 /* Deflate on Out Of Memory */ 75*95fbc42eSDiederik de Groot 76*95fbc42eSDiederik de Groot /* Size of a PFN in the balloon interface. */ 77*95fbc42eSDiederik de Groot #define VIRTIO_BALLOON_PFN_SHIFT 12 78*95fbc42eSDiederik de Groot 79*95fbc42eSDiederik de Groot struct virtio_balloon_config { 80*95fbc42eSDiederik de Groot /* Number of pages host wants Guest to give up. */ 81*95fbc42eSDiederik de Groot uint32_t num_pages; 82*95fbc42eSDiederik de Groot 83*95fbc42eSDiederik de Groot /* Number of pages we've actually got in balloon. */ 84*95fbc42eSDiederik de Groot uint32_t actual; 85*95fbc42eSDiederik de Groot }; 86*95fbc42eSDiederik de Groot 87*95fbc42eSDiederik de Groot #define VTBALLOON_S_SWAP_IN 0 /* The amount of memory that has been swapped in (in bytes) */ 88*95fbc42eSDiederik de Groot #define VTBALLOON_S_SWAP_OUT 1 /* The amount of memory that has been swapped out to disk (in bytes). */ 89*95fbc42eSDiederik de Groot #define VTBALLOON_S_MAJFLT 2 /* The number of major page faults that have occurred. */ 90*95fbc42eSDiederik de Groot #define VTBALLOON_S_MINFLT 3 /* The number of minor page faults that have occurred. */ 91*95fbc42eSDiederik de Groot #define VTBALLOON_S_MEMFREE 4 /* The amount of memory not being used for any purpose (in bytes). */ 92*95fbc42eSDiederik de Groot #define VTBALLOON_S_MEMTOT 5 /* The total amount of memory available (in bytes). */ 93*95fbc42eSDiederik de Groot #define VTBALLOON_S_AVAIL 6 /* The amount of availabe memory (in bytes) as in linux-proc */ 94*95fbc42eSDiederik de Groot #define VTBALLOON_S_CACHES 7 /* Disk-File caches */ 95*95fbc42eSDiederik de Groot #define VTBALLOON_S_HTLB_PGALLOC 8 /* Hugetlb page allocations */ 96*95fbc42eSDiederik de Groot #define VTBALLOON_S_HTLB_PGFAIL 9 /* Hugetlb page allocation failures */ 97*95fbc42eSDiederik de Groot #define VTBALLOON_S_NR 10 98*95fbc42eSDiederik de Groot 99*95fbc42eSDiederik de Groot #define VTBALLOON_S_NAMES_WITH_PREFIX(VTBALLOON_S_NAMES_prefix) { \ 100*95fbc42eSDiederik de Groot VTBALLOON_S_NAMES_prefix "swap-in", \ 101*95fbc42eSDiederik de Groot VTBALLOON_S_NAMES_prefix "swap-out", \ 102*95fbc42eSDiederik de Groot VTBALLOON_S_NAMES_prefix "major-faults", \ 103*95fbc42eSDiederik de Groot VTBALLOON_S_NAMES_prefix "minor-faults", \ 104*95fbc42eSDiederik de Groot VTBALLOON_S_NAMES_prefix "free-memory", \ 105*95fbc42eSDiederik de Groot VTBALLOON_S_NAMES_prefix "total-memory", \ 106*95fbc42eSDiederik de Groot VTBALLOON_S_NAMES_prefix "available-memory", \ 107*95fbc42eSDiederik de Groot VTBALLOON_S_NAMES_prefix "disk-file-caches", \ 108*95fbc42eSDiederik de Groot VTBALLOON_S_NAMES_prefix "hugetlb-allocations", \ 109*95fbc42eSDiederik de Groot VTBALLOON_S_NAMES_prefix "hugetlb-failures" \ 110*95fbc42eSDiederik de Groot } 111*95fbc42eSDiederik de Groot #define VTBALLOON_S_NAMES VTBALLOON_S_NAMES_WITH_PREFIX("") 112*95fbc42eSDiederik de Groot 113*95fbc42eSDiederik de Groot /* 114*95fbc42eSDiederik de Groot * Memory statistics structure. 115*95fbc42eSDiederik de Groot * Driver fills an array of these structures and passes to device. 116*95fbc42eSDiederik de Groot * 117*95fbc42eSDiederik de Groot * NOTE: fields are laid out in a way that would make compiler add padding 118*95fbc42eSDiederik de Groot * between and after fields, but the virtio specification does not allow 119*95fbc42eSDiederik de Groot * for this. So the struct has to be packed. 120*95fbc42eSDiederik de Groot */ 121*95fbc42eSDiederik de Groot struct vtballoon_stat { 122*95fbc42eSDiederik de Groot uint16_t tag; 123*95fbc42eSDiederik de Groot uint64_t val; 124*95fbc42eSDiederik de Groot } __packed; 125*95fbc42eSDiederik de Groot 126*95fbc42eSDiederik de Groot #endif /* _VIRTIO_BALLOON_H */ 127