GNU Linux-libre 5.4.200-gnu1
[releases.git] / drivers / xen / events / events_internal.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Xen Event Channels (internal header)
4  *
5  * Copyright (C) 2013 Citrix Systems R&D Ltd.
6  */
7 #ifndef __EVENTS_INTERNAL_H__
8 #define __EVENTS_INTERNAL_H__
9
10 /* Interrupt types. */
11 enum xen_irq_type {
12         IRQT_UNBOUND = 0,
13         IRQT_PIRQ,
14         IRQT_VIRQ,
15         IRQT_IPI,
16         IRQT_EVTCHN
17 };
18
19 /*
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.
27  *    VIRQ - virq number
28  *    IPI - IPI vector
29  *    EVTCHN -
30  */
31 struct irq_info {
32         struct list_head list;
33         struct list_head eoi_list;
34         short refcnt;
35         short spurious_cnt;
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? */
42         unsigned irq;
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. */
48         raw_spinlock_t lock;
49
50         union {
51                 unsigned short virq;
52                 enum ipi_vector ipi;
53                 struct {
54                         unsigned short pirq;
55                         unsigned short gsi;
56                         unsigned char vector;
57                         unsigned char flags;
58                         uint16_t domid;
59                 } pirq;
60         } u;
61 };
62
63 #define PIRQ_NEEDS_EOI  (1 << 0)
64 #define PIRQ_SHAREABLE  (1 << 1)
65 #define PIRQ_MSI_GROUP  (1 << 2)
66
67 struct evtchn_loop_ctrl;
68
69 struct evtchn_ops {
70         unsigned (*max_channels)(void);
71         unsigned (*nr_channels)(void);
72
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);
76
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);
82
83         void (*handle_events)(unsigned cpu, struct evtchn_loop_ctrl *ctrl);
84         void (*resume)(void);
85
86         int (*percpu_init)(unsigned int cpu);
87         int (*percpu_deinit)(unsigned int cpu);
88 };
89
90 extern const struct evtchn_ops *evtchn_ops;
91
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);
95
96 struct irq_info *info_for_irq(unsigned irq);
97 unsigned cpu_from_irq(unsigned irq);
98 unsigned cpu_from_evtchn(unsigned int evtchn);
99
100 static inline unsigned xen_evtchn_max_channels(void)
101 {
102         return evtchn_ops->max_channels();
103 }
104
105 /*
106  * Do any ABI specific setup for a bound event channel before it can
107  * be unmasked and used.
108  */
109 static inline int xen_evtchn_port_setup(struct irq_info *info)
110 {
111         if (evtchn_ops->setup)
112                 return evtchn_ops->setup(info);
113         return 0;
114 }
115
116 static inline void xen_evtchn_port_remove(evtchn_port_t evtchn,
117                                           unsigned int cpu)
118 {
119         if (evtchn_ops->remove)
120                 evtchn_ops->remove(evtchn, cpu);
121 }
122
123 static inline void xen_evtchn_port_bind_to_cpu(struct irq_info *info,
124                                                unsigned cpu)
125 {
126         evtchn_ops->bind_to_cpu(info, cpu);
127 }
128
129 static inline void clear_evtchn(unsigned port)
130 {
131         evtchn_ops->clear_pending(port);
132 }
133
134 static inline void set_evtchn(unsigned port)
135 {
136         evtchn_ops->set_pending(port);
137 }
138
139 static inline bool test_evtchn(unsigned port)
140 {
141         return evtchn_ops->is_pending(port);
142 }
143
144 static inline void mask_evtchn(unsigned port)
145 {
146         return evtchn_ops->mask(port);
147 }
148
149 static inline void unmask_evtchn(unsigned port)
150 {
151         return evtchn_ops->unmask(port);
152 }
153
154 static inline void xen_evtchn_handle_events(unsigned cpu,
155                                             struct evtchn_loop_ctrl *ctrl)
156 {
157         return evtchn_ops->handle_events(cpu, ctrl);
158 }
159
160 static inline void xen_evtchn_resume(void)
161 {
162         if (evtchn_ops->resume)
163                 evtchn_ops->resume();
164 }
165
166 void xen_evtchn_2l_init(void);
167 int xen_evtchn_fifo_init(void);
168
169 #endif /* #ifndef __EVENTS_INTERNAL_H__ */