nvmm.h revision 1.3 1 /* $NetBSD: nvmm.h,v 1.3 2019/01/24 13:05:59 maxv Exp $ */
2
3 /*
4 * Copyright (c) 2018 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 enum nvmm_exit_reason {
48 NVMM_EXIT_NONE = 0x0000000000000000,
49
50 /* General. */
51 NVMM_EXIT_MEMORY = 0x0000000000000001,
52 NVMM_EXIT_IO = 0x0000000000000002,
53 NVMM_EXIT_MSR = 0x0000000000000003,
54 NVMM_EXIT_INT_READY = 0x0000000000000004,
55 NVMM_EXIT_NMI_READY = 0x0000000000000005,
56 NVMM_EXIT_HALTED = 0x0000000000000006,
57 NVMM_EXIT_SHUTDOWN = 0x0000000000000007,
58
59 /* Instructions (x86). */
60 NVMM_EXIT_MONITOR = 0x0000000000001000,
61 NVMM_EXIT_MWAIT = 0x0000000000001001,
62 NVMM_EXIT_MWAIT_COND = 0x0000000000001002,
63
64 NVMM_EXIT_INVALID = 0xFFFFFFFFFFFFFFFF
65 };
66
67 enum nvmm_exit_memory_perm {
68 NVMM_EXIT_MEMORY_READ,
69 NVMM_EXIT_MEMORY_WRITE,
70 NVMM_EXIT_MEMORY_EXEC
71 };
72
73 struct nvmm_exit_memory {
74 enum nvmm_exit_memory_perm perm;
75 gpaddr_t gpa;
76 uint8_t inst_len;
77 uint8_t inst_bytes[15];
78 uint64_t npc;
79 };
80
81 enum nvmm_exit_io_type {
82 NVMM_EXIT_IO_IN,
83 NVMM_EXIT_IO_OUT
84 };
85
86 struct nvmm_exit_io {
87 enum nvmm_exit_io_type type;
88 uint16_t port;
89 int seg;
90 uint8_t address_size;
91 uint8_t operand_size;
92 bool rep;
93 bool str;
94 uint64_t npc;
95 };
96
97 enum nvmm_exit_msr_type {
98 NVMM_EXIT_MSR_RDMSR,
99 NVMM_EXIT_MSR_WRMSR
100 };
101
102 struct nvmm_exit_msr {
103 enum nvmm_exit_msr_type type;
104 uint64_t msr;
105 uint64_t val;
106 uint64_t npc;
107 };
108
109 struct nvmm_exit_insn {
110 uint64_t npc;
111 };
112
113 struct nvmm_exit {
114 enum nvmm_exit_reason reason;
115 union {
116 struct nvmm_exit_memory mem;
117 struct nvmm_exit_io io;
118 struct nvmm_exit_msr msr;
119 struct nvmm_exit_insn insn;
120 } u;
121 uint64_t exitstate[8];
122 };
123
124 enum nvmm_event_type {
125 NVMM_EVENT_INTERRUPT_HW,
126 NVMM_EVENT_INTERRUPT_SW,
127 NVMM_EVENT_EXCEPTION
128 };
129
130 struct nvmm_event {
131 enum nvmm_event_type type;
132 uint64_t vector;
133 union {
134 /* NVMM_EVENT_INTERRUPT_HW */
135 uint8_t prio;
136
137 /* NVMM_EVENT_EXCEPTION */
138 uint64_t error;
139 } u;
140 };
141
142 #define NVMM_CAPABILITY_VERSION 1
143
144 struct nvmm_capability {
145 uint64_t version;
146 uint64_t state_size;
147 uint64_t max_machines;
148 uint64_t max_vcpus;
149 uint64_t max_ram;
150 union {
151 struct {
152 uint64_t xcr0_mask;
153 uint64_t mxcsr_mask;
154 uint64_t conf_cpuid_maxops;
155 } x86;
156 uint64_t rsvd[8];
157 } u;
158 };
159
160 #endif
161