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