direct-io.hg

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