Module Name:    src
Committed By:   matt
Date:           Wed Aug 29 19:10:17 UTC 2012

Modified Files:
        src/sys/arch/arm/arm32: cortex_pmc.c
        src/sys/arch/arm/include/arm32: machdep.h
        src/sys/arch/evbarm/beagle: beagle_machdep.c
        src/sys/arch/evbarm/conf: std.beagle
        src/sys/arch/evbarm/gumstix: gumstix_machdep.c
        src/sys/arch/evbarm/netwalker: netwalker_machdep.c

Log Message:
Since the PMC cycle counter is started in cpufunc no reason to do so here.
Use curcpu()->ci_data.cpu_cc_freq and new armreg* inlines.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/arm32/cortex_pmc.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/arm/include/arm32/machdep.h
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/evbarm/beagle/beagle_machdep.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/evbarm/conf/std.beagle
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/evbarm/gumstix/gumstix_machdep.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/evbarm/netwalker/netwalker_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/arm/arm32/cortex_pmc.c
diff -u src/sys/arch/arm/arm32/cortex_pmc.c:1.1 src/sys/arch/arm/arm32/cortex_pmc.c:1.2
--- src/sys/arch/arm/arm32/cortex_pmc.c:1.1	Sat Jun 19 19:44:57 2010
+++ src/sys/arch/arm/arm32/cortex_pmc.c	Wed Aug 29 19:10:15 2012
@@ -28,12 +28,12 @@
 
 
 /*
- * support for ARM cortexa8 Performance Monitor Counters
+ * support for ARM cortex Performance Monitor Counters
  * based on arm11_pmc.c
  */
 
 #include <sys/cdefs.h>
-/* __KERNEL_RCSID(0, "$NetBSD: cortex_pmc.c,v 1.1 2010/06/19 19:44:57 matt Exp $"); */
+/* __KERNEL_RCSID(0, "$NetBSD: cortex_pmc.c,v 1.2 2012/08/29 19:10:15 matt Exp $"); */
 #include "opt_perfctrs.h"
 #include <sys/types.h>
 #include <sys/param.h>
@@ -41,69 +41,32 @@
 #include <sys/kernel.h>  
 #include <sys/time.h>
 #include <sys/timetc.h>
+
 #include <dev/clock_subr.h>
+
+#include <uvm/uvm_extern.h>
+
 #include <arm/armreg.h>
 #include <arm/cpufunc.h>
+#include <arm/arm32/machdep.h>
 
 #ifndef CORTEX_PMC_CCNT_HZ
 # define CORTEX_PMC_CCNT_HZ	400000000	/* 400MHz */
 #endif
 
-void cortexa8_pmc_ccnt_init(void);
-
-#define COUNTS_PER_USEC	(CORTEX_PMC_CCNT_HZ / 1000000)
-
-static uint32_t counts_per_wrap = ~0UL;		/* XXX off by 1 */
-
-#define PMNC "c9, c12, 0"
-#define CCNT "c9, c13, 0"
-
-static inline uint32_t
-cortexa8_pmc_ctrl_read(void)
-{
-	uint32_t val;
-
-	__asm volatile ("mrc p15, 0, %0, " PMNC : "=r" (val));
-
-	return val;
-}
-
-static inline void
-cortexa8_pmc_ctrl_write(uint32_t val)
-{
-	__asm volatile ("mcr p15, 0, %0, " PMNC :: "r" (val));
-}
-
-static inline uint32_t
-cortexa8_pmc_ccnt_read(void)
-{
-	uint32_t val;
+#define COUNTS_PER_USEC	(curcpu()->ci_data.cpu_cc_freq / (1000*1000))
 
-	__asm volatile ("mrc p15, 0, %0, " CCNT : "=r" (val));
-
-	return val;
-}
-
-static inline void
-cortexa8_pmc_ccnt_write(uint32_t val)
-{
-  __asm volatile ("mcr p15, 0, %0, c9, c12, 2"  :: "r" (CORTEX_CNTENC_C));
-  __asm volatile ("mcr p15, 0, %0, " CCNT :: "r" (val));
-  __asm volatile ("mcr p15, 0, %0, c9, c12, 1" :: "r" (CORTEX_CNTENS_C));
-}
+static const uint32_t counts_per_wrap = ~0UL - 1;
 
 /*
  * enable the PMC CCNT for delay()
  */
 void
