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

2021-08-10 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Aug 10 17:12:31 UTC 2021

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

Log Message:
Make gic_splfuncs optional and disable it by default until it has had
more testing.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/arm/cortex/files.cortex
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/arm/cortex/gic.c
cvs rdiff -u -r1.45 -r1.46 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/files.cortex
diff -u src/sys/arch/arm/cortex/files.cortex:1.15 src/sys/arch/arm/cortex/files.cortex:1.16
--- src/sys/arch/arm/cortex/files.cortex:1.15	Tue Aug 10 15:33:09 2021
+++ src/sys/arch/arm/cortex/files.cortex	Tue Aug 10 17:12:31 2021
@@ -1,4 +1,4 @@
-# $NetBSD: files.cortex,v 1.15 2021/08/10 15:33:09 jmcneill Exp $
+# $NetBSD: files.cortex,v 1.16 2021/08/10 17:12:31 jmcneill Exp $
 
 defflag opt_cpu_in_cksum.h			NEON_IN_CKSUM
 
@@ -11,16 +11,16 @@ device	armperiph: mpcorebus
 attach	armperiph at mainbus
 file	arch/arm/cortex/armperiph.c		armperiph
 
-define	gic_splfuncs
+defflag	opt_gic.hGIC_SPLFUNCS
 file	arch/arm/cortex/gic_splfuncs.c		gic_splfuncs
 
 # ARM Generic Interrupt Controller (initially on Cortex-A9)
-device	armgic: pic, pic_splfuncs, gic_splfuncs
+device	armgic: pic, pic_splfuncs
 attach	armgic at mpcorebus
 file	arch/arm/cortex/gic.c			armgic
 
 # ARM Generic Interrupt Controller v3+
-device	gicvthree: pic, pic_splfuncs, gic_splfuncs
+device	gicvthree: pic, pic_splfuncs
 file	arch/arm/cortex/gicv3.c			gicvthree
 file	arch/arm/cortex/gicv3_its.c		gicvthree & pci & __have_pci_msi_msix
 

Index: src/sys/arch/arm/cortex/gic.c
diff -u src/sys/arch/arm/cortex/gic.c:1.48 src/sys/arch/arm/cortex/gic.c:1.49
--- src/sys/arch/arm/cortex/gic.c:1.48	Tue Aug 10 15:33:09 2021
+++ src/sys/arch/arm/cortex/gic.c	Tue Aug 10 17:12:31 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: gic.c,v 1.48 2021/08/10 15:33:09 jmcneill Exp $	*/
+/*	$NetBSD: gic.c,v 1.49 2021/08/10 17:12:31 jmcneill Exp $	*/
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -30,11 +30,12 @@
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
+#include "opt_gic.h"
 
 #define _INTR_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gic.c,v 1.48 2021/08/10 15:33:09 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gic.c,v 1.49 2021/08/10 17:12:31 jmcneill Exp $");
 
 #include 
 #include 
@@ -50,9 +51,12 @@ __KERNEL_RCSID(0, "$NetBSD: gic.c,v 1.48
 #include 
 
 #include 
-#include 
 #include 
 
+#ifdef GIC_SPLFUNCS
+#include 
+#endif
+
 void armgic_irq_handler(void *);
 
 #define	ARMGIC_SGI_IPIBASE	0
@@ -730,7 +734,9 @@ armgic_attach(device_t parent, device_t 
 	"%u SGIs\n",  priorities, sc->sc_gic_lines - ppis - sgis, ppis,
 	sgis);
 
+#ifdef GIC_SPLFUNCS
 	gic_spl_init();
+#endif
 }
 
 CFATTACH_DECL_NEW(armgic, 0,

Index: src/sys/arch/arm/cortex/gicv3.c
diff -u src/sys/arch/arm/cortex/gicv3.c:1.45 src/sys/arch/arm/cortex/gicv3.c:1.46
--- src/sys/arch/arm/cortex/gicv3.c:1.45	Tue Aug 10 15:33:09 2021
+++ src/sys/arch/arm/cortex/gicv3.c	Tue Aug 10 17:12:31 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: gicv3.c,v 1.45 2021/08/10 15:33:09 jmcneill Exp $ */
+/* $NetBSD: gicv3.c,v 1.46 2021/08/10 17:12:31 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,11 +27,12 @@
  */
 
 #include "opt_multiprocessor.h"
+#include "opt_gic.h"
 
 #define	_INTR_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gicv3.c,v 1.45 2021/08/10 15:33:09 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gicv3.c,v 1.46 2021/08/10 17:12:31 jmcneill Exp $");
 
 #include 
 #include 
@@ -51,7 +52,10 @@ __KERNEL_RCSID(0, "$NetBSD: gicv3.c,v 1.
 
 #include 
 #include 
+
+#ifdef GIC_SPLFUNCS
 #include 
+#endif
 
 #define	PICTOSOFTC(pic)	\
 	((void *)((uintptr_t)(pic) - offsetof(struct gicv3_softc, sc_pic)))
@@ -952,7 +956,9 @@ gicv3_init(struct gicv3_softc *sc)
 #endif
 #endif
 
+#ifdef GIC_SPLFUNCS
 	gic_spl_init();
+#endif
 
 	return 0;
 }



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

2021-08-10 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Aug 10 16:52:43 UTC 2021

Modified Files:
src/sys/arch/arm/dts: sun50i-a64-sopine-baseboard.dts

Log Message:
Enable DVFS


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/dts/sun50i-a64-sopine-baseboard.dts

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/dts/sun50i-a64-sopine-baseboard.dts
diff -u src/sys/arch/arm/dts/sun50i-a64-sopine-baseboard.dts:1.4 src/sys/arch/arm/dts/sun50i-a64-sopine-baseboard.dts:1.5
--- src/sys/arch/arm/dts/sun50i-a64-sopine-baseboard.dts:1.4	Wed Jun 30 06:24:02 2021
+++ src/sys/arch/arm/dts/sun50i-a64-sopine-baseboard.dts	Tue Aug 10 16:52:43 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sun50i-a64-sopine-baseboard.dts,v 1.4 2021/06/30 06:24:02 skrll Exp $ */
+/* $NetBSD: sun50i-a64-sopine-baseboard.dts,v 1.5 2021/08/10 16:52:43 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -37,3 +37,15 @@
 	status = "okay";
 };
 
+&cpu0 {
+cpu-supply = <®_dcdc2>;
+operating-points = <
+/* kHzuV */
+1152000 130
+1104000 126
+1008000 120
+816000  108
+648000  104
+408000  100
+>;
+};



CVS commit: src/doc

2021-08-10 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Aug 10 16:45:35 UTC 2021

Modified Files:
src/doc: CHANGES

Log Message:
evbarm: Improvements in interrupt handling on Arm GIC v2 and v3 systems
resulting in better network and storage performance.


To generate a diff of this commit:
cvs rdiff -u -r1.2818 -r1.2819 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.2818 src/doc/CHANGES:1.2819
--- src/doc/CHANGES:1.2818	Sun Aug  8 12:35:43 2021
+++ src/doc/CHANGES	Tue Aug 10 16:45:35 2021
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2818 $>
+# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2819 $>
 #
 #
 # [Note: This file does not mention every change made to the NetBSD source tree.
@@ -396,3 +396,6 @@ Changes from NetBSD 9.0 to NetBSD 10.0:
 		on the Raspberry Pi 4. [jmcneill 20210808]
 	evbarm: Add support for shared ACPI platform interrupts.
 		[jmcneill 20210808]
+	evbarm: Improvements in interrupt handling on Arm GIC v2 and v3 systems
+		resulting in better network and storage performance.
+		[jmcneill 20210810]



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

2021-08-10 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Aug 10 15:33:09 UTC 2021

Modified Files:
src/sys/arch/arm/cortex: files.cortex gic.c gicv3.c
Added Files:
src/sys/arch/arm/cortex: gic_splfuncs.c gic_splfuncs.h

Log Message:
Use custom spl funcs for GIC and avoid unnecessary pmr register accesses
in splx.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/arm/cortex/files.cortex
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/arm/cortex/gic.c
cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/cortex/gic_splfuncs.c \
src/sys/arch/arm/cortex/gic_splfuncs.h
cvs rdiff -u -r1.44 -r1.45 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/files.cortex
diff -u src/sys/arch/arm/cortex/files.cortex:1.14 src/sys/arch/arm/cortex/files.cortex:1.15
--- src/sys/arch/arm/cortex/files.cortex:1.14	Tue Sep 29 19:58:50 2020
+++ src/sys/arch/arm/cortex/files.cortex	Tue Aug 10 15:33:09 2021
@@ -1,4 +1,4 @@
-# $NetBSD: files.cortex,v 1.14 2020/09/29 19:58:50 jmcneill Exp $
+# $NetBSD: files.cortex,v 1.15 2021/08/10 15:33:09 jmcneill Exp $
 
 defflag opt_cpu_in_cksum.h			NEON_IN_CKSUM
 
@@ -11,13 +11,16 @@ device	armperiph: mpcorebus
 attach	armperiph at mainbus
 file	arch/arm/cortex/armperiph.c		armperiph
 
+define	gic_splfuncs
+file	arch/arm/cortex/gic_splfuncs.c		gic_splfuncs
+
 # ARM Generic Interrupt Controller (initially on Cortex-A9)
-device	armgic: pic, pic_splfuncs
+device	armgic: pic, pic_splfuncs, gic_splfuncs
 attach	armgic at mpcorebus
 file	arch/arm/cortex/gic.c			armgic
 
 # ARM Generic Interrupt Controller v3+
-device	gicvthree: pic, pic_splfuncs
+device	gicvthree: pic, pic_splfuncs, gic_splfuncs
 file	arch/arm/cortex/gicv3.c			gicvthree
 file	arch/arm/cortex/gicv3_its.c		gicvthree & pci & __have_pci_msi_msix
 

Index: src/sys/arch/arm/cortex/gic.c
diff -u src/sys/arch/arm/cortex/gic.c:1.47 src/sys/arch/arm/cortex/gic.c:1.48
--- src/sys/arch/arm/cortex/gic.c:1.47	Sun Mar 28 09:11:38 2021
+++ src/sys/arch/arm/cortex/gic.c	Tue Aug 10 15:33:09 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: gic.c,v 1.47 2021/03/28 09:11:38 skrll Exp $	*/
+/*	$NetBSD: gic.c,v 1.48 2021/08/10 15:33:09 jmcneill Exp $	*/
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -34,7 +34,7 @@
 #define _INTR_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gic.c,v 1.47 2021/03/28 09:11:38 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gic.c,v 1.48 2021/08/10 15:33:09 jmcneill Exp $");
 
 #include 
 #include 
@@ -50,6 +50,7 @@ __KERNEL_RCSID(0, "$NetBSD: gic.c,v 1.47
 #include 
 
 #include 
+#include 
 #include 
 
 void armgic_irq_handler(void *);
@@ -224,11 +225,10 @@ armgic_set_priority(struct pic_softc *pi
 	struct armgic_softc * const sc = PICTOSOFTC(pic);
 	struct cpu_info * const ci = curcpu();
 
-	const uint32_t priority = armgic_ipl_to_priority(ipl);
-	if (priority > ci->ci_hwpl) {
+	if (ipl < ci->ci_hwpl) {
 		/* Lowering priority mask */
-		ci->ci_hwpl = priority;
-		gicc_write(sc, GICC_PMR, priority);
+		ci->ci_hwpl = ipl;
+		gicc_write(sc, GICC_PMR, armgic_ipl_to_priority(ipl));
 	}
 }
 
@@ -327,10 +327,9 @@ armgic_irq_handler(void *tf)
 
 	ci->ci_data.cpu_nintr++;
 
-	const uint32_t priority = armgic_ipl_to_priority(old_ipl);
-	if (ci->ci_hwpl != priority) {
-		ci->ci_hwpl = priority;
-		gicc_write(sc, GICC_PMR, priority);
+	if (ci->ci_hwpl != old_ipl) {
+		ci->ci_hwpl = old_ipl;
+		gicc_write(sc, GICC_PMR, armgic_ipl_to_priority(old_ipl));
 		if (old_ipl == IPL_HIGH) {
 			return;
 		}
@@ -545,7 +544,7 @@ armgic_cpu_init(struct pic_softc *pic, s
 			sc->sc_enabled_local);
 		}
 	}
-	ci->ci_hwpl = armgic_ipl_to_priority(ci->ci_cpl);
+	ci->ci_hwpl = ci->ci_cpl;
 	gicc_write(sc, GICC_PMR, armgic_ipl_to_priority(ci->ci_cpl));	// set PMR
 	gicc_write(sc, GICC_CTRL, GICC_CTRL_V1_Enable);	// enable interrupt
 	ENABLE_INTERRUPT();// allow IRQ exceptions
@@ -730,6 +729,8 @@ armgic_attach(device_t parent, device_t 
 	aprint_normal_dev(sc->sc_dev, "%u Priorities, %zu SPIs, %u PPIs, "
 	"%u SGIs\n",  priorities, sc->sc_gic_lines - ppis - sgis, ppis,
 	sgis);
+
+	gic_spl_init();
 }
 
 CFATTACH_DECL_NEW(armgic, 0,

Index: src/sys/arch/arm/cortex/gicv3.c
diff -u src/sys/arch/arm/cortex/gicv3.c:1.44 src/sys/arch/arm/cortex/gicv3.c:1.45
--- src/sys/arch/arm/cortex/gicv3.c:1.44	Sun Mar 28 11:13:24 2021
+++ src/sys/arch/arm/cortex/gicv3.c	Tue Aug 10 15:33:09 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: gicv3.c,v 1.44 2021/03/28 11:13:24 jmcneill Exp $ */
+/* $NetBSD: gicv3.c,v 1.45 2021/08/10 15:33:09 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -31,7 +31,7 @@
 #define	_INTR_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gicv3.c,v 1.44 2021/03/28 11:13:24 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gicv3.c,v 1.45 2021/08/10 15:33:09 jmcneill Exp $");
 
 #include 
 #include 
@@ -51,6 +51,7 @@ __KERNEL_RCSID(0, "$NetBSD: gic

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

2021-08-10 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Aug 10 15:31:55 UTC 2021

Modified Files:
src/sys/arch/arm/pic: pic_splfuncs.c picvar.h

Log Message:
arm: pic: allow overriding _splraise/_spllower/splx


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/arm/pic/pic_splfuncs.c
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/arm/pic/picvar.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/pic/pic_splfuncs.c
diff -u src/sys/arch/arm/pic/pic_splfuncs.c:1.20 src/sys/arch/arm/pic/pic_splfuncs.c:1.21
--- src/sys/arch/arm/pic/pic_splfuncs.c:1.20	Sat Mar 27 12:15:09 2021
+++ src/sys/arch/arm/pic/pic_splfuncs.c	Tue Aug 10 15:31:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pic_splfuncs.c,v 1.20 2021/03/27 12:15:09 jmcneill Exp $	*/
+/*	$NetBSD: pic_splfuncs.c,v 1.21 2021/08/10 15:31:55 jmcneill Exp $	*/
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -28,7 +28,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pic_splfuncs.c,v 1.20 2021/03/27 12:15:09 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pic_splfuncs.c,v 1.21 2021/08/10 15:31:55 jmcneill Exp $");
 
 #define _INTR_PRIVATE
 #include 
@@ -46,9 +46,16 @@ __KERNEL_RCSID(0, "$NetBSD: pic_splfuncs
 
 #include 
 
+static int	pic_default_splraise(int);
+static int	pic_default_spllower(int);
+static void	pic_default_splx(int);
+
+int (*_splraise)(int) = pic_default_splraise;
+int (*_spllower)(int) = pic_default_spllower;
+void (*splx)(int) = pic_default_splx;
 
-int
-_splraise(int newipl)
+static int
+pic_default_splraise(int newipl)
 {
 	struct cpu_info * const ci = curcpu();
 	const int oldipl = ci->ci_cpl;
@@ -58,8 +65,9 @@ _splraise(int newipl)
 	}
 	return oldipl;
 }
-int
-_spllower(int newipl)
+
+static int
+pic_default_spllower(int newipl)
 {
 	struct cpu_info * const ci = curcpu();
 	const int oldipl = ci->ci_cpl;
@@ -76,8 +84,8 @@ _spllower(int newipl)
 	return oldipl;
 }
 
-void
-splx(int savedipl)
+static void
+pic_default_splx(int savedipl)
 {
 	struct cpu_info * const ci = curcpu();
 	KASSERT(savedipl < NIPL);

Index: src/sys/arch/arm/pic/picvar.h
diff -u src/sys/arch/arm/pic/picvar.h:1.34 src/sys/arch/arm/pic/picvar.h:1.35
--- src/sys/arch/arm/pic/picvar.h:1.34	Sat Mar 27 12:15:09 2021
+++ src/sys/arch/arm/pic/picvar.h	Tue Aug 10 15:31:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: picvar.h,v 1.34 2021/03/27 12:15:09 jmcneill Exp $	*/
+/*	$NetBSD: picvar.h,v 1.35 2021/08/10 15:31:55 jmcneill Exp $	*/
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -40,9 +40,10 @@
 
 typedef uint32_t	intr_handle_t;		/* for ACPI */
 
-int	_splraise(int);
-int	_spllower(int);
-void	splx(int);
+extern int	(*_splraise)(int);
+extern int	(*_spllower)(int);
+extern void	(*splx)(int);
+
 const char *
 	intr_typename(int);
 



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

2021-08-10 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Aug 10 15:31:38 UTC 2021

Modified Files:
src/sys/arch/arm/acpi: acpipchb.c

Log Message:
Disable MSI if the linux,pcie-nomsi flag is present


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/arm/acpi/acpipchb.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/acpi/acpipchb.c
diff -u src/sys/arch/arm/acpi/acpipchb.c:1.27 src/sys/arch/arm/acpi/acpipchb.c:1.28
--- src/sys/arch/arm/acpi/acpipchb.c:1.27	Sat Aug  7 21:27:53 2021
+++ src/sys/arch/arm/acpi/acpipchb.c	Tue Aug 10 15:31:38 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: acpipchb.c,v 1.27 2021/08/07 21:27:53 jmcneill Exp $ */
+/* $NetBSD: acpipchb.c,v 1.28 2021/08/10 15:31:38 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpipchb.c,v 1.27 2021/08/07 21:27:53 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpipchb.c,v 1.28 2021/08/10 15:31:38 jmcneill Exp $");
 
 #include 
 #include 
@@ -123,7 +123,7 @@ acpipchb_attach(device_t parent, device_
 	struct acpipchb_softc * const sc = device_private(self);
 	struct acpi_attach_args *aa = aux;
 	struct pcibus_attach_args pba;
-	ACPI_INTEGER seg;
+	ACPI_INTEGER seg, nomsi;
 	ACPI_STATUS rv;
 	uint16_t bus_start;
 
@@ -148,6 +148,11 @@ acpipchb_attach(device_t parent, device_
 		seg = 0;
 	}
 
+	if (ACPI_FAILURE(acpi_dsd_integer(sc->sc_handle, "linux,pcie-nomsi",
+	&nomsi))) {
+		nomsi = 0;
+	}
+
 	aprint_naive("\n");
 	aprint_normal(": PCI Express Host Bridge\n");
 
@@ -156,6 +161,9 @@ acpipchb_attach(device_t parent, device_
 	memset(&pba, 0, sizeof(pba));
 	pba.pba_flags = aa->aa_pciflags &
 			~(PCI_FLAGS_MEM_OKAY | PCI_FLAGS_IO_OKAY);
+	if (nomsi) {
+		pba.pba_flags &= ~(PCI_FLAGS_MSI_OKAY | PCI_FLAGS_MSIX_OKAY);
+	}
 	pba.pba_memt = 0;
 	pba.pba_iot = 0;
 	pba.pba_dmat = aa->aa_dmat;



CVS commit: src/sys/dev/ic

2021-08-10 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Aug 10 15:28:44 UTC 2021

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

Log Message:
Clear IFF_OACTIVE in genet_txintr (bug introduced in r1.8) and don't
sync DMA maps with size 0.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/ic/bcmgenet.c

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

Modified files:

Index: src/sys/dev/ic/bcmgenet.c
diff -u src/sys/dev/ic/bcmgenet.c:1.9 src/sys/dev/ic/bcmgenet.c:1.10
--- src/sys/dev/ic/bcmgenet.c:1.9	Mon May  3 10:28:26 2021
+++ src/sys/dev/ic/bcmgenet.c	Tue Aug 10 15:28:44 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: bcmgenet.c,v 1.9 2021/05/03 10:28:26 rin Exp $ */
+/* $NetBSD: bcmgenet.c,v 1.10 2021/08/10 15:28:44 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2020 Jared McNeill 
@@ -34,7 +34,7 @@
 #include "opt_ddb.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bcmgenet.c,v 1.9 2021/05/03 10:28:26 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcmgenet.c,v 1.10 2021/08/10 15:28:44 jmcneill Exp $");
 
 #include 
 #include 
@@ -726,9 +726,11 @@ genet_rxintr(struct genet_softc *sc, int
 		}
 
 		/* unload map before it gets loaded in setup_rxbuf */
-		bus_dmamap_sync(sc->sc_rx.buf_tag, sc->sc_rx.buf_map[index].map,
-		0, sc->sc_rx.buf_map[index].map->dm_mapsize,
-		BUS_DMASYNC_POSTREAD);
+		if (sc->sc_rx.buf_map[index].map->dm_mapsize > 0) {
+			bus_dmamap_sync(sc->sc_rx.buf_tag, sc->sc_rx.buf_map[index].map,
+			0, sc->sc_rx.buf_map[index].map->dm_mapsize,
+			BUS_DMASYNC_POSTREAD);
+		}
 		bus_dmamap_unload(sc->sc_rx.buf_tag, sc->sc_rx.buf_map[index].map);
 		sc->sc_rx.buf_map[index].mbuf = NULL;
 
@@ -778,15 +780,18 @@ genet_txintr(struct genet_softc *sc, int
 		bmap = &sc->sc_tx.buf_map[i];
 		if (bmap->mbuf != NULL) {
 			/* XXX first segment already unloads */
-			bus_dmamap_sync(sc->sc_tx.buf_tag, bmap->map,
-			0, bmap->map->dm_mapsize,
-			BUS_DMASYNC_POSTWRITE);
+			if (bmap->map->dm_mapsize > 0) {
+bus_dmamap_sync(sc->sc_tx.buf_tag, bmap->map,
+0, bmap->map->dm_mapsize,
+BUS_DMASYNC_POSTWRITE);
+			}
 			bus_dmamap_unload(sc->sc_tx.buf_tag, bmap->map);
 			m_freem(bmap->mbuf);
 			bmap->mbuf = NULL;
 			++pkts;
 		}
 
+		ifp->if_flags &= ~IFF_OACTIVE;
 		i = TX_NEXT(i);
 		sc->sc_tx.cidx = (sc->sc_tx.cidx + 1) & 0x;
 	}



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

2021-08-08 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Aug  8 18:55:12 UTC 2021

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

Log Message:
Adjust register base and size


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/broadcom/bcm2835_com_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/arm/broadcom/bcm2835_com_acpi.c
diff -u src/sys/arch/arm/broadcom/bcm2835_com_acpi.c:1.1 src/sys/arch/arm/broadcom/bcm2835_com_acpi.c:1.2
--- src/sys/arch/arm/broadcom/bcm2835_com_acpi.c:1.1	Sun Aug  8 18:43:21 2021
+++ src/sys/arch/arm/broadcom/bcm2835_com_acpi.c	Sun Aug  8 18:55:12 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: bcm2835_com_acpi.c,v 1.1 2021/08/08 18:43:21 jmcneill Exp $ */
+/* $NetBSD: bcm2835_com_acpi.c,v 1.2 2021/08/08 18:55:12 jmcneill Exp $ */
 
 /*
  * Copyright (c) 2021 Jared McNeill 
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_com_acpi.c,v 1.1 2021/08/08 18:43:21 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_com_acpi.c,v 1.2 2021/08/08 18:55:12 jmcneill Exp $");
 
 #include 
 #include 
@@ -100,8 +100,8 @@ bcmcom_acpi_attach(device_t parent, devi
 	}
 
 	iot = aa->aa_memt;
-	base = mem->ar_base;
-	size = mem->ar_length;
+	base = mem->ar_base + 0x40;
+	size = mem->ar_length - 0x40;
 
 	irq = acpi_res_irq(&res, 0);
 	if (irq == NULL) {



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

2021-08-08 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Aug  8 18:43:21 UTC 2021

Modified Files:
src/sys/arch/arm/broadcom: files.bcm2835
Added Files:
src/sys/arch/arm/broadcom: bcm2835_com_acpi.c

Log Message:
broadcom: ACPI: Add support for mini UART in ACPI mode.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/broadcom/bcm2835_com_acpi.c
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/arm/broadcom/files.bcm2835

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/files.bcm2835
diff -u src/sys/arch/arm/broadcom/files.bcm2835:1.41 src/sys/arch/arm/broadcom/files.bcm2835:1.42
--- src/sys/arch/arm/broadcom/files.bcm2835:1.41	Sun Aug  8 10:32:26 2021
+++ src/sys/arch/arm/broadcom/files.bcm2835	Sun Aug  8 18:43:21 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: files.bcm2835,v 1.41 2021/08/08 10:32:26 jmcneill Exp $
+#	$NetBSD: files.bcm2835,v 1.42 2021/08/08 18:43:21 jmcneill Exp $
 #
 # Configuration info for Broadcom BCM2835 ARM Peripherals
 #
@@ -60,6 +60,11 @@ file	arch/arm/broadcom/bcm2835_aux.c		bc
 attach	com at fdt with bcmcom
 file	arch/arm/broadcom/bcm2835_com.c		bcmcom
 
+ifdef acpinodebus
+attach	com at acpinodebus with bcmcom_acpi
+file	arch/arm/broadcom/bcm2835_com_acpi.c	bcmcom_acpi
+endif
+
 # External Mass Media Controller (BCM2835_EMMC_BASE)
 attach	sdhc at fdt with bcmemmc
 file	arch/arm/broadcom/bcm2835_emmc.c	bcmemmc

Added files:

Index: src/sys/arch/arm/broadcom/bcm2835_com_acpi.c
diff -u /dev/null src/sys/arch/arm/broadcom/bcm2835_com_acpi.c:1.1
--- /dev/null	Sun Aug  8 18:43:21 2021
+++ src/sys/arch/arm/broadcom/bcm2835_com_acpi.c	Sun Aug  8 18:43:21 2021
@@ -0,0 +1,168 @@
+/* $NetBSD: bcm2835_com_acpi.c,v 1.1 2021/08/08 18:43:21 jmcneill Exp $ */
+
+/*
+ * Copyright (c) 2021 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. The name of the author may not be used to endorse or promote products
+ *derived from this software without specific prior written permission.
+ *
+ * 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 
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_com_acpi.c,v 1.1 2021/08/08 18:43:21 jmcneill Exp $");
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+
+static int	bcmcom_acpi_match(device_t, cfdata_t , void *);
+static void	bcmcom_acpi_attach(device_t, device_t, void *);
+
+static u_int	bcmcom_acpi_get_clockrate(device_t);
+
+struct vcmbox_clockrate_request {
+	struct vcprop_buffer_hdr	vb_hdr;
+	struct vcprop_tag_clockrate	vbt_clockrate;
+	struct vcprop_tag end;
+} __packed;
+
+CFATTACH_DECL_NEW(bcmcom_acpi, sizeof(struct com_softc), bcmcom_acpi_match,
+bcmcom_acpi_attach, NULL, NULL);
+
+static const struct device_compatible_entry compat_data[] = {
+	{ .compat = "BCM2836",		.value = COM_TYPE_BCMAUXUART },
+	DEVICE_COMPAT_EOL
+};
+
+static int
+bcmcom_acpi_match(device_t parent, cfdata_t match, void *aux)
+{
+	struct acpi_attach_args *aa = aux;
+
+	return acpi_compatible_match(aa, compat_data);
+}
+
+static void
+bcmcom_acpi_attach(device_t parent, device_t self, void *aux)
+{
+	struct com_softc *sc = device_private(self);
+	struct acpi_attach_args *aa = aux;
+	const struct device_compatible_entry *dce;
+	struct acpi_resources res;
+	struct acpi_mem *mem;
+	struct acpi_irq *irq;
+	bus_space_tag_t iot;
+	bus_space_handle_t ioh;
+	bus_addr_t base;
+	bus_size_t size;
+	ACPI_STATUS rv;
+	void *ih;
+
+	sc->sc_dev = self;
+
+	rv = acpi_resource_parse(sc->sc_dev, aa->aa_node->ad_handle, "_CRS",
+	&res, &acpi_resource_parse_ops_default);
+	if (ACPI_FAILURE(rv)) {
+		return;
+	}
+
+	mem = acpi_res_mem(&res, 0);
+	if (mem == NULL) {
+		aprint_error_dev(self, "couldn't find mem resource\n");
+		goto cleanup;
+	}
+
+	iot = aa->aa_memt;
+	base = mem->ar_base;
+	size = mem->ar_length;
+
+	irq = acpi_res_irq(&res, 0);
+	if (irq == NULL) {
+		aprint_error_dev(self, "couldn't find irq

CVS commit: src/sys/dev/sdmmc

2021-08-08 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Aug  8 16:23:37 UTC 2021

Modified Files:
src/sys/dev/sdmmc: if_bwfm_sdio.h

Log Message:
Fixup bwfm(4) register bit regarding SDIO device suspend/resume.

>From OpenBSD if_bwfm_sdio.h r1.3


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/sdmmc/if_bwfm_sdio.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/sdmmc/if_bwfm_sdio.h
diff -u src/sys/dev/sdmmc/if_bwfm_sdio.h:1.2 src/sys/dev/sdmmc/if_bwfm_sdio.h:1.3
--- src/sys/dev/sdmmc/if_bwfm_sdio.h:1.2	Thu Oct  3 10:53:34 2019
+++ src/sys/dev/sdmmc/if_bwfm_sdio.h	Sun Aug  8 16:23:37 2021
@@ -79,7 +79,7 @@
 #define  BWFM_SDIO_FUNC1_WAKEUPCTRL_HTWAIT		(1 << 1)
 #define BWFM_SDIO_FUNC1_SLEEPCSR		0x1001F
 #define  BWFM_SDIO_FUNC1_SLEEPCSR_KSO		(1 << 0)
-#define  BWFM_SDIO_FUNC1_SLEEPCSR_DEVON		(1 << 2)
+#define  BWFM_SDIO_FUNC1_SLEEPCSR_DEVON		(1 << 1)
 
 #define BWFM_SDIO_SB_OFT_ADDR_PAGE		0x08000
 #define BWFM_SDIO_SB_OFT_ADDR_MASK		0x07FFF



CVS commit: src/sys/dev/fdt

2021-08-08 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Aug  8 15:23:42 UTC 2021

Modified Files:
src/sys/dev/fdt: fdt_regulator.c

Log Message:
fdt: regulator: pre-allocate regulator handle

Workaround for PR# port-evbarm/54664


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/fdt/fdt_regulator.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/fdt/fdt_regulator.c
diff -u src/sys/dev/fdt/fdt_regulator.c:1.8 src/sys/dev/fdt/fdt_regulator.c:1.9
--- src/sys/dev/fdt/fdt_regulator.c:1.8	Mon May 27 23:18:33 2019
+++ src/sys/dev/fdt/fdt_regulator.c	Sun Aug  8 15:23:42 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_regulator.c,v 1.8 2019/05/27 23:18:33 jmcneill Exp $ */
+/* $NetBSD: fdt_regulator.c,v 1.9 2021/08/08 15:23:42 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdt_regulator.c,v 1.8 2019/05/27 23:18:33 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_regulator.c,v 1.9 2021/08/08 15:23:42 jmcneill Exp $");
 
 #include 
 #include 
@@ -37,6 +37,9 @@ __KERNEL_RCSID(0, "$NetBSD: fdt_regulato
 #include 
 #include 
 
+#define	REGULATOR_TO_RC(_reg)	\
+	container_of((_reg), struct fdtbus_regulator_controller, rc_reg)
+
 struct fdtbus_regulator_controller {
 	device_t rc_dev;
 	int rc_phandle;
@@ -44,6 +47,8 @@ struct fdtbus_regulator_controller {
 
 	u_int rc_enable_ramp_delay;
 
+	struct fdtbus_regulator rc_reg;	/* handle returned by acquire() */
+
 	LIST_ENTRY(fdtbus_regulator_controller) rc_next;
 };
 
@@ -60,6 +65,7 @@ fdtbus_register_regulator_controller(dev
 	rc->rc_dev = dev;
 	rc->rc_phandle = phandle;
 	rc->rc_funcs = funcs;
+	rc->rc_reg.reg_rc = rc;
 
 	of_getprop_uint32(phandle, "regulator-enable-ramp-delay", &rc->rc_enable_ramp_delay);
 
@@ -85,7 +91,6 @@ struct fdtbus_regulator *
 fdtbus_regulator_acquire(int phandle, const char *prop)
 {
 	struct fdtbus_regulator_controller *rc;
-	struct fdtbus_regulator *reg;
 	int regulator_phandle;
 	int error;
 
@@ -105,26 +110,21 @@ fdtbus_regulator_acquire(int phandle, co
 		return NULL;
 	}
 
-	reg = kmem_alloc(sizeof(*reg), KM_SLEEP);
-	reg->reg_rc = rc;
-
-	return reg;
+	return &rc->rc_reg;
 }
 
 void
 fdtbus_regulator_release(struct fdtbus_regulator *reg)
 {
-	struct fdtbus_regulator_controller *rc = reg->reg_rc;
+	struct fdtbus_regulator_controller *rc = REGULATOR_TO_RC(reg);
 
 	rc->rc_funcs->release(rc->rc_dev);
-
-	kmem_free(reg, sizeof(*reg));
 }
 
 int
 fdtbus_regulator_enable(struct fdtbus_regulator *reg)
 {
-	struct fdtbus_regulator_controller *rc = reg->reg_rc;
+	struct fdtbus_regulator_controller *rc = REGULATOR_TO_RC(reg);
 	int error;
 
 	error = rc->rc_funcs->enable(rc->rc_dev, true);
@@ -140,7 +140,7 @@ fdtbus_regulator_enable(struct fdtbus_re
 int
 fdtbus_regulator_disable(struct fdtbus_regulator *reg)
 {
-	struct fdtbus_regulator_controller *rc = reg->reg_rc;
+	struct fdtbus_regulator_controller *rc = REGULATOR_TO_RC(reg);
 
 	if (of_hasprop(rc->rc_phandle, "regulator-always-on"))
 		return EIO;
@@ -152,7 +152,7 @@ int
 fdtbus_regulator_set_voltage(struct fdtbus_regulator *reg, u_int min_uvol,
 u_int max_uvol)
 {
-	struct fdtbus_regulator_controller *rc = reg->reg_rc;
+	struct fdtbus_regulator_controller *rc = REGULATOR_TO_RC(reg);
 
 	if (rc->rc_funcs->set_voltage == NULL)
 		return EINVAL;
@@ -163,7 +163,7 @@ fdtbus_regulator_set_voltage(struct fdtb
 int
 fdtbus_regulator_get_voltage(struct fdtbus_regulator *reg, u_int *puvol)
 {
-	struct fdtbus_regulator_controller *rc = reg->reg_rc;
+	struct fdtbus_regulator_controller *rc = REGULATOR_TO_RC(reg);
 
 	if (rc->rc_funcs->get_voltage == NULL)
 		return EINVAL;
@@ -175,7 +175,7 @@ int
 fdtbus_regulator_supports_voltage(struct fdtbus_regulator *reg, u_int min_uvol,
 u_int max_uvol)
 {
-	struct fdtbus_regulator_controller *rc = reg->reg_rc;
+	struct fdtbus_regulator_controller *rc = REGULATOR_TO_RC(reg);
 	u_int uvol;
 
 	if (rc->rc_funcs->set_voltage == NULL)



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

2021-08-08 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Aug  8 13:43:09 UTC 2021

Modified Files:
src/sys/arch/arm/arm: smccc.c

Log Message:
fix armv7 build


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/arm/smccc.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/arm/smccc.c
diff -u src/sys/arch/arm/arm/smccc.c:1.2 src/sys/arch/arm/arm/smccc.c:1.3
--- src/sys/arch/arm/arm/smccc.c:1.2	Sat Aug  7 21:21:49 2021
+++ src/sys/arch/arm/arm/smccc.c	Sun Aug  8 13:43:09 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: smccc.c,v 1.2 2021/08/07 21:21:49 jmcneill Exp $ */
+/* $NetBSD: smccc.c,v 1.3 2021/08/08 13:43:09 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2021 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: smccc.c,v 1.2 2021/08/07 21:21:49 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: smccc.c,v 1.3 2021/08/08 13:43:09 jmcneill Exp $");
 
 #include 
 #include 
@@ -35,6 +35,12 @@ __KERNEL_RCSID(0, "$NetBSD: smccc.c,v 1.
 #include 
 #include 
 
+#if defined(__arm__)
+#define	SMCCC_ARCH_ATTRIBUTE  __attribute__ ((target("arch=armv7ve")))
+#else
+#define	SMCCC_ARCH_ATTRIBUTE
+#endif
+
 /* Minimum supported PSCI version for SMCCC discovery */
 #define	PSCI_VERSION_1_0	0x1
 
@@ -89,7 +95,7 @@ smccc_version(void)
  *
  *	Generic call interface for SMC/HVC calls.
  */
-int
+SMCCC_ARCH_ATTRIBUTE int
 smccc_call(uint32_t fid,
 register_t arg1, register_t arg2, register_t arg3, register_t arg4,
 register_t *res0, register_t *res1, register_t *res2, register_t *res3)



CVS commit: src/doc

2021-08-08 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Aug  8 12:35:44 UTC 2021

Modified Files:
src/doc: CHANGES

Log Message:
evbarm: Add support for Arm PCI Configuration Space Access Firmware
Interface (DEN0115).
evbarm: Add support for Broadcom BCM2838 EMMC2 in ACPI mode, as found
on the Raspberry Pi 4.
evbarm: Add support for shared ACPI platform interrupts.


To generate a diff of this commit:
cvs rdiff -u -r1.2817 -r1.2818 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.2817 src/doc/CHANGES:1.2818
--- src/doc/CHANGES:1.2817	Tue Aug  3 09:25:43 2021
+++ src/doc/CHANGES	Sun Aug  8 12:35:43 2021
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2817 $>
+# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2818 $>
 #
 #
 # [Note: This file does not mention every change made to the NetBSD source tree.
@@ -390,3 +390,9 @@ Changes from NetBSD 9.0 to NetBSD 10.0:
 	kernel: Tie the maximum file lock per unprivilegied uid to 
 		kern.maxfiles [manu 20210727]
 	evbppc: Switch ibm4xx to generic evbppc kernel modules. [rin 20210803]
+	evbarm: Add support for Arm PCI Configuration Space Access Firmware
+		Interface (DEN0115). [jmcneill 20210808]
+	evbarm: Add support for Broadcom BCM2838 EMMC2 in ACPI mode, as found
+		on the Raspberry Pi 4. [jmcneill 20210808]
+	evbarm: Add support for shared ACPI platform interrupts.
+		[jmcneill 20210808]



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

2021-08-08 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Aug  8 12:31:43 UTC 2021

Modified Files:
src/sys/arch/evbarm/conf: std.generic64

Log Message:
Enable options PCI_SMCCC on 64-bit Arm.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/evbarm/conf/std.generic64

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/std.generic64
diff -u src/sys/arch/evbarm/conf/std.generic64:1.13 src/sys/arch/evbarm/conf/std.generic64:1.14
--- src/sys/arch/evbarm/conf/std.generic64:1.13	Tue Sep  8 17:39:04 2020
+++ src/sys/arch/evbarm/conf/std.generic64	Sun Aug  8 12:31:42 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: std.generic64,v 1.13 2020/09/08 17:39:04 jakllsch Exp $
+#	$NetBSD: std.generic64,v 1.14 2021/08/08 12:31:42 jmcneill Exp $
 #
 #	generic NetBSD/evbarm64 with FDT support
 
@@ -19,6 +19,7 @@ options 	FPU_VFP
 options 	MODULAR
 options 	MODULAR_DEFAULT_AUTOLOAD
 options 	PCI_NETBSD_CONFIGURE
+options 	PCI_SMCCC		# Arm PCI Conf Access Firmware Interface
 options 	_ARM32_NEED_BUS_DMA_BOUNCE
 options 	__HAVE_GENERIC_CPU_INITCLOCKS
 options 	__HAVE_PCI_CONF_HOOK



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

2021-08-08 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Aug  8 12:09:52 UTC 2021

Modified Files:
src/sys/arch/arm/acpi: acpi_pci_machdep.c

Log Message:
Install the shared PCI INTx interrupt handler at IPL_VM to workaround a
possible interrupt storm at boot. Need to revisit this.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/arm/acpi/acpi_pci_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/arm/acpi/acpi_pci_machdep.c
diff -u src/sys/arch/arm/acpi/acpi_pci_machdep.c:1.19 src/sys/arch/arm/acpi/acpi_pci_machdep.c:1.20
--- src/sys/arch/arm/acpi/acpi_pci_machdep.c:1.19	Sat Aug  7 21:27:53 2021
+++ src/sys/arch/arm/acpi/acpi_pci_machdep.c	Sun Aug  8 12:09:52 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_pci_machdep.c,v 1.19 2021/08/07 21:27:53 jmcneill Exp $ */
+/* $NetBSD: acpi_pci_machdep.c,v 1.20 2021/08/08 12:09:52 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018, 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 #define	_INTR_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_pci_machdep.c,v 1.19 2021/08/07 21:27:53 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_pci_machdep.c,v 1.20 2021/08/08 12:09:52 jmcneill Exp $");
 
 #include 
 #include 
@@ -536,7 +536,7 @@ acpi_pci_md_intr_establish(void *v, pci_
 		pi->pi_pic.pic_ops = &acpi_pci_pic_ops;
 		pi->pi_irqbase = pic_add(&pi->pi_pic, PIC_IRQBASE_ALLOC);
 		TAILQ_INSERT_TAIL(&acpi_pci_intrs, pi, pi_list);
-		pi->pi_ih = intr_establish_xname(irq, IPL_SCHED, IST_LEVEL | IST_MPSAFE,
+		pi->pi_ih = intr_establish_xname(irq, IPL_VM, IST_LEVEL | IST_MPSAFE,
 		pic_handle_intr, &pi->pi_pic, device_xname(ap->ap_dev));
 	}
 	if (pi->pi_ih == NULL)



CVS commit: src/sys/dev/sdmmc

2021-08-08 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Aug  8 11:11:29 UTC 2021

Modified Files:
src/sys/dev/sdmmc: if_bwfm_sdio.c

Log Message:
Use SMBIOS system product instead of the string "netbsd,generic-acpi"
for firmware loading on ACPI systems.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/dev/sdmmc/if_bwfm_sdio.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/sdmmc/if_bwfm_sdio.c
diff -u src/sys/dev/sdmmc/if_bwfm_sdio.c:1.26 src/sys/dev/sdmmc/if_bwfm_sdio.c:1.27
--- src/sys/dev/sdmmc/if_bwfm_sdio.c:1.26	Mon Jun 21 03:17:59 2021
+++ src/sys/dev/sdmmc/if_bwfm_sdio.c	Sun Aug  8 11:11:29 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: if_bwfm_sdio.c,v 1.26 2021/06/21 03:17:59 christos Exp $ */
+/* $NetBSD: if_bwfm_sdio.c,v 1.27 2021/08/08 11:11:29 jmcneill Exp $ */
 /* $OpenBSD: if_bwfm_sdio.c,v 1.1 2017/10/11 17:19:50 patrick Exp $ */
 /*
  * Copyright (c) 2010-2016 Broadcom Corporation
@@ -592,10 +592,17 @@ bwfm_fdt_find_phandle(device_t self, dev
 static const char *
 bwfm_fdt_get_model(void)
 {
+	const char *model;
 	int phandle;
 
 	phandle = OF_finddevice("/");
-	return fdtbus_get_string_index(phandle, "compatible", 0);
+	model = fdtbus_get_string_index(phandle, "compatible", 0);
+	if (model == NULL ||
+	(model != NULL && strcmp(model, "netbsd,generic-acpi") == 0)) {
+		model = pmf_get_platform("system-product");
+	}
+
+	return model;
 }
 
 static int



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

2021-08-08 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Aug  8 10:59:27 UTC 2021

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

Log Message:
disable DMA for now...


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/broadcom/bcm2838_emmc2_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/arm/broadcom/bcm2838_emmc2_acpi.c
diff -u src/sys/arch/arm/broadcom/bcm2838_emmc2_acpi.c:1.1 src/sys/arch/arm/broadcom/bcm2838_emmc2_acpi.c:1.2
--- src/sys/arch/arm/broadcom/bcm2838_emmc2_acpi.c:1.1	Sun Aug  8 10:32:26 2021
+++ src/sys/arch/arm/broadcom/bcm2838_emmc2_acpi.c	Sun Aug  8 10:59:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: bcm2838_emmc2_acpi.c,v 1.1 2021/08/08 10:32:26 jmcneill Exp $	*/
+/*	$NetBSD: bcm2838_emmc2_acpi.c,v 1.2 2021/08/08 10:59:27 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 2021 Jared McNeill 
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bcm2838_emmc2_acpi.c,v 1.1 2021/08/08 10:32:26 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2838_emmc2_acpi.c,v 1.2 2021/08/08 10:59:27 jmcneill Exp $");
 
 #include 
 #include 
@@ -119,8 +119,10 @@ bcmemmc2_acpi_attach(device_t parent, de
 	 * disable UHS modes.
 	 */
 	sc->sc.sc_flags = SDHC_FLAG_32BIT_ACCESS |
+#if notyet
 			  SDHC_FLAG_USE_DMA |
 			  SDHC_FLAG_USE_ADMA2 |
+#endif
 			  SDHC_FLAG_NO_1_8_V;
 
 	sc->sc_ih = acpi_intr_establish(self,



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

2021-08-08 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Aug  8 10:32:27 UTC 2021

Modified Files:
src/sys/arch/arm/broadcom: files.bcm2835
Added Files:
src/sys/arch/arm/broadcom: bcm2838_emmc2_acpi.c

Log Message:
bcm2838: Add ACPI support for the EMMC2 SDHCI controller.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/broadcom/bcm2838_emmc2_acpi.c
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/arm/broadcom/files.bcm2835

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/files.bcm2835
diff -u src/sys/arch/arm/broadcom/files.bcm2835:1.40 src/sys/arch/arm/broadcom/files.bcm2835:1.41
--- src/sys/arch/arm/broadcom/files.bcm2835:1.40	Wed Mar 10 11:03:48 2021
+++ src/sys/arch/arm/broadcom/files.bcm2835	Sun Aug  8 10:32:26 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: files.bcm2835,v 1.40 2021/03/10 11:03:48 mlelstv Exp $
+#	$NetBSD: files.bcm2835,v 1.41 2021/08/08 10:32:26 jmcneill Exp $
 #
 # Configuration info for Broadcom BCM2835 ARM Peripherals
 #
@@ -67,6 +67,8 @@ file	arch/arm/broadcom/bcm2835_emmc.c	bc
 ifdef acpinodebus
 attach	sdhc at acpinodebus with bcmemmc_acpi
 file	arch/arm/broadcom/bcm2835_emmc_acpi.c	bcmemmc_acpi
+attach	sdhc at acpinodebus with bcmemmc2_acpi
+file	arch/arm/broadcom/bcm2838_emmc2_acpi.c	bcmemmc2_acpi
 endif
 
 # SD Host Controller (BCM2835_SDHOST_BASE)

Added files:

Index: src/sys/arch/arm/broadcom/bcm2838_emmc2_acpi.c
diff -u /dev/null src/sys/arch/arm/broadcom/bcm2838_emmc2_acpi.c:1.1
--- /dev/null	Sun Aug  8 10:32:27 2021
+++ src/sys/arch/arm/broadcom/bcm2838_emmc2_acpi.c	Sun Aug  8 10:32:26 2021
@@ -0,0 +1,164 @@
+/*	$NetBSD: bcm2838_emmc2_acpi.c,v 1.1 2021/08/08 10:32:26 jmcneill Exp $	*/
+
+/*
+ * Copyright (c) 2021 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. The name of the author may not be used to endorse or promote products
+ *derived from this software without specific prior written permission.
+ *
+ * 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 
+__KERNEL_RCSID(0, "$NetBSD: bcm2838_emmc2_acpi.c,v 1.1 2021/08/08 10:32:26 jmcneill Exp $");
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#define _COMPONENT	ACPI_RESOURCE_COMPONENT
+ACPI_MODULE_NAME	("bcmemmc2_acpi")
+
+static int	bcmemmc2_acpi_match(device_t, cfdata_t, void *);
+static void	bcmemmc2_acpi_attach(device_t, device_t, void *);
+static void	bcmemmc2_acpi_attach1(device_t);
+
+static const char * const compatible[] = {
+	"BRCME88C",
+	NULL
+};
+
+struct bcmemmc2_acpi_softc {
+	struct sdhc_softc sc;
+	bus_space_tag_t sc_memt;
+	bus_space_handle_t sc_memh;
+	bus_size_t sc_memsize;
+	void *sc_ih;
+	struct sdhc_host *sc_hosts[1];
+};
+
+CFATTACH_DECL_NEW(bcmemmc2_acpi, sizeof(struct bcmemmc2_acpi_softc),
+bcmemmc2_acpi_match, bcmemmc2_acpi_attach, NULL, NULL);
+
+static int
+bcmemmc2_acpi_match(device_t parent, cfdata_t match, void *opaque)
+{
+	struct acpi_attach_args *aa = opaque;
+
+	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
+		return 0;
+
+	return acpi_match_hid(aa->aa_node->ad_devinfo, compatible);
+}
+
+static void
+bcmemmc2_acpi_attach(device_t parent, device_t self, void *opaque)
+{
+	struct bcmemmc2_acpi_softc *sc = device_private(self);
+	struct acpi_attach_args *aa = opaque;
+	struct acpi_resources res;
+	struct acpi_mem *mem;
+	struct acpi_irq *irq;
+	ACPI_STATUS rv;
+
+	sc->sc.sc_dev = self;
+	sc->sc.sc_dmat = aa->aa_dmat;
+	sc->sc.sc_host = sc->sc_hosts;
+	sc->sc_memt = aa->aa_memt;
+
+	rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
+	&res, &acpi_resource_parse_ops_default);
+	if (ACPI_FAILURE(rv))
+		return;
+
+	mem = acpi_res_mem(&res, 0);
+	irq = acpi_res_irq(&res, 0);
+	if (mem == NULL || irq == NULL) {
+		aprint_error_dev(self, "incomplete resources\n");
+		goto cleanup;
+	}
+	if (mem->ar_length == 0) {
+		aprint_error_dev(self, "zero length memory resou

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

2021-08-08 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Aug  8 10:28:26 UTC 2021

Modified Files:
src/sys/arch/arm/acpi: acpi_machdep.c

Log Message:
arm: ACPI: Add support for simple sharing of platform interrupts

Allow sharing of platform interrupts provided that the type, ipl, and
mpsafe-ness are the same.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/arm/acpi/acpi_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/arm/acpi/acpi_machdep.c
diff -u src/sys/arch/arm/acpi/acpi_machdep.c:1.24 src/sys/arch/arm/acpi/acpi_machdep.c:1.25
--- src/sys/arch/arm/acpi/acpi_machdep.c:1.24	Sat Aug  7 18:40:45 2021
+++ src/sys/arch/arm/acpi/acpi_machdep.c	Sun Aug  8 10:28:26 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_machdep.c,v 1.24 2021/08/07 18:40:45 jmcneill Exp $ */
+/* $NetBSD: acpi_machdep.c,v 1.25 2021/08/08 10:28:26 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include "pci.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_machdep.c,v 1.24 2021/08/07 18:40:45 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_machdep.c,v 1.25 2021/08/08 10:28:26 jmcneill Exp $");
 
 #include 
 #include 
@@ -63,6 +63,27 @@ extern struct bus_space arm_generic_bs_t
 extern struct arm32_bus_dma_tag acpi_coherent_dma_tag;
 extern struct arm32_bus_dma_tag arm_generic_dma_tag;
 
+struct acpi_intrhandler {
+	int(*ah_fn)(void *);
+	void*ah_arg;
+	TAILQ_ENTRY(acpi_intrhandler)	ah_list;
+};
+
+struct acpi_intrvec {
+	intai_irq;
+	intai_ipl;
+	intai_type;
+	boolai_mpsafe;
+	intai_refcnt;
+	void*ai_arg;
+	void*ai_ih;
+	TAILQ_HEAD(, acpi_intrhandler)	ai_handlers;
+	TAILQ_ENTRY(acpi_intrvec)	ai_list;
+};
+
+static TAILQ_HEAD(, acpi_intrvec) acpi_intrvecs =
+TAILQ_HEAD_INITIALIZER(acpi_intrvecs);
+
 bus_dma_tag_t	arm_acpi_dma32_tag(struct acpi_softc *, struct acpi_devnode *);
 bus_dma_tag_t	arm_acpi_dma64_tag(struct acpi_softc *, struct acpi_devnode *);
 
@@ -256,28 +277,128 @@ acpi_md_OsDisableInterrupt(void)
 	cpsid(I32_bit);
 }
 
+static struct acpi_intrvec *
+acpi_md_intr_lookup(int irq)
+{
+	struct acpi_intrvec *ai;
+
+	TAILQ_FOREACH(ai, &acpi_intrvecs, ai_list) {
+		if (ai->ai_irq == irq) {
+			return ai;
+		}
+	}
+
+	return NULL;
+}
+
+static int
+acpi_md_intr(void *arg)
+{
+	struct acpi_intrvec *ai = arg;
+	struct acpi_intrhandler *ah;
+	int rv = 0;
+
+	TAILQ_FOREACH(ah, &ai->ai_handlers, ah_list) {
+		rv += ah->ah_fn(ah->ah_arg);
+	}
+
+	return rv;
+}
+
 void *
 acpi_md_intr_establish(uint32_t irq, int ipl, int type, int (*handler)(void *), void *arg, bool mpsafe, const char *xname)
 {
-	return intr_establish_xname(irq, ipl, type | (mpsafe ? IST_MPSAFE : 0), handler, arg, xname);
+	struct acpi_intrvec *ai;
+	struct acpi_intrhandler *ah;
+
+	ai = acpi_md_intr_lookup(irq);
+	if (ai == NULL) {
+		ai = kmem_zalloc(sizeof(*ai), KM_SLEEP);
+		ai->ai_refcnt = 0;
+		ai->ai_irq = irq;
+		ai->ai_ipl = ipl;
+		ai->ai_type = type;
+		ai->ai_mpsafe = mpsafe;
+		ai->ai_arg = arg;
+		TAILQ_INIT(&ai->ai_handlers);
+		if (arg == NULL) {
+			ai->ai_ih = intr_establish_xname(irq, ipl,
+			type | (mpsafe ? IST_MPSAFE : 0), handler, NULL,
+			xname);
+		} else {
+			ai->ai_ih = intr_establish_xname(irq, ipl,
+			type | (mpsafe ? IST_MPSAFE : 0), acpi_md_intr, ai,
+			xname);
+		}
+		if (ai->ai_ih == NULL) {
+			kmem_free(ai, sizeof(*ai));
+			return NULL;
+		}
+		TAILQ_INSERT_TAIL(&acpi_intrvecs, ai, ai_list);
+	} else {
+		if (ai->ai_arg == NULL) {
+			printf("ACPI: cannot share irq with NULL arg\n");
+			return NULL;
+		}
+		if (ai->ai_ipl != ipl) {
+			printf("ACPI: cannot share irq with different ipl\n");
+			return NULL;
+		}
+		if (ai->ai_type != type) {
+			printf("ACPI: cannot share edge and level interrupts\n");
+			return NULL;
+		}
+		if (ai->ai_mpsafe != mpsafe) {
+			printf("ACPI: cannot share between mpsafe/non-mpsafe\n");
+			return NULL;
+		}
+	}
+
+	ai->ai_refcnt++;
+
+	ah = kmem_zalloc(sizeof(*ah), KM_SLEEP);
+	ah->ah_fn = handler;
+	ah->ah_arg = arg;
+	TAILQ_INSERT_TAIL(&ai->ai_handlers, ah, ah_list);
+
+	return ai->ai_ih;
 }
 
 void
-acpi_md_intr_mask(void *ih)
+acpi_md_intr_disestablish(void *ih)
 {
-	intr_mask(ih);
+	struct acpi_intrvec *ai;
+	struct acpi_intrhandler *ah;
+
+	TAILQ_FOREACH(ai, &acpi_intrvecs, ai_list) {
+		if (ai->ai_ih == ih) {
+			KASSERT(ai->ai_refcnt > 0);
+			if (ai->ai_refcnt > 1) {
+panic("%s: cannot disestablish shared irq", __func__);
+			}
+
+			TAILQ_REMOVE(&acpi_intrvecs, ai, ai_list);
+			ah = TAILQ_FIRST(&ai->ai_handlers);
+			kmem_free(ah, sizeof(*ah));
+			intr_disestablish(ai->ai_ih);
+			kmem_free(ai, sizeof(*ai));
+			return;
+		}
+	}
+
+	panic("%s: interrupt not established", __func__);
 }
 
 void
-acpi_md_intr_unmask(void *ih)
+acpi_md_intr_mask(void *ih)
 {
-	intr_unmask(ih);
+	intr_mask(ih);
 }
 
 void
-acpi_md_intr_disestablish(void 

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

2021-08-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Aug  7 21:27:53 UTC 2021

Modified Files:
src/sys/arch/arm/acpi: acpi_pci_machdep.c acpi_pci_machdep.h acpipchb.c
files.acpi
Added Files:
src/sys/arch/arm/acpi: acpi_pci_smccc.c

Log Message:
arm: acpi: Add support for SMCCC based PCI config access.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/arm/acpi/acpi_pci_machdep.c
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/arm/acpi/acpi_pci_machdep.h
cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/acpi/acpi_pci_smccc.c
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/arm/acpi/acpipchb.c
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/arm/acpi/files.acpi

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/acpi/acpi_pci_machdep.c
diff -u src/sys/arch/arm/acpi/acpi_pci_machdep.c:1.18 src/sys/arch/arm/acpi/acpi_pci_machdep.c:1.19
--- src/sys/arch/arm/acpi/acpi_pci_machdep.c:1.18	Wed Jun 17 06:45:09 2020
+++ src/sys/arch/arm/acpi/acpi_pci_machdep.c	Sat Aug  7 21:27:53 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_pci_machdep.c,v 1.18 2020/06/17 06:45:09 thorpej Exp $ */
+/* $NetBSD: acpi_pci_machdep.c,v 1.19 2021/08/07 21:27:53 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018, 2020 The NetBSD Foundation, Inc.
@@ -29,10 +29,12 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "opt_pci.h"
+
 #define	_INTR_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_pci_machdep.c,v 1.18 2020/06/17 06:45:09 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_pci_machdep.c,v 1.19 2021/08/07 21:27:53 jmcneill Exp $");
 
 #include 
 #include 
@@ -60,6 +62,10 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_pci_mac
 #include 
 #include 
 
+#ifdef PCI_SMCCC
+#include 
+#endif
+
 #include 
 
 struct acpi_pci_prt {
@@ -94,7 +100,7 @@ struct acpi_pci_intr {
 static TAILQ_HEAD(, acpi_pci_intr) acpi_pci_intrs =
 TAILQ_HEAD_INITIALIZER(acpi_pci_intrs);
 
-static const struct acpi_pci_quirk acpi_pci_quirks[] = {
+static const struct acpi_pci_quirk acpi_pci_mcfg_quirks[] = {
 	/* OEM ID	OEM Table ID	Revision	Seg	Func */
 	{ "AMAZON",	"GRAVITON",	0,		-1,	acpi_pci_graviton_init },
 	{ "ARMLTD",	"ARMN1SDP",	0x20181101,	0,	acpi_pci_n1sdp_init },
@@ -102,6 +108,13 @@ static const struct acpi_pci_quirk acpi_
 	{ "NXP   ", "LX2160  ", 0,  -1,	acpi_pci_layerscape_gen4_init },
 };
 
+#ifdef PCI_SMCCC
+static const struct acpi_pci_quirk acpi_pci_smccc_quirk = {
+	.q_segment = -1,
+	.q_init = acpi_pci_smccc_init,
+};
+#endif
+
 pci_chipset_tag_t acpi_pci_md_get_chipset_tag(struct acpi_softc *, int, int);
 
 static void	acpi_pci_md_attach_hook(device_t, device_t,
@@ -554,11 +567,19 @@ acpi_pci_md_find_quirk(int seg)
 	u_int n;
 
 	rv = AcpiGetTable(ACPI_SIG_MCFG, 0, (ACPI_TABLE_HEADER **)&mcfg);
-	if (ACPI_FAILURE(rv))
+	if (ACPI_FAILURE(rv)) {
+#ifdef PCI_SMCCC
+		uint32_t ver = pci_smccc_version();
+		aprint_debug("%s: SMCCC version %#x\n", __func__, ver);
+		if (PCI_SMCCC_SUCCESS(ver)) {
+			return &acpi_pci_smccc_quirk;
+		}
+#endif
 		return NULL;
+	}
 
-	for (n = 0; n < __arraycount(acpi_pci_quirks); n++) {
-		const struct acpi_pci_quirk *q = &acpi_pci_quirks[n];
+	for (n = 0; n < __arraycount(acpi_pci_mcfg_quirks); n++) {
+		const struct acpi_pci_quirk *q = &acpi_pci_mcfg_quirks[n];
 		if (memcmp(q->q_oemid, mcfg->Header.OemId, ACPI_OEM_ID_SIZE) == 0 &&
 		memcmp(q->q_oemtableid, mcfg->Header.OemTableId, ACPI_OEM_TABLE_ID_SIZE) == 0 &&
 		q->q_oemrevision == mcfg->Header.OemRevision &&
@@ -589,6 +610,7 @@ acpi_pci_md_get_chipset_tag(struct acpi_
 		pct->pct_ap.ap_pc.pc_intr_v = &pct->pct_ap;
 		pct->pct_ap.ap_seg = seg;
 		pct->pct_ap.ap_bus = bbn;
+		pct->pct_ap.ap_maxbus = -1;
 		pct->pct_ap.ap_bst = acpi_softc->sc_memt;
 
 		q = acpi_pci_md_find_quirk(seg);

Index: src/sys/arch/arm/acpi/acpi_pci_machdep.h
diff -u src/sys/arch/arm/acpi/acpi_pci_machdep.h:1.7 src/sys/arch/arm/acpi/acpi_pci_machdep.h:1.8
--- src/sys/arch/arm/acpi/acpi_pci_machdep.h:1.7	Sat Feb  1 13:26:43 2020
+++ src/sys/arch/arm/acpi/acpi_pci_machdep.h	Sat Aug  7 21:27:53 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_pci_machdep.h,v 1.7 2020/02/01 13:26:43 jmcneill Exp $ */
+/* $NetBSD: acpi_pci_machdep.h,v 1.8 2021/08/07 21:27:53 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -39,12 +39,15 @@ struct acpi_pci_context {
 	device_t ap_dev;
 	u_int ap_seg;
 	int ap_bus;
+	int ap_maxbus;
 	bus_space_tag_t ap_bst;
 	bus_space_handle_t ap_conf_bsh;
 	int (*ap_conf_read)(pci_chipset_tag_t, pcitag_t, int, pcireg_t *);
 	int (*ap_conf_write)(pci_chipset_tag_t, pcitag_t, int, pcireg_t);
 	void *ap_conf_priv;
 	int ap_pciflags_clear;
+	u_int ap_flags;
+#define	ACPI_PCI_FLAG_NO_MCFG		__BIT(0)	/* ignore MCFG table */
 };
 
 struct acpi_pci_quirk {
@@ -57,6 +60,7 @@ struct acpi_pci_quirk {
 
 const struct acpi_pci_quirk *	acpi_pci_md_find_quirk(int);
 
+void	acpi_pci_smccc_init(struct acpi_pci_context *);
 void	ac

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

2021-08-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Aug  7 21:24:56 UTC 2021

Modified Files:
src/sys/arch/arm/acpi: acpi_platform.c

Log Message:
acpi: call smccc_probe() after PSCI init


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/arm/acpi/acpi_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/acpi/acpi_platform.c
diff -u src/sys/arch/arm/acpi/acpi_platform.c:1.27 src/sys/arch/arm/acpi/acpi_platform.c:1.28
--- src/sys/arch/arm/acpi/acpi_platform.c:1.27	Fri Aug  6 19:38:53 2021
+++ src/sys/arch/arm/acpi/acpi_platform.c	Sat Aug  7 21:24:56 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_platform.c,v 1.27 2021/08/06 19:38:53 jmcneill Exp $ */
+/* $NetBSD: acpi_platform.c,v 1.28 2021/08/07 21:24:56 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include "opt_multiprocessor.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_platform.c,v 1.27 2021/08/06 19:38:53 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_platform.c,v 1.28 2021/08/07 21:24:56 jmcneill Exp $");
 
 #include 
 #include 
@@ -253,6 +253,7 @@ acpi_platform_startup(void)
 			} else {
 psci_init(psci_call_smc);
 			}
+			smccc_probe();
 		}
 		acpi_table_unmap((ACPI_TABLE_HEADER *)fadt);
 	}



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

2021-08-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Aug  7 21:23:37 UTC 2021

Modified Files:
src/sys/arch/arm/pci: files.pci
Added Files:
src/sys/arch/arm/pci: pci_smccc.c pci_smccc.h

Log Message:
arm: PCI: Add support for Arm PCI Config Space Access Firmware Interface

This adds basic support for the PCI Config Access interface defined in
Arm DEN0115.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/pci/files.pci
cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/pci/pci_smccc.c \
src/sys/arch/arm/pci/pci_smccc.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/pci/files.pci
diff -u src/sys/arch/arm/pci/files.pci:1.1 src/sys/arch/arm/pci/files.pci:1.2
--- src/sys/arch/arm/pci/files.pci:1.1	Sun Oct 21 00:42:06 2018
+++ src/sys/arch/arm/pci/files.pci	Sat Aug  7 21:23:37 2021
@@ -1,4 +1,8 @@
-# $NetBSD: files.pci,v 1.1 2018/10/21 00:42:06 jmcneill Exp $
+# $NetBSD: files.pci,v 1.2 2021/08/07 21:23:37 jmcneill Exp $
 
 # PCI MSI/MSI-X support
 file	arch/arm/pci/pci_msi_machdep.c		pci & __have_pci_msi_msix
+
+# Arm PCI Configuration Space Access Firmware Interface (DEN0115)
+defflag	opt_pci.h	PCI_SMCCC
+file	arch/arm/pci/pci_smccc.c		pci_smccc

Added files:

Index: src/sys/arch/arm/pci/pci_smccc.c
diff -u /dev/null src/sys/arch/arm/pci/pci_smccc.c:1.1
--- /dev/null	Sat Aug  7 21:23:37 2021
+++ src/sys/arch/arm/pci/pci_smccc.c	Sat Aug  7 21:23:37 2021
@@ -0,0 +1,122 @@
+/* $NetBSD: pci_smccc.c,v 1.1 2021/08/07 21:23:37 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2021 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 
+__KERNEL_RCSID(0, "$NetBSD: pci_smccc.c,v 1.1 2021/08/07 21:23:37 jmcneill Exp $");
+
+#include 
+#include 
+
+#include 
+#include 
+
+/* Minimum SMCCC version required for PCI_VERSION call. */
+#define	SMCCC_VERSION_1_1	0x10001
+
+/* PCI Configuration Space Access ABI functions */
+#define	PCI_VERSION		0x84000130
+#define	PCI_FEATURES		0x84000131
+#define	PCI_READ		0x84000132
+#define	PCI_WRITE		0x84000133
+#define	PCI_GET_SEG_INFO	0x84000134
+#define	 GET_SEG_INFO_BUS_START		__BITS(7,0)
+#define	 GET_SEG_INFO_BUS_END		__BITS(15,8)
+
+static int
+pci_smccc_call(uint32_t fid,
+register_t arg1, register_t arg2, register_t arg3, register_t arg4,
+register_t *res0, register_t *res1, register_t *res2, register_t *res3)
+{
+	static int smccc_ver;
+
+	if (smccc_ver == 0) {
+		smccc_ver = smccc_version();
+	}
+	if (smccc_ver < SMCCC_VERSION_1_1) {
+		return SMCCC_NOT_SUPPORTED;
+	}
+
+	return smccc_call(fid, arg1, arg2, arg3, arg4,
+			  res0, res1, res2, res3);
+}
+
+int
+pci_smccc_version(void)
+{
+	return pci_smccc_call(PCI_VERSION, 0, 0, 0, 0,
+			  NULL, NULL, NULL, NULL);
+}
+
+int
+pci_smccc_features(uint32_t fid)
+{
+	return pci_smccc_call(PCI_FEATURES, fid, 0, 0, 0,
+			  NULL, NULL, NULL, NULL);
+}
+
+int
+pci_smccc_read(uint32_t sbdf, uint32_t offset, uint32_t access_size,
+uint32_t *data)
+{
+	register_t value;
+	int status;
+
+	status = pci_smccc_call(PCI_READ, sbdf, offset, access_size, 0,
+NULL, &value, NULL, NULL);
+	if (status == SMCCC_SUCCESS) {
+		*data = value;
+	}
+
+	return status;
+}
+
+int
+pci_smccc_write(uint32_t sbdf, uint32_t offset, uint32_t access_size,
+uint32_t data)
+{
+	return pci_smccc_call(PCI_WRITE, sbdf, offset, access_size, data,
+			  NULL, NULL, NULL, NULL);
+}
+
+int
+pci_smccc_get_seg_info(uint16_t seg, uint8_t *bus_start, uint8_t *bus_end,
+uint16_t *next_seg)
+{
+	register_t res1, res2;
+	int status;
+
+	status = pci_smccc_call(PCI_GET_SEG_INFO, seg, 0, 0, 0,
+NULL, &res1, &res2, NULL);
+	if (status == SMCCC_S

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

2021-08-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Aug  7 21:21:49 UTC 2021

Modified Files:
src/sys/arch/arm/arm: smccc.c smccc.h

Log Message:
arm: SMCCC: Add return values to smccc_call


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/arm/smccc.c \
src/sys/arch/arm/arm/smccc.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/arm/smccc.c
diff -u src/sys/arch/arm/arm/smccc.c:1.1 src/sys/arch/arm/arm/smccc.c:1.2
--- src/sys/arch/arm/arm/smccc.c:1.1	Fri Aug  6 19:38:53 2021
+++ src/sys/arch/arm/arm/smccc.c	Sat Aug  7 21:21:49 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: smccc.c,v 1.1 2021/08/06 19:38:53 jmcneill Exp $ */
+/* $NetBSD: smccc.c,v 1.2 2021/08/07 21:21:49 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2021 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: smccc.c,v 1.1 2021/08/06 19:38:53 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: smccc.c,v 1.2 2021/08/07 21:21:49 jmcneill Exp $");
 
 #include 
 #include 
@@ -42,7 +42,10 @@ __KERNEL_RCSID(0, "$NetBSD: smccc.c,v 1.
 #define	SMCCC_VERSION		0x8000
 
 /* True if SMCCC is detected. */
-static bool	smccc_present;
+static bool			smccc_present;
+
+/* SMCCC conduit (SMC or HVC) */
+static enum psci_conduit	smccc_conduit = PSCI_CONDUIT_NONE;
 
 /*
  * smccc_probe --
@@ -58,6 +61,13 @@ smccc_probe(void)
 		}
 
 		smccc_present = psci_features(SMCCC_VERSION) == PSCI_SUCCESS;
+		if (smccc_present) {
+			smccc_conduit = psci_conduit();
+
+			aprint_debug("SMCCC: Version %#x (%s)\n",
+			smccc_version(),
+			smccc_conduit == PSCI_CONDUIT_SMC ? "SMC" : "HVC");
+		}
 	}
 	return smccc_present;
 }
@@ -70,7 +80,8 @@ smccc_probe(void)
 int
 smccc_version(void)
 {
-	return smccc_call(SMCCC_VERSION, 0, 0, 0);
+	return smccc_call(SMCCC_VERSION, 0, 0, 0, 0,
+			  NULL, NULL, NULL, NULL);
 }
 
 /*
@@ -79,11 +90,54 @@ smccc_version(void)
  *	Generic call interface for SMC/HVC calls.
  */
 int
-smccc_call(register_t fid, register_t arg1, register_t arg2, register_t arg3)
+smccc_call(uint32_t fid,
+register_t arg1, register_t arg2, register_t arg3, register_t arg4,
+register_t *res0, register_t *res1, register_t *res2, register_t *res3)
 {
+	register_t args[5] = { fid, arg1, arg2, arg3, arg4 };
+
+	register register_t r0 asm ("r0");
+	register register_t r1 asm ("r1");
+	register register_t r2 asm ("r2");
+	register register_t r3 asm ("r3");
+	register register_t r4 asm ("r4");
+
 	if (!smccc_present) {
 		return SMCCC_NOT_SUPPORTED;
 	}
 
-	return psci_call(fid, arg1, arg2, arg3);
+	KASSERT(smccc_conduit != PSCI_CONDUIT_NONE);
+
+	r0 = args[0];
+	r1 = args[1];
+	r2 = args[2];
+	r3 = args[3];
+	r4 = args[4];
+
+	if (smccc_conduit == PSCI_CONDUIT_SMC) {
+		asm volatile ("smc #0" :
+			  "=r" (r0), "=r" (r1), "=r" (r2), "=r" (r3) :
+			  "r" (r0), "r" (r1), "r" (r2), "r" (r3), "r" (r4) :
+			  "memory");
+	} else {
+		asm volatile ("hvc #0" :
+			  "=r" (r0), "=r" (r1), "=r" (r2), "=r" (r3) :
+			  "r" (r0), "r" (r1), "r" (r2), "r" (r3), "r" (r4) :
+			  "memory");
+	}
+	
+	if (res0) {
+		*res0 = r0;
+	}
+	if (res1) {
+		*res1 = r1;
+	}
+	if (res2) {
+		*res2 = r2;
+	}
+	if (res3) {
+		*res3 = r3;
+	}
+
+	return r0;
 }
Index: src/sys/arch/arm/arm/smccc.h
diff -u src/sys/arch/arm/arm/smccc.h:1.1 src/sys/arch/arm/arm/smccc.h:1.2
--- src/sys/arch/arm/arm/smccc.h:1.1	Fri Aug  6 19:38:53 2021
+++ src/sys/arch/arm/arm/smccc.h	Sat Aug  7 21:21:49 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: smccc.h,v 1.1 2021/08/06 19:38:53 jmcneill Exp $ */
+/* $NetBSD: smccc.h,v 1.2 2021/08/07 21:21:49 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2021 Jared McNeill 
@@ -50,6 +50,7 @@ int	smccc_version(void);
 /*
  * Call an SMC/HVC service.
  */
-int	smccc_call(register_t, register_t, register_t, register_t);
+int	smccc_call(uint32_t, register_t, register_t, register_t, register_t,
+		   register_t *, register_t *, register_t *, register_t *);
 
 #endif /* _ARM_SMCCC_H */



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

2021-08-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Aug  7 21:20:14 UTC 2021

Modified Files:
src/sys/arch/arm/arm: psci.c psci.h

Log Message:
arm: PSCI: Add a function to return the PSCI conduit.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/arm/psci.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/arm/psci.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/arm/psci.c
diff -u src/sys/arch/arm/arm/psci.c:1.6 src/sys/arch/arm/arm/psci.c:1.7
--- src/sys/arch/arm/arm/psci.c:1.6	Fri Aug  6 19:38:53 2021
+++ src/sys/arch/arm/arm/psci.c	Sat Aug  7 21:20:14 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: psci.c,v 1.6 2021/08/06 19:38:53 jmcneill Exp $ */
+/* $NetBSD: psci.c,v 1.7 2021/08/07 21:20:14 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: psci.c,v 1.6 2021/08/06 19:38:53 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: psci.c,v 1.7 2021/08/07 21:20:14 jmcneill Exp $");
 
 #include 
 #include 
@@ -68,6 +68,18 @@ psci_call(register_t fid, register_t arg
 	return psci_call_fn(fid, arg1, arg2, arg3);
 }
 
+enum psci_conduit
+psci_conduit(void)
+{
+	if (psci_call_fn == psci_call_smc) {
+		return PSCI_CONDUIT_SMC;
+	} else if (psci_call_fn == psci_call_hvc) {
+		return PSCI_CONDUIT_HVC;
+	} else {
+		return PSCI_CONDUIT_NONE;
+	}
+}
+
 uint32_t
 psci_version(void)
 {

Index: src/sys/arch/arm/arm/psci.h
diff -u src/sys/arch/arm/arm/psci.h:1.3 src/sys/arch/arm/arm/psci.h:1.4
--- src/sys/arch/arm/arm/psci.h:1.3	Fri Aug  6 19:38:53 2021
+++ src/sys/arch/arm/arm/psci.h	Sat Aug  7 21:20:14 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: psci.h,v 1.3 2021/08/06 19:38:53 jmcneill Exp $ */
+/* $NetBSD: psci.h,v 1.4 2021/08/07 21:20:14 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -42,6 +42,15 @@ enum psci_function {
 };
 
 /*
+ * Possible PSCI conduits.
+ */
+enum psci_conduit {
+	PSCI_CONDUIT_NONE,
+	PSCI_CONDUIT_SMC,
+	PSCI_CONDUIT_HVC,
+};
+
+/*
  * PSCI error codes
  */
 #define	PSCI_SUCCESS		0
@@ -71,6 +80,11 @@ void	psci_init(psci_fn);
 bool	psci_available(void);
 
 /*
+ * Return the PSCI conduit type.
+ */
+enum psci_conduit psci_conduit(void);
+
+/*
  * PSCI call methods, implemented in psci.S
  */
 int	psci_call_smc(register_t, register_t, register_t, register_t);



CVS commit: src/sys/dev/acpi

2021-08-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Aug  7 21:19:16 UTC 2021

Modified Files:
src/sys/dev/acpi: acpi_mcfg.c acpi_mcfg.h

Log Message:
acpi: expose acpimcfg_configure_bus_cb


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/dev/acpi/acpi_mcfg.c
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/acpi/acpi_mcfg.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/acpi/acpi_mcfg.c
diff -u src/sys/dev/acpi/acpi_mcfg.c:1.23 src/sys/dev/acpi/acpi_mcfg.c:1.24
--- src/sys/dev/acpi/acpi_mcfg.c:1.23	Tue Jan 26 15:30:05 2021
+++ src/sys/dev/acpi/acpi_mcfg.c	Sat Aug  7 21:19:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_mcfg.c,v 1.23 2021/01/26 15:30:05 skrll Exp $	*/
+/*	$NetBSD: acpi_mcfg.c,v 1.24 2021/08/07 21:19:15 jmcneill Exp $	*/
 
 /*-
  * Copyright (C) 2015 NONAKA Kimihiro 
@@ -28,7 +28,7 @@
 #include "opt_pci.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.23 2021/01/26 15:30:05 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.24 2021/08/07 21:19:15 jmcneill Exp $");
 
 #include 
 #include 
@@ -693,7 +693,7 @@ out:
 }
 
 #ifdef PCI_NETBSD_CONFIGURE
-static ACPI_STATUS
+ACPI_STATUS
 acpimcfg_configure_bus_cb(ACPI_RESOURCE *res, void *ctx)
 {
 	struct pciconf_resources *pcires = ctx;

Index: src/sys/dev/acpi/acpi_mcfg.h
diff -u src/sys/dev/acpi/acpi_mcfg.h:1.3 src/sys/dev/acpi/acpi_mcfg.h:1.4
--- src/sys/dev/acpi/acpi_mcfg.h:1.3	Sun Feb  2 16:31:25 2020
+++ src/sys/dev/acpi/acpi_mcfg.h	Sat Aug  7 21:19:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_mcfg.h,v 1.3 2020/02/02 16:31:25 jmcneill Exp $	*/
+/*	$NetBSD: acpi_mcfg.h,v 1.4 2021/08/07 21:19:15 jmcneill Exp $	*/
 
 /*-
  * Copyright (C) 2015 NONAKA Kimihiro 
@@ -33,6 +33,7 @@ void	acpimcfg_probe(struct acpi_softc *)
 int	acpimcfg_init(bus_space_tag_t, const struct acpimcfg_ops *);
 int	acpimcfg_map_bus(device_t, pci_chipset_tag_t, int);
 int	acpimcfg_configure_bus(device_t, pci_chipset_tag_t, ACPI_HANDLE, int, int);
+ACPI_STATUS acpimcfg_configure_bus_cb(ACPI_RESOURCE *, void *);
 
 int	acpimcfg_conf_read(pci_chipset_tag_t, pcitag_t, int, pcireg_t *);
 int	acpimcfg_conf_write(pci_chipset_tag_t, pcitag_t, int, pcireg_t);



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

2021-08-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Aug  7 18:40:45 UTC 2021

Modified Files:
src/sys/arch/arm/acpi: acpi_machdep.c

Log Message:
acpi: DMA: Use acpi_resource_parse_any to parse _DMA resources

_DMA resources really should be marked ResourceProducer, so use
acpi_resource_parse_any to pick these up.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/arm/acpi/acpi_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/arm/acpi/acpi_machdep.c
diff -u src/sys/arch/arm/acpi/acpi_machdep.c:1.23 src/sys/arch/arm/acpi/acpi_machdep.c:1.24
--- src/sys/arch/arm/acpi/acpi_machdep.c:1.23	Sat Aug  7 16:18:42 2021
+++ src/sys/arch/arm/acpi/acpi_machdep.c	Sat Aug  7 18:40:45 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_machdep.c,v 1.23 2021/08/07 16:18:42 thorpej Exp $ */
+/* $NetBSD: acpi_machdep.c,v 1.24 2021/08/07 18:40:45 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include "pci.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_machdep.c,v 1.23 2021/08/07 16:18:42 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_machdep.c,v 1.24 2021/08/07 18:40:45 jmcneill Exp $");
 
 #include 
 #include 
@@ -417,7 +417,7 @@ default_tag:
 		return;
 	}
 
-	rv = acpi_resource_parse(sc->sc_dev, module, "_DMA", &res,
+	rv = acpi_resource_parse_any(sc->sc_dev, module, "_DMA", &res,
 	&acpi_resource_parse_ops_quiet);
 	if (ACPI_FAILURE(rv)) {
 		aprint_error_dev(sc->sc_dev,



CVS commit: src/sys/dev/acpi

2021-08-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Aug  7 18:39:40 UTC 2021

Modified Files:
src/sys/dev/acpi: acpi_resource.c acpivar.h

Log Message:
acpi: Add acpi_resource_parse_any().

Like acpi_resource_parse(), but doesn't exclude "produced" resources.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/dev/acpi/acpi_resource.c
cvs rdiff -u -r1.86 -r1.87 src/sys/dev/acpi/acpivar.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/acpi/acpi_resource.c
diff -u src/sys/dev/acpi/acpi_resource.c:1.41 src/sys/dev/acpi/acpi_resource.c:1.42
--- src/sys/dev/acpi/acpi_resource.c:1.41	Tue Dec 31 17:26:04 2019
+++ src/sys/dev/acpi/acpi_resource.c	Sat Aug  7 18:39:40 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_resource.c,v 1.41 2019/12/31 17:26:04 jmcneill Exp $	*/
+/*	$NetBSD: acpi_resource.c,v 1.42 2021/08/07 18:39:40 jmcneill Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_resource.c,v 1.41 2019/12/31 17:26:04 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_resource.c,v 1.42 2021/08/07 18:39:40 jmcneill Exp $");
 
 #include 
 #include 
@@ -83,6 +83,7 @@ static ACPI_STATUS acpi_resource_parse_c
 
 struct resource_parse_callback_arg {
 	const struct acpi_resource_parse_ops *ops;
+	bool include_producer;
 	device_t dev;
 	void *context;
 };
@@ -247,7 +248,8 @@ acpi_resource_parse_callback(ACPI_RESOUR
 	case ACPI_RESOURCE_TYPE_ADDRESS32:
 		/* XXX Only fixed size supported for now */
 		if (res->Data.Address32.Address.AddressLength == 0 ||
-		res->Data.Address32.ProducerConsumer != ACPI_CONSUMER)
+		(!arg->include_producer &&
+		 res->Data.Address32.ProducerConsumer != ACPI_CONSUMER))
 			break;
 #define ADDRESS32_FIXED2(r)		\
 	((r)->Data.Address32.MinAddressFixed == ACPI_ADDRESS_FIXED &&	\
@@ -302,7 +304,8 @@ acpi_resource_parse_callback(ACPI_RESOUR
 #ifdef _LP64
 		/* XXX Only fixed size supported for now */
 		if (res->Data.Address64.Address.AddressLength == 0 ||
-		res->Data.Address64.ProducerConsumer != ACPI_CONSUMER)
+		(!arg->include_producer &&
+		 res->Data.Address64.ProducerConsumer != ACPI_CONSUMER))
 			break;
 #define ADDRESS64_FIXED2(r)		\
 	((r)->Data.Address64.MinAddressFixed == ACPI_ADDRESS_FIXED &&	\
@@ -357,7 +360,8 @@ acpi_resource_parse_callback(ACPI_RESOUR
 		break;
 
 	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
-		if (res->Data.ExtendedIrq.ProducerConsumer != ACPI_CONSUMER) {
+		if (!arg->include_producer &&
+		res->Data.ExtendedIrq.ProducerConsumer != ACPI_CONSUMER) {
 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
 			"ignored ExtIRQ producer\n"));
 			break;
@@ -420,6 +424,7 @@ acpi_resource_parse(device_t dev, ACPI_H
 		cbarg.context = arg;
 	cbarg.ops = ops;
 	cbarg.dev = dev;
+	cbarg.include_producer = false;
 
 	rv = AcpiWalkResources(handle, path, acpi_resource_parse_callback,
 	&cbarg);
@@ -436,6 +441,45 @@ acpi_resource_parse(device_t dev, ACPI_H
 }
 
 /*
+ * acpi_resource_parse_any:
+ *
+ *	Parse a device node's resources and fill them in for the
+ *	client. Like acpi_resource_parse, but doesn't skip ResourceProducer
+ *	type resources.
+ */
+ACPI_STATUS
+acpi_resource_parse_any(device_t dev, ACPI_HANDLE handle, const char *path,
+void *arg, const struct acpi_resource_parse_ops *ops)
+{
+	struct resource_parse_callback_arg cbarg;
+	ACPI_STATUS rv;
+
+	ACPI_FUNCTION_TRACE(__func__);
+
+	if (ops->init)
+		(*ops->init)(dev, arg, &cbarg.context);
+	else
+		cbarg.context = arg;
+	cbarg.ops = ops;
+	cbarg.dev = dev;
+	cbarg.include_producer = true;
+
+	rv = AcpiWalkResources(handle, path, acpi_resource_parse_callback,
+	&cbarg);
+	if (ACPI_FAILURE(rv)) {
+		aprint_error_dev(dev, "ACPI: unable to get %s resources: %s\n",
+		path, AcpiFormatException(rv));
+		return_ACPI_STATUS(rv);
+	}
+
+	if (ops->fini)
+		(*ops->fini)(dev, cbarg.context);
+
+	return_ACPI_STATUS(AE_OK);
+}
+
+
+/*
  * acpi_resource_print:
  *
  *	Print the resources assigned to a device.

Index: src/sys/dev/acpi/acpivar.h
diff -u src/sys/dev/acpi/acpivar.h:1.86 src/sys/dev/acpi/acpivar.h:1.87
--- src/sys/dev/acpi/acpivar.h:1.86	Wed May 12 23:22:33 2021
+++ src/sys/dev/acpi/acpivar.h	Sat Aug  7 18:39:40 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpivar.h,v 1.86 2021/05/12 23:22:33 thorpej Exp $	*/
+/*	$NetBSD: acpivar.h,v 1.87 2021/08/07 18:39:40 jmcneill Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -330,6 +330,8 @@ void		acpi_deregister_notify(struct acpi
 
 ACPI_STATUS	acpi_resource_parse(device_t, ACPI_HANDLE, const char *,
 		void *, const struct acpi_resource_parse_ops *);
+ACPI_STATUS	acpi_resource_parse_any(device_t, ACPI_HANDLE, const char *,
+		void *, const struct acpi_resource_parse_ops *);
 void		acpi_resource_print(device_t, struct acpi_resources *);
 void		acpi_resource_cleanup(struct acpi_resources *);
 



CVS commit: src/sys/arch

2021-08-06 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Aug  6 19:38:54 UTC 2021

Modified Files:
src/sys/arch/aarch64/conf: files.aarch64
src/sys/arch/arm/acpi: acpi_platform.c
src/sys/arch/arm/arm: psci.c psci.h
src/sys/arch/arm/conf: files.arm
src/sys/arch/arm/fdt: psci_fdt.c
Added Files:
src/sys/arch/arm/arm: smccc.c smccc.h

Log Message:
Arm: Add support for SMC Calling Convention

Arm DEN0028 defines a calling mechanism used with Secure Monitor Call (SMC)
and Hypervisor Call (HVC) instructions. To discover SMCCC, we must:

 1) Find the PSCI conduit (either via ACPI FADT, or Device Tree)
 2) Use PSCI_VERSION to determine whether PSCI_FEATURES is supported
 3) Call PSCI_FEATURES with SMCCC_VERSION to determine the implementation
version.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/aarch64/conf/files.aarch64
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/arm/acpi/acpi_platform.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/arm/psci.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/arm/psci.h
cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/arm/smccc.c \
src/sys/arch/arm/arm/smccc.h
cvs rdiff -u -r1.164 -r1.165 src/sys/arch/arm/conf/files.arm
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/arm/fdt/psci_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/aarch64/conf/files.aarch64
diff -u src/sys/arch/aarch64/conf/files.aarch64:1.31 src/sys/arch/aarch64/conf/files.aarch64:1.32
--- src/sys/arch/aarch64/conf/files.aarch64:1.31	Sat Jul 24 23:38:41 2021
+++ src/sys/arch/aarch64/conf/files.aarch64	Fri Aug  6 19:38:53 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: files.aarch64,v 1.31 2021/07/24 23:38:41 jmcneill Exp $
+#	$NetBSD: files.aarch64,v 1.32 2021/08/06 19:38:53 jmcneill Exp $
 
 defflag opt_cpuoptions.h	AARCH64_ALIGNMENT_CHECK
 defflag opt_cpuoptions.h	AARCH64_EL0_STACK_ALIGNMENT_CHECK
@@ -33,11 +33,15 @@ defparam opt_console.h		CONSPEED
 defparam opt_console.h		CONMODE
 defparam opt_console.h		CONADDR
 
-# Power State Coordination Interface (PSCI)
 # FP support
 file	arch/aarch64/aarch64/fpu.c
 
-device	psci
+# SMC Calling Convention
+define	smccc
+file	arch/arm/arm/smccc.c			smccc
+
+# Power State Coordination Interface (PSCI)
+device	psci: smccc
 file	arch/arm/arm/psci.c			psci
 file	arch/arm/arm/psci_arm.S			psci
 

Index: src/sys/arch/arm/acpi/acpi_platform.c
diff -u src/sys/arch/arm/acpi/acpi_platform.c:1.26 src/sys/arch/arm/acpi/acpi_platform.c:1.27
--- src/sys/arch/arm/acpi/acpi_platform.c:1.26	Wed May 12 23:22:32 2021
+++ src/sys/arch/arm/acpi/acpi_platform.c	Fri Aug  6 19:38:53 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_platform.c,v 1.26 2021/05/12 23:22:32 thorpej Exp $ */
+/* $NetBSD: acpi_platform.c,v 1.27 2021/08/06 19:38:53 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include "opt_multiprocessor.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_platform.c,v 1.26 2021/05/12 23:22:32 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_platform.c,v 1.27 2021/08/06 19:38:53 jmcneill Exp $");
 
 #include 
 #include 
@@ -55,6 +55,7 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_platfor
 
 #include 
 
+#include 
 #include 
 #include 
 

Index: src/sys/arch/arm/arm/psci.c
diff -u src/sys/arch/arm/arm/psci.c:1.5 src/sys/arch/arm/arm/psci.c:1.6
--- src/sys/arch/arm/arm/psci.c:1.5	Sat Jan 16 23:51:50 2021
+++ src/sys/arch/arm/arm/psci.c	Fri Aug  6 19:38:53 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: psci.c,v 1.5 2021/01/16 23:51:50 chs Exp $ */
+/* $NetBSD: psci.c,v 1.6 2021/08/06 19:38:53 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: psci.c,v 1.5 2021/01/16 23:51:50 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: psci.c,v 1.6 2021/08/06 19:38:53 jmcneill Exp $");
 
 #include 
 #include 
@@ -45,6 +45,7 @@ __KERNEL_RCSID(0, "$NetBSD: psci.c,v 1.5
 #else
 #define	PSCI_CPU_ON		0x8403
 #endif
+#define	PSCI_FEATURES		0x840a
 
 static psci_fn psci_call_fn;
 
@@ -53,9 +54,10 @@ static uint32_t psci_functions[PSCI_FUNC
 [PSCI_FUNC_SYSTEM_OFF] = PSCI_SYSTEM_OFF,
 	[PSCI_FUNC_SYSTEM_RESET] = PSCI_SYSTEM_RESET,
 	[PSCI_FUNC_CPU_ON] = PSCI_CPU_ON,
+	[PSCI_FUNC_FEATURES] = PSCI_FEATURES,
 };
 
-static int
+int
 psci_call(register_t fid, register_t arg1, register_t arg2, register_t arg3)
 {
 	KASSERT(psci_call_fn != NULL);
@@ -98,6 +100,15 @@ psci_system_reset(void)
 	psci_call(psci_functions[PSCI_FUNC_SYSTEM_RESET], 0, 0, 0);
 }
 
+int
+psci_features(uint32_t fid)
+{
+	if (psci_functions[PSCI_FUNC_FEATURES] == 0) {
+		return PSCI_NOT_SUPPORTED;
+	}
+	return psci_call(psci_functions[PSCI_FUNC_FEATURES], fid, 0, 0);
+}
+
 void
 psci_init(psci_fn fn)
 {

Index: src/sys/arch/arm/arm/psci.h
diff -u src/sys/arch/arm/arm/psci.h:1.2 src/sys/arch/arm/arm/psci.h:1.3
--- src/sys/arch/arm/arm/psci.h:1.2	Sat Oct 13 00:07:55 2018
+++ src/sys/arch/arm/arm/ps

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

2021-07-25 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Jul 25 11:14:16 UTC 2021

Modified Files:
src/sys/arch/arm/rockchip: rk_anxdp.c

Log Message:
rockchip: edp: Force VOPB as CRTC for eDP.

Fixes display init on Pinebook Pro w/ U-Boot 2021.07.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/rockchip/rk_anxdp.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/rockchip/rk_anxdp.c
diff -u src/sys/arch/arm/rockchip/rk_anxdp.c:1.3 src/sys/arch/arm/rockchip/rk_anxdp.c:1.4
--- src/sys/arch/arm/rockchip/rk_anxdp.c:1.3	Wed Jan 27 03:10:19 2021
+++ src/sys/arch/arm/rockchip/rk_anxdp.c	Sun Jul 25 11:14:15 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: rk_anxdp.c,v 1.3 2021/01/27 03:10:19 thorpej Exp $ */
+/* $NetBSD: rk_anxdp.c,v 1.4 2021/07/25 11:14:15 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jonathan A. Kollasch 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rk_anxdp.c,v 1.3 2021/01/27 03:10:19 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rk_anxdp.c,v 1.4 2021/07/25 11:14:15 jmcneill Exp $");
 
 #include 
 #include 
@@ -172,7 +172,7 @@ rk_anxdp_ep_activate(device_t dev, struc
 		break;
 	}
 
-	sc->sc_encoder.possible_crtcs = 0x3; /* XXX */
+	sc->sc_encoder.possible_crtcs = 0x2; /* VOPB only */
 	drm_encoder_init(crtc->dev, &sc->sc_encoder, &rk_anxdp_encoder_funcs,
 	DRM_MODE_ENCODER_TMDS);
 	drm_encoder_helper_add(&sc->sc_encoder, &rk_anxdp_encoder_helper_funcs);



CVS commit: src/sys/dev/acpi

2021-07-24 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Jul 25 01:43:08 UTC 2021

Modified Files:
src/sys/dev/acpi: acpi_timer.c

Log Message:
acpi_timer: use ACPI-Fast if WAET timer one read flag is set

The Windows ACPI Emulated Devices Table (WAET) has a hint to inform the OS
that a single read of the PM timer is reliable. Honour this flag.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/dev/acpi/acpi_timer.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/acpi/acpi_timer.c
diff -u src/sys/dev/acpi/acpi_timer.c:1.26 src/sys/dev/acpi/acpi_timer.c:1.27
--- src/sys/dev/acpi/acpi_timer.c:1.26	Fri May 29 12:30:41 2020
+++ src/sys/dev/acpi/acpi_timer.c	Sun Jul 25 01:43:08 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_timer.c,v 1.26 2020/05/29 12:30:41 rin Exp $ */
+/* $NetBSD: acpi_timer.c,v 1.27 2021/07/25 01:43:08 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2006 Matthias Drochner 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_timer.c,v 1.26 2020/05/29 12:30:41 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_timer.c,v 1.27 2021/07/25 01:43:08 jmcneill Exp $");
 
 #include 
 #include 
@@ -61,6 +61,7 @@ int
 acpitimer_init(struct acpi_softc *sc)
 {
 #if (!ACPI_REDUCED_HARDWARE)
+	ACPI_TABLE_WAET *waet;
 	ACPI_STATUS rv;
 	uint32_t bits;
 	int i, j;
@@ -79,6 +80,18 @@ acpitimer_init(struct acpi_softc *sc)
 	for (i = j = 0; i < 10; i++)
 		j += acpitimer_test();
 
+	rv = AcpiGetTable(ACPI_SIG_WAET, 0, (ACPI_TABLE_HEADER **)&waet);
+	if (ACPI_SUCCESS(rv)) {
+		/*
+		 * Windows ACPI Emulated Devices Table (WAET) has a hint
+		 * to let the OS know that a single read of the PM timer
+		 * provides a reliable value.
+		 */
+		if ((waet->Flags & ACPI_WAET_TIMER_ONE_READ) != 0) {
+			j += 10;
+		}
+	}
+
 	if (j >= 10) {
 		acpi_timecounter.tc_name = "ACPI-Fast";
 		acpi_timecounter.tc_get_timecount = acpitimer_read_fast;



CVS commit: src/sys/arch/aarch64

2021-07-24 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jul 24 23:38:41 UTC 2021

Modified Files:
src/sys/arch/aarch64/conf: files.aarch64
Removed Files:
src/sys/arch/aarch64/aarch64: cctr_machdep.c

Log Message:
aarch64: Remove empty source file and references to it.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r0 src/sys/arch/aarch64/aarch64/cctr_machdep.c
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/aarch64/conf/files.aarch64

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/aarch64/conf/files.aarch64
diff -u src/sys/arch/aarch64/conf/files.aarch64:1.30 src/sys/arch/aarch64/conf/files.aarch64:1.31
--- src/sys/arch/aarch64/conf/files.aarch64:1.30	Wed Oct 21 13:31:50 2020
+++ src/sys/arch/aarch64/conf/files.aarch64	Sat Jul 24 23:38:41 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: files.aarch64,v 1.30 2020/10/21 13:31:50 christos Exp $
+#	$NetBSD: files.aarch64,v 1.31 2021/07/24 23:38:41 jmcneill Exp $
 
 defflag opt_cpuoptions.h	AARCH64_ALIGNMENT_CHECK
 defflag opt_cpuoptions.h	AARCH64_EL0_STACK_ALIGNMENT_CHECK
@@ -53,7 +53,6 @@ defflag opt_pmapboot.h		PMAPBOOT_DEBUG
 
 # MI support
 file	dev/cons.c
-#file	kern/kern_cctr.c
 
 # DDB
 file	arch/aarch64/aarch64/db_disasm.c		ddb
@@ -117,11 +116,6 @@ file	uvm/pmap/pmap_pvt.c
 # EFI runtime (machdep)
 file	arch/aarch64/aarch64/efi_machdep.c		efi_runtime
 
-# cyclecounter
-#file	arch/aarch64/aarch64/cctr_machdep.c
-#file	kern/kern_cctr.c
-
-
 # NetBSD 32-bit binary compatibility
 include "compat/netbsd32/files.netbsd32"
 file	arch/aarch64/aarch64/netbsd32_machdep.c		compat_netbsd32



CVS commit: src/sys/dev

2021-07-24 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jul 24 22:33:23 UTC 2021

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

Log Message:
build fix


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/smbios.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/smbios.c
diff -u src/sys/dev/smbios.c:1.2 src/sys/dev/smbios.c:1.3
--- src/sys/dev/smbios.c:1.2	Sat Jul 24 11:39:19 2021
+++ src/sys/dev/smbios.c	Sat Jul 24 22:33:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: smbios.c,v 1.2 2021/07/24 11:39:19 jmcneill Exp $	*/
+/*	$NetBSD: smbios.c,v 1.3 2021/07/24 22:33:23 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -86,7 +86,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: smbios.c,v 1.2 2021/07/24 11:39:19 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: smbios.c,v 1.3 2021/07/24 22:33:23 jmcneill Exp $");
 
 #include 
 #include 
@@ -138,7 +138,7 @@ smbios_map_memory(paddr_t pa, size_t siz
 	}
 	pmap_update(pmap_kernel());
 
-	return (void *)(va + (pa - spa));
+	return (void *)(uintptr_t)(va + (pa - spa));
 }
 
 static void



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

2021-07-24 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jul 24 20:45:45 UTC 2021

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

Log Message:
Build fix: vtophys takes vaddr_t, not a ptr


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/x86/x86/bios32.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/bios32.c
diff -u src/sys/arch/x86/x86/bios32.c:1.6 src/sys/arch/x86/x86/bios32.c:1.7
--- src/sys/arch/x86/x86/bios32.c:1.6	Sat Jul 24 11:39:19 2021
+++ src/sys/arch/x86/x86/bios32.c	Sat Jul 24 20:45:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: bios32.c,v 1.6 2021/07/24 11:39:19 jmcneill Exp $	*/
+/*	$NetBSD: bios32.c,v 1.7 2021/07/24 20:45:45 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -86,7 +86,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bios32.c,v 1.6 2021/07/24 11:39:19 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bios32.c,v 1.7 2021/07/24 20:45:45 jmcneill Exp $");
 
 #include 
 #include 
@@ -252,7 +252,7 @@ smbios2_map_kva(const uint8_t *p)
 	if (eva == 0)
 		return;
 
-	smbios_entry.hdrphys = vtophys(p);
+	smbios_entry.hdrphys = vtophys((vaddr_t)p);
 	smbios_entry.tabphys = sh->addr;
 	smbios_entry.addr = (uint8_t *)(eva + (sh->addr & PGOFSET));
 	smbios_entry.len = sh->size;
@@ -287,7 +287,7 @@ smbios3_map_kva(const uint8_t *p)
 	if (eva == 0)
 		return;
 
-	smbios_entry.hdrphys = vtophys(p);
+	smbios_entry.hdrphys = vtophys((vaddr_t)p);
 	smbios_entry.tabphys = sh->addr;
 	smbios_entry.addr = (uint8_t *)(eva + ((vaddr_t)sh->addr & PGOFSET));
 	smbios_entry.len = sh->size;



CVS commit: src/etc/etc.evbarm

2021-07-24 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jul 24 17:07:59 UTC 2021

Modified Files:
src/etc/etc.evbarm: Makefile.inc

Log Message:
aarch64: Restrict KERNEL_SUFFIXES to img only


To generate a diff of this commit:
cvs rdiff -u -r1.123 -r1.124 src/etc/etc.evbarm/Makefile.inc

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

Modified files:

Index: src/etc/etc.evbarm/Makefile.inc
diff -u src/etc/etc.evbarm/Makefile.inc:1.123 src/etc/etc.evbarm/Makefile.inc:1.124
--- src/etc/etc.evbarm/Makefile.inc:1.123	Thu May 27 08:43:02 2021
+++ src/etc/etc.evbarm/Makefile.inc	Sat Jul 24 17:07:59 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.123 2021/05/27 08:43:02 rin Exp $
+#	$NetBSD: Makefile.inc,v 1.124 2021/07/24 17:07:59 jmcneill Exp $
 #
 #	etc.evbarm/Makefile.inc -- evbarm-specific etc Makefile targets
 #
@@ -173,7 +173,11 @@ SNAP_MD_POST_DEPS+=	smp_rpi_inst
 
 snap_md_post: check_DESTDIR check_RELEASEDIR snap_post .WAIT ${SNAP_MD_POST_DEPS}
 
+.if !empty(MACHINE_ARCH:Maarch64*)
+KERNEL_SUFFIXES=	img
+.else
 KERNEL_SUFFIXES=	bin img srec ub
+.endif
 
 INSTALLATION_DIRS+=	binary/gzimg		\
 			installation/instkernel



CVS commit: src/distrib/amd64/liveimage/emuimage

2021-07-24 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jul 24 16:13:45 UTC 2021

Modified Files:
src/distrib/amd64/liveimage/emuimage: Makefile spec.emuimage
Added Files:
src/distrib/amd64/liveimage/emuimage: rc.conf.emuimage
Removed Files:
src/distrib/amd64/liveimage/emuimage: dhcpcd ec2_init resize_disklabel
resize_root sshd

Log Message:
amd64: liveimage: use RC_CONF_EXTRA instead of rc.conf.d


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/distrib/amd64/liveimage/emuimage/Makefile
cvs rdiff -u -r1.1 -r0 src/distrib/amd64/liveimage/emuimage/dhcpcd \
src/distrib/amd64/liveimage/emuimage/resize_disklabel \
src/distrib/amd64/liveimage/emuimage/resize_root \
src/distrib/amd64/liveimage/emuimage/sshd
cvs rdiff -u -r1.4 -r0 src/distrib/amd64/liveimage/emuimage/ec2_init
cvs rdiff -u -r0 -r1.1 src/distrib/amd64/liveimage/emuimage/rc.conf.emuimage
cvs rdiff -u -r1.1 -r1.2 src/distrib/amd64/liveimage/emuimage/spec.emuimage

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

Modified files:

Index: src/distrib/amd64/liveimage/emuimage/Makefile
diff -u src/distrib/amd64/liveimage/emuimage/Makefile:1.8 src/distrib/amd64/liveimage/emuimage/Makefile:1.9
--- src/distrib/amd64/liveimage/emuimage/Makefile:1.8	Wed Aug  5 01:35:18 2020
+++ src/distrib/amd64/liveimage/emuimage/Makefile	Sat Jul 24 16:13:44 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.8 2020/08/05 01:35:18 jmcneill Exp $
+#	$NetBSD: Makefile,v 1.9 2021/07/24 16:13:44 jmcneill Exp $
 
 LIVEIMGBASE=	NetBSD-${DISTRIBVER}-amd64-live	# gives ${IMGBASE}.img
 
@@ -10,13 +10,9 @@ IMAGEHOSTNAME=	netbsd
 FILESDIR!=	cd ${.CURDIR}/../../../utils/embedded/files ; pwd
 
 SPEC_EXTRA=	${.CURDIR}/spec.emuimage
+RC_CONF_EXTRA=	${.CURDIR}/rc.conf.emuimage
 IMGFILE_EXTRA=\
 	${FILESDIR}/ec2_init		etc/rc.d/ec2_init		\
-	${FILESDIR}/resize_disklabel	etc/rc.d/resize_disklabel	\
-	${.CURDIR}/dhcpcd		etc/rc.conf.d/dhcpcd		\
-	${.CURDIR}/ec2_init		etc/rc.conf.d/ec2_init		\
-	${.CURDIR}/resize_disklabel	etc/rc.conf.d/resize_disklabel	\
-	${.CURDIR}/resize_root		etc/rc.conf.d/resize_root	\
-	${.CURDIR}/sshd			etc/rc.conf.d/sshd
+	${FILESDIR}/resize_disklabel	etc/rc.d/resize_disklabel
 
 .include "${.CURDIR}/../Makefile.liveimage"

Index: src/distrib/amd64/liveimage/emuimage/spec.emuimage
diff -u src/distrib/amd64/liveimage/emuimage/spec.emuimage:1.1 src/distrib/amd64/liveimage/emuimage/spec.emuimage:1.2
--- src/distrib/amd64/liveimage/emuimage/spec.emuimage:1.1	Wed Aug  5 01:35:18 2020
+++ src/distrib/amd64/liveimage/emuimage/spec.emuimage	Sat Jul 24 16:13:44 2021
@@ -1,8 +1,3 @@
-# $NetBSD: spec.emuimage,v 1.1 2020/08/05 01:35:18 jmcneill Exp $
-./etc/rc.conf.d/dhcpcd			type=file mode=0644 uname=root gname=wheel
-./etc/rc.conf.d/ec2_init		type=file mode=0644 uname=root gname=wheel
-./etc/rc.conf.d/resize_disklabel	type=file mode=0644 uname=root gname=wheel
-./etc/rc.conf.d/resize_root		type=file mode=0644 uname=root gname=wheel
-./etc/rc.conf.d/sshd			type=file mode=0644 uname=root gname=wheel
+# $NetBSD: spec.emuimage,v 1.2 2021/07/24 16:13:44 jmcneill Exp $
 ./etc/rc.d/ec2_init			type=file mode=0555 uname=root gname=wheel
 ./etc/rc.d/resize_disklabel		type=file mode=0555 uname=root gname=wheel

Added files:

Index: src/distrib/amd64/liveimage/emuimage/rc.conf.emuimage
diff -u /dev/null src/distrib/amd64/liveimage/emuimage/rc.conf.emuimage:1.1
--- /dev/null	Sat Jul 24 16:13:45 2021
+++ src/distrib/amd64/liveimage/emuimage/rc.conf.emuimage	Sat Jul 24 16:13:44 2021
@@ -0,0 +1,36 @@
+# $NetBSD: rc.conf.emuimage,v 1.1 2021/07/24 16:13:44 jmcneill Exp $
+
+is_ec2() {
+	val=NO
+	# Look for the string "amazon" in one of these sysctl nodes
+	for node in machdep.dmi.system-vendor \
+		machdep.dmi.system-version \
+		machdep.dmi.bios-version \
+		machdep.xen.version ; do
+		if /sbin/sysctl -q $node; then
+			nodeval="$(/sbin/sysctl -n $node | tr '[A-Z]' '[a-z]')"
+			case "$nodeval" in
+			*amazon*)
+val=YES
+;;
+			# OpenStack is not EC2 but it does have a metadata service.
+			*openstack*)
+val=YES
+;;
+			esac
+		fi
+	done
+	printf $val
+}
+
+resize_disklabel=YES
+resize_root=YES
+resize_root_flags="-p"
+resize_root_postcmd="/sbin/reboot -n"
+dhcpcd=YES
+sshd=YES
+ec2_init=$(is_ec2)
+
+if checkyesno ec2_init; then
+	dhcpcd_flags="$dhcpcd_flags -w"
+fi



CVS commit: src/distrib/evbarm/liveimage/armimage

2021-07-24 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jul 24 14:00:08 UTC 2021

Modified Files:
src/distrib/evbarm/liveimage/armimage: Makefile spec.armimage
Added Files:
src/distrib/evbarm/liveimage/armimage: rc.conf.armimage
Removed Files:
src/distrib/evbarm/liveimage/armimage: dhcpcd ec2_init resize_gpt
resize_root sshd

Log Message:
evbarm: liveimage: use RC_CONF_EXTRA instead of rc.conf.d


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/distrib/evbarm/liveimage/armimage/Makefile \
src/distrib/evbarm/liveimage/armimage/spec.armimage
cvs rdiff -u -r1.1 -r0 src/distrib/evbarm/liveimage/armimage/dhcpcd \
src/distrib/evbarm/liveimage/armimage/ec2_init \
src/distrib/evbarm/liveimage/armimage/resize_gpt \
src/distrib/evbarm/liveimage/armimage/resize_root \
src/distrib/evbarm/liveimage/armimage/sshd
cvs rdiff -u -r0 -r1.1 src/distrib/evbarm/liveimage/armimage/rc.conf.armimage

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

Modified files:

Index: src/distrib/evbarm/liveimage/armimage/Makefile
diff -u src/distrib/evbarm/liveimage/armimage/Makefile:1.1 src/distrib/evbarm/liveimage/armimage/Makefile:1.2
--- src/distrib/evbarm/liveimage/armimage/Makefile:1.1	Fri Jul 23 21:53:34 2021
+++ src/distrib/evbarm/liveimage/armimage/Makefile	Sat Jul 24 14:00:08 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.1 2021/07/23 21:53:34 jmcneill Exp $
+#	$NetBSD: Makefile,v 1.2 2021/07/24 14:00:08 jmcneill Exp $
 
 LIVEIMGBASE=	NetBSD-${DISTRIBVER}-${MACHINE_ARCH}-live	# gives ${IMGBASE}.img
 
@@ -10,13 +10,9 @@ IMAGEHOSTNAME=	netbsd
 FILESDIR!=	cd ${.CURDIR}/../../../utils/embedded/files ; pwd
 
 SPEC_EXTRA=	${.CURDIR}/spec.armimage
+RC_CONF_EXTRA=	${.CURDIR}/rc.conf.armimage
 IMGFILE_EXTRA=\
 	${FILESDIR}/ec2_init		etc/rc.d/ec2_init		\
-	${FILESDIR}/resize_gpt		etc/rc.d/resize_gpt		\
-	${.CURDIR}/dhcpcd		etc/rc.conf.d/dhcpcd		\
-	${.CURDIR}/ec2_init		etc/rc.conf.d/ec2_init		\
-	${.CURDIR}/resize_gpt		etc/rc.conf.d/resize_gpt	\
-	${.CURDIR}/resize_root		etc/rc.conf.d/resize_root	\
-	${.CURDIR}/sshd			etc/rc.conf.d/sshd
+	${FILESDIR}/resize_gpt		etc/rc.d/resize_gpt
 
 .include "${.CURDIR}/../Makefile.liveimage"
Index: src/distrib/evbarm/liveimage/armimage/spec.armimage
diff -u src/distrib/evbarm/liveimage/armimage/spec.armimage:1.1 src/distrib/evbarm/liveimage/armimage/spec.armimage:1.2
--- src/distrib/evbarm/liveimage/armimage/spec.armimage:1.1	Fri Jul 23 21:53:34 2021
+++ src/distrib/evbarm/liveimage/armimage/spec.armimage	Sat Jul 24 14:00:08 2021
@@ -1,8 +1,3 @@
-# $NetBSD: spec.armimage,v 1.1 2021/07/23 21:53:34 jmcneill Exp $
-./etc/rc.conf.d/dhcpcd			type=file mode=0644 uname=root gname=wheel
-./etc/rc.conf.d/ec2_init		type=file mode=0644 uname=root gname=wheel
-./etc/rc.conf.d/resize_gpt		type=file mode=0644 uname=root gname=wheel
-./etc/rc.conf.d/resize_root		type=file mode=0644 uname=root gname=wheel
-./etc/rc.conf.d/sshd			type=file mode=0644 uname=root gname=wheel
+# $NetBSD: spec.armimage,v 1.2 2021/07/24 14:00:08 jmcneill Exp $
 ./etc/rc.d/ec2_init			type=file mode=0555 uname=root gname=wheel
 ./etc/rc.d/resize_gpt			type=file mode=0555 uname=root gname=wheel

Added files:

Index: src/distrib/evbarm/liveimage/armimage/rc.conf.armimage
diff -u /dev/null src/distrib/evbarm/liveimage/armimage/rc.conf.armimage:1.1
--- /dev/null	Sat Jul 24 14:00:08 2021
+++ src/distrib/evbarm/liveimage/armimage/rc.conf.armimage	Sat Jul 24 14:00:08 2021
@@ -0,0 +1,36 @@
+# $NetBSD: rc.conf.armimage,v 1.1 2021/07/24 14:00:08 jmcneill Exp $
+
+is_ec2() {
+	val=NO
+	# Look for the string "amazon" in one of these sysctl nodes
+	for node in machdep.dmi.system-vendor \
+		machdep.dmi.system-version \
+		machdep.dmi.bios-version \
+		machdep.xen.version ; do
+		if /sbin/sysctl -q $node; then
+			nodeval="$(/sbin/sysctl -n $node | tr '[A-Z]' '[a-z]')"
+			case "$nodeval" in
+			*amazon*)
+val=YES
+;;
+			# OpenStack is not EC2 but it does have a metadata service.
+			*openstack*)
+val=YES
+;;
+			esac
+		fi
+	done
+	printf $val
+}
+
+resize_gpt=YES
+resize_root=YES
+resize_root_flags="-p"
+resize_root_postcmd="/sbin/reboot -n"
+dhcpcd=YES
+sshd=YES
+ec2_init=$(is_ec2)
+
+if checkyesno ec2_init; then
+	dhcpcd_flags="$dhcpcd_flags -w"
+fi



CVS commit: src/distrib/common/bootimage

2021-07-24 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jul 24 13:59:29 UTC 2021

Modified Files:
src/distrib/common/bootimage: Makefile.bootimage

Log Message:
bootimage: allow appending additional rc.conf options

If RC_CONF_EXTRA is defined, append the contents of this file to the
target file-system's rc.conf


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/distrib/common/bootimage/Makefile.bootimage

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

Modified files:

Index: src/distrib/common/bootimage/Makefile.bootimage
diff -u src/distrib/common/bootimage/Makefile.bootimage:1.27 src/distrib/common/bootimage/Makefile.bootimage:1.28
--- src/distrib/common/bootimage/Makefile.bootimage:1.27	Fri Jun  4 17:09:36 2021
+++ src/distrib/common/bootimage/Makefile.bootimage	Sat Jul 24 13:59:28 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.bootimage,v 1.27 2021/06/04 17:09:36 tsutsui Exp $
+#	$NetBSD: Makefile.bootimage,v 1.28 2021/07/24 13:59:28 jmcneill Exp $
 #
 # Copyright (c) 2009, 2010, 2011 Izumi Tsutsui.  All rights reserved.
 #
@@ -366,6 +366,10 @@ ${TARGETFS}: prepare_md_post ${WORKFSTAB
 	@echo Setting savecore=NO in /etc/rc.conf ...
 	echo "savecore=NO" >> ${WORKRCCONF}
 .endif
+.if defined(RC_CONF_EXTRA)
+	@echo Adding contents of ${RC_CONF_EXTRA} to /etc/rc.conf ...
+	cat ${RC_CONF_EXTRA} >> ${WORKRCCONF}
+.endif
 	${INSTALL} ${COPY} -m 0644 ${WORKRCCONF} ${WORKDIR}/etc/rc.conf
 .if defined(IMGDIR_EXTRA)
 	@echo Copying extra dirs...



CVS commit: src

2021-07-24 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jul 24 11:39:19 UTC 2021

Modified Files:
src/etc: MAKEDEV.tmpl
src/etc/etc.aarch64: MAKEDEV.conf
src/etc/etc.amd64: MAKEDEV.conf
src/etc/etc.i386: MAKEDEV.conf
src/sys/arch/arm/fdt: acpi_fdt.c
src/sys/arch/x86/x86: bios32.c
src/sys/conf: majors
src/sys/dev: smbios.c smbiosvar.h

Log Message:
smbios: Add character device for accessing SMBIOS tables

The /dev/smbios character device gives an aperture into physical memory
that allows read-only access to the SMBIOS header and tables.


To generate a diff of this commit:
cvs rdiff -u -r1.223 -r1.224 src/etc/MAKEDEV.tmpl
cvs rdiff -u -r1.8 -r1.9 src/etc/etc.aarch64/MAKEDEV.conf
cvs rdiff -u -r1.32 -r1.33 src/etc/etc.amd64/MAKEDEV.conf
cvs rdiff -u -r1.33 -r1.34 src/etc/etc.i386/MAKEDEV.conf
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/arm/fdt/acpi_fdt.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/x86/x86/bios32.c
cvs rdiff -u -r1.97 -r1.98 src/sys/conf/majors
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/smbios.c src/sys/dev/smbiosvar.h

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

Modified files:

Index: src/etc/MAKEDEV.tmpl
diff -u src/etc/MAKEDEV.tmpl:1.223 src/etc/MAKEDEV.tmpl:1.224
--- src/etc/MAKEDEV.tmpl:1.223	Tue Jun 29 10:22:33 2021
+++ src/etc/MAKEDEV.tmpl	Sat Jul 24 11:39:18 2021
@@ -1,5 +1,5 @@
 #!/bin/sh -
-#	$NetBSD: MAKEDEV.tmpl,v 1.223 2021/06/29 10:22:33 nia Exp $
+#	$NetBSD: MAKEDEV.tmpl,v 1.224 2021/07/24 11:39:18 jmcneill Exp $
 #
 # Copyright (c) 2003,2007,2008 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -2240,6 +2240,10 @@ acpi)
 	mkdev acpi c %acpi_chr% 0
 	;;
 
+smbios)
+	mkdev smbios c %smbios_chr% 0
+	;;
+
 midevend)
 %MI_DEVICES_END%
 local)

Index: src/etc/etc.aarch64/MAKEDEV.conf
diff -u src/etc/etc.aarch64/MAKEDEV.conf:1.8 src/etc/etc.aarch64/MAKEDEV.conf:1.9
--- src/etc/etc.aarch64/MAKEDEV.conf:1.8	Sun Dec  6 02:57:30 2020
+++ src/etc/etc.aarch64/MAKEDEV.conf	Sat Jul 24 11:39:18 2021
@@ -1,4 +1,4 @@
-# $NetBSD: MAKEDEV.conf,v 1.8 2020/12/06 02:57:30 jmcneill Exp $
+# $NetBSD: MAKEDEV.conf,v 1.9 2021/07/24 11:39:18 jmcneill Exp $
 
 all_md)
 	makedev wscons fd0 fd1 wd0 wd1 wd2 wd3 sd0 sd1 sd2 sd3
@@ -21,6 +21,7 @@ all_md)
 	makedev bpf
 	makedev openfirm
 	makedev acpi
+	makedev smbios
 	;;
 
 ramdisk|floppy)

Index: src/etc/etc.amd64/MAKEDEV.conf
diff -u src/etc/etc.amd64/MAKEDEV.conf:1.32 src/etc/etc.amd64/MAKEDEV.conf:1.33
--- src/etc/etc.amd64/MAKEDEV.conf:1.32	Sun Dec  6 02:57:30 2020
+++ src/etc/etc.amd64/MAKEDEV.conf	Sat Jul 24 11:39:18 2021
@@ -1,4 +1,4 @@
-# $NetBSD: MAKEDEV.conf,v 1.32 2020/12/06 02:57:30 jmcneill Exp $
+# $NetBSD: MAKEDEV.conf,v 1.33 2021/07/24 11:39:18 jmcneill Exp $
 
 # As of 2003-04-17, the "init" case must not create more than 890 entries.
 all_md)
@@ -46,6 +46,7 @@ all_md)
 	makedev bio
 	makedev xmm0
 	makedev acpi
+	makedev smbios
 	;;
 
 xen)

Index: src/etc/etc.i386/MAKEDEV.conf
diff -u src/etc/etc.i386/MAKEDEV.conf:1.33 src/etc/etc.i386/MAKEDEV.conf:1.34
--- src/etc/etc.i386/MAKEDEV.conf:1.33	Sun Dec  6 02:57:30 2020
+++ src/etc/etc.i386/MAKEDEV.conf	Sat Jul 24 11:39:19 2021
@@ -1,4 +1,4 @@
-# $NetBSD: MAKEDEV.conf,v 1.33 2020/12/06 02:57:30 jmcneill Exp $
+# $NetBSD: MAKEDEV.conf,v 1.34 2021/07/24 11:39:19 jmcneill Exp $
 
 # As of 2005-03-15, the "init" case must not create more than 1024 entries.
 all_md)
@@ -50,6 +50,7 @@ all_md)
 	makedev bio
 	makedev cfs
 	makedev acpi
+	makedev smbios
 	;;
 
 xen)

Index: src/sys/arch/arm/fdt/acpi_fdt.c
diff -u src/sys/arch/arm/fdt/acpi_fdt.c:1.21 src/sys/arch/arm/fdt/acpi_fdt.c:1.22
--- src/sys/arch/arm/fdt/acpi_fdt.c:1.21	Fri Jul 23 21:33:35 2021
+++ src/sys/arch/arm/fdt/acpi_fdt.c	Sat Jul 24 11:39:19 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_fdt.c,v 1.21 2021/07/23 21:33:35 jmcneill Exp $ */
+/* $NetBSD: acpi_fdt.c,v 1.22 2021/07/24 11:39:19 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015-2017 Jared McNeill 
@@ -30,7 +30,7 @@
 #include "opt_efi.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_fdt.c,v 1.21 2021/07/23 21:33:35 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_fdt.c,v 1.22 2021/07/24 11:39:19 jmcneill Exp $");
 
 #include 
 #include 
@@ -179,6 +179,8 @@ acpi_fdt_smbios_init(device_t dev)
 		return;
 	}
 
+	smbios_entry.hdrphys = smbios_table;
+
 	smbver = acpi_fdt_smbios_version();
 	if (smbver == 3) {
 		struct smb3hdr *sh = AcpiOsMapMemory(smbios_table, sizeof(*sh));
@@ -188,6 +190,7 @@ acpi_fdt_smbios_init(device_t dev)
 
 		ptr = AcpiOsMapMemory(sh->addr, sh->size);
 		if (ptr != NULL) {
+			smbios_entry.tabphys = sh->addr;
 			smbios_entry.addr = ptr;
 			smbios_entry.len = sh->size;
 			smbios_entry.rev = sh->eprev;
@@ -208,6 +211,7 @@ acpi_fdt_smbios_init(device_t dev)
 
 		ptr = AcpiOsMapMemory(sh->addr, sh->size);
 		if (ptr != NULL) {
+			smbios_entry.tabphys = sh->addr;
 			smbios_entry.addr = ptr;
 			smbios_entry.len = sh->size;
 			smbios

CVS commit: src/sys/dev/acpi

2021-07-24 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jul 24 11:36:41 UTC 2021

Modified Files:
src/sys/dev/acpi: acpi_dev.c

Log Message:
acpi: /dev/acpi: fix bounds check when reading tables


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/acpi_dev.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/acpi/acpi_dev.c
diff -u src/sys/dev/acpi/acpi_dev.c:1.1 src/sys/dev/acpi/acpi_dev.c:1.2
--- src/sys/dev/acpi/acpi_dev.c:1.1	Sun Dec  6 02:57:30 2020
+++ src/sys/dev/acpi/acpi_dev.c	Sat Jul 24 11:36:41 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_dev.c,v 1.1 2020/12/06 02:57:30 jmcneill Exp $ */
+/* $NetBSD: acpi_dev.c,v 1.2 2021/07/24 11:36:41 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2020 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_dev.c,v 1.1 2020/12/06 02:57:30 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_dev.c,v 1.2 2021/07/24 11:36:41 jmcneill Exp $");
 
 #include 
 #include 
@@ -208,7 +208,7 @@ acpi_read(dev_t dev, struct uio *uio, in
 
 	/* Copy the contents of the table to user-space */
 	pa = uio->uio_offset;
-	len = uimin(pa - table_pa + table_len, uio->uio_resid);
+	len = uimin(table_len - (pa - table_pa), uio->uio_resid);
 	data = AcpiOsMapMemory(pa, len);
 	if (data == NULL) {
 		return ENOMEM;



CVS commit: src/sys/stand/efiboot

2021-07-24 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jul 24 10:22:28 UTC 2021

Modified Files:
src/sys/stand/efiboot: boot.c

Log Message:
efiboot: Allow "fs" as alias for "initrd", for compat with x86


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/stand/efiboot/boot.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/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.34 src/sys/stand/efiboot/boot.c:1.35
--- src/sys/stand/efiboot/boot.c:1.34	Wed Jun 23 21:43:38 2021
+++ src/sys/stand/efiboot/boot.c	Sat Jul 24 10:22:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.34 2021/06/23 21:43:38 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.35 2021/07/24 10:22:28 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -110,6 +110,7 @@ const struct boot_command commands[] = {
 	{ "dev",	command_dev,		"dev" },
 	{ "dtb",	command_dtb,		"dtb [dev:][filename]" },
 	{ "initrd",	command_initrd,		"initrd [dev:][filename]" },
+	{ "fs",		command_initrd,		NULL },
 	{ "rndseed",	command_rndseed,	"rndseed [dev:][filename]" },
 	{ "dtoverlay",	command_dtoverlay,	"dtoverlay [dev:][filename]" },
 	{ "dtoverlays",	command_dtoverlays,	"dtoverlays [{on|off|reset}]" },



CVS commit: src/distrib/evbarm

2021-07-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Jul 23 21:53:34 UTC 2021

Modified Files:
src/distrib/evbarm: Makefile
Added Files:
src/distrib/evbarm/liveimage: Makefile Makefile.liveimage
src/distrib/evbarm/liveimage/armimage: Makefile dhcpcd ec2_init
resize_gpt resize_root spec.armimage sshd

Log Message:
evbarm: Add build.sh live-image support for armv7/aarch64


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/distrib/evbarm/Makefile
cvs rdiff -u -r0 -r1.1 src/distrib/evbarm/liveimage/Makefile \
src/distrib/evbarm/liveimage/Makefile.liveimage
cvs rdiff -u -r0 -r1.1 src/distrib/evbarm/liveimage/armimage/Makefile \
src/distrib/evbarm/liveimage/armimage/dhcpcd \
src/distrib/evbarm/liveimage/armimage/ec2_init \
src/distrib/evbarm/liveimage/armimage/resize_gpt \
src/distrib/evbarm/liveimage/armimage/resize_root \
src/distrib/evbarm/liveimage/armimage/spec.armimage \
src/distrib/evbarm/liveimage/armimage/sshd

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

Modified files:

Index: src/distrib/evbarm/Makefile
diff -u src/distrib/evbarm/Makefile:1.15 src/distrib/evbarm/Makefile:1.16
--- src/distrib/evbarm/Makefile:1.15	Mon Nov 16 11:38:29 2020
+++ src/distrib/evbarm/Makefile	Fri Jul 23 21:53:33 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.15 2020/11/16 11:38:29 rin Exp $
+#	$NetBSD: Makefile,v 1.16 2021/07/23 21:53:33 jmcneill Exp $
 
 .include 
 .include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib"
@@ -8,6 +8,7 @@
 SUBDIR=		gzboot instkernel
 .if !empty(MACHINE_ARCH:Maarch64*) || !empty(MACHINE_ARCH:Mearmv7hf*)
 SUBDIR+=	installimage
+SUBDIR+=	liveimage
 .endif
 .if !empty(MACHINE_ARCH:Maarch64*)
 SUBDIR+=	isoimage
@@ -27,6 +28,9 @@ iso_image:
 	${MAKEDIRTARGET} isoimage iso_image
 .endif
 
+live_image:
+	${MAKEDIRTARGET} liveimage live_image
+
 install_image:
 	${MAKEDIRTARGET} installimage install_image
 

Added files:

Index: src/distrib/evbarm/liveimage/Makefile
diff -u /dev/null src/distrib/evbarm/liveimage/Makefile:1.1
--- /dev/null	Fri Jul 23 21:53:34 2021
+++ src/distrib/evbarm/liveimage/Makefile	Fri Jul 23 21:53:33 2021
@@ -0,0 +1,7 @@
+# $NetBSD: Makefile,v 1.1 2021/07/23 21:53:33 jmcneill Exp $
+
+SUBDIR=		armimage
+
+TARGETS+=	release live_image
+
+.include 
Index: src/distrib/evbarm/liveimage/Makefile.liveimage
diff -u /dev/null src/distrib/evbarm/liveimage/Makefile.liveimage:1.1
--- /dev/null	Fri Jul 23 21:53:34 2021
+++ src/distrib/evbarm/liveimage/Makefile.liveimage	Fri Jul 23 21:53:33 2021
@@ -0,0 +1,16 @@
+#	$NetBSD: Makefile.liveimage,v 1.1 2021/07/23 21:53:33 jmcneill Exp $
+
+.include 
+
+.if !empty(MACHINE_ARCH:Maarch64*)
+KERN_SET=		kern-GENERIC64
+EFIBOOT=		${WORKDIR}/usr/mdec/bootaa64.efi
+.else
+KERN_SET=		kern-GENERIC
+EFIBOOT=		${WORKDIR}/usr/mdec/bootarm.efi
+.endif
+
+USE_MBR=		yes
+USE_GPT=		yes
+
+.include "${.CURDIR}/../../../common/bootimage/Makefile.liveimage"

Index: src/distrib/evbarm/liveimage/armimage/Makefile
diff -u /dev/null src/distrib/evbarm/liveimage/armimage/Makefile:1.1
--- /dev/null	Fri Jul 23 21:53:34 2021
+++ src/distrib/evbarm/liveimage/armimage/Makefile	Fri Jul 23 21:53:34 2021
@@ -0,0 +1,22 @@
+#	$NetBSD: Makefile,v 1.1 2021/07/23 21:53:34 jmcneill Exp $
+
+LIVEIMGBASE=	NetBSD-${DISTRIBVER}-${MACHINE_ARCH}-live	# gives ${IMGBASE}.img
+
+EMUIMAGEMB?=	1907	# 2GB USB flash memories aren't 2GiB
+LIVEIMAGEMB=	${EMUIMAGEMB}
+SWAPMB=		0			# No swap
+IMAGEHOSTNAME=	netbsd
+
+FILESDIR!=	cd ${.CURDIR}/../../../utils/embedded/files ; pwd
+
+SPEC_EXTRA=	${.CURDIR}/spec.armimage
+IMGFILE_EXTRA=\
+	${FILESDIR}/ec2_init		etc/rc.d/ec2_init		\
+	${FILESDIR}/resize_gpt		etc/rc.d/resize_gpt		\
+	${.CURDIR}/dhcpcd		etc/rc.conf.d/dhcpcd		\
+	${.CURDIR}/ec2_init		etc/rc.conf.d/ec2_init		\
+	${.CURDIR}/resize_gpt		etc/rc.conf.d/resize_gpt	\
+	${.CURDIR}/resize_root		etc/rc.conf.d/resize_root	\
+	${.CURDIR}/sshd			etc/rc.conf.d/sshd
+
+.include "${.CURDIR}/../Makefile.liveimage"
Index: src/distrib/evbarm/liveimage/armimage/dhcpcd
diff -u /dev/null src/distrib/evbarm/liveimage/armimage/dhcpcd:1.1
--- /dev/null	Fri Jul 23 21:53:34 2021
+++ src/distrib/evbarm/liveimage/armimage/dhcpcd	Fri Jul 23 21:53:34 2021
@@ -0,0 +1,3 @@
+# $NetBSD: dhcpcd,v 1.1 2021/07/23 21:53:34 jmcneill Exp $
+
+dhcpcd=YES
Index: src/distrib/evbarm/liveimage/armimage/ec2_init
diff -u /dev/null src/distrib/evbarm/liveimage/armimage/ec2_init:1.1
--- /dev/null	Fri Jul 23 21:53:34 2021
+++ src/distrib/evbarm/liveimage/armimage/ec2_init	Fri Jul 23 21:53:34 2021
@@ -0,0 +1,31 @@
+# $NetBSD: ec2_init,v 1.1 2021/07/23 21:53:34 jmcneill Exp $
+
+is_ec2() {
+	val=NO
+	# Look for the string "amazon" in one of these sysctl nodes
+	for node in machdep.dmi.system-vendor \
+		machdep.dmi.system-version \
+		machdep.dmi.bios-version \
+		machdep.xen.version ; do
+		if /sbin/sysctl -q $node; then
+			nodeval="$(/sbin/sysctl -n $

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

2021-07-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Jul 23 21:33:35 UTC 2021

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

Log Message:
smbios: Support SMBIOS 2.x tables.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/arm/fdt/acpi_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/acpi_fdt.c
diff -u src/sys/arch/arm/fdt/acpi_fdt.c:1.20 src/sys/arch/arm/fdt/acpi_fdt.c:1.21
--- src/sys/arch/arm/fdt/acpi_fdt.c:1.20	Thu Jul 22 00:47:55 2021
+++ src/sys/arch/arm/fdt/acpi_fdt.c	Fri Jul 23 21:33:35 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_fdt.c,v 1.20 2021/07/22 00:47:55 jmcneill Exp $ */
+/* $NetBSD: acpi_fdt.c,v 1.21 2021/07/23 21:33:35 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015-2017 Jared McNeill 
@@ -30,7 +30,7 @@
 #include "opt_efi.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_fdt.c,v 1.20 2021/07/22 00:47:55 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_fdt.c,v 1.21 2021/07/23 21:33:35 jmcneill Exp $");
 
 #include 
 #include 
@@ -140,11 +140,36 @@ acpi_fdt_poweroff(device_t dev)
 		psci_system_off();
 }
 
+static int
+acpi_fdt_smbios_version(void)
+{
+	uint8_t *hdr;
+	int smbver;
+
+	if (smbios_table == 0) {
+		return 0;
+	}
+
+	hdr = AcpiOsMapMemory(smbios_table, 24);
+	if (hdr == NULL) {
+		return 0;
+	}
+	if (smbios3_check_header(hdr)) {
+		smbver = 3;
+	} else if (smbios2_check_header(hdr)) {
+		smbver = 2;
+	} else {
+		smbver = 0;
+	}
+	AcpiOsUnmapMemory(hdr, 24);
+	return smbver;
+}
+
 static void
 acpi_fdt_smbios_init(device_t dev)
 {
-	struct smb3hdr *sh;
 	uint8_t *ptr;
+	int smbver;
 
 	const int chosen = OF_finddevice("/chosen");
 	if (chosen >= 0) {
@@ -154,29 +179,48 @@ acpi_fdt_smbios_init(device_t dev)
 		return;
 	}
 
-	sh = AcpiOsMapMemory(smbios_table, sizeof(*sh));
-	if (sh == NULL) {
-		return;
-	}
-	if (!smbios3_check_header((uint8_t *)sh)) {
-		AcpiOsUnmapMemory(sh, sizeof(*sh));
-		return;
-	}
+	smbver = acpi_fdt_smbios_version();
+	if (smbver == 3) {
+		struct smb3hdr *sh = AcpiOsMapMemory(smbios_table, sizeof(*sh));
+		if (sh == NULL) {
+			return;
+		}
+
+		ptr = AcpiOsMapMemory(sh->addr, sh->size);
+		if (ptr != NULL) {
+			smbios_entry.addr = ptr;
+			smbios_entry.len = sh->size;
+			smbios_entry.rev = sh->eprev;
+			smbios_entry.mjr = sh->majrev;
+			smbios_entry.min = sh->minrev;
+			smbios_entry.doc = sh->docrev;
+			smbios_entry.count = UINT16_MAX;
+		}
 
-	ptr = AcpiOsMapMemory(sh->addr, sh->size);
-	if (ptr != NULL) {
-		smbios_entry.addr = ptr;
-		smbios_entry.len = sh->size;
-		smbios_entry.rev = sh->eprev;
-		smbios_entry.mjr = sh->majrev;
-		smbios_entry.min = sh->minrev;
-		smbios_entry.doc = sh->docrev;
-		smbios_entry.count = UINT16_MAX;
-
-		device_printf(dev, "SMBIOS rev. %d.%d.%d @ 0x%lx\n",
+		aprint_normal_dev(dev, "SMBIOS rev. %d.%d.%d @ 0x%lx\n",
 		sh->majrev, sh->minrev, sh->docrev, (u_long)sh->addr);
+		AcpiOsUnmapMemory(sh, sizeof(*sh));
+	} else if (smbver == 2) {
+		struct smbhdr *sh = AcpiOsMapMemory(smbios_table, sizeof(*sh));
+		if (sh == NULL) {
+			return;
+		}
+
+		ptr = AcpiOsMapMemory(sh->addr, sh->size);
+		if (ptr != NULL) {
+			smbios_entry.addr = ptr;
+			smbios_entry.len = sh->size;
+			smbios_entry.rev = 0;
+			smbios_entry.mjr = sh->majrev;
+			smbios_entry.min = sh->minrev;
+			smbios_entry.doc = 0;
+			smbios_entry.count = sh->count;
+		}
+
+		aprint_normal_dev(dev, "SMBIOS rev. %d.%d @ 0x%lx (%d entries)\n",
+		sh->majrev, sh->minrev, (u_long)sh->addr, sh->count);
+		AcpiOsUnmapMemory(sh, sizeof(*sh));
 	}
-	AcpiOsUnmapMemory(sh, sizeof(*sh));
 }
 
 static void



CVS commit: src/sys/stand/efiboot

2021-07-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Jul 23 21:33:00 UTC 2021

Modified Files:
src/sys/stand/efiboot: efiacpi.c smbios.c

Log Message:
efiboot: Add support for SMBIOS 2.x tables.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/stand/efiboot/efiacpi.c
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/smbios.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/stand/efiboot/efiacpi.c
diff -u src/sys/stand/efiboot/efiacpi.c:1.9 src/sys/stand/efiboot/efiacpi.c:1.10
--- src/sys/stand/efiboot/efiacpi.c:1.9	Fri May 21 21:53:15 2021
+++ src/sys/stand/efiboot/efiacpi.c	Fri Jul 23 21:33:00 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efiacpi.c,v 1.9 2021/05/21 21:53:15 jmcneill Exp $ */
+/* $NetBSD: efiacpi.c,v 1.10 2021/07/23 21:33:00 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -52,10 +52,11 @@ struct acpi_rdsp {
 
 static EFI_GUID Acpi20TableGuid = ACPI_20_TABLE_GUID;
 static EFI_GUID Smbios3TableGuid = SMBIOS3_TABLE_GUID;
+static EFI_GUID SmbiosTableGuid = SMBIOS_TABLE_GUID;
 
 static int acpi_enable = 1;
 static void *acpi_root = NULL;
-static void *smbios3_table = NULL;
+static void *smbios_table = NULL;
 
 int
 efi_acpi_probe(void)
@@ -66,9 +67,13 @@ efi_acpi_probe(void)
 	if (EFI_ERROR(status))
 		return EIO;
 
-	status = LibGetSystemConfigurationTable(&Smbios3TableGuid, &smbios3_table);
-	if (EFI_ERROR(status))
-		smbios3_table = NULL;
+	status = LibGetSystemConfigurationTable(&Smbios3TableGuid, &smbios_table);
+	if (EFI_ERROR(status)) {
+		status = LibGetSystemConfigurationTable(&SmbiosTableGuid, &smbios_table);
+	}
+	if (EFI_ERROR(status)) {
+		smbios_table = NULL;
+	}
 
 	return 0;
 }
@@ -103,8 +108,8 @@ efi_acpi_get_model(void)
 
 	memset(model_buf, 0, sizeof(model_buf));
 
-	if (smbios3_table != NULL) {
-		smbios_init(smbios3_table);
+	if (smbios_table != NULL) {
+		smbios_init(smbios_table);
 
 		buf = model_buf;
 		smbios.cookie = 0;
@@ -136,7 +141,7 @@ efi_acpi_show(void)
 	rsdp->oemid[0], rsdp->oemid[1], rsdp->oemid[2],
 	rsdp->oemid[3], rsdp->oemid[4], rsdp->oemid[5]);
 
-	if (smbios3_table)
+	if (smbios_table)
 		printf("SMBIOS: %s\n", efi_acpi_get_model());
 }
 
@@ -166,8 +171,8 @@ efi_acpi_create_fdt(void)
 
 	fdt_add_subnode(fdt, fdt_path_offset(fdt, "/"), "chosen");
 	fdt_setprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,acpi-root-table", (uint64_t)(uintptr_t)acpi_root);
-	if (smbios3_table)
-		fdt_setprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,smbios-table", (uint64_t)(uintptr_t)smbios3_table);
+	if (smbios_table)
+		fdt_setprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,smbios-table", (uint64_t)(uintptr_t)smbios_table);
 
 	fdt_add_subnode(fdt, fdt_path_offset(fdt, "/"), "acpi");
 	fdt_setprop_string(fdt, fdt_path_offset(fdt, "/acpi"), "compatible", "netbsd,acpi");

Index: src/sys/stand/efiboot/smbios.c
diff -u src/sys/stand/efiboot/smbios.c:1.2 src/sys/stand/efiboot/smbios.c:1.3
--- src/sys/stand/efiboot/smbios.c:1.2	Fri Dec 27 09:45:27 2019
+++ src/sys/stand/efiboot/smbios.c	Fri Jul 23 21:33:00 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: smbios.c,v 1.2 2019/12/27 09:45:27 msaitoh Exp $	*/
+/*	$NetBSD: smbios.c,v 1.3 2021/07/23 21:33:00 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -82,7 +82,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: smbios.c,v 1.2 2019/12/27 09:45:27 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: smbios.c,v 1.3 2021/07/23 21:33:00 jmcneill Exp $");
 
 #include 
 
@@ -91,8 +91,22 @@ __KERNEL_RCSID(0, "$NetBSD: smbios.c,v 1
 
 struct smbios_entry smbios_entry;
 
-void
-smbios_init(uint8_t *p)
+static void
+smbios2_init(uint8_t *p)
+{
+	const struct smbhdr *sh = (const struct smbhdr *)p;
+
+	smbios_entry.addr = (void *)(uintptr_t)sh->addr;
+	smbios_entry.len = sh->size;
+	smbios_entry.rev = 0;
+	smbios_entry.mjr = sh->majrev;
+	smbios_entry.min = sh->minrev;
+	smbios_entry.doc = 0;
+	smbios_entry.count = sh->count;
+}
+
+static void
+smbios3_init(uint8_t *p)
 {
 	const struct smb3hdr *sh = (const struct smb3hdr *)p;
 
@@ -105,6 +119,16 @@ smbios_init(uint8_t *p)
 	smbios_entry.count = UINT16_MAX;
 }
 
+void
+smbios_init(uint8_t *p)
+{
+	if (memcmp(p, "_SM3_", 5) == 0) {
+		smbios3_init(p);
+	} else if (memcmp(p, "_SM_", 4) == 0) {
+		smbios2_init(p);
+	}
+}
+
 /*
  * smbios_find_table() takes a caller supplied smbios struct type and
  * a pointer to a handle (struct smbtable) returning one if the structure
@@ -121,6 +145,10 @@ smbios_find_table(uint8_t type, struct s
 	struct smbtblhdr *hdr;
 	int ret = 0, tcount = 1;
 
+	if (smbios_entry.addr == 0) {
+		return 0;
+	}
+
 	va = smbios_entry.addr;
 	end = va + smbios_entry.len;
 
@@ -173,6 +201,10 @@ smbios_get_string(struct smbtable *st, u
 	char *ret = NULL;
 	int i;
 
+	if (smbios_entry.addr == 0) {
+		return NULL;
+	}
+
 	va = (uint8_t *)st->hdr + st->hdr->size;
 	end = smbios_entry.addr + 

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

2021-07-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Jul 22 00:47:56 UTC 2021

Modified Files:
src/sys/arch/arm/fdt: acpi_fdt.c files.fdt

Log Message:
Expose SMBIOS tables using sysctl machdep.dmi.*, same as x86.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/arm/fdt/acpi_fdt.c
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/arm/fdt/files.fdt

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/acpi_fdt.c
diff -u src/sys/arch/arm/fdt/acpi_fdt.c:1.19 src/sys/arch/arm/fdt/acpi_fdt.c:1.20
--- src/sys/arch/arm/fdt/acpi_fdt.c:1.19	Sat Apr 24 23:36:26 2021
+++ src/sys/arch/arm/fdt/acpi_fdt.c	Thu Jul 22 00:47:55 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_fdt.c,v 1.19 2021/04/24 23:36:26 thorpej Exp $ */
+/* $NetBSD: acpi_fdt.c,v 1.20 2021/07/22 00:47:55 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015-2017 Jared McNeill 
@@ -30,7 +30,7 @@
 #include "opt_efi.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_fdt.c,v 1.19 2021/04/24 23:36:26 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_fdt.c,v 1.20 2021/07/22 00:47:55 jmcneill Exp $");
 
 #include 
 #include 
@@ -47,6 +47,7 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_fdt.c,v
 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -61,6 +62,7 @@ static void	acpi_fdt_attach(device_t, de
 
 static void	acpi_fdt_poweroff(device_t);
 
+static void	acpi_fdt_smbios_init(device_t);
 static void	acpi_fdt_sysctl_init(void);
 
 extern struct arm32_bus_dma_tag acpi_coherent_dma_tag;
@@ -89,18 +91,24 @@ acpi_fdt_match(device_t parent, cfdata_t
 static void
 acpi_fdt_attach(device_t parent, device_t self, void *aux)
 {
+	extern void platform_init(void); /* XXX */
 	struct fdt_attach_args * const faa = aux;
 	struct acpibus_attach_args aa;
 
 	aprint_naive("\n");
 	aprint_normal("\n");
 
+	acpi_fdt_smbios_init(self);
+	platform_init();
+
 	fdtbus_register_power_controller(self, faa->faa_phandle,
 	&acpi_fdt_power_funcs);
 
 	if (!acpi_probe())
 		panic("ACPI subsystem failed to initialize");
 
+	platform_init();
+
 	memset(&aa, 0, sizeof(aa));
 #if NPCI > 0
 	aa.aa_pciflags =
@@ -133,26 +141,64 @@ acpi_fdt_poweroff(device_t dev)
 }
 
 static void
+acpi_fdt_smbios_init(device_t dev)
+{
+	struct smb3hdr *sh;
+	uint8_t *ptr;
+
+	const int chosen = OF_finddevice("/chosen");
+	if (chosen >= 0) {
+		of_getprop_uint64(chosen, "netbsd,smbios-table", &smbios_table);
+	}
+	if (smbios_table == 0) {
+		return;
+	}
+
+	sh = AcpiOsMapMemory(smbios_table, sizeof(*sh));
+	if (sh == NULL) {
+		return;
+	}
+	if (!smbios3_check_header((uint8_t *)sh)) {
+		AcpiOsUnmapMemory(sh, sizeof(*sh));
+		return;
+	}
+
+	ptr = AcpiOsMapMemory(sh->addr, sh->size);
+	if (ptr != NULL) {
+		smbios_entry.addr = ptr;
+		smbios_entry.len = sh->size;
+		smbios_entry.rev = sh->eprev;
+		smbios_entry.mjr = sh->majrev;
+		smbios_entry.min = sh->minrev;
+		smbios_entry.doc = sh->docrev;
+		smbios_entry.count = UINT16_MAX;
+
+		device_printf(dev, "SMBIOS rev. %d.%d.%d @ 0x%lx\n",
+		sh->majrev, sh->minrev, sh->docrev, (u_long)sh->addr);
+	}
+	AcpiOsUnmapMemory(sh, sizeof(*sh));
+}
+
+static void
 acpi_fdt_sysctl_init(void)
 {
 	const struct sysctlnode *rnode;
 	int error;
 
-	const int chosen = OF_finddevice("/chosen");
-	if (chosen >= 0)
-		of_getprop_uint64(chosen, "netbsd,smbios-table", &smbios_table);
+	if (smbios_table == 0) {
+		return;
+	}
 
 	error = sysctl_createv(NULL, 0, NULL, &rnode,
 	CTLFLAG_PERMANENT, CTLTYPE_NODE, "machdep", NULL,
 	NULL, 0, NULL, 0, CTL_MACHDEP, CTL_EOL);
-	if (error)
+	if (error) {
 		return;
-
-	if (smbios_table != 0) {
-		(void)sysctl_createv(NULL, 0, &rnode, NULL,
-		CTLFLAG_PERMANENT | CTLFLAG_READONLY | CTLFLAG_HEX, CTLTYPE_QUAD,
-		"smbios", SYSCTL_DESCR("SMBIOS table pointer"),
-		NULL, 0, &smbios_table, sizeof(smbios_table),
-		CTL_CREATE, CTL_EOL);
 	}
+
+	(void)sysctl_createv(NULL, 0, &rnode, NULL,
+	CTLFLAG_PERMANENT | CTLFLAG_READONLY | CTLFLAG_HEX, CTLTYPE_QUAD,
+	"smbios", SYSCTL_DESCR("SMBIOS table pointer"),
+	NULL, 0, &smbios_table, sizeof(smbios_table),
+	CTL_CREATE, CTL_EOL);
 }

Index: src/sys/arch/arm/fdt/files.fdt
diff -u src/sys/arch/arm/fdt/files.fdt:1.33 src/sys/arch/arm/fdt/files.fdt:1.34
--- src/sys/arch/arm/fdt/files.fdt:1.33	Mon Apr 26 14:44:16 2021
+++ src/sys/arch/arm/fdt/files.fdt	Thu Jul 22 00:47:55 2021
@@ -1,4 +1,4 @@
-# $NetBSD: files.fdt,v 1.33 2021/04/26 14:44:16 thorpej Exp $
+# $NetBSD: files.fdt,v 1.34 2021/07/22 00:47:55 jmcneill Exp $
 
 include	"dev/pckbport/files.pckbport"
 
@@ -75,6 +75,7 @@ file	arch/arm/fdt/pmu_fdt.c			pmu_fdt
 attach	genfb at fdt with plfb_fdt: fdt_display_timing
 file	arch/arm/fdt/plfb_fdt.c			plfb_fdt
 
-device	acpifdt: acpibus
+device	acpifdt: acpibus, smbios
 attach	acpifdt at fdt with acpi_fdt
 file	arch/arm/fdt/acpi_fdt.c			acpi_fdt
+file	dev/smbios_platform.c			acpi_fdt



CVS commit: src/sys

2021-07-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jul 21 23:26:15 UTC 2021

Modified Files:
src/sys/arch/x86/conf: files.x86
Added Files:
src/sys/dev: smbios_platform.c
Removed Files:
src/sys/arch/x86/x86: platform.c

Log Message:
x86's platform.c no longer has any x86 specific code in it, so move it to
dev/smbios_platform.c to let other ports use it


To generate a diff of this commit:
cvs rdiff -u -r1.121 -r1.122 src/sys/arch/x86/conf/files.x86
cvs rdiff -u -r1.17 -r0 src/sys/arch/x86/x86/platform.c
cvs rdiff -u -r0 -r1.1 src/sys/dev/smbios_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/x86/conf/files.x86
diff -u src/sys/arch/x86/conf/files.x86:1.121 src/sys/arch/x86/conf/files.x86:1.122
--- src/sys/arch/x86/conf/files.x86:1.121	Wed Jul 21 23:16:08 2021
+++ src/sys/arch/x86/conf/files.x86	Wed Jul 21 23:26:15 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: files.x86,v 1.121 2021/07/21 23:16:08 jmcneill Exp $
+#	$NetBSD: files.x86,v 1.122 2021/07/21 23:26:15 jmcneill Exp $
 
 # options for MP configuration through the MP spec
 defflag opt_mpbios.h MPBIOS MPDEBUG MPBIOS_SCANPCI
@@ -103,7 +103,7 @@ file	arch/x86/x86/idt.c		machdep
 file	arch/x86/x86/ipi.c		machdep & !xenpv
 file	arch/x86/x86/mtrr_i686.c	mtrr & !xenpv
 file 	arch/x86/x86/patch.c		machdep & !xenpv
-file	arch/x86/x86/platform.c		machdep
+file	dev/smbios_platform.c		machdep
 file 	arch/x86/x86/pmap.c		machdep
 file 	arch/x86/x86/x86_tlb.c		machdep
 file	arch/x86/x86/procfs_machdep.c	procfs

Added files:

Index: src/sys/dev/smbios_platform.c
diff -u /dev/null src/sys/dev/smbios_platform.c:1.1
--- /dev/null	Wed Jul 21 23:26:15 2021
+++ src/sys/dev/smbios_platform.c	Wed Jul 21 23:26:15 2021
@@ -0,0 +1,321 @@
+/* $NetBSD: smbios_platform.c,v 1.1 2021/07/21 23:26:15 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2007 Jared D. 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 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 "isa.h"
+
+#include 
+__KERNEL_RCSID(0, "$NetBSD: smbios_platform.c,v 1.1 2021/07/21 23:26:15 jmcneill Exp $");
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#if NISA > 0
+#include 
+#endif
+
+#include 
+
+static int platform_dminode = CTL_EOL;
+
+void		platform_init(void);	/* XXX */
+static void	platform_add(struct smbtable *, const char *, int);
+static void	platform_add_word(struct smbtable *, const char *, uint16_t,
+const char *);
+static void	platform_add_date(struct smbtable *, const char *, int);
+static void	platform_add_uuid(struct smbtable *, const char *,
+  const uint8_t *);
+static int	platform_dmi_sysctl(SYSCTLFN_PROTO);
+
+/* list of private DMI sysctl nodes */
+static const char *platform_private_nodes[] = {
+	"chassis-serial",
+	"board-serial",
+	"system-serial",
+	"system-uuid",
+	NULL
+};
+
+void
+platform_init(void)
+{
+	struct smbtable smbios;
+	struct smbios_sys *psys;
+	struct smbios_struct_bios *pbios;
+	struct smbios_board *pboard;
+	struct smbios_chassis *pchassis;
+	struct smbios_processor *pproc;
+	struct smbios_slot *pslot;
+	int nisa, nother;
+
+	smbios.cookie = 0;
+	if (smbios_find_table(SMBIOS_TYPE_SYSTEM, &smbios)) {
+		psys = smbios.tblhdr;
+
+		platform_add(&smbios, "system-vendor", psys->vendor);
+		platform_add(&smbios, "system-product", psys->product);
+		platform_add(&smbios, "system-version", psys->version);
+		platform_add(&smbios, "system-serial", psys->serial);
+		platform_add_uuid(&smbios, "sy

CVS commit: src/sys

2021-07-21 Thread Jared D. McNeill
] != '_')
-		return 0;
-	i = sh->len;
-	for (chksum = 0; i--; )
-		chksum += p[i];
-	if (chksum != 0)
-		return 0;
-	if (sh->eprev != SMBIOS3_EPREV_3_0)
-		return 0;
-
-	return 1;
-}
-
 static void
 smbios3_map_kva(const uint8_t *p)
 {
@@ -353,87 +304,3 @@ smbios3_map_kva(const uint8_t *p)
 	aprint_debug("SMBIOS rev. %d.%d.%d @ 0x%lx\n", sh->majrev,
 	sh->minrev, sh->docrev, (u_long)sh->addr);
 }
-
-/*
- * smbios_find_table() takes a caller supplied smbios struct type and
- * a pointer to a handle (struct smbtable) returning one if the structure
- * is successfully located and zero otherwise. Callers should take care
- * to initilize the cookie field of the smbtable structure to zero before
- * the first invocation of this function.
- * Multiple tables of the same type can be located by repeadtly calling
- * smbios_find_table with the same arguments.
- */
-int
-smbios_find_table(uint8_t type, struct smbtable *st)
-{
-	uint8_t *va, *end;
-	struct smbtblhdr *hdr;
-	int ret = 0, tcount = 1;
-
-	va = smbios_entry.addr;
-	end = va + smbios_entry.len;
-
-	/*
-	 * The cookie field of the smtable structure is used to locate
-	 * multiple instances of a table of an arbitrary type. Following the
-	 * sucessful location of a table, the type is encoded as bits 0:7 of
-	 * the cookie value, the offset in terms of the number of structures
-	 * preceding that referenced by the handle is encoded in bits 15:31.
-	 */
-	if ((st->cookie & 0xfff) == type && st->cookie >> 16) {
-		if ((uint8_t *)st->hdr >= va && (uint8_t *)st->hdr < end) {
-			hdr = st->hdr;
-			if (hdr->type == type) {
-va = (uint8_t *)hdr + hdr->size;
-for (; va + 1 < end; va++)
-	if (*va == 0 && *(va + 1) == 0)
-		break;
-va+= 2;
-tcount = st->cookie >> 16;
-			}
-		}
-	}
-	for (; va + sizeof(struct smbtblhdr) < end && tcount <=
-	smbios_entry.count; tcount++) {
-		hdr = (struct smbtblhdr *)va;
-		if (hdr->type == type) {
-			ret = 1;
-			st->hdr = hdr;
-			st->tblhdr = va + sizeof(struct smbtblhdr);
-			st->cookie = (tcount + 1) << 16 | type;
-			break;
-		}
-		if (hdr->type == SMBIOS_TYPE_EOT)
-			break;
-		va+= hdr->size;
-		for (; va + 1 < end; va++)
-			if (*va == 0 && *(va + 1) == 0)
-break;
-		va+=2;
-	}
-
-	return ret;
-}
-
-char *
-smbios_get_string(struct smbtable *st, uint8_t indx, char *dest, size_t len)
-{
-	uint8_t *va, *end;
-	char *ret = NULL;
-	int i;
-
-	va = (uint8_t *)st->hdr + st->hdr->size;
-	end = smbios_entry.addr + smbios_entry.len;
-	for (i = 1; va < end && i < indx && *va; i++)
-		while (*va++)
-			;
-	if (i == indx) {
-		if (va + len < end) {
-			ret = dest;
-			memcpy(ret, va, len);
-			ret[len - 1] = '\0';
-		}
-	}
-
-	return ret;
-}

Index: src/sys/arch/x86/x86/platform.c
diff -u src/sys/arch/x86/x86/platform.c:1.16 src/sys/arch/x86/x86/platform.c:1.17
--- src/sys/arch/x86/x86/platform.c:1.16	Tue Dec 25 16:45:02 2018
+++ src/sys/arch/x86/x86/platform.c	Wed Jul 21 23:16:09 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: platform.c,v 1.16 2018/12/25 16:45:02 mlelstv Exp $ */
+/* $NetBSD: platform.c,v 1.17 2021/07/21 23:16:09 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -29,7 +29,7 @@
 #include "isa.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: platform.c,v 1.16 2018/12/25 16:45:02 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: platform.c,v 1.17 2021/07/21 23:16:09 jmcneill Exp $");
 
 #include 
 #include 
@@ -42,7 +42,7 @@ __KERNEL_RCSID(0, "$NetBSD: platform.c,v
 #include 
 #endif
 
-#include 
+#include 
 
 static int platform_dminode = CTL_EOL;
 

Index: src/sys/arch/x86/x86/x86_ipmi.c
diff -u src/sys/arch/x86/x86/x86_ipmi.c:1.1 src/sys/arch/x86/x86/x86_ipmi.c:1.2
--- src/sys/arch/x86/x86/x86_ipmi.c:1.1	Tue Dec 25 11:56:13 2018
+++ src/sys/arch/x86/x86/x86_ipmi.c	Wed Jul 21 23:16:09 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_ipmi.c,v 1.1 2018/12/25 11:56:13 mlelstv Exp $ */
+/*	$NetBSD: x86_ipmi.c,v 1.2 2021/07/21 23:16:09 jmcneill Exp $ */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -52,7 +52,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_ipmi.c,v 1.1 2018/12/25 11:56:13 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_ipmi.c,v 1.2 2021/07/21 23:16:09 jmcneill Exp $");
 
 #include 
 #include 
@@ -62,7 +62,7 @@ __KERNEL_RCSID(0, "$NetBSD: x86_ipmi.c,v
 #include 
 #include 
 
-#include 
+#include 
 
 #include 
 #include 

Index: src/sys/conf/files
diff -u src/sys/conf/files:1.1286 src/sys/conf/files:1.1287
--- src/sys/conf/files:1.1286	Tue Jun  1 03:51:33 2021
+++ src/sys/conf/files	Wed Jul 21 23:16:09 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: files,v 1.1286 2021/06/01 03:51:33 yamaguchi Exp $
+#	$NetBSD: files,v 1.1287 2021/07/21 23:16:09 jmcneill Exp $
 #	@(#)files.newconf	7.5 (Berkeley) 5/10/93
 
 version 	20171118
@@ -378,6 +3

CVS commit: src/sys

2021-07-19 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Jul 19 21:16:33 UTC 2021

Modified Files:
src/sys/dev/pci: if_ena.c if_enavar.h
src/sys/external/bsd/ena-com: ena_plat.h

Log Message:
Various ena(4) bug fixes, from KUSABA Takeshi :

[PATCH 01/32] include device_xname for evcnt group.
[PATCH 02/32] fix improper NULL check.
[PATCH 03/32] add tx drop counter
[PATCH 04/32] remove unimplemented m_getjcl
[PATCH 05/32] make ENA_MEM_{ALLOC,FREE}_COHERENT symmetric.
[PATCH 06/32] disestablish the correct interrupt.
[PATCH 07/32] fix null check target.
[PATCH 08/32] use if_initialize() and if_register() instead of
[PATCH 09/32] free all pci-related resource.
[PATCH 10/32] no need to call if_free(), but to call if_detach
[PATCH 11/32] add some locking assertions.
[PATCH 12/32] use bus_size_t for bus_dma instead of uint32_t.
[PATCH 13/32] no need to pass interlock, ena_timer_service does not
[PATCH 14/32] enable ena(4) to down I/F
[PATCH 15/32] destroy I/O queues before disestablishing msix
[PATCH 16/32] count input/output packet stats.
[PATCH 17/32] fix missing #ifdef LRO, NetBSD does not support LRO
[PATCH 18/32] MP-ify TX, allocate mbuf queue to each TX ring.
[PATCH 19/32] down the interface first when to detach, to prevent
[PATCH 20/32] default link speed should be unknown.
[PATCH 21/32] protect ena_adapter members only by "global_mtx".
[PATCH 22/32] lower global_mtx interrupt level
[PATCH 23/32] reorder function declaration
[PATCH 24/32] add locking notes and some marking.
[PATCH 25/32] process RX in workqueue context, as same as FreeBSD
[PATCH 26/32] count rx_drops correctly.
[PATCH 27/32] no need to lock when attach/detach, down/up
[PATCH 28/32] fix memory leak.
[PATCH 29/32] add "stopping" flag to ena_ring.
[PATCH 30/32] make the flags atomic.
[PATCH 31/32] do not schedule timer when device is down.
[PATCH 32/32] no need to start timer if I/F is down.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/dev/pci/if_ena.c
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/pci/if_enavar.h
cvs rdiff -u -r1.6 -r1.7 src/sys/external/bsd/ena-com/ena_plat.h

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

Modified files:

Index: src/sys/dev/pci/if_ena.c
diff -u src/sys/dev/pci/if_ena.c:1.28 src/sys/dev/pci/if_ena.c:1.29
--- src/sys/dev/pci/if_ena.c:1.28	Thu Jul  1 17:22:10 2021
+++ src/sys/dev/pci/if_ena.c	Mon Jul 19 21:16:33 2021
@@ -36,7 +36,7 @@
 #if 0
 __FBSDID("$FreeBSD: head/sys/dev/ena/ena.c 333456 2018-05-10 09:37:54Z mw $");
 #endif
-__KERNEL_RCSID(0, "$NetBSD: if_ena.c,v 1.28 2021/07/01 17:22:10 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ena.c,v 1.29 2021/07/19 21:16:33 jmcneill Exp $");
 
 #include 
 #include 
@@ -72,112 +72,154 @@ __KERNEL_RCSID(0, "$NetBSD: if_ena.c,v 1
 /*
  *  Function prototypes
  */
+/* cfattach interface functions */
 static int	ena_probe(device_t, cfdata_t, void *);
-static int	ena_intr_msix_mgmnt(void *);
+static void	ena_attach(device_t, device_t, void *);
+static int	ena_detach(device_t, int);
+
+/* ifnet interface functions */
+static int	ena_init(struct ifnet *);
+static void	ena_stop(struct ifnet *, int);
+static int	ena_ioctl(struct ifnet *, u_long, void *);
+static int	ena_media_change(struct ifnet *);
+static void	ena_media_status(struct ifnet *, struct ifmediareq *);
+static int	ena_mq_start(struct ifnet *, struct mbuf *);
+
+/* attach or detach */
+static int	ena_calc_io_queue_num(struct pci_attach_args *,
+		struct ena_adapter *,
+		struct ena_com_dev_get_features_ctx *);
+static int	ena_calc_queue_size(struct ena_adapter *, uint16_t *,
+		uint16_t *, struct ena_com_dev_get_features_ctx *);
+
 static int	ena_allocate_pci_resources(struct pci_attach_args *,
 		struct ena_adapter *);
 static void	ena_free_pci_resources(struct ena_adapter *);
-static int	ena_change_mtu(struct ifnet *, int);
+static void	ena_free_irqs(struct ena_adapter*);
+
 static void	ena_init_io_rings_common(struct ena_adapter *,
-struct ena_ring *, uint16_t);
+struct ena_ring *, uint16_t);
 static void	ena_init_io_rings(struct ena_adapter *);
 static void	ena_free_io_ring_resources(struct ena_adapter *, unsigned int);
 static void	ena_free_all_io_rings_resources(struct ena_adapter *);
-#if 0
-static int	ena_setup_tx_dma_tag(struct ena_adapter *);
-static int	ena_free_tx_dma_tag(struct ena_adapter *);
-static int	ena_setup_rx_dma_tag(struct ena_adapter *);
-static int	ena_free_rx_dma_tag(struct ena_adapter *);
-#endif
-static int	ena_setup_tx_resources(struct ena_adapter *, int);
-static void	ena_free_tx_resources(struct ena_adapter *, int);
-static int	ena_setup_all_tx_resources(struct ena_adapter *);
-static void	ena_free_all_tx_resources(struct ena_adapter *);
-static inline int validate_rx_req_id(struct ena_ring *, uint16

CVS commit: src/distrib/utils/embedded/conf

2021-07-06 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Jul  6 11:49:36 UTC 2021

Modified Files:
src/distrib/utils/embedded/conf: evbarm.conf evbmips.conf rpi_inst.conf
usermode.conf x86.conf

Log Message:
Disable kernfs on live images -- it is not required.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/distrib/utils/embedded/conf/evbarm.conf
cvs rdiff -u -r1.2 -r1.3 src/distrib/utils/embedded/conf/evbmips.conf
cvs rdiff -u -r1.17 -r1.18 src/distrib/utils/embedded/conf/rpi_inst.conf
cvs rdiff -u -r1.5 -r1.6 src/distrib/utils/embedded/conf/usermode.conf
cvs rdiff -u -r1.9 -r1.10 src/distrib/utils/embedded/conf/x86.conf

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

Modified files:

Index: src/distrib/utils/embedded/conf/evbarm.conf
diff -u src/distrib/utils/embedded/conf/evbarm.conf:1.38 src/distrib/utils/embedded/conf/evbarm.conf:1.39
--- src/distrib/utils/embedded/conf/evbarm.conf:1.38	Wed Dec 23 10:35:18 2020
+++ src/distrib/utils/embedded/conf/evbarm.conf	Tue Jul  6 11:49:36 2021
@@ -1,4 +1,4 @@
-# $NetBSD: evbarm.conf,v 1.38 2020/12/23 10:35:18 rin Exp $
+# $NetBSD: evbarm.conf,v 1.39 2021/07/06 11:49:36 jmcneill Exp $
 # evbarm shared config
 #
 image=$HOME/${board}.img
@@ -71,7 +71,6 @@ make_fstab_evbarm_gpt() {
 # See /usr/share/examples/fstab/ for more examples.
 NAME=${gpt_label_ffs:-netbsd-root}	/		ffs	rw,noatime	1 1
 NAME=${gpt_label_boot:-EFI}		/boot		msdos	rw	1 1
-kernfs		/kern		kernfs	rw
 ptyfs		/dev/pts	ptyfs	rw
 procfs		/proc		procfs	rw
 tmpfs		/var/shm	tmpfs	rw,-m1777,-sram%25
@@ -84,7 +83,6 @@ make_fstab_evbarm_normal() {
 # See /usr/share/examples/fstab/ for more examples.
 ROOT.a		/		ffs	rw,noatime	1 1
 ROOT.e		/boot		msdos	rw	1 1
-kernfs		/kern		kernfs	rw
 ptyfs		/dev/pts	ptyfs	rw
 procfs		/proc		procfs	rw
 tmpfs		/var/shm	tmpfs	rw,-m1777,-sram%25
@@ -100,7 +98,6 @@ make_fstab_evbarm_minwrites() {
 # See /usr/share/examples/fstab/ for more examples.
 ROOT.a		/			ffs	rw,log,noatime,nodevmtime 1 1
 ROOT.e		/boot			msdos	rw			  1 1
-kernfs		/kern			kernfs	rw
 ptyfs		/dev/pts		ptyfs	rw
 procfs		/proc			procfs	rw
 tmpfs		/tmp			tmpfs	rw,-s32M
@@ -128,8 +125,6 @@ make_fstab_evbarm() {
 	# Missing mount points from fstab
 	echo "./proc type=dir uname=root gname=wheel mode=0755" \
 	>> "$tmp/selected_sets"
-	echo "./kern type=dir uname=root gname=wheel mode=0755" \
-	>> "$tmp/selected_sets"
 }
 
 customize_evbarm() {

Index: src/distrib/utils/embedded/conf/evbmips.conf
diff -u src/distrib/utils/embedded/conf/evbmips.conf:1.2 src/distrib/utils/embedded/conf/evbmips.conf:1.3
--- src/distrib/utils/embedded/conf/evbmips.conf:1.2	Wed Dec 23 10:35:18 2020
+++ src/distrib/utils/embedded/conf/evbmips.conf	Tue Jul  6 11:49:36 2021
@@ -1,4 +1,4 @@
-# $NetBSD: evbmips.conf,v 1.2 2020/12/23 10:35:18 rin Exp $
+# $NetBSD: evbmips.conf,v 1.3 2021/07/06 11:49:36 jmcneill Exp $
 # evbmips shared config
 #
 image=$HOME/${board}.img
@@ -71,7 +71,6 @@ make_fstab_evbmips_gpt() {
 # See /usr/share/examples/fstab/ for more examples.
 NAME=${gpt_label_ffs:-netbsd-root}	/		ffs	rw,noatime	1 1
 NAME=${gpt_label_boot:-boot}		/boot		msdos	rw	1 1
-kernfs		/kern		kernfs	rw
 ptyfs		/dev/pts	ptyfs	rw
 procfs		/proc		procfs	rw
 tmpfs		/var/shm	tmpfs	rw,-m1777,-sram%25
@@ -84,7 +83,6 @@ make_fstab_evbmips_normal() {
 # See /usr/share/examples/fstab/ for more examples.
 ROOT.a		/		ffs	rw,noatime	1 1
 ROOT.e		/boot		msdos	rw	1 1
-kernfs		/kern		kernfs	rw
 ptyfs		/dev/pts	ptyfs	rw
 procfs		/proc		procfs	rw
 tmpfs		/var/shm	tmpfs	rw,-m1777,-sram%25
@@ -100,7 +98,6 @@ make_fstab_evbmips_minwrites() {
 # See /usr/share/examples/fstab/ for more examples.
 ROOT.a		/			ffs	rw,log,noatime,nodevmtime 1 1
 ROOT.e		/boot			msdos	rw			  1 1
-kernfs		/kern			kernfs	rw
 ptyfs		/dev/pts		ptyfs	rw
 procfs		/proc			procfs	rw
 tmpfs		/tmp			tmpfs	rw,-s32M
@@ -128,8 +125,6 @@ make_fstab_evbmips() {
 	# Missing mount points from fstab
 	echo "./proc type=dir uname=root gname=wheel mode=0755" \
 	>> "$tmp/selected_sets"
-	echo "./kern type=dir uname=root gname=wheel mode=0755" \
-	>> "$tmp/selected_sets"
 }
 
 customize_evbmips() {

Index: src/distrib/utils/embedded/conf/rpi_inst.conf
diff -u src/distrib/utils/embedded/conf/rpi_inst.conf:1.17 src/distrib/utils/embedded/conf/rpi_inst.conf:1.18
--- src/distrib/utils/embedded/conf/rpi_inst.conf:1.17	Tue Dec  1 04:21:10 2020
+++ src/distrib/utils/embedded/conf/rpi_inst.conf	Tue Jul  6 11:49:36 2021
@@ -1,4 +1,4 @@
-# $NetBSD: rpi_inst.conf,v 1.17 2020/12/01 04:21:10 rin Exp $
+# $NetBSD: rpi_inst.conf,v 1.18 2021/07/06 11:49:36 jmcneill Exp $
 # Raspberry Pi customization script used by mkimage
 #
 
@@ -24,7 +24,7 @@ make_label() {
 
 customize() {
 	echo "${bar} creating directories ${bar}"
-	mkdir ${mnt}/proc ${mnt}/kern
+	mkdir ${mnt}/proc
 }
 
 make_fstab() {

Index: src/distrib/utils/embedded/conf/usermode.conf
diff -u src/distrib/utils/embedded/conf/usermode.conf:1.

CVS commit: src/share/examples/pud/intro

2021-07-06 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Jul  6 09:30:07 UTC 2021

Modified Files:
src/share/examples/pud/intro: doioctl.c

Log Message:
build fix


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/share/examples/pud/intro/doioctl.c

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

Modified files:

Index: src/share/examples/pud/intro/doioctl.c
diff -u src/share/examples/pud/intro/doioctl.c:1.1 src/share/examples/pud/intro/doioctl.c:1.2
--- src/share/examples/pud/intro/doioctl.c:1.1	Thu Nov 22 11:28:48 2007
+++ src/share/examples/pud/intro/doioctl.c	Tue Jul  6 09:30:07 2021
@@ -1,10 +1,12 @@
-/*	$NetBSD: doioctl.c,v 1.1 2007/11/22 11:28:48 pooka Exp $	*/
+/*	$NetBSD: doioctl.c,v 1.2 2021/07/06 09:30:07 jmcneill Exp $	*/
 
 #include 
 #include 
 
+#include 
 #include 
 #include 
+#include 
 
 #include "common.h"
 



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

2021-07-02 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Jul  2 10:14:07 UTC 2021

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

Log Message:
port-macppc/56289: kernel spinout on macppc when runing ATF tests with LOCKDEBUG

Move call to snapper_set_rate from trigger_output to commit_settings,
since the intr lock is not held when calling the latter.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/macppc/dev/snapper.c

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

Modified files:

Index: src/sys/arch/macppc/dev/snapper.c
diff -u src/sys/arch/macppc/dev/snapper.c:1.59 src/sys/arch/macppc/dev/snapper.c:1.60
--- src/sys/arch/macppc/dev/snapper.c:1.59	Mon Apr 26 14:01:47 2021
+++ src/sys/arch/macppc/dev/snapper.c	Fri Jul  2 10:14:07 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: snapper.c,v 1.59 2021/04/26 14:01:47 thorpej Exp $	*/
+/*	$NetBSD: snapper.c,v 1.60 2021/07/02 10:14:07 jmcneill Exp $	*/
 /*	Id: snapper.c,v 1.11 2002/10/31 17:42:13 tsubai Exp	*/
 /*	Id: i2s.c,v 1.12 2005/01/15 14:32:35 tsubai Exp		*/
 
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: snapper.c,v 1.59 2021/04/26 14:01:47 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: snapper.c,v 1.60 2021/07/02 10:14:07 jmcneill Exp $");
 
 #include 
 #include 
@@ -133,6 +133,7 @@ static int snapper_query_format(void *, 
 static int snapper_set_format(void *, int,
 const audio_params_t *, const audio_params_t *,
 audio_filter_reg_t *, audio_filter_reg_t *);
+static int snapper_commit_settings(void *);
 static int snapper_round_blocksize(void *, int, int, const audio_params_t *);
 static int snapper_halt_output(void *);
 static int snapper_halt_input(void *);
@@ -232,6 +233,7 @@ CFATTACH_DECL_NEW(snapper, sizeof(struct
 const struct audio_hw_if snapper_hw_if = {
 	.query_format		= snapper_query_format,
 	.set_format		= snapper_set_format,
+	.commit_settings	= snapper_commit_settings,
 	.round_blocksize	= snapper_round_blocksize,
 	.halt_output		= snapper_halt_output,
 	.halt_input		= snapper_halt_input,
@@ -1013,6 +1015,17 @@ snapper_set_format(void *h, int setmode,
 }
 
 static int
+snapper_commit_settings(void *h)
+{
+	struct snapper_softc *sc;
+
+	DPRINTF("commit_settings\n");
+	sc = h;
+
+	return snapper_set_rate(sc);
+}
+
+static int
 snapper_round_blocksize(void *h, int size, int mode,
 			const audio_params_t *param)
 {
@@ -1408,14 +1421,10 @@ snapper_trigger_output(void *h, void *st
 	struct dbdma_command *cmd;
 	vaddr_t va;
 	int i, len, intmode;
-	int res;
 
 	DPRINTF("trigger_output %p %p 0x%x\n", start, end, bsize);
 	sc = h;
 
-	if ((res = snapper_set_rate(sc)) != 0)
-		return res;
-
 	cmd = sc->sc_odmacmd;
 	sc->sc_ointr = intr;
 	sc->sc_oarg = arg;
@@ -1463,14 +1472,10 @@ snapper_trigger_input(void *h, void *sta
 	struct dbdma_command *cmd;
 	vaddr_t va;
 	int i, len, intmode;
-	int res;
 
 	DPRINTF("trigger_input %p %p 0x%x\n", start, end, bsize);
 	sc = h;
 
-	if ((res = snapper_set_rate(sc)) != 0)
-		return res;
-
 	cmd = sc->sc_idmacmd;
 	sc->sc_iintr = intr;
 	sc->sc_iarg = arg;



CVS commit: src/distrib/utils/embedded/files

2021-07-01 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Jul  1 18:05:45 UTC 2021

Modified Files:
src/distrib/utils/embedded/files: ec2_init

Log Message:
AWS marketplace does not allow root ssh logins. Create an ec2-user account
and install the ssh key in that user's home directory instead.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/distrib/utils/embedded/files/ec2_init

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

Modified files:

Index: src/distrib/utils/embedded/files/ec2_init
diff -u src/distrib/utils/embedded/files/ec2_init:1.1 src/distrib/utils/embedded/files/ec2_init:1.2
--- src/distrib/utils/embedded/files/ec2_init:1.1	Fri Nov 30 20:53:02 2018
+++ src/distrib/utils/embedded/files/ec2_init	Thu Jul  1 18:05:45 2021
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: ec2_init,v 1.1 2018/11/30 20:53:02 jmcneill Exp $
+# $NetBSD: ec2_init,v 1.2 2021/07/01 18:05:45 jmcneill Exp $
 #
 # PROVIDE: ec2_init
 # REQUIRE: NETWORKING
@@ -13,24 +13,37 @@ rcvar=${name}
 start_cmd="ec2_init"
 stop_cmd=":"
 
+EC2_USER="ec2-user"
 METADATA_URL="http://169.254.169.254/latest/meta-data/";
 SSH_KEY_URL="public-keys/0/openssh-key"
 HOSTNAME_URL="hostname"
 
-SSH_KEY_FILE="/root/.ssh/authorized_keys"
+SSH_KEY_FILE="/home/${EC2_USER}/.ssh/authorized_keys"
+
+ec2_newuser()
+{
+	echo "Creating EC2 user account ${EC2_USER}"
+	useradd -g users -G wheel,operator -m "${EC2_USER}"
+}
 
 ec2_init()
 {
 	(
 	umask 022
+
+	# create EC2 user
+	id "${EC2_USER}" >/dev/null 2>&1 || ec2_newuser
+
 	# fetch the key pair from Amazon Web Services
 	EC2_SSH_KEY=$(ftp -o - "${METADATA_URL}${SSH_KEY_URL}")
 
 	if [ -n "$EC2_SSH_KEY" ]; then
 		# A key pair is associated with this instance, add it
-		# to root 'authorized_keys' file
+		# to EC2_USER's 'authorized_keys' file
 		mkdir -p $(dirname "$SSH_KEY_FILE")
+		chown "${EC2_USER}:users" $(dirname "$SSH_KEY_FILE")
 		touch "$SSH_KEY_FILE"
+		chown "${EC2_USER}:users" "$SSH_KEY_FILE"
 		cd $(dirname "$SSH_KEY_FILE")
 
 		grep -q "$EC2_SSH_KEY" "$SSH_KEY_FILE"



CVS commit: src/distrib/utils/embedded/conf

2021-07-01 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Jul  1 17:31:21 UTC 2021

Modified Files:
src/distrib/utils/embedded/conf: arm64mbr.conf

Log Message:
No need for ec2_init on arm64mbr


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/distrib/utils/embedded/conf/arm64mbr.conf

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

Modified files:

Index: src/distrib/utils/embedded/conf/arm64mbr.conf
diff -u src/distrib/utils/embedded/conf/arm64mbr.conf:1.1 src/distrib/utils/embedded/conf/arm64mbr.conf:1.2
--- src/distrib/utils/embedded/conf/arm64mbr.conf:1.1	Thu May 28 10:22:49 2020
+++ src/distrib/utils/embedded/conf/arm64mbr.conf	Thu Jul  1 17:31:21 2021
@@ -1,4 +1,4 @@
-# $NetBSD: arm64mbr.conf,v 1.1 2020/05/28 10:22:49 jmcneill Exp $
+# $NetBSD: arm64mbr.conf,v 1.2 2021/07/01 17:31:21 jmcneill Exp $
 # ARM64 (MBR partitioning) customization script used by mkimage
 #
 board=arm64mbr
@@ -24,16 +24,10 @@ customize() {
 mdnsd=YES
 devpubd=YES
 wscons=\$(dev_exists wsdisplay0)
-ec2_init=\$(dev_exists ena0)
 EOF
 }
 
 populate_common() {
-	# Add EC2 init script
-	cp ${DIR}/files/ec2_init ${mnt}/etc/rc.d/ec2_init
-	echo "./etc/rc.d/ec2_init type=file uname=root gname=wheel mode=0555" \
-	>> "$tmp/selected_sets"
-
 	# Rename kernel to netbsd.img
 	mv "${mnt}/boot/netbsd-${kernel_GENERIC64}.img" "${mnt}/boot/netbsd.img"
 



CVS commit: src/distrib/utils/embedded/conf

2021-07-01 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Jul  1 17:32:07 UTC 2021

Modified Files:
src/distrib/utils/embedded/conf: arm64.conf

Log Message:
port-evbarm/56274: no network on ec2 arm64 9.99.85

Add -w to dhcpcd_flags when running on EC2, since we need to wait for the
network to come up before contacting the metadata service.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/distrib/utils/embedded/conf/arm64.conf

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

Modified files:

Index: src/distrib/utils/embedded/conf/arm64.conf
diff -u src/distrib/utils/embedded/conf/arm64.conf:1.12 src/distrib/utils/embedded/conf/arm64.conf:1.13
--- src/distrib/utils/embedded/conf/arm64.conf:1.12	Fri Jul 17 15:16:34 2020
+++ src/distrib/utils/embedded/conf/arm64.conf	Thu Jul  1 17:32:07 2021
@@ -1,4 +1,4 @@
-# $NetBSD: arm64.conf,v 1.12 2020/07/17 15:16:34 jmcneill Exp $
+# $NetBSD: arm64.conf,v 1.13 2021/07/01 17:32:07 jmcneill Exp $
 # ARM64 customization script used by mkimage
 #
 board=arm64
@@ -29,6 +29,9 @@ mdnsd=YES
 devpubd=YES
 wscons=\$(dev_exists wsdisplay0)
 ec2_init=\$(dev_exists ena0)
+if checkyesno ec2_init ; then
+	dhcpcd_flags="\$dhcpcd_flags -w"
+fi
 EOF
 }
 



CVS commit: src/sys/dev/pci

2021-07-01 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Jul  1 17:22:10 UTC 2021

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

Log Message:
port-evbarm/56274: no network on ec2 arm64 9.99.85

Remove custom SIOCSIFFLAGS handling and rely on ether_ioctl to DTRT


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/dev/pci/if_ena.c

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

Modified files:

Index: src/sys/dev/pci/if_ena.c
diff -u src/sys/dev/pci/if_ena.c:1.27 src/sys/dev/pci/if_ena.c:1.28
--- src/sys/dev/pci/if_ena.c:1.27	Sat Jan 23 11:50:30 2021
+++ src/sys/dev/pci/if_ena.c	Thu Jul  1 17:22:10 2021
@@ -36,7 +36,7 @@
 #if 0
 __FBSDID("$FreeBSD: head/sys/dev/ena/ena.c 333456 2018-05-10 09:37:54Z mw $");
 #endif
-__KERNEL_RCSID(0, "$NetBSD: if_ena.c,v 1.27 2021/01/23 11:50:30 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ena.c,v 1.28 2021/07/01 17:22:10 jmcneill Exp $");
 
 #include 
 #include 
@@ -2396,28 +2396,6 @@ ena_ioctl(struct ifnet *ifp, u_long comm
 		rw_exit(&adapter->ioctl_sx);
 		break;
 
-	case SIOCSIFFLAGS:
-		if ((ifp->if_flags & IFF_UP) != 0) {
-			if ((if_getdrvflags(ifp) & IFF_RUNNING) != 0) {
-if ((ifp->if_flags & (IFF_PROMISC |
-IFF_ALLMULTI)) != 0) {
-	device_printf(adapter->pdev,
-	"ioctl promisc/allmulti\n");
-}
-			} else {
-rw_enter(&adapter->ioctl_sx, RW_WRITER);
-rc = ena_up(adapter);
-rw_exit(&adapter->ioctl_sx);
-			}
-		} else {
-			if ((if_getdrvflags(ifp) & IFF_RUNNING) != 0) {
-rw_enter(&adapter->ioctl_sx, RW_WRITER);
-ena_down(adapter);
-rw_exit(&adapter->ioctl_sx);
-			}
-		}
-		break;
-
 	case SIOCADDMULTI:
 	case SIOCDELMULTI:
 		break;



CVS commit: src/sys/dev/fdt

2021-06-26 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jun 26 10:43:52 UTC 2021

Modified Files:
src/sys/dev/fdt: fdt_memory.c

Log Message:
Fix 32-bit build.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/fdt/fdt_memory.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/fdt/fdt_memory.c
diff -u src/sys/dev/fdt/fdt_memory.c:1.2 src/sys/dev/fdt/fdt_memory.c:1.3
--- src/sys/dev/fdt/fdt_memory.c:1.2	Fri Jun 25 08:41:09 2021
+++ src/sys/dev/fdt/fdt_memory.c	Sat Jun 26 10:43:52 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_memory.c,v 1.2 2021/06/25 08:41:09 ryo Exp $ */
+/* $NetBSD: fdt_memory.c,v 1.3 2021/06/26 10:43:52 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include "opt_fdt.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdt_memory.c,v 1.2 2021/06/25 08:41:09 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_memory.c,v 1.3 2021/06/26 10:43:52 jmcneill Exp $");
 
 #include 
 #include 
@@ -110,11 +110,12 @@ void
 fdt_memory_remove_reserved(uint64_t min_addr, uint64_t max_addr)
 {
 	uint64_t lstart = 0, lend = 0;
-	uint64_t addr, size;
 	int index, error, phandle, child;
 
 	const int num = fdt_num_mem_rsv(fdtbus_get_data());
 	for (index = 0; index <= num; index++) {
+		uint64_t addr, size;
+
 		error = fdt_get_mem_rsv(fdtbus_get_data(), index,
 		&addr, &size);
 		if (error != 0)
@@ -147,6 +148,9 @@ fdt_memory_remove_reserved(uint64_t min_
 	phandle = OF_finddevice("/reserved-memory");
 	if (phandle != -1) {
 		for (child = OF_child(phandle); child; child = OF_peer(child)) {
+			bus_addr_t addr;
+			bus_size_t size;
+
 			if (!of_hasprop(child, "no-map"))
 continue;
 



CVS commit: src/sys/stand/efiboot

2021-06-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jun 23 21:43:38 UTC 2021

Modified Files:
src/sys/stand/efiboot: boot.c

Log Message:
When printing memory size, don't promote to next unit size unless it is at
two digits.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/stand/efiboot/boot.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/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.33 src/sys/stand/efiboot/boot.c:1.34
--- src/sys/stand/efiboot/boot.c:1.33	Wed Jun 23 00:38:12 2021
+++ src/sys/stand/efiboot/boot.c	Wed Jun 23 21:43:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.33 2021/06/23 00:38:12 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.34 2021/06/23 21:43:38 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -479,7 +479,7 @@ format_bytes(uint64_t val, uint64_t *pdi
 	*punit = "bytes";
 	*pdiv = 1;
 
-	for (n = 0; n < __arraycount(units) && val >= 1024; n++) {
+	for (n = 0; n < __arraycount(units) && val >= 1024 * 10; n++) {
 		*punit = units[n];
 		*pdiv *= 1024;
 		val /= 1024;



CVS commit: src/sys/stand/efiboot

2021-06-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jun 23 21:42:43 UTC 2021

Modified Files:
src/sys/stand/efiboot: efiblock.c

Log Message:
fix typo


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/stand/efiboot/efiblock.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/stand/efiboot/efiblock.c
diff -u src/sys/stand/efiboot/efiblock.c:1.16 src/sys/stand/efiboot/efiblock.c:1.17
--- src/sys/stand/efiboot/efiblock.c:1.16	Wed Jun 23 20:55:50 2021
+++ src/sys/stand/efiboot/efiblock.c	Wed Jun 23 21:42:43 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.16 2021/06/23 20:55:50 jmcneill Exp $ */
+/* $NetBSD: efiblock.c,v 1.17 2021/06/23 21:42:43 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -133,7 +133,7 @@ efi_block_do_read_blockio(struct efi_blo
 	blkbuf_offset = off % bdev->bio->Media->BlockSize;
 	blkbuf_size = (lba_end - lba_start) * bdev->bio->Media->BlockSize;
 	if (bdev->bio->Media->IoAlign > 1) {
-		blkbuf_size = (blkbuf_size + bdev->bio-Media->IoAlign - 1) /
+		blkbuf_size = (blkbuf_size + bdev->bio->Media->IoAlign - 1) /
 		bdev->bio->Media->IoAlign *
 		bdev->bio->Media->IoAlign;
 	}



CVS commit: src/sys/stand/efiboot

2021-06-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jun 23 20:55:50 UTC 2021

Modified Files:
src/sys/stand/efiboot: efiblock.c

Log Message:
Fix buffer size for alignment adjusted block I/O reads.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/stand/efiboot/efiblock.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/stand/efiboot/efiblock.c
diff -u src/sys/stand/efiboot/efiblock.c:1.15 src/sys/stand/efiboot/efiblock.c:1.16
--- src/sys/stand/efiboot/efiblock.c:1.15	Tue Jun 22 21:56:51 2021
+++ src/sys/stand/efiboot/efiblock.c	Wed Jun 23 20:55:50 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.15 2021/06/22 21:56:51 jmcneill Exp $ */
+/* $NetBSD: efiblock.c,v 1.16 2021/06/23 20:55:50 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -133,7 +133,9 @@ efi_block_do_read_blockio(struct efi_blo
 	blkbuf_offset = off % bdev->bio->Media->BlockSize;
 	blkbuf_size = (lba_end - lba_start) * bdev->bio->Media->BlockSize;
 	if (bdev->bio->Media->IoAlign > 1) {
-		blkbuf_size += bdev->bio->Media->IoAlign - 1;
+		blkbuf_size = (blkbuf_size + bdev->bio-Media->IoAlign - 1) /
+		bdev->bio->Media->IoAlign *
+		bdev->bio->Media->IoAlign;
 	}
 
 	blkbuf = AllocatePool(blkbuf_size);



CVS commit: src/sys/stand/efiboot

2021-06-22 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jun 23 00:38:12 UTC 2021

Modified Files:
src/sys/stand/efiboot: boot.c

Log Message:
print_banner: Print memory size like x86 does


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/stand/efiboot/boot.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/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.32 src/sys/stand/efiboot/boot.c:1.33
--- src/sys/stand/efiboot/boot.c:1.32	Mon Jun 21 21:18:47 2021
+++ src/sys/stand/efiboot/boot.c	Wed Jun 23 00:38:12 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.32 2021/06/21 21:18:47 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.33 2021/06/23 00:38:12 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -450,13 +450,56 @@ set_bootargs(const char *arg)
 	return 0;
 }
 
+static void
+get_memory_info(uint64_t *ptotal)
+{
+	EFI_MEMORY_DESCRIPTOR *md, *memmap;
+	UINTN nentries, mapkey, descsize;
+	UINT32 descver;
+	uint64_t totalpg = 0;
+	int n;
+
+	memmap = LibMemoryMap(&nentries, &mapkey, &descsize, &descver);
+	for (n = 0, md = memmap; n < nentries; n++, md = NextMemoryDescriptor(md, descsize)) {
+		if ((md->Attribute & EFI_MEMORY_WB) == 0) {
+			continue;
+		}
+		totalpg += md->NumberOfPages;
+	}
+
+	*ptotal = totalpg * EFI_PAGE_SIZE;
+}
+
+static void
+format_bytes(uint64_t val, uint64_t *pdiv, const char **punit)
+{
+	static const char *units[] = { "KB", "MB", "GB" };
+	unsigned n;
+
+	*punit = "bytes";
+	*pdiv = 1;
+
+	for (n = 0; n < __arraycount(units) && val >= 1024; n++) {
+		*punit = units[n];
+		*pdiv *= 1024;
+		val /= 1024;
+	}
+}
+
 void
 print_banner(void)
 {
+	const char *total_unit;
+	uint64_t total, total_div;
+
+	get_memory_info(&total);
+	format_bytes(total, &total_div, &total_unit);
+
 	printf("  \\-__,--,___.\n");
 	printf("   \\__,---`  %s\n", bootprog_name);
 	printf("\\   `---,_.  Revision %s\n", bootprog_rev);
-	printf(" \\-,_,.---`\n");
+	printf(" \\-,_,.---`  Memory: %" PRIu64 " %s\n",
+	total / total_div, total_unit);
 	printf("  \\\n");
 	printf("   \\\n");
 	printf("\\\n\n");



CVS commit: src/sys/stand/efiboot

2021-06-22 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Jun 22 21:56:51 UTC 2021

Modified Files:
src/sys/stand/efiboot: efiblock.c

Log Message:
efiboot: Use EFI_BLOCK_IO_PROTOCOL if EFI_DISK_IO_PROTOCOL is missing

UEFI spec says that firmware should automatically add EFI_DISK_IO_PROTOCOL
for all produced EFI_BLOCK_IO_PROTOCOL interfaces. Unfortunately U-Boot
doesn't do this, so fallback to block I/O if disk I/O is not there.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/stand/efiboot/efiblock.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/stand/efiboot/efiblock.c
diff -u src/sys/stand/efiboot/efiblock.c:1.14 src/sys/stand/efiboot/efiblock.c:1.15
--- src/sys/stand/efiboot/efiblock.c:1.14	Mon Jun 21 21:18:47 2021
+++ src/sys/stand/efiboot/efiblock.c	Tue Jun 22 21:56:51 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.14 2021/06/21 21:18:47 jmcneill Exp $ */
+/* $NetBSD: efiblock.c,v 1.15 2021/06/22 21:56:51 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -118,7 +118,74 @@ efi_block_generate_hash_mbr(struct efi_b
 }
 
 static EFI_STATUS
-efi_block_disk_readahead(struct efi_block_dev *bdev, UINT64 off, void *buf,
+efi_block_do_read_blockio(struct efi_block_dev *bdev, UINT64 off, void *buf,
+UINTN bufsize)
+{
+	UINT8 *blkbuf, *blkbuf_start;
+	EFI_STATUS status;
+	EFI_LBA lba_start, lba_end;
+	UINT64 blkbuf_offset;
+	UINT64 blkbuf_size;
+
+	lba_start = off / bdev->bio->Media->BlockSize;
+	lba_end = (off + bufsize + bdev->bio->Media->BlockSize - 1) /
+	bdev->bio->Media->BlockSize;
+	blkbuf_offset = off % bdev->bio->Media->BlockSize;
+	blkbuf_size = (lba_end - lba_start) * bdev->bio->Media->BlockSize;
+	if (bdev->bio->Media->IoAlign > 1) {
+		blkbuf_size += bdev->bio->Media->IoAlign - 1;
+	}
+
+	blkbuf = AllocatePool(blkbuf_size);
+	if (blkbuf == NULL) {
+		return EFI_OUT_OF_RESOURCES;
+	}
+
+	if (bdev->bio->Media->IoAlign > 1) {
+		blkbuf_start = (void *)roundup2((intptr_t)blkbuf,
+		bdev->bio->Media->IoAlign);
+	} else {
+		blkbuf_start = blkbuf;
+	}
+
+	status = uefi_call_wrapper(bdev->bio->ReadBlocks, 5, bdev->bio,
+	bdev->media_id, lba_start, blkbuf_size, blkbuf_start);
+	if (EFI_ERROR(status)) {
+		goto done;
+	}
+
+	memcpy(buf, blkbuf_start + blkbuf_offset, bufsize);
+
+done:
+	FreePool(blkbuf);
+	return status;
+}
+
+static EFI_STATUS
+efi_block_do_read_diskio(struct efi_block_dev *bdev, UINT64 off, void *buf,
+UINTN bufsize)
+{
+	return uefi_call_wrapper(bdev->dio->ReadDisk, 5, bdev->dio,
+	bdev->media_id, off, bufsize, buf);
+}
+
+static EFI_STATUS
+efi_block_do_read(struct efi_block_dev *bdev, UINT64 off, void *buf,
+UINTN bufsize)
+{
+	/*
+	 * Perform read access using EFI_DISK_IO_PROTOCOL if available,
+	 * otherwise use EFI_BLOCK_IO_PROTOCOL.
+	 */
+	if (bdev->dio != NULL) {
+		return efi_block_do_read_diskio(bdev, off, buf, bufsize);
+	} else {
+		return efi_block_do_read_blockio(bdev, off, buf, bufsize);
+	}
+}
+
+static EFI_STATUS
+efi_block_readahead(struct efi_block_dev *bdev, UINT64 off, void *buf,
 UINTN bufsize)
 {
 	EFI_STATUS status;
@@ -140,8 +207,7 @@ efi_block_disk_readahead(struct efi_bloc
 		if (len > mediasize - off) {
 			len = mediasize - off;
 		}
-		status = uefi_call_wrapper(bdev->dio->ReadDisk, 5, bdev->dio,
-		bdev->media_id, off, len, efi_ra_buffer);
+		status = efi_block_do_read(bdev, off, efi_ra_buffer, len);
 		if (EFI_ERROR(status)) {
 			efi_ra_start = efi_ra_length = 0;
 			return status;
@@ -156,15 +222,14 @@ efi_block_disk_readahead(struct efi_bloc
 }
 
 static EFI_STATUS
-efi_block_disk_read(struct efi_block_dev *bdev, UINT64 off, void *buf,
+efi_block_read(struct efi_block_dev *bdev, UINT64 off, void *buf,
 UINTN bufsize)
 {
 	if (efi_ra_enable) {
-		return efi_block_disk_readahead(bdev, off, buf, bufsize);
+		return efi_block_readahead(bdev, off, buf, bufsize);
 	}
 
-	return uefi_call_wrapper(bdev->dio->ReadDisk, 5, bdev->dio,
-	bdev->media_id, off, bufsize, buf);
+	return efi_block_do_read(bdev, off, buf, bufsize);
 }
 
 static int
@@ -176,7 +241,7 @@ efi_block_find_partitions_cd9660(struct 
 	EFI_LBA lba;
 
 	for (lba = 16;; lba++) {
-		status = efi_block_disk_read(bdev,
+		status = efi_block_read(bdev,
 		lba * ISO_DEFAULT_BLOCK_SIZE, &vd, sizeof(vd));
 		if (EFI_ERROR(status)) {
 			goto io_error;
@@ -220,7 +285,7 @@ efi_block_find_partitions_disklabel(stru
 	EFI_STATUS status;
 	int n;
 
-	status = efi_block_disk_read(bdev,
+	status = efi_block_read(bdev,
 	((EFI_LBA)start + LABELSECTOR) * DEV_BSIZE, buf, sizeof(buf));
 	if (EFI_ERROR(status) || getdisklabel(buf, &d) != NULL) {
 		FreePool(buf);
@@ -268,7 +333,7 @@ efi_block_find_partitions_mbr(struct efi
 	EFI_STATUS status;
 	int n;
 
-	status = efi_block_disk_read(bdev, 0, &mbr, sizeof(mbr));
+	status = efi_block_read(bdev, 0, &mbr, sizeof(mbr));
 	if (EFI_ERROR(status))
 		return EIO;
 
@@ -3

CVS commit: src/sys/stand/efiboot

2021-06-22 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Jun 22 10:19:35 UTC 2021

Modified Files:
src/sys/stand/efiboot: efirng.c

Log Message:
efirng: fix va_num arg to uefi_call_wrapper for GetRNG calls

As far as I can tell this param isn't actually used, but it is supposed to
be the number of arguments passed to the called method.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/efirng.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/stand/efiboot/efirng.c
diff -u src/sys/stand/efiboot/efirng.c:1.2 src/sys/stand/efiboot/efirng.c:1.3
--- src/sys/stand/efiboot/efirng.c:1.2	Thu May 14 23:09:29 2020
+++ src/sys/stand/efiboot/efirng.c	Tue Jun 22 10:19:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: efirng.c,v 1.2 2020/05/14 23:09:29 jmcneill Exp $	*/
+/*	$NetBSD: efirng.c,v 1.3 2021/06/22 10:19:35 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -121,14 +121,14 @@ efi_rng(void *buf, UINTN len)
 	if (!efi_rng_available())
 		return EIO;
 
-	status = uefi_call_wrapper(rng->GetRNG, 3, rng, &RngAlgorithmRawGuid,
+	status = uefi_call_wrapper(rng->GetRNG, 4, rng, &RngAlgorithmRawGuid,
 	len, buf);
 	if (status == EFI_UNSUPPORTED) {
 		/*
 		 * Fall back to any supported RNG `algorithm' even
 		 * though we would prefer raw samples.
 		 */
-		status = uefi_call_wrapper(rng->GetRNG, 3, rng, NULL, len, buf);
+		status = uefi_call_wrapper(rng->GetRNG, 4, rng, NULL, len, buf);
 	}
 	if (EFI_ERROR(status)) {
 		DPRINT(L"efirng: GetRNG: %r\n", status);



CVS commit: src/sys/stand/efiboot

2021-06-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Jun 21 21:18:47 UTC 2021

Modified Files:
src/sys/stand/efiboot: boot.c efiblock.c efiblock.h

Log Message:
efiboot: Add readahead support.

Reading data through libsa file-systems ends up breaking block I/O
accesses into very small (512-byte or 2048-byte) accesses. This can be
very inefficient, and causes Ampere eMAG w/ BMC image direction to take
_minutes_ to load the install image and kernel. So slow in fact that
the default watchdog timeout will fire before it finishes.

So, when loading big files, optimistically read ahead up to 64KB of data.
Brings the time to boot the install ISO down to around 40 seconds -- still
not ideal but way better than before.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r1.13 -r1.14 src/sys/stand/efiboot/efiblock.c
cvs rdiff -u -r1.5 -r1.6 src/sys/stand/efiboot/efiblock.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/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.31 src/sys/stand/efiboot/boot.c:1.32
--- src/sys/stand/efiboot/boot.c:1.31	Mon Jun 21 19:07:30 2021
+++ src/sys/stand/efiboot/boot.c	Mon Jun 21 21:18:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.31 2021/06/21 19:07:30 nia Exp $	*/
+/*	$NetBSD: boot.c,v 1.32 2021/06/21 21:18:47 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -171,7 +171,9 @@ command_boot(char *arg)
 	if (!*bootargs)
 		bootargs = netbsd_args;
 
+	efi_block_set_readahead(true);
 	exec_netbsd(kernel, bootargs);
+	efi_block_set_readahead(false);
 }
 
 void
@@ -498,7 +500,9 @@ boot(void)
 		if (c != '\r' && c != '\n' && c != '\0')
 			bootprompt(); /* does not return */
 
+		efi_block_set_readahead(true);
 		exec_netbsd(netbsd_path, netbsd_args);
+		efi_block_set_readahead(false);
 	}
 
 	bootprompt();	/* does not return */

Index: src/sys/stand/efiboot/efiblock.c
diff -u src/sys/stand/efiboot/efiblock.c:1.13 src/sys/stand/efiboot/efiblock.c:1.14
--- src/sys/stand/efiboot/efiblock.c:1.13	Mon Jun 21 11:11:33 2021
+++ src/sys/stand/efiboot/efiblock.c	Mon Jun 21 21:18:47 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.13 2021/06/21 11:11:33 jmcneill Exp $ */
+/* $NetBSD: efiblock.c,v 1.14 2021/06/21 21:18:47 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -38,6 +38,7 @@
 #include "efiboot.h"
 #include "efiblock.h"
 
+#define	EFI_BLOCK_READAHEAD	(64 * 1024)
 #define	EFI_BLOCK_TIMEOUT	120
 #define	EFI_BLOCK_TIMEOUT_CODE	0x810c
 
@@ -52,6 +53,12 @@ static EFI_HANDLE *efi_block;
 static UINTN efi_nblock;
 static struct efi_block_part *efi_block_booted = NULL;
 
+static bool efi_ra_enable = false;
+static UINT8 *efi_ra_buffer = NULL;
+static UINT32 efi_ra_media_id;
+static UINT64 efi_ra_start = 0;
+static UINT64 efi_ra_length = 0;
+
 static TAILQ_HEAD(, efi_block_dev) efi_block_devs = TAILQ_HEAD_INITIALIZER(efi_block_devs);
 
 static int
@@ -111,9 +118,51 @@ efi_block_generate_hash_mbr(struct efi_b
 }
 
 static EFI_STATUS
+efi_block_disk_readahead(struct efi_block_dev *bdev, UINT64 off, void *buf,
+UINTN bufsize)
+{
+	EFI_STATUS status;
+	UINT64 mediasize, len;
+
+	if (efi_ra_buffer == NULL) {
+		efi_ra_buffer = AllocatePool(EFI_BLOCK_READAHEAD);
+		if (efi_ra_buffer == NULL) {
+			return EFI_OUT_OF_RESOURCES;
+		}
+	}
+
+	if (bdev->media_id != efi_ra_media_id ||
+	off < efi_ra_start ||
+	off + bufsize > efi_ra_start + efi_ra_length) {
+		mediasize = bdev->bio->Media->BlockSize *
+		(bdev->bio->Media->LastBlock + 1);
+		len = EFI_BLOCK_READAHEAD;
+		if (len > mediasize - off) {
+			len = mediasize - off;
+		}
+		status = uefi_call_wrapper(bdev->dio->ReadDisk, 5, bdev->dio,
+		bdev->media_id, off, len, efi_ra_buffer);
+		if (EFI_ERROR(status)) {
+			efi_ra_start = efi_ra_length = 0;
+			return status;
+		}
+		efi_ra_start = off;
+		efi_ra_length = len;
+		efi_ra_media_id = bdev->media_id;
+	}
+
+	memcpy(buf, &efi_ra_buffer[off - efi_ra_start], bufsize);
+	return EFI_SUCCESS;
+}
+
+static EFI_STATUS
 efi_block_disk_read(struct efi_block_dev *bdev, UINT64 off, void *buf,
 UINTN bufsize)
 {
+	if (efi_ra_enable) {
+		return efi_block_disk_readahead(bdev, off, buf, bufsize);
+	}
+
 	return uefi_call_wrapper(bdev->dio->ReadDisk, 5, bdev->dio,
 	bdev->media_id, off, bufsize, buf);
 }
@@ -588,3 +637,9 @@ efi_block_strategy(void *devdata, int rw
 
 	return 0;
 }
+
+void
+efi_block_set_readahead(bool onoff)
+{
+	efi_ra_enable = onoff;
+}

Index: src/sys/stand/efiboot/efiblock.h
diff -u src/sys/stand/efiboot/efiblock.h:1.5 src/sys/stand/efiboot/efiblock.h:1.6
--- src/sys/stand/efiboot/efiblock.h:1.5	Mon Jun 21 11:11:33 2021
+++ src/sys/stand/efiboot/efiblock.h	Mon Jun 21 21:18:47 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.h,v 1.5 2021/06/21 11:11:33 jmcneill Exp $ */
+/* $NetBSD: efiblock.h,v 1.6 2021/06/21 21:18:47 jmcneill Exp $ */
 
 /*-
  * Copyright (

CVS commit: src/sys/stand/efiboot

2021-06-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Jun 21 11:11:33 UTC 2021

Modified Files:
src/sys/stand/efiboot: efiblock.c efiblock.h version

Log Message:
efiboot: Use disk I/O protocol for block device access.

EFI_DISK_IO_PROTOCOL is a simplified interface to block devices. Use this
instead of EFI_BLOCK_IO_PROTOCOL for accessing block devices to simplify
the code -- we no longer need to worry about the underlying media's block
I/O size and alignment requirements.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/stand/efiboot/efiblock.c
cvs rdiff -u -r1.4 -r1.5 src/sys/stand/efiboot/efiblock.h
cvs rdiff -u -r1.26 -r1.27 src/sys/stand/efiboot/version

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

Modified files:

Index: src/sys/stand/efiboot/efiblock.c
diff -u src/sys/stand/efiboot/efiblock.c:1.12 src/sys/stand/efiboot/efiblock.c:1.13
--- src/sys/stand/efiboot/efiblock.c:1.12	Sun Jun 20 19:10:47 2021
+++ src/sys/stand/efiboot/efiblock.c	Mon Jun 21 11:11:33 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.12 2021/06/20 19:10:47 jmcneill Exp $ */
+/* $NetBSD: efiblock.c,v 1.13 2021/06/21 11:11:33 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -110,68 +110,41 @@ efi_block_generate_hash_mbr(struct efi_b
 	MD5Final(bpart->hash, &md5ctx);
 }
 
-static void *
-efi_block_allocate_device_buffer(struct efi_block_dev *bdev, UINTN size,
-	void **buf_start)
+static EFI_STATUS
+efi_block_disk_read(struct efi_block_dev *bdev, UINT64 off, void *buf,
+UINTN bufsize)
 {
-	void *buf;
-
-	if (bdev->bio->Media->IoAlign <= 1)
-		*buf_start = buf = AllocatePool(size);
-	else {
-		buf = AllocatePool(size + bdev->bio->Media->IoAlign - 1);
-		*buf_start = (buf == NULL) ? NULL :
-		(void *)roundup2((intptr_t)buf, bdev->bio->Media->IoAlign);
-	}
-
-	return buf;
+	return uefi_call_wrapper(bdev->dio->ReadDisk, 5, bdev->dio,
+	bdev->media_id, off, bufsize, buf);
 }
 
 static int
 efi_block_find_partitions_cd9660(struct efi_block_dev *bdev)
 {
 	struct efi_block_part *bpart;
-	struct iso_primary_descriptor *vd;
-	void *buf, *buf_start;
+	struct iso_primary_descriptor vd;
 	EFI_STATUS status;
 	EFI_LBA lba;
-	UINT32 sz;
-
-	if (bdev->bio->Media->BlockSize != DEV_BSIZE &&
-	bdev->bio->Media->BlockSize != ISO_DEFAULT_BLOCK_SIZE) {
-		return ENXIO;
-	}
-
-	sz = __MAX(sizeof(*vd), bdev->bio->Media->BlockSize);
-	sz = roundup(sz, bdev->bio->Media->BlockSize);
-	if ((buf = efi_block_allocate_device_buffer(bdev, sz, &buf_start)) == NULL) {
-		return ENOMEM;
-	}
 
 	for (lba = 16;; lba++) {
-		status = uefi_call_wrapper(bdev->bio->ReadBlocks, 5,
-		bdev->bio,
-		bdev->media_id,
-		lba * ISO_DEFAULT_BLOCK_SIZE / bdev->bio->Media->BlockSize,
-		sz,
-		buf_start);
+		status = efi_block_disk_read(bdev,
+		lba * ISO_DEFAULT_BLOCK_SIZE, &vd, sizeof(vd));
 		if (EFI_ERROR(status)) {
 			goto io_error;
 		}
 
-		vd = (struct iso_primary_descriptor *)buf_start;
-		if (memcmp(vd->id, ISO_STANDARD_ID, sizeof vd->id) != 0) {
+		if (memcmp(vd.id, ISO_STANDARD_ID, sizeof vd.id) != 0) {
 			goto io_error;
 		}
-		if (isonum_711(vd->type) == ISO_VD_END) {
+		if (isonum_711(vd.type) == ISO_VD_END) {
 			goto io_error;
 		}
-		if (isonum_711(vd->type) == ISO_VD_PRIMARY) {
+		if (isonum_711(vd.type) == ISO_VD_PRIMARY) {
 			break;
 		}
 	}
 
-	if (isonum_723(vd->logical_block_size) != ISO_DEFAULT_BLOCK_SIZE) {
+	if (isonum_723(vd.logical_block_size) != ISO_DEFAULT_BLOCK_SIZE) {
 		goto io_error;
 	}
 
@@ -181,39 +154,29 @@ efi_block_find_partitions_cd9660(struct 
 	bpart->type = EFI_BLOCK_PART_CD9660;
 	TAILQ_INSERT_TAIL(&bdev->partitions, bpart, entries);
 
-	FreePool(buf);
 	return 0;
 
 io_error:
-	FreePool(buf);
 	return EIO;
 }
 
 static int
-efi_block_find_partitions_disklabel(struct efi_block_dev *bdev, struct mbr_sector *mbr, uint32_t start, uint32_t size)
+efi_block_find_partitions_disklabel(struct efi_block_dev *bdev,
+struct mbr_sector *mbr, uint32_t start, uint32_t size)
 {
 	struct efi_block_part *bpart;
+	char buf[DEV_BSIZE];
 	struct disklabel d;
 	struct partition *p;
 	EFI_STATUS status;
-	EFI_LBA lba;
-	void *buf, *buf_start;
-	UINT32 sz;
 	int n;
 
-	sz = __MAX(sizeof(d), bdev->bio->Media->BlockSize);
-	sz = roundup(sz, bdev->bio->Media->BlockSize);
-	if ((buf = efi_block_allocate_device_buffer(bdev, sz, &buf_start)) == NULL)
-		return ENOMEM;
-
-	lba = (((EFI_LBA)start + LABELSECTOR) * DEV_BSIZE) / bdev->bio->Media->BlockSize;
-	status = uefi_call_wrapper(bdev->bio->ReadBlocks, 5, bdev->bio, bdev->media_id,
-		lba, sz, buf_start);
-	if (EFI_ERROR(status) || getdisklabel(buf_start, &d) != NULL) {
+	status = efi_block_disk_read(bdev,
+	((EFI_LBA)start + LABELSECTOR) * DEV_BSIZE, buf, sizeof(buf));
+	if (EFI_ERROR(status) || getdisklabel(buf, &d) != NULL) {
 		FreePool(buf);
 		return EIO;
 	}
-	FreePool(buf);
 
 	if (le32toh(d.d_magic) != DISKMAGIC || le32toh(d.d_ma

CVS commit: src/sys/stand/efiboot

2021-06-20 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Jun 20 19:10:47 UTC 2021

Modified Files:
src/sys/stand/efiboot: Makefile.efiboot efiblock.c efiboot.h version
Added Files:
src/sys/stand/efiboot: efiwatchdog.c

Log Message:
Add support for the boot services watchdog and pet it on every block I/O
access. For slow media (like ISO image redirection on Lenovo HR330A BMC)
this is needed because otherwise the default watchdog timeout fires before
we can finish loading the kernel from install media.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/stand/efiboot/Makefile.efiboot
cvs rdiff -u -r1.11 -r1.12 src/sys/stand/efiboot/efiblock.c
cvs rdiff -u -r1.14 -r1.15 src/sys/stand/efiboot/efiboot.h
cvs rdiff -u -r0 -r1.1 src/sys/stand/efiboot/efiwatchdog.c
cvs rdiff -u -r1.25 -r1.26 src/sys/stand/efiboot/version

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

Modified files:

Index: src/sys/stand/efiboot/Makefile.efiboot
diff -u src/sys/stand/efiboot/Makefile.efiboot:1.21 src/sys/stand/efiboot/Makefile.efiboot:1.22
--- src/sys/stand/efiboot/Makefile.efiboot:1.21	Thu May 27 06:54:45 2021
+++ src/sys/stand/efiboot/Makefile.efiboot	Sun Jun 20 19:10:47 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.21 2021/05/27 06:54:45 mrg Exp $
+# $NetBSD: Makefile.efiboot,v 1.22 2021/06/20 19:10:47 jmcneill Exp $
 
 S=		${.CURDIR}/../../..
 
@@ -24,7 +24,8 @@ SOURCES=	crt0-efi-${GNUEFIARCH}.S reloc_
 SOURCES+=	boot.c bootmenu.c conf.c console.c dev_net.c devopen.c exec.c \
 		module.c overlay.c panic.c prompt.c
 SOURCES+=	efiboot.c efichar.c efidev.c efigetsecs.c efifdt.c \
-		efifile.c efiblock.c efinet.c efipxe.c efiacpi.c efirng.c smbios.c
+		efifile.c efiblock.c efinet.c efipxe.c efiacpi.c efirng.c efiwatchdog.c \
+	   	smbios.c
 
 .PATH: ${S}/external/bsd/libfdt/dist
 CPPFLAGS+=	-I${S}/external/bsd/libfdt/dist

Index: src/sys/stand/efiboot/efiblock.c
diff -u src/sys/stand/efiboot/efiblock.c:1.11 src/sys/stand/efiboot/efiblock.c:1.12
--- src/sys/stand/efiboot/efiblock.c:1.11	Wed May 26 09:42:36 2021
+++ src/sys/stand/efiboot/efiblock.c	Sun Jun 20 19:10:47 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.11 2021/05/26 09:42:36 mrg Exp $ */
+/* $NetBSD: efiblock.c,v 1.12 2021/06/20 19:10:47 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -38,6 +38,9 @@
 #include "efiboot.h"
 #include "efiblock.h"
 
+#define	EFI_BLOCK_TIMEOUT	120
+#define	EFI_BLOCK_TIMEOUT_CODE	0x810c
+
 /*
  * The raidframe support is basic.  Ideally, it should be expanded to
  * consider raid volumes a first-class citizen like the x86 efiboot does,
@@ -605,6 +608,8 @@ efi_block_strategy(void *devdata, int rw
 	if (rw != F_READ)
 		return EROFS;
 
+	efi_set_watchdog(EFI_BLOCK_TIMEOUT, EFI_BLOCK_TIMEOUT_CODE);
+
 	switch (bpart->type) {
 	case EFI_BLOCK_PART_DISKLABEL:
 		if (bpart->bdev->bio->Media->BlockSize != bpart->disklabel.secsize) {

Index: src/sys/stand/efiboot/efiboot.h
diff -u src/sys/stand/efiboot/efiboot.h:1.14 src/sys/stand/efiboot/efiboot.h:1.15
--- src/sys/stand/efiboot/efiboot.h:1.14	Sun Oct 11 14:03:33 2020
+++ src/sys/stand/efiboot/efiboot.h	Sun Jun 20 19:10:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: efiboot.h,v 1.14 2020/10/11 14:03:33 jmcneill Exp $	*/
+/*	$NetBSD: efiboot.h,v 1.15 2021/06/20 19:10:47 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -104,6 +104,9 @@ extern struct netif_driver efinetif;
 void efi_pxe_probe(void);
 bool efi_pxe_match_booted_interface(const EFI_MAC_ADDRESS *, UINT32);
 
+/* efiwatchdog.c */
+void efi_set_watchdog(uint32_t, uint64_t);
+
 /* exec.c */
 int exec_netbsd(const char *, const char *);
 

Index: src/sys/stand/efiboot/version
diff -u src/sys/stand/efiboot/version:1.25 src/sys/stand/efiboot/version:1.26
--- src/sys/stand/efiboot/version:1.25	Thu May 27 06:54:45 2021
+++ src/sys/stand/efiboot/version	Sun Jun 20 19:10:47 2021
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.25 2021/05/27 06:54:45 mrg Exp $
+$NetBSD: version,v 1.26 2021/06/20 19:10:47 jmcneill Exp $
 
 NOTE ANY CHANGES YOU MAKE TO THE EFI BOOTLOADER HERE.  The format of this
 file is important - make sure the entries are appended on end, last item
@@ -29,3 +29,4 @@ is taken as the current.
 2.6:	Disable ACPI support when booting big endian kernels.
 2.7:	Add basic support for booting from RAID1 volumes.
 2.8:	Add bi-endian disklabel and FFS support.
+2.9:	Watchdog support.

Added files:

Index: src/sys/stand/efiboot/efiwatchdog.c
diff -u /dev/null src/sys/stand/efiboot/efiwatchdog.c:1.1
--- /dev/null	Sun Jun 20 19:10:47 2021
+++ src/sys/stand/efiboot/efiwatchdog.c	Sun Jun 20 19:10:47 2021
@@ -0,0 +1,40 @@
+/* $NetBSD: efiwatchdog.c,v 1.1 2021/06/20 19:10:47 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2021 Jared McNeill 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ *

CVS commit: src/sys/stand/efiboot

2021-06-20 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Jun 20 19:07:39 UTC 2021

Modified Files:
src/sys/stand/efiboot: exec.c

Log Message:
Enable the twiddle spinner when loading the kernel, ramdisk images, and
modules.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/stand/efiboot/exec.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/stand/efiboot/exec.c
diff -u src/sys/stand/efiboot/exec.c:1.21 src/sys/stand/efiboot/exec.c:1.22
--- src/sys/stand/efiboot/exec.c:1.21	Fri May 21 21:53:15 2021
+++ src/sys/stand/efiboot/exec.c	Sun Jun 20 19:07:39 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.21 2021/05/21 21:53:15 jmcneill Exp $ */
+/* $NetBSD: exec.c,v 1.22 2021/06/20 19:07:39 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -246,6 +246,8 @@ exec_netbsd(const char *fname, const cha
 	EFI_STATUS status;
 	int fd, ohowto;
 
+	twiddle_toggle = 0;
+
 	load_file(get_initrd_path(), 0, false, &initrd_addr, &initrd_size);
 	load_file(get_dtb_path(), 0, false, &dtb_addr, &dtb_size);
 	generate_efirng();



CVS commit: src/sys/arch/aarch64

2021-06-19 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jun 19 13:40:00 UTC 2021

Modified Files:
src/sys/arch/aarch64/aarch64: cpu.c
src/sys/arch/aarch64/include: armreg.h

Log Message:
Do not try to initialize PMU if ID_AA64DFR0_EL1 reports a non-standard
PMU implementation.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/aarch64/aarch64/cpu.c
cvs rdiff -u -r1.56 -r1.57 src/sys/arch/aarch64/include/armreg.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/aarch64/aarch64/cpu.c
diff -u src/sys/arch/aarch64/aarch64/cpu.c:1.59 src/sys/arch/aarch64/aarch64/cpu.c:1.60
--- src/sys/arch/aarch64/aarch64/cpu.c:1.59	Tue Mar  9 16:44:27 2021
+++ src/sys/arch/aarch64/aarch64/cpu.c	Sat Jun 19 13:40:00 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.59 2021/03/09 16:44:27 ryo Exp $ */
+/* $NetBSD: cpu.c,v 1.60 2021/06/19 13:40:00 jmcneill Exp $ */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.59 2021/03/09 16:44:27 ryo Exp $");
+__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.60 2021/06/19 13:40:00 jmcneill Exp $");
 
 #include "locators.h"
 #include "opt_arm_debug.h"
@@ -486,6 +486,10 @@ cpu_init_counter(struct cpu_info *ci)
 		/* Performance Monitors Extension not implemented. */
 		return;
 	}
+	if (pmuver == ID_AA64DFR0_EL1_PMUVER_IMPL) {
+		/* Non-standard Performance Monitors are not supported. */
+		return;
+	}
 
 	reg_pmcr_el0_write(PMCR_E | PMCR_C);
 	reg_pmcntenset_el0_write(PMCNTEN_C);

Index: src/sys/arch/aarch64/include/armreg.h
diff -u src/sys/arch/aarch64/include/armreg.h:1.56 src/sys/arch/aarch64/include/armreg.h:1.57
--- src/sys/arch/aarch64/include/armreg.h:1.56	Sat Jun 19 13:38:21 2021
+++ src/sys/arch/aarch64/include/armreg.h	Sat Jun 19 13:40:00 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: armreg.h,v 1.56 2021/06/19 13:38:21 jmcneill Exp $ */
+/* $NetBSD: armreg.h,v 1.57 2021/06/19 13:40:00 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -248,6 +248,7 @@ AARCH64REG_READ_INLINE(id_aa64dfr0_el1)
 #define	 ID_AA64DFR0_EL1_PMUVER_NONE	 0
 #define	 ID_AA64DFR0_EL1_PMUVER_V3	 1
 #define	 ID_AA64DFR0_EL1_PMUVER_NOV3	 2
+#define	 ID_AA64DFR0_EL1_PMUVER_IMPL	 15
 #define	ID_AA64DFR0_EL1_TRACEVER	__BITS(4,7)
 #define	 ID_AA64DFR0_EL1_TRACEVER_NONE	 0
 #define	 ID_AA64DFR0_EL1_TRACEVER_IMPL	 1



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

2021-06-19 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jun 19 13:38:21 UTC 2021

Modified Files:
src/sys/arch/aarch64/include: armreg.h

Log Message:
CNTV_CTL_EL0 is a 64-bit register


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/arch/aarch64/include/armreg.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/aarch64/include/armreg.h
diff -u src/sys/arch/aarch64/include/armreg.h:1.55 src/sys/arch/aarch64/include/armreg.h:1.56
--- src/sys/arch/aarch64/include/armreg.h:1.55	Tue Mar  9 16:41:43 2021
+++ src/sys/arch/aarch64/include/armreg.h	Sat Jun 19 13:38:21 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: armreg.h,v 1.55 2021/03/09 16:41:43 ryo Exp $ */
+/* $NetBSD: armreg.h,v 1.56 2021/06/19 13:38:21 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -1506,7 +1506,7 @@ gtmr_cntvct_read(void)
 /*
  * Counter-timer Virtual Timer Control register
  */
-static __inline uint32_t
+static __inline uint64_t
 gtmr_cntv_ctl_read(void)
 {
 
@@ -1514,7 +1514,7 @@ gtmr_cntv_ctl_read(void)
 }
 
 static __inline void
-gtmr_cntv_ctl_write(uint32_t val)
+gtmr_cntv_ctl_write(uint64_t val)
 {
 
 	reg_cntv_ctl_el0_write(val);



CVS commit: src

2021-06-02 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jun  2 10:31:18 UTC 2021

Modified Files:
src/distrib/sets/lists/dtb: ad.aarch64 ad.aarch64eb ad.earmv6
ad.earmv6eb ad.earmv6hf ad.earmv6hfeb ad.earmv7 ad.earmv7hf
ad.earmv7hfeb
src/sys/dtb/arm64/rockchip: Makefile

Log Message:
Install a copy of rk3399-pinebook-pro.dtb to the base dtb directory for
compatibility with the factory firmware. Normally this is frowned upon,
but this is the only easy way to boot NetBSD on this board without
having to crack open the case and/or hook up a serial console.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/distrib/sets/lists/dtb/ad.aarch64
cvs rdiff -u -r1.5 -r1.6 src/distrib/sets/lists/dtb/ad.aarch64eb \
src/distrib/sets/lists/dtb/ad.earmv7 \
src/distrib/sets/lists/dtb/ad.earmv7hf \
src/distrib/sets/lists/dtb/ad.earmv7hfeb
cvs rdiff -u -r1.4 -r1.5 src/distrib/sets/lists/dtb/ad.earmv6 \
src/distrib/sets/lists/dtb/ad.earmv6eb \
src/distrib/sets/lists/dtb/ad.earmv6hf \
src/distrib/sets/lists/dtb/ad.earmv6hfeb
cvs rdiff -u -r1.1 -r1.2 src/sys/dtb/arm64/rockchip/Makefile

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

Modified files:

Index: src/distrib/sets/lists/dtb/ad.aarch64
diff -u src/distrib/sets/lists/dtb/ad.aarch64:1.6 src/distrib/sets/lists/dtb/ad.aarch64:1.7
--- src/distrib/sets/lists/dtb/ad.aarch64:1.6	Sat Jan  2 11:36:36 2021
+++ src/distrib/sets/lists/dtb/ad.aarch64	Wed Jun  2 10:31:18 2021
@@ -1,4 +1,4 @@
-# $NetBSD: ad.aarch64,v 1.6 2021/01/02 11:36:36 ryo Exp $
+# $NetBSD: ad.aarch64,v 1.7 2021/06/02 10:31:18 jmcneill Exp $
 #
 # DO NOT EDIT THIS FILE MANUALLY
 # Generated by "make update-sets" in sys/dtb
@@ -101,6 +101,7 @@
 ./boot/dtb/nvidia/tegra210-p2894-0050-a08.dtbdtb-base-boot  dtb
 ./boot/dtb/nvidia/tegra210-p3450-.dtbdtb-base-boot  dtb
 ./boot/dtb/nvidia/tegra210-smaug.dtb dtb-base-boot  dtb
+./boot/dtb/rk3399-pinebook-pro.dtb   dtb-base-boot  dtb
 ./boot/dtb/rockchip  dtb-base-boot  dtb
 ./boot/dtb/rockchip/px30-evb.dtb dtb-base-boot  dtb
 ./boot/dtb/rockchip/rk3308-evb.dtb   dtb-base-boot  dtb

Index: src/distrib/sets/lists/dtb/ad.aarch64eb
diff -u src/distrib/sets/lists/dtb/ad.aarch64eb:1.5 src/distrib/sets/lists/dtb/ad.aarch64eb:1.6
--- src/distrib/sets/lists/dtb/ad.aarch64eb:1.5	Sat Jan  2 11:36:36 2021
+++ src/distrib/sets/lists/dtb/ad.aarch64eb	Wed Jun  2 10:31:18 2021
@@ -1,4 +1,4 @@
-# $NetBSD: ad.aarch64eb,v 1.5 2021/01/02 11:36:36 ryo Exp $
+# $NetBSD: ad.aarch64eb,v 1.6 2021/06/02 10:31:18 jmcneill Exp $
 #
 # DO NOT EDIT THIS FILE MANUALLY
 # Generated by "make update-sets" in sys/dtb
@@ -101,6 +101,7 @@
 ./boot/dtb/nvidia/tegra210-p2894-0050-a08.dtbdtb-base-boot  dtb
 ./boot/dtb/nvidia/tegra210-p3450-.dtbdtb-base-boot  dtb
 ./boot/dtb/nvidia/tegra210-smaug.dtb dtb-base-boot  dtb
+./boot/dtb/rk3399-pinebook-pro.dtb   dtb-base-boot  dtb
 ./boot/dtb/rockchip  dtb-base-boot  dtb
 ./boot/dtb/rockchip/px30-evb.dtb dtb-base-boot  dtb
 ./boot/dtb/rockchip/rk3308-evb.dtb   dtb-base-boot  dtb
Index: src/distrib/sets/lists/dtb/ad.earmv7
diff -u src/distrib/sets/lists/dtb/ad.earmv7:1.5 src/distrib/sets/lists/dtb/ad.earmv7:1.6
--- src/distrib/sets/lists/dtb/ad.earmv7:1.5	Wed Jun 10 18:53:31 2020
+++ src/distrib/sets/lists/dtb/ad.earmv7	Wed Jun  2 10:31:18 2021
@@ -1,4 +1,4 @@
-# $NetBSD: ad.earmv7,v 1.5 2020/06/10 18:53:31 jmcneill Exp $
+# $NetBSD: ad.earmv7,v 1.6 2021/06/02 10:31:18 jmcneill Exp $
 #
 # DO NOT EDIT THIS FILE MANUALLY
 # Generated by "make update-sets" in sys/dtb
Index: src/distrib/sets/lists/dtb/ad.earmv7hf
diff -u src/distrib/sets/lists/dtb/ad.earmv7hf:1.5 src/distrib/sets/lists/dtb/ad.earmv7hf:1.6
--- src/distrib/sets/lists/dtb/ad.earmv7hf:1.5	Wed Jun 10 18:53:31 2020
+++ src/distrib/sets/lists/dtb/ad.earmv7hf	Wed Jun  2 10:31:18 2021
@@ -1,4 +1,4 @@
-# $NetBSD: ad.earmv7hf,v 1.5 2020/06/10 18:53:31 jmcneill Exp $
+# $NetBSD: ad.earmv7hf,v 1.6 2021/06/02 10:31:18 jmcneill Exp $
 #
 # DO NOT EDIT THIS FILE MANUALLY
 # Generated by "make update-sets" in sys/dtb
Index: src/distrib/sets/lists/dtb/ad.earmv7hfeb
diff -u src/distrib/sets/lists/dtb/ad.earmv7hfeb:1.5 src/distrib/sets/lists/dtb/ad.earmv7hfeb:1.6
--- src/distrib/sets/lists/dtb/ad.earmv7hfeb:1.5	Wed Jun 10 18:53:31 2020
+++ src/distrib/sets/lists/dtb/ad.earmv7hfeb	Wed Jun  2 10:31:18 2021
@@ -1,4 +1,4 @@
-# $NetBSD: ad.earmv7hfeb,v 1.5 2020/06/10 18:53:31 jmcneill Exp $
+# $NetBSD: ad.earmv7hfeb,v 1.6 2021/06/02 10:31:18 jmcneill Exp $
 #
 # DO NOT EDIT THIS FILE MANUALLY
 # Generated by "make update-sets" in

CVS commit: src/share/mk

2021-06-02 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jun  2 10:28:21 UTC 2021

Modified Files:
src/share/mk: bsd.dtb.mk

Log Message:
Add support for installing a copy of dtb files to the base dtb directory
when DTBSUBDIR is defined.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/share/mk/bsd.dtb.mk

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

Modified files:

Index: src/share/mk/bsd.dtb.mk
diff -u src/share/mk/bsd.dtb.mk:1.2 src/share/mk/bsd.dtb.mk:1.3
--- src/share/mk/bsd.dtb.mk:1.2	Tue May 19 08:59:36 2020
+++ src/share/mk/bsd.dtb.mk	Wed Jun  2 10:28:21 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: bsd.dtb.mk,v 1.2 2020/05/19 08:59:36 rin Exp $
+#	$NetBSD: bsd.dtb.mk,v 1.3 2021/06/02 10:28:21 jmcneill Exp $
 
 .include 
 .include 
@@ -71,11 +71,24 @@ dtbinstall:	dtb
 	${INSTALL_FILE} -o ${DTBOWN} -g ${DTBGRP} -m ${DTBMODE} \
 	${.OBJDIR}/${_dtb} ${DESTDIR}${DTBINSTDIR}
 .endfor
+.if defined(DTSSUBDIR)
+.for _dtb in ${DTB_NOSUBDIR}
+	${_MKSHMSG_INSTALL} ${_dtb}
+	${_MKSHECHO} "${INSTALL_FILE} -o ${DTBOWN} -g ${DTBGRP} -m ${DTBMODE} \
+	${.OBJDIR}/${_dtb} ${DESTDIR}${DTBDIR}"
+	${INSTALL_FILE} -o ${DTBOWN} -g ${DTBGRP} -m ${DTBMODE} \
+	${.OBJDIR}/${_dtb} ${DESTDIR}${DTBDIR}
+.endfor
+.endif
 
 dtblist:
 .if defined(DTSSUBDIR)
 	@echo ".${DTBINSTDIR}\t\tdtb-base-boot\tdtb" | \
 	${TOOL_SED} 's/\\t/	/g'
+.for _dtb in ${DTB_NOSUBDIR}
+	@echo ".${DTBDIR}/${_dtb}\t\tdtb-base-boot\tdtb" | \
+	${TOOL_SED} 's/\\t/	/g'
+.endfor
 .endif
 .for _dtb in ${DTB}
 	@echo ".${DTBINSTDIR}/${_dtb}\t\tdtb-base-boot\tdtb" | \



CVS commit: src/sys/dev/usb

2021-05-27 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu May 27 10:44:29 UTC 2021

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

Log Message:
Honour USBMALLOC_ZERO when reusing blocks from the freelist.

>From sc.dying on tech-kern


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

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

Modified files:

Index: src/sys/dev/usb/usb_mem.c
diff -u src/sys/dev/usb/usb_mem.c:1.80 src/sys/dev/usb/usb_mem.c:1.81
--- src/sys/dev/usb/usb_mem.c:1.80	Tue Jan  5 18:00:21 2021
+++ src/sys/dev/usb/usb_mem.c	Thu May 27 10:44:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_mem.c,v 1.80 2021/01/05 18:00:21 skrll Exp $	*/
+/*	$NetBSD: usb_mem.c,v 1.81 2021/05/27 10:44:29 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.80 2021/01/05 18:00:21 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.81 2021/05/27 10:44:29 jmcneill Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -118,8 +118,13 @@ usb_block_allocmem(bus_dma_tag_t tag, si
 	KASSERT(size != 0);
 	KASSERT(mutex_owned(&usb_blk_lock));
 
+#ifdef USB_FRAG_DMA_WORKAROUND
+	flags |= USBMALLOC_ZERO;
+#endif
+
 	bool multiseg = (flags & USBMALLOC_MULTISEG) != 0;
 	bool coherent = (flags & USBMALLOC_COHERENT) != 0;
+	bool zero = (flags & USBMALLOC_ZERO) != 0;
 	u_int dmaflags = coherent ? USB_DMA_COHERENT : 0;
 
 	/* First check the free list. */
@@ -134,6 +139,11 @@ usb_block_allocmem(bus_dma_tag_t tag, si
 			LIST_REMOVE(b, next);
 			usb_blk_nfree--;
 			*dmap = b;
+			if (zero) {
+memset(b->kaddr, 0, b->size);
+bus_dmamap_sync(b->tag, b->map, 0, b->size,
+BUS_DMASYNC_PREWRITE);
+			}
 			DPRINTFN(6, "free list size=%ju", b->size, 0, 0, 0);
 			return 0;
 		}
@@ -180,10 +190,7 @@ usb_block_allocmem(bus_dma_tag_t tag, si
 
 	*dmap = b;
 
-#ifdef USB_FRAG_DMA_WORKAROUND
-	flags |= USBMALLOC_ZERO;
-#endif
-	if ((flags & USBMALLOC_ZERO) != 0) {
+	if (zero) {
 		memset(b->kaddr, 0, b->size);
 		bus_dmamap_sync(b->tag, b->map, 0, b->size,
 		BUS_DMASYNC_PREWRITE);



CVS commit: src/sys/stand/efiboot

2021-05-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri May 21 21:53:15 UTC 2021

Modified Files:
src/sys/stand/efiboot: efiacpi.c efiacpi.h efifdt.c exec.c version

Log Message:
Disable ACPI support when booting big endian kernels.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/stand/efiboot/efiacpi.c
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/efiacpi.h
cvs rdiff -u -r1.28 -r1.29 src/sys/stand/efiboot/efifdt.c
cvs rdiff -u -r1.20 -r1.21 src/sys/stand/efiboot/exec.c
cvs rdiff -u -r1.22 -r1.23 src/sys/stand/efiboot/version

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

Modified files:

Index: src/sys/stand/efiboot/efiacpi.c
diff -u src/sys/stand/efiboot/efiacpi.c:1.8 src/sys/stand/efiboot/efiacpi.c:1.9
--- src/sys/stand/efiboot/efiacpi.c:1.8	Sat Oct 10 19:17:39 2020
+++ src/sys/stand/efiboot/efiacpi.c	Fri May 21 21:53:15 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efiacpi.c,v 1.8 2020/10/10 19:17:39 jmcneill Exp $ */
+/* $NetBSD: efiacpi.c,v 1.9 2021/05/21 21:53:15 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -53,6 +53,7 @@ struct acpi_rdsp {
 static EFI_GUID Acpi20TableGuid = ACPI_20_TABLE_GUID;
 static EFI_GUID Smbios3TableGuid = SMBIOS3_TABLE_GUID;
 
+static int acpi_enable = 1;
 static void *acpi_root = NULL;
 static void *smbios3_table = NULL;
 
@@ -78,6 +79,18 @@ efi_acpi_available(void)
 	return acpi_root != NULL;
 }
 
+int
+efi_acpi_enabled(void)
+{
+	return acpi_enable;
+}
+
+void
+efi_acpi_enable(int enable)
+{
+	acpi_enable = enable;
+}
+
 static char model_buf[128];
 
 static const char *

Index: src/sys/stand/efiboot/efiacpi.h
diff -u src/sys/stand/efiboot/efiacpi.h:1.1 src/sys/stand/efiboot/efiacpi.h:1.2
--- src/sys/stand/efiboot/efiacpi.h:1.1	Fri Oct 12 22:08:04 2018
+++ src/sys/stand/efiboot/efiacpi.h	Fri May 21 21:53:15 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efiacpi.h,v 1.1 2018/10/12 22:08:04 jmcneill Exp $ */
+/* $NetBSD: efiacpi.h,v 1.2 2021/05/21 21:53:15 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -32,4 +32,6 @@
 int efi_acpi_probe(void);
 void efi_acpi_show(void);
 int efi_acpi_available(void);
+int efi_acpi_enabled(void);
+void efi_acpi_enable(int);
 int efi_acpi_create_fdt(void);

Index: src/sys/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.28 src/sys/stand/efiboot/efifdt.c:1.29
--- src/sys/stand/efiboot/efifdt.c:1.28	Sat Dec 19 08:09:31 2020
+++ src/sys/stand/efiboot/efifdt.c	Fri May 21 21:53:15 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.28 2020/12/19 08:09:31 skrll Exp $ */
+/* $NetBSD: efifdt.c,v 1.29 2021/05/21 21:53:15 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -370,7 +370,7 @@ efi_fdt_gop(void)
 		/*
 		 * In ACPI mode, use GOP as console.
 		 */
-		if (efi_acpi_available()) {
+		if (efi_acpi_available() && efi_acpi_enabled()) {
 			snprintf(buf, sizeof(buf), "/chosen/framebuffer@%" PRIx64, mode->FrameBufferBase);
 			fdt_setprop_string(fdt_data, chosen, "stdout-path", buf);
 		}

Index: src/sys/stand/efiboot/exec.c
diff -u src/sys/stand/efiboot/exec.c:1.20 src/sys/stand/efiboot/exec.c:1.21
--- src/sys/stand/efiboot/exec.c:1.20	Tue May 11 07:15:10 2021
+++ src/sys/stand/efiboot/exec.c	Fri May 21 21:53:15 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.20 2021/05/11 07:15:10 skrll Exp $ */
+/* $NetBSD: exec.c,v 1.21 2021/05/21 21:53:15 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -289,7 +289,10 @@ exec_netbsd(const char *fname, const cha
 	load_offset = 0;
 
 #ifdef EFIBOOT_ACPI
-	if (efi_acpi_available()) {
+	/* ACPI support only works for little endian kernels */
+	efi_acpi_enable(netbsd_elf_data == ELFDATA2LSB);
+
+	if (efi_acpi_available() && efi_acpi_enabled()) {
 		efi_acpi_create_fdt();
 	} else
 #endif

Index: src/sys/stand/efiboot/version
diff -u src/sys/stand/efiboot/version:1.22 src/sys/stand/efiboot/version:1.23
--- src/sys/stand/efiboot/version:1.22	Sun Oct 18 18:09:32 2020
+++ src/sys/stand/efiboot/version	Fri May 21 21:53:15 2021
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.22 2020/10/18 18:09:32 tnn Exp $
+$NetBSD: version,v 1.23 2021/05/21 21:53:15 jmcneill Exp $
 
 NOTE ANY CHANGES YOU MAKE TO THE EFI BOOTLOADER HERE.  The format of this
 file is important - make sure the entries are appended on end, last item
@@ -26,3 +26,4 @@ is taken as the current.
 2.3:	EFI RT and GOP support for devicetree mode.
 2.4:	Add ISO9660 support.
 2.5:	Recognize the EFI system partion as fstype MSDOS.
+2.6:	Disable ACPI support when booting big endian kernels.



CVS commit: src/sys/lib/libsa

2021-05-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri May 21 21:52:16 UTC 2021

Modified Files:
src/sys/lib/libsa: loadfile.c loadfile.h

Log Message:
Capture the endianness of the ELF file loaded in 'netbsd_elf_data', the
same way we do already for the class in 'netbsd_elf_class'.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/lib/libsa/loadfile.c
cvs rdiff -u -r1.14 -r1.15 src/sys/lib/libsa/loadfile.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/lib/libsa/loadfile.c
diff -u src/sys/lib/libsa/loadfile.c:1.32 src/sys/lib/libsa/loadfile.c:1.33
--- src/sys/lib/libsa/loadfile.c:1.32	Fri Apr  5 20:09:29 2019
+++ src/sys/lib/libsa/loadfile.c	Fri May 21 21:52:15 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: loadfile.c,v 1.32 2019/04/05 20:09:29 christos Exp $ */
+/* $NetBSD: loadfile.c,v 1.33 2021/05/21 21:52:15 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 1997, 2008 The NetBSD Foundation, Inc.
@@ -84,6 +84,7 @@
 
 uint32_t	netbsd_version;
 u_int		netbsd_elf_class;
+u_int		netbsd_elf_data;
 
 /*
  * Open 'filename', read in program and return the opened file
@@ -159,6 +160,7 @@ fdloadfile(int fd, u_long *marks, int fl
 	if (memcmp(hdr.elf32.e_ident, ELFMAG, SELFMAG) == 0 &&
 	hdr.elf32.e_ident[EI_CLASS] == ELFCLASS32) {
 		netbsd_elf_class = ELFCLASS32;
+		netbsd_elf_data = hdr.elf32.e_ident[EI_DATA];
 		rval = loadfile_elf32(fd, &hdr.elf32, marks, flags);
 	} else
 #endif
@@ -166,6 +168,7 @@ fdloadfile(int fd, u_long *marks, int fl
 	if (memcmp(hdr.elf64.e_ident, ELFMAG, SELFMAG) == 0 &&
 	hdr.elf64.e_ident[EI_CLASS] == ELFCLASS64) {
 		netbsd_elf_class = ELFCLASS64;
+		netbsd_elf_data = hdr.elf64.e_ident[EI_DATA];
 		rval = loadfile_elf64(fd, &hdr.elf64, marks, flags);
 	} else
 #endif

Index: src/sys/lib/libsa/loadfile.h
diff -u src/sys/lib/libsa/loadfile.h:1.14 src/sys/lib/libsa/loadfile.h:1.15
--- src/sys/lib/libsa/loadfile.h:1.14	Sat Oct  7 10:26:39 2017
+++ src/sys/lib/libsa/loadfile.h	Fri May 21 21:52:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: loadfile.h,v 1.14 2017/10/07 10:26:39 maxv Exp $	 */
+/*	$NetBSD: loadfile.h,v 1.15 2021/05/21 21:52:15 jmcneill Exp $	 */
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -93,3 +93,4 @@ int loadfile_aout(int, struct exec *, u_
 
 extern uint32_t netbsd_version;
 extern u_int netbsd_elf_class;
+extern u_int netbsd_elf_data;



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

2021-05-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri May 21 09:33:27 UTC 2021

Modified Files:
src/sys/arch/arm/rockchip: rk_fb.c

Log Message:
whitespace cleanup


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/rockchip/rk_fb.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/rockchip/rk_fb.c
diff -u src/sys/arch/arm/rockchip/rk_fb.c:1.1 src/sys/arch/arm/rockchip/rk_fb.c:1.2
--- src/sys/arch/arm/rockchip/rk_fb.c:1.1	Sat Nov  9 23:30:14 2019
+++ src/sys/arch/arm/rockchip/rk_fb.c	Fri May 21 09:33:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: rk_fb.c,v 1.1 2019/11/09 23:30:14 jmcneill Exp $ */
+/* $NetBSD: rk_fb.c,v 1.2 2021/05/21 09:33:27 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015-2019 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_wsdisplay_compat.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rk_fb.c,v 1.1 2019/11/09 23:30:14 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rk_fb.c,v 1.2 2021/05/21 09:33:27 jmcneill Exp $");
 
 #include 
 #include 
@@ -61,7 +61,6 @@ static int	rk_fb_ioctl(struct drmfb_soft
 static const struct drmfb_params rkfb_drmfb_params = {
 	.dp_mmapfb = rk_fb_mmapfb,
 	.dp_ioctl = rk_fb_ioctl,
-	
 };
 
 CFATTACH_DECL_NEW(rk_fb, sizeof(struct rk_fb_softc),



CVS commit: src/sys/dev/fdt

2021-05-18 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue May 18 11:13:31 UTC 2021

Modified Files:
src/sys/dev/fdt: dwc3_fdt.c

Log Message:
Unbreak previous; we have to look for a child node iff our node isn't
compatible with snps,dwc3.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/fdt/dwc3_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/dev/fdt/dwc3_fdt.c
diff -u src/sys/dev/fdt/dwc3_fdt.c:1.14 src/sys/dev/fdt/dwc3_fdt.c:1.15
--- src/sys/dev/fdt/dwc3_fdt.c:1.14	Sat Apr 24 23:36:53 2021
+++ src/sys/dev/fdt/dwc3_fdt.c	Tue May 18 11:13:31 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: dwc3_fdt.c,v 1.14 2021/04/24 23:36:53 thorpej Exp $ */
+/* $NetBSD: dwc3_fdt.c,v 1.15 2021/05/18 11:13:31 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dwc3_fdt.c,v 1.14 2021/04/24 23:36:53 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwc3_fdt.c,v 1.15 2021/05/18 11:13:31 jmcneill Exp $");
 
 #include 
 #include 
@@ -203,14 +203,18 @@ dwc3_fdt_set_mode(struct xhci_softc *sc,
 }
 
 static const struct device_compatible_entry compat_data[] = {
-		/* 1 = parent of dwc3 subnode */
-	{ .compat = "allwinner,sun50i-h6-dwc3",		.value = 1 },
-	{ .compat = "amlogic,meson-gxl-dwc3",		.value = 1 },
-	{ .compat = "fsl,imx8mq-dwc3",			.value = 1 },
-	{ .compat = "rockchip,rk3328-dwc3",		.value = 1 },
-	{ .compat = "rockchip,rk3399-dwc3",		.value = 1 },
-	{ .compat = "samsung,exynos5250-dwusb3",	.value = 1 },
-	{ .compat = "snps,dwc3",			.value = 0 },
+	{ .compat = "allwinner,sun50i-h6-dwc3" },
+	{ .compat = "amlogic,meson-gxl-dwc3" },
+	{ .compat = "fsl,imx8mq-dwc3" },
+	{ .compat = "rockchip,rk3328-dwc3" },
+	{ .compat = "rockchip,rk3399-dwc3" },
+	{ .compat = "samsung,exynos5250-dwusb3" },
+	{ .compat = "snps,dwc3" },
+	DEVICE_COMPAT_EOL
+};
+
+static const struct device_compatible_entry compat_data_dwc3[] = {
+	{ .compat = "snps,dwc3" },
 	DEVICE_COMPAT_EOL
 };
 
@@ -228,7 +232,6 @@ dwc3_fdt_attach(device_t parent, device_
 	struct xhci_softc * const sc = device_private(self);
 	struct fdt_attach_args * const faa = aux;
 	const int phandle = faa->faa_phandle;
-	const struct device_compatible_entry *dce;
 	struct fdtbus_reset *rst;
 	struct fdtbus_phy *phy;
 	struct clk *clk;
@@ -239,11 +242,8 @@ dwc3_fdt_attach(device_t parent, device_
 	void *ih;
 	u_int n;
 
-	dce = of_compatible_lookup(phandle, compat_data);
-	KASSERT(dce != NULL);
-
 	/* Find dwc3 sub-node */
-	if (dce->value != 0) {
+	if (of_compatible_lookup(phandle, compat_data_dwc3) == NULL) {
 		dwc3_phandle = of_find_firstchild_byname(phandle, "dwc3");
 	} else {
 		dwc3_phandle = phandle;



CVS commit: src/sys/dev/spi

2021-05-14 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri May 14 09:25:14 UTC 2021

Modified Files:
src/sys/dev/spi: m25p.c

Log Message:
Replace aprint_error with aprint_error_dev in config_interrupts callback.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/spi/m25p.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/spi/m25p.c
diff -u src/sys/dev/spi/m25p.c:1.17 src/sys/dev/spi/m25p.c:1.18
--- src/sys/dev/spi/m25p.c:1.17	Wed Jan 27 02:32:31 2021
+++ src/sys/dev/spi/m25p.c	Fri May 14 09:25:14 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: m25p.c,v 1.17 2021/01/27 02:32:31 thorpej Exp $ */
+/* $NetBSD: m25p.c,v 1.18 2021/05/14 09:25:14 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.17 2021/01/27 02:32:31 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.18 2021/05/14 09:25:14 jmcneill Exp $");
 
 #include 
 #include 
@@ -166,7 +166,7 @@ m25p_doattach(device_t self)
 	/* first we try JEDEC ID read */
 	cmd = SPIFLASH_CMD_RDJI;
 	if (spi_send_recv(sc->sc_sh, 1, &cmd, 3, buf)) {
-		aprint_error(": failed to get JEDEC identification\n");
+		aprint_error_dev(self, "failed to get JEDEC identification\n");
 		return;
 	}
 	mfgid = buf[0];
@@ -175,7 +175,8 @@ m25p_doattach(device_t self)
 	if ((mfgid == 0xff) || (mfgid == 0)) {
 		cmd = SPIFLASH_CMD_RDID;
 		if (spi_send_recv(sc->sc_sh, 1, &cmd, 4, buf)) {
-			aprint_error(": failed to get legacy signature\n");
+			aprint_error_dev(self,
+			"failed to get legacy signature\n");
 			return;
 		}
 		sig = buf[3];
@@ -192,8 +193,9 @@ m25p_doattach(device_t self)
 	}
 
 	if (info->name == NULL) {
-		aprint_error(": vendor 0x%02X dev 0x%04X sig 0x%02X not supported\n",
-			 mfgid, devid, sig);
+		aprint_error_dev(self,
+		"vendor 0x%02X dev 0x%04X sig 0x%02X not supported\n",
+		 mfgid, devid, sig);
 		return;
 	}
 



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

2021-05-05 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed May  5 20:58:03 UTC 2021

Modified Files:
src/sys/arch/arm/sunxi: sunxi_codec.c sunxi_codec.h

Log Message:
Fix GENERIC64 build


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/arm/sunxi/sunxi_codec.c
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/arm/sunxi/sunxi_codec.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/sunxi/sunxi_codec.c
diff -u src/sys/arch/arm/sunxi/sunxi_codec.c:1.13 src/sys/arch/arm/sunxi/sunxi_codec.c:1.14
--- src/sys/arch/arm/sunxi/sunxi_codec.c:1.13	Wed May  5 10:24:04 2021
+++ src/sys/arch/arm/sunxi/sunxi_codec.c	Wed May  5 20:58:03 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_codec.c,v 1.13 2021/05/05 10:24:04 jmcneill Exp $ */
+/* $NetBSD: sunxi_codec.c,v 1.14 2021/05/05 20:58:03 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_ddb.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_codec.c,v 1.13 2021/05/05 10:24:04 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_codec.c,v 1.14 2021/05/05 20:58:03 jmcneill Exp $");
 
 #include 
 #include 
@@ -89,10 +89,10 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_codec.
 #define	AC_ADC_CNT(_sc)		((_sc)->sc_cfg->ADC_CNT)
 
 static const struct device_compatible_entry compat_data[] = {
-	A10_CODEC_COMPATDATA,
-	A31_CODEC_COMPATDATA,
-	H3_CODEC_COMPATDATA,
-	V3S_CODEC_COMPATDATA,
+	A10_CODEC_COMPATDATA
+	A31_CODEC_COMPATDATA
+	H3_CODEC_COMPATDATA
+	V3S_CODEC_COMPATDATA
 
 	DEVICE_COMPAT_EOL
 };

Index: src/sys/arch/arm/sunxi/sunxi_codec.h
diff -u src/sys/arch/arm/sunxi/sunxi_codec.h:1.7 src/sys/arch/arm/sunxi/sunxi_codec.h:1.8
--- src/sys/arch/arm/sunxi/sunxi_codec.h:1.7	Wed May  5 10:24:04 2021
+++ src/sys/arch/arm/sunxi/sunxi_codec.h	Wed May  5 20:58:03 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_codec.h,v 1.7 2021/05/05 10:24:04 jmcneill Exp $ */
+/* $NetBSD: sunxi_codec.h,v 1.8 2021/05/05 20:58:03 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill 
@@ -121,7 +121,7 @@ struct sunxi_codec_softc {
 extern const struct sunxi_codec_conf sun8i_h3_codecconf;
 #define	H3_CODEC_COMPATDATA		\
 	{ .compat = "allwinner,sun8i-h3-codec",\
-	  .data = &sun8i_h3_codecconf }
+	  .data = &sun8i_h3_codecconf },
 #else
 #define	H3_CODEC_COMPATDATA
 #endif
@@ -130,7 +130,7 @@ extern const struct sunxi_codec_conf sun
 extern const struct sunxi_codec_conf sun8i_v3s_codecconf;
 #define V3S_CODEC_COMPATDATA		\
 	{ .compat = "allwinner,sun8i-v3s-codec",			\
-	  .data = &sun8i_v3s_codecconf }
+	  .data = &sun8i_v3s_codecconf },
 #else
 #define V3S_CODEC_COMPATDATA
 #endif
@@ -140,11 +140,11 @@ extern const struct sunxi_codec_conf sun
 	{ .compat = "allwinner,sun4i-a10-codec",			\
 	  .data = &sun4i_a10_codecconf }, \
 	{ .compat = "allwinner,sun7i-a20-codec",			\
-	  .data = &sun4i_a10_codecconf }
+	  .data = &sun4i_a10_codecconf },
 
 extern const struct sunxi_codec_conf sun6i_a31_codecconf;
 #define	A31_CODEC_COMPATDATA		\
 	{ .compat = "allwinner,sun6i-a31-codec",			\
-	  .data = &sun6i_a31_codecconf }
+	  .data = &sun6i_a31_codecconf },
 
 #endif /* !_ARM_SUNXI_CODEC_H */



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

2021-05-05 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed May  5 12:47:02 UTC 2021

Added Files:
src/sys/arch/riscv/include: loadfile_machdep.h

Log Message:
Add loadfile_machdep.h for riscv


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/arch/riscv/include/loadfile_machdep.h

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

Added files:

Index: src/sys/arch/riscv/include/loadfile_machdep.h
diff -u /dev/null src/sys/arch/riscv/include/loadfile_machdep.h:1.1
--- /dev/null	Wed May  5 12:47:02 2021
+++ src/sys/arch/riscv/include/loadfile_machdep.h	Wed May  5 12:47:02 2021
@@ -0,0 +1,33 @@
+/*	$NetBSD: loadfile_machdep.h,v 1.1 2021/05/05 12:47:02 jmcneill Exp $	*/
+
+#ifdef _LP64
+#define BOOT_ELF64
+#else
+#define BOOT_ELF32
+#endif
+
+#define LOAD_KERNEL	(LOAD_ALL & ~LOAD_TEXTA)
+#define COUNT_KERNEL	(COUNT_ALL & ~COUNT_TEXTA)
+
+#define LOADADDR(a)		(((u_long)(a)))
+#define ALIGNENTRY(a)		((u_long)(a))
+#define READ(f, b, c)		read((f), (void*)LOADADDR(b), (c))
+#define BCOPY(s, d, c)		memmove((void*)LOADADDR(d), (void*)(s), (c))
+#define BZERO(d, c)		memset((void*)LOADADDR(d), 0, (c))
+#define	WARN(a)			do { \
+	(void)printf a; \
+	if (errno) \
+		(void)printf(": %s\n", \
+		 strerror(errno)); \
+	else \
+		(void)printf("\n"); \
+} while(/* CONSTCOND */0)
+#ifdef PROGRESS_FN
+void PROGRESS_FN(const char *, ...) __printflike(1, 2);
+#define PROGRESS(a)		PROGRESS_FN a
+#else
+#define PROGRESS(a)		(void)printf a
+#endif
+#define ALLOC(a)		alloc(a)
+#define DEALLOC(a, b)		dealloc(a, b)
+#define OKMAGIC(a)		((a) == ZMAGIC)



CVS commit: src/doc

2021-05-05 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed May  5 10:25:37 UTC 2021

Modified Files:
src/doc: CHANGES

Log Message:
evbarm: Add support for Allwinner V3s SoCs.


To generate a diff of this commit:
cvs rdiff -u -r1.2802 -r1.2803 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.2802 src/doc/CHANGES:1.2803
--- src/doc/CHANGES:1.2802	Sat May  1 16:14:35 2021
+++ src/doc/CHANGES	Wed May  5 10:25:36 2021
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2802 $>
+# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2803 $>
 #
 #
 # [Note: This file does not mention every change made to the NetBSD source tree.
@@ -369,3 +369,4 @@ Changes from NetBSD 9.0 to NetBSD 10.0:
 	resolver: The default has been changed to check-names
 		(see resolv.conf(5)), which means that hostnames that
 		contain invalid characters will not resolve. [christos 20210430]
+	evbarm: Add support for Allwinner V3s SoCs. [jmcneill 20210505]



CVS commit: src/sys/arch

2021-05-05 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed May  5 10:24:04 UTC 2021

Modified Files:
src/sys/arch/arm/sunxi: files.sunxi sun6i_dma.c sunxi_codec.c
sunxi_codec.h
src/sys/arch/evbarm/conf: GENERIC
Added Files:
src/sys/arch/arm/sunxi: sun8i_v3s_ccu.c sun8i_v3s_ccu.h
sun8i_v3s_codec.c

Log Message:
Add support for Allwinner V3s, from Rui-Xiang Guo.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/arch/arm/sunxi/files.sunxi
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/arm/sunxi/sun6i_dma.c
cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/sunxi/sun8i_v3s_ccu.c \
src/sys/arch/arm/sunxi/sun8i_v3s_ccu.h \
src/sys/arch/arm/sunxi/sun8i_v3s_codec.c
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/arm/sunxi/sunxi_codec.c
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/sunxi/sunxi_codec.h
cvs rdiff -u -r1.96 -r1.97 src/sys/arch/evbarm/conf/GENERIC

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/sunxi/files.sunxi
diff -u src/sys/arch/arm/sunxi/files.sunxi:1.68 src/sys/arch/arm/sunxi/files.sunxi:1.69
--- src/sys/arch/arm/sunxi/files.sunxi:1.68	Tue Mar 24 22:09:50 2020
+++ src/sys/arch/arm/sunxi/files.sunxi	Wed May  5 10:24:04 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: files.sunxi,v 1.68 2020/03/24 22:09:50 tnn Exp $
+#	$NetBSD: files.sunxi,v 1.69 2021/05/05 10:24:04 jmcneill Exp $
 #
 # Configuration info for Allwinner sunxi family SoCs
 #
@@ -52,6 +52,11 @@ device	sun8ih3rccu: sunxi_ccu
 attach	sun8ih3rccu at fdt with sunxi_h3_r_ccu
 file	arch/arm/sunxi/sun8i_h3_r_ccu.c		sunxi_h3_r_ccu
 
+# CCU (V3s)
+device	sun8iv3sccu: sunxi_ccu
+attach	sun8iv3sccu at fdt with sunxi_v3s_ccu
+file	arch/arm/sunxi/sun8i_v3s_ccu.c		sunxi_v3s_ccu
+
 # CCU (A80)
 device	sun9ia80ccu: sunxi_ccu
 attach	sun9ia80ccu at fdt with sunxi_a80_ccu
@@ -233,6 +238,11 @@ device	h3codec
 attach	h3codec at fdt with h3_codec
 file	arch/arm/sunxi/sun8i_h3_codec.c		h3_codec needs-flag
 
+# V3s Audio codec (analog part)
+device	v3scodec
+attach	v3scodec at fdt with v3s_codec
+file	arch/arm/sunxi/sun8i_v3s_codec.c	v3s_codec needs-flag
+
 # A64 Audio codec (analog part)
 device	a64acodec
 attach	a64acodec at fdt with a64_acodec
@@ -375,6 +385,7 @@ defflag	opt_soc.h			SOC_SUN7I_A20: SOC_S
 defflag	opt_soc.h			SOC_SUN8I: SOC_SUNXI
 defflag	opt_soc.h			SOC_SUN8I_A83T: SOC_SUN8I, SOC_SUNXI_MC
 defflag	opt_soc.h			SOC_SUN8I_H3: SOC_SUN8I
+defflag	opt_soc.h			SOC_SUN8I_V3S: SOC_SUN8I
 defflag	opt_soc.h			SOC_SUN9I: SOC_SUNXI
 defflag	opt_soc.h			SOC_SUN9I_A80: SOC_SUN9I, SOC_SUNXI_MC
 defflag	opt_soc.h			SOC_SUN50I: SOC_SUNXI

Index: src/sys/arch/arm/sunxi/sun6i_dma.c
diff -u src/sys/arch/arm/sunxi/sun6i_dma.c:1.14 src/sys/arch/arm/sunxi/sun6i_dma.c:1.15
--- src/sys/arch/arm/sunxi/sun6i_dma.c:1.14	Wed Jan 27 03:10:20 2021
+++ src/sys/arch/arm/sunxi/sun6i_dma.c	Wed May  5 10:24:04 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sun6i_dma.c,v 1.14 2021/01/27 03:10:20 thorpej Exp $ */
+/* $NetBSD: sun6i_dma.c,v 1.15 2021/05/05 10:24:04 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_ddb.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sun6i_dma.c,v 1.14 2021/01/27 03:10:20 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sun6i_dma.c,v 1.15 2021/05/05 10:24:04 jmcneill Exp $");
 
 #include 
 #include 
@@ -141,6 +141,16 @@ static const struct sun6idma_config sun8
 	.widths = WIDTHS_1_2_4_8,
 };
 
+static const struct sun6idma_config sun8i_v3s_dma_config = {
+	.num_channels = 8,
+	.autogate = true,
+	.autogate_reg = 0x20,
+	.autogate_mask = 0x4,
+	.burst_mask = __BITS(8,7),
+	.bursts = BURSTS_1_8,
+	.widths = WIDTHS_1_2_4,
+};
+
 static const struct sun6idma_config sun50i_a64_dma_config = {
 	.num_channels = 8,
 	.autogate = true,
@@ -158,6 +168,8 @@ static const struct device_compatible_en
 	  .data = &sun8i_a83t_dma_config },
 	{ .compat = "allwinner,sun8i-h3-dma",
 	  .data = &sun8i_h3_dma_config },
+	{ .compat = "allwinner,sun8i-v3s-dma",
+	  .data = &sun8i_v3s_dma_config },
 	{ .compat = "allwinner,sun50i-a64-dma",
 	  .data = &sun50i_a64_dma_config },
 

Index: src/sys/arch/arm/sunxi/sunxi_codec.c
diff -u src/sys/arch/arm/sunxi/sunxi_codec.c:1.12 src/sys/arch/arm/sunxi/sunxi_codec.c:1.13
--- src/sys/arch/arm/sunxi/sunxi_codec.c:1.12	Wed Jan 27 03:10:20 2021
+++ src/sys/arch/arm/sunxi/sunxi_codec.c	Wed May  5 10:24:04 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_codec.c,v 1.12 2021/01/27 03:10:20 thorpej Exp $ */
+/* $NetBSD: sunxi_codec.c,v 1.13 2021/05/05 10:24:04 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_ddb.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_codec.c,v 1.12 2021/01/27 03:10:20 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_codec.c,v 1.13 2021/05/05 10:24:04 jmcneill Exp $");
 
 #include 
 #include 
@@ -92,6 +92,7 @@ static const struct device_compatible_en
 	A10_CODEC_COMPATDATA,
 	A31_CODEC_COMP

CVS commit: src/sys/stand/efiboot

2021-05-04 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue May  4 19:07:19 UTC 2021

Modified Files:
src/sys/stand/efiboot: Makefile.efiboot

Log Message:
Set VERSIONMACHINE to ${MACHINE} instead of evbarm (oops)


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/stand/efiboot/Makefile.efiboot

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

Modified files:

Index: src/sys/stand/efiboot/Makefile.efiboot
diff -u src/sys/stand/efiboot/Makefile.efiboot:1.19 src/sys/stand/efiboot/Makefile.efiboot:1.20
--- src/sys/stand/efiboot/Makefile.efiboot:1.19	Sun Oct 11 14:03:33 2020
+++ src/sys/stand/efiboot/Makefile.efiboot	Tue May  4 19:07:19 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.19 2020/10/11 14:03:33 jmcneill Exp $
+# $NetBSD: Makefile.efiboot,v 1.20 2021/05/04 19:07:19 jmcneill Exp $
 
 S=		${.CURDIR}/../../..
 
@@ -137,7 +137,7 @@ cleanlibdir:
 
 LIBLIST= ${LIBGNUEFI} ${LIBSA} ${LIBZ} ${LIBKERN} ${LIBSA}
 
-VERSIONMACHINE=evbarm
+VERSIONMACHINE=${MACHINE}
 .include "${S}/conf/newvers_stand.mk"
 
 CLEANFILES+=	${PROG}.so ${PROG}.tmp



CVS commit: src/sys/stand/efiboot/bootriscv64

2021-05-02 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun May  2 15:22:27 UTC 2021

Added Files:
src/sys/stand/efiboot/bootriscv64: Makefile efibootriscv64.c

Log Message:
Add RISC-V 64-bit support.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/stand/efiboot/bootriscv64/Makefile \
src/sys/stand/efiboot/bootriscv64/efibootriscv64.c

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

Added files:

Index: src/sys/stand/efiboot/bootriscv64/Makefile
diff -u /dev/null src/sys/stand/efiboot/bootriscv64/Makefile:1.1
--- /dev/null	Sun May  2 15:22:27 2021
+++ src/sys/stand/efiboot/bootriscv64/Makefile	Sun May  2 15:22:27 2021
@@ -0,0 +1,20 @@
+# $NetBSD: Makefile,v 1.1 2021/05/02 15:22:27 jmcneill Exp $
+
+PROG=		bootriscv64.efi
+OBJFMT=		binary
+NEWVERSWHAT=	"efiboot (riscv64)"
+GNUEFIARCH=	riscv64
+LIBGNUEFI_ARCH=	riscv64
+
+EXTRA_SOURCES=	efibootriscv64.c
+
+COPTS+=		-mcmodel=medany
+AFLAGS+=	-x assembler-with-cpp
+CFLAGS+=	-DEFIBOOT_ALIGN=0x20
+CFLAGS+=	-DEFIBOOT_MODULE_MACHINE=\"riscv\"
+
+.include "${.CURDIR}/../Makefile.efiboot"
+
+release: check_RELEASEDIR
+	${HOST_INSTALL_FILE} -m ${BINMODE} ${PROG} \
+		${RELEASEDIR}/${RELEASEMACHINEDIR}/installation/misc
Index: src/sys/stand/efiboot/bootriscv64/efibootriscv64.c
diff -u /dev/null src/sys/stand/efiboot/bootriscv64/efibootriscv64.c:1.1
--- /dev/null	Sun May  2 15:22:27 2021
+++ src/sys/stand/efiboot/bootriscv64/efibootriscv64.c	Sun May  2 15:22:27 2021
@@ -0,0 +1,78 @@
+/* $NetBSD: efibootriscv64.c,v 1.1 2021/05/02 15:22:27 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2021 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 REGENTS 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 REGENTS 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 "../efiboot.h"
+#include "../efifdt.h"
+
+#include 
+
+#include 
+#include 
+
+typedef void (*riscv_kernel_entry_t)(register_t, register_t);
+
+static uint32_t
+efi_fdt_get_boot_hartid(void)
+{
+	const int chosen = fdt_path_offset(efi_fdt_data(), "/chosen");
+	const uint32_t *data;
+
+	data = fdt_getprop(efi_fdt_data(), chosen, "boot-hartid", NULL);
+	if (data == NULL) {
+		return 0;	/* XXX */
+	}
+
+	return fdt32_to_cpu(*data);
+}
+
+void
+efi_boot_kernel(u_long marks[MARK_MAX])
+{
+	riscv_kernel_entry_t entry_fn;
+	register_t hart_id; /* a0 */
+	register_t fdt_start; /* a1 */
+
+	entry_fn = (riscv_kernel_entry_t)(uintptr_t)marks[MARK_ENTRY];
+
+	hart_id = efi_fdt_get_boot_hartid();
+	fdt_start = (register_t)efi_fdt_data();
+
+	asm volatile("fence rw,rw; fence.i" ::: "memory");
+
+	entry_fn(hart_id, fdt_start);
+}
+
+void
+efi_md_show(void)
+{
+}
+
+void
+efi_dcache_flush(u_long start, u_long size)
+{
+}



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

2021-03-28 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Mar 28 11:13:24 UTC 2021

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

Log Message:
Disable 1ofN distribution of SPIs by default. This is a workaround for an
issue in the USB stack -- signaling transfer complete on multiple PEs can
cause transfer completions to be processed out of order.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 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.43 src/sys/arch/arm/cortex/gicv3.c:1.44
--- src/sys/arch/arm/cortex/gicv3.c:1.43	Tue Feb 23 10:03:04 2021
+++ src/sys/arch/arm/cortex/gicv3.c	Sun Mar 28 11:13:24 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: gicv3.c,v 1.43 2021/02/23 10:03:04 jmcneill Exp $ */
+/* $NetBSD: gicv3.c,v 1.44 2021/03/28 11:13:24 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -31,7 +31,7 @@
 #define	_INTR_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gicv3.c,v 1.43 2021/02/23 10:03:04 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gicv3.c,v 1.44 2021/03/28 11:13:24 jmcneill Exp $");
 
 #include 
 #include 
@@ -65,6 +65,13 @@ __KERNEL_RCSID(0, "$NetBSD: gicv3.c,v 1.
 #define	GIC_PRIO_SHIFT_NS		4
 #define	GIC_PRIO_SHIFT_S		3
 
+/*
+ * Set to true if you want to use 1 of N interrupt distribution for SPIs
+ * when available. Disabled by default because it causes issues with the
+ * USB stack.
+ */
+bool gicv3_use_1ofn = false;
+
 static struct gicv3_softc *gicv3_softc;
 
 static inline uint32_t
@@ -195,7 +202,7 @@ gicv3_establish_irq(struct pic_softc *pi
 		 * If 1 of N SPI routing is supported, route MP-safe interrupts to all
 		 * participating PEs. Otherwise, just route to the primary PE.
 		 */
-		if (is->is_mpsafe && GIC_SUPPORTS_1OFN(sc)) {
+		if (is->is_mpsafe && GIC_SUPPORTS_1OFN(sc) && gicv3_use_1ofn) {
 			irouter = GICD_IROUTER_Interrupt_Routing_mode;
 		} else {
 			irouter = sc->sc_irouter[0];
@@ -498,7 +505,7 @@ gicv3_set_affinity(struct pic_softc *pic
 	const int set = kcpuset_countset(affinity);
 	if (set == 1) {
 		irouter = sc->sc_irouter[kcpuset_ffs(affinity) - 1];
-	} else if (set == ncpu && GIC_SUPPORTS_1OFN(sc)) {
+	} else if (set == ncpu && GIC_SUPPORTS_1OFN(sc) && gicv3_use_1ofn) {
 		irouter = GICD_IROUTER_Interrupt_Routing_mode;
 	} else {
 		return EINVAL;



CVS commit: src/sys/arch

2021-03-27 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Mar 27 12:15:09 UTC 2021

Modified Files:
src/sys/arch/aarch64/include: cpu.h
src/sys/arch/arm/include: cpu.h
src/sys/arch/arm/pic: pic.c pic_splfuncs.c picvar.h

Log Message:
Revert recent pic optimizations until I have more time to work on this.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/aarch64/include/cpu.h
cvs rdiff -u -r1.116 -r1.117 src/sys/arch/arm/include/cpu.h
cvs rdiff -u -r1.69 -r1.70 src/sys/arch/arm/pic/pic.c
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/arm/pic/pic_splfuncs.c
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/arm/pic/picvar.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/aarch64/include/cpu.h
diff -u src/sys/arch/aarch64/include/cpu.h:1.33 src/sys/arch/aarch64/include/cpu.h:1.34
--- src/sys/arch/aarch64/include/cpu.h:1.33	Sun Feb 21 17:07:06 2021
+++ src/sys/arch/aarch64/include/cpu.h	Sat Mar 27 12:15:09 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.33 2021/02/21 17:07:06 jmcneill Exp $ */
+/* $NetBSD: cpu.h,v 1.34 2021/03/27 12:15:09 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014, 2020 The NetBSD Foundation, Inc.
@@ -104,9 +104,6 @@ struct cpu_info {
 	int ci_hwpl;		/* current hardware priority */
 	volatile u_int ci_softints;
 	volatile u_int ci_intr_depth;
-	volatile uint32_t ci_blocked_pics;
-	volatile uint32_t ci_pending_pics;
-	volatile uint32_t ci_pending_ipls;
 
 	int ci_kfpu_spl;
 

Index: src/sys/arch/arm/include/cpu.h
diff -u src/sys/arch/arm/include/cpu.h:1.116 src/sys/arch/arm/include/cpu.h:1.117
--- src/sys/arch/arm/include/cpu.h:1.116	Sun Feb 21 15:00:04 2021
+++ src/sys/arch/arm/include/cpu.h	Sat Mar 27 12:15:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.116 2021/02/21 15:00:04 jmcneill Exp $	*/
+/*	$NetBSD: cpu.h,v 1.117 2021/03/27 12:15:08 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 1994-1996 Mark Brinicombe.
@@ -190,9 +190,6 @@ struct cpu_info {
 
 	volatile u_int	ci_intr_depth;	/* */
 	volatile u_int	ci_softints;
-	volatile uint32_t ci_blocked_pics;
-	volatile uint32_t ci_pending_pics;
-	volatile uint32_t ci_pending_ipls;
 
 	lwp_t *		ci_lastlwp;	/* last lwp */
 

Index: src/sys/arch/arm/pic/pic.c
diff -u src/sys/arch/arm/pic/pic.c:1.69 src/sys/arch/arm/pic/pic.c:1.70
--- src/sys/arch/arm/pic/pic.c:1.69	Sun Feb 21 17:07:45 2021
+++ src/sys/arch/arm/pic/pic.c	Sat Mar 27 12:15:09 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pic.c,v 1.69 2021/02/21 17:07:45 jmcneill Exp $	*/
+/*	$NetBSD: pic.c,v 1.70 2021/03/27 12:15:09 jmcneill Exp $	*/
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -33,7 +33,7 @@
 #include "opt_multiprocessor.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pic.c,v 1.69 2021/02/21 17:07:45 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pic.c,v 1.70 2021/03/27 12:15:09 jmcneill Exp $");
 
 #include 
 #include 
@@ -59,20 +59,43 @@ __KERNEL_RCSID(0, "$NetBSD: pic.c,v 1.69
 #include 
 
 #if defined(__HAVE_PIC_PENDING_INTRS)
-
 /*
  * This implementation of pending interrupts on a MULTIPROCESSOR system makes
  * the assumption that a PIC (pic_softc) shall only have all its interrupts
  * come from the same CPU.  In other words, interrupts from a single PIC will
  * not be distributed among multiple CPUs.
  */
+struct pic_pending {
+	volatile uint32_t blocked_pics;
+	volatile uint32_t pending_pics;
+	volatile uint32_t pending_ipls;
+};
 static uint32_t
 	pic_find_pending_irqs_by_ipl(struct pic_softc *, size_t, uint32_t, int);
 static struct pic_softc *
-	pic_list_find_pic_by_pending_ipl(struct cpu_info *, uint32_t);
+	pic_list_find_pic_by_pending_ipl(struct pic_pending *, uint32_t);
+static void
+	pic_deliver_irqs(struct pic_pending *, struct pic_softc *, int, void *);
 static void
-	pic_deliver_irqs(struct cpu_info *, struct pic_softc *, int, void *);
+	pic_list_deliver_irqs(struct pic_pending *, register_t, int, void *);
 
+#ifdef MULTIPROCESSOR
+percpu_t *pic_pending_percpu;
+static struct pic_pending *
+pic_pending_get(void)
+{
+	return percpu_getref(pic_pending_percpu);
+}
+static void
+pic_pending_put(struct pic_pending *pend)
+{
+	percpu_putref(pic_pending_percpu);
+}
+#else
+struct pic_pending pic_pending;
+#define	pic_pending_get()	(&pic_pending)
+#define	pic_pending_put(pend)	__nothing
+#endif /* MULTIPROCESSOR */
 #endif /* __HAVE_PIC_PENDING_INTRS */
 
 struct pic_softc *pic_list[PIC_MAXPICS];
@@ -95,6 +118,20 @@ EVCNT_ATTACH_STATIC(pic_deferral_ev);
 
 static int pic_init(void);
 
+#ifdef __HAVE_PIC_SET_PRIORITY
+void
+pic_set_priority(struct cpu_info *ci, int newipl)
+{
+	register_t psw = DISABLE_INTERRUPT_SAVE();
+	if (pic_list[0] != NULL)
+		(pic_list[0]->pic_ops->pic_set_priority)(pic_list[0], newipl);
+	ci->ci_cpl = newipl;
+	if ((psw & I32_bit) == 0) {
+		ENABLE_INTERRUPT();
+	}
+}
+#endif
+
 #ifdef MULTIPROCESSOR
 int
 pic_ipi_ast(void *arg)
@@ -138,9 +175,7 @@ pic_ipi_ddb(void *arg)
 int
 pic_ipi_kp

CVS commit: src/sys/dev/fdt

2021-03-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Mar 23 22:27:38 UTC 2021

Modified Files:
src/sys/dev/fdt: dwcmmc_fdt.c

Log Message:
Match generic "snps,dw-mshc" compat string as found in BeagleV.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/fdt/dwcmmc_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/dev/fdt/dwcmmc_fdt.c
diff -u src/sys/dev/fdt/dwcmmc_fdt.c:1.16 src/sys/dev/fdt/dwcmmc_fdt.c:1.17
--- src/sys/dev/fdt/dwcmmc_fdt.c:1.16	Wed Jan 27 03:10:21 2021
+++ src/sys/dev/fdt/dwcmmc_fdt.c	Tue Mar 23 22:27:38 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: dwcmmc_fdt.c,v 1.16 2021/01/27 03:10:21 thorpej Exp $ */
+/* $NetBSD: dwcmmc_fdt.c,v 1.17 2021/03/23 22:27:38 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015-2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dwcmmc_fdt.c,v 1.16 2021/01/27 03:10:21 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwcmmc_fdt.c,v 1.17 2021/03/23 22:27:38 jmcneill Exp $");
 
 #include 
 #include 
@@ -66,8 +66,14 @@ static const struct dwcmmc_fdt_config dw
 	.intr_cardmask = __BIT(24),
 };
 
+static const struct dwmmc_fdt_config dwmmc_default_config = {
+	.flags = DWC_MMC_F_USE_HOLD_REG |
+		 DWC_MMC_F_DMA,
+};
+
 static const struct device_compatible_entry compat_data[] = {
 	{ .compat = "rockchip,rk3288-dw-mshc",	.data = &dwcmmc_rk3288_config },
+	{ .compat = "snps,dw-mshc",		.data = &dwmmc_default_config },
 	DEVICE_COMPAT_EOL
 };
 
@@ -158,7 +164,7 @@ dwcmmc_fdt_attach(device_t parent, devic
 		sc->sc_bus_width = 4;
 
 	sc->sc_fifo_depth = fifo_depth;
-	sc->sc_intr_cardmask = esc->sc_conf->intr_cardmask;
+	sc->sc_entr_cardmask = esc->sc_conf->intr_cardmask;
 	sc->sc_ciu_div = esc->sc_conf->ciu_div;
 	sc->sc_flags = esc->sc_conf->flags;
 	sc->sc_pre_power_on = dwcmmc_fdt_pre_power_on;



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

2021-03-19 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Mar 19 10:23:34 UTC 2021

Modified Files:
src/sys/arch/evbarm/fdt: fdt_machdep.c

Log Message:
earlyconsgetc: return -1 instead of 0 because we will never produce input


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/sys/arch/evbarm/fdt/fdt_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/evbarm/fdt/fdt_machdep.c
diff -u src/sys/arch/evbarm/fdt/fdt_machdep.c:1.86 src/sys/arch/evbarm/fdt/fdt_machdep.c:1.87
--- src/sys/arch/evbarm/fdt/fdt_machdep.c:1.86	Fri Dec 18 07:37:21 2020
+++ src/sys/arch/evbarm/fdt/fdt_machdep.c	Fri Mar 19 10:23:34 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_machdep.c,v 1.86 2020/12/18 07:37:21 skrll Exp $ */
+/* $NetBSD: fdt_machdep.c,v 1.87 2021/03/19 10:23:34 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015-2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdt_machdep.c,v 1.86 2020/12/18 07:37:21 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_machdep.c,v 1.87 2021/03/19 10:23:34 jmcneill Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_bootconfig.h"
@@ -157,7 +157,7 @@ earlyconsputc(dev_t dev, int c)
 static int
 earlyconsgetc(dev_t dev)
 {
-	return 0;
+	return -1;
 }
 
 static struct consdev earlycons = {



CVS commit: src/sys

2021-03-02 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Mar  2 11:51:00 UTC 2021

Modified Files:
src/sys/arch/arm/fdt: arm_simplefb.c
src/sys/dev/fdt: simplefb.c

Log Message:
Fix previous: Each line is "stride" bytes wide, not "width * depth".

While here, add a comment explaining what this test is doing.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/arm/fdt/arm_simplefb.c
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/fdt/simplefb.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/arm_simplefb.c
diff -u src/sys/arch/arm/fdt/arm_simplefb.c:1.9 src/sys/arch/arm/fdt/arm_simplefb.c:1.10
--- src/sys/arch/arm/fdt/arm_simplefb.c:1.9	Tue Mar  2 07:02:05 2021
+++ src/sys/arch/arm/fdt/arm_simplefb.c	Tue Mar  2 11:51:00 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: arm_simplefb.c,v 1.9 2021/03/02 07:02:05 skrll Exp $ */
+/* $NetBSD: arm_simplefb.c,v 1.10 2021/03/02 11:51:00 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 #include "opt_vcons.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: arm_simplefb.c,v 1.9 2021/03/02 07:02:05 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arm_simplefb.c,v 1.10 2021/03/02 11:51:00 jmcneill Exp $");
 
 #include 
 #include 
@@ -237,8 +237,13 @@ arm_simplefb_preattach(void)
 		return;
 	}
 
-	if (size < width * height * depth)
+	/*
+	 * Make sure that the size of the linear FB mapping is big enough
+	 * to fit the requested screen dimensions.
+	 */
+	if (size < stride * height) {
 		return;
+	}
 
 	if (bus_space_map(bst, addr, size,
 	BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_PREFETCHABLE, &bsh) != 0)

Index: src/sys/dev/fdt/simplefb.c
diff -u src/sys/dev/fdt/simplefb.c:1.13 src/sys/dev/fdt/simplefb.c:1.14
--- src/sys/dev/fdt/simplefb.c:1.13	Tue Mar  2 07:02:06 2021
+++ src/sys/dev/fdt/simplefb.c	Tue Mar  2 11:51:00 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: simplefb.c,v 1.13 2021/03/02 07:02:06 skrll Exp $ */
+/* $NetBSD: simplefb.c,v 1.14 2021/03/02 11:51:00 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_wsdisplay_compat.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: simplefb.c,v 1.13 2021/03/02 07:02:06 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: simplefb.c,v 1.14 2021/03/02 11:51:00 jmcneill Exp $");
 
 #include 
 #include 
@@ -169,7 +169,7 @@ simplefb_attach_genfb(struct simplefb_so
 		return ENXIO;
 	}
 
-	if (size < width * height * depth) {
+	if (size < stride * height) {
 		aprint_error(": incorrect size\n");
 		return ENXIO;
 	}



CVS commit: src/sys/arch/aarch64/aarch64

2021-03-01 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Mar  1 11:37:31 UTC 2021

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

Log Message:
cpu_lwp_fork: KASSERT -> KASSERTMSG to print the actual value of DAIF if
it is not 0 in cpu_lwp_fork


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/aarch64/aarch64/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/aarch64/aarch64/vm_machdep.c
diff -u src/sys/arch/aarch64/aarch64/vm_machdep.c:1.9 src/sys/arch/aarch64/aarch64/vm_machdep.c:1.10
--- src/sys/arch/aarch64/aarch64/vm_machdep.c:1.9	Thu Oct 15 22:52:08 2020
+++ src/sys/arch/aarch64/aarch64/vm_machdep.c	Mon Mar  1 11:37:31 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: vm_machdep.c,v 1.9 2020/10/15 22:52:08 rin Exp $ */
+/* $NetBSD: vm_machdep.c,v 1.10 2021/03/01 11:37:31 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 #include "opt_ddb.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.9 2020/10/15 22:52:08 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.10 2021/03/01 11:37:31 jmcneill Exp $");
 
 #include 
 #include 
@@ -163,7 +163,7 @@ cpu_lwp_fork(struct lwp *l1, struct lwp 
 	ktf->tf_reg[27] = (uint64_t)func;
 	ktf->tf_reg[28] = (uint64_t)arg;
 	ktf->tf_reg[29] = 0;
-	KASSERT(reg_daif_read() == 0);
+	KASSERTMSG(reg_daif_read() == 0, "DAIF=0x%lx", reg_daif_read());
 	ktf->tf_lr = (uintptr_t)lwp_trampoline;
 #ifdef DDB
 	ktf->tf_pc = (uint64_t)&&backtrace_here;



CVS commit: src/sys/arch

2021-03-01 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Mar  1 11:29:14 UTC 2021

Modified Files:
src/sys/arch/aarch64/include: locore.h
src/sys/arch/arm/include: cpufunc.h
src/sys/arch/arm/pic: pic_splfuncs.c

Log Message:
Add DISABLE_INTERRUPT_SAVE(), like DISABLE_INTERRUPT() but also returns
the previous state.

Use DISABLE_INTERRUPT_SAVE()/ENABLE_INTERRUPT() in pic_splfuncs instead
of cpsid()/cpsie(). The difference here is the caller no longer specifies
which bits to disable and enable; on arm32 we continue to use I32_bit and
on aarch64 we now consistently toggle both IRQ and FIQ state.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/aarch64/include/locore.h
cvs rdiff -u -r1.87 -r1.88 src/sys/arch/arm/include/cpufunc.h
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/arm/pic/pic_splfuncs.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/aarch64/include/locore.h
diff -u src/sys/arch/aarch64/include/locore.h:1.8 src/sys/arch/aarch64/include/locore.h:1.9
--- src/sys/arch/aarch64/include/locore.h:1.8	Sat Feb 20 19:27:35 2021
+++ src/sys/arch/aarch64/include/locore.h	Mon Mar  1 11:29:14 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: locore.h,v 1.8 2021/02/20 19:27:35 jmcneill Exp $ */
+/* $NetBSD: locore.h,v 1.9 2021/03/01 11:29:14 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -58,11 +58,12 @@
 #define cpsie(psw)		daif_enable((psw))
 #define cpsid(psw)		daif_disable((psw))
 
-
-#define ENABLE_INTERRUPT()	\
+#define ENABLE_INTERRUPT()		\
 	reg_daifclr_write((DAIF_I|DAIF_F) >> DAIF_SETCLR_SHIFT)
-#define DISABLE_INTERRUPT()	\
+#define DISABLE_INTERRUPT()		\
 	reg_daifset_write((DAIF_I|DAIF_F) >> DAIF_SETCLR_SHIFT)
+#define DISABLE_INTERRUPT_SAVE()	\
+	daif_disable(DAIF_I|DAIF_F)
 
 #define DAIF_MASK		(DAIF_D|DAIF_A|DAIF_I|DAIF_F)
 

Index: src/sys/arch/arm/include/cpufunc.h
diff -u src/sys/arch/arm/include/cpufunc.h:1.87 src/sys/arch/arm/include/cpufunc.h:1.88
--- src/sys/arch/arm/include/cpufunc.h:1.87	Sun Feb  7 21:15:40 2021
+++ src/sys/arch/arm/include/cpufunc.h	Mon Mar  1 11:29:14 2021
@@ -353,8 +353,9 @@ enable_interrupts(uint32_t mask)
 #define restore_interrupts(old_cpsr)	\
 	(__set_cpsr_c((I32_bit | F32_bit), (old_cpsr) & (I32_bit | F32_bit)))
 
-#define	ENABLE_INTERRUPT()	cpsie(I32_bit)
-#define	DISABLE_INTERRUPT()	cpsid(I32_bit)
+#define	ENABLE_INTERRUPT()		cpsie(I32_bit)
+#define	DISABLE_INTERRUPT()		cpsid(I32_bit)
+#define	DISABLE_INTERRUPT_SAVE()	cpsid(I32_bit)
 
 static inline void cpsie(register_t psw) __attribute__((__unused__));
 static inline register_t cpsid(register_t psw) __attribute__((__unused__));

Index: src/sys/arch/arm/pic/pic_splfuncs.c
diff -u src/sys/arch/arm/pic/pic_splfuncs.c:1.18 src/sys/arch/arm/pic/pic_splfuncs.c:1.19
--- src/sys/arch/arm/pic/pic_splfuncs.c:1.18	Mon Feb 22 21:16:25 2021
+++ src/sys/arch/arm/pic/pic_splfuncs.c	Mon Mar  1 11:29:14 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pic_splfuncs.c,v 1.18 2021/02/22 21:16:25 jmcneill Exp $	*/
+/*	$NetBSD: pic_splfuncs.c,v 1.19 2021/03/01 11:29:14 jmcneill Exp $	*/
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -28,7 +28,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pic_splfuncs.c,v 1.18 2021/02/22 21:16:25 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pic_splfuncs.c,v 1.19 2021/03/01 11:29:14 jmcneill Exp $");
 
 #define _INTR_PRIVATE
 #include 
@@ -75,12 +75,13 @@ _spllower(int newipl)
 	const int oldipl = ci->ci_cpl;
 	KDASSERT(panicstr || newipl <= ci->ci_cpl);
 	if (newipl < ci->ci_cpl) {
-		register_t psw = cpsid(I32_bit);
+		register_t psw = DISABLE_INTERRUPT_SAVE();
 		ci->ci_intr_depth++;
 		pic_do_pending_ints(psw, newipl, NULL);
 		ci->ci_intr_depth--;
-		if ((psw & I32_bit) == 0 || newipl == IPL_NONE)
-			cpsie(I32_bit);
+		if ((psw & I32_bit) == 0 || newipl == IPL_NONE) {
+			ENABLE_INTERRUPT();
+		}
 		cpu_dosoftints();
 	}
 	return oldipl;
@@ -113,7 +114,7 @@ splx(int savedipl)
 static void __noinline
 splx_dopendingints(struct cpu_info *ci, const int savedipl)
 {
-	const register_t psw = cpsid(I32_bit);
+	const register_t psw = DISABLE_INTERRUPT_SAVE();
 	ci->ci_intr_depth++;
 	while ((ci->ci_pending_ipls & ~__BIT(savedipl)) > __BIT(savedipl)) {
 		KASSERT(ci->ci_pending_ipls < __BIT(NIPL));
@@ -131,7 +132,7 @@ splx_dopendingints(struct cpu_info *ci, 
 	}
 	ci->ci_intr_depth--;
 	if ((psw & I32_bit) == 0) {
-		cpsie(I32_bit);
+		ENABLE_INTERRUPT();
 	}
 }
 #endif



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

2021-02-27 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Feb 27 14:22:07 UTC 2021

Modified Files:
src/sys/arch/arm/pic: picvar.h

Log Message:
machine/cpufunc.h -> arm/cpufunc.h for the benefit of non-evbarm ports


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/arm/pic/picvar.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/pic/picvar.h
diff -u src/sys/arch/arm/pic/picvar.h:1.32 src/sys/arch/arm/pic/picvar.h:1.33
--- src/sys/arch/arm/pic/picvar.h:1.32	Fri Feb 26 10:06:42 2021
+++ src/sys/arch/arm/pic/picvar.h	Sat Feb 27 14:22:07 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: picvar.h,v 1.32 2021/02/26 10:06:42 jmcneill Exp $	*/
+/*	$NetBSD: picvar.h,v 1.33 2021/02/27 14:22:07 jmcneill Exp $	*/
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -107,7 +107,7 @@ void	intr_ipi_send(const kcpuset_t *, u_
 #include 
 #include 
 
-#include 
+#include 
 
 #ifndef PIC_MAXPICS
 #define PIC_MAXPICS	32



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

2021-02-26 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Feb 26 10:06:42 UTC 2021

Modified Files:
src/sys/arch/arm/pic: picvar.h

Log Message:
Unfortunately we need to disable interrupts in pic_set_priority to keep
hardware and ci_cpl in sync.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/arm/pic/picvar.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/pic/picvar.h
diff -u src/sys/arch/arm/pic/picvar.h:1.31 src/sys/arch/arm/pic/picvar.h:1.32
--- src/sys/arch/arm/pic/picvar.h:1.31	Sun Feb 21 17:07:45 2021
+++ src/sys/arch/arm/pic/picvar.h	Fri Feb 26 10:06:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: picvar.h,v 1.31 2021/02/21 17:07:45 jmcneill Exp $	*/
+/*	$NetBSD: picvar.h,v 1.32 2021/02/26 10:06:42 jmcneill Exp $	*/
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -107,6 +107,8 @@ void	intr_ipi_send(const kcpuset_t *, u_
 #include 
 #include 
 
+#include 
+
 #ifndef PIC_MAXPICS
 #define PIC_MAXPICS	32
 #endif
@@ -184,10 +186,14 @@ struct pic_ops {
  */
 #define pic_set_priority(ci, newipl)	\
 	do {\
+		register_t __psw = cpsid(I32_bit);			\
 		(ci)->ci_cpl = (newipl);\
 		if (__predict_true(pic_list[0] != NULL)) {		\
 			(pic_list[0]->pic_ops->pic_set_priority)(pic_list[0], newipl); \
 		}			\
+		if ((__psw & I32_bit) == 0) {\
+			cpsie(I32_bit);	\
+		}			\
 	} while (0)
 #else
 #define	pic_set_priority(ci, newipl)		((void)((ci)->ci_cpl = (newipl)))



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

2021-02-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Feb 23 11:31:52 UTC 2021

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

Log Message:
Install a default irq handler that panics when no interrupt controller
driver is installed.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/arm/fdt/arm_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/arm_fdt.c
diff -u src/sys/arch/arm/fdt/arm_fdt.c:1.14 src/sys/arch/arm/fdt/arm_fdt.c:1.15
--- src/sys/arch/arm/fdt/arm_fdt.c:1.14	Wed Jan 27 03:10:19 2021
+++ src/sys/arch/arm/fdt/arm_fdt.c	Tue Feb 23 11:31:52 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: arm_fdt.c,v 1.14 2021/01/27 03:10:19 thorpej Exp $ */
+/* $NetBSD: arm_fdt.c,v 1.15 2021/02/23 11:31:52 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared D. McNeill 
@@ -31,7 +31,7 @@
 #include "opt_modular.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: arm_fdt.c,v 1.14 2021/01/27 03:10:19 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arm_fdt.c,v 1.15 2021/02/23 11:31:52 jmcneill Exp $");
 
 #include 
 #include 
@@ -56,6 +56,8 @@ __KERNEL_RCSID(0, "$NetBSD: arm_fdt.c,v 
 static int	arm_fdt_match(device_t, cfdata_t, void *);
 static void	arm_fdt_attach(device_t, device_t, void *);
 
+static void	arm_fdt_irq_default_handler(void *);
+
 #ifdef EFI_RUNTIME
 static void	arm_fdt_efi_init(device_t);
 static int	arm_fdt_efi_rtc_gettime(todr_chip_handle_t, struct clock_ymdhms *);
@@ -76,7 +78,7 @@ struct arm_fdt_cpu_hatch_cb {
 static TAILQ_HEAD(, arm_fdt_cpu_hatch_cb) arm_fdt_cpu_hatch_cbs =
 TAILQ_HEAD_INITIALIZER(arm_fdt_cpu_hatch_cbs);
 
-static void (*_arm_fdt_irq_handler)(void *) = NULL;
+static void (*_arm_fdt_irq_handler)(void *) = arm_fdt_irq_default_handler;
 static void (*_arm_fdt_timer_init)(void) = NULL;
 
 int
@@ -169,10 +171,16 @@ arm_fdt_cpu_hatch(struct cpu_info *ci)
 		c->cb(c->priv, ci);
 }
 
+static void
+arm_fdt_irq_default_handler(void *frame)
+{
+	panic("missing interrupt controller driver");
+}
+
 void
 arm_fdt_irq_set_handler(void (*irq_handler)(void *))
 {
-	KASSERT(_arm_fdt_irq_handler == NULL);
+	KASSERT(_arm_fdt_irq_handler == arm_fdt_irq_default_handler);
 	_arm_fdt_irq_handler = irq_handler;
 }
 



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

2021-02-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Feb 23 10:03:05 UTC 2021

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

Log Message:
If we are committing a deferred splhigh() to hardware, no need to continue.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/arm/cortex/gic.c
cvs rdiff -u -r1.42 -r1.43 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/gic.c
diff -u src/sys/arch/arm/cortex/gic.c:1.45 src/sys/arch/arm/cortex/gic.c:1.46
--- src/sys/arch/arm/cortex/gic.c:1.45	Sun Feb 21 15:45:30 2021
+++ src/sys/arch/arm/cortex/gic.c	Tue Feb 23 10:03:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: gic.c,v 1.45 2021/02/21 15:45:30 jmcneill Exp $	*/
+/*	$NetBSD: gic.c,v 1.46 2021/02/23 10:03:04 jmcneill Exp $	*/
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -34,7 +34,7 @@
 #define _INTR_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gic.c,v 1.45 2021/02/21 15:45:30 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gic.c,v 1.46 2021/02/23 10:03:04 jmcneill Exp $");
 
 #include 
 #include 
@@ -331,6 +331,9 @@ armgic_irq_handler(void *tf)
 	if (ci->ci_hwpl != priority) {
 		ci->ci_hwpl = priority;
 		gicc_write(sc, GICC_PMR, priority);
+		if (old_ipl == IPL_HIGH) {
+			return;
+		}
 	}
 
 	for (;;) {

Index: src/sys/arch/arm/cortex/gicv3.c
diff -u src/sys/arch/arm/cortex/gicv3.c:1.42 src/sys/arch/arm/cortex/gicv3.c:1.43
--- src/sys/arch/arm/cortex/gicv3.c:1.42	Sun Feb 21 15:00:05 2021
+++ src/sys/arch/arm/cortex/gicv3.c	Tue Feb 23 10:03:04 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: gicv3.c,v 1.42 2021/02/21 15:00:05 jmcneill Exp $ */
+/* $NetBSD: gicv3.c,v 1.43 2021/02/23 10:03:04 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -31,7 +31,7 @@
 #define	_INTR_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gicv3.c,v 1.42 2021/02/21 15:00:05 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gicv3.c,v 1.43 2021/02/23 10:03:04 jmcneill Exp $");
 
 #include 
 #include 
@@ -738,6 +738,9 @@ gicv3_irq_handler(void *frame)
 	if (ci->ci_hwpl != pmr) {
 		ci->ci_hwpl = pmr;
 		icc_pmr_write(pmr);
+		if (oldipl == IPL_HIGH) {
+			return;
+		}
 	}
 
 	for (;;) {



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

2021-02-22 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Feb 22 21:16:25 UTC 2021

Modified Files:
src/sys/arch/arm/pic: pic_splfuncs.c

Log Message:
Make the splx fast path smaller.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/arm/pic/pic_splfuncs.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/pic/pic_splfuncs.c
diff -u src/sys/arch/arm/pic/pic_splfuncs.c:1.17 src/sys/arch/arm/pic/pic_splfuncs.c:1.18
--- src/sys/arch/arm/pic/pic_splfuncs.c:1.17	Sun Feb 21 17:07:45 2021
+++ src/sys/arch/arm/pic/pic_splfuncs.c	Mon Feb 22 21:16:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pic_splfuncs.c,v 1.17 2021/02/21 17:07:45 jmcneill Exp $	*/
+/*	$NetBSD: pic_splfuncs.c,v 1.18 2021/02/22 21:16:25 jmcneill Exp $	*/
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -28,7 +28,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pic_splfuncs.c,v 1.17 2021/02/21 17:07:45 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pic_splfuncs.c,v 1.18 2021/02/22 21:16:25 jmcneill Exp $");
 
 #define _INTR_PRIVATE
 #include 
@@ -46,23 +46,34 @@ __KERNEL_RCSID(0, "$NetBSD: pic_splfuncs
 
 #include 
 
+#if defined(__HAVE_CPU_DOSOFTINTS_CI)
+#define	CPU_DOSOFTINTS(ci)	cpu_dosoftints_ci((ci))
+#else
+#define	CPU_DOSOFTINTS(ci)	cpu_dosoftints()
+#endif
+
+#if defined(__HAVE_PIC_PENDING_INTRS)
+static void	splx_dopendingints(struct cpu_info *, const int);
+#endif
+
 int
 _splraise(int newipl)
 {
 	struct cpu_info * const ci = curcpu();
 	const int oldipl = ci->ci_cpl;
-	KASSERT(newipl < NIPL);
+	KDASSERT(newipl < NIPL);
 	if (newipl > ci->ci_cpl) {
 		pic_set_priority(ci, newipl);
 	}
 	return oldipl;
 }
+
 int
 _spllower(int newipl)
 {
 	struct cpu_info * const ci = curcpu();
 	const int oldipl = ci->ci_cpl;
-	KASSERT(panicstr || newipl <= ci->ci_cpl);
+	KDASSERT(panicstr || newipl <= ci->ci_cpl);
 	if (newipl < ci->ci_cpl) {
 		register_t psw = cpsid(I32_bit);
 		ci->ci_intr_depth++;
@@ -79,17 +90,29 @@ void
 splx(int savedipl)
 {
 	struct cpu_info * const ci = curcpu();
-	KASSERT(savedipl < NIPL);
+	KDASSERT(savedipl < NIPL);
 
 	if (__predict_false(savedipl == ci->ci_cpl)) {
 		return;
 	}
 
 #if defined(__HAVE_PIC_PENDING_INTRS)
-	if (__predict_true(ci->ci_pending_ipls == 0)) {
-		goto skip_pending;
+	if (__predict_false(ci->ci_pending_ipls != 0)) {
+		splx_dopendingints(ci, savedipl);
 	}
+#endif
+
+	pic_set_priority(ci, savedipl);
+	CPU_DOSOFTINTS(ci);
 
+	KDASSERTMSG(ci->ci_cpl == savedipl, "cpl %d savedipl %d",
+	ci->ci_cpl, savedipl);
+}
+
+#if defined(__HAVE_PIC_PENDING_INTRS)
+static void __noinline
+splx_dopendingints(struct cpu_info *ci, const int savedipl)
+{
 	const register_t psw = cpsid(I32_bit);
 	ci->ci_intr_depth++;
 	while ((ci->ci_pending_ipls & ~__BIT(savedipl)) > __BIT(savedipl)) {
@@ -110,16 +133,5 @@ splx(int savedipl)
 	if ((psw & I32_bit) == 0) {
 		cpsie(I32_bit);
 	}
-skip_pending:
-#endif
-
-	pic_set_priority(ci, savedipl);
-#if defined(__HAVE_CPU_DOSOFTINTS_CI)
-	cpu_dosoftints_ci(ci);
-#else
-	cpu_dosoftints();
-#endif
-
-	KASSERTMSG(ci->ci_cpl == savedipl, "cpl %d savedipl %d",
-	ci->ci_cpl, savedipl);
 }
+#endif



CVS commit: src/usr.sbin/intrctl

2021-02-22 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Feb 22 11:38:13 UTC 2021

Modified Files:
src/usr.sbin/intrctl: intrctl.8

Log Message:
Adjust description of compact list view output.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/intrctl/intrctl.8

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

Modified files:

Index: src/usr.sbin/intrctl/intrctl.8
diff -u src/usr.sbin/intrctl/intrctl.8:1.7 src/usr.sbin/intrctl/intrctl.8:1.8
--- src/usr.sbin/intrctl/intrctl.8:1.7	Tue Sep 24 11:31:06 2019
+++ src/usr.sbin/intrctl/intrctl.8	Mon Feb 22 11:38:13 2021
@@ -1,4 +1,4 @@
-.\" $NetBSD: intrctl.8,v 1.7 2019/09/24 11:31:06 wiz Exp $
+.\" $NetBSD: intrctl.8,v 1.8 2021/02/22 11:38:13 jmcneill Exp $
 .\"
 .\" Copyright (c) 2015 Internet Initiative Japan Inc.
 .\" All rights reserved.
@@ -24,7 +24,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd September 23, 2019
+.Dd February 22, 2021
 .Dt INTRCTL 8
 .Os
 .Sh NAME
@@ -63,7 +63,7 @@ The intrid is an interrupt name such as 
 If
 .Fl c
 is specified, display compact list with total counts per interrupt,
-and CPU affinity as comma separated list of CPU indexes.
+and CPU affinity as list of CPU indexes.
 .Pp
 If
 .Fl w



CVS commit: src/usr.sbin/intrctl

2021-02-22 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Feb 22 11:33:34 UTC 2021

Modified Files:
src/usr.sbin/intrctl: intrctl.c

Log Message:
In compact view, show the CPUs as a range (0-n) instead of a list
(0, 1, 2, ...) when the interrupt is assigned to all CPUs in the system.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/intrctl/intrctl.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.sbin/intrctl/intrctl.c
diff -u src/usr.sbin/intrctl/intrctl.c:1.11 src/usr.sbin/intrctl/intrctl.c:1.12
--- src/usr.sbin/intrctl/intrctl.c:1.11	Tue Sep 24 11:31:06 2019
+++ src/usr.sbin/intrctl/intrctl.c	Mon Feb 22 11:33:34 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: intrctl.c,v 1.11 2019/09/24 11:31:06 wiz Exp $	*/
+/*	$NetBSD: intrctl.c,v 1.12 2021/02/22 11:33:34 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 2015 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: intrctl.c,v 1.11 2019/09/24 11:31:06 wiz Exp $");
+__RCSID("$NetBSD: intrctl.c,v 1.12 2021/02/22 11:33:34 jmcneill Exp $");
 
 #include 
 #include 
@@ -110,6 +110,22 @@ usage(void)
 
 static int intrctl_io_alloc_retry_count = 4;
 
+static bool
+intrctl_list_line_allcpus(struct intrio_list_line *illine, int ncpus)
+{
+	struct intrio_list_line_cpu *illc;
+	int i;
+
+	for (i = 0; i < ncpus; i++) {
+		illc = &illine->ill_cpu[i];
+		if (illc->illc_assigned == false) {
+			return false;
+		}
+	}
+
+	return true;
+}
+
 static void
 intrctl_list_one(bool compact, bool skipzero)
 {
@@ -187,14 +203,20 @@ intrctl_list_one(bool compact, bool skip
 		printf("%-*s ", (int)intridlen, illine->ill_intrid);
 		if (compact) {
 			uint64_t total = 0;
+			bool allcpus = ncpus > 1 &&
+			intrctl_list_line_allcpus(illine, ncpus);
 			char *affinity = NULL, *oaffinity = NULL;
 			for (i = 0; i < ncpus; i++) {
 illc = &illine->ill_cpu[i];
 total += illc->illc_count;
+if (allcpus && i != 0 && i != ncpus - 1) {
+	continue;
+}
 if (illc->illc_assigned) {
+	const char *sep = allcpus ? "-" : ", ";
 	asprintf(&affinity, "%s%s%d",
 	oaffinity ? oaffinity : "",
-	oaffinity ? ", " : "",
+	oaffinity ? sep : "",
 	i);
 	if (oaffinity)
 		free(oaffinity);



CVS commit: src/sys/arch/aarch64/aarch64

2021-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Feb 22 02:18:33 UTC 2021

Modified Files:
src/sys/arch/aarch64/aarch64: trap.c

Log Message:
KNF


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/aarch64/aarch64/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/aarch64/aarch64/trap.c
diff -u src/sys/arch/aarch64/aarch64/trap.c:1.43 src/sys/arch/aarch64/aarch64/trap.c:1.44
--- src/sys/arch/aarch64/aarch64/trap.c:1.43	Thu Feb 18 11:23:15 2021
+++ src/sys/arch/aarch64/aarch64/trap.c	Mon Feb 22 02:18:33 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.43 2021/02/18 11:23:15 jmcneill Exp $ */
+/* $NetBSD: trap.c,v 1.44 2021/02/22 02:18:33 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.43 2021/02/18 11:23:15 jmcneill Exp $");
+__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.44 2021/02/22 02:18:33 jmcneill Exp $");
 
 #include "opt_arm_intr_impl.h"
 #include "opt_compat_netbsd32.h"
@@ -919,7 +919,8 @@ sigdebug(const struct trapframe *tf, con
 }
 #endif
 
-void do_trapsignal1(
+void
+do_trapsignal1(
 #ifdef TRAP_SIGDEBUG
 const char *func,
 size_t line,



CVS commit: src/sys/arch/aarch64/aarch64

2021-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Feb 21 23:37:10 UTC 2021

Modified Files:
src/sys/arch/aarch64/aarch64: idle_machdep.S

Log Message:
When waking from cpu_idle(), only call dosoftints if ci_intr_depth == 0


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/aarch64/aarch64/idle_machdep.S

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

Modified files:

Index: src/sys/arch/aarch64/aarch64/idle_machdep.S
diff -u src/sys/arch/aarch64/aarch64/idle_machdep.S:1.7 src/sys/arch/aarch64/aarch64/idle_machdep.S:1.8
--- src/sys/arch/aarch64/aarch64/idle_machdep.S:1.7	Thu Feb 11 08:35:12 2021
+++ src/sys/arch/aarch64/aarch64/idle_machdep.S	Sun Feb 21 23:37:09 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: idle_machdep.S,v 1.7 2021/02/11 08:35:12 ryo Exp $ */
+/* $NetBSD: idle_machdep.S,v 1.8 2021/02/21 23:37:09 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #include 
 #include "assym.h"
 
-RCSID("$NetBSD: idle_machdep.S,v 1.7 2021/02/11 08:35:12 ryo Exp $");
+RCSID("$NetBSD: idle_machdep.S,v 1.8 2021/02/21 23:37:09 jmcneill Exp $");
 
 #ifdef ARM_INTR_IMPL
 #include ARM_INTR_IMPL
@@ -93,6 +93,7 @@ ENTRY(cpu_idle)
 	str	w28, [x1, #CI_INTR_DEPTH]	/* ci->ci_intr_depth = old */
 
 #if defined(__HAVE_FAST_SOFTINTS) && !defined(__HAVE_PIC_FAST_SOFTINTS)
+	cbnz	w28, 1f/* Skip if intr_depth > 0 */
 	ldr	w3, [x1, #CI_SOFTINTS]		/* Get pending softint mask */
 	/* CPL should be 0 */
 	ldr	w2, [x1, #CI_CPL]		/* Get current priority level */



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

2021-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Feb 21 17:07:45 UTC 2021

Modified Files:
src/sys/arch/arm/pic: pic.c pic_splfuncs.c picvar.h

Log Message:
Inline pic_set_priority and use cpu_dosoftints_ci when available.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/arch/arm/pic/pic.c
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/arm/pic/pic_splfuncs.c
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/arm/pic/picvar.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/pic/pic.c
diff -u src/sys/arch/arm/pic/pic.c:1.68 src/sys/arch/arm/pic/pic.c:1.69
--- src/sys/arch/arm/pic/pic.c:1.68	Sun Feb 21 08:31:36 2021
+++ src/sys/arch/arm/pic/pic.c	Sun Feb 21 17:07:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pic.c,v 1.68 2021/02/21 08:31:36 skrll Exp $	*/
+/*	$NetBSD: pic.c,v 1.69 2021/02/21 17:07:45 jmcneill Exp $	*/
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -33,7 +33,7 @@
 #include "opt_multiprocessor.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pic.c,v 1.68 2021/02/21 08:31:36 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pic.c,v 1.69 2021/02/21 17:07:45 jmcneill Exp $");
 
 #include 
 #include 
@@ -95,34 +95,6 @@ EVCNT_ATTACH_STATIC(pic_deferral_ev);
 
 static int pic_init(void);
 
-#ifdef __HAVE_PIC_SET_PRIORITY
-void
-pic_set_priority(struct cpu_info *ci, int newipl)
-{
-	register_t psw = cpsid(I32_bit);
-	if (pic_list[0] != NULL)
-		(pic_list[0]->pic_ops->pic_set_priority)(pic_list[0], newipl);
-	ci->ci_cpl = newipl;
-	if ((psw & I32_bit) == 0)
-		cpsie(I32_bit);
-}
-
-void
-pic_set_priority_psw(struct cpu_info *ci, register_t psw, int newipl)
-{
-	if ((psw & I32_bit) == 0) {
-		DISABLE_INTERRUPT();
-	}
-	if (pic_list[0] != NULL) {
-		(pic_list[0]->pic_ops->pic_set_priority)(pic_list[0], newipl);
-	}
-	ci->ci_cpl = newipl;
-	if ((psw & I32_bit) == 0) {
-		ENABLE_INTERRUPT();
-	}
-}
-#endif
-
 #ifdef MULTIPROCESSOR
 int
 pic_ipi_ast(void *arg)
@@ -564,7 +536,7 @@ pic_do_pending_ints(register_t psw, int 
 			if (ipl <= newipl)
 break;
 
-			pic_set_priority_psw(ci, psw, ipl);
+			pic_set_priority(ci, ipl);
 			pic_list_deliver_irqs(ci, psw, ipl, frame);
 			pic_list_unblock_irqs(ci);
 		}
@@ -573,12 +545,12 @@ pic_do_pending_ints(register_t psw, int 
 #ifdef __HAVE_PREEMPTION
 	struct lwp *l = curlwp;
 	if (newipl == IPL_NONE && (l->l_md.md_astpending & __BIT(1))) {
-		pic_set_priority_psw(ci, psw, IPL_SCHED);
+		pic_set_priority(ci, IPL_SCHED);
 		kpreempt(0);
 	}
 #endif
 	if (ci->ci_cpl != newipl)
-		pic_set_priority_psw(ci, psw, newipl);
+		pic_set_priority(ci, newipl);
 }
 
 static void

Index: src/sys/arch/arm/pic/pic_splfuncs.c
diff -u src/sys/arch/arm/pic/pic_splfuncs.c:1.16 src/sys/arch/arm/pic/pic_splfuncs.c:1.17
--- src/sys/arch/arm/pic/pic_splfuncs.c:1.16	Sat Feb 20 22:53:31 2021
+++ src/sys/arch/arm/pic/pic_splfuncs.c	Sun Feb 21 17:07:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pic_splfuncs.c,v 1.16 2021/02/20 22:53:31 jmcneill Exp $	*/
+/*	$NetBSD: pic_splfuncs.c,v 1.17 2021/02/21 17:07:45 jmcneill Exp $	*/
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -28,7 +28,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pic_splfuncs.c,v 1.16 2021/02/20 22:53:31 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pic_splfuncs.c,v 1.17 2021/02/21 17:07:45 jmcneill Exp $");
 
 #define _INTR_PRIVATE
 #include 
@@ -101,7 +101,7 @@ splx(int savedipl)
 break;
 			}
 
-			pic_set_priority_psw(ci, psw, ipl);
+			pic_set_priority(ci, ipl);
 			pic_list_deliver_irqs(ci, psw, ipl, NULL);
 			pic_list_unblock_irqs(ci);
 		}
@@ -113,11 +113,12 @@ splx(int savedipl)
 skip_pending:
 #endif
 
-	ci->ci_cpl = savedipl;
-	if (__predict_true(pic_list[0] != NULL)) {
-		(pic_list[0]->pic_ops->pic_set_priority)(pic_list[0], savedipl);
-	}
+	pic_set_priority(ci, savedipl);
+#if defined(__HAVE_CPU_DOSOFTINTS_CI)
+	cpu_dosoftints_ci(ci);
+#else
 	cpu_dosoftints();
+#endif
 
 	KASSERTMSG(ci->ci_cpl == savedipl, "cpl %d savedipl %d",
 	ci->ci_cpl, savedipl);

Index: src/sys/arch/arm/pic/picvar.h
diff -u src/sys/arch/arm/pic/picvar.h:1.30 src/sys/arch/arm/pic/picvar.h:1.31
--- src/sys/arch/arm/pic/picvar.h:1.30	Sat Feb 20 19:30:46 2021
+++ src/sys/arch/arm/pic/picvar.h	Sun Feb 21 17:07:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: picvar.h,v 1.30 2021/02/20 19:30:46 jmcneill Exp $	*/
+/*	$NetBSD: picvar.h,v 1.31 2021/02/21 17:07:45 jmcneill Exp $	*/
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -176,18 +176,21 @@ struct pic_ops {
 #endif
 };
 
+/* Using an inline causes catch-22 problems with cpu.h */
 #ifdef __HAVE_PIC_SET_PRIORITY
 /*
  * This is used to update a hardware pic with a value corresponding
  * to the ipl being set.
  */
-struct cpu_info;
-void	pic_set_priority(struct cpu_info *, int);
-void	pic_set_priority_psw(struct cpu_info *, register_t, int);
+#defin

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

2021-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Feb 21 17:07:06 UTC 2021

Modified Files:
src/sys/arch/aarch64/include: cpu.h

Log Message:
Add cpu_dosoftints_ci(). Like cpu_dosoftints(), but takes a cpu_info ptr
so we can avoid the extra tpidr_el1 access if cpu_info is already known.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/aarch64/include/cpu.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/aarch64/include/cpu.h
diff -u src/sys/arch/aarch64/include/cpu.h:1.32 src/sys/arch/aarch64/include/cpu.h:1.33
--- src/sys/arch/aarch64/include/cpu.h:1.32	Sun Feb 21 15:00:04 2021
+++ src/sys/arch/aarch64/include/cpu.h	Sun Feb 21 17:07:06 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.32 2021/02/21 15:00:04 jmcneill Exp $ */
+/* $NetBSD: cpu.h,v 1.33 2021/02/21 17:07:06 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014, 2020 The NetBSD Foundation, Inc.
@@ -178,18 +178,29 @@ extern struct cpu_info cpu_info_store[];
 
 #define	LWP0_CPU_INFO	(&cpu_info_store[0])
 
+#define	__HAVE_CPU_DOSOFTINTS_CI
+
 static inline void
-cpu_dosoftints(void)
+cpu_dosoftints_ci(struct cpu_info *ci)
 {
 #if defined(__HAVE_FAST_SOFTINTS) && !defined(__HAVE_PIC_FAST_SOFTINTS)
 	void dosoftints(void);
-	struct cpu_info * const ci = curcpu();
 
-	if (ci->ci_intr_depth == 0 && (ci->ci_softints >> ci->ci_cpl) > 0)
+	if (ci->ci_intr_depth == 0 && (ci->ci_softints >> ci->ci_cpl) > 0) {
 		dosoftints();
+	}
+#endif
+}
+
+static inline void
+cpu_dosoftints(void)
+{
+#if defined(__HAVE_FAST_SOFTINTS) && !defined(__HAVE_PIC_FAST_SOFTINTS)
+	cpu_dosoftints_ci(curcpu());
 #endif
 }
 
+
 #endif /* _KERNEL */
 
 #endif /* _KERNEL || _KMEMUSER */



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

2021-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Feb 21 16:07:43 UTC 2021

Modified Files:
src/sys/arch/arm/sunxi: sunxi_emac.h

Log Message:
Align descriptors to 64 bytes instead of CACHE_LINE_SIZE (128) as all known
Allwinner SoCs with this part use 64-byte cache lines.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/sunxi/sunxi_emac.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/sunxi/sunxi_emac.h
diff -u src/sys/arch/arm/sunxi/sunxi_emac.h:1.4 src/sys/arch/arm/sunxi/sunxi_emac.h:1.5
--- src/sys/arch/arm/sunxi/sunxi_emac.h:1.4	Sun Oct  1 15:05:09 2017
+++ src/sys/arch/arm/sunxi/sunxi_emac.h	Sun Feb 21 16:07:43 2021
@@ -203,8 +203,8 @@ struct sunxi_emac_desc {
 	uint32_t	addr;
 
 	uint32_t	next;
-} __packed __aligned(CACHE_LINE_SIZE);
+} __packed __aligned(64);
 
-__CTASSERT(sizeof(struct sunxi_emac_desc) == CACHE_LINE_SIZE);
+__CTASSERT(sizeof(struct sunxi_emac_desc) == 64);
 
 #endif /* !__SUNXI_EMAC_H__ */



  1   2   3   4   5   6   7   8   9   10   >