Merge tag 'v9.1.0'
[qemu/ar7.git] / scripts / xen-detect.c
blobdb049e605cf9ab3ec07c568a1db7e6ac3559da49
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
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;
13 xd = xendevicemodel_open(0, 0);
14 xendevicemodel_pin_memory_cacheattr(xd, 0, 0, 0, 0);
16 xfmem = xenforeignmemory_open(0, 0);
17 xenforeignmemory_map_resource(xfmem, 0, 0, 0, 0, 0, NULL, 0, 0);
19 return 0;
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;
29 xfmem = xenforeignmemory_open(0, 0);
30 xenforeignmemory_map2(xfmem, 0, 0, 0, 0, 0, 0, 0);
31 xentoolcore_restrict_all(0);
33 return 0;
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;
43 xd = xendevicemodel_open(0, 0);
44 xendevicemodel_close(xd);
46 return 0;
49 #elif CONFIG_XEN_CTRL_INTERFACE_VERSION == 40800
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.
54 * Also, check if xengnttab_grant_copy_segment_t is defined and
55 * grant copy operation is implemented.
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;
77 xs_daemon_open();
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);
85 xfmem = xenforeignmemory_open(0, 0);
86 xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
88 xe = xenevtchn_open(0, 0);
89 xenevtchn_fd(xe);
91 xg = xengnttab_open(0, 0);
92 xengnttab_grant_copy(xg, 0, seg);
94 return 0;
97 #elif CONFIG_XEN_CTRL_INTERFACE_VERSION == 40701
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.
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;
121 xs_daemon_open();
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);
129 xfmem = xenforeignmemory_open(0, 0);
130 xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
132 xe = xenevtchn_open(0, 0);
133 xenevtchn_fd(xe);
135 xg = xengnttab_open(0, 0);
136 xengnttab_map_grant_ref(xg, 0, 0, 0);
138 return 0;
141 #else
142 #error invalid CONFIG_XEN_CTRL_INTERFACE_VERSION
143 #endif