]> git.saurik.com Git - apple/xnu.git/blame - osfmk/ppc/pmsCPU.c
xnu-1228.tar.gz
[apple/xnu.git] / osfmk / ppc / pmsCPU.c
CommitLineData
3a60a9f5 1/*
2d21ac55 2 * Copyright (c) 2004-2006 Apple Computer, Inc. All rights reserved.
3a60a9f5 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
3a60a9f5 5 *
2d21ac55
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 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>
0c530ab8 36#include <kern/pms.h>
3a60a9f5
A
37#include <ppc/savearea.h>
38#include <ppc/Diagnostics.h>
39#include <kern/processor.h>
40
41
0c530ab8
A
42static void pmsCPURemote(uint32_t nstep);
43
44
3a60a9f5
A
45pmsDef 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
134void pmsCPUSet(uint32_t sel) {
2d21ac55 135 int nfreq;
3a60a9f5
A
136 struct per_proc_info *pp;
137
138 pp = getPerProc(); /* Get our per_proc */
139
140 if(!((sel ^ pp->pms.pmsCSetCmd) & pmsCPU)) return; /* If there aren't any changes, bail now... */
141
142 nfreq = (sel & pmsCPU) >> 16; /* Isolate the new frequency */
143
144 switch(pp->pf.pfPowerModes & pmType) { /* Figure out what type to do */
145
146 case pmDFS: /* This is a DFS machine */
147 ml_set_processor_speed_dfs(nfreq); /* Yes, set it */
148 break;
149
150 case pmDualPLL:
151 ml_set_processor_speed_dpll(nfreq); /* THIS IS COMPLETELY UNTESTED!!! */
152 break;
153
154 case pmPowerTune: /* This is a PowerTune machine */
155 ml_set_processor_speed_powertune(nfreq); /* Diddle the deal */
156 break;
157
158 default: /* Not this time dolt!!! */
159 panic("pmsCPUSet: unsupported power manager type: %08X\n", pp->pf.pfPowerModes);
160 break;
161
162 }
163
164}
165
166/*
167 * This code configures the initial step tables. It should be called after the timebase frequency is initialized.
168 */
169
170void pmsCPUConf(void) {
171
172 int i;
173 kern_return_t ret;
174 pmsSetFunc_t pmsDfltFunc[pmsSetFuncMax]; /* List of functions for the external power control to use */
175
2d21ac55 176 for(i = 0; i < pmsSetFuncMax; i++) pmsDfltFunc[i] = NULL; /* Clear this */
3a60a9f5
A
177
178
179 ret = pmsBuild((pmsDef *)&pmsDefault, sizeof(pmsDefault), pmsDfltFunc, 0, (pmsQueryFunc_t)0); /* Configure the default stepper */
180
3a60a9f5
A
181 if(ret != KERN_SUCCESS) { /* Some screw up? */
182 panic("pmsCPUConf: initial stepper table build failed, ret = %08X\n", ret); /* Squeal */
183 }
184
185 pmsSetStep(pmsHigh, 1); /* Slew to high speed */
186 pmsPark(); /* Then park */
187 return;
188}
189
0c530ab8
A
190/*
191 * Machine-dependent initialization
192 */
193void
194pmsCPUMachineInit(void)
195{
196 return;
197}
198
3a60a9f5
A
199/*
200 * This function should be called once for each processor to force the
201 * processor to the correct voltage and frequency.
202 */
203
204void pmsCPUInit(void) {
205
206 int cpu;
207
208 cpu = cpu_number(); /* Who are we? */
209
210 kprintf("************ Initializing stepper hardware, cpu %d ******************\n", cpu); /* (BRINGUP) */
211
212 pmsSetStep(pmsHigh, 1); /* Slew to high speed */
213 pmsPark(); /* Then park */
214
215 kprintf("************ Stepper hardware initialized, cpu %d ******************\n", cpu); /* (BRINGUP) */
3a60a9f5
A
216}
217
2d21ac55 218extern uint32_t hid1get(void);
3a60a9f5 219
2d21ac55
A
220uint32_t
221pmsCPUQuery(void)
222{
3a60a9f5
A
223 uint32_t result;
224 struct per_proc_info *pp;
225 uint64_t scdata;
226
227 pp = getPerProc(); /* Get our per_proc */
228
229 switch(pp->pf.pfPowerModes & pmType) { /* Figure out what type to do */
230
231 case pmDFS: /* This is a DFS machine */
232 result = hid1get(); /* Get HID1 */
233 result = (result >> 6) & 0x00030000; /* Isolate the DFS bits */
234 break;
235
236 case pmPowerTune: /* This is a PowerTune machine */
237 (void)ml_scom_read(PowerTuneStatusReg, &scdata); /* Get the current power level */
238 result = (scdata >> (32 + 8)) & 0x00030000; /* Shift the data to align with the set command */
239 break;
240
241 default: /* Query not supported for this kind */
242 result = 0; /* Return highest if not supported */
243 break;
244
245 }
246
247 return result;
248}
249
0c530ab8
A
250/*
251 * These are not implemented for PPC.
252 */
253void pmsCPUYellowFlag(void) {
254}
255
256void pmsCPUGreenFlag(void) {
257}
258
259uint32_t pmsCPUPackageQuery(void)
260{
261 /* multi-core CPUs are not supported. */
262 return(~(uint32_t)0);
263}
264
265/*
266 * Broadcast a change to all processors including ourselves.
267 * This must transition before broadcasting because we may block and end up on a different processor.
268 *
269 * This will block until all processors have transitioned, so
270 * obviously, this can block.
271 *
272 * Called with interruptions disabled.
273 *
274 */
275
276void pmsCPURun(uint32_t nstep) {
277
278 pmsRunLocal(nstep); /* If we aren't parking (we are already parked), transition ourselves */
279 (void)cpu_broadcast(&pmsBroadcastWait, pmsCPURemote, nstep); /* Tell everyone else to do it too */
280
281 return;
282
283}
284
285/*
286 * Receive a broadcast and react.
287 * This is called from the interprocessor signal handler.
288 * We wake up the initiator after we are finished.
289 *
290 */
291
292static void pmsCPURemote(uint32_t nstep) {
293
294 pmsRunLocal(nstep); /* Go set the step */
295 if(!hw_atomic_sub(&pmsBroadcastWait, 1)) { /* Drop the wait count */
296 thread_wakeup((event_t)&pmsBroadcastWait); /* If we were the last, wake up the signaller */
297 }
298 return;
299}
300
301/*
302 * Control the Power Management Stepper.
303 * Called from user state by the superuser via a ppc system call.
304 * Interruptions disabled.
305 *
306 */
307int pmsCntrl(struct savearea *save) {
308 save->save_r3 = pmsControl(save->save_r3, (user_addr_t)(uintptr_t)save->save_r4, save->save_r5);
309 return 1;
310}
311
312
3a60a9f5 313