Module Name:    src
Committed By:   jdolecek
Date:           Sun Jun 24 13:35:33 UTC 2018

Modified Files:
        src/sys/arch/x86/include: intr.h
        src/sys/arch/x86/isa: isa_machdep.c
        src/sys/arch/x86/x86: intr.c
        src/sys/arch/xen/include: evtchn.h intr.h
        src/sys/arch/xen/x86: xen_ipi.c
        src/sys/arch/xen/xen: clock.c evtchn.c pciback.c xencons.c
        src/sys/arch/xen/xenbus: xenbus_comms.c

Log Message:
add support for kern.intr.list aka intrctl(8) 'list' for xen

event_set_handler() and pirq_establish() now have extra intrname
parameter; shared intr_create_intrid() is used to provide the value

xen drivers were changed to pass the specific driver instance
name as the xname, e.g.  'vcpu0 clock' instead just 'clock', or
'xencons0' instead of 'xencons'

associated evcnt is now changed to use intrname - this matches native x86


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/arch/x86/include/intr.h
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/x86/isa/isa_machdep.c
cvs rdiff -u -r1.125 -r1.126 src/sys/arch/x86/x86/intr.c
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/xen/include/evtchn.h
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/xen/x86/xen_ipi.c
cvs rdiff -u -r1.66 -r1.67 src/sys/arch/xen/xen/clock.c
cvs rdiff -u -r1.79 -r1.80 src/sys/arch/xen/xen/evtchn.c
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/xen/xen/pciback.c
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/xen/xen/xencons.c
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/xen/xenbus/xenbus_comms.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/include/intr.h
diff -u src/sys/arch/x86/include/intr.h:1.55 src/sys/arch/x86/include/intr.h:1.56
--- src/sys/arch/x86/include/intr.h:1.55	Wed Apr  4 22:52:58 2018
+++ src/sys/arch/x86/include/intr.h	Sun Jun 24 13:35:33 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.55 2018/04/04 22:52:58 christos Exp $	*/
+/*	$NetBSD: intr.h,v 1.56 2018/06/24 13:35:33 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -222,9 +222,7 @@ int intr_find_mpmapping(int, int, intr_h
 struct pic *intr_findpic(int);
 void intr_printconfig(void);
 
-#if !defined(XEN)
 const char *intr_create_intrid(int, struct pic *, int, char *, size_t);
-#endif /* XEN */
 struct intrsource *intr_allocate_io_intrsource(const char *);
 void intr_free_io_intrsource(const char *);
 

Index: src/sys/arch/x86/isa/isa_machdep.c
diff -u src/sys/arch/x86/isa/isa_machdep.c:1.38 src/sys/arch/x86/isa/isa_machdep.c:1.39
--- src/sys/arch/x86/isa/isa_machdep.c:1.38	Wed Dec 13 16:30:18 2017
+++ src/sys/arch/x86/isa/isa_machdep.c	Sun Jun 24 13:35:33 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: isa_machdep.c,v 1.38 2017/12/13 16:30:18 bouyer Exp $	*/
+/*	$NetBSD: isa_machdep.c,v 1.39 2018/06/24 13:35:33 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.38 2017/12/13 16:30:18 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.39 2018/06/24 13:35:33 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -241,25 +241,22 @@ isa_intr_establish_xname(isa_chipset_tag
 	KASSERT(APIC_IRQ_ISLEGACY(irq));
 
 	int evtch;
-	char evname[16];
+	const char *intrstr;
+	char intrstr_buf[INTRIDBUF];
 
 	mpih |= APIC_IRQ_LEGACY_IRQ(irq);
 
 	evtch = xen_pirq_alloc(&mpih, type); /* XXX: legacy - xen just tosses irq back at us */
 	if (evtch == -1)
 		return NULL;
