]> git.saurik.com Git - apple/xnu.git/blame - osfmk/ppc/pmsCPU.c
xnu-792.21.3.tar.gz
[apple/xnu.git] / osfmk / ppc / pmsCPU.c
CommitLineData
3a60a9f5
A
1/*
2 * Copyright (c) 2004-2005 Apple Computer, Inc. All rights reserved.
3 *
8f6c56a5 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
3a60a9f5 5 *
8f6c56a5
A
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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
8ad349bb 24 * limitations under the License.
8f6c56a5
A
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
3a60a9f5
A
27 */
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>
33#include <ppc/pmap.h>
34#include <ppc/asm.h>
35#include <ppc/proc_reg.h>
21362eb3 36#include <ppc/pms.h>
3a60a9f5
A
37#include <ppc/savearea.h>
38#include <ppc/Diagnostics.h>
39#include <kern/processor.h>
40
41
42pmsDef pmsDefault[] = {
43 {
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 */
50 },
51 {
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 */
58 },
59 {
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 */
66 },
67 {
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 */
74 },
75 {
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 */
82 },
83 {
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 */
90 },
91 {
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 */
98 },
99 {
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 */
106 },
107 {
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 */
114 }
115};
116
117
118
119/*
120 * This is where the CPU part of the stepper code lives.
121 *
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.
124 *
125 */
126
127/*
128 * Set the processor frequency and stuff
129 */
130
131void pmsCPUSet(uint32_t sel) {
132 int nvoltage, nfreq;
133 uint32_t oldaack;
134 struct per_proc_info *pp;
135
136 pp = getPerProc(); /* Get our per_proc */
137
138 if(!((sel ^ pp->pms.pmsCSetCmd) & pmsCPU)) return; /* If there aren't any changes, bail now... */
139
140 nfreq = (sel & pmsCPU) >> 16; /* Isolate the new frequency */
141
142 switch(pp->pf.pfPowerModes & pmType) { /* Figure out what type to do */
143
144 case pmDFS: /* This is a DFS machine */
145 ml_set_processor_speed_dfs(nfreq); /* Yes, set it */
146 break;
147
148 case pmDualPLL:
149 ml_set_processor_speed_dpll(nfreq); /* THIS IS COMPLETELY UNTESTED!!! */
150 break;
151
152 case pmPowerTune: /* This is a PowerTune machine */
153 ml_set_processor_speed_powertune(nfreq); /* Diddle the deal */
154 break;
155
156 default: /* Not this time dolt!!! */
157 panic("pmsCPUSet: unsupported power manager type: %08X\n", pp->pf.pfPowerModes);
158 break;
159
160 }
161
162}
163
164/*
165 * This code configures the initial step tables. It should be called after the timebase frequency is initialized.
166 */
167
168void pmsCPUConf(void) {
169
170 int i;
171 kern_return_t ret;
172 pmsSetFunc_t pmsDfltFunc[pmsSetFuncMax]; /* List of functions for the external power control to use */
173
174 for(i = 0; i < pmsSetFuncMax; i++) pmsDfltFunc[i] = 0; /* Clear this */
175
176
177 ret = pmsBuild((pmsDef *)&pmsDefault, sizeof(pmsDefault), pmsDfltFunc, 0, (pmsQueryFunc_t)0); /* Configure the default stepper */
178
179pCCfinish:
180 if(ret != KERN_SUCCESS) { /* Some screw up? */
181 panic("pmsCPUConf: initial stepper table build failed, ret = %08X\n", ret); /* Squeal */
182 }
183
184 pmsSetStep(pmsHigh, 1); /* Slew to high speed */
185 pmsPark(); /* Then park */
186 return;
187}
188
189/*
190 * This function should be called once for each processor to force the
191 * processor to the correct voltage and frequency.
192 */
193
194void pmsCPUInit(void) {
195
196 int cpu;
197
198 cpu = cpu_number(); /* Who are we? */
199
200 kprintf("************ Initializing stepper hardware, cpu %d ******************\n", cpu); /* (BRINGUP) */
201
202 pmsSetStep(pmsHigh, 1); /* Slew to high speed */
203 pmsPark(); /* Then park */
204
205 kprintf("************ Stepper hardware initialized, cpu %d ******************\n", cpu); /* (BRINGUP) */
206
207 return;
208}
209
21362eb3 210uint32_t pmsCPUquery(void) {
3a60a9f5
A
211
212 uint32_t result;
213 struct per_proc_info *pp;
214 uint64_t scdata;
215
216 pp = getPerProc(); /* Get our per_proc */
217
218 switch(pp->pf.pfPowerModes & pmType) { /* Figure out what type to do */
219
220 case pmDFS: /* This is a DFS machine */
221 result = hid1get(); /* Get HID1 */
222 result = (result >> 6) & 0x00030000; /* Isolate the DFS bits */
223 break;
224
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 */
228 break;
229
230 default: /* Query not supported for this kind */
231 result = 0; /* Return highest if not supported */
232 break;
233
234 }
235
236 return result;
237}
238
239