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

2021-07-28 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Wed Jul 28 14:59:02 UTC 2021

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

Log Message:
Pull up following revision(s) (requested by isaki in ticket #1325):
sys/dev/audio/audio.c: revision 1.105
AUDIO_SETINFO: fix a bug that the gain and the balance could not be set
at the same time.  Fix PR kern/56308.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.22 -r1.28.2.23 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.22 src/sys/dev/audio/audio.c:1.28.2.23
--- src/sys/dev/audio/audio.c:1.28.2.22	Wed May  5 17:01:41 2021
+++ src/sys/dev/audio/audio.c	Wed Jul 28 14:59:02 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.22 2021/05/05 17:01:41 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.23 2021/07/28 14:59:02 snj Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.22 2021/05/05 17:01:41 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.23 2021/07/28 14:59:02 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -7381,59 +7381,46 @@ audio_hw_setinfo(struct audio_softc *sc,
 		}
 	}
 
-	/* Backup play.{gain,balance} */
+	/* play.{gain,balance} */
 	if (SPECIFIED(newpi->gain) || SPECIFIED_CH(newpi->balance)) {
 		au_get_gain(sc, >sc_outports, , );
 		if (oldai) {
 			oldpi->gain = pgain;
 			oldpi->balance = pbalance;
 		}
+
+		if (SPECIFIED(newpi->gain))
+			pgain = newpi->gain;
+		if (SPECIFIED_CH(newpi->balance))
+			pbalance = newpi->balance;
+		error = au_set_gain(sc, >sc_outports, pgain, pbalance);
+		if (error) {
+			audio_printf(sc,
+			"setting play.gain=%d/balance=%d failed: "
+			"errno=%d\n",
+			pgain, pbalance, error);
+			goto abort;
+		}
 	}
-	/* Backup record.{gain,balance} */
+
+	/* record.{gain,balance} */
 	if (SPECIFIED(newri->gain) || SPECIFIED_CH(newri->balance)) {
 		au_get_gain(sc, >sc_inports, , );
 		if (oldai) {
 			oldri->gain = rgain;
 			oldri->balance = rbalance;
 		}
-	}
-	if (SPECIFIED(newpi->gain)) {
-		error = au_set_gain(sc, >sc_outports,
-		newpi->gain, pbalance);
-		if (error) {
-			audio_printf(sc,
-			"setting play.gain=%d failed: errno=%d\n",
-			newpi->gain, error);
-			goto abort;
-		}
-	}
-	if (SPECIFIED(newri->gain)) {
-		error = au_set_gain(sc, >sc_inports,
-		newri->gain, rbalance);
-		if (error) {
-			audio_printf(sc,
-			"setting record.gain=%d failed: errno=%d\n",
-			newri->gain, error);
-			goto abort;
-		}
-	}
-	if (SPECIFIED_CH(newpi->balance)) {
-		error = au_set_gain(sc, >sc_outports,
-		pgain, newpi->balance);
-		if (error) {
-			audio_printf(sc,
-			"setting play.balance=%d failed: errno=%d\n",
-			newpi->balance, error);
-			goto abort;
-		}
-	}
-	if (SPECIFIED_CH(newri->balance)) {
-		error = au_set_gain(sc, >sc_inports,
-		rgain, newri->balance);
+
+		if (SPECIFIED(newri->gain))
+			rgain = newri->gain;
+		if (SPECIFIED_CH(newri->balance))
+			rbalance = newri->balance;
+		error = au_set_gain(sc, >sc_inports, rgain, rbalance);
 		if (error) {
 			audio_printf(sc,
-			"setting record.balance=%d failed: errno=%d\n",
-			newri->balance, error);
+			"setting record.gain=%d/balance=%d failed: "
+			"errno=%d\n",
+			rgain, rbalance, error);
 			goto abort;
 		}
 	}



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

2021-07-28 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Wed Jul 28 14:59:02 UTC 2021

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

