xen.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  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 <sys/types.h>
  29. #include "xen-compat.h"
  30. #if defined(__i386__) || defined(__x86_64__)
  31. #include "arch-x86/xen.h"
  32. #elif defined(__ia64__)
  33. #include "arch-ia64.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. DEFINE_XEN_GUEST_HANDLE(long);
  44. __DEFINE_XEN_GUEST_HANDLE(ulong, unsigned long);
  45. DEFINE_XEN_GUEST_HANDLE(void);
  46. DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);
  47. #endif
  48. /*
  49. * HYPERCALLS
  50. */
  51. #define __HYPERVISOR_set_trap_table 0
  52. #define __HYPERVISOR_mmu_update 1
  53. #define __HYPERVISOR_set_gdt 2
  54. #define __HYPERVISOR_stack_switch 3
  55. #define __HYPERVISOR_set_callbacks 4
  56. #define __HYPERVISOR_fpu_taskswitch 5
  57. #define __HYPERVISOR_sched_op_compat 6 /* compat since 0x00030101 */
  58. #define __HYPERVISOR_platform_op 7
  59. #define __HYPERVISOR_set_debugreg 8
  60. #define __HYPERVISOR_get_debugreg 9
  61. #define __HYPERVISOR_update_descriptor 10
  62. #define __HYPERVISOR_memory_op 12
  63. #define __HYPERVISOR_multicall 13
  64. #define __HYPERVISOR_update_va_mapping 14
  65. #define __HYPERVISOR_set_timer_op 15
  66. #define __HYPERVISOR_event_channel_op_compat 16 /* compat since 0x00030202 */
  67. #define __HYPERVISOR_xen_version 17
  68. #define __HYPERVISOR_console_io 18
  69. #define __HYPERVISOR_physdev_op_compat 19 /* compat since 0x00030202 */
  70. #define __HYPERVISOR_grant_table_op 20
  71. #define __HYPERVISOR_vm_assist 21
  72. #define __HYPERVISOR_update_va_mapping_otherdomain 22
  73. #define __HYPERVISOR_iret 23 /* x86 only */
  74. #define __HYPERVISOR_vcpu_op 24
  75. #define __HYPERVISOR_set_segment_base 25 /* x86/64 only */
  76. #define __HYPERVISOR_mmuext_op 26
  77. #define __HYPERVISOR_xsm_op 27
  78. #define __HYPERVISOR_nmi_op 28
  79. #define __HYPERVISOR_sched_op 29
  80. #define __HYPERVISOR_callback_op 30
  81. #define __HYPERVISOR_xenoprof_op 31
  82. #define __HYPERVISOR_event_channel_op 32
  83. #define __HYPERVISOR_physdev_op 33
  84. #define __HYPERVISOR_hvm_op 34
  85. #define __HYPERVISOR_sysctl 35
  86. #define __HYPERVISOR_domctl 36
  87. #define __HYPERVISOR_kexec_op 37
  88. /* Architecture-specific hypercall definitions. */
  89. #define __HYPERVISOR_arch_0 48
  90. #define __HYPERVISOR_arch_1 49
  91. #define __HYPERVISOR_arch_2 50
  92. #define __HYPERVISOR_arch_3 51
  93. #define __HYPERVISOR_arch_4 52
  94. #define __HYPERVISOR_arch_5 53
  95. #define __HYPERVISOR_arch_6 54
  96. #define __HYPERVISOR_arch_7 55
  97. /*
  98. * HYPERCALL COMPATIBILITY.
  99. */
  100. /* New sched_op hypercall introduced in 0x00030101. */
  101. #if __XEN_INTERFACE_VERSION__ < 0x00030101
  102. #undef __HYPERVISOR_sched_op
  103. #define __HYPERVISOR_sched_op __HYPERVISOR_sched_op_compat
  104. #endif
  105. /* New event-channel and physdev hypercalls introduced in 0x00030202. */
  106. #if __XEN_INTERFACE_VERSION__ < 0x00030202
  107. #undef __HYPERVISOR_event_channel_op
  108. #define __HYPERVISOR_event_channel_op __HYPERVISOR_event_channel_op_compat
  109. #undef __HYPERVISOR_physdev_op
  110. #define __HYPERVISOR_physdev_op __HYPERVISOR_physdev_op_compat
  111. #endif
  112. /* New platform_op hypercall introduced in 0x00030204. */
  113. #if __XEN_INTERFACE_VERSION__ < 0x00030204
  114. #define __HYPERVISOR_dom0_op __HYPERVISOR_platform_op
  115. #endif
  116. /*
  117. * VIRTUAL INTERRUPTS
  118. *
  119. * Virtual interrupts that a guest OS may receive from Xen.
  120. *
  121. * In the side comments, 'V.' denotes a per-VCPU VIRQ while 'G.' denotes a
  122. * global VIRQ. The former can be bound once per VCPU and cannot be re-bound.
  123. * The latter can be allocated only once per guest: they must initially be
  124. * allocated to VCPU0 but can subsequently be re-bound.
  125. */
  126. #define VIRQ_TIMER 0 /* V. Timebase update, and/or requested timeout. */
  127. #define VIRQ_DEBUG 1 /* V. Request guest to dump debug info. */
  128. #define VIRQ_CONSOLE 2 /* G. (DOM0) Bytes received on emergency console. */
  129. #define VIRQ_DOM_EXC 3 /* G. (DOM0) Exceptional event for some domain. */
  130. #define VIRQ_TBUF 4 /* G. (DOM0) Trace buffer has records available. */
  131. #define VIRQ_DEBUGGER 6 /* G. (DOM0) A domain has paused for debugging. */
  132. #define VIRQ_XENOPROF 7 /* V. XenOprofile interrupt: new sample available */
  133. #define VIRQ_CON_RING 8 /* G. (DOM0) Bytes received on console */
  134. /* Architecture-specific VIRQ definitions. */
  135. #define VIRQ_ARCH_0 16
  136. #define VIRQ_ARCH_1 17
  137. #define VIRQ_ARCH_2 18
  138. #define VIRQ_ARCH_3 19
  139. #define VIRQ_ARCH_4 20
  140. #define VIRQ_ARCH_5 21
  141. #define VIRQ_ARCH_6 22
  142. #define VIRQ_ARCH_7 23
  143. #define NR_VIRQS 24
  144. /*
  145. * MMU-UPDATE REQUESTS
  146. *
  147. * HYPERVISOR_mmu_update() accepts a list of (ptr, val) pairs.
  148. * A foreigndom (FD) can be specified (or DOMID_SELF for none).
  149. * Where the FD has some effect, it is described below.
  150. * ptr[1:0] specifies the appropriate MMU_* command.
  151. *
  152. * ptr[1:0] == MMU_NORMAL_PT_UPDATE:
  153. * Updates an entry in a page table. If updating an L1 table, and the new
  154. * table entry is valid/present, the mapped frame must belong to the FD, if
  155. * an FD has been specified. If attempting to map an I/O page then the
  156. * caller assumes the privilege of the FD.
  157. * FD == DOMID_IO: Permit /only/ I/O mappings, at the priv level of the caller.
  158. * FD == DOMID_XEN: Map restricted areas of Xen's heap space.
  159. * ptr[:2] -- Machine address of the page-table entry to modify.
  160. * val -- Value to write.
  161. *
  162. * ptr[1:0] == MMU_MACHPHYS_UPDATE:
  163. * Updates an entry in the machine->pseudo-physical mapping table.
  164. * ptr[:2] -- Machine address within the frame whose mapping to modify.
  165. * The frame must belong to the FD, if one is specified.
  166. * val -- Value to write into the mapping entry.
  167. *
  168. * ptr[1:0] == MMU_PT_UPDATE_PRESERVE_AD:
  169. * As MMU_NORMAL_PT_UPDATE above, but A/D bits currently in the PTE are ORed
  170. * with those in @val.
  171. */
  172. #define MMU_NORMAL_PT_UPDATE 0 /* checked '*ptr = val'. ptr is MA. */
  173. #define MMU_MACHPHYS_UPDATE 1 /* ptr = MA of frame to modify entry for */
  174. #define MMU_PT_UPDATE_PRESERVE_AD 2 /* atomically: *ptr = val | (*ptr&(A|D)) */
  175. /*
  176. * MMU EXTENDED OPERATIONS
  177. *
  178. * HYPERVISOR_mmuext_op() accepts a list of mmuext_op structures.
  179. * A foreigndom (FD) can be specified (or DOMID_SELF for none).
  180. * Where the FD has some effect, it is described below.
  181. *
  182. * cmd: MMUEXT_(UN)PIN_*_TABLE
  183. * mfn: Machine frame number to be (un)pinned as a p.t. page.
  184. * The frame must belong to the FD, if one is specified.
  185. *
  186. * cmd: MMUEXT_NEW_BASEPTR
  187. * mfn: Machine frame number of new page-table base to install in MMU.
  188. *
  189. * cmd: MMUEXT_NEW_USER_BASEPTR [x86/64 only]
  190. * mfn: Machine frame number of new page-table base to install in MMU
  191. * when in user space.
  192. *
  193. * cmd: MMUEXT_TLB_FLUSH_LOCAL
  194. * No additional arguments. Flushes local TLB.
  195. *
  196. * cmd: MMUEXT_INVLPG_LOCAL
  197. * linear_addr: Linear address to be flushed from the local TLB.
  198. *
  199. * cmd: MMUEXT_TLB_FLUSH_MULTI
  200. * vcpumask: Pointer to bitmap of VCPUs to be flushed.
  201. *
  202. * cmd: MMUEXT_INVLPG_MULTI
  203. * linear_addr: Linear address to be flushed.
  204. * vcpumask: Pointer to bitmap of VCPUs to be flushed.
  205. *
  206. * cmd: MMUEXT_TLB_FLUSH_ALL
  207. * No additional arguments. Flushes all VCPUs' TLBs.
  208. *
  209. * cmd: MMUEXT_INVLPG_ALL
  210. * linear_addr: Linear address to be flushed from all VCPUs' TLBs.
  211. *
  212. * cmd: MMUEXT_FLUSH_CACHE
  213. * No additional arguments. Writes back and flushes cache contents.
  214. *
  215. * cmd: MMUEXT_SET_LDT
  216. * linear_addr: Linear address of LDT base (NB. must be page-aligned).
  217. * nr_ents: Number of entries in LDT.
  218. *
  219. * cmd: MMUEXT_CLEAR_PAGE
  220. * mfn: Machine frame number to be cleared.
  221. *
  222. * cmd: MMUEXT_COPY_PAGE
  223. * mfn: Machine frame number of the destination page.
  224. * src_mfn: Machine frame number of the source page.
  225. */
  226. #define MMUEXT_PIN_L1_TABLE 0
  227. #define MMUEXT_PIN_L2_TABLE 1
  228. #define MMUEXT_PIN_L3_TABLE 2
  229. #define MMUEXT_PIN_L4_TABLE 3
  230. #define MMUEXT_UNPIN_TABLE 4
  231. #define MMUEXT_NEW_BASEPTR 5
  232. #define MMUEXT_TLB_FLUSH_LOCAL 6
  233. #define MMUEXT_INVLPG_LOCAL 7
  234. #define MMUEXT_TLB_FLUSH_MULTI 8
  235. #define MMUEXT_INVLPG_MULTI 9
  236. #define MMUEXT_TLB_FLUSH_ALL 10
  237. #define MMUEXT_INVLPG_ALL 11
  238. #define MMUEXT_FLUSH_CACHE 12
  239. #define MMUEXT_SET_LDT 13
  240. #define MMUEXT_NEW_USER_BASEPTR 15
  241. #define MMUEXT_CLEAR_PAGE 16
  242. #define MMUEXT_COPY_PAGE 17
  243. #ifndef __ASSEMBLY__
  244. struct mmuext_op {
  245. unsigned int cmd;
  246. union {
  247. /* [UN]PIN_TABLE, NEW_BASEPTR, NEW_USER_BASEPTR
  248. * CLEAR_PAGE, COPY_PAGE */
  249. xen_pfn_t mfn;
  250. /* INVLPG_LOCAL, INVLPG_ALL, SET_LDT */
  251. unsigned long linear_addr;
  252. } arg1;
  253. union {
  254. /* SET_LDT */
  255. unsigned int nr_ents;
  256. /* TLB_FLUSH_MULTI, INVLPG_MULTI */
  257. #if __XEN_INTERFACE_VERSION__ >= 0x00030205
  258. XEN_GUEST_HANDLE(void) vcpumask;
  259. #else
  260. void *vcpumask;
  261. #endif
  262. /* COPY_PAGE */
  263. xen_pfn_t src_mfn;
  264. } arg2;
  265. };
  266. typedef struct mmuext_op mmuext_op_t;
  267. DEFINE_XEN_GUEST_HANDLE(mmuext_op_t);
  268. #endif
  269. /* These are passed as 'flags' to update_va_mapping. They can be ORed. */
  270. /* When specifying UVMF_MULTI, also OR in a pointer to a CPU bitmap. */
  271. /* UVMF_LOCAL is merely UVMF_MULTI with a NULL bitmap pointer. */
  272. #define UVMF_NONE (0UL<<0) /* No flushing at all. */
  273. #define UVMF_TLB_FLUSH (1UL<<0) /* Flush entire TLB(s). */
  274. #define UVMF_INVLPG (2UL<<0) /* Flush only one entry. */
  275. #define UVMF_FLUSHTYPE_MASK (3UL<<0)
  276. #define UVMF_MULTI (0UL<<2) /* Flush subset of TLBs. */
  277. #define UVMF_LOCAL (0UL<<2) /* Flush local TLB. */
  278. #define UVMF_ALL (1UL<<2) /* Flush all TLBs. */
  279. /*
  280. * Commands to HYPERVISOR_console_io().
  281. */
  282. #define CONSOLEIO_write 0
  283. #define CONSOLEIO_read 1
  284. /*
  285. * Commands to HYPERVISOR_vm_assist().
  286. */
  287. #define VMASST_CMD_enable 0
  288. #define VMASST_CMD_disable 1
  289. /* x86/32 guests: simulate full 4GB segment limits. */
  290. #define VMASST_TYPE_4gb_segments 0
  291. /* x86/32 guests: trap (vector 15) whenever above vmassist is used. */
  292. #define VMASST_TYPE_4gb_segments_notify 1
  293. /*
  294. * x86 guests: support writes to bottom-level PTEs.
  295. * NB1. Page-directory entries cannot be written.
  296. * NB2. Guest must continue to remove all writable mappings of PTEs.
  297. */
  298. #define VMASST_TYPE_writable_pagetables 2
  299. /* x86/PAE guests: support PDPTs above 4GB. */
  300. #define VMASST_TYPE_pae_extended_cr3 3
  301. #define MAX_VMASST_TYPE 3
  302. #ifndef __ASSEMBLY__
  303. typedef uint16_t domid_t;
  304. /* Domain ids >= DOMID_FIRST_RESERVED cannot be used for ordinary domains. */
  305. #define DOMID_FIRST_RESERVED (0x7FF0U)
  306. /* DOMID_SELF is used in certain contexts to refer to oneself. */
  307. #define DOMID_SELF (0x7FF0U)
  308. /*
  309. * DOMID_IO is used to restrict page-table updates to mapping I/O memory.
  310. * Although no Foreign Domain need be specified to map I/O pages, DOMID_IO
  311. * is useful to ensure that no mappings to the OS's own heap are accidentally
  312. * installed. (e.g., in Linux this could cause havoc as reference counts
  313. * aren't adjusted on the I/O-mapping code path).
  314. * This only makes sense in MMUEXT_SET_FOREIGNDOM, but in that context can
  315. * be specified by any calling domain.
  316. */
  317. #define DOMID_IO (0x7FF1U)
  318. /*
  319. * DOMID_XEN is used to allow privileged domains to map restricted parts of
  320. * Xen's heap space (e.g., the machine_to_phys table).
  321. * This only makes sense in MMUEXT_SET_FOREIGNDOM, and is only permitted if
  322. * the caller is privileged.
  323. */
  324. #define DOMID_XEN (0x7FF2U)
  325. /*
  326. * Send an array of these to HYPERVISOR_mmu_update().
  327. * NB. The fields are natural pointer/address size for this architecture.
  328. */
  329. struct mmu_update {
  330. uint64_t ptr; /* Machine address of PTE. */
  331. uint64_t val; /* New contents of PTE. */
  332. };
  333. typedef struct mmu_update mmu_update_t;
  334. DEFINE_XEN_GUEST_HANDLE(mmu_update_t);
  335. /*
  336. * Send an array of these to HYPERVISOR_multicall().
  337. * NB. The fields are natural register size for this architecture.
  338. */
  339. struct multicall_entry {
  340. unsigned long op, result;
  341. unsigned long args[6];
  342. };
  343. typedef struct multicall_entry multicall_entry_t;
  344. DEFINE_XEN_GUEST_HANDLE(multicall_entry_t);
  345. /*
  346. * Event channel endpoints per domain:
  347. * 1024 if a long is 32 bits; 4096 if a long is 64 bits.
  348. */
  349. #define NR_EVENT_CHANNELS (sizeof(unsigned long) * sizeof(unsigned long) * 64)
  350. struct vcpu_time_info {
  351. /*
  352. * Updates to the following values are preceded and followed by an
  353. * increment of 'version'. The guest can therefore detect updates by
  354. * looking for changes to 'version'. If the least-significant bit of
  355. * the version number is set then an update is in progress and the guest
  356. * must wait to read a consistent set of values.
  357. * The correct way to interact with the version number is similar to
  358. * Linux's seqlock: see the implementations of read_seqbegin/read_seqretry.
  359. */
  360. uint32_t version;
  361. uint32_t pad0;
  362. uint64_t tsc_timestamp; /* TSC at last update of time vals. */
  363. uint64_t system_time; /* Time, in nanosecs, since boot. */
  364. /*
  365. * Current system time:
  366. * system_time +
  367. * ((((tsc - tsc_timestamp) << tsc_shift) * tsc_to_system_mul) >> 32)
  368. * CPU frequency (Hz):
  369. * ((10^9 << 32) / tsc_to_system_mul) >> tsc_shift
  370. */
  371. uint32_t tsc_to_system_mul;
  372. int8_t tsc_shift;
  373. int8_t pad1[3];
  374. }; /* 32 bytes */
  375. typedef struct vcpu_time_info vcpu_time_info_t;
  376. struct vcpu_info {
  377. /*
  378. * 'evtchn_upcall_pending' is written non-zero by Xen to indicate
  379. * a pending notification for a particular VCPU. It is then cleared
  380. * by the guest OS /before/ checking for pending work, thus avoiding
  381. * a set-and-check race. Note that the mask is only accessed by Xen
  382. * on the CPU that is currently hosting the VCPU. This means that the
  383. * pending and mask flags can be updated by the guest without special
  384. * synchronisation (i.e., no need for the x86 LOCK prefix).
  385. * This may seem suboptimal because if the pending flag is set by
  386. * a different CPU then an IPI may be scheduled even when the mask
  387. * is set. However, note:
  388. * 1. The task of 'interrupt holdoff' is covered by the per-event-
  389. * channel mask bits. A 'noisy' event that is continually being
  390. * triggered can be masked at source at this very precise
  391. * granularity.
  392. * 2. The main purpose of the per-VCPU mask is therefore to restrict
  393. * reentrant execution: whether for concurrency control, or to
  394. * prevent unbounded stack usage. Whatever the purpose, we expect
  395. * that the mask will be asserted only for short periods at a time,
  396. * and so the likelihood of a 'spurious' IPI is suitably small.
  397. * The mask is read before making an event upcall to the guest: a
  398. * non-zero mask therefore guarantees that the VCPU will not receive
  399. * an upcall activation. The mask is cleared when the VCPU requests
  400. * to block: this avoids wakeup-waiting races.
  401. */
  402. uint8_t evtchn_upcall_pending;
  403. uint8_t evtchn_upcall_mask;
  404. unsigned long evtchn_pending_sel;
  405. struct arch_vcpu_info arch;
  406. struct vcpu_time_info time;
  407. }; /* 64 bytes (x86) */
  408. #ifndef __XEN__
  409. typedef struct vcpu_info vcpu_info_t;
  410. #endif
  411. /*
  412. * Xen/kernel shared data -- pointer provided in start_info.
  413. *
  414. * This structure is defined to be both smaller than a page, and the
  415. * only data on the shared page, but may vary in actual size even within
  416. * compatible Xen versions; guests should not rely on the size
  417. * of this structure remaining constant.
  418. */
  419. struct shared_info {
  420. struct vcpu_info vcpu_info[MAX_VIRT_CPUS];
  421. /*
  422. * A domain can create "event channels" on which it can send and receive
  423. * asynchronous event notifications. There are three classes of event that
  424. * are delivered by this mechanism:
  425. * 1. Bi-directional inter- and intra-domain connections. Domains must
  426. * arrange out-of-band to set up a connection (usually by allocating
  427. * an unbound 'listener' port and avertising that via a storage service
  428. * such as xenstore).
  429. * 2. Physical interrupts. A domain with suitable hardware-access
  430. * privileges can bind an event-channel port to a physical interrupt
  431. * source.
  432. * 3. Virtual interrupts ('events'). A domain can bind an event-channel
  433. * port to a virtual interrupt source, such as the virtual-timer
  434. * device or the emergency console.
  435. *
  436. * Event channels are addressed by a "port index". Each channel is
  437. * associated with two bits of information:
  438. * 1. PENDING -- notifies the domain that there is a pending notification
  439. * to be processed. This bit is cleared by the guest.
  440. * 2. MASK -- if this bit is clear then a 0->1 transition of PENDING
  441. * will cause an asynchronous upcall to be scheduled. This bit is only
  442. * updated by the guest. It is read-only within Xen. If a channel
  443. * becomes pending while the channel is masked then the 'edge' is lost
  444. * (i.e., when the channel is unmasked, the guest must manually handle
  445. * pending notifications as no upcall will be scheduled by Xen).
  446. *
  447. * To expedite scanning of pending notifications, any 0->1 pending
  448. * transition on an unmasked channel causes a corresponding bit in a
  449. * per-vcpu selector word to be set. Each bit in the selector covers a
  450. * 'C long' in the PENDING bitfield array.
  451. */
  452. unsigned long evtchn_pending[sizeof(unsigned long) * 8];
  453. unsigned long evtchn_mask[sizeof(unsigned long) * 8];
  454. /*
  455. * Wallclock time: updated only by control software. Guests should base
  456. * their gettimeofday() syscall on this wallclock-base value.
  457. */
  458. uint32_t wc_version; /* Version counter: see vcpu_time_info_t. */
  459. uint32_t wc_sec; /* Secs 00:00:00 UTC, Jan 1, 1970. */
  460. uint32_t wc_nsec; /* Nsecs 00:00:00 UTC, Jan 1, 1970. */
  461. struct arch_shared_info arch;
  462. };
  463. #ifndef __XEN__
  464. typedef struct shared_info shared_info_t;
  465. #endif
  466. /*
  467. * Start-of-day memory layout:
  468. * 1. The domain is started within contiguous virtual-memory region.
  469. * 2. The contiguous region ends on an aligned 4MB boundary.
  470. * 3. This the order of bootstrap elements in the initial virtual region:
  471. * a. relocated kernel image
  472. * b. initial ram disk [mod_start, mod_len]
  473. * c. list of allocated page frames [mfn_list, nr_pages]
  474. * d. start_info_t structure [register ESI (x86)]
  475. * e. bootstrap page tables [pt_base, CR3 (x86)]
  476. * f. bootstrap stack [register ESP (x86)]
  477. * 4. Bootstrap elements are packed together, but each is 4kB-aligned.
  478. * 5. The initial ram disk may be omitted.
  479. * 6. The list of page frames forms a contiguous 'pseudo-physical' memory
  480. * layout for the domain. In particular, the bootstrap virtual-memory
  481. * region is a 1:1 mapping to the first section of the pseudo-physical map.
  482. * 7. All bootstrap elements are mapped read-writable for the guest OS. The
  483. * only exception is the bootstrap page table, which is mapped read-only.
  484. * 8. There is guaranteed to be at least 512kB padding after the final
  485. * bootstrap element. If necessary, the bootstrap virtual region is
  486. * extended by an extra 4MB to ensure this.
  487. */
  488. #define MAX_GUEST_CMDLINE 1024
  489. struct start_info {
  490. /* THE FOLLOWING ARE FILLED IN BOTH ON INITIAL BOOT AND ON RESUME. */
  491. char magic[32]; /* "xen-<version>-<platform>". */
  492. unsigned long nr_pages; /* Total pages allocated to this domain. */
  493. unsigned long shared_info; /* MACHINE address of shared info struct. */
  494. uint32_t flags; /* SIF_xxx flags. */
  495. xen_pfn_t store_mfn; /* MACHINE page number of shared page. */
  496. uint32_t store_evtchn; /* Event channel for store communication. */
  497. union {
  498. struct {
  499. xen_pfn_t mfn; /* MACHINE page number of console page. */
  500. uint32_t evtchn; /* Event channel for console page. */
  501. } domU;
  502. struct {
  503. uint32_t info_off; /* Offset of console_info struct. */
  504. uint32_t info_size; /* Size of console_info struct from start.*/
  505. } dom0;
  506. } console;
  507. /* THE FOLLOWING ARE ONLY FILLED IN ON INITIAL BOOT (NOT RESUME). */
  508. unsigned long pt_base; /* VIRTUAL address of page directory. */
  509. unsigned long nr_pt_frames; /* Number of bootstrap p.t. frames. */
  510. unsigned long mfn_list; /* VIRTUAL address of page-frame list. */
  511. unsigned long mod_start; /* VIRTUAL address of pre-loaded module. */
  512. unsigned long mod_len; /* Size (bytes) of pre-loaded module. */
  513. int8_t cmd_line[MAX_GUEST_CMDLINE];
  514. /* hackish, for multiboot compatibility */
  515. unsigned mods_count;
  516. };
  517. typedef struct start_info start_info_t;
  518. /* New console union for dom0 introduced in 0x00030203. */
  519. #if __XEN_INTERFACE_VERSION__ < 0x00030203
  520. #define console_mfn console.domU.mfn
  521. #define console_evtchn console.domU.evtchn
  522. #endif
  523. /* These flags are passed in the 'flags' field of start_info_t. */
  524. #define SIF_PRIVILEGED (1<<0) /* Is the domain privileged? */
  525. #define SIF_INITDOMAIN (1<<1) /* Is this the initial control domain? */
  526. #define SIF_MULTIBOOT_MOD (1<<2) /* Is this the initial control domain? */
  527. #define SIF_PM_MASK (0xFF<<8) /* reserve 1 byte for xen-pm options */
  528. typedef struct dom0_vga_console_info {
  529. uint8_t video_type; /* DOM0_VGA_CONSOLE_??? */
  530. #define XEN_VGATYPE_TEXT_MODE_3 0x03
  531. #define XEN_VGATYPE_VESA_LFB 0x23
  532. union {
  533. struct {
  534. /* Font height, in pixels. */
  535. uint16_t font_height;
  536. /* Cursor location (column, row). */
  537. uint16_t cursor_x, cursor_y;
  538. /* Number of rows and columns (dimensions in characters). */
  539. uint16_t rows, columns;
  540. } text_mode_3;
  541. struct {
  542. /* Width and height, in pixels. */
  543. uint16_t width, height;
  544. /* Bytes per scan line. */
  545. uint16_t bytes_per_line;
  546. /* Bits per pixel. */
  547. uint16_t bits_per_pixel;
  548. /* LFB physical address, and size (in units of 64kB). */
  549. uint32_t lfb_base;
  550. uint32_t lfb_size;
  551. /* RGB mask offsets and sizes, as defined by VBE 1.2+ */
  552. uint8_t red_pos, red_size;
  553. uint8_t green_pos, green_size;
  554. uint8_t blue_pos, blue_size;
  555. uint8_t rsvd_pos, rsvd_size;
  556. #if __XEN_INTERFACE_VERSION__ >= 0x00030206
  557. /* VESA capabilities (offset 0xa, VESA command 0x4f00). */
  558. uint32_t gbl_caps;
  559. /* Mode attributes (offset 0x0, VESA command 0x4f01). */
  560. uint16_t mode_attrs;
  561. #endif
  562. } vesa_lfb;
  563. } u;
  564. } dom0_vga_console_info_t;
  565. #define xen_vga_console_info dom0_vga_console_info
  566. #define xen_vga_console_info_t dom0_vga_console_info_t
  567. typedef uint8_t xen_domain_handle_t[16];
  568. /* Turn a plain number into a C unsigned long constant. */
  569. #define __mk_unsigned_long(x) x ## UL
  570. #define mk_unsigned_long(x) __mk_unsigned_long(x)
  571. __DEFINE_XEN_GUEST_HANDLE(uint8, uint8_t);
  572. __DEFINE_XEN_GUEST_HANDLE(uint16, uint16_t);
  573. __DEFINE_XEN_GUEST_HANDLE(uint32, uint32_t);
  574. __DEFINE_XEN_GUEST_HANDLE(uint64, uint64_t);
  575. #else /* __ASSEMBLY__ */
  576. /* In assembly code we cannot use C numeric constant suffixes. */
  577. #define mk_unsigned_long(x) x
  578. #endif /* !__ASSEMBLY__ */
  579. /* Default definitions for macros used by domctl/sysctl. */
  580. #if defined(__XEN__) || defined(__XEN_TOOLS__)
  581. #ifndef uint64_aligned_t
  582. #define uint64_aligned_t uint64_t
  583. #endif
  584. #ifndef XEN_GUEST_HANDLE_64
  585. #define XEN_GUEST_HANDLE_64(name) XEN_GUEST_HANDLE(name)
  586. #endif
  587. #endif
  588. #endif /* __XEN_PUBLIC_XEN_H__ */
  589. /*
  590. * Local variables:
  591. * mode: C
  592. * c-set-style: "BSD"
  593. * c-basic-offset: 4
  594. * tab-width: 4
  595. * indent-tabs-mode: nil
  596. * End:
  597. */