Loading...
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. */
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;
36 evtchn_port_t evtchn; /* event channel */
37 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)
54#define PIRQ_MSI_GROUP (1 << 2)
55
56struct evtchn_ops {
57 unsigned (*max_channels)(void);
58 unsigned (*nr_channels)(void);
59
60 int (*setup)(struct irq_info *info);
61 void (*bind_to_cpu)(struct irq_info *info, unsigned cpu);
62
63 void (*clear_pending)(evtchn_port_t port);
64 void (*set_pending)(evtchn_port_t port);
65 bool (*is_pending)(evtchn_port_t port);
66 bool (*test_and_set_mask)(evtchn_port_t port);
67 void (*mask)(evtchn_port_t port);
68 void (*unmask)(evtchn_port_t port);
69
70 void (*handle_events)(unsigned cpu);
71 void (*resume)(void);
72};
73
74extern const struct evtchn_ops *evtchn_ops;
75
76extern int **evtchn_to_irq;
77int get_evtchn_to_irq(evtchn_port_t evtchn);
78
79struct irq_info *info_for_irq(unsigned irq);
80unsigned cpu_from_irq(unsigned irq);
81unsigned int cpu_from_evtchn(evtchn_port_t evtchn);
82
83static inline unsigned xen_evtchn_max_channels(void)
84{
85 return evtchn_ops->max_channels();
86}
87
88/*
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
99static 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}
104
105static inline void clear_evtchn(evtchn_port_t port)
106{
107 evtchn_ops->clear_pending(port);
108}
109
110static inline void set_evtchn(evtchn_port_t port)
111{
112 evtchn_ops->set_pending(port);
113}
114
115static inline bool test_evtchn(evtchn_port_t port)
116{
117 return evtchn_ops->is_pending(port);
118}
119
120static inline bool test_and_set_mask(evtchn_port_t port)
121{
122 return evtchn_ops->test_and_set_mask(port);
123}
124
125static inline void mask_evtchn(evtchn_port_t port)
126{
127 return evtchn_ops->mask(port);
128}
129
130static inline void unmask_evtchn(evtchn_port_t 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
140static inline void xen_evtchn_resume(void)
141{
142 if (evtchn_ops->resume)
143 evtchn_ops->resume();
144}
145
146void xen_evtchn_2l_init(void);
147int xen_evtchn_fifo_init(void);
148
149#endif /* #ifndef __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
10struct evtchn_loop_ctrl;
11
12struct evtchn_ops {
13 unsigned (*max_channels)(void);
14 unsigned (*nr_channels)(void);
15
16 int (*setup)(evtchn_port_t port);
17 void (*remove)(evtchn_port_t port, unsigned int cpu);
18 void (*bind_to_cpu)(evtchn_port_t evtchn, unsigned int cpu,
19 unsigned int old_cpu);
20
21 void (*clear_pending)(evtchn_port_t port);
22 void (*set_pending)(evtchn_port_t port);
23 bool (*is_pending)(evtchn_port_t port);
24 void (*mask)(evtchn_port_t port);
25 void (*unmask)(evtchn_port_t port);
26
27 void (*handle_events)(unsigned cpu, struct evtchn_loop_ctrl *ctrl);
28 void (*resume)(void);
29
30 int (*percpu_init)(unsigned int cpu);
31 int (*percpu_deinit)(unsigned int cpu);
32};
33
34extern const struct evtchn_ops *evtchn_ops;
35
36int get_evtchn_to_irq(evtchn_port_t evtchn);
37void handle_irq_for_port(evtchn_port_t port, struct evtchn_loop_ctrl *ctrl);
38
39unsigned int cpu_from_evtchn(evtchn_port_t evtchn);
40
41static inline unsigned xen_evtchn_max_channels(void)
42{
43 return evtchn_ops->max_channels();
44}
45
46/*
47 * Do any ABI specific setup for a bound event channel before it can
48 * be unmasked and used.
49 */
50static inline int xen_evtchn_port_setup(evtchn_port_t evtchn)
51{
52 if (evtchn_ops->setup)
53 return evtchn_ops->setup(evtchn);
54 return 0;
55}
56
57static inline void xen_evtchn_port_remove(evtchn_port_t evtchn,
58 unsigned int cpu)
59{
60 if (evtchn_ops->remove)
61 evtchn_ops->remove(evtchn, cpu);
62}
63
64static inline void xen_evtchn_port_bind_to_cpu(evtchn_port_t evtchn,
65 unsigned int cpu,
66 unsigned int old_cpu)
67{
68 evtchn_ops->bind_to_cpu(evtchn, cpu, old_cpu);
69}
70
71static inline void clear_evtchn(evtchn_port_t port)
72{
73 evtchn_ops->clear_pending(port);
74}
75
76static inline void set_evtchn(evtchn_port_t port)
77{
78 evtchn_ops->set_pending(port);
79}
80
81static inline bool test_evtchn(evtchn_port_t port)
82{
83 return evtchn_ops->is_pending(port);
84}
85
86static inline void mask_evtchn(evtchn_port_t port)
87{
88 return evtchn_ops->mask(port);
89}
90
91static inline void unmask_evtchn(evtchn_port_t port)
92{
93 return evtchn_ops->unmask(port);
94}
95
96static inline void xen_evtchn_handle_events(unsigned cpu,
97 struct evtchn_loop_ctrl *ctrl)
98{
99 return evtchn_ops->handle_events(cpu, ctrl);
100}
101
102static inline void xen_evtchn_resume(void)
103{
104 if (evtchn_ops->resume)
105 evtchn_ops->resume();
106}
107
108void xen_evtchn_2l_init(void);
109int xen_evtchn_fifo_init(void);
110
111#endif /* #ifndef __EVENTS_INTERNAL_H__ */