-#if NIOAPIC > 0
-	if (ioapic)
-		snprintf(evname, sizeof(evname), "%s pin %d",
-		    device_xname(ioapic->sc_dev), pin);
-	else
-#endif
-		snprintf(evname, sizeof(evname), "irq%d", irq);
+
+	intrstr = intr_create_intrid(irq, pic, pin, intrstr_buf,
+	    sizeof(intrstr_buf));
 
 	aprint_debug("irq: %d requested on pic: %s.\n", irq, pic->pic_name);
 
 	return (void *)pirq_establish(irq, evtch, ih_fun, ih_arg, level,
-	    evname);
+	    intrstr, xname);
 #else /* defined(XEN) */
 	return intr_establish_xname(irq, pic, pin, type, level, ih_fun, ih_arg,
 	    false, xname);

Index: src/sys/arch/x86/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.125 src/sys/arch/x86/x86/intr.c:1.126
--- src/sys/arch/x86/x86/intr.c:1.125	Wed Apr  4 22:52:59 2018
+++ src/sys/arch/x86/x86/intr.c	Sun Jun 24 13:35:33 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.125 2018/04/04 22:52:59 christos Exp $	*/
+/*	$NetBSD: intr.c,v 1.126 2018/06/24 13:35:33 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.125 2018/04/04 22:52:59 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.126 2018/06/24 13:35:33 jdolecek Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -238,12 +238,13 @@ static void intr_source_free(struct cpu_
 
 static void intr_establish_xcall(void *, void *);
 static void intr_disestablish_xcall(void *, void *);
+#endif
 
 static const char *legacy_intr_string(int, char *, size_t, struct pic *);
+
 #if defined(XEN) /* XXX: nuke conditional after integration */
 static const char *xen_intr_string(int, char *, size_t, struct pic *);
 #endif /* XXX: XEN */
-#endif
 
 #if defined(INTRSTACKSIZE)
 static inline bool redzone_const_or_false(bool);
@@ -489,7 +490,6 @@ intr_scan_bus(int bus, int pin, intr_han
 }
 #endif
 
-#if !defined(XEN)
 /*
  * Create an interrupt id such as "ioapic0 pin 9". This interrupt id is used
  * by MI code and intrctl(8).
@@ -551,8 +551,6 @@ intr_create_intrid(int legacy_irq, struc
 	return NULL; /* No pic found! */
 }
 
-#endif /* XEN */
-
 /*
  * Find intrsource from io_interrupt_sources list.
  */
@@ -869,6 +867,7 @@ intr_findpic(int num)
 	return NULL;
 }
 #endif
+
 #if !defined(XEN)
 /*
  * Append device name to intrsource. If device A and device B share IRQ number,
@@ -1222,6 +1221,9 @@ intr_establish_xname(int legacy_irq, str
     int type, int level, int (*handler)(void *), void *arg,
     bool known_mpsafe, const char *xname)
 {
+	const char *intrstr;
+	char intrstr_buf[INTRIDBUF];
+
 	if (pic->pic_type == PIC_XEN) {
 		struct intrhand *rih;
 
@@ -1232,7 +1234,10 @@ intr_establish_xname(int legacy_irq, str
 		 */
 		KASSERT(known_mpsafe == (level != IPL_VM));
 
