event_channel.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. /* SPDX-License-Identifier: MIT */
  2. /******************************************************************************
  3. * event_channel.h
  4. *
  5. * Event channels between domains.
  6. *
  7. * Copyright (c) 2003-2004, K A Fraser.
  8. */
  9. #ifndef __XEN_PUBLIC_EVENT_CHANNEL_H__
  10. #define __XEN_PUBLIC_EVENT_CHANNEL_H__
  11. #include "xen.h"
  12. /*
  13. * `incontents 150 evtchn Event Channels
  14. *
  15. * Event channels are the basic primitive provided by Xen for event
  16. * notifications. An event is the Xen equivalent of a hardware
  17. * interrupt. They essentially store one bit of information, the event
  18. * of interest is signalled by transitioning this bit from 0 to 1.
  19. *
  20. * Notifications are received by a guest via an upcall from Xen,
  21. * indicating when an event arrives (setting the bit). Further
  22. * notifications are masked until the bit is cleared again (therefore,
  23. * guests must check the value of the bit after re-enabling event
  24. * delivery to ensure no missed notifications).
  25. *
  26. * Event notifications can be masked by setting a flag; this is
  27. * equivalent to disabling interrupts and can be used to ensure
  28. * atomicity of certain operations in the guest kernel.
  29. *
  30. * Event channels are represented by the evtchn_* fields in
  31. * struct shared_info and struct vcpu_info.
  32. */
  33. /*
  34. * ` enum neg_errnoval
  35. * ` HYPERVISOR_event_channel_op(enum event_channel_op cmd, void *args)
  36. * `
  37. * @cmd == EVTCHNOP_* (event-channel operation).
  38. * @args == struct evtchn_* Operation-specific extra arguments (NULL if none).
  39. */
  40. /* ` enum event_channel_op { // EVTCHNOP_* => struct evtchn_* */
  41. #define EVTCHNOP_bind_interdomain 0
  42. #define EVTCHNOP_bind_virq 1
  43. #define EVTCHNOP_bind_pirq 2
  44. #define EVTCHNOP_close 3
  45. #define EVTCHNOP_send 4
  46. #define EVTCHNOP_status 5
  47. #define EVTCHNOP_alloc_unbound 6
  48. #define EVTCHNOP_bind_ipi 7
  49. #define EVTCHNOP_bind_vcpu 8
  50. #define EVTCHNOP_unmask 9
  51. #define EVTCHNOP_reset 10
  52. #define EVTCHNOP_init_control 11
  53. #define EVTCHNOP_expand_array 12
  54. #define EVTCHNOP_set_priority 13
  55. #ifdef __XEN__
  56. #define EVTCHNOP_reset_cont 14
  57. #endif
  58. /* ` } */
  59. typedef uint32_t evtchn_port_t;
  60. DEFINE_XEN_GUEST_HANDLE(evtchn_port_t);
  61. /*
  62. * EVTCHNOP_alloc_unbound: Allocate a port in domain <dom> and mark as
  63. * accepting interdomain bindings from domain <remote_dom>. A fresh port
  64. * is allocated in <dom> and returned as <port>.
  65. * NOTES:
  66. * 1. If the caller is unprivileged then <dom> must be DOMID_SELF.
  67. * 2. <remote_dom> may be DOMID_SELF, allowing loopback connections.
  68. */
  69. struct evtchn_alloc_unbound {
  70. /* IN parameters */
  71. domid_t dom, remote_dom;
  72. /* OUT parameters */
  73. evtchn_port_t port;
  74. };
  75. typedef struct evtchn_alloc_unbound evtchn_alloc_unbound_t;
  76. /*
  77. * EVTCHNOP_bind_interdomain: Construct an interdomain event channel between
  78. * the calling domain and <remote_dom>. <remote_dom,remote_port> must identify
  79. * a port that is unbound and marked as accepting bindings from the calling
  80. * domain. A fresh port is allocated in the calling domain and returned as
  81. * <local_port>.
  82. *
  83. * In case the peer domain has already tried to set our event channel
  84. * pending, before it was bound, EVTCHNOP_bind_interdomain always sets
  85. * the local event channel pending.
  86. *
  87. * The usual pattern of use, in the guest's upcall (or subsequent
  88. * handler) is as follows: (Re-enable the event channel for subsequent
  89. * signalling and then) check for the existence of whatever condition
  90. * is being waited for by other means, and take whatever action is
  91. * needed (if any).
  92. *
  93. * NOTES:
  94. * 1. <remote_dom> may be DOMID_SELF, allowing loopback connections.
  95. */
  96. struct evtchn_bind_interdomain {
  97. /* IN parameters. */
  98. domid_t remote_dom;
  99. evtchn_port_t remote_port;
  100. /* OUT parameters. */
  101. evtchn_port_t local_port;
  102. };
  103. typedef struct evtchn_bind_interdomain evtchn_bind_interdomain_t;
  104. /*
  105. * EVTCHNOP_bind_virq: Bind a local event channel to VIRQ <irq> on specified
  106. * vcpu.
  107. * NOTES:
  108. * 1. Virtual IRQs are classified as per-vcpu or global. See the VIRQ list
  109. * in xen.h for the classification of each VIRQ.
  110. * 2. Global VIRQs must be allocated on VCPU0 but can subsequently be
  111. * re-bound via EVTCHNOP_bind_vcpu.
  112. * 3. Per-vcpu VIRQs may be bound to at most one event channel per vcpu.
  113. * The allocated event channel is bound to the specified vcpu and the
  114. * binding cannot be changed.
  115. */
  116. struct evtchn_bind_virq {
  117. /* IN parameters. */
  118. uint32_t virq; /* enum virq */
  119. uint32_t vcpu;
  120. /* OUT parameters. */
  121. evtchn_port_t port;
  122. };
  123. typedef struct evtchn_bind_virq evtchn_bind_virq_t;
  124. /*
  125. * EVTCHNOP_bind_pirq: Bind a local event channel to a real IRQ (PIRQ <irq>).
  126. * NOTES:
  127. * 1. A physical IRQ may be bound to at most one event channel per domain.
  128. * 2. Only a sufficiently-privileged domain may bind to a physical IRQ.
  129. */
  130. struct evtchn_bind_pirq {
  131. /* IN parameters. */
  132. uint32_t pirq;
  133. #define BIND_PIRQ__WILL_SHARE 1
  134. uint32_t flags; /* BIND_PIRQ__* */
  135. /* OUT parameters. */
  136. evtchn_port_t port;
  137. };
  138. typedef struct evtchn_bind_pirq evtchn_bind_pirq_t;
  139. /*
  140. * EVTCHNOP_bind_ipi: Bind a local event channel to receive events.
  141. * NOTES:
  142. * 1. The allocated event channel is bound to the specified vcpu. The binding
  143. * may not be changed.
  144. */
  145. struct evtchn_bind_ipi {
  146. uint32_t vcpu;
  147. /* OUT parameters. */
  148. evtchn_port_t port;
  149. };
  150. typedef struct evtchn_bind_ipi evtchn_bind_ipi_t;
  151. /*
  152. * EVTCHNOP_close: Close a local event channel <port>. If the channel is
  153. * interdomain then the remote end is placed in the unbound state
  154. * (EVTCHNSTAT_unbound), awaiting a new connection.
  155. */
  156. struct evtchn_close {
  157. /* IN parameters. */
  158. evtchn_port_t port;
  159. };
  160. typedef struct evtchn_close evtchn_close_t;
  161. /*
  162. * EVTCHNOP_send: Send an event to the remote end of the channel whose local
  163. * endpoint is <port>.
  164. */
  165. struct evtchn_send {
  166. /* IN parameters. */
  167. evtchn_port_t port;
  168. };
  169. typedef struct evtchn_send evtchn_send_t;
  170. /*
  171. * EVTCHNOP_status: Get the current status of the communication channel which
  172. * has an endpoint at <dom, port>.
  173. * NOTES:
  174. * 1. <dom> may be specified as DOMID_SELF.
  175. * 2. Only a sufficiently-privileged domain may obtain the status of an event
  176. * channel for which <dom> is not DOMID_SELF.
  177. */
  178. struct evtchn_status {
  179. /* IN parameters */
  180. domid_t dom;
  181. evtchn_port_t port;
  182. /* OUT parameters */
  183. #define EVTCHNSTAT_closed 0 /* Channel is not in use. */
  184. #define EVTCHNSTAT_unbound 1 /* Channel is waiting interdom connection.*/
  185. #define EVTCHNSTAT_interdomain 2 /* Channel is connected to remote domain. */
  186. #define EVTCHNSTAT_pirq 3 /* Channel is bound to a phys IRQ line. */
  187. #define EVTCHNSTAT_virq 4 /* Channel is bound to a virtual IRQ line */
  188. #define EVTCHNSTAT_ipi 5 /* Channel is bound to a virtual IPI line */
  189. uint32_t status;
  190. uint32_t vcpu; /* VCPU to which this channel is bound. */
  191. union {
  192. struct {
  193. domid_t dom;
  194. } unbound; /* EVTCHNSTAT_unbound */
  195. struct {
  196. domid_t dom;
  197. evtchn_port_t port;
  198. } interdomain; /* EVTCHNSTAT_interdomain */
  199. uint32_t pirq; /* EVTCHNSTAT_pirq */
  200. uint32_t virq; /* EVTCHNSTAT_virq */
  201. } u;
  202. };
  203. typedef struct evtchn_status evtchn_status_t;
  204. /*
  205. * EVTCHNOP_bind_vcpu: Specify which vcpu a channel should notify when an
  206. * event is pending.
  207. * NOTES:
  208. * 1. IPI-bound channels always notify the vcpu specified at bind time.
  209. * This binding cannot be changed.
  210. * 2. Per-VCPU VIRQ channels always notify the vcpu specified at bind time.
  211. * This binding cannot be changed.
  212. * 3. All other channels notify vcpu0 by default. This default is set when
  213. * the channel is allocated (a port that is freed and subsequently reused
  214. * has its binding reset to vcpu0).
  215. */
  216. struct evtchn_bind_vcpu {
  217. /* IN parameters. */
  218. evtchn_port_t port;
  219. uint32_t vcpu;
  220. };
  221. typedef struct evtchn_bind_vcpu evtchn_bind_vcpu_t;
  222. /*
  223. * EVTCHNOP_unmask: Unmask the specified local event-channel port and deliver
  224. * a notification to the appropriate VCPU if an event is pending.
  225. */
  226. struct evtchn_unmask {
  227. /* IN parameters. */
  228. evtchn_port_t port;
  229. };
  230. typedef struct evtchn_unmask evtchn_unmask_t;
  231. /*
  232. * EVTCHNOP_reset: Close all event channels associated with specified domain.
  233. * NOTES:
  234. * 1. <dom> may be specified as DOMID_SELF.
  235. * 2. Only a sufficiently-privileged domain may specify other than DOMID_SELF.
  236. * 3. Destroys all control blocks and event array, resets event channel
  237. * operations to 2-level ABI if called with <dom> == DOMID_SELF and FIFO
  238. * ABI was used. Guests should not bind events during EVTCHNOP_reset call
  239. * as these events are likely to be lost.
  240. */
  241. struct evtchn_reset {
  242. /* IN parameters. */
  243. domid_t dom;
  244. };
  245. typedef struct evtchn_reset evtchn_reset_t;
  246. /*
  247. * EVTCHNOP_init_control: initialize the control block for the FIFO ABI.
  248. *
  249. * Note: any events that are currently pending will not be resent and
  250. * will be lost. Guests should call this before binding any event to
  251. * avoid losing any events.
  252. */
  253. struct evtchn_init_control {
  254. /* IN parameters. */
  255. uint64_t control_gfn;
  256. uint32_t offset;
  257. uint32_t vcpu;
  258. /* OUT parameters. */
  259. uint8_t link_bits;
  260. uint8_t _pad[7];
  261. };
  262. typedef struct evtchn_init_control evtchn_init_control_t;
  263. /*
  264. * EVTCHNOP_expand_array: add an additional page to the event array.
  265. */
  266. struct evtchn_expand_array {
  267. /* IN parameters. */
  268. uint64_t array_gfn;
  269. };
  270. typedef struct evtchn_expand_array evtchn_expand_array_t;
  271. /*
  272. * EVTCHNOP_set_priority: set the priority for an event channel.
  273. */
  274. struct evtchn_set_priority {
  275. /* IN parameters. */
  276. evtchn_port_t port;
  277. uint32_t priority;
  278. };
  279. typedef struct evtchn_set_priority evtchn_set_priority_t;
  280. /*
  281. * ` enum neg_errnoval
  282. * ` HYPERVISOR_event_channel_op_compat(struct evtchn_op *op)
  283. * `
  284. * Superceded by new event_channel_op() hypercall since 0x00030202.
  285. */
  286. struct evtchn_op {
  287. uint32_t cmd; /* enum event_channel_op */
  288. union {
  289. evtchn_alloc_unbound_t alloc_unbound;
  290. evtchn_bind_interdomain_t bind_interdomain;
  291. evtchn_bind_virq_t bind_virq;
  292. evtchn_bind_pirq_t bind_pirq;
  293. evtchn_bind_ipi_t bind_ipi;
  294. evtchn_close_t close;
  295. evtchn_send_t send;
  296. evtchn_status_t status;
  297. evtchn_bind_vcpu_t bind_vcpu;
  298. evtchn_unmask_t unmask;
  299. } u;
  300. };
  301. typedef struct evtchn_op evtchn_op_t;
  302. DEFINE_XEN_GUEST_HANDLE(evtchn_op_t);
  303. /*
  304. * 2-level ABI
  305. */
  306. #define EVTCHN_2L_NR_CHANNELS (sizeof(xen_ulong_t) * sizeof(xen_ulong_t) * 64)
  307. /*
  308. * FIFO ABI
  309. */
  310. /* Events may have priorities from 0 (highest) to 15 (lowest). */
  311. #define EVTCHN_FIFO_PRIORITY_MAX 0
  312. #define EVTCHN_FIFO_PRIORITY_DEFAULT 7
  313. #define EVTCHN_FIFO_PRIORITY_MIN 15
  314. #define EVTCHN_FIFO_MAX_QUEUES (EVTCHN_FIFO_PRIORITY_MIN + 1)
  315. typedef uint32_t event_word_t;
  316. #define EVTCHN_FIFO_PENDING 31
  317. #define EVTCHN_FIFO_MASKED 30
  318. #define EVTCHN_FIFO_LINKED 29
  319. #define EVTCHN_FIFO_BUSY 28
  320. #define EVTCHN_FIFO_LINK_BITS 17
  321. #define EVTCHN_FIFO_LINK_MASK ((1 << EVTCHN_FIFO_LINK_BITS) - 1)
  322. #define EVTCHN_FIFO_NR_CHANNELS (1 << EVTCHN_FIFO_LINK_BITS)
  323. struct evtchn_fifo_control_block {
  324. uint32_t ready;
  325. uint32_t _rsvd;
  326. uint32_t head[EVTCHN_FIFO_MAX_QUEUES];
  327. };
  328. typedef struct evtchn_fifo_control_block evtchn_fifo_control_block_t;
  329. #endif /* __XEN_PUBLIC_EVENT_CHANNEL_H__ */
  330. /*
  331. * Local variables:
  332. * mode: C
  333. * c-file-style: "BSD"
  334. * c-basic-offset: 4
  335. * tab-width: 4
  336. * indent-tabs-mode: nil
  337. * End:
  338. */