PERFORCE change 123447 for review

Maxim Zhuravlev thioretic at FreeBSD.org
Fri Jul 13 16:39:42 UTC 2007


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

Change 123447 by thioretic at thioretic on 2007/07/13 16:39:10

	TODO: bus_generic_*, resource_* stuff, some cleanups, locking,
		IO requests handling.
	DONE: 	a. naming:
		drv_compat_*	-> driverinfo_*
		pdrv_compat*	-> driverinfolink*
		pdevclass*	-> devclasslink*
		pdevice		-> devicelink*
	
		b. device_attach, _detach

Affected files ...

.. //depot/projects/soc2007/thioretic_gidl/TODO#13 edit
.. //depot/projects/soc2007/thioretic_gidl/kern/subr_bus.c#14 edit

Differences ...

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

@@ -53,7 +53,7 @@
 		# since now internally (and externally) for newbus, driver is
 		# 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_*)
+		# all these are hosted by compatibility layer (driverinfo_*)
 #TODO: check drivers, which use chainevh  
 	a.1.1 Compatibility layer:
 		SOLUTION: keep track of *drv_compat_* stuff
@@ -135,4 +135,4 @@
 		# probed/attached/.. driver. If driver to be set to is DR_LOWEST not equal
 		# to that already in stack or is NULL, the whole driver configuration is
 		# destroyed. Device won't process any i/o requests till its state is set
-		# to DS_ALIVE (i.e. there is no DS_RAW or other drivers in stack).+		# to DS_ATTACHED (i.e. there is no DS_RAW or other drivers in stack).
==== //depot/projects/soc2007/thioretic_gidl/kern/subr_bus.c#14 (text+ko) ====

@@ -67,7 +67,8 @@
 	TAILQ_ENTRY(driverlink) link;	/* list of drivers in devclass */
 };
 
