Home | History | Annotate | Line # | Download | only in nvmm
nvmm_internal.h revision 1.11.2.3
      1  1.11.2.3    martin /*	$NetBSD: nvmm_internal.h,v 1.11.2.3 2020/04/13 08:04:25 martin Exp $	*/
      2  1.11.2.2  christos 
      3  1.11.2.2  christos /*
      4  1.11.2.3    martin  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
      5  1.11.2.2  christos  * All rights reserved.
      6  1.11.2.2  christos  *
      7  1.11.2.2  christos  * This code is derived from software contributed to The NetBSD Foundation
      8  1.11.2.2  christos  * by Maxime Villard.
      9  1.11.2.2  christos  *
     10  1.11.2.2  christos  * Redistribution and use in source and binary forms, with or without
     11  1.11.2.2  christos  * modification, are permitted provided that the following conditions
     12  1.11.2.2  christos  * are met:
     13  1.11.2.2  christos  * 1. Redistributions of source code must retain the above copyright
     14  1.11.2.2  christos  *    notice, this list of conditions and the following disclaimer.
     15  1.11.2.2  christos  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.11.2.2  christos  *    notice, this list of conditions and the following disclaimer in the
     17  1.11.2.2  christos  *    documentation and/or other materials provided with the distribution.
     18  1.11.2.2  christos  *
     19  1.11.2.2  christos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.11.2.2  christos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.11.2.2  christos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.11.2.2  christos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.11.2.2  christos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.11.2.2  christos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.11.2.2  christos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.11.2.2  christos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.11.2.2  christos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.11.2.2  christos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.11.2.2  christos  * POSSIBILITY OF SUCH DAMAGE.
     30  1.11.2.2  christos  */
     31  1.11.2.2  christos 
     32  1.11.2.2  christos #ifndef _NVMM_INTERNAL_H_
     33  1.11.2.2  christos #define _NVMM_INTERNAL_H_
     34  1.11.2.2  christos 
     35  1.11.2.2  christos #define NVMM_MAX_MACHINES	128
     36  1.11.2.2  christos #define NVMM_MAX_VCPUS		256
     37  1.11.2.2  christos #define NVMM_MAX_HMAPPINGS	32
     38  1.11.2.2  christos #define NVMM_MAX_RAM		(128ULL * (1 << 30))
     39  1.11.2.2  christos 
     40  1.11.2.2  christos struct nvmm_owner {
     41  1.11.2.2  christos 	pid_t pid;
     42  1.11.2.2  christos };
     43  1.11.2.2  christos 
     44  1.11.2.2  christos struct nvmm_cpu {
     45  1.11.2.2  christos 	/* Shared. */
     46  1.11.2.2  christos 	bool present;
     47  1.11.2.2  christos 	nvmm_cpuid_t cpuid;
     48  1.11.2.2  christos 	kmutex_t lock;
     49  1.11.2.2  christos 
     50  1.11.2.2  christos 	/* Comm page. */
     51  1.11.2.2  christos 	struct nvmm_comm_page *comm;
     52  1.11.2.2  christos 
     53  1.11.2.2  christos 	/* Last host CPU on which the VCPU ran. */
     54  1.11.2.2  christos 	int hcpu_last;
     55  1.11.2.2  christos 
     56  1.11.2.2  christos 	/* Implementation-specific. */
     57  1.11.2.2  christos 	void *cpudata;
     58  1.11.2.2  christos };
     59  1.11.2.2  christos 
     60  1.11.2.2  christos struct nvmm_hmapping {
     61  1.11.2.2  christos 	bool present;
     62  1.11.2.2  christos 	uintptr_t hva;
     63  1.11.2.2  christos 	size_t size;
     64  1.11.2.2  christos 	struct uvm_object *uobj;
     65  1.11.2.2  christos };
     66  1.11.2.2  christos 
     67  1.11.2.2  christos struct nvmm_machine {
     68  1.11.2.2  christos 	bool present;
     69  1.11.2.2  christos 	nvmm_machid_t machid;
     70  1.11.2.2  christos 	time_t time;
     71  1.11.2.2  christos 	struct nvmm_owner *owner;
     72  1.11.2.2  christos 	krwlock_t lock;
     73  1.11.2.2  christos 
     74  1.11.2.2  christos 	/* Comm */
     75  1.11.2.2  christos 	struct uvm_object *commuobj;
     76  1.11.2.2  christos 
     77  1.11.2.2  christos 	/* Kernel */
     78  1.11.2.2  christos 	struct vmspace *vm;
     79  1.11.2.2  christos 	gpaddr_t gpa_begin;
     80  1.11.2.2  christos 	gpaddr_t gpa_end;
     81  1.11.2.2  christos 
     82  1.11.2.2  christos 	/* Host Mappings */
     83  1.11.2.2  christos 	struct nvmm_hmapping hmap[NVMM_MAX_HMAPPINGS];
     84  1.11.2.2  christos 
     85  1.11.2.2  christos 	/* CPU */
     86  1.11.2.2  christos 	struct nvmm_cpu cpus[NVMM_MAX_VCPUS];
     87  1.11.2.2  christos 
     88  1.11.2.2  christos 	/* Implementation-specific */
     89  1.11.2.2  christos 	void *machdata;
     90  1.11.2.2  christos };
     91  1.11.2.2  christos 
     92  1.11.2.2  christos struct nvmm_impl {
     93  1.11.2.2  christos 	bool (*ident)(void);
     94  1.11.2.2  christos 	void (*init)(void);
     95  1.11.2.2  christos 	void (*fini)(void);
     96  1.11.2.2  christos 	void (*capability)(struct nvmm_capability *);
     97  1.11.2.2  christos 
     98  1.11.2.3    martin 	size_t mach_conf_max;
     99  1.11.2.3    martin 	const size_t *mach_conf_sizes;
    100  1.11.2.3    martin 
    101  1.11.2.3    martin 	size_t vcpu_conf_max;
    102  1.11.2.3    martin 	const size_t *vcpu_conf_sizes;
    103  1.11.2.3    martin 
    104  1.11.2.2  christos 	size_t state_size;
    105  1.11.2.2  christos 
    106  1.11.2.2  christos 	void (*machine_create)(struct nvmm_machine *);
    107  1.11.2.2  christos 	void (*machine_destroy)(struct nvmm_machine *);
    108  1.11.2.2  christos 	int (*machine_configure)(struct nvmm_machine *, uint64_t, void *);
    109  1.11.2.2  christos 
    110  1.11.2.2  christos 	int (*vcpu_create)(struct nvmm_machine *, struct nvmm_cpu *);
    111  1.11.2.2  christos 	void (*vcpu_destroy)(struct nvmm_machine *, struct nvmm_cpu *);
    112  1.11.2.3    martin 	int (*vcpu_configure)(struct nvmm_cpu *, uint64_t, void *);
    113  1.11.2.2  christos 	void (*vcpu_setstate)(struct nvmm_cpu *);
    114  1.11.2.2  christos 	void (*vcpu_getstate)(struct nvmm_cpu *);
    115  1.11.2.2  christos 	int (*vcpu_inject)(struct nvmm_cpu *);
    116  1.11.2.2  christos 	int (*vcpu_run)(struct nvmm_machine *, struct nvmm_cpu *,
    117  1.11.2.3    martin 	    struct nvmm_vcpu_exit *);
    118  1.11.2.2  christos };
    119  1.11.2.2  christos 
    120  1.11.2.2  christos extern const struct nvmm_impl nvmm_x86_svm;
    121  1.11.2.2  christos extern const struct nvmm_impl nvmm_x86_vmx;
    122  1.11.2.2  christos 
    123  1.11.2.2  christos #endif /* _NVMM_INTERNAL_H_ */
    124