Reorder the NVMM headers, to make a clear(er) distinction between MI and

MD. Also use #defines for the exit reasons rather than an union. No ABI
change, and no API change except 'cap->u.{}' renamed to 'cap->arch'.
This commit is contained in:
maxv 2019-04-27 15:45:21 +00:00
parent 4402b4d24a
commit 6296b43f91
5 changed files with 99 additions and 93 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: nvmm.h,v 1.8 2019/04/10 18:49:04 maxv Exp $ */
/* $NetBSD: nvmm.h,v 1.9 2019/04/27 15:45:21 maxv Exp $ */
/*
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@ -37,9 +37,6 @@
#include <dev/nvmm/nvmm.h>
#include <dev/nvmm/nvmm_ioctl.h>
#ifdef __x86_64__
#include <dev/nvmm/x86/nvmm_x86.h>
#endif
struct nvmm_machine {
nvmm_machid_t machid;

View File

@ -1,4 +1,4 @@
/* $NetBSD: nvmm.h,v 1.6 2019/04/24 18:19:28 maxv Exp $ */
/* $NetBSD: nvmm.h,v 1.7 2019/04/27 15:45:21 maxv Exp $ */
/*
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@ -44,78 +44,24 @@ typedef uint64_t gvaddr_t;
typedef uint32_t nvmm_machid_t;
typedef uint32_t nvmm_cpuid_t;
enum nvmm_exit_reason {
NVMM_EXIT_NONE = 0x0000000000000000,
#ifdef __x86_64__
#include <dev/nvmm/x86/nvmm_x86.h>
#endif
/* General. */
NVMM_EXIT_MEMORY = 0x0000000000000001,
NVMM_EXIT_IO = 0x0000000000000002,
NVMM_EXIT_MSR = 0x0000000000000003,
NVMM_EXIT_INT_READY = 0x0000000000000004,
NVMM_EXIT_NMI_READY = 0x0000000000000005,
NVMM_EXIT_HALTED = 0x0000000000000006,
NVMM_EXIT_SHUTDOWN = 0x0000000000000007,
/* Instructions (x86). */
NVMM_EXIT_MONITOR = 0x0000000000001000,
NVMM_EXIT_MWAIT = 0x0000000000001001,
NVMM_EXIT_MWAIT_COND = 0x0000000000001002,
NVMM_EXIT_INVALID = 0xFFFFFFFFFFFFFFFF
};
struct nvmm_exit_memory {
int prot;
gpaddr_t gpa;
uint8_t inst_len;
uint8_t inst_bytes[15];
};
enum nvmm_exit_io_type {
NVMM_EXIT_IO_IN,
NVMM_EXIT_IO_OUT
};
struct nvmm_exit_io {
enum nvmm_exit_io_type type;
uint16_t port;
int seg;
uint8_t address_size;
uint8_t operand_size;
bool rep;
bool str;
uint64_t npc;
};
enum nvmm_exit_msr_type {
NVMM_EXIT_MSR_RDMSR,
NVMM_EXIT_MSR_WRMSR
};
struct nvmm_exit_msr {
enum nvmm_exit_msr_type type;
uint64_t msr;
uint64_t val;
uint64_t npc;
};
struct nvmm_exit_insn {
uint64_t npc;
};
struct nvmm_exit_invalid {
uint64_t hwcode;
};
#define NVMM_EXIT_NONE 0x0000000000000000ULL
#define NVMM_EXIT_MEMORY 0x0000000000000001ULL
#define NVMM_EXIT_IO 0x0000000000000002ULL
#define NVMM_EXIT_MSR 0x0000000000000003ULL /* x86 only? */
#define NVMM_EXIT_INT_READY 0x0000000000000004ULL
#define NVMM_EXIT_NMI_READY 0x0000000000000005ULL
#define NVMM_EXIT_HALTED 0x0000000000000006ULL
#define NVMM_EXIT_SHUTDOWN 0x0000000000000007ULL
/* Range 0x1000-0x10000 is MD. */
#define NVMM_EXIT_INVALID 0xFFFFFFFFFFFFFFFFULL
struct nvmm_exit {
enum nvmm_exit_reason reason;
union {
struct nvmm_exit_memory mem;
struct nvmm_exit_io io;
struct nvmm_exit_msr msr;
struct nvmm_exit_insn insn;
struct nvmm_exit_invalid inv;
} u;
uint64_t reason;
union nvmm_exit_md u;
uint64_t exitstate[8];
};
@ -145,14 +91,7 @@ struct nvmm_capability {
uint64_t max_machines;
uint64_t max_vcpus;
uint64_t max_ram;
union {
struct {
uint64_t xcr0_mask;
uint64_t mxcsr_mask;
uint64_t conf_cpuid_maxops;
} x86;
uint64_t rsvd[8];
} u;
struct nvmm_cap_md arch;
};
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: nvmm_x86.h,v 1.11 2019/04/06 11:49:53 maxv Exp $ */
/* $NetBSD: nvmm_x86.h,v 1.12 2019/04/27 15:45:21 maxv Exp $ */
/*
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@ -32,6 +32,76 @@
#ifndef _NVMM_X86_H_
#define _NVMM_X86_H_
/* --------------------------------------------------------------------- */
#ifndef ASM_NVMM
struct nvmm_exit_memory {
int prot;
gpaddr_t gpa;
uint8_t inst_len;
uint8_t inst_bytes[15];
};
enum nvmm_exit_io_type {
NVMM_EXIT_IO_IN,
NVMM_EXIT_IO_OUT
};
struct nvmm_exit_io {
enum nvmm_exit_io_type type;
uint16_t port;
int seg;
uint8_t address_size;
uint8_t operand_size;
bool rep;
bool str;
uint64_t npc;
};
enum nvmm_exit_msr_type {
NVMM_EXIT_MSR_RDMSR,
NVMM_EXIT_MSR_WRMSR
};
struct nvmm_exit_msr {
enum nvmm_exit_msr_type type;
uint64_t msr;
uint64_t val;
uint64_t npc;
};
struct nvmm_exit_insn {
uint64_t npc;
};
struct nvmm_exit_invalid {
uint64_t hwcode;
};
union nvmm_exit_md {
struct nvmm_exit_memory mem;
struct nvmm_exit_io io;
struct nvmm_exit_msr msr;
struct nvmm_exit_insn insn;
struct nvmm_exit_invalid inv;
};
#define NVMM_EXIT_MONITOR 0x0000000000001000ULL
#define NVMM_EXIT_MWAIT 0x0000000000001001ULL
#define NVMM_EXIT_MWAIT_COND 0x0000000000001002ULL
struct nvmm_cap_md {
uint64_t xcr0_mask;
uint64_t mxcsr_mask;
uint64_t conf_cpuid_maxops;
uint64_t rsvd[5];
};
#endif
/* --------------------------------------------------------------------- */
/* Segments. */
#define NVMM_X64_SEG_ES 0
#define NVMM_X64_SEG_CS 1

