Module Name:    src
Committed By:   jdolecek
Date:           Tue Apr 21 20:13:40 UTC 2020

Modified Files:
        src/sys/arch/amd64/amd64: machdep.c
        src/sys/arch/i386/i386: machdep.c
        src/sys/arch/xen/include: hypervisor.h i82093var.h
        src/sys/arch/xen/include/amd64: hypercalls.h
        src/sys/arch/xen/include/i386: hypercalls.h
        src/sys/arch/xen/x86: hypervisor_machdep.c pintr.c
        src/sys/arch/xen/xen: evtchn.c

Log Message:
convert to newer HYPERVISOR_physdev_op() interface, now command and the
arg are separate arguments - this is needed for newer physdev_op commands

remove code for PHYSDEVOP_IRQ_UNMASK_NOTIFY, it is obsolete since
interface version 0x00030202 and is unsupported by newer versions of Xen

confirmed working on amd64 Dom0, i386 compile-tested only


To generate a diff of this commit:
cvs rdiff -u -r1.346 -r1.347 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.825 -r1.826 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/xen/include/hypervisor.h
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/xen/include/i82093var.h
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/xen/include/amd64/hypercalls.h
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/xen/include/i386/hypercalls.h
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/xen/x86/hypervisor_machdep.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/xen/x86/pintr.c
cvs rdiff -u -r1.89 -r1.90 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/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.346 src/sys/arch/amd64/amd64/machdep.c:1.347
--- src/sys/arch/amd64/amd64/machdep.c:1.346	Fri Jan 31 08:21:11 2020
+++ src/sys/arch/amd64/amd64/machdep.c	Tue Apr 21 20:13:39 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.346 2020/01/31 08:21:11 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.347 2020/04/21 20:13:39 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.346 2020/01/31 08:21:11 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.347 2020/04/21 20:13:39 jdolecek Exp $");
 
 #include "opt_modular.h"
 #include "opt_user_ldt.h"
@@ -428,10 +428,9 @@ void
 x86_64_switch_context(struct pcb *new)
 {
 	HYPERVISOR_stack_switch(GSEL(GDATA_SEL, SEL_KPL), new->pcb_rsp0);
-	struct physdev_op physop;
-	physop.cmd = PHYSDEVOP_SET_IOPL;
-	physop.u.set_iopl.iopl = new->pcb_iopl;
-	HYPERVISOR_physdev_op(&physop);
+	struct physdev_set_iopl set_iopl;
+	set_iopl.iopl = new->pcb_iopl;
+	HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl);
 }
 
 void
@@ -489,14 +488,13 @@ x86_64_proc0_pcb_ldt_init(void)
 #if !defined(XENPV)
 	lldt(GSYSSEL(GLDT_SEL, SEL_KPL));
 #else
-	struct physdev_op physop;
 	xen_set_ldt((vaddr_t)ldtstore, LDT_SIZE >> 3);
 	/* Reset TS bit and set kernel stack for interrupt handlers */
 	HYPERVISOR_fpu_taskswitch(1);
 	HYPERVISOR_stack_switch(GSEL(GDATA_SEL, SEL_KPL), pcb->pcb_rsp0);
-	physop.cmd = PHYSDEVOP_SET_IOPL;
-	physop.u.set_iopl.iopl = pcb->pcb_iopl;
-	HYPERVISOR_physdev_op(&physop);
+	struct physdev_set_iopl set_iopl;
+	set_iopl.iopl = pcb->pcb_iopl;
+	HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl);
 #endif
 }
 

Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.825 src/sys/arch/i386/i386/machdep.c:1.826
--- src/sys/arch/i386/i386/machdep.c:1.825	Fri Jan 31 08:21:11 2020
+++ src/sys/arch/i386/i386/machdep.c	Tue Apr 21 20:13:39 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.825 2020/01/31 08:21:11 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.826 2020/04/21 20:13:39 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009, 2017
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.825 2020/01/31 08:21:11 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.826 2020/04/21 20:13:39 jdolecek Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_freebsd.h"
@@ -494,15 +494,14 @@ void
 i386_switch_context(lwp_t *l)
 {
 	struct pcb *pcb;
-	struct physdev_op physop;
 
 	pcb = lwp_getpcb(l);
 
 	HYPERVISOR_stack_switch(GSEL(GDATA_SEL, SEL_KPL), pcb->pcb_esp0);
 
-	physop.cmd = PHYSDEVOP_SET_IOPL;
-	physop.u.set_iopl.iopl = pcb->pcb_iopl;
-	HYPERVISOR_physdev_op(&physop);
+	struct physdev_set_iopl set_iopl;
+	set_iopl.iopl = pcb->pcb_iopl;
+	HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl);
 }
 
 void

