Module Name:    src
Committed By:   martin
Date:           Wed Feb  1 18:55:11 UTC 2023

Modified Files:
        src/sys/arch/next68k/dev [netbsd-10]: esp.c
        src/sys/arch/next68k/include [netbsd-10]: bus_space.h cpu.h
        src/sys/arch/next68k/next68k [netbsd-10]: clock.c machdep.c

Log Message:
Pull up following revision(s) (requested by tsutsui in ticket #63):

        sys/arch/next68k/next68k/machdep.c: revision 1.117
        sys/arch/next68k/dev/esp.c: revision 1.65
        sys/arch/next68k/include/cpu.h: revision 1.51
        sys/arch/next68k/include/bus_space.h: revision 1.20
        sys/arch/next68k/next68k/clock.c: revision 1.13

next68k: Fix delay_divisor value for proper delay(9) on 68040.

next68k: Specify proper constraints for bus_space_read region and multi ops.

These functions write the read data into memory at a specified pointer,
but without the "memory" constraint gcc could optimize out these ops
if the memory is allocated on local stack.

With this fix nextkbd(4) works again.
Should be pulled up to netbsd-10 and netbsd-9.

next68k: Fix silent stall of next68k esp(4) SCSI.

next68k esp(4) driver requires nextdma(4) interrupts at ipl 6
during ncr53c9x_intr() for esp(4) at ipl 3.  It worked on netbsd-5
and prior, but on netbsd-5 splbio() was changed from ipl 3 to 6
for SMP support and on netbsd-6 ncr53c9x driver was changed to
use mutex(9) instead of simple_lock(9), so nextdma interrupts
were no longer raised during ncr53c9x interrupt handler.

For now, just call mutex_exit(9) and mutex_enter(9) during
waiting nextdma(4) interrupts in MD esp_dma_intr() handler.

This could be wrong and the interrupt handler for nextdma should
be reorganized, but it just works.

Should be pulled up to netbsd-10 and netbsd-9.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.64.44.1 src/sys/arch/next68k/dev/esp.c
cvs rdiff -u -r1.19 -r1.19.18.1 src/sys/arch/next68k/include/bus_space.h
cvs rdiff -u -r1.50 -r1.50.26.1 src/sys/arch/next68k/include/cpu.h
cvs rdiff -u -r1.12 -r1.12.90.1 src/sys/arch/next68k/next68k/clock.c
cvs rdiff -u -r1.116 -r1.116.4.1 src/sys/arch/next68k/next68k/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/next68k/dev/esp.c
diff -u src/sys/arch/next68k/dev/esp.c:1.64 src/sys/arch/next68k/dev/esp.c:1.64.44.1
--- src/sys/arch/next68k/dev/esp.c:1.64	Fri Mar 31 08:38:13 2017
+++ src/sys/arch/next68k/dev/esp.c	Wed Feb  1 18:55:11 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: esp.c,v 1.64 2017/03/31 08:38:13 msaitoh Exp $	*/
+/*	$NetBSD: esp.c,v 1.64.44.1 2023/02/01 18:55:11 martin Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: esp.c,v 1.64 2017/03/31 08:38:13 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: esp.c,v 1.64.44.1 2023/02/01 18:55:11 martin Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -509,6 +509,7 @@ esp_dma_intr(struct ncr53c9x_softc *sc)
 			}
 #endif
 
+			mutex_exit(&sc->sc_lock);	/* for nextdma intr */
 			while (!nextdma_finished(nsc)) {
 			/* esp_dma_isactive(sc)) { */
 				NDTRACEIF (ndtrace_addc('w'));
@@ -602,7 +603,7 @@ esp_dma_intr(struct ncr53c9x_softc *sc)
 
 			}
 		out:
-			;
+			mutex_enter(&sc->sc_lock);	/* for nextdma intr */
 
 #ifdef ESP_DEBUG
 /* 			esp_dma_nest--; */

Index: src/sys/arch/next68k/include/bus_space.h
diff -u src/sys/arch/next68k/include/bus_space.h:1.19 src/sys/arch/next68k/include/bus_space.h:1.19.18.1
--- src/sys/arch/next68k/include/bus_space.h:1.19	Sat Jan 23 19:38:08 2021
+++ src/sys/arch/next68k/include/bus_space.h	Wed Feb  1 18:55:11 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus_space.h,v 1.19 2021/01/23 19:38:08 christos Exp $	*/
+/*	$NetBSD: bus_space.h,v 1.19.18.1 2023/02/01 18:55:11 martin Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -167,7 +167,7 @@ typedef u_long	bus_space_handle_t;
 		jne	1b"					:	\
 								:	\
 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
-		    "a0","a1","d0");					\
+		    "a0","a1","d0","memory");				\
 } while (0);
 
 #define	bus_space_read_multi_2(t, h, o, a, c) do {			\
@@ -181,7 +181,7 @@ typedef u_long	bus_space_handle_t;
 		jne	1b"					:	\
 								:	\
 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
-		    "a0","a1","d0");					\
+		    "a0","a1","d0","memory");				\
 } while (0);
 
 #define	bus_space_read_multi_4(t, h, o, a, c) do {			\
@@ -195,7 +195,7 @@ typedef u_long	bus_space_handle_t;
 		jne	1b"					:	\
 								:	\
 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
-		    "a0","a1","d0");					\
+		    "a0","a1","d0","memory");				\
 } while (0);
 
 /*
@@ -219,7 +219,7 @@ typedef u_long	bus_space_handle_t;
 		jne	1b"					:	\
 								:	\
 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
-		    "a0","a1","d0");					\
+		    "a0","a1","d0","memory");				\
 } while (0);
 
 #define	bus_space_read_region_2(t, h, o, a, c) do {			\
@@ -233,7 +233,7 @@ typedef u_long	bus_space_handle_t;
 		jne	1b"					:	\
 								:	\
 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
-		    "a0","a1","d0");					\
+		    "a0","a1","d0","memory");					\
 } while (0);
 
 #define	bus_space_read_region_4(t, h, o, a, c) do {			\
@@ -247,7 +247,7 @@ typedef u_long	bus_space_handle_t;
 		jne	1b"					:	\
 								:	\
 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
-		    "a0","a1","d0");					\
+		    "a0","a1","d0","memory");					\
 } while (0);
 
 /*

Index: src/sys/arch/next68k/include/cpu.h
diff -u src/sys/arch/next68k/include/cpu.h:1.50 src/sys/arch/next68k/include/cpu.h:1.50.26.1
--- src/sys/arch/next68k/include/cpu.h:1.50	Sat Nov 23 19:40:36 2019
+++ src/sys/arch/next68k/include/cpu.h	Wed Feb  1 18:55:11 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.50 2019/11/23 19:40:36 ad Exp $	*/
+/*	$NetBSD: cpu.h,v 1.50.26.1 2023/02/01 18:55:11 martin Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -120,9 +120,6 @@ void	loadustp(int);
 void	doboot(void) __attribute__((__noreturn__));
 int	nmihand(void *);
 
-/* clock.c functions */
-void	next68k_calibrate_delay(void);
-
 #endif /* _KERNEL */
 
 #define NEXT_RAMBASE  (0x4000000) /* really depends on slot, but... */

Index: src/sys/arch/next68k/next68k/clock.c
diff -u src/sys/arch/next68k/next68k/clock.c:1.12 src/sys/arch/next68k/next68k/clock.c:1.12.90.1
--- src/sys/arch/next68k/next68k/clock.c:1.12	Sat Apr 24 19:58:13 2010
+++ src/sys/arch/next68k/next68k/clock.c	Wed Feb  1 18:55:11 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.12 2010/04/24 19:58:13 dbj Exp $	*/
+/*	$NetBSD: clock.c,v 1.12.90.1 2023/02/01 18:55:11 martin Exp $	*/
 /*
  * Copyright (c) 1998 Darrin B. Jewell
  * All rights reserved.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.12 2010/04/24 19:58:13 dbj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.12.90.1 2023/02/01 18:55:11 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -48,38 +48,6 @@ __KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.
  * -- jew...@mit.edu
  */
 
-/*
- * Note that the value of delay_divisor is roughly
- * 2048 / cpuspeed (where cpuspeed is in MHz) on 68020
- * and 68030 systems.  See clock.c for the delay
- * calibration algorithm.
- */
-int	cpuspeed;		  /* relative cpu speed; XXX skewed on 68040 */
-int	delay_divisor = 2048/25;  /* delay constant */
-
-/*
- * Calibrate the delay constant.
- */
-void
-next68k_calibrate_delay(void)
-{
-	extern int delay_divisor;
-
-	/* @@@ write this once we know how to read
-	 * a real time clock
-	 */
-
-	/*
-	 * Sanity check the delay_divisor value.  If we totally lost,
-	 * assume a 25MHz CPU;
-	 */
-	if (delay_divisor == 0)
-		delay_divisor = 2048 / 25;
-
-	/* Calculate CPU speed. */
-	cpuspeed = 2048 / delay_divisor;
-}
-
 int clock_intr(void *);
 
 int

Index: src/sys/arch/next68k/next68k/machdep.c
diff -u src/sys/arch/next68k/next68k/machdep.c:1.116 src/sys/arch/next68k/next68k/machdep.c:1.116.4.1
--- src/sys/arch/next68k/next68k/machdep.c:1.116	Sat Oct  9 20:00:42 2021
+++ src/sys/arch/next68k/next68k/machdep.c	Wed Feb  1 18:55:11 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.116 2021/10/09 20:00:42 tsutsui Exp $	*/
+/*	$NetBSD: machdep.c,v 1.116.4.1 2023/02/01 18:55:11 martin Exp $	*/
 
 /*
  * Copyright (c) 1998 Darrin B. Jewell
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.116 2021/10/09 20:00:42 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.116.4.1 2023/02/01 18:55:11 martin Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -168,6 +168,17 @@ phys_seg_list_t phys_seg_list[VM_PHYSSEG
 phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
 int	mem_cluster_cnt;
 
+/*
+ * On the 68020/68030, the value of delay_divisor is roughly
+ * 2048 / cpuspeed (where cpuspeed is in MHz).
+ *
+ * On the 68040/68060(?), the value of delay_divisor is roughly
+ * 759 / cpuspeed (where cpuspeed is in MHz).
+ * XXX -- is the above formula correct?
+ */
+int	cpuspeed = 33;		  /* relative cpu speed; XXX skewed on 68040 */
+int	delay_divisor = 759 / 33;  /* delay constant; assume fastest 33 MHz */
+
 /****************************************************************/
 
 /*
@@ -208,9 +219,6 @@ next68k_init(void)
 		}
 	}
 
-	/* Calibrate the delay loop. */
-	next68k_calibrate_delay();
-
 	/*
 	 * Initialize error message buffer (at end of core).
 	 */
@@ -256,8 +264,6 @@ consinit(void)
 		}
 
 		init = 1;
-	} else {
-		next68k_calibrate_delay();
 	}
 }
 
@@ -316,6 +322,7 @@ void
 identifycpu(void)
 {
 	const char *mc, *mmu_str, *fpu_str, *cache_str;
+	extern int turbo;
 
 	/*
 	 * ...and the CPU type.
@@ -323,9 +330,13 @@ identifycpu(void)
 	switch (cputype) {
 	case CPU_68040:
 		mc = "40";
+		cpuspeed = turbo ? 33 : 25;
+		delay_divisor = 759 / cpuspeed;
 		break;
 	case CPU_68030:
 		mc = "30";
+		cpuspeed = 25;
+		delay_divisor = 2048 / cpuspeed;
 		break;
 	case CPU_68020:
 		mc = "20";

Reply via email to