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