direct-io.hg

view tools/libxc/xenctrl.h @ 7379:d48bc069122c

In addition to setting opaque handle during domain
creation, allow it to be changed after creation via
DOM0_SETDOMAINHANDLE operation (and libxc
xc_domain_sethandle, and via Pyhton wrapper fn).

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri Oct 14 16:01:11 2005 +0100 (2005-10-14)
parents bd3268de4145
children fa0faada967b
line source
1 /******************************************************************************
2 * xenctrl.h
3 *
4 * A library for low-level access to the Xen control interfaces.
5 *
6 * Copyright (c) 2003-2004, K A Fraser.
7 */
9 #ifndef XENCTRL_H
10 #define XENCTRL_H
12 #include <stdint.h>
13 #include <sys/ptrace.h>
14 #include <xen/xen.h>
15 #include <xen/dom0_ops.h>
16 #include <xen/version.h>
17 #include <xen/event_channel.h>
18 #include <xen/sched.h>
19 #include <xen/sched_ctl.h>
20 #include <xen/acm.h>
22 #ifdef __ia64__
23 #define XC_PAGE_SHIFT 14
24 #else
25 #define XC_PAGE_SHIFT 12
26 #endif
27 #define XC_PAGE_SIZE (1UL << XC_PAGE_SHIFT)
28 #define XC_PAGE_MASK (~(XC_PAGE_SIZE-1))
30 /*
31 * DEFINITIONS FOR CPU BARRIERS
32 */
34 #if defined(__i386__)
35 #define mb() __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : : "memory" )
36 #define rmb() __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : : "memory" )
37 #define wmb() __asm__ __volatile__ ( "" : : : "memory")
38 #elif defined(__x86_64__)
39 #define mb() __asm__ __volatile__ ( "mfence" : : : "memory")
40 #define rmb() __asm__ __volatile__ ( "lfence" : : : "memory")
41 #define wmb() __asm__ __volatile__ ( "" : : : "memory")
42 #elif defined(__ia64__)
43 /* FIXME */
44 #define mb()
45 #define rmb()
46 #define wmb()
47 #else
48 #error "Define barriers"
49 #endif
51 /*
52 * INITIALIZATION FUNCTIONS
53 */
55 /**
56 * This function opens a handle to the hypervisor interface. This function can
57 * be called multiple times within a single process. Multiple processes can
58 * have an open hypervisor interface at the same time.
59 *
60 * Each call to this function should have a corresponding call to
61 * xc_interface_close().
62 *
63 * This function can fail if the caller does not have superuser permission or
64 * if a Xen-enabled kernel is not currently running.
65 *
66 * @return a handle to the hypervisor interface or -1 on failure
67 */
68 int xc_interface_open(void);
70 /**
71 * This function closes an open hypervisor interface.
72 *
73 * This function can fail if the handle does not represent an open interface or
74 * if there were problems closing the interface.
75 *
76 * @parm xc_handle a handle to an open hypervisor interface
77 * @return 0 on success, -1 otherwise.
78 */
79 int xc_interface_close(int xc_handle);
81 /*
82 * DOMAIN DEBUGGING FUNCTIONS
83 */
85 typedef struct xc_core_header {
86 unsigned int xch_magic;
87 unsigned int xch_nr_vcpus;
88 unsigned int xch_nr_pages;
89 unsigned int xch_ctxt_offset;
90 unsigned int xch_index_offset;
91 unsigned int xch_pages_offset;
92 } xc_core_header_t;
95 long xc_ptrace(
96 int xc_handle,
97 enum __ptrace_request request,
98 uint32_t domid,
99 long addr,
100 long data);
102 long xc_ptrace_core(
103 int xc_handle,
104 enum __ptrace_request request,
105 uint32_t domid,
106 long addr,
107 long data);
109 int xc_waitdomain(
110 int xc_handle,
111 int domain,
112 int *status,
113 int options);
115 int xc_waitdomain_core(
116 int xc_handle,
117 int domain,
118 int *status,
119 int options);
121 /*
122 * DOMAIN MANAGEMENT FUNCTIONS
123 */
125 typedef struct {
126 uint32_t domid;
127 uint32_t ssidref;
128 unsigned int dying:1, crashed:1, shutdown:1,
129 paused:1, blocked:1, running:1;
130 unsigned int shutdown_reason; /* only meaningful if shutdown==1 */
131 unsigned long nr_pages;
132 unsigned long shared_info_frame;
133 uint64_t cpu_time;
134 unsigned long max_memkb;
135 unsigned int vcpus;
136 xen_domain_handle_t handle;
137 } xc_dominfo_t;
139 typedef dom0_getdomaininfo_t xc_domaininfo_t;
140 int xc_domain_create(int xc_handle,
141 uint32_t ssidref,
142 xen_domain_handle_t handle,
143 uint32_t *pdomid);
146 int xc_domain_dumpcore(int xc_handle,
147 uint32_t domid,
148 const char *corename);
150 /*
151 * This function sets the maximum number vcpus that a domian may create.
152 *
153 * @parm xc_handle a handle to an open hypervisor interface.
154 * @parm domid the domain id in which vcpus are to be created.
155 * @parm max the maximum number of vcpus that the domain may create.
156 * @return 0 on success, -1 on failure.
157 */
158 int xc_domain_max_vcpus(int xc_handle,
159 uint32_t domid,
160 unsigned int max);
162 /**
163 * This function pauses a domain. A paused domain still exists in memory
164 * however it does not receive any timeslices from the hypervisor.
165 *
166 * @parm xc_handle a handle to an open hypervisor interface
167 * @parm domid the domain id to pause
168 * @return 0 on success, -1 on failure.
169 */
170 int xc_domain_pause(int xc_handle,
171 uint32_t domid);
172 /**
173 * This function unpauses a domain. The domain should have been previously
174 * paused.
175 *
176 * @parm xc_handle a handle to an open hypervisor interface
177 * @parm domid the domain id to unpause
178 * return 0 on success, -1 on failure
179 */
180 int xc_domain_unpause(int xc_handle,
181 uint32_t domid);
183 /**
184 * This function will destroy a domain. Destroying a domain removes the domain
185 * completely from memory. This function should be called after sending the
186 * domain a SHUTDOWN control message to free up the domain resources.
187 *
188 * @parm xc_handle a handle to an open hypervisor interface
189 * @parm domid the domain id to destroy
190 * @return 0 on success, -1 on failure
191 */
192 int xc_domain_destroy(int xc_handle,
193 uint32_t domid);
194 int xc_domain_pincpu(int xc_handle,
195 uint32_t domid,
196 int vcpu,
197 cpumap_t cpumap);
199 /**
200 * This function will return information about one or more domains. It is
201 * designed to iterate over the list of domains. If a single domain is
202 * requested, this function will return the next domain in the list - if
203 * one exists. It is, therefore, important in this case to make sure the
204 * domain requested was the one returned.
205 *
206 * @parm xc_handle a handle to an open hypervisor interface
207 * @parm first_domid the first domain to enumerate information from. Domains
208 * are currently enumerate in order of creation.
209 * @parm max_doms the number of elements in info
210 * @parm info an array of max_doms size that will contain the information for
211 * the enumerated domains.
212 * @return the number of domains enumerated or -1 on error
213 */
214 int xc_domain_getinfo(int xc_handle,
215 uint32_t first_domid,
216 unsigned int max_doms,
217 xc_dominfo_t *info);
219 /**
220 * This function will return information about one or more domains, using a
221 * single hypercall. The domain information will be stored into the supplied
222 * array of xc_domaininfo_t structures.
223 *
224 * @parm xc_handle a handle to an open hypervisor interface
225 * @parm first_domain the first domain to enumerate information from.
226 * Domains are currently enumerate in order of creation.
227 * @parm max_domains the number of elements in info
228 * @parm info an array of max_doms size that will contain the information for
229 * the enumerated domains.
230 * @return the number of domains enumerated or -1 on error
231 */
232 int xc_domain_getinfolist(int xc_handle,
233 uint32_t first_domain,
234 unsigned int max_domains,
235 xc_domaininfo_t *info);
237 /**
238 * This function returns information about one domain. This information is
239 * more detailed than the information from xc_domain_getinfo().
240 *
241 * @parm xc_handle a handle to an open hypervisor interface
242 * @parm domid the domain to get information from
243 * @parm info a pointer to an xc_domaininfo_t to store the domain information
244 * @parm ctxt a pointer to a structure to store the execution context of the
245 * domain
246 * @return 0 on success, -1 on failure
247 */
248 int xc_domain_get_vcpu_context(int xc_handle,
249 uint32_t domid,
250 uint32_t vcpu,
251 vcpu_guest_context_t *ctxt);
253 int xc_domain_setcpuweight(int xc_handle,
254 uint32_t domid,
255 float weight);
256 long long xc_domain_get_cpu_usage(int xc_handle,
257 domid_t domid,
258 int vcpu);
260 int xc_domain_sethandle(int xc_handle, uint32_t domid,
261 xen_domain_handle_t handle);
263 typedef dom0_shadow_control_stats_t xc_shadow_control_stats_t;
264 int xc_shadow_control(int xc_handle,
265 uint32_t domid,
266 unsigned int sop,
267 unsigned long *dirty_bitmap,
268 unsigned long pages,
269 xc_shadow_control_stats_t *stats);
271 int xc_bvtsched_global_set(int xc_handle,
272 unsigned long ctx_allow);
274 int xc_bvtsched_domain_set(int xc_handle,
275 uint32_t domid,
276 uint32_t mcuadv,
277 int warpback,
278 int32_t warpvalue,
279 long long warpl,
280 long long warpu);
282 int xc_bvtsched_global_get(int xc_handle,
283 unsigned long *ctx_allow);
285 int xc_bvtsched_domain_get(int xc_handle,
286 uint32_t domid,
287 uint32_t *mcuadv,
288 int *warpback,
289 int32_t *warpvalue,
290 long long *warpl,
291 long long *warpu);
293 int xc_sedf_domain_set(int xc_handle,
294 uint32_t domid,
295 uint64_t period, uint64_t slice,
296 uint64_t latency, uint16_t extratime,
297 uint16_t weight);
299 int xc_sedf_domain_get(int xc_handle,
300 uint32_t domid,
301 uint64_t* period, uint64_t *slice,
302 uint64_t *latency, uint16_t *extratime,
303 uint16_t *weight);
305 typedef evtchn_status_t xc_evtchn_status_t;
307 /*
308 * EVENT CHANNEL FUNCTIONS
309 */
311 /**
312 * This function allocates an unbound port. Ports are named endpoints used for
313 * interdomain communication. This function is most useful in opening a
314 * well-known port within a domain to receive events on.
315 *
316 * @parm xc_handle a handle to an open hypervisor interface
317 * @parm dom the ID of the local domain (the 'allocatee')
318 * @parm remote_dom the ID of the domain who will later bind
319 * @return allocated port (in @dom) on success, -1 on failure
320 */
321 int xc_evtchn_alloc_unbound(int xc_handle,
322 uint32_t dom,
323 uint32_t remote_dom);
325 int xc_evtchn_status(int xc_handle,
326 uint32_t dom, /* may be DOMID_SELF */
327 int port,
328 xc_evtchn_status_t *status);
330 int xc_physdev_pci_access_modify(int xc_handle,
331 uint32_t domid,
332 int bus,
333 int dev,
334 int func,
335 int enable);
337 int xc_readconsolering(int xc_handle,
338 char **pbuffer,
339 unsigned int *pnr_chars,
340 int clear);
342 typedef dom0_physinfo_t xc_physinfo_t;
343 int xc_physinfo(int xc_handle,
344 xc_physinfo_t *info);
346 int xc_sched_id(int xc_handle,
347 int *sched_id);
349 int xc_domain_setmaxmem(int xc_handle,
350 uint32_t domid,
351 unsigned int max_memkb);
353 int xc_domain_memory_increase_reservation(int xc_handle,
354 uint32_t domid,
355 unsigned long nr_extents,
356 unsigned int extent_order,
357 unsigned int address_bits,
358 unsigned long *extent_start);
360 int xc_domain_memory_decrease_reservation(int xc_handle,
361 uint32_t domid,
362 unsigned long nr_extents,
363 unsigned int extent_order,
364 unsigned long *extent_start);
366 unsigned long xc_make_page_below_4G(int xc_handle, uint32_t domid,
367 unsigned long mfn);
369 typedef dom0_perfc_desc_t xc_perfc_desc_t;
370 /* IMPORTANT: The caller is responsible for mlock()'ing the @desc array. */
371 int xc_perfc_control(int xc_handle,
372 uint32_t op,
373 xc_perfc_desc_t *desc);
375 /* read/write msr */
376 long long xc_msr_read(int xc_handle, int cpu_mask, int msr);
377 int xc_msr_write(int xc_handle, int cpu_mask, int msr, unsigned int low,
378 unsigned int high);
380 /**
381 * Memory maps a range within one domain to a local address range. Mappings
382 * should be unmapped with munmap and should follow the same rules as mmap
383 * regarding page alignment. Returns NULL on failure.
384 *
385 * In Linux, the ring queue for the control channel is accessible by mapping
386 * the shared_info_frame (from xc_domain_getinfo()) + 2048. The structure
387 * stored there is of type control_if_t.
388 *
389 * @parm xc_handle a handle on an open hypervisor interface
390 * @parm dom the domain to map memory from
391 * @parm size the amount of memory to map (in multiples of page size)
392 * @parm prot same flag as in mmap().
393 * @parm mfn the frame address to map.
394 */
395 void *xc_map_foreign_range(int xc_handle, uint32_t dom,
396 int size, int prot,
397 unsigned long mfn );
399 void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
400 unsigned long *arr, int num );
402 int xc_get_pfn_list(int xc_handle, uint32_t domid, unsigned long *pfn_buf,
403 unsigned long max_pfns);
405 int xc_ia64_get_pfn_list(int xc_handle, uint32_t domid,
406 unsigned long *pfn_buf,
407 unsigned int start_page, unsigned int nr_pages);
409 long xc_get_max_pages(int xc_handle, uint32_t domid);
411 int xc_mmuext_op(int xc_handle, struct mmuext_op *op, unsigned int nr_ops,
412 domid_t dom);
414 int xc_memory_op(int xc_handle, int cmd, void *arg);
416 int xc_get_pfn_type_batch(int xc_handle, uint32_t dom,
417 int num, unsigned long *arr);
420 /*\
421 * GRANT TABLE FUNCTIONS
422 \*/
424 /**
425 * This function opens a handle to the more restricted grant table hypervisor
426 * interface. This may be used where the standard interface is not
427 * available because the domain is not privileged.
428 * This function can be called multiple times within a single process.
429 * Multiple processes can have an open hypervisor interface at the same time.
430 *
431 * Each call to this function should have a corresponding call to
432 * xc_grant_interface_close().
433 *
434 * This function can fail if a Xen-enabled kernel is not currently running.
435 *
436 * @return a handle to the hypervisor grant table interface or -1 on failure
437 */
438 int xc_grant_interface_open(void);
440 /**
441 * This function closes an open grant table hypervisor interface.
442 *
443 * This function can fail if the handle does not represent an open interface or
444 * if there were problems closing the interface.
445 *
446 * @parm xc_handle a handle to an open grant table hypervisor interface
447 * @return 0 on success, -1 otherwise.
448 */
449 int xc_grant_interface_close(int xc_handle);
451 int xc_gnttab_map_grant_ref(int xc_handle,
452 uint64_t host_virt_addr,
453 uint32_t dom,
454 uint16_t ref,
455 uint16_t flags,
456 int16_t *handle,
457 uint64_t *dev_bus_addr);
459 int xc_gnttab_unmap_grant_ref(int xc_handle,
460 uint64_t host_virt_addr,
461 uint64_t dev_bus_addr,
462 uint16_t handle,
463 int16_t *status);
465 int xc_gnttab_setup_table(int xc_handle,
466 uint32_t dom,
467 uint16_t nr_frames,
468 int16_t *status,
469 unsigned long **frame_list);
471 /* Grant debug builds only: */
472 int xc_gnttab_dump_table(int xc_handle,
473 uint32_t dom,
474 int16_t *status);
476 /* Get current total pages allocated to a domain. */
477 long xc_get_tot_pages(int xc_handle, uint32_t domid);
479 /* Execute a privileged dom0 operation. */
480 int xc_dom0_op(int xc_handle, dom0_op_t *op);
482 int xc_version(int xc_handle, int cmd, void *arg);
484 /* Initializes the store (for dom0)
485 remote_port should be the remote end of a bound interdomain channel between
486 the store and dom0.
488 This function returns a shared frame that should be passed to
489 xs_introduce_domain
490 */
491 long xc_init_store(int xc_handle, int remote_port);
493 /*
494 * MMU updates.
495 */
496 #define MAX_MMU_UPDATES 1024
497 struct xc_mmu {
498 mmu_update_t updates[MAX_MMU_UPDATES];
499 int idx;
500 domid_t subject;
501 };
502 typedef struct xc_mmu xc_mmu_t;
503 xc_mmu_t *xc_init_mmu_updates(int xc_handle, domid_t dom);
504 int xc_add_mmu_update(int xc_handle, xc_mmu_t *mmu,
505 unsigned long long ptr, unsigned long long val);
506 int xc_finish_mmu_updates(int xc_handle, xc_mmu_t *mmu);
508 #endif