xref: /illumos-gate/usr/src/uts/i86pc/sys/apic_timer.h (revision 21bcbe6e)
141afdfa7SKrishnendu Sadhukhan - Sun Microsystems /*
241afdfa7SKrishnendu Sadhukhan - Sun Microsystems  * CDDL HEADER START
341afdfa7SKrishnendu Sadhukhan - Sun Microsystems  *
441afdfa7SKrishnendu Sadhukhan - Sun Microsystems  * The contents of this file are subject to the terms of the
541afdfa7SKrishnendu Sadhukhan - Sun Microsystems  * Common Development and Distribution License (the "License").
641afdfa7SKrishnendu Sadhukhan - Sun Microsystems  * You may not use this file except in compliance with the License.
741afdfa7SKrishnendu Sadhukhan - Sun Microsystems  *
841afdfa7SKrishnendu Sadhukhan - Sun Microsystems  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
941afdfa7SKrishnendu Sadhukhan - Sun Microsystems  * or http://www.opensolaris.org/os/licensing.
1041afdfa7SKrishnendu Sadhukhan - Sun Microsystems  * See the License for the specific language governing permissions
1141afdfa7SKrishnendu Sadhukhan - Sun Microsystems  * and limitations under the License.
1241afdfa7SKrishnendu Sadhukhan - Sun Microsystems  *
1341afdfa7SKrishnendu Sadhukhan - Sun Microsystems  * When distributing Covered Code, include this CDDL HEADER in each
1441afdfa7SKrishnendu Sadhukhan - Sun Microsystems  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1541afdfa7SKrishnendu Sadhukhan - Sun Microsystems  * If applicable, add the following below this CDDL HEADER, with the
1641afdfa7SKrishnendu Sadhukhan - Sun Microsystems  * fields enclosed by brackets "[]" replaced with your own identifying
1741afdfa7SKrishnendu Sadhukhan - Sun Microsystems  * information: Portions Copyright [yyyy] [name of copyright owner]
1841afdfa7SKrishnendu Sadhukhan - Sun Microsystems  *
1941afdfa7SKrishnendu Sadhukhan - Sun Microsystems  * CDDL HEADER END
2041afdfa7SKrishnendu Sadhukhan - Sun Microsystems  */
2141afdfa7SKrishnendu Sadhukhan - Sun Microsystems /*
2241afdfa7SKrishnendu Sadhukhan - Sun Microsystems  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2341afdfa7SKrishnendu Sadhukhan - Sun Microsystems  */
2441afdfa7SKrishnendu Sadhukhan - Sun Microsystems /*
2541afdfa7SKrishnendu Sadhukhan - Sun Microsystems  * Copyright (c) 2010, Intel Corporation.
2641afdfa7SKrishnendu Sadhukhan - Sun Microsystems  * All rights reserved.
27*21bcbe6eSJason King  *
28*21bcbe6eSJason King  * Copyright 2020 Joyent, Inc.
2941afdfa7SKrishnendu Sadhukhan - Sun Microsystems  */
3041afdfa7SKrishnendu Sadhukhan - Sun Microsystems 
3141afdfa7SKrishnendu Sadhukhan - Sun Microsystems #ifndef _SYS_APIC_TIMER_H
3241afdfa7SKrishnendu Sadhukhan - Sun Microsystems #define	_SYS_APIC_TIMER_H
3341afdfa7SKrishnendu Sadhukhan - Sun Microsystems 
3441afdfa7SKrishnendu Sadhukhan - Sun Microsystems #ifdef	__cplusplus
3541afdfa7SKrishnendu Sadhukhan - Sun Microsystems extern "C" {
3641afdfa7SKrishnendu Sadhukhan - Sun Microsystems #endif
3741afdfa7SKrishnendu Sadhukhan - Sun Microsystems 
3841afdfa7SKrishnendu Sadhukhan - Sun Microsystems #include <sys/time.h>
3941afdfa7SKrishnendu Sadhukhan - Sun Microsystems 
4041afdfa7SKrishnendu Sadhukhan - Sun Microsystems #define	IA32_DEADLINE_TSC_MSR	0x6E0
4141afdfa7SKrishnendu Sadhukhan - Sun Microsystems 
4241afdfa7SKrishnendu Sadhukhan - Sun Microsystems /* Timer Vector Table register	*/
4341afdfa7SKrishnendu Sadhukhan - Sun Microsystems #define	APIC_LOCAL_TIMER	0xc8
4441afdfa7SKrishnendu Sadhukhan - Sun Microsystems 
4541afdfa7SKrishnendu Sadhukhan - Sun Microsystems /* timer vector table		*/
4641afdfa7SKrishnendu Sadhukhan - Sun Microsystems #define	AV_PERIODIC	0x20000 /* Set timer mode to periodic */
4741afdfa7SKrishnendu Sadhukhan - Sun Microsystems #define	AV_DEADLINE	0x40000 /* Set timer mode to deadline */
4841afdfa7SKrishnendu Sadhukhan - Sun Microsystems 
4941afdfa7SKrishnendu Sadhukhan - Sun Microsystems #define	APIC_TIMER_MODE_ONESHOT		0x0
5041afdfa7SKrishnendu Sadhukhan - Sun Microsystems #define	APIC_TIMER_MODE_PERIODIC	0x1
5141afdfa7SKrishnendu Sadhukhan - Sun Microsystems #define	APIC_TIMER_MODE_DEADLINE	0x2	/* TSC-Deadline timer mode */
5241afdfa7SKrishnendu Sadhukhan - Sun Microsystems 
5341afdfa7SKrishnendu Sadhukhan - Sun Microsystems extern int	apic_oneshot;
5441afdfa7SKrishnendu Sadhukhan - Sun Microsystems extern uint_t	apic_nsec_per_intr;
5541afdfa7SKrishnendu Sadhukhan - Sun Microsystems extern uint_t	apic_hertz_count;
5641afdfa7SKrishnendu Sadhukhan - Sun Microsystems extern uint64_t apic_ticks_per_SFnsecs;
5741afdfa7SKrishnendu Sadhukhan - Sun Microsystems 
5841afdfa7SKrishnendu Sadhukhan - Sun Microsystems /*
5941afdfa7SKrishnendu Sadhukhan - Sun Microsystems  * Use scaled-fixed-point arithmetic to calculate apic ticks.
6041afdfa7SKrishnendu Sadhukhan - Sun Microsystems  * Round when dividing (by adding half of divisor to dividend)
6141afdfa7SKrishnendu Sadhukhan - Sun Microsystems  * for one extra bit of precision.
6241afdfa7SKrishnendu Sadhukhan - Sun Microsystems  */
6341afdfa7SKrishnendu Sadhukhan - Sun Microsystems 
6441afdfa7SKrishnendu Sadhukhan - Sun Microsystems #define	SF	(1ULL<<20)		/* Scaling Factor: scale by 2^20 */
6541afdfa7SKrishnendu Sadhukhan - Sun Microsystems #define	APIC_TICKS_TO_NSECS(ticks)	((((int64_t)(ticks) * SF) + \
6641afdfa7SKrishnendu Sadhukhan - Sun Microsystems 					apic_ticks_per_SFnsecs / 2) / \
6741afdfa7SKrishnendu Sadhukhan - Sun Microsystems 					apic_ticks_per_SFnsecs);
6841afdfa7SKrishnendu Sadhukhan - Sun Microsystems #define	APIC_NSECS_TO_TICKS(nsecs)	(((int64_t)(nsecs) * \
6941afdfa7SKrishnendu Sadhukhan - Sun Microsystems 					apic_ticks_per_SFnsecs + (SF/2)) / SF)
7041afdfa7SKrishnendu Sadhukhan - Sun Microsystems 
7141afdfa7SKrishnendu Sadhukhan - Sun Microsystems extern int	apic_timer_init(int);
7241afdfa7SKrishnendu Sadhukhan - Sun Microsystems extern void	apic_timer_reprogram(hrtime_t);
7341afdfa7SKrishnendu Sadhukhan - Sun Microsystems extern void	apic_timer_enable(void);
7441afdfa7SKrishnendu Sadhukhan - Sun Microsystems extern void	apic_timer_disable(void);
7541afdfa7SKrishnendu Sadhukhan - Sun Microsystems 
76*21bcbe6eSJason King extern hrtime_t	apic_timer_stop_count(void);
77*21bcbe6eSJason King extern void	apic_timer_restart(hrtime_t);
78*21bcbe6eSJason King 
7941afdfa7SKrishnendu Sadhukhan - Sun Microsystems #ifdef	__cplusplus
8041afdfa7SKrishnendu Sadhukhan - Sun Microsystems }
8141afdfa7SKrishnendu Sadhukhan - Sun Microsystems #endif
8241afdfa7SKrishnendu Sadhukhan - Sun Microsystems 
8341afdfa7SKrishnendu Sadhukhan - Sun Microsystems #endif	/* _SYS_APIC_TIMER_H */
84