xref: /titanic_51/usr/src/uts/i86pc/sys/clock.h (revision 843e19887f64dde75055cf8842fc4db2171eff45)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5ae115bc7Smrj  * Common Development and Distribution License (the "License").
6ae115bc7Smrj  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22ae115bc7Smrj  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _SYS_CLOCK_H
277c478bd9Sstevel@tonic-gate #define	_SYS_CLOCK_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
327c478bd9Sstevel@tonic-gate extern "C" {
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifndef	_ASM
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include <sys/psw.h>
407c478bd9Sstevel@tonic-gate #include <sys/time.h>
417c478bd9Sstevel@tonic-gate #include <sys/processor.h>
427c478bd9Sstevel@tonic-gate #if defined(__GNUC__) && defined(_ASM_INLINES)
437c478bd9Sstevel@tonic-gate #include <asm/clock.h>
447c478bd9Sstevel@tonic-gate #endif
45ae115bc7Smrj #include <sys/machclock.h>
46ae115bc7Smrj 
47ae115bc7Smrj extern time_t ggmtl(void);
48ae115bc7Smrj extern void sgmtl(time_t);
49ae115bc7Smrj extern void rtcsync(void);
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate extern void unlock_hres_lock(void);
527c478bd9Sstevel@tonic-gate extern void hres_tick(void);
537c478bd9Sstevel@tonic-gate extern void (*hrtime_tick)(void);
547c478bd9Sstevel@tonic-gate 
55*843e1988Sjohnlev #ifndef __xpv
567c478bd9Sstevel@tonic-gate extern void tsc_hrtimeinit(uint64_t cpu_freq_hz);
577c478bd9Sstevel@tonic-gate extern void tsc_sync_master(processorid_t);
587c478bd9Sstevel@tonic-gate extern void tsc_sync_slave(void);
59*843e1988Sjohnlev #endif
60*843e1988Sjohnlev 
61*843e1988Sjohnlev /*
62*843e1988Sjohnlev  * Careful: this can always return zero on some systems.  Use the system hrtime
63*843e1988Sjohnlev  * routines if you want a meaningful time.
64*843e1988Sjohnlev  */
657c478bd9Sstevel@tonic-gate extern hrtime_t tsc_read(void);
66*843e1988Sjohnlev 
67ae115bc7Smrj extern hrtime_t __rdtsc_insn(void);
687c478bd9Sstevel@tonic-gate 
69*843e1988Sjohnlev extern int tsc_gethrtime_enable;
70*843e1988Sjohnlev 
717c478bd9Sstevel@tonic-gate #define	ADJ_SHIFT 4		/* used in get_hrestime */
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #define	YRBASE		00	/* 1900 - what year 0 in chip represents */
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate #endif	/* !_ASM */
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate #define	CBE_HIGH_PIL	14
787c478bd9Sstevel@tonic-gate #define	CBE_LOCK_PIL	LOCK_LEVEL
797c478bd9Sstevel@tonic-gate #define	CBE_LOW_PIL	2
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate  * CLOCK_LOCK() sets the LSB (bit 0) of the hres_lock. The rest of the
837c478bd9Sstevel@tonic-gate  * 31bits are used as the counter. This lock is acquired
847c478bd9Sstevel@tonic-gate  * around "hrestime" and "timedelta". This lock is acquired to make
857c478bd9Sstevel@tonic-gate  * sure that level-14 accounts for changes to this variable in that
867c478bd9Sstevel@tonic-gate  * interrupt itself. The level-14 interrupt code also acquires this
877c478bd9Sstevel@tonic-gate  * lock.
887c478bd9Sstevel@tonic-gate  * (Note: It is assumed that the lock_set_spl() uses only bit 0 of the lock.)
897c478bd9Sstevel@tonic-gate  *
907c478bd9Sstevel@tonic-gate  * CLOCK_UNLOCK() increments the lower bytes straight, thus clearing the
917c478bd9Sstevel@tonic-gate  * lock and also incrementing the counter. This way gethrtime()
927c478bd9Sstevel@tonic-gate  * can figure out if the value in the lock got changed or not.
937c478bd9Sstevel@tonic-gate  */
947c478bd9Sstevel@tonic-gate #define	HRES_LOCK_OFFSET 0	/* byte 0 has the lock bit(bit 0 in the byte) */
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate #define	CLOCK_LOCK(oldsplp)	\
977c478bd9Sstevel@tonic-gate 	lock_set_spl((lock_t *)&hres_lock + HRES_LOCK_OFFSET, 	\
987c478bd9Sstevel@tonic-gate 		ipltospl(XC_HI_PIL), oldsplp)
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate #define	CLOCK_UNLOCK(spl)		\
1017c478bd9Sstevel@tonic-gate 	unlock_hres_lock();		\
1027c478bd9Sstevel@tonic-gate 	splx(spl);			\
1037c478bd9Sstevel@tonic-gate 	LOCKSTAT_RECORD0(LS_CLOCK_UNLOCK_RELEASE,	\
1047c478bd9Sstevel@tonic-gate 		(lock_t *)&hres_lock + HRES_LOCK_OFFSET);
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate #endif	/* KERNEL */
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1097c478bd9Sstevel@tonic-gate }
1107c478bd9Sstevel@tonic-gate #endif
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate #endif	/* _SYS_CLOCK_H */
113