]>
Commit | Line | Data |
---|---|---|
0c530ab8 A |
1 | /* |
2 | * Copyright (c) 2004-2005 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * The contents of this file constitute Original Code as defined in and | |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
11 | * | |
12 | * This Original Code and all software distributed under the License are | |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the | |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | ||
23 | #ifdef KERNEL_PRIVATE | |
24 | ||
25 | #ifndef _KERN_PMS_H_ | |
26 | #define _KERN_PMS_H_ | |
27 | ||
28 | #define pmsMaxStates 64 | |
29 | #define HalfwayToForever 0x7FFFFFFFFFFFFFFFULL | |
30 | #define century 790560000000000ULL | |
31 | ||
32 | typedef void (*pmsSetFunc_t)(uint32_t, uint32_t, uint32_t); /* Function used to set hardware power state */ | |
33 | typedef uint32_t (*pmsQueryFunc_t)(uint32_t, uint32_t); /* Function used to query hardware power state */ | |
34 | ||
35 | typedef struct pmsStat { | |
36 | uint64_t stTime[2]; /* Total time until switch to next step */ | |
37 | uint32_t stCnt[2]; /* Number of times switched to next step */ | |
38 | } pmsStat; | |
39 | ||
40 | typedef struct pmsDef { | |
41 | uint64_t pmsLimit; /* Max time in this state in microseconds */ | |
42 | uint32_t pmsStepID; /* Unique ID for this step */ | |
43 | uint32_t pmsSetCmd; /* Command to select power state */ | |
44 | #define pmsCngXClk 0x80000000 /* Change external clock */ | |
45 | #define pmsXUnk 0x7F /* External clock unknown */ | |
46 | #define pmsXClk 0x7F000000 /* External clock frequency */ | |
47 | #define pmsCngCPU 0x00800000 /* Change CPU parameters */ | |
48 | #define pmsSync 0x00400000 /* Make changes synchronously, i.e., spin until delay finished */ | |
49 | #define pmsMustCmp 0x00200000 /* Delay must complete before next change */ | |
50 | #define pmsCPU 0x001F0000 /* CPU frequency */ | |
51 | #define pmsCPUUnk 0x1F /* CPU frequency unknown */ | |
52 | #define pmsCngVolt 0x00008000 /* Change voltage */ | |
53 | #define pmsVoltage 0x00007F00 /* Voltage */ | |
54 | #define pmsVoltUnk 0x7F /* Voltage unknown */ | |
55 | #define pmsPowerID 0x000000FF /* Identify power state to HW */ | |
56 | ||
57 | /* Special commands - various things */ | |
58 | #define pmsDelay 0xFFFFFFFD /* Delayed step, no processor or platform changes. Timer expiration causes transition to pmsTDelay */ | |
59 | #define pmsParkIt 0xFFFFFFFF /* Enters the parked state. No processor or platform changes. Timers cancelled */ | |
60 | #define pmsCInit ((pmsXUnk << 24) | (pmsCPUUnk << 16) | (pmsVoltUnk << 8)) /* Initial current set command value */ | |
61 | /* Note: pmsSetFuncInd is an index into a table of function pointers and pmsSetFunc is the address | |
62 | * of a function. Initially, when you create a step table, this field is set as an index into | |
63 | * a table of function addresses that gets passed as a parameter to pmsBuild. When pmsBuild | |
64 | * internalizes the step and function tables, it converts the index to the function address. | |
65 | */ | |
66 | union sf { | |
67 | pmsSetFunc_t pmsSetFunc; /* Function used to set platform power state */ | |
68 | uint32_t pmsSetFuncInd; /* Index to function in function table */ | |
69 | } sf; | |
70 | ||
71 | uint32_t pmsDown; /* Next state if going lower */ | |
72 | uint32_t pmsNext; /* Normal next state */ | |
73 | uint32_t pmsTDelay; /* State if command was pmsDelay and timer expired */ | |
74 | } pmsDef; | |
75 | ||
76 | typedef struct pmsCtl { | |
77 | pmsStat (*pmsStats)[pmsMaxStates]; /* Pointer to statistics information, 0 if not enabled */ | |
78 | pmsDef *pmsDefs[pmsMaxStates]; /* Indexed pointers to steps */ | |
79 | } pmsCtl; | |
80 | ||
81 | /* | |
82 | * Note that this block is in the middle of the per_proc and the size (32 bytes) | |
83 | * can't be changed without moving it. | |
84 | */ | |
85 | ||
86 | typedef struct pmsd { | |
87 | uint32_t pmsState; /* Current power management state */ | |
88 | uint32_t pmsCSetCmd; /* Current select command */ | |
89 | uint64_t pmsPop; /* Time of next step */ | |
90 | uint64_t pmsStamp; /* Time of transition to current state */ | |
91 | uint64_t pmsTime; /* Total time in this state */ | |
92 | } pmsd; | |
93 | ||
94 | /* | |
95 | * Required power management step programs | |
96 | */ | |
97 | ||
98 | enum { | |
99 | pmsIdle = 0, /* Power state in idle loop */ | |
100 | pmsNorm = 1, /* Normal step - usually low power */ | |
101 | pmsNormHigh = 2, /* Highest power in normal step */ | |
102 | pmsBoost = 3, /* Boost/overdrive step */ | |
103 | pmsLow = 4, /* Lowest non-idle power state, no transitions */ | |
104 | pmsHigh = 5, /* Power step for full on, no transitions */ | |
105 | pmsPrepCng = 6, /* Prepare for step table change */ | |
106 | pmsPrepSleep = 7, /* Prepare for sleep */ | |
107 | pmsOverTemp = 8, /* Machine is too hot */ | |
108 | pmsEnterNorm = 9, /* Enter into the normal step program */ | |
109 | pmsFree = 10, /* First available empty step */ | |
110 | pmsStartUp = 0xFFFFFFFE, /* Start stepping */ | |
111 | pmsParked = 0xFFFFFFFF /* Power parked - used when changing stepping table */ | |
112 | }; | |
113 | ||
114 | /* | |
115 | * Power Management Stepper Control requests | |
116 | */ | |
117 | ||
118 | enum { | |
119 | pmsCPark = 0, /* Parks the stepper */ | |
120 | pmsCStart = 1, /* Starts normal steppping */ | |
121 | pmsCFLow = 2, /* Forces low power */ | |
122 | pmsCFHigh = 3, /* Forces high power */ | |
123 | pmsCCnfg = 4, /* Loads new stepper program */ | |
124 | pmsCQuery = 5, /* Query current step and state */ | |
125 | pmsCExperimental = 6, /* Enter experimental mode */ | |
126 | pmsGCtls = 7, | |
127 | pmsGStats = 8, | |
128 | pmsCVID = 9, | |
129 | pmsCFree = 10 /* Next control command to be assigned */ | |
130 | }; | |
131 | ||
132 | /* | |
133 | * User request control structure passed to sysctl | |
134 | */ | |
135 | typedef struct { | |
136 | uint32_t request; /* stepper control request */ | |
137 | uint32_t reqsize; /* size of data */ | |
138 | void *reqaddr; /* read/write data buffer */ | |
139 | } pmsctl_t; | |
140 | ||
141 | extern pmsCtl pmsCtls; /* Power Management Stepper control */ | |
142 | #ifdef __ppc__ | |
143 | extern uint32_t pmsCtlp; | |
144 | #endif | |
145 | extern uint32_t pmsBroadcastWait; /* Number of outstanding broadcasts */ | |
146 | extern int pmsInstalled; | |
147 | extern int pmsExperimental; | |
148 | ||
149 | #define pmsSetFuncMax 32 | |
150 | extern pmsSetFunc_t pmsFuncTab[pmsSetFuncMax]; | |
151 | extern pmsQueryFunc_t pmsQueryFunc; | |
152 | extern uint32_t pmsPlatformData; | |
153 | ||
154 | #ifdef __ppc__ | |
155 | extern int pmsCntrl(struct savearea *save); | |
156 | #endif | |
157 | extern kern_return_t pmsControl(uint32_t request, user_addr_t reqaddr, uint32_t reqsize); | |
158 | extern void pmsInit(void); | |
159 | extern void pmsStep(int timer); | |
160 | extern void pmsDown(void); | |
161 | extern void pmsSetStep(uint32_t nstep, int dir); | |
162 | extern void pmsRunLocal(uint32_t nstep); | |
163 | extern void pmsCPUSet(uint32_t sel); | |
164 | extern uint32_t pmsCPUQuery(void); | |
165 | extern uint32_t pmsCPUPackageQuery(void); | |
166 | extern void pmsCPUConf(void); | |
167 | extern void pmsCPUMachineInit(void); | |
168 | extern void pmsCPUInit(void); | |
169 | extern void pmsCPURun(uint32_t nstep); | |
170 | ||
171 | extern void pmsCPUYellowFlag(void); | |
172 | extern void pmsCPUGreenFlag(void); | |
173 | ||
174 | #ifdef __cplusplus | |
175 | extern "C" { | |
176 | #endif | |
177 | ||
178 | extern kern_return_t pmsBuild(pmsDef *pd, uint32_t pdsize, pmsSetFunc_t *functab, uint32_t platformData, pmsQueryFunc_t queryFunc); | |
179 | extern void pmsRun(uint32_t nstep); | |
180 | extern void pmsPark(void); | |
181 | extern void pmsStart(void); | |
182 | # ifndef __ppc__ | |
183 | extern kern_return_t pmsCPULoadVIDTable(uint16_t *tablep, int nstates); /* i386 only */ | |
184 | extern kern_return_t pmsCPUSetPStateLimit(uint32_t limit); | |
185 | # endif | |
186 | #ifdef __cplusplus | |
187 | } | |
188 | #endif | |
189 | ||
190 | #endif /* _KERN_PMS_H_ */ | |
191 | #endif /* KERNEL_PRIVATE */ |