Index: src/sys/arch/xen/include/hypervisor.h
diff -u src/sys/arch/xen/include/hypervisor.h:1.49 src/sys/arch/xen/include/hypervisor.h:1.50
--- src/sys/arch/xen/include/hypervisor.h:1.49	Mon Feb  4 18:14:53 2019
+++ src/sys/arch/xen/include/hypervisor.h	Tue Apr 21 20:13:39 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor.h,v 1.49 2019/02/04 18:14:53 cherry Exp $	*/
+/*	$NetBSD: hypervisor.h,v 1.50 2020/04/21 20:13:39 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -147,10 +147,6 @@ extern volatile shared_info_t *HYPERVISO
 struct intrframe;
 struct cpu_info;
 void do_hypervisor_callback(struct intrframe *regs);
-#if NPCI > 0 || NISA > 0
-void hypervisor_prime_pirq_event(int, unsigned int);
-void hypervisor_ack_pirq_event(unsigned int);
-#endif /* NPCI > 0 || NISA > 0 */
 
 extern int xen_version;
 #define XEN_MAJOR(x) (((x) & 0xffff0000) >> 16)

Index: src/sys/arch/xen/include/i82093var.h
diff -u src/sys/arch/xen/include/i82093var.h:1.5 src/sys/arch/xen/include/i82093var.h:1.6
--- src/sys/arch/xen/include/i82093var.h:1.5	Sat Nov  4 09:31:08 2017
+++ src/sys/arch/xen/include/i82093var.h	Tue Apr 21 20:13:39 2020
@@ -1,4 +1,4 @@
-/*	 $NetBSD: i82093var.h,v 1.5 2017/11/04 09:31:08 cherry Exp $ */
+/*	 $NetBSD: i82093var.h,v 1.6 2020/04/21 20:13:39 jdolecek Exp $ */
 
 #ifndef _XEN_I82093VAR_H_
 #define _XEN_I82093VAR_H_
@@ -11,31 +11,29 @@
 static inline  uint32_t
 ioapic_read_ul(struct ioapic_softc *sc, int regid)
 {
-	physdev_op_t op;
+	struct physdev_apic apic_op;
 	int ret;
 
-        op.cmd = PHYSDEVOP_APIC_READ;
-	op.u.apic_op.apic_physbase = sc->sc_pa;
-	op.u.apic_op.reg = regid;
-	ret = HYPERVISOR_physdev_op(&op);
+	apic_op.apic_physbase = sc->sc_pa;
+	apic_op.reg = regid;
+	ret = HYPERVISOR_physdev_op(PHYSDEVOP_apic_read, &apic_op);
 	if (ret) {
 		printf("PHYSDEVOP_APIC_READ ret %d\n", ret);
 		panic("PHYSDEVOP_APIC_READ");
 	}
-	return op.u.apic_op.value;      
+	return apic_op.value;      
 }
 
 static inline void
 ioapic_write_ul(struct ioapic_softc *sc, int regid, uint32_t val)
 {
-	physdev_op_t op;
+	struct physdev_apic apic_op;
 	int ret;
 
-        op.cmd = PHYSDEVOP_APIC_WRITE;
-	op.u.apic_op.apic_physbase = sc->sc_pa;
-	op.u.apic_op.reg = regid;
-	op.u.apic_op.value = val;
-	ret = HYPERVISOR_physdev_op(&op);
+	apic_op.apic_physbase = sc->sc_pa;
+	apic_op.reg = regid;
+	apic_op.value = val;
+	ret = HYPERVISOR_physdev_op(PHYSDEVOP_apic_write, &apic_op);
 	if (ret)
 		printf("PHYSDEVOP_APIC_WRITE ret %d\n", ret);
 }

