Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Jul 2007 17:33:04 GMT
From:      Maxim Zhuravlev <thioretic@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 124042 for review
Message-ID:  <200707241733.l6OHX4fR074846@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=124042

Change 124042 by thioretic@thioretic on 2007/07/24 17:32:51

	drv_compat_ctrl_driver (nice name :)) implementation, some cleanups.

Affected files ...

.. //depot/projects/soc2007/thioretic_gidl/TODO#15 edit
.. //depot/projects/soc2007/thioretic_gidl/kern/device_if.m#3 edit
.. //depot/projects/soc2007/thioretic_gidl/kern/subr_bus.c#20 edit
.. //depot/projects/soc2007/thioretic_gidl/sys/bus.h#7 edit

Differences ...

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

@@ -142,4 +142,28 @@
 		FILE(S) AFFECTED: kern/subr_bus.c
 		# I'm unsure about what to do with those, who have more than a single parent.
 		# Although it's highly unlikely that any devices, which have multiple parents
-		# (functional devices) will use the api. +		# (functional devices) will use the api. 
+	a.1.7 generic device control driver
+		SOLUTION: add drv_compat_ctrl_driver
+		FILE(S) AFFECTED: kern/subr_bus.c
+		# The driver is implemented using macro. There are different implementations
+		# of corresponding bus_if and device_if methods. A method is implemented using
+		# one of the following macro:
+		# FOR_RAW_DRIVER  - is used for methods which suold just pass control to the
+		#	driver being probed/attached/...
+		# FOR_ALL_DRIVERS (exclude_raw, returns_val, return_on_non_zero, func, memb, 
+		#		   ...)
+		# here	exclude_raw - should we call the method for all drivers in the 
+		#		configuration, or exclude driver being probed/attached
+		#	returns_val - does the method, being called, return a value
+		#	return_on_non_zero - 
+		#		TRUE: the first positive value (with no
+		#		regard for which driver at which level returned it) is 
+		#		the vlue the generic driver returns to a caller.
+		#		This is useful, if a filter driver implements eg. cashing
+		#		functionality.
+		#		FALSE: the value, returned by DR_LOWEST driver is the
+		#		value returned to a caller.
+		#	func - the method from bus_if or driver_if being applied to drivers
+		#	memb - the object from driverinfo, which contains the method
+		#		implementation.
==== //depot/projects/soc2007/thioretic_gidl/kern/device_if.m#3 (text+ko) ====

@@ -341,6 +341,8 @@
  *					currently char* is more likely.
  *
  */
