]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/pmsCPU.c
2 * Copyright (c) 2004-2006 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
) {
136 struct per_proc_info
*pp
;
138 pp
= getPerProc(); /* Get our per_proc */
140 if(!((sel
^ pp
->pms
.pmsCSetCmd
) & pmsCPU
)) return; /* If there aren't any changes, bail now... */
142 nfreq
= (sel
& pmsCPU
) >> 16; /* Isolate the new frequency */
144 switch(pp
->pf
.pfPowerModes
& pmType
) { /* Figure out what type to do */
146 case pmDFS
: /* This is a DFS machine */
147 ml_set_processor_speed_dfs(nfreq
); /* Yes, set it */
151 ml_set_processor_speed_dpll(nfreq
); /* THIS IS COMPLETELY UNTESTED!!! */
154 case pmPowerTune
: /* This is a PowerTune machine */
155 ml_set_processor_speed_powertune(nfreq
); /* Diddle the deal */
158 default: /* Not this time dolt!!! */
159 panic("pmsCPUSet: unsupported power manager type: %08X\n", pp
->pf
.pfPowerModes
);
167 * This code configures the initial step tables. It should be called after the timebase frequency is initialized.
170 void pmsCPUConf(void) {
174 pmsSetFunc_t pmsDfltFunc
[pmsSetFuncMax
]; /* List of functions for the external power control to use */
176 for(i
= 0; i
< pmsSetFuncMax
; i
++) pmsDfltFunc
[i
] = NULL
; /* Clear this */
179 ret
= pmsBuild((pmsDef
*)&pmsDefault
, sizeof(pmsDefault
), pmsDfltFunc
, 0, (pmsQueryFunc_t
)0); /* Configure the default stepper */
181 if(ret
!= KERN_SUCCESS
) { /* Some screw up? */
182 panic("pmsCPUConf: initial stepper table build failed, ret = %08X\n", ret
); /* Squeal */
185 pmsSetStep(pmsHigh
, 1); /* Slew to high speed */
186 pmsPark(); /* Then park */
191 * Machine-dependent initialization
194 pmsCPUMachineInit(void)
200 * This function should be called once for each processor to force the
201 * processor to the correct voltage and frequency.
204 void pmsCPUInit(void) {
208 cpu
= cpu_number(); /* Who are we? */
210 kprintf("************ Initializing stepper hardware, cpu %d ******************\n", cpu
); /* (BRINGUP) */
212 pmsSetStep(pmsHigh
, 1); /* Slew to high speed */
213 pmsPark(); /* Then park */
215 kprintf("************ Stepper hardware initialized, cpu %d ******************\n", cpu
); /* (BRINGUP) */
218 extern uint32_t hid1get(void);
224 struct per_proc_info
*pp
;
227 pp
= getPerProc(); /* Get our per_proc */
229 switch(pp
->pf
.pfPowerModes
& pmType
) { /* Figure out what type to do */
231 case pmDFS
: /* This is a DFS machine */
232 result
= hid1get(); /* Get HID1 */
233 result
= (result
>> 6) & 0x00030000; /* Isolate the DFS bits */
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 */
241 default: /* Query not supported for this kind */
242 result
= 0; /* Return highest if not supported */
251 * These are not implemented for PPC.
253 void pmsCPUYellowFlag(void) {
256 void pmsCPUGreenFlag(void) {
259 uint32_t pmsCPUPackageQuery(void)
261 /* multi-core CPUs are not supported. */
262 return(~(uint32_t)0);
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.
269 * This will block until all processors have transitioned, so
270 * obviously, this can block.
272 * Called with interruptions disabled.
276 void pmsCPURun(uint32_t nstep
) {
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 */
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.
292 static void pmsCPURemote(uint32_t nstep
) {
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 */
302 * Control the Power Management Stepper.
303 * Called from user state by the superuser via a ppc system call.
304 * Interruptions disabled.
307 int pmsCntrl(struct savearea
*save
) {
308 save
->save_r3
= pmsControl(save
->save_r3
, (user_addr_t
)(uintptr_t)save
->save_r4
, save
->save_r5
);