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 5*ae115bc7Smrj * Common Development and Distribution License (the "License"). 6*ae115bc7Smrj * 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 /* 22*ae115bc7Smrj * 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 45*ae115bc7Smrj #include <sys/machclock.h> 46*ae115bc7Smrj 47*ae115bc7Smrj extern time_t ggmtl(void); 48*ae115bc7Smrj extern void sgmtl(time_t); 49*ae115bc7Smrj 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 557c478bd9Sstevel@tonic-gate extern void tsc_hrtimeinit(uint64_t cpu_freq_hz); 567c478bd9Sstevel@tonic-gate extern hrtime_t tsc_gethrtime(void); 577c478bd9Sstevel@tonic-gate extern hrtime_t tsc_gethrtime_delta(void); 587c478bd9Sstevel@tonic-gate extern hrtime_t tsc_gethrtimeunscaled(void); 597c478bd9Sstevel@tonic-gate extern void tsc_scalehrtime(hrtime_t *); 607c478bd9Sstevel@tonic-gate extern hrtime_t tsc_gethrtimeunscaled_delta(void); 617c478bd9Sstevel@tonic-gate extern void tsc_tick(void); 627c478bd9Sstevel@tonic-gate extern void tsc_sync_master(processorid_t); 637c478bd9Sstevel@tonic-gate extern void tsc_sync_slave(void); 647c478bd9Sstevel@tonic-gate extern hrtime_t tsc_read(void); 65*ae115bc7Smrj extern hrtime_t __rdtsc_insn(void); 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate #define ADJ_SHIFT 4 /* used in get_hrestime */ 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate #define YRBASE 00 /* 1900 - what year 0 in chip represents */ 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate #endif /* !_ASM */ 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate #define CBE_HIGH_PIL 14 747c478bd9Sstevel@tonic-gate #define CBE_LOCK_PIL LOCK_LEVEL 757c478bd9Sstevel@tonic-gate #define CBE_LOW_PIL 2 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate /* 787c478bd9Sstevel@tonic-gate * CLOCK_LOCK() sets the LSB (bit 0) of the hres_lock. The rest of the 797c478bd9Sstevel@tonic-gate * 31bits are used as the counter. This lock is acquired 807c478bd9Sstevel@tonic-gate * around "hrestime" and "timedelta". This lock is acquired to make 817c478bd9Sstevel@tonic-gate * sure that level-14 accounts for changes to this variable in that 827c478bd9Sstevel@tonic-gate * interrupt itself. The level-14 interrupt code also acquires this 837c478bd9Sstevel@tonic-gate * lock. 847c478bd9Sstevel@tonic-gate * (Note: It is assumed that the lock_set_spl() uses only bit 0 of the lock.) 857c478bd9Sstevel@tonic-gate * 867c478bd9Sstevel@tonic-gate * CLOCK_UNLOCK() increments the lower bytes straight, thus clearing the 877c478bd9Sstevel@tonic-gate * lock and also incrementing the counter. This way gethrtime() 887c478bd9Sstevel@tonic-gate * can figure out if the value in the lock got changed or not. 897c478bd9Sstevel@tonic-gate */ 907c478bd9Sstevel@tonic-gate #define HRES_LOCK_OFFSET 0 /* byte 0 has the lock bit(bit 0 in the byte) */ 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate #define CLOCK_LOCK(oldsplp) \ 937c478bd9Sstevel@tonic-gate lock_set_spl((lock_t *)&hres_lock + HRES_LOCK_OFFSET, \ 947c478bd9Sstevel@tonic-gate ipltospl(XC_HI_PIL), oldsplp) 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate #define CLOCK_UNLOCK(spl) \ 977c478bd9Sstevel@tonic-gate unlock_hres_lock(); \ 987c478bd9Sstevel@tonic-gate splx(spl); \ 997c478bd9Sstevel@tonic-gate LOCKSTAT_RECORD0(LS_CLOCK_UNLOCK_RELEASE, \ 1007c478bd9Sstevel@tonic-gate (lock_t *)&hres_lock + HRES_LOCK_OFFSET); 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate #endif /* KERNEL */ 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1057c478bd9Sstevel@tonic-gate } 1067c478bd9Sstevel@tonic-gate #endif 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate #endif /* _SYS_CLOCK_H */ 109