xref: /illumos-gate/usr/src/uts/intel/sys/vmm_drv.h (revision f2357d97)
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 /* This file is dual-licensed; see usr/src/contrib/bhyve/LICENSE */
12 
13 /*
14  * Copyright 2019 Joyent, Inc.
15  * Copyright 2022 Oxide Computer Company
16  */
17 
18 #ifndef _VMM_DRV_H_
19 #define	_VMM_DRV_H_
20 
21 #ifdef	_KERNEL
22 
23 #include <sys/file.h>
24 #include <sys/stdbool.h>
25 
26 struct vmm_hold;
27 typedef struct vmm_hold vmm_hold_t;
28 
29 struct vmm_lease;
30 typedef struct vmm_lease vmm_lease_t;
31 
32 /*
33  * This is effectively a synonym for the bhyve-internal 'struct vm_page' type.
34  * Use of `vmm_page_t *` instead allows us to keep those implementation details
35  * hidden from vmm_drv consumers.
36  */
37 struct vmm_page;
38 typedef struct vmm_page vmm_page_t;
39 
40 /* Flags defined for vmm_drv_page_hold_ext(), mirror those for vmc_hold(): */
41 #define	VMPF_DEFER_DIRTY		(1 << 0)
42 
43 /*
44  * Because of tangled headers, this definitions mirrors its ioport_handler_t
45  * counterpart in vmm_kernel.h.
46  */
47 typedef int (*vmm_drv_iop_cb_t)(void *, bool, uint16_t, uint8_t, uint32_t *);
48 
49 extern int vmm_drv_hold(file_t *, cred_t *, vmm_hold_t **);
50 extern void vmm_drv_rele(vmm_hold_t *);
51 extern boolean_t vmm_drv_release_reqd(vmm_hold_t *);
52 
53 extern vmm_lease_t *vmm_drv_lease_sign(vmm_hold_t *, boolean_t (*)(void *),
54     void *);
55 extern void vmm_drv_lease_break(vmm_hold_t *, vmm_lease_t *);
56 extern boolean_t vmm_drv_lease_expired(vmm_lease_t *);
57 
58 extern vmm_page_t *vmm_drv_page_hold(vmm_lease_t *, uintptr_t, int);
59 extern vmm_page_t *vmm_drv_page_hold_ext(vmm_lease_t *, uintptr_t, int, int);
60 extern void vmm_drv_page_release(vmm_page_t *);
61 extern void vmm_drv_page_release_chain(vmm_page_t *);
62 extern const void *vmm_drv_page_readable(const vmm_page_t *);
63 extern void *vmm_drv_page_writable(const vmm_page_t *);
64 extern void vmm_drv_page_mark_dirty(vmm_page_t *);
65 extern void vmm_drv_page_chain(vmm_page_t *, vmm_page_t *);
66 extern vmm_page_t *vmm_drv_page_next(const vmm_page_t *);
67 
68 extern int vmm_drv_msi(vmm_lease_t *, uint64_t, uint64_t);
69 
70 extern int vmm_drv_ioport_hook(vmm_hold_t *, uint16_t, vmm_drv_iop_cb_t, void *,
71     void **);
72 extern void vmm_drv_ioport_unhook(vmm_hold_t *, void **);
73 #endif /* _KERNEL */
74 
75 #endif /* _VMM_DRV_H_ */
76