iPXE
xen.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  * xen.h
00003  *
00004  * Guest OS interface to Xen.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a copy
00007  * of this software and associated documentation files (the "Software"), to
00008  * deal in the Software without restriction, including without limitation the
00009  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
00010  * sell copies of the Software, and to permit persons to whom the Software is
00011  * furnished to do so, subject to the following conditions:
00012  *
00013  * The above copyright notice and this permission notice shall be included in
00014  * all copies or substantial portions of the Software.
00015  *
00016  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00019  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00020  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00021  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00022  * DEALINGS IN THE SOFTWARE.
00023  *
00024  * Copyright (c) 2004, K A Fraser
00025  */
00026 
00027 #ifndef __XEN_PUBLIC_XEN_H__
00028 #define __XEN_PUBLIC_XEN_H__
00029 
00030 FILE_LICENCE ( MIT );
00031 
00032 #include "xen-compat.h"
00033 
00034 #if defined(__i386__) || defined(__x86_64__)
00035 #include "arch-x86/xen.h"
00036 #elif defined(__arm__) || defined (__aarch64__)
00037 #include "arch-arm.h"
00038 #else
00039 #error "Unsupported architecture"
00040 #endif
00041 
00042 #ifndef __ASSEMBLY__
00043 /* Guest handles for primitive C types. */
00044 DEFINE_XEN_GUEST_HANDLE(char);
00045 __DEFINE_XEN_GUEST_HANDLE(uchar, unsigned char);
00046 DEFINE_XEN_GUEST_HANDLE(int);
00047 __DEFINE_XEN_GUEST_HANDLE(uint,  unsigned int);
00048 #if __XEN_INTERFACE_VERSION__ < 0x00040300
00049 DEFINE_XEN_GUEST_HANDLE(long);
00050 __DEFINE_XEN_GUEST_HANDLE(ulong, unsigned long);
00051 #endif
00052 DEFINE_XEN_GUEST_HANDLE(void);
00053 
00054 DEFINE_XEN_GUEST_HANDLE(uint64_t);
00055 DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);
00056 DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);
00057 #endif
00058 
00059 /*
00060  * HYPERCALLS
00061  */
00062 
00063 /* `incontents 100 hcalls List of hypercalls
00064  * ` enum hypercall_num { // __HYPERVISOR_* => HYPERVISOR_*()
00065  */
00066 
00067 #define __HYPERVISOR_set_trap_table        0
00068 #define __HYPERVISOR_mmu_update            1
00069 #define __HYPERVISOR_set_gdt               2
00070 #define __HYPERVISOR_stack_switch          3
00071 #define __HYPERVISOR_set_callbacks         4
00072 #define __HYPERVISOR_fpu_taskswitch        5
00073 #define __HYPERVISOR_sched_op_compat       6 /* compat since 0x00030101 */
00074 #define __HYPERVISOR_platform_op           7
00075 #define __HYPERVISOR_set_debugreg          8
00076 #define __HYPERVISOR_get_debugreg          9
00077 #define __HYPERVISOR_update_descriptor    10
00078 #define __HYPERVISOR_memory_op            12
00079 #define __HYPERVISOR_multicall            13
00080 #define __HYPERVISOR_update_va_mapping    14
00081 #define __HYPERVISOR_set_timer_op         15
00082 #define __HYPERVISOR_event_channel_op_compat 16 /* compat since 0x00030202 */
00083 #define __HYPERVISOR_xen_version          17
00084 #define __HYPERVISOR_console_io           18
00085 #define __HYPERVISOR_physdev_op_compat    19 /* compat since 0x00030202 */
00086 #define __HYPERVISOR_grant_table_op       20
00087 #define __HYPERVISOR_vm_assist            21
00088 #define __HYPERVISOR_update_va_mapping_otherdomain 22
00089 #define __HYPERVISOR_iret                 23 /* x86 only */
00090 #define __HYPERVISOR_vcpu_op              24
00091 #define __HYPERVISOR_set_segment_base     25 /* x86/64 only */
00092 #define __HYPERVISOR_mmuext_op            26
00093 #define __HYPERVISOR_xsm_op               27
00094 #define __HYPERVISOR_nmi_op               28
00095 #define __HYPERVISOR_sched_op             29
00096 #define __HYPERVISOR_callback_op          30
00097 #define __HYPERVISOR_xenoprof_op          31
00098 #define __HYPERVISOR_event_channel_op     32
00099 #define __HYPERVISOR_physdev_op           33
00100 #define __HYPERVISOR_hvm_op               34
00101 #define __HYPERVISOR_sysctl               35
00102 #define __HYPERVISOR_domctl               36
00103 #define __HYPERVISOR_kexec_op             37
00104 #define __HYPERVISOR_tmem_op              38
00105 #define __HYPERVISOR_xc_reserved_op       39 /* reserved for XenClient */
00106 
00107 /* Architecture-specific hypercall definitions. */
00108 #define __HYPERVISOR_arch_0               48
00109 #define __HYPERVISOR_arch_1               49
00110 #define __HYPERVISOR_arch_2               50
00111 #define __HYPERVISOR_arch_3               51
00112 #define __HYPERVISOR_arch_4               52
00113 #define __HYPERVISOR_arch_5               53
00114 #define __HYPERVISOR_arch_6               54
00115 #define __HYPERVISOR_arch_7               55
00116 
00117 /* ` } */
00118 
00119 /*
00120  * HYPERCALL COMPATIBILITY.
00121  */
00122 
00123 /* New sched_op hypercall introduced in 0x00030101. */
00124 #if __XEN_INTERFACE_VERSION__ < 0x00030101
00125 #undef __HYPERVISOR_sched_op
00126 #define __HYPERVISOR_sched_op __HYPERVISOR_sched_op_compat
00127 #endif
00128 
00129 /* New event-channel and physdev hypercalls introduced in 0x00030202. */
00130 #if __XEN_INTERFACE_VERSION__ < 0x00030202
00131 #undef __HYPERVISOR_event_channel_op
00132 #define __HYPERVISOR_event_channel_op __HYPERVISOR_event_channel_op_compat
00133 #undef __HYPERVISOR_physdev_op
00134 #define __HYPERVISOR_physdev_op __HYPERVISOR_physdev_op_compat
00135 #endif
00136 
00137 /* New platform_op hypercall introduced in 0x00030204. */
00138 #if __XEN_INTERFACE_VERSION__ < 0x00030204
00139 #define __HYPERVISOR_dom0_op __HYPERVISOR_platform_op
00140 #endif
00141 
00142 /*
00143  * VIRTUAL INTERRUPTS
00144  *
00145  * Virtual interrupts that a guest OS may receive from Xen.
00146  *
00147  * In the side comments, 'V.' denotes a per-VCPU VIRQ while 'G.' denotes a
00148  * global VIRQ. The former can be bound once per VCPU and cannot be re-bound.
00149  * The latter can be allocated only once per guest: they must initially be
00150  * allocated to VCPU0 but can subsequently be re-bound.
00151  */
00152 /* ` enum virq { */
00153 #define VIRQ_TIMER      0  /* V. Timebase update, and/or requested timeout.  */
00154 #define VIRQ_DEBUG      1  /* V. Request guest to dump debug info.           */
00155 #define VIRQ_CONSOLE    2  /* G. (DOM0) Bytes received on emergency console. */
00156 #define VIRQ_DOM_EXC    3  /* G. (DOM0) Exceptional event for some domain.   */
00157 #define VIRQ_TBUF       4  /* G. (DOM0) Trace buffer has records available.  */
00158 #define VIRQ_DEBUGGER   6  /* G. (DOM0) A domain has paused for debugging.   */
00159 #define VIRQ_XENOPROF   7  /* V. XenOprofile interrupt: new sample available */
00160 #define VIRQ_CON_RING   8  /* G. (DOM0) Bytes received on console            */
00161 #define VIRQ_PCPU_STATE 9  /* G. (DOM0) PCPU state changed                   */
00162 #define VIRQ_MEM_EVENT  10 /* G. (DOM0) A memory event has occured           */
00163 #define VIRQ_XC_RESERVED 11 /* G. Reserved for XenClient                     */
00164 #define VIRQ_ENOMEM     12 /* G. (DOM0) Low on heap memory       */
00165 
00166 /* Architecture-specific VIRQ definitions. */
00167 #define VIRQ_ARCH_0    16
00168 #define VIRQ_ARCH_1    17
00169 #define VIRQ_ARCH_2    18
00170 #define VIRQ_ARCH_3    19
00171 #define VIRQ_ARCH_4    20
00172 #define VIRQ_ARCH_5    21
00173 #define VIRQ_ARCH_6    22
00174 #define VIRQ_ARCH_7    23
00175 /* ` } */
00176 
00177 #define NR_VIRQS       24
00178 
00179 /*
00180  * ` enum neg_errnoval
00181  * ` HYPERVISOR_mmu_update(const struct mmu_update reqs[],
00182  * `                       unsigned count, unsigned *done_out,
00183  * `                       unsigned foreigndom)
00184  * `
00185  * @reqs is an array of mmu_update_t structures ((ptr, val) pairs).
00186  * @count is the length of the above array.
00187  * @pdone is an output parameter indicating number of completed operations
00188  * @foreigndom[15:0]: FD, the expected owner of data pages referenced in this
00189  *                    hypercall invocation. Can be DOMID_SELF.
00190  * @foreigndom[31:16]: PFD, the expected owner of pagetable pages referenced
00191  *                     in this hypercall invocation. The value of this field
00192  *                     (x) encodes the PFD as follows:
00193  *                     x == 0 => PFD == DOMID_SELF
00194  *                     x != 0 => PFD == x - 1
00195  *
00196  * Sub-commands: ptr[1:0] specifies the appropriate MMU_* command.
00197  * -------------
00198  * ptr[1:0] == MMU_NORMAL_PT_UPDATE:
00199  * Updates an entry in a page table belonging to PFD. If updating an L1 table,
00200  * and the new table entry is valid/present, the mapped frame must belong to
00201  * FD. If attempting to map an I/O page then the caller assumes the privilege
00202  * of the FD.
00203  * FD == DOMID_IO: Permit /only/ I/O mappings, at the priv level of the caller.
00204  * FD == DOMID_XEN: Map restricted areas of Xen's heap space.
00205  * ptr[:2]  -- Machine address of the page-table entry to modify.
00206  * val      -- Value to write.
00207  *
00208  * There also certain implicit requirements when using this hypercall. The
00209  * pages that make up a pagetable must be mapped read-only in the guest.
00210  * This prevents uncontrolled guest updates to the pagetable. Xen strictly
00211  * enforces this, and will disallow any pagetable update which will end up
00212  * mapping pagetable page RW, and will disallow using any writable page as a
00213  * pagetable. In practice it means that when constructing a page table for a
00214  * process, thread, etc, we MUST be very dilligient in following these rules:
00215  *  1). Start with top-level page (PGD or in Xen language: L4). Fill out
00216  *      the entries.
00217  *  2). Keep on going, filling out the upper (PUD or L3), and middle (PMD
00218  *      or L2).
00219  *  3). Start filling out the PTE table (L1) with the PTE entries. Once
00220  *      done, make sure to set each of those entries to RO (so writeable bit
00221  *      is unset). Once that has been completed, set the PMD (L2) for this
00222  *      PTE table as RO.
00223  *  4). When completed with all of the PMD (L2) entries, and all of them have
00224  *      been set to RO, make sure to set RO the PUD (L3). Do the same
00225  *      operation on PGD (L4) pagetable entries that have a PUD (L3) entry.
00226  *  5). Now before you can use those pages (so setting the cr3), you MUST also
00227  *      pin them so that the hypervisor can verify the entries. This is done
00228  *      via the HYPERVISOR_mmuext_op(MMUEXT_PIN_L4_TABLE, guest physical frame
00229  *      number of the PGD (L4)). And this point the HYPERVISOR_mmuext_op(
00230  *      MMUEXT_NEW_BASEPTR, guest physical frame number of the PGD (L4)) can be
00231  *      issued.
00232  * For 32-bit guests, the L4 is not used (as there is less pagetables), so
00233  * instead use L3.
00234  * At this point the pagetables can be modified using the MMU_NORMAL_PT_UPDATE
00235  * hypercall. Also if so desired the OS can also try to write to the PTE
00236  * and be trapped by the hypervisor (as the PTE entry is RO).
00237  *
00238  * To deallocate the pages, the operations are the reverse of the steps
00239  * mentioned above. The argument is MMUEXT_UNPIN_TABLE for all levels and the
00240  * pagetable MUST not be in use (meaning that the cr3 is not set to it).
00241  *
00242  * ptr[1:0] == MMU_MACHPHYS_UPDATE:
00243  * Updates an entry in the machine->pseudo-physical mapping table.
00244  * ptr[:2]  -- Machine address within the frame whose mapping to modify.
00245  *             The frame must belong to the FD, if one is specified.
00246  * val      -- Value to write into the mapping entry.
00247  *
00248  * ptr[1:0] == MMU_PT_UPDATE_PRESERVE_AD:
00249  * As MMU_NORMAL_PT_UPDATE above, but A/D bits currently in the PTE are ORed
00250  * with those in @val.
00251  *
00252  * @val is usually the machine frame number along with some attributes.
00253  * The attributes by default follow the architecture defined bits. Meaning that
00254  * if this is a X86_64 machine and four page table layout is used, the layout
00255  * of val is:
00256  *  - 63 if set means No execute (NX)
00257  *  - 46-13 the machine frame number
00258  *  - 12 available for guest
00259  *  - 11 available for guest
00260  *  - 10 available for guest
00261  *  - 9 available for guest
00262  *  - 8 global
00263  *  - 7 PAT (PSE is disabled, must use hypercall to make 4MB or 2MB pages)
00264  *  - 6 dirty
00265  *  - 5 accessed
00266  *  - 4 page cached disabled
00267  *  - 3 page write through
00268  *  - 2 userspace accessible
00269  *  - 1 writeable
00270  *  - 0 present
00271  *
00272  *  The one bits that does not fit with the default layout is the PAGE_PSE
00273  *  also called PAGE_PAT). The MMUEXT_[UN]MARK_SUPER arguments to the
00274  *  HYPERVISOR_mmuext_op serve as mechanism to set a pagetable to be 4MB
00275  *  (or 2MB) instead of using the PAGE_PSE bit.
00276  *
00277  *  The reason that the PAGE_PSE (bit 7) is not being utilized is due to Xen
00278  *  using it as the Page Attribute Table (PAT) bit - for details on it please
00279  *  refer to Intel SDM 10.12. The PAT allows to set the caching attributes of
00280  *  pages instead of using MTRRs.
00281  *
00282  *  The PAT MSR is as follows (it is a 64-bit value, each entry is 8 bits):
00283  *                    PAT4                 PAT0
00284  *  +-----+-----+----+----+----+-----+----+----+
00285  *  | UC  | UC- | WC | WB | UC | UC- | WC | WB |  <= Linux
00286  *  +-----+-----+----+----+----+-----+----+----+
00287  *  | UC  | UC- | WT | WB | UC | UC- | WT | WB |  <= BIOS (default when machine boots)
00288  *  +-----+-----+----+----+----+-----+----+----+
00289  *  | rsv | rsv | WP | WC | UC | UC- | WT | WB |  <= Xen
00290  *  +-----+-----+----+----+----+-----+----+----+
00291  *
00292  *  The lookup of this index table translates to looking up
00293  *  Bit 7, Bit 4, and Bit 3 of val entry:
00294  *
00295  *  PAT/PSE (bit 7) ... PCD (bit 4) .. PWT (bit 3).
00296  *
00297  *  If all bits are off, then we are using PAT0. If bit 3 turned on,
00298  *  then we are using PAT1, if bit 3 and bit 4, then PAT2..
00299  *
00300  *  As you can see, the Linux PAT1 translates to PAT4 under Xen. Which means
00301  *  that if a guest that follows Linux's PAT setup and would like to set Write
00302  *  Combined on pages it MUST use PAT4 entry. Meaning that Bit 7 (PAGE_PAT) is
00303  *  set. For example, under Linux it only uses PAT0, PAT1, and PAT2 for the
00304  *  caching as:
00305  *
00306  *   WB = none (so PAT0)
00307  *   WC = PWT (bit 3 on)
00308  *   UC = PWT | PCD (bit 3 and 4 are on).
00309  *
00310  * To make it work with Xen, it needs to translate the WC bit as so:
00311  *
00312  *  PWT (so bit 3 on) --> PAT (so bit 7 is on) and clear bit 3
00313  *
00314  * And to translate back it would:
00315  *
00316  * PAT (bit 7 on) --> PWT (bit 3 on) and clear bit 7.
00317  */
00318 #define MMU_NORMAL_PT_UPDATE      0 /* checked '*ptr = val'. ptr is MA.      */
00319 #define MMU_MACHPHYS_UPDATE       1 /* ptr = MA of frame to modify entry for */
00320 #define MMU_PT_UPDATE_PRESERVE_AD 2 /* atomically: *ptr = val | (*ptr&(A|D)) */
00321 
00322 /*
00323  * MMU EXTENDED OPERATIONS
00324  *
00325  * ` enum neg_errnoval
00326  * ` HYPERVISOR_mmuext_op(mmuext_op_t uops[],
00327  * `                      unsigned int count,
00328  * `                      unsigned int *pdone,
00329  * `                      unsigned int foreigndom)
00330  */
00331 /* HYPERVISOR_mmuext_op() accepts a list of mmuext_op structures.
00332  * A foreigndom (FD) can be specified (or DOMID_SELF for none).
00333  * Where the FD has some effect, it is described below.
00334  *
00335  * cmd: MMUEXT_(UN)PIN_*_TABLE
00336  * mfn: Machine frame number to be (un)pinned as a p.t. page.
00337  *      The frame must belong to the FD, if one is specified.
00338  *
00339  * cmd: MMUEXT_NEW_BASEPTR
00340  * mfn: Machine frame number of new page-table base to install in MMU.
00341  *
00342  * cmd: MMUEXT_NEW_USER_BASEPTR [x86/64 only]
00343  * mfn: Machine frame number of new page-table base to install in MMU
00344  *      when in user space.
00345  *
00346  * cmd: MMUEXT_TLB_FLUSH_LOCAL
00347  * No additional arguments. Flushes local TLB.
00348  *
00349  * cmd: MMUEXT_INVLPG_LOCAL
00350  * linear_addr: Linear address to be flushed from the local TLB.
00351  *
00352  * cmd: MMUEXT_TLB_FLUSH_MULTI
00353  * vcpumask: Pointer to bitmap of VCPUs to be flushed.
00354  *
00355  * cmd: MMUEXT_INVLPG_MULTI
00356  * linear_addr: Linear address to be flushed.
00357  * vcpumask: Pointer to bitmap of VCPUs to be flushed.
00358  *
00359  * cmd: MMUEXT_TLB_FLUSH_ALL
00360  * No additional arguments. Flushes all VCPUs' TLBs.
00361  *
00362  * cmd: MMUEXT_INVLPG_ALL
00363  * linear_addr: Linear address to be flushed from all VCPUs' TLBs.
00364  *
00365  * cmd: MMUEXT_FLUSH_CACHE
00366  * No additional arguments. Writes back and flushes cache contents.
00367  *
00368  * cmd: MMUEXT_FLUSH_CACHE_GLOBAL
00369  * No additional arguments. Writes back and flushes cache contents
00370  * on all CPUs in the system.
00371  *
00372  * cmd: MMUEXT_SET_LDT
00373  * linear_addr: Linear address of LDT base (NB. must be page-aligned).
00374  * nr_ents: Number of entries in LDT.
00375  *
00376  * cmd: MMUEXT_CLEAR_PAGE
00377  * mfn: Machine frame number to be cleared.
00378  *
00379  * cmd: MMUEXT_COPY_PAGE
00380  * mfn: Machine frame number of the destination page.
00381  * src_mfn: Machine frame number of the source page.
00382  *
00383  * cmd: MMUEXT_[UN]MARK_SUPER
00384  * mfn: Machine frame number of head of superpage to be [un]marked.
00385  */
00386 /* ` enum mmuext_cmd { */
00387 #define MMUEXT_PIN_L1_TABLE      0
00388 #define MMUEXT_PIN_L2_TABLE      1
00389 #define MMUEXT_PIN_L3_TABLE      2
00390 #define MMUEXT_PIN_L4_TABLE      3
00391 #define MMUEXT_UNPIN_TABLE       4
00392 #define MMUEXT_NEW_BASEPTR       5
00393 #define MMUEXT_TLB_FLUSH_LOCAL   6
00394 #define MMUEXT_INVLPG_LOCAL      7
00395 #define MMUEXT_TLB_FLUSH_MULTI   8
00396 #define MMUEXT_INVLPG_MULTI      9
00397 #define MMUEXT_TLB_FLUSH_ALL    10
00398 #define MMUEXT_INVLPG_ALL       11
00399 #define MMUEXT_FLUSH_CACHE      12
00400 #define MMUEXT_SET_LDT          13
00401 #define MMUEXT_NEW_USER_BASEPTR 15
00402 #define MMUEXT_CLEAR_PAGE       16
00403 #define MMUEXT_COPY_PAGE        17
00404 #define MMUEXT_FLUSH_CACHE_GLOBAL 18
00405 #define MMUEXT_MARK_SUPER       19
00406 #define MMUEXT_UNMARK_SUPER     20
00407 /* ` } */
00408 
00409 #ifndef __ASSEMBLY__
00410 struct mmuext_op {
00411     unsigned int cmd; /* => enum mmuext_cmd */
00412     union {
00413         /* [UN]PIN_TABLE, NEW_BASEPTR, NEW_USER_BASEPTR
00414          * CLEAR_PAGE, COPY_PAGE, [UN]MARK_SUPER */
00415         xen_pfn_t     mfn;
00416         /* INVLPG_LOCAL, INVLPG_ALL, SET_LDT */
00417         unsigned long linear_addr;
00418     } arg1;
00419     union {
00420         /* SET_LDT */
00421         unsigned int nr_ents;
00422         /* TLB_FLUSH_MULTI, INVLPG_MULTI */
00423 #if __XEN_INTERFACE_VERSION__ >= 0x00030205
00424         XEN_GUEST_HANDLE(const_void) vcpumask;
00425 #else
00426         const void *vcpumask;
00427 #endif
00428         /* COPY_PAGE */
00429         xen_pfn_t src_mfn;
00430     } arg2;
00431 };
00432 typedef struct mmuext_op mmuext_op_t;
00433 DEFINE_XEN_GUEST_HANDLE(mmuext_op_t);
00434 #endif
00435 
00436 /*
00437  * ` enum neg_errnoval
00438  * ` HYPERVISOR_update_va_mapping(unsigned long va, u64 val,
00439  * `                              enum uvm_flags flags)
00440  * `
00441  * ` enum neg_errnoval
00442  * ` HYPERVISOR_update_va_mapping_otherdomain(unsigned long va, u64 val,
00443  * `                                          enum uvm_flags flags,
00444  * `                                          domid_t domid)
00445  * `
00446  * ` @va: The virtual address whose mapping we want to change
00447  * ` @val: The new page table entry, must contain a machine address
00448  * ` @flags: Control TLB flushes
00449  */
00450 /* These are passed as 'flags' to update_va_mapping. They can be ORed. */
00451 /* When specifying UVMF_MULTI, also OR in a pointer to a CPU bitmap.   */
00452 /* UVMF_LOCAL is merely UVMF_MULTI with a NULL bitmap pointer.         */
00453 /* ` enum uvm_flags { */
00454 #define UVMF_NONE               (0UL<<0) /* No flushing at all.   */
00455 #define UVMF_TLB_FLUSH          (1UL<<0) /* Flush entire TLB(s).  */
00456 #define UVMF_INVLPG             (2UL<<0) /* Flush only one entry. */
00457 #define UVMF_FLUSHTYPE_MASK     (3UL<<0)
00458 #define UVMF_MULTI              (0UL<<2) /* Flush subset of TLBs. */
00459 #define UVMF_LOCAL              (0UL<<2) /* Flush local TLB.      */
00460 #define UVMF_ALL                (1UL<<2) /* Flush all TLBs.       */
00461 /* ` } */
00462 
00463 /*
00464  * Commands to HYPERVISOR_console_io().
00465  */
00466 #define CONSOLEIO_write         0
00467 #define CONSOLEIO_read          1
00468 
00469 /*
00470  * Commands to HYPERVISOR_vm_assist().
00471  */
00472 #define VMASST_CMD_enable                0
00473 #define VMASST_CMD_disable               1
00474 
00475 /* x86/32 guests: simulate full 4GB segment limits. */
00476 #define VMASST_TYPE_4gb_segments         0
00477 
00478 /* x86/32 guests: trap (vector 15) whenever above vmassist is used. */
00479 #define VMASST_TYPE_4gb_segments_notify  1
00480 
00481 /*
00482  * x86 guests: support writes to bottom-level PTEs.
00483  * NB1. Page-directory entries cannot be written.
00484  * NB2. Guest must continue to remove all writable mappings of PTEs.
00485  */
00486 #define VMASST_TYPE_writable_pagetables  2
00487 
00488 /* x86/PAE guests: support PDPTs above 4GB. */
00489 #define VMASST_TYPE_pae_extended_cr3     3
00490 
00491 #define MAX_VMASST_TYPE                  3
00492 
00493 #ifndef __ASSEMBLY__
00494 
00495 typedef uint16_t domid_t;
00496 
00497 /* Domain ids >= DOMID_FIRST_RESERVED cannot be used for ordinary domains. */
00498 #define DOMID_FIRST_RESERVED (0x7FF0U)
00499 
00500 /* DOMID_SELF is used in certain contexts to refer to oneself. */
00501 #define DOMID_SELF (0x7FF0U)
00502 
00503 /*
00504  * DOMID_IO is used to restrict page-table updates to mapping I/O memory.
00505  * Although no Foreign Domain need be specified to map I/O pages, DOMID_IO
00506  * is useful to ensure that no mappings to the OS's own heap are accidentally
00507  * installed. (e.g., in Linux this could cause havoc as reference counts
00508  * aren't adjusted on the I/O-mapping code path).
00509  * This only makes sense in MMUEXT_SET_FOREIGNDOM, but in that context can
00510  * be specified by any calling domain.
00511  */
00512 #define DOMID_IO   (0x7FF1U)
00513 
00514 /*
00515  * DOMID_XEN is used to allow privileged domains to map restricted parts of
00516  * Xen's heap space (e.g., the machine_to_phys table).
00517  * This only makes sense in MMUEXT_SET_FOREIGNDOM, and is only permitted if
00518  * the caller is privileged.
00519  */
00520 #define DOMID_XEN  (0x7FF2U)
00521 
00522 /*
00523  * DOMID_COW is used as the owner of sharable pages */
00524 #define DOMID_COW  (0x7FF3U)
00525 
00526 /* DOMID_INVALID is used to identify pages with unknown owner. */
00527 #define DOMID_INVALID (0x7FF4U)
00528 
00529 /* Idle domain. */
00530 #define DOMID_IDLE (0x7FFFU)
00531 
00532 /*
00533  * Send an array of these to HYPERVISOR_mmu_update().
00534  * NB. The fields are natural pointer/address size for this architecture.
00535  */
00536 struct mmu_update {
00537     uint64_t ptr;       /* Machine address of PTE. */
00538     uint64_t val;       /* New contents of PTE.    */
00539 };
00540 typedef struct mmu_update mmu_update_t;
00541 DEFINE_XEN_GUEST_HANDLE(mmu_update_t);
00542 
00543 /*
00544  * ` enum neg_errnoval
00545  * ` HYPERVISOR_multicall(multicall_entry_t call_list[],
00546  * `                      uint32_t nr_calls);
00547  *
00548  * NB. The fields are logically the natural register size for this
00549  * architecture. In cases where xen_ulong_t is larger than this then
00550  * any unused bits in the upper portion must be zero.
00551  */
00552 struct multicall_entry {
00553     xen_ulong_t op, result;
00554     xen_ulong_t args[6];
00555 };
00556 typedef struct multicall_entry multicall_entry_t;
00557 DEFINE_XEN_GUEST_HANDLE(multicall_entry_t);
00558 
00559 #if __XEN_INTERFACE_VERSION__ < 0x00040400
00560 /*
00561  * Event channel endpoints per domain (when using the 2-level ABI):
00562  *  1024 if a long is 32 bits; 4096 if a long is 64 bits.
00563  */
00564 #define NR_EVENT_CHANNELS EVTCHN_2L_NR_CHANNELS
00565 #endif
00566 
00567 struct vcpu_time_info {
00568     /*
00569      * Updates to the following values are preceded and followed by an
00570      * increment of 'version'. The guest can therefore detect updates by
00571      * looking for changes to 'version'. If the least-significant bit of
00572      * the version number is set then an update is in progress and the guest
00573      * must wait to read a consistent set of values.
00574      * The correct way to interact with the version number is similar to
00575      * Linux's seqlock: see the implementations of read_seqbegin/read_seqretry.
00576      */
00577     uint32_t version;
00578     uint32_t pad0;
00579     uint64_t tsc_timestamp;   /* TSC at last update of time vals.  */
00580     uint64_t system_time;     /* Time, in nanosecs, since boot.    */
00581     /*
00582      * Current system time:
00583      *   system_time +
00584      *   ((((tsc - tsc_timestamp) << tsc_shift) * tsc_to_system_mul) >> 32)
00585      * CPU frequency (Hz):
00586      *   ((10^9 << 32) / tsc_to_system_mul) >> tsc_shift
00587      */
00588     uint32_t tsc_to_system_mul;
00589     int8_t   tsc_shift;
00590     int8_t   pad1[3];
00591 }; /* 32 bytes */
00592 typedef struct vcpu_time_info vcpu_time_info_t;
00593 
00594 struct vcpu_info {
00595     /*
00596      * 'evtchn_upcall_pending' is written non-zero by Xen to indicate
00597      * a pending notification for a particular VCPU. It is then cleared
00598      * by the guest OS /before/ checking for pending work, thus avoiding
00599      * a set-and-check race. Note that the mask is only accessed by Xen
00600      * on the CPU that is currently hosting the VCPU. This means that the
00601      * pending and mask flags can be updated by the guest without special
00602      * synchronisation (i.e., no need for the x86 LOCK prefix).
00603      * This may seem suboptimal because if the pending flag is set by
00604      * a different CPU then an IPI may be scheduled even when the mask
00605      * is set. However, note:
00606      *  1. The task of 'interrupt holdoff' is covered by the per-event-
00607      *     channel mask bits. A 'noisy' event that is continually being
00608      *     triggered can be masked at source at this very precise
00609      *     granularity.
00610      *  2. The main purpose of the per-VCPU mask is therefore to restrict
00611      *     reentrant execution: whether for concurrency control, or to
00612      *     prevent unbounded stack usage. Whatever the purpose, we expect
00613      *     that the mask will be asserted only for short periods at a time,
00614      *     and so the likelihood of a 'spurious' IPI is suitably small.
00615      * The mask is read before making an event upcall to the guest: a
00616      * non-zero mask therefore guarantees that the VCPU will not receive
00617      * an upcall activation. The mask is cleared when the VCPU requests
00618      * to block: this avoids wakeup-waiting races.
00619      */
00620     uint8_t evtchn_upcall_pending;
00621 #ifdef XEN_HAVE_PV_UPCALL_MASK
00622     uint8_t evtchn_upcall_mask;
00623 #else /* XEN_HAVE_PV_UPCALL_MASK */
00624     uint8_t pad0;
00625 #endif /* XEN_HAVE_PV_UPCALL_MASK */
00626     xen_ulong_t evtchn_pending_sel;
00627     struct arch_vcpu_info arch;
00628     struct vcpu_time_info time;
00629 }; /* 64 bytes (x86) */
00630 #ifndef __XEN__
00631 typedef struct vcpu_info vcpu_info_t;
00632 #endif
00633 
00634 /*
00635  * `incontents 200 startofday_shared Start-of-day shared data structure
00636  * Xen/kernel shared data -- pointer provided in start_info.
00637  *
00638  * This structure is defined to be both smaller than a page, and the
00639  * only data on the shared page, but may vary in actual size even within
00640  * compatible Xen versions; guests should not rely on the size
00641  * of this structure remaining constant.
00642  */
00643 struct shared_info {
00644     struct vcpu_info vcpu_info[XEN_LEGACY_MAX_VCPUS];
00645 
00646     /*
00647      * A domain can create "event channels" on which it can send and receive
00648      * asynchronous event notifications. There are three classes of event that
00649      * are delivered by this mechanism:
00650      *  1. Bi-directional inter- and intra-domain connections. Domains must
00651      *     arrange out-of-band to set up a connection (usually by allocating
00652      *     an unbound 'listener' port and avertising that via a storage service
00653      *     such as xenstore).
00654      *  2. Physical interrupts. A domain with suitable hardware-access
00655      *     privileges can bind an event-channel port to a physical interrupt
00656      *     source.
00657      *  3. Virtual interrupts ('events'). A domain can bind an event-channel
00658      *     port to a virtual interrupt source, such as the virtual-timer
00659      *     device or the emergency console.
00660      *
00661      * Event channels are addressed by a "port index". Each channel is
00662      * associated with two bits of information:
00663      *  1. PENDING -- notifies the domain that there is a pending notification
00664      *     to be processed. This bit is cleared by the guest.
00665      *  2. MASK -- if this bit is clear then a 0->1 transition of PENDING
00666      *     will cause an asynchronous upcall to be scheduled. This bit is only
00667      *     updated by the guest. It is read-only within Xen. If a channel
00668      *     becomes pending while the channel is masked then the 'edge' is lost
00669      *     (i.e., when the channel is unmasked, the guest must manually handle
00670      *     pending notifications as no upcall will be scheduled by Xen).
00671      *
00672      * To expedite scanning of pending notifications, any 0->1 pending
00673      * transition on an unmasked channel causes a corresponding bit in a
00674      * per-vcpu selector word to be set. Each bit in the selector covers a
00675      * 'C long' in the PENDING bitfield array.
00676      */
00677     xen_ulong_t evtchn_pending[sizeof(xen_ulong_t) * 8];
00678     xen_ulong_t evtchn_mask[sizeof(xen_ulong_t) * 8];
00679 
00680     /*
00681      * Wallclock time: updated only by control software. Guests should base
00682      * their gettimeofday() syscall on this wallclock-base value.
00683      */
00684     uint32_t wc_version;      /* Version counter: see vcpu_time_info_t. */
00685     uint32_t wc_sec;          /* Secs  00:00:00 UTC, Jan 1, 1970.  */
00686     uint32_t wc_nsec;         /* Nsecs 00:00:00 UTC, Jan 1, 1970.  */
00687 
00688     struct arch_shared_info arch;
00689 
00690 };
00691 #ifndef __XEN__
00692 typedef struct shared_info shared_info_t;
00693 #endif
00694 
00695 /*
00696  * `incontents 200 startofday Start-of-day memory layout
00697  *
00698  *  1. The domain is started within contiguous virtual-memory region.
00699  *  2. The contiguous region ends on an aligned 4MB boundary.
00700  *  3. This the order of bootstrap elements in the initial virtual region:
00701  *      a. relocated kernel image
00702  *      b. initial ram disk              [mod_start, mod_len]
00703  *      c. list of allocated page frames [mfn_list, nr_pages]
00704  *         (unless relocated due to XEN_ELFNOTE_INIT_P2M)
00705  *      d. start_info_t structure        [register ESI (x86)]
00706  *      e. bootstrap page tables         [pt_base and CR3 (x86)]
00707  *      f. bootstrap stack               [register ESP (x86)]
00708  *  4. Bootstrap elements are packed together, but each is 4kB-aligned.
00709  *  5. The initial ram disk may be omitted.
00710  *  6. The list of page frames forms a contiguous 'pseudo-physical' memory
00711  *     layout for the domain. In particular, the bootstrap virtual-memory
00712  *     region is a 1:1 mapping to the first section of the pseudo-physical map.
00713  *  7. All bootstrap elements are mapped read-writable for the guest OS. The
00714  *     only exception is the bootstrap page table, which is mapped read-only.
00715  *  8. There is guaranteed to be at least 512kB padding after the final
00716  *     bootstrap element. If necessary, the bootstrap virtual region is
00717  *     extended by an extra 4MB to ensure this.
00718  *
00719  * Note: Prior to 25833:bb85bbccb1c9. ("x86/32-on-64 adjust Dom0 initial page
00720  * table layout") a bug caused the pt_base (3.e above) and cr3 to not point
00721  * to the start of the guest page tables (it was offset by two pages).
00722  * This only manifested itself on 32-on-64 dom0 kernels and not 32-on-64 domU
00723  * or 64-bit kernels of any colour. The page tables for a 32-on-64 dom0 got
00724  * allocated in the order: 'first L1','first L2', 'first L3', so the offset
00725  * to the page table base is by two pages back. The initial domain if it is
00726  * 32-bit and runs under a 64-bit hypervisor should _NOT_ use two of the
00727  * pages preceding pt_base and mark them as reserved/unused.
00728  */
00729 #ifdef XEN_HAVE_PV_GUEST_ENTRY
00730 struct start_info {
00731     /* THE FOLLOWING ARE FILLED IN BOTH ON INITIAL BOOT AND ON RESUME.    */
00732     char magic[32];             /* "xen-<version>-<platform>".            */
00733     unsigned long nr_pages;     /* Total pages allocated to this domain.  */
00734     unsigned long shared_info;  /* MACHINE address of shared info struct. */
00735     uint32_t flags;             /* SIF_xxx flags.                         */
00736     xen_pfn_t store_mfn;        /* MACHINE page number of shared page.    */
00737     uint32_t store_evtchn;      /* Event channel for store communication. */
00738     union {
00739         struct {
00740             xen_pfn_t mfn;      /* MACHINE page number of console page.   */
00741             uint32_t  evtchn;   /* Event channel for console page.        */
00742         } domU;
00743         struct {
00744             uint32_t info_off;  /* Offset of console_info struct.         */
00745             uint32_t info_size; /* Size of console_info struct from start.*/
00746         } dom0;
00747     } console;
00748     /* THE FOLLOWING ARE ONLY FILLED IN ON INITIAL BOOT (NOT RESUME).     */
00749     unsigned long pt_base;      /* VIRTUAL address of page directory.     */
00750     unsigned long nr_pt_frames; /* Number of bootstrap p.t. frames.       */
00751     unsigned long mfn_list;     /* VIRTUAL address of page-frame list.    */
00752     unsigned long mod_start;    /* VIRTUAL address of pre-loaded module   */
00753                                 /* (PFN of pre-loaded module if           */
00754                                 /*  SIF_MOD_START_PFN set in flags).      */
00755     unsigned long mod_len;      /* Size (bytes) of pre-loaded module.     */
00756 #define MAX_GUEST_CMDLINE 1024
00757     int8_t cmd_line[MAX_GUEST_CMDLINE];
00758     /* The pfn range here covers both page table and p->m table frames.   */
00759     unsigned long first_p2m_pfn;/* 1st pfn forming initial P->M table.    */
00760     unsigned long nr_p2m_frames;/* # of pfns forming initial P->M table.  */
00761 };
00762 typedef struct start_info start_info_t;
00763 
00764 /* New console union for dom0 introduced in 0x00030203. */
00765 #if __XEN_INTERFACE_VERSION__ < 0x00030203
00766 #define console_mfn    console.domU.mfn
00767 #define console_evtchn console.domU.evtchn
00768 #endif
00769 #endif /* XEN_HAVE_PV_GUEST_ENTRY */
00770 
00771 /* These flags are passed in the 'flags' field of start_info_t. */
00772 #define SIF_PRIVILEGED    (1<<0)  /* Is the domain privileged? */
00773 #define SIF_INITDOMAIN    (1<<1)  /* Is this the initial control domain? */
00774 #define SIF_MULTIBOOT_MOD (1<<2)  /* Is mod_start a multiboot module? */
00775 #define SIF_MOD_START_PFN (1<<3)  /* Is mod_start a PFN? */
00776 #define SIF_PM_MASK       (0xFF<<8) /* reserve 1 byte for xen-pm options */
00777 
00778 /*
00779  * A multiboot module is a package containing modules very similar to a
00780  * multiboot module array. The only differences are:
00781  * - the array of module descriptors is by convention simply at the beginning
00782  *   of the multiboot module,
00783  * - addresses in the module descriptors are based on the beginning of the
00784  *   multiboot module,
00785  * - the number of modules is determined by a termination descriptor that has
00786  *   mod_start == 0.
00787  *
00788  * This permits to both build it statically and reference it in a configuration
00789  * file, and let the PV guest easily rebase the addresses to virtual addresses
00790  * and at the same time count the number of modules.
00791  */
00792 struct xen_multiboot_mod_list
00793 {
00794     /* Address of first byte of the module */
00795     uint32_t mod_start;
00796     /* Address of last byte of the module (inclusive) */
00797     uint32_t mod_end;
00798     /* Address of zero-terminated command line */
00799     uint32_t cmdline;
00800     /* Unused, must be zero */
00801     uint32_t pad;
00802 };
00803 /*
00804  * `incontents 200 startofday_dom0_console Dom0_console
00805  *
00806  * The console structure in start_info.console.dom0
00807  *
00808  * This structure includes a variety of information required to
00809  * have a working VGA/VESA console.
00810  */
00811 typedef struct dom0_vga_console_info {
00812     uint8_t video_type; /* DOM0_VGA_CONSOLE_??? */
00813 #define XEN_VGATYPE_TEXT_MODE_3 0x03
00814 #define XEN_VGATYPE_VESA_LFB    0x23
00815 #define XEN_VGATYPE_EFI_LFB     0x70
00816 
00817     union {
00818         struct {
00819             /* Font height, in pixels. */
00820             uint16_t font_height;
00821             /* Cursor location (column, row). */
00822             uint16_t cursor_x, cursor_y;
00823             /* Number of rows and columns (dimensions in characters). */
00824             uint16_t rows, columns;
00825         } text_mode_3;
00826 
00827         struct {
00828             /* Width and height, in pixels. */
00829             uint16_t width, height;
00830             /* Bytes per scan line. */
00831             uint16_t bytes_per_line;
00832             /* Bits per pixel. */
00833             uint16_t bits_per_pixel;
00834             /* LFB physical address, and size (in units of 64kB). */
00835             uint32_t lfb_base;
00836             uint32_t lfb_size;
00837             /* RGB mask offsets and sizes, as defined by VBE 1.2+ */
00838             uint8_t  red_pos, red_size;
00839             uint8_t  green_pos, green_size;
00840             uint8_t  blue_pos, blue_size;
00841             uint8_t  rsvd_pos, rsvd_size;
00842 #if __XEN_INTERFACE_VERSION__ >= 0x00030206
00843             /* VESA capabilities (offset 0xa, VESA command 0x4f00). */
00844             uint32_t gbl_caps;
00845             /* Mode attributes (offset 0x0, VESA command 0x4f01). */
00846             uint16_t mode_attrs;
00847 #endif
00848         } vesa_lfb;
00849     } u;
00850 } dom0_vga_console_info_t;
00851 #define xen_vga_console_info dom0_vga_console_info
00852 #define xen_vga_console_info_t dom0_vga_console_info_t
00853 
00854 typedef uint8_t xen_domain_handle_t[16];
00855 
00856 /* Turn a plain number into a C unsigned long constant. */
00857 #define __mk_unsigned_long(x) x ## UL
00858 #define mk_unsigned_long(x) __mk_unsigned_long(x)
00859 
00860 __DEFINE_XEN_GUEST_HANDLE(uint8,  uint8_t);
00861 __DEFINE_XEN_GUEST_HANDLE(uint16, uint16_t);
00862 __DEFINE_XEN_GUEST_HANDLE(uint32, uint32_t);
00863 __DEFINE_XEN_GUEST_HANDLE(uint64, uint64_t);
00864 
00865 #else /* __ASSEMBLY__ */
00866 
00867 /* In assembly code we cannot use C numeric constant suffixes. */
00868 #define mk_unsigned_long(x) x
00869 
00870 #endif /* !__ASSEMBLY__ */
00871 
00872 /* Default definitions for macros used by domctl/sysctl. */
00873 #if defined(__XEN__) || defined(__XEN_TOOLS__)
00874 
00875 #ifndef uint64_aligned_t
00876 #define uint64_aligned_t uint64_t
00877 #endif
00878 #ifndef XEN_GUEST_HANDLE_64
00879 #define XEN_GUEST_HANDLE_64(name) XEN_GUEST_HANDLE(name)
00880 #endif
00881 
00882 #ifndef __ASSEMBLY__
00883 struct xenctl_bitmap {
00884     XEN_GUEST_HANDLE_64(uint8) bitmap;
00885     uint32_t nr_bits;
00886 };
00887 #endif
00888 
00889 #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
00890 
00891 #endif /* __XEN_PUBLIC_XEN_H__ */
00892 
00893 /*
00894  * Local variables:
00895  * mode: C
00896  * c-file-style: "BSD"
00897  * c-basic-offset: 4
00898  * tab-width: 4
00899  * indent-tabs-mode: nil
00900  * End:
00901  */