xref: /titanic_52/usr/src/uts/common/xen/public/xen.h (revision 0a0e9771ca0211c15f3ac4466b661c145feeb9e4)
1 /******************************************************************************
2  * xen.h
3  *
4  * Guest OS interface to Xen.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  *
24  * Copyright (c) 2004, K A Fraser
25  */
26 
27 #ifndef __XEN_PUBLIC_XEN_H__
28 #define __XEN_PUBLIC_XEN_H__
29 
30 #include "xen-compat.h"
31 
32 #if defined(__i386) && !defined(__i386__)
33 #define __i386__ /* foo */
34 #endif
35 
36 #if defined(__amd64) && !defined(__x86_64__)
37 #define __x86_64__
38 #endif
39 
40 #if defined(_ASM) && !defined(__ASSEMBLY__)
41 #define __ASSEMBLY__
42 #endif
43 
44 #if defined(__i386__) || defined(__x86_64__)
45 #include "arch-x86/xen.h"
46 #elif defined(__ia64__)
47 #include "arch-ia64.h"
48 #else
49 #error "Unsupported architecture"
50 #endif
51 
52 #ifndef __ASSEMBLY__
53 /* Guest handles for primitive C types. */
54 DEFINE_XEN_GUEST_HANDLE(char);
55 __DEFINE_XEN_GUEST_HANDLE(uchar, unsigned char);
56 DEFINE_XEN_GUEST_HANDLE(int);
57 __DEFINE_XEN_GUEST_HANDLE(uint,  unsigned int);
58 DEFINE_XEN_GUEST_HANDLE(long);
59 __DEFINE_XEN_GUEST_HANDLE(ulong, unsigned long);
60 DEFINE_XEN_GUEST_HANDLE(void);
61 
62 DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);
63 #endif
64 
65 /*
66  * HYPERCALLS
67  */
68 
69 #define __HYPERVISOR_set_trap_table        0
70 #define __HYPERVISOR_mmu_update            1
71 #define __HYPERVISOR_set_gdt               2
72 #define __HYPERVISOR_stack_switch          3
73 #define __HYPERVISOR_set_callbacks         4
74 #define __HYPERVISOR_fpu_taskswitch        5
75 #define __HYPERVISOR_sched_op_compat       6 /* compat since 0x00030101 */
76 #define __HYPERVISOR_platform_op           7
77 #define __HYPERVISOR_set_debugreg          8
78 #define __HYPERVISOR_get_debugreg          9
79 #define __HYPERVISOR_update_descriptor    10
80 #define __HYPERVISOR_memory_op            12
81 #define __HYPERVISOR_multicall            13
82 #define __HYPERVISOR_update_va_mapping    14
83 #define __HYPERVISOR_set_timer_op         15
84 #define __HYPERVISOR_event_channel_op_compat 16 /* compat since 0x00030202 */
85 #define __HYPERVISOR_xen_version          17
86 #define __HYPERVISOR_console_io           18
87 #define __HYPERVISOR_physdev_op_compat    19 /* compat since 0x00030202 */
88 #define __HYPERVISOR_grant_table_op       20
89 #define __HYPERVISOR_vm_assist            21
90 #define __HYPERVISOR_update_va_mapping_otherdomain 22
91 #define __HYPERVISOR_iret                 23 /* x86 only */
92 #define __HYPERVISOR_vcpu_op              24
93 #define __HYPERVISOR_set_segment_base     25 /* x86/64 only */
94 #define __HYPERVISOR_mmuext_op            26
95 #define __HYPERVISOR_xsm_op               27
96 #define __HYPERVISOR_nmi_op               28
97 #define __HYPERVISOR_sched_op             29
98 #define __HYPERVISOR_callback_op          30
99 #define __HYPERVISOR_xenoprof_op          31
100 #define __HYPERVISOR_event_channel_op     32
101 #define __HYPERVISOR_physdev_op           33
102 #define __HYPERVISOR_hvm_op               34
103 #define __HYPERVISOR_sysctl               35
104 #define __HYPERVISOR_domctl               36
105 #define __HYPERVISOR_kexec_op             37
106 
107 /* Architecture-specific hypercall definitions. */
108 #define __HYPERVISOR_arch_0               48
109 #define __HYPERVISOR_arch_1               49
110 #define __HYPERVISOR_arch_2               50
111 #define __HYPERVISOR_arch_3               51
112 #define __HYPERVISOR_arch_4               52
113 #define __HYPERVISOR_arch_5               53
114 #define __HYPERVISOR_arch_6               54
115 #define __HYPERVISOR_arch_7               55
116 
117 /*
118  * HYPERCALL COMPATIBILITY.
119  */
120 
121 /* New sched_op hypercall introduced in 0x00030101. */
122 #if __XEN_INTERFACE_VERSION__ < 0x00030101
123 #undef __HYPERVISOR_sched_op
124 #define __HYPERVISOR_sched_op __HYPERVISOR_sched_op_compat
125 #endif
126 
127 /* New event-channel and physdev hypercalls introduced in 0x00030202. */
128 #if __XEN_INTERFACE_VERSION__ < 0x00030202
129 #undef __HYPERVISOR_event_channel_op
130 #define __HYPERVISOR_event_channel_op __HYPERVISOR_event_channel_op_compat
131 #undef __HYPERVISOR_physdev_op
132 #define __HYPERVISOR_physdev_op __HYPERVISOR_physdev_op_compat
133 #endif
134 
135 /* New platform_op hypercall introduced in 0x00030204. */
136 #if __XEN_INTERFACE_VERSION__ < 0x00030204
137 #define __HYPERVISOR_dom0_op __HYPERVISOR_platform_op
138 #endif
139 
140 /*
141  * VIRTUAL INTERRUPTS
142  *
143  * Virtual interrupts that a guest OS may receive from Xen.
144  *
145  * In the side comments, 'V.' denotes a per-VCPU VIRQ while 'G.' denotes a
146  * global VIRQ. The former can be bound once per VCPU and cannot be re-bound.
147  * The latter can be allocated only once per guest: they must initially be
148  * allocated to VCPU0 but can subsequently be re-bound.
149  */
150 #define VIRQ_TIMER      0  /* V. Timebase update, and/or requested timeout.  */
151 #define VIRQ_DEBUG      1  /* V. Request guest to dump debug info.           */
152 #define VIRQ_CONSOLE    2  /* G. (DOM0) Bytes received on emergency console. */
153 #define VIRQ_DOM_EXC    3  /* G. (DOM0) Exceptional event for some domain.   */
154 #define VIRQ_TBUF       4  /* G. (DOM0) Trace buffer has records available.  */
155 #define VIRQ_DEBUGGER   6  /* G. (DOM0) A domain has paused for debugging.   */
156 #define VIRQ_XENOPROF   7  /* V. XenOprofile interrupt: new sample available */
157 #define VIRQ_CON_RING   8  /* G. (DOM0) Bytes received on console            */
158 
159 /* Architecture-specific VIRQ definitions. */
160 #define VIRQ_ARCH_0    16
161 #define VIRQ_ARCH_1    17
162 #define VIRQ_ARCH_2    18
163 #define VIRQ_ARCH_3    19
164 #define VIRQ_ARCH_4    20
165 #define VIRQ_ARCH_5    21
166 #define VIRQ_ARCH_6    22
167 #define VIRQ_ARCH_7    23
168 
169 #define NR_VIRQS       24
170 
171 /*
172  * MMU-UPDATE REQUESTS
173  *
174  * HYPERVISOR_mmu_update() accepts a list of (ptr, val) pairs.
175  * A foreigndom (FD) can be specified (or DOMID_SELF for none).
176  * Where the FD has some effect, it is described below.
177  * ptr[1:0] specifies the appropriate MMU_* command.
178  *
179  * ptr[1:0] == MMU_NORMAL_PT_UPDATE:
180  * Updates an entry in a page table. If updating an L1 table, and the new
181  * table entry is valid/present, the mapped frame must belong to the FD, if
182  * an FD has been specified. If attempting to map an I/O page then the
183  * caller assumes the privilege of the FD.
184  * FD == DOMID_IO: Permit /only/ I/O mappings, at the priv level of the caller.
185  * FD == DOMID_XEN: Map restricted areas of Xen's heap space.
186  * ptr[:2]  -- Machine address of the page-table entry to modify.
187  * val      -- Value to write.
188  *
189  * ptr[1:0] == MMU_MACHPHYS_UPDATE:
190  * Updates an entry in the machine->pseudo-physical mapping table.
191  * ptr[:2]  -- Machine address within the frame whose mapping to modify.
192  *             The frame must belong to the FD, if one is specified.
193  * val      -- Value to write into the mapping entry.
194  *
195  * ptr[1:0] == MMU_PT_UPDATE_PRESERVE_AD:
196  * As MMU_NORMAL_PT_UPDATE above, but A/D bits currently in the PTE are ORed
197  * with those in @val.
198  */
199 #define MMU_NORMAL_PT_UPDATE      0 /* checked '*ptr = val'. ptr is MA.      */
200 #define MMU_MACHPHYS_UPDATE       1 /* ptr = MA of frame to modify entry for */
201 #define MMU_PT_UPDATE_PRESERVE_AD 2 /* atomically: *ptr = val | (*ptr&(A|D)) */
202 
203 /*
204  * MMU EXTENDED OPERATIONS
205  *
206  * HYPERVISOR_mmuext_op() accepts a list of mmuext_op structures.
207  * A foreigndom (FD) can be specified (or DOMID_SELF for none).
208  * Where the FD has some effect, it is described below.
209  *
210  * cmd: MMUEXT_(UN)PIN_*_TABLE
211  * mfn: Machine frame number to be (un)pinned as a p.t. page.
212  *      The frame must belong to the FD, if one is specified.
213  *
214  * cmd: MMUEXT_NEW_BASEPTR
215  * mfn: Machine frame number of new page-table base to install in MMU.
216  *
217  * cmd: MMUEXT_NEW_USER_BASEPTR [x86/64 only]
218  * mfn: Machine frame number of new page-table base to install in MMU
219  *      when in user space.
220  *
221  * cmd: MMUEXT_TLB_FLUSH_LOCAL
222  * No additional arguments. Flushes local TLB.
223  *
224  * cmd: MMUEXT_INVLPG_LOCAL
225  * linear_addr: Linear address to be flushed from the local TLB.
226  *
227  * cmd: MMUEXT_TLB_FLUSH_MULTI
228  * vcpumask: Pointer to bitmap of VCPUs to be flushed.
229  *
230  * cmd: MMUEXT_INVLPG_MULTI
231  * linear_addr: Linear address to be flushed.
232  * vcpumask: Pointer to bitmap of VCPUs to be flushed.
233  *
234  * cmd: MMUEXT_TLB_FLUSH_ALL
235  * No additional arguments. Flushes all VCPUs' TLBs.
236  *
237  * cmd: MMUEXT_INVLPG_ALL
238  * linear_addr: Linear address to be flushed from all VCPUs' TLBs.
239  *
240  * cmd: MMUEXT_FLUSH_CACHE
241  * No additional arguments. Writes back and flushes cache contents.
242  *
243  * cmd: MMUEXT_SET_LDT
244  * linear_addr: Linear address of LDT base (NB. must be page-aligned).
245  * nr_ents: Number of entries in LDT.
246  */
247 #define MMUEXT_PIN_L1_TABLE      0
248 #define MMUEXT_PIN_L2_TABLE      1
249 #define MMUEXT_PIN_L3_TABLE      2
250 #define MMUEXT_PIN_L4_TABLE      3
251 #define MMUEXT_UNPIN_TABLE       4
252 #define MMUEXT_NEW_BASEPTR       5
253 #define MMUEXT_TLB_FLUSH_LOCAL   6
254 #define MMUEXT_INVLPG_LOCAL      7
255 #define MMUEXT_TLB_FLUSH_MULTI   8
256 #define MMUEXT_INVLPG_MULTI      9
257 #define MMUEXT_TLB_FLUSH_ALL    10
258 #define MMUEXT_INVLPG_ALL       11
259 #define MMUEXT_FLUSH_CACHE      12
260 #define MMUEXT_SET_LDT          13
261 #define MMUEXT_NEW_USER_BASEPTR 15
262 
263 #ifndef __ASSEMBLY__
264 struct mmuext_op {
265     unsigned int cmd;
266     union {
267         /* [UN]PIN_TABLE, NEW_BASEPTR, NEW_USER_BASEPTR */
268         xen_pfn_t     mfn;
269         /* INVLPG_LOCAL, INVLPG_ALL, SET_LDT */
270         unsigned long linear_addr;
271     } arg1;
272     union {
273         /* SET_LDT */
274         unsigned int nr_ents;
275         /* TLB_FLUSH_MULTI, INVLPG_MULTI */
276 #if __XEN_INTERFACE_VERSION__ >= 0x00030205
277         XEN_GUEST_HANDLE(void) vcpumask;
278 #else
279         void *vcpumask;
280 #endif
281     } arg2;
282 };
283 typedef struct mmuext_op mmuext_op_t;
284 DEFINE_XEN_GUEST_HANDLE(mmuext_op_t);
285 #endif
286 
287 /* These are passed as 'flags' to update_va_mapping. They can be ORed. */
288 /* When specifying UVMF_MULTI, also OR in a pointer to a CPU bitmap.   */
289 /* UVMF_LOCAL is merely UVMF_MULTI with a NULL bitmap pointer.         */
290 #define UVMF_NONE               (0UL<<0) /* No flushing at all.   */
291 #define UVMF_TLB_FLUSH          (1UL<<0) /* Flush entire TLB(s).  */
292 #define UVMF_INVLPG             (2UL<<0) /* Flush only one entry. */
293 #define UVMF_FLUSHTYPE_MASK     (3UL<<0)
294 #define UVMF_MULTI              (0UL<<2) /* Flush subset of TLBs. */
295 #define UVMF_LOCAL              (0UL<<2) /* Flush local TLB.      */
296 #define UVMF_ALL                (1UL<<2) /* Flush all TLBs.       */
297 
298 /*
299  * Commands to HYPERVISOR_console_io().
300  */
301 #define CONSOLEIO_write         0
302 #define CONSOLEIO_read          1
303 #define CONSOLEIO_get_device   32
304 
305 /*
306  * Commands to HYPERVISOR_vm_assist().
307  */
308 #define VMASST_CMD_enable                0
309 #define VMASST_CMD_disable               1
310 
311 /* x86/32 guests: simulate full 4GB segment limits. */
312 #define VMASST_TYPE_4gb_segments         0
313 
314 /* x86/32 guests: trap (vector 15) whenever above vmassist is used. */
315 #define VMASST_TYPE_4gb_segments_notify  1
316 
317 /*
318  * x86 guests: support writes to bottom-level PTEs.
319  * NB1. Page-directory entries cannot be written.
320  * NB2. Guest must continue to remove all writable mappings of PTEs.
321  */
322 #define VMASST_TYPE_writable_pagetables  2
323 
324 /* x86/PAE guests: support PDPTs above 4GB. */
325 #define VMASST_TYPE_pae_extended_cr3     3
326 
327 #define MAX_VMASST_TYPE                  3
328 
329 #ifndef __ASSEMBLY__
330 
331 typedef uint16_t domid_t;
332 
333 /* Domain ids >= DOMID_FIRST_RESERVED cannot be used for ordinary domains. */
334 #define DOMID_FIRST_RESERVED (0x7FF0U)
335 
336 /* DOMID_SELF is used in certain contexts to refer to oneself. */
337 #define DOMID_SELF (0x7FF0U)
338 
339 /*
340  * DOMID_IO is used to restrict page-table updates to mapping I/O memory.
341  * Although no Foreign Domain need be specified to map I/O pages, DOMID_IO
342  * is useful to ensure that no mappings to the OS's own heap are accidentally
343  * installed. (e.g., in Linux this could cause havoc as reference counts
344  * aren't adjusted on the I/O-mapping code path).
345  * This only makes sense in MMUEXT_SET_FOREIGNDOM, but in that context can
346  * be specified by any calling domain.
347  */
348 #define DOMID_IO   (0x7FF1U)
349 
350 /*
351  * DOMID_XEN is used to allow privileged domains to map restricted parts of
352  * Xen's heap space (e.g., the machine_to_phys table).
353  * This only makes sense in MMUEXT_SET_FOREIGNDOM, and is only permitted if
354  * the caller is privileged.
355  */
356 #define DOMID_XEN  (0x7FF2U)
357 
358 /*
359  * Send an array of these to HYPERVISOR_mmu_update().
360  * NB. The fields are natural pointer/address size for this architecture.
361  */
362 struct mmu_update {
363     uint64_t ptr;       /* Machine address of PTE. */
364     uint64_t val;       /* New contents of PTE.    */
365 };
366 typedef struct mmu_update mmu_update_t;
367 DEFINE_XEN_GUEST_HANDLE(mmu_update_t);
368 
369 /*
370  * Send an array of these to HYPERVISOR_multicall().
371  * NB. The fields are natural register size for this architecture.
372  */
373 struct multicall_entry {
374     unsigned long op, result;
375     unsigned long args[6];
376 };
377 typedef struct multicall_entry multicall_entry_t;
378 DEFINE_XEN_GUEST_HANDLE(multicall_entry_t);
379 
380 /*
381  * Event channel endpoints per domain:
382  *  1024 if a long is 32 bits; 4096 if a long is 64 bits.
383  */
384 #define NR_EVENT_CHANNELS (sizeof(unsigned long) * sizeof(unsigned long) * 64)
385 
386 struct vcpu_time_info {
387     /*
388      * Updates to the following values are preceded and followed by an
389      * increment of 'version'. The guest can therefore detect updates by
390      * looking for changes to 'version'. If the least-significant bit of
391      * the version number is set then an update is in progress and the guest
392      * must wait to read a consistent set of values.
393      * The correct way to interact with the version number is similar to
394      * Linux's seqlock: see the implementations of read_seqbegin/read_seqretry.
395      */
396     uint32_t version;
397     uint32_t pad0;
398     uint64_t tsc_timestamp;   /* TSC at last update of time vals.  */
399     uint64_t system_time;     /* Time, in nanosecs, since boot.    */
400     /*
401      * Current system time:
402      *   system_time +
403      *   ((((tsc - tsc_timestamp) << tsc_shift) * tsc_to_system_mul) >> 32)
404      * CPU frequency (Hz):
405      *   ((10^9 << 32) / tsc_to_system_mul) >> tsc_shift
406      */
407     uint32_t tsc_to_system_mul;
408     int8_t   tsc_shift;
409     int8_t   pad1[3];
410 }; /* 32 bytes */
411 typedef struct vcpu_time_info vcpu_time_info_t;
412 
413 struct vcpu_info {
414     /*
415      * 'evtchn_upcall_pending' is written non-zero by Xen to indicate
416      * a pending notification for a particular VCPU. It is then cleared
417      * by the guest OS /before/ checking for pending work, thus avoiding
418      * a set-and-check race. Note that the mask is only accessed by Xen
419      * on the CPU that is currently hosting the VCPU. This means that the
420      * pending and mask flags can be updated by the guest without special
421      * synchronisation (i.e., no need for the x86 LOCK prefix).
422      * This may seem suboptimal because if the pending flag is set by
423      * a different CPU then an IPI may be scheduled even when the mask
424      * is set. However, note:
425      *  1. The task of 'interrupt holdoff' is covered by the per-event-
426      *     channel mask bits. A 'noisy' event that is continually being
427      *     triggered can be masked at source at this very precise
428      *     granularity.
429      *  2. The main purpose of the per-VCPU mask is therefore to restrict
430      *     reentrant execution: whether for concurrency control, or to
431      *     prevent unbounded stack usage. Whatever the purpose, we expect
432      *     that the mask will be asserted only for short periods at a time,
433      *     and so the likelihood of a 'spurious' IPI is suitably small.
434      * The mask is read before making an event upcall to the guest: a
435      * non-zero mask therefore guarantees that the VCPU will not receive
436      * an upcall activation. The mask is cleared when the VCPU requests
437      * to block: this avoids wakeup-waiting races.
438      */
439     uint8_t evtchn_upcall_pending;
440     uint8_t evtchn_upcall_mask;
441     unsigned long evtchn_pending_sel;
442     struct arch_vcpu_info arch;
443     struct vcpu_time_info time;
444 }; /* 64 bytes (x86) */
445 #ifndef __XEN__
446 typedef struct vcpu_info vcpu_info_t;
447 #endif
448 
449 /*
450  * Xen/kernel shared data -- pointer provided in start_info.
451  *
452  * This structure is defined to be both smaller than a page, and the
453  * only data on the shared page, but may vary in actual size even within
454  * compatible Xen versions; guests should not rely on the size
455  * of this structure remaining constant.
456  */
457 struct shared_info {
458     struct vcpu_info vcpu_info[MAX_VIRT_CPUS];
459 
460     /*
461      * A domain can create "event channels" on which it can send and receive
462      * asynchronous event notifications. There are three classes of event that
463      * are delivered by this mechanism:
464      *  1. Bi-directional inter- and intra-domain connections. Domains must
465      *     arrange out-of-band to set up a connection (usually by allocating
466      *     an unbound 'listener' port and avertising that via a storage service
467      *     such as xenstore).
468      *  2. Physical interrupts. A domain with suitable hardware-access
469      *     privileges can bind an event-channel port to a physical interrupt
470      *     source.
471      *  3. Virtual interrupts ('events'). A domain can bind an event-channel
472      *     port to a virtual interrupt source, such as the virtual-timer
473      *     device or the emergency console.
474      *
475      * Event channels are addressed by a "port index". Each channel is
476      * associated with two bits of information:
477      *  1. PENDING -- notifies the domain that there is a pending notification
478      *     to be processed. This bit is cleared by the guest.
479      *  2. MASK -- if this bit is clear then a 0->1 transition of PENDING
480      *     will cause an asynchronous upcall to be scheduled. This bit is only
481      *     updated by the guest. It is read-only within Xen. If a channel
482      *     becomes pending while the channel is masked then the 'edge' is lost
483      *     (i.e., when the channel is unmasked, the guest must manually handle
484      *     pending notifications as no upcall will be scheduled by Xen).
485      *
486      * To expedite scanning of pending notifications, any 0->1 pending
487      * transition on an unmasked channel causes a corresponding bit in a
488      * per-vcpu selector word to be set. Each bit in the selector covers a
489      * 'C long' in the PENDING bitfield array.
490      */
491     unsigned long evtchn_pending[sizeof(unsigned long) * 8];
492     unsigned long evtchn_mask[sizeof(unsigned long) * 8];
493 
494     /*
495      * Wallclock time: updated only by control software. Guests should base
496      * their gettimeofday() syscall on this wallclock-base value.
497      */
498     uint32_t wc_version;      /* Version counter: see vcpu_time_info_t. */
499     uint32_t wc_sec;          /* Secs  00:00:00 UTC, Jan 1, 1970.  */
500     uint32_t wc_nsec;         /* Nsecs 00:00:00 UTC, Jan 1, 1970.  */
501 
502     struct arch_shared_info arch;
503 
504 };
505 #ifndef __XEN__
506 typedef struct shared_info shared_info_t;
507 #endif
508 
509 /*
510  * Start-of-day memory layout:
511  *  1. The domain is started within contiguous virtual-memory region.
512  *  2. The contiguous region ends on an aligned 4MB boundary.
513  *  3. This the order of bootstrap elements in the initial virtual region:
514  *      a. relocated kernel image
515  *      b. initial ram disk              [mod_start, mod_len]
516  *      c. list of allocated page frames [mfn_list, nr_pages]
517  *      d. start_info_t structure        [register ESI (x86)]
518  *      e. bootstrap page tables         [pt_base, CR3 (x86)]
519  *      f. bootstrap stack               [register ESP (x86)]
520  *  4. Bootstrap elements are packed together, but each is 4kB-aligned.
521  *  5. The initial ram disk may be omitted.
522  *  6. The list of page frames forms a contiguous 'pseudo-physical' memory
523  *     layout for the domain. In particular, the bootstrap virtual-memory
524  *     region is a 1:1 mapping to the first section of the pseudo-physical map.
525  *  7. All bootstrap elements are mapped read-writable for the guest OS. The
526  *     only exception is the bootstrap page table, which is mapped read-only.
527  *  8. There is guaranteed to be at least 512kB padding after the final
528  *     bootstrap element. If necessary, the bootstrap virtual region is
529  *     extended by an extra 4MB to ensure this.
530  */
531 
532 #define MAX_GUEST_CMDLINE 1024
533 struct start_info {
534     /* THE FOLLOWING ARE FILLED IN BOTH ON INITIAL BOOT AND ON RESUME.    */
535     char magic[32];             /* "xen-<version>-<platform>".            */
536     unsigned long nr_pages;     /* Total pages allocated to this domain.  */
537     unsigned long shared_info;  /* MACHINE address of shared info struct. */
538     uint32_t flags;             /* SIF_xxx flags.                         */
539     xen_pfn_t store_mfn;        /* MACHINE page number of shared page.    */
540     uint32_t store_evtchn;      /* Event channel for store communication. */
541     union {
542         struct {
543             xen_pfn_t mfn;      /* MACHINE page number of console page.   */
544             uint32_t  evtchn;   /* Event channel for console page.        */
545         } domU;
546         struct {
547             uint32_t info_off;  /* Offset of console_info struct.         */
548             uint32_t info_size; /* Size of console_info struct from start.*/
549         } dom0;
550     } console;
551     /* THE FOLLOWING ARE ONLY FILLED IN ON INITIAL BOOT (NOT RESUME).     */
552     unsigned long pt_base;      /* VIRTUAL address of page directory.     */
553     unsigned long nr_pt_frames; /* Number of bootstrap p.t. frames.       */
554     unsigned long mfn_list;     /* VIRTUAL address of page-frame list.    */
555     unsigned long mod_start;    /* VIRTUAL address of pre-loaded module.  */
556     unsigned long mod_len;      /* Size (bytes) of pre-loaded module.     */
557     int8_t cmd_line[MAX_GUEST_CMDLINE];
558 };
559 typedef struct start_info start_info_t;
560 
561 /* New console union for dom0 introduced in 0x00030203. */
562 #if __XEN_INTERFACE_VERSION__ < 0x00030203
563 #define console_mfn    console.domU.mfn
564 #define console_evtchn console.domU.evtchn
565 #endif
566 
567 /* These flags are passed in the 'flags' field of start_info_t. */
568 #define SIF_PRIVILEGED    (1<<0)  /* Is the domain privileged? */
569 #define SIF_INITDOMAIN    (1<<1)  /* Is this the initial control domain? */
570 #define SIF_PM_MASK       (0xFF<<8) /* reserve 1 byte for xen-pm options */
571 
572 #define XEN_CONSOLE_INVALID   -1
573 #define XEN_CONSOLE_COM1       0
574 #define XEN_CONSOLE_COM2       1
575 #define XEN_CONSOLE_VGA        2
576 
577 typedef struct dom0_vga_console_info {
578     uint8_t video_type; /* DOM0_VGA_CONSOLE_??? */
579 #define XEN_VGATYPE_TEXT_MODE_3 0x03
580 #define XEN_VGATYPE_VESA_LFB    0x23
581 
582     union {
583         struct {
584             /* Font height, in pixels. */
585             uint16_t font_height;
586             /* Cursor location (column, row). */
587             uint16_t cursor_x, cursor_y;
588             /* Number of rows and columns (dimensions in characters). */
589             uint16_t rows, columns;
590         } text_mode_3;
591 
592         struct {
593             /* Width and height, in pixels. */
594             uint16_t width, height;
595             /* Bytes per scan line. */
596             uint16_t bytes_per_line;
597             /* Bits per pixel. */
598             uint16_t bits_per_pixel;
599             /* LFB physical address, and size (in units of 64kB). */
600             uint32_t lfb_base;
601             uint32_t lfb_size;
602             /* RGB mask offsets and sizes, as defined by VBE 1.2+ */
603             uint8_t  red_pos, red_size;
604             uint8_t  green_pos, green_size;
605             uint8_t  blue_pos, blue_size;
606             uint8_t  rsvd_pos, rsvd_size;
607 #if __XEN_INTERFACE_VERSION__ >= 0x00030206
608             /* VESA capabilities (offset 0xa, VESA command 0x4f00). */
609             uint32_t gbl_caps;
610             /* Mode attributes (offset 0x0, VESA command 0x4f01). */
611             uint16_t mode_attrs;
612 #endif
613         } vesa_lfb;
614     } u;
615 } dom0_vga_console_info_t;
616 #define xen_vga_console_info dom0_vga_console_info
617 #define xen_vga_console_info_t dom0_vga_console_info_t
618 
619 typedef uint8_t xen_domain_handle_t[16];
620 
621 /* Turn a plain number into a C unsigned long constant. */
622 #define __mk_unsigned_long(x) x ## UL
623 #define mk_unsigned_long(x) __mk_unsigned_long(x)
624 
625 __DEFINE_XEN_GUEST_HANDLE(uint8,  uint8_t);
626 __DEFINE_XEN_GUEST_HANDLE(uint16, uint16_t);
627 __DEFINE_XEN_GUEST_HANDLE(uint32, uint32_t);
628 __DEFINE_XEN_GUEST_HANDLE(uint64, uint64_t);
629 
630 #else /* __ASSEMBLY__ */
631 
632 /* In assembly code we cannot use C numeric constant suffixes. */
633 #define mk_unsigned_long(x) x
634 
635 #endif /* !__ASSEMBLY__ */
636 
637 /* Default definitions for macros used by domctl/sysctl. */
638 #if defined(__XEN__) || defined(__XEN_TOOLS__)
639 #ifndef uint64_aligned_t
640 #define uint64_aligned_t uint64_t
641 #endif
642 #ifndef XEN_GUEST_HANDLE_64
643 #define XEN_GUEST_HANDLE_64(name) XEN_GUEST_HANDLE(name)
644 #endif
645 #endif
646 
647 #endif /* __XEN_PUBLIC_XEN_H__ */
648 
649 /*
650  * Local variables:
651  * mode: C
652  * c-set-style: "BSD"
653  * c-basic-offset: 4
654  * tab-width: 4
655  * indent-tabs-mode: nil
656  * End:
657  */
658