xref: /titanic_44/usr/src/uts/i86pc/sys/clock.h (revision 2ec7cc7fc084163eaed884efee9bbd322cc8951b)
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_CLOCK_H
27 #define	_SYS_CLOCK_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #ifdef	_KERNEL
36 
37 #ifndef	_ASM
38 
39 #include <sys/psw.h>
40 #include <sys/time.h>
41 #include <sys/processor.h>
42 #if defined(__GNUC__) && defined(_ASM_INLINES)
43 #include <asm/clock.h>
44 #endif
45 #include <sys/machclock.h>
46 
47 extern time_t ggmtl(void);
48 extern void sgmtl(time_t);
49 extern void rtcsync(void);
50 
51 extern void unlock_hres_lock(void);
52 extern void hres_tick(void);
53 extern void (*hrtime_tick)(void);
54 
55 #ifndef __xpv
56 extern void tsc_hrtimeinit(uint64_t cpu_freq_hz);
57 extern void tsc_sync_master(processorid_t);
58 extern void tsc_sync_slave(void);
59 #endif
60 
61 /*
62  * Careful: this can always return zero on some systems.  Use the system hrtime
63  * routines if you want a meaningful time.
64  */
65 extern hrtime_t tsc_read(void);
66 
67 extern hrtime_t __rdtsc_insn(void);
68 
69 extern int tsc_gethrtime_enable;
70 
71 #define	ADJ_SHIFT 4		/* used in get_hrestime */
72 
73 #define	YRBASE		00	/* 1900 - what year 0 in chip represents */
74 
75 #endif	/* !_ASM */
76 
77 #define	CBE_HIGH_PIL	14
78 #define	CBE_LOCK_PIL	LOCK_LEVEL
79 #define	CBE_LOW_PIL	2
80 
81 /*
82  * CLOCK_LOCK() sets the LSB (bit 0) of the hres_lock. The rest of the
83  * 31bits are used as the counter. This lock is acquired
84  * around "hrestime" and "timedelta". This lock is acquired to make
85  * sure that level-14 accounts for changes to this variable in that
86  * interrupt itself. The level-14 interrupt code also acquires this
87  * lock.
88  * (Note: It is assumed that the lock_set_spl() uses only bit 0 of the lock.)
89  *
90  * CLOCK_UNLOCK() increments the lower bytes straight, thus clearing the
91  * lock and also incrementing the counter. This way gethrtime()
92  * can figure out if the value in the lock got changed or not.
93  */
94 #define	HRES_LOCK_OFFSET 0	/* byte 0 has the lock bit(bit 0 in the byte) */
95 
96 #define	CLOCK_LOCK(oldsplp)	\
97 	lock_set_spl((lock_t *)&hres_lock + HRES_LOCK_OFFSET, 	\
98 		ipltospl(XC_HI_PIL), oldsplp)
99 
100 #define	CLOCK_UNLOCK(spl)		\
101 	unlock_hres_lock();		\
102 	splx(spl);			\
103 	LOCKSTAT_RECORD0(LS_CLOCK_UNLOCK_RELEASE,	\
104 		(lock_t *)&hres_lock + HRES_LOCK_OFFSET);
105 
106 #endif	/* KERNEL */
107 
108 #ifdef	__cplusplus
109 }
110 #endif
111 
112 #endif	/* _SYS_CLOCK_H */
113