1 1.1 cherry /****************************************************************************** 2 1.1 cherry * arch-x86/xen.h 3 1.1 cherry * 4 1.1 cherry * Guest OS interface to x86 Xen. 5 1.1 cherry * 6 1.1 cherry * Permission is hereby granted, free of charge, to any person obtaining a copy 7 1.1 cherry * of this software and associated documentation files (the "Software"), to 8 1.1 cherry * deal in the Software without restriction, including without limitation the 9 1.1 cherry * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 1.1 cherry * sell copies of the Software, and to permit persons to whom the Software is 11 1.1 cherry * furnished to do so, subject to the following conditions: 12 1.1 cherry * 13 1.1 cherry * The above copyright notice and this permission notice shall be included in 14 1.1 cherry * all copies or substantial portions of the Software. 15 1.1 cherry * 16 1.1 cherry * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 1.1 cherry * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 1.1 cherry * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 1.1 cherry * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 1.1 cherry * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 1.1 cherry * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 1.1 cherry * DEALINGS IN THE SOFTWARE. 23 1.1 cherry * 24 1.1 cherry * Copyright (c) 2004-2006, K A Fraser 25 1.1 cherry */ 26 1.1 cherry 27 1.1 cherry #include "../xen.h" 28 1.1 cherry 29 1.1 cherry #ifndef __XEN_PUBLIC_ARCH_X86_XEN_H__ 30 1.1 cherry #define __XEN_PUBLIC_ARCH_X86_XEN_H__ 31 1.1 cherry 32 1.1 cherry /* Structural guest handles introduced in 0x00030201. */ 33 1.1 cherry #if __XEN_INTERFACE_VERSION__ >= 0x00030201 34 1.1 cherry #define ___DEFINE_XEN_GUEST_HANDLE(name, type) \ 35 1.1 cherry typedef struct { type *p; } __guest_handle_ ## name 36 1.1 cherry #else 37 1.1 cherry #define ___DEFINE_XEN_GUEST_HANDLE(name, type) \ 38 1.1 cherry typedef type * __guest_handle_ ## name 39 1.1 cherry #endif 40 1.1 cherry 41 1.1 cherry /* 42 1.1 cherry * XEN_GUEST_HANDLE represents a guest pointer, when passed as a field 43 1.1 cherry * in a struct in memory. 44 1.1 cherry * XEN_GUEST_HANDLE_PARAM represent a guest pointer, when passed as an 45 1.1 cherry * hypercall argument. 46 1.1 cherry * XEN_GUEST_HANDLE_PARAM and XEN_GUEST_HANDLE are the same on X86 but 47 1.1 cherry * they might not be on other architectures. 48 1.1 cherry */ 49 1.1 cherry #define __DEFINE_XEN_GUEST_HANDLE(name, type) \ 50 1.1 cherry ___DEFINE_XEN_GUEST_HANDLE(name, type); \ 51 1.1 cherry ___DEFINE_XEN_GUEST_HANDLE(const_##name, const type) 52 1.1 cherry #define DEFINE_XEN_GUEST_HANDLE(name) __DEFINE_XEN_GUEST_HANDLE(name, name) 53 1.1 cherry #define __XEN_GUEST_HANDLE(name) __guest_handle_ ## name 54 1.1 cherry #define XEN_GUEST_HANDLE(name) __XEN_GUEST_HANDLE(name) 55 1.1 cherry #define XEN_GUEST_HANDLE_PARAM(name) XEN_GUEST_HANDLE(name) 56 1.1 cherry #define set_xen_guest_handle_raw(hnd, val) do { (hnd).p = val; } while (0) 57 1.1 cherry #define set_xen_guest_handle(hnd, val) set_xen_guest_handle_raw(hnd, val) 58 1.1 cherry 59 1.1 cherry #if defined(__i386__) 60 1.1 cherry # ifdef __XEN__ 61 1.1 cherry __DeFiNe__ __DECL_REG_LO8(which) uint32_t e ## which ## x 62 1.1 cherry __DeFiNe__ __DECL_REG_LO16(name) union { uint32_t e ## name; } 63 1.1 cherry # endif 64 1.1 cherry #include "xen-x86_32.h" 65 1.1 cherry # ifdef __XEN__ 66 1.1 cherry __UnDeF__ __DECL_REG_LO8 67 1.1 cherry __UnDeF__ __DECL_REG_LO16 68 1.1 cherry __DeFiNe__ __DECL_REG_LO8(which) e ## which ## x 69 1.1 cherry __DeFiNe__ __DECL_REG_LO16(name) e ## name 70 1.1 cherry # endif 71 1.1 cherry #elif defined(__x86_64__) 72 1.1 cherry #include "xen-x86_64.h" 73 1.1 cherry #endif 74 1.1 cherry 75 1.1 cherry #ifndef __ASSEMBLY__ 76 1.1 cherry typedef unsigned long xen_pfn_t; 77 1.1 cherry #define PRI_xen_pfn "lx" 78 1.1 cherry #define PRIu_xen_pfn "lu" 79 1.1 cherry #endif 80 1.1 cherry 81 1.1 cherry #define XEN_HAVE_PV_GUEST_ENTRY 1 82 1.1 cherry 83 1.1 cherry #define XEN_HAVE_PV_UPCALL_MASK 1 84 1.1 cherry 85 1.1 cherry /* 86 1.1 cherry * `incontents 200 segdesc Segment Descriptor Tables 87 1.1 cherry */ 88 1.1 cherry /* 89 1.1 cherry * ` enum neg_errnoval 90 1.1 cherry * ` HYPERVISOR_set_gdt(const xen_pfn_t frames[], unsigned int entries); 91 1.1 cherry * ` 92 1.1 cherry */ 93 1.1 cherry /* 94 1.1 cherry * A number of GDT entries are reserved by Xen. These are not situated at the 95 1.1 cherry * start of the GDT because some stupid OSes export hard-coded selector values 96 1.1 cherry * in their ABI. These hard-coded values are always near the start of the GDT, 97 1.1 cherry * so Xen places itself out of the way, at the far end of the GDT. 98 1.1 cherry * 99 1.1 cherry * NB The LDT is set using the MMUEXT_SET_LDT op of HYPERVISOR_mmuext_op 100 1.1 cherry */ 101 1.1 cherry #define FIRST_RESERVED_GDT_PAGE 14 102 1.1 cherry #define FIRST_RESERVED_GDT_BYTE (FIRST_RESERVED_GDT_PAGE * 4096) 103 1.1 cherry #define FIRST_RESERVED_GDT_ENTRY (FIRST_RESERVED_GDT_BYTE / 8) 104 1.1 cherry 105 1.1 cherry 106 1.1 cherry /* 107 1.1 cherry * ` enum neg_errnoval 108 1.1 cherry * ` HYPERVISOR_update_descriptor(u64 pa, u64 desc); 109 1.1 cherry * ` 110 1.1 cherry * ` @pa The machine physical address of the descriptor to 111 1.1 cherry * ` update. Must be either a descriptor page or writable. 112 1.1 cherry * ` @desc The descriptor value to update, in the same format as a 113 1.1 cherry * ` native descriptor table entry. 114 1.1 cherry */ 115 1.1 cherry 116 1.1 cherry /* Maximum number of virtual CPUs in legacy multi-processor guests. */ 117 1.1 cherry #define XEN_LEGACY_MAX_VCPUS 32 118 1.1 cherry 119 1.1 cherry #ifndef __ASSEMBLY__ 120 1.1 cherry 121 1.1 cherry typedef unsigned long xen_ulong_t; 122 1.1 cherry #define PRI_xen_ulong "lx" 123 1.1 cherry 124 1.1 cherry /* 125 1.1 cherry * ` enum neg_errnoval 126 1.1 cherry * ` HYPERVISOR_stack_switch(unsigned long ss, unsigned long esp); 127 1.1 cherry * ` 128 1.1 cherry * Sets the stack segment and pointer for the current vcpu. 129 1.1 cherry */ 130 1.1 cherry 131 1.1 cherry /* 132 1.1 cherry * ` enum neg_errnoval 133 1.1 cherry * ` HYPERVISOR_set_trap_table(const struct trap_info traps[]); 134 1.1 cherry * ` 135 1.1 cherry */ 136 1.1 cherry /* 137 1.1 cherry * Send an array of these to HYPERVISOR_set_trap_table(). 138 1.1 cherry * Terminate the array with a sentinel entry, with traps[].address==0. 139 1.1 cherry * The privilege level specifies which modes may enter a trap via a software 140 1.1 cherry * interrupt. On x86/64, since rings 1 and 2 are unavailable, we allocate 141 1.1 cherry * privilege levels as follows: 142 1.1 cherry * Level == 0: Noone may enter 143 1.1 cherry * Level == 1: Kernel may enter 144 1.1 cherry * Level == 2: Kernel may enter 145 1.1 cherry * Level == 3: Everyone may enter 146 1.1 cherry */ 147 1.1 cherry #define TI_GET_DPL(_ti) ((_ti)->flags & 3) 148 1.1 cherry #define TI_GET_IF(_ti) ((_ti)->flags & 4) 149 1.1 cherry #define TI_SET_DPL(_ti,_dpl) ((_ti)->flags |= (_dpl)) 150 1.1 cherry #define TI_SET_IF(_ti,_if) ((_ti)->flags |= ((!!(_if))<<2)) 151 1.1 cherry struct trap_info { 152 1.1 cherry uint8_t vector; /* exception vector */ 153 1.1 cherry uint8_t flags; /* 0-3: privilege level; 4: clear event enable? */ 154 1.1 cherry uint16_t cs; /* code selector */ 155 1.1 cherry unsigned long address; /* code offset */ 156 1.1 cherry }; 157 1.1 cherry typedef struct trap_info trap_info_t; 158 1.1 cherry DEFINE_XEN_GUEST_HANDLE(trap_info_t); 159 1.1 cherry 160 1.1 cherry typedef uint64_t tsc_timestamp_t; /* RDTSC timestamp */ 161 1.1 cherry 162 1.1 cherry /* 163 1.1 cherry * The following is all CPU context. Note that the fpu_ctxt block is filled 164 1.1 cherry * in by FXSAVE if the CPU has feature FXSR; otherwise FSAVE is used. 165 1.1 cherry * 166 1.1 cherry * Also note that when calling DOMCTL_setvcpucontext for HVM guests, not all 167 1.1 cherry * information in this structure is updated, the fields read include: fpu_ctxt 168 1.1 cherry * (if VGCT_I387_VALID is set), flags, user_regs and debugreg[*]. 169 1.1 cherry * 170 1.1 cherry * Note: VCPUOP_initialise for HVM guests is non-symetric with 171 1.1 cherry * DOMCTL_setvcpucontext, and uses struct vcpu_hvm_context from hvm/hvm_vcpu.h 172 1.1 cherry */ 173 1.1 cherry struct vcpu_guest_context { 174 1.1 cherry /* FPU registers come first so they can be aligned for FXSAVE/FXRSTOR. */ 175 1.1 cherry struct { char x[512]; } fpu_ctxt; /* User-level FPU registers */ 176 1.1 cherry #define VGCF_I387_VALID (1<<0) 177 1.1 cherry #define VGCF_IN_KERNEL (1<<2) 178 1.1 cherry #define _VGCF_i387_valid 0 179 1.1 cherry #define VGCF_i387_valid (1<<_VGCF_i387_valid) 180 1.1 cherry #define _VGCF_in_kernel 2 181 1.1 cherry #define VGCF_in_kernel (1<<_VGCF_in_kernel) 182 1.1 cherry #define _VGCF_failsafe_disables_events 3 183 1.1 cherry #define VGCF_failsafe_disables_events (1<<_VGCF_failsafe_disables_events) 184 1.1 cherry #define _VGCF_syscall_disables_events 4 185 1.1 cherry #define VGCF_syscall_disables_events (1<<_VGCF_syscall_disables_events) 186 1.1 cherry #define _VGCF_online 5 187 1.1 cherry #define VGCF_online (1<<_VGCF_online) 188 1.1 cherry unsigned long flags; /* VGCF_* flags */ 189 1.1 cherry struct cpu_user_regs user_regs; /* User-level CPU registers */ 190 1.1 cherry struct trap_info trap_ctxt[256]; /* Virtual IDT */ 191 1.1 cherry unsigned long ldt_base, ldt_ents; /* LDT (linear address, # ents) */ 192 1.1 cherry unsigned long gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */ 193 1.1 cherry unsigned long kernel_ss, kernel_sp; /* Virtual TSS (only SS1/SP1) */ 194 1.1 cherry /* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */ 195 1.1 cherry unsigned long ctrlreg[8]; /* CR0-CR7 (control registers) */ 196 1.1 cherry unsigned long debugreg[8]; /* DB0-DB7 (debug registers) */ 197 1.1 cherry #ifdef __i386__ 198 1.1 cherry unsigned long event_callback_cs; /* CS:EIP of event callback */ 199 1.1 cherry unsigned long event_callback_eip; 200 1.1 cherry unsigned long failsafe_callback_cs; /* CS:EIP of failsafe callback */ 201 1.1 cherry unsigned long failsafe_callback_eip; 202 1.1 cherry #else 203 1.1 cherry unsigned long event_callback_eip; 204 1.1 cherry unsigned long failsafe_callback_eip; 205 1.1 cherry #ifdef __XEN__ 206 1.1 cherry union { 207 1.1 cherry unsigned long syscall_callback_eip; 208 1.1 cherry struct { 209 1.1 cherry unsigned int event_callback_cs; /* compat CS of event cb */ 210 1.1 cherry unsigned int failsafe_callback_cs; /* compat CS of failsafe cb */ 211 1.1 cherry }; 212 1.1 cherry }; 213 1.1 cherry #else 214 1.1 cherry unsigned long syscall_callback_eip; 215 1.1 cherry #endif 216 1.1 cherry #endif 217 1.1 cherry unsigned long vm_assist; /* VMASST_TYPE_* bitmap */ 218 1.1 cherry #ifdef __x86_64__ 219 1.1 cherry /* Segment base addresses. */ 220 1.1 cherry uint64_t fs_base; 221 1.1 cherry uint64_t gs_base_kernel; 222 1.1 cherry uint64_t gs_base_user; 223 1.1 cherry #endif 224 1.1 cherry }; 225 1.1 cherry typedef struct vcpu_guest_context vcpu_guest_context_t; 226 1.1 cherry DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t); 227 1.1 cherry 228 1.1 cherry struct arch_shared_info { 229 1.1 cherry /* 230 1.1 cherry * Number of valid entries in the p2m table(s) anchored at 231 1.1 cherry * pfn_to_mfn_frame_list_list and/or p2m_vaddr. 232 1.1 cherry */ 233 1.1 cherry unsigned long max_pfn; 234 1.1 cherry /* 235 1.1 cherry * Frame containing list of mfns containing list of mfns containing p2m. 236 1.1 cherry * A value of 0 indicates it has not yet been set up, ~0 indicates it has 237 1.1 cherry * been set to invalid e.g. due to the p2m being too large for the 3-level 238 1.1 cherry * p2m tree. In this case the linear mapper p2m list anchored at p2m_vaddr 239 1.1 cherry * is to be used. 240 1.1 cherry */ 241 1.1 cherry xen_pfn_t pfn_to_mfn_frame_list_list; 242 1.1 cherry unsigned long nmi_reason; 243 1.1 cherry /* 244 1.1 cherry * Following three fields are valid if p2m_cr3 contains a value different 245 1.1 cherry * from 0. 246 1.1 cherry * p2m_cr3 is the root of the address space where p2m_vaddr is valid. 247 1.1 cherry * p2m_cr3 is in the same format as a cr3 value in the vcpu register state 248 1.1 cherry * and holds the folded machine frame number (via xen_pfn_to_cr3) of a 249 1.1 cherry * L3 or L4 page table. 250 1.1 cherry * p2m_vaddr holds the virtual address of the linear p2m list. All entries 251 1.1 cherry * in the range [0...max_pfn[ are accessible via this pointer. 252 1.1 cherry * p2m_generation will be incremented by the guest before and after each 253 1.1 cherry * change of the mappings of the p2m list. p2m_generation starts at 0 and 254 1.1 cherry * a value with the least significant bit set indicates that a mapping 255 1.1 cherry * update is in progress. This allows guest external software (e.g. in Dom0) 256 1.1 cherry * to verify that read mappings are consistent and whether they have changed 257 1.1 cherry * since the last check. 258 1.1 cherry * Modifying a p2m element in the linear p2m list is allowed via an atomic 259 1.1 cherry * write only. 260 1.1 cherry */ 261 1.1 cherry unsigned long p2m_cr3; /* cr3 value of the p2m address space */ 262 1.1 cherry unsigned long p2m_vaddr; /* virtual address of the p2m list */ 263 1.1 cherry unsigned long p2m_generation; /* generation count of p2m mapping */ 264 1.1 cherry #ifdef __i386__ 265 1.1 cherry /* There's no room for this field in the generic structure. */ 266 1.1 cherry uint32_t wc_sec_hi; 267 1.1 cherry #endif 268 1.1 cherry }; 269 1.1 cherry typedef struct arch_shared_info arch_shared_info_t; 270 1.1 cherry 271 1.1 cherry #if defined(__XEN__) || defined(__XEN_TOOLS__) 272 1.1 cherry /* 273 1.1 cherry * struct xen_arch_domainconfig's ABI is covered by 274 1.1 cherry * XEN_DOMCTL_INTERFACE_VERSION. 275 1.1 cherry */ 276 1.1 cherry struct xen_arch_domainconfig { 277 1.1 cherry #define _XEN_X86_EMU_LAPIC 0 278 1.1 cherry #define XEN_X86_EMU_LAPIC (1U<<_XEN_X86_EMU_LAPIC) 279 1.1 cherry #define _XEN_X86_EMU_HPET 1 280 1.1 cherry #define XEN_X86_EMU_HPET (1U<<_XEN_X86_EMU_HPET) 281 1.1 cherry #define _XEN_X86_EMU_PM 2 282 1.1 cherry #define XEN_X86_EMU_PM (1U<<_XEN_X86_EMU_PM) 283 1.1 cherry #define _XEN_X86_EMU_RTC 3 284 1.1 cherry #define XEN_X86_EMU_RTC (1U<<_XEN_X86_EMU_RTC) 285 1.1 cherry #define _XEN_X86_EMU_IOAPIC 4 286 1.1 cherry #define XEN_X86_EMU_IOAPIC (1U<<_XEN_X86_EMU_IOAPIC) 287 1.1 cherry #define _XEN_X86_EMU_PIC 5 288 1.1 cherry #define XEN_X86_EMU_PIC (1U<<_XEN_X86_EMU_PIC) 289 1.1 cherry #define _XEN_X86_EMU_VGA 6 290 1.1 cherry #define XEN_X86_EMU_VGA (1U<<_XEN_X86_EMU_VGA) 291 1.1 cherry #define _XEN_X86_EMU_IOMMU 7 292 1.1 cherry #define XEN_X86_EMU_IOMMU (1U<<_XEN_X86_EMU_IOMMU) 293 1.1 cherry #define _XEN_X86_EMU_PIT 8 294 1.1 cherry #define XEN_X86_EMU_PIT (1U<<_XEN_X86_EMU_PIT) 295 1.1 cherry #define _XEN_X86_EMU_USE_PIRQ 9 296 1.1 cherry #define XEN_X86_EMU_USE_PIRQ (1U<<_XEN_X86_EMU_USE_PIRQ) 297 1.1 cherry #define _XEN_X86_EMU_VPCI 10 298 1.1 cherry #define XEN_X86_EMU_VPCI (1U<<_XEN_X86_EMU_VPCI) 299 1.1 cherry 300 1.1 cherry #define XEN_X86_EMU_ALL (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET | \ 301 1.1 cherry XEN_X86_EMU_PM | XEN_X86_EMU_RTC | \ 302 1.1 cherry XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC | \ 303 1.1 cherry XEN_X86_EMU_VGA | XEN_X86_EMU_IOMMU | \ 304 1.1 cherry XEN_X86_EMU_PIT | XEN_X86_EMU_USE_PIRQ |\ 305 1.1 cherry XEN_X86_EMU_VPCI) 306 1.1 cherry uint32_t emulation_flags; 307 1.1 cherry }; 308 1.1 cherry 309 1.1 cherry /* Location of online VCPU bitmap. */ 310 1.1 cherry #define XEN_ACPI_CPU_MAP 0xaf00 311 1.1 cherry #define XEN_ACPI_CPU_MAP_LEN ((HVM_MAX_VCPUS + 7) / 8) 312 1.1 cherry 313 1.1 cherry /* GPE0 bit set during CPU hotplug */ 314 1.1 cherry #define XEN_ACPI_GPE0_CPUHP_BIT 2 315 1.1 cherry #endif 316 1.1 cherry 317 1.1 cherry #endif /* !__ASSEMBLY__ */ 318 1.1 cherry 319 1.1 cherry /* 320 1.1 cherry * ` enum neg_errnoval 321 1.1 cherry * ` HYPERVISOR_fpu_taskswitch(int set); 322 1.1 cherry * ` 323 1.1 cherry * Sets (if set!=0) or clears (if set==0) CR0.TS. 324 1.1 cherry */ 325 1.1 cherry 326 1.1 cherry /* 327 1.1 cherry * ` enum neg_errnoval 328 1.1 cherry * ` HYPERVISOR_set_debugreg(int regno, unsigned long value); 329 1.1 cherry * 330 1.1 cherry * ` unsigned long 331 1.1 cherry * ` HYPERVISOR_get_debugreg(int regno); 332 1.1 cherry * For 0<=reg<=7, returns the debug register value. 333 1.1 cherry * For other values of reg, returns ((unsigned long)-EINVAL). 334 1.1 cherry * (Unfortunately, this interface is defective.) 335 1.1 cherry */ 336 1.1 cherry 337 1.1 cherry /* 338 1.1 cherry * Prefix forces emulation of some non-trapping instructions. 339 1.1 cherry * Currently only CPUID. 340 1.1 cherry */ 341 1.1 cherry #ifdef __ASSEMBLY__ 342 1.1 cherry #define XEN_EMULATE_PREFIX .byte 0x0f,0x0b,0x78,0x65,0x6e ; 343 1.1 cherry #define XEN_CPUID XEN_EMULATE_PREFIX cpuid 344 1.1 cherry #else 345 1.1 cherry #define XEN_EMULATE_PREFIX ".byte 0x0f,0x0b,0x78,0x65,0x6e ; " 346 1.1 cherry #define XEN_CPUID XEN_EMULATE_PREFIX "cpuid" 347 1.1 cherry #endif 348 1.1 cherry 349 1.1 cherry #endif /* __XEN_PUBLIC_ARCH_X86_XEN_H__ */ 350 1.1 cherry 351 1.1 cherry /* 352 1.1 cherry * Local variables: 353 1.1 cherry * mode: C 354 1.1 cherry * c-file-style: "BSD" 355 1.1 cherry * c-basic-offset: 4 356 1.1 cherry * tab-width: 4 357 1.1 cherry * indent-tabs-mode: nil 358 1.1 cherry * End: 359 1.1 cherry */ 360