processor_idle.c 33 KB

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