Home | History | Annotate | Line # | Download | only in include
cpu_counter.h revision 1.3.2.1
      1  1.3.2.1      yamt /*	$NetBSD: cpu_counter.h,v 1.3.2.1 2006/02/18 15:38:44 yamt Exp $	*/
      2      1.1  nakayama 
      3      1.1  nakayama /*-
      4      1.1  nakayama  * Copyright (c) 2000 Tsubai Masanari.  All rights reserved.
      5      1.1  nakayama  *
      6      1.1  nakayama  * Redistribution and use in source and binary forms, with or without
      7      1.1  nakayama  * modification, are permitted provided that the following conditions
      8      1.1  nakayama  * are met:
      9      1.1  nakayama  * 1. Redistributions of source code must retain the above copyright
     10      1.1  nakayama  *    notice, this list of conditions and the following disclaimer.
     11      1.1  nakayama  * 2. Redistributions in binary form must reproduce the above copyright
     12      1.1  nakayama  *    notice, this list of conditions and the following disclaimer in the
     13      1.1  nakayama  *    documentation and/or other materials provided with the distribution.
     14      1.1  nakayama  * 3. The name of the author may not be used to endorse or promote products
     15      1.1  nakayama  *    derived from this software without specific prior written permission.
     16      1.1  nakayama  *
     17      1.1  nakayama  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18      1.1  nakayama  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19      1.1  nakayama  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20      1.1  nakayama  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21      1.1  nakayama  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22      1.1  nakayama  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23      1.1  nakayama  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24      1.1  nakayama  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25      1.1  nakayama  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26      1.1  nakayama  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27      1.1  nakayama  */
     28      1.1  nakayama 
     29      1.1  nakayama #ifndef _POWERPC_CPU_COUNTER_H_
     30      1.1  nakayama #define _POWERPC_CPU_COUNTER_H_
     31      1.1  nakayama 
     32      1.1  nakayama /*
     33      1.1  nakayama  * Machine-specific support for CPU counter.
     34      1.1  nakayama  */
     35      1.1  nakayama 
     36      1.1  nakayama #ifdef _KERNEL
     37      1.1  nakayama 
     38      1.1  nakayama #include <powerpc/spr.h>
     39      1.1  nakayama 
     40      1.1  nakayama #define cpu_hascounter()	(1)
     41      1.1  nakayama #define cpu_counter()		cpu_counter32()
     42      1.1  nakayama 
     43  1.3.2.1      yamt static __inline uint32_t
     44      1.1  nakayama cpu_counter32(void)
     45      1.1  nakayama {
     46      1.1  nakayama 	uint32_t rv, rtcu, scratch;
     47      1.1  nakayama 
     48      1.3     perry 	__asm volatile (
     49      1.1  nakayama 	    "mfpvr	%0		\n"
     50      1.1  nakayama 	    "srwi	%0,%0,16	\n"
     51      1.1  nakayama 	    "cmpwi	%0,%3		\n"
     52      1.1  nakayama 	    "bne	1f		\n"	/* branch if not 601 */
     53      1.1  nakayama 	    "lis	%0,0x77		\n"
     54      1.1  nakayama 	    "ori	%0,%0,0x3594	\n"	/* 7.8125e6 */
     55      1.1  nakayama 	    "mfspr	%2,%4		\n"
     56      1.1  nakayama 	    "mullw	%2,%2,%0	\n"
     57      1.1  nakayama 	    "mfspr	%0,%5		\n"
     58      1.1  nakayama 	    "srwi	%0,%0,7		\n"
     59      1.1  nakayama 	    "add	%1,%2,%0	\n"
     60      1.1  nakayama 	    "b		2f		\n"
     61      1.1  nakayama 	    "1:				\n"
     62      1.2   hannken #ifdef PPC_IBM403
     63      1.2   hannken 	    "mftblo	%1		\n"
     64      1.2   hannken #else
     65      1.1  nakayama 	    "mftb	%1		\n"
     66      1.2   hannken #endif
     67      1.1  nakayama 	    "2:				\n"
     68      1.1  nakayama 	    : "=r"(scratch), "=r"(rv), "=r"(rtcu)
     69      1.1  nakayama 	    : "n"(MPC601), "n"(SPR_RTCU_R), "n"(SPR_RTCL_R));
     70      1.1  nakayama 
     71      1.1  nakayama 	return rv;
     72      1.1  nakayama }
     73      1.1  nakayama 
     74      1.1  nakayama #if 0	/* XXX MI microtime() needs frequency of CPU counter. */
     75  1.3.2.1      yamt static __inline uint64_t
     76      1.1  nakayama cpu_frequency(struct cpu_info *ci)
     77      1.1  nakayama {
     78      1.1  nakayama }
     79      1.1  nakayama #endif
     80      1.1  nakayama #endif /* _KERNEL */
     81      1.1  nakayama 
     82      1.1  nakayama #endif /* _POWERPC_CPU_COUNTER_H_ */
     83