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