svn commit: r255040 - in head/sys: amd64/amd64 amd64/include amd64/include/xen conf dev/xen/balloon dev/xen/blkback dev/xen/blkfront dev/xen/console dev/xen/control dev/xen/netback dev/xen/netfront...

Justin T. Gibbs gibbs at FreeBSD.org
Thu Aug 29 19:52:22 UTC 2013


Author: gibbs
Date: Thu Aug 29 19:52:18 2013
New Revision: 255040
URL: http://svnweb.freebsd.org/changeset/base/255040

Log:
  Implement vector callback for PVHVM and unify event channel implementations
  
  Re-structure Xen HVM support so that:
  	- Xen is detected and hypercalls can be performed very
  	  early in system startup.
  	- Xen interrupt services are implemented using FreeBSD's native
  	  interrupt delivery infrastructure.
  	- the Xen interrupt service implementation is shared between PV
  	  and HVM guests.
  	- Xen interrupt handlers can optionally use a filter handler
  	  in order to avoid the overhead of dispatch to an interrupt
  	  thread.
  	- interrupt load can be distributed among all available CPUs.
  	- the overhead of accessing the emulated local and I/O apics
  	  on HVM is removed for event channel port events.
  	- a similar optimization can eventually, and fairly easily,
  	  be used to optimize MSI.
  
  Early Xen detection, HVM refactoring, PVHVM interrupt infrastructure,
  and misc Xen cleanups:
  
  Sponsored by: Spectra Logic Corporation
  
  Unification of PV & HVM interrupt infrastructure, bug fixes,
  and misc Xen cleanups:
  
  Submitted by: Roger Pau Monné
  Sponsored by: Citrix Systems R&D
  
  sys/x86/x86/local_apic.c:
  sys/amd64/include/apicvar.h:
  sys/i386/include/apicvar.h:
  sys/amd64/amd64/apic_vector.S:
  sys/i386/i386/apic_vector.s:
  sys/amd64/amd64/machdep.c:
  sys/i386/i386/machdep.c:
  sys/i386/xen/exception.s:
  sys/x86/include/segments.h:
  	Reserve IDT vector 0x93 for the Xen event channel upcall
  	interrupt handler.  On Hypervisors that support the direct
  	vector callback feature, we can request that this vector be
  	called directly by an injected HVM interrupt event, instead
  	of a simulated PCI interrupt on the Xen platform PCI device.
  	This avoids all of the overhead of dealing with the emulated
  	I/O APIC and local APIC.  It also means that the Hypervisor
  	can inject these events on any CPU, allowing upcalls for
  	different ports to be handled in parallel.
  
  sys/amd64/amd64/mp_machdep.c:
  sys/i386/i386/mp_machdep.c:
  	Map Xen per-vcpu area during AP startup.
  
  sys/amd64/include/intr_machdep.h:
  sys/i386/include/intr_machdep.h:
  	Increase the FreeBSD IRQ vector table to include space
  	for event channel interrupt sources.
  
  sys/amd64/include/pcpu.h:
  sys/i386/include/pcpu.h:
  	Remove Xen HVM per-cpu variable data.  These fields are now
  	allocated via the dynamic per-cpu scheme.  See xen_intr.c
  	for details.
  
  sys/amd64/include/xen/hypercall.h:
  sys/dev/xen/blkback/blkback.c:
  sys/i386/include/xen/xenvar.h:
  sys/i386/xen/clock.c:
  sys/i386/xen/xen_machdep.c:
  sys/xen/gnttab.c:
  	Prefer FreeBSD primatives to Linux ones in Xen support code.
  
  sys/amd64/include/xen/xen-os.h:
  sys/i386/include/xen/xen-os.h:
  sys/xen/xen-os.h:
  sys/dev/xen/balloon/balloon.c:
  sys/dev/xen/blkback/blkback.c:
  sys/dev/xen/blkfront/blkfront.c:
  sys/dev/xen/console/xencons_ring.c:
  sys/dev/xen/control/control.c:
  sys/dev/xen/netback/netback.c:
  sys/dev/xen/netfront/netfront.c:
  sys/dev/xen/xenpci/xenpci.c:
  sys/i386/i386/machdep.c:
  sys/i386/include/pmap.h:
  sys/i386/include/xen/xenfunc.h:
  sys/i386/isa/npx.c:
  sys/i386/xen/clock.c:
  sys/i386/xen/mp_machdep.c:
  sys/i386/xen/mptable.c:
  sys/i386/xen/xen_clock_util.c:
  sys/i386/xen/xen_machdep.c:
  sys/i386/xen/xen_rtc.c:
  sys/xen/evtchn/evtchn_dev.c:
  sys/xen/features.c:
  sys/xen/gnttab.c:
  sys/xen/gnttab.h:
  sys/xen/hvm.h:
  sys/xen/xenbus/xenbus.c:
  sys/xen/xenbus/xenbus_if.m:
  sys/xen/xenbus/xenbusb_front.c:
  sys/xen/xenbus/xenbusvar.h:
  sys/xen/xenstore/xenstore.c:
  sys/xen/xenstore/xenstore_dev.c:
  sys/xen/xenstore/xenstorevar.h:
  	Pull common Xen OS support functions/settings into xen/xen-os.h.
  
  sys/amd64/include/xen/xen-os.h:
  sys/i386/include/xen/xen-os.h:
  sys/xen/xen-os.h:
  	Remove constants, macros, and functions unused in FreeBSD's Xen
  	support.
  
  sys/xen/xen-os.h:
  sys/i386/xen/xen_machdep.c:
  sys/x86/xen/hvm.c:
  	Introduce new functions xen_domain(), xen_pv_domain(), and
  	xen_hvm_domain().  These are used in favor of #ifdefs so that
  	FreeBSD can dynamically detect and adapt to the presence of
  	a hypervisor.  The goal is to have an HVM optimized GENERIC,
  	but more is necessary before this is possible.
  
  sys/amd64/amd64/machdep.c:
  sys/dev/xen/xenpci/xenpcivar.h:
  sys/dev/xen/xenpci/xenpci.c:
  sys/x86/xen/hvm.c:
  sys/sys/kernel.h:
  	Refactor magic ioport, Hypercall table and Hypervisor shared
  	information page setup, and move it to a dedicated HVM support
  	module.
  
  	HVM mode initialization is now triggered during the
  	SI_SUB_HYPERVISOR phase of system startup.  This currently
  	occurs just after the kernel VM is fully setup which is
  	just enough infrastructure to allow the hypercall table
  	and shared info page to be properly mapped.
  
  sys/xen/hvm.h:
  sys/x86/xen/hvm.c:
  	Add definitions and a method for configuring Hypervisor event
  	delievery via a direct vector callback.
  
  sys/amd64/include/xen/xen-os.h:
  sys/x86/xen/hvm.c:
  
  sys/conf/files:
  sys/conf/files.amd64:
  sys/conf/files.i386:
  	Adjust kernel build to reflect the refactoring of early
  	Xen startup code and Xen interrupt services.
  
  sys/dev/xen/blkback/blkback.c:
  sys/dev/xen/blkfront/blkfront.c:
  sys/dev/xen/blkfront/block.h:
  sys/dev/xen/control/control.c:
  sys/dev/xen/evtchn/evtchn_dev.c:
  sys/dev/xen/netback/netback.c:
  sys/dev/xen/netfront/netfront.c:
  sys/xen/xenstore/xenstore.c:
  sys/xen/evtchn/evtchn_dev.c:
  sys/dev/xen/console/console.c:
  sys/dev/xen/console/xencons_ring.c
  	Adjust drivers to use new xen_intr_*() API.
  
  sys/dev/xen/blkback/blkback.c:
  	Since blkback defers all event handling to a taskqueue,
  	convert this task queue to a "fast" taskqueue, and schedule
  	it via an interrupt filter.  This avoids an unnecessary
  	ithread context switch.
  
  sys/xen/xenstore/xenstore.c:
  	The xenstore driver is MPSAFE.  Indicate as much when
  	registering its interrupt handler.
  
  sys/xen/xenbus/xenbus.c:
  sys/xen/xenbus/xenbusvar.h:
  	Remove unused event channel APIs.
  
  sys/xen/evtchn.h:
  	Remove all kernel Xen interrupt service API definitions
  	from this file.  It is now only used for structure and
  	ioctl definitions related to the event channel userland
  	device driver.
  
  	Update the definitions in this file to match those from
  	NetBSD.  Implementing this interface will be necessary for
  	Dom0 support.
  
  sys/xen/evtchn/evtchnvar.h:
  	Add a header file for implemenation internal APIs related
  	to managing event channels event delivery.  This is used
  	to allow, for example, the event channel userland device
  	driver to access low-level routines that typical kernel
  	consumers of event channel services should never access.
  
  sys/xen/interface/event_channel.h:
  sys/xen/xen_intr.h:
  	Standardize on the evtchn_port_t type for referring to
  	an event channel port id.  In order to prevent low-level
  	event channel APIs from leaking to kernel consumers who
  	should not have access to this data, the type is defined
  	twice: Once in the Xen provided event_channel.h, and again
  	in xen/xen_intr.h.  The double declaration is protected by
  	__XEN_EVTCHN_PORT_DEFINED__ to ensure it is never declared
  	twice within a given compilation unit.
  
  sys/xen/xen_intr.h:
  sys/xen/evtchn/evtchn.c:
  sys/x86/xen/xen_intr.c:
  sys/dev/xen/xenpci/evtchn.c:
  sys/dev/xen/xenpci/xenpcivar.h:
  	New implementation of Xen interrupt services.  This is
  	similar in many respects to the i386 PV implementation with
  	the exception that events for bound to event channel ports
  	(i.e. not IPI, virtual IRQ, or physical IRQ) are further
  	optimized to avoid mask/unmask operations that aren't
  	necessary for these edge triggered events.
  
  	Stubs exist for supporting physical IRQ binding, but will
  	need additional work before this implementation can be
  	fully shared between PV and HVM.
  
  sys/amd64/amd64/mp_machdep.c:
  sys/i386/i386/mp_machdep.c:
  sys/i386/xen/mp_machdep.c
  sys/x86/xen/hvm.c:
  	Add support for placing vcpu_info into an arbritary memory
  	page instead of using HYPERVISOR_shared_info->vcpu_info.
  	This allows the creation of domains with more than 32 vcpus.
  
  sys/i386/i386/machdep.c:
  sys/i386/xen/clock.c:
  sys/i386/xen/xen_machdep.c:
  sys/i386/xen/exception.s:
  	Add support for new event channle implementation.

