Module Name:    src
Committed By:   bouyer
Date:           Thu Apr 16 08:46:36 UTC 2020

Modified Files:
        src/sys/arch/amd64/amd64 [bouyer-xenpvh]: vector.S
        src/sys/arch/amd64/conf [bouyer-xenpvh]: Makefile.amd64 XEN3_DOM0
            files.amd64 std.amd64 std.xen
        src/sys/arch/i386/conf [bouyer-xenpvh]: Makefile.i386 XEN3PAE_DOM0
            files.i386 std.i386
        src/sys/arch/i386/i386 [bouyer-xenpvh]: machdep.c vector.S
        src/sys/arch/x86/conf [bouyer-xenpvh]: files.x86
        src/sys/arch/x86/include [bouyer-xenpvh]: intr.h
        src/sys/arch/x86/x86 [bouyer-xenpvh]: cpu_ucode.c cpu_ucode_amd.c
            cpu_ucode_intel.c lapic.c mainbus.c
        src/sys/arch/xen/conf [bouyer-xenpvh]: Makefile.xen files.xen std.xen
        src/sys/arch/xen/include [bouyer-xenpvh]: hypervisor.h intr.h xenpmap.h
        src/sys/arch/xen/x86 [bouyer-xenpvh]: hypervisor_machdep.c xen_intr.c
            xen_ipi.c xen_mainbus.c
        src/sys/arch/xen/xen [bouyer-xenpvh]: evtchn.c if_xennet_xenbus.c
            xbd_xenbus.c xen_machdep.c xencons.c
        src/sys/arch/xen/xenbus [bouyer-xenpvh]: xenbus_comms.c xenbus_dev.c
Added Files:
        src/sys/arch/amd64/conf [bouyer-xenpvh]: GENERIC_XENHVM
        src/sys/arch/amd64/include/xen [bouyer-xenpvh]: hypercalls.h
        src/sys/arch/i386/conf [bouyer-xenpvh]: GENERIC_XENHVM
        src/sys/arch/i386/include/xen [bouyer-xenpvh]: hypercalls.h
        src/sys/arch/xen/conf [bouyer-xenpvh]: files.xen.pv
Removed Files:
        src/sys/arch/xen/include/amd64 [bouyer-xenpvh]: hypercalls.h
        src/sys/arch/xen/include/i386 [bouyer-xenpvh]: hypercalls.h

Log Message:
Reorganise sources to make it possible to include Xen PVHVM support in
native kernels. Among others:
- move xen/include/amd64/hypercall.h to amd64/include/xen and
  xen/include/i386/hypercall.h to i386/include/xen
- exclude some native files from the build for xenpv
- add xen to "machine" config statement for amd64 and i386
- split arch/xen/conf/files.xen to arch/xen/conf/files.xen (for pv drivers)
  and arch/xen/conf/files.xen.pv (for full pv support)
- add GENERIC_XENHVM kernel config which includes GENERIC and add Xen PV
  drivers.


To generate a diff of this commit:
cvs rdiff -u -r1.73.6.3 -r1.73.6.4 src/sys/arch/amd64/amd64/vector.S
cvs rdiff -u -r0 -r1.1.2.1 src/sys/arch/amd64/conf/GENERIC_XENHVM
cvs rdiff -u -r1.82 -r1.82.2.1 src/sys/arch/amd64/conf/Makefile.amd64
cvs rdiff -u -r1.175.4.1 -r1.175.4.2 src/sys/arch/amd64/conf/XEN3_DOM0
cvs rdiff -u -r1.115 -r1.115.4.1 src/sys/arch/amd64/conf/files.amd64
cvs rdiff -u -r1.11 -r1.11.26.1 src/sys/arch/amd64/conf/std.amd64
cvs rdiff -u -r1.11 -r1.11.10.1 src/sys/arch/amd64/conf/std.xen
cvs rdiff -u -r0 -r1.1.2.1 src/sys/arch/amd64/include/xen/hypercalls.h
cvs rdiff -u -r0 -r1.1.2.1 src/sys/arch/i386/conf/GENERIC_XENHVM
cvs rdiff -u -r1.194 -r1.194.10.1 src/sys/arch/i386/conf/Makefile.i386
cvs rdiff -u -r1.21.2.1 -r1.21.2.2 src/sys/arch/i386/conf/XEN3PAE_DOM0
cvs rdiff -u -r1.401 -r1.401.6.1 src/sys/arch/i386/conf/files.i386
cvs rdiff -u -r1.35 -r1.35.26.1 src/sys/arch/i386/conf/std.i386
cvs rdiff -u -r1.825.4.1 -r1.825.4.2 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.85.6.4 -r1.85.6.5 src/sys/arch/i386/i386/vector.S
cvs rdiff -u -r0 -r1.1.2.1 src/sys/arch/i386/include/xen/hypercalls.h
cvs rdiff -u -r1.107.10.1 -r1.107.10.2 src/sys/arch/x86/conf/files.x86
cvs rdiff -u -r1.61.6.2 -r1.61.6.3 src/sys/arch/x86/include/intr.h
cvs rdiff -u -r1.12 -r1.12.10.1 src/sys/arch/x86/x86/cpu_ucode.c
cvs rdiff -u -r1.10 -r1.10.6.1 src/sys/arch/x86/x86/cpu_ucode_amd.c
cvs rdiff -u -r1.17 -r1.17.8.1 src/sys/arch/x86/x86/cpu_ucode_intel.c
cvs rdiff -u -r1.76.6.1 -r1.76.6.2 src/sys/arch/x86/x86/lapic.c
cvs rdiff -u -r1.3.12.1 -r1.3.12.2 src/sys/arch/x86/x86/mainbus.c
cvs rdiff -u -r1.48 -r1.48.10.1 src/sys/arch/xen/conf/Makefile.xen
cvs rdiff -u -r1.180.2.2 -r1.180.2.3 src/sys/arch/xen/conf/files.xen
cvs rdiff -u -r0 -r1.1.2.1 src/sys/arch/xen/conf/files.xen.pv
cvs rdiff -u -r1.10 -r1.10.10.1 src/sys/arch/xen/conf/std.xen
cvs rdiff -u -r1.49.10.1 -r1.49.10.2 src/sys/arch/xen/include/hypervisor.h
cvs rdiff -u -r1.53.6.1 -r1.53.6.2 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.42 -r1.42.6.1 src/sys/arch/xen/include/xenpmap.h
cvs rdiff -u -r1.12 -r0 src/sys/arch/xen/include/amd64/hypercalls.h
cvs rdiff -u -r1.19 -r0 src/sys/arch/xen/include/i386/hypercalls.h
cvs rdiff -u -r1.36.8.1 -r1.36.8.2 src/sys/arch/xen/x86/hypervisor_machdep.c
cvs rdiff -u -r1.21.2.4 -r1.21.2.5 src/sys/arch/xen/x86/xen_intr.c
cvs rdiff -u -r1.35.6.2 -r1.35.6.3 src/sys/arch/xen/x86/xen_ipi.c
cvs rdiff -u -r1.6 -r1.6.12.1 src/sys/arch/xen/x86/xen_mainbus.c
cvs rdiff -u -r1.88.2.3 -r1.88.2.4 src/sys/arch/xen/xen/evtchn.c
cvs rdiff -u -r1.109 -r1.109.2.1 src/sys/arch/xen/xen/if_xennet_xenbus.c
cvs rdiff -u -r1.97 -r1.97.2.1 src/sys/arch/xen/xen/xbd_xenbus.c
cvs rdiff -u -r1.22 -r1.22.10.1 src/sys/arch/xen/xen/xen_machdep.c
cvs rdiff -u -r1.48 -r1.48.10.1 src/sys/arch/xen/xen/xencons.c
cvs rdiff -u -r1.21 -r1.21.10.1 src/sys/arch/xen/xenbus/xenbus_comms.c
cvs rdiff -u -r1.17 -r1.17.2.1 src/sys/arch/xen/xenbus/xenbus_dev.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.73.6.3 src/sys/arch/amd64/amd64/vector.S:1.73.6.4
--- src/sys/arch/amd64/amd64/vector.S:1.73.6.3	Sun Apr 12 17:25:52 2020
+++ src/sys/arch/amd64/amd64/vector.S	Thu Apr 16 08:46:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vector.S,v 1.73.6.3 2020/04/12 17:25:52 bouyer Exp $	*/
+/*	$NetBSD: vector.S,v 1.73.6.4 2020/04/16 08:46:34 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -84,7 +84,7 @@
 #include "ioapic.h"
 #include "lapic.h"
 #include "assym.h"
-#ifndef XEN
+#ifndef XENPV
 #include "hyperv.h"
 #endif
 
@@ -108,6 +108,7 @@
  * segment registers.
  */
 
+#ifndef XENPV
 #if NLAPIC > 0
 #ifdef MULTIPROCESSOR
 IDTVEC(recurse_lapic_ipi)
@@ -309,7 +310,6 @@ IDTVEC_END(intr_hyperv_hypercall)
 
 #endif /* NLAPIC > 0 */
 
-#ifndef XENPV
 /*
  * TLB shootdown handler.
  */

Index: src/sys/arch/amd64/conf/Makefile.amd64
diff -u src/sys/arch/amd64/conf/Makefile.amd64:1.82 src/sys/arch/amd64/conf/Makefile.amd64:1.82.2.1
--- src/sys/arch/amd64/conf/Makefile.amd64:1.82	Sat Apr  4 07:03:57 2020
+++ src/sys/arch/amd64/conf/Makefile.amd64	Thu Apr 16 08:46:34 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.amd64,v 1.82 2020/04/04 07:03:57 maxv Exp $
+#	$NetBSD: Makefile.amd64,v 1.82.2.1 2020/04/16 08:46:34 bouyer Exp $
 
 # Makefile for NetBSD
 #
@@ -77,6 +77,8 @@ KMSANFLAGS.${f}=	# empty
 CFLAGS+=	${KMSANFLAGS.${.IMPSRC:T}:U${KMSANFLAGS}}
 .endif
 
+EXTRA_INCLUDES= -I$S/external/mit/xen-include-public/dist/
+
 ##
 ## (3) libkern and compat
 ##

Index: src/sys/arch/amd64/conf/XEN3_DOM0
diff -u src/sys/arch/amd64/conf/XEN3_DOM0:1.175.4.1 src/sys/arch/amd64/conf/XEN3_DOM0:1.175.4.2
--- src/sys/arch/amd64/conf/XEN3_DOM0:1.175.4.1	Sun Apr 12 21:20:16 2020
+++ src/sys/arch/amd64/conf/XEN3_DOM0	Thu Apr 16 08:46:34 2020
@@ -1,4 +1,4 @@
-# $NetBSD: XEN3_DOM0,v 1.175.4.1 2020/04/12 21:20:16 bouyer Exp $
+# $NetBSD: XEN3_DOM0,v 1.175.4.2 2020/04/16 08:46:34 bouyer Exp $
 
 include 	"arch/amd64/conf/std.xen"
 
@@ -12,7 +12,7 @@ options 	INCLUDE_CONFIG_FILE	# embed con
 #options 	UVMHIST_PRINT
 #options 	SYSCALL_DEBUG
 
-#ident		"XEN3_DOM0-$Revision: 1.175.4.1 $"
+#ident		"XEN3_DOM0-$Revision: 1.175.4.2 $"
 
 maxusers	32		# estimated number of users
 
@@ -224,6 +224,7 @@ pci*		at hypervisor? bus ?
 pci*		at pchb? bus ?
 ppb*		at pci? dev ? function ?	# PCI-PCI bridges
 pci*		at ppb? bus ?
+options 	NO_PCI_MSI_MSIX
 
 # pci backend devices, used for PCI pass-through. To export a PCI device
 # to a domU, the device has to be attached to the pciback driver in the dom0.

Index: src/sys/arch/amd64/conf/files.amd64
diff -u src/sys/arch/amd64/conf/files.amd64:1.115 src/sys/arch/amd64/conf/files.amd64:1.115.4.1
--- src/sys/arch/amd64/conf/files.amd64:1.115	Thu Jan  9 00:42:24 2020
+++ src/sys/arch/amd64/conf/files.amd64	Thu Apr 16 08:46:34 2020
@@ -1,10 +1,8 @@
-#	$NetBSD: files.amd64,v 1.115 2020/01/09 00:42:24 manu Exp $
+#	$NetBSD: files.amd64,v 1.115.4.1 2020/04/16 08:46:34 bouyer Exp $
 #
 # new style config file for amd64 architecture
 #
 
-ifndef xen
-
 # maxpartitions must be first item in files.${ARCH}.newconf
 maxpartitions 16
 
@@ -37,7 +35,7 @@ file	arch/amd64/amd64/copy.S			machdep
 file	arch/amd64/amd64/spl.S			machdep
 
 file	arch/amd64/amd64/amd64_trap.S		machdep
-file	arch/amd64/amd64/autoconf.c		machdep
+file	arch/amd64/amd64/autoconf.c		machdep & !xenpv
 file	arch/amd64/amd64/busfunc.S		machdep
 file	arch/amd64/amd64/cpu_in_cksum.S		(inet | inet6) & cpu_in_cksum
 file	arch/amd64/amd64/cpufunc.S		machdep
@@ -53,11 +51,11 @@ file	arch/amd64/amd64/process_machdep.c	
 file	arch/amd64/amd64/trap.c			machdep
 file	arch/x86/x86/fpu.c			machdep
 file	arch/x86/x86/dbregs.c			machdep
-file	arch/x86/x86/spectre.c			machdep
+file	arch/x86/x86/spectre.c			machdep & !xenpv
 file	arch/amd64/amd64/lock_stubs.S		machdep
 file	dev/cons.c				machdep
 
-file	arch/amd64/amd64/mptramp.S        multiprocessor
+file	arch/amd64/amd64/mptramp.S        multiprocessor & !xenpv
 
 #
 # Stack-less Just-In-Time compiler
