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