xref: /illumos-gate/usr/src/uts/i86pc/sys/apic_timer.h (revision 21bcbe6e4903d8521ec66863bf0c21d9ed378cff)
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  * Copyright 2020 Joyent, Inc.
29  */
30 
31 #ifndef _SYS_APIC_TIMER_H
32 #define	_SYS_APIC_TIMER_H
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 #include <sys/time.h>
39 
40 #define	IA32_DEADLINE_TSC_MSR	0x6E0
41 
42 /* Timer Vector Table register	*/
43 #define	APIC_LOCAL_TIMER	0xc8
44 
45 /* timer vector table		*/
46 #define	AV_PERIODIC	0x20000 /* Set timer mode to periodic */
47 #define	AV_DEADLINE	0x40000 /* Set timer mode to deadline */
48 
49 #define	APIC_TIMER_MODE_ONESHOT		0x0
50 #define	APIC_TIMER_MODE_PERIODIC	0x1
51 #define	APIC_TIMER_MODE_DEADLINE	0x2	/* TSC-Deadline timer mode */
52 
53 extern int	apic_oneshot;
54 extern uint_t	apic_nsec_per_intr;
55 extern uint_t	apic_hertz_count;
56 extern uint64_t apic_ticks_per_SFnsecs;
57 
58 /*
59  * Use scaled-fixed-point arithmetic to calculate apic ticks.
60  * Round when dividing (by adding half of divisor to dividend)
61  * for one extra bit of precision.
62  */
63 
64 #define	SF	(1ULL<<20)		/* Scaling Factor: scale by 2^20 */
65 #define	APIC_TICKS_TO_NSECS(ticks)	((((int64_t)(ticks) * SF) + \
66 					apic_ticks_per_SFnsecs / 2) / \
67 					apic_ticks_per_SFnsecs);
68 #define	APIC_NSECS_TO_TICKS(nsecs)	(((int64_t)(nsecs) * \
69 					apic_ticks_per_SFnsecs + (SF/2)) / SF)
70 
71 extern int	apic_timer_init(int);
72 extern void	apic_timer_reprogram(hrtime_t);
73 extern void	apic_timer_enable(void);
74 extern void	apic_timer_disable(void);
75 
76 extern hrtime_t	apic_timer_stop_count(void);
77 extern void	apic_timer_restart(hrtime_t);
78 
79 #ifdef	__cplusplus
80 }
81 #endif
82 
83 #endif	/* _SYS_APIC_TIMER_H */
84