xen.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* SPDX-License-Identifier: MIT
  2. *
  3. * xen.h
  4. *
  5. * Guest OS interface to Xen.
  6. *
  7. * Copyright (c) 2004, K A Fraser
  8. */
  9. #ifndef __XEN_PUBLIC_XEN_H__
  10. #define __XEN_PUBLIC_XEN_H__
  11. #include <xen/arm/interface.h>
  12. /*
  13. * XEN "SYSTEM CALLS" (a.k.a. HYPERCALLS).
  14. */
  15. /*
  16. * x86_32: EAX = vector; EBX, ECX, EDX, ESI, EDI = args 1, 2, 3, 4, 5.
  17. * EAX = return value
  18. * (argument registers may be clobbered on return)
  19. * x86_64: RAX = vector; RDI, RSI, RDX, R10, R8, R9 = args 1, 2, 3, 4, 5, 6.
  20. * RAX = return value
  21. * (argument registers not clobbered on return; RCX, R11 are)
  22. */
  23. #define __HYPERVISOR_set_trap_table 0
  24. #define __HYPERVISOR_mmu_update 1
  25. #define __HYPERVISOR_set_gdt 2
  26. #define __HYPERVISOR_stack_switch 3
  27. #define __HYPERVISOR_set_callbacks 4
  28. #define __HYPERVISOR_fpu_taskswitch 5
  29. #define __HYPERVISOR_sched_op_compat 6
  30. #define __HYPERVISOR_platform_op 7
  31. #define __HYPERVISOR_set_debugreg 8
  32. #define __HYPERVISOR_get_debugreg 9
  33. #define __HYPERVISOR_update_descriptor 10
  34. #define __HYPERVISOR_memory_op 12
  35. #define __HYPERVISOR_multicall 13
  36. #define __HYPERVISOR_update_va_mapping 14
  37. #define __HYPERVISOR_set_timer_op 15
  38. #define __HYPERVISOR_event_channel_op_compat 16
  39. #define __HYPERVISOR_xen_version 17
  40. #define __HYPERVISOR_console_io 18
  41. #define __HYPERVISOR_physdev_op_compat 19
  42. #define __HYPERVISOR_grant_table_op 20
  43. #define __HYPERVISOR_vm_assist 21
  44. #define __HYPERVISOR_update_va_mapping_otherdomain 22
  45. #define __HYPERVISOR_iret 23 /* x86 only */
  46. #define __HYPERVISOR_vcpu_op 24
  47. #define __HYPERVISOR_set_segment_base 25 /* x86/64 only */
  48. #define __HYPERVISOR_mmuext_op 26
  49. #define __HYPERVISOR_xsm_op 27
  50. #define __HYPERVISOR_nmi_op 28
  51. #define __HYPERVISOR_sched_op 29
  52. #define __HYPERVISOR_callback_op 30
  53. #define __HYPERVISOR_xenoprof_op 31
  54. #define __HYPERVISOR_event_channel_op 32
  55. #define __HYPERVISOR_physdev_op 33
  56. #define __HYPERVISOR_hvm_op 34
  57. #define __HYPERVISOR_sysctl 35
  58. #define __HYPERVISOR_domctl 36
  59. #define __HYPERVISOR_kexec_op 37
  60. #define __HYPERVISOR_tmem_op 38
  61. #define __HYPERVISOR_xc_reserved_op 39 /* reserved for XenClient */
  62. #define __HYPERVISOR_xenpmu_op 40
  63. #define __HYPERVISOR_dm_op 41
  64. /* Architecture-specific hypercall definitions. */
  65. #define __HYPERVISOR_arch_0 48
  66. #define __HYPERVISOR_arch_1 49
  67. #define __HYPERVISOR_arch_2 50
  68. #define __HYPERVISOR_arch_3 51
  69. #define __HYPERVISOR_arch_4 52
  70. #define __HYPERVISOR_arch_5 53
  71. #define __HYPERVISOR_arch_6 54
  72. #define __HYPERVISOR_arch_7 55
  73. #ifndef __ASSEMBLY__
  74. typedef u16 domid_t;
  75. /* Domain ids >= DOMID_FIRST_RESERVED cannot be used for ordinary domains. */
  76. #define DOMID_FIRST_RESERVED (0x7FF0U)
  77. /* DOMID_SELF is used in certain contexts to refer to oneself. */
  78. #define DOMID_SELF (0x7FF0U)
  79. /*
  80. * DOMID_IO is used to restrict page-table updates to mapping I/O memory.
  81. * Although no Foreign Domain need be specified to map I/O pages, DOMID_IO
  82. * is useful to ensure that no mappings to the OS's own heap are accidentally
  83. * installed. (e.g., in Linux this could cause havoc as reference counts
  84. * aren't adjusted on the I/O-mapping code path).
  85. * This only makes sense in MMUEXT_SET_FOREIGNDOM, but in that context can
  86. * be specified by any calling domain.
  87. */
  88. #define DOMID_IO (0x7FF1U)
  89. /*
  90. * DOMID_XEN is used to allow privileged domains to map restricted parts of
  91. * Xen's heap space (e.g., the machine_to_phys table).
  92. * This only makes sense in MMUEXT_SET_FOREIGNDOM, and is only permitted if
  93. * the caller is privileged.
  94. */
  95. #define DOMID_XEN (0x7FF2U)
  96. /* DOMID_COW is used as the owner of sharable pages */
  97. #define DOMID_COW (0x7FF3U)
  98. /* DOMID_INVALID is used to identify pages with unknown owner. */
  99. #define DOMID_INVALID (0x7FF4U)
  100. /* Idle domain. */
  101. #define DOMID_IDLE (0x7FFFU)
  102. struct vcpu_info {
  103. /*
  104. * 'evtchn_upcall_pending' is written non-zero by Xen to indicate
  105. * a pending notification for a particular VCPU. It is then cleared
  106. * by the guest OS /before/ checking for pending work, thus avoiding
  107. * a set-and-check race. Note that the mask is only accessed by Xen
  108. * on the CPU that is currently hosting the VCPU. This means that the
  109. * pending and mask flags can be updated by the guest without special
  110. * synchronisation (i.e., no need for the x86 LOCK prefix).
  111. * This may seem suboptimal because if the pending flag is set by
  112. * a different CPU then an IPI may be scheduled even when the mask
  113. * is set. However, note:
  114. * 1. The task of 'interrupt holdoff' is covered by the per-event-
  115. * channel mask bits. A 'noisy' event that is continually being
  116. * triggered can be masked at source at this very precise
  117. * granularity.
  118. * 2. The main purpose of the per-VCPU mask is therefore to restrict
  119. * reentrant execution: whether for concurrency control, or to
  120. * prevent unbounded stack usage. Whatever the purpose, we expect
  121. * that the mask will be asserted only for short periods at a time,
  122. * and so the likelihood of a 'spurious' IPI is suitably small.
  123. * The mask is read before making an event upcall to the guest: a
  124. * non-zero mask therefore guarantees that the VCPU will not receive
  125. * an upcall activation. The mask is cleared when the VCPU requests
  126. * to block: this avoids wakeup-waiting races.
  127. */
  128. u8 evtchn_upcall_pending;
  129. u8 evtchn_upcall_mask;
  130. xen_ulong_t evtchn_pending_sel;
  131. struct arch_vcpu_info arch;
  132. struct pvclock_vcpu_time_info time;
  133. }; /* 64 bytes (x86) */
  134. /*
  135. * Xen/kernel shared data -- pointer provided in start_info.
  136. * NB. We expect that this struct is smaller than a page.
  137. */
  138. struct shared_info {
  139. struct vcpu_info vcpu_info[MAX_VIRT_CPUS];
  140. /*
  141. * A domain can create "event channels" on which it can send and receive
  142. * asynchronous event notifications. There are three classes of event that
  143. * are delivered by this mechanism:
  144. * 1. Bi-directional inter- and intra-domain connections. Domains must
  145. * arrange out-of-band to set up a connection (usually by allocating
  146. * an unbound 'listener' port and avertising that via a storage service
  147. * such as xenstore).
  148. * 2. Physical interrupts. A domain with suitable hardware-access
  149. * privileges can bind an event-channel port to a physical interrupt
  150. * source.
  151. * 3. Virtual interrupts ('events'). A domain can bind an event-channel
  152. * port to a virtual interrupt source, such as the virtual-timer
  153. * device or the emergency console.
  154. *
  155. * Event channels are addressed by a "port index". Each channel is
  156. * associated with two bits of information:
  157. * 1. PENDING -- notifies the domain that there is a pending notification
  158. * to be processed. This bit is cleared by the guest.
  159. * 2. MASK -- if this bit is clear then a 0->1 transition of PENDING
  160. * will cause an asynchronous upcall to be scheduled. This bit is only
  161. * updated by the guest. It is read-only within Xen. If a channel
  162. * becomes pending while the channel is masked then the 'edge' is lost
  163. * (i.e., when the channel is unmasked, the guest must manually handle
  164. * pending notifications as no upcall will be scheduled by Xen).
  165. *
  166. * To expedite scanning of pending notifications, any 0->1 pending
  167. * transition on an unmasked channel causes a corresponding bit in a
  168. * per-vcpu selector word to be set. Each bit in the selector covers a
  169. * 'C long' in the PENDING bitfield array.
  170. */
  171. xen_ulong_t evtchn_pending[sizeof(xen_ulong_t) * 8];
  172. xen_ulong_t evtchn_mask[sizeof(xen_ulong_t) * 8];
  173. /*
  174. * Wallclock time: updated only by control software. Guests should base
  175. * their gettimeofday() syscall on this wallclock-base value.
  176. */
  177. struct pvclock_wall_clock wc;
  178. struct arch_shared_info arch;
  179. };
  180. #else /* __ASSEMBLY__ */
  181. /* In assembly code we cannot use C numeric constant suffixes. */
  182. #define mk_unsigned_long(x) x
  183. #endif /* !__ASSEMBLY__ */
  184. #endif /* __XEN_PUBLIC_XEN_H__ */