CVS commit: src/sys/dev/audio

2024-04-20 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Apr 20 05:38:40 UTC 2024

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

Log Message:
Fix typo in comment.


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

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



CVS commit: src/sys/dev/audio

2024-04-20 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Apr 20 05:38:40 UTC 2024

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

Log Message:
Fix typo in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/audio/linear.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/linear.c
diff -u src/sys/dev/audio/linear.c:1.4 src/sys/dev/audio/linear.c:1.5
--- src/sys/dev/audio/linear.c:1.4	Wed Jul 21 06:35:44 2021
+++ src/sys/dev/audio/linear.c	Sat Apr 20 05:38:40 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: linear.c,v 1.4 2021/07/21 06:35:44 skrll Exp $	*/
+/*	$NetBSD: linear.c,v 1.5 2024/04/20 05:38:40 isaki Exp $	*/
 
 /*
  * Copyright (C) 2017 Tetsuya Isaki. All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linear.c,v 1.4 2021/07/21 06:35:44 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linear.c,v 1.5 2024/04/20 05:38:40 isaki Exp $");
 
 #include 
 #include 
@@ -222,7 +222,7 @@ audio_internal_to_linear16(audio_filter_
 /*
  * audio_linear24_to_internal:
  *	This filter performs conversion from [US]LINEAR24/24{LE,BE} to
- *	internal format.  Since it's rerely used, it's size optimized.
+ *	internal format.  Since it's rarely used, it's size optimized.
  */
 void
 audio_linear24_to_internal(audio_filter_arg_t *arg)



CVS commit: src/sys/dev/pci

2024-03-21 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Thu Mar 21 12:33:21 UTC 2024

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

Log Message:
Ensure that the number of bus_dma segments doesn't exceed VirtIO queue size.
This fixes reproducible panics when the host's VirtIO queue size is too small,
less than or equal to VIRTIO_NET_TX_MAXNSEGS(=16).
PR kern/58049.


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 src/sys/dev/pci/if_vioif.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/if_vioif.c
diff -u src/sys/dev/pci/if_vioif.c:1.110 src/sys/dev/pci/if_vioif.c:1.111
--- src/sys/dev/pci/if_vioif.c:1.110	Fri Feb  9 22:08:36 2024
+++ src/sys/dev/pci/if_vioif.c	Thu Mar 21 12:33:21 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vioif.c,v 1.110 2024/02/09 22:08:36 andvar Exp $	*/
+/*	$NetBSD: if_vioif.c,v 1.111 2024/03/21 12:33:21 isaki Exp $	*/
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.110 2024/02/09 22:08:36 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.111 2024/03/21 12:33:21 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -1280,12 +1280,14 @@ vioif_alloc_mems(struct vioif_softc *sc)
 
 		struct virtio_net_hdr *hdrs;
 		int dir;
+		int nsegs;
 
 		dir = VIOIF_NETQ_DIR(qid);
 		netq = >sc_netqs[qid];
 		vq_num = netq->netq_vq->vq_num;
 		maps = netq->netq_maps;
 		hdrs = netq->netq_maps_kva;
