Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/pmax/tc - split device_t/softc



details:   https://anonhg.NetBSD.org/src/rev/4c8d1ebd092d
branches:  trunk
changeset: 765725:4c8d1ebd092d
user:      tsutsui <tsutsui%NetBSD.org@localhost>
date:      Sat Jun 04 01:37:36 2011 +0000

description:
- split device_t/softc
- make sure that *(dtdv_handler)() registered via dt_establish_handler()
  takes softc, not device_t as other interrupt handlers

No crash during device attach on GXemul.

diffstat:

 sys/arch/pmax/tc/dt.c    |  36 ++++++++++++++++++------------------
 sys/arch/pmax/tc/dtkbd.c |  29 +++++++++++++++--------------
 sys/arch/pmax/tc/dtms.c  |  27 ++++++++++++++-------------
 sys/arch/pmax/tc/dtvar.h |   8 ++++----
 4 files changed, 51 insertions(+), 49 deletions(-)

diffs (truncated from 338 to 300 lines):

diff -r d473d1515f7e -r 4c8d1ebd092d sys/arch/pmax/tc/dt.c
--- a/sys/arch/pmax/tc/dt.c     Sat Jun 04 01:31:23 2011 +0000
+++ b/sys/arch/pmax/tc/dt.c     Sat Jun 04 01:37:36 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dt.c,v 1.10 2008/04/28 20:23:31 martin Exp $   */
+/*     $NetBSD: dt.c,v 1.11 2011/06/04 01:37:36 tsutsui Exp $  */
 
 /*-
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dt.c,v 1.10 2008/04/28 20:23:31 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dt.c,v 1.11 2011/06/04 01:37:36 tsutsui Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -168,10 +168,9 @@
 #define        DT_RX_AVAIL(poll)       ((*(poll) & 1) != 0)
 #define        DT_TX_AVAIL(poll)       ((*(poll) & 2) != 0)
 
-int    dt_match(struct device *, struct cfdata *, void *);
-void   dt_attach(struct device *, struct device *, void *);
+int    dt_match(device_t, cfdata_t, void *);
+void   dt_attach(device_t, device_t, void *);
 int    dt_intr(void *);
-int    dt_null_handler(struct device *, struct dt_msg *, int);
 int    dt_print(void *, const char *);
 void   dt_strvis(uint8_t *, char *, int);
 void   dt_dispatch(void *);
@@ -182,11 +181,11 @@
 struct dt_device dt_ms_dv;
 struct dt_state dt_state;
 
-CFATTACH_DECL(dt, sizeof(struct dt_softc),
+CFATTACH_DECL_NEW(dt, sizeof(struct dt_softc),
     dt_match, dt_attach, NULL, NULL);
 
 int
-dt_match(struct device *parent, struct cfdata *match, void *aux)
+dt_match(device_t parent, cfdata_t cf, void *aux)
 {
        struct ioasicdev_attach_args *d;
 
@@ -202,7 +201,7 @@
 }
 
 void
-dt_attach(struct device *parent, struct device *self, void *aux)
+dt_attach(device_t parent, device_t self, void *aux)
 {
        struct ioasicdev_attach_args *d;
        struct dt_attach_args dta;
@@ -211,19 +210,20 @@
        int i;
 
        d = aux;
-       sc = (struct dt_softc*)self;
+       sc = device_private(self);
+       sc->sc_dev = self;
 
        dt_cninit();
 
        msg = malloc(sizeof(*msg) * DT_BUF_CNT, M_DEVBUF, M_NOWAIT);
        if (msg == NULL) {
-               printf("%s: memory exhausted\n", sc->sc_dv.dv_xname);
+               printf("%s: memory exhausted\n", device_xname(self));
                return;
        }
 
        sc->sc_sih = softint_establish(SOFTINT_SERIAL, dt_dispatch, sc);
        if (sc->sc_sih == NULL) {
-               printf("%s: memory exhausted\n", sc->sc_dv.dv_xname);
+               printf("%s: memory exhausted\n", device_xname(self));
                free(msg, M_DEVBUF);
        }
 
@@ -260,10 +260,10 @@
 
 int
 dt_establish_handler(struct dt_softc *sc, struct dt_device *dtdv,
-    struct device *dv, void (*hdlr)(void *, struct dt_msg *))
+    void *arg, void (*hdlr)(void *, struct dt_msg *))
 {
 
-       dtdv->dtdv_dv = dv;
+       dtdv->dtdv_arg = arg;
        dtdv->dtdv_handler = hdlr;
        return (0);
 }
@@ -289,7 +289,7 @@
                sc->sc_msg.body[0] = DT_KBD_EMPTY;
 #ifdef DIAGNOSTIC
                printf("%s: data overrun or stray interrupt\n",
-                   sc->sc_dv.dv_xname);
+                   device_xname(sc->sc_dev));
 #endif
                break;
 
@@ -301,7 +301,7 @@
        }
 
        if ((msg = SLIST_FIRST(&sc->sc_free)) == NULL) {
-               printf("%s: input overflow\n", sc->sc_dv.dv_xname);
+               printf("%s: input overflow\n", device_xname(sc->sc_dev));
                return (1);
        }
        SLIST_REMOVE_HEAD(&sc->sc_free, chain.slist);
@@ -339,13 +339,13 @@
 
                if (msg->src != DT_ADDR_MOUSE && msg->src != DT_ADDR_KBD) {
                        printf("%s: message from unknown dev 0x%x\n",
-                           sc->sc_dv.dv_xname, sc->sc_msg.src);
+                           device_xname(sc->sc_dev), sc->sc_msg.src);
                        dt_msg_dump(msg);
                        continue;
                }
                if (DT_CTL_P(msg->ctl) != 0) {
                        printf("%s: received control message\n",
-                           sc->sc_dv.dv_xname);
+                           device_xname(sc->sc_dev));
                        dt_msg_dump(msg);
                        continue;
                }
@@ -375,7 +375,7 @@
                        dtdv = &dt_ms_dv;
 
                if (dtdv->dtdv_handler != NULL)
-                       (*dtdv->dtdv_handler)(dtdv->dtdv_dv, msg);
+                       (*dtdv->dtdv_handler)(dtdv->dtdv_arg, msg);
        }
 }
 
diff -r d473d1515f7e -r 4c8d1ebd092d sys/arch/pmax/tc/dtkbd.c
--- a/sys/arch/pmax/tc/dtkbd.c  Sat Jun 04 01:31:23 2011 +0000
+++ b/sys/arch/pmax/tc/dtkbd.c  Sat Jun 04 01:37:36 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dtkbd.c,v 1.8 2008/04/28 20:23:31 martin Exp $ */
+/*     $NetBSD: dtkbd.c,v 1.9 2011/06/04 01:37:36 tsutsui Exp $        */
 
 /*-
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dtkbd.c,v 1.8 2008/04/28 20:23:31 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dtkbd.c,v 1.9 2011/06/04 01:37:36 tsutsui Exp $");
 
 #include "locators.h"
 
@@ -55,13 +55,13 @@
 #include <pmax/pmax/cons.h>
 
 struct dtkbd_softc {
-       struct device   sc_dv;
-       struct device   *sc_wskbddev;
+       device_t        sc_dev;
+       device_t        sc_wskbddev;
        int             sc_enabled;
 };
 
-int    dtkbd_match(struct device *, struct cfdata *, void *);
-void   dtkbd_attach(struct device *, struct device *, void *);
+int    dtkbd_match(device_t, cfdata_t, void *);
+void   dtkbd_attach(device_t, device_t, void *);
 int    dtkbd_enable(void *, int);
 int    dtkbd_ioctl(void *, u_long, void *, int, struct lwp *);
 void   dtkbd_cngetc(void *, u_int *, int *);
@@ -81,7 +81,7 @@
        dtkbd_cnpollc,
 };
 
-CFATTACH_DECL(dtkbd, sizeof(struct dtkbd_softc),
+CFATTACH_DECL_NEW(dtkbd, sizeof(struct dtkbd_softc),
     dtkbd_match, dtkbd_attach, NULL, NULL);
 
 const struct wskbd_mapdata dtkbd_keymapdata = {
@@ -98,7 +98,7 @@
 int    dtkbd_maplen;
 
 int
-dtkbd_match(struct device *parent, struct cfdata *cf, void *aux)
+dtkbd_match(device_t parent, cfdata_t cf, void *aux)
 {
        struct dt_attach_args *dta;
 
@@ -107,19 +107,20 @@
 }
 
 void
-dtkbd_attach(struct device *parent, struct device *self, void *aux)
+dtkbd_attach(device_t parent, device_t self, void *aux)
 {
        struct dt_softc *dt;
        struct dtkbd_softc *sc;
        struct wskbddev_attach_args a;
 
-       dt = (struct dt_softc *)parent;
-       sc = (struct dtkbd_softc *)self;
+       dt = device_private(parent);
+       sc = device_private(self);
+       sc->sc_dev = self;
 
        printf("\n");
 
-       if (dt_establish_handler(dt, &dt_kbd_dv, self, dtkbd_handler)) {
-               printf("%s: unable to establish handler\n", self->dv_xname);
+       if (dt_establish_handler(dt, &dt_kbd_dv, sc, dtkbd_handler)) {
+               printf("%s: unable to establish handler\n", device_xname(self));
                return;
        }
 
@@ -189,7 +190,7 @@
 {
        struct dtkbd_softc *sc;
 
-       sc = (struct dtkbd_softc *)v;
+       sc = v;
 
        switch (cmd) {
        case WSKBDIO_GTYPE:
diff -r d473d1515f7e -r 4c8d1ebd092d sys/arch/pmax/tc/dtms.c
--- a/sys/arch/pmax/tc/dtms.c   Sat Jun 04 01:31:23 2011 +0000
+++ b/sys/arch/pmax/tc/dtms.c   Sat Jun 04 01:37:36 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dtms.c,v 1.9 2008/04/28 20:23:32 martin Exp $  */
+/*     $NetBSD: dtms.c,v 1.10 2011/06/04 01:37:36 tsutsui Exp $        */
 
 /*-
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dtms.c,v 1.9 2008/04/28 20:23:32 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dtms.c,v 1.10 2011/06/04 01:37:36 tsutsui Exp $");
 
 #include "locators.h"
 
@@ -49,20 +49,20 @@
 #include <dev/wscons/wsmousevar.h>
 
 struct dtms_softc {
-       struct device   sc_dv;
-       struct device   *sc_wsmousedev;
+       device_t        sc_dev;
+       device_t        sc_wsmousedev;
        int             sc_enabled;
 };
 
-int    dtms_match(struct device *, struct cfdata *, void *);
-void   dtms_attach(struct device *, struct device *, void *);
+int    dtms_match(device_t, cfdata_t, void *);
+void   dtms_attach(device_t, device_t, void *);
 int    dtms_input(void *, int);
 int    dtms_enable(void *);
 int    dtms_ioctl(void *, u_long, void *, int, struct lwp *);
 void   dtms_disable(void *);
 void   dtms_handler(void *, struct dt_msg *);
 
-CFATTACH_DECL(dtms, sizeof(struct dtms_softc),
+CFATTACH_DECL_NEW(dtms, sizeof(struct dtms_softc),
     dtms_match, dtms_attach, NULL, NULL);
 
 const struct wsmouse_accessops dtms_accessops = {
@@ -72,7 +72,7 @@
 };
 
 int
-dtms_match(struct device *parent, struct cfdata *cf, void *aux)
+dtms_match(device_t parent, cfdata_t cf, void *aux)
 {
        struct dt_attach_args *dta;
 
@@ -81,19 +81,20 @@
 }
 
 void
-dtms_attach(struct device *parent, struct device *self, void *aux)
+dtms_attach(device_t parent, device_t self, void *aux)
 {
        struct wsmousedev_attach_args a;
        struct dtms_softc *sc;
        struct dt_softc *dt;
 
-       dt = (struct dt_softc *)parent;
-       sc = (struct dtms_softc *)self;
+       dt = device_private(parent);
+       sc = device_private(self);
+       sc->sc_dev = self;
 
        printf("\n");
 
-       if (dt_establish_handler(dt, &dt_ms_dv, self, dtms_handler)) {
-               printf("%s: unable to establish handler\n", self->dv_xname);
+       if (dt_establish_handler(dt, &dt_ms_dv, sc, dtms_handler)) {
+               printf("%s: unable to establish handler\n", device_xname(self));
                return;



Home | Main Index | Thread Index | Old Index