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