-		event_set_handler(pin, handler, arg, level, xname);
+		intrstr = intr_create_intrid(legacy_irq, pic, pin, intrstr_buf,
+		    sizeof(intrstr_buf));
+
+		event_set_handler(pin, handler, arg, level, intrstr, xname);
 
 		rih = kmem_zalloc(sizeof(*rih), cold ? KM_NOSLEEP : KM_SLEEP);
 		if (rih == NULL) {
@@ -1260,7 +1265,6 @@ intr_establish_xname(int legacy_irq, str
 	struct pintrhand *pih;
 	intr_handle_t irq;
 	int evtchn;
-	char evname[16];
 
 	KASSERTMSG(legacy_irq == -1 || (0 <= legacy_irq && legacy_irq < 16),
 	    "bad legacy IRQ value: %d", legacy_irq);
@@ -1273,19 +1277,19 @@ intr_establish_xname(int legacy_irq, str
 		irq = APIC_INT_VIA_APIC;
 		irq |= pic->pic_apicid << APIC_INT_APIC_SHIFT;
 		irq |= pin << APIC_INT_PIN_SHIFT;
-		snprintf(evname, sizeof(evname), "%s pin %d",
-		    pic->pic_name, pin);
 #else /* NIOAPIC */
 		return NULL;
 #endif /* NIOAPIC */
 	} else {
-		snprintf(evname, sizeof(evname), "irq%d", legacy_irq);
 		irq = legacy_irq;
 	}
 
+	intrstr = intr_create_intrid(irq, pic, pin, intrstr_buf,
+	    sizeof(intrstr_buf));
+
 	evtchn = xen_pirq_alloc(&irq, type);
 	pih = pirq_establish(irq & 0xff, evtchn, handler, arg, level,
-	    evname);
+	    intrstr, xname);
 	pih->pic_type = pic->pic_type;
 	return pih;
 #endif /* NPCI > 0 || NISA > 0 */
@@ -1342,7 +1346,6 @@ intr_disestablish(struct intrhand *ih)
 #endif /* XEN */
 }
 
-#if !defined(XEN)
 #if defined(XEN) /* nuke conditional post integration */
 static const char *
 xen_intr_string(int port, char *buf, size_t len, struct pic *pic)
@@ -1356,7 +1359,7 @@ xen_intr_string(int port, char *buf, siz
 
 	return buf;
 }
-#endif /* XXX: XEN */
+#endif /* XEN */
 
 static const char *
 legacy_intr_string(int ih, char *buf, size_t len, struct pic *pic)
@@ -1377,7 +1380,6 @@ legacy_intr_string(int ih, char *buf, si
 
 	return buf;
 }
-#endif
 
 const char *
 intr_string(intr_handle_t ih, char *buf, size_t len)
@@ -2128,7 +2130,7 @@ intr_set_affinity(struct intrsource *isp
 
 	return err;
 }
-#endif /* XEN */
+
 static bool
 intr_is_affinity_intrsource(struct intrsource *isp, const kcpuset_t *cpuset)
 {
@@ -2163,7 +2165,6 @@ intr_get_handler(const char *intrid)
 	return isp->is_handlers;
 }
 
-#if !defined(XEN)
 /*
  * MI interface for subr_interrupt.c
  */
@@ -2209,8 +2210,6 @@ interrupt_get_count(const char *intrid, 
 	return count;
 }
 
-#endif /* XEN */
-
 /*
  * MI interface for subr_interrupt.c
  */
@@ -2235,7 +2234,7 @@ interrupt_get_assigned(const char *intri
 	mutex_exit(&cpu_lock);
 }
 
-#if !defined(XEN)
+#endif /* XEN */
 
 /*
  * MI interface for subr_interrupt.c
@@ -2257,6 +2256,8 @@ interrupt_get_available(kcpuset_t *cpuse
 	mutex_exit(&cpu_lock);
 }
 
+#if !defined(XEN)
+
 /*
  * MI interface for subr_interrupt.c
  */
@@ -2348,7 +2349,6 @@ interrupt_distribute_handler(const char 
 	mutex_exit(&intr_distribute_lock);
 	return error;
 }
