clock.h revision 18842
1/* 2 * Kernel interface to machine-dependent clock driver. 3 * Garrett Wollman, September 1994. 4 * This file is in the public domain. 5 * 6 * $Id: clock.h,v 1.16 1996/08/02 21:16:13 bde Exp $ 7 */ 8 9#ifndef _MACHINE_CLOCK_H_ 10#define _MACHINE_CLOCK_H_ 11 12#include "opt_cpu.h" 13 14#if defined(I586_CPU) || defined(I686_CPU) 15 16/* 17 * When we update the clock, we also update this bias value which is 18 * automatically subtracted in microtime(). We assume that CPU_THISTICKLEN() 19 * has been called at some point in the past, so that an appropriate value is 20 * set up in i586_last_tick. (This works even if we are not being called 21 * from hardclock because hardclock will have run before and will made the 22 * call.) 23 */ 24#define CPU_CLOCKUPDATE(otime, ntime) \ 25 do { \ 26 if (i586_ctr_freq != 0) { \ 27 disable_intr(); \ 28 i586_ctr_bias = i586_last_tick; \ 29 *(otime) = *(ntime); \ 30 enable_intr(); \ 31 } else { \ 32 *(otime) = *(ntime); \ 33 } \ 34 } while(0) 35 36#define CPU_THISTICKLEN(dflt) cpu_thisticklen(dflt) 37#else 38#define CPU_CLOCKUPDATE(otime, ntime) \ 39 (*(otime) = *(ntime)) 40#define CPU_THISTICKLEN(dflt) dflt 41#endif 42 43#define I586_CTR_COMULTIPLIER_SHIFT 20 44#define I586_CTR_MULTIPLIER_SHIFT 32 45 46#if defined(KERNEL) && !defined(LOCORE) 47#include <sys/cdefs.h> 48#include <machine/frame.h> 49 50/* 51 * i386 to clock driver interface. 52 * XXX almost all of it is misplaced. i586 stuff is done in isa/clock.c 53 * and isa stuff is done in i386/microtime.s and i386/support.s. 54 */ 55extern int adjkerntz; 56extern int disable_rtc_set; 57extern int statclock_disable; 58extern int wall_cmos_clock; 59 60#if defined(I586_CPU) || defined(I686_CPU) 61extern u_int i586_ctr_bias; 62extern u_int i586_ctr_comultiplier; 63extern u_int i586_ctr_freq; 64extern u_int i586_ctr_multiplier; 65extern long long i586_last_tick; 66extern unsigned long i586_avg_tick; 67#endif 68extern int timer0_max_count; 69extern u_int timer0_overflow_threshold; 70extern u_int timer0_prescaler_count; 71 72 73#if defined(I586_CPU) || defined(I686_CPU) 74static __inline u_long 75cpu_thisticklen(u_long dflt) 76{ 77 long long old; 78 long len; 79 80 if (i586_ctr_freq != 0) { 81 old = i586_last_tick; 82 i586_last_tick = rdtsc(); 83 len = ((i586_last_tick - old) * i586_ctr_multiplier) 84 >> I586_CTR_MULTIPLIER_SHIFT; 85 i586_avg_tick = i586_avg_tick * 15 / 16 + len / 16; 86 } 87 return dflt; 88} 89#endif 90 91/* 92 * Driver to clock driver interface. 93 */ 94void DELAY __P((int usec)); 95int acquire_timer0 __P((int rate, 96 void (*function)(struct clockframe *frame))); 97int acquire_timer2 __P((int mode)); 98int release_timer0 __P((void)); 99int release_timer2 __P((void)); 100#ifndef PC98 101int rtcin __P((int val)); 102#else 103int acquire_timer1 __P((int mode)); 104int release_timer1 __P((void)); 105void rtc_serialcombit __P((int i)); 106void rtc_serialcom __P((int i)); 107void rtc_outb __P((int val)); 108#endif 109int sysbeep __P((int pitch, int period)); 110 111#endif /* KERNEL && !LOCORE */ 112 113#endif /* !_MACHINE_CLOCK_H_ */ 114