Source-Changes-HG archive

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

[src/gehenna-devsw]: src/sys/dev Add the character device switch.



details:   https://anonhg.NetBSD.org/src/rev/1832f2162dd2
branches:  gehenna-devsw
changeset: 527059:1832f2162dd2
user:      gehenna <gehenna%NetBSD.org@localhost>
date:      Thu May 16 04:52:05 2002 +0000

description:
Add the character device switch.
Replace the direct-access to devsw table with calling devsw API.

diffstat:

 sys/dev/audio.c     |  20 +++++++++++++----
 sys/dev/cons.c      |  60 ++++++++++++++++++++++++++++++++++++++--------------
 sys/dev/midi.c      |  20 +++++++++++++----
 sys/dev/sequencer.c |  31 +++++++++++++++++++++++---
 4 files changed, 101 insertions(+), 30 deletions(-)

diffs (truncated from 355 to 300 lines):

diff -r d93e1c4ec6c0 -r 1832f2162dd2 sys/dev/audio.c
--- a/sys/dev/audio.c   Thu May 16 04:49:35 2002 +0000
+++ b/sys/dev/audio.c   Thu May 16 04:52:05 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.155 2002/03/23 17:17:10 kent Exp $ */
+/*     $NetBSD: audio.c,v 1.155.2.1 2002/05/16 04:52:05 gehenna Exp $  */
 
 /*
  * Copyright (c) 1991-1993 Regents of the University of California.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.155 2002/03/23 17:17:10 kent Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.155.2.1 2002/05/16 04:52:05 gehenna Exp $");
 
 #include "audio.h"
 #if NAUDIO > 0
@@ -181,6 +181,18 @@
                             int, int);
 int    au_portof(struct audio_softc *, char *);
 
+dev_type_open(audioopen);
+dev_type_close(audioclose);
+dev_type_read(audioread);
+dev_type_write(audiowrite);
+dev_type_ioctl(audioioctl);
+dev_type_poll(audiopoll);
+dev_type_mmap(audiommap);
+
+const struct cdevsw audio_cdevsw = {
+       audioopen, audioclose, audioread, audiowrite, audioioctl,
+       nostop, notty, audiopoll, audiommap,
+};
 
 /* The default audio mode: 8 kHz mono ulaw */
 struct audio_params audio_default =
@@ -372,9 +384,7 @@
        free(sc->sc_rconvbuffer, M_DEVBUF);
 
        /* locate the major number */
-       for (maj = 0; maj < nchrdev; maj++)
-               if (cdevsw[maj].d_open == audioopen)
-                       break;
+       maj = cdevsw_lookup_major(&audio_cdevsw);
 
        /* Nuke the vnodes for any open instances (calls close). */
        mn = self->dv_unit;
diff -r d93e1c4ec6c0 -r 1832f2162dd2 sys/dev/cons.c
--- a/sys/dev/cons.c    Thu May 16 04:49:35 2002 +0000
+++ b/sys/dev/cons.c    Thu May 16 04:52:05 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cons.c,v 1.41 2001/11/13 05:32:50 lukem Exp $  */
+/*     $NetBSD: cons.c,v 1.41.8.1 2002/05/16 04:52:05 gehenna Exp $    */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -43,7 +43,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.41 2001/11/13 05:32:50 lukem Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.41.8.1 2002/05/16 04:52:05 gehenna Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -58,6 +58,18 @@
 
 #include <dev/cons.h>
 
+dev_type_open(cnopen);
+dev_type_close(cnclose);
+dev_type_read(cnread);
+dev_type_write(cnwrite);
+dev_type_ioctl(cnioctl);
+dev_type_poll(cnpoll);
+
+const struct cdevsw cons_cdevsw = {
+       cnopen, cnclose, cnread, cnwrite, cnioctl,
+       nostop, notty, cnpoll, nommap, D_TTY
+};
+
 struct tty *constty = NULL;    /* virtual console output device */
 struct consdev *cn_tab;        /* physical console device info */
 struct vnode *cn_devvp;        /* vnode for underlying device. */
@@ -68,6 +80,7 @@
        int flag, mode;
        struct proc *p;
 {
+       const struct cdevsw *cdev;
        dev_t cndev;
 
        if (cn_tab == NULL)
@@ -96,12 +109,15 @@
                 */
                panic("cnopen: cn_tab->cn_dev == dev\n");
        }
+       cdev = cdevsw_lookup(cndev);
+       if (cdev == NULL)
+               return (ENXIO);
 
        if (cn_devvp == NULLVP) {
                /* try to get a reference on its vnode, but fail silently */
                cdevvp(cndev, &cn_devvp);
        }
-       return ((*cdevsw[major(cndev)].d_open)(cndev, flag, mode, p));
+       return ((*cdev->d_open)(cndev, flag, mode, p));
 }
  
 int
@@ -110,6 +126,7 @@
        int flag, mode;
        struct proc *p;
 {
+       const struct cdevsw *cdev;
        struct vnode *vp;
 
        if (cn_tab == NULL)
@@ -121,6 +138,9 @@
         * screw up others who have it open.
         */
        dev = cn_tab->cn_dev;
+       cdev = cdevsw_lookup(dev);
+       if (cdev == NULL)
+               return (ENXIO);
        if (cn_devvp != NULLVP) {
                /* release our reference to real dev's vnode */
                vrele(cn_devvp);
@@ -128,7 +148,7 @@
        }
        if (vfinddev(dev, VCHR, &vp) && vcount(vp))
                return (0);
-       return ((*cdevsw[major(dev)].d_close)(dev, flag, mode, p));
+       return ((*cdev->d_close)(dev, flag, mode, p));
 }
  
 int
