xref: /illumos-gate/usr/src/test/bhyve-tests/tests/common/in_guest.h (revision ce489a5e0a9c618cd26b66d6b1fd397d8545db9b)
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 2024 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 struct vmctx *test_initialize_plain(const char *);
23 struct vmctx *test_initialize_flags(const char *, uint64_t);
24 void test_reinitialize(struct vmctx *, uint64_t);
25 void test_cleanup(bool);
26 void test_fail(void);
27 void test_fail_errno(int err, const char *msg);
28 void test_fail_msg(const char *fmt, ...);
29 void test_fail_vmexit(const struct vm_exit *vexit);
30 void test_pass(void);
31 const char *test_msg_get(struct vmctx *);
32 void test_msg_print(struct vmctx *);
33 
34 int test_setup_vcpu(struct vcpu *, uint64_t, uint64_t);
35 
36 enum vm_exit_kind {
37 	/* Otherwise empty vmexit which should result in immediate re-entry */
38 	VEK_REENTR,
39 	/* Write to IOP_TEST_RESULT port with success value (0) */
40 	VEK_TEST_PASS,
41 	/* Write to IOP_TEST_RESULT port with failure value (non-zero) */
42 	VEK_TEST_FAIL,
43 	/* Payload emitted a message via IOP_TEST_MSG port */
44 	VEK_TEST_MSG,
45 	/* Test specific logic must handle exit data */
46 	VEK_UNHANDLED,
47 };
48 
49 enum vm_exit_kind test_run_vcpu(struct vcpu *, struct vm_entry *,
50     struct vm_exit *);
51 
52 void ventry_fulfill_inout(const struct vm_exit *, struct vm_entry *, uint32_t);
53 void ventry_fulfill_mmio(const struct vm_exit *, struct vm_entry *, uint64_t);
54 
55 bool vexit_match_inout(const struct vm_exit *, bool, uint16_t, uint_t,
56     uint32_t *);
57 bool vexit_match_mmio(const struct vm_exit *, bool, uint64_t, uint_t,
58     uint64_t *);
59 
60 #endif /* _IN_GUEST_H_ */
61