xref: /xnu-11215.81.4/osfmk/i386/hpet.h (revision d4514f0bc1d3f944c22d92e68b646ac3fb40d452)
1 /*
2  * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
6  * This file contains Original Code and/or Modifications of Original Code
7  * as defined in and that are subject to the Apple Public Source License
8  * Version 2.0 (the 'License'). You may not use this file except in
9  * compliance with the License. The rights granted to you under the License
10  * may not be used to create, or enable the creation or redistribution of,
11  * unlawful or unlicensed copies of an Apple operating system, or to
12  * circumvent, violate, or enable the circumvention or violation of, any
13  * terms of an Apple operating system software license agreement.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
18  * The Original Code and all software distributed under the License are
19  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23  * Please see the License for the specific language governing rights and
24  * limitations under the License.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27  */
28 #ifdef KERNEL_PRIVATE
29 #ifndef _I386_HPET_H_
30 #define _I386_HPET_H_
31 
32 /*
33  * HPET kernel functions to support the HPET KEXT and the
34  * power management KEXT.
35  */
36 
37 
38 /*
39  *	Memory mapped registers for the HPET
40  */
41 typedef struct hpetReg {
42 	uint64_t        GCAP_ID;                /* General capabilities */
43 	uint64_t        rsv1;
44 	uint64_t        GEN_CONF;               /* General configuration */
45 	uint64_t        rsv2;
46 	uint64_t        GINTR_STA;              /* General Interrupt status */
47 	uint64_t        rsv3[25];
48 	uint64_t        MAIN_CNT;               /* Main counter */
49 	uint64_t        rsv4;
50 	uint64_t        TIM0_CONF;              /* Timer 0 config and cap */
51 #define                 TIM_CONF 0
52 #define                 Tn_INT_ENB_CNF 4
53 	uint64_t        TIM0_COMP;              /* Timer 0 comparator */
54 #define                 TIM_COMP 8
55 	uint64_t        rsv5[2];
56 	uint64_t        TIM1_CONF;              /* Timer 1 config and cap */
57 	uint64_t        TIM1_COMP;              /* Timer 1 comparator */
58 	uint64_t        rsv6[2];
59 	uint64_t        TIM2_CONF;              /* Timer 2 config and cap */
60 	uint64_t        TIM2_COMP;              /* Timer 2 comparator */
61 	uint64_t        rsv7[2];
62 } hpetReg;
63 typedef struct  hpetReg hpetReg_t;
64 
65 typedef struct hpetTimer {
66 	uint64_t        Config;         /* Timer config and capabilities */
67 	uint64_t        Compare;        /* Timer comparitor */
68 } hpetTimer_t;
69 
70 struct hpetInfo {
71 	uint64_t        hpetCvtt2n;
72 	uint64_t        hpetCvtn2t;
73 	uint64_t        tsc2hpet;
74 	uint64_t        hpet2tsc;
75 	uint64_t        bus2hpet;
76 	uint64_t        hpet2bus;
77 	uint32_t        rcbaArea;
78 	uint32_t        rcbaAreap;
79 };
80 typedef struct hpetInfo hpetInfo_t;
81 
82 struct hpetRequest {
83 	uint32_t        flags;
84 	uint32_t        hpetOffset;
85 	uint32_t        hpetVector;
86 };
87 typedef struct hpetRequest hpetRequest_t;
88 
89 #define HPET_REQFL_64BIT        0x00000001      /* Timer is 64 bits */
90 
91 extern uint64_t hpetFemto;
92 extern uint64_t hpetFreq;
93 extern uint64_t hpetCvtt2n;
94 extern uint64_t hpetCvtn2t;
95 extern uint64_t tsc2hpet;
96 extern uint64_t hpet2tsc;
97 extern uint64_t bus2hpet;
98 extern uint64_t hpet2bus;
99 
100 extern vm_offset_t rcbaArea;
101 extern uint32_t rcbaAreap;
102 
103 extern void map_rcbaAread(void);
104 extern void hpet_init(void);
105 
106 extern void hpet_save(void);
107 extern void hpet_restore(void);
108 
109 #ifdef XNU_KERNEL_PRIVATE
110 extern int HPETInterrupt(void);
111 #endif
112 
113 extern int hpet_register_callback(int (*hpet_reqst)(uint32_t apicid, void *arg, hpetRequest_t *hpet), void *arg);
114 extern int hpet_request(uint32_t cpu);
115 
116 extern uint64_t rdHPET(void);
117 extern void hpet_get_info(hpetInfo_t *info);
118 
119 #define hpetAddr        0xFED00000
120 #define hptcAE          0x80
121 
122 #endif  /* _I386_HPET_H_ */
123 
124 #endif  /* KERNEL_PRIVATE */
125