2 * Xen Event Channels (internal header)
4 * Copyright (C) 2013 Citrix Systems R&D Ltd.
6 * This source code is licensed under the GNU General Public License,
7 * Version 2 or later. See the file COPYING for more details.
9 #ifndef __EVENTS_INTERNAL_H__
10 #define __EVENTS_INTERNAL_H__
12 /* Interrupt types. */
22 * Packed IRQ information:
23 * type - enum xen_irq_type
24 * event channel - irq->event channel mapping
25 * cpu - cpu this event channel is bound to
26 * index - type-specific information:
27 * PIRQ - vector, with MSB being "needs EIO", or physical IRQ of the HVM
28 * guest, or GSI (real passthrough IRQ) of the device.
34 struct list_head list;
35 struct list_head eoi_list;
38 short type; /* type */
39 u8 mask_reason; /* Why is event channel masked */
40 #define EVT_MASK_REASON_EXPLICIT 0x01
41 #define EVT_MASK_REASON_TEMPORARY 0x02
42 #define EVT_MASK_REASON_EOI_PENDING 0x04
43 u8 is_active; /* Is event just being handled? */
45 unsigned int evtchn; /* event channel */
46 unsigned short cpu; /* cpu bound */
47 unsigned short eoi_cpu; /* EOI must happen on this cpu */
48 unsigned int irq_epoch; /* If eoi_cpu valid: irq_epoch of event */
49 u64 eoi_time; /* Time in jiffies when to EOI. */
65 #define PIRQ_NEEDS_EOI (1 << 0)
66 #define PIRQ_SHAREABLE (1 << 1)
67 #define PIRQ_MSI_GROUP (1 << 2)
69 struct evtchn_loop_ctrl;
72 unsigned (*max_channels)(void);
73 unsigned (*nr_channels)(void);
75 int (*setup)(struct irq_info *info);
76 void (*remove)(evtchn_port_t port, unsigned int cpu);
77 void (*bind_to_cpu)(struct irq_info *info, unsigned cpu);
79 void (*clear_pending)(unsigned port);
80 void (*set_pending)(unsigned port);
81 bool (*is_pending)(unsigned port);
82 void (*mask)(unsigned port);
83 void (*unmask)(unsigned port);
85 void (*handle_events)(unsigned cpu, struct evtchn_loop_ctrl *ctrl);
88 int (*percpu_init)(unsigned int cpu);
89 int (*percpu_deinit)(unsigned int cpu);
92 extern const struct evtchn_ops *evtchn_ops;
94 extern int **evtchn_to_irq;
95 int get_evtchn_to_irq(unsigned int evtchn);
96 void handle_irq_for_port(evtchn_port_t port, struct evtchn_loop_ctrl *ctrl);
98 struct irq_info *info_for_irq(unsigned irq);
99 unsigned cpu_from_irq(unsigned irq);
100 unsigned cpu_from_evtchn(unsigned int evtchn);
102 static inline unsigned xen_evtchn_max_channels(void)
104 return evtchn_ops->max_channels();
108 * Do any ABI specific setup for a bound event channel before it can
109 * be unmasked and used.
111 static inline int xen_evtchn_port_setup(struct irq_info *info)
113 if (evtchn_ops->setup)
114 return evtchn_ops->setup(info);
118 static inline void xen_evtchn_port_remove(evtchn_port_t evtchn,
121 if (evtchn_ops->remove)
122 evtchn_ops->remove(evtchn, cpu);
125 static inline void xen_evtchn_port_bind_to_cpu(struct irq_info *info,
128 evtchn_ops->bind_to_cpu(info, cpu);
131 static inline void clear_evtchn(unsigned port)
133 evtchn_ops->clear_pending(port);
136 static inline void set_evtchn(unsigned port)
138 evtchn_ops->set_pending(port);
141 static inline bool test_evtchn(unsigned port)
143 return evtchn_ops->is_pending(port);
146 static inline void mask_evtchn(unsigned port)
148 return evtchn_ops->mask(port);
151 static inline void unmask_evtchn(unsigned port)
153 return evtchn_ops->unmask(port);
156 static inline void xen_evtchn_handle_events(unsigned cpu,
157 struct evtchn_loop_ctrl *ctrl)
159 return evtchn_ops->handle_events(cpu, ctrl);
162 static inline void xen_evtchn_resume(void)
164 if (evtchn_ops->resume)
165 evtchn_ops->resume();
168 void xen_evtchn_2l_init(void);
169 int xen_evtchn_fifo_init(void);
171 #endif /* #ifndef __EVENTS_INTERNAL_H__ */