Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Apr 2018 01:56:46 +0000 (UTC)
From:      Michal Meloun <mmel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r331968 - in stable/11/sys/arm: arm include
Message-ID:  <201804040156.w341uk90019363@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mmel
Date: Wed Apr  4 01:56:46 2018
New Revision: 331968
URL: https://svnweb.freebsd.org/changeset/base/331968

Log:
  MFC r319896,r320054:
  
    r319896:
      Implement tunable CPU quirks.  These quirks are intended for optimizing CPU
      performance, not for applying errata workarounds. Nobody can expect that
      CPU with unfixed errata is stable enough to execute the kernel until quirks
      are applied.
    r320054:
      Manually load tunable CPU quirks.  These are needed too early, far before
      SYSINIT is processed.

Modified:
  stable/11/sys/arm/arm/cpuinfo.c
  stable/11/sys/arm/arm/mp_machdep.c
  stable/11/sys/arm/arm/pmap-v6.c
  stable/11/sys/arm/include/cpuinfo.h
  stable/11/sys/arm/include/pmap-v6.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/arm/arm/cpuinfo.c
==============================================================================
--- stable/11/sys/arm/arm/cpuinfo.c	Wed Apr  4 01:13:28 2018	(r331967)
+++ stable/11/sys/arm/arm/cpuinfo.c	Wed Apr  4 01:56:46 2018	(r331968)
@@ -30,12 +30,18 @@ __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
 #include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
 
 #include <machine/cpu.h>
 #include <machine/cpuinfo.h>
 #include <machine/elf.h>
 #include <machine/md_var.h>
 
+#if __ARM_ARCH >= 6
+void reinit_mmu(uint32_t ttb, uint32_t aux_clr, uint32_t aux_set);
+#endif
+
 struct cpuinfo cpuinfo =
 {
 	/* Use safe defaults for start */
@@ -45,6 +51,30 @@ struct cpuinfo cpuinfo =
 	.icache_line_mask = 31,
 };
 
+static SYSCTL_NODE(_hw, OID_AUTO, cpu, CTLFLAG_RD, 0,
+    "CPU");
+static SYSCTL_NODE(_hw_cpu, OID_AUTO, quirks, CTLFLAG_RD, 0,
+    "CPU quirks");
+
+/*
+ * Tunable CPU quirks.
+ * Be careful, ACTRL cannot be changed if CPU is started in secure
+ * mode(world) and write to ACTRL can cause exception!
+ * These quirks are intended for optimizing CPU performance, not for
+ * applying errata workarounds. Nobody can expect that CPU with unfixed
+ * errata is stable enough to execute the kernel until quirks are applied.
+ */
+static uint32_t cpu_quirks_actlr_mask;
+SYSCTL_INT(_hw_cpu_quirks, OID_AUTO, actlr_mask,
+    CTLFLAG_RDTUN | CTLFLAG_NOFETCH, &cpu_quirks_actlr_mask, 0,
+    "Bits to be masked in ACTLR");
+
+static uint32_t cpu_quirks_actlr_set;
+SYSCTL_INT(_hw_cpu_quirks, OID_AUTO, actlr_set,
+    CTLFLAG_RDTUN | CTLFLAG_NOFETCH, &cpu_quirks_actlr_set, 0,
+    "Bits to be set in ACTLR");
+
+
 /* Read and parse CPU id scheme */
 void
 cpuinfo_init(void)
@@ -53,6 +83,14 @@ cpuinfo_init(void)
 	uint32_t tmp;
 #endif
 
+	/*
+	 * Prematurely fetch CPU quirks. Standard fetch for tunable
+	 * sysctls is handled using SYSINIT, thus too late for boot CPU.
+	 * Keep names in sync with sysctls.
+	 */
+	TUNABLE_INT_FETCH("hw.cpu.quirks.actlr_mask", &cpu_quirks_actlr_mask);
+	TUNABLE_INT_FETCH("hw.cpu.quirks.actlr_set", &cpu_quirks_actlr_set);
+
 	cpuinfo.midr = cp15_midr_get();
 	/* Test old version id schemes first */
 	if ((cpuinfo.midr & CPU_ID_IMPLEMENTOR_MASK) == CPU_ID_ARM_LTD) {
@@ -199,15 +237,17 @@ cpuinfo_init(void)
 #endif
 }
 
+#if __ARM_ARCH >= 6
 /*
  * Get bits that must be set or cleared in ACLR register.
  * Note: Bits in ACLR register are IMPLEMENTATION DEFINED.
  * Its expected that SCU is in operational state before this
  * function is called.
  */