-#endif
 
 /*
  * MI interface for subr_interrupt.c
@@ -2403,6 +2403,7 @@ interrupt_construct_intrids(const kcpuse
 
 	return ii_handler;
 }
+#endif /* !XEN */
 
 /*
  * MI interface for subr_interrupt.c

Index: src/sys/arch/xen/include/evtchn.h
diff -u src/sys/arch/xen/include/evtchn.h:1.25 src/sys/arch/xen/include/evtchn.h:1.26
--- src/sys/arch/xen/include/evtchn.h:1.25	Sat Nov  4 14:56:48 2017
+++ src/sys/arch/xen/include/evtchn.h	Sun Jun 24 13:35:32 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.h,v 1.25 2017/11/04 14:56:48 cherry Exp $	*/
+/*	$NetBSD: evtchn.h,v 1.26 2018/06/24 13:35:32 jdolecek Exp $	*/
 
 /*
  *
@@ -41,7 +41,8 @@ bool events_resume(void);
 unsigned int evtchn_do_event(int, struct intrframe *);
 void call_evtchn_do_event(int, struct intrframe *);
 void call_xenevt_event(int);
-int event_set_handler(int, int (*func)(void *), void *, int, const char *);
+int event_set_handler(int, int (*func)(void *), void *, int, const char *,
+    const char *);
 int event_remove_handler(int, int (*func)(void *), void *);
 
 struct cpu_info;
@@ -69,7 +70,7 @@ struct pintrhand {
 };
 
 struct pintrhand *pirq_establish(int, int, int (*)(void *), void *, int,
-     const char *);
+     const char *, const char *);
 void pirq_disestablish(struct pintrhand *);
 
 #endif /*  _XEN_EVENTS_H_ */

Index: src/sys/arch/xen/include/intr.h
diff -u src/sys/arch/xen/include/intr.h:1.45 src/sys/arch/xen/include/intr.h:1.46
--- src/sys/arch/xen/include/intr.h:1.45	Wed Dec 13 16:30:18 2017
+++ src/sys/arch/xen/include/intr.h	Sun Jun 24 13:35:32 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.45 2017/12/13 16:30:18 bouyer Exp $	*/
+/*	$NetBSD: intr.h,v 1.46 2018/06/24 13:35:32 jdolecek Exp $	*/
 /*	NetBSD intr.h,v 1.15 2004/10/31 10:39:34 yamt Exp	*/
 
 /*-
@@ -57,7 +57,8 @@ struct evtsource {
 	struct intrhand *ev_handlers;	/* handler chain */
 	struct evcnt ev_evcnt;		/* interrupt counter */
 	struct cpu_info *ev_cpu;        /* cpu on which this event is bound */
-	char ev_evname[32];		/* event counter name */
+	char ev_intrname[32];		/* interrupt string */
+	char ev_xname[64];		/* handler device list */
 };
 
 extern struct intrstub xenev_stubs[];

Index: src/sys/arch/xen/x86/xen_ipi.c
diff -u src/sys/arch/xen/x86/xen_ipi.c:1.24 src/sys/arch/xen/x86/xen_ipi.c:1.25
--- src/sys/arch/xen/x86/xen_ipi.c:1.24	Sat Jun 23 15:53:14 2018
+++ src/sys/arch/xen/x86/xen_ipi.c	Sun Jun 24 13:35:32 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_ipi.c,v 1.24 2018/06/23 15:53:14 jdolecek Exp $ */
+/* $NetBSD: xen_ipi.c,v 1.25 2018/06/24 13:35:32 jdolecek Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -33,10 +33,10 @@
 
 /* 
  * Based on: x86/ipi.c
- * __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.24 2018/06/23 15:53:14 jdolecek Exp $");
+ * __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.25 2018/06/24 13:35:32 jdolecek Exp $");
  */
 
-__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.24 2018/06/23 15:53:14 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.25 2018/06/24 13:35:32 jdolecek Exp $");
 
 #include "opt_ddb.h"
 
@@ -122,6 +122,7 @@ xen_ipi_init(void)
 	cpuid_t vcpu;
 	evtchn_port_t evtchn;
 	struct cpu_info *ci;
+	char intr_xname[INTRDEVNAMEBUF];
 
 	ci = curcpu();
 
@@ -133,8 +134,11 @@ xen_ipi_init(void)
 
 	KASSERT(evtchn != -1 && evtchn < NR_EVENT_CHANNELS);
 
