]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/pmsCPU.c
2 * Copyright (c) 2004-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_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 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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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>
35 #include <ppc/proc_reg.h>
37 #include <ppc/savearea.h>
38 #include <ppc/Diagnostics.h>
39 #include <kern/processor.h>
42 static void pmsCPURemote(uint32_t nstep
);
45 pmsDef pmsDefault
[] = {
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
123 * This is where the CPU part of the stepper code lives.
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.
131 * Set the processor frequency and stuff
134 void pmsCPUSet(uint32_t sel
) {
137 struct per_proc_info
*pp
;
139 pp
= getPerProc(); /* Get our per_proc */
141 if(!((sel
^ pp
->pms
.pmsCSetCmd
) & pmsCPU
)) return; /* If there aren't any changes, bail now... */
143 nfreq
= (sel
& pmsCPU
) >> 16; /* Isolate the new frequency */
145 switch(pp
->pf
.pfPowerModes
& pmType
) { /* Figure out what type to do */
147 case pmDFS
: /* This is a DFS machine */
148 ml_set_processor_speed_dfs(nfreq
); /* Yes, set it */
152 ml_set_processor_speed_dpll(nfreq
); /* THIS IS COMPLETELY UNTESTED!!! */
155 case pmPowerTune
: /* This is a PowerTune machine */
156 ml_set_processor_speed_powertune(nfreq
); /* Diddle the deal */
159 default: /* Not this time dolt!!! */
160 panic("pmsCPUSet: unsupported power manager type: %08X\n", pp
->pf
.pfPowerModes
);
168 * This code configures the initial step tables. It should be called after the timebase frequency is initialized.
171 void pmsCPUConf(void) {
175 pmsSetFunc_t pmsDfltFunc
[pmsSetFuncMax
]; /* List of functions for the external power control to use */
177 for(i
= 0; i
< pmsSetFuncMax
; i
++) pmsDfltFunc
[i
] = 0; /* Clear this */
180 ret
= pmsBuild((pmsDef
*)&pmsDefault
, sizeof(pmsDefault
), pmsDfltFunc
, 0, (pmsQueryFunc_t
)0); /* Configure the default stepper */
183 if(ret
!= KERN_SUCCESS
) { /* Some screw up? */
184 panic("pmsCPUConf: initial stepper table build failed, ret = %08X\n", ret
); /* Squeal */
187 pmsSetStep(pmsHigh
, 1); /* Slew to high speed */
188 pmsPark(); /* Then park */
193 * Machine-dependent initialization
196 pmsCPUMachineInit(void)
202 * This function should be called once for each processor to force the
203 * processor to the correct voltage and frequency.
206 void pmsCPUInit(void) {
210 cpu
= cpu_number(); /* Who are we? */
212 kprintf("************ Initializing stepper hardware, cpu %d ******************\n", cpu
); /* (BRINGUP) */
214 pmsSetStep(pmsHigh
, 1); /* Slew to high speed */
215 pmsPark(); /* Then park */
217 kprintf("************ Stepper hardware initialized, cpu %d ******************\n", cpu
); /* (BRINGUP) */
222 uint32_t pmsCPUQuery(void) {
225 struct per_proc_info
*pp
;
228 pp
= getPerProc(); /* Get our per_proc */
230 switch(pp
->pf
.pfPowerModes
& pmType
) { /* Figure out what type to do */
232 case pmDFS
: /* This is a DFS machine */
233 result
= hid1get(); /* Get HID1 */
234 result
= (result
>> 6) & 0x00030000; /* Isolate the DFS bits */
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 */
242 default: /* Query not supported for this kind */
243 result
= 0; /* Return highest if not supported */
252 * These are not implemented for PPC.
254 void pmsCPUYellowFlag(void) {
257 void pmsCPUGreenFlag(void) {
260 uint32_t pmsCPUPackageQuery(void)
262 /* multi-core CPUs are not supported. */
263 return(~(uint32_t)0);
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.
270 * This will block until all processors have transitioned, so
271 * obviously, this can block.
273 * Called with interruptions disabled.
277 void pmsCPURun(uint32_t nstep
) {
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 */
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.
293 static void pmsCPURemote(uint32_t nstep
) {
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 */
303 * Control the Power Management Stepper.
304 * Called from user state by the superuser via a ppc system call.
305 * Interruptions disabled.
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
);