xen_intr.c revision 1.9.64.2 1 1.9.64.2 pgoyette /* $NetBSD: xen_intr.c,v 1.9.64.2 2019/01/18 08:50:25 pgoyette Exp $ */
2 1.2 bouyer
3 1.2 bouyer /*-
4 1.2 bouyer * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
5 1.2 bouyer * All rights reserved.
6 1.2 bouyer *
7 1.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
8 1.2 bouyer * by Charles M. Hannum, and by Jason R. Thorpe.
9 1.2 bouyer *
10 1.2 bouyer * Redistribution and use in source and binary forms, with or without
11 1.2 bouyer * modification, are permitted provided that the following conditions
12 1.2 bouyer * are met:
13 1.2 bouyer * 1. Redistributions of source code must retain the above copyright
14 1.2 bouyer * notice, this list of conditions and the following disclaimer.
15 1.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
16 1.2 bouyer * notice, this list of conditions and the following disclaimer in the
17 1.2 bouyer * documentation and/or other materials provided with the distribution.
18 1.2 bouyer *
19 1.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
30 1.2 bouyer */
31 1.2 bouyer
32 1.2 bouyer #include <sys/cdefs.h>
33 1.9.64.2 pgoyette __KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.9.64.2 2019/01/18 08:50:25 pgoyette Exp $");
34 1.2 bouyer
35 1.2 bouyer #include <sys/param.h>
36 1.9.64.1 pgoyette #include <sys/kernel.h>
37 1.9.64.1 pgoyette #include <sys/kmem.h>
38 1.9.64.1 pgoyette
39 1.9.64.1 pgoyette #include <sys/cpu.h>
40 1.9.64.1 pgoyette
41 1.9.64.1 pgoyette #include <xen/evtchn.h>
42 1.9.64.1 pgoyette
43 1.9.64.1 pgoyette #include <uvm/uvm.h>
44 1.2 bouyer
45 1.2 bouyer #include <machine/cpu.h>
46 1.2 bouyer #include <machine/intr.h>
47 1.2 bouyer
48 1.9.64.1 pgoyette #include "acpica.h"
49 1.9.64.1 pgoyette #include "ioapic.h"
50 1.9.64.1 pgoyette #include "lapic.h"
51 1.9.64.1 pgoyette #include "pci.h"
52 1.9.64.1 pgoyette
53 1.9.64.1 pgoyette #if NACPICA > 0
54 1.9.64.1 pgoyette #include <dev/acpi/acpivar.h>
55 1.9.64.1 pgoyette #endif
56 1.9.64.1 pgoyette
57 1.9.64.1 pgoyette #if NIOAPIC > 0 || NACPICA > 0
58 1.9.64.1 pgoyette #include <machine/i82093var.h>
59 1.9.64.1 pgoyette #endif
60 1.9.64.1 pgoyette
61 1.9.64.1 pgoyette #if NLAPIC > 0
62 1.9.64.1 pgoyette #include <machine/i82489var.h>
63 1.9.64.1 pgoyette #endif
64 1.9.64.1 pgoyette
65 1.9.64.1 pgoyette #if NPCI > 0
66 1.9.64.1 pgoyette #include <dev/pci/ppbreg.h>
67 1.9.64.1 pgoyette #endif
68 1.9.64.1 pgoyette
69 1.9.64.1 pgoyette void xen_disable_intr(void);
70 1.9.64.1 pgoyette void xen_enable_intr(void);
71 1.9.64.1 pgoyette u_long xen_read_psl(void);
72 1.9.64.1 pgoyette void xen_write_psl(u_long);
73 1.9.64.1 pgoyette
74 1.2 bouyer /*
75 1.2 bouyer * Restore a value to cpl (unmasking interrupts). If any unmasked
76 1.2 bouyer * interrupts are pending, call Xspllower() to process them.
77 1.2 bouyer */
78 1.2 bouyer void
79 1.2 bouyer spllower(int nlevel)
80 1.2 bouyer {
81 1.2 bouyer struct cpu_info *ci = curcpu();
82 1.9.64.1 pgoyette uint32_t xmask;
83 1.2 bouyer u_long psl;
84 1.2 bouyer
85 1.8 bouyer if (ci->ci_ilevel <= nlevel)
86 1.8 bouyer return;
87 1.8 bouyer
88 1.2 bouyer __insn_barrier();
89 1.2 bouyer
90 1.9.64.1 pgoyette xmask = XUNMASK(ci, nlevel);
91 1.9.64.1 pgoyette psl = xen_read_psl();
92 1.9.64.1 pgoyette xen_disable_intr();
93 1.9.64.1 pgoyette if (ci->ci_xpending & xmask) {
94 1.7 bouyer KASSERT(psl == 0);
95 1.2 bouyer Xspllower(nlevel);
96 1.2 bouyer /* Xspllower does enable_intr() */
97 1.2 bouyer } else {
98 1.2 bouyer ci->ci_ilevel = nlevel;
99 1.9.64.1 pgoyette xen_write_psl(psl);
100 1.2 bouyer }
101 1.2 bouyer }
102 1.2 bouyer
103 1.2 bouyer void
104 1.9.64.1 pgoyette xen_disable_intr(void)
105 1.2 bouyer {
106 1.2 bouyer __cli();
107 1.2 bouyer }
108 1.2 bouyer
109 1.2 bouyer void
110 1.9.64.1 pgoyette xen_enable_intr(void)
111 1.2 bouyer {
112 1.2 bouyer __sti();
113 1.2 bouyer }
114 1.2 bouyer
115 1.2 bouyer u_long
116 1.9.64.1 pgoyette xen_read_psl(void)
117 1.2 bouyer {
118 1.2 bouyer
119 1.4 cegger return (curcpu()->ci_vcpu->evtchn_upcall_mask);
120 1.2 bouyer }
121 1.2 bouyer
122 1.2 bouyer void
123 1.9.64.1 pgoyette xen_write_psl(u_long psl)
124 1.2 bouyer {
125 1.4 cegger struct cpu_info *ci = curcpu();
126 1.2 bouyer
127 1.4 cegger ci->ci_vcpu->evtchn_upcall_mask = psl;
128 1.9 jym xen_rmb();
129 1.4 cegger if (ci->ci_vcpu->evtchn_upcall_pending && psl == 0) {
130 1.2 bouyer hypervisor_force_callback();
131 1.2 bouyer }
132 1.2 bouyer }
133 1.9.64.1 pgoyette
134 1.9.64.1 pgoyette void *
135 1.9.64.1 pgoyette xen_intr_establish(int legacy_irq, struct pic *pic, int pin,
136 1.9.64.1 pgoyette int type, int level, int (*handler)(void *), void *arg,
137 1.9.64.1 pgoyette bool known_mpsafe)
138 1.9.64.1 pgoyette {
139 1.9.64.1 pgoyette
140 1.9.64.1 pgoyette return xen_intr_establish_xname(legacy_irq, pic, pin, type, level,
141 1.9.64.1 pgoyette handler, arg, known_mpsafe, "XEN");
142 1.9.64.1 pgoyette }
143 1.9.64.1 pgoyette
144 1.9.64.1 pgoyette void *
145 1.9.64.1 pgoyette xen_intr_establish_xname(int legacy_irq, struct pic *pic, int pin,
146 1.9.64.1 pgoyette int type, int level, int (*handler)(void *), void *arg,
147 1.9.64.1 pgoyette bool known_mpsafe, const char *xname)
148 1.9.64.1 pgoyette {
149 1.9.64.1 pgoyette const char *intrstr;
150 1.9.64.1 pgoyette char intrstr_buf[INTRIDBUF];
151 1.9.64.1 pgoyette
152 1.9.64.1 pgoyette if (pic->pic_type == PIC_XEN) {
153 1.9.64.1 pgoyette struct intrhand *rih;
154 1.9.64.1 pgoyette
155 1.9.64.1 pgoyette /*
156 1.9.64.1 pgoyette * event_set_handler interprets `level != IPL_VM' to
157 1.9.64.1 pgoyette * mean MP-safe, so we require the caller to match that
158 1.9.64.1 pgoyette * for the moment.
159 1.9.64.1 pgoyette */
160 1.9.64.1 pgoyette KASSERT(known_mpsafe == (level != IPL_VM));
161 1.9.64.1 pgoyette
162 1.9.64.1 pgoyette intrstr = intr_create_intrid(legacy_irq, pic, pin, intrstr_buf,
163 1.9.64.1 pgoyette sizeof(intrstr_buf));
164 1.9.64.1 pgoyette
165 1.9.64.1 pgoyette event_set_handler(pin, handler, arg, level, intrstr, xname);
166 1.9.64.1 pgoyette
167 1.9.64.1 pgoyette rih = kmem_zalloc(sizeof(*rih), cold ? KM_NOSLEEP : KM_SLEEP);
168 1.9.64.1 pgoyette if (rih == NULL) {
169 1.9.64.1 pgoyette printf("%s: can't allocate handler info\n", __func__);
170 1.9.64.1 pgoyette return NULL;
171 1.9.64.1 pgoyette }
172 1.9.64.1 pgoyette
173 1.9.64.1 pgoyette /*
174 1.9.64.1 pgoyette * XXX:
175 1.9.64.1 pgoyette * This is just a copy for API conformance.
176 1.9.64.1 pgoyette * The real ih is lost in the innards of
177 1.9.64.1 pgoyette * event_set_handler(); where the details of
178 1.9.64.1 pgoyette * biglock_wrapper etc are taken care of.
179 1.9.64.1 pgoyette * All that goes away when we nuke event_set_handler()
180 1.9.64.1 pgoyette * et. al. and unify with x86/intr.c
181 1.9.64.1 pgoyette */
182 1.9.64.1 pgoyette rih->ih_pin = pin; /* port */
183 1.9.64.1 pgoyette rih->ih_fun = rih->ih_realfun = handler;
184 1.9.64.1 pgoyette rih->ih_arg = rih->ih_realarg = arg;
185 1.9.64.1 pgoyette rih->pic_type = pic->pic_type;
186 1.9.64.1 pgoyette return rih;
187 1.9.64.1 pgoyette } /* Else we assume pintr */
188 1.9.64.1 pgoyette
189 1.9.64.1 pgoyette #if NPCI > 0 || NISA > 0
190 1.9.64.1 pgoyette struct pintrhand *pih;
191 1.9.64.1 pgoyette int gsi;
192 1.9.64.1 pgoyette int vector, evtchn;
193 1.9.64.1 pgoyette
194 1.9.64.1 pgoyette KASSERTMSG(legacy_irq == -1 || (0 <= legacy_irq && legacy_irq < NUM_XEN_IRQS),
195 1.9.64.1 pgoyette "bad legacy IRQ value: %d", legacy_irq);
196 1.9.64.1 pgoyette KASSERTMSG(!(legacy_irq == -1 && pic == &i8259_pic),
197 1.9.64.1 pgoyette "non-legacy IRQon i8259 ");
198 1.9.64.1 pgoyette
199 1.9.64.1 pgoyette gsi = xen_pic_to_gsi(pic, pin);
200 1.9.64.1 pgoyette
201 1.9.64.1 pgoyette intrstr = intr_create_intrid(gsi, pic, pin, intrstr_buf,
202 1.9.64.1 pgoyette sizeof(intrstr_buf));
203 1.9.64.1 pgoyette
204 1.9.64.1 pgoyette vector = xen_vec_alloc(gsi);
205 1.9.64.1 pgoyette
206 1.9.64.1 pgoyette if (irq2port[gsi] == 0) {
207 1.9.64.1 pgoyette extern struct cpu_info phycpu_info_primary; /* XXX */
208 1.9.64.1 pgoyette struct cpu_info *ci = &phycpu_info_primary;
209 1.9.64.1 pgoyette
210 1.9.64.1 pgoyette pic->pic_addroute(pic, ci, pin, vector, type);
211 1.9.64.1 pgoyette
212 1.9.64.1 pgoyette evtchn = bind_pirq_to_evtch(gsi);
213 1.9.64.1 pgoyette KASSERT(evtchn > 0);
214 1.9.64.1 pgoyette KASSERT(evtchn < NR_EVENT_CHANNELS);
215 1.9.64.1 pgoyette irq2port[gsi] = evtchn + 1;
216 1.9.64.1 pgoyette xen_atomic_set_bit(&ci->ci_evtmask[0], evtchn);
217 1.9.64.1 pgoyette } else {
218 1.9.64.1 pgoyette /*
219 1.9.64.1 pgoyette * Shared interrupt - we can't rebind.
220 1.9.64.1 pgoyette * The port is shared instead.
221 1.9.64.1 pgoyette */
222 1.9.64.1 pgoyette evtchn = irq2port[gsi] - 1;
223 1.9.64.1 pgoyette }
224 1.9.64.1 pgoyette
225 1.9.64.1 pgoyette pih = pirq_establish(gsi, evtchn, handler, arg, level,
226 1.9.64.1 pgoyette intrstr, xname);
227 1.9.64.1 pgoyette pih->pic_type = pic->pic_type;
228 1.9.64.1 pgoyette return pih;
229 1.9.64.1 pgoyette #endif /* NPCI > 0 || NISA > 0 */
230 1.9.64.1 pgoyette
231 1.9.64.1 pgoyette /* FALLTHROUGH */
232 1.9.64.1 pgoyette return NULL;
233 1.9.64.1 pgoyette }
234 1.9.64.1 pgoyette
235 1.9.64.1 pgoyette /*
236 1.9.64.1 pgoyette * Deregister an interrupt handler.
237 1.9.64.1 pgoyette */
238 1.9.64.1 pgoyette void
239 1.9.64.1 pgoyette xen_intr_disestablish(struct intrhand *ih)
240 1.9.64.1 pgoyette {
241 1.9.64.1 pgoyette
242 1.9.64.1 pgoyette if (ih->pic_type == PIC_XEN) {
243 1.9.64.1 pgoyette event_remove_handler(ih->ih_pin, ih->ih_realfun,
244 1.9.64.1 pgoyette ih->ih_realarg);
245 1.9.64.1 pgoyette kmem_free(ih, sizeof(*ih));
246 1.9.64.1 pgoyette return;
247 1.9.64.1 pgoyette }
248 1.9.64.1 pgoyette #if defined(DOM0OPS)
249 1.9.64.1 pgoyette /*
250 1.9.64.1 pgoyette * Cache state, to prevent a use after free situation with
251 1.9.64.1 pgoyette * ih.
252 1.9.64.1 pgoyette */
253 1.9.64.1 pgoyette
254 1.9.64.1 pgoyette struct pintrhand *pih = (struct pintrhand *)ih;
255 1.9.64.1 pgoyette
256 1.9.64.1 pgoyette int pirq = pih->pirq;
257 1.9.64.1 pgoyette int port = pih->evtch;
258 1.9.64.1 pgoyette KASSERT(irq2port[pirq] != 0);
259 1.9.64.1 pgoyette
260 1.9.64.1 pgoyette pirq_disestablish(pih);
261 1.9.64.1 pgoyette
262 1.9.64.1 pgoyette if (evtsource[port] == NULL) {
263 1.9.64.1 pgoyette /*
264 1.9.64.1 pgoyette * Last handler was removed by
265 1.9.64.1 pgoyette * event_remove_handler().
266 1.9.64.1 pgoyette *
267 1.9.64.1 pgoyette * We can safely unbind the pirq now.
268 1.9.64.1 pgoyette */
269 1.9.64.1 pgoyette
270 1.9.64.1 pgoyette port = unbind_pirq_from_evtch(pirq);
271 1.9.64.1 pgoyette KASSERT(port == pih->evtch);
272 1.9.64.1 pgoyette irq2port[pirq] = 0;
273 1.9.64.1 pgoyette }
274 1.9.64.1 pgoyette #endif
275 1.9.64.1 pgoyette return;
276 1.9.64.1 pgoyette }
277 1.9.64.1 pgoyette
278 1.9.64.1 pgoyette /* MI interface for kern_cpu.c */
279 1.9.64.1 pgoyette void xen_cpu_intr_redistribute(void);
280 1.9.64.1 pgoyette
281 1.9.64.1 pgoyette void
282 1.9.64.1 pgoyette xen_cpu_intr_redistribute(void)
283 1.9.64.1 pgoyette {
284 1.9.64.1 pgoyette KASSERT(mutex_owned(&cpu_lock));
285 1.9.64.1 pgoyette KASSERT(mp_online);
286 1.9.64.1 pgoyette
287 1.9.64.1 pgoyette return;
288 1.9.64.1 pgoyette }
289 1.9.64.1 pgoyette
290 1.9.64.1 pgoyette /* MD - called by x86/cpu.c */
291 1.9.64.1 pgoyette #if defined(INTRSTACKSIZE)
292 1.9.64.1 pgoyette static inline bool
293 1.9.64.1 pgoyette redzone_const_or_false(bool x)
294 1.9.64.1 pgoyette {
295 1.9.64.1 pgoyette #ifdef DIAGNOSTIC
296 1.9.64.1 pgoyette return x;
297 1.9.64.1 pgoyette #else
298 1.9.64.1 pgoyette return false;
299 1.9.64.1 pgoyette #endif /* !DIAGNOSTIC */
300 1.9.64.1 pgoyette }
301 1.9.64.1 pgoyette
302 1.9.64.1 pgoyette static inline int
303 1.9.64.1 pgoyette redzone_const_or_zero(int x)
304 1.9.64.1 pgoyette {
305 1.9.64.1 pgoyette return redzone_const_or_false(true) ? x : 0;
306 1.9.64.1 pgoyette }
307 1.9.64.1 pgoyette #endif
308 1.9.64.1 pgoyette
309 1.9.64.1 pgoyette void
310 1.9.64.1 pgoyette cpu_intr_init(struct cpu_info *ci)
311 1.9.64.1 pgoyette {
312 1.9.64.1 pgoyette int i; /* XXX: duplicate */
313 1.9.64.1 pgoyette
314 1.9.64.1 pgoyette ci->ci_xunmask[0] = 0xfffffffe;
315 1.9.64.1 pgoyette for (i = 1; i < NIPL; i++)
316 1.9.64.1 pgoyette ci->ci_xunmask[i] = ci->ci_xunmask[i - 1] & ~(1 << i);
317 1.9.64.1 pgoyette
318 1.9.64.1 pgoyette #if defined(INTRSTACKSIZE)
319 1.9.64.1 pgoyette vaddr_t istack;
320 1.9.64.1 pgoyette
321 1.9.64.1 pgoyette /*
322 1.9.64.1 pgoyette * If the red zone is activated, protect both the top and
323 1.9.64.1 pgoyette * the bottom of the stack with an unmapped page.
324 1.9.64.1 pgoyette */
325 1.9.64.1 pgoyette istack = uvm_km_alloc(kernel_map,
326 1.9.64.1 pgoyette INTRSTACKSIZE + redzone_const_or_zero(2 * PAGE_SIZE), 0,
327 1.9.64.1 pgoyette UVM_KMF_WIRED|UVM_KMF_ZERO);
328 1.9.64.1 pgoyette if (redzone_const_or_false(true)) {
329 1.9.64.1 pgoyette pmap_kremove(istack, PAGE_SIZE);
330 1.9.64.1 pgoyette pmap_kremove(istack + INTRSTACKSIZE + PAGE_SIZE, PAGE_SIZE);
331 1.9.64.1 pgoyette pmap_update(pmap_kernel());
332 1.9.64.1 pgoyette }
333 1.9.64.1 pgoyette
334 1.9.64.1 pgoyette /*
335 1.9.64.1 pgoyette * 33 used to be 1. Arbitrarily reserve 32 more register_t's
336 1.9.64.1 pgoyette * of space for ddb(4) to examine some subroutine arguments
337 1.9.64.1 pgoyette * and to hunt for the next stack frame.
338 1.9.64.1 pgoyette */
339 1.9.64.1 pgoyette ci->ci_intrstack = (char *)istack + redzone_const_or_zero(PAGE_SIZE) +
340 1.9.64.1 pgoyette INTRSTACKSIZE - 33 * sizeof(register_t);
341 1.9.64.1 pgoyette #endif
342 1.9.64.1 pgoyette
343 1.9.64.1 pgoyette ci->ci_idepth = -1;
344 1.9.64.1 pgoyette }
345 1.9.64.1 pgoyette
346 1.9.64.1 pgoyette /*
347 1.9.64.1 pgoyette * Everything below from here is duplicated from x86/intr.c
348 1.9.64.1 pgoyette * When intr.c and xen_intr.c are unified, these will need to be
349 1.9.64.1 pgoyette * merged.
350 1.9.64.1 pgoyette */
351 1.9.64.1 pgoyette
352 1.9.64.1 pgoyette u_int xen_cpu_intr_count(struct cpu_info *ci);
353 1.9.64.1 pgoyette
354 1.9.64.1 pgoyette u_int
355 1.9.64.1 pgoyette xen_cpu_intr_count(struct cpu_info *ci)
356 1.9.64.1 pgoyette {
357 1.9.64.1 pgoyette
358 1.9.64.1 pgoyette KASSERT(ci->ci_nintrhand >= 0);
359 1.9.64.1 pgoyette
360 1.9.64.1 pgoyette return ci->ci_nintrhand;
361 1.9.64.1 pgoyette }
362 1.9.64.1 pgoyette
363 1.9.64.1 pgoyette static const char *
364 1.9.64.1 pgoyette xen_intr_string(int port, char *buf, size_t len, struct pic *pic)
365 1.9.64.1 pgoyette {
366 1.9.64.1 pgoyette KASSERT(pic->pic_type == PIC_XEN);
367 1.9.64.1 pgoyette
368 1.9.64.1 pgoyette KASSERT(port >= 0);
369 1.9.64.1 pgoyette KASSERT(port < NR_EVENT_CHANNELS);
370 1.9.64.1 pgoyette
371 1.9.64.1 pgoyette snprintf(buf, len, "%s channel %d", pic->pic_name, port);
372 1.9.64.1 pgoyette
373 1.9.64.1 pgoyette return buf;
374 1.9.64.1 pgoyette }
375 1.9.64.1 pgoyette
376 1.9.64.1 pgoyette static const char *
377 1.9.64.1 pgoyette legacy_intr_string(int ih, char *buf, size_t len, struct pic *pic)
378 1.9.64.1 pgoyette {
379 1.9.64.1 pgoyette int legacy_irq;
380 1.9.64.1 pgoyette
381 1.9.64.1 pgoyette KASSERT(pic->pic_type == PIC_I8259);
382 1.9.64.1 pgoyette #if NLAPIC > 0
383 1.9.64.1 pgoyette KASSERT(APIC_IRQ_ISLEGACY(ih));
384 1.9.64.1 pgoyette
385 1.9.64.1 pgoyette legacy_irq = APIC_IRQ_LEGACY_IRQ(ih);
386 1.9.64.1 pgoyette #else
387 1.9.64.1 pgoyette legacy_irq = ih;
388 1.9.64.1 pgoyette #endif
389 1.9.64.1 pgoyette KASSERT(legacy_irq >= 0 && legacy_irq < 16);
390 1.9.64.1 pgoyette
391 1.9.64.1 pgoyette snprintf(buf, len, "%s pin %d", pic->pic_name, legacy_irq);
392 1.9.64.1 pgoyette
393 1.9.64.1 pgoyette return buf;
394 1.9.64.1 pgoyette }
395 1.9.64.1 pgoyette
396 1.9.64.1 pgoyette const char *
397 1.9.64.1 pgoyette intr_string(intr_handle_t ih, char *buf, size_t len)
398 1.9.64.1 pgoyette {
399 1.9.64.1 pgoyette #if NIOAPIC > 0
400 1.9.64.1 pgoyette struct ioapic_softc *pic;
401 1.9.64.1 pgoyette #endif
402 1.9.64.1 pgoyette
403 1.9.64.1 pgoyette if (ih == 0)
404 1.9.64.1 pgoyette panic("%s: bogus handle 0x%" PRIx64, __func__, ih);
405 1.9.64.1 pgoyette
406 1.9.64.1 pgoyette #if NIOAPIC > 0
407 1.9.64.1 pgoyette if (ih & APIC_INT_VIA_APIC) {
408 1.9.64.1 pgoyette pic = ioapic_find(APIC_IRQ_APIC(ih));
409 1.9.64.1 pgoyette if (pic != NULL) {
410 1.9.64.1 pgoyette snprintf(buf, len, "%s pin %d",
411 1.9.64.1 pgoyette device_xname(pic->sc_dev), APIC_IRQ_PIN(ih));
412 1.9.64.1 pgoyette } else {
413 1.9.64.1 pgoyette snprintf(buf, len,
414 1.9.64.1 pgoyette "apic %d int %d (irq %d)",
415 1.9.64.1 pgoyette APIC_IRQ_APIC(ih),
416 1.9.64.1 pgoyette APIC_IRQ_PIN(ih),
417 1.9.64.1 pgoyette APIC_IRQ_LEGACY_IRQ(ih));
418 1.9.64.1 pgoyette }
419 1.9.64.1 pgoyette } else
420 1.9.64.1 pgoyette snprintf(buf, len, "irq %d", APIC_IRQ_LEGACY_IRQ(ih));
421 1.9.64.1 pgoyette
422 1.9.64.1 pgoyette #elif NLAPIC > 0
423 1.9.64.1 pgoyette snprintf(buf, len, "irq %d" APIC_IRQ_LEGACY_IRQ(ih));
424 1.9.64.1 pgoyette #else
425 1.9.64.1 pgoyette snprintf(buf, len, "irq %d", (int) ih);
426 1.9.64.1 pgoyette #endif
427 1.9.64.1 pgoyette return buf;
428 1.9.64.1 pgoyette
429 1.9.64.1 pgoyette }
430 1.9.64.1 pgoyette
431 1.9.64.1 pgoyette /*
432 1.9.64.1 pgoyette * Create an interrupt id such as "ioapic0 pin 9". This interrupt id is used
433 1.9.64.1 pgoyette * by MI code and intrctl(8).
434 1.9.64.1 pgoyette */
435 1.9.64.1 pgoyette const char *
436 1.9.64.1 pgoyette intr_create_intrid(int legacy_irq, struct pic *pic, int pin, char *buf, size_t len)
437 1.9.64.1 pgoyette {
438 1.9.64.1 pgoyette int ih = 0;
439 1.9.64.1 pgoyette
440 1.9.64.1 pgoyette #if NPCI > 0
441 1.9.64.1 pgoyette #if defined(__HAVE_PCI_MSI_MSIX)
442 1.9.64.1 pgoyette if ((pic->pic_type == PIC_MSI) || (pic->pic_type == PIC_MSIX)) {
443 1.9.64.1 pgoyette uint64_t pih;
444 1.9.64.1 pgoyette int dev, vec;
445 1.9.64.1 pgoyette
446 1.9.64.1 pgoyette dev = msipic_get_devid(pic);
447 1.9.64.1 pgoyette vec = pin;
448 1.9.64.1 pgoyette pih = __SHIFTIN((uint64_t)dev, MSI_INT_DEV_MASK)
449 1.9.64.1 pgoyette | __SHIFTIN((uint64_t)vec, MSI_INT_VEC_MASK)
450 1.9.64.1 pgoyette | APIC_INT_VIA_MSI;
451 1.9.64.1 pgoyette if (pic->pic_type == PIC_MSI)
452 1.9.64.1 pgoyette MSI_INT_MAKE_MSI(pih);
453 1.9.64.1 pgoyette else if (pic->pic_type == PIC_MSIX)
454 1.9.64.1 pgoyette MSI_INT_MAKE_MSIX(pih);
455 1.9.64.1 pgoyette
456 1.9.64.1 pgoyette return x86_pci_msi_string(NULL, pih, buf, len);
457 1.9.64.1 pgoyette }
458 1.9.64.1 pgoyette #endif /* __HAVE_PCI_MSI_MSIX */
459 1.9.64.1 pgoyette #endif
460 1.9.64.1 pgoyette
461 1.9.64.1 pgoyette if (pic->pic_type == PIC_XEN) {
462 1.9.64.1 pgoyette ih = pin; /* Port == pin */
463 1.9.64.1 pgoyette return xen_intr_string(pin, buf, len, pic);
464 1.9.64.1 pgoyette }
465 1.9.64.1 pgoyette
466 1.9.64.1 pgoyette /*
467 1.9.64.1 pgoyette * If the device is pci, "legacy_irq" is alway -1. Least 8 bit of "ih"
468 1.9.64.1 pgoyette * is only used in intr_string() to show the irq number.
469 1.9.64.1 pgoyette * If the device is "legacy"(such as floppy), it should not use
470 1.9.64.1 pgoyette * intr_string().
471 1.9.64.1 pgoyette */
472 1.9.64.1 pgoyette if (pic->pic_type == PIC_I8259) {
473 1.9.64.1 pgoyette ih = legacy_irq;
474 1.9.64.1 pgoyette return legacy_intr_string(ih, buf, len, pic);
475 1.9.64.1 pgoyette }
476 1.9.64.1 pgoyette
477 1.9.64.1 pgoyette #if NIOAPIC > 0 || NACPICA > 0
478 1.9.64.1 pgoyette ih = ((pic->pic_apicid << APIC_INT_APIC_SHIFT) & APIC_INT_APIC_MASK)
479 1.9.64.1 pgoyette | ((pin << APIC_INT_PIN_SHIFT) & APIC_INT_PIN_MASK);
480 1.9.64.1 pgoyette if (pic->pic_type == PIC_IOAPIC) {
481 1.9.64.1 pgoyette ih |= APIC_INT_VIA_APIC;
482 1.9.64.1 pgoyette }
483 1.9.64.1 pgoyette ih |= pin;
484 1.9.64.1 pgoyette return intr_string(ih, buf, len);
485 1.9.64.1 pgoyette #endif
486 1.9.64.1 pgoyette
487 1.9.64.1 pgoyette return NULL; /* No pic found! */
488 1.9.64.1 pgoyette }
489 1.9.64.1 pgoyette
490 1.9.64.1 pgoyette __weak_alias(x86_disable_intr, xen_disable_intr);
491 1.9.64.1 pgoyette __weak_alias(x86_enable_intr, xen_enable_intr);
492 1.9.64.1 pgoyette __weak_alias(x86_read_psl, xen_read_psl);
493 1.9.64.1 pgoyette __weak_alias(x86_write_psl, xen_write_psl);
494 1.9.64.1 pgoyette
495 1.9.64.1 pgoyette __weak_alias(intr_establish, xen_intr_establish);
496 1.9.64.1 pgoyette __weak_alias(intr_establish_xname, xen_intr_establish_xname);
497 1.9.64.1 pgoyette __weak_alias(intr_disestablish, xen_intr_disestablish);
498 1.9.64.1 pgoyette __weak_alias(cpu_intr_redistribute, xen_cpu_intr_redistribute);
499 1.9.64.1 pgoyette __weak_alias(cpu_intr_count, xen_cpu_intr_count);
500 1.9.64.1 pgoyette
501