xref: /titanic_44/usr/src/uts/i86pc/sys/apic_timer.h (revision db8b037b5616a366b7dfdc01ef9552f02f9adfdd)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 /*
25  * Copyright (c) 2010, Intel Corporation.
26  * All rights reserved.
27  */
28 
29 #ifndef _SYS_APIC_TIMER_H
30 #define	_SYS_APIC_TIMER_H
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/time.h>
37 
38 #define	IA32_DEADLINE_TSC_MSR	0x6E0
39 
40 /* Timer Vector Table register	*/
41 #define	APIC_LOCAL_TIMER	0xc8
42 
43 /* timer vector table		*/
44 #define	AV_PERIODIC	0x20000 /* Set timer mode to periodic */
45 #define	AV_DEADLINE	0x40000 /* Set timer mode to deadline */
46 
47 #define	APIC_TIMER_MODE_ONESHOT		0x0
48 #define	APIC_TIMER_MODE_PERIODIC	0x1
49 #define	APIC_TIMER_MODE_DEADLINE	0x2	/* TSC-Deadline timer mode */
50 
51 extern int	apic_oneshot;
52 extern uint_t	apic_nsec_per_intr;
53 extern uint_t	apic_hertz_count;
54 extern uint64_t apic_ticks_per_SFnsecs;
55 
56 /*
57  * Use scaled-fixed-point arithmetic to calculate apic ticks.
58  * Round when dividing (by adding half of divisor to dividend)
59  * for one extra bit of precision.
60  */
61 
62 #define	SF	(1ULL<<20)		/* Scaling Factor: scale by 2^20 */
63 #define	APIC_TICKS_TO_NSECS(ticks)	((((int64_t)(ticks) * SF) + \
64 					apic_ticks_per_SFnsecs / 2) / \
65 					apic_ticks_per_SFnsecs);
66 #define	APIC_NSECS_TO_TICKS(nsecs)	(((int64_t)(nsecs) * \
67 					apic_ticks_per_SFnsecs + (SF/2)) / SF)
68 
69 extern int	apic_timer_init(int);
70 extern void	apic_timer_reprogram(hrtime_t);
71 extern void	apic_timer_enable(void);
72 extern void	apic_timer_disable(void);
73 
74 #ifdef	__cplusplus
75 }
76 #endif
77 
78 #endif	/* _SYS_APIC_TIMER_H */
79