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