Debian Codegraph @

tools/ocaml/libs/xc/xenctrl.ml

raw
1 (*
2 * Copyright (C) 2006-2007 XenSource Ltd.
3 * Copyright (C) 2008 Citrix Ltd.
4 * Author Vincent Hanquez <[email protected]>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation; version 2.1 only. with the special
9 * exception on linking described in file LICENSE.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *)
16
17 (** *)
18 type domid = int
19
20 (* ** xenctrl.h ** *)
21
22 type vcpuinfo =
23 {
24 online: bool;
25 blocked: bool;
26 running: bool;
27 cputime: int64;
28 cpumap: int32;
29 }
30
31 type xen_arm_arch_domainconfig =
32 {
33 gic_version: int;
34 nr_spis: int;
35 clock_frequency: int32;
36 }
37
38 type x86_arch_emulation_flags =
39 | X86_EMU_LAPIC
40 | X86_EMU_HPET
41 | X86_EMU_PM
42 | X86_EMU_RTC
43 | X86_EMU_IOAPIC
44 | X86_EMU_PIC
45 | X86_EMU_VGA
46 | X86_EMU_IOMMU
47 | X86_EMU_PIT
48 | X86_EMU_USE_PIRQ
49 | X86_EMU_VPCI
50
51 type x86_arch_misc_flags =
52 | X86_MSR_RELAXED
53
54 type xen_x86_arch_domainconfig =
55 {
56 emulation_flags: x86_arch_emulation_flags list;
57 misc_flags: x86_arch_misc_flags list;
58 }
59
60 type arch_domainconfig =
61 | ARM of xen_arm_arch_domainconfig
62 | X86 of xen_x86_arch_domainconfig
63
64 type domain_create_flag =
65 | CDF_HVM
66 | CDF_HAP
67 | CDF_S3_INTEGRITY
68 | CDF_OOS_OFF
69 | CDF_XS_DOMAIN
70 | CDF_IOMMU
71 | CDF_NESTED_VIRT
72 | CDF_VPMU
73
74 type domain_create_iommu_opts =
75 | IOMMU_NO_SHAREPT
76
77 type domctl_create_config =
78 {
79 ssidref: int32;
80 handle: string;
81 flags: domain_create_flag list;
82 iommu_opts: domain_create_iommu_opts list;
83 max_vcpus: int;
84 max_evtchn_port: int;
85 max_grant_frames: int;
86 max_maptrack_frames: int;
87 max_grant_version: int;
88 altp2m_opts: int32;
89 vmtrace_buf_kb: int32;
90 cpupool_id: int32;
91 arch: arch_domainconfig;
92 }
93
94 type domaininfo =
95 {
96 domid : domid;
97 dying : bool;
98 shutdown : bool;
99 paused : bool;
100 blocked : bool;
101 running : bool;
102 hvm_guest : bool;
103 shutdown_code : int;
104 total_memory_pages: nativeint;
105 max_memory_pages : nativeint;
106 shared_info_frame : int64;
107 cpu_time : int64;
108 nr_online_vcpus : int;
109 max_vcpu_id : int;
110 ssidref : int32;
111 handle : int array;
112 arch_config : arch_domainconfig;
113 }
114
115 type sched_control =
116 {
117 weight : int;
118 cap : int;
119 }
120
121 type physinfo_cap_flag =
122 | CAP_HVM
123 | CAP_PV
124 | CAP_DirectIO
125 | CAP_HAP
126 | CAP_Shadow
127 | CAP_IOMMU_HAP_PT_SHARE
128 | CAP_Vmtrace
129 | CAP_Vpmu
130 | CAP_Gnttab_v1
131 | CAP_Gnttab_v2
132
133 type arm_physinfo_caps =
134 {
135 sve_vl: int;
136 }
137
138 type x86_physinfo_cap_flag
139
140 type arch_physinfo_cap_flags =
141 | ARM of arm_physinfo_caps
142 | X86 of x86_physinfo_cap_flag list
143
144 type physinfo =
145 {
146 threads_per_core : int;
147 cores_per_socket : int;
148 nr_cpus : int;
149 max_node_id : int;
150 cpu_khz : int;
151 total_pages : nativeint;
152 free_pages : nativeint;
153 scrub_pages : nativeint;
154 (* XXX hw_cap *)
155 capabilities : physinfo_cap_flag list;
156 max_nr_cpus : int;
157 arch_capabilities : arch_physinfo_cap_flags;
158 }
159
160 type version =
161 {
162 major : int;
163 minor : int;
164 extra : string;
165 }
166
167
168 type compile_info =
169 {
170 compiler : string;
171 compile_by : string;
172 compile_domain : string;
173 compile_date : string;
174 }
175
176 type shutdown_reason = Poweroff | Reboot | Suspend | Crash | Watchdog | Soft_reset
177
178 exception Error of string
179
180 type handle
181
182 external interface_open: unit -> handle = "stub_xc_interface_open"
183
184 let handle = ref None
185
186 let get_handle () = !handle
187
188 let close_handle () =
189 match !handle with
190 | Some _ -> handle := None
191 | None -> ()
192
193 let with_intf f =
194 match !handle with
195 | Some h -> f h
196 | None ->
197 let h =
198 try interface_open () with
199 | e ->
200 let msg = Printexc.to_string e in
201 failwith ("failed to open xenctrl: "^msg)
202 in
203 handle := Some h;
204 f h
205
206 external domain_create_stub: handle -> domid -> domctl_create_config -> domid
207 = "stub_xc_domain_create"
208
209 let domain_create handle ?(domid=0) config =
210 domain_create_stub handle domid config
211
212 external domain_sethandle: handle -> domid -> string -> unit
213 = "stub_xc_domain_sethandle"
214
215 external domain_max_vcpus: handle -> domid -> int -> unit
216 = "stub_xc_domain_max_vcpus"
217
218 external domain_pause: handle -> domid -> unit = "stub_xc_domain_pause"
219 external domain_unpause: handle -> domid -> unit = "stub_xc_domain_unpause"
220 external domain_resume_fast: handle -> domid -> unit = "stub_xc_domain_resume_fast"
221 external domain_destroy: handle -> domid -> unit = "stub_xc_domain_destroy"
222
223 external domain_shutdown: handle -> domid -> shutdown_reason -> unit
224 = "stub_xc_domain_shutdown"
225
226 external _domain_getinfolist: handle -> domid -> int -> domaininfo list
227 = "stub_xc_domain_getinfolist"
228
229 let rev_append_fold acc e = List.rev_append e acc
230
231 (**
232 * [rev_concat lst] is equivalent to [lst |> List.concat |> List.rev]
233 * except it is tail recursive, whereas [List.concat] isn't.
234 * Example:
235 * rev_concat [[10;9;8];[7;6];[5]]] = [5; 6; 7; 8; 9; 10]
236 *)
237 let rev_concat lst = List.fold_left rev_append_fold [] lst
238
239 let domain_getinfolist handle first_domain =
240 let nb = 1024 in
241 let rec __getlist lst from =
242 (* _domain_getinfolist returns domains in reverse order, largest first *)
243 match _domain_getinfolist handle from nb with
244 | [] -> rev_concat lst
245 | (hd :: _) as l -> __getlist (l :: lst) (hd.domid + 1)
246 in
247 __getlist [] first_domain
248
249 external domain_getinfo: handle -> domid -> domaininfo= "stub_xc_domain_getinfo"
250
251 external domain_get_vcpuinfo: handle -> int -> int -> vcpuinfo
252 = "stub_xc_vcpu_getinfo"
253
254 external domain_ioport_permission: handle -> domid -> int -> int -> bool -> unit
255 = "stub_xc_domain_ioport_permission"
256 external domain_iomem_permission: handle -> domid -> nativeint -> nativeint -> bool -> unit
257 = "stub_xc_domain_iomem_permission"
258 external domain_irq_permission: handle -> domid -> int -> bool -> unit
259 = "stub_xc_domain_irq_permission"
260
261 external vcpu_affinity_set: handle -> domid -> int -> bool array -> unit
262 = "stub_xc_vcpu_setaffinity"
263 external vcpu_affinity_get: handle -> domid -> int -> bool array
264 = "stub_xc_vcpu_getaffinity"
265
266 external vcpu_context_get: handle -> domid -> int -> string
267 = "stub_xc_vcpu_context_get"
268
269 external sched_id: handle -> int = "stub_xc_sched_id"
270
271 external sched_credit_domain_set: handle -> domid -> sched_control -> unit
272 = "stub_sched_credit_domain_set"
273 external sched_credit_domain_get: handle -> domid -> sched_control
274 = "stub_sched_credit_domain_get"
275
276 external shadow_allocation_set: handle -> domid -> int -> unit
277 = "stub_shadow_allocation_set"
278 external shadow_allocation_get: handle -> domid -> int
279 = "stub_shadow_allocation_get"
280
281 external evtchn_alloc_unbound: handle -> domid -> domid -> int
282 = "stub_xc_evtchn_alloc_unbound"
283 external evtchn_reset: handle -> domid -> unit = "stub_xc_evtchn_reset"
284
285 (* FIFO has theoretical maximum of 2^28 ports, fits in an int *)
286 type evtchn_interdomain = { dom: domid; port: int }
287
288 type evtchn_stat =
289 | EVTCHNSTAT_unbound of domid
290 | EVTCHNSTAT_interdomain of evtchn_interdomain
291 | EVTCHNSTAT_pirq of int
292 | EVTCHNSTAT_virq of Xeneventchn.virq_t
293 | EVTCHNSTAT_ipi
294
295 type evtchn_status = { vcpu: int; status: evtchn_stat }
296
297 external evtchn_status: handle -> domid -> int -> evtchn_status option =
298 "stub_xc_evtchn_status"
299
300 external readconsolering: handle -> string = "stub_xc_readconsolering"
301
302 external send_debug_keys: handle -> string -> unit = "stub_xc_send_debug_keys"
303 external physinfo: handle -> physinfo = "stub_xc_physinfo"
304 external pcpu_info: handle -> int -> int64 array = "stub_xc_pcpu_info"
305
306 external domain_setmaxmem: handle -> domid -> int64 -> unit
307 = "stub_xc_domain_setmaxmem"
308 external domain_set_memmap_limit: handle -> domid -> int64 -> unit
309 = "stub_xc_domain_set_memmap_limit"
310 external domain_memory_increase_reservation: handle -> domid -> int64 -> unit
311 = "stub_xc_domain_memory_increase_reservation"
312
313 external map_foreign_range: handle -> domid -> int
314 -> nativeint -> Xenmmap.mmap_interface
315 = "stub_map_foreign_range"
316
317 type hvm_param =
318 | HVM_PARAM_CALLBACK_IRQ
319 | HVM_PARAM_STORE_PFN
320 | HVM_PARAM_STORE_EVTCHN
321 | HVM_PARAM_UNDEF_3
322 | HVM_PARAM_PAE_ENABLED
323 | HVM_PARAM_IOREQ_PFN
324 | HVM_PARAM_BUFIOREQ_PFN
325 | HVM_PARAM_UNDEF_7
326 | HVM_PARAM_UNDEF_8
327 | HVM_PARAM_VIRIDIAN
328 | HVM_PARAM_TIMER_MODE
329 | HVM_PARAM_HPET_ENABLED
330 | HVM_PARAM_IDENT_PT
331 | HVM_PARAM_UNDEF_13
332 | HVM_PARAM_ACPI_S_STATE
333 | HVM_PARAM_VM86_TSS
334 | HVM_PARAM_VPT_ALIGN
335 | HVM_PARAM_CONSOLE_PFN
336 | HVM_PARAM_CONSOLE_EVTCHN
337 | HVM_PARAM_ACPI_IOPORTS_LOCATION
338 | HVM_PARAM_MEMORY_EVENT_CR0
339 | HVM_PARAM_MEMORY_EVENT_CR3
340 | HVM_PARAM_MEMORY_EVENT_CR4
341 | HVM_PARAM_MEMORY_EVENT_INT3
342 | HVM_PARAM_NESTEDHVM
343 | HVM_PARAM_MEMORY_EVENT_SINGLE_STEP
344 | HVM_PARAM_UNDEF_26
345 | HVM_PARAM_PAGING_RING_PFN
346 | HVM_PARAM_MONITOR_RING_PFN
347 | HVM_PARAM_SHARING_RING_PFN
348 | HVM_PARAM_MEMORY_EVENT_MSR
349 | HVM_PARAM_TRIPLE_FAULT_REASON
350 | HVM_PARAM_IOREQ_SERVER_PFN
351 | HVM_PARAM_NR_IOREQ_SERVER_PAGES
352 | HVM_PARAM_VM_GENERATION_ID_ADDR
353 | HVM_PARAM_ALTP2M
354 | HVM_PARAM_X87_FIP_WIDTH
355 | HVM_PARAM_VM86_TSS_SIZED
356 | HVM_PARAM_MCA_CAP
357
358 external hvm_param_get: handle -> domid -> hvm_param -> int64
359 = "stub_xc_hvm_param_get"
360
361 external hvm_param_set: handle -> domid -> hvm_param -> int64 -> unit
362 = "stub_xc_hvm_param_set"
363
364 external domain_assign_device: handle -> domid -> (int * int * int * int) -> unit
365 = "stub_xc_domain_assign_device"
366 external domain_deassign_device: handle -> domid -> (int * int * int * int) -> unit
367 = "stub_xc_domain_deassign_device"
368 external domain_test_assign_device: handle -> domid -> (int * int * int * int) -> bool
369 = "stub_xc_domain_test_assign_device"
370
371 external version: handle -> version = "stub_xc_version_version"
372 external version_compile_info: handle -> compile_info
373 = "stub_xc_version_compile_info"
374 external version_changeset: handle -> string = "stub_xc_version_changeset"
375 external version_capabilities: handle -> string =
376 "stub_xc_version_capabilities"
377
378 type featureset_index =
379 | Featureset_raw
380 | Featureset_host
381 | Featureset_pv
382 | Featureset_hvm
383 | Featureset_pv_max
384 | Featureset_hvm_max
385 external get_cpu_featureset : handle -> featureset_index -> int64 array = "stub_xc_get_cpu_featureset"
386
387 external watchdog : handle -> int -> int32 -> int
388 = "stub_xc_watchdog"
389
390 (* ** Misc ** *)
391
392 (**
393 Convert the given number of pages to an amount in KiB, rounded up.
394 *)
395 external pages_to_kib : int64 -> int64 = "stub_pages_to_kib"
396 let pages_to_mib pages = Int64.div (pages_to_kib pages) 1024L
397
398 let _ = Callback.register_exception "xc.error" (Error "register_callback")