You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

event_channel.h 12KB

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