processor_idle.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844
  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. } else {
  824. continue;
  825. }
  826. }
  827. obj = &(element->package.elements[2]);
  828. if (obj->type != ACPI_TYPE_INTEGER)
  829. continue;
  830. cx.latency = obj->integer.value;
  831. obj = &(element->package.elements[3]);
  832. if (obj->type != ACPI_TYPE_INTEGER)
  833. continue;
  834. cx.power = obj->integer.value;
  835. current_count++;
  836. memcpy(&(pr->power.states[current_count]), &cx, sizeof(cx));
  837. /*
  838. * We support total ACPI_PROCESSOR_MAX_POWER - 1
  839. * (From 1 through ACPI_PROCESSOR_MAX_POWER - 1)
  840. */
  841. if (current_count >= (ACPI_PROCESSOR_MAX_POWER - 1)) {
  842. printk(KERN_WARNING
  843. "Limiting number of power states to max (%d)\n",
  844. ACPI_PROCESSOR_MAX_POWER);
  845. printk(KERN_WARNING
  846. "Please increase ACPI_PROCESSOR_MAX_POWER if needed.\n");
  847. break;
  848. }
  849. }
  850. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d power states\n",
  851. current_count));
  852. /* Validate number of power states discovered */
  853. if (current_count < 2)
  854. status = -EFAULT;
  855. end:
  856. kfree(buffer.pointer);
  857. return status;
  858. }
  859. static void acpi_processor_power_verify_c2(struct acpi_processor_cx *cx)
  860. {
  861. if (!cx->address)
  862. return;
  863. /*
  864. * C2 latency must be less than or equal to 100
  865. * microseconds.
  866. */
  867. else if (cx->latency > ACPI_PROCESSOR_MAX_C2_LATENCY) {
  868. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  869. "latency too large [%d]\n", cx->latency));
  870. return;
  871. }
  872. /*
  873. * Otherwise we've met all of our C2 requirements.
  874. * Normalize the C2 latency to expidite policy
  875. */
  876. cx->valid = 1;
  877. #ifndef CONFIG_CPU_IDLE
  878. cx->latency_ticks = US_TO_PM_TIMER_TICKS(cx->latency);
  879. #else
  880. cx->latency_ticks = cx->latency;
  881. #endif
  882. return;
  883. }
  884. static void acpi_processor_power_verify_c3(struct acpi_processor *pr,
  885. struct acpi_processor_cx *cx)
  886. {
  887. static int bm_check_flag;
  888. if (!cx->address)
  889. return;
  890. /*
  891. * C3 latency must be less than or equal to 1000
  892. * microseconds.
  893. */
  894. else if (cx->latency > ACPI_PROCESSOR_MAX_C3_LATENCY) {
  895. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  896. "latency too large [%d]\n", cx->latency));
  897. return;
  898. }
  899. /*
  900. * PIIX4 Erratum #18: We don't support C3 when Type-F (fast)
  901. * DMA transfers are used by any ISA device to avoid livelock.
  902. * Note that we could disable Type-F DMA (as recommended by
  903. * the erratum), but this is known to disrupt certain ISA
  904. * devices thus we take the conservative approach.
  905. */
  906. else if (errata.piix4.fdma) {
  907. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  908. "C3 not supported on PIIX4 with Type-F DMA\n"));
  909. return;
  910. }
  911. /* All the logic here assumes flags.bm_check is same across all CPUs */
  912. if (!bm_check_flag) {
  913. /* Determine whether bm_check is needed based on CPU */
  914. acpi_processor_power_init_bm_check(&(pr->flags), pr->id);
  915. bm_check_flag = pr->flags.bm_check;
  916. } else {
  917. pr->flags.bm_check = bm_check_flag;
  918. }
  919. if (pr->flags.bm_check) {
  920. if (!pr->flags.bm_control) {
  921. if (pr->flags.has_cst != 1) {
  922. /* bus mastering control is necessary */
  923. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  924. "C3 support requires BM control\n"));
  925. return;
  926. } else {
  927. /* Here we enter C3 without bus mastering */
  928. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  929. "C3 support without BM control\n"));
  930. }
  931. }
  932. } else {
  933. /*
  934. * WBINVD should be set in fadt, for C3 state to be
  935. * supported on when bm_check is not required.
  936. */
  937. if (!(acpi_gbl_FADT.flags & ACPI_FADT_WBINVD)) {
  938. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  939. "Cache invalidation should work properly"
  940. " for C3 to be enabled on SMP systems\n"));
  941. return;
  942. }
  943. acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0);
  944. }
  945. /*
  946. * Otherwise we've met all of our C3 requirements.
  947. * Normalize the C3 latency to expidite policy. Enable
  948. * checking of bus mastering status (bm_check) so we can
  949. * use this in our C3 policy
  950. */
  951. cx->valid = 1;
  952. #ifndef CONFIG_CPU_IDLE
  953. cx->latency_ticks = US_TO_PM_TIMER_TICKS(cx->latency);
  954. #else
  955. cx->latency_ticks = cx->latency;
  956. #endif
  957. return;
  958. }
  959. static int acpi_processor_power_verify(struct acpi_processor *pr)
  960. {
  961. unsigned int i;
  962. unsigned int working = 0;
  963. pr->power.timer_broadcast_on_state = INT_MAX;
  964. for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
  965. struct acpi_processor_cx *cx = &pr->power.states[i];
  966. switch (cx->type) {
  967. case ACPI_STATE_C1:
  968. cx->valid = 1;
  969. break;
  970. case ACPI_STATE_C2:
  971. acpi_processor_power_verify_c2(cx);
  972. if (cx->valid)
  973. acpi_timer_check_state(i, pr, cx);
  974. break;
  975. case ACPI_STATE_C3:
  976. acpi_processor_power_verify_c3(pr, cx);
  977. if (cx->valid)
  978. acpi_timer_check_state(i, pr, cx);
  979. break;
  980. }
  981. if (cx->valid)
  982. working++;
  983. }
  984. acpi_propagate_timer_broadcast(pr);
  985. return (working);
  986. }
  987. static int acpi_processor_get_power_info(struct acpi_processor *pr)
  988. {
  989. unsigned int i;
  990. int result;
  991. /* NOTE: the idle thread may not be running while calling
  992. * this function */
  993. /* Zero initialize all the C-states info. */
  994. memset(pr->power.states, 0, sizeof(pr->power.states));
  995. result = acpi_processor_get_power_info_cst(pr);
  996. if (result == -ENODEV)
  997. result = acpi_processor_get_power_info_fadt(pr);
  998. if (result)
  999. return result;
  1000. acpi_processor_get_power_info_default(pr);
  1001. pr->power.count = acpi_processor_power_verify(pr);
  1002. #ifndef CONFIG_CPU_IDLE
  1003. /*
  1004. * Set Default Policy
  1005. * ------------------
  1006. * Now that we know which states are supported, set the default
  1007. * policy. Note that this policy can be changed dynamically
  1008. * (e.g. encourage deeper sleeps to conserve battery life when
  1009. * not on AC).
  1010. */
  1011. result = acpi_processor_set_power_policy(pr);
  1012. if (result)
  1013. return result;
  1014. #endif
  1015. /*
  1016. * if one state of type C2 or C3 is available, mark this
  1017. * CPU as being "idle manageable"
  1018. */
  1019. for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
  1020. if (pr->power.states[i].valid) {
  1021. pr->power.count = i;
  1022. if (pr->power.states[i].type >= ACPI_STATE_C2)
  1023. pr->flags.power = 1;
  1024. }
  1025. }
  1026. return 0;
  1027. }
  1028. static int acpi_processor_power_seq_show(struct seq_file *seq, void *offset)
  1029. {
  1030. struct acpi_processor *pr = seq->private;
  1031. unsigned int i;
  1032. if (!pr)
  1033. goto end;
  1034. seq_printf(seq, "active state: C%zd\n"
  1035. "max_cstate: C%d\n"
  1036. "bus master activity: %08x\n"
  1037. "maximum allowed latency: %d usec\n",
  1038. pr->power.state ? pr->power.state - pr->power.states : 0,
  1039. max_cstate, (unsigned)pr->power.bm_activity,
  1040. pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY));
  1041. seq_puts(seq, "states:\n");
  1042. for (i = 1; i <= pr->power.count; i++) {
  1043. seq_printf(seq, " %cC%d: ",
  1044. (&pr->power.states[i] ==
  1045. pr->power.state ? '*' : ' '), i);
  1046. if (!pr->power.states[i].valid) {
  1047. seq_puts(seq, "<not supported>\n");
  1048. continue;
  1049. }
  1050. switch (pr->power.states[i].type) {
  1051. case ACPI_STATE_C1:
  1052. seq_printf(seq, "type[C1] ");
  1053. break;
  1054. case ACPI_STATE_C2:
  1055. seq_printf(seq, "type[C2] ");
  1056. break;
  1057. case ACPI_STATE_C3:
  1058. seq_printf(seq, "type[C3] ");
  1059. break;
  1060. default:
  1061. seq_printf(seq, "type[--] ");
  1062. break;
  1063. }
  1064. if (pr->power.states[i].promotion.state)
  1065. seq_printf(seq, "promotion[C%zd] ",
  1066. (pr->power.states[i].promotion.state -
  1067. pr->power.states));
  1068. else
  1069. seq_puts(seq, "promotion[--] ");
  1070. if (pr->power.states[i].demotion.state)
  1071. seq_printf(seq, "demotion[C%zd] ",
  1072. (pr->power.states[i].demotion.state -
  1073. pr->power.states));
  1074. else
  1075. seq_puts(seq, "demotion[--] ");
  1076. seq_printf(seq, "latency[%03d] usage[%08d] duration[%020llu]\n",
  1077. pr->power.states[i].latency,
  1078. pr->power.states[i].usage,
  1079. (unsigned long long)pr->power.states[i].time);
  1080. }
  1081. end:
  1082. return 0;
  1083. }
  1084. static int acpi_processor_power_open_fs(struct inode *inode, struct file *file)
  1085. {
  1086. return single_open(file, acpi_processor_power_seq_show,
  1087. PDE(inode)->data);
  1088. }
  1089. static const struct file_operations acpi_processor_power_fops = {
  1090. .open = acpi_processor_power_open_fs,
  1091. .read = seq_read,
  1092. .llseek = seq_lseek,
  1093. .release = single_release,
  1094. };
  1095. #ifndef CONFIG_CPU_IDLE
  1096. int acpi_processor_cst_has_changed(struct acpi_processor *pr)
  1097. {
  1098. int result = 0;
  1099. if (!pr)
  1100. return -EINVAL;
  1101. if (nocst) {
  1102. return -ENODEV;
  1103. }
  1104. if (!pr->flags.power_setup_done)
  1105. return -ENODEV;
  1106. /* Fall back to the default idle loop */
  1107. pm_idle = pm_idle_save;
  1108. synchronize_sched(); /* Relies on interrupts forcing exit from idle. */
  1109. pr->flags.power = 0;
  1110. result = acpi_processor_get_power_info(pr);
  1111. if ((pr->flags.power == 1) && (pr->flags.power_setup_done))
  1112. pm_idle = acpi_processor_idle;
  1113. return result;
  1114. }
  1115. #ifdef CONFIG_SMP
  1116. static void smp_callback(void *v)
  1117. {
  1118. /* we already woke the CPU up, nothing more to do */
  1119. }
  1120. /*
  1121. * This function gets called when a part of the kernel has a new latency
  1122. * requirement. This means we need to get all processors out of their C-state,
  1123. * and then recalculate a new suitable C-state. Just do a cross-cpu IPI; that
  1124. * wakes them all right up.
  1125. */
  1126. static int acpi_processor_latency_notify(struct notifier_block *b,
  1127. unsigned long l, void *v)
  1128. {
  1129. smp_call_function(smp_callback, NULL, 0, 1);
  1130. return NOTIFY_OK;
  1131. }
  1132. static struct notifier_block acpi_processor_latency_notifier = {
  1133. .notifier_call = acpi_processor_latency_notify,
  1134. };
  1135. #endif
  1136. #else /* CONFIG_CPU_IDLE */
  1137. /**
  1138. * acpi_idle_bm_check - checks if bus master activity was detected
  1139. */
  1140. static int acpi_idle_bm_check(void)
  1141. {
  1142. u32 bm_status = 0;
  1143. acpi_get_register(ACPI_BITREG_BUS_MASTER_STATUS, &bm_status);
  1144. if (bm_status)
  1145. acpi_set_register(ACPI_BITREG_BUS_MASTER_STATUS, 1);
  1146. /*
  1147. * PIIX4 Erratum #18: Note that BM_STS doesn't always reflect
  1148. * the true state of bus mastering activity; forcing us to
  1149. * manually check the BMIDEA bit of each IDE channel.
  1150. */
  1151. else if (errata.piix4.bmisx) {
  1152. if ((inb_p(errata.piix4.bmisx + 0x02) & 0x01)
  1153. || (inb_p(errata.piix4.bmisx + 0x0A) & 0x01))
  1154. bm_status = 1;
  1155. }
  1156. return bm_status;
  1157. }
  1158. /**
  1159. * acpi_idle_update_bm_rld - updates the BM_RLD bit depending on target state
  1160. * @pr: the processor
  1161. * @target: the new target state
  1162. */
  1163. static inline void acpi_idle_update_bm_rld(struct acpi_processor *pr,
  1164. struct acpi_processor_cx *target)
  1165. {
  1166. if (pr->flags.bm_rld_set && target->type != ACPI_STATE_C3) {
  1167. acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0);
  1168. pr->flags.bm_rld_set = 0;
  1169. }
  1170. if (!pr->flags.bm_rld_set && target->type == ACPI_STATE_C3) {
  1171. acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 1);
  1172. pr->flags.bm_rld_set = 1;
  1173. }
  1174. }
  1175. /**
  1176. * acpi_idle_do_entry - a helper function that does C2 and C3 type entry
  1177. * @cx: cstate data
  1178. *
  1179. * Caller disables interrupt before call and enables interrupt after return.
  1180. */
  1181. static inline void acpi_idle_do_entry(struct acpi_processor_cx *cx)
  1182. {
  1183. if (cx->entry_method == ACPI_CSTATE_FFH) {
  1184. /* Call into architectural FFH based C-state */
  1185. acpi_processor_ffh_cstate_enter(cx);
  1186. } else if (cx->entry_method == ACPI_CSTATE_HALT) {
  1187. acpi_safe_halt();
  1188. } else {
  1189. int unused;
  1190. /* IO port based C-state */
  1191. inb(cx->address);
  1192. /* Dummy wait op - must do something useless after P_LVL2 read
  1193. because chipsets cannot guarantee that STPCLK# signal
  1194. gets asserted in time to freeze execution properly. */
  1195. unused = inl(acpi_gbl_FADT.xpm_timer_block.address);
  1196. }
  1197. }
  1198. /**
  1199. * acpi_idle_enter_c1 - enters an ACPI C1 state-type
  1200. * @dev: the target CPU
  1201. * @state: the state data
  1202. *
  1203. * This is equivalent to the HALT instruction.
  1204. */
  1205. static int acpi_idle_enter_c1(struct cpuidle_device *dev,
  1206. struct cpuidle_state *state)
  1207. {
  1208. u32 t1, t2;
  1209. struct acpi_processor *pr;
  1210. struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
  1211. pr = processors[smp_processor_id()];
  1212. if (unlikely(!pr))
  1213. return 0;
  1214. local_irq_disable();
  1215. if (pr->flags.bm_check)
  1216. acpi_idle_update_bm_rld(pr, cx);
  1217. t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
  1218. acpi_idle_do_entry(cx);
  1219. t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
  1220. local_irq_enable();
  1221. cx->usage++;
  1222. return ticks_elapsed_in_us(t1, t2);
  1223. }
  1224. /**
  1225. * acpi_idle_enter_simple - enters an ACPI state without BM handling
  1226. * @dev: the target CPU
  1227. * @state: the state data
  1228. */
  1229. static int acpi_idle_enter_simple(struct cpuidle_device *dev,
  1230. struct cpuidle_state *state)
  1231. {
  1232. struct acpi_processor *pr;
  1233. struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
  1234. u32 t1, t2;
  1235. int sleep_ticks = 0;
  1236. pr = processors[smp_processor_id()];
  1237. if (unlikely(!pr))
  1238. return 0;
  1239. if (acpi_idle_suspend)
  1240. return(acpi_idle_enter_c1(dev, state));
  1241. local_irq_disable();
  1242. current_thread_info()->status &= ~TS_POLLING;
  1243. /*
  1244. * TS_POLLING-cleared state must be visible before we test
  1245. * NEED_RESCHED:
  1246. */
  1247. smp_mb();
  1248. if (unlikely(need_resched())) {
  1249. current_thread_info()->status |= TS_POLLING;
  1250. local_irq_enable();
  1251. return 0;
  1252. }
  1253. acpi_unlazy_tlb(smp_processor_id());
  1254. /*
  1255. * Must be done before busmaster disable as we might need to
  1256. * access HPET !
  1257. */
  1258. acpi_state_timer_broadcast(pr, cx, 1);
  1259. if (pr->flags.bm_check)
  1260. acpi_idle_update_bm_rld(pr, cx);
  1261. if (cx->type == ACPI_STATE_C3)
  1262. ACPI_FLUSH_CPU_CACHE();
  1263. t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
  1264. /* Tell the scheduler that we are going deep-idle: */
  1265. sched_clock_idle_sleep_event();
  1266. acpi_idle_do_entry(cx);
  1267. t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
  1268. #if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86_TSC)
  1269. /* TSC could halt in idle, so notify users */
  1270. if (tsc_halts_in_c(cx->type))
  1271. mark_tsc_unstable("TSC halts in idle");;
  1272. #endif
  1273. sleep_ticks = ticks_elapsed(t1, t2);
  1274. /* Tell the scheduler how much we idled: */
  1275. sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS);
  1276. local_irq_enable();
  1277. current_thread_info()->status |= TS_POLLING;
  1278. cx->usage++;
  1279. acpi_state_timer_broadcast(pr, cx, 0);
  1280. cx->time += sleep_ticks;
  1281. return ticks_elapsed_in_us(t1, t2);
  1282. }
  1283. static int c3_cpu_count;
  1284. static DEFINE_SPINLOCK(c3_lock);
  1285. /**
  1286. * acpi_idle_enter_bm - enters C3 with proper BM handling
  1287. * @dev: the target CPU
  1288. * @state: the state data
  1289. *
  1290. * If BM is detected, the deepest non-C3 idle state is entered instead.
  1291. */
  1292. static int acpi_idle_enter_bm(struct cpuidle_device *dev,
  1293. struct cpuidle_state *state)
  1294. {
  1295. struct acpi_processor *pr;
  1296. struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
  1297. u32 t1, t2;
  1298. int sleep_ticks = 0;
  1299. pr = processors[smp_processor_id()];
  1300. if (unlikely(!pr))
  1301. return 0;
  1302. if (acpi_idle_suspend)
  1303. return(acpi_idle_enter_c1(dev, state));
  1304. if (acpi_idle_bm_check()) {
  1305. if (dev->safe_state) {
  1306. return dev->safe_state->enter(dev, dev->safe_state);
  1307. } else {
  1308. local_irq_disable();
  1309. acpi_safe_halt();
  1310. local_irq_enable();
  1311. return 0;
  1312. }
  1313. }
  1314. local_irq_disable();
  1315. current_thread_info()->status &= ~TS_POLLING;
  1316. /*
  1317. * TS_POLLING-cleared state must be visible before we test
  1318. * NEED_RESCHED:
  1319. */
  1320. smp_mb();
  1321. if (unlikely(need_resched())) {
  1322. current_thread_info()->status |= TS_POLLING;
  1323. local_irq_enable();
  1324. return 0;
  1325. }
  1326. /* Tell the scheduler that we are going deep-idle: */
  1327. sched_clock_idle_sleep_event();
  1328. /*
  1329. * Must be done before busmaster disable as we might need to
  1330. * access HPET !
  1331. */
  1332. acpi_state_timer_broadcast(pr, cx, 1);
  1333. acpi_idle_update_bm_rld(pr, cx);
  1334. /*
  1335. * disable bus master
  1336. * bm_check implies we need ARB_DIS
  1337. * !bm_check implies we need cache flush
  1338. * bm_control implies whether we can do ARB_DIS
  1339. *
  1340. * That leaves a case where bm_check is set and bm_control is
  1341. * not set. In that case we cannot do much, we enter C3
  1342. * without doing anything.
  1343. */
  1344. if (pr->flags.bm_check && pr->flags.bm_control) {
  1345. spin_lock(&c3_lock);
  1346. c3_cpu_count++;
  1347. /* Disable bus master arbitration when all CPUs are in C3 */
  1348. if (c3_cpu_count == num_online_cpus())
  1349. acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1);
  1350. spin_unlock(&c3_lock);
  1351. } else if (!pr->flags.bm_check) {
  1352. ACPI_FLUSH_CPU_CACHE();
  1353. }
  1354. t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
  1355. acpi_idle_do_entry(cx);
  1356. t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
  1357. /* Re-enable bus master arbitration */
  1358. if (pr->flags.bm_check && pr->flags.bm_control) {
  1359. spin_lock(&c3_lock);
  1360. acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0);
  1361. c3_cpu_count--;
  1362. spin_unlock(&c3_lock);
  1363. }
  1364. #if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86_TSC)
  1365. /* TSC could halt in idle, so notify users */
  1366. if (tsc_halts_in_c(ACPI_STATE_C3))
  1367. mark_tsc_unstable("TSC halts in idle");
  1368. #endif
  1369. sleep_ticks = ticks_elapsed(t1, t2);
  1370. /* Tell the scheduler how much we idled: */
  1371. sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS);
  1372. local_irq_enable();
  1373. current_thread_info()->status |= TS_POLLING;
  1374. cx->usage++;
  1375. acpi_state_timer_broadcast(pr, cx, 0);
  1376. cx->time += sleep_ticks;
  1377. return ticks_elapsed_in_us(t1, t2);
  1378. }
  1379. struct cpuidle_driver acpi_idle_driver = {
  1380. .name = "acpi_idle",
  1381. .owner = THIS_MODULE,
  1382. };
  1383. /**
  1384. * acpi_processor_setup_cpuidle - prepares and configures CPUIDLE
  1385. * @pr: the ACPI processor
  1386. */
  1387. static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
  1388. {
  1389. int i, count = CPUIDLE_DRIVER_STATE_START;
  1390. struct acpi_processor_cx *cx;
  1391. struct cpuidle_state *state;
  1392. struct cpuidle_device *dev = &pr->power.dev;
  1393. if (!pr->flags.power_setup_done)
  1394. return -EINVAL;
  1395. if (pr->flags.power == 0) {
  1396. return -EINVAL;
  1397. }
  1398. for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) {
  1399. cx = &pr->power.states[i];
  1400. state = &dev->states[count];
  1401. if (!cx->valid)
  1402. continue;
  1403. #ifdef CONFIG_HOTPLUG_CPU
  1404. if ((cx->type != ACPI_STATE_C1) && (num_online_cpus() > 1) &&
  1405. !pr->flags.has_cst &&
  1406. !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
  1407. continue;
  1408. #endif
  1409. cpuidle_set_statedata(state, cx);
  1410. snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i);
  1411. state->exit_latency = cx->latency;
  1412. state->target_residency = cx->latency * latency_factor;
  1413. state->power_usage = cx->power;
  1414. state->flags = 0;
  1415. switch (cx->type) {
  1416. case ACPI_STATE_C1:
  1417. state->flags |= CPUIDLE_FLAG_SHALLOW;
  1418. state->flags |= CPUIDLE_FLAG_TIME_VALID;
  1419. state->enter = acpi_idle_enter_c1;
  1420. dev->safe_state = state;
  1421. break;
  1422. case ACPI_STATE_C2:
  1423. state->flags |= CPUIDLE_FLAG_BALANCED;
  1424. state->flags |= CPUIDLE_FLAG_TIME_VALID;
  1425. state->enter = acpi_idle_enter_simple;
  1426. dev->safe_state = state;
  1427. break;
  1428. case ACPI_STATE_C3:
  1429. state->flags |= CPUIDLE_FLAG_DEEP;
  1430. state->flags |= CPUIDLE_FLAG_TIME_VALID;
  1431. state->flags |= CPUIDLE_FLAG_CHECK_BM;
  1432. state->enter = pr->flags.bm_check ?
  1433. acpi_idle_enter_bm :
  1434. acpi_idle_enter_simple;
  1435. break;
  1436. }
  1437. count++;
  1438. if (count == CPUIDLE_STATE_MAX)
  1439. break;
  1440. }
  1441. dev->state_count = count;
  1442. if (!count)
  1443. return -EINVAL;
  1444. return 0;
  1445. }
  1446. int acpi_processor_cst_has_changed(struct acpi_processor *pr)
  1447. {
  1448. int ret;
  1449. if (!pr)
  1450. return -EINVAL;
  1451. if (nocst) {
  1452. return -ENODEV;
  1453. }
  1454. if (!pr->flags.power_setup_done)
  1455. return -ENODEV;
  1456. cpuidle_pause_and_lock();
  1457. cpuidle_disable_device(&pr->power.dev);
  1458. acpi_processor_get_power_info(pr);
  1459. acpi_processor_setup_cpuidle(pr);
  1460. ret = cpuidle_enable_device(&pr->power.dev);
  1461. cpuidle_resume_and_unlock();
  1462. return ret;
  1463. }
  1464. #endif /* CONFIG_CPU_IDLE */
  1465. int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
  1466. struct acpi_device *device)
  1467. {
  1468. acpi_status status = 0;
  1469. static int first_run;
  1470. struct proc_dir_entry *entry = NULL;
  1471. unsigned int i;
  1472. if (!first_run) {
  1473. dmi_check_system(processor_power_dmi_table);
  1474. max_cstate = acpi_processor_cstate_check(max_cstate);
  1475. if (max_cstate < ACPI_C_STATES_MAX)
  1476. printk(KERN_NOTICE
  1477. "ACPI: processor limited to max C-state %d\n",
  1478. max_cstate);
  1479. first_run++;
  1480. #if !defined(CONFIG_CPU_IDLE) && defined(CONFIG_SMP)
  1481. pm_qos_add_notifier(PM_QOS_CPU_DMA_LATENCY,
  1482. &acpi_processor_latency_notifier);
  1483. #endif
  1484. }
  1485. if (!pr)
  1486. return -EINVAL;
  1487. if (acpi_gbl_FADT.cst_control && !nocst) {
  1488. status =
  1489. acpi_os_write_port(acpi_gbl_FADT.smi_command, acpi_gbl_FADT.cst_control, 8);
  1490. if (ACPI_FAILURE(status)) {
  1491. ACPI_EXCEPTION((AE_INFO, status,
  1492. "Notifying BIOS of _CST ability failed"));
  1493. }
  1494. }
  1495. acpi_processor_get_power_info(pr);
  1496. pr->flags.power_setup_done = 1;
  1497. /*
  1498. * Install the idle handler if processor power management is supported.
  1499. * Note that we use previously set idle handler will be used on
  1500. * platforms that only support C1.
  1501. */
  1502. if ((pr->flags.power) && (!boot_option_idle_override)) {
  1503. #ifdef CONFIG_CPU_IDLE
  1504. acpi_processor_setup_cpuidle(pr);
  1505. pr->power.dev.cpu = pr->id;
  1506. if (cpuidle_register_device(&pr->power.dev))
  1507. return -EIO;
  1508. #endif
  1509. printk(KERN_INFO PREFIX "CPU%d (power states:", pr->id);
  1510. for (i = 1; i <= pr->power.count; i++)
  1511. if (pr->power.states[i].valid)
  1512. printk(" C%d[C%d]", i,
  1513. pr->power.states[i].type);
  1514. printk(")\n");
  1515. #ifndef CONFIG_CPU_IDLE
  1516. if (pr->id == 0) {
  1517. pm_idle_save = pm_idle;
  1518. pm_idle = acpi_processor_idle;
  1519. }
  1520. #endif
  1521. }
  1522. /* 'power' [R] */
  1523. entry = create_proc_entry(ACPI_PROCESSOR_FILE_POWER,
  1524. S_IRUGO, acpi_device_dir(device));
  1525. if (!entry)
  1526. return -EIO;
  1527. else {
  1528. entry->proc_fops = &acpi_processor_power_fops;
  1529. entry->data = acpi_driver_data(device);
  1530. entry->owner = THIS_MODULE;
  1531. }
  1532. return 0;
  1533. }
  1534. int acpi_processor_power_exit(struct acpi_processor *pr,
  1535. struct acpi_device *device)
  1536. {
  1537. #ifdef CONFIG_CPU_IDLE
  1538. if ((pr->flags.power) && (!boot_option_idle_override))
  1539. cpuidle_unregister_device(&pr->power.dev);
  1540. #endif
  1541. pr->flags.power_setup_done = 0;
  1542. if (acpi_device_dir(device))
  1543. remove_proc_entry(ACPI_PROCESSOR_FILE_POWER,
  1544. acpi_device_dir(device));
  1545. #ifndef CONFIG_CPU_IDLE
  1546. /* Unregister the idle handler when processor #0 is removed. */
  1547. if (pr->id == 0) {
  1548. pm_idle = pm_idle_save;
  1549. /*
  1550. * We are about to unload the current idle thread pm callback
  1551. * (pm_idle), Wait for all processors to update cached/local
  1552. * copies of pm_idle before proceeding.
  1553. */
  1554. cpu_idle_wait();
  1555. #ifdef CONFIG_SMP
  1556. pm_qos_remove_notifier(PM_QOS_CPU_DMA_LATENCY,
  1557. &acpi_processor_latency_notifier);
  1558. #endif
  1559. }
  1560. #endif
  1561. return 0;
  1562. }