View File

@ -1,4 +1,4 @@
/* $NetBSD: nvmm_x86_svm.c,v 1.41 2019/04/27 09:06:18 maxv Exp $ */
/* $NetBSD: nvmm_x86_svm.c,v 1.42 2019/04/27 15:45:21 maxv Exp $ */
/*
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.41 2019/04/27 09:06:18 maxv Exp $");
__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.42 2019/04/27 15:45:21 maxv Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -2288,9 +2288,9 @@ svm_fini(void)
static void
svm_capability(struct nvmm_capability *cap)
{
cap->u.x86.xcr0_mask = svm_xcr0_mask;
cap->u.x86.mxcsr_mask = x86_fpu_mxcsr_mask;
cap->u.x86.conf_cpuid_maxops = SVM_NCPUIDS;
cap->arch.xcr0_mask = svm_xcr0_mask;
cap->arch.mxcsr_mask = x86_fpu_mxcsr_mask;
cap->arch.conf_cpuid_maxops = SVM_NCPUIDS;
}
const struct nvmm_impl nvmm_x86_svm = {

View File

@ -1,4 +1,4 @@
/* $NetBSD: nvmm_x86_vmx.c,v 1.29 2019/04/27 09:06:18 maxv Exp $ */
/* $NetBSD: nvmm_x86_vmx.c,v 1.30 2019/04/27 15:45:21 maxv Exp $ */
/*
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.29 2019/04/27 09:06:18 maxv Exp $");
__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.30 2019/04/27 15:45:21 maxv Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -3083,9 +3083,9 @@ vmx_fini(void)
static void
vmx_capability(struct nvmm_capability *cap)
{
cap->u.x86.xcr0_mask = vmx_xcr0_mask;
cap->u.x86.mxcsr_mask = x86_fpu_mxcsr_mask;
cap->u.x86.conf_cpuid_maxops = VMX_NCPUIDS;
cap->arch.xcr0_mask = vmx_xcr0_mask;
cap->arch.mxcsr_mask = x86_fpu_mxcsr_mask;
cap->arch.conf_cpuid_maxops = VMX_NCPUIDS;
}
const struct nvmm_impl nvmm_x86_vmx = {