1 /* 2 * Copyright (c) 2018-2021 Maxime Villard, m00nbsd.net 3 * All rights reserved. 4 * 5 * This code is part of the NVMM hypervisor. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #ifndef _NVMM_H_ 30 #define _NVMM_H_ 31 32 #include <sys/cdefs.h> 33 #include <sys/types.h> 34 35 #ifndef _KERNEL 36 #include <stdbool.h> 37 #endif 38 39 typedef uint64_t gpaddr_t; 40 typedef uint64_t gvaddr_t; 41 42 typedef uint32_t nvmm_machid_t; 43 typedef uint32_t nvmm_cpuid_t; 44 45 #undef CTASSERT 46 #define CTASSERT(x) NVMM_CTASSERT(x, __LINE__) 47 #define NVMM_CTASSERT(x, y) NVMM__CTASSERT(x, y) 48 #define NVMM__CTASSERT(x, y) typedef char __assert ## y[(x) ? 1 : -1] __unused 49 50 #if defined(__x86_64__) 51 #if defined(__NetBSD__) 52 #include <dev/nvmm/x86/nvmm_x86.h> 53 #elif defined(__DragonFly__) 54 #include <dev/virtual/nvmm/x86/nvmm_x86.h> 55 #endif 56 #endif /* __x86_64__ */ 57 58 #define NVMM_KERN_VERSION 3 59 60 struct nvmm_capability { 61 uint32_t version; 62 uint32_t state_size; 63 uint32_t comm_size; 64 uint32_t max_machines; 65 uint32_t max_vcpus; 66 uint64_t max_ram; 67 struct nvmm_cap_md arch; 68 }; 69 70 /* Machine configuration slots. */ 71 #define NVMM_MACH_CONF_LIBNVMM_BEGIN 0 72 #define NVMM_MACH_CONF_MI_BEGIN 100 73 #define NVMM_MACH_CONF_MD_BEGIN 200 74 #define NVMM_MACH_CONF_MD(op) (op - NVMM_MACH_CONF_MD_BEGIN) 75 76 /* VCPU configuration slots. */ 77 #define NVMM_VCPU_CONF_LIBNVMM_BEGIN 0 78 #define NVMM_VCPU_CONF_MI_BEGIN 100 79 #define NVMM_VCPU_CONF_MD_BEGIN 200 80 #define NVMM_VCPU_CONF_MD(op) (op - NVMM_VCPU_CONF_MD_BEGIN) 81 82 struct nvmm_comm_page { 83 /* State. */ 84 uint64_t state_wanted; 85 uint64_t state_cached; 86 uint64_t state_commit; 87 struct nvmm_vcpu_state state; 88 89 /* Event. */ 90 bool event_commit; 91 struct nvmm_vcpu_event event; 92 }; 93 94 #endif 95