nvmm.h revision 1.15 1 1.15 maxv /* $NetBSD: nvmm.h,v 1.15 2020/09/05 07:22:25 maxv Exp $ */
2 1.1 maxv
3 1.1 maxv /*
4 1.15 maxv * Copyright (c) 2018-2020 Maxime Villard, m00nbsd.net
5 1.1 maxv * All rights reserved.
6 1.1 maxv *
7 1.15 maxv * This code is part of the NVMM hypervisor.
8 1.1 maxv *
9 1.1 maxv * Redistribution and use in source and binary forms, with or without
10 1.1 maxv * modification, are permitted provided that the following conditions
11 1.1 maxv * are met:
12 1.1 maxv * 1. Redistributions of source code must retain the above copyright
13 1.1 maxv * notice, this list of conditions and the following disclaimer.
14 1.1 maxv * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 maxv * notice, this list of conditions and the following disclaimer in the
16 1.1 maxv * documentation and/or other materials provided with the distribution.
17 1.1 maxv *
18 1.15 maxv * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.15 maxv * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.15 maxv * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.15 maxv * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.15 maxv * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 1.15 maxv * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 1.15 maxv * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 1.15 maxv * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 1.15 maxv * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 1.15 maxv * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 1.15 maxv * SUCH DAMAGE.
29 1.1 maxv */
30 1.1 maxv
31 1.1 maxv #ifndef _NVMM_H_
32 1.1 maxv #define _NVMM_H_
33 1.1 maxv
34 1.1 maxv #include <sys/types.h>
35 1.1 maxv
36 1.1 maxv #ifndef _KERNEL
37 1.1 maxv #include <stdbool.h>
38 1.1 maxv #endif
39 1.1 maxv
40 1.1 maxv typedef uint64_t gpaddr_t;
41 1.1 maxv typedef uint64_t gvaddr_t;
42 1.1 maxv
43 1.1 maxv typedef uint32_t nvmm_machid_t;
44 1.1 maxv typedef uint32_t nvmm_cpuid_t;
45 1.1 maxv
46 1.13 maxv #if defined(__x86_64__)
47 1.7 maxv #include <dev/nvmm/x86/nvmm_x86.h>
48 1.7 maxv #endif
49 1.1 maxv
50 1.11 maxv #define NVMM_KERN_VERSION 1
51 1.1 maxv
52 1.1 maxv struct nvmm_capability {
53 1.12 maxv uint32_t version;
54 1.12 maxv uint32_t state_size;
55 1.12 maxv uint32_t max_machines;
56 1.12 maxv uint32_t max_vcpus;
57 1.1 maxv uint64_t max_ram;
58 1.7 maxv struct nvmm_cap_md arch;
59 1.1 maxv };
60 1.1 maxv
61 1.11 maxv /* Machine configuration slots. */
62 1.10 maxv #define NVMM_MACH_CONF_LIBNVMM_BEGIN 0
63 1.10 maxv #define NVMM_MACH_CONF_MI_BEGIN 100
64 1.10 maxv #define NVMM_MACH_CONF_MD_BEGIN 200
65 1.11 maxv #define NVMM_MACH_CONF_MD(op) (op - NVMM_MACH_CONF_MD_BEGIN)
66 1.10 maxv
67 1.11 maxv /* VCPU configuration slots. */
68 1.11 maxv #define NVMM_VCPU_CONF_LIBNVMM_BEGIN 0
69 1.11 maxv #define NVMM_VCPU_CONF_MI_BEGIN 100
70 1.11 maxv #define NVMM_VCPU_CONF_MD_BEGIN 200
71 1.11 maxv #define NVMM_VCPU_CONF_MD(op) (op - NVMM_VCPU_CONF_MD_BEGIN)
72 1.10 maxv
73 1.9 maxv struct nvmm_comm_page {
74 1.9 maxv /* State. */
75 1.9 maxv uint64_t state_wanted;
76 1.9 maxv uint64_t state_cached;
77 1.9 maxv uint64_t state_commit;
78 1.9 maxv struct nvmm_vcpu_state state;
79 1.9 maxv
80 1.9 maxv /* Event. */
81 1.9 maxv bool event_commit;
82 1.11 maxv struct nvmm_vcpu_event event;
83 1.9 maxv };
84 1.9 maxv
85 1.8 maxv /*
86 1.8 maxv * Bits 20:27 -> machid
87 1.8 maxv * Bits 12:19 -> cpuid
88 1.8 maxv */
89 1.8 maxv #define NVMM_COMM_OFF(machid, cpuid) \
90 1.8 maxv ((((uint64_t)machid & 0xFFULL) << 20) | (((uint64_t)cpuid & 0xFFULL) << 12))
91 1.8 maxv
92 1.8 maxv #define NVMM_COMM_MACHID(off) \
93 1.8 maxv ((off >> 20) & 0xFF)
94 1.8 maxv
95 1.8 maxv #define NVMM_COMM_CPUID(off) \
96 1.8 maxv ((off >> 12) & 0xFF)
97 1.8 maxv
98 1.14 maxv #ifdef _KERNEL
99 1.14 maxv /* At most one page, for the NVMM_COMM_* macros. */
100 1.14 maxv CTASSERT(sizeof(struct nvmm_comm_page) <= PAGE_SIZE);
101 1.14 maxv #endif
102 1.14 maxv
103 1.1 maxv #endif
104