blob: dc9650265e0412cf4088a9429dbd7891fd8c74c0 [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;
38 unsigned short evtchn; /* event channel */
39 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 Vrabel08385872013-03-18 16:54:57 +000058 int (*setup)(struct irq_info *info);
David Vrabelab9a1cc2013-03-14 12:49:19 +000059 void (*bind_to_cpu)(struct irq_info *info, unsigned cpu);
60
61 void (*clear_pending)(unsigned port);
62 void (*set_pending)(unsigned port);
63 bool (*is_pending)(unsigned port);
64 bool (*test_and_set_mask)(unsigned port);
65 void (*mask)(unsigned port);
66 void (*unmask)(unsigned port);
67
68 void (*handle_events)(unsigned cpu);
69};
70
71extern const struct evtchn_ops *evtchn_ops;
72
David Vrabel9a489f42013-03-13 15:29:25 +000073extern int *evtchn_to_irq;
74
75struct irq_info *info_for_irq(unsigned irq);
76unsigned cpu_from_irq(unsigned irq);
77unsigned cpu_from_evtchn(unsigned int evtchn);
78
David Vrabel08385872013-03-18 16:54:57 +000079/*
80 * Do any ABI specific setup for a bound event channel before it can
81 * be unmasked and used.
82 */
83static inline int xen_evtchn_port_setup(struct irq_info *info)
84{
85 if (evtchn_ops->setup)
86 return evtchn_ops->setup(info);
87 return 0;
88}
89
David Vrabelab9a1cc2013-03-14 12:49:19 +000090static inline void xen_evtchn_port_bind_to_cpu(struct irq_info *info,
91 unsigned cpu)
92{
93 evtchn_ops->bind_to_cpu(info, cpu);
94}
David Vrabel9a489f42013-03-13 15:29:25 +000095
David Vrabelab9a1cc2013-03-14 12:49:19 +000096static inline void clear_evtchn(unsigned port)
97{
98 evtchn_ops->clear_pending(port);
99}
David Vrabel9a489f42013-03-13 15:29:25 +0000100
David Vrabelab9a1cc2013-03-14 12:49:19 +0000101static inline void set_evtchn(unsigned port)
102{
103 evtchn_ops->set_pending(port);
104}
105
106static inline bool test_evtchn(unsigned port)
107{
108 return evtchn_ops->is_pending(port);
109}
110
111static inline bool test_and_set_mask(unsigned port)
112{
113 return evtchn_ops->test_and_set_mask(port);
114}
115
116static inline void mask_evtchn(unsigned port)
117{
118 return evtchn_ops->mask(port);
119}
120
121static inline void unmask_evtchn(unsigned port)
122{
123 return evtchn_ops->unmask(port);
124}
125
126static inline void xen_evtchn_handle_events(unsigned cpu)
127{
128 return evtchn_ops->handle_events(cpu);
129}
130
131void xen_evtchn_2l_init(void);
David Vrabel9a489f42013-03-13 15:29:25 +0000132
133#endif /* #ifndef __EVENTS_INTERNAL_H__ */