xref: /titanic_51/usr/src/uts/sun4u/sys/machclock.h (revision 0cd13cbfb4270b840b4bd22ec5f673b2b6a2c02b)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_MACHCLOCK_H
27 #define	_SYS_MACHCLOCK_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #ifdef _ASM
36 /*
37  * Macro to clear the NPT (non-privileged trap) bit in the %tick/%stick
38  * register.  Uses %g1-%g4.
39  */
40 #define	CLEARTICKNPT				\
41 	sethi	%hi(cpu_clearticknpt), %g1;	\
42 	jmp	%g1 + %lo(cpu_clearticknpt);	\
43 	rd	%pc, %g4
44 
45 #endif /* _ASM */
46 
47 #if defined(CPU_MODULE)
48 
49 /*
50  * Constants used to convert hi-res timestamps into nanoseconds
51  * (see <sys/clock.h> file for more information)
52  */
53 
54 #if defined(CHEETAH) || defined(HUMMINGBIRD) || defined(OLYMPUS_C)
55 
56 /*
57  * At least 3.9MHz, for slower %stick-based systems.
58  */
59 #define	NSEC_SHIFT	8
60 #define	VTRACE_SHIFT	8
61 
62 #elif defined(SPITFIRE)
63 
64 /*
65  * At least 62.5 MHz, for faster %tick-based systems.
66  */
67 #define	NSEC_SHIFT	4
68 #define	VTRACE_SHIFT	4
69 
70 #else
71 #error "Compiling for CPU_MODULE but no CPU specified"
72 #endif
73 
74 #endif /* CPU_MODULE */
75 
76 #ifndef _ASM
77 
78 #ifdef	_KERNEL
79 
80 /*
81  * Hardware watchdog variables and knobs
82  */
83 
84 #define	CLK_WATCHDOG_DEFAULT	10	/* 10 seconds */
85 
86 extern int	watchdog_enable;
87 extern int	watchdog_available;
88 extern int	watchdog_activated;
89 extern uint_t	watchdog_timeout_seconds;
90 
91 /*
92  * tod module name and operations
93  */
94 struct tod_ops {
95 	timestruc_t	(*tod_get)(void);
96 	void		(*tod_set)(timestruc_t);
97 	uint_t		(*tod_set_watchdog_timer)(uint_t);
98 	uint_t		(*tod_clear_watchdog_timer)(void);
99 	void		(*tod_set_power_alarm)(timestruc_t);
100 	void		(*tod_clear_power_alarm)(void);
101 	uint64_t	(*tod_get_cpufrequency)(void);
102 };
103 
104 extern struct tod_ops	tod_ops;
105 extern char		*tod_module_name;
106 
107 /*
108  * These defines allow common code to use TOD functions independant
109  * of hardware platform.
110  */
111 #define	TODOP_GET(top)		((top).tod_get())
112 #define	TODOP_SET(top, ts)	((top).tod_set(ts))
113 #define	TODOP_SETWD(top, nsec)	((top).tod_set_watchdog_timer(nsec))
114 #define	TODOP_CLRWD(top)	((top).tod_clear_watchdog_timer())
115 #define	TODOP_SETWAKE(top, ts)	((top).tod_set_power_alarm(ts))
116 #define	TODOP_CLRWAKE(top)	((top).tod_clear_power_alarm())
117 
118 #endif	/* _KERNEL */
119 
120 #endif	/* _ASM */
121 
122 #ifdef	__cplusplus
123 }
124 #endif
125 
126 #endif	/* !_SYS_MACHCLOCK_H */
127