Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Revert 1.194 rev.



details:   https://anonhg.NetBSD.org/src/rev/82c02448f573
branches:  trunk
changeset: 750747:82c02448f573
user:      rmind <rmind%NetBSD.org@localhost>
date:      Tue Jan 12 22:11:13 2010 +0000

description:
Revert 1.194 rev.

diffstat:

 sys/kern/subr_autoconf.c |  112 +++++++++++++++++++++++++++-------------------
 1 files changed, 66 insertions(+), 46 deletions(-)

diffs (279 lines):

diff -r 1b7ec14fe18e -r 82c02448f573 sys/kern/subr_autoconf.c
--- a/sys/kern/subr_autoconf.c  Tue Jan 12 21:48:26 2010 +0000
+++ b/sys/kern/subr_autoconf.c  Tue Jan 12 22:11:13 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_autoconf.c,v 1.196 2010/01/10 13:42:34 martin Exp $ */
+/* $NetBSD: subr_autoconf.c,v 1.197 2010/01/12 22:11:13 rmind Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.196 2010/01/10 13:42:34 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.197 2010/01/12 22:11:13 rmind Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -171,7 +171,10 @@
 static void config_devlink(device_t);
 static void config_alldevs_unlock(int);
 static int config_alldevs_lock(void);
-static void config_alldevs_unlock_gc(int);
+
+static void config_collect_garbage(struct devicelist *);
+static void config_dump_garbage(struct devicelist *);
+
 static void pmflock_debug(device_t, const char *, int);
 
 static device_t deviter_next1(deviter_t *);
@@ -205,7 +208,6 @@
 
 /* list of all devices */
 static struct devicelist alldevs = TAILQ_HEAD_INITIALIZER(alldevs);
-static struct devicelist devs_gclist = TAILQ_HEAD_INITIALIZER(devs_gclist);
 static kmutex_t alldevs_mtx;
 static volatile bool alldevs_garbage = false;
 static volatile devgen_t alldevs_gen = 1;
@@ -368,9 +370,11 @@
 int
 config_cfdriver_detach(struct cfdriver *cd)
 {
+       struct devicelist garbage = TAILQ_HEAD_INITIALIZER(garbage);
        int i, rc = 0, s;
 
        s = config_alldevs_lock();
+       config_collect_garbage(&garbage);
        /* Make sure there are no active instances. */
        for (i = 0; i < cd->cd_ndevs; i++) {
                if (cd->cd_devs[i] != NULL) {
@@ -378,7 +382,8 @@
                        break;
                }
        }
-       config_alldevs_unlock_gc(s);
+       config_alldevs_unlock(s);
+       config_dump_garbage(&garbage);
 
        if (rc != 0)
                return rc;
@@ -440,6 +445,7 @@
 int
 config_cfattach_detach(const char *driver, struct cfattach *ca)
 {
+       struct devicelist garbage = TAILQ_HEAD_INITIALIZER(garbage);
        struct cfdriver *cd;
        device_t dev;
        int i, rc = 0, s;
@@ -449,6 +455,7 @@
                return ESRCH;
 
        s = config_alldevs_lock();
+       config_collect_garbage(&garbage);
        /* Make sure there are no active instances. */
        for (i = 0; i < cd->cd_ndevs; i++) {
                if ((dev = cd->cd_devs[i]) == NULL)
@@ -458,7 +465,8 @@
                        break;
                }
        }
-       config_alldevs_unlock_gc(s);
+       config_alldevs_unlock(s);
+       config_dump_garbage(&garbage);
 
        if (rc != 0)
                return rc;
@@ -1024,9 +1032,7 @@
 }
 
 /*
- * config_devunlink: unlink the device and put into the garbage list.
- *
- * => caller must hold alldevs_mtx.
+ * Caller must hold alldevs_mtx.
  */
 static void
 config_devunlink(device_t dev, struct devicelist *garbage)
@@ -1075,12 +1081,14 @@
        KASSERT(dev->dv_properties != NULL);
        prop_object_release(dev->dv_properties);
 
-       KASSERT(dev->dv_activity_handlers == NULL);
+       if (dev->dv_activity_handlers)
+               panic("%s with registered handlers", __func__);
 
        if (dev->dv_locators) {
                size_t amount = *--dev->dv_locators;
                kmem_free(dev->dv_locators, amount);
        }
+
        config_devfree(dev);
 }
 
@@ -1108,10 +1116,12 @@
 static int
 config_unit_alloc(device_t dev, cfdriver_t cd, cfdata_t cf)
 {
+       struct devicelist garbage = TAILQ_HEAD_INITIALIZER(garbage);
        int s, unit;
 
        s = config_alldevs_lock();
        for (;;) {
+               config_collect_garbage(&garbage);
                unit = config_unit_nextfree(cd, cf);
                if (unit == -1)
                        break;
@@ -1122,7 +1132,8 @@
                }
                config_makeroom(unit, cd);
        }
