processor_idle.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863
  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. /*
  44. * Include the apic definitions for x86 to have the APIC timer related defines
  45. * available also for UP (on SMP it gets magically included via linux/smp.h).
  46. * asm/acpi.h is not an option, as it would require more include magic. Also
  47. * creating an empty asm-ia64/apic.h would just trade pest vs. cholera.
  48. */
  49. #ifdef CONFIG_X86
  50. #include <asm/apic.h>
  51. #endif
  52. #include <asm/io.h>
  53. #include <asm/uaccess.h>
  54. #include <acpi/acpi_bus.h>
  55. #include <acpi/processor.h>
  56. #define ACPI_PROCESSOR_COMPONENT 0x01000000
  57. #define ACPI_PROCESSOR_CLASS "processor"
  58. #define _COMPONENT ACPI_PROCESSOR_COMPONENT
  59. ACPI_MODULE_NAME("processor_idle");
  60. #define ACPI_PROCESSOR_FILE_POWER "power"
  61. #define US_TO_PM_TIMER_TICKS(t) ((t * (PM_TIMER_FREQUENCY/1000)) / 1000)
  62. #define PM_TIMER_TICK_NS (1000000000ULL/PM_TIMER_FREQUENCY)
  63. #ifndef CONFIG_CPU_IDLE
  64. #define C2_OVERHEAD 4 /* 1us (3.579 ticks per us) */
  65. #define C3_OVERHEAD 4 /* 1us (3.579 ticks per us) */
  66. static void (*pm_idle_save) (void) __read_mostly;
  67. #else
  68. #define C2_OVERHEAD 1 /* 1us */
  69. #define C3_OVERHEAD 1 /* 1us */
  70. #endif
  71. #define PM_TIMER_TICKS_TO_US(p) (((p) * 1000)/(PM_TIMER_FREQUENCY/1000))
  72. static unsigned int max_cstate __read_mostly = ACPI_PROCESSOR_MAX_POWER;
  73. #ifdef CONFIG_CPU_IDLE
  74. module_param(max_cstate, uint, 0000);
  75. #else
  76. module_param(max_cstate, uint, 0644);
  77. #endif
  78. static unsigned int nocst __read_mostly;
  79. module_param(nocst, uint, 0000);
  80. #ifndef CONFIG_CPU_IDLE
  81. /*
  82. * bm_history -- bit-mask with a bit per jiffy of bus-master activity
  83. * 1000 HZ: 0xFFFFFFFF: 32 jiffies = 32ms
  84. * 800 HZ: 0xFFFFFFFF: 32 jiffies = 40ms
  85. * 100 HZ: 0x0000000F: 4 jiffies = 40ms
  86. * reduce history for more aggressive entry into C3
  87. */
  88. static unsigned int bm_history __read_mostly =
  89. (HZ >= 800 ? 0xFFFFFFFF : ((1U << (HZ / 25)) - 1));
  90. module_param(bm_history, uint, 0644);
  91. static int acpi_processor_set_power_policy(struct acpi_processor *pr);
  92. #else /* CONFIG_CPU_IDLE */
  93. static unsigned int latency_factor __read_mostly = 2;
  94. module_param(latency_factor, uint, 0644);
  95. #endif
  96. /*
  97. * IBM ThinkPad R40e crashes mysteriously when going into C2 or C3.
  98. * For now disable this. Probably a bug somewhere else.
  99. *
  100. * To skip this limit, boot/load with a large max_cstate limit.
  101. */
  102. static int set_max_cstate(const struct dmi_system_id *id)
  103. {
  104. if (max_cstate > ACPI_PROCESSOR_MAX_POWER)
  105. return 0;
  106. printk(KERN_NOTICE PREFIX "%s detected - limiting to C%ld max_cstate."
  107. " Override with \"processor.max_cstate=%d\"\n", id->ident,
  108. (long)id->driver_data, ACPI_PROCESSOR_MAX_POWER + 1);
  109. max_cstate = (long)id->driver_data;
  110. return 0;
  111. }
  112. /* Actually this shouldn't be __cpuinitdata, would be better to fix the
  113. callers to only run once -AK */
  114. static struct dmi_system_id __cpuinitdata processor_power_dmi_table[] = {
  115. { set_max_cstate, "IBM ThinkPad R40e", {
  116. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  117. DMI_MATCH(DMI_BIOS_VERSION,"1SET70WW")}, (void *)1},
  118. { set_max_cstate, "IBM ThinkPad R40e", {
  119. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  120. DMI_MATCH(DMI_BIOS_VERSION,"1SET60WW")}, (void *)1},
  121. { set_max_cstate, "IBM ThinkPad R40e", {
  122. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  123. DMI_MATCH(DMI_BIOS_VERSION,"1SET43WW") }, (void*)1},
  124. { set_max_cstate, "IBM ThinkPad R40e", {
  125. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  126. DMI_MATCH(DMI_BIOS_VERSION,"1SET45WW") }, (void*)1},
  127. { set_max_cstate, "IBM ThinkPad R40e", {
  128. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  129. DMI_MATCH(DMI_BIOS_VERSION,"1SET47WW") }, (void*)1},
  130. { set_max_cstate, "IBM ThinkPad R40e", {
  131. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  132. DMI_MATCH(DMI_BIOS_VERSION,"1SET50WW") }, (void*)1},
  133. { set_max_cstate, "IBM ThinkPad R40e", {
  134. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  135. DMI_MATCH(DMI_BIOS_VERSION,"1SET52WW") }, (void*)1},
  136. { set_max_cstate, "IBM ThinkPad R40e", {
  137. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  138. DMI_MATCH(DMI_BIOS_VERSION,"1SET55WW") }, (void*)1},
  139. { set_max_cstate, "IBM ThinkPad R40e", {
  140. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  141. DMI_MATCH(DMI_BIOS_VERSION,"1SET56WW") }, (void*)1},
  142. { set_max_cstate, "IBM ThinkPad R40e", {
  143. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  144. DMI_MATCH(DMI_BIOS_VERSION,"1SET59WW") }, (void*)1},
  145. { set_max_cstate, "IBM ThinkPad R40e", {
  146. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  147. DMI_MATCH(DMI_BIOS_VERSION,"1SET60WW") }, (void*)1},
  148. { set_max_cstate, "IBM ThinkPad R40e", {
  149. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  150. DMI_MATCH(DMI_BIOS_VERSION,"1SET61WW") }, (void*)1},
  151. { set_max_cstate, "IBM ThinkPad R40e", {
  152. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  153. DMI_MATCH(DMI_BIOS_VERSION,"1SET62WW") }, (void*)1},
  154. { set_max_cstate, "IBM ThinkPad R40e", {
  155. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  156. DMI_MATCH(DMI_BIOS_VERSION,"1SET64WW") }, (void*)1},
  157. { set_max_cstate, "IBM ThinkPad R40e", {
  158. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  159. DMI_MATCH(DMI_BIOS_VERSION,"1SET65WW") }, (void*)1},
  160. { set_max_cstate, "IBM ThinkPad R40e", {
  161. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  162. DMI_MATCH(DMI_BIOS_VERSION,"1SET68WW") }, (void*)1},
  163. { set_max_cstate, "Medion 41700", {
  164. DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
  165. DMI_MATCH(DMI_BIOS_VERSION,"R01-A1J")}, (void *)1},
  166. { set_max_cstate, "Clevo 5600D", {
  167. DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
  168. DMI_MATCH(DMI_BIOS_VERSION,"SHE845M0.86C.0013.D.0302131307")},
  169. (void *)2},
  170. {},
  171. };
  172. static inline u32 ticks_elapsed(u32 t1, u32 t2)
  173. {
  174. if (t2 >= t1)
  175. return (t2 - t1);
  176. else if (!(acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER))
  177. return (((0x00FFFFFF - t1) + t2) & 0x00FFFFFF);
  178. else
  179. return ((0xFFFFFFFF - t1) + t2);
  180. }
  181. static inline u32 ticks_elapsed_in_us(u32 t1, u32 t2)
  182. {
  183. if (t2 >= t1)
  184. return PM_TIMER_TICKS_TO_US(t2 - t1);
  185. else if (!(acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER))
  186. return PM_TIMER_TICKS_TO_US(((0x00FFFFFF - t1) + t2) & 0x00FFFFFF);
  187. else
  188. return PM_TIMER_TICKS_TO_US((0xFFFFFFFF - t1) + t2);
  189. }
  190. /*
  191. * Callers should disable interrupts before the call and enable
  192. * interrupts after return.
  193. */
  194. static void acpi_safe_halt(void)
  195. {
  196. current_thread_info()->status &= ~TS_POLLING;
  197. /*
  198. * TS_POLLING-cleared state must be visible before we
  199. * test NEED_RESCHED:
  200. */
  201. smp_mb();
  202. if (!need_resched())
  203. safe_halt();
  204. current_thread_info()->status |= TS_POLLING;
  205. }
  206. #ifndef CONFIG_CPU_IDLE
  207. static void
  208. acpi_processor_power_activate(struct acpi_processor *pr,
  209. struct acpi_processor_cx *new)
  210. {
  211. struct acpi_processor_cx *old;
  212. if (!pr || !new)
  213. return;
  214. old = pr->power.state;
  215. if (old)
  216. old->promotion.count = 0;
  217. new->demotion.count = 0;
  218. /* Cleanup from old state. */
  219. if (old) {
  220. switch (old->type) {
  221. case ACPI_STATE_C3:
  222. /* Disable bus master reload */
  223. if (new->type != ACPI_STATE_C3 && pr->flags.bm_check)
  224. acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0);
  225. break;
  226. }
  227. }
  228. /* Prepare to use new state. */
  229. switch (new->type) {
  230. case ACPI_STATE_C3:
  231. /* Enable bus master reload */
  232. if (old->type != ACPI_STATE_C3 && pr->flags.bm_check)
  233. acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 1);
  234. break;
  235. }
  236. pr->power.state = new;
  237. return;
  238. }
  239. static atomic_t c3_cpu_count;
  240. /* Common C-state entry for C2, C3, .. */
  241. static void acpi_cstate_enter(struct acpi_processor_cx *cstate)
  242. {
  243. if (cstate->entry_method == ACPI_CSTATE_FFH) {
  244. /* Call into architectural FFH based C-state */
  245. acpi_processor_ffh_cstate_enter(cstate);
  246. } else {
  247. int unused;
  248. /* IO port based C-state */
  249. inb(cstate->address);
  250. /* Dummy wait op - must do something useless after P_LVL2 read
  251. because chipsets cannot guarantee that STPCLK# signal
  252. gets asserted in time to freeze execution properly. */
  253. unused = inl(acpi_gbl_FADT.xpm_timer_block.address);
  254. }
  255. }
  256. #endif /* !CONFIG_CPU_IDLE */
  257. #ifdef ARCH_APICTIMER_STOPS_ON_C3
  258. /*
  259. * Some BIOS implementations switch to C3 in the published C2 state.
  260. * This seems to be a common problem on AMD boxen, but other vendors
  261. * are affected too. We pick the most conservative approach: we assume
  262. * that the local APIC stops in both C2 and C3.
  263. */
  264. static void acpi_timer_check_state(int state, struct acpi_processor *pr,
  265. struct acpi_processor_cx *cx)
  266. {
  267. struct acpi_processor_power *pwr = &pr->power;
  268. u8 type = local_apic_timer_c2_ok ? ACPI_STATE_C3 : ACPI_STATE_C2;
  269. /*
  270. * Check, if one of the previous states already marked the lapic
  271. * unstable
  272. */
  273. if (pwr->timer_broadcast_on_state < state)
  274. return;
  275. if (cx->type >= type)
  276. pr->power.timer_broadcast_on_state = state;
  277. }
  278. static void acpi_propagate_timer_broadcast(struct acpi_processor *pr)
  279. {
  280. unsigned long reason;
  281. reason = pr->power.timer_broadcast_on_state < INT_MAX ?
  282. CLOCK_EVT_NOTIFY_BROADCAST_ON : CLOCK_EVT_NOTIFY_BROADCAST_OFF;
  283. clockevents_notify(reason, &pr->id);
  284. }
  285. /* Power(C) State timer broadcast control */
  286. static void acpi_state_timer_broadcast(struct acpi_processor *pr,
  287. struct acpi_processor_cx *cx,
  288. int broadcast)
  289. {
  290. int state = cx - pr->power.states;
  291. if (state >= pr->power.timer_broadcast_on_state) {
  292. unsigned long reason;
  293. reason = broadcast ? CLOCK_EVT_NOTIFY_BROADCAST_ENTER :
  294. CLOCK_EVT_NOTIFY_BROADCAST_EXIT;
  295. clockevents_notify(reason, &pr->id);
  296. }
  297. }
  298. #else
  299. static void acpi_timer_check_state(int state, struct acpi_processor *pr,
  300. struct acpi_processor_cx *cstate) { }
  301. static void acpi_propagate_timer_broadcast(struct acpi_processor *pr) { }
  302. static void acpi_state_timer_broadcast(struct acpi_processor *pr,
  303. struct acpi_processor_cx *cx,
  304. int broadcast)
  305. {
  306. }
  307. #endif
  308. /*
  309. * Suspend / resume control
  310. */
  311. static int acpi_idle_suspend;
  312. int acpi_processor_suspend(struct acpi_device * device, pm_message_t state)
  313. {
  314. acpi_idle_suspend = 1;
  315. return 0;
  316. }
  317. int acpi_processor_resume(struct acpi_device * device)
  318. {
  319. acpi_idle_suspend = 0;
  320. return 0;
  321. }
  322. #if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86_TSC)
  323. static int tsc_halts_in_c(int state)
  324. {
  325. switch (boot_cpu_data.x86_vendor) {
  326. case X86_VENDOR_AMD:
  327. /*
  328. * AMD Fam10h TSC will tick in all
  329. * C/P/S0/S1 states when this bit is set.
  330. */
  331. if (boot_cpu_has(X86_FEATURE_CONSTANT_TSC))
  332. return 0;
  333. /*FALL THROUGH*/
  334. case X86_VENDOR_INTEL:
  335. /* Several cases known where TSC halts in C2 too */
  336. default:
  337. return state > ACPI_STATE_C1;
  338. }
  339. }
  340. #endif
  341. #ifndef CONFIG_CPU_IDLE
  342. static void acpi_processor_idle(void)
  343. {
  344. struct acpi_processor *pr = NULL;
  345. struct acpi_processor_cx *cx = NULL;
  346. struct acpi_processor_cx *next_state = NULL;
  347. int sleep_ticks = 0;
  348. u32 t1, t2 = 0;
  349. /*
  350. * Interrupts must be disabled during bus mastering calculations and
  351. * for C2/C3 transitions.
  352. */
  353. local_irq_disable();
  354. pr = processors[smp_processor_id()];
  355. if (!pr) {
  356. local_irq_enable();
  357. return;
  358. }
  359. /*
  360. * Check whether we truly need to go idle, or should
  361. * reschedule:
  362. */
  363. if (unlikely(need_resched())) {
  364. local_irq_enable();
  365. return;
  366. }
  367. cx = pr->power.state;
  368. if (!cx || acpi_idle_suspend) {
  369. if (pm_idle_save)
  370. pm_idle_save();
  371. else
  372. acpi_safe_halt();
  373. local_irq_enable();
  374. return;
  375. }
  376. /*
  377. * Check BM Activity
  378. * -----------------
  379. * Check for bus mastering activity (if required), record, and check
  380. * for demotion.
  381. */
  382. if (pr->flags.bm_check) {
  383. u32 bm_status = 0;
  384. unsigned long diff = jiffies - pr->power.bm_check_timestamp;
  385. if (diff > 31)
  386. diff = 31;
  387. pr->power.bm_activity <<= diff;
  388. acpi_get_register(ACPI_BITREG_BUS_MASTER_STATUS, &bm_status);
  389. if (bm_status) {
  390. pr->power.bm_activity |= 0x1;
  391. acpi_set_register(ACPI_BITREG_BUS_MASTER_STATUS, 1);
  392. }
  393. /*
  394. * PIIX4 Erratum #18: Note that BM_STS doesn't always reflect
  395. * the true state of bus mastering activity; forcing us to
  396. * manually check the BMIDEA bit of each IDE channel.
  397. */
  398. else if (errata.piix4.bmisx) {
  399. if ((inb_p(errata.piix4.bmisx + 0x02) & 0x01)
  400. || (inb_p(errata.piix4.bmisx + 0x0A) & 0x01))
  401. pr->power.bm_activity |= 0x1;
  402. }
  403. pr->power.bm_check_timestamp = jiffies;
  404. /*
  405. * If bus mastering is or was active this jiffy, demote
  406. * to avoid a faulty transition. Note that the processor
  407. * won't enter a low-power state during this call (to this
  408. * function) but should upon the next.
  409. *
  410. * TBD: A better policy might be to fallback to the demotion
  411. * state (use it for this quantum only) istead of
  412. * demoting -- and rely on duration as our sole demotion
  413. * qualification. This may, however, introduce DMA
  414. * issues (e.g. floppy DMA transfer overrun/underrun).
  415. */
  416. if ((pr->power.bm_activity & 0x1) &&
  417. cx->demotion.threshold.bm) {
  418. local_irq_enable();
  419. next_state = cx->demotion.state;
  420. goto end;
  421. }
  422. }
  423. #ifdef CONFIG_HOTPLUG_CPU
  424. /*
  425. * Check for P_LVL2_UP flag before entering C2 and above on
  426. * an SMP system. We do it here instead of doing it at _CST/P_LVL
  427. * detection phase, to work cleanly with logical CPU hotplug.
  428. */
  429. if ((cx->type != ACPI_STATE_C1) && (num_online_cpus() > 1) &&
  430. !pr->flags.has_cst && !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
  431. cx = &pr->power.states[ACPI_STATE_C1];
  432. #endif
  433. /*
  434. * Sleep:
  435. * ------
  436. * Invoke the current Cx state to put the processor to sleep.
  437. */
  438. if (cx->type == ACPI_STATE_C2 || cx->type == ACPI_STATE_C3) {
  439. current_thread_info()->status &= ~TS_POLLING;
  440. /*
  441. * TS_POLLING-cleared state must be visible before we
  442. * test NEED_RESCHED:
  443. */
  444. smp_mb();
  445. if (need_resched()) {
  446. current_thread_info()->status |= TS_POLLING;
  447. local_irq_enable();
  448. return;
  449. }
  450. }
  451. switch (cx->type) {
  452. case ACPI_STATE_C1:
  453. /*
  454. * Invoke C1.
  455. * Use the appropriate idle routine, the one that would
  456. * be used without acpi C-states.
  457. */
  458. if (pm_idle_save)
  459. pm_idle_save();
  460. else
  461. acpi_safe_halt();
  462. /*
  463. * TBD: Can't get time duration while in C1, as resumes
  464. * go to an ISR rather than here. Need to instrument
  465. * base interrupt handler.
  466. *
  467. * Note: the TSC better not stop in C1, sched_clock() will
  468. * skew otherwise.
  469. */
  470. sleep_ticks = 0xFFFFFFFF;
  471. local_irq_enable();
  472. break;
  473. case ACPI_STATE_C2:
  474. /* Get start time (ticks) */
  475. t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
  476. /* Tell the scheduler that we are going deep-idle: */
  477. sched_clock_idle_sleep_event();
  478. /* Invoke C2 */
  479. acpi_state_timer_broadcast(pr, cx, 1);
  480. acpi_cstate_enter(cx);
  481. /* Get end time (ticks) */
  482. t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
  483. #if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86_TSC)
  484. /* TSC halts in C2, so notify users */
  485. if (tsc_halts_in_c(ACPI_STATE_C2))
  486. mark_tsc_unstable("possible TSC halt in C2");
  487. #endif
  488. /* Compute time (ticks) that we were actually asleep */
  489. sleep_ticks = ticks_elapsed(t1, t2);
  490. /* Tell the scheduler how much we idled: */
  491. sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS);
  492. /* Re-enable interrupts */
  493. local_irq_enable();
  494. /* Do not account our idle-switching overhead: */
  495. sleep_ticks -= cx->latency_ticks + C2_OVERHEAD;
  496. current_thread_info()->status |= TS_POLLING;
  497. acpi_state_timer_broadcast(pr, cx, 0);
  498. break;
  499. case ACPI_STATE_C3:
  500. acpi_unlazy_tlb(smp_processor_id());
  501. /*
  502. * Must be done before busmaster disable as we might
  503. * need to access HPET !
  504. */
  505. acpi_state_timer_broadcast(pr, cx, 1);
  506. /*
  507. * disable bus master
  508. * bm_check implies we need ARB_DIS
  509. * !bm_check implies we need cache flush
  510. * bm_control implies whether we can do ARB_DIS
  511. *
  512. * That leaves a case where bm_check is set and bm_control is
  513. * not set. In that case we cannot do much, we enter C3
  514. * without doing anything.
  515. */
  516. if (pr->flags.bm_check && pr->flags.bm_control) {
  517. if (atomic_inc_return(&c3_cpu_count) ==
  518. num_online_cpus()) {
  519. /*
  520. * All CPUs are trying to go to C3
  521. * Disable bus master arbitration
  522. */
  523. acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1);
  524. }
  525. } else if (!pr->flags.bm_check) {
  526. /* SMP with no shared cache... Invalidate cache */
  527. ACPI_FLUSH_CPU_CACHE();
  528. }
  529. /* Get start time (ticks) */
  530. t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
  531. /* Invoke C3 */
  532. /* Tell the scheduler that we are going deep-idle: */
  533. sched_clock_idle_sleep_event();
  534. acpi_cstate_enter(cx);
  535. /* Get end time (ticks) */
  536. t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
  537. if (pr->flags.bm_check && pr->flags.bm_control) {
  538. /* Enable bus master arbitration */
  539. atomic_dec(&c3_cpu_count);
  540. acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0);
  541. }
  542. #if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86_TSC)
  543. /* TSC halts in C3, so notify users */
  544. if (tsc_halts_in_c(ACPI_STATE_C3))
  545. mark_tsc_unstable("TSC halts in C3");
  546. #endif
  547. /* Compute time (ticks) that we were actually asleep */
  548. sleep_ticks = ticks_elapsed(t1, t2);
  549. /* Tell the scheduler how much we idled: */
  550. sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS);
  551. /* Re-enable interrupts */
  552. local_irq_enable();
  553. /* Do not account our idle-switching overhead: */
  554. sleep_ticks -= cx->latency_ticks + C3_OVERHEAD;
  555. current_thread_info()->status |= TS_POLLING;
  556. acpi_state_timer_broadcast(pr, cx, 0);
  557. break;
  558. default:
  559. local_irq_enable();
  560. return;
  561. }
  562. cx->usage++;
  563. if ((cx->type != ACPI_STATE_C1) && (sleep_ticks > 0))
  564. cx->time += sleep_ticks;
  565. next_state = pr->power.state;
  566. #ifdef CONFIG_HOTPLUG_CPU
  567. /* Don't do promotion/demotion */
  568. if ((cx->type == ACPI_STATE_C1) && (num_online_cpus() > 1) &&
  569. !pr->flags.has_cst && !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED)) {
  570. next_state = cx;
  571. goto end;
  572. }
  573. #endif
  574. /*
  575. * Promotion?
  576. * ----------
  577. * Track the number of longs (time asleep is greater than threshold)
  578. * and promote when the count threshold is reached. Note that bus
  579. * mastering activity may prevent promotions.
  580. * Do not promote above max_cstate.
  581. */
  582. if (cx->promotion.state &&
  583. ((cx->promotion.state - pr->power.states) <= max_cstate)) {
  584. if (sleep_ticks > cx->promotion.threshold.ticks &&
  585. cx->promotion.state->latency <=
  586. pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY)) {
  587. cx->promotion.count++;
  588. cx->demotion.count = 0;
  589. if (cx->promotion.count >=
  590. cx->promotion.threshold.count) {
  591. if (pr->flags.bm_check) {
  592. if (!
  593. (pr->power.bm_activity & cx->
  594. promotion.threshold.bm)) {
  595. next_state =
  596. cx->promotion.state;
  597. goto end;
  598. }
  599. } else {
  600. next_state = cx->promotion.state;
  601. goto end;
  602. }
  603. }
  604. }
  605. }
  606. /*
  607. * Demotion?
  608. * ---------
  609. * Track the number of shorts (time asleep is less than time threshold)
  610. * and demote when the usage threshold is reached.
  611. */
  612. if (cx->demotion.state) {
  613. if (sleep_ticks < cx->demotion.threshold.ticks) {
  614. cx->demotion.count++;
  615. cx->promotion.count = 0;
  616. if (cx->demotion.count >= cx->demotion.threshold.count) {
  617. next_state = cx->demotion.state;
  618. goto end;
  619. }
  620. }
  621. }
  622. end:
  623. /*
  624. * Demote if current state exceeds max_cstate
  625. * or if the latency of the current state is unacceptable
  626. */
  627. if ((pr->power.state - pr->power.states) > max_cstate ||
  628. pr->power.state->latency >
  629. pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY)) {
  630. if (cx->demotion.state)
  631. next_state = cx->demotion.state;
  632. }
  633. /*
  634. * New Cx State?
  635. * -------------
  636. * If we're going to start using a new Cx state we must clean up
  637. * from the previous and prepare to use the new.
  638. */
  639. if (next_state != pr->power.state)
  640. acpi_processor_power_activate(pr, next_state);
  641. }
  642. static int acpi_processor_set_power_policy(struct acpi_processor *pr)
  643. {
  644. unsigned int i;
  645. unsigned int state_is_set = 0;
  646. struct acpi_processor_cx *lower = NULL;
  647. struct acpi_processor_cx *higher = NULL;
  648. struct acpi_processor_cx *cx;
  649. if (!pr)
  650. return -EINVAL;
  651. /*
  652. * This function sets the default Cx state policy (OS idle handler).
  653. * Our scheme is to promote quickly to C2 but more conservatively
  654. * to C3. We're favoring C2 for its characteristics of low latency
  655. * (quick response), good power savings, and ability to allow bus
  656. * mastering activity. Note that the Cx state policy is completely
  657. * customizable and can be altered dynamically.
  658. */
  659. /* startup state */
  660. for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
  661. cx = &pr->power.states[i];
  662. if (!cx->valid)
  663. continue;
  664. if (!state_is_set)
  665. pr->power.state = cx;
  666. state_is_set++;
  667. break;
  668. }
  669. if (!state_is_set)
  670. return -ENODEV;
  671. /* demotion */
  672. for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
  673. cx = &pr->power.states[i];
  674. if (!cx->valid)
  675. continue;
  676. if (lower) {
  677. cx->demotion.state = lower;
  678. cx->demotion.threshold.ticks = cx->latency_ticks;
  679. cx->demotion.threshold.count = 1;
  680. if (cx->type == ACPI_STATE_C3)
  681. cx->demotion.threshold.bm = bm_history;
  682. }
  683. lower = cx;
  684. }
  685. /* promotion */
  686. for (i = (ACPI_PROCESSOR_MAX_POWER - 1); i > 0; i--) {
  687. cx = &pr->power.states[i];
  688. if (!cx->valid)
  689. continue;
  690. if (higher) {
  691. cx->promotion.state = higher;
  692. cx->promotion.threshold.ticks = cx->latency_ticks;
  693. if (cx->type >= ACPI_STATE_C2)
  694. cx->promotion.threshold.count = 4;
  695. else
  696. cx->promotion.threshold.count = 10;
  697. if (higher->type == ACPI_STATE_C3)
  698. cx->promotion.threshold.bm = bm_history;
  699. }
  700. higher = cx;
  701. }
  702. return 0;
  703. }
  704. #endif /* !CONFIG_CPU_IDLE */
  705. static int acpi_processor_get_power_info_fadt(struct acpi_processor *pr)
  706. {
  707. if (!pr)
  708. return -EINVAL;
  709. if (!pr->pblk)
  710. return -ENODEV;
  711. /* if info is obtained from pblk/fadt, type equals state */
  712. pr->power.states[ACPI_STATE_C2].type = ACPI_STATE_C2;
  713. pr->power.states[ACPI_STATE_C3].type = ACPI_STATE_C3;
  714. #ifndef CONFIG_HOTPLUG_CPU
  715. /*
  716. * Check for P_LVL2_UP flag before entering C2 and above on
  717. * an SMP system.
  718. */
  719. if ((num_online_cpus() > 1) &&
  720. !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
  721. return -ENODEV;
  722. #endif
  723. /* determine C2 and C3 address from pblk */
  724. pr->power.states[ACPI_STATE_C2].address = pr->pblk + 4;
  725. pr->power.states[ACPI_STATE_C3].address = pr->pblk + 5;
  726. /* determine latencies from FADT */
  727. pr->power.states[ACPI_STATE_C2].latency = acpi_gbl_FADT.C2latency;
  728. pr->power.states[ACPI_STATE_C3].latency = acpi_gbl_FADT.C3latency;
  729. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  730. "lvl2[0x%08x] lvl3[0x%08x]\n",
  731. pr->power.states[ACPI_STATE_C2].address,
  732. pr->power.states[ACPI_STATE_C3].address));
  733. return 0;
  734. }
  735. static int acpi_processor_get_power_info_default(struct acpi_processor *pr)
  736. {
  737. if (!pr->power.states[ACPI_STATE_C1].valid) {
  738. /* set the first C-State to C1 */
  739. /* all processors need to support C1 */
  740. pr->power.states[ACPI_STATE_C1].type = ACPI_STATE_C1;
  741. pr->power.states[ACPI_STATE_C1].valid = 1;
  742. }
  743. /* the C0 state only exists as a filler in our array */
  744. pr->power.states[ACPI_STATE_C0].valid = 1;
  745. return 0;
  746. }
  747. static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
  748. {
  749. acpi_status status = 0;
  750. acpi_integer count;
  751. int current_count;
  752. int i;
  753. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  754. union acpi_object *cst;
  755. if (nocst)
  756. return -ENODEV;
  757. current_count = 0;
  758. status = acpi_evaluate_object(pr->handle, "_CST", NULL, &buffer);
  759. if (ACPI_FAILURE(status)) {
  760. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No _CST, giving up\n"));
  761. return -ENODEV;
  762. }
  763. cst = buffer.pointer;
  764. /* There must be at least 2 elements */
  765. if (!cst || (cst->type != ACPI_TYPE_PACKAGE) || cst->package.count < 2) {
  766. printk(KERN_ERR PREFIX "not enough elements in _CST\n");
  767. status = -EFAULT;
  768. goto end;
  769. }
  770. count = cst->package.elements[0].integer.value;
  771. /* Validate number of power states. */
  772. if (count < 1 || count != cst->package.count - 1) {
  773. printk(KERN_ERR PREFIX "count given by _CST is not valid\n");
  774. status = -EFAULT;
  775. goto end;
  776. }
  777. /* Tell driver that at least _CST is supported. */
  778. pr->flags.has_cst = 1;
  779. for (i = 1; i <= count; i++) {
  780. union acpi_object *element;
  781. union acpi_object *obj;
  782. struct acpi_power_register *reg;
  783. struct acpi_processor_cx cx;
  784. memset(&cx, 0, sizeof(cx));
  785. element = &(cst->package.elements[i]);
  786. if (element->type != ACPI_TYPE_PACKAGE)
  787. continue;
  788. if (element->package.count != 4)
  789. continue;
  790. obj = &(element->package.elements[0]);
  791. if (obj->type != ACPI_TYPE_BUFFER)
  792. continue;
  793. reg = (struct acpi_power_register *)obj->buffer.pointer;
  794. if (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO &&
  795. (reg->space_id != ACPI_ADR_SPACE_FIXED_HARDWARE))
  796. continue;
  797. /* There should be an easy way to extract an integer... */
  798. obj = &(element->package.elements[1]);
  799. if (obj->type != ACPI_TYPE_INTEGER)
  800. continue;
  801. cx.type = obj->integer.value;
  802. /*
  803. * Some buggy BIOSes won't list C1 in _CST -
  804. * Let acpi_processor_get_power_info_default() handle them later
  805. */
  806. if (i == 1 && cx.type != ACPI_STATE_C1)
  807. current_count++;
  808. cx.address = reg->address;
  809. cx.index = current_count + 1;
  810. cx.entry_method = ACPI_CSTATE_SYSTEMIO;
  811. if (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) {
  812. if (acpi_processor_ffh_cstate_probe
  813. (pr->id, &cx, reg) == 0) {
  814. cx.entry_method = ACPI_CSTATE_FFH;
  815. } else if (cx.type == ACPI_STATE_C1) {
  816. /*
  817. * C1 is a special case where FIXED_HARDWARE
  818. * can be handled in non-MWAIT way as well.
  819. * In that case, save this _CST entry info.
  820. * Otherwise, ignore this info and continue.
  821. */
  822. cx.entry_method = ACPI_CSTATE_HALT;
  823. snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI HLT");
  824. } else {
  825. continue;
  826. }
  827. } else {
  828. snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI IOPORT 0x%x",
  829. cx.address);
  830. }
  831. obj = &(element->package.elements[2]);
  832. if (obj->type != ACPI_TYPE_INTEGER)
  833. continue;
  834. cx.latency = obj->integer.value;
  835. obj = &(element->package.elements[3]);
  836. if (obj->type != ACPI_TYPE_INTEGER)
  837. continue;
  838. cx.power = obj->integer.value;
  839. current_count++;
  840. memcpy(&(pr->power.states[current_count]), &cx, sizeof(cx));
  841. /*
  842. * We support total ACPI_PROCESSOR_MAX_POWER - 1
  843. * (From 1 through ACPI_PROCESSOR_MAX_POWER - 1)
  844. */
  845. if (current_count >= (ACPI_PROCESSOR_MAX_POWER - 1)) {
  846. printk(KERN_WARNING
  847. "Limiting number of power states to max (%d)\n",
  848. ACPI_PROCESSOR_MAX_POWER);
  849. printk(KERN_WARNING
  850. "Please increase ACPI_PROCESSOR_MAX_POWER if needed.\n");
  851. break;
  852. }
  853. }
  854. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d power states\n",
  855. current_count));
  856. /* Validate number of power states discovered */
  857. if (current_count < 2)
  858. status = -EFAULT;
  859. end:
  860. kfree(buffer.pointer);
  861. return status;
  862. }
  863. static void acpi_processor_power_verify_c2(struct acpi_processor_cx *cx)
  864. {
  865. if (!cx->address)
  866. return;
  867. /*
  868. * C2 latency must be less than or equal to 100
  869. * microseconds.
  870. */
  871. else if (cx->latency > ACPI_PROCESSOR_MAX_C2_LATENCY) {
  872. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  873. "latency too large [%d]\n", cx->latency));
  874. return;
  875. }
  876. /*
  877. * Otherwise we've met all of our C2 requirements.
  878. * Normalize the C2 latency to expidite policy
  879. */
  880. cx->valid = 1;
  881. #ifndef CONFIG_CPU_IDLE
  882. cx->latency_ticks = US_TO_PM_TIMER_TICKS(cx->latency);
  883. #else
  884. cx->latency_ticks = cx->latency;
  885. #endif
  886. return;
  887. }
  888. static void acpi_processor_power_verify_c3(struct acpi_processor *pr,
  889. struct acpi_processor_cx *cx)
  890. {
  891. static int bm_check_flag;
  892. if (!cx->address)
  893. return;
  894. /*
  895. * C3 latency must be less than or equal to 1000
  896. * microseconds.
  897. */
  898. else if (cx->latency > ACPI_PROCESSOR_MAX_C3_LATENCY) {
  899. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  900. "latency too large [%d]\n", cx->latency));
  901. return;
  902. }
  903. /*
  904. * PIIX4 Erratum #18: We don't support C3 when Type-F (fast)
  905. * DMA transfers are used by any ISA device to avoid livelock.
  906. * Note that we could disable Type-F DMA (as recommended by
  907. * the erratum), but this is known to disrupt certain ISA
  908. * devices thus we take the conservative approach.
  909. */
  910. else if (errata.piix4.fdma) {
  911. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  912. "C3 not supported on PIIX4 with Type-F DMA\n"));
  913. return;
  914. }
  915. /* All the logic here assumes flags.bm_check is same across all CPUs */
  916. if (!bm_check_flag) {
  917. /* Determine whether bm_check is needed based on CPU */
  918. acpi_processor_power_init_bm_check(&(pr->flags), pr->id);
  919. bm_check_flag = pr->flags.bm_check;
  920. } else {
  921. pr->flags.bm_check = bm_check_flag;
  922. }
  923. if (pr->flags.bm_check) {
  924. if (!pr->flags.bm_control) {
  925. if (pr->flags.has_cst != 1) {
  926. /* bus mastering control is necessary */
  927. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  928. "C3 support requires BM control\n"));
  929. return;
  930. } else {
  931. /* Here we enter C3 without bus mastering */
  932. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  933. "C3 support without BM control\n"));
  934. }
  935. }
  936. } else {
  937. /*
  938. * WBINVD should be set in fadt, for C3 state to be
  939. * supported on when bm_check is not required.
  940. */
  941. if (!(acpi_gbl_FADT.flags & ACPI_FADT_WBINVD)) {
  942. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  943. "Cache invalidation should work properly"
  944. " for C3 to be enabled on SMP systems\n"));
  945. return;
  946. }
  947. acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0);
  948. }
  949. /*
  950. * Otherwise we've met all of our C3 requirements.
  951. * Normalize the C3 latency to expidite policy. Enable
  952. * checking of bus mastering status (bm_check) so we can
  953. * use this in our C3 policy
  954. */
  955. cx->valid = 1;
  956. #ifndef CONFIG_CPU_IDLE
  957. cx->latency_ticks = US_TO_PM_TIMER_TICKS(cx->latency);
  958. #else
  959. cx->latency_ticks = cx->latency;
  960. #endif
  961. return;
  962. }
  963. static int acpi_processor_power_verify(struct acpi_processor *pr)
  964. {
  965. unsigned int i;
  966. unsigned int working = 0;
  967. pr->power.timer_broadcast_on_state = INT_MAX;
  968. for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
  969. struct acpi_processor_cx *cx = &pr->power.states[i];
  970. switch (cx->type) {
  971. case ACPI_STATE_C1:
  972. cx->valid = 1;
  973. break;
  974. case ACPI_STATE_C2:
  975. acpi_processor_power_verify_c2(cx);
  976. if (cx->valid)
  977. acpi_timer_check_state(i, pr, cx);
  978. break;
  979. case ACPI_STATE_C3:
  980. acpi_processor_power_verify_c3(pr, cx);
  981. if (cx->valid)
  982. acpi_timer_check_state(i, pr, cx);
  983. break;
  984. }
  985. if (cx->valid)
  986. working++;
  987. }
  988. acpi_propagate_timer_broadcast(pr);
  989. return (working);
  990. }
  991. static int acpi_processor_get_power_info(struct acpi_processor *pr)
  992. {
  993. unsigned int i;
  994. int result;
  995. /* NOTE: the idle thread may not be running while calling
  996. * this function */
  997. /* Zero initialize all the C-states info. */
  998. memset(pr->power.states, 0, sizeof(pr->power.states));
  999. result = acpi_processor_get_power_info_cst(pr);
  1000. if (result == -ENODEV)
  1001. result = acpi_processor_get_power_info_fadt(pr);
  1002. if (result)
  1003. return result;
  1004. acpi_processor_get_power_info_default(pr);
  1005. pr->power.count = acpi_processor_power_verify(pr);
  1006. #ifndef CONFIG_CPU_IDLE
  1007. /*
  1008. * Set Default Policy
  1009. * ------------------
  1010. * Now that we know which states are supported, set the default
  1011. * policy. Note that this policy can be changed dynamically
  1012. * (e.g. encourage deeper sleeps to conserve battery life when
  1013. * not on AC).
  1014. */
  1015. result = acpi_processor_set_power_policy(pr);
  1016. if (result)
  1017. return result;
  1018. #endif
  1019. /*
  1020. * if one state of type C2 or C3 is available, mark this
  1021. * CPU as being "idle manageable"
  1022. */
  1023. for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
  1024. if (pr->power.states[i].valid) {
  1025. pr->power.count = i;
  1026. if (pr->power.states[i].type >= ACPI_STATE_C2)
  1027. pr->flags.power = 1;
  1028. }
  1029. }
  1030. return 0;
  1031. }
  1032. static int acpi_processor_power_seq_show(struct seq_file *seq, void *offset)
  1033. {
  1034. struct acpi_processor *pr = seq->private;
  1035. unsigned int i;
  1036. if (!pr)
  1037. goto end;
  1038. seq_printf(seq, "active state: C%zd\n"
  1039. "max_cstate: C%d\n"
  1040. "bus master activity: %08x\n"
  1041. "maximum allowed latency: %d usec\n",
  1042. pr->power.state ? pr->power.state - pr->power.states : 0,
  1043. max_cstate, (unsigned)pr->power.bm_activity,
  1044. pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY));
  1045. seq_puts(seq, "states:\n");
  1046. for (i = 1; i <= pr->power.count; i++) {
  1047. seq_printf(seq, " %cC%d: ",
  1048. (&pr->power.states[i] ==
  1049. pr->power.state ? '*' : ' '), i);
  1050. if (!pr->power.states[i].valid) {
  1051. seq_puts(seq, "<not supported>\n");
  1052. continue;
  1053. }
  1054. switch (pr->power.states[i].type) {
  1055. case ACPI_STATE_C1:
  1056. seq_printf(seq, "type[C1] ");
  1057. break;
  1058. case ACPI_STATE_C2:
  1059. seq_printf(seq, "type[C2] ");
  1060. break;
  1061. case ACPI_STATE_C3:
  1062. seq_printf(seq, "type[C3] ");
  1063. break;
  1064. default:
  1065. seq_printf(seq, "type[--] ");
  1066. break;
  1067. }
  1068. if (pr->power.states[i].promotion.state)
  1069. seq_printf(seq, "promotion[C%zd] ",
  1070. (pr->power.states[i].promotion.state -
  1071. pr->power.states));
  1072. else
  1073. seq_puts(seq, "promotion[--] ");
  1074. if (pr->power.states[i].demotion.state)
  1075. seq_printf(seq, "demotion[C%zd] ",
  1076. (pr->power.states[i].demotion.state -
  1077. pr->power.states));
  1078. else
  1079. seq_puts(seq, "demotion[--] ");
  1080. seq_printf(seq, "latency[%03d] usage[%08d] duration[%020llu]\n",
  1081. pr->power.states[i].latency,
  1082. pr->power.states[i].usage,
  1083. (unsigned long long)pr->power.states[i].time);
  1084. }
  1085. end:
  1086. return 0;
  1087. }
  1088. static int acpi_processor_power_open_fs(struct inode *inode, struct file *file)
  1089. {
  1090. return single_open(file, acpi_processor_power_seq_show,
  1091. PDE(inode)->data);
  1092. }
  1093. static const struct file_operations acpi_processor_power_fops = {
  1094. .open = acpi_processor_power_open_fs,
  1095. .read = seq_read,
  1096. .llseek = seq_lseek,
  1097. .release = single_release,
  1098. };
  1099. #ifndef CONFIG_CPU_IDLE
  1100. int acpi_processor_cst_has_changed(struct acpi_processor *pr)
  1101. {
  1102. int result = 0;
  1103. if (!pr)
  1104. return -EINVAL;
  1105. if (nocst) {
  1106. return -ENODEV;
  1107. }
  1108. if (!pr->flags.power_setup_done)
  1109. return -ENODEV;
  1110. /* Fall back to the default idle loop */
  1111. pm_idle = pm_idle_save;
  1112. synchronize_sched(); /* Relies on interrupts forcing exit from idle. */
  1113. pr->flags.power = 0;
  1114. result = acpi_processor_get_power_info(pr);
  1115. if ((pr->flags.power == 1) && (pr->flags.power_setup_done))
  1116. pm_idle = acpi_processor_idle;
  1117. return result;
  1118. }
  1119. #ifdef CONFIG_SMP
  1120. static void smp_callback(void *v)
  1121. {
  1122. /* we already woke the CPU up, nothing more to do */
  1123. }
  1124. /*
  1125. * This function gets called when a part of the kernel has a new latency
  1126. * requirement. This means we need to get all processors out of their C-state,
  1127. * and then recalculate a new suitable C-state. Just do a cross-cpu IPI; that
  1128. * wakes them all right up.
  1129. */
  1130. static int acpi_processor_latency_notify(struct notifier_block *b,
  1131. unsigned long l, void *v)
  1132. {
  1133. smp_call_function(smp_callback, NULL, 0, 1);
  1134. return NOTIFY_OK;
  1135. }
  1136. static struct notifier_block acpi_processor_latency_notifier = {
  1137. .notifier_call = acpi_processor_latency_notify,
  1138. };
  1139. #endif
  1140. #else /* CONFIG_CPU_IDLE */
  1141. /**
  1142. * acpi_idle_bm_check - checks if bus master activity was detected
  1143. */
  1144. static int acpi_idle_bm_check(void)
  1145. {
  1146. u32 bm_status = 0;
  1147. acpi_get_register(ACPI_BITREG_BUS_MASTER_STATUS, &bm_status);
  1148. if (bm_status)
  1149. acpi_set_register(ACPI_BITREG_BUS_MASTER_STATUS, 1);
  1150. /*
  1151. * PIIX4 Erratum #18: Note that BM_STS doesn't always reflect
  1152. * the true state of bus mastering activity; forcing us to
  1153. * manually check the BMIDEA bit of each IDE channel.
  1154. */
  1155. else if (errata.piix4.bmisx) {
  1156. if ((inb_p(errata.piix4.bmisx + 0x02) & 0x01)
  1157. || (inb_p(errata.piix4.bmisx + 0x0A) & 0x01))
  1158. bm_status = 1;
  1159. }
  1160. return bm_status;
  1161. }
  1162. /**
  1163. * acpi_idle_update_bm_rld - updates the BM_RLD bit depending on target state
  1164. * @pr: the processor
  1165. * @target: the new target state
  1166. */
  1167. static inline void acpi_idle_update_bm_rld(struct acpi_processor *pr,
  1168. struct acpi_processor_cx *target)
  1169. {
  1170. if (pr->flags.bm_rld_set && target->type != ACPI_STATE_C3) {
  1171. acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0);
  1172. pr->flags.bm_rld_set = 0;
  1173. }
  1174. if (!pr->flags.bm_rld_set && target->type == ACPI_STATE_C3) {
  1175. acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 1);
  1176. pr->flags.bm_rld_set = 1;
  1177. }
  1178. }
  1179. /**
  1180. * acpi_idle_do_entry - a helper function that does C2 and C3 type entry
  1181. * @cx: cstate data
  1182. *
  1183. * Caller disables interrupt before call and enables interrupt after return.
  1184. */
  1185. static inline void acpi_idle_do_entry(struct acpi_processor_cx *cx)
  1186. {
  1187. if (cx->entry_method == ACPI_CSTATE_FFH) {
  1188. /* Call into architectural FFH based C-state */
  1189. acpi_processor_ffh_cstate_enter(cx);
  1190. } else if (cx->entry_method == ACPI_CSTATE_HALT) {
  1191. acpi_safe_halt();
  1192. } else {
  1193. int unused;
  1194. /* IO port based C-state */
  1195. inb(cx->address);
  1196. /* Dummy wait op - must do something useless after P_LVL2 read
  1197. because chipsets cannot guarantee that STPCLK# signal
  1198. gets asserted in time to freeze execution properly. */
  1199. unused = inl(acpi_gbl_FADT.xpm_timer_block.address);
  1200. }
  1201. }
  1202. /**
  1203. * acpi_idle_enter_c1 - enters an ACPI C1 state-type
  1204. * @dev: the target CPU
  1205. * @state: the state data
  1206. *
  1207. * This is equivalent to the HALT instruction.
  1208. */
  1209. static int acpi_idle_enter_c1(struct cpuidle_device *dev,
  1210. struct cpuidle_state *state)
  1211. {
  1212. u32 t1, t2;
  1213. struct acpi_processor *pr;
  1214. struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
  1215. pr = processors[smp_processor_id()];
  1216. if (unlikely(!pr))
  1217. return 0;
  1218. local_irq_disable();
  1219. /* Do not access any ACPI IO ports in suspend path */
  1220. if (acpi_idle_suspend) {
  1221. acpi_safe_halt();
  1222. local_irq_enable();
  1223. return 0;
  1224. }
  1225. if (pr->flags.bm_check)
  1226. acpi_idle_update_bm_rld(pr, cx);
  1227. t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
  1228. acpi_idle_do_entry(cx);
  1229. t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
  1230. local_irq_enable();
  1231. cx->usage++;
  1232. return ticks_elapsed_in_us(t1, t2);
  1233. }
  1234. /**
  1235. * acpi_idle_enter_simple - enters an ACPI state without BM handling
  1236. * @dev: the target CPU
  1237. * @state: the state data
  1238. */
  1239. static int acpi_idle_enter_simple(struct cpuidle_device *dev,
  1240. struct cpuidle_state *state)
  1241. {
  1242. struct acpi_processor *pr;
  1243. struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
  1244. u32 t1, t2;
  1245. int sleep_ticks = 0;
  1246. pr = processors[smp_processor_id()];
  1247. if (unlikely(!pr))
  1248. return 0;
  1249. if (acpi_idle_suspend)
  1250. return(acpi_idle_enter_c1(dev, state));
  1251. local_irq_disable();
  1252. current_thread_info()->status &= ~TS_POLLING;
  1253. /*
  1254. * TS_POLLING-cleared state must be visible before we test
  1255. * NEED_RESCHED:
  1256. */
  1257. smp_mb();
  1258. if (unlikely(need_resched())) {
  1259. current_thread_info()->status |= TS_POLLING;
  1260. local_irq_enable();
  1261. return 0;
  1262. }
  1263. acpi_unlazy_tlb(smp_processor_id());
  1264. /*
  1265. * Must be done before busmaster disable as we might need to
  1266. * access HPET !
  1267. */
  1268. acpi_state_timer_broadcast(pr, cx, 1);
  1269. if (pr->flags.bm_check)
  1270. acpi_idle_update_bm_rld(pr, cx);
  1271. if (cx->type == ACPI_STATE_C3)
  1272. ACPI_FLUSH_CPU_CACHE();
  1273. t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
  1274. /* Tell the scheduler that we are going deep-idle: */
  1275. sched_clock_idle_sleep_event();
  1276. acpi_idle_do_entry(cx);
  1277. t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
  1278. #if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86_TSC)
  1279. /* TSC could halt in idle, so notify users */
  1280. if (tsc_halts_in_c(cx->type))
  1281. mark_tsc_unstable("TSC halts in idle");;
  1282. #endif
  1283. sleep_ticks = ticks_elapsed(t1, t2);
  1284. /* Tell the scheduler how much we idled: */
  1285. sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS);
  1286. local_irq_enable();
  1287. current_thread_info()->status |= TS_POLLING;
  1288. cx->usage++;
  1289. acpi_state_timer_broadcast(pr, cx, 0);
  1290. cx->time += sleep_ticks;
  1291. return ticks_elapsed_in_us(t1, t2);
  1292. }
  1293. static int c3_cpu_count;
  1294. static DEFINE_SPINLOCK(c3_lock);
  1295. /**
  1296. * acpi_idle_enter_bm - enters C3 with proper BM handling
  1297. * @dev: the target CPU
  1298. * @state: the state data
  1299. *
  1300. * If BM is detected, the deepest non-C3 idle state is entered instead.
  1301. */
  1302. static int acpi_idle_enter_bm(struct cpuidle_device *dev,
  1303. struct cpuidle_state *state)
  1304. {
  1305. struct acpi_processor *pr;
  1306. struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
  1307. u32 t1, t2;
  1308. int sleep_ticks = 0;
  1309. pr = processors[smp_processor_id()];
  1310. if (unlikely(!pr))
  1311. return 0;
  1312. if (acpi_idle_suspend)
  1313. return(acpi_idle_enter_c1(dev, state));
  1314. if (acpi_idle_bm_check()) {
  1315. if (dev->safe_state) {
  1316. return dev->safe_state->enter(dev, dev->safe_state);
  1317. } else {
  1318. local_irq_disable();
  1319. acpi_safe_halt();
  1320. local_irq_enable();
  1321. return 0;
  1322. }
  1323. }
  1324. local_irq_disable();
  1325. current_thread_info()->status &= ~TS_POLLING;
  1326. /*
  1327. * TS_POLLING-cleared state must be visible before we test
  1328. * NEED_RESCHED:
  1329. */
  1330. smp_mb();
  1331. if (unlikely(need_resched())) {
  1332. current_thread_info()->status |= TS_POLLING;
  1333. local_irq_enable();
  1334. return 0;
  1335. }
  1336. /* Tell the scheduler that we are going deep-idle: */
  1337. sched_clock_idle_sleep_event();
  1338. /*
  1339. * Must be done before busmaster disable as we might need to
  1340. * access HPET !
  1341. */
  1342. acpi_state_timer_broadcast(pr, cx, 1);
  1343. acpi_idle_update_bm_rld(pr, cx);
  1344. /*
  1345. * disable bus master
  1346. * bm_check implies we need ARB_DIS
  1347. * !bm_check implies we need cache flush
  1348. * bm_control implies whether we can do ARB_DIS
  1349. *
  1350. * That leaves a case where bm_check is set and bm_control is
  1351. * not set. In that case we cannot do much, we enter C3
  1352. * without doing anything.
  1353. */
  1354. if (pr->flags.bm_check && pr->flags.bm_control) {
  1355. spin_lock(&c3_lock);
  1356. c3_cpu_count++;
  1357. /* Disable bus master arbitration when all CPUs are in C3 */
  1358. if (c3_cpu_count == num_online_cpus())
  1359. acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1);
  1360. spin_unlock(&c3_lock);
  1361. } else if (!pr->flags.bm_check) {
  1362. ACPI_FLUSH_CPU_CACHE();
  1363. }
  1364. t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
  1365. acpi_idle_do_entry(cx);
  1366. t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
  1367. /* Re-enable bus master arbitration */
  1368. if (pr->flags.bm_check && pr->flags.bm_control) {
  1369. spin_lock(&c3_lock);
  1370. acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0);
  1371. c3_cpu_count--;
  1372. spin_unlock(&c3_lock);
  1373. }
  1374. #if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86_TSC)
  1375. /* TSC could halt in idle, so notify users */
  1376. if (tsc_halts_in_c(ACPI_STATE_C3))
  1377. mark_tsc_unstable("TSC halts in idle");
  1378. #endif
  1379. sleep_ticks = ticks_elapsed(t1, t2);
  1380. /* Tell the scheduler how much we idled: */
  1381. sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS);
  1382. local_irq_enable();
  1383. current_thread_info()->status |= TS_POLLING;
  1384. cx->usage++;
  1385. acpi_state_timer_broadcast(pr, cx, 0);
  1386. cx->time += sleep_ticks;
  1387. return ticks_elapsed_in_us(t1, t2);
  1388. }
  1389. struct cpuidle_driver acpi_idle_driver = {
  1390. .name = "acpi_idle",
  1391. .owner = THIS_MODULE,
  1392. };
  1393. /**
  1394. * acpi_processor_setup_cpuidle - prepares and configures CPUIDLE
  1395. * @pr: the ACPI processor
  1396. */
  1397. static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
  1398. {
  1399. int i, count = CPUIDLE_DRIVER_STATE_START;
  1400. struct acpi_processor_cx *cx;
  1401. struct cpuidle_state *state;
  1402. struct cpuidle_device *dev = &pr->power.dev;
  1403. if (!pr->flags.power_setup_done)
  1404. return -EINVAL;
  1405. if (pr->flags.power == 0) {
  1406. return -EINVAL;
  1407. }
  1408. for (i = 0; i < CPUIDLE_STATE_MAX; i++) {
  1409. dev->states[i].name[0] = '\0';
  1410. dev->states[i].desc[0] = '\0';
  1411. }
  1412. for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) {
  1413. cx = &pr->power.states[i];
  1414. state = &dev->states[count];
  1415. if (!cx->valid)
  1416. continue;
  1417. #ifdef CONFIG_HOTPLUG_CPU
  1418. if ((cx->type != ACPI_STATE_C1) && (num_online_cpus() > 1) &&
  1419. !pr->flags.has_cst &&
  1420. !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
  1421. continue;
  1422. #endif
  1423. cpuidle_set_statedata(state, cx);
  1424. snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i);
  1425. strncpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);
  1426. state->exit_latency = cx->latency;
  1427. state->target_residency = cx->latency * latency_factor;
  1428. state->power_usage = cx->power;
  1429. state->flags = 0;
  1430. switch (cx->type) {
  1431. case ACPI_STATE_C1:
  1432. state->flags |= CPUIDLE_FLAG_SHALLOW;
  1433. state->flags |= CPUIDLE_FLAG_TIME_VALID;
  1434. state->enter = acpi_idle_enter_c1;
  1435. dev->safe_state = state;
  1436. break;
  1437. case ACPI_STATE_C2:
  1438. state->flags |= CPUIDLE_FLAG_BALANCED;
  1439. state->flags |= CPUIDLE_FLAG_TIME_VALID;
  1440. state->enter = acpi_idle_enter_simple;
  1441. dev->safe_state = state;
  1442. break;
  1443. case ACPI_STATE_C3:
  1444. state->flags |= CPUIDLE_FLAG_DEEP;
  1445. state->flags |= CPUIDLE_FLAG_TIME_VALID;
  1446. state->flags |= CPUIDLE_FLAG_CHECK_BM;
  1447. state->enter = pr->flags.bm_check ?
  1448. acpi_idle_enter_bm :
  1449. acpi_idle_enter_simple;
  1450. break;
  1451. }
  1452. count++;
  1453. if (count == CPUIDLE_STATE_MAX)
  1454. break;
  1455. }
  1456. dev->state_count = count;
  1457. if (!count)
  1458. return -EINVAL;
  1459. return 0;
  1460. }
  1461. int acpi_processor_cst_has_changed(struct acpi_processor *pr)
  1462. {
  1463. int ret;
  1464. if (!pr)
  1465. return -EINVAL;
  1466. if (nocst) {
  1467. return -ENODEV;
  1468. }
  1469. if (!pr->flags.power_setup_done)
  1470. return -ENODEV;
  1471. cpuidle_pause_and_lock();
  1472. cpuidle_disable_device(&pr->power.dev);
  1473. acpi_processor_get_power_info(pr);
  1474. acpi_processor_setup_cpuidle(pr);
  1475. ret = cpuidle_enable_device(&pr->power.dev);
  1476. cpuidle_resume_and_unlock();
  1477. return ret;
  1478. }
  1479. #endif /* CONFIG_CPU_IDLE */
  1480. int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
  1481. struct acpi_device *device)
  1482. {
  1483. acpi_status status = 0;
  1484. static int first_run;
  1485. struct proc_dir_entry *entry = NULL;
  1486. unsigned int i;
  1487. if (!first_run) {
  1488. dmi_check_system(processor_power_dmi_table);
  1489. max_cstate = acpi_processor_cstate_check(max_cstate);
  1490. if (max_cstate < ACPI_C_STATES_MAX)
  1491. printk(KERN_NOTICE
  1492. "ACPI: processor limited to max C-state %d\n",
  1493. max_cstate);
  1494. first_run++;
  1495. #if !defined(CONFIG_CPU_IDLE) && defined(CONFIG_SMP)
  1496. pm_qos_add_notifier(PM_QOS_CPU_DMA_LATENCY,
  1497. &acpi_processor_latency_notifier);
  1498. #endif
  1499. }
  1500. if (!pr)
  1501. return -EINVAL;
  1502. if (acpi_gbl_FADT.cst_control && !nocst) {
  1503. status =
  1504. acpi_os_write_port(acpi_gbl_FADT.smi_command, acpi_gbl_FADT.cst_control, 8);
  1505. if (ACPI_FAILURE(status)) {
  1506. ACPI_EXCEPTION((AE_INFO, status,
  1507. "Notifying BIOS of _CST ability failed"));
  1508. }
  1509. }
  1510. acpi_processor_get_power_info(pr);
  1511. pr->flags.power_setup_done = 1;
  1512. /*
  1513. * Install the idle handler if processor power management is supported.
  1514. * Note that we use previously set idle handler will be used on
  1515. * platforms that only support C1.
  1516. */
  1517. if ((pr->flags.power) && (!boot_option_idle_override)) {
  1518. #ifdef CONFIG_CPU_IDLE
  1519. acpi_processor_setup_cpuidle(pr);
  1520. pr->power.dev.cpu = pr->id;
  1521. if (cpuidle_register_device(&pr->power.dev))
  1522. return -EIO;
  1523. #endif
  1524. printk(KERN_INFO PREFIX "CPU%d (power states:", pr->id);
  1525. for (i = 1; i <= pr->power.count; i++)
  1526. if (pr->power.states[i].valid)
  1527. printk(" C%d[C%d]", i,
  1528. pr->power.states[i].type);
  1529. printk(")\n");
  1530. #ifndef CONFIG_CPU_IDLE
  1531. if (pr->id == 0) {
  1532. pm_idle_save = pm_idle;
  1533. pm_idle = acpi_processor_idle;
  1534. }
  1535. #endif
  1536. }
  1537. /* 'power' [R] */
  1538. entry = create_proc_entry(ACPI_PROCESSOR_FILE_POWER,
  1539. S_IRUGO, acpi_device_dir(device));
  1540. if (!entry)
  1541. return -EIO;
  1542. else {
  1543. entry->proc_fops = &acpi_processor_power_fops;
  1544. entry->data = acpi_driver_data(device);
  1545. entry->owner = THIS_MODULE;
  1546. }
  1547. return 0;
  1548. }
  1549. int acpi_processor_power_exit(struct acpi_processor *pr,
  1550. struct acpi_device *device)
  1551. {
  1552. #ifdef CONFIG_CPU_IDLE
  1553. if ((pr->flags.power) && (!boot_option_idle_override))
  1554. cpuidle_unregister_device(&pr->power.dev);
  1555. #endif
  1556. pr->flags.power_setup_done = 0;
  1557. if (acpi_device_dir(device))
  1558. remove_proc_entry(ACPI_PROCESSOR_FILE_POWER,
  1559. acpi_device_dir(device));
  1560. #ifndef CONFIG_CPU_IDLE
  1561. /* Unregister the idle handler when processor #0 is removed. */
  1562. if (pr->id == 0) {
  1563. pm_idle = pm_idle_save;
  1564. /*
  1565. * We are about to unload the current idle thread pm callback
  1566. * (pm_idle), Wait for all processors to update cached/local
  1567. * copies of pm_idle before proceeding.
  1568. */
  1569. cpu_idle_wait();
  1570. #ifdef CONFIG_SMP
  1571. pm_qos_remove_notifier(PM_QOS_CPU_DMA_LATENCY,
  1572. &acpi_processor_latency_notifier);
  1573. #endif
  1574. }
  1575. #endif
  1576. return 0;
  1577. }