| 1 | /*	$OpenBSD: vmmvar.h,v 1.3 2025/08/03 10:17:33 tb Exp $	*/ |
| 2 | /* |
| 3 | * Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org> |
| 4 | * |
| 5 | * Permission to use, copy, modify, and distribute this software for any |
| 6 | * purpose with or without fee is hereby granted, provided that the above |
| 7 | * copyright notice and this permission notice appear in all copies. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 | */ |
| 17 | |
| 18 | /* |
| 19 | * CPU capabilities for VMM operation |
| 20 | */ |
| 21 | #ifndef _MACHINE_VMMVAR_H_ |
| 22 | #define _MACHINE_VMMVAR_H_ |
| 23 | |
| 24 | #define VMM_HV_SIGNATURE 	"OpenBSDVMM58" |
| 25 | |
| 26 | /* Exit Reasons */ |
| 27 | #define VM_EXIT_TERMINATED			0xFFFE |
| 28 | #define VM_EXIT_NONE				0xFFFF |
| 29 | |
| 30 | struct vmm_softc_md { |
| 31 | 	/* Capabilities */ |
| 32 | 	uint32_t		nr_cpus;	/* [I] */ |
| 33 | }; |
| 34 | |
| 35 | /* |
| 36 | * struct vcpu_inject_event	: describes an exception or interrupt to inject. |
| 37 | */ |
| 38 | struct vcpu_inject_event { |
| 39 | 	uint8_t		vie_vector;	/* Exception or interrupt vector. */ |
| 40 | 	uint32_t	vie_errorcode;	/* Optional error code. */ |
| 41 | 	uint8_t		vie_type; |
| 42 | #define VCPU_INJECT_NONE	0 |
| 43 | #define VCPU_INJECT_INTR	1	/* External hardware interrupt. */ |
| 44 | #define VCPU_INJECT_EX		2	/* HW or SW Exception */ |
| 45 | #define VCPU_INJECT_NMI		3	/* Non-maskable Interrupt */ |
| 46 | }; |
| 47 | |
| 48 | #define VCPU_REGS_NGPRS		31 |
| 49 | |
| 50 | struct vcpu_reg_state { |
| 51 | 	uint64_t			vrs_gprs[VCPU_REGS_NGPRS]; |
| 52 | }; |
| 53 | |
| 54 | /* |
| 55 | * struct vm_exit |
| 56 | * |
| 57 | * Contains VM exit information communicated to vmd(8). This information is |
| 58 | * gathered by vmm(4) from the CPU on each exit that requires help from vmd. |
| 59 | */ |
| 60 | struct vm_exit { |
| 61 | 	struct vcpu_reg_state		vrs; |
| 62 | }; |
| 63 | |
| 64 | struct vm_intr_params { |
| 65 | 	/* Input parameters to VMM_IOC_INTR */ |
| 66 | 	uint32_t		vip_vm_id; |
| 67 | 	uint32_t		vip_vcpu_id; |
| 68 | 	uint16_t		vip_intr; |
| 69 | }; |
| 70 | |
| 71 | #define VM_RWREGS_GPRS	0x1	/* read/write GPRs */ |
| 72 | #define VM_RWREGS_ALL	(VM_RWREGS_GPRS) |
| 73 | |
| 74 | struct vm_rwregs_params { |
| 75 | 	/* |
| 76 | 	 * Input/output parameters to VMM_IOC_READREGS / |
| 77 | 	 * VMM_IOC_WRITEREGS |
| 78 | 	 */ |
| 79 | 	uint32_t		vrwp_vm_id; |
| 80 | 	uint32_t		vrwp_vcpu_id; |
| 81 | 	uint64_t		vrwp_mask; |
| 82 | 	struct vcpu_reg_state	vrwp_regs; |
| 83 | }; |
| 84 | |
| 85 | enum { |
| 86 | 	VEI_DIR_OUT, |
| 87 | 	VEI_DIR_IN |
| 88 | }; |
| 89 | |
| 90 | /* IOCTL definitions */ |
| 91 | #define VMM_IOC_INTR _IOW('V', 6, struct vm_intr_params) /* Intr pending */ |
| 92 | |
| 93 | #endif /* ! _MACHINE_VMMVAR_H_ */ |