Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: MIT */
0002 /******************************************************************************
0003  * xen.h
0004  *
0005  * Guest OS interface to Xen.
0006  *
0007  * Copyright (c) 2004, K A Fraser
0008  */
0009 
0010 #ifndef __XEN_PUBLIC_XEN_H__
0011 #define __XEN_PUBLIC_XEN_H__
0012 
0013 #include <asm/xen/interface.h>
0014 
0015 /*
0016  * XEN "SYSTEM CALLS" (a.k.a. HYPERCALLS).
0017  */
0018 
0019 /*
0020  * x86_32: EAX = vector; EBX, ECX, EDX, ESI, EDI = args 1, 2, 3, 4, 5.
0021  *         EAX = return value
0022  *         (argument registers may be clobbered on return)
0023  * x86_64: RAX = vector; RDI, RSI, RDX, R10, R8, R9 = args 1, 2, 3, 4, 5, 6.
0024  *         RAX = return value
0025  *         (argument registers not clobbered on return; RCX, R11 are)
0026  */
0027 #define __HYPERVISOR_set_trap_table        0
0028 #define __HYPERVISOR_mmu_update            1
0029 #define __HYPERVISOR_set_gdt               2
0030 #define __HYPERVISOR_stack_switch          3
0031 #define __HYPERVISOR_set_callbacks         4
0032 #define __HYPERVISOR_fpu_taskswitch        5
0033 #define __HYPERVISOR_sched_op_compat       6
0034 #define __HYPERVISOR_platform_op           7
0035 #define __HYPERVISOR_set_debugreg          8
0036 #define __HYPERVISOR_get_debugreg          9
0037 #define __HYPERVISOR_update_descriptor    10
0038 #define __HYPERVISOR_memory_op            12
0039 #define __HYPERVISOR_multicall            13
0040 #define __HYPERVISOR_update_va_mapping    14
0041 #define __HYPERVISOR_set_timer_op         15
0042 #define __HYPERVISOR_event_channel_op_compat 16
0043 #define __HYPERVISOR_xen_version          17
0044 #define __HYPERVISOR_console_io           18
0045 #define __HYPERVISOR_physdev_op_compat    19
0046 #define __HYPERVISOR_grant_table_op       20
0047 #define __HYPERVISOR_vm_assist            21
0048 #define __HYPERVISOR_update_va_mapping_otherdomain 22
0049 #define __HYPERVISOR_iret                 23 /* x86 only */
0050 #define __HYPERVISOR_vcpu_op              24
0051 #define __HYPERVISOR_set_segment_base     25 /* x86/64 only */
0052 #define __HYPERVISOR_mmuext_op            26
0053 #define __HYPERVISOR_xsm_op               27
0054 #define __HYPERVISOR_nmi_op               28
0055 #define __HYPERVISOR_sched_op             29
0056 #define __HYPERVISOR_callback_op          30
0057 #define __HYPERVISOR_xenoprof_op          31
0058 #define __HYPERVISOR_event_channel_op     32
0059 #define __HYPERVISOR_physdev_op           33
0060 #define __HYPERVISOR_hvm_op               34
0061 #define __HYPERVISOR_sysctl               35
0062 #define __HYPERVISOR_domctl               36
0063 #define __HYPERVISOR_kexec_op             37
0064 #define __HYPERVISOR_tmem_op              38
0065 #define __HYPERVISOR_xc_reserved_op       39 /* reserved for XenClient */
0066 #define __HYPERVISOR_xenpmu_op            40
0067 #define __HYPERVISOR_dm_op                41
0068 
0069 /* Architecture-specific hypercall definitions. */
0070 #define __HYPERVISOR_arch_0               48
0071 #define __HYPERVISOR_arch_1               49
0072 #define __HYPERVISOR_arch_2               50
0073 #define __HYPERVISOR_arch_3               51
0074 #define __HYPERVISOR_arch_4               52
0075 #define __HYPERVISOR_arch_5               53
0076 #define __HYPERVISOR_arch_6               54
0077 #define __HYPERVISOR_arch_7               55
0078 
0079 /*
0080  * VIRTUAL INTERRUPTS
0081  *
0082  * Virtual interrupts that a guest OS may receive from Xen.
0083  * In the side comments, 'V.' denotes a per-VCPU VIRQ while 'G.' denotes a
0084  * global VIRQ. The former can be bound once per VCPU and cannot be re-bound.
0085  * The latter can be allocated only once per guest: they must initially be
0086  * allocated to VCPU0 but can subsequently be re-bound.
0087  */
0088 #define VIRQ_TIMER      0  /* V. Timebase update, and/or requested timeout.  */
0089 #define VIRQ_DEBUG      1  /* V. Request guest to dump debug info.           */
0090 #define VIRQ_CONSOLE    2  /* G. (DOM0) Bytes received on emergency console. */
0091 #define VIRQ_DOM_EXC    3  /* G. (DOM0) Exceptional event for some domain.   */
0092 #define VIRQ_TBUF       4  /* G. (DOM0) Trace buffer has records available.  */
0093 #define VIRQ_DEBUGGER   6  /* G. (DOM0) A domain has paused for debugging.   */
0094 #define VIRQ_XENOPROF   7  /* V. XenOprofile interrupt: new sample available */
0095 #define VIRQ_CON_RING   8  /* G. (DOM0) Bytes received on console            */
0096 #define VIRQ_PCPU_STATE 9  /* G. (DOM0) PCPU state changed                   */
0097 #define VIRQ_MEM_EVENT  10 /* G. (DOM0) A memory event has occured           */
0098 #define VIRQ_XC_RESERVED 11 /* G. Reserved for XenClient                     */
0099 #define VIRQ_ENOMEM     12 /* G. (DOM0) Low on heap memory       */
0100 #define VIRQ_XENPMU     13  /* PMC interrupt                                 */
0101 
0102 /* Architecture-specific VIRQ definitions. */
0103 #define VIRQ_ARCH_0    16
0104 #define VIRQ_ARCH_1    17
0105 #define VIRQ_ARCH_2    18
0106 #define VIRQ_ARCH_3    19
0107 #define VIRQ_ARCH_4    20
0108 #define VIRQ_ARCH_5    21
0109 #define VIRQ_ARCH_6    22
0110 #define VIRQ_ARCH_7    23
0111 
0112 #define NR_VIRQS       24
0113 
0114 /*
0115  * enum neg_errnoval HYPERVISOR_mmu_update(const struct mmu_update reqs[],
0116  *                                         unsigned count, unsigned *done_out,
0117  *                                         unsigned foreigndom)
0118  * @reqs is an array of mmu_update_t structures ((ptr, val) pairs).
0119  * @count is the length of the above array.
0120  * @pdone is an output parameter indicating number of completed operations
0121  * @foreigndom[15:0]: FD, the expected owner of data pages referenced in this
0122  *                    hypercall invocation. Can be DOMID_SELF.
0123  * @foreigndom[31:16]: PFD, the expected owner of pagetable pages referenced
0124  *                     in this hypercall invocation. The value of this field
0125  *                     (x) encodes the PFD as follows:
0126  *                     x == 0 => PFD == DOMID_SELF
0127  *                     x != 0 => PFD == x - 1
0128  *
0129  * Sub-commands: ptr[1:0] specifies the appropriate MMU_* command.
0130  * -------------
0131  * ptr[1:0] == MMU_NORMAL_PT_UPDATE:
0132  * Updates an entry in a page table belonging to PFD. If updating an L1 table,
0133  * and the new table entry is valid/present, the mapped frame must belong to
0134  * FD. If attempting to map an I/O page then the caller assumes the privilege
0135  * of the FD.
0136  * FD == DOMID_IO: Permit /only/ I/O mappings, at the priv level of the caller.
0137  * FD == DOMID_XEN: Map restricted areas of Xen's heap space.
0138  * ptr[:2]  -- Machine address of the page-table entry to modify.
0139  * val      -- Value to write.
0140  *
0141  * There also certain implicit requirements when using this hypercall. The
0142  * pages that make up a pagetable must be mapped read-only in the guest.
0143  * This prevents uncontrolled guest updates to the pagetable. Xen strictly
0144  * enforces this, and will disallow any pagetable update which will end up
0145  * mapping pagetable page RW, and will disallow using any writable page as a
0146  * pagetable. In practice it means that when constructing a page table for a
0147  * process, thread, etc, we MUST be very dilligient in following these rules:
0148  *  1). Start with top-level page (PGD or in Xen language: L4). Fill out
0149  *      the entries.
0150  *  2). Keep on going, filling out the upper (PUD or L3), and middle (PMD
0151  *      or L2).
0152  *  3). Start filling out the PTE table (L1) with the PTE entries. Once
0153  *      done, make sure to set each of those entries to RO (so writeable bit
0154  *      is unset). Once that has been completed, set the PMD (L2) for this
0155  *      PTE table as RO.
0156  *  4). When completed with all of the PMD (L2) entries, and all of them have
0157  *      been set to RO, make sure to set RO the PUD (L3). Do the same
0158  *      operation on PGD (L4) pagetable entries that have a PUD (L3) entry.
0159  *  5). Now before you can use those pages (so setting the cr3), you MUST also
0160  *      pin them so that the hypervisor can verify the entries. This is done
0161  *      via the HYPERVISOR_mmuext_op(MMUEXT_PIN_L4_TABLE, guest physical frame
0162  *      number of the PGD (L4)). And this point the HYPERVISOR_mmuext_op(
0163  *      MMUEXT_NEW_BASEPTR, guest physical frame number of the PGD (L4)) can be
0164  *      issued.
0165  * For 32-bit guests, the L4 is not used (as there is less pagetables), so
0166  * instead use L3.
0167  * At this point the pagetables can be modified using the MMU_NORMAL_PT_UPDATE
0168  * hypercall. Also if so desired the OS can also try to write to the PTE
0169  * and be trapped by the hypervisor (as the PTE entry is RO).
0170  *
0171  * To deallocate the pages, the operations are the reverse of the steps
0172  * mentioned above. The argument is MMUEXT_UNPIN_TABLE for all levels and the
0173  * pagetable MUST not be in use (meaning that the cr3 is not set to it).
0174  *
0175  * ptr[1:0] == MMU_MACHPHYS_UPDATE:
0176  * Updates an entry in the machine->pseudo-physical mapping table.
0177  * ptr[:2]  -- Machine address within the frame whose mapping to modify.
0178  *             The frame must belong to the FD, if one is specified.
0179  * val      -- Value to write into the mapping entry.
0180  *
0181  * ptr[1:0] == MMU_PT_UPDATE_PRESERVE_AD:
0182  * As MMU_NORMAL_PT_UPDATE above, but A/D bits currently in the PTE are ORed
0183  * with those in @val.
0184  *
0185  * @val is usually the machine frame number along with some attributes.
0186  * The attributes by default follow the architecture defined bits. Meaning that
0187  * if this is a X86_64 machine and four page table layout is used, the layout
0188  * of val is:
0189  *  - 63 if set means No execute (NX)
0190  *  - 46-13 the machine frame number
0191  *  - 12 available for guest
0192  *  - 11 available for guest
0193  *  - 10 available for guest
0194  *  - 9 available for guest
0195  *  - 8 global
0196  *  - 7 PAT (PSE is disabled, must use hypercall to make 4MB or 2MB pages)
0197  *  - 6 dirty
0198  *  - 5 accessed
0199  *  - 4 page cached disabled
0200  *  - 3 page write through
0201  *  - 2 userspace accessible
0202  *  - 1 writeable
0203  *  - 0 present
0204  *
0205  *  The one bits that does not fit with the default layout is the PAGE_PSE
0206  *  also called PAGE_PAT). The MMUEXT_[UN]MARK_SUPER arguments to the
0207  *  HYPERVISOR_mmuext_op serve as mechanism to set a pagetable to be 4MB
0208  *  (or 2MB) instead of using the PAGE_PSE bit.
0209  *
0210  *  The reason that the PAGE_PSE (bit 7) is not being utilized is due to Xen
0211  *  using it as the Page Attribute Table (PAT) bit - for details on it please
0212  *  refer to Intel SDM 10.12. The PAT allows to set the caching attributes of
0213  *  pages instead of using MTRRs.
0214  *
0215  *  The PAT MSR is as follows (it is a 64-bit value, each entry is 8 bits):
0216  *                    PAT4                 PAT0
0217  *  +-----+-----+----+----+----+-----+----+----+
0218  *  | UC  | UC- | WC | WB | UC | UC- | WC | WB |  <= Linux
0219  *  +-----+-----+----+----+----+-----+----+----+
0220  *  | UC  | UC- | WT | WB | UC | UC- | WT | WB |  <= BIOS (default when machine boots)
0221  *  +-----+-----+----+----+----+-----+----+----+
0222  *  | rsv | rsv | WP | WC | UC | UC- | WT | WB |  <= Xen
0223  *  +-----+-----+----+----+----+-----+----+----+
0224  *
0225  *  The lookup of this index table translates to looking up
0226  *  Bit 7, Bit 4, and Bit 3 of val entry:
0227  *
0228  *  PAT/PSE (bit 7) ... PCD (bit 4) .. PWT (bit 3).
0229  *
0230  *  If all bits are off, then we are using PAT0. If bit 3 turned on,
0231  *  then we are using PAT1, if bit 3 and bit 4, then PAT2..
0232  *
0233  *  As you can see, the Linux PAT1 translates to PAT4 under Xen. Which means
0234  *  that if a guest that follows Linux's PAT setup and would like to set Write
0235  *  Combined on pages it MUST use PAT4 entry. Meaning that Bit 7 (PAGE_PAT) is
0236  *  set. For example, under Linux it only uses PAT0, PAT1, and PAT2 for the
0237  *  caching as:
0238  *
0239  *   WB = none (so PAT0)
0240  *   WC = PWT (bit 3 on)
0241  *   UC = PWT | PCD (bit 3 and 4 are on).
0242  *
0243  * To make it work with Xen, it needs to translate the WC bit as so:
0244  *
0245  *  PWT (so bit 3 on) --> PAT (so bit 7 is on) and clear bit 3
0246  *
0247  * And to translate back it would:
0248  *
0249  * PAT (bit 7 on) --> PWT (bit 3 on) and clear bit 7.
0250  */
0251 #define MMU_NORMAL_PT_UPDATE       0 /* checked '*ptr = val'. ptr is MA.      */
0252 #define MMU_MACHPHYS_UPDATE        1 /* ptr = MA of frame to modify entry for */
0253 #define MMU_PT_UPDATE_PRESERVE_AD  2 /* atomically: *ptr = val | (*ptr&(A|D)) */
0254 #define MMU_PT_UPDATE_NO_TRANSLATE 3 /* checked '*ptr = val'. ptr is MA.      */
0255 
0256 /*
0257  * MMU EXTENDED OPERATIONS
0258  *
0259  * enum neg_errnoval HYPERVISOR_mmuext_op(mmuext_op_t uops[],
0260  *                                        unsigned int count,
0261  *                                        unsigned int *pdone,
0262  *                                        unsigned int foreigndom)
0263  */
0264 /* HYPERVISOR_mmuext_op() accepts a list of mmuext_op structures.
0265  * A foreigndom (FD) can be specified (or DOMID_SELF for none).
0266  * Where the FD has some effect, it is described below.
0267  *
0268  * cmd: MMUEXT_(UN)PIN_*_TABLE
0269  * mfn: Machine frame number to be (un)pinned as a p.t. page.
0270  *      The frame must belong to the FD, if one is specified.
0271  *
0272  * cmd: MMUEXT_NEW_BASEPTR
0273  * mfn: Machine frame number of new page-table base to install in MMU.
0274  *
0275  * cmd: MMUEXT_NEW_USER_BASEPTR [x86/64 only]
0276  * mfn: Machine frame number of new page-table base to install in MMU
0277  *      when in user space.
0278  *
0279  * cmd: MMUEXT_TLB_FLUSH_LOCAL
0280  * No additional arguments. Flushes local TLB.
0281  *
0282  * cmd: MMUEXT_INVLPG_LOCAL
0283  * linear_addr: Linear address to be flushed from the local TLB.
0284  *
0285  * cmd: MMUEXT_TLB_FLUSH_MULTI
0286  * vcpumask: Pointer to bitmap of VCPUs to be flushed.
0287  *
0288  * cmd: MMUEXT_INVLPG_MULTI
0289  * linear_addr: Linear address to be flushed.
0290  * vcpumask: Pointer to bitmap of VCPUs to be flushed.
0291  *
0292  * cmd: MMUEXT_TLB_FLUSH_ALL
0293  * No additional arguments. Flushes all VCPUs' TLBs.
0294  *
0295  * cmd: MMUEXT_INVLPG_ALL
0296  * linear_addr: Linear address to be flushed from all VCPUs' TLBs.
0297  *
0298  * cmd: MMUEXT_FLUSH_CACHE
0299  * No additional arguments. Writes back and flushes cache contents.
0300  *
0301  * cmd: MMUEXT_FLUSH_CACHE_GLOBAL
0302  * No additional arguments. Writes back and flushes cache contents
0303  * on all CPUs in the system.
0304  *
0305  * cmd: MMUEXT_SET_LDT
0306  * linear_addr: Linear address of LDT base (NB. must be page-aligned).
0307  * nr_ents: Number of entries in LDT.
0308  *
0309  * cmd: MMUEXT_CLEAR_PAGE
0310  * mfn: Machine frame number to be cleared.
0311  *
0312  * cmd: MMUEXT_COPY_PAGE
0313  * mfn: Machine frame number of the destination page.
0314  * src_mfn: Machine frame number of the source page.
0315  *
0316  * cmd: MMUEXT_[UN]MARK_SUPER
0317  * mfn: Machine frame number of head of superpage to be [un]marked.
0318  */
0319 #define MMUEXT_PIN_L1_TABLE      0
0320 #define MMUEXT_PIN_L2_TABLE      1
0321 #define MMUEXT_PIN_L3_TABLE      2
0322 #define MMUEXT_PIN_L4_TABLE      3
0323 #define MMUEXT_UNPIN_TABLE       4
0324 #define MMUEXT_NEW_BASEPTR       5
0325 #define MMUEXT_TLB_FLUSH_LOCAL   6
0326 #define MMUEXT_INVLPG_LOCAL      7
0327 #define MMUEXT_TLB_FLUSH_MULTI   8
0328 #define MMUEXT_INVLPG_MULTI      9
0329 #define MMUEXT_TLB_FLUSH_ALL    10
0330 #define MMUEXT_INVLPG_ALL       11
0331 #define MMUEXT_FLUSH_CACHE      12
0332 #define MMUEXT_SET_LDT          13
0333 #define MMUEXT_NEW_USER_BASEPTR 15
0334 #define MMUEXT_CLEAR_PAGE       16
0335 #define MMUEXT_COPY_PAGE        17
0336 #define MMUEXT_FLUSH_CACHE_GLOBAL 18
0337 #define MMUEXT_MARK_SUPER       19
0338 #define MMUEXT_UNMARK_SUPER     20
0339 
0340 #ifndef __ASSEMBLY__
0341 struct mmuext_op {
0342     unsigned int cmd;
0343     union {
0344         /* [UN]PIN_TABLE, NEW_BASEPTR, NEW_USER_BASEPTR
0345          * CLEAR_PAGE, COPY_PAGE, [UN]MARK_SUPER */
0346         xen_pfn_t mfn;
0347         /* INVLPG_LOCAL, INVLPG_ALL, SET_LDT */
0348         unsigned long linear_addr;
0349     } arg1;
0350     union {
0351         /* SET_LDT */
0352         unsigned int nr_ents;
0353         /* TLB_FLUSH_MULTI, INVLPG_MULTI */
0354         void *vcpumask;
0355         /* COPY_PAGE */
0356         xen_pfn_t src_mfn;
0357     } arg2;
0358 };
0359 DEFINE_GUEST_HANDLE_STRUCT(mmuext_op);
0360 #endif
0361 
0362 /* These are passed as 'flags' to update_va_mapping. They can be ORed. */
0363 /* When specifying UVMF_MULTI, also OR in a pointer to a CPU bitmap.   */
0364 /* UVMF_LOCAL is merely UVMF_MULTI with a NULL bitmap pointer.         */
0365 #define UVMF_NONE               (0UL<<0) /* No flushing at all.   */
0366 #define UVMF_TLB_FLUSH          (1UL<<0) /* Flush entire TLB(s).  */
0367 #define UVMF_INVLPG             (2UL<<0) /* Flush only one entry. */
0368 #define UVMF_FLUSHTYPE_MASK     (3UL<<0)
0369 #define UVMF_MULTI              (0UL<<2) /* Flush subset of TLBs. */
0370 #define UVMF_LOCAL              (0UL<<2) /* Flush local TLB.      */
0371 #define UVMF_ALL                (1UL<<2) /* Flush all TLBs.       */
0372 
0373 /*
0374  * Commands to HYPERVISOR_console_io().
0375  */
0376 #define CONSOLEIO_write         0
0377 #define CONSOLEIO_read          1
0378 
0379 /*
0380  * Commands to HYPERVISOR_vm_assist().
0381  */
0382 #define VMASST_CMD_enable                0
0383 #define VMASST_CMD_disable               1
0384 
0385 /* x86/32 guests: simulate full 4GB segment limits. */
0386 #define VMASST_TYPE_4gb_segments         0
0387 
0388 /* x86/32 guests: trap (vector 15) whenever above vmassist is used. */
0389 #define VMASST_TYPE_4gb_segments_notify  1
0390 
0391 /*
0392  * x86 guests: support writes to bottom-level PTEs.
0393  * NB1. Page-directory entries cannot be written.
0394  * NB2. Guest must continue to remove all writable mappings of PTEs.
0395  */
0396 #define VMASST_TYPE_writable_pagetables  2
0397 
0398 /* x86/PAE guests: support PDPTs above 4GB. */
0399 #define VMASST_TYPE_pae_extended_cr3     3
0400 
0401 /*
0402  * x86 guests: Sane behaviour for virtual iopl
0403  *  - virtual iopl updated from do_iret() hypercalls.
0404  *  - virtual iopl reported in bounce frames.
0405  *  - guest kernels assumed to be level 0 for the purpose of iopl checks.
0406  */
0407 #define VMASST_TYPE_architectural_iopl   4
0408 
0409 /*
0410  * All guests: activate update indicator in vcpu_runstate_info
0411  * Enable setting the XEN_RUNSTATE_UPDATE flag in guest memory mapped
0412  * vcpu_runstate_info during updates of the runstate information.
0413  */
0414 #define VMASST_TYPE_runstate_update_flag 5
0415 
0416 #define MAX_VMASST_TYPE 5
0417 
0418 #ifndef __ASSEMBLY__
0419 
0420 typedef uint16_t domid_t;
0421 
0422 /* Domain ids >= DOMID_FIRST_RESERVED cannot be used for ordinary domains. */
0423 #define DOMID_FIRST_RESERVED (0x7FF0U)
0424 
0425 /* DOMID_SELF is used in certain contexts to refer to oneself. */
0426 #define DOMID_SELF (0x7FF0U)
0427 
0428 /*
0429  * DOMID_IO is used to restrict page-table updates to mapping I/O memory.
0430  * Although no Foreign Domain need be specified to map I/O pages, DOMID_IO
0431  * is useful to ensure that no mappings to the OS's own heap are accidentally
0432  * installed. (e.g., in Linux this could cause havoc as reference counts
0433  * aren't adjusted on the I/O-mapping code path).
0434  * This only makes sense in MMUEXT_SET_FOREIGNDOM, but in that context can
0435  * be specified by any calling domain.
0436  */
0437 #define DOMID_IO   (0x7FF1U)
0438 
0439 /*
0440  * DOMID_XEN is used to allow privileged domains to map restricted parts of
0441  * Xen's heap space (e.g., the machine_to_phys table).
0442  * This only makes sense in MMUEXT_SET_FOREIGNDOM, and is only permitted if
0443  * the caller is privileged.
0444  */
0445 #define DOMID_XEN  (0x7FF2U)
0446 
0447 /* DOMID_COW is used as the owner of sharable pages */
0448 #define DOMID_COW  (0x7FF3U)
0449 
0450 /* DOMID_INVALID is used to identify pages with unknown owner. */
0451 #define DOMID_INVALID (0x7FF4U)
0452 
0453 /* Idle domain. */
0454 #define DOMID_IDLE (0x7FFFU)
0455 
0456 /*
0457  * Send an array of these to HYPERVISOR_mmu_update().
0458  * NB. The fields are natural pointer/address size for this architecture.
0459  */
0460 struct mmu_update {
0461     uint64_t ptr;       /* Machine address of PTE. */
0462     uint64_t val;       /* New contents of PTE.    */
0463 };
0464 DEFINE_GUEST_HANDLE_STRUCT(mmu_update);
0465 
0466 /*
0467  * Send an array of these to HYPERVISOR_multicall().
0468  * NB. The fields are logically the natural register size for this
0469  * architecture. In cases where xen_ulong_t is larger than this then
0470  * any unused bits in the upper portion must be zero.
0471  */
0472 struct multicall_entry {
0473     xen_ulong_t op;
0474     xen_long_t result;
0475     xen_ulong_t args[6];
0476 };
0477 DEFINE_GUEST_HANDLE_STRUCT(multicall_entry);
0478 
0479 struct vcpu_time_info {
0480     /*
0481      * Updates to the following values are preceded and followed
0482      * by an increment of 'version'. The guest can therefore
0483      * detect updates by looking for changes to 'version'. If the
0484      * least-significant bit of the version number is set then an
0485      * update is in progress and the guest must wait to read a
0486      * consistent set of values.  The correct way to interact with
0487      * the version number is similar to Linux's seqlock: see the
0488      * implementations of read_seqbegin/read_seqretry.
0489      */
0490     uint32_t version;
0491     uint32_t pad0;
0492     uint64_t tsc_timestamp;   /* TSC at last update of time vals.  */
0493     uint64_t system_time;     /* Time, in nanosecs, since boot.    */
0494     /*
0495      * Current system time:
0496      *   system_time + ((tsc - tsc_timestamp) << tsc_shift) * tsc_to_system_mul
0497      * CPU frequency (Hz):
0498      *   ((10^9 << 32) / tsc_to_system_mul) >> tsc_shift
0499      */
0500     uint32_t tsc_to_system_mul;
0501     int8_t   tsc_shift;
0502     int8_t   pad1[3];
0503 }; /* 32 bytes */
0504 
0505 struct vcpu_info {
0506     /*
0507      * 'evtchn_upcall_pending' is written non-zero by Xen to indicate
0508      * a pending notification for a particular VCPU. It is then cleared
0509      * by the guest OS /before/ checking for pending work, thus avoiding
0510      * a set-and-check race. Note that the mask is only accessed by Xen
0511      * on the CPU that is currently hosting the VCPU. This means that the
0512      * pending and mask flags can be updated by the guest without special
0513      * synchronisation (i.e., no need for the x86 LOCK prefix).
0514      * This may seem suboptimal because if the pending flag is set by
0515      * a different CPU then an IPI may be scheduled even when the mask
0516      * is set. However, note:
0517      *  1. The task of 'interrupt holdoff' is covered by the per-event-
0518      *     channel mask bits. A 'noisy' event that is continually being
0519      *     triggered can be masked at source at this very precise
0520      *     granularity.
0521      *  2. The main purpose of the per-VCPU mask is therefore to restrict
0522      *     reentrant execution: whether for concurrency control, or to
0523      *     prevent unbounded stack usage. Whatever the purpose, we expect
0524      *     that the mask will be asserted only for short periods at a time,
0525      *     and so the likelihood of a 'spurious' IPI is suitably small.
0526      * The mask is read before making an event upcall to the guest: a
0527      * non-zero mask therefore guarantees that the VCPU will not receive
0528      * an upcall activation. The mask is cleared when the VCPU requests
0529      * to block: this avoids wakeup-waiting races.
0530      */
0531     uint8_t evtchn_upcall_pending;
0532     uint8_t evtchn_upcall_mask;
0533     xen_ulong_t evtchn_pending_sel;
0534     struct arch_vcpu_info arch;
0535     struct pvclock_vcpu_time_info time;
0536 }; /* 64 bytes (x86) */
0537 
0538 /*
0539  * Xen/kernel shared data -- pointer provided in start_info.
0540  * NB. We expect that this struct is smaller than a page.
0541  */
0542 struct shared_info {
0543     struct vcpu_info vcpu_info[MAX_VIRT_CPUS];
0544 
0545     /*
0546      * A domain can create "event channels" on which it can send and receive
0547      * asynchronous event notifications. There are three classes of event that
0548      * are delivered by this mechanism:
0549      *  1. Bi-directional inter- and intra-domain connections. Domains must
0550      *     arrange out-of-band to set up a connection (usually by allocating
0551      *     an unbound 'listener' port and avertising that via a storage service
0552      *     such as xenstore).
0553      *  2. Physical interrupts. A domain with suitable hardware-access
0554      *     privileges can bind an event-channel port to a physical interrupt
0555      *     source.
0556      *  3. Virtual interrupts ('events'). A domain can bind an event-channel
0557      *     port to a virtual interrupt source, such as the virtual-timer
0558      *     device or the emergency console.
0559      *
0560      * Event channels are addressed by a "port index". Each channel is
0561      * associated with two bits of information:
0562      *  1. PENDING -- notifies the domain that there is a pending notification
0563      *     to be processed. This bit is cleared by the guest.
0564      *  2. MASK -- if this bit is clear then a 0->1 transition of PENDING
0565      *     will cause an asynchronous upcall to be scheduled. This bit is only
0566      *     updated by the guest. It is read-only within Xen. If a channel
0567      *     becomes pending while the channel is masked then the 'edge' is lost
0568      *     (i.e., when the channel is unmasked, the guest must manually handle
0569      *     pending notifications as no upcall will be scheduled by Xen).
0570      *
0571      * To expedite scanning of pending notifications, any 0->1 pending
0572      * transition on an unmasked channel causes a corresponding bit in a
0573      * per-vcpu selector word to be set. Each bit in the selector covers a
0574      * 'C long' in the PENDING bitfield array.
0575      */
0576     xen_ulong_t evtchn_pending[sizeof(xen_ulong_t) * 8];
0577     xen_ulong_t evtchn_mask[sizeof(xen_ulong_t) * 8];
0578 
0579     /*
0580      * Wallclock time: updated only by control software. Guests should base
0581      * their gettimeofday() syscall on this wallclock-base value.
0582      */
0583     struct pvclock_wall_clock wc;
0584 #ifndef CONFIG_X86_32
0585     uint32_t wc_sec_hi;
0586 #endif
0587     struct arch_shared_info arch;
0588 
0589 };
0590 
0591 /*
0592  * Start-of-day memory layout
0593  *
0594  *  1. The domain is started within contiguous virtual-memory region.
0595  *  2. The contiguous region begins and ends on an aligned 4MB boundary.
0596  *  3. This the order of bootstrap elements in the initial virtual region:
0597  *      a. relocated kernel image
0598  *      b. initial ram disk              [mod_start, mod_len]
0599  *         (may be omitted)
0600  *      c. list of allocated page frames [mfn_list, nr_pages]
0601  *         (unless relocated due to XEN_ELFNOTE_INIT_P2M)
0602  *      d. start_info_t structure        [register ESI (x86)]
0603  *         in case of dom0 this page contains the console info, too
0604  *      e. unless dom0: xenstore ring page
0605  *      f. unless dom0: console ring page
0606  *      g. bootstrap page tables         [pt_base, CR3 (x86)]
0607  *      h. bootstrap stack               [register ESP (x86)]
0608  *  4. Bootstrap elements are packed together, but each is 4kB-aligned.
0609  *  5. The list of page frames forms a contiguous 'pseudo-physical' memory
0610  *     layout for the domain. In particular, the bootstrap virtual-memory
0611  *     region is a 1:1 mapping to the first section of the pseudo-physical map.
0612  *  6. All bootstrap elements are mapped read-writable for the guest OS. The
0613  *     only exception is the bootstrap page table, which is mapped read-only.
0614  *  7. There is guaranteed to be at least 512kB padding after the final
0615  *     bootstrap element. If necessary, the bootstrap virtual region is
0616  *     extended by an extra 4MB to ensure this.
0617  */
0618 
0619 #define MAX_GUEST_CMDLINE 1024
0620 struct start_info {
0621     /* THE FOLLOWING ARE FILLED IN BOTH ON INITIAL BOOT AND ON RESUME.    */
0622     char magic[32];             /* "xen-<version>-<platform>".            */
0623     unsigned long nr_pages;     /* Total pages allocated to this domain.  */
0624     unsigned long shared_info;  /* MACHINE address of shared info struct. */
0625     uint32_t flags;             /* SIF_xxx flags.                         */
0626     xen_pfn_t store_mfn;        /* MACHINE page number of shared page.    */
0627     uint32_t store_evtchn;      /* Event channel for store communication. */
0628     union {
0629         struct {
0630             xen_pfn_t mfn;      /* MACHINE page number of console page.   */
0631             uint32_t  evtchn;   /* Event channel for console page.        */
0632         } domU;
0633         struct {
0634             uint32_t info_off;  /* Offset of console_info struct.         */
0635             uint32_t info_size; /* Size of console_info struct from start.*/
0636         } dom0;
0637     } console;
0638     /* THE FOLLOWING ARE ONLY FILLED IN ON INITIAL BOOT (NOT RESUME).     */
0639     unsigned long pt_base;      /* VIRTUAL address of page directory.     */
0640     unsigned long nr_pt_frames; /* Number of bootstrap p.t. frames.       */
0641     unsigned long mfn_list;     /* VIRTUAL address of page-frame list.    */
0642     unsigned long mod_start;    /* VIRTUAL address of pre-loaded module.  */
0643     unsigned long mod_len;      /* Size (bytes) of pre-loaded module.     */
0644     int8_t cmd_line[MAX_GUEST_CMDLINE];
0645     /* The pfn range here covers both page table and p->m table frames.   */
0646     unsigned long first_p2m_pfn;/* 1st pfn forming initial P->M table.    */
0647     unsigned long nr_p2m_frames;/* # of pfns forming initial P->M table.  */
0648 };
0649 
0650 /* These flags are passed in the 'flags' field of start_info_t. */
0651 #define SIF_PRIVILEGED      (1<<0)  /* Is the domain privileged? */
0652 #define SIF_INITDOMAIN      (1<<1)  /* Is this the initial control domain? */
0653 #define SIF_MULTIBOOT_MOD   (1<<2)  /* Is mod_start a multiboot module? */
0654 #define SIF_MOD_START_PFN   (1<<3)  /* Is mod_start a PFN? */
0655 #define SIF_VIRT_P2M_4TOOLS (1<<4)  /* Do Xen tools understand a virt. mapped */
0656                     /* P->M making the 3 level tree obsolete? */
0657 #define SIF_PM_MASK       (0xFF<<8) /* reserve 1 byte for xen-pm options */
0658 
0659 /*
0660  * A multiboot module is a package containing modules very similar to a
0661  * multiboot module array. The only differences are:
0662  * - the array of module descriptors is by convention simply at the beginning
0663  *   of the multiboot module,
0664  * - addresses in the module descriptors are based on the beginning of the
0665  *   multiboot module,
0666  * - the number of modules is determined by a termination descriptor that has
0667  *   mod_start == 0.
0668  *
0669  * This permits to both build it statically and reference it in a configuration
0670  * file, and let the PV guest easily rebase the addresses to virtual addresses
0671  * and at the same time count the number of modules.
0672  */
0673 struct xen_multiboot_mod_list {
0674     /* Address of first byte of the module */
0675     uint32_t mod_start;
0676     /* Address of last byte of the module (inclusive) */
0677     uint32_t mod_end;
0678     /* Address of zero-terminated command line */
0679     uint32_t cmdline;
0680     /* Unused, must be zero */
0681     uint32_t pad;
0682 };
0683 /*
0684  * The console structure in start_info.console.dom0
0685  *
0686  * This structure includes a variety of information required to
0687  * have a working VGA/VESA console.
0688  */
0689 struct dom0_vga_console_info {
0690     uint8_t video_type;
0691 #define XEN_VGATYPE_TEXT_MODE_3 0x03
0692 #define XEN_VGATYPE_VESA_LFB    0x23
0693 #define XEN_VGATYPE_EFI_LFB     0x70
0694 
0695     union {
0696         struct {
0697             /* Font height, in pixels. */
0698             uint16_t font_height;
0699             /* Cursor location (column, row). */
0700             uint16_t cursor_x, cursor_y;
0701             /* Number of rows and columns (dimensions in characters). */
0702             uint16_t rows, columns;
0703         } text_mode_3;
0704 
0705         struct {
0706             /* Width and height, in pixels. */
0707             uint16_t width, height;
0708             /* Bytes per scan line. */
0709             uint16_t bytes_per_line;
0710             /* Bits per pixel. */
0711             uint16_t bits_per_pixel;
0712             /* LFB physical address, and size (in units of 64kB). */
0713             uint32_t lfb_base;
0714             uint32_t lfb_size;
0715             /* RGB mask offsets and sizes, as defined by VBE 1.2+ */
0716             uint8_t  red_pos, red_size;
0717             uint8_t  green_pos, green_size;
0718             uint8_t  blue_pos, blue_size;
0719             uint8_t  rsvd_pos, rsvd_size;
0720 
0721             /* VESA capabilities (offset 0xa, VESA command 0x4f00). */
0722             uint32_t gbl_caps;
0723             /* Mode attributes (offset 0x0, VESA command 0x4f01). */
0724             uint16_t mode_attrs;
0725             uint16_t pad;
0726             /* high 32 bits of lfb_base */
0727             uint32_t ext_lfb_base;
0728         } vesa_lfb;
0729     } u;
0730 };
0731 
0732 typedef uint64_t cpumap_t;
0733 
0734 typedef uint8_t xen_domain_handle_t[16];
0735 
0736 /* Turn a plain number into a C unsigned long constant. */
0737 #define __mk_unsigned_long(x) x ## UL
0738 #define mk_unsigned_long(x) __mk_unsigned_long(x)
0739 
0740 #define TMEM_SPEC_VERSION 1
0741 
0742 struct tmem_op {
0743     uint32_t cmd;
0744     int32_t pool_id;
0745     union {
0746         struct {  /* for cmd == TMEM_NEW_POOL */
0747             uint64_t uuid[2];
0748             uint32_t flags;
0749         } new;
0750         struct {
0751             uint64_t oid[3];
0752             uint32_t index;
0753             uint32_t tmem_offset;
0754             uint32_t pfn_offset;
0755             uint32_t len;
0756             GUEST_HANDLE(void) gmfn; /* guest machine page frame */
0757         } gen;
0758     } u;
0759 };
0760 
0761 DEFINE_GUEST_HANDLE(u64);
0762 
0763 #else /* __ASSEMBLY__ */
0764 
0765 /* In assembly code we cannot use C numeric constant suffixes. */
0766 #define mk_unsigned_long(x) x
0767 
0768 #endif /* !__ASSEMBLY__ */
0769 
0770 #endif /* __XEN_PUBLIC_XEN_H__ */