Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 251 lines (215 sloc) 6.807 kB
aa4c5c9 @djs55 [xenctrlext]: add 'xenctrlext' to contain miscellaneous bindings not …
djs55 authored
1 /*
2 * Copyright (C) Citrix Systems Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation; version 2.1 only. with the special
7 * exception on linking described in file LICENSE.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 */
14
15 #include <errno.h>
16 #include <fcntl.h>
17 #include <stdio.h>
18 #include <stdlib.h>
b09b34e @djs55 [xenctrlext]: add domain_set_{timer_mode,hpet,vpt_align}, domain_send…
djs55 authored
19 #include <string.h>
aa4c5c9 @djs55 [xenctrlext]: add 'xenctrlext' to contain miscellaneous bindings not …
djs55 authored
20 #include <unistd.h>
b09b34e @djs55 [xenctrlext]: add domain_set_{timer_mode,hpet,vpt_align}, domain_send…
djs55 authored
21 #include <xenctrl.h>
aa4c5c9 @djs55 [xenctrlext]: add 'xenctrlext' to contain miscellaneous bindings not …
djs55 authored
22
23 #include <caml/mlvalues.h>
24 #include <caml/memory.h>
25 #include <caml/alloc.h>
26 #include <caml/custom.h>
27 #include <caml/fail.h>
28 #include <caml/signals.h>
b09b34e @djs55 [xenctrlext]: add domain_set_{timer_mode,hpet,vpt_align}, domain_send…
djs55 authored
29 #include <caml/callback.h>
30
31 #define _H(__h) ((xc_interface *)(__h))
32 #define _D(__d) ((uint32_t)Int_val(__d))
33
34 /* From xenctrl_stubs */
35 #define ERROR_STRLEN 1024
36 static void failwith_xc(xc_interface *xch)
37 {
38 static char error_str[ERROR_STRLEN];
39 if (xch) {
40 const xc_error *error = xc_get_last_error(xch);
41 if (error->code == XC_ERROR_NONE)
42 snprintf(error_str, ERROR_STRLEN, "%d: %s", errno, strerror(errno));
43 else
44 snprintf(error_str, ERROR_STRLEN, "%d: %s: %s",
45 error->code,
46 xc_error_code_to_desc(error->code),
47 error->message);
48 } else {
49 snprintf(error_str, ERROR_STRLEN, "Unable to open XC interface");
50 }
51 caml_raise_with_string(*caml_named_value("xc.error"), error_str);
52 }
53
47cf39c @djs55 [xenctrlext]: make sure all C symbols have 'xenctrlext' in the name t…
djs55 authored
54 CAMLprim value stub_xenctrlext_get_runstate_info(value xch, value domid)
9966dc9 @djs55 [xenctrlext]: add domain_get_runstate_info
djs55 authored
55 {
56 CAMLparam2(xch, domid);
57 #if defined(XENCTRL_HAS_GET_RUNSTATE_INFO)
58 CAMLlocal1(result);
59 xc_runstate_info_t info;
60 int retval;
61
62 retval = xc_get_runstate_info(_H(xch), _D(domid), &info);
63 if (retval < 0)
64 failwith_xc(_H(xch));
65
66 /* Store
67 0 : state (int32)
68 1 : missed_changes (int32)
69 2 : state_entry_time (int64)
70 3-8 : times (int64s)
71 */
72 result = caml_alloc_tuple(9);
73 Store_field(result, 0, caml_copy_int32(info.state));
74 Store_field(result, 1, caml_copy_int32(info.missed_changes));
75 Store_field(result, 2, caml_copy_int64(info.state_entry_time));
76 Store_field(result, 3, caml_copy_int64(info.time[0]));
77 Store_field(result, 4, caml_copy_int64(info.time[1]));
78 Store_field(result, 5, caml_copy_int64(info.time[2]));
79 Store_field(result, 6, caml_copy_int64(info.time[3]));
80 Store_field(result, 7, caml_copy_int64(info.time[4]));
81 Store_field(result, 8, caml_copy_int64(info.time[5]));
82
83 CAMLreturn(result);
84 #else
85 caml_failwith("XENCTRL_HAS_GET_RUNSTATE_INFO not defined");
86 #endif
87 }
aa4c5c9 @djs55 [xenctrlext]: add 'xenctrlext' to contain miscellaneous bindings not …
djs55 authored
88
89 CAMLprim value stub_xenctrlext_get_boot_cpufeatures(value xch)
90 {
91 CAMLparam1(xch);
92 #if defined(XENCTRL_HAS_GET_CPUFEATURES)
93 CAMLlocal1(v);
94 uint32_t a, b, c, d, e, f, g, h;
95 int ret;
96
97 ret = xc_get_boot_cpufeatures(_H(xch), &a, &b, &c, &d, &e, &f, &g, &h);
98 if (ret < 0)
99 failwith_xc(_H(xch));
100
101 v = caml_alloc_tuple(8);
102 Store_field(v, 0, caml_copy_int32(a));
103 Store_field(v, 1, caml_copy_int32(b));
104 Store_field(v, 2, caml_copy_int32(c));
105 Store_field(v, 3, caml_copy_int32(d));
106 Store_field(v, 4, caml_copy_int32(e));
107 Store_field(v, 5, caml_copy_int32(f));
108 Store_field(v, 6, caml_copy_int32(g));
109 Store_field(v, 7, caml_copy_int32(h));
110
111 CAMLreturn(v);
112 #else
b09b34e @djs55 [xenctrlext]: add domain_set_{timer_mode,hpet,vpt_align}, domain_send…
djs55 authored
113 caml_failwith("XENCTRL_HAS_GET_CPUFEATURES not defined");
aa4c5c9 @djs55 [xenctrlext]: add 'xenctrlext' to contain miscellaneous bindings not …
djs55 authored
114 #endif
115 }
b09b34e @djs55 [xenctrlext]: add domain_set_{timer_mode,hpet,vpt_align}, domain_send…
djs55 authored
116
117 static int xcext_domain_send_s3resume(xc_interface *xch, unsigned int domid)
118 {
119 return xc_set_hvm_param(xch, domid, HVM_PARAM_ACPI_S_STATE, 0);
120 }
121
122 static int xcext_domain_set_timer_mode(xc_interface *xch, unsigned int domid, int mode)
123 {
124 return xc_set_hvm_param(xch, domid,
125 HVM_PARAM_TIMER_MODE, (unsigned long) mode);
126 }
127
128 CAMLprim value stub_xenctrlext_domain_get_acpi_s_state(value xch, value domid)
129 {
130 CAMLparam2(xch, domid);
131 unsigned long v;
132 int ret;
133
134 ret = xc_get_hvm_param(_H(xch), _D(domid), HVM_PARAM_ACPI_S_STATE, &v);
135 if (ret != 0)
136 failwith_xc(_H(xch));
137
138 CAMLreturn(Val_int(v));
139 }
140
141 CAMLprim value stub_xenctrlext_domain_send_s3resume(value xch, value domid)
142 {
143 CAMLparam2(xch, domid);
144 xcext_domain_send_s3resume(_H(xch), _D(domid));
145 CAMLreturn(Val_unit);
146 }
147
148 CAMLprim value stub_xenctrlext_domain_set_timer_mode(value xch, value id, value mode)
149 {
150 CAMLparam3(xch, id, mode);
151 int ret;
152
153 ret = xcext_domain_set_timer_mode(_H(xch), _D(id), Int_val(mode));
154 if (ret < 0)
155 failwith_xc(_H(xch));
156 CAMLreturn(Val_unit);
157 }
158
47cf39c @djs55 [xenctrlext]: make sure all C symbols have 'xenctrlext' in the name t…
djs55 authored
159 CAMLprim value stub_xenctrlext_domain_trigger_power(value xch, value domid)
e35d0f2 @djs55 [xenctrlext]: Add domain_trigger_{power,sleep}
djs55 authored
160 {
161 CAMLparam2(xch, domid);
162 #if defined(XENCTRL_HAS_TRIGGER_POWER)
163 xc_domain_trigger_power(_H(xch), _D(domid));
164 #endif
165 CAMLreturn(Val_unit);
166 }
167
47cf39c @djs55 [xenctrlext]: make sure all C symbols have 'xenctrlext' in the name t…
djs55 authored
168 CAMLprim value stub_xenctrlext_domain_trigger_sleep(value xch, value domid)
e35d0f2 @djs55 [xenctrlext]: Add domain_trigger_{power,sleep}
djs55 authored
169 {
170 CAMLparam2(xch, domid);
171 #if defined(XENCTRL_HAS_TRIGGER_SLEEP)
172 xc_domain_trigger_sleep(_H(xch), _D(domid));
173 #endif
174 CAMLreturn(Val_unit);
175 }
176
493f6dd @djs55 [xenctrlext]: add binding to xc_domain_suppress_spurious_page_faults
djs55 authored
177 CAMLprim value stub_xenctrlext_domain_suppress_spurious_page_faults(value xch,
178 value domid)
179 {
180 CAMLparam2(xch, domid);
181
182 int retval = xc_domain_suppress_spurious_page_faults(_H(xch), _D(domid));
183 if (retval)
184 failwith_xc(_H(xch));
185 CAMLreturn(Val_unit);
186 }
e35d0f2 @djs55 [xenctrlext]: Add domain_trigger_{power,sleep}
djs55 authored
187
db2e2e9 @djs55 [xenctrlext]: add get_max_nr_cpus
djs55 authored
188 CAMLprim value stub_xenctrlext_get_max_nr_cpus(value xch)
189 {
190 CAMLparam1(xch);
191 xc_physinfo_t c_physinfo;
192 int r;
193
194 caml_enter_blocking_section();
195 r = xc_physinfo(_H(xch), &c_physinfo);
196 caml_leave_blocking_section();
197
198 if (r)
199 failwith_xc(_H(xch));
200
201 CAMLreturn(Val_int(c_physinfo.max_cpu_id + 1));
202 }
203
bf0fb47 @djs55 [xenctrlext]: add 'domain_set_target' binding
djs55 authored
204 CAMLprim value stub_xenctrlext_domain_set_target(value xch,
205 value domid,
206 value target)
207 {
208 CAMLparam3(xch, domid, target);
209
210 int retval = xc_domain_set_target(_H(xch), _D(domid), _D(target));
211 if (retval)
212 failwith_xc(_H(xch));
213 CAMLreturn(Val_unit);
214 }
215
dcadccf @jonludlam CP-4480: Add a call to check whether PV drivers have started
jonludlam authored
216 CAMLprim value stub_xenctrlext_domain_pvcontrol_available(value xch,
217 value domid)
218 {
219 CAMLparam2(xch, domid);
220
221 int ret;
222 xc_domaininfo_t info;
223 value result = Val_false;
224 unsigned long pvdriver = 0;
225
226 ret = xc_domain_getinfolist(_H(xch), _D(domid), 1, &info);
227 if(ret != 1 || info.domain != _D(domid)) {
228 failwith_xc(_H(xch));
229 }
230
231 /* PV guests are always controllable */
232 if(!(info.flags & XEN_DOMINF_hvm_guest)) {
233 result = Val_true;
234 } else {
235 ret = xc_get_hvm_param(_H(xch), _D(domid), HVM_PARAM_CALLBACK_IRQ, &pvdriver);
236 if(ret<0) {
237 failwith_xc(_H(xch));
238 }
239 if(pvdriver!=0) {
240 /* If an HVM guest has set its CALLBACK_IRQ, it should be controllable */
241 result = Val_true;
242 }
243 }
244
245 CAMLreturn(result);
246 }
aa4c5c9 @djs55 [xenctrlext]: add 'xenctrlext' to contain miscellaneous bindings not …
djs55 authored
247 /*
248 * Local variables:
249 * indent-tabs-mode: t
250 */
Something went wrong with that request. Please try again.