ia64/xen-unstable

view tools/libxc/xenctrl.h @ 6435:b4b3f6be5226

merge?
author cl349@firebug.cl.cam.ac.uk
date Thu Aug 25 17:27:49 2005 +0000 (2005-08-25)
parents 0610add7c3fe fdfd511768a3
children 8799d14bef77 9312a3e8a6f8
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/event_channel.h>
27 #include <xen/sched_ctl.h>
28 #include <xen/acm.h>
30 #ifdef __ia64__
31 #define XC_PAGE_SHIFT 14
32 #else
33 #define XC_PAGE_SHIFT 12
34 #endif
35 #define XC_PAGE_SIZE (1UL << XC_PAGE_SHIFT)
36 #define XC_PAGE_MASK (~(XC_PAGE_SIZE-1))
38 /*
39 * DEFINITIONS FOR CPU BARRIERS
40 */
42 #if defined(__i386__)
43 #define mb() __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : : "memory" )
44 #define rmb() __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : : "memory" )
45 #define wmb() __asm__ __volatile__ ( "" : : : "memory")
46 #elif defined(__x86_64__)
47 #define mb() __asm__ __volatile__ ( "mfence" : : : "memory")
48 #define rmb() __asm__ __volatile__ ( "lfence" : : : "memory")
49 #define wmb() __asm__ __volatile__ ( "" : : : "memory")
50 #elif defined(__ia64__)
51 /* FIXME */
52 #define mb()
53 #define rmb()
54 #define wmb()
55 #else
56 #error "Define barriers"
57 #endif
59 /*
60 * INITIALIZATION FUNCTIONS
61 */
63 /**
64 * This function opens a handle to the hypervisor interface. This function can
65 * be called multiple times within a single process. Multiple processes can
66 * have an open hypervisor interface at the same time.
67 *
68 * Each call to this function should have a corresponding call to
69 * xc_interface_close().
70 *
71 * This function can fail if the caller does not have superuser permission or
72 * if a Xen-enabled kernel is not currently running.
73 *
74 * @return a handle to the hypervisor interface or -1 on failure
75 */
76 int xc_interface_open(void);
78 /**
79 * This function closes an open hypervisor interface.
80 *
81 * This function can fail if the handle does not represent an open interface or
82 * if there were problems closing the interface.
83 *
84 * @parm xc_handle a handle to an open hypervisor interface
85 * @return 0 on success, -1 otherwise.
86 */
87 int xc_interface_close(int xc_handle);
89 /*
90 * DOMAIN DEBUGGING FUNCTIONS
91 */
93 typedef struct xc_core_header {
94 unsigned int xch_magic;
95 unsigned int xch_nr_vcpus;
96 unsigned int xch_nr_pages;
97 unsigned int xch_ctxt_offset;
98 unsigned int xch_index_offset;
99 unsigned int xch_pages_offset;
100 } xc_core_header_t;
103 long xc_ptrace(enum __ptrace_request request,
104 u32 domid,
105 long addr,
106 long data);
108 long xc_ptrace_core(enum __ptrace_request request,
109 u32 domid,
110 long addr,
111 long data);
113 int xc_waitdomain(int domain,
114 int *status,
115 int options);
117 int xc_waitdomain_core(int domain,
118 int *status,
119 int options);
121 /*
122 * DOMAIN MANAGEMENT FUNCTIONS
123 */
125 typedef struct {
126 u32 domid;
127 u32 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 u64 cpu_time;
134 unsigned long max_memkb;
135 unsigned int vcpus;
136 s32 vcpu_to_cpu[MAX_VIRT_CPUS];
137 cpumap_t cpumap[MAX_VIRT_CPUS];
138 } xc_dominfo_t;
140 typedef dom0_getdomaininfo_t xc_domaininfo_t;
141 int xc_domain_create(int xc_handle,
142 u32 ssidref,
143 u32 *pdomid);
146 int xc_domain_dumpcore(int xc_handle,
147 u32 domid,
148 const char *corename);
151 /**
152 * This function pauses a domain. A paused domain still exists in memory
153 * however it does not receive any timeslices from the hypervisor.
154 *
155 * @parm xc_handle a handle to an open hypervisor interface
156 * @parm domid the domain id to pause
157 * @return 0 on success, -1 on failure.
158 */
159 int xc_domain_pause(int xc_handle,
160 u32 domid);
161 /**
162 * This function unpauses a domain. The domain should have been previously
163 * paused.
164 *
165 * @parm xc_handle a handle to an open hypervisor interface
166 * @parm domid the domain id to unpause
167 * return 0 on success, -1 on failure
168 */
169 int xc_domain_unpause(int xc_handle,
170 u32 domid);
172 /**
173 * This function will destroy a domain. Destroying a domain removes the domain
174 * completely from memory. This function should be called after sending the
175 * domain a SHUTDOWN control message to free up the domain resources.
176 *
177 * @parm xc_handle a handle to an open hypervisor interface
178 * @parm domid the domain id to destroy
179 * @return 0 on success, -1 on failure
180 */
181 int xc_domain_destroy(int xc_handle,
182 u32 domid);
183 int xc_domain_pincpu(int xc_handle,
184 u32 domid,
185 int vcpu,
186 cpumap_t *cpumap);
187 /**
188 * This function will return information about one or more domains. It is
189 * designed to iterate over the list of domains. If a single domain is
190 * requested, this function will return the next domain in the list - if
191 * one exists. It is, therefore, important in this case to make sure the
192 * domain requested was the one returned.
193 *
194 * @parm xc_handle a handle to an open hypervisor interface
195 * @parm first_domid the first domain to enumerate information from. Domains
196 * are currently enumerate in order of creation.
197 * @parm max_doms the number of elements in info
198 * @parm info an array of max_doms size that will contain the information for
199 * the enumerated domains.
200 * @return the number of domains enumerated or -1 on error
201 */
202 int xc_domain_getinfo(int xc_handle,
203 u32 first_domid,
204 unsigned int max_doms,
205 xc_dominfo_t *info);
207 /**
208 * This function will return information about one or more domains, using a
209 * single hypercall. The domain information will be stored into the supplied
210 * array of xc_domaininfo_t structures.
211 *
212 * @parm xc_handle a handle to an open hypervisor interface
213 * @parm first_domain the first domain to enumerate information from.
214 * Domains are currently enumerate in order of creation.
215 * @parm max_domains the number of elements in info
216 * @parm info an array of max_doms size that will contain the information for
217 * the enumerated domains.
218 * @return the number of domains enumerated or -1 on error
219 */
220 int xc_domain_getinfolist(int xc_handle,
221 u32 first_domain,
222 unsigned int max_domains,
223 xc_domaininfo_t *info);
225 /**
226 * This function returns information about one domain. This information is
227 * more detailed than the information from xc_domain_getinfo().
228 *
229 * @parm xc_handle a handle to an open hypervisor interface
230 * @parm domid the domain to get information from
231 * @parm info a pointer to an xc_domaininfo_t to store the domain information
232 * @parm ctxt a pointer to a structure to store the execution context of the
233 * domain
234 * @return 0 on success, -1 on failure
235 */
236 int xc_domain_get_vcpu_context(int xc_handle,
237 u32 domid,
238 u32 vcpu,
239 vcpu_guest_context_t *ctxt);
241 int xc_domain_setcpuweight(int xc_handle,
242 u32 domid,
243 float weight);
244 long long xc_domain_get_cpu_usage(int xc_handle,
245 domid_t domid,
246 int vcpu);
249 typedef dom0_shadow_control_stats_t xc_shadow_control_stats_t;
250 int xc_shadow_control(int xc_handle,
251 u32 domid,
252 unsigned int sop,
253 unsigned long *dirty_bitmap,
254 unsigned long pages,
255 xc_shadow_control_stats_t *stats);
257 int xc_bvtsched_global_set(int xc_handle,
258 unsigned long ctx_allow);
260 int xc_bvtsched_domain_set(int xc_handle,
261 u32 domid,
262 u32 mcuadv,
263 int warpback,
264 s32 warpvalue,
265 long long warpl,
266 long long warpu);
268 int xc_bvtsched_global_get(int xc_handle,
269 unsigned long *ctx_allow);
271 int xc_bvtsched_domain_get(int xc_handle,
272 u32 domid,
273 u32 *mcuadv,
274 int *warpback,
275 s32 *warpvalue,
276 long long *warpl,
277 long long *warpu);
279 int xc_sedf_domain_set(int xc_handle,
280 u32 domid,
281 u64 period, u64 slice, u64 latency, u16 extratime, u16 weight);
283 int xc_sedf_domain_get(int xc_handle,
284 u32 domid,
285 u64* period, u64 *slice, u64 *latency, u16 *extratime, u16* weight);
287 typedef evtchn_status_t xc_evtchn_status_t;
289 /*
290 * EVENT CHANNEL FUNCTIONS
291 */
293 /**
294 * This function allocates an unbound port. Ports are named endpoints used for
295 * interdomain communication. This function is most useful in opening a
296 * well-known port within a domain to receive events on.
297 *
298 * @parm xc_handle a handle to an open hypervisor interface
299 * @parm dom the ID of the domain. This maybe DOMID_SELF
300 * @parm port a pointer to a port. This is an in/out parameter. If *port is
301 * 0, then a new port will be assigned, if port is > 0 then that
302 * port is allocated if the port is unallocated.
303 * @return 0 on success, -1 on failure
304 */
305 int xc_evtchn_alloc_unbound(int xc_handle,
306 u32 dom,
307 int *port);
309 /**
310 * This function creates a pair of ports between two domains. A port can only
311 * be bound once within a domain.
312 *
313 * @parm xc_handle a handle to an open hypervisor interface
314 * @parm dom1 one of the two domains to connect. Can be DOMID_SELF.
315 * @parm dom2 the other domain to connect. Can be DOMID_SELF.
316 * @parm port1 an in/out parameter. If > 0, then try to connect *port. If
317 * 0, then allocate a new port and store the port in *port.
318 * @parm port2 the port connected on port2. This parameter behaves the same
319 * way as port1.
320 * @return 0 on success, -1 on error.
321 */
322 int xc_evtchn_bind_interdomain(int xc_handle,
323 u32 dom1,
324 u32 dom2,
325 int *port1,
326 int *port2);
327 int xc_evtchn_bind_virq(int xc_handle,
328 int virq,
329 int *port);
331 /**
332 * This function will close a single port on an event channel.
333 *
334 * @parm xc_handle a handle to an open hypervisor interface
335 * @parm dom the domain that the port exists on. May be DOMID_SELF.
336 * @parm port the port to close
337 * @return 0 on success, -1 on error
338 */
339 int xc_evtchn_close(int xc_handle,
340 u32 dom, /* may be DOMID_SELF */
341 int port);
343 /**
344 * This function generates a notify event on a bound port.
345 *
346 * Notifies can be read within Linux by opening /dev/xen/evtchn and reading
347 * a 16 bit value. The result will be the port the event occurred on. When
348 * events occur, the port is masked until the 16 bit port value is written back
349 * to the file. When /dev/xen/evtchn is opened, it has to be bound via an
350 * ioctl to each port to listen on. The ioctl for binding is _IO('E', 2). The
351 * parameter is the port to listen on.
352 *
353 * @parm xc_handle a handle to an open hypervisor interface
354 * @parm local_port the port to generate the notify on
355 * @return 0 on success, -1 on error
356 */
357 int xc_evtchn_send(int xc_handle,
358 int local_port);
359 int xc_evtchn_status(int xc_handle,
360 u32 dom, /* may be DOMID_SELF */
361 int port,
362 xc_evtchn_status_t *status);
364 int xc_physdev_pci_access_modify(int xc_handle,
365 u32 domid,
366 int bus,
367 int dev,
368 int func,
369 int enable);
371 int xc_readconsolering(int xc_handle,
372 char **pbuffer,
373 unsigned int *pnr_chars,
374 int clear);
376 typedef dom0_physinfo_t xc_physinfo_t;
377 int xc_physinfo(int xc_handle,
378 xc_physinfo_t *info);
380 int xc_sched_id(int xc_handle,
381 int *sched_id);
383 int xc_domain_setmaxmem(int xc_handle,
384 u32 domid,
385 unsigned int max_memkb);
387 int xc_domain_memory_increase_reservation(int xc_handle,
388 u32 domid,
389 unsigned int mem_kb);
391 typedef dom0_perfc_desc_t xc_perfc_desc_t;
392 /* IMPORTANT: The caller is responsible for mlock()'ing the @desc array. */
393 int xc_perfc_control(int xc_handle,
394 u32 op,
395 xc_perfc_desc_t *desc);
397 /* read/write msr */
398 long long xc_msr_read(int xc_handle, int cpu_mask, int msr);
399 int xc_msr_write(int xc_handle, int cpu_mask, int msr, unsigned int low,
400 unsigned int high);
402 /**
403 * Memory maps a range within one domain to a local address range. Mappings
404 * should be unmapped with munmap and should follow the same rules as mmap
405 * regarding page alignment. Returns NULL on failure.
406 *
407 * In Linux, the ring queue for the control channel is accessible by mapping
408 * the shared_info_frame (from xc_domain_getinfo()) + 2048. The structure
409 * stored there is of type control_if_t.
410 *
411 * @parm xc_handle a handle on an open hypervisor interface
412 * @parm dom the domain to map memory from
413 * @parm size the amount of memory to map (in multiples of page size)
414 * @parm prot same flag as in mmap().
415 * @parm mfn the frame address to map.
416 */
417 void *xc_map_foreign_range(int xc_handle, u32 dom,
418 int size, int prot,
419 unsigned long mfn );
421 void *xc_map_foreign_batch(int xc_handle, u32 dom, int prot,
422 unsigned long *arr, int num );
424 int xc_get_pfn_list(int xc_handle, u32 domid, unsigned long *pfn_buf,
425 unsigned long max_pfns);
427 int xc_ia64_get_pfn_list(int xc_handle, u32 domid, unsigned long *pfn_buf,
428 unsigned int start_page, unsigned int nr_pages);
430 int xc_mmuext_op(int xc_handle, struct mmuext_op *op, unsigned int nr_ops,
431 domid_t dom);
433 int xc_dom_mem_op(int xc_handle, unsigned int memop, unsigned int *extent_list,
434 unsigned int nr_extents, unsigned int extent_order,
435 domid_t domid);
437 int xc_get_pfn_type_batch(int xc_handle, u32 dom, 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 u64 host_virt_addr,
473 u32 dom,
474 u16 ref,
475 u16 flags,
476 s16 *handle,
477 u64 *dev_bus_addr);
479 int xc_gnttab_unmap_grant_ref(int xc_handle,
480 u64 host_virt_addr,
481 u64 dev_bus_addr,
482 u16 handle,
483 s16 *status);
485 int xc_gnttab_setup_table(int xc_handle,
486 u32 dom,
487 u16 nr_frames,
488 s16 *status,
489 unsigned long **frame_list);
491 /* Grant debug builds only: */
492 int xc_gnttab_dump_table(int xc_handle,
493 u32 dom,
494 s16 *status);
496 /* Get current total pages allocated to a domain. */
497 long xc_get_tot_pages(int xc_handle, u32 domid);
499 /* Execute a privileged dom0 operation. */
500 int xc_dom0_op(int xc_handle, dom0_op_t *op);
502 /* Initializes the store (for dom0)
503 remote_port should be the remote end of a bound interdomain channel between
504 the store and dom0.
506 This function returns a shared frame that should be passed to
507 xs_introduce_domain
508 */
509 long xc_init_store(int xc_handle, int remote_port);
511 /*
512 * MMU updates.
513 */
514 #define MAX_MMU_UPDATES 1024
515 struct xc_mmu {
516 mmu_update_t updates[MAX_MMU_UPDATES];
517 int idx;
518 domid_t subject;
519 };
520 typedef struct xc_mmu xc_mmu_t;
521 xc_mmu_t *xc_init_mmu_updates(int xc_handle, domid_t dom);
522 int xc_add_mmu_update(int xc_handle, xc_mmu_t *mmu,
523 unsigned long ptr, unsigned long val);
524 int xc_finish_mmu_updates(int xc_handle, xc_mmu_t *mmu);
526 #endif