xref: /freebsd/sys/xen/hvm.h (revision a90b9d0159070121c221b966469c3e36d912bf82)
1 /*
2  * Permission is hereby granted, free of charge, to any person obtaining a copy
3  * of this software and associated documentation files (the "Software"), to
4  * deal in the Software without restriction, including without limitation the
5  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
6  * sell copies of the Software, and to permit persons to whom the Software is
7  * furnished to do so, subject to the following conditions:
8  *
9  * The above copyright notice and this permission notice shall be included in
10  * all copies or substantial portions of the Software.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18  * DEALINGS IN THE SOFTWARE.
19  */
20 
21 #ifndef	__XEN_HVM_H__
22 #define	__XEN_HVM_H__
23 
24 #include <xen/xen-os.h>
25 #include <xen/hypervisor.h>
26 
27 #include <contrib/xen/hvm/params.h>
28 
29 /**
30  * \brief Wrapper function to obtain a HVM parameter value.
31  *
32  * \param index	HVM parameter index; see <contrib/xen/hvm/params.h>.
33  *
34  * \returns	0 on failure; the value of the parameter otherwise.
35  */
36 static inline unsigned long
37 hvm_get_parameter(int index)
38 {
39 	struct xen_hvm_param xhv;
40 	int error;
41 
42 	xhv.domid = DOMID_SELF;
43 	xhv.index = index;
44 	error = HYPERVISOR_hvm_op(HVMOP_get_param, &xhv);
45 	if (error) {
46 		printf("%s: error %d trying to get %d\n", __func__,
47 		    error, index);
48 		return (0);
49 	}
50 	return (xhv.value);
51 }
52 
53 /** The callback method types for Hypervisor event delivery to our domain. */
54 enum {
55 	HVM_CB_TYPE_GSI,
56 	HVM_CB_TYPE_PCI_INTX,
57 	HVM_CB_TYPE_VECTOR,
58 	HVM_CB_TYPE_MASK  = 0xFF,
59 	HVM_CB_TYPE_SHIFT = 56
60 };
61 
62 /** Format for specifying a GSI type callback. */
63 enum {
64 	HVM_CB_GSI_GSI_MASK  = 0xFFFFFFFF,
65 	HVM_CB_GSI_GSI_SHIFT = 0
66 };
67 #define HVM_CALLBACK_GSI(gsi) \
68     (((uint64_t)HVM_CB_TYPE_GSI << HVM_CB_TYPE_SHIFT) \
69    | ((gsi) & HVM_CB_GSI_GSI_MASK) << HVM_CB_GSI_GSI_SHIFT)
70 
71 /** Format for specifying a virtual PCI interrupt line GSI style callback. */
72 enum {
73 	HVM_CB_PCI_INTX_INTPIN_MASK  = 0x3,
74 	HVM_CB_PCI_INTX_INTPIN_SHIFT = 0,
75 	HVM_CB_PCI_INTX_SLOT_MASK    = 0x1F,
76 	HVM_CB_PCI_INTX_SLOT_SHIFT   = 11,
77 };
78 #define HVM_CALLBACK_PCI_INTX(slot, pin) \
79     (((uint64_t)HVM_CB_TYPE_PCI_INTX << HVM_CB_TYPE_SHIFT) \
80    | (((slot) & HVM_CB_PCI_INTX_SLOT_MASK) << HVM_CB_PCI_INTX_SLOT_SHIFT) \
81    | (((pin) & HVM_CB_PCI_INTX_INTPIN_MASK) << HVM_CB_PCI_INTX_INTPIN_SHIFT))
82 
83 /** Format for specifying a direct IDT vector injection style callback. */
84 enum {
85 	HVM_CB_VECTOR_VECTOR_MASK  = 0xFFFFFFFF,
86 	HVM_CB_VECTOR_VECTOR_SHIFT = 0
87 };
88 #define HVM_CALLBACK_VECTOR(vector) \
89     (((uint64_t)HVM_CB_TYPE_VECTOR << HVM_CB_TYPE_SHIFT) \
90    | (((vector) & HVM_CB_GSI_GSI_MASK) << HVM_CB_GSI_GSI_SHIFT))
91 
92 enum xen_hvm_init_type {
93 	XEN_HVM_INIT_EARLY,
94 	XEN_HVM_INIT_LATE,
95 	XEN_HVM_INIT_CANCELLED_SUSPEND,
96 	XEN_HVM_INIT_RESUME,
97 };
98 
99 int xen_hvm_init_hypercall_stubs(enum xen_hvm_init_type);
100 void xen_hvm_set_callback(device_t);
101 void xen_hvm_suspend(void);
102 void xen_hvm_resume(bool suspend_cancelled);
103 
104 extern uint32_t hvm_start_flags;
105 
106 #endif	/* __XEN_HVM_H__ */
107