CVS commit: src/share/man/man9

2021-08-06 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug  7 03:28:42 UTC 2021

Modified Files:
src/share/man/man9: kauth.9

Log Message:
x68k now uses KAUTH_MACHDEP_UNMANAGEDMEM.


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 src/share/man/man9/kauth.9

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

Modified files:

Index: src/share/man/man9/kauth.9
diff -u src/share/man/man9/kauth.9:1.112 src/share/man/man9/kauth.9:1.113
--- src/share/man/man9/kauth.9:1.112	Sun Jul 15 05:16:41 2018
+++ src/share/man/man9/kauth.9	Sat Aug  7 03:28:42 2021
@@ -1,4 +1,4 @@
-.\" $NetBSD: kauth.9,v 1.112 2018/07/15 05:16:41 maxv Exp $
+.\" $NetBSD: kauth.9,v 1.113 2021/08/07 03:28:42 isaki Exp $
 .\"
 .\" Copyright (c) 2005, 2006 Elad Efrat 
 .\" All rights reserved.
@@ -25,7 +25,7 @@
 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd July 14, 2018
+.Dd August 7, 2021
 .Dt KAUTH 9
 .Os
 .Sh NAME
@@ -1061,6 +1061,7 @@ Affects
 .Em powerpc ,
 .Em sh3 ,
 .Em vax ,
+.Em x68k ,
 .Em xen .
 .El
 .Ss Device Scope



CVS commit: src/sys/arch/x68k/x68k

2021-08-05 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Fri Aug  6 04:21:56 UTC 2021

Modified Files:
src/sys/arch/x68k/x68k: machdep.c

Log Message:
Fix broken mm_md_physacc().
- Fix access to main memory and extended memory.
  This makes /dev/mem work again.
- Introduce kauth(9) to access unmanaged memory area.
  Now you can read/write the internal I/O space via /dev/mem when
  securelevel = -1.
Thanks ryo@, tsutsui@ for advices and reviews.


To generate a diff of this commit:
cvs rdiff -u -r1.205 -r1.206 src/sys/arch/x68k/x68k/machdep.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/arch/x68k/x68k/machdep.c
diff -u src/sys/arch/x68k/x68k/machdep.c:1.205 src/sys/arch/x68k/x68k/machdep.c:1.206
--- src/sys/arch/x68k/x68k/machdep.c:1.205	Thu Feb 11 02:37:11 2021
+++ src/sys/arch/x68k/x68k/machdep.c	Fri Aug  6 04:21:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.205 2021/02/11 02:37:11 tsutsui Exp $	*/
+/*	$NetBSD: machdep.c,v 1.206 2021/08/06 04:21:56 isaki Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -39,7 +39,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.205 2021/02/11 02:37:11 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.206 2021/08/06 04:21:56 isaki Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -1252,15 +1252,28 @@ cpu_intr_p(void)
 int
 mm_md_physacc(paddr_t pa, vm_prot_t prot)
 {
-	uvm_physseg_t i;
+	int i;
 
-	for (i = uvm_physseg_get_first(); uvm_physseg_valid_p(i); i = uvm_physseg_get_next(i)) {
-		if (uvm_physseg_valid_p(i) == false)
-			break;
+	/* Main memory */
+	if (phys_basemem_seg.start <= pa && pa < phys_basemem_seg.end)
+		return 0;
 
-		if (ctob(uvm_physseg_get_start(i)) <= pa &&
-		pa < ctob(uvm_physseg_get_end(i)))
+#ifdef EXTENDED_MEMORY
+	for (i = 0; i < EXTMEM_SEGS; i++) {
+		if (phys_extmem_seg[i].start == phys_extmem_seg[i].end)
+			continue;
+		if (phys_extmem_seg[i].start <= pa &&
+		pa < phys_extmem_seg[i].end) {
 			return 0;
+		}
 	}
+#endif
+
+	/* I/O space */
+	if (INTIOBASE <= pa && pa < INTIOTOP) {
+		return kauth_authorize_machdep(kauth_cred_get(),
+		KAUTH_MACHDEP_UNMANAGEDMEM, NULL, NULL, NULL, NULL);
+	}
+
 	return EFAULT;
 }



CVS commit: src/tests/dev/audio

2021-07-21 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Jul 21 06:18:32 UTC 2021

Modified Files:
src/tests/dev/audio: audiotest.c

Log Message:
Add AUDIO_SETINFO_gain_balance test.
The test checks whether AUDIO_SETINFO can change the gain and the balance
at the same time (if MD driver has the capability).  See PR kern/56308.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/tests/dev/audio/audiotest.c

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

Modified files:

Index: src/tests/dev/audio/audiotest.c
diff -u src/tests/dev/audio/audiotest.c:1.13 src/tests/dev/audio/audiotest.c:1.14
--- src/tests/dev/audio/audiotest.c:1.13	Tue Oct 13 09:00:17 2020
+++ src/tests/dev/audio/audiotest.c	Wed Jul 21 06:18:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiotest.c,v 1.13 2020/10/13 09:00:17 rin Exp $	*/
+/*	$NetBSD: audiotest.c,v 1.14 2021/07/21 06:18:32 isaki Exp $	*/
 
 /*
  * Copyright (C) 2019 Tetsuya Isaki. All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: audiotest.c,v 1.13 2020/10/13 09:00:17 rin Exp $");
+__RCSID("$NetBSD: audiotest.c,v 1.14 2021/07/21 06:18:32 isaki Exp $");
 
 #include 
 #include 
@@ -5573,6 +5573,294 @@ DEF(AUDIO_SETINFO_gain)
 	XP_SYS_EQ(0, r);
 }
 
+/*
+ * Look if there are any (non-zero) gain values that can be changed.
+ * If any gain can be set, it is set to gain[0].
+ * If another gain can be set, it is set to gain[1], otherwise gain[1] = -1.
+ * This is for AUDIO_SETINFO_gain_balance.
+ */
+static void
+get_changeable_gain(int fd, int *gain, const char *dir, int offset)
+{
+	struct audio_info ai;
+	int *ai_gain;
+	int hi;
+	int lo;
+	int r;
+
+	/* A hack to handle ai.{play,record}.gain in the same code.. */
+	ai_gain = (int *)(((char *)) + offset);
+
+	/* Try to set the maximum gain */
+	AUDIO_INITINFO();
+	*ai_gain = AUDIO_MAX_GAIN;
+	r = IOCTL(fd, AUDIO_SETINFO, , "%s.gain=%d", dir, *ai_gain);
+	XP_SYS_EQ(0, r);
+	/* Get again.  The value you set is not always used as is. */
+	AUDIO_INITINFO();
+	r = IOCTL(fd, AUDIO_GETINFO, , "");
+	XP_SYS_EQ(0, r);
+	hi = *ai_gain;
+
+	/* Look for next configurable value. */
+	for (lo = hi - 1; lo >= 0; lo--) {
+		AUDIO_INITINFO();
+		*ai_gain = lo;
+		r = IOCTL(fd, AUDIO_SETINFO, , "%s.gain=%d", dir, *ai_gain);
+		XP_SYS_EQ(0, r);
+		/* Get again */
+		r = IOCTL(fd, AUDIO_GETINFO, , "");
+		XP_SYS_EQ(0, r);
+		if (*ai_gain != hi) {
+			lo = *ai_gain;
+			break;
+		}
+	}
+
+	/* Now gain is lo(=gain[0]). */
+
+	/*
+	 * hi  lo
+	 * --- ---
+	 *  <0  <0  : not available.
+	 * >=0  <0  : available but not changeable.
+	 * >=0 >=0 (hi!=lo) : available and changeable.
+	 */
+	if (hi < 0) {
+		gain[0] = -1;
+		gain[1] = -1;
+		DPRINTF("  > %s.gain cannot be set\n", dir);
+	} else if (lo < 0) {
+		gain[0] = hi;
+		gain[1] = -1;
+		DPRINTF("  > %s.gain can only be set %d\n", dir, gain[0]);
+	} else {
+		gain[0] = lo;
+		gain[1] = hi;
+		DPRINTF("  > %s.gain can be set %d, %d\n",
+		dir, gain[0], gain[1]);
+	}
+}
+
+/*
+ * Look if there are any balance values that can be changed.
+ * If any balance value can be set, it is set to balance[0].
+ * If another balance value can be set, it is set to balance[1],
+ * otherwise balance[1] = -1.
+ * This is for AUDIO_SETINFO_gain_balance.
+ */
+static void
+get_changeable_balance(int fd, int *balance, const char *dir, int offset)
+{
+	struct audio_info ai;
+	u_char *ai_balance;
+	u_char left;
+	u_char right;
+	int r;
+
+	/* A hack to handle ai.{play,record}.balance in the same code.. */
+	ai_balance = ((u_char *)) + offset;
+
+	/* Look for the right side configurable value. */
+	AUDIO_INITINFO();
+	*ai_balance = AUDIO_RIGHT_BALANCE;
+	r = IOCTL(fd, AUDIO_SETINFO, , "%s.balance=%d", dir, *ai_balance);
+	XP_SYS_EQ(0, r);
+	/* Get again.  The value you set is not always used as is. */
+	r = IOCTL(fd, AUDIO_GETINFO, , "");
+	XP_SYS_EQ(0, r);
+	right = *ai_balance;
+
+	/* Look for the left side configurable value. */
+	AUDIO_INITINFO();
+	*ai_balance = AUDIO_LEFT_BALANCE;
+	r = IOCTL(fd, AUDIO_SETINFO, , "%s.balance=%d", dir, *ai_balance);
+	XP_SYS_EQ(0, r);
+	/* Get again */
+	r = IOCTL(fd, AUDIO_GETINFO, , "");
+	XP_SYS_EQ(0, r);
+	left = *ai_balance;
+
+	/* Now balance is the left(=balance[0]). */
+
+	if (left == right) {
+		/* The driver has no balance feature. */
+		balance[0] = left;
+		balance[1] = -1;
+		DPRINTF("  > %s.balance can only be set %d\n",
+		dir, balance[0]);
+	} else {
+		balance[0] = left;
+		balance[1] = right;
+		DPRINTF("  > %s.balance can be set %d, %d\n",
+		dir, balance[0], balance[1]);
+	}
+}
+
+/*
+ * Check whether gain and balance can be set at the same time.
+ * PR kern/56308
+ */
+DEF(AUDIO_SETINFO_gain_balance)
+{
+	struct audio_info oai;
+	stru

CVS commit: src/sys/dev/audio

2021-07-21 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Jul 21 06:14:58 UTC 2021

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
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.104 -r1.105 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.104 src/sys/dev/audio/audio.c:1.105
--- src/sys/dev/audio/audio.c:1.104	Tue Jun  8 09:46:04 2021
+++ src/sys/dev/audio/audio.c	Wed Jul 21 06:14:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.104 2021/06/08 09:46:04 riastradh Exp $	*/
+/*	$NetBSD: audio.c,v 1.105 2021/07/21 06:14:58 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.104 2021/06/08 09:46:04 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.105 2021/07/21 06:14:58 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -7418,59 +7418,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: src/share/man/man4

2021-04-09 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Apr 10 04:10:21 UTC 2021

Modified Files:
src/share/man/man4: hdaudio.4

Log Message:
Fix a wrong description in previous.
MD drivers can support 20 or 24 bits formats even under current MI layer's
constraints.
http://mail-index.netbsd.org/source-changes-d/2021/03/12/msg013255.html


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/share/man/man4/hdaudio.4

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

Modified files:

Index: src/share/man/man4/hdaudio.4
diff -u src/share/man/man4/hdaudio.4:1.19 src/share/man/man4/hdaudio.4:1.20
--- src/share/man/man4/hdaudio.4:1.19	Fri Mar 12 08:03:24 2021
+++ src/share/man/man4/hdaudio.4	Sat Apr 10 04:10:21 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: hdaudio.4,v 1.19 2021/03/12 08:03:24 nia Exp $
+.\"	$NetBSD: hdaudio.4,v 1.20 2021/04/10 04:10:21 isaki Exp $
 .\"
 .\" Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -133,8 +133,8 @@ Handle unsolicited RIRB messages
 .It
 Modem function groups
 .It
-20-bit and 24-bit I/O formats.
-The machine-independent audio layer supports samples with 32-bit precision,
-but these will be converted down to 16-bit before output, because converting
-to a hardware precision that isn't a power of two is not yet handled.
+Hardware formats higher than 16 bits precision.
+Since the machine-independent audio layer converts all input from
+the userland and the hardware layer to 16 bits precision for processing,
+so there is no (or few) merit to support them.
 .El



CVS commit: src/sys/dev

2021-04-02 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Apr  3 04:10:30 UTC 2021

Modified Files:
src/sys/dev: spkr.c spkr_audio.c spkrvar.h
src/sys/dev/isa: spkr_pcppi.c

Log Message:
Rework about the rest note in speaker(4).
- Obsolete the sc_rest callback.  The rest note operation can be done by
  the common spkr layer.  This also fixes PR kern/56060.
  This work-in-progress patch was left in my local tree for years. :(
- Improve calculations of tone and rest length.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/spkr.c
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/spkr_audio.c
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/spkrvar.h
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/isa/spkr_pcppi.c

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

Modified files:

Index: src/sys/dev/spkr.c
diff -u src/sys/dev/spkr.c:1.18 src/sys/dev/spkr.c:1.19
--- src/sys/dev/spkr.c:1.18	Sat Apr  3 03:21:53 2021
+++ src/sys/dev/spkr.c	Sat Apr  3 04:10:30 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: spkr.c,v 1.18 2021/04/03 03:21:53 isaki Exp $	*/
+/*	$NetBSD: spkr.c,v 1.19 2021/04/03 04:10:30 isaki Exp $	*/
 
 /*
  * Copyright (c) 1990 Eric S. Raymond (e...@snark.thyrsus.com)
@@ -43,7 +43,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spkr.c,v 1.18 2021/04/03 03:21:53 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spkr.c,v 1.19 2021/04/03 04:10:30 isaki Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "wsmux.h"
@@ -99,12 +99,10 @@ static void playstring(struct spkr_softc
  *
  * Play string interpretation is modelled on IBM BASIC 2.0's PLAY statement;
  * M[LNS] are missing and the ~ synonym and octave-tracking facility is added.
- * Requires spkr_tone(), spkr_rest(). String play is not interruptible
- * except possibly at physical block boundaries.
+ * String play is not interruptible except possibly at physical block
+ * boundaries.
  */
 
-#define dtoi(c)		((c) - '0')
-
 /*
  * Magic number avoidance...
  */
@@ -156,45 +154,82 @@ playinit(struct spkr_softc *sc)
 	sc->sc_octprefix = true;/* act as though there was an initial O(n) */
 }
 
-/* play tone of proper duration for current rhythm signature */
+#define SPKRPRI (PZERO - 1)
+
+/* Rest for given number of ticks */
+static void
+rest(struct spkr_softc *sc, int ticks)
+{
+
+#ifdef SPKRDEBUG
+	device_printf(sc->sc_dev, "%s: rest for %d ticks\n", __func__, ticks);
+#endif /* SPKRDEBUG */
+	KASSERT(ticks > 0);
+
+	tsleep(sc->sc_dev, SPKRPRI | PCATCH, device_xname(sc->sc_dev), ticks);
+}
+
+/*
+ * Play tone of proper duration for current rhythm signature.
+ * note indicates "O0C" = 0, "O0C#" = 1, "O0D" = 2, ... , and
+ * -1 indiacates a rest.
+ * val indicates the length, "L4" = 4, "L8" = 8.
+ * sustain indicates the number of subsequent dots that extend the sound
+ * by one a half.
+ */
 static void
