You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xen.h 35KB

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