Module Name:    src
Committed By:   mrg
Date:           Sun Nov 20 12:08:19 UTC 2011

Modified Files:
        src/sys/dev/isa [jmcneill-audiomp3]: pcppi.c pcppivar.h

Log Message:
port the changes from ad-audiomp2 branch.  this mostly replaces the
changes i'd made to pcppi to achieve a similar result.

XXX: these actually could be pulled down to -current today, i think.
no actual dependancies on audiomp branch itself.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.37.6.1 src/sys/dev/isa/pcppi.c
cvs rdiff -u -r1.10.6.1 -r1.10.6.2 src/sys/dev/isa/pcppivar.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/dev/isa/pcppi.c
diff -u src/sys/dev/isa/pcppi.c:1.37 src/sys/dev/isa/pcppi.c:1.37.6.1
--- src/sys/dev/isa/pcppi.c:1.37	Tue May 24 09:28:03 2011
+++ src/sys/dev/isa/pcppi.c	Sun Nov 20 12:08:19 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: pcppi.c,v 1.37 2011/05/24 09:28:03 mrg Exp $ */
+/* $NetBSD: pcppi.c,v 1.37.6.1 2011/11/20 12:08:19 mrg Exp $ */
 
 /*
  * Copyright (c) 1996 Carnegie-Mellon University.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pcppi.c,v 1.37 2011/05/24 09:28:03 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pcppi.c,v 1.37.6.1 2011/11/20 12:08:19 mrg Exp $");
 
 #include "attimer.h"
 
@@ -42,6 +42,7 @@ __KERNEL_RCSID(0, "$NetBSD: pcppi.c,v 1.
 #include <sys/bus.h>
 #include <sys/mutex.h>
 #include <sys/condvar.h>
+#include <sys/tty.h>
 
 #include <dev/ic/attimervar.h>
 
@@ -66,16 +67,14 @@ CFATTACH_DECL3_NEW(pcppi, sizeof(struct 
     DVF_DETACH_SHUTDOWN);
 
 static int pcppisearch(device_t, cfdata_t, const int *, void *);
-static void pcppi_bell_stop_unlocked(void*);
-static void pcppi_bell_stop(void*);
+static void pcppi_bell_stop(struct pcppi_softc *);
+static void pcppi_bell_callout(void *);
 
 #if NATTIMER > 0
 static void pcppi_attach_speaker(device_t);
 static void pcppi_detach_speaker(struct pcppi_softc *);
 #endif
 
-#define PCPPIPRI (PZERO - 1)
-
 int
 pcppi_match(device_t parent, cfdata_t match, void *aux)
 {
@@ -175,6 +174,7 @@ pcppi_isa_attach(device_t parent, device
 void
 pcppi_childdet(device_t self, device_t child)
 {
+
 	/* we hold no child references, so do nothing */
 }
 
@@ -196,14 +196,16 @@ pcppi_detach(device_t self, int flags)
 #if NPCKBD > 0
 	pckbd_unhook_bell(pcppi_pckbd_bell, sc);
 #endif
+	mutex_spin_enter(&tty_lock);
 	pcppi_bell_stop(sc);
+	mutex_spin_exit(&tty_lock);
 
-	callout_stop(&sc->sc_bell_ch);
+	callout_halt(&sc->sc_bell_ch, NULL);
 	callout_destroy(&sc->sc_bell_ch);
-	bus_space_unmap(sc->sc_iot, sc->sc_ppi_ioh, sc->sc_size);
 
-	mutex_destroy(&sc->sc_lock);
-	cv_destroy(&sc->sc_stop_cv);
+	cv_destroy(&sc->sc_slp);
+
+	bus_space_unmap(sc->sc_iot, sc->sc_ppi_ioh, sc->sc_size);
 
 	return 0;
 }
@@ -214,12 +216,11 @@ pcppi_attach(struct pcppi_softc *sc)
         struct pcppi_attach_args pa;
 	device_t self = sc->sc_dv;
 
-        callout_init(&sc->sc_bell_ch, 0);
-
-        sc->sc_bellactive = sc->sc_bellpitch = sc->sc_slp = 0;
+	callout_init(&sc->sc_bell_ch, CALLOUT_MPSAFE);
+	callout_setfunc(&sc->sc_bell_ch, pcppi_bell_callout, sc);
+	cv_init(&sc->sc_slp, "bell");
 
-	mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_VM);
-	cv_init(&sc->sc_stop_cv, "bell");
+        sc->sc_bellactive = sc->sc_bellpitch = 0;
 
 #if NPCKBD > 0
 	/* Provide a beeper for the PC Keyboard, if there isn't one already. */
