PERFORCE change 122860 for review

Maxim Zhuravlev thioretic at FreeBSD.org
Wed Jul 4 16:02:43 UTC 2007


http://perforce.freebsd.org/chv.cgi?CH=122860

Change 122860 by thioretic at thioretic on 2007/07/04 16:01:51

	Add drv_compat_ctrl_driver proto.

Affected files ...

.. //depot/projects/soc2007/thioretic_gidl/TODO#6 edit
.. //depot/projects/soc2007/thioretic_gidl/kern/subr_bus.c#5 edit

Differences ...

==== //depot/projects/soc2007/thioretic_gidl/TODO#6 (text+ko) ====

@@ -54,4 +54,18 @@
 		# not just kernel object class to be compiled into device, but
 		# also has flags, default driversops (TODO)...
 		# all these are hosted by compatibility layer (drv_compat_*)
-#TODO: check drivers, which use chainevh  +#TODO: check drivers, which use chainevh  
+	a.1.1 Compatibility layer:
+		SOLUTION: keep track of *drv_compat_* stuff
+		FILE(S) AFFECTED: kern/subr_bus.c
+		# the compatibility layer is supposed to be quite a delicate 
+		# way to let old and new(stack-aware) drivers to coexist. 
+		# Hopefully, all those current drivers won't stop working :).
+		# Compatibility layer consists of:
+		# o Global: drv_compat_layer, which holds all info, the old
+		#	drivers are not aware about.
+		# o Per-driver: driver kobj now (will) inits not to a driver
+		#	attached, but to drv_compat_ctrl_driver, which will demux 
+		#	to stacked drivers.
+		#	dev->drivers are pointers to drv_compat structures that
+		#	represent drivers of interest.
==== //depot/projects/soc2007/thioretic_gidl/kern/subr_bus.c#5 (text+ko) ====

@@ -68,18 +68,32 @@
 };
 
 struct drv_compat {
-	kobj_class_t	driver;
-	uint32_t flags;
+	kobj_class_t	driver;	/**< kobj class, implementing driver 
+							& bus interface methods (from outer space)*/
+	kobj_class_t	drvops;	/**< kobj class, implementing driverops 
+							interface methods (from outer space)*/
+	kobj_t	topology_ops;	/**< object of class implemented by driver
+							(deeply internal:))*/
+	kobj_t	functional_ops;	/**< object of class implemented by driverops
+							(deeply internal:))*/
+	uint32_t flags;	/**< driver-specific flags (from outer space)*/
 	TAILQ_ENTRY(drv_compat) link;
 };
 typedef struct drv_compat *drv_compat_t;
+
+struct pdrv_compat {
+	drv_compat *pdriver;
+	TAILQ_ENTRY(pdrv_compat) link;
+}
 /*
  * Forward declarations
  */
 typedef TAILQ_HEAD(devclass_list, devclass) devclass_list_t;
 typedef TAILQ_HEAD(driver_list, driverlink) driver_list_t;
 typedef TAILQ_HEAD(device_list, device) device_list_t;
+
 typedef TAILQ_HEAD(drv_compat_list, drv_compat) drv_compat_list_t;
