clock.h revision 16363
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.13 1996/05/01 08:38:50 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_rate) { \
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_RATE_SHIFT	8
42
43#if defined(KERNEL) && !defined(LOCORE)
44#include <sys/cdefs.h>
45#include <machine/frame.h>
46
47/*
48 * i386 to clock driver interface.
49 * XXX almost all of it is misplaced.  i586 stuff is done in isa/clock.c
50 * and isa stuff is done in i386/microtime.s and i386/support.s.
51 */
52extern int	adjkerntz;
53extern int	disable_rtc_set;
54extern int	statclock_disable;
55extern int	wall_cmos_clock;
56
57#if defined(I586_CPU) || defined(I686_CPU)
58extern unsigned	i586_ctr_freq;
59extern unsigned	i586_ctr_rate;	/* fixed point */
60extern long long i586_last_tick;
61extern long long i586_ctr_bias;
62extern unsigned long i586_avg_tick;
63#endif
64extern int 	timer0_max_count;
65extern u_int 	timer0_overflow_threshold;
66extern u_int 	timer0_prescaler_count;
67
68
69#if defined(I586_CPU) || defined(I686_CPU)
70static __inline u_long
71cpu_thisticklen(u_long dflt)
72{
73	long long old;
74	long len;
75
76	if (i586_ctr_rate) {
77		old = i586_last_tick;
78		i586_last_tick = rdtsc();
79		len = ((i586_last_tick - old) << I586_CTR_RATE_SHIFT)
80			/ i586_ctr_rate;
81		i586_avg_tick = i586_avg_tick * 15 / 16 + len / 16;
82	}
83	return dflt;
84}
85#endif
86
87/*
88 * Driver to clock driver interface.
89 */
90void	DELAY __P((int usec));
91int	acquire_timer0 __P((int rate,
92			    void (*function)(struct clockframe *frame)));
93int	acquire_timer2 __P((int mode));
94int	release_timer0 __P((void));
95int	release_timer2 __P((void));
96#ifndef PC98
97int	rtcin __P((int val));
98#else
99int	acquire_timer1 __P((int mode));
100int	release_timer1 __P((void));
101void	rtc_serialcombit __P((int i));
102void	rtc_serialcom __P((int i));
103void	rtc_outb __P((int val));
104#endif
105int	sysbeep __P((int pitch, int period));
106
107#endif /* KERNEL && !LOCORE */
108
109#endif /* !_MACHINE_CLOCK_H_ */
110