xref: /onnv-gate/usr/src/uts/common/xen/public/xen.h (revision 6144:5a5f883be4e5)
15084Sjohnlev /******************************************************************************
25084Sjohnlev  * xen.h
35084Sjohnlev  *
45084Sjohnlev  * Guest OS interface to Xen.
55084Sjohnlev  *
65084Sjohnlev  * Permission is hereby granted, free of charge, to any person obtaining a copy
75084Sjohnlev  * of this software and associated documentation files (the "Software"), to
85084Sjohnlev  * deal in the Software without restriction, including without limitation the
95084Sjohnlev  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
105084Sjohnlev  * sell copies of the Software, and to permit persons to whom the Software is
115084Sjohnlev  * furnished to do so, subject to the following conditions:
125084Sjohnlev  *
135084Sjohnlev  * The above copyright notice and this permission notice shall be included in
145084Sjohnlev  * all copies or substantial portions of the Software.
155084Sjohnlev  *
165084Sjohnlev  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
175084Sjohnlev  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
185084Sjohnlev  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
195084Sjohnlev  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
205084Sjohnlev  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
215084Sjohnlev  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
225084Sjohnlev  * DEALINGS IN THE SOFTWARE.
235084Sjohnlev  *
245084Sjohnlev  * Copyright (c) 2004, K A Fraser
255084Sjohnlev  */
265084Sjohnlev 
275084Sjohnlev #ifndef __XEN_PUBLIC_XEN_H__
285084Sjohnlev #define __XEN_PUBLIC_XEN_H__
295084Sjohnlev 
305084Sjohnlev #include "xen-compat.h"
315084Sjohnlev 
325084Sjohnlev #if defined(__i386) && !defined(__i386__)
33*6144Srab #define __i386__ /* foo */
345084Sjohnlev #endif
355084Sjohnlev 
365084Sjohnlev #if defined(__amd64) && !defined(__x86_64__)
375084Sjohnlev #define __x86_64__
385084Sjohnlev #endif
395084Sjohnlev 
405084Sjohnlev #if defined(_ASM) && !defined(__ASSEMBLY__)
415084Sjohnlev #define __ASSEMBLY__
425084Sjohnlev #endif
435084Sjohnlev 
445084Sjohnlev #if defined(__i386__) || defined(__x86_64__)
455084Sjohnlev #include "arch-x86/xen.h"
465084Sjohnlev #elif defined(__ia64__)
475084Sjohnlev #include "arch-ia64.h"
485084Sjohnlev #elif defined(__powerpc__)
495084Sjohnlev #include "arch-powerpc.h"
505084Sjohnlev #else
515084Sjohnlev #error "Unsupported architecture"
525084Sjohnlev #endif
535084Sjohnlev 
545084Sjohnlev /*
555084Sjohnlev  * HYPERCALLS
565084Sjohnlev  */
575084Sjohnlev 
585084Sjohnlev #define __HYPERVISOR_set_trap_table        0
595084Sjohnlev #define __HYPERVISOR_mmu_update            1
605084Sjohnlev #define __HYPERVISOR_set_gdt               2
615084Sjohnlev #define __HYPERVISOR_stack_switch          3
625084Sjohnlev #define __HYPERVISOR_set_callbacks         4
635084Sjohnlev #define __HYPERVISOR_fpu_taskswitch        5
645084Sjohnlev #define __HYPERVISOR_sched_op_compat       6 /* compat since 0x00030101 */
655084Sjohnlev #define __HYPERVISOR_platform_op           7
665084Sjohnlev #define __HYPERVISOR_set_debugreg          8
675084Sjohnlev #define __HYPERVISOR_get_debugreg          9
685084Sjohnlev #define __HYPERVISOR_update_descriptor    10
695084Sjohnlev #define __HYPERVISOR_memory_op            12
705084Sjohnlev #define __HYPERVISOR_multicall            13
715084Sjohnlev #define __HYPERVISOR_update_va_mapping    14
725084Sjohnlev #define __HYPERVISOR_set_timer_op         15
735084Sjohnlev #define __HYPERVISOR_event_channel_op_compat 16 /* compat since 0x00030202 */
745084Sjohnlev #define __HYPERVISOR_xen_version          17
755084Sjohnlev #define __HYPERVISOR_console_io           18
765084Sjohnlev #define __HYPERVISOR_physdev_op_compat    19 /* compat since 0x00030202 */
775084Sjohnlev #define __HYPERVISOR_grant_table_op       20
785084Sjohnlev #define __HYPERVISOR_vm_assist            21
795084Sjohnlev #define __HYPERVISOR_update_va_mapping_otherdomain 22
805084Sjohnlev #define __HYPERVISOR_iret                 23 /* x86 only */
815084Sjohnlev #define __HYPERVISOR_vcpu_op              24
825084Sjohnlev #define __HYPERVISOR_set_segment_base     25 /* x86/64 only */
835084Sjohnlev #define __HYPERVISOR_mmuext_op            26
845084Sjohnlev #define __HYPERVISOR_acm_op               27
855084Sjohnlev #define __HYPERVISOR_nmi_op               28
865084Sjohnlev #define __HYPERVISOR_sched_op             29
875084Sjohnlev #define __HYPERVISOR_callback_op          30
885084Sjohnlev #define __HYPERVISOR_xenoprof_op          31
895084Sjohnlev #define __HYPERVISOR_event_channel_op     32
905084Sjohnlev #define __HYPERVISOR_physdev_op           33
915084Sjohnlev #define __HYPERVISOR_hvm_op               34
925084Sjohnlev #define __HYPERVISOR_sysctl               35
935084Sjohnlev #define __HYPERVISOR_domctl               36
945084Sjohnlev #define __HYPERVISOR_kexec_op             37
955084Sjohnlev 
965084Sjohnlev /* Architecture-specific hypercall definitions. */
975084Sjohnlev #define __HYPERVISOR_arch_0               48
985084Sjohnlev #define __HYPERVISOR_arch_1               49
995084Sjohnlev #define __HYPERVISOR_arch_2               50
1005084Sjohnlev #define __HYPERVISOR_arch_3               51
1015084Sjohnlev #define __HYPERVISOR_arch_4               52
1025084Sjohnlev #define __HYPERVISOR_arch_5               53
1035084Sjohnlev #define __HYPERVISOR_arch_6               54
1045084Sjohnlev #define __HYPERVISOR_arch_7               55
1055084Sjohnlev 
1065084Sjohnlev /*
1075084Sjohnlev  * HYPERCALL COMPATIBILITY.
1085084Sjohnlev  */
1095084Sjohnlev 
1105084Sjohnlev /* New sched_op hypercall introduced in 0x00030101. */
1115084Sjohnlev #if __XEN_INTERFACE_VERSION__ < 0x00030101
1125084Sjohnlev #undef __HYPERVISOR_sched_op
1135084Sjohnlev #define __HYPERVISOR_sched_op __HYPERVISOR_sched_op_compat
1145084Sjohnlev #endif
1155084Sjohnlev 
1165084Sjohnlev /* New event-channel and physdev hypercalls introduced in 0x00030202. */
1175084Sjohnlev #if __XEN_INTERFACE_VERSION__ < 0x00030202
1185084Sjohnlev #undef __HYPERVISOR_event_channel_op
1195084Sjohnlev #define __HYPERVISOR_event_channel_op __HYPERVISOR_event_channel_op_compat
1205084Sjohnlev #undef __HYPERVISOR_physdev_op
1215084Sjohnlev #define __HYPERVISOR_physdev_op __HYPERVISOR_physdev_op_compat
1225084Sjohnlev #endif
1235084Sjohnlev 
1245084Sjohnlev /* New platform_op hypercall introduced in 0x00030204. */
1255084Sjohnlev #if __XEN_INTERFACE_VERSION__ < 0x00030204
1265084Sjohnlev #define __HYPERVISOR_dom0_op __HYPERVISOR_platform_op
1275084Sjohnlev #endif
1285084Sjohnlev 
1295084Sjohnlev /*
1305084Sjohnlev  * VIRTUAL INTERRUPTS
1315084Sjohnlev  *
1325084Sjohnlev  * Virtual interrupts that a guest OS may receive from Xen.
1335084Sjohnlev  *
1345084Sjohnlev  * In the side comments, 'V.' denotes a per-VCPU VIRQ while 'G.' denotes a
1355084Sjohnlev  * global VIRQ. The former can be bound once per VCPU and cannot be re-bound.
1365084Sjohnlev  * The latter can be allocated only once per guest: they must initially be
1375084Sjohnlev  * allocated to VCPU0 but can subsequently be re-bound.
1385084Sjohnlev  */
1395084Sjohnlev #define VIRQ_TIMER      0  /* V. Timebase update, and/or requested timeout.  */
1405084Sjohnlev #define VIRQ_DEBUG      1  /* V. Request guest to dump debug info.           */
1415084Sjohnlev #define VIRQ_CONSOLE    2  /* G. (DOM0) Bytes received on emergency console. */
1425084Sjohnlev #define VIRQ_DOM_EXC    3  /* G. (DOM0) Exceptional event for some domain.   */
1435084Sjohnlev #define VIRQ_TBUF       4  /* G. (DOM0) Trace buffer has records available.  */
1445084Sjohnlev #define VIRQ_DEBUGGER   6  /* G. (DOM0) A domain has paused for debugging.   */
1455084Sjohnlev #define VIRQ_XENOPROF   7  /* V. XenOprofile interrupt: new sample available */
146*6144Srab #define VIRQ_CON_RING   8  /* G. (DOM0) Bytes received on console            */
1475084Sjohnlev 
1485084Sjohnlev /* Architecture-specific VIRQ definitions. */
1495084Sjohnlev #define VIRQ_ARCH_0    16
1505084Sjohnlev #define VIRQ_ARCH_1    17
1515084Sjohnlev #define VIRQ_ARCH_2    18
1525084Sjohnlev #define VIRQ_ARCH_3    19
1535084Sjohnlev #define VIRQ_ARCH_4    20
1545084Sjohnlev #define VIRQ_ARCH_5    21
1555084Sjohnlev #define VIRQ_ARCH_6    22
1565084Sjohnlev #define VIRQ_ARCH_7    23
1575084Sjohnlev 
1585084Sjohnlev #define NR_VIRQS       24
1595084Sjohnlev 
1605084Sjohnlev /*
1615084Sjohnlev  * MMU-UPDATE REQUESTS
1625084Sjohnlev  *
1635084Sjohnlev  * HYPERVISOR_mmu_update() accepts a list of (ptr, val) pairs.
1645084Sjohnlev  * A foreigndom (FD) can be specified (or DOMID_SELF for none).
1655084Sjohnlev  * Where the FD has some effect, it is described below.
1665084Sjohnlev  * ptr[1:0] specifies the appropriate MMU_* command.
1675084Sjohnlev  *
1685084Sjohnlev  * ptr[1:0] == MMU_NORMAL_PT_UPDATE:
1695084Sjohnlev  * Updates an entry in a page table. If updating an L1 table, and the new
1705084Sjohnlev  * table entry is valid/present, the mapped frame must belong to the FD, if
1715084Sjohnlev  * an FD has been specified. If attempting to map an I/O page then the
1725084Sjohnlev  * caller assumes the privilege of the FD.
1735084Sjohnlev  * FD == DOMID_IO: Permit /only/ I/O mappings, at the priv level of the caller.
1745084Sjohnlev  * FD == DOMID_XEN: Map restricted areas of Xen's heap space.
1755084Sjohnlev  * ptr[:2]  -- Machine address of the page-table entry to modify.
1765084Sjohnlev  * val      -- Value to write.
1775084Sjohnlev  *
1785084Sjohnlev  * ptr[1:0] == MMU_MACHPHYS_UPDATE:
1795084Sjohnlev  * Updates an entry in the machine->pseudo-physical mapping table.
1805084Sjohnlev  * ptr[:2]  -- Machine address within the frame whose mapping to modify.
1815084Sjohnlev  *             The frame must belong to the FD, if one is specified.
1825084Sjohnlev  * val      -- Value to write into the mapping entry.
1835084Sjohnlev  */
1845084Sjohnlev #define MMU_NORMAL_PT_UPDATE     0 /* checked '*ptr = val'. ptr is MA.       */
1855084Sjohnlev #define MMU_MACHPHYS_UPDATE      1 /* ptr = MA of frame to modify entry for  */
1865084Sjohnlev 
1875084Sjohnlev /*
1885084Sjohnlev  * MMU EXTENDED OPERATIONS
1895084Sjohnlev  *
1905084Sjohnlev  * HYPERVISOR_mmuext_op() accepts a list of mmuext_op structures.
1915084Sjohnlev  * A foreigndom (FD) can be specified (or DOMID_SELF for none).
1925084Sjohnlev  * Where the FD has some effect, it is described below.
1935084Sjohnlev  *
1945084Sjohnlev  * cmd: MMUEXT_(UN)PIN_*_TABLE
1955084Sjohnlev  * mfn: Machine frame number to be (un)pinned as a p.t. page.
1965084Sjohnlev  *      The frame must belong to the FD, if one is specified.
1975084Sjohnlev  *
1985084Sjohnlev  * cmd: MMUEXT_NEW_BASEPTR
1995084Sjohnlev  * mfn: Machine frame number of new page-table base to install in MMU.
2005084Sjohnlev  *
2015084Sjohnlev  * cmd: MMUEXT_NEW_USER_BASEPTR [x86/64 only]
2025084Sjohnlev  * mfn: Machine frame number of new page-table base to install in MMU
2035084Sjohnlev  *      when in user space.
2045084Sjohnlev  *
2055084Sjohnlev  * cmd: MMUEXT_TLB_FLUSH_LOCAL
2065084Sjohnlev  * No additional arguments. Flushes local TLB.
2075084Sjohnlev  *
2085084Sjohnlev  * cmd: MMUEXT_INVLPG_LOCAL
2095084Sjohnlev  * linear_addr: Linear address to be flushed from the local TLB.
2105084Sjohnlev  *
2115084Sjohnlev  * cmd: MMUEXT_TLB_FLUSH_MULTI
2125084Sjohnlev  * vcpumask: Pointer to bitmap of VCPUs to be flushed.
2135084Sjohnlev  *
2145084Sjohnlev  * cmd: MMUEXT_INVLPG_MULTI
2155084Sjohnlev  * linear_addr: Linear address to be flushed.
2165084Sjohnlev  * vcpumask: Pointer to bitmap of VCPUs to be flushed.
2175084Sjohnlev  *
2185084Sjohnlev  * cmd: MMUEXT_TLB_FLUSH_ALL
2195084Sjohnlev  * No additional arguments. Flushes all VCPUs' TLBs.
2205084Sjohnlev  *
2215084Sjohnlev  * cmd: MMUEXT_INVLPG_ALL
2225084Sjohnlev  * linear_addr: Linear address to be flushed from all VCPUs' TLBs.
2235084Sjohnlev  *
2245084Sjohnlev  * cmd: MMUEXT_FLUSH_CACHE
2255084Sjohnlev  * No additional arguments. Writes back and flushes cache contents.
2265084Sjohnlev  *
2275084Sjohnlev  * cmd: MMUEXT_SET_LDT
2285084Sjohnlev  * linear_addr: Linear address of LDT base (NB. must be page-aligned).
2295084Sjohnlev  * nr_ents: Number of entries in LDT.
2305084Sjohnlev  */
2315084Sjohnlev #define MMUEXT_PIN_L1_TABLE      0
2325084Sjohnlev #define MMUEXT_PIN_L2_TABLE      1
2335084Sjohnlev #define MMUEXT_PIN_L3_TABLE      2
2345084Sjohnlev #define MMUEXT_PIN_L4_TABLE      3
2355084Sjohnlev #define MMUEXT_UNPIN_TABLE       4
2365084Sjohnlev #define MMUEXT_NEW_BASEPTR       5
2375084Sjohnlev #define MMUEXT_TLB_FLUSH_LOCAL   6
2385084Sjohnlev #define MMUEXT_INVLPG_LOCAL      7
2395084Sjohnlev #define MMUEXT_TLB_FLUSH_MULTI   8
2405084Sjohnlev #define MMUEXT_INVLPG_MULTI      9
2415084Sjohnlev #define MMUEXT_TLB_FLUSH_ALL    10
2425084Sjohnlev #define MMUEXT_INVLPG_ALL       11
2435084Sjohnlev #define MMUEXT_FLUSH_CACHE      12
2445084Sjohnlev #define MMUEXT_SET_LDT          13
2455084Sjohnlev #define MMUEXT_NEW_USER_BASEPTR 15
2465084Sjohnlev 
2475084Sjohnlev #ifndef __ASSEMBLY__
2485084Sjohnlev struct mmuext_op {
2495084Sjohnlev     unsigned int cmd;
2505084Sjohnlev     union {
2515084Sjohnlev         /* [UN]PIN_TABLE, NEW_BASEPTR, NEW_USER_BASEPTR */
2525084Sjohnlev         xen_pfn_t     mfn;
2535084Sjohnlev         /* INVLPG_LOCAL, INVLPG_ALL, SET_LDT */
2545084Sjohnlev         unsigned long linear_addr;
2555084Sjohnlev     } arg1;
2565084Sjohnlev     union {
2575084Sjohnlev         /* SET_LDT */
2585084Sjohnlev         unsigned int nr_ents;
2595084Sjohnlev         /* TLB_FLUSH_MULTI, INVLPG_MULTI */
2605084Sjohnlev         XEN_GUEST_HANDLE_00030205(void) vcpumask;
2615084Sjohnlev     } arg2;
2625084Sjohnlev };
2635084Sjohnlev typedef struct mmuext_op mmuext_op_t;
2645084Sjohnlev DEFINE_XEN_GUEST_HANDLE(mmuext_op_t);
2655084Sjohnlev #endif
2665084Sjohnlev 
2675084Sjohnlev /* These are passed as 'flags' to update_va_mapping. They can be ORed. */
2685084Sjohnlev /* When specifying UVMF_MULTI, also OR in a pointer to a CPU bitmap.   */
2695084Sjohnlev /* UVMF_LOCAL is merely UVMF_MULTI with a NULL bitmap pointer.         */
2705084Sjohnlev #define UVMF_NONE               (0UL<<0) /* No flushing at all.   */
2715084Sjohnlev #define UVMF_TLB_FLUSH          (1UL<<0) /* Flush entire TLB(s).  */
2725084Sjohnlev #define UVMF_INVLPG             (2UL<<0) /* Flush only one entry. */
2735084Sjohnlev #define UVMF_FLUSHTYPE_MASK     (3UL<<0)
2745084Sjohnlev #define UVMF_MULTI              (0UL<<2) /* Flush subset of TLBs. */
2755084Sjohnlev #define UVMF_LOCAL              (0UL<<2) /* Flush local TLB.      */
2765084Sjohnlev #define UVMF_ALL                (1UL<<2) /* Flush all TLBs.       */
2775084Sjohnlev 
2785084Sjohnlev /*
2795084Sjohnlev  * Commands to HYPERVISOR_console_io().
2805084Sjohnlev  */
2815084Sjohnlev #define CONSOLEIO_write         0
2825084Sjohnlev #define CONSOLEIO_read          1
2835084Sjohnlev #define CONSOLEIO_get_device   32
2845084Sjohnlev 
2855084Sjohnlev /*
2865084Sjohnlev  * Commands to HYPERVISOR_vm_assist().
2875084Sjohnlev  */
2885084Sjohnlev #define VMASST_CMD_enable                0
2895084Sjohnlev #define VMASST_CMD_disable               1
2905084Sjohnlev 
2915084Sjohnlev /* x86/32 guests: simulate full 4GB segment limits. */
2925084Sjohnlev #define VMASST_TYPE_4gb_segments         0
2935084Sjohnlev 
2945084Sjohnlev /* x86/32 guests: trap (vector 15) whenever above vmassist is used. */
2955084Sjohnlev #define VMASST_TYPE_4gb_segments_notify  1
2965084Sjohnlev 
2975084Sjohnlev /*
2985084Sjohnlev  * x86 guests: support writes to bottom-level PTEs.
2995084Sjohnlev  * NB1. Page-directory entries cannot be written.
3005084Sjohnlev  * NB2. Guest must continue to remove all writable mappings of PTEs.
3015084Sjohnlev  */
3025084Sjohnlev #define VMASST_TYPE_writable_pagetables  2
3035084Sjohnlev 
3045084Sjohnlev /* x86/PAE guests: support PDPTs above 4GB. */
3055084Sjohnlev #define VMASST_TYPE_pae_extended_cr3     3
3065084Sjohnlev 
3075084Sjohnlev #define MAX_VMASST_TYPE                  3
3085084Sjohnlev 
3095084Sjohnlev #ifndef __ASSEMBLY__
3105084Sjohnlev 
3115084Sjohnlev typedef uint16_t domid_t;
3125084Sjohnlev 
3135084Sjohnlev /* Domain ids >= DOMID_FIRST_RESERVED cannot be used for ordinary domains. */
3145084Sjohnlev #define DOMID_FIRST_RESERVED (0x7FF0U)
3155084Sjohnlev 
3165084Sjohnlev /* DOMID_SELF is used in certain contexts to refer to oneself. */
3175084Sjohnlev #define DOMID_SELF (0x7FF0U)
3185084Sjohnlev 
3195084Sjohnlev /*
3205084Sjohnlev  * DOMID_IO is used to restrict page-table updates to mapping I/O memory.
3215084Sjohnlev  * Although no Foreign Domain need be specified to map I/O pages, DOMID_IO
3225084Sjohnlev  * is useful to ensure that no mappings to the OS's own heap are accidentally
3235084Sjohnlev  * installed. (e.g., in Linux this could cause havoc as reference counts
3245084Sjohnlev  * aren't adjusted on the I/O-mapping code path).
3255084Sjohnlev  * This only makes sense in MMUEXT_SET_FOREIGNDOM, but in that context can
3265084Sjohnlev  * be specified by any calling domain.
3275084Sjohnlev  */
3285084Sjohnlev #define DOMID_IO   (0x7FF1U)
3295084Sjohnlev 
3305084Sjohnlev /*
3315084Sjohnlev  * DOMID_XEN is used to allow privileged domains to map restricted parts of
3325084Sjohnlev  * Xen's heap space (e.g., the machine_to_phys table).
3335084Sjohnlev  * This only makes sense in MMUEXT_SET_FOREIGNDOM, and is only permitted if
3345084Sjohnlev  * the caller is privileged.
3355084Sjohnlev  */
3365084Sjohnlev #define DOMID_XEN  (0x7FF2U)
3375084Sjohnlev 
3385084Sjohnlev /*
3395084Sjohnlev  * Send an array of these to HYPERVISOR_mmu_update().
3405084Sjohnlev  * NB. The fields are natural pointer/address size for this architecture.
3415084Sjohnlev  */
3425084Sjohnlev struct mmu_update {
3435084Sjohnlev     uint64_t ptr;       /* Machine address of PTE. */
3445084Sjohnlev     uint64_t val;       /* New contents of PTE.    */
3455084Sjohnlev };
3465084Sjohnlev typedef struct mmu_update mmu_update_t;
3475084Sjohnlev DEFINE_XEN_GUEST_HANDLE(mmu_update_t);
3485084Sjohnlev 
3495084Sjohnlev /*
3505084Sjohnlev  * Send an array of these to HYPERVISOR_multicall().
3515084Sjohnlev  * NB. The fields are natural register size for this architecture.
3525084Sjohnlev  */
3535084Sjohnlev struct multicall_entry {
3545084Sjohnlev     unsigned long op, result;
3555084Sjohnlev     unsigned long args[6];
3565084Sjohnlev };
3575084Sjohnlev typedef struct multicall_entry multicall_entry_t;
3585084Sjohnlev DEFINE_XEN_GUEST_HANDLE(multicall_entry_t);
3595084Sjohnlev 
3605084Sjohnlev /*
3615084Sjohnlev  * Event channel endpoints per domain:
3625084Sjohnlev  *  1024 if a long is 32 bits; 4096 if a long is 64 bits.
3635084Sjohnlev  */
3645084Sjohnlev #define NR_EVENT_CHANNELS (sizeof(unsigned long) * sizeof(unsigned long) * 64)
3655084Sjohnlev 
3665084Sjohnlev struct vcpu_time_info {
3675084Sjohnlev     /*
3685084Sjohnlev      * Updates to the following values are preceded and followed by an
3695084Sjohnlev      * increment of 'version'. The guest can therefore detect updates by
3705084Sjohnlev      * looking for changes to 'version'. If the least-significant bit of
3715084Sjohnlev      * the version number is set then an update is in progress and the guest
3725084Sjohnlev      * must wait to read a consistent set of values.
3735084Sjohnlev      * The correct way to interact with the version number is similar to
3745084Sjohnlev      * Linux's seqlock: see the implementations of read_seqbegin/read_seqretry.
3755084Sjohnlev      */
3765084Sjohnlev     uint32_t version;
3775084Sjohnlev     uint32_t pad0;
3785084Sjohnlev     uint64_t tsc_timestamp;   /* TSC at last update of time vals.  */
3795084Sjohnlev     uint64_t system_time;     /* Time, in nanosecs, since boot.    */
3805084Sjohnlev     /*
3815084Sjohnlev      * Current system time:
3825084Sjohnlev      *   system_time +
3835084Sjohnlev      *   ((((tsc - tsc_timestamp) << tsc_shift) * tsc_to_system_mul) >> 32)
3845084Sjohnlev      * CPU frequency (Hz):
3855084Sjohnlev      *   ((10^9 << 32) / tsc_to_system_mul) >> tsc_shift
3865084Sjohnlev      */
3875084Sjohnlev     uint32_t tsc_to_system_mul;
3885084Sjohnlev     int8_t   tsc_shift;
3895084Sjohnlev     int8_t   pad1[3];
3905084Sjohnlev }; /* 32 bytes */
3915084Sjohnlev typedef struct vcpu_time_info vcpu_time_info_t;
3925084Sjohnlev 
3935084Sjohnlev struct vcpu_info {
3945084Sjohnlev     /*
3955084Sjohnlev      * 'evtchn_upcall_pending' is written non-zero by Xen to indicate
3965084Sjohnlev      * a pending notification for a particular VCPU. It is then cleared
3975084Sjohnlev      * by the guest OS /before/ checking for pending work, thus avoiding
3985084Sjohnlev      * a set-and-check race. Note that the mask is only accessed by Xen
3995084Sjohnlev      * on the CPU that is currently hosting the VCPU. This means that the
4005084Sjohnlev      * pending and mask flags can be updated by the guest without special
4015084Sjohnlev      * synchronisation (i.e., no need for the x86 LOCK prefix).
4025084Sjohnlev      * This may seem suboptimal because if the pending flag is set by
4035084Sjohnlev      * a different CPU then an IPI may be scheduled even when the mask
4045084Sjohnlev      * is set. However, note:
4055084Sjohnlev      *  1. The task of 'interrupt holdoff' is covered by the per-event-
4065084Sjohnlev      *     channel mask bits. A 'noisy' event that is continually being
4075084Sjohnlev      *     triggered can be masked at source at this very precise
4085084Sjohnlev      *     granularity.
4095084Sjohnlev      *  2. The main purpose of the per-VCPU mask is therefore to restrict
4105084Sjohnlev      *     reentrant execution: whether for concurrency control, or to
4115084Sjohnlev      *     prevent unbounded stack usage. Whatever the purpose, we expect
4125084Sjohnlev      *     that the mask will be asserted only for short periods at a time,
4135084Sjohnlev      *     and so the likelihood of a 'spurious' IPI is suitably small.
4145084Sjohnlev      * The mask is read before making an event upcall to the guest: a
4155084Sjohnlev      * non-zero mask therefore guarantees that the VCPU will not receive
4165084Sjohnlev      * an upcall activation. The mask is cleared when the VCPU requests
4175084Sjohnlev      * to block: this avoids wakeup-waiting races.
4185084Sjohnlev      */
4195084Sjohnlev     uint8_t evtchn_upcall_pending;
4205084Sjohnlev     uint8_t evtchn_upcall_mask;
4215084Sjohnlev     unsigned long evtchn_pending_sel;
4225084Sjohnlev     struct arch_vcpu_info arch;
4235084Sjohnlev     struct vcpu_time_info time;
4245084Sjohnlev }; /* 64 bytes (x86) */
425*6144Srab #ifndef __XEN__
4265084Sjohnlev typedef struct vcpu_info vcpu_info_t;
427*6144Srab #endif
4285084Sjohnlev 
4295084Sjohnlev /*
4305084Sjohnlev  * Xen/kernel shared data -- pointer provided in start_info.
4315084Sjohnlev  *
4325084Sjohnlev  * This structure is defined to be both smaller than a page, and the
4335084Sjohnlev  * only data on the shared page, but may vary in actual size even within
4345084Sjohnlev  * compatible Xen versions; guests should not rely on the size
4355084Sjohnlev  * of this structure remaining constant.
4365084Sjohnlev  */
4375084Sjohnlev struct shared_info {
4385084Sjohnlev     struct vcpu_info vcpu_info[MAX_VIRT_CPUS];
4395084Sjohnlev 
4405084Sjohnlev     /*
4415084Sjohnlev      * A domain can create "event channels" on which it can send and receive
4425084Sjohnlev      * asynchronous event notifications. There are three classes of event that
4435084Sjohnlev      * are delivered by this mechanism:
4445084Sjohnlev      *  1. Bi-directional inter- and intra-domain connections. Domains must
4455084Sjohnlev      *     arrange out-of-band to set up a connection (usually by allocating
4465084Sjohnlev      *     an unbound 'listener' port and avertising that via a storage service
4475084Sjohnlev      *     such as xenstore).
4485084Sjohnlev      *  2. Physical interrupts. A domain with suitable hardware-access
4495084Sjohnlev      *     privileges can bind an event-channel port to a physical interrupt
4505084Sjohnlev      *     source.
4515084Sjohnlev      *  3. Virtual interrupts ('events'). A domain can bind an event-channel
4525084Sjohnlev      *     port to a virtual interrupt source, such as the virtual-timer
4535084Sjohnlev      *     device or the emergency console.
4545084Sjohnlev      *
4555084Sjohnlev      * Event channels are addressed by a "port index". Each channel is
4565084Sjohnlev      * associated with two bits of information:
4575084Sjohnlev      *  1. PENDING -- notifies the domain that there is a pending notification
4585084Sjohnlev      *     to be processed. This bit is cleared by the guest.
4595084Sjohnlev      *  2. MASK -- if this bit is clear then a 0->1 transition of PENDING
4605084Sjohnlev      *     will cause an asynchronous upcall to be scheduled. This bit is only
4615084Sjohnlev      *     updated by the guest. It is read-only within Xen. If a channel
4625084Sjohnlev      *     becomes pending while the channel is masked then the 'edge' is lost
4635084Sjohnlev      *     (i.e., when the channel is unmasked, the guest must manually handle
4645084Sjohnlev      *     pending notifications as no upcall will be scheduled by Xen).
4655084Sjohnlev      *
4665084Sjohnlev      * To expedite scanning of pending notifications, any 0->1 pending
4675084Sjohnlev      * transition on an unmasked channel causes a corresponding bit in a
4685084Sjohnlev      * per-vcpu selector word to be set. Each bit in the selector covers a
4695084Sjohnlev      * 'C long' in the PENDING bitfield array.
4705084Sjohnlev      */
4715084Sjohnlev     unsigned long evtchn_pending[sizeof(unsigned long) * 8];
4725084Sjohnlev     unsigned long evtchn_mask[sizeof(unsigned long) * 8];
4735084Sjohnlev 
4745084Sjohnlev     /*
4755084Sjohnlev      * Wallclock time: updated only by control software. Guests should base
4765084Sjohnlev      * their gettimeofday() syscall on this wallclock-base value.
4775084Sjohnlev      */
4785084Sjohnlev     uint32_t wc_version;      /* Version counter: see vcpu_time_info_t. */
4795084Sjohnlev     uint32_t wc_sec;          /* Secs  00:00:00 UTC, Jan 1, 1970.  */
4805084Sjohnlev     uint32_t wc_nsec;         /* Nsecs 00:00:00 UTC, Jan 1, 1970.  */
4815084Sjohnlev 
4825084Sjohnlev     struct arch_shared_info arch;
4835084Sjohnlev 
4845084Sjohnlev };
485*6144Srab #ifndef __XEN__
4865084Sjohnlev typedef struct shared_info shared_info_t;
487*6144Srab #endif
4885084Sjohnlev 
4895084Sjohnlev /*
490*6144Srab  * Start-of-day memory layout:
4915084Sjohnlev  *  1. The domain is started within contiguous virtual-memory region.
492*6144Srab  *  2. The contiguous region ends on an aligned 4MB boundary.
493*6144Srab  *  3. This the order of bootstrap elements in the initial virtual region:
4945084Sjohnlev  *      a. relocated kernel image
4955084Sjohnlev  *      b. initial ram disk              [mod_start, mod_len]
4965084Sjohnlev  *      c. list of allocated page frames [mfn_list, nr_pages]
4975084Sjohnlev  *      d. start_info_t structure        [register ESI (x86)]
4985084Sjohnlev  *      e. bootstrap page tables         [pt_base, CR3 (x86)]
4995084Sjohnlev  *      f. bootstrap stack               [register ESP (x86)]
500*6144Srab  *  4. Bootstrap elements are packed together, but each is 4kB-aligned.
501*6144Srab  *  5. The initial ram disk may be omitted.
502*6144Srab  *  6. The list of page frames forms a contiguous 'pseudo-physical' memory
5035084Sjohnlev  *     layout for the domain. In particular, the bootstrap virtual-memory
5045084Sjohnlev  *     region is a 1:1 mapping to the first section of the pseudo-physical map.
505*6144Srab  *  7. All bootstrap elements are mapped read-writable for the guest OS. The
5065084Sjohnlev  *     only exception is the bootstrap page table, which is mapped read-only.
507*6144Srab  *  8. There is guaranteed to be at least 512kB padding after the final
5085084Sjohnlev  *     bootstrap element. If necessary, the bootstrap virtual region is
5095084Sjohnlev  *     extended by an extra 4MB to ensure this.
5105084Sjohnlev  */
5115084Sjohnlev 
5125084Sjohnlev #define MAX_GUEST_CMDLINE 1024
5135084Sjohnlev struct start_info {
5145084Sjohnlev     /* THE FOLLOWING ARE FILLED IN BOTH ON INITIAL BOOT AND ON RESUME.    */
5155084Sjohnlev     char magic[32];             /* "xen-<version>-<platform>".            */
5165084Sjohnlev     unsigned long nr_pages;     /* Total pages allocated to this domain.  */
5175084Sjohnlev     unsigned long shared_info;  /* MACHINE address of shared info struct. */
5185084Sjohnlev     uint32_t flags;             /* SIF_xxx flags.                         */
5195084Sjohnlev     xen_pfn_t store_mfn;        /* MACHINE page number of shared page.    */
5205084Sjohnlev     uint32_t store_evtchn;      /* Event channel for store communication. */
5215084Sjohnlev     union {
5225084Sjohnlev         struct {
5235084Sjohnlev             xen_pfn_t mfn;      /* MACHINE page number of console page.   */
5245084Sjohnlev             uint32_t  evtchn;   /* Event channel for console page.        */
5255084Sjohnlev         } domU;
5265084Sjohnlev         struct {
5275084Sjohnlev             uint32_t info_off;  /* Offset of console_info struct.         */
5285084Sjohnlev             uint32_t info_size; /* Size of console_info struct from start.*/
5295084Sjohnlev         } dom0;
5305084Sjohnlev     } console;
5315084Sjohnlev     /* THE FOLLOWING ARE ONLY FILLED IN ON INITIAL BOOT (NOT RESUME).     */
5325084Sjohnlev     unsigned long pt_base;      /* VIRTUAL address of page directory.     */
5335084Sjohnlev     unsigned long nr_pt_frames; /* Number of bootstrap p.t. frames.       */
5345084Sjohnlev     unsigned long mfn_list;     /* VIRTUAL address of page-frame list.    */
5355084Sjohnlev     unsigned long mod_start;    /* VIRTUAL address of pre-loaded module.  */
5365084Sjohnlev     unsigned long mod_len;      /* Size (bytes) of pre-loaded module.     */
5375084Sjohnlev     int8_t cmd_line[MAX_GUEST_CMDLINE];
5385084Sjohnlev };
5395084Sjohnlev typedef struct start_info start_info_t;
5405084Sjohnlev 
5415084Sjohnlev /* New console union for dom0 introduced in 0x00030203. */
5425084Sjohnlev #if __XEN_INTERFACE_VERSION__ < 0x00030203
5435084Sjohnlev #define console_mfn    console.domU.mfn
5445084Sjohnlev #define console_evtchn console.domU.evtchn
5455084Sjohnlev #endif
5465084Sjohnlev 
5475084Sjohnlev /* These flags are passed in the 'flags' field of start_info_t. */
5485084Sjohnlev #define SIF_PRIVILEGED    (1<<0)  /* Is the domain privileged? */
5495084Sjohnlev #define SIF_INITDOMAIN    (1<<1)  /* Is this the initial control domain? */
5505084Sjohnlev 
5515084Sjohnlev #define XEN_CONSOLE_INVALID   -1
5525084Sjohnlev #define XEN_CONSOLE_COM1       0
5535084Sjohnlev #define XEN_CONSOLE_COM2       1
5545084Sjohnlev #define XEN_CONSOLE_VGA        2
5555084Sjohnlev 
5565084Sjohnlev typedef struct dom0_vga_console_info {
5575084Sjohnlev     uint8_t video_type; /* DOM0_VGA_CONSOLE_??? */
5585084Sjohnlev #define XEN_VGATYPE_TEXT_MODE_3 0x03
5595084Sjohnlev #define XEN_VGATYPE_VESA_LFB    0x23
5605084Sjohnlev 
5615084Sjohnlev     union {
5625084Sjohnlev         struct {
5635084Sjohnlev             /* Font height, in pixels. */
5645084Sjohnlev             uint16_t font_height;
5655084Sjohnlev             /* Cursor location (column, row). */
5665084Sjohnlev             uint16_t cursor_x, cursor_y;
5675084Sjohnlev             /* Number of rows and columns (dimensions in characters). */
5685084Sjohnlev             uint16_t rows, columns;
5695084Sjohnlev         } text_mode_3;
5705084Sjohnlev 
5715084Sjohnlev         struct {
5725084Sjohnlev             /* Width and height, in pixels. */
5735084Sjohnlev             uint16_t width, height;
5745084Sjohnlev             /* Bytes per scan line. */
5755084Sjohnlev             uint16_t bytes_per_line;
5765084Sjohnlev             /* Bits per pixel. */
5775084Sjohnlev             uint16_t bits_per_pixel;
5785084Sjohnlev             /* LFB physical address, and size (in units of 64kB). */
5795084Sjohnlev             uint32_t lfb_base;
5805084Sjohnlev             uint32_t lfb_size;
5815084Sjohnlev             /* RGB mask offsets and sizes, as defined by VBE 1.2+ */
5825084Sjohnlev             uint8_t  red_pos, red_size;
5835084Sjohnlev             uint8_t  green_pos, green_size;
5845084Sjohnlev             uint8_t  blue_pos, blue_size;
5855084Sjohnlev             uint8_t  rsvd_pos, rsvd_size;
5865084Sjohnlev         } vesa_lfb;
5875084Sjohnlev     } u;
5885084Sjohnlev } dom0_vga_console_info_t;
589*6144Srab #define xen_vga_console_info dom0_vga_console_info
590*6144Srab #define xen_vga_console_info_t dom0_vga_console_info_t
5915084Sjohnlev 
5925084Sjohnlev typedef uint8_t xen_domain_handle_t[16];
5935084Sjohnlev 
5945084Sjohnlev /* Turn a plain number into a C unsigned long constant. */
5955084Sjohnlev #define __mk_unsigned_long(x) x ## UL
5965084Sjohnlev #define mk_unsigned_long(x) __mk_unsigned_long(x)
5975084Sjohnlev 
5985084Sjohnlev DEFINE_XEN_GUEST_HANDLE(uint8_t);
5995084Sjohnlev DEFINE_XEN_GUEST_HANDLE(uint16_t);
6005084Sjohnlev DEFINE_XEN_GUEST_HANDLE(uint32_t);
6015084Sjohnlev DEFINE_XEN_GUEST_HANDLE(uint64_t);
6025084Sjohnlev 
6035084Sjohnlev #else /* __ASSEMBLY__ */
6045084Sjohnlev 
6055084Sjohnlev /* In assembly code we cannot use C numeric constant suffixes. */
6065084Sjohnlev #define mk_unsigned_long(x) x
6075084Sjohnlev 
6085084Sjohnlev #endif /* !__ASSEMBLY__ */
6095084Sjohnlev 
610*6144Srab /* Default definitions for macros used by domctl/sysctl. */
611*6144Srab /*
612*6144Srab #if defined(__XEN__) || defined(__XEN_TOOLS__)
613*6144Srab */
614*6144Srab #ifndef uint64_aligned_t
615*6144Srab #define uint64_aligned_t uint64_t
616*6144Srab #endif
617*6144Srab #ifndef XEN_GUEST_HANDLE_64
618*6144Srab #define XEN_GUEST_HANDLE_64(name) XEN_GUEST_HANDLE(name)
619*6144Srab #endif
620*6144Srab /*
621*6144Srab #endif
622*6144Srab */
623*6144Srab 
624*6144Srab 
6255084Sjohnlev #endif /* __XEN_PUBLIC_XEN_H__ */
6265084Sjohnlev 
6275084Sjohnlev /*
6285084Sjohnlev  * Local variables:
6295084Sjohnlev  * mode: C
6305084Sjohnlev  * c-set-style: "BSD"
6315084Sjohnlev  * c-basic-offset: 4
6325084Sjohnlev  * tab-width: 4
6335084Sjohnlev  * indent-tabs-mode: nil
6345084Sjohnlev  * End:
6355084Sjohnlev  */
636