summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroyger <royger@FreeBSD.org>2014-09-30 17:31:04 +0000
committerroyger <royger@FreeBSD.org>2014-09-30 17:31:04 +0000
commitf5ff1ea28006d603e5433a79d303b57e24e33873 (patch)
tree91d4c62f04cd5d4690da0d8d01bd2a6fcd2e291f
parentb0061732f41d34918f174768b616bd6204daa054 (diff)
downloadFreeBSD-src-f5ff1ea28006d603e5433a79d303b57e24e33873.zip
FreeBSD-src-f5ff1ea28006d603e5433a79d303b57e24e33873.tar.gz
xen: convert the xenstore user-space char device to a newbus device
Convert the xenstore user-space device (/dev/xen/xenstore) to a device using the newbus interface. This allows us to make the device initialization dependant on the initialization of xenstore itself in the kernel. Sponsored by: Citrix Systems R&D dev/xen/xenstore/xenstore.c: - Convert to a newbus device, this removes the xs_dev_init function. xen/xenstore/xenstore_internal.h: - Remove xs_dev_init prototype. dev/xen/xenstore/xenstore.c: - Don't call xs_dev_init anymore, the device will attach itself when xenstore is started.
-rw-r--r--sys/dev/xen/xenstore/xenstore.c1
-rw-r--r--sys/dev/xen/xenstore/xenstore_dev.c69
-rw-r--r--sys/xen/xenstore/xenstore_internal.h3
3 files changed, 66 insertions, 7 deletions
diff --git a/sys/dev/xen/xenstore/xenstore.c b/sys/dev/xen/xenstore/xenstore.c
index 8ff766c..4cf985a 100644
--- a/sys/dev/xen/xenstore/xenstore.c
+++ b/sys/dev/xen/xenstore/xenstore.c
@@ -1130,7 +1130,6 @@ xs_probe(device_t dev)
static void
xs_attach_deferred(void *arg)
{
- xs_dev_init();
bus_generic_probe(xs.xs_dev);
bus_generic_attach(xs.xs_dev);
diff --git a/sys/dev/xen/xenstore/xenstore_dev.c b/sys/dev/xen/xenstore/xenstore_dev.c
index e1b40914..54b5e82 100644
--- a/sys/dev/xen/xenstore/xenstore_dev.c
+++ b/sys/dev/xen/xenstore/xenstore_dev.c
@@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/conf.h>
+#include <sys/module.h>
#include <xen/xen-os.h>
@@ -216,9 +217,71 @@ static struct cdevsw xs_dev_cdevsw = {
.d_name = "xs_dev",
};
-void
-xs_dev_init()
+/*------------------ Private Device Attachment Functions --------------------*/
+/**
+ * \brief Identify instances of this device type in the system.
+ *
+ * \param driver The driver performing this identify action.
+ * \param parent The NewBus parent device for any devices this method adds.
+ */
+static void
+xs_dev_identify(driver_t *driver __unused, device_t parent)
+{
+ /*
+ * A single device instance for our driver is always present
+ * in a system operating under Xen.
+ */
+ BUS_ADD_CHILD(parent, 0, driver->name, 0);
+}
+
+/**
+ * \brief Probe for the existance of the Xenstore device
+ *
+ * \param dev NewBus device_t for this instance.
+ *
+ * \return Always returns 0 indicating success.
+ */
+static int
+xs_dev_probe(device_t dev)
{
- make_dev(&xs_dev_cdevsw, 0, UID_ROOT, GID_WHEEL, 0400,
+
+ device_set_desc(dev, "Xenstore user-space device");
+ return (0);
+}
+
+/**
+ * \brief Attach the Xenstore device.
+ *
+ * \param dev NewBus device_t for this instance.
+ *
+ * \return On success, 0. Otherwise an errno value indicating the
+ * type of failure.
+ */
+static int
+xs_dev_attach(device_t dev)
+{
+ struct cdev *xs_cdev;
+
+ xs_cdev = make_dev(&xs_dev_cdevsw, 0, UID_ROOT, GID_WHEEL, 0400,
"xen/xenstore");
+ if (xs_cdev == NULL)
+ return (EINVAL);
+
+ return (0);
}
+
+/*-------------------- Private Device Attachment Data -----------------------*/
+static device_method_t xs_dev_methods[] = {
+ /* Device interface */
+ DEVMETHOD(device_identify, xs_dev_identify),
+ DEVMETHOD(device_probe, xs_dev_probe),
+ DEVMETHOD(device_attach, xs_dev_attach),
+
+ DEVMETHOD_END
+};
+
+DEFINE_CLASS_0(xs_dev, xs_dev_driver, xs_dev_methods, 0);
+devclass_t xs_dev_devclass;
+
+DRIVER_MODULE(xs_dev, xenstore, xs_dev_driver, xs_dev_devclass,
+ NULL, NULL);
diff --git a/sys/xen/xenstore/xenstore_internal.h b/sys/xen/xenstore/xenstore_internal.h
index 0398aef..3355c27 100644
--- a/sys/xen/xenstore/xenstore_internal.h
+++ b/sys/xen/xenstore/xenstore_internal.h
@@ -32,8 +32,5 @@
* $FreeBSD$
*/
-/* Initialize support for userspace access to the XenStore. */
-void xs_dev_init(void);
-
/* Used by the XenStore character device to borrow kernel's store connection. */
int xs_dev_request_and_reply(struct xsd_sockmsg *msg, void **result);
OpenPOWER on IntegriCloud