Index: src/sys/arch/xen/include/amd64/hypercalls.h
diff -u src/sys/arch/xen/include/amd64/hypercalls.h:1.12 src/sys/arch/xen/include/amd64/hypercalls.h:1.13
--- src/sys/arch/xen/include/amd64/hypercalls.h:1.12	Sun Feb 10 11:10:34 2019
+++ src/sys/arch/xen/include/amd64/hypercalls.h	Tue Apr 21 20:13:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: hypercalls.h,v 1.12 2019/02/10 11:10:34 cherry Exp $ */
+/* $NetBSD: hypercalls.h,v 1.13 2020/04/21 20:13:39 jdolecek Exp $ */
 /******************************************************************************
  * hypercall.h
  * 
@@ -274,9 +274,9 @@ HYPERVISOR_console_io(
 }
 
 static inline int
-HYPERVISOR_physdev_op(void *op)
+HYPERVISOR_physdev_op(int cmd, void *op)
 {
-	return _hypercall1(int, physdev_op_compat, op);
+	return _hypercall2(int, physdev_op, cmd, op);
 }
 
 static inline int

Index: src/sys/arch/xen/include/i386/hypercalls.h
diff -u src/sys/arch/xen/include/i386/hypercalls.h:1.19 src/sys/arch/xen/include/i386/hypercalls.h:1.20
--- src/sys/arch/xen/include/i386/hypercalls.h:1.19	Sun Feb 10 11:10:34 2019
+++ src/sys/arch/xen/include/i386/hypercalls.h	Tue Apr 21 20:13:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypercalls.h,v 1.19 2019/02/10 11:10:34 cherry Exp $	*/
+/*	$NetBSD: hypercalls.h,v 1.20 2020/04/21 20:13:40 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -533,13 +533,13 @@ HYPERVISOR_console_io(int cmd, int count
 }
 
 static __inline int
-HYPERVISOR_physdev_op(void *physdev_op)
+HYPERVISOR_physdev_op(int cmd, void *physdev_op)
 {
     int ret;
-    unsigned long ign1;
+    unsigned long ign1, ign2;
 
-    _hypercall(__HYPERVISOR_physdev_op, _harg("1" (physdev_op)),
-	_harg("=a" (ret), "=b" (ign1)));
+    _hypercall(__HYPERVISOR_physdev_op, _harg("1" (cmd), "2" (physdev_op)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
 
     return ret;
 }

Index: src/sys/arch/xen/x86/hypervisor_machdep.c
diff -u src/sys/arch/xen/x86/hypervisor_machdep.c:1.36 src/sys/arch/xen/x86/hypervisor_machdep.c:1.37
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.36	Thu May  9 17:09:51 2019
+++ src/sys/arch/xen/x86/hypervisor_machdep.c	Tue Apr 21 20:13:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor_machdep.c,v 1.36 2019/05/09 17:09:51 bouyer Exp $	*/
+/*	$NetBSD: hypervisor_machdep.c,v 1.37 2020/04/21 20:13:40 jdolecek Exp $	*/
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.36 2019/05/09 17:09:51 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.37 2020/04/21 20:13:40 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -378,9 +378,6 @@ evt_enable_event(unsigned int port, unsi
 {
 	KASSERT(args == NULL);
 	hypervisor_unmask_event(port);
-#if NPCI > 0 || NISA > 0
-	hypervisor_ack_pirq_event(port);
-#endif /* NPCI > 0 || NISA > 0 */
 }
 
 void

Index: src/sys/arch/xen/x86/pintr.c
diff -u src/sys/arch/xen/x86/pintr.c:1.11 src/sys/arch/xen/x86/pintr.c:1.12
--- src/sys/arch/xen/x86/pintr.c:1.11	Tue Apr  7 07:43:33 2020
+++ src/sys/arch/xen/x86/pintr.c	Tue Apr 21 20:13:40 2020
@@ -103,7 +103,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.11 2020/04/07 07:43:33 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.12 2020/04/21 20:13:40 jdolecek Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -163,22 +163,21 @@ static int vect2irq[256] = {0};
 int
 xen_vec_alloc(int gsi)
 {
-	physdev_op_t op;
-
 	KASSERT(gsi < 255);
 
 	if (irq2port[gsi] == 0) {
-		op.cmd = PHYSDEVOP_ASSIGN_VECTOR;
-		op.u.irq_op.irq = gsi;
-		if (HYPERVISOR_physdev_op(&op) < 0) {
+		struct physdev_irq irq_op;
+		irq_op.irq = gsi;
+		if (HYPERVISOR_physdev_op(PHYSDEVOP_alloc_irq_vector,
+		    &irq_op) < 0) {
 			panic("PHYSDEVOP_ASSIGN_VECTOR gsi %d", gsi);
 		}
 		KASSERT(irq2vect[gsi] == 0 ||
-			irq2vect[gsi] == op.u.irq_op.vector);
-		irq2vect[gsi] = op.u.irq_op.vector;
-		KASSERT(vect2irq[op.u.irq_op.vector] == 0 ||
-			 vect2irq[op.u.irq_op.vector] == gsi);
-		vect2irq[op.u.irq_op.vector] = gsi;
+			irq2vect[gsi] == irq_op.vector);
+		irq2vect[gsi] = irq_op.vector;
+		KASSERT(vect2irq[irq_op.vector] == 0 ||
+			 vect2irq[irq_op.vector] == gsi);
+		vect2irq[irq_op.vector] = gsi;
 	}
 
 	return (irq2vect[gsi]);

Index: src/sys/arch/xen/xen/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.89 src/sys/arch/xen/xen/evtchn.c:1.90
--- src/sys/arch/xen/xen/evtchn.c:1.89	Mon Apr 13 22:54:12 2020
+++ src/sys/arch/xen/xen/evtchn.c	Tue Apr 21 20:13:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.89 2020/04/13 22:54:12 bouyer Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.90 2020/04/21 20:13:40 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.89 2020/04/13 22:54:12 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.90 2020/04/21 20:13:40 jdolecek Exp $");
 
 #include "opt_xen.h"
 #include "isa.h"
@@ -108,12 +108,7 @@ static int virq_to_evtch[NR_VIRQS];
 #if NPCI > 0 || NISA > 0
 /* event-channel <-> PIRQ mapping */
 static int pirq_to_evtch[NR_PIRQS];
-/* PIRQ needing notify */
-static uint32_t pirq_needs_unmask_notify[NR_EVENT_CHANNELS / 32];
 int pirq_interrupt(void *);
-physdev_op_t physdev_op_notify = {
-	.cmd = PHYSDEVOP_IRQ_UNMASK_NOTIFY,
-};
 #endif
 
 static void xen_evtchn_mask(struct pic *, int);
@@ -239,8 +234,6 @@ events_default_setup(void)
 	/* No PIRQ -> event mappings. */
 	for (i = 0; i < NR_PIRQS; i++)
 		pirq_to_evtch[i] = -1;
-	for (i = 0; i < NR_EVENT_CHANNELS / 32; i++)
-		pirq_needs_unmask_notify[i] = 0;
 #endif
 
 	/* No event-channel are 'live' right now. */
@@ -271,9 +264,6 @@ events_init(void)
 	evtsource[debug_port] = (void *)-1;
 	xen_atomic_set_bit(&curcpu()->ci_evtmask[0], debug_port);
 	hypervisor_unmask_event(debug_port);
-#if NPCI > 0 || NISA > 0
-	hypervisor_ack_pirq_event(debug_port);
-#endif /* NPCI > 0 || NISA > 0 */
 #endif /* XENPV */
 	x86_enable_intr();		/* at long last... */
 }
@@ -336,9 +326,6 @@ evtchn_do_event(int evtch, struct intrfr
 	if (__predict_false(evtch == debug_port)) {
 		xen_debug_handler(NULL);
 		hypervisor_unmask_event(debug_port);
-#if NPCI > 0 || NISA > 0
-		hypervisor_ack_pirq_event(debug_port);
-#endif /* NPCI > 0 || NISA > 0 */		
 		return 0;
 	}
 
@@ -399,9 +386,6 @@ evtchn_do_event(int evtch, struct intrfr
 	mutex_spin_exit(&evtlock[evtch]);
 	x86_disable_intr();
 	hypervisor_unmask_event(evtch);
-#if NPCI > 0 || NISA > 0
-	hypervisor_ack_pirq_event(evtch);
-#endif /* NPCI > 0 || NISA > 0 */		
 
 splx:
 	/*
@@ -769,9 +753,7 @@ pirq_establish(int pirq, int evtch, int 
 		return NULL;
 	}
 
-	hypervisor_prime_pirq_event(pirq, evtch);
 	hypervisor_unmask_event(evtch);
-	hypervisor_ack_pirq_event(evtch);
 	return ih;
 }
 
@@ -1018,42 +1000,6 @@ event_remove_handler(int evtch, int (*fu
 	return 0;
 }
 
-#if NPCI > 0 || NISA > 0
-void
-hypervisor_prime_pirq_event(int pirq, unsigned int evtch)
-{
-	physdev_op_t physdev_op;
-	physdev_op.cmd = PHYSDEVOP_IRQ_STATUS_QUERY;
-	physdev_op.u.irq_status_query.irq = pirq;
-	if (HYPERVISOR_physdev_op(&physdev_op) < 0)
-		panic("HYPERVISOR_physdev_op(PHYSDEVOP_IRQ_STATUS_QUERY)");
-	if (physdev_op.u.irq_status_query.flags &
-	    PHYSDEVOP_IRQ_NEEDS_UNMASK_NOTIFY) {
-		pirq_needs_unmask_notify[evtch >> 5] |= (1 << (evtch & 0x1f));
-#ifdef IRQ_DEBUG
-		printf("pirq %d needs notify\n", pirq);
-#endif
-	}
-}
-
-void
-hypervisor_ack_pirq_event(unsigned int evtch)
-{
-#ifdef IRQ_DEBUG
-	if (evtch == IRQ_DEBUG)
-		printf("%s: evtch %d\n", __func__, evtch);
-#endif
-
-	if (pirq_needs_unmask_notify[evtch >> 5] & (1 << (evtch & 0x1f))) {
-#ifdef  IRQ_DEBUG
-		if (evtch == IRQ_DEBUG)
-		    printf("pirq_notify(%d)\n", evtch);
-#endif
-		(void)HYPERVISOR_physdev_op(&physdev_op_notify);
-	}
-}
-#endif /* NPCI > 0 || NISA > 0 */
-
 int
 xen_debug_handler(void *arg)
 {

Reply via email to