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