1(*
2 * Copyright (C) 2006-2007 XenSource Ltd.
3 * Copyright (C) 2008      Citrix Ltd.
4 * Author Vincent Hanquez <vincent.hanquez@eu.citrix.com>
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
17type domid = int
18type vcpuinfo = {
19  online : bool;
20  blocked : bool;
21  running : bool;
22  cputime : int64;
23  cpumap : int32;
24}
25
26type xen_arm_arch_domainconfig = {
27  gic_version: int;
28  nr_spis: int;
29  clock_frequency: int32;
30}
31
32type x86_arch_emulation_flags =
33  | X86_EMU_LAPIC
34  | X86_EMU_HPET
35  | X86_EMU_PM
36  | X86_EMU_RTC
37  | X86_EMU_IOAPIC
38  | X86_EMU_PIC
39  | X86_EMU_VGA
40  | X86_EMU_IOMMU
41  | X86_EMU_PIT
42  | X86_EMU_USE_PIRQ
43  | X86_EMU_VPCI
44
45type x86_arch_misc_flags =
46  | X86_MSR_RELAXED
47
48type xen_x86_arch_domainconfig = {
49  emulation_flags: x86_arch_emulation_flags list;
50  misc_flags: x86_arch_misc_flags list;
51}
52
53type arch_domainconfig =
54  | ARM of xen_arm_arch_domainconfig
55  | X86 of xen_x86_arch_domainconfig
56
57type domain_create_flag =
58  | CDF_HVM
59  | CDF_HAP
60  | CDF_S3_INTEGRITY
61  | CDF_OOS_OFF
62  | CDF_XS_DOMAIN
63  | CDF_IOMMU
64  | CDF_NESTED_VIRT
65  | CDF_VPMU
66  | CDF_TRAP_UNMAPPED_ACCESSES
67
68type domain_create_iommu_opts =
69  | IOMMU_NO_SHAREPT
70
71type domctl_create_config = {
72  ssidref: int32;
73  handle: string;
74  flags: domain_create_flag list;
75  iommu_opts: domain_create_iommu_opts list;
76  max_vcpus: int;
77  max_evtchn_port: int;
78  max_grant_frames: int;
79  max_maptrack_frames: int;
80  max_grant_version: int;
81  altp2m_opts: int32;
82  vmtrace_buf_kb: int32;
83  cpupool_id: int32;
84  arch: arch_domainconfig;
85}
86
87type domaininfo = {
88  domid : domid;
89  dying : bool;
90  shutdown : bool;
91  paused : bool;
92  blocked : bool;
93  running : bool;
94  hvm_guest : bool;
95  shutdown_code : int;
96  total_memory_pages : nativeint;
97  max_memory_pages : nativeint;
98  shared_info_frame : int64;
99  cpu_time : int64;
100  nr_online_vcpus : int;
101  max_vcpu_id : int;
102  ssidref : int32;
103  handle : int array;
104  arch_config : arch_domainconfig;
105}
106type sched_control = { weight : int; cap : int; }
107type physinfo_cap_flag =
108  | CAP_HVM
109  | CAP_PV
110  | CAP_DirectIO
111  | CAP_HAP
112  | CAP_Shadow
113  | CAP_IOMMU_HAP_PT_SHARE
114  | CAP_Vmtrace
115  | CAP_Vpmu
116  | CAP_Gnttab_v1
117  | CAP_Gnttab_v2
118
119type arm_physinfo_caps =
120  {
121    sve_vl: int;
122  }
123
124type x86_physinfo_cap_flag
125
126type arch_physinfo_cap_flags =
127  | ARM of arm_physinfo_caps
128  | X86 of x86_physinfo_cap_flag list
129
130type physinfo = {
131  threads_per_core : int;
132  cores_per_socket : int;
133  nr_cpus          : int;
134  max_node_id      : int;
135  cpu_khz          : int;
136  total_pages      : nativeint;
137  free_pages       : nativeint;
138  scrub_pages      : nativeint;
139  capabilities     : physinfo_cap_flag list;
140  max_nr_cpus      : int; (** compile-time max possible number of nr_cpus *)
141  arch_capabilities : arch_physinfo_cap_flags;
142}
143type version = { major : int; minor : int; extra : string; }
144type compile_info = {
145  compiler : string;
146  compile_by : string;
147  compile_domain : string;
148  compile_date : string;
149}
150type shutdown_reason = Poweroff | Reboot | Suspend | Crash | Watchdog | Soft_reset
151
152exception Error of string
153type handle
154external interface_open : unit -> handle = "stub_xc_interface_open"
155
156(** [with_intf f] runs [f] with a global handle that is opened on demand
157 * and kept open. Conceptually, a client should use either
158 * interface_open and interface_close or with_intf although mixing both
159 * is possible *)
160val with_intf : (handle -> 'a) -> 'a
161
162(** [get_handle] returns the global handle used by [with_intf] *)
163val get_handle: unit -> handle option
164
165(** [close handle] closes the handle maintained by [with_intf]. This
166 * should only be closed before process exit. It must not be called from
167 * a function called directly or indirectly by with_intf as this
168 * would invalidate the handle that with_intf passes to its argument. *)
169val close_handle: unit -> unit
170
171val domain_create: handle -> ?domid:int -> domctl_create_config -> domid
172
173external domain_sethandle : handle -> domid -> string -> unit = "stub_xc_domain_sethandle"
174external domain_max_vcpus : handle -> domid -> int -> unit
175  = "stub_xc_domain_max_vcpus"
176external domain_pause : handle -> domid -> unit = "stub_xc_domain_pause"
177external domain_unpause : handle -> domid -> unit = "stub_xc_domain_unpause"
178external domain_resume_fast : handle -> domid -> unit
179  = "stub_xc_domain_resume_fast"
180external domain_destroy : handle -> domid -> unit = "stub_xc_domain_destroy"
181external domain_shutdown : handle -> domid -> shutdown_reason -> unit
182  = "stub_xc_domain_shutdown"
183external _domain_getinfolist : handle -> domid -> int -> domaininfo list
184  = "stub_xc_domain_getinfolist"
185val domain_getinfolist : handle -> domid -> domaininfo list
186external domain_getinfo : handle -> domid -> domaininfo
187  = "stub_xc_domain_getinfo"
188external domain_get_vcpuinfo : handle -> int -> int -> vcpuinfo
189  = "stub_xc_vcpu_getinfo"
190external domain_ioport_permission: handle -> domid -> int -> int -> bool -> unit
191  = "stub_xc_domain_ioport_permission"
192external domain_iomem_permission: handle -> domid -> nativeint -> nativeint -> bool -> unit
193  = "stub_xc_domain_iomem_permission"
194external domain_irq_permission: handle -> domid -> int -> bool -> unit
195  = "stub_xc_domain_irq_permission"
196external vcpu_affinity_set : handle -> domid -> int -> bool array -> unit
197  = "stub_xc_vcpu_setaffinity"
198external vcpu_affinity_get : handle -> domid -> int -> bool array
199  = "stub_xc_vcpu_getaffinity"
200external vcpu_context_get : handle -> domid -> int -> string
201  = "stub_xc_vcpu_context_get"
202external sched_id : handle -> int = "stub_xc_sched_id"
203external sched_credit_domain_set : handle -> domid -> sched_control -> unit
204  = "stub_sched_credit_domain_set"
205external sched_credit_domain_get : handle -> domid -> sched_control
206  = "stub_sched_credit_domain_get"
207external shadow_allocation_set : handle -> domid -> int -> unit
208  = "stub_shadow_allocation_set"
209external shadow_allocation_get : handle -> domid -> int
210  = "stub_shadow_allocation_get"
211external evtchn_alloc_unbound : handle -> domid -> domid -> int
212  = "stub_xc_evtchn_alloc_unbound"
213external evtchn_reset : handle -> domid -> unit = "stub_xc_evtchn_reset"
214
215type evtchn_interdomain = { dom: domid; port: int }
216
217type evtchn_stat =
218  | EVTCHNSTAT_unbound of domid
219  | EVTCHNSTAT_interdomain of evtchn_interdomain
220  | EVTCHNSTAT_pirq of int
221  | EVTCHNSTAT_virq of Xeneventchn.virq_t
222  | EVTCHNSTAT_ipi
223
224type evtchn_status = { vcpu: int; status: evtchn_stat }
225
226external evtchn_status: handle -> domid -> int -> evtchn_status option =
227  "stub_xc_evtchn_status"
228
229external readconsolering : handle -> string = "stub_xc_readconsolering"
230external send_debug_keys : handle -> string -> unit = "stub_xc_send_debug_keys"
231external physinfo : handle -> physinfo = "stub_xc_physinfo"
232external pcpu_info: handle -> int -> int64 array = "stub_xc_pcpu_info"
233external domain_setmaxmem : handle -> domid -> int64 -> unit
234  = "stub_xc_domain_setmaxmem"
235external domain_set_memmap_limit : handle -> domid -> int64 -> unit
236  = "stub_xc_domain_set_memmap_limit"
237external domain_memory_increase_reservation :
238  handle -> domid -> int64 -> unit
239  = "stub_xc_domain_memory_increase_reservation"
240external map_foreign_range :
241  handle -> domid -> int -> nativeint -> Xenmmap.mmap_interface
242  = "stub_map_foreign_range"
243
244(* needs to be sorted according to its numeric value, watch out for gaps! *)
245type hvm_param =
246  | HVM_PARAM_CALLBACK_IRQ
247  | HVM_PARAM_STORE_PFN
248  | HVM_PARAM_STORE_EVTCHN
249  | HVM_PARAM_UNDEF_3
250  | HVM_PARAM_PAE_ENABLED
251  | HVM_PARAM_IOREQ_PFN
252  | HVM_PARAM_BUFIOREQ_PFN
253  | HVM_PARAM_UNDEF_7
254  | HVM_PARAM_UNDEF_8
255  | HVM_PARAM_VIRIDIAN
256  | HVM_PARAM_TIMER_MODE
257  | HVM_PARAM_HPET_ENABLED
258  | HVM_PARAM_IDENT_PT
259  | HVM_PARAM_UNDEF_13
260  | HVM_PARAM_ACPI_S_STATE
261  | HVM_PARAM_VM86_TSS
262  | HVM_PARAM_VPT_ALIGN
263  | HVM_PARAM_CONSOLE_PFN
264  | HVM_PARAM_CONSOLE_EVTCHN
265  | HVM_PARAM_ACPI_IOPORTS_LOCATION
266  | HVM_PARAM_MEMORY_EVENT_CR0
267  | HVM_PARAM_MEMORY_EVENT_CR3
268  | HVM_PARAM_MEMORY_EVENT_CR4
269  | HVM_PARAM_MEMORY_EVENT_INT3
270  | HVM_PARAM_NESTEDHVM
271  | HVM_PARAM_MEMORY_EVENT_SINGLE_STEP
272  | HVM_PARAM_UNDEF_26
273  | HVM_PARAM_PAGING_RING_PFN
274  | HVM_PARAM_MONITOR_RING_PFN
275  | HVM_PARAM_SHARING_RING_PFN
276  | HVM_PARAM_MEMORY_EVENT_MSR
277  | HVM_PARAM_TRIPLE_FAULT_REASON
278  | HVM_PARAM_IOREQ_SERVER_PFN
279  | HVM_PARAM_NR_IOREQ_SERVER_PAGES
280  | HVM_PARAM_VM_GENERATION_ID_ADDR
281  | HVM_PARAM_ALTP2M
282  | HVM_PARAM_X87_FIP_WIDTH
283  | HVM_PARAM_VM86_TSS_SIZED
284  | HVM_PARAM_MCA_CAP
285
286external hvm_param_get: handle -> domid -> hvm_param -> int64
287  = "stub_xc_hvm_param_get"
288
289external hvm_param_set: handle -> domid -> hvm_param -> int64 -> unit
290  = "stub_xc_hvm_param_set"
291
292external domain_assign_device: handle -> domid -> (int * int * int * int) -> unit
293  = "stub_xc_domain_assign_device"
294external domain_deassign_device: handle -> domid -> (int * int * int * int) -> unit
295  = "stub_xc_domain_deassign_device"
296external domain_test_assign_device: handle -> domid -> (int * int * int * int) -> bool
297  = "stub_xc_domain_test_assign_device"
298
299external version : handle -> version = "stub_xc_version_version"
300external version_compile_info : handle -> compile_info
301  = "stub_xc_version_compile_info"
302external version_changeset : handle -> string = "stub_xc_version_changeset"
303external version_capabilities : handle -> string
304  = "stub_xc_version_capabilities"
305
306type featureset_index =
307  | Featureset_raw
308  | Featureset_host
309  | Featureset_pv
310  | Featureset_hvm
311  | Featureset_pv_max
312  | Featureset_hvm_max
313external get_cpu_featureset : handle -> featureset_index -> int64 array = "stub_xc_get_cpu_featureset"
314
315external pages_to_kib : int64 -> int64 = "stub_pages_to_kib"
316val pages_to_mib : int64 -> int64
317external watchdog : handle -> int -> int32 -> int
318  = "stub_xc_watchdog"
319