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 #else 142 #error invalid CONFIG_XEN_CTRL_INTERFACE_VERSION 143 #endif 144