-METHOD void* info {
+METHOD int info {
 	device_t dev;
+	char *buf;
+	size_t buflen;
 } DEFAULT null_info;

==== //depot/projects/soc2007/thioretic_gidl/kern/subr_bus.c#20 (text+ko) ====

@@ -109,14 +109,14 @@
 typedef struct devclasslink* devclasslink_t;
 struct devclasslink{
 	devclass_t devclass_ptr;
-	TAILQ_ENTRY(pdevclass) link;
+	TAILQ_ENTRY(devclasslink) link;
 };
 
 struct devclass {
 	TAILQ_ENTRY(devclass) link;
 	devclass_t	parent;		/* parent in devclass hierarchy */
 	devclasslink_list_t	filters;	/* these are used to hold information, 
-									used for non-DRV_LOWEST drivers' classes */
+									used for non-DRL_LOWEST drivers' classes */
 	driver_list_t	drivers;     /* bus devclasses store drivers for bus */
 	char		*name;
 	device_t	*devices;	/* array of devices indexed by unit */
@@ -142,7 +142,6 @@
 	 */
 	TAILQ_ENTRY(device)	link;	/**< list of devices in parent */
 	TAILQ_ENTRY(device)	devlink; /**< global device list membership */
-	//device_t	parent;		/**< parent of this device  */
 	devicelink_list_t	parents;
 	devicelink_list_t	children;	/**< list of child devices */
 
@@ -151,7 +150,7 @@
 	 */
 	driverinfolink_t driver;	/**< current driver to be probed/attached/...*/
 	int driver_level;
-	driverinfolink_list_t drivers[DRV_LEVELS];
+	driverinfolink_list_t drivers[DRL_LEVELS];
 	int driverinfo_flags;
 	devclass_t	devclass;	/**< current device class */
 	int		unit;		/**< current unit number */
@@ -305,13 +304,13 @@
 	case DEVICE_SYSCTL_DRIVER:
 		value = buf = malloc(1024, M_BUS, M_WAITOK | M_ZERO);
 		buf[0]='\0';
-		for (level=DRV_LOWEST; level<=DRV_TOPMOST; level++){
+		for (level=DRL_LOWEST; level<=DRL_TOPMOST; level++){
 			switch(level){
-				case DRV_LOWEST:	tmpbuf="LOWEST:"; break;
-				case DRV_LOWER:	tmpbuf="LOWER:"; break;
-				case DRV_MIDDLE:	tmpbuf="MIDDLE:"; break;
-				case DRV_UPPER:	tmpbuf="UPPER:"; break;
-				case DRV_TOPMOST:	tmpbuf="TOPMOST:"; break;
+				case DRL_LOWEST:	tmpbuf="LOWEST:"; break;
+				case DRL_LOWER:	tmpbuf="LOWER:"; break;
+				case DRL_MIDDLE:	tmpbuf="MIDDLE:"; break;
+				case DRL_UPPER:	tmpbuf="UPPER:"; break;
+				case DRL_TOPMOST:	tmpbuf="TOPMOST:"; break;
 			}
 			if (strlen(tmpbuf)+strlen(buf)>1023) break;
 			TAILQ_FOREACH(dil, &((dev->drivers)[level]), link){
@@ -808,8 +807,19 @@
  * Driver compatibility layer implementation
  */
 
-static driverinfo_list_t driverinfo_layer = TAILQ_HEAD_INITIALIZER(driverinfo_layer);
+static driverinfo_list_t driverinfos = TAILQ_HEAD_INITIALIZER(driverinfos);
+
+static drv_internal_t
+driverinfo_create_driver_drv_internal (driver_t *driver){
+	drv_internal_t new_drv;
 
+	new_drv = malloc (sizeof(struct drv_internal), M_TEMP, M_NOWAIT|M_ZERO);
+	if (new_drv){
+		new_drv.devops = driver;
+		new_drv.flags = DR_LOWEST;
+	}
+	return (new_drv);
+}
 /**
  * @internal
  * @brief Find or add driver compatibility settings
@@ -828,7 +838,7 @@
 	if (!driver)
 		return (NULL);
 	
-	TAILQ_FOREACH(di, &driverinfo_layer, link){
+	TAILQ_FOREACH(di, &driverinfos, link){
 		if (driver->devops == di->driver)
 			break;
 	}
@@ -840,7 +850,7 @@
 			return (NULL);
 		di->driver = driver->devops;
 		di->flags = driver->flags;
-		TAILQ_INSERT_TAIL(&driverinfo_layer, di, link);
+		TAILQ_INSERT_TAIL(&driverinfos, di, link);
 
 		bus_data_generation_update();
 	}
@@ -858,7 +868,7 @@
 driverinfo_find_driver (driver_t *driver) {
 	driverinfo_t di;
 
-	TAILQ_FOREACH(di, &driverinfo_layer, link){
+	TAILQ_FOREACH(di, &driverinfos, link){
 		if (driver == di->driver)
 			break;
 	}
@@ -893,7 +903,7 @@
 
 	di = driverinfo_find_driver(driver);
 	if (di)
-		TAILQ_REMOVE(&driverinfo_layer, di, link);
+		TAILQ_REMOVE(&driverinfos, di, link);
 }
 
 /**
@@ -943,11 +953,11 @@
 static int
 driverinfo_flags2idx (uint32_t flags){
 	switch (flags & DR_ALLLEVELS){
-		case DR_LOWEST: return (DRV_LOWEST);
-		case DR_LOWER:	return (DRV_LOWER);
-		case DR_MIDDLE: return (DRV_MIDDLE);
-		case DR_UPPER:	return (DRV_UPPER);
-		case DR_TOPMOST:	return (DRV_TOPMOST);
+		case DR_LOWEST: return (DRL_LOWEST);
+		case DR_LOWER:	return (DRL_LOWER);
+		case DR_MIDDLE: return (DRL_MIDDLE);
+		case DR_UPPER:	return (DRL_UPPER);
+		case DR_TOPMOST:	return (DRL_TOPMOST);
 	}
 }
 
@@ -955,7 +965,7 @@
  * @internal
  * @brief Checks, whether this is a filtering driver
  *
- * Returns true, if driver level is DRV_LOWEST<level<DRV_TOPMOST,
+ * Returns true, if driver level is DRL_LOWEST<level<DRL_TOPMOST,
  *	false overwise
  */
 
@@ -966,216 +976,246 @@
 
 	driverinfo_get_flags (driver, &flags);
 	level = driverinfo_flags2idx (flags);
-	return((level>DRV_LOWEST & level<DRV_TOPMOST) ? TRUE : FALSE);
+	return((level>DRL_LOWEST & level<DRL_TOPMOST) ? TRUE : FALSE);
 }
 
 
 /**
- * device control multiplexing entries
+ * device control multiplexing driver implementation
  */
+
 #define PREFIX drv_compat_ctrl
 
-#define FUNC(retval, prefix, name, ...)	\
+#define FUNC (retval, prefix, name, ...)	\
 	static retval	\
 	prefix##_##name (__VA_ARGS__)
 
-#define FOR_RAW_DRIVER(func, ...)	\
-	return(func(__VA_ARGS__));
+#define FOR_RAW_DRIVER (func, ...)	\
+	return( func (__VA_ARGS__));
 
-#define FOR_ALL_BUT_RAW_DRIVER (func, memb, ...)	\
+#define FOR_ALL_DRIVERS (exclude_raw, returns_val, return_on_non_zero, func, memb, ...)	\
 	int level;		\
 	driverinfolink_t dil;		\
-	for (level = DRV_LOWEST; level <= DRV_TOPMOST; level++){	\
-		if(TAILQ_EMPTY(&(dev->drivers[level])))		\
+	int val = 0;		\
+	for (level = DRL_TOPMOST; level >= DRL_LOWEST; level--){	\
+		if (TAILQ_EMPTY(&dev->drivers[level]))		\
 			continue;	\
-		TAILQ_FOREACH (dil, &(dev->drivers[level]), link){	\
-			func(dil->pdriver->memb, __VA_ARGS__);		\
+		TAILQ_FOREACH (dil, &dev->drivers[level], link){	\
+			if (exclude_raw && dil->pdriver->state == DS_RAW)	\
+				continue;		\
+			if (returns_val){		\
+				val = func (dil->pdriver->##memb , __VA_ARGS__);	\
+				if (val && return_on_non_zero)		\
+					return (val);			\
+				}		\
+			else			\
+				func (dil->pdriver->##memb , __VA_ARGS__);	\				
 		}					\
-	}
+	}		\
+	if (returns_val)		\
+		return (val);
 
-
-FUNC(int, PREFIX, probe, device_t dev){
-	FOR_RAW_DRIVER(DEVICE_PROBE, dev->driver->pdriver->topology_ops);
+/**
+ * device control multiplexing entries
+ */
+FUNC (int, PREFIX, probe, device_t dev){
+	FOR_RAW_DRIVER (DEVICE_PROBE, dev->driver->pdriver->topology_ops);
 }
 
-FUNC(int, PREFIX, identify, driver_t *driver, device_t parent){
-	FOR_RAW_DRIVER(DEVICE_IDENTIFY, dev->driver->pdriver->driver, parent);
+FUNC (int, PREFIX, identify, driver_t *driver, device_t parent){
+	FOR_RAW_DRIVER (DEVICE_IDENTIFY, dev->driver->pdriver->driver, parent);
 }
 
-FUNC(int, PREFIX, attach, device_t dev){
-	FOR_RAW_DRIVER(DEVICE_ATTACH, dev->driver->pdriver->topology_ops);
+FUNC (int, PREFIX, attach, device_t dev){
+	FOR_RAW_DRIVER (DEVICE_ATTACH, dev->driver->pdriver->topology_ops);
 }
 
-FUNC(int, PREFIX, detach, device_t dev){
-	FOR_RAW_DRIVER(DEVICE_DETACH, dev->driver->pdriver->topology_ops);
+FUNC (int, PREFIX, detach, device_t dev){
+	FOR_RAW_DRIVER (DEVICE_DETACH, dev->driver->pdriver->topology_ops);
 }
 
-FUNC(int, PREFIX, shutdown, device_t parent){
-	FOR_RAW_DRIVER(DEVICE_SHUTDOWN, dev->driver->pdriver->topology_ops);
+FUNC (int, PREFIX, shutdown, device_t parent){
+	FOR_RAW_DRIVER (DEVICE_SHUTDOWN, dev->driver->pdriver->topology_ops);
 }
 
-FUNC(int, PREFIX, suspend, device_t dev){
-	FOR_RAW_DRIVER(DEVICE_SUSPEND, dev->driver->pdriver->topology_ops);
+FUNC (int, PREFIX, suspend, device_t dev){
+	FOR_RAW_DRIVER (DEVICE_SUSPEND, dev->driver->pdriver->topology_ops);
 }
 
-FUNC(int, PREFIX, resume, device_t dev){
-	FOR_RAW_DRIVER(DEVICE_RESUME, dev->driver->pdriver->topology_ops);
+FUNC (int, PREFIX, resume, device_t dev){
+	FOR_RAW_DRIVER (DEVICE_RESUME, dev->driver->pdriver->topology_ops);
 }
 
-FUNC(int, PREFIX, quiesce, device_t dev){
-	FOR_RAW_DRIVER(DEVICE_QUIESCE, dev->driver->pdriver->topology_ops);
+FUNC (int, PREFIX, quiesce, device_t dev){
+	FOR_RAW_DRIVER (DEVICE_QUIESCE, dev->driver->pdriver->topology_ops);
 }
 
-FUNC(void *, PREFIX, info, driver_t *driver, device_t parent){
-	FOR_ALL_BUT_RAW_DRIVER(DEVICE_INFO, topology_ops);
+FUNC (int, PREFIX, info, device_t dev, char *buf, size_t buflen){
+	FOR_ALL_DRIVERS (TRUE, TRUE, FALSE, DEVICE_INFO, topology_ops, buf, buflen);
 }
 
 /**
  * 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);
+FUNC (int, PREFIX, print_child, device_t dev, device_t child){
+	FOR_ALL_DRIVERS (FALSE, TRUE, FALSE, BUS_PRINT_CHILD, topology_ops, child);
+}
+
+FUNC (void, PREFIX, probe_nomatch, device_t dev, device_t child){
+	FOR_ALL_DRIVERS (FALSE, FALSE, FALSE, BUS_PROBE_NOMATCH, topology_ops, child);
+}
+
+FUNC (int, PREFIX, read_ivar, device_t dev, device_t child,
+      int index, uintptr_t *result){
+	FOR_ALL_DRIVERS (FALSE, TRUE, TRUE, BUS_READ_IVAR, topology_ops, child, 
+		index, result);
+}
+
+FUNC (int, PREFIX, write_ivar, device_t dev, device_t child,
+      int index, uintptr_t value){
+	FOR_ALL_DRIVERS (FALSE, TRUE, TRUE, BUS_WRITE_IVAR, topology_ops, child,
+		index, value);
+}
+
+FUNC (void, PREFIX, child_detached, device_t dev, device_t child){
+	FOR_ALL_DRIVERS (FALSE, FALSE, FALSE, BUS_CHILD_DETACHED, topology_ops, child);
+}
+
+FUNC (void, PREFIX, driver_added, device_t dev, driver_t *driver){
+	FOR_ALL_DRIVERS (FALSE, FALSE, FALSE, BUS_DRIVER_ADDED, topology_ops, driver);
+}
+
+FUNC (device_t, PREFIX, add_child, device_t dev, int order,
+      const char* name, int unit){
+	FOR_ALL_DRIVERS (FALSE, TRUE, TRUE, BUS_ADD_CHILD, topology_ops, order, 
+		name, unit);
+}
+
+FUNC (struct resource *, PREFIX, alloc_resource, device_t dev, 
+      device_t child, int type, int *rid, u_long start,
+      u_long end, u_long count, u_int flags){
+	FOR_ALL_DRIVERS (FALSE, TRUE, TRUE, BUS_ALLOC_RESOURCE, topology_ops, 
+		child, type, rid, start, end, count, flags);
+}
+
+FUNC (int, PREFIX, activate_resource, device_t dev, device_t child, 
+      int type, int rid, struct resource *r){
+	FOR_ALL_DRIVERS (FALSE, TRUE, TRUE, BUS_ACTIVATE_RESOURCE, topology_ops, 
+		child, type, rid, r);
+}
+
+FUNC (int, PREFIX, deactivate_resource, device_t dev, device_t child, 
+      int type, int rid, struct resource *r){
+	FOR_ALL_DRIVERS (FALSE, TRUE, TRUE, BUS_DEACTIVATE_RESOURCE, topology_ops, 
+		child, type, rid, r);
+}
+
+FUNC (int, PREFIX, release_resource, device_t dev, device_t child, 
+      int type, int rid, struct resource *res){
+	FOR_ALL_DRIVERS (FALSE, TRUE, TRUE, BUS_RELEASE_RESOURCE, topology_ops, 
+		child, type, rid, res);
+}
+
+FUNC (int, PREFIX, setup_intr, device_t dev, device_t child, 
+      struct resource *irq, int flags, driver_intr_t *intr,
+      void *arg, void **cookiep){
+	FOR_ALL_DRIVERS (FALSE, TRUE, TRUE, BUS_SETUP_INTR, topology_ops, 
+		child, irq, flags, intr, arg, cookiep);
+}
+
+FUNC (int, PREFIX, teardown_intr, device_t dev, device_t child, 
+      struct resource *irq, void *cookie){
+	FOR_ALL_DRIVERS (FALSE, TRUE, TRUE, BUS_TEARDOWN_INTR, topology_ops, 
+		child, irq, cookie);
+}
+
+FUNC (int, PREFIX, set_resource, device_t dev, device_t child, 
+      int type, int rid, u_long start, u_long count){
+	FOR_ALL_DRIVERS (FALSE, TRUE, TRUE, BUS_SET_RESOURCE, topology_ops, 
+		child, type, rid, start, count);
+}
+
+FUNC (int, PREFIX, get_resource, device_t dev, device_t child,
+      int type, int rid, u_long *startp, u_long *countp){
+	FOR_ALL_DRIVERS (FALSE, TRUE, TRUE, BUS_GET_RESOURCE, topology_ops, 
+		child, type, rid, startp, countp);
+}
+
+FUNC (void, PREFIX, delete_resource, device_t dev, device_t child,
+      int type, int rid){
+	FOR_ALL_DRIVERS (FALSE, FALSE, FALSE, BUS_DELETE_RESOURCE, topology_ops, 
+		child, type, rid);
+}
+
+FUNC (struct resource_list *, PREFIX, get_resource_list, device_t dev, 
+      device_t child){
+	FOR_ALL_DRIVERS (FALSE, TRUE, TRUE, BUS_GET_RESOURCE_LIST, topology_ops, 
+		child);
+}
+
+FUNC (int, PREFIX, child_present, device_t dev, device_t child){
+	FOR_ALL_DRIVERS (FALSE, TRUE, TRUE, BUS_CHILD_PRESENT, topology_ops, child);
+}
+
+FUNC (int, PREFIX, child_pnpinfo_str, device_t dev, device_t child, 
+      char *buf, size_t buflen){
+	FOR_ALL_DRIVERS (FALSE, TRUE, FALSE, BUS_CHILD_PNPINFO_STR, topology_ops, 
+		child, buf, buflen);
+}
+
+FUNC (int, PREFIX, child_location_str, device_t dev, device_t child, 
+      char *buf, size_t buflen){
+	FOR_ALL_DRIVERS (FALSE, TRUE, FALSE, BUS_CHILD_LOCATION_STR, topology_ops, 
+		child, buf, buflen);
+}
+
+FUNC (int, PREFIX, config_intr, device_t dev, int irq, 
+      enum intr_trigger trig, enum intr_polarity pol){
+	FOR_ALL_DRIVERS (FALSE, TRUE, TRUE, BUS_CONFIG_INTR, topology_ops, 
+		irq, trig, pol);
+}
+
+FUNC (void, PREFIX, hinted_child, device_t dev, const char *dname,
+      int dunit){
+	FOR_ALL_DRIVERS (FALSE, FALSE, FALSE, BUS_HINTED_CHILD, topology_ops, 
+		dname, dunit);
+}
+
+#define DRIVERMETHOD (name, if_prefix, driver_prefix)	\
+	DEVMETHOD (if_prefix##_##name, driver_prefix##_##name)
 
 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)
+	DRIVERMETHOD (probe, device, PREFIX),
+	DRIVERMETHOD (identify, device, PREFIX),
+	DRIVERMETHOD (attach, device, PREFIX),
+	DRIVERMETHOD (detach, device, PREFIX),
+	DRIVERMETHOD (shutdown, device, PREFIX),
+	DRIVERMETHOD (suspend, device, PREFIX),
+	DRIVERMETHOD (resume, device, PREFIX),
+	DRIVERMETHOD (info, device, PREFIX),
+
+	DRIVERMETHOD (print_child, bus, PREFIX),
+	DRIVERMETHOD (probe_nomatch, bus, PREFIX),
+	DRIVERMETHOD (read_ivar, bus, PREFIX),
+	DRIVERMETHOD (write_ivar, bus, PREFIX),
+	DRIVERMETHOD (child_detached, bus, PREFIX),
+	DRIVERMETHOD (driver_added, bus, PREFIX),
+	DRIVERMETHOD (add_child, bus, PREFIX),
+	DRIVERMETHOD (alloc_resource, bus, PREFIX),
+	DRIVERMETHOD (activate_resource, bus, PREFIX),
+	DRIVERMETHOD (deactivate_resource, bus, PREFIX),
+	DRIVERMETHOD (release_resource, bus, PREFIX),
+	DRIVERMETHOD (setup_intr, bus, PREFIX),
+	DRIVERMETHOD (teardown_intr, bus, PREFIX),
+	DRIVERMETHOD (set_resource, bus, PREFIX),
+	DRIVERMETHOD (get_resource, bus, PREFIX),
+	DRIVERMETHOD (delete_resource, bus, PREFIX),
+	DRIVERMETHOD (get_resource_list, bus, PREFIX),
+	DRIVERMETHOD (child_present, bus, PREFIX),
+	DRIVERMETHOD (child_pnpinfo_str, bus, PREFIX),
+	DRIVERMETHOD (child_location_str, bus, PREFIX),
+	DRIVERMETHOD (config_intr, bus, PREFIX),
+	DRIVERMETHOD (hinted_child, bus, PREFIX)
 };
 
 static	driver_t	drv_compat_ctrl_driver = {	/*TODO*/
@@ -1201,7 +1241,8 @@
 	uint32_t flags;
 	driverinfolink_t dil;
 
-	driverinfo_get_flags(driver, &flags);
+	if (!driverinfo_get_flags(driver, &flags);)
+		return (FALSE);
 	level = driverinfo_flags2idx (flags);
 	
 	TAILQ_FOREACH(dil, &dev->drivers[level], link){
@@ -1362,6 +1403,13 @@
 	 * double-free in devclass_delete_driver.
 	 */
 	di = driverinfo_find_driver (driver);
+	if (!di) {
+		drv_internal_t drv_intnl;
+		
+		drv_intnl = driverinfo_create_driver_drv_internal (driver);
+		if (!drv_intnl && !(di = driverinfo_add_driver(intnl)))
+			if (drv_intnl)	free (drv_intnl);
+	}
 	di->topology_ops = kobj_create (di->driver, M_BUS, M_NOWAIT|M_ZERO);
 
 	/*
@@ -2030,7 +2078,7 @@
 	TAILQ_INSERT_TAIL(&(dev->parents), pd, link);
 	TAILQ_INIT(&(dev->children));
 	kobj_init((kobj_t) dev, &drv_compat_ctrl_driver)
-	for (level=DRV_LOWEST; level<=DRV_TOPMOST; level++)
+	for (level=DRL_LOWEST; level<=DRL_TOPMOST; level++)
 		TAILQ_INIT(&((dev->drivers)[level]));
 	dev->devclass = NULL;
 	dev->state = DS_NOTPRESENT;
@@ -2213,7 +2261,7 @@
 destroy_recurse (device_t dev, device_t devtodel, int direction){
 	int error;
 	devicelink_t grand;
-	devicelink_t pd;
+	devicelink_t pd, pd2;
 	devicelink_list_t *list;
 	device_t child, parent;
 
@@ -2223,7 +2271,7 @@
 		return (destroy_recurse (devtodel, dev, CHILDREN));
 
 	/* remove children first */
-	if (devtodel->refs>1) goto deletefromparents;
+	if (devtodel->refs > 1) goto deletefromparents;
 	while ( (grand = TAILQ_FIRST(&devtodel->children)) ) {
 		error = destroy_recurse(devtodel, grand->device_ptr, direction);
 		if (error)
@@ -2237,7 +2285,7 @@
 	if (devtodel->devclass)
 		devclass_delete_device(devtodel->devclass, devtodel);
 deletefromparents:
-	TAILQ_FOREACH_SAFE(pd, &devtodel->parents, link){
+	TAILQ_FOREACH_SAFE(pd, &devtodel->parents, link, pd2){
 		if (pd->device_ptr == dev){
 			TAILQ_REMOVE(&devtodel->parents, pd, link);
 			devtodel->refs--;
@@ -2612,8 +2660,8 @@
 {
 	driverinfolink_t dil;
 
-	if (!TAILQ_EMPTY(&dev->drivers[DRV_LOWEST])){
-		dil=TAILQ_FIRST(&dev->drivers[DRV_LOWEST]);
+	if (!TAILQ_EMPTY(&dev->drivers[DRL_LOWEST])){
+		dil=TAILQ_FIRST(&dev->drivers[DRL_LOWEST]);
 		return (dil->pdriver->driver);
 	}
 	return (NULL);
@@ -2795,8 +2843,8 @@
 void *
 device_get_softc(device_t dev)
 {
-	if(!TAILQ_EMPTY(&dev->drivers[DRV_LOWEST]))
-		return ((TAILQ_FIRST(&dev->drivers[DRV_LOWEST]))->softc);
+	if(!TAILQ_EMPTY(&dev->drivers[DRL_LOWEST]))
+		return ((TAILQ_FIRST(&dev->drivers[DRL_LOWEST]))->softc);
 	return (NULL);
 }
 
@@ -2830,9 +2878,9 @@
 	void *psoftc;
 	driverinfolink_t dil;
 
-	if(TAILQ_EMPTY(&dev->drivers[DRV_LOWEST]))
+	if(TAILQ_EMPTY(&dev->drivers[DRL_LOWEST]))
 		return (NULL);		
-	dil = TAILQ_FIRST(&dev->drivers[DRV_LOWEST]);
+	dil = TAILQ_FIRST(&dev->drivers[DRL_LOWEST]);
 	if (dil && !(dil->flags & DF_EXTERNALSOFTC))
 		free(dil->softc, M_BUS_SC);
 	dil->softc = softc;
@@ -2906,9 +2954,9 @@
 	driverinfolink_t dil;
 
 	KASSERT(dev != NULL, ("device_get_ivars(NULL, ...)"));
-	if (TAILQ_EMPTY(&dev->drivers[DRV_LOWEST]))
+	if (TAILQ_EMPTY(&dev->drivers[DRL_LOWEST]))
 		return (NULL);
-	dil = TAILQ_FIRST(&dev->drivers[DRV_LOWEST]);
+	dil = TAILQ_FIRST(&dev->drivers[DRL_LOWEST]);
 	
 	return (dil>ivars);
 }
@@ -2945,10 +2993,10 @@
 	driverinfolink_t dil;
 
 	KASSERT(dev != NULL, ("device_set_ivars(NULL, ...)"));
-	if(!(TAILQ_EMPTY(&dev->drivers[DRV_LOWEST]))){
-		dil = TAILQ_FIRST(&dev->drivers[DRV_LOWEST]);
+	if(!(TAILQ_EMPTY(&dev->drivers[DRL_LOWEST]))){
+		dil = TAILQ_FIRST(&dev->drivers[DRL_LOWEST]);
 	}
-	dil = TAILQ_FIRST(&dev->drivers[DRV_LOWEST]);
+	dil = TAILQ_FIRST(&dev->drivers[DRL_LOWEST]);
 	dil->ivars = ivars;
 }
 
@@ -3109,7 +3157,7 @@
 	int level, error;
 	driverinfolink_t dil;
 
-	for (level = DRV_TOPMOST; level>= DRV_LOWEST; level--){
+	for (level = DRL_TOPMOST; level>= DRL_LOWEST; level--){
 		if (TAILQ_EMPTY(&dev->drivers[level]))
 			continue;
 		while(dil = TAILQ_FIRST(&dev->drivers[level])){
@@ -3144,7 +3192,14 @@
 	if (driver == dev->driver->pdriver->driver)
 		return (0);
 	
-	di = driverinfo_find_driver (driver);	
+	di = driverinfo_find_driver (driver);
+	if (!di) {
+		drv_internal_t drv_intnl;
+		
+		drv_intnl = driverinfo_create_driver_drv_internal (driver);
+		if (!drv_intnl && !(di = driverinfo_add_driver(intnl)))
+			if (drv_intnl)	free (drv_intnl);
+	}
 	driverinfo_get_flags(driver, &flags);
 	level = driverinfo_flags2idx(flags);
 
@@ -3155,7 +3210,7 @@
 		}
 	}
 
-	if(driver == NULL || level == DRV_LOWEST){
+	if(driver == NULL || level == DRL_LOWEST){
 		if(!device_destroy_configuration(dev))
 			return (EBUSY);
 	}
@@ -3295,23 +3350,23 @@
 		free(dev->driver);
 		device_sysctl_fini(dev);
 		if(!dev->raw){
-			dev->state = (dev->driver_level == DRV_LOWEST) ? DS_NOTPRESENT :
+			dev->state = (dev->driver_level == DRL_LOWEST) ? DS_NOTPRESENT :
 				DS_ATTACHED;
 		}
 		return (error);
 	}
 
 	dil = dev->driver;
-	if (dev->driver_level == DRV_LOWEST){
+	if (dev->driver_level == DRL_LOWEST){
 		dev->devclass = devclass_find (DRIVERNAME(dil->pdriver->driver));
 		devclass_device2filters(dev, dev->devclass);
 	}
 	dil->state = DS_ATTACHED;
 	if(!dev->raw)
 		dev->state = DS_ATTACHED;
-	dev->driver = (!TAILQ_EMPTY(&dev->drivers[DRV_LOWEST])) ? 
-		TAILQ_FIRST(&(dev->drivers[DRV_LOWEST])) : NULL;
-	dev->driver_level=DRV_LOWEST;
+	dev->driver = (!TAILQ_EMPTY(&dev->drivers[DRL_LOWEST])) ? 
+		TAILQ_FIRST(&dev->drivers[DRL_LOWEST]) : NULL;
+	dev->driver_level=DRL_LOWEST;
 	devadded(dev);
 	return (0);
 }
@@ -3348,12 +3403,12 @@
 
 	if ((error = DEVICE_DETACH(dev)) != 0)
 		return (error);
-	if (dev->driver_level != DRV_LOWEST){
+	if (dev->driver_level != DRL_LOWEST){
 		TAILQ_REMOVE(&dev->drivers[dev->driver_level], dev->driver, link);
 		free(dev->driver);
-		dev->driver = (!TAILQ_EMPTY(&dev->drivers[DRV_LOWEST])) ? 
-			TAILQ_FIRST(&dev->drivers[DRV_LOWEST]) : NULL;
-		dev->driver_level=DRV_LOWEST;
+		dev->driver = (!TAILQ_EMPTY(&dev->drivers[DRL_LOWEST])) ? 
+			TAILQ_FIRST(&dev->drivers[DRL_LOWEST]) : NULL;
+		dev->driver_level=DRL_LOWEST;
 		dev->raw--;
 		if(!dev->raw)
 			dev->state = DS_ATTACHED;
@@ -4911,7 +4966,7 @@
 	    (dev->flags&DF_DESCMALLOCED? "descmalloced,":""),
 	    (dev->flags&DF_REBID? "rebiddable,":""),
 	    (dev->ivars? "":"no "),
-	    ((TAILQ_FIRST(&(dev->drivers[DRV_LOWEST])))->softc? "":"no "),
+	    ((TAILQ_FIRST(&(dev->drivers[DRL_LOWEST])))->softc? "":"no "),
 	    dev->busy));
 }
 

==== //depot/projects/soc2007/thioretic_gidl/sys/bus.h#7 (text+ko) ====

@@ -479,12 +479,12 @@
 
 int	driver_module_handler(struct module *, int, void *);
 
-#define DRV_LEVELS	5
-#define DRV_LOWEST	0
-#define DRV_LOWER	1
-#define DRV_MIDDLE	2
-#define DRV_UPPER	3
-#define DRV_TOPMOST	4
+#define DRL_LEVELS	5
+#define DRL_LOWEST	0
+#define DRL_LOWER	1
+#define DRL_MIDDLE	2
+#define DRL_UPPER	3
+#define DRL_TOPMOST	4
 /**
  * Module support for automatically adding drivers to busses.
  */
@@ -517,7 +517,7 @@
 									\
 static struct drv_internal name##_##busname##_intnl {		\
 	(kobj_class_t)	&driver,		\
-	DR_LOWEST							\
+	DR_LOWEST						\
 };									\
 									\
 static struct driver_module_data name##_##busname##_driver_mod = {	\



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