[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v7 15/19] xen: create a Xen nexus to use in PV/PVH



Introduce a Xen specific nexus that is going to be in charge for
attaching Xen specific devices. Remove the identify routine from Xen
devices and instead attach them from the nexus (PV/PVH) or xenpci
(HVM).
---
 sys/conf/files.amd64        |    1 +
 sys/conf/files.i386         |    1 +
 sys/dev/xen/timer/timer.c   |   14 ------
 sys/dev/xen/xenpci/xenpci.c |    5 ++
 sys/x86/xen/xen_nexus.c     |   99 +++++++++++++++++++++++++++++++++++++++++++
 sys/xen/xenstore/xenstore.c |    7 ---
 6 files changed, 106 insertions(+), 21 deletions(-)
 create mode 100644 sys/x86/xen/xen_nexus.c

diff --git a/sys/conf/files.amd64 b/sys/conf/files.amd64
index 4a3f612..8bb0b5c 100644
--- a/sys/conf/files.amd64
+++ b/sys/conf/files.amd64
@@ -570,3 +570,4 @@ x86/xen/xen_intr.c          optional        xen | xenhvm
 x86/xen/pv.c                   optional        xenhvm
 x86/xen/mptable.c              optional        xenhvm
 x86/xen/pvcpu.c                        optional        xenhvm
+x86/xen/xen_nexus.c            optional        xenhvm
diff --git a/sys/conf/files.i386 b/sys/conf/files.i386
index 790296d..751db32 100644
--- a/sys/conf/files.i386
+++ b/sys/conf/files.i386
@@ -603,3 +603,4 @@ x86/x86/tsc.c                       standard
 x86/x86/delay.c                        standard
 x86/xen/hvm.c                  optional xenhvm
 x86/xen/xen_intr.c             optional xen | xenhvm
+x86/xen/xen_nexus.c            optional xen | xenhvm
diff --git a/sys/dev/xen/timer/timer.c b/sys/dev/xen/timer/timer.c
index 96372ab..b047786 100644
--- a/sys/dev/xen/timer/timer.c
+++ b/sys/dev/xen/timer/timer.c
@@ -98,19 +98,6 @@ struct xentimer_softc {
 /* Last time; this guarantees a monotonically increasing clock. */
 volatile uint64_t xen_timer_last_time = 0;
 
-static void
-xentimer_identify(driver_t *driver, device_t parent)
-{
-       if (!xen_domain())
-               return;
-
-       /* Handle all Xen PV timers in one device instance. */
-       if (devclass_get_device(xentimer_devclass, 0))
-               return;
-
-       BUS_ADD_CHILD(parent, 0, "xen_et", 0);
-}
-
 static int
 xentimer_probe(device_t dev)
 {
@@ -618,7 +605,6 @@ void xen_delay(int n)
 }
 
 static device_method_t xentimer_methods[] = {
-       DEVMETHOD(device_identify, xentimer_identify),
        DEVMETHOD(device_probe, xentimer_probe),
        DEVMETHOD(device_attach, xentimer_attach),
        DEVMETHOD(device_detach, xentimer_detach),
diff --git a/sys/dev/xen/xenpci/xenpci.c b/sys/dev/xen/xenpci/xenpci.c
index dd2ad92..cac8022 100644
--- a/sys/dev/xen/xenpci/xenpci.c
+++ b/sys/dev/xen/xenpci/xenpci.c
@@ -270,6 +270,11 @@ xenpci_attach(device_t dev)
                goto errexit;
        }
 
+       if (BUS_ADD_CHILD(dev, 0, "xenstore", 0) == NULL)
+               panic("xenpci: unable to add xenstore device");
+       if (BUS_ADD_CHILD(nexus, 0, "xen_et", 0) == NULL)
+               panic("xenpci: unable to add xen pv timer device");
+
        return (bus_generic_attach(dev));
 
 errexit:
diff --git a/sys/x86/xen/xen_nexus.c b/sys/x86/xen/xen_nexus.c
new file mode 100644
index 0000000..288e6b6
--- /dev/null
+++ b/sys/x86/xen/xen_nexus.c
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2013 Roger Pau Monnà <roger.pau@xxxxxxxxxx>
+ * All rights reserved.
+ *
+ * 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 AND CONTRIBUTORS 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 OR CONTRIBUTORS 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/sysctl.h>
+#include <sys/systm.h>
+#include <sys/smp.h>
+
+#include <machine/nexusvar.h>
+
+#include <xen/xen-os.h>
+
+static const char *xen_devices[] =
+{
+       "xenstore",             /* XenStore bus */
+       "xen_et",               /* Xen PV timer (provides: tc, et, clk) */
+       "xc",                   /* Xen PV console */
+       "isa",                  /* Dummy ISA bus for sc to attach */
+};
+
+/*
+ * Xen nexus(4) driver.
+ */
+static int
+nexus_xen_probe(device_t dev)
+{
+       if (!xen_pv_domain())
+               return (ENXIO);
+
+       return (BUS_PROBE_DEFAULT);
+}
+
+static int
+nexus_xen_attach(device_t dev)
+{
+       int i, error = 0;
+
+       nexus_init_resources();
+       bus_generic_probe(dev);
+
+       /*
+        * Since we have no ACPI, we need to create a dummy CPU device
+        * in order to set pcpu->pc_device.
+        */
+       CPU_FOREACH(i)
+               if (BUS_ADD_CHILD(dev, 0, "pvcpu", i) == NULL)
+                       panic("unable to add pvcpu#%d device", i);
+
+       for (i = 0; i < nitems(xen_devices); i++) {
+               if (BUS_ADD_CHILD(dev, 0, xen_devices[i], 0) == NULL)
+                       panic("%s: could not add", xen_devices[i]);
+       }
+
+       bus_generic_attach(dev);
+
+       return (error);
+}
+
+static device_method_t nexus_xen_methods[] = {
+       /* Device interface */
+       DEVMETHOD(device_probe,         nexus_xen_probe),
+       DEVMETHOD(device_attach,        nexus_xen_attach),
+
+       { 0, 0 }
+};
+
+DEFINE_CLASS_1(nexus, nexus_xen_driver, nexus_xen_methods, 1, nexus_driver);
+static devclass_t nexus_devclass;
+
+DRIVER_MODULE(nexus_xen, root, nexus_xen_driver, nexus_devclass, 0, 0);
diff --git a/sys/xen/xenstore/xenstore.c b/sys/xen/xenstore/xenstore.c
index d404862..bcf6357 100644
--- a/sys/xen/xenstore/xenstore.c
+++ b/sys/xen/xenstore/xenstore.c
@@ -1079,12 +1079,6 @@ xs_init_comms(void)
 }
 
 /*------------------ Private Device Attachment Functions  
--------------------*/
-static void
-xs_identify(driver_t *driver, device_t parent)
-{
-
-       BUS_ADD_CHILD(parent, 0, "xenstore", 0);
-}
 
 /**
  * Probe for the existance of the XenStore.
@@ -1240,7 +1234,6 @@ xs_resume(device_t dev __unused)
 /*-------------------- Private Device Attachment Data  
-----------------------*/
 static device_method_t xenstore_methods[] = { 
        /* Device interface */ 
-       DEVMETHOD(device_identify,      xs_identify),
        DEVMETHOD(device_probe,         xs_probe), 
        DEVMETHOD(device_attach,        xs_attach), 
        DEVMETHOD(device_detach,        bus_generic_detach), 
-- 
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.