1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 3 /* Test programs for various Xen versions that QEMU supports. */ 4 #if CONFIG_XEN_CTRL_INTERFACE_VERSION == 41100 5 #undef XC_WANT_COMPAT_DEVICEMODEL_API 6 #define __XEN_TOOLS__ 7 #include <xendevicemodel.h> 8 #include <xenforeignmemory.h> 9 int main(void) { 10 xendevicemodel_handle *xd; 11 xenforeignmemory_handle *xfmem; 12 13 xd = xendevicemodel_open(0, 0); 14 xendevicemodel_pin_memory_cacheattr(xd, 0, 0, 0, 0); 15 16 xfmem = xenforeignmemory_open(0, 0); 17 xenforeignmemory_map_resource(xfmem, 0, 0, 0, 0, 0, NULL, 0, 0); 18 19 return 0; 20 } 21 22 #elif CONFIG_XEN_CTRL_INTERFACE_VERSION == 41000 23 #undef XC_WANT_COMPAT_MAP_FOREIGN_API 24 #include <xenforeignmemory.h> 25 #include <xentoolcore.h> 26 int main(void) { 27 xenforeignmemory_handle *xfmem; 28 29 xfmem = xenforeignmemory_open(0, 0); 30 xenforeignmemory_map2(xfmem, 0, 0, 0, 0, 0, 0, 0); 31 xentoolcore_restrict_all(0); 32 33 return 0; 34 } 35 36 #elif CONFIG_XEN_CTRL_INTERFACE_VERSION == 40900 37 #undef XC_WANT_COMPAT_DEVICEMODEL_API 38 #define __XEN_TOOLS__ 39 #include <xendevicemodel.h> 40 int main(void) { 41 xendevicemodel_handle *xd; 42 43 xd = xendevicemodel_open(0, 0); 44 xendevicemodel_close(xd); 45 46 return 0; 47 } 48 49 #elif CONFIG_XEN_CTRL_INTERFACE_VERSION == 40800 50 /* 51 * If we have stable libs the we don't want the libxc compat 52 * layers, regardless of what CFLAGS we may have been given. 53 * 54 * Also, check if xengnttab_grant_copy_segment_t is defined and 55 * grant copy operation is implemented. 56 */ 57 #undef XC_WANT_COMPAT_EVTCHN_API 58 #undef XC_WANT_COMPAT_GNTTAB_API 59 #undef XC_WANT_COMPAT_MAP_FOREIGN_API 60 #include <xenctrl.h> 61 #include <xenstore.h> 62 #include <xenevtchn.h> 63 #include <xengnttab.h> 64 #include <xenforeignmemory.h> 65 #include <stdint.h> 66 #include <xen/hvm/hvm_info_table.h> 67 #if !defined(HVM_MAX_VCPUS) 68 # error HVM_MAX_VCPUS not defined 69 #endif 70 int main(void) { 71 xc_interface *xc = NULL; 72 xenforeignmemory_handle *xfmem; 73 xenevtchn_handle *xe; 74 xengnttab_handle *xg; 75 xengnttab_grant_copy_segment_t* seg = NULL; 76 77 xs_daemon_open(); 78 79 xc = xc_interface_open(0, 0, 0); 80 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); 81 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); 82 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); 83 xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL); 84 85 xfmem = xenforeignmemory_open(0, 0); 86 xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0); 87 88 xe = xenevtchn_open(0, 0); 89 xenevtchn_fd(xe); 90 91 xg = xengnttab_open(0, 0); 92 xengnttab_grant_copy(xg, 0, seg); 93 94 return 0; 95 } 96 97 #elif CONFIG_XEN_CTRL_INTERFACE_VERSION == 40701 98 /* 99 * If we have stable libs the we don't want the libxc compat 100 * layers, regardless of what CFLAGS we may have been given. 101 */ 102 #undef XC_WANT_COMPAT_EVTCHN_API 103 #undef XC_WANT_COMPAT_GNTTAB_API 104 #undef XC_WANT_COMPAT_MAP_FOREIGN_API 105 #include <xenctrl.h> 106 #include <xenstore.h> 107 #include <xenevtchn.h> 108 #include <xengnttab.h> 109 #include <xenforeignmemory.h> 110 #include <stdint.h> 111 #include <xen/hvm/hvm_info_table.h> 112 #if !defined(HVM_MAX_VCPUS) 113 # error HVM_MAX_VCPUS not defined 114 #endif 115 int main(void) { 116 xc_interface *xc = NULL; 117 xenforeignmemory_handle *xfmem; 118 xenevtchn_handle *xe; 119 xengnttab_handle *xg; 120 121 xs_daemon_open(); 122 123 xc = xc_interface_open(0, 0, 0); 124 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); 125 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); 126 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); 127 xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL); 128 129 xfmem = xenforeignmemory_open(0, 0); 130 xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0); 131 132 xe = xenevtchn_open(0, 0); 133 xenevtchn_fd(xe); 134 135 xg = xengnttab_open(0, 0); 136 xengnttab_map_grant_ref(xg, 0, 0, 0); 137 138 return 0; 139 } 140 141 #elif CONFIG_XEN_CTRL_INTERFACE_VERSION == 40600 142 #include <xenctrl.h> 143 #include <xenstore.h> 144 #include <stdint.h> 145 #include <xen/hvm/hvm_info_table.h> 146 #if !defined(HVM_MAX_VCPUS) 147 # error HVM_MAX_VCPUS not defined 148 #endif 149 int main(void) { 150 xc_interface *xc; 151 xs_daemon_open(); 152 xc = xc_interface_open(0, 0, 0); 153 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); 154 xc_gnttab_open(NULL, 0); 155 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); 156 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); 157 xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL); 158 xc_reserved_device_memory_map(xc, 0, 0, 0, 0, NULL, 0); 159 return 0; 160 } 161 162 #elif CONFIG_XEN_CTRL_INTERFACE_VERSION == 40500 163 #include <xenctrl.h> 164 #include <xenstore.h> 165 #include <stdint.h> 166 #include <xen/hvm/hvm_info_table.h> 167 #if !defined(HVM_MAX_VCPUS) 168 # error HVM_MAX_VCPUS not defined 169 #endif 170 int main(void) { 171 xc_interface *xc; 172 xs_daemon_open(); 173 xc = xc_interface_open(0, 0, 0); 174 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); 175 xc_gnttab_open(NULL, 0); 176 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); 177 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); 178 xc_hvm_create_ioreq_server(xc, 0, 0, NULL); 179 return 0; 180 } 181 182 #elif CONFIG_XEN_CTRL_INTERFACE_VERSION == 40200 183 #include <xenctrl.h> 184 #include <xenstore.h> 185 #include <stdint.h> 186 #include <xen/hvm/hvm_info_table.h> 187 #if !defined(HVM_MAX_VCPUS) 188 # error HVM_MAX_VCPUS not defined 189 #endif 190 int main(void) { 191 xc_interface *xc; 192 xs_daemon_open(); 193 xc = xc_interface_open(0, 0, 0); 194 xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); 195 xc_gnttab_open(NULL, 0); 196 xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); 197 xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); 198 return 0; 199 } 200 201 #else 202 #error invalid CONFIG_XEN_CTRL_INTERFACE_VERSION 203 #endif 204