speedstep-centrino.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. /*
  2. * cpufreq driver for Enhanced SpeedStep, as found in Intel's Pentium
  3. * M (part of the Centrino chipset).
  4. *
  5. * Despite the "SpeedStep" in the name, this is almost entirely unlike
  6. * traditional SpeedStep.
  7. *
  8. * Modelled on speedstep.c
  9. *
  10. * Copyright (C) 2003 Jeremy Fitzhardinge <jeremy@goop.org>
  11. *
  12. * WARNING WARNING WARNING
  13. *
  14. * This driver manipulates the PERF_CTL MSR, which is only somewhat
  15. * documented. While it seems to work on my laptop, it has not been
  16. * tested anywhere else, and it may not work for you, do strange
  17. * things or simply crash.
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/init.h>
  22. #include <linux/cpufreq.h>
  23. #include <linux/config.h>
  24. #include <linux/sched.h> /* current */
  25. #include <linux/delay.h>
  26. #include <linux/compiler.h>
  27. #ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_ACPI
  28. #include <linux/acpi.h>
  29. #include <acpi/processor.h>
  30. #endif
  31. #include <asm/msr.h>
  32. #include <asm/processor.h>
  33. #include <asm/cpufeature.h>
  34. #include "speedstep-est-common.h"
  35. #define PFX "speedstep-centrino: "
  36. #define MAINTAINER "Jeremy Fitzhardinge <jeremy@goop.org>"
  37. #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "speedstep-centrino", msg)
  38. struct cpu_id
  39. {
  40. __u8 x86; /* CPU family */
  41. __u8 x86_model; /* model */
  42. __u8 x86_mask; /* stepping */
  43. };
  44. enum {
  45. CPU_BANIAS,
  46. CPU_DOTHAN_A1,
  47. CPU_DOTHAN_A2,
  48. CPU_DOTHAN_B0,
  49. CPU_MP4HT_D0,
  50. CPU_MP4HT_E0,
  51. };
  52. static const struct cpu_id cpu_ids[] = {
  53. [CPU_BANIAS] = { 6, 9, 5 },
  54. [CPU_DOTHAN_A1] = { 6, 13, 1 },
  55. [CPU_DOTHAN_A2] = { 6, 13, 2 },
  56. [CPU_DOTHAN_B0] = { 6, 13, 6 },
  57. [CPU_MP4HT_D0] = {15, 3, 4 },
  58. [CPU_MP4HT_E0] = {15, 4, 1 },
  59. };
  60. #define N_IDS ARRAY_SIZE(cpu_ids)
  61. struct cpu_model
  62. {
  63. const struct cpu_id *cpu_id;
  64. const char *model_name;
  65. unsigned max_freq; /* max clock in kHz */
  66. struct cpufreq_frequency_table *op_points; /* clock/voltage pairs */
  67. };
  68. static int centrino_verify_cpu_id(const struct cpuinfo_x86 *c, const struct cpu_id *x);
  69. /* Operating points for current CPU */
  70. static struct cpu_model *centrino_model[NR_CPUS];
  71. static const struct cpu_id *centrino_cpu[NR_CPUS];
  72. static struct cpufreq_driver centrino_driver;
  73. #ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_TABLE
  74. /* Computes the correct form for IA32_PERF_CTL MSR for a particular
  75. frequency/voltage operating point; frequency in MHz, volts in mV.
  76. This is stored as "index" in the structure. */
  77. #define OP(mhz, mv) \
  78. { \
  79. .frequency = (mhz) * 1000, \
  80. .index = (((mhz)/100) << 8) | ((mv - 700) / 16) \
  81. }
  82. /*
  83. * These voltage tables were derived from the Intel Pentium M
  84. * datasheet, document 25261202.pdf, Table 5. I have verified they
  85. * are consistent with my IBM ThinkPad X31, which has a 1.3GHz Pentium
  86. * M.
  87. */
  88. /* Ultra Low Voltage Intel Pentium M processor 900MHz (Banias) */
  89. static struct cpufreq_frequency_table banias_900[] =
  90. {
  91. OP(600, 844),
  92. OP(800, 988),
  93. OP(900, 1004),
  94. { .frequency = CPUFREQ_TABLE_END }
  95. };
  96. /* Ultra Low Voltage Intel Pentium M processor 1000MHz (Banias) */
  97. static struct cpufreq_frequency_table banias_1000[] =
  98. {
  99. OP(600, 844),
  100. OP(800, 972),
  101. OP(900, 988),
  102. OP(1000, 1004),
  103. { .frequency = CPUFREQ_TABLE_END }
  104. };
  105. /* Low Voltage Intel Pentium M processor 1.10GHz (Banias) */
  106. static struct cpufreq_frequency_table banias_1100[] =
  107. {
  108. OP( 600, 956),
  109. OP( 800, 1020),
  110. OP( 900, 1100),
  111. OP(1000, 1164),
  112. OP(1100, 1180),
  113. { .frequency = CPUFREQ_TABLE_END }
  114. };
  115. /* Low Voltage Intel Pentium M processor 1.20GHz (Banias) */
  116. static struct cpufreq_frequency_table banias_1200[] =
  117. {
  118. OP( 600, 956),
  119. OP( 800, 1004),
  120. OP( 900, 1020),
  121. OP(1000, 1100),
  122. OP(1100, 1164),
  123. OP(1200, 1180),
  124. { .frequency = CPUFREQ_TABLE_END }
  125. };
  126. /* Intel Pentium M processor 1.30GHz (Banias) */
  127. static struct cpufreq_frequency_table banias_1300[] =
  128. {
  129. OP( 600, 956),
  130. OP( 800, 1260),
  131. OP(1000, 1292),
  132. OP(1200, 1356),
  133. OP(1300, 1388),
  134. { .frequency = CPUFREQ_TABLE_END }
  135. };
  136. /* Intel Pentium M processor 1.40GHz (Banias) */
  137. static struct cpufreq_frequency_table banias_1400[] =
  138. {
  139. OP( 600, 956),
  140. OP( 800, 1180),
  141. OP(1000, 1308),
  142. OP(1200, 1436),
  143. OP(1400, 1484),
  144. { .frequency = CPUFREQ_TABLE_END }
  145. };
  146. /* Intel Pentium M processor 1.50GHz (Banias) */
  147. static struct cpufreq_frequency_table banias_1500[] =
  148. {
  149. OP( 600, 956),
  150. OP( 800, 1116),
  151. OP(1000, 1228),
  152. OP(1200, 1356),
  153. OP(1400, 1452),
  154. OP(1500, 1484),
  155. { .frequency = CPUFREQ_TABLE_END }
  156. };
  157. /* Intel Pentium M processor 1.60GHz (Banias) */
  158. static struct cpufreq_frequency_table banias_1600[] =
  159. {
  160. OP( 600, 956),
  161. OP( 800, 1036),
  162. OP(1000, 1164),
  163. OP(1200, 1276),
  164. OP(1400, 1420),
  165. OP(1600, 1484),
  166. { .frequency = CPUFREQ_TABLE_END }
  167. };
  168. /* Intel Pentium M processor 1.70GHz (Banias) */
  169. static struct cpufreq_frequency_table banias_1700[] =
  170. {
  171. OP( 600, 956),
  172. OP( 800, 1004),
  173. OP(1000, 1116),
  174. OP(1200, 1228),
  175. OP(1400, 1308),
  176. OP(1700, 1484),
  177. { .frequency = CPUFREQ_TABLE_END }
  178. };
  179. #undef OP
  180. #define _BANIAS(cpuid, max, name) \
  181. { .cpu_id = cpuid, \
  182. .model_name = "Intel(R) Pentium(R) M processor " name "MHz", \
  183. .max_freq = (max)*1000, \
  184. .op_points = banias_##max, \
  185. }
  186. #define BANIAS(max) _BANIAS(&cpu_ids[CPU_BANIAS], max, #max)
  187. /* CPU models, their operating frequency range, and freq/voltage
  188. operating points */
  189. static struct cpu_model models[] =
  190. {
  191. _BANIAS(&cpu_ids[CPU_BANIAS], 900, " 900"),
  192. BANIAS(1000),
  193. BANIAS(1100),
  194. BANIAS(1200),
  195. BANIAS(1300),
  196. BANIAS(1400),
  197. BANIAS(1500),
  198. BANIAS(1600),
  199. BANIAS(1700),
  200. /* NULL model_name is a wildcard */
  201. { &cpu_ids[CPU_DOTHAN_A1], NULL, 0, NULL },
  202. { &cpu_ids[CPU_DOTHAN_A2], NULL, 0, NULL },
  203. { &cpu_ids[CPU_DOTHAN_B0], NULL, 0, NULL },
  204. { &cpu_ids[CPU_MP4HT_D0], NULL, 0, NULL },
  205. { &cpu_ids[CPU_MP4HT_E0], NULL, 0, NULL },
  206. { NULL, }
  207. };
  208. #undef _BANIAS
  209. #undef BANIAS
  210. static int centrino_cpu_init_table(struct cpufreq_policy *policy)
  211. {
  212. struct cpuinfo_x86 *cpu = &cpu_data[policy->cpu];
  213. struct cpu_model *model;
  214. for(model = models; model->cpu_id != NULL; model++)
  215. if (centrino_verify_cpu_id(cpu, model->cpu_id) &&
  216. (model->model_name == NULL ||
  217. strcmp(cpu->x86_model_id, model->model_name) == 0))
  218. break;
  219. if (model->cpu_id == NULL) {
  220. /* No match at all */
  221. dprintk(KERN_INFO PFX "no support for CPU model \"%s\": "
  222. "send /proc/cpuinfo to " MAINTAINER "\n",
  223. cpu->x86_model_id);
  224. return -ENOENT;
  225. }
  226. if (model->op_points == NULL) {
  227. /* Matched a non-match */
  228. dprintk(KERN_INFO PFX "no table support for CPU model \"%s\"\n",
  229. cpu->x86_model_id);
  230. #ifndef CONFIG_X86_SPEEDSTEP_CENTRINO_ACPI
  231. dprintk(KERN_INFO PFX "try compiling with CONFIG_X86_SPEEDSTEP_CENTRINO_ACPI enabled\n");
  232. #endif
  233. return -ENOENT;
  234. }
  235. centrino_model[policy->cpu] = model;
  236. dprintk("found \"%s\": max frequency: %dkHz\n",
  237. model->model_name, model->max_freq);
  238. return 0;
  239. }
  240. #else
  241. static inline int centrino_cpu_init_table(struct cpufreq_policy *policy) { return -ENODEV; }
  242. #endif /* CONFIG_X86_SPEEDSTEP_CENTRINO_TABLE */
  243. static int centrino_verify_cpu_id(const struct cpuinfo_x86 *c, const struct cpu_id *x)
  244. {
  245. if ((c->x86 == x->x86) &&
  246. (c->x86_model == x->x86_model) &&
  247. (c->x86_mask == x->x86_mask))
  248. return 1;
  249. return 0;
  250. }
  251. /* To be called only after centrino_model is initialized */
  252. static unsigned extract_clock(unsigned msr, unsigned int cpu, int failsafe)
  253. {
  254. int i;
  255. /*
  256. * Extract clock in kHz from PERF_CTL value
  257. * for centrino, as some DSDTs are buggy.
  258. * Ideally, this can be done using the acpi_data structure.
  259. */
  260. if ((centrino_cpu[cpu] == &cpu_ids[CPU_BANIAS]) ||
  261. (centrino_cpu[cpu] == &cpu_ids[CPU_DOTHAN_A1]) ||
  262. (centrino_cpu[cpu] == &cpu_ids[CPU_DOTHAN_B0])) {
  263. msr = (msr >> 8) & 0xff;
  264. return msr * 100000;
  265. }
  266. if ((!centrino_model[cpu]) || (!centrino_model[cpu]->op_points))
  267. return 0;
  268. msr &= 0xffff;
  269. for (i=0;centrino_model[cpu]->op_points[i].frequency != CPUFREQ_TABLE_END; i++) {
  270. if (msr == centrino_model[cpu]->op_points[i].index)
  271. return centrino_model[cpu]->op_points[i].frequency;
  272. }
  273. if (failsafe)
  274. return centrino_model[cpu]->op_points[i-1].frequency;
  275. else
  276. return 0;
  277. }
  278. /* Return the current CPU frequency in kHz */
  279. static unsigned int get_cur_freq(unsigned int cpu)
  280. {
  281. unsigned l, h;
  282. unsigned clock_freq;
  283. cpumask_t saved_mask;
  284. saved_mask = current->cpus_allowed;
  285. set_cpus_allowed(current, cpumask_of_cpu(cpu));
  286. if (smp_processor_id() != cpu)
  287. return 0;
  288. rdmsr(MSR_IA32_PERF_STATUS, l, h);
  289. clock_freq = extract_clock(l, cpu, 0);
  290. if (unlikely(clock_freq == 0)) {
  291. /*
  292. * On some CPUs, we can see transient MSR values (which are
  293. * not present in _PSS), while CPU is doing some automatic
  294. * P-state transition (like TM2). Get the last freq set
  295. * in PERF_CTL.
  296. */
  297. rdmsr(MSR_IA32_PERF_CTL, l, h);
  298. clock_freq = extract_clock(l, cpu, 1);
  299. }
  300. set_cpus_allowed(current, saved_mask);
  301. return clock_freq;
  302. }
  303. #ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_ACPI
  304. static struct acpi_processor_performance p;
  305. /*
  306. * centrino_cpu_init_acpi - register with ACPI P-States library
  307. *
  308. * Register with the ACPI P-States library (part of drivers/acpi/processor.c)
  309. * in order to determine correct frequency and voltage pairings by reading
  310. * the _PSS of the ACPI DSDT or SSDT tables.
  311. */
  312. static int centrino_cpu_init_acpi(struct cpufreq_policy *policy)
  313. {
  314. union acpi_object arg0 = {ACPI_TYPE_BUFFER};
  315. u32 arg0_buf[3];
  316. struct acpi_object_list arg_list = {1, &arg0};
  317. unsigned long cur_freq;
  318. int result = 0, i;
  319. unsigned int cpu = policy->cpu;
  320. /* _PDC settings */
  321. arg0.buffer.length = 12;
  322. arg0.buffer.pointer = (u8 *) arg0_buf;
  323. arg0_buf[0] = ACPI_PDC_REVISION_ID;
  324. arg0_buf[1] = 1;
  325. arg0_buf[2] = ACPI_PDC_EST_CAPABILITY_SMP_MSR;
  326. p.pdc = &arg_list;
  327. /* register with ACPI core */
  328. if (acpi_processor_register_performance(&p, cpu)) {
  329. dprintk(KERN_INFO PFX "obtaining ACPI data failed\n");
  330. return -EIO;
  331. }
  332. /* verify the acpi_data */
  333. if (p.state_count <= 1) {
  334. dprintk("No P-States\n");
  335. result = -ENODEV;
  336. goto err_unreg;
  337. }
  338. if ((p.control_register.space_id != ACPI_ADR_SPACE_FIXED_HARDWARE) ||
  339. (p.status_register.space_id != ACPI_ADR_SPACE_FIXED_HARDWARE)) {
  340. dprintk("Invalid control/status registers (%x - %x)\n",
  341. p.control_register.space_id, p.status_register.space_id);
  342. result = -EIO;
  343. goto err_unreg;
  344. }
  345. for (i=0; i<p.state_count; i++) {
  346. if (p.states[i].control != p.states[i].status) {
  347. dprintk("Different control (%llu) and status values (%llu)\n",
  348. p.states[i].control, p.states[i].status);
  349. result = -EINVAL;
  350. goto err_unreg;
  351. }
  352. if (!p.states[i].core_frequency) {
  353. dprintk("Zero core frequency for state %u\n", i);
  354. result = -EINVAL;
  355. goto err_unreg;
  356. }
  357. if (p.states[i].core_frequency > p.states[0].core_frequency) {
  358. dprintk("P%u has larger frequency (%llu) than P0 (%llu), skipping\n", i,
  359. p.states[i].core_frequency, p.states[0].core_frequency);
  360. p.states[i].core_frequency = 0;
  361. continue;
  362. }
  363. }
  364. centrino_model[cpu] = kzalloc(sizeof(struct cpu_model), GFP_KERNEL);
  365. if (!centrino_model[cpu]) {
  366. result = -ENOMEM;
  367. goto err_unreg;
  368. }
  369. centrino_model[cpu]->model_name=NULL;
  370. centrino_model[cpu]->max_freq = p.states[0].core_frequency * 1000;
  371. centrino_model[cpu]->op_points = kmalloc(sizeof(struct cpufreq_frequency_table) *
  372. (p.state_count + 1), GFP_KERNEL);
  373. if (!centrino_model[cpu]->op_points) {
  374. result = -ENOMEM;
  375. goto err_kfree;
  376. }
  377. for (i=0; i<p.state_count; i++) {
  378. centrino_model[cpu]->op_points[i].index = p.states[i].control;
  379. centrino_model[cpu]->op_points[i].frequency = p.states[i].core_frequency * 1000;
  380. dprintk("adding state %i with frequency %u and control value %04x\n",
  381. i, centrino_model[cpu]->op_points[i].frequency, centrino_model[cpu]->op_points[i].index);
  382. }
  383. centrino_model[cpu]->op_points[p.state_count].frequency = CPUFREQ_TABLE_END;
  384. cur_freq = get_cur_freq(cpu);
  385. for (i=0; i<p.state_count; i++) {
  386. if (!p.states[i].core_frequency) {
  387. dprintk("skipping state %u\n", i);
  388. centrino_model[cpu]->op_points[i].frequency = CPUFREQ_ENTRY_INVALID;
  389. continue;
  390. }
  391. if (extract_clock(centrino_model[cpu]->op_points[i].index, cpu, 0) !=
  392. (centrino_model[cpu]->op_points[i].frequency)) {
  393. dprintk("Invalid encoded frequency (%u vs. %u)\n",
  394. extract_clock(centrino_model[cpu]->op_points[i].index, cpu, 0),
  395. centrino_model[cpu]->op_points[i].frequency);
  396. result = -EINVAL;
  397. goto err_kfree_all;
  398. }
  399. if (cur_freq == centrino_model[cpu]->op_points[i].frequency)
  400. p.state = i;
  401. }
  402. /* notify BIOS that we exist */
  403. acpi_processor_notify_smm(THIS_MODULE);
  404. return 0;
  405. err_kfree_all:
  406. kfree(centrino_model[cpu]->op_points);
  407. err_kfree:
  408. kfree(centrino_model[cpu]);
  409. err_unreg:
  410. acpi_processor_unregister_performance(&p, cpu);
  411. dprintk(KERN_INFO PFX "invalid ACPI data\n");
  412. return (result);
  413. }
  414. #else
  415. static inline int centrino_cpu_init_acpi(struct cpufreq_policy *policy) { return -ENODEV; }
  416. #endif
  417. static int centrino_cpu_init(struct cpufreq_policy *policy)
  418. {
  419. struct cpuinfo_x86 *cpu = &cpu_data[policy->cpu];
  420. unsigned freq;
  421. unsigned l, h;
  422. int ret;
  423. int i;
  424. /* Only Intel makes Enhanced Speedstep-capable CPUs */
  425. if (cpu->x86_vendor != X86_VENDOR_INTEL || !cpu_has(cpu, X86_FEATURE_EST))
  426. return -ENODEV;
  427. if (is_const_loops_cpu(policy->cpu)) {
  428. centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
  429. }
  430. if (centrino_cpu_init_acpi(policy)) {
  431. if (policy->cpu != 0)
  432. return -ENODEV;
  433. for (i = 0; i < N_IDS; i++)
  434. if (centrino_verify_cpu_id(cpu, &cpu_ids[i]))
  435. break;
  436. if (i != N_IDS)
  437. centrino_cpu[policy->cpu] = &cpu_ids[i];
  438. if (!centrino_cpu[policy->cpu]) {
  439. dprintk(KERN_INFO PFX "found unsupported CPU with "
  440. "Enhanced SpeedStep: send /proc/cpuinfo to "
  441. MAINTAINER "\n");
  442. return -ENODEV;
  443. }
  444. if (centrino_cpu_init_table(policy)) {
  445. return -ENODEV;
  446. }
  447. }
  448. /* Check to see if Enhanced SpeedStep is enabled, and try to
  449. enable it if not. */
  450. rdmsr(MSR_IA32_MISC_ENABLE, l, h);
  451. if (!(l & (1<<16))) {
  452. l |= (1<<16);
  453. dprintk("trying to enable Enhanced SpeedStep (%x)\n", l);
  454. wrmsr(MSR_IA32_MISC_ENABLE, l, h);
  455. /* check to see if it stuck */
  456. rdmsr(MSR_IA32_MISC_ENABLE, l, h);
  457. if (!(l & (1<<16))) {
  458. printk(KERN_INFO PFX "couldn't enable Enhanced SpeedStep\n");
  459. return -ENODEV;
  460. }
  461. }
  462. freq = get_cur_freq(policy->cpu);
  463. policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
  464. policy->cpuinfo.transition_latency = 10000; /* 10uS transition latency */
  465. policy->cur = freq;
  466. dprintk("centrino_cpu_init: cur=%dkHz\n", policy->cur);
  467. ret = cpufreq_frequency_table_cpuinfo(policy, centrino_model[policy->cpu]->op_points);
  468. if (ret)
  469. return (ret);
  470. cpufreq_frequency_table_get_attr(centrino_model[policy->cpu]->op_points, policy->cpu);
  471. return 0;
  472. }
  473. static int centrino_cpu_exit(struct cpufreq_policy *policy)
  474. {
  475. unsigned int cpu = policy->cpu;
  476. if (!centrino_model[cpu])
  477. return -ENODEV;
  478. cpufreq_frequency_table_put_attr(cpu);
  479. #ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_ACPI
  480. if (!centrino_model[cpu]->model_name) {
  481. dprintk("unregistering and freeing ACPI data\n");
  482. acpi_processor_unregister_performance(&p, cpu);
  483. kfree(centrino_model[cpu]->op_points);
  484. kfree(centrino_model[cpu]);
  485. }
  486. #endif
  487. centrino_model[cpu] = NULL;
  488. return 0;
  489. }
  490. /**
  491. * centrino_verify - verifies a new CPUFreq policy
  492. * @policy: new policy
  493. *
  494. * Limit must be within this model's frequency range at least one
  495. * border included.
  496. */
  497. static int centrino_verify (struct cpufreq_policy *policy)
  498. {
  499. return cpufreq_frequency_table_verify(policy, centrino_model[policy->cpu]->op_points);
  500. }
  501. /**
  502. * centrino_setpolicy - set a new CPUFreq policy
  503. * @policy: new policy
  504. * @target_freq: the target frequency
  505. * @relation: how that frequency relates to achieved frequency (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H)
  506. *
  507. * Sets a new CPUFreq policy.
  508. */
  509. static int centrino_target (struct cpufreq_policy *policy,
  510. unsigned int target_freq,
  511. unsigned int relation)
  512. {
  513. unsigned int newstate = 0;
  514. unsigned int msr, oldmsr, h, cpu = policy->cpu;
  515. struct cpufreq_freqs freqs;
  516. cpumask_t saved_mask;
  517. int retval;
  518. if (centrino_model[cpu] == NULL)
  519. return -ENODEV;
  520. /*
  521. * Support for SMP systems.
  522. * Make sure we are running on the CPU that wants to change frequency
  523. */
  524. saved_mask = current->cpus_allowed;
  525. set_cpus_allowed(current, policy->cpus);
  526. if (!cpu_isset(smp_processor_id(), policy->cpus)) {
  527. dprintk("couldn't limit to CPUs in this domain\n");
  528. return(-EAGAIN);
  529. }
  530. if (cpufreq_frequency_table_target(policy, centrino_model[cpu]->op_points, target_freq,
  531. relation, &newstate)) {
  532. retval = -EINVAL;
  533. goto migrate_end;
  534. }
  535. msr = centrino_model[cpu]->op_points[newstate].index;
  536. rdmsr(MSR_IA32_PERF_CTL, oldmsr, h);
  537. if (msr == (oldmsr & 0xffff)) {
  538. retval = 0;
  539. dprintk("no change needed - msr was and needs to be %x\n", oldmsr);
  540. goto migrate_end;
  541. }
  542. freqs.cpu = cpu;
  543. freqs.old = extract_clock(oldmsr, cpu, 0);
  544. freqs.new = extract_clock(msr, cpu, 0);
  545. dprintk("target=%dkHz old=%d new=%d msr=%04x\n",
  546. target_freq, freqs.old, freqs.new, msr);
  547. cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
  548. /* all but 16 LSB are "reserved", so treat them with
  549. care */
  550. oldmsr &= ~0xffff;
  551. msr &= 0xffff;
  552. oldmsr |= msr;
  553. wrmsr(MSR_IA32_PERF_CTL, oldmsr, h);
  554. cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
  555. retval = 0;
  556. migrate_end:
  557. set_cpus_allowed(current, saved_mask);
  558. return (retval);
  559. }
  560. static struct freq_attr* centrino_attr[] = {
  561. &cpufreq_freq_attr_scaling_available_freqs,
  562. NULL,
  563. };
  564. static struct cpufreq_driver centrino_driver = {
  565. .name = "centrino", /* should be speedstep-centrino,
  566. but there's a 16 char limit */
  567. .init = centrino_cpu_init,
  568. .exit = centrino_cpu_exit,
  569. .verify = centrino_verify,
  570. .target = centrino_target,
  571. .get = get_cur_freq,
  572. .attr = centrino_attr,
  573. .owner = THIS_MODULE,
  574. };
  575. /**
  576. * centrino_init - initializes the Enhanced SpeedStep CPUFreq driver
  577. *
  578. * Initializes the Enhanced SpeedStep support. Returns -ENODEV on
  579. * unsupported devices, -ENOENT if there's no voltage table for this
  580. * particular CPU model, -EINVAL on problems during initiatization,
  581. * and zero on success.
  582. *
  583. * This is quite picky. Not only does the CPU have to advertise the
  584. * "est" flag in the cpuid capability flags, we look for a specific
  585. * CPU model and stepping, and we need to have the exact model name in
  586. * our voltage tables. That is, be paranoid about not releasing
  587. * someone's valuable magic smoke.
  588. */
  589. static int __init centrino_init(void)
  590. {
  591. struct cpuinfo_x86 *cpu = cpu_data;
  592. if (!cpu_has(cpu, X86_FEATURE_EST))
  593. return -ENODEV;
  594. return cpufreq_register_driver(&centrino_driver);
  595. }
  596. static void __exit centrino_exit(void)
  597. {
  598. cpufreq_unregister_driver(&centrino_driver);
  599. }
  600. MODULE_AUTHOR ("Jeremy Fitzhardinge <jeremy@goop.org>");
  601. MODULE_DESCRIPTION ("Enhanced SpeedStep driver for Intel Pentium M processors.");
  602. MODULE_LICENSE ("GPL");
  603. late_initcall(centrino_init);
  604. module_exit(centrino_exit);