CVS commit: src/sys/dev/audio

2020-02-21 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb 22 07:09:18 UTC 2020

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

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


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 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.47 src/sys/dev/audio/audio.c:1.48
--- src/sys/dev/audio/audio.c:1.47	Sat Feb 22 06:58:39 2020
+++ src/sys/dev/audio/audio.c	Sat Feb 22 07:09:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.47 2020/02/22 06:58:39 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.48 2020/02/22 07:09:18 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.47 2020/02/22 06:58:39 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.48 2020/02/22 07:09:18 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2690,15 +2690,11 @@ audio_ioctl(dev_t dev, struct audio_soft
 
 	case AUDIO_QUERYFORMAT:
 		query = (audio_format_query_t *)addr;
-		if (sc->hw_if->query_format) {
-			mutex_enter(sc->sc_lock);
-			error = sc->hw_if->query_format(sc->hw_hdl, query);
-			mutex_exit(sc->sc_lock);
-			/* Hide internal infomations */
-			query->fmt.driver_data = NULL;
-		} else {
-			error = ENODEV;
-		}
+		mutex_enter(sc->sc_lock);
+		error = sc->hw_if->query_format(sc->hw_hdl, query);
+		mutex_exit(sc->sc_lock);
+		/* Hide internal infomations */
+		query->fmt.driver_data = NULL;
 		break;
 
 	case AUDIO_GETFORMAT:
@@ -6226,21 +6222,6 @@ audio_hw_validate_format(struct audio_so
 
 	KASSERT(mutex_owned(sc->sc_lock));
 
-	/*
-	 * If query_format is not supported by hardware driver,
-	 * a rough check instead will be performed.
-	 * XXX This will gone in the future.
-	 */
-	if (sc->hw_if->query_format == NULL) {
-		if (fmt->encoding != AUDIO_ENCODING_SLINEAR_NE)
-			return EINVAL;
-		if (fmt->precision != AUDIO_INTERNAL_BITS)
-			return EINVAL;
-		if (fmt->stride != AUDIO_INTERNAL_BITS)
-			return EINVAL;
-		return 0;
-	}
-
 	for (index = 0; ; index++) {
 		query.index = index;
 		error = sc->hw_if->query_format(sc->hw_hdl, );



CVS commit: src/sys/dev/audio

2020-02-21 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb 22 06:58:40 UTC 2020

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

Log Message:
Improve KASSERT messages.


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.8 -r1.9 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.46 src/sys/dev/audio/audio.c:1.47
--- src/sys/dev/audio/audio.c:1.46	Sat Feb 22 06:36:07 2020
+++ src/sys/dev/audio/audio.c	Sat Feb 22 06:58:39 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.46 2020/02/22 06:36:07 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.47 2020/02/22 06:58:39 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.46 2020/02/22 06:36:07 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.47 2020/02/22 06:58:39 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2062,7 +2062,7 @@ audio_open(dev_t dev, struct audio_softc
 		*bellfile = af;
 	} else {
 		error = fd_clone(fp, fd, flags, _fileops, af);
-		KASSERT(error == EMOVEFD);
+		KASSERTMSG(error == EMOVEFD, "error=%d", error);
 	}
 
 	TRACEF(3, af, "done");
@@ -3060,7 +3060,7 @@ audioctl_open(dev_t dev, struct audio_so
 	/* Not necessary to insert sc_files. */
 
 	error = fd_clone(fp, fd, flags, _fileops, af);
-	KASSERT(error == EMOVEFD);
+	KASSERTMSG(error == EMOVEFD, "error=%d", error);
 
 	return error;
 }
@@ -3213,9 +3213,12 @@ audio_track_chvol(audio_filter_arg_t *ar
 	u_int channels;
 
 	DIAGNOSTIC_filter_arg(arg);
-	KASSERT(arg->srcfmt->channels == arg->dstfmt->channels);
+	KASSERTMSG(arg->srcfmt->channels == arg->dstfmt->channels,
+	"arg->srcfmt->channels=%d, arg->dstfmt->channels=%d",
+	arg->srcfmt->channels, arg->dstfmt->channels);
 	KASSERT(arg->context != NULL);
-	KASSERT(arg->srcfmt->channels <= AUDIO_MAX_CHANNELS);
+	KASSERTMSG(arg->srcfmt->channels <= AUDIO_MAX_CHANNELS,
+	"arg->srcfmt->channels=%d", arg->srcfmt->channels);
 
 	s = arg->src;
 	d = arg->dst;
@@ -3373,8 +3376,12 @@ audio_track_freq_up(audio_filter_arg_t *
 	DIAGNOSTIC_ring(dst);
 	DIAGNOSTIC_ring(src);
 	KASSERT(src->used > 0);
-	KASSERT(src->fmt.channels == dst->fmt.channels);
-	KASSERT(src->head % track->mixer->frames_per_block == 0);
+	KASSERTMSG(src->fmt.channels == dst->fmt.channels,
+	"src->fmt.channels=%d dst->fmt.channels=%d",
+	src->fmt.channels, dst->fmt.channels);
+	KASSERTMSG(src->head % track->mixer->frames_per_block == 0,
+	"src->head=%d track->mixer->frames_per_block=%d",
+	src->head, track->mixer->frames_per_block);
 
 	s = arg->src;
 	d = arg->dst;
@@ -3499,9 +3506,11 @@ audio_track_freq_down(audio_filter_arg_t
 	DIAGNOSTIC_ring(dst);
 	DIAGNOSTIC_ring(src);
 	KASSERT(src->used > 0);
-	KASSERT(src->fmt.channels == dst->fmt.channels);
+	KASSERTMSG(src->fmt.channels == dst->fmt.channels,
+	"src->fmt.channels=%d dst->fmt.channels=%d",
+	src->fmt.channels, dst->fmt.channels);
 	KASSERTMSG(src->head % track->mixer->frames_per_block == 0,
-	"src->head=%d fpb=%d",
+	"src->head=%d track->mixer->frames_per_block=%d",
 	src->head, track->mixer->frames_per_block);
 
 	s0 = arg->src;
@@ -4192,7 +4201,9 @@ audio_append_silence(audio_track_t *trac
 
 	n = (ring->capacity - ring->used) % fpb;
 
-	KASSERT(auring_get_contig_free(ring) >= n);
+	KASSERTMSG(auring_get_contig_free(ring) >= n,
+	"auring_get_contig_free(ring)=%d n=%d",
+	auring_get_contig_free(ring), n);
 
 	memset(auring_tailptr_aint(ring), 0,
 	n * ring->fmt.channels * sizeof(aint_t));
@@ -4225,7 +4236,7 @@ audio_apply_stage(audio_track_t *track, 
 	dstcount = auring_get_contig_free(stage->dst);
 
 	if (isfreq) {
-		KASSERTMSG(srccount > 0, "freq but srccount == %d", srccount);
+		KASSERTMSG(srccount > 0, "freq but srccount=%d", srccount);
 		count = uimin(dstcount, track->mixer->frames_per_block);
 	} else {
 		count = uimin(srccount, dstcount);
@@ -4310,7 +4321,8 @@ audio_track_play(audio_track_t *track)
 		int bytes2;
 
 		bytes1 = auring_get_contig_used(usrbuf);
-		KASSERT(bytes1 % framesize == 0);
+		KASSERTMSG(bytes1 % framesize == 0,
+		"bytes1=%d framesize=%d", bytes1, framesize);
 		memcpy((uint8_t *)input->mem + auring_tail(input) * framesize,
 		(uint8_t *)usrbuf->mem + usrbuf->head,
 		bytes1);
@@ -4473,7 +4485,8 @@ audio_track_record(audio_track_t *track)
 		int bytes2;
 
 		bytes1 = auring_get_contig_free(usrbuf);
-		KASSERT(bytes1 % framesize == 0);
+		KASSERTMSG(bytes1 % framesize == 0,
+		"bytes1=%d framesize=%d", bytes1, framesize);
 		memcpy((uint8_t *)usrbuf->mem + auring_tail(usrbuf),
 		(uint8_t *)outbuf->mem + outbuf->head * framesize,
 		bytes1);
@@ -4869,7 +4882,9 @@ audio_pmixer_process(struct audio_softc 
 	mixer = sc->sc_pmixer;
 
 	frame_count = 

CVS commit: src/sys/dev/audio

2020-02-21 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb 22 06:36:07 UTC 2020

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

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


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 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.45 src/sys/dev/audio/audio.c:1.46
--- src/sys/dev/audio/audio.c:1.45	Sat Feb 22 06:28:10 2020
+++ src/sys/dev/audio/audio.c	Sat Feb 22 06:36:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.45 2020/02/22 06:28:10 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.46 2020/02/22 06:36:07 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.45 2020/02/22 06:28:10 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.46 2020/02/22 06:36:07 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -5944,8 +5944,9 @@ audio_mixers_init(struct audio_softc *sc
 		}
 		error = audio_mixer_init(sc, AUMODE_PLAY, phwfmt, pfil);
 		if (error) {
-			aprint_error_dev(sc->sc_dev,
-			"configuring playback mode failed\n");
+			device_printf(sc->sc_dev,
+			"configuring playback mode failed with %d\n",
+			error);
 			kmem_free(sc->sc_pmixer, sizeof(*sc->sc_pmixer));
 			sc->sc_pmixer = NULL;
 			return error;
@@ -5962,8 +5963,9 @@ audio_mixers_init(struct audio_softc *sc
 		}
 		error = audio_mixer_init(sc, AUMODE_RECORD, rhwfmt, rfil);
 		if (error) {
-			aprint_error_dev(sc->sc_dev,
-			"configuring record mode failed\n");
+			device_printf(sc->sc_dev,
+			"configuring record mode failed with %d\n",
+			error);
 			kmem_free(sc->sc_rmixer, sizeof(*sc->sc_rmixer));
 			sc->sc_rmixer = NULL;
 			return error;



CVS commit: src/sys/dev/audio

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

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

Log Message:
const-ify.  These arguments are no longer written back.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 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.44 src/sys/dev/audio/audio.c:1.45
--- src/sys/dev/audio/audio.c:1.44	Sat Feb 22 06:22:46 2020
+++ src/sys/dev/audio/audio.c	Sat Feb 22 06:28:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.44 2020/02/22 06:22:46 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.45 2020/02/22 06:28:10 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.44 2020/02/22 06:22:46 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.45 2020/02/22 06:28:10 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -547,7 +547,7 @@ static void audio_track_setinfo_water(au
 static int audio_hw_setinfo(struct audio_softc *, const struct audio_info *,
 	struct audio_info *);
 static int audio_hw_set_format(struct audio_softc *, int,
-	audio_format2_t *, audio_format2_t *,
+	const audio_format2_t *, const audio_format2_t *,
 	audio_filter_reg_t *, audio_filter_reg_t *);
 static int audiogetinfo(struct audio_softc *, struct audio_info *, int,
 	audio_file_t *);
@@ -6993,7 +6993,6 @@ abort:
  *   parameters.
  * - pfil and rfil must be zero-filled.
  * If successful,
- * - phwfmt, rhwfmt will be overwritten by hardware format.
  * - pfil, rfil will be filled with filter information specified by the
  *   hardware driver.
  * and then returns 0.  Otherwise returns errno.
@@ -7001,7 +7000,7 @@ abort:
  */
 static int
 audio_hw_set_format(struct audio_softc *sc, int setmode,
-	audio_format2_t *phwfmt, audio_format2_t *rhwfmt,
+	const audio_format2_t *phwfmt, const audio_format2_t *rhwfmt,
 	audio_filter_reg_t *pfil, audio_filter_reg_t *rfil)
 {
 	audio_params_t pp, rp;



CVS commit: src/sys/dev/audio

2020-02-21 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb 22 06:22:46 UTC 2020

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

Log Message:
Fix/Update comments.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 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.43 src/sys/dev/audio/audio.c:1.44
--- src/sys/dev/audio/audio.c:1.43	Sat Feb 22 05:51:39 2020
+++ src/sys/dev/audio/audio.c	Sat Feb 22 06:22:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.43 2020/02/22 05:51:39 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.44 2020/02/22 06:22:46 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.43 2020/02/22 05:51:39 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.44 2020/02/22 06:22:46 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -6274,9 +6274,9 @@ audio_hw_validate_format(struct audio_so
 /*
  * Set track mixer's format depending on ai->mode.
  * If AUMODE_PLAY is set in ai->mode, it set up the playback mixer
- * with ai.play.{channels, sample_rate}.
+ * with ai.play.*.
  * If AUMODE_RECORD is set in ai->mode, it set up the recording mixer
- * with ai.record.{channels, sample_rate}.
+ * with ai.record.*.
  * All other fields in ai are ignored.
  * If successful returns 0.  Otherwise returns errno.
  * This function does not roll back even if it fails.
@@ -6304,7 +6304,6 @@ audio_mixers_set_format(struct audio_sof
 	if (!SPECIFIED(ai->mode) || ai->mode == 0)
 		return ENOTTY;
 
-	/* Only channels and sample_rate are changeable. */
 	mode = ai->mode;
 	if ((mode & AUMODE_PLAY)) {
 		phwfmt.encoding= ai->play.encoding;
@@ -6844,7 +6843,7 @@ audio_track_setinfo_water(audio_track_t 
 }
 
 /*
- * Set hardware part of *ai.
+ * Set hardware part of *newai.
  * The parameters handled here are *.port, *.gain, *.balance and monitor_gain.
  * If oldai is specified, previous parameters are stored.
  * This function itself does not roll back if error occurred.



CVS commit: src/tests/dev/audio

2020-02-21 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb 22 05:53:19 UTC 2020

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

Log Message:
Update AUDIO_SETINFO_channels test.
The kernel limits the number of channels that userland apps can set to
the number of channels supported by the hardware or less.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 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.5 src/tests/dev/audio/audiotest.c:1.6
--- src/tests/dev/audio/audiotest.c:1.5	Tue Feb 18 12:11:26 2020
+++ src/tests/dev/audio/audiotest.c	Sat Feb 22 05:53:19 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiotest.c,v 1.5 2020/02/18 12:11:26 isaki Exp $	*/
+/*	$NetBSD: audiotest.c,v 1.6 2020/02/22 05:53:19 isaki Exp $	*/
 
 /*
  * Copyright (C) 2019 Tetsuya Isaki. All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: audiotest.c,v 1.5 2020/02/18 12:11:26 isaki Exp $");
+__RCSID("$NetBSD: audiotest.c,v 1.6 2020/02/22 05:53:19 isaki Exp $");
 
 #include 
 #include 
@@ -5413,11 +5413,13 @@ DEF(AUDIO_SETINFO_params_simul)
  */
 DEF(AUDIO_SETINFO_channels)
 {
+	struct audio_info hwinfo;
 	struct audio_info ai;
 	int mode;
 	int r;
 	int fd;
 	int i;
+	unsigned int ch;
 	struct {
 		int ch;
 		bool expected;
@@ -5425,9 +5427,6 @@ DEF(AUDIO_SETINFO_channels)
 		{  0,	false },
 		{  1,	true },	/* monaural */
 		{  2,	true },	/* stereo */
-		{  3,	true },	/* multi channels */
-		{ 12,	true },	/* upper limit */
-		{ 13,	false },
 	};
 
 	TEST("AUDIO_SETINFO_channels");
@@ -5444,8 +5443,12 @@ DEF(AUDIO_SETINFO_channels)
 	fd = OPEN(devaudio, mode);
 	REQUIRED_SYS_OK(fd);
 
+	/*
+	 * The audio layer always supports monaural and stereo regardless of
+	 * the hardware capability.
+	 */
 	for (i = 0; i < (int)__arraycount(table); i++) {
-		int ch = table[i].ch;
+		ch = table[i].ch;
 		bool expected = table[i].expected;
 
 		AUDIO_INITINFO();
@@ -5470,6 +5473,52 @@ DEF(AUDIO_SETINFO_channels)
 		}
 	}
 
+	/*
+	 * The maximum number of supported channels depends the hardware.
+	 */
+	/* Get the number of channels that the hardware supports */
+	r = IOCTL(fd, AUDIO_GETFORMAT, , "");
+	REQUIRED_SYS_EQ(0, r);
+
+	if ((hwinfo.mode & AUMODE_PLAY)) {
+		DPRINTF("  > hwinfo.play.channels = %d\n",
+		hwinfo.play.channels);
+		for (ch = 3; ch <= hwinfo.play.channels; ch++) {
+			AUDIO_INITINFO();
+			ai.play.channels = ch;
+			r = IOCTL(fd, AUDIO_SETINFO, , "channels=%d", ch);
+			XP_SYS_EQ(0, r);
+
+			r = IOCTL(fd, AUDIO_GETBUFINFO, , "");
+			XP_SYS_EQ(0, r);
+			XP_EQ(ch, ai.play.channels);
+		}
+
+		AUDIO_INITINFO();
+		ai.play.channels = ch;
+		r = IOCTL(fd, AUDIO_SETINFO, , "channels=%d", ch);
+		XP_SYS_NG(EINVAL, r);
+	}
+	if ((hwinfo.mode & AUMODE_RECORD)) {
+		DPRINTF("  > hwinfo.record.channels = %d\n",
+		hwinfo.record.channels);
+		for (ch = 3; ch <= hwinfo.record.channels; ch++) {
+			AUDIO_INITINFO();
+			ai.record.channels = ch;
+			r = IOCTL(fd, AUDIO_SETINFO, , "channels=%d", ch);
+			XP_SYS_EQ(0, r);
+
+			r = IOCTL(fd, AUDIO_GETBUFINFO, , "");
+			XP_SYS_EQ(0, r);
+			XP_EQ(ch, ai.record.channels);
+		}
+
+		AUDIO_INITINFO();
+		ai.record.channels = ch;
+		r = IOCTL(fd, AUDIO_SETINFO, , "channels=%d", ch);
+		XP_SYS_NG(EINVAL, r);
+	}
+
 	r = CLOSE(fd);
 	XP_SYS_EQ(0, r);
 }



CVS commit: src/sys/dev/audio

2020-02-21 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Sat Feb 22 05:51:39 UTC 2020

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

Log Message:
Limit the number of channels that userland apps can set (by AUDIO_SETINFO)
to the number of channels supported by the hardware or less, if the hardware
supports multi channels.
- On monaural or stereo hardware, userland apps can always set 1ch or 2ch.
  The kernel (audio layer) can convert mono-stereo each other.
- On 3ch (2.1ch) hardware, for example, userland apps can set 1, 2, or 3ch,
  but not 4ch or more.
This allows userland apps to know actual number of channels supported by
the hardware in the same way as before.
PR kern/54973.


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 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.42 src/sys/dev/audio/audio.c:1.43
--- src/sys/dev/audio/audio.c:1.42	Sat Feb 15 02:47:00 2020
+++ src/sys/dev/audio/audio.c	Sat Feb 22 05:51:39 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.42 2020/02/15 02:47:00 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.43 2020/02/22 05:51:39 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.42 2020/02/15 02:47:00 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.43 2020/02/22 05:51:39 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -541,7 +541,7 @@ static __inline int audio_track_readable
 static int audio_file_setinfo(struct audio_softc *, audio_file_t *,
 	const struct audio_info *);
 static int audio_track_setinfo_check(audio_format2_t *,
-	const struct audio_prinfo *);
+	const struct audio_prinfo *, const audio_format2_t *);
 static void audio_track_setinfo_water(audio_track_t *,
 	const struct audio_info *);
 static int audio_hw_setinfo(struct audio_softc *, const struct audio_info *,
@@ -6634,7 +6634,8 @@ audio_file_setinfo(struct audio_softc *s
 	}
 
 	if (ptrack) {
-		pchanges = audio_track_setinfo_check(, pi);
+		pchanges = audio_track_setinfo_check(, pi,
+		>sc_pmixer->hwbuf.fmt);
 		if (pchanges == -1) {
 #if defined(AUDIO_DEBUG)
 			char fmtbuf[64];
@@ -6648,7 +6649,8 @@ audio_file_setinfo(struct audio_softc *s
 			pchanges = 1;
 	}
 	if (rtrack) {
-		rchanges = audio_track_setinfo_check(, ri);
+		rchanges = audio_track_setinfo_check(, ri,
+		>sc_rmixer->hwbuf.fmt);
 		if (rchanges == -1) {
 #if defined(AUDIO_DEBUG)
 			char fmtbuf[64];
@@ -6760,7 +6762,8 @@ abort1:
  * Return value of -1 indicates that error EINVAL has occurred.
  */
 static int
-audio_track_setinfo_check(audio_format2_t *fmt, const struct audio_prinfo *info)
+audio_track_setinfo_check(audio_format2_t *fmt, const struct audio_prinfo *info,
+	const audio_format2_t *hwfmt)
 {
 	int changes;
 
@@ -6784,6 +6787,13 @@ audio_track_setinfo_check(audio_format2_
 		changes = 1;
 	}
 	if (SPECIFIED(info->channels)) {
+		/*
+		 * We can convert between monaural and stereo each other.
+		 * We can reduce than the number of channels that the hardware
+		 * supports.
+		 */
+		if (info->channels > 2 && info->channels > hwfmt->channels)
+			return -1;
 		fmt->channels = info->channels;
 		changes = 1;
 	}



CVS commit: src/sys

2020-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Feb 22 02:28:06 UTC 2020

Modified Files:
src/sys/arch/evbarm/conf: GENERIC64
src/sys/dev/acpi: files.acpi
Added Files:
src/sys/dev/acpi: genet_acpi.c

Log Message:
Add ACPI glue for Broadcom GENETv5


To generate a diff of this commit:
cvs rdiff -u -r1.138 -r1.139 src/sys/arch/evbarm/conf/GENERIC64
cvs rdiff -u -r1.114 -r1.115 src/sys/dev/acpi/files.acpi
cvs rdiff -u -r0 -r1.1 src/sys/dev/acpi/genet_acpi.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/evbarm/conf/GENERIC64
diff -u src/sys/arch/evbarm/conf/GENERIC64:1.138 src/sys/arch/evbarm/conf/GENERIC64:1.139
--- src/sys/arch/evbarm/conf/GENERIC64:1.138	Sat Feb 22 00:28:35 2020
+++ src/sys/arch/evbarm/conf/GENERIC64	Sat Feb 22 02:28:06 2020
@@ -1,5 +1,5 @@
 #
-#	$NetBSD: GENERIC64,v 1.138 2020/02/22 00:28:35 jmcneill Exp $
+#	$NetBSD: GENERIC64,v 1.139 2020/02/22 02:28:06 jmcneill Exp $
 #
 #	GENERIC ARM (aarch64) kernel
 #
@@ -327,7 +327,8 @@ emac*		at fdt?# Allwinner Gigabit Et
 enet*		at fdt?# IMX FEC
 aq*		at pci? dev ? function ?	# Aquantia AQC 10 gigabit
 ena*		at pci? dev ? function ?	# Amazon.com Elastic Network Adapter
-genet*		at fdt?# Broadcom GENET v5
+genet*		at acpi?			# Broadcom GENET v5
+genet*		at fdt?
 mcx*		at pci? dev ? function ?	# Mellanox 5th generation Ethernet
 mskc*		at pci? dev ? function ?	# Marvell Yukon 2 Gigabit Ethernet
 msk*		at mskc?

Index: src/sys/dev/acpi/files.acpi
diff -u src/sys/dev/acpi/files.acpi:1.114 src/sys/dev/acpi/files.acpi:1.115
--- src/sys/dev/acpi/files.acpi:1.114	Tue Dec 25 11:56:14 2018
+++ src/sys/dev/acpi/files.acpi	Sat Feb 22 02:28:06 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.acpi,v 1.114 2018/12/25 11:56:14 mlelstv Exp $
+#	$NetBSD: files.acpi,v 1.115 2020/02/22 02:28:06 jmcneill Exp $
 
 include "dev/acpi/acpica/files.acpica"
 
@@ -269,4 +269,8 @@ device	ipmi_acpi: ipmibus
 attach	ipmi_acpi at acpinodebus
 file	dev/acpi/ipmi_acpi.c		ipmi_acpi
 
+# Broadcom GENETv5
+attach	genet at acpinodebus with genet_acpi
+file	dev/acpi/genet_acpi.c		genet_acpi
+
 include	"dev/acpi/wmi/files.wmi"

Added files:

Index: src/sys/dev/acpi/genet_acpi.c
diff -u /dev/null src/sys/dev/acpi/genet_acpi.c:1.1
--- /dev/null	Sat Feb 22 02:28:06 2020
+++ src/sys/dev/acpi/genet_acpi.c	Sat Feb 22 02:28:06 2020
@@ -0,0 +1,154 @@
+/* $NetBSD: genet_acpi.c,v 1.1 2020/02/22 02:28:06 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2020 Jared McNeill 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "opt_net_mpsafe.h"
+
+#include 
+__KERNEL_RCSID(0, "$NetBSD: genet_acpi.c,v 1.1 2020/02/22 02:28:06 jmcneill Exp $");
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+
+#ifdef NET_MPSAFE
+#define	GENET_INTR_MPSAFE	true
+#else
+#define	GENET_INTR_MPSAFE	false
+#endif
+
+static const char * const compatible[] = {
+	"BCM6E4E",	/* Broadcom GENET v5 */
+	NULL
+};
+
+static int	genet_acpi_match(device_t, cfdata_t, void *);
+static void	genet_acpi_attach(device_t, device_t, void *);
+
+CFATTACH_DECL_NEW(genet_acpi, sizeof(struct genet_softc),
+genet_acpi_match, genet_acpi_attach, NULL, NULL);
+
+static int
+genet_acpi_match(device_t parent, cfdata_t cf, void *aux)
+{
+	struct acpi_attach_args *aa = aux;
+
+	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
+		return 0;
+
+	return acpi_match_hid(aa->aa_node->ad_devinfo, compatible);
+}
+
+static void
+genet_acpi_attach(device_t parent, device_t self, void *aux)
+{
+	struct genet_softc * const sc = device_private(self);
+	struct acpi_attach_args *aa = aux;

CVS commit: src/sbin/route

2020-02-21 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Feb 22 00:42:15 UTC 2020

Modified Files:
src/sbin/route: route.c

Log Message:
Avoid undefined behavior

route.c:1523:20, left shift of 1073741824 by 1 places cannot be represented
in type 'int'


To generate a diff of this commit:
cvs rdiff -u -r1.165 -r1.166 src/sbin/route/route.c

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

Modified files:

Index: src/sbin/route/route.c
diff -u src/sbin/route/route.c:1.165 src/sbin/route/route.c:1.166
--- src/sbin/route/route.c:1.165	Wed Jan 22 19:22:06 2020
+++ src/sbin/route/route.c	Sat Feb 22 00:42:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.165 2020/01/22 19:22:06 roy Exp $	*/
+/*	$NetBSD: route.c,v 1.166 2020/02/22 00:42:15 kamil Exp $	*/
 
 /*
  * Copyright (c) 1983, 1989, 1991, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = "@(#)route.c	8.6 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: route.c,v 1.165 2020/01/22 19:22:06 roy Exp $");
+__RCSID("$NetBSD: route.c,v 1.166 2020/02/22 00:42:15 kamil Exp $");
 #endif
 #endif /* not lint */
 
@@ -1498,7 +1498,7 @@ print_getmsg(struct rt_msghdr *rtm, int 
 	struct sockaddr_dl *ifp = NULL;
 	struct sockaddr *sa;
 	char *cp;
-	int i;
+	unsigned int i;
 
 	if (! shortoutput) {
 		(void)printf("   route to: %s\n",



CVS commit: src/lib/libc/gdtoa

2020-02-21 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Feb 22 00:38:15 UTC 2020

Modified Files:
src/lib/libc/gdtoa: gethex.c

Log Message:
Avoid unportable left shift construct

left shift of 9 by 28 places cannot be represented in type 'int'


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/gdtoa/gethex.c

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

Modified files:

Index: src/lib/libc/gdtoa/gethex.c
diff -u src/lib/libc/gdtoa/gethex.c:1.6 src/lib/libc/gdtoa/gethex.c:1.7
--- src/lib/libc/gdtoa/gethex.c:1.6	Fri Apr 19 10:41:53 2013
+++ src/lib/libc/gdtoa/gethex.c	Sat Feb 22 00:38:14 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: gethex.c,v 1.6 2013/04/19 10:41:53 joerg Exp $ */
+/* $NetBSD: gethex.c,v 1.7 2020/02/22 00:38:14 kamil Exp $ */
 
 /
 
@@ -209,7 +209,7 @@ gethex( CONST char **sp, CONST FPI *fpi,
 			L = 0;
 			n = 0;
 			}
-		L |= (hexdig[(unsigned char)*s1] & 0x0f) << n;
+		L |= (unsigned int)(hexdig[(unsigned char)*s1] & 0x0f) << n;
 		n += 4;
 		}
 	*x++ = L;



CVS commit: src/sys/ufs/lfs

2020-02-21 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Feb 22 00:32:09 UTC 2020

Modified Files:
src/sys/ufs/lfs: lfs_alloc.c

Log Message:
Avoid undefined behavior in *_BITMAP_FREE() macros

left shift of 1 by 31 places cannot be represented in type 'int'


To generate a diff of this commit:
cvs rdiff -u -r1.138 -r1.139 src/sys/ufs/lfs/lfs_alloc.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/ufs/lfs/lfs_alloc.c
diff -u src/sys/ufs/lfs/lfs_alloc.c:1.138 src/sys/ufs/lfs/lfs_alloc.c:1.139
--- src/sys/ufs/lfs/lfs_alloc.c:1.138	Fri Jan 17 20:08:10 2020
+++ src/sys/ufs/lfs/lfs_alloc.c	Sat Feb 22 00:32:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_alloc.c,v 1.138 2020/01/17 20:08:10 ad Exp $	*/
+/*	$NetBSD: lfs_alloc.c,v 1.139 2020/02/22 00:32:08 kamil Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.138 2020/01/17 20:08:10 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.139 2020/02/22 00:32:08 kamil Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -95,16 +95,16 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,
 #define SET_BITMAP_FREE(F, I) do { \
 	DLOG((DLOG_ALLOC, "lfs: ino %d wrd %d bit %d set\n", (int)(I), 	\
 	 (int)((I) >> BMSHIFT), (int)((I) & BMMASK)));		\
-	(F)->lfs_ino_bitmap[(I) >> BMSHIFT] |= (1 << ((I) & BMMASK));	\
+	(F)->lfs_ino_bitmap[(I) >> BMSHIFT] |= (1U << ((I) & BMMASK));	\
 } while (0)
 #define CLR_BITMAP_FREE(F, I) do { \
 	DLOG((DLOG_ALLOC, "lfs: ino %d wrd %d bit %d clr\n", (int)(I), 	\
 	 (int)((I) >> BMSHIFT), (int)((I) & BMMASK)));		\
-	(F)->lfs_ino_bitmap[(I) >> BMSHIFT] &= ~(1 << ((I) & BMMASK));	\
+	(F)->lfs_ino_bitmap[(I) >> BMSHIFT] &= ~(1U << ((I) & BMMASK));	\
 } while(0)
 
 #define ISSET_BITMAP_FREE(F, I) \
-	((F)->lfs_ino_bitmap[(I) >> BMSHIFT] & (1 << ((I) & BMMASK)))
+	((F)->lfs_ino_bitmap[(I) >> BMSHIFT] & (1U << ((I) & BMMASK)))
 
 /*
  * Add a new block to the Ifile, to accommodate future file creations.



CVS commit: src/sys

2020-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Feb 22 00:28:36 UTC 2020

Modified Files:
src/sys/arch/arm/broadcom: bcm283x_platform.c
src/sys/arch/evbarm/conf: GENERIC64
src/sys/conf: files
src/sys/dev/fdt: files.fdt
Added Files:
src/sys/dev/fdt: genet_fdt.c
src/sys/dev/ic: bcmgenet.c bcmgenetreg.h bcmgenetvar.h

Log Message:
Add support for Broadcom GENET v5 ethernet controller as found on the
Raspberry Pi 4 (BCM2711).


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/arm/broadcom/bcm283x_platform.c
cvs rdiff -u -r1.137 -r1.138 src/sys/arch/evbarm/conf/GENERIC64
cvs rdiff -u -r1.1255 -r1.1256 src/sys/conf/files
cvs rdiff -u -r1.50 -r1.51 src/sys/dev/fdt/files.fdt
cvs rdiff -u -r0 -r1.1 src/sys/dev/fdt/genet_fdt.c
cvs rdiff -u -r0 -r1.1 src/sys/dev/ic/bcmgenet.c src/sys/dev/ic/bcmgenetreg.h \
src/sys/dev/ic/bcmgenetvar.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/arm/broadcom/bcm283x_platform.c
diff -u src/sys/arch/arm/broadcom/bcm283x_platform.c:1.36 src/sys/arch/arm/broadcom/bcm283x_platform.c:1.37
--- src/sys/arch/arm/broadcom/bcm283x_platform.c:1.36	Sat Feb 22 00:17:54 2020
+++ src/sys/arch/arm/broadcom/bcm283x_platform.c	Sat Feb 22 00:28:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: bcm283x_platform.c,v 1.36 2020/02/22 00:17:54 jmcneill Exp $	*/
+/*	$NetBSD: bcm283x_platform.c,v 1.37 2020/02/22 00:28:35 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2017 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bcm283x_platform.c,v 1.36 2020/02/22 00:17:54 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm283x_platform.c,v 1.37 2020/02/22 00:28:35 jmcneill Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_bcm283x.h"
@@ -1415,7 +1415,9 @@ bcm283x_platform_device_register(device_
 		booted_device = dev;
 	}
 #endif
-	if ((device_is_a(dev, "usmsc") || device_is_a(dev, "mue")) &&
+	if ((device_is_a(dev, "usmsc") ||
+	 device_is_a(dev, "mue") ||
+	 device_is_a(dev, "genet")) &&
 	vcprop_tag_success_p(_macaddr.tag)) {
 		const uint8_t enaddr[ETHER_ADDR_LEN] = {
 		 (vb.vbt_macaddr.addr >> 0) & 0xff,

Index: src/sys/arch/evbarm/conf/GENERIC64
diff -u src/sys/arch/evbarm/conf/GENERIC64:1.137 src/sys/arch/evbarm/conf/GENERIC64:1.138
--- src/sys/arch/evbarm/conf/GENERIC64:1.137	Thu Feb 20 01:36:37 2020
+++ src/sys/arch/evbarm/conf/GENERIC64	Sat Feb 22 00:28:35 2020
@@ -1,5 +1,5 @@
 #
-#	$NetBSD: GENERIC64,v 1.137 2020/02/20 01:36:37 jmcneill Exp $
+#	$NetBSD: GENERIC64,v 1.138 2020/02/22 00:28:35 jmcneill Exp $
 #
 #	GENERIC ARM (aarch64) kernel
 #
@@ -327,6 +327,7 @@ emac*		at fdt?# Allwinner Gigabit Et
 enet*		at fdt?# IMX FEC
 aq*		at pci? dev ? function ?	# Aquantia AQC 10 gigabit
 ena*		at pci? dev ? function ?	# Amazon.com Elastic Network Adapter
+genet*		at fdt?# Broadcom GENET v5
 mcx*		at pci? dev ? function ?	# Mellanox 5th generation Ethernet
 mskc*		at pci? dev ? function ?	# Marvell Yukon 2 Gigabit Ethernet
 msk*		at mskc?

Index: src/sys/conf/files
diff -u src/sys/conf/files:1.1255 src/sys/conf/files:1.1256
--- src/sys/conf/files:1.1255	Sat Feb  8 07:07:07 2020
+++ src/sys/conf/files	Sat Feb 22 00:28:35 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files,v 1.1255 2020/02/08 07:07:07 maxv Exp $
+#	$NetBSD: files,v 1.1256 2020/02/22 00:28:35 jmcneill Exp $
 #	@(#)files.newconf	7.5 (Berkeley) 5/10/93
 
 version 	20171118
@@ -1470,6 +1470,10 @@ file	dev/ic/dw_hdmi_phy.c		dwhdmi
 device	anxdp: edid, videomode, drmkms, drmkms_i2c
 file	dev/ic/anx_dp.c			anxdp
 
+# Broadcom GENET v5 ethernet
+device	genet: arp, ether, ifnet, mii
+file	dev/ic/bcmgenet.c		genet
+
 #
 # File systems
 #

Index: src/sys/dev/fdt/files.fdt
diff -u src/sys/dev/fdt/files.fdt:1.50 src/sys/dev/fdt/files.fdt:1.51
--- src/sys/dev/fdt/files.fdt:1.50	Thu Jan  2 00:57:10 2020
+++ src/sys/dev/fdt/files.fdt	Sat Feb 22 00:28:35 2020
@@ -1,4 +1,4 @@
-# $NetBSD: files.fdt,v 1.50 2020/01/02 00:57:10 jmcneill Exp $
+# $NetBSD: files.fdt,v 1.51 2020/02/22 00:28:35 jmcneill Exp $
 
 include	"external/bsd/libfdt/conf/files.libfdt"
 
@@ -171,3 +171,6 @@ device	simpleamp
 attach	simpleamp at fdt
 file	dev/fdt/simple_amplifier.c		simpleamp
 
+# Broadcom GENET v5
+attach	genet at fdt with genet_fdt
+file	dev/fdt/genet_fdt.c			genet_fdt

Added files:

Index: src/sys/dev/fdt/genet_fdt.c
diff -u /dev/null src/sys/dev/fdt/genet_fdt.c:1.1
--- /dev/null	Sat Feb 22 00:28:36 2020
+++ src/sys/dev/fdt/genet_fdt.c	Sat Feb 22 00:28:35 2020
@@ -0,0 +1,134 @@
+/* $NetBSD: genet_fdt.c,v 1.1 2020/02/22 00:28:35 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2020 Jared McNeill 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *

CVS commit: src/tests/modules

2020-02-21 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Feb 22 00:24:15 UTC 2020

Modified Files:
src/tests/modules: t_modctl.c

Log Message:
Avoid undefined behavior in get_modstat_info

t_modctl.c:114:16, member access within misaligned address 0x71bf5bcede84
for type 'struct modstat_t'

t_modctl.c:116:13, load of misaligned address 0x7e81bc3c9104 for type
'struct modstat_t' which requires 8 byte alignment


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/modules/t_modctl.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/modules/t_modctl.c
diff -u src/tests/modules/t_modctl.c:1.14 src/tests/modules/t_modctl.c:1.15
--- src/tests/modules/t_modctl.c:1.14	Sun Apr 21 11:45:09 2019
+++ src/tests/modules/t_modctl.c	Sat Feb 22 00:24:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_modctl.c,v 1.14 2019/04/21 11:45:09 maya Exp $	*/
+/*	$NetBSD: t_modctl.c,v 1.15 2020/02/22 00:24:15 kamil Exp $	*/
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: t_modctl.c,v 1.14 2019/04/21 11:45:09 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: t_modctl.c,v 1.15 2020/02/22 00:24:15 kamil Exp $");
 
 #include 
 #include 
@@ -87,6 +87,7 @@ get_modstat_info(const char *name, modst
 	int count;
 	struct iovec iov;
 	modstat_t *ms;
+	modstat_t m;
 
 	check_permission();
 	for (len = 8192; ;) {
@@ -111,9 +112,10 @@ get_modstat_info(const char *name, modst
 	count = *(int *)iov.iov_base;
 	ms = (modstat_t *)((char *)iov.iov_base + sizeof(int));
 	while ( count ) {
-		if (strcmp(ms->ms_name, name) == 0) {
+		memcpy(, ms, sizeof(m));
+		if (strcmp(m.ms_name, name) == 0) {
 			if (msdest != NULL)
-*msdest = *ms;
+memcpy(msdest, , sizeof(*msdest));
 			found = true;
 			break;
 		}



CVS commit: src/tests/modules

2020-02-21 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Feb 22 00:18:55 UTC 2020

Modified Files:
src/tests/modules: t_builtin.c

Log Message:
Avoid undefined behavior in disabledstat

t_builtin.c:174:16, member access within misaligned address 0x741271c25004
for type 'struct modstat_t'

t_builtin.c:175:4, member access within misaligned address 0x741271c251c4
for type 'struct modstat_t'


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/modules/t_builtin.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/modules/t_builtin.c
diff -u src/tests/modules/t_builtin.c:1.4 src/tests/modules/t_builtin.c:1.5
--- src/tests/modules/t_builtin.c:1.4	Sun Jan 27 02:08:50 2019
+++ src/tests/modules/t_builtin.c	Sat Feb 22 00:18:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_builtin.c,v 1.4 2019/01/27 02:08:50 pgoyette Exp $	*/
+/*	$NetBSD: t_builtin.c,v 1.5 2020/02/22 00:18:55 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.  All rights reserved.
@@ -140,6 +140,7 @@ ATF_TC_HEAD(disabledstat, tc)
 ATF_TC_BODY(disabledstat, tc)
 {
 	modstat_t *ms;
+	modstat_t m;
 	struct iovec iov;
 	size_t len;
 	int count;
@@ -171,8 +172,9 @@ ATF_TC_BODY(disabledstat, tc)
 	count = *(int *)iov.iov_base;
 	ms = (modstat_t *)((char *)iov.iov_base + sizeof(int));
 	while ( count ) {
-		if (strcmp(ms->ms_name, kernfs) == 0) {
-			ATF_REQUIRE_EQ(ms->ms_refcnt, (u_int)-1);
+		memcpy(, ms, sizeof(m));		
+		if (strcmp(m.ms_name, kernfs) == 0) {
+			ATF_REQUIRE_EQ(m.ms_refcnt, (u_int)-1);
 			found = true;
 			break;
 		}



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

2020-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Feb 22 00:17:54 UTC 2020

Modified Files:
src/sys/arch/arm/broadcom: bcm2835reg.h bcm283x_platform.c

Log Message:
Translate bus addresses for SCB on BCM2711


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/arm/broadcom/bcm2835reg.h
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/arm/broadcom/bcm283x_platform.c

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

Modified files:

Index: src/sys/arch/arm/broadcom/bcm2835reg.h
diff -u src/sys/arch/arm/broadcom/bcm2835reg.h:1.29 src/sys/arch/arm/broadcom/bcm2835reg.h:1.30
--- src/sys/arch/arm/broadcom/bcm2835reg.h:1.29	Mon Dec 30 16:19:27 2019
+++ src/sys/arch/arm/broadcom/bcm2835reg.h	Sat Feb 22 00:17:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: bcm2835reg.h,v 1.29 2019/12/30 16:19:27 skrll Exp $	*/
+/*	$NetBSD: bcm2835reg.h,v 1.30 2020/02/22 00:17:54 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -124,6 +124,15 @@
 
 #define	BCM2835_INTC_BASE	(0x0)	/* Relative to BCM2835_ARMICU_BASE */
 
+#define	BCM2711_SCB_BASE	0xfc00
+#define	BCM2711_SCB_SIZE	0x0380
+#define	BCM2711_SCB_BASE_BUS	0x7c00
+
+#define	BCM2711_SCB_PHYS_TO_BUS(a) \
+((a) - BCM2711_SCB_BASE + BCM2711_SCB_BASE_BUS)
+#define	BCM2711_SCB_BUS_TO_PHYS(a) \
+((a) - BCM2711_SCB_BASE_BUS + BCM2711_SCB_BASE)
+
 /* Interrupt controller */
 #define	BCM2835_INTC_IRQBPENDING	(BCM2835_INTC_BASE + 0x00)	/* IRQ Basic pending */
 #define	BCM2835_INTC_IRQ1PENDING	(BCM2835_INTC_BASE + 0x04)	/* IRQ pending 1 */

Index: src/sys/arch/arm/broadcom/bcm283x_platform.c
diff -u src/sys/arch/arm/broadcom/bcm283x_platform.c:1.35 src/sys/arch/arm/broadcom/bcm283x_platform.c:1.36
--- src/sys/arch/arm/broadcom/bcm283x_platform.c:1.35	Thu Feb 20 01:43:07 2020
+++ src/sys/arch/arm/broadcom/bcm283x_platform.c	Sat Feb 22 00:17:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: bcm283x_platform.c,v 1.35 2020/02/20 01:43:07 jmcneill Exp $	*/
+/*	$NetBSD: bcm283x_platform.c,v 1.36 2020/02/22 00:17:54 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2017 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bcm283x_platform.c,v 1.35 2020/02/20 01:43:07 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm283x_platform.c,v 1.36 2020/02/22 00:17:54 jmcneill Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_bcm283x.h"
@@ -187,6 +187,10 @@ bcm2711_bus_to_phys(bus_addr_t ba)
 	ba < BCM283X_PERIPHERALS_BASE_BUS + BCM283X_PERIPHERALS_SIZE)
 		return BCM2711_PERIPHERALS_BUS_TO_PHYS(ba);
 
+	if (ba >= BCM2711_SCB_BASE_BUS &&
+	ba < BCM2711_SCB_BASE_BUS + BCM2711_SCB_SIZE)
+		return BCM2711_SCB_BUS_TO_PHYS(ba);
+
 	if (ba >= BCM2711_ARM_LOCAL_BASE_BUS &&
 	ba < BCM2711_ARM_LOCAL_BASE_BUS + BCM2711_ARM_LOCAL_SIZE)
 		return BCM2711_ARM_LOCAL_BUS_TO_PHYS(ba);



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

2020-02-21 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Fri Feb 21 23:27:06 UTC 2020

Modified Files:
src/sys/arch/arm/arm32: bus_dma.c

Log Message:
Make sure to convey a failure to the calling function

Likely fix for PR kern/54999, but that was a one-off panic.


To generate a diff of this commit:
cvs rdiff -u -r1.118 -r1.119 src/sys/arch/arm/arm32/bus_dma.c

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

Modified files:

Index: src/sys/arch/arm/arm32/bus_dma.c
diff -u src/sys/arch/arm/arm32/bus_dma.c:1.118 src/sys/arch/arm/arm32/bus_dma.c:1.119
--- src/sys/arch/arm/arm32/bus_dma.c:1.118	Tue Nov  5 10:21:31 2019
+++ src/sys/arch/arm/arm32/bus_dma.c	Fri Feb 21 23:27:06 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus_dma.c,v 1.118 2019/11/05 10:21:31 jmcneill Exp $	*/
+/*	$NetBSD: bus_dma.c,v 1.119 2020/02/21 23:27:06 maya Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #include "opt_cputypes.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.118 2019/11/05 10:21:31 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.119 2020/02/21 23:27:06 maya Exp $");
 
 #include 
 #include 
@@ -404,7 +404,7 @@ _bus_dmamap_create(bus_dma_tag_t t, bus_
 #ifdef DEBUG_DMA
 	printf("dmamap_create:map=%p\n", map);
 #endif	/* DEBUG_DMA */
-	return 0;
+	return error;
 }
 
 /*



CVS commit: src/tests/lib/libc/gen

2020-02-21 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Fri Feb 21 22:25:50 UTC 2020

Modified Files:
src/tests/lib/libc/gen: t_siginfo.c

Log Message:
Mark division by 0 as expected in sigfpe_int

Disable ubsan instrumentation on the operation.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/tests/lib/libc/gen/t_siginfo.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/lib/libc/gen/t_siginfo.c
diff -u src/tests/lib/libc/gen/t_siginfo.c:1.37 src/tests/lib/libc/gen/t_siginfo.c:1.38
--- src/tests/lib/libc/gen/t_siginfo.c:1.37	Tue Feb 11 03:11:42 2020
+++ src/tests/lib/libc/gen/t_siginfo.c	Fri Feb 21 22:25:50 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: t_siginfo.c,v 1.37 2020/02/11 03:11:42 riastradh Exp $ */
+/* $NetBSD: t_siginfo.c,v 1.38 2020/02/21 22:25:50 kamil Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -361,6 +361,18 @@ ATF_TC_HEAD(sigfpe_int, tc)
 	"for integer div-by-zero (PR port-i386/43655)");
 }
 
+#if defined(__clang__)
+__attribute__((no_sanitize("undefined")))
+#else   
+__attribute__((no_sanitize_undefined))
+#endif
+static long int
+sigfpe_int_division(long int a, long int b)
+{
+
+	return a / b;
+}
+
 ATF_TC_BODY(sigfpe_int, tc)
 {
 	struct sigaction sa;
@@ -379,7 +391,7 @@ ATF_TC_BODY(sigfpe_int, tc)
 #elif defined(_FLOAT_IEEE754)
 		fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP);
 #endif
-		printf("%ld\n", 1 / l);
+		printf("%ld\n", sigfpe_int_division(1, l));
 	}
 	if (intdiv_signalled == 0)
 		atf_tc_fail("FPE signal handler was not invoked");



CVS commit: src/tests/lib/libc/stdio

2020-02-21 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Fri Feb 21 22:15:00 UTC 2020

Modified Files:
src/tests/lib/libc/stdio: t_fopen.c

Log Message:
Avoid undefined behavior in is_module_present()

t_fopen.c:339:18, member access within misaligned address 0x7f7ff7ebd004
for type 'modstat_t' (aka 'struct modstat') which requires 8 byte alignment


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libc/stdio/t_fopen.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/lib/libc/stdio/t_fopen.c
diff -u src/tests/lib/libc/stdio/t_fopen.c:1.7 src/tests/lib/libc/stdio/t_fopen.c:1.8
--- src/tests/lib/libc/stdio/t_fopen.c:1.7	Tue Jul 16 17:29:18 2019
+++ src/tests/lib/libc/stdio/t_fopen.c	Fri Feb 21 22:14:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_fopen.c,v 1.7 2019/07/16 17:29:18 martin Exp $ */
+/*	$NetBSD: t_fopen.c,v 1.8 2020/02/21 22:14:59 kamil Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_fopen.c,v 1.7 2019/07/16 17:29:18 martin Exp $");
+__RCSID("$NetBSD: t_fopen.c,v 1.8 2020/02/21 22:14:59 kamil Exp $");
 
 #include 
 #include 
@@ -314,6 +314,7 @@ is_module_present(const char *name)
 	int count;
 	struct iovec iov;
 	modstat_t *ms;
+	modstat_t m;
 
 	for (len = 8192; ;) {
 		iov.iov_base = malloc(len);
@@ -336,7 +337,8 @@ is_module_present(const char *name)
 	count = *(int *)iov.iov_base;
 	ms = (modstat_t *)((char *)iov.iov_base + sizeof(int));
 	while (count > 0) {
-		if (strcmp(ms->ms_name, name) == 0) {
+		memcpy(, ms, sizeof(m));
+		if (strcmp(m.ms_name, name) == 0) {
 			found = true;
 			break;
 		}



CVS commit: src/lib/libc/db/hash

2020-02-21 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Fri Feb 21 22:04:06 UTC 2020

Modified Files:
src/lib/libc/db/hash: hash.h

Log Message:
Avoid undefined behavior in *BIT macros

hash_page.c:792:2, left shift of 1 by 31 places cannot be represented in type 
'int'
hash_page.c:855:2, left shift of 1 by 31 places cannot be represented in type 
'int'
hash_page.c:779:3, left shift of 1 by 31 places cannot be represented in type 
'int'


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libc/db/hash/hash.h

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

Modified files:

Index: src/lib/libc/db/hash/hash.h
diff -u src/lib/libc/db/hash/hash.h:1.16 src/lib/libc/db/hash/hash.h:1.17
--- src/lib/libc/db/hash/hash.h:1.16	Wed Nov 18 18:22:42 2015
+++ src/lib/libc/db/hash/hash.h	Fri Feb 21 22:04:06 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: hash.h,v 1.16 2015/11/18 18:22:42 christos Exp $	*/
+/*	$NetBSD: hash.h,v 1.17 2020/02/21 22:04:06 kamil Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993, 1994
@@ -156,9 +156,9 @@ typedef struct htab	 {		/* Memory reside
 #define BITS_PER_MAP	32
 
 /* Given the address of the beginning of a big map, clear/set the nth bit */
-#define CLRBIT(A, N)	((A)[(N)/BITS_PER_MAP] &= ~(1<<((N)%BITS_PER_MAP)))
-#define SETBIT(A, N)	((A)[(N)/BITS_PER_MAP] |= (1<<((N)%BITS_PER_MAP)))
-#define ISSET(A, N)	((A)[(N)/BITS_PER_MAP] & (1<<((N)%BITS_PER_MAP)))
+#define CLRBIT(A, N)	((A)[(N)/BITS_PER_MAP] &= ~(1U<<((N)%BITS_PER_MAP)))
+#define SETBIT(A, N)	((A)[(N)/BITS_PER_MAP] |= (1U<<((N)%BITS_PER_MAP)))
+#define ISSET(A, N)	((A)[(N)/BITS_PER_MAP] & (1U<<((N)%BITS_PER_MAP)))
 
 /* Overflow management */
 /*



CVS commit: src/sys/arch/x86/x86

2020-02-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Feb 21 18:34:37 UTC 2020

Modified Files:
src/sys/arch/x86/x86: pmap.c

Log Message:
In pmap_changeprot_local(), drop the dirty bit along with the write bit.


To generate a diff of this commit:
cvs rdiff -u -r1.356 -r1.357 src/sys/arch/x86/x86/pmap.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/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.356 src/sys/arch/x86/x86/pmap.c:1.357
--- src/sys/arch/x86/x86/pmap.c:1.356	Fri Feb 21 18:31:55 2020
+++ src/sys/arch/x86/x86/pmap.c	Fri Feb 21 18:34:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.356 2020/02/21 18:31:55 maxv Exp $	*/
+/*	$NetBSD: pmap.c,v 1.357 2020/02/21 18:34:37 maxv Exp $	*/
 
 /*
  * Copyright (c) 2008, 2010, 2016, 2017, 2019, 2020 The NetBSD Foundation, Inc.
@@ -130,7 +130,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.356 2020/02/21 18:31:55 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.357 2020/02/21 18:34:37 maxv Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -868,7 +868,7 @@ pmap_changeprot_local(vaddr_t va, vm_pro
 	if ((prot & VM_PROT_WRITE) != 0)
 		npte |= PTE_W;
 	else
-		npte &= ~PTE_W;
+		npte &= ~(PTE_W|PTE_D);
 
 	if (opte != npte) {
 		pmap_pte_set(pte, npte);



CVS commit: src/sys/arch/x86/x86

2020-02-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Feb 21 18:31:56 UTC 2020

Modified Files:
src/sys/arch/x86/x86: pmap.c

Log Message:
Add comments.


To generate a diff of this commit:
cvs rdiff -u -r1.355 -r1.356 src/sys/arch/x86/x86/pmap.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/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.355 src/sys/arch/x86/x86/pmap.c:1.356
--- src/sys/arch/x86/x86/pmap.c:1.355	Sun Jan 12 13:01:11 2020
+++ src/sys/arch/x86/x86/pmap.c	Fri Feb 21 18:31:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.355 2020/01/12 13:01:11 ad Exp $	*/
+/*	$NetBSD: pmap.c,v 1.356 2020/02/21 18:31:55 maxv Exp $	*/
 
 /*
  * Copyright (c) 2008, 2010, 2016, 2017, 2019, 2020 The NetBSD Foundation, Inc.
@@ -130,7 +130,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.355 2020/01/12 13:01:11 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.356 2020/02/21 18:31:55 maxv Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -1258,6 +1258,17 @@ slotspace_rand(int type, size_t sz, size
 	vaddr_t startva, va;
 
 	sz = roundup(sz, align);
+
+	/*
+	 * Take one more slot with +NBPD_L4, because we may end up choosing
+	 * an area that crosses slots:
+	 * +--+--+--+
+	 * | Slot | Slot | Slot |
+	 * +--+--+--+
+	 *[Chosen Area]
+	 * And in that case we must take into account the additional slot
+	 * consumed.
+	 */
 	nslots = roundup(sz+NBPD_L4, NBPD_L4) / NBPD_L4;
 
 	/* Get the holes. */
@@ -1279,16 +1290,20 @@ slotspace_rand(int type, size_t sz, size
 minnslot = slotspace.area[i].nslot;
 			}
 		}
+
+		/* No hole anymore, stop here. */
 		if (minsslot == 512) {
 			break;
 		}
 
+		/* Register the hole. */
 		if (minsslot - curslot >= nslots) {
 			holes[nholes].start = curslot;
 			holes[nholes].end = minsslot;
 			nholes++;
 		}
 
+		/* Skip that hole, and iterate again. */
 		curslot = minsslot + minnslot;
 	}
 



CVS commit: src/sys/arch/powerpc/ibm4xx

2020-02-21 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Fri Feb 21 15:15:48 UTC 2020

Modified Files:
src/sys/arch/powerpc/ibm4xx: trap.c

Log Message:
Do not try to recovery from data page fault in interrupt context;
catch up belatedly with powerpc/trap.c rev 1.49 and etc.:


http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/arch/powerpc/powerpc/trap.c#rev1.49


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/arch/powerpc/ibm4xx/trap.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/powerpc/ibm4xx/trap.c
diff -u src/sys/arch/powerpc/ibm4xx/trap.c:1.77 src/sys/arch/powerpc/ibm4xx/trap.c:1.78
--- src/sys/arch/powerpc/ibm4xx/trap.c:1.77	Fri Feb 21 14:49:57 2020
+++ src/sys/arch/powerpc/ibm4xx/trap.c	Fri Feb 21 15:15:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.77 2020/02/21 14:49:57 rin Exp $	*/
+/*	$NetBSD: trap.c,v 1.78 2020/02/21 15:15:48 rin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.77 2020/02/21 14:49:57 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.78 2020/02/21 15:15:48 rin Exp $");
 
 #include "opt_altivec.h"
 #include "opt_ddb.h"
@@ -182,7 +182,15 @@ trap(struct trapframe *tf)
 		{
 			struct vm_map *map;
 			vaddr_t va;
-			struct faultbuf *fb = NULL;
+			struct faultbuf *fb;
+
+			pcb = lwp_getpcb(l);
+			fb = pcb->pcb_onfault;
+
+			if (curcpu()->ci_idepth >= 0) {
+rv = EFAULT;
+goto out;
+			}
 
 			va = tf->tf_dear;
 			if (tf->tf_pid == KERNEL_PID) {
@@ -200,13 +208,12 @@ trap(struct trapframe *tf)
 			(ftype & VM_PROT_WRITE) ? "write" : "read",
 			(void *)va, tf->tf_esr));
 
-			pcb = lwp_getpcb(l);
-			fb = pcb->pcb_onfault;
 			pcb->pcb_onfault = NULL;
 			rv = uvm_fault(map, trunc_page(va), ftype);
 			pcb->pcb_onfault = fb;
 			if (rv == 0)
 return;
+out:
 			if (fb != NULL) {
 tf->tf_pid = KERNEL_PID;
 tf->tf_srr0 = fb->fb_pc;



CVS commit: src/tools/llvm

2020-02-21 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri Feb 21 15:00:44 UTC 2020

Modified Files:
src/tools/llvm: Makefile

Log Message:
LLVM doesn't use term.h, so don't check for it when probing here either.
Increase robustness of checks for incremental builds by forcing a
dependency on the Makefile itself.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/tools/llvm/Makefile

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

Modified files:

Index: src/tools/llvm/Makefile
diff -u src/tools/llvm/Makefile:1.22 src/tools/llvm/Makefile:1.23
--- src/tools/llvm/Makefile:1.22	Tue May  1 19:59:47 2018
+++ src/tools/llvm/Makefile	Fri Feb 21 15:00:44 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.22 2018/05/01 19:59:47 christos Exp $
+#	$NetBSD: Makefile,v 1.23 2020/02/21 15:00:44 joerg Exp $
 
 .include 
 
@@ -20,7 +20,7 @@ config/config.status: ${LLVM_SRCDIR}/con
 	--with-python=${.OBJDIR}/config/python
 # --disable-assertions
 
-need-dl:
+need-dl: Makefile
 	printf '#include \nint main(void){void *p; return dladdr(p, p);}' > need-dl.c
 	if ${HOST_CC} -o need-dl.out -D_GNU_SOURCE need-dl.c > /dev/null 2>&1; then \
 		echo > ${.TARGET}; \
@@ -30,8 +30,8 @@ need-dl:
 		echo > ${.TARGET}; \
 	fi
 
-need-terminfo:
-	printf '#include \nint main(void){return setupterm(0, 0, 0);}' > need-terminfo.c
+need-terminfo: Makefile
+	printf 'int setupterm(char *, int, int *);\nint main(void){return setupterm("", 0, 0);}' > need-terminfo.c
 	for lib in tinfo terminfo ncurses curses; do \
 		if ${HOST_CC} -o need-terminfo.out need-terminfo.c -l$$lib > /dev/null 2>&1; then \
 			echo -l$$lib > ${.TARGET}; \



CVS commit: src/sys/arch/powerpc/ibm4xx

2020-02-21 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Fri Feb 21 14:49:58 UTC 2020

Modified Files:
src/sys/arch/powerpc/ibm4xx: trap.c

Log Message:
Tiny improvements to copyin() and copyout():

- Use lwz/stw instead of 4-byte lswi/stswi for 405 and later, which
  support unaligned word load/store by hardware. In many cases, both
  source and destination are aligned on word boundaries.

- Use dcbst instead of dcbf to flush cache. The former does not
  invalidate the cache line. Copied data should be used soon after.


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sys/arch/powerpc/ibm4xx/trap.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/powerpc/ibm4xx/trap.c
diff -u src/sys/arch/powerpc/ibm4xx/trap.c:1.76 src/sys/arch/powerpc/ibm4xx/trap.c:1.77
--- src/sys/arch/powerpc/ibm4xx/trap.c:1.76	Fri Feb 21 14:27:20 2020
+++ src/sys/arch/powerpc/ibm4xx/trap.c	Fri Feb 21 14:49:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.76 2020/02/21 14:27:20 rin Exp $	*/
+/*	$NetBSD: trap.c,v 1.77 2020/02/21 14:49:57 rin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.76 2020/02/21 14:27:20 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.77 2020/02/21 14:49:57 rin Exp $");
 
 #include "opt_altivec.h"
 #include "opt_ddb.h"
@@ -428,12 +428,20 @@ copyin(const void *udaddr, void *kaddr, 
 		"   beq- 2f;"			/* No words. Go do bytes */
 		"   mtctr %[count];"
 		"1: mtpid %[ctx]; sync;"
+#ifdef PPC_IBM403
 		"   lswi %[tmp],%[udaddr],4;"	/* Load user word */
+#else
+		"   lwz %[tmp],0(%[udaddr]);"
+#endif
 		"   addi %[udaddr],%[udaddr],0x4;" /* next udaddr word */
 		"   sync; isync;"
 		"   mtpid %[pid]; sync;"
+#ifdef PPC_IBM403
 		"   stswi %[tmp],%[kaddr],4;"	/* Store kernel word */
-		"   dcbf 0,%[kaddr];"		/* flush cache */
+#else
+		"   stw %[tmp],0(%[kaddr]);"
+#endif
+		"   dcbst 0,%[kaddr];"		/* flush cache */
 		"   addi %[kaddr],%[kaddr],0x4;" /* next udaddr word */
 		"   sync; isync;"
 		"   bdnz 1b;"			/* repeat */
@@ -448,7 +456,7 @@ copyin(const void *udaddr, void *kaddr, 
 		"   sync; isync;"
 		"   mtpid %[pid]; sync;"
 		"   stb %[tmp],0(%[kaddr]);"	/* Store kernel byte */
-		"   dcbf 0,%[kaddr];"		/* flush cache */
+		"   dcbst 0,%[kaddr];"		/* flush cache */
 		"   addi %[kaddr],%[kaddr],0x1;"
 		"   sync; isync;"
 		"   b 3b;"
@@ -527,12 +535,20 @@ copyout(const void *kaddr, void *udaddr,
 		"   beq- 2f;"			/* No words. Go do bytes */
 		"   mtctr %[count];"
 		"1: mtpid %[pid]; sync;"
+#ifdef PPC_IBM403
 		"   lswi %[tmp],%[kaddr],4;"	/* Load kernel word */
+#else
+		"   lwz %[tmp],0(%[kaddr]);"
+#endif
 		"   addi %[kaddr],%[kaddr],0x4;" /* next kaddr word */
 		"   sync; isync;"
 		"   mtpid %[ctx]; sync;"
+#ifdef PPC_IBM403
 		"   stswi %[tmp],%[udaddr],4;"	/* Store user word */
-		"   dcbf 0,%[udaddr];"		/* flush cache */
+#else
+		"   stw %[tmp],0(%[udaddr]);"
+#endif
+		"   dcbst 0,%[udaddr];"		/* flush cache */
 		"   addi %[udaddr],%[udaddr],0x4;" /* next udaddr word */
 		"   sync; isync;"
 		"   bdnz 1b;"			/* repeat */
@@ -547,7 +563,7 @@ copyout(const void *kaddr, void *udaddr,
 		"   sync; isync;"
 		"   mtpid %[ctx]; sync;"
 		"   stb %[tmp],0(%[udaddr]);"	/* Store user byte */
-		"   dcbf 0,%[udaddr];"		/* flush cache */
+		"   dcbst 0,%[udaddr];"		/* flush cache */
 		"   addi %[udaddr],%[udaddr],0x1;"
 		"   sync; isync;"
 		"   b 3b;"



CVS commit: src/sys/arch/powerpc/ibm4xx

2020-02-21 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Fri Feb 21 14:27:20 UTC 2020

Modified Files:
src/sys/arch/powerpc/ibm4xx: trap.c

Log Message:
Cosmetic changes for assembler codes. No binary changes.


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/sys/arch/powerpc/ibm4xx/trap.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/powerpc/ibm4xx/trap.c
diff -u src/sys/arch/powerpc/ibm4xx/trap.c:1.75 src/sys/arch/powerpc/ibm4xx/trap.c:1.76
--- src/sys/arch/powerpc/ibm4xx/trap.c:1.75	Fri Feb 21 13:32:31 2020
+++ src/sys/arch/powerpc/ibm4xx/trap.c	Fri Feb 21 14:27:20 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.75 2020/02/21 13:32:31 rin Exp $	*/
+/*	$NetBSD: trap.c,v 1.76 2020/02/21 14:27:20 rin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.75 2020/02/21 13:32:31 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.76 2020/02/21 14:27:20 rin Exp $");
 
 #include "opt_altivec.h"
 #include "opt_ddb.h"
@@ -418,43 +418,45 @@ copyin(const void *udaddr, void *kaddr, 
 	}
 
 	__asm volatile(
-		"   mfmsr %[msr];"  /* Save MSR */
-		"   li %[pid],0x20; "
-		"   andc %[pid],%[msr],%[pid]; mtmsr %[pid];"   /* Disable IMMU */
-		"   mfpid %[pid];"  /* Save old PID */
+		"   mfmsr %[msr];"		/* Save MSR */
+		"   li %[pid],0x20;"
+		"   andc %[pid],%[msr],%[pid]; mtmsr %[pid];" /* Disable IMMU */
+		"   mfpid %[pid];"		/* Save old PID */
 		"   sync; isync;"
 
-		"   srwi. %[count],%[len],0x2;" /* How many words? */
-		"   beq-  2f;"  /* No words. Go do bytes */
+		"   srwi. %[count],%[len],0x2;"	/* How many words? */
+		"   beq- 2f;"			/* No words. Go do bytes */
 		"   mtctr %[count];"
 		"1: mtpid %[ctx]; sync;"
-		"   lswi %[tmp],%[udaddr],4;"   /* Load user word */
-		"   addi %[udaddr],%[udaddr],0x4;"  /* next udaddr word */
+		"   lswi %[tmp],%[udaddr],4;"	/* Load user word */
+		"   addi %[udaddr],%[udaddr],0x4;" /* next udaddr word */
 		"   sync; isync;"
-		"   mtpid %[pid];sync;"
-		"   stswi %[tmp],%[kaddr],4;"/* Store kernel word */
-		"   dcbf 0,%[kaddr];"   /* flush cache */
-		"   addi %[kaddr],%[kaddr],0x4;"/* next udaddr word */
+		"   mtpid %[pid]; sync;"
+		"   stswi %[tmp],%[kaddr],4;"	/* Store kernel word */
+		"   dcbf 0,%[kaddr];"		/* flush cache */
+		"   addi %[kaddr],%[kaddr],0x4;" /* next udaddr word */
 		"   sync; isync;"
-		"   bdnz 1b;"   /* repeat */
+		"   bdnz 1b;"			/* repeat */
 
-		"2: andi. %[count],%[len],0x3;" /* How many remaining bytes? */
+		"2: andi. %[count],%[len],0x3;"	/* How many remaining bytes? */
 		"   addi %[count],%[count],0x1;"
 		"   mtctr %[count];"
-		"3: bdz 10f;"   /* while count */
-		"   mtpid %[ctx];sync;"
-		"   lbz %[tmp],0(%[udaddr]);"   /* Load user byte */
-		"   addi %[udaddr],%[udaddr],0x1;"  /* next udaddr byte */
+		"3: bdz 10f;"			/* while count */
+		"   mtpid %[ctx]; sync;"
+		"   lbz %[tmp],0(%[udaddr]);"	/* Load user byte */
+		"   addi %[udaddr],%[udaddr],0x1;" /* next udaddr byte */
 		"   sync; isync;"
 		"   mtpid %[pid]; sync;"
-		"   stb %[tmp],0(%[kaddr]);"/* Store kernel byte */
-		"   dcbf 0,%[kaddr];"   /* flush cache */
+		"   stb %[tmp],0(%[kaddr]);"	/* Store kernel byte */
+		"   dcbf 0,%[kaddr];"		/* flush cache */
 		"   addi %[kaddr],%[kaddr],0x1;"
 		"   sync; isync;"
 		"   b 3b;"
-		"10:mtpid %[pid]; mtmsr %[msr]; sync; isync;" /* Restore PID and MSR */
+		"10:mtpid %[pid]; mtmsr %[msr]; sync; isync;"
+		/* Restore PID and MSR */
 		: [msr] "=" (msr), [pid] "=" (pid), [tmp] "=" (tmp)
-		: [udaddr] "b" (udaddr), [ctx] "b" (ctx), [kaddr] "b" (kaddr), [len] "b" (len), [count] "b" (count));
+		: [udaddr] "b" (udaddr), [ctx] "b" (ctx), [kaddr] "b" (kaddr),
+		  [len] "b" (len), [count] "b" (count));
 
 	curpcb->pcb_onfault = NULL;
 	return 0;
@@ -515,43 +517,45 @@ copyout(const void *kaddr, void *udaddr,
 	}
 
 	__asm volatile(
-		"   mfmsr %[msr];"  /* Save MSR */ \
-		"   li %[pid],0x20; " \
-		"   andc %[pid],%[msr],%[pid]; mtmsr %[pid];"   /* Disable IMMU */ \
-		"   mfpid %[pid];"  /* Save old PID */ \
+		"   mfmsr %[msr];"		/* Save MSR */
+		"   li %[pid],0x20;"
+		"   andc %[pid],%[msr],%[pid]; mtmsr %[pid];" /* Disable IMMU */
+		"   mfpid %[pid];"		/* Save old PID */
 		"   sync; isync;"
 
-		"   srwi. %[count],%[len],0x2;" /* How many words? */
-		"   beq-  2f;"  /* No words. Go do bytes */
+		"   srwi. %[count],%[len],0x2;"	/* How many words? */
+		"   beq- 2f;"			/* No words. Go do bytes */
 		"   mtctr %[count];"
-		"1: mtpid %[pid];sync;"
-		"   lswi %[tmp],%[kaddr],4;"/* Load kernel word */
-		"   addi %[kaddr],%[kaddr],0x4;"/* next kaddr word */
+		"1: mtpid %[pid]; sync;"
+		"   lswi %[tmp],%[kaddr],4;"	/* Load kernel word */
+		"   addi 

CVS commit: src/sys/arch/powerpc/powerpc

2020-02-21 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Fri Feb 21 13:38:05 UTC 2020

Modified Files:
src/sys/arch/powerpc/powerpc: vm_machdep.c

Log Message:
When UPAGES > 1, both __HAVE_CPU_UAREA_ROUTINES and PMAP_MAP_POOLPAGE
must be defined in order to allocate physically contiguous memory for
u-area.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/sys/arch/powerpc/powerpc/vm_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/powerpc/powerpc/vm_machdep.c
diff -u src/sys/arch/powerpc/powerpc/vm_machdep.c:1.100 src/sys/arch/powerpc/powerpc/vm_machdep.c:1.101
--- src/sys/arch/powerpc/powerpc/vm_machdep.c:1.100	Mon Jul  6 05:25:29 2015
+++ src/sys/arch/powerpc/powerpc/vm_machdep.c	Fri Feb 21 13:38:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm_machdep.c,v 1.100 2015/07/06 05:25:29 matt Exp $	*/
+/*	$NetBSD: vm_machdep.c,v 1.101 2020/02/21 13:38:05 rin Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.100 2015/07/06 05:25:29 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.101 2020/02/21 13:38:05 rin Exp $");
 
 #include "opt_altivec.h"
 #include "opt_multiprocessor.h"
@@ -310,6 +310,11 @@ vunmapbuf(struct buf *bp, vsize_t len)
 	bp->b_saveaddr = 0;
 }
 
+#if UPAGES > 1 && \
+(!defined(__HAVE_CPU_UAREA_ROUTINES) || !defined(PMAP_MAP_POOLPAGE))
+#error "We need physically contiguous pages for u-area."
+#endif
+
 #ifdef __HAVE_CPU_UAREA_ROUTINES
 void *
 cpu_uarea_alloc(bool system)



CVS commit: src/sys/arch/alpha/alpha

2020-02-21 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Feb 21 13:33:07 UTC 2020

Modified Files:
src/sys/arch/alpha/alpha: prom.c

Log Message:
Use designated initialisers


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/alpha/alpha/prom.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/alpha/alpha/prom.c
diff -u src/sys/arch/alpha/alpha/prom.c:1.50 src/sys/arch/alpha/alpha/prom.c:1.51
--- src/sys/arch/alpha/alpha/prom.c:1.50	Mon Sep  3 16:29:22 2018
+++ src/sys/arch/alpha/alpha/prom.c	Fri Feb 21 13:33:07 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: prom.c,v 1.50 2018/09/03 16:29:22 riastradh Exp $ */
+/* $NetBSD: prom.c,v 1.51 2020/02/21 13:33:07 skrll Exp $ */
 
 /*
  * Copyright (c) 1992, 1994, 1995, 1996 Carnegie Mellon University
@@ -27,7 +27,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: prom.c,v 1.50 2018/09/03 16:29:22 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: prom.c,v 1.51 2020/02/21 13:33:07 skrll Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -46,8 +46,13 @@ __KERNEL_RCSID(0, "$NetBSD: prom.c,v 1.5
 #include 
 
 /* XXX this is to fake out the console routines, while booting. */
-struct consdev promcons = { NULL, NULL, promcngetc, promcnputc,
-			nullcnpollc, NULL, NULL, NULL, makedev(23,0), 1 };
+struct consdev promcons = {
+	.cn_getc = promcngetc,
+	.cn_putc = promcnputc,
+	.cn_pollc = nullcnpollc,
+	.cn_dev = makedev(23,0),
+	.cn_pri = 1
+};
 
 struct rpb	*hwrpb;
 int		alpha_console;



CVS commit: src/sys/arch/powerpc/ibm4xx

2020-02-21 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Fri Feb 21 13:32:31 UTC 2020

Modified Files:
src/sys/arch/powerpc/ibm4xx: trap.c

Log Message:
Comment out badaddr() and badaddr_read() on ibm4xx for now.

They are not used nor exposed externally in any header file; these
functions may have never been tested so far.

Enable them again when necessary.

Note that badaddr() for oea is used by macppc port, where it is
declared as an external function.


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/sys/arch/powerpc/ibm4xx/trap.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/powerpc/ibm4xx/trap.c
diff -u src/sys/arch/powerpc/ibm4xx/trap.c:1.74 src/sys/arch/powerpc/ibm4xx/trap.c:1.75
--- src/sys/arch/powerpc/ibm4xx/trap.c:1.74	Thu Feb 20 06:36:04 2020
+++ src/sys/arch/powerpc/ibm4xx/trap.c	Fri Feb 21 13:32:31 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.74 2020/02/20 06:36:04 rin Exp $	*/
+/*	$NetBSD: trap.c,v 1.75 2020/02/21 13:32:31 rin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.74 2020/02/20 06:36:04 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.75 2020/02/21 13:32:31 rin Exp $");
 
 #include "opt_altivec.h"
 #include "opt_ddb.h"
@@ -116,9 +116,11 @@ __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.7
 static int fix_unaligned(struct lwp *l, struct trapframe *tf);
 
 void trap(struct trapframe *);	/* Called from locore / trap_subr */
-/* Why are these not defined in a header? */
+#if 0
+/* Not currently used nor exposed externally in any header file */
 int badaddr(void *, size_t);
 int badaddr_read(void *, size_t, int *);
+#endif
 int ctx_setup(int, int);
 
 #ifdef DEBUG
@@ -616,6 +618,7 @@ kcopy(const void *src, void *dst, size_t
 	return 0;
 }
 
+#if 0
 int
 badaddr(void *addr, size_t size)
 {
@@ -666,6 +669,7 @@ badaddr_read(void *addr, size_t size, in
 
 	return 0;
 }
+#endif
 
 /*
  * For now, this only deals with the particular unaligned access case



CVS commit: src/sys/arch/powerpc/ibm4xx

2020-02-21 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Fri Feb 21 13:16:16 UTC 2020

Modified Files:
src/sys/arch/powerpc/ibm4xx: pmap.c

Log Message:
In ppc4xx_tlb_find_victim(), mark kernel stack page TLBF_REF instead of
TLBF_USED. This should be originally intended behavior of this code
segment, because

- TLBF_USED is already checked just before, so marking this page
  TLBF_USED is no-op.
- TLBF_REF flag exempts that page from being flushed from TLB in next
  scan, when kernel stack may be still there with high probability.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/sys/arch/powerpc/ibm4xx/pmap.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/powerpc/ibm4xx/pmap.c
diff -u src/sys/arch/powerpc/ibm4xx/pmap.c:1.79 src/sys/arch/powerpc/ibm4xx/pmap.c:1.80
--- src/sys/arch/powerpc/ibm4xx/pmap.c:1.79	Thu Feb 20 05:34:37 2020
+++ src/sys/arch/powerpc/ibm4xx/pmap.c	Fri Feb 21 13:16:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.79 2020/02/20 05:34:37 rin Exp $	*/
+/*	$NetBSD: pmap.c,v 1.80 2020/02/21 13:16:16 rin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.79 2020/02/20 05:34:37 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.80 2020/02/21 13:16:16 rin Exp $");
 
 #include 
 #include 
@@ -1276,7 +1276,7 @@ ppc4xx_tlb_find_victim(void)
 			(tlb_info[tlbnext].ti_ctx == KERNEL_PID) &&
 			 (flags & TLBF_USED)) {
 /* Kernel stack page */
-flags |= TLBF_USED;
+flags |= TLBF_REF;
 tlb_info[tlbnext].ti_flags = flags;
 			} else {
 /* Found it! */



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

2020-02-21 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Feb 21 13:15:54 UTC 2020

Modified Files:
src/sys/arch/arm/fdt: cpu_fdt.c

Log Message:
Improve a comment


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/arm/fdt/cpu_fdt.c

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

Modified files:

Index: src/sys/arch/arm/fdt/cpu_fdt.c
diff -u src/sys/arch/arm/fdt/cpu_fdt.c:1.34 src/sys/arch/arm/fdt/cpu_fdt.c:1.35
--- src/sys/arch/arm/fdt/cpu_fdt.c:1.34	Sat Feb 15 08:16:11 2020
+++ src/sys/arch/arm/fdt/cpu_fdt.c	Fri Feb 21 13:15:54 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_fdt.c,v 1.34 2020/02/15 08:16:11 skrll Exp $ */
+/* $NetBSD: cpu_fdt.c,v 1.35 2020/02/21 13:15:54 skrll Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -30,7 +30,7 @@
 #include "psci_fdt.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu_fdt.c,v 1.34 2020/02/15 08:16:11 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_fdt.c,v 1.35 2020/02/21 13:15:54 skrll Exp $");
 
 #include 
 #include 
@@ -327,7 +327,7 @@ spintable_cpu_on(u_int cpuindex, paddr_t
 {
 	/*
 	 * we need devmap for cpu-release-addr in advance.
-	 * __HAVE_MM_MD_DIRECT_MAPPED_PHYS nor pmap didn't work at this point.
+	 * __HAVE_MM_MD_DIRECT_MAPPED_PHYS nor pmap work at this point.
 	 */
 	if (pmap_devmap_find_pa(cpu_release_addr, sizeof(paddr_t)) == NULL) {
 		aprint_error("%s: devmap for cpu-release-addr"



CVS commit: src/sys/arch/powerpc/include

2020-02-21 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Fri Feb 21 12:56:37 UTC 2020

Modified Files:
src/sys/arch/powerpc/include: param.h

Log Message:
Reduce UPAGES from 2 to 1 for ibm4xx, which was originally 1 and bumped
to 2 in rev 1.29:


http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/arch/powerpc/include/param.h#rev1.29

Since page size is 16KB on ibm4xx, USPACE is still 16KB, which is the
same size as on other powerpc processors.

This avoids kernel crash described in PR kern/54994. Also, even if the
PR is resolved, fork(2) easily fails with ENOMEM if UPAGES is 2, which
requires physically contiguous pages for u-area. No bad side effect is
observed as far as I can see.

XXX
Even with this commit, kern/54994 still critically affects other archs
with __HAVE_CPU_UAREA_ROUTINES, i.e., alpha, mips, powerpc/{oea,booke},
and riscv.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/powerpc/include/param.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/powerpc/include/param.h
diff -u src/sys/arch/powerpc/include/param.h:1.31 src/sys/arch/powerpc/include/param.h:1.32
--- src/sys/arch/powerpc/include/param.h:1.31	Mon Jan  7 22:00:32 2019
+++ src/sys/arch/powerpc/include/param.h	Fri Feb 21 12:56:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.31 2019/01/07 22:00:32 jdolecek Exp $	*/
+/*	$NetBSD: param.h,v 1.32 2020/02/21 12:56:37 rin Exp $	*/
 
 /*-
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -67,7 +67,7 @@
 
 #ifdef PPC_IBM4XX
 #define	PGSHIFT		14	/* Use 16KB to reduce TLB thrashing */
-#define	UPAGES		2
+#define	UPAGES		1
 #else
 #define	PGSHIFT		12
 #define	UPAGES		4



CVS commit: src/sys

2020-02-21 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Feb 21 12:41:29 UTC 2020

Modified Files:
src/sys/arch/mips/adm5120/dev: ahci.c
src/sys/dev/usb: ehci.c ohci.c uhci.c
src/sys/external/bsd/dwc2: dwc2.c

Log Message:
Fix a memory leak.  Spotted by nat@


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/mips/adm5120/dev/ahci.c
cvs rdiff -u -r1.273 -r1.274 src/sys/dev/usb/ehci.c
cvs rdiff -u -r1.295 -r1.296 src/sys/dev/usb/ohci.c
cvs rdiff -u -r1.293 -r1.294 src/sys/dev/usb/uhci.c
cvs rdiff -u -r1.71 -r1.72 src/sys/external/bsd/dwc2/dwc2.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/mips/adm5120/dev/ahci.c
diff -u src/sys/arch/mips/adm5120/dev/ahci.c:1.20 src/sys/arch/mips/adm5120/dev/ahci.c:1.21
--- src/sys/arch/mips/adm5120/dev/ahci.c:1.20	Sat Feb 15 01:21:56 2020
+++ src/sys/arch/mips/adm5120/dev/ahci.c	Fri Feb 21 12:41:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahci.c,v 1.20 2020/02/15 01:21:56 riastradh Exp $	*/
+/*	$NetBSD: ahci.c,v 1.21 2020/02/21 12:41:29 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2007 Ruslan Ermilov and Vsevolod Lobko.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahci.c,v 1.20 2020/02/15 01:21:56 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahci.c,v 1.21 2020/02/21 12:41:29 skrll Exp $");
 
 #include 
 #include 
@@ -989,6 +989,9 @@ ahci_device_ctrl_start(struct usbd_xfer 
 
 	usb_transfer_complete(xfer);
 	mutex_exit(>sc_lock);
+
+	usb_freemem(>sc_bus, );
+
 	return USBD_NORMAL_COMPLETION;
 }
 

Index: src/sys/dev/usb/ehci.c
diff -u src/sys/dev/usb/ehci.c:1.273 src/sys/dev/usb/ehci.c:1.274
--- src/sys/dev/usb/ehci.c:1.273	Sat Feb 15 01:21:56 2020
+++ src/sys/dev/usb/ehci.c	Fri Feb 21 12:41:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ehci.c,v 1.273 2020/02/15 01:21:56 riastradh Exp $ */
+/*	$NetBSD: ehci.c,v 1.274 2020/02/21 12:41:29 skrll Exp $ */
 
 /*
  * Copyright (c) 2004-2012 The NetBSD Foundation, Inc.
@@ -53,7 +53,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.273 2020/02/15 01:21:56 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.274 2020/02/21 12:41:29 skrll Exp $");
 
 #include "ohci.h"
 #include "uhci.h"
@@ -3748,7 +3748,7 @@ Static void
 ehci_device_ctrl_close(struct usbd_pipe *pipe)
 {
 	ehci_softc_t *sc = EHCI_PIPE2SC(pipe);
-	/*struct ehci_pipe *epipe = EHCI_PIPE2EPIPE(pipe);*/
+	struct ehci_pipe * const epipe = EHCI_PIPE2EPIPE(pipe);
 
 	EHCIHIST_FUNC(); EHCIHIST_CALLED();
 
@@ -3757,6 +3757,8 @@ ehci_device_ctrl_close(struct usbd_pipe 
 	DPRINTF("pipe=%#jx", (uintptr_t)pipe, 0, 0, 0);
 
 	ehci_close_pipe(pipe, sc->sc_async_head);
+
+	usb_freemem(>sc_bus, >ctrl.reqdma);
 }
 
 /*

Index: src/sys/dev/usb/ohci.c
diff -u src/sys/dev/usb/ohci.c:1.295 src/sys/dev/usb/ohci.c:1.296
--- src/sys/dev/usb/ohci.c:1.295	Sat Feb 15 01:21:56 2020
+++ src/sys/dev/usb/ohci.c	Fri Feb 21 12:41:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ohci.c,v 1.295 2020/02/15 01:21:56 riastradh Exp $	*/
+/*	$NetBSD: ohci.c,v 1.296 2020/02/21 12:41:29 skrll Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004, 2005, 2012 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.295 2020/02/15 01:21:56 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.296 2020/02/21 12:41:29 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -2841,6 +2841,8 @@ ohci_device_ctrl_close(struct usbd_pipe 
 	DPRINTF("pipe=%#jx", (uintptr_t)pipe, 0, 0, 0);
 	ohci_close_pipe(pipe, sc->sc_ctrl_head);
 	ohci_free_std_locked(sc, opipe->tail.td);
+
+	usb_freemem(>sc_bus, >ctrl.reqdma);
 }
 
 //

Index: src/sys/dev/usb/uhci.c
diff -u src/sys/dev/usb/uhci.c:1.293 src/sys/dev/usb/uhci.c:1.294
--- src/sys/dev/usb/uhci.c:1.293	Sat Feb 15 01:21:56 2020
+++ src/sys/dev/usb/uhci.c	Fri Feb 21 12:41:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhci.c,v 1.293 2020/02/15 01:21:56 riastradh Exp $	*/
+/*	$NetBSD: uhci.c,v 1.294 2020/02/21 12:41:29 skrll Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004, 2011, 2012 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.293 2020/02/15 01:21:56 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.294 2020/02/21 12:41:29 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -2807,6 +2807,7 @@ uhci_device_ctrl_close(struct usbd_pipe 
 	uhci_free_std_locked(sc, upipe->ctrl.setup);
 	uhci_free_std_locked(sc, upipe->ctrl.stat);
 
+	usb_freemem(>sc_bus, >ctrl.reqdma);
 }
 
 /* Abort a device interrupt request. */

Index: src/sys/external/bsd/dwc2/dwc2.c
diff -u src/sys/external/bsd/dwc2/dwc2.c:1.71 src/sys/external/bsd/dwc2/dwc2.c:1.72
--- src/sys/external/bsd/dwc2/dwc2.c:1.71	Sat Feb 15 14:05:06 2020
+++ src/sys/external/bsd/dwc2/dwc2.c	Fri Feb 21 12:41:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dwc2.c,v 1.71 2020/02/15 14:05:06 riastradh Exp $	*/
+/*	$NetBSD: dwc2.c,v 1.72 2020/02/21