]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/pmsCPU.c
3350292f027b2819163da2fabcc2c44ef024c0b6
2 * Copyright (c) 2004-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 #include <ppc/machine_routines.h>
23 #include <ppc/machine_cpu.h>
24 #include <ppc/exception.h>
25 #include <ppc/misc_protos.h>
26 #include <ppc/Firmware.h>
29 #include <ppc/proc_reg.h>
31 #include <ppc/savearea.h>
32 #include <ppc/Diagnostics.h>
33 #include <kern/processor.h>
36 pmsDef pmsDefault
[] = {
38 .pmsLimit
= century
, /* We can normally stay here for 100 years */
39 .pmsStepID
= pmsIdle
, /* Unique identifier to this step */
40 .pmsSetCmd
= 0, /* Dummy platform power level */
41 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
42 .pmsDown
= pmsIdle
, /* We stay here */
43 .pmsNext
= pmsNorm
/* Next step */
46 .pmsLimit
= century
, /* We can normally stay here for 100 years */
47 .pmsStepID
= pmsNorm
, /* Unique identifier to this step */
48 .pmsSetCmd
= 0, /* Dummy platform power level */
49 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
50 .pmsDown
= pmsIdle
, /* Down to idle */
51 .pmsNext
= pmsNorm
/* Next step */
54 .pmsLimit
= century
, /* We can normally stay here for 100 years */
55 .pmsStepID
= pmsNormHigh
, /* Unique identifier to this step */
56 .pmsSetCmd
= 0, /* Dummy platform power level */
57 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
58 .pmsDown
= pmsIdle
, /* Down to idle */
59 .pmsNext
= pmsNormHigh
/* Next step */
62 .pmsLimit
= century
, /* We can normally stay here for 100 years */
63 .pmsStepID
= pmsBoost
, /* Unique identifier to this step */
64 .pmsSetCmd
= 0, /* Dummy platform power level */
65 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
66 .pmsDown
= pmsIdle
, /* Step down */
67 .pmsNext
= pmsBoost
/* Next step */
70 .pmsLimit
= century
, /* We can normally stay here for 100 years */
71 .pmsStepID
= pmsLow
, /* Unique identifier to this step */
72 .pmsSetCmd
= 0, /* Dummy platform power level */
73 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
74 .pmsDown
= pmsLow
, /* We always stay here */
75 .pmsNext
= pmsLow
/* We always stay here */
78 .pmsLimit
= century
, /* We can normally stay here for 100 years */
79 .pmsStepID
= pmsHigh
, /* Unique identifier to this step */
80 .pmsSetCmd
= 0, /* Dummy platform power level */
81 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
82 .pmsDown
= pmsHigh
, /* We always stay here */
83 .pmsNext
= pmsHigh
/* We always stay here */
86 .pmsLimit
= 0, /* Time doesn't matter for a prepare for change */
87 .pmsStepID
= pmsPrepCng
, /* Unique identifier to this step */
88 .pmsSetCmd
= pmsParkIt
, /* Force us to be parked */
89 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
90 .pmsDown
= pmsPrepCng
, /* We always stay here */
91 .pmsNext
= pmsPrepCng
/* We always stay here */
94 .pmsLimit
= 0, /* Time doesn't matter for a prepare for sleep */
95 .pmsStepID
= pmsPrepSleep
, /* Unique identifier to this step */
96 .pmsSetCmd
= pmsParkIt
, /* Force us to be parked */
97 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
98 .pmsDown
= pmsPrepSleep
, /* We always stay here */
99 .pmsNext
= pmsPrepSleep
/* We always stay here */
102 .pmsLimit
= 0, /* Time doesn't matter for a prepare for sleep */
103 .pmsStepID
= pmsOverTemp
, /* Unique identifier to this step */
104 .pmsSetCmd
= 0, /* Dummy platform power level */
105 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
106 .pmsDown
= pmsOverTemp
, /* We always stay here */
107 .pmsNext
= pmsOverTemp
/* We always stay here */
114 * This is where the CPU part of the stepper code lives.
116 * It also contains the "hacked kext" experimental code. This is/was used for
117 * experimentation and bringup. It should neither live long nor prosper.
122 * Set the processor frequency and stuff
125 void pmsCPUSet(uint32_t sel
) {
128 struct per_proc_info
*pp
;
130 pp
= getPerProc(); /* Get our per_proc */
132 if(!((sel
^ pp
->pms
.pmsCSetCmd
) & pmsCPU
)) return; /* If there aren't any changes, bail now... */
134 nfreq
= (sel
& pmsCPU
) >> 16; /* Isolate the new frequency */
136 switch(pp
->pf
.pfPowerModes
& pmType
) { /* Figure out what type to do */
138 case pmDFS
: /* This is a DFS machine */
139 ml_set_processor_speed_dfs(nfreq
); /* Yes, set it */
143 ml_set_processor_speed_dpll(nfreq
); /* THIS IS COMPLETELY UNTESTED!!! */
146 case pmPowerTune
: /* This is a PowerTune machine */
147 ml_set_processor_speed_powertune(nfreq
); /* Diddle the deal */
150 default: /* Not this time dolt!!! */
151 panic("pmsCPUSet: unsupported power manager type: %08X\n", pp
->pf
.pfPowerModes
);
159 * This code configures the initial step tables. It should be called after the timebase frequency is initialized.
162 void pmsCPUConf(void) {
166 pmsSetFunc_t pmsDfltFunc
[pmsSetFuncMax
]; /* List of functions for the external power control to use */
168 for(i
= 0; i
< pmsSetFuncMax
; i
++) pmsDfltFunc
[i
] = 0; /* Clear this */
171 ret
= pmsBuild((pmsDef
*)&pmsDefault
, sizeof(pmsDefault
), pmsDfltFunc
, 0, (pmsQueryFunc_t
)0); /* Configure the default stepper */
174 if(ret
!= KERN_SUCCESS
) { /* Some screw up? */
175 panic("pmsCPUConf: initial stepper table build failed, ret = %08X\n", ret
); /* Squeal */
178 pmsSetStep(pmsHigh
, 1); /* Slew to high speed */
179 pmsPark(); /* Then park */
184 * This function should be called once for each processor to force the
185 * processor to the correct voltage and frequency.
188 void pmsCPUInit(void) {
192 cpu
= cpu_number(); /* Who are we? */
194 kprintf("************ Initializing stepper hardware, cpu %d ******************\n", cpu
); /* (BRINGUP) */
196 pmsSetStep(pmsHigh
, 1); /* Slew to high speed */
197 pmsPark(); /* Then park */
199 kprintf("************ Stepper hardware initialized, cpu %d ******************\n", cpu
); /* (BRINGUP) */
204 uint32_t pmsCPUquery(void) {
207 struct per_proc_info
*pp
;
210 pp
= getPerProc(); /* Get our per_proc */
212 switch(pp
->pf
.pfPowerModes
& pmType
) { /* Figure out what type to do */
214 case pmDFS
: /* This is a DFS machine */
215 result
= hid1get(); /* Get HID1 */
216 result
= (result
>> 6) & 0x00030000; /* Isolate the DFS bits */
219 case pmPowerTune
: /* This is a PowerTune machine */
220 (void)ml_scom_read(PowerTuneStatusReg
, &scdata
); /* Get the current power level */
221 result
= (scdata
>> (32 + 8)) & 0x00030000; /* Shift the data to align with the set command */
224 default: /* Query not supported for this kind */
225 result
= 0; /* Return highest if not supported */