+typedef TAILQ_HEAD(pdrv_compat_list, pdrv_compat) pdrv_compat_list_t;
 
 struct devclass {
 	TAILQ_ENTRY(devclass) link;
@@ -101,7 +115,8 @@
 	 * A device is a kernel object. The first field must be the
 	 * current ops table for the object.
 	 */
-	KOBJ_FIELDS;
+	KOBJ_FIELDS;	/**< !TRICK: will init it to drv_compat_ctrl_driver
+						which gonna work around stacked drivers*/
 
 	/*
 	 * Device hierarchy.
@@ -114,8 +129,9 @@
 	/*
 	 * Details of this device.
 	 */
-	//driver_t	*driver;	/**< current driver */
-	driver_list_t drivers[DRV_LEVELS];
+	/*driver_t*/ drv_compat_t	driver;	/**< current driver to be probed/attached/...*/
+	//driver_list_t drivers[DRV_LEVELS];
+	pdrv_compat_list_t drivers[DRV_LEVELS];
 	int drv_compat_flags;
 	devclass_t	devclass;	/**< current device class */
 	int		unit;		/**< current unit number */
@@ -250,6 +266,8 @@
 	const char *value;
 	char *buf;
 	int error;
+	int level;
+	pdrv_compat* pdrvl;
 
 	buf = NULL;
 	switch (arg2) {
@@ -268,10 +286,10 @@
 				case DRV_TOPMOST:	tmpbuf="TOPMOST:"; break;
 			}
 			if (strlen(tmpbuf)+strlen(buf)>1023) break;
-			TAILQ_FOREACH(dl,&((dev->drivers)[level]),link){
-				if(strlen(dl->driver->name)+strlen(buf)>1022)
+			TAILQ_FOREACH(pdrvl,&((dev->drivers)[level]),link){
+				if(strlen(pdrvl->pdriver->driver->name)+strlen(buf)>1022)
 					break;
-				strcat(buf,dl->driver->name);
+				strcat(buf,pdrvl->pdriver->driver->name);
 				strcat(buf,",");
 			}
 			buf[strlen(buf)]='\0';
@@ -779,7 +797,7 @@
 drv_compat_find_internal (drv_internal_t driver, int add) {
 	drv_compat_t drvc;
 	
-	PDEBUG(("looking for driver %s to compatibility layer"), driver->devops->name);
+	PDEBUG(("looking for driver %s to compatibility layer", driver->devops->name));
 	if (!driver)
 		return (NULL);
 	
@@ -789,7 +807,7 @@
 	}
 	
 	if (!drvc && add){
-		PDEBUG(("adding driver %s to compatibility layer"), driver->devops->name);
+		PDEBUG(("adding driver %s to compatibility layer", driver->devops->name));
 		drvc = malloc(sizeof(struct drv_compat), M_BUS, M_NOWAIT|M_ZERO);
 		if (!drvc)
 			return (NULL);
@@ -887,6 +905,174 @@
 	drvc->flags = flags;
 	return (1);
 }
+
+/**
+ * device control multiplexing entries
+ */
+
+static int drv_compat_ctrl_probe (device_t dev);
+static int drv_compat_ctrl_identify (driver_t *driver, device_t parent);
+static int drv_compat_ctrl_attach (device_t dev);
+static int drv_compat_ctrl_detach (device_t dev);
+static int drv_compat_ctrl_shutdown (device_t dev);
+static int drv_compat_ctrl_suspend (device_t dev);
+static int drv_compat_ctrl_resume (device_t dev);
+static int drv_compat_ctrl_quiesce (device_t dev);
+static void* drv_compat_ctrl_info (device_t dev);
+/**
+ * bus control multiplexing entries
+ */
+static int 
+drv_compat_ctrl_print_child (device_t dev,
+							 device_t child);
+static void 
+drv_compat_ctrl_probe_nomatch (device_t dev,
+							   device_t child);
+static int 
+drv_compat_ctrl_read_ivar (device_t dev,
+						   device_t child,
+			 			   int index,
+						   uintptr_t *result);
+static int 
+drv_compat_ctrl_write_ivar (device_t dev,
+						    device_t child,
+							int index,
+							uintptr_t value);
+static void 
+drv_compat_ctrl_child_detached (device_t dev,
+								device_t child);
+static void 
+drv_compat_ctrl_driver_added (device_t dev,
+							  driver_t *driver);
+static device_t 
+drv_compat_ctrl_add_child (device_t dev,
+						   int order,
+						   const char* name,
+						   int unit);
+static struct_resource * 
+drv_compat_ctrl_alloc_resource (device_t dev,
+								device_t child,
+								int type,
+								int *rid,
+								u_long start,
+								u_long end,
+								u_long count,
+								u_int flags);
+static int 
+drv_compat_ctrl_activate_resource (device_t dev,
+								   device_t child,
+								   int type,
+								   int rid,
+								   struct resource *r);
+static int 
+drv_compat_ctrl_deactivate_resource (device_t dev,
+									 device_t child,
+									 int type,
+									 int rid,
+									 struct resource *r);
+static int 
+drv_compat_ctrl_release_resource (device_t dev,
+						 		  device_t child,
+								  int type,
+								  int rid,
+								  struct resource *res);
+static int 
+drv_compat_ctrl_setup_intr (device_t dev,
+							device_t child,
+							struct resource *irq,
+							int flags,
+							driver_intr_t *intr,
+							void *arg,
+							void **cookiep);
+static int 
+drv_compat_ctrl_teardown_intr (device_t dev,
+							   device_t child,
+							   struct resource *irq,
+							   void *cookie);
+static int 
+drv_compat_ctrl_set_resource (device_t dev,
+							  device_t child,
+							  int type,
+							  int rid,
+							  u_long start,
+							  u_long count);
+static int 
+drv_compat_ctrl_get_resource (device_t dev,
+							  device_t child,
+							  int type,
+							  int rid,
+							  u_long *startp,
+							  u_long *countp);
+static void 
+drv_compat_ctrl_delete_resource (device_t dev,
+								 device_t child,
+								 int type,
+								 int rid);
+static struct resource_list * 
+drv_compat_ctrl_get_resource_list (device_t dev,
+								   device_t child);
+static int 
+drv_compat_ctrl_child_present (device_t dev,
+							   device_t child);
+static int 
+drv_compat_ctrl_child_pnpinfo_str (device_t dev,
+								   device_t child,
+								   char *buf,
+								   size_t buflen);
+static int 
+drv_compat_ctrl_child_location_str (device_t dev,
+									device_t child,
+									char *buf,
+									size_t buflen);
+static int 
+drv_compat_ctrl_config_intr (device_t dev,
+							 int irq,
+							 enum intr_trigger trig,
+							 enum intr_polarity pol);
+static void
+drv_compat_ctrl_hinted_child (device_t dev,
+							  const char *dname,
+							  int dunit);
+
+static device_method_t drv_compat_ctrl_methods[] = {
+	DEVMETHOD(device_probe,		drv_compat_ctrl_probe),
+	DEVMETHOD(device_identify,	drv_compat_ctrl_identify),
+	DEVMETHOD(device_attach,	drv_compat_ctrl_attach),
+	DEVMETHOD(device_detach,	drv_compat_ctrl_detach),
+	DEVMETHOD(device_shutdown,	drv_compat_ctrl_shutdown),
+	DEVMETHOD(device_suspend,	drv_compat_ctrl_suspend),
+	DEVMETHOD(device_resume,	drv_compat_ctrl_resume),
+	DEVMETHOD(device_info,		drv_compat_ctrl_info),
+	DEVMETHOD(bus_print_child,	drv_compat_ctrl_print_child),
+	DEVMETHOD(bus_probe_nomatch,		drv_compat_ctrl_probe_nomatch),
+	DEVMETHOD(bus_read_ivar,			drv_compat_ctrl_read_ivar),
+	DEVMETHOD(bus_write_ivar,			drv_compat_ctrl_write_ivar),
+	DEVMETHOD(bus_child_detached,		drv_compat_ctrl_child_detached),
+	DEVMETHOD(bus_driver_added,			drv_compat_ctrl_driver_added),
+	DEVMETHOD(bus_add_child,			drv_compat_ctrl_add_child),
+	DEVMETHOD(bus_alloc_resource,		drv_compat_ctrl_alloc_resource),
+	DEVMETHOD(bus_activate_resource,		drv_compat_ctrl_activate_resource),
+	DEVMETHOD(bus_deactivate_resource,		drv_compat_ctrl_deactivate_resource),
+	DEVMETHOD(bus_release_resource,		drv_compat_ctrl_release_resource),
+	DEVMETHOD(bus_setup_intr,			drv_compat_ctrl_setup_intr),
+	DEVMETHOD(bus_teardown_intr,		drv_compat_ctrl_teardown_intr),
+	DEVMETHOD(bus_set_resource,			drv_compat_ctrl_set_resource),
+	DEVMETHOD(bus_get_resource,			drv_compat_ctrl_get_resource),
+	DEVMETHOD(bus_delete_resource,		drv_compat_ctrl_delete_resource),
+	DEVMETHOD(bus_get_resource_list,		drv_compat_ctrl_get_resource_list),
+	DEVMETHOD(bus_child_present,		drv_compat_ctrl_child_present),
+	DEVMETHOD(bus_child_pnpinfo_str,		drv_compat_ctrl_child_pnpinfo_str),
+	DEVMETHOD(bus_child_location_str,		drv_compat_ctrl_child_location_str),
+	DEVMETHOD(bus_config_intr,			drv_compat_ctrl_config_intr),
+	DEVMETHOD(bus_hinted_child,			drv_compat_ctrl_hinted_child)
+};
+
+static	driver_t	drv_compat_ctrl_driver = {
+	"drv_compat_ctrl",
+	drv_compat_ctrl_methods,
+	0
+};
+
 /*
  * End of compatibility layer implementaion
  */
@@ -895,8 +1081,8 @@
 is_device_driver (device_t dev, driver_t *driver){ /*TODO*/
 	int level;
 	uint32_t flags;
-	driverlink_t dl;
-
+	//driverlink_t dl;
+	pdrv_compat* pdrvl;
 	if (!drv_compat_get_flags(driver, &flags))
 		/*todo what?*/
 
@@ -907,8 +1093,8 @@
 		case DR_UPPER: level=DRV_UPPER; break;
 		case DR_TOPMOST: level=DRV_TOPMOST; break;
 	}
-	TAILQ_FOREACH(dl,&((dev->drivers)[level]),link){
-		if (dl->driver==driver) return(TRUE);
+	TAILQ_FOREACH(pdrvl,&((dev->drivers)[level]),link){
+		if (pdrvl->pdriver->driver==driver) return(TRUE);
 	}
 	return(FALSE);
 }
@@ -2075,10 +2261,11 @@
 driver_t *
 device_get_driver(device_t dev)
 {
-	driverlink_t dl;
+	//driverlink_t dl;
+	pdrv_compat *pdrvl;
 	if (!TAILQ_EMPTY(&((dev->drivers)[DRV_LOWEST]))){
-		dl=TAILQ_FIRST(&((dev->drivers)[DRV_LOWEST]));
-		return (dl->driver);
+		pdrvl=TAILQ_FIRST(&((dev->drivers)[DRV_LOWEST]));
+		return (pdrvl->pdriver->driver);
 	}
 	return (NULL);
 }


More information about the p4-projects mailing list