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