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