event_channel.h 12 KB

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