ia64/xen-unstable

view tools/libxc/xenctrl.h @ 7238:971e7c7411b3

Raise an exception if an error appears on the pipes to our children, and make
sure that the child's pipes are closed even under that exception. Move the
handling of POLLHUP to the end of the loop, so that we guarantee to read any
remaining data from the child if POLLHUP and POLLIN appear at the same time.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Thu Oct 06 10:13:11 2005 +0100 (2005-10-06)
parents 540d17fe32ce
children c3d9b7013b14
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>
14 typedef uint8_t u8;
15 typedef uint16_t u16;
16 typedef uint32_t u32;
17 typedef uint64_t u64;
18 typedef int8_t s8;
19 typedef int16_t s16;
20 typedef int32_t s32;
21 typedef int64_t s64;
23 #include <sys/ptrace.h>
24 #include <xen/xen.h>
25 #include <xen/dom0_ops.h>
26 #include <xen/version.h>
27 #include <xen/event_channel.h>
28 #include <xen/sched.h>
29 #include <xen/sched_ctl.h>
30 #include <xen/acm.h>
32 #ifdef __ia64__
33 #define XC_PAGE_SHIFT 14
34 #else
35 #define XC_PAGE_SHIFT 12
36 #endif
37 #define XC_PAGE_SIZE (1UL << XC_PAGE_SHIFT)
38 #define XC_PAGE_MASK (~(XC_PAGE_SIZE-1))
40 /*
41 * DEFINITIONS FOR CPU BARRIERS
42 */
44 #if defined(__i386__)
45 #define mb() __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : : "memory" )
46 #define rmb() __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : : "memory" )
47 #define wmb() __asm__ __volatile__ ( "" : : : "memory")
48 #elif defined(__x86_64__)
49 #define mb() __asm__ __volatile__ ( "mfence" : : : "memory")
50 #define rmb() __asm__ __volatile__ ( "lfence" : : : "memory")
51 #define wmb() __asm__ __volatile__ ( "" : : : "memory")
52 #elif defined(__ia64__)
53 /* FIXME */
54 #define mb()
55 #define rmb()
56 #define wmb()
57 #else
58 #error "Define barriers"
59 #endif
61 /*
62 * INITIALIZATION FUNCTIONS
63 */
65 /**
66 * This function opens a handle to the hypervisor interface. This function can
67 * be called multiple times within a single process. Multiple processes can
68 * have an open hypervisor interface at the same time.
69 *
70 * Each call to this function should have a corresponding call to
71 * xc_interface_close().
72 *
73 * This function can fail if the caller does not have superuser permission or
74 * if a Xen-enabled kernel is not currently running.
75 *
76 * @return a handle to the hypervisor interface or -1 on failure
77 */
78 int xc_interface_open(void);
80 /**
81 * This function closes an open hypervisor interface.
82 *
83 * This function can fail if the handle does not represent an open interface or
84 * if there were problems closing the interface.
85 *
86 * @parm xc_handle a handle to an open hypervisor interface
87 * @return 0 on success, -1 otherwise.
88 */
89 int xc_interface_close(int xc_handle);
91 /*
92 * DOMAIN DEBUGGING FUNCTIONS
93 */
95 typedef struct xc_core_header {
96 unsigned int xch_magic;
97 unsigned int xch_nr_vcpus;
98 unsigned int xch_nr_pages;
99 unsigned int xch_ctxt_offset;
100 unsigned int xch_index_offset;
101 unsigned int xch_pages_offset;
102 } xc_core_header_t;
105 long xc_ptrace(
106 int xc_handle,
107 enum __ptrace_request request,
108 u32 domid,
109 long addr,
110 long data);
112 long xc_ptrace_core(
113 int xc_handle,
114 enum __ptrace_request request,
115 u32 domid,
116 long addr,
117 long data);
119 int xc_waitdomain(
120 int xc_handle,
121 int domain,
122 int *status,
123 int options);
125 int xc_waitdomain_core(
126 int xc_handle,
127 int domain,
128 int *status,
129 int options);
131 /*
132 * DOMAIN MANAGEMENT FUNCTIONS
133 */
135 typedef struct {
136 u32 domid;
137 u32 ssidref;
138 unsigned int dying:1, crashed:1, shutdown:1,
139 paused:1, blocked:1, running:1;
140 unsigned int shutdown_reason; /* only meaningful if shutdown==1 */
141 unsigned long nr_pages;
142 unsigned long shared_info_frame;
143 u64 cpu_time;
144 unsigned long max_memkb;
145 unsigned int vcpus;
146 s32 vcpu_to_cpu[MAX_VIRT_CPUS];
147 cpumap_t cpumap[MAX_VIRT_CPUS];
148 } xc_dominfo_t;
150 typedef dom0_getdomaininfo_t xc_domaininfo_t;
151 int xc_domain_create(int xc_handle,
152 u32 ssidref,
153 u32 *pdomid);
156 int xc_domain_dumpcore(int xc_handle,
157 u32 domid,
158 const char *corename);
161 /**
162 * This function pauses a domain. A paused domain still exists in memory
163 * however it does not receive any timeslices from the hypervisor.
164 *
165 * @parm xc_handle a handle to an open hypervisor interface
166 * @parm domid the domain id to pause
167 * @return 0 on success, -1 on failure.
168 */
169 int xc_domain_pause(int xc_handle,
170 u32 domid);
171 /**
172 * This function unpauses a domain. The domain should have been previously
173 * paused.
174 *
175 * @parm xc_handle a handle to an open hypervisor interface
176 * @parm domid the domain id to unpause
177 * return 0 on success, -1 on failure
178 */
179 int xc_domain_unpause(int xc_handle,
180 u32 domid);
182 /**
183 * This function will destroy a domain. Destroying a domain removes the domain
184 * completely from memory. This function should be called after sending the
185 * domain a SHUTDOWN control message to free up the domain resources.
186 *
187 * @parm xc_handle a handle to an open hypervisor interface
188 * @parm domid the domain id to destroy
189 * @return 0 on success, -1 on failure
190 */
191 int xc_domain_destroy(int xc_handle,
192 u32 domid);
193 int xc_domain_pincpu(int xc_handle,
194 u32 domid,
195 int vcpu,
196 cpumap_t *cpumap);
197 /**
198 * This function will return information about one or more domains. It is
199 * designed to iterate over the list of domains. If a single domain is
200 * requested, this function will return the next domain in the list - if
201 * one exists. It is, therefore, important in this case to make sure the
202 * domain requested was the one returned.
203 *
204 * @parm xc_handle a handle to an open hypervisor interface
205 * @parm first_domid the first domain to enumerate information from. Domains
206 * are currently enumerate in order of creation.
207 * @parm max_doms the number of elements in info
208 * @parm info an array of max_doms size that will contain the information for
209 * the enumerated domains.
210 * @return the number of domains enumerated or -1 on error
211 */
212 int xc_domain_getinfo(int xc_handle,
213 u32 first_domid,
214 unsigned int max_doms,
215 xc_dominfo_t *info);
217 /**
218 * This function will return information about one or more domains, using a
219 * single hypercall. The domain information will be stored into the supplied
220 * array of xc_domaininfo_t structures.
221 *
222 * @parm xc_handle a handle to an open hypervisor interface
223 * @parm first_domain the first domain to enumerate information from.
224 * Domains are currently enumerate in order of creation.
225 * @parm max_domains the number of elements in info
226 * @parm info an array of max_doms size that will contain the information for
227 * the enumerated domains.
228 * @return the number of domains enumerated or -1 on error
229 */
230 int xc_domain_getinfolist(int xc_handle,
231 u32 first_domain,
232 unsigned int max_domains,
233 xc_domaininfo_t *info);
235 /**
236 * This function returns information about one domain. This information is
237 * more detailed than the information from xc_domain_getinfo().
238 *
239 * @parm xc_handle a handle to an open hypervisor interface
240 * @parm domid the domain to get information from
241 * @parm info a pointer to an xc_domaininfo_t to store the domain information
242 * @parm ctxt a pointer to a structure to store the execution context of the
243 * domain
244 * @return 0 on success, -1 on failure
245 */
246 int xc_domain_get_vcpu_context(int xc_handle,
247 u32 domid,
248 u32 vcpu,
249 vcpu_guest_context_t *ctxt);
251 int xc_domain_setcpuweight(int xc_handle,
252 u32 domid,
253 float weight);
254 long long xc_domain_get_cpu_usage(int xc_handle,
255 domid_t domid,
256 int vcpu);
259 typedef dom0_shadow_control_stats_t xc_shadow_control_stats_t;
260 int xc_shadow_control(int xc_handle,
261 u32 domid,
262 unsigned int sop,
263 unsigned long *dirty_bitmap,
264 unsigned long pages,
265 xc_shadow_control_stats_t *stats);
267 int xc_bvtsched_global_set(int xc_handle,
268 unsigned long ctx_allow);
270 int xc_bvtsched_domain_set(int xc_handle,
271 u32 domid,
272 u32 mcuadv,
273 int warpback,
274 s32 warpvalue,
275 long long warpl,
276 long long warpu);
278 int xc_bvtsched_global_get(int xc_handle,
279 unsigned long *ctx_allow);
281 int xc_bvtsched_domain_get(int xc_handle,
282 u32 domid,
283 u32 *mcuadv,
284 int *warpback,
285 s32 *warpvalue,
286 long long *warpl,
287 long long *warpu);
289 int xc_sedf_domain_set(int xc_handle,
290 u32 domid,
291 u64 period, u64 slice, u64 latency, u16 extratime, u16 weight);
293 int xc_sedf_domain_get(int xc_handle,
294 u32 domid,
295 u64* period, u64 *slice, u64 *latency, u16 *extratime, u16* weight);
297 typedef evtchn_status_t xc_evtchn_status_t;
299 /*
300 * EVENT CHANNEL FUNCTIONS
301 */
303 /**
304 * This function allocates an unbound port. Ports are named endpoints used for
305 * interdomain communication. This function is most useful in opening a
306 * well-known port within a domain to receive events on.
307 *
308 * @parm xc_handle a handle to an open hypervisor interface
309 * @parm dom the ID of the domain. This maybe DOMID_SELF
310 * @parm port a pointer to a port. This is an in/out parameter. If *port is
311 * 0, then a new port will be assigned, if port is > 0 then that
312 * port is allocated if the port is unallocated.
313 * @return 0 on success, -1 on failure
314 */
315 int xc_evtchn_alloc_unbound(int xc_handle,
316 u32 dom,
317 int *port);
319 /**
320 * This function creates a pair of ports between two domains. A port can only
321 * be bound once within a domain.
322 *
323 * @parm xc_handle a handle to an open hypervisor interface
324 * @parm dom1 one of the two domains to connect. Can be DOMID_SELF.
325 * @parm dom2 the other domain to connect. Can be DOMID_SELF.
326 * @parm port1 an in/out parameter. If > 0, then try to connect *port. If
327 * 0, then allocate a new port and store the port in *port.
328 * @parm port2 the port connected on port2. This parameter behaves the same
329 * way as port1.
330 * @return 0 on success, -1 on error.
331 */
332 int xc_evtchn_bind_interdomain(int xc_handle,
333 u32 dom1,
334 u32 dom2,
335 int *port1,
336 int *port2);
337 int xc_evtchn_bind_virq(int xc_handle,
338 int virq,
339 int *port);
341 /**
342 * This function will close a single port on an event channel.
343 *
344 * @parm xc_handle a handle to an open hypervisor interface
345 * @parm dom the domain that the port exists on. May be DOMID_SELF.
346 * @parm port the port to close
347 * @return 0 on success, -1 on error
348 */
349 int xc_evtchn_close(int xc_handle,
350 u32 dom, /* may be DOMID_SELF */
351 int port);
353 /**
354 * This function generates a notify event on a bound port.
355 *
356 * Notifies can be read within Linux by opening /dev/xen/evtchn and reading
357 * a 16 bit value. The result will be the port the event occurred on. When
358 * events occur, the port is masked until the 16 bit port value is written back
359 * to the file. When /dev/xen/evtchn is opened, it has to be bound via an
360 * ioctl to each port to listen on. The ioctl for binding is _IO('E', 2). The
361 * parameter is the port to listen on.
362 *
363 * @parm xc_handle a handle to an open hypervisor interface
364 * @parm local_port the port to generate the notify on
365 * @return 0 on success, -1 on error
366 */
367 int xc_evtchn_send(int xc_handle,
368 int local_port);
369 int xc_evtchn_status(int xc_handle,
370 u32 dom, /* may be DOMID_SELF */
371 int port,
372 xc_evtchn_status_t *status);
374 int xc_physdev_pci_access_modify(int xc_handle,
375 u32 domid,
376 int bus,
377 int dev,
378 int func,
379 int enable);
381 int xc_readconsolering(int xc_handle,
382 char **pbuffer,
383 unsigned int *pnr_chars,
384 int clear);
386 typedef dom0_physinfo_t xc_physinfo_t;
387 int xc_physinfo(int xc_handle,
388 xc_physinfo_t *info);
390 int xc_sched_id(int xc_handle,
391 int *sched_id);
393 int xc_domain_setmaxmem(int xc_handle,
394 u32 domid,
395 unsigned int max_memkb);
397 int xc_domain_memory_increase_reservation(int xc_handle,
398 u32 domid,
399 unsigned long nr_extents,
400 unsigned int extent_order,
401 unsigned int address_bits,
402 unsigned long *extent_start);
404 int xc_domain_memory_decrease_reservation(int xc_handle,
405 u32 domid,
406 unsigned long nr_extents,
407 unsigned int extent_order,
408 unsigned long *extent_start);
410 unsigned long xc_make_page_below_4G(int xc_handle, u32 domid,
411 unsigned long mfn);
413 typedef dom0_perfc_desc_t xc_perfc_desc_t;
414 /* IMPORTANT: The caller is responsible for mlock()'ing the @desc array. */
415 int xc_perfc_control(int xc_handle,
416 u32 op,
417 xc_perfc_desc_t *desc);
419 /* read/write msr */
420 long long xc_msr_read(int xc_handle, int cpu_mask, int msr);
421 int xc_msr_write(int xc_handle, int cpu_mask, int msr, unsigned int low,
422 unsigned int high);
424 /**
425 * Memory maps a range within one domain to a local address range. Mappings
426 * should be unmapped with munmap and should follow the same rules as mmap
427 * regarding page alignment. Returns NULL on failure.
428 *
429 * In Linux, the ring queue for the control channel is accessible by mapping
430 * the shared_info_frame (from xc_domain_getinfo()) + 2048. The structure
431 * stored there is of type control_if_t.
432 *
433 * @parm xc_handle a handle on an open hypervisor interface
434 * @parm dom the domain to map memory from
435 * @parm size the amount of memory to map (in multiples of page size)
436 * @parm prot same flag as in mmap().
437 * @parm mfn the frame address to map.
438 */
439 void *xc_map_foreign_range(int xc_handle, u32 dom,
440 int size, int prot,
441 unsigned long mfn );
443 void *xc_map_foreign_batch(int xc_handle, u32 dom, int prot,
444 unsigned long *arr, int num );
446 int xc_get_pfn_list(int xc_handle, u32 domid, unsigned long *pfn_buf,
447 unsigned long max_pfns);
449 int xc_ia64_get_pfn_list(int xc_handle, u32 domid, unsigned long *pfn_buf,
450 unsigned int start_page, unsigned int nr_pages);
452 long xc_get_max_pages(int xc_handle, u32 domid);
454 int xc_mmuext_op(int xc_handle, struct mmuext_op *op, unsigned int nr_ops,
455 domid_t dom);
457 int xc_memory_op(int xc_handle, int cmd, void *arg);
459 int xc_get_pfn_type_batch(int xc_handle, u32 dom, int num, unsigned long *arr);
462 /*\
463 * GRANT TABLE FUNCTIONS
464 \*/
466 /**
467 * This function opens a handle to the more restricted grant table hypervisor
468 * interface. This may be used where the standard interface is not
469 * available because the domain is not privileged.
470 * This function can be called multiple times within a single process.
471 * Multiple processes can have an open hypervisor interface at the same time.
472 *
473 * Each call to this function should have a corresponding call to
474 * xc_grant_interface_close().
475 *
476 * This function can fail if a Xen-enabled kernel is not currently running.
477 *
478 * @return a handle to the hypervisor grant table interface or -1 on failure
479 */
480 int xc_grant_interface_open(void);
482 /**
483 * This function closes an open grant table hypervisor interface.
484 *
485 * This function can fail if the handle does not represent an open interface or
486 * if there were problems closing the interface.
487 *
488 * @parm xc_handle a handle to an open grant table hypervisor interface
489 * @return 0 on success, -1 otherwise.
490 */
491 int xc_grant_interface_close(int xc_handle);
493 int xc_gnttab_map_grant_ref(int xc_handle,
494 u64 host_virt_addr,
495 u32 dom,
496 u16 ref,
497 u16 flags,
498 s16 *handle,
499 u64 *dev_bus_addr);
501 int xc_gnttab_unmap_grant_ref(int xc_handle,
502 u64 host_virt_addr,
503 u64 dev_bus_addr,
504 u16 handle,
505 s16 *status);
507 int xc_gnttab_setup_table(int xc_handle,
508 u32 dom,
509 u16 nr_frames,
510 s16 *status,
511 unsigned long **frame_list);
513 /* Grant debug builds only: */
514 int xc_gnttab_dump_table(int xc_handle,
515 u32 dom,
516 s16 *status);
518 /* Get current total pages allocated to a domain. */
519 long xc_get_tot_pages(int xc_handle, u32 domid);
521 /* Execute a privileged dom0 operation. */
522 int xc_dom0_op(int xc_handle, dom0_op_t *op);
524 int xc_version(int xc_handle, int cmd, void *arg);
526 /* Initializes the store (for dom0)
527 remote_port should be the remote end of a bound interdomain channel between
528 the store and dom0.
530 This function returns a shared frame that should be passed to
531 xs_introduce_domain
532 */
533 long xc_init_store(int xc_handle, int remote_port);
535 /*
536 * MMU updates.
537 */
538 #define MAX_MMU_UPDATES 1024
539 struct xc_mmu {
540 mmu_update_t updates[MAX_MMU_UPDATES];
541 int idx;
542 domid_t subject;
543 };
544 typedef struct xc_mmu xc_mmu_t;
545 xc_mmu_t *xc_init_mmu_updates(int xc_handle, domid_t dom);
546 int xc_add_mmu_update(int xc_handle, xc_mmu_t *mmu,
547 unsigned long long ptr, unsigned long long val);
548 int xc_finish_mmu_updates(int xc_handle, xc_mmu_t *mmu);
550 #endif