@@ -91,9 +89,10 @@ include	"dev/i2o/files.i2o"
 #
 
 # XXX BIOS32 only if something that uses it is configured!
-device	mainbus: isabus, pcibus, bios32, acpibus, cpubus, ioapicbus, ipmibus
+device	mainbus: isabus, pcibus, bios32, acpibus, cpubus, ioapicbus,
+	ipmibus, hypervisorbus
 attach	mainbus at root
-file	arch/amd64/amd64/amd64_mainbus.c	mainbus
+file	arch/amd64/amd64/amd64_mainbus.c	mainbus & !xenpv
 file	arch/x86/x86/mainbus.c			mainbus
 
 #
@@ -186,7 +185,7 @@ include "dev/sdmmc/files.sdmmc"
 include "dev/ieee1394/files.ieee1394"
 include "dev/apm/files.apm"
 include "dev/acpi/files.acpi"
-file	arch/amd64/acpi/acpi_wakeup_low.S	acpi
+file	arch/amd64/acpi/acpi_wakeup_low.S	acpi & !xenpv
 
 # Microsoft Hyper-V
 include "dev/hyperv/files.hyperv"
@@ -195,4 +194,3 @@ attach	vmbus at acpinodebus with vmbus_a
 file	dev/acpi/vmbus_acpi.c			vmbus_acpi
 
 include	"arch/amd64/conf/majors.amd64"
-endif #xen

Index: src/sys/arch/amd64/conf/std.amd64
diff -u src/sys/arch/amd64/conf/std.amd64:1.11 src/sys/arch/amd64/conf/std.amd64:1.11.26.1
--- src/sys/arch/amd64/conf/std.amd64:1.11	Thu Jan 12 05:24:36 2017
+++ src/sys/arch/amd64/conf/std.amd64	Thu Apr 16 08:46:34 2020
@@ -1,8 +1,8 @@
-# $NetBSD: std.amd64,v 1.11 2017/01/12 05:24:36 ryo Exp $
+# $NetBSD: std.amd64,v 1.11.26.1 2020/04/16 08:46:34 bouyer Exp $
 #
 # standard, required NetBSD/amd64 'options'
 
-machine amd64 x86
+machine amd64 x86 xen
 include 	"conf/std"	# MI standard options
 
 options 	CPU_IN_CKSUM
@@ -14,6 +14,8 @@ options 	MULTIPROCESSOR
 options 	CHILD_MAX=1024	# 160 is too few
 options 	OPEN_MAX=1024	# 128 is too few
 
+options         __XEN_INTERFACE_VERSION__=0x00030208 # Xen 3.1 interface
+
 mainbus0 at root
 cpu* at mainbus?
 ioapic* at mainbus? apid ?

Index: src/sys/arch/amd64/conf/std.xen
diff -u src/sys/arch/amd64/conf/std.xen:1.11 src/sys/arch/amd64/conf/std.xen:1.11.10.1
--- src/sys/arch/amd64/conf/std.xen:1.11	Mon Feb  4 18:14:53 2019
+++ src/sys/arch/amd64/conf/std.xen	Thu Apr 16 08:46:34 2020
@@ -1,10 +1,11 @@
-# $NetBSD: std.xen,v 1.11 2019/02/04 18:14:53 cherry Exp $
+# $NetBSD: std.xen,v 1.11.10.1 2020/04/16 08:46:34 bouyer Exp $
 # NetBSD: std.i386,v 1.24 2003/02/26 21:33:36 fvdl Exp 
 #
 # standard, required NetBSD/i386 'options'
 
-machine xen amd64
+machine xen amd64 x86
 include 	"conf/std"	# MI standard options
+include		"arch/xen/conf/files.xen.pv"
 
 options 	XEN	#Xen support
 options 	__XEN_INTERFACE_VERSION__=0x00030208 # Xen 3.1 interface

Index: src/sys/arch/i386/conf/Makefile.i386
diff -u src/sys/arch/i386/conf/Makefile.i386:1.194 src/sys/arch/i386/conf/Makefile.i386:1.194.10.1
--- src/sys/arch/i386/conf/Makefile.i386:1.194	Sat Sep 22 12:24:02 2018
+++ src/sys/arch/i386/conf/Makefile.i386	Thu Apr 16 08:46:34 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.i386,v 1.194 2018/09/22 12:24:02 rin Exp $
+#	$NetBSD: Makefile.i386,v 1.194.10.1 2020/04/16 08:46:34 bouyer Exp $
 
 # Makefile for NetBSD
 #
@@ -44,6 +44,7 @@ CFLAGS+=	-mno-mmx -mno-sse -mno-avx
 CFLAGS+=	-mindirect-branch=thunk
 CFLAGS+=	-mindirect-branch-register
 .endif
+EXTRA_INCLUDES= -I$S/external/mit/xen-include-public/dist/
 
 ##
 ## (3) libkern and compat

Index: src/sys/arch/i386/conf/XEN3PAE_DOM0
diff -u src/sys/arch/i386/conf/XEN3PAE_DOM0:1.21.2.1 src/sys/arch/i386/conf/XEN3PAE_DOM0:1.21.2.2
--- src/sys/arch/i386/conf/XEN3PAE_DOM0:1.21.2.1	Wed Apr  8 17:56:08 2020
+++ src/sys/arch/i386/conf/XEN3PAE_DOM0	Thu Apr 16 08:46:34 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: XEN3PAE_DOM0,v 1.21.2.1 2020/04/08 17:56:08 bouyer Exp $
+#	$NetBSD: XEN3PAE_DOM0,v 1.21.2.2 2020/04/16 08:46:34 bouyer Exp $
 #
 #	XEN3_0: Xen 3.0 domain0 kernel
 
@@ -6,6 +6,7 @@ include 	"arch/xen/conf/std.xen"
 
 options		XENPV		# PV dom0 support
 #options 	MULTIPROCESSOR	# (not yet - dom0 stuff is not MP-safe)
+options 	NO_PREEMPTION
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
@@ -212,6 +213,7 @@ balloon*	at xenbus?		# Xen balloon devic
 # PCI bus support
 pci*		at hypervisor? bus ?
 pci*		at pchb? bus ?
+options 	NO_PCI_MSI_MSIX
 
 # PCI bridges
 ichlpcib* at pci? dev ? function ?	# Intel ICH PCI-ISA w/ timecounter,

Index: src/sys/arch/i386/conf/files.i386
diff -u src/sys/arch/i386/conf/files.i386:1.401 src/sys/arch/i386/conf/files.i386:1.401.6.1
--- src/sys/arch/i386/conf/files.i386:1.401	Fri Oct 18 01:38:28 2019
+++ src/sys/arch/i386/conf/files.i386	Thu Apr 16 08:46:34 2020
@@ -1,10 +1,8 @@
-#	$NetBSD: files.i386,v 1.401 2019/10/18 01:38:28 manu Exp $
+#	$NetBSD: files.i386,v 1.401.6.1 2020/04/16 08:46:34 bouyer Exp $
 #
 # new style config file for i386 architecture
 #
 
-ifndef xen
-
 # maxpartitions must be first item in files.${ARCH}.newconf
 maxpartitions 8
 
@@ -53,7 +51,7 @@ obsolete 	defparam		MULTIBOOT_SYMTAB_SPA
 file 	arch/i386/i386/multiboot.c	multiboot
 file 	arch/x86/x86/multiboot2.c	multiboot
 
-file	arch/i386/i386/autoconf.c
+file	arch/i386/i386/autoconf.c	!xenpv
 file	arch/i386/i386/aout_machdep.c	exec_aout
 file	arch/i386/i386/busfunc.S
 file	arch/i386/i386/cpufunc.S
@@ -65,7 +63,7 @@ file	arch/i386/i386/dumpsys.c
 file	kern/subr_disk_mbr.c		disk
 file	kern/subr_spldebug.c		spldebug
 file	arch/i386/i386/gdt.c
-file	arch/i386/i386/i386func.S
+file	arch/i386/i386/i386func.S	!xenpv
 file	arch/i386/i386/kobj_machdep.c	modular
 file	arch/i386/i386/machdep.c
 file 	arch/i386/i386/longrun.c
@@ -77,7 +75,7 @@ file	arch/x86/x86/fpu.c
 file	arch/x86/x86/dbregs.c
 file	arch/x86/x86/spectre.c
 
-file	arch/i386/i386/mptramp.S	multiprocessor
+file	arch/i386/i386/mptramp.S	multiprocessor & ! xenpv
 
 file	crypto/des/arch/i386/des_enc.S		des
 file	crypto/des/arch/i386/des_cbc.S		des
@@ -128,9 +126,9 @@ define	pnpbiosbus {}
 # XXX BIOS32 only if something that uses it is configured!
 device	mainbus: isabus, eisabus, mcabus, pcibus, bios32, acpibus,
 	cpubus, ioapicbus, apmbus, pnpbiosbus, ipmibus,
-	bioscall
+	bioscall, hypervisorbus
 attach	mainbus at root
-file	arch/i386/i386/i386_mainbus.c	mainbus
+file	arch/i386/i386/i386_mainbus.c	mainbus & !xenpv
 file	arch/x86/x86/mainbus.c		mainbus
 
 #
@@ -404,7 +402,7 @@ include	"dev/ieee1394/files.ieee1394"
 include	"arch/i386/pnpbios/files.pnpbios"
 
 include "dev/acpi/files.acpi"
-file	arch/i386/acpi/acpi_wakeup_low.S	acpi
+file	arch/i386/acpi/acpi_wakeup_low.S	acpi & !xenpv
 
 # Microsoft Hyper-V
 include "dev/hyperv/files.hyperv"
@@ -423,4 +421,3 @@ attach	glxsb at pci
 file	arch/i386/pci/glxsb.c		glxsb
 
 include "arch/i386/conf/majors.i386"
-endif #xen

Index: src/sys/arch/i386/conf/std.i386
diff -u src/sys/arch/i386/conf/std.i386:1.35 src/sys/arch/i386/conf/std.i386:1.35.26.1
--- src/sys/arch/i386/conf/std.i386:1.35	Thu Jan 12 05:24:36 2017
+++ src/sys/arch/i386/conf/std.i386	Thu Apr 16 08:46:34 2020
@@ -1,8 +1,8 @@
-# $NetBSD: std.i386,v 1.35 2017/01/12 05:24:36 ryo Exp $
+# $NetBSD: std.i386,v 1.35.26.1 2020/04/16 08:46:34 bouyer Exp $
 #
 # standard, required NetBSD/i386 'options'
 
-machine i386 x86
+machine i386 x86 xen
 include		"conf/std"	# MI standard options
 
 options 	CPU_IN_CKSUM
@@ -18,6 +18,7 @@ options 	MPBIOS			# configure CPUs and A
 
 options 	CHILD_MAX=1024	# 160 is too few
 options 	OPEN_MAX=1024	# 128 is too few
+options		__XEN_INTERFACE_VERSION__=0x00030208 # Xen 3.1 interface
 
 mainbus0 at root
 cpu* at mainbus?

Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.825.4.1 src/sys/arch/i386/i386/machdep.c:1.825.4.2
--- src/sys/arch/i386/i386/machdep.c:1.825.4.1	Thu Apr  9 16:12:50 2020
+++ src/sys/arch/i386/i386/machdep.c	Thu Apr 16 08:46:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.825.4.1 2020/04/09 16:12:50 bouyer Exp $	*/
+/*	$NetBSD: machdep.c,v 1.825.4.2 2020/04/16 08:46:34 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009, 2017
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.825.4.1 2020/04/09 16:12:50 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.825.4.2 2020/04/16 08:46:34 bouyer Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_freebsd.h"
@@ -988,7 +988,7 @@ initgdt(union descriptor *tgdt)
 	    SDT_MEMERA, SEL_UPL, 1, 1);
 	setsegment(&gdtstore[GUDATA_SEL].sd, 0, 0xfffff,
 	    SDT_MEMRWA, SEL_UPL, 1, 1);
-#if NBIOSCALL > 0
+#if NBIOSCALL > 0 && !defined(XENPV)
 	/* bios trampoline GDT entries */
 	setsegment(&gdtstore[GBIOSCODE_SEL].sd, 0, 0xfffff,
 	    SDT_MEMERA, SEL_KPL, 0, 0);
@@ -1134,11 +1134,11 @@ init386(paddr_t first_avail)
 	extern paddr_t local_apic_pa;
 	union descriptor *tgdt;
 	struct region_descriptor region;
-#endif
 #if NBIOSCALL > 0
 	extern int biostramp_image_size;
 	extern u_char biostramp_image[];
 #endif
+#endif /* !XENPV */
 	struct pcb *pcb;
 
 	KASSERT(first_avail % PAGE_SIZE == 0);

