processor_idle.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  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/latency.h>
  41. #include <asm/io.h>
  42. #include <asm/uaccess.h>
  43. #include <acpi/acpi_bus.h>
  44. #include <acpi/processor.h>
  45. #define ACPI_PROCESSOR_COMPONENT 0x01000000
  46. #define ACPI_PROCESSOR_CLASS "processor"
  47. #define ACPI_PROCESSOR_DRIVER_NAME "ACPI Processor Driver"
  48. #define _COMPONENT ACPI_PROCESSOR_COMPONENT
  49. ACPI_MODULE_NAME("acpi_processor")
  50. #define ACPI_PROCESSOR_FILE_POWER "power"
  51. #define US_TO_PM_TIMER_TICKS(t) ((t * (PM_TIMER_FREQUENCY/1000)) / 1000)
  52. #define C2_OVERHEAD 4 /* 1us (3.579 ticks per us) */
  53. #define C3_OVERHEAD 4 /* 1us (3.579 ticks per us) */
  54. static void (*pm_idle_save) (void) __read_mostly;
  55. module_param(max_cstate, uint, 0644);
  56. static unsigned int nocst __read_mostly;
  57. module_param(nocst, uint, 0000);
  58. /*
  59. * bm_history -- bit-mask with a bit per jiffy of bus-master activity
  60. * 1000 HZ: 0xFFFFFFFF: 32 jiffies = 32ms
  61. * 800 HZ: 0xFFFFFFFF: 32 jiffies = 40ms
  62. * 100 HZ: 0x0000000F: 4 jiffies = 40ms
  63. * reduce history for more aggressive entry into C3
  64. */
  65. static unsigned int bm_history __read_mostly =
  66. (HZ >= 800 ? 0xFFFFFFFF : ((1U << (HZ / 25)) - 1));
  67. module_param(bm_history, uint, 0644);
  68. /* --------------------------------------------------------------------------
  69. Power Management
  70. -------------------------------------------------------------------------- */
  71. /*
  72. * IBM ThinkPad R40e crashes mysteriously when going into C2 or C3.
  73. * For now disable this. Probably a bug somewhere else.
  74. *
  75. * To skip this limit, boot/load with a large max_cstate limit.
  76. */
  77. static int set_max_cstate(struct dmi_system_id *id)
  78. {
  79. if (max_cstate > ACPI_PROCESSOR_MAX_POWER)
  80. return 0;
  81. printk(KERN_NOTICE PREFIX "%s detected - limiting to C%ld max_cstate."
  82. " Override with \"processor.max_cstate=%d\"\n", id->ident,
  83. (long)id->driver_data, ACPI_PROCESSOR_MAX_POWER + 1);
  84. max_cstate = (long)id->driver_data;
  85. return 0;
  86. }
  87. /* Actually this shouldn't be __cpuinitdata, would be better to fix the
  88. callers to only run once -AK */
  89. static struct dmi_system_id __cpuinitdata processor_power_dmi_table[] = {
  90. { set_max_cstate, "IBM ThinkPad R40e", {
  91. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  92. DMI_MATCH(DMI_BIOS_VERSION,"1SET70WW")}, (void *)1},
  93. { set_max_cstate, "IBM ThinkPad R40e", {
  94. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  95. DMI_MATCH(DMI_BIOS_VERSION,"1SET60WW")}, (void *)1},
  96. { set_max_cstate, "IBM ThinkPad R40e", {
  97. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  98. DMI_MATCH(DMI_BIOS_VERSION,"1SET43WW") }, (void*)1},
  99. { set_max_cstate, "IBM ThinkPad R40e", {
  100. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  101. DMI_MATCH(DMI_BIOS_VERSION,"1SET45WW") }, (void*)1},
  102. { set_max_cstate, "IBM ThinkPad R40e", {
  103. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  104. DMI_MATCH(DMI_BIOS_VERSION,"1SET47WW") }, (void*)1},
  105. { set_max_cstate, "IBM ThinkPad R40e", {
  106. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  107. DMI_MATCH(DMI_BIOS_VERSION,"1SET50WW") }, (void*)1},
  108. { set_max_cstate, "IBM ThinkPad R40e", {
  109. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  110. DMI_MATCH(DMI_BIOS_VERSION,"1SET52WW") }, (void*)1},
  111. { set_max_cstate, "IBM ThinkPad R40e", {
  112. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  113. DMI_MATCH(DMI_BIOS_VERSION,"1SET55WW") }, (void*)1},
  114. { set_max_cstate, "IBM ThinkPad R40e", {
  115. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  116. DMI_MATCH(DMI_BIOS_VERSION,"1SET56WW") }, (void*)1},
  117. { set_max_cstate, "IBM ThinkPad R40e", {
  118. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  119. DMI_MATCH(DMI_BIOS_VERSION,"1SET59WW") }, (void*)1},
  120. { set_max_cstate, "IBM ThinkPad R40e", {
  121. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  122. DMI_MATCH(DMI_BIOS_VERSION,"1SET60WW") }, (void*)1},
  123. { set_max_cstate, "IBM ThinkPad R40e", {
  124. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  125. DMI_MATCH(DMI_BIOS_VERSION,"1SET61WW") }, (void*)1},
  126. { set_max_cstate, "IBM ThinkPad R40e", {
  127. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  128. DMI_MATCH(DMI_BIOS_VERSION,"1SET62WW") }, (void*)1},
  129. { set_max_cstate, "IBM ThinkPad R40e", {
  130. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  131. DMI_MATCH(DMI_BIOS_VERSION,"1SET64WW") }, (void*)1},
  132. { set_max_cstate, "IBM ThinkPad R40e", {
  133. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  134. DMI_MATCH(DMI_BIOS_VERSION,"1SET65WW") }, (void*)1},
  135. { set_max_cstate, "IBM ThinkPad R40e", {
  136. DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
  137. DMI_MATCH(DMI_BIOS_VERSION,"1SET68WW") }, (void*)1},
  138. { set_max_cstate, "Medion 41700", {
  139. DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
  140. DMI_MATCH(DMI_BIOS_VERSION,"R01-A1J")}, (void *)1},
  141. { set_max_cstate, "Clevo 5600D", {
  142. DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
  143. DMI_MATCH(DMI_BIOS_VERSION,"SHE845M0.86C.0013.D.0302131307")},
  144. (void *)2},
  145. {},
  146. };
  147. static inline u32 ticks_elapsed(u32 t1, u32 t2)
  148. {
  149. if (t2 >= t1)
  150. return (t2 - t1);
  151. else if (!(acpi_fadt.flags & ACPI_FADT_32BIT_TIMER))
  152. return (((0x00FFFFFF - t1) + t2) & 0x00FFFFFF);
  153. else
  154. return ((0xFFFFFFFF - t1) + t2);
  155. }
  156. static void
  157. acpi_processor_power_activate(struct acpi_processor *pr,
  158. struct acpi_processor_cx *new)
  159. {
  160. struct acpi_processor_cx *old;
  161. if (!pr || !new)
  162. return;
  163. old = pr->power.state;
  164. if (old)
  165. old->promotion.count = 0;
  166. new->demotion.count = 0;
  167. /* Cleanup from old state. */
  168. if (old) {
  169. switch (old->type) {
  170. case ACPI_STATE_C3:
  171. /* Disable bus master reload */
  172. if (new->type != ACPI_STATE_C3 && pr->flags.bm_check)
  173. acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0,
  174. ACPI_MTX_DO_NOT_LOCK);
  175. break;
  176. }
  177. }
  178. /* Prepare to use new state. */
  179. switch (new->type) {
  180. case ACPI_STATE_C3:
  181. /* Enable bus master reload */
  182. if (old->type != ACPI_STATE_C3 && pr->flags.bm_check)
  183. acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 1,
  184. ACPI_MTX_DO_NOT_LOCK);
  185. break;
  186. }
  187. pr->power.state = new;
  188. return;
  189. }
  190. static void acpi_safe_halt(void)
  191. {
  192. current_thread_info()->status &= ~TS_POLLING;
  193. /*
  194. * TS_POLLING-cleared state must be visible before we
  195. * test NEED_RESCHED:
  196. */
  197. smp_mb();
  198. if (!need_resched())
  199. safe_halt();
  200. current_thread_info()->status |= TS_POLLING;
  201. }
  202. static atomic_t c3_cpu_count;
  203. /* Common C-state entry for C2, C3, .. */
  204. static void acpi_cstate_enter(struct acpi_processor_cx *cstate)
  205. {
  206. if (cstate->space_id == ACPI_CSTATE_FFH) {
  207. /* Call into architectural FFH based C-state */
  208. acpi_processor_ffh_cstate_enter(cstate);
  209. } else {
  210. int unused;
  211. /* IO port based C-state */
  212. inb(cstate->address);
  213. /* Dummy wait op - must do something useless after P_LVL2 read
  214. because chipsets cannot guarantee that STPCLK# signal
  215. gets asserted in time to freeze execution properly. */
  216. unused = inl(acpi_fadt.xpm_timer_block.address);
  217. }
  218. }
  219. static void acpi_processor_idle(void)
  220. {
  221. struct acpi_processor *pr = NULL;
  222. struct acpi_processor_cx *cx = NULL;
  223. struct acpi_processor_cx *next_state = NULL;
  224. int sleep_ticks = 0;
  225. u32 t1, t2 = 0;
  226. pr = processors[smp_processor_id()];
  227. if (!pr)
  228. return;
  229. /*
  230. * Interrupts must be disabled during bus mastering calculations and
  231. * for C2/C3 transitions.
  232. */
  233. local_irq_disable();
  234. /*
  235. * Check whether we truly need to go idle, or should
  236. * reschedule:
  237. */
  238. if (unlikely(need_resched())) {
  239. local_irq_enable();
  240. return;
  241. }
  242. cx = pr->power.state;
  243. if (!cx) {
  244. if (pm_idle_save)
  245. pm_idle_save();
  246. else
  247. acpi_safe_halt();
  248. return;
  249. }
  250. /*
  251. * Check BM Activity
  252. * -----------------
  253. * Check for bus mastering activity (if required), record, and check
  254. * for demotion.
  255. */
  256. if (pr->flags.bm_check) {
  257. u32 bm_status = 0;
  258. unsigned long diff = jiffies - pr->power.bm_check_timestamp;
  259. if (diff > 31)
  260. diff = 31;
  261. pr->power.bm_activity <<= diff;
  262. acpi_get_register(ACPI_BITREG_BUS_MASTER_STATUS,
  263. &bm_status, ACPI_MTX_DO_NOT_LOCK);
  264. if (bm_status) {
  265. pr->power.bm_activity |= 0x1;
  266. acpi_set_register(ACPI_BITREG_BUS_MASTER_STATUS,
  267. 1, ACPI_MTX_DO_NOT_LOCK);
  268. }
  269. /*
  270. * PIIX4 Erratum #18: Note that BM_STS doesn't always reflect
  271. * the true state of bus mastering activity; forcing us to
  272. * manually check the BMIDEA bit of each IDE channel.
  273. */
  274. else if (errata.piix4.bmisx) {
  275. if ((inb_p(errata.piix4.bmisx + 0x02) & 0x01)
  276. || (inb_p(errata.piix4.bmisx + 0x0A) & 0x01))
  277. pr->power.bm_activity |= 0x1;
  278. }
  279. pr->power.bm_check_timestamp = jiffies;
  280. /*
  281. * If bus mastering is or was active this jiffy, demote
  282. * to avoid a faulty transition. Note that the processor
  283. * won't enter a low-power state during this call (to this
  284. * function) but should upon the next.
  285. *
  286. * TBD: A better policy might be to fallback to the demotion
  287. * state (use it for this quantum only) istead of
  288. * demoting -- and rely on duration as our sole demotion
  289. * qualification. This may, however, introduce DMA
  290. * issues (e.g. floppy DMA transfer overrun/underrun).
  291. */
  292. if ((pr->power.bm_activity & 0x1) &&
  293. cx->demotion.threshold.bm) {
  294. local_irq_enable();
  295. next_state = cx->demotion.state;
  296. goto end;
  297. }
  298. }
  299. #ifdef CONFIG_HOTPLUG_CPU
  300. /*
  301. * Check for P_LVL2_UP flag before entering C2 and above on
  302. * an SMP system. We do it here instead of doing it at _CST/P_LVL
  303. * detection phase, to work cleanly with logical CPU hotplug.
  304. */
  305. if ((cx->type != ACPI_STATE_C1) && (num_online_cpus() > 1) &&
  306. !pr->flags.has_cst && !(acpi_fadt.flags & ACPI_FADT_C2_MP_SUPPORTED))
  307. cx = &pr->power.states[ACPI_STATE_C1];
  308. #endif
  309. /*
  310. * Sleep:
  311. * ------
  312. * Invoke the current Cx state to put the processor to sleep.
  313. */
  314. if (cx->type == ACPI_STATE_C2 || cx->type == ACPI_STATE_C3) {
  315. current_thread_info()->status &= ~TS_POLLING;
  316. /*
  317. * TS_POLLING-cleared state must be visible before we
  318. * test NEED_RESCHED:
  319. */
  320. smp_mb();
  321. if (need_resched()) {
  322. current_thread_info()->status |= TS_POLLING;
  323. local_irq_enable();
  324. return;
  325. }
  326. }
  327. switch (cx->type) {
  328. case ACPI_STATE_C1:
  329. /*
  330. * Invoke C1.
  331. * Use the appropriate idle routine, the one that would
  332. * be used without acpi C-states.
  333. */
  334. if (pm_idle_save)
  335. pm_idle_save();
  336. else
  337. acpi_safe_halt();
  338. /*
  339. * TBD: Can't get time duration while in C1, as resumes
  340. * go to an ISR rather than here. Need to instrument
  341. * base interrupt handler.
  342. */
  343. sleep_ticks = 0xFFFFFFFF;
  344. break;
  345. case ACPI_STATE_C2:
  346. /* Get start time (ticks) */
  347. t1 = inl(acpi_fadt.xpm_timer_block.address);
  348. /* Invoke C2 */
  349. acpi_cstate_enter(cx);
  350. /* Get end time (ticks) */
  351. t2 = inl(acpi_fadt.xpm_timer_block.address);
  352. #ifdef CONFIG_GENERIC_TIME
  353. /* TSC halts in C2, so notify users */
  354. mark_tsc_unstable();
  355. #endif
  356. /* Re-enable interrupts */
  357. local_irq_enable();
  358. current_thread_info()->status |= TS_POLLING;
  359. /* Compute time (ticks) that we were actually asleep */
  360. sleep_ticks =
  361. ticks_elapsed(t1, t2) - cx->latency_ticks - C2_OVERHEAD;
  362. break;
  363. case ACPI_STATE_C3:
  364. if (pr->flags.bm_check) {
  365. if (atomic_inc_return(&c3_cpu_count) ==
  366. num_online_cpus()) {
  367. /*
  368. * All CPUs are trying to go to C3
  369. * Disable bus master arbitration
  370. */
  371. acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1,
  372. ACPI_MTX_DO_NOT_LOCK);
  373. }
  374. } else {
  375. /* SMP with no shared cache... Invalidate cache */
  376. ACPI_FLUSH_CPU_CACHE();
  377. }
  378. /* Get start time (ticks) */
  379. t1 = inl(acpi_fadt.xpm_timer_block.address);
  380. /* Invoke C3 */
  381. acpi_cstate_enter(cx);
  382. /* Get end time (ticks) */
  383. t2 = inl(acpi_fadt.xpm_timer_block.address);
  384. if (pr->flags.bm_check) {
  385. /* Enable bus master arbitration */
  386. atomic_dec(&c3_cpu_count);
  387. acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0,
  388. ACPI_MTX_DO_NOT_LOCK);
  389. }
  390. #ifdef CONFIG_GENERIC_TIME
  391. /* TSC halts in C3, so notify users */
  392. mark_tsc_unstable();
  393. #endif
  394. /* Re-enable interrupts */
  395. local_irq_enable();
  396. current_thread_info()->status |= TS_POLLING;
  397. /* Compute time (ticks) that we were actually asleep */
  398. sleep_ticks =
  399. ticks_elapsed(t1, t2) - cx->latency_ticks - C3_OVERHEAD;
  400. break;
  401. default:
  402. local_irq_enable();
  403. return;
  404. }
  405. cx->usage++;
  406. if ((cx->type != ACPI_STATE_C1) && (sleep_ticks > 0))
  407. cx->time += sleep_ticks;
  408. next_state = pr->power.state;
  409. #ifdef CONFIG_HOTPLUG_CPU
  410. /* Don't do promotion/demotion */
  411. if ((cx->type == ACPI_STATE_C1) && (num_online_cpus() > 1) &&
  412. !pr->flags.has_cst && !(acpi_fadt.flags & ACPI_FADT_C2_MP_SUPPORTED)) {
  413. next_state = cx;
  414. goto end;
  415. }
  416. #endif
  417. /*
  418. * Promotion?
  419. * ----------
  420. * Track the number of longs (time asleep is greater than threshold)
  421. * and promote when the count threshold is reached. Note that bus
  422. * mastering activity may prevent promotions.
  423. * Do not promote above max_cstate.
  424. */
  425. if (cx->promotion.state &&
  426. ((cx->promotion.state - pr->power.states) <= max_cstate)) {
  427. if (sleep_ticks > cx->promotion.threshold.ticks &&
  428. cx->promotion.state->latency <= system_latency_constraint()) {
  429. cx->promotion.count++;
  430. cx->demotion.count = 0;
  431. if (cx->promotion.count >=
  432. cx->promotion.threshold.count) {
  433. if (pr->flags.bm_check) {
  434. if (!
  435. (pr->power.bm_activity & cx->
  436. promotion.threshold.bm)) {
  437. next_state =
  438. cx->promotion.state;
  439. goto end;
  440. }
  441. } else {
  442. next_state = cx->promotion.state;
  443. goto end;
  444. }
  445. }
  446. }
  447. }
  448. /*
  449. * Demotion?
  450. * ---------
  451. * Track the number of shorts (time asleep is less than time threshold)
  452. * and demote when the usage threshold is reached.
  453. */
  454. if (cx->demotion.state) {
  455. if (sleep_ticks < cx->demotion.threshold.ticks) {
  456. cx->demotion.count++;
  457. cx->promotion.count = 0;
  458. if (cx->demotion.count >= cx->demotion.threshold.count) {
  459. next_state = cx->demotion.state;
  460. goto end;
  461. }
  462. }
  463. }
  464. end:
  465. /*
  466. * Demote if current state exceeds max_cstate
  467. * or if the latency of the current state is unacceptable
  468. */
  469. if ((pr->power.state - pr->power.states) > max_cstate ||
  470. pr->power.state->latency > system_latency_constraint()) {
  471. if (cx->demotion.state)
  472. next_state = cx->demotion.state;
  473. }
  474. /*
  475. * New Cx State?
  476. * -------------
  477. * If we're going to start using a new Cx state we must clean up
  478. * from the previous and prepare to use the new.
  479. */
  480. if (next_state != pr->power.state)
  481. acpi_processor_power_activate(pr, next_state);
  482. }
  483. static int acpi_processor_set_power_policy(struct acpi_processor *pr)
  484. {
  485. unsigned int i;
  486. unsigned int state_is_set = 0;
  487. struct acpi_processor_cx *lower = NULL;
  488. struct acpi_processor_cx *higher = NULL;
  489. struct acpi_processor_cx *cx;
  490. if (!pr)
  491. return -EINVAL;
  492. /*
  493. * This function sets the default Cx state policy (OS idle handler).
  494. * Our scheme is to promote quickly to C2 but more conservatively
  495. * to C3. We're favoring C2 for its characteristics of low latency
  496. * (quick response), good power savings, and ability to allow bus
  497. * mastering activity. Note that the Cx state policy is completely
  498. * customizable and can be altered dynamically.
  499. */
  500. /* startup state */
  501. for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
  502. cx = &pr->power.states[i];
  503. if (!cx->valid)
  504. continue;
  505. if (!state_is_set)
  506. pr->power.state = cx;
  507. state_is_set++;
  508. break;
  509. }
  510. if (!state_is_set)
  511. return -ENODEV;
  512. /* demotion */
  513. for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
  514. cx = &pr->power.states[i];
  515. if (!cx->valid)
  516. continue;
  517. if (lower) {
  518. cx->demotion.state = lower;
  519. cx->demotion.threshold.ticks = cx->latency_ticks;
  520. cx->demotion.threshold.count = 1;
  521. if (cx->type == ACPI_STATE_C3)
  522. cx->demotion.threshold.bm = bm_history;
  523. }
  524. lower = cx;
  525. }
  526. /* promotion */
  527. for (i = (ACPI_PROCESSOR_MAX_POWER - 1); i > 0; i--) {
  528. cx = &pr->power.states[i];
  529. if (!cx->valid)
  530. continue;
  531. if (higher) {
  532. cx->promotion.state = higher;
  533. cx->promotion.threshold.ticks = cx->latency_ticks;
  534. if (cx->type >= ACPI_STATE_C2)
  535. cx->promotion.threshold.count = 4;
  536. else
  537. cx->promotion.threshold.count = 10;
  538. if (higher->type == ACPI_STATE_C3)
  539. cx->promotion.threshold.bm = bm_history;
  540. }
  541. higher = cx;
  542. }
  543. return 0;
  544. }
  545. static int acpi_processor_get_power_info_fadt(struct acpi_processor *pr)
  546. {
  547. if (!pr)
  548. return -EINVAL;
  549. if (!pr->pblk)
  550. return -ENODEV;
  551. /* if info is obtained from pblk/fadt, type equals state */
  552. pr->power.states[ACPI_STATE_C2].type = ACPI_STATE_C2;
  553. pr->power.states[ACPI_STATE_C3].type = ACPI_STATE_C3;
  554. #ifndef CONFIG_HOTPLUG_CPU
  555. /*
  556. * Check for P_LVL2_UP flag before entering C2 and above on
  557. * an SMP system.
  558. */
  559. if ((num_online_cpus() > 1) &&
  560. !(acpi_fadt.flags & ACPI_FADT_C2_MP_SUPPORTED))
  561. return -ENODEV;
  562. #endif
  563. /* determine C2 and C3 address from pblk */
  564. pr->power.states[ACPI_STATE_C2].address = pr->pblk + 4;
  565. pr->power.states[ACPI_STATE_C3].address = pr->pblk + 5;
  566. /* determine latencies from FADT */
  567. pr->power.states[ACPI_STATE_C2].latency = acpi_fadt.C2latency;
  568. pr->power.states[ACPI_STATE_C3].latency = acpi_fadt.C3latency;
  569. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  570. "lvl2[0x%08x] lvl3[0x%08x]\n",
  571. pr->power.states[ACPI_STATE_C2].address,
  572. pr->power.states[ACPI_STATE_C3].address));
  573. return 0;
  574. }
  575. static int acpi_processor_get_power_info_default(struct acpi_processor *pr)
  576. {
  577. if (!pr->power.states[ACPI_STATE_C1].valid) {
  578. /* set the first C-State to C1 */
  579. /* all processors need to support C1 */
  580. pr->power.states[ACPI_STATE_C1].type = ACPI_STATE_C1;
  581. pr->power.states[ACPI_STATE_C1].valid = 1;
  582. }
  583. /* the C0 state only exists as a filler in our array */
  584. pr->power.states[ACPI_STATE_C0].valid = 1;
  585. return 0;
  586. }
  587. static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
  588. {
  589. acpi_status status = 0;
  590. acpi_integer count;
  591. int current_count;
  592. int i;
  593. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  594. union acpi_object *cst;
  595. if (nocst)
  596. return -ENODEV;
  597. current_count = 0;
  598. status = acpi_evaluate_object(pr->handle, "_CST", NULL, &buffer);
  599. if (ACPI_FAILURE(status)) {
  600. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No _CST, giving up\n"));
  601. return -ENODEV;
  602. }
  603. cst = buffer.pointer;
  604. /* There must be at least 2 elements */
  605. if (!cst || (cst->type != ACPI_TYPE_PACKAGE) || cst->package.count < 2) {
  606. printk(KERN_ERR PREFIX "not enough elements in _CST\n");
  607. status = -EFAULT;
  608. goto end;
  609. }
  610. count = cst->package.elements[0].integer.value;
  611. /* Validate number of power states. */
  612. if (count < 1 || count != cst->package.count - 1) {
  613. printk(KERN_ERR PREFIX "count given by _CST is not valid\n");
  614. status = -EFAULT;
  615. goto end;
  616. }
  617. /* Tell driver that at least _CST is supported. */
  618. pr->flags.has_cst = 1;
  619. for (i = 1; i <= count; i++) {
  620. union acpi_object *element;
  621. union acpi_object *obj;
  622. struct acpi_power_register *reg;
  623. struct acpi_processor_cx cx;
  624. memset(&cx, 0, sizeof(cx));
  625. element = &(cst->package.elements[i]);
  626. if (element->type != ACPI_TYPE_PACKAGE)
  627. continue;
  628. if (element->package.count != 4)
  629. continue;
  630. obj = &(element->package.elements[0]);
  631. if (obj->type != ACPI_TYPE_BUFFER)
  632. continue;
  633. reg = (struct acpi_power_register *)obj->buffer.pointer;
  634. if (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO &&
  635. (reg->space_id != ACPI_ADR_SPACE_FIXED_HARDWARE))
  636. continue;
  637. /* There should be an easy way to extract an integer... */
  638. obj = &(element->package.elements[1]);
  639. if (obj->type != ACPI_TYPE_INTEGER)
  640. continue;
  641. cx.type = obj->integer.value;
  642. /*
  643. * Some buggy BIOSes won't list C1 in _CST -
  644. * Let acpi_processor_get_power_info_default() handle them later
  645. */
  646. if (i == 1 && cx.type != ACPI_STATE_C1)
  647. current_count++;
  648. cx.address = reg->address;
  649. cx.index = current_count + 1;
  650. cx.space_id = ACPI_CSTATE_SYSTEMIO;
  651. if (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) {
  652. if (acpi_processor_ffh_cstate_probe
  653. (pr->id, &cx, reg) == 0) {
  654. cx.space_id = ACPI_CSTATE_FFH;
  655. } else if (cx.type != ACPI_STATE_C1) {
  656. /*
  657. * C1 is a special case where FIXED_HARDWARE
  658. * can be handled in non-MWAIT way as well.
  659. * In that case, save this _CST entry info.
  660. * That is, we retain space_id of SYSTEM_IO for
  661. * halt based C1.
  662. * Otherwise, ignore this info and continue.
  663. */
  664. continue;
  665. }
  666. }
  667. obj = &(element->package.elements[2]);
  668. if (obj->type != ACPI_TYPE_INTEGER)
  669. continue;
  670. cx.latency = obj->integer.value;
  671. obj = &(element->package.elements[3]);
  672. if (obj->type != ACPI_TYPE_INTEGER)
  673. continue;
  674. cx.power = obj->integer.value;
  675. current_count++;
  676. memcpy(&(pr->power.states[current_count]), &cx, sizeof(cx));
  677. /*
  678. * We support total ACPI_PROCESSOR_MAX_POWER - 1
  679. * (From 1 through ACPI_PROCESSOR_MAX_POWER - 1)
  680. */
  681. if (current_count >= (ACPI_PROCESSOR_MAX_POWER - 1)) {
  682. printk(KERN_WARNING
  683. "Limiting number of power states to max (%d)\n",
  684. ACPI_PROCESSOR_MAX_POWER);
  685. printk(KERN_WARNING
  686. "Please increase ACPI_PROCESSOR_MAX_POWER if needed.\n");
  687. break;
  688. }
  689. }
  690. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d power states\n",
  691. current_count));
  692. /* Validate number of power states discovered */
  693. if (current_count < 2)
  694. status = -EFAULT;
  695. end:
  696. kfree(buffer.pointer);
  697. return status;
  698. }
  699. static void acpi_processor_power_verify_c2(struct acpi_processor_cx *cx)
  700. {
  701. if (!cx->address)
  702. return;
  703. /*
  704. * C2 latency must be less than or equal to 100
  705. * microseconds.
  706. */
  707. else if (cx->latency > ACPI_PROCESSOR_MAX_C2_LATENCY) {
  708. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  709. "latency too large [%d]\n", cx->latency));
  710. return;
  711. }
  712. /*
  713. * Otherwise we've met all of our C2 requirements.
  714. * Normalize the C2 latency to expidite policy
  715. */
  716. cx->valid = 1;
  717. cx->latency_ticks = US_TO_PM_TIMER_TICKS(cx->latency);
  718. return;
  719. }
  720. static void acpi_processor_power_verify_c3(struct acpi_processor *pr,
  721. struct acpi_processor_cx *cx)
  722. {
  723. static int bm_check_flag;
  724. if (!cx->address)
  725. return;
  726. /*
  727. * C3 latency must be less than or equal to 1000
  728. * microseconds.
  729. */
  730. else if (cx->latency > ACPI_PROCESSOR_MAX_C3_LATENCY) {
  731. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  732. "latency too large [%d]\n", cx->latency));
  733. return;
  734. }
  735. /*
  736. * PIIX4 Erratum #18: We don't support C3 when Type-F (fast)
  737. * DMA transfers are used by any ISA device to avoid livelock.
  738. * Note that we could disable Type-F DMA (as recommended by
  739. * the erratum), but this is known to disrupt certain ISA
  740. * devices thus we take the conservative approach.
  741. */
  742. else if (errata.piix4.fdma) {
  743. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  744. "C3 not supported on PIIX4 with Type-F DMA\n"));
  745. return;
  746. }
  747. /* All the logic here assumes flags.bm_check is same across all CPUs */
  748. if (!bm_check_flag) {
  749. /* Determine whether bm_check is needed based on CPU */
  750. acpi_processor_power_init_bm_check(&(pr->flags), pr->id);
  751. bm_check_flag = pr->flags.bm_check;
  752. } else {
  753. pr->flags.bm_check = bm_check_flag;
  754. }
  755. if (pr->flags.bm_check) {
  756. /* bus mastering control is necessary */
  757. if (!pr->flags.bm_control) {
  758. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  759. "C3 support requires bus mastering control\n"));
  760. return;
  761. }
  762. } else {
  763. /*
  764. * WBINVD should be set in fadt, for C3 state to be
  765. * supported on when bm_check is not required.
  766. */
  767. if (!(acpi_fadt.flags & ACPI_FADT_WBINVD)) {
  768. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  769. "Cache invalidation should work properly"
  770. " for C3 to be enabled on SMP systems\n"));
  771. return;
  772. }
  773. acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD,
  774. 0, ACPI_MTX_DO_NOT_LOCK);
  775. }
  776. /*
  777. * Otherwise we've met all of our C3 requirements.
  778. * Normalize the C3 latency to expidite policy. Enable
  779. * checking of bus mastering status (bm_check) so we can
  780. * use this in our C3 policy
  781. */
  782. cx->valid = 1;
  783. cx->latency_ticks = US_TO_PM_TIMER_TICKS(cx->latency);
  784. return;
  785. }
  786. static int acpi_processor_power_verify(struct acpi_processor *pr)
  787. {
  788. unsigned int i;
  789. unsigned int working = 0;
  790. #ifdef ARCH_APICTIMER_STOPS_ON_C3
  791. int timer_broadcast = 0;
  792. cpumask_t mask = cpumask_of_cpu(pr->id);
  793. on_each_cpu(switch_ipi_to_APIC_timer, &mask, 1, 1);
  794. #endif
  795. for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
  796. struct acpi_processor_cx *cx = &pr->power.states[i];
  797. switch (cx->type) {
  798. case ACPI_STATE_C1:
  799. cx->valid = 1;
  800. break;
  801. case ACPI_STATE_C2:
  802. acpi_processor_power_verify_c2(cx);
  803. #ifdef ARCH_APICTIMER_STOPS_ON_C3
  804. /* Some AMD systems fake C3 as C2, but still
  805. have timer troubles */
  806. if (cx->valid &&
  807. boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
  808. timer_broadcast++;
  809. #endif
  810. break;
  811. case ACPI_STATE_C3:
  812. acpi_processor_power_verify_c3(pr, cx);
  813. #ifdef ARCH_APICTIMER_STOPS_ON_C3
  814. if (cx->valid)
  815. timer_broadcast++;
  816. #endif
  817. break;
  818. }
  819. if (cx->valid)
  820. working++;
  821. }
  822. #ifdef ARCH_APICTIMER_STOPS_ON_C3
  823. if (timer_broadcast)
  824. on_each_cpu(switch_APIC_timer_to_ipi, &mask, 1, 1);
  825. #endif
  826. return (working);
  827. }
  828. static int acpi_processor_get_power_info(struct acpi_processor *pr)
  829. {
  830. unsigned int i;
  831. int result;
  832. /* NOTE: the idle thread may not be running while calling
  833. * this function */
  834. /* Zero initialize all the C-states info. */
  835. memset(pr->power.states, 0, sizeof(pr->power.states));
  836. result = acpi_processor_get_power_info_cst(pr);
  837. if (result == -ENODEV)
  838. result = acpi_processor_get_power_info_fadt(pr);
  839. if (result)
  840. return result;
  841. acpi_processor_get_power_info_default(pr);
  842. pr->power.count = acpi_processor_power_verify(pr);
  843. /*
  844. * Set Default Policy
  845. * ------------------
  846. * Now that we know which states are supported, set the default
  847. * policy. Note that this policy can be changed dynamically
  848. * (e.g. encourage deeper sleeps to conserve battery life when
  849. * not on AC).
  850. */
  851. result = acpi_processor_set_power_policy(pr);
  852. if (result)
  853. return result;
  854. /*
  855. * if one state of type C2 or C3 is available, mark this
  856. * CPU as being "idle manageable"
  857. */
  858. for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
  859. if (pr->power.states[i].valid) {
  860. pr->power.count = i;
  861. if (pr->power.states[i].type >= ACPI_STATE_C2)
  862. pr->flags.power = 1;
  863. }
  864. }
  865. return 0;
  866. }
  867. int acpi_processor_cst_has_changed(struct acpi_processor *pr)
  868. {
  869. int result = 0;
  870. if (!pr)
  871. return -EINVAL;
  872. if (nocst) {
  873. return -ENODEV;
  874. }
  875. if (!pr->flags.power_setup_done)
  876. return -ENODEV;
  877. /* Fall back to the default idle loop */
  878. pm_idle = pm_idle_save;
  879. synchronize_sched(); /* Relies on interrupts forcing exit from idle. */
  880. pr->flags.power = 0;
  881. result = acpi_processor_get_power_info(pr);
  882. if ((pr->flags.power == 1) && (pr->flags.power_setup_done))
  883. pm_idle = acpi_processor_idle;
  884. return result;
  885. }
  886. /* proc interface */
  887. static int acpi_processor_power_seq_show(struct seq_file *seq, void *offset)
  888. {
  889. struct acpi_processor *pr = seq->private;
  890. unsigned int i;
  891. if (!pr)
  892. goto end;
  893. seq_printf(seq, "active state: C%zd\n"
  894. "max_cstate: C%d\n"
  895. "bus master activity: %08x\n"
  896. "maximum allowed latency: %d usec\n",
  897. pr->power.state ? pr->power.state - pr->power.states : 0,
  898. max_cstate, (unsigned)pr->power.bm_activity,
  899. system_latency_constraint());
  900. seq_puts(seq, "states:\n");
  901. for (i = 1; i <= pr->power.count; i++) {
  902. seq_printf(seq, " %cC%d: ",
  903. (&pr->power.states[i] ==
  904. pr->power.state ? '*' : ' '), i);
  905. if (!pr->power.states[i].valid) {
  906. seq_puts(seq, "<not supported>\n");
  907. continue;
  908. }
  909. switch (pr->power.states[i].type) {
  910. case ACPI_STATE_C1:
  911. seq_printf(seq, "type[C1] ");
  912. break;
  913. case ACPI_STATE_C2:
  914. seq_printf(seq, "type[C2] ");
  915. break;
  916. case ACPI_STATE_C3:
  917. seq_printf(seq, "type[C3] ");
  918. break;
  919. default:
  920. seq_printf(seq, "type[--] ");
  921. break;
  922. }
  923. if (pr->power.states[i].promotion.state)
  924. seq_printf(seq, "promotion[C%zd] ",
  925. (pr->power.states[i].promotion.state -
  926. pr->power.states));
  927. else
  928. seq_puts(seq, "promotion[--] ");
  929. if (pr->power.states[i].demotion.state)
  930. seq_printf(seq, "demotion[C%zd] ",
  931. (pr->power.states[i].demotion.state -
  932. pr->power.states));
  933. else
  934. seq_puts(seq, "demotion[--] ");
  935. seq_printf(seq, "latency[%03d] usage[%08d] duration[%020llu]\n",
  936. pr->power.states[i].latency,
  937. pr->power.states[i].usage,
  938. pr->power.states[i].time);
  939. }
  940. end:
  941. return 0;
  942. }
  943. static int acpi_processor_power_open_fs(struct inode *inode, struct file *file)
  944. {
  945. return single_open(file, acpi_processor_power_seq_show,
  946. PDE(inode)->data);
  947. }
  948. static const struct file_operations acpi_processor_power_fops = {
  949. .open = acpi_processor_power_open_fs,
  950. .read = seq_read,
  951. .llseek = seq_lseek,
  952. .release = single_release,
  953. };
  954. #ifdef CONFIG_SMP
  955. static void smp_callback(void *v)
  956. {
  957. /* we already woke the CPU up, nothing more to do */
  958. }
  959. /*
  960. * This function gets called when a part of the kernel has a new latency
  961. * requirement. This means we need to get all processors out of their C-state,
  962. * and then recalculate a new suitable C-state. Just do a cross-cpu IPI; that
  963. * wakes them all right up.
  964. */
  965. static int acpi_processor_latency_notify(struct notifier_block *b,
  966. unsigned long l, void *v)
  967. {
  968. smp_call_function(smp_callback, NULL, 0, 1);
  969. return NOTIFY_OK;
  970. }
  971. static struct notifier_block acpi_processor_latency_notifier = {
  972. .notifier_call = acpi_processor_latency_notify,
  973. };
  974. #endif
  975. int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
  976. struct acpi_device *device)
  977. {
  978. acpi_status status = 0;
  979. static int first_run;
  980. struct proc_dir_entry *entry = NULL;
  981. unsigned int i;
  982. if (!first_run) {
  983. dmi_check_system(processor_power_dmi_table);
  984. if (max_cstate < ACPI_C_STATES_MAX)
  985. printk(KERN_NOTICE
  986. "ACPI: processor limited to max C-state %d\n",
  987. max_cstate);
  988. first_run++;
  989. #ifdef CONFIG_SMP
  990. register_latency_notifier(&acpi_processor_latency_notifier);
  991. #endif
  992. }
  993. if (!pr)
  994. return -EINVAL;
  995. if (acpi_fadt.cst_control && !nocst) {
  996. status =
  997. acpi_os_write_port(acpi_fadt.smi_command, acpi_fadt.cst_control, 8);
  998. if (ACPI_FAILURE(status)) {
  999. ACPI_EXCEPTION((AE_INFO, status,
  1000. "Notifying BIOS of _CST ability failed"));
  1001. }
  1002. }
  1003. acpi_processor_get_power_info(pr);
  1004. /*
  1005. * Install the idle handler if processor power management is supported.
  1006. * Note that we use previously set idle handler will be used on
  1007. * platforms that only support C1.
  1008. */
  1009. if ((pr->flags.power) && (!boot_option_idle_override)) {
  1010. printk(KERN_INFO PREFIX "CPU%d (power states:", pr->id);
  1011. for (i = 1; i <= pr->power.count; i++)
  1012. if (pr->power.states[i].valid)
  1013. printk(" C%d[C%d]", i,
  1014. pr->power.states[i].type);
  1015. printk(")\n");
  1016. if (pr->id == 0) {
  1017. pm_idle_save = pm_idle;
  1018. pm_idle = acpi_processor_idle;
  1019. }
  1020. }
  1021. /* 'power' [R] */
  1022. entry = create_proc_entry(ACPI_PROCESSOR_FILE_POWER,
  1023. S_IRUGO, acpi_device_dir(device));
  1024. if (!entry)
  1025. return -EIO;
  1026. else {
  1027. entry->proc_fops = &acpi_processor_power_fops;
  1028. entry->data = acpi_driver_data(device);
  1029. entry->owner = THIS_MODULE;
  1030. }
  1031. pr->flags.power_setup_done = 1;
  1032. return 0;
  1033. }
  1034. int acpi_processor_power_exit(struct acpi_processor *pr,
  1035. struct acpi_device *device)
  1036. {
  1037. pr->flags.power_setup_done = 0;
  1038. if (acpi_device_dir(device))
  1039. remove_proc_entry(ACPI_PROCESSOR_FILE_POWER,
  1040. acpi_device_dir(device));
  1041. /* Unregister the idle handler when processor #0 is removed. */
  1042. if (pr->id == 0) {
  1043. pm_idle = pm_idle_save;
  1044. /*
  1045. * We are about to unload the current idle thread pm callback
  1046. * (pm_idle), Wait for all processors to update cached/local
  1047. * copies of pm_idle before proceeding.
  1048. */
  1049. cpu_idle_wait();
  1050. #ifdef CONFIG_SMP
  1051. unregister_latency_notifier(&acpi_processor_latency_notifier);
  1052. #endif
  1053. }
  1054. return 0;
  1055. }