CVS commit: [netbsd-9] src/sys/dev/audio

2019-11-19 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Nov 19 12:58:30 UTC 2019

Modified Files:
src/sys/dev/audio [netbsd-9]: audio.c

Log Message:
Pull up following revision(s) (requested by isaki in ticket #448):

sys/dev/audio/audio.c: revision 1.33

Fix a wrong calculation of recording ring buffer.  Reported on
http://mail-index.netbsd.org/current-users/2019/11/04/msg036976.html


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.3 -r1.28.2.4 src/sys/dev/audio/audio.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/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.28.2.3 src/sys/dev/audio/audio.c:1.28.2.4
--- src/sys/dev/audio/audio.c:1.28.2.3	Sun Oct  6 11:02:32 2019
+++ src/sys/dev/audio/audio.c	Tue Nov 19 12:58:29 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.3 2019/10/06 11:02:32 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.4 2019/11/19 12:58:29 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.3 2019/10/06 11:02:32 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.4 2019/11/19 12:58:29 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -4510,7 +4510,7 @@ audio_track_record(audio_track_t *track)
 		int bytes1;
 		int bytes2;
 
-		bytes1 = auring_get_contig_used(usrbuf);
+		bytes1 = auring_get_contig_free(usrbuf);
 		KASSERT(bytes1 % framesize == 0);
 		memcpy((uint8_t *)usrbuf->mem + auring_tail(usrbuf),
 		(uint8_t *)outbuf->mem + outbuf->head * framesize,



CVS commit: [netbsd-9] src/sys/dev/audio

2019-11-19 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Nov 19 12:58:30 UTC 2019

Modified Files:
src/sys/dev/audio [netbsd-9]: audio.c

Log Message:
Pull up following revision(s) (requested by isaki in ticket #448):

sys/dev/audio/audio.c: revision 1.33

Fix a wrong calculation of recording ring buffer.  Reported on
http://mail-index.netbsd.org/current-users/2019/11/04/msg036976.html


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.3 -r1.28.2.4 src/sys/dev/audio/audio.c

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



CVS commit: [netbsd-9] src/sys/dev/audio

2019-10-06 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Oct  6 11:02:32 UTC 2019

Modified Files:
src/sys/dev/audio [netbsd-9]: audio.c

Log Message:
Pull up following revision(s) (requested by isaki in ticket #286):

sys/dev/audio/audio.c: revision 1.31

Tune some debug message level.
These messages are important for debugging hardware driver.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.2 -r1.28.2.3 src/sys/dev/audio/audio.c

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



CVS commit: [netbsd-9] src/sys/dev/audio

2019-10-06 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Oct  6 11:02:32 UTC 2019

Modified Files:
src/sys/dev/audio [netbsd-9]: audio.c

Log Message:
Pull up following revision(s) (requested by isaki in ticket #286):

sys/dev/audio/audio.c: revision 1.31

Tune some debug message level.
These messages are important for debugging hardware driver.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.2 -r1.28.2.3 src/sys/dev/audio/audio.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/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.28.2.2 src/sys/dev/audio/audio.c:1.28.2.3
--- src/sys/dev/audio/audio.c:1.28.2.2	Sun Oct  6 11:00:15 2019
+++ src/sys/dev/audio/audio.c	Sun Oct  6 11:02:32 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.2 2019/10/06 11:00:15 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.3 2019/10/06 11:02:32 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.2 2019/10/06 11:00:15 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.3 2019/10/06 11:02:32 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -4621,7 +4621,7 @@ audio_mixer_init(struct audio_softc *sc,
 		audio_params_t p = format2_to_params(>hwbuf.fmt);
 		rounded = sc->hw_if->round_blocksize(sc->hw_hdl, blksize,
 		mode, );
-		TRACE(2, "round_blocksize %d -> %d", blksize, rounded);
+		TRACE(1, "round_blocksize %d -> %d", blksize, rounded);
 		if (rounded != blksize) {
 			if ((rounded * NBBY) % (mixer->hwbuf.fmt.stride *
 			mixer->hwbuf.fmt.channels) != 0) {
@@ -4646,7 +4646,7 @@ audio_mixer_init(struct audio_softc *sc,
 		size_t rounded;
 		rounded = sc->hw_if->round_buffersize(sc->hw_hdl, mode,
 		bufsize);
-		TRACE(2, "round_buffersize %zd -> %zd", bufsize, rounded);
+		TRACE(1, "round_buffersize %zd -> %zd", bufsize, rounded);
 		if (rounded < bufsize) {
 			/* buffersize needs NBLKHW blocks at least. */
 			device_printf(sc->sc_dev,
@@ -4669,7 +4669,7 @@ audio_mixer_init(struct audio_softc *sc,
 			capacity = mixer->frames_per_block * hwblks;
 		}
 	}
-	TRACE(2, "buffersize for %s = %zu",
+	TRACE(1, "buffersize for %s = %zu",
 	(mode == AUMODE_PLAY) ? "playback" : "recording",
 	bufsize);
 	mixer->hwbuf.capacity = capacity;



CVS commit: [netbsd-9] src/sys/dev/audio

2019-10-06 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Oct  6 11:00:15 UTC 2019

Modified Files:
src/sys/dev/audio [netbsd-9]: audio.c audiovar.h

Log Message:
Pull up following revision(s) (requested by isaki in ticket #285):

sys/dev/audio/audiovar.h: revision 1.5
sys/dev/audio/audio.c: revision 1.30

Fix lock assertion on async I/O mode.
psignal() must be called without any spin locks.
Thanks maxv@!


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.1 -r1.28.2.2 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.4 -r1.4.2.1 src/sys/dev/audio/audiovar.h

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



CVS commit: [netbsd-9] src/sys/dev/audio

2019-10-06 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Oct  6 11:00:15 UTC 2019

Modified Files:
src/sys/dev/audio [netbsd-9]: audio.c audiovar.h

Log Message:
Pull up following revision(s) (requested by isaki in ticket #285):

sys/dev/audio/audiovar.h: revision 1.5
sys/dev/audio/audio.c: revision 1.30

Fix lock assertion on async I/O mode.
psignal() must be called without any spin locks.
Thanks maxv@!


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.1 -r1.28.2.2 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.4 -r1.4.2.1 src/sys/dev/audio/audiovar.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/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.28.2.1 src/sys/dev/audio/audio.c:1.28.2.2
--- src/sys/dev/audio/audio.c:1.28.2.1	Sun Oct  6 10:58:14 2019
+++ src/sys/dev/audio/audio.c	Sun Oct  6 11:00:15 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.1 2019/10/06 10:58:14 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.2 2019/10/06 11:00:15 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.1 2019/10/06 10:58:14 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.2 2019/10/06 11:00:15 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -5730,6 +5730,36 @@ audio_track_drain(struct audio_softc *sc
 }
 
 /*
+ * Send signal to process.
+ * This is intended to be called only from audio_softintr_{rd,wr}.
+ * Must be called with sc_lock && sc_intr_lock held.
+ */
+static inline void
+audio_psignal(struct audio_softc *sc, pid_t pid, int signum)
+{
+	proc_t *p;
+
+	KASSERT(mutex_owned(sc->sc_lock));
+	KASSERT(mutex_owned(sc->sc_intr_lock));
+	KASSERT(pid != 0);
+
+	/*
+	 * psignal() must be called without spin lock held.
+	 * So leave intr_lock temporarily here.
+	 */
+	mutex_exit(sc->sc_intr_lock);
+
+	mutex_enter(proc_lock);
+	p = proc_find(pid);
+	if (p)
+		psignal(p, signum);
+	mutex_exit(proc_lock);
+
+	/* Enter intr_lock again */
+	mutex_enter(sc->sc_intr_lock);
+}
+
+/*
  * This is software interrupt handler for record.
  * It is called from recording hardware interrupt everytime.
  * It does:
@@ -5747,7 +5777,6 @@ audio_softintr_rd(void *cookie)
 {
 	struct audio_softc *sc = cookie;
 	audio_file_t *f;
-	proc_t *p;
 	pid_t pid;
 
 	mutex_enter(sc->sc_lock);
@@ -5767,10 +5796,7 @@ audio_softintr_rd(void *cookie)
 		pid = f->async_audio;
 		if (pid != 0) {
 			TRACEF(4, f, "sending SIGIO %d", pid);
-			mutex_enter(proc_lock);
-			if ((p = proc_find(pid)) != NULL)
-psignal(p, SIGIO);
-			mutex_exit(proc_lock);
+			audio_psignal(sc, pid, SIGIO);
 		}
 	}
 	mutex_exit(sc->sc_intr_lock);
@@ -5799,7 +5825,6 @@ audio_softintr_wr(void *cookie)
 	struct audio_softc *sc = cookie;
 	audio_file_t *f;
 	bool found;
-	proc_t *p;
 	pid_t pid;
 
 	TRACE(4, "called");
@@ -5826,14 +5851,13 @@ audio_softintr_wr(void *cookie)
 		 */
 		if (track->usrbuf.used <= track->usrbuf_usedlow &&
 		!track->is_pause) {
+			/* For selnotify */
 			found = true;
+			/* For SIGIO */
 			pid = f->async_audio;
 			if (pid != 0) {
 TRACEF(4, f, "sending SIGIO %d", pid);
-mutex_enter(proc_lock);
-if ((p = proc_find(pid)) != NULL)
-	psignal(p, SIGIO);
-mutex_exit(proc_lock);
+audio_psignal(sc, pid, SIGIO);
 			}
 		}
 	}

Index: src/sys/dev/audio/audiovar.h
diff -u src/sys/dev/audio/audiovar.h:1.4 src/sys/dev/audio/audiovar.h:1.4.2.1
--- src/sys/dev/audio/audiovar.h:1.4	Wed Jun 26 06:57:45 2019
+++ src/sys/dev/audio/audiovar.h	Sun Oct  6 11:00:15 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiovar.h,v 1.4 2019/06/26 06:57:45 isaki Exp $	*/
+/*	$NetBSD: audiovar.h,v 1.4.2.1 2019/10/06 11:00:15 martin Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -149,7 +149,8 @@ struct audio_softc {
 
 	/*
 	 * List of opened descriptors.
-	 * Must be protected by sc_intr_lock.
+	 * Must be protected by sc_lock || sc_intr_lock for traversal(FOREACH).
+	 * Must be protected by sc_lock && sc_intr_lock for insertion/removal.
 	 */
 	SLIST_HEAD(, audio_file) sc_files;
 



CVS commit: [netbsd-9] src/sys/dev/audio

2019-10-06 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Oct  6 10:58:15 UTC 2019

Modified Files:
src/sys/dev/audio [netbsd-9]: audio.c

Log Message:
Pull up following revision(s) (requested by isaki in ticket #284):

sys/dev/audio/audio.c: revision 1.29

Add missing mutex, we were hitting a KASSERT.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.28.2.1 src/sys/dev/audio/audio.c

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



CVS commit: [netbsd-9] src/sys/dev/audio

2019-10-06 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Oct  6 10:58:15 UTC 2019

Modified Files:
src/sys/dev/audio [netbsd-9]: audio.c

Log Message:
Pull up following revision(s) (requested by isaki in ticket #284):

sys/dev/audio/audio.c: revision 1.29

Add missing mutex, we were hitting a KASSERT.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.28.2.1 src/sys/dev/audio/audio.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/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.28 src/sys/dev/audio/audio.c:1.28.2.1
--- src/sys/dev/audio/audio.c:1.28	Wed Jul 10 13:26:47 2019
+++ src/sys/dev/audio/audio.c	Sun Oct  6 10:58:14 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28 2019/07/10 13:26:47 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.1 2019/10/06 10:58:14 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28 2019/07/10 13:26:47 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.1 2019/10/06 10:58:14 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -7726,7 +7726,9 @@ mixer_ioctl(struct audio_softc *sc, u_lo
 		} else {
 			ma = NULL;
 		}
+		mutex_enter(sc->sc_lock);
 		mixer_remove(sc);	/* remove old entry */
+		mutex_exit(sc->sc_lock);
 		if (ma != NULL) {
 			ma->next = sc->sc_async_mixer;
 			ma->pid = curproc->p_pid;