xref: /freebsd/sys/i386/include/clock.h (revision 48991a368427cadb9cdac39581d1676c29619c52)
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$
7  */
8 
9 #ifndef _MACHINE_CLOCK_H_
10 #define	_MACHINE_CLOCK_H_
11 
12 #ifdef I586_CPU
13 
14 #define I586_CYCLECTR(x) \
15 	__asm __volatile(".byte 0x0f, 0x31" : "=A" (x))
16 
17 /*
18  * When we update the clock, we also update this bias value which is
19  * automatically subtracted in microtime().  We assume that CPU_THISTICKLEN()
20  * has been called at some point in the past, so that an appropriate value is
21  * set up in i586_last_tick.  (This works even if we are not being called
22  * from hardclock because hardclock will have run before and will made the
23  * call.)
24  */
25 #define CPU_CLOCKUPDATE(otime, ntime) \
26 	do { \
27 	if(i586_ctr_rate) { \
28 		disable_intr(); \
29 		i586_ctr_bias = i586_last_tick; \
30 		*(otime) = *(ntime); \
31 		enable_intr(); \
32 	} else { \
33 		*(otime) = *(ntime); \
34 	} \
35 	} while(0)
36 
37 #define	CPU_THISTICKLEN(dflt) cpu_thisticklen(dflt)
38 #else
39 #define CPU_CLOCKUPDATE(otime, ntime) \
40 		(*(otime) = *(ntime))
41 #define CPU_THISTICKLEN(dflt) dflt
42 #endif
43 
44 #define		I586_CTR_RATE_SHIFT	8
45 
46 #if defined(KERNEL) && !defined(LOCORE)
47 #include <sys/cdefs.h>
48 #include <machine/frame.h>
49 
50 /*
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  */
55 extern int	adjkerntz;
56 extern int	disable_rtc_set;
57 #ifdef I586_CPU
58 extern unsigned	i586_ctr_rate;	/* fixed point */
59 extern long long i586_last_tick;
60 extern long long i586_ctr_bias;
61 #endif
62 extern int 	timer0_max_count;
63 extern u_int 	timer0_overflow_threshold;
64 extern u_int 	timer0_prescaler_count;
65 
66 #ifdef I586_CPU
67 void	calibrate_cyclecounter __P((void));
68 #endif
69 void	clkintr __P((struct clockframe frame));
70 void	rtcintr __P((struct clockframe frame));
71 
72 #ifdef I586_CPU
73 static __inline u_long
74 cpu_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  */
94 void	DELAY __P((int usec));
95 int	acquire_timer0 __P((int rate,
96 			    void (*function)(struct clockframe *frame)));
97 int	acquire_timer2 __P((int mode));
98 int	release_timer0 __P((void));
99 int	release_timer2 __P((void));
100 int	sysbeep __P((int pitch, int period));
101 
102 #endif /* KERNEL && !LOCORE */
103 
104 #endif /* !_MACHINE_CLOCK_H_ */
105