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 * $FreeBSD$ 21 */ 22 23 #ifndef __XEN_HVM_H__ 24 #define __XEN_HVM_H__ 25 26 #include <xen/xen-os.h> 27 #include <xen/hypervisor.h> 28 29 #include <xen/interface/hvm/params.h> 30 31 /** 32 * \brief Wrapper function to obtain a HVM parameter value. 33 * 34 * \param index HVM parameter index; see <xen/interface/hvm/params.h>. 35 * 36 * \returns 0 on failure; the value of the parameter otherwise. 37 */ 38 static inline unsigned long 39 hvm_get_parameter(int index) 40 { 41 struct xen_hvm_param xhv; 42 int error; 43 44 xhv.domid = DOMID_SELF; 45 xhv.index = index; 46 error = HYPERVISOR_hvm_op(HVMOP_get_param, &xhv); 47 if (error) { 48 printf("%s: error %d trying to get %d\n", __func__, 49 error, index); 50 return (0); 51 } 52 return (xhv.value); 53 } 54 55 /** The callback method types for Hypervisor event delivery to our domain. */ 56 enum { 57 HVM_CB_TYPE_GSI, 58 HVM_CB_TYPE_PCI_INTX, 59 HVM_CB_TYPE_VECTOR, 60 HVM_CB_TYPE_MASK = 0xFF, 61 HVM_CB_TYPE_SHIFT = 56 62 }; 63 64 /** Format for specifying a GSI type callback. */ 65 enum { 66 HVM_CB_GSI_GSI_MASK = 0xFFFFFFFF, 67 HVM_CB_GSI_GSI_SHIFT = 0 68 }; 69 #define HVM_CALLBACK_GSI(gsi) \ 70 (((uint64_t)HVM_CB_TYPE_GSI << HVM_CB_TYPE_SHIFT) \ 71 | ((gsi) & HVM_CB_GSI_GSI_MASK) << HVM_CB_GSI_GSI_SHIFT) 72 73 /** Format for specifying a virtual PCI interrupt line GSI style callback. */ 74 enum { 75 HVM_CB_PCI_INTX_INTPIN_MASK = 0x3, 76 HVM_CB_PCI_INTX_INTPIN_SHIFT = 0, 77 HVM_CB_PCI_INTX_SLOT_MASK = 0x1F, 78 HVM_CB_PCI_INTX_SLOT_SHIFT = 11, 79 }; 80 #define HVM_CALLBACK_PCI_INTX(slot, pin) \ 81 (((uint64_t)HVM_CB_TYPE_PCI_INTX << HVM_CB_TYPE_SHIFT) \ 82 | (((slot) & HVM_CB_PCI_INTX_SLOT_MASK) << HVM_CB_PCI_INTX_SLOT_SHIFT) \ 83 | (((pin) & HVM_CB_PCI_INTX_INTPIN_MASK) << HVM_CB_PCI_INTX_INTPIN_SHIFT)) 84 85 /** Format for specifying a direct IDT vector injection style callback. */ 86 enum { 87 HVM_CB_VECTOR_VECTOR_MASK = 0xFFFFFFFF, 88 HVM_CB_VECTOR_VECTOR_SHIFT = 0 89 }; 90 #define HVM_CALLBACK_VECTOR(vector) \ 91 (((uint64_t)HVM_CB_TYPE_VECTOR << HVM_CB_TYPE_SHIFT) \ 92 | (((vector) & HVM_CB_GSI_GSI_MASK) << HVM_CB_GSI_GSI_SHIFT)) 93 94 enum xen_hvm_init_type { 95 XEN_HVM_INIT_EARLY, 96 XEN_HVM_INIT_LATE, 97 XEN_HVM_INIT_CANCELLED_SUSPEND, 98 XEN_HVM_INIT_RESUME, 99 }; 100 101 int xen_hvm_init_hypercall_stubs(enum xen_hvm_init_type); 102 void xen_hvm_set_callback(device_t); 103 void xen_hvm_suspend(void); 104 void xen_hvm_resume(bool suspend_cancelled); 105 106 extern uint32_t hvm_start_flags; 107 108 #endif /* __XEN_HVM_H__ */ 109