-	if(intr_establish_xname(0, &xen_pic, evtchn, IST_LEVEL, IPL_HIGH,
-		xen_ipi_handler, ci, true, "ipi") == NULL) {
+	snprintf(intr_xname, sizeof(intr_xname), "%s ipi",
+	    device_xname(ci->ci_dev));
+
+	if (intr_establish_xname(0, &xen_pic, evtchn, IST_LEVEL, IPL_HIGH,
+		xen_ipi_handler, ci, true, intr_xname) == NULL) {
 		panic("%s: unable to register ipi handler\n", __func__);
 		/* NOTREACHED */
 	}
@@ -215,7 +219,6 @@ xen_broadcast_ipi(uint32_t ipimask)
 }
 
 /* MD wrapper for the xcall(9) callback. */
-#define PRIuCPUID	"lu" /* XXX: move this somewhere more appropriate */
 
 static void
 xen_ipi_halt(struct cpu_info *ci, struct intrframe *intrf)
@@ -223,7 +226,7 @@ xen_ipi_halt(struct cpu_info *ci, struct
 	KASSERT(ci == curcpu());
 	KASSERT(ci != NULL);
 	if (HYPERVISOR_vcpu_op(VCPUOP_down, ci->ci_cpuid, NULL)) {
-		panic("vcpu%" PRIuCPUID "shutdown failed.\n", ci->ci_cpuid);
+		panic("%s shutdown failed.\n", device_xname(ci->ci_dev));
 	}
 
 }

Index: src/sys/arch/xen/xen/clock.c
diff -u src/sys/arch/xen/xen/clock.c:1.66 src/sys/arch/xen/xen/clock.c:1.67
--- src/sys/arch/xen/xen/clock.c:1.66	Fri May 11 13:24:46 2018
+++ src/sys/arch/xen/xen/clock.c	Sun Jun 24 13:35:33 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.66 2018/05/11 13:24:46 cherry Exp $	*/
+/*	$NetBSD: clock.c,v 1.67 2018/06/24 13:35:33 jdolecek Exp $	*/
 
 /*
  *
@@ -29,7 +29,7 @@
 #include "opt_xen.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.66 2018/05/11 13:24:46 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.67 2018/06/24 13:35:33 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -519,19 +519,24 @@ xen_suspendclocks(struct cpu_info *ci)
 void
 xen_resumeclocks(struct cpu_info *ci)
 {
+	char intr_xname[INTRDEVNAMEBUF];
 	int evtch;
        
 	evtch = bind_virq_to_evtch(VIRQ_TIMER);
 	KASSERT(evtch != -1);
 
+	snprintf(intr_xname, sizeof(intr_xname), "%s clock",
+	    device_xname(ci->ci_dev));
+
 	ih = intr_establish_xname(0, &xen_pic, evtch, IST_LEVEL, IPL_CLOCK,
-	    xen_timer_handler_stub, ci, true, "clock");
+	    xen_timer_handler_stub, ci, true, intr_xname);
 
 	KASSERT(ih != NULL);
 
 	hypervisor_enable_event(evtch);
 
-	aprint_verbose("Xen clock: using event channel %d\n", evtch);
+	aprint_verbose("Xen %s: using event channel %d\n",
+	    intr_xname, evtch);
 }
 
 /* ARGSUSED */

Index: src/sys/arch/xen/xen/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.79 src/sys/arch/xen/xen/evtchn.c:1.80
--- src/sys/arch/xen/xen/evtchn.c:1.79	Wed Dec 13 16:30:18 2017
+++ src/sys/arch/xen/xen/evtchn.c	Sun Jun 24 13:35:33 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.79 2017/12/13 16:30:18 bouyer Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.80 2018/06/24 13:35:33 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.79 2017/12/13 16:30:18 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.80 2018/06/24 13:35:33 jdolecek Exp $");
 
 #include "opt_xen.h"
 #include "isa.h"
@@ -69,6 +69,7 @@ __KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1
 #include <sys/kmem.h>
 #include <sys/reboot.h>
 #include <sys/mutex.h>
+#include <sys/interrupt.h>
 
 #include <uvm/uvm.h>
 
