1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Xen Event Channels (internal header)
5 * Copyright (C) 2013 Citrix Systems R&D Ltd.
7 #ifndef __EVENTS_INTERNAL_H__
8 #define __EVENTS_INTERNAL_H__
10 /* Interrupt types. */
20 * Packed IRQ information:
21 * type - enum xen_irq_type
22 * event channel - irq->event channel mapping
23 * cpu - cpu this event channel is bound to
24 * index - type-specific information:
25 * PIRQ - vector, with MSB being "needs EIO", or physical IRQ of the HVM
26 * guest, or GSI (real passthrough IRQ) of the device.
32 struct list_head list;
33 struct list_head eoi_list;
36 short type; /* type */
37 u8 mask_reason; /* Why is event channel masked */
38 #define EVT_MASK_REASON_EXPLICIT 0x01
39 #define EVT_MASK_REASON_TEMPORARY 0x02
40 #define EVT_MASK_REASON_EOI_PENDING 0x04
41 u8 is_active; /* Is event just being handled? */
43 unsigned int evtchn; /* event channel */
44 unsigned short cpu; /* cpu bound */
45 unsigned short eoi_cpu; /* EOI must happen on this cpu */
46 unsigned int irq_epoch; /* If eoi_cpu valid: irq_epoch of event */
47 u64 eoi_time; /* Time in jiffies when to EOI. */
63 #define PIRQ_NEEDS_EOI (1 << 0)
64 #define PIRQ_SHAREABLE (1 << 1)
65 #define PIRQ_MSI_GROUP (1 << 2)
67 struct evtchn_loop_ctrl;
70 unsigned (*max_channels)(void);
71 unsigned (*nr_channels)(void);
73 int (*setup)(struct irq_info *info);
74 void (*remove)(evtchn_port_t port, unsigned int cpu);
75 void (*bind_to_cpu)(struct irq_info *info, unsigned cpu);
77 void (*clear_pending)(unsigned port);
78 void (*set_pending)(unsigned port);
79 bool (*is_pending)(unsigned port);
80 void (*mask)(unsigned port);
81 void (*unmask)(unsigned port);
83 void (*handle_events)(unsigned cpu, struct evtchn_loop_ctrl *ctrl);
86 int (*percpu_init)(unsigned int cpu);
87 int (*percpu_deinit)(unsigned int cpu);
90 extern const struct evtchn_ops *evtchn_ops;
92 extern int **evtchn_to_irq;
93 int get_evtchn_to_irq(unsigned int evtchn);
94 void handle_irq_for_port(evtchn_port_t port, struct evtchn_loop_ctrl *ctrl);
96 struct irq_info *info_for_irq(unsigned irq);
97 unsigned cpu_from_irq(unsigned irq);
98 unsigned cpu_from_evtchn(unsigned int evtchn);
100 static inline unsigned xen_evtchn_max_channels(void)
102 return evtchn_ops->max_channels();
106 * Do any ABI specific setup for a bound event channel before it can
107 * be unmasked and used.
109 static inline int xen_evtchn_port_setup(struct irq_info *info)
111 if (evtchn_ops->setup)
112 return evtchn_ops->setup(info);
116 static inline void xen_evtchn_port_remove(evtchn_port_t evtchn,
119 if (evtchn_ops->remove)
120 evtchn_ops->remove(evtchn, cpu);
123 static inline void xen_evtchn_port_bind_to_cpu(struct irq_info *info,
126 evtchn_ops->bind_to_cpu(info, cpu);
129 static inline void clear_evtchn(unsigned port)
131 evtchn_ops->clear_pending(port);
134 static inline void set_evtchn(unsigned port)
136 evtchn_ops->set_pending(port);
139 static inline bool test_evtchn(unsigned port)
141 return evtchn_ops->is_pending(port);
144 static inline void mask_evtchn(unsigned port)
146 return evtchn_ops->mask(port);
149 static inline void unmask_evtchn(unsigned port)
151 return evtchn_ops->unmask(port);
154 static inline void xen_evtchn_handle_events(unsigned cpu,
155 struct evtchn_loop_ctrl *ctrl)
157 return evtchn_ops->handle_events(cpu, ctrl);
160 static inline void xen_evtchn_resume(void)
162 if (evtchn_ops->resume)
163 evtchn_ops->resume();
166 void xen_evtchn_2l_init(void);
167 int xen_evtchn_fifo_init(void);
169 #endif /* #ifndef __EVENTS_INTERNAL_H__ */