xref: /onnv-gate/usr/src/uts/common/xen/public/xen.h (revision 11120:fe619717975a)
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__)
336144Srab #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 #else
495084Sjohnlev #error "Unsupported architecture"
505084Sjohnlev #endif
515084Sjohnlev 
5210175SStuart.Maybee@Sun.COM #ifndef __ASSEMBLY__
5310175SStuart.Maybee@Sun.COM /* Guest handles for primitive C types. */
5410175SStuart.Maybee@Sun.COM DEFINE_XEN_GUEST_HANDLE(char);
5510175SStuart.Maybee@Sun.COM __DEFINE_XEN_GUEST_HANDLE(uchar, unsigned char);
5610175SStuart.Maybee@Sun.COM DEFINE_XEN_GUEST_HANDLE(int);
5710175SStuart.Maybee@Sun.COM __DEFINE_XEN_GUEST_HANDLE(uint,  unsigned int);
5810175SStuart.Maybee@Sun.COM DEFINE_XEN_GUEST_HANDLE(long);
5910175SStuart.Maybee@Sun.COM __DEFINE_XEN_GUEST_HANDLE(ulong, unsigned long);
6010175SStuart.Maybee@Sun.COM DEFINE_XEN_GUEST_HANDLE(void);
6110175SStuart.Maybee@Sun.COM 
6210175SStuart.Maybee@Sun.COM DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);
6310175SStuart.Maybee@Sun.COM #endif
6410175SStuart.Maybee@Sun.COM 
655084Sjohnlev /*
665084Sjohnlev  * HYPERCALLS
675084Sjohnlev  */
685084Sjohnlev 
695084Sjohnlev #define __HYPERVISOR_set_trap_table        0
705084Sjohnlev #define __HYPERVISOR_mmu_update            1
715084Sjohnlev #define __HYPERVISOR_set_gdt               2
725084Sjohnlev #define __HYPERVISOR_stack_switch          3
735084Sjohnlev #define __HYPERVISOR_set_callbacks         4
745084Sjohnlev #define __HYPERVISOR_fpu_taskswitch        5
755084Sjohnlev #define __HYPERVISOR_sched_op_compat       6 /* compat since 0x00030101 */
765084Sjohnlev #define __HYPERVISOR_platform_op           7
775084Sjohnlev #define __HYPERVISOR_set_debugreg          8
785084Sjohnlev #define __HYPERVISOR_get_debugreg          9
795084Sjohnlev #define __HYPERVISOR_update_descriptor    10
805084Sjohnlev #define __HYPERVISOR_memory_op            12
815084Sjohnlev #define __HYPERVISOR_multicall            13
825084Sjohnlev #define __HYPERVISOR_update_va_mapping    14
835084Sjohnlev #define __HYPERVISOR_set_timer_op         15
845084Sjohnlev #define __HYPERVISOR_event_channel_op_compat 16 /* compat since 0x00030202 */
855084Sjohnlev #define __HYPERVISOR_xen_version          17
865084Sjohnlev #define __HYPERVISOR_console_io           18
875084Sjohnlev #define __HYPERVISOR_physdev_op_compat    19 /* compat since 0x00030202 */
885084Sjohnlev #define __HYPERVISOR_grant_table_op       20
895084Sjohnlev #define __HYPERVISOR_vm_assist            21
905084Sjohnlev #define __HYPERVISOR_update_va_mapping_otherdomain 22
915084Sjohnlev #define __HYPERVISOR_iret                 23 /* x86 only */
925084Sjohnlev #define __HYPERVISOR_vcpu_op              24
935084Sjohnlev #define __HYPERVISOR_set_segment_base     25 /* x86/64 only */
945084Sjohnlev #define __HYPERVISOR_mmuext_op            26
9510175SStuart.Maybee@Sun.COM #define __HYPERVISOR_xsm_op               27
965084Sjohnlev #define __HYPERVISOR_nmi_op               28
975084Sjohnlev #define __HYPERVISOR_sched_op             29
985084Sjohnlev #define __HYPERVISOR_callback_op          30
995084Sjohnlev #define __HYPERVISOR_xenoprof_op          31
1005084Sjohnlev #define __HYPERVISOR_event_channel_op     32
1015084Sjohnlev #define __HYPERVISOR_physdev_op           33
1025084Sjohnlev #define __HYPERVISOR_hvm_op               34
1035084Sjohnlev #define __HYPERVISOR_sysctl               35
1045084Sjohnlev #define __HYPERVISOR_domctl               36
1055084Sjohnlev #define __HYPERVISOR_kexec_op             37
1065084Sjohnlev 
1075084Sjohnlev /* Architecture-specific hypercall definitions. */
1085084Sjohnlev #define __HYPERVISOR_arch_0               48
1095084Sjohnlev #define __HYPERVISOR_arch_1               49
1105084Sjohnlev #define __HYPERVISOR_arch_2               50
1115084Sjohnlev #define __HYPERVISOR_arch_3               51
1125084Sjohnlev #define __HYPERVISOR_arch_4               52
1135084Sjohnlev #define __HYPERVISOR_arch_5               53
1145084Sjohnlev #define __HYPERVISOR_arch_6               54
1155084Sjohnlev #define __HYPERVISOR_arch_7               55
1165084Sjohnlev 
1175084Sjohnlev /*
1185084Sjohnlev  * HYPERCALL COMPATIBILITY.
1195084Sjohnlev  */
1205084Sjohnlev 
1215084Sjohnlev /* New sched_op hypercall introduced in 0x00030101. */
1225084Sjohnlev #if __XEN_INTERFACE_VERSION__ < 0x00030101
1235084Sjohnlev #undef __HYPERVISOR_sched_op
1245084Sjohnlev #define __HYPERVISOR_sched_op __HYPERVISOR_sched_op_compat
1255084Sjohnlev #endif
1265084Sjohnlev 
1275084Sjohnlev /* New event-channel and physdev hypercalls introduced in 0x00030202. */
1285084Sjohnlev #if __XEN_INTERFACE_VERSION__ < 0x00030202
1295084Sjohnlev #undef __HYPERVISOR_event_channel_op
1305084Sjohnlev #define __HYPERVISOR_event_channel_op __HYPERVISOR_event_channel_op_compat
1315084Sjohnlev #undef __HYPERVISOR_physdev_op
1325084Sjohnlev #define __HYPERVISOR_physdev_op __HYPERVISOR_physdev_op_compat
1335084Sjohnlev #endif
1345084Sjohnlev 
1355084Sjohnlev /* New platform_op hypercall introduced in 0x00030204. */
1365084Sjohnlev #if __XEN_INTERFACE_VERSION__ < 0x00030204
1375084Sjohnlev #define __HYPERVISOR_dom0_op __HYPERVISOR_platform_op
1385084Sjohnlev #endif
1395084Sjohnlev 
1405084Sjohnlev /*
1415084Sjohnlev  * VIRTUAL INTERRUPTS
1425084Sjohnlev  *
1435084Sjohnlev  * Virtual interrupts that a guest OS may receive from Xen.
1445084Sjohnlev  *
1455084Sjohnlev  * In the side comments, 'V.' denotes a per-VCPU VIRQ while 'G.' denotes a
1465084Sjohnlev  * global VIRQ. The former can be bound once per VCPU and cannot be re-bound.
1475084Sjohnlev  * The latter can be allocated only once per guest: they must initially be
1485084Sjohnlev  * allocated to VCPU0 but can subsequently be re-bound.
1495084Sjohnlev  */
1505084Sjohnlev #define VIRQ_TIMER      0  /* V. Timebase update, and/or requested timeout.  */
1515084Sjohnlev #define VIRQ_DEBUG      1  /* V. Request guest to dump debug info.           */
1525084Sjohnlev #define VIRQ_CONSOLE    2  /* G. (DOM0) Bytes received on emergency console. */
1535084Sjohnlev #define VIRQ_DOM_EXC    3  /* G. (DOM0) Exceptional event for some domain.   */
1545084Sjohnlev #define VIRQ_TBUF       4  /* G. (DOM0) Trace buffer has records available.  */
1555084Sjohnlev #define VIRQ_DEBUGGER   6  /* G. (DOM0) A domain has paused for debugging.   */
1565084Sjohnlev #define VIRQ_XENOPROF   7  /* V. XenOprofile interrupt: new sample available */
1576144Srab #define VIRQ_CON_RING   8  /* G. (DOM0) Bytes received on console            */
1585084Sjohnlev 
1595084Sjohnlev /* Architecture-specific VIRQ definitions. */
1605084Sjohnlev #define VIRQ_ARCH_0    16
1615084Sjohnlev #define VIRQ_ARCH_1    17
1625084Sjohnlev #define VIRQ_ARCH_2    18
1635084Sjohnlev #define VIRQ_ARCH_3    19
1645084Sjohnlev #define VIRQ_ARCH_4    20
1655084Sjohnlev #define VIRQ_ARCH_5    21
1665084Sjohnlev #define VIRQ_ARCH_6    22
1675084Sjohnlev #define VIRQ_ARCH_7    23
1685084Sjohnlev 
1695084Sjohnlev #define NR_VIRQS       24
1705084Sjohnlev 
1715084Sjohnlev /*
1725084Sjohnlev  * MMU-UPDATE REQUESTS
1735084Sjohnlev  *
1745084Sjohnlev  * HYPERVISOR_mmu_update() accepts a list of (ptr, val) pairs.
1755084Sjohnlev  * A foreigndom (FD) can be specified (or DOMID_SELF for none).
1765084Sjohnlev  * Where the FD has some effect, it is described below.
1775084Sjohnlev  * ptr[1:0] specifies the appropriate MMU_* command.
1785084Sjohnlev  *
1795084Sjohnlev  * ptr[1:0] == MMU_NORMAL_PT_UPDATE:
1805084Sjohnlev  * Updates an entry in a page table. If updating an L1 table, and the new
1815084Sjohnlev  * table entry is valid/present, the mapped frame must belong to the FD, if
1825084Sjohnlev  * an FD has been specified. If attempting to map an I/O page then the
1835084Sjohnlev  * caller assumes the privilege of the FD.
1845084Sjohnlev  * FD == DOMID_IO: Permit /only/ I/O mappings, at the priv level of the caller.
1855084Sjohnlev  * FD == DOMID_XEN: Map restricted areas of Xen's heap space.
1865084Sjohnlev  * ptr[:2]  -- Machine address of the page-table entry to modify.
1875084Sjohnlev  * val      -- Value to write.
1885084Sjohnlev  *
1895084Sjohnlev  * ptr[1:0] == MMU_MACHPHYS_UPDATE:
1905084Sjohnlev  * Updates an entry in the machine->pseudo-physical mapping table.
1915084Sjohnlev  * ptr[:2]  -- Machine address within the frame whose mapping to modify.
1925084Sjohnlev  *             The frame must belong to the FD, if one is specified.
1935084Sjohnlev  * val      -- Value to write into the mapping entry.
19410175SStuart.Maybee@Sun.COM  *
19510175SStuart.Maybee@Sun.COM  * ptr[1:0] == MMU_PT_UPDATE_PRESERVE_AD:
19610175SStuart.Maybee@Sun.COM  * As MMU_NORMAL_PT_UPDATE above, but A/D bits currently in the PTE are ORed
19710175SStuart.Maybee@Sun.COM  * with those in @val.
1985084Sjohnlev  */
19910175SStuart.Maybee@Sun.COM #define MMU_NORMAL_PT_UPDATE      0 /* checked '*ptr = val'. ptr is MA.      */
20010175SStuart.Maybee@Sun.COM #define MMU_MACHPHYS_UPDATE       1 /* ptr = MA of frame to modify entry for */
20110175SStuart.Maybee@Sun.COM #define MMU_PT_UPDATE_PRESERVE_AD 2 /* atomically: *ptr = val | (*ptr&(A|D)) */
2025084Sjohnlev 
2035084Sjohnlev /*
2045084Sjohnlev  * MMU EXTENDED OPERATIONS
2055084Sjohnlev  *
2065084Sjohnlev  * HYPERVISOR_mmuext_op() accepts a list of mmuext_op structures.
2075084Sjohnlev  * A foreigndom (FD) can be specified (or DOMID_SELF for none).
2085084Sjohnlev  * Where the FD has some effect, it is described below.
2095084Sjohnlev  *
2105084Sjohnlev  * cmd: MMUEXT_(UN)PIN_*_TABLE
2115084Sjohnlev  * mfn: Machine frame number to be (un)pinned as a p.t. page.
2125084Sjohnlev  *      The frame must belong to the FD, if one is specified.
2135084Sjohnlev  *
2145084Sjohnlev  * cmd: MMUEXT_NEW_BASEPTR
2155084Sjohnlev  * mfn: Machine frame number of new page-table base to install in MMU.
2165084Sjohnlev  *
2175084Sjohnlev  * cmd: MMUEXT_NEW_USER_BASEPTR [x86/64 only]
2185084Sjohnlev  * mfn: Machine frame number of new page-table base to install in MMU
2195084Sjohnlev  *      when in user space.
2205084Sjohnlev  *
2215084Sjohnlev  * cmd: MMUEXT_TLB_FLUSH_LOCAL
2225084Sjohnlev  * No additional arguments. Flushes local TLB.
2235084Sjohnlev  *
2245084Sjohnlev  * cmd: MMUEXT_INVLPG_LOCAL
2255084Sjohnlev  * linear_addr: Linear address to be flushed from the local TLB.
2265084Sjohnlev  *
2275084Sjohnlev  * cmd: MMUEXT_TLB_FLUSH_MULTI
2285084Sjohnlev  * vcpumask: Pointer to bitmap of VCPUs to be flushed.
2295084Sjohnlev  *
2305084Sjohnlev  * cmd: MMUEXT_INVLPG_MULTI
2315084Sjohnlev  * linear_addr: Linear address to be flushed.
2325084Sjohnlev  * vcpumask: Pointer to bitmap of VCPUs to be flushed.
2335084Sjohnlev  *
2345084Sjohnlev  * cmd: MMUEXT_TLB_FLUSH_ALL
2355084Sjohnlev  * No additional arguments. Flushes all VCPUs' TLBs.
2365084Sjohnlev  *
2375084Sjohnlev  * cmd: MMUEXT_INVLPG_ALL
2385084Sjohnlev  * linear_addr: Linear address to be flushed from all VCPUs' TLBs.
2395084Sjohnlev  *
2405084Sjohnlev  * cmd: MMUEXT_FLUSH_CACHE
2415084Sjohnlev  * No additional arguments. Writes back and flushes cache contents.
2425084Sjohnlev  *
2435084Sjohnlev  * cmd: MMUEXT_SET_LDT
2445084Sjohnlev  * linear_addr: Linear address of LDT base (NB. must be page-aligned).
2455084Sjohnlev  * nr_ents: Number of entries in LDT.
246*11120SMark.Johnson@Sun.COM  *
247*11120SMark.Johnson@Sun.COM  * cmd: MMUEXT_CLEAR_PAGE
248*11120SMark.Johnson@Sun.COM  * mfn: Machine frame number to be cleared.
249*11120SMark.Johnson@Sun.COM  *
250*11120SMark.Johnson@Sun.COM  * cmd: MMUEXT_COPY_PAGE
251*11120SMark.Johnson@Sun.COM  * mfn: Machine frame number of the destination page.
252*11120SMark.Johnson@Sun.COM  * src_mfn: Machine frame number of the source page.
2535084Sjohnlev  */
2545084Sjohnlev #define MMUEXT_PIN_L1_TABLE      0
2555084Sjohnlev #define MMUEXT_PIN_L2_TABLE      1
2565084Sjohnlev #define MMUEXT_PIN_L3_TABLE      2
2575084Sjohnlev #define MMUEXT_PIN_L4_TABLE      3
2585084Sjohnlev #define MMUEXT_UNPIN_TABLE       4
2595084Sjohnlev #define MMUEXT_NEW_BASEPTR       5
2605084Sjohnlev #define MMUEXT_TLB_FLUSH_LOCAL   6
2615084Sjohnlev #define MMUEXT_INVLPG_LOCAL      7
2625084Sjohnlev #define MMUEXT_TLB_FLUSH_MULTI   8
2635084Sjohnlev #define MMUEXT_INVLPG_MULTI      9
2645084Sjohnlev #define MMUEXT_TLB_FLUSH_ALL    10
2655084Sjohnlev #define MMUEXT_INVLPG_ALL       11
2665084Sjohnlev #define MMUEXT_FLUSH_CACHE      12
2675084Sjohnlev #define MMUEXT_SET_LDT          13
2685084Sjohnlev #define MMUEXT_NEW_USER_BASEPTR 15
269*11120SMark.Johnson@Sun.COM #define MMUEXT_CLEAR_PAGE       16
270*11120SMark.Johnson@Sun.COM #define MMUEXT_COPY_PAGE        17
2715084Sjohnlev 
2725084Sjohnlev #ifndef __ASSEMBLY__
2735084Sjohnlev struct mmuext_op {
2745084Sjohnlev     unsigned int cmd;
2755084Sjohnlev     union {
276*11120SMark.Johnson@Sun.COM         /* [UN]PIN_TABLE, NEW_BASEPTR, NEW_USER_BASEPTR
277*11120SMark.Johnson@Sun.COM          * CLEAR_PAGE, COPY_PAGE */
2785084Sjohnlev         xen_pfn_t     mfn;
2795084Sjohnlev         /* INVLPG_LOCAL, INVLPG_ALL, SET_LDT */
2805084Sjohnlev         unsigned long linear_addr;
2815084Sjohnlev     } arg1;
2825084Sjohnlev     union {
2835084Sjohnlev         /* SET_LDT */
2845084Sjohnlev         unsigned int nr_ents;
2855084Sjohnlev         /* TLB_FLUSH_MULTI, INVLPG_MULTI */
28610175SStuart.Maybee@Sun.COM #if __XEN_INTERFACE_VERSION__ >= 0x00030205
287*11120SMark.Johnson@Sun.COM         XEN_GUEST_HANDLE(const_void) vcpumask;
28810175SStuart.Maybee@Sun.COM #else
289*11120SMark.Johnson@Sun.COM         const void *vcpumask;
29010175SStuart.Maybee@Sun.COM #endif
291*11120SMark.Johnson@Sun.COM         /* COPY_PAGE */
292*11120SMark.Johnson@Sun.COM         xen_pfn_t src_mfn;
2935084Sjohnlev     } arg2;
2945084Sjohnlev };
2955084Sjohnlev typedef struct mmuext_op mmuext_op_t;
2965084Sjohnlev DEFINE_XEN_GUEST_HANDLE(mmuext_op_t);
2975084Sjohnlev #endif
2985084Sjohnlev 
2995084Sjohnlev /* These are passed as 'flags' to update_va_mapping. They can be ORed. */
3005084Sjohnlev /* When specifying UVMF_MULTI, also OR in a pointer to a CPU bitmap.   */
3015084Sjohnlev /* UVMF_LOCAL is merely UVMF_MULTI with a NULL bitmap pointer.         */
3025084Sjohnlev #define UVMF_NONE               (0UL<<0) /* No flushing at all.   */
3035084Sjohnlev #define UVMF_TLB_FLUSH          (1UL<<0) /* Flush entire TLB(s).  */
3045084Sjohnlev #define UVMF_INVLPG             (2UL<<0) /* Flush only one entry. */
3055084Sjohnlev #define UVMF_FLUSHTYPE_MASK     (3UL<<0)
3065084Sjohnlev #define UVMF_MULTI              (0UL<<2) /* Flush subset of TLBs. */
3075084Sjohnlev #define UVMF_LOCAL              (0UL<<2) /* Flush local TLB.      */
3085084Sjohnlev #define UVMF_ALL                (1UL<<2) /* Flush all TLBs.       */
3095084Sjohnlev 
3105084Sjohnlev /*
3115084Sjohnlev  * Commands to HYPERVISOR_console_io().
3125084Sjohnlev  */
3135084Sjohnlev #define CONSOLEIO_write         0
3145084Sjohnlev #define CONSOLEIO_read          1
3155084Sjohnlev #define CONSOLEIO_get_device   32
3165084Sjohnlev 
3175084Sjohnlev /*
3185084Sjohnlev  * Commands to HYPERVISOR_vm_assist().
3195084Sjohnlev  */
3205084Sjohnlev #define VMASST_CMD_enable                0
3215084Sjohnlev #define VMASST_CMD_disable               1
3225084Sjohnlev 
3235084Sjohnlev /* x86/32 guests: simulate full 4GB segment limits. */
3245084Sjohnlev #define VMASST_TYPE_4gb_segments         0
3255084Sjohnlev 
3265084Sjohnlev /* x86/32 guests: trap (vector 15) whenever above vmassist is used. */
3275084Sjohnlev #define VMASST_TYPE_4gb_segments_notify  1
3285084Sjohnlev 
3295084Sjohnlev /*
3305084Sjohnlev  * x86 guests: support writes to bottom-level PTEs.
3315084Sjohnlev  * NB1. Page-directory entries cannot be written.
3325084Sjohnlev  * NB2. Guest must continue to remove all writable mappings of PTEs.
3335084Sjohnlev  */
3345084Sjohnlev #define VMASST_TYPE_writable_pagetables  2
3355084Sjohnlev 
3365084Sjohnlev /* x86/PAE guests: support PDPTs above 4GB. */
3375084Sjohnlev #define VMASST_TYPE_pae_extended_cr3     3
3385084Sjohnlev 
3395084Sjohnlev #define MAX_VMASST_TYPE                  3
3405084Sjohnlev 
3415084Sjohnlev #ifndef __ASSEMBLY__
3425084Sjohnlev 
3435084Sjohnlev typedef uint16_t domid_t;
3445084Sjohnlev 
3455084Sjohnlev /* Domain ids >= DOMID_FIRST_RESERVED cannot be used for ordinary domains. */
3465084Sjohnlev #define DOMID_FIRST_RESERVED (0x7FF0U)
3475084Sjohnlev 
3485084Sjohnlev /* DOMID_SELF is used in certain contexts to refer to oneself. */
3495084Sjohnlev #define DOMID_SELF (0x7FF0U)
3505084Sjohnlev 
3515084Sjohnlev /*
3525084Sjohnlev  * DOMID_IO is used to restrict page-table updates to mapping I/O memory.
3535084Sjohnlev  * Although no Foreign Domain need be specified to map I/O pages, DOMID_IO
3545084Sjohnlev  * is useful to ensure that no mappings to the OS's own heap are accidentally
3555084Sjohnlev  * installed. (e.g., in Linux this could cause havoc as reference counts
3565084Sjohnlev  * aren't adjusted on the I/O-mapping code path).
3575084Sjohnlev  * This only makes sense in MMUEXT_SET_FOREIGNDOM, but in that context can
3585084Sjohnlev  * be specified by any calling domain.
3595084Sjohnlev  */
3605084Sjohnlev #define DOMID_IO   (0x7FF1U)
3615084Sjohnlev 
3625084Sjohnlev /*
3635084Sjohnlev  * DOMID_XEN is used to allow privileged domains to map restricted parts of
3645084Sjohnlev  * Xen's heap space (e.g., the machine_to_phys table).
3655084Sjohnlev  * This only makes sense in MMUEXT_SET_FOREIGNDOM, and is only permitted if
3665084Sjohnlev  * the caller is privileged.
3675084Sjohnlev  */
3685084Sjohnlev #define DOMID_XEN  (0x7FF2U)
3695084Sjohnlev 
370*11120SMark.Johnson@Sun.COM /* DOMID_INVALID is used to identity invalid domid */
371*11120SMark.Johnson@Sun.COM #define DOMID_INVALID (0x7FFFU)
372*11120SMark.Johnson@Sun.COM 
3735084Sjohnlev /*
3745084Sjohnlev  * Send an array of these to HYPERVISOR_mmu_update().
3755084Sjohnlev  * NB. The fields are natural pointer/address size for this architecture.
3765084Sjohnlev  */
3775084Sjohnlev struct mmu_update {
3785084Sjohnlev     uint64_t ptr;       /* Machine address of PTE. */
3795084Sjohnlev     uint64_t val;       /* New contents of PTE.    */
3805084Sjohnlev };
3815084Sjohnlev typedef struct mmu_update mmu_update_t;
3825084Sjohnlev DEFINE_XEN_GUEST_HANDLE(mmu_update_t);
3835084Sjohnlev 
3845084Sjohnlev /*
3855084Sjohnlev  * Send an array of these to HYPERVISOR_multicall().
3865084Sjohnlev  * NB. The fields are natural register size for this architecture.
3875084Sjohnlev  */
3885084Sjohnlev struct multicall_entry {
3895084Sjohnlev     unsigned long op, result;
3905084Sjohnlev     unsigned long args[6];
3915084Sjohnlev };
3925084Sjohnlev typedef struct multicall_entry multicall_entry_t;
3935084Sjohnlev DEFINE_XEN_GUEST_HANDLE(multicall_entry_t);
3945084Sjohnlev 
3955084Sjohnlev /*
3965084Sjohnlev  * Event channel endpoints per domain:
3975084Sjohnlev  *  1024 if a long is 32 bits; 4096 if a long is 64 bits.
3985084Sjohnlev  */
3995084Sjohnlev #define NR_EVENT_CHANNELS (sizeof(unsigned long) * sizeof(unsigned long) * 64)
4005084Sjohnlev 
4015084Sjohnlev struct vcpu_time_info {
4025084Sjohnlev     /*
4035084Sjohnlev      * Updates to the following values are preceded and followed by an
4045084Sjohnlev      * increment of 'version'. The guest can therefore detect updates by
4055084Sjohnlev      * looking for changes to 'version'. If the least-significant bit of
4065084Sjohnlev      * the version number is set then an update is in progress and the guest
4075084Sjohnlev      * must wait to read a consistent set of values.
4085084Sjohnlev      * The correct way to interact with the version number is similar to
4095084Sjohnlev      * Linux's seqlock: see the implementations of read_seqbegin/read_seqretry.
4105084Sjohnlev      */
4115084Sjohnlev     uint32_t version;
4125084Sjohnlev     uint32_t pad0;
4135084Sjohnlev     uint64_t tsc_timestamp;   /* TSC at last update of time vals.  */
4145084Sjohnlev     uint64_t system_time;     /* Time, in nanosecs, since boot.    */
4155084Sjohnlev     /*
4165084Sjohnlev      * Current system time:
4175084Sjohnlev      *   system_time +
4185084Sjohnlev      *   ((((tsc - tsc_timestamp) << tsc_shift) * tsc_to_system_mul) >> 32)
4195084Sjohnlev      * CPU frequency (Hz):
4205084Sjohnlev      *   ((10^9 << 32) / tsc_to_system_mul) >> tsc_shift
4215084Sjohnlev      */
4225084Sjohnlev     uint32_t tsc_to_system_mul;
4235084Sjohnlev     int8_t   tsc_shift;
4245084Sjohnlev     int8_t   pad1[3];
4255084Sjohnlev }; /* 32 bytes */
4265084Sjohnlev typedef struct vcpu_time_info vcpu_time_info_t;
4275084Sjohnlev 
4285084Sjohnlev struct vcpu_info {
4295084Sjohnlev     /*
4305084Sjohnlev      * 'evtchn_upcall_pending' is written non-zero by Xen to indicate
4315084Sjohnlev      * a pending notification for a particular VCPU. It is then cleared
4325084Sjohnlev      * by the guest OS /before/ checking for pending work, thus avoiding
4335084Sjohnlev      * a set-and-check race. Note that the mask is only accessed by Xen
4345084Sjohnlev      * on the CPU that is currently hosting the VCPU. This means that the
4355084Sjohnlev      * pending and mask flags can be updated by the guest without special
4365084Sjohnlev      * synchronisation (i.e., no need for the x86 LOCK prefix).
4375084Sjohnlev      * This may seem suboptimal because if the pending flag is set by
4385084Sjohnlev      * a different CPU then an IPI may be scheduled even when the mask
4395084Sjohnlev      * is set. However, note:
4405084Sjohnlev      *  1. The task of 'interrupt holdoff' is covered by the per-event-
4415084Sjohnlev      *     channel mask bits. A 'noisy' event that is continually being
4425084Sjohnlev      *     triggered can be masked at source at this very precise
4435084Sjohnlev      *     granularity.
4445084Sjohnlev      *  2. The main purpose of the per-VCPU mask is therefore to restrict
4455084Sjohnlev      *     reentrant execution: whether for concurrency control, or to
4465084Sjohnlev      *     prevent unbounded stack usage. Whatever the purpose, we expect
4475084Sjohnlev      *     that the mask will be asserted only for short periods at a time,
4485084Sjohnlev      *     and so the likelihood of a 'spurious' IPI is suitably small.
4495084Sjohnlev      * The mask is read before making an event upcall to the guest: a
4505084Sjohnlev      * non-zero mask therefore guarantees that the VCPU will not receive
4515084Sjohnlev      * an upcall activation. The mask is cleared when the VCPU requests
4525084Sjohnlev      * to block: this avoids wakeup-waiting races.
4535084Sjohnlev      */
4545084Sjohnlev     uint8_t evtchn_upcall_pending;
4555084Sjohnlev     uint8_t evtchn_upcall_mask;
4565084Sjohnlev     unsigned long evtchn_pending_sel;
4575084Sjohnlev     struct arch_vcpu_info arch;
4585084Sjohnlev     struct vcpu_time_info time;
4595084Sjohnlev }; /* 64 bytes (x86) */
4606144Srab #ifndef __XEN__
4615084Sjohnlev typedef struct vcpu_info vcpu_info_t;
4626144Srab #endif
4635084Sjohnlev 
4645084Sjohnlev /*
4655084Sjohnlev  * Xen/kernel shared data -- pointer provided in start_info.
4665084Sjohnlev  *
4675084Sjohnlev  * This structure is defined to be both smaller than a page, and the
4685084Sjohnlev  * only data on the shared page, but may vary in actual size even within
4695084Sjohnlev  * compatible Xen versions; guests should not rely on the size
4705084Sjohnlev  * of this structure remaining constant.
4715084Sjohnlev  */
4725084Sjohnlev struct shared_info {
4735084Sjohnlev     struct vcpu_info vcpu_info[MAX_VIRT_CPUS];
4745084Sjohnlev 
4755084Sjohnlev     /*
4765084Sjohnlev      * A domain can create "event channels" on which it can send and receive
4775084Sjohnlev      * asynchronous event notifications. There are three classes of event that
4785084Sjohnlev      * are delivered by this mechanism:
4795084Sjohnlev      *  1. Bi-directional inter- and intra-domain connections. Domains must
4805084Sjohnlev      *     arrange out-of-band to set up a connection (usually by allocating
4815084Sjohnlev      *     an unbound 'listener' port and avertising that via a storage service
4825084Sjohnlev      *     such as xenstore).
4835084Sjohnlev      *  2. Physical interrupts. A domain with suitable hardware-access
4845084Sjohnlev      *     privileges can bind an event-channel port to a physical interrupt
4855084Sjohnlev      *     source.
4865084Sjohnlev      *  3. Virtual interrupts ('events'). A domain can bind an event-channel
4875084Sjohnlev      *     port to a virtual interrupt source, such as the virtual-timer
4885084Sjohnlev      *     device or the emergency console.
4895084Sjohnlev      *
4905084Sjohnlev      * Event channels are addressed by a "port index". Each channel is
4915084Sjohnlev      * associated with two bits of information:
4925084Sjohnlev      *  1. PENDING -- notifies the domain that there is a pending notification
4935084Sjohnlev      *     to be processed. This bit is cleared by the guest.
4945084Sjohnlev      *  2. MASK -- if this bit is clear then a 0->1 transition of PENDING
4955084Sjohnlev      *     will cause an asynchronous upcall to be scheduled. This bit is only
4965084Sjohnlev      *     updated by the guest. It is read-only within Xen. If a channel
4975084Sjohnlev      *     becomes pending while the channel is masked then the 'edge' is lost
4985084Sjohnlev      *     (i.e., when the channel is unmasked, the guest must manually handle
4995084Sjohnlev      *     pending notifications as no upcall will be scheduled by Xen).
5005084Sjohnlev      *
5015084Sjohnlev      * To expedite scanning of pending notifications, any 0->1 pending
5025084Sjohnlev      * transition on an unmasked channel causes a corresponding bit in a
5035084Sjohnlev      * per-vcpu selector word to be set. Each bit in the selector covers a
5045084Sjohnlev      * 'C long' in the PENDING bitfield array.
5055084Sjohnlev      */
5065084Sjohnlev     unsigned long evtchn_pending[sizeof(unsigned long) * 8];
5075084Sjohnlev     unsigned long evtchn_mask[sizeof(unsigned long) * 8];
5085084Sjohnlev 
5095084Sjohnlev     /*
5105084Sjohnlev      * Wallclock time: updated only by control software. Guests should base
5115084Sjohnlev      * their gettimeofday() syscall on this wallclock-base value.
5125084Sjohnlev      */
5135084Sjohnlev     uint32_t wc_version;      /* Version counter: see vcpu_time_info_t. */
5145084Sjohnlev     uint32_t wc_sec;          /* Secs  00:00:00 UTC, Jan 1, 1970.  */
5155084Sjohnlev     uint32_t wc_nsec;         /* Nsecs 00:00:00 UTC, Jan 1, 1970.  */
5165084Sjohnlev 
5175084Sjohnlev     struct arch_shared_info arch;
5185084Sjohnlev 
5195084Sjohnlev };
5206144Srab #ifndef __XEN__
5215084Sjohnlev typedef struct shared_info shared_info_t;
5226144Srab #endif
5235084Sjohnlev 
5245084Sjohnlev /*
5256144Srab  * Start-of-day memory layout:
5265084Sjohnlev  *  1. The domain is started within contiguous virtual-memory region.
5276144Srab  *  2. The contiguous region ends on an aligned 4MB boundary.
5286144Srab  *  3. This the order of bootstrap elements in the initial virtual region:
5295084Sjohnlev  *      a. relocated kernel image
5305084Sjohnlev  *      b. initial ram disk              [mod_start, mod_len]
5315084Sjohnlev  *      c. list of allocated page frames [mfn_list, nr_pages]
532*11120SMark.Johnson@Sun.COM  *         (unless relocated due to XEN_ELFNOTE_INIT_P2M)
5335084Sjohnlev  *      d. start_info_t structure        [register ESI (x86)]
5345084Sjohnlev  *      e. bootstrap page tables         [pt_base, CR3 (x86)]
5355084Sjohnlev  *      f. bootstrap stack               [register ESP (x86)]
5366144Srab  *  4. Bootstrap elements are packed together, but each is 4kB-aligned.
5376144Srab  *  5. The initial ram disk may be omitted.
5386144Srab  *  6. The list of page frames forms a contiguous 'pseudo-physical' memory
5395084Sjohnlev  *     layout for the domain. In particular, the bootstrap virtual-memory
5405084Sjohnlev  *     region is a 1:1 mapping to the first section of the pseudo-physical map.
5416144Srab  *  7. All bootstrap elements are mapped read-writable for the guest OS. The
5425084Sjohnlev  *     only exception is the bootstrap page table, which is mapped read-only.
5436144Srab  *  8. There is guaranteed to be at least 512kB padding after the final
5445084Sjohnlev  *     bootstrap element. If necessary, the bootstrap virtual region is
5455084Sjohnlev  *     extended by an extra 4MB to ensure this.
5465084Sjohnlev  */
5475084Sjohnlev 
5485084Sjohnlev #define MAX_GUEST_CMDLINE 1024
5495084Sjohnlev struct start_info {
5505084Sjohnlev     /* THE FOLLOWING ARE FILLED IN BOTH ON INITIAL BOOT AND ON RESUME.    */
5515084Sjohnlev     char magic[32];             /* "xen-<version>-<platform>".            */
5525084Sjohnlev     unsigned long nr_pages;     /* Total pages allocated to this domain.  */
5535084Sjohnlev     unsigned long shared_info;  /* MACHINE address of shared info struct. */
5545084Sjohnlev     uint32_t flags;             /* SIF_xxx flags.                         */
5555084Sjohnlev     xen_pfn_t store_mfn;        /* MACHINE page number of shared page.    */
5565084Sjohnlev     uint32_t store_evtchn;      /* Event channel for store communication. */
5575084Sjohnlev     union {
5585084Sjohnlev         struct {
5595084Sjohnlev             xen_pfn_t mfn;      /* MACHINE page number of console page.   */
5605084Sjohnlev             uint32_t  evtchn;   /* Event channel for console page.        */
5615084Sjohnlev         } domU;
5625084Sjohnlev         struct {
5635084Sjohnlev             uint32_t info_off;  /* Offset of console_info struct.         */
5645084Sjohnlev             uint32_t info_size; /* Size of console_info struct from start.*/
5655084Sjohnlev         } dom0;
5665084Sjohnlev     } console;
5675084Sjohnlev     /* THE FOLLOWING ARE ONLY FILLED IN ON INITIAL BOOT (NOT RESUME).     */
5685084Sjohnlev     unsigned long pt_base;      /* VIRTUAL address of page directory.     */
5695084Sjohnlev     unsigned long nr_pt_frames; /* Number of bootstrap p.t. frames.       */
5705084Sjohnlev     unsigned long mfn_list;     /* VIRTUAL address of page-frame list.    */
5715084Sjohnlev     unsigned long mod_start;    /* VIRTUAL address of pre-loaded module.  */
5725084Sjohnlev     unsigned long mod_len;      /* Size (bytes) of pre-loaded module.     */
5735084Sjohnlev     int8_t cmd_line[MAX_GUEST_CMDLINE];
574*11120SMark.Johnson@Sun.COM     /* The pfn range here covers both page table and p->m table frames.   */
575*11120SMark.Johnson@Sun.COM     unsigned long first_p2m_pfn;/* 1st pfn forming initial P->M table.    */
576*11120SMark.Johnson@Sun.COM     unsigned long nr_p2m_frames;/* # of pfns forming initial P->M table.  */
5775084Sjohnlev };
5785084Sjohnlev typedef struct start_info start_info_t;
5795084Sjohnlev 
5805084Sjohnlev /* New console union for dom0 introduced in 0x00030203. */
5815084Sjohnlev #if __XEN_INTERFACE_VERSION__ < 0x00030203
5825084Sjohnlev #define console_mfn    console.domU.mfn
5835084Sjohnlev #define console_evtchn console.domU.evtchn
5845084Sjohnlev #endif
5855084Sjohnlev 
5865084Sjohnlev /* These flags are passed in the 'flags' field of start_info_t. */
5875084Sjohnlev #define SIF_PRIVILEGED    (1<<0)  /* Is the domain privileged? */
5885084Sjohnlev #define SIF_INITDOMAIN    (1<<1)  /* Is this the initial control domain? */
58910175SStuart.Maybee@Sun.COM #define SIF_PM_MASK       (0xFF<<8) /* reserve 1 byte for xen-pm options */
5905084Sjohnlev 
5915084Sjohnlev #define XEN_CONSOLE_INVALID   -1
5925084Sjohnlev #define XEN_CONSOLE_COM1       0
5935084Sjohnlev #define XEN_CONSOLE_COM2       1
5945084Sjohnlev #define XEN_CONSOLE_VGA        2
5955084Sjohnlev 
5965084Sjohnlev typedef struct dom0_vga_console_info {
5975084Sjohnlev     uint8_t video_type; /* DOM0_VGA_CONSOLE_??? */
5985084Sjohnlev #define XEN_VGATYPE_TEXT_MODE_3 0x03
5995084Sjohnlev #define XEN_VGATYPE_VESA_LFB    0x23
6005084Sjohnlev 
6015084Sjohnlev     union {
6025084Sjohnlev         struct {
6035084Sjohnlev             /* Font height, in pixels. */
6045084Sjohnlev             uint16_t font_height;
6055084Sjohnlev             /* Cursor location (column, row). */
6065084Sjohnlev             uint16_t cursor_x, cursor_y;
6075084Sjohnlev             /* Number of rows and columns (dimensions in characters). */
6085084Sjohnlev             uint16_t rows, columns;
6095084Sjohnlev         } text_mode_3;
6105084Sjohnlev 
6115084Sjohnlev         struct {
6125084Sjohnlev             /* Width and height, in pixels. */
6135084Sjohnlev             uint16_t width, height;
6145084Sjohnlev             /* Bytes per scan line. */
6155084Sjohnlev             uint16_t bytes_per_line;
6165084Sjohnlev             /* Bits per pixel. */
6175084Sjohnlev             uint16_t bits_per_pixel;
6185084Sjohnlev             /* LFB physical address, and size (in units of 64kB). */
6195084Sjohnlev             uint32_t lfb_base;
6205084Sjohnlev             uint32_t lfb_size;
6215084Sjohnlev             /* RGB mask offsets and sizes, as defined by VBE 1.2+ */
6225084Sjohnlev             uint8_t  red_pos, red_size;
6235084Sjohnlev             uint8_t  green_pos, green_size;
6245084Sjohnlev             uint8_t  blue_pos, blue_size;
6255084Sjohnlev             uint8_t  rsvd_pos, rsvd_size;
62610175SStuart.Maybee@Sun.COM #if __XEN_INTERFACE_VERSION__ >= 0x00030206
62710175SStuart.Maybee@Sun.COM             /* VESA capabilities (offset 0xa, VESA command 0x4f00). */
62810175SStuart.Maybee@Sun.COM             uint32_t gbl_caps;
62910175SStuart.Maybee@Sun.COM             /* Mode attributes (offset 0x0, VESA command 0x4f01). */
63010175SStuart.Maybee@Sun.COM             uint16_t mode_attrs;
63110175SStuart.Maybee@Sun.COM #endif
6325084Sjohnlev         } vesa_lfb;
6335084Sjohnlev     } u;
6345084Sjohnlev } dom0_vga_console_info_t;
6356144Srab #define xen_vga_console_info dom0_vga_console_info
6366144Srab #define xen_vga_console_info_t dom0_vga_console_info_t
6375084Sjohnlev 
6385084Sjohnlev typedef uint8_t xen_domain_handle_t[16];
6395084Sjohnlev 
6405084Sjohnlev /* Turn a plain number into a C unsigned long constant. */
6415084Sjohnlev #define __mk_unsigned_long(x) x ## UL
6425084Sjohnlev #define mk_unsigned_long(x) __mk_unsigned_long(x)
6435084Sjohnlev 
64410175SStuart.Maybee@Sun.COM __DEFINE_XEN_GUEST_HANDLE(uint8,  uint8_t);
64510175SStuart.Maybee@Sun.COM __DEFINE_XEN_GUEST_HANDLE(uint16, uint16_t);
64610175SStuart.Maybee@Sun.COM __DEFINE_XEN_GUEST_HANDLE(uint32, uint32_t);
64710175SStuart.Maybee@Sun.COM __DEFINE_XEN_GUEST_HANDLE(uint64, uint64_t);
6485084Sjohnlev 
6495084Sjohnlev #else /* __ASSEMBLY__ */
6505084Sjohnlev 
6515084Sjohnlev /* In assembly code we cannot use C numeric constant suffixes. */
6525084Sjohnlev #define mk_unsigned_long(x) x
6535084Sjohnlev 
6545084Sjohnlev #endif /* !__ASSEMBLY__ */
6555084Sjohnlev 
6566144Srab /* Default definitions for macros used by domctl/sysctl. */
6576144Srab #if defined(__XEN__) || defined(__XEN_TOOLS__)
6586144Srab #ifndef uint64_aligned_t
6596144Srab #define uint64_aligned_t uint64_t
6606144Srab #endif
6616144Srab #ifndef XEN_GUEST_HANDLE_64
6626144Srab #define XEN_GUEST_HANDLE_64(name) XEN_GUEST_HANDLE(name)
6636144Srab #endif
6646144Srab #endif
6656144Srab 
6665084Sjohnlev #endif /* __XEN_PUBLIC_XEN_H__ */
6675084Sjohnlev 
6685084Sjohnlev /*
6695084Sjohnlev  * Local variables:
6705084Sjohnlev  * mode: C
6715084Sjohnlev  * c-set-style: "BSD"
6725084Sjohnlev  * c-basic-offset: 4
6735084Sjohnlev  * tab-width: 4
6745084Sjohnlev  * indent-tabs-mode: nil
6755084Sjohnlev  * End:
6765084Sjohnlev  */
677