Added:
  head/sys/x86/xen/
  head/sys/x86/xen/hvm.c   (contents, props changed)
  head/sys/x86/xen/xen_intr.c   (contents, props changed)
  head/sys/xen/evtchn/evtchnvar.h   (contents, props changed)
  head/sys/xen/xen-os.h   (contents, props changed)
Deleted:
  head/sys/dev/xen/xenpci/evtchn.c
  head/sys/xen/evtchn/evtchn.c
Modified:
  head/sys/amd64/amd64/apic_vector.S
  head/sys/amd64/amd64/machdep.c
  head/sys/amd64/amd64/mp_machdep.c
  head/sys/amd64/include/apicvar.h
  head/sys/amd64/include/intr_machdep.h
  head/sys/amd64/include/pcpu.h
  head/sys/amd64/include/xen/hypercall.h
  head/sys/amd64/include/xen/xen-os.h
  head/sys/conf/files
  head/sys/conf/files.amd64
  head/sys/conf/files.i386
  head/sys/dev/xen/balloon/balloon.c
  head/sys/dev/xen/blkback/blkback.c
  head/sys/dev/xen/blkfront/blkfront.c
  head/sys/dev/xen/blkfront/block.h
  head/sys/dev/xen/console/console.c
  head/sys/dev/xen/console/xencons_ring.c
  head/sys/dev/xen/control/control.c
  head/sys/dev/xen/netback/netback.c
  head/sys/dev/xen/netfront/netfront.c
  head/sys/dev/xen/xenpci/xenpci.c
  head/sys/dev/xen/xenpci/xenpcivar.h
  head/sys/i386/i386/apic_vector.s
  head/sys/i386/i386/machdep.c
  head/sys/i386/i386/mp_machdep.c
  head/sys/i386/include/apicvar.h
  head/sys/i386/include/intr_machdep.h
  head/sys/i386/include/pcpu.h
  head/sys/i386/include/pmap.h
  head/sys/i386/include/xen/xen-os.h
  head/sys/i386/include/xen/xenfunc.h
  head/sys/i386/include/xen/xenvar.h
  head/sys/i386/isa/npx.c
  head/sys/i386/xen/clock.c
  head/sys/i386/xen/exception.s
  head/sys/i386/xen/mp_machdep.c
  head/sys/i386/xen/mptable.c
  head/sys/i386/xen/xen_clock_util.c
  head/sys/i386/xen/xen_machdep.c
  head/sys/i386/xen/xen_rtc.c
  head/sys/sys/kernel.h
  head/sys/x86/include/segments.h
  head/sys/x86/x86/local_apic.c
  head/sys/xen/evtchn.h
  head/sys/xen/evtchn/evtchn_dev.c
  head/sys/xen/features.c
  head/sys/xen/gnttab.c
  head/sys/xen/gnttab.h
  head/sys/xen/hvm.h
  head/sys/xen/interface/event_channel.h
  head/sys/xen/xen_intr.h
  head/sys/xen/xenbus/xenbus.c
  head/sys/xen/xenbus/xenbus_if.m
  head/sys/xen/xenbus/xenbusb_front.c
  head/sys/xen/xenbus/xenbusvar.h
  head/sys/xen/xenstore/xenstore.c
  head/sys/xen/xenstore/xenstore_dev.c
  head/sys/xen/xenstore/xenstorevar.h

Modified: head/sys/amd64/amd64/apic_vector.S
==============================================================================
--- head/sys/amd64/amd64/apic_vector.S	Thu Aug 29 19:47:52 2013	(r255039)
+++ head/sys/amd64/amd64/apic_vector.S	Thu Aug 29 19:52:18 2013	(r255040)
@@ -128,6 +128,22 @@ IDTVEC(errorint)
 	MEXITCOUNT
 	jmp	doreti
 
