This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / include / xen / interface / xen.h
1 /******************************************************************************
2  * xen.h
3  * 
4  * Guest OS interface to Xen.
5  * 
6  * Copyright (c) 2004, K A Fraser
7  */
8
9 #ifndef __XEN_PUBLIC_XEN_H__
10 #define __XEN_PUBLIC_XEN_H__
11
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 #elif defined(__powerpc__)
19 #include "arch-powerpc.h"
20 #else
21 #error "Unsupported architecture"
22 #endif
23
24 /*
25  * XEN "SYSTEM CALLS" (a.k.a. HYPERCALLS).
26  */
27
28 /*
29  * x86_32: EAX = vector; EBX, ECX, EDX, ESI, EDI = args 1, 2, 3, 4, 5.
30  *         EAX = return value
31  *         (argument registers may be clobbered on return)
32  * x86_64: RAX = vector; RDI, RSI, RDX, R10, R8, R9 = args 1, 2, 3, 4, 5, 6. 
33  *         RAX = return value
34  *         (argument registers not clobbered on return; RCX, R11 are)
35  */
36 #define __HYPERVISOR_set_trap_table        0
37 #define __HYPERVISOR_mmu_update            1
38 #define __HYPERVISOR_set_gdt               2
39 #define __HYPERVISOR_stack_switch          3
40 #define __HYPERVISOR_set_callbacks         4
41 #define __HYPERVISOR_fpu_taskswitch        5
42 #define __HYPERVISOR_sched_op_compat       6 /* compat since 0x00030101 */
43 #define __HYPERVISOR_dom0_op               7
44 #define __HYPERVISOR_set_debugreg          8
45 #define __HYPERVISOR_get_debugreg          9
46 #define __HYPERVISOR_update_descriptor    10
47 #define __HYPERVISOR_memory_op            12
48 #define __HYPERVISOR_multicall            13
49 #define __HYPERVISOR_update_va_mapping    14
50 #define __HYPERVISOR_set_timer_op         15
51 #define __HYPERVISOR_event_channel_op_compat 16 /* compat since 0x00030202 */
52 #define __HYPERVISOR_xen_version          17
53 #define __HYPERVISOR_console_io           18
54 #define __HYPERVISOR_physdev_op_compat    19 /* compat since 0x00030202 */
55 #define __HYPERVISOR_grant_table_op       20
56 #define __HYPERVISOR_vm_assist            21
57 #define __HYPERVISOR_update_va_mapping_otherdomain 22
58 #define __HYPERVISOR_iret                 23 /* x86 only */
59 #define __HYPERVISOR_vcpu_op              24
60 #define __HYPERVISOR_set_segment_base     25 /* x86/64 only */
61 #define __HYPERVISOR_mmuext_op            26
62 #define __HYPERVISOR_acm_op               27
63 #define __HYPERVISOR_nmi_op               28
64 #define __HYPERVISOR_sched_op             29
65 #define __HYPERVISOR_callback_op          30
66 #define __HYPERVISOR_xenoprof_op          31
67 #define __HYPERVISOR_event_channel_op     32
68 #define __HYPERVISOR_physdev_op           33
69 #define __HYPERVISOR_hvm_op               34
70
71 /* Architecture-specific hypercall definitions. */
72 #define __HYPERVISOR_arch_0               48
73 #define __HYPERVISOR_arch_1               49
74 #define __HYPERVISOR_arch_2               50
75 #define __HYPERVISOR_arch_3               51
76 #define __HYPERVISOR_arch_4               52
77 #define __HYPERVISOR_arch_5               53
78 #define __HYPERVISOR_arch_6               54
79 #define __HYPERVISOR_arch_7               55
80
81 /* 
82  * VIRTUAL INTERRUPTS
83  * 
84  * Virtual interrupts that a guest OS may receive from Xen.
85  * 
86  * In the side comments, 'V.' denotes a per-VCPU VIRQ while 'G.' denotes a
87  * global VIRQ. The former can be bound once per VCPU and cannot be re-bound.
88  * The latter can be allocated only once per guest: they must initially be
89  * allocated to VCPU0 but can subsequently be re-bound.
90  */
91 #define VIRQ_TIMER      0  /* V. Timebase update, and/or requested timeout.  */
92 #define VIRQ_DEBUG      1  /* V. Request guest to dump debug info.           */
93 #define VIRQ_CONSOLE    2  /* G. (DOM0) Bytes received on emergency console. */
94 #define VIRQ_DOM_EXC    3  /* G. (DOM0) Exceptional event for some domain.   */
95 #define VIRQ_TBUF       4  /* G. (DOM0) Trace buffer has records available.  */
96 #define VIRQ_DEBUGGER   6  /* G. (DOM0) A domain has paused for debugging.   */
97 #define VIRQ_XENOPROF   7  /* V. XenOprofile interrupt: new sample available */
98
99 /* Architecture-specific VIRQ definitions. */
100 #define VIRQ_ARCH_0    16
101 #define VIRQ_ARCH_1    17
102 #define VIRQ_ARCH_2    18
103 #define VIRQ_ARCH_3    19
104 #define VIRQ_ARCH_4    20
105 #define VIRQ_ARCH_5    21
106 #define VIRQ_ARCH_6    22
107 #define VIRQ_ARCH_7    23
108
109 #define NR_VIRQS       24
110
111 /*
112  * MMU-UPDATE REQUESTS
113  * 
114  * HYPERVISOR_mmu_update() accepts a list of (ptr, val) pairs.
115  * A foreigndom (FD) can be specified (or DOMID_SELF for none).
116  * Where the FD has some effect, it is described below.
117  * ptr[1:0] specifies the appropriate MMU_* command.
118  * 
119  * ptr[1:0] == MMU_NORMAL_PT_UPDATE:
120  * Updates an entry in a page table. If updating an L1 table, and the new
121  * table entry is valid/present, the mapped frame must belong to the FD, if
122  * an FD has been specified. If attempting to map an I/O page then the
123  * caller assumes the privilege of the FD.
124  * FD == DOMID_IO: Permit /only/ I/O mappings, at the priv level of the caller.
125  * FD == DOMID_XEN: Map restricted areas of Xen's heap space.
126  * ptr[:2]  -- Machine address of the page-table entry to modify.
127  * val      -- Value to write.
128  * 
129  * ptr[1:0] == MMU_MACHPHYS_UPDATE:
130  * Updates an entry in the machine->pseudo-physical mapping table.
131  * ptr[:2]  -- Machine address within the frame whose mapping to modify.
132  *             The frame must belong to the FD, if one is specified.
133  * val      -- Value to write into the mapping entry.
134  */
135 #define MMU_NORMAL_PT_UPDATE     0 /* checked '*ptr = val'. ptr is MA.       */
136 #define MMU_MACHPHYS_UPDATE      1 /* ptr = MA of frame to modify entry for  */
137
138 /*
139  * MMU EXTENDED OPERATIONS
140  * 
141  * HYPERVISOR_mmuext_op() accepts a list of mmuext_op structures.
142  * A foreigndom (FD) can be specified (or DOMID_SELF for none).
143  * Where the FD has some effect, it is described below.
144  * 
145  * cmd: MMUEXT_(UN)PIN_*_TABLE
146  * mfn: Machine frame number to be (un)pinned as a p.t. page.
147  *      The frame must belong to the FD, if one is specified.
148  * 
149  * cmd: MMUEXT_NEW_BASEPTR
150  * mfn: Machine frame number of new page-table base to install in MMU.
151  * 
152  * cmd: MMUEXT_NEW_USER_BASEPTR [x86/64 only]
153  * mfn: Machine frame number of new page-table base to install in MMU
154  *      when in user space.
155  * 
156  * cmd: MMUEXT_TLB_FLUSH_LOCAL
157  * No additional arguments. Flushes local TLB.
158  * 
159  * cmd: MMUEXT_INVLPG_LOCAL
160  * linear_addr: Linear address to be flushed from the local TLB.
161  * 
162  * cmd: MMUEXT_TLB_FLUSH_MULTI
163  * vcpumask: Pointer to bitmap of VCPUs to be flushed.
164  * 
165  * cmd: MMUEXT_INVLPG_MULTI
166  * linear_addr: Linear address to be flushed.
167  * vcpumask: Pointer to bitmap of VCPUs to be flushed.
168  * 
169  * cmd: MMUEXT_TLB_FLUSH_ALL
170  * No additional arguments. Flushes all VCPUs' TLBs.
171  * 
172  * cmd: MMUEXT_INVLPG_ALL
173  * linear_addr: Linear address to be flushed from all VCPUs' TLBs.
174  * 
175  * cmd: MMUEXT_FLUSH_CACHE
176  * No additional arguments. Writes back and flushes cache contents.
177  * 
178  * cmd: MMUEXT_SET_LDT
179  * linear_addr: Linear address of LDT base (NB. must be page-aligned).
180  * nr_ents: Number of entries in LDT.
181  */
182 #define MMUEXT_PIN_L1_TABLE      0
183 #define MMUEXT_PIN_L2_TABLE      1
184 #define MMUEXT_PIN_L3_TABLE      2
185 #define MMUEXT_PIN_L4_TABLE      3
186 #define MMUEXT_UNPIN_TABLE       4
187 #define MMUEXT_NEW_BASEPTR       5
188 #define MMUEXT_TLB_FLUSH_LOCAL   6
189 #define MMUEXT_INVLPG_LOCAL      7
190 #define MMUEXT_TLB_FLUSH_MULTI   8
191 #define MMUEXT_INVLPG_MULTI      9
192 #define MMUEXT_TLB_FLUSH_ALL    10
193 #define MMUEXT_INVLPG_ALL       11
194 #define MMUEXT_FLUSH_CACHE      12
195 #define MMUEXT_SET_LDT          13
196 #define MMUEXT_NEW_USER_BASEPTR 15
197
198 #ifndef __ASSEMBLY__
199 struct mmuext_op {
200     unsigned int cmd;
201     union {
202         /* [UN]PIN_TABLE, NEW_BASEPTR, NEW_USER_BASEPTR */
203         xen_pfn_t     mfn;
204         /* INVLPG_LOCAL, INVLPG_ALL, SET_LDT */
205         unsigned long linear_addr;
206     } arg1;
207     union {
208         /* SET_LDT */
209         unsigned int nr_ents;
210         /* TLB_FLUSH_MULTI, INVLPG_MULTI */
211         void *vcpumask;
212     } arg2;
213 };
214 typedef struct mmuext_op mmuext_op_t;
215 DEFINE_XEN_GUEST_HANDLE(mmuext_op_t);
216 #endif
217
218 /* These are passed as 'flags' to update_va_mapping. They can be ORed. */
219 /* When specifying UVMF_MULTI, also OR in a pointer to a CPU bitmap.   */
220 /* UVMF_LOCAL is merely UVMF_MULTI with a NULL bitmap pointer.         */
221 #define UVMF_NONE               (0UL<<0) /* No flushing at all.   */
222 #define UVMF_TLB_FLUSH          (1UL<<0) /* Flush entire TLB(s).  */
223 #define UVMF_INVLPG             (2UL<<0) /* Flush only one entry. */
224 #define UVMF_FLUSHTYPE_MASK     (3UL<<0)
225 #define UVMF_MULTI              (0UL<<2) /* Flush subset of TLBs. */
226 #define UVMF_LOCAL              (0UL<<2) /* Flush local TLB.      */
227 #define UVMF_ALL                (1UL<<2) /* Flush all TLBs.       */
228
229 /*
230  * Commands to HYPERVISOR_console_io().
231  */
232 #define CONSOLEIO_write         0
233 #define CONSOLEIO_read          1
234
235 /*
236  * Commands to HYPERVISOR_vm_assist().
237  */
238 #define VMASST_CMD_enable                0
239 #define VMASST_CMD_disable               1
240
241 /* x86/32 guests: simulate full 4GB segment limits. */
242 #define VMASST_TYPE_4gb_segments         0
243
244 /* x86/32 guests: trap (vector 15) whenever above vmassist is used. */
245 #define VMASST_TYPE_4gb_segments_notify  1
246
247 /*
248  * x86 guests: support writes to bottom-level PTEs.
249  * NB1. Page-directory entries cannot be written.
250  * NB2. Guest must continue to remove all writable mappings of PTEs.
251  */
252 #define VMASST_TYPE_writable_pagetables  2
253
254 /* x86/PAE guests: support PDPTs above 4GB. */
255 #define VMASST_TYPE_pae_extended_cr3     3
256
257 #define MAX_VMASST_TYPE                  3
258
259 #ifndef __ASSEMBLY__
260
261 typedef uint16_t domid_t;
262
263 /* Domain ids >= DOMID_FIRST_RESERVED cannot be used for ordinary domains. */
264 #define DOMID_FIRST_RESERVED (0x7FF0U)
265
266 /* DOMID_SELF is used in certain contexts to refer to oneself. */
267 #define DOMID_SELF (0x7FF0U)
268
269 /*
270  * DOMID_IO is used to restrict page-table updates to mapping I/O memory.
271  * Although no Foreign Domain need be specified to map I/O pages, DOMID_IO
272  * is useful to ensure that no mappings to the OS's own heap are accidentally
273  * installed. (e.g., in Linux this could cause havoc as reference counts
274  * aren't adjusted on the I/O-mapping code path).
275  * This only makes sense in MMUEXT_SET_FOREIGNDOM, but in that context can
276  * be specified by any calling domain.
277  */
278 #define DOMID_IO   (0x7FF1U)
279
280 /*
281  * DOMID_XEN is used to allow privileged domains to map restricted parts of
282  * Xen's heap space (e.g., the machine_to_phys table).
283  * This only makes sense in MMUEXT_SET_FOREIGNDOM, and is only permitted if
284  * the caller is privileged.
285  */
286 #define DOMID_XEN  (0x7FF2U)
287
288 /*
289  * Send an array of these to HYPERVISOR_mmu_update().
290  * NB. The fields are natural pointer/address size for this architecture.
291  */
292 struct mmu_update {
293     uint64_t ptr;       /* Machine address of PTE. */
294     uint64_t val;       /* New contents of PTE.    */
295 };
296 typedef struct mmu_update mmu_update_t;
297 DEFINE_XEN_GUEST_HANDLE(mmu_update_t);
298
299 /*
300  * Send an array of these to HYPERVISOR_multicall().
301  * NB. The fields are natural register size for this architecture.
302  */
303 struct multicall_entry {
304     unsigned long op, result;
305     unsigned long args[6];
306 };
307 typedef struct multicall_entry multicall_entry_t;
308 DEFINE_XEN_GUEST_HANDLE(multicall_entry_t);
309
310 /*
311  * Event channel endpoints per domain:
312  *  1024 if a long is 32 bits; 4096 if a long is 64 bits.
313  */
314 #define NR_EVENT_CHANNELS (sizeof(unsigned long) * sizeof(unsigned long) * 64)
315
316 struct vcpu_time_info {
317     /*
318      * Updates to the following values are preceded and followed by an
319      * increment of 'version'. The guest can therefore detect updates by
320      * looking for changes to 'version'. If the least-significant bit of
321      * the version number is set then an update is in progress and the guest
322      * must wait to read a consistent set of values.
323      * The correct way to interact with the version number is similar to
324      * Linux's seqlock: see the implementations of read_seqbegin/read_seqretry.
325      */
326     uint32_t version;
327     uint32_t pad0;
328     uint64_t tsc_timestamp;   /* TSC at last update of time vals.  */
329     uint64_t system_time;     /* Time, in nanosecs, since boot.    */
330     /*
331      * Current system time:
332      *   system_time +
333      *   ((((tsc - tsc_timestamp) << tsc_shift) * tsc_to_system_mul) >> 32)
334      * CPU frequency (Hz):
335      *   ((10^9 << 32) / tsc_to_system_mul) >> tsc_shift
336      */
337     uint32_t tsc_to_system_mul;
338     int8_t   tsc_shift;
339     int8_t   pad1[3];
340 }; /* 32 bytes */
341 typedef struct vcpu_time_info vcpu_time_info_t;
342
343 struct vcpu_info {
344     /*
345      * 'evtchn_upcall_pending' is written non-zero by Xen to indicate
346      * a pending notification for a particular VCPU. It is then cleared 
347      * by the guest OS /before/ checking for pending work, thus avoiding
348      * a set-and-check race. Note that the mask is only accessed by Xen
349      * on the CPU that is currently hosting the VCPU. This means that the
350      * pending and mask flags can be updated by the guest without special
351      * synchronisation (i.e., no need for the x86 LOCK prefix).
352      * This may seem suboptimal because if the pending flag is set by
353      * a different CPU then an IPI may be scheduled even when the mask
354      * is set. However, note:
355      *  1. The task of 'interrupt holdoff' is covered by the per-event-
356      *     channel mask bits. A 'noisy' event that is continually being
357      *     triggered can be masked at source at this very precise
358      *     granularity.
359      *  2. The main purpose of the per-VCPU mask is therefore to restrict
360      *     reentrant execution: whether for concurrency control, or to
361      *     prevent unbounded stack usage. Whatever the purpose, we expect
362      *     that the mask will be asserted only for short periods at a time,
363      *     and so the likelihood of a 'spurious' IPI is suitably small.
364      * The mask is read before making an event upcall to the guest: a
365      * non-zero mask therefore guarantees that the VCPU will not receive
366      * an upcall activation. The mask is cleared when the VCPU requests
367      * to block: this avoids wakeup-waiting races.
368      */
369     uint8_t evtchn_upcall_pending;
370     uint8_t evtchn_upcall_mask;
371     unsigned long evtchn_pending_sel;
372     struct arch_vcpu_info arch;
373     struct vcpu_time_info time;
374 }; /* 64 bytes (x86) */
375 typedef struct vcpu_info vcpu_info_t;
376
377 /*
378  * Xen/kernel shared data -- pointer provided in start_info.
379  *
380  * This structure is defined to be both smaller than a page, and the
381  * only data on the shared page, but may vary in actual size even within
382  * compatible Xen versions; guests should not rely on the size
383  * of this structure remaining constant.
384  */
385 struct shared_info {
386     struct vcpu_info vcpu_info[MAX_VIRT_CPUS];
387
388     /*
389      * A domain can create "event channels" on which it can send and receive
390      * asynchronous event notifications. There are three classes of event that
391      * are delivered by this mechanism:
392      *  1. Bi-directional inter- and intra-domain connections. Domains must
393      *     arrange out-of-band to set up a connection (usually by allocating
394      *     an unbound 'listener' port and avertising that via a storage service
395      *     such as xenstore).
396      *  2. Physical interrupts. A domain with suitable hardware-access
397      *     privileges can bind an event-channel port to a physical interrupt
398      *     source.
399      *  3. Virtual interrupts ('events'). A domain can bind an event-channel
400      *     port to a virtual interrupt source, such as the virtual-timer
401      *     device or the emergency console.
402      * 
403      * Event channels are addressed by a "port index". Each channel is
404      * associated with two bits of information:
405      *  1. PENDING -- notifies the domain that there is a pending notification
406      *     to be processed. This bit is cleared by the guest.
407      *  2. MASK -- if this bit is clear then a 0->1 transition of PENDING
408      *     will cause an asynchronous upcall to be scheduled. This bit is only
409      *     updated by the guest. It is read-only within Xen. If a channel
410      *     becomes pending while the channel is masked then the 'edge' is lost
411      *     (i.e., when the channel is unmasked, the guest must manually handle
412      *     pending notifications as no upcall will be scheduled by Xen).
413      * 
414      * To expedite scanning of pending notifications, any 0->1 pending
415      * transition on an unmasked channel causes a corresponding bit in a
416      * per-vcpu selector word to be set. Each bit in the selector covers a
417      * 'C long' in the PENDING bitfield array.
418      */
419     unsigned long evtchn_pending[sizeof(unsigned long) * 8];
420     unsigned long evtchn_mask[sizeof(unsigned long) * 8];
421
422     /*
423      * Wallclock time: updated only by control software. Guests should base
424      * their gettimeofday() syscall on this wallclock-base value.
425      */
426     uint32_t wc_version;      /* Version counter: see vcpu_time_info_t. */
427     uint32_t wc_sec;          /* Secs  00:00:00 UTC, Jan 1, 1970.  */
428     uint32_t wc_nsec;         /* Nsecs 00:00:00 UTC, Jan 1, 1970.  */
429
430     struct arch_shared_info arch;
431
432 };
433 typedef struct shared_info shared_info_t;
434
435 /*
436  * Start-of-day memory layout for the initial domain (DOM0):
437  *  1. The domain is started within contiguous virtual-memory region.
438  *  2. The contiguous region begins and ends on an aligned 4MB boundary.
439  *  3. The region start corresponds to the load address of the OS image.
440  *     If the load address is not 4MB aligned then the address is rounded down.
441  *  4. This the order of bootstrap elements in the initial virtual region:
442  *      a. relocated kernel image
443  *      b. initial ram disk              [mod_start, mod_len]
444  *      c. list of allocated page frames [mfn_list, nr_pages]
445  *      d. start_info_t structure        [register ESI (x86)]
446  *      e. bootstrap page tables         [pt_base, CR3 (x86)]
447  *      f. bootstrap stack               [register ESP (x86)]
448  *  5. Bootstrap elements are packed together, but each is 4kB-aligned.
449  *  6. The initial ram disk may be omitted.
450  *  7. The list of page frames forms a contiguous 'pseudo-physical' memory
451  *     layout for the domain. In particular, the bootstrap virtual-memory
452  *     region is a 1:1 mapping to the first section of the pseudo-physical map.
453  *  8. All bootstrap elements are mapped read-writable for the guest OS. The
454  *     only exception is the bootstrap page table, which is mapped read-only.
455  *  9. There is guaranteed to be at least 512kB padding after the final
456  *     bootstrap element. If necessary, the bootstrap virtual region is
457  *     extended by an extra 4MB to ensure this.
458  */
459
460 #define MAX_GUEST_CMDLINE 1024
461 struct start_info {
462     /* THE FOLLOWING ARE FILLED IN BOTH ON INITIAL BOOT AND ON RESUME.    */
463     char magic[32];             /* "xen-<version>-<platform>".            */
464     unsigned long nr_pages;     /* Total pages allocated to this domain.  */
465     unsigned long shared_info;  /* MACHINE address of shared info struct. */
466     uint32_t flags;             /* SIF_xxx flags.                         */
467     xen_pfn_t store_mfn;        /* MACHINE page number of shared page.    */
468     uint32_t store_evtchn;      /* Event channel for store communication. */
469     xen_pfn_t console_mfn;      /* MACHINE page number of console page.   */
470     uint32_t console_evtchn;    /* Event channel for console messages.    */
471     /* THE FOLLOWING ARE ONLY FILLED IN ON INITIAL BOOT (NOT RESUME).     */
472     unsigned long pt_base;      /* VIRTUAL address of page directory.     */
473     unsigned long nr_pt_frames; /* Number of bootstrap p.t. frames.       */
474     unsigned long mfn_list;     /* VIRTUAL address of page-frame list.    */
475     unsigned long mod_start;    /* VIRTUAL address of pre-loaded module.  */
476     unsigned long mod_len;      /* Size (bytes) of pre-loaded module.     */
477     int8_t cmd_line[MAX_GUEST_CMDLINE];
478 };
479 typedef struct start_info start_info_t;
480
481 /* These flags are passed in the 'flags' field of start_info_t. */
482 #define SIF_PRIVILEGED    (1<<0)  /* Is the domain privileged? */
483 #define SIF_INITDOMAIN    (1<<1)  /* Is this the initial control domain? */
484
485 typedef uint64_t cpumap_t;
486
487 typedef uint8_t xen_domain_handle_t[16];
488
489 /* Turn a plain number into a C unsigned long constant. */
490 #define __mk_unsigned_long(x) x ## UL
491 #define mk_unsigned_long(x) __mk_unsigned_long(x)
492
493 #else /* __ASSEMBLY__ */
494
495 /* In assembly code we cannot use C numeric constant suffixes. */
496 #define mk_unsigned_long(x) x
497
498 #endif /* !__ASSEMBLY__ */
499
500 #include "xen-compat.h"
501
502 #endif /* __XEN_PUBLIC_XEN_H__ */
503
504 /*
505  * Local variables:
506  * mode: C
507  * c-set-style: "BSD"
508  * c-basic-offset: 4
509  * tab-width: 4
510  * indent-tabs-mode: nil
511  * End:
512  */