@@ -274,21 +275,27 @@ pcppi_attach_speaker(device_t self)
 void
 pcppi_bell(pcppi_tag_t self, int pitch, int period, int slp)
 {
+
+	mutex_spin_enter(&tty_lock);
+	pcppi_bell_locked(self, pitch, period, slp);
+	mutex_spin_exit(&tty_lock);
+}
+
+void
+pcppi_bell_locked(pcppi_tag_t self, int pitch, int period, int slp)
+{
 	struct pcppi_softc *sc = self;
 
-	mutex_enter(&sc->sc_lock);
 	if (sc->sc_bellactive) {
 		if (sc->sc_timeout) {
 			sc->sc_timeout = 0;
 			callout_stop(&sc->sc_bell_ch);
 		}
-		if (sc->sc_slp)
-			cv_broadcast(&sc->sc_stop_cv);
+		cv_broadcast(&sc->sc_slp);
 	}
 	if (pitch == 0 || period == 0) {
-		pcppi_bell_stop_unlocked(sc);
+		pcppi_bell_stop(sc);
 		sc->sc_bellpitch = 0;
-		mutex_exit(&sc->sc_lock);
 		return;
 	}
 	if (!sc->sc_bellactive || sc->sc_bellpitch != pitch) {
@@ -306,24 +313,32 @@ pcppi_bell(pcppi_tag_t self, int pitch, 
 	sc->sc_bellactive = 1;
 	if (slp & PCPPI_BELL_POLL) {
 		delay((period * 1000000) / hz);
-		pcppi_bell_stop_unlocked(sc);
+		pcppi_bell_stop(sc);
 	} else {
 		sc->sc_timeout = 1;
-		callout_reset(&sc->sc_bell_ch, period, pcppi_bell_stop, sc);
+		callout_schedule(&sc->sc_bell_ch, period);
 		if (slp & PCPPI_BELL_SLEEP) {
-			sc->sc_slp = 1;
-			cv_wait_sig(&sc->sc_stop_cv, &sc->sc_lock);
-			sc->sc_slp = 0;
+			cv_wait_sig(&sc->sc_slp, &tty_lock);
 		}
 	}
-	mutex_exit(&sc->sc_lock);
 }
 
 static void
-pcppi_bell_stop_unlocked(void *arg)
+pcppi_bell_callout(void *arg)
 {
 	struct pcppi_softc *sc = arg;
 
+	mutex_spin_enter(&tty_lock);
+	if (sc->sc_timeout != 0) {
+		pcppi_bell_stop(sc);
+	}
+	mutex_spin_exit(&tty_lock);
+}
+
+static void
+pcppi_bell_stop(struct pcppi_softc *sc)
+{
+
 	sc->sc_timeout = 0;
 
 	/* disable bell */
@@ -331,18 +346,7 @@ pcppi_bell_stop_unlocked(void *arg)
 			  bus_space_read_1(sc->sc_iot, sc->sc_ppi_ioh, 0)
 			  & ~PIT_SPKR);
 	sc->sc_bellactive = 0;
-	if (sc->sc_slp)
-		cv_broadcast(&sc->sc_stop_cv);
-}
-
-static void
-pcppi_bell_stop(void *arg)
-{
-	struct pcppi_softc *sc = arg;
-
-	mutex_enter(&sc->sc_lock);
-	pcppi_bell_stop_unlocked(arg);
-	mutex_exit(&sc->sc_lock);
+	cv_broadcast(&sc->sc_slp);
 }
 
 #if NPCKBD > 0
@@ -351,10 +355,12 @@ pcppi_pckbd_bell(void *arg, u_int pitch,
     int poll)
 {
 
+	KASSERT(mutex_owned(&tty_lock));
+
 	/*
 	 * Comes in as ms, goes out at ticks; volume ignored.
 	 */
-	pcppi_bell(arg, pitch, (period * hz) / 1000,
+	pcppi_bell_locked(arg, pitch, (period * hz) / 1000,
 	    poll ? PCPPI_BELL_POLL : 0);
 }
 #endif /* NPCKBD > 0 */

Index: src/sys/dev/isa/pcppivar.h
diff -u src/sys/dev/isa/pcppivar.h:1.10.6.1 src/sys/dev/isa/pcppivar.h:1.10.6.2
--- src/sys/dev/isa/pcppivar.h:1.10.6.1	Sat Nov 19 21:49:38 2011
+++ src/sys/dev/isa/pcppivar.h	Sun Nov 20 12:08:19 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: pcppivar.h,v 1.10.6.1 2011/11/19 21:49:38 jmcneill Exp $ */
+/* $NetBSD: pcppivar.h,v 1.10.6.2 2011/11/20 12:08:19 mrg Exp $ */
 
 /*
  * Copyright (c) 1996 Carnegie-Mellon University.
@@ -44,14 +44,11 @@ struct pcppi_softc {
 	bus_size_t sc_size;
 	device_t sc_timer;
         
-	struct callout sc_bell_ch;
-
 	int sc_bellactive, sc_bellpitch;
-	int sc_slp;
 	int sc_timeout;
 
-	kmutex_t sc_lock;
-	kcondvar_t sc_stop_cv;
+	kcondvar_t sc_slp;
+	callout_t sc_bell_ch;
 };
 
 void pcppi_attach(struct pcppi_softc *);

Reply via email to