xref: /freebsd/sys/x86/include/xen/arch-intr.h (revision e32fecd0c2c3ee37c47ee100f169e7eb0282a873)
1 /*-
2  * SPDX-License-Identifier: MIT OR GPL-2.0-only
3  *
4  * Copyright © 2015 Julien Grall
5  * Copyright © 2021 Elliott Mitchell
6  *
7  * This file may be distributed separately from the Linux kernel, or
8  * incorporated into other software packages, subject to the following license:
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a copy
11  * of this source file (the "Software"), to deal in the Software without
12  * restriction, including without limitation the rights to use, copy, modify,
13  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
14  * and to permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included in
18  * all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26  * IN THE SOFTWARE.
27  */
28 
29 #ifndef	_MACHINE__XEN_ARCH_INTR_H_
30 #define	_MACHINE__XEN_ARCH_INTR_H_
31 
32 #include <x86/intr_machdep.h>
33 #include <x86/apicvar.h>
34 
35 typedef struct {
36 	struct intsrc		intsrc;		/* @TOP -> *xen_arch_isrc */
37 	u_int			vector;		/* Global isrc vector number */
38 } xen_arch_isrc_t;
39 
40 #include <dev/xen/bus/intr-internal.h>
41 
42 /******************************* ARCH wrappers *******************************/
43 
44 extern void xen_arch_intr_init(void);
45 
46 extern struct xenisrc *xen_arch_intr_alloc(void);
47 extern void     xen_arch_intr_release(struct xenisrc *isrc);
48 
49 static inline u_int
50 xen_arch_intr_next_cpu(struct xenisrc *isrc)
51 {
52 
53 	return (apic_cpuid(intr_next_cpu(0)));
54 }
55 
56 static inline u_long
57 xen_arch_intr_execute_handlers(struct xenisrc *isrc, struct trapframe *frame)
58 {
59 
60 	intr_execute_handlers(&isrc->xi_arch.intsrc, frame);
61 	return (0);
62 }
63 
64 static inline int
65 xen_arch_intr_add_handler(const char *name, driver_filter_t filter,
66     driver_intr_t handler, void *arg, enum intr_type flags,
67     struct xenisrc *isrc, void **cookiep)
68 {
69 
70 	return (intr_add_handler(name, isrc->xi_arch.vector, filter, handler,
71 	    arg, flags, cookiep, 0));
72 }
73 
74 static inline int
75 xen_arch_intr_describe(struct xenisrc *isrc, void *cookie, const char *descr)
76 {
77 
78 	return (intr_describe(isrc->xi_arch.vector, cookie, descr));
79 }
80 
81 static inline int
82 xen_arch_intr_remove_handler(struct xenisrc *isrc, void *cookie)
83 {
84 
85 	return (intr_remove_handler(cookie));
86 }
87 
88 static inline int
89 xen_arch_intr_event_bind(struct xenisrc *isrc, u_int cpu)
90 {
91 
92 	return (intr_event_bind(isrc->xi_arch.intsrc.is_event, cpu));
93 }
94 
95 #endif	/* _MACHINE__XEN_ARCH_INTR_H_ */
96