Module Name:    src
Committed By:   bouyer
Date:           Sun Apr 19 11:40:31 UTC 2020

Modified Files:
        src/sys/arch/x86/include [bouyer-xenpvh]: intr.h
        src/sys/arch/x86/x86 [bouyer-xenpvh]: intr.c x86_softintr.c
        src/sys/arch/xen/include [bouyer-xenpvh]: evtchn.h
        src/sys/arch/xen/x86 [bouyer-xenpvh]: xen_intr.c
        src/sys/arch/xen/xen [bouyer-xenpvh]: evtchn.c

Log Message:
Add a struct pic * member to struct intrhand.
This will be used for interrupt_get_count()
For Xen remplace pic_type with a pointer to the pic, and add a pointer
to intrhand, in struct pintrhand
Make event_set_handler return the pointer to struct intrhand.
Don't allocate a fake intrhand in xen_intr_establish_xname(), use the
one returned by event_set_handler().


To generate a diff of this commit:
cvs rdiff -u -r1.61.6.3 -r1.61.6.4 src/sys/arch/x86/include/intr.h
cvs rdiff -u -r1.150.6.3 -r1.150.6.4 src/sys/arch/x86/x86/intr.c
cvs rdiff -u -r1.1.2.1 -r1.1.2.2 src/sys/arch/x86/x86/x86_softintr.c
cvs rdiff -u -r1.28 -r1.28.2.1 src/sys/arch/xen/include/evtchn.h
cvs rdiff -u -r1.21.2.5 -r1.21.2.6 src/sys/arch/xen/x86/xen_intr.c
cvs rdiff -u -r1.88.2.6 -r1.88.2.7 src/sys/arch/xen/xen/evtchn.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.61.6.3 src/sys/arch/x86/include/intr.h:1.61.6.4
--- src/sys/arch/x86/include/intr.h:1.61.6.3	Thu Apr 16 08:46:35 2020
+++ src/sys/arch/x86/include/intr.h	Sun Apr 19 11:40:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.61.6.3 2020/04/16 08:46:35 bouyer Exp $	*/
+/*	$NetBSD: intr.h,v 1.61.6.4 2020/04/19 11:40:30 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001, 2006, 2007, 2008, 2019 The NetBSD Foundation, Inc.
@@ -130,19 +130,7 @@ struct intrsource {
  */
 
 struct intrhand {
-#if defined(XEN)
-	/*
-	 * Note: This is transitional and will go away.
-	 * The only current consumer is xen_intr_disestablish()
-	 *
-	 * We ought to use a union here, but too much effort.
-	 * We use this field to tear down the cookie handed to us
-	 * via x86/intr.c:intr_disestablish();
-	 * Interestingly, the intr_establish_xname() function returns
-	 * a "void *" - so we abuse this for now.
-	 */
-	int	pic_type; /* Overloading wrt struct pintrhand */
-#endif
+	struct pic *ih_pic;
 	int	(*ih_fun)(void *);
 	void	*ih_arg;
 	int	ih_level;

Index: src/sys/arch/x86/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.150.6.3 src/sys/arch/x86/x86/intr.c:1.150.6.4
--- src/sys/arch/x86/x86/intr.c:1.150.6.3	Thu Apr 16 09:45:57 2020
+++ src/sys/arch/x86/x86/intr.c	Sun Apr 19 11:40:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.150.6.3 2020/04/16 09:45:57 bouyer Exp $	*/
+/*	$NetBSD: intr.c,v 1.150.6.4 2020/04/19 11:40:30 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008, 2009, 2019 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.150.6.3 2020/04/16 09:45:57 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.150.6.4 2020/04/19 11:40:30 bouyer Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -880,6 +880,7 @@ intr_establish_xname(int legacy_irq, str
 		/* nothing */;
 	}
 
+	ih->ih_pic = pic;
 	ih->ih_fun = ih->ih_realfun = handler;
 	ih->ih_arg = ih->ih_realarg = arg;
 	ih->ih_prevp = p;
@@ -1302,6 +1303,7 @@ cpu_intr_init(struct cpu_info *ci)
 	isp = kmem_zalloc(sizeof(*isp), KM_SLEEP);
 	isp->is_recurse = Xrecurse_lapic_ltimer;
 	isp->is_resume = Xresume_lapic_ltimer;
+	fake_timer_intrhand.ih_pic = &local_pic;
 	fake_timer_intrhand.ih_level = IPL_CLOCK;
 	isp->is_handlers = &fake_timer_intrhand;
 	isp->is_pic = &local_pic;
