Module Name:    src
Committed By:   jmcneill
Date:           Mon Jul 16 10:56:42 UTC 2018

Modified Files:
        src/sys/dev/tprof: tprof_armv7.c tprof_armv8.c

Log Message:
RW fields in performance monitor registers are reset to architecturally
UNKNOWN values. Initialize the PMU to a known state - all interrupts and
counters disabled, performance monitor disabled, and user access disabled.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/tprof/tprof_armv7.c \
    src/sys/dev/tprof/tprof_armv8.c

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

Modified files:

Index: src/sys/dev/tprof/tprof_armv7.c
diff -u src/sys/dev/tprof/tprof_armv7.c:1.1 src/sys/dev/tprof/tprof_armv7.c:1.2
--- src/sys/dev/tprof/tprof_armv7.c:1.1	Sun Jul 15 23:47:29 2018
+++ src/sys/dev/tprof/tprof_armv7.c	Mon Jul 16 10:56:42 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: tprof_armv7.c,v 1.1 2018/07/15 23:47:29 jmcneill Exp $ */
+/* $NetBSD: tprof_armv7.c,v 1.2 2018/07/16 10:56:42 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcne...@invisible.ca>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tprof_armv7.c,v 1.1 2018/07/15 23:47:29 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_armv7.c,v 1.2 2018/07/16 10:56:42 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -227,6 +227,18 @@ armv7_pmu_intr(void *priv)
 int
 armv7_pmu_init(void)
 {
+	/* Disable user mode access to performance monitors */
+	armreg_pmuserenr_write(0);
+
+	/* Disable interrupts */
+	armreg_pmintenclr_write(~0U);
+
+	/* Disable counters */
+	armreg_pmcntenclr_write(~0U);
+
+	/* Disable performance monitor */
+	armreg_pmcr_write(0);
+
 	return tprof_backend_register("tprof_armv7", &tprof_armv7_pmu_ops,
 	    TPROF_BACKEND_VERSION);
 }
Index: src/sys/dev/tprof/tprof_armv8.c
diff -u src/sys/dev/tprof/tprof_armv8.c:1.1 src/sys/dev/tprof/tprof_armv8.c:1.2
--- src/sys/dev/tprof/tprof_armv8.c:1.1	Sun Jul 15 16:05:24 2018
+++ src/sys/dev/tprof/tprof_armv8.c	Mon Jul 16 10:56:42 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: tprof_armv8.c,v 1.1 2018/07/15 16:05:24 jmcneill Exp $ */
+/* $NetBSD: tprof_armv8.c,v 1.2 2018/07/16 10:56:42 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcne...@invisible.ca>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.1 2018/07/15 16:05:24 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.2 2018/07/16 10:56:42 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -220,6 +220,18 @@ armv8_pmu_intr(void *priv)
 int
 armv8_pmu_init(void)
 {
+        /* Disable EL0 access to performance monitors */
+	reg_pmuserenr_el0_write(0);
+
+	/* Disable interrupts */
+	reg_pmintenclr_el1_write(~0U);
+
+	/* Disable counters */
+	reg_pmcntenclr_el0_write(~0U);
+
+	/* Disable performance monitor */
+	reg_pmcr_el0_write(0);
+
 	return tprof_backend_register("tprof_armv8", &tprof_armv8_pmu_ops,
 	    TPROF_BACKEND_VERSION);
 }

Reply via email to