debuggers.hg

view xen/include/public/xen.h @ 3683:1c55bbe02576

bitkeeper revision 1.1159.212.84 (42033fc2Q0eAAtQcKyCf8cXCt_Fgfg)

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