@@ -137,6 +157,7 @@
        struct uio *uio;
        int flag;
 {
+       const struct cdevsw *cdev;
 
        /*
         * If we would redirect input, punt.  This will keep strange
@@ -151,7 +172,10 @@
                return ENXIO;
 
        dev = cn_tab->cn_dev;
-       return ((*cdevsw[major(dev)].d_read)(dev, uio, flag));
+       cdev = cdevsw_lookup(dev);
+       if (cdev == NULL)
+               return (ENXIO);
+       return ((*cdev->d_read)(dev, uio, flag));
 }
  
 int
@@ -160,6 +184,7 @@
        struct uio *uio;
        int flag;
 {
+       const struct cdevsw *cdev;
 
        /*
         * Redirect output, if that's appropriate.
@@ -171,17 +196,12 @@
                return ENXIO;
        else
                dev = cn_tab->cn_dev;
-       return ((*cdevsw[major(dev)].d_write)(dev, uio, flag));
+       cdev = cdevsw_lookup(dev);
+       if (cdev == NULL)
+               return (ENXIO);
+       return ((*cdev->d_write)(dev, uio, flag));
 }
 
-void
-cnstop(tp, flag)
-       struct tty *tp;
-       int flag;
-{
-
-}
- 
 int
 cnioctl(dev, cmd, data, flag, p)
        dev_t dev;
@@ -190,6 +210,7 @@
        int flag;
        struct proc *p;
 {
+       const struct cdevsw *cdev;
        int error;
 
        /*
@@ -216,7 +237,10 @@
                return ENXIO;
        else
                dev = cn_tab->cn_dev;
-       return ((*cdevsw[major(dev)].d_ioctl)(dev, cmd, data, flag, p));
+       cdev = cdevsw_lookup(dev);
+       if (cdev == NULL)
+               return (ENXIO);
+       return ((*cdev->d_ioctl)(dev, cmd, data, flag, p));
 }
 
 /*ARGSUSED*/
@@ -226,6 +250,7 @@
        int events;
        struct proc *p;
 {
+       const struct cdevsw *cdev;
 
        /*
         * Redirect the poll, if that's appropriate.
@@ -238,7 +263,10 @@
                return ENXIO;
        else
                dev = cn_tab->cn_dev;
-       return ((*cdevsw[major(dev)].d_poll)(dev, events, p));
+       cdev = cdevsw_lookup(dev);
+       if (cdev == NULL)
+               return (ENXIO);
+       return ((*cdev->d_poll)(dev, events, p));
 }
 
 int
diff -r d93e1c4ec6c0 -r 1832f2162dd2 sys/dev/midi.c
--- a/sys/dev/midi.c    Thu May 16 04:49:35 2002 +0000
+++ b/sys/dev/midi.c    Thu May 16 04:52:05 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: midi.c,v 1.23 2001/11/13 05:32:50 lukem Exp $  */
+/*     $NetBSD: midi.c,v 1.23.8.1 2002/05/16 04:52:05 gehenna Exp $    */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: midi.c,v 1.23 2001/11/13 05:32:50 lukem Exp $");
+__KERNEL_RCSID(0, "$NetBSD: midi.c,v 1.23.8.1 2002/05/16 04:52:05 gehenna Exp $");
 
 #include "midi.h"
 #include "sequencer.h"
@@ -91,6 +91,18 @@
 int    mididetach(struct device *, int);
 int    midiactivate(struct device *, enum devact);
 
+dev_type_open(midiopen);
+dev_type_close(midiclose);
+dev_type_read(midiread);
+dev_type_write(midiwrite);
+dev_type_ioctl(midiioctl);
+dev_type_poll(midipoll);
+
+const struct cdevsw midi_cdevsw = {
+       midiopen, midiclose, midiread, midiwrite, midiioctl,
+       nostop, notty, midipoll, nommap,
+};
+
 struct cfattach midi_ca = {
        sizeof(struct midi_softc), midiprobe, midiattach,
        mididetach, midiactivate
@@ -179,9 +191,7 @@
        wakeup(&sc->rchan);
 
        /* locate the major number */
-       for (maj = 0; maj < nchrdev; maj++)
-               if (cdevsw[maj].d_open == midiopen)
-                       break;
+       maj = cdevsw_lookup_major(&midi_cdevsw);
 
        /* Nuke the vnodes for any open instances (calls close). */
        mn = self->dv_unit;
diff -r d93e1c4ec6c0 -r 1832f2162dd2 sys/dev/sequencer.c
--- a/sys/dev/sequencer.c       Thu May 16 04:49:35 2002 +0000
+++ b/sys/dev/sequencer.c       Thu May 16 04:52:05 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sequencer.c,v 1.19 2002/01/13 19:28:08 tsutsui Exp $   */
+/*     $NetBSD: sequencer.c,v 1.19.8.1 2002/05/16 04:52:05 gehenna Exp $       */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sequencer.c,v 1.19 2002/01/13 19:28:08 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sequencer.c,v 1.19.8.1 2002/05/16 04:52:05 gehenna Exp $");
 
 #include "sequencer.h"
 
@@ -149,6 +149,18 @@
 int midiseq_putc __P((struct midi_dev *, int));
 void midiseq_in __P((struct midi_dev *, u_char *, int));
 
+dev_type_open(sequenceropen);
+dev_type_close(sequencerclose);
+dev_type_read(sequencerread);



Home | Main Index | Thread Index | Old Index