event_channel.h 13 KB

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