/******************************************************************************1* arch-x86/xen.h2*3* Guest OS interface to x86 Xen.4*5* Permission is hereby granted, free of charge, to any person obtaining a copy6* of this software and associated documentation files (the "Software"), to7* deal in the Software without restriction, including without limitation the8* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or9* sell copies of the Software, and to permit persons to whom the Software is10* furnished to do so, subject to the following conditions:11*12* The above copyright notice and this permission notice shall be included in13* all copies or substantial portions of the Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE18* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING20* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER21* DEALINGS IN THE SOFTWARE.22*23* Copyright (c) 2004-2006, K A Fraser24*/2526#include "../xen.h"2728#ifndef __XEN_PUBLIC_ARCH_X86_XEN_H__29#define __XEN_PUBLIC_ARCH_X86_XEN_H__3031/* Structural guest handles introduced in 0x00030201. */32#if __XEN_INTERFACE_VERSION__ >= 0x0003020133#define ___DEFINE_XEN_GUEST_HANDLE(name, type) \34typedef struct { type *p; } __guest_handle_ ## name35#else36#define ___DEFINE_XEN_GUEST_HANDLE(name, type) \37typedef type * __guest_handle_ ## name38#endif3940/*41* XEN_GUEST_HANDLE represents a guest pointer, when passed as a field42* in a struct in memory.43* XEN_GUEST_HANDLE_PARAM represent a guest pointer, when passed as an44* hypercall argument.45* XEN_GUEST_HANDLE_PARAM and XEN_GUEST_HANDLE are the same on X86 but46* they might not be on other architectures.47*/48#define __DEFINE_XEN_GUEST_HANDLE(name, type) \49___DEFINE_XEN_GUEST_HANDLE(name, type); \50___DEFINE_XEN_GUEST_HANDLE(const_##name, const type)51#define DEFINE_XEN_GUEST_HANDLE(name) __DEFINE_XEN_GUEST_HANDLE(name, name)52#define __XEN_GUEST_HANDLE(name) __guest_handle_ ## name53#define XEN_GUEST_HANDLE(name) __XEN_GUEST_HANDLE(name)54#define XEN_GUEST_HANDLE_PARAM(name) XEN_GUEST_HANDLE(name)55#define set_xen_guest_handle_raw(hnd, val) do { (hnd).p = val; } while (0)56#define set_xen_guest_handle(hnd, val) set_xen_guest_handle_raw(hnd, val)5758#if defined(__i386__)59# ifdef __XEN__60__DeFiNe__ __DECL_REG_LO8(which) uint32_t e ## which ## x61__DeFiNe__ __DECL_REG_LO16(name) union { uint32_t e ## name; }62# endif63#include "xen-x86_32.h"64# ifdef __XEN__65__UnDeF__ __DECL_REG_LO866__UnDeF__ __DECL_REG_LO1667__DeFiNe__ __DECL_REG_LO8(which) e ## which ## x68__DeFiNe__ __DECL_REG_LO16(name) e ## name69# endif70#elif defined(__x86_64__)71#include "xen-x86_64.h"72#endif7374#ifndef __ASSEMBLY__75typedef unsigned long xen_pfn_t;76#define PRI_xen_pfn "lx"77#define PRIu_xen_pfn "lu"78#endif7980#define XEN_HAVE_PV_GUEST_ENTRY 18182#define XEN_HAVE_PV_UPCALL_MASK 18384/*85* `incontents 200 segdesc Segment Descriptor Tables86*/87/*88* ` enum neg_errnoval89* ` HYPERVISOR_set_gdt(const xen_pfn_t frames[], unsigned int entries);90* `91*/92/*93* A number of GDT entries are reserved by Xen. These are not situated at the94* start of the GDT because some stupid OSes export hard-coded selector values95* in their ABI. These hard-coded values are always near the start of the GDT,96* so Xen places itself out of the way, at the far end of the GDT.97*98* NB The LDT is set using the MMUEXT_SET_LDT op of HYPERVISOR_mmuext_op99*/100#define FIRST_RESERVED_GDT_PAGE 14101#define FIRST_RESERVED_GDT_BYTE (FIRST_RESERVED_GDT_PAGE * 4096)102#define FIRST_RESERVED_GDT_ENTRY (FIRST_RESERVED_GDT_BYTE / 8)103104105/*106* ` enum neg_errnoval107* ` HYPERVISOR_update_descriptor(u64 pa, u64 desc);108* `109* ` @pa The machine physical address of the descriptor to110* ` update. Must be either a descriptor page or writable.111* ` @desc The descriptor value to update, in the same format as a112* ` native descriptor table entry.113*/114115/* Maximum number of virtual CPUs in legacy multi-processor guests. */116#define XEN_LEGACY_MAX_VCPUS 32117118#ifndef __ASSEMBLY__119120typedef unsigned long xen_ulong_t;121#define PRI_xen_ulong "lx"122123/*124* ` enum neg_errnoval125* ` HYPERVISOR_stack_switch(unsigned long ss, unsigned long esp);126* `127* Sets the stack segment and pointer for the current vcpu.128*/129130/*131* ` enum neg_errnoval132* ` HYPERVISOR_set_trap_table(const struct trap_info traps[]);133* `134*/135/*136* Send an array of these to HYPERVISOR_set_trap_table().137* Terminate the array with a sentinel entry, with traps[].address==0.138* The privilege level specifies which modes may enter a trap via a software139* interrupt. On x86/64, since rings 1 and 2 are unavailable, we allocate140* privilege levels as follows:141* Level == 0: Noone may enter142* Level == 1: Kernel may enter143* Level == 2: Kernel may enter144* Level == 3: Everyone may enter145*146* Note: For compatibility with kernels not setting up exception handlers147* early enough, Xen will avoid trying to inject #GP (and hence crash148* the domain) when an RDMSR would require this, but no handler was149* set yet. The precise conditions are implementation specific, and150* new code may not rely on such behavior anyway.151*/152#define TI_GET_DPL(_ti) ((_ti)->flags & 3)153#define TI_GET_IF(_ti) ((_ti)->flags & 4)154#define TI_SET_DPL(_ti,_dpl) ((_ti)->flags |= (_dpl))155#define TI_SET_IF(_ti,_if) ((_ti)->flags |= ((!!(_if))<<2))156struct trap_info {157uint8_t vector; /* exception vector */158uint8_t flags; /* 0-3: privilege level; 4: clear event enable? */159uint16_t cs; /* code selector */160unsigned long address; /* code offset */161};162typedef struct trap_info trap_info_t;163DEFINE_XEN_GUEST_HANDLE(trap_info_t);164165typedef uint64_t tsc_timestamp_t; /* RDTSC timestamp */166167/*168* The following is all CPU context. Note that the fpu_ctxt block is filled169* in by FXSAVE if the CPU has feature FXSR; otherwise FSAVE is used.170*171* Also note that when calling DOMCTL_setvcpucontext for HVM guests, not all172* information in this structure is updated, the fields read include: fpu_ctxt173* (if VGCT_I387_VALID is set), flags, user_regs and debugreg[*].174*175* Note: VCPUOP_initialise for HVM guests is non-symetric with176* DOMCTL_setvcpucontext, and uses struct vcpu_hvm_context from hvm/hvm_vcpu.h177*/178struct vcpu_guest_context {179/* FPU registers come first so they can be aligned for FXSAVE/FXRSTOR. */180struct { char x[512]; } fpu_ctxt; /* User-level FPU registers */181#define VGCF_I387_VALID (1<<0)182#define VGCF_IN_KERNEL (1<<2)183#define _VGCF_i387_valid 0184#define VGCF_i387_valid (1<<_VGCF_i387_valid)185#define _VGCF_in_kernel 2186#define VGCF_in_kernel (1<<_VGCF_in_kernel)187#define _VGCF_failsafe_disables_events 3188#define VGCF_failsafe_disables_events (1<<_VGCF_failsafe_disables_events)189#define _VGCF_syscall_disables_events 4190#define VGCF_syscall_disables_events (1<<_VGCF_syscall_disables_events)191#define _VGCF_online 5192#define VGCF_online (1<<_VGCF_online)193unsigned long flags; /* VGCF_* flags */194struct cpu_user_regs user_regs; /* User-level CPU registers */195struct trap_info trap_ctxt[256]; /* Virtual IDT */196unsigned long ldt_base, ldt_ents; /* LDT (linear address, # ents) */197unsigned long gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */198unsigned long kernel_ss, kernel_sp; /* Virtual TSS (only SS1/SP1) */199/* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */200unsigned long ctrlreg[8]; /* CR0-CR7 (control registers) */201unsigned long debugreg[8]; /* DB0-DB7 (debug registers) */202#ifdef __i386__203unsigned long event_callback_cs; /* CS:EIP of event callback */204unsigned long event_callback_eip;205unsigned long failsafe_callback_cs; /* CS:EIP of failsafe callback */206unsigned long failsafe_callback_eip;207#else208unsigned long event_callback_eip;209unsigned long failsafe_callback_eip;210#ifdef __XEN__211union {212unsigned long syscall_callback_eip;213struct {214unsigned int event_callback_cs; /* compat CS of event cb */215unsigned int failsafe_callback_cs; /* compat CS of failsafe cb */216};217};218#else219unsigned long syscall_callback_eip;220#endif221#endif222unsigned long vm_assist; /* VMASST_TYPE_* bitmap */223#ifdef __x86_64__224/* Segment base addresses. */225uint64_t fs_base;226uint64_t gs_base_kernel;227uint64_t gs_base_user;228#endif229};230typedef struct vcpu_guest_context vcpu_guest_context_t;231DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);232233struct arch_shared_info {234/*235* Number of valid entries in the p2m table(s) anchored at236* pfn_to_mfn_frame_list_list and/or p2m_vaddr.237*/238unsigned long max_pfn;239/*240* Frame containing list of mfns containing list of mfns containing p2m.241* A value of 0 indicates it has not yet been set up, ~0 indicates it has242* been set to invalid e.g. due to the p2m being too large for the 3-level243* p2m tree. In this case the linear mapper p2m list anchored at p2m_vaddr244* is to be used.245*/246xen_pfn_t pfn_to_mfn_frame_list_list;247unsigned long nmi_reason;248/*249* Following three fields are valid if p2m_cr3 contains a value different250* from 0.251* p2m_cr3 is the root of the address space where p2m_vaddr is valid.252* p2m_cr3 is in the same format as a cr3 value in the vcpu register state253* and holds the folded machine frame number (via xen_pfn_to_cr3) of a254* L3 or L4 page table.255* p2m_vaddr holds the virtual address of the linear p2m list. All entries256* in the range [0...max_pfn[ are accessible via this pointer.257* p2m_generation will be incremented by the guest before and after each258* change of the mappings of the p2m list. p2m_generation starts at 0 and259* a value with the least significant bit set indicates that a mapping260* update is in progress. This allows guest external software (e.g. in Dom0)261* to verify that read mappings are consistent and whether they have changed262* since the last check.263* Modifying a p2m element in the linear p2m list is allowed via an atomic264* write only.265*/266unsigned long p2m_cr3; /* cr3 value of the p2m address space */267unsigned long p2m_vaddr; /* virtual address of the p2m list */268unsigned long p2m_generation; /* generation count of p2m mapping */269#ifdef __i386__270/* There's no room for this field in the generic structure. */271uint32_t wc_sec_hi;272#endif273};274typedef struct arch_shared_info arch_shared_info_t;275276#if defined(__XEN__) || defined(__XEN_TOOLS__)277/*278* struct xen_arch_domainconfig's ABI is covered by279* XEN_DOMCTL_INTERFACE_VERSION.280*/281struct xen_arch_domainconfig {282#define _XEN_X86_EMU_LAPIC 0283#define XEN_X86_EMU_LAPIC (1U<<_XEN_X86_EMU_LAPIC)284#define _XEN_X86_EMU_HPET 1285#define XEN_X86_EMU_HPET (1U<<_XEN_X86_EMU_HPET)286#define _XEN_X86_EMU_PM 2287#define XEN_X86_EMU_PM (1U<<_XEN_X86_EMU_PM)288#define _XEN_X86_EMU_RTC 3289#define XEN_X86_EMU_RTC (1U<<_XEN_X86_EMU_RTC)290#define _XEN_X86_EMU_IOAPIC 4291#define XEN_X86_EMU_IOAPIC (1U<<_XEN_X86_EMU_IOAPIC)292#define _XEN_X86_EMU_PIC 5293#define XEN_X86_EMU_PIC (1U<<_XEN_X86_EMU_PIC)294#define _XEN_X86_EMU_VGA 6295#define XEN_X86_EMU_VGA (1U<<_XEN_X86_EMU_VGA)296#define _XEN_X86_EMU_IOMMU 7297#define XEN_X86_EMU_IOMMU (1U<<_XEN_X86_EMU_IOMMU)298#define _XEN_X86_EMU_PIT 8299#define XEN_X86_EMU_PIT (1U<<_XEN_X86_EMU_PIT)300#define _XEN_X86_EMU_USE_PIRQ 9301#define XEN_X86_EMU_USE_PIRQ (1U<<_XEN_X86_EMU_USE_PIRQ)302#define _XEN_X86_EMU_VPCI 10303#define XEN_X86_EMU_VPCI (1U<<_XEN_X86_EMU_VPCI)304305#define XEN_X86_EMU_ALL (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET | \306XEN_X86_EMU_PM | XEN_X86_EMU_RTC | \307XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC | \308XEN_X86_EMU_VGA | XEN_X86_EMU_IOMMU | \309XEN_X86_EMU_PIT | XEN_X86_EMU_USE_PIRQ |\310XEN_X86_EMU_VPCI)311uint32_t emulation_flags;312313/*314* Select whether to use a relaxed behavior for accesses to MSRs not explicitly315* handled by Xen instead of injecting a #GP to the guest. Note this option316* doesn't allow the guest to read or write to the underlying MSR.317*/318#define XEN_X86_MSR_RELAXED (1u << 0)319uint32_t misc_flags;320};321322/* Location of online VCPU bitmap. */323#define XEN_ACPI_CPU_MAP 0xaf00324#define XEN_ACPI_CPU_MAP_LEN ((HVM_MAX_VCPUS + 7) / 8)325326/* GPE0 bit set during CPU hotplug */327#define XEN_ACPI_GPE0_CPUHP_BIT 2328#endif329330/*331* Representations of architectural CPUID and MSR information. Used as the332* serialised version of Xen's internal representation.333*/334typedef struct xen_cpuid_leaf {335#define XEN_CPUID_NO_SUBLEAF 0xffffffffu336uint32_t leaf, subleaf;337uint32_t a, b, c, d;338} xen_cpuid_leaf_t;339DEFINE_XEN_GUEST_HANDLE(xen_cpuid_leaf_t);340341typedef struct xen_msr_entry {342uint32_t idx;343uint32_t flags; /* Reserved MBZ. */344uint64_t val;345} xen_msr_entry_t;346DEFINE_XEN_GUEST_HANDLE(xen_msr_entry_t);347348#endif /* !__ASSEMBLY__ */349350/*351* ` enum neg_errnoval352* ` HYPERVISOR_fpu_taskswitch(int set);353* `354* Sets (if set!=0) or clears (if set==0) CR0.TS.355*/356357/*358* ` enum neg_errnoval359* ` HYPERVISOR_set_debugreg(int regno, unsigned long value);360*361* ` unsigned long362* ` HYPERVISOR_get_debugreg(int regno);363* For 0<=reg<=7, returns the debug register value.364* For other values of reg, returns ((unsigned long)-EINVAL).365* (Unfortunately, this interface is defective.)366*/367368/*369* Prefix forces emulation of some non-trapping instructions.370* Currently only CPUID.371*/372#ifdef __ASSEMBLY__373#define XEN_EMULATE_PREFIX .byte 0x0f,0x0b,0x78,0x65,0x6e ;374#define XEN_CPUID XEN_EMULATE_PREFIX cpuid375#else376#define XEN_EMULATE_PREFIX ".byte 0x0f,0x0b,0x78,0x65,0x6e ; "377#define XEN_CPUID XEN_EMULATE_PREFIX "cpuid"378#endif379380/*381* Debug console IO port, also called "port E9 hack". Each character written382* to this IO port will be printed on the hypervisor console, subject to log383* level restrictions.384*/385#define XEN_HVM_DEBUGCONS_IOPORT 0xe9386387#endif /* __XEN_PUBLIC_ARCH_X86_XEN_H__ */388389/*390* Local variables:391* mode: C392* c-file-style: "BSD"393* c-basic-offset: 4394* tab-width: 4395* indent-tabs-mode: nil396* End:397*/398399400