Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Dec 2008 06:31:03 +0000 (UTC)
From:      Kip Macy <kmacy@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r186557 - in head/sys: dev/xen/blkfront dev/xen/console dev/xen/evtchn dev/xen/netfront i386/conf i386/i386 i386/include/xen i386/isa i386/xen xen xen/evtchn xen/xenbus
Message-ID:  <200812290631.mBT6V3KJ047176@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kmacy
Date: Mon Dec 29 06:31:03 2008
New Revision: 186557
URL: http://svn.freebsd.org/changeset/base/186557

Log:
  merge 186535, 186537, and 186538 from releng_7_xen
  
  Log:
   - merge in latest xenbus from dfr's xenhvm
   - fix race condition in xs_read_reply by converting tsleep to mtx_sleep
  
  Log:
   unmask evtchn in bind_{virq, ipi}_to_irq
  
  Log:
   - remove code for handling case of not being able to sleep
   - eliminate tsleep - make sleeps atomic

Added:
  head/sys/xen/evtchn.h   (contents, props changed)
  head/sys/xen/hypervisor.h   (contents, props changed)
  head/sys/xen/xen_intr.h   (contents, props changed)
Deleted:
  head/sys/i386/include/xen/evtchn.h
  head/sys/i386/include/xen/hypervisor.h
  head/sys/i386/include/xen/xen_intr.h
Modified:
  head/sys/dev/xen/blkfront/blkfront.c
  head/sys/dev/xen/console/console.c
  head/sys/dev/xen/console/xencons_ring.c
  head/sys/dev/xen/evtchn/evtchn_dev.c
  head/sys/dev/xen/netfront/netfront.c
  head/sys/i386/conf/XEN
  head/sys/i386/i386/genassym.c
  head/sys/i386/i386/machdep.c
  head/sys/i386/i386/vm_machdep.c
  head/sys/i386/include/xen/xenfunc.h
  head/sys/i386/isa/npx.c
  head/sys/i386/xen/clock.c
  head/sys/i386/xen/mp_machdep.c
  head/sys/i386/xen/mptable.c
  head/sys/i386/xen/pmap.c
  head/sys/i386/xen/xen_machdep.c
  head/sys/xen/evtchn/evtchn.c
  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/xenbus/xenbus_client.c
  head/sys/xen/xenbus/xenbus_comms.c
  head/sys/xen/xenbus/xenbus_comms.h
  head/sys/xen/xenbus/xenbus_dev.c
  head/sys/xen/xenbus/xenbus_probe.c
  head/sys/xen/xenbus/xenbus_probe_backend.c
  head/sys/xen/xenbus/xenbus_xs.c
  head/sys/xen/xenbus/xenbusvar.h

Modified: head/sys/dev/xen/blkfront/blkfront.c
==============================================================================
--- head/sys/dev/xen/blkfront/blkfront.c	Mon Dec 29 04:40:52 2008	(r186556)
+++ head/sys/dev/xen/blkfront/blkfront.c	Mon Dec 29 06:31:03 2008	(r186557)
@@ -40,10 +40,10 @@ __FBSDID("$FreeBSD$");
 #include <machine/intr_machdep.h>
 #include <machine/vmparam.h>
 
-#include <machine/xen/hypervisor.h>
+#include <xen/hypervisor.h>
 #include <machine/xen/xen-os.h>
-#include <machine/xen/xen_intr.h>
-#include <machine/xen/evtchn.h>
+#include <xen/xen_intr.h>
+#include <xen/evtchn.h>
 #include <xen/interface/grant_table.h>
 #include <xen/interface/io/protocols.h>
 #include <xen/xenbus/xenbusvar.h>
@@ -214,7 +214,7 @@ xlvbd_add(device_t dev, blkif_sector_t c
 	struct xb_softc	*sc;
 	int	unit, error = 0;
 	const char *name;
-	
+
 	blkfront_vdevice_to_unit(vdevice, &unit, &name);
 
 	sc = (struct xb_softc *)malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO);
