blob: a3d9aeceda1a6e3252c24c490dc23b3e3115b464 [file] [log] [blame]
David Vrabel9a489f42013-03-13 15:29:25 +00001/*
2 * Xen Event Channels (internal header)
3 *
4 * Copyright (C) 2013 Citrix Systems R&D Ltd.
5 *
6 * This source code is licensed under the GNU General Public License,
7 * Version 2 or later. See the file COPYING for more details.
8 */
9#ifndef __EVENTS_INTERNAL_H__
10#define __EVENTS_INTERNAL_H__
11
12/* Interrupt types. */
13enum xen_irq_type {
14 IRQT_UNBOUND = 0,
15 IRQT_PIRQ,
16 IRQT_VIRQ,
17 IRQT_IPI,
18 IRQT_EVTCHN
19};
20
21/*
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.
29 * VIRQ - virq number
30 * IPI - IPI vector
31 * EVTCHN -
32 */
33struct irq_info {
34 struct list_head list;
35 int refcnt;
36 enum xen_irq_type type; /* type */
37 unsigned irq;
David Vrabeld0b075f2013-10-17 15:23:15 +010038 unsigned int evtchn; /* event channel */
David Vrabel9a489f42013-03-13 15:29:25 +000039 unsigned short cpu; /* cpu bound */
40
41 union {
42 unsigned short virq;
43 enum ipi_vector ipi;
44 struct {
45 unsigned short pirq;
46 unsigned short gsi;
47 unsigned char vector;
48 unsigned char flags;
49 uint16_t domid;
50 } pirq;
51 } u;
52};
53
54#define PIRQ_NEEDS_EOI (1 << 0)
55#define PIRQ_SHAREABLE (1 << 1)
56
David Vrabelab9a1cc2013-03-14 12:49:19 +000057struct evtchn_ops {
David Vrabeld0b075f2013-10-17 15:23:15 +010058 unsigned (*max_channels)(void);
59 unsigned (*nr_channels)(void);
60
David Vrabel08385872013-03-18 16:54:57 +000061 int (*setup)(struct irq_info *info);
David Vrabelab9a1cc2013-03-14 12:49:19 +000062 void (*bind_to_cpu)(struct irq_info *info, unsigned cpu);
63
64 void (*clear_pending)(unsigned port);
65 void (*set_pending)(unsigned port);
66 bool (*is_pending)(unsigned port);
67 bool (*test_and_set_mask)(unsigned port);
68 void (*mask)(unsigned port);
69 void (*unmask)(unsigned port);
70
71 void (*handle_events)(unsigned cpu);
72};
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
88static inline unsigned xen_evtchn_nr_channels(void)
89{
90 return evtchn_ops->nr_channels();
91}
92
David Vrabel08385872013-03-18 16:54:57 +000093/*
94 * Do any ABI specific setup for a bound event channel before it can
95 * be unmasked and used.
96 */
97static inline int xen_evtchn_port_setup(struct irq_info *info)
98{
99 if (evtchn_ops->setup)
100 return evtchn_ops->setup(info);
101 return 0;
102}
103
David Vrabelab9a1cc2013-03-14 12:49:19 +0000104static inline void xen_evtchn_port_bind_to_cpu(struct irq_info *info,
105 unsigned cpu)
106{
107 evtchn_ops->bind_to_cpu(info, cpu);
108}
David Vrabel9a489f42013-03-13 15:29:25 +0000109
David Vrabelab9a1cc2013-03-14 12:49:19 +0000110static inline void clear_evtchn(unsigned port)
111{
112 evtchn_ops->clear_pending(port);
113}
David Vrabel9a489f42013-03-13 15:29:25 +0000114
David Vrabelab9a1cc2013-03-14 12:49:19 +0000115static inline void set_evtchn(unsigned port)
116{
117 evtchn_ops->set_pending(port);
118}
119
120static inline bool test_evtchn(unsigned port)
121{
122 return evtchn_ops->is_pending(port);
123}
124
125static inline bool test_and_set_mask(unsigned port)
126{
127 return evtchn_ops->test_and_set_mask(port);
128}
129
130static inline void mask_evtchn(unsigned port)
131{
132 return evtchn_ops->mask(port);
133}
134
135static inline void unmask_evtchn(unsigned port)
136{
137 return evtchn_ops->unmask(port);
138}
139
140static inline void xen_evtchn_handle_events(unsigned cpu)
141{
142 return evtchn_ops->handle_events(cpu);
143}
144
145void xen_evtchn_2l_init(void);
David Vrabel9a489f42013-03-13 15:29:25 +0000146
147#endif /* #ifndef __EVENTS_INTERNAL_H__ */