nvmm.h revision 1.6 1 1.6 maxv /* $NetBSD: nvmm.h,v 1.6 2019/04/24 18:19:28 maxv Exp $ */
2 1.1 maxv
3 1.1 maxv /*
4 1.1 maxv * Copyright (c) 2018 The NetBSD Foundation, Inc.
5 1.1 maxv * All rights reserved.
6 1.1 maxv *
7 1.1 maxv * This code is derived from software contributed to The NetBSD Foundation
8 1.1 maxv * by Maxime Villard.
9 1.1 maxv *
10 1.1 maxv * Redistribution and use in source and binary forms, with or without
11 1.1 maxv * modification, are permitted provided that the following conditions
12 1.1 maxv * are met:
13 1.1 maxv * 1. Redistributions of source code must retain the above copyright
14 1.1 maxv * notice, this list of conditions and the following disclaimer.
15 1.1 maxv * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 maxv * notice, this list of conditions and the following disclaimer in the
17 1.1 maxv * documentation and/or other materials provided with the distribution.
18 1.1 maxv *
19 1.1 maxv * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 maxv * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 maxv * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 maxv * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 maxv * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 maxv * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 maxv * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 maxv * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 maxv * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 maxv * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 maxv * POSSIBILITY OF SUCH DAMAGE.
30 1.1 maxv */
31 1.1 maxv
32 1.1 maxv #ifndef _NVMM_H_
33 1.1 maxv #define _NVMM_H_
34 1.1 maxv
35 1.1 maxv #include <sys/types.h>
36 1.1 maxv
37 1.1 maxv #ifndef _KERNEL
38 1.1 maxv #include <stdbool.h>
39 1.1 maxv #endif
40 1.1 maxv
41 1.1 maxv typedef uint64_t gpaddr_t;
42 1.1 maxv typedef uint64_t gvaddr_t;
43 1.1 maxv
44 1.1 maxv typedef uint32_t nvmm_machid_t;
45 1.1 maxv typedef uint32_t nvmm_cpuid_t;
46 1.1 maxv
47 1.1 maxv enum nvmm_exit_reason {
48 1.1 maxv NVMM_EXIT_NONE = 0x0000000000000000,
49 1.1 maxv
50 1.1 maxv /* General. */
51 1.1 maxv NVMM_EXIT_MEMORY = 0x0000000000000001,
52 1.1 maxv NVMM_EXIT_IO = 0x0000000000000002,
53 1.1 maxv NVMM_EXIT_MSR = 0x0000000000000003,
54 1.1 maxv NVMM_EXIT_INT_READY = 0x0000000000000004,
55 1.1 maxv NVMM_EXIT_NMI_READY = 0x0000000000000005,
56 1.3 maxv NVMM_EXIT_HALTED = 0x0000000000000006,
57 1.3 maxv NVMM_EXIT_SHUTDOWN = 0x0000000000000007,
58 1.1 maxv
59 1.1 maxv /* Instructions (x86). */
60 1.3 maxv NVMM_EXIT_MONITOR = 0x0000000000001000,
61 1.3 maxv NVMM_EXIT_MWAIT = 0x0000000000001001,
62 1.3 maxv NVMM_EXIT_MWAIT_COND = 0x0000000000001002,
63 1.1 maxv
64 1.1 maxv NVMM_EXIT_INVALID = 0xFFFFFFFFFFFFFFFF
65 1.1 maxv };
66 1.1 maxv
67 1.1 maxv struct nvmm_exit_memory {
68 1.5 maxv int prot;
69 1.1 maxv gpaddr_t gpa;
70 1.1 maxv uint8_t inst_len;
71 1.1 maxv uint8_t inst_bytes[15];
72 1.1 maxv };
73 1.1 maxv
74 1.1 maxv enum nvmm_exit_io_type {
75 1.1 maxv NVMM_EXIT_IO_IN,
76 1.1 maxv NVMM_EXIT_IO_OUT
77 1.1 maxv };
78 1.1 maxv
79 1.1 maxv struct nvmm_exit_io {
80 1.1 maxv enum nvmm_exit_io_type type;
81 1.1 maxv uint16_t port;
82 1.1 maxv int seg;
83 1.1 maxv uint8_t address_size;
84 1.1 maxv uint8_t operand_size;
85 1.1 maxv bool rep;
86 1.1 maxv bool str;
87 1.1 maxv uint64_t npc;
88 1.1 maxv };
89 1.1 maxv
90 1.1 maxv enum nvmm_exit_msr_type {
91 1.1 maxv NVMM_EXIT_MSR_RDMSR,
92 1.1 maxv NVMM_EXIT_MSR_WRMSR
93 1.1 maxv };
94 1.1 maxv
95 1.1 maxv struct nvmm_exit_msr {
96 1.1 maxv enum nvmm_exit_msr_type type;
97 1.1 maxv uint64_t msr;
98 1.1 maxv uint64_t val;
99 1.1 maxv uint64_t npc;
100 1.1 maxv };
101 1.1 maxv
102 1.3 maxv struct nvmm_exit_insn {
103 1.2 maxv uint64_t npc;
104 1.2 maxv };
105 1.2 maxv
106 1.6 maxv struct nvmm_exit_invalid {
107 1.6 maxv uint64_t hwcode;
108 1.6 maxv };
109 1.6 maxv
110 1.1 maxv struct nvmm_exit {
111 1.1 maxv enum nvmm_exit_reason reason;
112 1.1 maxv union {
113 1.1 maxv struct nvmm_exit_memory mem;
114 1.1 maxv struct nvmm_exit_io io;
115 1.1 maxv struct nvmm_exit_msr msr;
116 1.3 maxv struct nvmm_exit_insn insn;
117 1.6 maxv struct nvmm_exit_invalid inv;
118 1.1 maxv } u;
119 1.1 maxv uint64_t exitstate[8];
120 1.1 maxv };
121 1.1 maxv
122 1.1 maxv enum nvmm_event_type {
123 1.1 maxv NVMM_EVENT_INTERRUPT_HW,
124 1.1 maxv NVMM_EVENT_INTERRUPT_SW,
125 1.1 maxv NVMM_EVENT_EXCEPTION
126 1.1 maxv };
127 1.1 maxv
128 1.1 maxv struct nvmm_event {
129 1.1 maxv enum nvmm_event_type type;
130 1.1 maxv uint64_t vector;
131 1.1 maxv union {
132 1.1 maxv /* NVMM_EVENT_INTERRUPT_HW */
133 1.1 maxv uint8_t prio;
134 1.1 maxv
135 1.1 maxv /* NVMM_EVENT_EXCEPTION */
136 1.1 maxv uint64_t error;
137 1.1 maxv } u;
138 1.1 maxv };
139 1.1 maxv
140 1.1 maxv #define NVMM_CAPABILITY_VERSION 1
141 1.1 maxv
142 1.1 maxv struct nvmm_capability {
143 1.1 maxv uint64_t version;
144 1.1 maxv uint64_t state_size;
145 1.1 maxv uint64_t max_machines;
146 1.1 maxv uint64_t max_vcpus;
147 1.1 maxv uint64_t max_ram;
148 1.1 maxv union {
149 1.1 maxv struct {
150 1.1 maxv uint64_t xcr0_mask;
151 1.1 maxv uint64_t mxcsr_mask;
152 1.1 maxv uint64_t conf_cpuid_maxops;
153 1.1 maxv } x86;
154 1.1 maxv uint64_t rsvd[8];
155 1.1 maxv } u;
156 1.1 maxv };
157 1.1 maxv
158 1.1 maxv #endif
159