-void
+static void
 cpuinfo_get_actlr_modifier(uint32_t *actlr_mask, uint32_t *actlr_set)
 {
+
 	*actlr_mask = 0;
 	*actlr_set = 0;
 
@@ -282,3 +322,18 @@ cpuinfo_get_actlr_modifier(uint32_t *actlr_mask, uint3
 		return;
 	}
 }
+
+/* Reinitialize MMU to final kernel mapping and apply all CPU quirks. */
+void
+cpuinfo_reinit_mmu(uint32_t ttb)
+{
+	uint32_t actlr_mask;
+	uint32_t actlr_set;
+
+	cpuinfo_get_actlr_modifier(&actlr_mask, &actlr_set);
+	actlr_mask |= cpu_quirks_actlr_mask;
+	actlr_set |= cpu_quirks_actlr_set;
+	reinit_mmu(ttb, actlr_mask, actlr_set);
+}
+
+#endif /* __ARM_ARCH >= 6 */

Modified: stable/11/sys/arm/arm/mp_machdep.c
==============================================================================
--- stable/11/sys/arm/arm/mp_machdep.c	Wed Apr  4 01:13:28 2018	(r331967)
+++ stable/11/sys/arm/arm/mp_machdep.c	Wed Apr  4 01:56:46 2018	(r331968)
@@ -155,11 +155,9 @@ init_secondary(int cpu)
 #ifndef INTRNG
 	int start = 0, end = 0;
 #endif
-	uint32_t actlr_mask, actlr_set;
 
 	pmap_set_tex();
-	cpuinfo_get_actlr_modifier(&actlr_mask, &actlr_set);
-	reinit_mmu(pmap_kern_ttb, actlr_mask, actlr_set);
+	cpuinfo_reinit_mmu(pmap_kern_ttb);
 	cpu_setup();
 
 	/* Provide stack pointers for other processor modes. */

Modified: stable/11/sys/arm/arm/pmap-v6.c
==============================================================================
--- stable/11/sys/arm/arm/pmap-v6.c	Wed Apr  4 01:13:28 2018	(r331967)
+++ stable/11/sys/arm/arm/pmap-v6.c	Wed Apr  4 01:56:46 2018	(r331968)
@@ -762,7 +762,7 @@ pmap_bootstrap_prepare(vm_paddr_t last)
 	pt1_entry_t *pte1p;
 	pt2_entry_t *pte2p;
 	u_int i;
-	uint32_t actlr_mask, actlr_set, l1_attr;
+	uint32_t l1_attr;
 
 	/*
 	 * Now, we are going to make real kernel mapping. Note that we are
@@ -879,8 +879,7 @@ pmap_bootstrap_prepare(vm_paddr_t last)
 
 	/* Finally, switch from 'boot_pt1' to 'kern_pt1'. */
 	pmap_kern_ttb = base_pt1 | ttb_flags;
-	cpuinfo_get_actlr_modifier(&actlr_mask, &actlr_set);
-	reinit_mmu(pmap_kern_ttb, actlr_mask, actlr_set);
+	cpuinfo_reinit_mmu(pmap_kern_ttb);
 	/*
 	 * Initialize the first available KVA. As kernel image is mapped by
 	 * sections, we are leaving some gap behind.

Modified: stable/11/sys/arm/include/cpuinfo.h
==============================================================================
--- stable/11/sys/arm/include/cpuinfo.h	Wed Apr  4 01:13:28 2018	(r331967)
+++ stable/11/sys/arm/include/cpuinfo.h	Wed Apr  4 01:56:46 2018	(r331968)
@@ -121,5 +121,7 @@ struct cpuinfo {
 extern struct cpuinfo cpuinfo;
 
 void cpuinfo_init(void);
-void cpuinfo_get_actlr_modifier(uint32_t *actlr_mask, uint32_t *actlr_set);
+#if __ARM_ARCH >= 6
+void cpuinfo_reinit_mmu(uint32_t ttb);
+#endif
 #endif	/* _MACHINE_CPUINFO_H_ */

Modified: stable/11/sys/arm/include/pmap-v6.h
==============================================================================
--- stable/11/sys/arm/include/pmap-v6.h	Wed Apr  4 01:13:28 2018	(r331967)
+++ stable/11/sys/arm/include/pmap-v6.h	Wed Apr  4 01:56:46 2018	(r331968)
@@ -177,7 +177,6 @@ vm_paddr_t pmap_dump_kextract(vm_offset_t, pt2_entry_t
 int pmap_fault(pmap_t, vm_offset_t, uint32_t, int, bool);
 
 void pmap_set_tex(void);
-void reinit_mmu(ttb_entry_t ttb, u_int aux_clr, u_int aux_set);
 
 /*
  * Pre-bootstrap epoch functions set.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201804040156.w341uk90019363>