processor_idle.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275
  1. /*
  2. * processor_idle - idle state submodule to the ACPI processor driver
  3. *
  4. * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
  5. * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  6. * Copyright (C) 2004, 2005 Dominik Brodowski <linux@brodo.de>
  7. * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
  8. * - Added processor hotplug support
  9. * Copyright (C) 2005 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
  10. * - Added support for C3 on SMP
  11. *
  12. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or (at
  17. * your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful, but
  20. * WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  22. * General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License along
  25. * with this program; if not, write to the Free Software Foundation, Inc.,
  26. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  27. *
  28. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  29. */
  30. #include <linux/kernel.h>
  31. #include <linux/module.h>
  32. #include <linux/init.h>
  33. #include <linux/cpufreq.h>
  34. #include <linux/proc_fs.h>
  35. #include <linux/seq_file.h>
  36. #include <linux/acpi.h>
  37. #include <linux/dmi.h>
  38. #include <linux/moduleparam.h>
  39. #include <linux/sched.h> /* need_resched() */
  40. #include <linux/pm_qos_params.h>
  41. #include <linux/clockchips.h>
  42. #include <linux/cpuidle.h>
  43. #include <linux/irqflags.h>
  44. /*
  45. * Include the apic definitions for x86 to have the APIC timer related defines
  46. * available also for UP (on SMP it gets magically included via linux/smp.h).
  47. * asm/acpi.h is not an option, as it would require more include magic. Also
  48. * creating an empty asm-ia64/apic.h would just trade pest vs. cholera.
  49. */
  50. #ifdef CONFIG_X86
  51. #include <asm/apic.h>
  52. #endif
  53. #include <asm/io.h>
  54. #include <asm/uaccess.h>
  55. #include <acpi/acpi_bus.h>
  56. #include <acpi/processor.h>
  57. #include <asm/processor.h>
  58. #define ACPI_PROCESSOR_CLASS "processor"
  59. #define _COMPONENT ACPI_PROCESSOR_COMPONENT
  60. ACPI_MODULE_NAME("processor_idle");
  61. #define ACPI_PROCESSOR_FILE_POWER "power"
  62. #define US_TO_PM_TIMER_TICKS(t) ((t * (PM_TIMER_FREQUENCY/1000)) / 1000)
  63. #define PM_TIMER_TICK_NS (1000000000ULL/PM_TIMER_FREQUENCY)
  64. #define C2_OVERHEAD 1 /* 1us */
  65. #define C3_OVERHEAD 1 /* 1us */
  66. #define PM_TIMER_TICKS_TO_US(p) (((p) * 1000)/(PM_TIMER_FREQUENCY/1000))
  67. static unsigned int max_cstate __read_mostly = ACPI_PROCESSOR_MAX_POWER;
  68. module_param(max_cstate, uint, 0000);
  69. static unsigned int nocst __read_mostly;
  70. module_param(nocst, uint, 0000);
  71. static unsigned int latency_factor __read_mostly = 2;
  72. module_param(latency_factor, uint, 0644);
  73. /*
  74. * IBM ThinkPad R40e crashes mysteriously when going into C2 or C3.
  75. * For now disable this. Probably a bug somewhere else.
  76. *
  77. * To skip this limit, boot/load with a large max_cstate limit.
  78. */
  79. static int set_max_cstate(const struct dmi_system_id *id)
  80. {
  81. if (max_cstate > ACPI_PROCESSOR_MAX_POWER)
  82. return 0;
  83. printk(KERN_NOTICE PREFIX "%s detected - limiting to C%ld max_cstate."
  84. " Override with \"processor.max_cstate=%d\"\n", id->ident,
  85. (long)id->driver_data, ACPI_PROCESSOR_MAX_POWER + 1);
  86. max_cstate = (long)id->driver_data;
  87. return 0;
  88. }
  89. /* Actually this shouldn't be __cpuinitdata, would be better to fix the
  90. callers to only run once -AK */
  91. static struct dmi_system_id __cpuinitdata processor_power_dmi_table[] = {
  92. { set_max_cstate, "IBM ThinkPad R40e", {
  93. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  94. DMI_MATCH(DMI_BIOS_VERSION,"1SET70WW")}, (void *)1},
  95. { set_max_cstate, "IBM ThinkPad R40e", {
  96. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  97. DMI_MATCH(DMI_BIOS_VERSION,"1SET60WW")}, (void *)1},
  98. { set_max_cstate, "IBM ThinkPad R40e", {
  99. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  100. DMI_MATCH(DMI_BIOS_VERSION,"1SET43WW") }, (void*)1},
  101. { set_max_cstate, "IBM ThinkPad R40e", {
  102. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  103. DMI_MATCH(DMI_BIOS_VERSION,"1SET45WW") }, (void*)1},
  104. { set_max_cstate, "IBM ThinkPad R40e", {
  105. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  106. DMI_MATCH(DMI_BIOS_VERSION,"1SET47WW") }, (void*)1},
  107. { set_max_cstate, "IBM ThinkPad R40e", {
  108. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  109. DMI_MATCH(DMI_BIOS_VERSION,"1SET50WW") }, (void*)1},
  110. { set_max_cstate, "IBM ThinkPad R40e", {
  111. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  112. DMI_MATCH(DMI_BIOS_VERSION,"1SET52WW") }, (void*)1},
  113. { set_max_cstate, "IBM ThinkPad R40e", {
  114. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  115. DMI_MATCH(DMI_BIOS_VERSION,"1SET55WW") }, (void*)1},
  116. { set_max_cstate, "IBM ThinkPad R40e", {
  117. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  118. DMI_MATCH(DMI_BIOS_VERSION,"1SET56WW") }, (void*)1},
  119. { set_max_cstate, "IBM ThinkPad R40e", {
  120. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  121. DMI_MATCH(DMI_BIOS_VERSION,"1SET59WW") }, (void*)1},
  122. { set_max_cstate, "IBM ThinkPad R40e", {
  123. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  124. DMI_MATCH(DMI_BIOS_VERSION,"1SET60WW") }, (void*)1},
  125. { set_max_cstate, "IBM ThinkPad R40e", {
  126. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  127. DMI_MATCH(DMI_BIOS_VERSION,"1SET61WW") }, (void*)1},
  128. { set_max_cstate, "IBM ThinkPad R40e", {
  129. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  130. DMI_MATCH(DMI_BIOS_VERSION,"1SET62WW") }, (void*)1},
  131. { set_max_cstate, "IBM ThinkPad R40e", {
  132. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  133. DMI_MATCH(DMI_BIOS_VERSION,"1SET64WW") }, (void*)1},
  134. { set_max_cstate, "IBM ThinkPad R40e", {
  135. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  136. DMI_MATCH(DMI_BIOS_VERSION,"1SET65WW") }, (void*)1},
  137. { set_max_cstate, "IBM ThinkPad R40e", {
  138. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  139. DMI_MATCH(DMI_BIOS_VERSION,"1SET68WW") }, (void*)1},
  140. { set_max_cstate, "Medion 41700", {
  141. DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
  142. DMI_MATCH(DMI_BIOS_VERSION,"R01-A1J")}, (void *)1},
  143. { set_max_cstate, "Clevo 5600D", {
  144. DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
  145. DMI_MATCH(DMI_BIOS_VERSION,"SHE845M0.86C.0013.D.0302131307")},
  146. (void *)2},
  147. {},
  148. };
  149. static inline u32 ticks_elapsed(u32 t1, u32 t2)
  150. {
  151. if (t2 >= t1)
  152. return (t2 - t1);
  153. else if (!(acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER))
  154. return (((0x00FFFFFF - t1) + t2) & 0x00FFFFFF);
  155. else
  156. return ((0xFFFFFFFF - t1) + t2);
  157. }
  158. static inline u32 ticks_elapsed_in_us(u32 t1, u32 t2)
  159. {
  160. if (t2 >= t1)
  161. return PM_TIMER_TICKS_TO_US(t2 - t1);
  162. else if (!(acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER))
  163. return PM_TIMER_TICKS_TO_US(((0x00FFFFFF - t1) + t2) & 0x00FFFFFF);
  164. else
  165. return PM_TIMER_TICKS_TO_US((0xFFFFFFFF - t1) + t2);
  166. }
  167. /*
  168. * Callers should disable interrupts before the call and enable
  169. * interrupts after return.
  170. */
  171. static void acpi_safe_halt(void)
  172. {
  173. current_thread_info()->status &= ~TS_POLLING;
  174. /*
  175. * TS_POLLING-cleared state must be visible before we
  176. * test NEED_RESCHED:
  177. */
  178. smp_mb();
  179. if (!need_resched()) {
  180. safe_halt();
  181. local_irq_disable();
  182. }
  183. current_thread_info()->status |= TS_POLLING;
  184. }
  185. #ifdef ARCH_APICTIMER_STOPS_ON_C3
  186. /*
  187. * Some BIOS implementations switch to C3 in the published C2 state.
  188. * This seems to be a common problem on AMD boxen, but other vendors
  189. * are affected too. We pick the most conservative approach: we assume
  190. * that the local APIC stops in both C2 and C3.
  191. */
  192. static void acpi_timer_check_state(int state, struct acpi_processor *pr,
  193. struct acpi_processor_cx *cx)
  194. {
  195. struct acpi_processor_power *pwr = &pr->power;
  196. u8 type = local_apic_timer_c2_ok ? ACPI_STATE_C3 : ACPI_STATE_C2;
  197. /*
  198. * Check, if one of the previous states already marked the lapic
  199. * unstable
  200. */
  201. if (pwr->timer_broadcast_on_state < state)
  202. return;
  203. if (cx->type >= type)
  204. pr->power.timer_broadcast_on_state = state;
  205. }
  206. static void acpi_propagate_timer_broadcast(struct acpi_processor *pr)
  207. {
  208. unsigned long reason;
  209. reason = pr->power.timer_broadcast_on_state < INT_MAX ?
  210. CLOCK_EVT_NOTIFY_BROADCAST_ON : CLOCK_EVT_NOTIFY_BROADCAST_OFF;
  211. clockevents_notify(reason, &pr->id);
  212. }
  213. /* Power(C) State timer broadcast control */
  214. static void acpi_state_timer_broadcast(struct acpi_processor *pr,
  215. struct acpi_processor_cx *cx,
  216. int broadcast)
  217. {
  218. int state = cx - pr->power.states;
  219. if (state >= pr->power.timer_broadcast_on_state) {
  220. unsigned long reason;
  221. reason = broadcast ? CLOCK_EVT_NOTIFY_BROADCAST_ENTER :
  222. CLOCK_EVT_NOTIFY_BROADCAST_EXIT;
  223. clockevents_notify(reason, &pr->id);
  224. }
  225. }
  226. #else
  227. static void acpi_timer_check_state(int state, struct acpi_processor *pr,
  228. struct acpi_processor_cx *cstate) { }
  229. static void acpi_propagate_timer_broadcast(struct acpi_processor *pr) { }
  230. static void acpi_state_timer_broadcast(struct acpi_processor *pr,
  231. struct acpi_processor_cx *cx,
  232. int broadcast)
  233. {
  234. }
  235. #endif
  236. /*
  237. * Suspend / resume control
  238. */
  239. static int acpi_idle_suspend;
  240. int acpi_processor_suspend(struct acpi_device * device, pm_message_t state)
  241. {
  242. acpi_idle_suspend = 1;
  243. return 0;
  244. }
  245. int acpi_processor_resume(struct acpi_device * device)
  246. {
  247. acpi_idle_suspend = 0;
  248. return 0;
  249. }
  250. #if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86)
  251. static int tsc_halts_in_c(int state)
  252. {
  253. switch (boot_cpu_data.x86_vendor) {
  254. case X86_VENDOR_AMD:
  255. case X86_VENDOR_INTEL:
  256. /*
  257. * AMD Fam10h TSC will tick in all
  258. * C/P/S0/S1 states when this bit is set.
  259. */
  260. if (boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
  261. return 0;
  262. /*FALL THROUGH*/
  263. default:
  264. return state > ACPI_STATE_C1;
  265. }
  266. }
  267. #endif
  268. static int acpi_processor_get_power_info_fadt(struct acpi_processor *pr)
  269. {
  270. if (!pr)
  271. return -EINVAL;
  272. if (!pr->pblk)
  273. return -ENODEV;
  274. /* if info is obtained from pblk/fadt, type equals state */
  275. pr->power.states[ACPI_STATE_C2].type = ACPI_STATE_C2;
  276. pr->power.states[ACPI_STATE_C3].type = ACPI_STATE_C3;
  277. #ifndef CONFIG_HOTPLUG_CPU
  278. /*
  279. * Check for P_LVL2_UP flag before entering C2 and above on
  280. * an SMP system.
  281. */
  282. if ((num_online_cpus() > 1) &&
  283. !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
  284. return -ENODEV;
  285. #endif
  286. /* determine C2 and C3 address from pblk */
  287. pr->power.states[ACPI_STATE_C2].address = pr->pblk + 4;
  288. pr->power.states[ACPI_STATE_C3].address = pr->pblk + 5;
  289. /* determine latencies from FADT */
  290. pr->power.states[ACPI_STATE_C2].latency = acpi_gbl_FADT.C2latency;
  291. pr->power.states[ACPI_STATE_C3].latency = acpi_gbl_FADT.C3latency;
  292. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  293. "lvl2[0x%08x] lvl3[0x%08x]\n",
  294. pr->power.states[ACPI_STATE_C2].address,
  295. pr->power.states[ACPI_STATE_C3].address));
  296. return 0;
  297. }
  298. static int acpi_processor_get_power_info_default(struct acpi_processor *pr)
  299. {
  300. if (!pr->power.states[ACPI_STATE_C1].valid) {
  301. /* set the first C-State to C1 */
  302. /* all processors need to support C1 */
  303. pr->power.states[ACPI_STATE_C1].type = ACPI_STATE_C1;
  304. pr->power.states[ACPI_STATE_C1].valid = 1;
  305. pr->power.states[ACPI_STATE_C1].entry_method = ACPI_CSTATE_HALT;
  306. }
  307. /* the C0 state only exists as a filler in our array */
  308. pr->power.states[ACPI_STATE_C0].valid = 1;
  309. return 0;
  310. }
  311. static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
  312. {
  313. acpi_status status = 0;
  314. acpi_integer count;
  315. int current_count;
  316. int i;
  317. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  318. union acpi_object *cst;
  319. if (nocst)
  320. return -ENODEV;
  321. current_count = 0;
  322. status = acpi_evaluate_object(pr->handle, "_CST", NULL, &buffer);
  323. if (ACPI_FAILURE(status)) {
  324. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No _CST, giving up\n"));
  325. return -ENODEV;
  326. }
  327. cst = buffer.pointer;
  328. /* There must be at least 2 elements */
  329. if (!cst || (cst->type != ACPI_TYPE_PACKAGE) || cst->package.count < 2) {
  330. printk(KERN_ERR PREFIX "not enough elements in _CST\n");
  331. status = -EFAULT;
  332. goto end;
  333. }
  334. count = cst->package.elements[0].integer.value;
  335. /* Validate number of power states. */
  336. if (count < 1 || count != cst->package.count - 1) {
  337. printk(KERN_ERR PREFIX "count given by _CST is not valid\n");
  338. status = -EFAULT;
  339. goto end;
  340. }
  341. /* Tell driver that at least _CST is supported. */
  342. pr->flags.has_cst = 1;
  343. for (i = 1; i <= count; i++) {
  344. union acpi_object *element;
  345. union acpi_object *obj;
  346. struct acpi_power_register *reg;
  347. struct acpi_processor_cx cx;
  348. memset(&cx, 0, sizeof(cx));
  349. element = &(cst->package.elements[i]);
  350. if (element->type != ACPI_TYPE_PACKAGE)
  351. continue;
  352. if (element->package.count != 4)
  353. continue;
  354. obj = &(element->package.elements[0]);
  355. if (obj->type != ACPI_TYPE_BUFFER)
  356. continue;
  357. reg = (struct acpi_power_register *)obj->buffer.pointer;
  358. if (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO &&
  359. (reg->space_id != ACPI_ADR_SPACE_FIXED_HARDWARE))
  360. continue;
  361. /* There should be an easy way to extract an integer... */
  362. obj = &(element->package.elements[1]);
  363. if (obj->type != ACPI_TYPE_INTEGER)
  364. continue;
  365. cx.type = obj->integer.value;
  366. /*
  367. * Some buggy BIOSes won't list C1 in _CST -
  368. * Let acpi_processor_get_power_info_default() handle them later
  369. */
  370. if (i == 1 && cx.type != ACPI_STATE_C1)
  371. current_count++;
  372. cx.address = reg->address;
  373. cx.index = current_count + 1;
  374. cx.entry_method = ACPI_CSTATE_SYSTEMIO;
  375. if (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) {
  376. if (acpi_processor_ffh_cstate_probe
  377. (pr->id, &cx, reg) == 0) {
  378. cx.entry_method = ACPI_CSTATE_FFH;
  379. } else if (cx.type == ACPI_STATE_C1) {
  380. /*
  381. * C1 is a special case where FIXED_HARDWARE
  382. * can be handled in non-MWAIT way as well.
  383. * In that case, save this _CST entry info.
  384. * Otherwise, ignore this info and continue.
  385. */
  386. cx.entry_method = ACPI_CSTATE_HALT;
  387. snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI HLT");
  388. } else {
  389. continue;
  390. }
  391. if (cx.type == ACPI_STATE_C1 &&
  392. (idle_halt || idle_nomwait)) {
  393. /*
  394. * In most cases the C1 space_id obtained from
  395. * _CST object is FIXED_HARDWARE access mode.
  396. * But when the option of idle=halt is added,
  397. * the entry_method type should be changed from
  398. * CSTATE_FFH to CSTATE_HALT.
  399. * When the option of idle=nomwait is added,
  400. * the C1 entry_method type should be
  401. * CSTATE_HALT.
  402. */
  403. cx.entry_method = ACPI_CSTATE_HALT;
  404. snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI HLT");
  405. }
  406. } else {
  407. snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI IOPORT 0x%x",
  408. cx.address);
  409. }
  410. if (cx.type == ACPI_STATE_C1) {
  411. cx.valid = 1;
  412. }
  413. obj = &(element->package.elements[2]);
  414. if (obj->type != ACPI_TYPE_INTEGER)
  415. continue;
  416. cx.latency = obj->integer.value;
  417. obj = &(element->package.elements[3]);
  418. if (obj->type != ACPI_TYPE_INTEGER)
  419. continue;
  420. cx.power = obj->integer.value;
  421. current_count++;
  422. memcpy(&(pr->power.states[current_count]), &cx, sizeof(cx));
  423. /*
  424. * We support total ACPI_PROCESSOR_MAX_POWER - 1
  425. * (From 1 through ACPI_PROCESSOR_MAX_POWER - 1)
  426. */
  427. if (current_count >= (ACPI_PROCESSOR_MAX_POWER - 1)) {
  428. printk(KERN_WARNING
  429. "Limiting number of power states to max (%d)\n",
  430. ACPI_PROCESSOR_MAX_POWER);
  431. printk(KERN_WARNING
  432. "Please increase ACPI_PROCESSOR_MAX_POWER if needed.\n");
  433. break;
  434. }
  435. }
  436. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d power states\n",
  437. current_count));
  438. /* Validate number of power states discovered */
  439. if (current_count < 2)
  440. status = -EFAULT;
  441. end:
  442. kfree(buffer.pointer);
  443. return status;
  444. }
  445. static void acpi_processor_power_verify_c2(struct acpi_processor_cx *cx)
  446. {
  447. if (!cx->address)
  448. return;
  449. /*
  450. * C2 latency must be less than or equal to 100
  451. * microseconds.
  452. */
  453. else if (cx->latency > ACPI_PROCESSOR_MAX_C2_LATENCY) {
  454. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  455. "latency too large [%d]\n", cx->latency));
  456. return;
  457. }
  458. /*
  459. * Otherwise we've met all of our C2 requirements.
  460. * Normalize the C2 latency to expidite policy
  461. */
  462. cx->valid = 1;
  463. cx->latency_ticks = cx->latency;
  464. return;
  465. }
  466. static void acpi_processor_power_verify_c3(struct acpi_processor *pr,
  467. struct acpi_processor_cx *cx)
  468. {
  469. static int bm_check_flag;
  470. if (!cx->address)
  471. return;
  472. /*
  473. * C3 latency must be less than or equal to 1000
  474. * microseconds.
  475. */
  476. else if (cx->latency > ACPI_PROCESSOR_MAX_C3_LATENCY) {
  477. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  478. "latency too large [%d]\n", cx->latency));
  479. return;
  480. }
  481. /*
  482. * PIIX4 Erratum #18: We don't support C3 when Type-F (fast)
  483. * DMA transfers are used by any ISA device to avoid livelock.
  484. * Note that we could disable Type-F DMA (as recommended by
  485. * the erratum), but this is known to disrupt certain ISA
  486. * devices thus we take the conservative approach.
  487. */
  488. else if (errata.piix4.fdma) {
  489. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  490. "C3 not supported on PIIX4 with Type-F DMA\n"));
  491. return;
  492. }
  493. /* All the logic here assumes flags.bm_check is same across all CPUs */
  494. if (!bm_check_flag) {
  495. /* Determine whether bm_check is needed based on CPU */
  496. acpi_processor_power_init_bm_check(&(pr->flags), pr->id);
  497. bm_check_flag = pr->flags.bm_check;
  498. } else {
  499. pr->flags.bm_check = bm_check_flag;
  500. }
  501. if (pr->flags.bm_check) {
  502. if (!pr->flags.bm_control) {
  503. if (pr->flags.has_cst != 1) {
  504. /* bus mastering control is necessary */
  505. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  506. "C3 support requires BM control\n"));
  507. return;
  508. } else {
  509. /* Here we enter C3 without bus mastering */
  510. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  511. "C3 support without BM control\n"));
  512. }
  513. }
  514. } else {
  515. /*
  516. * WBINVD should be set in fadt, for C3 state to be
  517. * supported on when bm_check is not required.
  518. */
  519. if (!(acpi_gbl_FADT.flags & ACPI_FADT_WBINVD)) {
  520. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  521. "Cache invalidation should work properly"
  522. " for C3 to be enabled on SMP systems\n"));
  523. return;
  524. }
  525. }
  526. /*
  527. * Otherwise we've met all of our C3 requirements.
  528. * Normalize the C3 latency to expidite policy. Enable
  529. * checking of bus mastering status (bm_check) so we can
  530. * use this in our C3 policy
  531. */
  532. cx->valid = 1;
  533. cx->latency_ticks = cx->latency;
  534. /*
  535. * On older chipsets, BM_RLD needs to be set
  536. * in order for Bus Master activity to wake the
  537. * system from C3. Newer chipsets handle DMA
  538. * during C3 automatically and BM_RLD is a NOP.
  539. * In either case, the proper way to
  540. * handle BM_RLD is to set it and leave it set.
  541. */
  542. acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 1);
  543. return;
  544. }
  545. static int acpi_processor_power_verify(struct acpi_processor *pr)
  546. {
  547. unsigned int i;
  548. unsigned int working = 0;
  549. pr->power.timer_broadcast_on_state = INT_MAX;
  550. for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
  551. struct acpi_processor_cx *cx = &pr->power.states[i];
  552. switch (cx->type) {
  553. case ACPI_STATE_C1:
  554. cx->valid = 1;
  555. break;
  556. case ACPI_STATE_C2:
  557. acpi_processor_power_verify_c2(cx);
  558. if (cx->valid)
  559. acpi_timer_check_state(i, pr, cx);
  560. break;
  561. case ACPI_STATE_C3:
  562. acpi_processor_power_verify_c3(pr, cx);
  563. if (cx->valid)
  564. acpi_timer_check_state(i, pr, cx);
  565. break;
  566. }
  567. if (cx->valid)
  568. working++;
  569. }
  570. acpi_propagate_timer_broadcast(pr);
  571. return (working);
  572. }
  573. static int acpi_processor_get_power_info(struct acpi_processor *pr)
  574. {
  575. unsigned int i;
  576. int result;
  577. /* NOTE: the idle thread may not be running while calling
  578. * this function */
  579. /* Zero initialize all the C-states info. */
  580. memset(pr->power.states, 0, sizeof(pr->power.states));
  581. result = acpi_processor_get_power_info_cst(pr);
  582. if (result == -ENODEV)
  583. result = acpi_processor_get_power_info_fadt(pr);
  584. if (result)
  585. return result;
  586. acpi_processor_get_power_info_default(pr);
  587. pr->power.count = acpi_processor_power_verify(pr);
  588. /*
  589. * if one state of type C2 or C3 is available, mark this
  590. * CPU as being "idle manageable"
  591. */
  592. for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
  593. if (pr->power.states[i].valid) {
  594. pr->power.count = i;
  595. if (pr->power.states[i].type >= ACPI_STATE_C2)
  596. pr->flags.power = 1;
  597. }
  598. }
  599. return 0;
  600. }
  601. static int acpi_processor_power_seq_show(struct seq_file *seq, void *offset)
  602. {
  603. struct acpi_processor *pr = seq->private;
  604. unsigned int i;
  605. if (!pr)
  606. goto end;
  607. seq_printf(seq, "active state: C%zd\n"
  608. "max_cstate: C%d\n"
  609. "bus master activity: %08x\n"
  610. "maximum allowed latency: %d usec\n",
  611. pr->power.state ? pr->power.state - pr->power.states : 0,
  612. max_cstate, (unsigned)pr->power.bm_activity,
  613. pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY));
  614. seq_puts(seq, "states:\n");
  615. for (i = 1; i <= pr->power.count; i++) {
  616. seq_printf(seq, " %cC%d: ",
  617. (&pr->power.states[i] ==
  618. pr->power.state ? '*' : ' '), i);
  619. if (!pr->power.states[i].valid) {
  620. seq_puts(seq, "<not supported>\n");
  621. continue;
  622. }
  623. switch (pr->power.states[i].type) {
  624. case ACPI_STATE_C1:
  625. seq_printf(seq, "type[C1] ");
  626. break;
  627. case ACPI_STATE_C2:
  628. seq_printf(seq, "type[C2] ");
  629. break;
  630. case ACPI_STATE_C3:
  631. seq_printf(seq, "type[C3] ");
  632. break;
  633. default:
  634. seq_printf(seq, "type[--] ");
  635. break;
  636. }
  637. if (pr->power.states[i].promotion.state)
  638. seq_printf(seq, "promotion[C%zd] ",
  639. (pr->power.states[i].promotion.state -
  640. pr->power.states));
  641. else
  642. seq_puts(seq, "promotion[--] ");
  643. if (pr->power.states[i].demotion.state)
  644. seq_printf(seq, "demotion[C%zd] ",
  645. (pr->power.states[i].demotion.state -
  646. pr->power.states));
  647. else
  648. seq_puts(seq, "demotion[--] ");
  649. seq_printf(seq, "latency[%03d] usage[%08d] duration[%020llu]\n",
  650. pr->power.states[i].latency,
  651. pr->power.states[i].usage,
  652. (unsigned long long)pr->power.states[i].time);
  653. }
  654. end:
  655. return 0;
  656. }
  657. static int acpi_processor_power_open_fs(struct inode *inode, struct file *file)
  658. {
  659. return single_open(file, acpi_processor_power_seq_show,
  660. PDE(inode)->data);
  661. }
  662. static const struct file_operations acpi_processor_power_fops = {
  663. .owner = THIS_MODULE,
  664. .open = acpi_processor_power_open_fs,
  665. .read = seq_read,
  666. .llseek = seq_lseek,
  667. .release = single_release,
  668. };
  669. /**
  670. * acpi_idle_bm_check - checks if bus master activity was detected
  671. */
  672. static int acpi_idle_bm_check(void)
  673. {
  674. u32 bm_status = 0;
  675. acpi_get_register_unlocked(ACPI_BITREG_BUS_MASTER_STATUS, &bm_status);
  676. if (bm_status)
  677. acpi_set_register(ACPI_BITREG_BUS_MASTER_STATUS, 1);
  678. /*
  679. * PIIX4 Erratum #18: Note that BM_STS doesn't always reflect
  680. * the true state of bus mastering activity; forcing us to
  681. * manually check the BMIDEA bit of each IDE channel.
  682. */
  683. else if (errata.piix4.bmisx) {
  684. if ((inb_p(errata.piix4.bmisx + 0x02) & 0x01)
  685. || (inb_p(errata.piix4.bmisx + 0x0A) & 0x01))
  686. bm_status = 1;
  687. }
  688. return bm_status;
  689. }
  690. /**
  691. * acpi_idle_do_entry - a helper function that does C2 and C3 type entry
  692. * @cx: cstate data
  693. *
  694. * Caller disables interrupt before call and enables interrupt after return.
  695. */
  696. static inline void acpi_idle_do_entry(struct acpi_processor_cx *cx)
  697. {
  698. /* Don't trace irqs off for idle */
  699. stop_critical_timings();
  700. if (cx->entry_method == ACPI_CSTATE_FFH) {
  701. /* Call into architectural FFH based C-state */
  702. acpi_processor_ffh_cstate_enter(cx);
  703. } else if (cx->entry_method == ACPI_CSTATE_HALT) {
  704. acpi_safe_halt();
  705. } else {
  706. int unused;
  707. /* IO port based C-state */
  708. inb(cx->address);
  709. /* Dummy wait op - must do something useless after P_LVL2 read
  710. because chipsets cannot guarantee that STPCLK# signal
  711. gets asserted in time to freeze execution properly. */
  712. unused = inl(acpi_gbl_FADT.xpm_timer_block.address);
  713. }
  714. start_critical_timings();
  715. }
  716. /**
  717. * acpi_idle_enter_c1 - enters an ACPI C1 state-type
  718. * @dev: the target CPU
  719. * @state: the state data
  720. *
  721. * This is equivalent to the HALT instruction.
  722. */
  723. static int acpi_idle_enter_c1(struct cpuidle_device *dev,
  724. struct cpuidle_state *state)
  725. {
  726. u32 t1, t2;
  727. struct acpi_processor *pr;
  728. struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
  729. pr = __get_cpu_var(processors);
  730. if (unlikely(!pr))
  731. return 0;
  732. local_irq_disable();
  733. /* Do not access any ACPI IO ports in suspend path */
  734. if (acpi_idle_suspend) {
  735. acpi_safe_halt();
  736. local_irq_enable();
  737. return 0;
  738. }
  739. t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
  740. acpi_idle_do_entry(cx);
  741. t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
  742. local_irq_enable();
  743. cx->usage++;
  744. return ticks_elapsed_in_us(t1, t2);
  745. }
  746. /**
  747. * acpi_idle_enter_simple - enters an ACPI state without BM handling
  748. * @dev: the target CPU
  749. * @state: the state data
  750. */
  751. static int acpi_idle_enter_simple(struct cpuidle_device *dev,
  752. struct cpuidle_state *state)
  753. {
  754. struct acpi_processor *pr;
  755. struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
  756. u32 t1, t2;
  757. int sleep_ticks = 0;
  758. pr = __get_cpu_var(processors);
  759. if (unlikely(!pr))
  760. return 0;
  761. if (acpi_idle_suspend)
  762. return(acpi_idle_enter_c1(dev, state));
  763. local_irq_disable();
  764. current_thread_info()->status &= ~TS_POLLING;
  765. /*
  766. * TS_POLLING-cleared state must be visible before we test
  767. * NEED_RESCHED:
  768. */
  769. smp_mb();
  770. if (unlikely(need_resched())) {
  771. current_thread_info()->status |= TS_POLLING;
  772. local_irq_enable();
  773. return 0;
  774. }
  775. /*
  776. * Must be done before busmaster disable as we might need to
  777. * access HPET !
  778. */
  779. acpi_state_timer_broadcast(pr, cx, 1);
  780. if (cx->type == ACPI_STATE_C3)
  781. ACPI_FLUSH_CPU_CACHE();
  782. t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
  783. /* Tell the scheduler that we are going deep-idle: */
  784. sched_clock_idle_sleep_event();
  785. acpi_idle_do_entry(cx);
  786. t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
  787. #if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86)
  788. /* TSC could halt in idle, so notify users */
  789. if (tsc_halts_in_c(cx->type))
  790. mark_tsc_unstable("TSC halts in idle");;
  791. #endif
  792. sleep_ticks = ticks_elapsed(t1, t2);
  793. /* Tell the scheduler how much we idled: */
  794. sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS);
  795. local_irq_enable();
  796. current_thread_info()->status |= TS_POLLING;
  797. cx->usage++;
  798. acpi_state_timer_broadcast(pr, cx, 0);
  799. cx->time += sleep_ticks;
  800. return ticks_elapsed_in_us(t1, t2);
  801. }
  802. static int c3_cpu_count;
  803. static DEFINE_SPINLOCK(c3_lock);
  804. /**
  805. * acpi_idle_enter_bm - enters C3 with proper BM handling
  806. * @dev: the target CPU
  807. * @state: the state data
  808. *
  809. * If BM is detected, the deepest non-C3 idle state is entered instead.
  810. */
  811. static int acpi_idle_enter_bm(struct cpuidle_device *dev,
  812. struct cpuidle_state *state)
  813. {
  814. struct acpi_processor *pr;
  815. struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
  816. u32 t1, t2;
  817. int sleep_ticks = 0;
  818. pr = __get_cpu_var(processors);
  819. if (unlikely(!pr))
  820. return 0;
  821. if (acpi_idle_suspend)
  822. return(acpi_idle_enter_c1(dev, state));
  823. if (acpi_idle_bm_check()) {
  824. if (dev->safe_state) {
  825. dev->last_state = dev->safe_state;
  826. return dev->safe_state->enter(dev, dev->safe_state);
  827. } else {
  828. local_irq_disable();
  829. acpi_safe_halt();
  830. local_irq_enable();
  831. return 0;
  832. }
  833. }
  834. local_irq_disable();
  835. current_thread_info()->status &= ~TS_POLLING;
  836. /*
  837. * TS_POLLING-cleared state must be visible before we test
  838. * NEED_RESCHED:
  839. */
  840. smp_mb();
  841. if (unlikely(need_resched())) {
  842. current_thread_info()->status |= TS_POLLING;
  843. local_irq_enable();
  844. return 0;
  845. }
  846. acpi_unlazy_tlb(smp_processor_id());
  847. /* Tell the scheduler that we are going deep-idle: */
  848. sched_clock_idle_sleep_event();
  849. /*
  850. * Must be done before busmaster disable as we might need to
  851. * access HPET !
  852. */
  853. acpi_state_timer_broadcast(pr, cx, 1);
  854. /*
  855. * disable bus master
  856. * bm_check implies we need ARB_DIS
  857. * !bm_check implies we need cache flush
  858. * bm_control implies whether we can do ARB_DIS
  859. *
  860. * That leaves a case where bm_check is set and bm_control is
  861. * not set. In that case we cannot do much, we enter C3
  862. * without doing anything.
  863. */
  864. if (pr->flags.bm_check && pr->flags.bm_control) {
  865. spin_lock(&c3_lock);
  866. c3_cpu_count++;
  867. /* Disable bus master arbitration when all CPUs are in C3 */
  868. if (c3_cpu_count == num_online_cpus())
  869. acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1);
  870. spin_unlock(&c3_lock);
  871. } else if (!pr->flags.bm_check) {
  872. ACPI_FLUSH_CPU_CACHE();
  873. }
  874. t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
  875. acpi_idle_do_entry(cx);
  876. t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
  877. /* Re-enable bus master arbitration */
  878. if (pr->flags.bm_check && pr->flags.bm_control) {
  879. spin_lock(&c3_lock);
  880. acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0);
  881. c3_cpu_count--;
  882. spin_unlock(&c3_lock);
  883. }
  884. #if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86)
  885. /* TSC could halt in idle, so notify users */
  886. if (tsc_halts_in_c(ACPI_STATE_C3))
  887. mark_tsc_unstable("TSC halts in idle");
  888. #endif
  889. sleep_ticks = ticks_elapsed(t1, t2);
  890. /* Tell the scheduler how much we idled: */
  891. sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS);
  892. local_irq_enable();
  893. current_thread_info()->status |= TS_POLLING;
  894. cx->usage++;
  895. acpi_state_timer_broadcast(pr, cx, 0);
  896. cx->time += sleep_ticks;
  897. return ticks_elapsed_in_us(t1, t2);
  898. }
  899. struct cpuidle_driver acpi_idle_driver = {
  900. .name = "acpi_idle",
  901. .owner = THIS_MODULE,
  902. };
  903. /**
  904. * acpi_processor_setup_cpuidle - prepares and configures CPUIDLE
  905. * @pr: the ACPI processor
  906. */
  907. static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
  908. {
  909. int i, count = CPUIDLE_DRIVER_STATE_START;
  910. struct acpi_processor_cx *cx;
  911. struct cpuidle_state *state;
  912. struct cpuidle_device *dev = &pr->power.dev;
  913. if (!pr->flags.power_setup_done)
  914. return -EINVAL;
  915. if (pr->flags.power == 0) {
  916. return -EINVAL;
  917. }
  918. dev->cpu = pr->id;
  919. for (i = 0; i < CPUIDLE_STATE_MAX; i++) {
  920. dev->states[i].name[0] = '\0';
  921. dev->states[i].desc[0] = '\0';
  922. }
  923. for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) {
  924. cx = &pr->power.states[i];
  925. state = &dev->states[count];
  926. if (!cx->valid)
  927. continue;
  928. #ifdef CONFIG_HOTPLUG_CPU
  929. if ((cx->type != ACPI_STATE_C1) && (num_online_cpus() > 1) &&
  930. !pr->flags.has_cst &&
  931. !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
  932. continue;
  933. #endif
  934. cpuidle_set_statedata(state, cx);
  935. snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i);
  936. strncpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);
  937. state->exit_latency = cx->latency;
  938. state->target_residency = cx->latency * latency_factor;
  939. state->power_usage = cx->power;
  940. state->flags = 0;
  941. switch (cx->type) {
  942. case ACPI_STATE_C1:
  943. state->flags |= CPUIDLE_FLAG_SHALLOW;
  944. if (cx->entry_method == ACPI_CSTATE_FFH)
  945. state->flags |= CPUIDLE_FLAG_TIME_VALID;
  946. state->enter = acpi_idle_enter_c1;
  947. dev->safe_state = state;
  948. break;
  949. case ACPI_STATE_C2:
  950. state->flags |= CPUIDLE_FLAG_BALANCED;
  951. state->flags |= CPUIDLE_FLAG_TIME_VALID;
  952. state->enter = acpi_idle_enter_simple;
  953. dev->safe_state = state;
  954. break;
  955. case ACPI_STATE_C3:
  956. state->flags |= CPUIDLE_FLAG_DEEP;
  957. state->flags |= CPUIDLE_FLAG_TIME_VALID;
  958. state->flags |= CPUIDLE_FLAG_CHECK_BM;
  959. state->enter = pr->flags.bm_check ?
  960. acpi_idle_enter_bm :
  961. acpi_idle_enter_simple;
  962. break;
  963. }
  964. count++;
  965. if (count == CPUIDLE_STATE_MAX)
  966. break;
  967. }
  968. dev->state_count = count;
  969. if (!count)
  970. return -EINVAL;
  971. return 0;
  972. }
  973. int acpi_processor_cst_has_changed(struct acpi_processor *pr)
  974. {
  975. int ret = 0;
  976. if (boot_option_idle_override)
  977. return 0;
  978. if (!pr)
  979. return -EINVAL;
  980. if (nocst) {
  981. return -ENODEV;
  982. }
  983. if (!pr->flags.power_setup_done)
  984. return -ENODEV;
  985. cpuidle_pause_and_lock();
  986. cpuidle_disable_device(&pr->power.dev);
  987. acpi_processor_get_power_info(pr);
  988. if (pr->flags.power) {
  989. acpi_processor_setup_cpuidle(pr);
  990. ret = cpuidle_enable_device(&pr->power.dev);
  991. }
  992. cpuidle_resume_and_unlock();
  993. return ret;
  994. }
  995. int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
  996. struct acpi_device *device)
  997. {
  998. acpi_status status = 0;
  999. static int first_run;
  1000. struct proc_dir_entry *entry = NULL;
  1001. unsigned int i;
  1002. if (boot_option_idle_override)
  1003. return 0;
  1004. if (!first_run) {
  1005. if (idle_halt) {
  1006. /*
  1007. * When the boot option of "idle=halt" is added, halt
  1008. * is used for CPU IDLE.
  1009. * In such case C2/C3 is meaningless. So the max_cstate
  1010. * is set to one.
  1011. */
  1012. max_cstate = 1;
  1013. }
  1014. dmi_check_system(processor_power_dmi_table);
  1015. max_cstate = acpi_processor_cstate_check(max_cstate);
  1016. if (max_cstate < ACPI_C_STATES_MAX)
  1017. printk(KERN_NOTICE
  1018. "ACPI: processor limited to max C-state %d\n",
  1019. max_cstate);
  1020. first_run++;
  1021. }
  1022. if (!pr)
  1023. return -EINVAL;
  1024. if (acpi_gbl_FADT.cst_control && !nocst) {
  1025. status =
  1026. acpi_os_write_port(acpi_gbl_FADT.smi_command, acpi_gbl_FADT.cst_control, 8);
  1027. if (ACPI_FAILURE(status)) {
  1028. ACPI_EXCEPTION((AE_INFO, status,
  1029. "Notifying BIOS of _CST ability failed"));
  1030. }
  1031. }
  1032. acpi_processor_get_power_info(pr);
  1033. pr->flags.power_setup_done = 1;
  1034. /*
  1035. * Install the idle handler if processor power management is supported.
  1036. * Note that we use previously set idle handler will be used on
  1037. * platforms that only support C1.
  1038. */
  1039. if (pr->flags.power) {
  1040. acpi_processor_setup_cpuidle(pr);
  1041. if (cpuidle_register_device(&pr->power.dev))
  1042. return -EIO;
  1043. printk(KERN_INFO PREFIX "CPU%d (power states:", pr->id);
  1044. for (i = 1; i <= pr->power.count; i++)
  1045. if (pr->power.states[i].valid)
  1046. printk(" C%d[C%d]", i,
  1047. pr->power.states[i].type);
  1048. printk(")\n");
  1049. }
  1050. /* 'power' [R] */
  1051. entry = proc_create_data(ACPI_PROCESSOR_FILE_POWER,
  1052. S_IRUGO, acpi_device_dir(device),
  1053. &acpi_processor_power_fops,
  1054. acpi_driver_data(device));
  1055. if (!entry)
  1056. return -EIO;
  1057. return 0;
  1058. }
  1059. int acpi_processor_power_exit(struct acpi_processor *pr,
  1060. struct acpi_device *device)
  1061. {
  1062. if (boot_option_idle_override)
  1063. return 0;
  1064. cpuidle_unregister_device(&pr->power.dev);
  1065. pr->flags.power_setup_done = 0;
  1066. if (acpi_device_dir(device))
  1067. remove_proc_entry(ACPI_PROCESSOR_FILE_POWER,
  1068. acpi_device_dir(device));
  1069. return 0;
  1070. }