xref: /netbsd-src/sys/arch/xen/include/intr.h (revision 9ddb6ab554e70fb9bbd90c3d96b812bc57755a14)
1 /*	$NetBSD: intr.h,v 1.34 2012/02/17 18:40:19 bouyer Exp $	*/
2 /*	NetBSD intr.h,v 1.15 2004/10/31 10:39:34 yamt Exp	*/
3 
4 /*-
5  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Charles M. Hannum, and by Jason R. Thorpe.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef _XEN_INTR_H_
34 #define	_XEN_INTR_H_
35 
36 #include <machine/intrdefs.h>
37 
38 #ifndef _LOCORE
39 #include <xen/xen.h>
40 #include <xen/hypervisor.h>
41 #include <xen/evtchn.h>
42 #include <machine/pic.h>
43 #include <sys/evcnt.h>
44 
45 #include "opt_xen.h"
46 
47 
48 struct cpu_info;
49 /*
50  * Struct describing an event channel.
51  */
52 
53 struct evtsource {
54 	int ev_maxlevel;		/* max. IPL for this source */
55 	uint32_t ev_imask;		/* interrupt mask */
56 	struct intrhand *ev_handlers;	/* handler chain */
57 	struct evcnt ev_evcnt;		/* interrupt counter */
58 	struct cpu_info *ev_cpu;        /* cpu on which this event is bound */
59 	char ev_evname[32];		/* event counter name */
60 };
61 
62 /*
63  * Structure describing an interrupt level. struct cpu_info has an array of
64  * IPL_MAX of theses. The index in the array is equal to the stub number of
65  * the stubcode as present in vector.s
66  */
67 
68 struct intrstub {
69 #if 0
70 	void *ist_entry;
71 #endif
72 	void *ist_recurse;
73 	void *ist_resume;
74 };
75 
76 /* for x86 compatibility */
77 extern struct intrstub i8259_stubs[];
78 extern struct intrstub ioapic_edge_stubs[];
79 extern struct intrstub ioapic_level_stubs[];
80 
81 struct iplsource {
82 	struct intrhand *ipl_handlers;   /* handler chain */
83 	void *ipl_recurse;               /* entry for spllower */
84 	void *ipl_resume;                /* entry for doreti */
85 	struct lwp *ipl_lwp;
86 	u_long ipl_evt_mask1;	/* pending events for this IPL */
87 	u_long ipl_evt_mask2[NR_EVENT_CHANNELS];
88 };
89 
90 
91 
92 /*
93  * Interrupt handler chains. These are linked in both the evtsource and
94  * the iplsource.
95  * The handler is called with its (single) argument.
96  */
97 
98 struct intrhand {
99 	int	(*ih_fun)(void *);
100 	void	*ih_arg;
101 	int	ih_level;
102 	int	(*ih_realfun)(void *);
103 	void	*ih_realarg;
104 	struct	intrhand *ih_ipl_next;
105 	struct	intrhand *ih_evt_next;
106 	struct cpu_info *ih_cpu;
107 };
108 
109 struct xen_intr_handle {
110 	int pirq; /* also contains the  APIC_INT_* flags if NIOAPIC > 0 */
111 	int evtch;
112 };
113 
114 extern struct intrstub xenev_stubs[];
115 
116 #define IUNMASK(ci,level) (ci)->ci_iunmask[(level)]
117 
118 extern void Xspllower(int);
119 
120 int splraise(int);
121 void spllower(int);
122 
123 #define SPL_ASSERT_BELOW(x) KDASSERT(curcpu()->ci_ilevel < (x))
124 
125 /*
126  * Miscellaneous
127  */
128 #define	spl0()		spllower(IPL_NONE)
129 #define	splx(x)		spllower(x)
130 
131 typedef uint8_t ipl_t;
132 typedef struct {
133 	ipl_t _ipl;
134 } ipl_cookie_t;
135 
136 static inline ipl_cookie_t
137 makeiplcookie(ipl_t ipl)
138 {
139 
140 	return (ipl_cookie_t){._ipl = ipl};
141 }
142 
143 static inline int
144 splraiseipl(ipl_cookie_t icookie)
145 {
146 
147 	return splraise(icookie._ipl);
148 }
149 
150 #include <sys/spl.h>
151 
152 /*
153  * Stub declarations.
154  */
155 
156 struct pcibus_attach_args;
157 
158 #ifdef MULTIPROCESSOR
159 int intr_biglock_wrapper(void *);
160 #endif
161 
162 void intr_default_setup(void);
163 int x86_nmi(void);
164 
165 void *intr_establish(int, struct pic *, int, int, int, int (*)(void *), void *, bool);
166 void intr_disestablish(struct intrhand *);
167 const char *intr_string(int);
168 void cpu_intr_init(struct cpu_info *);
169 int xen_intr_map(int *, int);
170 #ifdef INTRDEBUG
171 void intr_printconfig(void);
172 #endif
173 int intr_find_mpmapping(int, int, struct xen_intr_handle *);
174 struct pic *intr_findpic(int);
175 void intr_add_pcibus(struct pcibus_attach_args *);
176 
177 #ifdef MULTIPROCESSOR
178 void xen_ipi_init(void);
179 int xen_send_ipi(struct cpu_info *, uint32_t);
180 void xen_broadcast_ipi(uint32_t);
181 #else
182 #define xen_ipi_init(_1) ((void) 0) /* nothing */
183 #define xen_send_ipi(_i1, _i2) (0) /* nothing */
184 #define xen_broadcast_ipi(_i1) ((void) 0) /* nothing */
185 #endif /* MULTIPROCESSOR */
186 
187 #endif /* !_LOCORE */
188 
189 #endif /* _XEN_INTR_H_ */
190