From 88705535e167baba0e81ebd56854fcdc008e574a Mon Sep 17 00:00:00 2001
From: Julien Grall <julien.grall@linaro.org>
Date: Fri, 6 Jun 2014 01:21:48 +0100
Subject: [PATCH 1/5] Handle ARM dom0 for xenstore

---
 sys/dev/xen/xenstore/xenstore.c | 54 +++++++++++++++++++++--------------------
 1 file changed, 28 insertions(+), 26 deletions(-)

diff --git a/sys/dev/xen/xenstore/xenstore.c b/sys/dev/xen/xenstore/xenstore.c
index d675739..0a194cf 100644
--- a/sys/dev/xen/xenstore/xenstore.c
+++ b/sys/dev/xen/xenstore/xenstore.c
@@ -1165,40 +1165,42 @@ xs_attach(device_t dev)
 	struct proc *p;
 
 	xs.initialized = false;
+
 	if (xen_hvm_domain()) {
 		xs.evtchn = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN);
 		xs.gpfn = hvm_get_parameter(HVM_PARAM_STORE_PFN);
-		xen_store = xen_pmap(xs.gpfn * PAGE_SIZE, PAGE_SIZE);
-		xs.initialized = true;
+		if (xs.evtchn != 0)
+			xen_store = xen_pmap(xs.gpfn * PAGE_SIZE, PAGE_SIZE);
 	} else if (xen_pv_domain()) {
-		if (HYPERVISOR_start_info->store_evtchn == 0) {
-			struct evtchn_alloc_unbound alloc_unbound;
-
-			/* Allocate a local event channel for xenstore */
-			alloc_unbound.dom = DOMID_SELF;
-			alloc_unbound.remote_dom = DOMID_SELF;
-			error = HYPERVISOR_event_channel_op(
-			    EVTCHNOP_alloc_unbound, &alloc_unbound);
-			if (error != 0)
-				panic(
-				   "unable to alloc event channel for Dom0: %d",
-				    error);
-
-			HYPERVISOR_start_info->store_evtchn =
-			    alloc_unbound.port;
-			xs.evtchn = alloc_unbound.port;
-
-			/* Allocate memory for the xs shared ring */
-			xen_store = malloc(PAGE_SIZE, M_XENSTORE,
-			    M_WAITOK | M_ZERO);
-		} else {
-			xs.evtchn = HYPERVISOR_start_info->store_evtchn;
-			xs.initialized = true;
-		}
+		xs.evtchn = HYPERVISOR_start_info->store_evtchn;
 	} else {
 		panic("Unknown domain type, cannot initialize xenstore.");
 	}
 
+	if (xs.evtchn == 0) {
+		struct evtchn_alloc_unbound alloc_unbound;
+
+		/* Allocate a local event channel for xenstore */
+		alloc_unbound.dom = DOMID_SELF;
+		alloc_unbound.remote_dom = DOMID_SELF;
+		error = HYPERVISOR_event_channel_op(
+		    EVTCHNOP_alloc_unbound, &alloc_unbound);
+		if (error != 0)
+			panic(
+			   "unable to alloc event channel for Dom0: %d",
+			    error);
+
+		HYPERVISOR_start_info->store_evtchn =
+		    alloc_unbound.port;
+		xs.evtchn = alloc_unbound.port;
+
+		/* Allocate memory for the xs shared ring */
+		xen_store = malloc(PAGE_SIZE, M_XENSTORE,
+		    M_WAITOK | M_ZERO);
+	}
+	else
+		xs.initialized = true;
+
 	TAILQ_INIT(&xs.reply_list);
 	TAILQ_INIT(&xs.watch_events);
 
-- 
2.1.0

