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