+		nsegs = uimin(dmaparams[dir].dma_nsegs, vq_num - 1/*hdr*/);
 
 		for (i = 0; i < vq_num; i++) {
 			maps[i].vnm_hdr = [i];
@@ -1297,7 +1299,7 @@ vioif_alloc_mems(struct vioif_softc *sc)
 goto err_reqs;
 
 			r = vioif_dmamap_create(sc, [i].vnm_mbuf_map,
-			dmaparams[dir].dma_size, dmaparams[dir].dma_nsegs,
+			dmaparams[dir].dma_size, nsegs,
 			dmaparams[dir].msg_payload);
 			if (r != 0)
 goto err_reqs;



CVS commit: src/sys/dev/pci

2024-03-21 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Thu Mar 21 12:33:21 UTC 2024

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

Log Message:
Ensure that the number of bus_dma segments doesn't exceed VirtIO queue size.
This fixes reproducible panics when the host's VirtIO queue size is too small,
less than or equal to VIRTIO_NET_TX_MAXNSEGS(=16).
PR kern/58049.


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 src/sys/dev/pci/if_vioif.c

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



CVS commit: src/sys/dev/virtio

2024-03-09 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Mar  9 11:55:59 UTC 2024

Modified Files:
src/sys/dev/virtio: virtio_mmio.c

Log Message:
Fix a null dereference (on attach failure).
During cleanup, setup_queue may be called even before vsc->sc_vqs is assigned.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/virtio/virtio_mmio.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/virtio/virtio_mmio.c
diff -u src/sys/dev/virtio/virtio_mmio.c:1.13 src/sys/dev/virtio/virtio_mmio.c:1.14
--- src/sys/dev/virtio/virtio_mmio.c:1.13	Sat Jan  6 06:59:33 2024
+++ src/sys/dev/virtio/virtio_mmio.c	Sat Mar  9 11:55:59 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: virtio_mmio.c,v 1.13 2024/01/06 06:59:33 thorpej Exp $	*/
+/*	$NetBSD: virtio_mmio.c,v 1.14 2024/03/09 11:55:59 isaki Exp $	*/
 /*	$OpenBSD: virtio_mmio.c,v 1.2 2017/02/24 17:12:31 patrick Exp $	*/
 
 /*-
@@ -58,7 +58,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio_mmio.c,v 1.13 2024/01/06 06:59:33 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_mmio.c,v 1.14 2024/03/09 11:55:59 isaki Exp $");
 
 #include 
 #include 
@@ -208,8 +208,7 @@ virtio_mmio_v2_setup_queue(struct virtio
 uint64_t addr)
 {
 	struct virtio_mmio_softc *sc = (struct virtio_mmio_softc *)vsc;
-	struct virtqueue *vq = >sc_vqs[idx];
-	KASSERT(vq->vq_index == idx);
+	struct virtqueue *vq;
 
 	virtio_mmio_reg_write(sc, VIRTIO_MMIO_QUEUE_SEL, idx);
 	if (addr == 0) {
@@ -218,6 +217,9 @@ virtio_mmio_v2_setup_queue(struct virtio
 		virtio_mmio_v2_set_addr(sc, VIRTIO_MMIO_V2_QUEUE_AVAIL_LOW, 0);
 		virtio_mmio_v2_set_addr(sc, VIRTIO_MMIO_V2_QUEUE_USED_LOW, 0);
 	} else {
+		vq = >sc_vqs[idx];
+		KASSERT(vq->vq_index == idx);
+
 		virtio_mmio_reg_write(sc, VIRTIO_MMIO_QUEUE_NUM,
 		virtio_mmio_reg_read(sc, VIRTIO_MMIO_QUEUE_NUM_MAX));
 		virtio_mmio_v2_set_addr(sc, VIRTIO_MMIO_V2_QUEUE_DESC_LOW,



CVS commit: src/sys/dev/virtio

2024-03-09 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Mar  9 11:55:59 UTC 2024

Modified Files:
src/sys/dev/virtio: virtio_mmio.c

Log Message:
Fix a null dereference (on attach failure).
During cleanup, setup_queue may be called even before vsc->sc_vqs is assigned.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/virtio/virtio_mmio.c

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



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

2024-03-09 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Mar  9 11:16:31 UTC 2024

Modified Files:
src/sys/arch/virt68k/dev: virtio_mainbus.c

Log Message:
Fix a null dereference.
free_interrupts may be called even when sc_ih has not been assigned yet.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/virt68k/dev/virtio_mainbus.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/virt68k/dev/virtio_mainbus.c
diff -u src/sys/arch/virt68k/dev/virtio_mainbus.c:1.1 src/sys/arch/virt68k/dev/virtio_mainbus.c:1.2
--- src/sys/arch/virt68k/dev/virtio_mainbus.c:1.1	Tue Jan  2 07:40:59 2024
+++ src/sys/arch/virt68k/dev/virtio_mainbus.c	Sat Mar  9 11:16:31 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: virtio_mainbus.c,v 1.1 2024/01/02 07:40:59 thorpej Exp $	*/
+/*	$NetBSD: virtio_mainbus.c,v 1.2 2024/03/09 11:16:31 isaki Exp $	*/
 
 /*
  * Copyright (c) 2021, 2024 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio_mainbus.c,v 1.1 2024/01/02 07:40:59 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_mainbus.c,v 1.2 2024/03/09 11:16:31 isaki Exp $");
 
 #include 
 #include 
@@ -170,6 +170,8 @@ virtio_mainbus_alloc_interrupts(struct v
 static void
 virtio_mainbus_free_interrupts(struct virtio_mmio_softc *msc)
 {
-	intr_disestablish(msc->sc_ih);
-	msc->sc_ih = NULL;
+	if (msc->sc_ih) {
+		intr_disestablish(msc->sc_ih);
+		msc->sc_ih = NULL;
+	}
 }



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

2024-03-09 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Mar  9 11:16:31 UTC 2024

Modified Files:
src/sys/arch/virt68k/dev: virtio_mainbus.c

Log Message:
Fix a null dereference.
free_interrupts may be called even when sc_ih has not been assigned yet.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/virt68k/dev/virtio_mainbus.c

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



CVS commit: src/sys/dev/pci

2024-03-09 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Mar  9 11:04:22 UTC 2024

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

Log Message:
Modify a confused expression in ld_virtio_attach().
VIRTIO_BLK_MIN_SEGMENTS should be the total number of non-data segments,
so I rename it to VIRTIO_BLK_CTRL_SEGMENTS.
PR kern/57981.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/dev/pci/ld_virtio.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/ld_virtio.c
diff -u src/sys/dev/pci/ld_virtio.c:1.33 src/sys/dev/pci/ld_virtio.c:1.34
--- src/sys/dev/pci/ld_virtio.c:1.33	Mon Feb 12 02:28:28 2024
+++ src/sys/dev/pci/ld_virtio.c	Sat Mar  9 11:04:22 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: ld_virtio.c,v 1.33 2024/02/12 02:28:28 isaki Exp $	*/
+/*	$NetBSD: ld_virtio.c,v 1.34 2024/03/09 11:04:22 isaki Exp $	*/
 
 /*
  * Copyright (c) 2010 Minoura Makoto.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ld_virtio.c,v 1.33 2024/02/12 02:28:28 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_virtio.c,v 1.34 2024/03/09 11:04:22 isaki Exp $");
 
 #include 
 #include 
@@ -74,7 +74,7 @@ __KERNEL_RCSID(0, "$NetBSD: ld_virtio.c,
  * Each block request uses at least two segments - one for the header
  * and one for the status.
 */
-#define	VIRTIO_BLK_MIN_SEGMENTS	2
+#define	VIRTIO_BLK_CTRL_SEGMENTS	2
 
 #define VIRTIO_BLK_FLAG_BITS			\
 	VIRTIO_COMMON_FLAG_BITS			\
@@ -222,7 +222,7 @@ ld_virtio_alloc_reqs(struct ld_virtio_so
 		r = bus_dmamap_create(virtio_dmat(sc->sc_virtio),
   ld->sc_maxxfer,
   (ld->sc_maxxfer / NBPG) +
-  VIRTIO_BLK_MIN_SEGMENTS,
+  VIRTIO_BLK_CTRL_SEGMENTS,
   ld->sc_maxxfer,
   0,
   BUS_DMA_WAITOK|BUS_DMA_ALLOCNOW,
@@ -319,18 +319,15 @@ ld_virtio_attach(device_t parent, device
 	if (features & VIRTIO_BLK_F_SEG_MAX) {
 		maxnsegs = virtio_read_device_config_4(vsc,
 		VIRTIO_BLK_CONFIG_SEG_MAX);
-		if (maxnsegs < VIRTIO_BLK_MIN_SEGMENTS) {
+		if (maxnsegs == 0) {
 			aprint_error_dev(sc->sc_dev,
-			"Too small SEG_MAX %d minimum is %d\n",
-			maxnsegs, VIRTIO_BLK_MIN_SEGMENTS);
-			maxnsegs = maxxfersize / NBPG;
-			// goto err;
+			"Invalid SEG_MAX %d\n", maxnsegs);
+			goto err;
 		}
 	} else
 		maxnsegs = maxxfersize / NBPG;
 
-	/* 2 for the minimum size */
-	maxnsegs += VIRTIO_BLK_MIN_SEGMENTS;
+	maxnsegs += VIRTIO_BLK_CTRL_SEGMENTS;
 
 	virtio_init_vq_vqdone(vsc, >sc_vq, 0,
 	ld_virtio_vq_done);
@@ -414,7 +411,7 @@ ld_virtio_start(struct ld_softc *ld, str
 	}
 
 	r = virtio_enqueue_reserve(vsc, vq, slot, vr->vr_payload->dm_nsegs +
-	VIRTIO_BLK_MIN_SEGMENTS);
+	VIRTIO_BLK_CTRL_SEGMENTS);
 	if (r != 0) {
 		bus_dmamap_unload(virtio_dmat(vsc), vr->vr_payload);
 		return r;
@@ -543,7 +540,7 @@ ld_virtio_dump(struct ld_softc *ld, void
 		return r;
 
 	r = virtio_enqueue_reserve(vsc, vq, slot, vr->vr_payload->dm_nsegs +
-	VIRTIO_BLK_MIN_SEGMENTS);
+	VIRTIO_BLK_CTRL_SEGMENTS);
 	if (r != 0) {
 		bus_dmamap_unload(virtio_dmat(vsc), vr->vr_payload);
 		return r;
@@ -679,7 +676,7 @@ ld_virtio_flush(struct ld_softc *ld, boo
 	vr = >sc_reqs[slot];
 	KASSERT(vr->vr_bp == NULL);
 
-	r = virtio_enqueue_reserve(vsc, vq, slot, VIRTIO_BLK_MIN_SEGMENTS);
+	r = virtio_enqueue_reserve(vsc, vq, slot, VIRTIO_BLK_CTRL_SEGMENTS);
 	if (r != 0) {
 		return r;
 	}



CVS commit: src/sys/dev/pci

2024-03-09 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Mar  9 11:04:22 UTC 2024

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

Log Message:
Modify a confused expression in ld_virtio_attach().
VIRTIO_BLK_MIN_SEGMENTS should be the total number of non-data segments,
so I rename it to VIRTIO_BLK_CTRL_SEGMENTS.
PR kern/57981.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/dev/pci/ld_virtio.c

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



CVS commit: src/sys

2024-03-05 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Tue Mar  5 11:19:30 UTC 2024

Modified Files:
src/sys/arch/virt68k/dev: gfrtc_mainbus.c
src/sys/dev/goldfish: gfrtc.c

Log Message:
Fix two problems that the time runs late on virt68k.
- The time between the time the alarm occurred and the time read by
  TIME_* register in the next interrupt handler was not accumulated.
- With the one-shot timer method, once the host time prolongs, the
  guest time will never be able to catch up with the host time again.
New one does:
- The driver maintains its (guest's) time (as sc_alarm_time) and always
  set the next alarm sc_interval_ns after the previous alarm.
- gfrtc_set_alarm() takes an absolute time instead of a relative time
  as the argument.
PR kern/57980.  Confirmed on QEMU.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/virt68k/dev/gfrtc_mainbus.c
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/goldfish/gfrtc.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/virt68k/dev/gfrtc_mainbus.c
diff -u src/sys/arch/virt68k/dev/gfrtc_mainbus.c:1.2 src/sys/arch/virt68k/dev/gfrtc_mainbus.c:1.3
--- src/sys/arch/virt68k/dev/gfrtc_mainbus.c:1.2	Fri Jan 12 06:23:20 2024
+++ src/sys/arch/virt68k/dev/gfrtc_mainbus.c	Tue Mar  5 11:19:30 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: gfrtc_mainbus.c,v 1.2 2024/01/12 06:23:20 mlelstv Exp $	*/
+/*	$NetBSD: gfrtc_mainbus.c,v 1.3 2024/03/05 11:19:30 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2023, 2024 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gfrtc_mainbus.c,v 1.2 2024/01/12 06:23:20 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gfrtc_mainbus.c,v 1.3 2024/03/05 11:19:30 isaki Exp $");
 
 #include 
 #include 
@@ -58,6 +58,7 @@ struct gfrtc_mainbus_softc {
 	struct gfrtc_softc	sc_gfrtc;
 	struct clock_attach_args sc_clock_args;
 	uint64_t		sc_interval_ns;
+	uint64_t		sc_alarm_time;
 	void			(*sc_handler)(struct clockframe *);
 	struct evcnt *		sc_evcnt;
 	void *			sc_ih;
@@ -68,8 +69,9 @@ do {	\
 	/* Clear the interrupt condition. */\
 	gfrtc_clear_interrupt(>sc_gfrtc);\
 	\
-	/* Get the next alarm set ASAP. */\
-	gfrtc_set_alarm(>sc_gfrtc, sc->sc_interval_ns);		\
+	/* Get the next alarm set. */	\
+	sc->sc_alarm_time += sc->sc_interval_ns;			\
+	gfrtc_set_alarm(>sc_gfrtc, sc->sc_alarm_time);		\
 	\
 	/* Increment the counter and call the handler. */		\
 	sc->sc_evcnt->ev_count++;	\
@@ -103,7 +105,8 @@ gfrtc_mainbus_initclock(void *arg, unsig
 	gfrtc_enable_interrupt(>sc_gfrtc);
 
 	/* Start the first alarm! */
-	gfrtc_set_alarm(>sc_gfrtc, sc->sc_interval_ns);
+	sc->sc_alarm_time = gfrtc_get_time(>sc_gfrtc) + sc->sc_interval_ns;
+	gfrtc_set_alarm(>sc_gfrtc, sc->sc_alarm_time);
 }
 
 static int

Index: src/sys/dev/goldfish/gfrtc.c
diff -u src/sys/dev/goldfish/gfrtc.c:1.4 src/sys/dev/goldfish/gfrtc.c:1.5
--- src/sys/dev/goldfish/gfrtc.c:1.4	Thu Jan  4 12:02:11 2024
+++ src/sys/dev/goldfish/gfrtc.c	Tue Mar  5 11:19:30 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: gfrtc.c,v 1.4 2024/01/04 12:02:11 simonb Exp $	*/
+/*	$NetBSD: gfrtc.c,v 1.5 2024/03/05 11:19:30 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gfrtc.c,v 1.4 2024/01/04 12:02:11 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gfrtc.c,v 1.5 2024/03/05 11:19:30 isaki Exp $");
 
 #include 
 
@@ -141,10 +141,8 @@ gfrtc_get_time(struct gfrtc_softc * cons
 
 
 void
-gfrtc_set_alarm(struct gfrtc_softc * const sc, const uint64_t nsec)
+gfrtc_set_alarm(struct gfrtc_softc * const sc, const uint64_t next)
 {
-	uint64_t next = gfrtc_get_time(sc) + nsec;
-
 	GOLDFISH_RTC_WRITE(sc, GOLDFISH_RTC_ALARM_HIGH, (uint32_t)(next >> 32));
 	GOLDFISH_RTC_WRITE(sc, GOLDFISH_RTC_ALARM_LOW, (uint32_t)next);
 }



CVS commit: src/sys

2024-03-05 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Tue Mar  5 11:19:30 UTC 2024

Modified Files:
src/sys/arch/virt68k/dev: gfrtc_mainbus.c
src/sys/dev/goldfish: gfrtc.c

Log Message:
Fix two problems that the time runs late on virt68k.
- The time between the time the alarm occurred and the time read by
  TIME_* register in the next interrupt handler was not accumulated.
- With the one-shot timer method, once the host time prolongs, the
  guest time will never be able to catch up with the host time again.
New one does:
- The driver maintains its (guest's) time (as sc_alarm_time) and always
  set the next alarm sc_interval_ns after the previous alarm.
- gfrtc_set_alarm() takes an absolute time instead of a relative time
  as the argument.
PR kern/57980.  Confirmed on QEMU.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/virt68k/dev/gfrtc_mainbus.c
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/goldfish/gfrtc.c

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



CVS commit: src/sys/dev/pci

2024-02-11 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Mon Feb 12 02:28:28 UTC 2024

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

Log Message:
Fix typo in error message.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/dev/pci/ld_virtio.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/ld_virtio.c
diff -u src/sys/dev/pci/ld_virtio.c:1.32 src/sys/dev/pci/ld_virtio.c:1.33
--- src/sys/dev/pci/ld_virtio.c:1.32	Thu Mar 23 03:55:11 2023
+++ src/sys/dev/pci/ld_virtio.c	Mon Feb 12 02:28:28 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: ld_virtio.c,v 1.32 2023/03/23 03:55:11 yamaguchi Exp $	*/
+/*	$NetBSD: ld_virtio.c,v 1.33 2024/02/12 02:28:28 isaki Exp $	*/
 
 /*
  * Copyright (c) 2010 Minoura Makoto.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ld_virtio.c,v 1.32 2023/03/23 03:55:11 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_virtio.c,v 1.33 2024/02/12 02:28:28 isaki Exp $");
 
 #include 
 #include 
@@ -308,7 +308,7 @@ ld_virtio_attach(device_t parent, device
 			maxxfersize = MAXPHYS;
 		} else if (maxxfersize > MAXPHYS) {
 			aprint_normal_dev(sc->sc_dev,
-			"Clip SEG_MAX from %dK to %dK\n",
+			"Clip SIZE_MAX from %dK to %dK\n",
 			maxxfersize / 1024,
 			MAXPHYS / 1024);
 			maxxfersize = MAXPHYS;



CVS commit: src/sys/dev/pci

2024-02-11 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Mon Feb 12 02:28:28 UTC 2024

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

Log Message:
Fix typo in error message.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/dev/pci/ld_virtio.c

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



CVS commit: src/sys/dev/pci

2024-02-09 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb 10 02:25:15 UTC 2024

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

Log Message:
Split KASSERT(A && B) into KASSERT(A); KASSERT(B).


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/sys/dev/pci/virtio.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/virtio.c
diff -u src/sys/dev/pci/virtio.c:1.80 src/sys/dev/pci/virtio.c:1.81
--- src/sys/dev/pci/virtio.c:1.80	Fri Feb  9 22:08:36 2024
+++ src/sys/dev/pci/virtio.c	Sat Feb 10 02:25:15 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: virtio.c,v 1.80 2024/02/09 22:08:36 andvar Exp $	*/
+/*	$NetBSD: virtio.c,v 1.81 2024/02/10 02:25:15 isaki Exp $	*/
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.80 2024/02/09 22:08:36 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.81 2024/02/10 02:25:15 isaki Exp $");
 
 #include 
 #include 
@@ -1069,7 +1069,8 @@ virtio_enqueue_reserve(struct virtio_sof
 	struct vring_desc_extra *vdx;
 	int i;
 
-	KASSERT(1 <= nsegs && nsegs <= vq->vq_num);
+	KASSERT(1 <= nsegs);
+	KASSERT(nsegs <= vq->vq_num);
 
 	vdx = >vq_descx[slot];
 	vd = >vq_desc[slot];



CVS commit: src/sys/dev/pci

2024-02-09 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb 10 02:25:15 UTC 2024

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

Log Message:
Split KASSERT(A && B) into KASSERT(A); KASSERT(B).


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/sys/dev/pci/virtio.c

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



CVS commit: src/sys/arch/virt68k/virt68k

2024-01-18 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Thu Jan 18 12:07:51 UTC 2024

Modified Files:
src/sys/arch/virt68k/virt68k: locore.s

Log Message:
Set TT0 register to recognize the I/O space even on the 68030 case.

http://mail-index.netbsd.org/port-m68k/2024/01/17/msg000870.html


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/virt68k/virt68k/locore.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/virt68k/virt68k/locore.s
diff -u src/sys/arch/virt68k/virt68k/locore.s:1.13 src/sys/arch/virt68k/virt68k/locore.s:1.14
--- src/sys/arch/virt68k/virt68k/locore.s:1.13	Wed Jan 17 12:33:51 2024
+++ src/sys/arch/virt68k/virt68k/locore.s	Thu Jan 18 12:07:51 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.s,v 1.13 2024/01/17 12:33:51 thorpej Exp $	*/
+/*	$NetBSD: locore.s,v 1.14 2024/01/18 12:07:51 isaki Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -199,8 +199,13 @@ Lnot060cache:
 	jmp	Lenab1
 
 Lmotommu2:
+	movl	#VIRT68K_TT30_IO,%sp@-	| TT0 maps the I/O space
+	.long	0xf0170800		| pmove %sp@,%tt0
+	clrl	%sp@			| ensure TT1 is disabled
+	.long	0xf0170c00		| pmove %sp@,%tt1
+
 	pflusha
-	movl	#MMU51_TCR_BITS,%sp@-	| value to load TC with
+	movl	#MMU51_TCR_BITS,%sp@	| value to load TC with
 	pmove	%sp@,%tc		| load it
 
 /*



CVS commit: src/sys/arch/virt68k/virt68k

2024-01-18 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Thu Jan 18 12:07:51 UTC 2024

Modified Files:
src/sys/arch/virt68k/virt68k: locore.s

Log Message:
Set TT0 register to recognize the I/O space even on the 68030 case.

http://mail-index.netbsd.org/port-m68k/2024/01/17/msg000870.html


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/virt68k/virt68k/locore.s

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



CVS commit: src/sys/arch/x68k

2024-01-06 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Jan  7 07:58:35 UTC 2024

Modified Files:
src/sys/arch/x68k/conf: GENERIC INSTALL majors.x68k
src/sys/arch/x68k/dev: bmd.c fd.c intio_dmac.c ite.c ite_tv.c itevar.h
kbdmap.c kbdmap.c.ascii mha.c mhavar.h ms.c par.c scsiromvar.h
slhci_intio.c sram.c vsvar.h
src/sys/arch/x68k/include: cpu.h disklabel.h intr.h kbdmap.h
opmbellio.h
src/sys/arch/x68k/stand/aout2hux: aout2hux.c
src/sys/arch/x68k/stand/boot: boot.c boot.ldscript if_ne.c srt0.S
src/sys/arch/x68k/stand/boot_ufs: readufs_lfs.c
src/sys/arch/x68k/stand/common: exec_image.S start.S
src/sys/arch/x68k/stand/libsa: clock.c consio.c fd.c fdsub.S
parseutils.c sdcd.c
src/sys/arch/x68k/stand/loadbsd: Makefile loadbsd.c
src/sys/arch/x68k/stand/mboot: Makefile srt0.S
src/sys/arch/x68k/stand/xxboot: Makefile.xxboot bootmain.c memcmp.S
src/sys/arch/x68k/usr.bin/loadkmap: ascii_kmap.c jis_kmap.c kbdmap.h
loadkmap.c
src/sys/arch/x68k/x68k: autoconf.c bus.c clock.c disksubr.c iodevice.h
kgdb_stub.c trap.c vectors.s

Log Message:
TAB/space/indent cleanup.


To generate a diff of this commit:
cvs rdiff -u -r1.208 -r1.209 src/sys/arch/x68k/conf/GENERIC
cvs rdiff -u -r1.121 -r1.122 src/sys/arch/x68k/conf/INSTALL
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/x68k/conf/majors.x68k
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/x68k/dev/bmd.c
cvs rdiff -u -r1.128 -r1.129 src/sys/arch/x68k/dev/fd.c
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/x68k/dev/intio_dmac.c
cvs rdiff -u -r1.70 -r1.71 src/sys/arch/x68k/dev/ite.c
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/x68k/dev/ite_tv.c \
src/sys/arch/x68k/dev/vsvar.h
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/x68k/dev/itevar.h
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/x68k/dev/kbdmap.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/x68k/dev/kbdmap.c.ascii
cvs rdiff -u -r1.60 -r1.61 src/sys/arch/x68k/dev/mha.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/x68k/dev/mhavar.h
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/x68k/dev/ms.c
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/x68k/dev/par.c
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/x68k/dev/scsiromvar.h
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/x68k/dev/slhci_intio.c
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/x68k/dev/sram.c
cvs rdiff -u -r1.62 -r1.63 src/sys/arch/x68k/include/cpu.h
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/x68k/include/disklabel.h
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/x68k/include/intr.h
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/x68k/include/kbdmap.h
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/x68k/include/opmbellio.h
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/x68k/stand/aout2hux/aout2hux.c
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/x68k/stand/boot/boot.c
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/x68k/stand/boot/boot.ldscript
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/x68k/stand/boot/if_ne.c \
src/sys/arch/x68k/stand/boot/srt0.S
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/x68k/stand/boot_ufs/readufs_lfs.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/x68k/stand/common/exec_image.S
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/x68k/stand/common/start.S
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/x68k/stand/libsa/clock.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/x68k/stand/libsa/consio.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/x68k/stand/libsa/fd.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/x68k/stand/libsa/fdsub.S
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/x68k/stand/libsa/parseutils.c
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/x68k/stand/libsa/sdcd.c
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/x68k/stand/loadbsd/Makefile
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/x68k/stand/loadbsd/loadbsd.c
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/x68k/stand/mboot/Makefile
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/x68k/stand/mboot/srt0.S
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/x68k/stand/xxboot/Makefile.xxboot
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/x68k/stand/xxboot/bootmain.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/x68k/stand/xxboot/memcmp.S
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/x68k/usr.bin/loadkmap/ascii_kmap.c
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/x68k/usr.bin/loadkmap/jis_kmap.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/x68k/usr.bin/loadkmap/kbdmap.h
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/x68k/usr.bin/loadkmap/loadkmap.c
cvs rdiff -u -r1.68 -r1.69 src/sys/arch/x68k/x68k/autoconf.c
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/x68k/x68k/bus.c
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/x68k/x68k/clock.c
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/x68k/x68k/disksubr.c
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/x68k/x68k/iodevice.h \
src/sys/arch/x68k/x68k/vectors.s
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/x68k/x68k/kgdb_stub.c
cvs rdiff -u -r1.112 -r1.113 src/sys/arch/x68k/x68k/trap.c

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



CVS commit: src/sys/arch/x68k

2024-01-06 Thread Tetsuya Isaki
 layered filesystem
-#file-system 	OVERLAY		# overlay file system
+#file-system	OVERLAY		# overlay file system
 #file-system	MFS		# memory-based filesystem
 #file-system	FDESC		# user file descriptor filesystem
 #file-system	UMAPFS		# uid/gid remapping filesystem
@@ -150,7 +150,7 @@ file-system	NFS		# Sun NFS-compatible fi
 file-system	CD9660		# ISO 9660 + Rock Ridge file system
 #file-system	UNION		# union file system (a little buggy)
 file-system	MSDOSFS		# MS-DOS FAT filesystem(s).
-#file-system 	ADOSFS		# AmigaDOS filesystem
+#file-system	ADOSFS		# AmigaDOS filesystem
 #file-system	PTYFS		# /dev/pts/N support
 
 ## File system options.
@@ -225,7 +225,7 @@ zstty0	at zsc0 channel 0		# built-in RS-
 #zsc2	at intio0 addr 0xeafc10 intr 114
 #zstty4	at zsc2 channel 0
 #zstty5	at zsc2 channel 1
-#par0	at intio0 addr 0xe8c000 	# Builtin printer port
+#par0	at intio0 addr 0xe8c000		# Builtin printer port
 
 sram0	at intio0 addr 0xed		# battery-backuped static RAM
 #pseudo-device	bell			# OPM bell
@@ -252,5 +252,5 @@ ne*	at neptune? addr 0x300			# NE2000 or
 pseudo-device	md			# boot floppy image
 pseudo-device	loop
 pseudo-device	bpfilter
-pseudo-device	sl		
+pseudo-device	sl
 pseudo-device	pty			# pseudo-terminals

Index: src/sys/arch/x68k/conf/majors.x68k
diff -u src/sys/arch/x68k/conf/majors.x68k:1.33 src/sys/arch/x68k/conf/majors.x68k:1.34
--- src/sys/arch/x68k/conf/majors.x68k:1.33	Tue Jun 29 10:22:37 2021
+++ src/sys/arch/x68k/conf/majors.x68k	Sun Jan  7 07:58:33 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: majors.x68k,v 1.33 2021/06/29 10:22:37 nia Exp $
+#	$NetBSD: majors.x68k,v 1.34 2024/01/07 07:58:33 isaki Exp $
 #
 # Device majors for x68k
 #
@@ -63,5 +63,5 @@ device-major	sysmon		char 61			sysmon
 #device-major	obsolete	char 98			obsolete (nsmb)
 
 # Majors up to 143 are reserved for machine-dependent drivers.
-# New machine-independent driver majors are assigned in 
+# New machine-independent driver majors are assigned in
 # sys/conf/majors.

Index: src/sys/arch/x68k/dev/bmd.c
diff -u src/sys/arch/x68k/dev/bmd.c:1.27 src/sys/arch/x68k/dev/bmd.c:1.28
--- src/sys/arch/x68k/dev/bmd.c:1.27	Sun Dec 17 21:51:29 2023
+++ src/sys/arch/x68k/dev/bmd.c	Sun Jan  7 07:58:33 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: bmd.c,v 1.27 2023/12/17 21:51:29 andvar Exp $	*/
+/*	$NetBSD: bmd.c,v 1.28 2024/01/07 07:58:33 isaki Exp $	*/
 
 /*
  * Copyright (c) 2002 Tetsuya Isaki. All rights reserved.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bmd.c,v 1.27 2023/12/17 21:51:29 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bmd.c,v 1.28 2024/01/07 07:58:33 isaki Exp $");
 
 #include 
 #include 
@@ -152,7 +152,7 @@ bmd_match(device_t parent, cfdata_t cf, 
 		return (0);
 
 	/* Check CTRL addr */
- 	if (badaddr((void *)IIOV(ia->ia_addr)))
+	if (badaddr((void *)IIOV(ia->ia_addr)))
 		return (0);
 
 	ia->ia_size = 2;

Index: src/sys/arch/x68k/dev/fd.c
diff -u src/sys/arch/x68k/dev/fd.c:1.128 src/sys/arch/x68k/dev/fd.c:1.129
--- src/sys/arch/x68k/dev/fd.c:1.128	Sun Dec 17 21:52:11 2023
+++ src/sys/arch/x68k/dev/fd.c	Sun Jan  7 07:58:33 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: fd.c,v 1.128 2023/12/17 21:52:11 andvar Exp $	*/
+/*	$NetBSD: fd.c,v 1.129 2024/01/07 07:58:33 isaki Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fd.c,v 1.128 2023/12/17 21:52:11 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fd.c,v 1.129 2024/01/07 07:58:33 isaki Exp $");
 
 #include "opt_ddb.h"
 #include "opt_m68k_arch.h"
@@ -1768,7 +1768,7 @@ fdioctl(dev_t dev, u_long cmd, void *add
 		*(int *)addr = fd->sc_opts;
 		return 0;
 
-	case FDIOCSETOPTS:	/* set drive options */
+	case FDIOCSETOPTS:		/* set drive options */
 		DPRINTF(("FDIOCSETOPTS\n"));
 		fd->sc_opts = *(int *)addr;
 		return 0;
@@ -1882,7 +1882,7 @@ fdgetdisklabel(struct fd_softc *sc, dev_
 	lp->d_secperunit  = sc->sc_type->size;
 
 	lp->d_type= DKTYPE_FLOPPY;
-	lp->d_rpm = 300; 	/* XXX */
+	lp->d_rpm = 300;	/* XXX */
 	lp->d_interleave  = 1;		/* FIXME: is this OK?		*/
 	lp->d_bbsize  = 0;
 	lp->d_sbsize  = 0;

Index: src/sys/arch/x68k/dev/intio_dmac.c
diff -u src/sys/arch/x68k/dev/intio_dmac.c:1.39 src/sys/arch/x68k/dev/intio_dmac.c:1.40
--- src/sys/arch/x68k/dev/intio_dmac.c:1.39	Sun Dec 17 22:03:50 2023
+++ src/sys/arch/x68k/dev/intio_dmac.c	Sun Jan  7 07:58:33 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: intio_dmac.c,v 1.39 2023/12/17 22:03:50 andvar Exp $	*/
+/*	$NetBSD: intio_dmac.c,v 1.40 2024/01/07 07:58:33 isaki Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #include "opt_m68k_arch.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intio_dmac.c,v 1.39 2023/12/17 22:03:50 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intio_dmac.c,v 1.40 2024/01/07 07:58:33 isaki Exp $");
 
 #include 
 #include 
@@ -180,7

CVS commit: src/sys/arch/x68k

2024-01-05 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Jan  6 05:31:20 UTC 2024

Modified Files:
src/sys/arch/x68k/dev: mfp.c
src/sys/arch/x68k/include: param.h
src/sys/arch/x68k/x68k: locore.s

Log Message:
x68k: Make _delay() argument to microseconds.
'<< 8' is just a magnification factor and should not be visible
from the outside.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/x68k/dev/mfp.c
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/x68k/include/param.h
cvs rdiff -u -r1.125 -r1.126 src/sys/arch/x68k/x68k/locore.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/dev/mfp.c
diff -u src/sys/arch/x68k/dev/mfp.c:1.31 src/sys/arch/x68k/dev/mfp.c:1.32
--- src/sys/arch/x68k/dev/mfp.c:1.31	Sat Jan  6 05:24:33 2024
+++ src/sys/arch/x68k/dev/mfp.c	Sat Jan  6 05:31:19 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: mfp.c,v 1.31 2024/01/06 05:24:33 isaki Exp $	*/
+/*	$NetBSD: mfp.c,v 1.32 2024/01/06 05:31:19 isaki Exp $	*/
 
 /*-
  * Copyright (c) 1998 NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mfp.c,v 1.31 2024/01/06 05:24:33 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mfp.c,v 1.32 2024/01/06 05:31:19 isaki Exp $");
 
 #include 
 #include 
@@ -165,7 +165,7 @@ mfp_calibrate_delay(void)
 	for (delay_divisor = 140; delay_divisor > 0; delay_divisor--) {
 		mfp_set_tcdr(255-0);
 		mfp_set_tcdcr(0x70); /* 1/200 delay mode */
-		_delay(1 << 8);
+		_delay(1);
 		mfp_set_tcdcr(0); /* stop timer */
 		if ((255 - mfp_get_tcdr()) > 200)
 			break;	/* got it! */

Index: src/sys/arch/x68k/include/param.h
diff -u src/sys/arch/x68k/include/param.h:1.30 src/sys/arch/x68k/include/param.h:1.31
--- src/sys/arch/x68k/include/param.h:1.30	Mon May 31 14:38:57 2021
+++ src/sys/arch/x68k/include/param.h	Sat Jan  6 05:31:19 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.30 2021/05/31 14:38:57 simonb Exp $	*/
+/*	$NetBSD: param.h,v 1.31 2024/01/06 05:31:19 isaki Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -74,7 +74,7 @@
 #if defined(_KERNEL) && !defined(_LOCORE)
 #include 
 
-#define	delay(us)	_delay((us) << 8)
+#define	delay(us)	_delay(us)
 #define DELAY(us)	delay(us)
 
 void	_delay(u_int);

Index: src/sys/arch/x68k/x68k/locore.s
diff -u src/sys/arch/x68k/x68k/locore.s:1.125 src/sys/arch/x68k/x68k/locore.s:1.126
--- src/sys/arch/x68k/x68k/locore.s:1.125	Wed Dec 27 03:03:42 2023
+++ src/sys/arch/x68k/x68k/locore.s	Sat Jan  6 05:31:19 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.s,v 1.125 2023/12/27 03:03:42 thorpej Exp $	*/
+/*	$NetBSD: locore.s,v 1.126 2024/01/06 05:31:19 isaki Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -852,13 +852,14 @@ LmotommuC:
 /*
  * _delay(u_int N)
  *
- * Delay for at least (N/256) microseconds.
+ * Delay for at least N microseconds.
  * This routine depends on the variable:  delay_divisor
  * which should be set based on the CPU clock rate.
  */
 ENTRY_NOPROFILE(_delay)
-	| %d0 = arg = (usecs << 8)
+	| %d0 = (usecs * a certain magnification factor)
 	movl	%sp@(4),%d0
+	lsll	#8,%d0
 	| %d1 = delay_divisor
 	movl	_C_LABEL(delay_divisor),%d1
 L_delay:



CVS commit: src/sys/arch/x68k

2024-01-05 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Jan  6 05:31:20 UTC 2024

Modified Files:
src/sys/arch/x68k/dev: mfp.c
src/sys/arch/x68k/include: param.h
src/sys/arch/x68k/x68k: locore.s

Log Message:
x68k: Make _delay() argument to microseconds.
'<< 8' is just a magnification factor and should not be visible
from the outside.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/x68k/dev/mfp.c
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/x68k/include/param.h
cvs rdiff -u -r1.125 -r1.126 src/sys/arch/x68k/x68k/locore.s

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



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

2024-01-05 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Jan  6 05:24:34 UTC 2024

Modified Files:
src/sys/arch/x68k/dev: mfp.c

Log Message:
Remove a duplicated extern declaration.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/x68k/dev/mfp.c

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



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

2024-01-05 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Jan  6 05:24:34 UTC 2024

Modified Files:
src/sys/arch/x68k/dev: mfp.c

Log Message:
Remove a duplicated extern declaration.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/x68k/dev/mfp.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/dev/mfp.c
diff -u src/sys/arch/x68k/dev/mfp.c:1.30 src/sys/arch/x68k/dev/mfp.c:1.31
--- src/sys/arch/x68k/dev/mfp.c:1.30	Wed Dec 20 00:40:44 2023
+++ src/sys/arch/x68k/dev/mfp.c	Sat Jan  6 05:24:33 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: mfp.c,v 1.30 2023/12/20 00:40:44 thorpej Exp $	*/
+/*	$NetBSD: mfp.c,v 1.31 2024/01/06 05:24:33 isaki Exp $	*/
 
 /*-
  * Copyright (c) 1998 NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mfp.c,v 1.30 2023/12/20 00:40:44 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mfp.c,v 1.31 2024/01/06 05:24:33 isaki Exp $");
 
 #include 
 #include 
@@ -149,7 +149,6 @@ mfp_init(void)
 }
 
 extern int delay_divisor;
-void	_delay(u_int);
 
 static void
 mfp_calibrate_delay(void)



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

2024-01-05 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Jan  6 05:16:57 UTC 2024

Modified Files:
src/sys/arch/x68k/dev: if_ne_intio.c

Log Message:
White space cleanup.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/x68k/dev/if_ne_intio.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/dev/if_ne_intio.c
diff -u src/sys/arch/x68k/dev/if_ne_intio.c:1.19 src/sys/arch/x68k/dev/if_ne_intio.c:1.20
--- src/sys/arch/x68k/dev/if_ne_intio.c:1.19	Fri Jun 22 04:17:41 2018
+++ src/sys/arch/x68k/dev/if_ne_intio.c	Sat Jan  6 05:16:57 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ne_intio.c,v 1.19 2018/06/22 04:17:41 msaitoh Exp $	*/
+/*	$NetBSD: if_ne_intio.c,v 1.20 2024/01/06 05:16:57 isaki Exp $	*/
 
 /*
  * Copyright (c) 2001 Tetsuya Isaki. All rights reserved.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ne_intio.c,v 1.19 2018/06/22 04:17:41 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ne_intio.c,v 1.20 2024/01/06 05:16:57 isaki Exp $");
 
 #include "opt_inet.h"
 #include "opt_ns.h"
@@ -111,13 +111,13 @@ ne_intio_match(device_t parent, cfdata_t
 		return 0;
 
 	/* Map I/O space */
-	if (bus_space_map(iot, ia->ia_addr, NE2000_NPORTS*2,
+	if (bus_space_map(iot, ia->ia_addr, NE2000_NPORTS * 2,
 			BUS_SPACE_MAP_SHIFTED_EVEN, ))
 		return 0;
 
 	asict = iot;
-	if (bus_space_subregion(iot, ioh, NE2000_ASIC_OFFSET*2,
-			NE2000_ASIC_NPORTS*2, ))
+	if (bus_space_subregion(iot, ioh, NE2000_ASIC_OFFSET * 2,
+			NE2000_ASIC_NPORTS * 2, ))
 		goto out;
 
 	/* Look for an NE2000 compatible card */
@@ -145,15 +145,15 @@ ne_intio_attach(device_t parent, device_
 	aprint_normal(": Nereid Ethernet\n");
 
 	/* Map I/O space */
-	if (bus_space_map(iot, ia->ia_addr, NE2000_NPORTS*2,
-			BUS_SPACE_MAP_SHIFTED_EVEN, )){
+	if (bus_space_map(iot, ia->ia_addr, NE2000_NPORTS * 2,
+			BUS_SPACE_MAP_SHIFTED_EVEN, )) {
 		aprint_error_dev(self, "can't map I/O space\n");
 		return;
 	}
 
 	asict = iot;
-	if (bus_space_subregion(iot, ioh, NE2000_ASIC_OFFSET*2,
-			NE2000_ASIC_NPORTS*2, )) {
+	if (bus_space_subregion(iot, ioh, NE2000_ASIC_OFFSET * 2,
+			NE2000_ASIC_NPORTS * 2, )) {
 		aprint_error_dev(self, "can't subregion I/O space\n");
 		return;
 	}



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

2024-01-05 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Jan  6 05:16:57 UTC 2024

Modified Files:
src/sys/arch/x68k/dev: if_ne_intio.c

Log Message:
White space cleanup.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/x68k/dev/if_ne_intio.c

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



CVS commit: src/sys/dev/ic

2023-12-30 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Dec 31 03:19:22 UTC 2023

Modified Files:
src/sys/dev/ic: rtl80x9.c

Log Message:
ne(4): Write CR0 properly.
Writing 0b000 to RD2-0 in CR0 appears harmless, but it is "not allowed"
by the RTL8019AS (and several NE2000 derived) datasheets.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/ic/rtl80x9.c

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

Modified files:

Index: src/sys/dev/ic/rtl80x9.c
diff -u src/sys/dev/ic/rtl80x9.c:1.18 src/sys/dev/ic/rtl80x9.c:1.19
--- src/sys/dev/ic/rtl80x9.c:1.18	Thu Apr 25 10:44:52 2019
+++ src/sys/dev/ic/rtl80x9.c	Sun Dec 31 03:19:22 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtl80x9.c,v 1.18 2019/04/25 10:44:52 msaitoh Exp $	*/
+/*	$NetBSD: rtl80x9.c,v 1.19 2023/12/31 03:19:22 isaki Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rtl80x9.c,v 1.18 2019/04/25 10:44:52 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtl80x9.c,v 1.19 2023/12/31 03:19:22 isaki Exp $");
 
 #include 
 #include 
@@ -170,7 +170,8 @@ rtl80x9_media_init(struct dp8390_softc *
 	aprint_normal_dev(sc->sc_dev,
 	"10base2, 10baseT, 10baseT-FDX, auto, default ");
 
-	bus_space_write_1(sc->sc_regt, sc->sc_regh, ED_P0_CR, ED_CR_PAGE_3);
+	bus_space_write_1(sc->sc_regt, sc->sc_regh, ED_P0_CR,
+	sc->cr_proto | ED_CR_PAGE_3);
 
 	conf2 = bus_space_read_1(sc->sc_regt, sc->sc_regh, NERTL_RTL3_CONFIG2);
 	conf3 = bus_space_read_1(sc->sc_regt, sc->sc_regh, NERTL_RTL3_CONFIG3);
@@ -201,7 +202,8 @@ rtl80x9_media_init(struct dp8390_softc *
 		break;
 	}
 
-	bus_space_write_1(sc->sc_regt, sc->sc_regh, ED_P0_CR, ED_CR_PAGE_0);
+	bus_space_write_1(sc->sc_regt, sc->sc_regh, ED_P0_CR,
+	sc->cr_proto | ED_CR_PAGE_0);
 
 	ifmedia_init(>sc_media, 0, dp8390_mediachange, dp8390_mediastatus);
 	for (i = 0; i < rtl80x9_nmedia; i++)



CVS commit: src/sys/dev/ic

2023-12-30 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Dec 31 03:19:22 UTC 2023

Modified Files:
src/sys/dev/ic: rtl80x9.c

Log Message:
ne(4): Write CR0 properly.
Writing 0b000 to RD2-0 in CR0 appears harmless, but it is "not allowed"
by the RTL8019AS (and several NE2000 derived) datasheets.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/ic/rtl80x9.c

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



CVS commit: src/sys/arch/m68k/fpe

2023-11-18 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Nov 19 03:58:15 UTC 2023

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

Log Message:
m68k: Remove an unused variable since rev 1.1.
Detected by clang15 (nono emulator has imported and used this FPE).


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/m68k/fpe/fpu_rem.c

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



CVS commit: src/sys/arch/m68k/fpe

2023-11-18 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Nov 19 03:58:15 UTC 2023

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

Log Message:
m68k: Remove an unused variable since rev 1.1.
Detected by clang15 (nono emulator has imported and used this FPE).


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/m68k/fpe/fpu_rem.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_rem.c
diff -u src/sys/arch/m68k/fpe/fpu_rem.c:1.17 src/sys/arch/m68k/fpe/fpu_rem.c:1.18
--- src/sys/arch/m68k/fpe/fpu_rem.c:1.17	Thu Feb  5 12:22:06 2015
+++ src/sys/arch/m68k/fpe/fpu_rem.c	Sun Nov 19 03:58:15 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu_rem.c,v 1.17 2015/02/05 12:22:06 isaki Exp $	*/
+/*	$NetBSD: fpu_rem.c,v 1.18 2023/11/19 03:58:15 isaki Exp $	*/
 
 /*
  * Copyright (c) 1995  Ken Nakata
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fpu_rem.c,v 1.17 2015/02/05 12:22:06 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu_rem.c,v 1.18 2023/11/19 03:58:15 isaki Exp $");
 
 #include 
 #include 
@@ -48,7 +48,7 @@ __KERNEL_RCSID(0, "$NetBSD: fpu_rem.c,v 
  *signQ := signX EOR signY. Record whether MOD or REM
  *is requested.
  *
- *   Step 2.  Set L := expo(X)-expo(Y), k := 0, Q := 0.
+ *   Step 2.  Set L := expo(X)-expo(Y), Q := 0.
  *If (L < 0) then
  *   R := X, go to Step 4.
  *else
@@ -59,8 +59,7 @@ __KERNEL_RCSID(0, "$NetBSD: fpu_rem.c,v 
  *3.1 If R = Y, then { Q := Q + 1, R := 0, go to Step 7. }
  *3.2 If R > Y, then { R := R - Y, Q := Q + 1}
  *3.3 If j = 0, go to Step 4.
- *3.4 k := k + 1, j := j - 1, Q := 2Q, R := 2R. Go to
- *Step 3.1.
+ *3.4 j := j - 1, Q := 2Q, R := 2R. Go to Step 3.1.
  *
  *   Step 4.  R := signX*R.
  *
@@ -105,7 +104,7 @@ __fpu_modrem(struct fpemu *fe, int is_mo
 	static struct fpn X, Y;
 	struct fpn *x, *y, *r;
 	uint32_t signX, signY, signQ;
-	int j, k, l, q;
+	int j, l, q;
 	int cmp;
 
 	if (ISNAN(>fe_f1) || ISNAN(>fe_f2))
@@ -138,7 +137,6 @@ __fpu_modrem(struct fpemu *fe, int is_mo
 	 * Step 2
 	 */
 	l = x->fp_exp - y->fp_exp;
-	k = 0;
 	CPYFPN(r, x);
 	if (l >= 0) {
 		r->fp_exp -= l;
@@ -168,7 +166,6 @@ __fpu_modrem(struct fpemu *fe, int is_mo
 goto Step4;
 
 			/* Step 3.4 */
-			k++;
 			j--;
 			q += q;
 			r->fp_exp++;



CVS commit: src/sys/kern

2023-04-28 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Apr 29 03:36:55 UTC 2023

Modified Files:
src/sys/kern: subr_time.c

Log Message:
White space fix.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/kern/subr_time.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/kern/subr_time.c
diff -u src/sys/kern/subr_time.c:1.36 src/sys/kern/subr_time.c:1.37
--- src/sys/kern/subr_time.c:1.36	Sun Apr  9 09:18:09 2023
+++ src/sys/kern/subr_time.c	Sat Apr 29 03:36:55 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_time.c,v 1.36 2023/04/09 09:18:09 riastradh Exp $	*/
+/*	$NetBSD: subr_time.c,v 1.37 2023/04/29 03:36:55 isaki Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.36 2023/04/09 09:18:09 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.37 2023/04/29 03:36:55 isaki Exp $");
 
 #include 
 #include 
@@ -255,10 +255,10 @@ ticks2ts(uint64_t ticks, struct timespec
 	uint64_t sticks = ticks - ts->tv_sec * hz;
 	if (sticks > BINTIME_SCALE_MS)	/* floor(2^64 / 1000) */
 		ts->tv_nsec = sticks / hz * 10LL;
-   	else if (sticks > BINTIME_SCALE_US)	/* floor(2^64 / 100) */
-   		ts->tv_nsec = sticks * 1000LL / hz * 100LL;
+	else if (sticks > BINTIME_SCALE_US)	/* floor(2^64 / 100) */
+		ts->tv_nsec = sticks * 1000LL / hz * 100LL;
 	else
-   		ts->tv_nsec = sticks * 10LL / hz;
+		ts->tv_nsec = sticks * 10LL / hz;
 	DPRINTF(("%s: %ju/%ju -> %ju.%ju\n", __func__,
 	(uintmax_t)ticks, (uintmax_t)sticks,
 	(uintmax_t)ts->tv_sec, (uintmax_t)ts->tv_nsec));
@@ -307,7 +307,7 @@ clock_gettime1(clockid_t clock_id, struc
 		DPRINTF(("%s: r=%ju, s=%ju\n", __func__,
 		(uintmax_t)l->l_rticksum, (uintmax_t)l->l_slpticksum));
 		mutex_exit(p->p_lock);
-} else
+	} else
 		ticks = (uint64_t)-1;
 
 	if (ticks != (uint64_t)-1) {



CVS commit: src/sys/kern

2023-04-28 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Apr 29 03:36:55 UTC 2023

Modified Files:
src/sys/kern: subr_time.c

Log Message:
White space fix.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/kern/subr_time.c

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



CVS commit: src/sys/arch/m68k/m68k

2023-04-28 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Apr 29 03:17:30 UTC 2023

Modified Files:
src/sys/arch/m68k/m68k: busaddrerr.s

Log Message:
m68k: Support TT(Transparent Translation) for 020/030 buserror handler.
This avoids a panic when trying badaddr() against to an address where
bus error occurs in the TT region.  Only luna68k and news68k use TT.
Discussed on port-m68k.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/m68k/m68k/busaddrerr.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/m68k/m68k/busaddrerr.s
diff -u src/sys/arch/m68k/m68k/busaddrerr.s:1.1 src/sys/arch/m68k/m68k/busaddrerr.s:1.2
--- src/sys/arch/m68k/m68k/busaddrerr.s:1.1	Sat Mar 15 09:22:36 2014
+++ src/sys/arch/m68k/m68k/busaddrerr.s	Sat Apr 29 03:17:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: busaddrerr.s,v 1.1 2014/03/15 09:22:36 tsutsui Exp $	*/
+/*	$NetBSD: busaddrerr.s,v 1.2 2023/04/29 03:17:30 isaki Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -219,7 +219,12 @@ Lbe10:
 	jeq	Lbe10a			| if no, done
 	movql	#5,%d0			| else supervisor program access
 Lbe10a:
-	ptestr	%d0,%a0@,#7		| do a table search
+	ptestr	%d0,%a0@,#0		| only PTEST #0 can detect transparent
+	pmove	%psr,%sp@		|   translation (TT0 or TT1).
+	movw	%sp@,%d1
+	btst	#6,%d1			| transparent (TT0 or TT1)?
+	jne	Lisberr1		| yes -> bus error
+	ptestr	%d0,%a0@,#7		| no, do a table search
 	pmove	%psr,%sp@		| save result
 	movb	%sp@,%d1
 	btst	#2,%d1			| invalid (incl. limit viol. and berr)?



CVS commit: src/sys/arch/m68k/m68k

2023-04-28 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Apr 29 03:17:30 UTC 2023

Modified Files:
src/sys/arch/m68k/m68k: busaddrerr.s

Log Message:
m68k: Support TT(Transparent Translation) for 020/030 buserror handler.
This avoids a panic when trying badaddr() against to an address where
bus error occurs in the TT region.  Only luna68k and news68k use TT.
Discussed on port-m68k.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/m68k/m68k/busaddrerr.s

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



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

2023-01-11 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Jan 11 09:35:06 UTC 2023

Modified Files:
src/sys/arch/x68k/stand/boot_ufs: Makefile

Log Message:
Add udivdi3/umoddi3 (and ashldi3) that were required by recent UFS change.
This increases xxboot_ufs from about 4.5KB to 5.5KB (The upper limit is 8KB).
Thanks tsutsui@ for advices.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/x68k/stand/boot_ufs/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/boot_ufs/Makefile
diff -u src/sys/arch/x68k/stand/boot_ufs/Makefile:1.38 src/sys/arch/x68k/stand/boot_ufs/Makefile:1.39
--- src/sys/arch/x68k/stand/boot_ufs/Makefile:1.38	Wed Dec 15 13:22:34 2021
+++ src/sys/arch/x68k/stand/boot_ufs/Makefile	Wed Jan 11 09:35:06 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.38 2021/12/15 13:22:34 christos Exp $
+#	$NetBSD: Makefile,v 1.39 2023/01/11 09:35:06 isaki Exp $
 
 NOMAN=		# defined
 
@@ -30,6 +30,12 @@ LIBIOCS=	$M/stand/libiocs
 SRCS=	boot.S bootmain.c readufs.c readufs_ffs.c readufs_lfs.c
 SRCS+=	exec_image.S memset.S strcmp.S
 
+.PATH:	${S}/../common/lib/libc/quad
+SRCS+=	udivdi3.c umoddi3.c qdivrem.c
+
+.PATH:	${.CURDIR}/../xxboot
+SRCS+=	ashldi3.S
+
 .include "${S}/conf/newvers_stand.mk"
 
 CFLAGS=	-Os -fomit-frame-pointer -fno-unwind-tables



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

2023-01-11 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Jan 11 09:35:06 UTC 2023

Modified Files:
src/sys/arch/x68k/stand/boot_ufs: Makefile

Log Message:
Add udivdi3/umoddi3 (and ashldi3) that were required by recent UFS change.
This increases xxboot_ufs from about 4.5KB to 5.5KB (The upper limit is 8KB).
Thanks tsutsui@ for advices.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/x68k/stand/boot_ufs/Makefile

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



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

2022-09-25 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Sep 25 11:28:40 UTC 2022

Modified Files:
src/sys/arch/luna68k/dev: lunafb.c omrasops.c omrasopsvar.h

Log Message:
lunafb: Improve drawing performance using VRAM ROP features.
- Drawing a character on 4bpp normally needs 4 times writes, but by using
  VRAM ROP actively, it can be reduced to write only once.
  The same goes for copyrows.  If the whole row consists of only two colors
  (one foreground and one background), it can be copied by reading once and
  writing once, regardless of the number of planes.  Only if the row consists
  of more than two colors, it will be copied plane by plane.
- On 8bpp board, it acts as 4bpp (16 colors).
- On 4bpp board on the real LUNA-I(68030/20MHz), monochrome scroll is about
  4 times faster even without asm.  Using asm improves it by additional 5%
  (asm is enabled by default).
- By tsutsui@-san's report, even color scroll is about about 2 times faster
  on his 8bpp board on the real LUNA-II(68040).
This was first developped by Y.Sugahara back in late 2019, and was modified
a lot by me in 2022.
http://mail-index.netbsd.org/port-luna68k/2022/09/23/msg72.html


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/luna68k/dev/lunafb.c
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/luna68k/dev/omrasops.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/luna68k/dev/omrasopsvar.h

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



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

2022-09-25 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Sep 25 11:28:40 UTC 2022

Modified Files:
src/sys/arch/luna68k/dev: lunafb.c omrasops.c omrasopsvar.h

Log Message:
lunafb: Improve drawing performance using VRAM ROP features.
- Drawing a character on 4bpp normally needs 4 times writes, but by using
  VRAM ROP actively, it can be reduced to write only once.
  The same goes for copyrows.  If the whole row consists of only two colors
  (one foreground and one background), it can be copied by reading once and
  writing once, regardless of the number of planes.  Only if the row consists
  of more than two colors, it will be copied plane by plane.
- On 8bpp board, it acts as 4bpp (16 colors).
- On 4bpp board on the real LUNA-I(68030/20MHz), monochrome scroll is about
  4 times faster even without asm.  Using asm improves it by additional 5%
  (asm is enabled by default).
- By tsutsui@-san's report, even color scroll is about about 2 times faster
  on his 8bpp board on the real LUNA-II(68040).
This was first developped by Y.Sugahara back in late 2019, and was modified
a lot by me in 2022.
http://mail-index.netbsd.org/port-luna68k/2022/09/23/msg72.html


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/luna68k/dev/lunafb.c
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/luna68k/dev/omrasops.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/luna68k/dev/omrasopsvar.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/luna68k/dev/lunafb.c
diff -u src/sys/arch/luna68k/dev/lunafb.c:1.46 src/sys/arch/luna68k/dev/lunafb.c:1.47
--- src/sys/arch/luna68k/dev/lunafb.c:1.46	Thu Jul 14 20:13:21 2022
+++ src/sys/arch/luna68k/dev/lunafb.c	Sun Sep 25 11:28:40 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: lunafb.c,v 1.46 2022/07/14 20:13:21 tsutsui Exp $ */
+/* $NetBSD: lunafb.c,v 1.47 2022/09/25 11:28:40 isaki Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: lunafb.c,v 1.46 2022/07/14 20:13:21 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lunafb.c,v 1.47 2022/09/25 11:28:40 isaki Exp $");
 
 #include 
 #include 
@@ -76,6 +76,8 @@ struct bt458 {
 
 #define	OMFB_RFCNT	BMAP_RFCNT	/* video h-origin/v-origin */
 #define	OMFB_RAMDAC	BMAP_PALLET2	/* Bt454/Bt458 RAMDAC */
+#define	OMFB_FB_WADDR	(BMAP_BMP + 8)	/* common bitmap plane */
+#define	OMFB_FB_RADDR	(BMAP_BMAP0 + 8)/* bitmap plane #0 */
 
 #define	OMFB_SIZE	(BMAP_FN0 - BMAP_BMP + PAGE_SIZE)
 
@@ -173,6 +175,8 @@ CFATTACH_DECL_NEW(fb, sizeof(struct omfb
 
 extern int hwplanemask;	/* hardware planemask; retrieved at boot */
 
+int hwplanecount;	/* for omrasops */
+
 static int omfb_console;
 int  omfb_cnattach(void);
 
@@ -456,7 +460,7 @@ omfb_resetcmap(struct om_hwdevconfig *dc
 static void
 omfb_getdevconfig(paddr_t paddr, struct om_hwdevconfig *dc)
 {
-	int bpp, i;
+	int i;
 	struct rasops_info *ri;
 	union {
 		struct { short h, v; } p;
@@ -465,21 +469,21 @@ omfb_getdevconfig(paddr_t paddr, struct 
 
 	switch (hwplanemask) {
 	case 0xff:
-		bpp = 8;	/* XXX check monochrome bit in DIPSW */
+		hwplanecount = 8;	/* XXX check monochrome bit in DIPSW */
 		break;
 	default:
 	case 0x0f:
-		bpp = 4;	/* XXX check monochrome bit in DIPSW */
+		hwplanecount = 4;	/* XXX check monochrome bit in DIPSW */
 		break;
 	case 1:
-		bpp = 1;
+		hwplanecount = 1;
 		break;
 	}
 	dc->dc_wid = 1280;
 	dc->dc_ht = 1024;
-	dc->dc_depth = bpp;
+	dc->dc_depth = hwplanecount;
 	dc->dc_rowbytes = 2048 / 8;
-	dc->dc_cmsize = (bpp == 1) ? 0 : 1 << bpp;
+	dc->dc_cmsize = (hwplanecount == 1) ? 0 : 1 << hwplanecount;
 	dc->dc_videobase = paddr;
 
 	omfb_resetcmap(dc);
@@ -509,7 +513,7 @@ omfb_getdevconfig(paddr_t paddr, struct 
 		ri->ri_flg |= RI_NO_AUTO;
 	ri->ri_hw = dc;
 
-	if (bpp == 4 || bpp == 8)
+	if (hwplanecount == 4 || hwplanecount == 8)
 		omrasops4_init(ri, 34, 80);
 	else
 		omrasops1_init(ri, 34, 80);

Index: src/sys/arch/luna68k/dev/omrasops.c
diff -u src/sys/arch/luna68k/dev/omrasops.c:1.22 src/sys/arch/luna68k/dev/omrasops.c:1.23
--- src/sys/arch/luna68k/dev/omrasops.c:1.22	Sun Sep 25 11:22:36 2022
+++ src/sys/arch/luna68k/dev/omrasops.c	Sun Sep 25 11:28:40 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: omrasops.c,v 1.22 2022/09/25 11:22:36 isaki Exp $ */
+/* $NetBSD: omrasops.c,v 1.23 2022/09/25 11:28:40 isaki Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: omrasops.c,v 1.22 2022/09/25 11:22:36 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: omrasops.c,v 1.23 2022/09/25 11:28:40 isaki Exp $");
 
 /*
  * Designed speficically for 'm68k bitorder';
@@ -41,6 +41,15 @@ __KERNEL_RCSID(0, "$NetBSD: omrasops.c,v
  *	- first column is at 32bit aligned address,
  *	- font glyphs are stored in 32bit padded.
  */
+/*
+ * BMSEL affects both of
+ * 1) which plane a 

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

2022-09-25 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Sep 25 11:22:36 UTC 2022

Modified Files:
src/sys/arch/luna68k/dev: omrasops.c

Log Message:
Cosmetic changes.  Fix a typo in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/luna68k/dev/omrasops.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/luna68k/dev/omrasops.c
diff -u src/sys/arch/luna68k/dev/omrasops.c:1.21 src/sys/arch/luna68k/dev/omrasops.c:1.22
--- src/sys/arch/luna68k/dev/omrasops.c:1.21	Wed Jul 31 02:09:02 2019
+++ src/sys/arch/luna68k/dev/omrasops.c	Sun Sep 25 11:22:36 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: omrasops.c,v 1.21 2019/07/31 02:09:02 rin Exp $ */
+/* $NetBSD: omrasops.c,v 1.22 2022/09/25 11:22:36 isaki Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: omrasops.c,v 1.21 2019/07/31 02:09:02 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: omrasops.c,v 1.22 2022/09/25 11:22:36 isaki Exp $");
 
 /*
  * Designed speficically for 'm68k bitorder';
@@ -80,7 +80,7 @@ static int	omrasops_init(struct rasops_i
 
 /*
  * macros to handle unaligned bit copy ops.
- * See src/sys/dev/rasops/rasops_mask.h for MI version.
+ * See src/sys/dev/rasops/rasops_masks.h for MI version.
  * Also refer src/sys/arch/hp300/dev/maskbits.h.
  * (which was implemented for ancient src/sys/arch/hp300/dev/grf_hy.c)
  */
@@ -97,7 +97,7 @@ static int	omrasops_init(struct rasops_i
 	asm("bfins %3,%0{%1:%2}"	\
 	: "+o" (*(uint32_t *)(pdst))\
 	: "di" (x), "di" (w), "d" (src)\
-	: "memory" );
+	: "memory" )
 
 #define	GETBITS(psrc, x, w, dst)	FASTGETBITS(psrc, x, w, dst)
 #define	PUTBITS(src, x, w, pdst)	FASTPUTBITS(src, x, w, pdst)
@@ -629,7 +629,7 @@ om1_copycols(void *cookie, int startrow,
 
 	lmask = (db == 0) ? 0 : ALL1BITS >> db;
 	eb = (db + w) & ALIGNMASK;
-	rmask = (eb == 0) ? 0 : ALL1BITS << (32 - eb); 
+	rmask = (eb == 0) ? 0 : ALL1BITS << (32 - eb);
 	lnum = (32 - db) & ALIGNMASK;
 	rnum = (dstx + w) & ALIGNMASK;
 
@@ -765,7 +765,7 @@ om4_copycols(void *cookie, int startrow,
 
 	lmask = (db == 0) ? 0 : ALL1BITS >> db;
 	eb = (db + w) & ALIGNMASK;
-	rmask = (eb == 0) ? 0 : ALL1BITS << (32 - eb); 
+	rmask = (eb == 0) ? 0 : ALL1BITS << (32 - eb);
 	lnum = (32 - db) & ALIGNMASK;
 	rnum = (dstx + w) & ALIGNMASK;
 



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

2022-09-25 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sun Sep 25 11:22:36 UTC 2022

Modified Files:
src/sys/arch/luna68k/dev: omrasops.c

Log Message:
Cosmetic changes.  Fix a typo in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/luna68k/dev/omrasops.c

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



CVS commit: src/tests/dev/audio

2022-08-13 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 13 07:22:41 UTC 2022

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

Log Message:
audiotest: Add two tests for AUDIO_SETINFO after mmap.
These tests affect only standalone test, not atf.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 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.26 src/tests/dev/audio/audiotest.c:1.27
--- src/tests/dev/audio/audiotest.c:1.26	Sat Aug 13 07:19:15 2022
+++ src/tests/dev/audio/audiotest.c	Sat Aug 13 07:22:40 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiotest.c,v 1.26 2022/08/13 07:19:15 isaki Exp $	*/
+/*	$NetBSD: audiotest.c,v 1.27 2022/08/13 07:22:40 isaki Exp $	*/
 
 /*
  * Copyright (C) 2019 Tetsuya Isaki. All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: audiotest.c,v 1.26 2022/08/13 07:19:15 isaki Exp $");
+__RCSID("$NetBSD: audiotest.c,v 1.27 2022/08/13 07:22:40 isaki Exp $");
 
 #include 
 #include 
@@ -5870,6 +5870,102 @@ DEF(AUDIO_SETINFO_gain_balance)
 	XP_SYS_EQ(0, r);
 }
 
+/*
+ * Changing track formats after mmap should fail.
+ */
+DEF(AUDIO_SETINFO_mmap_enc)
+{
+	struct audio_info ai;
+	void *ptr;
+	int fd;
+	int r;
+
+	TEST("AUDIO_SETINFO_mmap");
+
+#if !defined(NO_RUMP)
+	if (use_rump) {
+		XP_SKIP("rump doesn't support mmap");
+		return;
+	}
+#endif
+
+	fd = OPEN(devaudio, O_WRONLY);
+	REQUIRED_SYS_OK(fd);
+
+	ptr = MMAP(NULL, 1, PROT_WRITE, MAP_FILE, fd, 0);
+	XP_SYS_PTR(0, ptr);
+
+	/*
+	 * SETINFO after mmap should fail.
+	 * NetBSD9 changes errno.
+	 */
+	AUDIO_INITINFO();
+	ai.play.channels = 2;
+	r = IOCTL(fd, AUDIO_SETINFO, , "channels=2");
+	if (netbsd < 9) {
+		XP_SYS_NG(EINVAL, r);
+	} else {
+		XP_SYS_NG(EIO, r);
+	}
+
+	r = CLOSE(fd);
+	XP_SYS_EQ(0, r);
+
+	reset_after_mmap();
+}
+
+/*
+ * Even after mmap, changing pause should succeed.
+ */
+DEF(AUDIO_SETINFO_mmap_pause)
+{
+	struct audio_info ai;
+	void *ptr;
+	int fd;
+	int r;
+
+	TEST("AUDIO_SETINFO_mmap");
+
+#if !defined(NO_RUMP)
+	if (use_rump) {
+		XP_SKIP("rump doesn't support mmap");
+		return;
+	}
+#endif
+
+	fd = OPEN(devaudio, O_WRONLY);
+	REQUIRED_SYS_OK(fd);
+
+	ptr = MMAP(NULL, 1, PROT_WRITE, MAP_FILE, fd, 0);
+	XP_SYS_PTR(0, ptr);
+
+	/* SETINFO after mmap should fail */
+	AUDIO_INITINFO();
+	ai.play.pause = 1;
+	r = IOCTL(fd, AUDIO_SETINFO, , "set pause");
+	XP_SYS_EQ(0, r);
+
+	AUDIO_INITINFO();
+	r = IOCTL(fd, AUDIO_GETBUFINFO, , "get pause");
+	XP_SYS_EQ(0, r);
+
+	XP_EQ(1, ai.play.pause);
+
+	/*
+	 * Unpause before close.  Unless, subsequent audioplay(1) which use
+	 * /dev/sound by default will pause...
+	 */
+	AUDIO_INITINFO();
+	ai.play.pause = 0;
+	r = IOCTL(fd, AUDIO_SETINFO, , "reset pause");
+	XP_SYS_EQ(0, r);
+
+	r = CLOSE(fd);
+	XP_SYS_EQ(0, r);
+
+	reset_after_mmap();
+}
+
 #define NENC	(AUDIO_ENCODING_AC3 + 1)
 #define NPREC	(5)
 /*
@@ -7221,6 +7317,8 @@ struct testentry testtable[] = {
 	ENT(AUDIO_SETINFO_pause_RDWR_3),
 	ENT(AUDIO_SETINFO_gain),
 	ENT(AUDIO_SETINFO_gain_balance),
+/**/	ENT(AUDIO_SETINFO_mmap_enc),	// XXX rump doesn't support mmap
+/**/	ENT(AUDIO_SETINFO_mmap_pause),	// XXX rump doesn't support mmap
 	ENT(AUDIO_GETENC_range),
 	ENT(AUDIO_GETENC_error),
 	ENT(AUDIO_ERROR_RDONLY),



CVS commit: src/tests/dev/audio

2022-08-13 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 13 07:22:41 UTC 2022

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

Log Message:
audiotest: Add two tests for AUDIO_SETINFO after mmap.
These tests affect only standalone test, not atf.


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



CVS commit: src/tests/dev/audio

2022-08-13 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 13 07:19:16 UTC 2022

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

Log Message:
audiotest: Fix typo in comments.


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



CVS commit: src/tests/dev/audio

2022-08-13 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 13 07:19:16 UTC 2022

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

Log Message:
audiotest: Fix typo in comments.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 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.25 src/tests/dev/audio/audiotest.c:1.26
--- src/tests/dev/audio/audiotest.c:1.25	Sat Aug 13 07:14:40 2022
+++ src/tests/dev/audio/audiotest.c	Sat Aug 13 07:19:15 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiotest.c,v 1.25 2022/08/13 07:14:40 isaki Exp $	*/
+/*	$NetBSD: audiotest.c,v 1.26 2022/08/13 07:19:15 isaki Exp $	*/
 
 /*
  * Copyright (C) 2019 Tetsuya Isaki. All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: audiotest.c,v 1.25 2022/08/13 07:14:40 isaki Exp $");
+__RCSID("$NetBSD: audiotest.c,v 1.26 2022/08/13 07:19:15 isaki Exp $");
 
 #include 
 #include 
@@ -7106,29 +7106,29 @@ struct testentry testtable[] = {
 	ENT(drain_incomplete),
 	ENT(drain_pause),
 	ENT(drain_onrec),
-/**/	ENT(mmap_mode_RDONLY_NONE),	// XXX rump doesn't supprot mmap
-/**/	ENT(mmap_mode_RDONLY_READ),	// XXX rump doesn't supprot mmap
-/**/	ENT(mmap_mode_RDONLY_WRITE),	// XXX rump doesn't supprot mmap
-/**/	ENT(mmap_mode_RDONLY_READWRITE),// XXX rump doesn't supprot mmap
-/**/	ENT(mmap_mode_WRONLY_NONE),	// XXX rump doesn't supprot mmap
-/**/	ENT(mmap_mode_WRONLY_READ),	// XXX rump doesn't supprot mmap
-/**/	ENT(mmap_mode_WRONLY_WRITE),	// XXX rump doesn't supprot mmap
-/**/	ENT(mmap_mode_WRONLY_READWRITE),// XXX rump doesn't supprot mmap
-/**/	ENT(mmap_mode_RDWR_NONE),	// XXX rump doesn't supprot mmap
-/**/	ENT(mmap_mode_RDWR_READ),	// XXX rump doesn't supprot mmap
-/**/	ENT(mmap_mode_RDWR_WRITE),	// XXX rump doesn't supprot mmap
-/**/	ENT(mmap_mode_RDWR_READWRITE),	// XXX rump doesn't supprot mmap
-/**/	ENT(mmap_len_0),		// XXX rump doesn't supprot mmap
-/**/	ENT(mmap_len_1),		// XXX rump doesn't supprot mmap
-/**/	ENT(mmap_len_2),		// XXX rump doesn't supprot mmap
-/**/	ENT(mmap_len_3),		// XXX rump doesn't supprot mmap
-/**/	ENT(mmap_len_4),		// XXX rump doesn't supprot mmap
-/**/	ENT(mmap_len_5),		// XXX rump doesn't supprot mmap
-/**/	ENT(mmap_len_6),		// XXX rump doesn't supprot mmap
-/**/	ENT(mmap_len_7),		// XXX rump doesn't supprot mmap
-/**/	ENT(mmap_len_8),		// XXX rump doesn't supprot mmap
-/**/	ENT(mmap_twice),		// XXX rump doesn't supprot mmap
-/**/	ENT(mmap_multi),		// XXX rump doesn't supprot mmap
+/**/	ENT(mmap_mode_RDONLY_NONE),	// XXX rump doesn't support mmap
+/**/	ENT(mmap_mode_RDONLY_READ),	// XXX rump doesn't support mmap
+/**/	ENT(mmap_mode_RDONLY_WRITE),	// XXX rump doesn't support mmap
+/**/	ENT(mmap_mode_RDONLY_READWRITE),// XXX rump doesn't support mmap
+/**/	ENT(mmap_mode_WRONLY_NONE),	// XXX rump doesn't support mmap
+/**/	ENT(mmap_mode_WRONLY_READ),	// XXX rump doesn't support mmap
+/**/	ENT(mmap_mode_WRONLY_WRITE),	// XXX rump doesn't support mmap
+/**/	ENT(mmap_mode_WRONLY_READWRITE),// XXX rump doesn't support mmap
+/**/	ENT(mmap_mode_RDWR_NONE),	// XXX rump doesn't support mmap
+/**/	ENT(mmap_mode_RDWR_READ),	// XXX rump doesn't support mmap
+/**/	ENT(mmap_mode_RDWR_WRITE),	// XXX rump doesn't support mmap
+/**/	ENT(mmap_mode_RDWR_READWRITE),	// XXX rump doesn't support mmap
+/**/	ENT(mmap_len_0),		// XXX rump doesn't support mmap
+/**/	ENT(mmap_len_1),		// XXX rump doesn't support mmap
+/**/	ENT(mmap_len_2),		// XXX rump doesn't support mmap
+/**/	ENT(mmap_len_3),		// XXX rump doesn't support mmap
+/**/	ENT(mmap_len_4),		// XXX rump doesn't support mmap
+/**/	ENT(mmap_len_5),		// XXX rump doesn't support mmap
+/**/	ENT(mmap_len_6),		// XXX rump doesn't support mmap
+/**/	ENT(mmap_len_7),		// XXX rump doesn't support mmap
+/**/	ENT(mmap_len_8),		// XXX rump doesn't support mmap
+/**/	ENT(mmap_twice),		// XXX rump doesn't support mmap
+/**/	ENT(mmap_multi),		// XXX rump doesn't support mmap
 	ENT(poll_mode_RDONLY_IN),
 	ENT(poll_mode_RDONLY_OUT),
 	ENT(poll_mode_RDONLY_INOUT),



CVS commit: src/tests/dev/audio

2022-08-13 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 13 07:14:40 UTC 2022

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

Log Message:
audiotest: Separate mmap_len test by parameters.
This change affects only standalone test, not atf.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 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.24 src/tests/dev/audio/audiotest.c:1.25
--- src/tests/dev/audio/audiotest.c:1.24	Sun Aug  7 10:12:19 2022
+++ src/tests/dev/audio/audiotest.c	Sat Aug 13 07:14:40 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiotest.c,v 1.24 2022/08/07 10:12:19 andvar Exp $	*/
+/*	$NetBSD: audiotest.c,v 1.25 2022/08/13 07:14:40 isaki Exp $	*/
 
 /*
  * Copyright (C) 2019 Tetsuya Isaki. All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: audiotest.c,v 1.24 2022/08/07 10:12:19 andvar Exp $");
+__RCSID("$NetBSD: audiotest.c,v 1.25 2022/08/13 07:14:40 isaki Exp $");
 
 #include 
 #include 
@@ -1382,6 +1382,7 @@ void test_open_multiuser(bool);
 void test_rdwr_fallback(int, bool, bool);
 void test_rdwr_two(int, int);
 void test_mmap_mode(int, int);
+void test_mmap_len(size_t, off_t, int);
 void test_poll_mode(int, int, int);
 void test_poll_in_open(const char *);
 void test_kqueue_mode(int, int, int);
@@ -2688,20 +2689,25 @@ DEF(mmap_mode_RDWR_READWRITE)	{ test_mma
 
 /*
  * Check mmap()'s length and offset.
+ *
+ * Actual len and offset cannot be determined before open.  So that,
+ * pass pre-defined constant as argument, and convert it after open.
  */
-DEF(mmap_len)
+#define LS	(100)	/* lsize */
+#define LS1	(101)	/* lsize + 1 */
+void
+test_mmap_len(size_t len, off_t offset, int exp)
 {
 	struct audio_info ai;
 	int fd;
 	int r;
-	size_t len;
-	off_t offset;
+	size_t plen;
 	void *ptr;
 	int bufsize;
 	int pagesize;
 	int lsize;
 
-	TEST("mmap_len");
+	TEST("mmap_len(%zd, %jd, %d)", len, offset, exp);
 	if ((props & AUDIO_PROP_MMAP) == 0) {
 		XP_SKIP("This test is only for mmap-able device");
 		return;
@@ -2713,8 +2719,8 @@ DEF(mmap_len)
 	}
 #endif
 
-	len = sizeof(pagesize);
-	r = SYSCTLBYNAME("hw.pagesize", , , NULL, 0);
+	plen = sizeof(pagesize);
+	r = SYSCTLBYNAME("hw.pagesize", , , NULL, 0);
 	REQUIRED_SYS_EQ(0, r);
 
 	fd = OPEN(devaudio, O_WRONLY);
@@ -2730,49 +2736,32 @@ DEF(mmap_len)
 	 * I'm not sure.
 	 */
 	lsize = roundup2(bufsize, pagesize);
-	struct {
-		size_t len;
-		off_t offset;
-		int exp;
-	} table[] = {
-		/* len offset	expected */
-
-		{ 0,	0,	0 },		/* len is 0  */
-		{ 1,	0,	0 },		/* len is smaller than lsize */
-		{ lsize, 0,	0 },		/* len is the same as lsize */
-		{ lsize + 1, 0,	EOVERFLOW },	/* len is larger */
-
-		{ 0, -1,	EINVAL },	/* offset is negative */
-		{ 0, lsize,	0 },		/* pointless param but ok */
-		{ 0, lsize + 1,	EOVERFLOW },	/* exceed */
-		{ 1, lsize,	EOVERFLOW },	/* exceed */
 
-		/*
-		 * When you treat offset as 32bit, offset will be 0
-		 * and thus it incorrectly succeeds.
-		 */
-		{ lsize,	1ULL<<32,	EOVERFLOW },
-	};
+	/* Here, lsize can be assigned */
+	if (len == LS) {
+		len = lsize;
+	} else if (len == LS1) {
+		len = lsize + 1;
+	}
+	if (offset == LS) {
+		offset = lsize;
+	} else if (offset == LS1) {
+		offset = lsize + 1;
+	}
 
-	for (int i = 0; i < (int)__arraycount(table); i++) {
-		len = table[i].len;
-		offset = table[i].offset;
-		int exp = table[i].exp;
-
-		ptr = MMAP(NULL, len, PROT_WRITE, MAP_FILE, fd, offset);
-		if (exp == 0) {
-			XP_SYS_PTR(0, ptr);
-		} else {
-			/* NetBSD8 introduces EOVERFLOW */
-			if (netbsd < 8 && exp == EOVERFLOW)
-exp = EINVAL;
-			XP_SYS_PTR(exp, ptr);
-		}
+	ptr = MMAP(NULL, len, PROT_WRITE, MAP_FILE, fd, offset);
+	if (exp == 0) {
+		XP_SYS_PTR(0, ptr);
+	} else {
+		/* NetBSD8 introduces EOVERFLOW */
+		if (netbsd < 8 && exp == EOVERFLOW)
+			exp = EINVAL;
+		XP_SYS_PTR(exp, ptr);
+	}
 
-		if (ptr != MAP_FAILED) {
-			r = MUNMAP(ptr, len);
-			XP_SYS_EQ(0, r);
-		}
+	if (ptr != MAP_FAILED) {
+		r = MUNMAP(ptr, len);
+		XP_SYS_EQ(0, r);
 	}
 
 	r = CLOSE(fd);
@@ -2780,6 +2769,21 @@ DEF(mmap_len)
 
 	reset_after_mmap();
 }
+#define f(l, o, e)	test_mmap_len(l, o, e)
+DEF(mmap_len_0)	{ f(0,   0,   0); }		/* len is 0 */
+DEF(mmap_len_1)	{ f(1,   0,   0); }		/* len is smaller than lsize */
+DEF(mmap_len_2)	{ f(LS,  0,   0); }		/* len is the same as lsize */
+DEF(mmap_len_3)	{ f(LS1, 0,   EOVERFLOW); }	/* len is larger */
+DEF(mmap_len_4)	{ f(0,   -1,  EINVAL); }	/* offset is negative */
+DEF(mmap_len_5)	{ f(0,   LS,  0); }		/* pointless param but ok */
+DEF(mmap_len_6)	{ f(0,   LS1, EOVERFLOW); }	/* exceed */
+DEF(mmap_len_7)	{ f(1,   LS,  EOVERFLOW); }	/* exceed */
+/*
+ * When you treat the offset as 32bit, offset will be 0 and thus it
+

CVS commit: src/tests/dev/audio

2022-08-13 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 13 07:14:40 UTC 2022

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

Log Message:
audiotest: Separate mmap_len test by parameters.
This change affects only standalone test, not atf.


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



CVS commit: src/sys/dev/audio

2022-08-13 Thread Tetsuya Isaki
)
 	 *Therefore it maps 15 * 4K pages and usrbuf->capacity = 61440.
 	 */
-	oldblksize = track->usrbuf_blksize;
 	track->usrbuf_blksize = frametobyte(>usrbuf.fmt,
 	frame_per_block(track->mixer, >usrbuf.fmt));
 	track->usrbuf.head = 0;
 	track->usrbuf.used = 0;
 	if (is_playback) {
-		if (track->usrbuf_blksize * AUMINNOBLK > 65536)
-			newbufsize = track->usrbuf_blksize * AUMINNOBLK;
-		else
+		newbufsize = track->usrbuf_blksize * AUMINNOBLK;
+		if (newbufsize < 65536)
 			newbufsize = rounddown(65536, track->usrbuf_blksize);
+		newvsize = roundup2(newbufsize, PAGE_SIZE);
 	} else {
 		newbufsize = track->usrbuf_blksize;
+		newvsize = track->usrbuf_blksize;
 	}
-	if (track->usrbuf_blksize != oldblksize) {
-		error = audio_realloc_usrbuf(track, newbufsize);
-		if (error) {
-			device_printf(sc->sc_dev, "malloc usrbuf(%d) failed\n",
-			newbufsize);
-			goto error;
+	/*
+	 * Reallocate only if the number of pages changes.
+	 * This is because we expect kmem to allocate memory on per page
+	 * basis if the request size is about 64KB.
+	 */
+	if (newvsize != track->usrbuf_allocsize) {
+		if (track->usrbuf_allocsize != 0) {
+			kmem_free(track->usrbuf.mem, track->usrbuf_allocsize);
 		}
+		TRACET(2, track, "usrbuf_allocsize %d -> %d",
+		track->usrbuf_allocsize, newvsize);
+		track->usrbuf.mem = kmem_alloc(newvsize, KM_SLEEP);
+		track->usrbuf_allocsize = newvsize;
 	}
+	track->usrbuf.capacity = newbufsize;
 
 	/* Recalc water mark. */
 	if (is_playback) {

Index: src/sys/dev/audio/audiodef.h
diff -u src/sys/dev/audio/audiodef.h:1.19 src/sys/dev/audio/audiodef.h:1.20
--- src/sys/dev/audio/audiodef.h:1.19	Sat Apr 23 07:55:07 2022
+++ src/sys/dev/audio/audiodef.h	Sat Aug 13 06:47:41 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiodef.h,v 1.19 2022/04/23 07:55:07 isaki Exp $	*/
+/*	$NetBSD: audiodef.h,v 1.20 2022/08/13 06:47:41 isaki Exp $	*/
 
 /*
  * Copyright (C) 2017 Tetsuya Isaki. All rights reserved.
@@ -119,7 +119,7 @@ struct audio_track {
 
 	audio_ring_t	usrbuf;		/* user i/o buffer */
 	u_int		usrbuf_blksize;	/* usrbuf block size in bytes */
-	struct uvm_object *uobj;
+	u_int		usrbuf_allocsize; /* allocation size in bytes */
 	bool		mmapped;	/* device is mmap()-ed */
 	u_int		usrbuf_usedhigh;/* high water mark in bytes */
 	u_int		usrbuf_usedlow;	/* low water mark in bytes */



CVS commit: src/sys/dev/audio

2022-08-13 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Aug 13 06:47:41 UTC 2022

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

Log Message:
audio: Rework about usrbuf allocation.
- Allocate the usrbuf from kmem(9) instead of uvm(9).  The usrbuf has used
  uvm(9), in case mmap(2) might be issued later.  However, despite the most
  apps don't use mmap(2), allocating (and reallocating) uvm(9) every time
  would be expensive.  In addition, uvm(9) for recording usrbuf was totally
  pointless now.
- For playback, the usrbuf memory will be allocated in pages.  Because the
  usrbuf for playback is mostly near 64KB for backward compatibility.
  This will reduce reallocation especially from the initial ulaw to the most
  commonly used format like slinear16/2ch/48kHz.
- When mmap(2) is called, it will replace the playback usrbuf from kmem(9) to
  uvm(9).
- Prohibit changing playback format once mmap(2) is called.
  It follows netbsd-7.
- For recording, the usrbuf memory will be allocated in the requested size
  every time as before.  Because the usrbuf for recording is only one block
  and is enough small to the page in the most case.
Inspired by PR kern/56947.


To generate a diff of this commit:
cvs rdiff -u -r1.134 -r1.135 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.19 -r1.20 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.



Re: CVS commit: src/sys/arch/m68k/m68k

2022-07-28 Thread Tetsuya Isaki
At Tue, 26 Jul 2022 09:52:40 -0700,
Chuck Silvers wrote:
> > This commit breaks usr.sbin/crash on m68k.
> > curlwp is defined only in _KERNEL.  usr.sbin/crash defines _KMEMUSER
> > but not _KERNEL.
> > 
> > Would you look into?
> 
> I fixed it now, sorry about that.

Thank you!
---
Tetsuya Isaki 


Re: CVS commit: src/sys/arch/m68k/m68k

2022-07-26 Thread Tetsuya Isaki
At Mon, 25 Jul 2022 01:59:26 +,
Chuck Silvers wrote:
> Module Name:  src
> Committed By: chs
> Date: Mon Jul 25 01:59:26 UTC 2022
> 
> Modified Files:
>   src/sys/arch/m68k/m68k: db_trace.c
> 
> Log Message:
> use the pcb of the thread we are tracing rather than always curlwp.
> 
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.59 -r1.60 src/sys/arch/m68k/m68k/db_trace.c

This commit breaks usr.sbin/crash on m68k.
curlwp is defined only in _KERNEL.  usr.sbin/crash defines _KMEMUSER
but not _KERNEL.

Would you look into?

Thanks,
---
Tetsuya Isaki 



CVS commit: src/sys/arch/x68k

2022-07-15 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Jul 16 04:55:35 UTC 2022

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

Log Message:
The system should halt if the powerdown fails.
On X680x0 hardware, front power button is an alternate switch.
If the power button is left on, the power will not turn off.
In addition, with this change, power_switch_is_off in powsw.c is
no longer necessary.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/x68k/dev/powsw.c
cvs rdiff -u -r1.208 -r1.209 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.



CVS commit: src/sys/arch/x68k

2022-07-15 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Jul 16 04:55:35 UTC 2022

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

Log Message:
The system should halt if the powerdown fails.
On X680x0 hardware, front power button is an alternate switch.
If the power button is left on, the power will not turn off.
In addition, with this change, power_switch_is_off in powsw.c is
no longer necessary.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/x68k/dev/powsw.c
cvs rdiff -u -r1.208 -r1.209 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/dev/powsw.c
diff -u src/sys/arch/x68k/dev/powsw.c:1.3 src/sys/arch/x68k/dev/powsw.c:1.4
--- src/sys/arch/x68k/dev/powsw.c:1.3	Sat Jul 16 04:49:07 2022
+++ src/sys/arch/x68k/dev/powsw.c	Sat Jul 16 04:55:35 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: powsw.c,v 1.3 2022/07/16 04:49:07 isaki Exp $	*/
+/*	$NetBSD: powsw.c,v 1.4 2022/07/16 04:55:35 isaki Exp $	*/
 
 /*
  * Copyright (c) 2011 Tetsuya Isaki. All rights reserved.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: powsw.c,v 1.3 2022/07/16 04:49:07 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: powsw.c,v 1.4 2022/07/16 04:55:35 isaki Exp $");
 
 #include 
 #include 
@@ -50,8 +50,6 @@ __KERNEL_RCSID(0, "$NetBSD: powsw.c,v 1.
 
 #include "ioconf.h"
 
-extern int power_switch_is_off;		/* XXX should be in .h */
-
 //#define POWSW_DEBUG
 
 #if defined(POWSW_DEBUG)
@@ -96,7 +94,6 @@ static void powsw_attach(device_t, devic
 static int  powsw_intr(void *);
 static void powsw_softintr(void *);
 static void powsw_pswitch_event(void *);
-static void powsw_shutdown_check(void *);
 static void powsw_reset_counter(struct powsw_softc *);
 static void powsw_set_aer(struct powsw_softc *, int);
 
@@ -152,9 +149,6 @@ powsw_attach(device_t parent, device_t s
 	callout_init(>sc_callout, 0);
 	callout_setfunc(>sc_callout, powsw_softintr, sc);
 
-	if (shutdownhook_establish(powsw_shutdown_check, sc) == NULL)
-		panic("%s: can't establish shutdown hook", xname);
-
 	if (intio_intr_establish(desc->vector, xname, powsw_intr, sc) < 0)
 		panic("%s: can't establish interrupt", xname);
 
@@ -256,19 +250,6 @@ powsw_pswitch_event(void *arg)
 }
 
 static void
-powsw_shutdown_check(void *arg)
-{
-	struct powsw_softc *sc = arg;
-	int poweroff;
-
-	poweroff = sc->sc_prev;
-	if (poweroff)
-		power_switch_is_off = 1;
-	DPRINTF("powsw_shutdown_check %s = %d\n",
-	device_xname(sc->sc_dev), power_switch_is_off);
-}
-
-static void
 powsw_reset_counter(struct powsw_softc *sc)
 {
 

Index: src/sys/arch/x68k/x68k/machdep.c
diff -u src/sys/arch/x68k/x68k/machdep.c:1.208 src/sys/arch/x68k/x68k/machdep.c:1.209
--- src/sys/arch/x68k/x68k/machdep.c:1.208	Sat Jun 25 08:19:01 2022
+++ src/sys/arch/x68k/x68k/machdep.c	Sat Jul 16 04:55:35 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.208 2022/06/25 08:19:01 isaki Exp $	*/
+/*	$NetBSD: machdep.c,v 1.209 2022/07/16 04:55:35 isaki Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -39,7 +39,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.208 2022/06/25 08:19:01 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.209 2022/07/16 04:55:35 isaki Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -482,7 +482,6 @@ SYSCTL_SETUP(sysctl_machdep_setup, "sysc
 }
 
 int	waittime = -1;
-int	power_switch_is_off = 0;
 
 void
 cpu_reboot(int howto, char *bootstr)
@@ -529,7 +528,6 @@ cpu_reboot(int howto, char *bootstr)
 	/* a) RB_POWERDOWN
 	 *  a1: the power switch is still on
 	 *	Power cannot be removed; simply halt the system (b)
-	 *	Power switch state is checked in shutdown hook
 	 *  a2: the power switch is off
 	 *	Remove the power
 	 * b) RB_HALT
@@ -537,7 +535,7 @@ cpu_reboot(int howto, char *bootstr)
 	 * c) otherwise
 	 *	Reboot
 	 */
-	if (((howto & RB_POWERDOWN) == RB_POWERDOWN) && power_switch_is_off) {
+	if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
 		printf("powering off...\n");
 		delay(100);
 
@@ -548,10 +546,8 @@ cpu_reboot(int howto, char *bootstr)
 		intio_set_sysport_powoff(0x0f);
 		intio_set_sysport_powoff(0x0f);
 		delay(100);
-		printf("WARNING: powerdown failed\n");
-		delay(100);
-		/* PASSTHROUGH even if came back */
-	} else if ((howto & RB_HALT) == RB_HALT) {
+	}
+	if ((howto & RB_HALT) != 0) {
 		printf("System halted.  Hit any key to reboot.\n\n");
 		cnpollc(1);
 		(void)cngetc();



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

2022-07-15 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Jul 16 04:49:07 UTC 2022

Modified Files:
src/sys/arch/x68k/dev: powsw.c

Log Message:
Style fixes.


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

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



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

2022-07-15 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Jul 16 04:49:07 UTC 2022

Modified Files:
src/sys/arch/x68k/dev: powsw.c

Log Message:
Style fixes.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/x68k/dev/powsw.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/dev/powsw.c
diff -u src/sys/arch/x68k/dev/powsw.c:1.2 src/sys/arch/x68k/dev/powsw.c:1.3
--- src/sys/arch/x68k/dev/powsw.c:1.2	Thu May 26 14:33:29 2022
+++ src/sys/arch/x68k/dev/powsw.c	Sat Jul 16 04:49:07 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: powsw.c,v 1.2 2022/05/26 14:33:29 tsutsui Exp $	*/
+/*	$NetBSD: powsw.c,v 1.3 2022/07/16 04:49:07 isaki Exp $	*/
 
 /*
  * Copyright (c) 2011 Tetsuya Isaki. All rights reserved.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: powsw.c,v 1.2 2022/05/26 14:33:29 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: powsw.c,v 1.3 2022/07/16 04:49:07 isaki Exp $");
 
 #include 
 #include 
@@ -55,7 +55,7 @@ extern int power_switch_is_off;		/* XXX 
 //#define POWSW_DEBUG
 
 #if defined(POWSW_DEBUG)
-#define DPRINTF(fmt...)	printf(fmt)
+#define DPRINTF(fmt...)		printf(fmt)
 #define DEBUG_LOG_ADD(c)	sc->sc_log[sc->sc_loglen++] = (c)
 #define DEBUG_LOG_PRINT()	do {	\
 	sc->sc_log[sc->sc_loglen] = '\0';	\
@@ -69,12 +69,12 @@ extern int power_switch_is_off;		/* XXX 
 
 /* mask */
 #define POWSW_ALARM		(0x01)
-#define POWSW_EXTERNAL	(0x02)
+#define POWSW_EXTERNAL		(0x02)
 #define POWSW_FRONT		(0x04)
 
 /* parameter */
-#define POWSW_MAX_TICK	(30)
-#define POWSW_THRESHOLD	(10)
+#define POWSW_MAX_TICK		(30)
+#define POWSW_THRESHOLD		(10)
 
 struct powsw_softc {
 	device_t sc_dev;
@@ -111,7 +111,7 @@ typedef const struct {
 } powsw_desc_t;
 
 static powsw_desc_t powsw_desc[2] = {
-	{ 66, POWSW_FRONT,		"Front Switch", },
+	{ 66, POWSW_FRONT,	"Front Switch", },
 	{ 65, POWSW_EXTERNAL,	"External Power Switch", },
 	/* XXX I'm not sure about alarm bit */
 };
@@ -120,6 +120,7 @@ static powsw_desc_t powsw_desc[2] = {
 static int
 powsw_match(device_t parent, cfdata_t cf, void *aux)
 {
+
 	return 1;
 }
 
@@ -223,7 +224,8 @@ powsw_softintr(void *arg)
 
 		if (sc->sc_last_sw == sc->sc_prev) {
 			/* switch state is not changed, it was a noise */
-			DPRINTF(" ignore(sw=%d,prev=%d)\n", sc->sc_last_sw, sc->sc_prev);
+			DPRINTF(" ignore(sw=%d,prev=%d)\n",
+			sc->sc_last_sw, sc->sc_prev);
 		} else {
 			/* switch state has been changed */
 			sc->sc_prev = sc->sc_last_sw;
@@ -231,7 +233,8 @@ powsw_softintr(void *arg)
 			sysmon_task_queue_sched(0, powsw_pswitch_event, sc);
 		}
 		powsw_reset_counter(sc);
-		mfp_bit_set_ierb(sc->sc_mask);	// enable interrupt
+		/* enable interrupt */
+		mfp_bit_set_ierb(sc->sc_mask);
 	}
 
 	splx(s);
@@ -249,7 +252,7 @@ powsw_pswitch_event(void *arg)
 	poweroff ? "off(PRESS)" : "on(RELEASE)");
 
 	sysmon_pswitch_event(>sc_smpsw,
-		poweroff ? PSWITCH_EVENT_PRESSED : PSWITCH_EVENT_RELEASED);
+	poweroff ? PSWITCH_EVENT_PRESSED : PSWITCH_EVENT_RELEASED);
 }
 
 static void
@@ -262,12 +265,13 @@ powsw_shutdown_check(void *arg)
 	if (poweroff)
 		power_switch_is_off = 1;
 	DPRINTF("powsw_shutdown_check %s = %d\n",
-		device_xname(sc->sc_dev), power_switch_is_off);
+	device_xname(sc->sc_dev), power_switch_is_off);
 }
 
 static void
 powsw_reset_counter(struct powsw_softc *sc)
 {
+
 	sc->sc_last_sw = -1;
 	sc->sc_tick = 0;
 	sc->sc_count = 0;
@@ -279,6 +283,7 @@ powsw_reset_counter(struct powsw_softc *
 static void
 powsw_set_aer(struct powsw_softc *sc, int aer)
 {
+
 	KASSERT(aer == 0 || aer == 1);
 
 	if (aer == 0) {



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

2022-06-25 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Jun 25 08:19:01 UTC 2022

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

Log Message:
Fix build without EXTENDED_MEMORY.


To generate a diff of this commit:
cvs rdiff -u -r1.207 -r1.208 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.207 src/sys/arch/x68k/x68k/machdep.c:1.208
--- src/sys/arch/x68k/x68k/machdep.c:1.207	Sat Oct  9 20:00:42 2021
+++ src/sys/arch/x68k/x68k/machdep.c	Sat Jun 25 08:19:01 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.207 2021/10/09 20:00:42 tsutsui Exp $	*/
+/*	$NetBSD: machdep.c,v 1.208 2022/06/25 08:19:01 isaki Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -39,7 +39,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.207 2021/10/09 20:00:42 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.208 2022/06/25 08:19:01 isaki Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -1256,7 +1256,9 @@ cpu_intr_p(void)
 int
 mm_md_physacc(paddr_t pa, vm_prot_t prot)
 {
+#ifdef EXTENDED_MEMORY
 	int i;
+#endif
 
 	/* Main memory */
 	if (phys_basemem_seg.start <= pa && pa < phys_basemem_seg.end)



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

2022-06-25 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Jun 25 08:19:01 UTC 2022

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

Log Message:
Fix build without EXTENDED_MEMORY.


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



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

2022-06-23 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Thu Jun 23 12:32:22 UTC 2022

Modified Files:
src/sys/arch/x68k/stand/boot: conf.c
src/sys/arch/x68k/stand/libsa: libx68k.h sdcd.c

Log Message:
x68k/stand: Merge {sd,cd}strategy and {sd,cd}close respectively.
For sd and cd devs, only open differs and the rest is the same.
No functional changes intended.
Suggested by tsutsui@ at port-x68k.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/x68k/stand/boot/conf.c
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/x68k/stand/libsa/libx68k.h
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/x68k/stand/libsa/sdcd.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/boot/conf.c
diff -u src/sys/arch/x68k/stand/boot/conf.c:1.12 src/sys/arch/x68k/stand/boot/conf.c:1.13
--- src/sys/arch/x68k/stand/boot/conf.c:1.12	Mon Apr 25 15:12:07 2022
+++ src/sys/arch/x68k/stand/boot/conf.c	Thu Jun 23 12:32:22 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: conf.c,v 1.12 2022/04/25 15:12:07 mlelstv Exp $	*/
+/*	$NetBSD: conf.c,v 1.13 2022/06/23 12:32:22 isaki Exp $	*/
 
 /*
  * Copyright (c) 2001 Minoura Makoto
@@ -40,8 +40,8 @@
 #include "libx68k.h"
 
 struct devsw devsw[] = {
-	{ "sd",	sdstrategy, sdopen, sdclose, noioctl },
-	{ "cd",	cdstrategy, cdopen, cdclose, noioctl },
+	{ "sd",	sdcdstrategy, sdopen, sdcdclose, noioctl },
+	{ "cd",	sdcdstrategy, cdopen, sdcdclose, noioctl },
 	{ "fd",	fdstrategy, fdopen, fdclose, noioctl },
 	{ "nfs", net_strategy, net_open, net_close, net_ioctl },
 	{ 0, 0, 0, 0, 0 }

Index: src/sys/arch/x68k/stand/libsa/libx68k.h
diff -u src/sys/arch/x68k/stand/libsa/libx68k.h:1.7 src/sys/arch/x68k/stand/libsa/libx68k.h:1.8
--- src/sys/arch/x68k/stand/libsa/libx68k.h:1.7	Sun Jun 26 04:17:17 2016
+++ src/sys/arch/x68k/stand/libsa/libx68k.h	Thu Jun 23 12:32:22 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: libx68k.h,v 1.7 2016/06/26 04:17:17 isaki Exp $	*/
+/*	$NetBSD: libx68k.h,v 1.8 2022/06/23 12:32:22 isaki Exp $	*/
 
 /*
  * Copyright (c) 2001 Minoura Makoto
@@ -50,13 +50,11 @@ int parseboot(char *, char **, int *);
 
 /* sdcd.c */
 struct sd_softc;
-int sdstrategy(void *, int, daddr_t, size_t, void *, size_t *);
 int sdopen(struct open_file *, ...);
-int sdclose(struct open_file *);
+int sdcdstrategy(void *, int, daddr_t, size_t, void *, size_t *);
+int sdcdclose(struct open_file *);
 int sd_getbsdpartition(int, int);
-int cdstrategy(void *, int, daddr_t, size_t, void *, size_t *);
 int cdopen(struct open_file *, ...);
-int cdclose(struct open_file *);
 
 /* fd.c */
 int fdstrategy(void *, int, daddr_t, size_t, void *, size_t *);

Index: src/sys/arch/x68k/stand/libsa/sdcd.c
diff -u src/sys/arch/x68k/stand/libsa/sdcd.c:1.17 src/sys/arch/x68k/stand/libsa/sdcd.c:1.18
--- src/sys/arch/x68k/stand/libsa/sdcd.c:1.17	Tue Jun 21 12:43:57 2022
+++ src/sys/arch/x68k/stand/libsa/sdcd.c	Thu Jun 23 12:32:22 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdcd.c,v 1.17 2022/06/21 12:43:57 isaki Exp $	*/
+/*	$NetBSD: sdcd.c,v 1.18 2022/06/23 12:32:22 isaki Exp $	*/
 
 /*
  * Copyright (c) 2001 MINOURA Makoto.
@@ -301,7 +301,7 @@ sdopen(struct open_file *f, ...)
 }
 
 int
-sdclose(struct open_file *f)
+sdcdclose(struct open_file *f)
 {
 
 	dealloc(f->f_devdata, sizeof(struct sdcd_softc));
@@ -309,7 +309,7 @@ sdclose(struct open_file *f)
 }
 
 int
-sdstrategy(void *arg, int rw, daddr_t dblk, size_t size,
+sdcdstrategy(void *arg, int rw, daddr_t dblk, size_t size,
void *buf, size_t *rsize)
 {
 	struct sdcd_softc *sc = arg;
@@ -382,18 +382,3 @@ cdopen(struct open_file *f, ...)
 
 	return 0;
 }
-
-int
-cdclose(struct open_file *f)
-{
-
-	dealloc(f->f_devdata, sizeof(struct sdcd_softc));
-	return 0;
-}
-
-int
-cdstrategy(void *arg, int rw, daddr_t dblk, size_t size,
-   void *buf, size_t *rsize)
-{
-	return sdstrategy(arg, rw, dblk, size, buf, rsize);
-}



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

2022-06-23 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Thu Jun 23 12:32:22 UTC 2022

Modified Files:
src/sys/arch/x68k/stand/boot: conf.c
src/sys/arch/x68k/stand/libsa: libx68k.h sdcd.c

Log Message:
x68k/stand: Merge {sd,cd}strategy and {sd,cd}close respectively.
For sd and cd devs, only open differs and the rest is the same.
No functional changes intended.
Suggested by tsutsui@ at port-x68k.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/x68k/stand/boot/conf.c
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/x68k/stand/libsa/libx68k.h
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/x68k/stand/libsa/sdcd.c

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



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

2022-06-21 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Tue Jun 21 12:45:46 UTC 2022

Modified Files:
src/sys/arch/x68k/stand/boot: version

Log Message:
x68k/stand: Bump boot's version.  Fix blocksize parameter passes to SCSI IOCS.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/x68k/stand/boot/version

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/boot/version
diff -u src/sys/arch/x68k/stand/boot/version:1.8 src/sys/arch/x68k/stand/boot/version:1.9
--- src/sys/arch/x68k/stand/boot/version:1.8	Sat Jun 25 14:35:58 2016
+++ src/sys/arch/x68k/stand/boot/version	Tue Jun 21 12:45:46 2022
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.8 2016/06/25 14:35:58 isaki Exp $
+$NetBSD: version,v 1.9 2022/06/21 12:45:46 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
@@ -14,3 +14,4 @@ is taken as the current.
 	non ASCII keys (CTRL, OPT.1 etc.) are pressed during boot.
 1.6:	Disable slow gunzip CRC32 calculation.
 1.7:	Integrate netboot.
+1.8:	Fix blocksize parameter passes to SCSI IOCS.



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

2022-06-21 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Tue Jun 21 12:45:46 UTC 2022

Modified Files:
src/sys/arch/x68k/stand/boot: version

Log Message:
x68k/stand: Bump boot's version.  Fix blocksize parameter passes to SCSI IOCS.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/x68k/stand/boot/version

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



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

2022-06-21 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Tue Jun 21 12:43:57 UTC 2022

Modified Files:
src/sys/arch/x68k/stand/libsa: sdcd.c

Log Message:
x68k/stand: Correct blocksize in case of CD.
- Fix calculation of the blocksize passes to SCSI IOCS.
- Use three kind of sector size (blocksize) properly; media's sector size,
  DEV_BSIZE from xxstrategy, and Human68k's sector size.
By this change,
- For 512 bytes/sector HDD, no changes are intended.
- For CD, corrects the blocksize (%d5) passes to SCSI IOCS.
  It has worked previously though the blocksize was incorrect.  Now it
  works with correct blocksize.
- As a secondary effect, 256 or 1024 bytes/sector media may work but not
  well tested.
Reviewed by tsutsui@ at port-x68k.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/x68k/stand/libsa/sdcd.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/libsa/sdcd.c
diff -u src/sys/arch/x68k/stand/libsa/sdcd.c:1.16 src/sys/arch/x68k/stand/libsa/sdcd.c:1.17
--- src/sys/arch/x68k/stand/libsa/sdcd.c:1.16	Tue Jun 21 12:20:43 2022
+++ src/sys/arch/x68k/stand/libsa/sdcd.c	Tue Jun 21 12:43:57 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdcd.c,v 1.16 2022/06/21 12:20:43 isaki Exp $	*/
+/*	$NetBSD: sdcd.c,v 1.17 2022/06/21 12:43:57 isaki Exp $	*/
 
 /*
  * Copyright (c) 2001 MINOURA Makoto.
@@ -26,6 +26,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -36,9 +37,14 @@
 
 
 static int current_id = -1;
-static int current_blklen, current_devsize, current_npart;
+static int current_blkbytes;
+static int current_blkshift;
+static int current_devsize, current_npart;
 static struct boot_partinfo partitions[MAXPARTITIONS];
 
+static uint human2blk(uint);
+static uint human2bsd(uint);
+static uint bsd2blk(uint);
 static int readdisklabel(int);
 static int check_unit(int);
 
@@ -48,6 +54,44 @@ static int check_unit(int);
 #define DPRINTF(x)	
 #endif
 
+/*
+ * Convert the number of sectors on Human68k
+ * into the number of blocks on the current device.
+ */
+static uint
+human2blk(uint n)
+{
+	uint blk_per_sect;
+
+	/* Human68k uses 1024 byte/sector. */
+	blk_per_sect = 4 >> current_blkshift;
+	if (blk_per_sect == 0)
+		blk_per_sect = 1;
+	return blk_per_sect * n;
+}
+
+/*
+ * Convert the number of sectors on Human68k
+ * into the number of DEV_BSIZE sectors.
+ */
+static uint
+human2bsd(uint n)
+{
+
+	return n * (1024 / DEV_BSIZE);
+}
+
+/*
+ * Convert the number of DEV_BSIZE sectors
+ * into the number of blocks on the current device.
+ */
+static uint
+bsd2blk(uint n)
+{
+
+	return ((DEV_BSIZE / 256) * n) >> current_blkshift;
+}
+
 static int
 check_unit(int id)
 {
@@ -90,12 +134,13 @@ check_unit(int id)
 			error = EUNIT;
 			goto out;
 		}
-		current_blklen = rcdata->size >> 9;
+		current_blkbytes = rcdata->size;
+		current_blkshift = fls32(current_blkbytes) - 9;
 		current_devsize = rcdata->block;
 	}
 
 	{
-		error = IOCS_S_READ(0, 1, id, current_blklen, buffer);
+		error = IOCS_S_READ(0, 1, id, current_blkshift, buffer);
 		if (error < 0) {
 			error =  EIO;
 			goto out;
@@ -125,15 +170,15 @@ readdisklabel(int id)
 	error = check_unit(id);
 	if (error)
 		return error;
-	if (current_blklen > 4) {
+	if (current_blkbytes > 2048) {
 		printf("FATAL: Unsupported block size %d.\n",
-		256 << current_blklen);
+		current_blkbytes);
 		return ERDLAB;
 	}
 
 	/* Try BSD disklabel first */
 	buffer = alloca(2048);
-	error = IOCS_S_READ(LABELSECTOR, 1, id, current_blklen, buffer);
+	error = IOCS_S_READ(LABELSECTOR, 1, id, current_blkshift, buffer);
 	if (error < 0)
 		return EIO;
 	label = (void *)(buffer + LABELOFFSET);
@@ -149,13 +194,7 @@ readdisklabel(int id)
 	}
 
 	/* Try Human68K-style partition table */
-#if 0
-	/* assumes 512byte/sec */
-	error = IOCS_S_READ(DOSPARTOFF, 2, id, current_blklen, buffer);
-#else
-	error = IOCS_S_READ(8 >> current_blklen, 8 >> current_blklen,
-			id, current_blklen, buffer);
-#endif
+	error = IOCS_S_READ(human2blk(2), 1, id, current_blkshift, buffer);
 	if (error < 0)
 		return EIO;
 	parttbl = (void *)(buffer + DOSBBSECTOR);
@@ -166,9 +205,9 @@ readdisklabel(int id)
 	 current_npart < MAXPARTITIONS && i < 15 && parttbl[i].dp_size;
 	 i++) {
 		partitions[current_npart].start
-			= parttbl[i].dp_start * 2;
+			= human2bsd(parttbl[i].dp_start);
 		partitions[current_npart].size
-			= parttbl[i].dp_size  * 2;
+			= human2bsd(parttbl[i].dp_size);
 		if (++current_npart == RAW_PART) {
 			partitions[current_npart].start = 0;
 			partitions[current_npart].size = -1; /* XXX */
@@ -205,8 +244,7 @@ sd_getbsdpartition(int id, int humanpart
 		return -1;
 	}
 	buffer = alloca(2048);
-	error = IOCS_S_READ(8 >> current_blklen, 8 >> current_blklen,
-			id, current_blklen, buffer);
+	error = IOCS_S_READ(human2blk(2), 1, id, current_blkshift, buffer);
 	if (error < 0) {
 		printf("Reading partition table: %s\n", 

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

2022-06-21 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Tue Jun 21 12:43:57 UTC 2022

Modified Files:
src/sys/arch/x68k/stand/libsa: sdcd.c

Log Message:
x68k/stand: Correct blocksize in case of CD.
- Fix calculation of the blocksize passes to SCSI IOCS.
- Use three kind of sector size (blocksize) properly; media's sector size,
  DEV_BSIZE from xxstrategy, and Human68k's sector size.
By this change,
- For 512 bytes/sector HDD, no changes are intended.
- For CD, corrects the blocksize (%d5) passes to SCSI IOCS.
  It has worked previously though the blocksize was incorrect.  Now it
  works with correct blocksize.
- As a secondary effect, 256 or 1024 bytes/sector media may work but not
  well tested.
Reviewed by tsutsui@ at port-x68k.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/x68k/stand/libsa/sdcd.c

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



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

2022-06-21 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Tue Jun 21 12:20:43 UTC 2022

Modified Files:
src/sys/arch/x68k/stand/libsa: sdcd.c

Log Message:
x68k/stand: Correct a condition expression.
- start is LBA but dblk is relative from this partition.
- The first term was wrong.  It should be '(x & 0x1f) == x', but
  it's more simple to use numerical comparison.
There would have been no impact.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/x68k/stand/libsa/sdcd.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/libsa/sdcd.c
diff -u src/sys/arch/x68k/stand/libsa/sdcd.c:1.15 src/sys/arch/x68k/stand/libsa/sdcd.c:1.16
--- src/sys/arch/x68k/stand/libsa/sdcd.c:1.15	Tue Feb 11 08:06:07 2014
+++ src/sys/arch/x68k/stand/libsa/sdcd.c	Tue Jun 21 12:20:43 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdcd.c,v 1.15 2014/02/11 08:06:07 tsutsui Exp $	*/
+/*	$NetBSD: sdcd.c,v 1.16 2022/06/21 12:20:43 isaki Exp $	*/
 
 /*
  * Copyright (c) 2001 MINOURA Makoto.
@@ -289,7 +289,7 @@ sdstrategy(void *arg, int rw, daddr_t db
 	}
 	nblks = howmany(size, 256 << current_blklen);
 
-	if ((dblk & 0x1f) == 0x1f && (nblks & 0xff) == nblks) {
+	if (start < 0x20 && nblks < 256) {
 		if (rw & F_WRITE)
 			error = IOCS_S_WRITE(start, nblks, current_id,
 			 current_blklen, buf);



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

2022-06-21 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Tue Jun 21 12:20:43 UTC 2022

Modified Files:
src/sys/arch/x68k/stand/libsa: sdcd.c

Log Message:
x68k/stand: Correct a condition expression.
- start is LBA but dblk is relative from this partition.
- The first term was wrong.  It should be '(x & 0x1f) == x', but
  it's more simple to use numerical comparison.
There would have been no impact.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/x68k/stand/libsa/sdcd.c

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



CVS commit: src/sys/dev/audio

2022-04-23 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Apr 23 11:44:01 UTC 2022

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

Log Message:
audio(4): Fix a typo in comment.  Remove several old comments.


To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 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.132 src/sys/dev/audio/audio.c:1.133
--- src/sys/dev/audio/audio.c:1.132	Sat Apr 23 11:30:57 2022
+++ src/sys/dev/audio/audio.c	Sat Apr 23 11:44:01 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.132 2022/04/23 11:30:57 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.133 2022/04/23 11:44:01 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -181,7 +181,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.132 2022/04/23 11:30:57 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.133 2022/04/23 11:44:01 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -3160,7 +3160,6 @@ audio_ioctl(dev_t dev, struct audio_soft
 			audio_exlock_exit(sc);
 			break;
 		}
-		/* XXX TODO: update last_ai if /dev/sound ? */
 		if (ISDEVSOUND(dev))
 			error = audiogetinfo(sc, >sc_ai, 0, file);
 		audio_exlock_exit(sc);
@@ -4514,7 +4513,7 @@ audio_track_init_freq(audio_track_t *tra
 
 		arg = >freq.arg;
 		arg->srcfmt = >fmt;
-		arg->dstfmt = dstfmt;/*_dst->fmt;*/
+		arg->dstfmt = dstfmt;
 		arg->context = track;
 
 		*last_dstp = srcbuf;
@@ -4780,7 +4779,7 @@ audio_track_set_format(audio_track_t *tr
 
 	/*
 	 * On the recording track, expand the input stage buffer, which is
-	 * the closest buffer to rmixer, to NBLKOUT blocks.
+	 * the closest buffer to rmixer, to NBLKIN blocks.
 	 * Note that input buffer may point to outbuf.
 	 */
 	if (!is_playback) {



CVS commit: src/sys/dev/audio

2022-04-23 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Apr 23 11:44:01 UTC 2022

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

Log Message:
audio(4): Fix a typo in comment.  Remove several old comments.


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

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



CVS commit: src/sys/dev/audio

2022-04-23 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Apr 23 11:30:57 UTC 2022

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

Log Message:
audio(4): Clean up about audio_realloc().
- audio_realloc() never returns NULL, so there is no need to check it.
- audio_free() is no point in this case.


To generate a diff of this commit:
cvs rdiff -u -r1.131 -r1.132 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.131 src/sys/dev/audio/audio.c:1.132
--- src/sys/dev/audio/audio.c:1.131	Sat Apr 23 07:55:07 2022
+++ src/sys/dev/audio/audio.c	Sat Apr 23 11:30:57 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.131 2022/04/23 07:55:07 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.132 2022/04/23 11:30:57 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -181,7 +181,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.131 2022/04/23 07:55:07 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.132 2022/04/23 11:30:57 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -3689,7 +3689,8 @@ audio_realloc(void *memblock, size_t byt
 {
 
 	KASSERT(bytes != 0);
-	audio_free(memblock);
+	if (memblock)
+		kern_free(memblock);
 	return kern_malloc(bytes, M_WAITOK);
 }
 
@@ -4776,11 +4777,6 @@ audio_track_set_format(audio_track_t *tr
 		track->outbuf.capacity *= NBLKOUT;
 	len = auring_bytelen(>outbuf);
 	track->outbuf.mem = audio_realloc(track->outbuf.mem, len);
-	if (track->outbuf.mem == NULL) {
-		device_printf(sc->sc_dev, "malloc outbuf(%d) failed\n", len);
-		error = ENOMEM;
-		goto error;
-	}
 
 	/*
 	 * On the recording track, expand the input stage buffer, which is
@@ -5387,12 +5383,6 @@ audio_mixer_init(struct audio_softc *sc,
 		mixer->codecbuf.capacity = mixer->frames_per_block;
 		len = auring_bytelen(>codecbuf);
 		mixer->codecbuf.mem = audio_realloc(mixer->codecbuf.mem, len);
-		if (mixer->codecbuf.mem == NULL) {
-			device_printf(sc->sc_dev,
-			"malloc codecbuf(%d) failed\n", len);
-			error = ENOMEM;
-			goto abort;
-		}
 	}
 
 	/* Succeeded so display it. */



CVS commit: src/sys/dev/audio

2022-04-23 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Apr 23 11:30:57 UTC 2022

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

Log Message:
audio(4): Clean up about audio_realloc().
- audio_realloc() never returns NULL, so there is no need to check it.
- audio_free() is no point in this case.


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

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



CVS commit: src/sys/dev/audio

2022-04-23 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Apr 23 07:55:07 UTC 2022

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

Log Message:
audio(4): Remove no longer used counters.
These were used at very early phase of development.


To generate a diff of this commit:
cvs rdiff -u -r1.130 -r1.131 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.18 -r1.19 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.130 src/sys/dev/audio/audio.c:1.131
--- src/sys/dev/audio/audio.c:1.130	Sat Apr 23 07:43:16 2022
+++ src/sys/dev/audio/audio.c	Sat Apr 23 07:55:07 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.130 2022/04/23 07:43:16 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.131 2022/04/23 07:55:07 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -181,7 +181,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.130 2022/04/23 07:43:16 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.131 2022/04/23 07:55:07 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2825,7 +2825,6 @@ audio_read(struct audio_softc *sc, struc
 			goto abort;
 		}
 		auring_take(usrbuf, bytes);
-		track->useriobytes += bytes;
 		TRACET(3, track, "uiomove(len=%d) usrbuf=%d/%d/C%d",
 		bytes,
 		usrbuf->head, usrbuf->used, usrbuf->capacity);
@@ -2953,7 +2952,6 @@ audio_write(struct audio_softc *sc, stru
 goto abort;
 			}
 			auring_push(usrbuf, len);
-			track->useriobytes += len;
 			TRACET(3, track, "uiomove(len=%d) usrbuf=%d/%d/C%d",
 			len,
 			usrbuf->head, usrbuf->used, usrbuf->capacity);
@@ -4955,9 +4953,6 @@ audio_track_play(audio_track_t *track)
 	"count=%d fpb=%d",
 	count, frame_per_block(track->mixer, >outbuf.fmt));
 
-	/* XXX TODO: is this necessary for now? */
-	int track_count_0 = track->outbuf.used;
-
 	usrbuf = >usrbuf;
 	input = track->input;
 
@@ -5068,12 +5063,6 @@ audio_track_play(audio_track_t *track)
 		}
 	}
 
-	if (track->input == >outbuf) {
-		track->outputcounter = track->inputcounter;
-	} else {
-		track->outputcounter += track->outbuf.used - track_count_0;
-	}
-
 	track->stamp++;
 
 #if defined(AUDIO_DEBUG)
@@ -6389,8 +6378,7 @@ audio_track_drain(struct audio_softc *sc
 	}
 
 	track->pstate = AUDIO_STATE_CLEAR;
-	TRACET(3, track, "done trk_inp=%d trk_out=%d",
-		(int)track->inputcounter, (int)track->outputcounter);
+	TRACET(3, track, "done");
 	return 0;
 }
 

Index: src/sys/dev/audio/audiodef.h
diff -u src/sys/dev/audio/audiodef.h:1.18 src/sys/dev/audio/audiodef.h:1.19
--- src/sys/dev/audio/audiodef.h:1.18	Wed Apr 20 07:11:13 2022
+++ src/sys/dev/audio/audiodef.h	Sat Apr 23 07:55:07 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiodef.h,v 1.18 2022/04/20 07:11:13 isaki Exp $	*/
+/*	$NetBSD: audiodef.h,v 1.19 2022/04/23 07:55:07 isaki Exp $	*/
 
 /*
  * Copyright (C) 2017 Tetsuya Isaki. All rights reserved.
@@ -175,11 +175,7 @@ struct audio_track {
 	audio_state_t	pstate;		/* playback state */
 	bool		is_pause;
 
-	/* Statistic counters. */
-	uint64_t	inputcounter;	/* # of frames input to track */
-	uint64_t	outputcounter;	/* # of frames output from track */
-	uint64_t	useriobytes;	/* # of bytes xfer to/from userland */
-	uint64_t	dropframes;	/* # of frames dropped */
+	uint64_t	dropframes;	/* number of dropped frames */
 	int		eofcounter;	/* count of zero-sized write */
 
 	/*



CVS commit: src/sys/dev/audio

2022-04-23 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Apr 23 07:55:07 UTC 2022

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

Log Message:
audio(4): Remove no longer used counters.
These were used at very early phase of development.


To generate a diff of this commit:
cvs rdiff -u -r1.130 -r1.131 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/audio/audiodef.h

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



CVS commit: src/tests/dev/audio

2022-04-23 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Apr 23 07:47:42 UTC 2022

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

Log Message:
tests: Add tests for AUDIO_GET[IO]OFFS ioctls.
- AUDIO_GETIOFFS_one_{RDONLY,RDWR,WRONLY}
- AUDIO_GETOOFFS_one_{RDONLY,RDWR,WRONLY}
- AUDIO_GETOOFFS_wrap_{RDONLY,RDWR,WRONLY}
- AUDIO_GETOOFFS_flush_{RDONLY,RDWR,WRONLY}
- AUDIO_GETOOFFS_set_{RDONLY,RDWR,WRONLY}


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 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.18 src/tests/dev/audio/audiotest.c:1.19
--- src/tests/dev/audio/audiotest.c:1.18	Fri Dec 10 20:36:05 2021
+++ src/tests/dev/audio/audiotest.c	Sat Apr 23 07:47:42 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiotest.c,v 1.18 2021/12/10 20:36:05 andvar Exp $	*/
+/*	$NetBSD: audiotest.c,v 1.19 2022/04/23 07:47:42 isaki Exp $	*/
 
 /*
  * Copyright (C) 2019 Tetsuya Isaki. All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: audiotest.c,v 1.18 2021/12/10 20:36:05 andvar Exp $");
+__RCSID("$NetBSD: audiotest.c,v 1.19 2022/04/23 07:47:42 isaki Exp $");
 
 #include 
 #include 
@@ -1395,6 +1395,11 @@ int getenc_make_table(int, int[][5]);
 void xp_getenc(int[][5], int, int, int, struct audio_prinfo *);
 void getenc_check_encodings(int, int[][5]);
 void test_AUDIO_ERROR(int);
+void test_AUDIO_GETIOFFS_one(int);
+void test_AUDIO_GETOOFFS_one(int);
+void test_AUDIO_GETOOFFS_wrap(int);
+void test_AUDIO_GETOOFFS_flush(int);
+void test_AUDIO_GETOOFFS_set(int);
 void test_audioctl_open_1(int, int);
 void test_audioctl_open_2(int, int);
 void try_audioctl_open_multiuser(const char *, const char *);
@@ -6175,6 +6180,553 @@ DEF(AUDIO_ERROR_WRONLY)	{ test_AUDIO_ERR
 DEF(AUDIO_ERROR_RDWR)	{ test_AUDIO_ERROR(O_RDWR); }
 
 /*
+ * AUDIO_GETIOFFS at least one block.
+ */
+void
+test_AUDIO_GETIOFFS_one(int openmode)
+{
+	struct audio_info ai;
+	audio_offset_t o;
+	int fd;
+	int r;
+	u_int blocksize;
+	u_int blk_ms;
+
+	TEST("AUDIO_GETIOFFS_one_%s", openmode_str[openmode] + 2);
+	if (mode2aumode(openmode) == 0) {
+		XP_SKIP("Operation not allowed on this hardware property");
+		return;
+	}
+
+	fd = OPEN(devaudio, openmode);
+	REQUIRED_SYS_OK(fd);
+
+#if 0
+	/*
+	 * On NetBSD7/8, native encodings and emulated encodings behave
+	 * differently.  But it's hard to identify which encoding is native.
+	 * If you try other encodings, edit these parameters manually.
+	 */
+	AUDIO_INITINFO();
+	ai.record.encoding = AUDIO_ENCODING_SLINEAR_NE;
+	ai.record.precision = 16;
+	ai.record.channels = 2;
+	ai.record.sample_rate = 48000;
+	/* ai.blocksize is shared by play and record, so set both the same. */
+	*ai.play = *ai.record;
+	r = IOCTL(fd, AUDIO_SETINFO, , "");
+	REQUIRED_SYS_EQ(0, r);
+#endif
+
+	/* Get blocksize to calc blk_ms. */
+	r = IOCTL(fd, AUDIO_GETBUFINFO, , "");
+	REQUIRED_SYS_EQ(0, r);
+	blocksize = ai.blocksize;
+	if (netbsd < 9) {
+		blk_ms = 0;
+	} else {
+		/* On NetBSD9, blocktime can always be calculated. */
+		blk_ms = blocksize * 1000 /
+		(ai.play.precision / 8 * ai.play.channels *
+		 ai.play.sample_rate);
+	}
+	if (blk_ms == 0)
+		blk_ms = 50;
+	DPRINTF("  > blocksize=%u, estimated blk_ms=%u\n", blocksize, blk_ms);
+
+	/*
+	 * Even when just opened, recording counters will start.
+	 * Wait a moment, about one block time.
+	 */
+	usleep(blk_ms * 1000);
+
+	r = IOCTL(fd, AUDIO_GETIOFFS, , "");
+	XP_SYS_EQ(0, r);
+	if (mode2rec(openmode)) {
+		/*
+		 * It's difficult to know exact values.
+		 * But at least these should not be zero.
+		 */
+		DPRINTF("  > %d: samples=%u deltablks=%u offset=%u\n",
+		__LINE__, o.samples, o.deltablks, o.offset);
+		XP_NE(0, o.samples);
+		XP_NE(0, o.deltablks);
+		XP_NE(0, o.offset);
+	} else {
+		/* All are zero on playback track. */
+		XP_EQ(0, o.samples);
+		XP_EQ(0, o.deltablks);
+		XP_EQ(0, o.offset);
+	}
+
+	r = CLOSE(fd);
+	XP_SYS_EQ(0, r);
+}
+DEF(AUDIO_GETIOFFS_one_RDONLY) { test_AUDIO_GETIOFFS_one(O_RDONLY); }
+DEF(AUDIO_GETIOFFS_one_WRONLY) { test_AUDIO_GETIOFFS_one(O_WRONLY); }
+DEF(AUDIO_GETIOFFS_one_RDWR)   { test_AUDIO_GETIOFFS_one(O_RDWR); }
+
+/*
+ * AUDIO_GETOOFFS for one block.
+ */
+void
+test_AUDIO_GETOOFFS_one(int openmode)
+{
+	struct audio_info ai;
+	audio_offset_t o;
+	char *buf;
+	int fd;
+	int r;
+	u_int blocksize;
+	u_int initial_offset;
+	u_int blk_ms;
+
+	TEST("AUDIO_GETOOFFS_one_%s", openmode_str[openmode] + 2);
+	if (mode2aumode(openmode) == 0) {
+		XP_SKIP("Operation not allowed on this hardware property");
+		return;
+	}
+
+	fd = OPEN(devaudio, openmode);
+	REQUIRED_SYS_OK(fd);
+
+#if 0
+	/*
+	 * On NetBSD7/8, native encodings and emulated encodings behave
+	 * differently.  But it's hard to ide

CVS commit: src/tests/dev/audio

2022-04-23 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Apr 23 07:47:42 UTC 2022

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

Log Message:
tests: Add tests for AUDIO_GET[IO]OFFS ioctls.
- AUDIO_GETIOFFS_one_{RDONLY,RDWR,WRONLY}
- AUDIO_GETOOFFS_one_{RDONLY,RDWR,WRONLY}
- AUDIO_GETOOFFS_wrap_{RDONLY,RDWR,WRONLY}
- AUDIO_GETOOFFS_flush_{RDONLY,RDWR,WRONLY}
- AUDIO_GETOOFFS_set_{RDONLY,RDWR,WRONLY}


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



CVS commit: src/sys/dev/audio

2022-04-23 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Apr 23 07:43:16 UTC 2022

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

Log Message:
audio(4): Restore(implement) AUDIO_GETIOFFS ioctl.


To generate a diff of this commit:
cvs rdiff -u -r1.129 -r1.130 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.129 src/sys/dev/audio/audio.c:1.130
--- src/sys/dev/audio/audio.c:1.129	Sat Apr 23 06:17:59 2022
+++ src/sys/dev/audio/audio.c	Sat Apr 23 07:43:16 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.129 2022/04/23 06:17:59 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.130 2022/04/23 07:43:16 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -181,7 +181,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.129 2022/04/23 06:17:59 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.130 2022/04/23 07:43:16 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -3086,12 +3086,31 @@ audio_ioctl(dev_t dev, struct audio_soft
 		break;
 
 	case AUDIO_GETIOFFS:
-		/* XXX TODO */
-		TRACEF(2, file, "%s", pre);
 		ao = (struct audio_offset *)addr;
-		ao->samples = 0;
-		ao->deltablks = 0;
-		ao->offset = 0;
+		track = file->rtrack;
+		if (track == NULL) {
+			ao->samples = 0;
+			ao->deltablks = 0;
+			ao->offset = 0;
+			TRACEF(2, file, "%s no rtrack", pre);
+			break;
+		}
+		mutex_enter(sc->sc_lock);
+		mutex_enter(sc->sc_intr_lock);
+		/* figure out where next transfer will start */
+		stamp = track->stamp;
+		offset = auring_tail(track->input);
+		mutex_exit(sc->sc_intr_lock);
+		mutex_exit(sc->sc_lock);
+
+		/* samples will overflow soon but is as per spec. */
+		ao->samples = stamp * track->usrbuf_blksize;
+		ao->deltablks = stamp - track->last_stamp;
+		ao->offset = audio_track_inputblk_as_usrbyte(track, offset);
+		TRACET(2, track, "%s samples=%u deltablks=%u offset=%u",
+		pre, ao->samples, ao->deltablks, ao->offset);
+
+		track->last_stamp = stamp;
 		break;
 
 	case AUDIO_GETOOFFS:
@@ -5152,8 +5171,6 @@ audio_track_record(audio_track_t *track)
 		auring_take(outbuf, bytes2 / framesize);
 	}
 
-	/* XXX TODO: any counters here? */
-
 #if defined(AUDIO_DEBUG)
 	if (audiodebug >= 3) {
 		struct audio_track_debugbuf m;
@@ -6098,7 +6115,7 @@ audio_rmixer_process(struct audio_softc 
 		bytes);
 		auring_push(input, count);
 
-		/* XXX sequence counter? */
+		track->stamp++;
 
 		audio_track_lock_exit(track);
 	}



CVS commit: src/sys/dev/audio

2022-04-23 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Apr 23 07:43:16 UTC 2022

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

Log Message:
audio(4): Restore(implement) AUDIO_GETIOFFS ioctl.


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

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



CVS commit: src/sys/dev/audio

2022-04-23 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Apr 23 06:17:59 UTC 2022

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

Log Message:
audio(4): Fix an (unintended) minor behavior on AUDIO_FLUSH.
On NetBSD7, when AUDIO_FLUSH was issued, .offset of AUDIO_GETOOFFS was
reinitialized (to one block ahead from zero) or unchanged depend on
whether the user encoding is hardware native or not (probably).
I don't believe that it's intended or we need to maintain it.
Now, AUDIO_FLUSH always clears the offset to zero.


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

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



CVS commit: src/sys/dev/audio

2022-04-23 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Apr 23 06:17:59 UTC 2022

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

Log Message:
audio(4): Fix an (unintended) minor behavior on AUDIO_FLUSH.
On NetBSD7, when AUDIO_FLUSH was issued, .offset of AUDIO_GETOOFFS was
reinitialized (to one block ahead from zero) or unchanged depend on
whether the user encoding is hardware native or not (probably).
I don't believe that it's intended or we need to maintain it.
Now, AUDIO_FLUSH always clears the offset to zero.


To generate a diff of this commit:
cvs rdiff -u -r1.128 -r1.129 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.128 src/sys/dev/audio/audio.c:1.129
--- src/sys/dev/audio/audio.c:1.128	Thu Apr 21 01:15:24 2022
+++ src/sys/dev/audio/audio.c	Sat Apr 23 06:17:59 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.128 2022/04/21 01:15:24 macallan Exp $	*/
+/*	$NetBSD: audio.c,v 1.129 2022/04/23 06:17:59 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -181,7 +181,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.128 2022/04/21 01:15:24 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.129 2022/04/23 06:17:59 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -6280,8 +6280,9 @@ audio_track_clear(struct audio_softc *sc
 
 	audio_track_lock_enter(track);
 
-	track->usrbuf.used = 0;
 	/* Clear all internal parameters. */
+	track->usrbuf.used = 0;
+	track->usrbuf.head = 0;
 	if (track->codec.filter) {
 		track->codec.srcbuf.used = 0;
 		track->codec.srcbuf.head = 0;



CVS commit: src/sys/dev/audio

2022-04-20 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Apr 20 07:11:14 UTC 2022

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

Log Message:
audio(4): Rework AUDIO_GETOOFFS.
- Count .samples/.deltablks in blocks.  It makes .deltablks integer wrap
  around safe.
- Remove suspicious one block offset from .offset.  I added the offset
  because it was observed so on NetBSD7.  But according to manpage, it
  should not be.  And it looks fine without the offset.
- Related to that, remove a comment in AUDIO_WSEEK.
  Limit the user-visible buffer to usrbuf only.


To generate a diff of this commit:
cvs rdiff -u -r1.126 -r1.127 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.17 -r1.18 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.126 src/sys/dev/audio/audio.c:1.127
--- src/sys/dev/audio/audio.c:1.126	Wed Apr 20 06:05:22 2022
+++ src/sys/dev/audio/audio.c	Wed Apr 20 07:11:13 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.126 2022/04/20 06:05:22 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.127 2022/04/20 07:11:13 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -181,7 +181,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.126 2022/04/20 06:05:22 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.127 2022/04/20 07:11:13 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2985,7 +2985,7 @@ audio_ioctl(dev_t dev, struct audio_soft
 	audio_encoding_t *ae;
 	audio_format_query_t *query;
 	u_int stamp;
-	u_int offs;
+	u_int offset;
 	int val;
 	int index;
 	int error;
@@ -3104,28 +3104,23 @@ audio_ioctl(dev_t dev, struct audio_soft
 		}
 		mutex_enter(sc->sc_lock);
 		mutex_enter(sc->sc_intr_lock);
-		/* figure out where next DMA will start */
-		stamp = track->usrbuf_stamp;
-		offs = track->usrbuf.head;
+		/* figure out where next transfer will start */
+		stamp = track->stamp;
+		offset = track->usrbuf.head;
 		mutex_exit(sc->sc_intr_lock);
 		mutex_exit(sc->sc_lock);
 
-		ao->samples = stamp;
-		ao->deltablks = (stamp / track->usrbuf_blksize) -
-		(track->usrbuf_stamp_last / track->usrbuf_blksize);
-		track->usrbuf_stamp_last = stamp;
-		offs = rounddown(offs, track->usrbuf_blksize)
-		+ track->usrbuf_blksize;
-		if (offs >= track->usrbuf.capacity)
-			offs -= track->usrbuf.capacity;
-		ao->offset = offs;
-
+		/* samples will overflow soon but is as per spec. */
+		ao->samples = stamp * track->usrbuf_blksize;
+		ao->deltablks = stamp - track->last_stamp;
+		ao->offset = offset;
 		TRACET(2, track, "%s samples=%u deltablks=%u offset=%u",
 		pre, ao->samples, ao->deltablks, ao->offset);
+
+		track->last_stamp = stamp;
 		break;
 
 	case AUDIO_WSEEK:
-		/* XXX return value does not include outbuf one. */
 		track = file->ptrack;
 		if (track) {
 			val = track->usrbuf.used;
@@ -4964,8 +4959,6 @@ audio_track_play(audio_track_t *track)
 	count = uimin(usrbuf->used, track->usrbuf_blksize) / framesize;
 	bytes = count * framesize;
 
-	track->usrbuf_stamp += bytes;
-
 	if (usrbuf->head + bytes < usrbuf->capacity) {
 		memcpy((uint8_t *)input->mem + auring_tail(input) * framesize,
 		(uint8_t *)usrbuf->mem + usrbuf->head,
@@ -5060,6 +5053,8 @@ audio_track_play(audio_track_t *track)
 		track->outputcounter += track->outbuf.used - track_count_0;
 	}
 
+	track->stamp++;
+
 #if defined(AUDIO_DEBUG)
 	if (audiodebug >= 3) {
 		struct audio_track_debugbuf m;
@@ -6311,6 +6306,8 @@ audio_track_clear(struct audio_softc *sc
 	track->outbuf.used = 0;
 
 	/* Clear counters. */
+	track->stamp = 0;
+	track->last_stamp = 0;
 	track->dropframes = 0;
 
 	audio_track_lock_exit(track);
@@ -7773,7 +7770,7 @@ audiogetinfo(struct audio_softc *sc, str
 
 	if (ptrack) {
 		pi->seek = ptrack->usrbuf.used;
-		pi->samples = ptrack->usrbuf_stamp;
+		pi->samples = ptrack->stamp * ptrack->usrbuf_blksize;
 		pi->eof = ptrack->eofcounter;
 		pi->error = (ptrack->dropframes != 0) ? 1 : 0;
 		pi->open = 1;
@@ -7784,7 +7781,7 @@ audiogetinfo(struct audio_softc *sc, str
 
 	if (rtrack) {
 		ri->seek = audio_track_readablebytes(rtrack);
-		ri->samples = rtrack->usrbuf_stamp;
+		ri->samples = rtrack->stamp * rtrack->usrbuf_blksize;
 		ri->eof = 0;
 		ri->error = (rtrack->dropframes != 0) ? 1 : 0;
 		ri->open = 1;

Index: src/sys/dev/audio/audiodef.h
diff -u src/sys/dev/audio/audiodef.h:1.17 src/sys/dev/audio/audiodef.h:1.18
--- src/sys/dev/audio/audiodef.h:1.17	Wed Apr 20 06:05:22 2022
+++ src/sys/dev/audio/audiodef.h	Wed Apr 20 07:11:13 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiodef.h,v 1.17 2022/04/20 06:05:22 isaki Exp $	*/
+/*	$NetBSD: audiodef.h,v 1.18 20

CVS commit: src/sys/dev/audio

2022-04-20 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Apr 20 07:11:14 UTC 2022

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

Log Message:
audio(4): Rework AUDIO_GETOOFFS.
- Count .samples/.deltablks in blocks.  It makes .deltablks integer wrap
  around safe.
- Remove suspicious one block offset from .offset.  I added the offset
  because it was observed so on NetBSD7.  But according to manpage, it
  should not be.  And it looks fine without the offset.
- Related to that, remove a comment in AUDIO_WSEEK.
  Limit the user-visible buffer to usrbuf only.


To generate a diff of this commit:
cvs rdiff -u -r1.126 -r1.127 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/audio/audiodef.h

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



CVS commit: src/sys/dev/audio

2022-04-20 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Apr 20 06:05:22 UTC 2022

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

Log Message:
audio(4): Make recording buffer more robust.
Previously, main buffer in recording track was usrbuf, which is the closest
buffer to the userland.  Because, this buffer arrangement was symmetrical
with the playback track, and had affinity with the past implementation.
However, in the current implementation, read(2) (from user application)
takes recorded block out from inputbuf, which is the closest buffer to
rmixer, to usrbuf.  So it was not good way to use the usrbuf as main buffer.
Now, usrbuf in recording track holds only fragment bytes in order to
transfer to the userland, and main buffer in recording track is the inputbuf,
the closest to rmixer.

Buffer size of the inputbuf is also modified.  Previously, it was less than
64KB or at least 4 blocks.  This had affinity with playback track and the
past implementation.  But this was not appropriate for both formats with
too large frames or too small frames.  In large frames (for example,
192kHz/12ch), 184KB buffer would be allocated but it corresponds to only
40msec.  In opposite, in small frames (for example, 8000Hz/1ch), 64KB
buffer would be allocated and it corresponds to 4.1 seconds.  But for such
machines that have 8000Hz/1ch device, in-kernel 64KB memory would probably
be expensive.
Now, inputbuf will always be allocated 16(NBLKIN) blocks, regardless of its
hardware format.  It corresponds to 160msec on modern archs (if blk_ms=10),
or 640msec on antique archs (if blk_ms=40).


To generate a diff of this commit:
cvs rdiff -u -r1.125 -r1.126 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/audio/audiodef.h

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



CVS commit: src/sys/dev/audio

2022-04-20 Thread Tetsuya Isaki
age buffer */
-	audio_ring_t *last_dst = >outbuf;
-	if (audio_track_is_playback(track)) {
+	last_dst = >outbuf;
+	if (is_playback) {
 		/* On playback, initialize from the mixer side in order. */
 		track->inputfmt = *usrfmt;
 		track->outbuf.fmt =  track->mixer->track_fmt;
@@ -4656,17 +4750,6 @@ audio_track_set_format(audio_track_t *tr
 	track->input = last_dst;
 
 	/*
-	 * On the recording track, make the first stage a ring buffer.
-	 * XXX is there a better way?
-	 */
-	if (audio_track_is_record(track)) {
-		track->input->capacity = NBLKOUT *
-		frame_per_block(track->mixer, >input->fmt);
-		len = auring_bytelen(track->input);
-		track->input->mem = audio_realloc(track->input->mem, len);
-	}
-
-	/*
 	 * Output buffer.
 	 * On the playback track, its capacity is NBLKOUT blocks.
 	 * On the recording track, its capacity is 1 block.
@@ -4675,7 +4758,7 @@ audio_track_set_format(audio_track_t *tr
 	track->outbuf.used = 0;
 	track->outbuf.capacity = frame_per_block(track->mixer,
 	>outbuf.fmt);
-	if (audio_track_is_playback(track))
+	if (is_playback)
 		track->outbuf.capacity *= NBLKOUT;
 	len = auring_bytelen(>outbuf);
 	track->outbuf.mem = audio_realloc(track->outbuf.mem, len);
@@ -4685,6 +4768,20 @@ audio_track_set_format(audio_track_t *tr
 		goto error;
 	}
 
+	/*
+	 * On the recording track, expand the input stage buffer, which is
+	 * the closest buffer to rmixer, to NBLKOUT blocks.
+	 * Note that input buffer may point to outbuf.
+	 */
+	if (!is_playback) {
+		int input_fpb;
+
+		input_fpb = frame_per_block(track->mixer, >input->fmt);
+		track->input->capacity = input_fpb * NBLKIN;
+		len = auring_bytelen(track->input);
+		track->input->mem = audio_realloc(track->input->mem, len);
+	}
+
 #if defined(AUDIO_DEBUG)
 	if (audiodebug >= 3) {
 		struct audio_track_debugbuf m;
@@ -4711,7 +4808,7 @@ audio_track_set_format(audio_track_t *tr
 		snprintf(m.usrbuf, sizeof(m.usrbuf),
 		" usr=%d", track->usrbuf.capacity);
 
-		if (audio_track_is_playback(track)) {
+		if (is_playback) {
 			TRACET(0, track, "bufsize%s%s%s%s%s%s",
 			m.outbuf, m.freq, m.chmix,
 			m.chvol, m.codec, m.usrbuf);
@@ -5016,8 +5113,8 @@ audio_track_record(audio_track_t *track)
 	/* Copy outbuf to usrbuf */
 	outbuf = >outbuf;
 	usrbuf = >usrbuf;
-	/* usrbuf must have at least one free block. */
-	KASSERT(usrbuf->used <= track->usrbuf_usedhigh - track->usrbuf_blksize);
+	/* usrbuf should be empty. */
+	KASSERT(usrbuf->used == 0);
 	/*
 	 * framesize is always 1 byte or more since all formats supported
 	 * as usrfmt(=output) have 8bit or more stride.
@@ -7686,12 +7783,13 @@ audiogetinfo(struct audio_softc *sc, str
 	pi->active = sc->sc_pbusy;
 
 	if (rtrack) {
-		ri->seek = rtrack->usrbuf.used;
+		ri->seek = audio_track_readablebytes(rtrack);
 		ri->samples = rtrack->usrbuf_stamp;
 		ri->eof = 0;
 		ri->error = (rtrack->dropframes != 0) ? 1 : 0;
 		ri->open = 1;
-		ri->buffer_size = rtrack->usrbuf.capacity;
+		ri->buffer_size = audio_track_inputblk_as_usrbyte(rtrack,
+		rtrack->input->capacity);
 	}
 	ri->waiting = 0;		/* open never hangs */
 	ri->active = sc->sc_rbusy;

Index: src/sys/dev/audio/audiodef.h
diff -u src/sys/dev/audio/audiodef.h:1.16 src/sys/dev/audio/audiodef.h:1.17
--- src/sys/dev/audio/audiodef.h:1.16	Sat Aug 21 10:18:14 2021
+++ src/sys/dev/audio/audiodef.h	Wed Apr 20 06:05:22 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiodef.h,v 1.16 2021/08/21 10:18:14 andvar Exp $	*/
+/*	$NetBSD: audiodef.h,v 1.17 2022/04/20 06:05:22 isaki Exp $	*/
 
 /*
  * Copyright (C) 2017 Tetsuya Isaki. All rights reserved.
@@ -33,13 +33,28 @@
 #include "opt_audio.h"
 #endif
 
-/* Number of HW buffer's blocks. */
+/* Number of blocks in HW buffer. */
 #define NBLKHW (3)
 
-/* Number of track output buffer's blocks.  Must be > NBLKHW */
+/* Number of blocks in output buffer on playback track.  Must be > NBLKHW */
 #define NBLKOUT	(4)
 
-/* Minimum number of usrbuf's blocks. */
+/*
+ * Number of blocks in input buffer on recording track.
+ *
+ * For references:
+ *  On 48000Hz/2ch (blk_ms=10), the buffer time is 160 [msec], and
+ *  the input buffer size is 30720 [bytes] (= 1920 [byte/block] * 16).
+ *
+ *  On 192000Hz/12ch (blk_ms=10), the buffer time is 160 [msec], and
+ *  the input buffer size is 737280 [bytes] (= 46080 [byte/block] * 16).
+ *
+ *  On 8000Hz/1ch (blk_ms=40), the buffer time is 640 [msec], and
+ *  the input buffer size = 10240 [bytes] (= 640 [byte/block] * 16).
+ */
+#define NBLKIN	(16)
+
+/* Minimum number of blocks in usrbuf on playback track. */
 #define AUMINNOBLK	(3)
 
 /*



CVS commit: src/sys/dev/audio

2022-04-19 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Apr 20 04:41:29 UTC 2022

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

Log Message:
audio(4): Make debug messages better in audio_ioctl() and mixier_ioctl().
Divide by case.  Reduce to one line if possible.


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 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.124 src/sys/dev/audio/audio.c:1.125
--- src/sys/dev/audio/audio.c:1.124	Tue Apr 19 09:19:53 2022
+++ src/sys/dev/audio/audio.c	Wed Apr 20 04:41:29 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.124 2022/04/19 09:19:53 riastradh Exp $	*/
+/*	$NetBSD: audio.c,v 1.125 2022/04/20 04:41:29 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -181,7 +181,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.124 2022/04/19 09:19:53 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.125 2022/04/20 04:41:29 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2992,40 +2992,44 @@ audio_ioctl(dev_t dev, struct audio_soft
 	audio_format_query_t *query;
 	u_int stamp;
 	u_int offs;
-	int fd;
+	int val;
 	int index;
 	int error;
 
 #if defined(AUDIO_DEBUG)
 	const char *ioctlnames[] = {
-		" AUDIO_GETINFO",	/* 21 */
-		" AUDIO_SETINFO",	/* 22 */
-		" AUDIO_DRAIN",		/* 23 */
-		" AUDIO_FLUSH",		/* 24 */
-		" AUDIO_WSEEK",		/* 25 */
-		" AUDIO_RERROR",	/* 26 */
-		" AUDIO_GETDEV",	/* 27 */
-		" AUDIO_GETENC",	/* 28 */
-		" AUDIO_GETFD",		/* 29 */
-		" AUDIO_SETFD",		/* 30 */
-		" AUDIO_PERROR",	/* 31 */
-		" AUDIO_GETIOFFS",	/* 32 */
-		" AUDIO_GETOOFFS",	/* 33 */
-		" AUDIO_GETPROPS",	/* 34 */
-		" AUDIO_GETBUFINFO",	/* 35 */
-		" AUDIO_SETCHAN",	/* 36 */
-		" AUDIO_GETCHAN",	/* 37 */
-		" AUDIO_QUERYFORMAT",	/* 38 */
-		" AUDIO_GETFORMAT",	/* 39 */
-		" AUDIO_SETFORMAT",	/* 40 */
+		"AUDIO_GETINFO",	/* 21 */
+		"AUDIO_SETINFO",	/* 22 */
+		"AUDIO_DRAIN",		/* 23 */
+		"AUDIO_FLUSH",		/* 24 */
+		"AUDIO_WSEEK",		/* 25 */
+		"AUDIO_RERROR",		/* 26 */
+		"AUDIO_GETDEV",		/* 27 */
+		"AUDIO_GETENC",		/* 28 */
+		"AUDIO_GETFD",		/* 29 */
+		"AUDIO_SETFD",		/* 30 */
+		"AUDIO_PERROR",		/* 31 */
+		"AUDIO_GETIOFFS",	/* 32 */
+		"AUDIO_GETOOFFS",	/* 33 */
+		"AUDIO_GETPROPS",	/* 34 */
+		"AUDIO_GETBUFINFO",	/* 35 */
+		"AUDIO_SETCHAN",	/* 36 */
+		"AUDIO_GETCHAN",	/* 37 */
+		"AUDIO_QUERYFORMAT",	/* 38 */
+		"AUDIO_GETFORMAT",	/* 39 */
+		"AUDIO_SETFORMAT",	/* 40 */
 	};
+	char pre[64];
 	int nameidx = (cmd & 0xff);
-	const char *ioctlname = "";
-	if (21 <= nameidx && nameidx <= 21 + __arraycount(ioctlnames))
-		ioctlname = ioctlnames[nameidx - 21];
-	TRACEF(2, file, "(%lu,'%c',%lu)%s pid=%d.%d",
-	IOCPARM_LEN(cmd), (char)IOCGROUP(cmd), cmd&0xff, ioctlname,
-	(int)curproc->p_pid, (int)l->l_lid);
+	if (21 <= nameidx && nameidx <= 21 + __arraycount(ioctlnames)) {
+		snprintf(pre, sizeof(pre), "pid=%d.%d %s",
+		(int)curproc->p_pid, (int)l->l_lid,
+		ioctlnames[nameidx - 21]);
+	} else {
+		snprintf(pre, sizeof(pre), "pid=%d.%d (%lu,'%c',%u)",
+		(int)curproc->p_pid, (int)l->l_lid,
+		IOCPARM_LEN(cmd), (char)IOCGROUP(cmd), nameidx);
+	}
 #endif
 
 	error = 0;
@@ -3036,10 +3040,15 @@ audio_ioctl(dev_t dev, struct audio_soft
 
 	case FIONREAD:
 		/* Get the number of bytes that can be read. */
-		if (file->rtrack) {
-			*(int *)addr = audio_track_readablebytes(file->rtrack);
+		track = file->rtrack;
+		if (track) {
+			val = audio_track_readablebytes(track);
+			*(int *)addr = val;
+			TRACET(2, track, "pid=%d.%d FIONREAD bytes=%d",
+			(int)curproc->p_pid, (int)l->l_lid, val);
 		} else {
-			*(int *)addr = 0;
+			TRACEF(2, file, "pid=%d.%d FIONREAD no track",
+			(int)curproc->p_pid, (int)l->l_lid);
 		}
 		break;
 
@@ -3047,48 +3056,42 @@ audio_ioctl(dev_t dev, struct audio_soft
 		/* Set/Clear ASYNC I/O. */
 		if (*(int *)addr) {
 			file->async_audio = curproc->p_pid;
-			TRACEF(2, file, "FIOASYNC pid %d", file->async_audio);
 		} else {
 			file->async_audio = 0;
-			TRACEF(2, file, "FIOASYNC off");
 		}
+		TRACEF(2, file, "pid=%d.%d FIOASYNC %s",
+		(int)curproc->p_pid, (int)l->l_lid,
+		file->async_audio ? "on" : "off");
 		break;
 
 	case AUDIO_FLUSH:
 		/* XXX TODO: clear errors and restart? */
+		TRACEF(2, file, "%s", pre);
 		audio_file_clear(sc, file);
 		break;
 
-	case AUDIO_RERROR:
-		/*
-		 * Number of read bytes dropped.  We don't know where
-		 * or when they were dropped (including conversion stage).
-		 * Therefore, the number of accurate bytes or samples is
-		 * also unknown.
-		 */
-		track = file->rtrack;
-		if (track) {
-			*(int *)addr = frametobyte(>usrbuf.fmt,
-			track->dropframes);
-		}
-		break;
-
 	case AUDIO_PERROR:
+	case AUDIO_RERROR:
 		/*
-		 * Number of write bytes dropped.  We don't know where
-		 * or when they were dropped (including conversion 

CVS commit: src/sys/dev/audio

2022-04-19 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Wed Apr 20 04:41:29 UTC 2022

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

Log Message:
audio(4): Make debug messages better in audio_ioctl() and mixier_ioctl().
Divide by case.  Reduce to one line if possible.


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

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



CVS commit: src/sys/dev/audio

2022-03-26 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Mar 26 06:49:27 UTC 2022

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

Log Message:
Add terminology comments.


To generate a diff of this commit:
cvs rdiff -u -r1.119 -r1.120 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.119 src/sys/dev/audio/audio.c:1.120
--- src/sys/dev/audio/audio.c:1.119	Sat Mar 26 06:43:36 2022
+++ src/sys/dev/audio/audio.c	Sat Mar 26 06:49:27 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.119 2022/03/26 06:43:36 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.120 2022/03/26 06:49:27 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -63,6 +63,49 @@
  */
 
 /*
+ * Terminology: "sample", "channel", "frame", "block", "track":
+ *
+ *  channel   frame
+ *   |   
+ *   v   :  :\
+ *+--:--:--:-  -+--+ : +--+-..   |
+ *  #0(L) |sample|sample|sample| .. |sample| : |sample|  |
+ *+--:--:--:-  -+--+ : +--+-..   |
+ *  #1(R) |sample|sample|sample| .. |sample| : |sample|  |
+ *+--:--:--:-  -+--+ : +--+-..   | track
+ *   :   :  ::   |
+ *+--:--:--:-  -+--+ : +--+-..   |
+ *|sample|sample|sample| .. |sample| : |sample|  |
+ *+--:--:--:-  -+--+ : +--+-..   |
+ *   :  :/
+ *   
+ *
+ *\/   \..
+ * block
+ *
+ * - A "frame" is the minimum unit in the time axis direction, and consists
+ *   of samples for the number of channels.
+ * - A "block" is basic length of processing.  The audio layer basically
+ *   handles audio data stream block by block, asks underlying hardware to
+ *   process them block by block, and then the hardware raises interrupt by
+ *   each block.
+ * - A "track" is single completed audio stream.
+ *
+ * For example, the hardware block is assumed to be 10 msec, and your audio
+ * track consists of 2.1(=3) channels 44.1kHz 16bit PCM,
+ *
+ * "channel" = 3
+ * "sample" = 2 [bytes]
+ * "frame" = 2 [bytes/sample] * 3 [channels] = 6 [bytes]
+ * "block" = 44100 [Hz] * (10/1000) [seconds] * 6 [bytes/frame] = 2646 [bytes]
+ *
+ * The terminologies shown here are only for this MI audio layer.  Note that
+ * different terminologies may be used in each manufacturer's datasheet, and
+ * each MD driver may follow it.  For example, what we call a "block" is
+ * called a "frame" in sys/dev/pci/yds.c.
+ */
+
+/*
  * Locking: there are three locks per device.
  *
  * - sc_lock, provided by the underlying driver.  This is an adaptive lock,
@@ -138,7 +181,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.119 2022/03/26 06:43:36 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.120 2022/03/26 06:49:27 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"



CVS commit: src/sys/dev/audio

2022-03-26 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Mar 26 06:49:27 UTC 2022

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

Log Message:
Add terminology comments.


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

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



CVS commit: src/sys/dev/audio

2022-03-26 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Mar 26 06:43:36 UTC 2022

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

Log Message:
Improve comments.


To generate a diff of this commit:
cvs rdiff -u -r1.118 -r1.119 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.118 src/sys/dev/audio/audio.c:1.119
--- src/sys/dev/audio/audio.c:1.118	Sat Mar 26 06:41:12 2022
+++ src/sys/dev/audio/audio.c	Sat Mar 26 06:43:36 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.118 2022/03/26 06:41:12 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.119 2022/03/26 06:43:36 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.118 2022/03/26 06:41:12 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.119 2022/03/26 06:43:36 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2767,7 +2767,7 @@ audio_read(struct audio_softc *sc, struc
 			audio_track_record(track);
 		}
 
-		/* uiomove from usrbuf as much as possible. */
+		/* uiomove from usrbuf as many bytes as possible. */
 		bytes = uimin(usrbuf->used, uio->uio_resid);
 		while (bytes > 0) {
 			int head = usrbuf->head;
@@ -2896,7 +2896,7 @@ audio_write(struct audio_softc *sc, stru
 
 		audio_track_lock_enter(track);
 
-		/* uiomove to usrbuf as much as possible. */
+		/* uiomove to usrbuf as many bytes as possible. */
 		bytes = uimin(track->usrbuf_usedhigh - usrbuf->used,
 		uio->uio_resid);
 		while (bytes > 0) {
@@ -2919,7 +2919,7 @@ audio_write(struct audio_softc *sc, stru
 			bytes -= len;
 		}
 
-		/* Convert them as much as possible. */
+		/* Convert them as many blocks as possible. */
 		while (usrbuf->used >= track->usrbuf_blksize &&
 		outbuf->used < outbuf->capacity) {
 			audio_track_play(track);
@@ -5905,7 +5905,10 @@ audio_rmixer_process(struct audio_softc 
 			continue;
 		}
 
-		/* If the track buffer is full, discard the oldest one? */
+		/*
+		 * If the track buffer has less than one block of free space,
+		 * make one block free.
+		 */
 		input = track->input;
 		if (input->capacity - input->used < mixer->frames_per_block) {
 			int drops = mixer->frames_per_block -



CVS commit: src/sys/dev/audio

2022-03-26 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Mar 26 06:43:36 UTC 2022

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

Log Message:
Improve comments.


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

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



CVS commit: src/sys/dev/audio

2022-03-26 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Mar 26 06:41:12 UTC 2022

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

Log Message:
Remove a dead code in audio_track_record().


To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.118 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.117 src/sys/dev/audio/audio.c:1.118
--- src/sys/dev/audio/audio.c:1.117	Sat Mar 26 06:36:06 2022
+++ src/sys/dev/audio/audio.c	Sat Mar 26 06:41:12 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.117 2022/03/26 06:36:06 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.118 2022/03/26 06:41:12 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.117 2022/03/26 06:36:06 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.118 2022/03/26 06:41:12 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -4912,11 +4912,8 @@ audio_track_record(audio_track_t *track)
 	KASSERT(track);
 	KASSERT(track->lock);
 
-	/* Number of frames to process */
-	count = auring_get_contig_used(track->input);
-	count = uimin(count, track->mixer->frames_per_block);
-	if (count == 0) {
-		TRACET(4, track, "count == 0");
+	if (auring_get_contig_used(track->input) == 0) {
+		TRACET(4, track, "input->used == 0");
 		return;
 	}
 



CVS commit: src/sys/dev/audio

2022-03-26 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Mar 26 06:41:12 UTC 2022

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

Log Message:
Remove a dead code in audio_track_record().


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

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



CVS commit: src/sys/dev/audio

2022-03-26 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Mar 26 06:36:06 UTC 2022

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

Log Message:
Clarify the assertion in audio_rmixer_process().
By previous commit (r1.116), the assersion no longer fires even without
this modification.  But the condition was a bit inaccurate.
There is no need to check the data length must be aligned to blocks here
(though it also should be aligned now).  What we should check here is that
the tail must be aligned.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 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.116 src/sys/dev/audio/audio.c:1.117
--- src/sys/dev/audio/audio.c:1.116	Sat Mar 26 06:27:32 2022
+++ src/sys/dev/audio/audio.c	Sat Mar 26 06:36:06 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.116 2022/03/26 06:27:32 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.117 2022/03/26 06:36:06 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.116 2022/03/26 06:27:32 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.117 2022/03/26 06:36:06 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -5919,10 +5919,10 @@ audio_rmixer_process(struct audio_softc 
 			input->head, input->used, input->capacity);
 			auring_take(input, drops);
 		}
-		KASSERTMSG(input->used % mixer->frames_per_block == 0,
-		"input->used=%d mixer->frames_per_block=%d",
-		input->used, mixer->frames_per_block);
 
+		KASSERTMSG(auring_tail(input) % mixer->frames_per_block == 0,
+		"inputtail=%d mixer->frames_per_block=%d",
+		auring_tail(input), mixer->frames_per_block);
 		memcpy(auring_tailptr_aint(input),
 		auring_headptr_aint(mixersrc),
 		bytes);



CVS commit: src/sys/dev/audio

2022-03-26 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Mar 26 06:36:06 UTC 2022

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

Log Message:
Clarify the assertion in audio_rmixer_process().
By previous commit (r1.116), the assersion no longer fires even without
this modification.  But the condition was a bit inaccurate.
There is no need to check the data length must be aligned to blocks here
(though it also should be aligned now).  What we should check here is that
the tail must be aligned.


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

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



CVS commit: src/sys/dev/audio

2022-03-26 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Mar 26 06:27:32 UTC 2022

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

Log Message:
Fix conditions that audio_read() calls audio_track_record().
audio_track_record() must be called when usrbuf has at least one free block.

I hope that this will fix the panic reported in PR kern/56644.
When an user process specifies the hardware format as its recording format
(i.e., there is no track conversions), if the user process read(2) a small
amount of data and the rmixer_process then runs, depending on the conditions,
the panic may happen.  I have never reproduced it because it's difficult to
do intentionally.

Thanks Y.Sugahara and riastradh@ for help and comments.


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 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.115 src/sys/dev/audio/audio.c:1.116
--- src/sys/dev/audio/audio.c:1.115	Mon Mar 14 21:38:04 2022
+++ src/sys/dev/audio/audio.c	Sat Mar 26 06:27:32 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.115 2022/03/14 21:38:04 riastradh Exp $	*/
+/*	$NetBSD: audio.c,v 1.116 2022/03/26 06:27:32 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.115 2022/03/14 21:38:04 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.116 2022/03/26 06:27:32 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2760,7 +2760,12 @@ audio_read(struct audio_softc *sc, struc
 		mutex_exit(sc->sc_lock);
 
 		audio_track_lock_enter(track);
-		audio_track_record(track);
+		/* Convert as many blocks as possible. */
+		while (usrbuf->used <=
+		track->usrbuf_usedhigh - track->usrbuf_blksize &&
+		input->used > 0) {
+			audio_track_record(track);
+		}
 
 		/* uiomove from usrbuf as much as possible. */
 		bytes = uimin(usrbuf->used, uio->uio_resid);
@@ -4938,6 +4943,8 @@ audio_track_record(audio_track_t *track)
 	/* Copy outbuf to usrbuf */
 	outbuf = >outbuf;
 	usrbuf = >usrbuf;
+	/* usrbuf must have at least one free block. */
+	KASSERT(usrbuf->used <= track->usrbuf_usedhigh - track->usrbuf_blksize);
 	/*
 	 * framesize is always 1 byte or more since all formats supported
 	 * as usrfmt(=output) have 8bit or more stride.
@@ -4949,8 +4956,7 @@ audio_track_record(audio_track_t *track)
 	 * bytes is the number of bytes to copy to usrbuf.
 	 */
 	count = outbuf->used;
-	count = uimin(count,
-	(track->usrbuf_usedhigh - usrbuf->used) / framesize);
+	count = uimin(count, track->usrbuf_blksize / framesize);
 	bytes = count * framesize;
 	if (auring_tail(usrbuf) + bytes < usrbuf->capacity) {
 		memcpy((uint8_t *)usrbuf->mem + auring_tail(usrbuf),



CVS commit: src/sys/dev/audio

2022-03-26 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Mar 26 06:27:32 UTC 2022

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

Log Message:
Fix conditions that audio_read() calls audio_track_record().
audio_track_record() must be called when usrbuf has at least one free block.

I hope that this will fix the panic reported in PR kern/56644.
When an user process specifies the hardware format as its recording format
(i.e., there is no track conversions), if the user process read(2) a small
amount of data and the rmixer_process then runs, depending on the conditions,
the panic may happen.  I have never reproduced it because it's difficult to
do intentionally.

Thanks Y.Sugahara and riastradh@ for help and comments.


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

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



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

2022-02-03 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Fri Feb  4 06:16:03 UTC 2022

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

Log Message:
Add missing -m68020-60 option.  This makes xxboot_ustarfs work even on 68060.
Problem reported by Makoto Kamada.  Confirmed on XEiJ (68060 mode).


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 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/xxboot/Makefile.xxboot
diff -u src/sys/arch/x68k/stand/xxboot/Makefile.xxboot:1.18 src/sys/arch/x68k/stand/xxboot/Makefile.xxboot:1.19
--- src/sys/arch/x68k/stand/xxboot/Makefile.xxboot:1.18	Sun Aug 16 06:43:43 2020
+++ src/sys/arch/x68k/stand/xxboot/Makefile.xxboot	Fri Feb  4 06:16:03 2022
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.xxboot,v 1.18 2020/08/16 06:43:43 isaki Exp $
+#	$NetBSD: Makefile.xxboot,v 1.19 2022/02/04 06:16:03 isaki Exp $
 
 NOMAN=		# defined
 
@@ -35,6 +35,7 @@ SRCS+=	memcmp.S
 .include "${S}/conf/newvers_stand.mk"
 
 CFLAGS=	-Os -fomit-frame-pointer -fno-unwind-tables -Wno-attributes
+CFLAGS+= -m68020-60
 #CFLAGS+= -Wall
 CPPFLAGS+= -D_STANDALONE
 CPPFLAGS+= -DTEXTADDR="$(TEXT)" -DBOOT_TEXTADDR="$(BOOT_TEXT)"



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

2022-02-03 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Fri Feb  4 06:16:03 UTC 2022

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

Log Message:
Add missing -m68020-60 option.  This makes xxboot_ustarfs work even on 68060.
Problem reported by Makoto Kamada.  Confirmed on XEiJ (68060 mode).


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



Re: CVS commit: src/share/man/man4

2021-03-12 Thread Tetsuya Isaki
At Fri, 12 Mar 2021 08:03:24 +,
Nia Alarie wrote:
> Committed By: nia
> Date: Fri Mar 12 08:03:24 UTC 2021
> 
> Modified Files:
>   src/share/man/man4: hdaudio.4
> 
> Log Message:
> Clarify problem.
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.18 -r1.19 src/share/man/man4/hdaudio.4

> @@ -133,5 +133,8 @@
:
> +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.

This looks incorrect.

MI audio layer synthesizes all streams coming from userland in 16bit,
even if the userland stream has precision higher than 16bit.
MI audio layer can and does handle any precision of underlying
hardware.  For example, the hardware of vraiu(4) on hpcmips (probably)
accepts only 10bit, the hardware of mavb(4) on sgimips (probably)
accepts only 24bit.
If the hardware supports 16bit precision and one or more precision
higher than 16bit like hdafg(4), I think that there is no or less
advantage for MD drivers to choice/support the precision higher than
16bit.

Thanks,
---
Tetsuya Isaki 


Re: CVS commit: src/share/man/man9

2021-02-08 Thread Tetsuya Isaki
At Sun, 7 Feb 2021 09:22:39 +,
nia wrote:
> > > -It is called at any time.
> > > +It can be called at any time.
> > 
> > The later sounds to me "You(developer of MD driver) can call
> > it at any time".  If so, it's incorrect.
> 
> Maybe "it can be called by the MI layer at any time" is clearer
> here, then? I can change it to that.

That's true, but sounds a bit redundant.
Because these all are callback functions called by the MI layer.

Is there any better text?
The MI layer can(will?) call this in the Opened phase or in the
Closed phase, or even in the Attach phase.  This means, for example,
that you (MD driver) cannot assume that you can prepare(initialize)
something in open() before this (since this can be called in the
Closed phase), and you cannot assume that it has returned from MI
attach (since this can be called in the Attach phase).

> > Is "only" a typo?  or is it better to remove it in English?
> 
> I think it's clear that conversion of other formats is not
> supported by the rest of the paragraph, so it doesn't need to
> be mentioned here, where the primary purpose of the sentence
> is to explain why you don't need to handle conversion in that
> case yourself.

If it's clear for readers, no problem to me.

Thanks,
---
Tetsuya Isaki 


Re: CVS commit: src/share/man/man9

2021-02-06 Thread Tetsuya Isaki
Hello,

At Sat, 6 Feb 2021 13:55:40 +,
Nia Alarie wrote:
> Module Name:  src
> Committed By: nia
> Date: Sat Feb  6 13:55:40 UTC 2021
> 
> Modified Files:
>   src/share/man/man9: audio.9
> 
> Log Message:
> Fix various typos, etc
> 
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.59 -r1.60 src/share/man/man9/audio.9

> @@ -175,9 +175,9 @@
>  .Vt audio_format_t
>  structure according to given number
>  .Va afp->index .
> -If there is no format with given number, return
> +If there is no format with the given number, return
>  .Er EINVAL .
> -It is called at any time.
> +It can be called at any time.

The later sounds to me "You(developer of MD driver) can call
it at any time".  If so, it's incorrect.

>  Similarly, if the driver supports
>  .Dv SLINEAR_OE:16
>  and the upper layer chooses it,
> -the driver does not need to provide a conversion function.
> -Because the upper layer only supports conversion between
> +the driver does not need to provide a conversion function,
> +because the upper layer supports conversion between

Is "only" a typo?  or is it better to remove it in English?

Thanks,
---
Tetsuya Isaki 


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

2021-02-04 Thread Tetsuya Isaki
Hello,

At Wed, 3 Feb 2021 13:37:24 -0500,
Michael wrote:
> > 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.
> 
> I just tested this on my C200 - playback works.

Thank you for quick response!

> The sample rate seems off - everything plays too slow, but that's
> probably completely unrelated.

Oops, this was my mistake.
I hope that harmony.c,v 1.9 will fix this problem.
Sorry for breaking it.
---
Tetsuya Isaki 



Re: CVS commit: src/sys/dev/audio

2020-05-30 Thread Tetsuya Isaki
At Fri, 29 May 2020 12:32:39 +,
nia wrote:
> OK... Can you request a pullup to ensure resuming with a stream
> playing doesn't panic on 9.1?

I will do it on next weekend.

Thanks,
---
Tetsuya Isaki 


Re: CVS commit: src/sys/dev/audio

2020-05-28 Thread Tetsuya Isaki
At Wed, 27 May 2020 13:19:22 +,
nia wrote:
> I think this is because audio_rmixer_start is used unguarded
> in audio_open (it doesn't check for the sc_rbusy flag).
> This isn't the case for pmixer. 
> 
> So, if the audio device is opened for recording for the 
> first time after system resumption, a panic will occur
> due to an assertion failure (the recording mixer would
> already be busy).

It's because your change didn't restore [pr]mixer's running
state correctly.  I have fixed it.

Thanks,
---
Tetsuya Isaki 


  1   2   3   >