@@ -1315,6 +1317,7 @@ cpu_intr_init(struct cpu_info *ci)
 	isp = kmem_zalloc(sizeof(*isp), KM_SLEEP);
 	isp->is_recurse = Xrecurse_lapic_ipi;
 	isp->is_resume = Xresume_lapic_ipi;
+	fake_ipi_intrhand.ih_pic = &local_pic;
 	fake_ipi_intrhand.ih_level = IPL_HIGH;
 	isp->is_handlers = &fake_ipi_intrhand;
 	isp->is_pic = &local_pic;

Index: src/sys/arch/x86/x86/x86_softintr.c
diff -u src/sys/arch/x86/x86/x86_softintr.c:1.1.2.1 src/sys/arch/x86/x86/x86_softintr.c:1.1.2.2
--- src/sys/arch/x86/x86/x86_softintr.c:1.1.2.1	Sat Apr 11 18:26:07 2020
+++ src/sys/arch/x86/x86/x86_softintr.c	Sun Apr 19 11:40:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_softintr.c,v 1.1.2.1 2020/04/11 18:26:07 bouyer Exp $	*/
+/*	$NetBSD: x86_softintr.c,v 1.1.2.2 2020/04/19 11:40:30 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008, 2009, 2019 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: x86_softintr.c,v 1.1.2.1 2020/04/11 18:26:07 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_softintr.c,v 1.1.2.2 2020/04/19 11:40:30 bouyer Exp $");
 
 #include <sys/kmem.h>
 #include <sys/proc.h>
@@ -226,6 +226,7 @@ x86_init_preempt(struct cpu_info *ci)
 	isp = kmem_zalloc(sizeof(*isp), KM_SLEEP);
 	isp->is_recurse = Xrecurse_preempt;
 	isp->is_resume = Xresume_preempt;
+	fake_preempt_intrhand.ih_pic = &softintr_pic;
 	fake_preempt_intrhand.ih_level = IPL_PREEMPT;
 	isp->is_handlers = &fake_preempt_intrhand;
 	isp->is_pic = &softintr_pic;
@@ -256,21 +257,25 @@ softint_init_md(lwp_t *l, u_int level, u
 	switch (level) {
 	case SOFTINT_BIO:
 		sir = SIR_BIO;
+		fake_softbio_intrhand.ih_pic = &softintr_pic;
 		fake_softbio_intrhand.ih_level = IPL_SOFTBIO;
 		isp->is_handlers = &fake_softbio_intrhand;
 		break;
 	case SOFTINT_NET:
 		sir = SIR_NET;
+		fake_softnet_intrhand.ih_pic = &softintr_pic;
 		fake_softnet_intrhand.ih_level = IPL_SOFTNET;
 		isp->is_handlers = &fake_softnet_intrhand;
 		break;
 	case SOFTINT_SERIAL:
 		sir = SIR_SERIAL;
+		fake_softserial_intrhand.ih_pic = &softintr_pic;
 		fake_softserial_intrhand.ih_level = IPL_SOFTSERIAL;
 		isp->is_handlers = &fake_softserial_intrhand;
 		break;
 	case SOFTINT_CLOCK:
 		sir = SIR_CLOCK;
+		fake_softclock_intrhand.ih_pic = &softintr_pic;
 		fake_softclock_intrhand.ih_level = IPL_SOFTCLOCK;
 		isp->is_handlers = &fake_softclock_intrhand;
 		break;

Index: src/sys/arch/xen/include/evtchn.h
diff -u src/sys/arch/xen/include/evtchn.h:1.28 src/sys/arch/xen/include/evtchn.h:1.28.2.1
--- src/sys/arch/xen/include/evtchn.h:1.28	Mon Apr  6 19:26:00 2020
+++ src/sys/arch/xen/include/evtchn.h	Sun Apr 19 11:40:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.h,v 1.28 2020/04/06 19:26:00 jdolecek Exp $	*/
+/*	$NetBSD: evtchn.h,v 1.28.2.1 2020/04/19 11:40:30 bouyer Exp $	*/
 
 /*
  *
@@ -62,7 +62,8 @@ evtchn_port_t bind_vcpu_to_evtch(cpuid_t
 
 struct pintrhand {
 	/* See comments in x86/include/intr.h:struct intrhand {} */
-	int pic_type;
+	struct pic *pic;
+	struct intrhand *ih;
 	int pirq;
 	int evtch;
 	int (*func)(void *);