Index: src/sys/arch/i386/i386/vector.S
diff -u src/sys/arch/i386/i386/vector.S:1.85.6.4 src/sys/arch/i386/i386/vector.S:1.85.6.5
--- src/sys/arch/i386/i386/vector.S:1.85.6.4	Sun Apr 12 17:25:52 2020
+++ src/sys/arch/i386/i386/vector.S	Thu Apr 16 08:46:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vector.S,v 1.85.6.4 2020/04/12 17:25:52 bouyer Exp $	*/
+/*	$NetBSD: vector.S,v 1.85.6.5 2020/04/16 08:46:34 bouyer Exp $	*/
 
 /*
  * Copyright 2002 (c) Wasabi Systems, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: vector.S,v 1.85.6.4 2020/04/12 17:25:52 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vector.S,v 1.85.6.5 2020/04/16 08:46:34 bouyer Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -85,7 +85,7 @@ __KERNEL_RCSID(0, "$NetBSD: vector.S,v 1
 
 #include "ioapic.h"
 #include "lapic.h"
-#ifndef XEN
+#ifndef XENPV
 #include "hyperv.h"
 #endif
 

Index: src/sys/arch/x86/conf/files.x86
diff -u src/sys/arch/x86/conf/files.x86:1.107.10.1 src/sys/arch/x86/conf/files.x86:1.107.10.2
--- src/sys/arch/x86/conf/files.x86:1.107.10.1	Sat Apr 11 18:26:07 2020
+++ src/sys/arch/x86/conf/files.x86	Thu Apr 16 08:46:34 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.x86,v 1.107.10.1 2020/04/11 18:26:07 bouyer Exp $
+#	$NetBSD: files.x86,v 1.107.10.2 2020/04/16 08:46:34 bouyer Exp $
 
 # options for MP configuration through the MP spec
 defflag opt_mpbios.h MPBIOS MPDEBUG MPBIOS_SCANPCI
@@ -35,8 +35,8 @@ file	arch/x86/x86/bios32.c		bios32 needs
 #
 device	cpu: cpufeaturebus
 attach	cpu at cpubus
-file 	arch/x86/x86/cpu.c 		cpu
-file	arch/x86/x86/cpu_rng.c		cpu
+file 	arch/x86/x86/cpu.c 		cpu & !xenpv
+file	arch/x86/x86/cpu_rng.c		cpu | vcpu
 
 device	acpicpu: acpi
 attach	acpicpu at cpufeaturebus
@@ -82,7 +82,7 @@ file	arch/x86/x86/hyperv.c		hyperv needs
 file	arch/x86/x86/apic.c		ioapic | lapic
 file	arch/x86/x86/bus_dma.c		machdep
 file	arch/x86/x86/bus_space.c	machdep
-file	arch/x86/x86/consinit.c		machdep
+file	arch/x86/x86/consinit.c		machdep & !xenpv
 file	arch/x86/x86/core_machdep.c	coredump
 file	arch/x86/x86/cpu_topology.c	machdep
 file	arch/x86/x86/db_memrw.c		ddb | kgdb
@@ -91,15 +91,15 @@ file	arch/x86/x86/efi.c		machdep
 file	arch/x86/x86/errata.c		machdep
 file	arch/x86/x86/genfb_machdep.c	machdep
 file	arch/x86/x86/identcpu.c		machdep
-file	arch/x86/x86/i8259.c		machdep
-file	arch/x86/x86/intr.c		machdep
+file	arch/x86/x86/i8259.c		machdep & (!xenpv | dom0ops)
+file	arch/x86/x86/intr.c		machdep & !xenpv
 file	arch/x86/x86/x86_softintr.c	machdep
 file	arch/x86/x86/kgdb_machdep.c	kgdb
 file	arch/x86/x86/nmi.c		machdep
 file	arch/x86/x86/idt.c		machdep
-file	arch/x86/x86/ipi.c		machdep
-file	arch/x86/x86/mtrr_i686.c	mtrr
-file 	arch/x86/x86/patch.c		machdep
+file	arch/x86/x86/ipi.c		machdep & ( !xenpv | dom0ops )
+file	arch/x86/x86/mtrr_i686.c	mtrr & !xenpv
+file 	arch/x86/x86/patch.c		machdep & !xenpv
 file	arch/x86/x86/platform.c		machdep
 file 	arch/x86/x86/pmap.c		machdep
 file 	arch/x86/x86/x86_tlb.c		machdep
@@ -109,7 +109,7 @@ file	arch/x86/x86/sys_machdep.c	machdep
 file	arch/x86/x86/syscall.c		machdep
 file	arch/x86/x86/tsc.c		machdep
 file	arch/x86/x86/vm_machdep.c	machdep
-file	arch/x86/x86/x86_autoconf.c	machdep
+file	arch/x86/x86/x86_autoconf.c	machdep & !xenpv
 file	arch/x86/x86/x86_userconf.c	userconf
 file	arch/x86/x86/x86_machdep.c	machdep
 
@@ -137,14 +137,14 @@ file 	arch/x86/x86/mp.c		acpi | mpbios
 file 	arch/x86/x86/mpacpi.c		acpi
 
 file	arch/x86/acpi/acpi_pdc.c	acpi
-file	arch/x86/acpi/acpi_wakeup.c	acpi
+file	arch/x86/acpi/acpi_wakeup.c	acpi & !xenpv
 file	arch/x86/acpi/acpi_machdep.c	acpi
 
-file	arch/x86/isa/isa_machdep.c
+file	arch/x86/isa/isa_machdep.c	isa
 
 # PC clock
-file 	arch/x86/isa/clock.c
-file	arch/x86/isa/rtc.c
+file 	arch/x86/isa/clock.c	!xenpv
+file	arch/x86/isa/rtc.c  	isa
 
 # Stubs for x86 routines not included in the system
 file	arch/x86/x86/x86_stub.c

Index: src/sys/arch/x86/include/intr.h
diff -u src/sys/arch/x86/include/intr.h:1.61.6.2 src/sys/arch/x86/include/intr.h:1.61.6.3
--- src/sys/arch/x86/include/intr.h:1.61.6.2	Sat Apr 11 18:26:07 2020
+++ src/sys/arch/x86/include/intr.h	Thu Apr 16 08:46:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.61.6.2 2020/04/11 18:26:07 bouyer Exp $	*/
+/*	$NetBSD: intr.h,v 1.61.6.3 2020/04/16 08:46:35 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001, 2006, 2007, 2008, 2019 The NetBSD Foundation, Inc.
@@ -47,6 +47,11 @@
 #include <sys/queue.h>
 #include <machine/intrdefs.h>
 
+#ifdef XEN
+#include <xen/include/public/xen.h>
+#include <xen/include/public/event_channel.h>
+#endif /* XEN */
+
 #ifndef _LOCORE
 #include <machine/pic.h>
 

Index: src/sys/arch/x86/x86/cpu_ucode.c
diff -u src/sys/arch/x86/x86/cpu_ucode.c:1.12 src/sys/arch/x86/x86/cpu_ucode.c:1.12.10.1
--- src/sys/arch/x86/x86/cpu_ucode.c:1.12	Mon Feb 11 14:59:33 2019
+++ src/sys/arch/x86/x86/cpu_ucode.c	Thu Apr 16 08:46:35 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_ucode.c,v 1.12 2019/02/11 14:59:33 cherry Exp $ */
+/* $NetBSD: cpu_ucode.c,v 1.12.10.1 2020/04/16 08:46:35 bouyer Exp $ */
 /*
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_ucode.c,v 1.12 2019/02/11 14:59:33 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_ucode.c,v 1.12.10.1 2020/04/16 08:46:35 bouyer Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_cpu_ucode.h"
@@ -158,4 +158,4 @@ cpu_ucode_apply(const struct cpu_ucode *
 	sc->sc_blobsize = 0;
 	return error;
 }
-#endif
+#endif /* XEN */

Index: src/sys/arch/x86/x86/cpu_ucode_amd.c
diff -u src/sys/arch/x86/x86/cpu_ucode_amd.c:1.10 src/sys/arch/x86/x86/cpu_ucode_amd.c:1.10.6.1
--- src/sys/arch/x86/x86/cpu_ucode_amd.c:1.10	Tue Oct 15 00:13:52 2019
+++ src/sys/arch/x86/x86/cpu_ucode_amd.c	Thu Apr 16 08:46:35 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_ucode_amd.c,v 1.10 2019/10/15 00:13:52 chs Exp $ */
+/* $NetBSD: cpu_ucode_amd.c,v 1.10.6.1 2020/04/16 08:46:35 bouyer Exp $ */
 /*
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_amd.c,v 1.10 2019/10/15 00:13:52 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_amd.c,v 1.10.6.1 2020/04/16 08:46:35 bouyer Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_xen.h"
@@ -138,7 +138,7 @@ cpu_ucode_amd_firmware_open(firmware_han
 	return firmware_open(fw_path, "microcode_amd.bin", fwh);
 }
 
-#ifndef XEN
+#ifndef XENPV
 struct mc_buf {
 	uint8_t *mc_buf;
 	uint32_t mc_equiv_cpuid;

Index: src/sys/arch/x86/x86/cpu_ucode_intel.c
diff -u src/sys/arch/x86/x86/cpu_ucode_intel.c:1.17 src/sys/arch/x86/x86/cpu_ucode_intel.c:1.17.8.1
--- src/sys/arch/x86/x86/cpu_ucode_intel.c:1.17	Fri May 10 18:21:01 2019
+++ src/sys/arch/x86/x86/cpu_ucode_intel.c	Thu Apr 16 08:46:35 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_ucode_intel.c,v 1.17 2019/05/10 18:21:01 maxv Exp $ */
+/* $NetBSD: cpu_ucode_intel.c,v 1.17.8.1 2020/04/16 08:46:35 bouyer Exp $ */
 
 /*
  * Copyright (c) 2012, 2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_intel.c,v 1.17 2019/05/10 18:21:01 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_intel.c,v 1.17.8.1 2020/04/16 08:46:35 bouyer Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_xen.h"
@@ -106,7 +106,7 @@ cpu_ucode_intel_firmware_open(firmware_h
 	return firmware_open(fw_path, cpuspec, fwh);
 }
 
-#ifndef XEN
+#ifndef XENPV
 static int
 cpu_ucode_intel_verify(struct cpu_ucode_softc *sc,
     struct intel1_ucode_header *buf)

Index: src/sys/arch/x86/x86/lapic.c
diff -u src/sys/arch/x86/x86/lapic.c:1.76.6.1 src/sys/arch/x86/x86/lapic.c:1.76.6.2
--- src/sys/arch/x86/x86/lapic.c:1.76.6.1	Wed Apr  8 17:59:16 2020
+++ src/sys/arch/x86/x86/lapic.c	Thu Apr 16 08:46:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lapic.c,v 1.76.6.1 2020/04/08 17:59:16 bouyer Exp $	*/
+/*	$NetBSD: lapic.c,v 1.76.6.2 2020/04/16 08:46:35 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lapic.c,v 1.76.6.1 2020/04/08 17:59:16 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lapic.c,v 1.76.6.2 2020/04/16 08:46:35 bouyer Exp $");
 
 #include "acpica.h"
 #include "ioapic.h"
@@ -41,6 +41,8 @@ __KERNEL_RCSID(0, "$NetBSD: lapic.c,v 1.
 #include "opt_mpbios.h"		/* for MPDEBUG */
 #include "opt_multiprocessor.h"
 #include "opt_ntp.h"
+#include "opt_xen.h"
+
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -70,6 +72,7 @@ __KERNEL_RCSID(0, "$NetBSD: lapic.c,v 1.
 #include <machine/i82489reg.h>
 #include <machine/i82489var.h>
 
+#ifndef XENPV
 #if NACPICA > 0
 #include <dev/acpi/acpica.h>
 #include <dev/acpi/acpivar.h>
@@ -963,3 +966,9 @@ lapic_dump(void)
 
 #undef APIC_LVT_PRIINT
 }
+#else /* XENPV */
+void
+lapic_boot_init(paddr_t lapic_base)
+{
+}
+#endif /* XENPV */

