speedstep-centrino.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  1. /*
  2. * cpufreq driver for Enhanced SpeedStep, as found in Intel's Pentium
  3. * M (part of the Centrino chipset).
  4. *
  5. * Since the original Pentium M, most new Intel CPUs support Enhanced
  6. * SpeedStep.
  7. *
  8. * Despite the "SpeedStep" in the name, this is almost entirely unlike
  9. * traditional SpeedStep.
  10. *
  11. * Modelled on speedstep.c
  12. *
  13. * Copyright (C) 2003 Jeremy Fitzhardinge <jeremy@goop.org>
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/init.h>
  18. #include <linux/cpufreq.h>
  19. #include <linux/sched.h> /* current */
  20. #include <linux/delay.h>
  21. #include <linux/compiler.h>
  22. #ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_ACPI
  23. #include <linux/acpi.h>
  24. #include <linux/dmi.h>
  25. #include <acpi/processor.h>
  26. #endif
  27. #include <asm/msr.h>
  28. #include <asm/processor.h>
  29. #include <asm/cpufeature.h>
  30. #define PFX "speedstep-centrino: "
  31. #define MAINTAINER "cpufreq@lists.linux.org.uk"
  32. #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "speedstep-centrino", msg)
  33. #define INTEL_MSR_RANGE (0xffff)
  34. struct cpu_id
  35. {
  36. __u8 x86; /* CPU family */
  37. __u8 x86_model; /* model */
  38. __u8 x86_mask; /* stepping */
  39. };
  40. enum {
  41. CPU_BANIAS,
  42. CPU_DOTHAN_A1,
  43. CPU_DOTHAN_A2,
  44. CPU_DOTHAN_B0,
  45. CPU_MP4HT_D0,
  46. CPU_MP4HT_E0,
  47. };
  48. static const struct cpu_id cpu_ids[] = {
  49. [CPU_BANIAS] = { 6, 9, 5 },
  50. [CPU_DOTHAN_A1] = { 6, 13, 1 },
  51. [CPU_DOTHAN_A2] = { 6, 13, 2 },
  52. [CPU_DOTHAN_B0] = { 6, 13, 6 },
  53. [CPU_MP4HT_D0] = {15, 3, 4 },
  54. [CPU_MP4HT_E0] = {15, 4, 1 },
  55. };
  56. #define N_IDS ARRAY_SIZE(cpu_ids)
  57. struct cpu_model
  58. {
  59. const struct cpu_id *cpu_id;
  60. const char *model_name;
  61. unsigned max_freq; /* max clock in kHz */
  62. struct cpufreq_frequency_table *op_points; /* clock/voltage pairs */
  63. };
  64. static int centrino_verify_cpu_id(const struct cpuinfo_x86 *c, const struct cpu_id *x);
  65. /* Operating points for current CPU */
  66. static struct cpu_model *centrino_model[NR_CPUS];
  67. static const struct cpu_id *centrino_cpu[NR_CPUS];
  68. static struct cpufreq_driver centrino_driver;
  69. #ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_TABLE
  70. /* Computes the correct form for IA32_PERF_CTL MSR for a particular
  71. frequency/voltage operating point; frequency in MHz, volts in mV.
  72. This is stored as "index" in the structure. */
  73. #define OP(mhz, mv) \
  74. { \
  75. .frequency = (mhz) * 1000, \
  76. .index = (((mhz)/100) << 8) | ((mv - 700) / 16) \
  77. }
  78. /*
  79. * These voltage tables were derived from the Intel Pentium M
  80. * datasheet, document 25261202.pdf, Table 5. I have verified they
  81. * are consistent with my IBM ThinkPad X31, which has a 1.3GHz Pentium
  82. * M.
  83. */
  84. /* Ultra Low Voltage Intel Pentium M processor 900MHz (Banias) */
  85. static struct cpufreq_frequency_table banias_900[] =
  86. {
  87. OP(600, 844),
  88. OP(800, 988),
  89. OP(900, 1004),
  90. { .frequency = CPUFREQ_TABLE_END }
  91. };
  92. /* Ultra Low Voltage Intel Pentium M processor 1000MHz (Banias) */
  93. static struct cpufreq_frequency_table banias_1000[] =
  94. {
  95. OP(600, 844),
  96. OP(800, 972),
  97. OP(900, 988),
  98. OP(1000, 1004),
  99. { .frequency = CPUFREQ_TABLE_END }
  100. };
  101. /* Low Voltage Intel Pentium M processor 1.10GHz (Banias) */
  102. static struct cpufreq_frequency_table banias_1100[] =
  103. {
  104. OP( 600, 956),
  105. OP( 800, 1020),
  106. OP( 900, 1100),
  107. OP(1000, 1164),
  108. OP(1100, 1180),
  109. { .frequency = CPUFREQ_TABLE_END }
  110. };
  111. /* Low Voltage Intel Pentium M processor 1.20GHz (Banias) */
  112. static struct cpufreq_frequency_table banias_1200[] =
  113. {
  114. OP( 600, 956),
  115. OP( 800, 1004),
  116. OP( 900, 1020),
  117. OP(1000, 1100),
  118. OP(1100, 1164),
  119. OP(1200, 1180),
  120. { .frequency = CPUFREQ_TABLE_END }
  121. };
  122. /* Intel Pentium M processor 1.30GHz (Banias) */
  123. static struct cpufreq_frequency_table banias_1300[] =
  124. {
  125. OP( 600, 956),
  126. OP( 800, 1260),
  127. OP(1000, 1292),
  128. OP(1200, 1356),
  129. OP(1300, 1388),
  130. { .frequency = CPUFREQ_TABLE_END }
  131. };
  132. /* Intel Pentium M processor 1.40GHz (Banias) */
  133. static struct cpufreq_frequency_table banias_1400[] =
  134. {
  135. OP( 600, 956),
  136. OP( 800, 1180),
  137. OP(1000, 1308),
  138. OP(1200, 1436),
  139. OP(1400, 1484),
  140. { .frequency = CPUFREQ_TABLE_END }
  141. };
  142. /* Intel Pentium M processor 1.50GHz (Banias) */
  143. static struct cpufreq_frequency_table banias_1500[] =
  144. {
  145. OP( 600, 956),
  146. OP( 800, 1116),
  147. OP(1000, 1228),
  148. OP(1200, 1356),
  149. OP(1400, 1452),
  150. OP(1500, 1484),
  151. { .frequency = CPUFREQ_TABLE_END }
  152. };
  153. /* Intel Pentium M processor 1.60GHz (Banias) */
  154. static struct cpufreq_frequency_table banias_1600[] =
  155. {
  156. OP( 600, 956),
  157. OP( 800, 1036),
  158. OP(1000, 1164),
  159. OP(1200, 1276),
  160. OP(1400, 1420),
  161. OP(1600, 1484),
  162. { .frequency = CPUFREQ_TABLE_END }
  163. };
  164. /* Intel Pentium M processor 1.70GHz (Banias) */
  165. static struct cpufreq_frequency_table banias_1700[] =
  166. {
  167. OP( 600, 956),
  168. OP( 800, 1004),
  169. OP(1000, 1116),
  170. OP(1200, 1228),
  171. OP(1400, 1308),
  172. OP(1700, 1484),
  173. { .frequency = CPUFREQ_TABLE_END }
  174. };
  175. #undef OP
  176. #define _BANIAS(cpuid, max, name) \
  177. { .cpu_id = cpuid, \
  178. .model_name = "Intel(R) Pentium(R) M processor " name "MHz", \
  179. .max_freq = (max)*1000, \
  180. .op_points = banias_##max, \
  181. }
  182. #define BANIAS(max) _BANIAS(&cpu_ids[CPU_BANIAS], max, #max)
  183. /* CPU models, their operating frequency range, and freq/voltage
  184. operating points */
  185. static struct cpu_model models[] =
  186. {
  187. _BANIAS(&cpu_ids[CPU_BANIAS], 900, " 900"),
  188. BANIAS(1000),
  189. BANIAS(1100),
  190. BANIAS(1200),
  191. BANIAS(1300),
  192. BANIAS(1400),
  193. BANIAS(1500),
  194. BANIAS(1600),
  195. BANIAS(1700),
  196. /* NULL model_name is a wildcard */
  197. { &cpu_ids[CPU_DOTHAN_A1], NULL, 0, NULL },
  198. { &cpu_ids[CPU_DOTHAN_A2], NULL, 0, NULL },
  199. { &cpu_ids[CPU_DOTHAN_B0], NULL, 0, NULL },
  200. { &cpu_ids[CPU_MP4HT_D0], NULL, 0, NULL },
  201. { &cpu_ids[CPU_MP4HT_E0], NULL, 0, NULL },
  202. { NULL, }
  203. };
  204. #undef _BANIAS
  205. #undef BANIAS
  206. static int centrino_cpu_init_table(struct cpufreq_policy *policy)
  207. {
  208. struct cpuinfo_x86 *cpu = &cpu_data[policy->cpu];
  209. struct cpu_model *model;
  210. for(model = models; model->cpu_id != NULL; model++)
  211. if (centrino_verify_cpu_id(cpu, model->cpu_id) &&
  212. (model->model_name == NULL ||
  213. strcmp(cpu->x86_model_id, model->model_name) == 0))
  214. break;
  215. if (model->cpu_id == NULL) {
  216. /* No match at all */
  217. dprintk("no support for CPU model \"%s\": "
  218. "send /proc/cpuinfo to " MAINTAINER "\n",
  219. cpu->x86_model_id);
  220. return -ENOENT;
  221. }
  222. if (model->op_points == NULL) {
  223. /* Matched a non-match */
  224. dprintk("no table support for CPU model \"%s\"\n",
  225. cpu->x86_model_id);
  226. #ifndef CONFIG_X86_SPEEDSTEP_CENTRINO_ACPI
  227. dprintk("try compiling with CONFIG_X86_SPEEDSTEP_CENTRINO_ACPI enabled\n");
  228. #endif
  229. return -ENOENT;
  230. }
  231. centrino_model[policy->cpu] = model;
  232. dprintk("found \"%s\": max frequency: %dkHz\n",
  233. model->model_name, model->max_freq);
  234. return 0;
  235. }
  236. #else
  237. static inline int centrino_cpu_init_table(struct cpufreq_policy *policy) { return -ENODEV; }
  238. #endif /* CONFIG_X86_SPEEDSTEP_CENTRINO_TABLE */
  239. static int centrino_verify_cpu_id(const struct cpuinfo_x86 *c, const struct cpu_id *x)
  240. {
  241. if ((c->x86 == x->x86) &&
  242. (c->x86_model == x->x86_model) &&
  243. (c->x86_mask == x->x86_mask))
  244. return 1;
  245. return 0;
  246. }
  247. /* To be called only after centrino_model is initialized */
  248. static unsigned extract_clock(unsigned msr, unsigned int cpu, int failsafe)
  249. {
  250. int i;
  251. /*
  252. * Extract clock in kHz from PERF_CTL value
  253. * for centrino, as some DSDTs are buggy.
  254. * Ideally, this can be done using the acpi_data structure.
  255. */
  256. if ((centrino_cpu[cpu] == &cpu_ids[CPU_BANIAS]) ||
  257. (centrino_cpu[cpu] == &cpu_ids[CPU_DOTHAN_A1]) ||
  258. (centrino_cpu[cpu] == &cpu_ids[CPU_DOTHAN_B0])) {
  259. msr = (msr >> 8) & 0xff;
  260. return msr * 100000;
  261. }
  262. if ((!centrino_model[cpu]) || (!centrino_model[cpu]->op_points))
  263. return 0;
  264. msr &= 0xffff;
  265. for (i=0;centrino_model[cpu]->op_points[i].frequency != CPUFREQ_TABLE_END; i++) {
  266. if (msr == centrino_model[cpu]->op_points[i].index)
  267. return centrino_model[cpu]->op_points[i].frequency;
  268. }
  269. if (failsafe)
  270. return centrino_model[cpu]->op_points[i-1].frequency;
  271. else
  272. return 0;
  273. }
  274. /* Return the current CPU frequency in kHz */
  275. static unsigned int get_cur_freq(unsigned int cpu)
  276. {
  277. unsigned l, h;
  278. unsigned clock_freq;
  279. cpumask_t saved_mask;
  280. saved_mask = current->cpus_allowed;
  281. set_cpus_allowed(current, cpumask_of_cpu(cpu));
  282. if (smp_processor_id() != cpu)
  283. return 0;
  284. rdmsr(MSR_IA32_PERF_STATUS, l, h);
  285. clock_freq = extract_clock(l, cpu, 0);
  286. if (unlikely(clock_freq == 0)) {
  287. /*
  288. * On some CPUs, we can see transient MSR values (which are
  289. * not present in _PSS), while CPU is doing some automatic
  290. * P-state transition (like TM2). Get the last freq set
  291. * in PERF_CTL.
  292. */
  293. rdmsr(MSR_IA32_PERF_CTL, l, h);
  294. clock_freq = extract_clock(l, cpu, 1);
  295. }
  296. set_cpus_allowed(current, saved_mask);
  297. return clock_freq;
  298. }
  299. #ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_ACPI
  300. static struct acpi_processor_performance *acpi_perf_data[NR_CPUS];
  301. /*
  302. * centrino_cpu_early_init_acpi - Do the preregistering with ACPI P-States
  303. * library
  304. *
  305. * Before doing the actual init, we need to do _PSD related setup whenever
  306. * supported by the BIOS. These are handled by this early_init routine.
  307. */
  308. static int centrino_cpu_early_init_acpi(void)
  309. {
  310. unsigned int i, j;
  311. struct acpi_processor_performance *data;
  312. for_each_possible_cpu(i) {
  313. data = kzalloc(sizeof(struct acpi_processor_performance),
  314. GFP_KERNEL);
  315. if (!data) {
  316. for_each_possible_cpu(j) {
  317. kfree(acpi_perf_data[j]);
  318. acpi_perf_data[j] = NULL;
  319. }
  320. return (-ENOMEM);
  321. }
  322. acpi_perf_data[i] = data;
  323. }
  324. acpi_processor_preregister_performance(acpi_perf_data);
  325. return 0;
  326. }
  327. #ifdef CONFIG_SMP
  328. /*
  329. * Some BIOSes do SW_ANY coordination internally, either set it up in hw
  330. * or do it in BIOS firmware and won't inform about it to OS. If not
  331. * detected, this has a side effect of making CPU run at a different speed
  332. * than OS intended it to run at. Detect it and handle it cleanly.
  333. */
  334. static int bios_with_sw_any_bug;
  335. static int sw_any_bug_found(struct dmi_system_id *d)
  336. {
  337. bios_with_sw_any_bug = 1;
  338. return 0;
  339. }
  340. static struct dmi_system_id sw_any_bug_dmi_table[] = {
  341. {
  342. .callback = sw_any_bug_found,
  343. .ident = "Supermicro Server X6DLP",
  344. .matches = {
  345. DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
  346. DMI_MATCH(DMI_BIOS_VERSION, "080010"),
  347. DMI_MATCH(DMI_PRODUCT_NAME, "X6DLP"),
  348. },
  349. },
  350. { }
  351. };
  352. #endif
  353. /*
  354. * centrino_cpu_init_acpi - register with ACPI P-States library
  355. *
  356. * Register with the ACPI P-States library (part of drivers/acpi/processor.c)
  357. * in order to determine correct frequency and voltage pairings by reading
  358. * the _PSS of the ACPI DSDT or SSDT tables.
  359. */
  360. static int centrino_cpu_init_acpi(struct cpufreq_policy *policy)
  361. {
  362. unsigned long cur_freq;
  363. int result = 0, i;
  364. unsigned int cpu = policy->cpu;
  365. struct acpi_processor_performance *p;
  366. p = acpi_perf_data[cpu];
  367. /* register with ACPI core */
  368. if (acpi_processor_register_performance(p, cpu)) {
  369. dprintk(PFX "obtaining ACPI data failed\n");
  370. return -EIO;
  371. }
  372. policy->shared_type = p->shared_type;
  373. /*
  374. * Will let policy->cpus know about dependency only when software
  375. * coordination is required.
  376. */
  377. if (policy->shared_type == CPUFREQ_SHARED_TYPE_ALL ||
  378. policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) {
  379. policy->cpus = p->shared_cpu_map;
  380. }
  381. #ifdef CONFIG_SMP
  382. dmi_check_system(sw_any_bug_dmi_table);
  383. if (bios_with_sw_any_bug && cpus_weight(policy->cpus) == 1) {
  384. policy->shared_type = CPUFREQ_SHARED_TYPE_ALL;
  385. policy->cpus = cpu_core_map[cpu];
  386. }
  387. #endif
  388. /* verify the acpi_data */
  389. if (p->state_count <= 1) {
  390. dprintk("No P-States\n");
  391. result = -ENODEV;
  392. goto err_unreg;
  393. }
  394. if ((p->control_register.space_id != ACPI_ADR_SPACE_FIXED_HARDWARE) ||
  395. (p->status_register.space_id != ACPI_ADR_SPACE_FIXED_HARDWARE)) {
  396. dprintk("Invalid control/status registers (%x - %x)\n",
  397. p->control_register.space_id, p->status_register.space_id);
  398. result = -EIO;
  399. goto err_unreg;
  400. }
  401. for (i=0; i<p->state_count; i++) {
  402. if ((p->states[i].control & INTEL_MSR_RANGE) !=
  403. (p->states[i].status & INTEL_MSR_RANGE)) {
  404. dprintk("Different MSR bits in control (%llu) and status (%llu)\n",
  405. p->states[i].control, p->states[i].status);
  406. result = -EINVAL;
  407. goto err_unreg;
  408. }
  409. if (!p->states[i].core_frequency) {
  410. dprintk("Zero core frequency for state %u\n", i);
  411. result = -EINVAL;
  412. goto err_unreg;
  413. }
  414. if (p->states[i].core_frequency > p->states[0].core_frequency) {
  415. dprintk("P%u has larger frequency (%llu) than P0 (%llu), skipping\n", i,
  416. p->states[i].core_frequency, p->states[0].core_frequency);
  417. p->states[i].core_frequency = 0;
  418. continue;
  419. }
  420. }
  421. centrino_model[cpu] = kzalloc(sizeof(struct cpu_model), GFP_KERNEL);
  422. if (!centrino_model[cpu]) {
  423. result = -ENOMEM;
  424. goto err_unreg;
  425. }
  426. centrino_model[cpu]->model_name=NULL;
  427. centrino_model[cpu]->max_freq = p->states[0].core_frequency * 1000;
  428. centrino_model[cpu]->op_points = kmalloc(sizeof(struct cpufreq_frequency_table) *
  429. (p->state_count + 1), GFP_KERNEL);
  430. if (!centrino_model[cpu]->op_points) {
  431. result = -ENOMEM;
  432. goto err_kfree;
  433. }
  434. for (i=0; i<p->state_count; i++) {
  435. centrino_model[cpu]->op_points[i].index = p->states[i].control & INTEL_MSR_RANGE;
  436. centrino_model[cpu]->op_points[i].frequency = p->states[i].core_frequency * 1000;
  437. dprintk("adding state %i with frequency %u and control value %04x\n",
  438. i, centrino_model[cpu]->op_points[i].frequency, centrino_model[cpu]->op_points[i].index);
  439. }
  440. centrino_model[cpu]->op_points[p->state_count].frequency = CPUFREQ_TABLE_END;
  441. cur_freq = get_cur_freq(cpu);
  442. for (i=0; i<p->state_count; i++) {
  443. if (!p->states[i].core_frequency) {
  444. dprintk("skipping state %u\n", i);
  445. centrino_model[cpu]->op_points[i].frequency = CPUFREQ_ENTRY_INVALID;
  446. continue;
  447. }
  448. if (extract_clock(centrino_model[cpu]->op_points[i].index, cpu, 0) !=
  449. (centrino_model[cpu]->op_points[i].frequency)) {
  450. dprintk("Invalid encoded frequency (%u vs. %u)\n",
  451. extract_clock(centrino_model[cpu]->op_points[i].index, cpu, 0),
  452. centrino_model[cpu]->op_points[i].frequency);
  453. result = -EINVAL;
  454. goto err_kfree_all;
  455. }
  456. if (cur_freq == centrino_model[cpu]->op_points[i].frequency)
  457. p->state = i;
  458. }
  459. /* notify BIOS that we exist */
  460. acpi_processor_notify_smm(THIS_MODULE);
  461. printk("speedstep-centrino with X86_SPEEDSTEP_CENTRINO_ACPI "
  462. "config is deprecated.\n "
  463. "Use X86_ACPI_CPUFREQ (acpi-cpufreq) instead.\n" );
  464. return 0;
  465. err_kfree_all:
  466. kfree(centrino_model[cpu]->op_points);
  467. err_kfree:
  468. kfree(centrino_model[cpu]);
  469. err_unreg:
  470. acpi_processor_unregister_performance(p, cpu);
  471. dprintk(PFX "invalid ACPI data\n");
  472. return (result);
  473. }
  474. #else
  475. static inline int centrino_cpu_init_acpi(struct cpufreq_policy *policy) { return -ENODEV; }
  476. static inline int centrino_cpu_early_init_acpi(void) { return 0; }
  477. #endif
  478. static int centrino_cpu_init(struct cpufreq_policy *policy)
  479. {
  480. struct cpuinfo_x86 *cpu = &cpu_data[policy->cpu];
  481. unsigned freq;
  482. unsigned l, h;
  483. int ret;
  484. int i;
  485. /* Only Intel makes Enhanced Speedstep-capable CPUs */
  486. if (cpu->x86_vendor != X86_VENDOR_INTEL || !cpu_has(cpu, X86_FEATURE_EST))
  487. return -ENODEV;
  488. if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
  489. centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
  490. if (centrino_cpu_init_acpi(policy)) {
  491. if (policy->cpu != 0)
  492. return -ENODEV;
  493. for (i = 0; i < N_IDS; i++)
  494. if (centrino_verify_cpu_id(cpu, &cpu_ids[i]))
  495. break;
  496. if (i != N_IDS)
  497. centrino_cpu[policy->cpu] = &cpu_ids[i];
  498. if (!centrino_cpu[policy->cpu]) {
  499. dprintk("found unsupported CPU with "
  500. "Enhanced SpeedStep: send /proc/cpuinfo to "
  501. MAINTAINER "\n");
  502. return -ENODEV;
  503. }
  504. if (centrino_cpu_init_table(policy)) {
  505. return -ENODEV;
  506. }
  507. }
  508. /* Check to see if Enhanced SpeedStep is enabled, and try to
  509. enable it if not. */
  510. rdmsr(MSR_IA32_MISC_ENABLE, l, h);
  511. if (!(l & (1<<16))) {
  512. l |= (1<<16);
  513. dprintk("trying to enable Enhanced SpeedStep (%x)\n", l);
  514. wrmsr(MSR_IA32_MISC_ENABLE, l, h);
  515. /* check to see if it stuck */
  516. rdmsr(MSR_IA32_MISC_ENABLE, l, h);
  517. if (!(l & (1<<16))) {
  518. printk(KERN_INFO PFX "couldn't enable Enhanced SpeedStep\n");
  519. return -ENODEV;
  520. }
  521. }
  522. freq = get_cur_freq(policy->cpu);
  523. policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
  524. policy->cpuinfo.transition_latency = 10000; /* 10uS transition latency */
  525. policy->cur = freq;
  526. dprintk("centrino_cpu_init: cur=%dkHz\n", policy->cur);
  527. ret = cpufreq_frequency_table_cpuinfo(policy, centrino_model[policy->cpu]->op_points);
  528. if (ret)
  529. return (ret);
  530. cpufreq_frequency_table_get_attr(centrino_model[policy->cpu]->op_points, policy->cpu);
  531. return 0;
  532. }
  533. static int centrino_cpu_exit(struct cpufreq_policy *policy)
  534. {
  535. unsigned int cpu = policy->cpu;
  536. if (!centrino_model[cpu])
  537. return -ENODEV;
  538. cpufreq_frequency_table_put_attr(cpu);
  539. #ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_ACPI
  540. if (!centrino_model[cpu]->model_name) {
  541. static struct acpi_processor_performance *p;
  542. if (acpi_perf_data[cpu]) {
  543. p = acpi_perf_data[cpu];
  544. dprintk("unregistering and freeing ACPI data\n");
  545. acpi_processor_unregister_performance(p, cpu);
  546. kfree(centrino_model[cpu]->op_points);
  547. kfree(centrino_model[cpu]);
  548. }
  549. }
  550. #endif
  551. centrino_model[cpu] = NULL;
  552. return 0;
  553. }
  554. /**
  555. * centrino_verify - verifies a new CPUFreq policy
  556. * @policy: new policy
  557. *
  558. * Limit must be within this model's frequency range at least one
  559. * border included.
  560. */
  561. static int centrino_verify (struct cpufreq_policy *policy)
  562. {
  563. return cpufreq_frequency_table_verify(policy, centrino_model[policy->cpu]->op_points);
  564. }
  565. /**
  566. * centrino_setpolicy - set a new CPUFreq policy
  567. * @policy: new policy
  568. * @target_freq: the target frequency
  569. * @relation: how that frequency relates to achieved frequency (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H)
  570. *
  571. * Sets a new CPUFreq policy.
  572. */
  573. static int centrino_target (struct cpufreq_policy *policy,
  574. unsigned int target_freq,
  575. unsigned int relation)
  576. {
  577. unsigned int newstate = 0;
  578. unsigned int msr, oldmsr = 0, h = 0, cpu = policy->cpu;
  579. struct cpufreq_freqs freqs;
  580. cpumask_t online_policy_cpus;
  581. cpumask_t saved_mask;
  582. cpumask_t set_mask;
  583. cpumask_t covered_cpus;
  584. int retval = 0;
  585. unsigned int j, k, first_cpu, tmp;
  586. if (unlikely(centrino_model[cpu] == NULL))
  587. return -ENODEV;
  588. if (unlikely(cpufreq_frequency_table_target(policy,
  589. centrino_model[cpu]->op_points,
  590. target_freq,
  591. relation,
  592. &newstate))) {
  593. return -EINVAL;
  594. }
  595. #ifdef CONFIG_HOTPLUG_CPU
  596. /* cpufreq holds the hotplug lock, so we are safe from here on */
  597. cpus_and(online_policy_cpus, cpu_online_map, policy->cpus);
  598. #else
  599. online_policy_cpus = policy->cpus;
  600. #endif
  601. saved_mask = current->cpus_allowed;
  602. first_cpu = 1;
  603. cpus_clear(covered_cpus);
  604. for_each_cpu_mask(j, online_policy_cpus) {
  605. /*
  606. * Support for SMP systems.
  607. * Make sure we are running on CPU that wants to change freq
  608. */
  609. cpus_clear(set_mask);
  610. if (policy->shared_type == CPUFREQ_SHARED_TYPE_ANY)
  611. cpus_or(set_mask, set_mask, online_policy_cpus);
  612. else
  613. cpu_set(j, set_mask);
  614. set_cpus_allowed(current, set_mask);
  615. preempt_disable();
  616. if (unlikely(!cpu_isset(smp_processor_id(), set_mask))) {
  617. dprintk("couldn't limit to CPUs in this domain\n");
  618. retval = -EAGAIN;
  619. if (first_cpu) {
  620. /* We haven't started the transition yet. */
  621. goto migrate_end;
  622. }
  623. preempt_enable();
  624. break;
  625. }
  626. msr = centrino_model[cpu]->op_points[newstate].index;
  627. if (first_cpu) {
  628. rdmsr(MSR_IA32_PERF_CTL, oldmsr, h);
  629. if (msr == (oldmsr & 0xffff)) {
  630. dprintk("no change needed - msr was and needs "
  631. "to be %x\n", oldmsr);
  632. retval = 0;
  633. goto migrate_end;
  634. }
  635. freqs.old = extract_clock(oldmsr, cpu, 0);
  636. freqs.new = extract_clock(msr, cpu, 0);
  637. dprintk("target=%dkHz old=%d new=%d msr=%04x\n",
  638. target_freq, freqs.old, freqs.new, msr);
  639. for_each_cpu_mask(k, online_policy_cpus) {
  640. freqs.cpu = k;
  641. cpufreq_notify_transition(&freqs,
  642. CPUFREQ_PRECHANGE);
  643. }
  644. first_cpu = 0;
  645. /* all but 16 LSB are reserved, treat them with care */
  646. oldmsr &= ~0xffff;
  647. msr &= 0xffff;
  648. oldmsr |= msr;
  649. }
  650. wrmsr(MSR_IA32_PERF_CTL, oldmsr, h);
  651. if (policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) {
  652. preempt_enable();
  653. break;
  654. }
  655. cpu_set(j, covered_cpus);
  656. preempt_enable();
  657. }
  658. for_each_cpu_mask(k, online_policy_cpus) {
  659. freqs.cpu = k;
  660. cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
  661. }
  662. if (unlikely(retval)) {
  663. /*
  664. * We have failed halfway through the frequency change.
  665. * We have sent callbacks to policy->cpus and
  666. * MSRs have already been written on coverd_cpus.
  667. * Best effort undo..
  668. */
  669. if (!cpus_empty(covered_cpus)) {
  670. for_each_cpu_mask(j, covered_cpus) {
  671. set_cpus_allowed(current, cpumask_of_cpu(j));
  672. wrmsr(MSR_IA32_PERF_CTL, oldmsr, h);
  673. }
  674. }
  675. tmp = freqs.new;
  676. freqs.new = freqs.old;
  677. freqs.old = tmp;
  678. for_each_cpu_mask(j, online_policy_cpus) {
  679. freqs.cpu = j;
  680. cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
  681. cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
  682. }
  683. }
  684. set_cpus_allowed(current, saved_mask);
  685. return 0;
  686. migrate_end:
  687. preempt_enable();
  688. set_cpus_allowed(current, saved_mask);
  689. return 0;
  690. }
  691. static struct freq_attr* centrino_attr[] = {
  692. &cpufreq_freq_attr_scaling_available_freqs,
  693. NULL,
  694. };
  695. static struct cpufreq_driver centrino_driver = {
  696. .name = "centrino", /* should be speedstep-centrino,
  697. but there's a 16 char limit */
  698. .init = centrino_cpu_init,
  699. .exit = centrino_cpu_exit,
  700. .verify = centrino_verify,
  701. .target = centrino_target,
  702. .get = get_cur_freq,
  703. .attr = centrino_attr,
  704. .owner = THIS_MODULE,
  705. };
  706. /**
  707. * centrino_init - initializes the Enhanced SpeedStep CPUFreq driver
  708. *
  709. * Initializes the Enhanced SpeedStep support. Returns -ENODEV on
  710. * unsupported devices, -ENOENT if there's no voltage table for this
  711. * particular CPU model, -EINVAL on problems during initiatization,
  712. * and zero on success.
  713. *
  714. * This is quite picky. Not only does the CPU have to advertise the
  715. * "est" flag in the cpuid capability flags, we look for a specific
  716. * CPU model and stepping, and we need to have the exact model name in
  717. * our voltage tables. That is, be paranoid about not releasing
  718. * someone's valuable magic smoke.
  719. */
  720. static int __init centrino_init(void)
  721. {
  722. struct cpuinfo_x86 *cpu = cpu_data;
  723. if (!cpu_has(cpu, X86_FEATURE_EST))
  724. return -ENODEV;
  725. centrino_cpu_early_init_acpi();
  726. return cpufreq_register_driver(&centrino_driver);
  727. }
  728. static void __exit centrino_exit(void)
  729. {
  730. #ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_ACPI
  731. unsigned int j;
  732. #endif
  733. cpufreq_unregister_driver(&centrino_driver);
  734. #ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_ACPI
  735. for_each_possible_cpu(j) {
  736. kfree(acpi_perf_data[j]);
  737. acpi_perf_data[j] = NULL;
  738. }
  739. #endif
  740. }
  741. MODULE_AUTHOR ("Jeremy Fitzhardinge <jeremy@goop.org>");
  742. MODULE_DESCRIPTION ("Enhanced SpeedStep driver for Intel Pentium M processors.");
  743. MODULE_LICENSE ("GPL");
  744. late_initcall(centrino_init);
  745. module_exit(centrino_exit);