-       config_alldevs_unlock_gc(s);
+       config_alldevs_unlock(s);
+       config_dump_garbage(&garbage);
 
        return unit;
 }
@@ -1130,6 +1141,7 @@
 static device_t
 config_devalloc(const device_t parent, const cfdata_t cf, const int *locs)
 {
+       struct devicelist garbage = TAILQ_HEAD_INITIALIZER(garbage);
        cfdriver_t cd;
        cfattach_t ca;
        size_t lname, lunit;
@@ -1360,6 +1372,43 @@
 }
 
 /*
+ * Caller must hold alldevs_mtx.
+ */
+static void
+config_collect_garbage(struct devicelist *garbage)
+{
+       device_t dv;
+
+       KASSERT(!cpu_intr_p());
+       KASSERT(!cpu_softintr_p());
+       KASSERT(mutex_owned(&alldevs_mtx));
+
+       while (alldevs_nwrite == 0 && alldevs_nread == 0 && alldevs_garbage) {
+               TAILQ_FOREACH(dv, &alldevs, dv_list) {
+                       if (dv->dv_del_gen != 0)
+                               break;
+               }
+               if (dv == NULL) {
+                       alldevs_garbage = false;
+                       break;
+               }
+               config_devunlink(dv, garbage);
+       }
+       KASSERT(mutex_owned(&alldevs_mtx));
+}
+
+static void
+config_dump_garbage(struct devicelist *garbage)
+{
+       device_t dv;
+
+       while ((dv = TAILQ_FIRST(garbage)) != NULL) {
+               TAILQ_REMOVE(garbage, dv, dv_list);
+               config_devdelete(dv);
+       }
+}
+
+/*
  * Detach a device.  Optionally forced (e.g. because of hardware
  * removal) and quiet.  Returns zero if successful, non-zero
  * (an error code) otherwise.
@@ -1371,6 +1420,7 @@
 int
 config_detach(device_t dev, int flags)
 {
+       struct devicelist garbage = TAILQ_HEAD_INITIALIZER(garbage);
        struct cftable *ct;
        cfdata_t cf;
        const struct cfattach *ca;
@@ -1485,7 +1535,9 @@
                dev->dv_del_gen = alldevs_gen;
                alldevs_garbage = true;
        }
-       config_alldevs_unlock_gc(s);
+       config_collect_garbage(&garbage);
+       config_alldevs_unlock(s);
+       config_dump_garbage(&garbage);
 
        return rv;
 }
@@ -1826,55 +1878,21 @@
 static int
 config_alldevs_lock(void)
 {
-       device_t dv;
        int s;
 
        s = splhigh();
        mutex_enter(&alldevs_mtx);
-
-       KASSERT(TAILQ_EMPTY(&devs_gclist));
-       while (alldevs_nwrite == 0 && alldevs_nread == 0 && alldevs_garbage) {
-               TAILQ_FOREACH(dv, &alldevs, dv_list)
-                       if (dv->dv_del_gen != 0)
-                               break;
-               if (dv == NULL) {
-                       alldevs_garbage = false;
-                       break;
-               }
-               config_devunlink(dv, &devs_gclist);
-       }
        return s;
 }
 
 static void
 config_alldevs_unlock(int s)
 {
-
        mutex_exit(&alldevs_mtx);
        splx(s);
 }
 
 /*
- * config_alldevs_unlock_gc: unlock and free garbage collected entries.
- */
-static void
-config_alldevs_unlock_gc(int s)
-{
-       struct devicelist gclist = TAILQ_HEAD_INITIALIZER(gclist);
-       device_t dv;
-
-       KASSERT(mutex_owned(&alldevs_mtx));
-       TAILQ_CONCAT(&gclist, &devs_gclist, dv_list);
-       KASSERT(TAILQ_EMPTY(&devs_gclist));
-       config_alldevs_unlock(s);
-
-       while ((dv = TAILQ_FIRST(&gclist)) != NULL) {
-               TAILQ_REMOVE(&gclist, dv, dv_list);
-               config_devdelete(dv);
-       }
-}
-
-/*
  * device_lookup:
  *
  *     Look up a device instance for a given driver.
@@ -1882,6 +1900,7 @@
 device_t
 device_lookup(cfdriver_t cd, int unit)
 {
+       struct devicelist garbage = TAILQ_HEAD_INITIALIZER(garbage);
        device_t dv;
        int s;
 
@@ -1892,6 +1911,7 @@
        else if ((dv = cd->cd_devs[unit]) != NULL && dv->dv_del_gen != 0)
                dv = NULL;
        config_alldevs_unlock(s);
+       config_dump_garbage(&garbage);
 
        return dv;
 }



Home | Main Index | Thread Index | Old Index