CVS commit: src/sys/arch

2019-02-14 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Feb 14 08:18:26 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: locore.S machdep.c spl.S vector.S
src/sys/arch/amd64/include: frame.h
src/sys/arch/i386/i386: machdep.c vector.S
src/sys/arch/i386/include: frame.h frameasm.h
src/sys/arch/x86/include: cpu.h intr.h
src/sys/arch/x86/x86: cpu.c intr.c mainbus.c pmap.c x86_machdep.c
src/sys/arch/xen/conf: files.xen
src/sys/arch/xen/x86: xen_intr.c xen_mainbus.c
src/sys/arch/xen/xen: hypervisor.c if_xennet_xenbus.c
Added Files:
src/sys/arch/amd64/conf: XEN3_PVHVM
src/sys/arch/i386/conf: XEN3PAE_PVHVM

Log Message:
Welcome XENPVHVM mode.

It is UP only, has xbd(4) and xennet(4) as PV drivers.

The console is com0 at isa and the native portion is very
rudimentary AT architecture, so is probably suboptimal to
run without PV support.


To generate a diff of this commit:
cvs rdiff -u -r1.177 -r1.178 src/sys/arch/amd64/amd64/locore.S
cvs rdiff -u -r1.325 -r1.326 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/amd64/amd64/spl.S
cvs rdiff -u -r1.67 -r1.68 src/sys/arch/amd64/amd64/vector.S
cvs rdiff -u -r0 -r1.1 src/sys/arch/amd64/conf/XEN3_PVHVM
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/amd64/include/frame.h
cvs rdiff -u -r0 -r1.1 src/sys/arch/i386/conf/XEN3PAE_PVHVM
cvs rdiff -u -r1.815 -r1.816 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.81 -r1.82 src/sys/arch/i386/i386/vector.S
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/i386/include/frame.h
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/i386/include/frameasm.h
cvs rdiff -u -r1.103 -r1.104 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/x86/include/intr.h
cvs rdiff -u -r1.165 -r1.166 src/sys/arch/x86/x86/cpu.c
cvs rdiff -u -r1.142 -r1.143 src/sys/arch/x86/x86/intr.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/x86/x86/mainbus.c
cvs rdiff -u -r1.322 -r1.323 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.122 -r1.123 src/sys/arch/x86/x86/x86_machdep.c
cvs rdiff -u -r1.177 -r1.178 src/sys/arch/xen/conf/files.xen
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/xen/x86/xen_intr.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/xen/x86/xen_mainbus.c
cvs rdiff -u -r1.71 -r1.72 src/sys/arch/xen/xen/hypervisor.c
cvs rdiff -u -r1.84 -r1.85 src/sys/arch/xen/xen/if_xennet_xenbus.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/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.177 src/sys/arch/amd64/amd64/locore.S:1.178
--- src/sys/arch/amd64/amd64/locore.S:1.177	Wed Feb 13 05:36:59 2019
+++ src/sys/arch/amd64/amd64/locore.S	Thu Feb 14 08:18:25 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.177 2019/02/13 05:36:59 cherry Exp $	*/
+/*	$NetBSD: locore.S,v 1.178 2019/02/14 08:18:25 cherry Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -1112,7 +1112,7 @@ ENTRY(cpu_switchto)
 .Lskip_svs:
 #endif
 
-#ifndef XENPV
+#ifndef XEN
 	movq	%r13,%rdi
 	movq	%r12,%rsi
 	callq	_C_LABEL(speculation_barrier)

Index: src/sys/arch/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.325 src/sys/arch/amd64/amd64/machdep.c:1.326
--- src/sys/arch/amd64/amd64/machdep.c:1.325	Mon Feb 11 14:59:32 2019
+++ src/sys/arch/amd64/amd64/machdep.c	Thu Feb 14 08:18:25 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.325 2019/02/11 14:59:32 cherry Exp $	*/
+/*	$NetBSD: machdep.c,v 1.326 2019/02/14 08:18:25 cherry Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.325 2019/02/11 14:59:32 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.326 2019/02/14 08:18:25 cherry Exp $");
 
 #include "opt_modular.h"
 #include "opt_user_ldt.h"
@@ -193,7 +193,9 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 
 #include 
 #include 
 #include 
-#endif
+#include 
+#include 
+#endif /* XEN */
 
 #ifdef DDB
 #include 
@@ -1693,7 +1695,7 @@ init_x86_64(paddr_t first_avail)
 	svs_init();
 #endif
 	cpu_init_msrs(_info_primary, true);
-#ifndef XENPV
+#ifndef XEN
 	cpu_speculation_init(_info_primary);
 #endif
 
@@ -1905,6 +1907,7 @@ init_x86_64(paddr_t first_avail)
 	(unsigned long) Xsyscall))
 		panic("HYPERVISOR_set_callbacks() failed");
 #endif /* XENPV */
+
 	cpu_init_idt();
 
 	init_x86_64_ksyms();

Index: src/sys/arch/amd64/amd64/spl.S
diff -u src/sys/arch/amd64/amd64/spl.S:1.39 src/sys/arch/amd64/amd64/spl.S:1.40
--- src/sys/arch/amd64/amd64/spl.S:1.39	Mon Feb 11 14:59:32 2019
+++ src/sys/arch/amd64/amd64/spl.S	Thu Feb 14 08:18:25 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: spl.S,v 1.39 2019/02/11 14:59:32 cherry Exp $	*/
+/*	$NetBSD: spl.S,v 1.40 2019/02/14 08:18:25 cherry Exp $	*/
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -211,7 +211,9 @@ IDTVEC(resume_preempt)
 	cli
 	jmp	*%r13			/* back to Xdoreti */
 IDTVEC_END(resume_preempt)
+#endif /* XEN */
 
+#ifndef XENPV
 /*
  * void 

CVS commit: src/sys/arch

2019-02-13 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Feb 14 07:12:40 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: amd64_mainbus.c db_interface.c
src/sys/arch/i386/i386: db_interface.c
src/sys/arch/x86/x86: cpu.c

Log Message:
Fix NLAPIC, NISA and NIOAPIC related conditional compile errors.

This will allow us to now compile an amd64 kernel without PCI.

No functional changes.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/amd64/amd64/amd64_mainbus.c
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/amd64/amd64/db_interface.c
cvs rdiff -u -r1.83 -r1.84 src/sys/arch/i386/i386/db_interface.c
cvs rdiff -u -r1.164 -r1.165 src/sys/arch/x86/x86/cpu.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/amd64_mainbus.c
diff -u src/sys/arch/amd64/amd64/amd64_mainbus.c:1.4 src/sys/arch/amd64/amd64/amd64_mainbus.c:1.5
--- src/sys/arch/amd64/amd64/amd64_mainbus.c:1.4	Sat Dec 22 08:35:04 2018
+++ src/sys/arch/amd64/amd64/amd64_mainbus.c	Thu Feb 14 07:12:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: amd64_mainbus.c,v 1.4 2018/12/22 08:35:04 maxv Exp $	*/
+/*	$NetBSD: amd64_mainbus.c,v 1.5 2019/02/14 07:12:40 cherry Exp $	*/
 /*	NetBSD: mainbus.c,v 1.39 2018/12/02 08:19:44 cherry Exp 	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: amd64_mainbus.c,v 1.4 2018/12/22 08:35:04 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amd64_mainbus.c,v 1.5 2019/02/14 07:12:40 cherry Exp $");
 
 #include 
 #include 
@@ -155,7 +155,7 @@ amd64_mainbus_match(device_t parent, cfd
 void
 amd64_mainbus_attach(device_t parent, device_t self, void *aux)
 {
-#if NPCI > 0 || NACPICA > 0 || NIPMI > 0
+#if NISA > 0 || NPCI > 0 || NACPICA > 0 || NIPMI > 0
 	union amd64_mainbus_attach_args mba;
 #endif
 

Index: src/sys/arch/amd64/amd64/db_interface.c
diff -u src/sys/arch/amd64/amd64/db_interface.c:1.35 src/sys/arch/amd64/amd64/db_interface.c:1.36
--- src/sys/arch/amd64/amd64/db_interface.c:1.35	Mon Feb 11 14:59:32 2019
+++ src/sys/arch/amd64/amd64/db_interface.c	Thu Feb 14 07:12:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_interface.c,v 1.35 2019/02/11 14:59:32 cherry Exp $	*/
+/*	$NetBSD: db_interface.c,v 1.36 2019/02/14 07:12:40 cherry Exp $	*/
 
 /*
  * Mach Operating System
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.35 2019/02/11 14:59:32 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.36 2019/02/14 07:12:40 cherry Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -52,9 +52,13 @@ __KERNEL_RCSID(0, "$NetBSD: db_interface
 #include 
 #include 
 #include 
+#if NIOAPIC > 0
 #include 
+#endif
+#if NLAPIC > 0
 #include 
 #include 
+#endif
 
 #include 
 #include 
@@ -145,7 +149,9 @@ db_suspend_others(void)
 #ifdef XENPV
 		xen_broadcast_ipi(XEN_IPI_DDB);
 #else
+#if NLAPIC > 0
 		x86_ipi(ddb_vec, LAPIC_DEST_ALLEXCL, LAPIC_DLMODE_FIXED);
+#endif
 #endif /* XENPV */
 	}
 	ddb_mp_online = x86_mp_online;

Index: src/sys/arch/i386/i386/db_interface.c
diff -u src/sys/arch/i386/i386/db_interface.c:1.83 src/sys/arch/i386/i386/db_interface.c:1.84
--- src/sys/arch/i386/i386/db_interface.c:1.83	Mon Feb 11 14:59:32 2019
+++ src/sys/arch/i386/i386/db_interface.c	Thu Feb 14 07:12:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_interface.c,v 1.83 2019/02/11 14:59:32 cherry Exp $	*/
+/*	$NetBSD: db_interface.c,v 1.84 2019/02/14 07:12:40 cherry Exp $	*/
 
 /*
  * Mach Operating System
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.83 2019/02/11 14:59:32 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.84 2019/02/14 07:12:40 cherry Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -150,7 +150,9 @@ db_suspend_others(void)
 #ifdef XENPV
 		xen_broadcast_ipi(XEN_IPI_DDB);
 #else
+#if NLAPIC > 0		
 		x86_ipi(ddb_vec, LAPIC_DEST_ALLEXCL, LAPIC_DLMODE_FIXED);
+#endif		
 #endif /* XENPV */
 	}
 	ddb_mp_online = x86_mp_online;

Index: src/sys/arch/x86/x86/cpu.c
diff -u src/sys/arch/x86/x86/cpu.c:1.164 src/sys/arch/x86/x86/cpu.c:1.165
--- src/sys/arch/x86/x86/cpu.c:1.164	Tue Dec  4 19:27:22 2018
+++ src/sys/arch/x86/x86/cpu.c	Thu Feb 14 07:12:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.164 2018/12/04 19:27:22 cherry Exp $	*/
+/*	$NetBSD: cpu.c,v 1.165 2019/02/14 07:12:40 cherry Exp $	*/
 
 /*
  * Copyright (c) 2000-2012 NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.164 2018/12/04 19:27:22 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.165 2019/02/14 07:12:40 cherry Exp $");
 
 #include "opt_ddb.h"
 #include "opt_mpbios.h"		/* for MPDEBUG */
@@ -754,12 +754,14 @@ cpu_init_idle_lwps(void)
 void
 cpu_start_secondary(struct cpu_info *ci)
 {
-	paddr_t mp_pdirpa;
 	u_long psl;
 	int i;
 
+#if NLAPIC > 0
+	paddr_t mp_pdirpa;
 	mp_pdirpa = pmap_init_tmp_pgtbl(mp_trampoline_paddr);
 	cpu_copy_trampoline(mp_pdirpa);

CVS commit: src/sys/arch/xen

2019-02-13 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Feb 14 06:59:25 UTC 2019

Modified Files:
src/sys/arch/xen/conf: files.xen
src/sys/arch/xen/include: bus_private.h
src/sys/arch/xen/include/amd64: vmparam.h

Log Message:
Snag the final bits of PV only code to conditionally compile under
-DXENPV

This completes the bifurcation.

The next step is to add -DXENPVHVM code.


To generate a diff of this commit:
cvs rdiff -u -r1.176 -r1.177 src/sys/arch/xen/conf/files.xen
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/xen/include/bus_private.h
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/xen/include/amd64/vmparam.h

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/xen/conf/files.xen
diff -u src/sys/arch/xen/conf/files.xen:1.176 src/sys/arch/xen/conf/files.xen:1.177
--- src/sys/arch/xen/conf/files.xen:1.176	Sun Jan 27 02:08:39 2019
+++ src/sys/arch/xen/conf/files.xen	Thu Feb 14 06:59:24 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: files.xen,v 1.176 2019/01/27 02:08:39 pgoyette Exp $
+#	$NetBSD: files.xen,v 1.177 2019/02/14 06:59:24 cherry Exp $
 #	NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp 
 #	NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp 
 
@@ -36,7 +36,7 @@ defflag opt_pcifixup.h	PCI_ADDR_FIXUP PC
 
 defparam		PCI_CONF_MODE
 
-file	arch/xen/x86/autoconf.c
+file	arch/xen/x86/autoconf.c		xenpv
 ifdef i386
 file	arch/i386/i386/aout_machdep.c	exec_aout
 file	arch/i386/i386/busfunc.S
@@ -86,10 +86,10 @@ file	arch/xen/x86/hypervisor_machdep.c
 file	arch/x86/x86/kgdb_machdep.c	kgdb
 # file 	arch/x86/x86/mtrr_i686.c	mtrr
 file	arch/x86/x86/syscall.c
-file	arch/xen/x86/x86_xpmap.c
-file	arch/xen/x86/xen_pmap.c
+file	arch/xen/x86/x86_xpmap.c	xenpv
+file	arch/xen/x86/xen_pmap.c		xenpv
 file	arch/xen/x86/xen_intr.c
-file	arch/xen/x86/xenfunc.c
+file	arch/xen/x86/xenfunc.c		xenpv
 
 file	arch/x86/x86/cpu_ucode.c	dom0ops & cpu_ucode needs-flag
 file	arch/x86/x86/cpu_ucode_amd.c	dom0ops & cpu_ucode needs-flag
@@ -97,9 +97,9 @@ file	arch/x86/x86/cpu_ucode_intel.c	dom0
 file	arch/x86/x86/compat_60_cpu_ucode.c  compat_60 & dom0ops & cpu_ucode
 
 
-file	arch/xen/xen/xen_machdep.c
+file	arch/xen/xen/xen_machdep.c	xenpv
 
-file	arch/xen/xen/clock.c
+file	arch/xen/xen/clock.c		xenpv
 file	arch/x86/isa/rtc.c		dom0ops
 file	arch/xen/xen/evtchn.c
 
@@ -133,12 +133,12 @@ file	dev/md_root.c			memory_disk_hooks
 
 file	arch/x86/x86/bus_dma.c		machdep
 file	arch/x86/x86/core_machdep.c	coredump
-file	arch/xen/x86/xen_bus_dma.c	machdep
+file	arch/xen/x86/xen_bus_dma.c	machdep & xenpv
 file	arch/x86/x86/bus_space.c	machdep
-file	arch/xen/x86/consinit.c		machdep
+file	arch/xen/x86/consinit.c		machdep & xenpv
 file	arch/x86/x86/identcpu.c		machdep
-file	arch/xen/x86/pintr.c		machdep & dom0ops
-file	arch/xen/x86/xen_ipi.c		multiprocessor
+file	arch/xen/x86/pintr.c		machdep & dom0ops & xenpv
+file	arch/xen/x86/xen_ipi.c		multiprocessor & xenpv
 file	arch/x86/x86/idt.c		machdep
 file	arch/x86/x86/pmap.c		machdep
 file	arch/x86/x86/x86_tlb.c		machdep
@@ -253,7 +253,7 @@ device	fdc {drive = -1} #XXX
 include "dev/apm/files.apm"
 
 include "dev/acpi/files.acpi"
-file	arch/xen/xen/xen_acpi_machdep.c	acpi
+file	arch/xen/xen/xen_acpi_machdep.c	acpi & xenpv
 file	arch/x86/x86/mpacpi.c		acpi
 file	arch/x86/x86/i8259.c		dom0ops
 
@@ -289,8 +289,7 @@ attach cpu at cpubus
 
 device vcpu
 attach vcpu at xendevbus
-
-file	arch/xen/x86/cpu.c		cpu | vcpu
+file	arch/xen/x86/cpu.c		xenpv & vcpu
 
 # CPU features
 #

Index: src/sys/arch/xen/include/bus_private.h
diff -u src/sys/arch/xen/include/bus_private.h:1.9 src/sys/arch/xen/include/bus_private.h:1.10
--- src/sys/arch/xen/include/bus_private.h:1.9	Wed Jan 23 19:46:45 2008
+++ src/sys/arch/xen/include/bus_private.h	Thu Feb 14 06:59:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus_private.h,v 1.9 2008/01/23 19:46:45 bouyer Exp $	*/
+/*	$NetBSD: bus_private.h,v 1.10 2019/02/14 06:59:24 cherry Exp $	*/
 
 /*-
  * Copyright (c)2005 YAMAMOTO Takashi,
@@ -29,6 +29,7 @@
 #include 
 #include "opt_xen.h"
 
+#ifdef XENPV
 #define	_BUS_PHYS_TO_BUS(pa)	((bus_addr_t)xpmap_ptom(pa))
 #define	_BUS_BUS_TO_PHYS(ba)	((paddr_t)xpmap_mtop(ba))
 #define	_BUS_VIRT_TO_BUS(pm, va) _bus_virt_to_bus((pm), (va))
@@ -65,5 +66,6 @@ int _xen_bus_dmamem_alloc_range(bus_dma_
 #else
 #define _BUS_AVAIL_END ((bus_addr_t)0x)
 #endif
-
+#endif /* XENPV */
 #include 
+

Index: src/sys/arch/xen/include/amd64/vmparam.h
diff -u src/sys/arch/xen/include/amd64/vmparam.h:1.2 src/sys/arch/xen/include/amd64/vmparam.h:1.3
--- src/sys/arch/xen/include/amd64/vmparam.h:1.2	Thu Nov 22 16:17:02 2007
+++ src/sys/arch/xen/include/amd64/vmparam.h	Thu Feb 14 06:59:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmparam.h,v 1.2 2007/11/22 16:17:02 bouyer Exp $	*/
+/*	$NetBSD: vmparam.h,v 1.3 2019/02/14 06:59:24 cherry Exp $	*/
 
 /*-
  * Copyright (c)2005 YAMAMOTO Takashi,
@@ -29,10 +29,13 @@
 #if !defined(_VMPARAM_H_)
 #include 
 
+#ifdef XENPV

CVS commit: src/sys/arch/xen/x86

2019-02-13 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Feb 13 09:57:46 UTC 2019

Modified Files:
src/sys/arch/xen/x86: xen_mainbus.c

Log Message:
Conditionally compile a conditionally used variable.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/xen/x86/xen_mainbus.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/xen/x86/xen_mainbus.c
diff -u src/sys/arch/xen/x86/xen_mainbus.c:1.4 src/sys/arch/xen/x86/xen_mainbus.c:1.5
--- src/sys/arch/xen/x86/xen_mainbus.c:1.4	Sat Dec 22 08:35:04 2018
+++ src/sys/arch/xen/x86/xen_mainbus.c	Wed Feb 13 09:57:46 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_mainbus.c,v 1.4 2018/12/22 08:35:04 maxv Exp $	*/
+/*	$NetBSD: xen_mainbus.c,v 1.5 2019/02/13 09:57:46 cherry Exp $	*/
 /*	NetBSD: mainbus.c,v 1.19 2017/05/23 08:54:39 nonaka Exp 	*/
 /*	NetBSD: mainbus.c,v 1.53 2003/10/27 14:11:47 junyoung Exp 	*/
 
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_mainbus.c,v 1.4 2018/12/22 08:35:04 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_mainbus.c,v 1.5 2019/02/13 09:57:46 cherry Exp $");
 
 #include 
 #include 
@@ -130,7 +130,9 @@ xen_mainbus_match(device_t parent, cfdat
 void
 xen_mainbus_attach(device_t parent, device_t self, void *aux)
 {
+#if NIPMI > 0 || NHYPERVISOR > 0
 	union xen_mainbus_attach_args mba;
+#endif
 
 #if NIPMI > 0
 	memset(_ipmi, 0, sizeof(mba.mba_ipmi));



CVS commit: src/sys/arch/xen

2019-02-12 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Feb 13 06:52:43 UTC 2019

Modified Files:
src/sys/arch/xen/include: xenpmap.h
src/sys/arch/xen/xen: evtchn.c hypervisor.c xen_machdep.c

Log Message:
Further restrict the scope of XENPV to relevant parts.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/xen/include/xenpmap.h
cvs rdiff -u -r1.84 -r1.85 src/sys/arch/xen/xen/evtchn.c
cvs rdiff -u -r1.70 -r1.71 src/sys/arch/xen/xen/hypervisor.c
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/xen/xen/xen_machdep.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/xen/include/xenpmap.h
diff -u src/sys/arch/xen/include/xenpmap.h:1.40 src/sys/arch/xen/include/xenpmap.h:1.41
--- src/sys/arch/xen/include/xenpmap.h:1.40	Thu Jul 26 17:20:08 2018
+++ src/sys/arch/xen/include/xenpmap.h	Wed Feb 13 06:52:43 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: xenpmap.h,v 1.40 2018/07/26 17:20:08 maxv Exp $	*/
+/*	$NetBSD: xenpmap.h,v 1.41 2019/02/13 06:52:43 cherry Exp $	*/
 
 /*
  *
@@ -72,6 +72,7 @@ void xen_kpm_sync(struct pmap *, int);
 #define xpq_queue_pin_l4_table(pa)	\
 	xpq_queue_pin_table(pa, MMUEXT_PIN_L4_TABLE)
 
+#ifdef XENPV
 extern unsigned long *xpmap_phys_to_machine_mapping;
 
 static __inline paddr_t
@@ -121,6 +122,8 @@ xpmap_ptom_isvalid(paddr_t ppa)
 	!= INVALID_P2M_ENTRY);
 }
 
+#endif /* XENPV */
+
 static inline void
 MULTI_update_va_mapping(
 	multicall_entry_t *mcl, vaddr_t va,

Index: src/sys/arch/xen/xen/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.84 src/sys/arch/xen/xen/evtchn.c:1.85
--- src/sys/arch/xen/xen/evtchn.c:1.84	Wed Feb 13 05:01:58 2019
+++ src/sys/arch/xen/xen/evtchn.c	Wed Feb 13 06:52:43 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.84 2019/02/13 05:01:58 cherry Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.85 2019/02/13 06:52:43 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.84 2019/02/13 05:01:58 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.85 2019/02/13 06:52:43 cherry Exp $");
 
 #include "opt_xen.h"
 #include "isa.h"
@@ -256,6 +256,7 @@ void
 events_init(void)
 {
 	mutex_init(_lock, MUTEX_DEFAULT, IPL_NONE);
+#ifdef XENPV
 	debug_port = bind_virq_to_evtch(VIRQ_DEBUG);
 
 	KASSERT(debug_port != -1);
@@ -273,6 +274,7 @@ events_init(void)
 #if NPCI > 0 || NISA > 0
 	hypervisor_ack_pirq_event(debug_port);
 #endif /* NPCI > 0 || NISA > 0 */
+#endif /* XENPV */
 	x86_enable_intr();		/* at long last... */
 }
 
@@ -1080,6 +1082,7 @@ xen_debug_handler(void *arg)
 	return 0;
 }
 
+#ifdef XENPV
 static struct evtsource *
 event_get_handler(const char *intrid)
 {
@@ -1207,3 +1210,4 @@ interrupt_construct_intrids(const kcpuse
 
 	return ii_handler;
 }
+#endif /* XENPV */

Index: src/sys/arch/xen/xen/hypervisor.c
diff -u src/sys/arch/xen/xen/hypervisor.c:1.70 src/sys/arch/xen/xen/hypervisor.c:1.71
--- src/sys/arch/xen/xen/hypervisor.c:1.70	Sat Feb  2 12:32:55 2019
+++ src/sys/arch/xen/xen/hypervisor.c	Wed Feb 13 06:52:43 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: hypervisor.c,v 1.70 2019/02/02 12:32:55 cherry Exp $ */
+/* $NetBSD: hypervisor.c,v 1.71 2019/02/13 06:52:43 cherry Exp $ */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.70 2019/02/02 12:32:55 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.71 2019/02/13 06:52:43 cherry Exp $");
 
 #include 
 #include 
@@ -373,20 +373,22 @@ hypervisor_attach(device_t parent, devic
 static bool
 hypervisor_suspend(device_t dev, const pmf_qual_t *qual)
 {
+#ifdef XENPV
 	events_suspend();
 	xengnt_suspend();
-
+#endif
 	return true;
 }
 
 static bool
 hypervisor_resume(device_t dev, const pmf_qual_t *qual)
 {
+#ifdef XENPV
 	hypervisor_machdep_resume();
 
 	xengnt_resume();
 	events_resume();
-
+#endif
 	return true;
 }
 

Index: src/sys/arch/xen/xen/xen_machdep.c
diff -u src/sys/arch/xen/xen/xen_machdep.c:1.20 src/sys/arch/xen/xen/xen_machdep.c:1.21
--- src/sys/arch/xen/xen/xen_machdep.c:1.20	Sat Feb  2 12:32:55 2019
+++ src/sys/arch/xen/xen/xen_machdep.c	Wed Feb 13 06:52:43 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_machdep.c,v 1.20 2019/02/02 12:32:55 cherry Exp $	*/
+/*	$NetBSD: xen_machdep.c,v 1.21 2019/02/13 06:52:43 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.20 2019/02/02 12:32:55 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.21 2019/02/13 06:52:43 cherry Exp $");
 
 #include "opt_xen.h"
 
@@ -80,6 +80,7 @@ u_int	tsc_get_timecount(struct timecount
 
 bool xen_suspend_allow;
 
+#ifdef XENPV
 extern uint64_t tsc_freq;	/* XXX */
 
 static int sysctl_xen_suspend(SYSCTLFN_ARGS);
@@ -419,6 +420,7 @@ xen_suspend_domain(void)
 	aprint_verbose("domain resumed\n");
 
 }
+#endif /* XENPV */
 
 #define PRINTK_BUFSIZE 1024
 void



CVS commit: src/sys/arch/xen/x86

2019-02-12 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Feb 13 06:15:51 UTC 2019

Modified Files:
src/sys/arch/xen/x86: pintr.c

Log Message:
Catchup with struct intrstub; unification.

This should fix dom0 build breakage.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/xen/x86/pintr.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/xen/x86/pintr.c
diff -u src/sys/arch/xen/x86/pintr.c:1.9 src/sys/arch/xen/x86/pintr.c:1.10
--- src/sys/arch/xen/x86/pintr.c:1.9	Wed Oct 10 02:34:08 2018
+++ src/sys/arch/xen/x86/pintr.c	Wed Feb 13 06:15:51 2019
@@ -103,7 +103,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.9 2018/10/10 02:34:08 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.10 2019/02/13 06:15:51 cherry Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -135,17 +135,19 @@ __KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.
 /* XXX: todo - compat with lapic.c and XEN for x2apic */
 bool x2apic_mode __read_mostly = false;
 /* for x86/i8259.c */
-struct intrstub legacy_stubs[NUM_LEGACY_IRQS] = {{0,0}};
+struct intrstub legacy_stubs[NUM_LEGACY_IRQS] = {{0,0,0}};
 /* for x86/ioapic.c */
-struct intrstub ioapic_edge_stubs[MAX_INTR_SOURCES] = {{0,0}};
-struct intrstub ioapic_level_stubs[MAX_INTR_SOURCES] = {{0,0}};
-struct intrstub x2apic_edge_stubs[MAX_INTR_SOURCES] = {{0,0}};
-struct intrstub x2apic_level_stubs[MAX_INTR_SOURCES] = {{0,0}};
+struct intrstub ioapic_edge_stubs[MAX_INTR_SOURCES] = {{0,0,0}};
+struct intrstub ioapic_level_stubs[MAX_INTR_SOURCES] = {{0,0,0}};
+struct intrstub x2apic_edge_stubs[MAX_INTR_SOURCES] = {{0,0,0}};
+struct intrstub x2apic_level_stubs[MAX_INTR_SOURCES] = {{0,0,0}};
 #include 
+#endif /* NIOAPIC */
+
 int irq2port[NR_EVENT_CHANNELS] = {0}; /* actually port + 1, so that 0 is invaid */
 static int irq2vect[256] = {0};
 static int vect2irq[256] = {0};
-#endif /* NIOAPIC */
+
 #if NACPICA > 0
 #include 
 #include 



CVS commit: src/sys/arch

2019-02-12 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Feb 13 05:36:59 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: locore.S
src/sys/arch/i386/i386: locore.S

Log Message:
Rig the hypercall callback page such that when the kernel happens to
run without a XEN domain loader having previously overwritten the
hypercall page with its hypercall trampoline machine code, we still
get to detect its presence by calling the xen_version hypercall stub.

We use this hack to detect the presence or absence of the hypervisor,
without relying on the MSR support on HVM domains.

This works as an added sanity check that the hypercall page
registration has indeed succeeded in HVM mode.


To generate a diff of this commit:
cvs rdiff -u -r1.176 -r1.177 src/sys/arch/amd64/amd64/locore.S
cvs rdiff -u -r1.163 -r1.164 src/sys/arch/i386/i386/locore.S

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/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.176 src/sys/arch/amd64/amd64/locore.S:1.177
--- src/sys/arch/amd64/amd64/locore.S:1.176	Mon Feb 11 14:59:32 2019
+++ src/sys/arch/amd64/amd64/locore.S	Wed Feb 13 05:36:59 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.176 2019/02/11 14:59:32 cherry Exp $	*/
+/*	$NetBSD: locore.S,v 1.177 2019/02/13 05:36:59 cherry Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -278,6 +278,8 @@
 #define __ASSEMBLY__
 #include 
 #include 
+#endif	/* XEN */
+
 #ifdef XENPV	
 #define ELFNOTE(name, type, desctype, descdata...) \
 .pushsection .note.name			;	\
@@ -312,7 +314,6 @@
 	ELFNOTE(Xen, XEN_ELFNOTE_BSD_SYMTAB, .asciz, "yes")
 #endif
 #endif  /* XENPV */	
-#endif	/* XEN */
 
 /*
  * Initialization
@@ -979,9 +980,12 @@ END(start)
 #if defined(XEN)
 /* space for the hypercall call page */
 #define HYPERCALL_PAGE_OFFSET 0x1000
-.org HYPERCALL_PAGE_OFFSET
-ENTRY(hypercall_page)
-.skip 0x1000
+.align HYPERCALL_PAGE_OFFSET
+ENTRY(hypercall_page) /* Returns -1, on HYPERVISOR_xen_version() */
+.skip	(__HYPERVISOR_xen_version*32), 0x90
+	movq	$-1, %rax
+	retq
+.align HYPERCALL_PAGE_OFFSET, 0x90
 END(hypercall_page)
 #endif /* XEN */
 

Index: src/sys/arch/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.163 src/sys/arch/i386/i386/locore.S:1.164
--- src/sys/arch/i386/i386/locore.S:1.163	Mon Feb 11 14:59:32 2019
+++ src/sys/arch/i386/i386/locore.S	Wed Feb 13 05:36:59 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.163 2019/02/11 14:59:32 cherry Exp $	*/
+/*	$NetBSD: locore.S,v 1.164 2019/02/13 05:36:59 cherry Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.163 2019/02/11 14:59:32 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.164 2019/02/13 05:36:59 cherry Exp $");
 
 #include "opt_copy_symtab.h"
 #include "opt_ddb.h"
@@ -242,6 +242,20 @@ __KERNEL_RCSID(0, "$NetBSD: locore.S,v 1
 	loop	1b			;
 
 
+#ifdef XEN
+/*
+ * Unfortunately, the Xen codebase uses nonstandard preprocessing tools.
+ * See: https://xenbits.xen.org/gitweb/?p=xen.git=search=HEAD=grep=__UnDeF__
+ * for a fine selection of examples.
+ *
+ * What this means for us here is that we can't include the standard
+ * xen.h header in assembler code.
+ *
+ * So we have to manually define, and keep track of the values we need, ourselves.
+ */
+#define __HYPERVISOR_xen_version  17
+#endif	/* XEN */
+
 #ifdef XENPV
 /*
  * Xen guest identifier and loader selection
@@ -916,9 +930,12 @@ END(start)
 #if defined(XEN)
 /* space for the hypercall call page */
 #define HYPERCALL_PAGE_OFFSET 0x1000
-.org HYPERCALL_PAGE_OFFSET
-ENTRY(hypercall_page)
-.skip 0x1000
+.align HYPERCALL_PAGE_OFFSET
+ENTRY(hypercall_page) /* Returns -1, on HYPERVISOR_xen_version() */
+.skip	(__HYPERVISOR_xen_version*32), 0x90
+	movl	$-1, %eax
+	retl
+.align HYPERCALL_PAGE_OFFSET, 0x90
 END(hypercall_page)
 
 #ifdef XENPV



CVS commit: src/sys/arch/x86/include

2019-02-12 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Feb 13 05:28:50 UTC 2019

Modified Files:
src/sys/arch/x86/include: intr.h

Log Message:
Missed the crucial header file in previous commit.

struct intrstub; is now uniform across native and XEN

This should fix the XEN builds.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/arch/x86/include/intr.h

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.58 src/sys/arch/x86/include/intr.h:1.59
--- src/sys/arch/x86/include/intr.h:1.58	Mon Feb 11 14:59:32 2019
+++ src/sys/arch/x86/include/intr.h	Wed Feb 13 05:28:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.58 2019/02/11 14:59:32 cherry Exp $	*/
+/*	$NetBSD: intr.h,v 1.59 2019/02/13 05:28:50 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -71,9 +71,7 @@
  */
 
 struct intrstub {
-#if !defined(XENPV)
 	void *ist_entry;
-#endif
 	void *ist_recurse;
 	void *ist_resume;
 };



CVS commit: src/sys/arch

2019-02-12 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Feb 13 05:01:58 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: vector.S
src/sys/arch/i386/i386: vector.S
src/sys/arch/xen/xen: evtchn.c

Log Message:
In preparation for debut-ing PVHVM mode:

 - Make the struct intrstub uniform across native and XEN.
 - Introduce vector callback entrypoints for PVHVM mode.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/sys/arch/amd64/amd64/vector.S
cvs rdiff -u -r1.80 -r1.81 src/sys/arch/i386/i386/vector.S
cvs rdiff -u -r1.83 -r1.84 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/vector.S
diff -u src/sys/arch/amd64/amd64/vector.S:1.66 src/sys/arch/amd64/amd64/vector.S:1.67
--- src/sys/arch/amd64/amd64/vector.S:1.66	Mon Feb 11 14:59:32 2019
+++ src/sys/arch/amd64/amd64/vector.S	Wed Feb 13 05:01:57 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vector.S,v 1.66 2019/02/11 14:59:32 cherry Exp $	*/
+/*	$NetBSD: vector.S,v 1.67 2019/02/13 05:01:57 cherry Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -631,19 +631,7 @@ LABEL(name ## _stubs); \
 	INTRSTUB_ENTRY(name ## 31)		; \
 END(name ## _stubs)
 
-	.section .rodata
-
-INTRSTUB_ARRAY_16(legacy)
-
-#if NIOAPIC > 0
-INTRSTUB_ARRAY_32(ioapic_edge)
-INTRSTUB_ARRAY_32(ioapic_level)
-
-INTRSTUB_ARRAY_32(x2apic_edge)
-INTRSTUB_ARRAY_32(x2apic_level)
-#endif
-
-#endif /* !defined(XENPV) */
+#endif /* !XENPV */
 
 #if defined(XEN)
 /* Resume/recurse procedures for spl() */
@@ -715,39 +703,49 @@ XENINTRSTUB(xenev,29,voidop,voidop,voido
 XENINTRSTUB(xenev,30,voidop,voidop,voidop,hypervisor_asm_unmask,voidop)
 XENINTRSTUB(xenev,31,voidop,voidop,voidop,hypervisor_asm_unmask,voidop)
 
+/* On Xen, the xenev_stubs are purely for spl entry, since there is no
+ * vector based mechanism. We however provide the entrypoint to ensure
+ * that native and Xen struct intrstub ; definitions are uniform.
+ */
+panicmsg:	.ascii "vector Xen event entry path entered."
+LABEL(entry_xenev)
+	movq $panicmsg, %rdi
+	callq _C_LABEL(panic)
+END(entry_xenev)
+
 LABEL(xenev_stubs)
-	.quad _C_LABEL(Xrecurse_xenev0), _C_LABEL(Xresume_xenev0)
-	.quad _C_LABEL(Xrecurse_xenev1) ,_C_LABEL(Xresume_xenev1)
-	.quad _C_LABEL(Xrecurse_xenev2) ,_C_LABEL(Xresume_xenev2)
-	.quad _C_LABEL(Xrecurse_xenev3) ,_C_LABEL(Xresume_xenev3)
-	.quad _C_LABEL(Xrecurse_xenev4) ,_C_LABEL(Xresume_xenev4)
-	.quad _C_LABEL(Xrecurse_xenev5) ,_C_LABEL(Xresume_xenev5)
-	.quad _C_LABEL(Xrecurse_xenev6) ,_C_LABEL(Xresume_xenev6)
-	.quad _C_LABEL(Xrecurse_xenev7) ,_C_LABEL(Xresume_xenev7)
-	.quad _C_LABEL(Xrecurse_xenev8) ,_C_LABEL(Xresume_xenev8)
-	.quad _C_LABEL(Xrecurse_xenev9) ,_C_LABEL(Xresume_xenev9)
-	.quad _C_LABEL(Xrecurse_xenev10), _C_LABEL(Xresume_xenev10)
-	.quad _C_LABEL(Xrecurse_xenev11), _C_LABEL(Xresume_xenev11)
-	.quad _C_LABEL(Xrecurse_xenev12), _C_LABEL(Xresume_xenev12)
-	.quad _C_LABEL(Xrecurse_xenev13), _C_LABEL(Xresume_xenev13)
-	.quad _C_LABEL(Xrecurse_xenev14), _C_LABEL(Xresume_xenev14)
-	.quad _C_LABEL(Xrecurse_xenev15), _C_LABEL(Xresume_xenev15)
-	.quad _C_LABEL(Xrecurse_xenev16), _C_LABEL(Xresume_xenev16)
-	.quad _C_LABEL(Xrecurse_xenev17), _C_LABEL(Xresume_xenev17)
-	.quad _C_LABEL(Xrecurse_xenev18), _C_LABEL(Xresume_xenev18)
-	.quad _C_LABEL(Xrecurse_xenev19), _C_LABEL(Xresume_xenev19)
-	.quad _C_LABEL(Xrecurse_xenev20), _C_LABEL(Xresume_xenev20)
-	.quad _C_LABEL(Xrecurse_xenev21), _C_LABEL(Xresume_xenev21)
-	.quad _C_LABEL(Xrecurse_xenev22), _C_LABEL(Xresume_xenev22)
-	.quad _C_LABEL(Xrecurse_xenev23), _C_LABEL(Xresume_xenev23)
-	.quad _C_LABEL(Xrecurse_xenev24), _C_LABEL(Xresume_xenev24)
-	.quad _C_LABEL(Xrecurse_xenev25), _C_LABEL(Xresume_xenev25)
-	.quad _C_LABEL(Xrecurse_xenev26), _C_LABEL(Xresume_xenev26)
-	.quad _C_LABEL(Xrecurse_xenev27), _C_LABEL(Xresume_xenev27)
-	.quad _C_LABEL(Xrecurse_xenev28), _C_LABEL(Xresume_xenev28)
-	.quad _C_LABEL(Xrecurse_xenev29), _C_LABEL(Xresume_xenev29)
-	.quad _C_LABEL(Xrecurse_xenev30), _C_LABEL(Xresume_xenev30)
-	.quad _C_LABEL(Xrecurse_xenev31), _C_LABEL(Xresume_xenev31)
+	.quad entry_xenev, _C_LABEL(Xrecurse_xenev0), _C_LABEL(Xresume_xenev0)
+	.quad entry_xenev, _C_LABEL(Xrecurse_xenev1) ,_C_LABEL(Xresume_xenev1)
+	.quad entry_xenev, _C_LABEL(Xrecurse_xenev2) ,_C_LABEL(Xresume_xenev2)
+	.quad entry_xenev, _C_LABEL(Xrecurse_xenev3) ,_C_LABEL(Xresume_xenev3)
+	.quad entry_xenev, _C_LABEL(Xrecurse_xenev4) ,_C_LABEL(Xresume_xenev4)
+	.quad entry_xenev, _C_LABEL(Xrecurse_xenev5) ,_C_LABEL(Xresume_xenev5)
+	.quad entry_xenev, _C_LABEL(Xrecurse_xenev6) ,_C_LABEL(Xresume_xenev6)
+	.quad entry_xenev, _C_LABEL(Xrecurse_xenev7) ,_C_LABEL(Xresume_xenev7)
+	.quad entry_xenev, _C_LABEL(Xrecurse_xenev8) ,_C_LABEL(Xresume_xenev8)
+	.quad entry_xenev, _C_LABEL(Xrecurse_xenev9) ,_C_LABEL(Xresume_xenev9)
+	.quad entry_xenev, _C_LABEL(Xrecurse_xenev10), 

CVS commit: src/sys/arch/xen

2019-02-12 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Tue Feb 12 08:04:53 UTC 2019

Modified Files:
src/sys/arch/xen/include: xenfunc.h
src/sys/arch/xen/x86: xen_intr.c

Log Message:
Move xen event related code which interfaces with the NetBSD interrupt
subsystem into a separate namespace where it can co-exist with the
native equivalent in PVHVM mode.

On PV, we alias and export the native symbols - this means that
although the namespace is different, the semantics must be identical.

Eg: xen_intr_establish_xname() vs. intr_establish_xname().

The specific functions we need in PVHVM are:

 - spllower, xen_spllower (for native as well as XEN event spl
   despatch/defer)
 - xen_disable_intr()/xen_enable_intr() ,
   x86_disable_intr()/x86_enable_intr()
 - xen_read_psl()/xen_write_psl(),
   x86_read_psl()/x86_write_psl()
 - intr_establish() et. al, xen_intr_establish() et. al.

This gives us the ability to manage Paravirtualised drivers such as
xbd(4) as well as fully emulated ones such as wd(4)., for eg


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/xen/include/xenfunc.h
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/xen/x86/xen_intr.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/xen/include/xenfunc.h
diff -u src/sys/arch/xen/include/xenfunc.h:1.16 src/sys/arch/xen/include/xenfunc.h:1.17
--- src/sys/arch/xen/include/xenfunc.h:1.16	Thu Jul 26 15:46:09 2018
+++ src/sys/arch/xen/include/xenfunc.h	Tue Feb 12 08:04:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: xenfunc.h,v 1.16 2018/07/26 15:46:09 maxv Exp $	*/
+/*	$NetBSD: xenfunc.h,v 1.17 2019/02/12 08:04:53 cherry Exp $	*/
 
 /*
  *
@@ -36,5 +36,10 @@
 #include 
 #include 
 
+void xen_disable_intr(void);
+void xen_enable_intr(void);
+u_long xen_read_psl(void);
+void xen_write_psl(u_long);
+
 void xen_set_ldt(vaddr_t, uint32_t);
 #endif /* _XEN_XENFUNC_H_ */

Index: src/sys/arch/xen/x86/xen_intr.c
diff -u src/sys/arch/xen/x86/xen_intr.c:1.13 src/sys/arch/xen/x86/xen_intr.c:1.14
--- src/sys/arch/xen/x86/xen_intr.c:1.13	Wed Dec 26 11:12:57 2018
+++ src/sys/arch/xen/x86/xen_intr.c	Tue Feb 12 08:04:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_intr.c,v 1.13 2018/12/26 11:12:57 cherry Exp $	*/
+/*	$NetBSD: xen_intr.c,v 1.14 2019/02/12 08:04:53 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.13 2018/12/26 11:12:57 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.14 2019/02/12 08:04:53 cherry Exp $");
 
 #include 
 #include 
@@ -66,17 +66,14 @@ __KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v
 #include 
 #endif
 
-void xen_disable_intr(void);
-void xen_enable_intr(void);
-u_long xen_read_psl(void);
-void xen_write_psl(u_long);
-
 /*
  * Restore a value to cpl (unmasking interrupts).  If any unmasked
  * interrupts are pending, call Xspllower() to process them.
  */
+void xen_spllower(int nlevel);
+
 void
-spllower(int nlevel)
+xen_spllower(int nlevel)
 {
 	struct cpu_info *ci = curcpu();
 	uint32_t xmask;
@@ -186,7 +183,7 @@ xen_intr_establish_xname(int legacy_irq,
 		return rih;
 	} 	/* Else we assume pintr */
 
-#if NPCI > 0 || NISA > 0
+#if (NPCI > 0 || NISA > 0) && defined(XENPV) /* XXX: support PVHVM pirq */
 	struct pintrhand *pih;
 	int gsi;
 	int vector, evtchn;
@@ -306,8 +303,9 @@ redzone_const_or_zero(int x)
 }
 #endif
 
+void xen_cpu_intr_init(struct cpu_info *);
 void
-cpu_intr_init(struct cpu_info *ci)
+xen_cpu_intr_init(struct cpu_info *ci)
 {
 	int i; /* XXX: duplicate */
 
@@ -393,8 +391,10 @@ legacy_intr_string(int ih, char *buf, si
 	return buf;
 }
 
+const char * xintr_string(intr_handle_t ih, char *buf, size_t len);
+
 const char *
-intr_string(intr_handle_t ih, char *buf, size_t len)
+xintr_string(intr_handle_t ih, char *buf, size_t len)
 {
 #if NIOAPIC > 0
 	struct ioapic_softc *pic;
@@ -420,7 +420,7 @@ intr_string(intr_handle_t ih, char *buf,
 		snprintf(buf, len, "irq %d", APIC_IRQ_LEGACY_IRQ(ih));
 
 #elif NLAPIC > 0
-	snprintf(buf, len, "irq %d" APIC_IRQ_LEGACY_IRQ(ih));
+	snprintf(buf, len, "irq %d", APIC_IRQ_LEGACY_IRQ(ih));
 #else
 	snprintf(buf, len, "irq %d", (int) ih);
 #endif
@@ -432,8 +432,11 @@ intr_string(intr_handle_t ih, char *buf,
  * Create an interrupt id such as "ioapic0 pin 9". This interrupt id is used
  * by MI code and intrctl(8).
  */
+const char * xen_intr_create_intrid(int legacy_irq, struct pic *pic,
+int pin, char *buf, size_t len);
+
 const char *
-intr_create_intrid(int legacy_irq, struct pic *pic, int pin, char *buf, size_t len)
+xen_intr_create_intrid(int legacy_irq, struct pic *pic, int pin, char *buf, size_t len)
 {
 	int ih = 0;
 
@@ -487,14 +490,19 @@ intr_create_intrid(int legacy_irq, struc
 	return NULL; /* No pic found! */
 }
 
-__weak_alias(x86_disable_intr, xen_disable_intr);
-__weak_alias(x86_enable_intr, xen_enable_intr);
-__weak_alias(x86_read_psl, 

CVS commit: src/sys/arch/xen

2019-02-11 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Tue Feb 12 07:58:26 UTC 2019

Modified Files:
src/sys/arch/xen/include: pci_machdep.h
src/sys/arch/xen/x86: hypervisor_machdep.c

Log Message:
conditionally include XENPV specific code.

This explicitly excludes PV only functionality that would be wrong to
attempt to use in other modes, for eg: p2m table management.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/xen/include/pci_machdep.h
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/xen/x86/hypervisor_machdep.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/xen/include/pci_machdep.h
diff -u src/sys/arch/xen/include/pci_machdep.h:1.19 src/sys/arch/xen/include/pci_machdep.h:1.20
--- src/sys/arch/xen/include/pci_machdep.h:1.19	Sun Jul 16 06:14:24 2017
+++ src/sys/arch/xen/include/pci_machdep.h	Tue Feb 12 07:58:26 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_machdep.h,v 1.19 2017/07/16 06:14:24 cherry Exp $ */
+/* $NetBSD: pci_machdep.h,v 1.20 2019/02/12 07:58:26 cherry Exp $ */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -66,7 +66,7 @@ typedef intr_handle_t pci_intr_handle_t;
 
 #include "opt_xen.h"
 
-#ifndef DOM0OPS
+#if !defined(DOM0OPS) && defined(XENPV)
 int		xpci_enumerate_bus(struct pci_softc *, const int *,
 		   int (*)(const struct pci_attach_args *),
 		   struct pci_attach_args *);

Index: src/sys/arch/xen/x86/hypervisor_machdep.c
diff -u src/sys/arch/xen/x86/hypervisor_machdep.c:1.34 src/sys/arch/xen/x86/hypervisor_machdep.c:1.35
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.34	Tue Dec 25 06:50:12 2018
+++ src/sys/arch/xen/x86/hypervisor_machdep.c	Tue Feb 12 07:58:26 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor_machdep.c,v 1.34 2018/12/25 06:50:12 cherry Exp $	*/
+/*	$NetBSD: hypervisor_machdep.c,v 1.35 2019/02/12 07:58:26 cherry Exp $	*/
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.34 2018/12/25 06:50:12 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.35 2019/02/12 07:58:26 cherry Exp $");
 
 #include 
 #include 
@@ -74,6 +74,7 @@ __KERNEL_RCSID(0, "$NetBSD: hypervisor_m
 #include "isa.h"
 #include "pci.h"
 
+#ifdef XENPV
 /*
  * arch-dependent p2m frame lists list (L3 and L2)
  * used by Xen for save/restore mappings
@@ -85,6 +86,8 @@ static int l2_p2m_page_size; /* size of 
 static void build_p2m_frame_list_list(void);
 static void update_p2m_frame_list_list(void);
 
+#endif
+
 // #define PORT_DEBUG 4
 // #define EARLY_DEBUG_EVENT
 
@@ -434,21 +437,26 @@ hypervisor_set_ipending(uint32_t iplmask
 void
 hypervisor_machdep_attach(void)
 {
+#ifdef XENPV
  	/* dom0 does not require the arch-dependent P2M translation table */
 	if (!xendomain_is_dom0()) {
 		build_p2m_frame_list_list();
 		sysctl_xen_suspend_setup();
 	}
+#endif
 }
 
 void
 hypervisor_machdep_resume(void)
 {
+#ifdef XENPV
 	/* dom0 does not require the arch-dependent P2M translation table */
 	if (!xendomain_is_dom0())
 		update_p2m_frame_list_list();
+#endif
 }
 
+#ifdef XENPV
 /*
  * Generate the p2m_frame_list_list table,
  * needed for guest save/restore
@@ -532,3 +540,4 @@ update_p2m_frame_list_list(void)
 HYPERVISOR_shared_info->arch.max_pfn = max_pfn;
 
 }
+#endif /* XENPV */



CVS commit: src/sys/arch/x86/x86

2019-02-11 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Tue Feb 12 03:13:50 UTC 2019

Modified Files:
src/sys/arch/x86/x86: intr.c

Log Message:
Fix typo: Parameters are seperated by ','.


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 src/sys/arch/x86/x86/intr.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/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.141 src/sys/arch/x86/x86/intr.c:1.142
--- src/sys/arch/x86/x86/intr.c:1.141	Tue Dec 25 06:50:12 2018
+++ src/sys/arch/x86/x86/intr.c	Tue Feb 12 03:13:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.141 2018/12/25 06:50:12 cherry Exp $	*/
+/*	$NetBSD: intr.c,v 1.142 2019/02/12 03:13:50 cherry Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.141 2018/12/25 06:50:12 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.142 2019/02/12 03:13:50 cherry Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -1131,7 +1131,7 @@ intr_string(intr_handle_t ih, char *buf,
 		snprintf(buf, len, "irq %d", APIC_IRQ_LEGACY_IRQ(ih));
 
 #elif NLAPIC > 0
-	snprintf(buf, len, "irq %d" APIC_IRQ_LEGACY_IRQ(ih));
+	snprintf(buf, len, "irq %d", APIC_IRQ_LEGACY_IRQ(ih));
 #else
 	snprintf(buf, len, "irq %d", (int) ih);
 #endif



CVS commit: src/sys/arch/x86/x86

2019-02-11 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Feb 11 18:50:15 UTC 2019

Modified Files:
src/sys/arch/x86/x86: identcpu.c

Log Message:
Detect and report running in a XEN hvm container.

This allows the lapic code to apply its x2apic probe logic while
running in a XEN hvm container.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/sys/arch/x86/x86/identcpu.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/x86/identcpu.c
diff -u src/sys/arch/x86/x86/identcpu.c:1.87 src/sys/arch/x86/x86/identcpu.c:1.88
--- src/sys/arch/x86/x86/identcpu.c:1.87	Mon Feb 11 14:59:33 2019
+++ src/sys/arch/x86/x86/identcpu.c	Mon Feb 11 18:50:15 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: identcpu.c,v 1.87 2019/02/11 14:59:33 cherry Exp $	*/
+/*	$NetBSD: identcpu.c,v 1.88 2019/02/11 18:50:15 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.87 2019/02/11 14:59:33 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.88 2019/02/11 18:50:15 cherry Exp $");
 
 #include "opt_xen.h"
 
@@ -1125,6 +1125,8 @@ identify_hypervisor(void)
 vm_guest = VM_GUEST_HV;
 			else if (memcmp(hv_vendor, "KVMKVMKVM\0\0\0", 12) == 0)
 vm_guest = VM_GUEST_KVM;
+			else if (memcmp(hv_vendor, "XenVMMXenVMM", 12) == 0)
+vm_guest = VM_GUEST_XEN;
 			/* FreeBSD bhyve: "bhyve bhyve " */
 			/* OpenBSD vmm:   "OpenBSDVMM58" */
 			/* NetBSD nvmm:   "___ NVMM ___" */



CVS commit: src/sys/arch/i386/i386

2019-02-11 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Feb 11 17:28:52 UTC 2019

Modified Files:
src/sys/arch/i386/i386: i386_trap.S

Log Message:
Remove redundant conditional IDT_VEC() entries.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/i386/i386/i386_trap.S

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/i386/i386/i386_trap.S
diff -u src/sys/arch/i386/i386/i386_trap.S:1.17 src/sys/arch/i386/i386/i386_trap.S:1.18
--- src/sys/arch/i386/i386/i386_trap.S:1.17	Mon Feb 11 14:59:32 2019
+++ src/sys/arch/i386/i386/i386_trap.S	Mon Feb 11 17:28:52 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: i386_trap.S,v 1.17 2019/02/11 14:59:32 cherry Exp $	*/
+/*	$NetBSD: i386_trap.S,v 1.18 2019/02/11 17:28:52 cherry Exp $	*/
 
 /*
  * Copyright 2002 (c) Wasabi Systems, Inc.
@@ -66,7 +66,7 @@
 
 #if 0
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i386_trap.S,v 1.17 2019/02/11 14:59:32 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i386_trap.S,v 1.18 2019/02/11 17:28:52 cherry Exp $");
 #endif
 
 /*
@@ -345,13 +345,8 @@ IDTVEC_END(trap17)
 IDTVEC_END(trap16)
 IDTVEC_END(trap15)
 IDTVEC_END(trap14)
-#ifndef XENPV
 IDTVEC_END(trap13)
 IDTVEC_END(trap12)
-#else
-IDTVEC_END(trap13)
-IDTVEC_END(trap12)
-#endif
 IDTVEC_END(trap11)
 
 IDTVEC(exceptions)



CVS commit: src/sys/arch

2019-02-11 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Feb 11 14:59:33 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: amd64_trap.S cpufunc.S db_interface.c gdt.c
genassym.cf lock_stubs.S locore.S machdep.c process_machdep.c spl.S
trap.c vector.S
src/sys/arch/amd64/conf: XEN3_DOM0 XEN3_DOMU
src/sys/arch/amd64/include: cpu.h frame.h frameasm.h param.h pmap.h
profile.h segments.h types.h vmparam.h
src/sys/arch/i386/conf: XEN3PAE_DOM0 XEN3PAE_DOMU
src/sys/arch/i386/i386: cpufunc.S db_interface.c gdt.c genassym.cf
i386_trap.S lock_stubs.S locore.S machdep.c spl.S trap.c vector.S
src/sys/arch/i386/include: cpu.h frame.h frameasm.h pmap.h segments.h
vmparam.h
src/sys/arch/x86/acpi: acpi_machdep.c
src/sys/arch/x86/include: cpu.h cpuvar.h intr.h intrdefs.h pmap.h
specialreg.h
src/sys/arch/x86/isa: isa_machdep.c
src/sys/arch/x86/pci: pci_intr_machdep.c pci_machdep.c pcib.c
src/sys/arch/x86/x86: bios32.c bus_space.c cpu_ucode.c fpu.c i8259.c
identcpu.c idt.c pmap.c sys_machdep.c vm_machdep.c x86_machdep.c
x86_tlb.c

Log Message:
We reorganise definitions for XEN source support as follows:

XEN - common sources required for baseline XEN support.
XENPV - sources required for support of XEN in PV mode.
XENPVHVM - sources required for support for XEN in HVM mode.
XENPVH - sources required for support for XEN in PVH mode.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/amd64/amd64/amd64_trap.S \
src/sys/arch/amd64/amd64/gdt.c
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/amd64/amd64/cpufunc.S
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/amd64/amd64/db_interface.c
cvs rdiff -u -r1.72 -r1.73 src/sys/arch/amd64/amd64/genassym.cf
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/amd64/amd64/lock_stubs.S
cvs rdiff -u -r1.175 -r1.176 src/sys/arch/amd64/amd64/locore.S
cvs rdiff -u -r1.324 -r1.325 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/amd64/amd64/process_machdep.c \
src/sys/arch/amd64/amd64/spl.S
cvs rdiff -u -r1.116 -r1.117 src/sys/arch/amd64/amd64/trap.c
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/amd64/amd64/vector.S
cvs rdiff -u -r1.165 -r1.166 src/sys/arch/amd64/conf/XEN3_DOM0
cvs rdiff -u -r1.87 -r1.88 src/sys/arch/amd64/conf/XEN3_DOMU
cvs rdiff -u -r1.63 -r1.64 src/sys/arch/amd64/include/cpu.h
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/amd64/include/frame.h
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/amd64/include/frameasm.h
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/amd64/include/param.h
cvs rdiff -u -r1.58 -r1.59 src/sys/arch/amd64/include/pmap.h \
src/sys/arch/amd64/include/types.h
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/amd64/include/profile.h
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/amd64/include/segments.h
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/amd64/include/vmparam.h
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/i386/conf/XEN3PAE_DOM0
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/i386/conf/XEN3PAE_DOMU
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/i386/i386/cpufunc.S
cvs rdiff -u -r1.82 -r1.83 src/sys/arch/i386/i386/db_interface.c
cvs rdiff -u -r1.68 -r1.69 src/sys/arch/i386/i386/gdt.c
cvs rdiff -u -r1.109 -r1.110 src/sys/arch/i386/i386/genassym.cf
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/i386/i386/i386_trap.S
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/i386/i386/lock_stubs.S
cvs rdiff -u -r1.162 -r1.163 src/sys/arch/i386/i386/locore.S
cvs rdiff -u -r1.814 -r1.815 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/i386/i386/spl.S
cvs rdiff -u -r1.297 -r1.298 src/sys/arch/i386/i386/trap.c
cvs rdiff -u -r1.79 -r1.80 src/sys/arch/i386/i386/vector.S
cvs rdiff -u -r1.180 -r1.181 src/sys/arch/i386/include/cpu.h
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/i386/include/frame.h
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/i386/include/frameasm.h
cvs rdiff -u -r1.121 -r1.122 src/sys/arch/i386/include/pmap.h
cvs rdiff -u -r1.67 -r1.68 src/sys/arch/i386/include/segments.h
cvs rdiff -u -r1.85 -r1.86 src/sys/arch/i386/include/vmparam.h
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/x86/acpi/acpi_machdep.c
cvs rdiff -u -r1.102 -r1.103 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/x86/include/cpuvar.h
cvs rdiff -u -r1.57 -r1.58 src/sys/arch/x86/include/intr.h
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/x86/include/intrdefs.h
cvs rdiff -u -r1.95 -r1.96 src/sys/arch/x86/include/pmap.h
cvs rdiff -u -r1.139 -r1.140 src/sys/arch/x86/include/specialreg.h
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/x86/isa/isa_machdep.c
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/x86/pci/pci_intr_machdep.c
cvs rdiff -u -r1.83 -r1.84 src/sys/arch/x86/pci/pci_machdep.c
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/x86/pci/pcib.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/x86/x86/bios32.c
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/x86/x86/bus_space.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/x86/x86/cpu_ucode.c
cvs rdiff -u -r1.49 -r1.50 

CVS commit: src/sys/arch/xen/include

2019-02-10 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Feb 10 11:10:34 UTC 2019

Modified Files:
src/sys/arch/xen/include/amd64: hypercalls.h
src/sys/arch/xen/include/i386: hypercalls.h

Log Message:
Catchup hypercall interfaces for HYPERVISOR_sched_op which use
arguments to __XEN_INTERFACE_VERSION__ >= 0x00030201

We've been using the sched_op_compat API with sched_op arguments.

fixes PR port-xen/53965


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/xen/include/amd64/hypercalls.h
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/xen/include/i386/hypercalls.h

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/xen/include/amd64/hypercalls.h
diff -u src/sys/arch/xen/include/amd64/hypercalls.h:1.11 src/sys/arch/xen/include/amd64/hypercalls.h:1.12
--- src/sys/arch/xen/include/amd64/hypercalls.h:1.11	Sat Feb  2 12:32:55 2019
+++ src/sys/arch/xen/include/amd64/hypercalls.h	Sun Feb 10 11:10:34 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: hypercalls.h,v 1.11 2019/02/02 12:32:55 cherry Exp $ */
+/* $NetBSD: hypercalls.h,v 1.12 2019/02/10 11:10:34 cherry Exp $ */
 /**
  * hypercall.h
  * 
@@ -320,8 +320,18 @@ static inline int
 HYPERVISOR_suspend(
 	unsigned long srec)
 {
+#if __XEN_INTERFACE_VERSION__ >= 0x00030201
+
+	struct sched_shutdown shutdown_reason = {
+		.reason = SHUTDOWN_suspend,
+	};
+
+	return _hypercall3(int, sched_op, SCHEDOP_shutdown,
+	_reason, srec);
+#else
 	return _hypercall3(int, sched_op, SCHEDOP_shutdown,
  SHUTDOWN_suspend, srec);
+#endif
 }
 
 static inline long
@@ -342,21 +352,51 @@ static inline long
 HYPERVISOR_shutdown(
 	void)
 {
-	return _hypercall2(int, sched_op, SCHEDOP_shutdown, SHUTDOWN_poweroff);
+#if __XEN_INTERFACE_VERSION__ >= 0x00030201
+
+	struct sched_shutdown shutdown_reason = {
+		.reason = SHUTDOWN_poweroff,
+	};
+
+	return _hypercall2(int, sched_op, SCHEDOP_shutdown,
+	_reason);
+#else
+-	return _hypercall2(int, sched_op, SCHEDOP_shutdown, SHUTDOWN_poweroff);
+#endif
 }
 
 static inline long
 HYPERVISOR_crash(
 	void)
 {
+#if __XEN_INTERFACE_VERSION__ >= 0x00030201
+
+	struct sched_shutdown shutdown_reason = {
+		.reason = SHUTDOWN_crash,
+	};
+
+	return _hypercall2(int, sched_op, SCHEDOP_shutdown,
+	_reason);
+#else
 	return _hypercall2(int, sched_op, SCHEDOP_shutdown, SHUTDOWN_crash);
+#endif
 }
 
 static inline long
 HYPERVISOR_reboot(
 	void)
 {
+#if __XEN_INTERFACE_VERSION__ >= 0x00030201
+
+	struct sched_shutdown shutdown_reason = {
+		.reason = SHUTDOWN_reboot,
+	};
+
+	return _hypercall2(int, sched_op, SCHEDOP_shutdown,
+	_reason);
+#else
 	return _hypercall2(int, sched_op, SCHEDOP_shutdown, SHUTDOWN_reboot);
+#endif
 }
 
 static inline int

Index: src/sys/arch/xen/include/i386/hypercalls.h
diff -u src/sys/arch/xen/include/i386/hypercalls.h:1.18 src/sys/arch/xen/include/i386/hypercalls.h:1.19
--- src/sys/arch/xen/include/i386/hypercalls.h:1.18	Sat Feb  2 12:32:55 2019
+++ src/sys/arch/xen/include/i386/hypercalls.h	Sun Feb 10 11:10:34 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypercalls.h,v 1.18 2019/02/02 12:32:55 cherry Exp $	*/
+/*	$NetBSD: hypercalls.h,v 1.19 2019/02/10 11:10:34 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -368,9 +368,21 @@ HYPERVISOR_shutdown(void)
 long ret;
 unsigned long ign1, ign2;
 
+#if __XEN_INTERFACE_VERSION__ >= 0x00030201
+
+struct sched_shutdown shutdown_reason = {
+	.reason = SHUTDOWN_poweroff
+};
+
 _hypercall(__HYPERVISOR_sched_op,
-	_harg("1" (SCHEDOP_shutdown), "2" (SHUTDOWN_poweroff)),
+	_harg("1" (SCHEDOP_shutdown), "2"  (_reason)),
 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
+#else
+ _hypercall(__HYPERVISOR_sched_op,
+	_harg("1" (SCHEDOP_shutdown), "2" (SHUTDOWN_poweroff)),
+ 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
+
+#endif	
 
 return ret;
 }
@@ -381,9 +393,20 @@ HYPERVISOR_crash(void)
 long ret;
 unsigned long ign1, ign2;
 
+#if __XEN_INTERFACE_VERSION__ >= 0x00030201
+
+struct sched_shutdown shutdown_reason = {
+	.reason = SHUTDOWN_crash
+};
+
+_hypercall(__HYPERVISOR_sched_op,
+	_harg("1" (SCHEDOP_shutdown), "2"  (_reason)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
+#else
 _hypercall(__HYPERVISOR_sched_op,
 	_harg("1" (SCHEDOP_shutdown), "2" (SHUTDOWN_crash)),
 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
+#endif
 
 return ret;
 }
@@ -394,9 +417,20 @@ HYPERVISOR_reboot(void)
 long ret;
 unsigned long ign1, ign2;
 
+#if __XEN_INTERFACE_VERSION__ >= 0x00030201
+
+struct sched_shutdown shutdown_reason = {
+	.reason = SHUTDOWN_reboot
+};
+
+_hypercall(__HYPERVISOR_sched_op,
+	_harg("1" (SCHEDOP_shutdown), "2"  (_reason)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
+#else
 _hypercall(__HYPERVISOR_sched_op,
 	_harg("1" (SCHEDOP_shutdown), "2" (SHUTDOWN_reboot)),
 	_harg("=a" 

CVS commit: src/sys/arch/xen/xen

2019-02-06 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Feb  6 12:24:46 UTC 2019

Modified Files:
src/sys/arch/xen/xen: xengnt.c

Log Message:
Add the codepath for grant table updates for VMs with an auto
translated physmap.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/xen/xen/xengnt.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/xen/xen/xengnt.c
diff -u src/sys/arch/xen/xen/xengnt.c:1.25 src/sys/arch/xen/xen/xengnt.c:1.26
--- src/sys/arch/xen/xen/xengnt.c:1.25	Wed Oct 24 13:07:46 2012
+++ src/sys/arch/xen/xen/xengnt.c	Wed Feb  6 12:24:46 2019
@@ -1,4 +1,4 @@
-/*  $NetBSD: xengnt.c,v 1.25 2012/10/24 13:07:46 royger Exp $  */
+/*  $NetBSD: xengnt.c,v 1.26 2019/02/06 12:24:46 cherry Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.25 2012/10/24 13:07:46 royger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.26 2019/02/06 12:24:46 cherry Exp $");
 
 #include 
 #include 
@@ -174,22 +174,44 @@ xengnt_more_entries(void)
 	if (pages == NULL)
 		return ENOMEM;
 
-	setup.dom = DOMID_SELF;
-	setup.nr_frames = nframes_new;
-	set_xen_guest_handle(setup.frame_list, pages);
-
-	/*
-	 * setup the grant table, made of nframes_new frames
-	 * and return the list of their virtual addresses
-	 * in 'pages'
-	 */
-	if (HYPERVISOR_grant_table_op(GNTTABOP_setup_table, , 1) != 0)
-		panic("%s: setup table failed", __func__);
-	if (setup.status != GNTST_okay) {
-		aprint_error("%s: setup table returned %d\n",
-		__func__, setup.status);
-		free(pages, M_DEVBUF);
-		return ENOMEM;
+	if (xen_feature(XENFEAT_auto_translated_physmap)) {
+		/*
+		 * Note: Although we allocate space for the entire
+		 * table, in this mode we only update one entry at a
+		 * time.
+		 */
+		struct vm_page *pg;
+		struct xen_add_to_physmap xmap;
+
+		pg = uvm_pagealloc(NULL, 0, NULL, UVM_PGA_USERESERVE|UVM_PGA_ZERO);
+		pages[gnt_nr_grant_frames] = atop(uvm_vm_page_to_phys(pg));
+
+		xmap.domid = DOMID_SELF;
+		xmap.space = XENMAPSPACE_grant_table;
+		xmap.idx = gnt_nr_grant_frames;
+		xmap.gpfn = pages[gnt_nr_grant_frames];
+
+		if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, ) < 0)
+			panic("%s: Unable to register HYPERVISOR_shared_info\n", __func__);
+
+	} else {
+		setup.dom = DOMID_SELF;
+		setup.nr_frames = nframes_new;
+		set_xen_guest_handle(setup.frame_list, pages);
+
+		/*
+		 * setup the grant table, made of nframes_new frames
+		 * and return the list of their virtual addresses
+		 * in 'pages'
+		 */
+		if (HYPERVISOR_grant_table_op(GNTTABOP_setup_table, , 1) != 0)
+			panic("%s: setup table failed", __func__);
+		if (setup.status != GNTST_okay) {
+			aprint_error("%s: setup table returned %d\n",
+			__func__, setup.status);
+			free(pages, M_DEVBUF);
+			return ENOMEM;
+		}
 	}
 
 	DPRINTF(("xengnt_more_entries: map 0x%lx -> %p\n",



CVS commit: src/sys/arch

2019-02-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Feb  4 18:14:54 UTC 2019

Modified Files:
src/sys/arch/amd64/conf: std.xen
src/sys/arch/xen/conf: std.xen
src/sys/arch/xen/include: hypervisor.h xen.h
src/sys/arch/xen/x86: x86_xpmap.c

Log Message:
Bump up XEN source API compatibility to 0x00030208 from 0x00030201,

but maintain backwards source API compilation compatibility.

ie; sources with config(5)
options __XEN_INTERFACE_VERSION__=0x00030201 # Xen 3.1 interface

should compile and run without problems.

Not that API version 0x00030201 is the lowest version we support now.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/amd64/conf/std.xen
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/xen/conf/std.xen
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/xen/include/hypervisor.h
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/xen/include/xen.h
cvs rdiff -u -r1.81 -r1.82 src/sys/arch/xen/x86/x86_xpmap.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/conf/std.xen
diff -u src/sys/arch/amd64/conf/std.xen:1.10 src/sys/arch/amd64/conf/std.xen:1.11
--- src/sys/arch/amd64/conf/std.xen:1.10	Sat Feb  2 12:32:54 2019
+++ src/sys/arch/amd64/conf/std.xen	Mon Feb  4 18:14:53 2019
@@ -1,4 +1,4 @@
-# $NetBSD: std.xen,v 1.10 2019/02/02 12:32:54 cherry Exp $
+# $NetBSD: std.xen,v 1.11 2019/02/04 18:14:53 cherry Exp $
 # NetBSD: std.i386,v 1.24 2003/02/26 21:33:36 fvdl Exp 
 #
 # standard, required NetBSD/i386 'options'
@@ -7,7 +7,7 @@ machine xen amd64
 include 	"conf/std"	# MI standard options
 
 options 	XEN	#Xen support
-options 	__XEN_INTERFACE_VERSION__=0x00030201 # Xen 3.1 interface
+options 	__XEN_INTERFACE_VERSION__=0x00030208 # Xen 3.1 interface
 #options 	__XEN_INTERFACE_VERSION__=0x00030205 # Xen 3.1 interface
 
 options 	CPU_IN_CKSUM

Index: src/sys/arch/xen/conf/std.xen
diff -u src/sys/arch/xen/conf/std.xen:1.9 src/sys/arch/xen/conf/std.xen:1.10
--- src/sys/arch/xen/conf/std.xen:1.9	Sat Feb  2 12:32:54 2019
+++ src/sys/arch/xen/conf/std.xen	Mon Feb  4 18:14:53 2019
@@ -1,4 +1,4 @@
-# $NetBSD: std.xen,v 1.9 2019/02/02 12:32:54 cherry Exp $
+# $NetBSD: std.xen,v 1.10 2019/02/04 18:14:53 cherry Exp $
 # NetBSD: std.i386,v 1.24 2003/02/26 21:33:36 fvdl Exp 
 #
 # standard, required NetBSD/i386 'options'
@@ -6,7 +6,7 @@
 machine xen i386
 include		"conf/std"	# MI standard options
 
-options 	__XEN_INTERFACE_VERSION__=0x00030201 # Xen 3.1 interface
+options 	__XEN_INTERFACE_VERSION__=0x00030208 # Xen 3.1 interface
 
 options 	EXEC_AOUT	# exec a.out binaries
 options 	EXEC_ELF32	# exec ELF binaries

Index: src/sys/arch/xen/include/hypervisor.h
diff -u src/sys/arch/xen/include/hypervisor.h:1.48 src/sys/arch/xen/include/hypervisor.h:1.49
--- src/sys/arch/xen/include/hypervisor.h:1.48	Sat Feb  2 14:50:15 2019
+++ src/sys/arch/xen/include/hypervisor.h	Mon Feb  4 18:14:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor.h,v 1.48 2019/02/02 14:50:15 cherry Exp $	*/
+/*	$NetBSD: hypervisor.h,v 1.49 2019/02/04 18:14:53 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -94,6 +94,7 @@ struct xen_npx_attach_args {
 #include 
 #include 
 
+#if __XEN_INTERFACE_VERSION < 0x00030208
 /* Undo namespace damage from xen/include/public/io/ring.h
  * The proper fix is to get upstream to stop assuming that all OSs use
  * mb(), rmb(), wmb().
@@ -105,6 +106,7 @@ struct xen_npx_attach_args {
 #define xen_mb()  membar_sync()
 #define xen_rmb() membar_producer()
 #define xen_wmb() membar_consumer()
+#endif /* __XEN_INTERFACE_VERSION */
 
 #include 
 

Index: src/sys/arch/xen/include/xen.h
diff -u src/sys/arch/xen/include/xen.h:1.42 src/sys/arch/xen/include/xen.h:1.43
--- src/sys/arch/xen/include/xen.h:1.42	Sat Feb  2 12:32:55 2019
+++ src/sys/arch/xen/include/xen.h	Mon Feb  4 18:14:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen.h,v 1.42 2019/02/02 12:32:55 cherry Exp $	*/
+/*	$NetBSD: xen.h,v 1.43 2019/02/04 18:14:53 cherry Exp $	*/
 
 /*
  *
@@ -122,6 +122,12 @@ void printk(const char *, ...);
 /* Everything below this point is not included by assembler (.S) files. */
 #ifndef _LOCORE
 
+/* Version Specific Glue */
+#if __XEN_INTERFACE_VERSION__ >= 0x00030203
+#define console_mfnconsole.domU.mfn
+#define console_evtchn console.domU.evtchn
+#endif
+
 /* some function prototypes */
 void trap_init(void);
 void xpq_flush_cache(void);

Index: src/sys/arch/xen/x86/x86_xpmap.c
diff -u src/sys/arch/xen/x86/x86_xpmap.c:1.81 src/sys/arch/xen/x86/x86_xpmap.c:1.82
--- src/sys/arch/xen/x86/x86_xpmap.c:1.81	Sun Jul 29 08:02:24 2018
+++ src/sys/arch/xen/x86/x86_xpmap.c	Mon Feb  4 18:14:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.81 2018/07/29 08:02:24 maxv Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.82 2019/02/04 18:14:53 cherry Exp $	*/
 
 /*
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.81 

CVS commit: src/sys/arch/amd64/conf

2019-02-02 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Feb  2 15:13:54 UTC 2019

Modified Files:
src/sys/arch/amd64/conf: XEN3_DOM0

Log Message:
Re-enable ixg(4) on NetBSD/xen dom0

Namespace conflicts have been resolved.

Note that driver still has an incorrect us of __asm() gnu primitives
via

#if __FreeBSD_version < 80
...
#endif

Since __FreeBSD_version is undefined and thus equates to 0 and thus
satisfies the inequality.

Needs fixing by driver maintainer.


To generate a diff of this commit:
cvs rdiff -u -r1.163 -r1.164 src/sys/arch/amd64/conf/XEN3_DOM0

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/conf/XEN3_DOM0
diff -u src/sys/arch/amd64/conf/XEN3_DOM0:1.163 src/sys/arch/amd64/conf/XEN3_DOM0:1.164
--- src/sys/arch/amd64/conf/XEN3_DOM0:1.163	Sat Feb  2 12:05:09 2019
+++ src/sys/arch/amd64/conf/XEN3_DOM0	Sat Feb  2 15:13:54 2019
@@ -1,4 +1,4 @@
-# $NetBSD: XEN3_DOM0,v 1.163 2019/02/02 12:05:09 cherry Exp $
+# $NetBSD: XEN3_DOM0,v 1.164 2019/02/02 15:13:54 cherry Exp $
 
 include 	"arch/amd64/conf/std.xen"
 
@@ -10,7 +10,7 @@ options 	INCLUDE_CONFIG_FILE	# embed con
 #options 	UVMHIST_PRINT
 #options 	SYSCALL_DEBUG
 
-#ident		"XEN3_DOM0-$Revision: 1.163 $"
+#ident		"XEN3_DOM0-$Revision: 1.164 $"
 
 maxusers	32		# estimated number of users
 
@@ -371,7 +371,7 @@ ipw*	at pci? dev ? function ?	# Intel PR
 iwi*	at pci? dev ? function ?	# Intel PRO/Wireless 2200BG
 iwn*	at pci? dev ? function ?	# Intel PRO/Wireless 4965AGN
 iwm*	at pci? dev ? function ?	# Intel Wireless WiFi Link 7xxx
-#ixg*	at pci? dev ? function ?	# Intel 8259x 10 gigabit
+ixg*	at pci? dev ? function ?	# Intel 8259x 10 gigabit
 jme*	at pci? dev ? function ?	# JMicron JMC2[56]0 ethernet
 le*	at pci? dev ? function ?	# PCnet-PCI Ethernet
 lii*	at pci? dev ? function ?	# Atheros L2 Fast-Ethernet



CVS commit: src/sys/arch/xen/include

2019-02-02 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Feb  2 15:09:32 UTC 2019

Modified Files:
src/sys/arch/xen/include: xenring.h

Log Message:
Fix build. A multiline macro needs 'line continuation'.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/xen/include/xenring.h

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/xen/include/xenring.h
diff -u src/sys/arch/xen/include/xenring.h:1.2 src/sys/arch/xen/include/xenring.h:1.3
--- src/sys/arch/xen/include/xenring.h:1.2	Sat Feb  2 14:50:15 2019
+++ src/sys/arch/xen/include/xenring.h	Sat Feb  2 15:09:32 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: xenring.h,v 1.2 2019/02/02 14:50:15 cherry Exp $ */
+/* $NetBSD: xenring.h,v 1.3 2019/02/02 15:09:32 cherry Exp $ */
 
 /*
  * Glue goop for xbd ring request/response protocol structures.
@@ -10,7 +10,7 @@
 #ifndef _XEN_RING_H
 #define _XEN_RING_H
 
-#if (__XEN_INTERFACE_VERSION__ >= 0x00030201) &&
+#if (__XEN_INTERFACE_VERSION__ >= 0x00030201) && \
 	(__XEN_INTERFACE_VERSION < 0x00030208)
 
 #include 



CVS commit: src/sys/arch/xen/include

2019-02-02 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Feb  2 14:50:15 UTC 2019

Modified Files:
src/sys/arch/xen/include: hypervisor.h xenring.h

Log Message:
Remove mb(), rmb() and wmb() from the kernel namespace.

These are introduced by external/bsd/common/include/asm/barrier.h

The purpose of barrier.h is to bridge the use of linux API calls
within code which uses them, such as drm code. The XEN api implicitly
uses these calls which are linuxisms within io/ring.h

This diff undos the damage.

The correct fix is to modify io/ring.h to not assume that all OSs that
XEN runs on has these functions, and to appropriately conditionally via
#ifdef __NetBSD__/#endif use the appropriate NetBSD functions. These
changes then need to be pushed upstream.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/xen/include/hypervisor.h
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/xen/include/xenring.h

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/xen/include/hypervisor.h
diff -u src/sys/arch/xen/include/hypervisor.h:1.47 src/sys/arch/xen/include/hypervisor.h:1.48
--- src/sys/arch/xen/include/hypervisor.h:1.47	Sat Feb  2 12:32:55 2019
+++ src/sys/arch/xen/include/hypervisor.h	Sat Feb  2 14:50:15 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor.h,v 1.47 2019/02/02 12:32:55 cherry Exp $	*/
+/*	$NetBSD: hypervisor.h,v 1.48 2019/02/02 14:50:15 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -80,7 +80,7 @@ struct xen_npx_attach_args {
 #define	s32 int32_t
 #define	s64 int64_t
 
-#include  /* Linux mb() and friends */
+#include 
 
 #include 
 #include 
@@ -94,6 +94,18 @@ struct xen_npx_attach_args {
 #include 
 #include 
 
+/* Undo namespace damage from xen/include/public/io/ring.h
+ * The proper fix is to get upstream to stop assuming that all OSs use
+ * mb(), rmb(), wmb().
+ */
+#undef xen_mb
+#undef xen_rmb
+#undef xen_wmb
+
+#define xen_mb()  membar_sync()
+#define xen_rmb() membar_producer()
+#define xen_wmb() membar_consumer()
+
 #include 
 
 #undef u8

Index: src/sys/arch/xen/include/xenring.h
diff -u src/sys/arch/xen/include/xenring.h:1.1 src/sys/arch/xen/include/xenring.h:1.2
--- src/sys/arch/xen/include/xenring.h:1.1	Sat Feb  2 12:32:55 2019
+++ src/sys/arch/xen/include/xenring.h	Sat Feb  2 14:50:15 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: xenring.h,v 1.1 2019/02/02 12:32:55 cherry Exp $ */
+/* $NetBSD: xenring.h,v 1.2 2019/02/02 14:50:15 cherry Exp $ */
 
 /*
  * Glue goop for xbd ring request/response protocol structures.
@@ -10,10 +10,28 @@
 #ifndef _XEN_RING_H
 #define _XEN_RING_H
 
-#if __XEN_INTERFACE_VERSION__ >= 0x00030201
+#if (__XEN_INTERFACE_VERSION__ >= 0x00030201) &&
+	(__XEN_INTERFACE_VERSION < 0x00030208)
 
 #include 
 
+/*
+ * Undo namespace damage from xen/include/public/io/ring.h
+ * The proper fix is to get upstream to stop assuming that all OSs use
+ * mb(), rmb(), wmb().
+ */
+#undef xen_mb
+#undef xen_rmb
+#undef xen_wmb
+
+#define xen_mb()  membar_sync()
+#define xen_rmb() membar_producer()
+#define xen_wmb() membar_consumer()
+
+/*
+ * Define ring types. These were previously part of the public API.
+ * Not anymore.
+ */
 DEFINE_RING_TYPES(blkif_x86_32, struct blkif_request, struct blkif_response);
 DEFINE_RING_TYPES(blkif_x86_64, struct blkif_request, struct blkif_response);
 
@@ -30,5 +48,6 @@ union blkif_back_ring_proto {
 };
 typedef union blkif_back_ring_proto blkif_back_ring_proto_t;
 
-#endif /* __XEN_INTERFACE_VERSION__ >= 0x00030201 */
+#endif /* __XEN_INTERFACE_VERSION__ */
+
 #endif /* _XEN_RING_H_ */



CVS commit: src/sys/arch/xen/include/xen-public

2019-02-02 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Feb  2 12:40:32 UTC 2019

Removed Files:
src/sys/arch/xen/include/xen-public: COPYING arch-ia64.h arch-x86_32.h
arch-x86_64.h callback.h dom0_ops.h domctl.h elfnote.h elfstructs.h
event_channel.h features.h grant_table.h kexec.h libelf.h
mem_event.h memory.h nmi.h physdev.h platform.h sched.h sysctl.h
tmem.h trace.h vcpu.h version.h xen-compat.h xen.h xencomm.h
xenoprof.h
src/sys/arch/xen/include/xen-public/arch-ia64: debug_op.h sioemu.h
src/sys/arch/xen/include/xen-public/arch-ia64/hvm: memmap.h save.h
src/sys/arch/xen/include/xen-public/arch-x86: cpuid.h xen-mca.h
xen-x86_32.h xen-x86_64.h xen.h
src/sys/arch/xen/include/xen-public/arch-x86/hvm: save.h
src/sys/arch/xen/include/xen-public/hvm: e820.h hvm_info_table.h
hvm_op.h ioreq.h params.h save.h vmx_assist.h
src/sys/arch/xen/include/xen-public/io: blkif.h console.h fbif.h fsif.h
kbdif.h netif.h pciif.h protocols.h ring.h tpmif.h usbif.h
vscsiif.h xenbus.h xs_wire.h
src/sys/arch/xen/include/xen-public/xsm: acm.h acm_ops.h flask_op.h

Log Message:
Remove legacy XEN source public API from source.

These have now been moved to sys/external/mit/xen-include-public/dist


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.2 -r0 src/sys/arch/xen/include/xen-public/COPYING \
src/sys/arch/xen/include/xen-public/arch-ia64.h \
src/sys/arch/xen/include/xen-public/callback.h \
src/sys/arch/xen/include/xen-public/elfnote.h \
src/sys/arch/xen/include/xen-public/features.h \
src/sys/arch/xen/include/xen-public/kexec.h \
src/sys/arch/xen/include/xen-public/memory.h \
src/sys/arch/xen/include/xen-public/nmi.h \
src/sys/arch/xen/include/xen-public/platform.h \
src/sys/arch/xen/include/xen-public/sched.h \
src/sys/arch/xen/include/xen-public/vcpu.h \
src/sys/arch/xen/include/xen-public/version.h \
src/sys/arch/xen/include/xen-public/xen-compat.h \
src/sys/arch/xen/include/xen-public/xencomm.h \
src/sys/arch/xen/include/xen-public/xenoprof.h
cvs rdiff -u -r1.5 -r0 src/sys/arch/xen/include/xen-public/arch-x86_32.h \
src/sys/arch/xen/include/xen-public/arch-x86_64.h \
src/sys/arch/xen/include/xen-public/dom0_ops.h
cvs rdiff -u -r1.2 -r0 src/sys/arch/xen/include/xen-public/domctl.h \
src/sys/arch/xen/include/xen-public/elfstructs.h \
src/sys/arch/xen/include/xen-public/sysctl.h
cvs rdiff -u -r1.6 -r0 src/sys/arch/xen/include/xen-public/event_channel.h \
src/sys/arch/xen/include/xen-public/grant_table.h \
src/sys/arch/xen/include/xen-public/trace.h
cvs rdiff -u -r1.1.1.1 -r0 src/sys/arch/xen/include/xen-public/libelf.h \
src/sys/arch/xen/include/xen-public/mem_event.h \
src/sys/arch/xen/include/xen-public/tmem.h
cvs rdiff -u -r1.7 -r0 src/sys/arch/xen/include/xen-public/physdev.h
cvs rdiff -u -r1.11 -r0 src/sys/arch/xen/include/xen-public/xen.h
cvs rdiff -u -r1.1.1.2 -r0 \
src/sys/arch/xen/include/xen-public/arch-ia64/debug_op.h \
src/sys/arch/xen/include/xen-public/arch-ia64/sioemu.h
cvs rdiff -u -r1.1.1.2 -r0 \
src/sys/arch/xen/include/xen-public/arch-ia64/hvm/memmap.h \
src/sys/arch/xen/include/xen-public/arch-ia64/hvm/save.h
cvs rdiff -u -r1.1.1.2 -r0 \
src/sys/arch/xen/include/xen-public/arch-x86/cpuid.h \
src/sys/arch/xen/include/xen-public/arch-x86/xen-x86_64.h
cvs rdiff -u -r1.2 -r0 src/sys/arch/xen/include/xen-public/arch-x86/xen-mca.h \
src/sys/arch/xen/include/xen-public/arch-x86/xen-x86_32.h \
src/sys/arch/xen/include/xen-public/arch-x86/xen.h
cvs rdiff -u -r1.1.1.2 -r0 \
src/sys/arch/xen/include/xen-public/arch-x86/hvm/save.h
cvs rdiff -u -r1.1.1.2 -r0 src/sys/arch/xen/include/xen-public/hvm/e820.h \
src/sys/arch/xen/include/xen-public/hvm/hvm_info_table.h \
src/sys/arch/xen/include/xen-public/hvm/hvm_op.h \
src/sys/arch/xen/include/xen-public/hvm/ioreq.h \
src/sys/arch/xen/include/xen-public/hvm/params.h \
src/sys/arch/xen/include/xen-public/hvm/save.h
cvs rdiff -u -r1.1.1.1 -r0 \
src/sys/arch/xen/include/xen-public/hvm/vmx_assist.h
cvs rdiff -u -r1.7 -r0 src/sys/arch/xen/include/xen-public/io/blkif.h
cvs rdiff -u -r1.1.1.2 -r0 src/sys/arch/xen/include/xen-public/io/console.h \
src/sys/arch/xen/include/xen-public/io/fbif.h \
src/sys/arch/xen/include/xen-public/io/fsif.h \
src/sys/arch/xen/include/xen-public/io/kbdif.h \
src/sys/arch/xen/include/xen-public/io/pciif.h \
src/sys/arch/xen/include/xen-public/io/protocols.h \
src/sys/arch/xen/include/xen-public/io/tpmif.h \
src/sys/arch/xen/include/xen-public/io/xenbus.h
cvs rdiff -u -r1.6 -r0 src/sys/arch/xen/include/xen-public/io/netif.h
cvs rdiff -u -r1.3 -r0 src/sys/arch/xen/include/xen-public/io/ring.h
cvs rdiff -u -r1.1.1.1 -r0 src/sys/arch/xen/include/xen-public/io/usbif.h \

CVS commit: src/sys/arch

2019-02-02 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Feb  2 12:32:55 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: genassym.cf locore.S
src/sys/arch/amd64/conf: std.xen
src/sys/arch/i386/i386: genassym.cf
src/sys/arch/x86/include: cpu.h
src/sys/arch/x86/x86: cpu_ucode.c pmap.c
src/sys/arch/xen/conf: Makefile.xen std.xen
src/sys/arch/xen/include: granttables.h hypervisor.h intr.h xen.h
xenbus.h
src/sys/arch/xen/include/amd64: hypercalls.h
src/sys/arch/xen/include/i386: hypercalls.h
src/sys/arch/xen/x86: cpu.c xen_ipi.c xen_pmap.c
src/sys/arch/xen/xen: clock.c hypervisor.c if_xennet_xenbus.c pciback.c
xbd_xenbus.c xbdback_xenbus.c xen_machdep.c xencons.c xpci_xenbus.c
Added Files:
src/sys/arch/xen/include: xenring.h

Log Message:
Switch NetBSD/xen to use XEN api tag RELEASE-4.11.1

The headers for this api are in sys/external/mit/xen-include-public/dist/


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/sys/arch/amd64/amd64/genassym.cf
cvs rdiff -u -r1.174 -r1.175 src/sys/arch/amd64/amd64/locore.S
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/amd64/conf/std.xen
cvs rdiff -u -r1.108 -r1.109 src/sys/arch/i386/i386/genassym.cf
cvs rdiff -u -r1.101 -r1.102 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/x86/x86/cpu_ucode.c
cvs rdiff -u -r1.319 -r1.320 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/xen/conf/Makefile.xen
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/xen/conf/std.xen
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/xen/include/granttables.h
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/xen/include/hypervisor.h
cvs rdiff -u -r1.51 -r1.52 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/xen/include/xen.h
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/xen/include/xenbus.h
cvs rdiff -u -r0 -r1.1 src/sys/arch/xen/include/xenring.h
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/xen/include/amd64/hypercalls.h
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/xen/include/i386/hypercalls.h
cvs rdiff -u -r1.127 -r1.128 src/sys/arch/xen/x86/cpu.c
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/xen/x86/xen_ipi.c
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/xen/x86/xen_pmap.c
cvs rdiff -u -r1.76 -r1.77 src/sys/arch/xen/xen/clock.c
cvs rdiff -u -r1.69 -r1.70 src/sys/arch/xen/xen/hypervisor.c
cvs rdiff -u -r1.82 -r1.83 src/sys/arch/xen/xen/if_xennet_xenbus.c
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/xen/xen/pciback.c
cvs rdiff -u -r1.91 -r1.92 src/sys/arch/xen/xen/xbd_xenbus.c
cvs rdiff -u -r1.70 -r1.71 src/sys/arch/xen/xen/xbdback_xenbus.c
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/xen/xen/xen_machdep.c
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/xen/xen/xencons.c
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/xen/xen/xpci_xenbus.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/genassym.cf
diff -u src/sys/arch/amd64/amd64/genassym.cf:1.71 src/sys/arch/amd64/amd64/genassym.cf:1.72
--- src/sys/arch/amd64/amd64/genassym.cf:1.71	Tue Dec 25 06:50:11 2018
+++ src/sys/arch/amd64/amd64/genassym.cf	Sat Feb  2 12:32:54 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: genassym.cf,v 1.71 2018/12/25 06:50:11 cherry Exp $
+#	$NetBSD: genassym.cf,v 1.72 2019/02/02 12:32:54 cherry Exp $
 
 #
 # Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -119,7 +119,7 @@ include 
 endif
 
 ifdef XEN
-include 
+include 
 endif  
 
 include 

Index: src/sys/arch/amd64/amd64/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.174 src/sys/arch/amd64/amd64/locore.S:1.175
--- src/sys/arch/amd64/amd64/locore.S:1.174	Sun Aug 12 15:31:01 2018
+++ src/sys/arch/amd64/amd64/locore.S	Sat Feb  2 12:32:54 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.174 2018/08/12 15:31:01 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.175 2019/02/02 12:32:54 cherry Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -276,8 +276,8 @@
 
 #ifdef XEN
 #define __ASSEMBLY__
-#include 
-#include 
+#include 
+#include 
 #define ELFNOTE(name, type, desctype, descdata...) \
 .pushsection .note.name			;	\
   .align 4;	\

Index: src/sys/arch/amd64/conf/std.xen
diff -u src/sys/arch/amd64/conf/std.xen:1.9 src/sys/arch/amd64/conf/std.xen:1.10
--- src/sys/arch/amd64/conf/std.xen:1.9	Thu Jan 12 05:24:36 2017
+++ src/sys/arch/amd64/conf/std.xen	Sat Feb  2 12:32:54 2019
@@ -1,4 +1,4 @@
-# $NetBSD: std.xen,v 1.9 2017/01/12 05:24:36 ryo Exp $
+# $NetBSD: std.xen,v 1.10 2019/02/02 12:32:54 cherry Exp $
 # NetBSD: std.i386,v 1.24 2003/02/26 21:33:36 fvdl Exp 
 #
 # standard, required NetBSD/i386 'options'
@@ -7,6 +7,7 @@ machine xen amd64
 include 	"conf/std"	# MI standard options
 
 options 	XEN	#Xen support
+options 	__XEN_INTERFACE_VERSION__=0x00030201 # Xen 3.1 interface
 #options 	__XEN_INTERFACE_VERSION__=0x00030205 # Xen 3.1 interface
 
 options 	CPU_IN_CKSUM

Index: src/sys/arch/i386/i386/genassym.cf
diff -u 

CVS commit: src/sys/arch/amd64/conf

2019-02-02 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Feb  2 12:05:09 UTC 2019

Modified Files:
src/sys/arch/amd64/conf: XEN3_DOM0

Log Message:
Summary: Disable ixg(4) until the linuxist mb() API re-definition
within the XEN amd64 dom0 build is resolved.

Detail:
The xen public headers >= 0x00030201 depend on a linuxism - a memory
barrier "API" namely mb(), rmb() and wmb(). These are made accessible
to NetBSD code via the interface
sys/external/bsd/common/include/asm/barrier.h

Currently the ixg(4) driver uses an identical API by defining them
(incorrectly) to inline assembler macro definitions in
sys/dev/pci/ixgbe/ixgbe_osdep.h

This will result in the dom0 builds failing to build due to this
redefinition of the macros. We therefore disable the driver in
NetBSD/amd64 dom0 in order to facilitate smoothly moving the XEN
kernel builds to the new XEN source level API (RELEASE-4.11.1).

The fix for this is trivial, but needs the attention of the driver
maintainer.


To generate a diff of this commit:
cvs rdiff -u -r1.162 -r1.163 src/sys/arch/amd64/conf/XEN3_DOM0

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/conf/XEN3_DOM0
diff -u src/sys/arch/amd64/conf/XEN3_DOM0:1.162 src/sys/arch/amd64/conf/XEN3_DOM0:1.163
--- src/sys/arch/amd64/conf/XEN3_DOM0:1.162	Tue Dec 25 11:56:14 2018
+++ src/sys/arch/amd64/conf/XEN3_DOM0	Sat Feb  2 12:05:09 2019
@@ -1,4 +1,4 @@
-# $NetBSD: XEN3_DOM0,v 1.162 2018/12/25 11:56:14 mlelstv Exp $
+# $NetBSD: XEN3_DOM0,v 1.163 2019/02/02 12:05:09 cherry Exp $
 
 include 	"arch/amd64/conf/std.xen"
 
@@ -10,7 +10,7 @@ options 	INCLUDE_CONFIG_FILE	# embed con
 #options 	UVMHIST_PRINT
 #options 	SYSCALL_DEBUG
 
-#ident		"XEN3_DOM0-$Revision: 1.162 $"
+#ident		"XEN3_DOM0-$Revision: 1.163 $"
 
 maxusers	32		# estimated number of users
 
@@ -371,7 +371,7 @@ ipw*	at pci? dev ? function ?	# Intel PR
 iwi*	at pci? dev ? function ?	# Intel PRO/Wireless 2200BG
 iwn*	at pci? dev ? function ?	# Intel PRO/Wireless 4965AGN
 iwm*	at pci? dev ? function ?	# Intel Wireless WiFi Link 7xxx
-ixg*	at pci? dev ? function ?	# Intel 8259x 10 gigabit
+#ixg*	at pci? dev ? function ?	# Intel 8259x 10 gigabit
 jme*	at pci? dev ? function ?	# JMicron JMC2[56]0 ethernet
 le*	at pci? dev ? function ?	# PCnet-PCI Ethernet
 lii*	at pci? dev ? function ?	# Atheros L2 Fast-Ethernet



CVS import: src/sys/external/mit/xen-include-public/dist/xen/include/public

2019-02-02 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Feb  2 08:03:48 UTC 2019

Update of 
/cvsroot/src/sys/external/mit/xen-include-public/dist/xen/include/public
In directory ivanova.netbsd.org:/tmp/cvs-serv20221

Log Message:
Import Xen public headers version 4.11.1

Release tag: RELEASE-4-11-1

git log of the freeze is as follows:

commit 96cbd0893f783997caaf117e897d5fa8f2dc7b5f
Author: Jan Beulich 
Date:   Thu Nov 29 15:04:11 2018 +0100

update Xen version to 4.11.1


Status:

Vendor Tag: RELEASE-4-11-1
Release Tags:   xen-4-11-1

N src/sys/external/mit/xen-include-public/dist/xen/include/public/COPYING
N src/sys/external/mit/xen-include-public/dist/xen/include/public/arch-arm.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/arch-x86_32.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/arch-x86_64.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/callback.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/dom0_ops.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/domctl.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/elfnote.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/features.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/errno.h
N 
src/sys/external/mit/xen-include-public/dist/xen/include/public/event_channel.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/kexec.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/grant_table.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/memory.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/nmi.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/physdev.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/platform.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/trace.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/pmu.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/sched.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/sysctl.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/tmem.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/vcpu.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/version.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/vm_event.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/xen-compat.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/xen.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/xencomm.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/xenoprof.h
N 
src/sys/external/mit/xen-include-public/dist/xen/include/public/arch-arm/smccc.h
N 
src/sys/external/mit/xen-include-public/dist/xen/include/public/arch-arm/hvm/save.h
N 
src/sys/external/mit/xen-include-public/dist/xen/include/public/arch-x86/cpufeatureset.h
N 
src/sys/external/mit/xen-include-public/dist/xen/include/public/arch-x86/cpuid.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/arch-x86/pmu.h
N 
src/sys/external/mit/xen-include-public/dist/xen/include/public/arch-x86/xen-mca.h
N 
src/sys/external/mit/xen-include-public/dist/xen/include/public/arch-x86/xen-x86_32.h
N 
src/sys/external/mit/xen-include-public/dist/xen/include/public/arch-x86/xen-x86_64.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/arch-x86/xen.h
N 
src/sys/external/mit/xen-include-public/dist/xen/include/public/arch-x86/hvm/save.h
N 
src/sys/external/mit/xen-include-public/dist/xen/include/public/arch-x86/hvm/start_info.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/hvm/dm_op.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/hvm/e820.h
N 
src/sys/external/mit/xen-include-public/dist/xen/include/public/hvm/hvm_info_table.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/hvm/hvm_op.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/hvm/hvm_vcpu.h
N 
src/sys/external/mit/xen-include-public/dist/xen/include/public/hvm/hvm_xs_strings.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/hvm/ioreq.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/hvm/params.h
N 
src/sys/external/mit/xen-include-public/dist/xen/include/public/hvm/pvdrivers.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/hvm/save.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/io/9pfs.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/io/blkif.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/io/console.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/io/displif.h
N src/sys/external/mit/xen-include-public/dist/xen/include/public/io/fbif.h
N 

CVS commit: src/sys/arch/xen/include

2019-01-23 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Jan 24 04:16:16 UTC 2019

Modified Files:
src/sys/arch/xen/include/amd64: hypercalls.h
src/sys/arch/xen/include/i386: hypercalls.h

Log Message:
The event_channel_op hypercall uses a newer API since
__XEN_INTERFACE_VERSION__  0x00030202

Since hvm_op only supports event_channel_op via the newer API, we
can't get away with our current event_channel_op_compat shim.

We thus introduce the new API to our internal hypercall C API
interface.

This change should have no effect on the PV kernels, since they will
continue to use the pre 0x00030202 API.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/xen/include/amd64/hypercalls.h
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/xen/include/i386/hypercalls.h

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/xen/include/amd64/hypercalls.h
diff -u src/sys/arch/xen/include/amd64/hypercalls.h:1.9 src/sys/arch/xen/include/amd64/hypercalls.h:1.10
--- src/sys/arch/xen/include/amd64/hypercalls.h:1.9	Thu Jan 24 04:11:38 2019
+++ src/sys/arch/xen/include/amd64/hypercalls.h	Thu Jan 24 04:16:16 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: hypercalls.h,v 1.9 2019/01/24 04:11:38 cherry Exp $ */
+/* $NetBSD: hypercalls.h,v 1.10 2019/01/24 04:16:16 cherry Exp $ */
 /**
  * hypercall.h
  * 
@@ -242,9 +242,14 @@ HYPERVISOR_update_va_mapping(
 }
 
 static inline int
-HYPERVISOR_event_channel_op(void *op)
+HYPERVISOR_event_channel_op(evtchn_op_t *op)
 {
+	KASSERT(op != NULL);
+#if __XEN_INTERFACE_VERSION__ < 0x00030202
 	return _hypercall1(int, event_channel_op, op);
+#else
+	return _hypercall2(int, event_channel_op, op->cmd, >u);
+#endif
 }
 
 static inline int

Index: src/sys/arch/xen/include/i386/hypercalls.h
diff -u src/sys/arch/xen/include/i386/hypercalls.h:1.16 src/sys/arch/xen/include/i386/hypercalls.h:1.17
--- src/sys/arch/xen/include/i386/hypercalls.h:1.16	Thu Jul 26 17:20:08 2018
+++ src/sys/arch/xen/include/i386/hypercalls.h	Thu Jan 24 04:16:16 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypercalls.h,v 1.16 2018/07/26 17:20:08 maxv Exp $	*/
+/*	$NetBSD: hypercalls.h,v 1.17 2019/01/24 04:16:16 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -457,14 +457,20 @@ HYPERVISOR_multicall(void *call_list, in
 
 
 static __inline int
-HYPERVISOR_event_channel_op(void *op)
+HYPERVISOR_event_channel_op(evtchn_op_t *op)
 {
 int ret;
 unsigned long ign1;
 
+#if __XEN_INTERFACE_VERSION__ < 0x00030202
 _hypercall(__HYPERVISOR_event_channel_op, _harg("1" (op)),
 	_harg("=a" (ret), "=b" (ign1)));
+#else
+unsigned long ign2;
 
+_hypercall(__HYPERVISOR_event_channel_op, _harg("1" (op->cmd), "2" (>u)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
+#endif
 return ret;
 }
 



CVS commit: src/sys/arch/xen/include/amd64

2019-01-23 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Jan 24 04:11:38 UTC 2019

Modified Files:
src/sys/arch/xen/include/amd64: hypercalls.h

Log Message:
hvm_op returns a signed value.

The pattern is that a hypercall which returns a value < 0 may imply an
error.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/xen/include/amd64/hypercalls.h

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/xen/include/amd64/hypercalls.h
diff -u src/sys/arch/xen/include/amd64/hypercalls.h:1.8 src/sys/arch/xen/include/amd64/hypercalls.h:1.9
--- src/sys/arch/xen/include/amd64/hypercalls.h:1.8	Wed Dec  7 16:01:39 2011
+++ src/sys/arch/xen/include/amd64/hypercalls.h	Thu Jan 24 04:11:38 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: hypercalls.h,v 1.8 2011/12/07 16:01:39 cegger Exp $ */
+/* $NetBSD: hypercalls.h,v 1.9 2019/01/24 04:11:38 cherry Exp $ */
 /**
  * hypercall.h
  * 
@@ -361,11 +361,11 @@ HYPERVISOR_nmi_op(
 	return _hypercall2(int, nmi_op, op, arg);
 }
 
-static inline unsigned long
+static inline long
 HYPERVISOR_hvm_op(
 int op, void *arg)
 {
-return _hypercall2(unsigned long, hvm_op, op, arg);
+return _hypercall2(long, hvm_op, op, arg);
 }
 
 static inline int



CVS commit: src/sys/arch

2019-01-06 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Jan  6 14:35:31 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: cpufunc.S
src/sys/arch/i386/i386: cpufunc.S i386func.S
src/sys/arch/xen/x86: xenfunc.c

Log Message:
Rollback http://mail-index.netbsd.org/source-changes/2018/12/22/msg101629.html

This change breaks module loading due to weak alias being unsupported
in the kernel module linker.

Requested by maxv@ and others as it affects their work.

No immediate decision on a replacement method is available, but other options
suggested include pre-processing, conditional compilation (#ifdef etc) and other
source level methods to avoid linktime decision making.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/amd64/amd64/cpufunc.S
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/i386/i386/cpufunc.S
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/i386/i386/i386func.S
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/xen/x86/xenfunc.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/cpufunc.S
diff -u src/sys/arch/amd64/amd64/cpufunc.S:1.34 src/sys/arch/amd64/amd64/cpufunc.S:1.35
--- src/sys/arch/amd64/amd64/cpufunc.S:1.34	Sat Dec 22 21:27:22 2018
+++ src/sys/arch/amd64/amd64/cpufunc.S	Sun Jan  6 14:35:31 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.S,v 1.34 2018/12/22 21:27:22 cherry Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.35 2019/01/06 14:35:31 cherry Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -63,53 +63,18 @@ ENTRY(x86_mfence)
 	ret
 END(x86_mfence)
 
-/*
- * These functions below should always be accessed via the corresponding wrapper
- * function names defined in x86/include/cpufunc.h and exported as WEAK_ALIAS()
- *
- * We use this rather roundabout method so that a runtime wrapper function may
- * be made available for PVHVM, which could override both native and PV aliases
- * and decide which to invoke at run time.
- */
-
-WEAK_ALIAS(invlpg, amd64_invlpg)
-WEAK_ALIAS(lidt, amd64_lidt)
-WEAK_ALIAS(lldt, amd64_lldt)
-WEAK_ALIAS(ltr, amd64_ltr)
-WEAK_ALIAS(lcr0, amd64_lcr0)
-WEAK_ALIAS(rcr0, amd64_rcr0)
-WEAK_ALIAS(rcr2, amd64_rcr2)
-WEAK_ALIAS(lcr2, amd64_lcr2)
-WEAK_ALIAS(rcr3, amd64_rcr3)
-WEAK_ALIAS(lcr3, amd64_lcr3)
-WEAK_ALIAS(tlbflush, amd64_tlbflush)
-WEAK_ALIAS(tlbflushg, amd64_tlbflushg)
-WEAK_ALIAS(rdr0, amd64_rdr0)
-WEAK_ALIAS(ldr0, amd64_ldr0)
-WEAK_ALIAS(rdr1, amd64_rdr1)
-WEAK_ALIAS(ldr1, amd64_ldr1)
-WEAK_ALIAS(rdr2, amd64_rdr2)
-WEAK_ALIAS(ldr2, amd64_ldr2)
-WEAK_ALIAS(rdr3, amd64_rdr3)
-WEAK_ALIAS(ldr3, amd64_ldr3)
-WEAK_ALIAS(rdr6, amd64_rdr6)
-WEAK_ALIAS(ldr6, amd64_ldr6)
-WEAK_ALIAS(rdr7, amd64_rdr7)
-WEAK_ALIAS(ldr7, amd64_ldr7)
-WEAK_ALIAS(wbinvd, amd64_wbinvd)
-
 #ifndef XEN
-ENTRY(amd64_invlpg)
+ENTRY(invlpg)
 	invlpg	(%rdi)
 	ret
-END(amd64_invlpg)
+END(invlpg)
 
-ENTRY(amd64_lidt)
+ENTRY(lidt)
 	lidt	(%rdi)
 	ret
-END(amd64_lidt)
+END(lidt)
 
-ENTRY(amd64_lldt)
+ENTRY(lldt)
 	cmpl	%edi, CPUVAR(CURLDT)
 	jne	1f
 	ret
@@ -117,42 +82,42 @@ ENTRY(amd64_lldt)
 	movl	%edi, CPUVAR(CURLDT)
 	lldt	%di
 	ret
-END(amd64_lldt)
+END(lldt)
 
-ENTRY(amd64_ltr)
+ENTRY(ltr)
 	ltr	%di
 	ret
-END(amd64_ltr)
+END(ltr)
 
-ENTRY(amd64_lcr0)
+ENTRY(lcr0)
 	movq	%rdi, %cr0
 	ret
-END(amd64_lcr0)
+END(lcr0)
 
-ENTRY(amd64_rcr0)
+ENTRY(rcr0)
 	movq	%cr0, %rax
 	ret
-END(amd64_rcr0)
+END(rcr0)
 
-ENTRY(amd64_lcr2)
+ENTRY(lcr2)
 	movq	%rdi, %cr2
 	ret
-END(amd64_lcr2)
+END(lcr2)
 
-ENTRY(amd64_rcr2)
+ENTRY(rcr2)
 	movq	%cr2, %rax
 	ret
-END(amd64_rcr2)
+END(rcr2)
 
-ENTRY(amd64_lcr3)
+ENTRY(lcr3)
 	movq	%rdi, %cr3
 	ret
-END(amd64_lcr3)
+END(lcr3)
 
-ENTRY(amd64_rcr3)
+ENTRY(rcr3)
 	movq	%cr3, %rax
 	ret
-END(amd64_rcr3)
+END(rcr3)
 #endif
 
 ENTRY(lcr4)
@@ -194,7 +159,7 @@ END(rcr8)
  * If PGE is not in use, we reload CR3.
  */
 #ifndef XEN
-ENTRY(amd64_tlbflushg)
+ENTRY(tlbflushg)
 	movq	%cr4, %rax
 	testq	$CR4_PGE, %rax
 	jz	1f
@@ -203,74 +168,74 @@ ENTRY(amd64_tlbflushg)
 	movq	%rdx, %cr4
 	movq	%rax, %cr4
 	ret
-END(amd64_tlbflushg)
+END(tlbflushg)
 
-ENTRY(amd64_tlbflush)
+ENTRY(tlbflush)
 1:
 	movq	%cr3, %rax
 	movq	%rax, %cr3
 	ret
-END(amd64_tlbflush)
+END(tlbflush)
 
-ENTRY(amd64_ldr0)
+ENTRY(ldr0)
 	movq	%rdi, %dr0
 	ret
-END(amd64_ldr0)
+END(ldr0)
 
-ENTRY(amd64_rdr0)
+ENTRY(rdr0)
 	movq	%dr0, %rax
 	ret
-END(amd64_rdr0)
+END(rdr0)
 
-ENTRY(amd64_ldr1)
+ENTRY(ldr1)
 	movq	%rdi, %dr1
 	ret
-END(amd64_ldr1)
+END(ldr1)
 
-ENTRY(amd64_rdr1)
+ENTRY(rdr1)
 	movq	%dr1, %rax
 	ret
-END(amd64_rdr1)
+END(rdr1)
 
-ENTRY(amd64_ldr2)
+ENTRY(ldr2)
 	movq	%rdi, %dr2
 	ret
-END(amd64_ldr2)
+END(ldr2)
 
-ENTRY(amd64_rdr2)
+ENTRY(rdr2)
 	movq	%dr2, %rax
 	ret
-END(amd64_rdr2)
+END(rdr2)
 
-ENTRY(amd64_ldr3)
+ENTRY(ldr3)
 	movq	%rdi, %dr3
 	ret
-END(amd64_ldr3)
+END(ldr3)
 
-ENTRY(amd64_rdr3)
+ENTRY(rdr3)
 	movq	%dr3, %rax
 	ret
-END(amd64_rdr3)
+END(rdr3)
 
-ENTRY(amd64_ldr6)
+ENTRY(ldr6)
 	movq	%rdi, %dr6
 	ret
-END(amd64_ldr6)

CVS commit: src/sys/arch

2018-12-26 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Dec 26 11:12:57 UTC 2018

Modified Files:
src/sys/arch/amd64/amd64: spl.S
src/sys/arch/i386/i386: spl.S
src/sys/arch/xen/x86: xen_intr.c

Log Message:
Xen can use the native splraise(9) functions.

There is no need for a slower C version.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/amd64/amd64/spl.S
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/i386/i386/spl.S
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/xen/x86/xen_intr.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/spl.S
diff -u src/sys/arch/amd64/amd64/spl.S:1.37 src/sys/arch/amd64/amd64/spl.S:1.38
--- src/sys/arch/amd64/amd64/spl.S:1.37	Tue Dec 25 06:50:11 2018
+++ src/sys/arch/amd64/amd64/spl.S	Wed Dec 26 11:12:57 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: spl.S,v 1.37 2018/12/25 06:50:11 cherry Exp $	*/
+/*	$NetBSD: spl.S,v 1.38 2018/12/26 11:12:57 cherry Exp $	*/
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -78,6 +78,17 @@
 
 	.text
 
+/*
+ * int splraise(int s);
+ */
+ENTRY(splraise)
+	movl	CPUVAR(ILEVEL),%eax
+	cmpl	%edi,%eax
+	cmoval	%eax,%edi
+	movl	%edi,CPUVAR(ILEVEL)
+	ret
+END(splraise)
+
 #ifndef XEN
 /*
  * Xsoftintr()
@@ -202,17 +213,6 @@ IDTVEC(resume_preempt)
 IDTVEC_END(resume_preempt)
 
 /*
- * int splraise(int s);
- */
-ENTRY(splraise)
-	movl	CPUVAR(ILEVEL),%eax
-	cmpl	%edi,%eax
-	cmoval	%eax,%edi
-	movl	%edi,CPUVAR(ILEVEL)
-	ret
-END(splraise)
-
-/*
  * void spllower(int s);
  *
  * Must be the same size as cx8_spllower().  This must use

Index: src/sys/arch/i386/i386/spl.S
diff -u src/sys/arch/i386/i386/spl.S:1.45 src/sys/arch/i386/i386/spl.S:1.46
--- src/sys/arch/i386/i386/spl.S:1.45	Tue Dec 25 09:00:26 2018
+++ src/sys/arch/i386/i386/spl.S	Wed Dec 26 11:12:57 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: spl.S,v 1.45 2018/12/25 09:00:26 cherry Exp $	*/
+/*	$NetBSD: spl.S,v 1.46 2018/12/26 11:12:57 cherry Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spl.S,v 1.45 2018/12/25 09:00:26 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spl.S,v 1.46 2018/12/26 11:12:57 cherry Exp $");
 
 #include "opt_ddb.h"
 #include "opt_spldebug.h"
@@ -44,7 +44,6 @@ __KERNEL_RCSID(0, "$NetBSD: spl.S,v 1.45
 
 	.text
 
-#ifndef XEN
 /*
  * int splraise(int s);
  */
@@ -68,6 +67,8 @@ ENTRY(splraise)
 	ret
 END(splraise)
 
+#ifndef XEN
+
 /*
  * void spllower(int s);
  *

Index: src/sys/arch/xen/x86/xen_intr.c
diff -u src/sys/arch/xen/x86/xen_intr.c:1.12 src/sys/arch/xen/x86/xen_intr.c:1.13
--- src/sys/arch/xen/x86/xen_intr.c:1.12	Tue Dec 25 09:00:26 2018
+++ src/sys/arch/xen/x86/xen_intr.c	Wed Dec 26 11:12:57 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_intr.c,v 1.12 2018/12/25 09:00:26 cherry Exp $	*/
+/*	$NetBSD: xen_intr.c,v 1.13 2018/12/26 11:12:57 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.12 2018/12/25 09:00:26 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.13 2018/12/26 11:12:57 cherry Exp $");
 
 #include 
 #include 
@@ -72,22 +72,6 @@ u_long xen_read_psl(void);
 void xen_write_psl(u_long);
 
 /*
- * Add a mask to cpl, and return the old value of cpl.
- */
-int
-splraise(int nlevel)
-{
-	int olevel;
-	struct cpu_info *ci = curcpu();
-
-	olevel = ci->ci_ilevel;
-	if (nlevel > olevel)
-		ci->ci_ilevel = nlevel;
-	__insn_barrier();
-	return (olevel);
-}
-
-/*
  * Restore a value to cpl (unmasking interrupts).  If any unmasked
  * interrupts are pending, call Xspllower() to process them.
  */



CVS commit: src/sys/arch/i386/i386

2018-12-25 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Dec 26 06:37:31 UTC 2018

Modified Files:
src/sys/arch/i386/i386: locore.S

Log Message:
Missed a file during previous commit completing transition to
separate handler queues for i386.

This should fix the build (hopefully!)

Thanks to Robert Elz for pointing it out.


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/sys/arch/i386/i386/locore.S

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/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.161 src/sys/arch/i386/i386/locore.S:1.162
--- src/sys/arch/i386/i386/locore.S:1.161	Wed Aug  1 13:35:01 2018
+++ src/sys/arch/i386/i386/locore.S	Wed Dec 26 06:37:31 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.161 2018/08/01 13:35:01 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.162 2018/12/26 06:37:31 cherry Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.161 2018/08/01 13:35:01 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.162 2018/12/26 06:37:31 cherry Exp $");
 
 #include "opt_copy_symtab.h"
 #include "opt_ddb.h"
@@ -1288,12 +1288,12 @@ IDTVEC(syscall)
 	movl	$.Lsyscall_resume, %esi /* address to resume loop at */
 .Lsyscall_resume:
 	movl	%ebx,%eax		/* get cpl */
-	movl	CPUVAR(IUNMASK)(,%eax,4),%eax
-	andl	CPUVAR(IPENDING),%eax	/* any non-masked bits left? */
+	movl	CPUVAR(XUNMASK)(,%eax,4),%eax
+	andl	CPUVAR(XPENDING),%eax	/* any non-masked bits left? */
 	jz	17f
 	bsrl	%eax,%eax
-	btrl	%eax,CPUVAR(IPENDING)
-	movl	CPUVAR(ISOURCES)(,%eax,4),%eax
+	btrl	%eax,CPUVAR(XPENDING)
+	movl	CPUVAR(XSOURCES)(,%eax,4),%eax
 	jmp	*IS_RESUME(%eax)
 17:	movl	%ebx, CPUVAR(ILEVEL)	/* restore cpl  */
 	jmp	.Lsyscall_checkast



CVS commit: src/sys/arch

2018-12-25 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Tue Dec 25 09:00:26 UTC 2018

Modified Files:
src/sys/arch/i386/i386: i386_trap.S spl.S
src/sys/arch/xen/x86: xen_intr.c

Log Message:
fix i386 build - missed sources migration in previous commit.

allow xen_intr.c to build by bringing in static support functions for
-D INTRSTACKSIZE

This should fix the i386 build now.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/i386/i386/i386_trap.S
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/i386/i386/spl.S
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/xen/x86/xen_intr.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/i386/i386/i386_trap.S
diff -u src/sys/arch/i386/i386/i386_trap.S:1.15 src/sys/arch/i386/i386/i386_trap.S:1.16
--- src/sys/arch/i386/i386/i386_trap.S:1.15	Sat Jul 14 14:29:40 2018
+++ src/sys/arch/i386/i386/i386_trap.S	Tue Dec 25 09:00:26 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: i386_trap.S,v 1.15 2018/07/14 14:29:40 maxv Exp $	*/
+/*	$NetBSD: i386_trap.S,v 1.16 2018/12/25 09:00:26 cherry Exp $	*/
 
 /*
  * Copyright 2002 (c) Wasabi Systems, Inc.
@@ -66,7 +66,7 @@
 
 #if 0
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i386_trap.S,v 1.15 2018/07/14 14:29:40 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i386_trap.S,v 1.16 2018/12/25 09:00:26 cherry Exp $");
 #endif
 
 /*
@@ -447,12 +447,12 @@ _C_LABEL(trapreturn):	.globl	trapreturn
 	movl	$.Lalltraps_resume,%esi /* address to resume loop at */
 .Lalltraps_resume:
 	movl	%ebx,%eax		/* get cpl */
-	movl	CPUVAR(IUNMASK)(,%eax,4),%eax
-	andl	CPUVAR(IPENDING),%eax	/* any non-masked bits left? */
+	movl	CPUVAR(XUNMASK)(,%eax,4),%eax
+	andl	CPUVAR(XPENDING),%eax	/* any non-masked bits left? */
 	jz	7f
 	bsrl	%eax,%eax
-	btrl	%eax,CPUVAR(IPENDING)
-	movl	CPUVAR(ISOURCES)(,%eax,4),%eax
+	btrl	%eax,CPUVAR(XPENDING)
+	movl	CPUVAR(XSOURCES)(,%eax,4),%eax
 	jmp	*IS_RESUME(%eax)
 7:	movl	%ebx,CPUVAR(ILEVEL)	/* restore cpl */
 	jmp	_C_LABEL(trapreturn)

Index: src/sys/arch/i386/i386/spl.S
diff -u src/sys/arch/i386/i386/spl.S:1.44 src/sys/arch/i386/i386/spl.S:1.45
--- src/sys/arch/i386/i386/spl.S:1.44	Tue Dec 25 06:50:11 2018
+++ src/sys/arch/i386/i386/spl.S	Tue Dec 25 09:00:26 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: spl.S,v 1.44 2018/12/25 06:50:11 cherry Exp $	*/
+/*	$NetBSD: spl.S,v 1.45 2018/12/25 09:00:26 cherry Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spl.S,v 1.44 2018/12/25 06:50:11 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spl.S,v 1.45 2018/12/25 09:00:26 cherry Exp $");
 
 #include "opt_ddb.h"
 #include "opt_spldebug.h"
@@ -290,12 +290,12 @@ IDTVEC(doreti)
 2:	/* Check for ASTs on exit to user mode. */
 #if	defined(XEN)
 	movl	%ebx,%eax
-	movl	CPUVAR(IUNMASK)(,%eax,4),%eax
-	andl	CPUVAR(IPENDING),%eax
+	movl	CPUVAR(XUNMASK)(,%eax,4),%eax
+	andl	CPUVAR(XPENDING),%eax
 	jz	3f
 	bsrl	%eax,%eax		/* slow, but not worth optimizing */
-	btrl	%eax,CPUVAR(IPENDING)
-	movl	CPUVAR(ISOURCES)(,%eax, 4),%eax
+	btrl	%eax,CPUVAR(XPENDING)
+	movl	CPUVAR(XSOURCES)(,%eax, 4),%eax
 	jmp	*IS_RESUME(%eax)
 #endif
 3:

Index: src/sys/arch/xen/x86/xen_intr.c
diff -u src/sys/arch/xen/x86/xen_intr.c:1.11 src/sys/arch/xen/x86/xen_intr.c:1.12
--- src/sys/arch/xen/x86/xen_intr.c:1.11	Tue Dec 25 06:50:12 2018
+++ src/sys/arch/xen/x86/xen_intr.c	Tue Dec 25 09:00:26 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_intr.c,v 1.11 2018/12/25 06:50:12 cherry Exp $	*/
+/*	$NetBSD: xen_intr.c,v 1.12 2018/12/25 09:00:26 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.11 2018/12/25 06:50:12 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.12 2018/12/25 09:00:26 cherry Exp $");
 
 #include 
 #include 
@@ -40,6 +40,8 @@ __KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v
 
 #include 
 
+#include 
+
 #include 
 #include 
 
@@ -302,6 +304,24 @@ xen_cpu_intr_redistribute(void)
 }
 
 /* MD - called by x86/cpu.c */
+#if defined(INTRSTACKSIZE)
+static inline bool
+redzone_const_or_false(bool x)
+{
+#ifdef DIAGNOSTIC
+	return x;
+#else
+	return false;
+#endif /* !DIAGNOSTIC */
+}
+
+static inline int
+redzone_const_or_zero(int x)
+{
+	return redzone_const_or_false(true) ? x : 0;
+}
+#endif
+
 void
 cpu_intr_init(struct cpu_info *ci)
 {



CVS commit: src/sys/arch

2018-12-24 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Tue Dec 25 06:50:12 UTC 2018

Modified Files:
src/sys/arch/amd64/amd64: genassym.cf lock_stubs.S spl.S vector.S
src/sys/arch/i386/i386: genassym.cf spl.S vector.S
src/sys/arch/x86/include: cpu.h
src/sys/arch/x86/isa: isa_machdep.c
src/sys/arch/x86/x86: i8259.c intr.c
src/sys/arch/xen/conf: files.xen
src/sys/arch/xen/include: intr.h
src/sys/arch/xen/x86: hypervisor_machdep.c xen_intr.c
src/sys/arch/xen/xen: clock.c evtchn.c xenevt.c

Log Message:
Excise XEN specific code out of x86/x86/intr.c into xen/x86/xen_intr.c

While at it, separate the source function tracking so that the interrupt
paths are truly independant.

Use weak symbol exporting to provision for future PVHVM co-existence
of both files, but with independant paths. Introduce assembler code
such that in a unified scenario, native interrupts get first priority
in spllower(), followed by XEN event callbacks. IPL management and
semantics are unchanged - native handlers and xen callbacks are
expected to maintain their ipl related semantics.

In summary, after this commit, native and XEN now have completely
unrelated interrupt handling mechanisms, including
intr_establish_xname() and assembler stubs and intr handler
management.

Happy Christmas!


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/sys/arch/amd64/amd64/genassym.cf
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/amd64/amd64/lock_stubs.S
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/amd64/amd64/spl.S
cvs rdiff -u -r1.64 -r1.65 src/sys/arch/amd64/amd64/vector.S
cvs rdiff -u -r1.107 -r1.108 src/sys/arch/i386/i386/genassym.cf
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/i386/i386/spl.S
cvs rdiff -u -r1.78 -r1.79 src/sys/arch/i386/i386/vector.S
cvs rdiff -u -r1.100 -r1.101 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/x86/isa/isa_machdep.c
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/x86/x86/i8259.c
cvs rdiff -u -r1.140 -r1.141 src/sys/arch/x86/x86/intr.c
cvs rdiff -u -r1.173 -r1.174 src/sys/arch/xen/conf/files.xen
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/xen/x86/hypervisor_machdep.c
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/xen/x86/xen_intr.c
cvs rdiff -u -r1.75 -r1.76 src/sys/arch/xen/xen/clock.c
cvs rdiff -u -r1.82 -r1.83 src/sys/arch/xen/xen/evtchn.c
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/xen/xen/xenevt.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/genassym.cf
diff -u src/sys/arch/amd64/amd64/genassym.cf:1.70 src/sys/arch/amd64/amd64/genassym.cf:1.71
--- src/sys/arch/amd64/amd64/genassym.cf:1.70	Sun Aug 12 15:31:01 2018
+++ src/sys/arch/amd64/amd64/genassym.cf	Tue Dec 25 06:50:11 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: genassym.cf,v 1.70 2018/08/12 15:31:01 maxv Exp $
+#	$NetBSD: genassym.cf,v 1.71 2018/12/25 06:50:11 cherry Exp $
 
 #
 # Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -248,12 +248,14 @@ define	CPU_INFO_CURPRIORITY	offsetof(str
 define	CPU_INFO_FPCURLWP	offsetof(struct cpu_info, ci_fpcurlwp)
 
 define	CPU_INFO_GDT		offsetof(struct cpu_info, ci_gdt)
+define	CPU_INFO_ILEVEL		offsetof(struct cpu_info, ci_ilevel)
+define	CPU_INFO_IDEPTH		offsetof(struct cpu_info, ci_idepth)
+if !defined(XEN)
 define	CPU_INFO_IPENDING	offsetof(struct cpu_info, ci_ipending)
 define	CPU_INFO_IMASK		offsetof(struct cpu_info, ci_imask)
 define	CPU_INFO_IUNMASK	offsetof(struct cpu_info, ci_iunmask)
-define	CPU_INFO_ILEVEL		offsetof(struct cpu_info, ci_ilevel)
-define	CPU_INFO_IDEPTH		offsetof(struct cpu_info, ci_idepth)
 define	CPU_INFO_ISOURCES	offsetof(struct cpu_info, ci_isources)
+endif
 define	CPU_INFO_MTX_COUNT	offsetof(struct cpu_info, ci_mtx_count)
 define	CPU_INFO_MTX_OLDSPL	offsetof(struct cpu_info, ci_mtx_oldspl)
 define  CPU_INFO_CPUID		offsetof(struct cpu_info, ci_cpuid)
@@ -352,6 +354,10 @@ define	BST_TYPE		offsetof(struct bus_spa
 
 ifdef XEN
 define CPU_INFO_VCPU		offsetof(struct cpu_info, ci_vcpu)
+define CPU_INFO_XPENDING	offsetof(struct cpu_info, ci_xpending)
+define CPU_INFO_XMASK		offsetof(struct cpu_info, ci_xmask)
+define CPU_INFO_XUNMASK		offsetof(struct cpu_info, ci_xunmask)
+define CPU_INFO_XSOURCES	offsetof(struct cpu_info, ci_xsources)
 define EVTCHN_UPCALL_MASK	offsetof(struct vcpu_info, evtchn_upcall_mask)
 define XEN_PT_BASE		offsetof(struct start_info, pt_base)
 define XEN_NR_PT_FRAMES		offsetof(struct start_info, nr_pt_frames)

Index: src/sys/arch/amd64/amd64/lock_stubs.S
diff -u src/sys/arch/amd64/amd64/lock_stubs.S:1.29 src/sys/arch/amd64/amd64/lock_stubs.S:1.30
--- src/sys/arch/amd64/amd64/lock_stubs.S:1.29	Sat Jul 14 14:29:40 2018
+++ src/sys/arch/amd64/amd64/lock_stubs.S	Tue Dec 25 06:50:11 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: lock_stubs.S,v 1.29 2018/07/14 14:29:40 maxv Exp $	*/
+/*	$NetBSD: lock_stubs.S,v 1.30 2018/12/25 

CVS commit: src/sys/arch/x86/x86

2018-12-24 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Dec 24 22:05:45 UTC 2018

Modified Files:
src/sys/arch/x86/x86: intr.c mp.c x86_machdep.c

Log Message:
Towards bifurcating XEN and native interrupt related functions,
this is a preliminary cleanup sweep.

Move functions related to MP bus probe and scanning to x86/mp.c

Move generic platform pic search function to x86/x86_machdep.c


To generate a diff of this commit:
cvs rdiff -u -r1.139 -r1.140 src/sys/arch/x86/x86/intr.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/x86/x86/mp.c
cvs rdiff -u -r1.120 -r1.121 src/sys/arch/x86/x86/x86_machdep.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/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.139 src/sys/arch/x86/x86/intr.c:1.140
--- src/sys/arch/x86/x86/intr.c:1.139	Mon Dec 24 14:55:41 2018
+++ src/sys/arch/x86/x86/intr.c	Mon Dec 24 22:05:45 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.139 2018/12/24 14:55:41 cherry Exp $	*/
+/*	$NetBSD: intr.c,v 1.140 2018/12/24 22:05:45 cherry Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.139 2018/12/24 14:55:41 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.140 2018/12/24 22:05:45 cherry Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -220,13 +220,6 @@ static SIMPLEQ_HEAD(, intrsource) io_int
 
 static kmutex_t intr_distribute_lock;
 
-#if NIOAPIC > 0 || NACPICA > 0
-static int intr_scan_bus(int, int, intr_handle_t *);
-#if NPCI > 0
-static int intr_find_pcibridge(int, pcitag_t *, pci_chipset_tag_t *);
-#endif
-#endif
-
 #if !defined(XEN)
 static int intr_allocate_slot_cpu(struct cpu_info *, struct pic *, int, int *,
   struct intrsource *);
@@ -374,123 +367,6 @@ intr_calculatemasks(struct cpu_info *ci)
 }
 
 /*
- * List to keep track of PCI buses that are probed but not known
- * to the firmware. Used to
- *
- * XXX should maintain one list, not an array and a linked list.
- */
-#if (NPCI > 0) && ((NIOAPIC > 0) || NACPICA > 0)
-struct intr_extra_bus {
-	int bus;
-	pcitag_t *pci_bridge_tag;
-	pci_chipset_tag_t pci_chipset_tag;
-	LIST_ENTRY(intr_extra_bus) list;
-};
-
-LIST_HEAD(, intr_extra_bus) intr_extra_buses =
-LIST_HEAD_INITIALIZER(intr_extra_buses);
-
-
-void
-intr_add_pcibus(struct pcibus_attach_args *pba)
-{
-	struct intr_extra_bus *iebp;
-
-	iebp = kmem_alloc(sizeof(*iebp), KM_SLEEP);
-	iebp->bus = pba->pba_bus;
-	iebp->pci_chipset_tag = pba->pba_pc;
-	iebp->pci_bridge_tag = pba->pba_bridgetag;
-	LIST_INSERT_HEAD(_extra_buses, iebp, list);
-}
-
-static int
-intr_find_pcibridge(int bus, pcitag_t *pci_bridge_tag,
-		pci_chipset_tag_t *pc)
-{
-	struct intr_extra_bus *iebp;
-	struct mp_bus *mpb;
-
-	if (bus < 0)
-		return ENOENT;
-
-	if (bus < mp_nbus) {
-		mpb = _busses[bus];
-		if (mpb->mb_pci_bridge_tag == NULL)
-			return ENOENT;
-		*pci_bridge_tag = *mpb->mb_pci_bridge_tag;
-		*pc = mpb->mb_pci_chipset_tag;
-		return 0;
-	}
-
-	LIST_FOREACH(iebp, _extra_buses, list) {
-		if (iebp->bus == bus) {
-			if (iebp->pci_bridge_tag == NULL)
-return ENOENT;
-			*pci_bridge_tag = *iebp->pci_bridge_tag;
-			*pc = iebp->pci_chipset_tag;
-			return 0;
-		}
-	}
-	return ENOENT;
-}
-#endif
-
-#if NIOAPIC > 0 || NACPICA > 0
-/*
- * 'pin' argument pci bus_pin encoding of a device/pin combination.
- */
-int
-intr_find_mpmapping(int bus, int pin, intr_handle_t *handle)
-{
-
-#if NPCI > 0
-	while (intr_scan_bus(bus, pin, handle) != 0) {
-		int dev, func;
-		pcitag_t pci_bridge_tag;
-		pci_chipset_tag_t pc;
-
-		if (intr_find_pcibridge(bus, _bridge_tag, ) != 0)
-			return ENOENT;
-		dev = pin >> 2;
-		pin = pin & 3;
-		pin = PPB_INTERRUPT_SWIZZLE(pin + 1, dev) - 1;
-		pci_decompose_tag(pc, pci_bridge_tag, , , );
-		pin |= (dev << 2);
-	}
-	return 0;
-#else
-	return intr_scan_bus(bus, pin, handle);
-#endif
-}
-
-static int
-intr_scan_bus(int bus, int pin, intr_handle_t *handle)
-{
-	struct mp_intr_map *mip, *intrs;
-
-	if (bus < 0 || bus >= mp_nbus)
-		return ENOENT;
-
-	intrs = mp_busses[bus].mb_intrs;
-	if (intrs == NULL)
-		return ENOENT;
-
-	for (mip = intrs; mip != NULL; mip = mip->next) {
-		if (mip->bus_pin == pin) {
-#if NACPICA > 0
-			if (mip->linkdev != NULL)
-if (mpacpi_findintr_linkdev(mip) != 0)
-	continue;
-#endif
-			*handle = mip->ioapic_ih;
-			return 0;
-		}
-	}
-	return ENOENT;
-}
-#endif
-
-/*
  * Create an interrupt id such as "ioapic0 pin 9". This interrupt id is used
  * by MI code and intrctl(8).
  */
@@ -852,23 +728,6 @@ intr_biglock_wrapper(void *vp)
 #endif /* MULTIPROCESSOR */
 #endif /* XEN */
 
-#if defined(DOM0OPS) || !defined(XEN)
-struct pic *
-intr_findpic(int num)
-{
-#if NIOAPIC > 0
-	struct ioapic_softc *pic;
-
-	pic = ioapic_find_bybase(num);
-	if (pic != NULL)
-		return >sc_pic;
-#endif
-	if (num < NUM_LEGACY_IRQS)
-		return _pic;
-
-	return NULL;
-}
-#endif
 
 

CVS commit: src/sys/arch/xen/conf

2018-12-24 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Dec 24 21:15:59 UTC 2018

Modified Files:
src/sys/arch/xen/conf: files.xen

Log Message:
Do not include files for MSI support on XEN dom0.

We do not support MSI as of now.


To generate a diff of this commit:
cvs rdiff -u -r1.172 -r1.173 src/sys/arch/xen/conf/files.xen

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/xen/conf/files.xen
diff -u src/sys/arch/xen/conf/files.xen:1.172 src/sys/arch/xen/conf/files.xen:1.173
--- src/sys/arch/xen/conf/files.xen:1.172	Sat Dec 22 07:45:58 2018
+++ src/sys/arch/xen/conf/files.xen	Mon Dec 24 21:15:59 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: files.xen,v 1.172 2018/12/22 07:45:58 cherry Exp $
+#	$NetBSD: files.xen,v 1.173 2018/12/24 21:15:59 cherry Exp $
 #	NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp 
 #	NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp 
 
@@ -381,8 +381,6 @@ file	arch/xen/xen/privcmd.c		dom0ops
 file 	arch/xen/x86/xen_shm_machdep.c	dom0ops
 file	arch/x86/pci/pci_machdep.c	hypervisor & pci & dom0ops
 file	arch/x86/pci/pci_intr_machdep.c	hypervisor & pci
-file	arch/x86/pci/pci_msi_machdep.c	hypervisor & pci
-file	arch/x86/pci/msipic.c		hypervisor & pci
 file	arch/x86/isa/isa_machdep.c	hypervisor & dom0ops
 file	arch/xen/xen/xenevt.c		xenevt & dom0ops
 file	arch/xen/xen/xennetback_xenbus.c xvif



CVS commit: src/sys/arch

2018-12-24 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Dec 24 14:55:42 UTC 2018

Modified Files:
src/sys/arch/x86/x86: intr.c
src/sys/arch/xen/include: intr.h
src/sys/arch/xen/x86: xen_intr.c xen_ipi.c
src/sys/arch/xen/xen: clock.c if_xennet_xenbus.c pciback.c xbd_xenbus.c
xbdback_xenbus.c xencons.c xenevt.c xennetback_xenbus.c
xpci_xenbus.c
src/sys/arch/xen/xenbus: xenbus_comms.c

Log Message:
Bifurcate the interrupt establish functions between XEN and non-XEN

Thus intr_establish_xname() becomes xen_intr_establish_xname() etc.

One consequence of this is that dom0 devices expect the native
function calls to be available and we thus provide weak aliasing for
dom0 builds to succeed. XEN and non-XEN devices are distinguished by
the PIC they are established on. XEN interrupts are exclusively
established on xen_pic, while dom0 interrupts are established on
natively available PICs.

This allows us an orthogonal path to xen device management (eg:
xenstore events) in XENPVHVM, without having to worry about unifying
the vector entry paths, etc., which is quite challenging.


To generate a diff of this commit:
cvs rdiff -u -r1.138 -r1.139 src/sys/arch/x86/x86/intr.c
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/xen/x86/xen_intr.c
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/xen/x86/xen_ipi.c
cvs rdiff -u -r1.74 -r1.75 src/sys/arch/xen/xen/clock.c
cvs rdiff -u -r1.81 -r1.82 src/sys/arch/xen/xen/if_xennet_xenbus.c
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/xen/xen/pciback.c
cvs rdiff -u -r1.90 -r1.91 src/sys/arch/xen/xen/xbd_xenbus.c
cvs rdiff -u -r1.69 -r1.70 src/sys/arch/xen/xen/xbdback_xenbus.c
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/xen/xen/xencons.c
cvs rdiff -u -r1.51 -r1.52 src/sys/arch/xen/xen/xenevt.c
cvs rdiff -u -r1.72 -r1.73 src/sys/arch/xen/xen/xennetback_xenbus.c
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/xen/xen/xpci_xenbus.c
cvs rdiff -u -r1.20 -r1.21 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/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.138 src/sys/arch/x86/x86/intr.c:1.139
--- src/sys/arch/x86/x86/intr.c:1.138	Sun Dec 23 12:11:40 2018
+++ src/sys/arch/x86/x86/intr.c	Mon Dec 24 14:55:41 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.138 2018/12/23 12:11:40 jdolecek Exp $	*/
+/*	$NetBSD: intr.c,v 1.139 2018/12/24 14:55:41 cherry Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.138 2018/12/23 12:11:40 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.139 2018/12/24 14:55:41 cherry Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -1207,117 +1207,12 @@ intr_num_handlers(struct intrsource *isp
 	return num;
 }
 
-#else /* XEN */
-void *
-intr_establish(int legacy_irq, struct pic *pic, int pin,
-int type, int level, int (*handler)(void *), void *arg,
-bool known_mpsafe)
-{
-
-	return intr_establish_xname(legacy_irq, pic, pin, type, level,
-	handler, arg, known_mpsafe, "XEN");
-}
-
-void *
-intr_establish_xname(int legacy_irq, struct pic *pic, int pin,
-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;
-
-		/*
-		 * event_set_handler interprets `level != IPL_VM' to
-		 * mean MP-safe, so we require the caller to match that
-		 * for the moment.
-		 */
-		KASSERT(known_mpsafe == (level != IPL_VM));
-
-		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) {
-			printf("%s: can't allocate handler info\n", __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 */
-
-#if NPCI > 0 || NISA > 0
-	struct pintrhand *pih;
-	int gsi;
-	int vector, evtchn;
-
-	KASSERTMSG(legacy_irq == -1 || (0 <= legacy_irq && legacy_irq < NUM_XEN_IRQS),
-	"bad legacy IRQ value: %d", legacy_irq);
-	KASSERTMSG(!(legacy_irq == -1 && pic == _pic),
-	"non-legacy IRQon i8259 ");
-
-	gsi = xen_pic_to_gsi(pic, pin);
-
-	intrstr = intr_create_intrid(gsi, pic, pin, intrstr_buf,
-	

CVS commit: src/sys/arch

2018-12-22 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Dec 22 21:27:22 UTC 2018

Modified Files:
src/sys/arch/amd64/amd64: cpufunc.S
src/sys/arch/i386/i386: cpufunc.S i386func.S
src/sys/arch/xen/x86: xenfunc.c

Log Message:
Introduce a weak alias method of exporting different implementations
of the same API.

For eg: the amd64 native implementation of invlpg() now becomes
amd64_invlpg() with a weak symbol export of invlpg(), while the XEN
implementation becomes xen_invlpg(), also weakly exported as invlpg()

Note that linking in both together without having an override function
named invlpg() would be a mistake, as we have limited control over
which of the two options would emerge as the finally exported invlpg()
resulting in a potential situation where the wrong function is finally
exported. This change avoids this situation.

We should however include an override function invlpg() in that case,
such that it is able to then pass on the call to the appropriate
backing function (amd64_invlpg() in the case of native, and
xen_invlpg() in the case of under XEN virtualisation) at runtime.

This change does not introduce such a function and therefore does not
alter builds to include native as well as XEN implementations in the
same binary. This will be done later, with the introduction of XEN
PVHVM mode, where precisely such a runtime switch is required.

There are no operational changes introduced by this change.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/amd64/amd64/cpufunc.S
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/i386/i386/cpufunc.S
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/i386/i386/i386func.S
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/xen/x86/xenfunc.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/cpufunc.S
diff -u src/sys/arch/amd64/amd64/cpufunc.S:1.33 src/sys/arch/amd64/amd64/cpufunc.S:1.34
--- src/sys/arch/amd64/amd64/cpufunc.S:1.33	Sat Jul 21 06:09:13 2018
+++ src/sys/arch/amd64/amd64/cpufunc.S	Sat Dec 22 21:27:22 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.S,v 1.33 2018/07/21 06:09:13 maxv Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.34 2018/12/22 21:27:22 cherry Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -63,18 +63,53 @@ ENTRY(x86_mfence)
 	ret
 END(x86_mfence)
 
+/*
+ * These functions below should always be accessed via the corresponding wrapper
+ * function names defined in x86/include/cpufunc.h and exported as WEAK_ALIAS()
+ *
+ * We use this rather roundabout method so that a runtime wrapper function may
+ * be made available for PVHVM, which could override both native and PV aliases
+ * and decide which to invoke at run time.
+ */
+
+WEAK_ALIAS(invlpg, amd64_invlpg)
+WEAK_ALIAS(lidt, amd64_lidt)
+WEAK_ALIAS(lldt, amd64_lldt)
+WEAK_ALIAS(ltr, amd64_ltr)
+WEAK_ALIAS(lcr0, amd64_lcr0)
+WEAK_ALIAS(rcr0, amd64_rcr0)
+WEAK_ALIAS(rcr2, amd64_rcr2)
+WEAK_ALIAS(lcr2, amd64_lcr2)
+WEAK_ALIAS(rcr3, amd64_rcr3)
+WEAK_ALIAS(lcr3, amd64_lcr3)
+WEAK_ALIAS(tlbflush, amd64_tlbflush)
+WEAK_ALIAS(tlbflushg, amd64_tlbflushg)
+WEAK_ALIAS(rdr0, amd64_rdr0)
+WEAK_ALIAS(ldr0, amd64_ldr0)
+WEAK_ALIAS(rdr1, amd64_rdr1)
+WEAK_ALIAS(ldr1, amd64_ldr1)
+WEAK_ALIAS(rdr2, amd64_rdr2)
+WEAK_ALIAS(ldr2, amd64_ldr2)
+WEAK_ALIAS(rdr3, amd64_rdr3)
+WEAK_ALIAS(ldr3, amd64_ldr3)
+WEAK_ALIAS(rdr6, amd64_rdr6)
+WEAK_ALIAS(ldr6, amd64_ldr6)
+WEAK_ALIAS(rdr7, amd64_rdr7)
+WEAK_ALIAS(ldr7, amd64_ldr7)
+WEAK_ALIAS(wbinvd, amd64_wbinvd)
+
 #ifndef XEN
-ENTRY(invlpg)
+ENTRY(amd64_invlpg)
 	invlpg	(%rdi)
 	ret
-END(invlpg)
+END(amd64_invlpg)
 
-ENTRY(lidt)
+ENTRY(amd64_lidt)
 	lidt	(%rdi)
 	ret
-END(lidt)
+END(amd64_lidt)
 
-ENTRY(lldt)
+ENTRY(amd64_lldt)
 	cmpl	%edi, CPUVAR(CURLDT)
 	jne	1f
 	ret
@@ -82,42 +117,42 @@ ENTRY(lldt)
 	movl	%edi, CPUVAR(CURLDT)
 	lldt	%di
 	ret
-END(lldt)
+END(amd64_lldt)
 
-ENTRY(ltr)
+ENTRY(amd64_ltr)
 	ltr	%di
 	ret
-END(ltr)
+END(amd64_ltr)
 
-ENTRY(lcr0)
+ENTRY(amd64_lcr0)
 	movq	%rdi, %cr0
 	ret
-END(lcr0)
+END(amd64_lcr0)
 
-ENTRY(rcr0)
+ENTRY(amd64_rcr0)
 	movq	%cr0, %rax
 	ret
-END(rcr0)
+END(amd64_rcr0)
 
-ENTRY(lcr2)
+ENTRY(amd64_lcr2)
 	movq	%rdi, %cr2
 	ret
-END(lcr2)
+END(amd64_lcr2)
 
-ENTRY(rcr2)
+ENTRY(amd64_rcr2)
 	movq	%cr2, %rax
 	ret
-END(rcr2)
+END(amd64_rcr2)
 
-ENTRY(lcr3)
+ENTRY(amd64_lcr3)
 	movq	%rdi, %cr3
 	ret
-END(lcr3)
+END(amd64_lcr3)
 
-ENTRY(rcr3)
+ENTRY(amd64_rcr3)
 	movq	%cr3, %rax
 	ret
-END(rcr3)
+END(amd64_rcr3)
 #endif
 
 ENTRY(lcr4)
@@ -159,7 +194,7 @@ END(rcr8)
  * If PGE is not in use, we reload CR3.
  */
 #ifndef XEN
-ENTRY(tlbflushg)
+ENTRY(amd64_tlbflushg)
 	movq	%cr4, %rax
 	testq	$CR4_PGE, %rax
 	jz	1f
@@ -168,74 +203,74 @@ ENTRY(tlbflushg)
 	movq	%rdx, %cr4
 	movq	%rax, %cr4
 	ret
-END(tlbflushg)
+END(amd64_tlbflushg)
 
-ENTRY(tlbflush)
+ENTRY(amd64_tlbflush)
 1:
 	movq	%cr3, %rax
 	movq	%rax, %cr3
 	ret
-END(tlbflush)
+END(amd64_tlbflush)
 
-ENTRY(ldr0)

CVS commit: src/sys/arch

2018-12-21 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Dec 22 07:45:59 UTC 2018

Modified Files:
src/sys/arch/amd64/amd64: amd64_mainbus.c
src/sys/arch/amd64/conf: XEN3_DOM0 files.amd64
src/sys/arch/i386/conf: XEN3PAE_DOM0 files.i386
src/sys/arch/i386/i386: i386_mainbus.c
src/sys/arch/x86/include: autoconf.h
src/sys/arch/xen/conf: files.xen
src/sys/arch/xen/x86: autoconf.c xen_mainbus.c
Added Files:
src/sys/arch/x86/x86: mainbus.c

Log Message:
This change modifies the mainbus(4) entry point for all x86 sub-archs
in the following way:

i) It provides a unified entry point in
   x86/x86/mainbus.c:mainbus_attach()
ii) It carves out the preliminary bus attachment sequence that is
   common to all sub-archs into
   x86/x86/mainbus.c: x86_cpubus_attach()
iii) It consolidates the remaining pathways as internal callee
   functions so that these may be called piecemeal if required. A
   special usecase of this is XEN PVHVM which may need to call the
   native configure path, the xen configure path, or both.
iv) It moves the driver private data structures from
   i386/i386_mainbus.c to an x86/ level one. This allows for other
   sub-arch's to do similar, if needed. (They do not at the moment).
v) For dom0 kernels, it enables 'acpi0 at mainbus?' and
   'acpi0 at hypervisorbus'. This serves two purposes:
   a) To demonstrate the possibility of dynamic configuration tree
  traversal ordering changes.
   b) To allow for the common acpi_check(self, "acpibus") call in
   x86/mainbus.c to not barf when it is called from the dom0 attach
   path. We allow for the acpi0 device to be a child of mainbus with
   the changes to amd64/conf/XEN3_DOM0 and i386/conf/XEN3PAE_DOM0
   without actually probing further in the code. This path will later
   be pursued in a PVHVM boot codepath.

There should be no operative changes with this change. If there are,
please complain loudly.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/amd64/amd64/amd64_mainbus.c
cvs rdiff -u -r1.160 -r1.161 src/sys/arch/amd64/conf/XEN3_DOM0
cvs rdiff -u -r1.109 -r1.110 src/sys/arch/amd64/conf/files.amd64
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/i386/conf/XEN3PAE_DOM0
cvs rdiff -u -r1.398 -r1.399 src/sys/arch/i386/conf/files.i386
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/i386/i386/i386_mainbus.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/x86/include/autoconf.h
cvs rdiff -u -r0 -r1.1 src/sys/arch/x86/x86/mainbus.c
cvs rdiff -u -r1.171 -r1.172 src/sys/arch/xen/conf/files.xen
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/xen/x86/autoconf.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/xen/x86/xen_mainbus.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/amd64_mainbus.c
diff -u src/sys/arch/amd64/amd64/amd64_mainbus.c:1.2 src/sys/arch/amd64/amd64/amd64_mainbus.c:1.3
--- src/sys/arch/amd64/amd64/amd64_mainbus.c:1.2	Sat Dec 22 06:59:27 2018
+++ src/sys/arch/amd64/amd64/amd64_mainbus.c	Sat Dec 22 07:45:58 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: amd64_mainbus.c,v 1.2 2018/12/22 06:59:27 cherry Exp $	*/
+/*	$NetBSD: amd64_mainbus.c,v 1.3 2018/12/22 07:45:58 cherry Exp $	*/
 /*	NetBSD: mainbus.c,v 1.39 2018/12/02 08:19:44 cherry Exp 	*/
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: amd64_mainbus.c,v 1.2 2018/12/22 06:59:27 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amd64_mainbus.c,v 1.3 2018/12/22 07:45:58 cherry Exp $");
 
 #include 
 #include 
@@ -83,15 +83,11 @@ __KERNEL_RCSID(0, "$NetBSD: amd64_mainbu
  * XXXfvdl ACPI
  */
 
-int	mainbus_match(device_t, cfdata_t, void *);
-void	mainbus_attach(device_t, device_t, void *);
+int	amd64_mainbus_match(device_t, cfdata_t, void *);
+void	amd64_mainbus_attach(device_t, device_t, void *);
+int	amd64_mainbus_print(void *, const char *);
 
-CFATTACH_DECL_NEW(mainbus, 0,
-mainbus_match, mainbus_attach, NULL, NULL);
-
-int	mainbus_print(void *, const char *);
-
-union mainbus_attach_args {
+union amd64_mainbus_attach_args {
 	const char *mba_busname;		/* first elem of all */
 	struct pcibus_attach_args mba_pba;
 	struct isabus_attach_args mba_iba;
@@ -128,8 +124,8 @@ int mp_nintr;
 int mp_isa_bus = -1;
 int mp_eisa_bus = -1;
 
-bool acpi_present;
-bool mpacpi_active;
+extern bool acpi_present;
+extern bool mpacpi_active;
 
 # ifdef MPVERBOSE
 #  if MPVERBOSE > 0
@@ -147,7 +143,7 @@ int mp_verbose = 0;
  * Probe for the mainbus; always succeeds.
  */
 int
-mainbus_match(device_t parent, cfdata_t match, void *aux)
+amd64_mainbus_match(device_t parent, cfdata_t match, void *aux)
 {
 
 	return 1;
@@ -157,82 +153,10 @@ mainbus_match(device_t parent, cfdata_t 
  * Attach the mainbus.
  */
 void
-mainbus_attach(device_t parent, device_t self, void *aux)
+amd64_mainbus_attach(device_t parent, device_t self, void *aux)
 {
 #if NPCI > 0 || NACPICA > 0 || 

CVS commit: src/sys/arch

2018-12-21 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Dec 22 06:59:27 UTC 2018

Modified Files:
src/sys/arch/amd64/amd64: amd64_mainbus.c
src/sys/arch/i386/i386: i386_mainbus.c
src/sys/arch/xen/x86: xen_mainbus.c

Log Message:
Don't forget pedigree. Re-introduce old RCS Id tags from the originals


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/amd64/amd64/amd64_mainbus.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/i386/i386/i386_mainbus.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/xen/x86/xen_mainbus.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/amd64_mainbus.c
diff -u src/sys/arch/amd64/amd64/amd64_mainbus.c:1.1 src/sys/arch/amd64/amd64/amd64_mainbus.c:1.2
--- src/sys/arch/amd64/amd64/amd64_mainbus.c:1.1	Sat Dec 22 06:33:36 2018
+++ src/sys/arch/amd64/amd64/amd64_mainbus.c	Sat Dec 22 06:59:27 2018
@@ -1,5 +1,5 @@
-/*	$NetBSD: amd64_mainbus.c,v 1.1 2018/12/22 06:33:36 cherry Exp $	*/
-
+/*	$NetBSD: amd64_mainbus.c,v 1.2 2018/12/22 06:59:27 cherry Exp $	*/
+/*	NetBSD: mainbus.c,v 1.39 2018/12/02 08:19:44 cherry Exp 	*/
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
  *
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: amd64_mainbus.c,v 1.1 2018/12/22 06:33:36 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amd64_mainbus.c,v 1.2 2018/12/22 06:59:27 cherry Exp $");
 
 #include 
 #include 

Index: src/sys/arch/i386/i386/i386_mainbus.c
diff -u src/sys/arch/i386/i386/i386_mainbus.c:1.1 src/sys/arch/i386/i386/i386_mainbus.c:1.2
--- src/sys/arch/i386/i386/i386_mainbus.c:1.1	Sat Dec 22 06:33:36 2018
+++ src/sys/arch/i386/i386/i386_mainbus.c	Sat Dec 22 06:59:27 2018
@@ -1,4 +1,5 @@
-/*	$NetBSD: i386_mainbus.c,v 1.1 2018/12/22 06:33:36 cherry Exp $	*/
+/*	$NetBSD: i386_mainbus.c,v 1.2 2018/12/22 06:59:27 cherry Exp $	*/
+/*	NetBSD: mainbus.c,v 1.104 2018/12/02 08:19:44 cherry Exp 	*/
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
@@ -31,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i386_mainbus.c,v 1.1 2018/12/22 06:33:36 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i386_mainbus.c,v 1.2 2018/12/22 06:59:27 cherry Exp $");
 
 #include 
 #include 

Index: src/sys/arch/xen/x86/xen_mainbus.c
diff -u src/sys/arch/xen/x86/xen_mainbus.c:1.1 src/sys/arch/xen/x86/xen_mainbus.c:1.2
--- src/sys/arch/xen/x86/xen_mainbus.c:1.1	Sat Dec 22 06:33:37 2018
+++ src/sys/arch/xen/x86/xen_mainbus.c	Sat Dec 22 06:59:27 2018
@@ -1,4 +1,5 @@
-/*	$NetBSD: xen_mainbus.c,v 1.1 2018/12/22 06:33:37 cherry Exp $	*/
+/*	$NetBSD: xen_mainbus.c,v 1.2 2018/12/22 06:59:27 cherry Exp $	*/
+/*	NetBSD: mainbus.c,v 1.19 2017/05/23 08:54:39 nonaka Exp 	*/
 /*	NetBSD: mainbus.c,v 1.53 2003/10/27 14:11:47 junyoung Exp 	*/
 
 /*
@@ -32,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_mainbus.c,v 1.1 2018/12/22 06:33:37 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_mainbus.c,v 1.2 2018/12/22 06:59:27 cherry Exp $");
 
 #include 
 #include 



CVS commit: src/sys/arch

2018-12-21 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Dec 22 06:33:37 UTC 2018

Modified Files:
src/sys/arch/amd64/conf: files.amd64
src/sys/arch/i386/conf: files.i386
src/sys/arch/xen/conf: files.xen
Added Files:
src/sys/arch/amd64/amd64: amd64_mainbus.c
src/sys/arch/i386/i386: i386_mainbus.c
src/sys/arch/xen/x86: xen_mainbus.c
Removed Files:
src/sys/arch/amd64/amd64: mainbus.c
src/sys/arch/i386/i386: mainbus.c
src/sys/arch/xen/x86: mainbus.c

Log Message:
Move mainbus(4) driver files in various x86 sub-archs to name prefixed
versions. This allows us to further modularise them by unifying common
bus probe code in x86/x86/mainbus.c to  be introduced next.

This commit has no functional changes. It is done for ease of
visibility of newer diffs in the queue.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/arch/amd64/amd64/amd64_mainbus.c
cvs rdiff -u -r1.39 -r0 src/sys/arch/amd64/amd64/mainbus.c
cvs rdiff -u -r1.108 -r1.109 src/sys/arch/amd64/conf/files.amd64
cvs rdiff -u -r1.397 -r1.398 src/sys/arch/i386/conf/files.i386
cvs rdiff -u -r0 -r1.1 src/sys/arch/i386/i386/i386_mainbus.c
cvs rdiff -u -r1.104 -r0 src/sys/arch/i386/i386/mainbus.c
cvs rdiff -u -r1.170 -r1.171 src/sys/arch/xen/conf/files.xen
cvs rdiff -u -r1.19 -r0 src/sys/arch/xen/x86/mainbus.c
cvs rdiff -u -r0 -r1.1 src/sys/arch/xen/x86/xen_mainbus.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/conf/files.amd64
diff -u src/sys/arch/amd64/conf/files.amd64:1.108 src/sys/arch/amd64/conf/files.amd64:1.109
--- src/sys/arch/amd64/conf/files.amd64:1.108	Mon Dec  3 00:12:22 2018
+++ src/sys/arch/amd64/conf/files.amd64	Sat Dec 22 06:33:36 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: files.amd64,v 1.108 2018/12/03 00:12:22 christos Exp $
+#	$NetBSD: files.amd64,v 1.109 2018/12/22 06:33:36 cherry Exp $
 #
 # new style config file for amd64 architecture
 #
@@ -94,7 +94,7 @@ include	"dev/i2o/files.i2o"
 # XXX BIOS32 only if something that uses it is configured!
 device	mainbus: isabus, pcibus, bios32, acpibus, cpubus, ioapicbus, ipmibus
 attach	mainbus at root
-file	arch/amd64/amd64/mainbus.c		mainbus
+file	arch/amd64/amd64/amd64_mainbus.c	mainbus
 
 #
 # PCI-only drivers

Index: src/sys/arch/i386/conf/files.i386
diff -u src/sys/arch/i386/conf/files.i386:1.397 src/sys/arch/i386/conf/files.i386:1.398
--- src/sys/arch/i386/conf/files.i386:1.397	Mon Dec  3 00:11:39 2018
+++ src/sys/arch/i386/conf/files.i386	Sat Dec 22 06:33:36 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: files.i386,v 1.397 2018/12/03 00:11:39 christos Exp $
+#	$NetBSD: files.i386,v 1.398 2018/12/22 06:33:36 cherry Exp $
 #
 # new style config file for i386 architecture
 #
@@ -129,7 +129,7 @@ device	mainbus: isabus, eisabus, mcabus,
 	cpubus, ioapicbus, apmbus, pnpbiosbus, ipmibus,
 	bioscall
 attach	mainbus at root
-file	arch/i386/i386/mainbus.c	mainbus
+file	arch/i386/i386/i386_mainbus.c	mainbus
 
 #
 # PCI-only drivers

Index: src/sys/arch/xen/conf/files.xen
diff -u src/sys/arch/xen/conf/files.xen:1.170 src/sys/arch/xen/conf/files.xen:1.171
--- src/sys/arch/xen/conf/files.xen:1.170	Thu Jul 26 15:38:26 2018
+++ src/sys/arch/xen/conf/files.xen	Sat Dec 22 06:33:37 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: files.xen,v 1.170 2018/07/26 15:38:26 maxv Exp $
+#	$NetBSD: files.xen,v 1.171 2018/12/22 06:33:37 cherry Exp $
 #	NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp 
 #	NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp 
 
@@ -173,7 +173,7 @@ define ipmibus {}
 
 device mainbus: cpubus, ioapicbus, hypervisorbus, bios32, ipmibus
 attach	mainbus at root
-file	arch/xen/x86/mainbus.c		mainbus
+file	arch/xen/x86/xen_mainbus.c		mainbus
 
 # Xen hypervisor
 device	hypervisor { [apid = -1]}: isabus, pcibus, sysmon_power, xendevbus, acpibus

Added files:

Index: src/sys/arch/amd64/amd64/amd64_mainbus.c
diff -u /dev/null src/sys/arch/amd64/amd64/amd64_mainbus.c:1.1
--- /dev/null	Sat Dec 22 06:33:37 2018
+++ src/sys/arch/amd64/amd64/amd64_mainbus.c	Sat Dec 22 06:33:36 2018
@@ -0,0 +1,326 @@
+/*	$NetBSD: amd64_mainbus.c,v 1.1 2018/12/22 06:33:36 cherry Exp $	*/
+
+/*
+ * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *must display the following acknowledgement:
+ *  This product includes software developed 

CVS commit: src

2018-12-20 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Dec 20 10:33:42 UTC 2018

Modified Files:
src/share/man/man4: options.4
src/sys/arch/x86/conf: files.x86

Log Message:
Enable 'options NO_PCI_MSI_MSIX' to DTRT in x86 builds.

Document 'options NO_PCI_MSI_MSIX' in options(4).


To generate a diff of this commit:
cvs rdiff -u -r1.495 -r1.496 src/share/man/man4/options.4
cvs rdiff -u -r1.104 -r1.105 src/sys/arch/x86/conf/files.x86

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

Modified files:

Index: src/share/man/man4/options.4
diff -u src/share/man/man4/options.4:1.495 src/share/man/man4/options.4:1.496
--- src/share/man/man4/options.4:1.495	Thu Dec 20 09:17:04 2018
+++ src/share/man/man4/options.4	Thu Dec 20 10:33:41 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: options.4,v 1.495 2018/12/20 09:17:04 cherry Exp $
+.\"	$NetBSD: options.4,v 1.496 2018/12/20 10:33:41 cherry Exp $
 .\"
 .\" Copyright (c) 1996
 .\" 	Perry E. Metzger.  All rights reserved.
@@ -2688,6 +2688,11 @@ bolded
 .El
 .Ss x86-specific Options
 .Bl -ohang
+.It Cd options NO_PCI_MSI_MSIX
+Disable support for MSI/MSIX in the kernel.
+See
+.Xr pci_msi 9
+for details of MSI/MSIX support
 .It Cd options NO_PREEMPTION
 Disables
 .Xr kpreempt 9

Index: src/sys/arch/x86/conf/files.x86
diff -u src/sys/arch/x86/conf/files.x86:1.104 src/sys/arch/x86/conf/files.x86:1.105
--- src/sys/arch/x86/conf/files.x86:1.104	Fri Dec  7 15:47:11 2018
+++ src/sys/arch/x86/conf/files.x86	Thu Dec 20 10:33:41 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: files.x86,v 1.104 2018/12/07 15:47:11 maxv Exp $
+#	$NetBSD: files.x86,v 1.105 2018/12/20 10:33:41 cherry Exp $
 
 # options for MP configuration through the MP spec
 defflag opt_mpbios.h MPBIOS MPDEBUG MPBIOS_SCANPCI
@@ -155,8 +155,8 @@ file	arch/x86/x86/vga_post.c		vga_post
 file	arch/x86/pci/pci_machdep.c	pci
 #file	arch/x86/pci/pci_ranges.c	pci
 file	arch/x86/pci/pci_intr_machdep.c	pci
-file	arch/x86/pci/pci_msi_machdep.c	pci
-file	arch/x86/pci/msipic.c		pci
+file	arch/x86/pci/pci_msi_machdep.c	pci & ! no_pci_msi_msix
+file	arch/x86/pci/msipic.c		pci & ! no_pci_msi_msix
 
 file	arch/x86/pci/pciide_machdep.c	pciide_common
 



CVS commit: src/share/man/man4

2018-12-20 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Dec 20 09:17:04 UTC 2018

Modified Files:
src/share/man/man4: options.4

Log Message:
Close .Bl directive properly


To generate a diff of this commit:
cvs rdiff -u -r1.494 -r1.495 src/share/man/man4/options.4

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

Modified files:

Index: src/share/man/man4/options.4
diff -u src/share/man/man4/options.4:1.494 src/share/man/man4/options.4:1.495
--- src/share/man/man4/options.4:1.494	Thu Dec 20 08:32:55 2018
+++ src/share/man/man4/options.4	Thu Dec 20 09:17:04 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: options.4,v 1.494 2018/12/20 08:32:55 cherry Exp $
+.\"	$NetBSD: options.4,v 1.495 2018/12/20 09:17:04 cherry Exp $
 .\"
 .\" Copyright (c) 1996
 .\" 	Perry E. Metzger.  All rights reserved.
@@ -2685,6 +2685,7 @@ underlined
 .It 4
 bolded
 .El
+.El
 .Ss x86-specific Options
 .Bl -ohang
 .It Cd options NO_PREEMPTION
@@ -2692,7 +2693,6 @@ Disables
 .Xr kpreempt 9
 support in the kernel.
 .El
-.El
 .\" The following requests should be uncommented and used where appropriate.
 .\" .Sh FILES
 .\" .Sh EXAMPLES



CVS commit: src/share/man/man4

2018-12-20 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Dec 20 08:32:55 UTC 2018

Modified Files:
src/share/man/man4: options.4

Log Message:
Document 'options NO_PREEMPTION'

With prompting from Christoph Badura.


To generate a diff of this commit:
cvs rdiff -u -r1.493 -r1.494 src/share/man/man4/options.4

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

Modified files:

Index: src/share/man/man4/options.4
diff -u src/share/man/man4/options.4:1.493 src/share/man/man4/options.4:1.494
--- src/share/man/man4/options.4:1.493	Wed Dec 19 13:57:45 2018
+++ src/share/man/man4/options.4	Thu Dec 20 08:32:55 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: options.4,v 1.493 2018/12/19 13:57:45 maxv Exp $
+.\"	$NetBSD: options.4,v 1.494 2018/12/20 08:32:55 cherry Exp $
 .\"
 .\" Copyright (c) 1996
 .\" 	Perry E. Metzger.  All rights reserved.
@@ -2685,6 +2685,13 @@ underlined
 .It 4
 bolded
 .El
+.Ss x86-specific Options
+.Bl -ohang
+.It Cd options NO_PREEMPTION
+Disables
+.Xr kpreempt 9
+support in the kernel.
+.El
 .El
 .\" The following requests should be uncommented and used where appropriate.
 .\" .Sh FILES



CVS commit: src/sys/arch/x86/include

2018-12-13 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Dec 13 16:16:51 UTC 2018

Modified Files:
src/sys/arch/x86/include: intr.h

Log Message:
Allow x86 builds to have the opportunity to not have pre-emption
enabled by default. This can be effected by having a:

"optionsNO_PREEMPTION"

line in the kernel configuration file.

While it was tempting to tie __HAVE_PREEMPTION to MULTIPROCESSOR,
as is currently assumed in sys/kern/kern_stub.c ,

having MULTIPROCESSOR without __HAVE_PREEMPTION
and not having either are valid configuration options which users
could have choice of. We thus err on the side of configurability.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/arch/x86/include/intr.h

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.56 src/sys/arch/x86/include/intr.h:1.57
--- src/sys/arch/x86/include/intr.h:1.56	Sun Jun 24 13:35:33 2018
+++ src/sys/arch/x86/include/intr.h	Thu Dec 13 16:16:51 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.56 2018/06/24 13:35:33 jdolecek Exp $	*/
+/*	$NetBSD: intr.h,v 1.57 2018/12/13 16:16:51 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -34,7 +34,9 @@
 
 #if !defined(XEN)
 #define	__HAVE_FAST_SOFTINTS
+#if !defined(NO_PREEMPTION)
 #define	__HAVE_PREEMPTION
+#endif /* !defined(NO_PREEMPTION) */
 #endif /*  !defined(XEN) */
 
 #ifdef _KERNEL



CVS commit: src/sys/arch/x86/x86

2018-12-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Tue Dec  4 19:27:22 UTC 2018

Modified Files:
src/sys/arch/x86/x86: cpu.c intr.c

Log Message:
Hypothetically speaking, if one were to want to compile a

'no options MULTIPROCESSOR'

kernel, these files may trip up the build.

Fix them by moving around the #defines as originally intended.

No Functional Changes.


To generate a diff of this commit:
cvs rdiff -u -r1.163 -r1.164 src/sys/arch/x86/x86/cpu.c
cvs rdiff -u -r1.136 -r1.137 src/sys/arch/x86/x86/intr.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/x86/cpu.c
diff -u src/sys/arch/x86/x86/cpu.c:1.163 src/sys/arch/x86/x86/cpu.c:1.164
--- src/sys/arch/x86/x86/cpu.c:1.163	Tue Dec  4 19:22:42 2018
+++ src/sys/arch/x86/x86/cpu.c	Tue Dec  4 19:27:22 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.163 2018/12/04 19:22:42 cherry Exp $	*/
+/*	$NetBSD: cpu.c,v 1.164 2018/12/04 19:27:22 cherry Exp $	*/
 
 /*
  * Copyright (c) 2000-2012 NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.163 2018/12/04 19:22:42 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.164 2018/12/04 19:27:22 cherry Exp $");
 
 #include "opt_ddb.h"
 #include "opt_mpbios.h"		/* for MPDEBUG */
@@ -188,10 +188,10 @@ struct cpu_info *cpu_starting;
 void	cpu_hatch(void *);
 static void	cpu_boot_secondary(struct cpu_info *ci);
 static void	cpu_start_secondary(struct cpu_info *ci);
-#endif
 #if NLAPIC > 0
 static void	cpu_copy_trampoline(paddr_t);
 #endif
+#endif /* MULTIPROCESSOR */
 
 /*
  * Runs once per boot once multiprocessor goo has been detected and
@@ -987,6 +987,7 @@ cpu_debug_dump(void)
 }
 #endif
 
+#ifdef MULTIPROCESSOR
 #if NLAPIC > 0
 static void
 cpu_copy_trampoline(paddr_t pdir_pa)
@@ -1028,7 +1029,6 @@ cpu_copy_trampoline(paddr_t pdir_pa)
 }
 #endif
 
-#ifdef MULTIPROCESSOR
 int
 mp_cpu_start(struct cpu_info *ci, paddr_t target)
 {

Index: src/sys/arch/x86/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.136 src/sys/arch/x86/x86/intr.c:1.137
--- src/sys/arch/x86/x86/intr.c:1.136	Sun Dec  2 08:19:44 2018
+++ src/sys/arch/x86/x86/intr.c	Tue Dec  4 19:27:22 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.136 2018/12/02 08:19:44 cherry Exp $	*/
+/*	$NetBSD: intr.c,v 1.137 2018/12/04 19:27:22 cherry Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.136 2018/12/02 08:19:44 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.137 2018/12/04 19:27:22 cherry Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -1493,7 +1493,9 @@ void
 cpu_intr_init(struct cpu_info *ci)
 {
 #if !defined(XEN)
+#if (NLAPIC > 0) || defined(MULTIPROCESSOR) || defined(__HAVE_PREEMPTION)
 	struct intrsource *isp;
+#endif
 #if NLAPIC > 0
 	static int first = 1;
 #if defined(MULTIPROCESSOR)



CVS commit: src/sys/arch/x86/x86

2018-12-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Tue Dec  4 19:22:42 UTC 2018

Modified Files:
src/sys/arch/x86/x86: cpu.c

Log Message:
Stop panic()ing on a UP system.

The reason for the panic is that the cpu_attach() doesn't run to
completion because it thinks it's run past maxcpus (which in the case
of UP), is 1.

This is because on x86 at least, mi_cpu_attach() is called *before*
configure() (and thus the cpu_match()/cpu_attach() pair). Thus ncpu
has already been incremented by the time MD cpu_attach() is called.

Fix this.


To generate a diff of this commit:
cvs rdiff -u -r1.162 -r1.163 src/sys/arch/x86/x86/cpu.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/x86/cpu.c
diff -u src/sys/arch/x86/x86/cpu.c:1.162 src/sys/arch/x86/x86/cpu.c:1.163
--- src/sys/arch/x86/x86/cpu.c:1.162	Mon Nov 12 18:10:36 2018
+++ src/sys/arch/x86/x86/cpu.c	Tue Dec  4 19:22:42 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.162 2018/11/12 18:10:36 maxv Exp $	*/
+/*	$NetBSD: cpu.c,v 1.163 2018/12/04 19:22:42 cherry Exp $	*/
 
 /*
  * Copyright (c) 2000-2012 NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.162 2018/11/12 18:10:36 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.163 2018/12/04 19:22:42 cherry Exp $");
 
 #include "opt_ddb.h"
 #include "opt_mpbios.h"		/* for MPDEBUG */
@@ -320,7 +320,7 @@ cpu_attach(device_t parent, device_t sel
 
 	sc->sc_dev = self;
 
-	if (ncpu == maxcpus) {
+	if (ncpu > maxcpus) {
 #ifndef _LP64
 		aprint_error(": too many CPUs, please use NetBSD/amd64\n");
 #else



CVS commit: src/sys/arch/x86/isa

2018-12-03 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Dec  3 19:51:09 UTC 2018

Modified Files:
src/sys/arch/x86/isa: isa_machdep.c

Log Message:
Allow isa_machdep.c to compile in the case of no ioapic support.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/x86/isa/isa_machdep.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/isa/isa_machdep.c
diff -u src/sys/arch/x86/isa/isa_machdep.c:1.40 src/sys/arch/x86/isa/isa_machdep.c:1.41
--- src/sys/arch/x86/isa/isa_machdep.c:1.40	Mon Sep 10 07:04:08 2018
+++ src/sys/arch/x86/isa/isa_machdep.c	Mon Dec  3 19:51:09 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: isa_machdep.c,v 1.40 2018/09/10 07:04:08 cherry Exp $	*/
+/*	$NetBSD: isa_machdep.c,v 1.41 2018/12/03 19:51:09 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.40 2018/09/10 07:04:08 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.41 2018/12/03 19:51:09 cherry Exp $");
 
 #include 
 #include 
@@ -210,8 +210,8 @@ isa_intr_establish_xname(isa_chipset_tag
 {
 	struct pic *pic;
 	int pin;
-	intr_handle_t mpih = 0;
 #if NIOAPIC > 0
+	intr_handle_t mpih = 0;
 	struct ioapic_softc *ioapic = NULL;
 #endif
 



CVS commit: src/sys/arch/x86/x86

2018-12-03 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Dec  3 19:46:43 UTC 2018

Modified Files:
src/sys/arch/x86/x86: efi.c

Log Message:
Do not assume that all uses of efi are pci aware.

Allow efi.c to compile in the case where pci is not enabled.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/x86/x86/efi.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/x86/efi.c
diff -u src/sys/arch/x86/x86/efi.c:1.18 src/sys/arch/x86/x86/efi.c:1.19
--- src/sys/arch/x86/x86/efi.c:1.18	Thu Nov 15 16:58:56 2018
+++ src/sys/arch/x86/x86/efi.c	Mon Dec  3 19:46:43 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: efi.c,v 1.18 2018/11/15 16:58:56 riastradh Exp $	*/
+/*	$NetBSD: efi.c,v 1.19 2018/12/03 19:46:43 cherry Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.18 2018/11/15 16:58:56 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.19 2018/12/03 19:46:43 cherry Exp $");
 
 #include 
 #include 
@@ -40,7 +40,9 @@ __KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.18
 #include 
 
 #include 
+#if NPCI > 0
 #include  /* for pci_mapreg_map_enable_decode */
+#endif
 
 const struct uuid EFI_UUID_ACPI20 = EFI_TABLE_ACPI20;
 const struct uuid EFI_UUID_ACPI10 = EFI_TABLE_ACPI10;
@@ -419,7 +421,9 @@ efi_init(void)
 		return;
 	}
 	bootmethod_efi = true;
+#if NPCI > 0	
 	pci_mapreg_map_enable_decode = true; /* PR port-amd64/53286 */
+#endif
 }
 
 bool



CVS commit: src/sys/dev/acpi

2018-12-02 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Dec  3 05:22:03 UTC 2018

Modified Files:
src/sys/dev/acpi: acpi_mcfg.c

Log Message:
Define macro before using it. This macro is used as a compile time
"plugin" mechanism to use various platform specific enumeration
functions. It is currently separately defined for 'native' and XEN,
but the mechanism is not exported globally as it should be.

XXX: fix this.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/acpi/acpi_mcfg.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/dev/acpi/acpi_mcfg.c
diff -u src/sys/dev/acpi/acpi_mcfg.c:1.13 src/sys/dev/acpi/acpi_mcfg.c:1.14
--- src/sys/dev/acpi/acpi_mcfg.c:1.13	Fri Nov  2 19:51:08 2018
+++ src/sys/dev/acpi/acpi_mcfg.c	Mon Dec  3 05:22:03 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_mcfg.c,v 1.13 2018/11/02 19:51:08 jmcneill Exp $	*/
+/*	$NetBSD: acpi_mcfg.c,v 1.14 2018/12/03 05:22:03 cherry Exp $	*/
 
 /*-
  * Copyright (C) 2015 NONAKA Kimihiro 
@@ -28,7 +28,7 @@
 #include "opt_pci.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.13 2018/11/02 19:51:08 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.14 2018/12/03 05:22:03 cherry Exp $");
 
 #include 
 #include 
@@ -539,6 +539,10 @@ acpimcfg_device_probe(const struct pci_a
 	return 0;
 }
 
+#ifdef PCI_MACHDEP_ENUMERATE_BUS
+#define pci_enumerate_bus PCI_MACHDEP_ENUMERATE_BUS
+#endif
+
 static void
 acpimcfg_scan_bus(struct pci_softc *sc, pci_chipset_tag_t pc, int bus)
 {



CVS commit: src/sys/arch

2018-12-02 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Dec  2 08:19:44 UTC 2018

Modified Files:
src/sys/arch/amd64/amd64: mainbus.c
src/sys/arch/i386/i386: mainbus.c
src/sys/arch/x86/pci: pci_intr_machdep.c
src/sys/arch/x86/x86: intr.c

Log Message:
make

options NO_PCI_MSI_MSIX

work again for arch/x86/


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/amd64/amd64/mainbus.c
cvs rdiff -u -r1.103 -r1.104 src/sys/arch/i386/i386/mainbus.c
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/x86/pci/pci_intr_machdep.c
cvs rdiff -u -r1.135 -r1.136 src/sys/arch/x86/x86/intr.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/mainbus.c
diff -u src/sys/arch/amd64/amd64/mainbus.c:1.38 src/sys/arch/amd64/amd64/mainbus.c:1.39
--- src/sys/arch/amd64/amd64/mainbus.c:1.38	Tue May 23 08:54:38 2017
+++ src/sys/arch/amd64/amd64/mainbus.c	Sun Dec  2 08:19:44 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: mainbus.c,v 1.38 2017/05/23 08:54:38 nonaka Exp $	*/
+/*	$NetBSD: mainbus.c,v 1.39 2018/12/02 08:19:44 cherry Exp $	*/
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.38 2017/05/23 08:54:38 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.39 2018/12/02 08:19:44 cherry Exp $");
 
 #include 
 #include 
@@ -74,7 +74,9 @@ __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 
 #include 
 #endif
 #endif
+#ifdef __HAVE_PCI_MSI_MSIX
 #include 
+#endif /* __HAVE_PCI_MSI_MSIX */
 #endif
 
 /*
@@ -179,7 +181,9 @@ mainbus_attach(device_t parent, device_t
 #endif
 
 #if NPCI > 0
+#ifdef __HAVE_PCI_MSI_MSIX
 	msipic_init();
+#endif
 
 	/*
 	 * ACPI needs to be able to access PCI configuration space.
@@ -209,9 +213,9 @@ mainbus_attach(device_t parent, device_t
 	 */
 	if (acpi_present)
 		mpacpi_active = mpacpi_scan_apics(self, ) != 0;
-#endif
 
 	if (!mpacpi_active) {
+#endif		
 #ifdef MPBIOS
 		if (mpbios_present)
 			mpbios_scan(self, );
@@ -227,7 +231,9 @@ mainbus_attach(device_t parent, device_t
 
 			config_found_ia(self, "cpubus", , mainbus_print);
 		}
+#if NACPICA > 0		
 	}
+#endif
 
 #if NISADMA > 0 && NACPICA > 0
 	/*

Index: src/sys/arch/i386/i386/mainbus.c
diff -u src/sys/arch/i386/i386/mainbus.c:1.103 src/sys/arch/i386/i386/mainbus.c:1.104
--- src/sys/arch/i386/i386/mainbus.c:1.103	Tue May 23 08:54:38 2017
+++ src/sys/arch/i386/i386/mainbus.c	Sun Dec  2 08:19:44 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: mainbus.c,v 1.103 2017/05/23 08:54:38 nonaka Exp $	*/
+/*	$NetBSD: mainbus.c,v 1.104 2018/12/02 08:19:44 cherry Exp $	*/
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.103 2017/05/23 08:54:38 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.104 2018/12/02 08:19:44 cherry Exp $");
 
 #include 
 #include 
@@ -86,7 +86,9 @@ __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 
 #include 
 #endif
 #endif
+#ifdef __HAVE_PCI_MSI_MSIX
 #include 
+#endif /* __HAVE_PCI_MSI_MSIX */
 #endif
 
 void	mainbus_childdetached(device_t, device_t);

Index: src/sys/arch/x86/pci/pci_intr_machdep.c
diff -u src/sys/arch/x86/pci/pci_intr_machdep.c:1.47 src/sys/arch/x86/pci/pci_intr_machdep.c:1.48
--- src/sys/arch/x86/pci/pci_intr_machdep.c:1.47	Tue Nov 27 21:03:50 2018
+++ src/sys/arch/x86/pci/pci_intr_machdep.c	Sun Dec  2 08:19:44 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: pci_intr_machdep.c,v 1.47 2018/11/27 21:03:50 jdolecek Exp $	*/
+/*	$NetBSD: pci_intr_machdep.c,v 1.48 2018/12/02 08:19:44 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2009 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.47 2018/11/27 21:03:50 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.48 2018/12/02 08:19:44 cherry Exp $");
 
 #include 
 #include 
@@ -102,6 +102,8 @@ __KERNEL_RCSID(0, "$NetBSD: pci_intr_mac
 #include 
 #include 
 #include 
+#else
+#include 
 #endif
 
 #ifdef MPBIOS
@@ -232,8 +234,10 @@ pci_intr_string(pci_chipset_tag_t pc, pc
 		buf, len);
 	}
 
+#if defined(__HAVE_PCI_MSI_MSIX)	
 	if (INT_VIA_MSI(ih))
 		return x86_pci_msi_string(pc, ih, buf, len);
+#endif
 
 	return intr_string(ih & ~MPSAFE_MASK, buf, len);
 }
@@ -319,6 +323,8 @@ pci_intr_establish_xname_internal(pci_ch
 		pc, ih, level, func, arg);
 	}
 
+
+#ifdef __HAVE_PCI_MSI_MSIX
 	if (INT_VIA_MSI(ih)) {
 		if (MSI_INT_IS_MSIX(ih))
 			return x86_pci_msix_establish(pc, ih, level, func, arg,
@@ -327,7 +333,7 @@ pci_intr_establish_xname_internal(pci_ch
 			return x86_pci_msi_establish(pc, ih, level, func, arg,
 			xname);
 	}
-
+#endif
 	if (pci_intr_find_intx_irq(ih, , , )) {
 		aprint_normal("%s: bad pic %d\n", __func__,
 		APIC_IRQ_APIC(ih));

Index: src/sys/arch/x86/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.135 

CVS commit: src/sys/arch

2018-11-18 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Nov 18 23:50:48 UTC 2018

Modified Files:
src/sys/arch/amd64/include: cpu.h
src/sys/arch/i386/include: cpu.h
src/sys/arch/x86/include: cpu.h
src/sys/arch/xen/x86: hypervisor_machdep.c
src/sys/arch/xen/xen: clock.c

Log Message:
On Xen, copy just the bits we need from the trapframe for hardclock(9)
and statclock(9).

Current, the macros that use the trapframe are:
CLKF_USERMODE()
CLKF_PC()
CLKF_INTR()

Of these, CLKF_INTR() already ignores the frame and uses the ci_idepth
variable to do its job.

Convert the two remaining ones to do this, but only for XEN.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/sys/arch/amd64/include/cpu.h
cvs rdiff -u -r1.179 -r1.180 src/sys/arch/i386/include/cpu.h
cvs rdiff -u -r1.99 -r1.100 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/xen/x86/hypervisor_machdep.c
cvs rdiff -u -r1.73 -r1.74 src/sys/arch/xen/xen/clock.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/include/cpu.h
diff -u src/sys/arch/amd64/include/cpu.h:1.62 src/sys/arch/amd64/include/cpu.h:1.63
--- src/sys/arch/amd64/include/cpu.h:1.62	Fri Mar 16 12:21:50 2018
+++ src/sys/arch/amd64/include/cpu.h	Sun Nov 18 23:50:48 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.62 2018/03/16 12:21:50 maxv Exp $	*/
+/*	$NetBSD: cpu.h,v 1.63 2018/11/18 23:50:48 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -83,8 +83,13 @@ cpu_set_curpri(int pri)
 }
 #endif	/* __GNUC__ && !_MODULE */
 
+#ifdef XEN
+#define	CLKF_USERMODE(frame)	(curcpu()->ci_xen_clockf_usermode)
+#define CLKF_PC(frame)		(curcpu()->ci_xen_clockf_pc)
+#else /* XEN */
 #define	CLKF_USERMODE(frame)	USERMODE((frame)->cf_if.if_tf.tf_cs)
 #define CLKF_PC(frame)		((frame)->cf_if.if_tf.tf_rip)
+#endif /* XEN */
 #define CLKF_INTR(frame)	(curcpu()->ci_idepth > 0)
 #define LWP_PC(l)		((l)->l_md.md_regs->tf_rip)
 

Index: src/sys/arch/i386/include/cpu.h
diff -u src/sys/arch/i386/include/cpu.h:1.179 src/sys/arch/i386/include/cpu.h:1.180
--- src/sys/arch/i386/include/cpu.h:1.179	Sun Sep 17 09:41:35 2017
+++ src/sys/arch/i386/include/cpu.h	Sun Nov 18 23:50:48 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.179 2017/09/17 09:41:35 maxv Exp $	*/
+/*	$NetBSD: cpu.h,v 1.180 2018/11/18 23:50:48 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -81,8 +81,13 @@ cpu_set_curpri(int pri)
 }
 #endif
 
+#ifdef XEN
+#define	CLKF_USERMODE(frame)	(curcpu()->ci_xen_clockf_usermode)
+#define CLKF_PC(frame)		(curcpu()->ci_xen_clockf_pc)
+#else /* XEN */
 #define	CLKF_USERMODE(frame)	USERMODE((frame)->cf_if.if_cs)
 #define	CLKF_PC(frame)		((frame)->cf_if.if_eip)
+#endif /* XEN */
 #define	CLKF_INTR(frame)	(curcpu()->ci_idepth > 0)
 #define	LWP_PC(l)		((l)->l_md.md_regs->tf_eip)
 

Index: src/sys/arch/x86/include/cpu.h
diff -u src/sys/arch/x86/include/cpu.h:1.99 src/sys/arch/x86/include/cpu.h:1.100
--- src/sys/arch/x86/include/cpu.h:1.99	Sun Nov 18 10:24:09 2018
+++ src/sys/arch/x86/include/cpu.h	Sun Nov 18 23:50:48 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.99 2018/11/18 10:24:09 cherry Exp $	*/
+/*	$NetBSD: cpu.h,v 1.100 2018/11/18 23:50:48 cherry Exp $	*/
 
 /*
  * Copyright (c) 1990 The Regents of the University of California.
@@ -286,7 +286,8 @@ struct cpu_info {
 	 * Clockframe for timer interrupt handler.
 	 * Saved at entry via event callback.
 	 */
-	struct clockframe ci_event_clockframe;
+	vaddr_t ci_xen_clockf_pc; /* RIP at last event interrupt */
+	bool ci_xen_clockf_usermode; /* Was the guest in usermode ? */
 
 	/* Event counters for various pathologies that might happen.  */
 	struct evcnt	ci_xen_cpu_tsc_backwards_evcnt;

Index: src/sys/arch/xen/x86/hypervisor_machdep.c
diff -u src/sys/arch/xen/x86/hypervisor_machdep.c:1.31 src/sys/arch/xen/x86/hypervisor_machdep.c:1.32
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.31	Sun Nov 18 10:24:09 2018
+++ src/sys/arch/xen/x86/hypervisor_machdep.c	Sun Nov 18 23:50:48 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor_machdep.c,v 1.31 2018/11/18 10:24:09 cherry Exp $	*/
+/*	$NetBSD: hypervisor_machdep.c,v 1.32 2018/11/18 23:50:48 cherry Exp $	*/
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.31 2018/11/18 10:24:09 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.32 2018/11/18 23:50:48 cherry Exp $");
 
 #include 
 #include 
@@ -263,7 +263,8 @@ do_hypervisor_callback(struct intrframe 
 
 	/* Save trapframe for clock handler */
 	KASSERT(regs != NULL);
-	ci->ci_event_clockframe.cf_if = *regs;
+	ci->ci_xen_clockf_usermode = USERMODE(regs->if_tf.tf_cs);
+	ci->ci_xen_clockf_pc = regs->if_tf.tf_rip;
 
 	// DDD printf("do_hypervisor_callback\n");
 

Index: src/sys/arch/xen/xen/clock.c
diff -u src/sys/arch/xen/xen/clock.c:1.73 

CVS commit: src/sys/arch

2018-11-18 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Nov 18 10:24:10 UTC 2018

Modified Files:
src/sys/arch/x86/include: cpu.h
src/sys/arch/xen/x86: hypervisor_machdep.c
src/sys/arch/xen/xen: clock.c

Log Message:
Save the interrupt trap/clockframe to a per-cpu copy.

We can use this copy to pass on the trapframe to hardclock(9) from
within the xen timer handler. This delinks the current dependency
between MD code and the handler, which is specially prototyped to take
the clockframe unlike any other handler.

This change has performance implications, as each interrupt entry will
copy the entire trapframe over to the per-cpu cached copy. This can be
mitigated by selectively copying just the parts of the clockframe that
are used by hardclock() et. al.

Tested on amd64 XEN domU


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/xen/x86/hypervisor_machdep.c
cvs rdiff -u -r1.72 -r1.73 src/sys/arch/xen/xen/clock.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/cpu.h
diff -u src/sys/arch/x86/include/cpu.h:1.98 src/sys/arch/x86/include/cpu.h:1.99
--- src/sys/arch/x86/include/cpu.h:1.98	Fri Oct  5 18:51:52 2018
+++ src/sys/arch/x86/include/cpu.h	Sun Nov 18 10:24:09 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.98 2018/10/05 18:51:52 maxv Exp $	*/
+/*	$NetBSD: cpu.h,v 1.99 2018/11/18 10:24:09 cherry Exp $	*/
 
 /*
  * Copyright (c) 1990 The Regents of the University of California.
@@ -94,6 +94,15 @@ struct cpu_tss {
 } __packed;
 
 /*
+ * Arguments to hardclock, softclock and statclock
+ * encapsulate the previous machine state in an opaque
+ * clockframe; for now, use generic intrframe.
+ */
+struct clockframe {
+	struct intrframe cf_if;
+};
+
+/*
  * a bunch of this belongs in cpuvar.h; move it later..
  */
 
@@ -273,6 +282,12 @@ struct cpu_info {
 	/* Xen periodic timer interrupt handle.  */
 	struct intrhand	*ci_xen_timer_intrhand;
 
+	/*
+	 * Clockframe for timer interrupt handler.
+	 * Saved at entry via event callback.
+	 */
+	struct clockframe ci_event_clockframe;
+
 	/* Event counters for various pathologies that might happen.  */
 	struct evcnt	ci_xen_cpu_tsc_backwards_evcnt;
 	struct evcnt	ci_xen_tsc_delta_negative_evcnt;
@@ -378,15 +393,6 @@ void cpu_speculation_init(struct cpu_inf
 #define	curpcb			((struct pcb *)lwp_getpcb(curlwp))
 
 /*
- * Arguments to hardclock, softclock and statclock
- * encapsulate the previous machine state in an opaque
- * clockframe; for now, use generic intrframe.
- */
-struct clockframe {
-	struct intrframe cf_if;
-};
-
-/*
  * Give a profiling tick to the current process when the user profiling
  * buffer pages are invalid.  On the i386, request an ast to send us
  * through trap(), marking the proc as needing a profiling tick.

Index: src/sys/arch/xen/x86/hypervisor_machdep.c
diff -u src/sys/arch/xen/x86/hypervisor_machdep.c:1.30 src/sys/arch/xen/x86/hypervisor_machdep.c:1.31
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.30	Sat Nov 17 05:26:46 2018
+++ src/sys/arch/xen/x86/hypervisor_machdep.c	Sun Nov 18 10:24:09 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor_machdep.c,v 1.30 2018/11/17 05:26:46 cherry Exp $	*/
+/*	$NetBSD: hypervisor_machdep.c,v 1.31 2018/11/18 10:24:09 cherry Exp $	*/
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.30 2018/11/17 05:26:46 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.31 2018/11/18 10:24:09 cherry Exp $");
 
 #include 
 #include 
@@ -261,6 +261,10 @@ do_hypervisor_callback(struct intrframe 
 	vci = ci->ci_vcpu;
 	level = ci->ci_ilevel;
 
+	/* Save trapframe for clock handler */
+	KASSERT(regs != NULL);
+	ci->ci_event_clockframe.cf_if = *regs;
+
 	// DDD printf("do_hypervisor_callback\n");
 
 #ifdef EARLY_DEBUG_EVENT

Index: src/sys/arch/xen/xen/clock.c
diff -u src/sys/arch/xen/xen/clock.c:1.72 src/sys/arch/xen/xen/clock.c:1.73
--- src/sys/arch/xen/xen/clock.c:1.72	Fri Oct 26 05:33:21 2018
+++ src/sys/arch/xen/xen/clock.c	Sun Nov 18 10:24:10 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.72 2018/10/26 05:33:21 cherry Exp $	*/
+/*	$NetBSD: clock.c,v 1.73 2018/11/18 10:24:10 cherry Exp $	*/
 
 /*-
  * Copyright (c) 2017, 2018 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.72 2018/10/26 05:33:21 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.73 2018/11/18 10:24:10 cherry Exp $");
 
 #include 
 #include 
@@ -811,6 +811,7 @@ xen_timer_handler(void *cookie, struct c
 	KASSERT(cpu_intr_p());
 	KASSERT(cookie == ci);
 
+	frame = >ci_event_clockframe;
 again:
 	/*
 	 * Find how many nanoseconds of Xen system time has elapsed



CVS commit: src/sys/arch/xen/x86

2018-11-16 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Nov 17 05:26:46 UTC 2018

Modified Files:
src/sys/arch/xen/x86: hypervisor_machdep.c

Log Message:
Use hypervisor provided interface to unmask specific ports.

Although at first glance this looks suboptimal, the unmask operation
fast path does not use hypervisor_unmask_event(). Instead, it directly
operates on the mask and pending bit arrays to provide what would
effectively be an "auto mask/eoi" semantic.

This change is thus not in the fast path, and has the advantage of
performance improvements since cross CPU state updates etc. is handled
within the hypervisor instead of domU IPIs.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/xen/x86/hypervisor_machdep.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/xen/x86/hypervisor_machdep.c
diff -u src/sys/arch/xen/x86/hypervisor_machdep.c:1.29 src/sys/arch/xen/x86/hypervisor_machdep.c:1.30
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.29	Fri Oct 26 05:33:21 2018
+++ src/sys/arch/xen/x86/hypervisor_machdep.c	Sat Nov 17 05:26:46 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor_machdep.c,v 1.29 2018/10/26 05:33:21 cherry Exp $	*/
+/*	$NetBSD: hypervisor_machdep.c,v 1.30 2018/11/17 05:26:46 cherry Exp $	*/
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.29 2018/10/26 05:33:21 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.30 2018/11/17 05:26:46 cherry Exp $");
 
 #include 
 #include 
@@ -322,47 +322,22 @@ hypervisor_send_event(struct cpu_info *c
 void
 hypervisor_unmask_event(unsigned int ev)
 {
-	volatile shared_info_t *s = HYPERVISOR_shared_info;
-	CPU_INFO_ITERATOR cii;
-	struct cpu_info *ci;
-	volatile struct vcpu_info *vci;
+
+	KASSERT(ev > 0 && ev < NR_EVENT_CHANNELS);
 
 #ifdef PORT_DEBUG
 	if (ev == PORT_DEBUG)
 		printf("hypervisor_unmask_event %d\n", ev);
 #endif
 
-	xen_atomic_clear_bit(>evtchn_mask[0], ev);
-	/*
-	 * The following is basically the equivalent of
-	 * 'hw_resend_irq'. Just like a real IO-APIC we 'lose the
-	 * interrupt edge' if the channel is masked.
-	 */
-	if (!xen_atomic_test_bit(>evtchn_pending[0], ev))
-		return;
+	/* Xen unmasks the evtchn_mask[0]:ev bit for us. */
+	evtchn_op_t op;
+	op.cmd = EVTCHNOP_unmask;
+	op.u.unmask.port = ev;
+	if (HYPERVISOR_event_channel_op() != 0)
+		panic("Failed to unmask event %d\n", ev);
 
-	for (CPU_INFO_FOREACH(cii, ci)) {
-		if (!xen_atomic_test_bit(>ci_evtmask[0], ev))
-			continue;
-		vci = ci->ci_vcpu;
-		if (__predict_true(ci == curcpu())) {
-			if (!xen_atomic_test_and_set_bit(>evtchn_pending_sel,
-ev>>LONG_SHIFT))
-xen_atomic_set_bit(>evtchn_upcall_pending, 0);
-		}
-		if (!vci->evtchn_upcall_mask) {
-			if (__predict_true(ci == curcpu())) {
-hypervisor_force_callback();
-			} else {
-if (__predict_false(
-xen_send_ipi(ci, XEN_IPI_HVCB))) {
-	panic("xen_send_ipi(cpu%d, "
-	"XEN_IPI_HVCB) failed\n",
-	(int) ci->ci_cpuid);
-}
-			}
-		}
-	}
+	return;
 }
 
 void



CVS commit: src/sys/arch/xen

2018-10-25 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Oct 26 05:33:21 UTC 2018

Modified Files:
src/sys/arch/xen/include: hypervisor.h
src/sys/arch/xen/x86: hypervisor_machdep.c xen_ipi.c
src/sys/arch/xen/xen: clock.c evtchn.c if_xennet_xenbus.c pciback.c
xbd_xenbus.c xbdback_xenbus.c xencons.c xennetback_xenbus.c
src/sys/arch/xen/xenbus: xenbus_comms.c

Log Message:
Decompose hypervisor_enable_event() into functional steps.

The hypervisor_unmask_event() step is relevant for any event.

The pirq related step is only relevant for pirq bound events.

Prune blanket usage of this, so that usage is semantically appropriate.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/xen/include/hypervisor.h
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/xen/x86/hypervisor_machdep.c
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/xen/x86/xen_ipi.c
cvs rdiff -u -r1.71 -r1.72 src/sys/arch/xen/xen/clock.c
cvs rdiff -u -r1.81 -r1.82 src/sys/arch/xen/xen/evtchn.c
cvs rdiff -u -r1.80 -r1.81 src/sys/arch/xen/xen/if_xennet_xenbus.c
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/xen/xen/pciback.c
cvs rdiff -u -r1.89 -r1.90 src/sys/arch/xen/xen/xbd_xenbus.c
cvs rdiff -u -r1.68 -r1.69 src/sys/arch/xen/xen/xbdback_xenbus.c
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/xen/xen/xencons.c
cvs rdiff -u -r1.70 -r1.71 src/sys/arch/xen/xen/xennetback_xenbus.c
cvs rdiff -u -r1.19 -r1.20 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/xen/include/hypervisor.h
diff -u src/sys/arch/xen/include/hypervisor.h:1.45 src/sys/arch/xen/include/hypervisor.h:1.46
--- src/sys/arch/xen/include/hypervisor.h:1.45	Sun Sep 23 02:27:24 2018
+++ src/sys/arch/xen/include/hypervisor.h	Fri Oct 26 05:33:21 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor.h,v 1.45 2018/09/23 02:27:24 cherry Exp $	*/
+/*	$NetBSD: hypervisor.h,v 1.46 2018/10/26 05:33:21 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -55,7 +55,8 @@
 #define _XEN_HYPERVISOR_H_
 
 #include "opt_xen.h"
-
+#include "isa.h"
+#include "pci.h"
 
 struct hypervisor_attach_args {
 	const char 		*haa_busname;
@@ -130,8 +131,10 @@ 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_enable_event(unsigned int);
+void hypervisor_ack_pirq_event(unsigned int);
+#endif /* NPCI > 0 || NISA > 0 */
 
 extern int xen_version;
 #define XEN_MAJOR(x) (((x) & 0x) >> 16)

Index: src/sys/arch/xen/x86/hypervisor_machdep.c
diff -u src/sys/arch/xen/x86/hypervisor_machdep.c:1.28 src/sys/arch/xen/x86/hypervisor_machdep.c:1.29
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.28	Sun Sep 21 12:46:15 2014
+++ src/sys/arch/xen/x86/hypervisor_machdep.c	Fri Oct 26 05:33:21 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor_machdep.c,v 1.28 2014/09/21 12:46:15 bouyer Exp $	*/
+/*	$NetBSD: hypervisor_machdep.c,v 1.29 2018/10/26 05:33:21 cherry Exp $	*/
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.28 2014/09/21 12:46:15 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.29 2018/10/26 05:33:21 cherry Exp $");
 
 #include 
 #include 
@@ -71,6 +71,8 @@ __KERNEL_RCSID(0, "$NetBSD: hypervisor_m
 #include 
 
 #include "opt_xen.h"
+#include "isa.h"
+#include "pci.h"
 
 /*
  * arch-dependent p2m frame lists list (L3 and L2)
@@ -392,7 +394,10 @@ evt_enable_event(unsigned int port, unsi
 		 unsigned int l2i, void *args)
 {
 	KASSERT(args == NULL);
-	hypervisor_enable_event(port);
+	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/xen_ipi.c
diff -u src/sys/arch/xen/x86/xen_ipi.c:1.27 src/sys/arch/xen/x86/xen_ipi.c:1.28
--- src/sys/arch/xen/x86/xen_ipi.c:1.27	Wed Oct 24 03:59:33 2018
+++ src/sys/arch/xen/x86/xen_ipi.c	Fri Oct 26 05:33:21 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_ipi.c,v 1.27 2018/10/24 03:59:33 cherry Exp $ */
+/* $NetBSD: xen_ipi.c,v 1.28 2018/10/26 05:33:21 cherry 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.27 2018/10/24 03:59:33 cherry Exp $");
+ * __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.28 2018/10/26 05:33:21 cherry Exp $");
  */
 
-__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.27 2018/10/24 03:59:33 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.28 2018/10/26 05:33:21 cherry Exp $");
 
 #include "opt_ddb.h"
 
@@ -143,7 +143,7 @@ xen_ipi_init(void)
 		/* NOTREACHED */
 	}
 
-	hypervisor_enable_event(evtchn);
+	hypervisor_unmask_event(evtchn);
 }
 
 #ifdef DIAGNOSTIC

Index: src/sys/arch/xen/xen/clock.c
diff -u src/sys/arch/xen/xen/clock.c:1.71 

CVS commit: src/sys/arch/xen

2018-10-23 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Oct 24 03:59:33 UTC 2018

Modified Files:
src/sys/arch/xen/x86: xen_ipi.c
src/sys/arch/xen/xen: clock.c if_xennet_xenbus.c pciback.c xbd_xenbus.c
xbdback_xenbus.c xencons.c xenevt.c xennetback_xenbus.c
xpci_xenbus.c
src/sys/arch/xen/xenbus: xenbus_comms.c

Log Message:
When using the intr_establish_xname() interface to register
XEN events, follow established x86/intr.c conventions - set
the 'legacy' irq value to -1, to indicate that the pic, pin
combination (_pic, port) is used for registration.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/xen/x86/xen_ipi.c
cvs rdiff -u -r1.70 -r1.71 src/sys/arch/xen/xen/clock.c
cvs rdiff -u -r1.79 -r1.80 src/sys/arch/xen/xen/if_xennet_xenbus.c
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/xen/xen/pciback.c
cvs rdiff -u -r1.88 -r1.89 src/sys/arch/xen/xen/xbd_xenbus.c
cvs rdiff -u -r1.67 -r1.68 src/sys/arch/xen/xen/xbdback_xenbus.c
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/xen/xen/xencons.c
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/xen/xen/xenevt.c
cvs rdiff -u -r1.69 -r1.70 src/sys/arch/xen/xen/xennetback_xenbus.c
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/xen/xen/xpci_xenbus.c
cvs rdiff -u -r1.18 -r1.19 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/xen/x86/xen_ipi.c
diff -u src/sys/arch/xen/x86/xen_ipi.c:1.26 src/sys/arch/xen/x86/xen_ipi.c:1.27
--- src/sys/arch/xen/x86/xen_ipi.c:1.26	Tue Jul 24 12:26:14 2018
+++ src/sys/arch/xen/x86/xen_ipi.c	Wed Oct 24 03:59:33 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_ipi.c,v 1.26 2018/07/24 12:26:14 bouyer Exp $ */
+/* $NetBSD: xen_ipi.c,v 1.27 2018/10/24 03:59:33 cherry 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.26 2018/07/24 12:26:14 bouyer Exp $");
+ * __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.27 2018/10/24 03:59:33 cherry Exp $");
  */
 
-__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.26 2018/07/24 12:26:14 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.27 2018/10/24 03:59:33 cherry Exp $");
 
 #include "opt_ddb.h"
 
@@ -137,7 +137,7 @@ xen_ipi_init(void)
 	snprintf(intr_xname, sizeof(intr_xname), "%s ipi",
 	device_xname(ci->ci_dev));
 
-	if (intr_establish_xname(0, _pic, evtchn, IST_LEVEL, IPL_HIGH,
+	if (intr_establish_xname(-1, _pic, evtchn, IST_LEVEL, IPL_HIGH,
 		xen_ipi_handler, ci, true, intr_xname) == NULL) {
 		panic("%s: unable to register ipi handler\n", __func__);
 		/* NOTREACHED */

Index: src/sys/arch/xen/xen/clock.c
diff -u src/sys/arch/xen/xen/clock.c:1.70 src/sys/arch/xen/xen/clock.c:1.71
--- src/sys/arch/xen/xen/clock.c:1.70	Sat Jun 30 14:59:38 2018
+++ src/sys/arch/xen/xen/clock.c	Wed Oct 24 03:59:33 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.70 2018/06/30 14:59:38 riastradh Exp $	*/
+/*	$NetBSD: clock.c,v 1.71 2018/10/24 03:59:33 cherry Exp $	*/
 
 /*-
  * Copyright (c) 2017, 2018 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.70 2018/06/30 14:59:38 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.71 2018/10/24 03:59:33 cherry Exp $");
 
 #include 
 #include 
@@ -763,7 +763,7 @@ xen_resumeclocks(struct cpu_info *ci)
 	snprintf(intr_xname, sizeof(intr_xname), "%s clock",
 	device_xname(ci->ci_dev));
 	/* XXX sketchy function pointer cast -- fix the API, please */
-	ci->ci_xen_timer_intrhand = intr_establish_xname(0, _pic, evtch,
+	ci->ci_xen_timer_intrhand = intr_establish_xname(-1, _pic, evtch,
 	IST_LEVEL, IPL_CLOCK, (int (*)(void *))xen_timer_handler, ci, true,
 	intr_xname);
 	if (ci->ci_xen_timer_intrhand == NULL)

Index: src/sys/arch/xen/xen/if_xennet_xenbus.c
diff -u src/sys/arch/xen/xen/if_xennet_xenbus.c:1.79 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.80
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.79	Mon Sep  3 16:29:29 2018
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Wed Oct 24 03:59:33 2018
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.79 2018/09/03 16:29:29 riastradh Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.80 2018/10/24 03:59:33 cherry Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -84,7 +84,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.79 2018/09/03 16:29:29 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.80 2018/10/24 03:59:33 cherry Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
@@ -517,7 +517,7 @@ xennet_xenbus_resume(device_t dev, const
 		goto abort_resume;
 	aprint_verbose_dev(dev, "using event channel %d\n",
 	sc->sc_evtchn);
-	sc->sc_ih = intr_establish_xname(0, _pic, sc->sc_evtchn, IST_LEVEL,
+	sc->sc_ih = intr_establish_xname(-1, _pic, sc->sc_evtchn, IST_LEVEL,
 	IPL_NET, _handler, sc, false, 

CVS commit: src/sys/arch/x86/x86

2018-10-23 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Oct 24 03:51:21 UTC 2018

Modified Files:
src/sys/arch/x86/x86: intr.c

Log Message:
When returning a cached shared irq event value, DTRT


To generate a diff of this commit:
cvs rdiff -u -r1.134 -r1.135 src/sys/arch/x86/x86/intr.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/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.134 src/sys/arch/x86/x86/intr.c:1.135
--- src/sys/arch/x86/x86/intr.c:1.134	Mon Oct  8 08:05:08 2018
+++ src/sys/arch/x86/x86/intr.c	Wed Oct 24 03:51:21 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.134 2018/10/08 08:05:08 cherry Exp $	*/
+/*	$NetBSD: intr.c,v 1.135 2018/10/24 03:51:21 cherry Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.134 2018/10/08 08:05:08 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.135 2018/10/24 03:51:21 cherry Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -1294,7 +1294,7 @@ intr_establish_xname(int legacy_irq, str
 		 * Shared interrupt - we can't rebind.
 		 * The port is shared instead.
 		 */
-		evtchn = irq2port[gsi];
+		evtchn = irq2port[gsi] - 1;
 	}
 
 	pih = pirq_establish(gsi, evtchn, handler, arg, level,



CVS commit: src/sys/arch/i386/i386

2018-10-17 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Oct 18 04:22:22 UTC 2018

Modified Files:
src/sys/arch/i386/i386: machdep.c

Log Message:
Use memory allocated for the ldt, not the idt.

This must have been a typo that we got away with because we were not
using the idt[] so far.

This fix should now allow -current i386 XEN to boot, as before.


To generate a diff of this commit:
cvs rdiff -u -r1.811 -r1.812 src/sys/arch/i386/i386/machdep.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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.811 src/sys/arch/i386/i386/machdep.c:1.812
--- src/sys/arch/i386/i386/machdep.c:1.811	Sat Sep 29 07:00:20 2018
+++ src/sys/arch/i386/i386/machdep.c	Thu Oct 18 04:22:22 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.811 2018/09/29 07:00:20 cherry Exp $	*/
+/*	$NetBSD: machdep.c,v 1.812 2018/10/18 04:22:22 cherry Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009, 2017
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.811 2018/09/29 07:00:20 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.812 2018/10/18 04:22:22 cherry Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_freebsd.h"
@@ -1326,7 +1326,7 @@ init386(paddr_t first_avail)
 	GSEL(GCODE_SEL, SEL_KPL), (unsigned long)hypervisor_callback,
 	GSEL(GCODE_SEL, SEL_KPL), (unsigned long)failsafe_callback);
 
-	ldtstore = (union descriptor *)idt_vaddr;
+	ldtstore = (union descriptor *)ldt_vaddr;
 #endif /* XEN */
 
 	/* make ldt gates and memory segments */



CVS commit: src/sys/arch/xen/x86

2018-10-17 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Oct 18 04:17:18 UTC 2018

Modified Files:
src/sys/arch/xen/x86: xenfunc.c

Log Message:
Zero out page table memory for IDT before use.
To copy the IDT entry before registration, de-reference the indexed
value, not the first entry.
Add a MAX_XEN_IDT value for max entries we expect and KASSERT() for
this as a sanity check.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/xen/x86/xenfunc.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/xen/x86/xenfunc.c
diff -u src/sys/arch/xen/x86/xenfunc.c:1.21 src/sys/arch/xen/x86/xenfunc.c:1.22
--- src/sys/arch/xen/x86/xenfunc.c:1.21	Sun Sep 23 15:28:49 2018
+++ src/sys/arch/xen/x86/xenfunc.c	Thu Oct 18 04:17:18 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: xenfunc.c,v 1.21 2018/09/23 15:28:49 cherry Exp $	*/
+/*	$NetBSD: xenfunc.c,v 1.22 2018/10/18 04:17:18 cherry Exp $	*/
 
 /*
  * Copyright (c) 2004 Christian Limpach.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenfunc.c,v 1.21 2018/09/23 15:28:49 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenfunc.c,v 1.22 2018/10/18 04:17:18 cherry Exp $");
 
 #include 
 
@@ -41,6 +41,8 @@ __KERNEL_RCSID(0, "$NetBSD: xenfunc.c,v 
 #include 
 #include 
 
+#define MAX_XEN_IDT 128
+
 void xen_set_ldt(vaddr_t, uint32_t);
 
 void 
@@ -59,7 +61,8 @@ lidt(struct region_descriptor *rd)
 	 * will be available at the boot stage when this is called.
 	 */
 	static char xen_idt_page[PAGE_SIZE] __attribute__((__aligned__ (PAGE_SIZE)));
-
+	memset(xen_idt_page, 0, PAGE_SIZE);
+	
 	struct trap_info *xen_idt = (void * )xen_idt_page;
 	int xen_idt_idx = 0;
 	
@@ -73,9 +76,9 @@ lidt(struct region_descriptor *rd)
 	 * back in the requestor array.
 	 */
 	for (i = 0; i < nidt; i++) {
-		if (idd->address == 0) /* Skip gap */
+		if (idd[i].address == 0) /* Skip gap */
 			continue;
-
+		KASSERT(xen_idt_idx < MAX_XEN_IDT);
 		/* Copy over entry */
 		xen_idt[xen_idt_idx++] = idd[i];
 	}



CVS commit: src/sys/arch/x86/x86

2018-10-17 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Oct 18 04:14:07 UTC 2018

Modified Files:
src/sys/arch/x86/x86: idt.c

Log Message:
Make compile-time type differentiation more explicit.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/x86/x86/idt.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/x86/idt.c
diff -u src/sys/arch/x86/x86/idt.c:1.8 src/sys/arch/x86/x86/idt.c:1.9
--- src/sys/arch/x86/x86/idt.c:1.8	Sun Sep 23 15:28:49 2018
+++ src/sys/arch/x86/x86/idt.c	Thu Oct 18 04:14:07 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: idt.c,v 1.8 2018/09/23 15:28:49 cherry Exp $	*/
+/*	$NetBSD: idt.c,v 1.9 2018/10/18 04:14:07 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2009 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: idt.c,v 1.8 2018/09/23 15:28:49 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: idt.c,v 1.9 2018/10/18 04:14:07 cherry Exp $");
 
 #include 
 #include 
@@ -89,7 +89,7 @@ static char idt_allocmap[NIDT];
 #if defined(XEN)
 
 void
-set_idtgate(idt_descriptor_t *xen_idd, void *function, int ist,
+set_idtgate(struct trap_info *xen_idd, void *function, int ist,
 	int type, int dpl, int sel)
 {
 	/* 
@@ -120,7 +120,7 @@ set_idtgate(idt_descriptor_t *xen_idd, v
 	 * implicitly part of an idt, which we infer as
 	 * xen_idt_vaddr. (See above).
 	 */
-	xen_idd->vector = xen_idd - (idt_descriptor_t *)xen_idt_vaddr;
+	xen_idd->vector = xen_idd - (struct trap_info *)xen_idt_vaddr;
 
 	/* Back to read-only, as it should be. */
 #if defined(__x86_64__)
@@ -129,7 +129,7 @@ set_idtgate(idt_descriptor_t *xen_idd, v
 	//kpreempt_enable();
 }
 void
-unset_idtgate(idt_descriptor_t *xen_idd)
+unset_idtgate(struct trap_info *xen_idd)
 {
 #if defined(__x86_64__)
 	vaddr_t xen_idt_vaddr = ((vaddr_t) xen_idd) & PAGE_MASK;
@@ -148,12 +148,12 @@ unset_idtgate(idt_descriptor_t *xen_idd)
 }
 #else /* XEN */
 void
-set_idtgate(idt_descriptor_t *idd, void *function, int ist, int type, int dpl, int sel)
+set_idtgate(struct gate_descriptor *idd, void *function, int ist, int type, int dpl, int sel)
 {
 	setgate(idd, function, ist, type, dpl,	sel);
 }
 void
-unset_idtgate(idt_descriptor_t *idd)
+unset_idtgate(struct gate_descriptor *idd)
 {
 	unsetgate(idd);
 }



CVS commit: src/sys/arch/i386/i386

2018-10-17 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Oct 18 04:11:14 UTC 2018

Modified Files:
src/sys/arch/i386/i386: cpufunc.S

Log Message:
Whitespace self-police.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/i386/i386/cpufunc.S

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/i386/i386/cpufunc.S
diff -u src/sys/arch/i386/i386/cpufunc.S:1.24 src/sys/arch/i386/i386/cpufunc.S:1.25
--- src/sys/arch/i386/i386/cpufunc.S:1.24	Sun Sep 23 15:28:48 2018
+++ src/sys/arch/i386/i386/cpufunc.S	Thu Oct 18 04:11:14 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.S,v 1.24 2018/09/23 15:28:48 cherry Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.25 2018/10/18 04:11:14 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 #include 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.24 2018/09/23 15:28:48 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.25 2018/10/18 04:11:14 cherry Exp $");
 
 #include "opt_xen.h"
 
@@ -66,7 +66,7 @@ ENTRY(x86_mfence)
 END(x86_mfence)
 
 #ifndef XEN
-	ENTRY(lidt)
+ENTRY(lidt)
 	movl	4(%esp), %eax
 	lidt	(%eax)
 	ret



CVS commit: src/sys/arch/xen/xen

2018-10-16 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Oct 17 03:43:24 UTC 2018

Modified Files:
src/sys/arch/xen/xen: xenevt.c

Log Message:
The known_mpsafe parameter is used by intr.c:intr_establish_xname()
especially in the non -D MULTIPROCESSOR case. We used it incorrectly.

Fix this.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/xen/xen/xenevt.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/xen/xen/xenevt.c
diff -u src/sys/arch/xen/xen/xenevt.c:1.49 src/sys/arch/xen/xen/xenevt.c:1.50
--- src/sys/arch/xen/xen/xenevt.c:1.49	Wed Oct 10 03:54:54 2018
+++ src/sys/arch/xen/xen/xenevt.c	Wed Oct 17 03:43:24 2018
@@ -1,4 +1,4 @@
-/*  $NetBSD: xenevt.c,v 1.49 2018/10/10 03:54:54 cherry Exp $  */
+/*  $NetBSD: xenevt.c,v 1.50 2018/10/17 03:43:24 cherry Exp $  */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenevt.c,v 1.49 2018/10/10 03:54:54 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenevt.c,v 1.50 2018/10/17 03:43:24 cherry Exp $");
 
 #include "opt_xen.h"
 #include 
@@ -163,11 +163,7 @@ xenevtattach(int n)
 {
 	struct intrhand *ih;
 	int level = IPL_HIGH;
-#ifdef MULTIPROCESSOR
 	bool mpsafe = (level != IPL_VM);
-#else
-	bool mpsafe = false;
-#endif /* MULTIPROCESSOR */
 
 	mutex_init(_lock, MUTEX_DEFAULT, IPL_HIGH);
 	STAILQ_INIT(_pending);



CVS commit: src/sys/arch/xen/include

2018-10-09 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Oct 10 04:16:58 UTC 2018

Modified Files:
src/sys/arch/xen/include: xen.h

Log Message:
In  xen_atomic_test_and_clear_bit()

Use the appropriate sized variable for inline assembler.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/xen/include/xen.h

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/xen/include/xen.h
diff -u src/sys/arch/xen/include/xen.h:1.40 src/sys/arch/xen/include/xen.h:1.41
--- src/sys/arch/xen/include/xen.h:1.40	Sun Oct  7 11:25:55 2018
+++ src/sys/arch/xen/include/xen.h	Wed Oct 10 04:16:58 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen.h,v 1.40 2018/10/07 11:25:55 mlelstv Exp $	*/
+/*	$NetBSD: xen.h,v 1.41 2018/10/10 04:16:58 cherry Exp $	*/
 
 /*
  *
@@ -248,7 +248,7 @@ xen_atomic_clearbits_l (volatile XATOMIC
 static __inline XATOMIC_T
 xen_atomic_test_and_clear_bit(volatile void *ptr, unsigned long bitno)
 {
-	int result;
+	long result;
 
 	__asm volatile(__LOCK_PREFIX
 #ifdef __x86_64__



CVS commit: src/sys/arch/xen/xen

2018-10-09 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Oct 10 03:54:54 UTC 2018

Modified Files:
src/sys/arch/xen/xen: xenevt.c

Log Message:
Do not re-expose the innards of evtchn.c, now that we have a way
to register interrupts via intr.c:intr_establish_xname()

evtchn.c is going to get refactored soon, so use the latter method.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/xen/xen/xenevt.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/xen/xen/xenevt.c
diff -u src/sys/arch/xen/xen/xenevt.c:1.48 src/sys/arch/xen/xen/xenevt.c:1.49
--- src/sys/arch/xen/xen/xenevt.c:1.48	Thu Nov 30 20:25:54 2017
+++ src/sys/arch/xen/xen/xenevt.c	Wed Oct 10 03:54:54 2018
@@ -1,4 +1,4 @@
-/*  $NetBSD: xenevt.c,v 1.48 2017/11/30 20:25:54 christos Exp $  */
+/*  $NetBSD: xenevt.c,v 1.49 2018/10/10 03:54:54 cherry Exp $  */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xenevt.c,v 1.48 2017/11/30 20:25:54 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenevt.c,v 1.49 2018/10/10 03:54:54 cherry Exp $");
 
 #include "opt_xen.h"
 #include 
@@ -145,15 +145,28 @@ long xenevt_ev1;
 long xenevt_ev2[NR_EVENT_CHANNELS];
 static int xenevt_processevt(void *);
 
+static evtchn_port_t xenevt_alloc_event(void)
+{
+	evtchn_op_t op;
+	op.cmd = EVTCHNOP_alloc_unbound;
+	op.u.alloc_unbound.dom = DOMID_SELF;
+	op.u.alloc_unbound.remote_dom = DOMID_SELF;
+	if (HYPERVISOR_event_channel_op() != 0)
+		panic("%s: Failed to allocate loopback event\n", __func__);	
+
+	return op.u.alloc_unbound.port;
+}
+
 /* called at boot time */
 void
 xenevtattach(int n)
 {
 	struct intrhand *ih;
-	int s;
 	int level = IPL_HIGH;
 #ifdef MULTIPROCESSOR
 	bool mpsafe = (level != IPL_VM);
+#else
+	bool mpsafe = false;
 #endif /* MULTIPROCESSOR */
 
 	mutex_init(_lock, MUTEX_DEFAULT, IPL_HIGH);
@@ -165,26 +178,19 @@ xenevtattach(int n)
 	xenevt_ev1 = 0;
 	memset(xenevt_ev2, 0, sizeof(xenevt_ev2));
 
-	/* register a handler at splhigh, so that spllower() will call us */
-	ih = malloc(sizeof (struct intrhand), M_DEVBUF,
-	 M_WAITOK|M_ZERO);
-	if (ih == NULL)
-		panic("can't allocate xenevt interrupt source");
-	ih->ih_level = level;
-	ih->ih_fun = ih->ih_realfun = xenevt_processevt;
-	ih->ih_arg = ih->ih_realarg = NULL;
-	ih->ih_next = NULL;
-	ih->ih_cpu = _info_primary;
-#ifdef MULTIPROCESSOR
-	if (!mpsafe) {
-		ih->ih_fun = xen_intr_biglock_wrapper;
-		ih->ih_arg = ih;
-	}
-#endif /* MULTIPROCESSOR */
+	/*
+	 * Allocate a loopback event port.
+	 * This helps us massage xenevt_processevt() into the
+	 * callchain at the appropriate level using only
+	 * intr_establish_xname().
+	 */
+	evtchn_port_t evtchn = xenevt_alloc_event();
+
+	/* The real objective here is to wiggle into the ih callchain for IPL level */
+	ih = intr_establish_xname(0, _pic, evtchn,  IST_LEVEL, level,
+	xenevt_processevt, NULL, mpsafe, "xenevt");
 
-	s = splhigh();
-	event_set_iplhandler(ih->ih_cpu, ih, level);
-	splx(s);
+	KASSERT(ih != NULL);
 }
 
 /* register pending event - always called with interrupt disabled */



CVS commit: src/sys/arch/xen

2018-10-09 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Oct 10 02:34:08 UTC 2018

Modified Files:
src/sys/arch/xen/include: intr.h
src/sys/arch/xen/x86: pintr.c

Log Message:
Do not export the 'irq<->vector' abstraction outside of pintr.c
anymore. We now think of them as a unified thing called 'gsi',
which is generated by mpacpi/mpbios


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/xen/x86/pintr.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/xen/include/intr.h
diff -u src/sys/arch/xen/include/intr.h:1.48 src/sys/arch/xen/include/intr.h:1.49
--- src/sys/arch/xen/include/intr.h:1.48	Sun Oct  7 05:23:01 2018
+++ src/sys/arch/xen/include/intr.h	Wed Oct 10 02:34:08 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.48 2018/10/07 05:23:01 cherry Exp $	*/
+/*	$NetBSD: intr.h,v 1.49 2018/10/10 02:34:08 cherry Exp $	*/
 /*	NetBSD intr.h,v 1.15 2004/10/31 10:39:34 yamt Exp	*/
 
 /*-
@@ -62,8 +62,6 @@ struct evtsource {
 };
 
 extern struct intrstub xenev_stubs[];
-extern int irq2vect[256];
-extern int vect2irq[256];
 extern int irq2port[NR_EVENT_CHANNELS]; /* actually port + 1, so that 0 is invaid */
 
 #ifdef MULTIPROCESSOR

Index: src/sys/arch/xen/x86/pintr.c
diff -u src/sys/arch/xen/x86/pintr.c:1.8 src/sys/arch/xen/x86/pintr.c:1.9
--- src/sys/arch/xen/x86/pintr.c:1.8	Wed Oct 10 02:16:34 2018
+++ src/sys/arch/xen/x86/pintr.c	Wed Oct 10 02:34:08 2018
@@ -103,7 +103,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.8 2018/10/10 02:16:34 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.9 2018/10/10 02:34:08 cherry Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -143,8 +143,8 @@ struct intrstub x2apic_edge_stubs[MAX_IN
 struct intrstub x2apic_level_stubs[MAX_INTR_SOURCES] = {{0,0}};
 #include 
 int irq2port[NR_EVENT_CHANNELS] = {0}; /* actually port + 1, so that 0 is invaid */
-int irq2vect[256] = {0};
-int vect2irq[256] = {0};
+static int irq2vect[256] = {0};
+static int vect2irq[256] = {0};
 #endif /* NIOAPIC */
 #if NACPICA > 0
 #include 



CVS commit: src/sys/arch/xen/x86

2018-10-09 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Oct 10 02:16:34 UTC 2018

Modified Files:
src/sys/arch/xen/x86: pintr.c

Log Message:
Since GSIs are invented by the mpbios/mpacpi interrupt routing probe code,
it's possible for shared GSIs to popup even outside the original
legacy_irq range.

Relax this latter, older assumption.

Thanks to Brad Spencer for extensive trialing on interesting hardware.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/xen/x86/pintr.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/xen/x86/pintr.c
diff -u src/sys/arch/xen/x86/pintr.c:1.7 src/sys/arch/xen/x86/pintr.c:1.8
--- src/sys/arch/xen/x86/pintr.c:1.7	Sun Oct  7 05:23:01 2018
+++ src/sys/arch/xen/x86/pintr.c	Wed Oct 10 02:16:34 2018
@@ -103,7 +103,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.7 2018/10/07 05:23:01 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.8 2018/10/10 02:16:34 cherry Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -176,8 +176,7 @@ xen_vec_alloc(int gsi)
 			irq2vect[gsi] == op.u.irq_op.vector);
 		irq2vect[gsi] = op.u.irq_op.vector;
 		KASSERT(vect2irq[op.u.irq_op.vector] == 0 ||
-			(gsi > 0 && gsi < 16 &&
-			 vect2irq[op.u.irq_op.vector] == gsi));
+			 vect2irq[op.u.irq_op.vector] == gsi);
 		vect2irq[op.u.irq_op.vector] = gsi;
 	}
 



CVS commit: src/sys/arch/x86/x86

2018-10-08 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Oct  8 08:05:08 UTC 2018

Modified Files:
src/sys/arch/x86/x86: i8259.c intr.c ioapic.c

Log Message:
Clean up XEN specific stuff from the apic code, and move to intr.c

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/x86/x86/i8259.c
cvs rdiff -u -r1.133 -r1.134 src/sys/arch/x86/x86/intr.c
cvs rdiff -u -r1.58 -r1.59 src/sys/arch/x86/x86/ioapic.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/x86/i8259.c
diff -u src/sys/arch/x86/x86/i8259.c:1.20 src/sys/arch/x86/x86/i8259.c:1.21
--- src/sys/arch/x86/x86/i8259.c:1.20	Sun Oct  7 16:36:36 2018
+++ src/sys/arch/x86/x86/i8259.c	Mon Oct  8 08:05:08 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: i8259.c,v 1.20 2018/10/07 16:36:36 cherry Exp $	*/
+/*	$NetBSD: i8259.c,v 1.21 2018/10/08 08:05:08 cherry Exp $	*/
 
 /*
  * Copyright 2002 (c) Wasabi Systems, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i8259.c,v 1.20 2018/10/07 16:36:36 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i8259.c,v 1.21 2018/10/08 08:05:08 cherry Exp $");
 
 #include  
 #include 
@@ -88,9 +88,6 @@ __KERNEL_RCSID(0, "$NetBSD: i8259.c,v 1.
 #include 
 #include 
 
-#ifdef XEN
-#include 
-#endif
 
 #ifndef __x86_64__
 #include "mca.h"
@@ -102,7 +99,6 @@ __KERNEL_RCSID(0, "$NetBSD: i8259.c,v 1.
 static void i8259_hwmask(struct pic *, int);
 static void i8259_hwunmask(struct pic *, int);
 static void i8259_setup(struct pic *, struct cpu_info *, int, int, int);
-static void i8259_unsetup(struct pic *, struct cpu_info *, int, int, int);
 static void i8259_reinit_irqs(void);
 
 unsigned i8259_imen;
@@ -119,7 +115,7 @@ struct pic i8259_pic = {
 	.pic_hwmask = i8259_hwmask,
 	.pic_hwunmask = i8259_hwunmask,
 	.pic_addroute = i8259_setup,
-	.pic_delroute = i8259_unsetup,
+	.pic_delroute = i8259_setup,
 	.pic_level_stubs = legacy_stubs,
 	.pic_edge_stubs = legacy_stubs,
 };
@@ -256,62 +252,10 @@ static void
 i8259_setup(struct pic *pic, struct cpu_info *ci,
 int pin, int idtvec, int type)
 {
-#if defined(XEN)
-	/*
-	 * This is kludgy, and not the right place, but we can't bind
-	 * before the routing has been set to the appropriate 'vector'.
-	 * in x86/intr.c, this is done after idt_vec_set(), where this
-	 * would have been more appropriate to put this.
-	 */
-
-	int port, irq;
-	irq = vect2irq[idtvec];
-	KASSERT(irq != 0);
-	if (irq2port[irq] != 0) {
-		/* 
-		 * Shared interrupt - we can't rebind.
-		 *  The port is shared instead.
-		 */
-		return;
-	}
-	
-	port = bind_pirq_to_evtch(irq);
-	KASSERT(port < NR_EVENT_CHANNELS);
-	KASSERT(port >= 0);
-
-	KASSERT(irq2port[irq] == 0);
-	irq2port[irq] = port + 1;
-
-	xen_atomic_set_bit(>ci_evtmask[0], port);
-#else
 	if (CPU_IS_PRIMARY(ci))
 		i8259_reinit_irqs();
-#endif
 }
 
-static void
-i8259_unsetup(struct pic *pic, struct cpu_info *ci,
-int pin, int idtvec, int type)
-{
-#if defined(XEN)
-	int port, irq;
-	irq = vect2irq[idtvec];
-	port = unbind_pirq_from_evtch(irq);
-
-	KASSERT(port < NR_EVENT_CHANNELS);
-
-	/* XXX: This is problematic for shared interrupts */
-	KASSERT(irq2port[irq] != 0);
-	irq2port[irq] = 0;
-
-	xen_atomic_clear_bit(>ci_evtmask[0], port);
-#else
-	if (CPU_IS_PRIMARY(ci))
-		i8259_reinit_irqs();
-#endif
-}
-
-
 void
 i8259_reinit(void)
 {

Index: src/sys/arch/x86/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.133 src/sys/arch/x86/x86/intr.c:1.134
--- src/sys/arch/x86/x86/intr.c:1.133	Sun Oct  7 05:23:01 2018
+++ src/sys/arch/x86/x86/intr.c	Mon Oct  8 08:05:08 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.133 2018/10/07 05:23:01 cherry Exp $	*/
+/*	$NetBSD: intr.c,v 1.134 2018/10/08 08:05:08 cherry Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.133 2018/10/07 05:23:01 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.134 2018/10/08 08:05:08 cherry Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -1278,12 +1278,24 @@ intr_establish_xname(int legacy_irq, str
 
 	vector = xen_vec_alloc(gsi);
 
-	extern struct cpu_info phycpu_info_primary; /* XXX */
-	struct cpu_info *ci = _info_primary;
-	pic->pic_addroute(pic, ci, pin, vector, type);
-
-	evtchn = irq2port[vect2irq[vector]];
-	KASSERT(evtchn > 0);
+	if (irq2port[gsi] == 0) {
+		extern struct cpu_info phycpu_info_primary; /* XXX */
+		struct cpu_info *ci = _info_primary;
+
+		pic->pic_addroute(pic, ci, pin, vector, type);
+
+		evtchn = bind_pirq_to_evtch(gsi);
+		KASSERT(evtchn > 0);
+		KASSERT(evtchn < NR_EVENT_CHANNELS);
+		irq2port[gsi] = evtchn + 1;
+		xen_atomic_set_bit(>ci_evtmask[0], evtchn);
+	} else {
+		/*
+		 * Shared interrupt - we can't rebind.
+		 * The port is shared instead.
+		 */
+		evtchn = irq2port[gsi];
+	}
 
 	pih = pirq_establish(gsi, evtchn, handler, arg, level,
 			 intrstr, 

CVS commit: src/sys/arch/xen/xen

2018-10-07 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Oct  8 05:42:45 UTC 2018

Modified Files:
src/sys/arch/xen/xen: pciback.c xpci_xenbus.c

Log Message:
Convert the last remaining users of event_set_handler() to
intr_establish_xname(,_pic,...)


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/xen/xen/pciback.c
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/xen/xen/xpci_xenbus.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/xen/xen/pciback.c
diff -u src/sys/arch/xen/xen/pciback.c:1.14 src/sys/arch/xen/xen/pciback.c:1.15
--- src/sys/arch/xen/xen/pciback.c:1.14	Sun Jun 24 20:15:00 2018
+++ src/sys/arch/xen/xen/pciback.c	Mon Oct  8 05:42:44 2018
@@ -1,4 +1,4 @@
-/*  $NetBSD: pciback.c,v 1.14 2018/06/24 20:15:00 jdolecek Exp $  */
+/*  $NetBSD: pciback.c,v 1.15 2018/10/08 05:42:44 cherry Exp $  */
 
 /*
  * Copyright (c) 2009 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pciback.c,v 1.14 2018/06/24 20:15:00 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pciback.c,v 1.15 2018/10/08 05:42:44 cherry Exp $");
 
 #include "opt_xen.h"
 
@@ -188,6 +188,7 @@ struct pb_xenbus_instance {
 	struct pciback_pci_devlist pbx_pb_pci_dev; /* list of exported PCI devices */
 	/* communication with the domU */
 unsigned int pbx_evtchn; /* our even channel */
+	struct intrhand *pbx_ih;
 struct xen_pci_sharedinfo *pbx_sh_info;
 struct xen_pci_op op;
 grant_handle_t pbx_shinfo_handle; /* to unmap shared page */
@@ -524,9 +525,7 @@ pciback_xenbus_destroy(void *arg)
 	int err;
 
 	hypervisor_mask_event(pbxi->pbx_evtchn);
-	event_remove_handler(pbxi->pbx_evtchn,
-	pciback_xenbus_evthandler, pbxi);
-
+	intr_disestablish(pbxi->pbx_ih);
 	mutex_enter(_xenbus_lock);
 	SLIST_REMOVE(_xenbus_instances,
 	pbxi, pb_xenbus_instance, pbx_next);
@@ -620,8 +619,9 @@ pciback_xenbus_frontend_changed(void *ar
 		x86_sfence();
 		xenbus_switch_state(xbusd, NULL, XenbusStateConnected);
 		x86_sfence();
-		event_set_handler(pbxi->pbx_evtchn, pciback_xenbus_evthandler,
-		pbxi, IPL_BIO, "pciback", "pciback"); // XXX intr info?
+		pbxi->pbx_ih = intr_establish_xname(0, _pic, pbxi->pbx_evtchn, IST_LEVEL, IPL_BIO,
+		pciback_xenbus_evthandler, pbxi, true, "pciback");
+		KASSERT(pbxi->pbx_ih != NULL);
 		hypervisor_enable_event(pbxi->pbx_evtchn);
 		hypervisor_notify_via_evtchn(pbxi->pbx_evtchn);
 		break;

Index: src/sys/arch/xen/xen/xpci_xenbus.c
diff -u src/sys/arch/xen/xen/xpci_xenbus.c:1.18 src/sys/arch/xen/xen/xpci_xenbus.c:1.19
--- src/sys/arch/xen/xen/xpci_xenbus.c:1.18	Sun Aug 19 01:33:26 2018
+++ src/sys/arch/xen/xen/xpci_xenbus.c	Mon Oct  8 05:42:45 2018
@@ -1,4 +1,4 @@
-/*  $NetBSD: xpci_xenbus.c,v 1.18 2018/08/19 01:33:26 riastradh Exp $  */
+/*  $NetBSD: xpci_xenbus.c,v 1.19 2018/10/08 05:42:45 cherry Exp $  */
 
 /*
  * Copyright (c) 2009 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xpci_xenbus.c,v 1.18 2018/08/19 01:33:26 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xpci_xenbus.c,v 1.19 2018/10/08 05:42:45 cherry Exp $");
 
 #include "opt_xen.h"
 
@@ -188,8 +188,9 @@ xpci_xenbus_resume(void *p)
 	aprint_verbose_dev(sc->sc_dev, "using event channel %d\n",
 	sc->sc_evtchn);
 #if 0
-	event_set_handler(sc->sc_evtchn, _handler, sc,
-	IPL_BIO, device_xname(sc->sc_dev));
+	intr_establish_xname(0, _pic, pbxi->pbx_evtchn, IST_LEVEL,
+	IPL_BIO, _handler, sc, true,
+	device_xname(sc->sc_dev));
 #endif
 
 again:



CVS commit: src/sys/arch/x86/x86

2018-10-07 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Oct  7 16:36:36 UTC 2018

Modified Files:
src/sys/arch/x86/x86: i8259.c ioapic.c

Log Message:
In the case of a shared GSI, bind will fail, so we do not attempt this.
The sharing is accomplished by demultiplexing the port event of the first
bind. This is accomplished in intr.c:intr_establish_xname()

Note that the pic_delroute() is buggy (commented suitably) for the shared
gsi case, since it will unbind reset it unconditionally, leaving the other
shared callbacks stranded.

This problem will go awaywhen we unify further with native code, as this
case is taken care of appropriately in that case.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/x86/x86/i8259.c
cvs rdiff -u -r1.57 -r1.58 src/sys/arch/x86/x86/ioapic.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/x86/i8259.c
diff -u src/sys/arch/x86/x86/i8259.c:1.19 src/sys/arch/x86/x86/i8259.c:1.20
--- src/sys/arch/x86/x86/i8259.c:1.19	Sun Oct  7 05:28:51 2018
+++ src/sys/arch/x86/x86/i8259.c	Sun Oct  7 16:36:36 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: i8259.c,v 1.19 2018/10/07 05:28:51 cherry Exp $	*/
+/*	$NetBSD: i8259.c,v 1.20 2018/10/07 16:36:36 cherry Exp $	*/
 
 /*
  * Copyright 2002 (c) Wasabi Systems, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i8259.c,v 1.19 2018/10/07 05:28:51 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i8259.c,v 1.20 2018/10/07 16:36:36 cherry Exp $");
 
 #include  
 #include 
@@ -267,6 +267,14 @@ i8259_setup(struct pic *pic, struct cpu_
 	int port, irq;
 	irq = vect2irq[idtvec];
 	KASSERT(irq != 0);
+	if (irq2port[irq] != 0) {
+		/* 
+		 * Shared interrupt - we can't rebind.
+		 *  The port is shared instead.
+		 */
+		return;
+	}
+	
 	port = bind_pirq_to_evtch(irq);
 	KASSERT(port < NR_EVENT_CHANNELS);
 	KASSERT(port >= 0);
@@ -292,6 +300,7 @@ i8259_unsetup(struct pic *pic, struct cp
 
 	KASSERT(port < NR_EVENT_CHANNELS);
 
+	/* XXX: This is problematic for shared interrupts */
 	KASSERT(irq2port[irq] != 0);
 	irq2port[irq] = 0;
 

Index: src/sys/arch/x86/x86/ioapic.c
diff -u src/sys/arch/x86/x86/ioapic.c:1.57 src/sys/arch/x86/x86/ioapic.c:1.58
--- src/sys/arch/x86/x86/ioapic.c:1.57	Sun Oct  7 05:28:51 2018
+++ src/sys/arch/x86/x86/ioapic.c	Sun Oct  7 16:36:36 2018
@@ -1,4 +1,4 @@
-/* 	$NetBSD: ioapic.c,v 1.57 2018/10/07 05:28:51 cherry Exp $	*/
+/* 	$NetBSD: ioapic.c,v 1.58 2018/10/07 16:36:36 cherry Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2009 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ioapic.c,v 1.57 2018/10/07 05:28:51 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ioapic.c,v 1.58 2018/10/07 16:36:36 cherry Exp $");
 
 #include "opt_ddb.h"
 
@@ -576,6 +576,15 @@ ioapic_addroute(struct pic *pic, struct 
 	int port, irq;
 	irq = vect2irq[idtvec];
 	KASSERT(irq != 0);
+
+	if (irq2port[irq] != 0) {
+		/* 
+		 * Shared interrupt - we can't rebind.
+		 *  The port is shared instead.
+		 */
+		return;
+	}
+
 	port = bind_pirq_to_evtch(irq);
 	KASSERT(port < NR_EVENT_CHANNELS);
 	KASSERT(port >= 0);
@@ -602,6 +611,7 @@ ioapic_delroute(struct pic *pic, struct 
 
 	KASSERT(port < NR_EVENT_CHANNELS);
 
+	/* XXX: This is problematic for shared interrupts */
 	KASSERT(irq2port[irq] != 0);
 	irq2port[irq] = 0;
 



CVS commit: src/sys/arch/x86/x86

2018-10-06 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Oct  7 05:28:51 UTC 2018

Modified Files:
src/sys/arch/x86/x86: i8259.c ioapic.c

Log Message:
While we're here, fix pic->pic_delroute() to DTRT on XEN and
cleanup after itself.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/x86/x86/i8259.c
cvs rdiff -u -r1.56 -r1.57 src/sys/arch/x86/x86/ioapic.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/x86/i8259.c
diff -u src/sys/arch/x86/x86/i8259.c:1.18 src/sys/arch/x86/x86/i8259.c:1.19
--- src/sys/arch/x86/x86/i8259.c:1.18	Sun Oct  7 05:23:01 2018
+++ src/sys/arch/x86/x86/i8259.c	Sun Oct  7 05:28:51 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: i8259.c,v 1.18 2018/10/07 05:23:01 cherry Exp $	*/
+/*	$NetBSD: i8259.c,v 1.19 2018/10/07 05:28:51 cherry Exp $	*/
 
 /*
  * Copyright 2002 (c) Wasabi Systems, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i8259.c,v 1.18 2018/10/07 05:23:01 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i8259.c,v 1.19 2018/10/07 05:28:51 cherry Exp $");
 
 #include  
 #include 
@@ -291,6 +291,11 @@ i8259_unsetup(struct pic *pic, struct cp
 	port = unbind_pirq_from_evtch(irq);
 
 	KASSERT(port < NR_EVENT_CHANNELS);
+
+	KASSERT(irq2port[irq] != 0);
+	irq2port[irq] = 0;
+
+	xen_atomic_clear_bit(>ci_evtmask[0], port);
 #else
 	if (CPU_IS_PRIMARY(ci))
 		i8259_reinit_irqs();

Index: src/sys/arch/x86/x86/ioapic.c
diff -u src/sys/arch/x86/x86/ioapic.c:1.56 src/sys/arch/x86/x86/ioapic.c:1.57
--- src/sys/arch/x86/x86/ioapic.c:1.56	Wed Dec 13 16:30:18 2017
+++ src/sys/arch/x86/x86/ioapic.c	Sun Oct  7 05:28:51 2018
@@ -1,4 +1,4 @@
-/* 	$NetBSD: ioapic.c,v 1.56 2017/12/13 16:30:18 bouyer Exp $	*/
+/* 	$NetBSD: ioapic.c,v 1.57 2018/10/07 05:28:51 cherry Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2009 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ioapic.c,v 1.56 2017/12/13 16:30:18 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ioapic.c,v 1.57 2018/10/07 05:28:51 cherry Exp $");
 
 #include "opt_ddb.h"
 
@@ -601,6 +601,12 @@ ioapic_delroute(struct pic *pic, struct 
 	port = unbind_pirq_from_evtch(irq);
 
 	KASSERT(port < NR_EVENT_CHANNELS);
+
+	KASSERT(irq2port[irq] != 0);
+	irq2port[irq] = 0;
+
+	xen_atomic_clear_bit(>ci_evtmask[0], port);
+
 #endif
 
 }



CVS commit: src/sys/arch

2018-10-06 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Oct  7 05:23:01 UTC 2018

Modified Files:
src/sys/arch/x86/x86: i8259.c intr.c
src/sys/arch/xen/include: intr.h
src/sys/arch/xen/x86: pintr.c

Log Message:
Switch over to a "GSI" concept for guest irqs.

On XEN there is a namespace called GSI which includes:

i) legacy_irq (0 - 16)
ii) "gsi" (16-nr_irqs_gsi)
iii) msi

We try to mirror this in guest space, but are mindful that legacy_irq
is 1:1 bound to actual hardware legacy_irq. Apart from this, XEN doesn't
really care what number scheme we use, as long as it doesn't encroach
on the MSI space, which is TBD for us.

Thus we trust the mpbios.c/mpacpi.c code to correctly map the pic,pin
tuples into the correct global gsi space, which we then register with
xen. As we now do, we allow for duplicate gsi registrations, in case
any hardware shares the same (pic,pin);

This enables us to now use the (pic,pin) tuple as the canonical reference
for device interrupt addresses, and leave any global mappings to specific
code. Thus xen_pic_to_gsi().

Note that this requires separate support for MSI, which I will get around to
once things stabilise - however the API change facilitates this nicely.

I note that the msi addroute() function does not use the "pin" parameter.
This can be made use of, to encode the gsi number, for XEN. This is however
TBD.

We further tweak the xen_vec_alloc() code to be uniform for the NIOAPICS
and other cases, and ensure that i8259.c DTRT wrt to route().

This will allow us to use pic->pic_addroute() without needing to worry about
pic specific issues.

The next step is to consolidate the pic_addroute() XEN related #ifdefs into
a -DXEN specific file, so that we don't clutter x86/ code with #ifdef XENs.

This change has functional implications, and there is likely breakage coming
especially on bespoke platforms that I haven't been able to test yet.

I am especially interested in bug reports from platforms with legacy (esp. i386)
and with multiple ioapics.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/x86/x86/i8259.c
cvs rdiff -u -r1.132 -r1.133 src/sys/arch/x86/x86/intr.c
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/xen/x86/pintr.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/x86/i8259.c
diff -u src/sys/arch/x86/x86/i8259.c:1.17 src/sys/arch/x86/x86/i8259.c:1.18
--- src/sys/arch/x86/x86/i8259.c:1.17	Sat Feb 17 18:51:53 2018
+++ src/sys/arch/x86/x86/i8259.c	Sun Oct  7 05:23:01 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: i8259.c,v 1.17 2018/02/17 18:51:53 maxv Exp $	*/
+/*	$NetBSD: i8259.c,v 1.18 2018/10/07 05:23:01 cherry Exp $	*/
 
 /*
  * Copyright 2002 (c) Wasabi Systems, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i8259.c,v 1.17 2018/02/17 18:51:53 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i8259.c,v 1.18 2018/10/07 05:23:01 cherry Exp $");
 
 #include  
 #include 
@@ -88,6 +88,9 @@ __KERNEL_RCSID(0, "$NetBSD: i8259.c,v 1.
 #include 
 #include 
 
+#ifdef XEN
+#include 
+#endif
 
 #ifndef __x86_64__
 #include "mca.h"
@@ -99,6 +102,7 @@ __KERNEL_RCSID(0, "$NetBSD: i8259.c,v 1.
 static void i8259_hwmask(struct pic *, int);
 static void i8259_hwunmask(struct pic *, int);
 static void i8259_setup(struct pic *, struct cpu_info *, int, int, int);
+static void i8259_unsetup(struct pic *, struct cpu_info *, int, int, int);
 static void i8259_reinit_irqs(void);
 
 unsigned i8259_imen;
@@ -115,7 +119,7 @@ struct pic i8259_pic = {
 	.pic_hwmask = i8259_hwmask,
 	.pic_hwunmask = i8259_hwunmask,
 	.pic_addroute = i8259_setup,
-	.pic_delroute = i8259_setup,
+	.pic_delroute = i8259_unsetup,
 	.pic_level_stubs = legacy_stubs,
 	.pic_edge_stubs = legacy_stubs,
 };
@@ -252,10 +256,48 @@ static void
 i8259_setup(struct pic *pic, struct cpu_info *ci,
 int pin, int idtvec, int type)
 {
+#if defined(XEN)
+	/*
+	 * This is kludgy, and not the right place, but we can't bind
+	 * before the routing has been set to the appropriate 'vector'.
+	 * in x86/intr.c, this is done after idt_vec_set(), where this
+	 * would have been more appropriate to put this.
+	 */
+
+	int port, irq;
+	irq = vect2irq[idtvec];
+	KASSERT(irq != 0);
+	port = bind_pirq_to_evtch(irq);
+	KASSERT(port < NR_EVENT_CHANNELS);
+	KASSERT(port >= 0);
+
+	KASSERT(irq2port[irq] == 0);
+	irq2port[irq] = port + 1;
+
+	xen_atomic_set_bit(>ci_evtmask[0], port);
+#else
+	if (CPU_IS_PRIMARY(ci))
+		i8259_reinit_irqs();
+#endif
+}
+
+static void
+i8259_unsetup(struct pic *pic, struct cpu_info *ci,
+int pin, int idtvec, int type)
+{
+#if defined(XEN)
+	int port, irq;
+	irq = vect2irq[idtvec];
+	port = unbind_pirq_from_evtch(irq);
+
+	KASSERT(port < NR_EVENT_CHANNELS);
+#else
 	if (CPU_IS_PRIMARY(ci))
 		i8259_reinit_irqs();
+#endif
 }
 
+
 void
 i8259_reinit(void)
 {

Index: src/sys/arch/x86/x86/intr.c
diff -u 

CVS commit: src/sys/arch

2018-10-06 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Oct  6 16:49:54 UTC 2018

Modified Files:
src/sys/arch/x86/x86: intr.c
src/sys/arch/xen/include: intr.h
src/sys/arch/xen/x86: pintr.c

Log Message:
Change the name of xen_pirq_alloc() to xen_vec_alloc() to reflect
its actual job.

The idea is that we will strip this down until it is as close to
idt_vec_alloc() as possible.


To generate a diff of this commit:
cvs rdiff -u -r1.131 -r1.132 src/sys/arch/x86/x86/intr.c
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/xen/x86/pintr.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/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.131 src/sys/arch/x86/x86/intr.c:1.132
--- src/sys/arch/x86/x86/intr.c:1.131	Sat Oct  6 16:44:55 2018
+++ src/sys/arch/x86/x86/intr.c	Sat Oct  6 16:49:54 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.131 2018/10/06 16:44:55 cherry Exp $	*/
+/*	$NetBSD: intr.c,v 1.132 2018/10/06 16:49:54 cherry Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.131 2018/10/06 16:44:55 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.132 2018/10/06 16:49:54 cherry Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -1290,7 +1290,8 @@ intr_establish_xname(int legacy_irq, str
 	intrstr = intr_create_intrid(irq, pic, pin, intrstr_buf,
 	sizeof(intrstr_buf));
 
-	vector = xen_pirq_alloc(, type);
+	vector = xen_vec_alloc(irq);
+	irq = vect2irq[vector];
 	irq = (legacy_irq == -1) ? irq : legacy_irq; /* ISA compat */
 
 #if NIOAPIC > 0

Index: src/sys/arch/xen/include/intr.h
diff -u src/sys/arch/xen/include/intr.h:1.46 src/sys/arch/xen/include/intr.h:1.47
--- src/sys/arch/xen/include/intr.h:1.46	Sun Jun 24 13:35:32 2018
+++ src/sys/arch/xen/include/intr.h	Sat Oct  6 16:49:54 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.46 2018/06/24 13:35:32 jdolecek Exp $	*/
+/*	$NetBSD: intr.h,v 1.47 2018/10/06 16:49:54 cherry Exp $	*/
 /*	NetBSD intr.h,v 1.15 2004/10/31 10:39:34 yamt Exp	*/
 
 /*-
@@ -71,7 +71,7 @@ int xen_intr_biglock_wrapper(void *);
 #endif
 
 #if defined(DOM0OPS) || NPCI > 0
-int xen_pirq_alloc(intr_handle_t *, int);
+int xen_vec_alloc(intr_handle_t);
 #endif /* defined(DOM0OPS) || NPCI > 0 */
 
 #ifdef MULTIPROCESSOR

Index: src/sys/arch/xen/x86/pintr.c
diff -u src/sys/arch/xen/x86/pintr.c:1.5 src/sys/arch/xen/x86/pintr.c:1.6
--- src/sys/arch/xen/x86/pintr.c:1.5	Sat Oct  6 16:44:55 2018
+++ src/sys/arch/xen/x86/pintr.c	Sat Oct  6 16:49:54 2018
@@ -103,7 +103,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.5 2018/10/06 16:44:55 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.6 2018/10/06 16:49:54 cherry Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -160,10 +160,10 @@ int vect2irq[256] = {0};
 
 #if defined(DOM0OPS) || NPCI > 0
 int
-xen_pirq_alloc(intr_handle_t *pirq, int type)
+xen_vec_alloc(intr_handle_t pirq)
 {
 	physdev_op_t op;
-	int irq = *pirq;
+	int irq = pirq;
 #if NIOAPIC > 0
 
 	/*
@@ -178,14 +178,14 @@ xen_pirq_alloc(intr_handle_t *pirq, int 
 	 * or none is available.
 	 */
 	static int xen_next_irq = 200;
-	struct ioapic_softc *ioapic = ioapic_find(APIC_IRQ_APIC(*pirq));
-	int pin = APIC_IRQ_PIN(*pirq);
+	struct ioapic_softc *ioapic = ioapic_find(APIC_IRQ_APIC(pirq));
+	int pin = APIC_IRQ_PIN(pirq);
 
-	if (*pirq & APIC_INT_VIA_APIC) {
+	if (pirq & APIC_INT_VIA_APIC) {
 		irq = vect2irq[ioapic->sc_pins[pin].ip_vector];
 		if (ioapic->sc_pins[pin].ip_vector == 0 || irq == 0) {
 			/* allocate IRQ */
-			irq = APIC_IRQ_LEGACY_IRQ(*pirq);
+			irq = APIC_IRQ_LEGACY_IRQ(pirq);
 			if (irq <= 0 || irq > 15)
 irq = xen_next_irq--;
 retry:
@@ -207,8 +207,6 @@ retry:
  vect2irq[op.u.irq_op.vector] == irq));
 			vect2irq[op.u.irq_op.vector] = irq;
 		}
-		*pirq &= ~0xff;
-		*pirq |= irq;
 	} else
 #endif /* NIOAPIC */
 	{



CVS commit: src/sys/arch

2018-10-06 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Oct  6 16:44:55 UTC 2018

Modified Files:
src/sys/arch/x86/x86: intr.c
src/sys/arch/xen/x86: pintr.c

Log Message:
Move the pic->pic_addroute() call from within pintr.c:xen_pirq_alloc() to
intr.c:intr_establish_xname()

xen_pirq_alloc() now returns a vector value, as is intended by
the semantics of the call to the hypervisor, PHYSDEVOP_ASSIGN_VECTOR.

This also brings our usage closer to native.


To generate a diff of this commit:
cvs rdiff -u -r1.130 -r1.131 src/sys/arch/x86/x86/intr.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/xen/x86/pintr.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/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.130 src/sys/arch/x86/x86/intr.c:1.131
--- src/sys/arch/x86/x86/intr.c:1.130	Thu Sep 20 05:08:45 2018
+++ src/sys/arch/x86/x86/intr.c	Sat Oct  6 16:44:55 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.130 2018/09/20 05:08:45 cherry Exp $	*/
+/*	$NetBSD: intr.c,v 1.131 2018/10/06 16:44:55 cherry Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.130 2018/09/20 05:08:45 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.131 2018/10/06 16:44:55 cherry Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -1264,7 +1264,7 @@ intr_establish_xname(int legacy_irq, str
 #if NPCI > 0 || NISA > 0
 	struct pintrhand *pih;
 	intr_handle_t irq;
-	int evtchn;
+	int vector, evtchn;
 
 	KASSERTMSG(legacy_irq == -1 || (0 <= legacy_irq && legacy_irq < NUM_XEN_IRQS),
 	"bad legacy IRQ value: %d", legacy_irq);
@@ -1290,10 +1290,21 @@ intr_establish_xname(int legacy_irq, str
 	intrstr = intr_create_intrid(irq, pic, pin, intrstr_buf,
 	sizeof(intrstr_buf));
 
-	evtchn = xen_pirq_alloc(, type);
-	irq = (legacy_irq == -1) ? irq : legacy_irq; /* ISA compat */	
+	vector = xen_pirq_alloc(, type);
+	irq = (legacy_irq == -1) ? irq : legacy_irq; /* ISA compat */
+
+#if NIOAPIC > 0
+	extern struct cpu_info phycpu_info_primary; /* XXX */
+	struct cpu_info *ci = _info_primary;
+	pic->pic_addroute(pic, ci, pin, vector, type);
+#else
+
+#endif /* NIOAPIC */
+	evtchn = irq2port[vect2irq[vector]];
+	KASSERT(evtchn > 0);
+
 	pih = pirq_establish(irq & 0xff, evtchn, handler, arg, level,
-	intrstr, xname);
+			 intrstr, xname);
 	pih->pic_type = pic->pic_type;
 	return pih;
 #endif /* NPCI > 0 || NISA > 0 */

Index: src/sys/arch/xen/x86/pintr.c
diff -u src/sys/arch/xen/x86/pintr.c:1.4 src/sys/arch/xen/x86/pintr.c:1.5
--- src/sys/arch/xen/x86/pintr.c:1.4	Sat Oct  6 16:37:11 2018
+++ src/sys/arch/xen/x86/pintr.c	Sat Oct  6 16:44:55 2018
@@ -103,7 +103,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.4 2018/10/06 16:37:11 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.5 2018/10/06 16:44:55 cherry Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -165,7 +165,7 @@ xen_pirq_alloc(intr_handle_t *pirq, int 
 	physdev_op_t op;
 	int irq = *pirq;
 #if NIOAPIC > 0
-	extern struct cpu_info phycpu_info_primary; /* XXX */
+
 	/*
 	 * The hypervisor has already allocated vectors and IRQs for the
 	 * devices. Reusing the same IRQ doesn't work because as we bind
@@ -179,7 +179,6 @@ xen_pirq_alloc(intr_handle_t *pirq, int 
 	 */
 	static int xen_next_irq = 200;
 	struct ioapic_softc *ioapic = ioapic_find(APIC_IRQ_APIC(*pirq));
-	struct pic *pic = >sc_pic;
 	int pin = APIC_IRQ_PIN(*pirq);
 
 	if (*pirq & APIC_INT_VIA_APIC) {
@@ -207,8 +206,6 @@ retry:
 (irq > 0 && irq < 16 &&
  vect2irq[op.u.irq_op.vector] == irq));
 			vect2irq[op.u.irq_op.vector] = irq;
-			pic->pic_addroute(pic, _info_primary, pin,
-			op.u.irq_op.vector, type);
 		}
 		*pirq &= ~0xff;
 		*pirq |= irq;
@@ -229,7 +226,6 @@ retry:
 			irq2port[irq] = bind_pirq_to_evtch(irq) + 1;
 		}
 	}
-	KASSERT(irq2port[irq] > 0);
-	return (irq2port[irq] - 1);
+	return (irq2vect[irq]);
 }
 #endif /* defined(DOM0OPS) || NPCI > 0 */



CVS commit: src/sys/arch/xen/x86

2018-10-06 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Oct  6 16:37:11 UTC 2018

Modified Files:
src/sys/arch/xen/x86: pintr.c

Log Message:
Teach intr_establish_xname() for XEN to tolerate shared legacy_irq
registrations.

The current XEN code has not been able to tolerate shared legacy_irq
requests in xen_pirq_alloc(). This was never a problem because:

i) The only potential callpath with shared legacy_irq was
   isa_intr_establish_xname().
ii) The other callpath, namely pci_intr_establish_xname() passed
legacy_irq to intr_establish_xname(). However, this was ignored,
and a value of zero was passed to xen_pirq_alloc() which in
turn, allocated a new irq value, thus effectively demultiplexing
any shared legacy_irq value intended across randomly allocated
new irq values.
iii) Presumably on all platforms that XEN runs on, the isa callpath
 mentioned in i) never had shared irqs, and thus this was never
 a problem.

Except:
We now use a unified path for both isa_intr_establish_xname() and
pci_intr_establish_xname(). This means that now, intr_establish_xname()
which is a callee of both, needs to have a way to discern who the caller
was, and decide to pass on or discard the legacy_irq value, to preserve
the old semantics. However, this is impossible to do so, because the
callpath doesn't explicitly provide a mechanism for this discernment.

This is however not a problem, because from XEN's point of view, a
repeat registration of an irq is only a warning. legacy_irq is the only
case in which this repeat should occur, per the current implementation of
xen_pirq_alloc(). We thus tweak the KASSERT()s to tolerate a repeat value
in the legacy_irq, while maintaining the original intent of the KASSERT()
which was to ensure that existing unrelated irq registrations should never
be overwritten.

Once we re-organise XEN specific code and unify with the native
intr_establish_xname() path, we will not run into this problem, because
legacy_irq will be treated as the pin number of the i8259 pic
exactly as it is now treated in native.

In short, this commit should fix some of the panics being seen on
-current for certain configurations of hardware on which dom0 runs.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/xen/x86/pintr.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/xen/x86/pintr.c
diff -u src/sys/arch/xen/x86/pintr.c:1.3 src/sys/arch/xen/x86/pintr.c:1.4
--- src/sys/arch/xen/x86/pintr.c:1.3	Sat Feb 17 18:51:53 2018
+++ src/sys/arch/xen/x86/pintr.c	Sat Oct  6 16:37:11 2018
@@ -103,7 +103,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.3 2018/02/17 18:51:53 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.4 2018/10/06 16:37:11 cherry Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -199,9 +199,13 @@ retry:
 	panic("PHYSDEVOP_ASSIGN_VECTOR irq %d", irq);
 goto retry;
 			}
-			KASSERT(irq2vect[irq] == 0);
+			KASSERT(irq2vect[irq] == 0 ||
+(irq > 0 && irq < 16 &&
+ irq2vect[irq] == op.u.irq_op.vector));
 			irq2vect[irq] = op.u.irq_op.vector;
-			KASSERT(vect2irq[op.u.irq_op.vector] == 0);
+			KASSERT(vect2irq[op.u.irq_op.vector] == 0 ||
+(irq > 0 && irq < 16 &&
+ vect2irq[op.u.irq_op.vector] == irq));
 			vect2irq[op.u.irq_op.vector] = irq;
 			pic->pic_addroute(pic, _info_primary, pin,
 			op.u.irq_op.vector, type);



CVS commit: src/sys/arch/x86/x86

2018-09-29 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Sep 29 13:19:38 UTC 2018

Modified Files:
src/sys/arch/x86/x86: pmap.c

Log Message:
For i386 XEN3PAE_DOM0, use the "native" idt registration
infrastructure by removing the #ifndef XEN clause.

This will hopefully be the last commit to "fix" boot
breakage of XEN3PAE_DOM0

Thanks to bouyer@ to focussed bug reports with

# xl dmesg
and relevant ddb> bt


To generate a diff of this commit:
cvs rdiff -u -r1.307 -r1.308 src/sys/arch/x86/x86/pmap.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/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.307 src/sys/arch/x86/x86/pmap.c:1.308
--- src/sys/arch/x86/x86/pmap.c:1.307	Wed Aug 29 16:26:25 2018
+++ src/sys/arch/x86/x86/pmap.c	Sat Sep 29 13:19:38 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.307 2018/08/29 16:26:25 maxv Exp $	*/
+/*	$NetBSD: pmap.c,v 1.308 2018/09/29 13:19:38 cherry Exp $	*/
 
 /*
  * Copyright (c) 2008, 2010, 2016, 2017 The NetBSD Foundation, Inc.
@@ -130,7 +130,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.307 2018/08/29 16:26:25 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.308 2018/09/29 13:19:38 cherry Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -1225,7 +1225,7 @@ pmap_bootstrap(vaddr_t kva_start)
 #endif
 	ldt_paddr = pmap_bootstrap_palloc(1);
 
-#if !defined(__x86_64__) && !defined(XEN)
+#if !defined(__x86_64__)
 	/* pentium f00f bug stuff */
 	pentium_idt_vaddr = pmap_bootstrap_valloc(1);
 #endif



CVS commit: src/sys/arch/i386/i386

2018-09-29 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Sep 29 07:00:20 UTC 2018

Modified Files:
src/sys/arch/i386/i386: machdep.c

Log Message:
Fix "use before init" of *idt.
This should fix boot time pagefaulting and panic(9)
on XEN kernels due to the boottime idt API reorg.


To generate a diff of this commit:
cvs rdiff -u -r1.810 -r1.811 src/sys/arch/i386/i386/machdep.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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.810 src/sys/arch/i386/i386/machdep.c:1.811
--- src/sys/arch/i386/i386/machdep.c:1.810	Sun Sep 23 15:28:48 2018
+++ src/sys/arch/i386/i386/machdep.c	Sat Sep 29 07:00:20 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.810 2018/09/23 15:28:48 cherry Exp $	*/
+/*	$NetBSD: machdep.c,v 1.811 2018/09/29 07:00:20 cherry Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009, 2017
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.810 2018/09/23 15:28:48 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.811 2018/09/29 07:00:20 cherry Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_freebsd.h"
@@ -1307,13 +1307,13 @@ init386(paddr_t first_avail)
 	memset((void *)gdt_vaddr, 0, PAGE_SIZE);
 	memset((void *)ldt_vaddr, 0, PAGE_SIZE);
 
-#ifndef XEN
 	pmap_kenter_pa(pentium_idt_vaddr, idt_paddr, VM_PROT_READ, 0);
 	pmap_update(pmap_kernel());
 	pentium_idt = (union descriptor *)pentium_idt_vaddr;
+	idt = (idt_descriptor_t *)idt_vaddr;
 
+#ifndef XEN	
 	tgdt = gdtstore;
-	idt = (struct gate_descriptor *)idt_vaddr;
 	gdtstore = (union descriptor *)gdt_vaddr;
 	ldtstore = (union descriptor *)ldt_vaddr;
 



CVS commit: src/sys/arch

2018-09-23 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Sep 23 15:28:49 UTC 2018

Modified Files:
src/sys/arch/i386/i386: cpufunc.S machdep.c
src/sys/arch/i386/include: segments.h
src/sys/arch/x86/x86: idt.c
src/sys/arch/xen/x86: xenfunc.c

Log Message:
Fix for i386, functionality intended in:
http://mail-index.netbsd.org/source-changes/2018/09/23/msg099357.html

This should fix the build for both GENERIC and XEN3PAE_DOM0

This has not been boot tested on native or xen3pae

Notes: pmap_changeprot_local() seems to be x86_64 only.
I was a bit surprised by this initially, but I suspect that the table
protections are enforced via ring0/ring1 fencing rather than page protections

the gdt registration code in i386 is still messy. I will leave it as is
for now - to avoid a rabbit hole.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/i386/i386/cpufunc.S
cvs rdiff -u -r1.809 -r1.810 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.66 -r1.67 src/sys/arch/i386/include/segments.h
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/x86/x86/idt.c
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/xen/x86/xenfunc.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/i386/i386/cpufunc.S
diff -u src/sys/arch/i386/i386/cpufunc.S:1.23 src/sys/arch/i386/i386/cpufunc.S:1.24
--- src/sys/arch/i386/i386/cpufunc.S:1.23	Sat Jul 21 16:21:27 2018
+++ src/sys/arch/i386/i386/cpufunc.S	Sun Sep 23 15:28:48 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.S,v 1.23 2018/07/21 16:21:27 maxv Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.24 2018/09/23 15:28:48 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 #include 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.23 2018/07/21 16:21:27 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.24 2018/09/23 15:28:48 cherry Exp $");
 
 #include "opt_xen.h"
 
@@ -65,11 +65,13 @@ ENTRY(x86_mfence)
 	ret
 END(x86_mfence)
 
-ENTRY(lidt)
+#ifndef XEN
+	ENTRY(lidt)
 	movl	4(%esp), %eax
 	lidt	(%eax)
 	ret
 END(lidt)
+#endif /* XEN */
 
 ENTRY(rcr3)
 	movl	%cr3, %eax

Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.809 src/sys/arch/i386/i386/machdep.c:1.810
--- src/sys/arch/i386/i386/machdep.c:1.809	Sun Sep 23 00:59:59 2018
+++ src/sys/arch/i386/i386/machdep.c	Sun Sep 23 15:28:48 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.809 2018/09/23 00:59:59 cherry Exp $	*/
+/*	$NetBSD: machdep.c,v 1.810 2018/09/23 15:28:48 cherry Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009, 2017
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.809 2018/09/23 00:59:59 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.810 2018/09/23 15:28:48 cherry Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_freebsd.h"
@@ -1360,19 +1360,20 @@ init386(paddr_t first_avail)
 		default:
 			break;
 		}
-		set_istgate([x], IDTVEC(exceptions)[x], 0, SDT_SYS386IGT,
+		set_idtgate([x], IDTVEC(exceptions)[x], 0, SDT_SYS386IGT,
 		sel, GSEL(GCODE_SEL, SEL_KPL));
 	}
 
 	/* new-style interrupt gate for syscalls */
 	idt_vec_reserve(128);
-	set_istgate([128], (syscall), 0, SDT_SYS386IGT, SEL_UPL,
+	set_idtgate([128], (syscall), 0, SDT_SYS386IGT, SEL_UPL,
 	GSEL(GCODE_SEL, SEL_KPL));
 
+#ifndef XEN
 	setregion(, gdtstore, NGDT * sizeof(gdtstore[0]) - 1);
 	lgdt();
-
-	cpu_init_idt();
+#endif
+	
 	lldt(GSEL(GLDT_SEL, SEL_KPL));
 	cpu_init_idt();
 

Index: src/sys/arch/i386/include/segments.h
diff -u src/sys/arch/i386/include/segments.h:1.66 src/sys/arch/i386/include/segments.h:1.67
--- src/sys/arch/i386/include/segments.h:1.66	Sun Sep 23 07:54:42 2018
+++ src/sys/arch/i386/include/segments.h	Sun Sep 23 15:28:49 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: segments.h,v 1.66 2018/09/23 07:54:42 cherry Exp $	*/
+/*	$NetBSD: segments.h,v 1.67 2018/09/23 15:28:49 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -200,7 +200,7 @@ extern idt_descriptor_t *idt;
 extern union descriptor *gdtstore, *ldtstore;
 
 void setgate(struct gate_descriptor *, void *, int, int, int, int);
-void set_idtgate(idt_descriptor_t *, void *, int, int, int);
+void set_idtgate(idt_descriptor_t *, void *, int, int, int, int);
 void unset_idtgate(idt_descriptor_t *);
 void setregion(struct region_descriptor *, void *, size_t);
 void setsegment(struct segment_descriptor *, const void *, size_t, int, int,

Index: src/sys/arch/x86/x86/idt.c
diff -u src/sys/arch/x86/x86/idt.c:1.7 src/sys/arch/x86/x86/idt.c:1.8
--- src/sys/arch/x86/x86/idt.c:1.7	Sun Sep 23 00:59:59 2018
+++ src/sys/arch/x86/x86/idt.c	Sun Sep 23 15:28:49 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: idt.c,v 1.7 2018/09/23 00:59:59 cherry Exp $	*/
+/*	$NetBSD: idt.c,v 1.8 2018/09/23 15:28:49 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2009 The NetBSD Foundation, Inc.
@@ -65,7 

CVS commit: src/sys/arch/i386/include

2018-09-23 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Sep 23 07:54:42 UTC 2018

Modified Files:
src/sys/arch/i386/include: segments.h

Log Message:
Summary: Remove older and now conflicting type declaration for global
variable 'idt'.

This should fix the i386 build failure now.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/i386/include/segments.h

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/i386/include/segments.h
diff -u src/sys/arch/i386/include/segments.h:1.65 src/sys/arch/i386/include/segments.h:1.66
--- src/sys/arch/i386/include/segments.h:1.65	Sun Sep 23 00:59:59 2018
+++ src/sys/arch/i386/include/segments.h	Sun Sep 23 07:54:42 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: segments.h,v 1.65 2018/09/23 00:59:59 cherry Exp $	*/
+/*	$NetBSD: segments.h,v 1.66 2018/09/23 07:54:42 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -198,7 +198,6 @@ typedef struct gate_descriptor idt_descr
 #endif /* XEN */
 extern idt_descriptor_t *idt;
 extern union descriptor *gdtstore, *ldtstore;
-extern struct gate_descriptor *idt;
 
 void setgate(struct gate_descriptor *, void *, int, int, int, int);
 void set_idtgate(idt_descriptor_t *, void *, int, int, int);



CVS commit: src/sys/arch/x86/pci

2018-09-22 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Sep 23 02:51:06 UTC 2018

Modified Files:
src/sys/arch/x86/pci: pci_intr_machdep.c

Log Message:
Revert:
http://mail-index.netbsd.org/source-changes/2018/09/10/msg098995.html

It is incorrect to infer semantics from usage.

the problem for which the original commit was intended should be fixed
within the callee intr_establish_xname() and not the caller:
pci_intr_find_intx_irq()

This was accomplished via:
http://mail-index.netbsd.org/source-changes/2018/09/20/msg099286.html


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/x86/pci/pci_intr_machdep.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/pci/pci_intr_machdep.c
diff -u src/sys/arch/x86/pci/pci_intr_machdep.c:1.44 src/sys/arch/x86/pci/pci_intr_machdep.c:1.45
--- src/sys/arch/x86/pci/pci_intr_machdep.c:1.44	Mon Sep 10 02:49:23 2018
+++ src/sys/arch/x86/pci/pci_intr_machdep.c	Sun Sep 23 02:51:06 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: pci_intr_machdep.c,v 1.44 2018/09/10 02:49:23 cherry Exp $	*/
+/*	$NetBSD: pci_intr_machdep.c,v 1.45 2018/09/23 02:51:06 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2009 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.44 2018/09/10 02:49:23 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.45 2018/09/23 02:51:06 cherry Exp $");
 
 #include 
 #include 
@@ -294,7 +294,9 @@ pci_intr_find_intx_irq(pci_intr_handle_t
 			return ENOENT;
 		*pic = >sc_pic;
 		*pin = APIC_IRQ_PIN(ih);
-		*irq = -1; /* PCI doesn't use legacy irq */
+		*irq = APIC_IRQ_LEGACY_IRQ(ih);
+		if (*irq < 0 || *irq >= NUM_LEGACY_IRQS)
+			*irq = -1;
 	}
 #endif
 



CVS commit: src/sys/arch/xen

2018-09-22 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Sep 23 02:27:25 UTC 2018

Modified Files:
src/sys/arch/xen/include: hypervisor.h
src/sys/arch/xen/xen: evtchn.c

Log Message:
Encapsulate pre-processing of registered (pirq,evtchn) pair in
preparation for API reorg.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/xen/include/hypervisor.h
cvs rdiff -u -r1.80 -r1.81 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/xen/include/hypervisor.h
diff -u src/sys/arch/xen/include/hypervisor.h:1.44 src/sys/arch/xen/include/hypervisor.h:1.45
--- src/sys/arch/xen/include/hypervisor.h:1.44	Sat Jun 14 02:53:02 2014
+++ src/sys/arch/xen/include/hypervisor.h	Sun Sep 23 02:27:24 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor.h,v 1.44 2014/06/14 02:53:02 pgoyette Exp $	*/
+/*	$NetBSD: hypervisor.h,v 1.45 2018/09/23 02:27:24 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -130,6 +130,7 @@ extern volatile shared_info_t *HYPERVISO
 struct intrframe;
 struct cpu_info;
 void do_hypervisor_callback(struct intrframe *regs);
+void hypervisor_prime_pirq_event(int, unsigned int);
 void hypervisor_enable_event(unsigned int);
 
 extern int xen_version;

Index: src/sys/arch/xen/xen/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.80 src/sys/arch/xen/xen/evtchn.c:1.81
--- src/sys/arch/xen/xen/evtchn.c:1.80	Sun Jun 24 13:35:33 2018
+++ src/sys/arch/xen/xen/evtchn.c	Sun Sep 23 02:27:24 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.80 2018/06/24 13:35:33 jdolecek Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.81 2018/09/23 02:27:24 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.80 2018/06/24 13:35:33 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.81 2018/09/23 02:27:24 cherry Exp $");
 
 #include "opt_xen.h"
 #include "isa.h"
@@ -737,7 +737,6 @@ pirq_establish(int pirq, int evtch, int 
 const char *intrname, const char *xname)
 {
 	struct pintrhand *ih;
-	physdev_op_t physdev_op;
 
 	ih = kmem_zalloc(sizeof(struct pintrhand),
 	cold ? KM_NOSLEEP : KM_SLEEP);
@@ -759,17 +758,7 @@ pirq_establish(int pirq, int evtch, int 
 		return NULL;
 	}
 
-	physdev_op.cmd = PHYSDEVOP_IRQ_STATUS_QUERY;
-	physdev_op.u.irq_status_query.irq = pirq;
-	if (HYPERVISOR_physdev_op(_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
-	}
+	hypervisor_prime_pirq_event(pirq, evtch);
 	hypervisor_enable_event(evtch);
 	return ih;
 }
@@ -1006,6 +995,25 @@ event_remove_handler(int evtch, int (*fu
 }
 
 void
+hypervisor_prime_pirq_event(int pirq, unsigned int evtch)
+{
+#if NPCI > 0 || NISA > 0
+	physdev_op_t physdev_op;
+	physdev_op.cmd = PHYSDEVOP_IRQ_STATUS_QUERY;
+	physdev_op.u.irq_status_query.irq = pirq;
+	if (HYPERVISOR_physdev_op(_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
+	}
+#endif /* NPCI > 0 || NISA > 0 */
+}
+
+void
 hypervisor_enable_event(unsigned int evtch)
 {
 #ifdef IRQ_DEBUG



CVS commit: src/sys/arch

2018-09-22 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Sep 23 01:00:00 UTC 2018

Modified Files:
src/sys/arch/amd64/amd64: db_interface.c machdep.c
src/sys/arch/amd64/include: segments.h
src/sys/arch/i386/i386: machdep.c
src/sys/arch/i386/include: segments.h
src/sys/arch/x86/x86: idt.c lapic.c
src/sys/arch/xen/x86: xenfunc.c

Log Message:
Make XEN use the same api as native, for idt vector allocation
and registration.

lidt() placed in xenfunc() on maxv@ suggestion.

There should be no functional change due to this commit.

Tested on amd64 native and XEN.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/amd64/amd64/db_interface.c
cvs rdiff -u -r1.318 -r1.319 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/amd64/include/segments.h
cvs rdiff -u -r1.808 -r1.809 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.64 -r1.65 src/sys/arch/i386/include/segments.h
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/x86/x86/idt.c
cvs rdiff -u -r1.66 -r1.67 src/sys/arch/x86/x86/lapic.c
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/xen/x86/xenfunc.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/db_interface.c
diff -u src/sys/arch/amd64/amd64/db_interface.c:1.33 src/sys/arch/amd64/amd64/db_interface.c:1.34
--- src/sys/arch/amd64/amd64/db_interface.c:1.33	Tue Apr  3 07:20:52 2018
+++ src/sys/arch/amd64/amd64/db_interface.c	Sun Sep 23 00:59:59 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_interface.c,v 1.33 2018/04/03 07:20:52 christos Exp $	*/
+/*	$NetBSD: db_interface.c,v 1.34 2018/09/23 00:59:59 cherry Exp $	*/
 
 /*
  * Mach Operating System
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.33 2018/04/03 07:20:52 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.34 2018/09/23 00:59:59 cherry Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -113,7 +113,7 @@ db_machine_init(void)
 		handler = _x2apic_ddbipi;
 #endif
 	ddb_vec = idt_vec_alloc(0xf0, 0xff);
-	setgate([ddb_vec], handler, 1, SDT_SYS386IGT, SEL_KPL,
+	set_idtgate([ddb_vec], handler, 1, SDT_SYS386IGT, SEL_KPL,
 	GSEL(GCODE_SEL, SEL_KPL));
 #else
 	/* Initialised as part of xen_ipi_init() */

Index: src/sys/arch/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.318 src/sys/arch/amd64/amd64/machdep.c:1.319
--- src/sys/arch/amd64/amd64/machdep.c:1.318	Wed Aug 29 16:26:25 2018
+++ src/sys/arch/amd64/amd64/machdep.c	Sun Sep 23 00:59:59 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.318 2018/08/29 16:26:25 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.319 2018/09/23 00:59:59 cherry Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.318 2018/08/29 16:26:25 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.319 2018/09/23 00:59:59 cherry Exp $");
 
 #include "opt_modular.h"
 #include "opt_user_ldt.h"
@@ -1397,11 +1397,6 @@ setregs(struct lwp *l, struct exec_packa
 /*
  * Initialize segments and descriptor tables
  */
-
-#ifdef XEN
-struct trap_info *xen_idt;
-int xen_idt_idx;
-#endif
 char *ldtstore;
 char *gdtstore;
 
@@ -1486,15 +1481,10 @@ set_sys_segment(struct sys_segment_descr
 void
 cpu_init_idt(void)
 {
-#ifndef XEN
 	struct region_descriptor region;
 
 	setregion(, idt, NIDT * sizeof(idt[0]) - 1);
 	lidt();
-#else
-	if (HYPERVISOR_set_trap_table(xen_idt))
-		panic("HYPERVISOR_set_trap_table() failed");
-#endif
 }
 
 #define	IDTVEC(name)	__CONCAT(X, name)
@@ -1681,7 +1671,6 @@ init_x86_64(paddr_t first_avail)
 	extern vaddr_t lwp0uarea;
 #ifndef XEN
 	extern paddr_t local_apic_pa;
-	int ist;
 #endif
 
 	KASSERT(first_avail % PAGE_SIZE == 0);
@@ -1806,12 +1795,7 @@ init_x86_64(paddr_t first_avail)
 
 	pmap_update(pmap_kernel());
 
-#ifndef XEN
-	idt = (struct gate_descriptor *)idt_vaddr;
-#else
-	xen_idt = (struct trap_info *)idt_vaddr;
-	xen_idt_idx = 0;
-#endif
+	idt = (idt_descriptor_t *)idt_vaddr;
 	gdtstore = (char *)gdt_vaddr;
 	ldtstore = (char *)ldt_vaddr;
 
@@ -1870,8 +1854,14 @@ init_x86_64(paddr_t first_avail)
 
 	/* CPU-specific IDT exceptions. */
 	for (x = 0; x < NCPUIDT; x++) {
-#ifndef XEN
+		int sel, ist;
+
+		/* Reset to default. Special cases below */
+		sel = SEL_KPL;
+		ist = 0;
+
 		idt_vec_reserve(x);
+
 		switch (x) {
 		case 1:	/* DB */
 			ist = 4;
@@ -1879,56 +1869,31 @@ init_x86_64(paddr_t first_avail)
 		case 2:	/* NMI */
 			ist = 3;
 			break;
+		case 3:
+		case 4:			
+			sel = SEL_UPL;
+			break;
 		case 8:	/* double fault */
 			ist = 2;
 			break;
-		default:
-			ist = 0;
-			break;
-		}
-		setgate([x], x86_exceptions[x], ist, SDT_SYS386IGT,
-		(x == 3 || x == 4) ? SEL_UPL : SEL_KPL,
-		GSEL(GCODE_SEL, SEL_KPL));
-#else /* XEN */
-		pmap_changeprot_local(idt_vaddr, VM_PROT_READ|VM_PROT_WRITE);
-		idt_vec_reserve(x);
-		

CVS commit: src/sys/arch/x86/x86

2018-09-19 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Sep 20 05:08:45 UTC 2018

Modified Files:
src/sys/arch/x86/x86: intr.c

Log Message:
When we removed the XEN special case from isa/isa_machdep.c
there was a corner case that was missed in
x86/intr.c:intr_establish_xname()

In isa_machdep.c:isa_intr_establish_xname() the legacy_irq parameter
is never set to -1. It is also incorrect to call
isa_intr_establish_xname() with a legacy_irq parameter of -1.

Thus we infer that whenever we see (legacy_irq == -1) in
intr_establish_xname() which is downstream, we were *NOT* called from
isa_machdep.c:isa_intr_establish_xname()

Given that there are no other users of intr_establish_xnam() which
pass a valid legacy_irq != -1, we assume therefore that we *WERE*
called from isa_machdep.c:isa_intr_establish_xname() in this case.

This is an important distinction in the case where a valid
legacy_irq > NUM_LEGACY_IRQS was passed down from
isa_intr_establish_xname() but was ignored by xen_pirq_alloc() and
overwritten with the "pseudo" irq which is then passed back. We thus
pass the incorrect "legacy" irq value to pirq_establish().

Even though non ISA (ie; PCI and MSI(X) cases), this is the correct
behaviour, we need to maintain (bug?) compatibility with the isa
case.

Thus the one liner diff.

CVS: --
CVS: CVSROOT  cvs.NetBSD.org:/cvsroot
CVS: please use "PR category/123" to have the commitmsg appended to PR 123
CVS:
CVS: Please evaluate your changes and consider the following.
CVS: Abort checkin if you answer no.
CVS: => For all changes:
CVS: Do the changed files compile?
CVS: Has the change been tested?
CVS: => If you are not completely familiar with the changed components:
CVS: Has the change been posted for review?
CVS: Have you allowed enough time for feedback?
CVS: => If the change is major:
CVS: => If the change adds files to, or removes files from $DESTDIR:
CVS: => If you are changing a library or kernel interface:
CVS: Have you successfully run "./build.sh release"?


To generate a diff of this commit:
cvs rdiff -u -r1.129 -r1.130 src/sys/arch/x86/x86/intr.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/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.129 src/sys/arch/x86/x86/intr.c:1.130
--- src/sys/arch/x86/x86/intr.c:1.129	Fri Sep 14 01:50:51 2018
+++ src/sys/arch/x86/x86/intr.c	Thu Sep 20 05:08:45 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.129 2018/09/14 01:50:51 mrg Exp $	*/
+/*	$NetBSD: intr.c,v 1.130 2018/09/20 05:08:45 cherry Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.129 2018/09/14 01:50:51 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.130 2018/09/20 05:08:45 cherry Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -1291,6 +1291,7 @@ intr_establish_xname(int legacy_irq, str
 	sizeof(intrstr_buf));
 
 	evtchn = xen_pirq_alloc(, type);
+	irq = (legacy_irq == -1) ? irq : legacy_irq; /* ISA compat */	
 	pih = pirq_establish(irq & 0xff, evtchn, handler, arg, level,
 	intrstr, xname);
 	pih->pic_type = pic->pic_type;



CVS commit: src/sys/arch/x86/isa

2018-09-10 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Sep 10 07:04:08 UTC 2018

Modified Files:
src/sys/arch/x86/isa: isa_machdep.c

Log Message:
Remove the last usage of xen_pirq_alloc() and pirq_establish()
outside of the x86 interrupt and xen events framework.

This allows us to finally unify the interrupt path for both Xen
and x86 as changes 'internal' to the subsystem.

This change has been kindly tested on real hardware by gson@

The change is not cosmetic and may thus affect users on various
hardware configurations - especially involving legacy hardware.

I look forward to bug reports.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/x86/isa/isa_machdep.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/isa/isa_machdep.c
diff -u src/sys/arch/x86/isa/isa_machdep.c:1.39 src/sys/arch/x86/isa/isa_machdep.c:1.40
--- src/sys/arch/x86/isa/isa_machdep.c:1.39	Sun Jun 24 13:35:33 2018
+++ src/sys/arch/x86/isa/isa_machdep.c	Mon Sep 10 07:04:08 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: isa_machdep.c,v 1.39 2018/06/24 13:35:33 jdolecek Exp $	*/
+/*	$NetBSD: isa_machdep.c,v 1.40 2018/09/10 07:04:08 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.39 2018/06/24 13:35:33 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.40 2018/09/10 07:04:08 cherry Exp $");
 
 #include 
 #include 
@@ -237,31 +237,8 @@ isa_intr_establish_xname(isa_chipset_tag
 			printf("isa_intr_establish: no MP mapping found\n");
 	}
 #endif
-#if defined(XEN)
-	KASSERT(APIC_IRQ_ISLEGACY(irq));
-
-	int evtch;
-	const char *intrstr;
-	char intrstr_buf[INTRIDBUF];
-
-	mpih |= APIC_IRQ_LEGACY_IRQ(irq);
-
-	evtch = xen_pirq_alloc(, type); /* XXX: legacy - xen just tosses irq back at us */
-	if (evtch == -1)
-		return NULL;
-
-	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,
-	intrstr, xname);
-#else /* defined(XEN) */
 	return intr_establish_xname(irq, pic, pin, type, level, ih_fun, ih_arg,
 	false, xname);
-#endif
-
 }
 
 /* Deregister an interrupt handler. */



CVS commit: src/sys/arch

2018-09-09 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Sep 10 05:08:55 UTC 2018

Modified Files:
src/sys/arch/x86/x86: intr.c
src/sys/arch/xen/include: intrdefs.h

Log Message:
Make the use of 'irqs' in the range 0 < irq < 255 by xen
as a handle for internal use explicit.

This allows us to pass up the handle as "legacy" irq while
establishing interrupt handlers for xen.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.127 -r1.128 src/sys/arch/x86/x86/intr.c
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/xen/include/intrdefs.h

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/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.127 src/sys/arch/x86/x86/intr.c:1.128
--- src/sys/arch/x86/x86/intr.c:1.127	Tue Jul  3 11:45:54 2018
+++ src/sys/arch/x86/x86/intr.c	Mon Sep 10 05:08:55 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.127 2018/07/03 11:45:54 kamil Exp $	*/
+/*	$NetBSD: intr.c,v 1.128 2018/09/10 05:08:55 cherry Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.127 2018/07/03 11:45:54 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.128 2018/09/10 05:08:55 cherry Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -1266,15 +1266,18 @@ intr_establish_xname(int legacy_irq, str
 	intr_handle_t irq;
 	int evtchn;
 
-	KASSERTMSG(legacy_irq == -1 || (0 <= legacy_irq && legacy_irq < 16),
+	KASSERTMSG(legacy_irq == -1 || (0 <= legacy_irq && legacy_irq < NUM_XEN_IRQS),
 	"bad legacy IRQ value: %d", legacy_irq);
 	KASSERTMSG(!(legacy_irq == -1 && pic == _pic),
 	"non-legacy IRQon i8259 ");
 
 	if (pic->pic_type != PIC_I8259) {
 #if NIOAPIC > 0
+		/* Are we passing mp tranmogrified/cascaded irqs ? */
+		irq = (legacy_irq == -1) ? 0 : legacy_irq;
+
 		/* will do interrupts via I/O APIC */
-		irq = APIC_INT_VIA_APIC;
+		irq |= APIC_INT_VIA_APIC;
 		irq |= pic->pic_apicid << APIC_INT_APIC_SHIFT;
 		irq |= pin << APIC_INT_PIN_SHIFT;
 #else /* NIOAPIC */

Index: src/sys/arch/xen/include/intrdefs.h
diff -u src/sys/arch/xen/include/intrdefs.h:1.12 src/sys/arch/xen/include/intrdefs.h:1.13
--- src/sys/arch/xen/include/intrdefs.h:1.12	Mon May 19 22:47:54 2014
+++ src/sys/arch/xen/include/intrdefs.h	Mon Sep 10 05:08:55 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: intrdefs.h,v 1.12 2014/05/19 22:47:54 rmind Exp $ */
+/* $NetBSD: intrdefs.h,v 1.13 2018/09/10 05:08:55 cherry Exp $ */
 
 /* This file co-exists, and is included via machine/intrdefs.h */
 
@@ -17,4 +17,7 @@
 /* Note: IPI_KICK does not have a handler. */
 #define XEN_NIPIS		6
 
+/* The number of 'irqs' that XEN understands */
+#define NUM_XEN_IRQS 		256
+
 #endif /* _XEN_INTRDEFS_H_ */



CVS commit: src/sys/arch/x86/pci

2018-09-09 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Sep 10 02:49:23 UTC 2018

Modified Files:
src/sys/arch/x86/pci: pci_intr_machdep.c

Log Message:
In the NIOAPIC case, we do not need to support "legacy" irqs,
ie; We don't need to simultaneously pass back the irq in the
range 0 < irq < 16 (which are sometimes described as "legacy"
in src

This was non-obvious, until the semantics of "legacy" were
used in inconsistent ways in Xen (to also mean interrupts in
the 0 < irq < 256 range) which causes problems with attempting
to unify the sys/arch/x86/isa/isa_machdep.c:isa_intr_establish_xname()
function between XEN and !XEN

This commit should not affect current functionality on any
either native or Xen. It is needed for future code reorg, and
published now as a preview.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/x86/pci/pci_intr_machdep.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/pci/pci_intr_machdep.c
diff -u src/sys/arch/x86/pci/pci_intr_machdep.c:1.43 src/sys/arch/x86/pci/pci_intr_machdep.c:1.44
--- src/sys/arch/x86/pci/pci_intr_machdep.c:1.43	Sun Jun 24 11:51:15 2018
+++ src/sys/arch/x86/pci/pci_intr_machdep.c	Mon Sep 10 02:49:23 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: pci_intr_machdep.c,v 1.43 2018/06/24 11:51:15 jdolecek Exp $	*/
+/*	$NetBSD: pci_intr_machdep.c,v 1.44 2018/09/10 02:49:23 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2009 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.43 2018/06/24 11:51:15 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.44 2018/09/10 02:49:23 cherry Exp $");
 
 #include 
 #include 
@@ -294,9 +294,7 @@ pci_intr_find_intx_irq(pci_intr_handle_t
 			return ENOENT;
 		*pic = >sc_pic;
 		*pin = APIC_IRQ_PIN(ih);
-		*irq = APIC_IRQ_LEGACY_IRQ(ih);
-		if (*irq < 0 || *irq >= NUM_LEGACY_IRQS)
-			*irq = -1;
+		*irq = -1; /* PCI doesn't use legacy irq */
 	}
 #endif
 



CVS commit: src/sys/arch/xen/xen

2018-05-11 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri May 11 13:24:46 UTC 2018

Modified Files:
src/sys/arch/xen/xen: clock.c

Log Message:
Fixes port-xen/53267
re-educate xen_clock_handler() how to use the interrupt stackframe.
The current regs value passed in is *ci, and thus invalid.

Reported and tested by kre@. See PR 53267 for more details.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/xen/xen/clock.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/xen/xen/clock.c
diff -u src/sys/arch/xen/xen/clock.c:1.65 src/sys/arch/xen/xen/clock.c:1.66
--- src/sys/arch/xen/xen/clock.c:1.65	Mon Nov  6 15:27:09 2017
+++ src/sys/arch/xen/xen/clock.c	Fri May 11 13:24:46 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.65 2017/11/06 15:27:09 cherry Exp $	*/
+/*	$NetBSD: clock.c,v 1.66 2018/05/11 13:24:46 cherry Exp $	*/
 
 /*
  *
@@ -29,7 +29,7 @@
 #include "opt_xen.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.65 2017/11/06 15:27:09 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.66 2018/05/11 13:24:46 cherry Exp $");
 
 #include 
 #include 
@@ -49,7 +49,8 @@ __KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.
 #include 
 #include 
 
-static int xen_timer_handler(void *);
+static int xen_timer_handler(void *, struct intrframe *);
+static int (*xen_timer_handler_stub)(void *) = (void *) xen_timer_handler;
 static struct intrhand *ih;
 
 /* A timecounter: Xen system_time extrapolated with a TSC. */
@@ -524,7 +525,7 @@ xen_resumeclocks(struct cpu_info *ci)
 	KASSERT(evtch != -1);
 
 	ih = intr_establish_xname(0, _pic, evtch, IST_LEVEL, IPL_CLOCK,
-	xen_timer_handler, ci, true, "clock");
+	xen_timer_handler_stub, ci, true, "clock");
 
 	KASSERT(ih != NULL);
 
@@ -535,11 +536,10 @@ xen_resumeclocks(struct cpu_info *ci)
 
 /* ARGSUSED */
 static int
-xen_timer_handler(void *arg)
+xen_timer_handler(void *arg, struct intrframe *regs)
 {
 	int64_t delta;
 	struct cpu_info *ci = curcpu();
-	struct intrframe *regs = arg;
 
 	int err;
 again:



CVS commit: src/sys/arch/xen

2017-11-06 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Nov  6 15:27:09 UTC 2017

Modified Files:
src/sys/arch/xen/x86: xen_ipi.c
src/sys/arch/xen/xen: clock.c if_xennet_xenbus.c xbd_xenbus.c
xbdback_xenbus.c xencons.c xennetback_xenbus.c
src/sys/arch/xen/xenbus: xenbus_comms.c

Log Message:
Switch XEN drivers to use intr_establish_xname()/intr_disestablish()

This completes the API transition.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/xen/x86/xen_ipi.c
cvs rdiff -u -r1.64 -r1.65 src/sys/arch/xen/xen/clock.c
cvs rdiff -u -r1.71 -r1.72 src/sys/arch/xen/xen/if_xennet_xenbus.c
cvs rdiff -u -r1.76 -r1.77 src/sys/arch/xen/xen/xbd_xenbus.c
cvs rdiff -u -r1.63 -r1.64 src/sys/arch/xen/xen/xbdback_xenbus.c
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/xen/xen/xencons.c
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/xen/xen/xennetback_xenbus.c
cvs rdiff -u -r1.15 -r1.16 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/xen/x86/xen_ipi.c
diff -u src/sys/arch/xen/x86/xen_ipi.c:1.22 src/sys/arch/xen/x86/xen_ipi.c:1.23
--- src/sys/arch/xen/x86/xen_ipi.c:1.22	Tue Aug 15 09:16:59 2017
+++ src/sys/arch/xen/x86/xen_ipi.c	Mon Nov  6 15:27:09 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_ipi.c,v 1.22 2017/08/15 09:16:59 maxv Exp $ */
+/* $NetBSD: xen_ipi.c,v 1.23 2017/11/06 15:27:09 cherry 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.22 2017/08/15 09:16:59 maxv Exp $");
+ * __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.23 2017/11/06 15:27:09 cherry Exp $");
  */
 
-__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.22 2017/08/15 09:16:59 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.23 2017/11/06 15:27:09 cherry Exp $");
 
 #include 
 
@@ -78,12 +78,17 @@ static void (*ipifunc[XEN_NIPIS])(struct
 	xen_ipi_generic,
 };
 
-static void
-xen_ipi_handler(struct cpu_info *ci, struct intrframe *regs)
+static int
+xen_ipi_handler(void *arg)
 {
 	uint32_t pending;
 	int bit;
+	struct cpu_info *ci;
+	struct intrframe *regs;
 
+	ci = curcpu();
+	regs = arg;
+	
 	pending = atomic_swap_32(>ci_ipis, 0);
 
 	KDASSERT((pending >> XEN_NIPIS) == 0);
@@ -98,6 +103,8 @@ xen_ipi_handler(struct cpu_info *ci, str
 			/* NOTREACHED */
 		}
 	}
+
+	return 0;
 }
 
 /* Must be called once for every cpu that expects to send/recv ipis */
@@ -118,9 +125,9 @@ xen_ipi_init(void)
 
 	KASSERT(evtchn != -1 && evtchn < NR_EVENT_CHANNELS);
 
-	if (0 != event_set_handler(evtchn, (int (*)(void *))xen_ipi_handler,
-   ci, IPL_HIGH, "ipi")) {
-		panic("event_set_handler(...) KPI violation\n");
+	if(intr_establish_xname(0, _pic, evtchn, IST_LEVEL, IPL_HIGH,
+		xen_ipi_handler, ci, true, "ipi") == NULL) {
+		panic("%s: unable to register ipi handler\n", __func__);
 		/* NOTREACHED */
 	}
 

Index: src/sys/arch/xen/xen/clock.c
diff -u src/sys/arch/xen/xen/clock.c:1.64 src/sys/arch/xen/xen/clock.c:1.65
--- src/sys/arch/xen/xen/clock.c:1.64	Sun Jun 12 09:08:09 2016
+++ src/sys/arch/xen/xen/clock.c	Mon Nov  6 15:27:09 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.64 2016/06/12 09:08:09 jnemeth Exp $	*/
+/*	$NetBSD: clock.c,v 1.65 2017/11/06 15:27:09 cherry Exp $	*/
 
 /*
  *
@@ -29,7 +29,7 @@
 #include "opt_xen.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.64 2016/06/12 09:08:09 jnemeth Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.65 2017/11/06 15:27:09 cherry Exp $");
 
 #include 
 #include 
@@ -49,7 +49,8 @@ __KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.
 #include 
 #include 
 
-static int xen_timer_handler(void *, struct intrframe *);
+static int xen_timer_handler(void *);
+static struct intrhand *ih;
 
 /* A timecounter: Xen system_time extrapolated with a TSC. */
 u_int xen_get_timecount(struct timecounter*);
@@ -509,7 +510,7 @@ xen_suspendclocks(struct cpu_info *ci)
 	KASSERT(evtch != -1);
 
 	hypervisor_mask_event(evtch);
-	event_remove_handler(evtch, (int (*)(void *))xen_timer_handler, ci);
+	intr_disestablish(ih);
 
 	aprint_verbose("Xen clock: removed event channel %d\n", evtch);
 }
@@ -522,8 +523,11 @@ xen_resumeclocks(struct cpu_info *ci)
 	evtch = bind_virq_to_evtch(VIRQ_TIMER);
 	KASSERT(evtch != -1);
 
-	event_set_handler(evtch, (int (*)(void *))xen_timer_handler,
-	ci, IPL_CLOCK, "clock");
+	ih = intr_establish_xname(0, _pic, evtch, IST_LEVEL, IPL_CLOCK,
+	xen_timer_handler, ci, true, "clock");
+
+	KASSERT(ih != NULL);
+
 	hypervisor_enable_event(evtch);
 
 	aprint_verbose("Xen clock: using event channel %d\n", evtch);
@@ -531,11 +535,12 @@ xen_resumeclocks(struct cpu_info *ci)
 
 /* ARGSUSED */
 static int
-xen_timer_handler(void *arg, struct intrframe *regs)
+xen_timer_handler(void *arg)
 {
 	int64_t delta;
 	struct cpu_info *ci = curcpu();
-	KASSERT(arg == ci);
+	struct intrframe *regs = arg;
+
 	int err;
 again:
 	

CVS commit: src/sys/arch/xen/conf

2017-11-06 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Nov  6 15:21:23 UTC 2017

Modified Files:
src/sys/arch/xen/conf: files.xen

Log Message:
Summary: xen/x86/intr.c has been retired. Don't try to build it.


To generate a diff of this commit:
cvs rdiff -u -r1.162 -r1.163 src/sys/arch/xen/conf/files.xen

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/xen/conf/files.xen
diff -u src/sys/arch/xen/conf/files.xen:1.162 src/sys/arch/xen/conf/files.xen:1.163
--- src/sys/arch/xen/conf/files.xen:1.162	Sat Nov  4 15:24:42 2017
+++ src/sys/arch/xen/conf/files.xen	Mon Nov  6 15:21:23 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: files.xen,v 1.162 2017/11/04 15:24:42 cherry Exp $
+#	$NetBSD: files.xen,v 1.163 2017/11/06 15:21:23 cherry Exp $
 #	NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp 
 #	NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp 
 
@@ -139,7 +139,6 @@ file	arch/x86/x86/bus_space.c	machdep
 file	arch/xen/x86/consinit.c		machdep
 file	arch/x86/x86/identcpu.c		machdep
 file	arch/xen/x86/pintr.c		machdep & dom0ops
-file	arch/xen/x86/intr.c		machdep
 file	arch/xen/x86/xen_ipi.c		multiprocessor
 file	arch/x86/x86/intr.c		machdep
 file	arch/x86/x86/idt.c		machdep



CVS commit: src/sys/arch

2017-11-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Nov  4 15:24:42 UTC 2017

Modified Files:
src/sys/arch/x86/pci: pciide_machdep.c
src/sys/arch/xen/conf: files.xen
Removed Files:
src/sys/arch/xen/xen: pci_intr_machdep.c pciide_machdep.c

Log Message:
Remove bitrotted xen specific versions of pci, pciide machdep related code.

Use the common x86/ code instead.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/x86/pci/pciide_machdep.c
cvs rdiff -u -r1.161 -r1.162 src/sys/arch/xen/conf/files.xen
cvs rdiff -u -r1.21 -r0 src/sys/arch/xen/xen/pci_intr_machdep.c
cvs rdiff -u -r1.20 -r0 src/sys/arch/xen/xen/pciide_machdep.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/pci/pciide_machdep.c
diff -u src/sys/arch/x86/pci/pciide_machdep.c:1.16 src/sys/arch/x86/pci/pciide_machdep.c:1.17
--- src/sys/arch/x86/pci/pciide_machdep.c:1.16	Sat Oct 15 16:46:14 2016
+++ src/sys/arch/x86/pci/pciide_machdep.c	Sat Nov  4 15:24:42 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pciide_machdep.c,v 1.16 2016/10/15 16:46:14 jdolecek Exp $	*/
+/*	$NetBSD: pciide_machdep.c,v 1.17 2017/11/04 15:24:42 cherry Exp $	*/
 
 /*
  * Copyright (c) 1998 Christopher G. Demetriou.  All rights reserved.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pciide_machdep.c,v 1.16 2016/10/15 16:46:14 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pciide_machdep.c,v 1.17 2017/11/04 15:24:42 cherry Exp $");
 
 #include 
 #include 
@@ -61,6 +61,7 @@ __KERNEL_RCSID(0, "$NetBSD: pciide_machd
 #include 
 #endif
 
+#ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
 void *
 pciide_machdep_compat_intr_establish(device_t dev,
 const struct pci_attach_args *pa, int chan, int (*func)(void *),
@@ -96,7 +97,9 @@ pciide_machdep_compat_intr_establish(dev
 	PCIIDE_CHANNEL_NAME(chan), irq);
 	return cookie;
 }
+#endif /* __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH */
 
+#ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_DISESTABLISH
 void
 pciide_machdep_compat_intr_disestablish(device_t dev, pci_chipset_tag_t pc,
 int chan, void *cookie)
@@ -104,3 +107,4 @@ pciide_machdep_compat_intr_disestablish(
 	isa_intr_disestablish(NULL, cookie);
 	return;
 }
+#endif /* __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_DISESTABLISH */

Index: src/sys/arch/xen/conf/files.xen
diff -u src/sys/arch/xen/conf/files.xen:1.161 src/sys/arch/xen/conf/files.xen:1.162
--- src/sys/arch/xen/conf/files.xen:1.161	Sat Nov  4 14:56:48 2017
+++ src/sys/arch/xen/conf/files.xen	Sat Nov  4 15:24:42 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: files.xen,v 1.161 2017/11/04 14:56:48 cherry Exp $
+#	$NetBSD: files.xen,v 1.162 2017/11/04 15:24:42 cherry Exp $
 #	NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp 
 #	NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp 
 
@@ -232,7 +232,7 @@ include	"dev/pckbport/files.pckbport"
 include "dev/i2o/files.i2o"
 include "dev/pci/files.pci"
 include "dev/pci/files.agp"
-file	arch/xen/xen/pciide_machdep.c	pciide_common
+file	arch/x86/pci/pciide_machdep.c	pciide_common
 
 device	pciback {unit = -1}
 attach	pciback at pci
@@ -382,7 +382,9 @@ defflag	opt_xen.h			DOM0OPS
 file	arch/xen/xen/privcmd.c		dom0ops
 file 	arch/xen/x86/xen_shm_machdep.c	dom0ops
 file	arch/x86/pci/pci_machdep.c	hypervisor & pci & dom0ops
-file	arch/xen/xen/pci_intr_machdep.c	hypervisor & pci
+file	arch/x86/pci/pci_intr_machdep.c	hypervisor & pci
+file	arch/x86/pci/pci_msi_machdep.c	hypervisor & pci
+file	arch/x86/pci/msipic.c		hypervisor & pci
 file	arch/x86/isa/isa_machdep.c	hypervisor & dom0ops
 file	arch/xen/xen/xenevt.c		xenevt & dom0ops
 file	arch/xen/xen/xennetback_xenbus.c xvif



CVS commit: src/sys/arch

2017-11-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Nov  4 14:56:48 UTC 2017

Modified Files:
src/sys/arch/x86/include: intr.h
src/sys/arch/x86/isa: isa_machdep.c
src/sys/arch/x86/x86: intr.c ioapic.c
src/sys/arch/xen/conf: files.xen
src/sys/arch/xen/include: evtchn.h intr.h
src/sys/arch/xen/xen: pci_intr_machdep.c pciide_machdep.c
Removed Files:
src/sys/arch/xen/x86: intr.c

Log Message:
Retire xen/x86/intr.c and use the new xen specific glue in x86/x86/intr.c

The purpose of this change is to expose the x86/include/intr.h API
to drivers. Specifically the following functions:

   void *intr_establish_xname(...);
   void *intr_establish(...);
   void intr_disestablish(...);

while maintaining the old API from xen/include/evtchn.h, specifically
the following functions:

int event_set_handler(...);
int event_remove_handler(...);

This is so that if things break, we can keep using the old API until
everything stabilises. This is a stepping stone towards getting the
actual XEN event callback path rework code in place - which can be
done opaquely behind the intr.h API - NetBSD/XEN specific drivers that
have been ported to the intr.h API should then work without
significant further modifications.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/arch/x86/include/intr.h
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/x86/isa/isa_machdep.c
cvs rdiff -u -r1.105 -r1.106 src/sys/arch/x86/x86/intr.c
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/x86/x86/ioapic.c
cvs rdiff -u -r1.160 -r1.161 src/sys/arch/xen/conf/files.xen
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/xen/include/evtchn.h
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.33 -r0 src/sys/arch/xen/x86/intr.c
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/xen/xen/pci_intr_machdep.c
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/xen/xen/pciide_machdep.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.51 src/sys/arch/x86/include/intr.h:1.52
--- src/sys/arch/x86/include/intr.h:1.51	Sun Jul 16 14:02:48 2017
+++ src/sys/arch/x86/include/intr.h	Sat Nov  4 14:56:48 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.51 2017/07/16 14:02:48 cherry Exp $	*/
+/*	$NetBSD: intr.h,v 1.52 2017/11/04 14:56:48 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -117,6 +117,18 @@ struct intrsource {
  */
 
 struct intrhand {
+#if defined(XEN)
+	/*
+	 * Note: This is transitional and will go away.
+	 *
+	 * 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
 	int	(*ih_fun)(void *);
 	void	*ih_arg;
 	int	ih_level;
@@ -124,10 +136,9 @@ struct intrhand {
 	void	*ih_realarg;
 	struct	intrhand *ih_next;
 	struct	intrhand **ih_prevp;
-#if !defined(XEN)
 	int	ih_pin;
 	int	ih_slot;
-#else
+#if defined(XEN)
 	struct	intrhand *ih_evt_next;
 #endif
 	struct cpu_info *ih_cpu;

Index: src/sys/arch/x86/isa/isa_machdep.c
diff -u src/sys/arch/x86/isa/isa_machdep.c:1.36 src/sys/arch/x86/isa/isa_machdep.c:1.37
--- src/sys/arch/x86/isa/isa_machdep.c:1.36	Fri Jul 21 12:27:48 2017
+++ src/sys/arch/x86/isa/isa_machdep.c	Sat Nov  4 14:56:48 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: isa_machdep.c,v 1.36 2017/07/21 12:27:48 cherry Exp $	*/
+/*	$NetBSD: isa_machdep.c,v 1.37 2017/11/04 14:56:48 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.36 2017/07/21 12:27:48 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.37 2017/11/04 14:56:48 cherry Exp $");
 
 #include 
 #include 
@@ -245,7 +245,7 @@ isa_intr_establish_xname(isa_chipset_tag
 
 	mpih |= APIC_IRQ_LEGACY_IRQ(irq);
 
-	evtch = xen_intr_map((int *), type); /* XXX: legacy - xen just tosses irq back at us */
+	evtch = xen_pirq_alloc((intr_handle_t *), type); /* XXX: legacy - xen just tosses irq back at us */
 	if (evtch == -1)
 		return NULL;
 #if NIOAPIC > 0

Index: src/sys/arch/x86/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.105 src/sys/arch/x86/x86/intr.c:1.106
--- src/sys/arch/x86/x86/intr.c:1.105	Fri Oct 27 12:25:14 2017
+++ src/sys/arch/x86/x86/intr.c	Sat Nov  4 14:56:48 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.105 2017/10/27 12:25:14 joerg Exp $	*/
+/*	$NetBSD: intr.c,v 1.106 2017/11/04 14:56:48 cherry Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.105 2017/10/27 12:25:14 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.106 

CVS commit: src/sys/arch

2017-11-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Nov  4 10:26:14 UTC 2017

Modified Files:
src/sys/arch/x86/include: pic.h
src/sys/arch/xen/xen: evtchn.c

Log Message:
Add a PIC_XEN abstraction to evtchn.c

This allows us to get XEN interrupt code closer to unification to x86/intr.c


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/x86/include/pic.h
cvs rdiff -u -r1.73 -r1.74 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/pic.h
diff -u src/sys/arch/x86/include/pic.h:1.8 src/sys/arch/x86/include/pic.h:1.9
--- src/sys/arch/x86/include/pic.h:1.8	Mon Apr 27 07:03:58 2015
+++ src/sys/arch/x86/include/pic.h	Sat Nov  4 10:26:14 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pic.h,v 1.8 2015/04/27 07:03:58 knakahara Exp $	*/
+/*	$NetBSD: pic.h,v 1.9 2017/11/04 10:26:14 cherry Exp $	*/
 
 #ifndef _X86_PIC_H
 #define _X86_PIC_H
@@ -34,8 +34,10 @@ struct pic {
 #define PIC_MSI		3
 #define PIC_MSIX	4
 #define PIC_SOFT	5
+#define PIC_XEN		6
 
 extern struct pic i8259_pic;
 extern struct pic local_pic;
 extern struct pic softintr_pic;
+extern struct pic xen_pic;
 #endif

Index: src/sys/arch/xen/xen/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.73 src/sys/arch/xen/xen/evtchn.c:1.74
--- src/sys/arch/xen/xen/evtchn.c:1.73	Sun Jul 16 14:02:48 2017
+++ src/sys/arch/xen/xen/evtchn.c	Sat Nov  4 10:26:14 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.73 2017/07/16 14:02:48 cherry Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.74 2017/11/04 10:26:14 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.73 2017/07/16 14:02:48 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.74 2017/11/04 10:26:14 cherry Exp $");
 
 #include "opt_xen.h"
 #include "isa.h"
@@ -115,6 +115,81 @@ physdev_op_t physdev_op_notify = {
 };
 #endif
 
+static void xen_evtchn_mask(struct pic *, int);
+static void xen_evtchn_unmask(struct pic *, int);
+static void xen_evtchn_addroute(struct pic *, struct cpu_info *, int, int, int);
+static void xen_evtchn_delroute(struct pic *, struct cpu_info *, int, int, int);
+static bool xen_evtchn_trymask(struct pic *, int);
+
+
+struct pic xen_pic = {
+	.pic_name = "xenev0",
+	.pic_type = PIC_XEN,
+	.pic_vecbase = 0,
+	.pic_apicid = 0,
+	.pic_lock = __SIMPLELOCK_UNLOCKED,
+	.pic_hwmask = xen_evtchn_mask,
+	.pic_hwunmask = xen_evtchn_unmask,
+	.pic_addroute = xen_evtchn_addroute,
+	.pic_delroute = xen_evtchn_delroute,
+	.pic_trymask = xen_evtchn_trymask,
+	.pic_level_stubs = xenev_stubs,
+	.pic_edge_stubs = xenev_stubs,
+};
+	
+/*
+ * We try to stick to the traditional x86 PIC semantics wrt Xen
+ * events.
+ *
+ * PIC pins exist in a global namespace which may be hierarchical, and
+ * are mapped to a cpu bus concept called 'IRQ' numbers, which are
+ * also global, but linear. Thus a PIC, pin tuple will always map to
+ * an IRQ number. These tuples can alias to the same IRQ number, thus
+ * causing IRQ "sharing". IRQ numbers can be bound to specific CPUs,
+ * and to specific callback vector indices on the CPU called idt_vec,
+ * which are aliases to handlers meant to run on destination
+ * CPUs. This binding can also happen at interrupt time and resolved
+ * 'round-robin' between all CPUs, depending on the lapic setup. In
+ * this case, all CPUs need to have identical idt_vec->handler
+ * mappings.
+ *
+ * The job of pic_addroute() is to setup the 'wiring' between the
+ * source pin, and the destination CPU handler, ideally on a specific
+ * CPU in MP systems (or 'round-robin').
+ *
+ * On Xen, a global namespace of 'events' exist, which are initially
+ * bound to nothing. This is similar to the relationship between
+ * realworld realworld IRQ numbers wrt PIC pins, since before routing,
+ * IRQ numbers by themselves have no causal connection setup with the
+ * real world. (Except for the hardwired cases on the PC Architecture,
+ * which we ignore for the purpose of this description). However the
+ * really important routing is from pin to idt_vec. On PIC_XEN, all
+ * three (pic, irq, idt_vec) belong to the same namespace and are
+ * identical. Further, the mapping between idt_vec and the actual
+ * callback handler is setup via calls to the evtchn.h api - this
+ * last bit is analogous to x86/idt.c:idt_vec_set() on real h/w
+ *
+ * For now we handle two cases:
+ * - IPC style events - eg: timer, PV devices, etc.
+ * - dom0 physical irq bound events.
+ *
+ * In the case of IPC style events, we currently externalise the
+ * event binding by using evtchn.h functions. From the POV of
+ * PIC_XEN ,  'pin' , 'irq' and 'idt_vec' are all identical to the
+ * port number of the event.
+ *
+ * In the case of dom0 physical irq bound events, we currently
+ * event binding by exporting evtchn.h functions. From the POV of
+ * PIC_LAPIC/PIC_IOAPIC, the 'pin' is the hardware 

CVS commit: src/sys/arch/xen/include

2017-11-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Nov  4 09:31:08 UTC 2017

Modified Files:
src/sys/arch/xen/include: i82093var.h

Log Message:
protect header against recursive include


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/xen/include/i82093var.h

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/xen/include/i82093var.h
diff -u src/sys/arch/xen/include/i82093var.h:1.4 src/sys/arch/xen/include/i82093var.h:1.5
--- src/sys/arch/xen/include/i82093var.h:1.4	Mon Mar 22 16:43:08 2010
+++ src/sys/arch/xen/include/i82093var.h	Sat Nov  4 09:31:08 2017
@@ -1,4 +1,7 @@
-/*	 $NetBSD: i82093var.h,v 1.4 2010/03/22 16:43:08 cegger Exp $ */
+/*	 $NetBSD: i82093var.h,v 1.5 2017/11/04 09:31:08 cherry Exp $ */
+
+#ifndef _XEN_I82093VAR_H_
+#define _XEN_I82093VAR_H_
 
 #include "opt_xen.h"
 #define _IOAPIC_CUSTOM_RW
@@ -36,3 +39,5 @@ ioapic_write_ul(struct ioapic_softc *sc,
 	if (ret)
 		printf("PHYSDEVOP_APIC_WRITE ret %d\n", ret);
 }
+
+#endif /* !_XEN_I82093VAR_H_ */



CVS commit: src/sys/arch/xen

2017-11-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Nov  4 09:22:16 UTC 2017

Modified Files:
src/sys/arch/xen/conf: files.xen
src/sys/arch/xen/include: intr.h
src/sys/arch/xen/x86: intr.c
Added Files:
src/sys/arch/xen/x86: pintr.c

Log Message:
On XEN dom0, the function xen/x86/intr.c:xen_intr_map() is used to map
hardware interrupts to XEN callbacks called 'events'. This function
combines both the allocation and the binding.

This change is the first part of breaking up that combination into
xen_pirq_alloc() and the binding will happen as part of the
pic_addroute() callback of a new pseudo PIC_XEN

This code will be added later on.


To generate a diff of this commit:
cvs rdiff -u -r1.159 -r1.160 src/sys/arch/xen/conf/files.xen
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/xen/x86/intr.c
cvs rdiff -u -r0 -r1.1 src/sys/arch/xen/x86/pintr.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/xen/conf/files.xen
diff -u src/sys/arch/xen/conf/files.xen:1.159 src/sys/arch/xen/conf/files.xen:1.160
--- src/sys/arch/xen/conf/files.xen:1.159	Sat Nov  4 08:55:50 2017
+++ src/sys/arch/xen/conf/files.xen	Sat Nov  4 09:22:16 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: files.xen,v 1.159 2017/11/04 08:55:50 cherry Exp $
+#	$NetBSD: files.xen,v 1.160 2017/11/04 09:22:16 cherry Exp $
 #	NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp 
 #	NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp 
 
@@ -138,6 +138,7 @@ file	arch/xen/x86/xen_bus_dma.c	machdep
 file	arch/x86/x86/bus_space.c	machdep
 file	arch/xen/x86/consinit.c		machdep
 file	arch/x86/x86/identcpu.c		machdep
+file	arch/xen/x86/pintr.c		machdep & dom0ops
 file	arch/xen/x86/intr.c		machdep
 file	arch/xen/x86/xen_ipi.c		multiprocessor
 file	arch/x86/x86/idt.c		machdep

Index: src/sys/arch/xen/include/intr.h
diff -u src/sys/arch/xen/include/intr.h:1.42 src/sys/arch/xen/include/intr.h:1.43
--- src/sys/arch/xen/include/intr.h:1.42	Sun Jul 16 14:02:48 2017
+++ src/sys/arch/xen/include/intr.h	Sat Nov  4 09:22:16 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.42 2017/07/16 14:02:48 cherry Exp $	*/
+/*	$NetBSD: intr.h,v 1.43 2017/11/04 09:22:16 cherry Exp $	*/
 /*	NetBSD intr.h,v 1.15 2004/10/31 10:39:34 yamt Exp	*/
 
 /*-
@@ -61,7 +61,9 @@ struct evtsource {
 };
 
 extern struct intrstub xenev_stubs[];
-
+extern int irq2vect[256];
+extern int vect2irq[256];
+extern int irq2port[NR_EVENT_CHANNELS];
 
 #ifdef MULTIPROCESSOR
 int xen_intr_biglock_wrapper(void *);
@@ -70,6 +72,9 @@ int xen_intr_biglock_wrapper(void *);
 int xen_intr_map(int *, int);
 struct pic *intr_findpic(int);
 void intr_add_pcibus(struct pcibus_attach_args *);
+#if defined(DOM0OPS) || NPCI > 0
+int xen_pirq_alloc(intr_handle_t *, int);
+#endif /* defined(DOM0OPS) || NPCI > 0 */
 
 #ifdef MULTIPROCESSOR
 void xen_ipi_init(void);

Index: src/sys/arch/xen/x86/intr.c
diff -u src/sys/arch/xen/x86/intr.c:1.32 src/sys/arch/xen/x86/intr.c:1.33
--- src/sys/arch/xen/x86/intr.c:1.32	Sun Jul 16 06:14:24 2017
+++ src/sys/arch/xen/x86/intr.c	Sat Nov  4 09:22:16 2017
@@ -103,7 +103,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.32 2017/07/16 06:14:24 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.33 2017/11/04 09:22:16 cherry Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -130,18 +130,9 @@ __KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.3
 #include "acpica.h"
 #include "ioapic.h"
 #include "opt_mpbios.h"
-/* for x86/i8259.c */
-struct intrstub i8259_stubs[NUM_LEGACY_IRQS] = {{0,0}};
-#if NIOAPIC > 0
-/* for x86/ioapic.c */
-struct intrstub ioapic_edge_stubs[MAX_INTR_SOURCES] = {{0,0}};
-struct intrstub ioapic_level_stubs[MAX_INTR_SOURCES] = {{0,0}};
-struct intrstub x2apic_edge_stubs[MAX_INTR_SOURCES] = {{0,0}};
-struct intrstub x2apic_level_stubs[MAX_INTR_SOURCES] = {{0,0}};
 
+#if NIOAPIC > 0
 #include 
-int irq2vect[256] = {0};
-int vect2irq[256] = {0};
 #endif /* NIOAPIC */
 #if NACPICA > 0
 #include 

Added files:

Index: src/sys/arch/xen/x86/pintr.c
diff -u /dev/null src/sys/arch/xen/x86/pintr.c:1.1
--- /dev/null	Sat Nov  4 09:22:17 2017
+++ src/sys/arch/xen/x86/pintr.c	Sat Nov  4 09:22:16 2017
@@ -0,0 +1,213 @@
+/*	NetBSD: intr.c,v 1.15 2004/04/10 14:49:55 kochi Exp 	*/
+
+/*
+ * Copyright 2002 (c) Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Frank van der Linden for Wasabi Systems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials 

CVS commit: src/sys/arch/xen/conf

2017-11-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Nov  4 08:55:50 UTC 2017

Modified Files:
src/sys/arch/xen/conf: files.xen

Log Message:
On XEN PV, the ISA 8259A PIC is only used on dom0


To generate a diff of this commit:
cvs rdiff -u -r1.158 -r1.159 src/sys/arch/xen/conf/files.xen

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/xen/conf/files.xen
diff -u src/sys/arch/xen/conf/files.xen:1.158 src/sys/arch/xen/conf/files.xen:1.159
--- src/sys/arch/xen/conf/files.xen:1.158	Sat Nov  4 08:50:47 2017
+++ src/sys/arch/xen/conf/files.xen	Sat Nov  4 08:55:50 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: files.xen,v 1.158 2017/11/04 08:50:47 cherry Exp $
+#	$NetBSD: files.xen,v 1.159 2017/11/04 08:55:50 cherry Exp $
 #	NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp 
 #	NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp 
 
@@ -256,7 +256,7 @@ include "dev/apm/files.apm"
 include "dev/acpi/files.acpi"
 file	arch/xen/xen/xen_acpi_machdep.c	acpi
 file	arch/x86/x86/mpacpi.c		acpi
-file	arch/x86/x86/i8259.c
+file	arch/x86/x86/i8259.c		dom0ops
 
 # Stubs for x86 routines not included in the system
 file	arch/x86/x86/x86_stub.c



CVS commit: src/sys/arch

2017-11-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Nov  4 08:50:48 UTC 2017

Modified Files:
src/sys/arch/amd64/amd64: machdep.c
src/sys/arch/amd64/include: segments.h
src/sys/arch/i386/i386: machdep.c
src/sys/arch/i386/include: segments.h
src/sys/arch/x86/x86: idt.c
src/sys/arch/xen/conf: files.xen

Log Message:
In XEN PV, the idt vector table is not required to be altered at
runtime, since only entries for exceptions/traps are registered with
the hypervisor and interrupts are managed via a completely different
mechanism.

This change uses the idt_vec_reserve() mechanism nevertheless,
modifying it slightly to only do namespace management in XEN, while on
native it will continue to do idt entry init as before.

Rationale: Consistent API usage and potential future merging of
XEN/non-XEN code.

There are no functional changes in this commit.


To generate a diff of this commit:
cvs rdiff -u -r1.274 -r1.275 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/amd64/include/segments.h
cvs rdiff -u -r1.797 -r1.798 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.62 -r1.63 src/sys/arch/i386/include/segments.h
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/x86/x86/idt.c
cvs rdiff -u -r1.157 -r1.158 src/sys/arch/xen/conf/files.xen

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.274 src/sys/arch/amd64/amd64/machdep.c:1.275
--- src/sys/arch/amd64/amd64/machdep.c:1.274	Sun Oct 29 10:25:28 2017
+++ src/sys/arch/amd64/amd64/machdep.c	Sat Nov  4 08:50:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.274 2017/10/29 10:25:28 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.275 2017/11/04 08:50:47 cherry Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.274 2017/10/29 10:25:28 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.275 2017/11/04 08:50:47 cherry Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -1747,6 +1747,7 @@ init_x86_64(paddr_t first_avail)
 		GSEL(GCODE_SEL, SEL_KPL));
 #else /* XEN */
 		pmap_changeprot_local(idt_vaddr, VM_PROT_READ|VM_PROT_WRITE);
+		idt_vec_reserve(x);
 		xen_idt[xen_idt_idx].vector = x;
 
 		switch (x) {
@@ -1776,6 +1777,7 @@ init_x86_64(paddr_t first_avail)
 	setgate([128], (osyscall), 0, SDT_SYS386IGT, SEL_UPL,
 	GSEL(GCODE_SEL, SEL_KPL));
 #else
+	idt_vec_reserve(128);
 	xen_idt[xen_idt_idx].vector = 128;
 	xen_idt[xen_idt_idx].flags = SEL_KPL;
 	xen_idt[xen_idt_idx].cs = GSEL(GCODE_SEL, SEL_KPL);

Index: src/sys/arch/amd64/include/segments.h
diff -u src/sys/arch/amd64/include/segments.h:1.32 src/sys/arch/amd64/include/segments.h:1.33
--- src/sys/arch/amd64/include/segments.h:1.32	Wed Nov  1 07:14:29 2017
+++ src/sys/arch/amd64/include/segments.h	Sat Nov  4 08:50:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: segments.h,v 1.32 2017/11/01 07:14:29 maxv Exp $	*/
+/*	$NetBSD: segments.h,v 1.33 2017/11/04 08:50:47 cherry Exp $	*/
 
 /*
  * Copyright (c) 1990 The Regents of the University of California.
@@ -245,12 +245,12 @@ void set_mem_segment(struct mem_segment_
 void cpu_init_idt(void);
 void update_descriptor(void *, void *);
 
-#if !defined(XEN)
+
 void idt_vec_reserve(int);
 int idt_vec_alloc(int, int);
 void idt_vec_set(int, void (*)(void));
 void idt_vec_free(int);
-#endif
+
 
 struct lwp;
 void cpu_segregs64_zero(struct lwp *);

Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.797 src/sys/arch/i386/i386/machdep.c:1.798
--- src/sys/arch/i386/i386/machdep.c:1.797	Sun Oct 29 10:01:21 2017
+++ src/sys/arch/i386/i386/machdep.c	Sat Nov  4 08:50:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.797 2017/10/29 10:01:21 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.798 2017/11/04 08:50:47 cherry Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009, 2017
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.797 2017/10/29 10:01:21 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.798 2017/11/04 08:50:47 cherry Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_freebsd.h"
@@ -1355,6 +1355,7 @@ init386(paddr_t first_avail)
 	xen_idt_idx = 0;
 	for (x = 0; x < 32; x++) {
 		KASSERT(xen_idt_idx < MAX_XEN_IDT);
+		idt_vec_reserve(x);
 		xen_idt[xen_idt_idx].vector = x;
 
 		switch (x) {
@@ -1377,6 +1378,7 @@ init386(paddr_t first_avail)
 		xen_idt_idx++;
 	}
 	KASSERT(xen_idt_idx < MAX_XEN_IDT);
+	idt_vec_reserve(128);
 	xen_idt[xen_idt_idx].vector = 128;
 	xen_idt[xen_idt_idx].flags = SEL_UPL;
 	xen_idt[xen_idt_idx].cs = GSEL(GCODE_SEL, SEL_KPL);

Index: src/sys/arch/i386/include/segments.h
diff -u src/sys/arch/i386/include/segments.h:1.62 src/sys/arch/i386/include/segments.h:1.63
--- src/sys/arch/i386/include/segments.h:1.62	Sun Sep 17 09:41:35 2017
+++ 

CVS commit: src/sys/arch/xen/conf

2017-11-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Nov  4 07:01:45 UTC 2017

Modified Files:
src/sys/arch/xen/conf: files.xen

Log Message:
opt_intrdebug.h - this unbreaks the i386 DOMU build under some conditions


To generate a diff of this commit:
cvs rdiff -u -r1.156 -r1.157 src/sys/arch/xen/conf/files.xen

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/xen/conf/files.xen
diff -u src/sys/arch/xen/conf/files.xen:1.156 src/sys/arch/xen/conf/files.xen:1.157
--- src/sys/arch/xen/conf/files.xen:1.156	Tue Aug 15 08:51:38 2017
+++ src/sys/arch/xen/conf/files.xen	Sat Nov  4 07:01:45 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: files.xen,v 1.156 2017/08/15 08:51:38 maxv Exp $
+#	$NetBSD: files.xen,v 1.157 2017/11/04 07:01:45 cherry Exp $
 #	NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp 
 #	NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp 
 
@@ -15,6 +15,9 @@ defparam opt_kernbase.h	KERNBASE
 # options for MP configuration through the MP spec
 defflag opt_mpbios.h MPBIOS MPVERBOSE MPDEBUG MPBIOS_SCANPCI
 
+# Interrupt debug
+defflag opt_intrdebug.h	INTRDEBUG
+
 # delay before cpu_reset() for reboot.
 defparam		CPURESET_DELAY
 



CVS commit: src/sys/arch/x86/x86

2017-09-03 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Sep  3 06:24:49 UTC 2017

Modified Files:
src/sys/arch/x86/x86: intr.c

Log Message:
Remove redundant static function declaration


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/sys/arch/x86/x86/intr.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/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.102 src/sys/arch/x86/x86/intr.c:1.103
--- src/sys/arch/x86/x86/intr.c:1.102	Mon Jul 31 18:54:40 2017
+++ src/sys/arch/x86/x86/intr.c	Sun Sep  3 06:24:49 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.102 2017/07/31 18:54:40 maxv Exp $	*/
+/*	$NetBSD: intr.c,v 1.103 2017/09/03 06:24:49 cherry Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.102 2017/07/31 18:54:40 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.103 2017/09/03 06:24:49 cherry Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -247,8 +247,6 @@ static struct intrsource *intr_get_io_in
 static void intr_free_io_intrsource_direct(struct intrsource *);
 static int intr_num_handlers(struct intrsource *);
 
-static const char *legacy_intr_string(int, char *, size_t, struct pic *);
-
 static int intr_find_unused_slot(struct cpu_info *, int *);
 static void intr_activate_xcall(void *, void *);
 static void intr_deactivate_xcall(void *, void *);



CVS commit: src/sys/dev/pci

2017-08-02 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Aug  2 08:39:14 UTC 2017

Modified Files:
src/sys/dev/pci: files.pci virtio.c virtiovar.h
Added Files:
src/sys/dev/pci: files.virtio virtio_pci.c

Log Message:
Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


To generate a diff of this commit:
cvs rdiff -u -r1.388 -r1.389 src/sys/dev/pci/files.pci
cvs rdiff -u -r0 -r1.1 src/sys/dev/pci/files.virtio \
src/sys/dev/pci/virtio_pci.c
cvs rdiff -u -r1.28 -r1.29 src/sys/dev/pci/virtio.c
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/pci/virtiovar.h

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

Modified files:

Index: src/sys/dev/pci/files.pci
diff -u src/sys/dev/pci/files.pci:1.388 src/sys/dev/pci/files.pci:1.389
--- src/sys/dev/pci/files.pci:1.388	Thu Apr 13 10:37:36 2017
+++ src/sys/dev/pci/files.pci	Wed Aug  2 08:39:14 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: files.pci,v 1.388 2017/04/13 10:37:36 knakahara Exp $
+#	$NetBSD: files.pci,v 1.389 2017/08/02 08:39:14 cherry Exp $
 #
 # Config file and device description for machine-independent PCI code.
 # Included by ports that need it.  Requires that the SCSI files be
@@ -1137,29 +1137,11 @@ device  sisfb: wsemuldisplaydev, rasops8
 attach  sisfb at pci
 filedev/pci/sisfb.c		sisfb	needs-flag
 
-# VirtIO
-device	virtio {}
-attach	virtio at pci
-file	dev/pci/virtio.c	virtio
-
-attach	ld at virtio with ld_virtio
-file	dev/pci/ld_virtio.c	ld_virtio
-
-device	viomb
-attach	viomb at virtio
-file	dev/pci/viomb.c		viomb
-
-device	vioif: ether, ifnet, arp
-attach	vioif at virtio
-file	dev/pci/if_vioif.c	vioif
-
-device	viornd
-attach	viornd at virtio
-file	dev/pci/viornd.c	viornd
-
-device	vioscsi: scsi
-attach	vioscsi at virtio
-file	dev/pci/vioscsi.c	vioscsi
+# VirtIO: XXX: move to dev/vmm/virtio
+include "dev/pci/files.virtio"
+
+attach	virtio at pci with virtio_pci
+file	dev/pci/virtio_pci.c	virtio_pci
 
 # Silicon Motion SM712(LynxEM+) frame buffer
 device	lynxfb: wsemuldisplaydev, rasops16

Index: src/sys/dev/pci/virtio.c
diff -u src/sys/dev/pci/virtio.c:1.28 src/sys/dev/pci/virtio.c:1.29
--- src/sys/dev/pci/virtio.c:1.28	Thu Jun  1 02:45:11 2017
+++ src/sys/dev/pci/virtio.c	Wed Aug  2 08:39:14 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: virtio.c,v 1.28 2017/06/01 02:45:11 chs Exp $	*/
+/*	$NetBSD: virtio.c,v 1.29 2017/08/02 08:39:14 cherry Exp $	*/
 
 /*
  * Copyright (c) 2010 Minoura Makoto.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.28 2017/06/01 02:45:11 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.29 2017/08/02 08:39:14 cherry Exp $");
 
 #include 
 #include 
@@ -43,15 +43,11 @@ __KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1
 
 #define VIRTIO_PRIVATE
 
-#include 
-#include 
+#include  /* XXX: move to non-pci */
+#include  /* XXX: move to non-pci */
 
 #define MINSEG_INDIRECT		2 /* use indirect if nsegs >= this value */
 
-static int	virtio_match(device_t, cfdata_t, void *);
-static void	virtio_attach(device_t, device_t, void *);
-static int	virtio_rescan(device_t, const char *, const int *);
-static int	virtio_detach(device_t, int);
 static int	virtio_intr(void *arg);
 static int	virtio_msix_queue_intr(void *);
 static int	virtio_msix_config_intr(void *);
@@ -66,9 +62,6 @@ static void	virtio_soft_intr(void *arg);
 static void	virtio_init_vq(struct virtio_softc *,
 		struct virtqueue *, const bool);
 
-CFATTACH_DECL3_NEW(virtio, sizeof(struct virtio_softc),
-virtio_match, virtio_attach, virtio_detach, NULL, virtio_rescan, NULL,
-DVF_DETACH_SHUTDOWN);
 
 /* we use the legacy virtio spec, so the pci registers are host native
  * byte order, not pci (i.e. LE) byte order */
@@ -109,7 +102,7 @@ nbo_bus_space_write_4(bus_space_tag_t sp
 #define	REG_LO_OFF	0
 #endif
 
-static void
+void
 virtio_set_status(struct virtio_softc *sc, int status)
 {
 	int old = 0;
@@ -121,42 +114,6 @@ virtio_set_status(struct virtio_softc *s
 			  status|old);
 }
 
-#define virtio_device_reset(sc)	virtio_set_status((sc), 0)
-
-static int
-virtio_match(device_t parent, cfdata_t match, void *aux)
-{
-	struct pci_attach_args *pa;
-
-	pa = (struct pci_attach_args *)aux;
-	switch (PCI_VENDOR(pa->pa_id)) {
-	case PCI_VENDOR_QUMRANET:
-		if ((PCI_PRODUCT_QUMRANET_VIRTIO_1000 <=
-		 PCI_PRODUCT(pa->pa_id)) &&
-		(PCI_PRODUCT(pa->pa_id) <=
-		 PCI_PRODUCT_QUMRANET_VIRTIO_103F))
-			return 1;
-		break;
-	}
-
-	return 0;
-}
-
-static const char *virtio_device_name[] = {
-	"Unknown (0)",			/* 0 */
-	"Network",			/* 1 */
-	"Block",			/* 2 */
-	"Console",			/* 3 */
-	"Entropy",			/* 4 */
-	"Memory Balloon",		/* 5 */
-	"I/O Memory",			/* 6 */
-	"Remote Processor Messaging",	/* 7 */
-	"SCSI",/* 8 */
-	"9P Transport",			/* 9 */
-	"mac80211 wlan",		/* 10 */
-};
-#define NDEVNAMES	__arraycount(virtio_device_name)
-
 #define VIRTIO_MSIX_CONFIG_VECTOR_INDEX	0
 #define 

CVS commit: src/sys/arch/xen/xen

2017-07-28 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Jul 28 07:42:41 UTC 2017

Modified Files:
src/sys/arch/xen/xen: pci_intr_machdep.c

Log Message:
APIC related macros are mixed with IOAPIC related ones.
This needs separation.

Until then, band-aid it.

This fixes pci-passthrough build failures on XEN3_DOMU pointed out by
msaitoh@


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/xen/xen/pci_intr_machdep.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/xen/xen/pci_intr_machdep.c
diff -u src/sys/arch/xen/xen/pci_intr_machdep.c:1.19 src/sys/arch/xen/xen/pci_intr_machdep.c:1.20
--- src/sys/arch/xen/xen/pci_intr_machdep.c:1.19	Sun Jul 16 14:02:48 2017
+++ src/sys/arch/xen/xen/pci_intr_machdep.c	Fri Jul 28 07:42:41 2017
@@ -1,4 +1,4 @@
-/*  $NetBSD: pci_intr_machdep.c,v 1.19 2017/07/16 14:02:48 cherry Exp $  */
+/*  $NetBSD: pci_intr_machdep.c,v 1.20 2017/07/28 07:42:41 cherry Exp $  */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.19 2017/07/16 14:02:48 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.20 2017/07/28 07:42:41 cherry Exp $");
 
 #include 
 #include 
@@ -61,6 +61,15 @@ __KERNEL_RCSID(0, "$NetBSD: pci_intr_mac
 #include 
 #endif
 
+/* XXX: cherry@: Hack - this is a symptom of lapic vs. ioapic
+ * needing more code separation.
+ */
+#if NIOAPIC > 0
+#define IRQ_LEGACY_IRQ(_irq) APIC_IRQ_LEGACY_IRQ(_irq)
+#else
+#define IRQ_LEGACY_IRQ(_irq) (_irq & 0xff)
+#endif
+
 int
 pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
 {
@@ -157,7 +166,7 @@ pci_intr_string(pci_chipset_tag_t pc, pc
 {
 	int evtch;
 
-	evtch = get_pirq_to_evtch(APIC_IRQ_LEGACY_IRQ(ih));
+	evtch = get_pirq_to_evtch(IRQ_LEGACY_IRQ(ih));
 #if NIOAPIC > 0
 	struct ioapic_softc *pic;
 	if (ih & APIC_INT_VIA_APIC) {
@@ -217,8 +226,8 @@ pci_intr_establish(pci_chipset_tag_t pci
 #endif
 		snprintf(evname, sizeof(evname), "irq%"PRIu64, intrh);
 
-	return (void *)pirq_establish(APIC_IRQ_LEGACY_IRQ(intrh),
-	get_pirq_to_evtch(APIC_IRQ_LEGACY_IRQ(intrh)), func, arg, level, evname);
+	return (void *)pirq_establish(IRQ_LEGACY_IRQ(intrh),
+	get_pirq_to_evtch(IRQ_LEGACY_IRQ(intrh)), func, arg, level, evname);
 }
 
 void



CVS commit: src/sys/arch/x86/isa

2017-07-21 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Jul 21 12:27:48 UTC 2017

Modified Files:
src/sys/arch/x86/isa: isa_machdep.c

Log Message:
Fix uninitialised use of variable mpih

Pointed out by joerg@


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/x86/isa/isa_machdep.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/isa/isa_machdep.c
diff -u src/sys/arch/x86/isa/isa_machdep.c:1.35 src/sys/arch/x86/isa/isa_machdep.c:1.36
--- src/sys/arch/x86/isa/isa_machdep.c:1.35	Sun Jul 16 06:14:23 2017
+++ src/sys/arch/x86/isa/isa_machdep.c	Fri Jul 21 12:27:48 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: isa_machdep.c,v 1.35 2017/07/16 06:14:23 cherry Exp $	*/
+/*	$NetBSD: isa_machdep.c,v 1.36 2017/07/21 12:27:48 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.35 2017/07/16 06:14:23 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.36 2017/07/21 12:27:48 cherry Exp $");
 
 #include 
 #include 
@@ -211,7 +211,7 @@ isa_intr_establish_xname(isa_chipset_tag
 	struct pic *pic;
 	int pin;
 #if NIOAPIC > 0
-	intr_handle_t mpih;
+	intr_handle_t mpih = 0;
 	struct ioapic_softc *ioapic = NULL;
 #endif
 



CVS commit: src/sys/arch

2017-07-16 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Jul 16 14:02:48 UTC 2017

Modified Files:
src/sys/arch/amd64/amd64: genassym.cf vector.S
src/sys/arch/i386/i386: genassym.cf vector.S
src/sys/arch/x86/include: cpu.h intr.h
src/sys/arch/xen/conf: files.xen
src/sys/arch/xen/include: intr.h
src/sys/arch/xen/xen: evtchn.c pci_intr_machdep.c xenevt.c
Removed Files:
src/sys/arch/xen/xen: isa_machdep.c

Log Message:
Unify the xen and native x86/ interrupt setup functions and
spl traversal data structures.

This is towards PVHVM.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/sys/arch/amd64/amd64/genassym.cf
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/amd64/amd64/vector.S
cvs rdiff -u -r1.99 -r1.100 src/sys/arch/i386/i386/genassym.cf
cvs rdiff -u -r1.69 -r1.70 src/sys/arch/i386/i386/vector.S
cvs rdiff -u -r1.73 -r1.74 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/x86/include/intr.h
cvs rdiff -u -r1.148 -r1.149 src/sys/arch/xen/conf/files.xen
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.72 -r1.73 src/sys/arch/xen/xen/evtchn.c
cvs rdiff -u -r1.27 -r0 src/sys/arch/xen/xen/isa_machdep.c
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/xen/xen/pci_intr_machdep.c
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/xen/xen/xenevt.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/genassym.cf
diff -u src/sys/arch/amd64/amd64/genassym.cf:1.60 src/sys/arch/amd64/amd64/genassym.cf:1.61
--- src/sys/arch/amd64/amd64/genassym.cf:1.60	Fri Nov 20 11:58:00 2015
+++ src/sys/arch/amd64/amd64/genassym.cf	Sun Jul 16 14:02:48 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: genassym.cf,v 1.60 2015/11/20 11:58:00 maxv Exp $
+#	$NetBSD: genassym.cf,v 1.61 2017/07/16 14:02:48 cherry Exp $
 
 #
 # Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -278,11 +278,7 @@ endif
 define	IH_FUN			offsetof(struct intrhand, ih_fun)
 define	IH_ARG			offsetof(struct intrhand, ih_arg)
 define  IH_LEVEL		offsetof(struct intrhand, ih_level)
-ifdef XEN
-define IH_IPL_NEXT		offsetof(struct intrhand, ih_ipl_next)
-else
 define	IH_NEXT			offsetof(struct intrhand, ih_next)
-endif
 
 ifdef COMPAT_NETBSD32
 define	SC_FS32			offsetof(struct netbsd32_sigcontext, sc_fs)
@@ -299,13 +295,6 @@ define  LINUX32_SYS_sigreturn		LINUX32_S
 define  LINUX32_SYS_exit		LINUX32_SYS_exit
 endif
 
-ifdef XEN
-define	SIZEOF_IPLSOURCE	sizeof(struct iplsource)
-define	IS_RECURSE  offsetof(struct iplsource, ipl_recurse)
-define	IS_RESUME   offsetof(struct iplsource, ipl_resume)
-define	IS_HANDLERS offsetof(struct iplsource, ipl_handlers)
-define	EV_EVCNTL	offsetof(struct evcnt, ev_count)
-else
 define	IS_RECURSE	offsetof(struct intrsource, is_recurse)
 define	IS_RESUME	offsetof(struct intrsource, is_resume)
 define	IS_EVCNT	offsetof(struct intrsource, is_evcnt.ev_count)
@@ -316,7 +305,6 @@ define	IS_PIN		offsetof(struct intrsourc
 define	IS_TYPE		offsetof(struct intrsource, is_type)
 define	IS_MAXLEVEL	offsetof(struct intrsource, is_maxlevel)
 define	IS_LWP			offsetof(struct intrsource, is_lwp)
-endif
 
 define	IPL_NONE		IPL_NONE
 define	IPL_PREEMPT		IPL_PREEMPT

Index: src/sys/arch/amd64/amd64/vector.S
diff -u src/sys/arch/amd64/amd64/vector.S:1.49 src/sys/arch/amd64/amd64/vector.S:1.50
--- src/sys/arch/amd64/amd64/vector.S:1.49	Tue May 23 08:54:38 2017
+++ src/sys/arch/amd64/amd64/vector.S	Sun Jul 16 14:02:48 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vector.S,v 1.49 2017/05/23 08:54:38 nonaka Exp $	*/
+/*	$NetBSD: vector.S,v 1.50 2017/07/16 14:02:48 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -829,7 +829,9 @@ LABEL(x2apic_level_stubs)
 END(x2apic_level_stubs)
 #endif
 
-#else	/* !XEN */
+#endif /* !defined(XEN) */
+
+#if defined(XEN)
 /* Resume/recurse procedures for spl() */
 #define	XENINTRSTUB(name, num, early_ack, late_ack, mask, unmask, level_mask) \
 IDTVEC(recurse_ ## name ## num)		;\
@@ -851,7 +853,7 @@ IDTVEC(resume_ ## name ## num)		\
 	movq	IH_ARG(%rbx),%rdi	;\
 	movq	%rsp,%rsi		;\
 	call	*IH_FUN(%rbx)		/* call it */			;\
-	movq	IH_IPL_NEXT(%rbx),%rbx	/* next handler in chain */	;\
+	movq	IH_NEXT(%rbx),%rbx	/* next handler in chain */	;\
 	testq	%rbx,%rbx		;\
 	jnz	6b			;\
 5:	\

Index: src/sys/arch/i386/i386/genassym.cf
diff -u src/sys/arch/i386/i386/genassym.cf:1.99 src/sys/arch/i386/i386/genassym.cf:1.100
--- src/sys/arch/i386/i386/genassym.cf:1.99	Wed Aug 26 03:00:53 2015
+++ src/sys/arch/i386/i386/genassym.cf	Sun Jul 16 14:02:48 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: genassym.cf,v 1.99 2015/08/26 03:00:53 uebayasi Exp $
+#	$NetBSD: genassym.cf,v 1.100 2017/07/16 14:02:48 cherry Exp $
 
 #
 # Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -250,11 +250,7 @@ endif
 define	IH_FUN			offsetof(struct intrhand, ih_fun)
 define	IH_ARG			

CVS commit: src/sys/arch

2017-07-16 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Jul 16 06:14:24 UTC 2017

Modified Files:
src/sys/arch/x86/isa: isa_machdep.c
src/sys/arch/xen/include: intr.h pci_machdep.h
src/sys/arch/xen/x86: intr.c
src/sys/arch/xen/xen: isa_machdep.c pci_intr_machdep.c pciback.c
pciide_machdep.c

Log Message:
Remove the xen specific interrupt type for the x86 intr_handle_t
For this to work, we use the evtchn.c:get_pirq_to_evtchn() glue
function to make things easier.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/x86/isa/isa_machdep.c
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/xen/include/pci_machdep.h
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/xen/x86/intr.c
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/xen/xen/isa_machdep.c
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/xen/xen/pci_intr_machdep.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/xen/xen/pciback.c
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/xen/xen/pciide_machdep.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/isa/isa_machdep.c
diff -u src/sys/arch/x86/isa/isa_machdep.c:1.34 src/sys/arch/x86/isa/isa_machdep.c:1.35
--- src/sys/arch/x86/isa/isa_machdep.c:1.34	Sat Oct 15 16:46:14 2016
+++ src/sys/arch/x86/isa/isa_machdep.c	Sun Jul 16 06:14:23 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: isa_machdep.c,v 1.34 2016/10/15 16:46:14 jdolecek Exp $	*/
+/*	$NetBSD: isa_machdep.c,v 1.35 2017/07/16 06:14:23 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.34 2016/10/15 16:46:14 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.35 2017/07/16 06:14:23 cherry Exp $");
 
 #include 
 #include 
@@ -212,7 +212,7 @@ isa_intr_establish_xname(isa_chipset_tag
 	int pin;
 #if NIOAPIC > 0
 	intr_handle_t mpih;
-	struct ioapic_softc *ioapic;
+	struct ioapic_softc *ioapic = NULL;
 #endif
 
 	pin = irq;
@@ -237,20 +237,48 @@ isa_intr_establish_xname(isa_chipset_tag
 			printf("isa_intr_establish: no MP mapping found\n");
 	}
 #endif
+#if defined(XEN)
+	KASSERT(APIC_IRQ_ISLEGACY(irq));
+
+	int evtch;
+	char evname[16];
+
+	mpih |= APIC_IRQ_LEGACY_IRQ(irq);
+
+	evtch = xen_intr_map((int *), 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);
+
+	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);
+#else /* defined(XEN) */
 	return intr_establish_xname(irq, pic, pin, type, level, ih_fun, ih_arg,
 	false, xname);
+#endif
+
 }
 
 /* Deregister an interrupt handler. */
 void
 isa_intr_disestablish(isa_chipset_tag_t ic, void *arg)
 {
+#if !defined(XEN)
 	struct intrhand *ih = arg;
 
 	if (!LEGAL_IRQ(ih->ih_pin))
 		panic("intr_disestablish: bogus irq");
 
 	intr_disestablish(ih);
+#endif	
 }
 
 void

Index: src/sys/arch/xen/include/intr.h
diff -u src/sys/arch/xen/include/intr.h:1.40 src/sys/arch/xen/include/intr.h:1.41
--- src/sys/arch/xen/include/intr.h:1.40	Tue May 23 08:54:39 2017
+++ src/sys/arch/xen/include/intr.h	Sun Jul 16 06:14:24 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.40 2017/05/23 08:54:39 nonaka Exp $	*/
+/*	$NetBSD: intr.h,v 1.41 2017/07/16 06:14:24 cherry Exp $	*/
 /*	NetBSD intr.h,v 1.15 2004/10/31 10:39:34 yamt Exp	*/
 
 /*-
@@ -175,7 +175,7 @@ int xen_intr_map(int *, int);
 #ifdef INTRDEBUG
 void intr_printconfig(void);
 #endif
-int intr_find_mpmapping(int, int, struct xen_intr_handle *);
+int intr_find_mpmapping(int, int, intr_handle_t *);
 struct pic *intr_findpic(int);
 void intr_add_pcibus(struct pcibus_attach_args *);
 

Index: src/sys/arch/xen/include/pci_machdep.h
diff -u src/sys/arch/xen/include/pci_machdep.h:1.18 src/sys/arch/xen/include/pci_machdep.h:1.19
--- src/sys/arch/xen/include/pci_machdep.h:1.18	Mon Apr  4 20:37:55 2011
+++ src/sys/arch/xen/include/pci_machdep.h	Sun Jul 16 06:14:24 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_machdep.h,v 1.18 2011/04/04 20:37:55 dyoung Exp $ */
+/* $NetBSD: pci_machdep.h,v 1.19 2017/07/16 06:14:24 cherry Exp $ */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -60,7 +60,7 @@
 /*
  * Types provided to machine-independent PCI code
  */
-typedef struct xen_intr_handle pci_intr_handle_t;
+typedef intr_handle_t pci_intr_handle_t;
 
 #include 
 

Index: src/sys/arch/xen/x86/intr.c
diff -u src/sys/arch/xen/x86/intr.c:1.31 src/sys/arch/xen/x86/intr.c:1.32
--- src/sys/arch/xen/x86/intr.c:1.31	Tue May 23 08:54:39 2017
+++ src/sys/arch/xen/x86/intr.c	Sun Jul 16 06:14:24 2017
@@ -103,7 +103,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.31 

  1   2   3   >