clock.h revision 12533
12858Swollman/*
22858Swollman * Kernel interface to machine-dependent clock driver.
32858Swollman * Garrett Wollman, September 1994.
42858Swollman * This file is in the public domain.
512533Swollman *
650477Speter *	$Id$
72858Swollman */
82858Swollman
92858Swollman#ifndef _MACHINE_CLOCK_H_
104174Sbde#define	_MACHINE_CLOCK_H_
112858Swollman
1219172Sbde#ifdef I586_CPU
134174Sbde
144174Sbde#define I586_CYCLECTR(x) \
1533809Sbde	__asm __volatile(".byte 0x0f, 0x31" : "=A" (x))
164174Sbde
174174Sbde/*
184174Sbde * When we update the clock, we also update this bias value which is
1932052Sphk * automatically subtracted in microtime().  We assume that CPU_THISTICKLEN()
2032052Sphk * has been called at some point in the past, so that an appropriate value is
2132052Sphk * set up in i586_last_tick.  (This works even if we are not being called
2232005Sphk * from hardclock because hardclock will have run before and will made the
2347592Sphk * call.)
2418992Sbde */
2534058Stegge#define CPU_CLOCKUPDATE(otime, ntime) \
2634058Stegge	do { \
2734058Stegge	if(i586_ctr_rate) { \
284174Sbde		disable_intr(); \
294174Sbde		i586_ctr_bias = i586_last_tick; \
304174Sbde		*(otime) = *(ntime); \
314174Sbde		enable_intr(); \
3219172Sbde	} else { \
3319172Sbde		*(otime) = *(ntime); \
344174Sbde	} \
354174Sbde	} while(0)
364174Sbde
374174Sbde#define	CPU_THISTICKLEN(dflt) cpu_thisticklen(dflt)
384174Sbde#else
394174Sbde#define CPU_CLOCKUPDATE(otime, ntime) \
4016363Sasami		(*(otime) = *(ntime))
4114943Sbde#define CPU_THISTICKLEN(dflt) dflt
4216363Sasami#endif
4316363Sasami
4416363Sasami#define		I586_CTR_RATE_SHIFT	8
4516363Sasami
464174Sbde#if defined(KERNEL) && !defined(LOCORE)
474174Sbde#include <sys/cdefs.h>
4819172Sbde#include <machine/frame.h>
4919172Sbde
504174Sbde/*
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;
57#ifdef I586_CPU
58extern unsigned	i586_ctr_rate;	/* fixed point */
59extern long long i586_last_tick;
60extern long long i586_ctr_bias;
61#endif
62extern int 	timer0_max_count;
63extern u_int 	timer0_overflow_threshold;
64extern u_int 	timer0_prescaler_count;
65
66#ifdef I586_CPU
67void	calibrate_cyclecounter __P((void));
68#endif
69void	clkintr __P((struct clockframe frame));
70void	rtcintr __P((struct clockframe frame));
71
72#ifdef I586_CPU
73static __inline u_long
74cpu_thisticklen(u_long dflt)
75{
76	long long old;
77	long rv;
78
79	if (i586_ctr_rate) {
80		old = i586_last_tick;
81		I586_CYCLECTR(i586_last_tick);
82		rv = ((i586_last_tick - old) << I586_CTR_RATE_SHIFT)
83			/ i586_ctr_rate;
84	} else {
85		rv = dflt;
86	}
87	return rv;
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));
100int	sysbeep __P((int pitch, int period));
101
102#endif /* KERNEL && !LOCORE */
103
104#endif /* !_MACHINE_CLOCK_H_ */
105