@@ -733,7 +734,7 @@ unbind_pirq_from_evtch(int pirq)
 
 struct pintrhand *
 pirq_establish(int pirq, int evtch, int (*func)(void *), void *arg, int level,
-    const char *evname)
+    const char *intrname, const char *xname)
 {
 	struct pintrhand *ih;
 	physdev_op_t physdev_op;
@@ -752,7 +753,8 @@ pirq_establish(int pirq, int evtch, int 
 	ih->func = func;
 	ih->arg = arg;
 
-	if (event_set_handler(evtch, pirq_interrupt, ih, level, evname) != 0) {
+	if (event_set_handler(evtch, pirq_interrupt, ih, level, intrname,
+	    xname) != 0) {
 		kmem_free(ih, sizeof(struct pintrhand));
 		return NULL;
 	}
@@ -789,7 +791,6 @@ pirq_interrupt(void *arg)
 	struct pintrhand *ih = arg;
 	int ret;
 
-
 	ret = ih->func(ih->arg);
 #ifdef IRQ_DEBUG
 	if (ih->evtch == IRQ_DEBUG)
@@ -832,7 +833,7 @@ intr_calculatemasks(struct evtsource *ev
 
 int
 event_set_handler(int evtch, int (*func)(void *), void *arg, int level,
-    const char *evname)
+    const char *intrname, const char *xname)
 {
 	struct cpu_info *ci = curcpu(); /* XXX: pass in ci ? */
 	struct evtsource *evts;
@@ -849,6 +850,7 @@ event_set_handler(int evtch, int (*func)
 	KASSERTMSG(evtch >= 0, "negative evtch: %d", evtch);
 	KASSERTMSG(evtch < NR_EVENT_CHANNELS,
 	    "evtch number %d > NR_EVENT_CHANNELS", evtch);
+	KASSERT(intrname != NULL && xname != NULL);
 
 #if 0
 	printf("event_set_handler evtch %d handler %p level %d\n", evtch,
@@ -894,14 +896,10 @@ event_set_handler(int evtch, int (*func)
 		evts->ev_cpu = ci;
 		mutex_init(&evtlock[evtch], MUTEX_DEFAULT, IPL_HIGH);
 		evtsource[evtch] = evts;
-		if (evname)
-			strncpy(evts->ev_evname, evname,
-			    sizeof(evts->ev_evname));
-		else
-			snprintf(evts->ev_evname, sizeof(evts->ev_evname),
-			    "evt%d", evtch);
+		strlcpy(evts->ev_intrname, intrname, sizeof(evts->ev_intrname));
+
 		evcnt_attach_dynamic(&evts->ev_evcnt, EVCNT_TYPE_INTR, NULL,
-		    device_xname(ci->ci_dev), evts->ev_evname);
+		    device_xname(ci->ci_dev), evts->ev_intrname);
 	} else {
 		evts = evtsource[evtch];
 		/* sort by IPL order, higher first */
@@ -921,6 +919,12 @@ event_set_handler(int evtch, int (*func)
 		mutex_spin_exit(&evtlock[evtch]);
 	}
 
+
+	// append device name
+	if (evts->ev_xname[0] != '\0')
+		strlcat(evts->ev_xname, ", ", sizeof(evts->ev_xname));
+	strlcat(evts->ev_xname, xname, sizeof(evts->ev_xname));
+
 	intr_calculatemasks(evts, evtch, ci);
 	splx(s);
 
@@ -1059,3 +1063,131 @@ xen_debug_handler(void *arg)
 	printf("\n");
 	return 0;
 }
+
+static struct evtsource *
+event_get_handler(const char *intrid)
+{
+	for (int i = 0; i < NR_EVENT_CHANNELS; i++) {
+		if (evtsource[i] == NULL || i == debug_port)
+			continue;
+
+		struct evtsource *evp = evtsource[i];
+
+		if (strcmp(evp->ev_intrname, intrid) == 0)
+			return evp;
+	}
+
+	return NULL;
+}
+
+/*
+ * MI interface for subr_interrupt.c
+ */
+uint64_t
+interrupt_get_count(const char *intrid, u_int cpu_idx)
+{
+	int count = 0;
+	struct evtsource *evp;
+
+	mutex_spin_enter(&evtchn_lock);
+
+	evp = event_get_handler(intrid);
+	if (evp != NULL && cpu_idx == cpu_index(evp->ev_cpu))
+		count = evp->ev_evcnt.ev_count;
+
+	mutex_spin_exit(&evtchn_lock);
+
+	return count;
+}
+
+/*
+ * MI interface for subr_interrupt.c
+ */
+void
+interrupt_get_assigned(const char *intrid, kcpuset_t *cpuset)
+{
+	struct evtsource *evp;
+
+	kcpuset_zero(cpuset);
+
+	mutex_spin_enter(&evtchn_lock);
+
+	evp = event_get_handler(intrid);
+	if (evp != NULL)
+		kcpuset_set(cpuset, cpu_index(evp->ev_cpu));
+
+	mutex_spin_exit(&evtchn_lock);
+}
+
+/*
+ * MI interface for subr_interrupt.c
+ */
+void
+interrupt_get_devname(const char *intrid, char *buf, size_t len)
+{
+	struct evtsource *evp;
+
+	mutex_spin_enter(&evtchn_lock);
+
+	evp = event_get_handler(intrid);
+	strlcpy(buf, evp ? evp->ev_xname : "unknown", len);
+
+	mutex_spin_exit(&evtchn_lock);
+}
+
+/*
+ * MI interface for subr_interrupt.
+ */
+struct intrids_handler *
+interrupt_construct_intrids(const kcpuset_t *cpuset)
+{
+	struct intrids_handler *ii_handler;
+	intrid_t *ids;
+	int i, count, off;
+	struct evtsource *evp;
+
+	if (kcpuset_iszero(cpuset))
+		return 0;
+
+	/*
+	 * Count the number of interrupts which affinity to any cpu of "cpuset".
+	 */
+	count = 0;
+	for (i = 0; i < NR_EVENT_CHANNELS; i++) {
+		evp = evtsource[i];
+
+		if (evp == NULL || i == debug_port)
+			continue;
+
+		if (!kcpuset_isset(cpuset, cpu_index(evp->ev_cpu)))
+			continue;
+
+		count++;
+	}
+
+	ii_handler = kmem_zalloc(sizeof(int) + sizeof(intrid_t) * count,
+	    KM_SLEEP);
+	if (ii_handler == NULL)
+		return NULL;
+	ii_handler->iih_nids = count;
+	if (count == 0)
+		return ii_handler;
+
+	ids = ii_handler->iih_intrids;
+	mutex_spin_enter(&evtchn_lock);
+	for (i = 0, off = 0; i < NR_EVENT_CHANNELS && off < count; i++) {
+		evp = evtsource[i];
+
+		if (evp == NULL || i == debug_port)
+			continue;
+
+		if (!kcpuset_isset(cpuset, cpu_index(evp->ev_cpu)))
+			continue;
+
+		snprintf(ids[off], sizeof(intrid_t), "%s", evp->ev_intrname);
+		off++;
+	}
+	mutex_spin_exit(&evtchn_lock);
+
+	return ii_handler;
+}

Index: src/sys/arch/xen/xen/pciback.c
diff -u src/sys/arch/xen/xen/pciback.c:1.12 src/sys/arch/xen/xen/pciback.c:1.13
--- src/sys/arch/xen/xen/pciback.c:1.12	Sun Jul 16 06:14:24 2017
+++ src/sys/arch/xen/xen/pciback.c	Sun Jun 24 13:35:33 2018
@@ -1,4 +1,4 @@
-/*      $NetBSD: pciback.c,v 1.12 2017/07/16 06:14:24 cherry Exp $      */
+/*      $NetBSD: pciback.c,v 1.13 2018/06/24 13:35:33 jdolecek Exp $      */
 
 /*
  * Copyright (c) 2009 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pciback.c,v 1.12 2017/07/16 06:14:24 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pciback.c,v 1.13 2018/06/24 13:35:33 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -619,7 +619,7 @@ pciback_xenbus_frontend_changed(void *ar
 		xenbus_switch_state(xbusd, NULL, XenbusStateConnected);
 		x86_sfence();
 		event_set_handler(pbxi->pbx_evtchn, pciback_xenbus_evthandler,
-		    pbxi, IPL_BIO, "pciback");
+		    pbxi, IPL_BIO, "pciback", "pciback"); // XXX intr info?
 		hypervisor_enable_event(pbxi->pbx_evtchn);
 		hypervisor_notify_via_evtchn(pbxi->pbx_evtchn);
 		break;

Index: src/sys/arch/xen/xen/xencons.c
diff -u src/sys/arch/xen/xen/xencons.c:1.43 src/sys/arch/xen/xen/xencons.c:1.44
--- src/sys/arch/xen/xen/xencons.c:1.43	Sat Nov 11 21:03:01 2017
+++ src/sys/arch/xen/xen/xencons.c	Sun Jun 24 13:35:33 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: xencons.c,v 1.43 2017/11/11 21:03:01 riastradh Exp $	*/
+/*	$NetBSD: xencons.c,v 1.44 2018/06/24 13:35:33 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xencons.c,v 1.43 2017/11/11 21:03:01 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xencons.c,v 1.44 2018/06/24 13:35:33 jdolecek Exp $");
 
 #include "opt_xen.h"
 
@@ -230,19 +230,20 @@ xencons_resume(device_t dev, const pmf_q
 	int evtch = -1;
 
 	if (xendomain_is_dom0()) {
-	/* dom0 console resume is required only during first start-up */
+		/* dom0 console resume is required only during first start-up */
 		if (cold) {
 			evtch = bind_virq_to_evtch(VIRQ_CONSOLE);
 			ih = intr_establish_xname(0, &xen_pic, evtch,
 			    IST_LEVEL, IPL_TTY, xencons_intr,
-			    xencons_console_device, false, "xencons");
+			    xencons_console_device, false,
+			    device_xname(dev));
 			KASSERT(ih != NULL);
 		}
 	} else {
 		evtch = xen_start_info.console_evtchn;
 		ih = intr_establish_xname(0, &xen_pic, evtch,
 		    IST_LEVEL, IPL_TTY, xencons_handler,
-		    xencons_console_device, false, "xencons");
+		    xencons_console_device, false, device_xname(dev));
 		KASSERT(ih != NULL);
 	}
 

Index: src/sys/arch/xen/xenbus/xenbus_comms.c
diff -u src/sys/arch/xen/xenbus/xenbus_comms.c:1.17 src/sys/arch/xen/xenbus/xenbus_comms.c:1.18
--- src/sys/arch/xen/xenbus/xenbus_comms.c:1.17	Mon Nov 13 02:12:29 2017
+++ src/sys/arch/xen/xenbus/xenbus_comms.c	Sun Jun 24 13:35:33 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus_comms.c,v 1.17 2017/11/13 02:12:29 riastradh Exp $ */
+/* $NetBSD: xenbus_comms.c,v 1.18 2018/06/24 13:35:33 jdolecek Exp $ */
 /******************************************************************************
  * xenbus_comms.c
  *
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xenbus_comms.c,v 1.17 2017/11/13 02:12:29 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenbus_comms.c,v 1.18 2018/06/24 13:35:33 jdolecek Exp $");
 
 #include <sys/types.h>
 #include <sys/null.h> 
@@ -222,7 +222,7 @@ xb_init_comms(device_t dev)
 	evtchn = xen_start_info.store_evtchn;
 
 	ih = intr_establish_xname(0, &xen_pic, evtchn, IST_LEVEL, IPL_TTY,
-	    wake_waiting, NULL, false, "xenbus");
+	    wake_waiting, NULL, false, device_xname(dev));
 
 	hypervisor_enable_event(evtchn);
 	aprint_verbose_dev(dev, "using event channel %d\n", evtchn);

Reply via email to