iPXE
event_channel.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  * event_channel.h
00003  *
00004  * Event channels between domains.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a copy
00007  * of this software and associated documentation files (the "Software"), to
00008  * deal in the Software without restriction, including without limitation the
00009  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
00010  * sell copies of the Software, and to permit persons to whom the Software is
00011  * furnished to do so, subject to the following conditions:
00012  *
00013  * The above copyright notice and this permission notice shall be included in
00014  * all copies or substantial portions of the Software.
00015  *
00016  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00019  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00020  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00021  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00022  * DEALINGS IN THE SOFTWARE.
00023  *
00024  * Copyright (c) 2003-2004, K A Fraser.
00025  */
00026 
00027 #ifndef __XEN_PUBLIC_EVENT_CHANNEL_H__
00028 #define __XEN_PUBLIC_EVENT_CHANNEL_H__
00029 
00030 FILE_LICENCE ( MIT );
00031 
00032 #include "xen.h"
00033 
00034 /*
00035  * `incontents 150 evtchn Event Channels
00036  *
00037  * Event channels are the basic primitive provided by Xen for event
00038  * notifications. An event is the Xen equivalent of a hardware
00039  * interrupt. They essentially store one bit of information, the event
00040  * of interest is signalled by transitioning this bit from 0 to 1.
00041  *
00042  * Notifications are received by a guest via an upcall from Xen,
00043  * indicating when an event arrives (setting the bit). Further
00044  * notifications are masked until the bit is cleared again (therefore,
00045  * guests must check the value of the bit after re-enabling event
00046  * delivery to ensure no missed notifications).
00047  *
00048  * Event notifications can be masked by setting a flag; this is
00049  * equivalent to disabling interrupts and can be used to ensure
00050  * atomicity of certain operations in the guest kernel.
00051  *
00052  * Event channels are represented by the evtchn_* fields in
00053  * struct shared_info and struct vcpu_info.
00054  */
00055 
00056 /*
00057  * ` enum neg_errnoval
00058  * ` HYPERVISOR_event_channel_op(enum event_channel_op cmd, void *args)
00059  * `
00060  * @cmd  == EVTCHNOP_* (event-channel operation).
00061  * @args == struct evtchn_* Operation-specific extra arguments (NULL if none).
00062  */
00063 
00064 /* ` enum event_channel_op { // EVTCHNOP_* => struct evtchn_* */
00065 #define EVTCHNOP_bind_interdomain 0
00066 #define EVTCHNOP_bind_virq        1
00067 #define EVTCHNOP_bind_pirq        2
00068 #define EVTCHNOP_close            3
00069 #define EVTCHNOP_send             4
00070 #define EVTCHNOP_status           5
00071 #define EVTCHNOP_alloc_unbound    6
00072 #define EVTCHNOP_bind_ipi         7
00073 #define EVTCHNOP_bind_vcpu        8
00074 #define EVTCHNOP_unmask           9
00075 #define EVTCHNOP_reset           10
00076 #define EVTCHNOP_init_control    11
00077 #define EVTCHNOP_expand_array    12
00078 #define EVTCHNOP_set_priority    13
00079 /* ` } */
00080 
00081 typedef uint32_t evtchn_port_t;
00082 DEFINE_XEN_GUEST_HANDLE(evtchn_port_t);
00083 
00084 /*
00085  * EVTCHNOP_alloc_unbound: Allocate a port in domain <dom> and mark as
00086  * accepting interdomain bindings from domain <remote_dom>. A fresh port
00087  * is allocated in <dom> and returned as <port>.
00088  * NOTES:
00089  *  1. If the caller is unprivileged then <dom> must be DOMID_SELF.
00090  *  2. <rdom> may be DOMID_SELF, allowing loopback connections.
00091  */
00092 struct evtchn_alloc_unbound {
00093     /* IN parameters */
00094     domid_t dom, remote_dom;
00095     /* OUT parameters */
00096     evtchn_port_t port;
00097 };
00098 typedef struct evtchn_alloc_unbound evtchn_alloc_unbound_t;
00099 
00100 /*
00101  * EVTCHNOP_bind_interdomain: Construct an interdomain event channel between
00102  * the calling domain and <remote_dom>. <remote_dom,remote_port> must identify
00103  * a port that is unbound and marked as accepting bindings from the calling
00104  * domain. A fresh port is allocated in the calling domain and returned as
00105  * <local_port>.
00106  *
00107  * In case the peer domain has already tried to set our event channel
00108  * pending, before it was bound, EVTCHNOP_bind_interdomain always sets
00109  * the local event channel pending.
00110  *
00111  * The usual pattern of use, in the guest's upcall (or subsequent
00112  * handler) is as follows: (Re-enable the event channel for subsequent
00113  * signalling and then) check for the existence of whatever condition
00114  * is being waited for by other means, and take whatever action is
00115  * needed (if any).
00116  *
00117  * NOTES:
00118  *  1. <remote_dom> may be DOMID_SELF, allowing loopback connections.
00119  */
00120 struct evtchn_bind_interdomain {
00121     /* IN parameters. */
00122     domid_t remote_dom;
00123     evtchn_port_t remote_port;
00124     /* OUT parameters. */
00125     evtchn_port_t local_port;
00126 };
00127 typedef struct evtchn_bind_interdomain evtchn_bind_interdomain_t;
00128 
00129 /*
00130  * EVTCHNOP_bind_virq: Bind a local event channel to VIRQ <irq> on specified
00131  * vcpu.
00132  * NOTES:
00133  *  1. Virtual IRQs are classified as per-vcpu or global. See the VIRQ list
00134  *     in xen.h for the classification of each VIRQ.
00135  *  2. Global VIRQs must be allocated on VCPU0 but can subsequently be
00136  *     re-bound via EVTCHNOP_bind_vcpu.
00137  *  3. Per-vcpu VIRQs may be bound to at most one event channel per vcpu.
00138  *     The allocated event channel is bound to the specified vcpu and the
00139  *     binding cannot be changed.
00140  */
00141 struct evtchn_bind_virq {
00142     /* IN parameters. */
00143     uint32_t virq; /* enum virq */
00144     uint32_t vcpu;
00145     /* OUT parameters. */
00146     evtchn_port_t port;
00147 };
00148 typedef struct evtchn_bind_virq evtchn_bind_virq_t;
00149 
00150 /*
00151  * EVTCHNOP_bind_pirq: Bind a local event channel to a real IRQ (PIRQ <irq>).
00152  * NOTES:
00153  *  1. A physical IRQ may be bound to at most one event channel per domain.
00154  *  2. Only a sufficiently-privileged domain may bind to a physical IRQ.
00155  */
00156 struct evtchn_bind_pirq {
00157     /* IN parameters. */
00158     uint32_t pirq;
00159 #define BIND_PIRQ__WILL_SHARE 1
00160     uint32_t flags; /* BIND_PIRQ__* */
00161     /* OUT parameters. */
00162     evtchn_port_t port;
00163 };
00164 typedef struct evtchn_bind_pirq evtchn_bind_pirq_t;
00165 
00166 /*
00167  * EVTCHNOP_bind_ipi: Bind a local event channel to receive events.
00168  * NOTES:
00169  *  1. The allocated event channel is bound to the specified vcpu. The binding
00170  *     may not be changed.
00171  */
00172 struct evtchn_bind_ipi {
00173     uint32_t vcpu;
00174     /* OUT parameters. */
00175     evtchn_port_t port;
00176 };
00177 typedef struct evtchn_bind_ipi evtchn_bind_ipi_t;
00178 
00179 /*
00180  * EVTCHNOP_close: Close a local event channel <port>. If the channel is
00181  * interdomain then the remote end is placed in the unbound state
00182  * (EVTCHNSTAT_unbound), awaiting a new connection.
00183  */
00184 struct evtchn_close {
00185     /* IN parameters. */
00186     evtchn_port_t port;
00187 };
00188 typedef struct evtchn_close evtchn_close_t;
00189 
00190 /*
00191  * EVTCHNOP_send: Send an event to the remote end of the channel whose local
00192  * endpoint is <port>.
00193  */
00194 struct evtchn_send {
00195     /* IN parameters. */
00196     evtchn_port_t port;
00197 };
00198 typedef struct evtchn_send evtchn_send_t;
00199 
00200 /*
00201  * EVTCHNOP_status: Get the current status of the communication channel which
00202  * has an endpoint at <dom, port>.
00203  * NOTES:
00204  *  1. <dom> may be specified as DOMID_SELF.
00205  *  2. Only a sufficiently-privileged domain may obtain the status of an event
00206  *     channel for which <dom> is not DOMID_SELF.
00207  */
00208 struct evtchn_status {
00209     /* IN parameters */
00210     domid_t  dom;
00211     evtchn_port_t port;
00212     /* OUT parameters */
00213 #define EVTCHNSTAT_closed       0  /* Channel is not in use.                 */
00214 #define EVTCHNSTAT_unbound      1  /* Channel is waiting interdom connection.*/
00215 #define EVTCHNSTAT_interdomain  2  /* Channel is connected to remote domain. */
00216 #define EVTCHNSTAT_pirq         3  /* Channel is bound to a phys IRQ line.   */
00217 #define EVTCHNSTAT_virq         4  /* Channel is bound to a virtual IRQ line */
00218 #define EVTCHNSTAT_ipi          5  /* Channel is bound to a virtual IPI line */
00219     uint32_t status;
00220     uint32_t vcpu;                 /* VCPU to which this channel is bound.   */
00221     union {
00222         struct {
00223             domid_t dom;
00224         } unbound;                 /* EVTCHNSTAT_unbound */
00225         struct {
00226             domid_t dom;
00227             evtchn_port_t port;
00228         } interdomain;             /* EVTCHNSTAT_interdomain */
00229         uint32_t pirq;             /* EVTCHNSTAT_pirq        */
00230         uint32_t virq;             /* EVTCHNSTAT_virq        */
00231     } u;
00232 };
00233 typedef struct evtchn_status evtchn_status_t;
00234 
00235 /*
00236  * EVTCHNOP_bind_vcpu: Specify which vcpu a channel should notify when an
00237  * event is pending.
00238  * NOTES:
00239  *  1. IPI-bound channels always notify the vcpu specified at bind time.
00240  *     This binding cannot be changed.
00241  *  2. Per-VCPU VIRQ channels always notify the vcpu specified at bind time.
00242  *     This binding cannot be changed.
00243  *  3. All other channels notify vcpu0 by default. This default is set when
00244  *     the channel is allocated (a port that is freed and subsequently reused
00245  *     has its binding reset to vcpu0).
00246  */
00247 struct evtchn_bind_vcpu {
00248     /* IN parameters. */
00249     evtchn_port_t port;
00250     uint32_t vcpu;
00251 };
00252 typedef struct evtchn_bind_vcpu evtchn_bind_vcpu_t;
00253 
00254 /*
00255  * EVTCHNOP_unmask: Unmask the specified local event-channel port and deliver
00256  * a notification to the appropriate VCPU if an event is pending.
00257  */
00258 struct evtchn_unmask {
00259     /* IN parameters. */
00260     evtchn_port_t port;
00261 };
00262 typedef struct evtchn_unmask evtchn_unmask_t;
00263 
00264 /*
00265  * EVTCHNOP_reset: Close all event channels associated with specified domain.
00266  * NOTES:
00267  *  1. <dom> may be specified as DOMID_SELF.
00268  *  2. Only a sufficiently-privileged domain may specify other than DOMID_SELF.
00269  */
00270 struct evtchn_reset {
00271     /* IN parameters. */
00272     domid_t dom;
00273 };
00274 typedef struct evtchn_reset evtchn_reset_t;
00275 
00276 /*
00277  * EVTCHNOP_init_control: initialize the control block for the FIFO ABI.
00278  *
00279  * Note: any events that are currently pending will not be resent and
00280  * will be lost.  Guests should call this before binding any event to
00281  * avoid losing any events.
00282  */
00283 struct evtchn_init_control {
00284     /* IN parameters. */
00285     uint64_t control_gfn;
00286     uint32_t offset;
00287     uint32_t vcpu;
00288     /* OUT parameters. */
00289     uint8_t link_bits;
00290     uint8_t _pad[7];
00291 };
00292 typedef struct evtchn_init_control evtchn_init_control_t;
00293 
00294 /*
00295  * EVTCHNOP_expand_array: add an additional page to the event array.
00296  */
00297 struct evtchn_expand_array {
00298     /* IN parameters. */
00299     uint64_t array_gfn;
00300 };
00301 typedef struct evtchn_expand_array evtchn_expand_array_t;
00302 
00303 /*
00304  * EVTCHNOP_set_priority: set the priority for an event channel.
00305  */
00306 struct evtchn_set_priority {
00307     /* IN parameters. */
00308     uint32_t port;
00309     uint32_t priority;
00310 };
00311 typedef struct evtchn_set_priority evtchn_set_priority_t;
00312 
00313 /*
00314  * ` enum neg_errnoval
00315  * ` HYPERVISOR_event_channel_op_compat(struct evtchn_op *op)
00316  * `
00317  * Superceded by new event_channel_op() hypercall since 0x00030202.
00318  */
00319 struct evtchn_op {
00320     uint32_t cmd; /* enum event_channel_op */
00321     union {
00322         struct evtchn_alloc_unbound    alloc_unbound;
00323         struct evtchn_bind_interdomain bind_interdomain;
00324         struct evtchn_bind_virq        bind_virq;
00325         struct evtchn_bind_pirq        bind_pirq;
00326         struct evtchn_bind_ipi         bind_ipi;
00327         struct evtchn_close            close;
00328         struct evtchn_send             send;
00329         struct evtchn_status           status;
00330         struct evtchn_bind_vcpu        bind_vcpu;
00331         struct evtchn_unmask           unmask;
00332     } u;
00333 };
00334 typedef struct evtchn_op evtchn_op_t;
00335 DEFINE_XEN_GUEST_HANDLE(evtchn_op_t);
00336 
00337 /*
00338  * 2-level ABI
00339  */
00340 
00341 #define EVTCHN_2L_NR_CHANNELS (sizeof(xen_ulong_t) * sizeof(xen_ulong_t) * 64)
00342 
00343 /*
00344  * FIFO ABI
00345  */
00346 
00347 /* Events may have priorities from 0 (highest) to 15 (lowest). */
00348 #define EVTCHN_FIFO_PRIORITY_MAX     0
00349 #define EVTCHN_FIFO_PRIORITY_DEFAULT 7
00350 #define EVTCHN_FIFO_PRIORITY_MIN     15
00351 
00352 #define EVTCHN_FIFO_MAX_QUEUES (EVTCHN_FIFO_PRIORITY_MIN + 1)
00353 
00354 typedef uint32_t event_word_t;
00355 
00356 #define EVTCHN_FIFO_PENDING 31
00357 #define EVTCHN_FIFO_MASKED  30
00358 #define EVTCHN_FIFO_LINKED  29
00359 #define EVTCHN_FIFO_BUSY    28
00360 
00361 #define EVTCHN_FIFO_LINK_BITS 17
00362 #define EVTCHN_FIFO_LINK_MASK ((1 << EVTCHN_FIFO_LINK_BITS) - 1)
00363 
00364 #define EVTCHN_FIFO_NR_CHANNELS (1 << EVTCHN_FIFO_LINK_BITS)
00365 
00366 struct evtchn_fifo_control_block {
00367     uint32_t ready;
00368     uint32_t _rsvd;
00369     uint32_t head[EVTCHN_FIFO_MAX_QUEUES];
00370 };
00371 typedef struct evtchn_fifo_control_block evtchn_fifo_control_block_t;
00372 
00373 #endif /* __XEN_PUBLIC_EVENT_CHANNEL_H__ */
00374 
00375 /*
00376  * Local variables:
00377  * mode: C
00378  * c-file-style: "BSD"
00379  * c-basic-offset: 4
00380  * tab-width: 4
00381  * indent-tabs-mode: nil
00382  * End:
00383  */