xref: /titanic_51/usr/src/uts/i86pc/sys/clock.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef _SYS_CLOCK_H
28*7c478bd9Sstevel@tonic-gate #define	_SYS_CLOCK_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
33*7c478bd9Sstevel@tonic-gate extern "C" {
34*7c478bd9Sstevel@tonic-gate #endif
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #ifndef	_ASM
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #include <sys/psw.h>
41*7c478bd9Sstevel@tonic-gate #include <sys/time.h>
42*7c478bd9Sstevel@tonic-gate #include <sys/processor.h>
43*7c478bd9Sstevel@tonic-gate #if defined(__GNUC__) && defined(_ASM_INLINES)
44*7c478bd9Sstevel@tonic-gate #include <asm/clock.h>
45*7c478bd9Sstevel@tonic-gate #endif
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate extern void unlock_hres_lock(void);
48*7c478bd9Sstevel@tonic-gate extern timestruc_t pc_tod_get(void);
49*7c478bd9Sstevel@tonic-gate extern void pc_tod_set(timestruc_t);
50*7c478bd9Sstevel@tonic-gate extern void hres_tick(void);
51*7c478bd9Sstevel@tonic-gate extern void (*hrtime_tick)(void);
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate extern void tsc_hrtimeinit(uint64_t cpu_freq_hz);
54*7c478bd9Sstevel@tonic-gate extern hrtime_t tsc_gethrtime(void);
55*7c478bd9Sstevel@tonic-gate extern hrtime_t tsc_gethrtime_delta(void);
56*7c478bd9Sstevel@tonic-gate extern hrtime_t tsc_gethrtimeunscaled(void);
57*7c478bd9Sstevel@tonic-gate extern void tsc_scalehrtime(hrtime_t *);
58*7c478bd9Sstevel@tonic-gate extern hrtime_t tsc_gethrtimeunscaled_delta(void);
59*7c478bd9Sstevel@tonic-gate extern void tsc_tick(void);
60*7c478bd9Sstevel@tonic-gate extern void tsc_sync_master(processorid_t);
61*7c478bd9Sstevel@tonic-gate extern void tsc_sync_slave(void);
62*7c478bd9Sstevel@tonic-gate extern hrtime_t tsc_read(void);
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate #define	ADJ_SHIFT 4		/* used in get_hrestime */
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate #define	YRBASE		00	/* 1900 - what year 0 in chip represents */
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate #endif	/* !_ASM */
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate #define	CBE_HIGH_PIL	14
72*7c478bd9Sstevel@tonic-gate #define	CBE_LOCK_PIL	LOCK_LEVEL
73*7c478bd9Sstevel@tonic-gate #define	CBE_LOW_PIL	2
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate /*
76*7c478bd9Sstevel@tonic-gate  * CLOCK_LOCK() sets the LSB (bit 0) of the hres_lock. The rest of the
77*7c478bd9Sstevel@tonic-gate  * 31bits are used as the counter. This lock is acquired
78*7c478bd9Sstevel@tonic-gate  * around "hrestime" and "timedelta". This lock is acquired to make
79*7c478bd9Sstevel@tonic-gate  * sure that level-14 accounts for changes to this variable in that
80*7c478bd9Sstevel@tonic-gate  * interrupt itself. The level-14 interrupt code also acquires this
81*7c478bd9Sstevel@tonic-gate  * lock.
82*7c478bd9Sstevel@tonic-gate  * (Note: It is assumed that the lock_set_spl() uses only bit 0 of the lock.)
83*7c478bd9Sstevel@tonic-gate  *
84*7c478bd9Sstevel@tonic-gate  * CLOCK_UNLOCK() increments the lower bytes straight, thus clearing the
85*7c478bd9Sstevel@tonic-gate  * lock and also incrementing the counter. This way gethrtime()
86*7c478bd9Sstevel@tonic-gate  * can figure out if the value in the lock got changed or not.
87*7c478bd9Sstevel@tonic-gate  */
88*7c478bd9Sstevel@tonic-gate #define	HRES_LOCK_OFFSET 0	/* byte 0 has the lock bit(bit 0 in the byte) */
89*7c478bd9Sstevel@tonic-gate 
90*7c478bd9Sstevel@tonic-gate #define	CLOCK_LOCK(oldsplp)	\
91*7c478bd9Sstevel@tonic-gate 	lock_set_spl((lock_t *)&hres_lock + HRES_LOCK_OFFSET, 	\
92*7c478bd9Sstevel@tonic-gate 		ipltospl(XC_HI_PIL), oldsplp)
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate #define	CLOCK_UNLOCK(spl)		\
95*7c478bd9Sstevel@tonic-gate 	unlock_hres_lock();		\
96*7c478bd9Sstevel@tonic-gate 	splx(spl);			\
97*7c478bd9Sstevel@tonic-gate 	LOCKSTAT_RECORD0(LS_CLOCK_UNLOCK_RELEASE,	\
98*7c478bd9Sstevel@tonic-gate 		(lock_t *)&hres_lock + HRES_LOCK_OFFSET);
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate #endif	/* KERNEL */
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
103*7c478bd9Sstevel@tonic-gate }
104*7c478bd9Sstevel@tonic-gate #endif
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_CLOCK_H */
107