]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/pmCPU.h
xnu-792.18.15.tar.gz
[apple/xnu.git] / osfmk / i386 / pmCPU.h
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_PMCPU_H_
30 #define _I386_PMCPU_H_
31
32 #include <kern/pms.h>
33
34 #ifndef ASSEMBLER
35
36 typedef enum { C1, C2, C3, C4, Hlt, C3Res, All, Cnum } pm_Cstate_t;
37 typedef struct pmStats {
38 uint64_t pmNapCnt[Cnum]; /* Total nap calls for states */
39 uint64_t pmNapTime[Cnum]; /* Total nap time for states */
40 uint64_t pmNapC2HPET; /* Total nap time for C2 using HPET for stats */
41 uint64_t pmNapC4HPET; /* Total nap time for C4 using HPET for stats */
42 uint64_t pmNapHPETPops; /* Number of times we detect HPET popping */
43 uint64_t pmHPETRupt; /* Number of HPET interruptions */
44 uint32_t pmCurC3Res; /* Current value of the C3 residency timer */
45 uint32_t pmLastApic; /* Last value of apic timer */
46 uint32_t pmNewApic; /* New value of apic timer */
47 uint64_t pmHpetTim; /* Time to next interrupt in HPET ticks */
48 uint64_t pmHpetCmp; /* HPET comparator */
49 uint64_t pmHpetCfg; /* HPET configuration */
50 uint64_t pmLSNs; /* (TEST) Last set nanotime */
51 uint64_t pmLLHpet; /* (TEST) Last loaded HPET */
52 } pmStats_t;
53
54 #define MAX_PSTATES 32 /* architectural limit */
55
56 typedef enum { Cn1, Cn2, Cn3, Cn4, Cnmax } Cstate_number_t;
57 typedef struct {
58 Cstate_number_t number;
59 uint32_t hint;
60 } Cstate_hint_t;
61
62
63 struct pmData {
64 uint8_t pad[93];
65 };
66 typedef struct pmData pmData_t;
67
68 #define pmNapHalt 0x00000010
69 #define pmNapC1 0x00000008
70 #define pmNapC2 0x00000004
71 #define pmNapC3 0x00000002
72 #define pmNapC4 0x00000001
73 #define pmNapMask 0x000000FF
74
75 #define cfgAdr 0xCF8
76 #define cfgDat 0xCFC
77 #define lpcCfg (0x80000000 | (0 << 16) | (31 << 11) | (0 << 8))
78
79 /*
80 * Dispatch table for functions that get installed when the power
81 * management KEXT loads.
82 */
83 typedef struct
84 {
85 /*
86 * The following are the stepper table interfaces.
87 */
88 void (*pmsCPUMachineInit)(void);
89 void (*pmsCPUInit)(void);
90 void (*pmsCPUSet)(uint32_t sel);
91 void (*pmsCPUConf)(void);
92 void (*pmsCPURun)(uint32_t nstep);
93 uint32_t (*pmsCPUQuery)(void);
94 uint32_t (*pmsCPUPackageQuery)(void);
95 void (*pmsCPUYellowFlag)(void);
96 void (*pmsCPUGreenFlag)(void);
97 kern_return_t (*pmsCPULoadVIDTable)(uint16_t *tablep, int nstates);
98 kern_return_t (*pmsCPUSetPStateLimit)(uint32_t limit);
99
100 /*
101 * The following are the 'C' State interfaces.
102 */
103 void (*cstateInit)(void);
104 void (*cstateMachineIdle)(uint32_t napCtl);
105 kern_return_t (*cstateTableSet)(Cstate_hint_t *tablep, unsigned int nstates);
106 uint32_t (*cstateNapPolicy)(uint32_t forcenap, uint32_t napCtl);
107 } pmDispatch_t;
108
109 typedef struct {
110 uint32_t PState;
111 uint32_t PLimit;
112 uint16_t VIDTable[MAX_PSTATES];
113 uint32_t VIDTableCount;
114 Cstate_hint_t CStates[Cnmax];
115 uint32_t CStatesCount;
116 } pmInitState_t;
117
118 typedef struct {
119 void (*Park)(void);
120 void (*Run)(uint32_t nstep);
121 void (*RunLocal)(uint32_t nstep);
122 void (*SetStep)(uint32_t nstep, int dir);
123 void (*NapPolicy)(void);
124 kern_return_t (*Build)(pmsDef *pd, uint32_t pdsize, pmsSetFunc_t *functab, uint32_t platformData, pmsQueryFunc_t queryFunc);
125 pmStats_t *(*Stats)(void);
126 pmsd *(*StepperData)(void);
127 uint64_t *(*HPETAddr)(void);
128 pmInitState_t *InitState;
129 void (*resetPop)(void);
130 } pmCallBacks_t;
131
132 extern pmDispatch_t *pmDispatch;
133
134 extern uint32_t maxBusDelay;
135 extern uint32_t C4C2SnoopDelay;
136 extern uint32_t forcenap;
137
138 void power_management_init(void);
139 void machine_nap_policy(void);
140 kern_return_t Cstate_table_set(Cstate_hint_t *tablep, unsigned int nstates);
141 void machine_idle_cstate(void);
142 void pmRegister(pmDispatch_t *cpuFuncs, pmCallBacks_t *callbacks);
143 void pmUnRegister(pmDispatch_t *cpuFuncs);
144
145 #endif /* ASSEMBLER */
146 #endif /* _I386_PMCPU_H_ */
147 #endif /* KERNEL_PRIVATE */