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