Module Name:    src
Committed By:   tsutsui
Date:           Sat Jun  4 01:37:36 UTC 2011

Modified Files:
        src/sys/arch/pmax/tc: dt.c dtkbd.c dtms.c dtvar.h

Log Message:
- 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.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/pmax/tc/dt.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/pmax/tc/dtkbd.c
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/pmax/tc/dtms.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/pmax/tc/dtvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/pmax/tc/dt.c
diff -u src/sys/arch/pmax/tc/dt.c:1.10 src/sys/arch/pmax/tc/dt.c:1.11
--- src/sys/arch/pmax/tc/dt.c:1.10	Mon Apr 28 20:23:31 2008
+++ src/sys/arch/pmax/tc/dt.c	Sat Jun  4 01:37:36 2011
@@ -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);
 	}
 }
 

Index: src/sys/arch/pmax/tc/dtkbd.c
diff -u src/sys/arch/pmax/tc/dtkbd.c:1.8 src/sys/arch/pmax/tc/dtkbd.c:1.9
--- src/sys/arch/pmax/tc/dtkbd.c:1.8	Mon Apr 28 20:23:31 2008
+++ src/sys/arch/pmax/tc/dtkbd.c	Sat Jun  4 01:37:36 2011
@@ -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:

Index: src/sys/arch/pmax/tc/dtms.c
diff -u src/sys/arch/pmax/tc/dtms.c:1.9 src/sys/arch/pmax/tc/dtms.c:1.10
--- src/sys/arch/pmax/tc/dtms.c:1.9	Mon Apr 28 20:23:32 2008
+++ src/sys/arch/pmax/tc/dtms.c	Sat Jun  4 01:37:36 2011
@@ -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;
 	}
 

Index: src/sys/arch/pmax/tc/dtvar.h
diff -u src/sys/arch/pmax/tc/dtvar.h:1.5 src/sys/arch/pmax/tc/dtvar.h:1.6
--- src/sys/arch/pmax/tc/dtvar.h:1.5	Mon Apr 28 20:23:32 2008
+++ src/sys/arch/pmax/tc/dtvar.h	Sat Jun  4 01:37:36 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: dtvar.h,v 1.5 2008/04/28 20:23:32 martin Exp $	*/
+/*	$NetBSD: dtvar.h,v 1.6 2011/06/04 01:37:36 tsutsui Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
 #define	DT_CTL_LEN(c)		(c & 0x1f)
 
 struct dt_device {
-	struct	device *dtdv_dv;
+	void	*dtdv_arg;
 	void	(*dtdv_handler)(void *, struct dt_msg *);
 };
 
@@ -71,7 +71,7 @@
 };
 
 struct dt_softc {
-	struct device	sc_dv;
+	device_t	sc_dev;
 	struct dt_msg	sc_msg;
 	void		*sc_sih;
 	SLIST_HEAD(, dt_msg) sc_free;
@@ -91,7 +91,7 @@
 int	dt_msg_get(struct dt_msg *, int);
 void	dt_msg_dump(struct dt_msg *);
 int	dt_establish_handler(struct dt_softc *, struct dt_device *,
-    struct device *, void (*)(void *, struct dt_msg *));
+    void *, void (*)(void *, struct dt_msg *));
 
 extern int	dt_kbd_addr;
 extern struct	dt_device dt_kbd_dv;

Reply via email to