CVS commit: src/doc

2020-12-22 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Wed Dec 23 07:26:36 UTC 2020

Modified Files:
src/doc: CHANGES

Log Message:
Mention sparc64 E250 environmental monitoring.
Belatedly mention pcf8574(4).


To generate a diff of this commit:
cvs rdiff -u -r1.2766 -r1.2767 src/doc/CHANGES

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

Modified files:

Index: src/doc/CHANGES
diff -u src/doc/CHANGES:1.2766 src/doc/CHANGES:1.2767
--- src/doc/CHANGES:1.2766	Sat Dec 12 11:02:06 2020
+++ src/doc/CHANGES	Wed Dec 23 07:26:36 2020
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2766 $>
+# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2767 $>
 #
 #
 # [Note: This file does not mention every change made to the NetBSD source tree.
@@ -297,6 +297,7 @@ Changes from NetBSD 9.0 to NetBSD 10.0:
 	tzcode: Updated to 2020c. [christos 20201017]
 	ossaudio(3): Added support for the OSSv4 Mixer API [nia 20201017]
 	tzdata updated to 2020d  [kre 20201022]
+	pcf8574(4): Add a driver for the PCF8574 I/O expander [jdc 20201029]
 	dhcpcd: Update to version 9.3.2 [roy 20201101]
 	tmux(1): Imported 3.1c. [christos 20201101]
 	kernel: Better default for kern.maxfiles for systems with
@@ -316,3 +317,4 @@ Changes from NetBSD 9.0 to NetBSD 10.0:
 	acpicpu(4): Add support for Arm CPUs. [jmcneill 20201207]
 	OpenSSL: Imported 1.1.1i. [christos 20201209]
 	pkg_install: Updated to 20201212. [wiz 20201212]
+	sparc64: Add environment monitoring for the E250 [jdc 20201223]



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

2020-12-22 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Wed Dec 23 07:09:50 UTC 2020

Modified Files:
src/sys/arch/sparc64/dev: pcf8591_envctrl.c

Log Message:
Rename the CPU fan to SYS fan to match what the firmware calls it.
Check for fan failure and high temperature events when setting the fan
speed.  If one or both is true, run the fans at full speed.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/sparc64/dev/pcf8591_envctrl.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/sparc64/dev/pcf8591_envctrl.c
diff -u src/sys/arch/sparc64/dev/pcf8591_envctrl.c:1.15 src/sys/arch/sparc64/dev/pcf8591_envctrl.c:1.16
--- src/sys/arch/sparc64/dev/pcf8591_envctrl.c:1.15	Sun Dec 20 09:08:15 2020
+++ src/sys/arch/sparc64/dev/pcf8591_envctrl.c	Wed Dec 23 07:09:50 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pcf8591_envctrl.c,v 1.15 2020/12/20 09:08:15 jdc Exp $	*/
+/*	$NetBSD: pcf8591_envctrl.c,v 1.16 2020/12/23 07:09:50 jdc Exp $	*/
 /*	$OpenBSD: pcf8591_envctrl.c,v 1.6 2007/10/25 21:17:20 kettenis Exp $ */
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pcf8591_envctrl.c,v 1.15 2020/12/20 09:08:15 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pcf8591_envctrl.c,v 1.16 2020/12/23 07:09:50 jdc Exp $");
 
 #include 
 #include 