+#ifdef XENHVM
+/*
+ * Xen event channel upcall interrupt handler.
+ * Only used when the hypervisor supports direct vector callbacks.
+ */
+	.text
+	SUPERALIGN_TEXT
+IDTVEC(xen_intr_upcall)
+	PUSH_FRAME
+	FAKE_MCOUNT(TF_RIP(%rsp))
+	movq	%rsp, %rdi
+	call	xen_intr_handle_upcall
+	MEXITCOUNT
+	jmp	doreti
+#endif
+
 #ifdef SMP
 /*
  * Global address space TLB shootdown.

Modified: head/sys/amd64/amd64/machdep.c
==============================================================================
--- head/sys/amd64/amd64/machdep.c	Thu Aug 29 19:47:52 2013	(r255039)
+++ head/sys/amd64/amd64/machdep.c	Thu Aug 29 19:52:18 2013	(r255040)
@@ -1204,6 +1204,9 @@ extern inthand_t
 #ifdef KDTRACE_HOOKS
 	IDTVEC(dtrace_ret),
 #endif
+#ifdef XENHVM
+	IDTVEC(xen_intr_upcall),
+#endif
 	IDTVEC(fast_syscall), IDTVEC(fast_syscall32);
 
 #ifdef DDB
@@ -1787,6 +1790,9 @@ hammer_time(u_int64_t modulep, u_int64_t
 #ifdef KDTRACE_HOOKS
 	setidt(IDT_DTRACE_RET, &IDTVEC(dtrace_ret), SDT_SYSIGT, SEL_UPL, 0);
 #endif
+#ifdef XENHVM
+	setidt(IDT_EVTCHN, &IDTVEC(xen_intr_upcall), SDT_SYSIGT, SEL_UPL, 0);
+#endif
 
 	r_idt.rd_limit = sizeof(idt0) - 1;
 	r_idt.rd_base = (long) idt;
@@ -1910,14 +1916,6 @@ hammer_time(u_int64_t modulep, u_int64_t
 	if (env != NULL)
 		strlcpy(kernelname, env, sizeof(kernelname));
 
-#ifdef XENHVM
-	if (inw(0x10) == 0x49d2) {
-		if (bootverbose)
-			printf("Xen detected: disabling emulated block and network devices\n");
-		outw(0x10, 3);
-	}
-#endif
-
 	cpu_probe_amdc1e();
 
 #ifdef FDT

Modified: head/sys/amd64/amd64/mp_machdep.c
==============================================================================
--- head/sys/amd64/amd64/mp_machdep.c	Thu Aug 29 19:47:52 2013	(r255039)
+++ head/sys/amd64/amd64/mp_machdep.c	Thu Aug 29 19:52:18 2013	(r255040)
@@ -70,6 +70,10 @@ __FBSDID("$FreeBSD$");
 #include <machine/specialreg.h>
 #include <machine/tss.h>
 
+#ifdef XENHVM
+#include <xen/hvm.h>
+#endif
+
 #define WARMBOOT_TARGET		0
 #define WARMBOOT_OFF		(KERNBASE + 0x0467)
 #define WARMBOOT_SEG		(KERNBASE + 0x0469)
@@ -711,6 +715,11 @@ init_secondary(void)
 	/* set up FPU state on the AP */
 	fpuinit();
 
