aboutsummaryrefslogtreecommitdiff
path: root/scripts/xen-detect.c
blob: 85e8206490e7fc1c27e4f25cd15fdccc105528bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/* SPDX-License-Identifier: GPL-2.0-or-later */

/* Test programs for various Xen versions that QEMU supports.  */
#if CONFIG_XEN_CTRL_INTERFACE_VERSION == 41100
  #undef XC_WANT_COMPAT_DEVICEMODEL_API
  #define __XEN_TOOLS__
  #include <xendevicemodel.h>
  #include <xenforeignmemory.h>
  int main(void) {
    xendevicemodel_handle *xd;
    xenforeignmemory_handle *xfmem;

    xd = xendevicemodel_open(0, 0);
    xendevicemodel_pin_memory_cacheattr(xd, 0, 0, 0, 0);

    xfmem = xenforeignmemory_open(0, 0);
    xenforeignmemory_map_resource(xfmem, 0, 0, 0, 0, 0, NULL, 0, 0);

    return 0;
  }

#elif CONFIG_XEN_CTRL_INTERFACE_VERSION == 41000
  #undef XC_WANT_COMPAT_MAP_FOREIGN_API
  #include <xenforeignmemory.h>
  #include <xentoolcore.h>
  int main(void) {
    xenforeignmemory_handle *xfmem;

    xfmem = xenforeignmemory_open(0, 0);
    xenforeignmemory_map2(xfmem, 0, 0, 0, 0, 0, 0, 0);
    xentoolcore_restrict_all(0);

    return 0;
  }

#elif CONFIG_XEN_CTRL_INTERFACE_VERSION == 40900
  #undef XC_WANT_COMPAT_DEVICEMODEL_API
  #define __XEN_TOOLS__
  #include <xendevicemodel.h>
  int main(void) {
    xendevicemodel_handle *xd;

    xd = xendevicemodel_open(0, 0);
    xendevicemodel_close(xd);

    return 0;
  }

#elif CONFIG_XEN_CTRL_INTERFACE_VERSION == 40800
  /*
   * If we have stable libs the we don't want the libxc compat
   * layers, regardless of what CFLAGS we may have been given.
   *
   * Also, check if xengnttab_grant_copy_segment_t is defined and
   * grant copy operation is implemented.
   */
  #undef XC_WANT_COMPAT_EVTCHN_API
  #undef XC_WANT_COMPAT_GNTTAB_API
  #undef XC_WANT_COMPAT_MAP_FOREIGN_API
  #include <xenctrl.h>
  #include <xenstore.h>
  #include <xenevtchn.h>
  #include <xengnttab.h>
  #include <xenforeignmemory.h>
  #include <stdint.h>
  #include <xen/hvm/hvm_info_table.h>
  #if !defined(HVM_MAX_VCPUS)
  # error HVM_MAX_VCPUS not defined
  #endif
  int main(void) {
    xc_interface *xc = NULL;
    xenforeignmemory_handle *xfmem;
    xenevtchn_handle *xe;
    xengnttab_handle *xg;
    xengnttab_grant_copy_segment_t* seg = NULL;

    xs_daemon_open();

    xc = xc_interface_open(0, 0, 0);
    xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
    xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
    xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
    xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);

    xfmem = xenforeignmemory_open(0, 0);
    xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);

    xe = xenevtchn_open(0, 0);
    xenevtchn_fd(xe);

    xg = xengnttab_open(0, 0);
    xengnttab_grant_copy(xg, 0, seg);

    return 0;
  }

#elif CONFIG_XEN_CTRL_INTERFACE_VERSION == 40701
  /*
   * If we have stable libs the we don't want the libxc compat
   * layers, regardless of what CFLAGS we may have been given.
   */
  #undef XC_WANT_COMPAT_EVTCHN_API
  #undef XC_WANT_COMPAT_GNTTAB_API
  #undef XC_WANT_COMPAT_MAP_FOREIGN_API
  #include <xenctrl.h>
  #include <xenstore.h>
  #include <xenevtchn.h>
  #include <xengnttab.h>
  #include <xenforeignmemory.h>
  #include <stdint.h>
  #include <xen/hvm/hvm_info_table.h>
  #if !defined(HVM_MAX_VCPUS)
  # error HVM_MAX_VCPUS not defined
  #endif
  int main(void) {
    xc_interface *xc = NULL;
    xenforeignmemory_handle *xfmem;
    xenevtchn_handle *xe;
    xengnttab_handle *xg;

    xs_daemon_open();

    xc = xc_interface_open(0, 0, 0);
    xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
    xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
    xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
    xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);

    xfmem = xenforeignmemory_open(0, 0);
    xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);

    xe = xenevtchn_open(0, 0);
    xenevtchn_fd(xe);

    xg = xengnttab_open(0, 0);
    xengnttab_map_grant_ref(xg, 0, 0, 0);

    return 0;
  }

#elif CONFIG_XEN_CTRL_INTERFACE_VERSION == 40600
  #include <xenctrl.h>
  #include <xenstore.h>
  #include <stdint.h>
  #include <xen/hvm/hvm_info_table.h>
  #if !defined(HVM_MAX_VCPUS)
  # error HVM_MAX_VCPUS not defined
  #endif
  int main(void) {
    xc_interface *xc;
    xs_daemon_open();
    xc = xc_interface_open(0, 0, 0);
    xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
    xc_gnttab_open(NULL, 0);
    xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
    xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
    xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
    xc_reserved_device_memory_map(xc, 0, 0, 0, 0, NULL, 0);
    return 0;
  }

#elif CONFIG_XEN_CTRL_INTERFACE_VERSION == 40500
  #include <xenctrl.h>
  #include <xenstore.h>
  #include <stdint.h>
  #include <xen/hvm/hvm_info_table.h>
  #if !defined(HVM_MAX_VCPUS)
  # error HVM_MAX_VCPUS not defined
  #endif
  int main(void) {
    xc_interface *xc;
    xs_daemon_open();
    xc = xc_interface_open(0, 0, 0);
    xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
    xc_gnttab_open(NULL, 0);
    xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
    xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
    xc_hvm_create_ioreq_server(xc, 0, 0, NULL);
    return 0;
  }

#elif CONFIG_XEN_CTRL_INTERFACE_VERSION == 40200
  #include <xenctrl.h>
  #include <xenstore.h>
  #include <stdint.h>
  #include <xen/hvm/hvm_info_table.h>
  #if !defined(HVM_MAX_VCPUS)
  # error HVM_MAX_VCPUS not defined
  #endif
  int main(void) {
    xc_interface *xc;
    xs_daemon_open();
    xc = xc_interface_open(0, 0, 0);
    xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
    xc_gnttab_open(NULL, 0);
    xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
    xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
    return 0;
  }

#else
#error invalid CONFIG_XEN_CTRL_INTERFACE_VERSION
#endif