Log Message:
Pull up following revision(s) (requested by isaki in ticket #1325):
sys/dev/audio/audio.c: revision 1.105
AUDIO_SETINFO: fix a bug that the gain and the balance could not be set
at the same time.  Fix PR kern/56308.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.22 -r1.28.2.23 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

2021-05-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed May  5 17:01:41 UTC 2021

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

Log Message:
Pull up following revision(s) (requested by nia in ticket #1268):

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

audio: Only score hardware formats by channel count at count<=2

Scoring by channel count makes sense when you are using hardware that
supports mono and stereo formats. However, if your hardware also supports
surround formats, defaulting to those might be confusing. So, don't
prefer them.

Problem reported and fix tested by tcmart14 with a 2015 model Macbook Pro.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.21 -r1.28.2.22 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

2021-05-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed May  5 17:01:41 UTC 2021

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

Log Message:
Pull up following revision(s) (requested by nia in ticket #1268):

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

audio: Only score hardware formats by channel count at count<=2

Scoring by channel count makes sense when you are using hardware that
supports mono and stereo formats. However, if your hardware also supports
surround formats, defaulting to those might be confusing. So, don't
prefer them.

Problem reported and fix tested by tcmart14 with a 2015 model Macbook Pro.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.21 -r1.28.2.22 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.21 src/sys/dev/audio/audio.c:1.28.2.22
--- src/sys/dev/audio/audio.c:1.28.2.21	Mon Mar  1 16:00:08 2021
+++ src/sys/dev/audio/audio.c	Wed May  5 17:01:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.21 2021/03/01 16:00:08 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.22 2021/05/05 17:01:41 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.21 2021/03/01 16:00:08 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.22 2021/05/05 17:01:41 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -6566,7 +6566,10 @@ audio_hw_probe(struct audio_softc *sc, a
 		query.fmt.precision == AUDIO_INTERNAL_BITS) {
 			score += 0x10;
 		}
-		score += query.fmt.channels;
+
+		/* Do not prefer surround formats */
+		if (query.fmt.channels <= 2)
+			score += query.fmt.channels;
 
 		if (score < cand_score) {
 			DPRINTF(1, "fmt[%d] skip; score 0x%x < 0x%x\n", i,



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

2021-04-06 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Apr  6 17:44:29 UTC 2021

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

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

sys/dev/audio/audiobell.c: revision 1.4

Fix and improve the buffer length calculation to avoid zero length
even if blk_ms is small.

This fixes PR kern/56059.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.3.2.1 src/sys/dev/audio/audiobell.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/audiobell.c
diff -u src/sys/dev/audio/audiobell.c:1.3 src/sys/dev/audio/audiobell.c:1.3.2.1
--- src/sys/dev/audio/audiobell.c:1.3	Wed Jun 26 06:57:45 2019
+++ src/sys/dev/audio/audiobell.c	Tue Apr  6 17:44:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiobell.c,v 1.3 2019/06/26 06:57:45 isaki Exp $	*/
+/*	$NetBSD: audiobell.c,v 1.3.2.1 2021/04/06 17:44:29 martin Exp $	*/
 
 /*
  * Copyright (c) 1999 Richard Earnshaw
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audiobell.c,v 1.3 2019/06/26 06:57:45 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audiobell.c,v 1.3.2.1 2021/04/06 17:44:29 martin Exp $");
 
 #include 
 #include 
@@ -81,6 +81,13 @@ static const int32_t sinewave[] = {
 #undef A
 
 /*
+ * The minimum and the maximum buffer sizes must be a multiple of 32
+ * (32 = countof(sinewave) * sizeof(uint16_t)).
+ */
+#define MINBUFSIZE	(1024)
+#define MAXBUFSIZE	(4096)
+
+/*
  * dev is a device_t for the audio device to use.
  * pitch is the pitch of the bell in Hz,
  * period is the length in ms,
@@ -102,7 +109,7 @@ audiobell(void *dev, u_int pitch, u_int 
 	u_int remainbytes;
 	u_int wave1count;
 	u_int wave1bytes;
-	u_int blkbytes;
+	u_int bufbytes;
 	u_int len;
 	u_int step;
 	u_int offset;
@@ -111,6 +118,10 @@ audiobell(void *dev, u_int pitch, u_int 
 
 	KASSERT(volume <= 100);
 
+	/* Playing for 0msec does nothing. */
+	if (period == 0)
+		return;
+
 	/* The audio system isn't built for polling. */
 	if (poll)
 		return;
@@ -158,16 +169,23 @@ audiobell(void *dev, u_int pitch, u_int 
 	remainbytes = remaincount * sizeof(int16_t);
 	wave1bytes = wave1count * sizeof(int16_t);
 
-	blkbytes = ptrack->usrbuf_blksize;
-	blkbytes = rounddown(blkbytes, wave1bytes);
-	blkbytes = uimin(blkbytes, remainbytes);
-	buf = malloc(blkbytes, M_TEMP, M_WAITOK);
+	/* Based on 3*usrbuf_blksize, but not too small or too large */
+	bufbytes = ptrack->usrbuf_blksize * NBLKHW;
+	if (bufbytes < MINBUFSIZE)
+		bufbytes = MINBUFSIZE;
+	else if (bufbytes > MAXBUFSIZE)
+		bufbytes = MAXBUFSIZE;
+	else
+		bufbytes = roundup(bufbytes, wave1bytes);
+	bufbytes = uimin(bufbytes, remainbytes);
+	KASSERT(bufbytes != 0);
+	buf = malloc(bufbytes, M_TEMP, M_WAITOK);
 	if (buf == NULL)
 		goto out;
 
 	/* Generate sinewave with specified volume */
 	j = offset;
-	for (i = 0; i < blkbytes / sizeof(int16_t); i++) {
+	for (i = 0; i < bufbytes / sizeof(int16_t); i++) {
 		/* XXX audio already has track volume feature though #if 0 */
 		buf[i] = AUDIO_SCALEDOWN(sinewave[j] * (int)volume, 16);
 		j += step;
@@ -177,7 +195,7 @@ audiobell(void *dev, u_int pitch, u_int 
 	/* Write while paused to avoid inserting silence. */
 	ptrack->is_pause = true;
 	for (; remainbytes > 0; remainbytes -= len) {
-		len = uimin(remainbytes, blkbytes);
+		len = uimin(remainbytes, bufbytes);
 		aiov.iov_base = (void *)buf;
 		aiov.iov_len = len;
 		auio.uio_iov = 



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

2021-04-06 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Apr  6 17:44:29 UTC 2021

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

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

sys/dev/audio/audiobell.c: revision 1.4

Fix and improve the buffer length calculation to avoid zero length
even if blk_ms is small.

This fixes PR kern/56059.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.3.2.1 src/sys/dev/audio/audiobell.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

2021-03-01 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Mar  1 16:00:08 UTC 2021

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

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

sys/dev/audio/audio.c: revision 1.89
sys/dev/audio/audio.c: revision 1.90
sys/dev/audio/audio.c: revision 1.91

Change the lock conditions to call audio_unlink().

This can remove a different copy of audio_exlock_enter() in audio_unlink()
and can use normal one.  Also, in audiodetach(), this can set the exlock
at more natual order (before calling audio_unlink()).

No noticeable functional changes are intended.
Thanks for comments, riastradh@.

Protect also audioopen() and audiobellopen() from audiodetach() with
psref(9), as well as others(audioread, audiowrite, etc..).
- Rename audio_file_enter to audio_sc_acquire_fromfile, audio_file_exit
  to audio_sc_release, for clarify.  These are the reference counter for
  this sc.
- Introduce audio_sc_acquire_foropen for audio{,bell}open.
- audio_open needs to examine sc_dying again before inserting it into
  sc_files, in order to keep sc_files consistency.

The race between audiodetach and audioopen is pointed out by riastradh@.
Thank you for many advices.

Add missing curlwp_bindx() corresponding to curlwp_bind().
Pointed out by riastradh@.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.20 -r1.28.2.21 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

2021-03-01 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Mar  1 16:00:08 UTC 2021

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

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

sys/dev/audio/audio.c: revision 1.89
sys/dev/audio/audio.c: revision 1.90
sys/dev/audio/audio.c: revision 1.91

Change the lock conditions to call audio_unlink().

This can remove a different copy of audio_exlock_enter() in audio_unlink()
and can use normal one.  Also, in audiodetach(), this can set the exlock
at more natual order (before calling audio_unlink()).

No noticeable functional changes are intended.
Thanks for comments, riastradh@.

Protect also audioopen() and audiobellopen() from audiodetach() with
psref(9), as well as others(audioread, audiowrite, etc..).
- Rename audio_file_enter to audio_sc_acquire_fromfile, audio_file_exit
  to audio_sc_release, for clarify.  These are the reference counter for
  this sc.
- Introduce audio_sc_acquire_foropen for audio{,bell}open.
- audio_open needs to examine sc_dying again before inserting it into
  sc_files, in order to keep sc_files consistency.

The race between audiodetach and audioopen is pointed out by riastradh@.
Thank you for many advices.

Add missing curlwp_bindx() corresponding to curlwp_bind().
Pointed out by riastradh@.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.20 -r1.28.2.21 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.20 src/sys/dev/audio/audio.c:1.28.2.21
--- src/sys/dev/audio/audio.c:1.28.2.20	Sun Feb 28 07:07:38 2021
+++ src/sys/dev/audio/audio.c	Mon Mar  1 16:00:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.20 2021/02/28 07:07:38 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.21 2021/03/01 16:00:08 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.20 2021/02/28 07:07:38 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.21 2021/03/01 16:00:08 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -524,8 +524,10 @@ static int audio_exlock_mutex_enter(stru
 static void audio_exlock_mutex_exit(struct audio_softc *);
 static int audio_exlock_enter(struct audio_softc *);
 static void audio_exlock_exit(struct audio_softc *);
-static struct audio_softc *audio_file_enter(audio_file_t *, struct psref *);
-static void audio_file_exit(struct audio_softc *, struct psref *);
+static void audio_sc_acquire_foropen(struct audio_softc *, struct psref *);
+static struct audio_softc *audio_sc_acquire_fromfile(audio_file_t *,
+	struct psref *);
+static void audio_sc_release(struct audio_softc *, struct psref *);
 static int audio_track_waitio(struct audio_softc *, audio_track_t *);
 
 static int audioclose(struct file *);
@@ -1295,7 +1297,10 @@ audiodetach(device_t self, int flags)
 	if (error)
 		return error;
 
-	/* delete sysctl nodes */
+	/*
+	 * This waits currently running sysctls to finish if exists.
+	 * After this, no more new sysctls will come.
+	 */
 	sysctl_teardown(>sc_log);
 
 	mutex_enter(sc->sc_lock);
@@ -1327,9 +1332,10 @@ audiodetach(device_t self, int flags)
 	 * that hold sc, and any new calls with files that were for sc will
 	 * fail.  Thus, we now have exclusive access to the softc.
 	 */
+	sc->sc_exlock = 1;
 
 	/*
-	 * Nuke all open instances.
+	 * Clean up all open instances.
 	 * Here, we no longer need any locks to traverse sc_files.
 	 */
 	while ((file = SLIST_FIRST(>sc_files)) != NULL) {
@@ -1352,7 +1358,6 @@ audiodetach(device_t self, int flags)
 	pmf_device_deregister(self);
 
 	/* Free resources */
-	sc->sc_exlock = 1;
 	if (sc->sc_pmixer) {
 		audio_mixer_destroy(sc, sc->sc_pmixer);
 		kmem_free(sc->sc_pmixer, sizeof(*sc->sc_pmixer));
@@ -1524,18 +1529,41 @@ audio_exlock_exit(struct audio_softc *sc
 }
 
 /*
- * Acquire sc from file, and increment the psref count.
+ * Increment reference counter for this sc.
+ * This is intended to be used for open.
+ */
+void
+audio_sc_acquire_foropen(struct audio_softc *sc, struct psref *refp)
+{
+	int s;
+
+	/* Block audiodetach while we acquire a reference */
+	s = pserialize_read_enter();
+
+	/*
+	 * We don't examine sc_dying here.  However, all open methods
+	 * call audio_exlock_enter() right after this, so we can examine
+	 * sc_dying in it.
+	 */
+
+	/* Acquire a reference */
+	psref_acquire(refp, >sc_psref, audio_psref_class);
+
+	/* Now sc won't go away until we drop the reference count */
+	pserialize_read_exit(s);
+}
+
+/*
+ * Get sc from file, and increment reference counter for this sc.
+ * This is intended to be used for methods other than open.
  * If successful, returns sc.  Otherwise returns NULL.
  */
 struct audio_softc *
-audio_file_enter(audio_file_t *file, struct psref *refp)

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

2021-02-27 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Feb 28 07:07:38 UTC 2021

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

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

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

Fix a return value of audiopoll().
fo_poll is expected to return revents rather than errno on error.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.19 -r1.28.2.20 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.19 src/sys/dev/audio/audio.c:1.28.2.20
--- src/sys/dev/audio/audio.c:1.28.2.19	Sun Feb 28 07:05:14 2021
+++ src/sys/dev/audio/audio.c	Sun Feb 28 07:07:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.19 2021/02/28 07:05:14 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.20 2021/02/28 07:07:38 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.19 2021/02/28 07:05:14 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.20 2021/02/28 07:07:38 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -1885,7 +1885,7 @@ audiopoll(struct file *fp, int events)
 
 	sc = audio_file_enter(file, _ref);
 	if (sc == NULL)
-		return EIO;
+		return POLLERR;
 
 	switch (AUDIODEV(dev)) {
 	case SOUND_DEVICE:



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

2021-02-27 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Feb 28 07:07:38 UTC 2021

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

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

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

Fix a return value of audiopoll().
fo_poll is expected to return revents rather than errno on error.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.19 -r1.28.2.20 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

2021-02-27 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Feb 28 07:05:14 UTC 2021

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

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

sys/dev/audio/audio.c: revision 1.46
sys/dev/audio/audio.c: revision 1.82
sys/dev/audio/audio.c: revision 1.85
sys/dev/audio/audio.c: revision 1.87
sys/dev/audio/audio.c: revision 1.88

Change two aprint_error_dev() to device_printf() (and improve messages).
This is also called from other than boot.

Add missing newline.

Revise comments.

Change (harmless) zero-length debug messages.
sys/modules is compiled with -Wzero-length-format and this
makes sys/modules compilable even if AUDIO_DEBUG is defined.

Improve error messages.
- prefix MD device name if it's considered to be related to the MD driver.
- revise some messages.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.18 -r1.28.2.19 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

2021-02-27 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Feb 28 07:05:14 UTC 2021

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

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

sys/dev/audio/audio.c: revision 1.46
sys/dev/audio/audio.c: revision 1.82
sys/dev/audio/audio.c: revision 1.85
sys/dev/audio/audio.c: revision 1.87
sys/dev/audio/audio.c: revision 1.88

Change two aprint_error_dev() to device_printf() (and improve messages).
This is also called from other than boot.

Add missing newline.

Revise comments.

Change (harmless) zero-length debug messages.
sys/modules is compiled with -Wzero-length-format and this
makes sys/modules compilable even if AUDIO_DEBUG is defined.

Improve error messages.
- prefix MD device name if it's considered to be related to the MD driver.
- revise some messages.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.18 -r1.28.2.19 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.18 src/sys/dev/audio/audio.c:1.28.2.19
--- src/sys/dev/audio/audio.c:1.28.2.18	Sat Dec 19 13:54:56 2020
+++ src/sys/dev/audio/audio.c	Sun Feb 28 07:05:14 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.18 2020/12/19 13:54:56 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.19 2021/02/28 07:05:14 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.18 2020/12/19 13:54:56 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.19 2021/02/28 07:05:14 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -518,6 +518,8 @@ static void audio_mixer_restore(struct a
 static void audio_softintr_rd(void *);
 static void audio_softintr_wr(void *);
 
+static void audio_printf(struct audio_softc *, const char *, ...)
+	__printflike(2, 3);
 static int audio_exlock_mutex_enter(struct audio_softc *);
 static void audio_exlock_mutex_exit(struct audio_softc *);
 static int audio_exlock_enter(struct audio_softc *);
@@ -965,19 +967,20 @@ audioattach(device_t parent, device_t se
 		perror = audio_hw_probe(sc, , AUMODE_PLAY);
 		rerror = audio_hw_probe(sc, , AUMODE_RECORD);
 		if (perror && rerror) {
-			aprint_error_dev(self, "audio_hw_probe failed, "
-			"perror = %d, rerror = %d\n", perror, rerror);
+			aprint_error_dev(self,
+			"audio_hw_probe failed: perror=%d, rerror=%d\n",
+			perror, rerror);
 			goto bad;
 		}
 		if (perror) {
 			mode &= ~AUMODE_PLAY;
-			aprint_error_dev(self, "audio_hw_probe failed with "
-			"%d, playback disabled\n", perror);
+			aprint_error_dev(self, "audio_hw_probe failed: "
+			"errno=%d, playback disabled\n", perror);
 		}
 		if (rerror) {
 			mode &= ~AUMODE_RECORD;
-			aprint_error_dev(self, "audio_hw_probe failed with "
-			"%d, capture disabled\n", rerror);
+			aprint_error_dev(self, "audio_hw_probe failed: "
+			"errno=%d, capture disabled\n", rerror);
 		}
 	} else {
 		/*
@@ -987,8 +990,8 @@ audioattach(device_t parent, device_t se
 		audio_format2_t *fmt = has_playback ?  : 
 		error = audio_hw_probe(sc, fmt, mode);
 		if (error) {
-			aprint_error_dev(self, "audio_hw_probe failed, "
-			"error = %d\n", error);
+			aprint_error_dev(self,
+			"audio_hw_probe failed: errno=%d\n", error);
 			goto bad;
 		}
 		if (has_playback && has_capture)
@@ -999,8 +1002,8 @@ audioattach(device_t parent, device_t se
 	/* hw_probe() also validates [pr]hwfmt.  */
 	error = audio_hw_set_format(sc, mode, , , , );
 	if (error) {
-		aprint_error_dev(self, "audio_hw_set_format failed, "
-		"error = %d\n", error);
+		aprint_error_dev(self,
+		"audio_hw_set_format failed: errno=%d\n", error);
 		goto bad;
 	}
 
@@ -1010,8 +1013,8 @@ audioattach(device_t parent, device_t se
 	 */
 	error = audio_mixers_init(sc, mode, , , , );
 	if (sc->sc_pmixer == NULL && sc->sc_rmixer == NULL) {
-		aprint_error_dev(self, "audio_mixers_init failed, "
-		"error = %d\n", error);
+		aprint_error_dev(self,
+		"audio_mixers_init failed: errno=%d\n", error);
 		goto bad;
 	}
 
@@ -1429,6 +1432,22 @@ audio_attach_mi(const struct audio_hw_if
 }
 
 /*
+ * audio_printf() outputs fmt... with the audio device name and MD device
+ * name prefixed.  If the message is considered to be related to the MD
+ * driver, use this one instead of device_printf().
+ */
+static void
+audio_printf(struct audio_softc *sc, const char *fmt, ...)
+{
+	va_list ap;
+
+	printf("%s(%s): ", device_xname(sc->sc_dev), device_xname(sc->hw_dev));
+	va_start(ap, fmt);
+	vprintf(fmt, ap);
+	va_end(ap);
+}
+
+/*
  * Enter critical section and also keep sc_lock.
  * If successful, returns 0 with sc_lock held.  Otherwise returns errno.
  * Must be called without sc_lock held.
@@ -1574,7 +1593,7 @@ 

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

2020-12-19 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Dec 19 13:54:56 UTC 2020

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

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

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

Avoid a dead lock in audiodetach, since rev 1.63.
audio_unlink() must be called without exlock held (and
audio_mixer_destroy() must be called with exlock held).

This makes unplugging during playing/recording work (again).

Reported by Julian Coleman on current-users:
 http://mail-index.netbsd.org/current-users/2020/12/10/msg040050.html


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.17 -r1.28.2.18 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.17 src/sys/dev/audio/audio.c:1.28.2.18
--- src/sys/dev/audio/audio.c:1.28.2.17	Sat Dec 19 13:48:27 2020
+++ src/sys/dev/audio/audio.c	Sat Dec 19 13:54:56 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.17 2020/12/19 13:48:27 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.18 2020/12/19 13:54:56 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.17 2020/12/19 13:48:27 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.18 2020/12/19 13:54:56 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -1324,7 +1324,6 @@ audiodetach(device_t self, int flags)
 	 * that hold sc, and any new calls with files that were for sc will
 	 * fail.  Thus, we now have exclusive access to the softc.
 	 */
-	sc->sc_exlock = 1;
 
 	/*
 	 * Nuke all open instances.
@@ -1350,6 +1349,7 @@ audiodetach(device_t self, int flags)
 	pmf_device_deregister(self);
 
 	/* Free resources */
+	sc->sc_exlock = 1;
 	if (sc->sc_pmixer) {
 		audio_mixer_destroy(sc, sc->sc_pmixer);
 		kmem_free(sc->sc_pmixer, sizeof(*sc->sc_pmixer));



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

2020-12-19 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Dec 19 13:54:56 UTC 2020

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

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

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

Avoid a dead lock in audiodetach, since rev 1.63.
audio_unlink() must be called without exlock held (and
audio_mixer_destroy() must be called with exlock held).

This makes unplugging during playing/recording work (again).

Reported by Julian Coleman on current-users:
 http://mail-index.netbsd.org/current-users/2020/12/10/msg040050.html


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.17 -r1.28.2.18 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

2020-12-19 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Dec 19 13:48:27 UTC 2020

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

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

sys/dev/audio/audio.c: revision 1.80
sys/dev/audio/audio.c: revision 1.81

Fix that audio_open() didn't halt the recording mixer correctly
if fd_allocfile() failed, since rev 1.65.

Will fix PR kern/55848.

 -

Rewrite error handling on audio_open().
This also fixes a few resource leaks on error case.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.16 -r1.28.2.17 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.16 src/sys/dev/audio/audio.c:1.28.2.17
--- src/sys/dev/audio/audio.c:1.28.2.16	Sun Jun  7 19:04:00 2020
+++ src/sys/dev/audio/audio.c	Sat Dec 19 13:48:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.16 2020/06/07 19:04:00 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.17 2020/12/19 13:48:27 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.16 2020/06/07 19:04:00 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.17 2020/12/19 13:48:27 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2075,6 +2075,9 @@ audio_open(dev_t dev, struct audio_softc
 	audio_file_t *af;
 	audio_ring_t *hwbuf;
 	bool fullduplex;
+	bool cred_held;
+	bool hw_opened;
+	bool rmixer_started;
 	int fd;
 	int error;
 
@@ -2085,6 +2088,11 @@ audio_open(dev_t dev, struct audio_softc
 	ISDEVSOUND(dev) ? "sound" : "audio",
 	flags, sc->sc_popens, sc->sc_ropens);
 
+	fp = NULL;
+	cred_held = false;
+	hw_opened = false;
+	rmixer_started = false;
+
 	af = kmem_zalloc(sizeof(audio_file_t), KM_SLEEP);
 	af->sc = sc;
 	af->dev = dev;
@@ -2094,7 +2102,7 @@ audio_open(dev_t dev, struct audio_softc
 		af->mode |= AUMODE_RECORD;
 	if (af->mode == 0) {
 		error = ENXIO;
-		goto bad1;
+		goto bad;
 	}
 
 	fullduplex = (sc->sc_props & AUDIO_PROP_FULLDUPLEX);
@@ -2110,7 +2118,7 @@ audio_open(dev_t dev, struct audio_softc
 			if (sc->sc_ropens != 0) {
 TRACE(1, "record track already exists");
 error = ENODEV;
-goto bad1;
+goto bad;
 			}
 			/* Play takes precedence */
 			af->mode &= ~AUMODE_RECORD;
@@ -2119,7 +2127,7 @@ audio_open(dev_t dev, struct audio_softc
 			if (sc->sc_popens != 0) {
 TRACE(1, "play track already exists");
 error = ENODEV;
-goto bad1;
+goto bad;
 			}
 		}
 	}
@@ -2166,13 +2174,14 @@ audio_open(dev_t dev, struct audio_softc
 	}
 	error = audio_file_setinfo(sc, af, );
 	if (error)
-		goto bad2;
+		goto bad;
 
 	if (sc->sc_popens + sc->sc_ropens == 0) {
 		/* First open */
 
 		sc->sc_cred = kauth_cred_get();
 		kauth_cred_hold(sc->sc_cred);
+		cred_held = true;
 
 		if (sc->hw_if->open) {
 			int hwflags;
@@ -2205,8 +2214,16 @@ audio_open(dev_t dev, struct audio_softc
 			mutex_exit(sc->sc_intr_lock);
 			mutex_exit(sc->sc_lock);
 			if (error)
-goto bad2;
+goto bad;
 		}
+		/*
+		 * Regardless of whether we called hw_if->open (whether
+		 * hw_if->open exists) or not, we move to the Opened phase
+		 * here.  Therefore from this point, we have to call
+		 * hw_if->close (if exists) whenever abort.
+		 * Note that both of hw_if->{open,close} are optional.
+		 */
+		hw_opened = true;
 
 		/*
 		 * Set speaker mode when a half duplex.
@@ -2226,14 +2243,14 @@ audio_open(dev_t dev, struct audio_softc
 mutex_exit(sc->sc_intr_lock);
 mutex_exit(sc->sc_lock);
 if (error)
-	goto bad3;
+	goto bad;
 			}
 		}
 	} else if (sc->sc_multiuser == false) {
 		uid_t euid = kauth_cred_geteuid(kauth_cred_get());
 		if (euid != 0 && euid != kauth_cred_geteuid(sc->sc_cred)) {
 			error = EPERM;
-			goto bad2;
+			goto bad;
 		}
 	}
 
@@ -2250,7 +2267,7 @@ audio_open(dev_t dev, struct audio_softc
 			mutex_exit(sc->sc_intr_lock);
 			mutex_exit(sc->sc_lock);
 			if (error)
-goto bad3;
+goto bad;
 		}
 	}
 	/*
@@ -2269,18 +2286,24 @@ audio_open(dev_t dev, struct audio_softc
 			mutex_exit(sc->sc_intr_lock);
 			mutex_exit(sc->sc_lock);
 			if (error)
-goto bad3;
+goto bad;
 		}
 
 		mutex_enter(sc->sc_lock);
 		audio_rmixer_start(sc);
 		mutex_exit(sc->sc_lock);
+		rmixer_started = true;
 	}
 
-	if (bellfile == NULL) {
+	if (bellfile) {
+		*bellfile = af;
+	} else {
 		error = fd_allocfile(, );
 		if (error)
-			goto bad3;
+			goto bad;
+
+		error = fd_clone(fp, fd, flags, _fileops, af);
+		KASSERTMSG(error == EMOVEFD, "error=%d", error);
 	}
 
 	/*
@@ -2297,22 +2320,21 @@ audio_open(dev_t dev, struct audio_softc
 	mutex_exit(sc->sc_intr_lock);
 	mutex_exit(sc->sc_lock);
 
-	if (bellfile) {
-		*bellfile = af;
-	} else {
-		error = fd_clone(fp, fd, flags, _fileops, af);
-		KASSERTMSG(error == EMOVEFD, 

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

2020-12-19 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Dec 19 13:48:27 UTC 2020

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

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

sys/dev/audio/audio.c: revision 1.80
sys/dev/audio/audio.c: revision 1.81

Fix that audio_open() didn't halt the recording mixer correctly
if fd_allocfile() failed, since rev 1.65.

Will fix PR kern/55848.

 -

Rewrite error handling on audio_open().
This also fixes a few resource leaks on error case.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.16 -r1.28.2.17 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

2020-06-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jun  7 19:04:00 UTC 2020

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

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

sys/dev/audio/audio.c: revision 1.71
sys/dev/audio/audio.c: revision 1.73
sys/dev/audio/audio.c: revision 1.74
sys/dev/audio/audio.c: revision 1.75
sys/dev/audio/audiovar.h: revision 1.12

audio: Fix logic for resuming when the device is in use.

audio_[r/p]mixer_start should never be called when the device is
marked busy.

Resolves a panic on resume when audio is playing, PR kern/55301

audio: remove comment that is no longer valid

audio: Only restart recording mixer on resume if it's already been started

Fix suspend/resume.
- Revert temporary usage of sc_[pr]busy during suspend.  These indicate
  whether the mixer needs to be restarted or not.
- Avoid timeout error when about to suspend.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.15 -r1.28.2.16 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.4.2.3 -r1.4.2.4 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.15 src/sys/dev/audio/audio.c:1.28.2.16
--- src/sys/dev/audio/audio.c:1.28.2.15	Mon May 18 18:12:24 2020
+++ src/sys/dev/audio/audio.c	Sun Jun  7 19:04:00 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.15 2020/05/18 18:12:24 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.16 2020/06/07 19:04:00 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.15 2020/05/18 18:12:24 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.16 2020/06/07 19:04:00 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -1561,6 +1561,13 @@ audio_track_waitio(struct audio_softc *s
 	/* Wait for pending I/O to complete. */
 	error = cv_timedwait_sig(>mixer->outcv, sc->sc_lock,
 	mstohz(AUDIO_TIMEOUT));
+	if (sc->sc_suspending) {
+		/* If it's about to suspend, ignore timeout error. */
+		if (error == EWOULDBLOCK) {
+			TRACET(2, track, "timeout (suspending)");
+			return 0;
+		}
+	}
 	if (sc->sc_dying) {
 		error = EIO;
 	}
@@ -7748,15 +7755,17 @@ audio_suspend(device_t dv, const pmf_qua
 	error = audio_exlock_mutex_enter(sc);
 	if (error)
 		return error;
+	sc->sc_suspending = true;
 	audio_mixer_capture(sc);
 
-	/* Halts mixers but don't clear busy flag for resume */
 	if (sc->sc_pbusy) {
 		audio_pmixer_halt(sc);
+		/* Reuse this as need-to-restart flag while suspending */
 		sc->sc_pbusy = true;
 	}
 	if (sc->sc_rbusy) {
 		audio_rmixer_halt(sc);
+		/* Reuse this as need-to-restart flag while suspending */
 		sc->sc_rbusy = true;
 	}
 
@@ -7779,15 +7788,28 @@ audio_resume(device_t dv, const pmf_qual
 	if (error)
 		return error;
 
+	sc->sc_suspending = false;
 	audio_mixer_restore(sc);
 	/* XXX ? */
 	AUDIO_INITINFO();
 	audio_hw_setinfo(sc, , NULL);
 
-	if (sc->sc_pbusy)
+	/*
+	 * During from suspend to resume here, sc_[pr]busy is used as
+	 * need-to-restart flag temporarily.  After this point,
+	 * sc_[pr]busy is returned to its original usage (busy flag).
+	 * And note that sc_[pr]busy must be false to call [pr]mixer_start().
+	 */
+	if (sc->sc_pbusy) {
+		/* pmixer_start() requires pbusy is false */
+		sc->sc_pbusy = false;
 		audio_pmixer_start(sc, true);
-	if (sc->sc_rbusy)
+	}
+	if (sc->sc_rbusy) {
+		/* rmixer_start() requires rbusy is false */
+		sc->sc_rbusy = false;
 		audio_rmixer_start(sc);
+	}
 
 	audio_exlock_mutex_exit(sc);
 

Index: src/sys/dev/audio/audiovar.h
diff -u src/sys/dev/audio/audiovar.h:1.4.2.3 src/sys/dev/audio/audiovar.h:1.4.2.4
--- src/sys/dev/audio/audiovar.h:1.4.2.3	Thu Apr 30 16:05:18 2020
+++ src/sys/dev/audio/audiovar.h	Sun Jun  7 19:04:00 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiovar.h,v 1.4.2.3 2020/04/30 16:05:18 martin Exp $	*/
+/*	$NetBSD: audiovar.h,v 1.4.2.4 2020/06/07 19:04:00 martin Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -243,6 +243,12 @@ struct audio_softc {
 	bool		sc_dying;
 
 	/*
+	 * Indicates that about to suspend.
+	 * Must be protected by sc_lock.
+	 */
+	bool		sc_suspending;
+
+	/*
 	 * If multiuser is false, other users who have different euid
 	 * than the first user cannot open this device.
 	 * Must be protected by sc_exlock.



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

2020-06-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jun  7 19:04:00 UTC 2020

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

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

sys/dev/audio/audio.c: revision 1.71
sys/dev/audio/audio.c: revision 1.73
sys/dev/audio/audio.c: revision 1.74
sys/dev/audio/audio.c: revision 1.75
sys/dev/audio/audiovar.h: revision 1.12

audio: Fix logic for resuming when the device is in use.

audio_[r/p]mixer_start should never be called when the device is
marked busy.

Resolves a panic on resume when audio is playing, PR kern/55301

audio: remove comment that is no longer valid

audio: Only restart recording mixer on resume if it's already been started

Fix suspend/resume.
- Revert temporary usage of sc_[pr]busy during suspend.  These indicate
  whether the mixer needs to be restarted or not.
- Avoid timeout error when about to suspend.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.15 -r1.28.2.16 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.4.2.3 -r1.4.2.4 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

2020-05-18 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon May 18 18:05:34 UTC 2020

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

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

sys/dev/audio/audio.c: revision 1.49
sys/dev/audio/audio.c: revision 1.61
sys/dev/audio/audio.c: revision 1.66
sys/dev/audio/audio.c: revision 1.67

Move #if DIAGNOSTIC..#endif to correct place.
It should ignore stray interrupts regardless of DIAGNOSTIC.

Improve an error message about round_blocksize.

Improve diagnostic messages.

Improve the blocksize notation.
The blocksize is expressed in bytes, and the millisecond notation
is supplementary information to make it easier to understand.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.13 -r1.28.2.14 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.13 src/sys/dev/audio/audio.c:1.28.2.14
--- src/sys/dev/audio/audio.c:1.28.2.13	Mon May 18 18:02:23 2020
+++ src/sys/dev/audio/audio.c	Mon May 18 18:05:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.13 2020/05/18 18:02:23 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.14 2020/05/18 18:05:34 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.13 2020/05/18 18:02:23 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.14 2020/05/18 18:05:34 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -4783,6 +4783,7 @@ audio_mixer_init(struct audio_softc *sc,
 	const audio_format2_t *hwfmt, const audio_filter_reg_t *reg)
 {
 	char codecbuf[64];
+	char blkdmsbuf[8];
 	audio_trackmixer_t *mixer;
 	void (*softint_handler)(void *);
 	int len;
@@ -4791,6 +4792,7 @@ audio_mixer_init(struct audio_softc *sc,
 	size_t bufsize;
 	int hwblks;
 	int blkms;
+	int blkdms;
 	int error;
 
 	KASSERT(hwfmt != NULL);
@@ -4827,8 +4829,13 @@ audio_mixer_init(struct audio_softc *sc,
 			if ((rounded * NBBY) % (mixer->hwbuf.fmt.stride *
 			mixer->hwbuf.fmt.channels) != 0) {
 device_printf(sc->sc_dev,
-"blksize not configured %d -> %d\n",
-blksize, rounded);
+"round_blocksize must return blocksize "
+"divisible by framesize: "
+"blksize=%d rounded=%d "
+"stride=%ubit channels=%u\n",
+blksize, rounded,
+mixer->hwbuf.fmt.stride,
+mixer->hwbuf.fmt.channels);
 return EINVAL;
 			}
 			/* Recalculation */
@@ -4965,13 +4972,20 @@ audio_mixer_init(struct audio_softc *sc,
 		mixer->hwbuf.fmt.precision);
 	}
 	blkms = mixer->blktime_n * 1000 / mixer->blktime_d;
-	aprint_normal_dev(sc->sc_dev, "%s:%d%s %dch %dHz, blk %dms for %s\n",
+	blkdms = (mixer->blktime_n * 1 / mixer->blktime_d) % 10;
+	blkdmsbuf[0] = '\0';
+	if (blkdms != 0) {
+		snprintf(blkdmsbuf, sizeof(blkdmsbuf), ".%1d", blkdms);
+	}
+	aprint_normal_dev(sc->sc_dev,
+	"%s:%d%s %dch %dHz, blk %d bytes (%d%sms) for %s\n",
 	audio_encoding_name(mixer->track_fmt.encoding),
 	mixer->track_fmt.precision,
 	codecbuf,
 	mixer->track_fmt.channels,
 	mixer->track_fmt.sample_rate,
-	blkms,
+	blksize,
+	blkms, blkdmsbuf,
 	(mode == AUMODE_PLAY) ? "playback" : "recording");
 
 	return 0;
@@ -5455,12 +5469,14 @@ audio_pintr(void *arg)
 
 	if (sc->sc_dying)
 		return;
-#if defined(DIAGNOSTIC)
 	if (sc->sc_pbusy == false) {
-		device_printf(sc->sc_dev, "stray interrupt\n");
+#if defined(DIAGNOSTIC)
+		device_printf(sc->sc_dev,
+		"DIAGNOSTIC: %s raised stray interrupt\n",
+		device_xname(sc->hw_dev));
+#endif
 		return;
 	}
-#endif
 
 	mixer = sc->sc_pmixer;
 	mixer->hw_complete_counter += mixer->frames_per_block;
@@ -5728,12 +5744,14 @@ audio_rintr(void *arg)
 
 	if (sc->sc_dying)
 		return;
-#if defined(DIAGNOSTIC)
 	if (sc->sc_rbusy == false) {
-		device_printf(sc->sc_dev, "stray interrupt\n");
+#if defined(DIAGNOSTIC)
+		device_printf(sc->sc_dev,
+		"DIAGNOSTIC: %s raised stray interrupt\n",
+		device_xname(sc->hw_dev));
+#endif
 		return;
 	}
-#endif
 
 	mixer = sc->sc_rmixer;
 	mixer->hw_complete_counter += mixer->frames_per_block;



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

2020-05-18 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon May 18 18:05:34 UTC 2020

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

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

sys/dev/audio/audio.c: revision 1.49
sys/dev/audio/audio.c: revision 1.61
sys/dev/audio/audio.c: revision 1.66
sys/dev/audio/audio.c: revision 1.67

Move #if DIAGNOSTIC..#endif to correct place.
It should ignore stray interrupts regardless of DIAGNOSTIC.

Improve an error message about round_blocksize.

Improve diagnostic messages.

Improve the blocksize notation.
The blocksize is expressed in bytes, and the millisecond notation
is supplementary information to make it easier to understand.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.13 -r1.28.2.14 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

2020-05-18 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon May 18 18:02:23 UTC 2020

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

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

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

Fix to start recording immediately when open() with READ mode is
called (unless pause).
- Opening /dev/audio always initializes pause with false.  Therefore
  it always starts recording.
- Opening /dev/sound inherites pause from the sticky parameter.
  Therefore whether /dev/sound starts recording or not depends on the
  sticky pause parameter.

This fixes two problems:
- Opening /dev/audio didn't start recording after merging isaki-audio2.
- Opening /dev/sound didn't start recording regardless of the sticky
  pause, probably since long time ago (at least netbsd-7).


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.12 -r1.28.2.13 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.12 src/sys/dev/audio/audio.c:1.28.2.13
--- src/sys/dev/audio/audio.c:1.28.2.12	Thu Apr 30 16:05:18 2020
+++ src/sys/dev/audio/audio.c	Mon May 18 18:02:23 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.12 2020/04/30 16:05:18 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.13 2020/05/18 18:02:23 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.12 2020/04/30 16:05:18 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.13 2020/05/18 18:02:23 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2224,7 +2224,10 @@ audio_open(dev_t dev, struct audio_softc
 goto bad3;
 		}
 	}
-	/* Call init_input if this is the first recording open. */
+	/*
+	 * Call init_input and start rmixer, if this is the first recording
+	 * open.  See pause consideration notes.
+	 */
 	if (af->rtrack && sc->sc_ropens == 0) {
 		if (sc->hw_if->init_input) {
 			hwbuf = >sc_rmixer->hwbuf;
@@ -2239,6 +2242,10 @@ audio_open(dev_t dev, struct audio_softc
 			if (error)
 goto bad3;
 		}
+
+		mutex_enter(sc->sc_lock);
+		audio_rmixer_start(sc);
+		mutex_exit(sc->sc_lock);
 	}
 
 	if (bellfile == NULL) {
@@ -2457,21 +2464,18 @@ audio_read(struct audio_softc *sc, struc
 
 	TRACET(2, track, "resid=%zd", uio->uio_resid);
 
+#ifdef AUDIO_PM_IDLE
 	error = audio_exlock_mutex_enter(sc);
 	if (error)
 		return error;
 
-#ifdef AUDIO_PM_IDLE
 	if (device_is_active(>sc_dev) || sc->sc_idle)
 		device_active(>sc_dev, DVA_SYSTEM);
-#endif
 
-	/*
-	 * The first read starts rmixer.
-	 */
-	if (sc->sc_rbusy == false)
-		audio_rmixer_start(sc);
+	/* In recording, unlike playback, read() never operates rmixer. */
+
 	audio_exlock_mutex_exit(sc);
+#endif
 
 	usrbuf = >usrbuf;
 	input = track->input;
@@ -6672,10 +6676,22 @@ audio_mixers_get_format(struct audio_sof
 /*
  * Pause consideration:
  *
- * The introduction of these two behavior makes pause/unpause operation
- * simple.
- * 1. The first read/write access of the first track makes mixer start.
- * 2. A pause of the last track doesn't make mixer stop.
+ * Pausing/unpausing never affect [pr]mixer.  This single rule makes
+ * operation simple.  Note that playback and recording are asymmetric.
+ *
+ * For playback,
+ *  1. Any playback open doesn't start pmixer regardless of initial pause
+ * state of this track.
+ *  2. The first write access among playback tracks only starts pmixer
+ * regardless of this track's pause state.
+ *  3. Even a pause of the last playback track doesn't stop pmixer.
+ *  4. The last close of all playback tracks only stops pmixer.
+ *
+ * For recording,
+ *  1. The first recording open only starts rmixer regardless of initial
+ * pause state of this track.
+ *  2. Even a pause of the last track doesn't stop rmixer.
+ *  3. The last close of all recording tracks only stops rmixer.
  */
 
 /*



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

2020-05-18 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon May 18 18:02:23 UTC 2020

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

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

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

Fix to start recording immediately when open() with READ mode is
called (unless pause).
- Opening /dev/audio always initializes pause with false.  Therefore
  it always starts recording.
- Opening /dev/sound inherites pause from the sticky parameter.
  Therefore whether /dev/sound starts recording or not depends on the
  sticky pause parameter.

This fixes two problems:
- Opening /dev/audio didn't start recording after merging isaki-audio2.
- Opening /dev/sound didn't start recording regardless of the sticky
  pause, probably since long time ago (at least netbsd-7).


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.12 -r1.28.2.13 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

2020-04-30 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Apr 30 16:05:18 UTC 2020

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

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

sys/dev/audio/audio.c: revision 1.55
sys/dev/audio/audio.c: revision 1.41
sys/dev/audio/audio.c: revision 1.48
sys/dev/audio/audiovar.h: revision 1.7
sys/dev/audio/audio.c: revision 1.63 (via patch)
sys/dev/audio/audiovar.h: revision 1.11
sys/dev/audio/audio.c: revision 1.64

Simplify async_mixer handling.
- It makes FIOASYNC code in mixer_ioctl() symmetric.
- For readability, mixer_async_{add,remove}() should take pid argument
  though pid is always curproc.

hw_if->query_format is already mandatory method.  Drop null checks.

Improve error handling around audio_hw_probe().
It was difficult to return multiple errors.

Split sc_lock and sc_exlock.

Most (probably all) malloc/free (or routines which may sleep) now can be
called without holding mutex.
Pointed out by riastradh@.

Fix/Update comments about allocm/freem.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.11 -r1.28.2.12 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.4.2.2 -r1.4.2.3 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.11 src/sys/dev/audio/audio.c:1.28.2.12
--- src/sys/dev/audio/audio.c:1.28.2.11	Thu Apr 30 15:43:30 2020
+++ src/sys/dev/audio/audio.c	Thu Apr 30 16:05:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.11 2020/04/30 15:43:30 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.12 2020/04/30 16:05:18 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -118,8 +118,8 @@
  *	set_port 		-	x +
  *	get_port 		-	x +
  *	query_devinfo 		-	x
- *	allocm 			-	- +	(*1)
- *	freem 			-	- +	(*1)
+ *	allocm 			-	- +
+ *	freem 			-	- +
  *	round_buffersize 	-	x
  *	get_props 		-	x	Called at attach time
  *	trigger_output 		x	x +
@@ -127,10 +127,6 @@
  *	dev_ioctl 		-	x
  *	get_locks 		-	-	Called at attach time
  *
- * *1 Note: Before 8.0, since these have been called only at attach time,
- *   neither lock were necessary.  Currently, on the other hand, since
- *   these may be also called after attach, the thread lock is required.
- *
  * In addition, there is an additional lock.
  *
  * - track->lock.  This is an atomic variable and is similar to the
@@ -142,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.11 2020/04/30 15:43:30 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.12 2020/04/30 16:05:18 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -466,6 +462,9 @@ audio_track_bufstat(audio_track_t *track
 int audio_idle_timeout = 30;
 #endif
 
+/* Number of elements of async mixer's pid */
+#define AM_CAPACITY	(4)
+
 struct portname {
 	const char *name;
 	int mask;
@@ -497,8 +496,10 @@ static void audio_mixer_restore(struct a
 static void audio_softintr_rd(void *);
 static void audio_softintr_wr(void *);
 
-static int  audio_enter_exclusive(struct audio_softc *);
-static void audio_exit_exclusive(struct audio_softc *);
+static int audio_exlock_mutex_enter(struct audio_softc *);
+static void audio_exlock_mutex_exit(struct audio_softc *);
+static int audio_exlock_enter(struct audio_softc *);
+static void audio_exlock_exit(struct audio_softc *);
 static struct audio_softc *audio_file_enter(audio_file_t *, struct psref *);
 static void audio_file_exit(struct audio_softc *, struct psref *);
 static int audio_track_waitio(struct audio_softc *, audio_track_t *);
@@ -560,9 +561,7 @@ static int audio_mixers_init(struct audi
 	const audio_format2_t *, const audio_format2_t *,
 	const audio_filter_reg_t *, const audio_filter_reg_t *);
 static int audio_select_freq(const struct audio_format *);
-static int audio_hw_probe(struct audio_softc *, int, int *,
-	audio_format2_t *, audio_format2_t *);
-static int audio_hw_probe_fmt(struct audio_softc *, audio_format2_t *, int);
+static int audio_hw_probe(struct audio_softc *, audio_format2_t *, int);
 static int audio_hw_validate_format(struct audio_softc *, int,
 	const audio_format2_t *);
 static int audio_mixers_set_format(struct audio_softc *,
@@ -609,7 +608,8 @@ static void mixer_init(struct audio_soft
 static int mixer_open(dev_t, struct audio_softc *, int, int, struct lwp *);
 static int mixer_close(struct audio_softc *, audio_file_t *);
 static int mixer_ioctl(struct audio_softc *, u_long, void *, int, struct lwp *);
-static void mixer_remove(struct audio_softc *);
+static void mixer_async_add(struct audio_softc *, pid_t);
+static void mixer_async_remove(struct audio_softc *, pid_t);
 static void mixer_signal(struct audio_softc *);
 
 static int au_portof(struct audio_softc *, char *, int);
@@ -882,9 +882,13 @@ audioattach(device_t parent, 

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

2020-04-30 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Apr 30 16:05:18 UTC 2020

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

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

sys/dev/audio/audio.c: revision 1.55
sys/dev/audio/audio.c: revision 1.41
sys/dev/audio/audio.c: revision 1.48
sys/dev/audio/audiovar.h: revision 1.7
sys/dev/audio/audio.c: revision 1.63 (via patch)
sys/dev/audio/audiovar.h: revision 1.11
sys/dev/audio/audio.c: revision 1.64

Simplify async_mixer handling.
- It makes FIOASYNC code in mixer_ioctl() symmetric.
- For readability, mixer_async_{add,remove}() should take pid argument
  though pid is always curproc.

hw_if->query_format is already mandatory method.  Drop null checks.

Improve error handling around audio_hw_probe().
It was difficult to return multiple errors.

Split sc_lock and sc_exlock.

Most (probably all) malloc/free (or routines which may sleep) now can be
called without holding mutex.
Pointed out by riastradh@.

Fix/Update comments about allocm/freem.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.11 -r1.28.2.12 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.4.2.2 -r1.4.2.3 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

2020-04-30 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Apr 30 15:43:30 UTC 2020

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

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

sys/dev/audio/audio.c: revision 1.60
sys/dev/audio/audio.c: revision 1.62

Fix wrong parameter displayed in debug messages.

Restore backward compatibility with netbsd-7 audio.

For sticky parameters (encoding, precision, channels, sample_rate and pause):
 - AUDIO_SETINFO for nonexistent track updates sticky parameters.
 - AUDIO_GETINFO for nonexistent track reads sticky parameters.

For blocksize, hiwat, lowat and {play.record}.buffer_size:
 - AUDIO_SETINFO for nonexistent track does nothing.
 - AUDIO_GETINFO for nonexistent track returns dummy non-zero values.

Nonexistent track is a playback track on O_RDONLY descriptor for example,
or both tracks on /dev/audioctl.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.10 -r1.28.2.11 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

2020-04-30 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Apr 30 15:43:30 UTC 2020

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

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

sys/dev/audio/audio.c: revision 1.60
sys/dev/audio/audio.c: revision 1.62

Fix wrong parameter displayed in debug messages.

Restore backward compatibility with netbsd-7 audio.

For sticky parameters (encoding, precision, channels, sample_rate and pause):
 - AUDIO_SETINFO for nonexistent track updates sticky parameters.
 - AUDIO_GETINFO for nonexistent track reads sticky parameters.

For blocksize, hiwat, lowat and {play.record}.buffer_size:
 - AUDIO_SETINFO for nonexistent track does nothing.
 - AUDIO_GETINFO for nonexistent track returns dummy non-zero values.

Nonexistent track is a playback track on O_RDONLY descriptor for example,
or both tracks on /dev/audioctl.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.10 -r1.28.2.11 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.10 src/sys/dev/audio/audio.c:1.28.2.11
--- src/sys/dev/audio/audio.c:1.28.2.10	Thu Apr 30 15:40:50 2020
+++ src/sys/dev/audio/audio.c	Thu Apr 30 15:43:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.10 2020/04/30 15:40:50 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.11 2020/04/30 15:43:30 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.10 2020/04/30 15:40:50 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.11 2020/04/30 15:43:30 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -542,8 +542,8 @@ static int audio_query_devinfo(struct au
 static __inline int audio_track_readablebytes(const audio_track_t *);
 static int audio_file_setinfo(struct audio_softc *, audio_file_t *,
 	const struct audio_info *);
-static int audio_track_setinfo_check(audio_format2_t *,
-	const struct audio_prinfo *, const audio_format2_t *);
+static int audio_track_setinfo_check(audio_track_t *,
+	audio_format2_t *, const struct audio_prinfo *);
 static void audio_track_setinfo_water(audio_track_t *,
 	const struct audio_info *);
 static int audio_hw_setinfo(struct audio_softc *, const struct audio_info *,
@@ -6779,20 +6779,30 @@ audio_file_setinfo(struct audio_softc *s
 	memset(_pfmt, 0, sizeof(saved_pfmt));
 	memset(_rfmt, 0, sizeof(saved_rfmt));
 
-	/* Set default value and save current parameters */
+	/*
+	 * Set default value and save current parameters.
+	 * For backward compatibility, use sticky parameters for nonexistent
+	 * track.
+	 */
 	if (ptrack) {
 		pfmt = ptrack->usrbuf.fmt;
 		saved_pfmt = ptrack->usrbuf.fmt;
 		saved_ai.play.pause = ptrack->is_pause;
+	} else {
+		pfmt = sc->sc_sound_pparams;
 	}
 	if (rtrack) {
 		rfmt = rtrack->usrbuf.fmt;
 		saved_rfmt = rtrack->usrbuf.fmt;
 		saved_ai.record.pause = rtrack->is_pause;
+	} else {
+		rfmt = sc->sc_sound_rparams;
 	}
 	saved_ai.mode = file->mode;
 
-	/* Overwrite if specified */
+	/*
+	 * Overwrite if specified.
+	 */
 	mode = file->mode;
 	if (SPECIFIED(ai->mode)) {
 		/*
@@ -6811,35 +6821,35 @@ audio_file_setinfo(struct audio_softc *s
 		}
 	}
 
-	if (ptrack) {
-		pchanges = audio_track_setinfo_check(, pi,
-		>sc_pmixer->hwbuf.fmt);
-		if (pchanges == -1) {
+	pchanges = audio_track_setinfo_check(ptrack, , pi);
+	if (pchanges == -1) {
 #if defined(AUDIO_DEBUG)
-			char fmtbuf[64];
-			audio_format2_tostr(fmtbuf, sizeof(fmtbuf), );
-			TRACET(1, ptrack, "check play.params failed: %s",
-			fmtbuf);
+		TRACEF(1, file, "check play.params failed: "
+		"%s %ubit %uch %uHz",
+		audio_encoding_name(pi->encoding),
+		pi->precision,
+		pi->channels,
+		pi->sample_rate);
 #endif
-			return EINVAL;
-		}
-		if (SPECIFIED(ai->mode))
-			pchanges = 1;
+		return EINVAL;
 	}
-	if (rtrack) {
-		rchanges = audio_track_setinfo_check(, ri,
-		>sc_rmixer->hwbuf.fmt);
-		if (rchanges == -1) {
+
+	rchanges = audio_track_setinfo_check(rtrack, , ri);
+	if (rchanges == -1) {
 #if defined(AUDIO_DEBUG)
-			char fmtbuf[64];
-			audio_format2_tostr(fmtbuf, sizeof(fmtbuf), );
-			TRACET(1, rtrack, "check record.params failed: %s",
-			fmtbuf);
+		TRACEF(1, file, "check record.params failed: "
+		"%s %ubit %uch %uHz",
+		audio_encoding_name(ri->encoding),
+		ri->precision,
+		ri->channels,
+		ri->sample_rate);
 #endif
-			return EINVAL;
-		}
-		if (SPECIFIED(ai->mode))
-			rchanges = 1;
+		return EINVAL;
+	}
+
+	if (SPECIFIED(ai->mode)) {
+		pchanges = 1;
+		rchanges = 1;
 	}
 
 	/*
@@ -6849,16 +6859,27 @@ audio_file_setinfo(struct audio_softc *s
 	if (pchanges || rchanges) {
 		audio_file_clear(sc, file);
 #if defined(AUDIO_DEBUG)
+		char nbuf[16];
 		char fmtbuf[64];
 		if (pchanges) {
+			if 

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

2020-03-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Mar 21 15:47:01 UTC 2020

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

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

sys/dev/audio/audiodef.h: revision 1.10
sys/dev/audio/audio.c: revision 1.56 (via patch)
sys/dev/audio/audio.c: revision 1.57
sys/dev/audio/audiovar.h: revision 1.8
sys/dev/audio/audio.c: revision 1.38

Remove obsoleted comment.

Prevent a race between audiodetach and fileops methods using psref(9).
Fix PR kern/54427.
Thank you so much riastradh@

Release memories on audiobellclose.
It's rest of the last commit.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.8 -r1.28.2.9 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.7.2.2 -r1.7.2.3 src/sys/dev/audio/audiodef.h
cvs rdiff -u -r1.4.2.1 -r1.4.2.2 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

2020-03-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Mar 21 15:47:01 UTC 2020

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

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

sys/dev/audio/audiodef.h: revision 1.10
sys/dev/audio/audio.c: revision 1.56 (via patch)
sys/dev/audio/audio.c: revision 1.57
sys/dev/audio/audiovar.h: revision 1.8
sys/dev/audio/audio.c: revision 1.38

Remove obsoleted comment.

Prevent a race between audiodetach and fileops methods using psref(9).
Fix PR kern/54427.
Thank you so much riastradh@

Release memories on audiobellclose.
It's rest of the last commit.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.8 -r1.28.2.9 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.7.2.2 -r1.7.2.3 src/sys/dev/audio/audiodef.h
cvs rdiff -u -r1.4.2.1 -r1.4.2.2 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.8 src/sys/dev/audio/audio.c:1.28.2.9
--- src/sys/dev/audio/audio.c:1.28.2.8	Sat Mar 21 15:41:18 2020
+++ src/sys/dev/audio/audio.c	Sat Mar 21 15:47:00 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.8 2020/03/21 15:41:18 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.9 2020/03/21 15:47:00 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.8 2020/03/21 15:41:18 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.9 2020/03/21 15:47:00 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -499,6 +499,8 @@ static void audio_softintr_wr(void *);
 
 static int  audio_enter_exclusive(struct audio_softc *);
 static void audio_exit_exclusive(struct audio_softc *);
+static struct audio_softc *audio_file_enter(audio_file_t *, struct psref *);
+static void audio_file_exit(struct audio_softc *, struct psref *);
 static int audio_track_waitio(struct audio_softc *, audio_track_t *);
 
 static int audioclose(struct file *);
@@ -519,6 +521,7 @@ static int  filt_audioread_event(struct 
 static int audio_open(dev_t, struct audio_softc *, int, int, struct lwp *,
 	audio_file_t **);
 static int audio_close(struct audio_softc *, audio_file_t *);
+static int audio_unlink(struct audio_softc *, audio_file_t *);
 static int audio_read(struct audio_softc *, struct uio *, int, audio_file_t *);
 static int audio_write(struct audio_softc *, struct uio *, int, audio_file_t *);
 static void audio_file_clear(struct audio_softc *, audio_file_t *);
@@ -530,7 +533,6 @@ static int audio_mmap(struct audio_softc
 	struct uvm_object **, int *, audio_file_t *);
 
 static int audioctl_open(dev_t, struct audio_softc *, int, int, struct lwp *);
-static int audioctl_close(struct audio_softc *, audio_file_t *);
 
 static void audio_pintr(void *);
 static void audio_rintr(void *);
@@ -811,6 +813,8 @@ static const struct portname otable[] = 
 	{ 0, 0 }
 };
 
+static struct psref_class *audio_psref_class __read_mostly;
+
 CFATTACH_DECL3_NEW(audio, sizeof(struct audio_softc),
 audiomatch, audioattach, audiodetach, audioactivate, audiorescan,
 audiochilddet, DVF_DETACH_SHUTDOWN);
@@ -963,6 +967,9 @@ audioattach(device_t parent, device_t se
 		goto bad;
 	}
 
+	sc->sc_psz = pserialize_create();
+	psref_target_init(>sc_psref, audio_psref_class);
+
 	selinit(>sc_wsel);
 	selinit(>sc_rsel);
 
@@ -1220,7 +1227,7 @@ static int
 audiodetach(device_t self, int flags)
 {
 	struct audio_softc *sc;
-	int maj, mn;
+	struct audio_file *file;
 	int error;
 
 	sc = device_private(self);
@@ -1235,6 +1242,9 @@ audiodetach(device_t self, int flags)
 	if (error)
 		return error;
 
+	/* delete sysctl nodes */
+	sysctl_teardown(>sc_log);
+
 	mutex_enter(sc->sc_lock);
 	sc->sc_dying = true;
 	cv_broadcast(>sc_exlockcv);
@@ -1242,23 +1252,36 @@ audiodetach(device_t self, int flags)
 		cv_broadcast(>sc_pmixer->outcv);
 	if (sc->sc_rmixer)
 		cv_broadcast(>sc_rmixer->outcv);
-	mutex_exit(sc->sc_lock);
 
-	/* delete sysctl nodes */
-	sysctl_teardown(>sc_log);
+	/* Prevent new users */
+	SLIST_FOREACH(file, >sc_files, entry) {
+		atomic_store_relaxed(>dying, true);
+	}
+
+	/*
+	 * Wait for existing users to drain.
+	 * - pserialize_perform waits for all pserialize_read sections on
+	 *   all CPUs; after this, no more new psref_acquire can happen.
+	 * - psref_target_destroy waits for all extant acquired psrefs to
+	 *   be psref_released.
+	 */
+	pserialize_perform(sc->sc_psz);
+	mutex_exit(sc->sc_lock);
+	psref_target_destroy(>sc_psref, audio_psref_class);
 
-	/* locate the major number */
-	maj = cdevsw_lookup_major(_cdevsw);
+	/*
+	 * We are now guaranteed that there are no calls to audio fileops
+	 * that hold sc, and any new calls with files that were for sc will
+	 * fail.  Thus, we now have exclusive access to the softc.
+	 */
 

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

2020-03-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Mar 21 15:41:19 UTC 2020

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

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

sys/dev/audio/audio.c: revision 1.42
sys/dev/audio/audio.c: revision 1.47
sys/dev/audio/audiodef.h: revision 1.9

Remove incorrect KASSERT(!mutex_owned()).
Pointed out by riastradh@.

Improve KASSERT messages.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.7 -r1.28.2.8 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.7.2.1 -r1.7.2.2 src/sys/dev/audio/audiodef.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

2020-03-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Mar 21 15:41:19 UTC 2020

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

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

sys/dev/audio/audio.c: revision 1.42
sys/dev/audio/audio.c: revision 1.47
sys/dev/audio/audiodef.h: revision 1.9

Remove incorrect KASSERT(!mutex_owned()).
Pointed out by riastradh@.

Improve KASSERT messages.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.7 -r1.28.2.8 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.7.2.1 -r1.7.2.2 src/sys/dev/audio/audiodef.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.7 src/sys/dev/audio/audio.c:1.28.2.8
--- src/sys/dev/audio/audio.c:1.28.2.7	Tue Jan 21 11:19:19 2020
+++ src/sys/dev/audio/audio.c	Sat Mar 21 15:41:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.7 2020/01/21 11:19:19 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.8 2020/03/21 15:41:18 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.7 2020/01/21 11:19:19 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.8 2020/03/21 15:41:18 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -1357,14 +1357,13 @@ audio_attach_mi(const struct audio_hw_if
 /*
  * Acquire sc_lock and enter exlock critical section.
  * If successful, it returns 0.  Otherwise returns errno.
+ * Must be called without sc_lock held.
  */
 static int
 audio_enter_exclusive(struct audio_softc *sc)
 {
 	int error;
 
-	KASSERT(!mutex_owned(sc->sc_lock));
-
 	mutex_enter(sc->sc_lock);
 	if (sc->sc_dying) {
 		mutex_exit(sc->sc_lock);
@@ -2062,7 +2061,7 @@ audio_open(dev_t dev, struct audio_softc
 		*bellfile = af;
 	} else {
 		error = fd_clone(fp, fd, flags, _fileops, af);
-		KASSERT(error == EMOVEFD);
+		KASSERTMSG(error == EMOVEFD, "error=%d", error);
 	}
 
 	TRACEF(3, af, "done");
@@ -2095,7 +2094,7 @@ bad1:
 }
 
 /*
- * Must NOT called with sc_lock nor sc_exlock held.
+ * Must be called without sc_lock nor sc_exlock held.
  */
 int
 audio_close(struct audio_softc *sc, audio_file_t *file)
@@ -2103,8 +2102,6 @@ audio_close(struct audio_softc *sc, audi
 	audio_track_t *oldtrack;
 	int error;
 
-	KASSERT(!mutex_owned(sc->sc_lock));
-
 	TRACEF(1, file, "%spid=%d.%d po=%d ro=%d",
 	(audiodebug >= 3) ? "start " : "",
 	(int)curproc->p_pid, (int)curlwp->l_lid,
@@ -2205,6 +2202,9 @@ audio_close(struct audio_softc *sc, audi
 	return 0;
 }
 
+/*
+ * Must be called without sc_lock nor sc_exlock held.
+ */
 int
 audio_read(struct audio_softc *sc, struct uio *uio, int ioflag,
 	audio_file_t *file)
@@ -2214,8 +2214,6 @@ audio_read(struct audio_softc *sc, struc
 	audio_ring_t *input;
 	int error;
 
-	KASSERT(!mutex_owned(sc->sc_lock));
-
 	/*
 	 * On half-duplex hardware, O_RDWR is treated as O_WRONLY.
 	 * However read() system call itself can be called because it's
@@ -2332,6 +2330,9 @@ audio_file_clear(struct audio_softc *sc,
 		audio_track_clear(sc, file->rtrack);
 }
 
+/*
+ * Must be called without sc_lock nor sc_exlock held.
+ */
 int
 audio_write(struct audio_softc *sc, struct uio *uio, int ioflag,
 	audio_file_t *file)
@@ -2341,8 +2342,6 @@ audio_write(struct audio_softc *sc, stru
 	audio_ring_t *outbuf;
 	int error;
 
-	KASSERT(!mutex_owned(sc->sc_lock));
-
 	track = file->ptrack;
 	KASSERT(track);
 
@@ -2454,6 +2453,9 @@ abort:
 	return error;
 }
 
+/*
+ * Must be called without sc_lock nor sc_exlock held.
+ */
 int
 audio_ioctl(dev_t dev, struct audio_softc *sc, u_long cmd, void *addr, int flag,
 	struct lwp *l, audio_file_t *file)
@@ -2469,8 +2471,6 @@ audio_ioctl(dev_t dev, struct audio_soft
 	int index;
 	int error;
 
-	KASSERT(!mutex_owned(sc->sc_lock));
-
 #if defined(AUDIO_DEBUG)
 	const char *ioctlnames[] = {
 		" AUDIO_GETINFO",	/* 21 */
@@ -2762,6 +2762,9 @@ audio_track_readablebytes(const audio_tr
 	return bytes;
 }
 
+/*
+ * Must be called without sc_lock nor sc_exlock held.
+ */
 int
 audio_poll(struct audio_softc *sc, int events, struct lwp *l,
 	audio_file_t *file)
@@ -2771,8 +2774,6 @@ audio_poll(struct audio_softc *sc, int e
 	bool in_is_valid;
 	bool out_is_valid;
 
-	KASSERT(!mutex_owned(sc->sc_lock));
-
 #if defined(AUDIO_DEBUG)
 #define POLLEV_BITMAP "\177\020" \
 	"b\10WRBAND\0" \
@@ -2920,13 +2921,14 @@ filt_audiowrite_event(struct knote *kn, 
 	return (track->usrbuf.used < track->usrbuf_usedlow);
 }
 
+/*
+ * Must be called without sc_lock nor sc_exlock held.
+ */
 int
 audio_kqfilter(struct audio_softc *sc, audio_file_t *file, struct knote *kn)
 {
 	struct klist *klist;
 
-	KASSERT(!mutex_owned(sc->sc_lock));
-
 	TRACEF(3, file, "kn=%p kn_filter=%x", kn, (int)kn->kn_filter);
 
 	switch (kn->kn_filter) {
@@ -2953,6 +2955,9 @@ audio_kqfilter(struct 

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

2020-01-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Jan 21 11:19:19 UTC 2020

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

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

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

Fix an resource leak on audiobell close.
audioclose() freed audio_file_t structure, but only audiobellclose
didn't pass there.  I change that all of freeing audio_file_t is done
by each *_close().


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.6 -r1.28.2.7 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.6 src/sys/dev/audio/audio.c:1.28.2.7
--- src/sys/dev/audio/audio.c:1.28.2.6	Tue Jan 21 11:17:58 2020
+++ src/sys/dev/audio/audio.c	Tue Jan 21 11:19:19 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.6 2020/01/21 11:17:58 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.7 2020/01/21 11:19:19 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.6 2020/01/21 11:17:58 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.7 2020/01/21 11:19:19 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -530,6 +530,7 @@ static int audio_mmap(struct audio_softc
 	struct uvm_object **, int *, audio_file_t *);
 
 static int audioctl_open(dev_t, struct audio_softc *, int, int, struct lwp *);
+static int audioctl_close(struct audio_softc *, audio_file_t *);
 
 static void audio_pintr(void *);
 static void audio_rintr(void *);
@@ -1521,7 +1522,7 @@ audioclose(struct file *fp)
 		error = audio_close(sc, file);
 		break;
 	case AUDIOCTL_DEVICE:
-		error = 0;
+		error = audioctl_close(sc, file);
 		break;
 	case MIXER_DEVICE:
 		error = mixer_close(sc, file);
@@ -1530,10 +1531,8 @@ audioclose(struct file *fp)
 		error = ENXIO;
 		break;
 	}
-	if (error == 0) {
-		kmem_free(fp->f_audioctx, sizeof(audio_file_t));
-		fp->f_audioctx = NULL;
-	}
+	/* f_audioctx has already been freed in lower *_close() */
+	fp->f_audioctx = NULL;
 
 	return error;
 }
@@ -2201,6 +2200,8 @@ audio_close(struct audio_softc *sc, audi
 
 	TRACE(3, "done");
 	audio_exit_exclusive(sc);
+
+	kmem_free(file, sizeof(*file));
 	return 0;
 }
 
@@ -3060,6 +3061,14 @@ audioctl_open(dev_t dev, struct audio_so
 	return error;
 }
 
+static int
+audioctl_close(struct audio_softc *sc, audio_file_t *file)
+{
+
+	kmem_free(file, sizeof(*file));
+	return 0;
+}
+
 /*
  * Free 'mem' if available, and initialize the pointer.
  * For this reason, this is implemented as macro.
@@ -7660,6 +7669,7 @@ mixer_close(struct audio_softc *sc, audi
 	mixer_remove(sc);
 	mutex_exit(sc->sc_lock);
 
+	kmem_free(file, sizeof(*file));
 	return 0;
 }
 



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

2020-01-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Jan 21 11:19:19 UTC 2020

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

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

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

Fix an resource leak on audiobell close.
audioclose() freed audio_file_t structure, but only audiobellclose
didn't pass there.  I change that all of freeing audio_file_t is done
by each *_close().


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.6 -r1.28.2.7 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

2020-01-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Jan 21 11:17:58 UTC 2020

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

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

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

Move mutex_exit() correct place to protect sc_async_mixer.
Thanks maxv@!


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.5 -r1.28.2.6 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.5 src/sys/dev/audio/audio.c:1.28.2.6
--- src/sys/dev/audio/audio.c:1.28.2.5	Thu Jan  2 09:18:15 2020
+++ src/sys/dev/audio/audio.c	Tue Jan 21 11:17:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.5 2020/01/02 09:18:15 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.6 2020/01/21 11:17:58 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.5 2020/01/02 09:18:15 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.6 2020/01/21 11:17:58 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -7694,12 +7694,12 @@ mixer_ioctl(struct audio_softc *sc, u_lo
 		}
 		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;
 			sc->sc_async_mixer = ma;
 		}
+		mutex_exit(sc->sc_lock);
 		error = 0;
 		break;
 



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

2020-01-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Jan 21 11:17:58 UTC 2020

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

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

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

Move mutex_exit() correct place to protect sc_async_mixer.
Thanks maxv@!


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.5 -r1.28.2.6 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

2020-01-02 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Jan  2 09:18:15 UTC 2020

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

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

sys/dev/audio/audio.c: revision 1.34
sys/dev/audio/audio.c: revision 1.35

Use M_WAITOK instead of M_NOWAIT.
These allocations don't require NOWAIT constraints.

Will fix PR kern/54796.

 -

Improve and simplify around audio_realloc().


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.4 -r1.28.2.5 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.4 src/sys/dev/audio/audio.c:1.28.2.5
--- src/sys/dev/audio/audio.c:1.28.2.4	Tue Nov 19 12:58:29 2019
+++ src/sys/dev/audio/audio.c	Thu Jan  2 09:18:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.4 2019/11/19 12:58:29 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.5 2020/01/02 09:18: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.4 2019/11/19 12:58:29 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.5 2020/01/02 09:18:15 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -3061,30 +3061,6 @@ audioctl_open(dev_t dev, struct audio_so
 }
 
 /*
- * Reallocate 'memblock' with specified 'bytes' if 'bytes' > 0.
- * Or free 'memblock' and return NULL if 'byte' is zero.
- */
-static void *
-audio_realloc(void *memblock, size_t bytes)
-{
-
-	if (memblock != NULL) {
-		if (bytes != 0) {
-			return kern_realloc(memblock, bytes, M_NOWAIT);
-		} else {
-			kern_free(memblock);
-			return NULL;
-		}
-	} else {
-		if (bytes != 0) {
-			return kern_malloc(bytes, M_NOWAIT);
-		} else {
-			return NULL;
-		}
-	}
-}
-
-/*
  * Free 'mem' if available, and initialize the pointer.
  * For this reason, this is implemented as macro.
  */
@@ -3096,6 +3072,20 @@ audio_realloc(void *memblock, size_t byt
 } while (0)
 
 /*
+ * (Re)allocate 'memblock' with specified 'bytes'.
+ * bytes must not be 0.
+ * This function never returns NULL.
+ */
+static void *
+audio_realloc(void *memblock, size_t bytes)
+{
+
+	KASSERT(bytes != 0);
+	audio_free(memblock);
+	return kern_malloc(bytes, M_WAITOK);
+}
+
+/*
  * (Re)allocate usrbuf with 'newbufsize' bytes.
  * Use this function for usrbuf because only usrbuf can be mmapped.
  * If successful, it updates track->usrbuf.mem, track->usrbuf.capacity and
@@ -3660,7 +3650,6 @@ abort:
 static int
 audio_track_init_codec(audio_track_t *track, audio_ring_t **last_dstp)
 {
-	struct audio_softc *sc;
 	audio_ring_t *last_dst;
 	audio_ring_t *srcbuf;
 	audio_format2_t *srcfmt;
@@ -3671,7 +3660,6 @@ audio_track_init_codec(audio_track_t *tr
 
 	KASSERT(track);
 
-	sc = track->mixer->sc;
 	last_dst = *last_dstp;
 	dstfmt = _dst->fmt;
 	srcfmt = >inputfmt;
@@ -3700,12 +3688,6 @@ audio_track_init_codec(audio_track_t *tr
 		srcbuf->capacity = frame_per_block(track->mixer, >fmt);
 		len = auring_bytelen(srcbuf);
 		srcbuf->mem = audio_realloc(srcbuf->mem, len);
-		if (srcbuf->mem == NULL) {
-			device_printf(sc->sc_dev, "%s: malloc(%d) failed\n",
-			__func__, len);
-			error = ENOMEM;
-			goto abort;
-		}
 
 		arg = >codec.arg;
 		arg->srcfmt = >fmt;
@@ -3731,7 +3713,6 @@ abort:
 static int
 audio_track_init_chvol(audio_track_t *track, audio_ring_t **last_dstp)
 {
-	struct audio_softc *sc;
 	audio_ring_t *last_dst;
 	audio_ring_t *srcbuf;
 	audio_format2_t *srcfmt;
@@ -3742,7 +3723,6 @@ audio_track_init_chvol(audio_track_t *tr
 
 	KASSERT(track);
 
-	sc = track->mixer->sc;
 	last_dst = *last_dstp;
 	dstfmt = _dst->fmt;
 	srcfmt = >inputfmt;
@@ -3770,12 +3750,6 @@ audio_track_init_chvol(audio_track_t *tr
 		srcbuf->capacity = frame_per_block(track->mixer, >fmt);
 		len = auring_bytelen(srcbuf);
 		srcbuf->mem = audio_realloc(srcbuf->mem, len);
-		if (srcbuf->mem == NULL) {
-			device_printf(sc->sc_dev, "%s: malloc(%d) failed\n",
-			__func__, len);
-			error = ENOMEM;
-			goto abort;
-		}
 
 		arg = >chvol.arg;
 		arg->srcfmt = >fmt;
@@ -3786,7 +3760,6 @@ audio_track_init_chvol(audio_track_t *tr
 		return 0;
 	}
 
-abort:
 	track->chvol.filter = NULL;
 	audio_free(srcbuf->mem);
 	return error;
@@ -3801,7 +3774,6 @@ abort:
 static int
 audio_track_init_chmix(audio_track_t *track, audio_ring_t **last_dstp)
 {
-	struct audio_softc *sc;
 	audio_ring_t *last_dst;
 	audio_ring_t *srcbuf;
 	audio_format2_t *srcfmt;
@@ -3814,7 +3786,6 @@ audio_track_init_chmix(audio_track_t *tr
 
 	KASSERT(track);
 
-	sc = track->mixer->sc;
 	last_dst = *last_dstp;
 	dstfmt = _dst->fmt;
 	srcfmt = >inputfmt;
@@ -3845,12 +3816,6 @@ audio_track_init_chmix(audio_track_t *tr
 		srcbuf->capacity = frame_per_block(track->mixer, >fmt);
 		len = auring_bytelen(srcbuf);
 		srcbuf->mem = audio_realloc(srcbuf->mem, len);
-		if 

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

2020-01-02 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Jan  2 09:18:15 UTC 2020

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

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

sys/dev/audio/audio.c: revision 1.34
sys/dev/audio/audio.c: revision 1.35

Use M_WAITOK instead of M_NOWAIT.
These allocations don't require NOWAIT constraints.

Will fix PR kern/54796.

 -

Improve and simplify around audio_realloc().


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.4 -r1.28.2.5 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-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;