xen.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. /******************************************************************************
  2. * xen.h
  3. *
  4. * Guest OS interface to Xen.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to
  8. * deal in the Software without restriction, including without limitation the
  9. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  10. * sell copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. *
  24. * Copyright (c) 2004, K A Fraser
  25. */
  26. #ifndef __XEN_PUBLIC_XEN_H__
  27. #define __XEN_PUBLIC_XEN_H__
  28. #include <asm/xen/interface.h>
  29. /*
  30. * XEN "SYSTEM CALLS" (a.k.a. HYPERCALLS).
  31. */
  32. /*
  33. * x86_32: EAX = vector; EBX, ECX, EDX, ESI, EDI = args 1, 2, 3, 4, 5.
  34. * EAX = return value
  35. * (argument registers may be clobbered on return)
  36. * x86_64: RAX = vector; RDI, RSI, RDX, R10, R8, R9 = args 1, 2, 3, 4, 5, 6.
  37. * RAX = return value
  38. * (argument registers not clobbered on return; RCX, R11 are)
  39. */
  40. #define __HYPERVISOR_set_trap_table 0
  41. #define __HYPERVISOR_mmu_update 1
  42. #define __HYPERVISOR_set_gdt 2
  43. #define __HYPERVISOR_stack_switch 3
  44. #define __HYPERVISOR_set_callbacks 4
  45. #define __HYPERVISOR_fpu_taskswitch 5
  46. #define __HYPERVISOR_sched_op_compat 6
  47. #define __HYPERVISOR_platform_op 7
  48. #define __HYPERVISOR_set_debugreg 8
  49. #define __HYPERVISOR_get_debugreg 9
  50. #define __HYPERVISOR_update_descriptor 10
  51. #define __HYPERVISOR_memory_op 12
  52. #define __HYPERVISOR_multicall 13
  53. #define __HYPERVISOR_update_va_mapping 14
  54. #define __HYPERVISOR_set_timer_op 15
  55. #define __HYPERVISOR_event_channel_op_compat 16
  56. #define __HYPERVISOR_xen_version 17
  57. #define __HYPERVISOR_console_io 18
  58. #define __HYPERVISOR_physdev_op_compat 19
  59. #define __HYPERVISOR_grant_table_op 20
  60. #define __HYPERVISOR_vm_assist 21
  61. #define __HYPERVISOR_update_va_mapping_otherdomain 22
  62. #define __HYPERVISOR_iret 23 /* x86 only */
  63. #define __HYPERVISOR_vcpu_op 24
  64. #define __HYPERVISOR_set_segment_base 25 /* x86/64 only */
  65. #define __HYPERVISOR_mmuext_op 26
  66. #define __HYPERVISOR_xsm_op 27
  67. #define __HYPERVISOR_nmi_op 28
  68. #define __HYPERVISOR_sched_op 29
  69. #define __HYPERVISOR_callback_op 30
  70. #define __HYPERVISOR_xenoprof_op 31
  71. #define __HYPERVISOR_event_channel_op 32
  72. #define __HYPERVISOR_physdev_op 33
  73. #define __HYPERVISOR_hvm_op 34
  74. #define __HYPERVISOR_sysctl 35
  75. #define __HYPERVISOR_domctl 36
  76. #define __HYPERVISOR_kexec_op 37
  77. #define __HYPERVISOR_tmem_op 38
  78. #define __HYPERVISOR_xc_reserved_op 39 /* reserved for XenClient */
  79. #define __HYPERVISOR_xenpmu_op 40
  80. #define __HYPERVISOR_dm_op 41
  81. /* Architecture-specific hypercall definitions. */
  82. #define __HYPERVISOR_arch_0 48
  83. #define __HYPERVISOR_arch_1 49
  84. #define __HYPERVISOR_arch_2 50
  85. #define __HYPERVISOR_arch_3 51
  86. #define __HYPERVISOR_arch_4 52
  87. #define __HYPERVISOR_arch_5 53
  88. #define __HYPERVISOR_arch_6 54
  89. #define __HYPERVISOR_arch_7 55
  90. /*
  91. * VIRTUAL INTERRUPTS
  92. *
  93. * Virtual interrupts that a guest OS may receive from Xen.
  94. * In the side comments, 'V.' denotes a per-VCPU VIRQ while 'G.' denotes a
  95. * global VIRQ. The former can be bound once per VCPU and cannot be re-bound.
  96. * The latter can be allocated only once per guest: they must initially be
  97. * allocated to VCPU0 but can subsequently be re-bound.
  98. */
  99. #define VIRQ_TIMER 0 /* V. Timebase update, and/or requested timeout. */
  100. #define VIRQ_DEBUG 1 /* V. Request guest to dump debug info. */
  101. #define VIRQ_CONSOLE 2 /* G. (DOM0) Bytes received on emergency console. */
  102. #define VIRQ_DOM_EXC 3 /* G. (DOM0) Exceptional event for some domain. */
  103. #define VIRQ_TBUF 4 /* G. (DOM0) Trace buffer has records available. */
  104. #define VIRQ_DEBUGGER 6 /* G. (DOM0) A domain has paused for debugging. */
  105. #define VIRQ_XENOPROF 7 /* V. XenOprofile interrupt: new sample available */
  106. #define VIRQ_CON_RING 8 /* G. (DOM0) Bytes received on console */
  107. #define VIRQ_PCPU_STATE 9 /* G. (DOM0) PCPU state changed */
  108. #define VIRQ_MEM_EVENT 10 /* G. (DOM0) A memory event has occured */
  109. #define VIRQ_XC_RESERVED 11 /* G. Reserved for XenClient */
  110. #define VIRQ_ENOMEM 12 /* G. (DOM0) Low on heap memory */
  111. #define VIRQ_XENPMU 13 /* PMC interrupt */
  112. /* Architecture-specific VIRQ definitions. */
  113. #define VIRQ_ARCH_0 16
  114. #define VIRQ_ARCH_1 17
  115. #define VIRQ_ARCH_2 18
  116. #define VIRQ_ARCH_3 19
  117. #define VIRQ_ARCH_4 20
  118. #define VIRQ_ARCH_5 21
  119. #define VIRQ_ARCH_6 22
  120. #define VIRQ_ARCH_7 23
  121. #define NR_VIRQS 24
  122. /*
  123. * enum neg_errnoval HYPERVISOR_mmu_update(const struct mmu_update reqs[],
  124. * unsigned count, unsigned *done_out,
  125. * unsigned foreigndom)
  126. * @reqs is an array of mmu_update_t structures ((ptr, val) pairs).
  127. * @count is the length of the above array.
  128. * @pdone is an output parameter indicating number of completed operations
  129. * @foreigndom[15:0]: FD, the expected owner of data pages referenced in this
  130. * hypercall invocation. Can be DOMID_SELF.
  131. * @foreigndom[31:16]: PFD, the expected owner of pagetable pages referenced
  132. * in this hypercall invocation. The value of this field
  133. * (x) encodes the PFD as follows:
  134. * x == 0 => PFD == DOMID_SELF
  135. * x != 0 => PFD == x - 1
  136. *
  137. * Sub-commands: ptr[1:0] specifies the appropriate MMU_* command.
  138. * -------------
  139. * ptr[1:0] == MMU_NORMAL_PT_UPDATE:
  140. * Updates an entry in a page table belonging to PFD. If updating an L1 table,
  141. * and the new table entry is valid/present, the mapped frame must belong to
  142. * FD. If attempting to map an I/O page then the caller assumes the privilege
  143. * of the FD.
  144. * FD == DOMID_IO: Permit /only/ I/O mappings, at the priv level of the caller.
  145. * FD == DOMID_XEN: Map restricted areas of Xen's heap space.
  146. * ptr[:2] -- Machine address of the page-table entry to modify.
  147. * val -- Value to write.
  148. *
  149. * There also certain implicit requirements when using this hypercall. The
  150. * pages that make up a pagetable must be mapped read-only in the guest.
  151. * This prevents uncontrolled guest updates to the pagetable. Xen strictly
  152. * enforces this, and will disallow any pagetable update which will end up
  153. * mapping pagetable page RW, and will disallow using any writable page as a
  154. * pagetable. In practice it means that when constructing a page table for a
  155. * process, thread, etc, we MUST be very dilligient in following these rules:
  156. * 1). Start with top-level page (PGD or in Xen language: L4). Fill out
  157. * the entries.
  158. * 2). Keep on going, filling out the upper (PUD or L3), and middle (PMD
  159. * or L2).
  160. * 3). Start filling out the PTE table (L1) with the PTE entries. Once
  161. * done, make sure to set each of those entries to RO (so writeable bit
  162. * is unset). Once that has been completed, set the PMD (L2) for this
  163. * PTE table as RO.
  164. * 4). When completed with all of the PMD (L2) entries, and all of them have
  165. * been set to RO, make sure to set RO the PUD (L3). Do the same
  166. * operation on PGD (L4) pagetable entries that have a PUD (L3) entry.
  167. * 5). Now before you can use those pages (so setting the cr3), you MUST also
  168. * pin them so that the hypervisor can verify the entries. This is done
  169. * via the HYPERVISOR_mmuext_op(MMUEXT_PIN_L4_TABLE, guest physical frame
  170. * number of the PGD (L4)). And this point the HYPERVISOR_mmuext_op(
  171. * MMUEXT_NEW_BASEPTR, guest physical frame number of the PGD (L4)) can be
  172. * issued.
  173. * For 32-bit guests, the L4 is not used (as there is less pagetables), so
  174. * instead use L3.
  175. * At this point the pagetables can be modified using the MMU_NORMAL_PT_UPDATE
  176. * hypercall. Also if so desired the OS can also try to write to the PTE
  177. * and be trapped by the hypervisor (as the PTE entry is RO).
  178. *
  179. * To deallocate the pages, the operations are the reverse of the steps
  180. * mentioned above. The argument is MMUEXT_UNPIN_TABLE for all levels and the
  181. * pagetable MUST not be in use (meaning that the cr3 is not set to it).
  182. *
  183. * ptr[1:0] == MMU_MACHPHYS_UPDATE:
  184. * Updates an entry in the machine->pseudo-physical mapping table.
  185. * ptr[:2] -- Machine address within the frame whose mapping to modify.
  186. * The frame must belong to the FD, if one is specified.
  187. * val -- Value to write into the mapping entry.
  188. *
  189. * ptr[1:0] == MMU_PT_UPDATE_PRESERVE_AD:
  190. * As MMU_NORMAL_PT_UPDATE above, but A/D bits currently in the PTE are ORed
  191. * with those in @val.
  192. *
  193. * @val is usually the machine frame number along with some attributes.
  194. * The attributes by default follow the architecture defined bits. Meaning that
  195. * if this is a X86_64 machine and four page table layout is used, the layout
  196. * of val is:
  197. * - 63 if set means No execute (NX)
  198. * - 46-13 the machine frame number
  199. * - 12 available for guest
  200. * - 11 available for guest
  201. * - 10 available for guest
  202. * - 9 available for guest
  203. * - 8 global
  204. * - 7 PAT (PSE is disabled, must use hypercall to make 4MB or 2MB pages)
  205. * - 6 dirty
  206. * - 5 accessed
  207. * - 4 page cached disabled
  208. * - 3 page write through
  209. * - 2 userspace accessible
  210. * - 1 writeable
  211. * - 0 present
  212. *
  213. * The one bits that does not fit with the default layout is the PAGE_PSE
  214. * also called PAGE_PAT). The MMUEXT_[UN]MARK_SUPER arguments to the
  215. * HYPERVISOR_mmuext_op serve as mechanism to set a pagetable to be 4MB
  216. * (or 2MB) instead of using the PAGE_PSE bit.
  217. *
  218. * The reason that the PAGE_PSE (bit 7) is not being utilized is due to Xen
  219. * using it as the Page Attribute Table (PAT) bit - for details on it please
  220. * refer to Intel SDM 10.12. The PAT allows to set the caching attributes of
  221. * pages instead of using MTRRs.
  222. *
  223. * The PAT MSR is as follows (it is a 64-bit value, each entry is 8 bits):
  224. * PAT4 PAT0
  225. * +-----+-----+----+----+----+-----+----+----+
  226. * | UC | UC- | WC | WB | UC | UC- | WC | WB | <= Linux
  227. * +-----+-----+----+----+----+-----+----+----+
  228. * | UC | UC- | WT | WB | UC | UC- | WT | WB | <= BIOS (default when machine boots)
  229. * +-----+-----+----+----+----+-----+----+----+
  230. * | rsv | rsv | WP | WC | UC | UC- | WT | WB | <= Xen
  231. * +-----+-----+----+----+----+-----+----+----+
  232. *
  233. * The lookup of this index table translates to looking up
  234. * Bit 7, Bit 4, and Bit 3 of val entry:
  235. *
  236. * PAT/PSE (bit 7) ... PCD (bit 4) .. PWT (bit 3).
  237. *
  238. * If all bits are off, then we are using PAT0. If bit 3 turned on,
  239. * then we are using PAT1, if bit 3 and bit 4, then PAT2..
  240. *
  241. * As you can see, the Linux PAT1 translates to PAT4 under Xen. Which means
  242. * that if a guest that follows Linux's PAT setup and would like to set Write
  243. * Combined on pages it MUST use PAT4 entry. Meaning that Bit 7 (PAGE_PAT) is
  244. * set. For example, under Linux it only uses PAT0, PAT1, and PAT2 for the
  245. * caching as:
  246. *
  247. * WB = none (so PAT0)
  248. * WC = PWT (bit 3 on)
  249. * UC = PWT | PCD (bit 3 and 4 are on).
  250. *
  251. * To make it work with Xen, it needs to translate the WC bit as so:
  252. *
  253. * PWT (so bit 3 on) --> PAT (so bit 7 is on) and clear bit 3
  254. *
  255. * And to translate back it would:
  256. *
  257. * PAT (bit 7 on) --> PWT (bit 3 on) and clear bit 7.
  258. */
  259. #define MMU_NORMAL_PT_UPDATE 0 /* checked '*ptr = val'. ptr is MA. */
  260. #define MMU_MACHPHYS_UPDATE 1 /* ptr = MA of frame to modify entry for */
  261. #define MMU_PT_UPDATE_PRESERVE_AD 2 /* atomically: *ptr = val | (*ptr&(A|D)) */
  262. #define MMU_PT_UPDATE_NO_TRANSLATE 3 /* checked '*ptr = val'. ptr is MA. */
  263. /*
  264. * MMU EXTENDED OPERATIONS
  265. *
  266. * enum neg_errnoval HYPERVISOR_mmuext_op(mmuext_op_t uops[],
  267. * unsigned int count,
  268. * unsigned int *pdone,
  269. * unsigned int foreigndom)
  270. */
  271. /* HYPERVISOR_mmuext_op() accepts a list of mmuext_op structures.
  272. * A foreigndom (FD) can be specified (or DOMID_SELF for none).
  273. * Where the FD has some effect, it is described below.
  274. *
  275. * cmd: MMUEXT_(UN)PIN_*_TABLE
  276. * mfn: Machine frame number to be (un)pinned as a p.t. page.
  277. * The frame must belong to the FD, if one is specified.
  278. *
  279. * cmd: MMUEXT_NEW_BASEPTR
  280. * mfn: Machine frame number of new page-table base to install in MMU.
  281. *
  282. * cmd: MMUEXT_NEW_USER_BASEPTR [x86/64 only]
  283. * mfn: Machine frame number of new page-table base to install in MMU
  284. * when in user space.
  285. *
  286. * cmd: MMUEXT_TLB_FLUSH_LOCAL
  287. * No additional arguments. Flushes local TLB.
  288. *
  289. * cmd: MMUEXT_INVLPG_LOCAL
  290. * linear_addr: Linear address to be flushed from the local TLB.
  291. *
  292. * cmd: MMUEXT_TLB_FLUSH_MULTI
  293. * vcpumask: Pointer to bitmap of VCPUs to be flushed.
  294. *
  295. * cmd: MMUEXT_INVLPG_MULTI
  296. * linear_addr: Linear address to be flushed.
  297. * vcpumask: Pointer to bitmap of VCPUs to be flushed.
  298. *
  299. * cmd: MMUEXT_TLB_FLUSH_ALL
  300. * No additional arguments. Flushes all VCPUs' TLBs.
  301. *
  302. * cmd: MMUEXT_INVLPG_ALL
  303. * linear_addr: Linear address to be flushed from all VCPUs' TLBs.
  304. *
  305. * cmd: MMUEXT_FLUSH_CACHE
  306. * No additional arguments. Writes back and flushes cache contents.
  307. *
  308. * cmd: MMUEXT_FLUSH_CACHE_GLOBAL
  309. * No additional arguments. Writes back and flushes cache contents
  310. * on all CPUs in the system.
  311. *
  312. * cmd: MMUEXT_SET_LDT
  313. * linear_addr: Linear address of LDT base (NB. must be page-aligned).
  314. * nr_ents: Number of entries in LDT.
  315. *
  316. * cmd: MMUEXT_CLEAR_PAGE
  317. * mfn: Machine frame number to be cleared.
  318. *
  319. * cmd: MMUEXT_COPY_PAGE
  320. * mfn: Machine frame number of the destination page.
  321. * src_mfn: Machine frame number of the source page.
  322. *
  323. * cmd: MMUEXT_[UN]MARK_SUPER
  324. * mfn: Machine frame number of head of superpage to be [un]marked.
  325. */
  326. #define MMUEXT_PIN_L1_TABLE 0
  327. #define MMUEXT_PIN_L2_TABLE 1
  328. #define MMUEXT_PIN_L3_TABLE 2
  329. #define MMUEXT_PIN_L4_TABLE 3
  330. #define MMUEXT_UNPIN_TABLE 4
  331. #define MMUEXT_NEW_BASEPTR 5
  332. #define MMUEXT_TLB_FLUSH_LOCAL 6
  333. #define MMUEXT_INVLPG_LOCAL 7
  334. #define MMUEXT_TLB_FLUSH_MULTI 8
  335. #define MMUEXT_INVLPG_MULTI 9
  336. #define MMUEXT_TLB_FLUSH_ALL 10
  337. #define MMUEXT_INVLPG_ALL 11
  338. #define MMUEXT_FLUSH_CACHE 12
  339. #define MMUEXT_SET_LDT 13
  340. #define MMUEXT_NEW_USER_BASEPTR 15
  341. #define MMUEXT_CLEAR_PAGE 16
  342. #define MMUEXT_COPY_PAGE 17
  343. #define MMUEXT_FLUSH_CACHE_GLOBAL 18
  344. #define MMUEXT_MARK_SUPER 19
  345. #define MMUEXT_UNMARK_SUPER 20
  346. #ifndef __ASSEMBLY__
  347. struct mmuext_op {
  348. unsigned int cmd;
  349. union {
  350. /* [UN]PIN_TABLE, NEW_BASEPTR, NEW_USER_BASEPTR
  351. * CLEAR_PAGE, COPY_PAGE, [UN]MARK_SUPER */
  352. xen_pfn_t mfn;
  353. /* INVLPG_LOCAL, INVLPG_ALL, SET_LDT */
  354. unsigned long linear_addr;
  355. } arg1;
  356. union {
  357. /* SET_LDT */
  358. unsigned int nr_ents;
  359. /* TLB_FLUSH_MULTI, INVLPG_MULTI */
  360. void *vcpumask;
  361. /* COPY_PAGE */
  362. xen_pfn_t src_mfn;
  363. } arg2;
  364. };
  365. DEFINE_GUEST_HANDLE_STRUCT(mmuext_op);
  366. #endif
  367. /* These are passed as 'flags' to update_va_mapping. They can be ORed. */
  368. /* When specifying UVMF_MULTI, also OR in a pointer to a CPU bitmap. */
  369. /* UVMF_LOCAL is merely UVMF_MULTI with a NULL bitmap pointer. */
  370. #define UVMF_NONE (0UL<<0) /* No flushing at all. */
  371. #define UVMF_TLB_FLUSH (1UL<<0) /* Flush entire TLB(s). */
  372. #define UVMF_INVLPG (2UL<<0) /* Flush only one entry. */
  373. #define UVMF_FLUSHTYPE_MASK (3UL<<0)
  374. #define UVMF_MULTI (0UL<<2) /* Flush subset of TLBs. */
  375. #define UVMF_LOCAL (0UL<<2) /* Flush local TLB. */
  376. #define UVMF_ALL (1UL<<2) /* Flush all TLBs. */
  377. /*
  378. * Commands to HYPERVISOR_console_io().
  379. */
  380. #define CONSOLEIO_write 0
  381. #define CONSOLEIO_read 1
  382. /*
  383. * Commands to HYPERVISOR_vm_assist().
  384. */
  385. #define VMASST_CMD_enable 0
  386. #define VMASST_CMD_disable 1
  387. /* x86/32 guests: simulate full 4GB segment limits. */
  388. #define VMASST_TYPE_4gb_segments 0
  389. /* x86/32 guests: trap (vector 15) whenever above vmassist is used. */
  390. #define VMASST_TYPE_4gb_segments_notify 1
  391. /*
  392. * x86 guests: support writes to bottom-level PTEs.
  393. * NB1. Page-directory entries cannot be written.
  394. * NB2. Guest must continue to remove all writable mappings of PTEs.
  395. */
  396. #define VMASST_TYPE_writable_pagetables 2
  397. /* x86/PAE guests: support PDPTs above 4GB. */
  398. #define VMASST_TYPE_pae_extended_cr3 3
  399. /*
  400. * x86 guests: Sane behaviour for virtual iopl
  401. * - virtual iopl updated from do_iret() hypercalls.
  402. * - virtual iopl reported in bounce frames.
  403. * - guest kernels assumed to be level 0 for the purpose of iopl checks.
  404. */
  405. #define VMASST_TYPE_architectural_iopl 4
  406. /*
  407. * All guests: activate update indicator in vcpu_runstate_info
  408. * Enable setting the XEN_RUNSTATE_UPDATE flag in guest memory mapped
  409. * vcpu_runstate_info during updates of the runstate information.
  410. */
  411. #define VMASST_TYPE_runstate_update_flag 5
  412. #define MAX_VMASST_TYPE 5
  413. #ifndef __ASSEMBLY__
  414. typedef uint16_t domid_t;
  415. /* Domain ids >= DOMID_FIRST_RESERVED cannot be used for ordinary domains. */
  416. #define DOMID_FIRST_RESERVED (0x7FF0U)
  417. /* DOMID_SELF is used in certain contexts to refer to oneself. */
  418. #define DOMID_SELF (0x7FF0U)
  419. /*
  420. * DOMID_IO is used to restrict page-table updates to mapping I/O memory.
  421. * Although no Foreign Domain need be specified to map I/O pages, DOMID_IO
  422. * is useful to ensure that no mappings to the OS's own heap are accidentally
  423. * installed. (e.g., in Linux this could cause havoc as reference counts
  424. * aren't adjusted on the I/O-mapping code path).
  425. * This only makes sense in MMUEXT_SET_FOREIGNDOM, but in that context can
  426. * be specified by any calling domain.
  427. */
  428. #define DOMID_IO (0x7FF1U)
  429. /*
  430. * DOMID_XEN is used to allow privileged domains to map restricted parts of
  431. * Xen's heap space (e.g., the machine_to_phys table).
  432. * This only makes sense in MMUEXT_SET_FOREIGNDOM, and is only permitted if
  433. * the caller is privileged.
  434. */
  435. #define DOMID_XEN (0x7FF2U)
  436. /* DOMID_COW is used as the owner of sharable pages */
  437. #define DOMID_COW (0x7FF3U)
  438. /* DOMID_INVALID is used to identify pages with unknown owner. */
  439. #define DOMID_INVALID (0x7FF4U)
  440. /* Idle domain. */
  441. #define DOMID_IDLE (0x7FFFU)
  442. /*
  443. * Send an array of these to HYPERVISOR_mmu_update().
  444. * NB. The fields are natural pointer/address size for this architecture.
  445. */
  446. struct mmu_update {
  447. uint64_t ptr; /* Machine address of PTE. */
  448. uint64_t val; /* New contents of PTE. */
  449. };
  450. DEFINE_GUEST_HANDLE_STRUCT(mmu_update);
  451. /*
  452. * Send an array of these to HYPERVISOR_multicall().
  453. * NB. The fields are logically the natural register size for this
  454. * architecture. In cases where xen_ulong_t is larger than this then
  455. * any unused bits in the upper portion must be zero.
  456. */
  457. struct multicall_entry {
  458. xen_ulong_t op;
  459. xen_long_t result;
  460. xen_ulong_t args[6];
  461. };
  462. DEFINE_GUEST_HANDLE_STRUCT(multicall_entry);
  463. struct vcpu_time_info {
  464. /*
  465. * Updates to the following values are preceded and followed
  466. * by an increment of 'version'. The guest can therefore
  467. * detect updates by looking for changes to 'version'. If the
  468. * least-significant bit of the version number is set then an
  469. * update is in progress and the guest must wait to read a
  470. * consistent set of values. The correct way to interact with
  471. * the version number is similar to Linux's seqlock: see the
  472. * implementations of read_seqbegin/read_seqretry.
  473. */
  474. uint32_t version;
  475. uint32_t pad0;
  476. uint64_t tsc_timestamp; /* TSC at last update of time vals. */
  477. uint64_t system_time; /* Time, in nanosecs, since boot. */
  478. /*
  479. * Current system time:
  480. * system_time + ((tsc - tsc_timestamp) << tsc_shift) * tsc_to_system_mul
  481. * CPU frequency (Hz):
  482. * ((10^9 << 32) / tsc_to_system_mul) >> tsc_shift
  483. */
  484. uint32_t tsc_to_system_mul;
  485. int8_t tsc_shift;
  486. int8_t pad1[3];
  487. }; /* 32 bytes */
  488. struct vcpu_info {
  489. /*
  490. * 'evtchn_upcall_pending' is written non-zero by Xen to indicate
  491. * a pending notification for a particular VCPU. It is then cleared
  492. * by the guest OS /before/ checking for pending work, thus avoiding
  493. * a set-and-check race. Note that the mask is only accessed by Xen
  494. * on the CPU that is currently hosting the VCPU. This means that the
  495. * pending and mask flags can be updated by the guest without special
  496. * synchronisation (i.e., no need for the x86 LOCK prefix).
  497. * This may seem suboptimal because if the pending flag is set by
  498. * a different CPU then an IPI may be scheduled even when the mask
  499. * is set. However, note:
  500. * 1. The task of 'interrupt holdoff' is covered by the per-event-
  501. * channel mask bits. A 'noisy' event that is continually being
  502. * triggered can be masked at source at this very precise
  503. * granularity.
  504. * 2. The main purpose of the per-VCPU mask is therefore to restrict
  505. * reentrant execution: whether for concurrency control, or to
  506. * prevent unbounded stack usage. Whatever the purpose, we expect
  507. * that the mask will be asserted only for short periods at a time,
  508. * and so the likelihood of a 'spurious' IPI is suitably small.
  509. * The mask is read before making an event upcall to the guest: a
  510. * non-zero mask therefore guarantees that the VCPU will not receive
  511. * an upcall activation. The mask is cleared when the VCPU requests
  512. * to block: this avoids wakeup-waiting races.
  513. */
  514. uint8_t evtchn_upcall_pending;
  515. uint8_t evtchn_upcall_mask;
  516. xen_ulong_t evtchn_pending_sel;
  517. struct arch_vcpu_info arch;
  518. struct pvclock_vcpu_time_info time;
  519. }; /* 64 bytes (x86) */
  520. /*
  521. * Xen/kernel shared data -- pointer provided in start_info.
  522. * NB. We expect that this struct is smaller than a page.
  523. */
  524. struct shared_info {
  525. struct vcpu_info vcpu_info[MAX_VIRT_CPUS];
  526. /*
  527. * A domain can create "event channels" on which it can send and receive
  528. * asynchronous event notifications. There are three classes of event that
  529. * are delivered by this mechanism:
  530. * 1. Bi-directional inter- and intra-domain connections. Domains must
  531. * arrange out-of-band to set up a connection (usually by allocating
  532. * an unbound 'listener' port and avertising that via a storage service
  533. * such as xenstore).
  534. * 2. Physical interrupts. A domain with suitable hardware-access
  535. * privileges can bind an event-channel port to a physical interrupt
  536. * source.
  537. * 3. Virtual interrupts ('events'). A domain can bind an event-channel
  538. * port to a virtual interrupt source, such as the virtual-timer
  539. * device or the emergency console.
  540. *
  541. * Event channels are addressed by a "port index". Each channel is
  542. * associated with two bits of information:
  543. * 1. PENDING -- notifies the domain that there is a pending notification
  544. * to be processed. This bit is cleared by the guest.
  545. * 2. MASK -- if this bit is clear then a 0->1 transition of PENDING
  546. * will cause an asynchronous upcall to be scheduled. This bit is only
  547. * updated by the guest. It is read-only within Xen. If a channel
  548. * becomes pending while the channel is masked then the 'edge' is lost
  549. * (i.e., when the channel is unmasked, the guest must manually handle
  550. * pending notifications as no upcall will be scheduled by Xen).
  551. *
  552. * To expedite scanning of pending notifications, any 0->1 pending
  553. * transition on an unmasked channel causes a corresponding bit in a
  554. * per-vcpu selector word to be set. Each bit in the selector covers a
  555. * 'C long' in the PENDING bitfield array.
  556. */
  557. xen_ulong_t evtchn_pending[sizeof(xen_ulong_t) * 8];
  558. xen_ulong_t evtchn_mask[sizeof(xen_ulong_t) * 8];
  559. /*
  560. * Wallclock time: updated only by control software. Guests should base
  561. * their gettimeofday() syscall on this wallclock-base value.
  562. */
  563. struct pvclock_wall_clock wc;
  564. struct arch_shared_info arch;
  565. };
  566. /*
  567. * Start-of-day memory layout
  568. *
  569. * 1. The domain is started within contiguous virtual-memory region.
  570. * 2. The contiguous region begins and ends on an aligned 4MB boundary.
  571. * 3. This the order of bootstrap elements in the initial virtual region:
  572. * a. relocated kernel image
  573. * b. initial ram disk [mod_start, mod_len]
  574. * (may be omitted)
  575. * c. list of allocated page frames [mfn_list, nr_pages]
  576. * (unless relocated due to XEN_ELFNOTE_INIT_P2M)
  577. * d. start_info_t structure [register ESI (x86)]
  578. * in case of dom0 this page contains the console info, too
  579. * e. unless dom0: xenstore ring page
  580. * f. unless dom0: console ring page
  581. * g. bootstrap page tables [pt_base, CR3 (x86)]
  582. * h. bootstrap stack [register ESP (x86)]
  583. * 4. Bootstrap elements are packed together, but each is 4kB-aligned.
  584. * 5. The list of page frames forms a contiguous 'pseudo-physical' memory
  585. * layout for the domain. In particular, the bootstrap virtual-memory
  586. * region is a 1:1 mapping to the first section of the pseudo-physical map.
  587. * 6. All bootstrap elements are mapped read-writable for the guest OS. The
  588. * only exception is the bootstrap page table, which is mapped read-only.
  589. * 7. There is guaranteed to be at least 512kB padding after the final
  590. * bootstrap element. If necessary, the bootstrap virtual region is
  591. * extended by an extra 4MB to ensure this.
  592. */
  593. #define MAX_GUEST_CMDLINE 1024
  594. struct start_info {
  595. /* THE FOLLOWING ARE FILLED IN BOTH ON INITIAL BOOT AND ON RESUME. */
  596. char magic[32]; /* "xen-<version>-<platform>". */
  597. unsigned long nr_pages; /* Total pages allocated to this domain. */
  598. unsigned long shared_info; /* MACHINE address of shared info struct. */
  599. uint32_t flags; /* SIF_xxx flags. */
  600. xen_pfn_t store_mfn; /* MACHINE page number of shared page. */
  601. uint32_t store_evtchn; /* Event channel for store communication. */
  602. union {
  603. struct {
  604. xen_pfn_t mfn; /* MACHINE page number of console page. */
  605. uint32_t evtchn; /* Event channel for console page. */
  606. } domU;
  607. struct {
  608. uint32_t info_off; /* Offset of console_info struct. */
  609. uint32_t info_size; /* Size of console_info struct from start.*/
  610. } dom0;
  611. } console;
  612. /* THE FOLLOWING ARE ONLY FILLED IN ON INITIAL BOOT (NOT RESUME). */
  613. unsigned long pt_base; /* VIRTUAL address of page directory. */
  614. unsigned long nr_pt_frames; /* Number of bootstrap p.t. frames. */
  615. unsigned long mfn_list; /* VIRTUAL address of page-frame list. */
  616. unsigned long mod_start; /* VIRTUAL address of pre-loaded module. */
  617. unsigned long mod_len; /* Size (bytes) of pre-loaded module. */
  618. int8_t cmd_line[MAX_GUEST_CMDLINE];
  619. /* The pfn range here covers both page table and p->m table frames. */
  620. unsigned long first_p2m_pfn;/* 1st pfn forming initial P->M table. */
  621. unsigned long nr_p2m_frames;/* # of pfns forming initial P->M table. */
  622. };
  623. /* These flags are passed in the 'flags' field of start_info_t. */
  624. #define SIF_PRIVILEGED (1<<0) /* Is the domain privileged? */
  625. #define SIF_INITDOMAIN (1<<1) /* Is this the initial control domain? */
  626. #define SIF_MULTIBOOT_MOD (1<<2) /* Is mod_start a multiboot module? */
  627. #define SIF_MOD_START_PFN (1<<3) /* Is mod_start a PFN? */
  628. #define SIF_VIRT_P2M_4TOOLS (1<<4) /* Do Xen tools understand a virt. mapped */
  629. /* P->M making the 3 level tree obsolete? */
  630. #define SIF_PM_MASK (0xFF<<8) /* reserve 1 byte for xen-pm options */
  631. /*
  632. * A multiboot module is a package containing modules very similar to a
  633. * multiboot module array. The only differences are:
  634. * - the array of module descriptors is by convention simply at the beginning
  635. * of the multiboot module,
  636. * - addresses in the module descriptors are based on the beginning of the
  637. * multiboot module,
  638. * - the number of modules is determined by a termination descriptor that has
  639. * mod_start == 0.
  640. *
  641. * This permits to both build it statically and reference it in a configuration
  642. * file, and let the PV guest easily rebase the addresses to virtual addresses
  643. * and at the same time count the number of modules.
  644. */
  645. struct xen_multiboot_mod_list {
  646. /* Address of first byte of the module */
  647. uint32_t mod_start;
  648. /* Address of last byte of the module (inclusive) */
  649. uint32_t mod_end;
  650. /* Address of zero-terminated command line */
  651. uint32_t cmdline;
  652. /* Unused, must be zero */
  653. uint32_t pad;
  654. };
  655. /*
  656. * The console structure in start_info.console.dom0
  657. *
  658. * This structure includes a variety of information required to
  659. * have a working VGA/VESA console.
  660. */
  661. struct dom0_vga_console_info {
  662. uint8_t video_type;
  663. #define XEN_VGATYPE_TEXT_MODE_3 0x03
  664. #define XEN_VGATYPE_VESA_LFB 0x23
  665. #define XEN_VGATYPE_EFI_LFB 0x70
  666. union {
  667. struct {
  668. /* Font height, in pixels. */
  669. uint16_t font_height;
  670. /* Cursor location (column, row). */
  671. uint16_t cursor_x, cursor_y;
  672. /* Number of rows and columns (dimensions in characters). */
  673. uint16_t rows, columns;
  674. } text_mode_3;
  675. struct {
  676. /* Width and height, in pixels. */
  677. uint16_t width, height;
  678. /* Bytes per scan line. */
  679. uint16_t bytes_per_line;
  680. /* Bits per pixel. */
  681. uint16_t bits_per_pixel;
  682. /* LFB physical address, and size (in units of 64kB). */
  683. uint32_t lfb_base;
  684. uint32_t lfb_size;
  685. /* RGB mask offsets and sizes, as defined by VBE 1.2+ */
  686. uint8_t red_pos, red_size;
  687. uint8_t green_pos, green_size;
  688. uint8_t blue_pos, blue_size;
  689. uint8_t rsvd_pos, rsvd_size;
  690. /* VESA capabilities (offset 0xa, VESA command 0x4f00). */
  691. uint32_t gbl_caps;
  692. /* Mode attributes (offset 0x0, VESA command 0x4f01). */
  693. uint16_t mode_attrs;
  694. } vesa_lfb;
  695. } u;
  696. };
  697. typedef uint64_t cpumap_t;
  698. typedef uint8_t xen_domain_handle_t[16];
  699. /* Turn a plain number into a C unsigned long constant. */
  700. #define __mk_unsigned_long(x) x ## UL
  701. #define mk_unsigned_long(x) __mk_unsigned_long(x)
  702. #define TMEM_SPEC_VERSION 1
  703. struct tmem_op {
  704. uint32_t cmd;
  705. int32_t pool_id;
  706. union {
  707. struct { /* for cmd == TMEM_NEW_POOL */
  708. uint64_t uuid[2];
  709. uint32_t flags;
  710. } new;
  711. struct {
  712. uint64_t oid[3];
  713. uint32_t index;
  714. uint32_t tmem_offset;
  715. uint32_t pfn_offset;
  716. uint32_t len;
  717. GUEST_HANDLE(void) gmfn; /* guest machine page frame */
  718. } gen;
  719. } u;
  720. };
  721. DEFINE_GUEST_HANDLE(u64);
  722. #else /* __ASSEMBLY__ */
  723. /* In assembly code we cannot use C numeric constant suffixes. */
  724. #define mk_unsigned_long(x) x
  725. #endif /* !__ASSEMBLY__ */
  726. #endif /* __XEN_PUBLIC_XEN_H__ */