1 1.1 cherry /****************************************************************************** 2 1.1 cherry * xen.h 3 1.1 cherry * 4 1.1 cherry * Guest OS interface to 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, K A Fraser 25 1.1 cherry */ 26 1.1 cherry 27 1.1 cherry #ifndef __XEN_PUBLIC_XEN_H__ 28 1.1 cherry #define __XEN_PUBLIC_XEN_H__ 29 1.1 cherry 30 1.1 cherry #include "xen-compat.h" 31 1.1 cherry 32 1.1 cherry #if defined(__i386__) || defined(__x86_64__) 33 1.1 cherry #include "arch-x86/xen.h" 34 1.1 cherry #elif defined(__arm__) || defined (__aarch64__) 35 1.1 cherry #include "arch-arm.h" 36 1.1 cherry #else 37 1.1 cherry #error "Unsupported architecture" 38 1.1 cherry #endif 39 1.1 cherry 40 1.1 cherry #ifndef __ASSEMBLY__ 41 1.1 cherry /* Guest handles for primitive C types. */ 42 1.1 cherry DEFINE_XEN_GUEST_HANDLE(char); 43 1.1 cherry __DEFINE_XEN_GUEST_HANDLE(uchar, unsigned char); 44 1.1 cherry DEFINE_XEN_GUEST_HANDLE(int); 45 1.1 cherry __DEFINE_XEN_GUEST_HANDLE(uint, unsigned int); 46 1.1 cherry #if __XEN_INTERFACE_VERSION__ < 0x00040300 47 1.1 cherry DEFINE_XEN_GUEST_HANDLE(long); 48 1.1 cherry __DEFINE_XEN_GUEST_HANDLE(ulong, unsigned long); 49 1.1 cherry #endif 50 1.1 cherry DEFINE_XEN_GUEST_HANDLE(void); 51 1.1 cherry 52 1.1 cherry DEFINE_XEN_GUEST_HANDLE(uint64_t); 53 1.1 cherry DEFINE_XEN_GUEST_HANDLE(xen_pfn_t); 54 1.1 cherry DEFINE_XEN_GUEST_HANDLE(xen_ulong_t); 55 1.1 cherry 56 1.1 cherry /* Turn a plain number into a C unsigned (long (long)) constant. */ 57 1.1 cherry #define __xen_mk_uint(x) x ## U 58 1.1 cherry #define __xen_mk_ulong(x) x ## UL 59 1.1 cherry #ifndef __xen_mk_ullong 60 1.1 cherry # define __xen_mk_ullong(x) x ## ULL 61 1.1 cherry #endif 62 1.1 cherry #define xen_mk_uint(x) __xen_mk_uint(x) 63 1.1 cherry #define xen_mk_ulong(x) __xen_mk_ulong(x) 64 1.1 cherry #define xen_mk_ullong(x) __xen_mk_ullong(x) 65 1.1 cherry 66 1.1 cherry #else 67 1.1 cherry 68 1.1 cherry /* In assembly code we cannot use C numeric constant suffixes. */ 69 1.1 cherry #define xen_mk_uint(x) x 70 1.1 cherry #define xen_mk_ulong(x) x 71 1.1 cherry #define xen_mk_ullong(x) x 72 1.1 cherry 73 1.1 cherry #endif 74 1.1 cherry 75 1.1 cherry /* 76 1.1 cherry * HYPERCALLS 77 1.1 cherry */ 78 1.1 cherry 79 1.1 cherry /* `incontents 100 hcalls List of hypercalls 80 1.1 cherry * ` enum hypercall_num { // __HYPERVISOR_* => HYPERVISOR_*() 81 1.1 cherry */ 82 1.1 cherry 83 1.1 cherry #define __HYPERVISOR_set_trap_table 0 84 1.1 cherry #define __HYPERVISOR_mmu_update 1 85 1.1 cherry #define __HYPERVISOR_set_gdt 2 86 1.1 cherry #define __HYPERVISOR_stack_switch 3 87 1.1 cherry #define __HYPERVISOR_set_callbacks 4 88 1.1 cherry #define __HYPERVISOR_fpu_taskswitch 5 89 1.1 cherry #define __HYPERVISOR_sched_op_compat 6 /* compat since 0x00030101 */ 90 1.1 cherry #define __HYPERVISOR_platform_op 7 91 1.1 cherry #define __HYPERVISOR_set_debugreg 8 92 1.1 cherry #define __HYPERVISOR_get_debugreg 9 93 1.1 cherry #define __HYPERVISOR_update_descriptor 10 94 1.1 cherry #define __HYPERVISOR_memory_op 12 95 1.1 cherry #define __HYPERVISOR_multicall 13 96 1.1 cherry #define __HYPERVISOR_update_va_mapping 14 97 1.1 cherry #define __HYPERVISOR_set_timer_op 15 98 1.1 cherry #define __HYPERVISOR_event_channel_op_compat 16 /* compat since 0x00030202 */ 99 1.1 cherry #define __HYPERVISOR_xen_version 17 100 1.1 cherry #define __HYPERVISOR_console_io 18 101 1.1 cherry #define __HYPERVISOR_physdev_op_compat 19 /* compat since 0x00030202 */ 102 1.1 cherry #define __HYPERVISOR_grant_table_op 20 103 1.1 cherry #define __HYPERVISOR_vm_assist 21 104 1.1 cherry #define __HYPERVISOR_update_va_mapping_otherdomain 22 105 1.1 cherry #define __HYPERVISOR_iret 23 /* x86 only */ 106 1.1 cherry #define __HYPERVISOR_vcpu_op 24 107 1.1 cherry #define __HYPERVISOR_set_segment_base 25 /* x86/64 only */ 108 1.1 cherry #define __HYPERVISOR_mmuext_op 26 109 1.1 cherry #define __HYPERVISOR_xsm_op 27 110 1.1 cherry #define __HYPERVISOR_nmi_op 28 111 1.1 cherry #define __HYPERVISOR_sched_op 29 112 1.1 cherry #define __HYPERVISOR_callback_op 30 113 1.1 cherry #define __HYPERVISOR_xenoprof_op 31 114 1.1 cherry #define __HYPERVISOR_event_channel_op 32 115 1.1 cherry #define __HYPERVISOR_physdev_op 33 116 1.1 cherry #define __HYPERVISOR_hvm_op 34 117 1.1 cherry #define __HYPERVISOR_sysctl 35 118 1.1 cherry #define __HYPERVISOR_domctl 36 119 1.1 cherry #define __HYPERVISOR_kexec_op 37 120 1.1 cherry #define __HYPERVISOR_tmem_op 38 121 1.1 cherry #define __HYPERVISOR_xc_reserved_op 39 /* reserved for XenClient */ 122 1.1 cherry #define __HYPERVISOR_xenpmu_op 40 123 1.1 cherry #define __HYPERVISOR_dm_op 41 124 1.1 cherry 125 1.1 cherry /* Architecture-specific hypercall definitions. */ 126 1.1 cherry #define __HYPERVISOR_arch_0 48 127 1.1 cherry #define __HYPERVISOR_arch_1 49 128 1.1 cherry #define __HYPERVISOR_arch_2 50 129 1.1 cherry #define __HYPERVISOR_arch_3 51 130 1.1 cherry #define __HYPERVISOR_arch_4 52 131 1.1 cherry #define __HYPERVISOR_arch_5 53 132 1.1 cherry #define __HYPERVISOR_arch_6 54 133 1.1 cherry #define __HYPERVISOR_arch_7 55 134 1.1 cherry 135 1.1 cherry /* ` } */ 136 1.1 cherry 137 1.1 cherry /* 138 1.1 cherry * HYPERCALL COMPATIBILITY. 139 1.1 cherry */ 140 1.1 cherry 141 1.1 cherry /* New sched_op hypercall introduced in 0x00030101. */ 142 1.1 cherry #if __XEN_INTERFACE_VERSION__ < 0x00030101 143 1.1 cherry #undef __HYPERVISOR_sched_op 144 1.1 cherry #define __HYPERVISOR_sched_op __HYPERVISOR_sched_op_compat 145 1.1 cherry #endif 146 1.1 cherry 147 1.1 cherry /* New event-channel and physdev hypercalls introduced in 0x00030202. */ 148 1.1 cherry #if __XEN_INTERFACE_VERSION__ < 0x00030202 149 1.1 cherry #undef __HYPERVISOR_event_channel_op 150 1.1 cherry #define __HYPERVISOR_event_channel_op __HYPERVISOR_event_channel_op_compat 151 1.1 cherry #undef __HYPERVISOR_physdev_op 152 1.1 cherry #define __HYPERVISOR_physdev_op __HYPERVISOR_physdev_op_compat 153 1.1 cherry #endif 154 1.1 cherry 155 1.1 cherry /* New platform_op hypercall introduced in 0x00030204. */ 156 1.1 cherry #if __XEN_INTERFACE_VERSION__ < 0x00030204 157 1.1 cherry #define __HYPERVISOR_dom0_op __HYPERVISOR_platform_op 158 1.1 cherry #endif 159 1.1 cherry 160 1.1 cherry /* 161 1.1 cherry * VIRTUAL INTERRUPTS 162 1.1 cherry * 163 1.1 cherry * Virtual interrupts that a guest OS may receive from Xen. 164 1.1 cherry * 165 1.1 cherry * In the side comments, 'V.' denotes a per-VCPU VIRQ while 'G.' denotes a 166 1.1 cherry * global VIRQ. The former can be bound once per VCPU and cannot be re-bound. 167 1.1 cherry * The latter can be allocated only once per guest: they must initially be 168 1.1 cherry * allocated to VCPU0 but can subsequently be re-bound. 169 1.1 cherry */ 170 1.1 cherry /* ` enum virq { */ 171 1.1 cherry #define VIRQ_TIMER 0 /* V. Timebase update, and/or requested timeout. */ 172 1.1 cherry #define VIRQ_DEBUG 1 /* V. Request guest to dump debug info. */ 173 1.1 cherry #define VIRQ_CONSOLE 2 /* G. (DOM0) Bytes received on emergency console. */ 174 1.1 cherry #define VIRQ_DOM_EXC 3 /* G. (DOM0) Exceptional event for some domain. */ 175 1.1 cherry #define VIRQ_TBUF 4 /* G. (DOM0) Trace buffer has records available. */ 176 1.1 cherry #define VIRQ_DEBUGGER 6 /* G. (DOM0) A domain has paused for debugging. */ 177 1.1 cherry #define VIRQ_XENOPROF 7 /* V. XenOprofile interrupt: new sample available */ 178 1.1 cherry #define VIRQ_CON_RING 8 /* G. (DOM0) Bytes received on console */ 179 1.1 cherry #define VIRQ_PCPU_STATE 9 /* G. (DOM0) PCPU state changed */ 180 1.1 cherry #define VIRQ_MEM_EVENT 10 /* G. (DOM0) A memory event has occured */ 181 1.1 cherry #define VIRQ_XC_RESERVED 11 /* G. Reserved for XenClient */ 182 1.1 cherry #define VIRQ_ENOMEM 12 /* G. (DOM0) Low on heap memory */ 183 1.1 cherry #define VIRQ_XENPMU 13 /* V. PMC interrupt */ 184 1.1 cherry 185 1.1 cherry /* Architecture-specific VIRQ definitions. */ 186 1.1 cherry #define VIRQ_ARCH_0 16 187 1.1 cherry #define VIRQ_ARCH_1 17 188 1.1 cherry #define VIRQ_ARCH_2 18 189 1.1 cherry #define VIRQ_ARCH_3 19 190 1.1 cherry #define VIRQ_ARCH_4 20 191 1.1 cherry #define VIRQ_ARCH_5 21 192 1.1 cherry #define VIRQ_ARCH_6 22 193 1.1 cherry #define VIRQ_ARCH_7 23 194 1.1 cherry /* ` } */ 195 1.1 cherry 196 1.1 cherry #define NR_VIRQS 24 197 1.1 cherry 198 1.1 cherry /* 199 1.1 cherry * ` enum neg_errnoval 200 1.1 cherry * ` HYPERVISOR_mmu_update(const struct mmu_update reqs[], 201 1.1 cherry * ` unsigned count, unsigned *done_out, 202 1.1 cherry * ` unsigned foreigndom) 203 1.1 cherry * ` 204 1.1 cherry * @reqs is an array of mmu_update_t structures ((ptr, val) pairs). 205 1.1 cherry * @count is the length of the above array. 206 1.1 cherry * @pdone is an output parameter indicating number of completed operations 207 1.1 cherry * @foreigndom[15:0]: FD, the expected owner of data pages referenced in this 208 1.1 cherry * hypercall invocation. Can be DOMID_SELF. 209 1.1 cherry * @foreigndom[31:16]: PFD, the expected owner of pagetable pages referenced 210 1.1 cherry * in this hypercall invocation. The value of this field 211 1.1 cherry * (x) encodes the PFD as follows: 212 1.1 cherry * x == 0 => PFD == DOMID_SELF 213 1.1 cherry * x != 0 => PFD == x - 1 214 1.1 cherry * 215 1.1 cherry * Sub-commands: ptr[1:0] specifies the appropriate MMU_* command. 216 1.1 cherry * ------------- 217 1.1 cherry * ptr[1:0] == MMU_NORMAL_PT_UPDATE: 218 1.1 cherry * Updates an entry in a page table belonging to PFD. If updating an L1 table, 219 1.1 cherry * and the new table entry is valid/present, the mapped frame must belong to 220 1.1 cherry * FD. If attempting to map an I/O page then the caller assumes the privilege 221 1.1 cherry * of the FD. 222 1.1 cherry * FD == DOMID_IO: Permit /only/ I/O mappings, at the priv level of the caller. 223 1.1 cherry * FD == DOMID_XEN: Map restricted areas of Xen's heap space. 224 1.1 cherry * ptr[:2] -- Machine address of the page-table entry to modify. 225 1.1 cherry * val -- Value to write. 226 1.1 cherry * 227 1.1 cherry * There also certain implicit requirements when using this hypercall. The 228 1.1 cherry * pages that make up a pagetable must be mapped read-only in the guest. 229 1.1 cherry * This prevents uncontrolled guest updates to the pagetable. Xen strictly 230 1.1 cherry * enforces this, and will disallow any pagetable update which will end up 231 1.1 cherry * mapping pagetable page RW, and will disallow using any writable page as a 232 1.1 cherry * pagetable. In practice it means that when constructing a page table for a 233 1.1 cherry * process, thread, etc, we MUST be very dilligient in following these rules: 234 1.1 cherry * 1). Start with top-level page (PGD or in Xen language: L4). Fill out 235 1.1 cherry * the entries. 236 1.1 cherry * 2). Keep on going, filling out the upper (PUD or L3), and middle (PMD 237 1.1 cherry * or L2). 238 1.1 cherry * 3). Start filling out the PTE table (L1) with the PTE entries. Once 239 1.1 cherry * done, make sure to set each of those entries to RO (so writeable bit 240 1.1 cherry * is unset). Once that has been completed, set the PMD (L2) for this 241 1.1 cherry * PTE table as RO. 242 1.1 cherry * 4). When completed with all of the PMD (L2) entries, and all of them have 243 1.1 cherry * been set to RO, make sure to set RO the PUD (L3). Do the same 244 1.1 cherry * operation on PGD (L4) pagetable entries that have a PUD (L3) entry. 245 1.1 cherry * 5). Now before you can use those pages (so setting the cr3), you MUST also 246 1.1 cherry * pin them so that the hypervisor can verify the entries. This is done 247 1.1 cherry * via the HYPERVISOR_mmuext_op(MMUEXT_PIN_L4_TABLE, guest physical frame 248 1.1 cherry * number of the PGD (L4)). And this point the HYPERVISOR_mmuext_op( 249 1.1 cherry * MMUEXT_NEW_BASEPTR, guest physical frame number of the PGD (L4)) can be 250 1.1 cherry * issued. 251 1.1 cherry * For 32-bit guests, the L4 is not used (as there is less pagetables), so 252 1.1 cherry * instead use L3. 253 1.1 cherry * At this point the pagetables can be modified using the MMU_NORMAL_PT_UPDATE 254 1.1 cherry * hypercall. Also if so desired the OS can also try to write to the PTE 255 1.1 cherry * and be trapped by the hypervisor (as the PTE entry is RO). 256 1.1 cherry * 257 1.1 cherry * To deallocate the pages, the operations are the reverse of the steps 258 1.1 cherry * mentioned above. The argument is MMUEXT_UNPIN_TABLE for all levels and the 259 1.1 cherry * pagetable MUST not be in use (meaning that the cr3 is not set to it). 260 1.1 cherry * 261 1.1 cherry * ptr[1:0] == MMU_MACHPHYS_UPDATE: 262 1.1 cherry * Updates an entry in the machine->pseudo-physical mapping table. 263 1.1 cherry * ptr[:2] -- Machine address within the frame whose mapping to modify. 264 1.1 cherry * The frame must belong to the FD, if one is specified. 265 1.1 cherry * val -- Value to write into the mapping entry. 266 1.1 cherry * 267 1.1 cherry * ptr[1:0] == MMU_PT_UPDATE_PRESERVE_AD: 268 1.1 cherry * As MMU_NORMAL_PT_UPDATE above, but A/D bits currently in the PTE are ORed 269 1.1 cherry * with those in @val. 270 1.1 cherry * 271 1.1 cherry * ptr[1:0] == MMU_PT_UPDATE_NO_TRANSLATE: 272 1.1 cherry * As MMU_NORMAL_PT_UPDATE above, but @val is not translated though FD 273 1.1 cherry * page tables. 274 1.1 cherry * 275 1.1 cherry * @val is usually the machine frame number along with some attributes. 276 1.1 cherry * The attributes by default follow the architecture defined bits. Meaning that 277 1.1 cherry * if this is a X86_64 machine and four page table layout is used, the layout 278 1.1 cherry * of val is: 279 1.1 cherry * - 63 if set means No execute (NX) 280 1.1 cherry * - 46-13 the machine frame number 281 1.1 cherry * - 12 available for guest 282 1.1 cherry * - 11 available for guest 283 1.1 cherry * - 10 available for guest 284 1.1 cherry * - 9 available for guest 285 1.1 cherry * - 8 global 286 1.1 cherry * - 7 PAT (PSE is disabled, must use hypercall to make 4MB or 2MB pages) 287 1.1 cherry * - 6 dirty 288 1.1 cherry * - 5 accessed 289 1.1 cherry * - 4 page cached disabled 290 1.1 cherry * - 3 page write through 291 1.1 cherry * - 2 userspace accessible 292 1.1 cherry * - 1 writeable 293 1.1 cherry * - 0 present 294 1.1 cherry * 295 1.1 cherry * The one bits that does not fit with the default layout is the PAGE_PSE 296 1.1 cherry * also called PAGE_PAT). The MMUEXT_[UN]MARK_SUPER arguments to the 297 1.1 cherry * HYPERVISOR_mmuext_op serve as mechanism to set a pagetable to be 4MB 298 1.1 cherry * (or 2MB) instead of using the PAGE_PSE bit. 299 1.1 cherry * 300 1.1 cherry * The reason that the PAGE_PSE (bit 7) is not being utilized is due to Xen 301 1.1 cherry * using it as the Page Attribute Table (PAT) bit - for details on it please 302 1.1 cherry * refer to Intel SDM 10.12. The PAT allows to set the caching attributes of 303 1.1 cherry * pages instead of using MTRRs. 304 1.1 cherry * 305 1.1 cherry * The PAT MSR is as follows (it is a 64-bit value, each entry is 8 bits): 306 1.1 cherry * PAT4 PAT0 307 1.1 cherry * +-----+-----+----+----+----+-----+----+----+ 308 1.1 cherry * | UC | UC- | WC | WB | UC | UC- | WC | WB | <= Linux 309 1.1 cherry * +-----+-----+----+----+----+-----+----+----+ 310 1.1 cherry * | UC | UC- | WT | WB | UC | UC- | WT | WB | <= BIOS (default when machine boots) 311 1.1 cherry * +-----+-----+----+----+----+-----+----+----+ 312 1.1 cherry * | rsv | rsv | WP | WC | UC | UC- | WT | WB | <= Xen 313 1.1 cherry * +-----+-----+----+----+----+-----+----+----+ 314 1.1 cherry * 315 1.1 cherry * The lookup of this index table translates to looking up 316 1.1 cherry * Bit 7, Bit 4, and Bit 3 of val entry: 317 1.1 cherry * 318 1.1 cherry * PAT/PSE (bit 7) ... PCD (bit 4) .. PWT (bit 3). 319 1.1 cherry * 320 1.1 cherry * If all bits are off, then we are using PAT0. If bit 3 turned on, 321 1.1 cherry * then we are using PAT1, if bit 3 and bit 4, then PAT2.. 322 1.1 cherry * 323 1.1 cherry * As you can see, the Linux PAT1 translates to PAT4 under Xen. Which means 324 1.1 cherry * that if a guest that follows Linux's PAT setup and would like to set Write 325 1.1 cherry * Combined on pages it MUST use PAT4 entry. Meaning that Bit 7 (PAGE_PAT) is 326 1.1 cherry * set. For example, under Linux it only uses PAT0, PAT1, and PAT2 for the 327 1.1 cherry * caching as: 328 1.1 cherry * 329 1.1 cherry * WB = none (so PAT0) 330 1.1 cherry * WC = PWT (bit 3 on) 331 1.1 cherry * UC = PWT | PCD (bit 3 and 4 are on). 332 1.1 cherry * 333 1.1 cherry * To make it work with Xen, it needs to translate the WC bit as so: 334 1.1 cherry * 335 1.1 cherry * PWT (so bit 3 on) --> PAT (so bit 7 is on) and clear bit 3 336 1.1 cherry * 337 1.1 cherry * And to translate back it would: 338 1.1 cherry * 339 1.1 cherry * PAT (bit 7 on) --> PWT (bit 3 on) and clear bit 7. 340 1.1 cherry */ 341 1.1 cherry #define MMU_NORMAL_PT_UPDATE 0 /* checked '*ptr = val'. ptr is MA. */ 342 1.1 cherry #define MMU_MACHPHYS_UPDATE 1 /* ptr = MA of frame to modify entry for */ 343 1.1 cherry #define MMU_PT_UPDATE_PRESERVE_AD 2 /* atomically: *ptr = val | (*ptr&(A|D)) */ 344 1.1 cherry #define MMU_PT_UPDATE_NO_TRANSLATE 3 /* checked '*ptr = val'. ptr is MA. */ 345 1.1 cherry /* val never translated. */ 346 1.1 cherry 347 1.1 cherry /* 348 1.1 cherry * MMU EXTENDED OPERATIONS 349 1.1 cherry * 350 1.1 cherry * ` enum neg_errnoval 351 1.1 cherry * ` HYPERVISOR_mmuext_op(mmuext_op_t uops[], 352 1.1 cherry * ` unsigned int count, 353 1.1 cherry * ` unsigned int *pdone, 354 1.1 cherry * ` unsigned int foreigndom) 355 1.1 cherry */ 356 1.1 cherry /* HYPERVISOR_mmuext_op() accepts a list of mmuext_op structures. 357 1.1 cherry * A foreigndom (FD) can be specified (or DOMID_SELF for none). 358 1.1 cherry * Where the FD has some effect, it is described below. 359 1.1 cherry * 360 1.1 cherry * cmd: MMUEXT_(UN)PIN_*_TABLE 361 1.1 cherry * mfn: Machine frame number to be (un)pinned as a p.t. page. 362 1.1 cherry * The frame must belong to the FD, if one is specified. 363 1.1 cherry * 364 1.1 cherry * cmd: MMUEXT_NEW_BASEPTR 365 1.1 cherry * mfn: Machine frame number of new page-table base to install in MMU. 366 1.1 cherry * 367 1.1 cherry * cmd: MMUEXT_NEW_USER_BASEPTR [x86/64 only] 368 1.1 cherry * mfn: Machine frame number of new page-table base to install in MMU 369 1.1 cherry * when in user space. 370 1.1 cherry * 371 1.1 cherry * cmd: MMUEXT_TLB_FLUSH_LOCAL 372 1.1 cherry * No additional arguments. Flushes local TLB. 373 1.1 cherry * 374 1.1 cherry * cmd: MMUEXT_INVLPG_LOCAL 375 1.1 cherry * linear_addr: Linear address to be flushed from the local TLB. 376 1.1 cherry * 377 1.1 cherry * cmd: MMUEXT_TLB_FLUSH_MULTI 378 1.1 cherry * vcpumask: Pointer to bitmap of VCPUs to be flushed. 379 1.1 cherry * 380 1.1 cherry * cmd: MMUEXT_INVLPG_MULTI 381 1.1 cherry * linear_addr: Linear address to be flushed. 382 1.1 cherry * vcpumask: Pointer to bitmap of VCPUs to be flushed. 383 1.1 cherry * 384 1.1 cherry * cmd: MMUEXT_TLB_FLUSH_ALL 385 1.1 cherry * No additional arguments. Flushes all VCPUs' TLBs. 386 1.1 cherry * 387 1.1 cherry * cmd: MMUEXT_INVLPG_ALL 388 1.1 cherry * linear_addr: Linear address to be flushed from all VCPUs' TLBs. 389 1.1 cherry * 390 1.1 cherry * cmd: MMUEXT_FLUSH_CACHE 391 1.1 cherry * No additional arguments. Writes back and flushes cache contents. 392 1.1 cherry * 393 1.1 cherry * cmd: MMUEXT_FLUSH_CACHE_GLOBAL 394 1.1 cherry * No additional arguments. Writes back and flushes cache contents 395 1.1 cherry * on all CPUs in the system. 396 1.1 cherry * 397 1.1 cherry * cmd: MMUEXT_SET_LDT 398 1.1 cherry * linear_addr: Linear address of LDT base (NB. must be page-aligned). 399 1.1 cherry * nr_ents: Number of entries in LDT. 400 1.1 cherry * 401 1.1 cherry * cmd: MMUEXT_CLEAR_PAGE 402 1.1 cherry * mfn: Machine frame number to be cleared. 403 1.1 cherry * 404 1.1 cherry * cmd: MMUEXT_COPY_PAGE 405 1.1 cherry * mfn: Machine frame number of the destination page. 406 1.1 cherry * src_mfn: Machine frame number of the source page. 407 1.1 cherry * 408 1.1 cherry * cmd: MMUEXT_[UN]MARK_SUPER 409 1.1 cherry * mfn: Machine frame number of head of superpage to be [un]marked. 410 1.1 cherry */ 411 1.1 cherry /* ` enum mmuext_cmd { */ 412 1.1 cherry #define MMUEXT_PIN_L1_TABLE 0 413 1.1 cherry #define MMUEXT_PIN_L2_TABLE 1 414 1.1 cherry #define MMUEXT_PIN_L3_TABLE 2 415 1.1 cherry #define MMUEXT_PIN_L4_TABLE 3 416 1.1 cherry #define MMUEXT_UNPIN_TABLE 4 417 1.1 cherry #define MMUEXT_NEW_BASEPTR 5 418 1.1 cherry #define MMUEXT_TLB_FLUSH_LOCAL 6 419 1.1 cherry #define MMUEXT_INVLPG_LOCAL 7 420 1.1 cherry #define MMUEXT_TLB_FLUSH_MULTI 8 421 1.1 cherry #define MMUEXT_INVLPG_MULTI 9 422 1.1 cherry #define MMUEXT_TLB_FLUSH_ALL 10 423 1.1 cherry #define MMUEXT_INVLPG_ALL 11 424 1.1 cherry #define MMUEXT_FLUSH_CACHE 12 425 1.1 cherry #define MMUEXT_SET_LDT 13 426 1.1 cherry #define MMUEXT_NEW_USER_BASEPTR 15 427 1.1 cherry #define MMUEXT_CLEAR_PAGE 16 428 1.1 cherry #define MMUEXT_COPY_PAGE 17 429 1.1 cherry #define MMUEXT_FLUSH_CACHE_GLOBAL 18 430 1.1 cherry #define MMUEXT_MARK_SUPER 19 431 1.1 cherry #define MMUEXT_UNMARK_SUPER 20 432 1.1 cherry /* ` } */ 433 1.1 cherry 434 1.1 cherry #ifndef __ASSEMBLY__ 435 1.1 cherry struct mmuext_op { 436 1.1 cherry unsigned int cmd; /* => enum mmuext_cmd */ 437 1.1 cherry union { 438 1.1 cherry /* [UN]PIN_TABLE, NEW_BASEPTR, NEW_USER_BASEPTR 439 1.1 cherry * CLEAR_PAGE, COPY_PAGE, [UN]MARK_SUPER */ 440 1.1 cherry xen_pfn_t mfn; 441 1.1 cherry /* INVLPG_LOCAL, INVLPG_ALL, SET_LDT */ 442 1.1 cherry unsigned long linear_addr; 443 1.1 cherry } arg1; 444 1.1 cherry union { 445 1.1 cherry /* SET_LDT */ 446 1.1 cherry unsigned int nr_ents; 447 1.1 cherry /* TLB_FLUSH_MULTI, INVLPG_MULTI */ 448 1.1 cherry #if __XEN_INTERFACE_VERSION__ >= 0x00030205 449 1.1 cherry XEN_GUEST_HANDLE(const_void) vcpumask; 450 1.1 cherry #else 451 1.1 cherry const void *vcpumask; 452 1.1 cherry #endif 453 1.1 cherry /* COPY_PAGE */ 454 1.1 cherry xen_pfn_t src_mfn; 455 1.1 cherry } arg2; 456 1.1 cherry }; 457 1.1 cherry typedef struct mmuext_op mmuext_op_t; 458 1.1 cherry DEFINE_XEN_GUEST_HANDLE(mmuext_op_t); 459 1.1 cherry #endif 460 1.1 cherry 461 1.1 cherry /* 462 1.1 cherry * ` enum neg_errnoval 463 1.1 cherry * ` HYPERVISOR_update_va_mapping(unsigned long va, u64 val, 464 1.1 cherry * ` enum uvm_flags flags) 465 1.1 cherry * ` 466 1.1 cherry * ` enum neg_errnoval 467 1.1 cherry * ` HYPERVISOR_update_va_mapping_otherdomain(unsigned long va, u64 val, 468 1.1 cherry * ` enum uvm_flags flags, 469 1.1 cherry * ` domid_t domid) 470 1.1 cherry * ` 471 1.1 cherry * ` @va: The virtual address whose mapping we want to change 472 1.1 cherry * ` @val: The new page table entry, must contain a machine address 473 1.1 cherry * ` @flags: Control TLB flushes 474 1.1 cherry */ 475 1.1 cherry /* These are passed as 'flags' to update_va_mapping. They can be ORed. */ 476 1.1 cherry /* When specifying UVMF_MULTI, also OR in a pointer to a CPU bitmap. */ 477 1.1 cherry /* UVMF_LOCAL is merely UVMF_MULTI with a NULL bitmap pointer. */ 478 1.1 cherry /* ` enum uvm_flags { */ 479 1.1 cherry #define UVMF_NONE (xen_mk_ulong(0)<<0) /* No flushing at all. */ 480 1.1 cherry #define UVMF_TLB_FLUSH (xen_mk_ulong(1)<<0) /* Flush entire TLB(s). */ 481 1.1 cherry #define UVMF_INVLPG (xen_mk_ulong(2)<<0) /* Flush only one entry. */ 482 1.1 cherry #define UVMF_FLUSHTYPE_MASK (xen_mk_ulong(3)<<0) 483 1.1 cherry #define UVMF_MULTI (xen_mk_ulong(0)<<2) /* Flush subset of TLBs. */ 484 1.1 cherry #define UVMF_LOCAL (xen_mk_ulong(0)<<2) /* Flush local TLB. */ 485 1.1 cherry #define UVMF_ALL (xen_mk_ulong(1)<<2) /* Flush all TLBs. */ 486 1.1 cherry /* ` } */ 487 1.1 cherry 488 1.1 cherry /* 489 1.1 cherry * Commands to HYPERVISOR_console_io(). 490 1.1 cherry */ 491 1.1 cherry #define CONSOLEIO_write 0 492 1.1 cherry #define CONSOLEIO_read 1 493 1.1 cherry 494 1.1 cherry /* 495 1.1 cherry * Commands to HYPERVISOR_vm_assist(). 496 1.1 cherry */ 497 1.1 cherry #define VMASST_CMD_enable 0 498 1.1 cherry #define VMASST_CMD_disable 1 499 1.1 cherry 500 1.1 cherry /* x86/32 guests: simulate full 4GB segment limits. */ 501 1.1 cherry #define VMASST_TYPE_4gb_segments 0 502 1.1 cherry 503 1.1 cherry /* x86/32 guests: trap (vector 15) whenever above vmassist is used. */ 504 1.1 cherry #define VMASST_TYPE_4gb_segments_notify 1 505 1.1 cherry 506 1.1 cherry /* 507 1.1 cherry * x86 guests: support writes to bottom-level PTEs. 508 1.1 cherry * NB1. Page-directory entries cannot be written. 509 1.1 cherry * NB2. Guest must continue to remove all writable mappings of PTEs. 510 1.1 cherry */ 511 1.1 cherry #define VMASST_TYPE_writable_pagetables 2 512 1.1 cherry 513 1.1 cherry /* x86/PAE guests: support PDPTs above 4GB. */ 514 1.1 cherry #define VMASST_TYPE_pae_extended_cr3 3 515 1.1 cherry 516 1.1 cherry /* 517 1.1 cherry * x86 guests: Sane behaviour for virtual iopl 518 1.1 cherry * - virtual iopl updated from do_iret() hypercalls. 519 1.1 cherry * - virtual iopl reported in bounce frames. 520 1.1 cherry * - guest kernels assumed to be level 0 for the purpose of iopl checks. 521 1.1 cherry */ 522 1.1 cherry #define VMASST_TYPE_architectural_iopl 4 523 1.1 cherry 524 1.1 cherry /* 525 1.1 cherry * All guests: activate update indicator in vcpu_runstate_info 526 1.1 cherry * Enable setting the XEN_RUNSTATE_UPDATE flag in guest memory mapped 527 1.1 cherry * vcpu_runstate_info during updates of the runstate information. 528 1.1 cherry */ 529 1.1 cherry #define VMASST_TYPE_runstate_update_flag 5 530 1.1 cherry 531 1.1 cherry /* 532 1.1 cherry * x86/64 guests: strictly hide M2P from user mode. 533 1.1 cherry * This allows the guest to control respective hypervisor behavior: 534 1.1 cherry * - when not set, L4 tables get created with the respective slot blank, 535 1.1 cherry * and whenever the L4 table gets used as a kernel one the missing 536 1.1 cherry * mapping gets inserted, 537 1.1 cherry * - when set, L4 tables get created with the respective slot initialized 538 1.1 cherry * as before, and whenever the L4 table gets used as a user one the 539 1.1 cherry * mapping gets zapped. 540 1.1 cherry */ 541 1.1 cherry #define VMASST_TYPE_m2p_strict 32 542 1.1 cherry 543 1.1 cherry #if __XEN_INTERFACE_VERSION__ < 0x00040600 544 1.1 cherry #define MAX_VMASST_TYPE 3 545 1.1 cherry #endif 546 1.1 cherry 547 1.1 cherry /* Domain ids >= DOMID_FIRST_RESERVED cannot be used for ordinary domains. */ 548 1.1 cherry #define DOMID_FIRST_RESERVED xen_mk_uint(0x7FF0) 549 1.1 cherry 550 1.1 cherry /* DOMID_SELF is used in certain contexts to refer to oneself. */ 551 1.1 cherry #define DOMID_SELF xen_mk_uint(0x7FF0) 552 1.1 cherry 553 1.1 cherry /* 554 1.1 cherry * DOMID_IO is used to restrict page-table updates to mapping I/O memory. 555 1.1 cherry * Although no Foreign Domain need be specified to map I/O pages, DOMID_IO 556 1.1 cherry * is useful to ensure that no mappings to the OS's own heap are accidentally 557 1.1 cherry * installed. (e.g., in Linux this could cause havoc as reference counts 558 1.1 cherry * aren't adjusted on the I/O-mapping code path). 559 1.1 cherry * This only makes sense as HYPERVISOR_mmu_update()'s and 560 1.1 cherry * HYPERVISOR_update_va_mapping_otherdomain()'s "foreigndom" argument. For 561 1.1 cherry * HYPERVISOR_mmu_update() context it can be specified by any calling domain, 562 1.1 cherry * otherwise it's only permitted if the caller is privileged. 563 1.1 cherry */ 564 1.1 cherry #define DOMID_IO xen_mk_uint(0x7FF1) 565 1.1 cherry 566 1.1 cherry /* 567 1.1 cherry * DOMID_XEN is used to allow privileged domains to map restricted parts of 568 1.1 cherry * Xen's heap space (e.g., the machine_to_phys table). 569 1.1 cherry * This only makes sense as 570 1.1 cherry * - HYPERVISOR_mmu_update()'s, HYPERVISOR_mmuext_op()'s, or 571 1.1 cherry * HYPERVISOR_update_va_mapping_otherdomain()'s "foreigndom" argument, 572 1.1 cherry * - with XENMAPSPACE_gmfn_foreign, 573 1.1 cherry * and is only permitted if the caller is privileged. 574 1.1 cherry */ 575 1.1 cherry #define DOMID_XEN xen_mk_uint(0x7FF2) 576 1.1 cherry 577 1.1 cherry /* 578 1.1 cherry * DOMID_COW is used as the owner of sharable pages */ 579 1.1 cherry #define DOMID_COW xen_mk_uint(0x7FF3) 580 1.1 cherry 581 1.1 cherry /* DOMID_INVALID is used to identify pages with unknown owner. */ 582 1.1 cherry #define DOMID_INVALID xen_mk_uint(0x7FF4) 583 1.1 cherry 584 1.1 cherry /* Idle domain. */ 585 1.1 cherry #define DOMID_IDLE xen_mk_uint(0x7FFF) 586 1.1 cherry 587 1.1 cherry #ifndef __ASSEMBLY__ 588 1.1 cherry 589 1.1 cherry typedef uint16_t domid_t; 590 1.1 cherry 591 1.1 cherry /* 592 1.1 cherry * Send an array of these to HYPERVISOR_mmu_update(). 593 1.1 cherry * NB. The fields are natural pointer/address size for this architecture. 594 1.1 cherry */ 595 1.1 cherry struct mmu_update { 596 1.1 cherry uint64_t ptr; /* Machine address of PTE. */ 597 1.1 cherry uint64_t val; /* New contents of PTE. */ 598 1.1 cherry }; 599 1.1 cherry typedef struct mmu_update mmu_update_t; 600 1.1 cherry DEFINE_XEN_GUEST_HANDLE(mmu_update_t); 601 1.1 cherry 602 1.1 cherry /* 603 1.1 cherry * ` enum neg_errnoval 604 1.1 cherry * ` HYPERVISOR_multicall(multicall_entry_t call_list[], 605 1.1 cherry * ` uint32_t nr_calls); 606 1.1 cherry * 607 1.1 cherry * NB. The fields are logically the natural register size for this 608 1.1 cherry * architecture. In cases where xen_ulong_t is larger than this then 609 1.1 cherry * any unused bits in the upper portion must be zero. 610 1.1 cherry */ 611 1.1 cherry struct multicall_entry { 612 1.1 cherry xen_ulong_t op, result; 613 1.1 cherry xen_ulong_t args[6]; 614 1.1 cherry }; 615 1.1 cherry typedef struct multicall_entry multicall_entry_t; 616 1.1 cherry DEFINE_XEN_GUEST_HANDLE(multicall_entry_t); 617 1.1 cherry 618 1.1 cherry #if __XEN_INTERFACE_VERSION__ < 0x00040400 619 1.1 cherry /* 620 1.1 cherry * Event channel endpoints per domain (when using the 2-level ABI): 621 1.1 cherry * 1024 if a long is 32 bits; 4096 if a long is 64 bits. 622 1.1 cherry */ 623 1.1 cherry #define NR_EVENT_CHANNELS EVTCHN_2L_NR_CHANNELS 624 1.1 cherry #endif 625 1.1 cherry 626 1.1 cherry struct vcpu_time_info { 627 1.1 cherry /* 628 1.1 cherry * Updates to the following values are preceded and followed by an 629 1.1 cherry * increment of 'version'. The guest can therefore detect updates by 630 1.1 cherry * looking for changes to 'version'. If the least-significant bit of 631 1.1 cherry * the version number is set then an update is in progress and the guest 632 1.1 cherry * must wait to read a consistent set of values. 633 1.1 cherry * The correct way to interact with the version number is similar to 634 1.1 cherry * Linux's seqlock: see the implementations of read_seqbegin/read_seqretry. 635 1.1 cherry */ 636 1.1 cherry uint32_t version; 637 1.1 cherry uint32_t pad0; 638 1.1 cherry uint64_t tsc_timestamp; /* TSC at last update of time vals. */ 639 1.1 cherry uint64_t system_time; /* Time, in nanosecs, since boot. */ 640 1.1 cherry /* 641 1.1 cherry * Current system time: 642 1.1 cherry * system_time + 643 1.1 cherry * ((((tsc - tsc_timestamp) << tsc_shift) * tsc_to_system_mul) >> 32) 644 1.1 cherry * CPU frequency (Hz): 645 1.1 cherry * ((10^9 << 32) / tsc_to_system_mul) >> tsc_shift 646 1.1 cherry */ 647 1.1 cherry uint32_t tsc_to_system_mul; 648 1.1 cherry int8_t tsc_shift; 649 1.1 cherry #if __XEN_INTERFACE_VERSION__ > 0x040600 650 1.1 cherry uint8_t flags; 651 1.1 cherry uint8_t pad1[2]; 652 1.1 cherry #else 653 1.1 cherry int8_t pad1[3]; 654 1.1 cherry #endif 655 1.1 cherry }; /* 32 bytes */ 656 1.1 cherry typedef struct vcpu_time_info vcpu_time_info_t; 657 1.1 cherry 658 1.1 cherry #define XEN_PVCLOCK_TSC_STABLE_BIT (1 << 0) 659 1.1 cherry #define XEN_PVCLOCK_GUEST_STOPPED (1 << 1) 660 1.1 cherry 661 1.1 cherry struct vcpu_info { 662 1.1 cherry /* 663 1.1 cherry * 'evtchn_upcall_pending' is written non-zero by Xen to indicate 664 1.1 cherry * a pending notification for a particular VCPU. It is then cleared 665 1.1 cherry * by the guest OS /before/ checking for pending work, thus avoiding 666 1.1 cherry * a set-and-check race. Note that the mask is only accessed by Xen 667 1.1 cherry * on the CPU that is currently hosting the VCPU. This means that the 668 1.1 cherry * pending and mask flags can be updated by the guest without special 669 1.1 cherry * synchronisation (i.e., no need for the x86 LOCK prefix). 670 1.1 cherry * This may seem suboptimal because if the pending flag is set by 671 1.1 cherry * a different CPU then an IPI may be scheduled even when the mask 672 1.1 cherry * is set. However, note: 673 1.1 cherry * 1. The task of 'interrupt holdoff' is covered by the per-event- 674 1.1 cherry * channel mask bits. A 'noisy' event that is continually being 675 1.1 cherry * triggered can be masked at source at this very precise 676 1.1 cherry * granularity. 677 1.1 cherry * 2. The main purpose of the per-VCPU mask is therefore to restrict 678 1.1 cherry * reentrant execution: whether for concurrency control, or to 679 1.1 cherry * prevent unbounded stack usage. Whatever the purpose, we expect 680 1.1 cherry * that the mask will be asserted only for short periods at a time, 681 1.1 cherry * and so the likelihood of a 'spurious' IPI is suitably small. 682 1.1 cherry * The mask is read before making an event upcall to the guest: a 683 1.1 cherry * non-zero mask therefore guarantees that the VCPU will not receive 684 1.1 cherry * an upcall activation. The mask is cleared when the VCPU requests 685 1.1 cherry * to block: this avoids wakeup-waiting races. 686 1.1 cherry */ 687 1.1 cherry uint8_t evtchn_upcall_pending; 688 1.1 cherry #ifdef XEN_HAVE_PV_UPCALL_MASK 689 1.1 cherry uint8_t evtchn_upcall_mask; 690 1.1 cherry #else /* XEN_HAVE_PV_UPCALL_MASK */ 691 1.1 cherry uint8_t pad0; 692 1.1 cherry #endif /* XEN_HAVE_PV_UPCALL_MASK */ 693 1.1 cherry xen_ulong_t evtchn_pending_sel; 694 1.1 cherry struct arch_vcpu_info arch; 695 1.1 cherry struct vcpu_time_info time; 696 1.1 cherry }; /* 64 bytes (x86) */ 697 1.1 cherry #ifndef __XEN__ 698 1.1 cherry typedef struct vcpu_info vcpu_info_t; 699 1.1 cherry #endif 700 1.1 cherry 701 1.1 cherry /* 702 1.1 cherry * `incontents 200 startofday_shared Start-of-day shared data structure 703 1.1 cherry * Xen/kernel shared data -- pointer provided in start_info. 704 1.1 cherry * 705 1.1 cherry * This structure is defined to be both smaller than a page, and the 706 1.1 cherry * only data on the shared page, but may vary in actual size even within 707 1.1 cherry * compatible Xen versions; guests should not rely on the size 708 1.1 cherry * of this structure remaining constant. 709 1.1 cherry */ 710 1.1 cherry struct shared_info { 711 1.1 cherry struct vcpu_info vcpu_info[XEN_LEGACY_MAX_VCPUS]; 712 1.1 cherry 713 1.1 cherry /* 714 1.1 cherry * A domain can create "event channels" on which it can send and receive 715 1.1 cherry * asynchronous event notifications. There are three classes of event that 716 1.1 cherry * are delivered by this mechanism: 717 1.1 cherry * 1. Bi-directional inter- and intra-domain connections. Domains must 718 1.1 cherry * arrange out-of-band to set up a connection (usually by allocating 719 1.1 cherry * an unbound 'listener' port and avertising that via a storage service 720 1.1 cherry * such as xenstore). 721 1.1 cherry * 2. Physical interrupts. A domain with suitable hardware-access 722 1.1 cherry * privileges can bind an event-channel port to a physical interrupt 723 1.1 cherry * source. 724 1.1 cherry * 3. Virtual interrupts ('events'). A domain can bind an event-channel 725 1.1 cherry * port to a virtual interrupt source, such as the virtual-timer 726 1.1 cherry * device or the emergency console. 727 1.1 cherry * 728 1.1 cherry * Event channels are addressed by a "port index". Each channel is 729 1.1 cherry * associated with two bits of information: 730 1.1 cherry * 1. PENDING -- notifies the domain that there is a pending notification 731 1.1 cherry * to be processed. This bit is cleared by the guest. 732 1.1 cherry * 2. MASK -- if this bit is clear then a 0->1 transition of PENDING 733 1.1 cherry * will cause an asynchronous upcall to be scheduled. This bit is only 734 1.1 cherry * updated by the guest. It is read-only within Xen. If a channel 735 1.1 cherry * becomes pending while the channel is masked then the 'edge' is lost 736 1.1 cherry * (i.e., when the channel is unmasked, the guest must manually handle 737 1.1 cherry * pending notifications as no upcall will be scheduled by Xen). 738 1.1 cherry * 739 1.1 cherry * To expedite scanning of pending notifications, any 0->1 pending 740 1.1 cherry * transition on an unmasked channel causes a corresponding bit in a 741 1.1 cherry * per-vcpu selector word to be set. Each bit in the selector covers a 742 1.1 cherry * 'C long' in the PENDING bitfield array. 743 1.1 cherry */ 744 1.1 cherry xen_ulong_t evtchn_pending[sizeof(xen_ulong_t) * 8]; 745 1.1 cherry xen_ulong_t evtchn_mask[sizeof(xen_ulong_t) * 8]; 746 1.1 cherry 747 1.1 cherry /* 748 1.1 cherry * Wallclock time: updated only by control software. Guests should base 749 1.1 cherry * their gettimeofday() syscall on this wallclock-base value. 750 1.1 cherry */ 751 1.1 cherry uint32_t wc_version; /* Version counter: see vcpu_time_info_t. */ 752 1.1 cherry uint32_t wc_sec; /* Secs 00:00:00 UTC, Jan 1, 1970. */ 753 1.1 cherry uint32_t wc_nsec; /* Nsecs 00:00:00 UTC, Jan 1, 1970. */ 754 1.1 cherry #if !defined(__i386__) 755 1.1 cherry uint32_t wc_sec_hi; 756 1.1 cherry # define xen_wc_sec_hi wc_sec_hi 757 1.1 cherry #elif !defined(__XEN__) && !defined(__XEN_TOOLS__) 758 1.1 cherry # define xen_wc_sec_hi arch.wc_sec_hi 759 1.1 cherry #endif 760 1.1 cherry 761 1.1 cherry struct arch_shared_info arch; 762 1.1 cherry 763 1.1 cherry }; 764 1.1 cherry #ifndef __XEN__ 765 1.1 cherry typedef struct shared_info shared_info_t; 766 1.1 cherry #endif 767 1.1 cherry 768 1.1 cherry /* 769 1.1 cherry * `incontents 200 startofday Start-of-day memory layout 770 1.1 cherry * 771 1.1 cherry * 1. The domain is started within contiguous virtual-memory region. 772 1.1 cherry * 2. The contiguous region ends on an aligned 4MB boundary. 773 1.1 cherry * 3. This the order of bootstrap elements in the initial virtual region: 774 1.1 cherry * a. relocated kernel image 775 1.1 cherry * b. initial ram disk [mod_start, mod_len] 776 1.1 cherry * (may be omitted) 777 1.1 cherry * c. list of allocated page frames [mfn_list, nr_pages] 778 1.1 cherry * (unless relocated due to XEN_ELFNOTE_INIT_P2M) 779 1.1 cherry * d. start_info_t structure [register rSI (x86)] 780 1.1 cherry * in case of dom0 this page contains the console info, too 781 1.1 cherry * e. unless dom0: xenstore ring page 782 1.1 cherry * f. unless dom0: console ring page 783 1.1 cherry * g. bootstrap page tables [pt_base and CR3 (x86)] 784 1.1 cherry * h. bootstrap stack [register ESP (x86)] 785 1.1 cherry * 4. Bootstrap elements are packed together, but each is 4kB-aligned. 786 1.1 cherry * 5. The list of page frames forms a contiguous 'pseudo-physical' memory 787 1.1 cherry * layout for the domain. In particular, the bootstrap virtual-memory 788 1.1 cherry * region is a 1:1 mapping to the first section of the pseudo-physical map. 789 1.1 cherry * 6. All bootstrap elements are mapped read-writable for the guest OS. The 790 1.1 cherry * only exception is the bootstrap page table, which is mapped read-only. 791 1.1 cherry * 7. There is guaranteed to be at least 512kB padding after the final 792 1.1 cherry * bootstrap element. If necessary, the bootstrap virtual region is 793 1.1 cherry * extended by an extra 4MB to ensure this. 794 1.1 cherry * 795 1.1 cherry * Note: Prior to 25833:bb85bbccb1c9. ("x86/32-on-64 adjust Dom0 initial page 796 1.1 cherry * table layout") a bug caused the pt_base (3.g above) and cr3 to not point 797 1.1 cherry * to the start of the guest page tables (it was offset by two pages). 798 1.1 cherry * This only manifested itself on 32-on-64 dom0 kernels and not 32-on-64 domU 799 1.1 cherry * or 64-bit kernels of any colour. The page tables for a 32-on-64 dom0 got 800 1.1 cherry * allocated in the order: 'first L1','first L2', 'first L3', so the offset 801 1.1 cherry * to the page table base is by two pages back. The initial domain if it is 802 1.1 cherry * 32-bit and runs under a 64-bit hypervisor should _NOT_ use two of the 803 1.1 cherry * pages preceding pt_base and mark them as reserved/unused. 804 1.1 cherry */ 805 1.1 cherry #ifdef XEN_HAVE_PV_GUEST_ENTRY 806 1.1 cherry struct start_info { 807 1.1 cherry /* THE FOLLOWING ARE FILLED IN BOTH ON INITIAL BOOT AND ON RESUME. */ 808 1.1 cherry char magic[32]; /* "xen-<version>-<platform>". */ 809 1.1 cherry unsigned long nr_pages; /* Total pages allocated to this domain. */ 810 1.1 cherry unsigned long shared_info; /* MACHINE address of shared info struct. */ 811 1.1 cherry uint32_t flags; /* SIF_xxx flags. */ 812 1.1 cherry xen_pfn_t store_mfn; /* MACHINE page number of shared page. */ 813 1.1 cherry uint32_t store_evtchn; /* Event channel for store communication. */ 814 1.1 cherry union { 815 1.1 cherry struct { 816 1.1 cherry xen_pfn_t mfn; /* MACHINE page number of console page. */ 817 1.1 cherry uint32_t evtchn; /* Event channel for console page. */ 818 1.1 cherry } domU; 819 1.1 cherry struct { 820 1.1 cherry uint32_t info_off; /* Offset of console_info struct. */ 821 1.1 cherry uint32_t info_size; /* Size of console_info struct from start.*/ 822 1.1 cherry } dom0; 823 1.1 cherry } console; 824 1.1 cherry /* THE FOLLOWING ARE ONLY FILLED IN ON INITIAL BOOT (NOT RESUME). */ 825 1.1 cherry unsigned long pt_base; /* VIRTUAL address of page directory. */ 826 1.1 cherry unsigned long nr_pt_frames; /* Number of bootstrap p.t. frames. */ 827 1.1 cherry unsigned long mfn_list; /* VIRTUAL address of page-frame list. */ 828 1.1 cherry unsigned long mod_start; /* VIRTUAL address of pre-loaded module */ 829 1.1 cherry /* (PFN of pre-loaded module if */ 830 1.1 cherry /* SIF_MOD_START_PFN set in flags). */ 831 1.1 cherry unsigned long mod_len; /* Size (bytes) of pre-loaded module. */ 832 1.1 cherry #define MAX_GUEST_CMDLINE 1024 833 1.1 cherry int8_t cmd_line[MAX_GUEST_CMDLINE]; 834 1.1 cherry /* The pfn range here covers both page table and p->m table frames. */ 835 1.1 cherry unsigned long first_p2m_pfn;/* 1st pfn forming initial P->M table. */ 836 1.1 cherry unsigned long nr_p2m_frames;/* # of pfns forming initial P->M table. */ 837 1.1 cherry }; 838 1.1 cherry typedef struct start_info start_info_t; 839 1.1 cherry 840 1.1 cherry /* New console union for dom0 introduced in 0x00030203. */ 841 1.1 cherry #if __XEN_INTERFACE_VERSION__ < 0x00030203 842 1.1 cherry #define console_mfn console.domU.mfn 843 1.1 cherry #define console_evtchn console.domU.evtchn 844 1.1 cherry #endif 845 1.1 cherry #endif /* XEN_HAVE_PV_GUEST_ENTRY */ 846 1.1 cherry 847 1.1 cherry /* These flags are passed in the 'flags' field of start_info_t. */ 848 1.1 cherry #define SIF_PRIVILEGED (1<<0) /* Is the domain privileged? */ 849 1.1 cherry #define SIF_INITDOMAIN (1<<1) /* Is this the initial control domain? */ 850 1.1 cherry #define SIF_MULTIBOOT_MOD (1<<2) /* Is mod_start a multiboot module? */ 851 1.1 cherry #define SIF_MOD_START_PFN (1<<3) /* Is mod_start a PFN? */ 852 1.1 cherry #define SIF_VIRT_P2M_4TOOLS (1<<4) /* Do Xen tools understand a virt. mapped */ 853 1.1 cherry /* P->M making the 3 level tree obsolete? */ 854 1.1 cherry #define SIF_PM_MASK (0xFF<<8) /* reserve 1 byte for xen-pm options */ 855 1.1 cherry 856 1.1 cherry /* 857 1.1 cherry * A multiboot module is a package containing modules very similar to a 858 1.1 cherry * multiboot module array. The only differences are: 859 1.1 cherry * - the array of module descriptors is by convention simply at the beginning 860 1.1 cherry * of the multiboot module, 861 1.1 cherry * - addresses in the module descriptors are based on the beginning of the 862 1.1 cherry * multiboot module, 863 1.1 cherry * - the number of modules is determined by a termination descriptor that has 864 1.1 cherry * mod_start == 0. 865 1.1 cherry * 866 1.1 cherry * This permits to both build it statically and reference it in a configuration 867 1.1 cherry * file, and let the PV guest easily rebase the addresses to virtual addresses 868 1.1 cherry * and at the same time count the number of modules. 869 1.1 cherry */ 870 1.1 cherry struct xen_multiboot_mod_list 871 1.1 cherry { 872 1.1 cherry /* Address of first byte of the module */ 873 1.1 cherry uint32_t mod_start; 874 1.1 cherry /* Address of last byte of the module (inclusive) */ 875 1.1 cherry uint32_t mod_end; 876 1.1 cherry /* Address of zero-terminated command line */ 877 1.1 cherry uint32_t cmdline; 878 1.1 cherry /* Unused, must be zero */ 879 1.1 cherry uint32_t pad; 880 1.1 cherry }; 881 1.1 cherry /* 882 1.1 cherry * `incontents 200 startofday_dom0_console Dom0_console 883 1.1 cherry * 884 1.1 cherry * The console structure in start_info.console.dom0 885 1.1 cherry * 886 1.1 cherry * This structure includes a variety of information required to 887 1.1 cherry * have a working VGA/VESA console. 888 1.1 cherry */ 889 1.1 cherry typedef struct dom0_vga_console_info { 890 1.1 cherry uint8_t video_type; /* DOM0_VGA_CONSOLE_??? */ 891 1.1 cherry #define XEN_VGATYPE_TEXT_MODE_3 0x03 892 1.1 cherry #define XEN_VGATYPE_VESA_LFB 0x23 893 1.1 cherry #define XEN_VGATYPE_EFI_LFB 0x70 894 1.1 cherry 895 1.1 cherry union { 896 1.1 cherry struct { 897 1.1 cherry /* Font height, in pixels. */ 898 1.1 cherry uint16_t font_height; 899 1.1 cherry /* Cursor location (column, row). */ 900 1.1 cherry uint16_t cursor_x, cursor_y; 901 1.1 cherry /* Number of rows and columns (dimensions in characters). */ 902 1.1 cherry uint16_t rows, columns; 903 1.1 cherry } text_mode_3; 904 1.1 cherry 905 1.1 cherry struct { 906 1.1 cherry /* Width and height, in pixels. */ 907 1.1 cherry uint16_t width, height; 908 1.1 cherry /* Bytes per scan line. */ 909 1.1 cherry uint16_t bytes_per_line; 910 1.1 cherry /* Bits per pixel. */ 911 1.1 cherry uint16_t bits_per_pixel; 912 1.1 cherry /* LFB physical address, and size (in units of 64kB). */ 913 1.1 cherry uint32_t lfb_base; 914 1.1 cherry uint32_t lfb_size; 915 1.1 cherry /* RGB mask offsets and sizes, as defined by VBE 1.2+ */ 916 1.1 cherry uint8_t red_pos, red_size; 917 1.1 cherry uint8_t green_pos, green_size; 918 1.1 cherry uint8_t blue_pos, blue_size; 919 1.1 cherry uint8_t rsvd_pos, rsvd_size; 920 1.1 cherry #if __XEN_INTERFACE_VERSION__ >= 0x00030206 921 1.1 cherry /* VESA capabilities (offset 0xa, VESA command 0x4f00). */ 922 1.1 cherry uint32_t gbl_caps; 923 1.1 cherry /* Mode attributes (offset 0x0, VESA command 0x4f01). */ 924 1.1 cherry uint16_t mode_attrs; 925 1.2 bouyer /* high 32 bits of lfb_base */ 926 1.2 bouyer uint32_t ext_lfb_base; 927 1.1 cherry #endif 928 1.1 cherry } vesa_lfb; 929 1.1 cherry } u; 930 1.1 cherry } dom0_vga_console_info_t; 931 1.1 cherry #define xen_vga_console_info dom0_vga_console_info 932 1.1 cherry #define xen_vga_console_info_t dom0_vga_console_info_t 933 1.1 cherry 934 1.1 cherry typedef uint8_t xen_domain_handle_t[16]; 935 1.1 cherry 936 1.1 cherry __DEFINE_XEN_GUEST_HANDLE(uint8, uint8_t); 937 1.1 cherry __DEFINE_XEN_GUEST_HANDLE(uint16, uint16_t); 938 1.1 cherry __DEFINE_XEN_GUEST_HANDLE(uint32, uint32_t); 939 1.1 cherry __DEFINE_XEN_GUEST_HANDLE(uint64, uint64_t); 940 1.1 cherry 941 1.1 cherry typedef struct { 942 1.1 cherry uint8_t a[16]; 943 1.1 cherry } xen_uuid_t; 944 1.1 cherry 945 1.1 cherry /* 946 1.1 cherry * XEN_DEFINE_UUID(0x00112233, 0x4455, 0x6677, 0x8899, 947 1.1 cherry * 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff) 948 1.1 cherry * will construct UUID 00112233-4455-6677-8899-aabbccddeeff presented as 949 1.1 cherry * {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 950 1.1 cherry * 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; 951 1.1 cherry * 952 1.1 cherry * NB: This is compatible with Linux kernel and with libuuid, but it is not 953 1.1 cherry * compatible with Microsoft, as they use mixed-endian encoding (some 954 1.1 cherry * components are little-endian, some are big-endian). 955 1.1 cherry */ 956 1.1 cherry #define XEN_DEFINE_UUID_(a, b, c, d, e1, e2, e3, e4, e5, e6) \ 957 1.1 cherry {{((a) >> 24) & 0xFF, ((a) >> 16) & 0xFF, \ 958 1.1 cherry ((a) >> 8) & 0xFF, ((a) >> 0) & 0xFF, \ 959 1.1 cherry ((b) >> 8) & 0xFF, ((b) >> 0) & 0xFF, \ 960 1.1 cherry ((c) >> 8) & 0xFF, ((c) >> 0) & 0xFF, \ 961 1.1 cherry ((d) >> 8) & 0xFF, ((d) >> 0) & 0xFF, \ 962 1.1 cherry e1, e2, e3, e4, e5, e6}} 963 1.1 cherry 964 1.1 cherry #if defined(__STDC_VERSION__) ? __STDC_VERSION__ >= 199901L : defined(__GNUC__) 965 1.1 cherry #define XEN_DEFINE_UUID(a, b, c, d, e1, e2, e3, e4, e5, e6) \ 966 1.1 cherry ((xen_uuid_t)XEN_DEFINE_UUID_(a, b, c, d, e1, e2, e3, e4, e5, e6)) 967 1.1 cherry #else 968 1.1 cherry #define XEN_DEFINE_UUID(a, b, c, d, e1, e2, e3, e4, e5, e6) \ 969 1.1 cherry XEN_DEFINE_UUID_(a, b, c, d, e1, e2, e3, e4, e5, e6) 970 1.1 cherry #endif /* __STDC_VERSION__ / __GNUC__ */ 971 1.1 cherry 972 1.1 cherry #endif /* !__ASSEMBLY__ */ 973 1.1 cherry 974 1.1 cherry /* Default definitions for macros used by domctl/sysctl. */ 975 1.1 cherry #if defined(__XEN__) || defined(__XEN_TOOLS__) 976 1.1 cherry 977 1.1 cherry #ifndef int64_aligned_t 978 1.1 cherry #define int64_aligned_t int64_t 979 1.1 cherry #endif 980 1.1 cherry #ifndef uint64_aligned_t 981 1.1 cherry #define uint64_aligned_t uint64_t 982 1.1 cherry #endif 983 1.1 cherry #ifndef XEN_GUEST_HANDLE_64 984 1.1 cherry #define XEN_GUEST_HANDLE_64(name) XEN_GUEST_HANDLE(name) 985 1.1 cherry #endif 986 1.1 cherry 987 1.1 cherry #ifndef __ASSEMBLY__ 988 1.1 cherry struct xenctl_bitmap { 989 1.1 cherry XEN_GUEST_HANDLE_64(uint8) bitmap; 990 1.1 cherry uint32_t nr_bits; 991 1.1 cherry }; 992 1.1 cherry #endif 993 1.1 cherry 994 1.1 cherry #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ 995 1.1 cherry 996 1.1 cherry #endif /* __XEN_PUBLIC_XEN_H__ */ 997 1.1 cherry 998 1.1 cherry /* 999 1.1 cherry * Local variables: 1000 1.1 cherry * mode: C 1001 1.1 cherry * c-file-style: "BSD" 1002 1.1 cherry * c-basic-offset: 4 1003 1.1 cherry * tab-width: 4 1004 1.1 cherry * indent-tabs-mode: nil 1005 1.1 cherry * End: 1006 1.1 cherry */ 1007