debuggers.hg

view xen/include/public/xen.h @ 3337:cd90fe329149

bitkeeper revision 1.1159.206.1 (41c1bb28OOf2b0kzcmnY96TsE1LXVA)

Merge arcadians.cl.cam.ac.uk:/auto/groups/xeno/BK/xen-unstable.bk
into arcadians.cl.cam.ac.uk:/auto/groups/xeno/users/cl349/BK/xen-unstable.bk
author cl349@arcadians.cl.cam.ac.uk
date Thu Dec 16 16:43:20 2004 +0000 (2004-12-16)
parents fd0d4d8e6193 53a0cc27ab17
children 3609a4de4be5
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 #ifndef PACKED
13 /* GCC-specific way to pack structure definitions (no implicit padding). */
14 #define PACKED __attribute__ ((packed))
15 #endif
17 #if defined(__i386__)
18 #include "arch-x86_32.h"
19 #elif defined(__x86_64__)
20 #include "arch-x86_64.h"
21 #else
22 #error "Unsupported architecture"
23 #endif
25 /*
26 * XEN "SYSTEM CALLS" (a.k.a. HYPERCALLS).
27 */
29 /* EAX = vector; EBX, ECX, EDX, ESI, EDI = args 1, 2, 3, 4, 5. */
30 #define __HYPERVISOR_set_trap_table 0
31 #define __HYPERVISOR_mmu_update 1
32 #define __HYPERVISOR_set_gdt 2
33 #define __HYPERVISOR_stack_switch 3
34 #define __HYPERVISOR_set_callbacks 4
35 #define __HYPERVISOR_fpu_taskswitch 5
36 #define __HYPERVISOR_sched_op 6
37 #define __HYPERVISOR_dom0_op 7
38 #define __HYPERVISOR_set_debugreg 8
39 #define __HYPERVISOR_get_debugreg 9
40 #define __HYPERVISOR_update_descriptor 10
41 #define __HYPERVISOR_set_fast_trap 11
42 #define __HYPERVISOR_dom_mem_op 12
43 #define __HYPERVISOR_multicall 13
44 #define __HYPERVISOR_update_va_mapping 14
45 #define __HYPERVISOR_set_timer_op 15
46 #define __HYPERVISOR_event_channel_op 16
47 #define __HYPERVISOR_xen_version 17
48 #define __HYPERVISOR_console_io 18
49 #define __HYPERVISOR_physdev_op 19
50 #define __HYPERVISOR_grant_table_op 20
51 #define __HYPERVISOR_vm_assist 21
52 #define __HYPERVISOR_update_va_mapping_otherdomain 22
53 #define __HYPERVISOR_switch_vm86 23
54 #define __HYPERVISOR_boot_vcpu 24
56 /*
57 * MULTICALLS
58 *
59 * Multicalls are listed in an array, with each element being a fixed size
60 * (BYTES_PER_MULTICALL_ENTRY). Each is of the form (op, arg1, ..., argN)
61 * where each element of the tuple is a machine word.
62 */
63 #define ARGS_PER_MULTICALL_ENTRY 8
66 /*
67 * VIRTUAL INTERRUPTS
68 *
69 * Virtual interrupts that a guest OS may receive from Xen.
70 */
71 #define VIRQ_TIMER 0 /* Timebase update, and/or requested timeout. */
72 #define VIRQ_DEBUG 1 /* Request guest to dump debug info. */
73 #define VIRQ_CONSOLE 2 /* (DOM0) bytes received on emergency console. */
74 #define VIRQ_DOM_EXC 3 /* (DOM0) Exceptional event for some domain. */
75 #define VIRQ_PARITY_ERR 4 /* (DOM0) NMI parity error. */
76 #define VIRQ_IO_ERR 5 /* (DOM0) NMI I/O error. */
77 #define NR_VIRQS 7
79 /*
80 * MMU-UPDATE REQUESTS
81 *
82 * HYPERVISOR_mmu_update() accepts a list of (ptr, val) pairs.
83 * ptr[1:0] specifies the appropriate MMU_* command.
84 *
85 * FOREIGN DOMAIN (FD)
86 * -------------------
87 * Some commands recognise an explicitly-declared foreign domain,
88 * in which case they will operate with respect to the foreigner rather than
89 * the calling domain. Where the FD has some effect, it is described below.
90 *
91 * ptr[1:0] == MMU_NORMAL_PT_UPDATE:
92 * Updates an entry in a page table. If updating an L1 table, and the new
93 * table entry is valid/present, the mapped frame must belong to the FD, if
94 * an FD has been specified. If attempting to map an I/O page then the
95 * caller assumes the privilege of the FD.
96 * FD == DOMID_IO: Permit /only/ I/O mappings, at the priv level of the caller.
97 * FD == DOMID_XEN: Map restricted areas of Xen's heap space.
98 * ptr[:2] -- Machine address of the page-table entry to modify.
99 * val -- Value to write.
100 *
101 * ptr[1:0] == MMU_MACHPHYS_UPDATE:
102 * Updates an entry in the machine->pseudo-physical mapping table.
103 * ptr[:2] -- Machine address within the frame whose mapping to modify.
104 * The frame must belong to the FD, if one is specified.
105 * val -- Value to write into the mapping entry.
106 *
107 * ptr[1:0] == MMU_EXTENDED_COMMAND:
108 * val[7:0] -- MMUEXT_* command.
109 *
110 * val[7:0] == MMUEXT_(UN)PIN_*_TABLE:
111 * ptr[:2] -- Machine address of frame to be (un)pinned as a p.t. page.
112 * The frame must belong to the FD, if one is specified.
113 *
114 * val[7:0] == MMUEXT_NEW_BASEPTR:
115 * ptr[:2] -- Machine address of new page-table base to install in MMU.
116 *
117 * val[7:0] == MMUEXT_TLB_FLUSH:
118 * No additional arguments.
119 *
120 * val[7:0] == MMUEXT_INVLPG:
121 * ptr[:2] -- Linear address to be flushed from the TLB.
122 *
123 * val[7:0] == MMUEXT_FLUSH_CACHE:
124 * No additional arguments. Writes back and flushes cache contents.
125 *
126 * val[7:0] == MMUEXT_SET_LDT:
127 * ptr[:2] -- Linear address of LDT base (NB. must be page-aligned).
128 * val[:8] -- Number of entries in LDT.
129 *
130 * val[7:0] == MMUEXT_TRANSFER_PAGE:
131 * val[31:16] -- Domain to whom page is to be transferred.
132 * (val[15:8],ptr[9:2]) -- 16-bit reference into transferee's grant table.
133 * ptr[:12] -- Page frame to be reassigned to the FD.
134 * (NB. The frame must currently belong to the calling domain).
135 *
136 * val[7:0] == MMUEXT_SET_FOREIGNDOM:
137 * val[31:16] -- Domain to set as the Foreign Domain (FD).
138 * (NB. DOMID_SELF is not recognised)
139 * If FD != DOMID_IO then the caller must be privileged.
140 *
141 * val[7:0] == MMUEXT_CLEAR_FOREIGNDOM:
142 * Clears the FD.
143 *
144 * val[7:0] == MMUEXT_REASSIGN_PAGE:
145 * ptr[:2] -- A machine address within the page to be reassigned to the FD.
146 * (NB. page must currently belong to the calling domain).
147 */
148 #define MMU_NORMAL_PT_UPDATE 0 /* checked '*ptr = val'. ptr is MA. */
149 #define MMU_MACHPHYS_UPDATE 2 /* ptr = MA of frame to modify entry for */
150 #define MMU_EXTENDED_COMMAND 3 /* least 8 bits of val demux further */
151 #define MMUEXT_PIN_L1_TABLE 0 /* ptr = MA of frame to pin */
152 #define MMUEXT_PIN_L2_TABLE 1 /* ptr = MA of frame to pin */
153 #define MMUEXT_PIN_L3_TABLE 2 /* ptr = MA of frame to pin */
154 #define MMUEXT_PIN_L4_TABLE 3 /* ptr = MA of frame to pin */
155 #define MMUEXT_UNPIN_TABLE 4 /* ptr = MA of frame to unpin */
156 #define MMUEXT_NEW_BASEPTR 5 /* ptr = MA of new pagetable base */
157 #define MMUEXT_TLB_FLUSH 6 /* ptr = NULL */
158 #define MMUEXT_INVLPG 7 /* ptr = VA to invalidate */
159 #define MMUEXT_FLUSH_CACHE 8
160 #define MMUEXT_SET_LDT 9 /* ptr = VA of table; val = # entries */
161 #define MMUEXT_SET_FOREIGNDOM 10 /* val[31:16] = dom */
162 #define MMUEXT_CLEAR_FOREIGNDOM 11
163 #define MMUEXT_TRANSFER_PAGE 12 /* ptr = MA of frame; val[31:16] = dom */
164 #define MMUEXT_REASSIGN_PAGE 13
165 #define MMUEXT_CMD_MASK 255
166 #define MMUEXT_CMD_SHIFT 8
168 /* These are passed as 'flags' to update_va_mapping. They can be ORed. */
169 #define UVMF_FLUSH_TLB 1 /* Flush entire TLB. */
170 #define UVMF_INVLPG 2 /* Flush the VA mapping being updated. */
173 /*
174 * Commands to HYPERVISOR_sched_op().
175 */
176 #define SCHEDOP_yield 0 /* Give up the CPU voluntarily. */
177 #define SCHEDOP_block 1 /* Block until an event is received. */
178 #define SCHEDOP_shutdown 2 /* Stop executing this domain. */
179 #define SCHEDOP_cmdmask 255 /* 8-bit command. */
180 #define SCHEDOP_reasonshift 8 /* 8-bit reason code. (SCHEDOP_shutdown) */
182 /*
183 * Commands to HYPERVISOR_console_io().
184 */
185 #define CONSOLEIO_write 0
186 #define CONSOLEIO_read 1
188 /*
189 * Commands to HYPERVISOR_dom_mem_op().
190 */
191 #define MEMOP_increase_reservation 0
192 #define MEMOP_decrease_reservation 1
194 /*
195 * Commands to HYPERVISOR_vm_assist().
196 */
197 #define VMASST_CMD_enable 0
198 #define VMASST_CMD_disable 1
199 #define VMASST_TYPE_4gb_segments 0
200 #define VMASST_TYPE_4gb_segments_notify 1
201 #define VMASST_TYPE_writable_pagetables 2
202 #define MAX_VMASST_TYPE 2
204 #ifndef __ASSEMBLY__
206 typedef u16 domid_t;
208 /* Domain ids >= DOMID_FIRST_RESERVED cannot be used for ordinary domains. */
209 #define DOMID_FIRST_RESERVED (0x7FF0U)
211 /* DOMID_SELF is used in certain contexts to refer to oneself. */
212 #define DOMID_SELF (0x7FF0U)
214 /*
215 * DOMID_IO is used to restrict page-table updates to mapping I/O memory.
216 * Although no Foreign Domain need be specified to map I/O pages, DOMID_IO
217 * is useful to ensure that no mappings to the OS's own heap are accidentally
218 * installed. (e.g., in Linux this could cause havoc as reference counts
219 * aren't adjusted on the I/O-mapping code path).
220 * This only makes sense in MMUEXT_SET_FOREIGNDOM, but in that context can
221 * be specified by any calling domain.
222 */
223 #define DOMID_IO (0x7FF1U)
225 /*
226 * DOMID_XEN is used to allow privileged domains to map restricted parts of
227 * Xen's heap space (e.g., the machine_to_phys table).
228 * This only makes sense in MMUEXT_SET_FOREIGNDOM, and is only permitted if
229 * the caller is privileged.
230 */
231 #define DOMID_XEN (0x7FF2U)
233 /*
234 * Send an array of these to HYPERVISOR_mmu_update().
235 * NB. The fields are natural pointer/address size for this architecture.
236 */
237 typedef struct
238 {
239 memory_t ptr; /* Machine address of PTE. */
240 memory_t val; /* New contents of PTE. */
241 } PACKED mmu_update_t;
243 /*
244 * Send an array of these to HYPERVISOR_multicall().
245 * NB. The fields are natural register size for this architecture.
246 */
247 typedef struct
248 {
249 cpureg_t op;
250 cpureg_t args[7];
251 } PACKED multicall_entry_t;
253 /* Event channel endpoints per domain. */
254 #define NR_EVENT_CHANNELS 1024
256 /* Support for multi-processor guests. */
257 #define MAX_VIRT_CPUS 32
259 /*
260 * Per-VCPU information goes here. This will be cleaned up more when Xen
261 * actually supports multi-VCPU guests.
262 */
263 typedef struct vcpu_info_st
264 {
265 /*
266 * 'evtchn_upcall_pending' is written non-zero by Xen to indicate
267 * a pending notification for a particular VCPU. It is then cleared
268 * by the guest OS /before/ checking for pending work, thus avoiding
269 * a set-and-check race. Note that the mask is only accessed by Xen
270 * on the CPU that is currently hosting the VCPU. This means that the
271 * pending and mask flags can be updated by the guest without special
272 * synchronisation (i.e., no need for the x86 LOCK prefix).
273 * This may seem suboptimal because if the pending flag is set by
274 * a different CPU then an IPI may be scheduled even when the mask
275 * is set. However, note:
276 * 1. The task of 'interrupt holdoff' is covered by the per-event-
277 * channel mask bits. A 'noisy' event that is continually being
278 * triggered can be masked at source at this very precise
279 * granularity.
280 * 2. The main purpose of the per-VCPU mask is therefore to restrict
281 * reentrant execution: whether for concurrency control, or to
282 * prevent unbounded stack usage. Whatever the purpose, we expect
283 * that the mask will be asserted only for short periods at a time,
284 * and so the likelihood of a 'spurious' IPI is suitably small.
285 * The mask is read before making an event upcall to the guest: a
286 * non-zero mask therefore guarantees that the VCPU will not receive
287 * an upcall activation. The mask is cleared when the VCPU requests
288 * to block: this avoids wakeup-waiting races.
289 */
290 u8 evtchn_upcall_pending;
291 u8 evtchn_upcall_mask;
292 u8 pad0, pad1;
293 u32 evtchn_pending_sel; /* 4 */
294 } PACKED vcpu_info_t; /* 8 */
296 /*
297 * Xen/guestos shared data -- pointer provided in start_info.
298 * NB. We expect that this struct is smaller than a page.
299 */
300 typedef struct shared_info_st
301 {
302 vcpu_info_t vcpu_data[MAX_VIRT_CPUS]; /* 0 */
304 u32 n_vcpu;
306 /*
307 * A domain can have up to 1024 "event channels" on which it can send
308 * and receive asynchronous event notifications. There are three classes
309 * of event that are delivered by this mechanism:
310 * 1. Bi-directional inter- and intra-domain connections. Domains must
311 * arrange out-of-band to set up a connection (usually the setup
312 * is initiated and organised by a privileged third party such as
313 * software running in domain 0).
314 * 2. Physical interrupts. A domain with suitable hardware-access
315 * privileges can bind an event-channel port to a physical interrupt
316 * source.
317 * 3. Virtual interrupts ('events'). A domain can bind an event-channel
318 * port to a virtual interrupt source, such as the virtual-timer
319 * device or the emergency console.
320 *
321 * Event channels are addressed by a "port index" between 0 and 1023.
322 * Each channel is associated with two bits of information:
323 * 1. PENDING -- notifies the domain that there is a pending notification
324 * to be processed. This bit is cleared by the guest.
325 * 2. MASK -- if this bit is clear then a 0->1 transition of PENDING
326 * will cause an asynchronous upcall to be scheduled. This bit is only
327 * updated by the guest. It is read-only within Xen. If a channel
328 * becomes pending while the channel is masked then the 'edge' is lost
329 * (i.e., when the channel is unmasked, the guest must manually handle
330 * pending notifications as no upcall will be scheduled by Xen).
331 *
332 * To expedite scanning of pending notifications, any 0->1 pending
333 * transition on an unmasked channel causes a corresponding bit in a
334 * 32-bit selector to be set. Each bit in the selector covers a 32-bit
335 * word in the PENDING bitfield array.
336 */
337 u32 evtchn_pending[32]; /* 4 */
338 u32 evtchn_mask[32]; /* 136 */
340 /*
341 * Time: The following abstractions are exposed: System Time, Clock Time,
342 * Domain Virtual Time. Domains can access Cycle counter time directly.
343 */
344 u64 cpu_freq; /* 264: CPU frequency (Hz). */
346 /*
347 * The following values are updated periodically (and not necessarily
348 * atomically!). The guest OS detects this because 'time_version1' is
349 * incremented just before updating these values, and 'time_version2' is
350 * incremented immediately after. See the Xen-specific Linux code for an
351 * example of how to read these values safely (arch/xen/kernel/time.c).
352 */
353 u32 time_version1; /* 272 */
354 u32 time_version2; /* 276 */
355 tsc_timestamp_t tsc_timestamp; /* TSC at last update of time vals. */
356 u64 system_time; /* Time, in nanosecs, since boot. */
357 u32 wc_sec; /* Secs 00:00:00 UTC, Jan 1, 1970. */
358 u32 wc_usec; /* Usecs 00:00:00 UTC, Jan 1, 1970. */
359 u64 domain_time; /* Domain virtual time, in nanosecs. */
361 /*
362 * Timeout values:
363 * Allow a domain to specify a timeout value in system time and
364 * domain virtual time.
365 */
366 u64 wall_timeout; /* 312 */
367 u64 domain_timeout; /* 320 */
369 arch_shared_info_t arch;
371 } PACKED shared_info_t;
373 /*
374 * Start-of-day memory layout for the initial domain (DOM0):
375 * 1. The domain is started within contiguous virtual-memory region.
376 * 2. The contiguous region begins and ends on an aligned 4MB boundary.
377 * 3. The region start corresponds to the load address of the OS image.
378 * If the load address is not 4MB aligned then the address is rounded down.
379 * 4. This the order of bootstrap elements in the initial virtual region:
380 * a. relocated kernel image
381 * b. initial ram disk [mod_start, mod_len]
382 * c. list of allocated page frames [mfn_list, nr_pages]
383 * d. bootstrap page tables [pt_base, CR3 (x86)]
384 * e. start_info_t structure [register ESI (x86)]
385 * f. bootstrap stack [register ESP (x86)]
386 * 5. Bootstrap elements are packed together, but each is 4kB-aligned.
387 * 6. The initial ram disk may be omitted.
388 * 7. The list of page frames forms a contiguous 'pseudo-physical' memory
389 * layout for the domain. In particular, the bootstrap virtual-memory
390 * region is a 1:1 mapping to the first section of the pseudo-physical map.
391 * 8. All bootstrap elements are mapped read-writable for the guest OS. The
392 * only exception is the bootstrap page table, which is mapped read-only.
393 * 9. There is guaranteed to be at least 512kB padding after the final
394 * bootstrap element. If necessary, the bootstrap virtual region is
395 * extended by an extra 4MB to ensure this.
396 */
398 #define MAX_CMDLINE 256
399 typedef struct {
400 /* THE FOLLOWING ARE FILLED IN BOTH ON INITIAL BOOT AND ON RESUME. */
401 memory_t nr_pages; /* 0: Total pages allocated to this domain. */
402 _MEMORY_PADDING(A);
403 memory_t shared_info; /* 8: MACHINE address of shared info struct.*/
404 _MEMORY_PADDING(B);
405 u32 flags; /* 16: SIF_xxx flags. */
406 u16 domain_controller_evtchn; /* 20 */
407 u16 __pad;
408 /* THE FOLLOWING ARE ONLY FILLED IN ON INITIAL BOOT (NOT RESUME). */
409 memory_t pt_base; /* 24: VIRTUAL address of page directory. */
410 _MEMORY_PADDING(C);
411 memory_t nr_pt_frames; /* 32: Number of bootstrap p.t. frames. */
412 _MEMORY_PADDING(D);
413 memory_t mfn_list; /* 40: VIRTUAL address of page-frame list. */
414 _MEMORY_PADDING(E);
415 memory_t mod_start; /* 48: VIRTUAL address of pre-loaded module. */
416 _MEMORY_PADDING(F);
417 memory_t mod_len; /* 56: Size (bytes) of pre-loaded module. */
418 _MEMORY_PADDING(G);
419 u8 cmd_line[MAX_CMDLINE]; /* 64 */
420 } PACKED start_info_t; /* 320 bytes */
422 /* These flags are passed in the 'flags' field of start_info_t. */
423 #define SIF_PRIVILEGED (1<<0) /* Is the domain privileged? */
424 #define SIF_INITDOMAIN (1<<1) /* Is this the initial control domain? */
425 #define SIF_BLK_BE_DOMAIN (1<<4) /* Is this a block backend domain? */
426 #define SIF_NET_BE_DOMAIN (1<<5) /* Is this a net backend domain? */
428 /* For use in guest OSes. */
429 extern shared_info_t *HYPERVISOR_shared_info;
431 #endif /* !__ASSEMBLY__ */
433 #endif /* __XEN_PUBLIC_XEN_H__ */