-struct drv_compat {
+typedef struct driverinfo* driverinfo_t;
+struct driverinfo {
 	kobj_class_t	driver;	/**< kobj class, implementing driver 
 							& bus interface methods (from outer space)*/
 	kobj_class_t	drvops;	/**< kobj class, implementing driverops 
@@ -77,33 +78,36 @@
 	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;
+	TAILQ_ENTRY(driverinfo) link;
 };
-typedef struct drv_compat *drv_compat_t;
 
-struct pdrv_compat {
-	drv_compat_t pdriver;
+typedef struct driverinfolink* driverinfolink_t;
+struct driverinfolink {
+	driverinfo_t pdriver;
 	void *ivars;
 	void *softc;
 #define	DF_EXTERNALSOFTC 1		/* softc not allocated by us */
 	int flags;
 	device_state_t state;
-	TAILQ_ENTRY(pdrv_compat) link;
+	TAILQ_ENTRY(driverinfolink) link;
 };
 
 /*
  * Forward declarations
  */
 typedef TAILQ_HEAD(devclass_list, devclass) devclass_list_t;
-typedef TAILQ_HEAD(pdevclass_list, pdevclass) pdevclass_list_t;
+typedef TAILQ_HEAD(devclasslink_list, devclasslink) devclasslink_list_t;
+
 typedef TAILQ_HEAD(driver_list, driverlink) driver_list_t;
+
 typedef TAILQ_HEAD(device_list, device) device_list_t;
-typedef TAILQ_HEAD(pdevice_list, pdevice) pdevice_list_t;
+typedef TAILQ_HEAD(devicelink_list, devicelink) devicelink_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;
+typedef TAILQ_HEAD(driverinfo_list, driverinfo) driverinfo_list_t;
+typedef TAILQ_HEAD(driverinfolink_list, driverinfolink) driverinfolink_list_t;
 
-struct pdevclass{
+typedef struct devclasslink* devclasslink_t;
+struct devclasslink{
 	devclass_t devclass_ptr;
 	TAILQ_ENTRY(pdevclass) link;
 };
@@ -111,7 +115,7 @@
 struct devclass {
 	TAILQ_ENTRY(devclass) link;
 	devclass_t	parent;		/* parent in devclass hierarchy */
-	pdevclass_list_t	filters;	/* these are used to hold information, 
+	devclasslink_list_t	filters;	/* these are used to hold information, 
 									used for non-DRV_LOWEST drivers' classes */
 	driver_list_t	drivers;     /* bus devclasses store drivers for bus */
 	char		*name;
@@ -139,17 +143,16 @@
 	TAILQ_ENTRY(device)	link;	/**< list of devices in parent */
 	TAILQ_ENTRY(device)	devlink; /**< global device list membership */
 	//device_t	parent;		/**< parent of this device  */
-	/*device_list_t*/ pdevice_list_t	parents;
-	/*device_list_t*/ pdevice_list_t	children;	/**< list of child devices */
+	devicelink_list_t	parents;
+	devicelink_list_t	children;	/**< list of child devices */
 
 	/*
 	 * Details of this device.
 	 */
-	/*driver_t*/ pdrv_compat	*driver;	/**< current driver to be probed/attached/...*/
+	driverinfolink_t driver;	/**< current driver to be probed/attached/...*/
 	int driver_level;
-	//driver_list_t drivers[DRV_LEVELS];
-	pdrv_compat_list_t drivers[DRV_LEVELS];
-	int drv_compat_flags;
+	driverinfolink_list_t drivers[DRV_LEVELS];
+	int driverinfo_flags;
 	devclass_t	devclass;	/**< current device class */
 	int		unit;		/**< current unit number */
 	char*		nameunit;	/**< name+unit e.g. foodev0 */
@@ -170,17 +173,18 @@
 	void	*ivars;			/**< instance variables  */
 	void	*softc;			/**< current driver's variables  */
 	u_long	refs;
+	int raw;
 
 	struct sysctl_ctx_list sysctl_ctx; /**< state for sysctl variables  */
 	struct sysctl_oid *sysctl_tree;	/**< state for sysctl variables */
 };
 
-struct pdevice {
+typedef struct devicelink* devicelink_t;
+struct devicelink {
 	device_t device_ptr;
-	TAILQ(pdevice) link;
+	TAILQ(devicelink) link;
 };
 
-
 static MALLOC_DEFINE(M_BUS, "bus", "Bus data structures");
 static MALLOC_DEFINE(M_BUS_SC, "bus-sc", "Bus data structures, softc");
 
@@ -290,7 +294,7 @@
 	char *buf;
 	int error;
 	int level;
-	pdrv_compat* pdrvl;
+	driverinfolink_t dil;
 
 	buf = NULL;
 	switch (arg2) {
@@ -309,10 +313,10 @@
 				case DRV_TOPMOST:	tmpbuf="TOPMOST:"; break;
 			}
 			if (strlen(tmpbuf)+strlen(buf)>1023) break;
-			TAILQ_FOREACH(pdrvl,&((dev->drivers)[level]),link){
-				if(strlen(pdrvl->pdriver->driver->name)+strlen(buf)>1022)
+			TAILQ_FOREACH(dil, &((dev->drivers)[level]), link){
+				if(strlen(dil->pdriver->driver->name)+strlen(buf)>1022)
 					break;
-				strcat(buf,pdrvl->pdriver->driver->name);
+				strcat(buf,dil->pdriver->driver->name);
 				strcat(buf,",");
 			}
 			buf[strlen(buf)]='\0';
@@ -804,7 +808,7 @@
  * Driver compatibility layer implementation
  */
 
-static drv_compat_list_t drv_compat_layer = TAILQ_HEAD_INITIALIZER(drv_compat_layer);
+static driverinfo_list_t driverinfo_layer = TAILQ_HEAD_INITIALIZER(driverinfo_layer);
 
 /**
  * @internal
@@ -816,31 +820,31 @@
  * @param driver	the device class and flags
  * @param add	non-zero to add driver to layer
  */
-static drv_compat_t
-drv_compat_find_internal (drv_internal_t driver, int add) {
-	drv_compat_t drvc;
+static driverinfo_t
+driverinfo_find_internal (drv_internal_t driver, int add) {
+	driverinfo_t di;
 	
 	PDEBUG(("looking for driver %s to compatibility layer", driver->devops->name));
 	if (!driver)
 		return (NULL);
 	
-	TAILQ_FOREACH(drvc,&drv_compat_layer,link){
-		if (driver->devops == drvc->driver)
+	TAILQ_FOREACH(di, &driverinfo_layer, link){
+		if (driver->devops == di->driver)
 			break;
 	}
 	
-	if (!drvc && add){
+	if (!di && add){
 		PDEBUG(("adding driver %s to compatibility layer", driver->devops->name));
-		drvc = malloc(sizeof(struct drv_compat), M_BUS, M_NOWAIT|M_ZERO);
+		di = malloc(sizeof(struct /*drv_compat*/ driverinfo), M_BUS, M_NOWAIT|M_ZERO);
 		if (!drvc)
 			return (NULL);
-		drvc->driver = driver->devops;
-		drvc->flags = driver->flags;
-		TAILQ_INSERT_TAIL(&drv_compat_layer, drvc, link);
+		di->driver = driver->devops;
+		di->flags = driver->flags;
+		TAILQ_INSERT_TAIL(&driverinfo_layer, di, link);
 
 		bus_data_generation_update();
 	}
-	return (drvc);
+	return (di);
 }
 
 /**
@@ -850,16 +854,16 @@
  *
  * @param driver	device kobj_class pointer
  */	
-static drv_compat_t
-drv_compat_find_driver (driver_t *driver) {
-	drv_compat_t drvc;
+static driverinfo_t
+driverinfo_find_driver (driver_t *driver) {
+	driverinfo_t di;
 
-	TAILQ_FOREACH(drvc,&drv_compat_layer,link){
-		if (driver == drvc->driver)
+	TAILQ_FOREACH(di, &driverinfo_layer, link){
+		if (driver == di->driver)
 			break;
 	}
 
-	return drvc; 
+	return di; 
 }
 
 /**
@@ -871,9 +875,9 @@
  *
  * @param driver	devops plus flags
  */
-static drv_compat_t
-drv_compat_add_driver (drv_internal_t driver) {
-	return (drv_compat_find_internal(driver, TRUE));
+static driverinfo_t
+driverinfo_add_driver (drv_internal_t driver) {
+	return (driverinfo_find_internal(driver, TRUE));
 }
 
 /**
@@ -884,10 +888,10 @@
  *					implementation
  */
 static void
-drv_compat_delete_driver (driver_t *driver) {
-	drv_compat_t drvc;
-	drvc = drv_compat_find_driver(driver);
-	TAILQ_REMOVE(&drv_compat_layer, drvc, link);
+driverinfo_delete_driver (driver_t *driver) {
+	driverinfo_t di;
+	di = driverinfo_find_driver(driver);
+	TAILQ_REMOVE(&driverinfo_layer, di, link);
 }
 
 /**
@@ -898,15 +902,15 @@
  * @param flags	pointer to flags to be stored
  */
 static int
-drv_compat_get_flags (driver_t *driver, uint32_t *flags){
-	drv_compat_t drvc;
+driverinfo_get_flags (driver_t *driver, uint32_t *flags){
+	driverinfo_t di;
 
-	drvc = drv_compat_find_driver(driver);
+	di = driverinfo_find_driver(driver);
 
-	if (!drvc)
+	if (!di)
 		return (0);
 	
-	*flags = drvc->flags;
+	*flags = di->flags;
 	return (1);
 }
 
@@ -918,14 +922,14 @@
  * @param flags	flags to be set
  */
 static int
-drv_compat_set_flags (driver_t *driver, uint32_t flags){
-	drv_compat_t drvc;
+driverinfo_set_flags (driver_t *driver, uint32_t flags){
+	driverinfo_t di;
 
-	drvc = drv_compat_find_driver(driver);
+	di = driverinfo_find_driver(driver);
 
-	if (!drvc)
+	if (!di)
 		return (0);
-	drvc->flags = flags;
+	di->flags = flags;
 	return (1);
 }
 /**
@@ -935,7 +939,7 @@
  * @param flags	drv_compat flags
  */
 static int
-drv_compat_flags2idx (uint32_t flags){
+driverinfo_flags2idx (uint32_t flags){
 	switch (flags & DR_ALLEVELS){
 		case DR_LOWEST: return (DRV_LOWEST);
 		case DR_LOWER:	return (DRV_LOWER);
@@ -945,12 +949,12 @@
 	}
 }
 
-drv_compat_isfilter (driver_t *driver){
+driverinfo_isfilter (driver_t *driver){
 	uint32_t flags;
 	int level;
 
-	drv_compat_get_flags (driver, &flags);
-	level = drv_compat_flags2idx (flags);
+	driverinfo_get_flags (driver, &flags);
+	level = driverinfo_flags2idx (flags);
 	return((level>DR_LOWEST & level<DR_TOPMOST) ? TRUE : FALSE);
 }
 
@@ -969,12 +973,12 @@
 
 #define FOR_ALL_BUT_RAW_DRIVER (func, memb, ...)	\
 	int level;		\
-	pdrv_compat *pdc;		\
+	/*pdrv_compat **/ driverinfolink_t dil;		\
 	for (level = DRV_LOWEST; level <= DRV_TOPMOST; level++){	\
 		if(TAILQ_EMPTY(&(dev->drivers[level])))		\
 			continue;	\
-		TAILQ_FOREACH (pdc, &(dev->drivers[level]), link){	\
-			func(pdc->pdriver->memb, __VA_ARGS__);		\
+		TAILQ_FOREACH (dil, &(dev->drivers[level]), link){	\
+			func(dil->pdriver->memb, __VA_ARGS__);		\
 		}					\
 	}
 
@@ -1184,14 +1188,14 @@
 is_device_driver (device_t dev, driver_t *driver){
 	int level;
 	uint32_t flags;
-	pdrv_compat* pdrvl;
+	driverinfolink_t dil;
 
-	if (!drv_compat_get_flags(driver, &flags))
+	if (!driverinfo_get_flags(driver, &flags))
 		/*todo what?*/;
-	level = drv_compat_flags2idx (flags);
+	level = driverinfo_flags2idx (flags);
 	
-	TAILQ_FOREACH(pdrvl,&((dev->drivers)[level]),link){
-		if (pdrvl->pdriver->driver == driver) 
+	TAILQ_FOREACH(dil, &((dev->drivers)[level]), link){
+		if (dil->pdriver->driver == driver) 
 			return(TRUE);
 	}
 	return(FALSE);
@@ -1225,6 +1229,7 @@
 		       int create, int filter)	/**TODO*/
 {
 	devclass_t dc, dcp;
+	devclasslink_t dcl;
 
 	PDEBUG(("looking for %s", classname));
 	if (!classname)
@@ -1271,7 +1276,10 @@
 	}
 
 	if (filter) {
-		TAILQ_INSERT_TAIL(&(dcp->filters), &dc, link);
+		dcl = malloc(sizeof(struct devclasslink), M_BUS, M_NOWAIT|M_ZERO);
+		if (!dcl)
+			return (NULL); /*TODO*/
+		TAILQ_INSERT_TAIL(&(dcp->filters), dcl, link);
 	}
 
 	return (dc);
@@ -1320,10 +1328,10 @@
 devclass_add_driver(devclass_t dc, driver_t *driver)	/*TODO*/
 {
 	driverlink_t dl;
+	driverinfo_t di;
 	int i;
 	uint32_t flags;
 	int isfilter;
-	drv_compat_t drvc;
 
 	PDEBUG(("%s", DRIVERNAME(driver)));
 
@@ -1331,7 +1339,7 @@
 	if (!dl)
 		return (ENOMEM);
 
-	isfilter = drv_compat_isfilter (driver); 
+	isfilter = driverinfo_isfilter (driver); 
 	/*
 	 * Compile the driver's methods. Also increase the reference count
 	 * so that the class doesn't get freed when the last instance
@@ -1340,8 +1348,8 @@
 	 */
 	//kobj_class_compile((kobj_class_t) driver);
 	
-	drvc = drv_compat_find_driver (driver);
-	drvc->topology_ops = kobj_create (drvc->driver, M_BUS, M_NOWAIT|M_ZERO);
+	di = driverinfo_find_driver (driver);
+	di->topology_ops = kobj_create (di->driver, M_BUS, M_NOWAIT|M_ZERO);
 
 	/*
 	 * Make sure the devclass which the driver is implementing exists.
@@ -1391,10 +1399,10 @@
 {
 	devclass_t dc = devclass_find(driver->name);
 	driverlink_t dl;
+	driverinfo_t di;
 	device_t dev;
 	int i;
 	int error;
-	drv_compat_t drvc;
 
 	PDEBUG(("%s from devclass %s", driver->name, DEVCLANAME(busclass)));
 
@@ -1446,9 +1454,9 @@
 	/* XXX: kobj_mtx */
 	driver->refs--;
 	if (driver->refs == 0){
-		drvc = drv_compat_find_driver (driver);
+		di = driverinfo_find_driver (driver);
 		//kobj_class_free((kobj_class_t) driver);
-		kobj_delete (drvc->topology_ops, M_BUS);
+		kobj_delete (di->topology_ops, M_BUS);
 	}
 
 	bus_data_generation_update();
@@ -1876,7 +1884,7 @@
 devclass_add_device(devclass_t dc, device_t dev)	/*TODO*/
 {
 	int buflen, error;
-	drv_compat_t drvc;
+	driverinfo_t di;
 
 	PDEBUG(("%s in devclass %s", DEVICENAME(dev), DEVCLANAME(dc)));
 
@@ -1935,29 +1943,26 @@
 
 static int
 filter_probe_and_attach (device_t dev, driver_t *driver){
-	drv_compat_t drvc;
+	driverinfolink_t dil;
 	int level;
 
-	device_set_driver (dev, drvc->driver);
+	device_set_driver (dev, driver);
 	if (DEVICE_PROBE(dev)<=0){
-		drvc = dev->driver;
-		level = drv_compat_flags2idx(drvc->flags);
-		TAILQ_INSERT_TAIL (&((dev->drivers)[level]), &drvc, link);
+		driver_attach(dev);
 	}
-	device_set_driver (dev, NULL);
 }
 
 static void
 devclass_device2filters (devclass_t dc, device_t dev){
-	pdevclass *pdc;
+	devclasslink_t dcl;
 	driver_t *drv;
 	driverlink_t dl;
 
 	if (TAILQ_EMPTY(&(dc->filters))) return ();
-	TAILQ_FOREACH (pdc, &(dc->filters), link){
-		if (TAILQ_EMPTY(&(pdc->driver_ptr->drivers))) 
+	TAILQ_FOREACH (dcl, &(dc->filters), link){
+		if (TAILQ_EMPTY(&(dcl->devclass_ptr->drivers))) 
 			continue;
-		TAILQ_FOREACH(dl, &(pdc->driver_ptr->drivers), link){
+		TAILQ_FOREACH(dl, &(dcl->devclass_ptr->drivers), link){
 			filter_probe_and_attach (dev, dl->driver);
 		}
 	}
@@ -1991,8 +1996,8 @@
 	device_t dev;
 	devclass_t dc;
 	int level;
-	drv_compat_t drvc;
-	pdevice *pd;
+	driverinfo_t di;
+	devicelink_t pd;
 
 	PDEBUG(("%s at %s as unit %d", name, DEVICENAME(parent), unit));
 
@@ -2011,7 +2016,7 @@
 	if (!dev)
 		return (NULL);
 	TAILQ_INIT(&(dev->parents));
-	pd = malloc(sizeof(struct pdevice), M_BUS, M_NOWAIT|M_ZERO);
+	pd = malloc(sizeof(struct devicelink), M_BUS, M_NOWAIT|M_ZERO);
 	pd->device_ptr = parent;
 	TAILQ_INSERT_TAIL(&(dev->parents), pd, link);
 	TAILQ_INIT(&(dev->children));
@@ -2042,6 +2047,7 @@
 	dev->devflags = 0;
 	dev->flags = DF_ENABLED;
 	dev->order = 0;
+	dev->raw = 0;
 	if (unit == -1)
 		dev->flags |= DF_WILDCARD;
 	if (name) {
@@ -2102,14 +2108,14 @@
 }
 
 static int
-device_add_to_dev_list (device_t addwhat, pdevice_list_t *addwhere, int incr_refs){
-	pdevice *pd;
+device_add_to_dev_list (device_t addwhat, devicelink_list_t *addwhere, int incr_refs){
+	devicelink_t pd;
 	TAILQ_FOREACH (pd, addwhere, link){
 		if (pd->device_ptr == addwhat)
 			return (1);
 	}
 	
-	pd = malloc(sizeof(struct pdevice), M_BUS, M_NOWAIT|M_ZERO);
+	pd = malloc(sizeof(struct devicelink), M_BUS, M_NOWAIT|M_ZERO);
 	if (!pd) 
 		return (0);
 
@@ -2167,13 +2173,13 @@
 device_t
 device_add_child_ordered(device_t dev, int order, const char *name, int unit)
 {
-	/*device_t*/ pdevice *child;
-	/*device_t*/ pdevice *place;
+	devicelink_t child;
+	devicelink_t place;
 
 	PDEBUG(("%s at %s with order %d as unit %d",
 	    name, DEVICENAME(dev), order, unit));
 
-	child = malloc (sizeof(pdevice), M_BUS, M_NOWAIT|M_ZERO);
+	child = malloc (sizeof(struct devicelink), M_BUS, M_NOWAIT|M_ZERO);
 	child->device_ptr = make_device(dev, name, unit/*, NULL*/);
 	if (child->device_ptr == NULL){
 		free (child);
@@ -2213,9 +2219,9 @@
 static int
 destroy_recurse (device_t dev, device_t devtodel, int direction){
 	int error;
-	pdevice *grand;
-	pdevice *pd;
-	pdevice_list_t *list;
+	devicelink_t grand;
+	devicelink_t pd;
+	devicelink_list_t *list;
 	device_t child, parent;
 
 	PDEBUG(("%s from %s", DEVICENAME(child), DEVICENAME(dev)));
@@ -2289,8 +2295,8 @@
 
 static int
 is_device_relation (device_t dev, device_t tocheck, int direction){
-	pdevice *dc;
-	pdevice_list_t list;
+	devicelink_t dc;
+	devicelink_list_t list;
 
 	list = (direction == CHILDREN) ? &tocheck->parents : &tocheck->children;
 	TAILQ_FOREACH (dc, list, link){
@@ -2418,7 +2424,7 @@
 		for (dl = first_matching_driver(dc, child);
 		     dl;
 		     dl = next_matching_driver(dc, child, dl)) {
-			if(!drv_compat_get_flags(dl->driver, &flags))
+			if(!driverinfo_get_flags(dl->driver, &flags))
 				/*todo what?*/;
 			if (child->state == DS_ALIVE && flags & DR_LOWEST ||
 				(child->state != DS_ALIVE && flags & ~(DR_STACKAWARE|DR_LOWEST)))
@@ -2536,7 +2542,7 @@
 device_t
 device_get_parent(device_t dev) /*TODO*/
 {
-	pdevice *pd;
+	devicelink_t pd;
 	if (!TAILQ_EMPTY(&(dev->parents))){
 		pd = TAILQ_FIRST(&(dev->parents));
 		return (pd->device_ptr);
@@ -2564,9 +2570,9 @@
 device_get_relations(device_t dev, device_t **devlistp, int *devcountp, int direction)
 {
 	int count;
-	/*device_t*/ pdevice *relation;
+	devicelink_t relation;
 	device_t *list;
-	pdevice_list_t wherelist;
+	devicelink_list_t wherelist;
 
 	wherelist = (direction == CHILDREN) : &dev->children : &dev->parents;
 	count = 0;
@@ -2608,10 +2614,10 @@
 device_get_driver(device_t dev)
 {
 	//driverlink_t dl;
-	pdrv_compat *pdrvl;
+	driverinfolink_t dil;
 	if (!TAILQ_EMPTY(&((dev->drivers)[DRV_LOWEST]))){
-		pdrvl=TAILQ_FIRST(&((dev->drivers)[DRV_LOWEST]));
-		return (pdrvl->pdriver->driver);
+		dil=TAILQ_FIRST(&((dev->drivers)[DRV_LOWEST]));
+		return (dil->pdriver->driver);
 	}
 	return (NULL);
 }
@@ -2801,15 +2807,15 @@
 device_get_driver_softc(device_t dev, driver_t *driver){
 	int level;
 	uint32_t flags;
-	pdrv_compat *pdrvc;
+	driverinfolink_t dil;
 	
-	if (!drv_compat_get_flags (driver, &flags))
+	if (!driverinfo_get_flags (driver, &flags))
 		return (NULL);
-	level = drv_compat_flags2idx (flags);
+	level = driverinfo_flags2idx (flags);
 
-	TAILQ_FOREACH (pdrvc, &(dev->drivers[level]), link){
-		if (pdrvc->pdriver->driver == driver)
-			return (pdrvc->softc);
+	TAILQ_FOREACH (dil, &(dev->drivers[level]), link){
+		if (dil->pdriver->driver == driver)
+			return (dil->softc);
 	}
 	return (NULL);
 }
@@ -2825,42 +2831,42 @@
 device_set_softc(device_t dev, void *softc)
 {
 	void *psoftc;
-	pdrv_compat *pdrvc;
+	driverinfolink_t dil;
 
 	if(!TAILQ_EMPTY(&(dev->drivers[DRV_LOWEST])))
-		pdrvc = TAILQ_FIRST(&(dev->drivers[DRV_LOWEST]));
-	if (pdrvc && !(pdrvc->flags & DF_EXTERNALSOFTC))
-		free(pdrvc->softc, M_BUS_SC);
-	pdrvc->softc = softc;
-	if (pdrvc->softc)
-		pdrvc->flags |= DF_EXTERNALSOFTC;
+		dil = TAILQ_FIRST(&(dev->drivers[DRV_LOWEST]));
+	if (dil && !(dil->flags & DF_EXTERNALSOFTC))
+		free(dil->softc, M_BUS_SC);
+	dil->softc = softc;
+	if (dil->softc)
+		dil->flags |= DF_EXTERNALSOFTC;
 	else
-		pdrvc->flags &= ~DF_EXTERNALSOFTC;
+		dil->flags &= ~DF_EXTERNALSOFTC;
 }
 
 void
 device_set_driver_softc(device_t dev, driver_t *driver, void* softc){
 	int level;
 	uint32_t flags;
-	pdrv_compat *pdrvc;
+	driverinfolink_t dil;
 	
-	if (!drv_compat_get_flags (driver, &flags))
+	if (!driverinfo_get_flags (driver, &flags))
 		return();
-	level = drv_compat_flags2idx (flags);
+	level = driverinfo_flags2idx (flags);
 
-	TAILQ_FOREACH (pdrvc, &(dev->drivers[level]), link){
-		if (pdrvc->pdriver->driver == driver)
+	TAILQ_FOREACH (dil, &(dev->drivers[level]), link){
+		if (dil->pdriver->driver == driver)
 			break;
 	}
-	if (!pdrvc) return();
+	if (!dil) return();
 
-	if (!(pdrv->flags & DF_EXTERNALSOFTC))
-		free(pdrvc->softc, M_BUS_SC);
-	pdrvc->softc = softc;
-	if (pdrvc->softc)
-		pdrvc->flags |= DF_EXTERNALSOFTC;
+	if (!(dil->flags & DF_EXTERNALSOFTC))
+		free(dil->softc, M_BUS_SC);
+	dil->softc = softc;
+	if (dil->softc)
+		dil->flags |= DF_EXTERNALSOFTC;
 	else
-		pdrvc->flags &= ~DF_EXTERNALSOFTC;
+		dil->flags &= ~DF_EXTERNALSOFTC;
 }
 
 /**
@@ -2922,7 +2928,7 @@
 void
 device_busy(device_t dev)
 {
-	pdevice *parent;
+	devicelink_t parent;
 	if (dev->state < DS_ATTACHED)
 		panic("device_busy: called for unattached device");
 	if (dev->busy == 0 && !TAILQ_EMPTY(&(dev->parents))){
@@ -2940,7 +2946,7 @@
 void
 device_unbusy(device_t dev)
 {
-	pdevice *parent;
+	devicelink_t parent;
 	if (dev->state != DS_BUSY)
 		panic("device_unbusy: called for non-busy device %s",
 		    device_get_nameunit(dev));
@@ -3045,17 +3051,17 @@
 static int
 device_destroy_configuration (device_t dev){
 	int level, error;
-	pdrv_compat *pdrvc;
+	driverinfolink_t dil;
 
 	for (level = DRV_TOPMOST; level>= DRV_LOWEST; level--){
 		if (TAILQ_EMPTY(&(dev->drivers[level])))
 			continue;
-		while(pdrvc = TAILQ_FIRST(&(dev->drivers[level]))){
-			pdrvc->state = DS_RAW;
+		while(dil = TAILQ_FIRST(&(dev->drivers[level]))){
+			dil->state = DS_RAW;
 			if(error = device_detach(dev))
 				return(error);
-			TAILQ_REMOVE(&(dev->drivers[level]), pdrvc, link);
-			free(pdrvc);
+			TAILQ_REMOVE(&(dev->drivers[level]), dil, link);
+			free(dil);
 
 		}
 	}
@@ -3071,26 +3077,29 @@
 int
 device_set_driver(device_t dev, driver_t *driver) /*TODO*/
 {
-	drv_compat_t drvc; 
-	pdrv_compat *pdrvc;
+	driverinfo_t di; 
+	driverinfolink_t dil;
 	uint32_t flags;
 	int level;
 
 	if (dev->state >= DS_ATTACHED)
 		return (EBUSY);
+
+	if (driver == dev->driver->pdriver->driver)
+		return (0);
 	
 	if (driver != NULL){
-		drvc = drv_compat_find_driver (driver);
+		di = driverinfo_find_driver (driver);
 
-		drv_compat_get_flags(driver, &flags);
-		level = drv_compat_flags2idx(flags);
+		driverinfo_get_flags(driver, &flags);
+		level = driverinfo_flags2idx(flags);
 
-		TAILQ_FOREACH(pdrvc, &(dev->drivers[level]), link){
-			if (pdrvc->pdriver == drvc)
+		TAILQ_FOREACH(dil, &(dev->drivers[level]), link){
+			if (dil->pdriver == di)
 				break;
 		}
-		if (pdrvc){
-			pdrvc->state = DS_RAW;
+		if (dil){
+			dil->state = DS_RAW;
 			return (0);
 		}
 	}
@@ -3100,16 +3109,17 @@
 			return (EBUSY);
 	}
 
-	pdrvc = malloc (sizeof(struct pdrv_compat), M_BUS, M_NOWAIT|M_ZERO);
-	pdrvc->pdriver = drvc;
-	pdrvc->state = DS_RAW;
+	dil = malloc (sizeof(struct driverinfolink), M_BUS, M_NOWAIT|M_ZERO);
+	dil->pdriver = di;
+	dil->state = DS_RAW;
+	dev->raw++;
 	
-	TAILQ_INSERT_TAIL (&(dev->drivers[level]), pdrvc);
+	TAILQ_INSERT_TAIL (&(dev->drivers[level]), dil);
 
-	dev->driver = pdrvc;
-//	dev->driver_level = level;
+	dev->driver = dil;
+	dev->driver_level = level;
 
-	if (dev->softc && !(dev->flags & DF_EXTERNALSOFTC)) {
+	if (dev->softc && !(dev->flags & DF_EXTERNALSOFTC)) {	/*TODO*/
 		free(dev->softc, M_BUS_SC);
 		dev->softc = NULL;
 	}
@@ -3121,8 +3131,8 @@
 				//kobj_delete((kobj_t) dev, 0);
 				//kobj_init((kobj_t) dev, &null_class);
 				//dev->driver = NULL;
-				TAILQ_REMOVE(&(dev->drivers[level]), pdrvc, link);
-				free (pdrvc);
+				TAILQ_REMOVE(&(dev->drivers[level]), dil, link);
+				free (dil);
 				return (ENOMEM);
 			}
 		}
@@ -3211,8 +3221,8 @@
 device_attach(device_t dev)
 {
 	int error;
-	pdevice *pd;
-	drv_compat_t drvc;
+	devicelink_t pd;
+	driverinfolink_t dil;
 
 	device_sysctl_init(dev);
 	if (!device_is_quiet(dev)){
@@ -3220,25 +3230,36 @@
 			device_print_child(pd->device_ptr, dev);
 		}
 	}
+	
+	dev->raw--;
+
 	if ((error = DEVICE_ATTACH(dev)) != 0) {
 		printf("device_attach: %s%d attach returned %d\n",
 		    dev->driver->name, dev->unit, error);
 		/* Unset the class; set in device_probe_child */
 		if (dev->devclass == 0)
 			device_set_devclass(dev, 0);
-		device_set_driver(dev, NULL);
+		TAILQ_REMOVE(&(dev->drivers[dev->driver_level]), dev->driver, link);
+		free(dev->driver);
 		device_sysctl_fini(dev);
-		dev->state = DS_NOTPRESENT;
+		if(!dev->raw){
+			dev->state = (dev->driver_level == DRV_LOWEST) ? DS_NOTPRESENT :
+				DS_ATTACHED;
+		}
 		return (error);
-	} else {
-		drvc = dev->driver;
-		dev->devclass = devclass_find (DRIVERNAME(drvc->driver));
-		//level = drv_compat_flags2idx(drvc->flags);
-		
-		//TAILQ_INSERT_TAIL (&((dev->drivers)[level]), &drvc, link);
-		//dev->driver = NULL;
+	}
+
+	dil = dev->driver;
+	if (dev->driver_level == DRV_LOWEST){
+		dev->devclass = devclass_find (DRIVERNAME(dil->pdriver->driver));
+		devclass_device2filters(dev, dev->devclass);
 	}
-	dev->state = DS_ATTACHED;
+	dil->state = DS_ATTACHED;
+	if(!dev->raw)
+		dev->state = DS_ATTECHED;
+	dev->driver = (!TAILQ_EMPTY(&(dev->drivers[DRV_LOWEST]))) ? 
+		TAILQ_FIRST(&(dev->drivers[DRV_LOWEST])) : NULL;
+	dev->driver_level=DRV_LOWEST;
 	devadded(dev);
 	return (0);
 }
@@ -3263,7 +3284,7 @@
 device_detach(device_t dev)
 {
 	int error;
-	pdevice *pd;
+	devicelink_t pd;
 
 	GIANT_REQUIRED;
 
@@ -3275,6 +3296,17 @@
 
 	if ((error = DEVICE_DETACH(dev)) != 0)
 		return (error);
+	if (dev->driver_level != DRV_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->raw--;
+		if(!dev->raw)
+			dev->state = DS_ATTACHED;
+		return (0);
+	}
 	devremoved(dev);
 	device_printf(dev, "detached\n");
 	if (!TAILQ_EMPTY(&(dev->parents))){
@@ -3287,7 +3319,7 @@
 		devclass_delete_device(dev->devclass, dev);
 
 	dev->state = DS_NOTPRESENT;
-	//device_set_driver(dev, NULL);
+	device_set_driver(dev, NULL);
 	device_set_desc(dev, NULL);
 	device_sysctl_fini(dev);
 
@@ -3733,7 +3765,7 @@
 int
 bus_generic_attach(device_t dev)
 {
-	/*device_t*/ pdevice *child;
+	devicelink_t child;
 
 	TAILQ_FOREACH(child, &dev->children, link) {
 		device_probe_and_attach(child->device_ptr);
@@ -4627,13 +4659,13 @@
 		if (dmd->dmd_chainevh)
 			error = dmd->dmd_chainevh(mod,what,dmd->dmd_chainarg);
 
-		drv_compat_add_driver(drv_intnl);
+		driverinfo_add_driver(drv_intnl);
 		driver = drv_intnl->devops;
 		PDEBUG(("Loading module: driver %s on bus %s",
 		    DRIVERNAME(driver), dmd->dmd_busname));
 		if (!parse_parent_name(dmd->dmd_busname, &parents))
 			break;
-		isfilter = drv_compat_isfilter (driver);
+		isfilter = driverinfo_isfilter (driver);
 		while (parents[count]){
 			parent_devclass = devclass_find_internal(parents[count], 0, TRUE, FALSE);
 			error &= devclass_add_driver (parent_devclass, driver);
@@ -4689,7 +4721,7 @@
 		    dmd->dmd_busname));
 		error = devclass_delete_driver(bus_devclass,
 		    driver);
-		drv_compat_delete_driver(driver);
+		driverinfo_delete_driver(driver);
 		if (!error && dmd->dmd_chainevh)
 			error = dmd->dmd_chainevh(mod,what,dmd->dmd_chainarg);
 		break;


More information about the p4-projects mailing list