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