direct-io.hg

view tools/libxc/xc.h @ 3961:a19f7bbbe144

bitkeeper revision 1.1236.1.44 (4224f156AyEV3oV5JinuYtfS9e_ITA)

Rationalise memory-barrier definitions in user-space tools.
Signed-off-by: Jerone Young <jyoung5@us.ibm.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@scramble.cl.cam.ac.uk
date Tue Mar 01 22:48:54 2005 +0000 (2005-03-01)
parents 0a4b76b6b5a0
children 24703bde489b 0b9ff7354a95
line source
1 /******************************************************************************
2 * xc.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 __XC_H__
10 #define __XC_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 <xen/xen.h>
24 #include <xen/dom0_ops.h>
25 #include <xen/event_channel.h>
26 #include <xen/sched_ctl.h>
29 /*
30 * DEFINITIONS FOR CPU BARRIERS
31 */
33 #if defined(__i386__)
34 #define rmb() __asm__ __volatile__ ("lock; addl $0,0(%%esp)" : : : "memory")
35 #define wmb() __asm__ __volatile__ ("" : : : "memory")
36 #elif defined(__x86_64__)
37 #define mb() asm volatile("mfence":::"memory")
38 #define rmb() asm volatile("lfence":::"memory")
39 #define wmb() asm volatile( "" :::"memory")
40 #else
41 #error "Define barriers"
42 #endif
44 /*
45 * INITIALIZATION FUNCTIONS
46 */
48 /**
49 * This function opens a handle to the hypervisor interface. This function can
50 * be called multiple times within a single process. Multiple processes can
51 * have an open hypervisor interface at the same time.
52 *
53 * Each call to this function should have a corresponding call to
54 * xc_interface_close().
55 *
56 * This function can fail if the caller does not have superuser permission or
57 * if a Xen-enabled kernel is not currently running.
58 *
59 * @return a handle to the hypervisor interface or -1 on failure
60 */
61 int xc_interface_open(void);
63 /**
64 * This function closes an open hypervisor interface.
65 *
66 * This function can fail if the handle does not represent an open interface or
67 * if there were problems closing the interface.
68 *
69 * @parm xc_handle a handle to an open hypervisor interface
70 * @return 0 on success, -1 otherwise.
71 */
72 int xc_interface_close(int xc_handle);
74 /*
75 * DOMAIN MANAGEMENT FUNCTIONS
76 */
78 typedef struct {
79 u32 domid;
80 unsigned int cpu;
81 unsigned int dying:1, crashed:1, shutdown:1,
82 paused:1, blocked:1, running:1;
83 unsigned int shutdown_reason; /* only meaningful if shutdown==1 */
84 unsigned long nr_pages;
85 unsigned long shared_info_frame;
86 u64 cpu_time;
87 unsigned long max_memkb;
88 } xc_dominfo_t;
90 typedef dom0_getdomaininfo_t xc_domaininfo_t;
91 int xc_domain_create(int xc_handle,
92 unsigned int mem_kb,
93 int cpu,
94 float cpu_weight,
95 u32 *pdomid);
97 /**
98 * This function pauses a domain. A paused domain still exists in memory
99 * however it does not receive any timeslices from the hypervisor.
100 *
101 * @parm xc_handle a handle to an open hypervisor interface
102 * @parm domid the domain id to pause
103 * @return 0 on success, -1 on failure.
104 */
105 int xc_domain_pause(int xc_handle,
106 u32 domid);
107 /**
108 * This function unpauses a domain. The domain should have been previously
109 * paused.
110 *
111 * @parm xc_handle a handle to an open hypervisor interface
112 * @parm domid the domain id to unpause
113 * return 0 on success, -1 on failure
114 */
115 int xc_domain_unpause(int xc_handle,
116 u32 domid);
118 /**
119 * This function will destroy a domain. Destroying a domain removes the domain
120 * completely from memory. This function should be called after sending the
121 * domain a SHUTDOWN control message to free up the domain resources.
122 *
123 * @parm xc_handle a handle to an open hypervisor interface
124 * @parm domid the domain id to destroy
125 * @return 0 on success, -1 on failure
126 */
127 int xc_domain_destroy(int xc_handle,
128 u32 domid);
129 int xc_domain_pincpu(int xc_handle,
130 u32 domid,
131 int cpu);
132 /**
133 * This function will return information about one or more domains.
134 *
135 * @parm xc_handle a handle to an open hypervisor interface
136 * @parm first_domid the first domain to enumerate information from. Domains
137 * are currently enumerate in order of creation.
138 * @parm max_doms the number of elements in info
139 * @parm info an array of max_doms size that will contain the information for
140 * the enumerated domains.
141 * @return the number of domains enumerated or -1 on error
142 */
143 int xc_domain_getinfo(int xc_handle,
144 u32 first_domid,
145 unsigned int max_doms,
146 xc_dominfo_t *info);
148 /**
149 * This function returns information about one domain. This information is
150 * more detailed than the information from xc_domain_getinfo().
151 *
152 * @parm xc_handle a handle to an open hypervisor interface
153 * @parm domid the domain to get information from
154 * @parm info a pointer to an xc_domaininfo_t to store the domain information
155 * @parm ctxt a pointer to a structure to store the execution context of the
156 * domain
157 * @return 0 on success, -1 on failure
158 */
159 int xc_domain_getfullinfo(int xc_handle,
160 u32 domid,
161 u32 vcpu,
162 xc_domaininfo_t *info,
163 full_execution_context_t *ctxt);
164 int xc_domain_setcpuweight(int xc_handle,
165 u32 domid,
166 float weight);
167 long long xc_domain_get_cpu_usage(int xc_handle,
168 domid_t domid,
169 int vcpu);
172 typedef dom0_shadow_control_stats_t xc_shadow_control_stats_t;
173 int xc_shadow_control(int xc_handle,
174 u32 domid,
175 unsigned int sop,
176 unsigned long *dirty_bitmap,
177 unsigned long pages,
178 xc_shadow_control_stats_t *stats);
181 #define XCFLAGS_VERBOSE 1
182 #define XCFLAGS_LIVE 2
183 #define XCFLAGS_DEBUG 4
184 #define XCFLAGS_CONFIGURE 8
186 struct XcIOContext;
188 /**
189 * This function will save a domain running Linux to an IO context. This
190 * IO context is currently a private interface making this function difficult
191 * to call. It's interface will likely change in the future.
192 *
193 * @parm xc_handle a handle to an open hypervisor interface
194 * @parm ioctxt the IO context to save a domain to
195 * @return 0 on success, -1 on failure
196 */
197 int xc_linux_save(int xc_handle, struct XcIOContext *ioctxt);
199 /**
200 * This function will restore a saved domain running Linux to an IO context.
201 * Like xc_linux_save(), this function uses a parameter who's structure is
202 * privately defined. It's interface will also likely change.
203 *
204 * @parm xc_handle a handle to an open hypervisor interface
205 * @parm ioctxt the IO context to restore a domain from
206 * @return 0 on success, -1 on failure
207 */
208 int xc_linux_restore(int xc_handle, struct XcIOContext *ioctxt);
210 int xc_linux_build(int xc_handle,
211 u32 domid,
212 const char *image_name,
213 const char *ramdisk_name,
214 const char *cmdline,
215 unsigned int control_evtchn,
216 unsigned long flags,
217 unsigned int vcpus);
219 int
220 xc_plan9_build (int xc_handle,
221 u32 domid,
222 const char *image_name,
223 const char *cmdline,
224 unsigned int control_evtchn,
225 unsigned long flags);
227 struct mem_map;
228 int xc_vmx_build(int xc_handle,
229 u32 domid,
230 int memsize,
231 const char *image_name,
232 struct mem_map *memmap,
233 const char *ramdisk_name,
234 const char *cmdline,
235 unsigned int control_evtchn,
236 unsigned long flags);
238 int xc_bvtsched_global_set(int xc_handle,
239 unsigned long ctx_allow);
241 int xc_bvtsched_domain_set(int xc_handle,
242 u32 domid,
243 u32 mcuadv,
244 int warpback,
245 s32 warpvalue,
246 long long warpl,
247 long long warpu);
249 int xc_bvtsched_global_get(int xc_handle,
250 unsigned long *ctx_allow);
252 int xc_bvtsched_domain_get(int xc_handle,
253 u32 domid,
254 u32 *mcuadv,
255 int *warpback,
256 s32 *warpvalue,
257 long long *warpl,
258 long long *warpu);
260 int xc_atropos_domain_set(int xc_handle,
261 u32 domid,
262 u64 period, u64 slice, u64 latency,
263 int xtratime);
265 int xc_atropos_domain_get(int xc_handle,
266 u32 domid,
267 u64* period, u64 *slice, u64 *latency,
268 int *xtratime);
270 int xc_rrobin_global_set(int xc_handle, u64 slice);
272 int xc_rrobin_global_get(int xc_handle, u64 *slice);
274 typedef evtchn_status_t xc_evtchn_status_t;
276 /*
277 * EVENT CHANNEL FUNCTIONS
278 */
280 /**
281 * This function allocates an unbound port. Ports are named endpoints used for
282 * interdomain communication. This function is most useful in opening a
283 * well-known port within a domain to receive events on.
284 *
285 * @parm xc_handle a handle to an open hypervisor interface
286 * @parm dom the ID of the domain. This maybe DOMID_SELF
287 * @parm port a pointer to a port. This is an in/out parameter. If *port is
288 * 0, then a new port will be assigned, if port is > 0 then that
289 * port is allocated if the port is unallocated.
290 * @return 0 on success, -1 on failure
291 */
292 int xc_evtchn_alloc_unbound(int xc_handle,
293 u32 dom,
294 int *port);
296 /**
297 * This function creates a pair of ports between two domains. A port can only
298 * be bound once within a domain.
299 *
300 * @parm xc_handle a handle to an open hypervisor interface
301 * @parm dom1 one of the two domains to connect. Can be DOMID_SELF.
302 * @parm dom2 the other domain to connect. Can be DOMID_SELF.
303 * @parm port1 an in/out parameter. If > 0, then try to connect *port. If
304 * 0, then allocate a new port and store the port in *port.
305 * @parm port2 the port connected on port2. This parameter behaves the same
306 * way as port1.
307 * @return 0 on success, -1 on error.
308 */
309 int xc_evtchn_bind_interdomain(int xc_handle,
310 u32 dom1,
311 u32 dom2,
312 int *port1,
313 int *port2);
314 int xc_evtchn_bind_virq(int xc_handle,
315 int virq,
316 int *port);
318 /**
319 * This function will close a single port on an event channel.
320 *
321 * @parm xc_handle a handle to an open hypervisor interface
322 * @parm dom the domain that the port exists on. May be DOMID_SELF.
323 * @parm port the port to close
324 * @return 0 on success, -1 on error
325 */
326 int xc_evtchn_close(int xc_handle,
327 u32 dom, /* may be DOMID_SELF */
328 int port);
330 /**
331 * This function generates a notify event on a bound port.
332 *
333 * Notifies can be read within Linux by opening /dev/xen/evtchn and reading
334 * a 16 bit value. The result will be the port the event occurred on. When
335 * events occur, the port is masked until the 16 bit port value is written back
336 * to the file. When /dev/xen/evtchn is opened, it has to be bound via an
337 * ioctl to each port to listen on. The ioctl for binding is _IO('E', 2). The
338 * parameter is the port to listen on.
339 *
340 * @parm xc_handle a handle to an open hypervisor interface
341 * @parm local_port the port to generate the notify on
342 * @return 0 on success, -1 on error
343 */
344 int xc_evtchn_send(int xc_handle,
345 int local_port);
346 int xc_evtchn_status(int xc_handle,
347 u32 dom, /* may be DOMID_SELF */
348 int port,
349 xc_evtchn_status_t *status);
351 int xc_physdev_pci_access_modify(int xc_handle,
352 u32 domid,
353 int bus,
354 int dev,
355 int func,
356 int enable);
358 int xc_readconsolering(int xc_handle,
359 char *str,
360 unsigned int max_chars,
361 int clear);
363 typedef dom0_physinfo_t xc_physinfo_t;
364 int xc_physinfo(int xc_handle,
365 xc_physinfo_t *info);
367 int xc_sched_id(int xc_handle,
368 int *sched_id);
370 int xc_domain_setinitialmem(int xc_handle,
371 u32 domid,
372 unsigned int initial_memkb);
374 int xc_domain_setmaxmem(int xc_handle,
375 u32 domid,
376 unsigned int max_memkb);
378 int xc_domain_setvmassist(int xc_handle,
379 u32 domid,
380 unsigned int cmd,
381 unsigned int type);
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 u32 op,
387 xc_perfc_desc_t *desc);
389 /**
390 * Memory maps a range within one domain to a local address range. Mappings
391 * should be unmapped with munmap and should follow the same rules as mmap
392 * regarding page alignment.
393 *
394 * In Linux, the ring queue for the control channel is accessible by mapping
395 * the shared_info_frame (from xc_domain_getinfo()) + 2048. The structure
396 * stored there is of type control_if_t.
397 *
398 * @parm xc_handle a handle on an open hypervisor interface
399 * @parm dom the domain to map memory from
400 * @parm size the amount of memory to map (in multiples of page size)
401 * @parm prot same flag as in mmap().
402 * @parm mfn the frame address to map.
403 */
404 void *xc_map_foreign_range(int xc_handle, u32 dom,
405 int size, int prot,
406 unsigned long mfn );
408 void *xc_map_foreign_batch(int xc_handle, u32 dom, int prot,
409 unsigned long *arr, int num );
411 int xc_get_pfn_list(int xc_handle, u32 domid, unsigned long *pfn_buf,
412 unsigned long max_pfns);
414 #endif /* __XC_H__ */