+#ifdef XENHVM
+	/* register vcpu_info area */
+	xen_hvm_init_cpu();
+#endif
+
 	/* A quick check from sanity claus */
 	cpuid = PCPU_GET(cpuid);
 	if (PCPU_GET(apic_id) != lapic_id()) {

Modified: head/sys/amd64/include/apicvar.h
==============================================================================
--- head/sys/amd64/include/apicvar.h	Thu Aug 29 19:47:52 2013	(r255039)
+++ head/sys/amd64/include/apicvar.h	Thu Aug 29 19:52:18 2013	(r255040)
@@ -227,6 +227,7 @@ int	lapic_set_lvt_triggermode(u_int apic
 	    enum intr_trigger trigger);
 void	lapic_set_tpr(u_int vector);
 void	lapic_setup(int boot);
+void	xen_intr_handle_upcall(struct trapframe *frame);
 
 #endif /* !LOCORE */
 #endif /* _MACHINE_APICVAR_H_ */

Modified: head/sys/amd64/include/intr_machdep.h
==============================================================================
--- head/sys/amd64/include/intr_machdep.h	Thu Aug 29 19:47:52 2013	(r255039)
+++ head/sys/amd64/include/intr_machdep.h	Thu Aug 29 19:52:18 2013	(r255040)
@@ -44,12 +44,24 @@
  * allocate IDT vectors.
  *
  * The first 255 IRQs (0 - 254) are reserved for ISA IRQs and PCI intline IRQs.
- * IRQ values beyond 256 are used by MSI.  We leave 255 unused to avoid
- * confusion since 255 is used in PCI to indicate an invalid IRQ.
+ * IRQ values from 256 to 767 are used by MSI.  When running under the Xen
+ * Hypervisor, IRQ values from 768 to 4863 are available for binding to
+ * event channel events.  We leave 255 unused to avoid confusion since 255 is
+ * used in PCI to indicate an invalid IRQ.
  */
 #define	NUM_MSI_INTS	512
 #define	FIRST_MSI_INT	256
-#define	NUM_IO_INTS	(FIRST_MSI_INT + NUM_MSI_INTS)
+#ifdef XENHVM
+#include <xen/xen-os.h>
+#define	NUM_EVTCHN_INTS	NR_EVENT_CHANNELS
+#define	FIRST_EVTCHN_INT \
+    (FIRST_MSI_INT + NUM_MSI_INTS)
+#define	LAST_EVTCHN_INT \
+    (FIRST_EVTCHN_INT + NUM_EVTCHN_INTS - 1)
+#else
+#define	NUM_EVTCHN_INTS	0
+#endif
+#define	NUM_IO_INTS	(FIRST_MSI_INT + NUM_MSI_INTS + NUM_EVTCHN_INTS)
 
 /*
  * Default base address for MSI messages on x86 platforms.

Modified: head/sys/amd64/include/pcpu.h
==============================================================================
--- head/sys/amd64/include/pcpu.h	Thu Aug 29 19:47:52 2013	(r255039)
+++ head/sys/amd64/include/pcpu.h	Thu Aug 29 19:52:18 2013	(r255040)
@@ -42,15 +42,6 @@
 #endif
 #endif
 
-#ifdef XENHVM
-#define PCPU_XEN_FIELDS							\
-	;								\
-	unsigned int pc_last_processed_l1i;				\
-	unsigned int pc_last_processed_l2i
-#else
-#define PCPU_XEN_FIELDS
-#endif
-
 /*
  * The SMP parts are setup in pmap.c and locore.s for the BSP, and
  * mp_machdep.c sets up the data for the AP's to "see" when they awake.
@@ -76,8 +67,7 @@
 	struct system_segment_descriptor *pc_ldt;			\
 	/* Pointer to the CPU TSS descriptor */				\
 	struct system_segment_descriptor *pc_tss;			\
-	u_int	pc_cmci_mask		/* MCx banks for CMCI */	\
-	PCPU_XEN_FIELDS;						\
+	u_int	pc_cmci_mask;		/* MCx banks for CMCI */	\
 	uint64_t pc_dbreg[16];		/* ddb debugging regs */	\
 	int pc_dbreg_cmd;		/* ddb debugging reg cmd */	\
 	char	__pad[161]		/* be divisor of PAGE_SIZE	\

Modified: head/sys/amd64/include/xen/hypercall.h
==============================================================================
--- head/sys/amd64/include/xen/hypercall.h	Thu Aug 29 19:47:52 2013	(r255039)
+++ head/sys/amd64/include/xen/hypercall.h	Thu Aug 29 19:52:18 2013	(r255040)
@@ -1,7 +1,7 @@
 /******************************************************************************
  * hypercall.h
  * 
- * Linux-specific hypervisor handling.
+ * FreeBSD-specific hypervisor handling.
  * 
  * Copyright (c) 2002-2004, K A Fraser
  * 
@@ -32,6 +32,8 @@
  * 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.
+ *
+ * $FreeBSD$
  */
 
 #ifndef __MACHINE_XEN_HYPERCALL_H__
@@ -270,7 +272,7 @@ HYPERVISOR_event_channel_op(
 	int rc = _hypercall2(int, event_channel_op, cmd, arg);
 
 #if CONFIG_XEN_COMPAT <= 0x030002
-	if (unlikely(rc == -ENOXENSYS)) {
+	if (__predict_false(rc == -ENOXENSYS)) {
 		struct evtchn_op op;
 		op.cmd = cmd;
 		memcpy(&op.u, arg, sizeof(op.u));
@@ -303,7 +305,7 @@ HYPERVISOR_physdev_op(
 	int rc = _hypercall2(int, physdev_op, cmd, arg);
 
 #if CONFIG_XEN_COMPAT <= 0x030002
-	if (unlikely(rc == -ENOXENSYS)) {
+	if (__predict_false(rc == -ENOXENSYS)) {
 		struct physdev_op op;
 		op.cmd = cmd;
 		memcpy(&op.u, arg, sizeof(op.u));

Modified: head/sys/amd64/include/xen/xen-os.h
==============================================================================
--- head/sys/amd64/include/xen/xen-os.h	Thu Aug 29 19:47:52 2013	(r255039)
+++ head/sys/amd64/include/xen/xen-os.h	Thu Aug 29 19:52:18 2013	(r255040)
@@ -1,40 +1,42 @@
 /******************************************************************************
- * os.h
+ * amd64/xen/xen-os.h
  * 
- * random collection of macros and definition
+ * Random collection of macros and definition
+ *
+ * Copyright (c) 2003, 2004 Keir Fraser (on behalf of the Xen team)
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (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.
  *
  * $FreeBSD$
  */
 
-#ifndef _XEN_OS_H_
-#define _XEN_OS_H_
+#ifndef _MACHINE_XEN_XEN_OS_H_
+#define _MACHINE_XEN_XEN_OS_H_
 
 #ifdef PAE
 #define CONFIG_X86_PAE
 #endif
 
-#ifdef LOCORE
-#define __ASSEMBLY__
-#endif
-
-#if !defined(__XEN_INTERFACE_VERSION__)  
-#define  __XEN_INTERFACE_VERSION__ 0x00030208
-#endif  
-
-#define GRANT_REF_INVALID   0xffffffff
-
-#include <xen/interface/xen.h>
-
 /* Everything below this point is not included by assembler (.S) files. */
 #ifndef __ASSEMBLY__
 
-/* Force a proper event-channel callback from Xen. */
-void force_evtchn_callback(void);
-
-extern int gdtset;
-
-extern shared_info_t *HYPERVISOR_shared_info;
-
 /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
 static inline void rep_nop(void)
 {
@@ -42,161 +44,12 @@ static inline void rep_nop(void)
 }
 #define cpu_relax() rep_nop()
 
-/* crude memory allocator for memory allocation early in 
- *  boot
- */
-void *bootmem_alloc(unsigned int size);
-void bootmem_free(void *ptr, unsigned int size);
-
-void printk(const char *fmt, ...);
-
-/* some function prototypes */
-void trap_init(void);
-
-#define likely(x)  __builtin_expect((x),1)
-#define unlikely(x)  __builtin_expect((x),0)
-
-#ifndef XENHVM
-
-/*
- * STI/CLI equivalents. These basically set and clear the virtual
- * event_enable flag in the shared_info structure. Note that when
- * the enable bit is set, there may be pending events to be handled.
- * We may therefore call into do_hypervisor_callback() directly.
- */
-
-#define __cli()                                                         \
-do {                                                                    \
-        vcpu_info_t *_vcpu;                                             \
-        _vcpu = &HYPERVISOR_shared_info->vcpu_info[PCPU_GET(cpuid)];	\
-        _vcpu->evtchn_upcall_mask = 1;                                  \
-        barrier();                                                      \
-} while (0)
-
-#define __sti()                                                         \
-do {                                                                    \
-        vcpu_info_t *_vcpu;                                             \
-        barrier();                                                      \
-        _vcpu = &HYPERVISOR_shared_info->vcpu_info[PCPU_GET(cpuid)];	\
-        _vcpu->evtchn_upcall_mask = 0;                                  \
-        barrier(); /* unmask then check (avoid races) */                \
-        if ( unlikely(_vcpu->evtchn_upcall_pending) )                   \
-                force_evtchn_callback();                                \
-} while (0)
-
-#define __restore_flags(x)                                              \
-do {                                                                    \
-        vcpu_info_t *_vcpu;                                             \
-        barrier();                                                      \
-        _vcpu = &HYPERVISOR_shared_info->vcpu_info[PCPU_GET(cpuid)];	\
-        if ((_vcpu->evtchn_upcall_mask = (x)) == 0) {                   \
-                barrier(); /* unmask then check (avoid races) */        \
-                if ( unlikely(_vcpu->evtchn_upcall_pending) )           \
-                        force_evtchn_callback();                        \
-        } 								\
-} while (0)
-
-/*
- * Add critical_{enter, exit}?
- *
- */
-#define __save_and_cli(x)                                               \
-do {                                                                    \
-        vcpu_info_t *_vcpu;                                             \
-        _vcpu = &HYPERVISOR_shared_info->vcpu_info[PCPU_GET(cpuid)];	\
-        (x) = _vcpu->evtchn_upcall_mask;                                \
-        _vcpu->evtchn_upcall_mask = 1;                                  \
-        barrier();                                                      \
-} while (0)
-
-
-#define cli() __cli()
-#define sti() __sti()
-#define save_flags(x) __save_flags(x)
-#define restore_flags(x) __restore_flags(x)
-#define save_and_cli(x) __save_and_cli(x)
-
-#define local_irq_save(x)       __save_and_cli(x)
-#define local_irq_restore(x)    __restore_flags(x)
-#define local_irq_disable()     __cli()
-#define local_irq_enable()      __sti()
-
-#define mtx_lock_irqsave(lock, x) {local_irq_save((x)); mtx_lock_spin((lock));}
-#define mtx_unlock_irqrestore(lock, x) {mtx_unlock_spin((lock)); local_irq_restore((x)); }
-#define spin_lock_irqsave mtx_lock_irqsave
-#define spin_unlock_irqrestore mtx_unlock_irqrestore
-
-#else
-#endif
-
-#ifndef xen_mb
-#define xen_mb() mb()
-#endif
-#ifndef xen_rmb
-#define xen_rmb() rmb()
-#endif
-#ifndef xen_wmb
-#define xen_wmb() wmb()
-#endif
-#ifdef SMP
-#define smp_mb() mb() 
-#define smp_rmb() rmb()
-#define smp_wmb() wmb()
-#define smp_read_barrier_depends()      read_barrier_depends()
-#define set_mb(var, value) do { xchg(&var, value); } while (0)
-#else
-#define smp_mb()        barrier()
-#define smp_rmb()       barrier()
-#define smp_wmb()       barrier()
-#define smp_read_barrier_depends()      do { } while(0)
-#define set_mb(var, value) do { var = value; barrier(); } while (0)
-#endif
-
-
 /* This is a barrier for the compiler only, NOT the processor! */
 #define barrier() __asm__ __volatile__("": : :"memory")
 
 #define LOCK_PREFIX ""
 #define LOCK ""
 #define ADDR (*(volatile long *) addr)
-/*
- * Make sure gcc doesn't try to be clever and move things around
- * on us. We need to use _exactly_ the address the user gave us,
- * not some alias that contains the same information.
- */
-typedef struct { volatile int counter; } atomic_t;
-
-
-
-#define xen_xchg(ptr,v) \
-        ((__typeof__(*(ptr)))__xchg((unsigned long)(v),(ptr),sizeof(*(ptr))))
-struct __xchg_dummy { unsigned long a[100]; };
-#define __xg(x) ((volatile struct __xchg_dummy *)(x))
-static __inline unsigned long __xchg(unsigned long x, volatile void * ptr,
-                                   int size)
-{
-    switch (size) {
-    case 1:
-        __asm__ __volatile__("xchgb %b0,%1"
-                             :"=q" (x)
-                             :"m" (*__xg(ptr)), "0" (x)
-                             :"memory");
-        break;
-    case 2:
-        __asm__ __volatile__("xchgw %w0,%1"
-                             :"=r" (x)
-                             :"m" (*__xg(ptr)), "0" (x)
-                             :"memory");
-        break;
-    case 4:
-        __asm__ __volatile__("xchgl %0,%1"
-                             :"=r" (x)
-                             :"m" (*__xg(ptr)), "0" (x)
-                             :"memory");
-        break;
-    }
-    return x;
-}
 
 /**
  * test_and_clear_bit - Clear a bit and return its old value
@@ -238,7 +91,6 @@ static __inline int variable_test_bit(in
  constant_test_bit((nr),(addr)) : \
  variable_test_bit((nr),(addr)))
 
-
 /**
  * set_bit - Atomically set a bit in memory
  * @nr: the bit to set
@@ -275,25 +127,6 @@ static __inline__ void clear_bit(int nr,
                 :"Ir" (nr));
 }
 
-/**
- * atomic_inc - increment atomic variable
- * @v: pointer of type atomic_t
- * 
- * Atomically increments @v by 1.  Note that the guaranteed
- * useful range of an atomic_t is only 24 bits.
- */ 
-static __inline__ void atomic_inc(atomic_t *v)
-{
-        __asm__ __volatile__(
-                LOCK "incl %0"
-                :"=m" (v->counter)
-                :"m" (v->counter));
-}
-
-
-#define rdtscll(val) \
-     __asm__ __volatile__("rdtsc" : "=A" (val))
-
 #endif /* !__ASSEMBLY__ */
 
-#endif /* _OS_H_ */
+#endif /* _MACHINE_XEN_XEN_OS_H_ */

Modified: head/sys/conf/files
==============================================================================
--- head/sys/conf/files	Thu Aug 29 19:47:52 2013	(r255039)
+++ head/sys/conf/files	Thu Aug 29 19:52:18 2013	(r255040)
@@ -2499,7 +2499,6 @@ dev/xen/control/control.c	optional xen |
 dev/xen/netback/netback.c	optional xen | xenhvm
 dev/xen/netfront/netfront.c	optional xen | xenhvm
 dev/xen/xenpci/xenpci.c		optional xenpci
-dev/xen/xenpci/evtchn.c         optional xenpci
 dev/xl/if_xl.c			optional xl pci
 dev/xl/xlphy.c			optional xl pci
 fs/deadfs/dead_vnops.c		standard
@@ -3815,7 +3814,6 @@ vm/vm_zeroidle.c		standard
 vm/vnode_pager.c		standard
 xen/gnttab.c			optional xen | xenhvm
 xen/features.c			optional xen | xenhvm
-xen/evtchn/evtchn.c		optional xen
 xen/evtchn/evtchn_dev.c		optional xen | xenhvm
 xen/xenbus/xenbus_if.m		optional xen | xenhvm
 xen/xenbus/xenbus.c		optional xen | xenhvm

Modified: head/sys/conf/files.amd64
==============================================================================
--- head/sys/conf/files.amd64	Thu Aug 29 19:47:52 2013	(r255039)
+++ head/sys/conf/files.amd64	Thu Aug 29 19:52:18 2013	(r255040)
@@ -531,3 +531,5 @@ x86/x86/mptable_pci.c		optional	mptable 
 x86/x86/msi.c			optional	pci
 x86/x86/nexus.c			standard
 x86/x86/tsc.c			standard
+x86/xen/hvm.c			optional	xenhvm
+x86/xen/xen_intr.c		optional	xen | xenhvm

Modified: head/sys/conf/files.i386
==============================================================================
--- head/sys/conf/files.i386	Thu Aug 29 19:47:52 2013	(r255039)
+++ head/sys/conf/files.i386	Thu Aug 29 19:52:18 2013	(r255040)
@@ -568,3 +568,5 @@ x86/x86/mptable_pci.c		optional apic nat
 x86/x86/msi.c			optional apic pci
 x86/x86/nexus.c			standard
 x86/x86/tsc.c			standard
+x86/xen/hvm.c			optional xenhvm
+x86/xen/xen_intr.c		optional xen | xenhvm

Modified: head/sys/dev/xen/balloon/balloon.c
==============================================================================
--- head/sys/dev/xen/balloon/balloon.c	Thu Aug 29 19:47:52 2013	(r255039)
+++ head/sys/dev/xen/balloon/balloon.c	Thu Aug 29 19:52:18 2013	(r255040)
@@ -40,14 +40,15 @@ __FBSDID("$FreeBSD$");
 #include <sys/mutex.h>
 #include <sys/sysctl.h>
 
-#include <machine/xen/xen-os.h>
-#include <machine/xen/xenvar.h>
-#include <machine/xen/xenfunc.h>
+#include <vm/vm.h>
+#include <vm/vm_page.h>
+
+#include <xen/xen-os.h>
 #include <xen/hypervisor.h>
+#include <xen/features.h>
 #include <xen/xenstore/xenstorevar.h>
 
-#include <vm/vm.h>
-#include <vm/vm_page.h>
+#include <machine/xen/xenvar.h>
 
 static MALLOC_DEFINE(M_BALLOON, "Balloon", "Xen Balloon Driver");
 

Modified: head/sys/dev/xen/blkback/blkback.c
==============================================================================
--- head/sys/dev/xen/blkback/blkback.c	Thu Aug 29 19:47:52 2013	(r255039)
+++ head/sys/dev/xen/blkback/blkback.c	Thu Aug 29 19:52:18 2013	(r255040)
@@ -70,14 +70,13 @@ __FBSDID("$FreeBSD$");
 #include <geom/geom.h>
 
 #include <machine/_inttypes.h>
-#include <machine/xen/xen-os.h>
 
 #include <vm/vm.h>
 #include <vm/vm_extern.h>
 #include <vm/vm_kern.h>
 
+#include <xen/xen-os.h>
 #include <xen/blkif.h>
-#include <xen/evtchn.h>
 #include <xen/gnttab.h>
 #include <xen/xen_intr.h>
 
@@ -682,7 +681,7 @@ struct xbb_softc {
 	blkif_back_rings_t	  rings;
 
 	/** IRQ mapping for the communication ring event channel. */
-	int			  irq;
+	xen_intr_handle_t	  xen_intr_handle;
 
 	/**
 	 * \brief Backend access mode flags (e.g. write, or read-only).
@@ -1347,7 +1346,7 @@ xbb_send_response(struct xbb_softc *xbb,
 		taskqueue_enqueue(xbb->io_taskqueue, &xbb->io_task); 
 
 	if (notify)
-		notify_remote_via_irq(xbb->irq);
+		xen_intr_signal(xbb->xen_intr_handle);
 }
 
 /**
@@ -1616,8 +1615,8 @@ xbb_dispatch_io(struct xbb_softc *xbb, s
 		sg	              = NULL;
 
 		/* Check that number of segments is sane. */
-		if (unlikely(nseg == 0)
-		 || unlikely(nseg > xbb->max_request_segments)) {
+		if (__predict_false(nseg == 0)
+		 || __predict_false(nseg > xbb->max_request_segments)) {
 			DPRINTF("Bad number of segments in request (%d)\n",
 				nseg);
 			reqlist->status = BLKIF_RSP_ERROR;
@@ -1734,7 +1733,7 @@ xbb_dispatch_io(struct xbb_softc *xbb, s
 	for (seg_idx = 0, map = xbb->maps; seg_idx < reqlist->nr_segments;
 	     seg_idx++, map++){
 
-		if (unlikely(map->status != 0)) {
+		if (__predict_false(map->status != 0)) {
 			DPRINTF("invalid buffer -- could not remap "
 			        "it (%d)\n", map->status);
 			DPRINTF("Mapping(%d): Host Addr 0x%lx, flags "
@@ -2026,14 +2025,16 @@ xbb_run_queue(void *context, int pending
  * \param arg  Callback argument registerd during event channel
  *             binding - the xbb_softc for this instance.
  */
-static void
-xbb_intr(void *arg)
+static int
+xbb_filter(void *arg)
 {
 	struct xbb_softc *xbb;
 
-	/* Defer to kernel thread. */
+	/* Defer to taskqueue thread. */
 	xbb = (struct xbb_softc *)arg;
 	taskqueue_enqueue(xbb->io_taskqueue, &xbb->io_task); 
+
+	return (FILTER_HANDLED);
 }
 
 SDT_PROVIDER_DEFINE(xbb);
@@ -2081,7 +2082,7 @@ xbb_dispatch_dev(struct xbb_softc *xbb, 
 	if (operation == BIO_FLUSH) {
 		nreq = STAILQ_FIRST(&reqlist->contig_req_list);
 		bio = g_new_bio();
-		if (unlikely(bio == NULL)) {
+		if (__predict_false(bio == NULL)) {
 			DPRINTF("Unable to allocate bio for BIO_FLUSH\n");
 			error = ENOMEM;
 			return (error);
@@ -2143,7 +2144,7 @@ xbb_dispatch_dev(struct xbb_softc *xbb, 
 			}
 
 			bio = bios[nbio++] = g_new_bio();
-			if (unlikely(bio == NULL)) {
+			if (__predict_false(bio == NULL)) {
 				error = ENOMEM;
 				goto fail_free_bios;
 			}
@@ -2811,10 +2812,7 @@ xbb_disconnect(struct xbb_softc *xbb)
 	if ((xbb->flags & XBBF_RING_CONNECTED) == 0)
 		return (0);
 
-	if (xbb->irq != 0) {
-		unbind_from_irqhandler(xbb->irq);
-		xbb->irq = 0;
-	}
+	xen_intr_unbind(&xbb->xen_intr_handle);
 
 	mtx_unlock(&xbb->lock);
 	taskqueue_drain(xbb->io_taskqueue, &xbb->io_task); 
@@ -2966,13 +2964,14 @@ xbb_connect_ring(struct xbb_softc *xbb)
 
 	xbb->flags |= XBBF_RING_CONNECTED;
 
-	error =
-	    bind_interdomain_evtchn_to_irqhandler(xbb->otherend_id,
-						  xbb->ring_config.evtchn,
-						  device_get_nameunit(xbb->dev),
-						  xbb_intr, /*arg*/xbb,
-						  INTR_TYPE_BIO | INTR_MPSAFE,
-						  &xbb->irq);
+	error = xen_intr_bind_remote_port(xbb->dev,
+					  xbb->otherend_id,
+					  xbb->ring_config.evtchn,
+					  xbb_filter,
+					  /*ithread_handler*/NULL,
+					  /*arg*/xbb,
+					  INTR_TYPE_BIO | INTR_MPSAFE,
+					  &xbb->xen_intr_handle);
 	if (error) {
 		(void)xbb_disconnect(xbb);
 		xenbus_dev_fatal(xbb->dev, error, "binding event channel");
@@ -3791,9 +3790,10 @@ xbb_attach(device_t dev)
 	 * Create a taskqueue for doing work that must occur from a
 	 * thread context.
 	 */
-	xbb->io_taskqueue = taskqueue_create(device_get_nameunit(dev), M_NOWAIT,
-					     taskqueue_thread_enqueue,
-					     /*context*/&xbb->io_taskqueue);
+	xbb->io_taskqueue = taskqueue_create_fast(device_get_nameunit(dev),
+						  M_NOWAIT,
+						  taskqueue_thread_enqueue,
+						  /*contxt*/&xbb->io_taskqueue);
 	if (xbb->io_taskqueue == NULL) {
 		xbb_attach_failed(xbb, error, "Unable to create taskqueue");
 		return (ENOMEM);

Modified: head/sys/dev/xen/blkfront/blkfront.c
==============================================================================
--- head/sys/dev/xen/blkfront/blkfront.c	Thu Aug 29 19:47:52 2013	(r255039)
+++ head/sys/dev/xen/blkfront/blkfront.c	Thu Aug 29 19:52:18 2013	(r255040)
@@ -51,19 +51,17 @@ __FBSDID("$FreeBSD$");
 #include <machine/vmparam.h>
 #include <sys/bus_dma.h>
 
-#include <machine/_inttypes.h>
-#include <machine/xen/xen-os.h>
-#include <machine/xen/xenvar.h>
-#include <machine/xen/xenfunc.h>
-
+#include <xen/xen-os.h>
 #include <xen/hypervisor.h>
 #include <xen/xen_intr.h>
-#include <xen/evtchn.h>
 #include <xen/gnttab.h>
 #include <xen/interface/grant_table.h>
 #include <xen/interface/io/protocols.h>
 #include <xen/xenbus/xenbusvar.h>
 
+#include <machine/_inttypes.h>
+#include <machine/xen/xenvar.h>
+
 #include <geom/geom_disk.h>
 
 #include <dev/xen/blkfront/block.h>
@@ -139,7 +137,7 @@ xbd_flush_requests(struct xbd_softc *sc)
 	RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&sc->xbd_ring, notify);
 
 	if (notify)
-		notify_remote_via_irq(sc->xbd_irq);
+		xen_intr_signal(sc->xen_intr_handle);
 }
 
 static void
@@ -310,7 +308,7 @@ xbd_bio_command(struct xbd_softc *sc)
 	struct xbd_command *cm;
 	struct bio *bp;
 
-	if (unlikely(sc->xbd_state != XBD_STATE_CONNECTED))
+	if (__predict_false(sc->xbd_state != XBD_STATE_CONNECTED))
 		return (NULL);
 
 	bp = xbd_dequeue_bio(sc);
@@ -437,7 +435,7 @@ xbd_bio_complete(struct xbd_softc *sc, s
 
 	bp = cm->cm_bp;
 
-	if (unlikely(cm->cm_status != BLKIF_RSP_OKAY)) {
+	if (__predict_false(cm->cm_status != BLKIF_RSP_OKAY)) {
 		disk_err(bp, "disk error" , -1, 0);
 		printf(" status: %x\n", cm->cm_status);
 		bp->bio_flags |= BIO_ERROR;
@@ -470,7 +468,7 @@ xbd_int(void *xsc)
 
 	mtx_lock(&sc->xbd_io_lock);
 
-	if (unlikely(sc->xbd_state == XBD_STATE_DISCONNECTED)) {
+	if (__predict_false(sc->xbd_state == XBD_STATE_DISCONNECTED)) {
 		mtx_unlock(&sc->xbd_io_lock);
 		return;
 	}
@@ -531,7 +529,7 @@ xbd_int(void *xsc)
 
 	xbd_startio(sc);
 
-	if (unlikely(sc->xbd_state == XBD_STATE_SUSPENDED))
+	if (__predict_false(sc->xbd_state == XBD_STATE_SUSPENDED))
 		wakeup(&sc->xbd_cm_q[XBD_Q_BUSY]);
 
 	mtx_unlock(&sc->xbd_io_lock);
@@ -782,13 +780,12 @@ xbd_alloc_ring(struct xbd_softc *sc)
 		}
 	}
 
-	error = bind_listening_port_to_irqhandler(
-	    xenbus_get_otherend_id(sc->xbd_dev),
-	    "xbd", (driver_intr_t *)xbd_int, sc,
-	    INTR_TYPE_BIO | INTR_MPSAFE, &sc->xbd_irq);
+	error = xen_intr_alloc_and_bind_local_port(sc->xbd_dev,
+	    xenbus_get_otherend_id(sc->xbd_dev), NULL, xbd_int, sc,
+	    INTR_TYPE_BIO | INTR_MPSAFE, &sc->xen_intr_handle);
 	if (error) {
 		xenbus_dev_fatal(sc->xbd_dev, error,
-		    "bind_evtchn_to_irqhandler failed");
+		    "xen_intr_alloc_and_bind_local_port failed");
 		return (error);
 	}
 
@@ -1042,10 +1039,8 @@ xbd_free(struct xbd_softc *sc)
 		xbd_initq_cm(sc, XBD_Q_COMPLETE);
 	}
 		
-	if (sc->xbd_irq) {
-		unbind_from_irqhandler(sc->xbd_irq);
-		sc->xbd_irq = 0;
-	}
+	xen_intr_unbind(&sc->xen_intr_handle);
+
 }
 
 /*--------------------------- State Change Handlers --------------------------*/
@@ -1277,7 +1272,7 @@ xbd_initialize(struct xbd_softc *sc)
 	}
 
 	error = xs_printf(XST_NIL, node_path, "event-channel",
-	    "%u", irq_to_evtchn_port(sc->xbd_irq));
+	    "%u", xen_intr_port(sc->xen_intr_handle));
 	if (error) {
 		xenbus_dev_fatal(sc->xbd_dev, error,
 		    "writing %s/event-channel",

Modified: head/sys/dev/xen/blkfront/block.h
==============================================================================
--- head/sys/dev/xen/blkfront/block.h	Thu Aug 29 19:47:52 2013	(r255039)
+++ head/sys/dev/xen/blkfront/block.h	Thu Aug 29 19:52:18 2013	(r255040)
@@ -179,7 +179,7 @@ struct xbd_softc {
 	uint32_t			 xbd_max_request_size;
 	grant_ref_t			 xbd_ring_ref[XBD_MAX_RING_PAGES];
 	blkif_front_ring_t		 xbd_ring;
-	unsigned int			 xbd_irq;
+	xen_intr_handle_t		 xen_intr_handle;
 	struct gnttab_free_callback	 xbd_callback;
 	xbd_cm_q_t			 xbd_cm_q[XBD_Q_COUNT];
 	bus_dma_tag_t			 xbd_io_dmat;

Modified: head/sys/dev/xen/console/console.c
==============================================================================
--- head/sys/dev/xen/console/console.c	Thu Aug 29 19:47:52 2013	(r255039)
+++ head/sys/dev/xen/console/console.c	Thu Aug 29 19:52:18 2013	(r255040)
@@ -15,7 +15,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/kernel.h>
 #include <sys/bus.h>
 #include <machine/stdarg.h>
-#include <machine/xen/xen-os.h>
+#include <xen/xen-os.h>
 #include <xen/hypervisor.h>
 #include <xen/xen_intr.h>
 #include <sys/cons.h>
@@ -71,6 +71,8 @@ static char rbuf[RBUF_SIZE];
 static int rc, rp;
 static unsigned int cnsl_evt_reg;
 static unsigned int wc, wp; /* write_cons, write_prod */
+xen_intr_handle_t xen_intr_handle;
+device_t xencons_dev;
 
 #ifdef KDB
 static int	xc_altbrk;
@@ -232,6 +234,7 @@ xc_attach(device_t dev) 
 {
 	int error;
 
+	xencons_dev = dev;
 	xccons = tty_alloc(&xc_ttydevsw, NULL);
 	tty_makedev(xccons, NULL, "xc%r", 0);
 
@@ -243,15 +246,10 @@ xc_attach(device_t dev) 
 	callout_reset(&xc_callout, XC_POLLTIME, xc_timeout, xccons);
     
 	if (xen_start_info->flags & SIF_INITDOMAIN) {
-			error = bind_virq_to_irqhandler(
-				 VIRQ_CONSOLE,
-				 0,
-				 "console",
-				 NULL,
-				 xencons_priv_interrupt, NULL,
-				 INTR_TYPE_TTY, NULL);
-		
-				KASSERT(error >= 0, ("can't register console interrupt"));
+		error = xen_intr_bind_virq(dev, VIRQ_CONSOLE, 0, NULL,
+		                           xencons_priv_interrupt, NULL,
+		                           INTR_TYPE_TTY, &xen_intr_handle);
+		KASSERT(error >= 0, ("can't register console interrupt"));
 	}
 
 	/* register handler to flush console on shutdown */

Modified: head/sys/dev/xen/console/xencons_ring.c
==============================================================================
--- head/sys/dev/xen/console/xencons_ring.c	Thu Aug 29 19:47:52 2013	(r255039)
+++ head/sys/dev/xen/console/xencons_ring.c	Thu Aug 29 19:52:18 2013	(r255040)
@@ -16,7 +16,8 @@ __FBSDID("$FreeBSD$");
 #include <sys/cons.h>
 
 #include <machine/stdarg.h>
-#include <machine/xen/xen-os.h>
+
+#include <xen/xen-os.h>
 #include <xen/hypervisor.h>
 #include <xen/xen_intr.h>
 #include <sys/cons.h>
@@ -30,9 +31,10 @@ __FBSDID("$FreeBSD$");
 #include <xen/interface/io/console.h>
 
 #define console_evtchn	console.domU.evtchn
-static unsigned int console_irq;
+xen_intr_handle_t console_handle;
 extern char *console_page;
 extern struct mtx              cn_mtx;
+extern device_t xencons_dev;
 
 static inline struct xencons_interface *
 xencons_interface(void)
@@ -74,7 +76,7 @@ xencons_ring_send(const char *data, unsi
 	wmb();
 	intf->out_prod = prod;
 
-	notify_remote_via_evtchn(xen_start_info->console_evtchn);
+	xen_intr_signal(console_handle);
 
 	return sent;
 
@@ -106,7 +108,7 @@ xencons_handle_input(void *unused)
 	intf->in_cons = cons;
 
 	CN_LOCK(cn_mtx);
-	notify_remote_via_evtchn(xen_start_info->console_evtchn);
+	xen_intr_signal(console_handle);
 
 	xencons_tx();
 	CN_UNLOCK(cn_mtx);
@@ -126,9 +128,9 @@ xencons_ring_init(void)
 	if (!xen_start_info->console_evtchn)
 		return 0;
 
-	err = bind_caller_port_to_irqhandler(xen_start_info->console_evtchn,
-		"xencons", xencons_handle_input, NULL,
-		INTR_TYPE_MISC | INTR_MPSAFE, &console_irq);
+	err = xen_intr_bind_local_port(xencons_dev,
+	    xen_start_info->console_evtchn, NULL, xencons_handle_input, NULL,
+	    INTR_TYPE_MISC | INTR_MPSAFE, &console_handle);
 	if (err) {
 		return err;
 	}
@@ -146,7 +148,7 @@ xencons_suspend(void)
 	if (!xen_start_info->console_evtchn)
 		return;
 
-	unbind_from_irqhandler(console_irq);
+	xen_intr_unbind(&console_handle);
 }
 
 void 

Modified: head/sys/dev/xen/control/control.c
==============================================================================
--- head/sys/dev/xen/control/control.c	Thu Aug 29 19:47:52 2013	(r255039)
+++ head/sys/dev/xen/control/control.c	Thu Aug 29 19:52:18 2013	(r255040)
@@ -128,12 +128,13 @@ __FBSDID("$FreeBSD$");
 #include <geom/geom.h>
 
 #include <machine/_inttypes.h>
-#include <machine/xen/xen-os.h>
+#include <machine/intr_machdep.h>
 
 #include <vm/vm.h>
 #include <vm/vm_extern.h>
 #include <vm/vm_kern.h>
 
+#include <xen/xen-os.h>
 #include <xen/blkif.h>
 #include <xen/evtchn.h>
 #include <xen/gnttab.h>
@@ -144,6 +145,9 @@ __FBSDID("$FreeBSD$");
 
 #include <xen/xenbus/xenbusvar.h>
 
+#include <machine/xen/xenvar.h>
+#include <machine/xen/xenfunc.h>
+
 /*--------------------------- Forward Declarations --------------------------*/
 /** Function signature for shutdown event handlers. */
 typedef	void (xctrl_shutdown_handler_t)(void);
@@ -242,6 +246,7 @@ xctrl_suspend()
 
 	xencons_suspend();
 	gnttab_suspend();
+	intr_suspend();
 
 	max_pfn = HYPERVISOR_shared_info->arch.max_pfn;
 
@@ -282,7 +287,7 @@ xctrl_suspend()
 	HYPERVISOR_shared_info->arch.max_pfn = max_pfn;
 
 	gnttab_resume();
-	irq_resume();
+	intr_resume();
 	local_irq_enable();
 	xencons_resume();
 
@@ -352,13 +357,11 @@ xctrl_suspend()
 	 * Prevent any races with evtchn_interrupt() handler.
 	 */
 	disable_intr();
-	irq_suspend();
+	intr_suspend();
 
 	suspend_cancelled = HYPERVISOR_suspend(0);
-	if (suspend_cancelled)
-		irq_resume();
-	else
-		xenpci_resume();
+
+	intr_resume();
 
 	/*
 	 * Re-enable interrupts and put the scheduler back to normal.

Modified: head/sys/dev/xen/netback/netback.c
==============================================================================
--- head/sys/dev/xen/netback/netback.c	Thu Aug 29 19:47:52 2013	(r255039)
+++ head/sys/dev/xen/netback/netback.c	Thu Aug 29 19:52:18 2013	(r255040)
@@ -79,14 +79,15 @@ __FBSDID("$FreeBSD$");
 #include <vm/vm_kern.h>
 
 #include <machine/_inttypes.h>
-#include <machine/xen/xen-os.h>
-#include <machine/xen/xenvar.h>
 
-#include <xen/evtchn.h>
+#include <xen/xen-os.h>
+#include <xen/hypervisor.h>
 #include <xen/xen_intr.h>
 #include <xen/interface/io/netif.h>
 #include <xen/xenbus/xenbusvar.h>
 
+#include <machine/xen/xenvar.h>
+
 /*--------------------------- Compile-time Tunables --------------------------*/
 
 /*---------------------------------- Macros ----------------------------------*/
@@ -433,8 +434,8 @@ struct xnb_softc {
 	/** Xen device handle.*/
 	long 			handle;
 
-	/** IRQ mapping for the communication ring event channel. */
-	int			irq;
+	/** Handle to the communication ring event channel. */
+	xen_intr_handle_t	xen_intr_handle;
 
 	/**
 	 * \brief Cached value of the front-end's domain id.
@@ -647,10 +648,7 @@ xnb_disconnect(struct xnb_softc *xnb)
 	int error;
 	int i;
 
-	if (xnb->irq != 0) {
-		unbind_from_irqhandler(xnb->irq);
-		xnb->irq = 0;
-	}
+	xen_intr_unbind(xnb->xen_intr_handle);
 
 	/*
 	 * We may still have another thread currently processing requests.  We
@@ -773,13 +771,13 @@ xnb_connect_comms(struct xnb_softc *xnb)
 
 	xnb->flags |= XNBF_RING_CONNECTED;
 

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***


More information about the svn-src-head mailing list