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 extern void tsc_hrtimeinit(uint64_t cpu_freq_hz); 56 extern hrtime_t tsc_gethrtime(void); 57 extern hrtime_t tsc_gethrtime_delta(void); 58 extern hrtime_t tsc_gethrtimeunscaled(void); 59 extern void tsc_scalehrtime(hrtime_t *); 60 extern hrtime_t tsc_gethrtimeunscaled_delta(void); 61 extern void tsc_tick(void); 62 extern void tsc_sync_master(processorid_t); 63 extern void tsc_sync_slave(void); 64 extern hrtime_t tsc_read(void); 65 extern hrtime_t __rdtsc_insn(void); 66 67 #define ADJ_SHIFT 4 /* used in get_hrestime */ 68 69 #define YRBASE 00 /* 1900 - what year 0 in chip represents */ 70 71 #endif /* !_ASM */ 72 73 #define CBE_HIGH_PIL 14 74 #define CBE_LOCK_PIL LOCK_LEVEL 75 #define CBE_LOW_PIL 2 76 77 /* 78 * CLOCK_LOCK() sets the LSB (bit 0) of the hres_lock. The rest of the 79 * 31bits are used as the counter. This lock is acquired 80 * around "hrestime" and "timedelta". This lock is acquired to make 81 * sure that level-14 accounts for changes to this variable in that 82 * interrupt itself. The level-14 interrupt code also acquires this 83 * lock. 84 * (Note: It is assumed that the lock_set_spl() uses only bit 0 of the lock.) 85 * 86 * CLOCK_UNLOCK() increments the lower bytes straight, thus clearing the 87 * lock and also incrementing the counter. This way gethrtime() 88 * can figure out if the value in the lock got changed or not. 89 */ 90 #define HRES_LOCK_OFFSET 0 /* byte 0 has the lock bit(bit 0 in the byte) */ 91 92 #define CLOCK_LOCK(oldsplp) \ 93 lock_set_spl((lock_t *)&hres_lock + HRES_LOCK_OFFSET, \ 94 ipltospl(XC_HI_PIL), oldsplp) 95 96 #define CLOCK_UNLOCK(spl) \ 97 unlock_hres_lock(); \ 98 splx(spl); \ 99 LOCKSTAT_RECORD0(LS_CLOCK_UNLOCK_RELEASE, \ 100 (lock_t *)&hres_lock + HRES_LOCK_OFFSET); 101 102 #endif /* KERNEL */ 103 104 #ifdef __cplusplus 105 } 106 #endif 107 108 #endif /* _SYS_CLOCK_H */ 109