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

2021-08-13 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Fri Aug 13 20:19:45 UTC 2021

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

Log Message:
fix multiple typos in comments.


To generate a diff of this commit:
cvs rdiff -u -r1.300 -r1.301 src/sys/arch/alpha/alpha/pmap.c

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

Modified files:

Index: src/sys/arch/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.300 src/sys/arch/alpha/alpha/pmap.c:1.301
--- src/sys/arch/alpha/alpha/pmap.c:1.300	Sat Jul 31 14:51:25 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Fri Aug 13 20:19:45 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.300 2021/07/31 14:51:25 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.301 2021/08/13 20:19:45 andvar Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -106,8 +106,8 @@
  *
  *	All user page table access is done via K0SEG.  Kernel
  *	page table access is done via the recursive Virtual Page
- *	Table becase kernel PT pages are pre-allocated and never
- *	freed, so no VPT fault handling is requiried.
+ *	Table because kernel PT pages are pre-allocated and never
+ *	freed, so no VPT fault handling is required.
  */
 
 /*
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.300 2021/07/31 14:51:25 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.301 2021/08/13 20:19:45 andvar Exp $");
 
 #include 
 #include 
@@ -578,9 +578,9 @@ pmap_pvlist_free(struct pmap_pvlist * co
  * that includes room for 8 VAs, the pmap the VAs belong to, a bitmap of
  * CPUs to be notified, and a list for PT pages that are freed during
  * removal off mappings.  The number of valid addresses in the list as
- * well as flags are sqeezed into the lower bits of the first two VAs.
+ * well as flags are squeezed into the lower bits of the first two VAs.
  * Storage for this structure is allocated on the stack.  We need to be
- * careful to keep the size of this struture under control.
+ * careful to keep the size of this structure under control.
  *
  * When notifying remote CPUs, we acquire the tlb_lock (which also
  * blocks IPIs), record the pointer to our context structure, set a
@@ -589,9 +589,9 @@ pmap_pvlist_free(struct pmap_pvlist * co
  * any invalidations necessary on the local CPU.  Once that is done,
  * we then wait the the global context pointer to be cleared, which
  * will be done by the final remote CPU to complete their work. This
- * method reduces cache line contention during pocessing.
+ * method reduces cache line contention during processing.
  *
- * When removing mappings in user pmaps, this implemention frees page
+ * When removing mappings in user pmaps, this implementation frees page
  * table pages back to the VM system once they contain no valid mappings.
  * As we do this, we must ensure to invalidate TLB entries that the
  * CPU might hold for the respective recursive VPT mappings.  This must
@@ -1038,7 +1038,7 @@ pmap_tlb_shootnow(const struct pmap_tlb_
 
 	/*
 	 * Figure out who to notify.  If it's for the kernel or
-	 * multiple aaddress spaces, we notify everybody.  If
+	 * multiple address spaces, we notify everybody.  If
 	 * it's a single user pmap, then we try to acquire the
 	 * activation lock so we can get an accurate accounting
 	 * of who needs to be notified.  If we can't acquire
@@ -2094,7 +2094,7 @@ pmap_enter_tlb_shootdown(pmap_t const pm
  * pmap_enter_l2pt_delref:
  *
  *	Release a reference on an L2 PT page for pmap_enter().
- *	This is factored out separately becacause we expect it
+ *	This is factored out separately because we expect it
  *	to be a rare case.
  */
 static void __noinline
@@ -2105,7 +2105,7 @@ pmap_enter_l2pt_delref(pmap_t const pmap
 
 	/*
 	 * PALcode may have tried to service a TLB miss with
-	 * this L2 PTE, so we need to make sure we don't actully
+	 * this L2 PTE, so we need to make sure we don't actually
 	 * free the PT page untl we've shot down any TLB entries
 	 * for this VPT index.
 	 */
@@ -2122,7 +2122,7 @@ pmap_enter_l2pt_delref(pmap_t const pmap
  * pmap_enter_l3pt_delref:
  *
  *	Release a reference on an L3 PT page for pmap_enter().
- *	This is factored out separately becacause we expect it
+ *	This is factored out separately because we expect it
  *	to be a rare case.
  */
 static void __noinline
@@ -2133,8 +2133,8 @@ pmap_enter_l3pt_delref(pmap_t const pmap
 
 	/*
 	 * PALcode may have tried to service a TLB miss with
-	 * this PTE, so we need to make sure we don't actully
-	 * free the PT page untl we've shot down any TLB entries
+	 * this PTE, so we need to make sure we don't actually
+	 * free the PT page until we've shot down any TLB entries
 	 * for this VPT index.
 	 */
 
@@ -2256,7 +2256,7 @@ pmap_enter(pmap_t pmap, vaddr_t va, padd
 	 * new one immediately.
 	 */
 	if ((opte & PG_V) == 0) {
-		/* No TLB invalidatons needed for new mappings. */
+		/* No TLB 

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

2021-07-31 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Jul 31 14:51:25 UTC 2021

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

Log Message:
Fix a silly mistake (missing return) in the DEBUG case of the kernel pmap
case of pmap_extract().


To generate a diff of this commit:
cvs rdiff -u -r1.299 -r1.300 src/sys/arch/alpha/alpha/pmap.c

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

Modified files:

Index: src/sys/arch/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.299 src/sys/arch/alpha/alpha/pmap.c:1.300
--- src/sys/arch/alpha/alpha/pmap.c:1.299	Mon Jul 19 16:31:19 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Sat Jul 31 14:51:25 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.299 2021/07/19 16:31:19 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.300 2021/07/31 14:51:25 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.299 2021/07/19 16:31:19 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.300 2021/07/31 14:51:25 thorpej Exp $");
 
 #include 
 #include 
@@ -2587,6 +2587,7 @@ pmap_extract(pmap_t pmap, vaddr_t va, pa
 printf("failed (kernel vtophys)\n");
 			}
 		}
+		return address_is_valid;
 #else
 		return vtophys_internal(va, pap);
 #endif



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

2021-07-23 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jul 23 14:38:58 UTC 2021

Modified Files:
src/sys/arch/alpha/conf: GENERIC INSTALL

Log Message:
Use wildcard matches more consistently, and attach pci, eisa, isa, and
usb to their interface attributes, which makes for easier trimming-down
with "no" directives.


To generate a diff of this commit:
cvs rdiff -u -r1.412 -r1.413 src/sys/arch/alpha/conf/GENERIC
cvs rdiff -u -r1.117 -r1.118 src/sys/arch/alpha/conf/INSTALL

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

Modified files:

Index: src/sys/arch/alpha/conf/GENERIC
diff -u src/sys/arch/alpha/conf/GENERIC:1.412 src/sys/arch/alpha/conf/GENERIC:1.413
--- src/sys/arch/alpha/conf/GENERIC:1.412	Tue Jun 29 10:22:34 2021
+++ src/sys/arch/alpha/conf/GENERIC	Fri Jul 23 14:38:58 2021
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.412 2021/06/29 10:22:34 nia Exp $
+# $NetBSD: GENERIC,v 1.413 2021/07/23 14:38:58 thorpej Exp $
 #
 # This machine description file is used to generate the default NetBSD
 # kernel.
@@ -19,7 +19,7 @@ include 	"arch/alpha/conf/std.alpha"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-ident		"GENERIC-$Revision: 1.412 $"
+ident		"GENERIC-$Revision: 1.413 $"
 
 maxusers 32
 
@@ -184,11 +184,11 @@ config		netbsd	root on ? type ?
 #config		netbsd	root on ? type nfs
 
 mainbus0 at	root
-cpu*	at	mainbus0
-qemu*	at	mainbus0
+cpu*	at	mainbus?
+qemu*	at	mainbus?
 
 # TurboLaser bus support and devices
-tlsb*	at	mainbus0
+tlsb*	at	mainbus?
 gbus*	at	tlsb? node ? offset ?
 tlsbmem* at	tlsb? node ? offset ?
 kft*	at	tlsb? node ? offset ?
@@ -197,19 +197,19 @@ kft*	at	tlsb? node ? offset ?
 mcclock* at	gbus? offset ?
 
 # MCBUS bus support
-mcbus*	at	mainbus0
+mcbus*	at	mainbus?
 mcmem*	at	mcbus? mid ?
 
 #i2c	at	mcbus?
 
 #EV6 Tsunami Core Logic
 
-tsc*	at	mainbus0
+tsc*	at	mainbus?
 tsciic* 	at	tsc?
 iic* 	at	tsciic?
 
 # DECpc AXP150 (Jensen) internal bus support
-jensenio* at	mainbus0
+jensenio* at	mainbus?
 
 com*	at	jensenio? port ?
 lpt*	at	jensenio? port ?
@@ -217,7 +217,7 @@ mcclock* at	jensenio? port ?
 pckbc*	at	jensenio? port ?
 
 # TURBOchannel host bus adapter support
-tcasic*	at	mainbus0
+tcasic*	at	mainbus?
 
 # TURBOchannel bus support
 tc*	at	tcasic?
@@ -269,18 +269,10 @@ pckbc*	at	sableio? port ?
 fdc*	at	sableio? port ?
 
 # PCI bus support
-pci*	at	apecs?
-pci*	at	cia?
-pci*	at	irongate?
-pci*	at	lca?
-pci*	at	ppb?
-pci*	at	dwlpx?
-pci*	at	mcpcia?
-pci*	at	tsp?
-pci*	at	ttwopci?
+pci*	at	pcibus?			# "pcibus" interface attribute
 
 # AGP support
-agp*	at	irongate?
+agp*	at	agpbus?			# "agpbus" interface attribute
 
 # PCI devices
 
@@ -404,11 +396,8 @@ tqphy*	at mii? phy ?			# TDK Semiconduct
 ukphy*	at mii? phy ?			# generic unknown PHYs
 
 # ISA/EISA bus support
-isa*	at	jensenio?
-eisa*	at	jensenio?
-isa*	at	pceb?
-eisa*	at	pceb?
-isa*	at	sio?
+isa*	at	isabus?			# "isabus" interface attribute
+eisa*	at	eisabus?		# "eisabus" interface attribute
 #isapnp*	at	isa?
 
 # ISA devices
@@ -550,11 +539,7 @@ iic* 	at alipm?
 slhci*	at pcmcia? function ?			# ScanLogic SL811HS
 
 # USB bus support
-usb*	at xhci?
-usb*	at ehci?
-usb*	at ohci?
-usb*	at slhci?
-usb*	at uhci?
+usb*	at usbus?			# "usbus" interface attribute
 
 # USB Hubs
 uhub*	at usb?

Index: src/sys/arch/alpha/conf/INSTALL
diff -u src/sys/arch/alpha/conf/INSTALL:1.117 src/sys/arch/alpha/conf/INSTALL:1.118
--- src/sys/arch/alpha/conf/INSTALL:1.117	Mon Sep 28 03:48:12 2020
+++ src/sys/arch/alpha/conf/INSTALL	Fri Jul 23 14:38:58 2021
@@ -1,4 +1,4 @@
-# $NetBSD: INSTALL,v 1.117 2020/09/28 03:48:12 thorpej Exp $
+# $NetBSD: INSTALL,v 1.118 2021/07/23 14:38:58 thorpej Exp $
 #
 # Alpha INSTALL kernel.
 
@@ -86,11 +86,11 @@ options 	WSEMUL_VT100
 config		netbsd	root on ? type ?
 
 mainbus0 at	root
-cpu*	at	mainbus0
-qemu*	at	mainbus0
+cpu*	at	mainbus?
+qemu*	at	mainbus?
 
 # TurboLaser bus support and devices
-tlsb*	at	mainbus0
+tlsb*	at	mainbus?
 gbus*	at	tlsb? node ? offset ?
 tlsbmem* at	tlsb? node ? offset ?
 kft*	at	tlsb? node ? offset ?
@@ -99,15 +99,15 @@ kft*	at	tlsb? node ? offset ?
 mcclock* at	gbus? offset ?
 
 # MCBUS bus support
-mcbus*	at	mainbus0
+mcbus*	at	mainbus?
 mcmem*	at	mcbus? mid ?
 
 #EV6 Tsunami Core Logic
 
-tsc*	at	mainbus0
+tsc*	at	mainbus?
 
 # DECpc AXP150 (Jensen) internal bus support
-jensenio* at	mainbus0
+jensenio* at	mainbus?
 
 com*	at	jensenio? port ?
 lpt*	at	jensenio? port ?
@@ -115,7 +115,7 @@ mcclock* at	jensenio? port ?
 pckbc*	at	jensenio? port ?
 
 # TURBOchannel host bus adapter support
-tcasic*	at	mainbus0
+tcasic*	at	mainbus?
 
 # TURBOchannel bus support
 tc*	at	tcasic?
@@ -164,18 +164,10 @@ pckbc*	at	sableio? port ?
 fdc*	at	sableio? port ?
 
 # PCI bus support
-pci*	at	apecs?
-pci*	at	cia?
-pci*	at	irongate?
-pci*	at	lca?
-pci*	at	ppb?
-pci*	at	dwlpx?
-pci*	at	mcpcia?
-pci*	at	tsp?
-pci*	at	ttwopci?
+pci*	at	pcibus?			# "pcibus" interface attribute
 
 # AGP support
-agp*	at	

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

2021-07-22 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jul 23 04:19:50 UTC 2021

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

Log Message:
Emulate the IEEE flavors of the FIX extension instructions:
- FTOIS, FTOIT
- ITOFS, ITOFT
- SRQTS, SQRTT

Left out for now are the VAX FP flavors:
- ITOFF
- SQRTF, SQRTG


To generate a diff of this commit:
cvs rdiff -u -r1.137 -r1.138 src/sys/arch/alpha/alpha/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/alpha/alpha/trap.c
diff -u src/sys/arch/alpha/alpha/trap.c:1.137 src/sys/arch/alpha/alpha/trap.c:1.138
--- src/sys/arch/alpha/alpha/trap.c:1.137	Tue Jul 20 01:56:06 2021
+++ src/sys/arch/alpha/alpha/trap.c	Fri Jul 23 04:19:50 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.137 2021/07/20 01:56:06 thorpej Exp $ */
+/* $NetBSD: trap.c,v 1.138 2021/07/23 04:19:50 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2000, 2001, 2021 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.137 2021/07/20 01:56:06 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.138 2021/07/23 04:19:50 thorpej Exp $");
 
 #include 
 #include 
@@ -383,6 +383,8 @@ trap(const u_long a0, const u_long a1, c
 ksi.ksi_code = SEGV_MAPERR;
 			else if (i == SIGILL)
 ksi.ksi_code = ILL_ILLOPC;
+			else if (i == SIGFPE)
+ksi.ksi_code = alpha_ucode_to_ksiginfo(ucode);
 			ksi.ksi_signo = i;
 			ksi.ksi_addr =
 (void *)l->l_md.md_tf->tf_regs[FRAME_PC];
@@ -961,6 +963,128 @@ unaligned_fixup(u_long va, u_long opcode
 	return (signo);
 }
 
+#define	EMUL_COUNT(ev)	atomic_inc_64(&(ev).ev_count)
+
+static struct evcnt emul_fix_ftoit =
+EVCNT_INITIALIZER(EVCNT_TYPE_TRAP, NULL, "emul fix", "ftoit");
+static struct evcnt emul_fix_ftois =
+EVCNT_INITIALIZER(EVCNT_TYPE_TRAP, NULL, "emul fix", "ftois");
+static struct evcnt emul_fix_itofs =
+EVCNT_INITIALIZER(EVCNT_TYPE_TRAP, NULL, "emul fix", "itofs");
+#if 0
+static struct evcnt emul_fix_itoff =
+EVCNT_INITIALIZER(EVCNT_TYPE_TRAP, NULL, "emul fix", "itoff");
+#endif
+static struct evcnt emul_fix_itoft =
+EVCNT_INITIALIZER(EVCNT_TYPE_TRAP, NULL, "emul fix", "itoft");
+static struct evcnt emul_fix_sqrtt =
+EVCNT_INITIALIZER(EVCNT_TYPE_TRAP, NULL, "emul fix", "sqrtt");
+static struct evcnt emul_fix_sqrts =
+EVCNT_INITIALIZER(EVCNT_TYPE_TRAP, NULL, "emul fix", "sqrts");
+
+EVCNT_ATTACH_STATIC(emul_fix_ftoit);
+EVCNT_ATTACH_STATIC(emul_fix_ftois);
+EVCNT_ATTACH_STATIC(emul_fix_itofs);
+#if 0
+EVCNT_ATTACH_STATIC(emul_fix_itoff);
+#endif
+EVCNT_ATTACH_STATIC(emul_fix_itoft);
+EVCNT_ATTACH_STATIC(emul_fix_sqrtt);
+EVCNT_ATTACH_STATIC(emul_fix_sqrts);
+
+static void
+emul_fix(struct lwp *l, const alpha_instruction *inst)
+{
+	union {
+		f_float f;
+		s_float s;
+		t_float t;
+	} fmem;
+	register_t *regptr;
+
+	KASSERT(l == curlwp);
+
+	/*
+	 * FIX instructions don't cause any exceptions, including
+	 * MM exceptions.  However, they are equivalent in result
+	 * to e.g. STL,LDF.  We will just assume that we can access
+	 * our kernel stack, and thus no exception checks are
+	 * required.
+	 */
+
+	kpreempt_disable();
+	if ((l->l_md.md_flags & MDLWP_FPACTIVE) == 0) {
+		fpu_load();
+	}
+	alpha_pal_wrfen(1);
+
+	if (inst->float_format.opcode == op_intmisc) {
+		regptr = irp(l, inst->float_format.fc);
+		switch (inst->float_format.function) {
+		case op_ftoit:
+			EMUL_COUNT(emul_fix_ftoit);
+			alpha_stt(inst->float_format.fa, );
+			if (regptr != NULL) {
+*regptr = fmem.t.i;
+			}
+			break;
+
+		case op_ftois:
+			EMUL_COUNT(emul_fix_ftois);
+			alpha_sts(inst->float_format.fa, );
+			if (regptr != NULL) {
+*regptr = (int32_t)fmem.s.i;
+			}
+			break;
+
+		default:
+			panic("%s: bad intmisc function=0x%x\n", __func__,
+			inst->float_format.function);
+		}
+	} else if (inst->float_format.opcode == op_fix_float) {
+		regptr = irp(l, inst->float_format.fa);
+		register_t regval = (regptr != NULL) ? *regptr : 0;
+
+		switch (inst->float_format.function) {
+		case op_itofs:
+			EMUL_COUNT(emul_fix_itofs);
+			fmem.s.i = (uint32_t)regval;
+			alpha_lds(inst->float_format.fc, );
+			break;
+
+		/*
+		 * The Book says about ITOFF:
+		 *
+		 *	ITOFF is equivalent to the following sequence,
+		 *	except that the word swapping that LDF normally
+		 *	performs is not performed by ITOFF.
+		 *
+		 *		STL
+		 *		LDF
+		 *
+		 * ...implying that we can't actually use LDF here ??? So
+		 * we'll skip it for now.
+		 */
+
+		case op_itoft:
+			EMUL_COUNT(emul_fix_itoft);
+			fmem.t.i = regval;
+			alpha_ldt(inst->float_format.fc, );
+			break;
+
+		default:
+			panic("%s: bad fix_float function=0x%x\n", __func__,
+			inst->float_format.function);
+		}
+	} else {
+		panic("%s: bad opcode=0x%02x", __func__,
+		inst->float_format.opcode);
+	}
+
+	alpha_pal_wrfen(0);
+	kpreempt_enable();
+}
+
 static struct evcnt 

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

2021-07-22 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jul 23 03:57:06 UTC 2021

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

Log Message:
IEEE SQRTS / SQRTT is fix_float opclass 11, not fix_float opclass 10
(which is VAX SQRTF / SQRTG).


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/alpha/alpha/fp_complete.c

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

Modified files:

Index: src/sys/arch/alpha/alpha/fp_complete.c
diff -u src/sys/arch/alpha/alpha/fp_complete.c:1.26 src/sys/arch/alpha/alpha/fp_complete.c:1.27
--- src/sys/arch/alpha/alpha/fp_complete.c:1.26	Fri Jul 23 03:50:32 2021
+++ src/sys/arch/alpha/alpha/fp_complete.c	Fri Jul 23 03:57:06 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: fp_complete.c,v 1.26 2021/07/23 03:50:32 thorpej Exp $ */
+/* $NetBSD: fp_complete.c,v 1.27 2021/07/23 03:57:06 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2001 Ross Harvey
@@ -37,7 +37,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: fp_complete.c,v 1.26 2021/07/23 03:50:32 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fp_complete.c,v 1.27 2021/07/23 03:57:06 thorpej Exp $");
 
 #include 
 #include 
@@ -588,7 +588,7 @@ alpha_fp_interpret(unsigned long pc, str
 		switch(inst.float_detail.src) {
 		case op_src_sf:
 			sts(inst.float_detail.fb, , l);
-			if (inst.float_detail.opclass == 10)
+			if (inst.float_detail.opclass == 11)
 sfc.i = float32_sqrt(sfb.i);
 			else if (inst.float_detail.opclass & ~3) {
 this_cannot_happen(1, inst.bits);
@@ -607,7 +607,7 @@ alpha_fp_interpret(unsigned long pc, str
 inst.bits, l);
 			else {
 stt(inst.float_detail.fb, , l);
-if (inst.float_detail.opclass == 10)
+if (inst.float_detail.opclass == 11)
 	tfc.i = float64_sqrt(tfb.i);
 else {
 	stt(inst.float_detail.fa, , l);



CVS commit: src/sys/arch/alpha

2021-07-22 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jul 23 03:50:32 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: fp_complete.c
src/sys/arch/alpha/include: alpha.h

Log Message:
- Expose alpha_fp_complete_at() to callers outside fp_complete.c.
- Use ufetch_32() instead of copyin() to fetch the instruction.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/alpha/alpha/fp_complete.c
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/alpha/include/alpha.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/alpha/alpha/fp_complete.c
diff -u src/sys/arch/alpha/alpha/fp_complete.c:1.25 src/sys/arch/alpha/alpha/fp_complete.c:1.26
--- src/sys/arch/alpha/alpha/fp_complete.c:1.25	Thu Jul 22 01:39:18 2021
+++ src/sys/arch/alpha/alpha/fp_complete.c	Fri Jul 23 03:50:32 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: fp_complete.c,v 1.25 2021/07/22 01:39:18 thorpej Exp $ */
+/* $NetBSD: fp_complete.c,v 1.26 2021/07/23 03:50:32 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2001 Ross Harvey
@@ -37,7 +37,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: fp_complete.c,v 1.25 2021/07/22 01:39:18 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fp_complete.c,v 1.26 2021/07/23 03:50:32 thorpej Exp $");
 
 #include 
 #include 
@@ -522,13 +522,13 @@ float64_unk(float64 a, float64 b)
  */
 
 static void
-print_fp_instruction(alpha_instruction *pc, struct lwp *l, uint32_t bits)
+print_fp_instruction(unsigned long pc, struct lwp *l, uint32_t bits)
 {
 #if defined(DDB)
 	char buf[32];
 	struct alpha_print_instruction_context ctx = {
 		.insn.bits = bits,
-		.pc = (unsigned long)pc,
+		.pc = pc,
 		.buf = buf,
 		.bufsize = sizeof(buf),
 	};
@@ -553,7 +553,7 @@ print_fp_instruction(alpha_instruction *
 }
 
 static void
-alpha_fp_interpret(alpha_instruction *pc, struct lwp *l, uint32_t bits)
+alpha_fp_interpret(unsigned long pc, struct lwp *l, uint32_t bits)
 {
 	s_float sfa, sfb, sfc;
 	t_float tfa, tfb, tfc;
@@ -624,16 +624,15 @@ alpha_fp_interpret(alpha_instruction *pc
 	}
 }
 
-static int
-alpha_fp_complete_at(alpha_instruction *trigger_pc, struct lwp *l,
-uint64_t *ucode)
+int
+alpha_fp_complete_at(unsigned long trigger_pc, struct lwp *l, uint64_t *ucode)
 {
 	int needsig;
 	alpha_instruction inst;
 	uint64_t rm, fpcr, orig_fpcr;
 	uint64_t orig_flags, new_flags, changed_flags, md_flags;
 
-	if (__predict_false(copyin(trigger_pc, , sizeof inst))) {
+	if (__predict_false(ufetch_32((void *)trigger_pc, ))) {
 		this_cannot_happen(6, -1);
 		return SIGSEGV;
 	}
@@ -712,7 +711,8 @@ alpha_fp_complete(u_long a0, u_long a1, 
 	if (cpu_amask & ALPHA_AMASK_PAT) {
 		if ((a0 & (ALPHA_AESR_SWC | ALPHA_AESR_INV)) != 0 ||
 		alpha_fp_sync_complete) {
-			sig = alpha_fp_complete_at(trigger_pc, l, ucode);
+			sig = alpha_fp_complete_at((u_long)trigger_pc, l,
+			ucode);
 			goto resolved;
 		}
 	}
@@ -773,7 +773,7 @@ alpha_fp_complete(u_long a0, u_long a1, 
 		alpha_shadow.max = t;
 	if (__predict_true(trigger_pc != 0 && a1 == 0)) {
 		++alpha_shadow.resolved;
-		sig = alpha_fp_complete_at(trigger_pc, l, ucode);
+		sig = alpha_fp_complete_at((u_long)trigger_pc, l, ucode);
 		goto resolved;
 	} else {
 		++alpha_shadow.unresolved;

Index: src/sys/arch/alpha/include/alpha.h
diff -u src/sys/arch/alpha/include/alpha.h:1.46 src/sys/arch/alpha/include/alpha.h:1.47
--- src/sys/arch/alpha/include/alpha.h:1.46	Tue Jul 20 05:43:10 2021
+++ src/sys/arch/alpha/include/alpha.h	Fri Jul 23 03:50:32 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: alpha.h,v 1.46 2021/07/20 05:43:10 thorpej Exp $ */
+/* $NetBSD: alpha.h,v 1.47 2021/07/23 03:50:32 thorpej Exp $ */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -178,6 +178,7 @@ uint64_t alpha_read_fp_c(struct lwp *);
 void alpha_write_fp_c(struct lwp *, uint64_t);
 
 int alpha_fp_complete(u_long, u_long, struct lwp *, uint64_t *);
+int alpha_fp_complete_at(u_long, struct lwp *, uint64_t *);
 
 /* Security sensitive rate limiting printf */
 



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

2021-07-22 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Thu Jul 22 15:48:40 UTC 2021

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

Log Message:
It's unlikely that a process will be using restartable atomic sequences
on Alpha, and furthermore it's unlikely that any given context switch
will be returning to one even if the process has them.  So, re-arrange
the RAS processing in cpu_switchto() so that the most likely code paths
are predicted by the branch predictor.  On an EV4-class processor, this
will save ~4-6 cycles on just about every context switch.


To generate a diff of this commit:
cvs rdiff -u -r1.140 -r1.141 src/sys/arch/alpha/alpha/locore.s

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

Modified files:

Index: src/sys/arch/alpha/alpha/locore.s
diff -u src/sys/arch/alpha/alpha/locore.s:1.140 src/sys/arch/alpha/alpha/locore.s:1.141
--- src/sys/arch/alpha/alpha/locore.s:1.140	Sun Jul 11 01:55:51 2021
+++ src/sys/arch/alpha/alpha/locore.s	Thu Jul 22 15:48:40 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: locore.s,v 1.140 2021/07/11 01:55:51 thorpej Exp $ */
+/* $NetBSD: locore.s,v 1.141 2021/07/22 15:48:40 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000, 2019 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: locore.s,v 1.140 2021/07/11 01:55:51 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.s,v 1.141 2021/07/22 15:48:40 thorpej Exp $");
 
 #include "assym.h"
 
@@ -844,14 +844,7 @@ LEAF(cpu_switchto, 0)
 	 */
 	ldq	a0, L_PROC(s2)			/* first ras_lookup() arg */
 	ldq	t0, P_RASLIST(a0)		/* any RAS entries? */
-	beq	t0, 2f/* no, skip */
-	ldq	s1, L_MD_TF(s2)			/* s1 = l->l_md.md_tf */
-	ldq	a1, (FRAME_PC*8)(s1)		/* second ras_lookup() arg */
-	CALL(ras_lookup)			/* ras_lookup(p, PC) */
-	addq	v0, 1, t0			/* -1 means "not in ras" */
-	beq	t0, 2f
-	stq	v0, (FRAME_PC*8)(s1)
-
+	bne	t0, 4f/* yes, go deal with it */
 2:
 	mov	s4, v0/* return the old lwp */
 	/*
@@ -883,6 +876,16 @@ LEAF(cpu_switchto, 0)
 	stq	sp, PCB_HWPCB_KSP(a3)		/* save old SP */
 	ldq	sp, PCB_HWPCB_KSP(a2)		/* restore new SP */
 	br	1b/* finish up */
+
+4:
+	ldq	s1, L_MD_TF(s2)			/* s1 = l->l_md.md_tf */
+	ldq	a1, (FRAME_PC*8)(s1)		/* second ras_lookup() arg */
+	CALL(ras_lookup)			/* ras_lookup(p, PC) */
+	addq	v0, 1, t0			/* -1 means "not in ras" */
+	beq	t0, 2b/* not in ras? return */
+	stq	v0, (FRAME_PC*8)(s1)		/* in ras? fix up PC */
+	br	2b/* finish up */
+
 	END(cpu_switchto)
 
 /*



CVS commit: src/sys/arch/alpha

2021-07-21 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Thu Jul 22 01:39:18 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: fp_complete.c machdep.c
src/sys/arch/alpha/include: cpu.h fpu.h

Log Message:
Various minor cleanups and bug fixes to the FP software completion code:
- Use __CTASSERT() instead of rolling our own compile-time assertion
  using cpp.
- Use __BIT()  instead of rolling our own.
- Improve some comments.
- Define a default FP_C and FPCR value that is self-consistent, and
  initialize it properly at process creation time.
- Fix signal information when the trap shadow cannot be resolved.
- Use defined constants rather than magic numbers for the exception
  summary bits.
- Add a machdep sysctl to enable FP software-completion debugging.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/alpha/alpha/fp_complete.c
cvs rdiff -u -r1.374 -r1.375 src/sys/arch/alpha/alpha/machdep.c
cvs rdiff -u -r1.102 -r1.103 src/sys/arch/alpha/include/cpu.h
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/alpha/include/fpu.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/alpha/alpha/fp_complete.c
diff -u src/sys/arch/alpha/alpha/fp_complete.c:1.24 src/sys/arch/alpha/alpha/fp_complete.c:1.25
--- src/sys/arch/alpha/alpha/fp_complete.c:1.24	Tue Sep  1 08:22:36 2020
+++ src/sys/arch/alpha/alpha/fp_complete.c	Thu Jul 22 01:39:18 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: fp_complete.c,v 1.24 2020/09/01 08:22:36 thorpej Exp $ */
+/* $NetBSD: fp_complete.c,v 1.25 2021/07/22 01:39:18 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2001 Ross Harvey
@@ -33,9 +33,11 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "opt_ddb.h"
+
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: fp_complete.c,v 1.24 2020/09/01 08:22:36 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fp_complete.c,v 1.25 2021/07/22 01:39:18 thorpej Exp $");
 
 #include 
 #include 
@@ -51,6 +53,30 @@ __KERNEL_RCSID(0, "$NetBSD: fp_complete.
 
 #include 
 
+/*
+ * Validate our assumptions about bit positions.
+ */
+__CTASSERT(ALPHA_AESR_INV == (FP_X_INV << 1));
+__CTASSERT(ALPHA_AESR_DZE == (FP_X_DZ  << 1));
+__CTASSERT(ALPHA_AESR_OVF == (FP_X_OFL << 1));
+__CTASSERT(ALPHA_AESR_UNF == (FP_X_UFL << 1));
+__CTASSERT(ALPHA_AESR_INE == (FP_X_IMP << 1));
+__CTASSERT(ALPHA_AESR_IOV == (FP_X_IOV << 1));
+
+__CTASSERT(IEEE_TRAP_ENABLE_INV == (FP_X_INV << 1));
+__CTASSERT(IEEE_TRAP_ENABLE_DZE == (FP_X_DZ  << 1));
+__CTASSERT(IEEE_TRAP_ENABLE_OVF == (FP_X_OFL << 1));
+__CTASSERT(IEEE_TRAP_ENABLE_UNF == (FP_X_UFL << 1));
+__CTASSERT(IEEE_TRAP_ENABLE_INE == (FP_X_IMP << 1));
+
+__CTASSERT((uint64_t)FP_X_IMP << (61 - 3) == FPCR_INED);
+__CTASSERT((uint64_t)FP_X_UFL << (61 - 3) == FPCR_UNFD);
+__CTASSERT((uint64_t)FP_X_OFL << (49 - 0) == FPCR_OVFD);
+__CTASSERT((uint64_t)FP_X_DZ  << (49 - 0) == FPCR_DZED);
+__CTASSERT((uint64_t)FP_X_INV << (49 - 0) == FPCR_INVD);
+
+__CTASSERT(FP_C_ALLBITS == MDLWP_FP_C);
+
 #define	TSWINSIZE 4	/* size of trap shadow window in uint32_t units */
 
 /*	Set Name		Opcodes			AARM C.* Symbols  */
@@ -351,11 +377,12 @@ fp_c_to_fpcr_1(uint64_t fpcr, uint64_t f
 	 * it is necessary to initially set a sticky bit.
 	 */
 
-	fpcr &= FPCR_DYN(3);
+	fpcr &= FPCR_DYN_RM;
 
 	/*
-	 * enable traps = case where flag bit is clear OR program wants a trap
-	 * enables = ~flags | mask
+	 * enable traps = case where flag bit is clear AND program wants a trap
+	 *
+	 * enables = ~flags & mask
 	 * disables = ~(~flags | mask)
 	 * disables = flags & ~mask. Thank you, Augustus De Morgan (1806-1871)
 	 */
@@ -364,18 +391,6 @@ fp_c_to_fpcr_1(uint64_t fpcr, uint64_t f
 	fpcr |= (disables & (FP_X_IMP | FP_X_UFL)) << (61 - 3);
 	fpcr |= (disables & (FP_X_OFL | FP_X_DZ | FP_X_INV)) << (49 - 0);
 
-#	if !(FP_X_INV == 1 && FP_X_DZ == 2 && FP_X_OFL == 4 &&		\
-	FP_X_UFL == 8 && FP_X_IMP == 16 && FP_X_IOV == 32 &&	\
-	FP_X_UFL << (61 - 3) == FPCR_UNFD &&			\
-	FP_X_IMP << (61 - 3) == FPCR_INED &&			\
-	FP_X_OFL << (49 - 0) == FPCR_OVFD)
-#		error "Assertion failed"
-	/*
-	 * We don't care about the other built-in bit numbers because they
-	 * have been architecturally specified.
-	 */
-#	endif
-
 	fpcr |= fp_c & FP_C_MIRRORED << (FPCR_MIR_START - FP_C_MIR_START);
 	fpcr |= (fp_c & IEEE_MAP_DMZ) << 36;
 	if (fp_c & FP_C_MIRRORED)
@@ -407,6 +422,11 @@ alpha_write_fp_c(struct lwp *l, uint64_t
 		alpha_pal_wrfen(1);
 		fp_c_to_fpcr(l);
 		alpha_pal_wrfen(0);
+	} else {
+		struct pcb *pcb = l->l_addr;
+
+		pcb->pcb_fp.fpr_cr =
+		fp_c_to_fpcr_1(pcb->pcb_fp.fpr_cr, l->l_md.md_flags);
 	}
 	kpreempt_enable();
 }
@@ -502,12 +522,47 @@ float64_unk(float64 a, float64 b)
  */
 
 static void
+print_fp_instruction(alpha_instruction *pc, struct lwp *l, uint32_t bits)
+{
+#if defined(DDB)
+	char buf[32];
+	struct alpha_print_instruction_context ctx = {
+		.insn.bits = bits,
+		.pc = (unsigned long)pc,
+		.buf = buf,

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

2021-07-21 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Thu Jul 22 01:31:55 UTC 2021

Modified Files:
src/sys/arch/alpha/include: proc.h

Log Message:
Use __BITS() to define MDLWP_FP_C.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/alpha/include/proc.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/alpha/include/proc.h
diff -u src/sys/arch/alpha/include/proc.h:1.22 src/sys/arch/alpha/include/proc.h:1.23
--- src/sys/arch/alpha/include/proc.h:1.22	Fri May 16 19:18:21 2014
+++ src/sys/arch/alpha/include/proc.h	Thu Jul 22 01:31:55 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: proc.h,v 1.22 2014/05/16 19:18:21 matt Exp $ */
+/* $NetBSD: proc.h,v 1.23 2021/07/22 01:31:55 thorpej Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Carnegie-Mellon University.
@@ -61,7 +61,7 @@ struct mdlwp {
  * 	C99 API's, the use of the MDLWP_FP_C bits is defined variously in
  * 	ieeefp.h and fpu.h.
  */
-#define	MDLWP_FP_C	0x007e	/* Extended FP_C Quadword bits */
+#define	MDLWP_FP_C	__BITS(1,22)	/* Extended FP_C Quadword bits */
 #define	MDLWP_FPACTIVE	__BIT(63)	/* FPU is active on LWP's PCU CPU */
 
 /*



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

2021-07-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Tue Jul 20 05:43:10 UTC 2021

Modified Files:
src/sys/arch/alpha/include: alpha.h

Log Message:
Define the f_float in-memory format.  Line of the fields in s_float and
t_float.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/alpha/include/alpha.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/alpha/include/alpha.h
diff -u src/sys/arch/alpha/include/alpha.h:1.45 src/sys/arch/alpha/include/alpha.h:1.46
--- src/sys/arch/alpha/include/alpha.h:1.45	Wed May  5 15:36:17 2021
+++ src/sys/arch/alpha/include/alpha.h	Tue Jul 20 05:43:10 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: alpha.h,v 1.45 2021/05/05 15:36:17 thorpej Exp $ */
+/* $NetBSD: alpha.h,v 1.46 2021/07/20 05:43:10 thorpej Exp $ */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -41,18 +41,26 @@
 #ifndef _ALPHA_H_
 #define _ALPHA_H_
 
+typedef union alpha_f_float {
+	uint32_t i;
+	uint32_t frac_hi:  7,
+		 exp:  8,
+		sign:  1,
+		 frac_lo: 16;
+} f_float;
+
 typedef union alpha_s_float {
 	uint32_t i;
 	uint32_t frac: 23,
-		  exp:   8,
-		  sign:  1;
+		  exp:  8,
+		 sign:  1;
 } s_float;
 
 typedef union alpha_t_float {
 	uint64_t i;
 	uint64_t frac: 52,
-		  exp:  11,
-		  sign:  1;
+		  exp: 11,
+		 sign:  1;
 } t_float;
 
 #ifdef _KERNEL
@@ -73,6 +81,7 @@ extern u_long cpu_implver;		/* from IMPL
 extern u_long cpu_amask;		/* from AMASK instruction */
 extern int bootdev_debug;
 extern int alpha_fp_sync_complete;
+extern int alpha_fp_complete_debug;
 extern int alpha_unaligned_print, alpha_unaligned_fix, alpha_unaligned_sigbus;
 extern void (*alpha_delay_fn)(unsigned long);
 



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

2021-07-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Tue Jul 20 02:42:10 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: db_instruction.h

Log Message:
Define the FIX float function codes (ITOFF, ITOFS, ITOFT).


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/alpha/alpha/db_instruction.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/alpha/alpha/db_instruction.h
diff -u src/sys/arch/alpha/alpha/db_instruction.h:1.12 src/sys/arch/alpha/alpha/db_instruction.h:1.13
--- src/sys/arch/alpha/alpha/db_instruction.h:1.12	Mon Jun 21 02:10:46 2021
+++ src/sys/arch/alpha/alpha/db_instruction.h	Tue Jul 20 02:42:10 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: db_instruction.h,v 1.12 2021/06/21 02:10:46 thorpej Exp $ */
+/* $NetBSD: db_instruction.h,v 1.13 2021/07/20 02:42:10 thorpej Exp $ */
 
 /*
  * Copyright (c) 1999 Christopher G. Demetriou.  All rights reserved.
@@ -445,6 +445,11 @@ typedef union {
 #define	op_cvtql_v	0x130
 #define	op_cvtql_sv	0x530
 
+		/* FIX FLOAT, "function" opcodes (bits 5..11)  */
+
+#define	op_itofs	0x004
+#define	op_itoff	0x014
+#define	op_itoft	0x024
 
 		/* ieee FLOAT, "function" opcodes (bits 5..11)  */
 



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

2021-07-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Tue Jul 20 01:56:06 UTC 2021

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

Log Message:
Emulate the CIX extension instructions (CTPOP, CTTZ, CTLZ).


To generate a diff of this commit:
cvs rdiff -u -r1.136 -r1.137 src/sys/arch/alpha/alpha/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/alpha/alpha/trap.c
diff -u src/sys/arch/alpha/alpha/trap.c:1.136 src/sys/arch/alpha/alpha/trap.c:1.137
--- src/sys/arch/alpha/alpha/trap.c:1.136	Mon Jul 19 22:21:36 2021
+++ src/sys/arch/alpha/alpha/trap.c	Tue Jul 20 01:56:06 2021
@@ -1,7 +1,7 @@
-/* $NetBSD: trap.c,v 1.136 2021/07/19 22:21:36 thorpej Exp $ */
+/* $NetBSD: trap.c,v 1.137 2021/07/20 01:56:06 thorpej Exp $ */
 
 /*-
- * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
+ * Copyright (c) 2000, 2001, 2021 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -95,7 +95,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.136 2021/07/19 22:21:36 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.137 2021/07/20 01:56:06 thorpej Exp $");
 
 #include 
 #include 
@@ -106,6 +106,7 @@ __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.1
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -980,6 +981,17 @@ EVCNT_ATTACH_STATIC(emul_bwx_stw);
 EVCNT_ATTACH_STATIC(emul_bwx_sextb);
 EVCNT_ATTACH_STATIC(emul_bwx_sextw);
 
+static struct evcnt emul_cix_ctpop =
+EVCNT_INITIALIZER(EVCNT_TYPE_TRAP, NULL, "emul cix", "ctpop");
+static struct evcnt emul_cix_ctlz =
+EVCNT_INITIALIZER(EVCNT_TYPE_TRAP, NULL, "emul cix", "ctlz");
+static struct evcnt emul_cix_cttz =
+EVCNT_INITIALIZER(EVCNT_TYPE_TRAP, NULL, "emul cix", "cttz");
+
+EVCNT_ATTACH_STATIC(emul_cix_ctpop);
+EVCNT_ATTACH_STATIC(emul_cix_ctlz);
+EVCNT_ATTACH_STATIC(emul_cix_cttz);
+
 #define	EMUL_COUNT(ev)	atomic_inc_64(&(ev).ev_count)
 
 /*
@@ -1129,6 +1141,60 @@ handle_opdec(struct lwp *l, u_long *ucod
 *regptr = w;
 			break;
 		}
+		if (inst.operate_reg_format.function == op_ctpop &&
+		inst.operate_reg_format.zero == 0 &&
+		inst.operate_reg_format.sbz == 0 &&
+		inst.operate_reg_format.ra == 31) {
+			unsigned long val;
+			unsigned int res;
+
+			EMUL_COUNT(emul_cix_ctpop);
+			regptr = irp(l, inst.operate_reg_format.rb);
+			val = (regptr != NULL) ? *regptr : 0;
+			res = popcount64(val);
+			regptr = irp(l, inst.operate_reg_format.rc);
+			if (regptr != NULL) {
+*regptr = res;
+			}
+			break;
+		}
+		if (inst.operate_reg_format.function == op_ctlz &&
+		inst.operate_reg_format.zero == 0 &&
+		inst.operate_reg_format.sbz == 0 &&
+		inst.operate_reg_format.ra == 31) {
+			unsigned long val;
+			unsigned int res;
+
+			EMUL_COUNT(emul_cix_ctlz);
+			regptr = irp(l, inst.operate_reg_format.rb);
+			val = (regptr != NULL) ? *regptr : 0;
+			res = fls64(val);
+			res = (res == 0) ? 64 : 64 - res;
+			regptr = irp(l, inst.operate_reg_format.rc);
+			if (regptr != NULL) {
+*regptr = res;
+			}
+			break;
+		}
+		if (inst.operate_reg_format.function == op_cttz &&
+		inst.operate_reg_format.zero == 0 &&
+		inst.operate_reg_format.sbz == 0 &&
+		inst.operate_reg_format.ra == 31) {
+			unsigned long val;
+			unsigned int res;
+
+			EMUL_COUNT(emul_cix_cttz);
+			regptr = irp(l, inst.operate_reg_format.rb);
+			val = (regptr != NULL) ? *regptr : 0;
+			res = ffs64(val);
+			res = (res == 0) ? 64 : res - 1;
+			regptr = irp(l, inst.operate_reg_format.rc);
+			if (regptr != NULL) {
+*regptr = res;
+			}
+			break;
+		}
+
 		goto sigill;
 
 	default:



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

2021-07-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon Jul 19 22:21:36 UTC 2021

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

Log Message:
- In unaligned_fixup(), use defined constants for opcodes, not magic numbers.

- In handle_opdec(), use ufetch_int() to fetch the instruction and
  _u{fetch,store}_{8,16}() when emulating BWX instructions rather
  than copyin() / copyout() (they're faster).

- Add event counters for BWX instruction emulation.


To generate a diff of this commit:
cvs rdiff -u -r1.135 -r1.136 src/sys/arch/alpha/alpha/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/alpha/alpha/trap.c
diff -u src/sys/arch/alpha/alpha/trap.c:1.135 src/sys/arch/alpha/alpha/trap.c:1.136
--- src/sys/arch/alpha/alpha/trap.c:1.135	Thu Nov 21 19:23:58 2019
+++ src/sys/arch/alpha/alpha/trap.c	Mon Jul 19 22:21:36 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.135 2019/11/21 19:23:58 ad Exp $ */
+/* $NetBSD: trap.c,v 1.136 2021/07/19 22:21:36 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -87,13 +87,15 @@
  * rights to redistribute these changes.
  */
 
+#define	__UFETCHSTORE_PRIVATE	/* see handle_opdec() */
+
 #include "opt_fix_unaligned_vax_fp.h"
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.135 2019/11/21 19:23:58 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.136 2021/07/19 22:21:36 thorpej Exp $");
 
 #include 
 #include 
@@ -875,65 +877,65 @@ unaligned_fixup(u_long va, u_long opcode
 	signo = SIGSEGV;
 	if (dofix && selected_tab->fixable) {
 		switch (opcode) {
-		case 0x0c:			/* ldwu */
+		case op_ldwu:
 			/* XXX ONLY WORKS ON LITTLE-ENDIAN ALPHA */
 			unaligned_load_integer(worddata);
 			break;
 
-		case 0x0d:			/* stw */
+		case op_stw:
 			/* XXX ONLY WORKS ON LITTLE-ENDIAN ALPHA */
 			unaligned_store_integer(worddata);
 			break;
 
 #ifdef FIX_UNALIGNED_VAX_FP
-		case 0x20:			/* ldf */
+		case op_ldf:
 			unaligned_load_floating(intdata, Ffloat_to_reg);
 			break;
 
-		case 0x21:			/* ldg */
+		case op_ldg:
 			unaligned_load_floating(longdata, Gfloat_reg_cvt);
 			break;
 #endif
 
-		case 0x22:			/* lds */
+		case op_lds:
 			unaligned_load_floating(intdata, Sfloat_to_reg);
 			break;
 
-		case 0x23:			/* ldt */
+		case op_ldt:
 			unaligned_load_floating(longdata, Tfloat_reg_cvt);
 			break;
 
 #ifdef FIX_UNALIGNED_VAX_FP
-		case 0x24:			/* stf */
+		case op_stf:
 			unaligned_store_floating(intdata, reg_to_Ffloat);
 			break;
 
-		case 0x25:			/* stg */
+		case op_stg:
 			unaligned_store_floating(longdata, Gfloat_reg_cvt);
 			break;
 #endif
 
-		case 0x26:			/* sts */
+		case op_sts:
 			unaligned_store_floating(intdata, reg_to_Sfloat);
 			break;
 
-		case 0x27:			/* stt */
+		case op_stt:
 			unaligned_store_floating(longdata, Tfloat_reg_cvt);
 			break;
 
-		case 0x28:			/* ldl */
+		case op_ldl:
 			unaligned_load_integer(intdata);
 			break;
 
-		case 0x29:			/* ldq */
+		case op_ldq:
 			unaligned_load_integer(longdata);
 			break;
 
-		case 0x2c:			/* stl */
+		case op_stl:
 			unaligned_store_integer(intdata);
 			break;
 
-		case 0x2d:			/* stq */
+		case op_stq:
 			unaligned_store_integer(longdata);
 			break;
 
@@ -958,6 +960,28 @@ unaligned_fixup(u_long va, u_long opcode
 	return (signo);
 }
 
+static struct evcnt emul_bwx_ldbu =
+EVCNT_INITIALIZER(EVCNT_TYPE_TRAP, NULL, "emul bwx", "ldbu");
+static struct evcnt emul_bwx_ldwu =
+EVCNT_INITIALIZER(EVCNT_TYPE_TRAP, NULL, "emul bwx", "ldwu");
+static struct evcnt emul_bwx_stb =
+EVCNT_INITIALIZER(EVCNT_TYPE_TRAP, NULL, "emul bwx", "stb");
+static struct evcnt emul_bwx_stw =
+EVCNT_INITIALIZER(EVCNT_TYPE_TRAP, NULL, "emul bwx", "stw");
+static struct evcnt emul_bwx_sextb =
+EVCNT_INITIALIZER(EVCNT_TYPE_TRAP, NULL, "emul bwx", "sextb");
+static struct evcnt emul_bwx_sextw =
+EVCNT_INITIALIZER(EVCNT_TYPE_TRAP, NULL, "emul bwx", "sextw");
+
+EVCNT_ATTACH_STATIC(emul_bwx_ldbu);
+EVCNT_ATTACH_STATIC(emul_bwx_ldwu);
+EVCNT_ATTACH_STATIC(emul_bwx_stb);
+EVCNT_ATTACH_STATIC(emul_bwx_stw);
+EVCNT_ATTACH_STATIC(emul_bwx_sextb);
+EVCNT_ATTACH_STATIC(emul_bwx_sextw);
+
+#define	EMUL_COUNT(ev)	atomic_inc_64(&(ev).ev_count)
+
 /*
  * Reserved/unimplemented instruction (opDec fault) handler
  *
@@ -986,7 +1010,7 @@ handle_opdec(struct lwp *l, u_long *ucod
 	l->l_md.md_tf->tf_regs[FRAME_SP] = alpha_pal_rdusp();
 
 	inst_pc = memaddr = l->l_md.md_tf->tf_regs[FRAME_PC] - 4;
-	if (copyin((void *)inst_pc, , sizeof (inst)) != 0) {
+	if (ufetch_int((void *)inst_pc, ) != 0) {
 		/*
 		 * really, this should never happen, but in case it
 		 * does we handle it.
@@ -1012,6 +1036,11 @@ handle_opdec(struct lwp *l, u_long *ucod
 		if (inst.mem_format.opcode == op_ldwu ||
 		inst.mem_format.opcode == op_stw) {
 			if (memaddr & 0x01) {
+if (inst.mem_format.opcode == 

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

2021-07-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon Jul 19 16:31:19 UTC 2021

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

Log Message:
Re-arrange the kernel pmap fast-path in pmap_extract() so that
when DEBUG is not enabled, the compiler can emit a tail-call to
vtophys_internal().


To generate a diff of this commit:
cvs rdiff -u -r1.298 -r1.299 src/sys/arch/alpha/alpha/pmap.c

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

Modified files:

Index: src/sys/arch/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.298 src/sys/arch/alpha/alpha/pmap.c:1.299
--- src/sys/arch/alpha/alpha/pmap.c:1.298	Fri Jul 16 19:02:22 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Mon Jul 19 16:31:19 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.298 2021/07/16 19:02:22 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.299 2021/07/19 16:31:19 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.298 2021/07/16 19:02:22 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.299 2021/07/19 16:31:19 thorpej Exp $");
 
 #include 
 #include 
@@ -2578,18 +2578,18 @@ pmap_extract(pmap_t pmap, vaddr_t va, pa
 	 * handles K0SEG.
 	 */
 	if (__predict_true(pmap == pmap_kernel())) {
-		if (__predict_true(vtophys_internal(va, pap))) {
 #ifdef DEBUG
-			if (pmapdebug & PDB_FOLLOW)
+		bool address_is_valid = vtophys_internal(va, pap);
+		if (pmapdebug & PDB_FOLLOW) {
+			if (address_is_valid) {
 printf("0x%lx (kernel vtophys)\n", *pap);
-#endif
-			return true;
+			} else {
+printf("failed (kernel vtophys)\n");
+			}
 		}
-#ifdef DEBUG
-		if (pmapdebug & PDB_FOLLOW)
-			printf("failed (kernel vtophys)\n");
+#else
+		return vtophys_internal(va, pap);
 #endif
-		return false;
 	}
 
 	pt_entry_t * const lev1map = pmap_lev1map(pmap);



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

2021-07-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon Jul 19 16:25:54 UTC 2021

Modified Files:
src/sys/arch/alpha/common: bus_dma.c sgmap_typedep.c

Log Message:
There is already a fast-path in pmap_extract() for the kernel pmap, so
don't bother doing a conditional for kernel vs. user-space here.

KASSERT() that pmap_extract() succeeds; it is a programming error if
it does not, and it's not a great idea to insert a garbage address
into the SGMAP page table.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/sys/arch/alpha/common/bus_dma.c
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/alpha/common/sgmap_typedep.c

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

Modified files:

Index: src/sys/arch/alpha/common/bus_dma.c
diff -u src/sys/arch/alpha/common/bus_dma.c:1.72 src/sys/arch/alpha/common/bus_dma.c:1.73
--- src/sys/arch/alpha/common/bus_dma.c:1.72	Fri May  7 16:58:33 2021
+++ src/sys/arch/alpha/common/bus_dma.c	Mon Jul 19 16:25:54 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: bus_dma.c,v 1.72 2021/05/07 16:58:33 thorpej Exp $ */
+/* $NetBSD: bus_dma.c,v 1.73 2021/07/19 16:25:54 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.72 2021/05/07 16:58:33 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.73 2021/07/19 16:25:54 thorpej Exp $");
 
 #include 
 #include 
@@ -138,6 +138,7 @@ _bus_dmamap_load_buffer_direct(bus_dma_t
 	bus_addr_t curaddr, lastaddr, baddr, bmask;
 	vaddr_t vaddr = (vaddr_t)buf;
 	int seg;
+	bool address_is_valid __diagused;
 
 	lastaddr = *lastaddrp;
 	bmask = ~(map->_dm_boundary - 1);
@@ -146,10 +147,9 @@ _bus_dmamap_load_buffer_direct(bus_dma_t
 		/*
 		 * Get the physical address for this segment.
 		 */
-		if (!VMSPACE_IS_KERNEL_P(vm))
-			(void) pmap_extract(vm->vm_map.pmap, vaddr, );
-		else
-			curaddr = vtophys(vaddr);
+		address_is_valid =
+		pmap_extract(vm->vm_map.pmap, vaddr, );
+		KASSERT(address_is_valid);
 
 		/*
 		 * If we're beyond the current DMA window, indicate

Index: src/sys/arch/alpha/common/sgmap_typedep.c
diff -u src/sys/arch/alpha/common/sgmap_typedep.c:1.43 src/sys/arch/alpha/common/sgmap_typedep.c:1.44
--- src/sys/arch/alpha/common/sgmap_typedep.c:1.43	Sun Jul 18 05:12:27 2021
+++ src/sys/arch/alpha/common/sgmap_typedep.c	Mon Jul 19 16:25:54 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sgmap_typedep.c,v 1.43 2021/07/18 05:12:27 thorpej Exp $ */
+/* $NetBSD: sgmap_typedep.c,v 1.44 2021/07/19 16:25:54 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.43 2021/07/18 05:12:27 thorpej Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.44 2021/07/19 16:25:54 thorpej Exp $");
 
 #include "opt_ddb.h"
 
@@ -74,6 +74,7 @@ __C(SGMAP_TYPE,_load_buffer)(bus_dma_tag
 	bus_size_t sgvalen, extra_sgvalen, boundary, alignment;
 	SGMAP_PTE_TYPE *pte, *page_table = sgmap->aps_pt;
 	int pteidx, error, spill, seg = *segp;
+	bool address_is_valid __diagused;
 
 	/* Initialize the spill page PTE if it hasn't been already. */
 	if (__C(SGMAP_TYPE,_prefetch_spill_page_pte) == 0)
@@ -268,10 +269,8 @@ __C(SGMAP_TYPE,_load_buffer)(bus_dma_tag
 	for (; va < endva; va += PAGE_SIZE, pteidx++,
 	 pte = _table[pteidx * SGMAP_PTE_SPACING]) {
 		/* Get the physical address for this segment. */
-		if (!VMSPACE_IS_KERNEL_P(vm))
-			(void) pmap_extract(vm->vm_map.pmap, va, );
-		else
-			pa = vtophys(va);
+		address_is_valid = pmap_extract(vm->vm_map.pmap, va, );
+		KASSERT(address_is_valid);
 
 		/* Load the current PTE with this page. */
 		*pte = (pa >> SGPTE_PGADDR_SHIFT) | SGPTE_VALID;
@@ -289,10 +288,8 @@ __C(SGMAP_TYPE,_load_buffer)(bus_dma_tag
 
 		/* va == endva == address of extra page */
 		KASSERT(va == endva);
-		if (!VMSPACE_IS_KERNEL_P(vm))
-			(void) pmap_extract(vm->vm_map.pmap, va, );
-		else
-			pa = vtophys(va);
+		address_is_valid = pmap_extract(vm->vm_map.pmap, va, );
+		KASSERT(address_is_valid);
 
 		/*
 		 * If a spill page is needed, the previous segment will



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

2021-07-18 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon Jul 19 01:06:14 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: cia_dma.c ciavar.h tsp_dma.c tsvar.h

Log Message:
For CIA/Pyxis and Tsunami/Typhoon/Titan, save the firmware's idea of
the DMA window configuration, and restore it at shutdown time.  Make
sure that all assumptions we've made on the firmware's configuration
of DMA windows is correct.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/alpha/pci/cia_dma.c
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/alpha/pci/ciavar.h \
src/sys/arch/alpha/pci/tsp_dma.c
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/alpha/pci/tsvar.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/alpha/pci/cia_dma.c
diff -u src/sys/arch/alpha/pci/cia_dma.c:1.36 src/sys/arch/alpha/pci/cia_dma.c:1.37
--- src/sys/arch/alpha/pci/cia_dma.c:1.36	Sun Jul 18 05:09:47 2021
+++ src/sys/arch/alpha/pci/cia_dma.c	Mon Jul 19 01:06:14 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: cia_dma.c,v 1.36 2021/07/18 05:09:47 thorpej Exp $ */
+/* $NetBSD: cia_dma.c,v 1.37 2021/07/19 01:06:14 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: cia_dma.c,v 1.36 2021/07/18 05:09:47 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cia_dma.c,v 1.37 2021/07/19 01:06:14 thorpej Exp $");
 
 #include 
 #include 
@@ -100,12 +100,49 @@ struct alpha_sgmap cia_pyxis_bug_sgmap;
 #define	CIA_PYXIS_BUG_BASE	(128UL*1024*1024)
 #define	CIA_PYXIS_BUG_SIZE	(2UL*1024*1024)
 
+static void
+cia_dma_shutdown(void *arg)
+{
+	struct cia_config *ccp = arg;
+	int i;
+
+	/*
+	 * Restore the original values, to make the firmware happy.
+	 */
+	for (i = 0; i < 4; i++) {
+		REGVAL(CIA_PCI_W0BASE + (i * 0x100)) =
+		ccp->cc_saved_windows.wbase[i];
+		alpha_mb();
+		REGVAL(CIA_PCI_W0MASK + (i * 0x100)) =
+		ccp->cc_saved_windows.wmask[i];
+		alpha_mb();
+		REGVAL(CIA_PCI_T0BASE + (i * 0x100)) =
+		ccp->cc_saved_windows.tbase[i];
+		alpha_mb();
+	}
+}
+
 void
 cia_dma_init(struct cia_config *ccp)
 {
 	bus_addr_t tbase;
 	bus_dma_tag_t t;
 	bus_dma_tag_t t_sg_hi = NULL;
+	int i;
+
+	/*
+	 * Save our configuration to restore at shutdown, just
+	 * in case the firmware would get cranky with us.
+	 */
+	for (i = 0; i < 4; i++) {
+		ccp->cc_saved_windows.wbase[i] =
+		REGVAL(CIA_PCI_W0BASE + (i * 0x100));
+		ccp->cc_saved_windows.wmask[i] =
+		REGVAL(CIA_PCI_W0MASK + (i * 0x100));
+		ccp->cc_saved_windows.tbase[i] =
+		REGVAL(CIA_PCI_T0BASE + (i * 0x100));
+	}
+	shutdownhook_establish(cia_dma_shutdown, ccp);
 
 	/*
 	 * If we have more than 1GB of RAM, then set up an sgmap-mapped
@@ -195,11 +232,17 @@ cia_dma_init(struct cia_config *ccp)
 	t->_dmamem_mmap = _bus_dmamem_mmap;
 
 	/*
-	 * The firmware has set up window 1 as a 1G direct-mapped DMA
-	 * window beginning at 1G.  We leave it alone.  Leave window
-	 * 0 alone until we reconfigure it for SGMAP-mapped DMA.
-	 * Windows 2 and 3 are already disabled.
+	 * The firmware will have set up window 1 as a 1G dirct-mapped
+	 * DMA window beginning at 1G.  While it's pretty safe to assume
+	 * this is the case, we'll go ahead and program the registers
+	 * as we expect as a belt-and-suspenders measure.
 	 */
+	REGVAL(CIA_PCI_W1BASE) = CIA_DIRECT_MAPPED_BASE | CIA_PCI_WnBASE_W_EN;
+	alpha_mb();
+	REGVAL(CIA_PCI_W1MASK) = CIA_PCI_WnMASK_1G;
+	alpha_mb();
+	REGVAL(CIA_PCI_T1BASE) = 0;
+	alpha_mb();
 
 	/*
 	 * Initialize the SGMAP(s).  Must align page table to at least 32k
@@ -248,6 +291,9 @@ cia_dma_init(struct cia_config *ccp)
 			panic("cia_dma_init: bad page table address");
 		REGVAL(CIA_PCI_T3BASE) = tbase;
 		alpha_mb();
+	} else {
+		REGVAL(CIA_PCI_W3BASE) = 0;
+		alpha_mb();
 	}
 
 	/*
@@ -261,7 +307,6 @@ cia_dma_init(struct cia_config *ccp)
 	 */
 	if ((ccp->cc_flags & CCF_ISPYXIS) != 0 && ccp->cc_rev <= 1) {
 		uint64_t *page_table;
-		int i;
 
 		cia_tlb_invalidate_fn =
 		cia_broken_pyxis_tlb_invalidate;
@@ -296,8 +341,12 @@ cia_dma_init(struct cia_config *ccp)
 			pci_sgmap_pte64_prefetch_spill_page_pte;
 		}
 		alpha_mb();
-	} else
+	} else {
+		REGVAL(CIA_PCI_W2BASE) = 0;
+		alpha_mb();
+
 		cia_tlb_invalidate_fn = cia_tlb_invalidate;
+	}
 
 	CIA_TLB_INVALIDATE();
 }

Index: src/sys/arch/alpha/pci/ciavar.h
diff -u src/sys/arch/alpha/pci/ciavar.h:1.21 src/sys/arch/alpha/pci/ciavar.h:1.22
--- src/sys/arch/alpha/pci/ciavar.h:1.21	Sat Jul 17 00:30:39 2021
+++ src/sys/arch/alpha/pci/ciavar.h	Mon Jul 19 01:06:14 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ciavar.h,v 1.21 2021/07/17 00:30:39 thorpej Exp $ */
+/* $NetBSD: ciavar.h,v 1.22 2021/07/19 01:06:14 thorpej Exp $ */
 
 /*
  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
@@ -65,6 +65,12 @@ struct cia_config {
 
 	struct extent *cc_io_ex, *cc_d_mem_ex, *cc_s_mem_ex;
 	int	cc_mallocsafe;
+
+	struct {
+	

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

2021-07-18 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Jul 18 19:58:34 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: tsp_dma.c

Log Message:
According to section 8.1.2.2 of the Tsunami/Typhoon hardware reference
manual (DS-0025A-TE), the SGMAP TLB is arranged as 168 locations of 4
consecutive quadwords.  It seems that on some revisions of the Pchip,
SGMAP translation is not perfectly reliable unless we align the DMA
segments to the TLBs natural boundaries (observed on the API CS20).

N.B. the Titan (as observed on a Compaq DS25) does not seem to have this
problem, but we'll play it safe and run this way on both variants.

PR port-alpha/40604.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/alpha/pci/tsp_dma.c

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

Modified files:

Index: src/sys/arch/alpha/pci/tsp_dma.c
diff -u src/sys/arch/alpha/pci/tsp_dma.c:1.20 src/sys/arch/alpha/pci/tsp_dma.c:1.21
--- src/sys/arch/alpha/pci/tsp_dma.c:1.20	Sun Jul 18 05:09:47 2021
+++ src/sys/arch/alpha/pci/tsp_dma.c	Sun Jul 18 19:58:34 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tsp_dma.c,v 1.20 2021/07/18 05:09:47 thorpej Exp $ */
+/* $NetBSD: tsp_dma.c,v 1.21 2021/07/18 19:58:34 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 2021 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tsp_dma.c,v 1.20 2021/07/18 05:09:47 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tsp_dma.c,v 1.21 2021/07/18 19:58:34 thorpej Exp $");
 
 #include 
 #include 
@@ -187,6 +187,20 @@ tsp_dma_init(struct tsp_config *pcp)
 		t->_next_window = NULL;
 		t->_boundary = 0;
 		t->_sgmap = >pc_sgmap_hi;
+		/*
+		 * According to section 8.1.2.2 of the Tsunami/Typhoon
+		 * hardware reference manual (DS-0025A-TE), the SGMAP
+		 * TLB is arranged as 168 locations of 4 consecutive
+		 * quadwords.  It seems that on some revisions of the
+		 * Pchip, SGMAP translation is not perfectly reliable
+		 * unless we align the DMA segments to the TLBs natural
+		 * boundaries (observed on the API CS20).
+		 *
+		 * N.B. the Titan (as observed on a Compaq DS25) does not
+		 * seem to have this problem, but we'll play it safe and
+		 * run this way on both variants.
+		 */
+		t->_sgmap_minalign = PAGE_SIZE * 4;
 		t->_pfthresh = TSP_SGMAP_PFTHRESH;
 		t->_get_tag = tsp_dma_get_tag;
 		t->_dmamap_create = alpha_sgmap_dmamap_create;
@@ -267,6 +281,11 @@ tsp_dma_init(struct tsp_config *pcp)
 	t->_next_window = NULL;
 	t->_boundary = 0;
 	t->_sgmap = >pc_sgmap_lo;
+	/*
+	 * This appears to be needed to make DMA on the ALI southbridge
+	 * that's present in some systems happy.  ???
+	 */
+	t->_sgmap_minalign = (64UL * 1024);
 	t->_pfthresh = TSP_SGMAP_PFTHRESH;
 	t->_get_tag = tsp_dma_get_tag;
 	t->_dmamap_create = alpha_sgmap_dmamap_create;



CVS commit: src/sys/arch/alpha

2021-07-17 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Jul 18 05:12:27 UTC 2021

Modified Files:
src/sys/arch/alpha/common: sgmap_common.c sgmap_typedep.c
src/sys/arch/alpha/include: bus_defs.h
src/sys/arch/alpha/tc: tc_dma.c tc_dma_3000_500.c

Log Message:
Allow for the SGMAP implementation to specify a minimum alignment for
SGMAP DMA segments.  If not specified, PAGE_SIZE will be used, as before.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/alpha/common/sgmap_common.c
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/alpha/common/sgmap_typedep.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/alpha/include/bus_defs.h
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/alpha/tc/tc_dma.c
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/alpha/tc/tc_dma_3000_500.c

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

Modified files:

Index: src/sys/arch/alpha/common/sgmap_common.c
diff -u src/sys/arch/alpha/common/sgmap_common.c:1.28 src/sys/arch/alpha/common/sgmap_common.c:1.29
--- src/sys/arch/alpha/common/sgmap_common.c:1.28	Sun Jul  4 22:42:35 2021
+++ src/sys/arch/alpha/common/sgmap_common.c	Sun Jul 18 05:12:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sgmap_common.c,v 1.28 2021/07/04 22:42:35 thorpej Exp $ */
+/* $NetBSD: sgmap_common.c,v 1.29 2021/07/18 05:12:27 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: sgmap_common.c,v 1.28 2021/07/04 22:42:35 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sgmap_common.c,v 1.29 2021/07/18 05:12:27 thorpej Exp $");
 
 #include 
 #include 
@@ -68,6 +68,14 @@ alpha_sgmap_init(bus_dma_tag_t t, struct
 		goto die;
 	}
 
+	/*
+	 * If we don't yet have a minimum SGVA alignment, default
+	 * to the system page size.
+	 */
+	if (t->_sgmap_minalign < PAGE_SIZE) {
+		t->_sgmap_minalign = PAGE_SIZE;
+	}
+
 	sgmap->aps_wbase = wbase;
 	sgmap->aps_sgvabase = sgvabase;
 	sgmap->aps_sgvasize = sgvasize;

Index: src/sys/arch/alpha/common/sgmap_typedep.c
diff -u src/sys/arch/alpha/common/sgmap_typedep.c:1.42 src/sys/arch/alpha/common/sgmap_typedep.c:1.43
--- src/sys/arch/alpha/common/sgmap_typedep.c:1.42	Thu Jun 24 16:41:16 2021
+++ src/sys/arch/alpha/common/sgmap_typedep.c	Sun Jul 18 05:12:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sgmap_typedep.c,v 1.42 2021/06/24 16:41:16 thorpej Exp $ */
+/* $NetBSD: sgmap_typedep.c,v 1.43 2021/07/18 05:12:27 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.42 2021/06/24 16:41:16 thorpej Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.43 2021/07/18 05:12:27 thorpej Exp $");
 
 #include "opt_ddb.h"
 
@@ -130,7 +130,8 @@ __C(SGMAP_TYPE,_load_buffer)(bus_dma_tag
 	const vm_flag_t vmflags = VM_INSTANTFIT |
 	((flags & BUS_DMA_NOWAIT) ? VM_NOSLEEP : VM_SLEEP);
 
-	alignment = PAGE_SIZE;
+	KASSERT(t->_sgmap_minalign != 0);
+	alignment = t->_sgmap_minalign;
 	sgvalen = (endva - va);
 
 	SGMAP_PTE_TYPE spill_pte_v = __C(SGMAP_TYPE,_prefetch_spill_page_pte);
@@ -193,13 +194,16 @@ __C(SGMAP_TYPE,_load_buffer)(bus_dma_tag
 		 * ARGH!  If the addition of the spill page bumped us
 		 * over our boundary, we have to 2x the boundary limit.
 		 * To compensate (and enforce the original boundary
-		 * constraint), we force our alignment to be the previous
-		 * boundary, thus ensuring that the only boundary violation
-		 * is the pre-fetch that the SGMAP controller performs that
-		 * necessitates the spill page in the first place.
+		 * constraint), we force our alignment to be at least the
+		 * previous boundary, thus ensuring that the only boundary
+		 * violation is the pre-fetch that the SGMAP controller
+		 * performs that necessitates the spill page in the first
+		 * place.
 		 */
 		if (boundary && boundary < sgvalen) {
-			alignment = boundary;
+			if (alignment < boundary) {
+alignment = boundary;
+			}
 			do {
 boundary <<= 1;
 			} while (boundary < sgvalen);

Index: src/sys/arch/alpha/include/bus_defs.h
diff -u src/sys/arch/alpha/include/bus_defs.h:1.5 src/sys/arch/alpha/include/bus_defs.h:1.6
--- src/sys/arch/alpha/include/bus_defs.h:1.5	Mon Sep 23 16:17:54 2019
+++ src/sys/arch/alpha/include/bus_defs.h	Sun Jul 18 05:12:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: bus_defs.h,v 1.5 2019/09/23 16:17:54 skrll Exp $ */
+/* $NetBSD: bus_defs.h,v 1.6 2021/07/18 05:12:27 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 2000, 2001 The NetBSD Foundation, Inc.
@@ -364,6 +364,12 @@ struct alpha_bus_dma_tag {
 	struct alpha_sgmap *_sgmap;
 
 	/*
+	 * Some chipsets may want to enforce a minimum alignment
+	 * constraint for SGMAP DMA addresses.
+	 */
+	bus_size_t _sgmap_minalign;
+
+	/*
 	 * The SGMAP MMU implements a prefetch FIFO to keep data
 	 * moving down the pipe, when doing host->bus DMA writes.
 	 * 

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

2021-07-17 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Jul 18 05:09:47 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: cia_dma.c tsp_dma.c

Log Message:
Oops, pass the correct bus_dma_tag_t to the "hi" sgmap init function.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/alpha/pci/cia_dma.c
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/alpha/pci/tsp_dma.c

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

Modified files:

Index: src/sys/arch/alpha/pci/cia_dma.c
diff -u src/sys/arch/alpha/pci/cia_dma.c:1.35 src/sys/arch/alpha/pci/cia_dma.c:1.36
--- src/sys/arch/alpha/pci/cia_dma.c:1.35	Sat Jul 17 00:30:39 2021
+++ src/sys/arch/alpha/pci/cia_dma.c	Sun Jul 18 05:09:47 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: cia_dma.c,v 1.35 2021/07/17 00:30:39 thorpej Exp $ */
+/* $NetBSD: cia_dma.c,v 1.36 2021/07/18 05:09:47 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: cia_dma.c,v 1.35 2021/07/17 00:30:39 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cia_dma.c,v 1.36 2021/07/18 05:09:47 thorpej Exp $");
 
 #include 
 #include 
@@ -202,14 +202,14 @@ cia_dma_init(struct cia_config *ccp)
 	 */
 
 	/*
-	 * Initialize the SGMAP(s).  Must align page table to 32k
+	 * Initialize the SGMAP(s).  Must align page table to at least 32k
 	 * (hardware bug?).
 	 */
 	alpha_sgmap_init(t, >cc_sgmap_lo, "cia_sgmap_lo",
 	CIA_SGMAP_MAPPED_LO_BASE, 0, CIA_SGMAP_MAPPED_LO_SIZE,
 	sizeof(uint64_t), NULL, (32*1024));
 	if (t_sg_hi != NULL) {
-		alpha_sgmap_init(t, >cc_sgmap_hi, "cia_sgmap_hi",
+		alpha_sgmap_init(t_sg_hi, >cc_sgmap_hi, "cia_sgmap_hi",
 		CIA_SGMAP_MAPPED_HI_BASE, 0, CIA_SGMAP_MAPPED_HI_SIZE,
 		sizeof(uint64_t), NULL, (32*1024));
 	}

Index: src/sys/arch/alpha/pci/tsp_dma.c
diff -u src/sys/arch/alpha/pci/tsp_dma.c:1.19 src/sys/arch/alpha/pci/tsp_dma.c:1.20
--- src/sys/arch/alpha/pci/tsp_dma.c:1.19	Sun Jul 18 00:01:20 2021
+++ src/sys/arch/alpha/pci/tsp_dma.c	Sun Jul 18 05:09:47 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tsp_dma.c,v 1.19 2021/07/18 00:01:20 thorpej Exp $ */
+/* $NetBSD: tsp_dma.c,v 1.20 2021/07/18 05:09:47 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 2021 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tsp_dma.c,v 1.19 2021/07/18 00:01:20 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tsp_dma.c,v 1.20 2021/07/18 05:09:47 thorpej Exp $");
 
 #include 
 #include 
@@ -292,7 +292,7 @@ tsp_dma_init(struct tsp_config *pcp)
 	TSP_SGMAP_MAPPED_LO_BASE, 0, TSP_SGMAP_MAPPED_LO_SIZE,
 	sizeof(uint64_t), NULL, (32*1024));
 	if (t_sg_hi != NULL) {
-		alpha_sgmap_init(t, >pc_sgmap_hi, "tsp_sgmap_hi",
+		alpha_sgmap_init(t_sg_hi, >pc_sgmap_hi, "tsp_sgmap_hi",
 		TSP_SGMAP_MAPPED_HI_BASE, 0, TSP_SGMAP_MAPPED_HI_SIZE,
 		sizeof(uint64_t), NULL, (32*1024));
 	}



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

2021-07-17 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Jul 18 00:01:21 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: tsp_dma.c tsvar.h

Log Message:
- Don't bother issuing a warning if we program the WBASE / WSM register
  to different values than the firmware.
- Reduce the differences in how we initialize the DMA tags vis a vis the
  other Alpha implementations.
- Use Window 2 to provide a 1G @ 3G PCI SGMAP window on systems with more
  than 1G of RAM, rather than falling back on the ISA DMA window which is
  small and could get starved by PCI devices.
- Make sure we set TBASE to 0 for direct-mapped windows.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/alpha/pci/tsp_dma.c
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/alpha/pci/tsvar.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/alpha/pci/tsp_dma.c
diff -u src/sys/arch/alpha/pci/tsp_dma.c:1.18 src/sys/arch/alpha/pci/tsp_dma.c:1.19
--- src/sys/arch/alpha/pci/tsp_dma.c:1.18	Sun Jul  4 22:42:36 2021
+++ src/sys/arch/alpha/pci/tsp_dma.c	Sun Jul 18 00:01:20 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tsp_dma.c,v 1.18 2021/07/04 22:42:36 thorpej Exp $ */
+/* $NetBSD: tsp_dma.c,v 1.19 2021/07/18 00:01:20 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 2021 The NetBSD Foundation, Inc.
@@ -61,13 +61,15 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tsp_dma.c,v 1.18 2021/07/04 22:42:36 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tsp_dma.c,v 1.19 2021/07/18 00:01:20 thorpej Exp $");
 
 #include 
 #include 
 #include 
 #include 
 
+#include 
+
 #include 
 #define _ALPHA_BUS_DMA_PRIVATE
 #include 
@@ -80,8 +82,6 @@ __KERNEL_RCSID(0, "$NetBSD: tsp_dma.c,v 
 
 #define tsp_dma() { Generate ctags(1) key. }
 
-#define	EDIFF(a, b) (((a) | WSBA_ENA | WSBA_SG)	!= ((b) | WSBA_ENA | WSBA_SG))
-
 static bus_dma_tag_t tsp_dma_get_tag(bus_dma_tag_t, alpha_bus_t);
 
 static int	tsp_bus_dmamap_load_sgmap(bus_dma_tag_t, bus_dmamap_t, void *,
@@ -126,53 +126,93 @@ static void	tsp_tlb_invalidate(struct ts
  * 64-bit DMA tag.  This leaves us possibly having to fall back on SGMAP
  * DMA on a Titan system (those support up to 64GB of RAM), and we may have
  * to address that with an additional large SGMAP DAC window at another
- * time.
+ * time.  XXX Does the Titan Monster Window support the extra bit?
  */
 #define	TSP_MONSTER_DMA_WINDOW_BASE	0x100##UL
 #define	TSP_MONSTER_DMA_WINDOW_SIZE	0x008##UL
 
+/*
+ * Basic 24-bit ISA DMA window is 8MB @ 8MB.  The firmware will
+ * have set this up in Window 0.
+ */
+#define	TSP_SGMAP_MAPPED_LO_BASE	(8UL * 1024 * 1024)
+#define	TSP_SGMAP_MAPPED_LO_SIZE	(8UL * 1024 * 1024)
+
+/*
+ * Basic 32-bit PCI DMA window is 1GB @ 2GB.  The firmware will
+ * have set this up in Window 1.
+ */
+#define	TSP_DIRECT_MAPPED_BASE		(2UL * 1024 * 1024 * 1024)
+#define	TSP_DIRECT_MAPPED_SIZE		(1UL * 1024 * 1024 * 1024)
+
+/*
+ * For systems that have > 1GB of RAM, but PCI devices that don't
+ * support dual-address cycle, we will also set up an additional
+ * SGMAP DMA window 1GB @ 3GB.  We will use Window 2 for this purpose.
+ */
+#define	TSP_SGMAP_MAPPED_HI_BASE	(3UL * 1024 * 1024 * 1024)
+#define	TSP_SGMAP_MAPPED_HI_SIZE	(1UL * 1024 * 1024 * 1024)
+
+/*
+ * Window 3 is still available for use in the future.  Window 3 supports
+ * dual address cycle.
+ */
+
 void
 tsp_dma_init(struct tsp_config *pcp)
 {
-	int i;
 	bus_dma_tag_t t;
+	bus_dma_tag_t t_sg_hi = NULL;
 	struct ts_pchip *pccsr = pcp->pc_csr;
-	bus_addr_t dwbase, dwlen, sgwbase, sgwlen, tbase;
-	static struct map_expected {
-		uint32_t base, mask, enables;
-	} premap[4] = {
-		{ 0x0080, 0x0070, WSBA_ENA | WSBA_SG },
-		{ 0x8000, 0x3ff0, WSBA_ENA   },
-		{ 0, 0, 0 },
-		{ 0, 0, 0 }
-	};
-
-	alpha_mb();
-	for(i = 0; i < 4; ++i) {
-		if (EDIFF(pccsr->tsp_wsba[i].tsg_r, premap[i].base) ||
-		EDIFF(pccsr->tsp_wsm[i].tsg_r, premap[i].mask))
-			printf("tsp%d: window %d: %lx/base %lx/mask %lx"
-			" reinitialized\n",
-			pcp->pc_pslot, i,
-			pccsr->tsp_wsba[i].tsg_r,
-			pccsr->tsp_wsm[i].tsg_r,
-			pccsr->tsp_tba[i].tsg_r);
-		pccsr->tsp_wsba[i].tsg_r = premap[i].base | premap[i].enables;
-		pccsr->tsp_wsm[i].tsg_r = premap[i].mask;
-	}
+	bus_addr_t tbase;
 
 	/* Ensure the Monster Window is enabled. */
+	alpha_mb();
 	pccsr->tsp_pctl.tsg_r |= PCTL_MWIN;
 	alpha_mb();
 
 	/*
+	 * If we have more than 1GB of RAM, then set up an sgmap-mapped
+	 * DMA window for non-DAC PCI.  This is better than using the ISA
+	 * window, which is pretty small and PCI devices could starve it.
+	 *
+	 * N.B. avail_end is "last-usable PFN + 1".
+	 */
+	if (uvm_physseg_get_avail_end(uvm_physseg_get_last()) >
+	atop(TSP_DIRECT_MAPPED_SIZE)) {
+		t = t_sg_hi = >pc_dmat_sgmap_hi;
+		t->_cookie = pcp;
+		t->_wbase = TSP_SGMAP_MAPPED_HI_BASE;
+		t->_wsize = TSP_SGMAP_MAPPED_HI_SIZE;
+		t->_next_window = NULL;
+		

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

2021-07-17 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Jul 17 23:53:02 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: tsreg.h

Log Message:
- Define the DAC enable bit that's present in WSBA3.
- Define symbolic constants for the valid WSM values.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/alpha/pci/tsreg.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/alpha/pci/tsreg.h
diff -u src/sys/arch/alpha/pci/tsreg.h:1.9 src/sys/arch/alpha/pci/tsreg.h:1.10
--- src/sys/arch/alpha/pci/tsreg.h:1.9	Thu May 27 22:11:31 2021
+++ src/sys/arch/alpha/pci/tsreg.h	Sat Jul 17 23:53:02 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tsreg.h,v 1.9 2021/05/27 22:11:31 thorpej Exp $ */
+/* $NetBSD: tsreg.h,v 1.10 2021/07/17 23:53:02 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1999 by Ross Harvey.  All rights reserved.
@@ -150,14 +150,29 @@
 #define P_WSBA3		0x00c0
 
 #	define	WSBA_ADDR(r) (TSFIELDBB((r), 31, 20) << 20)
-#	define	WSBA_SG	 2
-#	define	WSBA_ENA 1
+#	define	WSBA3_DAC__BIT(39)
+#	define	WSBA_SG	 __BIT(1)
+#	define	WSBA_ENA __BIT(0)
 
 #define P_WSM0		0x0100
 #define P_WSM1		0x0140
 #define P_WSM2		0x0180
 #define P_WSM3		0x01c0
 
+#	define	WSM_1MB  (0x000UL << 20)
+#	define	WSM_2MB  (0x001UL << 20)
+#	define	WSM_4MB  (0x003UL << 20)
+#	define	WSM_8MB  (0x007UL << 20)
+#	define	WSM_16MB (0x00fUL << 20)
+#	define	WSM_32MB (0x01fUL << 20)
+#	define	WSM_64MB (0x03fUL << 20)
+#	define	WSM_128MB(0x07fUL << 20)
+#	define	WSM_256MB(0x0ffUL << 20)
+#	define	WSM_512MB(0x1ffUL << 20)
+#	define	WSM_1GB  (0x3ffUL << 20)
+#	define	WSM_2GB  (0x7ffUL << 20)
+/*#	define	WSM_4GB  N/A		monster window / DAC only */
+
 #	define	WSM_AM(r)TSFIELDBB((r), 31, 20)
 #	define	WSM_LEN(r)   ((WSM_AM(r) + 1) << 20)
 



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

2021-07-16 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Jul 17 00:30:39 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: cia_dma.c ciavar.h

Log Message:
Back in rev 1.21, mhitch@ fixed an issue with his 1.5GB RAM PWS 500au
by using a fall-back to the ISA DMA window if DMA was out of range for
the 1G @ 1G PCI DMA window.  Alas, the ISA DMA window is pretty small
(8M @ 8M), and it's possible to starve it with PCI devices that might
have, for example, large control data structures there.

So, instead, if the system has more than 1G of RAM, use Window 3
(previously unused) as a SGMAP window 1G @ 3G, and set that as the
fall-back if the direct-mapped window fails.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/alpha/pci/cia_dma.c
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/alpha/pci/ciavar.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/alpha/pci/cia_dma.c
diff -u src/sys/arch/alpha/pci/cia_dma.c:1.34 src/sys/arch/alpha/pci/cia_dma.c:1.35
--- src/sys/arch/alpha/pci/cia_dma.c:1.34	Sun Jul  4 22:42:36 2021
+++ src/sys/arch/alpha/pci/cia_dma.c	Sat Jul 17 00:30:39 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: cia_dma.c,v 1.34 2021/07/04 22:42:36 thorpej Exp $ */
+/* $NetBSD: cia_dma.c,v 1.35 2021/07/17 00:30:39 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: cia_dma.c,v 1.34 2021/07/04 22:42:36 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cia_dma.c,v 1.35 2021/07/17 00:30:39 thorpej Exp $");
 
 #include 
 #include 
@@ -42,6 +42,8 @@ __KERNEL_RCSID(0, "$NetBSD: cia_dma.c,v 
 #define _ALPHA_BUS_DMA_PRIVATE
 #include 
 
+#include 
+
 #include 
 #include 
 #include 
@@ -69,14 +71,20 @@ static void	cia_bus_dmamap_unload_sgmap(
 /*
  * Direct-mapped window: 1G at 1G
  */
-#define	CIA_DIRECT_MAPPED_BASE	(1*1024*1024*1024)
-#define	CIA_DIRECT_MAPPED_SIZE	(1*1024*1024*1024)
+#define	CIA_DIRECT_MAPPED_BASE	(1UL*1024*1024*1024)
+#define	CIA_DIRECT_MAPPED_SIZE	(1UL*1024*1024*1024)
+
+/*
+ * SGMAP window for ISA: 8M at 8M
+ */
+#define	CIA_SGMAP_MAPPED_LO_BASE (8UL*1024*1024)
+#define	CIA_SGMAP_MAPPED_LO_SIZE (8UL*1024*1024)
 
 /*
- * SGMAP window: 8M at 8M
+ * SGMAP window for PCI: 1G at 3G
  */
-#define	CIA_SGMAP_MAPPED_BASE	(8*1024*1024)
-#define	CIA_SGMAP_MAPPED_SIZE	(8*1024*1024)
+#define	CIA_SGMAP_MAPPED_HI_BASE (3UL*1024*1024*1024)
+#define	CIA_SGMAP_MAPPED_HI_SIZE (1UL*1024*1024*1024)
 
 /* ALCOR/ALGOR2/PYXIS have a 256-byte out-bound DMA prefetch threshold. */
 #define	CIA_SGMAP_PFTHRESH	256
@@ -89,14 +97,49 @@ static void	(*cia_tlb_invalidate_fn)(voi
 #define	CIA_TLB_INVALIDATE()	(*cia_tlb_invalidate_fn)()
 
 struct alpha_sgmap cia_pyxis_bug_sgmap;
-#define	CIA_PYXIS_BUG_BASE	(128*1024*1024)
-#define	CIA_PYXIS_BUG_SIZE	(2*1024*1024)
+#define	CIA_PYXIS_BUG_BASE	(128UL*1024*1024)
+#define	CIA_PYXIS_BUG_SIZE	(2UL*1024*1024)
 
 void
 cia_dma_init(struct cia_config *ccp)
 {
 	bus_addr_t tbase;
 	bus_dma_tag_t t;
+	bus_dma_tag_t t_sg_hi = NULL;
+
+	/*
+	 * If we have more than 1GB of RAM, then set up an sgmap-mapped
+	 * DMA window for PCI.  This is better than using the ISA window,
+	 * which is pretty small and PCI devices could starve it.
+	 *
+	 * N.B. avail_end is "last-usable PFN + 1".
+	 */
+	if (uvm_physseg_get_avail_end(uvm_physseg_get_last()) >
+	atop(CIA_DIRECT_MAPPED_SIZE)) {
+		t = t_sg_hi = >cc_dmat_sgmap_hi;
+		t->_cookie = ccp;
+		t->_wbase = CIA_SGMAP_MAPPED_HI_BASE;
+		t->_wsize = CIA_SGMAP_MAPPED_HI_SIZE;
+		t->_next_window = NULL;
+		t->_boundary = 0;
+		t->_sgmap = >cc_sgmap_hi;
+		t->_pfthresh = CIA_SGMAP_PFTHRESH;
+		t->_get_tag = cia_dma_get_tag;
+		t->_dmamap_create = alpha_sgmap_dmamap_create;
+		t->_dmamap_destroy = alpha_sgmap_dmamap_destroy;
+		t->_dmamap_load = cia_bus_dmamap_load_sgmap;
+		t->_dmamap_load_mbuf = cia_bus_dmamap_load_mbuf_sgmap;
+		t->_dmamap_load_uio = cia_bus_dmamap_load_uio_sgmap;
+		t->_dmamap_load_raw = cia_bus_dmamap_load_raw_sgmap;
+		t->_dmamap_unload = cia_bus_dmamap_unload_sgmap;
+		t->_dmamap_sync = _bus_dmamap_sync;
+
+		t->_dmamem_alloc = _bus_dmamem_alloc;
+		t->_dmamem_free = _bus_dmamem_free;
+		t->_dmamem_map = _bus_dmamem_map;
+		t->_dmamem_unmap = _bus_dmamem_unmap;
+		t->_dmamem_mmap = _bus_dmamem_mmap;
+	}
 
 	/*
 	 * Initialize the DMA tag used for direct-mapped DMA.
@@ -105,7 +148,7 @@ cia_dma_init(struct cia_config *ccp)
 	t->_cookie = ccp;
 	t->_wbase = CIA_DIRECT_MAPPED_BASE;
 	t->_wsize = CIA_DIRECT_MAPPED_SIZE;
-	t->_next_window = >cc_dmat_sgmap;
+	t->_next_window = t_sg_hi;
 	t->_boundary = 0;
 	t->_sgmap = NULL;
 	t->_get_tag = cia_dma_get_tag;
@@ -125,15 +168,15 @@ cia_dma_init(struct cia_config *ccp)
 	t->_dmamem_mmap = _bus_dmamem_mmap;
 
 	/*
-	 * Initialize the DMA tag used for sgmap-mapped DMA.
+	 * Initialize the DMA tag used for sgmap-mapped ISA DMA.
 	 */
-	t = 

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

2021-07-16 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jul 16 19:13:21 UTC 2021

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

Log Message:
Instrument success/faulure of phyisically contiguous uarea allocation.


To generate a diff of this commit:
cvs rdiff -u -r1.120 -r1.121 src/sys/arch/alpha/alpha/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/alpha/alpha/vm_machdep.c
diff -u src/sys/arch/alpha/alpha/vm_machdep.c:1.120 src/sys/arch/alpha/alpha/vm_machdep.c:1.121
--- src/sys/arch/alpha/alpha/vm_machdep.c:1.120	Tue Jul  6 12:20:52 2021
+++ src/sys/arch/alpha/alpha/vm_machdep.c	Fri Jul 16 19:13:21 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: vm_machdep.c,v 1.120 2021/07/06 12:20:52 thorpej Exp $ */
+/* $NetBSD: vm_machdep.c,v 1.121 2021/07/16 19:13:21 thorpej Exp $ */
 
 /*
  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
@@ -29,7 +29,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.120 2021/07/06 12:20:52 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.121 2021/07/16 19:13:21 thorpej Exp $");
 
 #include 
 #include 
@@ -248,6 +248,14 @@ vunmapbuf(struct buf *bp, vsize_t len)
 }
 
 #ifdef __HAVE_CPU_UAREA_ROUTINES
+static struct evcnt uarea_direct_success =
+EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "uarea direct", "success");
+static struct evcnt uarea_direct_failure =
+EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "uarea direct", "failure");
+
+EVCNT_ATTACH_STATIC(uarea_direct_success);
+EVCNT_ATTACH_STATIC(uarea_direct_failure);
+
 void *
 cpu_uarea_alloc(bool system)
 {
@@ -259,8 +267,11 @@ cpu_uarea_alloc(bool system)
 	 * direct-mapped.
 	 */
 	error = uvm_pglistalloc(USPACE, 0, ptoa(physmem), 0, 0, , 1, 1);
-	if (error)
+	if (error) {
+		atomic_inc_ulong(_direct_failure.ev_count);
 		return NULL;
+	}
+	atomic_inc_ulong(_direct_success.ev_count);
 
 	/*
 	 * Get the physical address from the first page.



CVS commit: src/sys/arch/alpha

2021-07-16 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jul 16 19:02:22 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: interrupt.c pmap.c
src/sys/arch/alpha/include: intr.h

Log Message:
The Alpha AXP Architecture Reference Manual is explcit that the only
valid bits in the PSL are the IPL and USER bits, the latter of which
will always be clear when in the kernel, and that all other bits MBZ.
So, when reading the PSL to get the current IPL, don't bother masking
with ALPHA_PSL_IPL_MASK.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/sys/arch/alpha/alpha/interrupt.c
cvs rdiff -u -r1.297 -r1.298 src/sys/arch/alpha/alpha/pmap.c
cvs rdiff -u -r1.84 -r1.85 src/sys/arch/alpha/include/intr.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/alpha/alpha/interrupt.c
diff -u src/sys/arch/alpha/alpha/interrupt.c:1.98 src/sys/arch/alpha/alpha/interrupt.c:1.99
--- src/sys/arch/alpha/alpha/interrupt.c:1.98	Sun Jul  4 22:42:35 2021
+++ src/sys/arch/alpha/alpha/interrupt.c	Fri Jul 16 19:02:22 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: interrupt.c,v 1.98 2021/07/04 22:42:35 thorpej Exp $ */
+/* $NetBSD: interrupt.c,v 1.99 2021/07/16 19:02:22 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: interrupt.c,v 1.98 2021/07/04 22:42:35 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: interrupt.c,v 1.99 2021/07/16 19:02:22 thorpej Exp $");
 
 #include 
 #include 
@@ -502,7 +502,7 @@ void
 softint_trigger(uintptr_t const machdep)
 {
 	/* No need for an atomic; called at splhigh(). */
-	KASSERT((alpha_pal_rdps() & ALPHA_PSL_IPL_MASK) == ALPHA_PSL_IPL_HIGH);
+	KASSERT(alpha_pal_rdps() == ALPHA_PSL_IPL_HIGH);
 	curcpu()->ci_ssir |= machdep;
 }
 
@@ -534,8 +534,7 @@ softint_init_md(lwp_t * const l, u_int c
 		ci->ci_ssir &= ~SOFTINT_##level##_MASK;			\
 		alpha_softint_switchto(l, IPL_SOFT##level,		\
 		ci->ci_silwps[SOFTINT_##level]);			\
-		KASSERT((alpha_pal_rdps() & ALPHA_PSL_IPL_MASK) ==	\
-		ALPHA_PSL_IPL_HIGH);\
+		KASSERT(alpha_pal_rdps() == ALPHA_PSL_IPL_HIGH);	\
 		continue;		\
 	}\
 
@@ -553,7 +552,7 @@ alpha_softint_dispatch(int const ipl)
 	unsigned long ssir;
 	const unsigned long eligible = SOFTINTS_ELIGIBLE(ipl);
 
-	KASSERT((alpha_pal_rdps() & ALPHA_PSL_IPL_MASK) == ALPHA_PSL_IPL_HIGH);
+	KASSERT(alpha_pal_rdps() == ALPHA_PSL_IPL_HIGH);
 
 	for (;;) {
 		ssir = ci->ci_ssir & eligible;

Index: src/sys/arch/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.297 src/sys/arch/alpha/alpha/pmap.c:1.298
--- src/sys/arch/alpha/alpha/pmap.c:1.297	Sat Jul 10 20:22:37 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Fri Jul 16 19:02:22 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.297 2021/07/10 20:22:37 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.298 2021/07/16 19:02:22 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.297 2021/07/10 20:22:37 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.298 2021/07/16 19:02:22 thorpej Exp $");
 
 #include 
 #include 
@@ -1027,7 +1027,7 @@ pmap_tlb_shootnow(const struct pmap_tlb_
 	 * interrupts and disable preemption.  It is critically important
 	 * that IPIs not be blocked in this routine.
 	 */
-	KASSERT((alpha_pal_rdps() & ALPHA_PSL_IPL_MASK) < ALPHA_PSL_IPL_CLOCK);
+	KASSERT(alpha_pal_rdps() < ALPHA_PSL_IPL_CLOCK);
 	mutex_spin_enter(_lock);
 	tlb_evcnt.ev_count++;
 
@@ -1121,7 +1121,7 @@ pmap_tlb_shootnow(const struct pmap_tlb_
 tlb_pending);
 printf("TLB CONTEXT = %p\n", tlb_context);
 printf("TLB LOCAL IPL = %lu\n",
-alpha_pal_rdps() & ALPHA_PSL_IPL_MASK);
+alpha_pal_rdps());
 panic("pmap_tlb_shootnow");
 			}
 		}

Index: src/sys/arch/alpha/include/intr.h
diff -u src/sys/arch/alpha/include/intr.h:1.84 src/sys/arch/alpha/include/intr.h:1.85
--- src/sys/arch/alpha/include/intr.h:1.84	Sun Jul  4 22:36:43 2021
+++ src/sys/arch/alpha/include/intr.h	Fri Jul 16 19:02:22 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: intr.h,v 1.84 2021/07/04 22:36:43 thorpej Exp $ */
+/* $NetBSD: intr.h,v 1.85 2021/07/16 19:02:22 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2000, 2001, 2002 The NetBSD Foundation, Inc.
@@ -157,7 +157,7 @@ void	spllower(int);
 static __inline int
 _splraise(int s)
 {
-	int cur = alpha_pal_rdps() & ALPHA_PSL_IPL_MASK;
+	int cur = (int)alpha_pal_rdps();
 	return (s > cur ? (int)alpha_pal_swpipl(s) : cur);
 }
 



CVS commit: src/sys/arch/alpha

2021-07-16 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jul 16 18:50:19 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: dec_alphabook1.c dec_axppci_33.c dec_eb66.c
src/sys/arch/alpha/pci: lca.c lcavar.h

Log Message:
On LCA45 systems, look at the memory controller's Bcache configuration
to initialize uvmexp.ncolors rather than hard-coding a value per model
(some models can have more than one configuration).


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/alpha/alpha/dec_alphabook1.c
cvs rdiff -u -r1.67 -r1.68 src/sys/arch/alpha/alpha/dec_axppci_33.c
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/alpha/alpha/dec_eb66.c
cvs rdiff -u -r1.55 -r1.56 src/sys/arch/alpha/pci/lca.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/alpha/pci/lcavar.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/alpha/alpha/dec_alphabook1.c
diff -u src/sys/arch/alpha/alpha/dec_alphabook1.c:1.27 src/sys/arch/alpha/alpha/dec_alphabook1.c:1.28
--- src/sys/arch/alpha/alpha/dec_alphabook1.c:1.27	Sat Oct 13 17:58:54 2012
+++ src/sys/arch/alpha/alpha/dec_alphabook1.c	Fri Jul 16 18:50:19 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: dec_alphabook1.c,v 1.27 2012/10/13 17:58:54 jdc Exp $ */
+/* $NetBSD: dec_alphabook1.c,v 1.28 2021/07/16 18:50:19 thorpej Exp $ */
 
 /*
  * Copyright (c) 1995, 1996, 1997 Carnegie-Mellon University.
@@ -34,7 +34,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: dec_alphabook1.c,v 1.27 2012/10/13 17:58:54 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dec_alphabook1.c,v 1.28 2021/07/16 18:50:19 thorpej Exp $");
 
 #include 
 #include 
@@ -107,6 +107,8 @@ dec_alphabook1_init(void)
 	platform.iobus = "lca";
 	platform.cons_init = dec_alphabook1_cons_init;
 	platform.device_register = dec_alphabook1_device_register;
+
+	lca_probe_bcache();
 }
 
 static void

Index: src/sys/arch/alpha/alpha/dec_axppci_33.c
diff -u src/sys/arch/alpha/alpha/dec_axppci_33.c:1.67 src/sys/arch/alpha/alpha/dec_axppci_33.c:1.68
--- src/sys/arch/alpha/alpha/dec_axppci_33.c:1.67	Sat Oct 13 17:58:54 2012
+++ src/sys/arch/alpha/alpha/dec_axppci_33.c	Fri Jul 16 18:50:19 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: dec_axppci_33.c,v 1.67 2012/10/13 17:58:54 jdc Exp $ */
+/* $NetBSD: dec_axppci_33.c,v 1.68 2021/07/16 18:50:19 thorpej Exp $ */
 
 /*
  * Copyright (c) 1995, 1996, 1997 Carnegie-Mellon University.
@@ -34,7 +34,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: dec_axppci_33.c,v 1.67 2012/10/13 17:58:54 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dec_axppci_33.c,v 1.68 2021/07/16 18:50:19 thorpej Exp $");
 
 #include 
 #include 
@@ -43,8 +43,6 @@ __KERNEL_RCSID(0, "$NetBSD: dec_axppci_3
 #include 
 #include 
 
-#include 
-
 #include 
 #include 
 #include 
@@ -156,13 +154,7 @@ dec_axppci_33_init(void)
 
 	/* Leave nsio mapped to catch any accidental port space collisions  */
 
-	/*
-	 * AXPpci33 systems have either 0, 256K, or 1M secondary
-	 * caches.  Default to middle-of-the-road.
-	 *
-	 * XXX Dynamically size it!
-	 */
-	uvmexp.ncolors = atop(256 * 1024);
+	lca_probe_bcache();
 }
 
 static void

Index: src/sys/arch/alpha/alpha/dec_eb66.c
diff -u src/sys/arch/alpha/alpha/dec_eb66.c:1.28 src/sys/arch/alpha/alpha/dec_eb66.c:1.29
--- src/sys/arch/alpha/alpha/dec_eb66.c:1.28	Sat Oct 13 17:58:54 2012
+++ src/sys/arch/alpha/alpha/dec_eb66.c	Fri Jul 16 18:50:19 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: dec_eb66.c,v 1.28 2012/10/13 17:58:54 jdc Exp $ */
+/* $NetBSD: dec_eb66.c,v 1.29 2021/07/16 18:50:19 thorpej Exp $ */
 
 /*
  * Copyright (c) 1995, 1996, 1997 Carnegie-Mellon University.
@@ -34,7 +34,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: dec_eb66.c,v 1.28 2012/10/13 17:58:54 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dec_eb66.c,v 1.29 2021/07/16 18:50:19 thorpej Exp $");
 
 #include 
 #include 
@@ -43,8 +43,6 @@ __KERNEL_RCSID(0, "$NetBSD: dec_eb66.c,v
 #include 
 #include 
 
-#include 
-
 #include 
 #include 
 #include 
@@ -110,10 +108,7 @@ dec_eb66_init(void)
 	platform.cons_init = dec_eb66_cons_init;
 	platform.device_register = dec_eb66_device_register;
 
-	/*
-	 * EB66 systems have 1M secondary caches.
-	 */
-	uvmexp.ncolors = atop(1 * 1024 * 1024);
+	lca_probe_bcache();
 }
 
 static void

Index: src/sys/arch/alpha/pci/lca.c
diff -u src/sys/arch/alpha/pci/lca.c:1.55 src/sys/arch/alpha/pci/lca.c:1.56
--- src/sys/arch/alpha/pci/lca.c:1.55	Sun Jul  4 22:42:36 2021
+++ src/sys/arch/alpha/pci/lca.c	Fri Jul 16 18:50:19 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lca.c,v 1.55 2021/07/04 22:42:36 thorpej Exp $ */
+/* $NetBSD: lca.c,v 1.56 2021/07/16 18:50:19 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -58,13 +58,15 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: lca.c,v 1.55 2021/07/04 22:42:36 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lca.c,v 1.56 

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

2021-07-16 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jul 16 17:09:33 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: lcareg.h

Log Message:
Define the memory controller registers, and contents for the Cache
register.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/alpha/pci/lcareg.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/alpha/pci/lcareg.h
diff -u src/sys/arch/alpha/pci/lcareg.h:1.9 src/sys/arch/alpha/pci/lcareg.h:1.10
--- src/sys/arch/alpha/pci/lcareg.h:1.9	Mon Feb  6 02:14:14 2012
+++ src/sys/arch/alpha/pci/lcareg.h	Fri Jul 16 17:09:33 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lcareg.h,v 1.9 2012/02/06 02:14:14 matt Exp $ */
+/* $NetBSD: lcareg.h,v 1.10 2021/07/16 17:09:33 thorpej Exp $ */
 
 /*
  * Copyright (c) 1995 Carnegie-Mellon University.
@@ -37,12 +37,52 @@
 /*
  * Base addresses
  */
+#define	LCA_MEMC_BASE	0x12000L		/* LCA memory controller regs */
 #define LCA_IOC_BASE	0x18000L		/* LCA IOC Regs */
 #define LCA_PCI_SIO	0x1c000L		/* PCI Sp. I/O Space */
 #define LCA_PCI_CONF	0x1e000L		/* PCI Conf. Space */
 #define LCA_PCI_SPARSE	0x2L		/* PCI Sparse Space */
 #define LCA_PCI_DENSE	0x3L		/* PCI Dense Space */
 
+#define LCA_MEMC_BCR0	(LCA_MEMC_BASE + 0x00)	/* Bank Configuration 0 */
+#define LCA_MEMC_BCR1	(LCA_MEMC_BASE + 0x08)	/* Bank Configuration 1 */
+#define LCA_MEMC_BCR2	(LCA_MEMC_BASE + 0x10)	/* Bank Configuration 2 */
+#define LCA_MEMC_BCR3	(LCA_MEMC_BASE + 0x18)	/* Bank Configuration 3 */
+#define LCA_MEMC_BMR0	(LCA_MEMC_BASE + 0x20)	/* Bank Address Mask 0 */
+#define LCA_MEMC_BMR1	(LCA_MEMC_BASE + 0x28)	/* Bank Address Mask 1 */
+#define LCA_MEMC_BMR2	(LCA_MEMC_BASE + 0x30)	/* Bank Address Mask 2 */
+#define LCA_MEMC_BMR3	(LCA_MEMC_BASE + 0x38)	/* Bank Address Mask 3 */
+#define LCA_MEMC_BTR0	(LCA_MEMC_BASE + 0x40)	/* Bank Timing 0 */
+#define LCA_MEMC_BTR1	(LCA_MEMC_BASE + 0x48)	/* Bank Timing 1 */
+#define LCA_MEMC_BTR2	(LCA_MEMC_BASE + 0x50)	/* Bank Timing 2 */
+#define LCA_MEMC_BTR3	(LCA_MEMC_BASE + 0x58)	/* Bank Timing 3 */
+#define LCA_MEMC_GTR	(LCA_MEMC_BASE + 0x60)	/* Global Timing */
+#define LCA_MEMC_ESR	(LCA_MEMC_BASE + 0x68)	/* Error Status */
+#define LCA_MEMC_EAR	(LCA_MEMC_BASE + 0x70)	/* Error Address */
+#define LCA_MEMC_CAR	(LCA_MEMC_BASE + 0x78)	/* Cache */
+#define LCA_MEMC_VGR	(LCA_MEMC_BASE + 0x80)	/* Video and Graphics Control */
+#define LCA_MEMC_PLM	(LCA_MEMC_BASE + 0x88)	/* Plane mask */
+#define LCA_MEMC_FOR	(LCA_MEMC_BASE + 0x90)	/* Foreground */
+
+#define MEMC_CAR_BCE	__BIT(0)	/* Bcache enable */
+#define MEMC_CAR_ETP	__BIT(2)	/* Enable tag parity check */
+#define MEMC_CAR_WWP	__BIT(3)	/* Write wrong tag parity */
+#define MEMC_CAR_ECE	__BIT(4)	/* Enable Bcache ECC */
+#define MEMC_CAR_BCS	__BITS(5,7)	/* Bcache size */
+#define MEMC_CAR_RCC	__BITS(8,10)	/* Read Cycle Count */
+#define MEMC_CAR_WCC	__BITS(11,13)	/* Write Cycle Count */
+#define MEMC_CAR_WHD	__BIT(14)	/* Write Hold Time */
+#define MEMC_CAR_PWR	__BIT(15)	/* Power Saving */
+#define MEMC_CAR_TAG	__BITS(16,30)	/* latched Bcache tag value */
+#define MEMC_CAR_HIT	__BIT(31)	/* Bcache hit */
+
+#define BCS_64K		0
+#define BCS_128K	1
+#define BCS_256K	2
+#define BCS_512K	3
+#define BCS_1M		4
+#define BCS_2M		5
+
 #define LCA_IOC_HAE	LCA_IOC_BASE		/* Host Address Ext. (64) */
 #define	IOC_HAE_ADDREXT	0xf800UL
 #define	IOC_HAE_RSVSD	0x07ffUL



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

2021-07-14 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Thu Jul 15 01:43:54 UTC 2021

Modified Files:
src/sys/arch/alpha/jensenio: jensenio_intr.c

Log Message:
- Use defined constants for PIC registers, not magic numbers (XXX except
  for the ELCR register; need a new header file).
- In jensenio_specific_eoi(), actually issue a specific EOI (the code
  was erroneously issuing a non-specific EOI).
- In jensenio_pic_init(), ensure all IRQs are initialized to EDGE trigger.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/alpha/jensenio/jensenio_intr.c

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

Modified files:

Index: src/sys/arch/alpha/jensenio/jensenio_intr.c
diff -u src/sys/arch/alpha/jensenio/jensenio_intr.c:1.17 src/sys/arch/alpha/jensenio/jensenio_intr.c:1.18
--- src/sys/arch/alpha/jensenio/jensenio_intr.c:1.17	Sun Jul  4 22:42:35 2021
+++ src/sys/arch/alpha/jensenio/jensenio_intr.c	Thu Jul 15 01:43:54 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: jensenio_intr.c,v 1.17 2021/07/04 22:42:35 thorpej Exp $ */
+/* $NetBSD: jensenio_intr.c,v 1.18 2021/07/15 01:43:54 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: jensenio_intr.c,v 1.17 2021/07/04 22:42:35 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: jensenio_intr.c,v 1.18 2021/07/15 01:43:54 thorpej Exp $");
 
 #include 
 #include 
@@ -44,6 +44,8 @@ __KERNEL_RCSID(0, "$NetBSD: jensenio_int
 
 #include 
 
+#include 
+
 #include 
 
 #include 
@@ -97,11 +99,12 @@ static inline void
 jensenio_specific_eoi(int irq)
 {
 
-	if (irq > 7)
-		bus_space_write_1(pic_iot, pic_ioh[1],
-		0, 0x20 | (irq & 0x07));
-	bus_space_write_1(pic_iot, pic_ioh[0],
-	0, 0x20 | (irq > 7 ? 2 : irq));
+	if (irq > 7) {
+		bus_space_write_1(pic_iot, pic_ioh[1], PIC_OCW2,
+		OCW2_EOI | OCW2_SL | (irq & 0x07));
+	}
+	bus_space_write_1(pic_iot, pic_ioh[0], PIC_OCW2,
+	OCW2_EOI | OCW2_SL | (irq > 7 ? 2 : irq));
 }
 
 void
@@ -341,12 +344,12 @@ jensenio_enable_intr(int irq, int onoff)
 	pic = irq >> 3;
 	bit = 1 << (irq & 0x7);
 
-	mask = bus_space_read_1(pic_iot, pic_ioh[pic], 1);
+	mask = bus_space_read_1(pic_iot, pic_ioh[pic], PIC_OCW1);
 	if (onoff)
 		mask &= ~bit;
 	else
 		mask |= bit;
-	bus_space_write_1(pic_iot, pic_ioh[pic], 1, mask);
+	bus_space_write_1(pic_iot, pic_ioh[pic], PIC_OCW1, mask);
 }
 
 void
@@ -378,12 +381,15 @@ jensenio_pic_init(void)
 	for (pic = 0; pic < 2; pic++) {
 		if (bus_space_map(pic_iot, picaddr[pic], 2, 0, _ioh[pic]))
 			panic("jensenio_init_intr: unable to map PIC %d", pic);
-		bus_space_write_1(pic_iot, pic_ioh[pic], 1, 0xff);
+		bus_space_write_1(pic_iot, pic_ioh[pic], PIC_OCW1, 0xff);
 	}
 
 	/*
-	 * Map the ELCR registers.
+	 * Map the ELCR registers and initialize all interrupts to EDGE
+	 * trigger.
 	 */
 	if (bus_space_map(pic_iot, 0x4d0, 2, 0, _elcr_ioh))
 		panic("jensenio_init_intr: unable to map ELCR registers");
+	bus_space_write_1(pic_iot, pic_elcr_ioh, 0, 0);
+	bus_space_write_1(pic_iot, pic_elcr_ioh, 1, 0);
 }



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

2021-07-14 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Thu Jul 15 01:29:23 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: sio_pic.c

Log Message:
- Use defined constants for PIC registers, not magic numbers.
- Inline specific_eoi().

NFC.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/alpha/pci/sio_pic.c

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

Modified files:

Index: src/sys/arch/alpha/pci/sio_pic.c
diff -u src/sys/arch/alpha/pci/sio_pic.c:1.52 src/sys/arch/alpha/pci/sio_pic.c:1.53
--- src/sys/arch/alpha/pci/sio_pic.c:1.52	Sun Jul  4 22:42:36 2021
+++ src/sys/arch/alpha/pci/sio_pic.c	Thu Jul 15 01:29:23 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sio_pic.c,v 1.52 2021/07/04 22:42:36 thorpej Exp $ */
+/* $NetBSD: sio_pic.c,v 1.53 2021/07/15 01:29:23 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 2000, 2020 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: sio_pic.c,v 1.52 2021/07/04 22:42:36 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sio_pic.c,v 1.53 2021/07/15 01:29:23 thorpej Exp $");
 
 #include 
 #include 
@@ -78,6 +78,8 @@ __KERNEL_RCSID(0, "$NetBSD: sio_pic.c,v 
 #include 
 #include 
 
+#include 
+
 #include 
 #include 
 
@@ -150,7 +152,7 @@ i82378_setup_elcr(void)
 	 * fall-back in case nothing else matches.
 	 */
 
-	rv = bus_space_map(sio_iot, 0x4d0, 2, 0, _ioh_elcr);
+	rv = bus_space_map(sio_iot, SIO_REG_ICU1ELC, 2, 0, _ioh_elcr);
 
 	if (rv == 0) {
 		sio_read_elcr = i82378_read_elcr;
@@ -270,6 +272,17 @@ static int (*const sio_elcr_setup_funcs[
 
 / Shared SIO/Cypress functions /
 
+static inline void
+specific_eoi(int irq)
+{
+	if (irq > 7) {
+		bus_space_write_1(sio_iot, sio_ioh_icu2, PIC_OCW2,
+		OCW2_EOI | OCW2_SL | (irq & 0x07));	/* XXX */
+	}
+	bus_space_write_1(sio_iot, sio_ioh_icu1, PIC_OCW2,
+	OCW2_EOI | OCW2_SL | (irq > 7 ? 2 : irq));
+}
+
 static void
 sio_setirqstat(int irq, int enabled, int type)
 {
@@ -284,8 +297,8 @@ sio_setirqstat(int irq, int enabled, int
 	icu = irq / 8;
 	bit = irq % 8;
 
-	ocw1[0] = bus_space_read_1(sio_iot, sio_ioh_icu1, 1);
-	ocw1[1] = bus_space_read_1(sio_iot, sio_ioh_icu2, 1);
+	ocw1[0] = bus_space_read_1(sio_iot, sio_ioh_icu1, PIC_OCW1);
+	ocw1[1] = bus_space_read_1(sio_iot, sio_ioh_icu2, PIC_OCW1);
 	elcr[0] = (*sio_read_elcr)(0);/* XXX */
 	elcr[1] = (*sio_read_elcr)(1);/* XXX */
 
@@ -730,12 +743,3 @@ sio_intr_alloc(void *v, int mask, int ty
 
 	return (0);
 }
-
-static void
-specific_eoi(int irq)
-{
-	if (irq > 7)
-		bus_space_write_1(sio_iot,
-		sio_ioh_icu2, 0, 0x60 | (irq & 0x07));	/* XXX */
-	bus_space_write_1(sio_iot, sio_ioh_icu1, 0, 0x60 | (irq > 7 ? 2 : irq));
-}



CVS commit: src/sys/arch/alpha

2021-07-13 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jul 14 02:18:10 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: lock_stubs.s
src/sys/arch/alpha/include: mutex.h

Log Message:
Disable the mutex_spin_{enter,exit}() fast-path stubs while I investigate
some an odd IPL-related panic that seems to be related (that I can fairly
reliabily reproduce on an LCA45).


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/alpha/alpha/lock_stubs.s
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/alpha/include/mutex.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/alpha/alpha/lock_stubs.s
diff -u src/sys/arch/alpha/alpha/lock_stubs.s:1.8 src/sys/arch/alpha/alpha/lock_stubs.s:1.9
--- src/sys/arch/alpha/alpha/lock_stubs.s:1.8	Tue Jul 13 13:58:30 2021
+++ src/sys/arch/alpha/alpha/lock_stubs.s	Wed Jul 14 02:18:10 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lock_stubs.s,v 1.8 2021/07/13 13:58:30 thorpej Exp $	*/
+/*	$NetBSD: lock_stubs.s,v 1.9 2021/07/14 02:18:10 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2021 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: lock_stubs.s,v 1.8 2021/07/13 13:58:30 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lock_stubs.s,v 1.9 2021/07/14 02:18:10 thorpej Exp $");
 
 #include "assym.h"
 
@@ -114,6 +114,7 @@ LEAF(mutex_exit, 1)
 	br	1b
 	END(mutex_exit)
 
+#if 0 /* XXX disabled for now XXX */
 /*
  * void mutex_spin_enter(kmutex_t *mtx);
  */
@@ -227,6 +228,7 @@ LEAF(mutex_spin_exit, 1)
 1:
 	RET
 	END(mutex_spin_exit)
+#endif /* XXX disabled for now XXX */
 
 /*
  * void rw_enter(krwlock_t *rwl, krw_t op);
@@ -399,8 +401,10 @@ lock_stub_patch_table:
 #if !defined(LOCKDEBUG)
 	.quad	.L_mutex_enter_mb_1
 	.quad	.L_mutex_exit_mb_1
+#if 0 /* XXX disabled for now XXX */
 	.quad	.L_mutex_spin_enter_mb_1
 	.quad	.L_mutex_spin_exit_mb_1
+#endif /* XXX disabled for now XXX */
 	.quad	.L_rw_enter_mb_1
 	.quad	.L_rw_enter_mb_2
 	.quad	.L_rw_tryenter_mb_1

Index: src/sys/arch/alpha/include/mutex.h
diff -u src/sys/arch/alpha/include/mutex.h:1.9 src/sys/arch/alpha/include/mutex.h:1.10
--- src/sys/arch/alpha/include/mutex.h:1.9	Mon Jul 12 15:21:51 2021
+++ src/sys/arch/alpha/include/mutex.h	Wed Jul 14 02:18:10 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: mutex.h,v 1.9 2021/07/12 15:21:51 thorpej Exp $	*/
+/*	$NetBSD: mutex.h,v 1.10 2021/07/14 02:18:10 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@ struct kmutex {
 
 #define	__HAVE_SIMPLE_MUTEXES		1
 #define	__HAVE_MUTEX_STUBS		1
-#define	__HAVE_SPIN_MUTEX_STUBS		1
+/* XXX #define	__HAVE_SPIN_MUTEX_STUBS		1 XXX */
 
 #define	MUTEX_CAS(p, o, n)		_lock_cas((p), (o), (n))
 



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

2021-07-13 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Tue Jul 13 13:58:30 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: lock_stubs.s

Log Message:
Fix non-MULTIPROCESSOR build (e.g. INSTALL kernel).


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/alpha/alpha/lock_stubs.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/alpha/alpha/lock_stubs.s
diff -u src/sys/arch/alpha/alpha/lock_stubs.s:1.7 src/sys/arch/alpha/alpha/lock_stubs.s:1.8
--- src/sys/arch/alpha/alpha/lock_stubs.s:1.7	Tue Jul 13 01:59:10 2021
+++ src/sys/arch/alpha/alpha/lock_stubs.s	Tue Jul 13 13:58:30 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lock_stubs.s,v 1.7 2021/07/13 01:59:10 thorpej Exp $	*/
+/*	$NetBSD: lock_stubs.s,v 1.8 2021/07/13 13:58:30 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2021 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: lock_stubs.s,v 1.7 2021/07/13 01:59:10 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lock_stubs.s,v 1.8 2021/07/13 13:58:30 thorpej Exp $");
 
 #include "assym.h"
 
@@ -45,7 +45,7 @@ __KERNEL_RCSID(0, "$NetBSD: lock_stubs.s
  */
 #define	MB(label)	label: unop
 #else
-#define	MB		/* nothing */
+#define	MB(label)	/* nothing */
 #endif
 
 /*



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

2021-07-12 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Tue Jul 13 01:59:10 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: lock_stubs.s patch.c

Log Message:
As with membar_producer() and membar_sync(), initialize the fast-path
lock stubs with "unop" isns where memory barriers need to be, and if
we detect a multiprocessor system, patch those locations with "mb" insns.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/alpha/alpha/lock_stubs.s \
src/sys/arch/alpha/alpha/patch.c

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

Modified files:

Index: src/sys/arch/alpha/alpha/lock_stubs.s
diff -u src/sys/arch/alpha/alpha/lock_stubs.s:1.6 src/sys/arch/alpha/alpha/lock_stubs.s:1.7
--- src/sys/arch/alpha/alpha/lock_stubs.s:1.6	Mon Jul 12 15:21:51 2021
+++ src/sys/arch/alpha/alpha/lock_stubs.s	Tue Jul 13 01:59:10 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lock_stubs.s,v 1.6 2021/07/12 15:21:51 thorpej Exp $	*/
+/*	$NetBSD: lock_stubs.s,v 1.7 2021/07/13 01:59:10 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2021 The NetBSD Foundation, Inc.
@@ -34,12 +34,16 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: lock_stubs.s,v 1.6 2021/07/12 15:21:51 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lock_stubs.s,v 1.7 2021/07/13 01:59:10 thorpej Exp $");
 
 #include "assym.h"
 
 #if defined(MULTIPROCESSOR)
-#define	MB		mb
+/*
+ * These 'unop' insns will be patched with 'mb' insns at run-time if
+ * the system has more than one processor.
+ */
+#define	MB(label)	label: unop
 #else
 #define	MB		/* nothing */
 #endif
@@ -55,11 +59,11 @@ LEAF(_lock_cas, 3)
 	beq	t1, 2f
 	stq_c	v0, 0(a0)
 	beq	v0, 3f
-	MB	
+	MB(.L__lock_cas_mb_1)
 	RET
 2:
 	mov	zero, v0
-	MB
+	MB(.L__lock_cas_mb_2)
 	RET
 3:
 	br	1b
@@ -79,7 +83,7 @@ LEAF(mutex_enter, 1)
 	bne	t2, 2f
 	stq_c	t1, 0(a0)
 	beq	t1, 3f
-	MB
+	MB(.L_mutex_enter_mb_1)
 	RET
 2:
 	lda	t12, mutex_vector_enter
@@ -93,7 +97,7 @@ LEAF(mutex_enter, 1)
  */
 LEAF(mutex_exit, 1)
 	LDGP(pv)
-	MB
+	MB(.L_mutex_exit_mb_1)
 	GET_CURLWP	/* Note: GET_CURLWP clobbers v0, t0, t8...t11. */
 	mov	zero, t3
 1:
@@ -179,7 +183,7 @@ LEAF(mutex_spin_enter, 1);
 	bne	t0, 2f			/* contended */
 	stl_c	t1, MUTEX_SIMPLELOCK(a1)
 	beq	t1, 2f			/* STL_C failed; consider contended */
-	MB
+	MB(.L_mutex_spin_enter_mb_1)
 	RET
 2:
 	mov	a1, a0			/* restore first argument */
@@ -192,7 +196,7 @@ LEAF(mutex_spin_enter, 1);
  */
 LEAF(mutex_spin_exit, 1)
 	LDGP(pv);
-	MB
+	MB(.L_mutex_spin_exit_mb_1)
 
 	/*
 	 * STEP 1: __cpu_simple_unlock(>mtx_lock)
@@ -247,7 +251,7 @@ LEAF(rw_enter, 2)
 	bne	t1, 4f		/* contended */
 	stq_c	t2, 0(a0)
 	beq	t2, 2f		/* STQ_C failed; retry */
-	MB
+	MB(.L_rw_enter_mb_1)
 	RET
 
 2:	br	1b
@@ -259,7 +263,7 @@ LEAF(rw_enter, 2)
 	bne	t0, 4f		/* contended */
 	stq_c	t2, 0(a0)
 	beq	t2, 4f		/* STQ_C failed; consider it contended */
-	MB
+	MB(.L_rw_enter_mb_2)
 	RET
 
 4:	lda	pv, rw_vector_enter
@@ -284,7 +288,7 @@ LEAF(rw_tryenter, 2)
 	bne	t1, 4f		/* contended */
 	stq_c	v0, 0(a0)
 	beq	v0, 2f		/* STQ_C failed; retry */
-	MB
+	MB(.L_rw_tryenter_mb_1)
 	RET			/* v0 contains non-zero LOCK_FLAG from STQ_C */
 
 2:	br	1b
@@ -302,7 +306,7 @@ LEAF(rw_tryenter, 2)
 	 * in the failure case because we expect it to be rare and it saves
 	 * a branch-not-taken instruction in the success case.
 	 */
-	MB
+	MB(.L_rw_tryenter_mb_2)
 	RET
 
 4:	mov	zero, v0	/* return 0 (failure) */
@@ -316,7 +320,7 @@ LEAF(rw_tryenter, 2)
  */
 LEAF(rw_exit, 1)
 	LDGP(pv)
-	MB
+	MB(.L_rw_exit_mb_1)
 
 	/*
 	 * Check for write-lock release, and get the owner/count field
@@ -381,3 +385,27 @@ LEAF(rw_exit, 1)
 	END(rw_exit)
 
 #endif	/* !LOCKDEBUG */
+
+#if defined(MULTIPROCESSOR)
+/*
+ * Table of locations to patch with MB instructions on multiprocessor
+ * systems.
+ */
+	.section ".rodata"
+	.globl	lock_stub_patch_table
+lock_stub_patch_table:
+	.quad	.L__lock_cas_mb_1
+	.quad	.L__lock_cas_mb_2
+#if !defined(LOCKDEBUG)
+	.quad	.L_mutex_enter_mb_1
+	.quad	.L_mutex_exit_mb_1
+	.quad	.L_mutex_spin_enter_mb_1
+	.quad	.L_mutex_spin_exit_mb_1
+	.quad	.L_rw_enter_mb_1
+	.quad	.L_rw_enter_mb_2
+	.quad	.L_rw_tryenter_mb_1
+	.quad	.L_rw_tryenter_mb_2
+	.quad	.L_rw_exit_mb_1
+#endif /* ! LOCKDEBUG */
+	.quad	0		/* NULL terminator */
+#endif /* MULTIPROCESSOR */
Index: src/sys/arch/alpha/alpha/patch.c
diff -u src/sys/arch/alpha/alpha/patch.c:1.6 src/sys/arch/alpha/alpha/patch.c:1.7
--- src/sys/arch/alpha/alpha/patch.c:1.6	Wed Jul  7 03:30:35 2021
+++ src/sys/arch/alpha/alpha/patch.c	Tue Jul 13 01:59:10 2021
@@ -1,7 +1,7 @@
-/*	$NetBSD: patch.c,v 1.6 2021/07/07 03:30:35 thorpej Exp $	*/
+/*	$NetBSD: patch.c,v 1.7 2021/07/13 01:59:10 thorpej Exp $	*/
 
 /*-
- * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * Copyright (c) 2007, 2021 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: patch.c,v 

CVS commit: src/sys/arch/alpha

2021-07-12 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon Jul 12 15:21:51 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: genassym.cf lock_stubs.s
src/sys/arch/alpha/include: mutex.h

Log Message:
Optimized fast-paths for mutex_spin_enter() and mutex_spin_exit().


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/alpha/alpha/genassym.cf
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/alpha/alpha/lock_stubs.s
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/alpha/include/mutex.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/alpha/alpha/genassym.cf
diff -u src/sys/arch/alpha/alpha/genassym.cf:1.29 src/sys/arch/alpha/alpha/genassym.cf:1.30
--- src/sys/arch/alpha/alpha/genassym.cf:1.29	Sun Jul 11 01:58:41 2021
+++ src/sys/arch/alpha/alpha/genassym.cf	Mon Jul 12 15:21:51 2021
@@ -1,4 +1,4 @@
-# $NetBSD: genassym.cf,v 1.29 2021/07/11 01:58:41 thorpej Exp $
+# $NetBSD: genassym.cf,v 1.30 2021/07/12 15:21:51 thorpej Exp $
 
 #
 # Copyright (c) 1982, 1990, 1993
@@ -67,6 +67,7 @@
 #
 
 quote #define __RWLOCK_PRIVATE
+quote #define __MUTEX_PRIVATE
 
 include 
 include 
@@ -75,6 +76,7 @@ include 
 include 
 include 
 include 
+include 
 include 
 
 include 
@@ -198,6 +200,7 @@ define	CPU_INFO_CURLWP		offsetof(struct 
 define	CPU_INFO_IDLE_LWP	offsetof(struct cpu_info, ci_data.cpu_idlelwp)
 define	CPU_INFO_SSIR		offsetof(struct cpu_info, ci_ssir)
 define	CPU_INFO_MTX_COUNT	offsetof(struct cpu_info, ci_mtx_count)
+define	CPU_INFO_MTX_OLDSPL	offsetof(struct cpu_info, ci_mtx_oldspl)
 define	CPU_INFO_SIZEOF		sizeof(struct cpu_info)
 
 # Bits in lock fields
@@ -205,3 +208,6 @@ define	RW_WRITE_WANTED		RW_WRITE_WANTED
 define	RW_WRITE_LOCKED		RW_WRITE_LOCKED
 define	RW_READ_INCR		RW_READ_INCR
 define	RW_READ_COUNT_SHIFT	RW_READ_COUNT_SHIFT
+define	MUTEX_IPL		offsetof(struct kmutex, mtx_ipl)
+define	MUTEX_SIMPLELOCK	offsetof(struct kmutex, mtx_lock)
+define	__SIMPLELOCK_LOCKED	__SIMPLELOCK_LOCKED

Index: src/sys/arch/alpha/alpha/lock_stubs.s
diff -u src/sys/arch/alpha/alpha/lock_stubs.s:1.5 src/sys/arch/alpha/alpha/lock_stubs.s:1.6
--- src/sys/arch/alpha/alpha/lock_stubs.s:1.5	Sun Jul 11 01:58:41 2021
+++ src/sys/arch/alpha/alpha/lock_stubs.s	Mon Jul 12 15:21:51 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lock_stubs.s,v 1.5 2021/07/11 01:58:41 thorpej Exp $	*/
+/*	$NetBSD: lock_stubs.s,v 1.6 2021/07/12 15:21:51 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2021 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: lock_stubs.s,v 1.5 2021/07/11 01:58:41 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lock_stubs.s,v 1.6 2021/07/12 15:21:51 thorpej Exp $");
 
 #include "assym.h"
 
@@ -111,6 +111,120 @@ LEAF(mutex_exit, 1)
 	END(mutex_exit)
 
 /*
+ * void mutex_spin_enter(kmutex_t *mtx);
+ */
+LEAF(mutex_spin_enter, 1);
+	LDGP(pv)
+
+	/*
+	 * STEP 1: Perform the MUTEX_SPIN_SPLRAISE() function.
+	 * (see sys/kern/kern_mutex.c)
+	 *
+	 *	s = splraise(mtx->mtx_ipl);
+	 *	if (curcpu->ci_mtx_count-- == 0)
+	 *		curcpu->ci_mtx_oldspl = s;
+	 */
+
+	call_pal PAL_OSF1_rdps		/* clobbers v0, t0, t8..t11 */
+	/* v0 = cur_ipl */
+#ifdef __BWX__
+	mov	a0, a1			/* a1 = mtx */
+	ldbu	a0, MUTEX_IPL(a0)	/* a0 = new_ipl */
+	mov	v0, a4			/* save cur_ipl in a4 */
+#else
+	mov	a0, a1			/* a1 = mtx */
+	ldq_u	a2, MUTEX_IPL(a0)
+	mov	v0, a4			/* save cur_ipl in a4 */
+	extbl	a2, MUTEX_IPL, a0	/* a0 = new_ipl */
+#endif /* __BWX__ */
+	cmplt	v0, a0, a3		/* a3 = (cur_ipl < new_ipl) */
+	GET_CURLWP	/* Note: GET_CURLWP clobbers v0, t0, t8...t11. */
+	mov	v0, a5			/* save curlwp in a5 */
+	/*
+	 * The forward-branch over the SWPIPL call is correctly predicted
+	 * not-taken by the CPU because it's rare for a code path to acquire
+	 * 2 spin mutexes.
+	 */
+	beq	a3, 1f			/*  no? -> skip... */
+	call_pal PAL_OSF1_swpipl	/* clobbers v0, t0, t8..t11 */
+	/*
+	 * v0 returns the old_ipl, which will be the same as the
+	 * cur_ipl we squirreled away in a4 earlier.
+	 */
+1:
+	/*
+	 * curlwp->l_cpu is now stable.  Update the counter and
+	 * stash the old_ipl.  Just in case it's not clear what's
+	 * going on, we:
+	 *
+	 *	- Load previous value of mtx_oldspl into t1.
+	 *	- Conditionally move old_ipl into t1 if mtx_count == 0.
+	 *	- Store t1 back to mtx_oldspl; if mtx_count != 0,
+	 *	  the store is redundant, but it's faster than a forward
+	 *	  branch.
+	 */
+	ldq	a3, L_CPU(a5)		/* a3 = curlwp->l_cpu (curcpu) */
+	ldl	t0, CPU_INFO_MTX_COUNT(a3)
+	ldl	t1, CPU_INFO_MTX_OLDSPL(a3)
+	cmoveq	t0, a4, t1		/* mtx_count == 0? -> t1 = old_ipl */
+	subl	t0, 1, t2		/* mtx_count-- */
+	stl	t1, CPU_INFO_MTX_OLDSPL(a3)
+	stl	t2, CPU_INFO_MTX_COUNT(a3)
+
+	/*
+	 * STEP 2: __cpu_simple_lock_try(>mtx_lock)
+	 */
+	ldl_l	t0, MUTEX_SIMPLELOCK(a1)
+	ldiq	t1, __SIMPLELOCK_LOCKED
+	bne	t0, 2f			/* contended */
+	stl_c	t1, MUTEX_SIMPLELOCK(a1)
+	beq	t1, 2f			/* STL_C failed; consider contended */
+	MB
+	RET
+2:
+	mov	

CVS commit: src/sys/arch/alpha

2021-07-10 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Jul 11 01:58:41 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: genassym.cf lock_stubs.s machdep.c
src/sys/arch/alpha/include: rwlock.h

Log Message:
Optimized fast-paths for rw_enter() / rw_tryenter() / rw_exit().


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/alpha/alpha/genassym.cf
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/alpha/alpha/lock_stubs.s
cvs rdiff -u -r1.373 -r1.374 src/sys/arch/alpha/alpha/machdep.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/alpha/include/rwlock.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/alpha/alpha/genassym.cf
diff -u src/sys/arch/alpha/alpha/genassym.cf:1.28 src/sys/arch/alpha/alpha/genassym.cf:1.29
--- src/sys/arch/alpha/alpha/genassym.cf:1.28	Sun Jul 11 01:54:42 2021
+++ src/sys/arch/alpha/alpha/genassym.cf	Sun Jul 11 01:58:41 2021
@@ -1,4 +1,4 @@
-# $NetBSD: genassym.cf,v 1.28 2021/07/11 01:54:42 thorpej Exp $
+# $NetBSD: genassym.cf,v 1.29 2021/07/11 01:58:41 thorpej Exp $
 
 #
 # Copyright (c) 1982, 1990, 1993
@@ -66,12 +66,15 @@
 #	from: @(#)genassym.c	8.3 (Berkeley) 1/4/94
 #
 
+quote #define __RWLOCK_PRIVATE
+
 include 
 include 
 include 
 include 
 include 
 include 
+include 
 include 
 
 include 
@@ -196,3 +199,9 @@ define	CPU_INFO_IDLE_LWP	offsetof(struct
 define	CPU_INFO_SSIR		offsetof(struct cpu_info, ci_ssir)
 define	CPU_INFO_MTX_COUNT	offsetof(struct cpu_info, ci_mtx_count)
 define	CPU_INFO_SIZEOF		sizeof(struct cpu_info)
+
+# Bits in lock fields
+define	RW_WRITE_WANTED		RW_WRITE_WANTED
+define	RW_WRITE_LOCKED		RW_WRITE_LOCKED
+define	RW_READ_INCR		RW_READ_INCR
+define	RW_READ_COUNT_SHIFT	RW_READ_COUNT_SHIFT

Index: src/sys/arch/alpha/alpha/lock_stubs.s
diff -u src/sys/arch/alpha/alpha/lock_stubs.s:1.4 src/sys/arch/alpha/alpha/lock_stubs.s:1.5
--- src/sys/arch/alpha/alpha/lock_stubs.s:1.4	Fri Sep  4 02:54:56 2020
+++ src/sys/arch/alpha/alpha/lock_stubs.s	Sun Jul 11 01:58:41 2021
@@ -1,11 +1,11 @@
-/*	$NetBSD: lock_stubs.s,v 1.4 2020/09/04 02:54:56 thorpej Exp $	*/
+/*	$NetBSD: lock_stubs.s,v 1.5 2021/07/11 01:58:41 thorpej Exp $	*/
 
 /*-
- * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * Copyright (c) 2007, 2021 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
- * by Andrew Doran.
+ * by Andrew Doran, and by Jason R. Thorpe.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -34,7 +34,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: lock_stubs.s,v 1.4 2020/09/04 02:54:56 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lock_stubs.s,v 1.5 2021/07/11 01:58:41 thorpej Exp $");
 
 #include "assym.h"
 
@@ -63,7 +63,7 @@ LEAF(_lock_cas, 3)
 	RET
 3:
 	br	1b
-END(_lock_cas)
+	END(_lock_cas)
 
 #if !defined(LOCKDEBUG)
 
@@ -72,7 +72,7 @@ END(_lock_cas)
  */
 LEAF(mutex_enter, 1)
 	LDGP(pv)
-	GET_CURLWP
+	GET_CURLWP	/* Note: GET_CURLWP clobbers v0, t0, t8...t11. */
 1:
 	mov	v0, t1
 	ldq_l	t2, 0(a0)
@@ -86,7 +86,7 @@ LEAF(mutex_enter, 1)
 	jmp	(t12)
 3:
 	br	1b
-END(mutex_enter)
+	END(mutex_enter)
 
 /*
  * void mutex_exit(kmutex_t *mtx);
@@ -94,7 +94,7 @@ END(mutex_enter)
 LEAF(mutex_exit, 1)
 	LDGP(pv)
 	MB
-	GET_CURLWP
+	GET_CURLWP	/* Note: GET_CURLWP clobbers v0, t0, t8...t11. */
 	mov	zero, t3
 1:
 	ldq_l	t2, 0(a0)
@@ -108,6 +108,162 @@ LEAF(mutex_exit, 1)
 	jmp	(t12)
 3:
 	br	1b
-END(mutex_exit)
+	END(mutex_exit)
+
+/*
+ * void rw_enter(krwlock_t *rwl, krw_t op);
+ *
+ * Acquire one hold on a RW lock.
+ */
+LEAF(rw_enter, 2)
+	LDGP(pv)
+
+	/*
+	 * RW_READER == 0 (we have a compile-time assert in machdep.c
+	 * to ensure this).
+	 *
+	 * Acquire for read is the most common case.
+	 */
+	bne	a1, 3f
+
+	/* Acquiring for read. */
+1:	ldq_l	t0, 0(a0)
+	and	t0, (RW_WRITE_LOCKED|RW_WRITE_WANTED), t1
+	addq	t0, RW_READ_INCR, t2
+	bne	t1, 4f		/* contended */
+	stq_c	t2, 0(a0)
+	beq	t2, 2f		/* STQ_C failed; retry */
+	MB
+	RET
+
+2:	br	1b
+
+3:	/* Acquiring for write. */
+	GET_CURLWP	/* Note: GET_CURLWP clobbers v0, t0, t8...t11. */
+	ldq_l	t0, 0(a0)
+	or	v0, RW_WRITE_LOCKED, t2
+	bne	t0, 4f		/* contended */
+	stq_c	t2, 0(a0)
+	beq	t2, 4f		/* STQ_C failed; consider it contended */
+	MB
+	RET
+
+4:	lda	pv, rw_vector_enter
+	jmp	(pv)
+	END(rw_enter)
+
+/*
+ * int rw_tryenter(krwlock_t *rwl, krw_t op);
+ *
+ * Try to acquire one hold on a RW lock.
+ */
+LEAF(rw_tryenter, 2)
+	LDGP(pv)
+
+	/* See above. */
+	bne	a1, 3f
+
+	/* Acquiring for read. */
+1:	ldq_l	t0, 0(a0)
+	and	t0, (RW_WRITE_LOCKED|RW_WRITE_WANTED), t1
+	addq	t0, RW_READ_INCR, v0
+	bne	t1, 4f		/* contended */
+	stq_c	v0, 0(a0)
+	beq	v0, 2f		/* STQ_C failed; retry */
+	MB
+	RET			/* v0 contains non-zero LOCK_FLAG from STQ_C */
+
+2:	br	1b
+
+	/* Acquiring for write. */
+3:	GET_CURLWP	/* Note: GET_CURLWP clobbers v0, t0, 

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

2021-07-10 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Jul 11 01:55:51 UTC 2021

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

Log Message:
Pull in pmap_subr.s (missed in prior commit).


To generate a diff of this commit:
cvs rdiff -u -r1.139 -r1.140 src/sys/arch/alpha/alpha/locore.s

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

Modified files:

Index: src/sys/arch/alpha/alpha/locore.s
diff -u src/sys/arch/alpha/alpha/locore.s:1.139 src/sys/arch/alpha/alpha/locore.s:1.140
--- src/sys/arch/alpha/alpha/locore.s:1.139	Wed Jul  7 03:30:35 2021
+++ src/sys/arch/alpha/alpha/locore.s	Sun Jul 11 01:55:51 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: locore.s,v 1.139 2021/07/07 03:30:35 thorpej Exp $ */
+/* $NetBSD: locore.s,v 1.140 2021/07/11 01:55:51 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000, 2019 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: locore.s,v 1.139 2021/07/07 03:30:35 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.s,v 1.140 2021/07/11 01:55:51 thorpej Exp $");
 
 #include "assym.h"
 
@@ -217,6 +217,15 @@ NESTED_NOPROFILE(locorestart,1,0,ra,0,0)
 
 /**/
 
+/*
+ * Pull in optimized pmap subroutines.
+ */
+#include 
+
+/**/
+
+/**/
+
 	.text
 .stabs	__FILE__,132,0,0,backtolocore1	/* done with includes */
 .loc	1 __LINE__



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

2021-07-10 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Jul 11 01:54:42 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: genassym.cf

Log Message:
Define ALPHA_PGBYTES (missed in prior commit).


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/alpha/alpha/genassym.cf

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

Modified files:

Index: src/sys/arch/alpha/alpha/genassym.cf
diff -u src/sys/arch/alpha/alpha/genassym.cf:1.27 src/sys/arch/alpha/alpha/genassym.cf:1.28
--- src/sys/arch/alpha/alpha/genassym.cf:1.27	Sat Sep 19 01:24:31 2020
+++ src/sys/arch/alpha/alpha/genassym.cf	Sun Jul 11 01:54:42 2021
@@ -1,4 +1,4 @@
-# $NetBSD: genassym.cf,v 1.27 2020/09/19 01:24:31 thorpej Exp $
+# $NetBSD: genassym.cf,v 1.28 2021/07/11 01:54:42 thorpej Exp $
 
 #
 # Copyright (c) 1982, 1990, 1993
@@ -84,6 +84,7 @@ include 
 
 # general constants 
 define	VM_MAX_ADDRESS		VM_MAX_ADDRESS
+define	ALPHA_PGBYTES		ALPHA_PGBYTES
 
 # Register offsets, for stack frames.
 define	FRAME_V0		FRAME_V0



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

2021-07-10 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Jul 10 20:22:38 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: pmap.c
Added Files:
src/sys/arch/alpha/alpha: pmap_subr.s

Log Message:
Move the optimized pmap_zero_page() from pmap.c to a new pmap_subr.s,
and optimize it a teeny bit little more.  Provide an optimized (for 21164,
anyway) pmap_copy_page() as well.


To generate a diff of this commit:
cvs rdiff -u -r1.296 -r1.297 src/sys/arch/alpha/alpha/pmap.c
cvs rdiff -u -r0 -r1.1 src/sys/arch/alpha/alpha/pmap_subr.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/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.296 src/sys/arch/alpha/alpha/pmap.c:1.297
--- src/sys/arch/alpha/alpha/pmap.c:1.296	Mon Jul  5 15:12:00 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Sat Jul 10 20:22:37 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.296 2021/07/05 15:12:00 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.297 2021/07/10 20:22:37 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.296 2021/07/05 15:12:00 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.297 2021/07/10 20:22:37 thorpej Exp $");
 
 #include 
 #include 
@@ -2758,85 +2758,9 @@ pmap_deactivate(struct lwp *l)
 	pmap_destroy(pmap);
 }
 
-/*
- * pmap_zero_page:		[ INTERFACE ]
- *
- *	Zero the specified (machine independent) page by mapping the page
- *	into virtual memory and clear its contents, one machine dependent
- *	page at a time.
- *
- *	Note: no locking is necessary in this function.
- */
-void
-pmap_zero_page(paddr_t phys)
-{
-	u_long *p0, *p1, *pend;
-
-#ifdef DEBUG
-	if (pmapdebug & PDB_FOLLOW)
-		printf("pmap_zero_page(%lx)\n", phys);
-#endif
-
-	p0 = (u_long *)ALPHA_PHYS_TO_K0SEG(phys);
-	p1 = NULL;
-	pend = (u_long *)((u_long)p0 + PAGE_SIZE);
-
-	/*
-	 * Unroll the loop a bit, doing 16 quadwords per iteration.
-	 * Do only 8 back-to-back stores, and alternate registers.
-	 */
-	do {
-		__asm volatile(
-		"# BEGIN loop body\n"
-		"	addq	%2, (8 * 8), %1		\n"
-		"	stq	$31, (0 * 8)(%0)	\n"
-		"	stq	$31, (1 * 8)(%0)	\n"
-		"	stq	$31, (2 * 8)(%0)	\n"
-		"	stq	$31, (3 * 8)(%0)	\n"
-		"	stq	$31, (4 * 8)(%0)	\n"
-		"	stq	$31, (5 * 8)(%0)	\n"
-		"	stq	$31, (6 * 8)(%0)	\n"
-		"	stq	$31, (7 * 8)(%0)	\n"
-		"	\n"
-		"	addq	%3, (8 * 8), %0		\n"
-		"	stq	$31, (0 * 8)(%1)	\n"
-		"	stq	$31, (1 * 8)(%1)	\n"
-		"	stq	$31, (2 * 8)(%1)	\n"
-		"	stq	$31, (3 * 8)(%1)	\n"
-		"	stq	$31, (4 * 8)(%1)	\n"
-		"	stq	$31, (5 * 8)(%1)	\n"
-		"	stq	$31, (6 * 8)(%1)	\n"
-		"	stq	$31, (7 * 8)(%1)	\n"
-		"	# END loop body"
-		: "=r" (p0), "=r" (p1)
-		: "0" (p0), "1" (p1)
-		: "memory");
-	} while (p0 < pend);
-}
-
-/*
- * pmap_copy_page:		[ INTERFACE ]
- *
- *	Copy the specified (machine independent) page by mapping the page
- *	into virtual memory and using memcpy to copy the page, one machine
- *	dependent page at a time.
- *
- *	Note: no locking is necessary in this function.
- */
-void
-pmap_copy_page(paddr_t src, paddr_t dst)
-{
-	const void *s;
-	void *d;
+/* pmap_zero_page() is in pmap_subr.s */
 
-#ifdef DEBUG
-	if (pmapdebug & PDB_FOLLOW)
-		printf("pmap_copy_page(%lx, %lx)\n", src, dst);
-#endif
-	s = (const void *)ALPHA_PHYS_TO_K0SEG(src);
-	d = (void *)ALPHA_PHYS_TO_K0SEG(dst);
-	memcpy(d, s, PAGE_SIZE);
-}
+/* pmap_copy_page() is in pmap_subr.s */
 
 /*
  * pmap_pageidlezero:		[ INTERFACE ]

Added files:

Index: src/sys/arch/alpha/alpha/pmap_subr.s
diff -u /dev/null src/sys/arch/alpha/alpha/pmap_subr.s:1.1
--- /dev/null	Sat Jul 10 20:22:38 2021
+++ src/sys/arch/alpha/alpha/pmap_subr.s	Sat Jul 10 20:22:37 2021
@@ -0,0 +1,165 @@
+/* $NetBSD: pmap_subr.s,v 1.1 2021/07/10 20:22:37 thorpej Exp $ */
+
+/*-
+ * Copyright (c) 2021 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * 

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

2021-07-08 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jul  9 01:29:21 UTC 2021

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

Log Message:
If we're netbooting on a system with, for example, an ISA DE204 Ethernet
interface, we don't have sufficient information to find the device using
the bus/slot scheme that we do with a PCI network interface.  However, in
these cases, some versions of the SRM console supply the MAC address of
the interface in the booted_dev environment variable, like so:

BOOTP 1 1 0 0 0 5 0 08-00-2B-xx-xx-xx 1

So, if we weren't able to find the booted device by the usual means,
check for this and, if we find a MAC address, try to find the network
interface by the MAC address.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sys/arch/alpha/alpha/autoconf.c

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

Modified files:

Index: src/sys/arch/alpha/alpha/autoconf.c
diff -u src/sys/arch/alpha/alpha/autoconf.c:1.57 src/sys/arch/alpha/alpha/autoconf.c:1.58
--- src/sys/arch/alpha/alpha/autoconf.c:1.57	Sat May 22 15:05:36 2021
+++ src/sys/arch/alpha/alpha/autoconf.c	Fri Jul  9 01:29:20 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: autoconf.c,v 1.57 2021/05/22 15:05:36 thorpej Exp $ */
+/* $NetBSD: autoconf.c,v 1.58 2021/07/09 01:29:20 thorpej Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -42,7 +42,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.57 2021/05/22 15:05:36 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.58 2021/07/09 01:29:20 thorpej Exp $");
 
 #include "pci.h"
 
@@ -57,6 +57,9 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v
 
 #include 
 
+#include 
+#include 
+
 #include 
 #include 
 #include 
@@ -66,8 +69,7 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v
 
 struct bootdev_data	*bootdev_data;
 
-void	parse_prom_bootdev(void);
-static inline int atoi(const char *);
+static void	parse_prom_bootdev(void);
 
 /*
  * cpu_configure:
@@ -138,6 +140,86 @@ qemu_find_rootdev(void)
 	booted_device = device_find_by_xname(cp);
 }
 
+static bool
+parse_dec_macaddr(const char *str, uint8_t enaddr[ETHER_ADDR_LEN])
+{
+	char *cp;
+	long long l;
+	int i;
+
+	/*
+	 * DEC Ethernet address strings are formatted like so:
+	 *
+	 *	XX-XX-XX-XX-XX-XX
+	 */
+
+	for (i = 0; i < ETHER_ADDR_LEN; i++) {
+		l = strtoll(str, , 16);
+		if (l < 0 || l > 0xff) {
+			/* Not a valid MAC address. */
+			return false;
+		}
+		if (*cp == '-') {
+			/* Octet separator. */
+			enaddr[i] = (uint8_t)l;
+			str = cp + 1;
+			continue;
+		}
+		if (*cp == ' ' || *cp == '\0') {
+			/* End of the string. */
+			enaddr[i] = (uint8_t)l;
+			return i == ETHER_ADDR_LEN - 1;
+		}
+		/* Bogus character. */
+		break;
+	}
+
+	/* Encountered bogus character or didn't reach end of string. */
+	return false;
+}
+
+static void
+netboot_find_rootdev_planb(void)
+{
+	struct psref psref;
+	uint8_t enaddr[ETHER_ADDR_LEN];
+	char ifname[IFNAMSIZ];
+	int i;
+
+	if (strncasecmp(bootinfo.booted_dev, "BOOTP ", 6) != 0 &&
+	strncasecmp(bootinfo.booted_dev, "MOP ", 4) != 0) {
+		/* We weren't netbooted. */
+		return;
+	}
+
+	for (i = 2; bootinfo.booted_dev[i] != '\0'; i++) {
+		if (bootinfo.booted_dev[i] == '-') {
+			if (parse_dec_macaddr(_dev[i - 2],
+	  enaddr)) {
+/* Found it! */
+break;
+			}
+		}
+	}
+	if (bootinfo.booted_dev[i] == '\0') {
+		/* No MAC address in string. */
+		return;
+	}
+
+	/* Now try to look up the interface by the link address. */
+	struct ifnet *ifp = if_get_bylla(enaddr, ETHER_ADDR_LEN, );
+	if (ifp == NULL) {
+		/* No interface attached with that MAC address. */
+		return;
+	}
+
+	strlcpy(ifname, if_name(ifp), sizeof(ifname));
+	if_put(ifp, );
+
+	/* Ok! Now look up the device_t by name! */
+	booted_device = device_find_by_xname(ifname);
+}
+
 void
 cpu_rootconf(void)
 {
@@ -147,13 +229,33 @@ cpu_rootconf(void)
 	}
 
 	if (booted_device == NULL) {
+		/*
+		 * It's possible that we netbooted from an Ethernet
+		 * interface that can't be matched via the usual
+		 * logic in device_register() (a DE204 in an ISA slot,
+		 * for example).  In these cases, the console may have
+		 * provided us with a MAC address that we can use to
+		 * try and find the interface, * e.g.:
+		 *
+		 *	BOOTP 1 1 0 0 0 5 0 08-00-2B-xx-xx-xx 1
+		 */
+		netboot_find_rootdev_planb();
+	}
+
+	if (booted_device == NULL) {
 		printf("WARNING: can't figure what device matches \"%s\"\n",
 		bootinfo.booted_dev);
 	}
 	rootconf();
 }
 
-void
+static inline int
+atoi(const char *s)
+{
+	return (int)strtoll(s, NULL, 10);
+}
+
+static void
 parse_prom_bootdev(void)
 {
 	static char hacked_boot_dev[128];
@@ -213,12 +315,6 @@ parse_prom_bootdev(void)
 	bootdev_data = 
 }
 
-static inline int
-atoi(const char *s)
-{
-	return (int)strtoll(s, NULL, 10);
-}
-
 void
 device_register(device_t dev, void *aux)
 {



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

2021-07-06 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jul  7 03:30:35 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: locore.s patch.c

Log Message:
Provide a BWX version of alpha_copystr() and patch it into place if
the system supports the BWX extension.  The inner loop of the BWX
version is 42% shorter than the non-BWX version (7 vs 12 insns).


To generate a diff of this commit:
cvs rdiff -u -r1.138 -r1.139 src/sys/arch/alpha/alpha/locore.s
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/alpha/alpha/patch.c

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

Modified files:

Index: src/sys/arch/alpha/alpha/locore.s
diff -u src/sys/arch/alpha/alpha/locore.s:1.138 src/sys/arch/alpha/alpha/locore.s:1.139
--- src/sys/arch/alpha/alpha/locore.s:1.138	Wed Jul  7 02:44:04 2021
+++ src/sys/arch/alpha/alpha/locore.s	Wed Jul  7 03:30:35 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: locore.s,v 1.138 2021/07/07 02:44:04 thorpej Exp $ */
+/* $NetBSD: locore.s,v 1.139 2021/07/07 03:30:35 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000, 2019 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: locore.s,v 1.138 2021/07/07 02:44:04 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.s,v 1.139 2021/07/07 03:30:35 thorpej Exp $");
 
 #include "assym.h"
 
@@ -902,6 +902,44 @@ LEAF_NOPROFILE(lwp_trampoline, 0)
 /*
  * alpha_copystr(const void *from, void *to, size_t len, size_t *donep)
  */
+	.arch	ev56
+LEAF(alpha_copystr_bwx, 4)
+	LDGP(pv)
+
+	mov	a2, t0			/* t0 = i = len */
+	beq	a2, 5f			/* if (len == 0), bail */
+
+1:	ldbu	t1, 0(a0)		/* t1 = *from */
+	subl	a2, 1, a2		/* len-- */
+	addq	a0, 1, a0		/* from++ */
+	stb	t1, 0(a1)		/* *to = t1 */
+	beq	t1, 2f			/* if (t1 == '\0'), bail out */
+	addq	a1, 1, a1		/* to++ */
+	bne	a2, 1b			/* if (len != 0), copy more */
+
+2:	beq	a3, 3f			/* if (lenp != NULL) */
+	subl	t0, a2, t0		/* *lenp = (i - len) */
+	stq	t0, 0(a3)
+3:	bne	t1, 4f			/* *from != '\0'; leave in a huff */
+
+	mov	zero, v0		/* return 0. */
+	RET
+
+4:	ldiq	v0, ENAMETOOLONG
+	RET
+
+5:	ldiq	t1, 1			/* fool the test above... */
+	br	zero, 2b
+
+	nop/* pad to same length as... */
+	nop/* non-BWX version. */
+	nop
+	nop
+	nop
+	EXPORT(alpha_copystr_bwx_end)
+	END(alpha_copystr_bwx)
+	.arch	ev4
+
 LEAF(alpha_copystr, 4)
 	LDGP(pv)
 
@@ -935,6 +973,7 @@ LEAF(alpha_copystr, 4)
 
 5:	ldiq	t1, 1			/* fool the test above... */
 	br	zero, 2b
+	EXPORT(alpha_copystr_end)
 	END(alpha_copystr)
 
 NESTED(copyinstr, 4, 16, ra, IM_RA|IM_S0, 0)

Index: src/sys/arch/alpha/alpha/patch.c
diff -u src/sys/arch/alpha/alpha/patch.c:1.5 src/sys/arch/alpha/alpha/patch.c:1.6
--- src/sys/arch/alpha/alpha/patch.c:1.5	Fri Sep  4 03:41:49 2020
+++ src/sys/arch/alpha/alpha/patch.c	Wed Jul  7 03:30:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: patch.c,v 1.5 2020/09/04 03:41:49 thorpej Exp $	*/
+/*	$NetBSD: patch.c,v 1.6 2021/07/07 03:30:35 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: patch.c,v 1.5 2020/09/04 03:41:49 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: patch.c,v 1.6 2021/07/07 03:30:35 thorpej Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -57,6 +57,9 @@ void	_membar_sync_end(void);
 void	_membar_sync_mp(void);
 void	_membar_sync_mp_end(void);
 
+extern char alpha_copystr_bwx[], alpha_copystr_bwx_end[];
+extern char alpha_copystr[], alpha_copystr_end[];
+
 static void __attribute__((__unused__))
 patchfunc(void *from_s, void *from_e, void *to_s, void *to_e)
 {
@@ -85,6 +88,11 @@ alpha_patch(bool is_mp)
 	 * kernel code.
 	 */
 
+	if (cpu_amask & ALPHA_AMASK_BWX) {
+		patchfunc(alpha_copystr_bwx, alpha_copystr_bwx_end,
+		alpha_copystr, alpha_copystr_end);
+	}
+
 #if defined(MULTIPROCESSOR)
 	if (is_mp) {
 		KASSERT(curcpu()->ci_flags & CPUF_PRIMARY);



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

2021-07-06 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jul  7 03:24:26 UTC 2021

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

Log Message:
After attaching CPUs, call alpha_patch() in case there are any function
patches we wish to do based on discovered architecture features.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/alpha/alpha/mainbus.c

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

Modified files:

Index: src/sys/arch/alpha/alpha/mainbus.c
diff -u src/sys/arch/alpha/alpha/mainbus.c:1.35 src/sys/arch/alpha/alpha/mainbus.c:1.36
--- src/sys/arch/alpha/alpha/mainbus.c:1.35	Sat Apr 24 23:36:23 2021
+++ src/sys/arch/alpha/alpha/mainbus.c	Wed Jul  7 03:24:26 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: mainbus.c,v 1.35 2021/04/24 23:36:23 thorpej Exp $ */
+/* $NetBSD: mainbus.c,v 1.36 2021/07/07 03:24:26 thorpej Exp $ */
 
 /*
  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
@@ -29,7 +29,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.35 2021/04/24 23:36:23 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.36 2021/07/07 03:24:26 thorpej Exp $");
 
 #include 
 #include 
@@ -92,6 +92,9 @@ mbattach(device_t parent, device_t self,
 		printf("WARNING: %d cpus in machine, %d attached\n",
 			ncpus, cpuattachcnt);
 
+	/* Patch-up any routines based on architecture features. */
+	alpha_patch(false);
+
 	if (alpha_is_qemu) {
 		ma.ma_name = "qemu";
 		ma.ma_slot = 0;			/* meaningless */



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

2021-07-06 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jul  7 02:44:04 UTC 2021

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

Log Message:
Re-arrange alpha_copystr() so that the the error/unlikely cases are forward
branches (which will be predicted as not-taken), and that the likely cases
are fall-through, with the exception of the loop branch (which is a backward
branch, and thus will be predicted as taken).


To generate a diff of this commit:
cvs rdiff -u -r1.137 -r1.138 src/sys/arch/alpha/alpha/locore.s

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

Modified files:

Index: src/sys/arch/alpha/alpha/locore.s
diff -u src/sys/arch/alpha/alpha/locore.s:1.137 src/sys/arch/alpha/alpha/locore.s:1.138
--- src/sys/arch/alpha/alpha/locore.s:1.137	Sun May 23 01:00:53 2021
+++ src/sys/arch/alpha/alpha/locore.s	Wed Jul  7 02:44:04 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: locore.s,v 1.137 2021/05/23 01:00:53 thorpej Exp $ */
+/* $NetBSD: locore.s,v 1.138 2021/07/07 02:44:04 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000, 2019 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: locore.s,v 1.137 2021/05/23 01:00:53 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.s,v 1.138 2021/07/07 02:44:04 thorpej Exp $");
 
 #include "assym.h"
 
@@ -900,15 +900,13 @@ LEAF_NOPROFILE(lwp_trampoline, 0)
 /**/
 
 /*
- * XXX XXX XXX: Should be removed?
+ * alpha_copystr(const void *from, void *to, size_t len, size_t *donep)
  */
 LEAF(alpha_copystr, 4)
 	LDGP(pv)
 
 	mov	a2, t0			/* t0 = i = len */
-	bne	a2, 1f			/* if (len != 0), proceed */
-	ldiq	t1, 1			/* else bail */
-	br	zero, 2f
+	beq	a2, 5f			/* if (len == 0), bail */
 
 1:	ldq_u	t1, 0(a0)		/* t1 = *from */
 	extbl	t1, a0, t1
@@ -927,13 +925,16 @@ LEAF(alpha_copystr, 4)
 2:	beq	a3, 3f			/* if (lenp != NULL) */
 	subl	t0, a2, t0		/* *lenp = (i - len) */
 	stq	t0, 0(a3)
-3:	beq	t1, 4f			/* *from == '\0'; leave quietly */
+3:	bne	t1, 4f			/* *from != '\0'; leave in a huff */
 
-	ldiq	v0, ENAMETOOLONG	/* *from != '\0'; error. */
+	mov	zero, v0		/* return 0. */
 	RET
 
-4:	mov	zero, v0		/* return 0. */
+4:	ldiq	v0, ENAMETOOLONG
 	RET
+
+5:	ldiq	t1, 1			/* fool the test above... */
+	br	zero, 2b
 	END(alpha_copystr)
 
 NESTED(copyinstr, 4, 16, ra, IM_RA|IM_S0, 0)



CVS commit: src/sys/arch/alpha

2021-07-06 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Tue Jul  6 12:20:52 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: vm_machdep.c
src/sys/arch/alpha/include: param.h

Log Message:
- Define STACK_ALIGNBYTES to override the default and ensure that
  stacks are 16-byte aligned, an assumption made by the compiler
  and recommended by the Alpha Architecture Handbook.
- cpu_lwp_fork(): Ensure 16-byte stack alignment if the caller specified
  one.

Addresses root casue of PR port-alpha/54307 and PR toolchain/56153.

Many thanks to rin@ for performing the root cause analysis and testing
changes.


To generate a diff of this commit:
cvs rdiff -u -r1.119 -r1.120 src/sys/arch/alpha/alpha/vm_machdep.c
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/alpha/include/param.h

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

Modified files:

Index: src/sys/arch/alpha/alpha/vm_machdep.c
diff -u src/sys/arch/alpha/alpha/vm_machdep.c:1.119 src/sys/arch/alpha/alpha/vm_machdep.c:1.120
--- src/sys/arch/alpha/alpha/vm_machdep.c:1.119	Sun Jul  4 22:42:35 2021
+++ src/sys/arch/alpha/alpha/vm_machdep.c	Tue Jul  6 12:20:52 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: vm_machdep.c,v 1.119 2021/07/04 22:42:35 thorpej Exp $ */
+/* $NetBSD: vm_machdep.c,v 1.120 2021/07/06 12:20:52 thorpej Exp $ */
 
 /*
  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
@@ -29,7 +29,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.119 2021/07/04 22:42:35 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.120 2021/07/06 12:20:52 thorpej Exp $");
 
 #include 
 #include 
@@ -116,10 +116,12 @@ cpu_lwp_fork(struct lwp *l1, struct lwp 
 	 * Floating point state from the FP chip has already been saved.
 	 */
 	*pcb2 = *pcb1;
-	if (stack != NULL)
-		pcb2->pcb_hw.apcb_usp = (u_long)stack + stacksize;
-	else
+	if (stack != NULL) {
+		pcb2->pcb_hw.apcb_usp =
+		((u_long)stack + stacksize) & ~((u_long)STACK_ALIGNBYTES);
+	} else {
 		pcb2->pcb_hw.apcb_usp = alpha_pal_rdusp();
+	}
 
 	/*
 	 * Put l2 on the kernel's page tables until its first trip

Index: src/sys/arch/alpha/include/param.h
diff -u src/sys/arch/alpha/include/param.h:1.48 src/sys/arch/alpha/include/param.h:1.49
--- src/sys/arch/alpha/include/param.h:1.48	Mon May 31 14:38:55 2021
+++ src/sys/arch/alpha/include/param.h	Tue Jul  6 12:20:52 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: param.h,v 1.48 2021/05/31 14:38:55 simonb Exp $ */
+/* $NetBSD: param.h,v 1.49 2021/07/06 12:20:52 thorpej Exp $ */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -57,6 +57,12 @@
 #define ALPHA_PGSHIFT	13
 #endif
 
+/*
+ * Compiler assumes 16 byte stack alignment, per recommendation of
+ * Alpha Architecture Handbook.
+ */
+#define	STACK_ALIGNBYTES	(16 - 1)
+
 #define	NBPG		(1 << ALPHA_PGSHIFT)		/* bytes/page */
 #define	PGOFSET		(NBPG-1)			/* byte off. into pg */
 #define	PGSHIFT		ALPHA_PGSHIFT			/* LOG2(NBPG) */



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

2021-07-05 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon Jul  5 15:12:01 UTC 2021

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

Log Message:
Instrument the number of calls to pmap_growkernel().


To generate a diff of this commit:
cvs rdiff -u -r1.295 -r1.296 src/sys/arch/alpha/alpha/pmap.c

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

Modified files:

Index: src/sys/arch/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.295 src/sys/arch/alpha/alpha/pmap.c:1.296
--- src/sys/arch/alpha/alpha/pmap.c:1.295	Mon Jul  5 10:00:22 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Mon Jul  5 15:12:00 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.295 2021/07/05 10:00:22 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.296 2021/07/05 15:12:00 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.295 2021/07/05 10:00:22 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.296 2021/07/05 15:12:00 thorpej Exp $");
 
 #include 
 #include 
@@ -258,6 +258,11 @@ int		pmap_pv_lowat __read_mostly = PMAP_
 static TAILQ_HEAD(, pmap) pmap_all_pmaps __cacheline_aligned;
 
 /*
+ * Instrument the number of calls to pmap_growkernel().
+ */
+static struct evcnt pmap_growkernel_evcnt __read_mostly;
+
+/*
  * The pools from which pmap structures and sub-structures are allocated.
  */
 static struct pool_cache pmap_pmap_cache __read_mostly;
@@ -1548,6 +1553,10 @@ pmap_init(void)
 	/* Initialize TLB handling. */
 	pmap_tlb_init();
 
+	/* Instrument pmap_growkernel(). */
+	evcnt_attach_dynamic_nozero(_growkernel_evcnt, EVCNT_TYPE_MISC,
+	NULL, "pmap", "growkernel");
+
 	/*
 	 * Set a low water mark on the pv_entry pool, so that we are
 	 * more likely to have these around even in extreme memory
@@ -3593,6 +3602,8 @@ pmap_growkernel(vaddr_t maxkvaddr)
 	if (maxkvaddr <= virtual_end)
 		goto out;		/* we are OK */
 
+	pmap_growkernel_evcnt.ev_count++;
+
 	va = virtual_end;
 
 	while (va < maxkvaddr) {



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

2021-07-05 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon Jul  5 10:00:22 UTC 2021

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

Log Message:
Fix a bug introduced in pmap.c,v 1.287 where, when creating the PTE
in pmap_enter(), we would erroneously disregard MOD/REF attributes
already present on the page, thus causing FOW/FOR to be set incorrectly.
Normally this is not a big problem (an extra page fault will be taken
to resolve it), but if you access the mapping in interrupt context
(such as during IDE PIO, for example), a KASSERT can fire due to
acquiring an rwlock in interrupt context while servicing that fault.

Reported and bisected-to-commit by rin@.


To generate a diff of this commit:
cvs rdiff -u -r1.294 -r1.295 src/sys/arch/alpha/alpha/pmap.c

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

Modified files:

Index: src/sys/arch/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.294 src/sys/arch/alpha/alpha/pmap.c:1.295
--- src/sys/arch/alpha/alpha/pmap.c:1.294	Sun Jul  4 22:42:35 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Mon Jul  5 10:00:22 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.294 2021/07/04 22:42:35 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.295 2021/07/05 10:00:22 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.294 2021/07/04 22:42:35 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.295 2021/07/05 10:00:22 thorpej Exp $");
 
 #include 
 #include 
@@ -2344,7 +2344,7 @@ pmap_enter(pmap_t pmap, vaddr_t va, padd
 
 		lock = pmap_pvh_lock(pg);
 		mutex_enter(lock);
-		md->pvh_listx |= attrs;
+		attrs = (md->pvh_listx |= attrs);
 		mutex_exit(lock);
 
 		/* Set up referenced/modified emulation for new mapping. */



CVS commit: src/sys/arch/alpha

2021-07-04 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Jul  4 22:42:36 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: core_machdep.c interrupt.c machdep.c pmap.c
vm_machdep.c
src/sys/arch/alpha/common: sgmap_common.c
src/sys/arch/alpha/isa: isapnp_machdep.c
src/sys/arch/alpha/jensenio: jensenio_bus_intio.c jensenio_bus_io.c
jensenio_bus_mem.c jensenio_dma.c jensenio_intr.c
src/sys/arch/alpha/mcbus: mcbus.c mcmem.c
src/sys/arch/alpha/pci: apecs.c apecs_bus_io.c apecs_bus_mem.c
apecs_dma.c cia.c cia_bwx_bus_io.c cia_bwx_bus_mem.c cia_dma.c
cia_swiz_bus_io.c cia_swiz_bus_mem.c dwlpx_bus_io.c dwlpx_bus_mem.c
irongate.c irongate_bus_io.c irongate_bus_mem.c irongate_dma.c
lca.c lca_bus_io.c lca_bus_mem.c lca_dma.c mcpcia_bus_io.c
mcpcia_bus_mem.c mcpcia_dma.c pci_1000.c pci_1000a.c
pci_2100_a500.c pci_550.c pci_6600.c pci_eb164.c pci_eb64plus.c
pci_eb66.c pci_kn20aa.c pci_kn300.c pci_kn8ae.c pci_sgmap_pte32.c
pci_sgmap_pte64.c sio_pic.c tsc.c tsp_bus_io.c tsp_bus_mem.c
tsp_dma.c ttwoga.c ttwoga_bus_io.c ttwoga_bus_mem.c
src/sys/arch/alpha/tc: tc_bus_mem.c tc_sgmap.c
src/sys/arch/alpha/tlsb: kftxx.c tlsb.c tlsbmem.c

Log Message:
Remove unnecessary #include 


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/alpha/alpha/core_machdep.c
cvs rdiff -u -r1.97 -r1.98 src/sys/arch/alpha/alpha/interrupt.c
cvs rdiff -u -r1.372 -r1.373 src/sys/arch/alpha/alpha/machdep.c
cvs rdiff -u -r1.293 -r1.294 src/sys/arch/alpha/alpha/pmap.c
cvs rdiff -u -r1.118 -r1.119 src/sys/arch/alpha/alpha/vm_machdep.c
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/alpha/common/sgmap_common.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/alpha/isa/isapnp_machdep.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/alpha/jensenio/jensenio_bus_intio.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/alpha/jensenio/jensenio_bus_io.c \
src/sys/arch/alpha/jensenio/jensenio_bus_mem.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/alpha/jensenio/jensenio_dma.c
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/alpha/jensenio/jensenio_intr.c
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/alpha/mcbus/mcbus.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/alpha/mcbus/mcmem.c
cvs rdiff -u -r1.57 -r1.58 src/sys/arch/alpha/pci/apecs.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/alpha/pci/apecs_bus_io.c \
src/sys/arch/alpha/pci/apecs_bus_mem.c \
src/sys/arch/alpha/pci/irongate_bus_mem.c \
src/sys/arch/alpha/pci/lca_bus_io.c src/sys/arch/alpha/pci/lca_bus_mem.c
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/alpha/pci/apecs_dma.c
cvs rdiff -u -r1.77 -r1.78 src/sys/arch/alpha/pci/cia.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/alpha/pci/cia_bwx_bus_io.c \
src/sys/arch/alpha/pci/cia_bwx_bus_mem.c \
src/sys/arch/alpha/pci/mcpcia_bus_io.c \
src/sys/arch/alpha/pci/mcpcia_bus_mem.c
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/alpha/pci/cia_dma.c \
src/sys/arch/alpha/pci/pci_kn8ae.c
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/alpha/pci/cia_swiz_bus_io.c \
src/sys/arch/alpha/pci/pci_2100_a500.c src/sys/arch/alpha/pci/tsp_dma.c
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/alpha/pci/cia_swiz_bus_mem.c \
src/sys/arch/alpha/pci/ttwoga.c
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/alpha/pci/dwlpx_bus_io.c \
src/sys/arch/alpha/pci/dwlpx_bus_mem.c
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/alpha/pci/irongate.c
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/alpha/pci/irongate_bus_io.c
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/alpha/pci/irongate_dma.c \
src/sys/arch/alpha/pci/pci_sgmap_pte32.c \
src/sys/arch/alpha/pci/pci_sgmap_pte64.c
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/alpha/pci/lca.c
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/alpha/pci/lca_dma.c
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/alpha/pci/mcpcia_dma.c
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/alpha/pci/pci_1000.c
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/alpha/pci/pci_1000a.c \
src/sys/arch/alpha/pci/pci_6600.c
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/alpha/pci/pci_550.c
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/alpha/pci/pci_eb164.c
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/alpha/pci/pci_eb64plus.c \
src/sys/arch/alpha/pci/pci_eb66.c
cvs rdiff -u -r1.58 -r1.59 src/sys/arch/alpha/pci/pci_kn20aa.c
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/alpha/pci/pci_kn300.c
cvs rdiff -u -r1.51 -r1.52 src/sys/arch/alpha/pci/sio_pic.c
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/alpha/pci/tsc.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/alpha/pci/tsp_bus_io.c
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/alpha/pci/tsp_bus_mem.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/alpha/pci/ttwoga_bus_io.c \
src/sys/arch/alpha/pci/ttwoga_bus_mem.c
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/alpha/tc/tc_bus_mem.c
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/alpha/tc/tc_sgmap.c
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/alpha/tlsb/kftxx.c
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/alpha/tlsb/tlsb.c
cvs rdiff -u -r1.11 

CVS commit: src/sys/arch/alpha

2021-07-04 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Jul  4 22:36:43 UTC 2021

Modified Files:
src/sys/arch/alpha/common: shared_intr.c
src/sys/arch/alpha/include: intr.h pci_machdep.h
src/sys/arch/alpha/jensenio: jensenio_intr.c
src/sys/arch/alpha/pci: pci_1000.c pci_1000a.c pci_2100_a500.c
pci_550.c pci_6600.c pci_eb164.c pci_eb64plus.c pci_eb66.c
pci_kn20aa.c pci_kn300.c pci_machdep.c sio_pic.c

Log Message:
Reduce code duplication when setting up the interrupt handler data
structures:
- alpha_shared_intr_alloc() no longer takes a "string length" argument,
  and just uses kmem_asprintf() to create an "irq %u" string by default.
  This is suitable for nearly every caller.
- Add a alpha_shared_intr_set_string() that allows callers to override
  the default IRQ description string.
- Related: make alpha_shared_intr_string() return a const char *, since
  no callers should need to modify the string directly now.
- Re-factor PCI shared interrupt structure allocation / initialization
  into a new alpha_pci_intr_alloc(), which is suitable for nearly every
  Alpha PCI platform.  Callers are expected to first have initialized
  the interrupt hardware to the quiescent state.

Adjust various call sites of above functions to account for changes,
even if they are not able to use the newly re-factored code.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/alpha/common/shared_intr.c
cvs rdiff -u -r1.83 -r1.84 src/sys/arch/alpha/include/intr.h
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/alpha/include/pci_machdep.h
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/alpha/jensenio/jensenio_intr.c
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/alpha/pci/pci_1000.c
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/alpha/pci/pci_1000a.c \
src/sys/arch/alpha/pci/pci_6600.c src/sys/arch/alpha/pci/pci_machdep.c
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/alpha/pci/pci_2100_a500.c
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/alpha/pci/pci_550.c
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/alpha/pci/pci_eb164.c
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/alpha/pci/pci_eb64plus.c \
src/sys/arch/alpha/pci/pci_eb66.c
cvs rdiff -u -r1.57 -r1.58 src/sys/arch/alpha/pci/pci_kn20aa.c
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/alpha/pci/pci_kn300.c
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/alpha/pci/sio_pic.c

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

Modified files:

Index: src/sys/arch/alpha/common/shared_intr.c
diff -u src/sys/arch/alpha/common/shared_intr.c:1.28 src/sys/arch/alpha/common/shared_intr.c:1.29
--- src/sys/arch/alpha/common/shared_intr.c:1.28	Fri Jun 25 18:08:34 2021
+++ src/sys/arch/alpha/common/shared_intr.c	Sun Jul  4 22:36:43 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: shared_intr.c,v 1.28 2021/06/25 18:08:34 thorpej Exp $ */
+/* $NetBSD: shared_intr.c,v 1.29 2021/07/04 22:36:43 thorpej Exp $ */
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: shared_intr.c,v 1.28 2021/06/25 18:08:34 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: shared_intr.c,v 1.29 2021/07/04 22:36:43 thorpej Exp $");
 
 #include 
 #include 
@@ -96,25 +96,23 @@ intr_typename(int type)
 }
 
 struct alpha_shared_intr *
-alpha_shared_intr_alloc(unsigned int n, unsigned int namesize)
+alpha_shared_intr_alloc(unsigned int n)
 {
 	struct alpha_shared_intr *intr;
 	unsigned int i;
 
+	KASSERT(n != 0);
+
 	intr = kmem_alloc(n * sizeof(*intr), KM_SLEEP);
 	for (i = 0; i < n; i++) {
 		TAILQ_INIT([i].intr_q);
 		intr[i].intr_sharetype = IST_NONE;
 		intr[i].intr_dfltsharetype = IST_NONE;
 		intr[i].intr_nstrays = 0;
-		intr[i].intr_maxstrays = 5;
+		intr[i].intr_maxstrays = 0;
 		intr[i].intr_private = NULL;
 		intr[i].intr_cpu = NULL;
-		if (namesize != 0) {
-			intr[i].intr_string = kmem_zalloc(namesize, KM_SLEEP);
-		} else {
-			intr[i].intr_string = NULL;
-		}
+		intr[i].intr_string = kmem_asprintf("irq %u", i);
 	}
 
 	return (intr);
@@ -492,7 +490,16 @@ alpha_shared_intr_evcnt(struct alpha_sha
 	return ([num].intr_evcnt);
 }
 
-char *
+void
+alpha_shared_intr_set_string(struct alpha_shared_intr *intr,
+unsigned int num, char *str)
+{
+	char *ostr = intr[num].intr_string;
+	intr[num].intr_string = str;
+	kmem_strfree(ostr);
+}
+
+const char *
 alpha_shared_intr_string(struct alpha_shared_intr *intr,
 unsigned int num)
 {

Index: src/sys/arch/alpha/include/intr.h
diff -u src/sys/arch/alpha/include/intr.h:1.83 src/sys/arch/alpha/include/intr.h:1.84
--- src/sys/arch/alpha/include/intr.h:1.83	Sat Oct 10 03:05:04 2020
+++ src/sys/arch/alpha/include/intr.h	Sun Jul  4 22:36:43 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: intr.h,v 1.83 2020/10/10 03:05:04 thorpej Exp $ */
+/* $NetBSD: intr.h,v 1.84 2021/07/04 22:36:43 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2000, 2001, 2002 The NetBSD Foundation, Inc.
@@ -227,7 +227,7 @@ struct alpha_shared_intr {
 	

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

2021-06-26 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Jun 26 15:02:19 UTC 2021

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

Log Message:
Fix typo in comment


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/sys/arch/alpha/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/alpha/include/cpu.h
diff -u src/sys/arch/alpha/include/cpu.h:1.101 src/sys/arch/alpha/include/cpu.h:1.102
--- src/sys/arch/alpha/include/cpu.h:1.101	Tue Apr 20 00:09:45 2021
+++ src/sys/arch/alpha/include/cpu.h	Sat Jun 26 15:02:19 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.101 2021/04/20 00:09:45 thorpej Exp $ */
+/* $NetBSD: cpu.h,v 1.102 2021/06/26 15:02:19 skrll Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -203,7 +203,7 @@ struct clockframe {
 /*
  * This isn't perfect; if the clock interrupt comes in before the
  * r/m/w cycle is complete, we won't be counted... but it's not
- * like this stastic has to be extremely accurate.
+ * like this statistic has to be extremely accurate.
  */
 #define	CLKF_INTR(framep)		\
 	((curcpu()->ci_intrdepth & 0xf) != 0)	/* see interrupt() */



CVS commit: src/sys/arch/alpha

2021-06-25 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jun 25 18:08:34 UTC 2021

Modified Files:
src/sys/arch/alpha/common: shared_intr.c
src/sys/arch/alpha/jensenio: jensenio_intr.c
src/sys/arch/alpha/pci: pci_1000.c pci_1000a.c pci_2100_a500.c
pci_550.c pci_6600.c pci_eb164.c pci_eb64plus.c pci_eb66.c
pci_kn20aa.c pci_kn300.c pci_machdep.c sio_pic.c

Log Message:
Tweak how the IRQ description strings are generated to enable additional
duplicated code re-factoring.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/alpha/common/shared_intr.c
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/alpha/jensenio/jensenio_intr.c
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/alpha/pci/pci_1000.c
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/alpha/pci/pci_1000a.c \
src/sys/arch/alpha/pci/pci_6600.c src/sys/arch/alpha/pci/pci_machdep.c
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/alpha/pci/pci_2100_a500.c
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/alpha/pci/pci_550.c
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/alpha/pci/pci_eb164.c
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/alpha/pci/pci_eb64plus.c \
src/sys/arch/alpha/pci/pci_eb66.c
cvs rdiff -u -r1.56 -r1.57 src/sys/arch/alpha/pci/pci_kn20aa.c
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/alpha/pci/pci_kn300.c
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/alpha/pci/sio_pic.c

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

Modified files:

Index: src/sys/arch/alpha/common/shared_intr.c
diff -u src/sys/arch/alpha/common/shared_intr.c:1.27 src/sys/arch/alpha/common/shared_intr.c:1.28
--- src/sys/arch/alpha/common/shared_intr.c:1.27	Fri May  7 16:58:33 2021
+++ src/sys/arch/alpha/common/shared_intr.c	Fri Jun 25 18:08:34 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: shared_intr.c,v 1.27 2021/05/07 16:58:33 thorpej Exp $ */
+/* $NetBSD: shared_intr.c,v 1.28 2021/06/25 18:08:34 thorpej Exp $ */
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: shared_intr.c,v 1.27 2021/05/07 16:58:33 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: shared_intr.c,v 1.28 2021/06/25 18:08:34 thorpej Exp $");
 
 #include 
 #include 
@@ -170,7 +170,7 @@ alpha_shared_intr_alloc_intrhand(struct 
 	struct alpha_shared_intrhand *ih;
 
 	if (intr[num].intr_sharetype == IST_UNUSABLE) {
-		printf("%s: %s %d: unusable\n", __func__,
+		printf("%s: %s irq %d: unusable\n", __func__,
 		basename, num);
 		return NULL;
 	}
@@ -249,12 +249,12 @@ alpha_shared_intr_link(struct alpha_shar
 	case IST_PULSE:
 		if (type != IST_NONE) {
 			if (intr[num].intr_q.tqh_first == NULL) {
-printf("alpha_shared_intr_establish: %s %d: warning: using %s on %s\n",
+printf("alpha_shared_intr_establish: %s irq %d: warning: using %s on %s\n",
 basename, num, intr_typename(type),
 intr_typename(intr[num].intr_sharetype));
 type = intr[num].intr_sharetype;
 			} else {
-printf("alpha_shared_intr_establish: %s %d: can't share %s with %s\n",
+printf("alpha_shared_intr_establish: %s irq %d: can't share %s with %s\n",
 basename, num, intr_typename(type),
 intr_typename(intr[num].intr_sharetype));
 return (false);
@@ -381,7 +381,7 @@ alpha_shared_intr_stray(struct alpha_sha
 		return;
 
 	if (intr[num].intr_nstrays <= intr[num].intr_maxstrays)
-		log(LOG_ERR, "stray %s %d%s\n", basename, num,
+		log(LOG_ERR, "stray %s irq %d%s\n", basename, num,
 		intr[num].intr_nstrays >= intr[num].intr_maxstrays ?
 		  "; stopped logging" : "");
 }

Index: src/sys/arch/alpha/jensenio/jensenio_intr.c
diff -u src/sys/arch/alpha/jensenio/jensenio_intr.c:1.14 src/sys/arch/alpha/jensenio/jensenio_intr.c:1.15
--- src/sys/arch/alpha/jensenio/jensenio_intr.c:1.14	Fri May  7 16:58:34 2021
+++ src/sys/arch/alpha/jensenio/jensenio_intr.c	Fri Jun 25 18:08:34 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: jensenio_intr.c,v 1.14 2021/05/07 16:58:34 thorpej Exp $ */
+/* $NetBSD: jensenio_intr.c,v 1.15 2021/06/25 18:08:34 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: jensenio_intr.c,v 1.14 2021/05/07 16:58:34 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: jensenio_intr.c,v 1.15 2021/06/25 18:08:34 thorpej Exp $");
 
 #include 
 #include 
@@ -269,14 +269,14 @@ jensenio_eisa_intr_establish(void *v, in
 	}
 
 	cookie = alpha_shared_intr_alloc_intrhand(jensenio_eisa_intr, irq,
-	type, level, 0, fn, arg, "eisa irq");
+	type, level, 0, fn, arg, "eisa");
 
 	if (cookie == NULL)
 		return NULL;
 
 	mutex_enter(_lock);
 
-	if (! alpha_shared_intr_link(jensenio_eisa_intr, cookie, "eisa irq")) {
+	if (! alpha_shared_intr_link(jensenio_eisa_intr, cookie, "eisa")) {
 		mutex_exit(_lock);
 		alpha_shared_intr_free_intrhand(cookie);
 		return NULL;
@@ -310,7 +310,7 @@ 

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

2021-06-25 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jun 25 13:41:34 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: pci_2100_a50.c pci_axppci_33.c sio_pic.c
siovar.h

Log Message:
Reduce code duplication among platforms that use the i82378 SIO to
route PCI interrupts to the ISA PIC by refactoring it into a new
sio_pirq_intr_map() function.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/alpha/pci/pci_2100_a50.c
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/alpha/pci/pci_axppci_33.c
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/alpha/pci/sio_pic.c
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/alpha/pci/siovar.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/alpha/pci/pci_2100_a50.c
diff -u src/sys/arch/alpha/pci/pci_2100_a50.c:1.43 src/sys/arch/alpha/pci/pci_2100_a50.c:1.44
--- src/sys/arch/alpha/pci/pci_2100_a50.c:1.43	Sat Jun 19 16:59:07 2021
+++ src/sys/arch/alpha/pci/pci_2100_a50.c	Fri Jun 25 13:41:33 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_2100_a50.c,v 1.43 2021/06/19 16:59:07 thorpej Exp $ */
+/* $NetBSD: pci_2100_a50.c,v 1.44 2021/06/25 13:41:33 thorpej Exp $ */
 
 /*
  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
@@ -29,7 +29,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pci_2100_a50.c,v 1.43 2021/06/19 16:59:07 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_2100_a50.c,v 1.44 2021/06/25 13:41:33 thorpej Exp $");
 
 #include 
 #include 
@@ -57,21 +57,10 @@ __KERNEL_RCSID(0, "$NetBSD: pci_2100_a50
 static int	dec_2100_a50_intr_map(const struct pci_attach_args *,
 		pci_intr_handle_t *);
 
-#define	APECS_SIO_DEVICE	7	/* XXX */
-
 static void
 pci_2100_a50_pickintr(void *core, bus_space_tag_t iot, bus_space_tag_t memt,
 pci_chipset_tag_t pc)
 {
-	pcireg_t sioclass;
-	int sioII;
-
-	/* XXX MAGIC NUMBER */
-	sioclass = pci_conf_read(pc, pci_make_tag(pc, 0, 7, 0), PCI_CLASS_REG);
-	sioII = (sioclass & 0xff) >= 3;
-
-	if (!sioII)
-		printf("WARNING: SIO NOT SIO II... NO BETS...\n");
 
 	pc->pc_intr_v = core;
 	pc->pc_intr_map = dec_2100_a50_intr_map;
@@ -98,8 +87,6 @@ dec_2100_a50_intr_map(const struct pci_a
 	int buspin = pa->pa_intrpin;
 	pci_chipset_tag_t pc = pa->pa_pc;
 	int device, pirq;
-	pcireg_t pirqreg;
-	uint8_t pirqline;
 
 #ifndef DIAGNOSTIC
 	pirq = 0;/* XXX gcc -Wuninitialized */
@@ -189,22 +176,10 @@ dec_2100_a50_intr_map(const struct pci_a
 	return 1;
 	}
 
-	pirqreg = pci_conf_read(pc, pci_make_tag(pc, 0, APECS_SIO_DEVICE, 0),
-	SIO_PCIREG_PIRQ_RTCTRL);
-#if 0
-	printf("pci_2100_a50_intr_map: device %d pin %c: pirq %d, reg = %x\n",
-		device, '@' + buspin, pirq, pirqreg);
-#endif
-	pirqline = (pirqreg >> (pirq * 8)) & 0xff;
-	if ((pirqline & 0x80) != 0)
-		return 1;
-	pirqline &= 0xf;
-
 #if 0
-	printf("pci_2100_a50_intr_map: device %d pin %c: mapped to line %d\n",
-	device, '@' + buspin, pirqline);
+	printf("pci_2100_a50_intr_map: device %d pin %c: pirq %d\n",
+		device, '@' + buspin, pirq);
 #endif
 
-	alpha_pci_intr_handle_init(ihp, pirqline, 0);
-	return (0);
+	return sio_pirq_intr_map(pc, pirq, ihp);
 }

Index: src/sys/arch/alpha/pci/pci_axppci_33.c
diff -u src/sys/arch/alpha/pci/pci_axppci_33.c:1.40 src/sys/arch/alpha/pci/pci_axppci_33.c:1.41
--- src/sys/arch/alpha/pci/pci_axppci_33.c:1.40	Sat Jun 19 16:59:07 2021
+++ src/sys/arch/alpha/pci/pci_axppci_33.c	Fri Jun 25 13:41:33 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_axppci_33.c,v 1.40 2021/06/19 16:59:07 thorpej Exp $ */
+/* $NetBSD: pci_axppci_33.c,v 1.41 2021/06/25 13:41:33 thorpej Exp $ */
 
 /*
  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
@@ -29,7 +29,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pci_axppci_33.c,v 1.40 2021/06/19 16:59:07 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_axppci_33.c,v 1.41 2021/06/25 13:41:33 thorpej Exp $");
 
 #include 
 #include 
@@ -57,22 +57,10 @@ __KERNEL_RCSID(0, "$NetBSD: pci_axppci_3
 static int	dec_axppci_33_intr_map(const struct pci_attach_args *,
 		pci_intr_handle_t *);
 
-#define	LCA_SIO_DEVICE	7	/* XXX */
-
 static void
 pci_axppci_33_pickintr(void *core, bus_space_tag_t iot, bus_space_tag_t memt,
 pci_chipset_tag_t pc)
 {
-	pcireg_t sioclass;
-	int sioII;
-
-	/* XXX MAGIC NUMBER */
-	sioclass = pci_conf_read(pc, pci_make_tag(pc, 0, LCA_SIO_DEVICE, 0),
-	PCI_CLASS_REG);
-	sioII = (sioclass & 0xff) >= 3;
-
-	if (!sioII)
-		printf("WARNING: SIO NOT SIO II... NO BETS...\n");
 
 	pc->pc_intr_v = core;
 	pc->pc_intr_map = dec_axppci_33_intr_map;
@@ -99,8 +87,6 @@ dec_axppci_33_intr_map(const struct pci_
 	int buspin = pa->pa_intrpin;
 	pci_chipset_tag_t pc = pa->pa_pc;
 	int device, pirq;
-	pcireg_t pirqreg;
-	uint8_t pirqline;
 
 #ifndef DIAGNOSTIC
 	pirq = 0;/* XXX gcc -Wuninitialized */
@@ -189,22 +175,10 @@ dec_axppci_33_intr_map(const struct pci_
 	return 1;
 	}
 
-	pirqreg = 

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

2021-06-25 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jun 25 13:38:21 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: pci_alphabook1.c

Log Message:
Remove pointless warning.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/alpha/pci/pci_alphabook1.c

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

Modified files:

Index: src/sys/arch/alpha/pci/pci_alphabook1.c
diff -u src/sys/arch/alpha/pci/pci_alphabook1.c:1.19 src/sys/arch/alpha/pci/pci_alphabook1.c:1.20
--- src/sys/arch/alpha/pci/pci_alphabook1.c:1.19	Sat Jun 19 16:59:07 2021
+++ src/sys/arch/alpha/pci/pci_alphabook1.c	Fri Jun 25 13:38:21 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_alphabook1.c,v 1.19 2021/06/19 16:59:07 thorpej Exp $ */
+/* $NetBSD: pci_alphabook1.c,v 1.20 2021/06/25 13:38:21 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pci_alphabook1.c,v 1.19 2021/06/19 16:59:07 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_alphabook1.c,v 1.20 2021/06/25 13:38:21 thorpej Exp $");
 
 #include 
 #include 
@@ -85,22 +85,10 @@ __KERNEL_RCSID(0, "$NetBSD: pci_alphaboo
 static int	dec_alphabook1_intr_map(const struct pci_attach_args *,
 		pci_intr_handle_t *);
 
-#define	LCA_SIO_DEVICE	7	/* XXX */
-
 static void
 pci_alphabook1_pickintr(void *core, bus_space_tag_t iot, bus_space_tag_t memt,
 pci_chipset_tag_t pc)
 {
-	pcireg_t sioclass;
-	int sioII;
-
-	/* XXX MAGIC NUMBER */
-	sioclass = pci_conf_read(pc, pci_make_tag(pc, 0, LCA_SIO_DEVICE, 0),
-	PCI_CLASS_REG);
-	sioII = (sioclass & 0xff) >= 3;
-
-	if (!sioII)
-		printf("WARNING: SIO NOT SIO II... NO BETS...\n");
 
 	pc->pc_intr_v = core;
 	pc->pc_intr_map = dec_alphabook1_intr_map;



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

2021-06-25 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jun 25 13:32:39 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: sioreg.h

Log Message:
Define macros to desribe the PIRQ_RTCTRL register(s).


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/alpha/pci/sioreg.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/alpha/pci/sioreg.h
diff -u src/sys/arch/alpha/pci/sioreg.h:1.2 src/sys/arch/alpha/pci/sioreg.h:1.3
--- src/sys/arch/alpha/pci/sioreg.h:1.2	Mon Apr  7 02:00:07 1997
+++ src/sys/arch/alpha/pci/sioreg.h	Fri Jun 25 13:32:39 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sioreg.h,v 1.2 1997/04/07 02:00:07 cgd Exp $ */
+/* $NetBSD: sioreg.h,v 1.3 2021/06/25 13:32:39 thorpej Exp $ */
 
 /*
  * Copyright (c) 1996 BBN Corporation.
@@ -83,6 +83,13 @@
 #define	SIO_PCIREG_PIRQ3	0x63	/* PIRQ3 Route Control */
 #define	SIO_PCIREG_PIRQ_RTCTRL	SIO_PCIREG_PIRQ0
 
+	/* extract the PIRQx field from 32-bit reg */
+#define	PIRQ_RTCTRL_PIRQx(r, p)	(((r) >> ((p) * 8)) & 0xff)
+
+	/* bits within each PIRQx field */
+#define	PIRQ_RTCTRL_NOT_ROUTED	__BIT(7)/* 0 == interrupt routed */
+#define	PIRQ_RTCTRL_IRQ		__BITS(0,3) /* PIRQ routed to this ISA IRQ */
+
 /*
  * System Management Interrupt (SMI)
  */



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

2021-06-24 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jun 25 03:52:41 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: lca_pci.c

Log Message:
- Use the default implementations of attach_hook(), make_tag(), and
  decompose_tag().
- In lca_bus_maxdevs(), only allow devices 0-15 on bus #0.
- Re-factor some duplicated code into lca_make_type0addr().


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/alpha/pci/lca_pci.c

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

Modified files:

Index: src/sys/arch/alpha/pci/lca_pci.c
diff -u src/sys/arch/alpha/pci/lca_pci.c:1.23 src/sys/arch/alpha/pci/lca_pci.c:1.24
--- src/sys/arch/alpha/pci/lca_pci.c:1.23	Fri May  7 16:58:34 2021
+++ src/sys/arch/alpha/pci/lca_pci.c	Fri Jun 25 03:52:41 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lca_pci.c,v 1.23 2021/05/07 16:58:34 thorpej Exp $ */
+/* $NetBSD: lca_pci.c,v 1.24 2021/06/25 03:52:41 thorpej Exp $ */
 
 /*
  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
@@ -29,7 +29,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: lca_pci.c,v 1.23 2021/05/07 16:58:34 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lca_pci.c,v 1.24 2021/06/25 03:52:41 thorpej Exp $");
 
 #include 
 #include 
@@ -41,11 +41,7 @@ __KERNEL_RCSID(0, "$NetBSD: lca_pci.c,v 
 #include 
 #include 
 
-static void	lca_attach_hook(device_t, device_t,
-		struct pcibus_attach_args *);
 static int	lca_bus_maxdevs(void *, int);
-static pcitag_t	lca_make_tag(void *, int, int, int);
-static void	lca_decompose_tag(void *, pcitag_t, int *, int *, int *);
 static pcireg_t	lca_conf_read(void *, pcitag_t, int);
 static void	lca_conf_write(void *, pcitag_t, int, pcireg_t);
 
@@ -54,46 +50,26 @@ lca_pci_init(pci_chipset_tag_t pc, void 
 {
 
 	pc->pc_conf_v = v;
-	pc->pc_attach_hook = lca_attach_hook;
 	pc->pc_bus_maxdevs = lca_bus_maxdevs;
-	pc->pc_make_tag = lca_make_tag;
-	pc->pc_decompose_tag = lca_decompose_tag;
 	pc->pc_conf_read = lca_conf_read;
 	pc->pc_conf_write = lca_conf_write;
 }
 
-static void
-lca_attach_hook(device_t parent, device_t self, struct pcibus_attach_args *pba)
-{
-}
-
 static int
 lca_bus_maxdevs(void *cpv, int busno)
 {
-
-	if (busno == 0)
-		return 16;
-	else
-		return 32;
+	/*
+	 * We have to drive the IDSEL directly on bus 0, so we are
+	 * limited to 16 devices there.
+	 */
+	return busno == 0 ? 16 : 32;
 }
 
-static pcitag_t
-lca_make_tag(void *cpv, int b, int d, int f)
+static paddr_t
+lca_make_type0addr(int d, int f)
 {
-
-	return (b << 16) | (d << 11) | (f << 8);
-}
-
-static void
-lca_decompose_tag(void *cpv, pcitag_t tag, int *bp, int *dp, int *fp)
-{
-
-	if (bp != NULL)
-		*bp = (tag >> 16) & 0xff;
-	if (dp != NULL)
-		*dp = (tag >> 11) & 0x1f;
-	if (fp != NULL)
-		*fp = (tag >> 8) & 0x7;
+	KASSERT(d < 16);
+	return PCI_CONF_TYPE0_IDSEL(d) | __SHIFTIN(f, PCI_CONF_TYPE0_FUNCTION);
 }
 
 static pcireg_t
@@ -101,7 +77,8 @@ lca_conf_read(void *cpv, pcitag_t tag, i
 {
 	struct lca_config *lcp = cpv;
 	pcireg_t *datap, data;
-	int s, secondary, device, ba;
+	paddr_t confaddr;
+	int s, secondary, d, f, ba;
 
 	if ((unsigned int)offset >= PCI_CONF_SIZE)
 		return (pcireg_t) -1;
@@ -109,24 +86,19 @@ lca_conf_read(void *cpv, pcitag_t tag, i
 	s = 0;	/* XXX gcc -Wuninitialized */
 
 	/* secondary if bus # != 0 */
-	pci_decompose_tag(>lc_pc, tag, , , 0);
+	pci_decompose_tag(>lc_pc, tag, , , );
 	if (secondary) {
 		s = splhigh();
 		alpha_mb();
 		REGVAL(LCA_IOC_CONF) = 0x01;
 		alpha_mb();
+		confaddr = tag;
 	} else {
-		/*
-		 * on the LCA, must frob the tag used for
-		 * devices on the primary bus, in the same ways
-		 * as is used by type 1 configuration cycles
-		 * on PCs.
-		 */
-		tag = (1 << (device + 11)) | (tag & 0x7ff);
+		confaddr = lca_make_type0addr(d, f);
 	}
 
 	datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(LCA_PCI_CONF |
-	tag << 5UL |	/* XXX */
+	confaddr << 5UL |	/* XXX */
 	(offset & ~0x03) << 5 |/* XXX */
 	0 << 5 |		/* XXX */
 	0x3 << 3);		/* XXX */
@@ -154,7 +126,8 @@ lca_conf_write(void *cpv, pcitag_t tag, 
 {
 	struct lca_config *lcp = cpv;
 	pcireg_t *datap;
-	int s, secondary, device;
+	paddr_t confaddr;
+	int s, secondary, d, f;
 
 	if ((unsigned int)offset >= PCI_CONF_SIZE)
 		return;
@@ -162,24 +135,19 @@ lca_conf_write(void *cpv, pcitag_t tag, 
 	s = 0;	/* XXX gcc -Wuninitialized */
 
 	/* secondary if bus # != 0 */
-	pci_decompose_tag(>lc_pc, tag, , , 0);
+	pci_decompose_tag(>lc_pc, tag, , , );
 	if (secondary) {
 		s = splhigh();
 		alpha_mb();
 		REGVAL(LCA_IOC_CONF) = 0x01;
 		alpha_mb();
+		confaddr = tag;
 	} else {
-		/*
-		 * on the LCA, must frob the tag used for
-		 * devices on the primary bus, in the same ways
-		 * as is used by type 1 configuration cycles
-		 * on PCs.
-		 */
-		tag = (1 << (device + 11)) | (tag & 0x7ff);
+		confaddr = lca_make_type0addr(d, f);
 	}
 
 	datap = (pcireg_t 

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

2021-06-24 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jun 25 03:49:47 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: ttwoga_pci.c

Log Message:
- Use the default implementations of attach_hook(), make_tag(), and
  decompose_tag().
- In ttwoga_make_type0addr(), assert that we have an IDSEL in our range,
  and otherwise always succeed.
- In ttwoga_bus_maxdevs(), allow only devices 0-9 on bus #0.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/alpha/pci/ttwoga_pci.c

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

Modified files:

Index: src/sys/arch/alpha/pci/ttwoga_pci.c
diff -u src/sys/arch/alpha/pci/ttwoga_pci.c:1.9 src/sys/arch/alpha/pci/ttwoga_pci.c:1.10
--- src/sys/arch/alpha/pci/ttwoga_pci.c:1.9	Fri May  7 16:58:34 2021
+++ src/sys/arch/alpha/pci/ttwoga_pci.c	Fri Jun 25 03:49:47 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ttwoga_pci.c,v 1.9 2021/05/07 16:58:34 thorpej Exp $ */
+/* $NetBSD: ttwoga_pci.c,v 1.10 2021/06/25 03:49:47 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: ttwoga_pci.c,v 1.9 2021/05/07 16:58:34 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ttwoga_pci.c,v 1.10 2021/06/25 03:49:47 thorpej Exp $");
 
 #include 
 #include 
@@ -44,12 +44,7 @@ __KERNEL_RCSID(0, "$NetBSD: ttwoga_pci.c
 #include 
 #include 
 
-static void	ttwoga_attach_hook(device_t, device_t,
-		struct pcibus_attach_args *);
 static int	ttwoga_bus_maxdevs(void *, int);
-static pcitag_t	ttwoga_make_tag(void *, int, int, int);
-static void	ttwoga_decompose_tag(void *, pcitag_t, int *, int *,
-		int *);
 static pcireg_t	ttwoga_conf_read(void *, pcitag_t, int);
 static void	ttwoga_conf_write(void *, pcitag_t, int, pcireg_t);
 
@@ -87,54 +82,26 @@ ttwoga_pci_init(pci_chipset_tag_t pc, vo
 	mutex_init(_conf_lock, MUTEX_DEFAULT, IPL_HIGH);
 
 	pc->pc_conf_v = v;
-	pc->pc_attach_hook = ttwoga_attach_hook;
 	pc->pc_bus_maxdevs = ttwoga_bus_maxdevs;
-	pc->pc_make_tag = ttwoga_make_tag;
-	pc->pc_decompose_tag = ttwoga_decompose_tag;
 	pc->pc_conf_read = ttwoga_conf_read;
 	pc->pc_conf_write = ttwoga_conf_write;
 }
 
-static void
-ttwoga_attach_hook(device_t parent, device_t self,
-struct pcibus_attach_args *pba)
-{
-}
-
 static int
 ttwoga_bus_maxdevs(void *cpv, int busno)
 {
-
-	return 32;
-}
-
-static pcitag_t
-ttwoga_make_tag(void *cpv, int b, int d, int f)
-{
-
-	/* This is the format used for Type 1 configuration cycles. */
-	return (b << 16) | (d << 11) | (f << 8);
-}
-
-static void
-ttwoga_decompose_tag(void *cpv, pcitag_t tag, int *bp, int *dp, int *fp)
-{
-
-	if (bp != NULL)
-		*bp = (tag >> 16) & 0xff;
-	if (dp != NULL)
-		*dp = (tag >> 11) & 0x1f;
-	if (fp != NULL)
-		*fp = (tag >> 8) & 0x7;
+	/*
+	 * We have to drive the IDSEL directly on bus 0, so we are
+	 * limited to 9 devices there.
+	 */
+	return busno == 0 ? 9 : 32;
 }
 
 static paddr_t
 ttwoga_make_type0addr(int d, int f)
 {
-
-	if (d > 8)			/* XXX ??? */
-		return ((paddr_t) -1);
-	return ((0x0800UL << d) | (f << 8));
+	KASSERT(d < 9);
+	return PCI_CONF_TYPE0_IDSEL(d) | __SHIFTIN(f, PCI_CONF_TYPE1_FUNCTION);
 }
 
 static pcireg_t
@@ -152,8 +119,6 @@ ttwoga_conf_read(void *cpv, pcitag_t tag
 	pci_decompose_tag(>tc_pc, tag, , , );
 
 	addr = b ? tag : ttwoga_make_type0addr(d, f);
-	if (addr == (paddr_t)-1)
-		return ((pcireg_t) -1);
 
 	TTWOGA_CONF_LOCK();
 
@@ -207,8 +172,6 @@ ttwoga_conf_write(void *cpv, pcitag_t ta
 	pci_decompose_tag(>tc_pc, tag, , , );
 
 	addr = b ? tag : ttwoga_make_type0addr(d, f);
-	if (addr == (paddr_t)-1)
-		return;
 
 	TTWOGA_CONF_LOCK();
 



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

2021-06-24 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jun 25 03:46:54 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: mcpcia_pci.c

Log Message:
Use the default implementation of attach_hook().


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/alpha/pci/mcpcia_pci.c

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

Modified files:

Index: src/sys/arch/alpha/pci/mcpcia_pci.c
diff -u src/sys/arch/alpha/pci/mcpcia_pci.c:1.13 src/sys/arch/alpha/pci/mcpcia_pci.c:1.14
--- src/sys/arch/alpha/pci/mcpcia_pci.c:1.13	Fri May  7 16:58:34 2021
+++ src/sys/arch/alpha/pci/mcpcia_pci.c	Fri Jun 25 03:46:54 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: mcpcia_pci.c,v 1.13 2021/05/07 16:58:34 thorpej Exp $ */
+/* $NetBSD: mcpcia_pci.c,v 1.14 2021/06/25 03:46:54 thorpej Exp $ */
 
 /*
  * Copyright (c) 1998 by Matthew Jacob
@@ -32,7 +32,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: mcpcia_pci.c,v 1.13 2021/05/07 16:58:34 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mcpcia_pci.c,v 1.14 2021/06/25 03:46:54 thorpej Exp $");
 
 #include 
 #include 
@@ -46,8 +46,6 @@ __KERNEL_RCSID(0, "$NetBSD: mcpcia_pci.c
 
 #define	KV(_addr)	((void *)ALPHA_PHYS_TO_K0SEG((_addr)))
 
-static void	mcpcia_attach_hook(device_t, device_t,
-		struct pcibus_attach_args *);
 static int	mcpcia_bus_maxdevs(void *, int);
 static pcitag_t	mcpcia_make_tag(void *, int, int, int);
 static void	mcpcia_decompose_tag(void *, pcitag_t, int *, int *, int *);
@@ -58,7 +56,6 @@ void
 mcpcia_pci_init(pci_chipset_tag_t pc, void *v)
 {
 	pc->pc_conf_v = v;
-	pc->pc_attach_hook = mcpcia_attach_hook;
 	pc->pc_bus_maxdevs = mcpcia_bus_maxdevs;
 	pc->pc_make_tag = mcpcia_make_tag;
 	pc->pc_decompose_tag = mcpcia_decompose_tag;
@@ -66,11 +63,6 @@ mcpcia_pci_init(pci_chipset_tag_t pc, vo
 	pc->pc_conf_write = mcpcia_conf_write;
 }
 
-static void
-mcpcia_attach_hook(device_t parent, device_t self, struct pcibus_attach_args *pba)
-{
-}
-
 static int
 mcpcia_bus_maxdevs(void *cpv, int busno)
 {



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

2021-06-24 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jun 25 03:46:30 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: dwlpx_pci.c

Log Message:
Use the default implementation of attach_hook().


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/alpha/pci/dwlpx_pci.c

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

Modified files:

Index: src/sys/arch/alpha/pci/dwlpx_pci.c
diff -u src/sys/arch/alpha/pci/dwlpx_pci.c:1.20 src/sys/arch/alpha/pci/dwlpx_pci.c:1.21
--- src/sys/arch/alpha/pci/dwlpx_pci.c:1.20	Fri May  7 16:58:34 2021
+++ src/sys/arch/alpha/pci/dwlpx_pci.c	Fri Jun 25 03:46:30 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: dwlpx_pci.c,v 1.20 2021/05/07 16:58:34 thorpej Exp $ */
+/* $NetBSD: dwlpx_pci.c,v 1.21 2021/06/25 03:46:30 thorpej Exp $ */
 
 /*
  * Copyright (c) 1997 by Matthew Jacob
@@ -32,7 +32,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: dwlpx_pci.c,v 1.20 2021/05/07 16:58:34 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwlpx_pci.c,v 1.21 2021/06/25 03:46:30 thorpej Exp $");
 
 #include 
 #include 
@@ -47,8 +47,6 @@ __KERNEL_RCSID(0, "$NetBSD: dwlpx_pci.c,
 
 #define	KV(_addr)	((void *)ALPHA_PHYS_TO_K0SEG((_addr)))
 
-static void	dwlpx_attach_hook(device_t, device_t,
-		struct pcibus_attach_args *);
 static int	dwlpx_bus_maxdevs(void *, int);
 static pcitag_t	dwlpx_make_tag(void *, int, int, int);
 static void	dwlpx_decompose_tag(void *, pcitag_t, int *, int *,
@@ -60,7 +58,6 @@ void
 dwlpx_pci_init(pci_chipset_tag_t pc, void *v)
 {
 	pc->pc_conf_v = v;
-	pc->pc_attach_hook = dwlpx_attach_hook;
 	pc->pc_bus_maxdevs = dwlpx_bus_maxdevs;
 	pc->pc_make_tag = dwlpx_make_tag;
 	pc->pc_decompose_tag = dwlpx_decompose_tag;
@@ -68,11 +65,6 @@ dwlpx_pci_init(pci_chipset_tag_t pc, voi
 	pc->pc_conf_write = dwlpx_conf_write;
 }
 
-static void
-dwlpx_attach_hook(device_t parent, device_t self, struct pcibus_attach_args *pba)
-{
-}
-
 static int
 dwlpx_bus_maxdevs(void *cpv, int busno)
 {



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

2021-06-24 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jun 25 03:45:59 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: apecs_pci.c cia_pci.c irongate_pci.c tsp_pci.c

Log Message:
Use the default implementations of attach_hook(), bus_maxdevs(),
make_tag(), and decompose_tag().


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/alpha/pci/apecs_pci.c
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/alpha/pci/cia_pci.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/alpha/pci/irongate_pci.c \
src/sys/arch/alpha/pci/tsp_pci.c

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

Modified files:

Index: src/sys/arch/alpha/pci/apecs_pci.c
diff -u src/sys/arch/alpha/pci/apecs_pci.c:1.27 src/sys/arch/alpha/pci/apecs_pci.c:1.28
--- src/sys/arch/alpha/pci/apecs_pci.c:1.27	Fri May  7 16:58:34 2021
+++ src/sys/arch/alpha/pci/apecs_pci.c	Fri Jun 25 03:45:59 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: apecs_pci.c,v 1.27 2021/05/07 16:58:34 thorpej Exp $ */
+/* $NetBSD: apecs_pci.c,v 1.28 2021/06/25 03:45:59 thorpej Exp $ */
 
 /*
  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
@@ -29,7 +29,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: apecs_pci.c,v 1.27 2021/05/07 16:58:34 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apecs_pci.c,v 1.28 2021/06/25 03:45:59 thorpej Exp $");
 
 #include 
 #include 
@@ -41,11 +41,6 @@ __KERNEL_RCSID(0, "$NetBSD: apecs_pci.c,
 #include 
 #include 
 
-static void	apecs_attach_hook(device_t, device_t,
-		struct pcibus_attach_args *);
-static int	apecs_bus_maxdevs(void *, int);
-static pcitag_t	apecs_make_tag(void *, int, int, int);
-static void	apecs_decompose_tag(void *, pcitag_t, int *, int *, int *);
 static pcireg_t	apecs_conf_read(void *, pcitag_t, int);
 static void	apecs_conf_write(void *, pcitag_t, int, pcireg_t);
 
@@ -54,45 +49,10 @@ apecs_pci_init(pci_chipset_tag_t pc, voi
 {
 
 	pc->pc_conf_v = v;
-	pc->pc_attach_hook = apecs_attach_hook;
-	pc->pc_bus_maxdevs = apecs_bus_maxdevs;
-	pc->pc_make_tag = apecs_make_tag;
-	pc->pc_decompose_tag = apecs_decompose_tag;
 	pc->pc_conf_read = apecs_conf_read;
 	pc->pc_conf_write = apecs_conf_write;
 }
 
-static void
-apecs_attach_hook(device_t parent, device_t self, struct pcibus_attach_args *pba)
-{
-}
-
-static int
-apecs_bus_maxdevs(void *cpv, int busno)
-{
-
-	return 32;
-}
-
-static pcitag_t
-apecs_make_tag(void *cpv, int b, int d, int f)
-{
-
-	return (b << 16) | (d << 11) | (f << 8);
-}
-
-static void
-apecs_decompose_tag(void *cpv, pcitag_t tag, int *bp, int *dp, int *fp)
-{
-
-	if (bp != NULL)
-		*bp = (tag >> 16) & 0xff;
-	if (dp != NULL)
-		*dp = (tag >> 11) & 0x1f;
-	if (fp != NULL)
-		*fp = (tag >> 8) & 0x7;
-}
-
 static pcireg_t
 apecs_conf_read(void *cpv, pcitag_t tag, int offset)
 {

Index: src/sys/arch/alpha/pci/cia_pci.c
diff -u src/sys/arch/alpha/pci/cia_pci.c:1.34 src/sys/arch/alpha/pci/cia_pci.c:1.35
--- src/sys/arch/alpha/pci/cia_pci.c:1.34	Fri May  7 16:58:34 2021
+++ src/sys/arch/alpha/pci/cia_pci.c	Fri Jun 25 03:45:59 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: cia_pci.c,v 1.34 2021/05/07 16:58:34 thorpej Exp $ */
+/* $NetBSD: cia_pci.c,v 1.35 2021/06/25 03:45:59 thorpej Exp $ */
 
 /*
  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
@@ -29,7 +29,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: cia_pci.c,v 1.34 2021/05/07 16:58:34 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cia_pci.c,v 1.35 2021/06/25 03:45:59 thorpej Exp $");
 
 #include 
 #include 
@@ -41,11 +41,6 @@ __KERNEL_RCSID(0, "$NetBSD: cia_pci.c,v 
 #include 
 #include 
 
-static void	cia_attach_hook(device_t, device_t,
-		struct pcibus_attach_args *);
-static int	cia_bus_maxdevs(void *, int);
-static pcitag_t	cia_make_tag(void *, int, int, int);
-static void	cia_decompose_tag(void *, pcitag_t, int *, int *, int *);
 static pcireg_t	cia_conf_read(void *, pcitag_t, int);
 static void	cia_conf_write(void *, pcitag_t, int, pcireg_t);
 
@@ -54,45 +49,10 @@ cia_pci_init(pci_chipset_tag_t pc, void 
 {
 
 	pc->pc_conf_v = v;
-	pc->pc_attach_hook = cia_attach_hook;
-	pc->pc_bus_maxdevs = cia_bus_maxdevs;
-	pc->pc_make_tag = cia_make_tag;
-	pc->pc_decompose_tag = cia_decompose_tag;
 	pc->pc_conf_read = cia_conf_read;
 	pc->pc_conf_write = cia_conf_write;
 }
 
-static void
-cia_attach_hook(device_t parent, device_t self, struct pcibus_attach_args *pba)
-{
-}
-
-static int
-cia_bus_maxdevs(void *cpv, int busno)
-{
-
-	return 32;
-}
-
-static pcitag_t
-cia_make_tag(void *cpv, int b, int d, int f)
-{
-
-	return (b << 16) | (d << 11) | (f << 8);
-}
-
-static void
-cia_decompose_tag(void *cpv, pcitag_t tag, int *bp, int *dp, int *fp)
-{
-
-	if (bp != NULL)
-		*bp = (tag >> 16) & 0xff;
-	if (dp != NULL)
-		*dp = (tag >> 11) & 0x1f;
-	if (fp != NULL)
-		*fp = (tag >> 8) & 0x7;
-}
-
 static pcireg_t
 cia_conf_read(void *cpv, pcitag_t tag, int offset)
 {

Index: src/sys/arch/alpha/pci/irongate_pci.c

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

2021-06-24 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jun 25 03:44:10 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: pci_machdep.c

Log Message:
Make the following PCI chipset functions optional:
- attach_hook()
- bus_maxdevs()
- make_tag()
- decompose_tag()
...and provide a default implementation for each.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/alpha/pci/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/alpha/pci/pci_machdep.c
diff -u src/sys/arch/alpha/pci/pci_machdep.c:1.29 src/sys/arch/alpha/pci/pci_machdep.c:1.30
--- src/sys/arch/alpha/pci/pci_machdep.c:1.29	Sat Jun 19 16:59:07 2021
+++ src/sys/arch/alpha/pci/pci_machdep.c	Fri Jun 25 03:44:10 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_machdep.c,v 1.29 2021/06/19 16:59:07 thorpej Exp $ */
+/* $NetBSD: pci_machdep.c,v 1.30 2021/06/25 03:44:10 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.29 2021/06/19 16:59:07 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.30 2021/06/25 03:44:10 thorpej Exp $");
 
 #include 
 #include 
@@ -481,14 +481,18 @@ pci_attach_hook(device_t const parent, d
 {
 	pci_chipset_tag_t const pc = pba->pba_pc;
 
-	KASSERT(pc->pc_attach_hook != NULL);
-	pc->pc_attach_hook(parent, self, pba);
+	if (pc->pc_attach_hook != NULL) {
+		pc->pc_attach_hook(parent, self, pba);
+	}
 }
 
 int
 pci_bus_maxdevs(pci_chipset_tag_t const pc, int const busno)
 {
-	KASSERT(pc->pc_bus_maxdevs != NULL);
+	if (pc->pc_bus_maxdevs == NULL) {
+		return 32;
+	}
+
 	return pc->pc_bus_maxdevs(pc->pc_conf_v, busno);
 }
 
@@ -496,7 +500,13 @@ pcitag_t
 pci_make_tag(pci_chipset_tag_t const pc, int const bus, int const dev,
 int const func)
 {
-	KASSERT(pc->pc_make_tag != NULL);
+	if (__predict_true(pc->pc_make_tag == NULL)) {
+		/* Just use the standard Type 1 address format. */
+		return __SHIFTIN(bus, PCI_CONF_TYPE1_BUS) |
+		   __SHIFTIN(dev, PCI_CONF_TYPE1_DEVICE) |
+		   __SHIFTIN(func, PCI_CONF_TYPE1_FUNCTION);
+	}
+
 	return pc->pc_make_tag(pc->pc_conf_v, bus, dev, func);
 }
 
@@ -504,7 +514,16 @@ void
 pci_decompose_tag(pci_chipset_tag_t const pc, pcitag_t const tag,
 int * const busp, int * const devp, int * const funcp)
 {
-	KASSERT(pc->pc_decompose_tag != NULL);
+	if (__predict_true(pc->pc_decompose_tag == NULL)) {
+		if (busp != NULL)
+			*busp = __SHIFTOUT(tag, PCI_CONF_TYPE1_BUS);
+		if (devp != NULL)
+			*devp = __SHIFTOUT(tag, PCI_CONF_TYPE1_DEVICE);
+		if (funcp != NULL)
+			*funcp = __SHIFTOUT(tag, PCI_CONF_TYPE1_FUNCTION);
+		return;
+	}
+
 	pc->pc_decompose_tag(pc->pc_conf_v, tag, busp, devp, funcp);
 }
 



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

2021-06-24 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Thu Jun 24 16:41:16 UTC 2021

Modified Files:
src/sys/arch/alpha/common: sgmap_typedep.c

Log Message:
Deal with a scenario where:
- DMA map has a boundary constraint.
- Caller asks us to map a buffer that's exactly the same size as the
  boundary constraint, but is not page-aligned.

This results in the size being larger than the boundary constraint after
page-rounding, and and vmem_xalloc() fires a KASSERT for it.  This is
easy to trigger by running fsck.

We handle this by detecting the condition and creating an extra DMA
segment for it the spill-over.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/alpha/common/sgmap_typedep.c

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

Modified files:

Index: src/sys/arch/alpha/common/sgmap_typedep.c
diff -u src/sys/arch/alpha/common/sgmap_typedep.c:1.41 src/sys/arch/alpha/common/sgmap_typedep.c:1.42
--- src/sys/arch/alpha/common/sgmap_typedep.c:1.41	Thu Apr 15 00:11:09 2021
+++ src/sys/arch/alpha/common/sgmap_typedep.c	Thu Jun 24 16:41:16 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sgmap_typedep.c,v 1.41 2021/04/15 00:11:09 rin Exp $ */
+/* $NetBSD: sgmap_typedep.c,v 1.42 2021/06/24 16:41:16 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.41 2021/04/15 00:11:09 rin Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.42 2021/06/24 16:41:16 thorpej Exp $");
 
 #include "opt_ddb.h"
 
@@ -60,23 +60,31 @@ __C(SGMAP_TYPE,_init_spill_page_pte)(voi
 }
 
 DMA_COUNT_DECL(spill_page);
+DMA_COUNT_DECL(extra_segment);
+DMA_COUNT_DECL(extra_segment_and_spill);
 
 static int
 __C(SGMAP_TYPE,_load_buffer)(bus_dma_tag_t t, bus_dmamap_t map, void *buf,
-size_t buflen, struct vmspace *vm, int flags, int seg,
+size_t buflen, struct vmspace *vm, int flags, int * const segp,
 struct alpha_sgmap *sgmap)
 {
 	vaddr_t endva, va = (vaddr_t)buf;
 	paddr_t pa;
-	bus_addr_t dmaoffset, sgva;
-	bus_size_t sgvalen, boundary, alignment;
+	bus_addr_t dmaoffset, sgva, extra_sgva;
+	bus_size_t sgvalen, extra_sgvalen, boundary, alignment;
 	SGMAP_PTE_TYPE *pte, *page_table = sgmap->aps_pt;
-	int pteidx, error, spill;
+	int pteidx, error, spill, seg = *segp;
 
 	/* Initialize the spill page PTE if it hasn't been already. */
 	if (__C(SGMAP_TYPE,_prefetch_spill_page_pte) == 0)
 		__C(SGMAP_TYPE,_init_spill_page_pte)();
 
+	if (seg == map->_dm_segcnt) {
+		/* Ran of segments. */
+		return EFBIG;
+	}
+	KASSERT(seg < map->_dm_segcnt);
+
 	/*
 	 * Remember the offset into the first page and the total
 	 * transfer length.
@@ -106,13 +114,77 @@ __C(SGMAP_TYPE,_load_buffer)(bus_dma_tag
 	else
 		spill = 0;
 
+	boundary = map->_dm_boundary;
+
+	/*
+	 * Caller's mistake if the requested length is larger than
+	 * their own boundary constraint.
+	 */
+	if (__predict_false(boundary != 0 && buflen > boundary)) {
+		return EINVAL;
+	}
+
 	endva = round_page(va + buflen);
 	va = trunc_page(va);
 
-	boundary = map->_dm_boundary;
-	alignment = PAGE_SIZE;
+	const vm_flag_t vmflags = VM_INSTANTFIT |
+	((flags & BUS_DMA_NOWAIT) ? VM_NOSLEEP : VM_SLEEP);
 
+	alignment = PAGE_SIZE;
 	sgvalen = (endva - va);
+
+	SGMAP_PTE_TYPE spill_pte_v = __C(SGMAP_TYPE,_prefetch_spill_page_pte);
+
+	/*
+	 * If we have a boundary constraint, it's possible to end up in
+	 * a situation where sgvalen > boundary if the caller's buffer
+	 * is not page aligned.  In this case, we will have to allocate
+	 * an extra SG segment and split the buffer.
+	 */
+	if (__predict_false(boundary != 0 && boundary < sgvalen)) {
+#ifdef SGMAP_DEBUG
+		if (__C(SGMAP_TYPE,_debug)) {
+			printf("sgmap_load: extra segment needed\n");
+		}
+#endif
+		DMA_COUNT(extra_segment);
+
+		/* This should only ever happen for unaligned buffers. */
+		KASSERT(dmaoffset != 0);
+
+		extra_sgvalen = sgvalen - boundary;
+		KASSERT(extra_sgvalen == PAGE_SIZE);
+
+		/*
+		 * Adjust the lengths of the first segment.  The length
+		 * of the second segment will be dmaoffset.
+		 */
+		sgvalen -= extra_sgvalen;
+		endva -= extra_sgvalen;
+		buflen -= dmaoffset;
+
+		if (spill) {
+			DMA_COUNT(extra_segment_and_spill);
+			extra_sgvalen += PAGE_SIZE;
+		}
+
+		error = vmem_xalloc(sgmap->aps_arena, extra_sgvalen,
+alignment,		/* alignment */
+0,			/* phase */
+boundary,		/* nocross */
+VMEM_ADDR_MIN,	/* minaddr */
+VMEM_ADDR_MAX,	/* maxaddr */
+vmflags,
+_sgva);
+		if (error) {
+			return error;
+		}
+	} else {
+		extra_sgvalen = 0;
+		extra_sgva = 0;
+	}
+
+
 	if (spill) {
 		DMA_COUNT(spill_page);
 		sgvalen += PAGE_SIZE;
@@ -120,6 +192,11 @@ __C(SGMAP_TYPE,_load_buffer)(bus_dma_tag
 		/*
 		 * ARGH!  If the addition of the spill page bumped us
 		 * over our boundary, we have to 2x the boundary limit.
+		 * To compensate (and 

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

2021-06-20 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon Jun 21 02:10:46 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: db_disasm.c db_instruction.h

Log Message:
Remove the /I "alternate format" from db_disasm(), which was internally
interpreted as "showregs", whcih would print the values of the registers
at each instruction.  Unfortunately, this was fundamentally broken because
the saved registers accessible to DDB are only valid for the faulting
insn that got us into DDB, and not arbitrary isns that can be examined
from within DDB.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/alpha/alpha/db_disasm.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/alpha/alpha/db_instruction.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/alpha/alpha/db_disasm.c
diff -u src/sys/arch/alpha/alpha/db_disasm.c:1.17 src/sys/arch/alpha/alpha/db_disasm.c:1.18
--- src/sys/arch/alpha/alpha/db_disasm.c:1.17	Mon Jun 21 02:01:13 2021
+++ src/sys/arch/alpha/alpha/db_disasm.c	Mon Jun 21 02:10:46 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: db_disasm.c,v 1.17 2021/06/21 02:01:13 thorpej Exp $ */
+/* $NetBSD: db_disasm.c,v 1.18 2021/06/21 02:10:46 thorpej Exp $ */
 
 /*
  * Mach Operating System
@@ -48,7 +48,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.17 2021/06/21 02:01:13 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.18 2021/06/21 02:10:46 thorpej Exp $");
 
 #include 
 #include 
@@ -784,13 +784,6 @@ static const char * const name_of_regist
 static const char *
 register_name(struct alpha_print_instruction_context *ctx, int ireg)
 {
-	int	i;
-
-	for (i = 0; i < ctx->regcount; i++)
-		if (ctx->regnum[i] == ireg)
-			break;
-	if (i >= ctx->regcount)
-		ctx->regnum[ctx->regcount++] = ireg;
 	return (name_of_register[ireg]);
 }
 
@@ -824,12 +817,10 @@ int
 alpha_print_instruction(struct alpha_print_instruction_context *ctx)
 {
 	const char	*opcode;
-	int		ireg;
 	long		signed_immediate;
 	bool		fstore;
 	pal_instruction	p;
 
-	ctx->regcount = 0;
 	fstore = false;
 	opcode = op_name[ctx->insn.mem_format.opcode];
 
@@ -1038,16 +1029,6 @@ loadstore_address:
 			insn_printf(ctx, "%s(%s)", tbuf,
 			register_name(ctx, ctx->insn.mem_format.rb));
 		}
-		/*
-		 * For convenience, do the address computation
-		 */
-		if (ctx->showregs) {
-			if (ctx->insn.mem_format.opcode == op_ldah)
-signed_immediate <<= 16;
-			insn_printf(ctx, " <0x%lx>", signed_immediate +
-			db_register_value(DDB_REGS,
-	  ctx->insn.mem_format.rb));
-		}
 		break;
 	case op_br:
 	case op_fbeq:
@@ -1084,21 +1065,6 @@ branch_displacement:
 		insn_printf(ctx, "? 0x%x ?", ctx->insn.bits);
 	}
 
-	/*
-	 *	Print out the registers used in this instruction
-	 */
-	if (ctx->showregs && ctx->regcount > 0) {
-		insn_printf(ctx, "\t<");
-		for (ireg = 0; ireg < ctx->regcount; ireg++) {
-			if (ireg != 0)
-insn_printf(ctx, ",");
-			insn_printf(ctx, "%s=0x%lx",
-			name_of_register[ctx->regnum[ireg]],
-			db_register_value(DDB_REGS, ctx->regnum[ireg]));
-		}
-		insn_printf(ctx, ">");
-	}
-
 	/* If printing into a buffer, skip the newline. */
 	if (ctx->buf == NULL) {
 		insn_printf(ctx, "\n");
@@ -1108,12 +1074,11 @@ branch_displacement:
 }
 
 db_addr_t
-db_disasm(db_addr_t loc, bool altfmt)
+db_disasm(db_addr_t loc, bool altfmt __unused)
 {
 	struct alpha_print_instruction_context ctx = {
 		.insn.bits = db_get_value(loc, 4, 0),
 		.pc = loc,
-		.showregs = altfmt,
 	};
 
 	loc += alpha_print_instruction();

Index: src/sys/arch/alpha/alpha/db_instruction.h
diff -u src/sys/arch/alpha/alpha/db_instruction.h:1.11 src/sys/arch/alpha/alpha/db_instruction.h:1.12
--- src/sys/arch/alpha/alpha/db_instruction.h:1.11	Mon Jun 21 02:01:13 2021
+++ src/sys/arch/alpha/alpha/db_instruction.h	Mon Jun 21 02:10:46 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: db_instruction.h,v 1.11 2021/06/21 02:01:13 thorpej Exp $ */
+/* $NetBSD: db_instruction.h,v 1.12 2021/06/21 02:10:46 thorpej Exp $ */
 
 /*
  * Copyright (c) 1999 Christopher G. Demetriou.  All rights reserved.
@@ -748,9 +748,6 @@ struct alpha_print_instruction_context {
 	char	*buf;		/* output buffer (if not DDB) */
 	size_t	bufsize;	/* size of output buffer */
 	size_t	cursor;		/* current next output location */
-	int	regcount;	/* how many rebgs used in this insn */
-	int	regnum[3];	/* which regs are used in this insn */
-	bool	showregs;	/* show registers */
 };
 
 int	alpha_print_instruction(struct alpha_print_instruction_context *);



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

2021-06-20 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon Jun 21 02:01:13 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: db_disasm.c db_instruction.h

Log Message:
Allow alpha_print_instruction() to be called from outside DDB, and
allow the caller to supply a buffer to contain the pretty-printed
insn string, rather than db_printf() (which is used if there is no
supplied buffer).


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/alpha/alpha/db_disasm.c
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/alpha/alpha/db_instruction.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/alpha/alpha/db_disasm.c
diff -u src/sys/arch/alpha/alpha/db_disasm.c:1.16 src/sys/arch/alpha/alpha/db_disasm.c:1.17
--- src/sys/arch/alpha/alpha/db_disasm.c:1.16	Thu Mar 20 20:51:40 2014
+++ src/sys/arch/alpha/alpha/db_disasm.c	Mon Jun 21 02:01:13 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: db_disasm.c,v 1.16 2014/03/20 20:51:40 christos Exp $ */
+/* $NetBSD: db_disasm.c,v 1.17 2021/06/21 02:01:13 thorpej Exp $ */
 
 /*
  * Mach Operating System
@@ -48,7 +48,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.16 2014/03/20 20:51:40 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.17 2021/06/21 02:01:13 thorpej Exp $");
 
 #include 
 #include 
@@ -781,31 +781,47 @@ static const char * const name_of_regist
 	"t10",	"t11",	"ra",	"pv",	"at",	"gp",	"sp",	"zero"
 };
 
-static int regcount;		/* how many regs used in this inst */
-static int regnum[3];		/* which regs used in this inst */
-
 static const char *
-register_name(int ireg)
+register_name(struct alpha_print_instruction_context *ctx, int ireg)
 {
 	int	i;
 
-	for (i = 0; i < regcount; i++)
-		if (regnum[i] == ireg)
+	for (i = 0; i < ctx->regcount; i++)
+		if (ctx->regnum[i] == ireg)
 			break;
-	if (i >= regcount)
-		regnum[regcount++] = ireg;
+	if (i >= ctx->regcount)
+		ctx->regnum[ctx->regcount++] = ireg;
 	return (name_of_register[ireg]);
 }
 
+static void
+insn_printf(struct alpha_print_instruction_context *ctx,
+const char *fmt, ...)
+{
+	va_list ap;
+
+	va_start(ap, fmt);
+
+	if (ctx->buf != NULL) {
+		if (ctx->cursor < ctx->bufsize) {
+			ctx->cursor += vsnprintf(ctx->buf + ctx->cursor,
+			ctx->bufsize - ctx->cursor, fmt, ap);
+		}
+	} else {
+		db_vprintf(fmt, ap);
+	}
+
+	va_end(ap);
+}
+
 /*
  * Disassemble instruction at 'loc'.  'altfmt' specifies an
  * (optional) alternate format.  Return address of start of
  * next instruction.
  */
 
-static int
-alpha_print_instruction(db_addr_t iadr, alpha_instruction i,
-bool showregs)
+int
+alpha_print_instruction(struct alpha_print_instruction_context *ctx)
 {
 	const char	*opcode;
 	int		ireg;
@@ -813,18 +829,19 @@ alpha_print_instruction(db_addr_t iadr, 
 	bool		fstore;
 	pal_instruction	p;
 
-	regcount = 0;
+	ctx->regcount = 0;
 	fstore = false;
-	opcode = op_name[i.mem_format.opcode];
+	opcode = op_name[ctx->insn.mem_format.opcode];
 
 	/*
 	 *	Dispatch directly on the opcode, save code
 	 *	duplication sometimes via "harmless gotos".
 	 */
-	switch (i.mem_format.opcode) {
+	switch (ctx->insn.mem_format.opcode) {
 	case op_pal:
 		/* "call_pal" is a long string; just use a space. */
-		db_printf("%s %s", opcode, pal_opname(i.pal_format.function));
+		insn_printf(ctx, "%s %s", opcode,
+		pal_opname(ctx->insn.pal_format.function));
 		break;
 	case op_lda:
 	case op_ldah:
@@ -846,49 +863,54 @@ alpha_print_instruction(db_addr_t iadr, 
 		 * For this and the following three groups we
 		 * just need different opcode strings
 		 */
-		opcode = arit_name(i.operate_lit_format.function);
+		opcode = arit_name(ctx->insn.operate_lit_format.function);
 		goto operate;
 		break;
 	case op_logical:
-		opcode = logical_name(i.operate_lit_format.function);
+		opcode = logical_name(ctx->insn.operate_lit_format.function);
 		goto operate;
 		break;
 	case op_bit:
-		opcode = bitop_name(i.operate_lit_format.function);
+		opcode = bitop_name(ctx->insn.operate_lit_format.function);
 		goto operate;
 		break;
 	case op_mul:
-		opcode = mul_name(i.operate_lit_format.function);
+		opcode = mul_name(ctx->insn.operate_lit_format.function);
 operate:
 		/*
 		 * Nice and uniform, just check for literals
 		 */
-		db_printf("%s\t%s,", opcode,
-		register_name(i.operate_lit_format.ra));
-		if (i.operate_lit_format.one)
-			db_printf("#0x%x", i.operate_lit_format.literal);
-		else
-			db_printf("%s", register_name(i.operate_reg_format.rb));
-		db_printf(",%s", register_name(i.operate_lit_format.rc));
+		insn_printf(ctx, "%s\t%s,", opcode,
+		register_name(ctx, ctx->insn.operate_lit_format.ra));
+		if (ctx->insn.operate_lit_format.one) {
+			insn_printf(ctx, "#0x%x",
+			ctx->insn.operate_lit_format.literal);
+		} else {
+			insn_printf(ctx, "%s",
+			register_name(ctx,
+	  ctx->insn.operate_reg_format.rb));
+		}
+		

CVS commit: src/sys/arch/alpha

2021-06-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Jun 19 16:59:07 UTC 2021

Modified Files:
src/sys/arch/alpha/include: pci_machdep.h
src/sys/arch/alpha/pci: apecs.c cia.c dwlpx.c irongate.c lca.c mcpcia.c
pci_1000.c pci_1000a.c pci_2100_a50.c pci_2100_a500.c
pci_2100_a500.h pci_550.c pci_6600.c pci_alphabook1.c
pci_axppci_33.c pci_eb164.c pci_eb64plus.c pci_eb66.c pci_kn20aa.c
pci_kn300.c pci_kn8ae.c pci_machdep.c pci_up1000.c tsc.c ttwoga.c
Removed Files:
src/sys/arch/alpha/pci: pci_1000.h pci_1000a.h pci_2100_a50.h pci_550.h
pci_6600.h pci_alphabook1.h pci_axppci_33.h pci_eb164.h
pci_eb64plus.h pci_eb66.h pci_kn20aa.h pci_kn300.h pci_kn8ae.h
pci_up1000.h

Log Message:
Don't use a bunch of switch() statements in the core logic drivers to select
the PCI interrupt initialization routine.  Instead, register said routines
by systype in a link set, and look them up and invoke them in a new function
alpha_pci_intr_init().


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/alpha/include/pci_machdep.h
cvs rdiff -u -r1.56 -r1.57 src/sys/arch/alpha/pci/apecs.c
cvs rdiff -u -r1.76 -r1.77 src/sys/arch/alpha/pci/cia.c
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/alpha/pci/dwlpx.c
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/alpha/pci/irongate.c \
src/sys/arch/alpha/pci/pci_alphabook1.c
cvs rdiff -u -r1.53 -r1.54 src/sys/arch/alpha/pci/lca.c
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/alpha/pci/mcpcia.c
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/alpha/pci/pci_1000.c
cvs rdiff -u -r1.3 -r0 src/sys/arch/alpha/pci/pci_1000.h \
src/sys/arch/alpha/pci/pci_eb64plus.h src/sys/arch/alpha/pci/pci_up1000.h
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/alpha/pci/pci_1000a.c \
src/sys/arch/alpha/pci/pci_6600.c
cvs rdiff -u -r1.4 -r0 src/sys/arch/alpha/pci/pci_1000a.h \
src/sys/arch/alpha/pci/pci_eb164.h src/sys/arch/alpha/pci/pci_kn300.h
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/alpha/pci/pci_2100_a50.c
cvs rdiff -u -r1.5 -r0 src/sys/arch/alpha/pci/pci_2100_a50.h \
src/sys/arch/alpha/pci/pci_550.h src/sys/arch/alpha/pci/pci_axppci_33.h \
src/sys/arch/alpha/pci/pci_kn20aa.h
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/alpha/pci/pci_2100_a500.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/alpha/pci/pci_2100_a500.h
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/alpha/pci/pci_550.c
cvs rdiff -u -r1.2 -r0 src/sys/arch/alpha/pci/pci_6600.h \
src/sys/arch/alpha/pci/pci_alphabook1.h src/sys/arch/alpha/pci/pci_eb66.h
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/alpha/pci/pci_axppci_33.c \
src/sys/arch/alpha/pci/pci_kn300.c
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/alpha/pci/pci_eb164.c
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/alpha/pci/pci_eb64plus.c \
src/sys/arch/alpha/pci/pci_eb66.c
cvs rdiff -u -r1.55 -r1.56 src/sys/arch/alpha/pci/pci_kn20aa.c
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/alpha/pci/pci_kn8ae.c
cvs rdiff -u -r1.6 -r0 src/sys/arch/alpha/pci/pci_kn8ae.h
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/alpha/pci/pci_machdep.c
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/alpha/pci/pci_up1000.c
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/alpha/pci/tsc.c
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/alpha/pci/ttwoga.c

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

Modified files:

Index: src/sys/arch/alpha/include/pci_machdep.h
diff -u src/sys/arch/alpha/include/pci_machdep.h:1.22 src/sys/arch/alpha/include/pci_machdep.h:1.23
--- src/sys/arch/alpha/include/pci_machdep.h:1.22	Thu May 27 22:11:31 2021
+++ src/sys/arch/alpha/include/pci_machdep.h	Sat Jun 19 16:59:07 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_machdep.h,v 1.22 2021/05/27 22:11:31 thorpej Exp $ */
+/* $NetBSD: pci_machdep.h,v 1.23 2021/06/19 16:59:07 thorpej Exp $ */
 
 /*
  * Copyright (c) 1996 Carnegie-Mellon University.
@@ -96,6 +96,18 @@ struct alpha_pci_chipset {
 			struct cpu_info *);
 };
 
+struct alpha_pci_intr_impl {
+	uint64_t	systype;
+	void		(*intr_init)(void *, bus_space_tag_t, bus_space_tag_t,
+			pci_chipset_tag_t);
+};
+
+#define	ALPHA_PCI_INTR_INIT(_st_, _fn_)	\
+static const struct alpha_pci_intr_impl __CONCAT(intr_impl_st_,_st_) = {\
+	.systype = (_st_), .intr_init = (_fn_),\
+};	\
+__link_set_add_rodata(alpha_pci_intr_impls, __CONCAT(intr_impl_st_,_st_));
+
 /*
  * Functions provided to machine-independent PCI code.
  */
@@ -122,6 +134,9 @@ void	pci_display_console(bus_space_tag_t
 	pci_chipset_tag_t, int, int, int);
 void	device_pci_register(device_t, void *);
 
+void	alpha_pci_intr_init(void *, bus_space_tag_t, bus_space_tag_t,
+	pci_chipset_tag_t);
+
 int	alpha_pci_generic_intr_map(const struct pci_attach_args *,
 	pci_intr_handle_t *);
 const char *alpha_pci_generic_intr_string(pci_chipset_tag_t,

Index: src/sys/arch/alpha/pci/apecs.c
diff -u src/sys/arch/alpha/pci/apecs.c:1.56 src/sys/arch/alpha/pci/apecs.c:1.57
--- 

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

2021-06-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Jun 19 16:43:11 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: dwlpx_dma.c

Log Message:
No need to include pci_kn8ae.h here.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/alpha/pci/dwlpx_dma.c

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

Modified files:

Index: src/sys/arch/alpha/pci/dwlpx_dma.c
diff -u src/sys/arch/alpha/pci/dwlpx_dma.c:1.29 src/sys/arch/alpha/pci/dwlpx_dma.c:1.30
--- src/sys/arch/alpha/pci/dwlpx_dma.c:1.29	Wed May  5 02:15:18 2021
+++ src/sys/arch/alpha/pci/dwlpx_dma.c	Sat Jun 19 16:43:11 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: dwlpx_dma.c,v 1.29 2021/05/05 02:15:18 thorpej Exp $ */
+/* $NetBSD: dwlpx_dma.c,v 1.30 2021/06/19 16:43:11 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: dwlpx_dma.c,v 1.29 2021/05/05 02:15:18 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwlpx_dma.c,v 1.30 2021/06/19 16:43:11 thorpej Exp $");
 
 #include 
 #include 
@@ -50,7 +50,6 @@ __KERNEL_RCSID(0, "$NetBSD: dwlpx_dma.c,
 #include 
 #include 
 #include 
-#include 
 
 static bus_dma_tag_t dwlpx_dma_get_tag(bus_dma_tag_t, alpha_bus_t);
 



CVS commit: src/sys/arch/alpha

2021-06-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Jun 19 16:36:36 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: dec_kn300.c
src/sys/arch/alpha/pci: mcpcia_dma.c

Log Message:
No need to include pci_kn300.h here.


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/alpha/alpha/dec_kn300.c
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/alpha/pci/mcpcia_dma.c

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

Modified files:

Index: src/sys/arch/alpha/alpha/dec_kn300.c
diff -u src/sys/arch/alpha/alpha/dec_kn300.c:1.42 src/sys/arch/alpha/alpha/dec_kn300.c:1.43
--- src/sys/arch/alpha/alpha/dec_kn300.c:1.42	Mon Dec 14 10:12:45 2015
+++ src/sys/arch/alpha/alpha/dec_kn300.c	Sat Jun 19 16:36:35 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: dec_kn300.c,v 1.42 2015/12/14 10:12:45 martin Exp $ */
+/* $NetBSD: dec_kn300.c,v 1.43 2021/06/19 16:36:35 thorpej Exp $ */
 
 /*
  * Copyright (c) 1998 by Matthew Jacob
@@ -34,7 +34,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: dec_kn300.c,v 1.42 2015/12/14 10:12:45 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dec_kn300.c,v 1.43 2021/06/19 16:36:35 thorpej Exp $");
 
 #include 
 #include 
@@ -65,7 +65,6 @@ __KERNEL_RCSID(0, "$NetBSD: dec_kn300.c,
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #include 

Index: src/sys/arch/alpha/pci/mcpcia_dma.c
diff -u src/sys/arch/alpha/pci/mcpcia_dma.c:1.24 src/sys/arch/alpha/pci/mcpcia_dma.c:1.25
--- src/sys/arch/alpha/pci/mcpcia_dma.c:1.24	Wed May  5 02:15:18 2021
+++ src/sys/arch/alpha/pci/mcpcia_dma.c	Sat Jun 19 16:36:36 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: mcpcia_dma.c,v 1.24 2021/05/05 02:15:18 thorpej Exp $ */
+/* $NetBSD: mcpcia_dma.c,v 1.25 2021/06/19 16:36:36 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: mcpcia_dma.c,v 1.24 2021/05/05 02:15:18 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mcpcia_dma.c,v 1.25 2021/06/19 16:36:36 thorpej Exp $");
 
 #include 
 #include 
@@ -47,7 +47,6 @@ __KERNEL_RCSID(0, "$NetBSD: mcpcia_dma.c
 #include 
 #include 
 #include 
-#include 
 
 static bus_dma_tag_t mcpcia_dma_get_tag(bus_dma_tag_t, alpha_bus_t);
 



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

2021-06-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Jun 19 16:29:04 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: dwlpx.c pci_kn8ae.c pci_kn8ae.h

Log Message:
Remove the "first" argument from pci_kn8ae_pickintr(), instead using
a real once control in that function. Removes a needless divergence from
other "pickintr" routines.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/alpha/pci/dwlpx.c
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/alpha/pci/pci_kn8ae.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/alpha/pci/pci_kn8ae.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/alpha/pci/dwlpx.c
diff -u src/sys/arch/alpha/pci/dwlpx.c:1.40 src/sys/arch/alpha/pci/dwlpx.c:1.41
--- src/sys/arch/alpha/pci/dwlpx.c:1.40	Sat Apr 24 23:36:23 2021
+++ src/sys/arch/alpha/pci/dwlpx.c	Sat Jun 19 16:29:03 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: dwlpx.c,v 1.40 2021/04/24 23:36:23 thorpej Exp $ */
+/* $NetBSD: dwlpx.c,v 1.41 2021/06/19 16:29:03 thorpej Exp $ */
 
 /*
  * Copyright (c) 1997 by Matthew Jacob
@@ -32,7 +32,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: dwlpx.c,v 1.40 2021/04/24 23:36:23 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwlpx.c,v 1.41 2021/06/19 16:29:03 thorpej Exp $");
 
 #include 
 #include 
@@ -106,7 +106,6 @@ dwlpxmatch(device_t parent, cfdata_t cf,
 static void
 dwlpxattach(device_t parent, device_t self, void *aux)
 {
-	static int once = 0;
 	struct dwlpx_softc *sc = device_private(self);
 	struct dwlpx_config *ccp = >dwlpx_cc;
 	struct kft_dev_attach_args *ka = aux;
@@ -158,15 +157,10 @@ dwlpxattach(device_t parent, device_t se
 	}
 #endif
 
-	if (once == 0) {
-		/*
-		 * Set up interrupts
-		 */
-		pci_kn8ae_pickintr(>dwlpx_cc, 1);
-		once++;
-	} else {
-		pci_kn8ae_pickintr(>dwlpx_cc, 0);
-	}
+	/*
+	 * Set up interrupts
+	 */
+	pci_kn8ae_pickintr(>dwlpx_cc);
 
 	/*
 	 * Attach PCI bus

Index: src/sys/arch/alpha/pci/pci_kn8ae.c
diff -u src/sys/arch/alpha/pci/pci_kn8ae.c:1.31 src/sys/arch/alpha/pci/pci_kn8ae.c:1.32
--- src/sys/arch/alpha/pci/pci_kn8ae.c:1.31	Fri Sep 25 03:40:11 2020
+++ src/sys/arch/alpha/pci/pci_kn8ae.c	Sat Jun 19 16:29:03 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_kn8ae.c,v 1.31 2020/09/25 03:40:11 thorpej Exp $ */
+/* $NetBSD: pci_kn8ae.c,v 1.32 2021/06/19 16:29:03 thorpej Exp $ */
 
 /*
  * Copyright (c) 1997 by Matthew Jacob
@@ -32,7 +32,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pci_kn8ae.c,v 1.31 2020/09/25 03:40:11 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_kn8ae.c,v 1.32 2021/06/19 16:29:03 thorpej Exp $");
 
 #include 
 #include 
@@ -43,6 +43,7 @@ __KERNEL_RCSID(0, "$NetBSD: pci_kn8ae.c,
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -87,10 +88,27 @@ kn8ae_intr_wrapper(void *arg, u_long vec
 	KERNEL_UNLOCK_ONE(NULL);
 }
 
-void
-pci_kn8ae_pickintr(struct dwlpx_config *ccp, int first)
+static ONCE_DECL(pci_kn8ae_once);
+
+static int
+pci_kn8ae_init_imaskcache(void)
 {
 	int io, hose, dev;
+
+	for (io = 0; io < DWLPX_NIONODE; io++) {
+		for (hose = 0; hose < DWLPX_NHOSE; hose++) {
+			for (dev = 0; dev < NHPC; dev++) {
+imaskcache[io][hose][dev] = DWLPX_IMASK_DFLT;
+			}
+		}
+	}
+
+	return 0;
+}
+
+void
+pci_kn8ae_pickintr(struct dwlpx_config *ccp)
+{
 	pci_chipset_tag_t pc = >cc_pc;
 
 	pc->pc_intr_v = ccp;
@@ -103,17 +121,7 @@ pci_kn8ae_pickintr(struct dwlpx_config *
 	/* Not supported on KN8AE. */
 	pc->pc_pciide_compat_intr_establish = NULL;
 
-	if (!first) {
-		return;
-	}
-
-	for (io = 0; io < DWLPX_NIONODE; io++) {
-		for (hose = 0; hose < DWLPX_NHOSE; hose++) {
-			for (dev = 0; dev < NHPC; dev++) {
-imaskcache[io][hose][dev] = DWLPX_IMASK_DFLT;
-			}
-		}
-	}
+	RUN_ONCE(_kn8ae_once, pci_kn8ae_init_imaskcache);
 }
 
 #define	IH_MAKE(vec, dev, pin)		\

Index: src/sys/arch/alpha/pci/pci_kn8ae.h
diff -u src/sys/arch/alpha/pci/pci_kn8ae.h:1.5 src/sys/arch/alpha/pci/pci_kn8ae.h:1.6
--- src/sys/arch/alpha/pci/pci_kn8ae.h:1.5	Sat Mar 14 14:45:53 2009
+++ src/sys/arch/alpha/pci/pci_kn8ae.h	Sat Jun 19 16:29:03 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_kn8ae.h,v 1.5 2009/03/14 14:45:53 dsl Exp $ */
+/* $NetBSD: pci_kn8ae.h,v 1.6 2021/06/19 16:29:03 thorpej Exp $ */
 
 /*
  * Copyright (c) 1997 by Matthew Jacob
@@ -30,4 +30,4 @@
  * SUCH DAMAGE.
  */
 
-void	pci_kn8ae_pickintr(struct dwlpx_config *, int);
+void	pci_kn8ae_pickintr(struct dwlpx_config *);



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

2021-06-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Jun 19 16:13:40 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: mcpcia.c pci_kn300.c pci_kn300.h

Log Message:
Remove the "first" argument from pci_kn300_pickintr().  It's redundant with
information we already have, and is a needless divergence from other
"pickintr" routines.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/alpha/pci/mcpcia.c
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/alpha/pci/pci_kn300.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/alpha/pci/pci_kn300.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/alpha/pci/mcpcia.c
diff -u src/sys/arch/alpha/pci/mcpcia.c:1.32 src/sys/arch/alpha/pci/mcpcia.c:1.33
--- src/sys/arch/alpha/pci/mcpcia.c:1.32	Fri Jun 18 22:17:53 2021
+++ src/sys/arch/alpha/pci/mcpcia.c	Sat Jun 19 16:13:40 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: mcpcia.c,v 1.32 2021/06/18 22:17:53 thorpej Exp $ */
+/* $NetBSD: mcpcia.c,v 1.33 2021/06/19 16:13:40 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: mcpcia.c,v 1.32 2021/06/18 22:17:53 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mcpcia.c,v 1.33 2021/06/19 16:13:40 thorpej Exp $");
 
 #include 
 #include 
@@ -126,7 +126,6 @@ mcpciamatch(device_t parent, cfdata_t cf
 static void
 mcpciaattach(device_t parent, device_t self, void *aux)
 {
-	static int first = 1;
 	struct mcbus_dev_attach_args *ma = aux;
 	struct mcpcia_softc *mcp = device_private(self);
 	struct mcpcia_config *ccp;
@@ -174,8 +173,7 @@ mcpciaattach(device_t parent, device_t s
 	/*
 	 * Set up interrupts
 	 */
-	pci_kn300_pickintr(ccp, first);
-	first = 0;
+	pci_kn300_pickintr(ccp);
 
 	/*
 	 * Attach PCI bus

Index: src/sys/arch/alpha/pci/pci_kn300.c
diff -u src/sys/arch/alpha/pci/pci_kn300.c:1.38 src/sys/arch/alpha/pci/pci_kn300.c:1.39
--- src/sys/arch/alpha/pci/pci_kn300.c:1.38	Fri Sep 25 03:40:11 2020
+++ src/sys/arch/alpha/pci/pci_kn300.c	Sat Jun 19 16:13:40 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_kn300.c,v 1.38 2020/09/25 03:40:11 thorpej Exp $ */
+/* $NetBSD: pci_kn300.c,v 1.39 2021/06/19 16:13:40 thorpej Exp $ */
 
 /*
  * Copyright (c) 1998 by Matthew Jacob
@@ -32,7 +32,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pci_kn300.c,v 1.38 2020/09/25 03:40:11 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_kn300.c,v 1.39 2021/06/19 16:13:40 thorpej Exp $");
 
 #include 
 #include 
@@ -85,12 +85,12 @@ static void	kn300_enable_intr(struct mcp
 static void	kn300_disable_intr(struct mcpcia_config *, int);
 
 void
-pci_kn300_pickintr(struct mcpcia_config *ccp, int first)
+pci_kn300_pickintr(struct mcpcia_config *ccp)
 {
 	char *cp;
 	pci_chipset_tag_t pc = >cc_pc;
 
-	if (first) {
+	if (kn300_pci_intr == NULL) {
 		int g;
 
 #define PCI_KN300_IRQ_STR	16

Index: src/sys/arch/alpha/pci/pci_kn300.h
diff -u src/sys/arch/alpha/pci/pci_kn300.h:1.3 src/sys/arch/alpha/pci/pci_kn300.h:1.4
--- src/sys/arch/alpha/pci/pci_kn300.h:1.3	Sat Mar 14 14:45:53 2009
+++ src/sys/arch/alpha/pci/pci_kn300.h	Sat Jun 19 16:13:40 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_kn300.h,v 1.3 2009/03/14 14:45:53 dsl Exp $ */
+/* $NetBSD: pci_kn300.h,v 1.4 2021/06/19 16:13:40 thorpej Exp $ */
 
 /*
  * Copyright (c) 1998 by Matthew Jacob
@@ -30,4 +30,4 @@
  * SUCH DAMAGE.
  */
 
-void	pci_kn300_pickintr(struct mcpcia_config *, int);
+void	pci_kn300_pickintr(struct mcpcia_config *);



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

2021-06-18 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jun 18 22:18:10 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: cia_dma.c

Log Message:
Wrap a couple of long lines.


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

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

Modified files:

Index: src/sys/arch/alpha/pci/cia_dma.c
diff -u src/sys/arch/alpha/pci/cia_dma.c:1.32 src/sys/arch/alpha/pci/cia_dma.c:1.33
--- src/sys/arch/alpha/pci/cia_dma.c:1.32	Wed May  5 02:15:18 2021
+++ src/sys/arch/alpha/pci/cia_dma.c	Fri Jun 18 22:18:10 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: cia_dma.c,v 1.32 2021/05/05 02:15:18 thorpej Exp $ */
+/* $NetBSD: cia_dma.c,v 1.33 2021/06/18 22:18:10 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: cia_dma.c,v 1.32 2021/05/05 02:15:18 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cia_dma.c,v 1.33 2021/06/18 22:18:10 thorpej Exp $");
 
 #include 
 #include 
@@ -321,7 +321,8 @@ cia_bus_dmamap_create_direct(
  * Load a CIA SGMAP-mapped DMA map with a linear buffer.
  */
 static int
-cia_bus_dmamap_load_sgmap(bus_dma_tag_t t, bus_dmamap_t map, void *buf, bus_size_t buflen, struct proc *p, int flags)
+cia_bus_dmamap_load_sgmap(bus_dma_tag_t t, bus_dmamap_t map, void *buf,
+bus_size_t buflen, struct proc *p, int flags)
 {
 	int error;
 
@@ -337,7 +338,8 @@ cia_bus_dmamap_load_sgmap(bus_dma_tag_t 
  * Load a CIA SGMAP-mapped DMA map with an mbuf chain.
  */
 static int
-cia_bus_dmamap_load_mbuf_sgmap(bus_dma_tag_t t, bus_dmamap_t map, struct mbuf *m, int flags)
+cia_bus_dmamap_load_mbuf_sgmap(bus_dma_tag_t t, bus_dmamap_t map,
+struct mbuf *m, int flags)
 {
 	int error;
 
@@ -352,7 +354,8 @@ cia_bus_dmamap_load_mbuf_sgmap(bus_dma_t
  * Load a CIA SGMAP-mapped DMA map with a uio.
  */
 static int
-cia_bus_dmamap_load_uio_sgmap(bus_dma_tag_t t, bus_dmamap_t map, struct uio *uio, int flags)
+cia_bus_dmamap_load_uio_sgmap(bus_dma_tag_t t, bus_dmamap_t map,
+struct uio *uio, int flags)
 {
 	int error;
 
@@ -367,7 +370,8 @@ cia_bus_dmamap_load_uio_sgmap(bus_dma_ta
  * Load a CIA SGMAP-mapped DMA map with raw memory.
  */
 static int
-cia_bus_dmamap_load_raw_sgmap(bus_dma_tag_t t, bus_dmamap_t map, bus_dma_segment_t *segs, int nsegs, bus_size_t size, int flags)
+cia_bus_dmamap_load_raw_sgmap(bus_dma_tag_t t, bus_dmamap_t map,
+bus_dma_segment_t *segs, int nsegs, bus_size_t size, int flags)
 {
 	int error;
 



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

2021-06-18 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jun 18 22:17:53 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: apecs.c cia.c irongate.c lca.c mcpcia.c

Log Message:
Sprinkle some static.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/arch/alpha/pci/apecs.c
cvs rdiff -u -r1.75 -r1.76 src/sys/arch/alpha/pci/cia.c
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/alpha/pci/irongate.c
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/alpha/pci/lca.c
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/alpha/pci/mcpcia.c

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

Modified files:

Index: src/sys/arch/alpha/pci/apecs.c
diff -u src/sys/arch/alpha/pci/apecs.c:1.55 src/sys/arch/alpha/pci/apecs.c:1.56
--- src/sys/arch/alpha/pci/apecs.c:1.55	Sat Apr 24 23:36:23 2021
+++ src/sys/arch/alpha/pci/apecs.c	Fri Jun 18 22:17:53 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: apecs.c,v 1.55 2021/04/24 23:36:23 thorpej Exp $ */
+/* $NetBSD: apecs.c,v 1.56 2021/06/18 22:17:53 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: apecs.c,v 1.55 2021/04/24 23:36:23 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apecs.c,v 1.56 2021/06/18 22:17:53 thorpej Exp $");
 
 #include 
 #include 
@@ -106,7 +106,7 @@ static int apecs_bus_get_window(int, int
 struct alpha_bus_space_translation *);
 
 /* There can be only one. */
-int apecsfound;
+static int apecsfound;
 struct apecs_config apecs_configuration;
 
 static int
@@ -234,7 +234,8 @@ apecsattach(device_t parent, device_t se
 }
 
 static int
-apecs_bus_get_window(int type, int window, struct alpha_bus_space_translation *abst)
+apecs_bus_get_window(int type, int window,
+struct alpha_bus_space_translation *abst)
 {
 	struct apecs_config *acp = _configuration;
 	bus_space_tag_t st;

Index: src/sys/arch/alpha/pci/cia.c
diff -u src/sys/arch/alpha/pci/cia.c:1.75 src/sys/arch/alpha/pci/cia.c:1.76
--- src/sys/arch/alpha/pci/cia.c:1.75	Sat Apr 24 23:36:23 2021
+++ src/sys/arch/alpha/pci/cia.c	Fri Jun 18 22:17:53 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: cia.c,v 1.75 2021/04/24 23:36:23 thorpej Exp $ */
+/* $NetBSD: cia.c,v 1.76 2021/06/18 22:17:53 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: cia.c,v 1.75 2021/04/24 23:36:23 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cia.c,v 1.76 2021/06/18 22:17:53 thorpej Exp $");
 
 #include 
 #include 
@@ -102,18 +102,19 @@ __KERNEL_RCSID(0, "$NetBSD: cia.c,v 1.75
 #include 
 #endif
 
-int	ciamatch(device_t, cfdata_t, void *);
-void	ciaattach(device_t, device_t, void *);
+static int	ciamatch(device_t, cfdata_t, void *);
+static void	ciaattach(device_t, device_t, void *);
 
 CFATTACH_DECL_NEW(cia, sizeof(struct cia_softc),
 ciamatch, ciaattach, NULL, NULL);
 
 extern struct cfdriver cia_cd;
 
-int	cia_bus_get_window(int, int, struct alpha_bus_space_translation *);
+static int	cia_bus_get_window(int, int,
+		struct alpha_bus_space_translation *);
 
 /* There can be only one. */
-int ciafound;
+static int ciafound;
 struct cia_config cia_configuration;
 
 /*
@@ -147,7 +148,7 @@ int	cia_pci_use_bwx = CIA_PCI_USE_BWX;
 int	cia_bus_use_bwx = CIA_BUS_USE_BWX;
 int	cia_pyxis_force_bwx = CIA_PYXIS_FORCE_BWX;
 
-int
+static int
 ciamatch(device_t parent, cfdata_t match, void *aux)
 {
 	struct mainbus_attach_args *ma = aux;
@@ -260,7 +261,7 @@ cia_init(struct cia_config *ccp, int mal
 	ccp->cc_initted = 1;
 }
 
-void
+static void
 ciaattach(device_t parent, device_t self, void *aux)
 {
 	struct cia_softc *sc = device_private(self);
@@ -404,8 +405,9 @@ ciaattach(device_t parent, device_t self
 	config_found(self, , pcibusprint, CFARG_EOL);
 }
 
-int
-cia_bus_get_window(int type, int window, struct alpha_bus_space_translation *abst)
+static int
+cia_bus_get_window(int type, int window,
+struct alpha_bus_space_translation *abst)
 {
 	struct cia_config *ccp = _configuration;
 	bus_space_tag_t st;

Index: src/sys/arch/alpha/pci/irongate.c
diff -u src/sys/arch/alpha/pci/irongate.c:1.17 src/sys/arch/alpha/pci/irongate.c:1.18
--- src/sys/arch/alpha/pci/irongate.c:1.17	Sat Apr 24 23:36:23 2021
+++ src/sys/arch/alpha/pci/irongate.c	Fri Jun 18 22:17:53 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: irongate.c,v 1.17 2021/04/24 23:36:23 thorpej Exp $ */
+/* $NetBSD: irongate.c,v 1.18 2021/06/18 22:17:53 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: irongate.c,v 1.17 2021/04/24 23:36:23 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: irongate.c,v 1.18 2021/06/18 22:17:53 thorpej Exp $");
 
 #include 
 #include 
@@ -57,8 +57,8 @@ __KERNEL_RCSID(0, "$NetBSD: irongate.c,v
 #include 
 #endif
 
-int	irongate_match(device_t, cfdata_t, void *);
-void	

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

2021-05-31 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon May 31 17:22:45 UTC 2021

Modified Files:
src/sys/arch/alpha/include: pmap.h

Log Message:
Additional comment about the range (0-1025) that's needed for the PT page
reference count, and thus now many bits we need to scare up.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/sys/arch/alpha/include/pmap.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/alpha/include/pmap.h
diff -u src/sys/arch/alpha/include/pmap.h:1.97 src/sys/arch/alpha/include/pmap.h:1.98
--- src/sys/arch/alpha/include/pmap.h:1.97	Mon May 31 17:16:05 2021
+++ src/sys/arch/alpha/include/pmap.h	Mon May 31 17:22:44 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.h,v 1.97 2021/05/31 17:16:05 thorpej Exp $ */
+/* $NetBSD: pmap.h,v 1.98 2021/05/31 17:22:44 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007 The NetBSD Foundation, Inc.
@@ -360,6 +360,10 @@ struct vm_page_md {
 	 * XXX These fields are only needed for pages that are used
 	 * as PT pages.  It would be nice to find safely-unused fields
 	 * in the vm_page structure that could be used instead.
+	 *
+	 * (Only 11 bits are needed ... we need to be able to count from
+	 * 0-1025 ... 1025 because sometimes we need to take an extra
+	 * reference temporarily in pmap_enter().)
 	 */
 	unsigned int pvh_physpgrefs;	/* # refs as a PT page */
 	unsigned int pvh_spare0;	/* XXX spare field */



CVS commit: src/sys/arch/alpha

2021-05-31 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon May 31 17:16:05 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: pmap.c
src/sys/arch/alpha/include: pmap.h

Log Message:
After a comment by joerg@, go back to using a dedicated field for the
PT page reference count, but add an XXX comment stating the desire to
find a safely-unused field in the vm_page structure when pages are in-
use as PT pages, so that we can save the 8 bytes per page needed for
this.


To generate a diff of this commit:
cvs rdiff -u -r1.292 -r1.293 src/sys/arch/alpha/alpha/pmap.c
cvs rdiff -u -r1.96 -r1.97 src/sys/arch/alpha/include/pmap.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/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.292 src/sys/arch/alpha/alpha/pmap.c:1.293
--- src/sys/arch/alpha/alpha/pmap.c:1.292	Sun May 30 19:50:23 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Mon May 31 17:16:04 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.292 2021/05/30 19:50:23 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.293 2021/05/31 17:16:04 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.292 2021/05/30 19:50:23 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.293 2021/05/31 17:16:04 thorpej Exp $");
 
 #include 
 #include 
@@ -507,8 +507,8 @@ pmap_pagelist_free(struct pmap_pagelist 
 
 	while ((pg = LIST_FIRST(list)) != NULL) {
 		LIST_REMOVE(pg, pageq.list);
-		/* Zap any fields we used internally. */
-		atomic_store_relaxed(>loan_count, 0);
+		/* Fix up ref count; it's not always 0 when we get here. */
+		PHYSPAGE_REFCNT_SET(pg, 0);
 		uvm_pagefree(pg);
 	}
 }
@@ -1893,7 +1893,7 @@ pmap_remove_all(pmap_t pmap)
 
 	/* Fix up the reference count on the lev1map page. */
 	pg = PHYS_TO_VM_PAGE(ALPHA_K0SEG_TO_PHYS((vaddr_t)lev1map));
-	atomic_store_relaxed(>loan_count, 0);
+	PHYSPAGE_REFCNT_SET(pg, 0);
 
 	/* Step 3 */
 	while ((pv = LIST_FIRST(>pm_pvents)) != NULL) {
@@ -3470,15 +3470,6 @@ pmap_pv_page_free(struct pool *pp, void 
 / misc. functions /
 
 /*
- * Pages that are in-use as page table pages should never be part
- * of a UVM loan, so we'll use that field for our PT page reference
- * count.
- */
-#define	PHYSPAGE_REFCNT(pg)	atomic_load_relaxed(&(pg)->loan_count)
-#define	PHYSPAGE_REFCNT_INC(pg)	atomic_inc_uint_nv(&(pg)->loan_count)
-#define	PHYSPAGE_REFCNT_DEC(pg)	atomic_dec_uint_nv(&(pg)->loan_count)
-
-/*
  * pmap_physpage_alloc:
  *
  *	Allocate a single page from the VM system and return the

Index: src/sys/arch/alpha/include/pmap.h
diff -u src/sys/arch/alpha/include/pmap.h:1.96 src/sys/arch/alpha/include/pmap.h:1.97
--- src/sys/arch/alpha/include/pmap.h:1.96	Sun May 30 19:41:59 2021
+++ src/sys/arch/alpha/include/pmap.h	Mon May 31 17:16:05 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.h,v 1.96 2021/05/30 19:41:59 thorpej Exp $ */
+/* $NetBSD: pmap.h,v 1.97 2021/05/31 17:16:05 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007 The NetBSD Foundation, Inc.
@@ -355,9 +355,26 @@ do {	\
  */
 #define	__HAVE_VM_PAGE_MD
 struct vm_page_md {
-	uintptr_t pvh_listx;			/* pv_entry list + attrs */
+	uintptr_t pvh_listx;		/* pv_entry list + attrs */
+	/*
+	 * XXX These fields are only needed for pages that are used
+	 * as PT pages.  It would be nice to find safely-unused fields
+	 * in the vm_page structure that could be used instead.
+	 */
+	unsigned int pvh_physpgrefs;	/* # refs as a PT page */
+	unsigned int pvh_spare0;	/* XXX spare field */
 };
 
+/* Reference counting for page table pages. */
+#define	PHYSPAGE_REFCNT(pg)		\
+	atomic_load_relaxed(&(pg)->mdpage.pvh_physpgrefs)
+#define	PHYSPAGE_REFCNT_SET(pg, v)	\
+	atomic_store_relaxed(&(pg)->mdpage.pvh_physpgrefs, (v))
+#define	PHYSPAGE_REFCNT_INC(pg)		\
+	atomic_inc_uint_nv(&(pg)->mdpage.pvh_physpgrefs)
+#define	PHYSPAGE_REFCNT_DEC(pg)		\
+	atomic_dec_uint_nv(&(pg)->mdpage.pvh_physpgrefs)
+
 #define	VM_MDPAGE_PVS(pg)		\
 	((struct pv_entry *)((pg)->mdpage.pvh_listx & ~3UL))
 



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

2021-05-30 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 30 19:50:23 UTC 2021

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

Log Message:
Fix DEBUG build.


To generate a diff of this commit:
cvs rdiff -u -r1.291 -r1.292 src/sys/arch/alpha/alpha/pmap.c

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

Modified files:

Index: src/sys/arch/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.291 src/sys/arch/alpha/alpha/pmap.c:1.292
--- src/sys/arch/alpha/alpha/pmap.c:1.291	Sun May 30 19:46:21 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Sun May 30 19:50:23 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.291 2021/05/30 19:46:21 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.292 2021/05/30 19:50:23 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.291 2021/05/30 19:46:21 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.292 2021/05/30 19:50:23 thorpej Exp $");
 
 #include 
 #include 
@@ -1933,9 +1933,6 @@ pmap_page_protect(struct vm_page *pg, vm
 	struct pmap_tlb_context tlbctx;
 
 #ifdef DEBUG
-	paddr_t pa = VM_PAGE_TO_PHYS(pg);
-
-
 	if ((pmapdebug & (PDB_FOLLOW|PDB_PROTECT)) ||
 	(prot == VM_PROT_NONE && (pmapdebug & PDB_REMOVE)))
 		printf("pmap_page_protect(%p, %x)\n", pg, prot);
@@ -2576,7 +2573,7 @@ pmap_extract(pmap_t pmap, vaddr_t va, pa
 		if (__predict_true(vtophys_internal(va, pap))) {
 #ifdef DEBUG
 			if (pmapdebug & PDB_FOLLOW)
-printf("0x%lx (kernel vtophys)\n", pa);
+printf("0x%lx (kernel vtophys)\n", *pap);
 #endif
 			return true;
 		}
@@ -3278,7 +3275,7 @@ pmap_pv_dump(paddr_t pa)
 	lock = pmap_pvh_lock(pg);
 	mutex_enter(lock);
 
-	printf("pa 0x%lx (attrs = 0x%x):\n", pa, md->pvh_listx & PGA_ATTRS);
+	printf("pa 0x%lx (attrs = 0x%lx):\n", pa, md->pvh_listx & PGA_ATTRS);
 	for (pv = VM_MDPAGE_PVS(pg); pv != NULL; pv = pv->pv_next)
 		printf(" pmap %p, va 0x%lx\n",
 		pv->pv_pmap, pv->pv_va);
@@ -4004,7 +4001,7 @@ pmap_asn_alloc(pmap_t const pmap, struct
 #ifdef DEBUG
 		if (pmapdebug & PDB_ASN)
 			printf("pmap_asn_alloc: generation bumped to %lu\n",
-			ci->ci_asn_ge);
+			ci->ci_asn_gen);
 #endif
 	}
 



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

2021-05-30 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 30 19:46:21 UTC 2021

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

Log Message:
Fix unused variable warning when DIAGNOSTIC is disabled.  Pointed out
by jklos.


To generate a diff of this commit:
cvs rdiff -u -r1.290 -r1.291 src/sys/arch/alpha/alpha/pmap.c

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

Modified files:

Index: src/sys/arch/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.290 src/sys/arch/alpha/alpha/pmap.c:1.291
--- src/sys/arch/alpha/alpha/pmap.c:1.290	Sun May 30 19:41:59 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Sun May 30 19:46:21 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.290 2021/05/30 19:41:59 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.291 2021/05/30 19:46:21 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.290 2021/05/30 19:41:59 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.291 2021/05/30 19:46:21 thorpej Exp $");
 
 #include 
 #include 
@@ -1657,7 +1657,6 @@ pmap_destroy(pmap_t pmap)
 		return;
 
 	pt_entry_t *lev1map = pmap_lev1map(pmap);
-	int i;
 
 	rw_enter(_growkernel_lock, RW_READER);
 
@@ -1670,6 +1669,7 @@ pmap_destroy(pmap_t pmap)
 
 	pool_cache_put(_l1pt_cache, lev1map);
 #ifdef DIAGNOSTIC
+	int i;
 	for (i = 0; i < pmap_ncpuids; i++) {
 		pmap->pm_percpu[i].pmc_lev1map = (pt_entry_t *)0xdeadbeefUL;
 	}



CVS commit: src/sys/arch/alpha

2021-05-30 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 30 19:41:59 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: pmap.c
src/sys/arch/alpha/include: pmap.h

Log Message:
Implement pmap_remove_all().


To generate a diff of this commit:
cvs rdiff -u -r1.289 -r1.290 src/sys/arch/alpha/alpha/pmap.c
cvs rdiff -u -r1.95 -r1.96 src/sys/arch/alpha/include/pmap.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/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.289 src/sys/arch/alpha/alpha/pmap.c:1.290
--- src/sys/arch/alpha/alpha/pmap.c:1.289	Sun May 30 14:06:37 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Sun May 30 19:41:59 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.289 2021/05/30 14:06:37 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.290 2021/05/30 19:41:59 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.289 2021/05/30 14:06:37 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.290 2021/05/30 19:41:59 thorpej Exp $");
 
 #include 
 #include 
@@ -507,6 +507,8 @@ pmap_pagelist_free(struct pmap_pagelist 
 
 	while ((pg = LIST_FIRST(list)) != NULL) {
 		LIST_REMOVE(pg, pageq.list);
+		/* Zap any fields we used internally. */
+		atomic_store_relaxed(>loan_count, 0);
 		uvm_pagefree(pg);
 	}
 }
@@ -663,6 +665,7 @@ TLB_COUNT_DECL(shootnow_remote);
 
 TLB_COUNT_DECL(reason_remove_kernel);
 TLB_COUNT_DECL(reason_remove_user);
+TLB_COUNT_DECL(reason_remove_all_user);
 TLB_COUNT_DECL(reason_page_protect_read);
 TLB_COUNT_DECL(reason_page_protect_none);
 TLB_COUNT_DECL(reason_protect);
@@ -729,6 +732,7 @@ pmap_tlb_init(void)
 
 	TLB_COUNT_ATTACH(reason_remove_kernel);
 	TLB_COUNT_ATTACH(reason_remove_user);
+	TLB_COUNT_ATTACH(reason_remove_all_user);
 	TLB_COUNT_ATTACH(reason_page_protect_read);
 	TLB_COUNT_ATTACH(reason_page_protect_none);
 	TLB_COUNT_ATTACH(reason_protect);
@@ -1844,6 +1848,77 @@ pmap_remove(pmap_t pmap, vaddr_t sva, va
 }
 
 /*
+ * pmap_remove_all:		[ INTERFACE ]
+ *
+ *	Remove all mappings from a pmap in bulk.  This is only called
+ *	when it's known that the address space is no longer visible to
+ *	any user process (e.g. during exit or exec).
+ */
+bool
+pmap_remove_all(pmap_t pmap)
+{
+	struct pmap_tlb_context tlbctx;
+	struct vm_page *pg;
+	pv_entry_t pv;
+
+	KASSERT(pmap != pmap_kernel());
+
+	/*
+	 * This process is pretty simple:
+	 *
+	 * ==> (1) Zero out the user-space portion of the lev1map.
+	 *
+	 * ==> (2) Copy the PT page list to the tlbctx and re-init.
+	 *
+	 * ==> (3) Walk the PV entry list and remove each entry.
+	 *
+	 * ==> (4) Zero the wired and resident count.
+	 *
+	 * Once we've done that, we just need to free everything
+	 * back to the system.
+	 */
+
+	pmap_tlb_context_init(, 0);
+
+	PMAP_MAP_TO_HEAD_LOCK();
+	PMAP_LOCK(pmap);
+
+	/* Step 1 */
+	pt_entry_t * const lev1map = pmap_lev1map(pmap);
+	memset(lev1map, 0,
+	   l1pte_index(VM_MAXUSER_ADDRESS) * sizeof(pt_entry_t));
+
+	/* Step 2 */
+	LIST_MOVE(>pm_ptpages, _freeptq, pageq.list);
+
+	/* Fix up the reference count on the lev1map page. */
+	pg = PHYS_TO_VM_PAGE(ALPHA_K0SEG_TO_PHYS((vaddr_t)lev1map));
+	atomic_store_relaxed(>loan_count, 0);
+
+	/* Step 3 */
+	while ((pv = LIST_FIRST(>pm_pvents)) != NULL) {
+		KASSERT(pv->pv_pmap == pmap);
+		pmap_pv_remove(pmap, PHYS_TO_VM_PAGE(pmap_pte_pa(pv->pv_pte)),
+		pv->pv_va, true, NULL, );
+	}
+
+	/* Step 4 */
+	atomic_store_relaxed(>pm_stats.wired_count, 0);
+	atomic_store_relaxed(>pm_stats.resident_count, 0);
+
+	pmap_tlb_shootdown_all_user(pmap, PG_EXEC, );
+
+	PMAP_UNLOCK(pmap);
+	PMAP_MAP_TO_HEAD_UNLOCK();
+
+	pmap_tlb_shootnow();
+	pmap_tlb_context_drain();
+	TLB_COUNT(reason_remove_all_user);
+
+	return true;
+}
+
+/*
  * pmap_page_protect:		[ INTERFACE ]
  *
  *	Lower the permission for all mappings to a given page to

Index: src/sys/arch/alpha/include/pmap.h
diff -u src/sys/arch/alpha/include/pmap.h:1.95 src/sys/arch/alpha/include/pmap.h:1.96
--- src/sys/arch/alpha/include/pmap.h:1.95	Sun May 30 14:06:37 2021
+++ src/sys/arch/alpha/include/pmap.h	Sun May 30 19:41:59 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.h,v 1.95 2021/05/30 14:06:37 thorpej Exp $ */
+/* $NetBSD: pmap.h,v 1.96 2021/05/30 19:41:59 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007 The NetBSD Foundation, Inc.
@@ -209,13 +209,6 @@ void	pmap_tlb_shootdown_ipi(struct cpu_i
 #define	pmap_copy(dp, sp, da, l, sa)	/* nothing */
 #define	pmap_update(pmap)		/* nothing (yet) */
 
-static __inline bool
-pmap_remove_all(struct pmap *pmap)
-{
-	/* Nothing. */
-	return false;
-}
-
 #define	pmap_is_referenced(pg)		\
 	(((pg)->mdpage.pvh_listx & PGA_REFERENCED) != 0)
 #define	pmap_is_modified(pg)		\



CVS commit: src/sys/arch/alpha

2021-05-30 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 30 14:06:37 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: pmap.c
src/sys/arch/alpha/include: pmap.h

Log Message:
When removing mappings, hang PV entries to be freed off of the
pmap_tlb_context structure, and free them back in bulk after we
release all of our locks (as we do with PT pages that are freed).


To generate a diff of this commit:
cvs rdiff -u -r1.288 -r1.289 src/sys/arch/alpha/alpha/pmap.c
cvs rdiff -u -r1.94 -r1.95 src/sys/arch/alpha/include/pmap.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/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.288 src/sys/arch/alpha/alpha/pmap.c:1.289
--- src/sys/arch/alpha/alpha/pmap.c:1.288	Sun May 30 13:34:21 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Sun May 30 14:06:37 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.288 2021/05/30 13:34:21 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.289 2021/05/30 14:06:37 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.288 2021/05/30 13:34:21 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.289 2021/05/30 14:06:37 thorpej Exp $");
 
 #include 
 #include 
@@ -432,6 +432,71 @@ pmap_activation_lock(pmap_t const pmap)
 #endif /* MULTIPROCESSOR */
 
 /*
+ * TLB context structure; see description in "TLB management" section
+ * below.
+ */
+#define	TLB_CTX_MAXVA		8
+#define	TLB_CTX_ALLVA		PAGE_MASK
+struct pmap_tlb_context {
+	uintptr_t		t_addrdata[TLB_CTX_MAXVA];
+	pmap_t			t_pmap;
+	struct pmap_pagelist	t_freeptq;
+	struct pmap_pvlist	t_freepvq;
+};
+
+/*
+ * Internal routines
+ */
+static void	alpha_protection_init(void);
+static pt_entry_t pmap_remove_mapping(pmap_t, vaddr_t, pt_entry_t *, bool,
+  pv_entry_t *,
+  struct pmap_tlb_context *);
+static void	pmap_changebit(struct vm_page *, pt_entry_t, pt_entry_t,
+			   struct pmap_tlb_context *);
+
+/*
+ * PT page management functions.
+ */
+static int	pmap_ptpage_alloc(pmap_t, pt_entry_t *, int);
+static void	pmap_ptpage_free(pmap_t, pt_entry_t *,
+ struct pmap_tlb_context *);
+static void	pmap_l3pt_delref(pmap_t, vaddr_t, pt_entry_t *,
+		 struct pmap_tlb_context *);
+static void	pmap_l2pt_delref(pmap_t, pt_entry_t *, pt_entry_t *,
+		 struct pmap_tlb_context *);
+static void	pmap_l1pt_delref(pmap_t, pt_entry_t *);
+
+static void	*pmap_l1pt_alloc(struct pool *, int);
+static void	pmap_l1pt_free(struct pool *, void *);
+
+static struct pool_allocator pmap_l1pt_allocator = {
+	pmap_l1pt_alloc, pmap_l1pt_free, 0,
+};
+
+static int	pmap_l1pt_ctor(void *, void *, int);
+
+/*
+ * PV table management functions.
+ */
+static int	pmap_pv_enter(pmap_t, struct vm_page *, vaddr_t, pt_entry_t *,
+			  bool, pv_entry_t);
+static void	pmap_pv_remove(pmap_t, struct vm_page *, vaddr_t, bool,
+			   pv_entry_t *, struct pmap_tlb_context *);
+static void	*pmap_pv_page_alloc(struct pool *, int);
+static void	pmap_pv_page_free(struct pool *, void *);
+
+static struct pool_allocator pmap_pv_page_allocator = {
+	pmap_pv_page_alloc, pmap_pv_page_free, 0,
+};
+
+#ifdef DEBUG
+void	pmap_pv_dump(paddr_t);
+#endif
+
+#define	pmap_pv_alloc()		pool_cache_get(_pv_cache, PR_NOWAIT)
+#define	pmap_pv_free(pv)	pool_cache_put(_pv_cache, (pv))
+
+/*
  * Generic routine for freeing pages on a pmap_pagelist back to
  * the system.
  */
@@ -447,6 +512,21 @@ pmap_pagelist_free(struct pmap_pagelist 
 }
 
 /*
+ * Generic routine for freeing a list of PV entries back to the
+ * system.
+ */
+static void
+pmap_pvlist_free(struct pmap_pvlist * const list)
+{
+	pv_entry_t pv;
+
+	while ((pv = LIST_FIRST(list)) != NULL) {
+		LIST_REMOVE(pv, pv_link);
+		pmap_pv_free(pv);
+	}
+}
+
+/*
  * TLB management.
  *
  * TLB invalidations need to be performed on local and remote CPUs
@@ -518,9 +598,6 @@ pmap_pagelist_free(struct pmap_pagelist 
  * window size (defined as 64KB on alpha in ).
  */
 
-#define	TLB_CTX_MAXVA		8
-#define	TLB_CTX_ALLVA		PAGE_MASK
-
 #define	TLB_CTX_F_ASM		__BIT(0)
 #define	TLB_CTX_F_IMB		__BIT(1)
 #define	TLB_CTX_F_KIMB		__BIT(2)
@@ -538,12 +615,6 @@ pmap_pagelist_free(struct pmap_pagelist 
 #define	TLB_CTX_SETVA(ctx, i, va)	\
 	(ctx)->t_addrdata[(i)] = (va) | ((ctx)->t_addrdata[(i)] & PAGE_MASK)
 
-struct pmap_tlb_context {
-	uintptr_t	t_addrdata[TLB_CTX_MAXVA];
-	pmap_t		t_pmap;
-	struct pmap_pagelist t_freeptq;
-};
-
 static struct {
 	kmutex_t	lock;
 	struct evcnt	events;
@@ -689,6 +760,7 @@ pmap_tlb_context_init(struct pmap_tlb_co
 	tlbctx->t_addrdata[1] = flags;
 	tlbctx->t_pmap = NULL;
 	LIST_INIT(>t_freeptq);
+	LIST_INIT(>t_freepvq);
 }
 
 static void
@@ -1081,65 +1153,18 @@ pmap_tlb_shootdown_ipi(struct cpu_info *
 }
 #endif /* MULTIPROCESSOR */
 
-static __inline void
-pmap_tlb_ptpage_drain(struct 

CVS commit: src/sys/arch/alpha

2021-05-30 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 30 13:34:21 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: pmap.c
src/sys/arch/alpha/include: pmap.h

Log Message:
Keep track of a pmap's PV entries with a list hanging off the pmap.


To generate a diff of this commit:
cvs rdiff -u -r1.287 -r1.288 src/sys/arch/alpha/alpha/pmap.c
cvs rdiff -u -r1.93 -r1.94 src/sys/arch/alpha/include/pmap.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/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.287 src/sys/arch/alpha/alpha/pmap.c:1.288
--- src/sys/arch/alpha/alpha/pmap.c:1.287	Sun May 30 06:41:19 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Sun May 30 13:34:21 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.287 2021/05/30 06:41:19 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.288 2021/05/30 13:34:21 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.287 2021/05/30 06:41:19 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.288 2021/05/30 13:34:21 thorpej Exp $");
 
 #include 
 #include 
@@ -1384,6 +1384,7 @@ pmap_bootstrap(paddr_t ptaddr, u_int max
 	 */
 	memset(pmap_kernel(), 0, sizeof(struct pmap));
 	LIST_INIT(_kernel()->pm_ptpages);
+	LIST_INIT(_kernel()->pm_pvents);
 	atomic_store_relaxed(_kernel()->pm_count, 1);
 	/* Kernel pmap does not have per-CPU info. */
 	TAILQ_INSERT_TAIL(_all_pmaps, pmap_kernel(), pm_list);
@@ -1568,6 +1569,7 @@ pmap_create(void)
 	pmap = pool_cache_get(_pmap_cache, PR_WAITOK);
 	memset(pmap, 0, sizeof(*pmap));
 	LIST_INIT(>pm_ptpages);
+	LIST_INIT(>pm_pvents);
 
 	atomic_store_relaxed(>pm_count, 1);
 
@@ -3278,6 +3280,7 @@ pmap_pv_enter(pmap_t pmap, struct vm_pag
 	uintptr_t const attrs = md->pvh_listx & PGA_ATTRS;
 	newpv->pv_next = (struct pv_entry *)(md->pvh_listx & ~PGA_ATTRS);
 	md->pvh_listx = (uintptr_t)newpv | attrs;
+	LIST_INSERT_HEAD(>pm_pvents, newpv, pv_link);
 
 	if (dolock) {
 		mutex_exit(lock);
@@ -3316,8 +3319,15 @@ pmap_pv_remove(pmap_t pmap, struct vm_pa
 
 	KASSERT(pv != NULL);
 
+	/*
+	 * The page attributes are in the lower 2 bits of the first
+	 * PV entry pointer.  Rather than comparing the pointer address
+	 * and branching, we just always preserve what might be there
+	 * (either attribute bits or zero bits).
+	 */
 	*pvp = (pv_entry_t)((uintptr_t)pv->pv_next |
 			(((uintptr_t)*pvp) & PGA_ATTRS));
+	LIST_REMOVE(pv, pv_link);
 
 	if (dolock) {
 		mutex_exit(lock);

Index: src/sys/arch/alpha/include/pmap.h
diff -u src/sys/arch/alpha/include/pmap.h:1.93 src/sys/arch/alpha/include/pmap.h:1.94
--- src/sys/arch/alpha/include/pmap.h:1.93	Sun May 30 06:41:19 2021
+++ src/sys/arch/alpha/include/pmap.h	Sun May 30 13:34:21 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.h,v 1.93 2021/05/30 06:41:19 thorpej Exp $ */
+/* $NetBSD: pmap.h,v 1.94 2021/05/30 13:34:21 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007 The NetBSD Foundation, Inc.
@@ -151,7 +151,7 @@ struct pmap {	/* pmaps are aligned to CO
 	unsigned int		pm_count;	/* [24] reference count */
 	unsigned int		__pm_spare0;	/* [28] spare field */
 	struct pmap_pagelist	pm_ptpages;	/* [32] list of PT pages */
-	unsigned long		__pm_spare1;	/* [40] spare field */
+	LIST_HEAD(, pv_entry)	pm_pvents;	/* [40] list of PV entries */
 	TAILQ_ENTRY(pmap)	pm_list;	/* [48] list of all pmaps */
 	/* -- COHERENCY_UNIT boundary -- */
 	struct pmap_percpu	pm_percpu[];	/* [64] per-CPU data */
@@ -171,7 +171,8 @@ struct pmap {	/* pmaps are aligned to CO
  * mappings of that page.  An entry is a pv_entry_t, the list is pv_table.
  */
 typedef struct pv_entry {
-	struct pv_entry	*pv_next;	/* next pv_entry on list */
+	struct pv_entry	*pv_next;	/* next pv_entry on page list */
+	LIST_ENTRY(pv_entry) pv_link;	/* link on owning pmap's list */
 	struct pmap	*pv_pmap;	/* pmap where mapping lies */
 	vaddr_t		pv_va;		/* virtual address for mapping */
 	pt_entry_t	*pv_pte;	/* PTE that maps the VA */



CVS commit: src/sys/arch/alpha

2021-05-30 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 30 06:41:19 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: pmap.c
src/sys/arch/alpha/include: pmap.h

Log Message:
Store the modified / referenced attribute bits in the lower 2 bits of
the PV entry list pointer in struct vm_page_md.  This reduces the size
of that structure from 16 bytes to 8, and will go a fair way to making
up for increasing the size of struct pv_entry in a future commit.


To generate a diff of this commit:
cvs rdiff -u -r1.286 -r1.287 src/sys/arch/alpha/alpha/pmap.c
cvs rdiff -u -r1.92 -r1.93 src/sys/arch/alpha/include/pmap.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/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.286 src/sys/arch/alpha/alpha/pmap.c:1.287
--- src/sys/arch/alpha/alpha/pmap.c:1.286	Sun May 30 05:26:09 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Sun May 30 06:41:19 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.286 2021/05/30 05:26:09 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.287 2021/05/30 06:41:19 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.286 2021/05/30 05:26:09 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.287 2021/05/30 06:41:19 thorpej Exp $");
 
 #include 
 #include 
@@ -2233,17 +2233,18 @@ pmap_enter(pmap_t pmap, vaddr_t va, padd
 	npte = ((pa >> PGSHIFT) << PG_SHIFT) | pte_prot(pmap, prot) | PG_V;
 	if (pg != NULL) {
 		struct vm_page_md * const md = VM_PAGE_TO_MD(pg);
-		int attrs;
+		uintptr_t attrs = 0;
 
 		KASSERT(((flags & VM_PROT_ALL) & ~prot) == 0);
 
-		lock = pmap_pvh_lock(pg);
-		mutex_enter(lock);
 		if (flags & VM_PROT_WRITE)
-			md->pvh_attrs |= (PGA_REFERENCED|PGA_MODIFIED);
+			attrs |= (PGA_REFERENCED|PGA_MODIFIED);
 		else if (flags & VM_PROT_ALL)
-			md->pvh_attrs |= PGA_REFERENCED;
-		attrs = md->pvh_attrs;
+			attrs |= PGA_REFERENCED;
+
+		lock = pmap_pvh_lock(pg);
+		mutex_enter(lock);
+		md->pvh_listx |= attrs;
 		mutex_exit(lock);
 
 		/* Set up referenced/modified emulation for new mapping. */
@@ -2779,10 +2780,10 @@ pmap_clear_modify(struct vm_page *pg)
 	lock = pmap_pvh_lock(pg);
 	mutex_enter(lock);
 
-	if (md->pvh_attrs & PGA_MODIFIED) {
+	if (md->pvh_listx & PGA_MODIFIED) {
 		rv = true;
 		pmap_changebit(pg, PG_FOW, ~0UL, );
-		md->pvh_attrs &= ~PGA_MODIFIED;
+		md->pvh_listx &= ~PGA_MODIFIED;
 	}
 
 	mutex_exit(lock);
@@ -2818,10 +2819,10 @@ pmap_clear_reference(struct vm_page *pg)
 	lock = pmap_pvh_lock(pg);
 	mutex_enter(lock);
 
-	if (md->pvh_attrs & PGA_REFERENCED) {
+	if (md->pvh_listx & PGA_REFERENCED) {
 		rv = true;
 		pmap_changebit(pg, PG_FOR | PG_FOW | PG_FOE, ~0UL, );
-		md->pvh_attrs &= ~PGA_REFERENCED;
+		md->pvh_listx &= ~PGA_REFERENCED;
 	}
 
 	mutex_exit(lock);
@@ -3133,10 +3134,10 @@ pmap_emulate_reference(struct lwp *l, va
 	mutex_enter(lock);
 
 	if (type == ALPHA_MMCSR_FOW) {
-		md->pvh_attrs |= (PGA_REFERENCED|PGA_MODIFIED);
+		md->pvh_listx |= (PGA_REFERENCED|PGA_MODIFIED);
 		faultoff = PG_FOR | PG_FOW;
 	} else {
-		md->pvh_attrs |= PGA_REFERENCED;
+		md->pvh_listx |= PGA_REFERENCED;
 		faultoff = PG_FOR;
 		if (exec) {
 			faultoff |= PG_FOE;
@@ -3173,7 +3174,7 @@ pmap_pv_dump(paddr_t pa)
 	lock = pmap_pvh_lock(pg);
 	mutex_enter(lock);
 
-	printf("pa 0x%lx (attrs = 0x%x):\n", pa, md->pvh_attrs);
+	printf("pa 0x%lx (attrs = 0x%x):\n", pa, md->pvh_listx & PGA_ATTRS);
 	for (pv = VM_MDPAGE_PVS(pg); pv != NULL; pv = pv->pv_next)
 		printf(" pmap %p, va 0x%lx\n",
 		pv->pv_pmap, pv->pv_va);
@@ -3274,8 +3275,9 @@ pmap_pv_enter(pmap_t pmap, struct vm_pag
 	/*
 	 * ...and put it in the list.
 	 */
-	newpv->pv_next = md->pvh_list;
-	md->pvh_list = newpv;
+	uintptr_t const attrs = md->pvh_listx & PGA_ATTRS;
+	newpv->pv_next = (struct pv_entry *)(md->pvh_listx & ~PGA_ATTRS);
+	md->pvh_listx = (uintptr_t)newpv | attrs;
 
 	if (dolock) {
 		mutex_exit(lock);
@@ -3307,14 +3309,15 @@ pmap_pv_remove(pmap_t pmap, struct vm_pa
 	/*
 	 * Find the entry to remove.
 	 */
-	for (pvp = >pvh_list, pv = *pvp;
+	for (pvp = (struct pv_entry **)>pvh_listx, pv = VM_MDPAGE_PVS(pg);
 	 pv != NULL; pvp = >pv_next, pv = *pvp)
 		if (pmap == pv->pv_pmap && va == pv->pv_va)
 			break;
 
 	KASSERT(pv != NULL);
 
-	*pvp = pv->pv_next;
+	*pvp = (pv_entry_t)((uintptr_t)pv->pv_next |
+			(((uintptr_t)*pvp) & PGA_ATTRS));
 
 	if (dolock) {
 		mutex_exit(lock);

Index: src/sys/arch/alpha/include/pmap.h
diff -u src/sys/arch/alpha/include/pmap.h:1.92 src/sys/arch/alpha/include/pmap.h:1.93
--- src/sys/arch/alpha/include/pmap.h:1.92	Sun May 30 05:26:09 2021
+++ src/sys/arch/alpha/include/pmap.h	Sun May 30 06:41:19 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.h,v 1.92 2021/05/30 05:26:09 thorpej Exp $ */
+/* $NetBSD: pmap.h,v 1.93 2021/05/30 06:41:19 thorpej Exp $ */
 
 /*-
  * 

CVS commit: src/sys/arch/alpha

2021-05-29 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 30 05:26:09 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: pmap.c
src/sys/arch/alpha/include: pmap.h

Log Message:
Define a macro, VM_MDPAGE_PVS(), for fetching the first pv entry
for a page.


To generate a diff of this commit:
cvs rdiff -u -r1.285 -r1.286 src/sys/arch/alpha/alpha/pmap.c
cvs rdiff -u -r1.91 -r1.92 src/sys/arch/alpha/include/pmap.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/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.285 src/sys/arch/alpha/alpha/pmap.c:1.286
--- src/sys/arch/alpha/alpha/pmap.c:1.285	Sun May 30 04:04:26 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Sun May 30 05:26:09 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.285 2021/05/30 04:04:26 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.286 2021/05/30 05:26:09 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.285 2021/05/30 04:04:26 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.286 2021/05/30 05:26:09 thorpej Exp $");
 
 #include 
 #include 
@@ -1823,7 +1823,6 @@ pmap_remove(pmap_t pmap, vaddr_t sva, va
 void
 pmap_page_protect(struct vm_page *pg, vm_prot_t prot)
 {
-	struct vm_page_md * const md = VM_PAGE_TO_MD(pg);
 	pv_entry_t pv, nextpv;
 	pt_entry_t opte;
 	kmutex_t *lock;
@@ -1851,7 +1850,7 @@ pmap_page_protect(struct vm_page *pg, vm
 		PMAP_HEAD_TO_MAP_LOCK();
 		lock = pmap_pvh_lock(pg);
 		mutex_enter(lock);
-		for (pv = md->pvh_list; pv != NULL; pv = pv->pv_next) {
+		for (pv = VM_MDPAGE_PVS(pg); pv != NULL; pv = pv->pv_next) {
 			PMAP_LOCK(pv->pv_pmap);
 			opte = atomic_load_relaxed(pv->pv_pte);
 			if (opte & (PG_KWE | PG_UWE)) {
@@ -1876,7 +1875,7 @@ pmap_page_protect(struct vm_page *pg, vm
 	PMAP_HEAD_TO_MAP_LOCK();
 	lock = pmap_pvh_lock(pg);
 	mutex_enter(lock);
-	for (pv = md->pvh_list; pv != NULL; pv = nextpv) {
+	for (pv = VM_MDPAGE_PVS(pg); pv != NULL; pv = nextpv) {
 		pt_entry_t pte_bits;
 		pmap_t pmap;
 		vaddr_t va;
@@ -3007,7 +3006,6 @@ static void
 pmap_changebit(struct vm_page *pg, pt_entry_t set, pt_entry_t mask,
 struct pmap_tlb_context * const tlbctx)
 {
-	struct vm_page_md * const md = VM_PAGE_TO_MD(pg);
 	pv_entry_t pv;
 	pt_entry_t *pte, npte, opte;
 
@@ -3020,7 +3018,7 @@ pmap_changebit(struct vm_page *pg, pt_en
 	/*
 	 * Loop over all current mappings setting/clearing as apropos.
 	 */
-	for (pv = md->pvh_list; pv != NULL; pv = pv->pv_next) {
+	for (pv = VM_MDPAGE_PVS(pg); pv != NULL; pv = pv->pv_next) {
 		PMAP_LOCK(pv->pv_pmap);
 
 		pte = pv->pv_pte;
@@ -3176,7 +3174,7 @@ pmap_pv_dump(paddr_t pa)
 	mutex_enter(lock);
 
 	printf("pa 0x%lx (attrs = 0x%x):\n", pa, md->pvh_attrs);
-	for (pv = md->pvh_list; pv != NULL; pv = pv->pv_next)
+	for (pv = VM_MDPAGE_PVS(pg); pv != NULL; pv = pv->pv_next)
 		printf(" pmap %p, va 0x%lx\n",
 		pv->pv_pmap, pv->pv_va);
 	printf("\n");
@@ -3264,7 +3262,7 @@ pmap_pv_enter(pmap_t pmap, struct vm_pag
 	/*
 	 * Make sure the entry doesn't already exist.
 	 */
-	for (pv = md->pvh_list; pv != NULL; pv = pv->pv_next) {
+	for (pv = VM_MDPAGE_PVS(pg); pv != NULL; pv = pv->pv_next) {
 		if (pmap == pv->pv_pmap && va == pv->pv_va) {
 			printf("pmap = %p, va = 0x%lx\n", pmap, va);
 			panic("pmap_pv_enter: already in pv table");

Index: src/sys/arch/alpha/include/pmap.h
diff -u src/sys/arch/alpha/include/pmap.h:1.91 src/sys/arch/alpha/include/pmap.h:1.92
--- src/sys/arch/alpha/include/pmap.h:1.91	Sun May 30 04:04:26 2021
+++ src/sys/arch/alpha/include/pmap.h	Sun May 30 05:26:09 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.h,v 1.91 2021/05/30 04:04:26 thorpej Exp $ */
+/* $NetBSD: pmap.h,v 1.92 2021/05/30 05:26:09 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007 The NetBSD Foundation, Inc.
@@ -363,6 +363,9 @@ struct vm_page_md {
 	int pvh_attrs;/* page attributes */
 };
 
+#define	VM_MDPAGE_PVS(pg)		\
+	((pg)->mdpage.pvh_list)
+
 #define	VM_MDPAGE_INIT(pg)		\
 do {	\
 	(pg)->mdpage.pvh_list = NULL;	\



CVS commit: src/sys/arch/alpha

2021-05-29 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 30 04:04:27 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: pmap.c
src/sys/arch/alpha/include: pmap.h

Log Message:
Pages that are in-use as page table pages should never be part of a
UVM loan transaction, so use the vm_page::loan_count field as the PT
page reference count.


To generate a diff of this commit:
cvs rdiff -u -r1.284 -r1.285 src/sys/arch/alpha/alpha/pmap.c
cvs rdiff -u -r1.90 -r1.91 src/sys/arch/alpha/include/pmap.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/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.284 src/sys/arch/alpha/alpha/pmap.c:1.285
--- src/sys/arch/alpha/alpha/pmap.c:1.284	Sun May 30 01:41:45 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Sun May 30 04:04:26 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.284 2021/05/30 01:41:45 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.285 2021/05/30 04:04:26 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.284 2021/05/30 01:41:45 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.285 2021/05/30 04:04:26 thorpej Exp $");
 
 #include 
 #include 
@@ -3358,6 +3358,15 @@ pmap_pv_page_free(struct pool *pp, void 
 / misc. functions /
 
 /*
+ * Pages that are in-use as page table pages should never be part
+ * of a UVM loan, so we'll use that field for our PT page reference
+ * count.
+ */
+#define	PHYSPAGE_REFCNT(pg)	atomic_load_relaxed(&(pg)->loan_count)
+#define	PHYSPAGE_REFCNT_INC(pg)	atomic_inc_uint_nv(&(pg)->loan_count)
+#define	PHYSPAGE_REFCNT_DEC(pg)	atomic_dec_uint_nv(&(pg)->loan_count)
+
+/*
  * pmap_physpage_alloc:
  *
  *	Allocate a single page from the VM system and return the
@@ -3376,14 +3385,7 @@ pmap_physpage_alloc(int usage)
 	pg = uvm_pagealloc(NULL, 0, NULL, usage == PGU_L1PT ?
 	UVM_PGA_USERESERVE : UVM_PGA_USERESERVE|UVM_PGA_ZERO);
 	if (pg != NULL) {
-#ifdef DEBUG
-		struct vm_page_md * const md = VM_PAGE_TO_MD(pg);
-		if (md->pvh_refcnt != 0) {
-			printf("pmap_physpage_alloc: page 0x%lx has "
-			"%d references\n", pa, md->pvh_refcnt);
-			panic("pmap_physpage_alloc");
-		}
-#endif
+		KASSERT(PHYSPAGE_REFCNT(pg) == 0);
 	}
 	return pg;
 }
@@ -3401,11 +3403,7 @@ pmap_physpage_free(paddr_t pa)
 	if ((pg = PHYS_TO_VM_PAGE(pa)) == NULL)
 		panic("pmap_physpage_free: bogus physical page address");
 
-#ifdef DEBUG
-	struct vm_page_md * const md = VM_PAGE_TO_MD(pg);
-	if (md->pvh_refcnt != 0)
-		panic("pmap_physpage_free: page still has references");
-#endif
+	KASSERT(PHYSPAGE_REFCNT(pg) == 0);
 
 	uvm_pagefree(pg);
 }
@@ -3419,16 +3417,14 @@ static int
 pmap_physpage_addref(void *kva)
 {
 	struct vm_page *pg;
-	struct vm_page_md *md;
 	paddr_t pa;
 
 	pa = ALPHA_K0SEG_TO_PHYS(trunc_page((vaddr_t)kva));
 	pg = PHYS_TO_VM_PAGE(pa);
-	md = VM_PAGE_TO_MD(pg);
 
-	KASSERT((int)md->pvh_refcnt >= 0);
+	KASSERT(PHYSPAGE_REFCNT(pg) < UINT32_MAX);
 
-	return atomic_inc_uint_nv(>pvh_refcnt);
+	return PHYSPAGE_REFCNT_INC(pg);
 }
 
 /*
@@ -3440,16 +3436,14 @@ static int
 pmap_physpage_delref(void *kva)
 {
 	struct vm_page *pg;
-	struct vm_page_md *md;
 	paddr_t pa;
 
 	pa = ALPHA_K0SEG_TO_PHYS(trunc_page((vaddr_t)kva));
 	pg = PHYS_TO_VM_PAGE(pa);
-	md = VM_PAGE_TO_MD(pg);
 
-	KASSERT((int)md->pvh_refcnt > 0);
+	KASSERT(PHYSPAGE_REFCNT(pg) != 0);
 
-	return atomic_dec_uint_nv(>pvh_refcnt);
+	return PHYSPAGE_REFCNT_DEC(pg);
 }
 
 / page table page management /
@@ -3685,10 +3679,8 @@ pmap_ptpage_free(pmap_t pmap, pt_entry_t
 	struct vm_page * const pg = PHYS_TO_VM_PAGE(ptpa);
 	KASSERT(pg != NULL);
 
+	KASSERT(PHYSPAGE_REFCNT(pg) == 0);
 #ifdef DEBUG
-	struct vm_page_md * const md = VM_PAGE_TO_MD(pg);
-	KDASSERT(md->pvh_refcnt == 0);
-
 	pmap_zero_page(ptpa);
 #endif
 

Index: src/sys/arch/alpha/include/pmap.h
diff -u src/sys/arch/alpha/include/pmap.h:1.90 src/sys/arch/alpha/include/pmap.h:1.91
--- src/sys/arch/alpha/include/pmap.h:1.90	Sun May 30 01:41:45 2021
+++ src/sys/arch/alpha/include/pmap.h	Sun May 30 04:04:26 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.h,v 1.90 2021/05/30 01:41:45 thorpej Exp $ */
+/* $NetBSD: pmap.h,v 1.91 2021/05/30 04:04:26 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007 The NetBSD Foundation, Inc.
@@ -361,13 +361,12 @@ do {	\
 struct vm_page_md {
 	struct pv_entry *pvh_list;		/* pv_entry list */
 	int pvh_attrs;/* page attributes */
-	unsigned pvh_refcnt;
 };
 
 #define	VM_MDPAGE_INIT(pg)		\
 do {	\
 	(pg)->mdpage.pvh_list = NULL;	\
-	(pg)->mdpage.pvh_refcnt = 0;	\
+	(pg)->mdpage.pvh_attrs = 0;	\
 } while (/*CONSTCOND*/0)
 
 #endif /* _KERNEL */



CVS commit: src/sys/arch/alpha

2021-05-29 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 30 01:41:45 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: pmap.c
src/sys/arch/alpha/include: pmap.h

Log Message:
Track the PT pages allocated to a pmap in the pmap itself.


To generate a diff of this commit:
cvs rdiff -u -r1.283 -r1.284 src/sys/arch/alpha/alpha/pmap.c
cvs rdiff -u -r1.89 -r1.90 src/sys/arch/alpha/include/pmap.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/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.283 src/sys/arch/alpha/alpha/pmap.c:1.284
--- src/sys/arch/alpha/alpha/pmap.c:1.283	Sun May 30 01:24:19 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Sun May 30 01:41:45 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.283 2021/05/30 01:24:19 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.284 2021/05/30 01:41:45 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.283 2021/05/30 01:24:19 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.284 2021/05/30 01:41:45 thorpej Exp $");
 
 #include 
 #include 
@@ -1081,22 +1081,6 @@ pmap_tlb_shootdown_ipi(struct cpu_info *
 }
 #endif /* MULTIPROCESSOR */
 
-static void
-pmap_tlb_physpage_free(paddr_t const ptpa,
-struct pmap_tlb_context * const tlbctx)
-{
-	struct vm_page * const pg = PHYS_TO_VM_PAGE(ptpa);
-
-	KASSERT(pg != NULL);
-
-#ifdef DEBUG
-	struct vm_page_md * const md = VM_PAGE_TO_MD(pg);
-	KDASSERT(md->pvh_refcnt == 0);
-#endif
-
-	LIST_INSERT_HEAD(>t_freeptq, pg, pageq.list);
-}
-
 static __inline void
 pmap_tlb_ptpage_drain(struct pmap_tlb_context * const tlbctx)
 {
@@ -1116,8 +1100,9 @@ static void	pmap_changebit(struct vm_pag
 /*
  * PT page management functions.
  */
-static int	pmap_ptpage_alloc(pt_entry_t *, int);
-static void	pmap_ptpage_free(pt_entry_t *, struct pmap_tlb_context *);
+static int	pmap_ptpage_alloc(pmap_t, pt_entry_t *, int);
+static void	pmap_ptpage_free(pmap_t, pt_entry_t *,
+ struct pmap_tlb_context *);
 static void	pmap_l3pt_delref(pmap_t, vaddr_t, pt_entry_t *,
 		 struct pmap_tlb_context *);
 static void	pmap_l2pt_delref(pmap_t, pt_entry_t *, pt_entry_t *,
@@ -1398,6 +1383,7 @@ pmap_bootstrap(paddr_t ptaddr, u_int max
 	 * generation.
 	 */
 	memset(pmap_kernel(), 0, sizeof(struct pmap));
+	LIST_INIT(_kernel()->pm_ptpages);
 	atomic_store_relaxed(_kernel()->pm_count, 1);
 	/* Kernel pmap does not have per-CPU info. */
 	TAILQ_INSERT_TAIL(_all_pmaps, pmap_kernel(), pm_list);
@@ -1581,6 +1567,7 @@ pmap_create(void)
 
 	pmap = pool_cache_get(_pmap_cache, PR_WAITOK);
 	memset(pmap, 0, sizeof(*pmap));
+	LIST_INIT(>pm_ptpages);
 
 	atomic_store_relaxed(>pm_count, 1);
 
@@ -2105,7 +2092,7 @@ pmap_enter(pmap_t pmap, vaddr_t va, padd
 		l1pte = pmap_l1pte(lev1map, va);
 		if (pmap_pte_v(l1pte) == 0) {
 			pmap_physpage_addref(l1pte);
-			error = pmap_ptpage_alloc(l1pte, PGU_L2PT);
+			error = pmap_ptpage_alloc(pmap, l1pte, PGU_L2PT);
 			if (error) {
 pmap_l1pt_delref(pmap, l1pte);
 if (flags & PMAP_CANFAIL)
@@ -2129,7 +2116,7 @@ pmap_enter(pmap_t pmap, vaddr_t va, padd
 		l2pte = pmap_l2pte(lev1map, va, l1pte);
 		if (pmap_pte_v(l2pte) == 0) {
 			pmap_physpage_addref(l2pte);
-			error = pmap_ptpage_alloc(l2pte, PGU_L3PT);
+			error = pmap_ptpage_alloc(pmap, l2pte, PGU_L3PT);
 			if (error) {
 /* unlocks pmap */
 pmap_enter_l2pt_delref(pmap, l1pte, l2pte);
@@ -3652,7 +3639,7 @@ pmap_l1pt_free(struct pool *pp, void *v)
  *	Note: the pmap must already be locked.
  */
 static int
-pmap_ptpage_alloc(pt_entry_t * const pte, int const usage)
+pmap_ptpage_alloc(pmap_t pmap, pt_entry_t * const pte, int const usage)
 {
 	/*
 	 * Allocate the page table page.
@@ -3662,6 +3649,8 @@ pmap_ptpage_alloc(pt_entry_t * const pte
 		return ENOMEM;
 	}
 
+	LIST_INSERT_HEAD(>pm_ptpages, pg, pageq.list);
+
 	/*
 	 * Initialize the referencing PTE.
 	 */
@@ -3682,7 +3671,8 @@ pmap_ptpage_alloc(pt_entry_t * const pte
  *	Note: the pmap must already be locked.
  */
 static void
-pmap_ptpage_free(pt_entry_t * const pte, struct pmap_tlb_context * const tlbctx)
+pmap_ptpage_free(pmap_t pmap, pt_entry_t * const pte,
+struct pmap_tlb_context * const tlbctx)
 {
 
 	/*
@@ -3692,10 +3682,18 @@ pmap_ptpage_free(pt_entry_t * const pte,
 	const paddr_t ptpa = pmap_pte_pa(pte);
 	atomic_store_relaxed(pte, PG_NV);
 
+	struct vm_page * const pg = PHYS_TO_VM_PAGE(ptpa);
+	KASSERT(pg != NULL);
+
 #ifdef DEBUG
+	struct vm_page_md * const md = VM_PAGE_TO_MD(pg);
+	KDASSERT(md->pvh_refcnt == 0);
+
 	pmap_zero_page(ptpa);
 #endif
-	pmap_tlb_physpage_free(ptpa, tlbctx);
+
+	LIST_REMOVE(pg, pageq.list);
+	LIST_INSERT_HEAD(>t_freeptq, pg, pageq.list);
 }
 
 /*
@@ -3735,7 +3733,7 @@ pmap_l3pt_delref(pmap_t pmap, vaddr_t va
 		 * be dropped.
 		 */
 		KASSERT(tlbctx != NULL);
-		

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

2021-05-29 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 30 01:24:19 UTC 2021

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

Log Message:
Change pmap_physpage_alloc() to return the vm_page * so that the
callers have access to it.


To generate a diff of this commit:
cvs rdiff -u -r1.282 -r1.283 src/sys/arch/alpha/alpha/pmap.c

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

Modified files:

Index: src/sys/arch/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.282 src/sys/arch/alpha/alpha/pmap.c:1.283
--- src/sys/arch/alpha/alpha/pmap.c:1.282	Sun May 30 00:34:27 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Sun May 30 01:24:19 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.282 2021/05/30 00:34:27 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.283 2021/05/30 01:24:19 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.282 2021/05/30 00:34:27 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.283 2021/05/30 01:24:19 thorpej Exp $");
 
 #include 
 #include 
@@ -1162,7 +1162,7 @@ static u_int	pmap_asn_alloc(pmap_t, stru
 /*
  * Misc. functions.
  */
-static bool	pmap_physpage_alloc(int, paddr_t *);
+static struct vm_page *pmap_physpage_alloc(int);
 static void	pmap_physpage_free(paddr_t);
 static int	pmap_physpage_addref(void *);
 static int	pmap_physpage_delref(void *);
@@ -3349,11 +3349,11 @@ pmap_pv_remove(pmap_t pmap, struct vm_pa
 static void *
 pmap_pv_page_alloc(struct pool *pp, int flags)
 {
-	paddr_t pg;
-
-	if (pmap_physpage_alloc(PGU_PVENT, ))
-		return ((void *)ALPHA_PHYS_TO_K0SEG(pg));
-	return (NULL);
+	struct vm_page * const pg = pmap_physpage_alloc(PGU_PVENT);
+	if (__predict_false(pg == NULL)) {
+		return NULL;
+	}
+	return (void *)ALPHA_PHYS_TO_K0SEG(VM_PAGE_TO_PHYS(pg));
 }
 
 /*
@@ -3376,11 +3376,10 @@ pmap_pv_page_free(struct pool *pp, void 
  *	Allocate a single page from the VM system and return the
  *	physical address for that page.
  */
-static bool
-pmap_physpage_alloc(int usage, paddr_t *pap)
+static struct vm_page *
+pmap_physpage_alloc(int usage)
 {
 	struct vm_page *pg;
-	paddr_t pa;
 
 	/*
 	 * Don't ask for a zero'd page in the L1PT case -- we will
@@ -3390,7 +3389,6 @@ pmap_physpage_alloc(int usage, paddr_t *
 	pg = uvm_pagealloc(NULL, 0, NULL, usage == PGU_L1PT ?
 	UVM_PGA_USERESERVE : UVM_PGA_USERESERVE|UVM_PGA_ZERO);
 	if (pg != NULL) {
-		pa = VM_PAGE_TO_PHYS(pg);
 #ifdef DEBUG
 		struct vm_page_md * const md = VM_PAGE_TO_MD(pg);
 		if (md->pvh_refcnt != 0) {
@@ -3399,10 +3397,8 @@ pmap_physpage_alloc(int usage, paddr_t *
 			panic("pmap_physpage_alloc");
 		}
 #endif
-		*pap = pa;
-		return (true);
 	}
-	return (false);
+	return pg;
 }
 
 /*
@@ -3485,7 +3481,12 @@ pmap_kptpage_alloc(paddr_t *pap)
 		return true;
 	}
 
-	return pmap_physpage_alloc(PGU_NORMAL, pap);
+	struct vm_page * const pg = pmap_physpage_alloc(PGU_NORMAL);
+	if (__predict_true(pg != NULL)) {
+		*pap = VM_PAGE_TO_PHYS(pg);
+		return true;
+	}
+	return false;
 }
 
 /*
@@ -3620,15 +3621,14 @@ pmap_l1pt_ctor(void *arg, void *object, 
 static void *
 pmap_l1pt_alloc(struct pool *pp, int flags)
 {
-	paddr_t ptpa;
-
 	/*
 	 * Attempt to allocate a free page.
 	 */
-	if (pmap_physpage_alloc(PGU_L1PT, ) == false)
-		return (NULL);
-
-	return ((void *) ALPHA_PHYS_TO_K0SEG(ptpa));
+	struct vm_page * const pg = pmap_physpage_alloc(PGU_L1PT);
+	if (__predict_false(pg == NULL)) {
+		return NULL;
+	}
+	return (void *)ALPHA_PHYS_TO_K0SEG(VM_PAGE_TO_PHYS(pg));
 }
 
 /*
@@ -3654,18 +3654,18 @@ pmap_l1pt_free(struct pool *pp, void *v)
 static int
 pmap_ptpage_alloc(pt_entry_t * const pte, int const usage)
 {
-	paddr_t ptpa;
-
 	/*
 	 * Allocate the page table page.
 	 */
-	if (pmap_physpage_alloc(usage, ) == false)
-		return (ENOMEM);
+	struct vm_page * const pg = pmap_physpage_alloc(usage);
+	if (__predict_false(pg == NULL)) {
+		return ENOMEM;
+	}
 
 	/*
 	 * Initialize the referencing PTE.
 	 */
-	const pt_entry_t npte = ((ptpa >> PGSHIFT) << PG_SHIFT) |
+	const pt_entry_t npte = ((VM_PAGE_TO_PHYS(pg) >> PGSHIFT) << PG_SHIFT) |
 	PG_V | PG_KRE | PG_KWE | PG_WIRED;
 
 	atomic_store_relaxed(pte, npte);



CVS commit: src/sys/arch/alpha

2021-05-29 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 30 00:34:27 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: pmap.c
src/sys/arch/alpha/include: pmap.h

Log Message:
Define a pmap_pagelist LIST_HEAD and use it where we used ad hoc LIST_HEADs
of vm_page structures.  Define and use a generic routine to free such a list
back to UVM.

In pmap_remove_internal(), KASSERT that no PT pages are queued up to be
freed when removing mappings from the kernel pmap.


To generate a diff of this commit:
cvs rdiff -u -r1.281 -r1.282 src/sys/arch/alpha/alpha/pmap.c
cvs rdiff -u -r1.88 -r1.89 src/sys/arch/alpha/include/pmap.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/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.281 src/sys/arch/alpha/alpha/pmap.c:1.282
--- src/sys/arch/alpha/alpha/pmap.c:1.281	Sat May 29 23:27:22 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Sun May 30 00:34:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.281 2021/05/29 23:27:22 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.282 2021/05/30 00:34:27 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.281 2021/05/29 23:27:22 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.282 2021/05/30 00:34:27 thorpej Exp $");
 
 #include 
 #include 
@@ -432,6 +432,21 @@ pmap_activation_lock(pmap_t const pmap)
 #endif /* MULTIPROCESSOR */
 
 /*
+ * Generic routine for freeing pages on a pmap_pagelist back to
+ * the system.
+ */
+static void
+pmap_pagelist_free(struct pmap_pagelist * const list)
+{
+	struct vm_page *pg;
+
+	while ((pg = LIST_FIRST(list)) != NULL) {
+		LIST_REMOVE(pg, pageq.list);
+		uvm_pagefree(pg);
+	}
+}
+
+/*
  * TLB management.
  *
  * TLB invalidations need to be performed on local and remote CPUs
@@ -526,7 +541,7 @@ pmap_activation_lock(pmap_t const pmap)
 struct pmap_tlb_context {
 	uintptr_t	t_addrdata[TLB_CTX_MAXVA];
 	pmap_t		t_pmap;
-	LIST_HEAD(, vm_page) t_freeptq;
+	struct pmap_pagelist t_freeptq;
 };
 
 static struct {
@@ -1082,15 +1097,10 @@ pmap_tlb_physpage_free(paddr_t const ptp
 	LIST_INSERT_HEAD(>t_freeptq, pg, pageq.list);
 }
 
-static void
+static __inline void
 pmap_tlb_ptpage_drain(struct pmap_tlb_context * const tlbctx)
 {
-	struct vm_page *pg;
-
-	while ((pg = LIST_FIRST(>t_freeptq)) != NULL) {
-		LIST_REMOVE(pg, pageq.list);
-		uvm_pagefree(pg);
-	}
+	pmap_pagelist_free(>t_freeptq);
 }
 
 /*
@@ -1720,7 +1730,8 @@ pmap_remove_internal(pmap_t pmap, vaddr_
 		PMAP_MAP_TO_HEAD_UNLOCK();
 		PMAP_UNLOCK(pmap);
 		pmap_tlb_shootnow(tlbctx);
-		pmap_tlb_ptpage_drain(tlbctx);
+		/* kernel PT pages are never freed. */
+		KASSERT(LIST_EMPTY(>t_freeptq));
 		TLB_COUNT(reason_remove_kernel);
 
 		return;

Index: src/sys/arch/alpha/include/pmap.h
diff -u src/sys/arch/alpha/include/pmap.h:1.88 src/sys/arch/alpha/include/pmap.h:1.89
--- src/sys/arch/alpha/include/pmap.h:1.88	Sat May 29 23:27:22 2021
+++ src/sys/arch/alpha/include/pmap.h	Sun May 30 00:34:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.h,v 1.88 2021/05/29 23:27:22 thorpej Exp $ */
+/* $NetBSD: pmap.h,v 1.89 2021/05/30 00:34:27 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007 The NetBSD Foundation, Inc.
@@ -131,6 +131,9 @@
  * allocate any ASN info for the kernel pmap at all.
  * arrays which hold enough for ALPHA_MAXPROCS.
  */
+
+LIST_HEAD(pmap_pagelist, vm_page);
+
 struct pmap_percpu {
 	unsigned int		pmc_asn;	/* address space number */
 	unsigned int		pmc_pad0;



CVS commit: src/sys/arch/alpha

2021-05-29 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May 29 23:27:22 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: pmap.c vm_machdep.c
src/sys/arch/alpha/include: pmap.h

Log Message:
Move the pointer to the pmap's lev1map out of the shared pmap structure
and into each CPU's pmap_percpu area.  This pointer is constant for the
life of the pmap, and moving it gives us an additional 8 bytes in the
shared pmap structure.

Because the kernel pmap does not have per-CPU data, all places where we
need the kernel pmap's lev1map now just reference kernel_lev1map directly.


To generate a diff of this commit:
cvs rdiff -u -r1.280 -r1.281 src/sys/arch/alpha/alpha/pmap.c
cvs rdiff -u -r1.117 -r1.118 src/sys/arch/alpha/alpha/vm_machdep.c
cvs rdiff -u -r1.87 -r1.88 src/sys/arch/alpha/include/pmap.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/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.280 src/sys/arch/alpha/alpha/pmap.c:1.281
--- src/sys/arch/alpha/alpha/pmap.c:1.280	Sat May 29 22:14:09 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Sat May 29 23:27:22 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.280 2021/05/29 22:14:09 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.281 2021/05/29 23:27:22 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.280 2021/05/29 22:14:09 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.281 2021/05/29 23:27:22 thorpej Exp $");
 
 #include 
 #include 
@@ -1173,19 +1173,19 @@ static bool	vtophys_internal(vaddr_t, pa
 ({	\
 	pt_entry_t *l1pte_, *l2pte_;	\
 	\
-	l1pte_ = pmap_l1pte(pmap_kernel(), va);\
+	l1pte_ = pmap_l1pte(kernel_lev1map, va);			\
 	if (pmap_pte_v(l1pte_) == 0) {	\
 		printf("kernel level 1 PTE not valid, va 0x%lx "	\
 		"(line %d)\n", (va), __LINE__);			\
 		panic("PMAP_KERNEL_PTE");\
 	}\
-	l2pte_ = pmap_l2pte(pmap_kernel(), va, l1pte_);			\
+	l2pte_ = pmap_l2pte(kernel_lev1map, va, l1pte_);		\
 	if (pmap_pte_v(l2pte_) == 0) {	\
 		printf("kernel level 2 PTE not valid, va 0x%lx "	\
 		"(line %d)\n", (va), __LINE__);			\
 		panic("PMAP_KERNEL_PTE");\
 	}\
-	pmap_l3pte(pmap_kernel(), va, l2pte_);\
+	pmap_l3pte(kernel_lev1map, va, l2pte_);\
 })
 #else
 #define	PMAP_KERNEL_PTE(va)	([VPT_INDEX((va))])
@@ -1388,9 +1388,8 @@ pmap_bootstrap(paddr_t ptaddr, u_int max
 	 * generation.
 	 */
 	memset(pmap_kernel(), 0, sizeof(struct pmap));
-	pmap_kernel()->pm_lev1map = kernel_lev1map;
 	atomic_store_relaxed(_kernel()->pm_count, 1);
-	/* Kernel pmap does not have ASN info. */
+	/* Kernel pmap does not have per-CPU info. */
 	TAILQ_INSERT_TAIL(_all_pmaps, pmap_kernel(), pm_list);
 
 	/*
@@ -1562,6 +1561,7 @@ pmap_t
 pmap_create(void)
 {
 	pmap_t pmap;
+	pt_entry_t *lev1map;
 	int i;
 
 #ifdef DEBUG
@@ -1574,24 +1574,29 @@ pmap_create(void)
 
 	atomic_store_relaxed(>pm_count, 1);
 
+ try_again:
+	rw_enter(_growkernel_lock, RW_READER);
+
+	lev1map = pool_cache_get(_l1pt_cache, PR_NOWAIT);
+	if (__predict_false(lev1map == NULL)) {
+		rw_exit(_growkernel_lock);
+		(void) kpause("pmap_create", false, hz >> 2, NULL);
+		goto try_again;
+	}
+
 	/*
 	 * There are only kernel mappings at this point; give the pmap
 	 * the kernel ASN.  This will be initialized to correct values
 	 * when the pmap is activated.
+	 *
+	 * We stash a pointer to the pmap's lev1map in each CPU's
+	 * private data.  It remains constant for the life of the
+	 * pmap, and gives us more room in the shared pmap structure.
 	 */
 	for (i = 0; i < pmap_ncpuids; i++) {
 		pmap->pm_percpu[i].pmc_asn = PMAP_ASN_KERNEL;
 		pmap->pm_percpu[i].pmc_asngen = PMAP_ASNGEN_INVALID;
-	}
-
- try_again:
-	rw_enter(_growkernel_lock, RW_READER);
-
-	pmap->pm_lev1map = pool_cache_get(_l1pt_cache, PR_NOWAIT);
-	if (__predict_false(pmap->pm_lev1map == NULL)) {
-		rw_exit(_growkernel_lock);
-		(void) kpause("pmap_create", false, hz >> 2, NULL);
-		goto try_again;
+		pmap->pm_percpu[i].pmc_lev1map = lev1map;
 	}
 
 	mutex_enter(_all_pmaps_lock);
@@ -1623,6 +1628,9 @@ pmap_destroy(pmap_t pmap)
 	if (atomic_dec_uint_nv(>pm_count) > 0)
 		return;
 
+	pt_entry_t *lev1map = pmap_lev1map(pmap);
+	int i;
+
 	rw_enter(_growkernel_lock, RW_READER);
 
 	/*
@@ -1632,8 +1640,12 @@ pmap_destroy(pmap_t pmap)
 	TAILQ_REMOVE(_all_pmaps, pmap, pm_list);
 	mutex_exit(_all_pmaps_lock);
 
-	pool_cache_put(_l1pt_cache, pmap->pm_lev1map);
-	pmap->pm_lev1map = (pt_entry_t *)0xdeadbeefUL;
+	pool_cache_put(_l1pt_cache, lev1map);
+#ifdef DIAGNOSTIC
+	for (i = 0; i < pmap_ncpuids; i++) {
+		pmap->pm_percpu[i].pmc_lev1map = (pt_entry_t *)0xdeadbeefUL;
+	}
+#endif /* DIAGNOSTIC */
 
 	rw_exit(_growkernel_lock);
 
@@ -1714,19 +1726,21 @@ pmap_remove_internal(pmap_t pmap, vaddr_
 		return;
 	}
 
+	pt_entry_t * const 

CVS commit: src/sys/arch/alpha

2021-05-29 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May 29 22:14:09 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: pmap.c
src/sys/arch/alpha/include: pmap.h

Log Message:
Rather than tracking "needs I-sync on return to userspace" in a bitmap,
track it with a separate field in the pmap_percpu.  Not only does this
reduce cache line contention ever so slightly, it also frees up a field
in the shared portion of the pmap structure.


To generate a diff of this commit:
cvs rdiff -u -r1.279 -r1.280 src/sys/arch/alpha/alpha/pmap.c
cvs rdiff -u -r1.86 -r1.87 src/sys/arch/alpha/include/pmap.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/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.279 src/sys/arch/alpha/alpha/pmap.c:1.280
--- src/sys/arch/alpha/alpha/pmap.c:1.279	Sat May 29 21:54:50 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Sat May 29 22:14:09 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.279 2021/05/29 21:54:50 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.280 2021/05/29 22:14:09 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.279 2021/05/29 21:54:50 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.280 2021/05/29 22:14:09 thorpej Exp $");
 
 #include 
 #include 
@@ -862,8 +862,6 @@ pmap_tlb_invalidate(const struct pmap_tl
 	pmap_t const pmap = tlbctx->t_pmap;
 	KASSERT(pmap != NULL);
 
-	const u_long cpu_mask = 1UL << ci->ci_cpuid;
-
 	if (__predict_false(pmap != ci->ci_pmap)) {
 		TLB_COUNT(invalidate_user_not_current);
 
@@ -875,6 +873,8 @@ pmap_tlb_invalidate(const struct pmap_tl
 			return;
 		}
 
+		const u_long cpu_mask = 1UL << ci->ci_cpuid;
+
 		/*
 		 * We cannot directly invalidate the TLB in this case,
 		 * so force allocation of a new ASN when the pmap becomes
@@ -890,14 +890,14 @@ pmap_tlb_invalidate(const struct pmap_tl
 		 * of accounting for internal consistency.
 		 */
 		if (TLB_CTX_FLAGS(tlbctx) & TLB_CTX_F_IMB) {
-			atomic_or_ulong(>pm_needisync, cpu_mask);
+			pmap->pm_percpu[ci->ci_cpuid].pmc_needisync = 1;
 		}
 		return;
 	}
 
 	if (TLB_CTX_FLAGS(tlbctx) & TLB_CTX_F_IMB) {
 		TLB_COUNT(invalidate_user_lazy_imb);
-		atomic_or_ulong(>pm_needisync, cpu_mask);
+		pmap->pm_percpu[ci->ci_cpuid].pmc_needisync = 1;
 	}
 
 	if (count == TLB_CTX_ALLVA) {
@@ -3882,7 +3882,7 @@ pmap_asn_alloc(pmap_t const pmap, struct
 	 * We have a new ASN, so we can skip any pending I-stream sync
 	 * on the way back out to user space.
 	 */
-	atomic_and_ulong(>pm_needisync, ~(1UL << ci->ci_cpuid));
+	pmc->pmc_needisync = 0;
 
 #ifdef DEBUG
 	if (pmapdebug & PDB_ASN)

Index: src/sys/arch/alpha/include/pmap.h
diff -u src/sys/arch/alpha/include/pmap.h:1.86 src/sys/arch/alpha/include/pmap.h:1.87
--- src/sys/arch/alpha/include/pmap.h:1.86	Sat May 29 21:54:51 2021
+++ src/sys/arch/alpha/include/pmap.h	Sat May 29 22:14:09 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.h,v 1.86 2021/05/29 21:54:51 thorpej Exp $ */
+/* $NetBSD: pmap.h,v 1.87 2021/05/29 22:14:09 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007 The NetBSD Foundation, Inc.
@@ -135,17 +135,19 @@ struct pmap_percpu {
 	unsigned int		pmc_asn;	/* address space number */
 	unsigned int		pmc_pad0;
 	unsigned long		pmc_asngen;	/* ASN generation number */
-	unsigned long		pmc_padN[(COHERENCY_UNIT / 8) - 2];
+	unsigned int		pmc_needisync;	/* CPU needes isync */
+	unsigned int		pmc_pad1;
+	unsigned long		pmc_padN[(COHERENCY_UNIT / 8) - 3];
 };
 
 struct pmap {	/* pmaps are aligned to COHERENCY_UNIT boundaries */
 		/* pmaps are locked by hashed mutexes */
 	pt_entry_t		*pm_lev1map;	/* [ 0] level 1 map */
 	unsigned long		pm_cpus;	/* [ 8] CPUs using pmap */
-	unsigned long		pm_needisync;	/* [16] CPUs needing isync */
+	unsigned long		__pm_spare0;	/* [16] spare field */
 	struct pmap_statistics	pm_stats;	/* [32] statistics */
 	unsigned int		pm_count;	/* [40] reference count */
-	unsigned int		__pm_spare;	/* [44] spare field */
+	unsigned int		__pm_spare1;	/* [44] spare field */
 	TAILQ_ENTRY(pmap)	pm_list;	/* [48] list of all pmaps */
 	/* -- COHERENCY_UNIT boundary -- */
 	struct pmap_percpu	pm_percpu[];	/* [64] per-CPU data */
@@ -326,10 +328,10 @@ pmap_l3pte(pmap_t pmap, vaddr_t v, pt_en
  */
 #define	PMAP_USERRET(pmap)		\
 do {	\
-	u_long cpu_mask = (1UL << cpu_number());			\
+	const unsigned long cpu_id = cpu_number();			\
 	\
-	if ((pmap)->pm_needisync & cpu_mask) {\
-		atomic_and_ulong(&(pmap)->pm_needisync,	~cpu_mask);	\
+	if ((pmap)->pm_percpu[cpu_id].pmc_needisync) {			\
+		(pmap)->pm_percpu[cpu_id].pmc_needisync = 0;		\
 		alpha_pal_imb();	\
 	}\
 } while (0)



CVS commit: src/sys/arch/alpha

2021-05-29 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May 29 21:54:51 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: pmap.c
src/sys/arch/alpha/include: pmap.h

Log Message:
Rename pmap_asn_info to pmap_percpu, and pmap::pm_asni to pmap::pm_percpu.
No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.278 -r1.279 src/sys/arch/alpha/alpha/pmap.c
cvs rdiff -u -r1.85 -r1.86 src/sys/arch/alpha/include/pmap.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/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.278 src/sys/arch/alpha/alpha/pmap.c:1.279
--- src/sys/arch/alpha/alpha/pmap.c:1.278	Mon May 24 03:43:24 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Sat May 29 21:54:50 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.278 2021/05/24 03:43:24 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.279 2021/05/29 21:54:50 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.278 2021/05/24 03:43:24 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.279 2021/05/29 21:54:50 thorpej Exp $");
 
 #include 
 #include 
@@ -265,9 +265,9 @@ static struct pool_cache pmap_pmap_cache
 static struct pool_cache pmap_l1pt_cache __read_mostly;
 static struct pool_cache pmap_pv_cache __read_mostly;
 
-CTASSERT(offsetof(struct pmap, pm_asni[0]) == COHERENCY_UNIT);
+CTASSERT(offsetof(struct pmap, pm_percpu[0]) == COHERENCY_UNIT);
 CTASSERT(PMAP_SIZEOF(ALPHA_MAXPROCS) < ALPHA_PGBYTES);
-CTASSERT(sizeof(struct pmap_asn_info) == COHERENCY_UNIT);
+CTASSERT(sizeof(struct pmap_percpu) == COHERENCY_UNIT);
 
 /*
  * Address Space Numbers.
@@ -880,7 +880,7 @@ pmap_tlb_invalidate(const struct pmap_tl
 		 * so force allocation of a new ASN when the pmap becomes
 		 * active again.
 		 */
-		pmap->pm_asni[ci->ci_cpuid].pma_asngen = PMAP_ASNGEN_INVALID;
+		pmap->pm_percpu[ci->ci_cpuid].pmc_asngen = PMAP_ASNGEN_INVALID;
 		atomic_and_ulong(>pm_cpus, ~cpu_mask);
 
 		/*
@@ -1580,8 +1580,8 @@ pmap_create(void)
 	 * when the pmap is activated.
 	 */
 	for (i = 0; i < pmap_ncpuids; i++) {
-		pmap->pm_asni[i].pma_asn = PMAP_ASN_KERNEL;
-		pmap->pm_asni[i].pma_asngen = PMAP_ASNGEN_INVALID;
+		pmap->pm_percpu[i].pmc_asn = PMAP_ASN_KERNEL;
+		pmap->pm_percpu[i].pmc_asngen = PMAP_ASNGEN_INVALID;
 	}
 
  try_again:
@@ -3814,7 +3814,7 @@ pmap_asn_alloc(pmap_t const pmap, struct
 	if (pmap_max_asn == 0)
 		return 0;
 
-	struct pmap_asn_info * const pma = >pm_asni[ci->ci_cpuid];
+	struct pmap_percpu * const pmc = >pm_percpu[ci->ci_cpuid];
 
 	/*
 	 * Hopefully, we can continue using the one we have...
@@ -3824,14 +3824,14 @@ pmap_asn_alloc(pmap_t const pmap, struct
 	 * the generation counter at 1, but initialize pmaps with
 	 * 0; this forces the first ASN allocation to occur.
 	 */
-	if (pma->pma_asngen == ci->ci_asn_gen) {
+	if (pmc->pmc_asngen == ci->ci_asn_gen) {
 #ifdef DEBUG
 		if (pmapdebug & PDB_ASN)
 			printf("pmap_asn_alloc: same generation, keeping %u\n",
-			pma->pma_asn);
+			pmc->pmc_asn);
 #endif
 		TLB_COUNT(asn_reuse);
-		return pma->pma_asn;
+		return pmc->pmc_asn;
 	}
 
 	/*
@@ -3874,8 +3874,8 @@ pmap_asn_alloc(pmap_t const pmap, struct
 	/*
 	 * Assign the new ASN and validate the generation number.
 	 */
-	pma->pma_asn = ci->ci_next_asn++;
-	pma->pma_asngen = ci->ci_asn_gen;
+	pmc->pmc_asn = ci->ci_next_asn++;
+	pmc->pmc_asngen = ci->ci_asn_gen;
 	TLB_COUNT(asn_assign);
 
 	/*
@@ -3887,7 +3887,7 @@ pmap_asn_alloc(pmap_t const pmap, struct
 #ifdef DEBUG
 	if (pmapdebug & PDB_ASN)
 		printf("pmap_asn_alloc: assigning %u to pmap %p\n",
-		pma->pma_asn, pmap);
+		pmc->pmc_asn, pmap);
 #endif
-	return pma->pma_asn;
+	return pmc->pmc_asn;
 }

Index: src/sys/arch/alpha/include/pmap.h
diff -u src/sys/arch/alpha/include/pmap.h:1.85 src/sys/arch/alpha/include/pmap.h:1.86
--- src/sys/arch/alpha/include/pmap.h:1.85	Mon May 24 03:43:24 2021
+++ src/sys/arch/alpha/include/pmap.h	Sat May 29 21:54:51 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.h,v 1.85 2021/05/24 03:43:24 thorpej Exp $ */
+/* $NetBSD: pmap.h,v 1.86 2021/05/29 21:54:51 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007 The NetBSD Foundation, Inc.
@@ -131,11 +131,11 @@
  * allocate any ASN info for the kernel pmap at all.
  * arrays which hold enough for ALPHA_MAXPROCS.
  */
-struct pmap_asn_info {
-	unsigned int		pma_asn;	/* address space number */
-	unsigned int		pma_pad0;
-	unsigned long		pma_asngen;	/* ASN generation number */
-	unsigned long		pma_padN[(COHERENCY_UNIT / 8) - 2];
+struct pmap_percpu {
+	unsigned int		pmc_asn;	/* address space number */
+	unsigned int		pmc_pad0;
+	unsigned long		pmc_asngen;	/* ASN generation number */
+	unsigned long		pmc_padN[(COHERENCY_UNIT / 8) - 2];
 };
 
 struct pmap {	/* pmaps are aligned to COHERENCY_UNIT boundaries */
@@ 

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

2021-05-28 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri May 28 07:33:02 UTC 2021

Modified Files:
src/sys/arch/alpha/conf: GENERIC

Log Message:
 Add ixg* (commented out). Tested with rin@'s AlphaServer DS10.


To generate a diff of this commit:
cvs rdiff -u -r1.410 -r1.411 src/sys/arch/alpha/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/alpha/conf/GENERIC
diff -u src/sys/arch/alpha/conf/GENERIC:1.410 src/sys/arch/alpha/conf/GENERIC:1.411
--- src/sys/arch/alpha/conf/GENERIC:1.410	Mon Sep 28 03:30:47 2020
+++ src/sys/arch/alpha/conf/GENERIC	Fri May 28 07:33:02 2021
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.410 2020/09/28 03:30:47 thorpej Exp $
+# $NetBSD: GENERIC,v 1.411 2021/05/28 07:33:02 msaitoh Exp $
 #
 # This machine description file is used to generate the default NetBSD
 # kernel.
@@ -19,7 +19,7 @@ include 	"arch/alpha/conf/std.alpha"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-ident		"GENERIC-$Revision: 1.410 $"
+ident		"GENERIC-$Revision: 1.411 $"
 
 maxusers 32
 
@@ -311,6 +311,7 @@ fxp*	at	pci? dev ? function ?		# Intel E
 gsip*	at	pci? dev ? function ?		# NS DP83820 Gigabit Ethernet
 iha*	at	pci? dev ? function ?		# Initio INIC-940/950 SCSI
 isp*	at	pci? dev ? function ?		# Qlogic ISP 10x0 SCSI
+#ixg*	at	pci? dev ? function ?		# Intel 8259x 10G Ethernet
 pcn*	at	pci? dev ? function ?		# PCnet-PCI Ethernet
 sf*	at	pci? dev ? function ?		# Adaptec AIC-6915 Ethernet
 siop*	at	pci? dev ? function ?		# Symbios 53c8xx SCSI



CVS commit: src/sys/arch/alpha

2021-05-27 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Thu May 27 22:11:31 UTC 2021

Modified Files:
src/sys/arch/alpha/include: pci_machdep.h
src/sys/arch/alpha/pci: tsc.c tsp_dma.c tsreg.h tsvar.h

Log Message:
The Tsunami / Typhoon chipsets have a static "monster window" for DMA
that allows for up to 32GB of RAM to be direct-mapped if the PCI device
can issue a 64-bit address (the monster window lives at 0x100).
Enable this window and provide this to the PCI bus as a "dmat64".


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/alpha/include/pci_machdep.h
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/alpha/pci/tsc.c
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/alpha/pci/tsp_dma.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/alpha/pci/tsreg.h
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/alpha/pci/tsvar.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/alpha/include/pci_machdep.h
diff -u src/sys/arch/alpha/include/pci_machdep.h:1.21 src/sys/arch/alpha/include/pci_machdep.h:1.22
--- src/sys/arch/alpha/include/pci_machdep.h:1.21	Sat Sep 26 21:07:48 2020
+++ src/sys/arch/alpha/include/pci_machdep.h	Thu May 27 22:11:31 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_machdep.h,v 1.21 2020/09/26 21:07:48 thorpej Exp $ */
+/* $NetBSD: pci_machdep.h,v 1.22 2021/05/27 22:11:31 thorpej Exp $ */
 
 /*
  * Copyright (c) 1996 Carnegie-Mellon University.
@@ -36,6 +36,7 @@
  * Machine-specific definitions for PCI autoconfiguration.
  */
 #define	__HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
+#define	_PCI_HAVE_DMA64
 
 /*
  * Types provided to machine-independent PCI code

Index: src/sys/arch/alpha/pci/tsc.c
diff -u src/sys/arch/alpha/pci/tsc.c:1.25 src/sys/arch/alpha/pci/tsc.c:1.26
--- src/sys/arch/alpha/pci/tsc.c:1.25	Sat Apr 24 23:36:23 2021
+++ src/sys/arch/alpha/pci/tsc.c	Thu May 27 22:11:31 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tsc.c,v 1.25 2021/04/24 23:36:23 thorpej Exp $ */
+/* $NetBSD: tsc.c,v 1.26 2021/05/27 22:11:31 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1999 by Ross Harvey.  All rights reserved.
@@ -35,7 +35,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.25 2021/04/24 23:36:23 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.26 2021/05/27 22:11:31 thorpej Exp $");
 
 #include 
 #include 
@@ -231,7 +231,7 @@ tspattach(device_t parent, device_t self
 	pba.pba_memt = >pc_memt;
 	pba.pba_dmat =
 	alphabus_dma_get_tag(>pc_dmat_direct, ALPHA_BUS_PCI);
-	pba.pba_dmat64 = NULL;
+	pba.pba_dmat64 = >pc_dmat64_direct;
 	pba.pba_pc = >pc_pc;
 	pba.pba_bus = 0;
 	pba.pba_bridgetag = NULL;

Index: src/sys/arch/alpha/pci/tsp_dma.c
diff -u src/sys/arch/alpha/pci/tsp_dma.c:1.16 src/sys/arch/alpha/pci/tsp_dma.c:1.17
--- src/sys/arch/alpha/pci/tsp_dma.c:1.16	Wed May  5 02:15:18 2021
+++ src/sys/arch/alpha/pci/tsp_dma.c	Thu May 27 22:11:31 2021
@@ -1,4 +1,34 @@
-/* $NetBSD: tsp_dma.c,v 1.16 2021/05/05 02:15:18 thorpej Exp $ */
+/* $NetBSD: tsp_dma.c,v 1.17 2021/05/27 22:11:31 thorpej Exp $ */
+
+/*-
+ * Copyright (c) 1997, 1998, 2021 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
+ * NASA Ames Research Center.
+ *
+ * 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.
+ */
 
 /*-
  * Copyright (c) 1999 by Ross Harvey.  All rights reserved.
@@ -28,41 +58,10 @@
  * 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.
- *
- */
-
-/*-
- * Copyright (c) 1997, 1998 The NetBSD 

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

2021-05-27 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Thu May 27 22:05:25 UTC 2021

Modified Files:
src/sys/arch/alpha/include: alpha_cpu.h

Log Message:
Define the arithmetic exception summary bits passed in a0 to entArith.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/arch/alpha/include/alpha_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/alpha/include/alpha_cpu.h
diff -u src/sys/arch/alpha/include/alpha_cpu.h:1.53 src/sys/arch/alpha/include/alpha_cpu.h:1.54
--- src/sys/arch/alpha/include/alpha_cpu.h:1.53	Thu Oct 15 00:55:09 2020
+++ src/sys/arch/alpha/include/alpha_cpu.h	Thu May 27 22:05:24 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: alpha_cpu.h,v 1.53 2020/10/15 00:55:09 thorpej Exp $ */
+/* $NetBSD: alpha_cpu.h,v 1.54 2021/05/27 22:05:24 thorpej Exp $ */
 
 /*
  * Copyright (c) 1996 Carnegie-Mellon University.
@@ -44,6 +44,7 @@
  *	Virtual Memory Management
  *	Kernel Entry Vectors
  *	MMCSR Fault Type Codes
+ *	AESR Fault Code bits
  *	Translation Buffer Invalidation
  *
  * and miscellaneous PALcode operations.
@@ -265,6 +266,18 @@ typedef unsigned long alpha_pt_entry_t;
 #define	ALPHA_KENTRY_SYS	5
 
 /*
+ * Arithmetic Exception Summary Register.  [OSF/1 PALcode Specific]
+ */
+
+#define	ALPHA_AESR_SWC		__BIT(0)	/* software completion */
+#define	ALPHA_AESR_INV		__BIT(1)	/* invalid operation */
+#define	ALPHA_AESR_DZE		__BIT(2)	/* division by zero */
+#define	ALPHA_AESR_OVF		__BIT(3)	/* overflow */
+#define	ALPHA_AESR_UNF		__BIT(4)	/* underflow */
+#define	ALPHA_AESR_INE		__BIT(5)	/* inexact result */
+#define	ALPHA_AESR_IOV		__BIT(6)	/* integer overflow */
+
+/*
  * MMCSR Fault Type Codes.  [OSF/1 PALcode Specific]
  */
 



CVS commit: src/sys/arch/alpha

2021-05-24 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon May 24 21:00:12 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: machdep.c
src/sys/arch/alpha/include: mcontext.h

Log Message:
Add _UC_SETSTACK / _UC_CLRSTACK handling.  Fixes the t_sigaltstack test
on alpha.


To generate a diff of this commit:
cvs rdiff -u -r1.371 -r1.372 src/sys/arch/alpha/alpha/machdep.c
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/alpha/include/mcontext.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/alpha/alpha/machdep.c
diff -u src/sys/arch/alpha/alpha/machdep.c:1.371 src/sys/arch/alpha/alpha/machdep.c:1.372
--- src/sys/arch/alpha/alpha/machdep.c:1.371	Wed May  5 15:36:17 2021
+++ src/sys/arch/alpha/alpha/machdep.c	Mon May 24 21:00:12 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.371 2021/05/05 15:36:17 thorpej Exp $ */
+/* $NetBSD: machdep.c,v 1.372 2021/05/24 21:00:12 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2019, 2020 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.371 2021/05/05 15:36:17 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.372 2021/05/24 21:00:12 thorpej Exp $");
 
 #include 
 #include 
@@ -1525,6 +1525,8 @@ sendsig_siginfo(const ksiginfo_t *ksi, c
 	frame.sf_uc.uc_flags = _UC_SIGMASK;
 	frame.sf_uc.uc_sigmask = *mask;
 	frame.sf_uc.uc_link = l->l_ctxlink;
+	frame.sf_uc.uc_flags |= (l->l_sigstk.ss_flags & SS_ONSTACK)
+	? _UC_SETSTACK : _UC_CLRSTACK;
 	sendsig_reset(l, sig);
 	mutex_exit(p->p_lock);
 	cpu_getmcontext(l, _uc.uc_mcontext, _uc.uc_flags);
@@ -1885,8 +1887,10 @@ cpu_setmcontext(struct lwp *l, const mco
 		frame->tf_regs[FRAME_PC] = gr[_REG_PC];
 		frame->tf_regs[FRAME_PS] = gr[_REG_PS];
 	}
+
 	if (flags & _UC_TLSBASE)
 		lwp_setprivate(l, (void *)(uintptr_t)gr[_REG_UNIQUE]);
+
 	/* Restore floating point register context, if any. */
 	if (flags & _UC_FPU) {
 		/* If we have an FP register context, get rid of it. */
@@ -1896,6 +1900,13 @@ cpu_setmcontext(struct lwp *l, const mco
 		l->l_md.md_flags = mcp->__fpregs.__fp_fpcr & MDLWP_FP_C;
 	}
 
+	mutex_enter(l->l_proc->p_lock);
+	if (flags & _UC_SETSTACK)
+		l->l_sigstk.ss_flags |= SS_ONSTACK;
+	if (flags & _UC_CLRSTACK)
+		l->l_sigstk.ss_flags &= ~SS_ONSTACK;
+	mutex_exit(l->l_proc->p_lock);
+
 	return (0);
 }
 

Index: src/sys/arch/alpha/include/mcontext.h
diff -u src/sys/arch/alpha/include/mcontext.h:1.10 src/sys/arch/alpha/include/mcontext.h:1.11
--- src/sys/arch/alpha/include/mcontext.h:1.10	Fri Dec 27 00:32:16 2019
+++ src/sys/arch/alpha/include/mcontext.h	Mon May 24 21:00:12 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: mcontext.h,v 1.10 2019/12/27 00:32:16 kamil Exp $	*/
+/*	$NetBSD: mcontext.h,v 1.11 2021/05/24 21:00:12 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -94,6 +94,8 @@ typedef struct {
 
 /* Machine-dependent uc_flags */
 #define _UC_TLSBASE	0x20	/* valid process-unique value in _REG_UNIQUE */
+#define _UC_SETSTACK	0x0001
+#define _UC_CLRSTACK	0x0002
 
 #define _UC_MACHINE_SP(uc)	((uc)->uc_mcontext.__gregs[_REG_SP])
 #define _UC_MACHINE_FP(uc)	((uc)->uc_mcontext.__gregs[_REG_S6])



CVS commit: src/sys/arch/alpha

2021-05-23 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon May 24 03:43:24 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: pmap.c
src/sys/arch/alpha/include: pmap.h

Log Message:
pmap_tlb_shootdown_all_user() can be called in the PV scenario as well
as the forward scenario, for example if a pmap_page_protect() to remove
all mappings results in the freeing of a PT page.  It therefore needs
to do the same reference counting dance as pmap_tlb_shootdown_pv().

Also fix a use-after-free error in pmap_page_protect().

Add / tweak some assertions, and shrink the pmap::pm_count field from
long to unsigned int (which gave me a spare unsigned int field for
debugging purposes).

PR port-alpha/56201.


To generate a diff of this commit:
cvs rdiff -u -r1.277 -r1.278 src/sys/arch/alpha/alpha/pmap.c
cvs rdiff -u -r1.84 -r1.85 src/sys/arch/alpha/include/pmap.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/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.277 src/sys/arch/alpha/alpha/pmap.c:1.278
--- src/sys/arch/alpha/alpha/pmap.c:1.277	Sun May 23 19:13:27 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Mon May 24 03:43:24 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.277 2021/05/23 19:13:27 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.278 2021/05/24 03:43:24 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.277 2021/05/23 19:13:27 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.278 2021/05/24 03:43:24 thorpej Exp $");
 
 #include 
 #include 
@@ -667,17 +667,17 @@ pmap_tlb_init(void)
 }
 
 static inline void
-pmap_tlb_context_init(struct pmap_tlb_context * const tlbctx)
+pmap_tlb_context_init(struct pmap_tlb_context * const tlbctx, uintptr_t flags)
 {
 	/* Initialize the minimum number of fields. */
 	tlbctx->t_addrdata[0] = 0;
-	tlbctx->t_addrdata[1] = 0;
+	tlbctx->t_addrdata[1] = flags;
 	tlbctx->t_pmap = NULL;
 	LIST_INIT(>t_freeptq);
 }
 
 static void
-pmap_tlb_shootdown(pmap_t const pmap, vaddr_t const va,
+pmap_tlb_shootdown_internal(pmap_t const pmap, vaddr_t const va,
 pt_entry_t const pte_bits, struct pmap_tlb_context * const tlbctx)
 {
 	KASSERT(pmap != NULL);
@@ -730,6 +730,14 @@ pmap_tlb_shootdown(pmap_t const pmap, va
 }
 
 static void
+pmap_tlb_shootdown(pmap_t const pmap, vaddr_t const va,
+pt_entry_t const pte_bits, struct pmap_tlb_context * const tlbctx)
+{
+	KASSERT((TLB_CTX_FLAGS(tlbctx) & TLB_CTX_F_PV) == 0);
+	pmap_tlb_shootdown_internal(pmap, va, pte_bits, tlbctx);
+}
+
+static void
 pmap_tlb_shootdown_all_user(pmap_t const pmap, pt_entry_t const pte_bits,
 struct pmap_tlb_context * const tlbctx)
 {
@@ -743,29 +751,42 @@ pmap_tlb_shootdown_all_user(pmap_t const
 		TLB_CTX_SET_FLAG(tlbctx, TLB_CTX_F_IMB);
 	}
 
-	KASSERT(tlbctx->t_pmap == NULL || tlbctx->t_pmap == pmap);
-	tlbctx->t_pmap = pmap;
+	if (TLB_CTX_FLAGS(tlbctx) & TLB_CTX_F_PV) {
+		if (tlbctx->t_pmap == NULL || tlbctx->t_pmap == pmap) {
+			if (tlbctx->t_pmap == NULL) {
+pmap_reference(pmap);
+tlbctx->t_pmap = pmap;
+			}
+		} else {
+			TLB_CTX_SET_FLAG(tlbctx, TLB_CTX_F_MULTI);
+		}
+	} else {
+		KASSERT(tlbctx->t_pmap == NULL || tlbctx->t_pmap == pmap);
+		tlbctx->t_pmap = pmap;
+	}
 
 	TLB_CTX_SET_ALLVA(tlbctx);
 }
 
 static void
-pmap_tlb_shootdown_pv(const pv_entry_t pv, pt_entry_t const pte_bits,
-struct pmap_tlb_context * const tlbctx)
+pmap_tlb_shootdown_pv(pmap_t const pmap, vaddr_t const va,
+pt_entry_t const pte_bits, struct pmap_tlb_context * const tlbctx)
 {
-	uintptr_t flags = TLB_CTX_F_PV;
+
+	KASSERT(TLB_CTX_FLAGS(tlbctx) & TLB_CTX_F_PV);
 
 	TLB_COUNT(shootdown_pv);
 
-	if (tlbctx->t_pmap == NULL || tlbctx->t_pmap == pv->pv_pmap) {
+	if (tlbctx->t_pmap == NULL || tlbctx->t_pmap == pmap) {
 		if (tlbctx->t_pmap == NULL) {
-			pmap_reference(pv->pv_pmap);
+			pmap_reference(pmap);
+			tlbctx->t_pmap = pmap;
 		}
-		pmap_tlb_shootdown(pv->pv_pmap, pv->pv_va, pte_bits, tlbctx);
+		pmap_tlb_shootdown_internal(pmap, va, pte_bits, tlbctx);
 	} else {
 		TLB_COUNT(shootdown_pv_multi);
-		flags |= TLB_CTX_F_MULTI;
-		if (pv->pv_pmap == pmap_kernel()) {
+		uintptr_t flags = TLB_CTX_F_MULTI;
+		if (pmap == pmap_kernel()) {
 			KASSERT(pte_bits & PG_ASM);
 			flags |= TLB_CTX_F_ASM;
 		} else {
@@ -780,8 +801,8 @@ pmap_tlb_shootdown_pv(const pv_entry_t p
 			flags |= TLB_CTX_F_IMB;
 		}
 		TLB_CTX_SET_ALLVA(tlbctx);
+		TLB_CTX_SET_FLAG(tlbctx, flags);
 	}
-	TLB_CTX_SET_FLAG(tlbctx, flags);
 }
 
 static void
@@ -1034,6 +1055,7 @@ pmap_tlb_shootnow(const struct pmap_tlb_
 #if defined(MULTIPROCESSOR)
 void
 pmap_tlb_shootdown_ipi(struct cpu_info * const ci,
+
 struct trapframe * const tf __unused)
 {
 	KASSERT(tlb_context != NULL);
@@ -1367,7 +1389,7 @@ pmap_bootstrap(paddr_t ptaddr, u_int max
 	 */
 	memset(pmap_kernel(), 0, 

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

2021-05-23 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 23 19:13:27 UTC 2021

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

Log Message:
Fix a bug in pmap_tlb_shootdown_all_user(), where it was not
stashing away the pointer to the pmap in the TLB context structure
like pmap_tlb_shootdown() was doing.  This would result in the
following failure scenario:

- Page fault handler calls pmap_enter() to map a page.  Mapping
  is the first one for that L2 PT L3 PT, meaning that an L2 PT
  and an L3 PT must be allocated.
- L2 PT allocation succeeds.
- L3 PT allocation fails under memory pressure.
- pmap_enter() goes to drop the reference on the L2 PT, which, because
  it was the first of its mappings, frees the L2 PT.  Becuse PALcode
  may have already tried to service a TLB miss though that L2 PT, we
  must issue an all-user-VA shootdown, and call pmap_tlb_shootdown_all_user()
  to do so.
- pmap_tlb_shootnow() is called and an assert fires because the TLB
  context structure does not point to a pmap.

This did not fail in the pmap_remove() scenario because the TLB context
would have already had at least one call to pmap_tlb_shootdown(), which
was initializing the pmap pointer properly.

PR port-alpha/56200


To generate a diff of this commit:
cvs rdiff -u -r1.276 -r1.277 src/sys/arch/alpha/alpha/pmap.c

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

Modified files:

Index: src/sys/arch/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.276 src/sys/arch/alpha/alpha/pmap.c:1.277
--- src/sys/arch/alpha/alpha/pmap.c:1.276	Sat Apr  3 15:29:02 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Sun May 23 19:13:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.276 2021/04/03 15:29:02 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.277 2021/05/23 19:13:27 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.276 2021/04/03 15:29:02 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.277 2021/05/23 19:13:27 thorpej Exp $");
 
 #include 
 #include 
@@ -743,6 +743,9 @@ pmap_tlb_shootdown_all_user(pmap_t const
 		TLB_CTX_SET_FLAG(tlbctx, TLB_CTX_F_IMB);
 	}
 
+	KASSERT(tlbctx->t_pmap == NULL || tlbctx->t_pmap == pmap);
+	tlbctx->t_pmap = pmap;
+
 	TLB_CTX_SET_ALLVA(tlbctx);
 }
 



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

2021-05-22 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 23 01:34:18 UTC 2021

Added Files:
src/sys/arch/alpha/conf: GENERIC.QEMU

Log Message:
Add a GENERIC.QEMU kernel config.  This just includes QEMU and then
sets some options specifically to make the Qemu experience a little
batter.

Currently, this just sets COPY_SYMTAB=1 (Qemu loads the kernel directly,
and does not load the symbol table).


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/arch/alpha/conf/GENERIC.QEMU

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/alpha/conf/GENERIC.QEMU
diff -u /dev/null src/sys/arch/alpha/conf/GENERIC.QEMU:1.1
--- /dev/null	Sun May 23 01:34:18 2021
+++ src/sys/arch/alpha/conf/GENERIC.QEMU	Sun May 23 01:34:17 2021
@@ -0,0 +1,10 @@
+# $NetBSD: GENERIC.QEMU,v 1.1 2021/05/23 01:34:17 thorpej Exp $
+#
+# Generic Alpha kernel specifically configured for Qemu.
+
+include	"arch/alpha/conf/GENERIC"
+
+# reserve symbol space and copy the symbol table into it.  Needed
+# because Qemu does not load the symbol table when loading the
+# kernel.
+makeoptions	COPY_SYMTAB=1



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

2021-05-22 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 23 01:00:53 UTC 2021

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

Log Message:
Fix an error introduced in rev 1.130 where the previous pcb_onfault
handler was not restored properly in the kcopyerr case.  Also add a
comment explaining why it's save for these routines to be wrappers
around memcpy().

Fixes port-alpha/56197.


To generate a diff of this commit:
cvs rdiff -u -r1.136 -r1.137 src/sys/arch/alpha/alpha/locore.s

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

Modified files:

Index: src/sys/arch/alpha/alpha/locore.s
diff -u src/sys/arch/alpha/alpha/locore.s:1.136 src/sys/arch/alpha/alpha/locore.s:1.137
--- src/sys/arch/alpha/alpha/locore.s:1.136	Sat Sep 19 01:32:16 2020
+++ src/sys/arch/alpha/alpha/locore.s	Sun May 23 01:00:53 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: locore.s,v 1.136 2020/09/19 01:32:16 thorpej Exp $ */
+/* $NetBSD: locore.s,v 1.137 2021/05/23 01:00:53 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000, 2019 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: locore.s,v 1.136 2020/09/19 01:32:16 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.s,v 1.137 2021/05/23 01:00:53 thorpej Exp $");
 
 #include "assym.h"
 
@@ -987,6 +987,11 @@ NESTED(copyoutstr, 4, 16, ra, IM_RA|IM_S
  * kcopy() _must_ save and restore the old fault handler since it is
  * called by uiomove(), which may be in the path of servicing a non-fatal
  * page fault.
+ *
+ * N.B. This implementation is a wrapper around memcpy(), which is
+ * implemented in src/common/lib/libc/arch/alpha/string/bcopy.S.
+ * This is safe ONLY because we know that, as implemented, it is
+ * a LEAF function (and thus does not use any callee-saved registers).
  */
 NESTED(kcopy, 3, 32, ra, IM_RA|IM_S0|IM_S1, 0)
 	LDGP(pv)
@@ -1016,10 +1021,7 @@ NESTED(kcopy, 3, 32, ra, IM_RA|IM_S0|IM_
 
 LEAF(kcopyerr, 0)
 	LDGP(pv)
-	.set noat
-	ldq	at_reg, L_PCB(s1)		/* restore the old handler.  */
-	stq	s0, PCB_ONFAULT(at_reg)
-	.set at
+	stq	s0, PCB_ONFAULT(s1)		/* s1 == pcb (from above)*/
 	ldq	ra, (32-8)(sp)			/* restore ra.		 */
 	ldq	s0, (32-16)(sp)			/* restore s0.		 */
 	ldq	s1, (32-24)(sp)			/* restore s1.		 */



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

2021-05-22 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May 22 15:05:37 UTC 2021

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

Log Message:
Gah, fix cut-and-paste-o.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/arch/alpha/alpha/autoconf.c

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

Modified files:

Index: src/sys/arch/alpha/alpha/autoconf.c
diff -u src/sys/arch/alpha/alpha/autoconf.c:1.56 src/sys/arch/alpha/alpha/autoconf.c:1.57
--- src/sys/arch/alpha/alpha/autoconf.c:1.56	Sat May 22 15:04:33 2021
+++ src/sys/arch/alpha/alpha/autoconf.c	Sat May 22 15:05:36 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: autoconf.c,v 1.56 2021/05/22 15:04:33 thorpej Exp $ */
+/* $NetBSD: autoconf.c,v 1.57 2021/05/22 15:05:36 thorpej Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -42,7 +42,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.56 2021/05/22 15:04:33 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.57 2021/05/22 15:05:36 thorpej Exp $");
 
 #include "pci.h"
 
@@ -116,13 +116,6 @@ qemu_find_rootdev(void)
 		}
 	}
 
-	if (prom_qemu_getenv("rootdev", buf, sizeof(buf))) {
-		snprintf(bootinfo.booted_dev, sizeof(bootinfo.booted_dev),
-		"rootdev=%s", buf);
-		booted_device = device_find_by_xname(buf);
-		return;
-	}
-
 	const size_t devlen = strlen("/dev/");
 	const char *cp = buf;
 	char *ecp = [sizeof(buf) - 1];



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

2021-05-22 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May 22 15:04:34 UTC 2021

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

Log Message:
qemu_find_rootdev(): Zero the buffer that we use to fetch the Qemu
"prom" root device variable; junk past the trailing NUL would cause
the way we parse the string to fail.  Also parse rootdev= and root=
the same way ("be liberal in what you accept" approach).


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/arch/alpha/alpha/autoconf.c

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

Modified files:

Index: src/sys/arch/alpha/alpha/autoconf.c
diff -u src/sys/arch/alpha/alpha/autoconf.c:1.55 src/sys/arch/alpha/alpha/autoconf.c:1.56
--- src/sys/arch/alpha/alpha/autoconf.c:1.55	Sat Oct  3 17:31:46 2020
+++ src/sys/arch/alpha/alpha/autoconf.c	Sat May 22 15:04:33 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: autoconf.c,v 1.55 2020/10/03 17:31:46 thorpej Exp $ */
+/* $NetBSD: autoconf.c,v 1.56 2021/05/22 15:04:33 thorpej Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -42,7 +42,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.55 2020/10/03 17:31:46 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.56 2021/05/22 15:04:33 thorpej Exp $");
 
 #include "pci.h"
 
@@ -100,11 +100,22 @@ cpu_configure(void)
 static void
 qemu_find_rootdev(void)
 {
-	char buf[32];
+	char buf[32] = { 0 };
 
 	/*
 	 * Check for "rootdev=wd0".
 	 */
+	if (! prom_qemu_getenv("rootdev", buf, sizeof(buf))) {
+		/*
+		 * Check "root=/dev/wd0a", "root=/dev/hda1", etc.
+		 */
+		if (! prom_qemu_getenv("root", buf, sizeof(buf))) {
+			printf("WARNING: no rootdev= or root= arguments "
+			   "provided by Qemu\n");
+			return;
+		}
+	}
+
 	if (prom_qemu_getenv("rootdev", buf, sizeof(buf))) {
 		snprintf(bootinfo.booted_dev, sizeof(bootinfo.booted_dev),
 		"rootdev=%s", buf);
@@ -112,35 +123,26 @@ qemu_find_rootdev(void)
 		return;
 	}
 
-	/*
-	 * Check for "root=/dev/wd0a", "root=/dev/hda1", etc.
-	 */
-	if (prom_qemu_getenv("root", buf, sizeof(buf))) {
-		const size_t devlen = strlen("/dev/");
-		const char *cp = buf;
-		char *ecp = [sizeof(buf) - 1];
-
-		snprintf(bootinfo.booted_dev, sizeof(bootinfo.booted_dev),
-		"root=%s", buf);
-
-		/* Find the start of the device xname. */
-		if (strlen(cp) > devlen && strncmp(cp, "/dev/", devlen) == 0) {
-			cp += devlen;
-		}
+	const size_t devlen = strlen("/dev/");
+	const char *cp = buf;
+	char *ecp = [sizeof(buf) - 1];
+
+	/* Find the start of the device xname. */
+	if (strlen(cp) > devlen && strncmp(cp, "/dev/", devlen) == 0) {
+		cp += devlen;
+	}
 
-		/* Now strip any partition letter off the end. */
-		while (ecp != cp) {
-			if (*ecp >= '0' && *ecp <= '9') {
-break;
-			}
-			*ecp-- = '\0';
+	/* Now strip any partition letter off the end. */
+	while (ecp != cp) {
+		if (*ecp >= '0' && *ecp <= '9') {
+			break;
 		}
-
-		booted_device = device_find_by_xname(cp);
-		return;
+		*ecp-- = '\0';
 	}
 
-	printf("WARNING: no rootdev= or root= arguments provided by Qemu\n");
+	snprintf(bootinfo.booted_dev, sizeof(bootinfo.booted_dev),
+	"root=%s", cp);
+	booted_device = device_find_by_xname(cp);
 }
 
 void



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

2021-05-07 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May  8 00:08:43 UTC 2021

Modified Files:
src/sys/arch/alpha/pci: sio_pic.c ttwoga.c ttwoga_dma.c ttwogavar.h

Log Message:
More symbol sanitizing.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/alpha/pci/sio_pic.c
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/alpha/pci/ttwoga.c
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/alpha/pci/ttwoga_dma.c
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/alpha/pci/ttwogavar.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/alpha/pci/sio_pic.c
diff -u src/sys/arch/alpha/pci/sio_pic.c:1.47 src/sys/arch/alpha/pci/sio_pic.c:1.48
--- src/sys/arch/alpha/pci/sio_pic.c:1.47	Fri May  7 16:58:34 2021
+++ src/sys/arch/alpha/pci/sio_pic.c	Sat May  8 00:08:43 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sio_pic.c,v 1.47 2021/05/07 16:58:34 thorpej Exp $ */
+/* $NetBSD: sio_pic.c,v 1.48 2021/05/08 00:08:43 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 2000, 2020 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: sio_pic.c,v 1.47 2021/05/07 16:58:34 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sio_pic.c,v 1.48 2021/05/08 00:08:43 thorpej Exp $");
 
 #include 
 #include 
@@ -102,9 +102,9 @@ __KERNEL_RCSID(0, "$NetBSD: sio_pic.c,v 
  * Private functions and variables.
  */
 
-bus_space_tag_t sio_iot;
-pci_chipset_tag_t sio_pc;
-bus_space_handle_t sio_ioh_icu1, sio_ioh_icu2;
+static bus_space_tag_t sio_iot;
+static pci_chipset_tag_t sio_pc;
+static bus_space_handle_t sio_ioh_icu1, sio_ioh_icu2;
 
 #define	ICU_LEN		16		/* number of ISA IRQs */
 
@@ -262,7 +262,7 @@ cy82c693_write_elcr(int elcr, uint8_t va
  * they should panic.
  */
 
-int (*const sio_elcr_setup_funcs[])(void) = {
+static int (*const sio_elcr_setup_funcs[])(void) = {
 	cy82c693_setup_elcr,
 	i82378_setup_elcr,
 	NULL,

Index: src/sys/arch/alpha/pci/ttwoga.c
diff -u src/sys/arch/alpha/pci/ttwoga.c:1.16 src/sys/arch/alpha/pci/ttwoga.c:1.17
--- src/sys/arch/alpha/pci/ttwoga.c:1.16	Sat Apr 24 23:36:23 2021
+++ src/sys/arch/alpha/pci/ttwoga.c	Sat May  8 00:08:43 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ttwoga.c,v 1.16 2021/04/24 23:36:23 thorpej Exp $ */
+/* $NetBSD: ttwoga.c,v 1.17 2021/05/08 00:08:43 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: ttwoga.c,v 1.16 2021/04/24 23:36:23 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ttwoga.c,v 1.17 2021/05/08 00:08:43 thorpej Exp $");
 
 #include 
 #include 
@@ -62,27 +62,27 @@ __KERNEL_RCSID(0, "$NetBSD: ttwoga.c,v 1
 
 #include "locators.h"
 
-int	ttwogamatch(device_t, cfdata_t, void *);
-void	ttwogaattach(device_t, device_t, void *);
+static int	ttwogamatch(device_t, cfdata_t, void *);
+static void	ttwogaattach(device_t, device_t, void *);
 
 CFATTACH_DECL_NEW(ttwoga, 0,
 ttwogamatch, ttwogaattach, NULL, NULL);
 
-int	ttwogaprint(void *, const char *);
+static int	ttwogaprint(void *, const char *);
 
-int	ttwopcimatch(device_t, cfdata_t, void *);
-void	ttwopciattach(device_t, device_t, void *);
+static int	ttwopcimatch(device_t, cfdata_t, void *);
+static void	ttwopciattach(device_t, device_t, void *);
 
 CFATTACH_DECL_NEW(ttwopci, 0,
 ttwopcimatch, ttwopciattach, NULL, NULL);
 
-int	ttwosableioprint(void *, const char *);
+static int	ttwosableioprint(void *, const char *);
 
 /*
  * There can be only one, but it might have 2 primary PCI busses.
  */
-int ttwogafound;
-struct ttwoga_config ttwoga_configuration[2];
+static int ttwogafound;
+static struct ttwoga_config ttwoga_configuration[2];
 
 /* CBUS address bias for Gamma systems. */
 bus_addr_t ttwoga_gamma_cbus_bias;
@@ -90,7 +90,7 @@ bus_addr_t ttwoga_gamma_cbus_bias;
 #define	GIGABYTE	(1024UL * 1024UL * 1024UL)
 #define	MEGABYTE	(1024UL * 1024UL)
 
-const struct ttwoga_sysmap ttwoga_sysmap[2] = {
+static const struct ttwoga_sysmap ttwoga_sysmap[2] = {
 /*	  Base			System size	Bus size	*/
 	{ T2_PCI0_SIO_BASE,	256UL * MEGABYTE, 8UL * MEGABYTE,
 	  T2_PCI0_SMEM_BASE,	4UL * GIGABYTE,	128UL * MEGABYTE,
@@ -107,7 +107,7 @@ const struct ttwoga_sysmap ttwoga_sysmap
 #undef GIGABYTE
 #undef MEGABYTE
 
-int
+static int
 ttwogamatch(device_t parent, cfdata_t match, void *aux)
 {
 	struct mainbus_attach_args *ma = aux;
@@ -122,7 +122,7 @@ ttwogamatch(device_t parent, cfdata_t ma
 	return (1);
 }
 
-void
+static void
 ttwogaattach(device_t parent, device_t self, void *aux)
 {
 	struct pcibus_attach_args pba;
@@ -149,7 +149,7 @@ ttwogaattach(device_t parent, device_t s
 	}
 }
 
-int
+static int
 ttwogaprint(void *aux, const char *pnp)
 {
 	struct pcibus_attach_args *pba = aux;
@@ -204,7 +204,7 @@ ttwoga_init(int hose, int mallocsafe)
 	return (tcp);
 }
 
-int
+static int
 ttwopcimatch(device_t parent, cfdata_t match, void *aux)
 {
 	struct 

CVS commit: src/sys/arch/alpha

2021-05-07 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri May  7 22:46:11 UTC 2021

Modified Files:
src/sys/arch/alpha/tc: tcasic.c
src/sys/arch/alpha/tlsb: gbus.c mcclock_tlsb.c

Log Message:
Static'ify more symbols.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/alpha/tc/tcasic.c
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/alpha/tlsb/gbus.c
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/alpha/tlsb/mcclock_tlsb.c

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

Modified files:

Index: src/sys/arch/alpha/tc/tcasic.c
diff -u src/sys/arch/alpha/tc/tcasic.c:1.50 src/sys/arch/alpha/tc/tcasic.c:1.51
--- src/sys/arch/alpha/tc/tcasic.c:1.50	Sat Apr 24 23:36:24 2021
+++ src/sys/arch/alpha/tc/tcasic.c	Fri May  7 22:46:10 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tcasic.c,v 1.50 2021/04/24 23:36:24 thorpej Exp $ */
+/* $NetBSD: tcasic.c,v 1.51 2021/05/07 22:46:10 thorpej Exp $ */
 
 /*
  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
@@ -32,7 +32,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: tcasic.c,v 1.50 2021/04/24 23:36:24 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcasic.c,v 1.51 2021/05/07 22:46:10 thorpej Exp $");
 
 #include 
 #include 
@@ -47,20 +47,20 @@ __KERNEL_RCSID(0, "$NetBSD: tcasic.c,v 1
 #include 
 
 /* Definition of the driver for autoconfig. */
-int	tcasicmatch(device_t, cfdata_t, void *);
-void	tcasicattach(device_t, device_t, void *);
+static int	tcasicmatch(device_t, cfdata_t, void *);
+static void	tcasicattach(device_t, device_t, void *);
 
 CFATTACH_DECL_NEW(tcasic, 0,
 tcasicmatch, tcasicattach, NULL, NULL);
 
 extern struct cfdriver tcasic_cd;
 
-int	tcasicprint(void *, const char *);
+static int	tcasicprint(void *, const char *);
 
 /* There can be only one. */
-int	tcasicfound;
+static int	tcasicfound;
 
-int
+static int
 tcasicmatch(device_t parent, cfdata_t cf, void *aux)
 {
 	struct mainbus_attach_args *ma = aux;
@@ -79,7 +79,7 @@ tcasicmatch(device_t parent, cfdata_t cf
 	return (1);
 }
 
-void
+static void
 tcasicattach(device_t parent, device_t self, void *aux)
 {
 	struct tcbus_attach_args tba;
@@ -153,7 +153,7 @@ tcasicattach(device_t parent, device_t s
 	config_found(self, , tcasicprint, CFARG_EOL);
 }
 
-int
+static int
 tcasicprint(void *aux, const char *pnp)
 {
 

Index: src/sys/arch/alpha/tlsb/gbus.c
diff -u src/sys/arch/alpha/tlsb/gbus.c:1.23 src/sys/arch/alpha/tlsb/gbus.c:1.24
--- src/sys/arch/alpha/tlsb/gbus.c:1.23	Sat Apr 24 23:36:24 2021
+++ src/sys/arch/alpha/tlsb/gbus.c	Fri May  7 22:46:10 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: gbus.c,v 1.23 2021/04/24 23:36:24 thorpej Exp $ */
+/* $NetBSD: gbus.c,v 1.24 2021/05/07 22:46:10 thorpej Exp $ */
 
 /*
  * Copyright (c) 1997 by Matthew Jacob
@@ -37,7 +37,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: gbus.c,v 1.23 2021/04/24 23:36:24 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gbus.c,v 1.24 2021/05/07 22:46:10 thorpej Exp $");
 
 #include 
 #include 
@@ -69,7 +69,7 @@ CFATTACH_DECL_NEW(gbus, sizeof(struct gb
 
 static int	gbusprint(void *, const char *);
 
-const struct gbus_attach_args gbus_children[] = {
+static const struct gbus_attach_args gbus_children[] = {
 	{ "zsc",	GBUS_DUART0_OFFSET },
 	{ "zsc",	GBUS_DUART1_OFFSET },
 	{ "mcclock",	GBUS_CLOCK_OFFSET },

Index: src/sys/arch/alpha/tlsb/mcclock_tlsb.c
diff -u src/sys/arch/alpha/tlsb/mcclock_tlsb.c:1.17 src/sys/arch/alpha/tlsb/mcclock_tlsb.c:1.18
--- src/sys/arch/alpha/tlsb/mcclock_tlsb.c:1.17	Fri Jul  1 19:19:51 2011
+++ src/sys/arch/alpha/tlsb/mcclock_tlsb.c	Fri May  7 22:46:11 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: mcclock_tlsb.c,v 1.17 2011/07/01 19:19:51 dyoung Exp $ */
+/* $NetBSD: mcclock_tlsb.c,v 1.18 2021/05/07 22:46:11 thorpej Exp $ */
 
 /*
  * Copyright (c) 1997 by Matthew Jacob
@@ -32,7 +32,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: mcclock_tlsb.c,v 1.17 2011/07/01 19:19:51 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mcclock_tlsb.c,v 1.18 2021/05/07 22:46:11 thorpej Exp $");
 
 #include 
 #include 
@@ -65,8 +65,8 @@ struct mcclock_tlsb_softc {
 	unsigned long regbase;
 };
 
-int	mcclock_tlsb_match(device_t, cfdata_t, void *);
-void	mcclock_tlsb_attach(device_t, device_t, void *);
+static int	mcclock_tlsb_match(device_t, cfdata_t, void *);
+static void	mcclock_tlsb_attach(device_t, device_t, void *);
 
 CFATTACH_DECL_NEW(mcclock_tlsb, sizeof(struct mcclock_tlsb_softc),
 mcclock_tlsb_match, mcclock_tlsb_attach, NULL, NULL);
@@ -75,7 +75,7 @@ static void	mcclock_tlsb_write(struct mc
 static u_int	mcclock_tlsb_read(struct mc146818_softc *, u_int);
 
 
-int
+static int
 mcclock_tlsb_match(device_t parent, cfdata_t cf, void *aux)
 {
 	struct gbus_attach_args *ga = aux;
@@ -85,7 +85,7 @@ mcclock_tlsb_match(device_t parent, cfda
 	return (1);
 }
 
-void
+static void
 mcclock_tlsb_attach(device_t parent, device_t self, void 

CVS commit: src/sys/arch/alpha

2021-05-07 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri May  7 16:58:34 UTC 2021

Modified Files:
src/sys/arch/alpha/common: bus_dma.c shared_intr.c
src/sys/arch/alpha/isa: isa_machdep.c isadma_bounce.c mcclock_isa.c
src/sys/arch/alpha/jensenio: com_jensenio.c jensenio.c jensenio_dma.c
jensenio_intr.c lpt_jensenio.c mcclock_jensenio.c pckbc_jensenio.c
src/sys/arch/alpha/pci: apecs_pci.c cia_pci.c dwlpx_pci.c
irongate_pci.c lca_pci.c mcpcia_pci.c sio.c sio_pic.c tsp_pci.c
ttwoga_pci.c
src/sys/arch/alpha/sableio: com_sableio.c fdc_sableio.c lpt_sableio.c
pckbc_sableio.c sableio.c
src/sys/arch/alpha/tc: ioasic.c mcclock_ioasic.c tc_3000_300.c
tc_3000_500.c tc_conf.h

Log Message:
Liberally sprinkle static around to get more symbols out of the
global namespace.  A small bit of const poisoning in the TC code.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/sys/arch/alpha/common/bus_dma.c
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/alpha/common/shared_intr.c
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/alpha/isa/isa_machdep.c
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/alpha/isa/isadma_bounce.c
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/alpha/isa/mcclock_isa.c
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/alpha/jensenio/com_jensenio.c
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/alpha/jensenio/jensenio.c
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/alpha/jensenio/jensenio_dma.c
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/alpha/jensenio/jensenio_intr.c \
src/sys/arch/alpha/jensenio/lpt_jensenio.c
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/alpha/jensenio/mcclock_jensenio.c
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/alpha/jensenio/pckbc_jensenio.c
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/alpha/pci/apecs_pci.c
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/alpha/pci/cia_pci.c
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/alpha/pci/dwlpx_pci.c
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/alpha/pci/irongate_pci.c \
src/sys/arch/alpha/pci/tsp_pci.c
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/alpha/pci/lca_pci.c
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/alpha/pci/mcpcia_pci.c
cvs rdiff -u -r1.55 -r1.56 src/sys/arch/alpha/pci/sio.c
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/alpha/pci/sio_pic.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/alpha/pci/ttwoga_pci.c
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/alpha/sableio/com_sableio.c
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/alpha/sableio/fdc_sableio.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/alpha/sableio/lpt_sableio.c
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/alpha/sableio/pckbc_sableio.c \
src/sys/arch/alpha/sableio/sableio.c
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/alpha/tc/ioasic.c
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/alpha/tc/mcclock_ioasic.c
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/alpha/tc/tc_3000_300.c
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/alpha/tc/tc_3000_500.c
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/alpha/tc/tc_conf.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/alpha/common/bus_dma.c
diff -u src/sys/arch/alpha/common/bus_dma.c:1.71 src/sys/arch/alpha/common/bus_dma.c:1.72
--- src/sys/arch/alpha/common/bus_dma.c:1.71	Wed Nov 18 02:04:29 2020
+++ src/sys/arch/alpha/common/bus_dma.c	Fri May  7 16:58:33 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: bus_dma.c,v 1.71 2020/11/18 02:04:29 thorpej Exp $ */
+/* $NetBSD: bus_dma.c,v 1.72 2021/05/07 16:58:33 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.71 2020/11/18 02:04:29 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.72 2021/05/07 16:58:33 thorpej Exp $");
 
 #include 
 #include 
@@ -50,9 +50,9 @@ __KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 
 
 #include 
 
-int	_bus_dmamap_load_buffer_direct(bus_dma_tag_t,
-	bus_dmamap_t, void *, bus_size_t, struct vmspace *, int,
-	paddr_t *, int *, int);
+static int	_bus_dmamap_load_buffer_direct(bus_dma_tag_t,
+		bus_dmamap_t, void *, bus_size_t, struct vmspace *, int,
+		paddr_t *, int *, int);
 
 extern paddr_t avail_start, avail_end;	/* from pmap.c */
 
@@ -129,7 +129,7 @@ _bus_dmamap_destroy(bus_dma_tag_t t, bus
  * the starting segment on entrance, and the ending segment on exit.
  * first indicates if this is the first invocation of this function.
  */
-int
+static int
 _bus_dmamap_load_buffer_direct(bus_dma_tag_t t, bus_dmamap_t map,
 void *buf, size_t buflen, struct vmspace *vm, int flags, paddr_t *lastaddrp,
 int *segp, int first)

Index: src/sys/arch/alpha/common/shared_intr.c
diff -u src/sys/arch/alpha/common/shared_intr.c:1.26 src/sys/arch/alpha/common/shared_intr.c:1.27
--- src/sys/arch/alpha/common/shared_intr.c:1.26	Sat Sep 26 02:35:31 2020
+++ src/sys/arch/alpha/common/shared_intr.c	Fri May  7 16:58:33 2021
@@ -1,4 +1,4 @@
-/* 

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

2021-05-05 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed May  5 15:39:39 UTC 2021

Modified Files:
src/sys/arch/alpha/conf: Makefile.alpha

Log Message:
Remove unneeded Makefile dependency for things which have long since
used opt_*.h headers.


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/sys/arch/alpha/conf/Makefile.alpha

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

Modified files:

Index: src/sys/arch/alpha/conf/Makefile.alpha
diff -u src/sys/arch/alpha/conf/Makefile.alpha:1.86 src/sys/arch/alpha/conf/Makefile.alpha:1.87
--- src/sys/arch/alpha/conf/Makefile.alpha:1.86	Wed May  5 01:35:35 2021
+++ src/sys/arch/alpha/conf/Makefile.alpha	Wed May  5 15:39:39 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.alpha,v 1.86 2021/05/05 01:35:35 thorpej Exp $
+#	$NetBSD: Makefile.alpha,v 1.87 2021/05/05 15:39:39 thorpej Exp $
 
 # Makefile for NetBSD
 #
@@ -71,9 +71,6 @@ STRIPFLAGS=	-g -X
 ## (6) port specific target dependencies
 ##
 
-# depend on CPU configuration
-clock.o apecs.o cia.o lca.o ioasic.o icasic.o: Makefile
-
 ##
 ## (7) misc settings
 ##



CVS commit: src/sys/arch/alpha

2021-05-05 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed May  5 15:36:17 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: machdep.c
src/sys/arch/alpha/include: alpha.h

Log Message:
Remove unused dot_conv() function.


To generate a diff of this commit:
cvs rdiff -u -r1.370 -r1.371 src/sys/arch/alpha/alpha/machdep.c
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/alpha/include/alpha.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/alpha/alpha/machdep.c
diff -u src/sys/arch/alpha/alpha/machdep.c:1.370 src/sys/arch/alpha/alpha/machdep.c:1.371
--- src/sys/arch/alpha/alpha/machdep.c:1.370	Wed May  5 15:34:54 2021
+++ src/sys/arch/alpha/alpha/machdep.c	Wed May  5 15:36:17 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.370 2021/05/05 15:34:54 thorpej Exp $ */
+/* $NetBSD: machdep.c,v 1.371 2021/05/05 15:36:17 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2019, 2020 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.370 2021/05/05 15:34:54 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.371 2021/05/05 15:36:17 thorpej Exp $");
 
 #include 
 #include 
@@ -1810,27 +1810,6 @@ mm_md_direct_mapped_phys(paddr_t paddr, 
 	return true;
 }
 
-char *
-dot_conv(unsigned long x)
-{
-	int i;
-	char *xc;
-	static int next;
-	static char space[2][20];
-
-	xc = space[next ^= 1] + sizeof space[0];
-	*--xc = '\0';
-	for (i = 0;; ++i) {
-		if (i && (i & 3) == 0)
-			*--xc = '.';
-		*--xc = hexdigits[x & 0xf];
-		x >>= 4;
-		if (x == 0)
-			break;
-	}
-	return xc;
-}
-
 void
 cpu_getmcontext(struct lwp *l, mcontext_t *mcp, unsigned int *flags)
 {

Index: src/sys/arch/alpha/include/alpha.h
diff -u src/sys/arch/alpha/include/alpha.h:1.44 src/sys/arch/alpha/include/alpha.h:1.45
--- src/sys/arch/alpha/include/alpha.h:1.44	Wed Oct 14 00:59:50 2020
+++ src/sys/arch/alpha/include/alpha.h	Wed May  5 15:36:17 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: alpha.h,v 1.44 2020/10/14 00:59:50 thorpej Exp $ */
+/* $NetBSD: alpha.h,v 1.45 2021/05/05 15:36:17 thorpej Exp $ */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -108,7 +108,6 @@ void	trap(unsigned long, unsigned long, 
 	struct trapframe *);
 void	trap_init(void);
 void	enable_nsio_ide(bus_space_tag_t);
-char *	dot_conv(unsigned long);
 
 extern const pcu_ops_t fpu_ops;
 



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

2021-05-05 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed May  5 15:34:54 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: interrupt.c machdep.c

Log Message:
Disable preemption around the main work of badaddr_read() and delay();
they both use "current CPU" resources.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/sys/arch/alpha/alpha/interrupt.c
cvs rdiff -u -r1.369 -r1.370 src/sys/arch/alpha/alpha/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/alpha/alpha/interrupt.c
diff -u src/sys/arch/alpha/alpha/interrupt.c:1.96 src/sys/arch/alpha/alpha/interrupt.c:1.97
--- src/sys/arch/alpha/alpha/interrupt.c:1.96	Wed May  5 14:58:57 2021
+++ src/sys/arch/alpha/alpha/interrupt.c	Wed May  5 15:34:54 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: interrupt.c,v 1.96 2021/05/05 14:58:57 thorpej Exp $ */
+/* $NetBSD: interrupt.c,v 1.97 2021/05/05 15:34:54 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: interrupt.c,v 1.96 2021/05/05 14:58:57 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: interrupt.c,v 1.97 2021/05/05 15:34:54 thorpej Exp $");
 
 #include 
 #include 
@@ -383,6 +383,9 @@ badaddr(void *addr, size_t size)
 int
 badaddr_read(void *addr, size_t size, void *rptr)
 {
+	lwp_t * const l = curlwp;
+	KPREEMPT_DISABLE(l);
+
 	struct mchkinfo *mcp = ()->ci_mcinfo;
 	long rcpt;
 	int rv;
@@ -450,6 +453,9 @@ badaddr_read(void *addr, size_t size, vo
 			break;
 		}
 	}
+
+	KPREEMPT_ENABLE(l);
+
 	/* Return non-zero (i.e. true) if it's a bad address. */
 	return (rv);
 }

Index: src/sys/arch/alpha/alpha/machdep.c
diff -u src/sys/arch/alpha/alpha/machdep.c:1.369 src/sys/arch/alpha/alpha/machdep.c:1.370
--- src/sys/arch/alpha/alpha/machdep.c:1.369	Thu Oct 15 01:00:01 2020
+++ src/sys/arch/alpha/alpha/machdep.c	Wed May  5 15:34:54 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.369 2020/10/15 01:00:01 thorpej Exp $ */
+/* $NetBSD: machdep.c,v 1.370 2021/05/05 15:34:54 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2019, 2020 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.369 2020/10/15 01:00:01 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.370 2021/05/05 15:34:54 thorpej Exp $");
 
 #include 
 #include 
@@ -1706,6 +1706,9 @@ delay(unsigned long n)
 		return;
 	}
 
+	lwp_t * const l = curlwp;
+	KPREEMPT_DISABLE(l);
+
 	pcc0 = alpha_rpcc() & 0xUL;
 	cycles = 0;
 	usec = 0;
@@ -1734,6 +1737,8 @@ delay(unsigned long n)
 		}
 		pcc0 = pcc1;
 	}
+
+	KPREEMPT_ENABLE(l);
 }
 
 #ifdef EXEC_ECOFF



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

2021-05-05 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed May  5 14:58:57 UTC 2021

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

Log Message:
Make scb_strat() static.


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/sys/arch/alpha/alpha/interrupt.c

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

Modified files:

Index: src/sys/arch/alpha/alpha/interrupt.c
diff -u src/sys/arch/alpha/alpha/interrupt.c:1.95 src/sys/arch/alpha/alpha/interrupt.c:1.96
--- src/sys/arch/alpha/alpha/interrupt.c:1.95	Tue Apr 20 01:29:40 2021
+++ src/sys/arch/alpha/alpha/interrupt.c	Wed May  5 14:58:57 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: interrupt.c,v 1.95 2021/04/20 01:29:40 thorpej Exp $ */
+/* $NetBSD: interrupt.c,v 1.96 2021/05/05 14:58:57 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: interrupt.c,v 1.95 2021/04/20 01:29:40 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: interrupt.c,v 1.96 2021/05/05 14:58:57 thorpej Exp $");
 
 #include 
 #include 
@@ -92,7 +92,7 @@ __KERNEL_RCSID(0, "$NetBSD: interrupt.c,
 struct scbvec scb_iovectab[SCB_VECTOIDX(SCB_SIZE - SCB_IOVECBASE)]
 			__read_mostly;
 
-void	scb_stray(void *, u_long);
+static void	scb_stray(void *, u_long);
 
 void
 scb_init(void)
@@ -105,7 +105,7 @@ scb_init(void)
 	}
 }
 
-void
+static void
 scb_stray(void *arg, u_long vec)
 {
 



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

2021-05-04 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed May  5 03:54:16 UTC 2021

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

Log Message:
Decorate cpu_info_list with __read_mostly; it's never modified once
all the CPUs are attached.


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/sys/arch/alpha/alpha/cpu.c

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

Modified files:

Index: src/sys/arch/alpha/alpha/cpu.c
diff -u src/sys/arch/alpha/alpha/cpu.c:1.103 src/sys/arch/alpha/alpha/cpu.c:1.104
--- src/sys/arch/alpha/alpha/cpu.c:1.103	Thu Oct 15 01:00:01 2020
+++ src/sys/arch/alpha/alpha/cpu.c	Wed May  5 03:54:16 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.103 2020/10/15 01:00:01 thorpej Exp $ */
+/* $NetBSD: cpu.c,v 1.104 2021/05/05 03:54:16 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2020 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.103 2020/10/15 01:00:01 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.104 2021/05/05 03:54:16 thorpej Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -84,7 +84,7 @@ __KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.10
 struct cpu_info cpu_info_primary __cacheline_aligned = {
 	.ci_curlwp = 
 };
-struct cpu_info *cpu_info_list = _info_primary;
+struct cpu_info *cpu_info_list __read_mostly = _info_primary;
 
 #if defined(MULTIPROCESSOR)
 /*



  1   2   3   4   >