@@ -54,7 +54,7 @@ __KERNEL_RCSID(0, "$NetBSD: pcf8591_envc
 #define PCF8591_CTRL_OSCILLATOR	0x40
 
 #define PCF8591_TEMP_SENS	0x00
-#define PCF8591_CPU_FAN_CTRL	0x01
+#define PCF8591_SYS_FAN_CTRL	0x01
 
 struct ecadc_channel {
 	u_int		chan_num;
@@ -228,12 +228,12 @@ ecadc_attach(device_t parent, device_t s
 	OF_getprop(node, "cpu-fan-speeds", >sc_cpu_fan_spd,
 	XLATE_MAX) > 0) {
 		sc->sc_channels[sc->sc_nchan].chan_num = 1;
-		sc->sc_channels[sc->sc_nchan].chan_type = PCF8591_CPU_FAN_CTRL;
+		sc->sc_channels[sc->sc_nchan].chan_type = PCF8591_SYS_FAN_CTRL;
 		sensor = >sc_channels[sc->sc_nchan].chan_sensor;
 		sensor->units = ENVSYS_INTEGER;
 		sensor->flags = ENVSYS_FMONNOTSUPP;
 		sensor->state = ENVSYS_SINVALID;
-		strlcpy(sensor->desc, "CPUFAN", sizeof(sensor->desc));
+		strlcpy(sensor->desc, "SYSFAN", sizeof(sensor->desc));
 		sc->sc_channels[sc->sc_nchan].chan_xlate = sc->sc_cpu_fan_spd;
 		DPRINTF("%s: "
 		"added CPUFAN sensor (chan %d) with cpu-fan xlate\n",
@@ -298,7 +298,7 @@ ecadc_detach(device_t self, int flags)
 	for (i = 0; i < sc->sc_nchan; i++) {
 		struct ecadc_channel *chp = >sc_channels[i];
 
-		if (chp->chan_type == PCF8591_CPU_FAN_CTRL) {
+		if (chp->chan_type == PCF8591_SYS_FAN_CTRL) {
 			/* Loop in case the bus is busy */
 			for (c = 0; c < 5; c++) {
 chp->chan_speed = sc->sc_cpu_fan_spd[0];
@@ -307,8 +307,8 @@ ecadc_detach(device_t self, int flags)
 	return 0;
 delay(1);
 			}
-			aprint_error_dev(sc->sc_dev,
-			"cannot set fan speed (chan %d)\n", chp->chan_num);
+			printf("%s: cannot set fan speed (chan %d)\n",
+			device_xname(sc->sc_dev), chp->chan_num);
 		}
 	}
 
@@ -374,11 +374,10 @@ ecadc_refresh(struct sysmon_envsys *sme,
 			}
 			chp->chan_sensor.flags |= ENVSYS_FMONLIMITS;
 		}
-		if (chp->chan_type == PCF8591_CPU_FAN_CTRL)
+		if (chp->chan_type == PCF8591_SYS_FAN_CTRL)
 			chp->chan_sensor.value_cur = data[1 + chp->chan_num];
 
 		chp->chan_sensor.state = ENVSYS_SVALID;
-		chp->chan_sensor.flags &= ~ENVSYS_FNEED_REFRESH;
 	}
 }
 
@@ -419,6 +418,22 @@ is_cpu_temp(const envsys_data_t *edata)
 	return strncmp(edata->desc, "CPU", 3) == 0;
 }
 
+static bool
+is_high_temp(const envsys_data_t *edata)
+{
+	if (edata->units != ENVSYS_INDICATOR)
+		return false;
+	return strcmp(edata->desc, "high_temp") == 0;
+}
+
+static bool
+is_fan_fail(const envsys_data_t *edata)
+{
+	if (edata->units != ENVSYS_INDICATOR)
+		return false;
+	return strcmp(edata->desc, "fan_fail") == 0;
+}
+
 static int
 ecadc_set_fan_speed(struct ecadc_softc *sc, u_int8_t chan, u_int8_t val)
 {
@@ -428,15 +443,15 @@ ecadc_set_fan_speed(struct ecadc_softc *
 	ctrl |= chan;
 	ret = iic_acquire_bus(sc->sc_tag, 0);
 	if (ret) {
-		aprint_error_dev(sc->sc_dev,
-		"error acquiring i2c bus (ch %d)\n", chan);
+		printf("%s: error acquiring i2c bus (ch %d)\n",
+		device_xname(sc->sc_dev), chan);
 		return ret;
 	}
 	ret = iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_addr,
 	, 1, , 1, 0);
 	if (ret)
-		aprint_error_dev(sc->sc_dev,
-		"error changing fan speed (ch %d)\n", chan);
+		printf("%s: error changing fan speed (ch %d)\n",
+		device_xname(sc->sc_dev), chan);
 	else
 		DPRINTF("%s changed fan speed (ch %d) to 0x%x\n",
 		device_xname(sc->sc_dev), chan, val);
@@ -448,30 +463,47 @@ static void
 ecadc_fan_adjust(void *v)
 {
 	struct ecadc_softc *sc = v;
+	struct ecadc_channel *chp;
 	int i;
 	u_int8_t temp, speed;
+	u_int32_t htemp, ffail;
 
 	for (i = 0; i < sc->sc_nchan; i++) {
-		struct ecadc_channel *chp = >sc_channels[i];
+		chp = >sc_channels[i];
+		if (chp->chan_type != 

CVS commit: src/sys/dev/i2c

2020-12-22 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Wed Dec 23 07:06:26 UTC 2020

Modified Files:
src/sys/dev/i2c: pcf8574.c

Log Message:
Handle pins that represent alerts.
  split out common code for alert and indicator pins
  change the previously debug-only callout to work for alerts too
  split out common code for alerts in refresh and in callout
While here, remove redundant variable used for checking sysmon setup.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/pcf8574.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/i2c/pcf8574.c
diff -u src/sys/dev/i2c/pcf8574.c:1.5 src/sys/dev/i2c/pcf8574.c:1.6
--- src/sys/dev/i2c/pcf8574.c:1.5	Sun Dec  6 10:09:36 2020
+++ src/sys/dev/i2c/pcf8574.c	Wed Dec 23 07:06:26 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: pcf8574.c,v 1.5 2020/12/06 10:09:36 jdc Exp $ */
+/* $NetBSD: pcf8574.c,v 1.6 2020/12/23 07:06:26 jdc Exp $ */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pcf8574.c,v 1.5 2020/12/06 10:09:36 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pcf8574.c,v 1.6 2020/12/23 07:06:26 jdc Exp $");
 
 #include 
 #include 
@@ -43,6 +43,7 @@ __KERNEL_RCSID(0, "$NetBSD: pcf8574.c,v 
 #include 
 
 #include 
+#include 
 
 #include 
 #include 
@@ -59,6 +60,12 @@ struct pcf8574_led {
 	uint8_t mask, v_on, v_off;
 };
 
+struct pcf8574_pin {
+	int pin_sensor;
+	int pin_active;
+	char pin_desc[ENVSYS_DESCLEN];
+};
+
 #define PCF8574_NPINS	8
 struct pcf8574_softc {
 	device_t	sc_dev;
@@ -67,34 +74,35 @@ struct pcf8574_softc {
 	uint8_t		sc_state;
 	uint8_t		sc_mask;
 
+	uint8_t		sc_alert_mask;
+#define	PCF8574_DEFAULT_TIMER	60
+	int		sc_callout_time;
+	callout_t	sc_timer;
+
 	int		sc_nleds;
 	struct pcf8574_led sc_leds[PCF8574_NPINS];
+	struct pcf8574_pin sc_pins[PCF8574_NPINS];
 
 	struct sysmon_envsys *sc_sme;
 	envsys_data_t	sc_sensor[PCF8574_NPINS];
-	int		sc_pin_sensor[PCF8574_NPINS];
-	int		sc_pin_active[PCF8574_NPINS];
-
-#ifdef PCF8574_DEBUG
-	callout_t	sc_timer;
-#endif
 };
 
 static int	pcf8574_match(device_t, cfdata_t, void *);
 static void	pcf8574_attach(device_t, device_t, void *);
 static int	pcf8574_detach(device_t, int);
 
-static int	pcf8574_read(struct pcf8574_softc *sc, uint8_t *val);
-static int	pcf8574_write(struct pcf8574_softc *sc, uint8_t val);
+static int	pcf8574_read(struct pcf8574_softc *sc, uint8_t *);
+static int	pcf8574_write(struct pcf8574_softc *sc, uint8_t);
 static void	pcf8574_attach_led(
 			struct pcf8574_softc *, char *, int, int, int);
+static int	pcf8574_attach_sysmon(
+			struct pcf8574_softc *, char *, int, int, int);
 void		pcf8574_refresh(struct sysmon_envsys *, envsys_data_t *);
 int		pcf8574_get_led(void *);
 void		pcf8574_set_led(void *, int);
-
-#ifdef PCF8574_DEBUG
-static void pcf8574_timeout(void *);
-#endif
+static void	pcf8574_timeout(void *);
+static void	pcf8574_check(void *);
+static void	pcf8574_check_alert(struct pcf8574_softc *, uint8_t, uint8_t);
 
 CFATTACH_DECL_NEW(pcf8574io, sizeof(struct pcf8574_softc),
 	pcf8574_match, pcf8574_attach, pcf8574_detach, NULL);
@@ -128,12 +136,19 @@ pcf8574_attach(device_t parent, device_t
 	int i, num, def, envc = 0;
 	char name[32];
 	const char *nptr = NULL, *spptr;
-	bool ok = TRUE, act, sysmon = FALSE;
+	bool ok = TRUE, act;
 
 	sc->sc_tag = ia->ia_tag;
 	sc->sc_addr = ia->ia_addr;
 	sc->sc_dev = self;
 
+	sc->sc_sme = NULL;
+#ifdef PCF8574_DEBUG
+	sc->sc_callout_time = 60;	/* watch for changes when debugging */
+#else
+	sc->sc_callout_time = 0;
+#endif
+
 	/*
 	 * The PCF8574 requires input pins to be written with the value 1,
 	 * and then read.  Assume that all pins are input initially.
@@ -150,9 +165,6 @@ pcf8574_attach(device_t parent, device_t
 
 #ifdef PCF8574_DEBUG
 	aprint_normal(": GPIO: state = 0x%02x\n", sc->sc_state);
-
-	callout_init(>sc_timer, CALLOUT_MPSAFE);
-	callout_reset(>sc_timer, hz*30, pcf8574_timeout, sc);
 #else
 	aprint_normal(": GPIO\n");
 #endif
@@ -177,37 +189,38 @@ pcf8574_attach(device_t parent, device_t
 			continue;
 		spptr += 1;
 		strncpy(name, spptr, 31);
-		sc->sc_pin_active[i] = act;
+		sc->sc_pins[i].pin_active = act;
 		if (!strncmp(nptr, "LED ", 4)) {
 			sc->sc_mask &= ~(1 << num);
 			pcf8574_attach_led(sc, name, num, act, def);
 		}
-		if (!strncmp(nptr, "INDICATOR ", 4)) {
-			if (!sysmon) {
-sc->sc_sme = sysmon_envsys_create();
-sysmon = TRUE;
-			}
-			/* envsys sensor # to pin # mapping */
-			sc->sc_pin_sensor[envc] = num;
-			sc->sc_sensor[i].state = ENVSYS_SINVALID;
-			sc->sc_sensor[i].units = ENVSYS_INDICATOR;
-			strlcpy(sc->sc_sensor[i].desc, name,
-			sizeof(sc->sc_sensor[i].desc));
-			if (sysmon_envsys_sensor_attach(sc->sc_sme,
-			>sc_sensor[i])) {
-sysmon_envsys_destroy(sc->sc_sme);
-sc->sc_sme = NULL;
-aprint_error_dev(self,
-"unable to attach pin %d at sysmon\n", i);
+		if 

CVS commit: src/sys/arch/sparc64/sparc64

2020-12-22 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Wed Dec 23 07:01:14 UTC 2020

Modified Files:
src/sys/arch/sparc64/sparc64: ofw_patch.c

Log Message:
Add GPIO pin alert definitions for the E250.
Note, that the front panel also applies to the E450.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/sparc64/sparc64/ofw_patch.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/sparc64/sparc64/ofw_patch.c
diff -u src/sys/arch/sparc64/sparc64/ofw_patch.c:1.6 src/sys/arch/sparc64/sparc64/ofw_patch.c:1.7
--- src/sys/arch/sparc64/sparc64/ofw_patch.c:1.6	Thu Oct 29 06:47:38 2020
+++ src/sys/arch/sparc64/sparc64/ofw_patch.c	Wed Dec 23 07:01:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_patch.c,v 1.6 2020/10/29 06:47:38 jdc Exp $ */
+/*	$NetBSD: ofw_patch.c,v 1.7 2020/12/23 07:01:14 jdc Exp $ */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_patch.c,v 1.6 2020/10/29 06:47:38 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_patch.c,v 1.7 2020/12/23 07:01:14 jdc Exp $");
 
 #include 
 
@@ -134,6 +134,16 @@ add_gpio_props_e250(device_t dev, void *
 	prop_array_t pins;
 
 	switch (ia->ia_addr) {
+		case 0x38:	/* interrupt status */
+			pins = prop_array_create();
+			add_gpio_pin(pins, "ALERT high_temp", 1, 0, 30);
+			add_gpio_pin(pins, "ALERT disk_event", 2, 0, 30);
+			add_gpio_pin(pins, "ALERT fan_fail", 4, 0, 30);
+			add_gpio_pin(pins, "ALERT key_event", 5, 0, 30);
+			add_gpio_pin(pins, "ALERT psu_event", 6, 0, 30);
+			prop_dictionary_set(dict, "pins", pins);
+			prop_object_release(pins);
+			break;
 		case 0x39:	/* PSU status */
 			pins = prop_array_create();
 			add_gpio_pin(pins, "INDICATOR psu0_present", 0, 0, -1);
@@ -160,7 +170,7 @@ add_gpio_props_e250(device_t dev, void *
 			prop_dictionary_set(dict, "pins", pins);
 			prop_object_release(pins);
 			break;
-		case 0x3e:	/* front panel LEDs */
+		case 0x3e:	/* front panel LEDs (E250/E450) */
 			pins = prop_array_create();
 			add_gpio_pin(pins, "LED disk_fault", 0, 0, -1);
 			add_gpio_pin(pins, "LED psu_fault", 1, 0, -1);



CVS commit: src/share/man/man4

2020-12-22 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed Dec 23 06:10:13 UTC 2020

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

Log Message:
wsdisplay(4): WSDISPLAYIO_GET_EDID - fix struct name.

Spotted by RVP.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/share/man/man4/wsdisplay.4

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

Modified files:

Index: src/share/man/man4/wsdisplay.4
diff -u src/share/man/man4/wsdisplay.4:1.49 src/share/man/man4/wsdisplay.4:1.50
--- src/share/man/man4/wsdisplay.4:1.49	Sat May 16 20:27:38 2020
+++ src/share/man/man4/wsdisplay.4	Wed Dec 23 06:10:13 2020
@@ -1,4 +1,4 @@
-.\" $NetBSD: wsdisplay.4,v 1.49 2020/05/16 20:27:38 tnn Exp $
+.\" $NetBSD: wsdisplay.4,v 1.50 2020/12/23 06:10:13 uwe Exp $
 .\"
 .\" Copyright (c) 1999 Matthias Drochner.
 .\" Copyright (c) 2002 Ben Harris.
@@ -583,7 +583,7 @@ Toggle the splash screen.
 This call is only available with the
 .Dv SPLASHSCREEN
 kernel option.
-.It Dv WSDISPLAYIO_GET_EDID Pq Li struct wsdisplay_edid_info
+.It Dv WSDISPLAYIO_GET_EDID Pq Li struct wsdisplayio_edid_info
 Retrieve EDID data from a driver.
 .Bd -literal -offset indent
 struct wsdisplayio_edid_info {



CVS commit: src/sys/dev/wscons

2020-12-22 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Wed Dec 23 05:50:51 UTC 2020

Modified Files:
src/sys/dev/wscons: wsdisplay_vcons.c

Log Message:
fix tpyo
spotted by RVP, thanks!


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/dev/wscons/wsdisplay_vcons.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/wscons/wsdisplay_vcons.c
diff -u src/sys/dev/wscons/wsdisplay_vcons.c:1.42 src/sys/dev/wscons/wsdisplay_vcons.c:1.43
--- src/sys/dev/wscons/wsdisplay_vcons.c:1.42	Sat Nov 21 11:26:55 2020
+++ src/sys/dev/wscons/wsdisplay_vcons.c	Wed Dec 23 05:50:51 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: wsdisplay_vcons.c,v 1.42 2020/11/21 11:26:55 mlelstv Exp $ */
+/*	$NetBSD: wsdisplay_vcons.c,v 1.43 2020/12/23 05:50:51 macallan Exp $ */
 
 /*-
  * Copyright (c) 2005, 2006 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: wsdisplay_vcons.c,v 1.42 2020/11/21 11:26:55 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wsdisplay_vcons.c,v 1.43 2020/12/23 05:50:51 macallan Exp $");
 
 #include 
 #include 
@@ -1541,7 +1541,7 @@ vcons_invalidate_cache(struct vcons_data
 	if (vd->cells == 0)
 		return;
 
-	for (i = 0; i > vd->cells; i++) {
+	for (i = 0; i < vd->cells; i++) {
 		vd->chars[i] = -1;
 		vd->attrs[i] = -1;
 	}



CVS commit: src/sys

2020-12-22 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Dec 23 04:09:32 UTC 2020

Modified Files:
src/sys/arch/evbarm/conf: GENERIC GENERIC64
src/sys/dev/fdt: files.fdt
Added Files:
src/sys/dev/fdt: i2cmux_fdt.c

Log Message:
Add support for i2c-mux-gpio and i2c-mux-pinctrl I2C mux virtual
controllers.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/sys/arch/evbarm/conf/GENERIC
cvs rdiff -u -r1.167 -r1.168 src/sys/arch/evbarm/conf/GENERIC64
cvs rdiff -u -r1.57 -r1.58 src/sys/dev/fdt/files.fdt
cvs rdiff -u -r0 -r1.1 src/sys/dev/fdt/i2cmux_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/evbarm/conf/GENERIC
diff -u src/sys/arch/evbarm/conf/GENERIC:1.83 src/sys/arch/evbarm/conf/GENERIC:1.84
--- src/sys/arch/evbarm/conf/GENERIC:1.83	Tue Sep 29 19:58:50 2020
+++ src/sys/arch/evbarm/conf/GENERIC	Wed Dec 23 04:09:32 2020
@@ -1,5 +1,5 @@
 #
-#	$NetBSD: GENERIC,v 1.83 2020/09/29 19:58:50 jmcneill Exp $
+#	$NetBSD: GENERIC,v 1.84 2020/12/23 04:09:32 thorpej Exp $
 #
 #	GENERIC ARM (aarch32) kernel
 #
@@ -324,11 +324,12 @@ zynquart* 	at fdt?	pass 4		# Cadence UAR
 options 	I2C_MAX_ADDR=0xfff
 bsciic* 	at fdt?			# Broadcom BCM283x Serial Control
 exyoi2c* 	at fdt?			# Samsung Exynos I2C
-imxi2c* 	at fdt?			# i.MX I2C
+imxi2c* 	at fdt? pass 4		# i.MX I2C
 sunxirsb* 	at fdt? pass 4		# Allwinner RSB
 sunxitwi* 	at fdt?			# Allwinner TWI
 tegrai2c* 	at fdt? pass 4		# NVIDIA Tegra I2C
 tiiic*		at fdt? pass 4		# TI OMAP I2C
+iicmux*		at fdt? pass 5		# I2C mux virtual controllers
 iic* 		at i2cbus?
 
 # I2C devices

Index: src/sys/arch/evbarm/conf/GENERIC64
diff -u src/sys/arch/evbarm/conf/GENERIC64:1.167 src/sys/arch/evbarm/conf/GENERIC64:1.168
--- src/sys/arch/evbarm/conf/GENERIC64:1.167	Sun Dec 13 20:40:38 2020
+++ src/sys/arch/evbarm/conf/GENERIC64	Wed Dec 23 04:09:32 2020
@@ -1,5 +1,5 @@
 #
-#	$NetBSD: GENERIC64,v 1.167 2020/12/13 20:40:38 jmcneill Exp $
+#	$NetBSD: GENERIC64,v 1.168 2020/12/23 04:09:32 thorpej Exp $
 #
 #	GENERIC ARM (aarch64) kernel
 #
@@ -302,6 +302,7 @@ sunxitwi*	at fdt?			# Allwinner TWI
 tegrai2c*	at fdt? pass 4		# NVIDIA Tegra I2C
 #sniiic*	at fdt?			# Socionext SC2A11 I2C
 #sniiic*	at acpi?
+iicmux*		at fdt? pass 5		# I2C mux virtual controllers
 iic*		at i2cbus?
 
 # I2C devices

Index: src/sys/dev/fdt/files.fdt
diff -u src/sys/dev/fdt/files.fdt:1.57 src/sys/dev/fdt/files.fdt:1.58
--- src/sys/dev/fdt/files.fdt:1.57	Sat Dec 12 09:27:31 2020
+++ src/sys/dev/fdt/files.fdt	Wed Dec 23 04:09:32 2020
@@ -1,4 +1,4 @@
-# $NetBSD: files.fdt,v 1.57 2020/12/12 09:27:31 skrll Exp $
+# $NetBSD: files.fdt,v 1.58 2020/12/23 04:09:32 thorpej Exp $
 
 include	"external/bsd/libfdt/conf/files.libfdt"
 
@@ -54,6 +54,10 @@ device	dispcon: fdt_port, drmkms, ddc_re
 attach	dispcon at fdt with dispcon_hdmi
 file	dev/fdt/hdmi_connector.c		dispcon_hdmi
 
+device	iicmux: i2cbus
+attach	iicmux at fdt with iicmux_fdt
+file	dev/fdt/i2cmux_fdt.c			iicmux_fdt
+
 file	dev/fdt/fdt_memory.c			fdtbase
 file	dev/fdt/fdt_openfirm.c			fdtbase
 file	dev/fdt/fdt_subr.c			fdtbase

Added files:

Index: src/sys/dev/fdt/i2cmux_fdt.c
diff -u /dev/null src/sys/dev/fdt/i2cmux_fdt.c:1.1
--- /dev/null	Wed Dec 23 04:09:32 2020
+++ src/sys/dev/fdt/i2cmux_fdt.c	Wed Dec 23 04:09:32 2020
@@ -0,0 +1,418 @@
+/*	$NetBSD: i2cmux_fdt.c,v 1.1 2020/12/23 04:09:32 thorpej Exp $	*/
+
+/*-
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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 

CVS commit: src/sys/dev/fdt

2020-12-22 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Dec 23 04:07:34 UTC 2020

Modified Files:
src/sys/dev/fdt: fdt_gpio.c fdtvar.h

Log Message:
Add fdtbus_gpio_count(), which counts the number of GPIO entries
in a specified property.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/fdt/fdt_gpio.c
cvs rdiff -u -r1.62 -r1.63 src/sys/dev/fdt/fdtvar.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/fdt/fdt_gpio.c
diff -u src/sys/dev/fdt/fdt_gpio.c:1.6 src/sys/dev/fdt/fdt_gpio.c:1.7
--- src/sys/dev/fdt/fdt_gpio.c:1.6	Sat Jun 30 20:34:43 2018
+++ src/sys/dev/fdt/fdt_gpio.c	Wed Dec 23 04:07:34 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_gpio.c,v 1.6 2018/06/30 20:34:43 jmcneill Exp $ */
+/* $NetBSD: fdt_gpio.c,v 1.7 2020/12/23 04:07:34 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdt_gpio.c,v 1.6 2018/06/30 20:34:43 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_gpio.c,v 1.7 2020/12/23 04:07:34 thorpej Exp $");
 
 #include 
 #include 
@@ -77,6 +77,30 @@ fdtbus_get_gpio_controller(int phandle)
 	return NULL;
 }
 
+int
+fdtbus_gpio_count(int phandle, const char *prop)
+{
+	const uint32_t *gpios, *p;
+	u_int n, gpio_cells;
+	int len, resid;
+
+	gpios = fdtbus_get_prop(phandle, prop, );
+	if (gpios == NULL)
+		return 0;
+
+	p = gpios;
+	for (n = 0, resid = len; resid > 0; n++) {
+		const int gc_phandle =
+		fdtbus_get_phandle_from_native(be32toh(p[0]));
+		if (of_getprop_uint32(gc_phandle, "#gpio-cells", _cells))
+			break;
+		resid -= (gpio_cells + 1) * 4;
+		p += gpio_cells + 1;
+	}
+
+	return n;
+}
+
 struct fdtbus_gpio_pin *
 fdtbus_gpio_acquire(int phandle, const char *prop, int flags)
 {

Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.62 src/sys/dev/fdt/fdtvar.h:1.63
--- src/sys/dev/fdt/fdtvar.h:1.62	Fri Dec 11 09:40:28 2020
+++ src/sys/dev/fdt/fdtvar.h	Wed Dec 23 04:07:34 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.62 2020/12/11 09:40:28 skrll Exp $ */
+/* $NetBSD: fdtvar.h,v 1.63 2020/12/23 04:07:34 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -331,6 +331,7 @@ void		fdtbus_intr_unmask(int, void *);
 void		fdtbus_intr_disestablish(int, void *);
 bool		fdtbus_intr_str(int, u_int, char *, size_t);
 bool		fdtbus_intr_str_raw(int, const u_int *, char *, size_t);
+int		fdtbus_gpio_count(int, const char *);
 struct fdtbus_gpio_pin *fdtbus_gpio_acquire(int, const char *, int);
 struct fdtbus_gpio_pin *fdtbus_gpio_acquire_index(int, const char *, int, int);
 void		fdtbus_gpio_release(struct fdtbus_gpio_pin *);



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

2020-12-22 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Dec 23 02:56:11 UTC 2020

Modified Files:
src/sys/arch/arm/broadcom: bcm2835_bsc_fdt.c

Log Message:
Add missing call to fdtbus_register_i2c_controller().  This doesn't
affect basic child attachment, but would have broken other references
to the i2c controller in DT overlays.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/broadcom/bcm2835_bsc_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/broadcom/bcm2835_bsc_fdt.c
diff -u src/sys/arch/arm/broadcom/bcm2835_bsc_fdt.c:1.2 src/sys/arch/arm/broadcom/bcm2835_bsc_fdt.c:1.3
--- src/sys/arch/arm/broadcom/bcm2835_bsc_fdt.c:1.2	Sun May 31 23:52:19 2020
+++ src/sys/arch/arm/broadcom/bcm2835_bsc_fdt.c	Wed Dec 23 02:56:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: bcm2835_bsc_fdt.c,v 1.2 2020/05/31 23:52:19 thorpej Exp $	*/
+/*	$NetBSD: bcm2835_bsc_fdt.c,v 1.3 2020/12/23 02:56:11 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2019 Jason R. Thorpe
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_bsc_fdt.c,v 1.2 2020/05/31 23:52:19 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_bsc_fdt.c,v 1.3 2020/12/23 02:56:11 thorpej Exp $");
 
 #include 
 #include 
@@ -46,6 +46,18 @@ __KERNEL_RCSID(0, "$NetBSD: bcm2835_bsc_
 
 #include 
 
+static i2c_tag_t
+bsciic_fdt_get_tag(device_t dev)
+{
+	struct bsciic_softc * const sc = device_private(dev);
+
+	return >sc_i2c;
+}
+
+static const struct fdtbus_i2c_controller_func bsciic_fdt_funcs = {
+	.get_tag = bsciic_fdt_get_tag,
+};
+
 static int bsciic_fdt_match(device_t, cfdata_t, void *);
 static void bsciic_fdt_attach(device_t, device_t, void *);
 
@@ -129,5 +141,7 @@ bsciic_fdt_attach(device_t parent, devic
 	sc->sc_i2c.ic_release_bus = bsciic_release_bus;
 	sc->sc_i2c.ic_exec = bsciic_exec;
 
+	fdtbus_register_i2c_controller(self, phandle, _fdt_funcs);
+
 	fdtbus_attach_i2cbus(self, phandle, >sc_i2c, iicbus_print);
 }



CVS commit: src/sys/arch/evbarm/conf

2020-12-22 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Tue Dec 22 23:26:42 UTC 2020

Modified Files:
src/sys/arch/evbarm/conf: GENERIC.common

Log Message:
evbarm: GENERIC.common - g/c the commented out copy of pseudo-device fss.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/evbarm/conf/GENERIC.common

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/GENERIC.common
diff -u src/sys/arch/evbarm/conf/GENERIC.common:1.39 src/sys/arch/evbarm/conf/GENERIC.common:1.40
--- src/sys/arch/evbarm/conf/GENERIC.common:1.39	Sun Sep 27 13:48:50 2020
+++ src/sys/arch/evbarm/conf/GENERIC.common	Tue Dec 22 23:26:42 2020
@@ -1,5 +1,5 @@
 #
-#	$NetBSD: GENERIC.common,v 1.39 2020/09/27 13:48:50 roy Exp $
+#	$NetBSD: GENERIC.common,v 1.40 2020/12/22 23:26:42 uwe Exp $
 #
 #	GENERIC evbarm kernel config (template)
 #
@@ -128,7 +128,7 @@ pseudo-device	swcrypto		# software crypt
 # disk/mass storage pseudo-devices
 #pseudo-device	md			# memory disk device (ramdisk)
 pseudo-device	vnd			# disk-like interface to files
-#pseudo-device	fss			# file system snapshot device
+pseudo-device	fss			# file system snapshot device
 pseudo-device	drvctl			# driver control
 pseudo-device	cgd			# cryptographic disk devices
 pseudo-device	raid			# RAIDframe disk driver
@@ -141,7 +141,6 @@ options 	RAID_AUTOCONFIG		# auto-configu
 #options 	RF_INCLUDE_INTERDECLUSTER=1
 #options 	RF_INCLUDE_PARITY_DECLUSTERING=1
 #options 	RF_INCLUDE_PARITY_DECLUSTERING_DS=1
-pseudo-device	fss			# file system snapshot device
 
 # network pseudo-devices
 pseudo-device	bpfilter		# Berkeley packet filter



CVS commit: src/usr.bin/make

2020-12-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Dec 22 22:31:50 UTC 2020

Modified Files:
src/usr.bin/make: make.h meta.c

Log Message:
make(1): fix return type of macro DEBUG

This macro was supposed to return a boolean expression all the time, it
just hadn't been implemented this way.  This resulted in wrong output
for the test sh-flags, in compilation modes -DUSE_UCHAR_BOOLEAN and
-DUSE_CHAR_BOOLEAN, since in ParseCommandFlags, the expression
DEBUG(LOUD) didn't fit into a boolean.


To generate a diff of this commit:
cvs rdiff -u -r1.235 -r1.236 src/usr.bin/make/make.h
cvs rdiff -u -r1.164 -r1.165 src/usr.bin/make/meta.c

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

Modified files:

Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.235 src/usr.bin/make/make.h:1.236
--- src/usr.bin/make/make.h:1.235	Fri Dec 18 18:17:45 2020
+++ src/usr.bin/make/make.h	Tue Dec 22 22:31:50 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.h,v 1.235 2020/12/18 18:17:45 rillig Exp $	*/
+/*	$NetBSD: make.h,v 1.236 2020/12/22 22:31:50 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -581,7 +581,7 @@ typedef enum DebugFlags {
 
 #define CONCAT(a, b) a##b
 
-#define DEBUG(module) (opts.debug & CONCAT(DEBUG_,module))
+#define DEBUG(module) ((opts.debug & CONCAT(DEBUG_, module)) != 0)
 
 void debug_printf(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
 

Index: src/usr.bin/make/meta.c
diff -u src/usr.bin/make/meta.c:1.164 src/usr.bin/make/meta.c:1.165
--- src/usr.bin/make/meta.c:1.164	Sun Dec 20 22:36:40 2020
+++ src/usr.bin/make/meta.c	Tue Dec 22 22:31:50 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: meta.c,v 1.164 2020/12/20 22:36:40 rillig Exp $ */
+/*  $NetBSD: meta.c,v 1.165 2020/12/22 22:31:50 rillig Exp $ */
 
 /*
  * Implement 'meta' mode.
@@ -416,7 +416,7 @@ meta_needed(GNode *gn, const char *dname
 struct cached_stat cst;
 
 if (verbose)
-	verbose = DEBUG(META) != 0;
+	verbose = DEBUG(META);
 
 /* This may be a phony node which we don't want meta data for... */
 /* Skip .meta for .BEGIN, .END, .ERROR etc as well. */



CVS commit: src/usr.bin/make

2020-12-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Dec 22 20:10:21 UTC 2020

Modified Files:
src/usr.bin/make: make.1 nonints.h var.c
src/usr.bin/make/unit-tests: directive-undef.exp directive-undef.mk

Log Message:
make(1): allow .undef to undefine multiple variables at once

Since make doesn't support variable names containing spaces, this edge
case is not enough reason to stop this feature.  Having multiple
variable names as arguments nicely aligns with other directives such as
.for and .export.


To generate a diff of this commit:
cvs rdiff -u -r1.293 -r1.294 src/usr.bin/make/make.1
cvs rdiff -u -r1.180 -r1.181 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.761 -r1.762 src/usr.bin/make/var.c
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/directive-undef.exp
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/directive-undef.mk

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

Modified files:

Index: src/usr.bin/make/make.1
diff -u src/usr.bin/make/make.1:1.293 src/usr.bin/make/make.1:1.294
--- src/usr.bin/make/make.1:1.293	Wed Nov 25 00:50:44 2020
+++ src/usr.bin/make/make.1	Tue Dec 22 20:10:21 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: make.1,v 1.293 2020/11/25 00:50:44 sjg Exp $
+.\"	$NetBSD: make.1,v 1.294 2020/12/22 20:10:21 rillig Exp $
 .\"
 .\" Copyright (c) 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"	from: @(#)make.1	8.4 (Berkeley) 3/19/94
 .\"
-.Dd November 24, 2020
+.Dd December 22, 2020
 .Dt MAKE 1
 .Os
 .Sh NAME
@@ -1748,9 +1748,9 @@ The same as
 except that variables in the value are not expanded.
 .It Ic .info Ar message
 The message is printed along with the name of the makefile and line number.
-.It Ic .undef Ar variable
-Un-define the specified global variable.
-Only global variables may be un-defined.
+.It Ic .undef Ar variable ...
+Un-define the specified global variables.
+Only global variables can be un-defined.
 .It Ic .unexport Ar variable ...
 The opposite of
 .Ql .export .

Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.180 src/usr.bin/make/nonints.h:1.181
--- src/usr.bin/make/nonints.h:1.180	Sun Dec 20 21:07:32 2020
+++ src/usr.bin/make/nonints.h	Tue Dec 22 20:10:21 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nonints.h,v 1.180 2020/12/20 21:07:32 rillig Exp $	*/
+/*	$NetBSD: nonints.h,v 1.181 2020/12/22 20:10:21 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -396,7 +396,7 @@ typedef enum VarExportMode {
 
 void Var_DeleteVar(const char *, GNode *);
 void Var_Delete(const char *, GNode *);
-void Var_Undef(char *);
+void Var_Undef(const char *);
 void Var_Set(const char *, const char *, GNode *);
 void Var_SetWithFlags(const char *, const char *, GNode *, VarSetFlags);
 void Var_Append(const char *, const char *, GNode *);

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.761 src/usr.bin/make/var.c:1.762
--- src/usr.bin/make/var.c:1.761	Mon Dec 21 21:04:18 2020
+++ src/usr.bin/make/var.c	Tue Dec 22 20:10:21 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.761 2020/12/21 21:04:18 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.762 2020/12/22 20:10:21 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.761 2020/12/21 21:04:18 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.762 2020/12/22 20:10:21 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -513,38 +513,40 @@ Var_Delete(const char *name, GNode *ctxt
 }
 
 /*
- * Undefine a single variable from the global scope.  The argument is
- * expanded once.
+ * Undefine one or more variables from the global scope.
+ * The argument is expanded exactly once and then split into words.
  */
 void
-Var_Undef(char *arg)
+Var_Undef(const char *arg)
 {
-	/*
-	 * The argument must consist of exactly 1 word.  Accepting more than
-	 * 1 word would have required to split the argument into several
-	 * words, and such splitting is already done subtly different in many
-	 * other places of make.
-	 *
-	 * Using Str_Words to split the words, followed by Var_Subst to expand
-	 * each variable name once would make it impossible to undefine
-	 * variables whose names contain space characters or unbalanced
-	 * quotes or backslashes in arbitrary positions.
-	 *
-	 * Using Var_Subst on the whole argument and splitting the words
-	 * afterwards using Str_Words would make it impossible to undefine
-	 * variables whose names contain space characters.
-	 */
-	char *cp = arg;
+	VarParseResult vpr;
+	char *expanded;
+	Words varnames;
+	size_t i;
 
-	for (; !ch_isspace(*cp) && *cp != '\0'; cp++)
-		continue;
-	if (cp == arg || *cp != '\0') {
+	if (arg[0] == '\0') {
 		Parse_Error(PARSE_FATAL,
-		"The .undef directive requires exactly 1 argument");
+		"The .undef directive requires an argument");
+		return;
+	}
+
+	vpr = 

CVS commit: src/usr.bin/make/unit-tests

2020-12-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Dec 22 19:38:44 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: depsrc.exp depsrc.mk

Log Message:
make(1): add test for undefined variable in dependency declaration


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/depsrc.exp
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/depsrc.mk

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

Modified files:

Index: src/usr.bin/make/unit-tests/depsrc.exp
diff -u src/usr.bin/make/unit-tests/depsrc.exp:1.1 src/usr.bin/make/unit-tests/depsrc.exp:1.2
--- src/usr.bin/make/unit-tests/depsrc.exp:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/depsrc.exp	Tue Dec 22 19:38:44 2020
@@ -1 +1,4 @@
+: 'Undefined variables are expanded directly in the dependency'
+: 'declaration.  They are not preserved and maybe expanded later.'
+: 'This is in contrast to local variables such as ${.TARGET}.'
 exit status 0

Index: src/usr.bin/make/unit-tests/depsrc.mk
diff -u src/usr.bin/make/unit-tests/depsrc.mk:1.3 src/usr.bin/make/unit-tests/depsrc.mk:1.4
--- src/usr.bin/make/unit-tests/depsrc.mk:1.3	Sun Nov 15 20:20:58 2020
+++ src/usr.bin/make/unit-tests/depsrc.mk	Tue Dec 22 19:38:44 2020
@@ -1,4 +1,4 @@
-# $NetBSD: depsrc.mk,v 1.3 2020/11/15 20:20:58 rillig Exp $
+# $NetBSD: depsrc.mk,v 1.4 2020/12/22 19:38:44 rillig Exp $
 #
 # Tests for special sources (those starting with a dot, followed by
 # uppercase letters) in dependency declarations, such as .PHONY.
@@ -7,5 +7,20 @@
 
 # TODO: Test 'target: ${:U.SILENT}'
 
+# Demonstrate when exactly undefined variables are expanded in a dependency
+# declaration.
+target: .PHONY source-${DEFINED_LATER}
+#
+DEFINED_LATER=	later
+#
+source-: .PHONY
+	: 'Undefined variables are expanded directly in the dependency'
+	: 'declaration.  They are not preserved and maybe expanded later.'
+	: 'This is in contrast to local variables such as $${.TARGET}.'
+source-later: .PHONY
+	: 'Undefined variables are tried to be expanded in a dependency'
+	: 'declaration.  If that fails because the variable is undefined,'
+	: 'the expression is preserved and tried to be expanded later.'
+
 all:
 	@:;



CVS commit: src/usr.bin/nl

2020-12-22 Thread Brian Ginsbach
Module Name:src
Committed By:   ginsbach
Date:   Tue Dec 22 17:50:56 UTC 2020

Modified Files:
src/usr.bin/nl: nl.c

Log Message:
nl(1): remove superfluous exit

Remove exit(3) call missed when errors were converted to errx(3).


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/nl/nl.c

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

Modified files:

Index: src/usr.bin/nl/nl.c
diff -u src/usr.bin/nl/nl.c:1.12 src/usr.bin/nl/nl.c:1.13
--- src/usr.bin/nl/nl.c:1.12	Tue Sep 17 20:00:50 2013
+++ src/usr.bin/nl/nl.c	Tue Dec 22 17:50:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nl.c,v 1.12 2013/09/17 20:00:50 wiz Exp $	*/
+/*	$NetBSD: nl.c,v 1.13 2020/12/22 17:50:55 ginsbach Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1999\
  The NetBSD Foundation, Inc.  All rights reserved.");
-__RCSID("$NetBSD: nl.c,v 1.12 2013/09/17 20:00:50 wiz Exp $");
+__RCSID("$NetBSD: nl.c,v 1.13 2020/12/22 17:50:55 ginsbach Exp $");
 #endif
 
 #include 
@@ -392,7 +392,6 @@ parse_numbering(const char *argstr, int 
 		errx(EXIT_FAILURE,
 		"illegal %s line numbering type -- %s",
 		numbering_properties[section].name, argstr);
-		exit(EXIT_FAILURE);
 	}
 }
 



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

2020-12-22 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Tue Dec 22 13:07:33 UTC 2020

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

Log Message:
Count bus_dmamap_sync events for coherent ranges and non-coherent ranges


To generate a diff of this commit:
cvs rdiff -u -r1.128 -r1.129 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.128 src/sys/arch/arm/arm32/bus_dma.c:1.129
--- src/sys/arch/arm/arm32/bus_dma.c:1.128	Sun Dec 20 10:34:33 2020
+++ src/sys/arch/arm/arm32/bus_dma.c	Tue Dec 22 13:07:32 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus_dma.c,v 1.128 2020/12/20 10:34:33 jmcneill Exp $	*/
+/*	$NetBSD: bus_dma.c,v 1.129 2020/12/22 13:07:32 skrll Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2020 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #include "opt_cputypes.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.128 2020/12/20 10:34:33 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.129 2020/12/22 13:07:32 skrll Exp $");
 
 #include 
 
@@ -94,6 +94,19 @@ static struct evcnt bus_dma_sync_postrea
 static struct evcnt bus_dma_sync_postwrite =
 	EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "busdma", "sync postwrite");
 
+static struct evcnt bus_dma_sync_coherent_prereadwrite =
+	EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "busdma", "sync coherent prereadwrite");
+static struct evcnt bus_dma_sync_coherent_preread =
+	EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "busdma", "sync coherent preread");
+static struct evcnt bus_dma_sync_coherent_prewrite =
+	EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "busdma", "sync coherent prewrite");
+static struct evcnt bus_dma_sync_coherent_postread =
+	EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "busdma", "sync coherent postread");
+static struct evcnt bus_dma_sync_coherent_postreadwrite =
+	EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "busdma", "sync coherent postreadwrite");
+static struct evcnt bus_dma_sync_coherent_postwrite =
+	EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "busdma", "sync coherent postwrite");
+
 EVCNT_ATTACH_STATIC(bus_dma_creates);
 EVCNT_ATTACH_STATIC(bus_dma_bounced_creates);
 EVCNT_ATTACH_STATIC(bus_dma_loads);
@@ -114,6 +127,13 @@ EVCNT_ATTACH_STATIC(bus_dma_sync_postrea
 EVCNT_ATTACH_STATIC(bus_dma_sync_postreadwrite);
 EVCNT_ATTACH_STATIC(bus_dma_sync_postwrite);
 
+EVCNT_ATTACH_STATIC(bus_dma_sync_coherent_prereadwrite);
+EVCNT_ATTACH_STATIC(bus_dma_sync_coherent_preread);
+EVCNT_ATTACH_STATIC(bus_dma_sync_coherent_prewrite);
+EVCNT_ATTACH_STATIC(bus_dma_sync_coherent_postread);
+EVCNT_ATTACH_STATIC(bus_dma_sync_coherent_postreadwrite);
+EVCNT_ATTACH_STATIC(bus_dma_sync_coherent_postwrite);
+
 #define	STAT_INCR(x)	(bus_dma_ ## x.ev_count++)
 #else
 #define	STAT_INCR(x)	__nothing
@@ -1108,7 +1128,11 @@ _bus_dmamap_sync(bus_dma_tag_t t, bus_dm
 
 	if (post_ops == BUS_DMASYNC_POSTWRITE) {
 		KASSERT(pre_ops == 0);
-		STAT_INCR(sync_postwrite);
+		if ((map->_dm_flags & _BUS_DMAMAP_COHERENT)) {
+			STAT_INCR(sync_coherent_postwrite);
+		} else {
+			STAT_INCR(sync_postwrite);
+		}
 		return;
 	}
 
@@ -1157,23 +1181,23 @@ _bus_dmamap_sync(bus_dma_tag_t t, bus_dm
 	if ((map->_dm_flags & _BUS_DMAMAP_COHERENT)) {
 		switch (ops) {
 		case BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE:
-			STAT_INCR(sync_prereadwrite);
+			STAT_INCR(sync_coherent_prereadwrite);
 			break;
 
 		case BUS_DMASYNC_PREREAD:
-			STAT_INCR(sync_preread);
+			STAT_INCR(sync_coherent_preread);
 			break;
 
 		case BUS_DMASYNC_PREWRITE:
-			STAT_INCR(sync_prewrite);
+			STAT_INCR(sync_coherent_prewrite);
 			break;
 
 		case BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE:
-			STAT_INCR(sync_postreadwrite);
+			STAT_INCR(sync_coherent_postreadwrite);
 			break;
 
 		case BUS_DMASYNC_POSTREAD:
-			STAT_INCR(sync_postread);
+			STAT_INCR(sync_coherent_postread);
 			break;
 
 		/* BUS_DMASYNC_POSTWRITE was aleady handled as a fastpath */



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

2020-12-22 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Dec 22 10:46:51 UTC 2020

Modified Files:
src/sys/arch/arm/cortex: gicv3.c

Log Message:
When lpiconf flushing is required, make sure to flush to PoC and not PoU.
Spotted by nick.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/arm/cortex/gicv3.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/cortex/gicv3.c
diff -u src/sys/arch/arm/cortex/gicv3.c:1.37 src/sys/arch/arm/cortex/gicv3.c:1.38
--- src/sys/arch/arm/cortex/gicv3.c:1.37	Fri Dec 11 21:22:36 2020
+++ src/sys/arch/arm/cortex/gicv3.c	Tue Dec 22 10:46:51 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: gicv3.c,v 1.37 2020/12/11 21:22:36 jmcneill Exp $ */
+/* $NetBSD: gicv3.c,v 1.38 2020/12/22 10:46:51 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -31,7 +31,7 @@
 #define	_INTR_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gicv3.c,v 1.37 2020/12/11 21:22:36 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gicv3.c,v 1.38 2020/12/22 10:46:51 jmcneill Exp $");
 
 #include 
 #include 
@@ -514,6 +514,13 @@ static const struct pic_ops gicv3_picops
 };
 
 static void
+gicv3_dcache_wb_range(vaddr_t va, vsize_t len)
+{
+	cpu_dcache_wb_range(va, len);
+	dsb(sy);
+}
+
+static void
 gicv3_lpi_unblock_irqs(struct pic_softc *pic, size_t irqbase, uint32_t mask)
 {
 	struct gicv3_softc * const sc = LPITOSOFTC(pic);
@@ -522,7 +529,7 @@ gicv3_lpi_unblock_irqs(struct pic_softc 
 	while ((bit = ffs(mask)) != 0) {
 		sc->sc_lpiconf.base[irqbase + bit - 1] |= GIC_LPICONF_Enable;
 		if (sc->sc_lpiconf_flush)
-			cpu_dcache_wb_range((vaddr_t)>sc_lpiconf.base[irqbase + bit - 1], 1);
+			gicv3_dcache_wb_range((vaddr_t)>sc_lpiconf.base[irqbase + bit - 1], 1);
 		mask &= ~__BIT(bit - 1);
 	}
 
@@ -539,7 +546,7 @@ gicv3_lpi_block_irqs(struct pic_softc *p
 	while ((bit = ffs(mask)) != 0) {
 		sc->sc_lpiconf.base[irqbase + bit - 1] &= ~GIC_LPICONF_Enable;
 		if (sc->sc_lpiconf_flush)
-			cpu_dcache_wb_range((vaddr_t)>sc_lpiconf.base[irqbase + bit - 1], 1);
+			gicv3_dcache_wb_range((vaddr_t)>sc_lpiconf.base[irqbase + bit - 1], 1);
 		mask &= ~__BIT(bit - 1);
 	}
 
@@ -555,7 +562,7 @@ gicv3_lpi_establish_irq(struct pic_softc
 	sc->sc_lpiconf.base[is->is_irq] = IPL_TO_PRIORITY(sc, is->is_ipl) | GIC_LPICONF_Res1;
 
 	if (sc->sc_lpiconf_flush)
-		cpu_dcache_wb_range((vaddr_t)>sc_lpiconf.base[is->is_irq], 1);
+		gicv3_dcache_wb_range((vaddr_t)>sc_lpiconf.base[is->is_irq], 1);
 	else
 		dsb(ishst);
 }



CVS commit: src/usr.bin/make/unit-tests

2020-12-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Dec 22 08:57:23 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: opt-file.mk

Log Message:
make(1): fix comment in test about null bytes in makefiles


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/make/unit-tests/opt-file.mk

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

Modified files:

Index: src/usr.bin/make/unit-tests/opt-file.mk
diff -u src/usr.bin/make/unit-tests/opt-file.mk:1.10 src/usr.bin/make/unit-tests/opt-file.mk:1.11
--- src/usr.bin/make/unit-tests/opt-file.mk:1.10	Tue Dec 22 08:51:30 2020
+++ src/usr.bin/make/unit-tests/opt-file.mk	Tue Dec 22 08:57:23 2020
@@ -1,4 +1,4 @@
-# $NetBSD: opt-file.mk,v 1.10 2020/12/22 08:51:30 rillig Exp $
+# $NetBSD: opt-file.mk,v 1.11 2020/12/22 08:57:23 rillig Exp $
 #
 # Tests for the -f command line option.
 
@@ -54,9 +54,9 @@ line-with-trailing-whitespace: .PHONY
 	@${MAKE} -r -f opt-file-trailing-whitespace -V VAR
 	@rm opt-file-trailing-whitespace
 
-# If a file contains null bytes, the rest of the line is skipped, and parsing
-# continues in the next line.  Throughout the history of make, the behavior
-# has changed several times, sometimes knowingly, sometimes by accident.
+# If a makefile contains null bytes, it is an error.  Throughout the history
+# of make, the behavior has changed several times, sometimes intentionally,
+# sometimes by accident.
 #
 #	echo 'VAR=value' | tr 'l' '\0' > zero-byte.in
 #	printf '%s\n' 'all:' ': VAR=${VAR:Q}' >> zero-byte.in



CVS commit: src/usr.bin/make

2020-12-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Dec 22 08:51:30 UTC 2020

Modified Files:
src/usr.bin/make: parse.c
src/usr.bin/make/unit-tests: opt-file.exp opt-file.mk

Log Message:
make(1): re-add improved assertion in ParseGetLine


To generate a diff of this commit:
cvs rdiff -u -r1.513 -r1.514 src/usr.bin/make/parse.c
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/opt-file.exp
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/opt-file.mk

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

Modified files:

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.513 src/usr.bin/make/parse.c:1.514
--- src/usr.bin/make/parse.c:1.513	Tue Dec 22 08:31:13 2020
+++ src/usr.bin/make/parse.c	Tue Dec 22 08:51:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.513 2020/12/22 08:31:13 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.514 2020/12/22 08:51:30 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -117,7 +117,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.513 2020/12/22 08:31:13 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.514 2020/12/22 08:51:30 rillig Exp $");
 
 /* types and constants */
 
@@ -2840,7 +2840,7 @@ ParseGetLine(GetLineMode mode)
 		}
 
 		/* We now have a line of data */
-		/* TODO: Remove line_end, it's not necessary here. */
+		assert(ch_isspace(*line_end));
 		*line_end = '\0';
 
 		if (mode == GLM_FOR_BODY)

Index: src/usr.bin/make/unit-tests/opt-file.exp
diff -u src/usr.bin/make/unit-tests/opt-file.exp:1.6 src/usr.bin/make/unit-tests/opt-file.exp:1.7
--- src/usr.bin/make/unit-tests/opt-file.exp:1.6	Tue Dec 22 08:05:08 2020
+++ src/usr.bin/make/unit-tests/opt-file.exp	Tue Dec 22 08:51:30 2020
@@ -1,5 +1,6 @@
 value
 value
+line-with-trailing-whitespace
 make: "(stdin)" line 1: Zero byte read from file
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests

Index: src/usr.bin/make/unit-tests/opt-file.mk
diff -u src/usr.bin/make/unit-tests/opt-file.mk:1.9 src/usr.bin/make/unit-tests/opt-file.mk:1.10
--- src/usr.bin/make/unit-tests/opt-file.mk:1.9	Tue Dec 22 08:23:12 2020
+++ src/usr.bin/make/unit-tests/opt-file.mk	Tue Dec 22 08:51:30 2020
@@ -1,4 +1,4 @@
-# $NetBSD: opt-file.mk,v 1.9 2020/12/22 08:23:12 rillig Exp $
+# $NetBSD: opt-file.mk,v 1.10 2020/12/22 08:51:30 rillig Exp $
 #
 # Tests for the -f command line option.
 
@@ -7,6 +7,7 @@
 all: .PHONY
 all: file-ending-in-backslash
 all: file-ending-in-backslash-mmap
+all: line-with-trailing-whitespace
 all: file-containing-null-byte
 
 # Passing '-' as the filename reads from stdin.  This is unusual but possible.
@@ -45,6 +46,14 @@ file-ending-in-backslash-mmap: .PHONY
 	@${MAKE} -r -f opt-file-backslash -V VAR
 	@rm opt-file-backslash
 
+# Since parse.c 1.511 from 2020-12-22, an assertion in ParseGetLine failed
+# for lines that contained trailing whitespace.  Worked around in parse.c
+# 1.513, properly fixed in parse.c 1.514.
+line-with-trailing-whitespace: .PHONY
+	@printf '%s' 'VAR=$@ ' > opt-file-trailing-whitespace
+	@${MAKE} -r -f opt-file-trailing-whitespace -V VAR
+	@rm opt-file-trailing-whitespace
+
 # If a file contains null bytes, the rest of the line is skipped, and parsing
 # continues in the next line.  Throughout the history of make, the behavior
 # has changed several times, sometimes knowingly, sometimes by accident.



CVS commit: src/usr.bin/make

2020-12-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Dec 22 08:31:13 UTC 2020

Modified Files:
src/usr.bin/make: parse.c

Log Message:
make(1): remove assertion about lines ending with '\n'

It fails the NetBSD build.sh.


To generate a diff of this commit:
cvs rdiff -u -r1.512 -r1.513 src/usr.bin/make/parse.c

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

Modified files:

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.512 src/usr.bin/make/parse.c:1.513
--- src/usr.bin/make/parse.c:1.512	Tue Dec 22 08:10:39 2020
+++ src/usr.bin/make/parse.c	Tue Dec 22 08:31:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.512 2020/12/22 08:10:39 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.513 2020/12/22 08:31:13 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -117,7 +117,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.512 2020/12/22 08:10:39 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.513 2020/12/22 08:31:13 rillig Exp $");
 
 /* types and constants */
 
@@ -2841,7 +2841,6 @@ ParseGetLine(GetLineMode mode)
 
 		/* We now have a line of data */
 		/* TODO: Remove line_end, it's not necessary here. */
-		assert(*line_end == '\n');
 		*line_end = '\0';
 
 		if (mode == GLM_FOR_BODY)



CVS commit: src/usr.bin/make/unit-tests

2020-12-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Dec 22 08:23:12 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: opt-file.mk

Log Message:
make(1): clean up after test opt-file


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/opt-file.mk

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

Modified files:

Index: src/usr.bin/make/unit-tests/opt-file.mk
diff -u src/usr.bin/make/unit-tests/opt-file.mk:1.8 src/usr.bin/make/unit-tests/opt-file.mk:1.9
--- src/usr.bin/make/unit-tests/opt-file.mk:1.8	Tue Dec 22 08:05:08 2020
+++ src/usr.bin/make/unit-tests/opt-file.mk	Tue Dec 22 08:23:12 2020
@@ -1,4 +1,4 @@
-# $NetBSD: opt-file.mk,v 1.8 2020/12/22 08:05:08 rillig Exp $
+# $NetBSD: opt-file.mk,v 1.9 2020/12/22 08:23:12 rillig Exp $
 #
 # Tests for the -f command line option.
 
@@ -43,6 +43,7 @@ file-ending-in-backslash: .PHONY
 file-ending-in-backslash-mmap: .PHONY
 	@printf '%s' 'VAR=value\' > opt-file-backslash
 	@${MAKE} -r -f opt-file-backslash -V VAR
+	@rm opt-file-backslash
 
 # If a file contains null bytes, the rest of the line is skipped, and parsing
 # continues in the next line.  Throughout the history of make, the behavior



CVS commit: src/usr.bin/make

2020-12-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Dec 22 08:10:39 UTC 2020

Modified Files:
src/usr.bin/make: parse.c

Log Message:
make(1): remove needless assignment to line_end in ParseGetLine


To generate a diff of this commit:
cvs rdiff -u -r1.511 -r1.512 src/usr.bin/make/parse.c

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

Modified files:

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.511 src/usr.bin/make/parse.c:1.512
--- src/usr.bin/make/parse.c:1.511	Tue Dec 22 08:05:08 2020
+++ src/usr.bin/make/parse.c	Tue Dec 22 08:10:39 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.511 2020/12/22 08:05:08 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.512 2020/12/22 08:10:39 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -117,7 +117,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.511 2020/12/22 08:05:08 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.512 2020/12/22 08:10:39 rillig Exp $");
 
 /* types and constants */
 
@@ -2853,10 +2853,8 @@ ParseGetLine(GetLineMode mode)
 	}
 
 	/* Brutally ignore anything after a non-escaped '#' in non-commands. */
-	if (firstComment != NULL && line[0] != '\t') {
-		line_end = firstComment;
-		*line_end = '\0';
-	}
+	if (firstComment != NULL && line[0] != '\t')
+		*firstComment = '\0';
 
 	/* If we didn't see a '\\' then the in-situ data is fine. */
 	if (firstBackslash == NULL)



CVS commit: src/usr.bin/make

2020-12-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Dec 22 08:05:08 UTC 2020

Modified Files:
src/usr.bin/make: parse.c
src/usr.bin/make/unit-tests: opt-file.exp opt-file.mk

Log Message:
make(1): fix assertion failure for files without trailing newline

Previously, mmapped files didn't always have the final newline added.
Only those that ended at a page boundary did.

This confused ParseRawLine, which assumed (and since parse.c 1.510 from
moments ago also asserted) that every line ends with a newline, which
allows the code to assume that after a backslash, there is at least one
other character in the buffer, thereby preventing an out-of-bounds read.

This bug had been there at least since parse.c 1.170 from 2010-12-25
04:57:07, maybe even earlier, I didn't check.

Now line_end always points to the trailing newline, which allows
ParseGetLine to overwrite that character to end the string.


To generate a diff of this commit:
cvs rdiff -u -r1.510 -r1.511 src/usr.bin/make/parse.c
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/opt-file.exp
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/opt-file.mk

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

Modified files:

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.510 src/usr.bin/make/parse.c:1.511
--- src/usr.bin/make/parse.c:1.510	Tue Dec 22 06:48:33 2020
+++ src/usr.bin/make/parse.c	Tue Dec 22 08:05:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.510 2020/12/22 06:48:33 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.511 2020/12/22 08:05:08 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -117,7 +117,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.510 2020/12/22 06:48:33 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.511 2020/12/22 08:05:08 rillig Exp $");
 
 /* types and constants */
 
@@ -466,13 +466,14 @@ loadedfile_mmap(struct loadedfile *lf, i
 	if (lf->buf == MAP_FAILED)
 		return FALSE;
 
-	if (lf->len == lf->maplen && lf->buf[lf->len - 1] != '\n') {
-		char *b = bmake_malloc(lf->len + 1);
-		b[lf->len] = '\n';
-		memcpy(b, lf->buf, lf->len++);
-		munmap(lf->buf, lf->maplen);
-		lf->maplen = 0;
-		lf->buf = b;
+	if (lf->len > 0 && lf->buf[lf->len - 1] != '\n') {
+		if (lf->len == lf->maplen) {
+			char *b = bmake_malloc(lf->len + 1);
+			memcpy(b, lf->buf, lf->len);
+			munmap(lf->buf, lf->maplen);
+			lf->maplen = 0;
+		}
+		lf->buf[lf->len++] = '\n';
 	}
 
 	return TRUE;
@@ -2687,19 +2688,15 @@ ParseRawLine(IFile *curFile, char **out_
 		if (ch == '\\') {
 			if (firstBackslash == NULL)
 firstBackslash = p;
-			/*
-			 * FIXME: In opt-file.mk, this command succeeds:
-			 *	printf '%s' 'V=v\' | make -r -f -
-			 * Using an intermediate file fails though:
-			 *	printf '%s' 'V=v\' > backslash
-			 *	make -r -f backslash
-			 *
-			 * In loadedfile_mmap, the trailing newline is not
-			 * added in every case, only if the file ends at a
-			 * page boundary.
-			 */
-			if (p[1] == '\n')
+			if (p[1] == '\n') {
 curFile->lineno++;
+if (p + 2 == curFile->buf_end) {
+	line_end = p;
+	*line_end = '\n';
+	p += 2;
+	continue;
+}
+			}
 			p += 2;
 			line_end = p;
 			assert(p <= curFile->buf_end);
@@ -2843,12 +2840,8 @@ ParseGetLine(GetLineMode mode)
 		}
 
 		/* We now have a line of data */
-		/*
-		 * FIXME: undefined behavior since line_end points right
-		 * after the allocated buffer. This becomes apparent when
-		 * using a strict malloc implementation that adds canaries
-		 * before and after the allocated space.
-		 */
+		/* TODO: Remove line_end, it's not necessary here. */
+		assert(*line_end == '\n');
 		*line_end = '\0';
 
 		if (mode == GLM_FOR_BODY)

Index: src/usr.bin/make/unit-tests/opt-file.exp
diff -u src/usr.bin/make/unit-tests/opt-file.exp:1.5 src/usr.bin/make/unit-tests/opt-file.exp:1.6
--- src/usr.bin/make/unit-tests/opt-file.exp:1.5	Mon Dec  7 00:53:30 2020
+++ src/usr.bin/make/unit-tests/opt-file.exp	Tue Dec 22 08:05:08 2020
@@ -1,4 +1,5 @@
 value
+value
 make: "(stdin)" line 1: Zero byte read from file
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests

Index: src/usr.bin/make/unit-tests/opt-file.mk
diff -u src/usr.bin/make/unit-tests/opt-file.mk:1.7 src/usr.bin/make/unit-tests/opt-file.mk:1.8
--- src/usr.bin/make/unit-tests/opt-file.mk:1.7	Sun Dec  6 20:55:30 2020
+++ src/usr.bin/make/unit-tests/opt-file.mk	Tue Dec 22 08:05:08 2020
@@ -1,4 +1,4 @@
-# $NetBSD: opt-file.mk,v 1.7 2020/12/06 20:55:30 rillig Exp $
+# $NetBSD: opt-file.mk,v 1.8 2020/12/22 08:05:08 rillig Exp $
 #
 # Tests for the -f command line option.
 
@@ -6,6 +6,7 @@
 
 all: .PHONY
 all: file-ending-in-backslash
+all: file-ending-in-backslash-mmap
 all: file-containing-null-byte
 
 # Passing '-' as the filename reads from stdin.  This is unusual but possible.
@@ -35,6 +36,14 @@ file-ending-in-backslash: .PHONY