nvmm.h revision 1.5 1 /* $NetBSD: nvmm.h,v 1.5 2019/03/21 20:21:40 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 struct nvmm_exit_memory {
68 int prot;
69 gpaddr_t gpa;
70 uint8_t inst_len;
71 uint8_t inst_bytes[15];
72 };
73
74 enum nvmm_exit_io_type {
75 NVMM_EXIT_IO_IN,
76 NVMM_EXIT_IO_OUT
77 };
78
79 struct nvmm_exit_io {
80 enum nvmm_exit_io_type type;
81 uint16_t port;
82 int seg;
83 uint8_t address_size;
84 uint8_t operand_size;
85 bool rep;
86 bool str;
87 uint64_t npc;
88 };
89
90 enum nvmm_exit_msr_type {
91 NVMM_EXIT_MSR_RDMSR,
92 NVMM_EXIT_MSR_WRMSR
93 };
94
95 struct nvmm_exit_msr {
96 enum nvmm_exit_msr_type type;
97 uint64_t msr;
98 uint64_t val;
99 uint64_t npc;
100 };
101
102 struct nvmm_exit_insn {
103 uint64_t npc;
104 };
105
106 struct nvmm_exit {
107 enum nvmm_exit_reason reason;
108 union {
109 struct nvmm_exit_memory mem;
110 struct nvmm_exit_io io;
111 struct nvmm_exit_msr msr;
112 struct nvmm_exit_insn insn;
113 } u;
114 uint64_t exitstate[8];
115 };
116
117 enum nvmm_event_type {
118 NVMM_EVENT_INTERRUPT_HW,
119 NVMM_EVENT_INTERRUPT_SW,
120 NVMM_EVENT_EXCEPTION
121 };
122
123 struct nvmm_event {
124 enum nvmm_event_type type;
125 uint64_t vector;
126 union {
127 /* NVMM_EVENT_INTERRUPT_HW */
128 uint8_t prio;
129
130 /* NVMM_EVENT_EXCEPTION */
131 uint64_t error;
132 } u;
133 };
134
135 #define NVMM_CAPABILITY_VERSION 1
136
137 struct nvmm_capability {
138 uint64_t version;
139 uint64_t state_size;
140 uint64_t max_machines;
141 uint64_t max_vcpus;
142 uint64_t max_ram;
143 union {
144 struct {
145 uint64_t xcr0_mask;
146 uint64_t mxcsr_mask;
147 uint64_t conf_cpuid_maxops;
148 } x86;
149 uint64_t rsvd[8];
150 } u;
151 };
152
153 #endif
154