]>
Commit | Line | Data |
---|---|---|
3a60a9f5 A |
1 | /* |
2 | * Copyright (c) 2004-2005 Apple Computer, Inc. All rights reserved. | |
3 | * | |
8f6c56a5 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
3a60a9f5 | 5 | * |
8f6c56a5 A |
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 | |
8ad349bb | 24 | * limitations under the License. |
8f6c56a5 A |
25 | * |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
3a60a9f5 A |
27 | */ |
28 | #include <ppc/machine_routines.h> | |
29 | #include <ppc/machine_cpu.h> | |
30 | #include <ppc/exception.h> | |
31 | #include <ppc/misc_protos.h> | |
32 | #include <ppc/Firmware.h> | |
33 | #include <ppc/pmap.h> | |
34 | #include <ppc/asm.h> | |
35 | #include <ppc/proc_reg.h> | |
89b3af67 | 36 | #include <kern/pms.h> |
3a60a9f5 A |
37 | #include <ppc/savearea.h> |
38 | #include <ppc/Diagnostics.h> | |
39 | #include <kern/processor.h> | |
40 | ||
41 | ||
89b3af67 A |
42 | static void pmsCPURemote(uint32_t nstep); |
43 | ||
44 | ||
3a60a9f5 A |
45 | pmsDef pmsDefault[] = { |
46 | { | |
47 | .pmsLimit = century, /* We can normally stay here for 100 years */ | |
48 | .pmsStepID = pmsIdle, /* Unique identifier to this step */ | |
49 | .pmsSetCmd = 0, /* Dummy platform power level */ | |
50 | .sf.pmsSetFuncInd = 0, /* Dummy platform set function */ | |
51 | .pmsDown = pmsIdle, /* We stay here */ | |
52 | .pmsNext = pmsNorm /* Next step */ | |
53 | }, | |
54 | { | |
55 | .pmsLimit = century, /* We can normally stay here for 100 years */ | |
56 | .pmsStepID = pmsNorm, /* Unique identifier to this step */ | |
57 | .pmsSetCmd = 0, /* Dummy platform power level */ | |
58 | .sf.pmsSetFuncInd = 0, /* Dummy platform set function */ | |
59 | .pmsDown = pmsIdle, /* Down to idle */ | |
60 | .pmsNext = pmsNorm /* Next step */ | |
61 | }, | |
62 | { | |
63 | .pmsLimit = century, /* We can normally stay here for 100 years */ | |
64 | .pmsStepID = pmsNormHigh, /* Unique identifier to this step */ | |
65 | .pmsSetCmd = 0, /* Dummy platform power level */ | |
66 | .sf.pmsSetFuncInd = 0, /* Dummy platform set function */ | |
67 | .pmsDown = pmsIdle, /* Down to idle */ | |
68 | .pmsNext = pmsNormHigh /* Next step */ | |
69 | }, | |
70 | { | |
71 | .pmsLimit = century, /* We can normally stay here for 100 years */ | |
72 | .pmsStepID = pmsBoost, /* Unique identifier to this step */ | |
73 | .pmsSetCmd = 0, /* Dummy platform power level */ | |
74 | .sf.pmsSetFuncInd = 0, /* Dummy platform set function */ | |
75 | .pmsDown = pmsIdle, /* Step down */ | |
76 | .pmsNext = pmsBoost /* Next step */ | |
77 | }, | |
78 | { | |
79 | .pmsLimit = century, /* We can normally stay here for 100 years */ | |
80 | .pmsStepID = pmsLow, /* Unique identifier to this step */ | |
81 | .pmsSetCmd = 0, /* Dummy platform power level */ | |
82 | .sf.pmsSetFuncInd = 0, /* Dummy platform set function */ | |
83 | .pmsDown = pmsLow, /* We always stay here */ | |
84 | .pmsNext = pmsLow /* We always stay here */ | |
85 | }, | |
86 | { | |
87 | .pmsLimit = century, /* We can normally stay here for 100 years */ | |
88 | .pmsStepID = pmsHigh, /* Unique identifier to this step */ | |
89 | .pmsSetCmd = 0, /* Dummy platform power level */ | |
90 | .sf.pmsSetFuncInd = 0, /* Dummy platform set function */ | |
91 | .pmsDown = pmsHigh, /* We always stay here */ | |
92 | .pmsNext = pmsHigh /* We always stay here */ | |
93 | }, | |
94 | { | |
95 | .pmsLimit = 0, /* Time doesn't matter for a prepare for change */ | |
96 | .pmsStepID = pmsPrepCng, /* Unique identifier to this step */ | |
97 | .pmsSetCmd = pmsParkIt, /* Force us to be parked */ | |
98 | .sf.pmsSetFuncInd = 0, /* Dummy platform set function */ | |
99 | .pmsDown = pmsPrepCng, /* We always stay here */ | |
100 | .pmsNext = pmsPrepCng /* We always stay here */ | |
101 | }, | |
102 | { | |
103 | .pmsLimit = 0, /* Time doesn't matter for a prepare for sleep */ | |
104 | .pmsStepID = pmsPrepSleep, /* Unique identifier to this step */ | |
105 | .pmsSetCmd = pmsParkIt, /* Force us to be parked */ | |
106 | .sf.pmsSetFuncInd = 0, /* Dummy platform set function */ | |
107 | .pmsDown = pmsPrepSleep, /* We always stay here */ | |
108 | .pmsNext = pmsPrepSleep /* We always stay here */ | |
109 | }, | |
110 | { | |
111 | .pmsLimit = 0, /* Time doesn't matter for a prepare for sleep */ | |
112 | .pmsStepID = pmsOverTemp, /* Unique identifier to this step */ | |
113 | .pmsSetCmd = 0, /* Dummy platform power level */ | |
114 | .sf.pmsSetFuncInd = 0, /* Dummy platform set function */ | |
115 | .pmsDown = pmsOverTemp, /* We always stay here */ | |
116 | .pmsNext = pmsOverTemp /* We always stay here */ | |
117 | } | |
118 | }; | |
119 | ||
120 | ||
121 | ||
122 | /* | |
123 | * This is where the CPU part of the stepper code lives. | |
124 | * | |
125 | * It also contains the "hacked kext" experimental code. This is/was used for | |
126 | * experimentation and bringup. It should neither live long nor prosper. | |
127 | * | |
128 | */ | |
129 | ||
130 | /* | |
131 | * Set the processor frequency and stuff | |
132 | */ | |
133 | ||
134 | void pmsCPUSet(uint32_t sel) { | |
135 | int nvoltage, nfreq; | |
136 | uint32_t oldaack; | |
137 | struct per_proc_info *pp; | |
138 | ||
139 | pp = getPerProc(); /* Get our per_proc */ | |
140 | ||
141 | if(!((sel ^ pp->pms.pmsCSetCmd) & pmsCPU)) return; /* If there aren't any changes, bail now... */ | |
142 | ||
143 | nfreq = (sel & pmsCPU) >> 16; /* Isolate the new frequency */ | |
144 | ||
145 | switch(pp->pf.pfPowerModes & pmType) { /* Figure out what type to do */ | |
146 | ||
147 | case pmDFS: /* This is a DFS machine */ | |
148 | ml_set_processor_speed_dfs(nfreq); /* Yes, set it */ | |
149 | break; | |
150 | ||
151 | case pmDualPLL: | |
152 | ml_set_processor_speed_dpll(nfreq); /* THIS IS COMPLETELY UNTESTED!!! */ | |
153 | break; | |
154 | ||
155 | case pmPowerTune: /* This is a PowerTune machine */ | |
156 | ml_set_processor_speed_powertune(nfreq); /* Diddle the deal */ | |
157 | break; | |
158 | ||
159 | default: /* Not this time dolt!!! */ | |
160 | panic("pmsCPUSet: unsupported power manager type: %08X\n", pp->pf.pfPowerModes); | |
161 | break; | |
162 | ||
163 | } | |
164 | ||
165 | } | |
166 | ||
167 | /* | |
168 | * This code configures the initial step tables. It should be called after the timebase frequency is initialized. | |
169 | */ | |
170 | ||
171 | void pmsCPUConf(void) { | |
172 | ||
173 | int i; | |
174 | kern_return_t ret; | |
175 | pmsSetFunc_t pmsDfltFunc[pmsSetFuncMax]; /* List of functions for the external power control to use */ | |
176 | ||
177 | for(i = 0; i < pmsSetFuncMax; i++) pmsDfltFunc[i] = 0; /* Clear this */ | |
178 | ||
179 | ||
180 | ret = pmsBuild((pmsDef *)&pmsDefault, sizeof(pmsDefault), pmsDfltFunc, 0, (pmsQueryFunc_t)0); /* Configure the default stepper */ | |
181 | ||
182 | pCCfinish: | |
183 | if(ret != KERN_SUCCESS) { /* Some screw up? */ | |
184 | panic("pmsCPUConf: initial stepper table build failed, ret = %08X\n", ret); /* Squeal */ | |
185 | } | |
186 | ||
187 | pmsSetStep(pmsHigh, 1); /* Slew to high speed */ | |
188 | pmsPark(); /* Then park */ | |
189 | return; | |
190 | } | |
191 | ||
89b3af67 A |
192 | /* |
193 | * Machine-dependent initialization | |
194 | */ | |
195 | void | |
196 | pmsCPUMachineInit(void) | |
197 | { | |
198 | return; | |
199 | } | |
200 | ||
3a60a9f5 A |
201 | /* |
202 | * This function should be called once for each processor to force the | |
203 | * processor to the correct voltage and frequency. | |
204 | */ | |
205 | ||
206 | void pmsCPUInit(void) { | |
207 | ||
208 | int cpu; | |
209 | ||
210 | cpu = cpu_number(); /* Who are we? */ | |
211 | ||
212 | kprintf("************ Initializing stepper hardware, cpu %d ******************\n", cpu); /* (BRINGUP) */ | |
213 | ||
214 | pmsSetStep(pmsHigh, 1); /* Slew to high speed */ | |
215 | pmsPark(); /* Then park */ | |
216 | ||
217 | kprintf("************ Stepper hardware initialized, cpu %d ******************\n", cpu); /* (BRINGUP) */ | |
218 | ||
219 | return; | |
220 | } | |
221 | ||
89b3af67 | 222 | uint32_t pmsCPUQuery(void) { |
3a60a9f5 A |
223 | |
224 | uint32_t result; | |
225 | struct per_proc_info *pp; | |
226 | uint64_t scdata; | |
227 | ||
228 | pp = getPerProc(); /* Get our per_proc */ | |
229 | ||
230 | switch(pp->pf.pfPowerModes & pmType) { /* Figure out what type to do */ | |
231 | ||
232 | case pmDFS: /* This is a DFS machine */ | |
233 | result = hid1get(); /* Get HID1 */ | |
234 | result = (result >> 6) & 0x00030000; /* Isolate the DFS bits */ | |
235 | break; | |
236 | ||
237 | case pmPowerTune: /* This is a PowerTune machine */ | |
238 | (void)ml_scom_read(PowerTuneStatusReg, &scdata); /* Get the current power level */ | |
239 | result = (scdata >> (32 + 8)) & 0x00030000; /* Shift the data to align with the set command */ | |
240 | break; | |
241 | ||
242 | default: /* Query not supported for this kind */ | |
243 | result = 0; /* Return highest if not supported */ | |
244 | break; | |
245 | ||
246 | } | |
247 | ||
248 | return result; | |
249 | } | |
250 | ||
89b3af67 A |
251 | /* |
252 | * These are not implemented for PPC. | |
253 | */ | |
254 | void pmsCPUYellowFlag(void) { | |
255 | } | |
256 | ||
257 | void pmsCPUGreenFlag(void) { | |
258 | } | |
259 | ||
260 | uint32_t pmsCPUPackageQuery(void) | |
261 | { | |
262 | /* multi-core CPUs are not supported. */ | |
263 | return(~(uint32_t)0); | |
264 | } | |
265 | ||
266 | /* | |
267 | * Broadcast a change to all processors including ourselves. | |
268 | * This must transition before broadcasting because we may block and end up on a different processor. | |
269 | * | |
270 | * This will block until all processors have transitioned, so | |
271 | * obviously, this can block. | |
272 | * | |
273 | * Called with interruptions disabled. | |
274 | * | |
275 | */ | |
276 | ||
277 | void pmsCPURun(uint32_t nstep) { | |
278 | ||
279 | pmsRunLocal(nstep); /* If we aren't parking (we are already parked), transition ourselves */ | |
280 | (void)cpu_broadcast(&pmsBroadcastWait, pmsCPURemote, nstep); /* Tell everyone else to do it too */ | |
281 | ||
282 | return; | |
283 | ||
284 | } | |
285 | ||
286 | /* | |
287 | * Receive a broadcast and react. | |
288 | * This is called from the interprocessor signal handler. | |
289 | * We wake up the initiator after we are finished. | |
290 | * | |
291 | */ | |
292 | ||
293 | static void pmsCPURemote(uint32_t nstep) { | |
294 | ||
295 | pmsRunLocal(nstep); /* Go set the step */ | |
296 | if(!hw_atomic_sub(&pmsBroadcastWait, 1)) { /* Drop the wait count */ | |
297 | thread_wakeup((event_t)&pmsBroadcastWait); /* If we were the last, wake up the signaller */ | |
298 | } | |
299 | return; | |
300 | } | |
301 | ||
302 | /* | |
303 | * Control the Power Management Stepper. | |
304 | * Called from user state by the superuser via a ppc system call. | |
305 | * Interruptions disabled. | |
306 | * | |
307 | */ | |
308 | int pmsCntrl(struct savearea *save) { | |
309 | save->save_r3 = pmsControl(save->save_r3, (user_addr_t)(uintptr_t)save->save_r4, save->save_r5); | |
310 | return 1; | |
311 | } | |
312 | ||
313 | ||
3a60a9f5 | 314 |