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