ia64/xen-unstable

view xen/include/public/xen.h @ 6316:f7dfaa2af90c

merge?
author cl349@firebug.cl.cam.ac.uk
date Sun Aug 21 11:02:00 2005 +0000 (2005-08-21)
parents 1872e09bfba3
children 6721abf6b16d
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_dom_mem_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_dom_mem_op().
229 */
230 #define MEMOP_increase_reservation 0
231 #define MEMOP_decrease_reservation 1
233 /*
234 * Commands to HYPERVISOR_vm_assist().
235 */
236 #define VMASST_CMD_enable 0
237 #define VMASST_CMD_disable 1
238 #define VMASST_TYPE_4gb_segments 0
239 #define VMASST_TYPE_4gb_segments_notify 1
240 #define VMASST_TYPE_writable_pagetables 2
241 #define MAX_VMASST_TYPE 2
243 #ifndef __ASSEMBLY__
245 typedef u16 domid_t;
247 /* Domain ids >= DOMID_FIRST_RESERVED cannot be used for ordinary domains. */
248 #define DOMID_FIRST_RESERVED (0x7FF0U)
250 /* DOMID_SELF is used in certain contexts to refer to oneself. */
251 #define DOMID_SELF (0x7FF0U)
253 /*
254 * DOMID_IO is used to restrict page-table updates to mapping I/O memory.
255 * Although no Foreign Domain need be specified to map I/O pages, DOMID_IO
256 * is useful to ensure that no mappings to the OS's own heap are accidentally
257 * installed. (e.g., in Linux this could cause havoc as reference counts
258 * aren't adjusted on the I/O-mapping code path).
259 * This only makes sense in MMUEXT_SET_FOREIGNDOM, but in that context can
260 * be specified by any calling domain.
261 */
262 #define DOMID_IO (0x7FF1U)
264 /*
265 * DOMID_XEN is used to allow privileged domains to map restricted parts of
266 * Xen's heap space (e.g., the machine_to_phys table).
267 * This only makes sense in MMUEXT_SET_FOREIGNDOM, and is only permitted if
268 * the caller is privileged.
269 */
270 #define DOMID_XEN (0x7FF2U)
272 /*
273 * Send an array of these to HYPERVISOR_mmu_update().
274 * NB. The fields are natural pointer/address size for this architecture.
275 */
276 typedef struct
277 {
278 u64 ptr; /* Machine address of PTE. */
279 u64 val; /* New contents of PTE. */
280 } mmu_update_t;
282 /*
283 * Send an array of these to HYPERVISOR_multicall().
284 * NB. The fields are natural register size for this architecture.
285 */
286 typedef struct
287 {
288 unsigned long op, result;
289 unsigned long args[6];
290 } multicall_entry_t;
292 /* Event channel endpoints per domain. */
293 #define NR_EVENT_CHANNELS 1024
295 /*
296 * Per-VCPU information goes here. This will be cleaned up more when Xen
297 * actually supports multi-VCPU guests.
298 */
299 typedef struct vcpu_info {
300 /*
301 * 'evtchn_upcall_pending' is written non-zero by Xen to indicate
302 * a pending notification for a particular VCPU. It is then cleared
303 * by the guest OS /before/ checking for pending work, thus avoiding
304 * a set-and-check race. Note that the mask is only accessed by Xen
305 * on the CPU that is currently hosting the VCPU. This means that the
306 * pending and mask flags can be updated by the guest without special
307 * synchronisation (i.e., no need for the x86 LOCK prefix).
308 * This may seem suboptimal because if the pending flag is set by
309 * a different CPU then an IPI may be scheduled even when the mask
310 * is set. However, note:
311 * 1. The task of 'interrupt holdoff' is covered by the per-event-
312 * channel mask bits. A 'noisy' event that is continually being
313 * triggered can be masked at source at this very precise
314 * granularity.
315 * 2. The main purpose of the per-VCPU mask is therefore to restrict
316 * reentrant execution: whether for concurrency control, or to
317 * prevent unbounded stack usage. Whatever the purpose, we expect
318 * that the mask will be asserted only for short periods at a time,
319 * and so the likelihood of a 'spurious' IPI is suitably small.
320 * The mask is read before making an event upcall to the guest: a
321 * non-zero mask therefore guarantees that the VCPU will not receive
322 * an upcall activation. The mask is cleared when the VCPU requests
323 * to block: this avoids wakeup-waiting races.
324 */
325 u8 evtchn_upcall_pending;
326 u8 evtchn_upcall_mask;
327 u32 evtchn_pending_sel;
328 #ifdef __ARCH_HAS_VCPU_INFO
329 arch_vcpu_info_t arch;
330 #endif
331 } vcpu_info_t;
333 typedef struct vcpu_time_info {
334 /*
335 * Updates to the following values are preceded and followed by an
336 * increment of 'version'. The guest can therefore detect updates by
337 * looking for changes to 'version'. If the least-significant bit of
338 * the version number is set then an update is in progress and the guest
339 * must wait to read a consistent set of values.
340 * The correct way to interact with the version number is similar to
341 * Linux's seqlock: see the implementations of read_seqbegin/read_seqretry.
342 */
343 u32 version;
344 u64 tsc_timestamp; /* TSC at last update of time vals. */
345 u64 system_time; /* Time, in nanosecs, since boot. */
346 /*
347 * Current system time:
348 * system_time + ((tsc - tsc_timestamp) << tsc_shift) * tsc_to_system_mul
349 * CPU frequency (Hz):
350 * ((10^9 << 32) / tsc_to_system_mul) >> tsc_shift
351 */
352 u32 tsc_to_system_mul;
353 s8 tsc_shift;
354 } vcpu_time_info_t;
356 /*
357 * Xen/kernel shared data -- pointer provided in start_info.
358 * NB. We expect that this struct is smaller than a page.
359 */
360 typedef struct shared_info {
361 vcpu_info_t vcpu_data[MAX_VIRT_CPUS];
363 vcpu_time_info_t vcpu_time[MAX_VIRT_CPUS];
365 u32 n_vcpu;
367 /*
368 * A domain can have up to 1024 "event channels" on which it can send
369 * and receive asynchronous event notifications. There are three classes
370 * of event that are delivered by this mechanism:
371 * 1. Bi-directional inter- and intra-domain connections. Domains must
372 * arrange out-of-band to set up a connection (usually the setup
373 * is initiated and organised by a privileged third party such as
374 * software running in domain 0).
375 * 2. Physical interrupts. A domain with suitable hardware-access
376 * privileges can bind an event-channel port to a physical interrupt
377 * source.
378 * 3. Virtual interrupts ('events'). A domain can bind an event-channel
379 * port to a virtual interrupt source, such as the virtual-timer
380 * device or the emergency console.
381 *
382 * Event channels are addressed by a "port index" between 0 and 1023.
383 * Each channel is associated with two bits of information:
384 * 1. PENDING -- notifies the domain that there is a pending notification
385 * to be processed. This bit is cleared by the guest.
386 * 2. MASK -- if this bit is clear then a 0->1 transition of PENDING
387 * will cause an asynchronous upcall to be scheduled. This bit is only
388 * updated by the guest. It is read-only within Xen. If a channel
389 * becomes pending while the channel is masked then the 'edge' is lost
390 * (i.e., when the channel is unmasked, the guest must manually handle
391 * pending notifications as no upcall will be scheduled by Xen).
392 *
393 * To expedite scanning of pending notifications, any 0->1 pending
394 * transition on an unmasked channel causes a corresponding bit in a
395 * 32-bit selector to be set. Each bit in the selector covers a 32-bit
396 * word in the PENDING bitfield array.
397 */
398 u32 evtchn_pending[32];
399 u32 evtchn_mask[32];
401 /*
402 * Wallclock time: updated only by control software. Guests should base
403 * their gettimeofday() syscall on this wallclock-base value.
404 */
405 u32 wc_version; /* Version counter: see vcpu_time_info_t. */
406 u32 wc_sec; /* Secs 00:00:00 UTC, Jan 1, 1970. */
407 u32 wc_nsec; /* Nsecs 00:00:00 UTC, Jan 1, 1970. */
409 arch_shared_info_t arch;
411 } shared_info_t;
413 /*
414 * Start-of-day memory layout for the initial domain (DOM0):
415 * 1. The domain is started within contiguous virtual-memory region.
416 * 2. The contiguous region begins and ends on an aligned 4MB boundary.
417 * 3. The region start corresponds to the load address of the OS image.
418 * If the load address is not 4MB aligned then the address is rounded down.
419 * 4. This the order of bootstrap elements in the initial virtual region:
420 * a. relocated kernel image
421 * b. initial ram disk [mod_start, mod_len]
422 * c. list of allocated page frames [mfn_list, nr_pages]
423 * d. bootstrap page tables [pt_base, CR3 (x86)]
424 * e. start_info_t structure [register ESI (x86)]
425 * f. bootstrap stack [register ESP (x86)]
426 * 5. Bootstrap elements are packed together, but each is 4kB-aligned.
427 * 6. The initial ram disk may be omitted.
428 * 7. The list of page frames forms a contiguous 'pseudo-physical' memory
429 * layout for the domain. In particular, the bootstrap virtual-memory
430 * region is a 1:1 mapping to the first section of the pseudo-physical map.
431 * 8. All bootstrap elements are mapped read-writable for the guest OS. The
432 * only exception is the bootstrap page table, which is mapped read-only.
433 * 9. There is guaranteed to be at least 512kB padding after the final
434 * bootstrap element. If necessary, the bootstrap virtual region is
435 * extended by an extra 4MB to ensure this.
436 */
438 #define MAX_GUEST_CMDLINE 1024
439 typedef struct start_info {
440 /* THE FOLLOWING ARE FILLED IN BOTH ON INITIAL BOOT AND ON RESUME. */
441 unsigned long nr_pages; /* Total pages allocated to this domain. */
442 unsigned long shared_info;/* MACHINE address of shared info struct. */
443 u32 flags; /* SIF_xxx flags. */
444 u16 domain_controller_evtchn;
445 /* THE FOLLOWING ARE ONLY FILLED IN ON INITIAL BOOT (NOT RESUME). */
446 unsigned long pt_base; /* VIRTUAL address of page directory. */
447 unsigned long nr_pt_frames;/* Number of bootstrap p.t. frames. */
448 unsigned long mfn_list; /* VIRTUAL address of page-frame list. */
449 unsigned long mod_start; /* VIRTUAL address of pre-loaded module. */
450 unsigned long mod_len; /* Size (bytes) of pre-loaded module. */
451 s8 cmd_line[MAX_GUEST_CMDLINE];
452 unsigned long store_mfn; /* MACHINE page number of shared page. */
453 u16 store_evtchn; /* Event channel for store communication. */
454 } start_info_t;
456 /* These flags are passed in the 'flags' field of start_info_t. */
457 #define SIF_PRIVILEGED (1<<0) /* Is the domain privileged? */
458 #define SIF_INITDOMAIN (1<<1) /* Is this the initial control domain? */
459 #define SIF_BLK_BE_DOMAIN (1<<4) /* Is this a block backend domain? */
460 #define SIF_NET_BE_DOMAIN (1<<5) /* Is this a net backend domain? */
461 #define SIF_USB_BE_DOMAIN (1<<6) /* Is this a usb backend domain? */
462 /* For use in guest OSes. */
463 extern shared_info_t *HYPERVISOR_shared_info;
465 typedef u64 cpumap_t;
467 #endif /* !__ASSEMBLY__ */
469 #endif /* __XEN_PUBLIC_XEN_H__ */