Index: src/sys/arch/x86/x86/mainbus.c
diff -u src/sys/arch/x86/x86/mainbus.c:1.3.12.1 src/sys/arch/x86/x86/mainbus.c:1.3.12.2
--- src/sys/arch/x86/x86/mainbus.c:1.3.12.1	Sat Apr 11 21:21:49 2020
+++ src/sys/arch/x86/x86/mainbus.c	Thu Apr 16 08:46:35 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: mainbus.c,v 1.3.12.1 2020/04/11 21:21:49 bouyer Exp $ */
+/* $NetBSD: mainbus.c,v 1.3.12.2 2020/04/16 08:46:35 bouyer Exp $ */
 
 /*
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.3.12.1 2020/04/11 21:21:49 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.3.12.2 2020/04/16 08:46:35 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -40,6 +40,7 @@ __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 
 #include <machine/cpuvar.h>
 #include <machine/mpbiosvar.h>
 #include <machine/mpacpi.h>
+#include <xen/hypervisor.h>
 
 #include "pci.h"
 #include "isa.h"
@@ -96,10 +97,6 @@ void i386_mainbus_attach(device_t, devic
 void amd64_mainbus_attach(device_t, device_t, void *);
 #endif
 
-#if defined(XEN)
-void xen_mainbus_attach(device_t, device_t, void *);
-#endif
-
 static int
 mainbus_cpu_print(void *aux, const char *busname)
 {

Index: src/sys/arch/xen/conf/Makefile.xen
diff -u src/sys/arch/xen/conf/Makefile.xen:1.48 src/sys/arch/xen/conf/Makefile.xen:1.48.10.1
--- src/sys/arch/xen/conf/Makefile.xen:1.48	Sat Feb  2 12:32:54 2019
+++ src/sys/arch/xen/conf/Makefile.xen	Thu Apr 16 08:46:35 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.xen,v 1.48 2019/02/02 12:32:54 cherry Exp $
+#	$NetBSD: Makefile.xen,v 1.48.10.1 2020/04/16 08:46:35 bouyer Exp $
 #	NetBSD: Makefile.i386,v 1.132 2003/07/05 16:56:10 simonb Exp 
 
 # Makefile for NetBSD
@@ -67,21 +67,24 @@ OPT_MODULAR=	%MODULAR%
 ##
 ## (4) local objects, compile rules, and dependencies
 ##
-MD_OBJS=	locore.o spl.o copy.o vector.o
-.if ${XEN_BUILD} == amd64
-MD_OBJS+=	amd64_trap.o
+
+MD_OBJS=
+.if ${XEN_BUILD} == i386
+MD_OBJS+=	locore.o spl.o copy.o vector.o lock_stubs.o
 .endif
 MD_CFILES=
 
-MD_SFILES=	$S/arch/${XEN_BUILD}/${XEN_BUILD}/locore.S \
+MD_SFILES=
+.if ${XEN_BUILD} == i386
+MD_SFILES+=	$S/arch/${XEN_BUILD}/${XEN_BUILD}/locore.S \
 		$S/arch/${XEN_BUILD}/${XEN_BUILD}/spl.S \
 		$S/arch/${XEN_BUILD}/${XEN_BUILD}/vector.S \
-		$S/arch/${XEN_BUILD}/${XEN_BUILD}/copy.S
+		$S/arch/${XEN_BUILD}/${XEN_BUILD}/copy.S \
+		$S/arch/${XEN_BUILD}/${XEN_BUILD}/lock_stubs.S
 
-.if ${XEN_BUILD} == amd64
-MD_SFILES+=	$S/arch/${XEN_BUILD}/${XEN_BUILD}/amd64_trap.S
 .endif
 
+.if ${XEN_BUILD} == i386
 copy.o: $S/arch/${XEN_BUILD}/${XEN_BUILD}/copy.S assym.h
 	${NORMAL_S}
 
@@ -94,8 +97,7 @@ spl.o: $S/arch/${XEN_BUILD}/${XEN_BUILD}
 vector.o: $S/arch/${XEN_BUILD}/${XEN_BUILD}/vector.S assym.h
 	${NORMAL_S}
 
-.if ${XEN_BUILD} == amd64
-amd64_trap.o: $S/arch/${XEN_BUILD}/${XEN_BUILD}/amd64_trap.S assym.h
+lock_stubs.o: $S/arch/${XEN_BUILD}/${XEN_BUILD}/lock_stubs.S assym.h
 	${NORMAL_S}
 .endif
 

Index: src/sys/arch/xen/conf/files.xen
diff -u src/sys/arch/xen/conf/files.xen:1.180.2.2 src/sys/arch/xen/conf/files.xen:1.180.2.3
--- src/sys/arch/xen/conf/files.xen:1.180.2.2	Tue Apr 14 16:53:57 2020
+++ src/sys/arch/xen/conf/files.xen	Thu Apr 16 08:46:35 2020
@@ -1,196 +1,19 @@
-#	$NetBSD: files.xen,v 1.180.2.2 2020/04/14 16:53:57 bouyer 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 
+#	$NetBSD: files.xen,v 1.180.2.3 2020/04/16 08:46:35 bouyer Exp $
 
-ifdef i386
-maxpartitions 8
-else
-maxpartitions 16
-endif
+defflag	opt_xen.h			XEN XENPVH XENPVHVM
 
-maxusers 2 16 128
+file	arch/xen/x86/hypervisor_machdep.c	xen
+file	arch/xen/x86/xen_intr.c			xen
+file	arch/xen/xen/xen_machdep.c		xen
+file	arch/xen/xen/evtchn.c			xen
+file	arch/xen/xen/xengnt.c			xen
+file	arch/xen/x86/xen_ipi.c			multiprocessor & xen
+file	arch/xen/x86/xen_mainbus.c		xen
 
-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
-
-# splraise()/spllower() debug
-defflag	opt_spldebug.h			SPLDEBUG
-
-# Beep on halt
-defflag opt_beep.h		BEEP_ONHALT
-defparam opt_beep.h		BEEP_ONHALT_COUNT=3
-defparam opt_beep.h		BEEP_ONHALT_PITCH=1500
-defparam opt_beep.h		BEEP_ONHALT_PERIOD=250
-
-# PCI fixup options
-defflag opt_pcifixup.h	PCI_ADDR_FIXUP PCI_BUS_FIXUP
-			PCI_INTR_FIXUP PCI_INTR_FIXUP_FORCE
-
-defparam		PCI_CONF_MODE
-
-file	arch/xen/x86/autoconf.c		xenpv
-ifdef i386
-file	arch/i386/i386/autoconf.c	xenpvhvm
-file	arch/i386/i386/aout_machdep.c	exec_aout
-file	arch/i386/i386/i386func.S	machdep & xenpvhvm
-file	arch/i386/i386/busfunc.S
-file	arch/i386/i386/cpufunc.S
-file	arch/i386/i386/cpu_in_cksum.S   (inet | inet6) & cpu_in_cksum
-file	arch/i386/i386/db_disasm.c	ddb
-file	arch/i386/i386/db_interface.c	ddb
-file	arch/i386/i386/db_machdep.c	ddb
-file	arch/i386/i386/dumpsys.c
-file	arch/i386/i386/gdt.c
-file	arch/i386/i386/kobj_machdep.c	modular
-file	arch/i386/i386/machdep.c
-file	arch/i386/i386/longrun.c
-file	arch/i386/i386/mtrr_k6.c	mtrr
-file	arch/i386/i386/process_machdep.c
-file	arch/i386/i386/trap.c
-file	arch/i386/i386/lock_stubs.S
-
-file	crypto/des/arch/i386/des_enc.S		des
-file	crypto/des/arch/i386/des_cbc.S		des
-
-file	crypto/blowfish/arch/i386/bf_enc.S	blowfish
-file	crypto/blowfish/arch/i386/bf_cbc.S	blowfish
-
-elifdef amd64
-file	arch/amd64/amd64/autoconf.c		xenpvhvm
-file	arch/amd64/amd64/busfunc.S
-file	arch/amd64/amd64/cpufunc.S
-file	arch/amd64/amd64/cpu_in_cksum.S		(inet | inet6) & cpu_in_cksum
-file	arch/amd64/amd64/db_disasm.c		ddb
-file	arch/amd64/amd64/db_interface.c		ddb
-file	arch/amd64/amd64/db_machdep.c		ddb
-file	arch/amd64/amd64/kobj_machdep.c	 	modular
-file	arch/amd64/amd64/gdt.c
-file	arch/amd64/amd64/machdep.c
-file	arch/amd64/amd64/process_machdep.c
-file	arch/amd64/amd64/trap.c
-file	arch/amd64/amd64/lock_stubs.S
-endif
-
-file	kern/subr_disk_mbr.c		disk
-file	uvm/pmap/pmap_pvt.c
-file	arch/x86/x86/db_memrw.c		ddb | kgdb
-file	arch/x86/x86/db_trace.c		ddb
-file	arch/x86/x86/efi.c		machdep
-file	arch/x86/x86/errata.c		machdep
-file	arch/x86/x86/fpu.c
-file	arch/x86/x86/dbregs.c
-file	arch/xen/x86/hypervisor_machdep.c
-file	arch/x86/x86/kgdb_machdep.c	kgdb
-file 	arch/x86/x86/mtrr_i686.c	mtrr & (dom0ops | xenpvhvm)
-file	arch/x86/x86/syscall.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		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
-file	arch/x86/x86/cpu_ucode_intel.c	dom0ops & cpu_ucode needs-flag
-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/clock.c		xenpv
-file	arch/x86/isa/clock.c		xenpvhvm
-file	arch/x86/isa/rtc.c		dom0ops | xenpvhvm
-file	arch/xen/xen/evtchn.c
-
-file	arch/xen/xen/xengnt.c
-
-file	arch/x86/x86/cpu_rng.c
-
-file	dev/cons.c
-
-
-#
-# Stack-less Just-In-Time compiler
-#
-
-include	"external/bsd/sljit/conf/files.sljit"
-
-#
-# Machine-independent SCSI drivers
-#
-
-include	"dev/scsipi/files.scsipi"
-
-#
-# Machine-independent ATA drivers
-#
-
-include	"dev/ata/files.ata"
-
-# Memory Disk for install floppy
-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 & xenpv
-file	arch/x86/x86/bus_space.c	machdep
-file	arch/xen/x86/consinit.c		machdep & xenpv
-file	arch/x86/x86/consinit.c		machdep & xenpvhvm
-file	arch/x86/x86/identcpu.c		machdep
-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/intr.c		machdep & xenpvhvm
-file	arch/x86/x86/x86_softintr.c	machdep
-file	arch/x86/x86/ipi.c		xenpvhvm
-file 	arch/x86/x86/patch.c		machdep & ! xenpv
-file	arch/x86/x86/pmap.c		machdep
-file	arch/x86/x86/x86_tlb.c		machdep
-file	arch/x86/x86/procfs_machdep.c	procfs
-file	arch/x86/x86/sys_machdep.c	machdep
-file	arch/x86/x86/tsc.c		machdep
-file	arch/x86/x86/vm_machdep.c	machdep
-file	arch/x86/x86/x86_autoconf.c	machdep & xenpvhvm
-file	arch/x86/x86/x86_machdep.c	machdep
-file	arch/x86/x86/platform.c		machdep
-
-include	"arch/xen/conf/files.compat"
-
-# BIOS32 routines
-define	bios32
-file	arch/x86/x86/bios32.c		bios32 needs-flag
-
-# xen specific mainbus attributes
-define cpubus { [apid = -1] }
-define cpufeaturebus {}
-define ioapicbus { [apid = -1] }
-define apmbus {}
-define pnpbiosbus {}
 define hypervisorbus {}
 define xendevbus {}
 
-#
-# System bus types
-#
-
-device mainbus: isabus, pcibus, cpubus, ioapicbus, hypervisorbus, bios32, ipmibus, acpibus
-attach	mainbus at root
-file	arch/xen/x86/xen_mainbus.c		mainbus
-ifdef  	amd64
-file	arch/amd64/amd64/amd64_mainbus.c	mainbus & xenpvhvm
-elifdef i386
-file	arch/i386/i386/i386_mainbus.c		mainbus & xenpvhvm
-file	dev/eisa/eisabusprint.c			xenpvhvm
-endif
-file	arch/x86/x86/mainbus.c			mainbus
-
 # Xen hypervisor
 device	hypervisor { [apid = -1]}: isabus, pcibus, sysmon_power, xendevbus, acpibus
 attach hypervisor at hypervisorbus
@@ -211,201 +34,13 @@ device	xencons: tty
 attach	xencons at xendevbus
 file	arch/xen/xen/xencons.c		xencons needs-flag
 
-# Xen event peudo-device
-defpseudo xenevt
-defpseudo xvif
-defpseudo xbdback
-
 # Xen Network driver
 device	xennet: arp, ether, ifnet
 attach xennet at xenbus
 file	arch/xen/xen/if_xennet_xenbus.c xennet needs-flag
+file	arch/xen/xen/xennet_checksum.c	xvif | xennet
 
 # Xen Block device driver and wd/sd/cd identities
 device	xbd: disk
 attach	xbd at xenbus
 file	arch/xen/xen/xbd_xenbus.c	xbd
-
-# PCI frontend
-device xpci: pcibus
-attach xpci at xenbus with xpci_xenbus
-file	arch/xen/xen/xpci_xenbus.c	xpci_xenbus
-
-# Xen Balloon driver
-device	balloon
-attach	balloon at xenbus
-file	arch/xen/xen/balloon.c		balloon
-
-# Non-Xen specific devices and options
-
-include	"dev/pckbport/files.pckbport"
-
-#
-# Machine-independent PCI devices
-#
-include "dev/i2o/files.i2o"
-include "dev/pci/files.pci"
-include "dev/pci/files.agp"
-file	arch/x86/pci/pciide_machdep.c	pciide_common
-
-device	pciback {unit = -1}
-attach	pciback at pci
-file	arch/xen/xen/pciback.c		pciback
-
-
-# x86 specific PCI hardware
-include "arch/x86/pci/files.pci"
-
-#
-# Machine-independent ISA devices
-#
-include "dev/isa/files.isa"
-
-include "dev/usb/files.usb"
-
-include "dev/ieee1394/files.ieee1394"
-
-device	fdc {drive = -1} #XXX
-
-include "dev/apm/files.apm"
-
-include "dev/acpi/files.acpi"
-file	arch/xen/xen/xen_acpi_machdep.c	acpi & xenpv
-file	arch/x86/x86/mpacpi.c		acpi
-file	arch/x86/x86/i8259.c		xenpvhvm | dom0ops
-
-# Stubs for x86 routines not included in the system
-file	arch/x86/x86/x86_stub.c
-
-# MP configuration using Intel SMP specification 1.4
-file	arch/x86/x86/mpbios.c		mpbios
-
-# MP configuration using either ACPI or Intel SMP specification 1.4
-file 	arch/x86/x86/mp.c		acpi | mpbios
-
-file	arch/x86/pci/pci_bus_fixup.c	pci_bus_fixup
-file	arch/x86/pci/pci_addr_fixup.c	pci_addr_fixup
-
-file	arch/x86/x86/apic.c		ioapic
-file	arch/x86/x86/nmi.c
-
-file	arch/x86/acpi/acpi_machdep.c	acpi
-file	arch/x86/acpi/acpi_pdc.c	acpi
-
-device ioapic
-attach ioapic at ioapicbus
-file	arch/x86/x86/ioapic.c		ioapic needs-flag
-
-#IPMI device
-file	arch/x86/x86/x86_ipmi.c		ipmi needs-flag
-
-# CPUs
-#
-device cpu: cpufeaturebus
-attach cpu at cpubus
-
-device vcpu
-attach vcpu at xendevbus
-file	arch/xen/x86/cpu.c		xenpv & vcpu
-file 	arch/x86/x86/cpu.c			xenpvhvm
-
-# CPU features
-#
-device	est
-attach	est at cpufeaturebus
-file	arch/x86/x86/est.c		est
-file	arch/x86/x86/intel_busclock.c	est
-
-device	powernow
-attach	powernow at cpufeaturebus
-file	arch/x86/x86/powernow.c		powernow
-
-#
-# Compatibility modules
-#
-
-ifdef i386
-
-# Binary compatibility with previous NetBSD releases (COMPAT_XX)
-file	arch/i386/i386/compat_13_machdep.c	compat_13
-file	arch/i386/i386/compat_16_machdep.c	compat_16
-
-# Linux binary compatibility (COMPAT_LINUX)
-include	"compat/linux/files.linux"
-include	"compat/linux/arch/i386/files.linux_i386"
-file	arch/i386/i386/linux_sigcode.S		compat_linux
-file	arch/i386/i386/linux_syscall.c		compat_linux
-file	arch/x86/x86/linux_trap.c		compat_linux
-
-# FreeBSD binary compatibility (COMPAT_FREEBSD)
-include	"compat/freebsd/files.freebsd"
-
-elifdef amd64
-
-# Binary compatibility with previous NetBSD releases (COMPAT_XX)
-file	arch/amd64/amd64/compat_16_machdep.c	compat_16
-
-# NetBSD/i386 32-bit binary compatibility (COMPAT_NETBSD32)
-include "compat/netbsd32/files.netbsd32"
-file	arch/amd64/amd64/netbsd32_machdep.c	compat_netbsd32
-file	arch/amd64/amd64/netbsd32_machdep_13.c	compat_netbsd32 & compat_13
-file	arch/amd64/amd64/netbsd32_machdep_16.c	compat_netbsd32 & compat_16
-file	arch/amd64/amd64/netbsd32_sigcode.S	compat_netbsd32 & compat_16
-file	arch/amd64/amd64/netbsd32_syscall.c	compat_netbsd32
-
-# Linux compatibility (COMPAT_LINUX)
-include "compat/linux/files.linux"
-include "compat/linux/arch/amd64/files.linux_amd64"
-file	arch/amd64/amd64/linux_sigcode.S	compat_linux
-file	arch/amd64/amd64/linux_syscall.c	compat_linux
-file	arch/x86/x86/linux_trap.c		compat_linux
-# Linux 32 bit compatibility (COMPAT_LINUX32)
-include "compat/linux32/files.linux32"
-include "compat/linux32/arch/amd64/files.linux32_amd64"
-file	arch/amd64/amd64/linux32_sigcode.S	compat_linux32
-file	arch/amd64/amd64/linux32_syscall.c	compat_linux32
-endif
-
-# OSS audio driver compatibility
-include	"compat/ossaudio/files.ossaudio"
-
-# Bluetooth
-include "dev/bluetooth/files.bluetooth"
-
-include "dev/sdmmc/files.sdmmc"
-
-#
-# CARDBUS
-#
-include	"dev/cardbus/files.cardbus"
-ifdef i386
-file	arch/i386/i386/rbus_machdep.c	cardbus
-elifdef amd64
-file	arch/amd64/amd64/rbus_machdep.c cardbus
-endif
-
-# this wants to be probed as late as possible.
-#
-# Machine-independent PCMCIA drivers
-#
-include	"dev/pcmcia/files.pcmcia"
-
-# Domain-0 operations
-defflag	opt_xen.h			DOM0OPS XENPV
-file	arch/xen/xen/privcmd.c		dom0ops
-file 	arch/xen/x86/xen_shm_machdep.c	dom0ops
-file	arch/x86/pci/pci_machdep.c	(xenpvhvm | hypervisor) & pci & ( dom0ops | xenpvhvm )
-file	arch/x86/pci/pci_intr_machdep.c	(xenpvhvm | hypervisor) & pci
-file	arch/x86/pci/pci_msi_machdep.c	hypervisor & xenpvhvm & pci & ! no_pci_msi_msix
-file	arch/x86/pci/msipic.c		hypervisor & xenpvhvm & pci & ! no_pci_msi_msix
-file	arch/x86/isa/isa_machdep.c	(xenpvhvm | hypervisor) & ( dom0ops | xenpvhvm )
-file	arch/xen/xen/xenevt.c		xenevt & (dom0ops | xenpvhvm)
-file	arch/xen/xen/xennetback_xenbus.c xvif
-file	arch/xen/xen/xennet_checksum.c	xvif | xennet
-file	arch/xen/xen/xbdback_xenbus.c xbdback
-
-ifdef i386
-include "arch/i386/conf/majors.i386"
-elifdef amd64
-include "arch/amd64/conf/majors.amd64"
-endif

Index: src/sys/arch/xen/conf/std.xen
diff -u src/sys/arch/xen/conf/std.xen:1.10 src/sys/arch/xen/conf/std.xen:1.10.10.1
--- src/sys/arch/xen/conf/std.xen:1.10	Mon Feb  4 18:14:53 2019
+++ src/sys/arch/xen/conf/std.xen	Thu Apr 16 08:46:35 2020
@@ -1,10 +1,11 @@
-# $NetBSD: std.xen,v 1.10 2019/02/04 18:14:53 cherry Exp $
+# $NetBSD: std.xen,v 1.10.10.1 2020/04/16 08:46:35 bouyer Exp $
 # NetBSD: std.i386,v 1.24 2003/02/26 21:33:36 fvdl Exp 
 #
 # standard, required NetBSD/i386 'options'
 
-machine xen i386
+machine xen i386 x86
 include		"conf/std"	# MI standard options
+include		"arch/xen/conf/files.xen.pv"
 
 options 	__XEN_INTERFACE_VERSION__=0x00030208 # Xen 3.1 interface
 

Index: src/sys/arch/xen/include/hypervisor.h
diff -u src/sys/arch/xen/include/hypervisor.h:1.49.10.1 src/sys/arch/xen/include/hypervisor.h:1.49.10.2
--- src/sys/arch/xen/include/hypervisor.h:1.49.10.1	Sun Apr 12 17:25:52 2020
+++ src/sys/arch/xen/include/hypervisor.h	Thu Apr 16 08:46:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor.h,v 1.49.10.1 2020/04/12 17:25:52 bouyer Exp $	*/
+/*	$NetBSD: hypervisor.h,v 1.49.10.2 2020/04/16 08:46:35 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -58,6 +58,8 @@
 #include "isa.h"
 #include "pci.h"
 
+void xen_mainbus_attach(device_t, device_t, void *);
+
 struct hypervisor_attach_args {
 	const char 		*haa_busname;
 };
@@ -108,7 +110,7 @@ struct xen_npx_attach_args {
 #define xen_wmb() membar_consumer()
 #endif /* __XEN_INTERFACE_VERSION */
 
