]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/pmsCPU.c
81a70c9ca8c51b51efa15225bedb9b7d6e7a1034
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 pmsDef pmsDefault
[] = {
44 .pmsLimit
= century
, /* We can normally stay here for 100 years */
45 .pmsStepID
= pmsIdle
, /* Unique identifier to this step */
46 .pmsSetCmd
= 0, /* Dummy platform power level */
47 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
48 .pmsDown
= pmsIdle
, /* We stay here */
49 .pmsNext
= pmsNorm
/* Next step */
52 .pmsLimit
= century
, /* We can normally stay here for 100 years */
53 .pmsStepID
= pmsNorm
, /* Unique identifier to this step */
54 .pmsSetCmd
= 0, /* Dummy platform power level */
55 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
56 .pmsDown
= pmsIdle
, /* Down to idle */
57 .pmsNext
= pmsNorm
/* Next step */
60 .pmsLimit
= century
, /* We can normally stay here for 100 years */
61 .pmsStepID
= pmsNormHigh
, /* Unique identifier to this step */
62 .pmsSetCmd
= 0, /* Dummy platform power level */
63 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
64 .pmsDown
= pmsIdle
, /* Down to idle */
65 .pmsNext
= pmsNormHigh
/* Next step */
68 .pmsLimit
= century
, /* We can normally stay here for 100 years */
69 .pmsStepID
= pmsBoost
, /* Unique identifier to this step */
70 .pmsSetCmd
= 0, /* Dummy platform power level */
71 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
72 .pmsDown
= pmsIdle
, /* Step down */
73 .pmsNext
= pmsBoost
/* Next step */
76 .pmsLimit
= century
, /* We can normally stay here for 100 years */
77 .pmsStepID
= pmsLow
, /* Unique identifier to this step */
78 .pmsSetCmd
= 0, /* Dummy platform power level */
79 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
80 .pmsDown
= pmsLow
, /* We always stay here */
81 .pmsNext
= pmsLow
/* We always stay here */
84 .pmsLimit
= century
, /* We can normally stay here for 100 years */
85 .pmsStepID
= pmsHigh
, /* Unique identifier to this step */
86 .pmsSetCmd
= 0, /* Dummy platform power level */
87 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
88 .pmsDown
= pmsHigh
, /* We always stay here */
89 .pmsNext
= pmsHigh
/* We always stay here */
92 .pmsLimit
= 0, /* Time doesn't matter for a prepare for change */
93 .pmsStepID
= pmsPrepCng
, /* Unique identifier to this step */
94 .pmsSetCmd
= pmsParkIt
, /* Force us to be parked */
95 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
96 .pmsDown
= pmsPrepCng
, /* We always stay here */
97 .pmsNext
= pmsPrepCng
/* We always stay here */
100 .pmsLimit
= 0, /* Time doesn't matter for a prepare for sleep */
101 .pmsStepID
= pmsPrepSleep
, /* Unique identifier to this step */
102 .pmsSetCmd
= pmsParkIt
, /* Force us to be parked */
103 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
104 .pmsDown
= pmsPrepSleep
, /* We always stay here */
105 .pmsNext
= pmsPrepSleep
/* We always stay here */
108 .pmsLimit
= 0, /* Time doesn't matter for a prepare for sleep */
109 .pmsStepID
= pmsOverTemp
, /* Unique identifier to this step */
110 .pmsSetCmd
= 0, /* Dummy platform power level */
111 .sf
.pmsSetFuncInd
= 0, /* Dummy platform set function */
112 .pmsDown
= pmsOverTemp
, /* We always stay here */
113 .pmsNext
= pmsOverTemp
/* We always stay here */
120 * This is where the CPU part of the stepper code lives.
122 * It also contains the "hacked kext" experimental code. This is/was used for
123 * experimentation and bringup. It should neither live long nor prosper.
128 * Set the processor frequency and stuff
131 void pmsCPUSet(uint32_t sel
) {
134 struct per_proc_info
*pp
;
136 pp
= getPerProc(); /* Get our per_proc */
138 if(!((sel
^ pp
->pms
.pmsCSetCmd
) & pmsCPU
)) return; /* If there aren't any changes, bail now... */
140 nfreq
= (sel
& pmsCPU
) >> 16; /* Isolate the new frequency */
142 switch(pp
->pf
.pfPowerModes
& pmType
) { /* Figure out what type to do */
144 case pmDFS
: /* This is a DFS machine */
145 ml_set_processor_speed_dfs(nfreq
); /* Yes, set it */
149 ml_set_processor_speed_dpll(nfreq
); /* THIS IS COMPLETELY UNTESTED!!! */
152 case pmPowerTune
: /* This is a PowerTune machine */
153 ml_set_processor_speed_powertune(nfreq
); /* Diddle the deal */
156 default: /* Not this time dolt!!! */
157 panic("pmsCPUSet: unsupported power manager type: %08X\n", pp
->pf
.pfPowerModes
);
165 * This code configures the initial step tables. It should be called after the timebase frequency is initialized.
168 void pmsCPUConf(void) {
172 pmsSetFunc_t pmsDfltFunc
[pmsSetFuncMax
]; /* List of functions for the external power control to use */
174 for(i
= 0; i
< pmsSetFuncMax
; i
++) pmsDfltFunc
[i
] = 0; /* Clear this */
177 ret
= pmsBuild((pmsDef
*)&pmsDefault
, sizeof(pmsDefault
), pmsDfltFunc
, 0, (pmsQueryFunc_t
)0); /* Configure the default stepper */
180 if(ret
!= KERN_SUCCESS
) { /* Some screw up? */
181 panic("pmsCPUConf: initial stepper table build failed, ret = %08X\n", ret
); /* Squeal */
184 pmsSetStep(pmsHigh
, 1); /* Slew to high speed */
185 pmsPark(); /* Then park */
190 * This function should be called once for each processor to force the
191 * processor to the correct voltage and frequency.
194 void pmsCPUInit(void) {
198 cpu
= cpu_number(); /* Who are we? */
200 kprintf("************ Initializing stepper hardware, cpu %d ******************\n", cpu
); /* (BRINGUP) */
202 pmsSetStep(pmsHigh
, 1); /* Slew to high speed */
203 pmsPark(); /* Then park */
205 kprintf("************ Stepper hardware initialized, cpu %d ******************\n", cpu
); /* (BRINGUP) */
210 uint32_t pmsCPUquery(void) {
213 struct per_proc_info
*pp
;
216 pp
= getPerProc(); /* Get our per_proc */
218 switch(pp
->pf
.pfPowerModes
& pmType
) { /* Figure out what type to do */
220 case pmDFS
: /* This is a DFS machine */
221 result
= hid1get(); /* Get HID1 */
222 result
= (result
>> 6) & 0x00030000; /* Isolate the DFS bits */
225 case pmPowerTune
: /* This is a PowerTune machine */
226 (void)ml_scom_read(PowerTuneStatusReg
, &scdata
); /* Get the current power level */
227 result
= (scdata
>> (32 + 8)) & 0x00030000; /* Shift the data to align with the set command */
230 default: /* Query not supported for this kind */
231 result
= 0; /* Return highest if not supported */