Source-Changes-HG archive

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

[src/gehenna-devsw]: src/sys Get rid of LM_DT_BLOCK/LM_DT_CHAR.



details:   https://anonhg.NetBSD.org/src/rev/319591e17f28
branches:  gehenna-devsw
changeset: 527054:319591e17f28
user:      gehenna <gehenna%NetBSD.org@localhost>
date:      Thu May 16 04:41:43 2002 +0000

description:
Get rid of LM_DT_BLOCK/LM_DT_CHAR.
Attach/detach both device switches at once, if necessary.
XXX break backward compatibility

diffstat:

 sys/kern/kern_lkm.c |  119 ++++++---------------------------------------------
 sys/sys/lkm.h       |   36 +++++----------
 2 files changed, 29 insertions(+), 126 deletions(-)

diffs (232 lines):

diff -r 8893c58868cd -r 319591e17f28 sys/kern/kern_lkm.c
--- a/sys/kern/kern_lkm.c       Thu May 16 04:35:49 2002 +0000
+++ b/sys/kern/kern_lkm.c       Thu May 16 04:41:43 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_lkm.c,v 1.57 2001/11/12 15:25:11 lukem Exp $      */
+/*     $NetBSD: kern_lkm.c,v 1.57.8.1 2002/05/16 04:41:43 gehenna Exp $        */
 
 /*
  * Copyright (c) 1994 Christopher G. Demetriou
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_lkm.c,v 1.57 2001/11/12 15:25:11 lukem Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lkm.c,v 1.57.8.1 2002/05/16 04:41:43 gehenna Exp $");
 
 #include "opt_ddb.h"
 
@@ -109,6 +109,14 @@
 static int _lkm_exec __P((struct lkm_table *, int));
 static int _lkm_compat __P((struct lkm_table *, int));
 
+dev_type_open(lkmopen);
+dev_type_close(lkmclose);
+dev_type_ioctl(lkmioctl);
+
+const struct cdevsw lkm_cdevsw = {
+       lkmopen, lkmclose, noread, nowrite, lkmioctl,
+       nostop, notty, nopoll, nommap,
+};
 
 /*ARGSUSED*/
 int
@@ -576,20 +584,6 @@
 }
 
 /*
- * Acts like "enodev", but can be identified in cdevsw and bdevsw for
- * dynamic driver major number assignment for a limited number of
- * drivers.
- *
- * Place holder for device switch slots reserved for loadable modules.
- */
-int
-lkmenodev()
-{
-
-       return (enodev());
-}
-
-/*
  * A placeholder function for load/unload/stat calls; simply returns zero.
  * Used where people don't want to specify a special function.
  */
