15 #include <linux/kernel.h>
16 #include <linux/module.h>
35 static unsigned int smi_sig;
50 #define GET_SPEEDSTEP_OWNER 0
51 #define GET_SPEEDSTEP_STATE 1
52 #define SET_SPEEDSTEP_STATE 2
53 #define GET_SPEEDSTEP_FREQS 4
62 static int speedstep_smi_ownership(
void)
66 unsigned char magic_data[] =
"Copyright (c) 1999 Intel Corporation";
68 command = (smi_sig & 0xffffff00) | (
smi_cmd & 0xff);
71 pr_debug(
"trying to obtain ownership with command %x at port %x\n",
79 "=a" (dummy),
"=b" (dummy),
"=c" (dummy),
"=d" (dummy),
81 :
"a" (command),
"b" (
function),
"c" (0),
"d" (smi_port),
100 static int speedstep_smi_get_freqs(
unsigned int *
low,
unsigned int *
high)
107 pr_debug(
"bug #1422 -- can't read freqs from BIOS\n");
111 command = (smi_sig & 0xffffff00) | (
smi_cmd & 0xff);
113 pr_debug(
"trying to determine frequencies with command %x at port %x\n",
123 "=d" (state),
"=D" (edi),
"=S" (dummy)
127 "d" (smi_port),
"S" (0),
"D" (0)
130 pr_debug(
"result %x, low_freq %u, high_freq %u\n",
131 result, low_mhz, high_mhz);
134 if ((high_mhz + low_mhz) < 600)
137 *high = high_mhz * 1000;
138 *low = low_mhz * 1000;
148 static int speedstep_get_state(
void)
153 command = (smi_sig & 0xffffff00) | (
smi_cmd & 0xff);
155 pr_debug(
"trying to determine current setting with command %x "
156 "at port %x\n", command, smi_port);
163 "=b" (state),
"=D" (edi),
164 "=c" (dummy),
"=d" (dummy),
"=S" (dummy)
165 :
"a" (command),
"b" (
function),
"c" (0),
166 "d" (smi_port),
"S" (0),
"D" (0)
169 pr_debug(
"state is %x, result is %x\n", state, result);
180 static void speedstep_set_state(
unsigned int state)
185 unsigned int retry = 0;
193 command = (smi_sig & 0xffffff00) | (
smi_cmd & 0xff);
195 pr_debug(
"trying to set frequency to state %u "
196 "with command %x at port %x\n",
197 state, command, smi_port);
201 pr_debug(
"retry %u, previous result %u, waiting...\n",
210 :
"=b" (new_state),
"=D" (result),
211 "=c" (dummy),
"=a" (dummy),
212 "=d" (dummy),
"=S" (dummy)
213 :
"a" (command),
"b" (
function),
"c" (state),
214 "d" (smi_port),
"S" (0),
"D" (0)
216 }
while ((new_state != state) && (retry <=
SMI_TRIES));
221 if (new_state == state)
222 pr_debug(
"change to %u MHz succeeded after %u tries "
224 (speedstep_freqs[new_state].
frequency / 1000),
228 "failed with new_state %u and result %u\n",
229 state, new_state, result);
244 unsigned int target_freq,
unsigned int relation)
246 unsigned int newstate = 0;
250 target_freq, relation, &newstate))
253 freqs.old = speedstep_freqs[speedstep_get_state()].
frequency;
254 freqs.new = speedstep_freqs[newstate].
frequency;
257 if (freqs.old == freqs.new)
261 speedstep_set_state(newstate);
288 if (policy->
cpu != 0)
291 result = speedstep_smi_ownership();
293 pr_debug(
"fails in acquiring ownership of a SMI interface.\n");
301 result = speedstep_smi_get_freqs(low, high);
305 pr_debug(
"could not detect low and high frequencies "
310 &speedstep_set_state);
313 pr_debug(
"could not detect two different speeds"
321 state = speedstep_get_state();
324 pr_debug(
"currently at %s speed setting - %i MHz\n",
348 static unsigned int speedstep_get(
unsigned int cpu)
358 int result = speedstep_smi_ownership();
361 pr_debug(
"fails in re-acquiring ownership of a SMI interface.\n");
366 static struct freq_attr *speedstep_attr[] = {
372 .name =
"speedstep-smi",
373 .verify = speedstep_verify,
374 .target = speedstep_target,
375 .init = speedstep_cpu_init,
376 .exit = speedstep_cpu_exit,
377 .get = speedstep_get,
378 .resume = speedstep_resume,
380 .attr = speedstep_attr,
383 static const struct x86_cpu_id ss_smi_ids[] = {
401 static int __init speedstep_init(
void)
418 pr_debug(
"No supported Intel CPU detected.\n");
422 pr_debug(
"signature:0x%.8ulx, command:0x%.8ulx, "
423 "event:0x%.8ulx, perf_level:0x%.8ulx.\n",
430 (smi_port == 0) || (
smi_cmd == 0)))
434 smi_sig = 0x47534943;
439 if ((smi_port > 0xff) || (smi_port < 0))
441 else if (smi_port == 0)
458 static void __exit speedstep_exit(
void)
467 MODULE_PARM_DESC(smi_port,
"Override the BIOS-given IST port with this value "
468 "-- Intel's default setting is 0xb2");
470 "-- Intel's default setting is 0x82");
471 MODULE_PARM_DESC(smi_sig,
"Set to 1 to fake the IST signature when using the "