Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch Add __HAVE_CPU_COUNTER support for ARM11 and Cortex...
details: https://anonhg.NetBSD.org/src/rev/15975d6596f8
branches: trunk
changeset: 781005:15975d6596f8
user: matt <matt%NetBSD.org@localhost>
date: Tue Aug 14 21:12:59 2012 +0000
description:
Add __HAVE_CPU_COUNTER support for ARM11 and Cortex CPUs
diffstat:
sys/arch/arm/include/armreg.h | 3 +-
sys/arch/arm/include/cpu_counter.h | 81 +++++++++++++++++++++++++++++++++++
sys/arch/evbarm/include/cpu_counter.h | 3 +
3 files changed, 86 insertions(+), 1 deletions(-)
diffs (109 lines):
diff -r a6931678880a -r 15975d6596f8 sys/arch/arm/include/armreg.h
--- a/sys/arch/arm/include/armreg.h Tue Aug 14 20:42:33 2012 +0000
+++ b/sys/arch/arm/include/armreg.h Tue Aug 14 21:12:59 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: armreg.h,v 1.57 2012/07/31 07:39:56 matt Exp $ */
+/* $NetBSD: armreg.h,v 1.58 2012/08/14 21:12:59 matt Exp $ */
/*
* Copyright (c) 1998, 2001 Ben Harris
@@ -202,6 +202,7 @@
#define CPU_ID_ARM1136JSR1 0x4117b360
#define CPU_ID_ARM1156T2S 0x4107b560 /* MPU only */
#define CPU_ID_ARM1176JZS 0x410fb760
+#define CPU_ID_ARM11_P(n) ((n & 0xff07f000) == 0x4107b000)
#define CPU_ID_CORTEXA5R0 0x410fc050
#define CPU_ID_CORTEXA8R1 0x411fc080
#define CPU_ID_CORTEXA8R2 0x412fc080
diff -r a6931678880a -r 15975d6596f8 sys/arch/arm/include/cpu_counter.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/include/cpu_counter.h Tue Aug 14 21:12:59 2012 +0000
@@ -0,0 +1,81 @@
+/* $NetBSD: cpu_counter.h,v 1.1 2012/08/14 21:12:59 matt Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matt Thomas of 3am Software Foundry.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _ARM_CPU_COUNTER_H_
+#define _ARM_CPU_COUNTER_H_
+
+/*
+ * ARM specific support for CPU counter (ARM11 and Cortex only).
+ * If __HAVE_CPU_COUNTER is defined for any other CPU_*, it will crash.
+ */
+
+#ifdef _KERNEL
+
+#include <sys/cpu.h>
+
+#if defined(CPU_CORTEX) || defined(CPU_ARM11)
+#define cpu_hascounter() true
+#else
+#define cpu_hascounter() false
+#endif
+
+#define cpu_counter() cpu_counter32()
+
+#if defined(CPU_CORTEX) || defined(CPU_ARM11)
+static __inline uint32_t
+cpu_counter32(void)
+{
+#if defined(CPU_CORTEX) && defined(CPU_ARM11)
+ const bool cortex_p = CPU_ID_CORTEX_P(curcpu()->ci_cpu_id);
+#elif defined(CPU_CORTEX)
+ const bool cortex_p = true;
+#elif defined(CPU_ARM11)
+ const bool cortex_p = false;
+#endif
+
+ uint32_t rv;
+ if (cortex_p)
+ __asm __volatile("mrc p15, 0, %0, c9, c12, 1" : "=r"(rv));
+ else
+ __asm __volatile("mrc p15, 0, %0, c15, c12, 1" : "=r"(rv));
+ return rv;
+}
+#endif
+
+static __inline uint64_t
+cpu_frequency(struct cpu_info *ci)
+{
+ return ci->ci_ccnt_freq;
+}
+
+#endif /* _KERNEL */
+
+#endif /* _ARM_CPU_COUNTER_H_ */
diff -r a6931678880a -r 15975d6596f8 sys/arch/evbarm/include/cpu_counter.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/evbarm/include/cpu_counter.h Tue Aug 14 21:12:59 2012 +0000
@@ -0,0 +1,3 @@
+/* $NetBSD: cpu_counter.h,v 1.1 2012/08/14 21:12:59 matt Exp $ */
+
+#include <arm/cpu_counter.h>
Home |
Main Index |
Thread Index |
Old Index