]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/pmsCPU.c
44ea326dbe53b2650f2d3816ab7e54febacd35e6
[apple/xnu.git] / osfmk / ppc / pmsCPU.c
1 /*
2 * Copyright (c) 2004-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
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
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
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.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
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>
35 #include <ppc/pmap.h>
36 #include <ppc/asm.h>
37 #include <ppc/proc_reg.h>
38 #include <ppc/pms.h>
39 #include <ppc/savearea.h>
40 #include <ppc/Diagnostics.h>
41 #include <kern/processor.h>
42
43
44 pmsDef pmsDefault[] = {
45 {
46 .pmsLimit = century, /* We can normally stay here for 100 years */
47 .pmsStepID = pmsIdle, /* Unique identifier to this step */
48 .pmsSetCmd = 0, /* Dummy platform power level */
49 .sf.pmsSetFuncInd = 0, /* Dummy platform set function */
50 .pmsDown = pmsIdle, /* We stay here */
51 .pmsNext = pmsNorm /* Next step */
52 },
53 {
54 .pmsLimit = century, /* We can normally stay here for 100 years */
55 .pmsStepID = pmsNorm, /* 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 = pmsNorm /* Next step */
60 },
61 {
62 .pmsLimit = century, /* We can normally stay here for 100 years */
63 .pmsStepID = pmsNormHigh, /* Unique identifier to this step */
64 .pmsSetCmd = 0, /* Dummy platform power level */
65 .sf.pmsSetFuncInd = 0, /* Dummy platform set function */
66 .pmsDown = pmsIdle, /* Down to idle */
67 .pmsNext = pmsNormHigh /* Next step */
68 },
69 {
70 .pmsLimit = century, /* We can normally stay here for 100 years */
71 .pmsStepID = pmsBoost, /* Unique identifier to this step */
72 .pmsSetCmd = 0, /* Dummy platform power level */
73 .sf.pmsSetFuncInd = 0, /* Dummy platform set function */
74 .pmsDown = pmsIdle, /* Step down */
75 .pmsNext = pmsBoost /* Next step */
76 },
77 {
78 .pmsLimit = century, /* We can normally stay here for 100 years */
79 .pmsStepID = pmsLow, /* Unique identifier to this step */
80 .pmsSetCmd = 0, /* Dummy platform power level */
81 .sf.pmsSetFuncInd = 0, /* Dummy platform set function */
82 .pmsDown = pmsLow, /* We always stay here */
83 .pmsNext = pmsLow /* We always stay here */
84 },
85 {
86 .pmsLimit = century, /* We can normally stay here for 100 years */
87 .pmsStepID = pmsHigh, /* Unique identifier to this step */
88 .pmsSetCmd = 0, /* Dummy platform power level */
89 .sf.pmsSetFuncInd = 0, /* Dummy platform set function */
90 .pmsDown = pmsHigh, /* We always stay here */
91 .pmsNext = pmsHigh /* We always stay here */
92 },
93 {
94 .pmsLimit = 0, /* Time doesn't matter for a prepare for change */
95 .pmsStepID = pmsPrepCng, /* Unique identifier to this step */
96 .pmsSetCmd = pmsParkIt, /* Force us to be parked */
97 .sf.pmsSetFuncInd = 0, /* Dummy platform set function */
98 .pmsDown = pmsPrepCng, /* We always stay here */
99 .pmsNext = pmsPrepCng /* We always stay here */
100 },
101 {
102 .pmsLimit = 0, /* Time doesn't matter for a prepare for sleep */
103 .pmsStepID = pmsPrepSleep, /* Unique identifier to this step */
104 .pmsSetCmd = pmsParkIt, /* Force us to be parked */
105 .sf.pmsSetFuncInd = 0, /* Dummy platform set function */
106 .pmsDown = pmsPrepSleep, /* We always stay here */
107 .pmsNext = pmsPrepSleep /* We always stay here */
108 },
109 {
110 .pmsLimit = 0, /* Time doesn't matter for a prepare for sleep */
111 .pmsStepID = pmsOverTemp, /* Unique identifier to this step */
112 .pmsSetCmd = 0, /* Dummy platform power level */
113 .sf.pmsSetFuncInd = 0, /* Dummy platform set function */
114 .pmsDown = pmsOverTemp, /* We always stay here */
115 .pmsNext = pmsOverTemp /* We always stay here */
116 }
117 };
118
119
120
121 /*
122 * This is where the CPU part of the stepper code lives.
123 *
124 * It also contains the "hacked kext" experimental code. This is/was used for
125 * experimentation and bringup. It should neither live long nor prosper.
126 *
127 */
128
129 /*
130 * Set the processor frequency and stuff
131 */
132
133 void pmsCPUSet(uint32_t sel) {
134 int nvoltage, nfreq;
135 uint32_t oldaack;
136 struct per_proc_info *pp;
137
138 pp = getPerProc(); /* Get our per_proc */
139
140 if(!((sel ^ pp->pms.pmsCSetCmd) & pmsCPU)) return; /* If there aren't any changes, bail now... */
141
142 nfreq = (sel & pmsCPU) >> 16; /* Isolate the new frequency */
143
144 switch(pp->pf.pfPowerModes & pmType) { /* Figure out what type to do */
145
146 case pmDFS: /* This is a DFS machine */
147 ml_set_processor_speed_dfs(nfreq); /* Yes, set it */
148 break;
149
150 case pmDualPLL:
151 ml_set_processor_speed_dpll(nfreq); /* THIS IS COMPLETELY UNTESTED!!! */
152 break;
153
154 case pmPowerTune: /* This is a PowerTune machine */
155 ml_set_processor_speed_powertune(nfreq); /* Diddle the deal */
156 break;
157
158 default: /* Not this time dolt!!! */
159 panic("pmsCPUSet: unsupported power manager type: %08X\n", pp->pf.pfPowerModes);
160 break;
161
162 }
163
164 }
165
166 /*
167 * This code configures the initial step tables. It should be called after the timebase frequency is initialized.
168 */
169
170 void pmsCPUConf(void) {
171
172 int i;
173 kern_return_t ret;
174 pmsSetFunc_t pmsDfltFunc[pmsSetFuncMax]; /* List of functions for the external power control to use */
175
176 for(i = 0; i < pmsSetFuncMax; i++) pmsDfltFunc[i] = 0; /* Clear this */
177
178
179 ret = pmsBuild((pmsDef *)&pmsDefault, sizeof(pmsDefault), pmsDfltFunc, 0, (pmsQueryFunc_t)0); /* Configure the default stepper */
180
181 pCCfinish:
182 if(ret != KERN_SUCCESS) { /* Some screw up? */
183 panic("pmsCPUConf: initial stepper table build failed, ret = %08X\n", ret); /* Squeal */
184 }
185
186 pmsSetStep(pmsHigh, 1); /* Slew to high speed */
187 pmsPark(); /* Then park */
188 return;
189 }
190
191 /*
192 * This function should be called once for each processor to force the
193 * processor to the correct voltage and frequency.
194 */
195
196 void pmsCPUInit(void) {
197
198 int cpu;
199
200 cpu = cpu_number(); /* Who are we? */
201
202 kprintf("************ Initializing stepper hardware, cpu %d ******************\n", cpu); /* (BRINGUP) */
203
204 pmsSetStep(pmsHigh, 1); /* Slew to high speed */
205 pmsPark(); /* Then park */
206
207 kprintf("************ Stepper hardware initialized, cpu %d ******************\n", cpu); /* (BRINGUP) */
208
209 return;
210 }
211
212 uint32_t pmsCPUquery(void) {
213
214 uint32_t result;
215 struct per_proc_info *pp;
216 uint64_t scdata;
217
218 pp = getPerProc(); /* Get our per_proc */
219
220 switch(pp->pf.pfPowerModes & pmType) { /* Figure out what type to do */
221
222 case pmDFS: /* This is a DFS machine */
223 result = hid1get(); /* Get HID1 */
224 result = (result >> 6) & 0x00030000; /* Isolate the DFS bits */
225 break;
226
227 case pmPowerTune: /* This is a PowerTune machine */
228 (void)ml_scom_read(PowerTuneStatusReg, &scdata); /* Get the current power level */
229 result = (scdata >> (32 + 8)) & 0x00030000; /* Shift the data to align with the set command */
230 break;
231
232 default: /* Query not supported for this kind */
233 result = 0; /* Return highest if not supported */
234 break;
235
236 }
237
238 return result;
239 }
240
241