direct-io.hg

view tools/libxc/xenctrl.h @ 8151:f5b119533cc8

Define explicit evtchn_port_t type (32 bits) and plumb up
to user space thru /dev/xen/evtchn.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Dec 01 15:22:22 2005 +0100 (2005-12-01)
parents 58d46463413e
children b5b7a9d9fc56
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/grant_table.h>
17 #include <xen/version.h>
18 #include <xen/event_channel.h>
19 #include <xen/sched.h>
20 #include <xen/sched_ctl.h>
21 #include <xen/memory.h>
22 #include <xen/acm.h>
24 #ifdef __ia64__
25 #define XC_PAGE_SHIFT 14
26 #else
27 #define XC_PAGE_SHIFT 12
28 #endif
29 #define XC_PAGE_SIZE (1UL << XC_PAGE_SHIFT)
30 #define XC_PAGE_MASK (~(XC_PAGE_SIZE-1))
32 /*
33 * DEFINITIONS FOR CPU BARRIERS
34 */
36 #if defined(__i386__)
37 #define mb() __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : : "memory" )
38 #define rmb() __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : : "memory" )
39 #define wmb() __asm__ __volatile__ ( "" : : : "memory")
40 #elif defined(__x86_64__)
41 #define mb() __asm__ __volatile__ ( "mfence" : : : "memory")
42 #define rmb() __asm__ __volatile__ ( "lfence" : : : "memory")
43 #define wmb() __asm__ __volatile__ ( "" : : : "memory")
44 #elif defined(__ia64__)
45 /* FIXME */
46 #define mb()
47 #define rmb()
48 #define wmb()
49 #else
50 #error "Define barriers"
51 #endif
53 /*
54 * INITIALIZATION FUNCTIONS
55 */
57 /**
58 * This function opens a handle to the hypervisor interface. This function can
59 * be called multiple times within a single process. Multiple processes can
60 * have an open hypervisor interface at the same time.
61 *
62 * Each call to this function should have a corresponding call to
63 * xc_interface_close().
64 *
65 * This function can fail if the caller does not have superuser permission or
66 * if a Xen-enabled kernel is not currently running.
67 *
68 * @return a handle to the hypervisor interface or -1 on failure
69 */
70 int xc_interface_open(void);
72 /**
73 * This function closes an open hypervisor interface.
74 *
75 * This function can fail if the handle does not represent an open interface or
76 * if there were problems closing the interface.
77 *
78 * @parm xc_handle a handle to an open hypervisor interface
79 * @return 0 on success, -1 otherwise.
80 */
81 int xc_interface_close(int xc_handle);
83 /*
84 * DOMAIN DEBUGGING FUNCTIONS
85 */
87 typedef struct xc_core_header {
88 unsigned int xch_magic;
89 unsigned int xch_nr_vcpus;
90 unsigned int xch_nr_pages;
91 unsigned int xch_ctxt_offset;
92 unsigned int xch_index_offset;
93 unsigned int xch_pages_offset;
94 } xc_core_header_t;
97 long xc_ptrace(
98 int xc_handle,
99 enum __ptrace_request request,
100 uint32_t domid,
101 long addr,
102 long data);
104 long xc_ptrace_core(
105 int xc_handle,
106 enum __ptrace_request request,
107 uint32_t domid,
108 long addr,
109 long data);
111 int xc_waitdomain(
112 int xc_handle,
113 int domain,
114 int *status,
115 int options);
117 int xc_waitdomain_core(
118 int xc_handle,
119 int domain,
120 int *status,
121 int options);
123 /*
124 * DOMAIN MANAGEMENT FUNCTIONS
125 */
127 typedef struct {
128 uint32_t domid;
129 uint32_t ssidref;
130 unsigned int dying:1, crashed:1, shutdown:1,
131 paused:1, blocked:1, running:1;
132 unsigned int shutdown_reason; /* only meaningful if shutdown==1 */
133 unsigned long nr_pages;
134 unsigned long shared_info_frame;
135 uint64_t cpu_time;
136 unsigned long max_memkb;
137 unsigned int nr_online_vcpus;
138 unsigned int max_vcpu_id;
139 xen_domain_handle_t handle;
140 } xc_dominfo_t;
142 typedef dom0_getdomaininfo_t xc_domaininfo_t;
143 int xc_domain_create(int xc_handle,
144 uint32_t ssidref,
145 xen_domain_handle_t handle,
146 uint32_t *pdomid);
149 int xc_domain_dumpcore(int xc_handle,
150 uint32_t domid,
151 const char *corename);
153 /*
154 * This function sets the maximum number of vcpus that a domain may create.
155 *
156 * @parm xc_handle a handle to an open hypervisor interface.
157 * @parm domid the domain id in which vcpus are to be created.
158 * @parm max the maximum number of vcpus that the domain may create.
159 * @return 0 on success, -1 on failure.
160 */
161 int xc_domain_max_vcpus(int xc_handle,
162 uint32_t domid,
163 unsigned int max);
165 /**
166 * This function pauses a domain. A paused domain still exists in memory
167 * however it does not receive any timeslices from the hypervisor.
168 *
169 * @parm xc_handle a handle to an open hypervisor interface
170 * @parm domid the domain id to pause
171 * @return 0 on success, -1 on failure.
172 */
173 int xc_domain_pause(int xc_handle,
174 uint32_t domid);
175 /**
176 * This function unpauses a domain. The domain should have been previously
177 * paused.
178 *
179 * @parm xc_handle a handle to an open hypervisor interface
180 * @parm domid the domain id to unpause
181 * return 0 on success, -1 on failure
182 */
183 int xc_domain_unpause(int xc_handle,
184 uint32_t domid);
186 /**
187 * This function will destroy a domain. Destroying a domain removes the domain
188 * completely from memory. This function should be called after sending the
189 * domain a SHUTDOWN control message to free up the domain resources.
190 *
191 * @parm xc_handle a handle to an open hypervisor interface
192 * @parm domid the domain id to destroy
193 * @return 0 on success, -1 on failure
194 */
195 int xc_domain_destroy(int xc_handle,
196 uint32_t domid);
197 int xc_domain_pincpu(int xc_handle,
198 uint32_t domid,
199 int vcpu,
200 cpumap_t cpumap);
202 /**
203 * This function will return information about one or more domains. It is
204 * designed to iterate over the list of domains. If a single domain is
205 * requested, this function will return the next domain in the list - if
206 * one exists. It is, therefore, important in this case to make sure the
207 * domain requested was the one returned.
208 *
209 * @parm xc_handle a handle to an open hypervisor interface
210 * @parm first_domid the first domain to enumerate information from. Domains
211 * are currently enumerate in order of creation.
212 * @parm max_doms the number of elements in info
213 * @parm info an array of max_doms size that will contain the information for
214 * the enumerated domains.
215 * @return the number of domains enumerated or -1 on error
216 */
217 int xc_domain_getinfo(int xc_handle,
218 uint32_t first_domid,
219 unsigned int max_doms,
220 xc_dominfo_t *info);
222 /**
223 * This function will return information about one or more domains, using a
224 * single hypercall. The domain information will be stored into the supplied
225 * array of xc_domaininfo_t structures.
226 *
227 * @parm xc_handle a handle to an open hypervisor interface
228 * @parm first_domain the first domain to enumerate information from.
229 * Domains are currently enumerate in order of creation.
230 * @parm max_domains the number of elements in info
231 * @parm info an array of max_doms size that will contain the information for
232 * the enumerated domains.
233 * @return the number of domains enumerated or -1 on error
234 */
235 int xc_domain_getinfolist(int xc_handle,
236 uint32_t first_domain,
237 unsigned int max_domains,
238 xc_domaininfo_t *info);
240 /**
241 * This function returns information about the execution context of a
242 * particular vcpu of a domain.
243 *
244 * @parm xc_handle a handle to an open hypervisor interface
245 * @parm domid the domain to get information from
246 * @parm vcpu the vcpu number
247 * @parm ctxt a pointer to a structure to store the execution context of the
248 * domain
249 * @return 0 on success, -1 on failure
250 */
251 int xc_domain_get_vcpu_context(int xc_handle,
252 uint32_t domid,
253 uint32_t vcpu,
254 vcpu_guest_context_t *ctxt);
256 typedef dom0_getvcpuinfo_t xc_vcpuinfo_t;
257 int xc_domain_get_vcpu_info(int xc_handle,
258 uint32_t domid,
259 uint32_t vcpu,
260 xc_vcpuinfo_t *info);
263 int xc_domain_setcpuweight(int xc_handle,
264 uint32_t domid,
265 float weight);
266 long long xc_domain_get_cpu_usage(int xc_handle,
267 domid_t domid,
268 int vcpu);
270 int xc_domain_sethandle(int xc_handle, uint32_t domid,
271 xen_domain_handle_t handle);
273 typedef dom0_shadow_control_stats_t xc_shadow_control_stats_t;
274 int xc_shadow_control(int xc_handle,
275 uint32_t domid,
276 unsigned int sop,
277 unsigned long *dirty_bitmap,
278 unsigned long pages,
279 xc_shadow_control_stats_t *stats);
281 int xc_bvtsched_global_set(int xc_handle,
282 unsigned long ctx_allow);
284 int xc_bvtsched_domain_set(int xc_handle,
285 uint32_t domid,
286 uint32_t mcuadv,
287 int warpback,
288 int32_t warpvalue,
289 long long warpl,
290 long long warpu);
292 int xc_bvtsched_global_get(int xc_handle,
293 unsigned long *ctx_allow);
295 int xc_bvtsched_domain_get(int xc_handle,
296 uint32_t domid,
297 uint32_t *mcuadv,
298 int *warpback,
299 int32_t *warpvalue,
300 long long *warpl,
301 long long *warpu);
303 int xc_sedf_domain_set(int xc_handle,
304 uint32_t domid,
305 uint64_t period, uint64_t slice,
306 uint64_t latency, uint16_t extratime,
307 uint16_t weight);
309 int xc_sedf_domain_get(int xc_handle,
310 uint32_t domid,
311 uint64_t* period, uint64_t *slice,
312 uint64_t *latency, uint16_t *extratime,
313 uint16_t *weight);
315 typedef evtchn_status_t xc_evtchn_status_t;
317 /*
318 * EVENT CHANNEL FUNCTIONS
319 */
321 /**
322 * This function allocates an unbound port. Ports are named endpoints used for
323 * interdomain communication. This function is most useful in opening a
324 * well-known port within a domain to receive events on.
325 *
326 * @parm xc_handle a handle to an open hypervisor interface
327 * @parm dom the ID of the local domain (the 'allocatee')
328 * @parm remote_dom the ID of the domain who will later bind
329 * @return allocated port (in @dom) on success, -1 on failure
330 */
331 int xc_evtchn_alloc_unbound(int xc_handle,
332 uint32_t dom,
333 uint32_t remote_dom);
335 int xc_evtchn_status(int xc_handle,
336 uint32_t dom, /* may be DOMID_SELF */
337 evtchn_port_t port,
338 xc_evtchn_status_t *status);
340 int xc_physdev_pci_access_modify(int xc_handle,
341 uint32_t domid,
342 int bus,
343 int dev,
344 int func,
345 int enable);
347 int xc_readconsolering(int xc_handle,
348 char **pbuffer,
349 unsigned int *pnr_chars,
350 int clear);
352 typedef dom0_physinfo_t xc_physinfo_t;
353 int xc_physinfo(int xc_handle,
354 xc_physinfo_t *info);
356 int xc_sched_id(int xc_handle,
357 int *sched_id);
359 int xc_domain_setmaxmem(int xc_handle,
360 uint32_t domid,
361 unsigned int max_memkb);
363 int xc_domain_memory_increase_reservation(int xc_handle,
364 uint32_t domid,
365 unsigned long nr_extents,
366 unsigned int extent_order,
367 unsigned int address_bits,
368 unsigned long *extent_start);
370 int xc_domain_memory_decrease_reservation(int xc_handle,
371 uint32_t domid,
372 unsigned long nr_extents,
373 unsigned int extent_order,
374 unsigned long *extent_start);
376 int xc_domain_ioport_permission(int xc_handle,
377 uint32_t domid,
378 uint32_t first_port,
379 uint32_t nr_ports,
380 uint32_t allow_access);
382 unsigned long xc_make_page_below_4G(int xc_handle, uint32_t domid,
383 unsigned long mfn);
385 typedef dom0_perfc_desc_t xc_perfc_desc_t;
386 /* IMPORTANT: The caller is responsible for mlock()'ing the @desc array. */
387 int xc_perfc_control(int xc_handle,
388 uint32_t op,
389 xc_perfc_desc_t *desc);
391 /* read/write msr */
392 long long xc_msr_read(int xc_handle, int cpu_mask, int msr);
393 int xc_msr_write(int xc_handle, int cpu_mask, int msr, unsigned int low,
394 unsigned int high);
396 /**
397 * Memory maps a range within one domain to a local address range. Mappings
398 * should be unmapped with munmap and should follow the same rules as mmap
399 * regarding page alignment. Returns NULL on failure.
400 *
401 * In Linux, the ring queue for the control channel is accessible by mapping
402 * the shared_info_frame (from xc_domain_getinfo()) + 2048. The structure
403 * stored there is of type control_if_t.
404 *
405 * @parm xc_handle a handle on an open hypervisor interface
406 * @parm dom the domain to map memory from
407 * @parm size the amount of memory to map (in multiples of page size)
408 * @parm prot same flag as in mmap().
409 * @parm mfn the frame address to map.
410 */
411 void *xc_map_foreign_range(int xc_handle, uint32_t dom,
412 int size, int prot,
413 unsigned long mfn );
415 void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
416 unsigned long *arr, int num );
418 int xc_get_pfn_list(int xc_handle, uint32_t domid, unsigned long *pfn_buf,
419 unsigned long max_pfns);
421 int xc_ia64_get_pfn_list(int xc_handle, uint32_t domid,
422 unsigned long *pfn_buf,
423 unsigned int start_page, unsigned int nr_pages);
425 int xc_copy_to_domain_page(int xc_handle, uint32_t domid,
426 unsigned long dst_pfn, void *src_page);
428 int xc_clear_domain_page(int xc_handle, uint32_t domid,
429 unsigned long dst_pfn);
431 int xc_ia64_copy_to_domain_pages(int xc_handle, uint32_t domid,
432 void* src_page, unsigned long dst_pfn, int nr_pages);
434 long xc_get_max_pages(int xc_handle, uint32_t domid);
436 int xc_mmuext_op(int xc_handle, struct mmuext_op *op, unsigned int nr_ops,
437 domid_t dom);
439 int xc_memory_op(int xc_handle, int cmd, void *arg);
441 int xc_get_pfn_type_batch(int xc_handle, uint32_t dom,
442 int num, unsigned long *arr);
445 /*\
446 * GRANT TABLE FUNCTIONS
447 \*/
449 /**
450 * This function opens a handle to the more restricted grant table hypervisor
451 * interface. This may be used where the standard interface is not
452 * available because the domain is not privileged.
453 * This function can be called multiple times within a single process.
454 * Multiple processes can have an open hypervisor interface at the same time.
455 *
456 * Each call to this function should have a corresponding call to
457 * xc_grant_interface_close().
458 *
459 * This function can fail if a Xen-enabled kernel is not currently running.
460 *
461 * @return a handle to the hypervisor grant table interface or -1 on failure
462 */
463 int xc_grant_interface_open(void);
465 /**
466 * This function closes an open grant table hypervisor interface.
467 *
468 * This function can fail if the handle does not represent an open interface or
469 * if there were problems closing the interface.
470 *
471 * @parm xc_handle a handle to an open grant table hypervisor interface
472 * @return 0 on success, -1 otherwise.
473 */
474 int xc_grant_interface_close(int xc_handle);
476 int xc_gnttab_map_grant_ref(int xc_handle,
477 uint64_t host_virt_addr,
478 uint32_t dom,
479 grant_ref_t ref,
480 uint16_t flags,
481 int16_t *status,
482 grant_handle_t *handle,
483 uint64_t *dev_bus_addr);
485 int xc_gnttab_unmap_grant_ref(int xc_handle,
486 uint64_t host_virt_addr,
487 uint64_t dev_bus_addr,
488 grant_handle_t handle,
489 int16_t *status);
491 int xc_gnttab_setup_table(int xc_handle,
492 uint32_t dom,
493 uint16_t nr_frames,
494 int16_t *status,
495 unsigned long **frame_list);
497 /* Grant debug builds only: */
498 int xc_gnttab_dump_table(int xc_handle,
499 uint32_t dom,
500 int16_t *status);
502 /* Get current total pages allocated to a domain. */
503 long xc_get_tot_pages(int xc_handle, uint32_t domid);
506 /*
507 * Trace Buffer Operations
508 */
510 /**
511 * This function enables or disables tracing. Trace buffer memory must
512 * be already allocated by setting the size to a non-zero value, otherwise
513 * tracing cannot be enabled.
514 *
515 * @parm xc_handle a handle to an open hypervisor interface
516 * @parm enable the desired action, 1 for enable, 0 for disable
517 * @return 0 on success, -1 on failure.
518 */
519 int xc_tbuf_enable(int xc_handle, int enable);
521 /**
522 * This function sets the size of the trace buffers. Setting the size
523 * is currently a one-shot operation that may be performed either at boot
524 * time or via this interface, not both. The buffer size must be set before
525 * enabling tracing.
526 *
527 * @parm xc_handle a handle to an open hypervisor interface
528 * @parm size the size in pages per cpu for the trace buffers
529 * @return 0 on success, -1 on failure.
530 */
531 int xc_tbuf_set_size(int xc_handle, uint32_t size);
533 /**
534 * This function retrieves the current size of the trace buffers.
535 * Note that the size returned is in terms of bytes, not pages.
537 * @parm xc_handle a handle to an open hypervisor interface
538 * @parm size will contain the size in bytes for the trace buffers
539 * @return 0 on success, -1 on failure.
540 */
541 int xc_tbuf_get_size(int xc_handle, uint32_t *size);
544 /* Execute a privileged dom0 operation. */
545 int xc_dom0_op(int xc_handle, dom0_op_t *op);
547 int xc_version(int xc_handle, int cmd, void *arg);
549 /*
550 * MMU updates.
551 */
552 #define MAX_MMU_UPDATES 1024
553 struct xc_mmu {
554 mmu_update_t updates[MAX_MMU_UPDATES];
555 int idx;
556 domid_t subject;
557 };
558 typedef struct xc_mmu xc_mmu_t;
559 xc_mmu_t *xc_init_mmu_updates(int xc_handle, domid_t dom);
560 int xc_add_mmu_update(int xc_handle, xc_mmu_t *mmu,
561 unsigned long long ptr, unsigned long long val);
562 int xc_finish_mmu_updates(int xc_handle, xc_mmu_t *mmu);
564 #endif