-cortexa8_pmc_ccnt_init(void)
+cortex_pmc_ccnt_init(void)
 {
-  uint32_t val;
-  
-  val = ARM11_PMCCTL_E | ARM11_PMCCTL_P | ARM11_PMCCTL_C;
-	
-  cortexa8_pmc_ctrl_write(val);
-  __asm volatile ("mcr p15, 0, %0, c9, c12, 1" :: "r" (CORTEX_CNTENS_C));
+	if (curcpu()->ci_data.cpu_cc_freq == 0) {
+		curcpu()->ci_data.cpu_cc_freq = CORTEX_PMC_CCNT_HZ;
+	}
 }
 
 /*
@@ -112,7 +75,6 @@ cortexa8_pmc_ccnt_init(void)
  *	NOTE: at 400MHz we are restricted to (uint32_t)~0 "counts"
  *	if this is a problem, accumulate counts in LL vars
  */
-#define DELAY_ARG_LIMIT (((uint32_t)~0) / COUNTS_PER_USEC)	/* about 10 sec */
 void
 delay(u_int arg)
 {
@@ -121,29 +83,32 @@ delay(u_int arg)
 	uint32_t last;
 	uint32_t delta = 0;
 	uint32_t usecs = 0;
+	const uint32_t counts_per_usec = COUNTS_PER_USEC;
+	const uint32_t delay_arg_limit = ~0UL / counts_per_usec; /* about 10 sec */
 
-	if (arg > DELAY_ARG_LIMIT)
-		panic("delay: arg %u overflow, limit is %d usec\n", arg, DELAY_ARG_LIMIT);
+	if (arg > delay_arg_limit)
+		panic("%s: arg %u overflow, limit is %u usec\n",
+		    __func__, arg, delay_arg_limit);
 
-	last = cortexa8_pmc_ccnt_read();
+	last = armreg_pmccntr_read();
 	delta = usecs = 0;
 	while (arg > usecs) {
-		cur  = cortexa8_pmc_ccnt_read();
+		cur = armreg_pmccntr_read();
 		
 		/* overflow flag is moved to a separate register
 		   and is not read from PMC Control Register */
-		__asm volatile ("mrc p15, 0, %0, c9, c12, 3" : "=r" (ctrl));
-		if(ctrl & CORTEX_CNTOFL_C){
+		ctrl = armreg_pmovsr_read();
+		if (ctrl & CORTEX_CNTOFL_C) {
 		  /* Reset overflow flag for cycle counter in overflow register */
-		  __asm volatile ("mcr p15, 0, %0, c9, c12, 3" :: "r" (CORTEX_CNTOFL_C));
-		  delta += (last + (counts_per_wrap - cur));
+			armreg_pmovsr_write(CORTEX_CNTOFL_C);
+			delta += (last + (counts_per_wrap - cur));
 		} else {
 			delta += (cur - last);
 		}
 		last = cur;
-		if (delta >= COUNTS_PER_USEC) {
-			usecs += delta / COUNTS_PER_USEC;
-			delta %= COUNTS_PER_USEC;
+		if (delta >= counts_per_usec) {
+			usecs += delta / counts_per_usec;
+			delta %= counts_per_usec;
 		}
 	}
 }

Index: src/sys/arch/arm/include/arm32/machdep.h
diff -u src/sys/arch/arm/include/arm32/machdep.h:1.11 src/sys/arch/arm/include/arm32/machdep.h:1.12
--- src/sys/arch/arm/include/arm32/machdep.h:1.11	Thu Aug 16 18:22:40 2012
+++ src/sys/arch/arm/include/arm32/machdep.h	Wed Aug 29 19:10:16 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.h,v 1.11 2012/08/16 18:22:40 matt Exp $ */
+/* $NetBSD: machdep.h,v 1.12 2012/08/29 19:10:16 matt Exp $ */
 
 #ifndef _ARM32_BOOT_MACHDEP_H_
 #define _ARM32_BOOT_MACHDEP_H_
@@ -32,6 +32,7 @@ extern u_int undefined_handler_address;
 extern char *booted_kernel;
 
 /* misc prototypes used by the many arm machdeps */
+void cortex_pmc_ccnt_init(void);
 void halt(void);
 void parse_mi_bootargs(char *);
 void data_abort_handler(trapframe_t *);

Index: src/sys/arch/evbarm/beagle/beagle_machdep.c
diff -u src/sys/arch/evbarm/beagle/beagle_machdep.c:1.18 src/sys/arch/evbarm/beagle/beagle_machdep.c:1.19
--- src/sys/arch/evbarm/beagle/beagle_machdep.c:1.18	Wed Aug 29 18:05:41 2012
+++ src/sys/arch/evbarm/beagle/beagle_machdep.c	Wed Aug 29 19:10:16 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: beagle_machdep.c,v 1.18 2012/08/29 18:05:41 matt Exp $ */
+/*	$NetBSD: beagle_machdep.c,v 1.19 2012/08/29 19:10:16 matt Exp $ */
 
 /*
  * Machine dependent functions for kernel setup for TI OSK5912 board.
@@ -125,7 +125,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: beagle_machdep.c,v 1.18 2012/08/29 18:05:41 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: beagle_machdep.c,v 1.19 2012/08/29 19:10:16 matt Exp $");
 
 #include "opt_machdep.h"
 #include "opt_ddb.h"
@@ -645,8 +645,6 @@ initarm(void *arg)
 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
 }
 
-void cortexa8_pmc_ccnt_init(void);
-
 static void
 init_clocks(void)
 {
@@ -663,7 +661,7 @@ init_clocks(void)
 	}
 	beagle_putchar('G');
 #endif
-	cortexa8_pmc_ccnt_init();
+	cortex_pmc_ccnt_init();
 }
 
 #ifndef CONSADDR

Index: src/sys/arch/evbarm/conf/std.beagle
diff -u src/sys/arch/evbarm/conf/std.beagle:1.4 src/sys/arch/evbarm/conf/std.beagle:1.5
--- src/sys/arch/evbarm/conf/std.beagle:1.4	Wed Aug 29 07:14:05 2012
+++ src/sys/arch/evbarm/conf/std.beagle	Wed Aug 29 19:10:16 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: std.beagle,v 1.4 2012/08/29 07:14:05 matt Exp $
+#	$NetBSD: std.beagle,v 1.5 2012/08/29 19:10:16 matt Exp $
 #
 # standard NetBSD/evbarm for BEAGLEBAORD options
 
@@ -12,9 +12,9 @@ options 	EXEC_ELF32
 options 	EXEC_SCRIPT
 
 # To support easy transit to ../arch/arm/arm32
+options 	__HAVE_CPU_COUNTER
 options 	ARM32
 options 	CORTEX_PMC
-options 	CORTEX_PMC_CCNT_HZ=500000000
 options 	__HAVE_FAST_SOFTINTS		# should be in types.h
 options 	TPIDRPRW_IS_CURCPU
 options 	KERNEL_BASE_EXT=0x80000000

Index: src/sys/arch/evbarm/gumstix/gumstix_machdep.c
diff -u src/sys/arch/evbarm/gumstix/gumstix_machdep.c:1.41 src/sys/arch/evbarm/gumstix/gumstix_machdep.c:1.42
--- src/sys/arch/evbarm/gumstix/gumstix_machdep.c:1.41	Thu Aug 16 18:22:43 2012
+++ src/sys/arch/evbarm/gumstix/gumstix_machdep.c	Wed Aug 29 19:10:16 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: gumstix_machdep.c,v 1.41 2012/08/16 18:22:43 matt Exp $ */
+/*	$NetBSD: gumstix_machdep.c,v 1.42 2012/08/29 19:10:16 matt Exp $ */
 /*
  * Copyright (C) 2005, 2006, 2007  WIDE Project and SOUM Corporation.
  * All rights reserved.
@@ -530,12 +530,8 @@ initarm(void *arg)
 	pxa2x0_gpio_bootstrap(GUMSTIX_GPIO_VBASE);
 
 	pxa2x0_clkman_bootstrap(GUMSTIX_CLKMAN_VBASE);
-#elif defined(CPU_CORTEXA8)
-	{
-		void cortexa8_pmc_ccnt_init(void);
-
-		cortexa8_pmc_ccnt_init();
-	}
+#elif defined(CPU_CORTEX)
+	cortex_pmc_ccnt_init();
 #endif
 
 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);

Index: src/sys/arch/evbarm/netwalker/netwalker_machdep.c
diff -u src/sys/arch/evbarm/netwalker/netwalker_machdep.c:1.8 src/sys/arch/evbarm/netwalker/netwalker_machdep.c:1.9
--- src/sys/arch/evbarm/netwalker/netwalker_machdep.c:1.8	Thu Aug 16 18:22:45 2012
+++ src/sys/arch/evbarm/netwalker/netwalker_machdep.c	Wed Aug 29 19:10:17 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: netwalker_machdep.c,v 1.8 2012/08/16 18:22:45 matt Exp $	*/
+/*	$NetBSD: netwalker_machdep.c,v 1.9 2012/08/29 19:10:17 matt Exp $	*/
 
 /*
  * Copyright (c) 2002, 2003, 2005, 2010  Genetec Corporation. 
@@ -102,7 +102,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netwalker_machdep.c,v 1.8 2012/08/16 18:22:45 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netwalker_machdep.c,v 1.9 2012/08/29 19:10:17 matt Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -887,9 +887,7 @@ process_kernel_args(char *args)
 static void
 init_clocks(void)
 {
-	extern void cortexa8_pmc_ccnt_init(void);
-
-	cortexa8_pmc_ccnt_init();
+	cortex_pmc_ccnt_init();
 }
 
 struct iomux_setup {

Reply via email to