direct-io.hg

view tools/libxc/xenctrl.h @ 7624:15dc55145e55

Added xc_domain_ioport_permission to libxc, which wraps the dom0 op

Signed-off-by: Jody Belka <knew (at) pimb (dot) org>
author kaf24@firebug.cl.cam.ac.uk
date Sun Nov 06 16:39:55 2005 +0100 (2005-11-06)
parents 8cc7ce549d00
children b3c2bc39d815
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 nr_online_vcpus;
136 unsigned int max_vcpu_id;
137 xen_domain_handle_t handle;
138 } xc_dominfo_t;
140 typedef dom0_getdomaininfo_t xc_domaininfo_t;
141 int xc_domain_create(int xc_handle,
142 uint32_t ssidref,
143 xen_domain_handle_t handle,
144 uint32_t *pdomid);
147 int xc_domain_dumpcore(int xc_handle,
148 uint32_t domid,
149 const char *corename);
151 /*
152 * This function sets the maximum number of vcpus that a domain may create.
153 *
154 * @parm xc_handle a handle to an open hypervisor interface.
155 * @parm domid the domain id in which vcpus are to be created.
156 * @parm max the maximum number of vcpus that the domain may create.
157 * @return 0 on success, -1 on failure.
158 */
159 int xc_domain_max_vcpus(int xc_handle,
160 uint32_t domid,
161 unsigned int max);
163 /**
164 * This function pauses a domain. A paused domain still exists in memory
165 * however it does not receive any timeslices from the hypervisor.
166 *
167 * @parm xc_handle a handle to an open hypervisor interface
168 * @parm domid the domain id to pause
169 * @return 0 on success, -1 on failure.
170 */
171 int xc_domain_pause(int xc_handle,
172 uint32_t domid);
173 /**
174 * This function unpauses a domain. The domain should have been previously
175 * paused.
176 *
177 * @parm xc_handle a handle to an open hypervisor interface
178 * @parm domid the domain id to unpause
179 * return 0 on success, -1 on failure
180 */
181 int xc_domain_unpause(int xc_handle,
182 uint32_t domid);
184 /**
185 * This function will destroy a domain. Destroying a domain removes the domain
186 * completely from memory. This function should be called after sending the
187 * domain a SHUTDOWN control message to free up the domain resources.
188 *
189 * @parm xc_handle a handle to an open hypervisor interface
190 * @parm domid the domain id to destroy
191 * @return 0 on success, -1 on failure
192 */
193 int xc_domain_destroy(int xc_handle,
194 uint32_t domid);
195 int xc_domain_pincpu(int xc_handle,
196 uint32_t domid,
197 int vcpu,
198 cpumap_t cpumap);
200 /**
201 * This function will return information about one or more domains. It is
202 * designed to iterate over the list of domains. If a single domain is
203 * requested, this function will return the next domain in the list - if
204 * one exists. It is, therefore, important in this case to make sure the
205 * domain requested was the one returned.
206 *
207 * @parm xc_handle a handle to an open hypervisor interface
208 * @parm first_domid the first domain to enumerate information from. Domains
209 * are currently enumerate in order of creation.
210 * @parm max_doms the number of elements in info
211 * @parm info an array of max_doms size that will contain the information for
212 * the enumerated domains.
213 * @return the number of domains enumerated or -1 on error
214 */
215 int xc_domain_getinfo(int xc_handle,
216 uint32_t first_domid,
217 unsigned int max_doms,
218 xc_dominfo_t *info);
220 /**
221 * This function will return information about one or more domains, using a
222 * single hypercall. The domain information will be stored into the supplied
223 * array of xc_domaininfo_t structures.
224 *
225 * @parm xc_handle a handle to an open hypervisor interface
226 * @parm first_domain the first domain to enumerate information from.
227 * Domains are currently enumerate in order of creation.
228 * @parm max_domains the number of elements in info
229 * @parm info an array of max_doms size that will contain the information for
230 * the enumerated domains.
231 * @return the number of domains enumerated or -1 on error
232 */
233 int xc_domain_getinfolist(int xc_handle,
234 uint32_t first_domain,
235 unsigned int max_domains,
236 xc_domaininfo_t *info);
238 /**
239 * This function returns information about the execution context of a
240 * particular vcpu of a domain.
241 *
242 * @parm xc_handle a handle to an open hypervisor interface
243 * @parm domid the domain to get information from
244 * @parm vcpu the vcpu number
245 * @parm ctxt a pointer to a structure to store the execution context of the
246 * domain
247 * @return 0 on success, -1 on failure
248 */
249 int xc_domain_get_vcpu_context(int xc_handle,
250 uint32_t domid,
251 uint32_t vcpu,
252 vcpu_guest_context_t *ctxt);
254 typedef dom0_getvcpuinfo_t xc_vcpuinfo_t;
255 int xc_domain_get_vcpu_info(int xc_handle,
256 uint32_t domid,
257 uint32_t vcpu,
258 xc_vcpuinfo_t *info);
261 int xc_domain_setcpuweight(int xc_handle,
262 uint32_t domid,
263 float weight);
264 long long xc_domain_get_cpu_usage(int xc_handle,
265 domid_t domid,
266 int vcpu);
268 int xc_domain_sethandle(int xc_handle, uint32_t domid,
269 xen_domain_handle_t handle);
271 typedef dom0_shadow_control_stats_t xc_shadow_control_stats_t;
272 int xc_shadow_control(int xc_handle,
273 uint32_t domid,
274 unsigned int sop,
275 unsigned long *dirty_bitmap,
276 unsigned long pages,
277 xc_shadow_control_stats_t *stats);
279 int xc_bvtsched_global_set(int xc_handle,
280 unsigned long ctx_allow);
282 int xc_bvtsched_domain_set(int xc_handle,
283 uint32_t domid,
284 uint32_t mcuadv,
285 int warpback,
286 int32_t warpvalue,
287 long long warpl,
288 long long warpu);
290 int xc_bvtsched_global_get(int xc_handle,
291 unsigned long *ctx_allow);
293 int xc_bvtsched_domain_get(int xc_handle,
294 uint32_t domid,
295 uint32_t *mcuadv,
296 int *warpback,
297 int32_t *warpvalue,
298 long long *warpl,
299 long long *warpu);
301 int xc_sedf_domain_set(int xc_handle,
302 uint32_t domid,
303 uint64_t period, uint64_t slice,
304 uint64_t latency, uint16_t extratime,
305 uint16_t weight);
307 int xc_sedf_domain_get(int xc_handle,
308 uint32_t domid,
309 uint64_t* period, uint64_t *slice,
310 uint64_t *latency, uint16_t *extratime,
311 uint16_t *weight);
313 typedef evtchn_status_t xc_evtchn_status_t;
315 /*
316 * EVENT CHANNEL FUNCTIONS
317 */
319 /**
320 * This function allocates an unbound port. Ports are named endpoints used for
321 * interdomain communication. This function is most useful in opening a
322 * well-known port within a domain to receive events on.
323 *
324 * @parm xc_handle a handle to an open hypervisor interface
325 * @parm dom the ID of the local domain (the 'allocatee')
326 * @parm remote_dom the ID of the domain who will later bind
327 * @return allocated port (in @dom) on success, -1 on failure
328 */
329 int xc_evtchn_alloc_unbound(int xc_handle,
330 uint32_t dom,
331 uint32_t remote_dom);
333 int xc_evtchn_status(int xc_handle,
334 uint32_t dom, /* may be DOMID_SELF */
335 int port,
336 xc_evtchn_status_t *status);
338 int xc_physdev_pci_access_modify(int xc_handle,
339 uint32_t domid,
340 int bus,
341 int dev,
342 int func,
343 int enable);
345 int xc_readconsolering(int xc_handle,
346 char **pbuffer,
347 unsigned int *pnr_chars,
348 int clear);
350 typedef dom0_physinfo_t xc_physinfo_t;
351 int xc_physinfo(int xc_handle,
352 xc_physinfo_t *info);
354 int xc_sched_id(int xc_handle,
355 int *sched_id);
357 int xc_domain_setmaxmem(int xc_handle,
358 uint32_t domid,
359 unsigned int max_memkb);
361 int xc_domain_memory_increase_reservation(int xc_handle,
362 uint32_t domid,
363 unsigned long nr_extents,
364 unsigned int extent_order,
365 unsigned int address_bits,
366 unsigned long *extent_start);
368 int xc_domain_memory_decrease_reservation(int xc_handle,
369 uint32_t domid,
370 unsigned long nr_extents,
371 unsigned int extent_order,
372 unsigned long *extent_start);
374 int xc_domain_ioport_permission(int xc_handle,
375 uint32_t domid,
376 uint16_t first_port,
377 uint16_t nr_ports,
378 uint16_t allow_access);
380 unsigned long xc_make_page_below_4G(int xc_handle, uint32_t domid,
381 unsigned long mfn);
383 typedef dom0_perfc_desc_t xc_perfc_desc_t;
384 /* IMPORTANT: The caller is responsible for mlock()'ing the @desc array. */
385 int xc_perfc_control(int xc_handle,
386 uint32_t op,
387 xc_perfc_desc_t *desc);
389 /* read/write msr */
390 long long xc_msr_read(int xc_handle, int cpu_mask, int msr);
391 int xc_msr_write(int xc_handle, int cpu_mask, int msr, unsigned int low,
392 unsigned int high);
394 /**
395 * Memory maps a range within one domain to a local address range. Mappings
396 * should be unmapped with munmap and should follow the same rules as mmap
397 * regarding page alignment. Returns NULL on failure.
398 *
399 * In Linux, the ring queue for the control channel is accessible by mapping
400 * the shared_info_frame (from xc_domain_getinfo()) + 2048. The structure
401 * stored there is of type control_if_t.
402 *
403 * @parm xc_handle a handle on an open hypervisor interface
404 * @parm dom the domain to map memory from
405 * @parm size the amount of memory to map (in multiples of page size)
406 * @parm prot same flag as in mmap().
407 * @parm mfn the frame address to map.
408 */
409 void *xc_map_foreign_range(int xc_handle, uint32_t dom,
410 int size, int prot,
411 unsigned long mfn );
413 void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
414 unsigned long *arr, int num );
416 int xc_get_pfn_list(int xc_handle, uint32_t domid, unsigned long *pfn_buf,
417 unsigned long max_pfns);
419 int xc_ia64_get_pfn_list(int xc_handle, uint32_t domid,
420 unsigned long *pfn_buf,
421 unsigned int start_page, unsigned int nr_pages);
423 int xc_copy_to_domain_page(int xc_handle, uint32_t domid,
424 unsigned long dst_pfn, void *src_page);
426 int xc_ia64_copy_to_domain_pages(int xc_handle, uint32_t domid,
427 void* src_page, unsigned long dst_pfn, int nr_pages);
429 long xc_get_max_pages(int xc_handle, uint32_t domid);
431 int xc_mmuext_op(int xc_handle, struct mmuext_op *op, unsigned int nr_ops,
432 domid_t dom);
434 int xc_memory_op(int xc_handle, int cmd, void *arg);
436 int xc_get_pfn_type_batch(int xc_handle, uint32_t dom,
437 int num, unsigned long *arr);
440 /*\
441 * GRANT TABLE FUNCTIONS
442 \*/
444 /**
445 * This function opens a handle to the more restricted grant table hypervisor
446 * interface. This may be used where the standard interface is not
447 * available because the domain is not privileged.
448 * This function can be called multiple times within a single process.
449 * Multiple processes can have an open hypervisor interface at the same time.
450 *
451 * Each call to this function should have a corresponding call to
452 * xc_grant_interface_close().
453 *
454 * This function can fail if a Xen-enabled kernel is not currently running.
455 *
456 * @return a handle to the hypervisor grant table interface or -1 on failure
457 */
458 int xc_grant_interface_open(void);
460 /**
461 * This function closes an open grant table hypervisor interface.
462 *
463 * This function can fail if the handle does not represent an open interface or
464 * if there were problems closing the interface.
465 *
466 * @parm xc_handle a handle to an open grant table hypervisor interface
467 * @return 0 on success, -1 otherwise.
468 */
469 int xc_grant_interface_close(int xc_handle);
471 int xc_gnttab_map_grant_ref(int xc_handle,
472 uint64_t host_virt_addr,
473 uint32_t dom,
474 uint16_t ref,
475 uint16_t flags,
476 int16_t *handle,
477 uint64_t *dev_bus_addr);
479 int xc_gnttab_unmap_grant_ref(int xc_handle,
480 uint64_t host_virt_addr,
481 uint64_t dev_bus_addr,
482 uint16_t handle,
483 int16_t *status);
485 int xc_gnttab_setup_table(int xc_handle,
486 uint32_t dom,
487 uint16_t nr_frames,
488 int16_t *status,
489 unsigned long **frame_list);
491 /* Grant debug builds only: */
492 int xc_gnttab_dump_table(int xc_handle,
493 uint32_t dom,
494 int16_t *status);
496 /* Get current total pages allocated to a domain. */
497 long xc_get_tot_pages(int xc_handle, uint32_t domid);
500 /*
501 * Trace Buffer Operations
502 */
504 /**
505 * This function enables or disables tracing. Trace buffer memory must
506 * be already allocated by setting the size to a non-zero value, otherwise
507 * tracing cannot be enabled.
508 *
509 * @parm xc_handle a handle to an open hypervisor interface
510 * @parm enable the desired action, 1 for enable, 0 for disable
511 * @return 0 on success, -1 on failure.
512 */
513 int xc_tbuf_enable(int xc_handle, int enable);
515 /**
516 * This function sets the size of the trace buffers. Setting the size
517 * is currently a one-shot operation that may be performed either at boot
518 * time or via this interface, not both. The buffer size must be set before
519 * enabling tracing.
520 *
521 * @parm xc_handle a handle to an open hypervisor interface
522 * @parm size the size in pages per cpu for the trace buffers
523 * @return 0 on success, -1 on failure.
524 */
525 int xc_tbuf_set_size(int xc_handle, uint32_t size);
527 /**
528 * This function retrieves the current size of the trace buffers.
529 * Note that the size returned is in terms of bytes, not pages.
531 * @parm xc_handle a handle to an open hypervisor interface
532 * @parm size will contain the size in bytes for the trace buffers
533 * @return 0 on success, -1 on failure.
534 */
535 int xc_tbuf_get_size(int xc_handle, uint32_t *size);
538 /* Execute a privileged dom0 operation. */
539 int xc_dom0_op(int xc_handle, dom0_op_t *op);
541 int xc_version(int xc_handle, int cmd, void *arg);
543 /*
544 * MMU updates.
545 */
546 #define MAX_MMU_UPDATES 1024
547 struct xc_mmu {
548 mmu_update_t updates[MAX_MMU_UPDATES];
549 int idx;
550 domid_t subject;
551 };
552 typedef struct xc_mmu xc_mmu_t;
553 xc_mmu_t *xc_init_mmu_updates(int xc_handle, domid_t dom);
554 int xc_add_mmu_update(int xc_handle, xc_mmu_t *mmu,
555 unsigned long long ptr, unsigned long long val);
556 int xc_finish_mmu_updates(int xc_handle, xc_mmu_t *mmu);
558 #endif