Module Name:    src
Committed By:   jmcneill
Date:           Fri Nov 12 21:59:05 UTC 2021

Modified Files:
        src/sys/arch/arm/cortex: gtmr.c gtmr_var.h
        src/sys/arch/arm/fdt: gtmr_fdt.c

Log Message:
gtmr: Add support for arm,cpu-registers-not-fw-configured property.

On armv7, arm,cpu-registers-not-fw-configured means that firmware hasn't
bothered to configure any generic timer registers and we need to
initialize cntfrq ourselves.


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/arm/cortex/gtmr.c
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/arm/cortex/gtmr_var.h
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/arm/fdt/gtmr_fdt.c

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

Modified files:

Index: src/sys/arch/arm/cortex/gtmr.c
diff -u src/sys/arch/arm/cortex/gtmr.c:1.46 src/sys/arch/arm/cortex/gtmr.c:1.47
--- src/sys/arch/arm/cortex/gtmr.c:1.46	Sun Oct 31 16:23:47 2021
+++ src/sys/arch/arm/cortex/gtmr.c	Fri Nov 12 21:59:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: gtmr.c,v 1.46 2021/10/31 16:23:47 skrll Exp $	*/
+/*	$NetBSD: gtmr.c,v 1.47 2021/11/12 21:59:04 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gtmr.c,v 1.46 2021/10/31 16:23:47 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gtmr.c,v 1.47 2021/11/12 21:59:04 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -127,6 +127,13 @@ gtmr_attach(device_t parent, device_t se
 	aprint_normal(": Generic Timer (%s, %s)\n", freqbuf,
 	    sc->sc_physical ? "physical" : "virtual");
 
+#if defined(__arm__)
+	if (prop_dictionary_get_bool(dict, "arm,cpu-registers-not-fw-configured", &flag) && flag) {
+		sc->sc_flags |= GTMR_FLAG_CPU_REGISTERS_NOT_FW_CONFIGURED;
+		aprint_debug_dev(self, "CPU registers not initialized by firmware\n");
+	}
+#endif
+
 	if (prop_dictionary_get_bool(dict, "sun50i-a64-unstable-timer", &flag) && flag) {
 		sc->sc_flags |= GTMR_FLAG_SUN50I_A64_UNSTABLE_TIMER;
 		aprint_debug_dev(self, "enabling Allwinner A64 timer workaround\n");
@@ -250,6 +257,10 @@ gtmr_init_cpu_clock(struct cpu_info *ci)
 	/* XXX hmm... called from cpu_hatch which hasn't lowered ipl yet */
 	int s = splsched();
 
+	if ((sc->sc_flags & GTMR_FLAG_CPU_REGISTERS_NOT_FW_CONFIGURED) != 0) {
+		armreg_cnt_frq_write(sc->sc_freq);
+	}
+
 	/*
 	 * Allow the virtual and physical counters to be accessed from
 	 * usermode. (PL0)

Index: src/sys/arch/arm/cortex/gtmr_var.h
diff -u src/sys/arch/arm/cortex/gtmr_var.h:1.14 src/sys/arch/arm/cortex/gtmr_var.h:1.15
--- src/sys/arch/arm/cortex/gtmr_var.h:1.14	Thu Mar  5 15:18:54 2020
+++ src/sys/arch/arm/cortex/gtmr_var.h	Fri Nov 12 21:59:04 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: gtmr_var.h,v 1.14 2020/03/05 15:18:54 riastradh Exp $ */
+/* $NetBSD: gtmr_var.h,v 1.15 2021/11/12 21:59:04 jmcneill Exp $ */
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -38,7 +38,8 @@ struct gtmr_softc {
 	struct evcnt sc_ev_missing_ticks;
 	uint32_t sc_freq;
 	uint32_t sc_flags;
-#define	GTMR_FLAG_SUN50I_A64_UNSTABLE_TIMER	__BIT(0)
+#define	GTMR_FLAG_SUN50I_A64_UNSTABLE_TIMER		__BIT(0)
+#define	GTMR_FLAG_CPU_REGISTERS_NOT_FW_CONFIGURED	__BIT(1)
 	u_long sc_autoinc;
 	bool sc_physical;
 	void *sc_global_ih;

Index: src/sys/arch/arm/fdt/gtmr_fdt.c
diff -u src/sys/arch/arm/fdt/gtmr_fdt.c:1.11 src/sys/arch/arm/fdt/gtmr_fdt.c:1.12
--- src/sys/arch/arm/fdt/gtmr_fdt.c:1.11	Sat Aug  7 16:18:43 2021
+++ src/sys/arch/arm/fdt/gtmr_fdt.c	Fri Nov 12 21:59:05 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: gtmr_fdt.c,v 1.11 2021/08/07 16:18:43 thorpej Exp $ */
+/* $NetBSD: gtmr_fdt.c,v 1.12 2021/11/12 21:59:05 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill <jmcne...@invisible.ca>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gtmr_fdt.c,v 1.11 2021/08/07 16:18:43 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gtmr_fdt.c,v 1.12 2021/11/12 21:59:05 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -44,6 +44,10 @@ __KERNEL_RCSID(0, "$NetBSD: gtmr_fdt.c,v
 #include <dev/fdt/fdtvar.h>
 #include <arm/fdt/arm_fdtvar.h>
 
+#if defined(__arm__)
+#include <arm/armreg.h>
+#endif
+
 static int	gtmr_fdt_match(device_t, cfdata_t, void *);
 static void	gtmr_fdt_attach(device_t, device_t, void *);
 
@@ -95,6 +99,23 @@ gtmr_fdt_attach(device_t parent, device_
 	}
 	aprint_normal_dev(self, "interrupting on %s\n", intrstr);
 
+#if defined(__arm__)
+	/*
+	 * If arm,cpu-registers-not-fw-configured is present, we need
+	 * to initialize cntfrq from the clock-frequency property. Only
+	 * applicable on Armv7.
+	 */
+	if (of_hasprop(phandle, "arm,cpu-registers-not-fw-configured")) {
+		uint32_t freq;
+
+		if (of_getprop_uint32(phandle, "clock-frequency", &freq) == 0) {
+			armreg_cnt_frq_write(freq);
+			prop_dictionary_set_bool(device_properties(self),
+			    "arm,cpu-registers-not-fw-configured", true);
+		}
+	}
+#endif
+
 	config_found(self, &mpcaa, NULL, CFARGS_NONE);
 
 	arm_fdt_cpu_hatch_register(self, gtmr_fdt_cpu_hatch);

Reply via email to