event_channel.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /* SPDX-License-Identifier: GPL-2.0 */
  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/interface/xen.h>
  12. typedef uint32_t evtchn_port_t;
  13. DEFINE_GUEST_HANDLE(evtchn_port_t);
  14. /*
  15. * EVTCHNOP_alloc_unbound: Allocate a port in domain <dom> and mark as
  16. * accepting interdomain bindings from domain <remote_dom>. A fresh port
  17. * is allocated in <dom> and returned as <port>.
  18. * NOTES:
  19. * 1. If the caller is unprivileged then <dom> must be DOMID_SELF.
  20. * 2. <rdom> may be DOMID_SELF, allowing loopback connections.
  21. */
  22. #define EVTCHNOP_alloc_unbound 6
  23. struct evtchn_alloc_unbound {
  24. /* IN parameters */
  25. domid_t dom, remote_dom;
  26. /* OUT parameters */
  27. evtchn_port_t port;
  28. };
  29. /*
  30. * EVTCHNOP_bind_interdomain: Construct an interdomain event channel between
  31. * the calling domain and <remote_dom>. <remote_dom,remote_port> must identify
  32. * a port that is unbound and marked as accepting bindings from the calling
  33. * domain. A fresh port is allocated in the calling domain and returned as
  34. * <local_port>.
  35. * NOTES:
  36. * 2. <remote_dom> may be DOMID_SELF, allowing loopback connections.
  37. */
  38. #define EVTCHNOP_bind_interdomain 0
  39. struct evtchn_bind_interdomain {
  40. /* IN parameters. */
  41. domid_t remote_dom;
  42. evtchn_port_t remote_port;
  43. /* OUT parameters. */
  44. evtchn_port_t local_port;
  45. };
  46. /*
  47. * EVTCHNOP_bind_virq: Bind a local event channel to VIRQ <irq> on specified
  48. * vcpu.
  49. * NOTES:
  50. * 1. A virtual IRQ may be bound to at most one event channel per vcpu.
  51. * 2. The allocated event channel is bound to the specified vcpu. The binding
  52. * may not be changed.
  53. */
  54. #define EVTCHNOP_bind_virq 1
  55. struct evtchn_bind_virq {
  56. /* IN parameters. */
  57. uint32_t virq;
  58. uint32_t vcpu;
  59. /* OUT parameters. */
  60. evtchn_port_t port;
  61. };
  62. /*
  63. * EVTCHNOP_bind_pirq: Bind a local event channel to PIRQ <irq>.
  64. * NOTES:
  65. * 1. A physical IRQ may be bound to at most one event channel per domain.
  66. * 2. Only a sufficiently-privileged domain may bind to a physical IRQ.
  67. */
  68. #define EVTCHNOP_bind_pirq 2
  69. struct evtchn_bind_pirq {
  70. /* IN parameters. */
  71. uint32_t pirq;
  72. #define BIND_PIRQ__WILL_SHARE 1
  73. uint32_t flags; /* BIND_PIRQ__* */
  74. /* OUT parameters. */
  75. evtchn_port_t port;
  76. };
  77. /*
  78. * EVTCHNOP_bind_ipi: Bind a local event channel to receive events.
  79. * NOTES:
  80. * 1. The allocated event channel is bound to the specified vcpu. The binding
  81. * may not be changed.
  82. */
  83. #define EVTCHNOP_bind_ipi 7
  84. struct evtchn_bind_ipi {
  85. uint32_t vcpu;
  86. /* OUT parameters. */
  87. evtchn_port_t port;
  88. };
  89. /*
  90. * EVTCHNOP_close: Close a local event channel <port>. If the channel is
  91. * interdomain then the remote end is placed in the unbound state
  92. * (EVTCHNSTAT_unbound), awaiting a new connection.
  93. */
  94. #define EVTCHNOP_close 3
  95. struct evtchn_close {
  96. /* IN parameters. */
  97. evtchn_port_t port;
  98. };
  99. /*
  100. * EVTCHNOP_send: Send an event to the remote end of the channel whose local
  101. * endpoint is <port>.
  102. */
  103. #define EVTCHNOP_send 4
  104. struct evtchn_send {
  105. /* IN parameters. */
  106. evtchn_port_t port;
  107. };
  108. /*
  109. * EVTCHNOP_status: Get the current status of the communication channel which
  110. * has an endpoint at <dom, port>.
  111. * NOTES:
  112. * 1. <dom> may be specified as DOMID_SELF.
  113. * 2. Only a sufficiently-privileged domain may obtain the status of an event
  114. * channel for which <dom> is not DOMID_SELF.
  115. */
  116. #define EVTCHNOP_status 5
  117. struct evtchn_status {
  118. /* IN parameters */
  119. domid_t dom;
  120. evtchn_port_t port;
  121. /* OUT parameters */
  122. #define EVTCHNSTAT_closed 0 /* Channel is not in use. */
  123. #define EVTCHNSTAT_unbound 1 /* Channel is waiting interdom connection.*/
  124. #define EVTCHNSTAT_interdomain 2 /* Channel is connected to remote domain. */
  125. #define EVTCHNSTAT_pirq 3 /* Channel is bound to a phys IRQ line. */
  126. #define EVTCHNSTAT_virq 4 /* Channel is bound to a virtual IRQ line */
  127. #define EVTCHNSTAT_ipi 5 /* Channel is bound to a virtual IPI line */
  128. uint32_t status;
  129. uint32_t vcpu; /* VCPU to which this channel is bound. */
  130. union {
  131. struct {
  132. domid_t dom;
  133. } unbound; /* EVTCHNSTAT_unbound */
  134. struct {
  135. domid_t dom;
  136. evtchn_port_t port;
  137. } interdomain; /* EVTCHNSTAT_interdomain */
  138. uint32_t pirq; /* EVTCHNSTAT_pirq */
  139. uint32_t virq; /* EVTCHNSTAT_virq */
  140. } u;
  141. };
  142. /*
  143. * EVTCHNOP_bind_vcpu: Specify which vcpu a channel should notify when an
  144. * event is pending.
  145. * NOTES:
  146. * 1. IPI- and VIRQ-bound channels always notify the vcpu that initialised
  147. * the binding. This binding cannot be changed.
  148. * 2. All other channels notify vcpu0 by default. This default is set when
  149. * the channel is allocated (a port that is freed and subsequently reused
  150. * has its binding reset to vcpu0).
  151. */
  152. #define EVTCHNOP_bind_vcpu 8
  153. struct evtchn_bind_vcpu {
  154. /* IN parameters. */
  155. evtchn_port_t port;
  156. uint32_t vcpu;
  157. };
  158. /*
  159. * EVTCHNOP_unmask: Unmask the specified local event-channel port and deliver
  160. * a notification to the appropriate VCPU if an event is pending.
  161. */
  162. #define EVTCHNOP_unmask 9
  163. struct evtchn_unmask {
  164. /* IN parameters. */
  165. evtchn_port_t port;
  166. };
  167. /*
  168. * EVTCHNOP_reset: Close all event channels associated with specified domain.
  169. * NOTES:
  170. * 1. <dom> may be specified as DOMID_SELF.
  171. * 2. Only a sufficiently-privileged domain may specify other than DOMID_SELF.
  172. */
  173. #define EVTCHNOP_reset 10
  174. struct evtchn_reset {
  175. /* IN parameters. */
  176. domid_t dom;
  177. };
  178. typedef struct evtchn_reset evtchn_reset_t;
  179. /*
  180. * EVTCHNOP_init_control: initialize the control block for the FIFO ABI.
  181. */
  182. #define EVTCHNOP_init_control 11
  183. struct evtchn_init_control {
  184. /* IN parameters. */
  185. uint64_t control_gfn;
  186. uint32_t offset;
  187. uint32_t vcpu;
  188. /* OUT parameters. */
  189. uint8_t link_bits;
  190. uint8_t _pad[7];
  191. };
  192. /*
  193. * EVTCHNOP_expand_array: add an additional page to the event array.
  194. */
  195. #define EVTCHNOP_expand_array 12
  196. struct evtchn_expand_array {
  197. /* IN parameters. */
  198. uint64_t array_gfn;
  199. };
  200. /*
  201. * EVTCHNOP_set_priority: set the priority for an event channel.
  202. */
  203. #define EVTCHNOP_set_priority 13
  204. struct evtchn_set_priority {
  205. /* IN parameters. */
  206. uint32_t port;
  207. uint32_t priority;
  208. };
  209. struct evtchn_op {
  210. uint32_t cmd; /* EVTCHNOP_* */
  211. union {
  212. struct evtchn_alloc_unbound alloc_unbound;
  213. struct evtchn_bind_interdomain bind_interdomain;
  214. struct evtchn_bind_virq bind_virq;
  215. struct evtchn_bind_pirq bind_pirq;
  216. struct evtchn_bind_ipi bind_ipi;
  217. struct evtchn_close close;
  218. struct evtchn_send send;
  219. struct evtchn_status status;
  220. struct evtchn_bind_vcpu bind_vcpu;
  221. struct evtchn_unmask unmask;
  222. } u;
  223. };
  224. DEFINE_GUEST_HANDLE_STRUCT(evtchn_op);
  225. /*
  226. * 2-level ABI
  227. */
  228. #define EVTCHN_2L_NR_CHANNELS (sizeof(xen_ulong_t) * sizeof(xen_ulong_t) * 64)
  229. /*
  230. * FIFO ABI
  231. */
  232. /* Events may have priorities from 0 (highest) to 15 (lowest). */
  233. #define EVTCHN_FIFO_PRIORITY_MAX 0
  234. #define EVTCHN_FIFO_PRIORITY_DEFAULT 7
  235. #define EVTCHN_FIFO_PRIORITY_MIN 15
  236. #define EVTCHN_FIFO_MAX_QUEUES (EVTCHN_FIFO_PRIORITY_MIN + 1)
  237. typedef uint32_t event_word_t;
  238. #define EVTCHN_FIFO_PENDING 31
  239. #define EVTCHN_FIFO_MASKED 30
  240. #define EVTCHN_FIFO_LINKED 29
  241. #define EVTCHN_FIFO_BUSY 28
  242. #define EVTCHN_FIFO_LINK_BITS 17
  243. #define EVTCHN_FIFO_LINK_MASK ((1 << EVTCHN_FIFO_LINK_BITS) - 1)
  244. #define EVTCHN_FIFO_NR_CHANNELS (1 << EVTCHN_FIFO_LINK_BITS)
  245. struct evtchn_fifo_control_block {
  246. uint32_t ready;
  247. uint32_t _rsvd;
  248. event_word_t head[EVTCHN_FIFO_MAX_QUEUES];
  249. };
  250. #endif /* __XEN_PUBLIC_EVENT_CHANNEL_H__ */