nvmm.h revision 1.8 1 /* $NetBSD: nvmm.h,v 1.8 2019/04/28 14:22:13 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 #ifdef __x86_64__
48 #include <dev/nvmm/x86/nvmm_x86.h>
49 #endif
50
51 #define NVMM_EXIT_NONE 0x0000000000000000ULL
52 #define NVMM_EXIT_MEMORY 0x0000000000000001ULL
53 #define NVMM_EXIT_IO 0x0000000000000002ULL
54 #define NVMM_EXIT_MSR 0x0000000000000003ULL /* x86 only? */
55 #define NVMM_EXIT_INT_READY 0x0000000000000004ULL
56 #define NVMM_EXIT_NMI_READY 0x0000000000000005ULL
57 #define NVMM_EXIT_HALTED 0x0000000000000006ULL
58 #define NVMM_EXIT_SHUTDOWN 0x0000000000000007ULL
59 /* Range 0x1000-0x10000 is MD. */
60 #define NVMM_EXIT_INVALID 0xFFFFFFFFFFFFFFFFULL
61
62 struct nvmm_exit {
63 uint64_t reason;
64 union nvmm_exit_md u;
65 uint64_t exitstate[8];
66 };
67
68 enum nvmm_event_type {
69 NVMM_EVENT_INTERRUPT_HW,
70 NVMM_EVENT_INTERRUPT_SW,
71 NVMM_EVENT_EXCEPTION
72 };
73
74 struct nvmm_event {
75 enum nvmm_event_type type;
76 uint64_t vector;
77 union {
78 /* NVMM_EVENT_INTERRUPT_HW */
79 uint8_t prio;
80
81 /* NVMM_EVENT_EXCEPTION */
82 uint64_t error;
83 } u;
84 };
85
86 #define NVMM_CAPABILITY_VERSION 1
87
88 struct nvmm_capability {
89 uint64_t version;
90 uint64_t state_size;
91 uint64_t max_machines;
92 uint64_t max_vcpus;
93 uint64_t max_ram;
94 struct nvmm_cap_md arch;
95 };
96
97 /*
98 * Bits 20:27 -> machid
99 * Bits 12:19 -> cpuid
100 */
101 #define NVMM_COMM_OFF(machid, cpuid) \
102 ((((uint64_t)machid & 0xFFULL) << 20) | (((uint64_t)cpuid & 0xFFULL) << 12))
103
104 #define NVMM_COMM_MACHID(off) \
105 ((off >> 20) & 0xFF)
106
107 #define NVMM_COMM_CPUID(off) \
108 ((off >> 12) & 0xFF)
109
110 #endif
111