Module Name:    src
Committed By:   dyoung
Date:           Tue Apr  7 22:30:09 UTC 2009

Modified Files:
        src/sys/dev/ic: attimer.c attimervar.h
        src/sys/dev/isa: pcppi.c

Log Message:
Make pcppi(4) detach the "speaker" from attimer(4), so that the
corresponding attimer(4) resource is not perpetually busy: now it
is possible to detach and to reattach pcppi(4).  Make attimer(4)'s
device-detachment hook return EBUSY if pcppi(4) is still attached, so
that pcppi(4) cannot end up with a dangling pointer to attimer(4).


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/ic/attimer.c
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/ic/attimervar.h
cvs rdiff -u -r1.33 -r1.34 src/sys/dev/isa/pcppi.c

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

Modified files:

Index: src/sys/dev/ic/attimer.c
diff -u src/sys/dev/ic/attimer.c:1.9 src/sys/dev/ic/attimer.c:1.10
--- src/sys/dev/ic/attimer.c:1.9	Thu Jun 12 22:30:30 2008
+++ src/sys/dev/ic/attimer.c	Tue Apr  7 22:30:09 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: attimer.c,v 1.9 2008/06/12 22:30:30 cegger Exp $	*/
+/*	$NetBSD: attimer.c,v 1.10 2009/04/07 22:30:09 dyoung Exp $	*/
 
 /*
  *  Copyright (c) 2005 The NetBSD Foundation.
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: attimer.c,v 1.9 2008/06/12 22:30:30 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: attimer.c,v 1.10 2009/04/07 22:30:09 dyoung Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -62,6 +62,9 @@
 attimer_detach(device_t self, int flags)
 {
 	struct attimer_softc *sc = device_private(self);
+	
+	if ((sc->sc_flags & ATT_ATTACHED) != 0)
+		return EBUSY;
 
 	pmf_device_deregister(self);
 	sc->sc_flags &= ~ATT_CONFIGURED;
@@ -98,6 +101,14 @@
 }
 
 void
+attimer_detach_speaker(device_t dev)
+{
+	struct attimer_softc *sc = device_private(dev);
+
+	sc->sc_flags &= ~ATT_ATTACHED;
+}
+
+void
 attimer_set_pitch(device_t dev, int pitch)
 {
 	struct attimer_softc *sc = device_private(dev);

Index: src/sys/dev/ic/attimervar.h
diff -u src/sys/dev/ic/attimervar.h:1.6 src/sys/dev/ic/attimervar.h:1.7
--- src/sys/dev/ic/attimervar.h:1.6	Tue Apr 29 06:53:02 2008
+++ src/sys/dev/ic/attimervar.h	Tue Apr  7 22:30:09 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: attimervar.h,v 1.6 2008/04/29 06:53:02 martin Exp $	*/
+/*	$NetBSD: attimervar.h,v 1.7 2009/04/07 22:30:09 dyoung Exp $	*/
 
 /*
  *  Copyright (c) 2005 The NetBSD Foundation.
@@ -39,4 +39,5 @@
 void		attimer_attach(struct attimer_softc *);
 int		attimer_detach(device_t, int);
 device_t	attimer_attach_speaker(void);
+void		attimer_detach_speaker(device_t);
 void		attimer_set_pitch(device_t, int);

Index: src/sys/dev/isa/pcppi.c
diff -u src/sys/dev/isa/pcppi.c:1.33 src/sys/dev/isa/pcppi.c:1.34
--- src/sys/dev/isa/pcppi.c:1.33	Sat Mar 14 11:08:28 2009
+++ src/sys/dev/isa/pcppi.c	Tue Apr  7 22:30:09 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: pcppi.c,v 1.33 2009/03/14 11:08:28 ad Exp $ */
+/* $NetBSD: pcppi.c,v 1.34 2009/04/07 22:30:09 dyoung Exp $ */
 
 /*
  * Copyright (c) 1996 Carnegie-Mellon University.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pcppi.c,v 1.33 2009/03/14 11:08:28 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pcppi.c,v 1.34 2009/04/07 22:30:09 dyoung Exp $");
 
 #include "attimer.h"
 
@@ -68,6 +68,7 @@
 
 #if NATTIMER > 0
 static void pcppi_attach_speaker(device_t);
+static void pcppi_detach_speaker(struct pcppi_softc *);
 #endif
 
 #define PCPPIPRI (PZERO - 1)
@@ -180,6 +181,10 @@
 	int rc;
 	struct pcppi_softc *sc = device_private(self);
 
+#if NATTIMER > 0
+	pcppi_detach_speaker(sc);
+#endif
+
 	if ((rc = config_detach_children(sc->sc_dv, flags)) != 0)
 		return rc;
 
@@ -234,6 +239,15 @@
 
 #if NATTIMER > 0
 static void
+pcppi_detach_speaker(struct pcppi_softc *sc)
+{
+	if (sc->sc_timer != NULL) {
+		attimer_detach_speaker(sc->sc_timer);
+		sc->sc_timer = NULL;
+	}
+}
+
+static void
 pcppi_attach_speaker(device_t self)
 {
 	struct pcppi_softc *sc = device_private(self);

Reply via email to