clock.h revision 18855
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.17 1996/10/09 19:47: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;
55extern int	statclock_disable;
56extern int	wall_cmos_clock;
57
58#if defined(I586_CPU) || defined(I686_CPU)
59extern u_int	i586_ctr_bias;
60extern u_int	i586_ctr_comultiplier;
61extern u_int	i586_ctr_freq;
62extern u_int	i586_ctr_multiplier;
63extern long long i586_last_tick;
64extern unsigned long i586_avg_tick;
65#endif
66extern int 	timer0_max_count;
67extern u_int 	timer0_overflow_threshold;
68extern u_int 	timer0_prescaler_count;
69
70
71#if defined(I586_CPU) || defined(I686_CPU)
72static __inline u_long
73cpu_thisticklen(u_long dflt)
74{
75	long long old;
76	long len;
77
78	if (i586_ctr_freq != 0) {
79		old = i586_last_tick;
80		i586_last_tick = rdtsc();
81		len = ((i586_last_tick - old) * i586_ctr_multiplier)
82			>> I586_CTR_MULTIPLIER_SHIFT;
83		i586_avg_tick = i586_avg_tick * 15 / 16 + len / 16;
84	}
85	return dflt;
86}
87#endif
88
89/*
90 * Driver to clock driver interface.
91 */
92void	DELAY __P((int usec));
93int	acquire_timer0 __P((int rate,
94			    void (*function)(struct clockframe *frame)));
95int	acquire_timer2 __P((int mode));
96int	release_timer0 __P((void));
97int	release_timer2 __P((void));
98#ifndef PC98
99int	rtcin __P((int val));
100#else
101int	acquire_timer1 __P((int mode));
102int	release_timer1 __P((void));
103void	rtc_serialcombit __P((int i));
104void	rtc_serialcom __P((int i));
105void	rtc_outb __P((int val));
106#endif
107int	sysbeep __P((int pitch, int period));
108
109#endif /* KERNEL && !LOCORE */
110
111#endif /* !_MACHINE_CLOCK_H_ */
112