@@ -227,12 +227,12 @@ xlvbd_add(device_t dev, blkif_sector_t c
 
 	memset(&sc->xb_disk, 0, sizeof(sc->xb_disk)); 
 	sc->xb_disk = disk_alloc();
-	sc->xb_disk->d_unit = unit;
+	sc->xb_disk->d_unit = sc->xb_unit;
 	sc->xb_disk->d_open = blkif_open;
 	sc->xb_disk->d_close = blkif_close;
 	sc->xb_disk->d_ioctl = blkif_ioctl;
 	sc->xb_disk->d_strategy = xb_strategy;
-	sc->xb_disk->d_name = "xbd";
+	sc->xb_disk->d_name = name;
 	sc->xb_disk->d_drv1 = sc;
 	sc->xb_disk->d_sectorsize = sector_size;
 
@@ -329,8 +329,8 @@ blkfront_attach(device_t dev)
 
 	/* FIXME: Use dynamic device id if this is not set. */
 	err = xenbus_scanf(XBT_NIL, xenbus_get_node(dev),
-			   "virtual-device", "%i", &vdevice);
-	if (err != 1) {
+	    "virtual-device", NULL, "%i", &vdevice);
+	if (err) {
 		xenbus_dev_fatal(dev, err, "reading virtual-device");
 		printf("couldn't find virtual device");
 		return (err);
@@ -363,9 +363,8 @@ blkfront_attach(device_t dev)
 	info->handle = strtoul(strrchr(xenbus_get_node(dev),'/')+1, NULL, 0);
 
 	err = talk_to_backend(dev, info);
-	if (err) {
-		return err;
-	}
+	if (err)
+		return (err);
 
 	return (0);
 }
@@ -381,7 +380,8 @@ blkfront_resume(device_t dev)
 	blkif_free(info, 1);
 
 	err = talk_to_backend(dev, info);
-	if (!err)
+
+	if (info->connected == BLKIF_STATE_SUSPENDED && !err)
 		blkif_recover(info);
 
 	return err;
@@ -427,7 +427,7 @@ talk_to_backend(device_t dev, struct blk
 	}
 	err = xenbus_transaction_end(xbt, 0);
 	if (err) {
-		if (err == -EAGAIN)
+		if (err == EAGAIN)
 			goto again;
 		xenbus_dev_fatal(dev, err, "completing transaction");
 		goto destroy_blkring;
@@ -450,7 +450,7 @@ static int 
 setup_blkring(device_t dev, struct blkfront_info *info)
 {
 	blkif_sring_t *sring;
-	int err;
+	int error;
 
 	info->ring_ref = GRANT_INVALID_REF;
 
@@ -462,28 +462,27 @@ setup_blkring(device_t dev, struct blkfr
 	SHARED_RING_INIT(sring);
 	FRONT_RING_INIT(&info->ring, sring, PAGE_SIZE);
 
-	err = xenbus_grant_ring(dev, (vtomach(info->ring.sring) >> PAGE_SHIFT));
-	if (err < 0) {
+	error = xenbus_grant_ring(dev, (vtomach(info->ring.sring) >> PAGE_SHIFT),
+		&info->ring_ref);
+	if (error) {
 		free(sring, M_DEVBUF);
 		info->ring.sring = NULL;
 		goto fail;
 	}
-	info->ring_ref = err;
 	
-	err = bind_listening_port_to_irqhandler(xenbus_get_otherend_id(dev),
+	error = bind_listening_port_to_irqhandler(xenbus_get_otherend_id(dev),
 		"xbd", (driver_intr_t *)blkif_int, info,
-					INTR_TYPE_BIO | INTR_MPSAFE, NULL);
-	if (err <= 0) {
-		xenbus_dev_fatal(dev, err,
+					INTR_TYPE_BIO | INTR_MPSAFE, &info->irq);
+	if (error) {
+		xenbus_dev_fatal(dev, error,
 				 "bind_evtchn_to_irqhandler failed");
 		goto fail;
 	}
-	info->irq = err;
 
-	return 0;
+	return (0);
  fail:
 	blkif_free(info, 0);
-	return err;
+	return (error);
 }
 
 
@@ -999,7 +998,7 @@ blkif_free(struct blkfront_info *info, i
 		info->ring.sring = NULL;
 	}
 	if (info->irq)
-		unbind_from_irqhandler(info->irq, info); 
+		unbind_from_irqhandler(info->irq);
 	info->irq = 0;
 
 }

Modified: head/sys/dev/xen/console/console.c
==============================================================================
--- head/sys/dev/xen/console/console.c	Mon Dec 29 04:40:52 2008	(r186556)
+++ head/sys/dev/xen/console/console.c	Mon Dec 29 06:31:03 2008	(r186557)
@@ -15,8 +15,8 @@ __FBSDID("$FreeBSD$");
 #include <sys/bus.h>
 #include <machine/stdarg.h>
 #include <machine/xen/xen-os.h>
-#include <machine/xen/hypervisor.h>
-#include <machine/xen/xen_intr.h>
+#include <xen/hypervisor.h>
+#include <xen/xen_intr.h>
 #include <sys/cons.h>
 #include <sys/priv.h>
 #include <sys/proc.h>
@@ -75,17 +75,17 @@ static unsigned int wc, wp; /* write_con
 #define	XCUNIT(x)	(dev2unit(x))
 #define ISTTYOPEN(tp)	((tp) && ((tp)->t_state & TS_ISOPEN))
 #define CN_LOCK_INIT(x, _name) \
-        mtx_init(&x, _name, NULL, MTX_SPIN|MTX_RECURSE)
+        mtx_init(&x, _name, NULL, MTX_DEF|MTX_RECURSE)
 
 #define CN_LOCK(l)        								\
 		do {											\
 				if (panicstr == NULL)					\
-                        mtx_lock_spin(&(l));			\
+                        mtx_lock(&(l));			\
 		} while (0)
 #define CN_UNLOCK(l)        							\
 		do {											\
 				if (panicstr == NULL)					\
-                        mtx_unlock_spin(&(l));			\
+                        mtx_unlock(&(l));			\
 		} while (0)
 #define CN_LOCK_ASSERT(x)    mtx_assert(&x, MA_OWNED)
 #define CN_LOCK_DESTROY(x)   mtx_destroy(&x)
@@ -216,6 +216,8 @@ xc_probe(device_t dev)
 static int
 xc_attach(device_t dev) 
 {
+	int error;
+	struct xc_softc *sc = (struct xc_softc *)device_get_softc(dev);
 
 	if (xen_start_info->flags & SIF_INITDOMAIN) {
 		xc_consdev.cn_putc = xccnputc_dom0;
@@ -232,14 +234,15 @@ xc_attach(device_t dev) 
 	callout_reset(&xc_callout, XC_POLLTIME, xc_timeout, xccons);
     
 	if (xen_start_info->flags & SIF_INITDOMAIN) {
-		PANIC_IF(bind_virq_to_irqhandler(
-				 VIRQ_CONSOLE,
-				 0,
-				 "console",
-				 NULL,
-				 xencons_priv_interrupt,
-				 INTR_TYPE_TTY) < 0);
+			error = bind_virq_to_irqhandler(
+					VIRQ_CONSOLE,
+						0,
+						"console",
+						NULL,
+						xencons_priv_interrupt,
+						sc, INTR_TYPE_TTY, NULL);
 		
+				KASSERT(error >= 0, ("can't register console interrupt"));
 	}
 
 

Modified: head/sys/dev/xen/console/xencons_ring.c
==============================================================================
--- head/sys/dev/xen/console/xencons_ring.c	Mon Dec 29 04:40:52 2008	(r186556)
+++ head/sys/dev/xen/console/xencons_ring.c	Mon Dec 29 06:31:03 2008	(r186557)
@@ -15,19 +15,20 @@ __FBSDID("$FreeBSD$");
 #include <sys/bus.h>
 #include <machine/stdarg.h>
 #include <machine/xen/xen-os.h>
-#include <machine/xen/hypervisor.h>
-#include <machine/xen/xen_intr.h>
+#include <xen/hypervisor.h>
+#include <xen/xen_intr.h>
 #include <sys/cons.h>
 
 
 #include <dev/xen/console/xencons_ring.h>
-#include <machine/xen/evtchn.h>
+#include <xen/evtchn.h>
 #include <xen/interface/io/console.h>
 
 
 #define console_evtchn	console.domU.evtchn
 extern char *console_page;
- 
+extern struct mtx              cn_mtx;
+
 static inline struct xencons_interface *
 xencons_interface(void)
 {
@@ -82,6 +83,7 @@ xencons_handle_input(void *unused)
 	struct xencons_interface *intf;
 	XENCONS_RING_IDX cons, prod;
 
+	mtx_lock(&cn_mtx);
 	intf = xencons_interface();
 
 	cons = intf->in_cons;
@@ -99,6 +101,7 @@ xencons_handle_input(void *unused)
 	notify_remote_via_evtchn(xen_start_info->console_evtchn);
 
 	xencons_tx();
+	mtx_unlock(&cn_mtx);
 }
 
 void 

Modified: head/sys/dev/xen/evtchn/evtchn_dev.c
==============================================================================
--- head/sys/dev/xen/evtchn/evtchn_dev.c	Mon Dec 29 04:40:52 2008	(r186556)
+++ head/sys/dev/xen/evtchn/evtchn_dev.c	Mon Dec 29 06:31:03 2008	(r186557)
@@ -26,13 +26,13 @@ __FBSDID("$FreeBSD$");
 #include <machine/cpufunc.h>
 #include <machine/intr_machdep.h>
 #include <machine/xen-os.h>
-#include <machine/xen_intr.h>
+#include <xen/xen_intr.h>
 #include <machine/bus.h>
 #include <sys/rman.h>
 #include <machine/resource.h>
 #include <machine/synch_bitops.h>
 
-#include <machine/hypervisor.h>
+#include <xen/hypervisor.h>
 
 
 typedef struct evtchn_sotfc {

Modified: head/sys/dev/xen/netfront/netfront.c
==============================================================================
--- head/sys/dev/xen/netfront/netfront.c	Mon Dec 29 04:40:52 2008	(r186556)
+++ head/sys/dev/xen/netfront/netfront.c	Mon Dec 29 06:31:03 2008	(r186557)
@@ -62,9 +62,9 @@ __FBSDID("$FreeBSD$");
 #include <machine/intr_machdep.h>
 
 #include <machine/xen/xen-os.h>
-#include <machine/xen/hypervisor.h>
-#include <machine/xen/xen_intr.h>
-#include <machine/xen/evtchn.h>
+#include <xen/hypervisor.h>
+#include <xen/xen_intr.h>
+#include <xen/evtchn.h>
 #include <xen/gnttab.h>
 #include <xen/interface/memory.h>
 #include <dev/xen/netfront/mbufq.h>
@@ -363,24 +363,25 @@ makembuf (struct mbuf *buf)
 static int 
 xen_net_read_mac(device_t dev, uint8_t mac[])
 {
-	char *s;
-	int i;
-	char *e;
-	char *macstr = xenbus_read(XBT_NIL, xenbus_get_node(dev), "mac", NULL);
-	if (IS_ERR(macstr)) {
-		return PTR_ERR(macstr);
-	}
+	int error, i;
+	char *s, *e, *macstr;
+
+	error = xenbus_read(XBT_NIL, xenbus_get_node(dev), "mac", NULL,
+	    (void **) &macstr);
+	if (error)
+		return (error);
+
 	s = macstr;
 	for (i = 0; i < ETHER_ADDR_LEN; i++) {
 		mac[i] = strtoul(s, &e, 16);
 		if (s == e || (e[0] != ':' && e[0] != 0)) {
 			free(macstr, M_DEVBUF);
-			return ENOENT;
+			return (ENOENT);
 		}
 		s = &e[1];
 	}
 	free(macstr, M_DEVBUF);
-	return 0;
+	return (0);
 }
 
 /**
@@ -422,13 +423,11 @@ netfront_attach(device_t dev)
  * leave the device-layer structures intact so that this is transparent to the
  * rest of the kernel.
  */
-static int 
+static int
 netfront_resume(device_t dev)
 {
 	struct netfront_info *info = device_get_softc(dev);
-	
-	DPRINTK("%s\n", xenbus_get_node(dev));
-	
+
 	netif_disconnect_backend(info);
 	return (0);
 }
@@ -532,7 +531,7 @@ setup_device(device_t dev, struct netfro
 {
 	netif_tx_sring_t *txs;
 	netif_rx_sring_t *rxs;
-	int err;
+	int error;
 	struct ifnet *ifp;
 	
 	ifp = info->xn_ifp;
@@ -545,51 +544,45 @@ setup_device(device_t dev, struct netfro
 
 	txs = (netif_tx_sring_t *)malloc(PAGE_SIZE, M_DEVBUF, M_NOWAIT|M_ZERO);
 	if (!txs) {
-		err = ENOMEM;
-		xenbus_dev_fatal(dev, err, "allocating tx ring page");
+		error = ENOMEM;
+		xenbus_dev_fatal(dev, error, "allocating tx ring page");
 		goto fail;
 	}
 	SHARED_RING_INIT(txs);
 	FRONT_RING_INIT(&info->tx, txs, PAGE_SIZE);
-	err = xenbus_grant_ring(dev, virt_to_mfn(txs));
-	if (err < 0)
+	error = xenbus_grant_ring(dev, virt_to_mfn(txs), &info->tx_ring_ref);
+	if (error)
 		goto fail;
-	info->tx_ring_ref = err;
 
 	rxs = (netif_rx_sring_t *)malloc(PAGE_SIZE, M_DEVBUF, M_NOWAIT|M_ZERO);
 	if (!rxs) {
-		err = ENOMEM;
-		xenbus_dev_fatal(dev, err, "allocating rx ring page");
+		error = ENOMEM;
+		xenbus_dev_fatal(dev, error, "allocating rx ring page");
 		goto fail;
 	}
 	SHARED_RING_INIT(rxs);
 	FRONT_RING_INIT(&info->rx, rxs, PAGE_SIZE);
 
-	err = xenbus_grant_ring(dev, virt_to_mfn(rxs));
-	if (err < 0)
+	error = xenbus_grant_ring(dev, virt_to_mfn(rxs), &info->rx_ring_ref);
+	if (error)
 		goto fail;
-	info->rx_ring_ref = err;
 
-#if 0	
-	network_connect(info);
-#endif
-	err = bind_listening_port_to_irqhandler(xenbus_get_otherend_id(dev),
-		"xn", xn_intr, info, INTR_TYPE_NET | INTR_MPSAFE, NULL);
+	error = bind_listening_port_to_irqhandler(xenbus_get_otherend_id(dev),
+	         "xn", xn_intr, info, INTR_TYPE_NET | INTR_MPSAFE, &info->irq);
 
-	if (err <= 0) {
-		xenbus_dev_fatal(dev, err,
+	if (error) {
+		xenbus_dev_fatal(dev, error,
 				 "bind_evtchn_to_irqhandler failed");
 		goto fail;
 	}
-	info->irq = err;
-	
+
 	show_device(info);
 	
-	return 0;
+	return (0);
 	
  fail:
 	netif_free(info);
-	return err;
+	return (error);
 }
 
 /**
@@ -1225,7 +1218,7 @@ xennet_get_responses(struct netfront_inf
 				MULTI_update_va_mapping(mcl, (u_long)vaddr,
 				    (((vm_paddr_t)mfn) << PAGE_SHIFT) | PG_RW |
 				    PG_V | PG_M | PG_A, 0);
-				pfn = (uint32_t)m->m_ext.ext_arg1;
+				pfn = (uintptr_t)m->m_ext.ext_arg1;
 				mmu->ptr = ((vm_paddr_t)mfn << PAGE_SHIFT) |
 				    MMU_MACHPHYS_UPDATE;
 				mmu->val = pfn;
@@ -1557,18 +1550,18 @@ xn_stop(struct netfront_info *sc)
 int
 network_connect(struct netfront_info *np)
 {
-	int i, requeue_idx, err;
+	int i, requeue_idx, error;
 	grant_ref_t ref;
 	netif_rx_request_t *req;
 	u_int feature_rx_copy, feature_rx_flip;
 
-	err = xenbus_scanf(XBT_NIL, xenbus_get_otherend_path(np->xbdev),
-			   "feature-rx-copy", "%u", &feature_rx_copy);
-	if (err != 1)
+	error = xenbus_scanf(XBT_NIL, xenbus_get_otherend_path(np->xbdev),
+	    "feature-rx-copy", NULL, "%u", &feature_rx_copy);
+	if (error)
 		feature_rx_copy = 0;
-	err = xenbus_scanf(XBT_NIL, xenbus_get_otherend_path(np->xbdev),
-			   "feature-rx-flip", "%u", &feature_rx_flip);
-	if (err != 1)
+	error = xenbus_scanf(XBT_NIL, xenbus_get_otherend_path(np->xbdev),
+	    "feature-rx-flip", NULL, "%u", &feature_rx_flip);
+	if (error)
 		feature_rx_flip = 1;
 
 	/*
@@ -1581,9 +1574,9 @@ network_connect(struct netfront_info *np
 
 	XN_LOCK(np);
 	/* Recovery procedure: */
-	err = talk_to_backend(np->xbdev, np);
-	if (err) 
-		return (err);
+	error = talk_to_backend(np->xbdev, np);
+	if (error) 
+		return (error);
 	
 	/* Step 1: Reinitialise variables. */
 	netif_release_tx_bufs(np);
@@ -1591,6 +1584,7 @@ network_connect(struct netfront_info *np
 	/* Step 2: Rebuild the RX buffer freelist and the RX ring itself. */
 	for (requeue_idx = 0, i = 0; i < NET_RX_RING_SIZE; i++) {
 		struct mbuf *m;
+		u_long pfn;
 
 		if (np->rx_mbufs[i] == NULL)
 			continue;
@@ -1598,15 +1592,16 @@ network_connect(struct netfront_info *np
 		m = np->rx_mbufs[requeue_idx] = xennet_get_rx_mbuf(np, i);
 		ref = np->grant_rx_ref[requeue_idx] = xennet_get_rx_ref(np, i);
 		req = RING_GET_REQUEST(&np->rx, requeue_idx);
+		pfn = vtophys(mtod(m, vm_offset_t)) >> PAGE_SHIFT;
 
 		if (!np->copying_receiver) {
 			gnttab_grant_foreign_transfer_ref(ref,
 			    xenbus_get_otherend_id(np->xbdev),
-			    vtophys(mtod(m, vm_offset_t)));
+			    pfn);
 		} else {
 			gnttab_grant_foreign_access_ref(ref,
 			    xenbus_get_otherend_id(np->xbdev),
-			    vtophys(mtod(m, vm_offset_t)), 0);
+			    PFNTOMFN(pfn), 0);
 		}
 		req->gref = ref;
 		req->id   = requeue_idx;
@@ -1707,7 +1702,7 @@ create_netdev(device_t dev)
 	ifp = np->xn_ifp = if_alloc(IFT_ETHER);
     	ifp->if_softc = np;
     	if_initname(ifp, "xn",  device_get_unit(dev));
-    	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX;
+    	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
     	ifp->if_ioctl = xn_ioctl;
     	ifp->if_output = ether_output;
     	ifp->if_start = xn_start;
@@ -1777,11 +1772,14 @@ static void netif_free(struct netfront_i
 #endif
 }
 
-
-
 static void netif_disconnect_backend(struct netfront_info *info)
 {
-	xn_stop(info);
+	XN_RX_LOCK(info);
+	XN_TX_LOCK(info);
+	netfront_carrier_off(info);
+	XN_TX_UNLOCK(info);
+	XN_RX_UNLOCK(info);
+
 	end_access(info->tx_ring_ref, info->tx.sring);
 	end_access(info->rx_ring_ref, info->rx.sring);
 	info->tx_ring_ref = GRANT_INVALID_REF;
@@ -1789,12 +1787,9 @@ static void netif_disconnect_backend(str
 	info->tx.sring = NULL;
 	info->rx.sring = NULL;
 
-#if 0
 	if (info->irq)
-		unbind_from_irqhandler(info->irq, info->netdev);
-#else 
-	panic("FIX ME");
-#endif
+		unbind_from_irqhandler(info->irq);
+
 	info->irq = 0;
 }
 

Modified: head/sys/i386/conf/XEN
==============================================================================
--- head/sys/i386/conf/XEN	Mon Dec 29 04:40:52 2008	(r186556)
+++ head/sys/i386/conf/XEN	Mon Dec 29 06:31:03 2008	(r186557)
@@ -9,9 +9,9 @@ ident		XEN
 makeoptions	DEBUG=-g		# Build kernel with gdb(1) debug symbols
 makeoptions	MODULES_OVERRIDE=""
 
-#options 	SCHED_ULE		# ULE scheduler
-#options 	PREEMPTION		# Enable kernel thread preemption
-options		SCHED_4BSD		 
+options 	SCHED_ULE		# ULE scheduler
+options 	PREEMPTION		# Enable kernel thread preemption
+#options		SCHED_4BSD		 
 
 options 	INET			# InterNETworking
 options 	INET6			# IPv6 communications protocols

Modified: head/sys/i386/i386/genassym.c
==============================================================================
--- head/sys/i386/i386/genassym.c	Mon Dec 29 04:40:52 2008	(r186556)
+++ head/sys/i386/i386/genassym.c	Mon Dec 29 06:31:03 2008	(r186557)
@@ -234,7 +234,7 @@ ASSYM(BUS_SPACE_HANDLE_IAT, offsetof(str
 #endif
 
 #ifdef XEN
-#include <machine/xen/hypervisor.h>
+#include <xen/hypervisor.h>
 ASSYM(PC_CR3, offsetof(struct pcpu, pc_cr3));
 ASSYM(HYPERVISOR_VIRT_START, __HYPERVISOR_VIRT_START);
 #endif

Modified: head/sys/i386/i386/machdep.c
==============================================================================
--- head/sys/i386/i386/machdep.c	Mon Dec 29 04:40:52 2008	(r186556)
+++ head/sys/i386/i386/machdep.c	Mon Dec 29 06:31:03 2008	(r186557)
@@ -144,11 +144,11 @@ uint32_t arch_i386_xbox_memsize = 0;
 #ifdef XEN
 /* XEN includes */
 #include <machine/xen/xen-os.h>
-#include <machine/xen/hypervisor.h>
+#include <xen/hypervisor.h>
 #include <machine/xen/xen-os.h>
 #include <machine/xen/xenvar.h>
 #include <machine/xen/xenfunc.h>
-#include <machine/xen/xen_intr.h>
+#include <xen/xen_intr.h>
 
 void Xhypervisor_callback(void);
 void failsafe_callback(void);

Modified: head/sys/i386/i386/vm_machdep.c
==============================================================================
--- head/sys/i386/i386/vm_machdep.c	Mon Dec 29 04:40:52 2008	(r186556)
+++ head/sys/i386/i386/vm_machdep.c	Mon Dec 29 06:31:03 2008	(r186557)
@@ -89,7 +89,7 @@ __FBSDID("$FreeBSD$");
 #include <vm/vm_param.h>
 
 #ifdef XEN
-#include <machine/xen/hypervisor.h>
+#include <xen/hypervisor.h>
 #endif
 #ifdef PC98
 #include <pc98/cbus/cbus.h>

Modified: head/sys/i386/include/xen/xenfunc.h
==============================================================================
--- head/sys/i386/include/xen/xenfunc.h	Mon Dec 29 04:40:52 2008	(r186556)
+++ head/sys/i386/include/xen/xenfunc.h	Mon Dec 29 06:31:03 2008	(r186557)
@@ -33,7 +33,7 @@
 #define _XEN_XENFUNC_H_
 
 #include <machine/xen/xen-os.h>
-#include <machine/xen/hypervisor.h>
+#include <xen/hypervisor.h>
 #include <machine/xen/xenpmap.h>
 #include <machine/segments.h>
 #include <sys/pcpu.h>

Modified: head/sys/i386/isa/npx.c
==============================================================================
--- head/sys/i386/isa/npx.c	Mon Dec 29 04:40:52 2008	(r186556)
+++ head/sys/i386/isa/npx.c	Mon Dec 29 06:31:03 2008	(r186557)
@@ -70,7 +70,7 @@ __FBSDID("$FreeBSD$");
 #include <machine/intr_machdep.h>
 #ifdef XEN
 #include <machine/xen/xen-os.h>
-#include <machine/xen/hypervisor.h>
+#include <xen/hypervisor.h>
 #endif
 
 #ifdef DEV_ISA

Modified: head/sys/i386/xen/clock.c
==============================================================================
--- head/sys/i386/xen/clock.c	Mon Dec 29 04:40:52 2008	(r186556)
+++ head/sys/i386/xen/clock.c	Mon Dec 29 06:31:03 2008	(r186557)
@@ -78,11 +78,11 @@ __FBSDID("$FreeBSD$");
 #include <i386/isa/isa.h>
 #include <isa/rtc.h>
 
-#include <machine/xen/xen_intr.h>
+#include <xen/xen_intr.h>
 #include <vm/vm.h>
 #include <vm/pmap.h>
 #include <machine/pmap.h>
-#include <machine/xen/hypervisor.h>
+#include <xen/hypervisor.h>
 #include <machine/xen/xen-os.h>
 #include <machine/xen/xenfunc.h>
 #include <xen/interface/vcpu.h>
@@ -791,18 +791,20 @@ static struct vcpu_set_periodic_timer xe
 void
 cpu_initclocks(void)
 {
-	int time_irq;
-
+	unsigned int time_irq;
+	int error;
+	
 	xen_set_periodic_tick.period_ns = NS_PER_TICK;
 
 	HYPERVISOR_vcpu_op(VCPUOP_set_periodic_timer, 0,
 			   &xen_set_periodic_tick);
-
-        if ((time_irq = bind_virq_to_irqhandler(VIRQ_TIMER, 0, "clk", 
-		                                clkintr, NULL,
-						INTR_TYPE_CLK | INTR_FAST)) < 0) {
+	
+        error = bind_virq_to_irqhandler(VIRQ_TIMER, 0, "clk", 
+	    clkintr, NULL, NULL,
+	    INTR_TYPE_CLK | INTR_FAST, &time_irq);
+	if (error)
 		panic("failed to register clock interrupt\n");
-	}
+
 
 	/* should fast clock be enabled ? */
 	
@@ -811,18 +813,19 @@ cpu_initclocks(void)
 int
 ap_cpu_initclocks(int cpu)
 {
-	int time_irq;
+	unsigned int time_irq;
+	int error;
 
 	xen_set_periodic_tick.period_ns = NS_PER_TICK;
 
 	HYPERVISOR_vcpu_op(VCPUOP_set_periodic_timer, cpu,
 			   &xen_set_periodic_tick);
-
-        if ((time_irq = bind_virq_to_irqhandler(VIRQ_TIMER, cpu, "clk", 
-						clkintr2, NULL,
-						INTR_TYPE_CLK | INTR_FAST)) < 0) {
+        error = bind_virq_to_irqhandler(VIRQ_TIMER, 0, "clk", 
+	    clkintr, NULL, NULL,
+	    INTR_TYPE_CLK | INTR_FAST, &time_irq);
+	if (error)
 		panic("failed to register clock interrupt\n");
-	}
+
 
 	return (0);
 }

Modified: head/sys/i386/xen/mp_machdep.c
==============================================================================
--- head/sys/i386/xen/mp_machdep.c	Mon Dec 29 04:40:52 2008	(r186556)
+++ head/sys/i386/xen/mp_machdep.c	Mon Dec 29 06:31:03 2008	(r186557)
@@ -85,9 +85,9 @@ __FBSDID("$FreeBSD$");
 
 
 #include <machine/xen/xen-os.h>
-#include <machine/xen/evtchn.h>
-#include <machine/xen/xen_intr.h>
-#include <machine/xen/hypervisor.h>
+#include <xen/evtchn.h>
+#include <xen/xen_intr.h>
+#include <xen/hypervisor.h>
 #include <xen/interface/vcpu.h>
 
 #define stop_cpus_with_nmi	0
@@ -464,7 +464,8 @@ static int
 xen_smp_intr_init(unsigned int cpu)
 {
 	int rc;
-
+	unsigned int irq;
+	
 	per_cpu(resched_irq, cpu) = per_cpu(callfunc_irq, cpu) = -1;
 
 	sprintf(resched_name[cpu], "resched%u", cpu);
@@ -472,22 +473,22 @@ xen_smp_intr_init(unsigned int cpu)
 				    cpu,
 				    resched_name[cpu],
 				    smp_reschedule_interrupt,
-				    INTR_FAST|INTR_TYPE_TTY|INTR_MPSAFE);
+	    INTR_FAST|INTR_TYPE_TTY|INTR_MPSAFE, &irq);
 
 	printf("cpu=%d irq=%d vector=%d\n",
 	    cpu, rc, RESCHEDULE_VECTOR);
 	
-	per_cpu(resched_irq, cpu) = rc;
+	per_cpu(resched_irq, cpu) = irq;
 
 	sprintf(callfunc_name[cpu], "callfunc%u", cpu);
 	rc = bind_ipi_to_irqhandler(CALL_FUNCTION_VECTOR,
 				    cpu,
 				    callfunc_name[cpu],
 				    smp_call_function_interrupt,
-				    INTR_FAST|INTR_TYPE_TTY|INTR_MPSAFE);
+	    INTR_FAST|INTR_TYPE_TTY|INTR_MPSAFE, &irq);
 	if (rc < 0)
 		goto fail;
-	per_cpu(callfunc_irq, cpu) = rc;
+	per_cpu(callfunc_irq, cpu) = irq;
 
 	printf("cpu=%d irq=%d vector=%d\n",
 	    cpu, rc, CALL_FUNCTION_VECTOR);
@@ -500,9 +501,9 @@ xen_smp_intr_init(unsigned int cpu)
 
  fail:
 	if (per_cpu(resched_irq, cpu) >= 0)
-		unbind_from_irqhandler(per_cpu(resched_irq, cpu), NULL);
+		unbind_from_irqhandler(per_cpu(resched_irq, cpu));
 	if (per_cpu(callfunc_irq, cpu) >= 0)
-		unbind_from_irqhandler(per_cpu(callfunc_irq, cpu), NULL);
+		unbind_from_irqhandler(per_cpu(callfunc_irq, cpu));
 	return rc;
 }
 

Modified: head/sys/i386/xen/mptable.c
==============================================================================
--- head/sys/i386/xen/mptable.c	Mon Dec 29 04:40:52 2008	(r186556)
+++ head/sys/i386/xen/mptable.c	Mon Dec 29 06:31:03 2008	(r186557)
@@ -45,7 +45,7 @@ __FBSDID("$FreeBSD$");
 #include <machine/mptable.h>
 #include <machine/specialreg.h>
 
-#include <machine/xen/hypervisor.h>
+#include <xen/hypervisor.h>
 #include <machine/xen/xen-os.h>
 #include <machine/smp.h>
 #include <xen/interface/vcpu.h>

Modified: head/sys/i386/xen/pmap.c
==============================================================================
--- head/sys/i386/xen/pmap.c	Mon Dec 29 04:40:52 2008	(r186556)
+++ head/sys/i386/xen/pmap.c	Mon Dec 29 06:31:03 2008	(r186557)
@@ -154,7 +154,7 @@ __FBSDID("$FreeBSD$");
 #endif
 
 #include <xen/interface/xen.h>
-#include <machine/xen/hypervisor.h>
+#include <xen/hypervisor.h>
 #include <machine/xen/hypercall.h>
 #include <machine/xen/xenvar.h>
 #include <machine/xen/xenfunc.h>

Modified: head/sys/i386/xen/xen_machdep.c
==============================================================================
--- head/sys/i386/xen/xen_machdep.c	Mon Dec 29 04:40:52 2008	(r186556)
+++ head/sys/i386/xen/xen_machdep.c	Mon Dec 29 06:31:03 2008	(r186557)
@@ -59,7 +59,7 @@ __FBSDID("$FreeBSD$");
 
 
 
-#include <machine/xen/hypervisor.h>
+#include <xen/hypervisor.h>
 #include <machine/xen/xenvar.h>
 #include <machine/xen/xenfunc.h>
 #include <machine/xen/xenpmap.h>

Added: head/sys/xen/evtchn.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/xen/evtchn.h	Mon Dec 29 06:31:03 2008	(r186557)
@@ -0,0 +1,94 @@
+/******************************************************************************
+ * evtchn.h
+ * 
+ * Communication via Xen event channels.
+ * Also definitions for the device that demuxes notifications to userspace.
+ * 
+ * Copyright (c) 2004, K A Fraser
+ *
+ * $FreeBSD$
+ */
+
+#ifndef __ASM_EVTCHN_H__
+#define __ASM_EVTCHN_H__
+#include <machine/pcpu.h>
+#include <xen/hypervisor.h>
+#include <machine/xen/synch_bitops.h>
+#include <machine/frame.h>
+
+/*
+ * LOW-LEVEL DEFINITIONS
+ */
+
+/*
+ * Unlike notify_remote_via_evtchn(), this is safe to use across
+ * save/restore. Notifications on a broken connection are silently dropped.
+ */
+void notify_remote_via_irq(int irq);
+
+
+/* Entry point for notifications into Linux subsystems. */
+void evtchn_do_upcall(struct trapframe *frame);
+
+/* Entry point for notifications into the userland character device. */
+void evtchn_device_upcall(int port);
+
+void mask_evtchn(int port);
+
+void unmask_evtchn(int port);
+
+#ifdef SMP
+void rebind_evtchn_to_cpu(int port, unsigned int cpu);
+#else
+#define rebind_evtchn_to_cpu(port, cpu)	((void)0)
+#endif
+
+static inline
+int test_and_set_evtchn_mask(int port)
+{
+	shared_info_t *s = HYPERVISOR_shared_info;
+	return synch_test_and_set_bit(port, s->evtchn_mask);
+}
+
+static inline void 
+clear_evtchn(int port)
+{
+	shared_info_t *s = HYPERVISOR_shared_info;
+	synch_clear_bit(port, &s->evtchn_pending[0]);
+}
+
+static inline void 
+notify_remote_via_evtchn(int port)
+{
+        struct evtchn_send send = { .port = port };
+        (void)HYPERVISOR_event_channel_op(EVTCHNOP_send, &send);
+}
+
+/*
+ * Use these to access the event channel underlying the IRQ handle returned
+ * by bind_*_to_irqhandler().
+ */
+int irq_to_evtchn_port(int irq);
+
+void ipi_pcpu(unsigned int cpu, int vector);
+
+/*
+ * CHARACTER-DEVICE DEFINITIONS
+ */
+
+#define PORT_NORMAL    0x0000
+#define PORT_EXCEPTION 0x8000
+#define PORTIDX_MASK   0x7fff
+
+/* /dev/xen/evtchn resides at device number major=10, minor=200 */
+#define EVTCHN_MINOR 200
+
+/* /dev/xen/evtchn ioctls: */
+/* EVTCHN_RESET: Clear and reinit the event buffer. Clear error condition. */
+#define EVTCHN_RESET  _IO('E', 1)
+/* EVTCHN_BIND: Bind to the specified event-channel port. */
+#define EVTCHN_BIND   _IO('E', 2)
+/* EVTCHN_UNBIND: Unbind from the specified event-channel port. */
+#define EVTCHN_UNBIND _IO('E', 3)
+
+#endif /* __ASM_EVTCHN_H__ */

Modified: head/sys/xen/evtchn/evtchn.c
==============================================================================
--- head/sys/xen/evtchn/evtchn.c	Mon Dec 29 04:40:52 2008	(r186556)
+++ head/sys/xen/evtchn/evtchn.c	Mon Dec 29 06:31:03 2008	(r186557)
@@ -23,10 +23,10 @@ __FBSDID("$FreeBSD$");
 #include <machine/cpufunc.h>
 #include <machine/intr_machdep.h>
 #include <machine/xen/xen-os.h>
-#include <machine/xen/xen_intr.h>
+#include <xen/xen_intr.h>
 #include <machine/xen/synch_bitops.h>
-#include <machine/xen/evtchn.h>
-#include <machine/xen/hypervisor.h>
+#include <xen/evtchn.h>
+#include <xen/hypervisor.h>
 #include <sys/smp.h>
 
 
@@ -76,6 +76,7 @@ static struct mtx irq_mapping_update_loc
 static struct xenpic *xp;
 struct xenpic_intsrc {
 	struct intsrc     xp_intsrc;
+	void		  *xp_cookie;
 	uint8_t           xp_vector;
 	boolean_t	  xp_masked;
 };
@@ -295,6 +296,7 @@ bind_caller_port_to_irq(unsigned int cal
         }
 
         irq_bindcount[irq]++;
+	unmask_evtchn(caller_port);
 
  out:
         mtx_unlock_spin(&irq_mapping_update_lock);
@@ -320,6 +322,7 @@ bind_local_port_to_irq(unsigned int loca
         evtchn_to_irq[local_port] = irq;
         irq_info[irq] = mk_irq_info(IRQT_LOCAL_PORT, 0, local_port);
         irq_bindcount[irq]++;
+	unmask_evtchn(local_port);
 
  out:
         mtx_unlock_spin(&irq_mapping_update_lock);
@@ -361,7 +364,7 @@ static int 
 bind_virq_to_irq(unsigned int virq, unsigned int cpu)
 {
 	struct evtchn_bind_virq bind_virq;
-	int evtchn, irq;
+	int evtchn = 0, irq;
 
 	mtx_lock_spin(&irq_mapping_update_lock);
 
@@ -385,6 +388,7 @@ bind_virq_to_irq(unsigned int virq, unsi
 	}
 
 	irq_bindcount[irq]++;
+	unmask_evtchn(evtchn);
 out:
 	mtx_unlock_spin(&irq_mapping_update_lock);
 
@@ -398,8 +402,9 @@ int 
 bind_ipi_to_irq(unsigned int ipi, unsigned int cpu)
 {
 	struct evtchn_bind_ipi bind_ipi;
-	int evtchn, irq;
-	
+	int irq;
+	int evtchn = 0;
+
 	mtx_lock_spin(&irq_mapping_update_lock);
 	
 	if ((irq = per_cpu(ipi_to_irq, cpu)[ipi]) == -1) {
@@ -418,6 +423,7 @@ bind_ipi_to_irq(unsigned int ipi, unsign
 		bind_evtchn_to_cpu(evtchn, cpu);
 	}
 	irq_bindcount[irq]++;
+	unmask_evtchn(evtchn);
 out:
 	
 	mtx_unlock_spin(&irq_mapping_update_lock);
@@ -465,20 +471,25 @@ bind_caller_port_to_irqhandler(unsigned 
 			  driver_intr_t handler,
 			  void *arg,
 			  unsigned long irqflags,
-                          void **cookiep)
+                          unsigned int *irqp)
 {
 	unsigned int irq;
-	int retval;
+	int error;
 
 	irq = bind_caller_port_to_irq(caller_port);
 	intr_register_source(&xp->xp_pins[irq].xp_intsrc);
-	retval = intr_add_handler(devname, irq, NULL, handler, arg, irqflags, cookiep);
-	if (retval != 0) {
+	error = intr_add_handler(devname, irq, NULL, handler, arg, irqflags,
+	    &xp->xp_pins[irq].xp_cookie);
+
+	if (error) {
 		unbind_from_irq(irq);
-		return -retval;
+		return (error);
 	}
 
-	return irq;
+	if (irqp)
+		*irqp = irq;
+
+	return (0);
 }
 
 int 
@@ -488,43 +499,50 @@ bind_listening_port_to_irqhandler(
 			  driver_intr_t handler,
 			  void *arg,
 			  unsigned long irqflags,
-                          void **cookiep)
+                          unsigned int *irqp)
 {
 	unsigned int irq;
-	int retval;
+	int error;
 
 	irq = bind_listening_port_to_irq(remote_domain);
 	intr_register_source(&xp->xp_pins[irq].xp_intsrc);
-	retval = intr_add_handler(devname, irq, NULL, handler, arg, irqflags, cookiep);
-	if (retval != 0) {
+	error = intr_add_handler(devname, irq, NULL, handler, arg, irqflags,
+	    &xp->xp_pins[irq].xp_cookie);
+	if (error) {
 		unbind_from_irq(irq);
-		return -retval;
+		return (error);
 	}
-
-	return irq;
+	if (irqp)
+		*irqp = irq;
+	
+	return (0);

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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200812290631.mBT6V3KJ047176>