clock.h revision 17353
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.14 1996/06/14 11:00:56 asami 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_COMULTIPLIER_SHIFT	20
42#define	I586_CTR_MULTIPLIER_SHIFT	32
43#define		I586_CTR_RATE_SHIFT	8
44
45#if defined(KERNEL) && !defined(LOCORE)
46#include <sys/cdefs.h>
47#include <machine/frame.h>
48
49/*
50 * i386 to clock driver interface.
51 * XXX almost all of it is misplaced.  i586 stuff is done in isa/clock.c
52 * and isa stuff is done in i386/microtime.s and i386/support.s.
53 */
54extern int	adjkerntz;
55extern int	disable_rtc_set;
56extern int	statclock_disable;
57extern int	wall_cmos_clock;
58
59#if defined(I586_CPU) || defined(I686_CPU)
60extern u_int	i586_ctr_comultiplier;
61extern u_int	i586_ctr_freq;
62extern u_int	i586_ctr_multiplier;
63extern unsigned	i586_ctr_rate;	/* fixed point */
64extern long long i586_last_tick;
65extern long long i586_ctr_bias;
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_rate) {
81		old = i586_last_tick;
82		i586_last_tick = rdtsc();
83		len = ((i586_last_tick - old) << I586_CTR_RATE_SHIFT)
84			/ i586_ctr_rate;
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