vcpu.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /* SPDX-License-Identifier: MIT */
  2. /******************************************************************************
  3. * vcpu.h
  4. *
  5. * VCPU initialisation, query, and hotplug.
  6. *
  7. * Copyright (c) 2005, Keir Fraser <keir@xensource.com>
  8. */
  9. #ifndef __XEN_PUBLIC_VCPU_H__
  10. #define __XEN_PUBLIC_VCPU_H__
  11. #include "xen.h"
  12. /*
  13. * Prototype for this hypercall is:
  14. * long vcpu_op(int cmd, unsigned int vcpuid, void *extra_args)
  15. * @cmd == VCPUOP_??? (VCPU operation).
  16. * @vcpuid == VCPU to operate on.
  17. * @extra_args == Operation-specific extra arguments (NULL if none).
  18. */
  19. /*
  20. * Initialise a VCPU. Each VCPU can be initialised only once. A
  21. * newly-initialised VCPU will not run until it is brought up by VCPUOP_up.
  22. *
  23. * @extra_arg == For PV or ARM guests this is a pointer to a vcpu_guest_context
  24. * structure containing the initial state for the VCPU. For x86
  25. * HVM based guests this is a pointer to a vcpu_hvm_context
  26. * structure.
  27. */
  28. #define VCPUOP_initialise 0
  29. /*
  30. * Bring up a VCPU. This makes the VCPU runnable. This operation will fail
  31. * if the VCPU has not been initialised (VCPUOP_initialise).
  32. */
  33. #define VCPUOP_up 1
  34. /*
  35. * Bring down a VCPU (i.e., make it non-runnable).
  36. * There are a few caveats that callers should observe:
  37. * 1. This operation may return, and VCPU_is_up may return false, before the
  38. * VCPU stops running (i.e., the command is asynchronous). It is a good
  39. * idea to ensure that the VCPU has entered a non-critical loop before
  40. * bringing it down. Alternatively, this operation is guaranteed
  41. * synchronous if invoked by the VCPU itself.
  42. * 2. After a VCPU is initialised, there is currently no way to drop all its
  43. * references to domain memory. Even a VCPU that is down still holds
  44. * memory references via its pagetable base pointer and GDT. It is good
  45. * practise to move a VCPU onto an 'idle' or default page table, LDT and
  46. * GDT before bringing it down.
  47. */
  48. #define VCPUOP_down 2
  49. /* Returns 1 if the given VCPU is up. */
  50. #define VCPUOP_is_up 3
  51. /*
  52. * Return information about the state and running time of a VCPU.
  53. * @extra_arg == pointer to vcpu_runstate_info structure.
  54. */
  55. #define VCPUOP_get_runstate_info 4
  56. struct vcpu_runstate_info {
  57. /* VCPU's current state (RUNSTATE_*). */
  58. int state;
  59. /* When was current state entered (system time, ns)? */
  60. uint64_t state_entry_time;
  61. /*
  62. * Update indicator set in state_entry_time:
  63. * When activated via VMASST_TYPE_runstate_update_flag, set during
  64. * updates in guest memory mapped copy of vcpu_runstate_info.
  65. */
  66. #define XEN_RUNSTATE_UPDATE (xen_mk_ullong(1) << 63)
  67. /*
  68. * Time spent in each RUNSTATE_* (ns). The sum of these times is
  69. * guaranteed not to drift from system time.
  70. */
  71. uint64_t time[4];
  72. };
  73. typedef struct vcpu_runstate_info vcpu_runstate_info_t;
  74. DEFINE_XEN_GUEST_HANDLE(vcpu_runstate_info_t);
  75. /* VCPU is currently running on a physical CPU. */
  76. #define RUNSTATE_running 0
  77. /* VCPU is runnable, but not currently scheduled on any physical CPU. */
  78. #define RUNSTATE_runnable 1
  79. /* VCPU is blocked (a.k.a. idle). It is therefore not runnable. */
  80. #define RUNSTATE_blocked 2
  81. /*
  82. * VCPU is not runnable, but it is not blocked.
  83. * This is a 'catch all' state for things like hotplug and pauses by the
  84. * system administrator (or for critical sections in the hypervisor).
  85. * RUNSTATE_blocked dominates this state (it is the preferred state).
  86. */
  87. #define RUNSTATE_offline 3
  88. /*
  89. * Register a shared memory area from which the guest may obtain its own
  90. * runstate information without needing to execute a hypercall.
  91. * Notes:
  92. * 1. The registered address may be virtual or physical or guest handle,
  93. * depending on the platform. Virtual address or guest handle should be
  94. * registered on x86 systems.
  95. * 2. Only one shared area may be registered per VCPU. The shared area is
  96. * updated by the hypervisor each time the VCPU is scheduled. Thus
  97. * runstate.state will always be RUNSTATE_running and
  98. * runstate.state_entry_time will indicate the system time at which the
  99. * VCPU was last scheduled to run.
  100. * @extra_arg == pointer to vcpu_register_runstate_memory_area structure.
  101. */
  102. #define VCPUOP_register_runstate_memory_area 5
  103. struct vcpu_register_runstate_memory_area {
  104. union {
  105. XEN_GUEST_HANDLE(vcpu_runstate_info_t) h;
  106. struct vcpu_runstate_info *v;
  107. uint64_t p;
  108. } addr;
  109. };
  110. typedef struct vcpu_register_runstate_memory_area vcpu_register_runstate_memory_area_t;
  111. DEFINE_XEN_GUEST_HANDLE(vcpu_register_runstate_memory_area_t);
  112. /*
  113. * Set or stop a VCPU's periodic timer. Every VCPU has one periodic timer
  114. * which can be set via these commands. Periods smaller than one millisecond
  115. * may not be supported.
  116. */
  117. #define VCPUOP_set_periodic_timer 6 /* arg == vcpu_set_periodic_timer_t */
  118. #define VCPUOP_stop_periodic_timer 7 /* arg == NULL */
  119. struct vcpu_set_periodic_timer {
  120. uint64_t period_ns;
  121. };
  122. typedef struct vcpu_set_periodic_timer vcpu_set_periodic_timer_t;
  123. DEFINE_XEN_GUEST_HANDLE(vcpu_set_periodic_timer_t);
  124. /*
  125. * Set or stop a VCPU's single-shot timer. Every VCPU has one single-shot
  126. * timer which can be set via these commands.
  127. */
  128. #define VCPUOP_set_singleshot_timer 8 /* arg == vcpu_set_singleshot_timer_t */
  129. #define VCPUOP_stop_singleshot_timer 9 /* arg == NULL */
  130. struct vcpu_set_singleshot_timer {
  131. uint64_t timeout_abs_ns; /* Absolute system time value in nanoseconds. */
  132. uint32_t flags; /* VCPU_SSHOTTMR_??? */
  133. };
  134. typedef struct vcpu_set_singleshot_timer vcpu_set_singleshot_timer_t;
  135. DEFINE_XEN_GUEST_HANDLE(vcpu_set_singleshot_timer_t);
  136. /* Flags to VCPUOP_set_singleshot_timer. */
  137. /* Require the timeout to be in the future (return -ETIME if it's passed). */
  138. #define _VCPU_SSHOTTMR_future (0)
  139. #define VCPU_SSHOTTMR_future (1U << _VCPU_SSHOTTMR_future)
  140. /*
  141. * Register a memory location in the guest address space for the
  142. * vcpu_info structure. This allows the guest to place the vcpu_info
  143. * structure in a convenient place, such as in a per-cpu data area.
  144. * The pointer need not be page aligned, but the structure must not
  145. * cross a page boundary.
  146. *
  147. * This may be called only once per vcpu.
  148. */
  149. #define VCPUOP_register_vcpu_info 10 /* arg == vcpu_register_vcpu_info_t */
  150. struct vcpu_register_vcpu_info {
  151. uint64_t mfn; /* mfn of page to place vcpu_info */
  152. uint32_t offset; /* offset within page */
  153. uint32_t rsvd; /* unused */
  154. };
  155. typedef struct vcpu_register_vcpu_info vcpu_register_vcpu_info_t;
  156. DEFINE_XEN_GUEST_HANDLE(vcpu_register_vcpu_info_t);
  157. /* Send an NMI to the specified VCPU. @extra_arg == NULL. */
  158. #define VCPUOP_send_nmi 11
  159. /*
  160. * Get the physical ID information for a pinned vcpu's underlying physical
  161. * processor. The physical ID informmation is architecture-specific.
  162. * On x86: id[31:0]=apic_id, id[63:32]=acpi_id.
  163. * This command returns -EINVAL if it is not a valid operation for this VCPU.
  164. */
  165. #define VCPUOP_get_physid 12 /* arg == vcpu_get_physid_t */
  166. struct vcpu_get_physid {
  167. uint64_t phys_id;
  168. };
  169. typedef struct vcpu_get_physid vcpu_get_physid_t;
  170. DEFINE_XEN_GUEST_HANDLE(vcpu_get_physid_t);
  171. #define xen_vcpu_physid_to_x86_apicid(physid) ((uint32_t)(physid))
  172. #define xen_vcpu_physid_to_x86_acpiid(physid) ((uint32_t)((physid) >> 32))
  173. /*
  174. * Register a memory location to get a secondary copy of the vcpu time
  175. * parameters. The master copy still exists as part of the vcpu shared
  176. * memory area, and this secondary copy is updated whenever the master copy
  177. * is updated (and using the same versioning scheme for synchronisation).
  178. *
  179. * The intent is that this copy may be mapped (RO) into userspace so
  180. * that usermode can compute system time using the time info and the
  181. * tsc. Usermode will see an array of vcpu_time_info structures, one
  182. * for each vcpu, and choose the right one by an existing mechanism
  183. * which allows it to get the current vcpu number (such as via a
  184. * segment limit). It can then apply the normal algorithm to compute
  185. * system time from the tsc.
  186. *
  187. * @extra_arg == pointer to vcpu_register_time_info_memory_area structure.
  188. */
  189. #define VCPUOP_register_vcpu_time_memory_area 13
  190. DEFINE_XEN_GUEST_HANDLE(vcpu_time_info_t);
  191. struct vcpu_register_time_memory_area {
  192. union {
  193. XEN_GUEST_HANDLE(vcpu_time_info_t) h;
  194. struct vcpu_time_info *v;
  195. uint64_t p;
  196. } addr;
  197. };
  198. typedef struct vcpu_register_time_memory_area vcpu_register_time_memory_area_t;
  199. DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
  200. #endif /* __XEN_PUBLIC_VCPU_H__ */
  201. /*
  202. * Local variables:
  203. * mode: C
  204. * c-file-style: "BSD"
  205. * c-basic-offset: 4
  206. * tab-width: 4
  207. * indent-tabs-mode: nil
  208. * End:
  209. */