@@ -739,7 +733,6 @@
        int cmd;
 {
        struct lkm_dev *args = lkmtp->private.lkm_dev;
-       int i;
        int error = 0;
 
        switch(cmd) {
@@ -748,95 +741,15 @@
                if (lkmexists(lkmtp))
                        return (EEXIST);
 
-               switch(args->lkm_devtype) {
-               case LM_DT_BLOCK:
-                       if ((i = args->lkm_offset) == -1) {     /* auto */
-                               /*
-                                * Search the table looking for a slot...
-                                */
-                               for (i = 0; i < nblkdev; i++)
-                                       if (bdevsw[i].d_open == 
-                                           (dev_type_open((*))) lkmenodev)
-                                               break;          /* found it! */
-                               /* out of allocable slots? */
-                               if (i == nblkdev) {
-                                       error = ENFILE;
-                                       break;
-                               }
-                       } else {                                /* assign */
-                               if (i < 0 || i >= nblkdev) {
-                                       error = EINVAL;
-                                       break;
-                               }
-                       }
-
-                       /* save old */
-                       memcpy(&args->lkm_olddev.bdev, &bdevsw[i], sizeof(struct bdevsw));
-
-                       /* replace with new */
-                       memcpy(&bdevsw[i], args->lkm_dev.bdev, sizeof(struct bdevsw));
-
-                       /* done! */
-                       args->lkm_offset = i;   /* slot in bdevsw[] */
-                       break;
-
-               case LM_DT_CHAR:
-                       if ((i = args->lkm_offset) == -1) {     /* auto */
-                               /*
-                                * Search the table looking for a slot...
-                                */
-                               for (i = 0; i < nchrdev; i++)
-                                       if (cdevsw[i].d_open ==
-                                           (dev_type_open((*))) lkmenodev)
-                                               break;          /* found it! */
-                               /* out of allocable slots? */
-                               if (i == nchrdev) {
-                                       error = ENFILE;
-                                       break;
-                               }
-                       } else {                                /* assign */
-                               if (i < 0 || i >= nchrdev) {
-                                       error = EINVAL;
-                                       break;
-                               }
-                       }
-
-                       /* save old */
-                       memcpy(&args->lkm_olddev.cdev, &cdevsw[i], sizeof(struct cdevsw));
-
-                       /* replace with new */
-                       memcpy(&cdevsw[i], args->lkm_dev.cdev, sizeof(struct cdevsw));
-
-                       /* done! */
-                       args->lkm_offset = i;   /* slot in cdevsw[] */
-
-                       break;
-
-               default:
-                       error = ENODEV;
-                       break;
-               }
+               error = devsw_attach(args->lkm_devname,
+                                    args->lkm_bdev, &args->lkm_bdevmaj,
+                                    args->lkm_cdev, &args->lkm_cdevmaj);
                break;
 
        case LKM_E_UNLOAD:
-               /* current slot... */
-               i = args->lkm_offset;
-
-               switch(args->lkm_devtype) {
-               case LM_DT_BLOCK:
-                       /* replace current slot contents with old contents */
-                       memcpy(&bdevsw[i], &args->lkm_olddev.bdev, sizeof(struct bdevsw));
-                       break;
-
-               case LM_DT_CHAR:
-                       /* replace current slot contents with old contents */
-                       memcpy(&cdevsw[i], &args->lkm_olddev.cdev, sizeof(struct cdevsw));
-                       break;
-
-               default:
-                       error = ENODEV;
-                       break;
-               }
+               devsw_detach(args->lkm_bdev, args->lkm_cdev);
+               args->lkm_bdevmaj = -1;
+               args->lkm_cdevmaj = -1;
                break;
 
        case LKM_E_STAT:        /* no special handling... */
diff -r 8893c58868cd -r 319591e17f28 sys/sys/lkm.h
--- a/sys/sys/lkm.h     Thu May 16 04:35:49 2002 +0000
+++ b/sys/sys/lkm.h     Thu May 16 04:41:43 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lkm.h,v 1.20 2001/02/25 17:44:15 mrg Exp $     */
+/*     $NetBSD: lkm.h,v 1.20.16.1 2002/05/16 04:41:43 gehenna Exp $    */
 
 /*
  * Header file used by loadable kernel modules and loadable kernel module
@@ -86,14 +86,6 @@
 };
 
 /*
- * Supported device module types
- */
-typedef enum devtype {
-       LM_DT_BLOCK,
-       LM_DT_CHAR
-} DEVTYPE;
-
-/*
  * Loadable device driver
  */
 struct lkm_dev {
@@ -101,16 +93,11 @@
        int     lkm_ver;
        const char *lkm_name;
        u_long  lkm_offset;
-       DEVTYPE lkm_devtype;
-       union {
-               void    *anon;
-               struct bdevsw   *bdev;
-               struct cdevsw   *cdev;
-       } lkm_dev;
-       union {
-               struct bdevsw   bdev;
-               struct cdevsw   cdev;
-       } lkm_olddev;
+       const char *lkm_devname;
+       const struct bdevsw     *lkm_bdev;
+       int lkm_bdevmaj;
+       const struct cdevsw     *lkm_cdev;
+       int lkm_cdevmaj;
 };
 
 /*
@@ -234,14 +221,17 @@
                vfsopsp                         \
        };
 
-#define        MOD_DEV(name,devtype,devslot,devp)      \
+#define        MOD_DEV(name,devname,bdevp,bdevm,cdevp,cdevm)   \
        static struct lkm_dev _module = {       \
                LM_DEV,                         \
                LKM_VERSION,                    \
                name,                           \
-               devslot,                        \
-               devtype,                        \
-               { (void *)devp },               \
+               -1,                             \
+               devname,                        \
+               bdevp,                          \
+               bdevm,                          \
+               cdevp,                          \
+               cdevm,                          \
        };
 
 #define        MOD_COMPAT(name, compatslot,emulp)      \



Home | Main Index | Thread Index | Old Index