svn commit: r275677 - in head/sys: dev/xen/grant_table x86/xen xen

Roger Pau Monné royger at FreeBSD.org
Wed Dec 10 11:35:43 UTC 2014


Author: royger
Date: Wed Dec 10 11:35:41 2014
New Revision: 275677
URL: https://svnweb.freebsd.org/changeset/base/275677

Log:
  xen: convert the Grant-table code to a NewBus device
  
  This allows the Grant-table code to attach directly to the xenpv bus,
  allowing us to remove the grant-table initialization done in xenpv.
  
  Sponsored by: Citrix Systems R&D

Modified:
  head/sys/dev/xen/grant_table/grant_table.c
  head/sys/x86/xen/xenpv.c
  head/sys/xen/gnttab.h

Modified: head/sys/dev/xen/grant_table/grant_table.c
==============================================================================
--- head/sys/dev/xen/grant_table/grant_table.c	Wed Dec 10 11:35:10 2014	(r275676)
+++ head/sys/dev/xen/grant_table/grant_table.c	Wed Dec 10 11:35:41 2014	(r275677)
@@ -659,16 +659,59 @@ gnttab_expand(unsigned int req_entries)
 	return (error);
 }
 
-int 
-gnttab_init(device_t dev)
+MTX_SYSINIT(gnttab, &gnttab_list_lock, "GNTTAB LOCK", MTX_DEF); 
+
+/*------------------ 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
+granttable_identify(driver_t *driver __unused, device_t parent)
+{
+
+	KASSERT(xen_domain(),
+	    ("Trying to attach grant-table device on non Xen domain"));
+	/*
+	 * A single device instance for our driver is always present
+	 * in a system operating under Xen.
+	 */
+	if (BUS_ADD_CHILD(parent, 0, driver->name, 0) == NULL)
+		panic("unable to attach Xen Grant-table device");
+}
+
+/**
+ * \brief Probe for the existence of the Xen Grant-table device
+ *
+ * \param dev  NewBus device_t for this instance.
+ *
+ * \return  Always returns 0 indicating success.
+ */
+static int 
+granttable_probe(device_t dev)
+{
+
+	device_set_desc(dev, "Xen Grant-table Device");
+	return (BUS_PROBE_NOWILDCARD);
+}
+
+/**
+ * \brief Attach the Xen Grant-table device.
+ *
+ * \param dev  NewBus device_t for this instance.
+ *
+ * \return  On success, 0. Otherwise an errno value indicating the
+ *          type of failure.
+ */
+static int
+granttable_attach(device_t dev)
 {
 	int i;
 	unsigned int max_nr_glist_frames;
 	unsigned int nr_init_grefs;
 
-	if (!is_running_on_xen())
-		return (ENODEV);
-
 	nr_grant_frames = 1;
 	boot_max_nr_grant_frames = __max_nr_grant_frames();
 
@@ -714,7 +757,20 @@ ini_nomem:
 		free(gnttab_list[i], M_DEVBUF);
 	free(gnttab_list, M_DEVBUF);
 	return (ENOMEM);
-
 }
 
-MTX_SYSINIT(gnttab, &gnttab_list_lock, "GNTTAB LOCK", MTX_DEF); 
+/*-------------------- Private Device Attachment Data  -----------------------*/
+static device_method_t granttable_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_identify,	granttable_identify),
+	DEVMETHOD(device_probe,         granttable_probe),
+	DEVMETHOD(device_attach,        granttable_attach),
+
+	DEVMETHOD_END
+};
+
+DEFINE_CLASS_0(granttable, granttable_driver, granttable_methods, 0);
+devclass_t granttable_devclass;
+
+DRIVER_MODULE_ORDERED(granttable, xenpv, granttable_driver, granttable_devclass,
+    NULL, NULL, SI_ORDER_FIRST);

Modified: head/sys/x86/xen/xenpv.c
==============================================================================
--- head/sys/x86/xen/xenpv.c	Wed Dec 10 11:35:10 2014	(r275676)
+++ head/sys/x86/xen/xenpv.c	Wed Dec 10 11:35:41 2014	(r275677)
@@ -66,15 +66,6 @@ static int
 xenpv_attach(device_t dev)
 {
 	device_t child;
-	int error;
-
-	/* Initialize grant table before any Xen specific device is attached */
-	error = gnttab_init(dev);
-	if (error != 0) {
-		device_printf(dev, "error initializing grant table: %d\n",
-		    error);
-		return (error);
-	}
 
 	/*
 	 * Let our child drivers identify any child devices that they

Modified: head/sys/xen/gnttab.h
==============================================================================
--- head/sys/xen/gnttab.h	Wed Dec 10 11:35:10 2014	(r275676)
+++ head/sys/xen/gnttab.h	Wed Dec 10 11:35:41 2014	(r275677)
@@ -51,8 +51,6 @@ struct gnttab_free_callback {
 	uint16_t count;
 };
 
-int gnttab_init(device_t);
-
 /*
  * Allocate a grant table reference and return it in *result. Returns
  * zero on success or errno on error.


More information about the svn-src-all mailing list