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