-playtone(struct spkr_softc *sc, int pitch, int val, int sustain)
+playtone(struct spkr_softc *sc, int note, int val, int sustain)
 {
-	int sound, silence, snum = 1, sdenom = 1;
+	int whole;
+	int total;
+	int sound;
+	int silence;
 
 	/* this weirdness avoids floating-point arithmetic */
+	whole = sc->sc_whole;
 	for (; sustain; sustain--) {
-		snum *= NUM_MULT;
-		sdenom *= DENOM_MULT;
+		whole *= NUM_MULT;
+		val *= DENOM_MULT;
 	}
 
-	if (pitch == -1) {
-		(*sc->sc_rest)(sc->sc_dev, sc->sc_whole
-		* snum / (val * sdenom));
+	/* Total length in tick */
+	total = whole / val;
+
+	if (note == -1) {
+#ifdef SPKRDEBUG
+		device_printf(sc->sc_dev, "%s: rest for %d ticks\n",
+		__func__, total);
+#endif /* SPKRDEBUG */
+		if (total != 0)
+			rest(sc, total);
 		return;
 	}
 
-	int fac = sc->sc_whole * (FILLTIME - sc->sc_fill);
-	int fval = FILLTIME * val;
-	sound = (sc->sc_whole * snum) / (val * sdenom) -  fac / fval;
-	silence = fac * snum / (fval * sdenom);
+	/*
+	 * Rest 1/8 (if NORMAL) or 3/8 (if STACCATO) in tick.
+	 * silence should be rounded down.
+	 */
+	silence = total * (FILLTIME - sc->sc_fill) / FILLTIME;
+	sound = total - silence;
 
 #ifdef SPKRDEBUG
 	device_printf(sc->sc_dev,
-	"%s: pitch %d for %d ticks, rest for %d ticks\n", __func__,
-	pitch, sound, silence);
+	"%s: note %d for %d ticks, rest for %d ticks\n", __func__,
+	note, sound, silence);
 #endif /* SPKRDEBUG */
 
-	(*sc->sc_tone)(sc->sc_dev, pitchtab[pitch], sound);
-	if (sc->sc_fill != LEGATO)
-		(*sc->sc_rest)(sc->sc_dev, silence);
+	if (sound != 0)
+		(*sc->sc_tone)(sc->sc_dev, pitchtab[note], sound);
+	if (silence != 0)
+		rest(sc, silence);
 }
 
 /* interpret and play an item from a notation string */
 static void
 playstring(struct spkr_softc *sc, const char *cp, size_t slen)
 {
-	int		pitch, lastpitch = OCTAVE_NOTES * DFLT_OCTAVE;
+	int pitch;
+	int lastpitch = OCTAVE_NOTES * DFLT_OCTAVE;
 
 #define GETNUM(cp, v)	\
 	for (v = 0; slen > 0 && isdigit((unsigned char)cp[1]); ) { \
@@ -357,16 +392,26 @@ playstring(struct spkr_softc *sc, const 
 	}
 }
 
-/*** UNIX DRIVER HOOKS BEGIN 

CVS commit: src/sys/dev

2021-04-02 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Apr  3 03:21:53 UTC 2021

Modified Files:
src/sys/dev: spkr.c spkr_audio.c
src/sys/dev/isa: spkr_pcppi.c

Log Message:
Improve SPKRDEBUG code.
- Replace wrong aprint_debug_dev() with device_printf().
  By this, it no longer need to print dev_t.
- Improve some messages.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/spkr.c
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/spkr_audio.c
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/isa/spkr_pcppi.c

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

Modified files:

Index: src/sys/dev/spkr.c
diff -u src/sys/dev/spkr.c:1.17 src/sys/dev/spkr.c:1.18
--- src/sys/dev/spkr.c:1.17	Thu Apr 18 13:01:38 2019
+++ src/sys/dev/spkr.c	Sat Apr  3 03:21:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: spkr.c,v 1.17 2019/04/18 13:01:38 isaki Exp $	*/
+/*	$NetBSD: spkr.c,v 1.18 2021/04/03 03:21:53 isaki Exp $	*/
 
 /*
  * Copyright (c) 1990 Eric S. Raymond (e...@snark.thyrsus.com)
@@ -43,7 +43,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spkr.c,v 1.17 2019/04/18 13:01:38 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spkr.c,v 1.18 2021/04/03 03:21:53 isaki Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "wsmux.h"
@@ -180,7 +180,7 @@ playtone(struct spkr_softc *sc, int pitc
 	silence = fac * snum / (fval * sdenom);
 
 #ifdef SPKRDEBUG
-	aprint_debug_dev(sc->sc_dev,
+	device_printf(sc->sc_dev,
 	"%s: pitch %d for %d ticks, rest for %d ticks\n", __func__,
 	pitch, sound, silence);
 #endif /* SPKRDEBUG */
@@ -207,7 +207,11 @@ playstring(struct spkr_softc *sc, const 
 		char c = toupper((unsigned char)*cp);
 
 #ifdef SPKRDEBUG
-		aprint_debug_dev(sc->sc_dev, "%s: %c (%x)\n", __func__, c, c);
+		if (0x20 <= c && c < 0x7f) {
+			device_printf(sc->sc_dev, "%s: '%c'\n", __func__, c);
+		} else {
+			device_printf(sc->sc_dev, "%s: (0x%x)\n", __func__, c);
+		}
 #endif /* SPKRDEBUG */
 
 		switch (c) {
@@ -431,11 +435,11 @@ spkr_childdet(device_t self, device_t ch
 int
 spkropen(dev_t dev, int	flags, int mode, struct lwp *l)
 {
-#ifdef SPKRDEBUG
-	aprint_debug("%s: entering with dev = %"PRIx64"\n", __func__, dev);
-#endif /* SPKRDEBUG */
 	struct spkr_softc *sc = spkrenter(minor(dev));
 
+#ifdef SPKRDEBUG
+	device_printf(sc->sc_dev, "%s: entering\n", __func__);
+#endif /* SPKRDEBUG */
 	if (sc == NULL)
 		return ENXIO;
 	if (sc->sc_inbuf != NULL)
@@ -449,12 +453,12 @@ spkropen(dev_t dev, int	flags, int mode,
 int
 spkrwrite(dev_t dev, struct uio *uio, int flags)
 {
-#ifdef SPKRDEBUG
-	aprint_debug("%s: entering with dev = %"PRIx64", count = %zu\n",
-	__func__, dev, uio->uio_resid);
-#endif /* SPKRDEBUG */
 	struct spkr_softc *sc = spkrenter(minor(dev));
 
+#ifdef SPKRDEBUG
+	device_printf(sc->sc_dev, "%s: entering with length = %zu\n",
+	__func__, uio->uio_resid);
+#endif /* SPKRDEBUG */
 	if (sc == NULL)
 		return ENXIO;
 	if (sc->sc_inbuf == NULL)
@@ -471,11 +475,11 @@ spkrwrite(dev_t dev, struct uio *uio, in
 int
 spkrclose(dev_t dev, int flags, int mode, struct lwp *l)
 {
-#ifdef SPKRDEBUG
-	aprint_debug("%s: entering with dev = %"PRIx64"\n", __func__, dev);
-#endif /* SPKRDEBUG */
 	struct spkr_softc *sc = spkrenter(minor(dev));
 
+#ifdef SPKRDEBUG
+	device_printf(sc->sc_dev, "%s: entering\n", __func__);
+#endif /* SPKRDEBUG */
 	if (sc == NULL)
 		return ENXIO;
 	if (sc->sc_inbuf == NULL)
@@ -500,16 +504,15 @@ playonetone(struct spkr_softc *sc, tone_
 int
 spkrioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
 {
+	struct spkr_softc *sc = spkrenter(minor(dev));
 	tone_t *tp;
 	tone_t ttp;
 	int error;
+
 #ifdef SPKRDEBUG
-	aprint_debug("%s: entering with dev = %"PRIx64", cmd = %lx\n",
-	__func__, dev, cmd);
+	device_printf(sc->sc_dev, "%s: entering with cmd = %lx\n",
+	__func__, cmd);
 #endif /* SPKRDEBUG */
-
-	struct spkr_softc *sc = spkrenter(minor(dev));
-
 	if (sc == NULL)
 		return ENXIO;
 	if (sc->sc_inbuf == NULL)

Index: src/sys/dev/spkr_audio.c
diff -u src/sys/dev/spkr_audio.c:1.9 src/sys/dev/spkr_audio.c:1.10
--- src/sys/dev/spkr_audio.c:1.9	Wed Feb 17 12:37:33 2021
+++ src/sys/dev/spkr_audio.c	Sat Apr  3 03:21:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: spkr_audio.c,v 1.9 2021/02/17 12:37:33 isaki Exp $	*/
+/*	$NetBSD: spkr_audio.c,v 1.10 2021/04/03 03:21:53 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spkr_audio.c,v 1.9 2021/02/17 12:37:33 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spkr_audio.c,v 1.10 2021/04/03 03:21:53 isaki Exp $");
 
 #include 
 #include 
@@ -69,7 +69,7 @@ spkr_audio_tone(device_t self, u_int xhz
 	struct spkr_audio_softc *sc = device_private(self);
 
 #ifdef SPKRDEBUG
-	aprint_debug_dev(self, "%s: %u %d\n", __func__, xhz, ticks);
+	device_printf(self, "%s: %u %u\n", __func__, xhz, ticks);
 #endif /* SPKRDEBUG */
 	audiobell(sc->sc_audiodev, xhz, hztoms(ticks),
 	sc->sc_spkr.sc_vol, 0);


CVS commit: src/share/man/man9

2021-03-28 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Mar 28 07:42:06 UTC 2021

Modified Files:
src/share/man/man9: audio.9

Log Message:
Update documents.
- query_format has been mandatory (since at least Feb 2020).
- set_params has been replaced to set_format (since May 2019).


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/share/man/man9/audio.9

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

Modified files:

Index: src/share/man/man9/audio.9
diff -u src/share/man/man9/audio.9:1.60 src/share/man/man9/audio.9:1.61
--- src/share/man/man9/audio.9:1.60	Sat Feb  6 13:55:40 2021
+++ src/share/man/man9/audio.9	Sun Mar 28 07:42:06 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: audio.9,v 1.60 2021/02/06 13:55:40 nia Exp $
+.\"	$NetBSD: audio.9,v 1.61 2021/03/28 07:42:06 isaki Exp $
 .\"
 .\" Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -241,17 +241,13 @@ The
 and
 .Va rec
 structures contain the encoding parameters that should be set to the hardware.
-If the driver has query_format, all parameters on
-.Va play
-and/or
-.Va rec
-are chosen from formats returned by query_format.
+All of these parameters are chosen from formats returned by
+.Va query_format .
 Therefore
 .Va play
 and/or
 .Va rec
 are always settable.
-If the driver does not have query_format, the driver has to validate the format.
 If the hardware does not support
 .Dv AUDIO_ENCODING_SLINEAR_{NE,OE}:16 ,
 conversion information should be filled the
@@ -355,7 +351,7 @@ The return value also must be non-zero a
 It is called in the Attach or Closed phases.
 .It Dv int commit_settings(void *hdl)
 optional, is called after all calls to
-.Va set_params ,
+.Va set_format ,
 and
 .Va set_port ,
 are done.



CVS commit: src/sys/dev/audio

2021-03-19 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Mar 20 04:56:52 UTC 2021

Modified Files:
src/sys/dev/audio: audiobell.c

Log Message:
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.4 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.4
--- src/sys/dev/audio/audiobell.c:1.3	Wed Jun 26 06:57:45 2019
+++ src/sys/dev/audio/audiobell.c	Sat Mar 20 04:56:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiobell.c,v 1.3 2019/06/26 06:57:45 isaki Exp $	*/
+/*	$NetBSD: audiobell.c,v 1.4 2021/03/20 04:56:52 isaki 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.4 2021/03/20 04:56:52 isaki 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: src/sys/arch/m68k/fpe

2021-03-08 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Mon Mar  8 14:37:55 UTC 2021

Modified Files:
src/sys/arch/m68k/fpe: fpu_explode.c

Log Message:
Remove incorrect byte and word conversions from fpu_explode.
The correct operation here is arithmetic right shift, but nobody calls it.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/m68k/fpe/fpu_explode.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/arch/m68k/fpe/fpu_explode.c
diff -u src/sys/arch/m68k/fpe/fpu_explode.c:1.15 src/sys/arch/m68k/fpe/fpu_explode.c:1.16
--- src/sys/arch/m68k/fpe/fpu_explode.c:1.15	Thu Feb  5 12:23:27 2015
+++ src/sys/arch/m68k/fpe/fpu_explode.c	Mon Mar  8 14:37:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu_explode.c,v 1.15 2015/02/05 12:23:27 isaki Exp $ */
+/*	$NetBSD: fpu_explode.c,v 1.16 2021/03/08 14:37:55 isaki Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -46,7 +46,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fpu_explode.c,v 1.15 2015/02/05 12:23:27 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu_explode.c,v 1.16 2021/03/08 14:37:55 isaki Exp $");
 
 #include 
 #include 
@@ -230,11 +230,6 @@ fpu_explode(struct fpemu *fe, struct fpn
 	fp->fp_sign = s >> 31;
 	fp->fp_sticky = 0;
 	switch (type) {
-
-	case FTYPE_BYT:
-		s >>= 8;
-	case FTYPE_WRD:
-		s >>= 16;
 	case FTYPE_LNG:
 		s = fpu_itof(fp, s);
 		break;
@@ -251,6 +246,10 @@ fpu_explode(struct fpemu *fe, struct fpn
 		s = fpu_xtof(fp, s, space[1], space[2]);
 		break;
 
+	case FTYPE_BYT:
+	case FTYPE_WRD:
+		/* Caller must cast it to signed LNG instead of calling this */
+		/* FALLTHROUGH */
 	default:
 		panic("fpu_explode");
 	}



CVS commit: src/sys/dev

2021-02-17 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Feb 17 12:37:33 UTC 2021

Modified Files:
src/sys/dev: spkr_audio.c

Log Message:
Attach this only if the parent device has playback capability.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/spkr_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/spkr_audio.c
diff -u src/sys/dev/spkr_audio.c:1.8 src/sys/dev/spkr_audio.c:1.9
--- src/sys/dev/spkr_audio.c:1.8	Fri Jun 21 09:34:30 2019
+++ src/sys/dev/spkr_audio.c	Wed Feb 17 12:37:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: spkr_audio.c,v 1.8 2019/06/21 09:34:30 isaki Exp $	*/
+/*	$NetBSD: spkr_audio.c,v 1.9 2021/02/17 12:37:33 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss 
@@ -27,10 +27,11 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spkr_audio.c,v 1.8 2019/06/21 09:34:30 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spkr_audio.c,v 1.9 2021/02/17 12:37:33 isaki Exp $");
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -41,7 +42,7 @@ __KERNEL_RCSID(0, "$NetBSD: spkr_audio.c
 #include 
 #include 
 
-#include 
+#include 
 #include 
 
 #include 
@@ -90,8 +91,12 @@ spkr_audio_rest(device_t self, int ticks
 static int
 spkr_audio_probe(device_t parent, cfdata_t cf, void *aux)
 {
+	struct audio_softc *asc = device_private(parent);
 
-	return 1;
+	if ((asc->sc_props & AUDIO_PROP_PLAYBACK))
+		return 1;
+
+	return 0;
 }
 
 static void



CVS commit: src/sys/dev/usb

2021-02-15 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Mon Feb 15 13:39:18 UTC 2021

Modified Files:
src/sys/dev/usb: uaudio.c

Log Message:
Fix my copy-and-paste bug in rev1.160.
This fixes recording sample dropout.


To generate a diff of this commit:
cvs rdiff -u -r1.168 -r1.169 src/sys/dev/usb/uaudio.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/usb/uaudio.c
diff -u src/sys/dev/usb/uaudio.c:1.168 src/sys/dev/usb/uaudio.c:1.169
--- src/sys/dev/usb/uaudio.c:1.168	Sun Jan 10 15:50:16 2021
+++ src/sys/dev/usb/uaudio.c	Mon Feb 15 13:39:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uaudio.c,v 1.168 2021/01/10 15:50:16 ryoon Exp $	*/
+/*	$NetBSD: uaudio.c,v 1.169 2021/02/15 13:39:18 isaki Exp $	*/
 
 /*
  * Copyright (c) 1999, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.168 2021/01/10 15:50:16 ryoon Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.169 2021/02/15 13:39:18 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -3020,7 +3020,8 @@ uaudio_set_format(void *addr, int setmod
 		raltidx = audio_indexof_format(sc->sc_formats, sc->sc_nformats,
 		AUMODE_RECORD, rec);
 		/* Transfer should have halted */
-		uaudio_chan_init(>sc_recchan, raltidx, rec, 0);
+		uaudio_chan_init(>sc_recchan, raltidx, rec,
+		UGETW(sc->sc_alts[raltidx].edesc->wMaxPacketSize));
 	}
 
 	if ((setmode & AUMODE_PLAY) && sc->sc_playchan.altidx != -1) {



CVS commit: src/sys/dev/audio

2021-02-13 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Feb 14 03:41:13 UTC 2021

Modified Files:
src/sys/dev/audio: audio.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 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.90 src/sys/dev/audio/audio.c:1.91
--- src/sys/dev/audio/audio.c:1.90	Tue Feb  9 12:36:34 2021
+++ src/sys/dev/audio/audio.c	Sun Feb 14 03:41:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.90 2021/02/09 12:36:34 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.91 2021/02/14 03:41:13 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.90 2021/02/09 12:36:34 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.91 2021/02/14 03:41:13 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -1544,9 +1544,6 @@ audio_sc_acquire_foropen(struct audio_so
 {
 	int s;
 
-	/* psref(9) forbids to migrate CPUs */
-	curlwp_bind();
-
 	/* Block audiodetach while we acquire a reference */
 	s = pserialize_read_enter();
 
@@ -1574,9 +1571,6 @@ audio_sc_acquire_fromfile(audio_file_t *
 	int s;
 	bool dying;
 
-	/* psref(9) forbids to migrate CPUs */
-	curlwp_bind();
-
 	/* Block audiodetach while we acquire a reference */
 	s = pserialize_read_enter();
 
@@ -1679,6 +1673,7 @@ audioopen(dev_t dev, int flags, int ifmt
 {
 	struct audio_softc *sc;
 	struct psref sc_ref;
+	int bound;
 	int error;
 
 	/* Find the device */
@@ -1686,6 +1681,7 @@ audioopen(dev_t dev, int flags, int ifmt
 	if (sc == NULL || sc->hw_if == NULL)
 		return ENXIO;
 
+	bound = curlwp_bind();
 	audio_sc_acquire_foropen(sc, _ref);
 
 	error = audio_exlock_enter(sc);
@@ -1712,6 +1708,7 @@ audioopen(dev_t dev, int flags, int ifmt
 
 done:
 	audio_sc_release(sc, _ref);
+	curlwp_bindx(bound);
 	return error;
 }
 
@@ -1721,6 +1718,7 @@ audioclose(struct file *fp)
 	struct audio_softc *sc;
 	struct psref sc_ref;
 	audio_file_t *file;
+	int bound;
 	int error;
 	dev_t dev;
 
@@ -1736,6 +1734,7 @@ audioclose(struct file *fp)
 	 * - free all memory objects, regardless of sc.
 	 */
 
+	bound = curlwp_bind();
 	sc = audio_sc_acquire_fromfile(file, _ref);
 	if (sc) {
 		switch (AUDIODEV(dev)) {
@@ -1756,6 +1755,7 @@ audioclose(struct file *fp)
 
 		audio_sc_release(sc, _ref);
 	}
+	curlwp_bindx(bound);
 
 	/* Free memory objects anyway */
 	TRACEF(2, file, "free memory");
@@ -1776,6 +1776,7 @@ audioread(struct file *fp, off_t *offp, 
 	struct audio_softc *sc;
 	struct psref sc_ref;
 	audio_file_t *file;
+	int bound;
 	int error;
 	dev_t dev;
 
@@ -1783,9 +1784,12 @@ audioread(struct file *fp, off_t *offp, 
 	file = fp->f_audioctx;
 	dev = file->dev;
 
+	bound = curlwp_bind();
 	sc = audio_sc_acquire_fromfile(file, _ref);
-	if (sc == NULL)
-		return EIO;
+	if (sc == NULL) {
+		error = EIO;
+		goto done;
+	}
 
 	if (fp->f_flag & O_NONBLOCK)
 		ioflag |= IO_NDELAY;
@@ -1805,6 +1809,8 @@ audioread(struct file *fp, off_t *offp, 
 	}
 
 	audio_sc_release(sc, _ref);
+done:
+	curlwp_bindx(bound);
 	return error;
 }
 
@@ -1815,6 +1821,7 @@ audiowrite(struct file *fp, off_t *offp,
 	struct audio_softc *sc;
 	struct psref sc_ref;
 	audio_file_t *file;
+	int bound;
 	int error;
 	dev_t dev;
 
@@ -1822,9 +1829,12 @@ audiowrite(struct file *fp, off_t *offp,
 	file = fp->f_audioctx;
 	dev = file->dev;
 
+	bound = curlwp_bind();
 	sc = audio_sc_acquire_fromfile(file, _ref);
-	if (sc == NULL)
-		return EIO;
+	if (sc == NULL) {
+		error = EIO;
+		goto done;
+	}
 
 	if (fp->f_flag & O_NONBLOCK)
 		ioflag |= IO_NDELAY;
@@ -1844,6 +1854,8 @@ audiowrite(struct file *fp, off_t *offp,
 	}
 
 	audio_sc_release(sc, _ref);
+done:
+	curlwp_bindx(bound);
 	return error;
 }
 
@@ -1854,6 +1866,7 @@ audioioctl(struct file *fp, u_long cmd, 
 	struct psref sc_ref;
 	audio_file_t *file;
 	struct lwp *l = curlwp;
+	int bound;
 	int error;
 	dev_t dev;
 
@@ -1861,9 +1874,12 @@ audioioctl(struct file *fp, u_long cmd, 
 	file = fp->f_audioctx;
 	dev = file->dev;
 
+	bound = curlwp_bind();
 	sc = audio_sc_acquire_fromfile(file, _ref);
-	if (sc == NULL)
-		return EIO;
+	if (sc == NULL) {
+		error = EIO;
+		goto done;
+	}
 
 	switch (AUDIODEV(dev)) {
 	case SOUND_DEVICE:
@@ -1887,6 +1903,8 @@ audioioctl(struct file *fp, u_long cmd, 
 	}
 
 	audio_sc_release(sc, _ref);
+done:
+	curlwp_bindx(bound);
 	return error;
 }
 
@@ -1896,14 +1914,20 @@ audiostat(struct file *fp, struct stat *
 	struct audio_softc *sc;
 	struct psref sc_ref;
 	audio_file_t *file;
+	int bound;
+	int error;
 
 	KASSERT(fp->f_audioctx);
 	file = fp->f_audioctx;
 
+	bound = curlwp_bind();
 	sc = audio_sc_acquire_fromfile(file, _ref);
-	if (sc == NULL)
-		return EIO;
+	if (sc == NULL) {
+		error = EIO;
+		goto done;
+	}
 
+	

CVS commit: src/sys/arch/dreamcast/dev/g2

2021-02-09 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Tue Feb  9 12:39:28 UTC 2021

Modified Files:
src/sys/arch/dreamcast/dev/g2: aica.c

Log Message:
Update function name in a comment.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/dreamcast/dev/g2/aica.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/arch/dreamcast/dev/g2/aica.c
diff -u src/sys/arch/dreamcast/dev/g2/aica.c:1.29 src/sys/arch/dreamcast/dev/g2/aica.c:1.30
--- src/sys/arch/dreamcast/dev/g2/aica.c:1.29	Sat Feb  6 09:14:03 2021
+++ src/sys/arch/dreamcast/dev/g2/aica.c	Tue Feb  9 12:39:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: aica.c,v 1.29 2021/02/06 09:14:03 isaki Exp $	*/
+/*	$NetBSD: aica.c,v 1.30 2021/02/09 12:39:28 isaki Exp $	*/
 
 /*
  * Copyright (c) 2003 SHIMIZU Ryo 
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: aica.c,v 1.29 2021/02/06 09:14:03 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: aica.c,v 1.30 2021/02/09 12:39:28 isaki Exp $");
 
 #include 
 #include 
@@ -530,7 +530,7 @@ aica_intr(void *arg)
 
 	aica_fillbuffer(sc);
 
-	/* call audio interrupt handler (audio_pint()) */
+	/* call audio interrupt handler (audio_pintr()) */
 	if (sc->sc_intr != NULL) {
 		(*(sc->sc_intr))(sc->sc_intr_arg);
 	}



CVS commit: src/sys/dev/audio

2021-02-09 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Tue Feb  9 12:36:34 UTC 2021

Modified Files:
src/sys/dev/audio: audio.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 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.89 src/sys/dev/audio/audio.c:1.90
--- src/sys/dev/audio/audio.c:1.89	Tue Feb  9 05:53:14 2021
+++ src/sys/dev/audio/audio.c	Tue Feb  9 12:36:34 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.89 2021/02/09 05:53:14 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.90 2021/02/09 12:36:34 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.89 2021/02/09 05:53:14 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.90 2021/02/09 12:36:34 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -521,8 +521,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 *);
@@ -1302,7 +1304,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);
@@ -1531,11 +1536,40 @@ 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;
+
+	/* psref(9) forbids to migrate CPUs */
+	curlwp_bind();
+
+	/* 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)
+audio_sc_acquire_fromfile(audio_file_t *file, struct psref *refp)
 {
 	int s;
 	bool dying;
@@ -1563,10 +1597,10 @@ audio_file_enter(audio_file_t *file, str
 }
 
 /*
- * Decrement the psref count.
+ * Decrement reference counter for this sc.
  */
 void
-audio_file_exit(struct audio_softc *sc, struct psref *refp)
+audio_sc_release(struct audio_softc *sc, struct psref *refp)
 {
 
 	psref_release(refp, >sc_psref, audio_psref_class);
@@ -1644,6 +1678,7 @@ static int
 audioopen(dev_t dev, int flags, int ifmt, struct lwp *l)
 {
 	struct audio_softc *sc;
+	struct psref sc_ref;
 	int error;
 
 	/* Find the device */
@@ -1651,9 +1686,11 @@ audioopen(dev_t dev, int flags, int ifmt
 	if (sc == NULL || sc->hw_if == NULL)
 		return ENXIO;
 
+	audio_sc_acquire_foropen(sc, _ref);
+
 	error = audio_exlock_enter(sc);
 	if (error)
-		return error;
+		goto done;
 
 	device_active(sc->sc_dev, DVA_SYSTEM);
 	switch (AUDIODEV(dev)) {
@@ -1673,6 +1710,8 @@ audioopen(dev_t dev, int flags, int ifmt
 	}
 	audio_exlock_exit(sc);
 
+done:
+	audio_sc_release(sc, _ref);
 	return error;
 }
 
@@ -1697,7 +1736,7 @@ audioclose(struct file *fp)
 	 * - free all memory objects, regardless of sc.
 	 */
 
-	sc = audio_file_enter(file, _ref);
+	sc = audio_sc_acquire_fromfile(file, _ref);
 	if (sc) {
 		switch 

CVS commit: src/sys/dev/audio

2021-02-08 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Tue Feb  9 05:53:14 UTC 2021

Modified Files:
src/sys/dev/audio: audio.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 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.88 src/sys/dev/audio/audio.c:1.89
--- src/sys/dev/audio/audio.c:1.88	Fri Jan 15 05:34:49 2021
+++ src/sys/dev/audio/audio.c	Tue Feb  9 05:53:14 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.88 2021/01/15 05:34:49 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.89 2021/02/09 05:53:14 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.88 2021/01/15 05:34:49 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.89 2021/02/09 05:53:14 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -1334,9 +1334,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) {
@@ -1359,7 +1360,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));
@@ -2396,6 +2396,7 @@ bad:
 int
 audio_close(struct audio_softc *sc, audio_file_t *file)
 {
+	int error;
 
 	/* Protect entering new fileops to this file */
 	atomic_store_relaxed(>dying, true);
@@ -2410,12 +2411,27 @@ audio_close(struct audio_softc *sc, audi
 		mutex_exit(sc->sc_lock);
 	}
 
-	return audio_unlink(sc, file);
+	error = audio_exlock_enter(sc);
+	if (error) {
+		/*
+		 * If EIO, this sc is about to detach.  In this case, even if
+		 * we don't do subsequent _unlink(), audiodetach() will do it.
+		 */
+		if (error == EIO)
+			return error;
+
+		/* XXX This should not happen but what should I do ? */
+		panic("%s: can't acquire exlock: errno=%d", __func__, error);
+	}
+	error = audio_unlink(sc, file);
+	audio_exlock_exit(sc);
+
+	return error;
 }
 
 /*
  * Unlink this file, but not freeing memory here.
- * Must be called without sc_lock nor sc_exlock held.
+ * Must be called with sc_exlock held and without sc_lock held.
  */
 int
 audio_unlink(struct audio_softc *sc, audio_file_t *file)
@@ -2432,25 +2448,6 @@ audio_unlink(struct audio_softc *sc, aud
 	"sc->sc_popens=%d, sc->sc_ropens=%d",
 	sc->sc_popens, sc->sc_ropens);
 
-	/*
-	 * Acquire exlock to protect counters.
-	 * audio_exlock_enter() cannot be used here because we have to go
-	 * forward even if sc_dying is set.
-	 */
-	while (__predict_false(sc->sc_exlock != 0)) {
-		error = cv_timedwait_sig(>sc_exlockcv, sc->sc_lock,
-		mstohz(AUDIO_TIMEOUT));
-		/* XXX what should I do on error? */
-		if (error == EWOULDBLOCK) {
-			mutex_exit(sc->sc_lock);
-			audio_printf(sc,
-			"%s: cv_timedwait_sig failed: errno=%d\n",
-			__func__, error);
-			return error;
-		}
-	}
-	sc->sc_exlock = 1;
-
 	device_active(sc->sc_dev, DVA_SYSTEM);
 
 	mutex_enter(sc->sc_intr_lock);
@@ -2517,7 +2514,6 @@ audio_unlink(struct audio_softc *sc, aud
 		kauth_cred_free(sc->sc_cred);
 
 	TRACE(3, "done");
-	audio_exlock_exit(sc);
 
 	return 0;
 }



CVS commit: src/sys/dev/sbus

2021-02-06 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb  6 13:02:28 UTC 2021

Modified Files:
src/sys/dev/sbus: dbri.c

Log Message:
Remove an extra mutex_spin_exit() in error path.
This is a part of rev 1.38.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/dev/sbus/dbri.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/sbus/dbri.c
diff -u src/sys/dev/sbus/dbri.c:1.44 src/sys/dev/sbus/dbri.c:1.45
--- src/sys/dev/sbus/dbri.c:1.44	Sat Feb  6 09:15:11 2021
+++ src/sys/dev/sbus/dbri.c	Sat Feb  6 13:02:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: dbri.c,v 1.44 2021/02/06 09:15:11 isaki Exp $	*/
+/*	$NetBSD: dbri.c,v 1.45 2021/02/06 13:02:28 isaki Exp $	*/
 
 /*
  * Copyright (C) 1997 Rudolf Koenig (rfkoe...@immd4.informatik.uni-erlangen.de)
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dbri.c,v 1.44 2021/02/06 09:15:11 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dbri.c,v 1.45 2021/02/06 13:02:28 isaki Exp $");
 
 #include "audio.h"
 #if NAUDIO > 0
@@ -1065,7 +1065,6 @@ mmcodec_setcontrol(struct dbri_softc *sc
 		if (error == EINTR) {
 			DPRINTF("%s: interrupted\n", device_xname(sc->sc_dev));
 			ret = -1;
-			mutex_spin_exit(>sc_intr_lock);
 			goto fail;
 		}
 		bail++;



CVS commit: src/sys/dev/pci

2021-02-06 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb  6 12:59:13 UTC 2021

Modified Files:
src/sys/dev/pci: yds.c

Log Message:
Remove an extra mutex_spin_exit() in yds_resume().
This one has been moved to before yds_init() in rev 1.59.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/dev/pci/yds.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/pci/yds.c
diff -u src/sys/dev/pci/yds.c:1.65 src/sys/dev/pci/yds.c:1.66
--- src/sys/dev/pci/yds.c:1.65	Sat Feb 29 05:51:11 2020
+++ src/sys/dev/pci/yds.c	Sat Feb  6 12:59:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: yds.c,v 1.65 2020/02/29 05:51:11 isaki Exp $	*/
+/*	$NetBSD: yds.c,v 1.66 2021/02/06 12:59:13 isaki Exp $	*/
 
 /*
  * Copyright (c) 2000, 2001 Kazuki Sakamoto and Minoura Makoto.
@@ -39,7 +39,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: yds.c,v 1.65 2020/02/29 05:51:11 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: yds.c,v 1.66 2021/02/06 12:59:13 isaki Exp $");
 
 #include "mpu.h"
 
@@ -725,7 +725,6 @@ yds_resume(device_t dv, const pmf_qual_t
 
 	pci_conf_write(pc, tag, YDS_PCI_DSCTRL, sc->sc_dsctrl);
 	sc->sc_enabled = 1;
-	mutex_spin_exit(>sc_intr_lock);
 	sc->sc_codec[0].codec_if->vtbl->restore_ports(sc->sc_codec[0].codec_if);
 	mutex_exit(>sc_lock);
 



CVS commit: src/sys/dev/pci

2021-02-06 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb  6 12:55:34 UTC 2021

Modified Files:
src/sys/dev/pci: sv.c

Log Message:
Add a missing mutex_spin_exit().


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/dev/pci/sv.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/pci/sv.c
diff -u src/sys/dev/pci/sv.c:1.58 src/sys/dev/pci/sv.c:1.59
--- src/sys/dev/pci/sv.c:1.58	Sun Apr 19 08:18:19 2020
+++ src/sys/dev/pci/sv.c	Sat Feb  6 12:55:34 2021
@@ -1,4 +1,4 @@
-/*  $NetBSD: sv.c,v 1.58 2020/04/19 08:18:19 isaki Exp $ */
+/*  $NetBSD: sv.c,v 1.59 2021/02/06 12:55:34 isaki Exp $ */
 /*  $OpenBSD: sv.c,v 1.2 1998/07/13 01:50:15 csapuntz Exp $ */
 
 /*
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sv.c,v 1.58 2020/04/19 08:18:19 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sv.c,v 1.59 2021/02/06 12:55:34 isaki Exp $");
 
 #include 
 #include 
@@ -1236,6 +1236,7 @@ sv_mixer_get_port(void *addr, mixer_ctrl
 			}
 		}
 
+		mutex_spin_exit(>sc_intr_lock);
 		return error;
 	}
 



CVS commit: src/sys/arch/arm/xscale

2021-02-06 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb  6 12:53:37 UTC 2021

Modified Files:
src/sys/arch/arm/xscale: pxa2x0_ac97.c

Log Message:
Fix "locking against myself".
halt_{input,output} will be called with sc_intr_lock held.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/arm/xscale/pxa2x0_ac97.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/arch/arm/xscale/pxa2x0_ac97.c
diff -u src/sys/arch/arm/xscale/pxa2x0_ac97.c:1.19 src/sys/arch/arm/xscale/pxa2x0_ac97.c:1.20
--- src/sys/arch/arm/xscale/pxa2x0_ac97.c:1.19	Sat Feb  6 07:16:54 2021
+++ src/sys/arch/arm/xscale/pxa2x0_ac97.c	Sat Feb  6 12:53:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pxa2x0_ac97.c,v 1.19 2021/02/06 07:16:54 isaki Exp $	*/
+/*	$NetBSD: pxa2x0_ac97.c,v 1.20 2021/02/06 12:53:36 isaki Exp $	*/
 
 /*
  * Copyright (c) 2003, 2005 Wasabi Systems, Inc.
@@ -724,14 +724,12 @@ acu_halt_output(void *arg)
 {
 	struct acu_softc *sc = arg;
 
-	mutex_spin_enter(>sc_intr_lock);
 	if (sc->sc_txdma) {
 		acu_reg_write(sc, AC97_POCR, 0);
 		acu_reg_write(sc, AC97_POSR, AC97_FIFOE);
 		pxa2x0_dmac_abort_xfer(sc->sc_txdma->ad_dx);
 		sc->sc_txdma = NULL;
 	}
-	mutex_spin_exit(>sc_intr_lock);
 	return (0);
 }
 
@@ -740,14 +738,12 @@ acu_halt_input(void *arg)
 {
 	struct acu_softc *sc = arg;
 
-	mutex_spin_enter(>sc_intr_lock);
 	if (sc->sc_rxdma) {
 		acu_reg_write(sc, AC97_PICR, 0);
 		acu_reg_write(sc, AC97_PISR, AC97_FIFOE);
 		pxa2x0_dmac_abort_xfer(sc->sc_rxdma->ad_dx);
 		sc->sc_rxdma = NULL;
 	}
-	mutex_spin_exit(>sc_intr_lock);
 	return (0);
 }
 



CVS commit: src/sys/arch/x68k/dev

2021-02-06 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb  6 12:50:04 UTC 2021

Modified Files:
src/sys/arch/x68k/dev: vs.c vsvar.h

Log Message:
Remove an unused variable.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/arch/x68k/dev/vs.c
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/x68k/dev/vsvar.h

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

Modified files:

Index: src/sys/arch/x68k/dev/vs.c
diff -u src/sys/arch/x68k/dev/vs.c:1.53 src/sys/arch/x68k/dev/vs.c:1.54
--- src/sys/arch/x68k/dev/vs.c:1.53	Sat Feb  6 09:27:35 2021
+++ src/sys/arch/x68k/dev/vs.c	Sat Feb  6 12:50:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: vs.c,v 1.53 2021/02/06 09:27:35 isaki Exp $	*/
+/*	$NetBSD: vs.c,v 1.54 2021/02/06 12:50:04 isaki Exp $	*/
 
 /*
  * Copyright (c) 2001 Tetsuya Isaki. All rights reserved.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vs.c,v 1.53 2021/02/06 09:27:35 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vs.c,v 1.54 2021/02/06 12:50:04 isaki Exp $");
 
 #include "audio.h"
 #include "vs.h"
@@ -212,7 +212,6 @@ vs_attach(device_t parent, device_t self
 	/* Initialize sc */
 	sc->sc_iot = iot;
 	sc->sc_ioh = ioh;
-	sc->sc_hw_if = _hw_if;
 	sc->sc_addr = (void *) ia->ia_addr;
 	sc->sc_dmas = NULL;
 	sc->sc_prev_vd = NULL;

Index: src/sys/arch/x68k/dev/vsvar.h
diff -u src/sys/arch/x68k/dev/vsvar.h:1.18 src/sys/arch/x68k/dev/vsvar.h:1.19
--- src/sys/arch/x68k/dev/vsvar.h:1.18	Sat Feb  6 09:27:35 2021
+++ src/sys/arch/x68k/dev/vsvar.h	Sat Feb  6 12:50:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: vsvar.h,v 1.18 2021/02/06 09:27:35 isaki Exp $	*/
+/*	$NetBSD: vsvar.h,v 1.19 2021/02/06 12:50:04 isaki Exp $	*/
 
 /*
  * Copyright (c) 2001 Tetsuya Isaki. All rights reserved.
@@ -99,8 +99,6 @@ struct vs_softc {
 		int rate;
 	} sc_current;
 
-	const struct audio_hw_if *sc_hw_if;
-
 	void (*sc_pintr)(void *);
 	void (*sc_rintr)(void *);
 	void *sc_parg;



CVS commit: src/sys/dev/pci

2021-02-06 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb  6 09:45:17 UTC 2021

Modified Files:
src/sys/dev/pci: auich.c auvia.c

Log Message:
Hold sc_intr_lock in open()/close().
vtbl->{lock,unlock} (in fact ac97_{lock,unlock}) don't seem to need
releasing an interrupt lock.
Confirmed on auich.


To generate a diff of this commit:
cvs rdiff -u -r1.159 -r1.160 src/sys/dev/pci/auich.c
cvs rdiff -u -r1.86 -r1.87 src/sys/dev/pci/auvia.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/pci/auich.c
diff -u src/sys/dev/pci/auich.c:1.159 src/sys/dev/pci/auich.c:1.160
--- src/sys/dev/pci/auich.c:1.159	Sat Feb 29 06:34:30 2020
+++ src/sys/dev/pci/auich.c	Sat Feb  6 09:45:17 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: auich.c,v 1.159 2020/02/29 06:34:30 isaki Exp $	*/
+/*	$NetBSD: auich.c,v 1.160 2021/02/06 09:45:17 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2004, 2005, 2008 The NetBSD Foundation, Inc.
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: auich.c,v 1.159 2020/02/29 06:34:30 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: auich.c,v 1.160 2021/02/06 09:45:17 isaki Exp $");
 
 #include 
 #include 
@@ -930,9 +930,7 @@ auich_open(void *addr, int flags)
 	struct auich_softc *sc;
 
 	sc = (struct auich_softc *)addr;
-	mutex_spin_exit(>sc_intr_lock);
 	sc->codec_if->vtbl->lock(sc->codec_if);
-	mutex_spin_enter(>sc_intr_lock);
 	return 0;
 }
 
@@ -942,9 +940,7 @@ auich_close(void *addr)
 	struct auich_softc *sc;
 
 	sc = (struct auich_softc *)addr;
-	mutex_spin_exit(>sc_intr_lock);
 	sc->codec_if->vtbl->unlock(sc->codec_if);
-	mutex_spin_enter(>sc_intr_lock);
 }
 
 static int

Index: src/sys/dev/pci/auvia.c
diff -u src/sys/dev/pci/auvia.c:1.86 src/sys/dev/pci/auvia.c:1.87
--- src/sys/dev/pci/auvia.c:1.86	Sun Apr 19 08:18:19 2020
+++ src/sys/dev/pci/auvia.c	Sat Feb  6 09:45:17 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: auvia.c,v 1.86 2020/04/19 08:18:19 isaki Exp $	*/
+/*	$NetBSD: auvia.c,v 1.87 2021/02/06 09:45:17 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2008 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: auvia.c,v 1.86 2020/04/19 08:18:19 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: auvia.c,v 1.87 2021/02/06 09:45:17 isaki Exp $");
 
 #include 
 #include 
@@ -614,9 +614,7 @@ auvia_open(void *addr, int flags)
 	struct auvia_softc *sc;
 
 	sc = (struct auvia_softc *)addr;
-	mutex_spin_exit(>sc_intr_lock);
 	sc->codec_if->vtbl->lock(sc->codec_if);
-	mutex_spin_enter(>sc_intr_lock);
 	return 0;
 }
 
@@ -626,9 +624,7 @@ auvia_close(void *addr)
 	struct auvia_softc *sc;
 
 	sc = (struct auvia_softc *)addr;
-	mutex_spin_exit(>sc_intr_lock);
 	sc->codec_if->vtbl->unlock(sc->codec_if);
-	mutex_spin_enter(>sc_intr_lock);
 }
 
 static int



CVS commit: src/sys/arch/x68k/dev

2021-02-06 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb  6 09:27:35 UTC 2021

Modified Files:
src/sys/arch/x68k/dev: vs.c vsvar.h

Log Message:
Remove sc_active flag.  sc_[pr]intr can be used instead of it.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/x68k/dev/vs.c
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/x68k/dev/vsvar.h

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

Modified files:

Index: src/sys/arch/x68k/dev/vs.c
diff -u src/sys/arch/x68k/dev/vs.c:1.52 src/sys/arch/x68k/dev/vs.c:1.53
--- src/sys/arch/x68k/dev/vs.c:1.52	Sat Jun  8 08:02:37 2019
+++ src/sys/arch/x68k/dev/vs.c	Sat Feb  6 09:27:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: vs.c,v 1.52 2019/06/08 08:02:37 isaki Exp $	*/
+/*	$NetBSD: vs.c,v 1.53 2021/02/06 09:27:35 isaki Exp $	*/
 
 /*
  * Copyright (c) 2001 Tetsuya Isaki. All rights reserved.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vs.c,v 1.52 2019/06/08 08:02:37 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vs.c,v 1.53 2021/02/06 09:27:35 isaki Exp $");
 
 #include "audio.h"
 #include "vs.h"
@@ -72,8 +72,6 @@ static int  vs_dmaintr(void *);
 static int  vs_dmaerrintr(void *);
 
 /* MI audio layer interface */
-static int  vs_open(void *, int);
-static void vs_close(void *);
 static int  vs_query_format(void *, audio_format_query_t *);
 static int  vs_set_format(void *, int,
 	const audio_params_t *, const audio_params_t *,
@@ -108,8 +106,6 @@ CFATTACH_DECL_NEW(vs, sizeof(struct vs_s
 static int vs_attached;
 
 static const struct audio_hw_if vs_hw_if = {
-	.open			= vs_open,
-	.close			= vs_close,
 	.query_format		= vs_query_format,
 	.set_format		= vs_set_format,
 	.commit_settings	= vs_commit_settings,
@@ -220,7 +216,6 @@ vs_attach(device_t parent, device_t self
 	sc->sc_addr = (void *) ia->ia_addr;
 	sc->sc_dmas = NULL;
 	sc->sc_prev_vd = NULL;
-	sc->sc_active = 0;
 	mutex_init(>sc_lock, MUTEX_DEFAULT, IPL_NONE);
 	mutex_init(>sc_intr_lock, MUTEX_DEFAULT, IPL_VM);
 
@@ -286,27 +281,6 @@ vs_dmaerrintr(void *hdl)
  */
 
 static int
-vs_open(void *hdl, int flags)
-{
-	struct vs_softc *sc;
-
-	DPRINTF(1, ("vs_open: flags=%d\n", flags));
-	sc = hdl;
-	sc->sc_pintr = NULL;
-	sc->sc_rintr = NULL;
-	sc->sc_active = 0;
-
-	return 0;
-}
-
-static void
-vs_close(void *hdl)
-{
-
-	DPRINTF(1, ("vs_close\n"));
-}
-
-static int
 vs_query_format(void *hdl, audio_format_query_t *afp)
 {
 
@@ -398,9 +372,6 @@ vs_start_output(void *hdl, void *block, 
 	DPRINTF(2, ("%s: block=%p blksize=%d\n", __func__, block, blksize));
 	sc = hdl;
 
-	sc->sc_pintr = intr;
-	sc->sc_parg  = arg;
-
 	/* Find DMA buffer. */
 	for (vd = sc->sc_dmas; vd != NULL; vd = vd->vd_next) {
 		if (KVADDR(vd) <= block && block < KVADDR_END(vd)
@@ -424,11 +395,13 @@ vs_start_output(void *hdl, void *block, 
 	dmac_start_xfer_offset(chan->ch_softc, sc->sc_current.xfer,
 	(int)block - (int)KVADDR(vd), blksize);
 
-	if (sc->sc_active == 0) {
+	if (sc->sc_pintr == NULL) {
+		sc->sc_pintr = intr;
+		sc->sc_parg  = arg;
+
 		vs_set_panout(sc, VS_PANOUT_LR);
 		bus_space_write_1(sc->sc_iot, sc->sc_ioh,
 			MSM6258_CMD, MSM6258_CMD_PLAY_START);
-		sc->sc_active = 1;
 	}
 
 	return 0;
@@ -445,9 +418,6 @@ vs_start_input(void *hdl, void *block, i
 	DPRINTF(2, ("%s: block=%p blksize=%d\n", __func__, block, blksize));
 	sc = hdl;
 
-	sc->sc_rintr = intr;
-	sc->sc_rarg  = arg;
-
 	/* Find DMA buffer. */
 	for (vd = sc->sc_dmas; vd != NULL; vd = vd->vd_next) {
 		if (KVADDR(vd) <= block && block < KVADDR_END(vd)
@@ -471,10 +441,12 @@ vs_start_input(void *hdl, void *block, i
 	dmac_start_xfer_offset(chan->ch_softc, sc->sc_current.xfer,
 	(int)block - (int)KVADDR(vd), blksize);
 
-	if (sc->sc_active == 0) {
+	if (sc->sc_rintr == NULL) {
+		sc->sc_rintr = intr;
+		sc->sc_rarg  = arg;
+
 		bus_space_write_1(sc->sc_iot, sc->sc_ioh,
 			MSM6258_CMD, MSM6258_CMD_REC_START);
-		sc->sc_active = 1;
 	}
 
 	return 0;
@@ -487,13 +459,12 @@ vs_halt_output(void *hdl)
 
 	DPRINTF(1, ("vs_halt_output\n"));
 	sc = hdl;
-	if (sc->sc_active) {
-		/* stop ADPCM play */
-		dmac_abort_xfer(sc->sc_dma_ch->ch_softc, sc->sc_current.xfer);
-		bus_space_write_1(sc->sc_iot, sc->sc_ioh,
-			MSM6258_CMD, MSM6258_CMD_STOP);
-		sc->sc_active = 0;
-	}
+
+	/* stop ADPCM play */
+	dmac_abort_xfer(sc->sc_dma_ch->ch_softc, sc->sc_current.xfer);
+	bus_space_write_1(sc->sc_iot, sc->sc_ioh,
+	MSM6258_CMD, MSM6258_CMD_STOP);
+	sc->sc_pintr = NULL;
 
 	return 0;
 }
@@ -505,13 +476,12 @@ vs_halt_input(void *hdl)
 
 	DPRINTF(1, ("vs_halt_input\n"));
 	sc = hdl;
-	if (sc->sc_active) {
-		/* stop ADPCM recoding */
-		dmac_abort_xfer(sc->sc_dma_ch->ch_softc, sc->sc_current.x

CVS commit: src/sys/dev/sbus

2021-02-06 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb  6 09:15:11 UTC 2021

Modified Files:
src/sys/dev/sbus: dbri.c dbrivar.h

Log Message:
Remove something like counters.
- Counting {open,close} is done by the MI audio layer.
- trigger_* is not called again between trigger_* and halt_*.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/dev/sbus/dbri.c
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/sbus/dbrivar.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/sbus/dbri.c
diff -u src/sys/dev/sbus/dbri.c:1.43 src/sys/dev/sbus/dbri.c:1.44
--- src/sys/dev/sbus/dbri.c:1.43	Tue Aug 25 13:36:41 2020
+++ src/sys/dev/sbus/dbri.c	Sat Feb  6 09:15:11 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: dbri.c,v 1.43 2020/08/25 13:36:41 skrll Exp $	*/
+/*	$NetBSD: dbri.c,v 1.44 2021/02/06 09:15:11 isaki Exp $	*/
 
 /*
  * Copyright (C) 1997 Rudolf Koenig (rfkoe...@immd4.informatik.uni-erlangen.de)
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dbri.c,v 1.43 2020/08/25 13:36:41 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dbri.c,v 1.44 2021/02/06 09:15:11 isaki Exp $");
 
 #include "audio.h"
 #if NAUDIO > 0
@@ -368,7 +368,6 @@ dbri_attach_sbus(device_t parent, device
 
 	sc->sc_locked = 0;
 	sc->sc_desc_used = 0;
-	sc->sc_refcount = 0;
 	sc->sc_playing = 0;
 	sc->sc_recording = 0;
 	sc->sc_init_done = 0;
@@ -1894,8 +1893,7 @@ dbri_trigger_output(void *hdl, void *sta
 	struct dbri_softc *sc = hdl;
 	unsigned long count, num;
 
-	if (sc->sc_playing)
-		return 0;
+	KASSERT(sc->sc_playing == 0);
 
 	count = (unsigned long)(((char *)end - (char *)start));
 	num = count / blksize;
@@ -1937,8 +1935,7 @@ dbri_trigger_input(void *hdl, void *star
 	struct dbri_softc *sc = hdl;
 	unsigned long count, num;
 
-	if (sc->sc_recording)
-		return 0;
+	KASSERT(sc->sc_recording == 0);
 
 	count = (unsigned long)(((char *)end - (char *)start));
 	num = count / blksize;
@@ -2051,14 +2048,9 @@ dbri_open(void *cookie, int flags)
 {
 	struct dbri_softc *sc = cookie;
 
-	DPRINTF("%s: %d\n", __func__, sc->sc_refcount);
-
-	if (sc->sc_refcount == 0) {
-		dbri_bring_up(sc);
-	}
-
-	sc->sc_refcount++;
+	DPRINTF("%s\n", __func__);
 
+	dbri_bring_up(sc);
 	return 0;
 }
 
@@ -2067,16 +2059,11 @@ dbri_close(void *cookie)
 {
 	struct dbri_softc *sc = cookie;
 
-	DPRINTF("%s: %d\n", __func__, sc->sc_refcount);
-
-	sc->sc_refcount--;
-	KASSERT(sc->sc_refcount >= 0);
-	if (sc->sc_refcount > 0)
-		return;
+	DPRINTF("%s\n", __func__);
+	KASSERT(sc->sc_playing == 0);
+	KASSERT(sc->sc_recording == 0);
 
 	dbri_set_power(sc, 0);
-	sc->sc_playing = 0;
-	sc->sc_recording = 0;
 }
 
 static bool
@@ -2097,7 +2084,7 @@ dbri_resume(device_t self, const pmf_qua
 
 	if (sc->sc_powerstate != 0)
 		return true;
-	aprint_verbose("resume: %d\n", sc->sc_refcount);
+	aprint_verbose("resume\n");
 	if (sc->sc_playing) {
 		volatile uint32_t *cmd;
 

Index: src/sys/dev/sbus/dbrivar.h
diff -u src/sys/dev/sbus/dbrivar.h:1.16 src/sys/dev/sbus/dbrivar.h:1.17
--- src/sys/dev/sbus/dbrivar.h:1.16	Wed May  8 13:40:19 2019
+++ src/sys/dev/sbus/dbrivar.h	Sat Feb  6 09:15:11 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: dbrivar.h,v 1.16 2019/05/08 13:40:19 isaki Exp $	*/
+/*	$NetBSD: dbrivar.h,v 1.17 2021/02/06 09:15:11 isaki Exp $	*/
 
 /*
  * Copyright (C) 1997 Rudolf Koenig (rfkoe...@immd4.informatik.uni-erlangen.de)
@@ -140,7 +140,6 @@ struct dbri_softc {
 
 	int		sc_waitseen;
 
-	int		sc_refcount;
 	int		sc_playing;
 	int		sc_recording;
 



CVS commit: src/sys/arch/dreamcast/dev/g2

2021-02-06 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb  6 09:14:03 UTC 2021

Modified Files:
src/sys/arch/dreamcast/dev/g2: aica.c

Log Message:
Remove sc_open flag.
Counting {open,close} is done by the MI audio layer.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/dreamcast/dev/g2/aica.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/arch/dreamcast/dev/g2/aica.c
diff -u src/sys/arch/dreamcast/dev/g2/aica.c:1.28 src/sys/arch/dreamcast/dev/g2/aica.c:1.29
--- src/sys/arch/dreamcast/dev/g2/aica.c:1.28	Sun Feb 23 04:02:45 2020
+++ src/sys/arch/dreamcast/dev/g2/aica.c	Sat Feb  6 09:14:03 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: aica.c,v 1.28 2020/02/23 04:02:45 isaki Exp $	*/
+/*	$NetBSD: aica.c,v 1.29 2021/02/06 09:14:03 isaki Exp $	*/
 
 /*
  * Copyright (c) 2003 SHIMIZU Ryo 
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: aica.c,v 1.28 2020/02/23 04:02:45 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: aica.c,v 1.29 2021/02/06 09:14:03 isaki Exp $");
 
 #include 
 #include 
@@ -63,7 +63,6 @@ struct aica_softc {
 	bus_space_handle_t	sc_aica_memh;
 
 	/* audio property */
-	int			sc_open;
 	int			sc_precision;
 	int			sc_channels;
 	int			sc_rate;
@@ -125,8 +124,6 @@ void aica_fillbuffer(struct aica_softc *
 int aica_intr(void *);
 
 /* for audio */
-int aica_open(void *, int);
-void aica_close(void *);
 int aica_query_format(void *, audio_format_query_t *);
 int aica_set_format(void *, int,
 const audio_params_t *, const audio_params_t *,
@@ -145,8 +142,6 @@ int aica_get_props(void *);
 void aica_get_locks(void *, kmutex_t **, kmutex_t **);
 
 const struct audio_hw_if aica_hw_if = {
-	.open			= aica_open,
-	.close			= aica_close,
 	.query_format		= aica_query_format,
 	.set_format		= aica_set_format,
 	.round_blocksize	= aica_round_blocksize,
@@ -389,31 +384,6 @@ aica_ch2p8write(struct aica_softc *sc, b
 }
 
 int
-aica_open(void *addr, int flags)
-{
-	struct aica_softc *sc;
-
-	sc = addr;
-	if (sc->sc_open)
-		return EBUSY;
-
-	sc->sc_intr = NULL;
-	sc->sc_open = 1;
-
-	return 0;
-}
-
-void
-aica_close(void *addr)
-{
-	struct aica_softc *sc;
-
-	sc = addr;
-	sc->sc_open = 0;
-	sc->sc_intr = NULL;
-}
-
-int
 aica_query_format(void *addr, audio_format_query_t *afp)
 {
 
@@ -561,7 +531,7 @@ aica_intr(void *arg)
 	aica_fillbuffer(sc);
 
 	/* call audio interrupt handler (audio_pint()) */
-	if (sc->sc_open && sc->sc_intr != NULL) {
+	if (sc->sc_intr != NULL) {
 		(*(sc->sc_intr))(sc->sc_intr_arg);
 	}
 
@@ -610,6 +580,7 @@ aica_halt_output(void *addr)
 
 	sc = addr;
 	aica_command(sc, AICA_COMMAND_STOP);
+	sc->sc_intr = NULL;
 	return 0;
 }
 



CVS commit: src/sys/arch/macppc/dev

2021-02-05 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb  6 07:20:36 UTC 2021

Modified Files:
src/sys/arch/macppc/dev: awacs.c

Log Message:
Calling halt_{input,output} is done by the MI audio layer if necessary.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/macppc/dev/awacs.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/arch/macppc/dev/awacs.c
diff -u src/sys/arch/macppc/dev/awacs.c:1.49 src/sys/arch/macppc/dev/awacs.c:1.50
--- src/sys/arch/macppc/dev/awacs.c:1.49	Tue Jan 26 14:49:41 2021
+++ src/sys/arch/macppc/dev/awacs.c	Sat Feb  6 07:20:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: awacs.c,v 1.49 2021/01/26 14:49:41 thorpej Exp $	*/
+/*	$NetBSD: awacs.c,v 1.50 2021/02/06 07:20:36 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2000 Tsubai Masanari.  All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: awacs.c,v 1.49 2021/01/26 14:49:41 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: awacs.c,v 1.50 2021/02/06 07:20:36 isaki Exp $");
 
 #include 
 #include 
@@ -110,7 +110,6 @@ static void awacs_attach(device_t, devic
 static int awacs_intr(void *);
 static int awacs_status_intr(void *);
 
-static void awacs_close(void *);
 static int awacs_query_format(void *, audio_format_query_t *);
 static int awacs_set_format(void *, int,
 		 const audio_params_t *, const audio_params_t *,
@@ -154,7 +153,6 @@ CFATTACH_DECL_NEW(awacs, sizeof(struct a
 awacs_match, awacs_attach, NULL, NULL);
 
 const struct audio_hw_if awacs_hw_if = {
-	.close			= awacs_close,
 	.query_format		= awacs_query_format,
 	.set_format		= awacs_set_format,
 	.round_blocksize	= awacs_round_blocksize,
@@ -620,22 +618,6 @@ awacs_intr(void *v)
 	return 1;
 }
 
-/*
- * Close function is called at splaudio().
- */
-static void
-awacs_close(void *h)
-{
-	struct awacs_softc *sc;
-
-	sc = h;
-	awacs_halt_output(sc);
-	awacs_halt_input(sc);
-
-	sc->sc_ointr = 0;
-	sc->sc_iintr = 0;
-}
-
 static int
 awacs_query_format(void *h, audio_format_query_t *afp)
 {
@@ -678,6 +660,7 @@ awacs_halt_output(void *h)
 	sc = h;
 	dbdma_stop(sc->sc_odma);
 	dbdma_reset(sc->sc_odma);
+	sc->sc_ointr = NULL;
 	return 0;
 }
 
@@ -689,6 +672,7 @@ awacs_halt_input(void *h)
 	sc = h;
 	dbdma_stop(sc->sc_idma);
 	dbdma_reset(sc->sc_idma);
+	sc->sc_iintr = NULL;
 	return 0;
 }
 



CVS commit: src/sys/arch/arm/xscale

2021-02-05 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb  6 07:16:54 UTC 2021

Modified Files:
src/sys/arch/arm/xscale: pxa2x0_ac97.c

Log Message:
Calling halt_{input,output} is done by the MI audio layer if necessary.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/arm/xscale/pxa2x0_ac97.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/arch/arm/xscale/pxa2x0_ac97.c
diff -u src/sys/arch/arm/xscale/pxa2x0_ac97.c:1.18 src/sys/arch/arm/xscale/pxa2x0_ac97.c:1.19
--- src/sys/arch/arm/xscale/pxa2x0_ac97.c:1.18	Sun Apr 19 08:18:19 2020
+++ src/sys/arch/arm/xscale/pxa2x0_ac97.c	Sat Feb  6 07:16:54 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pxa2x0_ac97.c,v 1.18 2020/04/19 08:18:19 isaki Exp $	*/
+/*	$NetBSD: pxa2x0_ac97.c,v 1.19 2021/02/06 07:16:54 isaki Exp $	*/
 
 /*
  * Copyright (c) 2003, 2005 Wasabi Systems, Inc.
@@ -545,8 +545,6 @@ acu_close(void *arg)
 	/*
 	 * Make sure the hardware is quiescent
 	 */
-	acu_halt_output(sc);
-	acu_halt_input(sc);
 	delay(100);
 
 	/* Assert Cold Reset */



CVS commit: src/sys/dev/isa

2021-02-05 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb  6 07:16:18 UTC 2021

Modified Files:
src/sys/dev/isa: gus.c

Log Message:
Calling halt_{input,output} is done by the MI audio layer if necessary.


To generate a diff of this commit:
cvs rdiff -u -r1.118 -r1.119 src/sys/dev/isa/gus.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/isa/gus.c
diff -u src/sys/dev/isa/gus.c:1.118 src/sys/dev/isa/gus.c:1.119
--- src/sys/dev/isa/gus.c:1.118	Sat Feb 29 05:51:11 2020
+++ src/sys/dev/isa/gus.c	Sat Feb  6 07:16:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: gus.c,v 1.118 2020/02/29 05:51:11 isaki Exp $	*/
+/*	$NetBSD: gus.c,v 1.119 2021/02/06 07:16:18 isaki Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1999, 2008 The NetBSD Foundation, Inc.
@@ -88,7 +88,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gus.c,v 1.118 2020/02/29 05:51:11 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gus.c,v 1.119 2021/02/06 07:16:18 isaki Exp $");
 
 #include 
 #include 
@@ -1359,14 +1359,10 @@ gusclose(void *addr)
 	sc = addr;
 	DPRINTF(("gus_close: sc=%p\n", sc));
 
+	KASSERT((sc->sc_flags & (GUS_DMAOUT_ACTIVE | GUS_LOCKED)) == 0);
+	KASSERT((sc->sc_flags & GUS_DMAIN_ACTIVE) == 0);
 
-/*	if (sc->sc_flags & GUS_DMAOUT_ACTIVE) */ {
-		gus_halt_out_dma(sc);
-	}
-/*	if (sc->sc_flags & GUS_DMAIN_ACTIVE) */ {
-		gus_halt_in_dma(sc);
-	}
-	sc->sc_flags &= ~(GUS_OPEN|GUS_LOCKED|GUS_DMAOUT_ACTIVE|GUS_DMAIN_ACTIVE);
+	sc->sc_flags &= ~GUS_OPEN;
 
 	/* turn off speaker, etc. */
 



CVS commit: src/share/man/man9

2021-02-05 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb  6 06:15:13 UTC 2021

Modified Files:
src/share/man/man9: audio.9

Log Message:
Add a description to close().
> Before call to this, halt_input and halt_output are called if necessary.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/share/man/man9/audio.9

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

Modified files:

Index: src/share/man/man9/audio.9
diff -u src/share/man/man9/audio.9:1.58 src/share/man/man9/audio.9:1.59
--- src/share/man/man9/audio.9:1.58	Sat Feb 29 05:39:03 2020
+++ src/share/man/man9/audio.9	Sat Feb  6 06:15:13 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: audio.9,v 1.58 2020/02/29 05:39:03 isaki Exp $
+.\"	$NetBSD: audio.9,v 1.59 2021/02/06 06:15:13 isaki Exp $
 .\"
 .\" Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -163,6 +163,11 @@ It is called in the Closed phase.
 .It Dv void close(void *hdl)
 optional, is called when the last audio device combining
 playback and recording is closed.
+Before call to this,
+.Va halt_input
+and
+.Va halt_output
+are called if necessary.
 It is called in the Opened phase.
 .It Dv int query_format(void *hdl, audio_format_query_t *afp)
 is called to enumerate formats supported by the hardware.



CVS commit: src/sys/dev/pci

2021-02-05 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb  6 05:15:03 UTC 2021

Modified Files:
src/sys/dev/pci: emuxki.c

Log Message:
Remove debug messages which are no longer necessary.


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/sys/dev/pci/emuxki.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/pci/emuxki.c
diff -u src/sys/dev/pci/emuxki.c:1.70 src/sys/dev/pci/emuxki.c:1.71
--- src/sys/dev/pci/emuxki.c:1.70	Sat Jun  8 08:02:38 2019
+++ src/sys/dev/pci/emuxki.c	Sat Feb  6 05:15:03 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: emuxki.c,v 1.70 2019/06/08 08:02:38 isaki Exp $	*/
+/*	$NetBSD: emuxki.c,v 1.71 2021/02/06 05:15:03 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2007 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: emuxki.c,v 1.70 2019/06/08 08:02:38 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: emuxki.c,v 1.71 2021/02/06 05:15:03 isaki Exp $");
 
 #include 
 #include 
@@ -217,8 +217,6 @@ static void	emuxki_play_start(struct emu
 		uint32_t);
 static void	emuxki_play_stop(struct emuxki_softc *, int);
 
-static int	emuxki_open(void *, int);
-static void	emuxki_close(void *);
 static int	emuxki_query_format(void *, audio_format_query_t *);
 static int	emuxki_set_format(void *, int,
 		const audio_params_t *, const audio_params_t *,
@@ -254,8 +252,6 @@ CFATTACH_DECL_NEW(emuxki, sizeof(struct 
 emuxki_match, emuxki_attach, emuxki_detach, NULL);
 
 static const struct audio_hw_if emuxki_hw_if = {
-	.open			= emuxki_open,
-	.close			= emuxki_close,
 	.query_format		= emuxki_query_format,
 	.set_format		= emuxki_set_format,
 	.round_blocksize	= emuxki_round_blocksize,
@@ -952,24 +948,6 @@ emuxki_timer_stop(struct emuxki_softc *s
  */
 
 static int
-emuxki_open(void *hdl, int flags)
-{
-
-	DPRINTF("%s for %s%s\n", __func__,
-	(flags & FWRITE) ? "P" : "",
-	(flags & FREAD)  ? "R" : "");
-
-	return 0;
-}
-
-static void
-emuxki_close(void *hdl)
-{
-
-	DPRINTF("%s\n", __func__);
-}
-
-static int
 emuxki_query_format(void *hdl, audio_format_query_t *afp)
 {
 



CVS commit: src/sys/arch/hppa/gsc

2021-02-04 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Thu Feb  4 15:08:45 UTC 2021

Modified Files:
src/sys/arch/hppa/gsc: harmony.c

Log Message:
Simplify harmony_speed_bits().
It no longer needs to write back the speed value.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/hppa/gsc/harmony.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/arch/hppa/gsc/harmony.c
diff -u src/sys/arch/hppa/gsc/harmony.c:1.9 src/sys/arch/hppa/gsc/harmony.c:1.10
--- src/sys/arch/hppa/gsc/harmony.c:1.9	Thu Feb  4 15:06:11 2021
+++ src/sys/arch/hppa/gsc/harmony.c	Thu Feb  4 15:08:44 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: harmony.c,v 1.9 2021/02/04 15:06:11 isaki Exp $	*/
+/*	$NetBSD: harmony.c,v 1.10 2021/02/04 15:08:44 isaki Exp $	*/
 
 /*	$OpenBSD: harmony.c,v 1.23 2004/02/13 21:28:19 mickey Exp $	*/
 
@@ -165,7 +165,7 @@ CFATTACH_DECL_NEW(harmony, sizeof(struct
 int harmony_intr(void *);
 void harmony_intr_enable(struct harmony_softc *);
 void harmony_intr_disable(struct harmony_softc *);
-uint32_t harmony_speed_bits(struct harmony_softc *, u_int *);
+uint32_t harmony_speed_bits(struct harmony_softc *, u_int);
 int harmony_set_gainctl(struct harmony_softc *);
 void harmony_reset_codec(struct harmony_softc *);
 void harmony_start_cp(struct harmony_softc *, int);
@@ -441,7 +441,6 @@ harmony_set_format(void *vsc, int setmod
 {
 	struct harmony_softc *sc;
 	uint32_t bits;
-	int rate;
 
 	sc = vsc;
 
@@ -464,10 +463,7 @@ harmony_set_format(void *vsc, int setmod
 		bits |= CNTL_OLB;
 
 	bits |= CNTL_CHANS_STEREO;
-
-	/* XXX modify harmony_speed_bits() not to rewrite rate */
-	rate = play->sample_rate;
-	bits |= harmony_speed_bits(sc, );
+	bits |= harmony_speed_bits(sc, play->sample_rate);
 	sc->sc_cntlbits = bits;
 	sc->sc_need_commit = 1;
 
@@ -1161,39 +1157,17 @@ static const struct speed_struct {
 };
 
 uint32_t
-harmony_speed_bits(struct harmony_softc *sc, u_int *speedp)
+harmony_speed_bits(struct harmony_softc *sc, u_int speed)
 {
-	int i, n, selected;
-
-	selected = -1;
-	n = sizeof(harmony_speeds) / sizeof(harmony_speeds[0]);
+	int i;
 
-	if ((*speedp) <= harmony_speeds[0].speed)
-		selected = 0;
-	else if ((*speedp) >= harmony_speeds[n - 1].speed)
-		selected = n - 1;
-	else {
-		for (i = 1; selected == -1 && i < n; i++) {
-			if ((*speedp) == harmony_speeds[i].speed)
-selected = i;
-			else if ((*speedp) < harmony_speeds[i].speed) {
-int diff1, diff2;
-
-diff1 = (*speedp) - harmony_speeds[i - 1].speed;
-diff2 = harmony_speeds[i].speed - (*speedp);
-if (diff1 < diff2)
-	selected = i - 1;
-else
-	selected = i;
-			}
+	for (i = 0; i < __arraycount(harmony_speeds); i++) {
+		if (speed == harmony_speeds[i].speed) {
+			return harmony_speeds[i].bits;
 		}
 	}
-
-	if (selected == -1)
-		selected = 2;
-
-	*speedp = harmony_speeds[selected].speed;
-	return harmony_speeds[selected].bits;
+	/* If this happens, harmony_formats[] is wrong */
+	panic("speed %u not supported", speed);
 }
 
 int



CVS commit: src/sys/arch/hppa/gsc

2021-02-04 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Thu Feb  4 15:06:11 UTC 2021

Modified Files:
src/sys/arch/hppa/gsc: harmony.c

Log Message:
Fix my mistakes in rev1.6.
- I had to merge the channel bit and the speed bits.
  Reported by macallan@.
- I also fix my indent, while I'm here.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/hppa/gsc/harmony.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/arch/hppa/gsc/harmony.c
diff -u src/sys/arch/hppa/gsc/harmony.c:1.8 src/sys/arch/hppa/gsc/harmony.c:1.9
--- src/sys/arch/hppa/gsc/harmony.c:1.8	Wed Feb  3 15:13:49 2021
+++ src/sys/arch/hppa/gsc/harmony.c	Thu Feb  4 15:06:11 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: harmony.c,v 1.8 2021/02/03 15:13:49 isaki Exp $	*/
+/*	$NetBSD: harmony.c,v 1.9 2021/02/04 15:06:11 isaki Exp $	*/
 
 /*	$OpenBSD: harmony.c,v 1.23 2004/02/13 21:28:19 mickey Exp $	*/
 
@@ -437,7 +437,7 @@ harmony_query_format(void *vsc, audio_fo
 int
 harmony_set_format(void *vsc, int setmode,
 const audio_params_t *play, const audio_params_t *rec,
-	audio_filter_reg_t *pfil, audio_filter_reg_t *rfil)
+audio_filter_reg_t *pfil, audio_filter_reg_t *rfil)
 {
 	struct harmony_softc *sc;
 	uint32_t bits;
@@ -467,7 +467,8 @@ harmony_set_format(void *vsc, int setmod
 
 	/* XXX modify harmony_speed_bits() not to rewrite rate */
 	rate = play->sample_rate;
-	sc->sc_cntlbits |= harmony_speed_bits(sc, );
+	bits |= harmony_speed_bits(sc, );
+	sc->sc_cntlbits = bits;
 	sc->sc_need_commit = 1;
 
 	return 0;



CVS commit: src/sys/arch/hppa/gsc

2021-02-03 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Feb  3 15:13:49 UTC 2021

Modified Files:
src/sys/arch/hppa/gsc: harmony.c

Log Message:
Fix locking against myself.
trigger_output will be called with sc_intr_lock held.
>From source code review, not tested.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/hppa/gsc/harmony.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/arch/hppa/gsc/harmony.c
diff -u src/sys/arch/hppa/gsc/harmony.c:1.7 src/sys/arch/hppa/gsc/harmony.c:1.8
--- src/sys/arch/hppa/gsc/harmony.c:1.7	Sat Jun  8 08:02:37 2019
+++ src/sys/arch/hppa/gsc/harmony.c	Wed Feb  3 15:13:49 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: harmony.c,v 1.7 2019/06/08 08:02:37 isaki Exp $	*/
+/*	$NetBSD: harmony.c,v 1.8 2021/02/03 15:13:49 isaki Exp $	*/
 
 /*	$OpenBSD: harmony.c,v 1.23 2004/02/13 21:28:19 mickey Exp $	*/
 
@@ -1004,8 +1004,6 @@ harmony_trigger_output(void *vsc, void *
 		return EINVAL;
 	}
 
-	mutex_spin_enter(>sc_intr_lock);
-
 	c->c_intr = intr;
 	c->c_intrarg = intrarg;
 	c->c_blksz = blksize;
@@ -1020,8 +1018,6 @@ harmony_trigger_output(void *vsc, void *
 	harmony_start_cp(sc, 0);
 	harmony_intr_enable(sc);
 
-	mutex_spin_exit(>sc_intr_lock);
-
 	return 0;
 }
 



CVS commit: src/sys/dev/pci

2021-02-03 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Feb  3 14:44:32 UTC 2021

Modified Files:
src/sys/dev/pci: cs4280.c cs4281.c cs428x.h

Log Message:
Remove code no longer used.
The code that used sc->{halt_input,halt_output} function pointer
was removed in 2004. (see cs428x.c rev 1.7)


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/sys/dev/pci/cs4280.c
cvs rdiff -u -r1.56 -r1.57 src/sys/dev/pci/cs4281.c
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/pci/cs428x.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/pci/cs4280.c
diff -u src/sys/dev/pci/cs4280.c:1.72 src/sys/dev/pci/cs4280.c:1.73
--- src/sys/dev/pci/cs4280.c:1.72	Wed May  8 13:40:18 2019
+++ src/sys/dev/pci/cs4280.c	Wed Feb  3 14:44:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cs4280.c,v 1.72 2019/05/08 13:40:18 isaki Exp $	*/
+/*	$NetBSD: cs4280.c,v 1.73 2021/02/03 14:44:32 isaki Exp $	*/
 
 /*
  * Copyright (c) 1999, 2000 Tatoku Ogaito.  All rights reserved.
@@ -52,7 +52,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cs4280.c,v 1.72 2019/05/08 13:40:18 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cs4280.c,v 1.73 2021/02/03 14:44:32 isaki Exp $");
 
 #include "midi.h"
 
@@ -346,8 +346,6 @@ cs4280_attach(device_t parent, device_t 
 	}
 
 	sc->type = TYPE_CS4280;
-	sc->halt_input  = cs4280_halt_input;
-	sc->halt_output = cs4280_halt_output;
 
 	/* setup buffer related parameters */
 	sc->dma_size = CS4280_DCHUNK;

Index: src/sys/dev/pci/cs4281.c
diff -u src/sys/dev/pci/cs4281.c:1.56 src/sys/dev/pci/cs4281.c:1.57
--- src/sys/dev/pci/cs4281.c:1.56	Fri May  8 13:52:40 2020
+++ src/sys/dev/pci/cs4281.c	Wed Feb  3 14:44:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cs4281.c,v 1.56 2020/05/08 13:52:40 simonb Exp $	*/
+/*	$NetBSD: cs4281.c,v 1.57 2021/02/03 14:44:32 isaki Exp $	*/
 
 /*
  * Copyright (c) 2000 Tatoku Ogaito.  All rights reserved.
@@ -43,7 +43,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cs4281.c,v 1.56 2020/05/08 13:52:40 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cs4281.c,v 1.57 2021/02/03 14:44:32 isaki Exp $");
 
 #include 
 #include 
@@ -272,8 +272,6 @@ cs4281_attach(device_t parent, device_t 
 	}
 
 	sc->type = TYPE_CS4281;
-	sc->halt_input  = cs4281_halt_input;
-	sc->halt_output = cs4281_halt_output;
 
 	sc->dma_size = CS4281_BUFFER_SIZE / MAX_CHANNELS;
 	sc->dma_align= 0x10;

Index: src/sys/dev/pci/cs428x.h
diff -u src/sys/dev/pci/cs428x.h:1.17 src/sys/dev/pci/cs428x.h:1.18
--- src/sys/dev/pci/cs428x.h:1.17	Wed May  8 13:40:18 2019
+++ src/sys/dev/pci/cs428x.h	Wed Feb  3 14:44:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cs428x.h,v 1.17 2019/05/08 13:40:18 isaki Exp $	*/
+/*	$NetBSD: cs428x.h,v 1.18 2021/02/03 14:44:32 isaki Exp $	*/
 
 /*
  * Copyright (c) 2000 Tatoku Ogaito.  All rights reserved.
@@ -106,7 +106,6 @@ struct cs428x_softc {
 	int	sc_pi;
 	struct	cs428x_dma *sc_pdma;
 	char	*sc_pbuf;
-	int	(*halt_output)(void *);
 	char	sc_prun;		/* playback status */
 	int	sc_prate;		/* playback sample rate */
 
@@ -118,7 +117,6 @@ struct cs428x_softc {
 	int	sc_ri;
 	struct	cs428x_dma *sc_rdma;
 	char	*sc_rbuf;
-	int	(*halt_input)(void *);
 	char	sc_rrun;		/* recording status */
 	int	sc_rrate;		/* recording sample rate */
 



CVS commit: src/sys/arch/arm/iomd

2021-02-03 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Feb  3 14:22:21 UTC 2021

Modified Files:
src/sys/arch/arm/iomd: vidcaudio.c

Log Message:
Remove a comment no longer correct.
Because halt_output is no longer called from an interrupt context,
but that does not mean it's better to put this back to halt_output.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/sys/arch/arm/iomd/vidcaudio.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/arch/arm/iomd/vidcaudio.c
diff -u src/sys/arch/arm/iomd/vidcaudio.c:1.60 src/sys/arch/arm/iomd/vidcaudio.c:1.61
--- src/sys/arch/arm/iomd/vidcaudio.c:1.60	Sun Feb 23 04:02:45 2020
+++ src/sys/arch/arm/iomd/vidcaudio.c	Wed Feb  3 14:22:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: vidcaudio.c,v 1.60 2020/02/23 04:02:45 isaki Exp $	*/
+/*	$NetBSD: vidcaudio.c,v 1.61 2021/02/03 14:22:21 isaki Exp $	*/
 
 /*
  * Copyright (c) 1995 Melvin Tang-Richardson
@@ -65,7 +65,7 @@
 
 #include 	/* proc.h */
 
-__KERNEL_RCSID(0, "$NetBSD: vidcaudio.c,v 1.60 2020/02/23 04:02:45 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vidcaudio.c,v 1.61 2021/02/03 14:22:21 isaki Exp $");
 
 #include 
 #include/* autoconfig functions */
@@ -293,11 +293,6 @@ vidcaudio_close(void *addr)
 
 	DPRINTF(("DEBUG: vidcaudio_close called\n"));
 	sc = addr;
-	/*
-	 * We do this here rather than in vidcaudio_halt_output()
-	 * because the latter can be called from interrupt context
-	 * (audio_pint()->audio_clear()->vidcaudio_halt_output()).
-	 */
 	if (sc->sc_ppages != NULL) {
 		free(sc->sc_ppages, M_DEVBUF);
 		sc->sc_ppages = NULL;



CVS commit: src/sys/dev/audio

2021-01-14 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Fri Jan 15 05:34:49 UTC 2021

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
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.87 -r1.88 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.87 src/sys/dev/audio/audio.c:1.88
--- src/sys/dev/audio/audio.c:1.87	Fri Jan 15 04:09:28 2021
+++ src/sys/dev/audio/audio.c	Fri Jan 15 05:34:49 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.87 2021/01/15 04:09:28 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.88 2021/01/15 05:34:49 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.87 2021/01/15 04:09:28 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.88 2021/01/15 05:34:49 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -515,6 +515,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 *);
@@ -972,19 +974,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 {
 		/*
@@ -994,8 +997,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)
@@ -1006,8 +1009,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;
 	}
 
@@ -1017,8 +1020,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;
 	}
 
@@ -1436,6 +1439,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.
@@ -1581,7 +1600,7 @@ audio_track_waitio(struct audio_softc *s
 	if (error) {
 		TRACET(2, track, "cv_timedwait_sig failed %d", error);
 		if (error == EWOULDBLOCK)
-			device_printf(sc->sc_dev, "device timeout\n");
+			audio_printf(sc, "device timeout\n");
 	} else {
 		TRACET(3, track, "wakeup");
 	}
@@ -2424,8 +2443,8 @@ audio_unlink(struct audio_softc *sc, aud
 		/* XXX what should I do on error? */
 		if (error == EWOULDBLOCK) {
 			mutex_exit(sc->sc_lock);
-			device_printf(sc->sc_dev,
-			"%s: cv_timedwait_sig failed %d\n",
+			audio_printf(sc,
+			"%s: cv_timedwait_sig failed: errno=%d\n",
 			__func__, error);
 			return error;
 		}
@@ -2449,8 +2468,8 @@ audio_unlink(struct audio_softc 

CVS commit: src/sys/dev/audio

2021-01-14 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Fri Jan 15 04:09:28 UTC 2021

Modified Files:
src/sys/dev/audio: audio.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 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.86 src/sys/dev/audio/audio.c:1.87
--- src/sys/dev/audio/audio.c:1.86	Sat Dec 19 01:18:58 2020
+++ src/sys/dev/audio/audio.c	Fri Jan 15 04:09:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.86 2020/12/19 01:18:58 thorpej Exp $	*/
+/*	$NetBSD: audio.c,v 1.87 2021/01/15 04:09:28 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.86 2020/12/19 01:18:58 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.87 2021/01/15 04:09:28 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -3140,7 +3140,7 @@ filt_audioread_detach(struct knote *kn)
 
 	file = kn->kn_hook;
 	sc = file->sc;
-	TRACEF(3, file, "");
+	TRACEF(3, file, "called");
 
 	mutex_enter(sc->sc_lock);
 	selremove_knote(>sc_rsel, kn);
@@ -3187,7 +3187,7 @@ filt_audiowrite_detach(struct knote *kn)
 
 	file = kn->kn_hook;
 	sc = file->sc;
-	TRACEF(3, file, "");
+	TRACEF(3, file, "called");
 
 	mutex_enter(sc->sc_lock);
 	selremove_knote(>sc_wsel, kn);
@@ -3344,7 +3344,7 @@ audioctl_open(dev_t dev, struct audio_so
 
 	KASSERT(sc->sc_exlock);
 
-	TRACE(1, "");
+	TRACE(1, "called");
 
 	error = fd_allocfile(, );
 	if (error)
@@ -5856,7 +5856,7 @@ audio_pmixer_halt(struct audio_softc *sc
 {
 	int error;
 
-	TRACE(2, "");
+	TRACE(2, "called");
 	KASSERT(mutex_owned(sc->sc_lock));
 	KASSERT(sc->sc_exlock);
 
@@ -5886,7 +5886,7 @@ audio_rmixer_halt(struct audio_softc *sc
 {
 	int error;
 
-	TRACE(2, "");
+	TRACE(2, "called");
 	KASSERT(mutex_owned(sc->sc_lock));
 	KASSERT(sc->sc_exlock);
 
@@ -8069,7 +8069,7 @@ mixer_close(struct audio_softc *sc, audi
 	error = audio_exlock_enter(sc);
 	if (error)
 		return error;
-	TRACE(1, "");
+	TRACE(1, "called");
 	mixer_async_remove(sc, curproc->p_pid);
 	audio_exlock_exit(sc);
 



CVS commit: src/sys/dev/audio

2020-12-12 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Dec 13 05:47:09 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Revise comments.


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 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.84 src/sys/dev/audio/audio.c:1.85
--- src/sys/dev/audio/audio.c:1.84	Sun Dec 13 05:44:09 2020
+++ src/sys/dev/audio/audio.c	Sun Dec 13 05:47:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.84 2020/12/13 05:44:09 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.85 2020/12/13 05:47:08 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.84 2020/12/13 05:44:09 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.85 2020/12/13 05:47:08 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2415,7 +2415,8 @@ audio_unlink(struct audio_softc *sc, aud
 
 	/*
 	 * Acquire exlock to protect counters.
-	 * Does not use audio_exlock_enter() due to sc_dying.
+	 * audio_exlock_enter() cannot be used here because we have to go
+	 * forward even if sc_dying is set.
 	 */
 	while (__predict_false(sc->sc_exlock != 0)) {
 		error = cv_timedwait_sig(>sc_exlockcv, sc->sc_lock,
@@ -6153,8 +6154,8 @@ audio_softintr_wr(void *cookie)
 
 /*
  * Check (and convert) the format *p came from userland.
- * If successful, it writes back the converted format to *p if necessary
- * and returns 0.  Otherwise returns errno (*p may change even this case).
+ * If successful, it writes back the converted format to *p if necessary and
+ * returns 0.  Otherwise returns errno (*p may be changed even in this case).
  */
 static int
 audio_check_params(audio_format2_t *p)



CVS commit: src/sys/dev/audio

2020-12-12 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Dec 13 05:44:09 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
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.83 -r1.84 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.83 src/sys/dev/audio/audio.c:1.84
--- src/sys/dev/audio/audio.c:1.83	Sun Dec 13 05:29:19 2020
+++ src/sys/dev/audio/audio.c	Sun Dec 13 05:44:09 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.83 2020/12/13 05:29:19 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.84 2020/12/13 05:44:09 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.83 2020/12/13 05:29:19 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.84 2020/12/13 05:44:09 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -1873,7 +1873,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: src/sys/dev/audio

2020-12-12 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Dec 13 05:29:20 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
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.82 -r1.83 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.82 src/sys/dev/audio/audio.c:1.83
--- src/sys/dev/audio/audio.c:1.82	Sun Dec 13 05:21:12 2020
+++ src/sys/dev/audio/audio.c	Sun Dec 13 05:29:19 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.82 2020/12/13 05:21:12 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.83 2020/12/13 05:29:19 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.82 2020/12/13 05:21:12 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.83 2020/12/13 05:29:19 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -1331,7 +1331,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.
@@ -1357,6 +1356,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: src/sys/dev/audio

2020-12-12 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Dec 13 05:21:12 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Add missing newline.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 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.81 src/sys/dev/audio/audio.c:1.82
--- src/sys/dev/audio/audio.c:1.81	Wed Dec  9 04:30:39 2020
+++ src/sys/dev/audio/audio.c	Sun Dec 13 05:21:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.81 2020/12/09 04:30:39 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.82 2020/12/13 05:21:12 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.81 2020/12/09 04:30:39 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.82 2020/12/13 05:21:12 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2424,7 +2424,8 @@ audio_unlink(struct audio_softc *sc, aud
 		if (error == EWOULDBLOCK) {
 			mutex_exit(sc->sc_lock);
 			device_printf(sc->sc_dev,
-			"%s: cv_timedwait_sig failed %d", __func__, error);
+			"%s: cv_timedwait_sig failed %d\n",
+			__func__, error);
 			return error;
 		}
 	}



CVS commit: src/share/man/man4

2020-12-08 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Dec  9 05:48:56 UTC 2020

Modified Files:
src/share/man/man4: audio.4

Log Message:
Remove an old description.
This behavior was modified in sys/dev/audio/audio.c rev 1.65 (Mar. 2020).


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/share/man/man4/audio.4

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

Modified files:

Index: src/share/man/man4/audio.4
diff -u src/share/man/man4/audio.4:1.103 src/share/man/man4/audio.4:1.104
--- src/share/man/man4/audio.4:1.103	Sat Mar 28 05:47:41 2020
+++ src/share/man/man4/audio.4	Wed Dec  9 05:48:56 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: audio.4,v 1.103 2020/03/28 05:47:41 wiz Exp $
+.\"	$NetBSD: audio.4,v 1.104 2020/12/09 05:48:56 isaki Exp $
 .\"
 .\" Copyright (c) 1996 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -85,8 +85,6 @@ are identical.
 .Pp
 On a full-duplex device, reads and writes may operate concurrently
 without interference.
-If a full-duplex capable audio device is opened for both reading and writing
-it will start in play mode but not start in record mode.
 .Pp
 On a half-duplex device, if there are any recording descriptors already,
 opening with write mode will fail.



CVS commit: src/sys/dev/audio

2020-12-08 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Dec  9 04:30:39 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
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.80 -r1.81 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.80 src/sys/dev/audio/audio.c:1.81
--- src/sys/dev/audio/audio.c:1.80	Wed Dec  9 04:24:08 2020
+++ src/sys/dev/audio/audio.c	Wed Dec  9 04:30:39 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.80 2020/12/09 04:24:08 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.81 2020/12/09 04:30:39 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.80 2020/12/09 04:24:08 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.81 2020/12/09 04:30:39 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2082,6 +2082,8 @@ 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;
@@ -2093,6 +2095,9 @@ 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);
@@ -2104,7 +2109,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);
@@ -2120,7 +2125,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;
@@ -2129,7 +2134,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;
 			}
 		}
 	}
@@ -2176,13 +2181,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;
@@ -2215,8 +2221,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.
@@ -2236,14 +2250,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;
 		}
 	}
 
@@ -2260,7 +2274,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;
 		}
 	}
 	/*
@@ -2279,7 +2293,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;
 		}
 
 		mutex_enter(sc->sc_lock);
@@ -2288,10 +2302,15 @@ audio_open(dev_t dev, struct audio_softc
 		rmixer_started = true;
 	}
 
-	if (bellfile == NULL) {
+	if (bellfile) {
+		*bellfile = af;
+	} else {
 		error = fd_allocfile(, );
 		if (error)
-			goto bad4;
+			goto bad;
+
+		error = fd_clone(fp, fd, flags, _fileops, af);
+		KASSERTMSG(error == EMOVEFD, "error=%d", error);
 	}
 
 	/*
@@ -2308,24 +2327,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, "error=%d", error);
-	}
-
 	TRACEF(3, af, "done");
 	return error;
 
-bad4:
+bad:
+	if (fp) {
+		fd_abort(curproc, fp, fd);
+	}
+
 	if (rmixer_started) {
 		mutex_enter(sc->sc_lock);
 		audio_rmixer_halt(sc);
 		mutex_exit(sc->sc_lock);
 	}
-bad3:
-	if (sc->sc_popens + sc->sc_ropens == 0) {
+
+	if (hw_opened) {
 		if (sc->hw_if->close) {
 			mutex_enter(sc->sc_lock);
 			

CVS commit: src/sys/dev/audio

2020-12-08 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Dec  9 04:24:08 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Fix that audio_open() didn't halt the recording mixer correctly
if fd_allocfile() failed, since rev 1.65.
Will fix PR kern/55848.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 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.79 src/sys/dev/audio/audio.c:1.80
--- src/sys/dev/audio/audio.c:1.79	Mon Sep  7 03:36:11 2020
+++ src/sys/dev/audio/audio.c	Wed Dec  9 04:24:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.79 2020/09/07 03:36:11 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.80 2020/12/09 04:24:08 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.79 2020/09/07 03:36:11 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.80 2020/12/09 04:24:08 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2082,6 +2082,7 @@ audio_open(dev_t dev, struct audio_softc
 	audio_file_t *af;
 	audio_ring_t *hwbuf;
 	bool fullduplex;
+	bool rmixer_started;
 	int fd;
 	int error;
 
@@ -2092,6 +2093,8 @@ audio_open(dev_t dev, struct audio_softc
 	ISDEVSOUND(dev) ? "sound" : "audio",
 	flags, sc->sc_popens, sc->sc_ropens);
 
+	rmixer_started = false;
+
 	af = kmem_zalloc(sizeof(audio_file_t), KM_SLEEP);
 	af->sc = sc;
 	af->dev = dev;
@@ -2282,12 +2285,13 @@ audio_open(dev_t dev, struct audio_softc
 		mutex_enter(sc->sc_lock);
 		audio_rmixer_start(sc);
 		mutex_exit(sc->sc_lock);
+		rmixer_started = true;
 	}
 
 	if (bellfile == NULL) {
 		error = fd_allocfile(, );
 		if (error)
-			goto bad3;
+			goto bad4;
 	}
 
 	/*
@@ -2314,10 +2318,12 @@ audio_open(dev_t dev, struct audio_softc
 	TRACEF(3, af, "done");
 	return error;
 
-	/*
-	 * Since track here is not yet linked to sc_files,
-	 * you can call track_destroy() without sc_intr_lock.
-	 */
+bad4:
+	if (rmixer_started) {
+		mutex_enter(sc->sc_lock);
+		audio_rmixer_halt(sc);
+		mutex_exit(sc->sc_lock);
+	}
 bad3:
 	if (sc->sc_popens + sc->sc_ropens == 0) {
 		if (sc->hw_if->close) {
@@ -2329,6 +2335,10 @@ bad3:
 		}
 	}
 bad2:
+	/*
+	 * Since track here is not yet linked to sc_files,
+	 * you can call track_destroy() without sc_intr_lock.
+	 */
 	if (af->rtrack) {
 		audio_track_destroy(af->rtrack);
 		af->rtrack = NULL;



CVS commit: src

2020-09-12 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Sep 13 04:14:49 UTC 2020

Modified Files:
src/sys/dev/audio: audio_if.h audiodef.h
src/usr.bin/fstat: misc.c

Log Message:
Support audio descriptor for fstat(1).
sys/dev/audio/*.h: export only what we need for fstat.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/audio/audio_if.h
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/audio/audiodef.h
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/fstat/misc.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_if.h
diff -u src/sys/dev/audio/audio_if.h:1.2 src/sys/dev/audio/audio_if.h:1.3
--- src/sys/dev/audio/audio_if.h:1.2	Wed May  8 13:40:17 2019
+++ src/sys/dev/audio/audio_if.h	Sun Sep 13 04:14:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio_if.h,v 1.2 2019/05/08 13:40:17 isaki Exp $	*/
+/*	$NetBSD: audio_if.h,v 1.3 2020/09/13 04:14:48 isaki Exp $	*/
 
 /*
  * Copyright (c) 1994 Havard Eidnes.
@@ -57,6 +57,8 @@
 
 struct audio_softc;
 
+#if defined(_KERNEL)
+
 /**
  * audio stream format
  */
@@ -154,6 +156,8 @@ extern int audio_indexof_format(const st
 	const audio_params_t *);
 extern const char *audio_encoding_name(int);
 
+#endif /* _KERNEL */
+
 /* Device identity flags */
 #define SOUND_DEVICE		0
 #define AUDIO_DEVICE		0x80

Index: src/sys/dev/audio/audiodef.h
diff -u src/sys/dev/audio/audiodef.h:1.14 src/sys/dev/audio/audiodef.h:1.15
--- src/sys/dev/audio/audiodef.h:1.14	Wed Apr 29 03:58:27 2020
+++ src/sys/dev/audio/audiodef.h	Sun Sep 13 04:14:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiodef.h,v 1.14 2020/04/29 03:58:27 isaki Exp $	*/
+/*	$NetBSD: audiodef.h,v 1.15 2020/09/13 04:14:48 isaki Exp $	*/
 
 /*
  * Copyright (C) 2017 Tetsuya Isaki. All rights reserved.
@@ -78,6 +78,8 @@
 #define AUDIO_SCALEDOWN(value, bits)	((value) / (1 << (bits)))
 #endif
 
+#if defined(_KERNEL)
+
 /* conversion stage */
 typedef struct {
 	audio_ring_t srcbuf;
@@ -92,7 +94,7 @@ typedef enum {
 	AUDIO_STATE_DRAINING,	/* now draining */
 } audio_state_t;
 
-typedef struct audio_track {
+struct audio_track {
 	/*
 	 * AUMODE_PLAY for playback track, or
 	 * AUMODE_RECORD for recoding track.
@@ -167,7 +169,10 @@ typedef struct audio_track {
 	volatile uint	lock;
 
 	int		id;		/* track id for debug */
-} audio_track_t;
+};
+#endif /* _KERNEL */
+
+typedef struct audio_track audio_track_t;
 
 struct audio_file {
 	struct audio_softc *sc;
@@ -197,6 +202,8 @@ struct audio_file {
 	SLIST_ENTRY(audio_file) entry;
 };
 
+#if defined(_KERNEL)
+
 struct audio_trackmixer {
 	struct audio_softc *sc;
 
@@ -439,4 +446,6 @@ auring_get_contig_free(const audio_ring_
 	}
 }
 
+#endif /* _KERNEL */
+
 #endif /* !_SYS_DEV_AUDIO_AUDIODEF_H_ */

Index: src/usr.bin/fstat/misc.c
diff -u src/usr.bin/fstat/misc.c:1.23 src/usr.bin/fstat/misc.c:1.24
--- src/usr.bin/fstat/misc.c:1.23	Sat May  2 18:42:30 2020
+++ src/usr.bin/fstat/misc.c	Sun Sep 13 04:14:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: misc.c,v 1.23 2020/05/02 18:42:30 christos Exp $	*/
+/*	$NetBSD: misc.c,v 1.24 2020/09/13 04:14:48 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: misc.c,v 1.23 2020/05/02 18:42:30 christos Exp $");
+__RCSID("$NetBSD: misc.c,v 1.24 2020/09/13 04:14:48 isaki Exp $");
 
 #include 
 #include 
@@ -60,6 +60,9 @@ __RCSID("$NetBSD: misc.c,v 1.23 2020/05/
 
 #include 
 
+#include 
+#include 
+
 #include 
 #include 
 #include 
@@ -220,6 +223,46 @@ p_kqueue(struct file *f)
 	return 0;
 }
 
+static int
+p_audio(struct file *f)
+{
+	struct audio_file af;
+	const char *devname;
+	const char *modename;
+
+	if (!KVM_READ(f->f_data, , sizeof(af))) {
+		dprintf("can't read audio_file at %p for pid %d",
+		f->f_data, Pid);
+		return 0;
+	}
+
+	if (ISDEVAUDIO(af.dev)) {
+		devname = "audio";
+	} else if (ISDEVSOUND(af.dev)) {
+		devname = "sound";
+	} else if (ISDEVAUDIOCTL(af.dev)) {
+		devname = "audioctl";
+	} else if (ISDEVMIXER(af.dev)) {
+		devname = "mixer";
+	} else {
+		devname = "???";
+	}
+
+	if (af.ptrack && af.rtrack) {
+		modename = "playback, record";
+	} else if (af.ptrack) {
+		modename = "playback";
+	} else if (af.rtrack) {
+		modename = "record";
+	} else {
+		modename = "-";
+	}
+
+	(void)printf("* audio@%s%d %s", devname, AUDIOUNIT(af.dev), modename);
+	oprint(f, "\n");
+	return 0;
+}
+
 int
 pmisc(struct file *f, const char *name)
 {
@@ -263,8 +306,7 @@ pmisc(struct file *f, const char *name)
 		printf("* crypto %p", f->f_data);
 		break;
 	case NL_AUDIO:
-		printf("* audio %p", f->f_data);
-		break;
+		return p_audio(f);
 	case NL_PAD:
 		printf("* pad %p", f->f_data);
 		break;



CVS commit: src/sys/dev/audio

2020-09-12 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Sep 12 06:09:17 UTC 2020

Modified Files:
src/sys/dev/audio: mulaw.c

Log Message:
Improve slinear16-to-mulaw conversion calculation.
It's about 2~3 times faster on my amd64 and x68k(68030).


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/audio/mulaw.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/mulaw.c
diff -u src/sys/dev/audio/mulaw.c:1.3 src/sys/dev/audio/mulaw.c:1.4
--- src/sys/dev/audio/mulaw.c:1.3	Sat Jan 11 04:06:13 2020
+++ src/sys/dev/audio/mulaw.c	Sat Sep 12 06:09:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: mulaw.c,v 1.3 2020/01/11 04:06:13 isaki Exp $	*/
+/*	$NetBSD: mulaw.c,v 1.4 2020/09/12 06:09:16 isaki Exp $	*/
 
 /*
  * Copyright (C) 2017 Tetsuya Isaki. All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mulaw.c,v 1.3 2020/01/11 04:06:13 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mulaw.c,v 1.4 2020/09/12 06:09:16 isaki Exp $");
 
 #include 
 #include 
@@ -45,7 +45,7 @@ __KERNEL_RCSID(0, "$NetBSD: mulaw.c,v 1.
  *
  * 2. Calculation (default)
  *  It calculates mu-law with full spec and its precision is 14bit.
- *  It's about 10 times slower but the size is less than a half (on m68k,
+ *  It's about 3 times slower but the size is less than a half (on m68k,
  *  for example).
  *
  * mu-law is no longer a popular format.  I think size-optimized is better.
@@ -247,33 +247,40 @@ audio_internal_to_mulaw32(audio_filter_a
 		m = slinear8_to_mulaw[val];
 #else
 		/* 14bit (fullspec, slow but small) encoder */
-		int16_t val;
+		uint16_t val;
 		int c;
 
-		val = (int16_t)(*s++ >> (AUDIO_INTERNAL_BITS - 16));
-		if (val < 0) {
+		val = *s++ >> (AUDIO_INTERNAL_BITS - 16);
+		if ((int16_t)val < 0) {
 			m = 0;
 		} else {
 			val = ~val;
 			m = 0x80;
 		}
 		/* limit */
-		if (val < -8158 * 4)
+		if ((int16_t)val < -8158 * 4)
 			val = -8158 * 4;
 		val -= 33 * 4;	/* bias */
 
-		val <<= 1;
-		for (c = 0; c < 7; c++) {
-			if (val >= 0) {
-break;
-			}
+		// Before(1) Before(2) Before(3)
+		// S0xx_ 0xxx_xxx0 c=0,v=0xxx_xxx0
+		// S10x_ 10xx_xxx0 c=1,v=0xxx_xx00
+		// S110_ 110x_xxx0 c=2,v=0xxx_x000
+		// : : :
+		// S110_ 110M_MMM0 c=6,v=0xxx_x000
 
-			m += (1 << 4);	/* exponent */
-			val <<= 1;
-		}
+		// (1) Push out sign bit
 		val <<= 1;
 
-		m += (val >> 12) & 0x0f; /* mantissa */
+		// (2) Find first zero (and align val to left)
+		c = 0;
+		if (val >= 0xf000) c += 4, val <<= 4;
+		if (val >= 0xc000) c += 2, val <<= 2;
+		if (val >= 0x8000) c += 1, val <<= 1;
+
+		// (3)
+		m += (c << 4);
+		m += (val >> 11) & 0x0f;
 #endif
 
 #if defined(MULAW32)



CVS commit: src/sys

2020-09-11 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Sep 12 05:19:16 UTC 2020

Modified Files:
src/sys/arch/sparc/conf: files.sparc
src/sys/arch/sparc/dev: audioamd.c
src/sys/arch/sparc/sparc: genassym.cf
src/sys/arch/vax/vsa: vsaudio.c
src/sys/dev/ic: am7930.c am7930var.h
src/sys/dev/tc: bba.c
Removed Files:
src/sys/arch/sparc/dev: audioamdvar.h
src/sys/arch/sparc/include: am7930_machdep.h
src/sys/arch/sparc/sparc: amd7930intr.s

Log Message:
Improve am7930 family drivers to share more code.
audioamd(4) on sparc, vsaudio(4) on vax, and bba(4) are.
- Remove complex and useless callbacks: onopen, onclose, and
  indirect_{read,write}.  This makes audioamd and vsaudio almost the same.
- Remove (already disabled) assembly fast interrupt path from audioamd(4).
  cf. http://mail-index.netbsd.org/source-changes/2009/12/19/msg004585.html
- Use trigger_* method rather than start_* method.  It's more suitable.
vsaudio(4) was tested by naru@, bba(4) was tested by tsutsui@.


To generate a diff of this commit:
cvs rdiff -u -r1.159 -r1.160 src/sys/arch/sparc/conf/files.sparc
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/sparc/dev/audioamd.c
cvs rdiff -u -r1.4 -r0 src/sys/arch/sparc/dev/audioamdvar.h
cvs rdiff -u -r1.1 -r0 src/sys/arch/sparc/include/am7930_machdep.h
cvs rdiff -u -r1.23 -r0 src/sys/arch/sparc/sparc/amd7930intr.s
cvs rdiff -u -r1.70 -r1.71 src/sys/arch/sparc/sparc/genassym.cf
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/vax/vsa/vsaudio.c
cvs rdiff -u -r1.59 -r1.60 src/sys/dev/ic/am7930.c
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/ic/am7930var.h
cvs rdiff -u -r1.45 -r1.46 src/sys/dev/tc/bba.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/arch/sparc/conf/files.sparc
diff -u src/sys/arch/sparc/conf/files.sparc:1.159 src/sys/arch/sparc/conf/files.sparc:1.160
--- src/sys/arch/sparc/conf/files.sparc:1.159	Fri Mar  1 02:28:27 2019
+++ src/sys/arch/sparc/conf/files.sparc	Sat Sep 12 05:19:15 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.sparc,v 1.159 2019/03/01 02:28:27 macallan Exp $
+#	$NetBSD: files.sparc,v 1.160 2020/09/12 05:19:15 isaki Exp $
 
 # @(#)files.sparc	8.1 (Berkeley) 7/19/93
 # sparc-specific configuration info
@@ -233,7 +233,6 @@ attach	audioamd at mainbus with audioamd
 attach	audioamd at obio with audioamd_obio
 attach	audioamd at sbus with audioamd_sbus
 file	arch/sparc/dev/audioamd.c		audioamd
-file	arch/sparc/sparc/amd7930intr.s		audioamd
 
 device	apc
 attach	apc at sbus

Index: src/sys/arch/sparc/dev/audioamd.c
diff -u src/sys/arch/sparc/dev/audioamd.c:1.29 src/sys/arch/sparc/dev/audioamd.c:1.30
--- src/sys/arch/sparc/dev/audioamd.c:1.29	Wed May  8 13:40:16 2019
+++ src/sys/arch/sparc/dev/audioamd.c	Sat Sep 12 05:19:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audioamd.c,v 1.29 2019/05/08 13:40:16 isaki Exp $	*/
+/*	$NetBSD: audioamd.c,v 1.30 2020/09/12 05:19:16 isaki Exp $	*/
 /*	NetBSD: am7930_sparc.c,v 1.44 1999/03/14 22:29:00 jonathan Exp 	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audioamd.c,v 1.29 2019/05/08 13:40:16 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audioamd.c,v 1.30 2020/09/12 05:19:16 isaki Exp $");
 
 #include "audio.h"
 #if NAUDIO > 0
@@ -52,52 +52,14 @@ __KERNEL_RCSID(0, "$NetBSD: audioamd.c,v
 
 #include 
 #include 
-#include 
 
 #define AUDIO_ROM_NAME "audio"
 
-#ifdef AUDIO_DEBUG
-#define DPRINTF(x)  if (am7930debug) printf x
-#define DPRINTFN(n,x)   if (am7930debug>(n)) printf x
-#else
-#define DPRINTF(x)
-#define DPRINTFN(n,x)
-#endif	/* AUDIO_DEBUG */
-
-
-/* interrupt interfaces */
-int	am7930hwintr(void *);
-struct auio *auiop;
-void	am7930swintr(void *);
-
-/* from amd7930intr.s: */
-void	amd7930_trap(void);
-
-/*
- * interrupt-handler status
- */
-struct am7930_intrhand {
-	int	(*ih_fun)(void *);
-	void	*ih_arg;
-};
-
 struct audioamd_softc {
 	struct am7930_softc sc_am7930;	/* glue to MI code */
 
 	bus_space_tag_t sc_bt;		/* bus cookie */
 	bus_space_handle_t sc_bh;	/* device registers */
-
-	struct am7930_intrhand	sc_ih;	/* interrupt vector (hw or sw)  */
-	void	(*sc_rintr)(void*);	/* input completion intr handler */
-	void	*sc_rarg;		/* arg for sc_rintr() */
-	void	(*sc_pintr)(void*);	/* output completion intr handler */
-	void	*sc_parg;		/* arg for sc_pintr() */
-
-	/* sc_au is special in that the hardware interrupt handler uses it */
-	struct  auio sc_au;		/* recv and xmit buffers, etc */
-#define sc_intrcnt	sc_au.au_intrcnt	/* statistics */
-	void	*sc_sicookie;		/* softintr(9) cookie */
-	kmutex_t	sc_lock;
 };
 
 int	audioamd_mainbus_match(device_t, cfdata_t, void *);
@@ -121,40 +83,25 @@ CFATTACH_DECL_NEW(audioamd_sbus, sizeof(
  * Define our interface into the am7930 MI driver.
  */
 
-uint8_t	audioamd_codec_iread(struct am7930_softc *, int);
-uint16_t	audioamd_codec_iread16(struct am7930_softc *, int);
-uint8_t	audioamd_codec_dread(struct audioamd_softc *, int);
-void	

CVS commit: src/sys/dev/audio

2020-09-06 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Mon Sep  7 03:36:11 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Fix misspellings in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 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.78 src/sys/dev/audio/audio.c:1.79
--- src/sys/dev/audio/audio.c:1.78	Sun Aug 23 04:20:01 2020
+++ src/sys/dev/audio/audio.c	Mon Sep  7 03:36:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.78 2020/08/23 04:20:01 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.79 2020/09/07 03:36:11 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.78 2020/08/23 04:20:01 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.79 2020/09/07 03:36:11 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2961,7 +2961,7 @@ audio_ioctl(dev_t dev, struct audio_soft
 		mutex_enter(sc->sc_lock);
 		error = sc->hw_if->query_format(sc->hw_hdl, query);
 		mutex_exit(sc->sc_lock);
-		/* Hide internal infomations */
+		/* Hide internal information */
 		query->fmt.driver_data = NULL;
 		break;
 
@@ -4775,7 +4775,7 @@ audio_track_record(audio_track_t *track)
 }
 
 /*
- * Calcurate blktime [msec] from mixer(.hwbuf.fmt).
+ * Calculate blktime [msec] from mixer(.hwbuf.fmt).
  * Must be called with sc_exlock held.
  */
 static u_int
@@ -4910,7 +4910,7 @@ audio_mixer_init(struct audio_softc *sc,
 			return EINVAL;
 		}
 		if (rounded != bufsize) {
-			/* Recalcuration */
+			/* Recalculation */
 			bufsize = rounded;
 			hwblks = bufsize / blksize;
 			capacity = mixer->frames_per_block * hwblks;



CVS commit: src/sys/dev/tc

2020-08-28 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 29 03:24:31 UTC 2020

Modified Files:
src/sys/dev/tc: bba.c

Log Message:
Fix white space and indent.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/dev/tc/bba.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/tc/bba.c
diff -u src/sys/dev/tc/bba.c:1.44 src/sys/dev/tc/bba.c:1.45
--- src/sys/dev/tc/bba.c:1.44	Sat Jun  8 08:02:38 2019
+++ src/sys/dev/tc/bba.c	Sat Aug 29 03:24:31 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: bba.c,v 1.44 2019/06/08 08:02:38 isaki Exp $ */
+/* $NetBSD: bba.c,v 1.45 2020/08/29 03:24:31 isaki Exp $ */
 
 /*
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 /* maxine/alpha baseboard audio (bba) */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bba.c,v 1.44 2019/06/08 08:02:38 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bba.c,v 1.45 2020/08/29 03:24:31 isaki Exp $");
 
 #include 
 #include 
@@ -230,7 +230,7 @@ bba_attach(device_t parent, device_t sel
 
 	printf("\n");
 
-	bba_reset(sc,1);
+	bba_reset(sc, 1);
 
 	/*
 	 * Set up glue for MI code early; we use some of it here.
@@ -285,7 +285,6 @@ bba_reset(struct bba_softc *sc, int rese
 		ssr |= IOASIC_CSR_ISDN_ENABLE;
 		bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_CSR, ssr);
 	}
-
 }
 
 
@@ -468,7 +467,7 @@ bba_trigger_output(void *addr, void *sta
 
 	if (bus_dmamap_load(sc->sc_dmat, d->dmam, start,
 	(char *)end - (char *)start, NULL, BUS_DMA_WRITE|BUS_DMA_NOWAIT)) {
-	printf("bba_trigger_output: can't load DMA map\n");
+		printf("bba_trigger_output: can't load DMA map\n");
 		goto bad;
 	}
 	state |= 2;



CVS commit: src/sys/arch/vax/vsa

2020-08-26 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Aug 26 12:59:28 UTC 2020

Modified Files:
src/sys/arch/vax/vsa: vsaudio.c

Log Message:
Fix misuse of device_private().  sc_dev is device_t.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/vax/vsa/vsaudio.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/arch/vax/vsa/vsaudio.c
diff -u src/sys/arch/vax/vsa/vsaudio.c:1.5 src/sys/arch/vax/vsa/vsaudio.c:1.6
--- src/sys/arch/vax/vsa/vsaudio.c:1.5	Wed May  8 13:40:16 2019
+++ src/sys/arch/vax/vsa/vsaudio.c	Wed Aug 26 12:59:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vsaudio.c,v 1.5 2019/05/08 13:40:16 isaki Exp $	*/
+/*	$NetBSD: vsaudio.c,v 1.6 2020/08/26 12:59:28 isaki Exp $	*/
 /*	$OpenBSD: vsaudio.c,v 1.4 2013/05/15 21:21:11 ratchov Exp $	*/
 
 /*
@@ -271,7 +271,7 @@ vsaudio_attach(device_t parent, device_t
 		return;
 	}
 	sc->sc_bt = va->va_memt;
-	sc->sc_am7930.sc_dev = device_private(self);
+	sc->sc_am7930.sc_dev = self;
 	sc->sc_am7930.sc_glue = _glue;
 	mutex_init(>sc_lock, MUTEX_DEFAULT, IPL_HIGH);
 	am7930_init(>sc_am7930, AUDIOAMD_POLL_MODE);



CVS commit: src/sys/dev/audio

2020-08-22 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Aug 23 04:20:01 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Improve debug messages.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 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.77 src/sys/dev/audio/audio.c:1.78
--- src/sys/dev/audio/audio.c:1.77	Sun Aug 23 04:14:57 2020
+++ src/sys/dev/audio/audio.c	Sun Aug 23 04:20:01 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.77 2020/08/23 04:14:57 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.78 2020/08/23 04:20:01 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.77 2020/08/23 04:14:57 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.78 2020/08/23 04:20:01 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2498,7 +2498,7 @@ audio_read(struct audio_softc *sc, struc
 	if (track->mmapped)
 		return EPERM;
 
-	TRACET(2, track, "resid=%zd", uio->uio_resid);
+	TRACET(2, track, "resid=%zd ioflag=0x%x", uio->uio_resid, ioflag);
 
 #ifdef AUDIO_PM_IDLE
 	error = audio_exlock_mutex_enter(sc);
@@ -6082,7 +6082,7 @@ audio_softintr_wr(void *cookie)
 		if (track == NULL)
 			continue;
 
-		TRACET(4, track, "broadcast; trseq=%d out=%d/%d/%d",
+		TRACET(4, track, "broadcast; trkseq=%d out=%d/%d/%d",
 		(int)track->seq,
 		track->outbuf.head,
 		track->outbuf.used,



CVS commit: src/sys/dev/audio

2020-08-22 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Aug 23 04:14:57 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Improve and update comments.


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 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.76 src/sys/dev/audio/audio.c:1.77
--- src/sys/dev/audio/audio.c:1.76	Sun Aug 23 04:07:23 2020
+++ src/sys/dev/audio/audio.c	Sun Aug 23 04:14:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.76 2020/08/23 04:07:23 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.77 2020/08/23 04:14:57 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.76 2020/08/23 04:07:23 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.77 2020/08/23 04:14:57 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -4233,8 +4233,9 @@ audio_track_init_freq(audio_track_t *tra
 
 /*
  * Set the userland format of this track.
- * usrfmt argument should be parameter verified with audio_check_params().
- * It will release and reallocate all internal conversion buffers.
+ * usrfmt argument should have been previously verified by
+ * audio_track_setinfo_check().
+ * This function may release and reallocate all internal conversion buffers.
  * It returns 0 if successful.  Otherwise it returns errno with clearing all
  * internal buffers.
  * It must be called without sc_intr_lock since uvm_* routines require non
@@ -7295,7 +7296,7 @@ abort:
  * - pfil and rfil must be zero-filled.
  * If successful,
  * - pfil, rfil will be filled with filter information specified by the
- *   hardware driver.
+ *   hardware driver if necessary.
  * and then returns 0.  Otherwise returns errno.
  * Must be called without sc_lock held.
  */



CVS commit: src/sys/dev/audio

2020-08-22 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Aug 23 04:07:23 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Style fixes.


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 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.75 src/sys/dev/audio/audio.c:1.76
--- src/sys/dev/audio/audio.c:1.75	Fri May 29 03:09:14 2020
+++ src/sys/dev/audio/audio.c	Sun Aug 23 04:07:23 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.75 2020/05/29 03:09:14 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.76 2020/08/23 04:07:23 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.75 2020/05/29 03:09:14 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.76 2020/08/23 04:07:23 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -901,13 +901,15 @@ audioattach(device_t parent, device_t se
 		return;
 	}
 	if (has_playback) {
-		if ((hw_if->start_output == NULL && hw_if->trigger_output == NULL) ||
+		if ((hw_if->start_output == NULL &&
+		 hw_if->trigger_output == NULL) ||
 		hw_if->halt_output == NULL) {
 			aprint_error(": missing playback method\n");
 		}
 	}
 	if (has_capture) {
-		if ((hw_if->start_input == NULL && hw_if->trigger_input == NULL) ||
+		if ((hw_if->start_input == NULL &&
+		 hw_if->trigger_input == NULL) ||
 		hw_if->halt_input == NULL) {
 			aprint_error(": missing capture method\n");
 		}
@@ -6129,7 +6131,7 @@ audio_check_params(audio_format2_t *p)
 
 	/*
 	 * Convert obsolete AUDIO_ENCODING_PCM encodings.
-	 * 
+	 *
 	 * AUDIO_ENCODING_PCM16 == AUDIO_ENCODING_LINEAR
 	 * So, it's always signed, as in SunOS.
 	 *
@@ -6432,7 +6434,7 @@ audio_hw_probe(struct audio_softc *sc, a
  * If fmt is included in the result of query_format, returns 0.
  * Otherwise returns EINVAL.
  * Must be called without sc_lock held.
- */ 
+ */
 static int
 audio_hw_validate_format(struct audio_softc *sc, int mode,
 	const audio_format2_t *fmt)



CVS commit: src/sys/arch/x68k/stand/xxboot

2020-08-22 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 22 10:12:29 UTC 2020

Modified Files:
src/sys/arch/x68k/stand/xxboot: ashldi3.S

Log Message:
Minor improvement.
add/addx is faster and the size remains the same.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/x68k/stand/xxboot/ashldi3.S

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

Modified files:

Index: src/sys/arch/x68k/stand/xxboot/ashldi3.S
diff -u src/sys/arch/x68k/stand/xxboot/ashldi3.S:1.2 src/sys/arch/x68k/stand/xxboot/ashldi3.S:1.3
--- src/sys/arch/x68k/stand/xxboot/ashldi3.S:1.2	Sat Aug 22 10:05:04 2020
+++ src/sys/arch/x68k/stand/xxboot/ashldi3.S	Sat Aug 22 10:12:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ashldi3.S,v 1.2 2020/08/22 10:05:04 isaki Exp $	*/
+/*	$NetBSD: ashldi3.S,v 1.3 2020/08/22 10:12:29 isaki Exp $	*/
 
 /*
  * Copyright (C) 2020 Tetsuya Isaki. All rights reserved.
@@ -37,8 +37,8 @@ ASENTRY_NOPROFILE(__ashldi3)
 		| %a0 = shift count
 		jbra	start
 loop:
-		lsll	#1,%d1			| X:%d1 <<= 1
-		roxll	#1,%d0			| %d0:X <<= 1
+		addl	%d1,%d1			| X:%d1 <<= 1
+		addxl	%d0,%d0			| %d0:X <<= 1
 start:
 		subql	#1,%a0			| sub %a0 doesn't affect ccr,
 		tstl	%a0			|  but this extra TST op is



CVS commit: src/sys/arch/x68k/stand/xxboot

2020-08-22 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 22 10:05:04 UTC 2020

Modified Files:
src/sys/arch/x68k/stand/xxboot: ashldi3.S

Log Message:
typo in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/x68k/stand/xxboot/ashldi3.S

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

Modified files:

Index: src/sys/arch/x68k/stand/xxboot/ashldi3.S
diff -u src/sys/arch/x68k/stand/xxboot/ashldi3.S:1.1 src/sys/arch/x68k/stand/xxboot/ashldi3.S:1.2
--- src/sys/arch/x68k/stand/xxboot/ashldi3.S:1.1	Sun Aug 16 06:43:43 2020
+++ src/sys/arch/x68k/stand/xxboot/ashldi3.S	Sat Aug 22 10:05:04 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ashldi3.S,v 1.1 2020/08/16 06:43:43 isaki Exp $	*/
+/*	$NetBSD: ashldi3.S,v 1.2 2020/08/22 10:05:04 isaki Exp $	*/
 
 /*
  * Copyright (C) 2020 Tetsuya Isaki. All rights reserved.
@@ -37,8 +37,8 @@ ASENTRY_NOPROFILE(__ashldi3)
 		| %a0 = shift count
 		jbra	start
 loop:
-		lsll	#1,%d1			| X:%d1 =<< 1
-		roxll	#1,%d0			| %d0:X =<< 1
+		lsll	#1,%d1			| X:%d1 <<= 1
+		roxll	#1,%d0			| %d0:X <<= 1
 start:
 		subql	#1,%a0			| sub %a0 doesn't affect ccr,
 		tstl	%a0			|  but this extra TST op is



CVS commit: src/sys/arch/amiga/stand/bootblock/boot

2020-08-21 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 22 05:09:02 UTC 2020

Modified Files:
src/sys/arch/amiga/stand/bootblock/boot: ashldi3.s

Log Message:
Fix register order.  %d0 is higher and %d1 is lower.
This would have rarely affected.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/amiga/stand/bootblock/boot/ashldi3.s

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

Modified files:

Index: src/sys/arch/amiga/stand/bootblock/boot/ashldi3.s
diff -u src/sys/arch/amiga/stand/bootblock/boot/ashldi3.s:1.2 src/sys/arch/amiga/stand/bootblock/boot/ashldi3.s:1.3
--- src/sys/arch/amiga/stand/bootblock/boot/ashldi3.s:1.2	Mon Apr 28 20:23:13 2008
+++ src/sys/arch/amiga/stand/bootblock/boot/ashldi3.s	Sat Aug 22 05:09:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ashldi3.s,v 1.2 2008/04/28 20:23:13 martin Exp $ */
+/*	$NetBSD: ashldi3.s,v 1.3 2020/08/22 05:09:02 isaki Exp $ */
 
 /*-
  * Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -36,8 +36,8 @@ ENTRY_NOPROFILE(__ashldi3)
 	movml %sp@(8),%d0-%d2
 	jra L2
 L1:
-	asll #1,%d0
-	roxll #1,%d1
+	asll #1,%d1
+	roxll #1,%d0
 L2:
 	dbra %d2,L1
 



CVS commit: src/sys/arch/x68k/stand

2020-08-16 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Aug 16 07:25:51 UTC 2020

Modified Files:
src/sys/arch/x68k/stand: README

Log Message:
Update and fix.
All primary bootloaders can recognize Human68k partition table.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/x68k/stand/README

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

Modified files:

Index: src/sys/arch/x68k/stand/README
diff -u src/sys/arch/x68k/stand/README:1.2 src/sys/arch/x68k/stand/README:1.3
--- src/sys/arch/x68k/stand/README:1.2	Sun Aug 16 07:03:45 2020
+++ src/sys/arch/x68k/stand/README	Sun Aug 16 07:25:51 2020
@@ -1,13 +1,12 @@
-$NetBSD: README,v 1.2 2020/08/16 07:03:45 isaki Exp $
+$NetBSD: README,v 1.3 2020/08/16 07:25:51 isaki Exp $
 
 Primary bootloaders:
 	boot_ufs/
 		contains xxboot_ufs.
 		It is placed in ffs's boot area and loads secondary bootloader
 		from its filesystem (ffsv1/v2).
-		This historical primary bootloader uses custom ffs op functions
-		and can recognize Human68k partition table.
-		(See #ifdef SCSI_ADHOC_BOOTPART part for details)
+		This historical primary bootloader uses custom ffs op
+		functions.
 
 	xxboot/
 		contains following variants.
@@ -25,8 +24,7 @@ Primary bootloaders:
 			and loads secondary bootloader from its filesystem.
 
 		These primary bootloaders use MI ffs/lfs op functions in
-		src/sys/lib/libsa. Currently these don't recognize Human68k
-		partition table.
+		src/sys/lib/libsa.
 
 Secondary bootloaders:
 	boot/



CVS commit: src

2020-08-16 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Aug 16 07:03:45 UTC 2020

Modified Files:
src/distrib/sets/lists/base: md.x68k
src/distrib/x68k/floppies/bootfloppy.generic: Makefile
src/distrib/x68k/floppies/bootfloppy.sysinst: Makefile
src/sys/arch/x68k/stand: Makefile README
src/sys/arch/x68k/stand/xxboot: Makefile
Removed Files:
src/sys/arch/x68k/stand/boot_ustar: Makefile boot_ustar.S
boot_ustar.ldscript version

Log Message:
Replace boot_ustar with xxboot_ustarfs.
The old boot_ustar had many hard coding and was small(<1KB).
The new xxboot_ustarfs is a part of integrated larger(<8KB) xxboot.
We had to maintain three similar but not the same bootloaders, but
now we have two!


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/distrib/sets/lists/base/md.x68k
cvs rdiff -u -r1.9 -r1.10 \
src/distrib/x68k/floppies/bootfloppy.generic/Makefile
cvs rdiff -u -r1.13 -r1.14 \
src/distrib/x68k/floppies/bootfloppy.sysinst/Makefile
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/x68k/stand/Makefile
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/x68k/stand/README
cvs rdiff -u -r1.30 -r0 src/sys/arch/x68k/stand/boot_ustar/Makefile
cvs rdiff -u -r1.12 -r0 src/sys/arch/x68k/stand/boot_ustar/boot_ustar.S
cvs rdiff -u -r1.6 -r0 src/sys/arch/x68k/stand/boot_ustar/boot_ustar.ldscript
cvs rdiff -u -r1.3 -r0 src/sys/arch/x68k/stand/boot_ustar/version
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/x68k/stand/xxboot/Makefile

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

Modified files:

Index: src/distrib/sets/lists/base/md.x68k
diff -u src/distrib/sets/lists/base/md.x68k:1.46 src/distrib/sets/lists/base/md.x68k:1.47
--- src/distrib/sets/lists/base/md.x68k:1.46	Sun Aug 11 22:29:02 2013
+++ src/distrib/sets/lists/base/md.x68k	Sun Aug 16 07:03:45 2020
@@ -1,4 +1,4 @@
-# $NetBSD: md.x68k,v 1.46 2013/08/11 22:29:02 joerg Exp $
+# $NetBSD: md.x68k,v 1.47 2020/08/16 07:03:45 isaki Exp $
 ./dev/pow0	base-obsolete		obsolete
 ./dev/pow1	base-obsolete		obsolete
 ./usr/bin/bellctrlbase-util-bin
@@ -9,7 +9,7 @@
 ./usr/bin/tvctrlbase-util-bin
 ./usr/mdec/boot	base-sysutil-bin
 ./usr/mdec/fdboot_ufsbase-sysutil-bin
-./usr/mdec/fdboot_ustarbase-sysutil-bin
+./usr/mdec/fdboot_ustarbase-obsolete		obsolete
 ./usr/mdec/installbootbase-sysutil-bin
 ./usr/mdec/installboot.new			base-obsolete		obsolete
 ./usr/mdec/loadbsd.xbase-sysutil-bin
@@ -24,6 +24,7 @@
 ./usr/mdec/xxboot_lfsv1base-sysutil-bin
 ./usr/mdec/xxboot_lfsv2base-sysutil-bin
 ./usr/mdec/xxboot_ufsbase-sysutil-bin
+./usr/mdec/xxboot_ustarfs			base-sysutil-bin
 ./usr/sbin/memswitchbase-sysutil-bin
 ./usr/sbin/poffdbase-obsolete		obsolete
 ./usr/share/keymaps/x68k/ascii_kmap		base-sys-share

Index: src/distrib/x68k/floppies/bootfloppy.generic/Makefile
diff -u src/distrib/x68k/floppies/bootfloppy.generic/Makefile:1.9 src/distrib/x68k/floppies/bootfloppy.generic/Makefile:1.10
--- src/distrib/x68k/floppies/bootfloppy.generic/Makefile:1.9	Tue Aug  5 15:40:58 2014
+++ src/distrib/x68k/floppies/bootfloppy.generic/Makefile	Sun Aug 16 07:03:45 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.9 2014/08/05 15:40:58 apb Exp $
+#	$NetBSD: Makefile,v 1.10 2020/08/16 07:03:45 isaki Exp $
 
 .include 
 .include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib"
@@ -17,7 +17,7 @@ MDEC=		${DESTDIR}/usr/mdec
 FLOPPY_NETBSD=	netbsd.gz
 # XXXDISTRIB: use MI installboot
 FLOPPYINSTBOOT=\
-	"dd if=${MDEC}/fdboot_ustar of=@IMAGE@ bs=8k count=1 conv=sync,notrunc"
+	"dd if=${MDEC}/xxboot_ustarfs of=@IMAGE@ bs=8k count=1 conv=sync,notrunc"
 
 CLEANFILES+=	${BOOTNAME} netbsd.gz
 

Index: src/distrib/x68k/floppies/bootfloppy.sysinst/Makefile
diff -u src/distrib/x68k/floppies/bootfloppy.sysinst/Makefile:1.13 src/distrib/x68k/floppies/bootfloppy.sysinst/Makefile:1.14
--- src/distrib/x68k/floppies/bootfloppy.sysinst/Makefile:1.13	Sun Nov  4 13:12:10 2012
+++ src/distrib/x68k/floppies/bootfloppy.sysinst/Makefile	Sun Aug 16 07:03:45 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.13 2012/11/04 13:12:10 isaki Exp $
+#	$NetBSD: Makefile,v 1.14 2020/08/16 07:03:45 isaki Exp $
 
 .include 
 .include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib"
@@ -19,7 +19,7 @@ KERNOBJ!=	cd ${.CURDIR}/../instkernel &&
 FLOPPY_NETBSD=	${KERNOBJ}/netbsd-INSTALL.gz
 # XXXDISTRIB: use MI installboot
 FLOPPYINSTBOOT=\
-	"dd if=${MDEC}/fdboot_ustar of=@IMAGE@ bs=8k count=1 conv=sync,notrunc"
+	"dd if=${MDEC}/xxboot_ustarfs of=@IMAGE@ bs=8k count=1 conv=sync,notrunc"
 
 CLEANFILES+=	${BOOTNAME}
 

Index: src/sys/arch/x68k/stand/Makefile
diff -u src/sys/arch/x68k/stand/Makefile:1.14 src/sys/arch/x68k/stand/Makefile:1.15
--- src/sys/arch/x68k/stand/Makefile:1.14	Fri Aug 14 03:29:23 2020
+++ src/sys/arch/x68k/stand/Makefile	Sun Aug 16 07:03:45 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.14 2020/08/14 03:29:23 isaki Exp $
+#	$NetBSD: Makefile,v 1.15 

CVS commit: src/sys/arch/x68k/stand

2020-08-16 Thread Tetsuya Isaki
		   ID & 7, 0, 0);
-#elif defined(FDBOOT) || defined(SDBOOT)
 	if (BINF_ISFD(_INFO)) {
 		/* floppy */
+		int minor;
+		/* fdNa for 1024 bytes/sector, fdNc for 512 bytes/sector */
+		minor = (FDSEC.minsec.N == 3) ? 0 : 2;
+		bootdev = X68K_MAKEBOOTDEV(X68K_MAJOR_FD, BOOT_INFO & 3, minor);
 #ifdef XXBOOT_DEBUG
 		*(uint32_t *)bootdevstr =
 		('f' << 24) | ('d' << 16) | ('@' << 8) |
 		('0' + (BOOT_INFO & 3));
-		bootdevstr[4] = '\0';
+		bootdevstr[4] = 'a' + minor;
+		bootdevstr[5] = '\0';
 #endif
-		/* fdNa for 1024 bytes/sector, fdNc for 512 bytes/sector */
-		bootdev = X68K_MAKEBOOTDEV(X68K_MAJOR_FD, BOOT_INFO & 3,
-		(FDSECMINMAX.minsec.N == 3) ? 0 : 2);
 	} else {
 		/* SCSI */
-		bootdev = X68K_MAKESCSIBOOTDEV(X68K_MAJOR_SD, ha >> 4, ha & 15,
-		ID & 7, 0, 0 /* XXX: assume partition a */);
-	}
+		int major, ha, part;
+		ha = get_scsi_host_adapter(bootdevstr);
+		part = 0;
+#if defined(CDBOOT)
+		major = X68K_MAJOR_CD;
 #else
-	bootdev = 0;
+		major = X68K_MAJOR_SD;
+		if (SCSI_PARTTOP != 0)
+			part = get_scsi_part();
+#endif
+		bootdev = X68K_MAKESCSIBOOTDEV(major, ha >> 4, ha & 15,
+		SCSI_ID & 7, 0, part);
+#ifdef XXBOOT_DEBUG
+		bootdevstr[10] = '0' + (SCSI_ID & 7);
+		bootdevstr[14] = 'a' + part;
 #endif
+	}
 
 #ifdef XXBOOT_DEBUG
 	IOCS_B_PRINT("boot device: ");
@@ -143,9 +227,17 @@ bootmain(void)
 	IOCS_B_PRINT("\r\n");
 
 	marks[MARK_START] = BOOT_TEXTADDR;
+
+#if defined(XXBOOT_USTARFS)
+	/* ustarfs requires mangled filename... */
+	fd = loadfile("USTAR.volsize.4540", marks,
+	LOAD_TEXT|LOAD_DATA|LOAD_BSS);
+#else
+	/* XXX what is x68k/boot? */
 	fd = loadfile("x68k/boot", marks, LOAD_TEXT|LOAD_DATA|LOAD_BSS);
 	if (fd < 0)
 		fd = loadfile("boot", marks, LOAD_TEXT|LOAD_DATA|LOAD_BSS);
+#endif
 	if (fd >= 0) {
 		close(fd);
 		exec_image(BOOT_TEXTADDR, /* image loaded at */

Index: src/sys/arch/x68k/stand/xxboot/consio1.c
diff -u src/sys/arch/x68k/stand/xxboot/consio1.c:1.1 src/sys/arch/x68k/stand/xxboot/consio1.c:1.2
--- src/sys/arch/x68k/stand/xxboot/consio1.c:1.1	Tue Mar 20 13:01:32 2012
+++ src/sys/arch/x68k/stand/xxboot/consio1.c	Sun Aug 16 06:43:43 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: consio1.c,v 1.1 2012/03/20 13:01:32 minoura Exp $	*/
+/*	$NetBSD: consio1.c,v 1.2 2020/08/16 06:43:43 isaki Exp $	*/
 
 /*
  * Copyright (c) 2001,2010 MINOURA Makoto.
@@ -29,10 +29,8 @@
 #include 
 #include 
 
-#include "libx68k.h"
-
+#include "xxboot.h"
 #include "iocs.h"
-#include "consio.h"
 
 int
 getchar(void)

Index: src/sys/arch/x68k/stand/xxboot/version
diff -u src/sys/arch/x68k/stand/xxboot/version:1.3 src/sys/arch/x68k/stand/xxboot/version:1.4
--- src/sys/arch/x68k/stand/xxboot/version:1.3	Sat Jan 18 05:07:34 2020
+++ src/sys/arch/x68k/stand/xxboot/version	Sun Aug 16 06:43:43 2020
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.3 2020/01/18 05:07:34 isaki Exp $
+$NetBSD: version,v 1.4 2020/08/16 06:43:43 isaki Exp $
 
 NOTE ANY CHANGES YOU MAKE TO THE BOOTBLOCKS HERE.  The format of this
 file is important - make sure the entries are appended on end, last item
@@ -7,3 +7,4 @@ is taken as the current.
 1.0:	Initial revision.
 1.1:	Fix FFS and LFS boot from SCSI HD and floppies.  Always print version.
 1.2:	Initialize the screen.
+2.0:	Rewrite mostly.  Support xxboot_ustarfs.
Index: src/sys/arch/x68k/stand/xxboot/xx.c
diff -u src/sys/arch/x68k/stand/xxboot/xx.c:1.3 src/sys/arch/x68k/stand/xxboot/xx.c:1.4
--- src/sys/arch/x68k/stand/xxboot/xx.c:1.3	Fri Aug 14 03:34:22 2020
+++ src/sys/arch/x68k/stand/xxboot/xx.c	Sun Aug 16 06:43:43 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xx.c,v 1.3 2020/08/14 03:34:22 isaki Exp $	*/
+/*	$NetBSD: xx.c,v 1.4 2020/08/16 06:43:43 isaki Exp $	*/
 
 /*
  * Copyright (c) 2010 MINOURA Makoto.
@@ -29,6 +29,7 @@
 #include 
 
 #include "xxboot.h"
+#include "iocs.h"
 
 int
 xxopen(struct open_file *f, ...)
@@ -49,7 +50,24 @@ xxstrategy(void *arg, int rw, daddr_t db
void *buf, size_t *rsize)
 {
 
-	RAW_READ(buf, (uint32_t)dblk, size);
+	/*
+	 * dblk is (always?) in 512 bytes unit, even if CD (2048 byte/sect).
+	 * size is in byte.
+	 *
+	 * On SCSI HD, the position specified in raw_read() (1st argument)
+	 * counts from the beginning of the disk, not the beginning of the
+	 * partition.  On SCSI CD and floppy, SCSI_PARTTOP is zero.
+	 */
+#if defined(XXBOOT_DEBUG)
+	IOCS_B_PRINT("xxstrategy ");
+	print_hex(dblk, 8);
+	IOCS_B_PRINT(" len=");
+	print_hex(size, 8);
+	IOCS_B_PRINT("\r\n");
+#endif
+	if (size != 0) {
+		raw_read((uint32_t)(SCSI_PARTTOP + dblk), (uint32_t)size, buf);
+	}
 	if (rsize)
 		*rsize = size;
 	return 0;
Index: src/sys/arch/x68k/stand/xxboot/xxboot.h
diff -u src/sys/arch/x68k/stand/xxboot/xxboot.h:1.3 src/sys/arch/x68k/stand/xxboot/xxboot.h:1.4
--- src/sys/arch/x68k/stand/xxboot/xxboot.h:1.3	Fri Aug 14 03:34:22 2020
+++ src/sys/arch/x

CVS commit: src/sys/arch/x68k/stand/xxboot

2020-08-13 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Fri Aug 14 03:54:46 UTC 2020

Modified Files:
src/sys/arch/x68k/stand/xxboot: Makefile.xxboot xxboot.ldscript

Log Message:
Reduce binary size as possible.  These reduce filesize about 20 words.
- Use word alignment (rather than longword alignment) for text/data section.
- Use short reference.  In the bootloader, all symbols can be expressed in
  short.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/x68k/stand/xxboot/Makefile.xxboot
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/x68k/stand/xxboot/xxboot.ldscript

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

Modified files:

Index: src/sys/arch/x68k/stand/xxboot/Makefile.xxboot
diff -u src/sys/arch/x68k/stand/xxboot/Makefile.xxboot:1.16 src/sys/arch/x68k/stand/xxboot/Makefile.xxboot:1.17
--- src/sys/arch/x68k/stand/xxboot/Makefile.xxboot:1.16	Fri Aug 14 03:40:47 2020
+++ src/sys/arch/x68k/stand/xxboot/Makefile.xxboot	Fri Aug 14 03:54:46 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.xxboot,v 1.16 2020/08/14 03:40:47 isaki Exp $
+#	$NetBSD: Makefile.xxboot,v 1.17 2020/08/14 03:54:46 isaki Exp $
 
 NOMAN=		# defined
 
@@ -40,6 +40,7 @@ CPPFLAGS+= -DHEAP_START=0x0010
 CPPFLAGS+= -nostdinc -I${.OBJDIR} -I${S}
 CPPFLAGS+= -I$M/stand/libiocs -I$M/stand/libsa -I$M/stand/common
 AFLAGS=	   ${CFLAGS:M-[ID]*}
+AFLAGS+=   -Wa,-l
 LINKFLAGS=   -n -Bstatic -T ${.CURDIR}/../xxboot.ldscript
 LINKFLAGS+=  --defsym=TEXTADDR=$(TEXT)
 LINKFLAGS+=  --defsym=BOOT_TEXTADDR=$(BOOT_TEXT)

Index: src/sys/arch/x68k/stand/xxboot/xxboot.ldscript
diff -u src/sys/arch/x68k/stand/xxboot/xxboot.ldscript:1.8 src/sys/arch/x68k/stand/xxboot/xxboot.ldscript:1.9
--- src/sys/arch/x68k/stand/xxboot/xxboot.ldscript:1.8	Fri Aug 14 03:25:39 2020
+++ src/sys/arch/x68k/stand/xxboot/xxboot.ldscript	Fri Aug 14 03:54:46 2020
@@ -8,6 +8,8 @@ SECTIONS
 {
   . = TEXTADDR;
   .text :
+  ALIGN(2)
+  SUBALIGN(2)
   {
 CREATE_OBJECT_SYMBOLS
 *(.text)
@@ -24,6 +26,8 @@ SECTIONS
 _etext = .;
   }
   .data :
+  ALIGN(2)
+  SUBALIGN(2)
   {
 /* The first three sections are for SunOS dynamic linking.  */
 *(.dynamic)



CVS commit: src/sys/arch/x68k/stand/xxboot

2020-08-13 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Fri Aug 14 03:43:28 UTC 2020

Modified Files:
src/sys/arch/x68k/stand/xxboot: bootmain.c

Log Message:
Use DEV_OPEN() macro.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/x68k/stand/xxboot/bootmain.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/arch/x68k/stand/xxboot/bootmain.c
diff -u src/sys/arch/x68k/stand/xxboot/bootmain.c:1.6 src/sys/arch/x68k/stand/xxboot/bootmain.c:1.7
--- src/sys/arch/x68k/stand/xxboot/bootmain.c:1.6	Fri Aug 14 03:34:22 2020
+++ src/sys/arch/x68k/stand/xxboot/bootmain.c	Fri Aug 14 03:43:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: bootmain.c,v 1.6 2020/08/14 03:34:22 isaki Exp $	*/
+/*	$NetBSD: bootmain.c,v 1.7 2020/08/14 03:43:28 isaki Exp $	*/
 
 /*-
  * Copyright (c) 1993, 1994 Takumi Nakamura.
@@ -163,5 +163,5 @@ devopen(struct open_file *f, const char 
 {
 
 	*file = __UNCONST(fname);
-	return xxopen(f);
+	return DEV_OPEN()(f);
 }



CVS commit: src/sys/arch/x68k/stand/xxboot

2020-08-13 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Fri Aug 14 03:40:48 UTC 2020

Modified Files:
src/sys/arch/x68k/stand/xxboot: Makefile.xxboot
src/sys/arch/x68k/stand/xxboot/cdboot_cd9660: Makefile
src/sys/arch/x68k/stand/xxboot/xxboot_ffsv1: Makefile
src/sys/arch/x68k/stand/xxboot/xxboot_ffsv2: Makefile
src/sys/arch/x68k/stand/xxboot/xxboot_lfsv1: Makefile
src/sys/arch/x68k/stand/xxboot/xxboot_lfsv2: Makefile

Log Message:
Use fixed 'xx' instead of DEV and DEVDRV for simplicity.
There is no choice other than xx for now.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/x68k/stand/xxboot/Makefile.xxboot
cvs rdiff -u -r1.2 -r1.3 \
src/sys/arch/x68k/stand/xxboot/cdboot_cd9660/Makefile
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/x68k/stand/xxboot/xxboot_ffsv1/Makefile
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/x68k/stand/xxboot/xxboot_ffsv2/Makefile
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/x68k/stand/xxboot/xxboot_lfsv1/Makefile
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/x68k/stand/xxboot/xxboot_lfsv2/Makefile

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

Modified files:

Index: src/sys/arch/x68k/stand/xxboot/Makefile.xxboot
diff -u src/sys/arch/x68k/stand/xxboot/Makefile.xxboot:1.15 src/sys/arch/x68k/stand/xxboot/Makefile.xxboot:1.16
--- src/sys/arch/x68k/stand/xxboot/Makefile.xxboot:1.15	Fri Aug 14 03:29:23 2020
+++ src/sys/arch/x68k/stand/xxboot/Makefile.xxboot	Fri Aug 14 03:40:47 2020
@@ -1,10 +1,10 @@
-#	$NetBSD: Makefile.xxboot,v 1.15 2020/08/14 03:29:23 isaki Exp $
+#	$NetBSD: Makefile.xxboot,v 1.16 2020/08/14 03:40:47 isaki Exp $
 
 NOMAN=		# defined
 
 .include 
 
-BOOT=	$(DEV)boot_$(FS)
+BOOT=	xxboot_$(FS)
 VERSIONFILE=	${.CURDIR}/../version
 VERSION!=	${TOOL_AWK} -F: '$$1 ~ /^[0-9.]*$$/ { it = $$1; } \
 			END { print it }' ${VERSIONFILE}
@@ -25,7 +25,7 @@ BINMODE=	444
 S=		${.CURDIR}/../../../../..
 M=		$S/arch/x68k
 .PATH:		${.CURDIR}/..
-SRCS=	boot.S bootmain.c conf.c consio1.c $(DEVDRV).c
+SRCS=	boot.S bootmain.c conf.c consio1.c xx.c
 
 .include "${S}/conf/newvers_stand.mk"
 
@@ -51,7 +51,7 @@ LDLIBS+=  -L${LIBIOCS} -liocs
 
 .PATH: $S/lib/libsa
 CPPFLAGS+= -DLIBSA_SINGLE_FILESYSTEM=$(FS)
-CPPFLAGS+= -DLIBSA_SINGLE_DEVICE=$(DEV)
+CPPFLAGS+= -DLIBSA_SINGLE_DEVICE=xx
 CPPFLAGS+= -DLIBSA_NO_FD_CHECKING
 CPPFLAGS+= -DLIBSA_NO_FS_WRITE
 CPPFLAGS+= -DLIBSA_NO_RAW_ACCESS

Index: src/sys/arch/x68k/stand/xxboot/cdboot_cd9660/Makefile
diff -u src/sys/arch/x68k/stand/xxboot/cdboot_cd9660/Makefile:1.2 src/sys/arch/x68k/stand/xxboot/cdboot_cd9660/Makefile:1.3
--- src/sys/arch/x68k/stand/xxboot/cdboot_cd9660/Makefile:1.2	Sat Nov 17 19:10:46 2012
+++ src/sys/arch/x68k/stand/xxboot/cdboot_cd9660/Makefile	Fri Aug 14 03:40:47 2020
@@ -1,7 +1,5 @@
-#	$NetBSD: Makefile,v 1.2 2012/11/17 19:10:46 tsutsui Exp $
+#	$NetBSD: Makefile,v 1.3 2020/08/14 03:40:47 isaki Exp $
 
-DEV=		xx
-DEVDRV=		xx
 FS=		cd9660
 BOOTCPPFLAGS=	-DCDBOOT
 

Index: src/sys/arch/x68k/stand/xxboot/xxboot_ffsv1/Makefile
diff -u src/sys/arch/x68k/stand/xxboot/xxboot_ffsv1/Makefile:1.4 src/sys/arch/x68k/stand/xxboot/xxboot_ffsv1/Makefile:1.5
--- src/sys/arch/x68k/stand/xxboot/xxboot_ffsv1/Makefile:1.4	Sat Nov 17 19:10:47 2012
+++ src/sys/arch/x68k/stand/xxboot/xxboot_ffsv1/Makefile	Fri Aug 14 03:40:47 2020
@@ -1,7 +1,5 @@
-#	$NetBSD: Makefile,v 1.4 2012/11/17 19:10:47 tsutsui Exp $
+#	$NetBSD: Makefile,v 1.5 2020/08/14 03:40:47 isaki Exp $
 
-DEV=		xx
-DEVDRV=		xx
 FS=		ffsv1
 BOOTCPPFLAGS=	-DSDBOOT -DFDBOOT
 

Index: src/sys/arch/x68k/stand/xxboot/xxboot_ffsv2/Makefile
diff -u src/sys/arch/x68k/stand/xxboot/xxboot_ffsv2/Makefile:1.4 src/sys/arch/x68k/stand/xxboot/xxboot_ffsv2/Makefile:1.5
--- src/sys/arch/x68k/stand/xxboot/xxboot_ffsv2/Makefile:1.4	Sat Nov 17 19:10:47 2012
+++ src/sys/arch/x68k/stand/xxboot/xxboot_ffsv2/Makefile	Fri Aug 14 03:40:47 2020
@@ -1,7 +1,5 @@
-#	$NetBSD: Makefile,v 1.4 2012/11/17 19:10:47 tsutsui Exp $
+#	$NetBSD: Makefile,v 1.5 2020/08/14 03:40:47 isaki Exp $
 
-DEV=		xx
-DEVDRV=		xx
 FS=		ffsv2
 BOOTCPPFLAGS=	-DSDBOOT -DFDBOOT
 

Index: src/sys/arch/x68k/stand/xxboot/xxboot_lfsv1/Makefile
diff -u src/sys/arch/x68k/stand/xxboot/xxboot_lfsv1/Makefile:1.4 src/sys/arch/x68k/stand/xxboot/xxboot_lfsv1/Makefile:1.5
--- src/sys/arch/x68k/stand/xxboot/xxboot_lfsv1/Makefile:1.4	Sat Nov 17 19:10:47 2012
+++ src/sys/arch/x68k/stand/xxboot/xxboot_lfsv1/Makefile	Fri Aug 14 03:40:47 2020
@@ -1,7 +1,5 @@
-#	$NetBSD: Makefile,v 1.4 2012/11/17 19:10:47 tsutsui Exp $
+#	$NetBSD: Makefile,v 1.5 2020/08/14 03:40:47 isaki Exp $
 
-DEV=		xx
-DEVDRV=		xx
 FS=		lfsv1
 BOOTCPPFLAGS=	-DSDBOOT -DFDBOOT
 

Index: src/sys/arch/x68k/stand/xxboot/xxboot_lfsv2/Makefile
diff -u src/sys/arch/x68k/stand/xxboot/xxboot_lfsv2/Makefile:1.4 src/sys/arch/x68k/stand/xxboot/xxboot_lfsv2/Makefile:1.5
--- src/sys/arch/x68k/stand/xxboot/xxboot_lfsv2/Makefile:1.4	Sat Nov 17 19:10:47 2012
+++ 

CVS commit: src/sys/arch/x68k/stand/xxboot

2020-08-13 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Fri Aug 14 03:34:22 UTC 2020

Modified Files:
src/sys/arch/x68k/stand/xxboot: bootmain.c xx.c
Added Files:
src/sys/arch/x68k/stand/xxboot: xxboot.h

Log Message:
Add xxboot.h common header to share prototype definitions.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/x68k/stand/xxboot/bootmain.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/x68k/stand/xxboot/xx.c
cvs rdiff -u -r0 -r1.3 src/sys/arch/x68k/stand/xxboot/xxboot.h

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

Modified files:

Index: src/sys/arch/x68k/stand/xxboot/bootmain.c
diff -u src/sys/arch/x68k/stand/xxboot/bootmain.c:1.5 src/sys/arch/x68k/stand/xxboot/bootmain.c:1.6
--- src/sys/arch/x68k/stand/xxboot/bootmain.c:1.5	Fri Aug 14 02:51:48 2020
+++ src/sys/arch/x68k/stand/xxboot/bootmain.c	Fri Aug 14 03:34:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: bootmain.c,v 1.5 2020/08/14 02:51:48 isaki Exp $	*/
+/*	$NetBSD: bootmain.c,v 1.6 2020/08/14 03:34:22 isaki Exp $	*/
 
 /*-
  * Copyright (c) 1993, 1994 Takumi Nakamura.
@@ -39,25 +39,12 @@
 #include 
 #include 
 
+#include "xxboot.h"
 #include "libx68k.h"
 #include "iocs.h"
 #include "exec_image.h"
 
 #define EXSCSI_BDID	((void *)0x00ea0001)
-#define BINF_ISFD(pbinf)	(*((uint8_t *)(pbinf) + 1) == 0)
-
-/* boot.S */
-extern int badbaddr(volatile void *);
-extern unsigned int ID;		/* target SCSI ID */
-extern unsigned int BOOT_INFO;	/* result of IOCS(__BOOTINF) */
-extern struct {
-	struct fdfmt{
-		uint8_t	N;	/* sector length 0: 128, ..., 3: 1K */
-		uint8_t	C;	/* cylinder # */
-		uint8_t	H;	/* head # */
-		uint8_t	R;	/* sector # */
-	} minsec, maxsec;
-} FDSECMINMAX;			/* FD format type of the first track */
 
 /* for debug */
 unsigned int startregs[16];
@@ -107,8 +94,6 @@ get_scsi_host_adapter(char *devstr)
 	return ha;
 }
 
-extern const char bootprog_name[], bootprog_rev[];
-
 void
 bootmain(void)
 {

Index: src/sys/arch/x68k/stand/xxboot/xx.c
diff -u src/sys/arch/x68k/stand/xxboot/xx.c:1.2 src/sys/arch/x68k/stand/xxboot/xx.c:1.3
--- src/sys/arch/x68k/stand/xxboot/xx.c:1.2	Sat Nov 17 16:02:00 2012
+++ src/sys/arch/x68k/stand/xxboot/xx.c	Fri Aug 14 03:34:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xx.c,v 1.2 2012/11/17 16:02:00 tsutsui Exp $	*/
+/*	$NetBSD: xx.c,v 1.3 2020/08/14 03:34:22 isaki Exp $	*/
 
 /*
  * Copyright (c) 2010 MINOURA Makoto.
@@ -28,7 +28,7 @@
 #include 
 #include 
 
-extern void RAW_READ(void *buf, uint32_t blkpos, size_t bytelen);
+#include "xxboot.h"
 
 int
 xxopen(struct open_file *f, ...)

Added files:

Index: src/sys/arch/x68k/stand/xxboot/xxboot.h
diff -u /dev/null src/sys/arch/x68k/stand/xxboot/xxboot.h:1.3
--- /dev/null	Fri Aug 14 03:34:22 2020
+++ src/sys/arch/x68k/stand/xxboot/xxboot.h	Fri Aug 14 03:34:22 2020
@@ -0,0 +1,51 @@
+/*	$NetBSD: xxboot.h,v 1.3 2020/08/14 03:34:22 isaki Exp $	*/
+
+/*
+ * Copyright (C) 2020 Tetsuya Isaki. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#define BINF_ISFD(pbinf)	(*((uint8_t *)(pbinf) + 1) == 0)
+
+/* boot.S */
+extern void RAW_READ(void *, uint32_t, size_t);
+extern int badbaddr(volatile void *);
+extern unsigned int BOOT_INFO;	/* result of IOCS(__BOOTINF) */
+extern unsigned int ID;		/* target SCSI ID */
+extern struct {
+	struct fdfmt{
+		uint8_t	N;	/* sector length 0: 128, ..., 3: 1K */
+		uint8_t	C;	/* cylinder # */
+		uint8_t	H;	/* head # */
+		uint8_t	R;	/* sector # */
+	} minsec, maxsec;
+} FDSECMINMAX;			/* FD format type of the first track */
+
+/* xx.c */
+extern int xxopen(struct open_file *, ...);
+extern int xxclose(struct open_file *);
+extern int xxstrategy(void *, int, daddr_t, 

CVS commit: src/sys/arch/x68k/stand

2020-08-13 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Fri Aug 14 03:29:23 UTC 2020

Modified Files:
src/sys/arch/x68k/stand: Makefile
src/sys/arch/x68k/stand/xxboot: Makefile Makefile.xxboot

Log Message:
Style fixes.  One entry per line for some parts.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/x68k/stand/Makefile
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/x68k/stand/xxboot/Makefile
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/x68k/stand/xxboot/Makefile.xxboot

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

Modified files:

Index: src/sys/arch/x68k/stand/Makefile
diff -u src/sys/arch/x68k/stand/Makefile:1.13 src/sys/arch/x68k/stand/Makefile:1.14
--- src/sys/arch/x68k/stand/Makefile:1.13	Fri Oct 12 20:15:52 2012
+++ src/sys/arch/x68k/stand/Makefile	Fri Aug 14 03:29:23 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.13 2012/10/12 20:15:52 tsutsui Exp $
+#	$NetBSD: Makefile,v 1.14 2020/08/14 03:29:23 isaki Exp $
 
 # host tools
 SUBDIR= newdisk installboot
@@ -8,7 +8,9 @@ SUBDIR+= libdos libiocs libsa .WAIT
 
 # standalone bootloaders
 SUBDIR+= mboot
-SUBDIR+= boot_ufs boot_ustar xxboot
+SUBDIR+= boot_ufs
+SUBDIR+= boot_ustar
+SUBDIR+= xxboot
 SUBDIR+= boot netboot
 
 # Human68k utility

Index: src/sys/arch/x68k/stand/xxboot/Makefile
diff -u src/sys/arch/x68k/stand/xxboot/Makefile:1.15 src/sys/arch/x68k/stand/xxboot/Makefile:1.16
--- src/sys/arch/x68k/stand/xxboot/Makefile:1.15	Tue Mar 20 13:01:32 2012
+++ src/sys/arch/x68k/stand/xxboot/Makefile	Fri Aug 14 03:29:23 2020
@@ -1,5 +1,9 @@
-#	$NetBSD: Makefile,v 1.15 2012/03/20 13:01:32 minoura Exp $
+#	$NetBSD: Makefile,v 1.16 2020/08/14 03:29:23 isaki Exp $
 
-SUBDIR=	cdboot_cd9660 xxboot_ffsv1 xxboot_ffsv2 xxboot_lfsv1 xxboot_lfsv2
+SUBDIR+=	cdboot_cd9660
+SUBDIR+=	xxboot_ffsv1
+SUBDIR+=	xxboot_ffsv2
+SUBDIR+=	xxboot_lfsv1
+SUBDIR+=	xxboot_lfsv2
 
 .include 

Index: src/sys/arch/x68k/stand/xxboot/Makefile.xxboot
diff -u src/sys/arch/x68k/stand/xxboot/Makefile.xxboot:1.14 src/sys/arch/x68k/stand/xxboot/Makefile.xxboot:1.15
--- src/sys/arch/x68k/stand/xxboot/Makefile.xxboot:1.14	Fri Aug 14 03:25:39 2020
+++ src/sys/arch/x68k/stand/xxboot/Makefile.xxboot	Fri Aug 14 03:29:23 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.xxboot,v 1.14 2020/08/14 03:25:39 isaki Exp $
+#	$NetBSD: Makefile.xxboot,v 1.15 2020/08/14 03:29:23 isaki Exp $
 
 NOMAN=		# defined
 
@@ -52,7 +52,10 @@ LDLIBS+=  -L${LIBIOCS} -liocs
 .PATH: $S/lib/libsa
 CPPFLAGS+= -DLIBSA_SINGLE_FILESYSTEM=$(FS)
 CPPFLAGS+= -DLIBSA_SINGLE_DEVICE=$(DEV)
-CPPFLAGS+= -DLIBSA_NO_TWIDDLE -DLIBSA_NO_FD_CHECKING -DLIBSA_NO_RAW_ACCESS -DLIBSA_NO_FS_WRITE
+CPPFLAGS+= -DLIBSA_NO_FD_CHECKING
+CPPFLAGS+= -DLIBSA_NO_FS_WRITE
+CPPFLAGS+= -DLIBSA_NO_RAW_ACCESS
+CPPFLAGS+= -DLIBSA_NO_TWIDDLE
 SRCS+=	open.c close.c read.c lseek.c loadfile.c loadfile_aout.c alloc.c
 SRCS+=  $(FS).c
 



CVS commit: src/sys/arch/x68k/stand/xxboot

2020-08-13 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Fri Aug 14 03:25:39 UTC 2020

Modified Files:
src/sys/arch/x68k/stand/xxboot: Makefile.xxboot xxboot.ldscript

Log Message:
- Restore display of first_kbyte.  This is helpful for development.
- Check the filesize of resulting file instead of section sizes.
  If there is a gap between sections, the filesize may be exceeded even
  though the section total is not exceeded.  Of course that doesn't
  usually happen but I've experienced this during development.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/x68k/stand/xxboot/Makefile.xxboot
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/x68k/stand/xxboot/xxboot.ldscript

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

Modified files:

Index: src/sys/arch/x68k/stand/xxboot/Makefile.xxboot
diff -u src/sys/arch/x68k/stand/xxboot/Makefile.xxboot:1.13 src/sys/arch/x68k/stand/xxboot/Makefile.xxboot:1.14
--- src/sys/arch/x68k/stand/xxboot/Makefile.xxboot:1.13	Mon Aug 10 07:00:49 2020
+++ src/sys/arch/x68k/stand/xxboot/Makefile.xxboot	Fri Aug 14 03:25:39 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.xxboot,v 1.13 2020/08/10 07:00:49 rin Exp $
+#	$NetBSD: Makefile.xxboot,v 1.14 2020/08/14 03:25:39 isaki Exp $
 
 NOMAN=		# defined
 
@@ -61,10 +61,19 @@ SRCS+=	exec_image.S
 
 .include "${.CURDIR}/../../Makefile.booters"
 
+CLEANFILES+=	${PROG}.map
+
 
 ${PROG}: $(OBJS)
 	${_MKTARGET_LINK}
-	$(LD) $(LINKFLAGS) -o ${PROG} $(OBJS) $(LDLIBS)
+	$(LD) $(LINKFLAGS) -Map=${PROG}.map -o ${PROG} $(OBJS) $(LDLIBS)
+	: Print some addresses for convenience
+	@${TOOL_AWK} '/first_kbyte$$/ { print "\t\t" $$2 "\t" $$1 }' ${PROG}.map
+	@echo "		filesize	"`${TOOL_STAT} -f %z ${PROG}`
+	@if [ `${TOOL_STAT} -f %z ${PROG}` -gt 8192 ]; then \
+	echo "${PROG} filesize exceeds 8192 bytes"; \
+		exit 1; \
+	fi
 	${TOUCHPROG}
 
 .include 

Index: src/sys/arch/x68k/stand/xxboot/xxboot.ldscript
diff -u src/sys/arch/x68k/stand/xxboot/xxboot.ldscript:1.7 src/sys/arch/x68k/stand/xxboot/xxboot.ldscript:1.8
--- src/sys/arch/x68k/stand/xxboot/xxboot.ldscript:1.7	Tue Jan 28 11:57:22 2020
+++ src/sys/arch/x68k/stand/xxboot/xxboot.ldscript	Fri Aug 14 03:25:39 2020
@@ -48,6 +48,4 @@ SECTIONS
 }
 
 ASSERT(first_kbyte - TEXTADDR <= 1024, "Error: first_kbyte exceeds 1KB");
-ASSERT(_edata - TEXTADDR <= TEXTDATASIZE,
-"Error: text+data is too large to bootarea");
 ASSERT(_end <= BOOT_TEXTADDR, "Error: _end conflicts BOOT_TEXT");



CVS commit: src/sys/arch/x68k/stand/xxboot

2020-08-13 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Fri Aug 14 02:51:48 UTC 2020

Modified Files:
src/sys/arch/x68k/stand/xxboot: bootmain.c

Log Message:
Make compilable even with XXBOOT_DEBUG.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/x68k/stand/xxboot/bootmain.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/arch/x68k/stand/xxboot/bootmain.c
diff -u src/sys/arch/x68k/stand/xxboot/bootmain.c:1.4 src/sys/arch/x68k/stand/xxboot/bootmain.c:1.5
--- src/sys/arch/x68k/stand/xxboot/bootmain.c:1.4	Sat Nov 17 19:10:46 2012
+++ src/sys/arch/x68k/stand/xxboot/bootmain.c	Fri Aug 14 02:51:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: bootmain.c,v 1.4 2012/11/17 19:10:46 tsutsui Exp $	*/
+/*	$NetBSD: bootmain.c,v 1.5 2020/08/14 02:51:48 isaki Exp $	*/
 
 /*-
  * Copyright (c) 1993, 1994 Takumi Nakamura.
@@ -135,7 +135,8 @@ bootmain(void)
 		/* floppy */
 #ifdef XXBOOT_DEBUG
 		*(uint32_t *)bootdevstr =
-		('f' << 24 | 'd' << 16 | '@' << 8 | '0' + (BOOT_INFO & 3));
+		('f' << 24) | ('d' << 16) | ('@' << 8) |
+		('0' + (BOOT_INFO & 3));
 		bootdevstr[4] = '\0';
 #endif
 		/* fdNa for 1024 bytes/sector, fdNc for 512 bytes/sector */



CVS commit: src/sys/dev/pci

2020-07-03 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Fri Jul  3 12:39:54 UTC 2020

Modified Files:
src/sys/dev/pci: auixp.c

Log Message:
Fix an argument passes to auixp_intr().
This is rest of rev 1.39 (split device_t/softc) in 2012.
Problem reported and tested by Riccardo Mottola.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/dev/pci/auixp.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/pci/auixp.c
diff -u src/sys/dev/pci/auixp.c:1.49 src/sys/dev/pci/auixp.c:1.50
--- src/sys/dev/pci/auixp.c:1.49	Sat Feb 29 06:34:30 2020
+++ src/sys/dev/pci/auixp.c	Fri Jul  3 12:39:54 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: auixp.c,v 1.49 2020/02/29 06:34:30 isaki Exp $ */
+/* $NetBSD: auixp.c,v 1.50 2020/07/03 12:39:54 isaki Exp $ */
 
 /*
  * Copyright (c) 2004, 2005 Reinoud Zandijk 
@@ -43,7 +43,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: auixp.c,v 1.49 2020/02/29 06:34:30 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: auixp.c,v 1.50 2020/07/03 12:39:54 isaki Exp $");
 
 #include 
 #include 
@@ -1116,7 +1116,7 @@ auixp_attach(device_t parent, device_t s
 
 	/* establish interrupt routine hookup at IPL_AUDIO level */
 	sc->sc_ih = pci_intr_establish_xname(pc, ih, IPL_AUDIO, auixp_intr,
-	self, device_xname(self));
+	sc, device_xname(self));
 	if (sc->sc_ih == NULL) {
 		aprint_error_dev(sc->sc_dev, "can't establish interrupt");
 		if (intrstr != NULL)



CVS commit: src/sys/dev/audio

2020-05-28 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Fri May 29 03:09:14 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c audiovar.h

Log Message:
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.74 -r1.75 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.11 -r1.12 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.74 src/sys/dev/audio/audio.c:1.75
--- src/sys/dev/audio/audio.c:1.74	Tue May 26 15:20:16 2020
+++ src/sys/dev/audio/audio.c	Fri May 29 03:09:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.74 2020/05/26 15:20:16 nia Exp $	*/
+/*	$NetBSD: audio.c,v 1.75 2020/05/29 03:09:14 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.74 2020/05/26 15:20:16 nia Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.75 2020/05/29 03:09:14 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -1566,6 +1566,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;
 	}
@@ -7754,13 +7761,18 @@ 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);
 
 	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;
 	}
 
 #ifdef AUDIO_PM_IDLE
@@ -7782,15 +7794,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 && sc->sc_ropens > 0)
+	}
+	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.11 src/sys/dev/audio/audiovar.h:1.12
--- src/sys/dev/audio/audiovar.h:1.11	Sat Mar  7 06:25:57 2020
+++ src/sys/dev/audio/audiovar.h	Fri May 29 03:09:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiovar.h,v 1.11 2020/03/07 06:25:57 isaki Exp $	*/
+/*	$NetBSD: audiovar.h,v 1.12 2020/05/29 03:09:14 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -235,6 +235,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: src/sys

2020-05-01 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Fri May  1 08:21:27 UTC 2020

Modified Files:
src/sys/arch/hppa/include: param.h
src/sys/arch/m68k/include: param.h
src/sys/arch/sh3/include: param.h
src/sys/arch/sparc/include: param.h
src/sys/arch/vax/include: param.h
src/sys/dev/audio: audio.c

Log Message:
Move machine dependent AUDIO_BLK_MS default value to .
If the port has __AUDIO_BLK_MS in , it will be used.
Otherwise the default value (currently 10 msec) defined in audio.c will
be used.  This mechanism is for very old ports which cannot satisfactorily
handle 10 msec block.  Currently hppa, m68k, sh3, sparc(!64) and vax are.

For port maintainers, if general models in your port cannot satisfactorily
handle 10 msec block, please consider to define your suitable longer period
(40 msec would be a good first choice).
But please don't be eager to make the default value shorter.

 was discussed in source-changes-d.  It's better than
ifdef storm, or adding 60+ new header files in every arch/*/include/
directories for this.  Thanks mrg@, ad@, and everyone.
http://mail-index.netbsd.org/source-changes-d/2020/05/01/msg012572.html


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/hppa/include/param.h
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/m68k/include/param.h
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/sh3/include/param.h
cvs rdiff -u -r1.73 -r1.74 src/sys/arch/sparc/include/param.h
cvs rdiff -u -r1.62 -r1.63 src/sys/arch/vax/include/param.h
cvs rdiff -u -r1.68 -r1.69 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/arch/hppa/include/param.h
diff -u src/sys/arch/hppa/include/param.h:1.26 src/sys/arch/hppa/include/param.h:1.27
--- src/sys/arch/hppa/include/param.h:1.26	Sat Mar 21 17:00:47 2020
+++ src/sys/arch/hppa/include/param.h	Fri May  1 08:21:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.26 2020/03/21 17:00:47 riastradh Exp $	*/
+/*	$NetBSD: param.h,v 1.27 2020/05/01 08:21:27 isaki Exp $	*/
 
 /*	$OpenBSD: param.h,v 1.12 2001/07/06 02:07:41 provos Exp $	*/
 
@@ -88,3 +88,8 @@
 
 #define btop(x)		((unsigned long)(x) >> PGSHIFT)
 #define ptob(x)		((unsigned long)(x) << PGSHIFT)
+
+/* Default audio blocksize in msec.  See sys/dev/audio/audio.c */
+#if defined(_KERNEL)
+#define	__AUDIO_BLK_MS (40)
+#endif

Index: src/sys/arch/m68k/include/param.h
diff -u src/sys/arch/m68k/include/param.h:1.22 src/sys/arch/m68k/include/param.h:1.23
--- src/sys/arch/m68k/include/param.h:1.22	Mon Jan  7 22:00:31 2019
+++ src/sys/arch/m68k/include/param.h	Fri May  1 08:21:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.22 2019/01/07 22:00:31 jdolecek Exp $	*/
+/*	$NetBSD: param.h,v 1.23 2020/05/01 08:21:27 isaki Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -95,4 +95,9 @@
 #define	m68k_btop(x)		((vaddr_t)(x) >> PGSHIFT)
 #define	m68k_ptob(x)		((vaddr_t)(x) << PGSHIFT)
 
+/* Default audio blocksize in msec.  See sys/dev/audio/audio.c */
+#if defined(_KERNEL)
+#define	__AUDIO_BLK_MS (40)
+#endif
+
 #endif	/* !_M68K_PARAM_H_ */

Index: src/sys/arch/sh3/include/param.h
diff -u src/sys/arch/sh3/include/param.h:1.24 src/sys/arch/sh3/include/param.h:1.25
--- src/sys/arch/sh3/include/param.h:1.24	Mon Jan  7 22:00:32 2019
+++ src/sys/arch/sh3/include/param.h	Fri May  1 08:21:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.24 2019/01/07 22:00:32 jdolecek Exp $	*/
+/*	$NetBSD: param.h,v 1.25 2020/05/01 08:21:27 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc. All rights reserved.
@@ -91,4 +91,9 @@
 #define	NKMEMPAGES_MIN_DEFAULT	((16 * 1024 * 1024) >> PAGE_SHIFT)
 #define	NKMEMPAGES_MAX_DEFAULT	((128 * 1024 * 1024) >> PAGE_SHIFT)
 
+/* Default audio blocksize in msec.  See sys/dev/audio/audio.c */
+#if defined(_KERNEL)
+#define	__AUDIO_BLK_MS (40)
+#endif
+
 #endif /* !_SH3_PARAM_H_ */

Index: src/sys/arch/sparc/include/param.h
diff -u src/sys/arch/sparc/include/param.h:1.73 src/sys/arch/sparc/include/param.h:1.74
--- src/sys/arch/sparc/include/param.h:1.73	Wed May 15 16:59:10 2019
+++ src/sys/arch/sparc/include/param.h	Fri May  1 08:21:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.73 2019/05/15 16:59:10 christos Exp $ */
+/*	$NetBSD: param.h,v 1.74 2020/05/01 08:21:27 isaki Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -155,4 +155,7 @@ extern void	delay(unsigned int);
 #	define PGSHIFT		pgshift
 #endif
 
+/* Default audio blocksize in msec.  See sys/dev/audio/audio.c */
+#define	__AUDIO_BLK_MS (40)
+
 #endif /* _KERNEL || _STANDALONE */

Index: src/sys/arch/vax/include/param.h
diff -u src/sys/arch/vax/include/param.h:1.62 src/sys/arch/vax/include/param.h:1.63
--- src/sys/arch/vax/include/param.h:1.62	Mon Jan  7 22:00:33 2019
+++ src/sys/arch/vax/include/param.h	Fri May  1 08:21:27 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: param.h,v 1.62 2019/01/07 22:00:33 jdolecek Exp $*/
+/*  $NetBSD: 

CVS commit: src/tests/dev/audio

2020-04-30 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Fri May  1 05:45:57 UTC 2020

Modified Files:
src/tests/dev/audio: audiotest.c

Log Message:
Fix two tests.
- kqueue_mode_{RDONLY,RDWR}_READ: Fix expected value.
  This is rest of rev1.9.
- AUDIO_SETINFO_params_simul: Fix condition.
  This happens on full-duplex, not bi-directional.
These affect only standalone test, not atf.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/dev/audio/audiotest.c

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

Modified files:

Index: src/tests/dev/audio/audiotest.c
diff -u src/tests/dev/audio/audiotest.c:1.10 src/tests/dev/audio/audiotest.c:1.11
--- src/tests/dev/audio/audiotest.c:1.10	Thu Mar 26 13:43:10 2020
+++ src/tests/dev/audio/audiotest.c	Fri May  1 05:45:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiotest.c,v 1.10 2020/03/26 13:43:10 isaki Exp $	*/
+/*	$NetBSD: audiotest.c,v 1.11 2020/05/01 05:45:57 isaki Exp $	*/
 
 /*
  * Copyright (C) 2019 Tetsuya Isaki. All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: audiotest.c,v 1.10 2020/03/26 13:43:10 isaki Exp $");
+__RCSID("$NetBSD: audiotest.c,v 1.11 2020/05/01 05:45:57 isaki Exp $");
 
 #include 
 #include 
@@ -3582,9 +3582,8 @@ test_kqueue_mode(int openmode, int filt,
 	XP_SYS_EQ(0, r);
 }
 DEF(kqueue_mode_RDONLY_READ) {
-	/* Should not raise yet (NetBSD7 has bugs?) */
-	int expected = (netbsd < 8) ? 1 : 0;
-	test_kqueue_mode(O_RDONLY, EVFILT_READ, expected);
+	/* Should raise */
+	test_kqueue_mode(O_RDONLY, EVFILT_READ, 1);
 }
 DEF(kqueue_mode_RDONLY_WRITE) {
 	/* Should never raise (NetBSD7 has bugs) */
@@ -3600,8 +3599,8 @@ DEF(kqueue_mode_WRONLY_WRITE) {
 	test_kqueue_mode(O_WRONLY, EVFILT_WRITE, 1);
 }
 DEF(kqueue_mode_RDWR_READ) {
-	/* Should not raise yet (NetBSD7 is something strange) */
-	int expected = (netbsd < 8 && hw_fulldup()) ? 1 : 0;
+	/* Should raise on fulldup but not on halfdup, on NetBSD9 */
+	int expected = hw_fulldup() ? 1 : 0;
 	test_kqueue_mode(O_RDWR, EVFILT_READ, expected);
 }
 DEF(kqueue_mode_RDWR_WRITE) {
@@ -5149,16 +5148,16 @@ DEF(AUDIO_SETINFO_params_simul)
 	XP_SYS_EQ(0, r);
 
 	/*
-	 * On bi-directional device, the 2nd one has both track so that
+	 * On full-duplex device, the 2nd one has both track so that
 	 * both track are not affected by sticky parameter.
-	 * On uni-directional device, the 2nd one has only playback track
-	 * so that playback track is not affected by sticky parameter.
+	 * Otherwise, the 2nd one has only playback track so that
+	 * playback track is not affected by sticky parameter.
 	 */
 	memset(, 0, sizeof(ai));
 	r = IOCTL(fd1, AUDIO_GETBUFINFO, , "");
 	XP_SYS_EQ(0, r);
 	XP_EQ(11025, ai.play.sample_rate);
-	if (hw_bidir()) {
+	if (hw_fulldup()) {
 		XP_EQ(11025, ai.record.sample_rate);
 	} else {
 		XP_EQ(16000, ai.record.sample_rate);



CVS commit: src/sys/dev/audio

2020-04-28 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Apr 29 03:58:27 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c audiodef.h

Log Message:
Set AUDIO_BLK_MS 40 msec on other old(slow) architectures not only m68k.
Thanks tsutsui@ for comment about architecture choice.
And move it from audiodef.h to audio.c as suggested by joerg@.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.13 -r1.14 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.67 src/sys/dev/audio/audio.c:1.68
--- src/sys/dev/audio/audio.c:1.67	Sun Apr 19 03:52:22 2020
+++ src/sys/dev/audio/audio.c	Wed Apr 29 03:58:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.67 2020/04/19 03:52:22 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.68 2020/04/29 03:58:27 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.67 2020/04/19 03:52:22 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.68 2020/04/29 03:58:27 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -451,6 +451,41 @@ audio_track_bufstat(audio_track_t *track
 #define SPECIFIED(x)	((x) != ~0)
 #define SPECIFIED_CH(x)	((x) != (u_char)~0)
 
+/*
+ * Default hardware blocksize in msec.
+ *
+ * We use 10 msec for most platforms.  This period is good enough to play
+ * audio and video synchronizely.
+ * In contrast, for very old platforms, this is usually too short and too
+ * severe.  Also such platforms usually can not play video confortably, so
+ * it's not so important to make the blocksize shorter.
+ * In either case, you can overwrite AUDIO_BLK_MS by your kernel
+ * configuration file if you wish.
+ *
+ * 40 msec was initially choosen for the following reason:
+ * (1 / 40ms) = 25 = 5^2.  Thus, the frequency is factored by 5.
+ * In this case, the number of frames in a block can be an integer
+ * even if the frequency is a multiple of 100 (44100, 48000, etc),
+ * or even if 15625Hz (vs(4)).
+ */
+#if defined(__hppa__)	|| \
+defined(__m68k__)	|| \
+defined(__sh3__)	|| \
+(defined(__sparc__) && !defined(__sparc64__))	|| \
+defined(__vax__)
+#define AUDIO_TOO_SLOW_ARCHS 1
+#endif
+
+#if !defined(AUDIO_BLK_MS)
+# if defined(AUDIO_TOO_SLOW_ARCHS)
+#  define AUDIO_BLK_MS 40
+# else
+#  define AUDIO_BLK_MS 10
+# endif
+#endif
+
+#undef AUDIO_TOO_SLOW_ARCHS
+
 /* Device timeout in msec */
 #define AUDIO_TIMEOUT	(3000)
 

Index: src/sys/dev/audio/audiodef.h
diff -u src/sys/dev/audio/audiodef.h:1.13 src/sys/dev/audio/audiodef.h:1.14
--- src/sys/dev/audio/audiodef.h:1.13	Sat Mar 28 08:35:36 2020
+++ src/sys/dev/audio/audiodef.h	Wed Apr 29 03:58:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiodef.h,v 1.13 2020/03/28 08:35:36 isaki Exp $	*/
+/*	$NetBSD: audiodef.h,v 1.14 2020/04/29 03:58:27 isaki Exp $	*/
 
 /*
  * Copyright (C) 2017 Tetsuya Isaki. All rights reserved.
@@ -43,25 +43,6 @@
 #define AUMINNOBLK	(3)
 
 /*
- * Hardware blocksize in msec.
- * We use 10 msec as default for most platforms.  But it's too severe for
- * most m68k.
- *
- * 40 msec was initially choosen for the following reason:
- * (1 / 40ms) = 25 = 5^2.  Thus, the frequency is factored by 5.
- * In this case, the number of frames in a block can be an integer
- * even if the frequency is a multiple of 100 (44100, 48000, etc),
- * or even if 15625Hz (vs(4)).
- */
-#if !defined(AUDIO_BLK_MS)
-# if defined(__m68k__)
-#  define AUDIO_BLK_MS 40
-# else
-#  define AUDIO_BLK_MS 10
-# endif
-#endif
-
-/*
  * Whether the playback mixer use single buffer mode.
  * It reduces the latency one block but needs machine power.
  * In case of the double buffer (as default), it increases the latency



CVS commit: src/sys

2020-04-19 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Apr 19 08:18:19 UTC 2020

Modified Files:
src/sys/arch/arm/imx: imx23_digfilt.c
src/sys/arch/arm/xscale: pxa2x0_ac97.c
src/sys/dev/pci: auvia.c esm.c sv.c

Log Message:
Fix round_blocksize not to return 0.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/imx/imx23_digfilt.c
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/arm/xscale/pxa2x0_ac97.c
cvs rdiff -u -r1.85 -r1.86 src/sys/dev/pci/auvia.c
cvs rdiff -u -r1.64 -r1.65 src/sys/dev/pci/esm.c
cvs rdiff -u -r1.57 -r1.58 src/sys/dev/pci/sv.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/arch/arm/imx/imx23_digfilt.c
diff -u src/sys/arch/arm/imx/imx23_digfilt.c:1.2 src/sys/arch/arm/imx/imx23_digfilt.c:1.3
--- src/sys/arch/arm/imx/imx23_digfilt.c:1.2	Wed May  8 13:40:14 2019
+++ src/sys/arch/arm/imx/imx23_digfilt.c	Sun Apr 19 08:18:19 2020
@@ -1,4 +1,4 @@
-/* $Id: imx23_digfilt.c,v 1.2 2019/05/08 13:40:14 isaki Exp $ */
+/* $Id: imx23_digfilt.c,v 1.3 2020/04/19 08:18:19 isaki Exp $ */
 
 /*
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -380,6 +380,8 @@ const audio_params_t *param)
 		blocksize = DIGFILT_BLOCKSIZE_MAX;
 	else
 		blocksize = bs & ~(DIGFILT_BLOCKSIZE_ROUND-1);
+	if (blocksize < DIGFILT_BLOCKSIZE_ROUND)
+		blocksize = DIGFILT_BLOCKSIZE_ROUND;
 
 	return blocksize;
 }

Index: src/sys/arch/arm/xscale/pxa2x0_ac97.c
diff -u src/sys/arch/arm/xscale/pxa2x0_ac97.c:1.17 src/sys/arch/arm/xscale/pxa2x0_ac97.c:1.18
--- src/sys/arch/arm/xscale/pxa2x0_ac97.c:1.17	Sat Jun  8 08:02:37 2019
+++ src/sys/arch/arm/xscale/pxa2x0_ac97.c	Sun Apr 19 08:18:19 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pxa2x0_ac97.c,v 1.17 2019/06/08 08:02:37 isaki Exp $	*/
+/*	$NetBSD: pxa2x0_ac97.c,v 1.18 2020/04/19 08:18:19 isaki Exp $	*/
 
 /*
  * Copyright (c) 2003, 2005 Wasabi Systems, Inc.
@@ -593,7 +593,10 @@ static int
 acu_round_blocksize(void *arg, int blk, int mode, const audio_params_t *param)
 {
 
-	return (blk & ~0x1f);
+	blk = (blk & ~0x1f);
+	if (blk < 0x20)
+		blk = 0x20;
+	return blk;
 }
 
 static int

Index: src/sys/dev/pci/auvia.c
diff -u src/sys/dev/pci/auvia.c:1.85 src/sys/dev/pci/auvia.c:1.86
--- src/sys/dev/pci/auvia.c:1.85	Fri Feb 28 13:31:03 2020
+++ src/sys/dev/pci/auvia.c	Sun Apr 19 08:18:19 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: auvia.c,v 1.85 2020/02/28 13:31:03 isaki Exp $	*/
+/*	$NetBSD: auvia.c,v 1.86 2020/04/19 08:18:19 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2008 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: auvia.c,v 1.85 2020/02/28 13:31:03 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: auvia.c,v 1.86 2020/04/19 08:18:19 isaki Exp $");
 
 #include 
 #include 
@@ -749,7 +749,10 @@ auvia_round_blocksize(void *addr, int bl
 	if (sc->sc_flags & AUVIA_FLAGS_VT8233 && blk < 288)
 		blk = 288;
 
-	return (blk & -32);
+	blk = (blk & -32);
+	if (blk < 32)
+		blk = 32;
+	return blk;
 }
 
 static int

Index: src/sys/dev/pci/esm.c
diff -u src/sys/dev/pci/esm.c:1.64 src/sys/dev/pci/esm.c:1.65
--- src/sys/dev/pci/esm.c:1.64	Sat Oct  5 01:30:28 2019
+++ src/sys/dev/pci/esm.c	Sun Apr 19 08:18:19 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: esm.c,v 1.64 2019/10/05 01:30:28 mrg Exp $  */
+/*  $NetBSD: esm.c,v 1.65 2020/04/19 08:18:19 isaki Exp $  */
 
 /*-
  * Copyright (c) 2002, 2003 Matt Fredette
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: esm.c,v 1.64 2019/10/05 01:30:28 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: esm.c,v 1.65 2020/04/19 08:18:19 isaki Exp $");
 
 #include 
 #include 
@@ -1186,6 +1186,8 @@ esm_round_blocksize(void *sc, int blk, i
 	("esm_round_blocksize(%p, 0x%x)", sc, blk));
 
 	blk &= ~0x3f;		/* keep good alignment */
+	if (blk < 0x40)
+		blk = 0x40;
 
 	DPRINTF(ESM_DEBUG_PARAM, (" = 0x%x\n", blk));
 

Index: src/sys/dev/pci/sv.c
diff -u src/sys/dev/pci/sv.c:1.57 src/sys/dev/pci/sv.c:1.58
--- src/sys/dev/pci/sv.c:1.57	Mon Oct 28 18:38:43 2019
+++ src/sys/dev/pci/sv.c	Sun Apr 19 08:18:19 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: sv.c,v 1.57 2019/10/28 18:38:43 joerg Exp $ */
+/*  $NetBSD: sv.c,v 1.58 2020/04/19 08:18:19 isaki Exp $ */
 /*  $OpenBSD: sv.c,v 1.2 1998/07/13 01:50:15 csapuntz Exp $ */
 
 /*
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sv.c,v 1.57 2019/10/28 18:38:43 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sv.c,v 1.58 2020/04/19 08:18:19 isaki Exp $");
 
 #include 
 #include 
@@ -679,7 +679,10 @@ sv_round_blocksize(void *addr, int blk, 
 const audio_params_t *param)
 {
 
-	return blk & -32;	/* keep good alignment */
+	blk = blk & -32;	/* keep good alignment */
+	if (blk < 32)
+		blk = 32;
+	return blk;
 }
 
 static int



CVS commit: src/sys/dev/hdaudio

2020-04-18 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Apr 19 04:13:10 UTC 2020

Modified Files:
src/sys/dev/hdaudio: hdafg.c

Log Message:
Make round_blocksize satisfy all of
- restrictions that existed before merging isaki-audio2 branch.
- better support for 6 channels hardware.
- audio layer's requirement.
This may help PR kern/54474.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/hdaudio/hdafg.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/hdaudio/hdafg.c
diff -u src/sys/dev/hdaudio/hdafg.c:1.21 src/sys/dev/hdaudio/hdafg.c:1.22
--- src/sys/dev/hdaudio/hdafg.c:1.21	Sat Feb 15 03:04:45 2020
+++ src/sys/dev/hdaudio/hdafg.c	Sun Apr 19 04:13:09 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: hdafg.c,v 1.21 2020/02/15 03:04:45 isaki Exp $ */
+/* $NetBSD: hdafg.c,v 1.22 2020/04/19 04:13:09 isaki Exp $ */
 
 /*
  * Copyright (c) 2009 Precedence Technologies Ltd 
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hdafg.c,v 1.21 2020/02/15 03:04:45 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hdafg.c,v 1.22 2020/04/19 04:13:09 isaki Exp $");
 
 #include 
 #include 
@@ -3942,12 +3942,28 @@ hdafg_set_format(void *opaque, int setmo
 	return 0;
 }
 
+/* LCM for round_blocksize */
+static u_int gcd(u_int, u_int);
+static u_int lcm(u_int, u_int);
+
+static u_int gcd(u_int a, u_int b)
+{
+
+	return (b == 0) ? a : gcd(b, a % b);
+}
+static u_int lcm(u_int a, u_int b)
+{
+
+	return a * b / gcd(a, b);
+}
+
 static int
 hdafg_round_blocksize(void *opaque, int blksize, int mode,
 const audio_params_t *param)
 {
 	struct hdaudio_audiodev *ad = opaque;
 	struct hdaudio_stream *st;
+	u_int minblksize;
 	int bufsize;
 
 	st = (mode == AUMODE_PLAY) ? ad->ad_playback : ad->ad_capture;
@@ -3957,6 +3973,15 @@ hdafg_round_blocksize(void *opaque, int 
 		return 128;
 	}
 
+	if (blksize > 8192)
+		blksize = 8192;
+
+	/* Make sure there are enough BDL descriptors */
+	bufsize = st->st_data.dma_size;
+	if (bufsize > HDAUDIO_BDL_MAX * blksize) {
+		blksize = bufsize / HDAUDIO_BDL_MAX;
+	}
+
 	/*
 	 * HD audio's buffer constraint looks like following:
 	 * - The buffer MUST start on a 128bytes boundary.
@@ -3964,13 +3989,15 @@ hdafg_round_blocksize(void *opaque, int 
 	 * - The buffer size is preferred multiple of 128bytes for efficiency.
 	 *
 	 * https://www.intel.co.jp/content/www/jp/ja/standards/high-definition-audio-specification.html , p70.
+	 *
+	 * Also, the audio layer requires that the blocksize must be a
+	 * multiple of the number of channels.
 	 */
+	minblksize = lcm(128, param->channels);
+	blksize = rounddown(blksize, minblksize);
+	if (blksize < minblksize)
+		blksize = minblksize;
 
-	/* Make sure there are enough BDL descriptors */
-	bufsize = st->st_data.dma_size;
-	if (bufsize > HDAUDIO_BDL_MAX * blksize) {
-		blksize = bufsize / HDAUDIO_BDL_MAX;
-	}
 	return blksize;
 }
 



CVS commit: src/sys/dev/audio

2020-04-18 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Apr 19 03:52:22 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
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.66 -r1.67 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.66 src/sys/dev/audio/audio.c:1.67
--- src/sys/dev/audio/audio.c:1.66	Fri Apr 17 07:48:35 2020
+++ src/sys/dev/audio/audio.c	Sun Apr 19 03:52:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.66 2020/04/17 07:48:35 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.67 2020/04/19 03:52:22 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.66 2020/04/17 07:48:35 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.67 2020/04/19 03:52:22 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -4788,6 +4788,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;
@@ -4796,6 +4797,7 @@ audio_mixer_init(struct audio_softc *sc,
 	size_t bufsize;
 	int hwblks;
 	int blkms;
+	int blkdms;
 	int error;
 
 	KASSERT(hwfmt != NULL);
@@ -4975,13 +4977,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;



CVS commit: src/sys/dev/audio

2020-04-17 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Fri Apr 17 07:48:35 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Improve diagnostic messages.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 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.65 src/sys/dev/audio/audio.c:1.66
--- src/sys/dev/audio/audio.c:1.65	Thu Mar 26 13:32:03 2020
+++ src/sys/dev/audio/audio.c	Fri Apr 17 07:48:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.65 2020/03/26 13:32:03 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.66 2020/04/17 07:48:35 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.65 2020/03/26 13:32:03 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.66 2020/04/17 07:48:35 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -5468,7 +5468,9 @@ audio_pintr(void *arg)
 		return;
 	if (sc->sc_pbusy == false) {
 #if defined(DIAGNOSTIC)
-		device_printf(sc->sc_dev, "stray interrupt\n");
+		device_printf(sc->sc_dev,
+		"DIAGNOSTIC: %s raised stray interrupt\n",
+		device_xname(sc->hw_dev));
 #endif
 		return;
 	}
@@ -5737,7 +5739,9 @@ audio_rintr(void *arg)
 		return;
 	if (sc->sc_rbusy == false) {
 #if defined(DIAGNOSTIC)
-		device_printf(sc->sc_dev, "stray interrupt\n");
+		device_printf(sc->sc_dev,
+		"DIAGNOSTIC: %s raised stray interrupt\n",
+		device_xname(sc->hw_dev));
 #endif
 		return;
 	}



CVS commit: src/sys

2020-03-28 Thread Tetsuya Isaki
/arch/macppc/conf/GENERIC:1.366
--- src/sys/arch/macppc/conf/GENERIC:1.365	Mon Mar 16 19:09:34 2020
+++ src/sys/arch/macppc/conf/GENERIC	Sat Mar 28 08:35:36 2020
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.365 2020/03/16 19:09:34 nia Exp $
+# $NetBSD: GENERIC,v 1.366 2020/03/28 08:35:36 isaki Exp $
 #
 # GENERIC machine description file
 # 
@@ -22,7 +22,7 @@ include		"arch/macppc/conf/std.macppc"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		"GENERIC-$Revision: 1.365 $"
+#ident 		"GENERIC-$Revision: 1.366 $"
 
 maxusers	32
 
@@ -31,9 +31,6 @@ options 	ALTIVEC		# Include AltiVec supp
 # Standard system options
 options 	INSECURE	# disable kernel security levels
 
-options		AUDIO_BLK_MS=4	# make software with low latency needs performant
-# no substantial CPU overhead on this platform
-
 options 	RTC_OFFSET=0	# hardware clock is this many mins. west of GMT
 options 	NTP		# NTP phase/frequency locked loop
 options 	KTRACE		# system call tracing via ktrace(1)

Index: src/sys/arch/sparc64/conf/GENERIC
diff -u src/sys/arch/sparc64/conf/GENERIC:1.225 src/sys/arch/sparc64/conf/GENERIC:1.226
--- src/sys/arch/sparc64/conf/GENERIC:1.225	Mon Mar 16 19:09:34 2020
+++ src/sys/arch/sparc64/conf/GENERIC	Sat Mar 28 08:35:36 2020
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.225 2020/03/16 19:09:34 nia Exp $
+# $NetBSD: GENERIC,v 1.226 2020/03/28 08:35:36 isaki Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@ include 	"arch/sparc64/conf/std.sparc64"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident		"GENERIC-$Revision: 1.225 $"
+#ident		"GENERIC-$Revision: 1.226 $"
 
 maxusers	64
 
@@ -48,9 +48,6 @@ config		netbsd	root on ? type ?
 #options 	UVMHIST
 #options 	UVMHIST_PRINT	# Loud!
 
-options		AUDIO_BLK_MS=4	# make software with low latency needs performant
-# no substantial CPU overhead on this platform
-
 ## System call tracing (see ktrace(1)).
 options 	KTRACE
 

Index: src/sys/dev/audio/audiodef.h
diff -u src/sys/dev/audio/audiodef.h:1.12 src/sys/dev/audio/audiodef.h:1.13
--- src/sys/dev/audio/audiodef.h:1.12	Thu Mar  5 15:18:55 2020
+++ src/sys/dev/audio/audiodef.h	Sat Mar 28 08:35:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiodef.h,v 1.12 2020/03/05 15:18:55 riastradh Exp $	*/
+/*	$NetBSD: audiodef.h,v 1.13 2020/03/28 08:35:36 isaki Exp $	*/
 
 /*
  * Copyright (C) 2017 Tetsuya Isaki. All rights reserved.
@@ -44,13 +44,21 @@
 
 /*
  * Hardware blocksize in msec.
- * We use 40 msec as default.  (1 / 40ms) = 25 = 5^2.
+ * We use 10 msec as default for most platforms.  But it's too severe for
+ * most m68k.
+ *
+ * 40 msec was initially choosen for the following reason:
+ * (1 / 40ms) = 25 = 5^2.  Thus, the frequency is factored by 5.
  * In this case, the number of frames in a block can be an integer
  * even if the frequency is a multiple of 100 (44100, 48000, etc),
  * or even if 15625Hz (vs(4)).
  */
 #if !defined(AUDIO_BLK_MS)
-#define AUDIO_BLK_MS 40
+# if defined(__m68k__)
+#  define AUDIO_BLK_MS 40
+# else
+#  define AUDIO_BLK_MS 10
+# endif
 #endif
 
 /*



CVS commit: src/share/man/man4

2020-03-27 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Mar 28 04:55:08 UTC 2020

Modified Files:
src/share/man/man4: audio.4

Log Message:
Add description about channel limitation introduced in audio.c 1.43.
PR kern/54973.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/share/man/man4/audio.4

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

Modified files:

Index: src/share/man/man4/audio.4
diff -u src/share/man/man4/audio.4:1.101 src/share/man/man4/audio.4:1.102
--- src/share/man/man4/audio.4:1.101	Sat Mar 28 04:21:58 2020
+++ src/share/man/man4/audio.4	Sat Mar 28 04:55:08 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: audio.4,v 1.101 2020/03/28 04:21:58 isaki Exp $
+.\"	$NetBSD: audio.4,v 1.102 2020/03/28 04:55:08 isaki Exp $
 .\"
 .\" Copyright (c) 1996 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -400,18 +400,25 @@ unsigned linear encoding with big endian
 Dolby Digital AC3
 .El
 .Pp
-Regardless of formats supported by underlying driver, the
+The
 .Nm
 driver accepts the following formats.
 .Va encoding
 and
 .Va precision
 are one of the values obtained by
-.Dv AUDIO_GETENC .
-.Va channels
-ranges from 1 to 12.
+.Dv AUDIO_GETENC ,
+regardless of formats supported by underlying driver.
 .Va frequency
-ranges from 1000Hz to 192000Hz.
+ranges from 1000Hz to 192000Hz,
+regardless of frequency (ranges) supported by underlying driver.
+.Va channels
+depends your underlying driver.
+If the underlying driver only supports monaural (1channel)
+or stereo (2channels), you can specify 1 or 2 regardless of
+number of channels supported by underlying driver.
+If the underlying driver supports three or more channels, you can specify
+the number of channels supported by the underlying driver or less. 
 .Pp
 The
 .Va gain ,



CVS commit: src/share/man/man4

2020-03-27 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Mar 28 04:21:58 UTC 2020

Modified Files:
src/share/man/man4: audio.4

Log Message:
Revert 1.96, 1.97 and 1.100.  (no response from nia@)
These changes are not correct nor notable unresolvable problem.
If you find any problems, please send a report before changing manpage.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/share/man/man4/audio.4

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

Modified files:

Index: src/share/man/man4/audio.4
diff -u src/share/man/man4/audio.4:1.100 src/share/man/man4/audio.4:1.101
--- src/share/man/man4/audio.4:1.100	Tue Mar 17 10:50:59 2020
+++ src/share/man/man4/audio.4	Sat Mar 28 04:21:58 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: audio.4,v 1.100 2020/03/17 10:50:59 nia Exp $
+.\"	$NetBSD: audio.4,v 1.101 2020/03/28 04:21:58 isaki Exp $
 .\"
 .\" Copyright (c) 1996 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd March 16, 2020
+.Dd March 28, 2020
 .Dt AUDIO 4
 .Os
 .Sh NAME
@@ -157,6 +157,14 @@ For historical reasons, only encodings t
 .Dv AUDIO_ENCODINGFLAG_EMULATED
 are able to
 .Xr mmap 2 .
+.Pp
+The audio device, like most devices, can be used in
+.Xr select 2 ,
+can be set in non-blocking mode and can be set (with a
+.Dv FIOASYNC
+ioctl) to send a
+.Dv SIGIO
+when I/O is possible.
 The mixer device can be set to generate a
 .Dv SIGIO
 whenever a mixer value is changed.
@@ -401,7 +409,7 @@ and
 are one of the values obtained by
 .Dv AUDIO_GETENC .
 .Va channels
-ranges from 1 to 12 for playback.
+ranges from 1 to 12.
 .Va frequency
 ranges from 1000Hz to 192000Hz.
 .Pp
@@ -811,12 +819,6 @@ string values.
 .Sh HISTORY
 Support for virtual channels and mixing first appeared in
 .Nx 8.0 .
-.Sh CAVEATS
-The audio device cannot be reliably used with event notification mechanisms
-such as
-.Xr poll 2 .
-Most users are expected to only read and write a limited number of samples at
-a time, limiting the time spent in the system call.
 .Sh BUGS
 If the device is used in
 .Xr mmap 2



CVS commit: src/tests/dev/audio

2020-03-26 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Thu Mar 26 13:43:10 UTC 2020

Modified Files:
src/tests/dev/audio: audiotest.c

Log Message:
Add tests for poll(POLLIN) before read().
This affects only standalone test, not atf.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/dev/audio/audiotest.c

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

Modified files:

Index: src/tests/dev/audio/audiotest.c
diff -u src/tests/dev/audio/audiotest.c:1.9 src/tests/dev/audio/audiotest.c:1.10
--- src/tests/dev/audio/audiotest.c:1.9	Thu Mar 26 13:37:44 2020
+++ src/tests/dev/audio/audiotest.c	Thu Mar 26 13:43:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiotest.c,v 1.9 2020/03/26 13:37:44 isaki Exp $	*/
+/*	$NetBSD: audiotest.c,v 1.10 2020/03/26 13:43:10 isaki Exp $	*/
 
 /*
  * Copyright (C) 2019 Tetsuya Isaki. All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: audiotest.c,v 1.9 2020/03/26 13:37:44 isaki Exp $");
+__RCSID("$NetBSD: audiotest.c,v 1.10 2020/03/26 13:43:10 isaki Exp $");
 
 #include 
 #include 
@@ -1383,6 +1383,7 @@ void test_rdwr_fallback(int, bool, bool)
 void test_rdwr_two(int, int);
 void test_mmap_mode(int, int);
 void test_poll_mode(int, int, int);
+void test_poll_in_open(const char *);
 void test_kqueue_mode(int, int, int);
 volatile int sigio_caught;
 void signal_FIOASYNC(int);
@@ -3372,6 +3373,81 @@ DEF(poll_out_simul)
 }
 
 /*
+ * Open with READ mode starts recording immediately.
+ * Of course, audioctl doesn't start.
+ */
+void
+test_poll_in_open(const char *devname)
+{
+	struct audio_info ai;
+	struct pollfd pfd;
+	char buf[4096];
+	char devfile[16];
+	int fd;
+	int r;
+	bool is_audioctl;
+
+	TEST("poll_in_open_%s", devname);
+	if (hw_canrec() == 0) {
+		XP_SKIP("This test is only for recordable device");
+		return;
+	}
+
+	snprintf(devfile, sizeof(devfile), "/dev/%s%d", devname, unit);
+	is_audioctl = (strcmp(devname, "audioctl") == 0);
+
+	fd = OPEN(devfile, O_RDONLY);
+	REQUIRED_SYS_OK(fd);
+
+	r = IOCTL(fd, AUDIO_GETBUFINFO, , "");
+	REQUIRED_SYS_EQ(0, r);
+	if (is_audioctl) {
+		/* opening /dev/audioctl doesn't start recording. */
+		XP_EQ(0, ai.record.active);
+	} else {
+		/* opening /dev/{audio,sound} starts recording. */
+		/*
+		 * On NetBSD7/8, opening /dev/sound doesn't start recording.
+		 * It must be a bug.
+		 */
+		XP_EQ(1, ai.record.active);
+	}
+
+	memset(, 0, sizeof(pfd));
+	pfd.fd = fd;
+	pfd.events = POLLIN;
+	r = POLL(, 1, 1000);
+	if (is_audioctl) {
+		/*
+		 * poll-ing /dev/audioctl always fails.
+		 * XXX Returning error instead of timeout should be better(?).
+		 */
+		REQUIRED_SYS_EQ(0, r);
+	} else {
+		/*
+		 * poll-ing /dev/{audio,sound} will succeed when recorded
+		 * data is arrived.
+		 */
+		/*
+		 * On NetBSD7/8, opening /dev/sound doesn't start recording.
+		 * It must be a bug.
+		 */
+		REQUIRED_SYS_EQ(1, r);
+
+		/* In this case, read() should succeed. */
+		r = READ(fd, buf, sizeof(buf));
+		XP_SYS_OK(r);
+		XP_NE(0, r);
+	}
+
+	r = CLOSE(fd);
+	XP_SYS_EQ(0, r);
+}
+DEF(poll_in_open_audio)		{ test_poll_in_open("audio"); }
+DEF(poll_in_open_sound)		{ test_poll_in_open("sound"); }
+DEF(poll_in_open_audioctl)	{ test_poll_in_open("audioctl"); }
+
+/*
  * poll(2) must not be affected by other recording descriptors even if
  * playback descriptor waits with POLLIN (though it's not normal usage).
  * In other words, two POLLIN must not interfere.
@@ -6216,6 +6292,9 @@ struct testentry testtable[] = {
 	ENT(poll_out_hiwat),
 /**/	ENT(poll_out_unpause),		// XXX does not seem to work on rump
 /**/	ENT(poll_out_simul),		// XXX does not seem to work on rump
+	ENT(poll_in_open_audio),
+	ENT(poll_in_open_sound),
+	ENT(poll_in_open_audioctl),
 	ENT(poll_in_simul),
 	ENT(kqueue_mode_RDONLY_READ),
 	ENT(kqueue_mode_RDONLY_WRITE),



CVS commit: src/tests/dev/audio

2020-03-26 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Thu Mar 26 13:37:44 UTC 2020

Modified Files:
src/tests/dev/audio: audiotest.c

Log Message:
Sync with sys/dev/audio/audio.c rev1.65.
> Fix to start recording immediately when open() with READ mode is called.
This affects only standalone test, not atf.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/dev/audio/audiotest.c

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

Modified files:

Index: src/tests/dev/audio/audiotest.c
diff -u src/tests/dev/audio/audiotest.c:1.8 src/tests/dev/audio/audiotest.c:1.9
--- src/tests/dev/audio/audiotest.c:1.8	Wed Mar 25 13:07:04 2020
+++ src/tests/dev/audio/audiotest.c	Thu Mar 26 13:37:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiotest.c,v 1.8 2020/03/25 13:07:04 isaki Exp $	*/
+/*	$NetBSD: audiotest.c,v 1.9 2020/03/26 13:37:44 isaki Exp $	*/
 
 /*
  * Copyright (C) 2019 Tetsuya Isaki. All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: audiotest.c,v 1.8 2020/03/25 13:07:04 isaki Exp $");
+__RCSID("$NetBSD: audiotest.c,v 1.9 2020/03/26 13:37:44 isaki Exp $");
 
 #include 
 #include 
@@ -1557,14 +1557,14 @@ test_open(const char *devname, int mode)
 	XP_EQ(0, ai.record.waiting);
 		/* balance */
 	XP_EQ(exp_ropen, ai.record.open);
-	/*
-	 * NetBSD7,8 (may?) be active when opened in recording mode but
-	 * recording has not started yet. (?)
-	 * NetBSD9 is not active at that time.
-	 */
-	if (netbsd < 9) {
-	} else {
+	if (netbsd < 9 && strcmp(devname, "sound") == 0) {
+		/*
+		 * On NetBSD7/8, it doesn't seem to start recording on open
+		 * for /dev/sound.  It should be a bug.
+		 */
 		XP_EQ(0, ai.record.active);
+	} else {
+		XP_EQ(exp_ropen, ai.record.active);
 	}
 	/* Save it */
 	ai0 = ai;
@@ -1645,9 +1645,14 @@ test_open(const char *devname, int mode)
 	XP_EQ(0, ai.record.waiting);
 		/* balance */
 	XP_EQ(exp_ropen, ai.record.open);
-	if (netbsd < 9) {
-	} else {
+	if (netbsd < 9 && strcmp(devname, "sound") == 0) {
+		/*
+		 * On NetBSD7/8, it doesn't seem to start recording on open
+		 * for /dev/sound.  It should be a bug.
+		 */
 		XP_EQ(0, ai.record.active);
+	} else {
+		XP_EQ(exp_ropen, ai.record.active);
 	}
 
 	r = CLOSE(fd);
@@ -2921,6 +2926,9 @@ test_poll_mode(int mode, int events, int
 	fd = OPEN(devaudio, mode);
 	REQUIRED_SYS_OK(fd);
 
+	/* Wait a bit to be recorded. */
+	usleep(100 * 1000);
+
 	memset(, 0, sizeof(pfd));
 	pfd.fd = fd;
 	pfd.events = events;
@@ -2948,15 +2956,23 @@ test_poll_mode(int mode, int events, int
 	r = CLOSE(fd);
 	XP_SYS_EQ(0, r);
 }
-DEF(poll_mode_RDONLY_IN)	{ test_poll_mode(O_RDONLY, IN, 0); }
+DEF(poll_mode_RDONLY_IN)	{ test_poll_mode(O_RDONLY, IN, IN); }
 DEF(poll_mode_RDONLY_OUT)	{ test_poll_mode(O_RDONLY, OUT,0); }
-DEF(poll_mode_RDONLY_INOUT)	{ test_poll_mode(O_RDONLY, IN|OUT, 0); }
+DEF(poll_mode_RDONLY_INOUT)	{ test_poll_mode(O_RDONLY, IN|OUT, IN); }
 DEF(poll_mode_WRONLY_IN)	{ test_poll_mode(O_WRONLY, IN, 0); }
 DEF(poll_mode_WRONLY_OUT)	{ test_poll_mode(O_WRONLY, OUT,	   OUT); }
 DEF(poll_mode_WRONLY_INOUT)	{ test_poll_mode(O_WRONLY, IN|OUT, OUT); }
-DEF(poll_mode_RDWR_IN)		{ test_poll_mode(O_RDWR,   IN, 0); }
+DEF(poll_mode_RDWR_IN)		{
+	/* On half-duplex, O_RDWR is the same as O_WRONLY. */
+	if (hw_fulldup()) test_poll_mode(O_RDWR,   IN, IN);
+	else		  test_poll_mode(O_RDWR,   IN, 0);
+}
 DEF(poll_mode_RDWR_OUT)		{ test_poll_mode(O_RDWR,   OUT,	   OUT); }
-DEF(poll_mode_RDWR_INOUT)	{ test_poll_mode(O_RDWR,   IN|OUT, OUT); }
+DEF(poll_mode_RDWR_INOUT)	{
+	/* On half-duplex, O_RDWR is the same as O_WRONLY. */
+	if (hw_fulldup()) test_poll_mode(O_RDWR,   IN|OUT, IN|OUT);
+	else		  test_poll_mode(O_RDWR,   IN|OUT,OUT);
+}
 
 /*
  * Poll(OUT) when buffer is empty.



CVS commit: src/sys/dev/audio

2020-03-26 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Thu Mar 26 13:32:03 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
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.64 -r1.65 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.64 src/sys/dev/audio/audio.c:1.65
--- src/sys/dev/audio/audio.c:1.64	Sat Mar  7 06:27:19 2020
+++ src/sys/dev/audio/audio.c	Thu Mar 26 13:32:03 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.64 2020/03/07 06:27:19 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.65 2020/03/26 13:32:03 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.64 2020/03/07 06:27:19 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.65 2020/03/26 13:32:03 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2229,7 +2229,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;
@@ -2244,6 +2247,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) {
@@ -2462,21 +2469,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;
@@ -6680,10 +6684,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: src/tests/dev/audio

2020-03-25 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Mar 25 13:07:04 UTC 2020

Modified Files:
src/tests/dev/audio: audiotest.c t_audio.awk

Log Message:
Use exact match to search testname.
This didn't affect test results.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/dev/audio/audiotest.c
cvs rdiff -u -r1.1 -r1.2 src/tests/dev/audio/t_audio.awk

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

Modified files:

Index: src/tests/dev/audio/audiotest.c
diff -u src/tests/dev/audio/audiotest.c:1.7 src/tests/dev/audio/audiotest.c:1.8
--- src/tests/dev/audio/audiotest.c:1.7	Wed Mar  4 14:20:44 2020
+++ src/tests/dev/audio/audiotest.c	Wed Mar 25 13:07:04 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiotest.c,v 1.7 2020/03/04 14:20:44 isaki Exp $	*/
+/*	$NetBSD: audiotest.c,v 1.8 2020/03/25 13:07:04 isaki Exp $	*/
 
 /*
  * Copyright (C) 2019 Tetsuya Isaki. All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: audiotest.c,v 1.7 2020/03/04 14:20:44 isaki Exp $");
+__RCSID("$NetBSD: audiotest.c,v 1.8 2020/03/25 13:07:04 isaki Exp $");
 
 #include 
 #include 
@@ -75,6 +75,7 @@ struct testentry {
 void usage(void) __dead;
 void xp_err(int, int, const char *, ...) __printflike(3, 4) __dead;
 void xp_errx(int, int, const char *, ...) __printflike(3, 4) __dead;
+bool match(const char *, const char *);
 void xxx_close_wait(void);
 int mixer_get_outputs_master(int);
 void do_test(int);
@@ -168,6 +169,7 @@ int skipcount;
 int unit;
 bool use_rump;
 bool use_pad;
+bool exact_match;
 int padfd;
 int maxfd;
 pthread_t th;
@@ -186,6 +188,8 @@ usage(void)
 	fprintf(stderr, "\t-A: make output suitable for ATF\n");
 	fprintf(stderr, "\t-a: Test all\n");
 	fprintf(stderr, "\t-d: Increase debug level\n");
+	fprintf(stderr, "\t-e: Use exact match for testnames "
+	"(default is forward match)\n");
 	fprintf(stderr, "\t-l: List all tests\n");
 	fprintf(stderr, "\t-p: Open pad\n");
 #if !defined(NO_RUMP)
@@ -246,8 +250,9 @@ main(int argc, char *argv[])
 	cmd = CMD_TEST;
 	use_pad = false;
 	padfd = -1;
+	exact_match = false;
 
-	while ((c = getopt(argc, argv, "AadlpRu:")) != -1) {
+	while ((c = getopt(argc, argv, "AadelpRu:")) != -1) {
 		switch (c) {
 		case 'A':
 			opt_atf = true;
@@ -258,6 +263,9 @@ main(int argc, char *argv[])
 		case 'd':
 			debug++;
 			break;
+		case 'e':
+			exact_match = true;
+			break;
 		case 'l':
 			cmd = CMD_LIST;
 			break;
@@ -305,8 +313,7 @@ main(int argc, char *argv[])
 		found = false;
 		for (j = 0; j < argc; j++) {
 			for (i = 0; testtable[i].name != NULL; i++) {
-if (strncmp(argv[j], testtable[i].name,
-strlen(argv[j])) == 0) {
+if (match(argv[j], testtable[i].name)) {
 	do_test(i);
 	found = true;
 }
@@ -337,6 +344,21 @@ main(int argc, char *argv[])
 	return 0;
 }
 
+bool
+match(const char *arg, const char *name)
+{
+	if (exact_match) {
+		/* Exact match */
+		if (strcmp(arg, name) == 0)
+			return true;
+	} else {
+		/* Forward match */
+		if (strncmp(arg, name, strlen(arg)) == 0)
+			return true;
+	}
+	return false;
+}
+
 /*
  * XXX
  * Some hardware drivers (e.g. hdafg(4)) require a little "rest" between

Index: src/tests/dev/audio/t_audio.awk
diff -u src/tests/dev/audio/t_audio.awk:1.1 src/tests/dev/audio/t_audio.awk:1.2
--- src/tests/dev/audio/t_audio.awk:1.1	Tue Feb 11 07:03:16 2020
+++ src/tests/dev/audio/t_audio.awk	Wed Mar 25 13:07:04 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: t_audio.awk,v 1.1 2020/02/11 07:03:16 isaki Exp $
+#	$NetBSD: t_audio.awk,v 1.2 2020/03/25 13:07:04 isaki Exp $
 #
 # Copyright (C) 2019 Tetsuya Isaki. All rights reserved.
 #
@@ -34,7 +34,7 @@ BEGIN {
 	print "h_audio() {"
 	print "	local testname=$1"
 	print "	local outfile=/tmp/t_audio_$testname.$$"
-	print "	$(atf_get_srcdir)/audiotest -AR $testname > $outfile"
+	print "	$(atf_get_srcdir)/audiotest -ARe $testname > $outfile"
 	print "	local retval=$?"
 	print "	# Discard rump outputs..."
 	print "	outmsg=`cat $outfile | grep -v '^\\['`"



CVS commit: src/sys/dev/audio

2020-03-06 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Mar  7 06:27:19 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Fix/Update comments about allocm/freem.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 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.63 src/sys/dev/audio/audio.c:1.64
--- src/sys/dev/audio/audio.c:1.63	Sat Mar  7 06:25:57 2020
+++ src/sys/dev/audio/audio.c	Sat Mar  7 06:27:19 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.63 2020/03/07 06:25:57 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.64 2020/03/07 06:27:19 isaki 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 		-	-	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.63 2020/03/07 06:25:57 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.64 2020/03/07 06:27:19 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -4887,10 +4883,8 @@ audio_mixer_init(struct audio_softc *sc,
 	bufsize);
 	mixer->hwbuf.capacity = capacity;
 
-	/*
-	 * XXX need to release sc_lock for compatibility?
-	 */
 	if (sc->hw_if->allocm) {
+		/* sc_lock is not necessary for allocm */
 		mixer->hwbuf.mem = sc->hw_if->allocm(sc->hw_hdl, mode, bufsize);
 		if (mixer->hwbuf.mem == NULL) {
 			device_printf(sc->sc_dev, "%s: allocm(%zu) failed\n",
@@ -5009,6 +5003,7 @@ audio_mixer_destroy(struct audio_softc *
 
 	if (mixer->hwbuf.mem != NULL) {
 		if (sc->hw_if->freem) {
+			/* sc_lock is not necessary for freem */
 			sc->hw_if->freem(sc->hw_hdl, mixer->hwbuf.mem, bufsize);
 		} else {
 			kmem_free(mixer->hwbuf.mem, bufsize);



CVS commit: src/sys/dev/audio

2020-03-06 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Mar  7 06:25:57 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c audiovar.h

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


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.10 -r1.11 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.62 src/sys/dev/audio/audio.c:1.63
--- src/sys/dev/audio/audio.c:1.62	Wed Mar  4 14:19:41 2020
+++ src/sys/dev/audio/audio.c	Sat Mar  7 06:25:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.62 2020/03/04 14:19:41 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.63 2020/03/07 06:25:57 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.62 2020/03/04 14:19:41 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.63 2020/03/07 06:25:57 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -497,8 +497,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 *);
@@ -898,6 +900,7 @@ audioattach(device_t parent, device_t se
 	sc->hw_hdl = hdlp;
 	sc->hw_dev = parent;
 
+	sc->sc_exlock = 1;
 	sc->sc_blk_ms = AUDIO_BLK_MS;
 	SLIST_INIT(>sc_files);
 	cv_init(>sc_exlockcv, "audiolk");
@@ -981,10 +984,8 @@ audioattach(device_t parent, device_t se
 
 	/* Init hardware. */
 	/* hw_probe() also validates [pr]hwfmt.  */
-	mutex_enter(sc->sc_lock);
 	error = audio_hw_set_format(sc, mode, , , , );
 	if (error) {
-		mutex_exit(sc->sc_lock);
 		aprint_error_dev(self, "audio_hw_set_format failed, "
 		"error = %d\n", error);
 		goto bad;
@@ -995,7 +996,6 @@ audioattach(device_t parent, device_t se
 	 * attach time, we assume a success.
 	 */
 	error = audio_mixers_init(sc, mode, , , , );
-	mutex_exit(sc->sc_lock);
 	if (sc->sc_pmixer == NULL && sc->sc_rmixer == NULL) {
 		aprint_error_dev(self, "audio_mixers_init failed, "
 		"error = %d\n", error);
@@ -1087,11 +1087,13 @@ audioattach(device_t parent, device_t se
 #endif
 
 	audiorescan(self, "audio", NULL);
+	sc->sc_exlock = 0;
 	return;
 
 bad:
 	/* Clearing hw_if means that device is attached but disabled. */
 	sc->hw_if = NULL;
+	sc->sc_exlock = 0;
 	aprint_error_dev(sc->sc_dev, "disabled\n");
 	return;
 }
@@ -1309,6 +1311,7 @@ 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.
@@ -1334,7 +1337,6 @@ audiodetach(device_t self, int flags)
 	pmf_device_deregister(self);
 
 	/* Free resources */
-	mutex_enter(sc->sc_lock);
 	if (sc->sc_pmixer) {
 		audio_mixer_destroy(sc, sc->sc_pmixer);
 		kmem_free(sc->sc_pmixer, sizeof(*sc->sc_pmixer));
@@ -1343,7 +1345,6 @@ audiodetach(device_t self, int flags)
 		audio_mixer_destroy(sc, sc->sc_rmixer);
 		kmem_free(sc->sc_rmixer, sizeof(*sc->sc_rmixer));
 	}
-	mutex_exit(sc->sc_lock);
 	if (sc->sc_am)
 		kern_free(sc->sc_am);
 
@@ -1415,12 +1416,12 @@ audio_attach_mi(const struct audio_hw_if
 }
 
 /*
- * Acquire sc_lock and enter exlock critical section.
- * If successful, it returns 0.  Otherwise returns errno.
+ * 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.
  */
 static int
-audio_enter_exclusive(struct audio_softc *sc)
+audio_exlock_mutex_enter(struct audio_softc *sc)
 {
 	int error;
 
@@ -1446,23 +1447,51 @@ audio_enter_exclusive(struct audio_softc
 }
 
 /*
- * Leave exlock critical section and release sc_lock.
+ * Exit critical section and exit sc_lock.
  * Must be called with sc_lock held.
  */
 static void
-audio_exit_exclusive(struct audio_softc *sc)
+audio_exlock_mutex_exit(struct audio_softc *sc)
 {
 
 	KASSERT(mutex_owned(sc->sc_lock));
-	KASSERT(sc->sc_exlock);
 
-	/* Leave critical section */
 	sc->sc_exlock = 0;
 	cv_broadcast(>sc_exlockcv);
 	mutex_exit(sc->sc_lock);
 }
 
 /*
+ * Enter critical section.
+ * If successful, it returns 0.  Otherwise returns 

CVS commit: src/tests/dev/audio

2020-03-04 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Mar  4 14:20:44 UTC 2020

Modified Files:
src/tests/dev/audio: audiotest.c

Log Message:
Sync with sys/dev/audio/audio.c rev1.62.
> Restore backward compatibility with netbsd-7 audio.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/dev/audio/audiotest.c

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

Modified files:

Index: src/tests/dev/audio/audiotest.c
diff -u src/tests/dev/audio/audiotest.c:1.6 src/tests/dev/audio/audiotest.c:1.7
--- src/tests/dev/audio/audiotest.c:1.6	Sat Feb 22 05:53:19 2020
+++ src/tests/dev/audio/audiotest.c	Wed Mar  4 14:20:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiotest.c,v 1.6 2020/02/22 05:53:19 isaki Exp $	*/
+/*	$NetBSD: audiotest.c,v 1.7 2020/03/04 14:20:44 isaki Exp $	*/
 
 /*
  * Copyright (C) 2019 Tetsuya Isaki. All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: audiotest.c,v 1.6 2020/02/22 05:53:19 isaki Exp $");
+__RCSID("$NetBSD: audiotest.c,v 1.7 2020/03/04 14:20:44 isaki Exp $");
 
 #include 
 #include 
@@ -106,7 +106,6 @@ bool xp_sys_eq(int, int, int, const char
 bool xp_sys_ok(int, int, const char *);
 bool xp_sys_ng(int, int, int, const char *);
 bool xp_sys_ptr(int, int, void *, const char *);
-bool xp_buffsize(int, bool, int, const char *);
 int debug_open(int, const char *, int);
 int debug_write(int, int, const void *, size_t);
 int debug_read(int, int, void *, size_t);
@@ -920,29 +919,6 @@ bool xp_sys_ptr(int line, int exp, void 
 	return r;
 }
 
-/*
- * Check ai.*.buffer_size.
- * If exp == true, it expects that buffer_size is non-zero.
- * If exp == false, it expects that buffer_size is zero.
- */
-#define XP_BUFFSIZE(exp, act)	\
-	xp_buffsize(__LINE__, exp, act, #act)
-bool xp_buffsize(int line, bool exp, int act, const char *varname)
-{
-	bool r = true;
-
-	testcount++;
-	if (exp) {
-		if (act == 0)
-			r = xp_fail(line, "%s expects non-zero but %d",
-			varname, act);
-	} else {
-		if (act != 0)
-			r = xp_fail(line, "%s expects zero but %d",
-			varname, act);
-	}
-	return r;
-}
 
 /*
  * REQUIRED_* return immediately if condition does not meet.
@@ -1377,9 +1353,7 @@ mixer_get_outputs_master(int mixerfd)
  */
 
 void test_open_mode(int);
-void test_open_audio(int);
-void test_open_sound(int);
-void test_open_audioctl(int);
+void test_open(const char *, int);
 void test_open_simul(int, int);
 void try_open_multiuser(bool);
 void test_open_multiuser(bool);
@@ -1435,248 +1409,89 @@ DEF(open_mode_RDONLY)	{ test_open_mode(O
 DEF(open_mode_WRONLY)	{ test_open_mode(O_WRONLY); }
 DEF(open_mode_RDWR)	{ test_open_mode(O_RDWR);   }
 
-
 /*
- * The initial parameters are always the same whenever you open /dev/audio.
+ * Check the initial parameters and stickiness.
+ * /dev/audio
+ *	The initial parameters are always the same whenever you open.
+ * /dev/sound and /dev/audioctl
+ *	The initial parameters are inherited from the last /dev/sound or
+ *	/dev/audio.
  */
 void
-test_open_audio(int mode)
+test_open(const char *devname, int mode)
 {
 	struct audio_info ai;
 	struct audio_info ai0;
+	char devfile[16];
 	int fd;
 	int r;
 	int can_play;
 	int can_rec;
-	bool pbuff;
-	bool rbuff;
+	int exp_mode;
+	int exp_encoding;
+	int exp_precision;
+	int exp_channels;
+	int exp_sample_rate;
+	int exp_pause;
+	int exp_popen;
+	int exp_ropen;
 
-	TEST("open_audio_%s", openmode_str[mode] + 2);
+	TEST("open_%s_%s", devname, openmode_str[mode] + 2);
 
+	snprintf(devfile, sizeof(devfile), "/dev/%s%d", devname, unit);
 	can_play = mode2play(mode);
 	can_rec  = mode2rec(mode);
-	if (can_play + can_rec == 0) {
-		/* Check whether it cannot be opened */
-		fd = OPEN(devaudio, mode);
-		XP_SYS_NG(ENXIO, fd);
-		return;
+	if (strcmp(devname, "audioctl") != 0) {
+		if (can_play + can_rec == 0) {
+			/* Check whether it cannot be opened */
+			fd = OPEN(devaudio, mode);
+			XP_SYS_NG(ENXIO, fd);
+			return;
+		}
 	}
 
-	/*
-	 * NetBSD7,8 always has both buffers for playback and recording.
-	 * NetBSD9 only has necessary buffers.
-	 */
-	if (netbsd < 9) {
-		pbuff = true;
-		rbuff = true;
+	/* /dev/audio is always initialized */
+	if (strcmp(devname, "audio") == 0) {
+		exp_encoding = AUDIO_ENCODING_ULAW;
+		exp_precision = 8;
+		exp_channels = 1;
+		exp_sample_rate = 8000;
+		exp_pause = 0;
 	} else {
-		pbuff = can_play;
-		rbuff = can_rec;
+		exp_encoding = AUDIO_ENCODING_SLINEAR_LE;
+		exp_precision = 16;
+		exp_channels = 2;
+		exp_sample_rate = 11025;
+		exp_pause = 1;
 	}
 
-	/*
-	 * Open /dev/audio and check parameters
-	 */
-	fd = OPEN(devaudio, mode);
-	REQUIRED_SYS_OK(fd);
-	memset(, 0, sizeof(ai));
-	r = IOCTL(fd, AUDIO_GETBUFINFO, , "");
-	REQUIRED_SYS_EQ(0, r);
-
-	XP_NE(0, ai.blocksize);
-		/* hiwat/lowat */
-	XP_EQ(mode2aumode(mode), ai.mode);
-	/* ai.play */
-	XP_EQ(8000, ai.p

CVS commit: src/sys/dev/audio

2020-03-04 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Mar  4 14:19:41 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
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.61 -r1.62 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.61 src/sys/dev/audio/audio.c:1.62
--- src/sys/dev/audio/audio.c:1.61	Sun Mar  1 07:42:07 2020
+++ src/sys/dev/audio/audio.c	Wed Mar  4 14:19:41 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.61 2020/03/01 07:42:07 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.62 2020/03/04 14:19:41 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.61 2020/03/01 07:42:07 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.62 2020/03/04 14:19:41 isaki 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 *,
@@ -6745,20 +6745,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)) {
 		/*
@@ -6777,39 +6787,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)
-			TRACET(1, ptrack, "check play.params failed: "
-			"%s %ubit %uch %uHz",
-			audio_encoding_name(pi->encoding),
-			pi->precision,
-			pi->channels,
-			pi->sample_rate);
+		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)
-			TRACET(1, rtrack, "check record.params failed: "
-			"%s %ubit %uch %uHz",
-			audio_encoding_name(ri->encoding),
-			ri->precision,
-			ri->channels,
-			ri->sample_rate);
+		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;
 	}
 
 	/*
@@ -6819,16 +6825,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 (ptrack) {
+snprintf(nbuf, sizeof(nbuf), "%d", ptrack->id);
+			} else {
+snprintf(nbuf, sizeof(nbuf), "-");
+			}
 			audio_format2_tostr(fmtbuf, sizeof(fmtbuf), 

CVS commit: src/tests/dev/audio

2020-03-01 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Mon Mar  2 04:25:08 UTC 2020

Modified Files:
src/tests/dev/audio: Makefile

Log Message:
Re-add -lrumpdev dropped in the previous commit.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/dev/audio/Makefile

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

Modified files:

Index: src/tests/dev/audio/Makefile
diff -u src/tests/dev/audio/Makefile:1.8 src/tests/dev/audio/Makefile:1.9
--- src/tests/dev/audio/Makefile:1.8	Sun Mar  1 18:08:12 2020
+++ src/tests/dev/audio/Makefile	Mon Mar  2 04:25:08 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.8 2020/03/01 18:08:12 christos Exp $
+#	$NetBSD: Makefile,v 1.9 2020/03/02 04:25:08 isaki Exp $
 #
 
 .include 
@@ -21,7 +21,7 @@ BINDIR=		${TESTSDIR}
 MKMAN=no
 
 CPPFLAGS+=	-D_KERNTYPES
-LDADD+=	-lrumpdev_pad -lrumpdev_audio ${LIBRUMPBASE}
+LDADD+=	-lrumpdev_pad -lrumpdev_audio -lrumpdev ${LIBRUMPBASE}
 
 WARNS=	4
 NOMAN=



CVS commit: src/sys/dev/audio

2020-02-29 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Mar  1 07:42:08 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Improve an error message about round_blocksize.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 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.60 src/sys/dev/audio/audio.c:1.61
--- src/sys/dev/audio/audio.c:1.60	Sun Mar  1 07:40:03 2020
+++ src/sys/dev/audio/audio.c	Sun Mar  1 07:42:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.60 2020/03/01 07:40:03 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.61 2020/03/01 07:42:07 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.60 2020/03/01 07:40:03 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.61 2020/03/01 07:42:07 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -4777,8 +4777,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 */



CVS commit: src/sys/dev/audio

2020-02-29 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Mar  1 07:40:04 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Fix wrong parameter displayed in debug messages.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 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.59 src/sys/dev/audio/audio.c:1.60
--- src/sys/dev/audio/audio.c:1.59	Sun Mar  1 07:35:33 2020
+++ src/sys/dev/audio/audio.c	Sun Mar  1 07:40:03 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.59 2020/03/01 07:35:33 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.60 2020/03/01 07:40:03 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.59 2020/03/01 07:35:33 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.60 2020/03/01 07:40:03 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -6777,10 +6777,12 @@ audio_file_setinfo(struct audio_softc *s
 		>sc_pmixer->hwbuf.fmt);
 		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);
+			TRACET(1, ptrack, "check play.params failed: "
+			"%s %ubit %uch %uHz",
+			audio_encoding_name(pi->encoding),
+			pi->precision,
+			pi->channels,
+			pi->sample_rate);
 #endif
 			return EINVAL;
 		}
@@ -6792,10 +6794,12 @@ audio_file_setinfo(struct audio_softc *s
 		>sc_rmixer->hwbuf.fmt);
 		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);
+			TRACET(1, rtrack, "check record.params failed: "
+			"%s %ubit %uch %uHz",
+			audio_encoding_name(ri->encoding),
+			ri->precision,
+			ri->channels,
+			ri->sample_rate);
 #endif
 			return EINVAL;
 		}



CVS commit: src/sys/dev/audio

2020-02-29 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Mar  1 07:35:33 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Reinitialize the sticky parameters whenever the hardware format is changed.
When the number of the hardware channels becomes less than the number of
channels that sticky parameters remember, subsequent open("/dev/sound") will
fail without this treatment.  This is for rev 1.43.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 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.58 src/sys/dev/audio/audio.c:1.59
--- src/sys/dev/audio/audio.c:1.58	Sat Feb 29 09:38:10 2020
+++ src/sys/dev/audio/audio.c	Sun Mar  1 07:35:33 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.58 2020/02/29 09:38:10 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.59 2020/03/01 07:35:33 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.58 2020/02/29 09:38:10 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.59 2020/03/01 07:35:33 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -6507,6 +6507,18 @@ audio_mixers_set_format(struct audio_sof
 	if (error)
 		return error;
 
+	/*
+	 * Reinitialize the sticky parameters for /dev/sound.
+	 * If the number of the hardware channels becomes less than the number
+	 * of channels that sticky parameters remember, subsequent /dev/sound
+	 * open will fail.  To prevent this, reinitialize the sticky
+	 * parameters whenever the hardware format is changed.
+	 */
+	sc->sc_sound_pparams = params_to_format2(_default);
+	sc->sc_sound_rparams = params_to_format2(_default);
+	sc->sc_sound_ppause = false;
+	sc->sc_sound_rpause = false;
+
 	return 0;
 }
 



CVS commit: src/sys/dev/audio

2020-02-29 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb 29 09:38:10 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
Minor fix.  audio_prinfo.pause is u_char, not bool.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 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.57 src/sys/dev/audio/audio.c:1.58
--- src/sys/dev/audio/audio.c:1.57	Sat Feb 29 07:13:37 2020
+++ src/sys/dev/audio/audio.c	Sat Feb 29 09:38:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.57 2020/02/29 07:13:37 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.58 2020/02/29 09:38:10 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.57 2020/02/29 07:13:37 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.58 2020/02/29 09:38:10 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2086,19 +2086,19 @@ audio_open(dev_t dev, struct audio_softc
 		ai.play.encoding  = AUDIO_ENCODING_SLINEAR_NE;
 		ai.play.channels  = 1;
 		ai.play.precision = 16;
-		ai.play.pause = false;
+		ai.play.pause = 0;
 	} else if (ISDEVAUDIO(dev)) {
 		/* If /dev/audio, initialize everytime. */
 		ai.play.sample_rate   = audio_default.sample_rate;
 		ai.play.encoding  = audio_default.encoding;
 		ai.play.channels  = audio_default.channels;
 		ai.play.precision = audio_default.precision;
-		ai.play.pause = false;
+		ai.play.pause = 0;
 		ai.record.sample_rate = audio_default.sample_rate;
 		ai.record.encoding= audio_default.encoding;
 		ai.record.channels= audio_default.channels;
 		ai.record.precision   = audio_default.precision;
-		ai.record.pause   = false;
+		ai.record.pause   = 0;
 	} else {
 		/* If /dev/sound, take over the previous parameters. */
 		ai.play.sample_rate   = sc->sc_sound_pparams.sample_rate;



CVS commit: src/sys/dev/audio

2020-02-28 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb 29 07:13:37 UTC 2020

Modified Files:
src/sys/dev/audio: audio.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 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.56 src/sys/dev/audio/audio.c:1.57
--- src/sys/dev/audio/audio.c:1.56	Sun Feb 23 07:17:01 2020
+++ src/sys/dev/audio/audio.c	Sat Feb 29 07:13:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.56 2020/02/23 07:17:01 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.57 2020/02/29 07:13:37 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.56 2020/02/23 07:17:01 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.57 2020/02/29 07:13:37 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -1956,6 +1956,11 @@ audiobellclose(audio_file_t *file)
 	error = audio_close(sc, file);
 
 	audio_file_exit(sc, _ref);
+
+	KASSERT(file->ptrack);
+	audio_track_destroy(file->ptrack);
+	KASSERT(file->rtrack == NULL);
+	kmem_free(file, sizeof(*file));
 	return error;
 }
 



CVS commit: src/sys/dev/pci

2020-02-28 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb 29 06:34:30 UTC 2020

Modified Files:
src/sys/dev/pci: auacer.c auich.c auixp.c

Log Message:
round_blocksize must return a multiple of the framesize
even if 6 channels mode.
I believe that keeping "good alignment" is just a wish, not constraint.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/dev/pci/auacer.c
cvs rdiff -u -r1.158 -r1.159 src/sys/dev/pci/auich.c
cvs rdiff -u -r1.48 -r1.49 src/sys/dev/pci/auixp.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/pci/auacer.c
diff -u src/sys/dev/pci/auacer.c:1.38 src/sys/dev/pci/auacer.c:1.39
--- src/sys/dev/pci/auacer.c:1.38	Sat Jun  8 08:02:38 2019
+++ src/sys/dev/pci/auacer.c	Sat Feb 29 06:34:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: auacer.c,v 1.38 2019/06/08 08:02:38 isaki Exp $	*/
+/*	$NetBSD: auacer.c,v 1.39 2020/02/29 06:34:30 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2004, 2008 The NetBSD Foundation, Inc.
@@ -44,7 +44,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: auacer.c,v 1.38 2019/06/08 08:02:38 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: auacer.c,v 1.39 2020/02/29 06:34:30 isaki Exp $");
 
 #include 
 #include 
@@ -154,8 +154,6 @@ static int	auacer_query_format(void *, a
 static int	auacer_set_format(void *, int,
  const audio_params_t *, const audio_params_t *,
  audio_filter_reg_t *, audio_filter_reg_t *);
-static int	auacer_round_blocksize(void *, int, int,
-   const audio_params_t *);
 static int	auacer_halt_output(void *);
 static int	auacer_halt_input(void *);
 static int	auacer_getdev(void *, struct audio_device *);
@@ -188,7 +186,6 @@ static void auacer_reset(struct auacer_s
 static const struct audio_hw_if auacer_hw_if = {
 	.query_format		= auacer_query_format,
 	.set_format		= auacer_set_format,
-	.round_blocksize	= auacer_round_blocksize,
 	.halt_output		= auacer_halt_output,
 	.halt_input		= auacer_halt_input,
 	.getdev			= auacer_getdev,
@@ -562,14 +559,6 @@ auacer_set_format(void *v, int setmode,
 	return 0;
 }
 
-static int
-auacer_round_blocksize(void *v, int blk, int mode,
-const audio_params_t *param)
-{
-
-	return blk & ~0x3f;		/* keep good alignment */
-}
-
 static void
 auacer_halt(struct auacer_softc *sc, struct auacer_chan *chan)
 {

Index: src/sys/dev/pci/auich.c
diff -u src/sys/dev/pci/auich.c:1.158 src/sys/dev/pci/auich.c:1.159
--- src/sys/dev/pci/auich.c:1.158	Fri Dec  6 07:27:07 2019
+++ src/sys/dev/pci/auich.c	Sat Feb 29 06:34:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: auich.c,v 1.158 2019/12/06 07:27:07 maxv Exp $	*/
+/*	$NetBSD: auich.c,v 1.159 2020/02/29 06:34:30 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2004, 2005, 2008 The NetBSD Foundation, Inc.
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: auich.c,v 1.158 2019/12/06 07:27:07 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: auich.c,v 1.159 2020/02/29 06:34:30 isaki Exp $");
 
 #include 
 #include 
@@ -259,7 +259,6 @@ static int	auich_query_format(void *, st
 static int	auich_set_format(void *, int,
 		const audio_params_t *, const audio_params_t *,
 		audio_filter_reg_t *, audio_filter_reg_t *);
-static int	auich_round_blocksize(void *, int, int, const audio_params_t *);
 static void	auich_halt_pipe(struct auich_softc *, int);
 static int	auich_halt_output(void *);
 static int	auich_halt_input(void *);
@@ -304,7 +303,6 @@ static const struct audio_hw_if auich_hw
 	.close			= auich_close,
 	.query_format		= auich_query_format,
 	.set_format		= auich_set_format,
-	.round_blocksize	= auich_round_blocksize,
 	.halt_output		= auich_halt_output,
 	.halt_input		= auich_halt_input,
 	.getdev			= auich_getdev,
@@ -1053,17 +1051,6 @@ auich_set_format(void *v, int setmode,
 	return 0;
 }
 
-static int
-auich_round_blocksize(void *v, int blk, int mode,
-const audio_params_t *param)
-{
-
-	if (blk < 0x40)
-		return 0x40;		/* avoid 0 block size */
-
-	return blk & ~0x3f;		/* keep good alignment */
-}
-
 static void
 auich_halt_pipe(struct auich_softc *sc, int pipe)
 {

Index: src/sys/dev/pci/auixp.c
diff -u src/sys/dev/pci/auixp.c:1.48 src/sys/dev/pci/auixp.c:1.49
--- src/sys/dev/pci/auixp.c:1.48	Wed Oct 16 21:52:22 2019
+++ src/sys/dev/pci/auixp.c	Sat Feb 29 06:34:30 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: auixp.c,v 1.48 2019/10/16 21:52:22 maya Exp $ */
+/* $NetBSD: auixp.c,v 1.49 2020/02/29 06:34:30 isaki Exp $ */
 
 /*
  * Copyright (c) 2004, 2005 Reinoud Zandijk 
@@ -43,7 +43,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: auixp.c,v 1.48 2019/10/16 21:52:22 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: auixp.c,v 1.49 2020/02/29 06:34:30 isaki Exp $");
 
 #include 
 #include 
@@ -422,16 +422,13 @@ static int
 auixp_round_blocksize(void *hdl, int bs, int mode,
 const audio_params_t *param)
 {
-	uint32_t new_bs;
 
-	new_bs = bs;
-	/* Be conservative; align to 32 bytes and maximise it to 64 kb */
 	/* 256 kb possible */
-	if (new_bs > 

CVS commit: src/sys/dev/pci

2020-02-28 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb 29 06:25:33 UTC 2020

Modified Files:
src/sys/dev/pci: gcscaudio.c

Log Message:
round_blocksize must return a multiple of the framesize.
It's not divisible when blk=GCSCAUDI_PRD_SIZE_MAX and channels=4.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/pci/gcscaudio.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/pci/gcscaudio.c
diff -u src/sys/dev/pci/gcscaudio.c:1.18 src/sys/dev/pci/gcscaudio.c:1.19
--- src/sys/dev/pci/gcscaudio.c:1.18	Sat Jun  8 08:02:38 2019
+++ src/sys/dev/pci/gcscaudio.c	Sat Feb 29 06:25:33 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: gcscaudio.c,v 1.18 2019/06/08 08:02:38 isaki Exp $	*/
+/*	$NetBSD: gcscaudio.c,v 1.19 2020/02/29 06:25:33 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 SHIMIZU Ryo 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gcscaudio.c,v 1.18 2019/06/08 08:02:38 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gcscaudio.c,v 1.19 2020/02/29 06:25:33 isaki Exp $");
 
 #include 
 #include 
@@ -549,9 +549,10 @@ static int
 gcscaudio_round_blocksize(void *arg, int blk, int mode,
   const audio_params_t *param)
 {
-	blk &= -4;
+
 	if (blk > GCSCAUDIO_PRD_SIZE_MAX)
 		blk = GCSCAUDIO_PRD_SIZE_MAX;
+	blk = rounddown(blk, param->channels * param->precision / NBBY);
 
 	return blk;
 }



CVS commit: src/sys/dev/sbus

2020-02-28 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb 29 06:06:29 UTC 2020

Modified Files:
src/sys/dev/sbus: dbri.c

Log Message:
round_blocksize must return a multiple of the framesize
even if passed blocksize is greater than the upper limit.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/dev/sbus/dbri.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/sbus/dbri.c
diff -u src/sys/dev/sbus/dbri.c:1.41 src/sys/dev/sbus/dbri.c:1.42
--- src/sys/dev/sbus/dbri.c:1.41	Sat Jun  8 08:02:38 2019
+++ src/sys/dev/sbus/dbri.c	Sat Feb 29 06:06:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dbri.c,v 1.41 2019/06/08 08:02:38 isaki Exp $	*/
+/*	$NetBSD: dbri.c,v 1.42 2020/02/29 06:06:29 isaki Exp $	*/
 
 /*
  * Copyright (C) 1997 Rudolf Koenig (rfkoe...@immd4.informatik.uni-erlangen.de)
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dbri.c,v 1.41 2019/06/08 08:02:38 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dbri.c,v 1.42 2020/02/29 06:06:29 isaki Exp $");
 
 #include "audio.h"
 #if NAUDIO > 0
@@ -1636,8 +1636,8 @@ dbri_round_blocksize(void *hdl, int bs, 
 			const audio_params_t *param)
 {
 
-	if (bs > 0x1fff)
-		return 0x1fff;
+	if (bs > 0x1ffc)
+		return 0x1ffc;
 	return bs;
 }
 



CVS commit: src/sys/arch/amiga/dev

2020-02-28 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb 29 06:03:55 UTC 2020

Modified Files:
src/sys/arch/amiga/dev: aucc.c

Log Message:
round_blocksize must return a multiple of the framesize.
aucc(4) supports 3 channels mode.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/amiga/dev/aucc.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/arch/amiga/dev/aucc.c
diff -u src/sys/arch/amiga/dev/aucc.c:1.47 src/sys/arch/amiga/dev/aucc.c:1.48
--- src/sys/arch/amiga/dev/aucc.c:1.47	Sat Sep  7 11:57:08 2019
+++ src/sys/arch/amiga/dev/aucc.c	Sat Feb 29 06:03:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: aucc.c,v 1.47 2019/09/07 11:57:08 rin Exp $ */
+/*	$NetBSD: aucc.c,v 1.48 2020/02/29 06:03:55 isaki Exp $ */
 
 /*
  * Copyright (c) 1999 Bernardo Innocenti
@@ -46,7 +46,7 @@
 #if NAUCC > 0
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: aucc.c,v 1.47 2019/09/07 11:57:08 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: aucc.c,v 1.48 2020/02/29 06:03:55 isaki Exp $");
 
 #include 
 #include 
@@ -404,8 +404,11 @@ aucc_round_blocksize(void *addr, int blk
 		 int mode, const audio_params_t *param)
 {
 
-	/* round up to even size */
-	return blk > AUDIO_BUF_SIZE ? AUDIO_BUF_SIZE : blk;
+	if (blk > AUDIO_BUF_SIZE)
+		blk = AUDIO_BUF_SIZE;
+
+	blk = rounddown(blk, param->channels * param->precision / NBBY);
+	return blk;
 }
 
 int



CVS commit: src/sys

2020-02-28 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb 29 05:51:11 UTC 2020

Modified Files:
src/sys/arch/amiga/dev: toccata.c
src/sys/arch/arm/rockchip: rk_i2s.c
src/sys/arch/arm/sunxi: sunxi_codec.c sunxi_i2s.c
src/sys/arch/evbarm/mini2440: audio_mini2440.c
src/sys/arch/prep/isa: paud_isa.c
src/sys/dev/ic: ad1848.c ad1848var.h interwave.c interwavevar.h pl041.c
src/sys/dev/isa: gus.c wss.c ym.c
src/sys/dev/isapnp: gus_isapnp.c
src/sys/dev/pci: autri.c cmpci.c yds.c

Log Message:
Remove rounding by 4 bytes on round_blocksize().
For drivers which supports only 16bit * 2channels sampling,
rounding by 4 bytes no longer meaningful.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/amiga/dev/toccata.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/rockchip/rk_i2s.c
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/arm/sunxi/sunxi_codec.c \
src/sys/arch/arm/sunxi/sunxi_i2s.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/evbarm/mini2440/audio_mini2440.c
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/prep/isa/paud_isa.c
cvs rdiff -u -r1.32 -r1.33 src/sys/dev/ic/ad1848.c
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/ic/ad1848var.h \
src/sys/dev/ic/interwavevar.h
cvs rdiff -u -r1.42 -r1.43 src/sys/dev/ic/interwave.c
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/ic/pl041.c
cvs rdiff -u -r1.117 -r1.118 src/sys/dev/isa/gus.c
cvs rdiff -u -r1.73 -r1.74 src/sys/dev/isa/wss.c
cvs rdiff -u -r1.46 -r1.47 src/sys/dev/isa/ym.c
cvs rdiff -u -r1.40 -r1.41 src/sys/dev/isapnp/gus_isapnp.c
cvs rdiff -u -r1.58 -r1.59 src/sys/dev/pci/autri.c
cvs rdiff -u -r1.56 -r1.57 src/sys/dev/pci/cmpci.c
cvs rdiff -u -r1.64 -r1.65 src/sys/dev/pci/yds.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/arch/amiga/dev/toccata.c
diff -u src/sys/arch/amiga/dev/toccata.c:1.20 src/sys/arch/amiga/dev/toccata.c:1.21
--- src/sys/arch/amiga/dev/toccata.c:1.20	Sat Jun  8 08:02:36 2019
+++ src/sys/arch/amiga/dev/toccata.c	Sat Feb 29 05:51:10 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: toccata.c,v 1.20 2019/06/08 08:02:36 isaki Exp $ */
+/* $NetBSD: toccata.c,v 1.21 2020/02/29 05:51:10 isaki Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2001, 2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: toccata.c,v 1.20 2019/06/08 08:02:36 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: toccata.c,v 1.21 2020/02/29 05:51:10 isaki Exp $");
 
 #include 
 #include 
@@ -415,11 +415,10 @@ int
 toccata_round_blocksize(void *addr, int blk,
 			int mode, const audio_params_t *param)
 {
-	int ret;
 
-	ret = blk > 512 ? 512 : (blk & -4);
-
-	return ret;
+	if (blk > 512)
+		blk = 512;
+	return blk;
 }
 
 size_t

Index: src/sys/arch/arm/rockchip/rk_i2s.c
diff -u src/sys/arch/arm/rockchip/rk_i2s.c:1.2 src/sys/arch/arm/rockchip/rk_i2s.c:1.3
--- src/sys/arch/arm/rockchip/rk_i2s.c:1.2	Sat Jan  4 13:54:04 2020
+++ src/sys/arch/arm/rockchip/rk_i2s.c	Sat Feb 29 05:51:10 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: rk_i2s.c,v 1.2 2020/01/04 13:54:04 jmcneill Exp $ */
+/* $NetBSD: rk_i2s.c,v 1.3 2020/02/29 05:51:10 isaki Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rk_i2s.c,v 1.2 2020/01/04 13:54:04 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rk_i2s.c,v 1.3 2020/02/29 05:51:10 isaki Exp $");
 
 #include 
 #include 
@@ -231,16 +231,6 @@ rk_i2s_get_props(void *priv)
 	AUDIO_PROP_FULLDUPLEX;
 }
 
-static int
-rk_i2s_round_blocksize(void *priv, int bs, int mode,
-const audio_params_t *params)
-{
-	bs &= ~3;
-	if (bs == 0)
-		bs = 4;
-	return bs;
-}
-
 static void *
 rk_i2s_allocm(void *priv, int dir, size_t size)
 {
@@ -360,7 +350,6 @@ static const struct audio_hw_if rk_i2s_h
 	.query_format = rk_i2s_query_format,
 	.set_format = rk_i2s_set_format,
 	.get_props = rk_i2s_get_props,
-	.round_blocksize = rk_i2s_round_blocksize,
 	.allocm = rk_i2s_allocm,
 	.freem = rk_i2s_freem,
 	.trigger_output = rk_i2s_trigger_output,

Index: src/sys/arch/arm/sunxi/sunxi_codec.c
diff -u src/sys/arch/arm/sunxi/sunxi_codec.c:1.7 src/sys/arch/arm/sunxi/sunxi_codec.c:1.8
--- src/sys/arch/arm/sunxi/sunxi_codec.c:1.7	Sat Jun  8 08:02:37 2019
+++ src/sys/arch/arm/sunxi/sunxi_codec.c	Sat Feb 29 05:51:10 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_codec.c,v 1.7 2019/06/08 08:02:37 isaki Exp $ */
+/* $NetBSD: sunxi_codec.c,v 1.8 2020/02/29 05:51:10 isaki Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_ddb.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_codec.c,v 1.7 2019/06/08 08:02:37 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_codec.c,v 1.8 2020/02/29 05:51:10 isaki Exp $");
 
 #include 
 #include 
@@ -261,16 +261,6 @@ sunxi_codec_get_props(void *priv)
 }
 
 static int
-sunxi_codec_round_blocksize(void *priv, int bs, int mode,
-const audio_params_t *params)
-{
-	bs &= ~3;
-	if (bs == 0)
-		bs = 4;

CVS commit: src/share/man/man9

2020-02-28 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb 29 05:39:03 UTC 2020

Modified Files:
src/share/man/man9: audio.9

Log Message:
Describe about (existing) constraints on round_blocksize().


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/share/man/man9/audio.9

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

Modified files:

Index: src/share/man/man9/audio.9
diff -u src/share/man/man9/audio.9:1.57 src/share/man/man9/audio.9:1.58
--- src/share/man/man9/audio.9:1.57	Sun Feb 23 04:02:45 2020
+++ src/share/man/man9/audio.9	Sat Feb 29 05:39:03 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: audio.9,v 1.57 2020/02/23 04:02:45 isaki Exp $
+.\"	$NetBSD: audio.9,v 1.58 2020/02/29 05:39:03 isaki Exp $
 .\"
 .\" Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -344,8 +344,12 @@ or
 and
 .Va param ,
 encoding parameters for the hardware.
+.Va bs
+passed is always non-zero and a multiple of the frame size represented by
+param->channels * param->precision / 8.
 It should return a block size, possibly changed according to the needs
 of the hardware driver.
+The return value also must be non-zero and a multiple of the frame size.
 It is called in the Attach or Closed phases.
 .It Dv int commit_settings(void *hdl)
 optional, is called after all calls to



CVS commit: src/sys/dev/pci

2020-02-28 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Fri Feb 28 13:31:03 UTC 2020

Modified Files:
src/sys/dev/pci: auvia.c

Log Message:
Drop 512 bytes limit on auvia_round_blocksize().
This fixes attach on 6 channels device.
PR kern/55017.


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 src/sys/dev/pci/auvia.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/pci/auvia.c
diff -u src/sys/dev/pci/auvia.c:1.84 src/sys/dev/pci/auvia.c:1.85
--- src/sys/dev/pci/auvia.c:1.84	Sat Jun  8 08:02:38 2019
+++ src/sys/dev/pci/auvia.c	Fri Feb 28 13:31:03 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: auvia.c,v 1.84 2019/06/08 08:02:38 isaki Exp $	*/
+/*	$NetBSD: auvia.c,v 1.85 2020/02/28 13:31:03 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2008 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: auvia.c,v 1.84 2019/06/08 08:02:38 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: auvia.c,v 1.85 2020/02/28 13:31:03 isaki Exp $");
 
 #include 
 #include 
@@ -749,8 +749,7 @@ auvia_round_blocksize(void *addr, int bl
 	if (sc->sc_flags & AUVIA_FLAGS_VT8233 && blk < 288)
 		blk = 288;
 
-	/* Avoid too many dma_ops. */
-	return uimin((blk & -32), AUVIA_MINBLKSZ);
+	return (blk & -32);
 }
 
 static int



CVS commit: src/sys/dev/audio

2020-02-22 Thread Tetsuya Isaki
ters. */
-	/* XXX what should I do when an error occurs? */
-	error = audio_enter_exclusive(sc);
-	if (error)
-		return error;
+	device_active(sc->sc_dev, DVA_SYSTEM);
+
+	mutex_enter(sc->sc_intr_lock);
+	SLIST_REMOVE(>sc_files, file, audio_file, entry);
+	mutex_exit(sc->sc_intr_lock);
 
 	if (file->ptrack) {
+		TRACET(3, file->ptrack, "dropframes=%" PRIu64,
+		file->ptrack->dropframes);
+
+		KASSERT(sc->sc_popens > 0);
+		sc->sc_popens--;
+
 		/* Call hw halt_output if this is the last playback track. */
-		if (sc->sc_popens == 1 && sc->sc_pbusy) {
+		if (sc->sc_popens == 0 && sc->sc_pbusy) {
 			error = audio_pmixer_halt(sc);
 			if (error) {
 device_printf(sc->sc_dev,
-"halt_output failed with %d\n", error);
+"halt_output failed with %d (ignored)\n",
+error);
 			}
 		}
 
-		/* Destroy the track. */
-		oldtrack = file->ptrack;
-		mutex_enter(sc->sc_intr_lock);
-		file->ptrack = NULL;
-		mutex_exit(sc->sc_intr_lock);
-		TRACET(3, oldtrack, "dropframes=%" PRIu64,
-		oldtrack->dropframes);
-		audio_track_destroy(oldtrack);
-
-		KASSERT(sc->sc_popens > 0);
-		sc->sc_popens--;
-
 		/* Restore mixing volume if all tracks are gone. */
 		if (sc->sc_popens == 0) {
+			/* intr_lock is not necessary, but just manners. */
 			mutex_enter(sc->sc_intr_lock);
 			sc->sc_pmixer->volume = 256;
 			sc->sc_pmixer->voltimer = 0;
@@ -2189,26 +2350,22 @@ audio_close(struct audio_softc *sc, audi
 		}
 	}
 	if (file->rtrack) {
+		TRACET(3, file->rtrack, "dropframes=%" PRIu64,
+		file->rtrack->dropframes);
+
+		KASSERT(sc->sc_ropens > 0);
+		sc->sc_ropens--;
+
 		/* Call hw halt_input if this is the last recording track. */
-		if (sc->sc_ropens == 1 && sc->sc_rbusy) {
+		if (sc->sc_ropens == 0 && sc->sc_rbusy) {
 			error = audio_rmixer_halt(sc);
 			if (error) {
 device_printf(sc->sc_dev,
-"halt_input failed with %d\n", error);
+"halt_input failed with %d (ignored)\n",
+error);
 			}
 		}
 
-		/* Destroy the track. */
-		oldtrack = file->rtrack;
-		mutex_enter(sc->sc_intr_lock);
-		file->rtrack = NULL;
-		mutex_exit(sc->sc_intr_lock);
-		TRACET(3, oldtrack, "dropframes=%" PRIu64,
-		oldtrack->dropframes);
-		audio_track_destroy(oldtrack);
-
-		KASSERT(sc->sc_ropens > 0);
-		sc->sc_ropens--;
 	}
 
 	/* Call hw close if this is the last track. */
@@ -2223,14 +2380,9 @@ audio_close(struct audio_softc *sc, audi
 		kauth_cred_free(sc->sc_cred);
 	}
 
-	mutex_enter(sc->sc_intr_lock);
-	SLIST_REMOVE(>sc_files, file, audio_file, entry);
-	mutex_exit(sc->sc_intr_lock);
-
 	TRACE(3, "done");
 	audio_exit_exclusive(sc);
 
-	kmem_free(file, sizeof(*file));
 	return 0;
 }
 
@@ -3092,14 +3244,6 @@ 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.
@@ -7693,7 +7837,6 @@ mixer_close(struct audio_softc *sc, audi
 	mixer_async_remove(sc, curproc->p_pid);
 	mutex_exit(sc->sc_lock);
 
-	kmem_free(file, sizeof(*file));
 	return 0;
 }
 
@@ -8445,9 +8588,11 @@ audio_modcmd(modcmd_t cmd, void *arg)
 {
 	int error = 0;
 
-#ifdef _MODULE
 	switch (cmd) {
 	case MODULE_CMD_INIT:
+		/* XXX interrupt level? */
+		audio_psref_class = psref_class_create("audio", IPL_SOFTSERIAL);
+#ifdef _MODULE
 		error = devsw_attach(audio_cd.cd_name, NULL, _bmajor,
 		_cdevsw, _cmajor);
 		if (error)
@@ -8458,20 +8603,23 @@ audio_modcmd(modcmd_t cmd, void *arg)
 		if (error) {
 			devsw_detach(NULL, _cdevsw);
 		}
+#endif
 		break;
 	case MODULE_CMD_FINI:
+#ifdef _MODULE
 		devsw_detach(NULL, _cdevsw);
 		error = config_fini_component(cfdriver_ioconf_audio,
 		   cfattach_ioconf_audio, cfdata_ioconf_audio);
 		if (error)
 			devsw_attach(audio_cd.cd_name, NULL, _bmajor,
 			_cdevsw, _cmajor);
+#endif
+		psref_class_destroy(audio_psref_class);
 		break;
 	default:
 		error = ENOTTY;
 		break;
 	}
-#endif
 
 	return error;
 }

Index: src/sys/dev/audio/audiodef.h
diff -u src/sys/dev/audio/audiodef.h:1.9 src/sys/dev/audio/audiodef.h:1.10
--- src/sys/dev/audio/audiodef.h:1.9	Sat Feb 22 06:58:39 2020
+++ src/sys/dev/audio/audiodef.h	Sun Feb 23 07:17:01 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiodef.h,v 1.9 2020/02/22 06:58:39 isaki Exp $	*/
+/*	$NetBSD: audiodef.h,v 1.10 2020/02/23 07:17:01 isaki Exp $	*/
 
 /*
  * Copyright (C) 2017 Tetsuya Isaki. All rights reserved.
@@ -202,6 +202,9 @@ struct audio_file {
 	/* process who wants audio SIGIO. */
 	pid_t		async_audio;
 
+	/* true when closing */
+	bool		dying;
+
 	SLIST_ENTRY(audio_file) entry;

  1   2   3   4   5   >