]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/pmsCPU.c
f241ba7d17ca60b96d6b7b853f83c90532f8cde5
2 * Copyright (c) 2004-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 #include <ppc/machine_routines.h>
31 #include <ppc/machine_cpu.h>
32 #include <ppc/exception.h>
33 #include <ppc/misc_protos.h>
34 #include <ppc/Firmware.h>
37 #include <ppc/proc_reg.h>
39 #include <ppc/savearea.h>
40 #include <ppc/Diagnostics.h>
41 #include <kern/processor.h>
44 static void pmsCPURemote(uint32_t nstep
);
47 pmsDef pmsDefault
[] = {
49 .pmsLimit
= century
, /* We can normally stay here for 100 years */
50 .pmsStepID
= pmsIdle
, /* Unique identifier to this step */
51 .pmsSetCmd
= 0, /* Dummy platform power level */
52 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
53 .pmsDown
= pmsIdle
, /* We stay here */
54 .pmsNext
= pmsNorm
/* Next step */
57 .pmsLimit
= century
, /* We can normally stay here for 100 years */
58 .pmsStepID
= pmsNorm
, /* Unique identifier to this step */
59 .pmsSetCmd
= 0, /* Dummy platform power level */
60 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
61 .pmsDown
= pmsIdle
, /* Down to idle */
62 .pmsNext
= pmsNorm
/* Next step */
65 .pmsLimit
= century
, /* We can normally stay here for 100 years */
66 .pmsStepID
= pmsNormHigh
, /* Unique identifier to this step */
67 .pmsSetCmd
= 0, /* Dummy platform power level */
68 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
69 .pmsDown
= pmsIdle
, /* Down to idle */
70 .pmsNext
= pmsNormHigh
/* Next step */
73 .pmsLimit
= century
, /* We can normally stay here for 100 years */
74 .pmsStepID
= pmsBoost
, /* Unique identifier to this step */
75 .pmsSetCmd
= 0, /* Dummy platform power level */
76 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
77 .pmsDown
= pmsIdle
, /* Step down */
78 .pmsNext
= pmsBoost
/* Next step */
81 .pmsLimit
= century
, /* We can normally stay here for 100 years */
82 .pmsStepID
= pmsLow
, /* Unique identifier to this step */
83 .pmsSetCmd
= 0, /* Dummy platform power level */
84 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
85 .pmsDown
= pmsLow
, /* We always stay here */
86 .pmsNext
= pmsLow
/* We always stay here */
89 .pmsLimit
= century
, /* We can normally stay here for 100 years */
90 .pmsStepID
= pmsHigh
, /* Unique identifier to this step */
91 .pmsSetCmd
= 0, /* Dummy platform power level */
92 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
93 .pmsDown
= pmsHigh
, /* We always stay here */
94 .pmsNext
= pmsHigh
/* We always stay here */
97 .pmsLimit
= 0, /* Time doesn't matter for a prepare for change */
98 .pmsStepID
= pmsPrepCng
, /* Unique identifier to this step */
99 .pmsSetCmd
= pmsParkIt
, /* Force us to be parked */
100 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
101 .pmsDown
= pmsPrepCng
, /* We always stay here */
102 .pmsNext
= pmsPrepCng
/* We always stay here */
105 .pmsLimit
= 0, /* Time doesn't matter for a prepare for sleep */
106 .pmsStepID
= pmsPrepSleep
, /* Unique identifier to this step */
107 .pmsSetCmd
= pmsParkIt
, /* Force us to be parked */
108 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
109 .pmsDown
= pmsPrepSleep
, /* We always stay here */
110 .pmsNext
= pmsPrepSleep
/* We always stay here */
113 .pmsLimit
= 0, /* Time doesn't matter for a prepare for sleep */
114 .pmsStepID
= pmsOverTemp
, /* Unique identifier to this step */
115 .pmsSetCmd
= 0, /* Dummy platform power level */
116 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
117 .pmsDown
= pmsOverTemp
, /* We always stay here */
118 .pmsNext
= pmsOverTemp
/* We always stay here */
125 * This is where the CPU part of the stepper code lives.
127 * It also contains the "hacked kext" experimental code. This is/was used for
128 * experimentation and bringup. It should neither live long nor prosper.
133 * Set the processor frequency and stuff
136 void pmsCPUSet(uint32_t sel
) {
139 struct per_proc_info
*pp
;
141 pp
= getPerProc(); /* Get our per_proc */
143 if(!((sel
^ pp
->pms
.pmsCSetCmd
) & pmsCPU
)) return; /* If there aren't any changes, bail now... */
145 nfreq
= (sel
& pmsCPU
) >> 16; /* Isolate the new frequency */
147 switch(pp
->pf
.pfPowerModes
& pmType
) { /* Figure out what type to do */
149 case pmDFS
: /* This is a DFS machine */
150 ml_set_processor_speed_dfs(nfreq
); /* Yes, set it */
154 ml_set_processor_speed_dpll(nfreq
); /* THIS IS COMPLETELY UNTESTED!!! */
157 case pmPowerTune
: /* This is a PowerTune machine */
158 ml_set_processor_speed_powertune(nfreq
); /* Diddle the deal */
161 default: /* Not this time dolt!!! */
162 panic("pmsCPUSet: unsupported power manager type: %08X\n", pp
->pf
.pfPowerModes
);
170 * This code configures the initial step tables. It should be called after the timebase frequency is initialized.
173 void pmsCPUConf(void) {
177 pmsSetFunc_t pmsDfltFunc
[pmsSetFuncMax
]; /* List of functions for the external power control to use */
179 for(i
= 0; i
< pmsSetFuncMax
; i
++) pmsDfltFunc
[i
] = 0; /* Clear this */
182 ret
= pmsBuild((pmsDef
*)&pmsDefault
, sizeof(pmsDefault
), pmsDfltFunc
, 0, (pmsQueryFunc_t
)0); /* Configure the default stepper */
185 if(ret
!= KERN_SUCCESS
) { /* Some screw up? */
186 panic("pmsCPUConf: initial stepper table build failed, ret = %08X\n", ret
); /* Squeal */
189 pmsSetStep(pmsHigh
, 1); /* Slew to high speed */
190 pmsPark(); /* Then park */
195 * Machine-dependent initialization
198 pmsCPUMachineInit(void)
204 * This function should be called once for each processor to force the
205 * processor to the correct voltage and frequency.
208 void pmsCPUInit(void) {
212 cpu
= cpu_number(); /* Who are we? */
214 kprintf("************ Initializing stepper hardware, cpu %d ******************\n", cpu
); /* (BRINGUP) */
216 pmsSetStep(pmsHigh
, 1); /* Slew to high speed */
217 pmsPark(); /* Then park */
219 kprintf("************ Stepper hardware initialized, cpu %d ******************\n", cpu
); /* (BRINGUP) */
224 uint32_t pmsCPUQuery(void) {
227 struct per_proc_info
*pp
;
230 pp
= getPerProc(); /* Get our per_proc */
232 switch(pp
->pf
.pfPowerModes
& pmType
) { /* Figure out what type to do */
234 case pmDFS
: /* This is a DFS machine */
235 result
= hid1get(); /* Get HID1 */
236 result
= (result
>> 6) & 0x00030000; /* Isolate the DFS bits */
239 case pmPowerTune
: /* This is a PowerTune machine */
240 (void)ml_scom_read(PowerTuneStatusReg
, &scdata
); /* Get the current power level */
241 result
= (scdata
>> (32 + 8)) & 0x00030000; /* Shift the data to align with the set command */
244 default: /* Query not supported for this kind */
245 result
= 0; /* Return highest if not supported */
254 * These are not implemented for PPC.
256 void pmsCPUYellowFlag(void) {
259 void pmsCPUGreenFlag(void) {
262 uint32_t pmsCPUPackageQuery(void)
264 /* multi-core CPUs are not supported. */
265 return(~(uint32_t)0);
269 * Broadcast a change to all processors including ourselves.
270 * This must transition before broadcasting because we may block and end up on a different processor.
272 * This will block until all processors have transitioned, so
273 * obviously, this can block.
275 * Called with interruptions disabled.
279 void pmsCPURun(uint32_t nstep
) {
281 pmsRunLocal(nstep
); /* If we aren't parking (we are already parked), transition ourselves */
282 (void)cpu_broadcast(&pmsBroadcastWait
, pmsCPURemote
, nstep
); /* Tell everyone else to do it too */
289 * Receive a broadcast and react.
290 * This is called from the interprocessor signal handler.
291 * We wake up the initiator after we are finished.
295 static void pmsCPURemote(uint32_t nstep
) {
297 pmsRunLocal(nstep
); /* Go set the step */
298 if(!hw_atomic_sub(&pmsBroadcastWait
, 1)) { /* Drop the wait count */
299 thread_wakeup((event_t
)&pmsBroadcastWait
); /* If we were the last, wake up the signaller */
305 * Control the Power Management Stepper.
306 * Called from user state by the superuser via a ppc system call.
307 * Interruptions disabled.
310 int pmsCntrl(struct savearea
*save
) {
311 save
->save_r3
= pmsControl(save
->save_r3
, (user_addr_t
)(uintptr_t)save
->save_r4
, save
->save_r5
);