-#include <machine/hypercalls.h>
+#include <machine/xen/hypercalls.h>
 
 #undef u8
 #undef u16

Index: src/sys/arch/xen/include/intr.h
diff -u src/sys/arch/xen/include/intr.h:1.53.6.1 src/sys/arch/xen/include/intr.h:1.53.6.2
--- src/sys/arch/xen/include/intr.h:1.53.6.1	Sun Apr 12 17:25:52 2020
+++ src/sys/arch/xen/include/intr.h	Thu Apr 16 08:46:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.53.6.1 2020/04/12 17:25:52 bouyer Exp $	*/
+/*	$NetBSD: intr.h,v 1.53.6.2 2020/04/16 08:46:35 bouyer Exp $	*/
 /*	NetBSD intr.h,v 1.15 2004/10/31 10:39:34 yamt Exp	*/
 
 /*-
@@ -33,7 +33,7 @@
 #ifndef _XEN_INTR_H_
 #define	_XEN_INTR_H_
 
-#include <machine/intrdefs.h>
+#include <xen/intrdefs.h>
 
 #ifndef _LOCORE
 #include <xen/include/public/xen.h>

Index: src/sys/arch/xen/include/xenpmap.h
diff -u src/sys/arch/xen/include/xenpmap.h:1.42 src/sys/arch/xen/include/xenpmap.h:1.42.6.1
--- src/sys/arch/xen/include/xenpmap.h:1.42	Wed Oct 30 07:40:06 2019
+++ src/sys/arch/xen/include/xenpmap.h	Thu Apr 16 08:46:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xenpmap.h,v 1.42 2019/10/30 07:40:06 maxv Exp $	*/
+/*	$NetBSD: xenpmap.h,v 1.42.6.1 2020/04/16 08:46:35 bouyer Exp $	*/
 
 /*
  *
@@ -122,7 +122,6 @@ xpmap_ptom_isvalid(paddr_t ppa)
 	    != INVALID_P2M_ENTRY);
 }
 
-#endif /* XENPV */
 
 static inline void
 MULTI_update_va_mapping(
@@ -170,5 +169,6 @@ MULTI_update_va_mapping_otherdomain(
 #if defined(__x86_64__)
 void xen_set_user_pgd(paddr_t);
 #endif
+#endif /* XENPV */
 
 #endif /* _XEN_XENPMAP_H_ */

Index: src/sys/arch/xen/x86/hypervisor_machdep.c
diff -u src/sys/arch/xen/x86/hypervisor_machdep.c:1.36.8.1 src/sys/arch/xen/x86/hypervisor_machdep.c:1.36.8.2
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.36.8.1	Sun Apr 12 17:25:52 2020
+++ src/sys/arch/xen/x86/hypervisor_machdep.c	Thu Apr 16 08:46:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor_machdep.c,v 1.36.8.1 2020/04/12 17:25:52 bouyer Exp $	*/
+/*	$NetBSD: hypervisor_machdep.c,v 1.36.8.2 2020/04/16 08:46:35 bouyer Exp $	*/
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.36.8.1 2020/04/12 17:25:52 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.36.8.2 2020/04/16 08:46:35 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -66,6 +66,7 @@ __KERNEL_RCSID(0, "$NetBSD: hypervisor_m
 #include <machine/pmap.h>
 
 #include <xen/xen.h>
+#include <xen/intr.h>
 #include <xen/hypervisor.h>
 #include <xen/evtchn.h>
 #include <xen/xenpmap.h>

Index: src/sys/arch/xen/x86/xen_intr.c
diff -u src/sys/arch/xen/x86/xen_intr.c:1.21.2.4 src/sys/arch/xen/x86/xen_intr.c:1.21.2.5
--- src/sys/arch/xen/x86/xen_intr.c:1.21.2.4	Tue Apr 14 16:52:35 2020
+++ src/sys/arch/xen/x86/xen_intr.c	Thu Apr 16 08:46:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_intr.c,v 1.21.2.4 2020/04/14 16:52:35 bouyer Exp $	*/
+/*	$NetBSD: xen_intr.c,v 1.21.2.5 2020/04/16 08:46:35 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.21.2.4 2020/04/14 16:52:35 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.21.2.5 2020/04/16 08:46:35 bouyer Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -40,6 +40,7 @@ __KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v
 #include <sys/cpu.h>
 #include <sys/device.h>
 
+#include <xen/intr.h>
 #include <xen/evtchn.h>
 #include <xen/xenfunc.h>
 
@@ -444,7 +445,7 @@ xen_intr_create_intrid(int legacy_irq, s
 {
 	int ih = 0;
 
-#if NPCI > 0
+#if NPCI > 0 && defined(XENPV)
 #if defined(__HAVE_PCI_MSI_MSIX)
 	if ((pic->pic_type == PIC_MSI) || (pic->pic_type == PIC_MSIX)) {
 		uint64_t pih;

Index: src/sys/arch/xen/x86/xen_ipi.c
diff -u src/sys/arch/xen/x86/xen_ipi.c:1.35.6.2 src/sys/arch/xen/x86/xen_ipi.c:1.35.6.3
--- src/sys/arch/xen/x86/xen_ipi.c:1.35.6.2	Sun Apr 12 17:17:38 2020
+++ src/sys/arch/xen/x86/xen_ipi.c	Thu Apr 16 08:46:35 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_ipi.c,v 1.35.6.2 2020/04/12 17:17:38 bouyer Exp $ */
+/* $NetBSD: xen_ipi.c,v 1.35.6.3 2020/04/16 08:46:35 bouyer Exp $ */
 
 /*-
  * Copyright (c) 2011, 2019 The NetBSD Foundation, Inc.
@@ -33,10 +33,10 @@
 
 /* 
  * Based on: x86/ipi.c
- * __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.35.6.2 2020/04/12 17:17:38 bouyer Exp $");
+ * __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.35.6.3 2020/04/16 08:46:35 bouyer Exp $");
  */
 
-__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.35.6.2 2020/04/12 17:17:38 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.35.6.3 2020/04/16 08:46:35 bouyer Exp $");
 
 #include "opt_ddb.h"
 
@@ -74,7 +74,7 @@ static void xen_ipi_generic(struct cpu_i
 static void xen_ipi_ast(struct cpu_info *, struct intrframe *);
 static void xen_ipi_kpreempt(struct cpu_info *ci, struct intrframe *);
 
-static void (*ipifunc[XEN_NIPIS])(struct cpu_info *, struct intrframe *) =
+static void (*xen_ipifunc[XEN_NIPIS])(struct cpu_info *, struct intrframe *) =
 {	/* In order of priority (see: xen/include/intrdefs.h */
 	xen_ipi_halt,
 	xen_ipi_synch_fpu,
@@ -100,6 +100,8 @@ xen_ipi_handler(void *arg)
 
 	ci = curcpu();
 	regs = arg;
+
+	KASSERT(ci == arg);
 	
 	pending = atomic_swap_32(&ci->ci_ipis, 0);
 
@@ -108,10 +110,10 @@ xen_ipi_handler(void *arg)
 		bit--;
 		pending &= ~(1 << bit);
 		ci->ci_ipi_events[bit].ev_count++;
-		if (ipifunc[bit] != NULL) {
-			(*ipifunc[bit])(ci, regs);
+		if (xen_ipifunc[bit] != NULL) {
+			(*xen_ipifunc[bit])(ci, regs);
 		} else {
-			panic("ipifunc[%d] unsupported!\n", bit);
+			panic("xen_ipifunc[%d] unsupported!\n", bit);
 			/* NOTREACHED */
 		}
 	}
@@ -296,6 +298,32 @@ xen_ipi_ast(struct cpu_info *ci, struct 
 	aston(ci->ci_onproc);
 }
 
+static void
+xen_ipi_generic(struct cpu_info *ci, struct intrframe *intrf)
+{
+	KASSERT(ci != NULL);
+	KASSERT(intrf != NULL);
+	ipi_cpu_handler();
+}
+
+static void
+xen_ipi_hvcb(struct cpu_info *ci, struct intrframe *intrf)
+{
+	KASSERT(ci != NULL);
+	KASSERT(intrf != NULL);
+	KASSERT(ci == curcpu());
+	KASSERT(!ci->ci_vcpu->evtchn_upcall_mask);
+
+	hypervisor_force_callback();
+}
+
+static void
+xen_ipi_kpreempt(struct cpu_info *ci, struct intrframe * intrf)
+{
+	softint_trigger(1 << SIR_PREEMPT);
+}
+
+#ifdef XENPV
 void
 xc_send_ipi(struct cpu_info *ci)
 {
@@ -311,15 +339,6 @@ xc_send_ipi(struct cpu_info *ci)
 	}
 }
 
-static void
-xen_ipi_generic(struct cpu_info *ci, struct intrframe *intrf)
-{
-	KASSERT(ci != NULL);
-	KASSERT(intrf != NULL);
-
-	ipi_cpu_handler();
-}
-
 void
 cpu_ipi(struct cpu_info *ci)
 {
@@ -333,20 +352,4 @@ cpu_ipi(struct cpu_info *ci)
 		xen_broadcast_ipi(XEN_IPI_GENERIC);
 	}
 }
-
-static void
-xen_ipi_hvcb(struct cpu_info *ci, struct intrframe *intrf)
-{
-	KASSERT(ci != NULL);
-	KASSERT(intrf != NULL);
-	KASSERT(ci == curcpu());
-	KASSERT(!ci->ci_vcpu->evtchn_upcall_mask);
-
-	hypervisor_force_callback();
-}
-
-static void
-xen_ipi_kpreempt(struct cpu_info *ci, struct intrframe * intrf)
-{
-	softint_trigger(1 << SIR_PREEMPT);
-}
+#endif /* XENPV */

Index: src/sys/arch/xen/x86/xen_mainbus.c
diff -u src/sys/arch/xen/x86/xen_mainbus.c:1.6 src/sys/arch/xen/x86/xen_mainbus.c:1.6.12.1
--- src/sys/arch/xen/x86/xen_mainbus.c:1.6	Thu Feb 14 08:18:26 2019
+++ src/sys/arch/xen/x86/xen_mainbus.c	Thu Apr 16 08:46:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_mainbus.c,v 1.6 2019/02/14 08:18:26 cherry Exp $	*/
+/*	$NetBSD: xen_mainbus.c,v 1.6.12.1 2020/04/16 08:46:35 bouyer 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 <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xen_mainbus.c,v 1.6 2019/02/14 08:18:26 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_mainbus.c,v 1.6.12.1 2020/04/16 08:46:35 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -99,9 +99,8 @@ int mp_verbose = 0;
 extern bool acpi_present;
 extern bool mpacpi_active;
 
-int	xen_mainbus_match(device_t, cfdata_t, void *);
 void	xen_mainbus_attach(device_t, device_t, void *);
-int	xen_mainbus_print(void *, const char *);
+static int	xen_mainbus_print(void *, const char *);
 
 union xen_mainbus_attach_args {
 	const char *mba_busname;		/* first elem of all */
@@ -115,26 +114,14 @@ union xen_mainbus_attach_args {
 };
 
 /*
- * Probe for the mainbus; always succeeds.
- */
-int
-xen_mainbus_match(device_t parent, cfdata_t match, void *aux)
-{
-
-	return 1;
-}
-
-/*
  * Attach the mainbus.
  */
 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
+#if NIPMI > 0 && defined(XENPV)
 	memset(&mba.mba_ipmi, 0, sizeof(mba.mba_ipmi));
 	mba.mba_ipmi.iaa_iot = x86_bus_space_io;
 	mba.mba_ipmi.iaa_memt = x86_bus_space_mem;
@@ -142,17 +129,15 @@ xen_mainbus_attach(device_t parent, devi
 		config_found_ia(self, "ipmibus", &mba.mba_ipmi, 0);
 #endif
 
-#if NHYPERVISOR > 0
 	mba.mba_haa.haa_busname = "hypervisor";
 	config_found_ia(self, "hypervisorbus", &mba.mba_haa, xen_mainbus_print);
-#endif
 
 	/* save/restore for Xen */
 	if (!pmf_device_register(self, NULL, NULL))
 		aprint_error_dev(self, "couldn't establish power handler\n");
 }
 
-int
+static int
 xen_mainbus_print(void *aux, const char *pnp)
 {
 	union xen_mainbus_attach_args *mba = aux;

Index: src/sys/arch/xen/xen/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.88.2.3 src/sys/arch/xen/xen/evtchn.c:1.88.2.4
--- src/sys/arch/xen/xen/evtchn.c:1.88.2.3	Sun Apr 12 17:25:53 2020
+++ src/sys/arch/xen/xen/evtchn.c	Thu Apr 16 08:46:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.88.2.3 2020/04/12 17:25:53 bouyer Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.88.2.4 2020/04/16 08:46:36 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.88.2.3 2020/04/12 17:25:53 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.88.2.4 2020/04/16 08:46:36 bouyer Exp $");
 
 #include "opt_xen.h"
 #include "isa.h"
@@ -73,7 +73,7 @@ __KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1
 
 #include <uvm/uvm.h>
 
-#include <machine/intrdefs.h>
+#include <xen/intr.h>
 
 #include <xen/xen.h>
 #include <xen/hypervisor.h>

Index: src/sys/arch/xen/xen/if_xennet_xenbus.c
diff -u src/sys/arch/xen/xen/if_xennet_xenbus.c:1.109 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.109.2.1
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.109	Tue Apr  7 11:47:06 2020
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Thu Apr 16 08:46:36 2020
@@ -1,4 +1,4 @@
-/*      $NetBSD: if_xennet_xenbus.c,v 1.109 2020/04/07 11:47:06 jdolecek Exp $      */
+/*      $NetBSD: if_xennet_xenbus.c,v 1.109.2.1 2020/04/16 08:46:36 bouyer Exp $      */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -81,7 +81,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.109 2020/04/07 11:47:06 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.109.2.1 2020/04/16 08:46:36 bouyer Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
@@ -117,6 +117,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_xennet_xe
 
 #include <uvm/uvm.h>
 
+#include <xen/intr.h>
 #include <xen/hypervisor.h>
 #include <xen/evtchn.h>
 #include <xen/granttables.h>

Index: src/sys/arch/xen/xen/xbd_xenbus.c
diff -u src/sys/arch/xen/xen/xbd_xenbus.c:1.97 src/sys/arch/xen/xen/xbd_xenbus.c:1.97.2.1
--- src/sys/arch/xen/xen/xbd_xenbus.c:1.97	Tue Apr  7 11:47:06 2020
+++ src/sys/arch/xen/xen/xbd_xenbus.c	Thu Apr 16 08:46:36 2020
@@ -1,4 +1,4 @@
-/*      $NetBSD: xbd_xenbus.c,v 1.97 2020/04/07 11:47:06 jdolecek Exp $      */
+/*      $NetBSD: xbd_xenbus.c,v 1.97.2.1 2020/04/16 08:46:36 bouyer Exp $      */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.97 2020/04/07 11:47:06 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.97.2.1 2020/04/16 08:46:36 bouyer Exp $");
 
 #include "opt_xen.h"
 
@@ -73,6 +73,7 @@ __KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c
 
 #include <uvm/uvm.h>
 
+#include <xen/intr.h>
 #include <xen/hypervisor.h>
 #include <xen/evtchn.h>
 #include <xen/granttables.h>

Index: src/sys/arch/xen/xen/xen_machdep.c
diff -u src/sys/arch/xen/xen/xen_machdep.c:1.22 src/sys/arch/xen/xen/xen_machdep.c:1.22.10.1
--- src/sys/arch/xen/xen/xen_machdep.c:1.22	Sat Mar  9 08:42:25 2019
+++ src/sys/arch/xen/xen/xen_machdep.c	Thu Apr 16 08:46:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_machdep.c,v 1.22 2019/03/09 08:42:25 maxv Exp $	*/
+/*	$NetBSD: xen_machdep.c,v 1.22.10.1 2020/04/16 08:46:36 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.22 2019/03/09 08:42:25 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.22.10.1 2020/04/16 08:46:36 bouyer Exp $");
 
 #include "opt_xen.h"
 
@@ -67,6 +67,7 @@ __KERNEL_RCSID(0, "$NetBSD: xen_machdep.
 #include <sys/pmf.h>
 #include <sys/xcall.h>
 
+#include <xen/intr.h>
 #include <xen/hypervisor.h>
 #include <xen/shutdown_xenbus.h>
 #include <xen/include/public/version.h>

Index: src/sys/arch/xen/xen/xencons.c
diff -u src/sys/arch/xen/xen/xencons.c:1.48 src/sys/arch/xen/xen/xencons.c:1.48.10.1
--- src/sys/arch/xen/xen/xencons.c:1.48	Sat Feb  2 12:32:55 2019
+++ src/sys/arch/xen/xen/xencons.c	Thu Apr 16 08:46:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xencons.c,v 1.48 2019/02/02 12:32:55 cherry Exp $	*/
+/*	$NetBSD: xencons.c,v 1.48.10.1 2020/04/16 08:46:36 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xencons.c,v 1.48 2019/02/02 12:32:55 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xencons.c,v 1.48.10.1 2020/04/16 08:46:36 bouyer Exp $");
 
 #include "opt_xen.h"
 
@@ -67,6 +67,7 @@ __KERNEL_RCSID(0, "$NetBSD: xencons.c,v 
 #include <sys/kauth.h>
 #include <sys/kernel.h>
 
+#include <xen/intr.h>
 #include <xen/xen.h>
 #include <xen/hypervisor.h>
 #include <xen/evtchn.h>

Index: src/sys/arch/xen/xenbus/xenbus_comms.c
diff -u src/sys/arch/xen/xenbus/xenbus_comms.c:1.21 src/sys/arch/xen/xenbus/xenbus_comms.c:1.21.10.1
--- src/sys/arch/xen/xenbus/xenbus_comms.c:1.21	Mon Dec 24 14:55:42 2018
+++ src/sys/arch/xen/xenbus/xenbus_comms.c	Thu Apr 16 08:46:36 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus_comms.c,v 1.21 2018/12/24 14:55:42 cherry Exp $ */
+/* $NetBSD: xenbus_comms.c,v 1.21.10.1 2020/04/16 08:46:36 bouyer Exp $ */
 /******************************************************************************
  * xenbus_comms.c
  *
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xenbus_comms.c,v 1.21 2018/12/24 14:55:42 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenbus_comms.c,v 1.21.10.1 2020/04/16 08:46:36 bouyer Exp $");
 
 #include <sys/types.h>
 #include <sys/null.h> 
@@ -39,6 +39,7 @@ __KERNEL_RCSID(0, "$NetBSD: xenbus_comms
 #include <sys/systm.h>
 
 #include <xen/xen.h>	/* for xendomain_is_dom0() */
+#include <xen/intr.h>	/* for xendomain_is_dom0() */
 #include <xen/hypervisor.h>
 #include <xen/evtchn.h>
 #include <xen/xenbus.h>

Index: src/sys/arch/xen/xenbus/xenbus_dev.c
diff -u src/sys/arch/xen/xenbus/xenbus_dev.c:1.17 src/sys/arch/xen/xenbus/xenbus_dev.c:1.17.2.1
--- src/sys/arch/xen/xenbus/xenbus_dev.c:1.17	Tue Apr  7 16:10:48 2020
+++ src/sys/arch/xen/xenbus/xenbus_dev.c	Thu Apr 16 08:46:36 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus_dev.c,v 1.17 2020/04/07 16:10:48 jdolecek Exp $ */
+/* $NetBSD: xenbus_dev.c,v 1.17.2.1 2020/04/16 08:46:36 bouyer Exp $ */
 /*
  * xenbus_dev.c
  * 
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xenbus_dev.c,v 1.17 2020/04/07 16:10:48 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenbus_dev.c,v 1.17.2.1 2020/04/16 08:46:36 bouyer Exp $");
 
 #include "opt_xen.h"
 
@@ -50,6 +50,7 @@ __KERNEL_RCSID(0, "$NetBSD: xenbus_dev.c
 
 #include <xen/kernfs_machdep.h>
 
+#include <xen/intr.h>
 #include <xen/hypervisor.h>
 #include <xen/xenbus.h>
 #include "xenbus_comms.h"

Added files:

Index: src/sys/arch/amd64/conf/GENERIC_XENHVM
diff -u /dev/null src/sys/arch/amd64/conf/GENERIC_XENHVM:1.1.2.1
--- /dev/null	Thu Apr 16 08:46:36 2020
+++ src/sys/arch/amd64/conf/GENERIC_XENHVM	Thu Apr 16 08:46:34 2020
@@ -0,0 +1,14 @@
+# $NetBSD: GENERIC_XENHVM,v 1.1.2.1 2020/04/16 08:46:34 bouyer Exp $
+
+include "arch/amd64/conf/GENERIC"
+
+options 	XENPVHVM
+options 	XEN
+no options 	SVS		# Separate Virtual Space
+options 	MAXPHYS=32768	#xbd doesn't handle 64k transfers
+hypervisor*	at mainbus?		# Xen hypervisor
+#vcpu*		at hypervisor?		# Xen virtual CPUs
+xenbus*	 	at hypervisor?		# Xen virtual bus
+xencons*	at hypervisor?		# Xen virtual console
+xennet*	 	at xenbus?		# Xen virtual network interface
+xbd*		at xenbus?		# Xen virtual block device

Index: src/sys/arch/amd64/include/xen/hypercalls.h
diff -u /dev/null src/sys/arch/amd64/include/xen/hypercalls.h:1.1.2.1
--- /dev/null	Thu Apr 16 08:46:36 2020
+++ src/sys/arch/amd64/include/xen/hypercalls.h	Thu Apr 16 08:46:34 2020
@@ -0,0 +1,462 @@
+/* $NetBSD: hypercalls.h,v 1.1.2.1 2020/04/16 08:46:34 bouyer Exp $ */
+/******************************************************************************
+ * hypercall.h
+ * 
+ * Linux-specific hypervisor handling.
+ * 
+ * Copyright (c) 2002-2004, K A Fraser
+ * 
+ * 64-bit updates:
+ *   Benjamin Liu <benjamin....@intel.com>
+ *   Jun Nakajima <jun.nakaj...@intel.com>
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation; or, when distributed
+ * separately from the Linux kernel or incorporated into other
+ * software packages, subject to the following license:
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this source file (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy, modify,
+ * merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef __HYPERCALL_H__
+#define __HYPERCALL_H__
+
+#define __STR(x) #x
+#define STR(x) __STR(x)
+
+#define HYPERCALL_STR(name)					\
+	"call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"
+
+#define _hypercall0(type, name)			\
+({						\
+	long __res;				\
+	asm volatile (				\
+		HYPERCALL_STR(name)		\
+		: "=a" (__res)			\
+		:				\
+		: "memory" );			\
+	(type)__res;				\
+})
+
+#define _hypercall1(type, name, a1)				\
+({								\
+	long __res, __ign1;					\
+	asm volatile (						\
+		HYPERCALL_STR(name)				\
+		: "=a" (__res), "=D" (__ign1)			\
+		: "1" ((long)(a1))				\
+		: "memory" );					\
+	(type)__res;						\
+})
+
+#define _hypercall2(type, name, a1, a2)				\
+({								\
+	long __res, __ign1, __ign2;				\
+	asm volatile (						\
+		HYPERCALL_STR(name)				\
+		: "=a" (__res), "=D" (__ign1), "=S" (__ign2)	\
+		: "1" ((long)(a1)), "2" ((long)(a2))		\
+		: "memory" );					\
+	(type)__res;						\
+})
+
+#define _hypercall3(type, name, a1, a2, a3)			\
+({								\
+	long __res, __ign1, __ign2, __ign3;			\
+	asm volatile (						\
+		HYPERCALL_STR(name)				\
+		: "=a" (__res), "=D" (__ign1), "=S" (__ign2), 	\
+		"=d" (__ign3)					\
+		: "1" ((long)(a1)), "2" ((long)(a2)),		\
+		"3" ((long)(a3))				\
+		: "memory" );					\
+	(type)__res;						\
+})
+
+#define _hypercall4(type, name, a1, a2, a3, a4)			\
+({								\
+	long __res, __ign1, __ign2, __ign3;			\
+	asm volatile (						\
+		"movq %7,%%r10; "				\
+		HYPERCALL_STR(name)				\
+		: "=a" (__res), "=D" (__ign1), "=S" (__ign2),	\
+		"=d" (__ign3)					\
+		: "1" ((long)(a1)), "2" ((long)(a2)),		\
+		"3" ((long)(a3)), "g" ((long)(a4))		\
+		: "memory", "r10" );				\
+	(type)__res;						\
+})
+
+#define _hypercall5(type, name, a1, a2, a3, a4, a5)		\
+({								\
+	long __res, __ign1, __ign2, __ign3;			\
+	asm volatile (						\
+		"movq %7,%%r10; movq %8,%%r8; "			\
+		HYPERCALL_STR(name)				\
+		: "=a" (__res), "=D" (__ign1), "=S" (__ign2),	\
+		"=d" (__ign3)					\
+		: "1" ((long)(a1)), "2" ((long)(a2)),		\
+		"3" ((long)(a3)), "g" ((long)(a4)),		\
+		"g" ((long)(a5))				\
+		: "memory", "r10", "r8" );			\
+	(type)__res;						\
+})
+
+static inline int
+HYPERVISOR_set_trap_table(
+	trap_info_t *table)
+{
+	return _hypercall1(int, set_trap_table, table);
+}
+
+static inline int
+HYPERVISOR_mmu_update(
+	mmu_update_t *req, int count, int *success_count, domid_t domid)
+{
+	return _hypercall4(int, mmu_update, req, count, success_count, domid);
+}
+
+static inline int
+HYPERVISOR_mmuext_op(
+	struct mmuext_op *op, int count, int *success_count, domid_t domid)
+{
+	return _hypercall4(int, mmuext_op, op, count, success_count, domid);
+}
+
+static inline int
+HYPERVISOR_set_gdt(
+	unsigned long *frame_list, int entries)
+{
+	return _hypercall2(int, set_gdt, frame_list, entries);
+}
+
+static inline int
+HYPERVISOR_stack_switch(
+	unsigned long ss, unsigned long esp)
+{
+	return _hypercall2(int, stack_switch, ss, esp);
+}
+
+static inline int
+HYPERVISOR_set_callbacks(
+	unsigned long event_address, unsigned long failsafe_address, 
+	unsigned long syscall_address)
+{
+	return _hypercall3(int, set_callbacks,
+			   event_address, failsafe_address, syscall_address);
+}
+
+static inline int
+HYPERVISOR_fpu_taskswitch(
+	int set)
+{
+	return _hypercall1(int, fpu_taskswitch, set);
+}
+
+static inline int
+HYPERVISOR_sched_op_compat(
+	int cmd, unsigned long arg)
+{
+	return _hypercall2(int, sched_op_compat, cmd, arg);
+}
+
+static inline int
+HYPERVISOR_sched_op(
+	int cmd, void *arg)
+{
+	return _hypercall2(int, sched_op, cmd, arg);
+}
+
+static inline long
+HYPERVISOR_set_timer_op(
+	u64 timeout)
+{
+	return _hypercall1(long, set_timer_op, timeout);
+}
+
+static inline int
+HYPERVISOR_platform_op(
+	struct xen_platform_op *platform_op)
+{
+	platform_op->interface_version = XENPF_INTERFACE_VERSION;
+	return _hypercall1(int, platform_op, platform_op);
+}
+
+static inline int
+HYPERVISOR_set_debugreg(
+	int reg, unsigned long value)
+{
+	return _hypercall2(int, set_debugreg, reg, value);
+}
+
+static inline unsigned long
+HYPERVISOR_get_debugreg(
+	int reg)
+{
+	return _hypercall1(unsigned long, get_debugreg, reg);
+}
+
+static inline int
+HYPERVISOR_update_descriptor(
+	unsigned long ma, unsigned long word)
+{
+	return _hypercall2(int, update_descriptor, ma, word);
+}
+
+static inline int
+HYPERVISOR_memory_op(
+	unsigned int cmd, void *arg)
+{
+	return _hypercall2(int, memory_op, cmd, arg);
+}
+
+static inline int
+HYPERVISOR_multicall(
+	multicall_entry_t *call_list, int nr_calls)
+{
+	return _hypercall2(int, multicall, call_list, nr_calls);
+}
+
+static inline int
+HYPERVISOR_update_va_mapping(
+	unsigned long va, unsigned long new_val, unsigned long flags)
+{
+	return _hypercall3(int, update_va_mapping, va, new_val, flags);
+}
+
+static inline int
+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, &op->u);
+#endif
+}
+
+static inline int
+HYPERVISOR_acm_op(
+	int cmd, void *arg)
+{
+	return _hypercall2(int, acm_op, cmd, arg);
+}
+
+static inline int
+HYPERVISOR_xen_version(
+	int cmd, void *arg)
+{
+	return _hypercall2(int, xen_version, cmd, arg);
+}
+
+static inline int
+HYPERVISOR_console_io(
+	int cmd, int count, char *str)
+{
+	return _hypercall3(int, console_io, cmd, count, str);
+}
+
+static inline int
+HYPERVISOR_physdev_op(void *op)
+{
+	return _hypercall1(int, physdev_op_compat, op);
+}
+
+static inline int
+HYPERVISOR_grant_table_op(
+	unsigned int cmd, void *uop, unsigned int count)
+{
+	return _hypercall3(int, grant_table_op, cmd, uop, count);
+}
+
+static inline int
+HYPERVISOR_update_va_mapping_otherdomain(
+	unsigned long va, unsigned long new_val, unsigned long flags,
+	domid_t domid)
+{
+	return _hypercall4(int, update_va_mapping_otherdomain, va,
+			   new_val, flags, domid);
+}
+
+static inline int
+HYPERVISOR_vm_assist(
+	unsigned int cmd, unsigned int type)
+{
+	return _hypercall2(int, vm_assist, cmd, type);
+}
+
+static inline int
+HYPERVISOR_vcpu_op(
+	int cmd, int vcpuid, void *extra_args)
+{
+	return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args);
+}
+
+static inline int
+HYPERVISOR_set_segment_base(
+	int reg, unsigned long value)
+{
+	return _hypercall2(int, set_segment_base, reg, value);
+}
+
+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,
+	    &shutdown_reason, srec);
+#else
+	return _hypercall3(int, sched_op, SCHEDOP_shutdown,
+				 SHUTDOWN_suspend, srec);
+#endif
+}
+
+static inline long
+HYPERVISOR_yield(
+	void)
+{
+	return _hypercall2(int, sched_op, SCHEDOP_yield, 0);
+}
+
+static inline long
+HYPERVISOR_block(
+	void)
+{
+	return _hypercall2(int, sched_op, SCHEDOP_block, 0);
+}
+
+static inline long
+HYPERVISOR_shutdown(
+	void)
+{
+#if __XEN_INTERFACE_VERSION__ >= 0x00030201
+
+	struct sched_shutdown shutdown_reason = {
+		.reason = SHUTDOWN_poweroff,
+	};
+
+	return _hypercall2(int, sched_op, SCHEDOP_shutdown,
+	    &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,
+	    &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,
+	    &shutdown_reason);
+#else
+	return _hypercall2(int, sched_op, SCHEDOP_shutdown, SHUTDOWN_reboot);
+#endif
+}
+
+static inline int
+HYPERVISOR_nmi_op(
+	unsigned long op, void *arg)
+{
+	return _hypercall2(int, nmi_op, op, arg);
+}
+
+static inline long
+HYPERVISOR_hvm_op(
+    int op, void *arg)
+{
+    return _hypercall2(long, hvm_op, op, arg);
+}
+
+static inline int
+HYPERVISOR_callback_op(
+	int cmd, void *arg)
+{
+	return _hypercall2(int, callback_op, cmd, arg);
+}
+
+static inline int
+HYPERVISOR_xenoprof_op(
+	int op, void *arg)
+{
+	return _hypercall2(int, xenoprof_op, op, arg);
+}
+
+static inline int
+HYPERVISOR_kexec_op(
+	unsigned long op, void *args)
+{
+	return _hypercall2(int, kexec_op, op, args);
+}
+
+#if __XEN_INTERFACE_VERSION__ < 0x00030204
+static inline int
+HYPERVISOR_dom0_op(
+	dom0_op_t *dom0_op)
+{
+	dom0_op->interface_version = DOM0_INTERFACE_VERSION;
+	return _hypercall1(int, dom0_op, dom0_op);
+}
+#endif	/* __XEN_INTERFACE_VERSION__ */
+
+#include <xen/include/public/arch-x86/xen-mca.h>
+
+static inline int
+HYPERVISOR_machine_check(struct xen_mc *mc)
+{
+	mc->interface_version = XEN_MCA_INTERFACE_VERSION;
+	return _hypercall1(int, mca, mc);
+}
+
+static inline int
+HYPERVISOR_sysctl(void *sysctl)
+{
+	return _hypercall1(int, sysctl, sysctl);
+}
+
+#endif /* __HYPERCALL_H__ */

Index: src/sys/arch/i386/conf/GENERIC_XENHVM
diff -u /dev/null src/sys/arch/i386/conf/GENERIC_XENHVM:1.1.2.1
--- /dev/null	Thu Apr 16 08:46:36 2020
+++ src/sys/arch/i386/conf/GENERIC_XENHVM	Thu Apr 16 08:46:34 2020
@@ -0,0 +1,14 @@
+# $NetBSD: GENERIC_XENHVM,v 1.1.2.1 2020/04/16 08:46:34 bouyer Exp $
+
+include "arch/i386/conf/GENERIC"
+
+options 	XENPVHVM
+options 	XEN
+
+options 	MAXPHYS=32768	#xbd doesn't handle 64k transfers
+hypervisor*	at mainbus?		# Xen hypervisor
+#vcpu*		at hypervisor?		# Xen virtual CPUs
+xenbus*	 	at hypervisor?		# Xen virtual bus
+xencons*	at hypervisor?		# Xen virtual console
+xennet*	 	at xenbus?		# Xen virtual network interface
+xbd*		at xenbus?		# Xen virtual block device

Index: src/sys/arch/i386/include/xen/hypercalls.h
diff -u /dev/null src/sys/arch/i386/include/xen/hypercalls.h:1.1.2.1
--- /dev/null	Thu Apr 16 08:46:36 2020
+++ src/sys/arch/i386/include/xen/hypercalls.h	Thu Apr 16 08:46:34 2020
@@ -0,0 +1,573 @@
+/*	$NetBSD: hypercalls.h,v 1.1.2.1 2020/04/16 08:46:34 bouyer Exp $	*/
+
+/*
+ * Copyright (c) 2006 Manuel Bouyer.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * 
+ * Communication to/from hypervisor.
+ * 
+ * Copyright (c) 2002-2004, K A Fraser
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this source file (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy, modify,
+ * merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+
+#ifndef _XENI386_HYPERVISOR_H_
+#define _XENI386_HYPERVISOR_H_
+/*
+ * Assembler stubs for hyper-calls.
+ */
+
+#include <machine/pte.h> /* pt_entry_t */
+
+/* hypercall via the hypercall call page */
+#define __str(x) #x
+#define _str(x) __str(x)
+#define _hypercall(name, input_const, output_const) \
+	__asm volatile ( \
+	    "call hypercall_page + ("_str(name)" * 32)" \
+	    : output_const \
+	    : input_const \
+	    : "memory" )
+
+#define _harg(...) __VA_ARGS__
+	
+
+static __inline int
+HYPERVISOR_set_trap_table(trap_info_t *table)
+{
+    int ret;
+    unsigned long ign1;
+
+	_hypercall(__HYPERVISOR_set_trap_table, _harg("1" (table)),
+	    _harg("=a" (ret), "=b" (ign1)));
+
+    return ret;
+}
+
+static __inline int
+HYPERVISOR_set_gdt(unsigned long *frame_list, int entries)
+{
+    int ret;
+    unsigned long ign1, ign2;
+
+    _hypercall(__HYPERVISOR_set_gdt, _harg("1" (frame_list), "2" (entries)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
+
+    return ret;
+}
+
+static __inline int
+HYPERVISOR_stack_switch(unsigned long ss, unsigned long esp)
+{
+    int ret;
+    unsigned long ign1, ign2;
+
+    _hypercall(__HYPERVISOR_stack_switch, _harg("1" (ss), "2" (esp)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
+
+    return ret;
+}
+
+static __inline int
+HYPERVISOR_set_callbacks(
+    unsigned long event_selector, unsigned long event_address,
+    unsigned long failsafe_selector, unsigned long failsafe_address)
+{
+    int ret;
+    unsigned long ign1, ign2, ign3, ign4;
+
+    _hypercall(__HYPERVISOR_set_callbacks,
+	_harg("1" (event_selector),"2" (event_address),
+	    "3" (failsafe_selector), "4" (failsafe_address)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)));
+
+    return ret;
+}
+
+#if __XEN_INTERFACE_VERSION__ < 0x00030204
+static __inline int
+HYPERVISOR_dom0_op(dom0_op_t *dom0_op)
+{
+    int ret;
+    unsigned long ign1;
+
+    dom0_op->interface_version = DOM0_INTERFACE_VERSION;
+    _hypercall(__HYPERVISOR_dom0_op, _harg("1" (dom0_op)),
+	_harg("=a" (ret), "=b" (ign1)));
+
+    return ret;
+}
+#endif	/* __XEN_INTERFACE_VERSION__ */
+
+static __inline int
+HYPERVISOR_set_debugreg(int reg, unsigned long value)
+{
+    int ret;
+    unsigned long ign1, ign2;
+
+    _hypercall(__HYPERVISOR_set_debugreg, _harg("1" (reg), "2" (value)),
+	 _harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
+
+    return ret;
+}
+
+static __inline unsigned long
+HYPERVISOR_get_debugreg(int reg)
+{
+    unsigned long ret;
+    unsigned long ign1;
+
+    _hypercall(__HYPERVISOR_get_debugreg, _harg("1" (reg)),
+	_harg("=a" (ret), "=b" (ign1)));
+
+    return ret;
+}
+
+#include <xen/include/public/arch-x86/xen-mca.h>
+
+static __inline int
+HYPERVISOR_machine_check(struct xen_mc *mc)
+{
+     int ret;
+     unsigned long ign1;
+  
+     mc->interface_version = XEN_MCA_INTERFACE_VERSION;
+     _hypercall(__HYPERVISOR_mca, _harg("1" (mc)),
+	  _harg("=a" (ret), "=b" (ign1)));
+  
+     return ret;
+}
+
+static __inline int
+HYPERVISOR_hvm_op(int cmd, void *arg)
+{
+    int ret;
+    unsigned long ign1, ign2;
+
+    _hypercall(__HYPERVISOR_hvm_op, _harg("1" (cmd), "2" (arg)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
+
+    return ret;
+}
+
+static __inline int
+HYPERVISOR_mmu_update(mmu_update_t *req, int count, int *success_count,
+    domid_t domid)
+{
+    int ret;
+    unsigned long ign1, ign2, ign3, ign4;
+
+    _hypercall(__HYPERVISOR_mmu_update,
+	_harg("1" (req), "2" (count), "3" (success_count), "4" (domid)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)));
+
+    return ret;
+}
+
+static __inline int
+HYPERVISOR_mmuext_op(struct mmuext_op *op, int count, int *success_count,
+    domid_t domid)
+{
+    int ret;
+    unsigned long ign1, ign2, ign3, ign4;
+
+    _hypercall(__HYPERVISOR_mmuext_op,
+	_harg("1" (op), "2" (count), "3" (success_count), "4" (domid)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)));
+
+    return ret;
+}
+
+static __inline int
+HYPERVISOR_fpu_taskswitch(int set)
+{
+    long ret;
+    long ign1;
+
+    _hypercall(__HYPERVISOR_fpu_taskswitch, _harg("1" (set)),
+	_harg("=a" (ret), "=b" (ign1)));
+
+    return ret;
+}
+
+static __inline int
+HYPERVISOR_update_descriptor(uint64_t ma, uint32_t word1, uint32_t word2)
+{
+    int ret;
+    unsigned long ign1, ign2, ign3, ign4;
+    int ma1 = ma & 0xffffffff;
+    int ma2 = (ma >> 32) & 0xffffffff;
+
+    _hypercall(__HYPERVISOR_update_descriptor,
+	_harg("1" (ma1), "2" (ma2), "3" (word1), "4" (word2)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)));
+
+    return ret;
+}
+
+static __inline int
+HYPERVISOR_memory_op(unsigned int cmd, void *arg)
+{
+    int ret;
+    unsigned long ign1, ign2;
+
+    _hypercall(__HYPERVISOR_memory_op, _harg("1" (cmd), "2" (arg)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
+
+    return ret;
+}
+
+#ifdef XENPV
+static __inline int
+HYPERVISOR_update_va_mapping(unsigned long page_nr, pt_entry_t new_val,
+    unsigned long flags)
+{
+    int ret;
+    unsigned long ign1, ign2, ign3, ign4;
+    unsigned long pte_low, pte_hi;
+
+    pte_low = new_val & 0xffffffff;
+    pte_hi = new_val >> 32;
+
+    _hypercall(__HYPERVISOR_update_va_mapping,
+	_harg("1" (page_nr), "2" (pte_low), "3" (pte_hi), "4" (flags)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)));
+
+#ifdef notdef
+    if (__predict_false(ret < 0))
+        panic("Failed update VA mapping: %08lx, %08lx, %08lx",
+              page_nr, new_val, flags);
+#endif
+
+    return ret;
+}
+
+static __inline int
+HYPERVISOR_update_va_mapping_otherdomain(unsigned long page_nr,
+    pt_entry_t new_val, unsigned long flags, domid_t domid)
+{
+    int ret;
+    unsigned long ign1, ign2, ign3, ign4, ign5;
+    unsigned long pte_low, pte_hi;
+
+    pte_low = new_val & 0xffffffff;
+    pte_hi = new_val >> 32;
+
+    _hypercall(__HYPERVISOR_update_va_mapping_otherdomain,
+	_harg("1" (page_nr), "2" (pte_low), "3" (pte_hi), "4" (flags), "5" (domid)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4),
+	    "=D" (ign5)));
+
+    return ret;
+}
+#endif /* XENPV */
+
+static __inline int
+HYPERVISOR_xen_version(int cmd, void *arg)
+{
+    int ret;
+    unsigned long ign1, ign2;
+
+    _hypercall(__HYPERVISOR_xen_version, _harg("1" (cmd), "2" (arg)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
+
+    return ret;
+}
+
+static __inline int
+HYPERVISOR_grant_table_op(unsigned int cmd, void *uop, unsigned int count)
+{
+    int ret;
+    unsigned long ign1, ign2, ign3;
+
+    _hypercall(__HYPERVISOR_grant_table_op,
+	_harg("1" (cmd), "2" (uop), "3" (count)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)));
+
+    return ret;
+}
+
+
+static __inline int
+HYPERVISOR_vcpu_op(int cmd, int vcpuid, void *extra_args)
+{
+    long ret;
+    unsigned long ign1, ign2, ign3;
+
+    _hypercall(__HYPERVISOR_vcpu_op,
+	_harg("1" (cmd), "2" (vcpuid), "3" (extra_args)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)));
+
+    return ret;
+}
+
+static __inline long
+HYPERVISOR_yield(void)
+{
+    long ret;
+    unsigned long ign1, ign2;
+
+    _hypercall(__HYPERVISOR_sched_op, _harg("1" (SCHEDOP_yield), "2" (0)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
+
+    return ret;
+}
+
+static __inline long
+HYPERVISOR_block(void)
+{
+    long ret;
+    unsigned long ign1, ign2;
+
+    _hypercall(__HYPERVISOR_sched_op, _harg("1" (SCHEDOP_block), "2" (0)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
+
+    return ret;
+}
+
+static __inline long
+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_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;
+}
+
+static __inline long
+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"  (&shutdown_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;
+}
+
+static __inline long
+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"  (&shutdown_reason)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
+#else
+    _hypercall(__HYPERVISOR_sched_op,
+	_harg("1" (SCHEDOP_shutdown), "2" (SHUTDOWN_reboot)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
+#endif
+
+    return ret;
+}
+
+static __inline long
+HYPERVISOR_suspend(unsigned long srec)
+{
+    long ret;
+    unsigned long ign1, ign2, ign3;
+
+#if __XEN_INTERFACE_VERSION__ >= 0x00030201
+
+    struct sched_shutdown shutdown_reason = {
+	    .reason = SHUTDOWN_suspend
+    };
+
+    _hypercall(__HYPERVISOR_sched_op,
+	_harg("1" (SCHEDOP_shutdown), "2"  (&shutdown_reason), "3" (srec)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)));
+#else
+    _hypercall(__HYPERVISOR_sched_op,
+	_harg("1" (SCHEDOP_shutdown), "2" (SHUTDOWN_suspend), "3" (srec)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)));
+#endif
+
+    return ret;
+}
+
+static __inline long
+HYPERVISOR_set_timer_op(uint64_t timeout)
+{
+    long ret;
+    unsigned long timeout_hi = (unsigned long)(timeout>>32);
+    unsigned long timeout_lo = (unsigned long)timeout;
+    unsigned long ign1, ign2;
+
+    _hypercall(__HYPERVISOR_set_timer_op,
+	 _harg("1" (timeout_lo), "2" (timeout_hi)),
+	 _harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
+
+    return ret;
+}
+
+static __inline int
+HYPERVISOR_platform_op(struct xen_platform_op *platform_op)
+{
+    int ret;
+    unsigned long ign1;
+
+    platform_op->interface_version = XENPF_INTERFACE_VERSION;
+    _hypercall(__HYPERVISOR_platform_op, _harg("1" (platform_op)),
+	_harg("=a" (ret), "=b" (ign1)));
+
+    return ret;
+}
+
+static __inline int
+HYPERVISOR_multicall(void *call_list, int nr_calls)
+{
+    int ret;
+    unsigned long ign1, ign2;
+
+    _hypercall(__HYPERVISOR_multicall,
+	 _harg("1" (call_list), "2" (nr_calls)),
+	 _harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
+
+    return ret;
+}
+
+
+static __inline int
+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" (&op->u)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
+#endif
+    return ret;
+}
+
+static __inline int
+HYPERVISOR_console_io(int cmd, int count, char *str)
+{
+    int ret;
+    unsigned long ign1, ign2, ign3;
+
+    _hypercall(__HYPERVISOR_console_io,
+	_harg("1" (cmd), "2" (count), "3" (str)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)));
+
+    return ret;
+}
+
+static __inline int
+HYPERVISOR_physdev_op(void *physdev_op)
+{
+    int ret;
+    unsigned long ign1;
+
+    _hypercall(__HYPERVISOR_physdev_op, _harg("1" (physdev_op)),
+	_harg("=a" (ret), "=b" (ign1)));
+
+    return ret;
+}
+
+static __inline int
+HYPERVISOR_vm_assist(unsigned int cmd, unsigned int type)
+{
+    int ret;
+    unsigned long ign1, ign2;
+
+    _hypercall(__HYPERVISOR_vm_assist, _harg("1" (cmd), "2" (type)),
+	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
+
+    return ret;
+}
+
+static __inline int
+HYPERVISOR_sysctl(void *sysctl)
+{
+    int ret;
+    unsigned long ign1;
+
+    _hypercall(__HYPERVISOR_sysctl, _harg("1" (sysctl)),
+	_harg("=a" (ret), "=b" (ign1)));
+
+    return ret;
+}
+#endif /* _XENI386_HYPERVISOR_H_ */

Index: src/sys/arch/xen/conf/files.xen.pv
diff -u /dev/null src/sys/arch/xen/conf/files.xen.pv:1.1.2.1
--- /dev/null	Thu Apr 16 08:46:36 2020
+++ src/sys/arch/xen/conf/files.xen.pv	Thu Apr 16 08:46:35 2020
@@ -0,0 +1,47 @@
+#	$NetBSD: files.xen.pv,v 1.1.2.1 2020/04/16 08:46:35 bouyer Exp $
+
+file	arch/xen/x86/autoconf.c		xenpv
+file	arch/xen/x86/x86_xpmap.c	xenpv
+file	arch/xen/x86/xen_pmap.c		xenpv
+file	arch/xen/x86/xenfunc.c		xenpv
+file	arch/xen/xen/xen_acpi_machdep.c	acpi & xenpv
+
+file	arch/xen/xen/clock.c		xenpv
+file	arch/xen/x86/xen_bus_dma.c	machdep & xenpv
+file	arch/xen/x86/consinit.c		machdep & xenpv
+file	arch/xen/x86/pintr.c		machdep & dom0ops & xenpv
+
+#
+# System bus types
+#
+
+# Xen event peudo-device
+defpseudo xenevt
+defpseudo xvif
+defpseudo xbdback
+
+# PCI frontend
+device xpci: pcibus
+attach xpci at xenbus with xpci_xenbus
+file	arch/xen/xen/xpci_xenbus.c	xpci_xenbus
+
+# Xen Balloon driver
+device	balloon
+attach	balloon at xenbus
+file	arch/xen/xen/balloon.c		balloon
+
+device	pciback {unit = -1}
+attach	pciback at pci
+file	arch/xen/xen/pciback.c		pciback
+
+device vcpu
+attach vcpu at xendevbus
+file	arch/xen/x86/cpu.c		xenpv & vcpu
+
+# Domain-0 operations
+defflag	opt_xen.h			DOM0OPS XENPV
+file	arch/xen/xen/privcmd.c		dom0ops
+file 	arch/xen/x86/xen_shm_machdep.c	dom0ops
+file	arch/xen/xen/xenevt.c		xenevt & (dom0ops | xenpvhvm)
+file	arch/xen/xen/xennetback_xenbus.c xvif
+file	arch/xen/xen/xbdback_xenbus.c xbdback

Reply via email to