From 7df19b6b5dc2baaaa18514d063651044c818672f Mon Sep 17 00:00:00 2001
From: Roger Pau Monne <roger.pau@citrix.com>
Date: Tue, 17 Sep 2013 16:01:28 +0200
Subject: [PATCH] xen: fix UP builds

---
 sys/dev/xen/control/control.c |    6 ++++++
 sys/x86/xen/hvm.c             |   10 ++++++++++
 sys/x86/xen/xen_intr.c        |   16 ++++++++++++++++
 3 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/sys/dev/xen/control/control.c b/sys/dev/xen/control/control.c
index bdbcece..09ca54b 100644
--- a/sys/dev/xen/control/control.c
+++ b/sys/dev/xen/control/control.c
@@ -338,7 +338,9 @@ xen_pv_shutdown_final(void *arg, int howto)
 static void
 xctrl_suspend()
 {
+#ifdef SMP
 	cpuset_t cpu_suspend_map;
+#endif
 	int suspend_cancelled;
 
 	EVENTHANDLER_INVOKE(power_suspend);
@@ -368,6 +370,7 @@ xctrl_suspend()
 	}
 	mtx_unlock(&Giant);
 
+#ifdef SMP
 	if (smp_started) {
 		/*
 		 * Suspend other CPUs. This prevents IPIs while we
@@ -379,6 +382,7 @@ xctrl_suspend()
 		if (!CPU_EMPTY(&cpu_suspend_map))
 			suspend_cpus(cpu_suspend_map);
 	}
+#endif
 
 	/*
 	 * Prevent any races with evtchn_interrupt() handler.
@@ -398,6 +402,7 @@ xctrl_suspend()
 	 */
 	gnttab_resume();
 
+#ifdef SMP
 	if (smp_started && !CPU_EMPTY(&cpu_suspend_map)) {
 		/*
 		 * Now that event channels have been initialized,
@@ -405,6 +410,7 @@ xctrl_suspend()
 		 */
 		resume_cpus(cpu_suspend_map);
 	}
+#endif
 
 	/*
 	 * FreeBSD really needs to add DEVICE_SUSPEND_CANCEL or
diff --git a/sys/x86/xen/hvm.c b/sys/x86/xen/hvm.c
index 4b47d39..ebdc591 100644
--- a/sys/x86/xen/hvm.c
+++ b/sys/x86/xen/hvm.c
@@ -58,6 +58,7 @@ __FBSDID("$FreeBSD$");
 #include <xen/interface/vcpu.h>
 
 /*--------------------------- Forward Declarations ---------------------------*/
+#ifdef SMP
 static driver_filter_t xen_smp_rendezvous_action;
 static driver_filter_t xen_invltlb;
 static driver_filter_t xen_invlpg;
@@ -70,6 +71,7 @@ static driver_filter_t xen_ipi_bitmap_handler;
 static driver_filter_t xen_cpustop_handler;
 static driver_filter_t xen_cpususpend_handler;
 static driver_filter_t xen_cpustophard_handler;
+#endif
 
 /*---------------------------- Extern Declarations ---------------------------*/
 /* Variables used by mp_machdep to perform the MMU related IPIs */
@@ -110,6 +112,7 @@ enum xen_domain_type xen_domain_type = XEN_NATIVE;
 
 static MALLOC_DEFINE(M_XENHVM, "xen_hvm", "Xen HVM PV Support");
 
+#ifdef SMP
 static struct xen_ipi_handler xen_ipis[] = 
 {
 	[IPI_TO_IDX(IPI_RENDEZVOUS)]	= { xen_smp_rendezvous_action,	"r"   },
@@ -125,6 +128,7 @@ static struct xen_ipi_handler xen_ipis[] =
 	[IPI_TO_IDX(IPI_SUSPEND)]	= { xen_cpususpend_handler,	"sp"  },
 	[IPI_TO_IDX(IPI_STOP_HARD)]	= { xen_cpustophard_handler,	"sth" },
 };
+#endif
 
 /**
  * If non-zero, the hypervisor has been configured to use a direct
@@ -135,13 +139,16 @@ int xen_vector_callback_enabled;
 /*------------------------------- Per-CPU Data -------------------------------*/
 DPCPU_DEFINE(struct vcpu_info, vcpu_local_info);
 DPCPU_DEFINE(struct vcpu_info *, vcpu_info);
+#ifdef SMP
 DPCPU_DEFINE(xen_intr_handle_t, ipi_handle[nitems(xen_ipis)]);
+#endif
 
 /*------------------ Hypervisor Access Shared Memory Regions -----------------*/
 /** Hypercall table accessed via HYPERVISOR_*_op() methods. */
 char *hypercall_stubs;
 shared_info_t *HYPERVISOR_shared_info;
 
+#ifdef SMP
 /*---------------------------- XEN PV IPI Handlers ---------------------------*/
 /*
  * This are C clones of the ASM functions found in apic_vector.s
@@ -502,6 +509,7 @@ xen_init_ipis(void)
 	/* Set the xen pv ipi ops to replace the native ones */
 	cpu_ops.ipi_vectored = xen_ipi_vectored;
 }
