blob: 82938cff6c7a897d0050bbaf75f2bdf1e688340c [file] [log] [blame]
Thomas Gleixner495e0022019-05-22 09:51:27 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
David Vrabel9a489f42013-03-13 15:29:25 +00002/*
3 * Xen Event Channels (internal header)
4 *
5 * Copyright (C) 2013 Citrix Systems R&D Ltd.
David Vrabel9a489f42013-03-13 15:29:25 +00006 */
7#ifndef __EVENTS_INTERNAL_H__
8#define __EVENTS_INTERNAL_H__
9
10/* Interrupt types. */
11enum 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 */
31struct irq_info {
32 struct list_head list;
33 int refcnt;
34 enum xen_irq_type type; /* type */
35 unsigned irq;
David Vrabeld0b075f2013-10-17 15:23:15 +010036 unsigned int evtchn; /* event channel */
David Vrabel9a489f42013-03-13 15:29:25 +000037 unsigned short cpu; /* cpu bound */
38
39 union {
40 unsigned short virq;
41 enum ipi_vector ipi;
42 struct {
43 unsigned short pirq;
44 unsigned short gsi;
45 unsigned char vector;
46 unsigned char flags;
47 uint16_t domid;
48 } pirq;
49 } u;
50};
51
52#define PIRQ_NEEDS_EOI (1 << 0)
53#define PIRQ_SHAREABLE (1 << 1)
Roger Pau Monne4892c9b2014-02-27 19:15:35 +010054#define PIRQ_MSI_GROUP (1 << 2)
David Vrabel9a489f42013-03-13 15:29:25 +000055
David Vrabelab9a1cc2013-03-14 12:49:19 +000056struct evtchn_ops {
David Vrabeld0b075f2013-10-17 15:23:15 +010057 unsigned (*max_channels)(void);
58 unsigned (*nr_channels)(void);
59
David Vrabel08385872013-03-18 16:54:57 +000060 int (*setup)(struct irq_info *info);
David Vrabelab9a1cc2013-03-14 12:49:19 +000061 void (*bind_to_cpu)(struct irq_info *info, unsigned cpu);
62
63 void (*clear_pending)(unsigned port);
64 void (*set_pending)(unsigned port);
65 bool (*is_pending)(unsigned port);
66 bool (*test_and_set_mask)(unsigned port);
67 void (*mask)(unsigned port);
68 void (*unmask)(unsigned port);
69
70 void (*handle_events)(unsigned cpu);
David Vrabel1fe56552013-03-15 13:02:35 +000071 void (*resume)(void);
David Vrabelab9a1cc2013-03-14 12:49:19 +000072};
73
74extern const struct evtchn_ops *evtchn_ops;
75
David Vrabeld0b075f2013-10-17 15:23:15 +010076extern int **evtchn_to_irq;
77int get_evtchn_to_irq(unsigned int evtchn);
David Vrabel9a489f42013-03-13 15:29:25 +000078
79struct irq_info *info_for_irq(unsigned irq);
80unsigned cpu_from_irq(unsigned irq);
81unsigned cpu_from_evtchn(unsigned int evtchn);
82
David Vrabeld0b075f2013-10-17 15:23:15 +010083static inline unsigned xen_evtchn_max_channels(void)
84{
85 return evtchn_ops->max_channels();
86}
87
David Vrabel08385872013-03-18 16:54:57 +000088/*
89 * Do any ABI specific setup for a bound event channel before it can
90 * be unmasked and used.
91 */
92static inline int xen_evtchn_port_setup(struct irq_info *info)
93{
94 if (evtchn_ops->setup)
95 return evtchn_ops->setup(info);
96 return 0;
97}
98
David Vrabelab9a1cc2013-03-14 12:49:19 +000099static inline void xen_evtchn_port_bind_to_cpu(struct irq_info *info,
100 unsigned cpu)
101{
102 evtchn_ops->bind_to_cpu(info, cpu);
103}
David Vrabel9a489f42013-03-13 15:29:25 +0000104
David Vrabelab9a1cc2013-03-14 12:49:19 +0000105static inline void clear_evtchn(unsigned port)
106{
107 evtchn_ops->clear_pending(port);
108}
David Vrabel9a489f42013-03-13 15:29:25 +0000109
David Vrabelab9a1cc2013-03-14 12:49:19 +0000110static inline void set_evtchn(unsigned port)
111{
112 evtchn_ops->set_pending(port);
113}
114
115static inline bool test_evtchn(unsigned port)
116{
117 return evtchn_ops->is_pending(port);
118}
119
120static inline bool test_and_set_mask(unsigned port)
121{
122 return evtchn_ops->test_and_set_mask(port);
123}
124
125static inline void mask_evtchn(unsigned port)
126{
127 return evtchn_ops->mask(port);
128}
129
130static inline void unmask_evtchn(unsigned port)
131{
132 return evtchn_ops->unmask(port);
133}
134
135static inline void xen_evtchn_handle_events(unsigned cpu)
136{
137 return evtchn_ops->handle_events(cpu);
138}
139
David Vrabel1fe56552013-03-15 13:02:35 +0000140static inline void xen_evtchn_resume(void)
141{
142 if (evtchn_ops->resume)
143 evtchn_ops->resume();
144}
145
David Vrabelab9a1cc2013-03-14 12:49:19 +0000146void xen_evtchn_2l_init(void);
David Vrabel1fe56552013-03-15 13:02:35 +0000147int xen_evtchn_fifo_init(void);
David Vrabel9a489f42013-03-13 15:29:25 +0000148
149#endif /* #ifndef __EVENTS_INTERNAL_H__ */