powernow-k8.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  1. /*
  2. * (c) 2003-2012 Advanced Micro Devices, Inc.
  3. * Your use of this code is subject to the terms and conditions of the
  4. * GNU general public license version 2. See "COPYING" or
  5. * http://www.gnu.org/licenses/gpl.html
  6. *
  7. * Maintainer:
  8. * Andreas Herrmann <andreas.herrmann3@amd.com>
  9. *
  10. * Based on the powernow-k7.c module written by Dave Jones.
  11. * (C) 2003 Dave Jones on behalf of SuSE Labs
  12. * (C) 2004 Dominik Brodowski <linux@brodo.de>
  13. * (C) 2004 Pavel Machek <pavel@ucw.cz>
  14. * Licensed under the terms of the GNU GPL License version 2.
  15. * Based upon datasheets & sample CPUs kindly provided by AMD.
  16. *
  17. * Valuable input gratefully received from Dave Jones, Pavel Machek,
  18. * Dominik Brodowski, Jacob Shin, and others.
  19. * Originally developed by Paul Devriendt.
  20. *
  21. * Processor information obtained from Chapter 9 (Power and Thermal
  22. * Management) of the "BIOS and Kernel Developer's Guide (BKDG) for
  23. * the AMD Athlon 64 and AMD Opteron Processors" and section "2.x
  24. * Power Management" in BKDGs for newer AMD CPU families.
  25. *
  26. * Tables for specific CPUs can be inferred from AMD's processor
  27. * power and thermal data sheets, (e.g. 30417.pdf, 30430.pdf, 43375.pdf)
  28. */
  29. #include <linux/kernel.h>
  30. #include <linux/smp.h>
  31. #include <linux/module.h>
  32. #include <linux/init.h>
  33. #include <linux/cpufreq.h>
  34. #include <linux/slab.h>
  35. #include <linux/string.h>
  36. #include <linux/cpumask.h>
  37. #include <linux/sched.h> /* for current / set_cpus_allowed() */
  38. #include <linux/io.h>
  39. #include <linux/delay.h>
  40. #include <asm/msr.h>
  41. #include <asm/cpu_device_id.h>
  42. #include <linux/acpi.h>
  43. #include <linux/mutex.h>
  44. #include <acpi/processor.h>
  45. #define PFX "powernow-k8: "
  46. #define VERSION "version 2.20.00"
  47. #include "powernow-k8.h"
  48. /* serialize freq changes */
  49. static DEFINE_MUTEX(fidvid_mutex);
  50. static DEFINE_PER_CPU(struct powernow_k8_data *, powernow_data);
  51. static struct cpufreq_driver cpufreq_amd64_driver;
  52. #ifndef CONFIG_SMP
  53. static inline const struct cpumask *cpu_core_mask(int cpu)
  54. {
  55. return cpumask_of(0);
  56. }
  57. #endif
  58. /* Return a frequency in MHz, given an input fid */
  59. static u32 find_freq_from_fid(u32 fid)
  60. {
  61. return 800 + (fid * 100);
  62. }
  63. /* Return a frequency in KHz, given an input fid */
  64. static u32 find_khz_freq_from_fid(u32 fid)
  65. {
  66. return 1000 * find_freq_from_fid(fid);
  67. }
  68. /* Return the vco fid for an input fid
  69. *
  70. * Each "low" fid has corresponding "high" fid, and you can get to "low" fids
  71. * only from corresponding high fids. This returns "high" fid corresponding to
  72. * "low" one.
  73. */
  74. static u32 convert_fid_to_vco_fid(u32 fid)
  75. {
  76. if (fid < HI_FID_TABLE_BOTTOM)
  77. return 8 + (2 * fid);
  78. else
  79. return fid;
  80. }
  81. /*
  82. * Return 1 if the pending bit is set. Unless we just instructed the processor
  83. * to transition to a new state, seeing this bit set is really bad news.
  84. */
  85. static int pending_bit_stuck(void)
  86. {
  87. u32 lo, hi;
  88. rdmsr(MSR_FIDVID_STATUS, lo, hi);
  89. return lo & MSR_S_LO_CHANGE_PENDING ? 1 : 0;
  90. }
  91. /*
  92. * Update the global current fid / vid values from the status msr.
  93. * Returns 1 on error.
  94. */
  95. static int query_current_values_with_pending_wait(struct powernow_k8_data *data)
  96. {
  97. u32 lo, hi;
  98. u32 i = 0;
  99. do {
  100. if (i++ > 10000) {
  101. pr_debug("detected change pending stuck\n");
  102. return 1;
  103. }
  104. rdmsr(MSR_FIDVID_STATUS, lo, hi);
  105. } while (lo & MSR_S_LO_CHANGE_PENDING);
  106. data->currvid = hi & MSR_S_HI_CURRENT_VID;
  107. data->currfid = lo & MSR_S_LO_CURRENT_FID;
  108. return 0;
  109. }
  110. /* the isochronous relief time */
  111. static void count_off_irt(struct powernow_k8_data *data)
  112. {
  113. udelay((1 << data->irt) * 10);
  114. return;
  115. }
  116. /* the voltage stabilization time */
  117. static void count_off_vst(struct powernow_k8_data *data)
  118. {
  119. udelay(data->vstable * VST_UNITS_20US);
  120. return;
  121. }
  122. /* need to init the control msr to a safe value (for each cpu) */
  123. static void fidvid_msr_init(void)
  124. {
  125. u32 lo, hi;
  126. u8 fid, vid;
  127. rdmsr(MSR_FIDVID_STATUS, lo, hi);
  128. vid = hi & MSR_S_HI_CURRENT_VID;
  129. fid = lo & MSR_S_LO_CURRENT_FID;
  130. lo = fid | (vid << MSR_C_LO_VID_SHIFT);
  131. hi = MSR_C_HI_STP_GNT_BENIGN;
  132. pr_debug("cpu%d, init lo 0x%x, hi 0x%x\n", smp_processor_id(), lo, hi);
  133. wrmsr(MSR_FIDVID_CTL, lo, hi);
  134. }
  135. /* write the new fid value along with the other control fields to the msr */
  136. static int write_new_fid(struct powernow_k8_data *data, u32 fid)
  137. {
  138. u32 lo;
  139. u32 savevid = data->currvid;
  140. u32 i = 0;
  141. if ((fid & INVALID_FID_MASK) || (data->currvid & INVALID_VID_MASK)) {
  142. printk(KERN_ERR PFX "internal error - overflow on fid write\n");
  143. return 1;
  144. }
  145. lo = fid;
  146. lo |= (data->currvid << MSR_C_LO_VID_SHIFT);
  147. lo |= MSR_C_LO_INIT_FID_VID;
  148. pr_debug("writing fid 0x%x, lo 0x%x, hi 0x%x\n",
  149. fid, lo, data->plllock * PLL_LOCK_CONVERSION);
  150. do {
  151. wrmsr(MSR_FIDVID_CTL, lo, data->plllock * PLL_LOCK_CONVERSION);
  152. if (i++ > 100) {
  153. printk(KERN_ERR PFX
  154. "Hardware error - pending bit very stuck - "
  155. "no further pstate changes possible\n");
  156. return 1;
  157. }
  158. } while (query_current_values_with_pending_wait(data));
  159. count_off_irt(data);
  160. if (savevid != data->currvid) {
  161. printk(KERN_ERR PFX
  162. "vid change on fid trans, old 0x%x, new 0x%x\n",
  163. savevid, data->currvid);
  164. return 1;
  165. }
  166. if (fid != data->currfid) {
  167. printk(KERN_ERR PFX
  168. "fid trans failed, fid 0x%x, curr 0x%x\n", fid,
  169. data->currfid);
  170. return 1;
  171. }
  172. return 0;
  173. }
  174. /* Write a new vid to the hardware */
  175. static int write_new_vid(struct powernow_k8_data *data, u32 vid)
  176. {
  177. u32 lo;
  178. u32 savefid = data->currfid;
  179. int i = 0;
  180. if ((data->currfid & INVALID_FID_MASK) || (vid & INVALID_VID_MASK)) {
  181. printk(KERN_ERR PFX "internal error - overflow on vid write\n");
  182. return 1;
  183. }
  184. lo = data->currfid;
  185. lo |= (vid << MSR_C_LO_VID_SHIFT);
  186. lo |= MSR_C_LO_INIT_FID_VID;
  187. pr_debug("writing vid 0x%x, lo 0x%x, hi 0x%x\n",
  188. vid, lo, STOP_GRANT_5NS);
  189. do {
  190. wrmsr(MSR_FIDVID_CTL, lo, STOP_GRANT_5NS);
  191. if (i++ > 100) {
  192. printk(KERN_ERR PFX "internal error - pending bit "
  193. "very stuck - no further pstate "
  194. "changes possible\n");
  195. return 1;
  196. }
  197. } while (query_current_values_with_pending_wait(data));
  198. if (savefid != data->currfid) {
  199. printk(KERN_ERR PFX "fid changed on vid trans, old "
  200. "0x%x new 0x%x\n",
  201. savefid, data->currfid);
  202. return 1;
  203. }
  204. if (vid != data->currvid) {
  205. printk(KERN_ERR PFX "vid trans failed, vid 0x%x, "
  206. "curr 0x%x\n",
  207. vid, data->currvid);
  208. return 1;
  209. }
  210. return 0;
  211. }
  212. /*
  213. * Reduce the vid by the max of step or reqvid.
  214. * Decreasing vid codes represent increasing voltages:
  215. * vid of 0 is 1.550V, vid of 0x1e is 0.800V, vid of VID_OFF is off.
  216. */
  217. static int decrease_vid_code_by_step(struct powernow_k8_data *data,
  218. u32 reqvid, u32 step)
  219. {
  220. if ((data->currvid - reqvid) > step)
  221. reqvid = data->currvid - step;
  222. if (write_new_vid(data, reqvid))
  223. return 1;
  224. count_off_vst(data);
  225. return 0;
  226. }
  227. /* Change Opteron/Athlon64 fid and vid, by the 3 phases. */
  228. static int transition_fid_vid(struct powernow_k8_data *data,
  229. u32 reqfid, u32 reqvid)
  230. {
  231. if (core_voltage_pre_transition(data, reqvid, reqfid))
  232. return 1;
  233. if (core_frequency_transition(data, reqfid))
  234. return 1;
  235. if (core_voltage_post_transition(data, reqvid))
  236. return 1;
  237. if (query_current_values_with_pending_wait(data))
  238. return 1;
  239. if ((reqfid != data->currfid) || (reqvid != data->currvid)) {
  240. printk(KERN_ERR PFX "failed (cpu%d): req 0x%x 0x%x, "
  241. "curr 0x%x 0x%x\n",
  242. smp_processor_id(),
  243. reqfid, reqvid, data->currfid, data->currvid);
  244. return 1;
  245. }
  246. pr_debug("transitioned (cpu%d): new fid 0x%x, vid 0x%x\n",
  247. smp_processor_id(), data->currfid, data->currvid);
  248. return 0;
  249. }
  250. /* Phase 1 - core voltage transition ... setup voltage */
  251. static int core_voltage_pre_transition(struct powernow_k8_data *data,
  252. u32 reqvid, u32 reqfid)
  253. {
  254. u32 rvosteps = data->rvo;
  255. u32 savefid = data->currfid;
  256. u32 maxvid, lo, rvomult = 1;
  257. pr_debug("ph1 (cpu%d): start, currfid 0x%x, currvid 0x%x, "
  258. "reqvid 0x%x, rvo 0x%x\n",
  259. smp_processor_id(),
  260. data->currfid, data->currvid, reqvid, data->rvo);
  261. if ((savefid < LO_FID_TABLE_TOP) && (reqfid < LO_FID_TABLE_TOP))
  262. rvomult = 2;
  263. rvosteps *= rvomult;
  264. rdmsr(MSR_FIDVID_STATUS, lo, maxvid);
  265. maxvid = 0x1f & (maxvid >> 16);
  266. pr_debug("ph1 maxvid=0x%x\n", maxvid);
  267. if (reqvid < maxvid) /* lower numbers are higher voltages */
  268. reqvid = maxvid;
  269. while (data->currvid > reqvid) {
  270. pr_debug("ph1: curr 0x%x, req vid 0x%x\n",
  271. data->currvid, reqvid);
  272. if (decrease_vid_code_by_step(data, reqvid, data->vidmvs))
  273. return 1;
  274. }
  275. while ((rvosteps > 0) &&
  276. ((rvomult * data->rvo + data->currvid) > reqvid)) {
  277. if (data->currvid == maxvid) {
  278. rvosteps = 0;
  279. } else {
  280. pr_debug("ph1: changing vid for rvo, req 0x%x\n",
  281. data->currvid - 1);
  282. if (decrease_vid_code_by_step(data, data->currvid-1, 1))
  283. return 1;
  284. rvosteps--;
  285. }
  286. }
  287. if (query_current_values_with_pending_wait(data))
  288. return 1;
  289. if (savefid != data->currfid) {
  290. printk(KERN_ERR PFX "ph1 err, currfid changed 0x%x\n",
  291. data->currfid);
  292. return 1;
  293. }
  294. pr_debug("ph1 complete, currfid 0x%x, currvid 0x%x\n",
  295. data->currfid, data->currvid);
  296. return 0;
  297. }
  298. /* Phase 2 - core frequency transition */
  299. static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid)
  300. {
  301. u32 vcoreqfid, vcocurrfid, vcofiddiff;
  302. u32 fid_interval, savevid = data->currvid;
  303. if (data->currfid == reqfid) {
  304. printk(KERN_ERR PFX "ph2 null fid transition 0x%x\n",
  305. data->currfid);
  306. return 0;
  307. }
  308. pr_debug("ph2 (cpu%d): starting, currfid 0x%x, currvid 0x%x, "
  309. "reqfid 0x%x\n",
  310. smp_processor_id(),
  311. data->currfid, data->currvid, reqfid);
  312. vcoreqfid = convert_fid_to_vco_fid(reqfid);
  313. vcocurrfid = convert_fid_to_vco_fid(data->currfid);
  314. vcofiddiff = vcocurrfid > vcoreqfid ? vcocurrfid - vcoreqfid
  315. : vcoreqfid - vcocurrfid;
  316. if ((reqfid <= LO_FID_TABLE_TOP) && (data->currfid <= LO_FID_TABLE_TOP))
  317. vcofiddiff = 0;
  318. while (vcofiddiff > 2) {
  319. (data->currfid & 1) ? (fid_interval = 1) : (fid_interval = 2);
  320. if (reqfid > data->currfid) {
  321. if (data->currfid > LO_FID_TABLE_TOP) {
  322. if (write_new_fid(data,
  323. data->currfid + fid_interval))
  324. return 1;
  325. } else {
  326. if (write_new_fid
  327. (data,
  328. 2 + convert_fid_to_vco_fid(data->currfid)))
  329. return 1;
  330. }
  331. } else {
  332. if (write_new_fid(data, data->currfid - fid_interval))
  333. return 1;
  334. }
  335. vcocurrfid = convert_fid_to_vco_fid(data->currfid);
  336. vcofiddiff = vcocurrfid > vcoreqfid ? vcocurrfid - vcoreqfid
  337. : vcoreqfid - vcocurrfid;
  338. }
  339. if (write_new_fid(data, reqfid))
  340. return 1;
  341. if (query_current_values_with_pending_wait(data))
  342. return 1;
  343. if (data->currfid != reqfid) {
  344. printk(KERN_ERR PFX
  345. "ph2: mismatch, failed fid transition, "
  346. "curr 0x%x, req 0x%x\n",
  347. data->currfid, reqfid);
  348. return 1;
  349. }
  350. if (savevid != data->currvid) {
  351. printk(KERN_ERR PFX "ph2: vid changed, save 0x%x, curr 0x%x\n",
  352. savevid, data->currvid);
  353. return 1;
  354. }
  355. pr_debug("ph2 complete, currfid 0x%x, currvid 0x%x\n",
  356. data->currfid, data->currvid);
  357. return 0;
  358. }
  359. /* Phase 3 - core voltage transition flow ... jump to the final vid. */
  360. static int core_voltage_post_transition(struct powernow_k8_data *data,
  361. u32 reqvid)
  362. {
  363. u32 savefid = data->currfid;
  364. u32 savereqvid = reqvid;
  365. pr_debug("ph3 (cpu%d): starting, currfid 0x%x, currvid 0x%x\n",
  366. smp_processor_id(),
  367. data->currfid, data->currvid);
  368. if (reqvid != data->currvid) {
  369. if (write_new_vid(data, reqvid))
  370. return 1;
  371. if (savefid != data->currfid) {
  372. printk(KERN_ERR PFX
  373. "ph3: bad fid change, save 0x%x, curr 0x%x\n",
  374. savefid, data->currfid);
  375. return 1;
  376. }
  377. if (data->currvid != reqvid) {
  378. printk(KERN_ERR PFX
  379. "ph3: failed vid transition\n, "
  380. "req 0x%x, curr 0x%x",
  381. reqvid, data->currvid);
  382. return 1;
  383. }
  384. }
  385. if (query_current_values_with_pending_wait(data))
  386. return 1;
  387. if (savereqvid != data->currvid) {
  388. pr_debug("ph3 failed, currvid 0x%x\n", data->currvid);
  389. return 1;
  390. }
  391. if (savefid != data->currfid) {
  392. pr_debug("ph3 failed, currfid changed 0x%x\n",
  393. data->currfid);
  394. return 1;
  395. }
  396. pr_debug("ph3 complete, currfid 0x%x, currvid 0x%x\n",
  397. data->currfid, data->currvid);
  398. return 0;
  399. }
  400. static const struct x86_cpu_id powernow_k8_ids[] = {
  401. /* IO based frequency switching */
  402. { X86_VENDOR_AMD, 0xf },
  403. {}
  404. };
  405. MODULE_DEVICE_TABLE(x86cpu, powernow_k8_ids);
  406. static void check_supported_cpu(void *_rc)
  407. {
  408. u32 eax, ebx, ecx, edx;
  409. int *rc = _rc;
  410. *rc = -ENODEV;
  411. eax = cpuid_eax(CPUID_PROCESSOR_SIGNATURE);
  412. if ((eax & CPUID_XFAM) == CPUID_XFAM_K8) {
  413. if (((eax & CPUID_USE_XFAM_XMOD) != CPUID_USE_XFAM_XMOD) ||
  414. ((eax & CPUID_XMOD) > CPUID_XMOD_REV_MASK)) {
  415. printk(KERN_INFO PFX
  416. "Processor cpuid %x not supported\n", eax);
  417. return;
  418. }
  419. eax = cpuid_eax(CPUID_GET_MAX_CAPABILITIES);
  420. if (eax < CPUID_FREQ_VOLT_CAPABILITIES) {
  421. printk(KERN_INFO PFX
  422. "No frequency change capabilities detected\n");
  423. return;
  424. }
  425. cpuid(CPUID_FREQ_VOLT_CAPABILITIES, &eax, &ebx, &ecx, &edx);
  426. if ((edx & P_STATE_TRANSITION_CAPABLE)
  427. != P_STATE_TRANSITION_CAPABLE) {
  428. printk(KERN_INFO PFX
  429. "Power state transitions not supported\n");
  430. return;
  431. }
  432. *rc = 0;
  433. }
  434. }
  435. static int check_pst_table(struct powernow_k8_data *data, struct pst_s *pst,
  436. u8 maxvid)
  437. {
  438. unsigned int j;
  439. u8 lastfid = 0xff;
  440. for (j = 0; j < data->numps; j++) {
  441. if (pst[j].vid > LEAST_VID) {
  442. printk(KERN_ERR FW_BUG PFX "vid %d invalid : 0x%x\n",
  443. j, pst[j].vid);
  444. return -EINVAL;
  445. }
  446. if (pst[j].vid < data->rvo) {
  447. /* vid + rvo >= 0 */
  448. printk(KERN_ERR FW_BUG PFX "0 vid exceeded with pstate"
  449. " %d\n", j);
  450. return -ENODEV;
  451. }
  452. if (pst[j].vid < maxvid + data->rvo) {
  453. /* vid + rvo >= maxvid */
  454. printk(KERN_ERR FW_BUG PFX "maxvid exceeded with pstate"
  455. " %d\n", j);
  456. return -ENODEV;
  457. }
  458. if (pst[j].fid > MAX_FID) {
  459. printk(KERN_ERR FW_BUG PFX "maxfid exceeded with pstate"
  460. " %d\n", j);
  461. return -ENODEV;
  462. }
  463. if (j && (pst[j].fid < HI_FID_TABLE_BOTTOM)) {
  464. /* Only first fid is allowed to be in "low" range */
  465. printk(KERN_ERR FW_BUG PFX "two low fids - %d : "
  466. "0x%x\n", j, pst[j].fid);
  467. return -EINVAL;
  468. }
  469. if (pst[j].fid < lastfid)
  470. lastfid = pst[j].fid;
  471. }
  472. if (lastfid & 1) {
  473. printk(KERN_ERR FW_BUG PFX "lastfid invalid\n");
  474. return -EINVAL;
  475. }
  476. if (lastfid > LO_FID_TABLE_TOP)
  477. printk(KERN_INFO FW_BUG PFX
  478. "first fid not from lo freq table\n");
  479. return 0;
  480. }
  481. static void invalidate_entry(struct cpufreq_frequency_table *powernow_table,
  482. unsigned int entry)
  483. {
  484. powernow_table[entry].frequency = CPUFREQ_ENTRY_INVALID;
  485. }
  486. static void print_basics(struct powernow_k8_data *data)
  487. {
  488. int j;
  489. for (j = 0; j < data->numps; j++) {
  490. if (data->powernow_table[j].frequency !=
  491. CPUFREQ_ENTRY_INVALID) {
  492. printk(KERN_INFO PFX
  493. "fid 0x%x (%d MHz), vid 0x%x\n",
  494. data->powernow_table[j].index & 0xff,
  495. data->powernow_table[j].frequency/1000,
  496. data->powernow_table[j].index >> 8);
  497. }
  498. }
  499. if (data->batps)
  500. printk(KERN_INFO PFX "Only %d pstates on battery\n",
  501. data->batps);
  502. }
  503. static int fill_powernow_table(struct powernow_k8_data *data,
  504. struct pst_s *pst, u8 maxvid)
  505. {
  506. struct cpufreq_frequency_table *powernow_table;
  507. unsigned int j;
  508. if (data->batps) {
  509. /* use ACPI support to get full speed on mains power */
  510. printk(KERN_WARNING PFX
  511. "Only %d pstates usable (use ACPI driver for full "
  512. "range\n", data->batps);
  513. data->numps = data->batps;
  514. }
  515. for (j = 1; j < data->numps; j++) {
  516. if (pst[j-1].fid >= pst[j].fid) {
  517. printk(KERN_ERR PFX "PST out of sequence\n");
  518. return -EINVAL;
  519. }
  520. }
  521. if (data->numps < 2) {
  522. printk(KERN_ERR PFX "no p states to transition\n");
  523. return -ENODEV;
  524. }
  525. if (check_pst_table(data, pst, maxvid))
  526. return -EINVAL;
  527. powernow_table = kmalloc((sizeof(struct cpufreq_frequency_table)
  528. * (data->numps + 1)), GFP_KERNEL);
  529. if (!powernow_table) {
  530. printk(KERN_ERR PFX "powernow_table memory alloc failure\n");
  531. return -ENOMEM;
  532. }
  533. for (j = 0; j < data->numps; j++) {
  534. int freq;
  535. powernow_table[j].index = pst[j].fid; /* lower 8 bits */
  536. powernow_table[j].index |= (pst[j].vid << 8); /* upper 8 bits */
  537. freq = find_khz_freq_from_fid(pst[j].fid);
  538. powernow_table[j].frequency = freq;
  539. }
  540. powernow_table[data->numps].frequency = CPUFREQ_TABLE_END;
  541. powernow_table[data->numps].index = 0;
  542. if (query_current_values_with_pending_wait(data)) {
  543. kfree(powernow_table);
  544. return -EIO;
  545. }
  546. pr_debug("cfid 0x%x, cvid 0x%x\n", data->currfid, data->currvid);
  547. data->powernow_table = powernow_table;
  548. if (cpumask_first(cpu_core_mask(data->cpu)) == data->cpu)
  549. print_basics(data);
  550. for (j = 0; j < data->numps; j++)
  551. if ((pst[j].fid == data->currfid) &&
  552. (pst[j].vid == data->currvid))
  553. return 0;
  554. pr_debug("currfid/vid do not match PST, ignoring\n");
  555. return 0;
  556. }
  557. /* Find and validate the PSB/PST table in BIOS. */
  558. static int find_psb_table(struct powernow_k8_data *data)
  559. {
  560. struct psb_s *psb;
  561. unsigned int i;
  562. u32 mvs;
  563. u8 maxvid;
  564. u32 cpst = 0;
  565. u32 thiscpuid;
  566. for (i = 0xc0000; i < 0xffff0; i += 0x10) {
  567. /* Scan BIOS looking for the signature. */
  568. /* It can not be at ffff0 - it is too big. */
  569. psb = phys_to_virt(i);
  570. if (memcmp(psb, PSB_ID_STRING, PSB_ID_STRING_LEN) != 0)
  571. continue;
  572. pr_debug("found PSB header at 0x%p\n", psb);
  573. pr_debug("table vers: 0x%x\n", psb->tableversion);
  574. if (psb->tableversion != PSB_VERSION_1_4) {
  575. printk(KERN_ERR FW_BUG PFX "PSB table is not v1.4\n");
  576. return -ENODEV;
  577. }
  578. pr_debug("flags: 0x%x\n", psb->flags1);
  579. if (psb->flags1) {
  580. printk(KERN_ERR FW_BUG PFX "unknown flags\n");
  581. return -ENODEV;
  582. }
  583. data->vstable = psb->vstable;
  584. pr_debug("voltage stabilization time: %d(*20us)\n",
  585. data->vstable);
  586. pr_debug("flags2: 0x%x\n", psb->flags2);
  587. data->rvo = psb->flags2 & 3;
  588. data->irt = ((psb->flags2) >> 2) & 3;
  589. mvs = ((psb->flags2) >> 4) & 3;
  590. data->vidmvs = 1 << mvs;
  591. data->batps = ((psb->flags2) >> 6) & 3;
  592. pr_debug("ramp voltage offset: %d\n", data->rvo);
  593. pr_debug("isochronous relief time: %d\n", data->irt);
  594. pr_debug("maximum voltage step: %d - 0x%x\n", mvs, data->vidmvs);
  595. pr_debug("numpst: 0x%x\n", psb->num_tables);
  596. cpst = psb->num_tables;
  597. if ((psb->cpuid == 0x00000fc0) ||
  598. (psb->cpuid == 0x00000fe0)) {
  599. thiscpuid = cpuid_eax(CPUID_PROCESSOR_SIGNATURE);
  600. if ((thiscpuid == 0x00000fc0) ||
  601. (thiscpuid == 0x00000fe0))
  602. cpst = 1;
  603. }
  604. if (cpst != 1) {
  605. printk(KERN_ERR FW_BUG PFX "numpst must be 1\n");
  606. return -ENODEV;
  607. }
  608. data->plllock = psb->plllocktime;
  609. pr_debug("plllocktime: 0x%x (units 1us)\n", psb->plllocktime);
  610. pr_debug("maxfid: 0x%x\n", psb->maxfid);
  611. pr_debug("maxvid: 0x%x\n", psb->maxvid);
  612. maxvid = psb->maxvid;
  613. data->numps = psb->numps;
  614. pr_debug("numpstates: 0x%x\n", data->numps);
  615. return fill_powernow_table(data,
  616. (struct pst_s *)(psb+1), maxvid);
  617. }
  618. /*
  619. * If you see this message, complain to BIOS manufacturer. If
  620. * he tells you "we do not support Linux" or some similar
  621. * nonsense, remember that Windows 2000 uses the same legacy
  622. * mechanism that the old Linux PSB driver uses. Tell them it
  623. * is broken with Windows 2000.
  624. *
  625. * The reference to the AMD documentation is chapter 9 in the
  626. * BIOS and Kernel Developer's Guide, which is available on
  627. * www.amd.com
  628. */
  629. printk(KERN_ERR FW_BUG PFX "No PSB or ACPI _PSS objects\n");
  630. printk(KERN_ERR PFX "Make sure that your BIOS is up to date"
  631. " and Cool'N'Quiet support is enabled in BIOS setup\n");
  632. return -ENODEV;
  633. }
  634. static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data,
  635. unsigned int index)
  636. {
  637. u64 control;
  638. if (!data->acpi_data.state_count)
  639. return;
  640. control = data->acpi_data.states[index].control;
  641. data->irt = (control >> IRT_SHIFT) & IRT_MASK;
  642. data->rvo = (control >> RVO_SHIFT) & RVO_MASK;
  643. data->exttype = (control >> EXT_TYPE_SHIFT) & EXT_TYPE_MASK;
  644. data->plllock = (control >> PLL_L_SHIFT) & PLL_L_MASK;
  645. data->vidmvs = 1 << ((control >> MVS_SHIFT) & MVS_MASK);
  646. data->vstable = (control >> VST_SHIFT) & VST_MASK;
  647. }
  648. static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data)
  649. {
  650. struct cpufreq_frequency_table *powernow_table;
  651. int ret_val = -ENODEV;
  652. u64 control, status;
  653. if (acpi_processor_register_performance(&data->acpi_data, data->cpu)) {
  654. pr_debug("register performance failed: bad ACPI data\n");
  655. return -EIO;
  656. }
  657. /* verify the data contained in the ACPI structures */
  658. if (data->acpi_data.state_count <= 1) {
  659. pr_debug("No ACPI P-States\n");
  660. goto err_out;
  661. }
  662. control = data->acpi_data.control_register.space_id;
  663. status = data->acpi_data.status_register.space_id;
  664. if ((control != ACPI_ADR_SPACE_FIXED_HARDWARE) ||
  665. (status != ACPI_ADR_SPACE_FIXED_HARDWARE)) {
  666. pr_debug("Invalid control/status registers (%llx - %llx)\n",
  667. control, status);
  668. goto err_out;
  669. }
  670. /* fill in data->powernow_table */
  671. powernow_table = kmalloc((sizeof(struct cpufreq_frequency_table)
  672. * (data->acpi_data.state_count + 1)), GFP_KERNEL);
  673. if (!powernow_table) {
  674. pr_debug("powernow_table memory alloc failure\n");
  675. goto err_out;
  676. }
  677. /* fill in data */
  678. data->numps = data->acpi_data.state_count;
  679. powernow_k8_acpi_pst_values(data, 0);
  680. ret_val = fill_powernow_table_fidvid(data, powernow_table);
  681. if (ret_val)
  682. goto err_out_mem;
  683. powernow_table[data->acpi_data.state_count].frequency =
  684. CPUFREQ_TABLE_END;
  685. powernow_table[data->acpi_data.state_count].index = 0;
  686. data->powernow_table = powernow_table;
  687. if (cpumask_first(cpu_core_mask(data->cpu)) == data->cpu)
  688. print_basics(data);
  689. /* notify BIOS that we exist */
  690. acpi_processor_notify_smm(THIS_MODULE);
  691. if (!zalloc_cpumask_var(&data->acpi_data.shared_cpu_map, GFP_KERNEL)) {
  692. printk(KERN_ERR PFX
  693. "unable to alloc powernow_k8_data cpumask\n");
  694. ret_val = -ENOMEM;
  695. goto err_out_mem;
  696. }
  697. return 0;
  698. err_out_mem:
  699. kfree(powernow_table);
  700. err_out:
  701. acpi_processor_unregister_performance(&data->acpi_data, data->cpu);
  702. /* data->acpi_data.state_count informs us at ->exit()
  703. * whether ACPI was used */
  704. data->acpi_data.state_count = 0;
  705. return ret_val;
  706. }
  707. static int fill_powernow_table_fidvid(struct powernow_k8_data *data,
  708. struct cpufreq_frequency_table *powernow_table)
  709. {
  710. int i;
  711. for (i = 0; i < data->acpi_data.state_count; i++) {
  712. u32 fid;
  713. u32 vid;
  714. u32 freq, index;
  715. u64 status, control;
  716. if (data->exttype) {
  717. status = data->acpi_data.states[i].status;
  718. fid = status & EXT_FID_MASK;
  719. vid = (status >> VID_SHIFT) & EXT_VID_MASK;
  720. } else {
  721. control = data->acpi_data.states[i].control;
  722. fid = control & FID_MASK;
  723. vid = (control >> VID_SHIFT) & VID_MASK;
  724. }
  725. pr_debug(" %d : fid 0x%x, vid 0x%x\n", i, fid, vid);
  726. index = fid | (vid<<8);
  727. powernow_table[i].index = index;
  728. freq = find_khz_freq_from_fid(fid);
  729. powernow_table[i].frequency = freq;
  730. /* verify frequency is OK */
  731. if ((freq > (MAX_FREQ * 1000)) || (freq < (MIN_FREQ * 1000))) {
  732. pr_debug("invalid freq %u kHz, ignoring\n", freq);
  733. invalidate_entry(powernow_table, i);
  734. continue;
  735. }
  736. /* verify voltage is OK -
  737. * BIOSs are using "off" to indicate invalid */
  738. if (vid == VID_OFF) {
  739. pr_debug("invalid vid %u, ignoring\n", vid);
  740. invalidate_entry(powernow_table, i);
  741. continue;
  742. }
  743. if (freq != (data->acpi_data.states[i].core_frequency * 1000)) {
  744. printk(KERN_INFO PFX "invalid freq entries "
  745. "%u kHz vs. %u kHz\n", freq,
  746. (unsigned int)
  747. (data->acpi_data.states[i].core_frequency
  748. * 1000));
  749. invalidate_entry(powernow_table, i);
  750. continue;
  751. }
  752. }
  753. return 0;
  754. }
  755. static void powernow_k8_cpu_exit_acpi(struct powernow_k8_data *data)
  756. {
  757. if (data->acpi_data.state_count)
  758. acpi_processor_unregister_performance(&data->acpi_data,
  759. data->cpu);
  760. free_cpumask_var(data->acpi_data.shared_cpu_map);
  761. }
  762. static int get_transition_latency(struct powernow_k8_data *data)
  763. {
  764. int max_latency = 0;
  765. int i;
  766. for (i = 0; i < data->acpi_data.state_count; i++) {
  767. int cur_latency = data->acpi_data.states[i].transition_latency
  768. + data->acpi_data.states[i].bus_master_latency;
  769. if (cur_latency > max_latency)
  770. max_latency = cur_latency;
  771. }
  772. if (max_latency == 0) {
  773. pr_err(FW_WARN PFX "Invalid zero transition latency\n");
  774. max_latency = 1;
  775. }
  776. /* value in usecs, needs to be in nanoseconds */
  777. return 1000 * max_latency;
  778. }
  779. /* Take a frequency, and issue the fid/vid transition command */
  780. static int transition_frequency_fidvid(struct powernow_k8_data *data,
  781. unsigned int index)
  782. {
  783. u32 fid = 0;
  784. u32 vid = 0;
  785. int res, i;
  786. struct cpufreq_freqs freqs;
  787. pr_debug("cpu %d transition to index %u\n", smp_processor_id(), index);
  788. /* fid/vid correctness check for k8 */
  789. /* fid are the lower 8 bits of the index we stored into
  790. * the cpufreq frequency table in find_psb_table, vid
  791. * are the upper 8 bits.
  792. */
  793. fid = data->powernow_table[index].index & 0xFF;
  794. vid = (data->powernow_table[index].index & 0xFF00) >> 8;
  795. pr_debug("table matched fid 0x%x, giving vid 0x%x\n", fid, vid);
  796. if (query_current_values_with_pending_wait(data))
  797. return 1;
  798. if ((data->currvid == vid) && (data->currfid == fid)) {
  799. pr_debug("target matches current values (fid 0x%x, vid 0x%x)\n",
  800. fid, vid);
  801. return 0;
  802. }
  803. pr_debug("cpu %d, changing to fid 0x%x, vid 0x%x\n",
  804. smp_processor_id(), fid, vid);
  805. freqs.old = find_khz_freq_from_fid(data->currfid);
  806. freqs.new = find_khz_freq_from_fid(fid);
  807. for_each_cpu(i, data->available_cores) {
  808. freqs.cpu = i;
  809. cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
  810. }
  811. res = transition_fid_vid(data, fid, vid);
  812. if (res)
  813. return res;
  814. freqs.new = find_khz_freq_from_fid(data->currfid);
  815. for_each_cpu(i, data->available_cores) {
  816. freqs.cpu = i;
  817. cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
  818. }
  819. return res;
  820. }
  821. /* Driver entry point to switch to the target frequency */
  822. static int powernowk8_target(struct cpufreq_policy *pol,
  823. unsigned targfreq, unsigned relation)
  824. {
  825. cpumask_var_t oldmask;
  826. struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu);
  827. u32 checkfid;
  828. u32 checkvid;
  829. unsigned int newstate;
  830. int ret = -EIO;
  831. if (!data)
  832. return -EINVAL;
  833. checkfid = data->currfid;
  834. checkvid = data->currvid;
  835. /* only run on specific CPU from here on. */
  836. /* This is poor form: use a workqueue or smp_call_function_single */
  837. if (!alloc_cpumask_var(&oldmask, GFP_KERNEL))
  838. return -ENOMEM;
  839. cpumask_copy(oldmask, tsk_cpus_allowed(current));
  840. set_cpus_allowed_ptr(current, cpumask_of(pol->cpu));
  841. if (smp_processor_id() != pol->cpu) {
  842. printk(KERN_ERR PFX "limiting to cpu %u failed\n", pol->cpu);
  843. goto err_out;
  844. }
  845. if (pending_bit_stuck()) {
  846. printk(KERN_ERR PFX "failing targ, change pending bit set\n");
  847. goto err_out;
  848. }
  849. pr_debug("targ: cpu %d, %d kHz, min %d, max %d, relation %d\n",
  850. pol->cpu, targfreq, pol->min, pol->max, relation);
  851. if (query_current_values_with_pending_wait(data))
  852. goto err_out;
  853. pr_debug("targ: curr fid 0x%x, vid 0x%x\n",
  854. data->currfid, data->currvid);
  855. if ((checkvid != data->currvid) ||
  856. (checkfid != data->currfid)) {
  857. pr_info(PFX
  858. "error - out of sync, fix 0x%x 0x%x, vid 0x%x 0x%x\n",
  859. checkfid, data->currfid,
  860. checkvid, data->currvid);
  861. }
  862. if (cpufreq_frequency_table_target(pol, data->powernow_table,
  863. targfreq, relation, &newstate))
  864. goto err_out;
  865. mutex_lock(&fidvid_mutex);
  866. powernow_k8_acpi_pst_values(data, newstate);
  867. ret = transition_frequency_fidvid(data, newstate);
  868. if (ret) {
  869. printk(KERN_ERR PFX "transition frequency failed\n");
  870. ret = 1;
  871. mutex_unlock(&fidvid_mutex);
  872. goto err_out;
  873. }
  874. mutex_unlock(&fidvid_mutex);
  875. pol->cur = find_khz_freq_from_fid(data->currfid);
  876. ret = 0;
  877. err_out:
  878. set_cpus_allowed_ptr(current, oldmask);
  879. free_cpumask_var(oldmask);
  880. return ret;
  881. }
  882. /* Driver entry point to verify the policy and range of frequencies */
  883. static int powernowk8_verify(struct cpufreq_policy *pol)
  884. {
  885. struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu);
  886. if (!data)
  887. return -EINVAL;
  888. return cpufreq_frequency_table_verify(pol, data->powernow_table);
  889. }
  890. struct init_on_cpu {
  891. struct powernow_k8_data *data;
  892. int rc;
  893. };
  894. static void __cpuinit powernowk8_cpu_init_on_cpu(void *_init_on_cpu)
  895. {
  896. struct init_on_cpu *init_on_cpu = _init_on_cpu;
  897. if (pending_bit_stuck()) {
  898. printk(KERN_ERR PFX "failing init, change pending bit set\n");
  899. init_on_cpu->rc = -ENODEV;
  900. return;
  901. }
  902. if (query_current_values_with_pending_wait(init_on_cpu->data)) {
  903. init_on_cpu->rc = -ENODEV;
  904. return;
  905. }
  906. fidvid_msr_init();
  907. init_on_cpu->rc = 0;
  908. }
  909. static const char missing_pss_msg[] =
  910. KERN_ERR
  911. FW_BUG PFX "No compatible ACPI _PSS objects found.\n"
  912. FW_BUG PFX "First, make sure Cool'N'Quiet is enabled in the BIOS.\n"
  913. FW_BUG PFX "If that doesn't help, try upgrading your BIOS.\n";
  914. /* per CPU init entry point to the driver */
  915. static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)
  916. {
  917. struct powernow_k8_data *data;
  918. struct init_on_cpu init_on_cpu;
  919. int rc;
  920. if (!cpu_online(pol->cpu))
  921. return -ENODEV;
  922. smp_call_function_single(pol->cpu, check_supported_cpu, &rc, 1);
  923. if (rc)
  924. return -ENODEV;
  925. data = kzalloc(sizeof(struct powernow_k8_data), GFP_KERNEL);
  926. if (!data) {
  927. printk(KERN_ERR PFX "unable to alloc powernow_k8_data");
  928. return -ENOMEM;
  929. }
  930. data->cpu = pol->cpu;
  931. if (powernow_k8_cpu_init_acpi(data)) {
  932. /*
  933. * Use the PSB BIOS structure. This is only available on
  934. * an UP version, and is deprecated by AMD.
  935. */
  936. if (num_online_cpus() != 1) {
  937. printk_once(missing_pss_msg);
  938. goto err_out;
  939. }
  940. if (pol->cpu != 0) {
  941. printk(KERN_ERR FW_BUG PFX "No ACPI _PSS objects for "
  942. "CPU other than CPU0. Complain to your BIOS "
  943. "vendor.\n");
  944. goto err_out;
  945. }
  946. rc = find_psb_table(data);
  947. if (rc)
  948. goto err_out;
  949. /* Take a crude guess here.
  950. * That guess was in microseconds, so multiply with 1000 */
  951. pol->cpuinfo.transition_latency = (
  952. ((data->rvo + 8) * data->vstable * VST_UNITS_20US) +
  953. ((1 << data->irt) * 30)) * 1000;
  954. } else /* ACPI _PSS objects available */
  955. pol->cpuinfo.transition_latency = get_transition_latency(data);
  956. /* only run on specific CPU from here on */
  957. init_on_cpu.data = data;
  958. smp_call_function_single(data->cpu, powernowk8_cpu_init_on_cpu,
  959. &init_on_cpu, 1);
  960. rc = init_on_cpu.rc;
  961. if (rc != 0)
  962. goto err_out_exit_acpi;
  963. cpumask_copy(pol->cpus, cpu_core_mask(pol->cpu));
  964. data->available_cores = pol->cpus;
  965. pol->cur = find_khz_freq_from_fid(data->currfid);
  966. pr_debug("policy current frequency %d kHz\n", pol->cur);
  967. /* min/max the cpu is capable of */
  968. if (cpufreq_frequency_table_cpuinfo(pol, data->powernow_table)) {
  969. printk(KERN_ERR FW_BUG PFX "invalid powernow_table\n");
  970. powernow_k8_cpu_exit_acpi(data);
  971. kfree(data->powernow_table);
  972. kfree(data);
  973. return -EINVAL;
  974. }
  975. cpufreq_frequency_table_get_attr(data->powernow_table, pol->cpu);
  976. pr_debug("cpu_init done, current fid 0x%x, vid 0x%x\n",
  977. data->currfid, data->currvid);
  978. per_cpu(powernow_data, pol->cpu) = data;
  979. return 0;
  980. err_out_exit_acpi:
  981. powernow_k8_cpu_exit_acpi(data);
  982. err_out:
  983. kfree(data);
  984. return -ENODEV;
  985. }
  986. static int __devexit powernowk8_cpu_exit(struct cpufreq_policy *pol)
  987. {
  988. struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu);
  989. if (!data)
  990. return -EINVAL;
  991. powernow_k8_cpu_exit_acpi(data);
  992. cpufreq_frequency_table_put_attr(pol->cpu);
  993. kfree(data->powernow_table);
  994. kfree(data);
  995. per_cpu(powernow_data, pol->cpu) = NULL;
  996. return 0;
  997. }
  998. static void query_values_on_cpu(void *_err)
  999. {
  1000. int *err = _err;
  1001. struct powernow_k8_data *data = __this_cpu_read(powernow_data);
  1002. *err = query_current_values_with_pending_wait(data);
  1003. }
  1004. static unsigned int powernowk8_get(unsigned int cpu)
  1005. {
  1006. struct powernow_k8_data *data = per_cpu(powernow_data, cpu);
  1007. unsigned int khz = 0;
  1008. int err;
  1009. if (!data)
  1010. return 0;
  1011. smp_call_function_single(cpu, query_values_on_cpu, &err, true);
  1012. if (err)
  1013. goto out;
  1014. khz = find_khz_freq_from_fid(data->currfid);
  1015. out:
  1016. return khz;
  1017. }
  1018. static struct freq_attr *powernow_k8_attr[] = {
  1019. &cpufreq_freq_attr_scaling_available_freqs,
  1020. NULL,
  1021. };
  1022. static struct cpufreq_driver cpufreq_amd64_driver = {
  1023. .verify = powernowk8_verify,
  1024. .target = powernowk8_target,
  1025. .bios_limit = acpi_processor_get_bios_limit,
  1026. .init = powernowk8_cpu_init,
  1027. .exit = __devexit_p(powernowk8_cpu_exit),
  1028. .get = powernowk8_get,
  1029. .name = "powernow-k8",
  1030. .owner = THIS_MODULE,
  1031. .attr = powernow_k8_attr,
  1032. };
  1033. /* driver entry point for init */
  1034. static int __cpuinit powernowk8_init(void)
  1035. {
  1036. unsigned int i, supported_cpus = 0;
  1037. int rv;
  1038. if (static_cpu_has(X86_FEATURE_HW_PSTATE)) {
  1039. pr_warn(PFX "this CPU is not supported anymore, using acpi-cpufreq instead.\n");
  1040. request_module("acpi-cpufreq");
  1041. return -ENODEV;
  1042. }
  1043. if (!x86_match_cpu(powernow_k8_ids))
  1044. return -ENODEV;
  1045. for_each_online_cpu(i) {
  1046. int rc;
  1047. smp_call_function_single(i, check_supported_cpu, &rc, 1);
  1048. if (rc == 0)
  1049. supported_cpus++;
  1050. }
  1051. if (supported_cpus != num_online_cpus())
  1052. return -ENODEV;
  1053. rv = cpufreq_register_driver(&cpufreq_amd64_driver);
  1054. if (!rv)
  1055. pr_info(PFX "Found %d %s (%d cpu cores) (" VERSION ")\n",
  1056. num_online_nodes(), boot_cpu_data.x86_model_id,
  1057. supported_cpus);
  1058. return rv;
  1059. }
  1060. /* driver entry point for term */
  1061. static void __exit powernowk8_exit(void)
  1062. {
  1063. pr_debug("exit\n");
  1064. cpufreq_unregister_driver(&cpufreq_amd64_driver);
  1065. }
  1066. MODULE_AUTHOR("Paul Devriendt <paul.devriendt@amd.com> and "
  1067. "Mark Langsdorf <mark.langsdorf@amd.com>");
  1068. MODULE_DESCRIPTION("AMD Athlon 64 and Opteron processor frequency driver.");
  1069. MODULE_LICENSE("GPL");
  1070. late_initcall(powernowk8_init);
  1071. module_exit(powernowk8_exit);