Thomas Gleixner | 495e002 | 2019-05-22 09:51:27 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
David Vrabel | 9a489f4 | 2013-03-13 15:29:25 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Xen Event Channels (internal header) |
| 4 | * |
| 5 | * Copyright (C) 2013 Citrix Systems R&D Ltd. |
David Vrabel | 9a489f4 | 2013-03-13 15:29:25 +0000 | [diff] [blame] | 6 | */ |
| 7 | #ifndef __EVENTS_INTERNAL_H__ |
| 8 | #define __EVENTS_INTERNAL_H__ |
| 9 | |
Juergen Gross | e99502f | 2020-09-07 15:47:30 +0200 | [diff] [blame] | 10 | struct evtchn_loop_ctrl; |
| 11 | |
David Vrabel | ab9a1cc | 2013-03-14 12:49:19 +0000 | [diff] [blame] | 12 | struct evtchn_ops { |
David Vrabel | d0b075f | 2013-10-17 15:23:15 +0100 | [diff] [blame] | 13 | unsigned (*max_channels)(void); |
| 14 | unsigned (*nr_channels)(void); |
| 15 | |
Juergen Gross | 7e14cde | 2020-10-22 11:49:04 +0200 | [diff] [blame] | 16 | int (*setup)(evtchn_port_t port); |
Juergen Gross | 9e77d96 | 2021-03-06 17:18:31 +0100 | [diff] [blame] | 17 | void (*remove)(evtchn_port_t port, unsigned int cpu); |
Juergen Gross | 7e14cde | 2020-10-22 11:49:04 +0200 | [diff] [blame] | 18 | void (*bind_to_cpu)(evtchn_port_t evtchn, unsigned int cpu, |
| 19 | unsigned int old_cpu); |
David Vrabel | ab9a1cc | 2013-03-14 12:49:19 +0000 | [diff] [blame] | 20 | |
Yan Yankovskyi | 0102e4e | 2020-03-23 18:15:11 +0200 | [diff] [blame] | 21 | void (*clear_pending)(evtchn_port_t port); |
| 22 | void (*set_pending)(evtchn_port_t port); |
| 23 | bool (*is_pending)(evtchn_port_t port); |
Yan Yankovskyi | 0102e4e | 2020-03-23 18:15:11 +0200 | [diff] [blame] | 24 | void (*mask)(evtchn_port_t port); |
| 25 | void (*unmask)(evtchn_port_t port); |
David Vrabel | ab9a1cc | 2013-03-14 12:49:19 +0000 | [diff] [blame] | 26 | |
Juergen Gross | e99502f | 2020-09-07 15:47:30 +0200 | [diff] [blame] | 27 | void (*handle_events)(unsigned cpu, struct evtchn_loop_ctrl *ctrl); |
David Vrabel | 1fe5655 | 2013-03-15 13:02:35 +0000 | [diff] [blame] | 28 | void (*resume)(void); |
Juergen Gross | 7beb290 | 2020-09-13 14:23:02 +0200 | [diff] [blame] | 29 | |
| 30 | int (*percpu_init)(unsigned int cpu); |
| 31 | int (*percpu_deinit)(unsigned int cpu); |
David Vrabel | ab9a1cc | 2013-03-14 12:49:19 +0000 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | extern const struct evtchn_ops *evtchn_ops; |
| 35 | |
Yan Yankovskyi | 0102e4e | 2020-03-23 18:15:11 +0200 | [diff] [blame] | 36 | int get_evtchn_to_irq(evtchn_port_t evtchn); |
Juergen Gross | e99502f | 2020-09-07 15:47:30 +0200 | [diff] [blame] | 37 | void handle_irq_for_port(evtchn_port_t port, struct evtchn_loop_ctrl *ctrl); |
David Vrabel | 9a489f4 | 2013-03-13 15:29:25 +0000 | [diff] [blame] | 38 | |
Yan Yankovskyi | 0102e4e | 2020-03-23 18:15:11 +0200 | [diff] [blame] | 39 | unsigned int cpu_from_evtchn(evtchn_port_t evtchn); |
David Vrabel | 9a489f4 | 2013-03-13 15:29:25 +0000 | [diff] [blame] | 40 | |
David Vrabel | d0b075f | 2013-10-17 15:23:15 +0100 | [diff] [blame] | 41 | static inline unsigned xen_evtchn_max_channels(void) |
| 42 | { |
| 43 | return evtchn_ops->max_channels(); |
| 44 | } |
| 45 | |
David Vrabel | 0838587 | 2013-03-18 16:54:57 +0000 | [diff] [blame] | 46 | /* |
| 47 | * Do any ABI specific setup for a bound event channel before it can |
| 48 | * be unmasked and used. |
| 49 | */ |
Juergen Gross | 7e14cde | 2020-10-22 11:49:04 +0200 | [diff] [blame] | 50 | static inline int xen_evtchn_port_setup(evtchn_port_t evtchn) |
David Vrabel | 0838587 | 2013-03-18 16:54:57 +0000 | [diff] [blame] | 51 | { |
| 52 | if (evtchn_ops->setup) |
Juergen Gross | 7e14cde | 2020-10-22 11:49:04 +0200 | [diff] [blame] | 53 | return evtchn_ops->setup(evtchn); |
David Vrabel | 0838587 | 2013-03-18 16:54:57 +0000 | [diff] [blame] | 54 | return 0; |
| 55 | } |
| 56 | |
Juergen Gross | 9e77d96 | 2021-03-06 17:18:31 +0100 | [diff] [blame] | 57 | static 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 | |
Juergen Gross | 7e14cde | 2020-10-22 11:49:04 +0200 | [diff] [blame] | 64 | static inline void xen_evtchn_port_bind_to_cpu(evtchn_port_t evtchn, |
| 65 | unsigned int cpu, |
| 66 | unsigned int old_cpu) |
David Vrabel | ab9a1cc | 2013-03-14 12:49:19 +0000 | [diff] [blame] | 67 | { |
Juergen Gross | 7e14cde | 2020-10-22 11:49:04 +0200 | [diff] [blame] | 68 | evtchn_ops->bind_to_cpu(evtchn, cpu, old_cpu); |
David Vrabel | ab9a1cc | 2013-03-14 12:49:19 +0000 | [diff] [blame] | 69 | } |
David Vrabel | 9a489f4 | 2013-03-13 15:29:25 +0000 | [diff] [blame] | 70 | |
Yan Yankovskyi | 0102e4e | 2020-03-23 18:15:11 +0200 | [diff] [blame] | 71 | static inline void clear_evtchn(evtchn_port_t port) |
David Vrabel | ab9a1cc | 2013-03-14 12:49:19 +0000 | [diff] [blame] | 72 | { |
| 73 | evtchn_ops->clear_pending(port); |
| 74 | } |
David Vrabel | 9a489f4 | 2013-03-13 15:29:25 +0000 | [diff] [blame] | 75 | |
Yan Yankovskyi | 0102e4e | 2020-03-23 18:15:11 +0200 | [diff] [blame] | 76 | static inline void set_evtchn(evtchn_port_t port) |
David Vrabel | ab9a1cc | 2013-03-14 12:49:19 +0000 | [diff] [blame] | 77 | { |
| 78 | evtchn_ops->set_pending(port); |
| 79 | } |
| 80 | |
Yan Yankovskyi | 0102e4e | 2020-03-23 18:15:11 +0200 | [diff] [blame] | 81 | static inline bool test_evtchn(evtchn_port_t port) |
David Vrabel | ab9a1cc | 2013-03-14 12:49:19 +0000 | [diff] [blame] | 82 | { |
| 83 | return evtchn_ops->is_pending(port); |
| 84 | } |
| 85 | |
Yan Yankovskyi | 0102e4e | 2020-03-23 18:15:11 +0200 | [diff] [blame] | 86 | static inline void mask_evtchn(evtchn_port_t port) |
David Vrabel | ab9a1cc | 2013-03-14 12:49:19 +0000 | [diff] [blame] | 87 | { |
| 88 | return evtchn_ops->mask(port); |
| 89 | } |
| 90 | |
Yan Yankovskyi | 0102e4e | 2020-03-23 18:15:11 +0200 | [diff] [blame] | 91 | static inline void unmask_evtchn(evtchn_port_t port) |
David Vrabel | ab9a1cc | 2013-03-14 12:49:19 +0000 | [diff] [blame] | 92 | { |
| 93 | return evtchn_ops->unmask(port); |
| 94 | } |
| 95 | |
Juergen Gross | e99502f | 2020-09-07 15:47:30 +0200 | [diff] [blame] | 96 | static inline void xen_evtchn_handle_events(unsigned cpu, |
| 97 | struct evtchn_loop_ctrl *ctrl) |
David Vrabel | ab9a1cc | 2013-03-14 12:49:19 +0000 | [diff] [blame] | 98 | { |
Juergen Gross | e99502f | 2020-09-07 15:47:30 +0200 | [diff] [blame] | 99 | return evtchn_ops->handle_events(cpu, ctrl); |
David Vrabel | ab9a1cc | 2013-03-14 12:49:19 +0000 | [diff] [blame] | 100 | } |
| 101 | |
David Vrabel | 1fe5655 | 2013-03-15 13:02:35 +0000 | [diff] [blame] | 102 | static inline void xen_evtchn_resume(void) |
| 103 | { |
| 104 | if (evtchn_ops->resume) |
| 105 | evtchn_ops->resume(); |
| 106 | } |
| 107 | |
David Vrabel | ab9a1cc | 2013-03-14 12:49:19 +0000 | [diff] [blame] | 108 | void xen_evtchn_2l_init(void); |
David Vrabel | 1fe5655 | 2013-03-15 13:02:35 +0000 | [diff] [blame] | 109 | int xen_evtchn_fifo_init(void); |
David Vrabel | 9a489f4 | 2013-03-13 15:29:25 +0000 | [diff] [blame] | 110 | |
| 111 | #endif /* #ifndef __EVENTS_INTERNAL_H__ */ |