xref: /illumos-gate/usr/src/uts/intel/sys/vmm_drv.h (revision ac2250cb76bb32944fd2c8a3ba2cd3f79747748d)
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 2025 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 typedef int (*vmm_drv_mmio_cb_t)(void *, bool, uint64_t, int, uint64_t *);
49 
50 extern int vmm_drv_hold(file_t *, cred_t *, vmm_hold_t **);
51 extern void vmm_drv_rele(vmm_hold_t *);
52 extern boolean_t vmm_drv_release_reqd(vmm_hold_t *);
53 
54 extern vmm_lease_t *vmm_drv_lease_sign(vmm_hold_t *, boolean_t (*)(void *),
55     void *);
56 extern void vmm_drv_lease_break(vmm_hold_t *, vmm_lease_t *);
57 extern boolean_t vmm_drv_lease_expired(vmm_lease_t *);
58 
59 extern vmm_page_t *vmm_drv_page_hold(vmm_lease_t *, uintptr_t, int);
60 extern vmm_page_t *vmm_drv_page_hold_ext(vmm_lease_t *, uintptr_t, int, int);
61 extern void vmm_drv_page_release(vmm_page_t *);
62 extern void vmm_drv_page_release_chain(vmm_page_t *);
63 extern const void *vmm_drv_page_readable(const vmm_page_t *);
64 extern void *vmm_drv_page_writable(const vmm_page_t *);
65 extern void vmm_drv_page_mark_dirty(vmm_page_t *);
66 extern void vmm_drv_page_chain(vmm_page_t *, vmm_page_t *);
67 extern vmm_page_t *vmm_drv_page_next(const vmm_page_t *);
68 
69 extern int vmm_drv_msi(vmm_lease_t *, uint64_t, uint64_t);
70 
71 extern int vmm_drv_ioport_hook(vmm_hold_t *, uint16_t, vmm_drv_iop_cb_t, void *,
72     void **);
73 extern void vmm_drv_ioport_unhook(vmm_hold_t *, void **);
74 
75 extern int vmm_drv_mmio_hook(vmm_hold_t *, uint64_t, uint32_t,
76     vmm_drv_mmio_cb_t, void *, void **);
77 extern int vmm_drv_mmio_unhook(vmm_hold_t *, void **);
78 #endif /* _KERNEL */
79 
80 #endif /* _VMM_DRV_H_ */
81