+#endif
 
 /*---------------------- XEN Hypervisor Probe and Setup ----------------------*/
 static uint32_t
@@ -734,5 +742,7 @@ xen_hvm_init_cpu(void)
 }
 
 SYSINIT(xen_hvm_init, SI_SUB_HYPERVISOR, SI_ORDER_FIRST, xen_hvm_sysinit, NULL);
+#ifdef SMP
 SYSINIT(xen_init_ipis, SI_SUB_SMP, SI_ORDER_FIRST, xen_init_ipis, NULL);
+#endif
 SYSINIT(xen_hvm_init_cpu, SI_SUB_INTR, SI_ORDER_FIRST, xen_hvm_init_cpu, NULL);
diff --git a/sys/x86/xen/xen_intr.c b/sys/x86/xen/xen_intr.c
index 0c87411..4f62cce 100644
--- a/sys/x86/xen/xen_intr.c
+++ b/sys/x86/xen/xen_intr.c
@@ -609,6 +609,7 @@ xen_intr_suspend(struct pic *unused)
 static void
 xen_rebind_ipi(struct xenisrc *isrc)
 {
+#ifdef SMP
 	int cpu = isrc->xi_cpu;
 	int acpi_id = pcpu_find(cpu)->pc_acpi_id;
 	int error;
@@ -630,6 +631,9 @@ xen_rebind_ipi(struct xenisrc *isrc)
 		      cpu, error);
 
 	evtchn_unmask_port(bind_ipi.port);
+#else
+	panic("Resume IPI event channel on UP");
+#endif
 }
 
 static void
@@ -650,11 +654,13 @@ xen_rebind_virq(struct xenisrc *isrc)
 	isrc->xi_cpu = 0;
 	xen_intr_port_to_isrc[bind_virq.port] = isrc;
 
+#ifdef SMP
 	error = xen_intr_assign_cpu(&isrc->xi_intsrc,
 	                            cpu_apic_ids[cpu]);
 	if (error)
 		panic("unable to bind xen VIRQ#%d to CPU#%d: %d",
 		      isrc->xi_virq, cpu, error);
+#endif
 
 	evtchn_unmask_port(bind_virq.port);
 }
@@ -787,6 +793,7 @@ xen_intr_config_intr(struct intsrc *isrc, enum intr_trigger trig,
 static int
 xen_intr_assign_cpu(struct intsrc *base_isrc, u_int apic_id)
 {
+#ifdef SMP
 	struct evtchn_bind_vcpu bind_vcpu;
 	struct xenisrc *isrc;
 	u_int to_cpu, acpi_id;
@@ -843,6 +850,9 @@ xen_intr_assign_cpu(struct intsrc *base_isrc, u_int apic_id)
 	}
 	mtx_unlock(&xen_intr_isrc_lock);
 	return (0);
+#else
+	return (EOPNOTSUPP);
+#endif
 }
 
 /*------------------- Virtual Interrupt Source PIC Functions -----------------*/
@@ -1085,6 +1095,7 @@ xen_intr_bind_virq(device_t dev, u_int virq, u_int cpu,
 		return (error);
 	}
 
+#ifdef SMP
 	if (isrc->xi_cpu != cpu) {
 		/*
 		 * Too early in the boot process for the generic interrupt
@@ -1094,6 +1105,7 @@ xen_intr_bind_virq(device_t dev, u_int virq, u_int cpu,
 		 */
 		xen_intr_assign_cpu(&isrc->xi_intsrc, cpu_apic_ids[cpu]);
 	}
+#endif
 
 	/*
 	 * The Event Channel API opened this port, so it is
@@ -1110,6 +1122,7 @@ xen_intr_alloc_and_bind_ipi(device_t dev, u_int cpu,
     driver_filter_t filter, enum intr_type flags,
     xen_intr_handle_t *port_handlep)
 {
+#ifdef SMP
 	int acpi_id = pcpu_find(cpu)->pc_acpi_id;
 	struct xenisrc *isrc;
 	struct evtchn_bind_ipi bind_ipi = { .vcpu = acpi_id };
@@ -1159,6 +1172,9 @@ xen_intr_alloc_and_bind_ipi(device_t dev, u_int cpu,
 	 */
 	isrc->xi_close = 1;
 	return (0);
+#else
+	return (EOPNOTSUPP);
+#endif
 }
 
 int
-- 
1.7.7.5 (Apple Git-26)

