xref: /freebsd/sys/amd64/include/clock.h (revision a316b26e50bbed7cf655fbba726ab87d8ab7599d)
1 /*
2  * Kernel interface to machine-dependent clock driver.
3  * Garrett Wollman, September 1994.
4  * This file is in the public domain.
5  */
6 
7 #ifndef _MACHINE_CLOCK_H_
8 #define	_MACHINE_CLOCK_H_
9 
10 #ifdef I586_CPU
11 	/*
12 	 * This resets the CPU cycle counter to zero, to make our
13 	 * job easier in microtime().  Some fancy ifdefs could speed
14 	 * this up for Pentium-only kernels.
15 	 * We want this to be done as close as possible to the actual
16 	 * timer incrementing in hardclock(), because there is a window
17 	 * between the two where the value is no longer valid.  Experimentation
18 	 * may reveal a good precompensation to apply in microtime().
19 	 */
20 #define CPU_CLOCKUPDATE(otime, ntime) \
21 	do { \
22 	if(pentium_mhz) { \
23 		__asm __volatile("cli\n" \
24 				 "movl (%2),%%eax\n" \
25 				 "movl %%eax,(%1)\n" \
26 				 "movl 4(%2),%%eax\n" \
27 				 "movl %%eax,4(%1)\n" \
28 				 "movl $0x10,%%ecx\n" \
29 				 "xorl %%eax,%%eax\n" \
30 				 "movl %%eax,%%edx\n" \
31 				 ".byte 0x0f, 0x30\n" \
32 				 "sti\n" \
33 				 "#%0%1%2" \
34 				 : "=m"(*otime)	/* no outputs */ \
35 				 : "c"(otime), "b"(ntime) /* fake input */ \
36 				 : "ax", "cx", "dx"); \
37 	} else { \
38 		*(otime) = *(ntime); \
39 	} \
40 	} while(0)
41 
42 #else
43 #define CPU_CLOCKUPDATE(otime, ntime) \
44 		(*(otime) = *(ntime))
45 #endif
46 
47 #if defined(KERNEL) && !defined(LOCORE)
48 #include <sys/cdefs.h>
49 #include <machine/frame.h>
50 
51 /*
52  * Kernel to clock driver interface.
53  */
54 void	inittodr __P((time_t base));
55 void	resettodr __P((void));
56 void	startrtclock __P((void));
57 
58 /*
59  * i386 to clock driver interface.
60  * XXX almost all of it is misplaced.  i586 stuff is done in isa/clock.c
61  * and isa stuff is done in i386/microtime.s and i386/support.s.
62  */
63 extern int	adjkerntz;
64 extern int	disable_rtc_set;
65 #ifdef I586_CPU
66 extern int	pentium_mhz;
67 #endif
68 extern int 	timer0_max_count;
69 extern u_int 	timer0_overflow_threshold;
70 extern u_int 	timer0_prescaler_count;
71 
72 #ifdef I586_CPU
73 void	calibrate_cyclecounter __P((void));
74 #endif
75 void	clkintr __P((struct clockframe frame));
76 void	rtcintr __P((struct clockframe frame));
77 
78 /*
79  * Driver to clock driver interface.
80  */
81 void	DELAY __P((int usec));
82 int	acquire_timer0 __P((int rate,
83 			    void (*function)(struct clockframe *frame)));
84 int	acquire_timer2 __P((int mode));
85 int	release_timer0 __P((void));
86 int	release_timer2 __P((void));
87 int	sysbeep __P((int pitch, int period));
88 
89 #endif /* KERNEL && !LOCORE */
90 
91 #endif /* !_MACHINE_CLOCK_H_ */
92