Index: src/sys/arch/xen/x86/xen_intr.c
diff -u src/sys/arch/xen/x86/xen_intr.c:1.21.2.5 src/sys/arch/xen/x86/xen_intr.c:1.21.2.6
--- src/sys/arch/xen/x86/xen_intr.c:1.21.2.5	Thu Apr 16 08:46:35 2020
+++ src/sys/arch/xen/x86/xen_intr.c	Sun Apr 19 11:40:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_intr.c,v 1.21.2.5 2020/04/16 08:46:35 bouyer Exp $	*/
+/*	$NetBSD: xen_intr.c,v 1.21.2.6 2020/04/19 11:40:30 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.21.2.5 2020/04/16 08:46:35 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.21.2.6 2020/04/19 11:40:30 bouyer Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -138,28 +138,14 @@ xen_intr_establish_xname(int legacy_irq,
 		intrstr = intr_create_intrid(legacy_irq, pic, pin, intrstr_buf,
 		    sizeof(intrstr_buf));
 
-		event_set_handler(pin, handler, arg, level, intrstr, xname,
-		    known_mpsafe);
+		rih = event_set_handler(pin, handler, arg, level,
+		    intrstr, xname, known_mpsafe);
 
-		rih = kmem_zalloc(sizeof(*rih), cold ? KM_NOSLEEP : KM_SLEEP);
 		if (rih == NULL) {
-			printf("%s: can't allocate handler info\n", __func__);
+			printf("%s: can't establish interrupt", __func__);
 			return NULL;
 		}
 
-		/*
-		 * XXX:
-		 * This is just a copy for API conformance.
-		 * The real ih is lost in the innards of
-		 * event_set_handler(); where the details of
-		 * biglock_wrapper etc are taken care of.
-		 * All that goes away when we nuke event_set_handler()
-		 * et. al. and unify with x86/intr.c
-		 */
-		rih->ih_pin = pin; /* port */
-		rih->ih_fun = rih->ih_realfun = handler;
-		rih->ih_arg = rih->ih_realarg = arg;
-		rih->pic_type = pic->pic_type;
 		return rih;
 	} 	/* Else we assume pintr */
 
@@ -201,7 +187,7 @@ xen_intr_establish_xname(int legacy_irq,
 
 	pih = pirq_establish(gsi, evtchn, handler, arg, level,
 			     intrstr, xname, known_mpsafe);
-	pih->pic_type = pic->pic_type;
+	pih->pic = pic;
 	return pih;
 #endif /* NPCI > 0 || NISA > 0 */
 
@@ -236,10 +222,10 @@ void
 xen_intr_disestablish(struct intrhand *ih)
 {
 
-	if (ih->pic_type == PIC_XEN) {
+	if (ih->ih_pic->pic_type == PIC_XEN) {
 		event_remove_handler(ih->ih_pin, ih->ih_realfun,
 		    ih->ih_realarg);
-		kmem_free(ih, sizeof(*ih));
+		/* event_remove_handler frees ih */
 		return;
 	}
 #if defined(DOM0OPS)

Index: src/sys/arch/xen/xen/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.88.2.6 src/sys/arch/xen/xen/evtchn.c:1.88.2.7
--- src/sys/arch/xen/xen/evtchn.c:1.88.2.6	Sat Apr 18 20:36:31 2020
+++ src/sys/arch/xen/xen/evtchn.c	Sun Apr 19 11:40:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.88.2.6 2020/04/18 20:36:31 bouyer Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.88.2.7 2020/04/19 11:40:30 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.88.2.6 2020/04/18 20:36:31 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.88.2.7 2020/04/19 11:40:30 bouyer Exp $");
 
 #include "opt_xen.h"
 #include "isa.h"
@@ -800,7 +800,7 @@ intr_calculatemasks(struct evtsource *ev
 	mutex_spin_exit(&evtlock[evtch]);
 }
 
-int
+struct intrhand *
 event_set_handler(int evtch, int (*func)(void *), void *arg, int level,
     const char *intrname, const char *xname, bool mpsafe)
 {
@@ -827,12 +827,14 @@ event_set_handler(int evtch, int (*func)
 		panic("can't allocate fixed interrupt source");
 
 
+	ih->ih_pic = &xen_pic;
 	ih->ih_level = level;
 	ih->ih_fun = ih->ih_realfun = func;
 	ih->ih_arg = ih->ih_realarg = arg;
 	ih->ih_evt_next = NULL;
 	ih->ih_next = NULL;
 	ih->ih_cpu = ci;
+	ih->ih_pin = evtch;
 #ifdef MULTIPROCESSOR
 	if (!mpsafe) {
 		ih->ih_fun = xen_intr_biglock_wrapper;
@@ -894,7 +896,7 @@ event_set_handler(int evtch, int (*func)
 	intr_calculatemasks(evts, evtch, ci);
 	splx(s);
 
-	return 0;
+	return ih;
 }
 
 void

Reply via email to