summaryrefslogtreecommitdiff
path: root/lib/libnvmm/nvmm.h
blob: fc258d2867ddcffb8ad0fdeaf6cb3bbd1a07f859 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*	$NetBSD: nvmm.h,v 1.19 2021/04/06 08:40:17 reinoud Exp $	*/

/*
 * Copyright (c) 2018-2020 Maxime Villard, m00nbsd.net
 * All rights reserved.
 *
 * This code is part of the NVMM hypervisor.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef _LIBNVMM_H_
#define _LIBNVMM_H_

#include <stdint.h>
#include <stdbool.h>

#include <dev/nvmm/nvmm.h>
#include <dev/nvmm/nvmm_ioctl.h>

#define NVMM_USER_VERSION	2

/*
 * Version 1 - Initial release in NetBSD 9.0.
 * Version 2 - Added nvmm_vcpu::stop.
 */

struct nvmm_io;
struct nvmm_mem;

struct nvmm_assist_callbacks {
	void (*io)(struct nvmm_io *);
	void (*mem)(struct nvmm_mem *);
};

struct nvmm_machine {
	nvmm_machid_t machid;
	struct nvmm_comm_page **pages;
	void *areas; /* opaque */
};

struct nvmm_vcpu {
	nvmm_cpuid_t cpuid;
	struct nvmm_assist_callbacks cbs;
	struct nvmm_vcpu_state *state;
	struct nvmm_vcpu_event *event;
	struct nvmm_vcpu_exit *exit;
	volatile int *stop;
};

struct nvmm_io {
	struct nvmm_machine *mach;
	struct nvmm_vcpu *vcpu;
	uint16_t port;
	bool in;
	size_t size;
	uint8_t *data;
};

struct nvmm_mem {
	struct nvmm_machine *mach;
	struct nvmm_vcpu *vcpu;
	gpaddr_t gpa;
	bool write;
	size_t size;
	uint8_t *data;
};

#define NVMM_VCPU_CONF_CALLBACKS	NVMM_VCPU_CONF_LIBNVMM_BEGIN

#define NVMM_PROT_READ		0x01
#define NVMM_PROT_WRITE		0x02
#define NVMM_PROT_EXEC		0x04
#define NVMM_PROT_USER		0x08
#define NVMM_PROT_ALL		0x0F
typedef uint64_t nvmm_prot_t;

int nvmm_init(void);
int nvmm_root_init(void);

int nvmm_capability(struct nvmm_capability *);

int nvmm_machine_create(struct nvmm_machine *);
int nvmm_machine_destroy(struct nvmm_machine *);
int nvmm_machine_configure(struct nvmm_machine *, uint64_t, void *);

int nvmm_vcpu_create(struct nvmm_machine *, nvmm_cpuid_t, struct nvmm_vcpu *);
int nvmm_vcpu_destroy(struct nvmm_machine *, struct nvmm_vcpu *);
int nvmm_vcpu_configure(struct nvmm_machine *, struct nvmm_vcpu *, uint64_t,
    void *);
int nvmm_vcpu_setstate(struct nvmm_machine *, struct nvmm_vcpu *, uint64_t);
int nvmm_vcpu_getstate(struct nvmm_machine *, struct nvmm_vcpu *, uint64_t);
int nvmm_vcpu_inject(struct nvmm_machine *, struct nvmm_vcpu *);
int nvmm_vcpu_run(struct nvmm_machine *, struct nvmm_vcpu *);

int nvmm_gpa_map(struct nvmm_machine *, uintptr_t, gpaddr_t, size_t, int);
int nvmm_gpa_unmap(struct nvmm_machine *, uintptr_t, gpaddr_t, size_t);
int nvmm_hva_map(struct nvmm_machine *, uintptr_t, size_t);
int nvmm_hva_unmap(struct nvmm_machine *, uintptr_t, size_t);

int nvmm_gva_to_gpa(struct nvmm_machine *, struct nvmm_vcpu *, gvaddr_t, gpaddr_t *,
    nvmm_prot_t *);
int nvmm_gpa_to_hva(struct nvmm_machine *, gpaddr_t, uintptr_t *,
    nvmm_prot_t *);

int nvmm_assist_io(struct nvmm_machine *, struct nvmm_vcpu *);
int nvmm_assist_mem(struct nvmm_machine *, struct nvmm_vcpu *);

int nvmm_ctl(int, void *, size_t);

int nvmm_vcpu_dump(struct nvmm_machine *, struct nvmm_vcpu *);

int nvmm_vcpu_stop(struct nvmm_vcpu *);

#endif /* _LIBNVMM_H_ */