]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/pmCPU.h
xnu-1228.3.13.tar.gz
[apple/xnu.git] / osfmk / i386 / pmCPU.h
1 /*
2 * Copyright (c) 2006-2007 Apple 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 #include <i386/cpu_topology.h>
34
35 #ifndef ASSEMBLER
36
37 #define MAX_PSTATES 32 /* architectural limit */
38
39 typedef enum
40 {
41 Cn1, Cn2, Cn3, Cn4, Cn5, Cn6, CnHlt, Cn0, CnRun, Cnmax
42 } Cstate_number_t;
43
44 typedef struct
45 {
46 Cstate_number_t number;
47 uint32_t hint;
48 } Cstate_hint_t;
49
50
51 struct pmData {
52 uint8_t pad[93];
53 };
54 typedef struct pmData pmData_t;
55
56 #define pmNapHalt 0x00000010
57 #define pmNapC1 0x00000008
58 #define pmNapC2 0x00000004
59 #define pmNapC3 0x00000002
60 #define pmNapC4 0x00000001
61 #define pmNapMask 0x000000FF
62
63 #define cfgAdr 0xCF8
64 #define cfgDat 0xCFC
65 #define lpcCfg (0x80000000 | (0 << 16) | (31 << 11) | (0 << 8))
66
67 /*
68 * This value should be changed each time that pmDsipatch_t or pmCallBacks_t
69 * changes.
70 */
71 #define PM_DISPATCH_VERSION 7
72
73 /*
74 * Dispatch table for functions that get installed when the power
75 * management KEXT loads.
76 */
77 typedef struct
78 {
79 /*
80 * The following are the stepper table interfaces.
81 */
82 int (*pmCPUStateInit)(void);
83 void (*pmsInit)(void);
84 void (*pmsStart)(void);
85 void (*pmsPark)(void);
86 kern_return_t (*pmsCPUSetPStateLimit)(uint32_t limit);
87
88 /*
89 * The following are legacy stepper interfaces.
90 */
91 void (*pmsRun)(uint32_t nstep);
92 kern_return_t (*pmsBuild)(pmsDef *pd, uint32_t pdsize, pmsSetFunc_t *functab, uint32_t platformData, pmsQueryFunc_t queryFunc);
93 kern_return_t (*pmsCPULoadVIDTable)(uint16_t *tablep, int nstates);
94
95 /*
96 * The following are the 'C' State interfaces.
97 */
98 void (*cstateInit)(void);
99 uint64_t (*cstateMachineIdle)(uint64_t maxIdleDuration);
100 kern_return_t (*cstateTableSet)(Cstate_hint_t *tablep, unsigned int nstates);
101 uint64_t (*GetDeadline)(x86_lcpu_t *lcpu);
102 uint64_t (*SetDeadline)(x86_lcpu_t *lcpu, uint64_t);
103 void (*Deadline)(x86_lcpu_t *lcpu);
104 boolean_t (*exitIdle)(x86_lcpu_t *lcpu);
105 void (*markCPURunning)(x86_lcpu_t *lcpu);
106 void (*HPETInterrupt)(void);
107 int (*pmCPUControl)(uint32_t cmd, void *datap);
108 void (*pmCPUHalt)(void);
109 uint64_t (*getMaxSnoop)(void);
110 void (*setMaxBusDelay)(uint64_t time);
111 uint64_t (*getMaxBusDelay)(void);
112 void (*pmCPUSafeMode)(x86_lcpu_t *lcpu, uint32_t flags);
113 } pmDispatch_t;
114
115 typedef struct {
116 uint32_t PState;
117 uint32_t PLimit;
118 uint16_t VIDTable[MAX_PSTATES];
119 uint32_t VIDTableCount;
120 Cstate_hint_t CStates[Cnmax];
121 uint32_t CStatesCount;
122 uint64_t maxBusDelay;
123 } pmInitState_t;
124
125 typedef struct {
126 uint64_t *(*HPETAddr)(void);
127 pmInitState_t *InitState;
128 int (*setRTCPop)(uint64_t time);
129 void (*resyncDeadlines)(void);
130 void (*initComplete)(void);
131 x86_lcpu_t *(*GetLCPU)(int cpu);
132 x86_core_t *(*GetCore)(int cpu);
133 x86_pkg_t *(*GetPackage)(int cpu);
134 x86_lcpu_t *(*GetMyLCPU)(void);
135 x86_core_t *(*GetMyCore)(void);
136 x86_pkg_t *(*GetMyPackage)(void);
137 uint32_t CoresPerPkg;
138 x86_pkg_t *(*GetPkgRoot)(void);
139 void (*LockCPUTopology)(int lock);
140 boolean_t (*GetHibernate)(int cpu);
141 processor_t (*LCPUtoProcessor)(int lcpu);
142 } pmCallBacks_t;
143
144 extern pmDispatch_t *pmDispatch;
145
146 extern uint32_t forcenap;
147
148 void power_management_init(void);
149 void machine_nap_policy(void);
150 kern_return_t Cstate_table_set(Cstate_hint_t *tablep, unsigned int nstates);
151 void machine_idle_cstate(boolean_t halted);
152 void pmKextRegister(uint32_t version, pmDispatch_t *cpuFuncs,
153 pmCallBacks_t *callbacks);
154 void pmUnRegister(pmDispatch_t *cpuFuncs);
155 void pmCPUStateInit(void);
156 uint64_t pmCPUGetDeadline(struct cpu_data *cpu);
157 uint64_t pmCPUSetDeadline(struct cpu_data *cpu, uint64_t deadline);
158 void pmCPUDeadline(struct cpu_data *cpu);
159 boolean_t pmCPUExitIdle(struct cpu_data *cpu);
160 void pmCPUMarkRunning(struct cpu_data *cpu);
161 void pmHPETInterrupt(void);
162 int pmCPUControl(uint32_t cmd, void *datap);
163 void pmCPUHalt(uint32_t reason);
164
165 #define PM_HALT_NORMAL 0 /* normal halt path */
166 #define PM_HALT_DEBUG 1 /* debug code wants to halt */
167 #define PM_HALT_PANIC 2 /* panic code wants to halt */
168
169 void pmSafeMode(x86_lcpu_t *lcpu, uint32_t flags);
170
171 #define PM_SAFE_FL_NORMAL 0x00000001 /* put CPU into "normal" power mode */
172 #define PM_SAFE_FL_SAFE 0x00000002 /* put CPU into a "safe" power mode */
173 #define PM_SAFE_FL_PAUSE 0x00000010 /* pause execution on the CPU */
174 #define PM_SAFE_FL_RESUME 0x00000020 /* resume execution on the CPU */
175
176 extern int pmsafe_debug;
177
178 #endif /* ASSEMBLER */
179
180 #endif /* _I386_PMCPU_H_ */
181 #endif /* KERNEL_PRIVATE */