xref: /illumos-gate/usr/src/test/bhyve-tests/tests/common/in_guest.h (revision 3ee592424ed4bb7b850d9adccb9f3c493ce7534b)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2022 Oxide Computer Company
14  */
15 
16 #ifndef _IN_GUEST_H_
17 #define	_IN_GUEST_H_
18 
19 #include "payload_common.h"
20 
21 struct vmctx *test_initialize(const char *);
22 void test_fail_errno(int err, const char *msg);
23 void test_fail_msg(const char *fmt, ...);
24 void test_fail_vmexit(const struct vm_exit *vexit);
25 void test_pass(void);
26 
27 int test_setup_vcpu(struct vmctx *, int, uint64_t, uint64_t);
28 
29 enum vm_exit_kind {
30 	/* Otherwise empty vmexit which should result in immediate re-entry */
31 	VEK_REENTR,
32 	/* Write to IOP_TEST_RESULT port with success value (0) */
33 	VEK_TEST_PASS,
34 	/* Write to IOP_TEST_RESULT port with failure value (non-zero) */
35 	VEK_TEST_FAIL,
36 	/* Test specific logic must handle exit data */
37 	VEK_UNHANDLED,
38 };
39 
40 enum vm_exit_kind test_run_vcpu(struct vmctx *, int, struct vm_entry *,
41     struct vm_exit *);
42 
43 void ventry_fulfill_inout(const struct vm_exit *, struct vm_entry *, uint32_t);
44 void ventry_fulfill_mmio(const struct vm_exit *, struct vm_entry *, uint64_t);
45 
46 bool vexit_match_inout(const struct vm_exit *, bool, uint16_t, uint_t,
47     uint32_t *);
48 bool vexit_match_mmio(const struct vm_exit *, bool, uint64_t, uint_t,
49     uint64_t *);
50 
51 #endif /* _IN_GUEST_H_ */
52