1994-09-18 20:40:01 +00:00
|
|
|
/*
|
|
|
|
* Kernel interface to machine-dependent clock driver.
|
|
|
|
* Garrett Wollman, September 1994.
|
|
|
|
* This file is in the public domain.
|
1995-11-29 19:57:22 +00:00
|
|
|
*
|
1998-02-01 22:45:23 +00:00
|
|
|
* $Id: clock.h,v 1.30 1997/12/28 17:33:08 phk Exp $
|
1994-09-18 20:40:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _MACHINE_CLOCK_H_
|
1994-11-05 22:51:17 +00:00
|
|
|
#define _MACHINE_CLOCK_H_
|
1994-09-18 20:40:01 +00:00
|
|
|
|
1996-10-25 13:01:56 +00:00
|
|
|
#define CPU_CLOCKUPDATE(otime, ntime) cpu_clockupdate((otime), (ntime))
|
1994-09-18 20:40:01 +00:00
|
|
|
|
1996-10-25 13:01:56 +00:00
|
|
|
#define CPU_THISTICKLEN(dflt) dflt
|
|
|
|
|
1997-12-26 20:42:37 +00:00
|
|
|
#define TSC_COMULTIPLIER_SHIFT 20
|
|
|
|
#define TSC_MULTIPLIER_SHIFT 32
|
1995-11-29 19:57:22 +00:00
|
|
|
|
1996-10-25 13:01:56 +00:00
|
|
|
#ifdef KERNEL
|
1994-11-05 22:51:17 +00:00
|
|
|
/*
|
|
|
|
* i386 to clock driver interface.
|
|
|
|
* XXX almost all of it is misplaced. i586 stuff is done in isa/clock.c
|
|
|
|
* and isa stuff is done in i386/microtime.s and i386/support.s.
|
|
|
|
*/
|
|
|
|
extern int adjkerntz;
|
|
|
|
extern int disable_rtc_set;
|
1997-12-28 13:36:09 +00:00
|
|
|
extern int statclock_disable;
|
|
|
|
extern u_int timer_freq;
|
|
|
|
extern int timer0_max_count;
|
|
|
|
extern u_int timer0_overflow_threshold;
|
|
|
|
extern u_int timer0_prescaler_count;
|
1997-12-26 20:42:37 +00:00
|
|
|
extern u_int tsc_bias;
|
|
|
|
extern u_int tsc_comultiplier;
|
|
|
|
extern u_int tsc_freq;
|
|
|
|
extern u_int tsc_multiplier;
|
1996-10-17 17:31:25 +00:00
|
|
|
extern int wall_cmos_clock;
|
1994-11-05 22:51:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Driver to clock driver interface.
|
|
|
|
*/
|
1996-10-25 13:01:56 +00:00
|
|
|
struct clockframe;
|
|
|
|
|
1994-11-05 22:51:17 +00:00
|
|
|
void DELAY __P((int usec));
|
|
|
|
int acquire_timer0 __P((int rate,
|
|
|
|
void (*function)(struct clockframe *frame)));
|
|
|
|
int acquire_timer2 __P((int mode));
|
|
|
|
int release_timer0 __P((void));
|
|
|
|
int release_timer2 __P((void));
|
1996-06-14 11:02:28 +00:00
|
|
|
#ifndef PC98
|
1996-03-31 04:05:36 +00:00
|
|
|
int rtcin __P((int val));
|
1996-06-14 11:02:28 +00:00
|
|
|
#else
|
|
|
|
int acquire_timer1 __P((int mode));
|
|
|
|
int release_timer1 __P((void));
|
|
|
|
#endif
|
1994-11-05 22:51:17 +00:00
|
|
|
int sysbeep __P((int pitch, int period));
|
|
|
|
|
1996-10-25 13:01:56 +00:00
|
|
|
#ifdef CLOCK_HAIR
|
|
|
|
|
1996-10-30 22:41:46 +00:00
|
|
|
#ifdef PC98
|
|
|
|
#include <pc98/pc98/pc98.h> /* XXX */
|
|
|
|
#else
|
1996-10-25 13:01:56 +00:00
|
|
|
#include <i386/isa/isa.h> /* XXX */
|
1996-10-30 22:41:46 +00:00
|
|
|
#endif
|
1996-10-25 13:01:56 +00:00
|
|
|
#include <i386/isa/timerreg.h> /* XXX */
|
|
|
|
|
|
|
|
static __inline u_int
|
|
|
|
clock_latency(void)
|
|
|
|
{
|
|
|
|
u_char high, low;
|
|
|
|
|
|
|
|
outb(TIMER_MODE, TIMER_SEL0 | TIMER_LATCH);
|
|
|
|
low = inb(TIMER_CNTR0);
|
|
|
|
high = inb(TIMER_CNTR0);
|
|
|
|
return (timer0_prescaler_count + timer0_max_count
|
|
|
|
- ((high << 8) | low));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1998-02-01 22:45:23 +00:00
|
|
|
* When we update `time', we also update `tsc_bias' atomically (if we
|
|
|
|
* are using the TSC). `tsc_bias' is the best available approximation
|
|
|
|
* to the value of the TSC (mod 2^32) at the time of the i8254
|
1996-10-25 13:01:56 +00:00
|
|
|
* counter transition that caused the clock interrupt that caused the
|
|
|
|
* update. clock_latency() gives the time between the transition and
|
|
|
|
* the update to within a few usec provided another such transition
|
|
|
|
* hasn't occurred. We don't bother checking for counter overflow as
|
|
|
|
* in microtime(), since if it occurs then we're close to losing clock
|
|
|
|
* interrupts.
|
|
|
|
*/
|
|
|
|
static __inline void
|
|
|
|
cpu_clockupdate(volatile struct timeval *otime, struct timeval *ntime)
|
|
|
|
{
|
1997-12-26 20:42:37 +00:00
|
|
|
if (tsc_freq != 0) {
|
1997-12-28 13:36:09 +00:00
|
|
|
u_int tsc_count; /* truncated */
|
1996-10-25 13:01:56 +00:00
|
|
|
u_int i8254_count;
|
|
|
|
|
|
|
|
disable_intr();
|
|
|
|
i8254_count = clock_latency();
|
1997-12-28 13:36:09 +00:00
|
|
|
tsc_count = rdtsc();
|
|
|
|
tsc_bias = tsc_count
|
1996-10-25 13:01:56 +00:00
|
|
|
- (u_int)
|
1997-12-26 20:42:37 +00:00
|
|
|
(((unsigned long long)tsc_comultiplier
|
1996-10-25 13:01:56 +00:00
|
|
|
* i8254_count)
|
1997-12-26 20:42:37 +00:00
|
|
|
>> TSC_COMULTIPLIER_SHIFT);
|
1996-10-25 13:01:56 +00:00
|
|
|
*otime = *ntime;
|
|
|
|
enable_intr();
|
|
|
|
} else
|
|
|
|
*otime = *ntime;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CLOCK_HAIR */
|
|
|
|
|
|
|
|
#endif /* KERNEL */
|
1994-11-05 22:51:17 +00:00
|
|
|
|
|
|
|
#endif /* !_MACHINE_CLOCK_H_ */
|