ia64/xen-unstable

view xen/include/public/xen.h @ 6689:7d0fb56b4a91

merge?
author cl349@firebug.cl.cam.ac.uk
date Wed Sep 07 19:01:31 2005 +0000 (2005-09-07)
parents 549f4256ab3c dd668f7527cb
children b2f4823b6ff0 b35215021b32 b9b120c7631a e2f0a6fdb7d9
line source
1 /******************************************************************************
2 * xen.h
3 *
4 * Guest OS interface to Xen.
5 *
6 * Copyright (c) 2004, K A Fraser
7 */
9 #ifndef __XEN_PUBLIC_XEN_H__
10 #define __XEN_PUBLIC_XEN_H__
12 #if defined(__i386__)
13 #include "arch-x86_32.h"
14 #elif defined(__x86_64__)
15 #include "arch-x86_64.h"
16 #elif defined(__ia64__)
17 #include "arch-ia64.h"
18 #else
19 #error "Unsupported architecture"
20 #endif
22 /*
23 * XEN "SYSTEM CALLS" (a.k.a. HYPERCALLS).
24 */
26 /*
27 * x86_32: EAX = vector; EBX, ECX, EDX, ESI, EDI = args 1, 2, 3, 4, 5.
28 * EAX = return value
29 * (argument registers may be clobbered on return)
30 * x86_64: RAX = vector; RDI, RSI, RDX, R10, R8, R9 = args 1, 2, 3, 4, 5, 6.
31 * RAX = return value
32 * (argument registers not clobbered on return; RCX, R11 are)
33 */
34 #define __HYPERVISOR_set_trap_table 0
35 #define __HYPERVISOR_mmu_update 1
36 #define __HYPERVISOR_set_gdt 2
37 #define __HYPERVISOR_stack_switch 3
38 #define __HYPERVISOR_set_callbacks 4
39 #define __HYPERVISOR_fpu_taskswitch 5
40 #define __HYPERVISOR_sched_op 6
41 #define __HYPERVISOR_dom0_op 7
42 #define __HYPERVISOR_set_debugreg 8
43 #define __HYPERVISOR_get_debugreg 9
44 #define __HYPERVISOR_update_descriptor 10
45 #define __HYPERVISOR_memory_op 12
46 #define __HYPERVISOR_multicall 13
47 #define __HYPERVISOR_update_va_mapping 14
48 #define __HYPERVISOR_set_timer_op 15
49 #define __HYPERVISOR_event_channel_op 16
50 #define __HYPERVISOR_xen_version 17
51 #define __HYPERVISOR_console_io 18
52 #define __HYPERVISOR_physdev_op 19
53 #define __HYPERVISOR_grant_table_op 20
54 #define __HYPERVISOR_vm_assist 21
55 #define __HYPERVISOR_update_va_mapping_otherdomain 22
56 #define __HYPERVISOR_switch_vm86 23 /* x86/32 only */
57 #define __HYPERVISOR_switch_to_user 23 /* x86/64 only */
58 #define __HYPERVISOR_boot_vcpu 24
59 #define __HYPERVISOR_set_segment_base 25 /* x86/64 only */
60 #define __HYPERVISOR_mmuext_op 26
61 #define __HYPERVISOR_acm_op 27
63 /*
64 * VIRTUAL INTERRUPTS
65 *
66 * Virtual interrupts that a guest OS may receive from Xen.
67 */
68 #define VIRQ_TIMER 0 /* Timebase update, and/or requested timeout. */
69 #define VIRQ_DEBUG 1 /* Request guest to dump debug info. */
70 #define VIRQ_CONSOLE 2 /* (DOM0) bytes received on emergency console. */
71 #define VIRQ_DOM_EXC 3 /* (DOM0) Exceptional event for some domain. */
72 #define VIRQ_PARITY_ERR 4 /* (DOM0) NMI parity error. */
73 #define VIRQ_IO_ERR 5 /* (DOM0) NMI I/O error. */
74 #define VIRQ_DEBUGGER 6 /* (DOM0) A domain has paused for debugging. */
75 #define NR_VIRQS 7
77 /*
78 * MMU-UPDATE REQUESTS
79 *
80 * HYPERVISOR_mmu_update() accepts a list of (ptr, val) pairs.
81 * A foreigndom (FD) can be specified (or DOMID_SELF for none).
82 * Where the FD has some effect, it is described below.
83 * ptr[1:0] specifies the appropriate MMU_* command.
84 *
85 * ptr[1:0] == MMU_NORMAL_PT_UPDATE:
86 * Updates an entry in a page table. If updating an L1 table, and the new
87 * table entry is valid/present, the mapped frame must belong to the FD, if
88 * an FD has been specified. If attempting to map an I/O page then the
89 * caller assumes the privilege of the FD.
90 * FD == DOMID_IO: Permit /only/ I/O mappings, at the priv level of the caller.
91 * FD == DOMID_XEN: Map restricted areas of Xen's heap space.
92 * ptr[:2] -- Machine address of the page-table entry to modify.
93 * val -- Value to write.
94 *
95 * ptr[1:0] == MMU_MACHPHYS_UPDATE:
96 * Updates an entry in the machine->pseudo-physical mapping table.
97 * ptr[:2] -- Machine address within the frame whose mapping to modify.
98 * The frame must belong to the FD, if one is specified.
99 * val -- Value to write into the mapping entry.
100 */
101 #define MMU_NORMAL_PT_UPDATE 0 /* checked '*ptr = val'. ptr is MA. */
102 #define MMU_MACHPHYS_UPDATE 1 /* ptr = MA of frame to modify entry for */
104 /*
105 * MMU EXTENDED OPERATIONS
106 *
107 * HYPERVISOR_mmuext_op() accepts a list of mmuext_op structures.
108 * A foreigndom (FD) can be specified (or DOMID_SELF for none).
109 * Where the FD has some effect, it is described below.
110 *
111 * cmd: MMUEXT_(UN)PIN_*_TABLE
112 * mfn: Machine frame number to be (un)pinned as a p.t. page.
113 * The frame must belong to the FD, if one is specified.
114 *
115 * cmd: MMUEXT_NEW_BASEPTR
116 * mfn: Machine frame number of new page-table base to install in MMU.
117 *
118 * cmd: MMUEXT_NEW_USER_BASEPTR [x86/64 only]
119 * mfn: Machine frame number of new page-table base to install in MMU
120 * when in user space.
121 *
122 * cmd: MMUEXT_TLB_FLUSH_LOCAL
123 * No additional arguments. Flushes local TLB.
124 *
125 * cmd: MMUEXT_INVLPG_LOCAL
126 * linear_addr: Linear address to be flushed from the local TLB.
127 *
128 * cmd: MMUEXT_TLB_FLUSH_MULTI
129 * vcpumask: Pointer to bitmap of VCPUs to be flushed.
130 *
131 * cmd: MMUEXT_INVLPG_MULTI
132 * linear_addr: Linear address to be flushed.
133 * vcpumask: Pointer to bitmap of VCPUs to be flushed.
134 *
135 * cmd: MMUEXT_TLB_FLUSH_ALL
136 * No additional arguments. Flushes all VCPUs' TLBs.
137 *
138 * cmd: MMUEXT_INVLPG_ALL
139 * linear_addr: Linear address to be flushed from all VCPUs' TLBs.
140 *
141 * cmd: MMUEXT_FLUSH_CACHE
142 * No additional arguments. Writes back and flushes cache contents.
143 *
144 * cmd: MMUEXT_SET_LDT
145 * linear_addr: Linear address of LDT base (NB. must be page-aligned).
146 * nr_ents: Number of entries in LDT.
147 *
148 * cmd: MMUEXT_REASSIGN_PAGE
149 * mfn: Machine frame number to be reassigned to the FD.
150 * (NB. page must currently belong to the calling domain).
151 */
152 #define MMUEXT_PIN_L1_TABLE 0
153 #define MMUEXT_PIN_L2_TABLE 1
154 #define MMUEXT_PIN_L3_TABLE 2
155 #define MMUEXT_PIN_L4_TABLE 3
156 #define MMUEXT_UNPIN_TABLE 4
157 #define MMUEXT_NEW_BASEPTR 5
158 #define MMUEXT_TLB_FLUSH_LOCAL 6
159 #define MMUEXT_INVLPG_LOCAL 7
160 #define MMUEXT_TLB_FLUSH_MULTI 8
161 #define MMUEXT_INVLPG_MULTI 9
162 #define MMUEXT_TLB_FLUSH_ALL 10
163 #define MMUEXT_INVLPG_ALL 11
164 #define MMUEXT_FLUSH_CACHE 12
165 #define MMUEXT_SET_LDT 13
166 #define MMUEXT_REASSIGN_PAGE 14
167 #define MMUEXT_NEW_USER_BASEPTR 15
169 #ifndef __ASSEMBLY__
170 struct mmuext_op {
171 unsigned int cmd;
172 union {
173 /* [UN]PIN_TABLE, NEW_BASEPTR, NEW_USER_BASEPTR, REASSIGN_PAGE */
174 unsigned long mfn;
175 /* INVLPG_LOCAL, INVLPG_ALL, SET_LDT */
176 unsigned long linear_addr;
177 };
178 union {
179 /* SET_LDT */
180 unsigned int nr_ents;
181 /* TLB_FLUSH_MULTI, INVLPG_MULTI */
182 void *vcpumask;
183 };
184 };
185 #endif
187 /* These are passed as 'flags' to update_va_mapping. They can be ORed. */
188 /* When specifying UVMF_MULTI, also OR in a pointer to a CPU bitmap. */
189 /* UVMF_LOCAL is merely UVMF_MULTI with a NULL bitmap pointer. */
190 #define UVMF_NONE (0UL<<0) /* No flushing at all. */
191 #define UVMF_TLB_FLUSH (1UL<<0) /* Flush entire TLB(s). */
192 #define UVMF_INVLPG (2UL<<0) /* Flush only one entry. */
193 #define UVMF_FLUSHTYPE_MASK (3UL<<0)
194 #define UVMF_MULTI (0UL<<2) /* Flush subset of TLBs. */
195 #define UVMF_LOCAL (0UL<<2) /* Flush local TLB. */
196 #define UVMF_ALL (1UL<<2) /* Flush all TLBs. */
198 /*
199 * Commands to HYPERVISOR_sched_op().
200 */
201 #define SCHEDOP_yield 0 /* Give up the CPU voluntarily. */
202 #define SCHEDOP_block 1 /* Block until an event is received. */
203 #define SCHEDOP_shutdown 2 /* Stop executing this domain. */
204 #define SCHEDOP_vcpu_down 3 /* make target VCPU not-runnable. */
205 #define SCHEDOP_vcpu_up 4 /* make target VCPU runnable. */
206 #define SCHEDOP_vcpu_pickle 5 /* save a vcpu's context to memory. */
207 #define SCHEDOP_cmdmask 255 /* 8-bit command. */
208 #define SCHEDOP_reasonshift 8 /* 8-bit reason code. (SCHEDOP_shutdown) */
209 #define SCHEDOP_vcpushift 8 /* 8-bit VCPU target. (SCHEDOP_up|down) */
211 /*
212 * Reason codes for SCHEDOP_shutdown. These may be interpreted by control
213 * software to determine the appropriate action. For the most part, Xen does
214 * not care about the shutdown code (SHUTDOWN_crash excepted).
215 */
216 #define SHUTDOWN_poweroff 0 /* Domain exited normally. Clean up and kill. */
217 #define SHUTDOWN_reboot 1 /* Clean up, kill, and then restart. */
218 #define SHUTDOWN_suspend 2 /* Clean up, save suspend info, kill. */
219 #define SHUTDOWN_crash 3 /* Tell controller we've crashed. */
221 /*
222 * Commands to HYPERVISOR_console_io().
223 */
224 #define CONSOLEIO_write 0
225 #define CONSOLEIO_read 1
227 /*
228 * Commands to HYPERVISOR_vm_assist().
229 */
230 #define VMASST_CMD_enable 0
231 #define VMASST_CMD_disable 1
232 #define VMASST_TYPE_4gb_segments 0
233 #define VMASST_TYPE_4gb_segments_notify 1
234 #define VMASST_TYPE_writable_pagetables 2
235 #define MAX_VMASST_TYPE 2
237 #ifndef __ASSEMBLY__
239 typedef u16 domid_t;
241 /* Domain ids >= DOMID_FIRST_RESERVED cannot be used for ordinary domains. */
242 #define DOMID_FIRST_RESERVED (0x7FF0U)
244 /* DOMID_SELF is used in certain contexts to refer to oneself. */
245 #define DOMID_SELF (0x7FF0U)
247 /*
248 * DOMID_IO is used to restrict page-table updates to mapping I/O memory.
249 * Although no Foreign Domain need be specified to map I/O pages, DOMID_IO
250 * is useful to ensure that no mappings to the OS's own heap are accidentally
251 * installed. (e.g., in Linux this could cause havoc as reference counts
252 * aren't adjusted on the I/O-mapping code path).
253 * This only makes sense in MMUEXT_SET_FOREIGNDOM, but in that context can
254 * be specified by any calling domain.
255 */
256 #define DOMID_IO (0x7FF1U)
258 /*
259 * DOMID_XEN is used to allow privileged domains to map restricted parts of
260 * Xen's heap space (e.g., the machine_to_phys table).
261 * This only makes sense in MMUEXT_SET_FOREIGNDOM, and is only permitted if
262 * the caller is privileged.
263 */
264 #define DOMID_XEN (0x7FF2U)
266 /*
267 * Send an array of these to HYPERVISOR_mmu_update().
268 * NB. The fields are natural pointer/address size for this architecture.
269 */
270 typedef struct
271 {
272 u64 ptr; /* Machine address of PTE. */
273 u64 val; /* New contents of PTE. */
274 } mmu_update_t;
276 /*
277 * Send an array of these to HYPERVISOR_multicall().
278 * NB. The fields are natural register size for this architecture.
279 */
280 typedef struct
281 {
282 unsigned long op, result;
283 unsigned long args[6];
284 } multicall_entry_t;
286 /* Event channel endpoints per domain. */
287 #define NR_EVENT_CHANNELS 1024
289 /*
290 * Per-VCPU information goes here. This will be cleaned up more when Xen
291 * actually supports multi-VCPU guests.
292 */
293 typedef struct vcpu_info {
294 /*
295 * 'evtchn_upcall_pending' is written non-zero by Xen to indicate
296 * a pending notification for a particular VCPU. It is then cleared
297 * by the guest OS /before/ checking for pending work, thus avoiding
298 * a set-and-check race. Note that the mask is only accessed by Xen
299 * on the CPU that is currently hosting the VCPU. This means that the
300 * pending and mask flags can be updated by the guest without special
301 * synchronisation (i.e., no need for the x86 LOCK prefix).
302 * This may seem suboptimal because if the pending flag is set by
303 * a different CPU then an IPI may be scheduled even when the mask
304 * is set. However, note:
305 * 1. The task of 'interrupt holdoff' is covered by the per-event-
306 * channel mask bits. A 'noisy' event that is continually being
307 * triggered can be masked at source at this very precise
308 * granularity.
309 * 2. The main purpose of the per-VCPU mask is therefore to restrict
310 * reentrant execution: whether for concurrency control, or to
311 * prevent unbounded stack usage. Whatever the purpose, we expect
312 * that the mask will be asserted only for short periods at a time,
313 * and so the likelihood of a 'spurious' IPI is suitably small.
314 * The mask is read before making an event upcall to the guest: a
315 * non-zero mask therefore guarantees that the VCPU will not receive
316 * an upcall activation. The mask is cleared when the VCPU requests
317 * to block: this avoids wakeup-waiting races.
318 */
319 u8 evtchn_upcall_pending;
320 u8 evtchn_upcall_mask;
321 u32 evtchn_pending_sel;
322 #ifdef __ARCH_HAS_VCPU_INFO
323 arch_vcpu_info_t arch;
324 #endif
325 } vcpu_info_t;
327 typedef struct vcpu_time_info {
328 /*
329 * Updates to the following values are preceded and followed by an
330 * increment of 'version'. The guest can therefore detect updates by
331 * looking for changes to 'version'. If the least-significant bit of
332 * the version number is set then an update is in progress and the guest
333 * must wait to read a consistent set of values.
334 * The correct way to interact with the version number is similar to
335 * Linux's seqlock: see the implementations of read_seqbegin/read_seqretry.
336 */
337 u32 version;
338 u64 tsc_timestamp; /* TSC at last update of time vals. */
339 u64 system_time; /* Time, in nanosecs, since boot. */
340 /*
341 * Current system time:
342 * system_time + ((tsc - tsc_timestamp) << tsc_shift) * tsc_to_system_mul
343 * CPU frequency (Hz):
344 * ((10^9 << 32) / tsc_to_system_mul) >> tsc_shift
345 */
346 u32 tsc_to_system_mul;
347 s8 tsc_shift;
348 } vcpu_time_info_t;
350 /*
351 * Xen/kernel shared data -- pointer provided in start_info.
352 * NB. We expect that this struct is smaller than a page.
353 */
354 typedef struct shared_info {
355 vcpu_info_t vcpu_data[MAX_VIRT_CPUS];
357 vcpu_time_info_t vcpu_time[MAX_VIRT_CPUS];
359 u32 n_vcpu;
361 /*
362 * A domain can have up to 1024 "event channels" on which it can send
363 * and receive asynchronous event notifications. There are three classes
364 * of event that are delivered by this mechanism:
365 * 1. Bi-directional inter- and intra-domain connections. Domains must
366 * arrange out-of-band to set up a connection (usually the setup
367 * is initiated and organised by a privileged third party such as
368 * software running in domain 0).
369 * 2. Physical interrupts. A domain with suitable hardware-access
370 * privileges can bind an event-channel port to a physical interrupt
371 * source.
372 * 3. Virtual interrupts ('events'). A domain can bind an event-channel
373 * port to a virtual interrupt source, such as the virtual-timer
374 * device or the emergency console.
375 *
376 * Event channels are addressed by a "port index" between 0 and 1023.
377 * Each channel is associated with two bits of information:
378 * 1. PENDING -- notifies the domain that there is a pending notification
379 * to be processed. This bit is cleared by the guest.
380 * 2. MASK -- if this bit is clear then a 0->1 transition of PENDING
381 * will cause an asynchronous upcall to be scheduled. This bit is only
382 * updated by the guest. It is read-only within Xen. If a channel
383 * becomes pending while the channel is masked then the 'edge' is lost
384 * (i.e., when the channel is unmasked, the guest must manually handle
385 * pending notifications as no upcall will be scheduled by Xen).
386 *
387 * To expedite scanning of pending notifications, any 0->1 pending
388 * transition on an unmasked channel causes a corresponding bit in a
389 * 32-bit selector to be set. Each bit in the selector covers a 32-bit
390 * word in the PENDING bitfield array.
391 */
392 u32 evtchn_pending[32];
393 u32 evtchn_mask[32];
395 /*
396 * Wallclock time: updated only by control software. Guests should base
397 * their gettimeofday() syscall on this wallclock-base value.
398 */
399 u32 wc_version; /* Version counter: see vcpu_time_info_t. */
400 u32 wc_sec; /* Secs 00:00:00 UTC, Jan 1, 1970. */
401 u32 wc_nsec; /* Nsecs 00:00:00 UTC, Jan 1, 1970. */
403 arch_shared_info_t arch;
405 } shared_info_t;
407 /*
408 * Start-of-day memory layout for the initial domain (DOM0):
409 * 1. The domain is started within contiguous virtual-memory region.
410 * 2. The contiguous region begins and ends on an aligned 4MB boundary.
411 * 3. The region start corresponds to the load address of the OS image.
412 * If the load address is not 4MB aligned then the address is rounded down.
413 * 4. This the order of bootstrap elements in the initial virtual region:
414 * a. relocated kernel image
415 * b. initial ram disk [mod_start, mod_len]
416 * c. list of allocated page frames [mfn_list, nr_pages]
417 * d. bootstrap page tables [pt_base, CR3 (x86)]
418 * e. start_info_t structure [register ESI (x86)]
419 * f. bootstrap stack [register ESP (x86)]
420 * 5. Bootstrap elements are packed together, but each is 4kB-aligned.
421 * 6. The initial ram disk may be omitted.
422 * 7. The list of page frames forms a contiguous 'pseudo-physical' memory
423 * layout for the domain. In particular, the bootstrap virtual-memory
424 * region is a 1:1 mapping to the first section of the pseudo-physical map.
425 * 8. All bootstrap elements are mapped read-writable for the guest OS. The
426 * only exception is the bootstrap page table, which is mapped read-only.
427 * 9. There is guaranteed to be at least 512kB padding after the final
428 * bootstrap element. If necessary, the bootstrap virtual region is
429 * extended by an extra 4MB to ensure this.
430 */
432 #define MAX_GUEST_CMDLINE 1024
433 typedef struct start_info {
434 /* THE FOLLOWING ARE FILLED IN BOTH ON INITIAL BOOT AND ON RESUME. */
435 unsigned long nr_pages; /* Total pages allocated to this domain. */
436 unsigned long shared_info; /* MACHINE address of shared info struct. */
437 u32 flags; /* SIF_xxx flags. */
438 unsigned long store_mfn; /* MACHINE page number of shared page. */
439 u16 store_evtchn; /* Event channel for store communication. */
440 unsigned long console_mfn; /* MACHINE address of console page. */
441 u16 console_evtchn; /* Event channel for console messages. */
442 /* THE FOLLOWING ARE ONLY FILLED IN ON INITIAL BOOT (NOT RESUME). */
443 unsigned long pt_base; /* VIRTUAL address of page directory. */
444 unsigned long nr_pt_frames; /* Number of bootstrap p.t. frames. */
445 unsigned long mfn_list; /* VIRTUAL address of page-frame list. */
446 unsigned long mod_start; /* VIRTUAL address of pre-loaded module. */
447 unsigned long mod_len; /* Size (bytes) of pre-loaded module. */
448 s8 cmd_line[MAX_GUEST_CMDLINE];
449 } start_info_t;
451 /* These flags are passed in the 'flags' field of start_info_t. */
452 #define SIF_PRIVILEGED (1<<0) /* Is the domain privileged? */
453 #define SIF_INITDOMAIN (1<<1) /* Is this the initial control domain? */
454 #define SIF_BLK_BE_DOMAIN (1<<4) /* Is this a block backend domain? */
455 #define SIF_NET_BE_DOMAIN (1<<5) /* Is this a net backend domain? */
456 #define SIF_USB_BE_DOMAIN (1<<6) /* Is this a usb backend domain? */
457 #define SIF_TPM_BE_DOMAIN (1<<7) /* Is this a TPM backend domain? */
458 /* For use in guest OSes. */
459 extern shared_info_t *HYPERVISOR_shared_info;
461 typedef u64 cpumap_t;
463 #endif /* !__ASSEMBLY__ */
465 #endif /* __XEN_PUBLIC_XEN_H__ */