intel_idle.c 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * intel_idle.c - native hardware idle loop for modern Intel processors
  4. *
  5. * Copyright (c) 2013 - 2020, Intel Corporation.
  6. * Len Brown <len.brown@intel.com>
  7. * Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  8. */
  9. /*
  10. * intel_idle is a cpuidle driver that loads on all Intel CPUs with MWAIT
  11. * in lieu of the legacy ACPI processor_idle driver. The intent is to
  12. * make Linux more efficient on these processors, as intel_idle knows
  13. * more than ACPI, as well as make Linux more immune to ACPI BIOS bugs.
  14. */
  15. /*
  16. * Design Assumptions
  17. *
  18. * All CPUs have same idle states as boot CPU
  19. *
  20. * Chipset BM_STS (bus master status) bit is a NOP
  21. * for preventing entry into deep C-states
  22. *
  23. * CPU will flush caches as needed when entering a C-state via MWAIT
  24. * (in contrast to entering ACPI C3, in which case the WBINVD
  25. * instruction needs to be executed to flush the caches)
  26. */
  27. /*
  28. * Known limitations
  29. *
  30. * ACPI has a .suspend hack to turn off deep c-statees during suspend
  31. * to avoid complications with the lapic timer workaround.
  32. * Have not seen issues with suspend, but may need same workaround here.
  33. *
  34. */
  35. /* un-comment DEBUG to enable pr_debug() statements */
  36. /* #define DEBUG */
  37. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  38. #include <linux/acpi.h>
  39. #include <linux/kernel.h>
  40. #include <linux/cpuidle.h>
  41. #include <linux/tick.h>
  42. #include <linux/time64.h>
  43. #include <trace/events/power.h>
  44. #include <linux/sched.h>
  45. #include <linux/sched/smt.h>
  46. #include <linux/mutex.h>
  47. #include <linux/notifier.h>
  48. #include <linux/cpu.h>
  49. #include <linux/moduleparam.h>
  50. #include <linux/sysfs.h>
  51. #include <asm/cpuid/api.h>
  52. #include <asm/cpu_device_id.h>
  53. #include <asm/intel-family.h>
  54. #include <asm/mwait.h>
  55. #include <asm/spec-ctrl.h>
  56. #include <asm/msr.h>
  57. #include <asm/tsc.h>
  58. #include <asm/fpu/api.h>
  59. #include <asm/smp.h>
  60. static struct cpuidle_driver intel_idle_driver = {
  61. .name = "intel_idle",
  62. .owner = THIS_MODULE,
  63. };
  64. /* intel_idle.max_cstate=0 disables driver */
  65. static int max_cstate = CPUIDLE_STATE_MAX - 1;
  66. static unsigned int disabled_states_mask __read_mostly;
  67. static bool force_irq_on __read_mostly;
  68. static bool ibrs_off __read_mostly;
  69. /* The maximum allowed length for the 'table' module parameter */
  70. #define MAX_CMDLINE_TABLE_LEN 256
  71. /* Maximum allowed C-state latency */
  72. #define MAX_CMDLINE_LATENCY_US (5 * USEC_PER_MSEC)
  73. /* Maximum allowed C-state target residency */
  74. #define MAX_CMDLINE_RESIDENCY_US (100 * USEC_PER_MSEC)
  75. static char cmdline_table_str[MAX_CMDLINE_TABLE_LEN] __read_mostly;
  76. static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;
  77. static unsigned long auto_demotion_disable_flags;
  78. static enum {
  79. C1E_PROMOTION_PRESERVE,
  80. C1E_PROMOTION_ENABLE,
  81. C1E_PROMOTION_DISABLE
  82. } c1e_promotion = C1E_PROMOTION_PRESERVE;
  83. struct idle_cpu {
  84. struct cpuidle_state *state_table;
  85. /*
  86. * Hardware C-state auto-demotion may not always be optimal.
  87. * Indicate which enable bits to clear here.
  88. */
  89. unsigned long auto_demotion_disable_flags;
  90. bool disable_promotion_to_c1e;
  91. bool c1_demotion_supported;
  92. bool use_acpi;
  93. };
  94. static bool c1_demotion_supported;
  95. static DEFINE_MUTEX(c1_demotion_mutex);
  96. static struct device *sysfs_root __initdata;
  97. static const struct idle_cpu *icpu __initdata;
  98. static struct cpuidle_state *cpuidle_state_table __initdata;
  99. /* C-states data from the 'intel_idle.table' cmdline parameter */
  100. static struct cpuidle_state cmdline_states[CPUIDLE_STATE_MAX] __initdata;
  101. static unsigned int mwait_substates __initdata;
  102. /*
  103. * Enable interrupts before entering the C-state. On some platforms and for
  104. * some C-states, this may measurably decrease interrupt latency.
  105. */
  106. #define CPUIDLE_FLAG_IRQ_ENABLE BIT(14)
  107. /*
  108. * Enable this state by default even if the ACPI _CST does not list it.
  109. */
  110. #define CPUIDLE_FLAG_ALWAYS_ENABLE BIT(15)
  111. /*
  112. * Disable IBRS across idle (when KERNEL_IBRS), is exclusive vs IRQ_ENABLE
  113. * above.
  114. */
  115. #define CPUIDLE_FLAG_IBRS BIT(16)
  116. /*
  117. * Initialize large xstate for the C6-state entrance.
  118. */
  119. #define CPUIDLE_FLAG_INIT_XSTATE BIT(17)
  120. /*
  121. * Ignore the sub-state when matching mwait hints between the ACPI _CST and
  122. * custom tables.
  123. */
  124. #define CPUIDLE_FLAG_PARTIAL_HINT_MATCH BIT(18)
  125. /*
  126. * MWAIT takes an 8-bit "hint" in EAX "suggesting"
  127. * the C-state (top nibble) and sub-state (bottom nibble)
  128. * 0x00 means "MWAIT(C1)", 0x10 means "MWAIT(C2)" etc.
  129. *
  130. * We store the hint at the top of our "flags" for each state.
  131. */
  132. #define flg2MWAIT(flags) (((flags) >> 24) & 0xFF)
  133. #define MWAIT2flg(eax) ((eax & 0xFF) << 24)
  134. static __always_inline int __intel_idle(struct cpuidle_device *dev,
  135. struct cpuidle_driver *drv,
  136. int index, bool irqoff)
  137. {
  138. struct cpuidle_state *state = &drv->states[index];
  139. unsigned int eax = flg2MWAIT(state->flags);
  140. unsigned int ecx = 1*irqoff; /* break on interrupt flag */
  141. mwait_idle_with_hints(eax, ecx);
  142. return index;
  143. }
  144. /**
  145. * intel_idle - Ask the processor to enter the given idle state.
  146. * @dev: cpuidle device of the target CPU.
  147. * @drv: cpuidle driver (assumed to point to intel_idle_driver).
  148. * @index: Target idle state index.
  149. *
  150. * Use the MWAIT instruction to notify the processor that the CPU represented by
  151. * @dev is idle and it can try to enter the idle state corresponding to @index.
  152. *
  153. * If the local APIC timer is not known to be reliable in the target idle state,
  154. * enable one-shot tick broadcasting for the target CPU before executing MWAIT.
  155. *
  156. * Must be called under local_irq_disable().
  157. */
  158. static __cpuidle int intel_idle(struct cpuidle_device *dev,
  159. struct cpuidle_driver *drv, int index)
  160. {
  161. return __intel_idle(dev, drv, index, true);
  162. }
  163. static __cpuidle int intel_idle_irq(struct cpuidle_device *dev,
  164. struct cpuidle_driver *drv, int index)
  165. {
  166. return __intel_idle(dev, drv, index, false);
  167. }
  168. static __cpuidle int intel_idle_ibrs(struct cpuidle_device *dev,
  169. struct cpuidle_driver *drv, int index)
  170. {
  171. bool smt_active = sched_smt_active();
  172. u64 spec_ctrl = spec_ctrl_current();
  173. int ret;
  174. if (smt_active)
  175. __update_spec_ctrl(0);
  176. ret = __intel_idle(dev, drv, index, true);
  177. if (smt_active)
  178. __update_spec_ctrl(spec_ctrl);
  179. return ret;
  180. }
  181. static __cpuidle int intel_idle_xstate(struct cpuidle_device *dev,
  182. struct cpuidle_driver *drv, int index)
  183. {
  184. fpu_idle_fpregs();
  185. return __intel_idle(dev, drv, index, true);
  186. }
  187. /**
  188. * intel_idle_s2idle - Ask the processor to enter the given idle state.
  189. * @dev: cpuidle device of the target CPU.
  190. * @drv: cpuidle driver (assumed to point to intel_idle_driver).
  191. * @index: Target idle state index.
  192. *
  193. * Use the MWAIT instruction to notify the processor that the CPU represented by
  194. * @dev is idle and it can try to enter the idle state corresponding to @index.
  195. *
  196. * Invoked as a suspend-to-idle callback routine with frozen user space, frozen
  197. * scheduler tick and suspended scheduler clock on the target CPU.
  198. */
  199. static __cpuidle int intel_idle_s2idle(struct cpuidle_device *dev,
  200. struct cpuidle_driver *drv, int index)
  201. {
  202. struct cpuidle_state *state = &drv->states[index];
  203. unsigned int eax = flg2MWAIT(state->flags);
  204. unsigned int ecx = 1; /* break on interrupt flag */
  205. if (state->flags & CPUIDLE_FLAG_INIT_XSTATE)
  206. fpu_idle_fpregs();
  207. mwait_idle_with_hints(eax, ecx);
  208. return 0;
  209. }
  210. static void intel_idle_enter_dead(struct cpuidle_device *dev, int index)
  211. {
  212. struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
  213. struct cpuidle_state *state = &drv->states[index];
  214. unsigned long eax = flg2MWAIT(state->flags);
  215. mwait_play_dead(eax);
  216. }
  217. /*
  218. * States are indexed by the cstate number,
  219. * which is also the index into the MWAIT hint array.
  220. * Thus C0 is a dummy.
  221. */
  222. static struct cpuidle_state nehalem_cstates[] __initdata = {
  223. {
  224. .name = "C1",
  225. .desc = "MWAIT 0x00",
  226. .flags = MWAIT2flg(0x00),
  227. .exit_latency = 3,
  228. .target_residency = 6,
  229. .enter = intel_idle,
  230. .enter_s2idle = intel_idle_s2idle, },
  231. {
  232. .name = "C1E",
  233. .desc = "MWAIT 0x01",
  234. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  235. .exit_latency = 10,
  236. .target_residency = 20,
  237. .enter = intel_idle,
  238. .enter_s2idle = intel_idle_s2idle, },
  239. {
  240. .name = "C3",
  241. .desc = "MWAIT 0x10",
  242. .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
  243. .exit_latency = 20,
  244. .target_residency = 80,
  245. .enter = intel_idle,
  246. .enter_s2idle = intel_idle_s2idle, },
  247. {
  248. .name = "C6",
  249. .desc = "MWAIT 0x20",
  250. .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
  251. .exit_latency = 200,
  252. .target_residency = 800,
  253. .enter = intel_idle,
  254. .enter_s2idle = intel_idle_s2idle, },
  255. {
  256. .enter = NULL }
  257. };
  258. static struct cpuidle_state snb_cstates[] __initdata = {
  259. {
  260. .name = "C1",
  261. .desc = "MWAIT 0x00",
  262. .flags = MWAIT2flg(0x00),
  263. .exit_latency = 2,
  264. .target_residency = 2,
  265. .enter = intel_idle,
  266. .enter_s2idle = intel_idle_s2idle, },
  267. {
  268. .name = "C1E",
  269. .desc = "MWAIT 0x01",
  270. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  271. .exit_latency = 10,
  272. .target_residency = 20,
  273. .enter = intel_idle,
  274. .enter_s2idle = intel_idle_s2idle, },
  275. {
  276. .name = "C3",
  277. .desc = "MWAIT 0x10",
  278. .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
  279. .exit_latency = 80,
  280. .target_residency = 211,
  281. .enter = intel_idle,
  282. .enter_s2idle = intel_idle_s2idle, },
  283. {
  284. .name = "C6",
  285. .desc = "MWAIT 0x20",
  286. .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
  287. .exit_latency = 104,
  288. .target_residency = 345,
  289. .enter = intel_idle,
  290. .enter_s2idle = intel_idle_s2idle, },
  291. {
  292. .name = "C7",
  293. .desc = "MWAIT 0x30",
  294. .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
  295. .exit_latency = 109,
  296. .target_residency = 345,
  297. .enter = intel_idle,
  298. .enter_s2idle = intel_idle_s2idle, },
  299. {
  300. .enter = NULL }
  301. };
  302. static struct cpuidle_state byt_cstates[] __initdata = {
  303. {
  304. .name = "C1",
  305. .desc = "MWAIT 0x00",
  306. .flags = MWAIT2flg(0x00),
  307. .exit_latency = 1,
  308. .target_residency = 1,
  309. .enter = intel_idle,
  310. .enter_s2idle = intel_idle_s2idle, },
  311. {
  312. .name = "C6N",
  313. .desc = "MWAIT 0x58",
  314. .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED,
  315. .exit_latency = 300,
  316. .target_residency = 275,
  317. .enter = intel_idle,
  318. .enter_s2idle = intel_idle_s2idle, },
  319. {
  320. .name = "C6S",
  321. .desc = "MWAIT 0x52",
  322. .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
  323. .exit_latency = 500,
  324. .target_residency = 560,
  325. .enter = intel_idle,
  326. .enter_s2idle = intel_idle_s2idle, },
  327. {
  328. .name = "C7",
  329. .desc = "MWAIT 0x60",
  330. .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
  331. .exit_latency = 1200,
  332. .target_residency = 4000,
  333. .enter = intel_idle,
  334. .enter_s2idle = intel_idle_s2idle, },
  335. {
  336. .name = "C7S",
  337. .desc = "MWAIT 0x64",
  338. .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
  339. .exit_latency = 10000,
  340. .target_residency = 20000,
  341. .enter = intel_idle,
  342. .enter_s2idle = intel_idle_s2idle, },
  343. {
  344. .enter = NULL }
  345. };
  346. static struct cpuidle_state cht_cstates[] __initdata = {
  347. {
  348. .name = "C1",
  349. .desc = "MWAIT 0x00",
  350. .flags = MWAIT2flg(0x00),
  351. .exit_latency = 1,
  352. .target_residency = 1,
  353. .enter = intel_idle,
  354. .enter_s2idle = intel_idle_s2idle, },
  355. {
  356. .name = "C6N",
  357. .desc = "MWAIT 0x58",
  358. .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED,
  359. .exit_latency = 80,
  360. .target_residency = 275,
  361. .enter = intel_idle,
  362. .enter_s2idle = intel_idle_s2idle, },
  363. {
  364. .name = "C6S",
  365. .desc = "MWAIT 0x52",
  366. .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
  367. .exit_latency = 200,
  368. .target_residency = 560,
  369. .enter = intel_idle,
  370. .enter_s2idle = intel_idle_s2idle, },
  371. {
  372. .name = "C7",
  373. .desc = "MWAIT 0x60",
  374. .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
  375. .exit_latency = 1200,
  376. .target_residency = 4000,
  377. .enter = intel_idle,
  378. .enter_s2idle = intel_idle_s2idle, },
  379. {
  380. .name = "C7S",
  381. .desc = "MWAIT 0x64",
  382. .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
  383. .exit_latency = 10000,
  384. .target_residency = 20000,
  385. .enter = intel_idle,
  386. .enter_s2idle = intel_idle_s2idle, },
  387. {
  388. .enter = NULL }
  389. };
  390. static struct cpuidle_state ivb_cstates[] __initdata = {
  391. {
  392. .name = "C1",
  393. .desc = "MWAIT 0x00",
  394. .flags = MWAIT2flg(0x00),
  395. .exit_latency = 1,
  396. .target_residency = 1,
  397. .enter = intel_idle,
  398. .enter_s2idle = intel_idle_s2idle, },
  399. {
  400. .name = "C1E",
  401. .desc = "MWAIT 0x01",
  402. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  403. .exit_latency = 10,
  404. .target_residency = 20,
  405. .enter = intel_idle,
  406. .enter_s2idle = intel_idle_s2idle, },
  407. {
  408. .name = "C3",
  409. .desc = "MWAIT 0x10",
  410. .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
  411. .exit_latency = 59,
  412. .target_residency = 156,
  413. .enter = intel_idle,
  414. .enter_s2idle = intel_idle_s2idle, },
  415. {
  416. .name = "C6",
  417. .desc = "MWAIT 0x20",
  418. .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
  419. .exit_latency = 80,
  420. .target_residency = 300,
  421. .enter = intel_idle,
  422. .enter_s2idle = intel_idle_s2idle, },
  423. {
  424. .name = "C7",
  425. .desc = "MWAIT 0x30",
  426. .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
  427. .exit_latency = 87,
  428. .target_residency = 300,
  429. .enter = intel_idle,
  430. .enter_s2idle = intel_idle_s2idle, },
  431. {
  432. .enter = NULL }
  433. };
  434. static struct cpuidle_state ivt_cstates[] __initdata = {
  435. {
  436. .name = "C1",
  437. .desc = "MWAIT 0x00",
  438. .flags = MWAIT2flg(0x00),
  439. .exit_latency = 1,
  440. .target_residency = 1,
  441. .enter = intel_idle,
  442. .enter_s2idle = intel_idle_s2idle, },
  443. {
  444. .name = "C1E",
  445. .desc = "MWAIT 0x01",
  446. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  447. .exit_latency = 10,
  448. .target_residency = 80,
  449. .enter = intel_idle,
  450. .enter_s2idle = intel_idle_s2idle, },
  451. {
  452. .name = "C3",
  453. .desc = "MWAIT 0x10",
  454. .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
  455. .exit_latency = 59,
  456. .target_residency = 156,
  457. .enter = intel_idle,
  458. .enter_s2idle = intel_idle_s2idle, },
  459. {
  460. .name = "C6",
  461. .desc = "MWAIT 0x20",
  462. .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
  463. .exit_latency = 82,
  464. .target_residency = 300,
  465. .enter = intel_idle,
  466. .enter_s2idle = intel_idle_s2idle, },
  467. {
  468. .enter = NULL }
  469. };
  470. static struct cpuidle_state ivt_cstates_4s[] __initdata = {
  471. {
  472. .name = "C1",
  473. .desc = "MWAIT 0x00",
  474. .flags = MWAIT2flg(0x00),
  475. .exit_latency = 1,
  476. .target_residency = 1,
  477. .enter = intel_idle,
  478. .enter_s2idle = intel_idle_s2idle, },
  479. {
  480. .name = "C1E",
  481. .desc = "MWAIT 0x01",
  482. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  483. .exit_latency = 10,
  484. .target_residency = 250,
  485. .enter = intel_idle,
  486. .enter_s2idle = intel_idle_s2idle, },
  487. {
  488. .name = "C3",
  489. .desc = "MWAIT 0x10",
  490. .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
  491. .exit_latency = 59,
  492. .target_residency = 300,
  493. .enter = intel_idle,
  494. .enter_s2idle = intel_idle_s2idle, },
  495. {
  496. .name = "C6",
  497. .desc = "MWAIT 0x20",
  498. .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
  499. .exit_latency = 84,
  500. .target_residency = 400,
  501. .enter = intel_idle,
  502. .enter_s2idle = intel_idle_s2idle, },
  503. {
  504. .enter = NULL }
  505. };
  506. static struct cpuidle_state ivt_cstates_8s[] __initdata = {
  507. {
  508. .name = "C1",
  509. .desc = "MWAIT 0x00",
  510. .flags = MWAIT2flg(0x00),
  511. .exit_latency = 1,
  512. .target_residency = 1,
  513. .enter = intel_idle,
  514. .enter_s2idle = intel_idle_s2idle, },
  515. {
  516. .name = "C1E",
  517. .desc = "MWAIT 0x01",
  518. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  519. .exit_latency = 10,
  520. .target_residency = 500,
  521. .enter = intel_idle,
  522. .enter_s2idle = intel_idle_s2idle, },
  523. {
  524. .name = "C3",
  525. .desc = "MWAIT 0x10",
  526. .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
  527. .exit_latency = 59,
  528. .target_residency = 600,
  529. .enter = intel_idle,
  530. .enter_s2idle = intel_idle_s2idle, },
  531. {
  532. .name = "C6",
  533. .desc = "MWAIT 0x20",
  534. .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
  535. .exit_latency = 88,
  536. .target_residency = 700,
  537. .enter = intel_idle,
  538. .enter_s2idle = intel_idle_s2idle, },
  539. {
  540. .enter = NULL }
  541. };
  542. static struct cpuidle_state hsw_cstates[] __initdata = {
  543. {
  544. .name = "C1",
  545. .desc = "MWAIT 0x00",
  546. .flags = MWAIT2flg(0x00),
  547. .exit_latency = 2,
  548. .target_residency = 2,
  549. .enter = intel_idle,
  550. .enter_s2idle = intel_idle_s2idle, },
  551. {
  552. .name = "C1E",
  553. .desc = "MWAIT 0x01",
  554. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  555. .exit_latency = 10,
  556. .target_residency = 20,
  557. .enter = intel_idle,
  558. .enter_s2idle = intel_idle_s2idle, },
  559. {
  560. .name = "C3",
  561. .desc = "MWAIT 0x10",
  562. .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
  563. .exit_latency = 33,
  564. .target_residency = 100,
  565. .enter = intel_idle,
  566. .enter_s2idle = intel_idle_s2idle, },
  567. {
  568. .name = "C6",
  569. .desc = "MWAIT 0x20",
  570. .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
  571. .exit_latency = 133,
  572. .target_residency = 400,
  573. .enter = intel_idle,
  574. .enter_s2idle = intel_idle_s2idle, },
  575. {
  576. .name = "C7s",
  577. .desc = "MWAIT 0x32",
  578. .flags = MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED,
  579. .exit_latency = 166,
  580. .target_residency = 500,
  581. .enter = intel_idle,
  582. .enter_s2idle = intel_idle_s2idle, },
  583. {
  584. .name = "C8",
  585. .desc = "MWAIT 0x40",
  586. .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
  587. .exit_latency = 300,
  588. .target_residency = 900,
  589. .enter = intel_idle,
  590. .enter_s2idle = intel_idle_s2idle, },
  591. {
  592. .name = "C9",
  593. .desc = "MWAIT 0x50",
  594. .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
  595. .exit_latency = 600,
  596. .target_residency = 1800,
  597. .enter = intel_idle,
  598. .enter_s2idle = intel_idle_s2idle, },
  599. {
  600. .name = "C10",
  601. .desc = "MWAIT 0x60",
  602. .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
  603. .exit_latency = 2600,
  604. .target_residency = 7700,
  605. .enter = intel_idle,
  606. .enter_s2idle = intel_idle_s2idle, },
  607. {
  608. .enter = NULL }
  609. };
  610. static struct cpuidle_state bdw_cstates[] __initdata = {
  611. {
  612. .name = "C1",
  613. .desc = "MWAIT 0x00",
  614. .flags = MWAIT2flg(0x00),
  615. .exit_latency = 2,
  616. .target_residency = 2,
  617. .enter = intel_idle,
  618. .enter_s2idle = intel_idle_s2idle, },
  619. {
  620. .name = "C1E",
  621. .desc = "MWAIT 0x01",
  622. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  623. .exit_latency = 10,
  624. .target_residency = 20,
  625. .enter = intel_idle,
  626. .enter_s2idle = intel_idle_s2idle, },
  627. {
  628. .name = "C3",
  629. .desc = "MWAIT 0x10",
  630. .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
  631. .exit_latency = 40,
  632. .target_residency = 100,
  633. .enter = intel_idle,
  634. .enter_s2idle = intel_idle_s2idle, },
  635. {
  636. .name = "C6",
  637. .desc = "MWAIT 0x20",
  638. .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
  639. .exit_latency = 133,
  640. .target_residency = 400,
  641. .enter = intel_idle,
  642. .enter_s2idle = intel_idle_s2idle, },
  643. {
  644. .name = "C7s",
  645. .desc = "MWAIT 0x32",
  646. .flags = MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED,
  647. .exit_latency = 166,
  648. .target_residency = 500,
  649. .enter = intel_idle,
  650. .enter_s2idle = intel_idle_s2idle, },
  651. {
  652. .name = "C8",
  653. .desc = "MWAIT 0x40",
  654. .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
  655. .exit_latency = 300,
  656. .target_residency = 900,
  657. .enter = intel_idle,
  658. .enter_s2idle = intel_idle_s2idle, },
  659. {
  660. .name = "C9",
  661. .desc = "MWAIT 0x50",
  662. .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
  663. .exit_latency = 600,
  664. .target_residency = 1800,
  665. .enter = intel_idle,
  666. .enter_s2idle = intel_idle_s2idle, },
  667. {
  668. .name = "C10",
  669. .desc = "MWAIT 0x60",
  670. .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
  671. .exit_latency = 2600,
  672. .target_residency = 7700,
  673. .enter = intel_idle,
  674. .enter_s2idle = intel_idle_s2idle, },
  675. {
  676. .enter = NULL }
  677. };
  678. static struct cpuidle_state skl_cstates[] __initdata = {
  679. {
  680. .name = "C1",
  681. .desc = "MWAIT 0x00",
  682. .flags = MWAIT2flg(0x00),
  683. .exit_latency = 2,
  684. .target_residency = 2,
  685. .enter = intel_idle,
  686. .enter_s2idle = intel_idle_s2idle, },
  687. {
  688. .name = "C1E",
  689. .desc = "MWAIT 0x01",
  690. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  691. .exit_latency = 10,
  692. .target_residency = 20,
  693. .enter = intel_idle,
  694. .enter_s2idle = intel_idle_s2idle, },
  695. {
  696. .name = "C3",
  697. .desc = "MWAIT 0x10",
  698. .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
  699. .exit_latency = 70,
  700. .target_residency = 100,
  701. .enter = intel_idle,
  702. .enter_s2idle = intel_idle_s2idle, },
  703. {
  704. .name = "C6",
  705. .desc = "MWAIT 0x20",
  706. .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED | CPUIDLE_FLAG_IBRS,
  707. .exit_latency = 85,
  708. .target_residency = 200,
  709. .enter = intel_idle,
  710. .enter_s2idle = intel_idle_s2idle, },
  711. {
  712. .name = "C7s",
  713. .desc = "MWAIT 0x33",
  714. .flags = MWAIT2flg(0x33) | CPUIDLE_FLAG_TLB_FLUSHED | CPUIDLE_FLAG_IBRS,
  715. .exit_latency = 124,
  716. .target_residency = 800,
  717. .enter = intel_idle,
  718. .enter_s2idle = intel_idle_s2idle, },
  719. {
  720. .name = "C8",
  721. .desc = "MWAIT 0x40",
  722. .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED | CPUIDLE_FLAG_IBRS,
  723. .exit_latency = 200,
  724. .target_residency = 800,
  725. .enter = intel_idle,
  726. .enter_s2idle = intel_idle_s2idle, },
  727. {
  728. .name = "C9",
  729. .desc = "MWAIT 0x50",
  730. .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED | CPUIDLE_FLAG_IBRS,
  731. .exit_latency = 480,
  732. .target_residency = 5000,
  733. .enter = intel_idle,
  734. .enter_s2idle = intel_idle_s2idle, },
  735. {
  736. .name = "C10",
  737. .desc = "MWAIT 0x60",
  738. .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED | CPUIDLE_FLAG_IBRS,
  739. .exit_latency = 890,
  740. .target_residency = 5000,
  741. .enter = intel_idle,
  742. .enter_s2idle = intel_idle_s2idle, },
  743. {
  744. .enter = NULL }
  745. };
  746. static struct cpuidle_state skx_cstates[] __initdata = {
  747. {
  748. .name = "C1",
  749. .desc = "MWAIT 0x00",
  750. .flags = MWAIT2flg(0x00) | CPUIDLE_FLAG_IRQ_ENABLE,
  751. .exit_latency = 2,
  752. .target_residency = 2,
  753. .enter = intel_idle,
  754. .enter_s2idle = intel_idle_s2idle, },
  755. {
  756. .name = "C1E",
  757. .desc = "MWAIT 0x01",
  758. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  759. .exit_latency = 10,
  760. .target_residency = 20,
  761. .enter = intel_idle,
  762. .enter_s2idle = intel_idle_s2idle, },
  763. {
  764. .name = "C6",
  765. .desc = "MWAIT 0x20",
  766. .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED | CPUIDLE_FLAG_IBRS,
  767. .exit_latency = 133,
  768. .target_residency = 600,
  769. .enter = intel_idle,
  770. .enter_s2idle = intel_idle_s2idle, },
  771. {
  772. .enter = NULL }
  773. };
  774. static struct cpuidle_state icx_cstates[] __initdata = {
  775. {
  776. .name = "C1",
  777. .desc = "MWAIT 0x00",
  778. .flags = MWAIT2flg(0x00) | CPUIDLE_FLAG_IRQ_ENABLE,
  779. .exit_latency = 1,
  780. .target_residency = 1,
  781. .enter = intel_idle,
  782. .enter_s2idle = intel_idle_s2idle, },
  783. {
  784. .name = "C1E",
  785. .desc = "MWAIT 0x01",
  786. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  787. .exit_latency = 4,
  788. .target_residency = 4,
  789. .enter = intel_idle,
  790. .enter_s2idle = intel_idle_s2idle, },
  791. {
  792. .name = "C6",
  793. .desc = "MWAIT 0x20",
  794. .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
  795. .exit_latency = 170,
  796. .target_residency = 600,
  797. .enter = intel_idle,
  798. .enter_s2idle = intel_idle_s2idle, },
  799. {
  800. .enter = NULL }
  801. };
  802. /*
  803. * On AlderLake C1 has to be disabled if C1E is enabled, and vice versa.
  804. * C1E is enabled only if "C1E promotion" bit is set in MSR_IA32_POWER_CTL.
  805. * But in this case there is effectively no C1, because C1 requests are
  806. * promoted to C1E. If the "C1E promotion" bit is cleared, then both C1
  807. * and C1E requests end up with C1, so there is effectively no C1E.
  808. *
  809. * By default we enable C1E and disable C1 by marking it with
  810. * 'CPUIDLE_FLAG_UNUSABLE'.
  811. */
  812. static struct cpuidle_state adl_cstates[] __initdata = {
  813. {
  814. .name = "C1",
  815. .desc = "MWAIT 0x00",
  816. .flags = MWAIT2flg(0x00) | CPUIDLE_FLAG_UNUSABLE,
  817. .exit_latency = 1,
  818. .target_residency = 1,
  819. .enter = intel_idle,
  820. .enter_s2idle = intel_idle_s2idle, },
  821. {
  822. .name = "C1E",
  823. .desc = "MWAIT 0x01",
  824. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  825. .exit_latency = 2,
  826. .target_residency = 4,
  827. .enter = intel_idle,
  828. .enter_s2idle = intel_idle_s2idle, },
  829. {
  830. .name = "C6",
  831. .desc = "MWAIT 0x20",
  832. .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
  833. .exit_latency = 220,
  834. .target_residency = 600,
  835. .enter = intel_idle,
  836. .enter_s2idle = intel_idle_s2idle, },
  837. {
  838. .name = "C8",
  839. .desc = "MWAIT 0x40",
  840. .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
  841. .exit_latency = 280,
  842. .target_residency = 800,
  843. .enter = intel_idle,
  844. .enter_s2idle = intel_idle_s2idle, },
  845. {
  846. .name = "C10",
  847. .desc = "MWAIT 0x60",
  848. .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
  849. .exit_latency = 680,
  850. .target_residency = 2000,
  851. .enter = intel_idle,
  852. .enter_s2idle = intel_idle_s2idle, },
  853. {
  854. .enter = NULL }
  855. };
  856. static struct cpuidle_state adl_l_cstates[] __initdata = {
  857. {
  858. .name = "C1",
  859. .desc = "MWAIT 0x00",
  860. .flags = MWAIT2flg(0x00) | CPUIDLE_FLAG_UNUSABLE,
  861. .exit_latency = 1,
  862. .target_residency = 1,
  863. .enter = intel_idle,
  864. .enter_s2idle = intel_idle_s2idle, },
  865. {
  866. .name = "C1E",
  867. .desc = "MWAIT 0x01",
  868. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  869. .exit_latency = 2,
  870. .target_residency = 4,
  871. .enter = intel_idle,
  872. .enter_s2idle = intel_idle_s2idle, },
  873. {
  874. .name = "C6",
  875. .desc = "MWAIT 0x20",
  876. .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
  877. .exit_latency = 170,
  878. .target_residency = 500,
  879. .enter = intel_idle,
  880. .enter_s2idle = intel_idle_s2idle, },
  881. {
  882. .name = "C8",
  883. .desc = "MWAIT 0x40",
  884. .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
  885. .exit_latency = 200,
  886. .target_residency = 600,
  887. .enter = intel_idle,
  888. .enter_s2idle = intel_idle_s2idle, },
  889. {
  890. .name = "C10",
  891. .desc = "MWAIT 0x60",
  892. .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
  893. .exit_latency = 230,
  894. .target_residency = 700,
  895. .enter = intel_idle,
  896. .enter_s2idle = intel_idle_s2idle, },
  897. {
  898. .enter = NULL }
  899. };
  900. static struct cpuidle_state mtl_l_cstates[] __initdata = {
  901. {
  902. .name = "C1E",
  903. .desc = "MWAIT 0x01",
  904. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  905. .exit_latency = 1,
  906. .target_residency = 1,
  907. .enter = intel_idle,
  908. .enter_s2idle = intel_idle_s2idle, },
  909. {
  910. .name = "C6",
  911. .desc = "MWAIT 0x20",
  912. .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
  913. .exit_latency = 140,
  914. .target_residency = 420,
  915. .enter = intel_idle,
  916. .enter_s2idle = intel_idle_s2idle, },
  917. {
  918. .name = "C10",
  919. .desc = "MWAIT 0x60",
  920. .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
  921. .exit_latency = 310,
  922. .target_residency = 930,
  923. .enter = intel_idle,
  924. .enter_s2idle = intel_idle_s2idle, },
  925. {
  926. .enter = NULL }
  927. };
  928. static struct cpuidle_state gmt_cstates[] __initdata = {
  929. {
  930. .name = "C1",
  931. .desc = "MWAIT 0x00",
  932. .flags = MWAIT2flg(0x00) | CPUIDLE_FLAG_UNUSABLE,
  933. .exit_latency = 1,
  934. .target_residency = 1,
  935. .enter = intel_idle,
  936. .enter_s2idle = intel_idle_s2idle, },
  937. {
  938. .name = "C1E",
  939. .desc = "MWAIT 0x01",
  940. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  941. .exit_latency = 2,
  942. .target_residency = 4,
  943. .enter = intel_idle,
  944. .enter_s2idle = intel_idle_s2idle, },
  945. {
  946. .name = "C6",
  947. .desc = "MWAIT 0x20",
  948. .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
  949. .exit_latency = 195,
  950. .target_residency = 585,
  951. .enter = intel_idle,
  952. .enter_s2idle = intel_idle_s2idle, },
  953. {
  954. .name = "C8",
  955. .desc = "MWAIT 0x40",
  956. .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
  957. .exit_latency = 260,
  958. .target_residency = 1040,
  959. .enter = intel_idle,
  960. .enter_s2idle = intel_idle_s2idle, },
  961. {
  962. .name = "C10",
  963. .desc = "MWAIT 0x60",
  964. .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
  965. .exit_latency = 660,
  966. .target_residency = 1980,
  967. .enter = intel_idle,
  968. .enter_s2idle = intel_idle_s2idle, },
  969. {
  970. .enter = NULL }
  971. };
  972. static struct cpuidle_state spr_cstates[] __initdata = {
  973. {
  974. .name = "C1",
  975. .desc = "MWAIT 0x00",
  976. .flags = MWAIT2flg(0x00),
  977. .exit_latency = 1,
  978. .target_residency = 1,
  979. .enter = intel_idle,
  980. .enter_s2idle = intel_idle_s2idle, },
  981. {
  982. .name = "C1E",
  983. .desc = "MWAIT 0x01",
  984. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  985. .exit_latency = 2,
  986. .target_residency = 4,
  987. .enter = intel_idle,
  988. .enter_s2idle = intel_idle_s2idle, },
  989. {
  990. .name = "C6",
  991. .desc = "MWAIT 0x20",
  992. .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED |
  993. CPUIDLE_FLAG_INIT_XSTATE,
  994. .exit_latency = 290,
  995. .target_residency = 800,
  996. .enter = intel_idle,
  997. .enter_s2idle = intel_idle_s2idle, },
  998. {
  999. .enter = NULL }
  1000. };
  1001. static struct cpuidle_state gnr_cstates[] __initdata = {
  1002. {
  1003. .name = "C1",
  1004. .desc = "MWAIT 0x00",
  1005. .flags = MWAIT2flg(0x00),
  1006. .exit_latency = 1,
  1007. .target_residency = 1,
  1008. .enter = intel_idle,
  1009. .enter_s2idle = intel_idle_s2idle, },
  1010. {
  1011. .name = "C1E",
  1012. .desc = "MWAIT 0x01",
  1013. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  1014. .exit_latency = 4,
  1015. .target_residency = 4,
  1016. .enter = intel_idle,
  1017. .enter_s2idle = intel_idle_s2idle, },
  1018. {
  1019. .name = "C6",
  1020. .desc = "MWAIT 0x20",
  1021. .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED |
  1022. CPUIDLE_FLAG_INIT_XSTATE |
  1023. CPUIDLE_FLAG_PARTIAL_HINT_MATCH,
  1024. .exit_latency = 170,
  1025. .target_residency = 650,
  1026. .enter = intel_idle,
  1027. .enter_s2idle = intel_idle_s2idle, },
  1028. {
  1029. .name = "C6P",
  1030. .desc = "MWAIT 0x21",
  1031. .flags = MWAIT2flg(0x21) | CPUIDLE_FLAG_TLB_FLUSHED |
  1032. CPUIDLE_FLAG_INIT_XSTATE |
  1033. CPUIDLE_FLAG_PARTIAL_HINT_MATCH,
  1034. .exit_latency = 210,
  1035. .target_residency = 1000,
  1036. .enter = intel_idle,
  1037. .enter_s2idle = intel_idle_s2idle, },
  1038. {
  1039. .enter = NULL }
  1040. };
  1041. static struct cpuidle_state gnrd_cstates[] __initdata = {
  1042. {
  1043. .name = "C1",
  1044. .desc = "MWAIT 0x00",
  1045. .flags = MWAIT2flg(0x00),
  1046. .exit_latency = 1,
  1047. .target_residency = 1,
  1048. .enter = intel_idle,
  1049. .enter_s2idle = intel_idle_s2idle, },
  1050. {
  1051. .name = "C1E",
  1052. .desc = "MWAIT 0x01",
  1053. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  1054. .exit_latency = 4,
  1055. .target_residency = 4,
  1056. .enter = intel_idle,
  1057. .enter_s2idle = intel_idle_s2idle, },
  1058. {
  1059. .name = "C6",
  1060. .desc = "MWAIT 0x20",
  1061. .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED |
  1062. CPUIDLE_FLAG_INIT_XSTATE |
  1063. CPUIDLE_FLAG_PARTIAL_HINT_MATCH,
  1064. .exit_latency = 220,
  1065. .target_residency = 650,
  1066. .enter = intel_idle,
  1067. .enter_s2idle = intel_idle_s2idle, },
  1068. {
  1069. .name = "C6P",
  1070. .desc = "MWAIT 0x21",
  1071. .flags = MWAIT2flg(0x21) | CPUIDLE_FLAG_TLB_FLUSHED |
  1072. CPUIDLE_FLAG_INIT_XSTATE |
  1073. CPUIDLE_FLAG_PARTIAL_HINT_MATCH,
  1074. .exit_latency = 240,
  1075. .target_residency = 750,
  1076. .enter = intel_idle,
  1077. .enter_s2idle = intel_idle_s2idle, },
  1078. {
  1079. .enter = NULL }
  1080. };
  1081. static struct cpuidle_state atom_cstates[] __initdata = {
  1082. {
  1083. .name = "C1E",
  1084. .desc = "MWAIT 0x00",
  1085. .flags = MWAIT2flg(0x00),
  1086. .exit_latency = 10,
  1087. .target_residency = 20,
  1088. .enter = intel_idle,
  1089. .enter_s2idle = intel_idle_s2idle, },
  1090. {
  1091. .name = "C2",
  1092. .desc = "MWAIT 0x10",
  1093. .flags = MWAIT2flg(0x10),
  1094. .exit_latency = 20,
  1095. .target_residency = 80,
  1096. .enter = intel_idle,
  1097. .enter_s2idle = intel_idle_s2idle, },
  1098. {
  1099. .name = "C4",
  1100. .desc = "MWAIT 0x30",
  1101. .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
  1102. .exit_latency = 100,
  1103. .target_residency = 400,
  1104. .enter = intel_idle,
  1105. .enter_s2idle = intel_idle_s2idle, },
  1106. {
  1107. .name = "C6",
  1108. .desc = "MWAIT 0x52",
  1109. .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
  1110. .exit_latency = 140,
  1111. .target_residency = 560,
  1112. .enter = intel_idle,
  1113. .enter_s2idle = intel_idle_s2idle, },
  1114. {
  1115. .enter = NULL }
  1116. };
  1117. static struct cpuidle_state tangier_cstates[] __initdata = {
  1118. {
  1119. .name = "C1",
  1120. .desc = "MWAIT 0x00",
  1121. .flags = MWAIT2flg(0x00),
  1122. .exit_latency = 1,
  1123. .target_residency = 4,
  1124. .enter = intel_idle,
  1125. .enter_s2idle = intel_idle_s2idle, },
  1126. {
  1127. .name = "C4",
  1128. .desc = "MWAIT 0x30",
  1129. .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
  1130. .exit_latency = 100,
  1131. .target_residency = 400,
  1132. .enter = intel_idle,
  1133. .enter_s2idle = intel_idle_s2idle, },
  1134. {
  1135. .name = "C6",
  1136. .desc = "MWAIT 0x52",
  1137. .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
  1138. .exit_latency = 140,
  1139. .target_residency = 560,
  1140. .enter = intel_idle,
  1141. .enter_s2idle = intel_idle_s2idle, },
  1142. {
  1143. .name = "C7",
  1144. .desc = "MWAIT 0x60",
  1145. .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
  1146. .exit_latency = 1200,
  1147. .target_residency = 4000,
  1148. .enter = intel_idle,
  1149. .enter_s2idle = intel_idle_s2idle, },
  1150. {
  1151. .name = "C9",
  1152. .desc = "MWAIT 0x64",
  1153. .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
  1154. .exit_latency = 10000,
  1155. .target_residency = 20000,
  1156. .enter = intel_idle,
  1157. .enter_s2idle = intel_idle_s2idle, },
  1158. {
  1159. .enter = NULL }
  1160. };
  1161. static struct cpuidle_state avn_cstates[] __initdata = {
  1162. {
  1163. .name = "C1",
  1164. .desc = "MWAIT 0x00",
  1165. .flags = MWAIT2flg(0x00),
  1166. .exit_latency = 2,
  1167. .target_residency = 2,
  1168. .enter = intel_idle,
  1169. .enter_s2idle = intel_idle_s2idle, },
  1170. {
  1171. .name = "C6",
  1172. .desc = "MWAIT 0x51",
  1173. .flags = MWAIT2flg(0x51) | CPUIDLE_FLAG_TLB_FLUSHED,
  1174. .exit_latency = 15,
  1175. .target_residency = 45,
  1176. .enter = intel_idle,
  1177. .enter_s2idle = intel_idle_s2idle, },
  1178. {
  1179. .enter = NULL }
  1180. };
  1181. static struct cpuidle_state knl_cstates[] __initdata = {
  1182. {
  1183. .name = "C1",
  1184. .desc = "MWAIT 0x00",
  1185. .flags = MWAIT2flg(0x00),
  1186. .exit_latency = 1,
  1187. .target_residency = 2,
  1188. .enter = intel_idle,
  1189. .enter_s2idle = intel_idle_s2idle },
  1190. {
  1191. .name = "C6",
  1192. .desc = "MWAIT 0x10",
  1193. .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
  1194. .exit_latency = 120,
  1195. .target_residency = 500,
  1196. .enter = intel_idle,
  1197. .enter_s2idle = intel_idle_s2idle },
  1198. {
  1199. .enter = NULL }
  1200. };
  1201. static struct cpuidle_state bxt_cstates[] __initdata = {
  1202. {
  1203. .name = "C1",
  1204. .desc = "MWAIT 0x00",
  1205. .flags = MWAIT2flg(0x00),
  1206. .exit_latency = 2,
  1207. .target_residency = 2,
  1208. .enter = intel_idle,
  1209. .enter_s2idle = intel_idle_s2idle, },
  1210. {
  1211. .name = "C1E",
  1212. .desc = "MWAIT 0x01",
  1213. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  1214. .exit_latency = 10,
  1215. .target_residency = 20,
  1216. .enter = intel_idle,
  1217. .enter_s2idle = intel_idle_s2idle, },
  1218. {
  1219. .name = "C6",
  1220. .desc = "MWAIT 0x20",
  1221. .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
  1222. .exit_latency = 133,
  1223. .target_residency = 133,
  1224. .enter = intel_idle,
  1225. .enter_s2idle = intel_idle_s2idle, },
  1226. {
  1227. .name = "C7s",
  1228. .desc = "MWAIT 0x31",
  1229. .flags = MWAIT2flg(0x31) | CPUIDLE_FLAG_TLB_FLUSHED,
  1230. .exit_latency = 155,
  1231. .target_residency = 155,
  1232. .enter = intel_idle,
  1233. .enter_s2idle = intel_idle_s2idle, },
  1234. {
  1235. .name = "C8",
  1236. .desc = "MWAIT 0x40",
  1237. .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
  1238. .exit_latency = 1000,
  1239. .target_residency = 1000,
  1240. .enter = intel_idle,
  1241. .enter_s2idle = intel_idle_s2idle, },
  1242. {
  1243. .name = "C9",
  1244. .desc = "MWAIT 0x50",
  1245. .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
  1246. .exit_latency = 2000,
  1247. .target_residency = 2000,
  1248. .enter = intel_idle,
  1249. .enter_s2idle = intel_idle_s2idle, },
  1250. {
  1251. .name = "C10",
  1252. .desc = "MWAIT 0x60",
  1253. .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
  1254. .exit_latency = 10000,
  1255. .target_residency = 10000,
  1256. .enter = intel_idle,
  1257. .enter_s2idle = intel_idle_s2idle, },
  1258. {
  1259. .enter = NULL }
  1260. };
  1261. static struct cpuidle_state dnv_cstates[] __initdata = {
  1262. {
  1263. .name = "C1",
  1264. .desc = "MWAIT 0x00",
  1265. .flags = MWAIT2flg(0x00),
  1266. .exit_latency = 2,
  1267. .target_residency = 2,
  1268. .enter = intel_idle,
  1269. .enter_s2idle = intel_idle_s2idle, },
  1270. {
  1271. .name = "C1E",
  1272. .desc = "MWAIT 0x01",
  1273. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  1274. .exit_latency = 10,
  1275. .target_residency = 20,
  1276. .enter = intel_idle,
  1277. .enter_s2idle = intel_idle_s2idle, },
  1278. {
  1279. .name = "C6",
  1280. .desc = "MWAIT 0x20",
  1281. .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
  1282. .exit_latency = 50,
  1283. .target_residency = 500,
  1284. .enter = intel_idle,
  1285. .enter_s2idle = intel_idle_s2idle, },
  1286. {
  1287. .enter = NULL }
  1288. };
  1289. /*
  1290. * Note, depending on HW and FW revision, SnowRidge SoC may or may not support
  1291. * C6, and this is indicated in the CPUID mwait leaf.
  1292. */
  1293. static struct cpuidle_state snr_cstates[] __initdata = {
  1294. {
  1295. .name = "C1",
  1296. .desc = "MWAIT 0x00",
  1297. .flags = MWAIT2flg(0x00),
  1298. .exit_latency = 2,
  1299. .target_residency = 2,
  1300. .enter = intel_idle,
  1301. .enter_s2idle = intel_idle_s2idle, },
  1302. {
  1303. .name = "C1E",
  1304. .desc = "MWAIT 0x01",
  1305. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  1306. .exit_latency = 15,
  1307. .target_residency = 25,
  1308. .enter = intel_idle,
  1309. .enter_s2idle = intel_idle_s2idle, },
  1310. {
  1311. .name = "C6",
  1312. .desc = "MWAIT 0x20",
  1313. .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
  1314. .exit_latency = 130,
  1315. .target_residency = 500,
  1316. .enter = intel_idle,
  1317. .enter_s2idle = intel_idle_s2idle, },
  1318. {
  1319. .enter = NULL }
  1320. };
  1321. static struct cpuidle_state grr_cstates[] __initdata = {
  1322. {
  1323. .name = "C1",
  1324. .desc = "MWAIT 0x00",
  1325. .flags = MWAIT2flg(0x00) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  1326. .exit_latency = 1,
  1327. .target_residency = 1,
  1328. .enter = intel_idle,
  1329. .enter_s2idle = intel_idle_s2idle, },
  1330. {
  1331. .name = "C1E",
  1332. .desc = "MWAIT 0x01",
  1333. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  1334. .exit_latency = 2,
  1335. .target_residency = 10,
  1336. .enter = intel_idle,
  1337. .enter_s2idle = intel_idle_s2idle, },
  1338. {
  1339. .name = "C6S",
  1340. .desc = "MWAIT 0x22",
  1341. .flags = MWAIT2flg(0x22) | CPUIDLE_FLAG_TLB_FLUSHED,
  1342. .exit_latency = 140,
  1343. .target_residency = 500,
  1344. .enter = intel_idle,
  1345. .enter_s2idle = intel_idle_s2idle, },
  1346. {
  1347. .enter = NULL }
  1348. };
  1349. static struct cpuidle_state srf_cstates[] __initdata = {
  1350. {
  1351. .name = "C1",
  1352. .desc = "MWAIT 0x00",
  1353. .flags = MWAIT2flg(0x00) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  1354. .exit_latency = 1,
  1355. .target_residency = 1,
  1356. .enter = intel_idle,
  1357. .enter_s2idle = intel_idle_s2idle, },
  1358. {
  1359. .name = "C1E",
  1360. .desc = "MWAIT 0x01",
  1361. .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
  1362. .exit_latency = 2,
  1363. .target_residency = 10,
  1364. .enter = intel_idle,
  1365. .enter_s2idle = intel_idle_s2idle, },
  1366. {
  1367. .name = "C6S",
  1368. .desc = "MWAIT 0x22",
  1369. .flags = MWAIT2flg(0x22) | CPUIDLE_FLAG_TLB_FLUSHED |
  1370. CPUIDLE_FLAG_PARTIAL_HINT_MATCH,
  1371. .exit_latency = 270,
  1372. .target_residency = 700,
  1373. .enter = intel_idle,
  1374. .enter_s2idle = intel_idle_s2idle, },
  1375. {
  1376. .name = "C6SP",
  1377. .desc = "MWAIT 0x23",
  1378. .flags = MWAIT2flg(0x23) | CPUIDLE_FLAG_TLB_FLUSHED |
  1379. CPUIDLE_FLAG_PARTIAL_HINT_MATCH,
  1380. .exit_latency = 310,
  1381. .target_residency = 900,
  1382. .enter = intel_idle,
  1383. .enter_s2idle = intel_idle_s2idle, },
  1384. {
  1385. .enter = NULL }
  1386. };
  1387. static const struct idle_cpu idle_cpu_nehalem __initconst = {
  1388. .state_table = nehalem_cstates,
  1389. .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
  1390. .disable_promotion_to_c1e = true,
  1391. };
  1392. static const struct idle_cpu idle_cpu_nhx __initconst = {
  1393. .state_table = nehalem_cstates,
  1394. .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
  1395. .disable_promotion_to_c1e = true,
  1396. .use_acpi = true,
  1397. };
  1398. static const struct idle_cpu idle_cpu_atom __initconst = {
  1399. .state_table = atom_cstates,
  1400. };
  1401. static const struct idle_cpu idle_cpu_tangier __initconst = {
  1402. .state_table = tangier_cstates,
  1403. };
  1404. static const struct idle_cpu idle_cpu_lincroft __initconst = {
  1405. .state_table = atom_cstates,
  1406. .auto_demotion_disable_flags = ATM_LNC_C6_AUTO_DEMOTE,
  1407. };
  1408. static const struct idle_cpu idle_cpu_snb __initconst = {
  1409. .state_table = snb_cstates,
  1410. .disable_promotion_to_c1e = true,
  1411. };
  1412. static const struct idle_cpu idle_cpu_snx __initconst = {
  1413. .state_table = snb_cstates,
  1414. .disable_promotion_to_c1e = true,
  1415. .use_acpi = true,
  1416. };
  1417. static const struct idle_cpu idle_cpu_byt __initconst = {
  1418. .state_table = byt_cstates,
  1419. .disable_promotion_to_c1e = true,
  1420. };
  1421. static const struct idle_cpu idle_cpu_cht __initconst = {
  1422. .state_table = cht_cstates,
  1423. .disable_promotion_to_c1e = true,
  1424. };
  1425. static const struct idle_cpu idle_cpu_ivb __initconst = {
  1426. .state_table = ivb_cstates,
  1427. .disable_promotion_to_c1e = true,
  1428. };
  1429. static const struct idle_cpu idle_cpu_ivt __initconst = {
  1430. .state_table = ivt_cstates,
  1431. .disable_promotion_to_c1e = true,
  1432. .use_acpi = true,
  1433. };
  1434. static const struct idle_cpu idle_cpu_hsw __initconst = {
  1435. .state_table = hsw_cstates,
  1436. .disable_promotion_to_c1e = true,
  1437. };
  1438. static const struct idle_cpu idle_cpu_hsx __initconst = {
  1439. .state_table = hsw_cstates,
  1440. .disable_promotion_to_c1e = true,
  1441. .use_acpi = true,
  1442. };
  1443. static const struct idle_cpu idle_cpu_bdw __initconst = {
  1444. .state_table = bdw_cstates,
  1445. .disable_promotion_to_c1e = true,
  1446. };
  1447. static const struct idle_cpu idle_cpu_bdx __initconst = {
  1448. .state_table = bdw_cstates,
  1449. .disable_promotion_to_c1e = true,
  1450. .use_acpi = true,
  1451. };
  1452. static const struct idle_cpu idle_cpu_skl __initconst = {
  1453. .state_table = skl_cstates,
  1454. .disable_promotion_to_c1e = true,
  1455. };
  1456. static const struct idle_cpu idle_cpu_skx __initconst = {
  1457. .state_table = skx_cstates,
  1458. .disable_promotion_to_c1e = true,
  1459. .use_acpi = true,
  1460. };
  1461. static const struct idle_cpu idle_cpu_icx __initconst = {
  1462. .state_table = icx_cstates,
  1463. .disable_promotion_to_c1e = true,
  1464. .use_acpi = true,
  1465. };
  1466. static const struct idle_cpu idle_cpu_adl __initconst = {
  1467. .state_table = adl_cstates,
  1468. };
  1469. static const struct idle_cpu idle_cpu_adl_l __initconst = {
  1470. .state_table = adl_l_cstates,
  1471. };
  1472. static const struct idle_cpu idle_cpu_mtl_l __initconst = {
  1473. .state_table = mtl_l_cstates,
  1474. };
  1475. static const struct idle_cpu idle_cpu_gmt __initconst = {
  1476. .state_table = gmt_cstates,
  1477. };
  1478. static const struct idle_cpu idle_cpu_spr __initconst = {
  1479. .state_table = spr_cstates,
  1480. .disable_promotion_to_c1e = true,
  1481. .c1_demotion_supported = true,
  1482. .use_acpi = true,
  1483. };
  1484. static const struct idle_cpu idle_cpu_gnr __initconst = {
  1485. .state_table = gnr_cstates,
  1486. .disable_promotion_to_c1e = true,
  1487. .c1_demotion_supported = true,
  1488. .use_acpi = true,
  1489. };
  1490. static const struct idle_cpu idle_cpu_gnrd __initconst = {
  1491. .state_table = gnrd_cstates,
  1492. .disable_promotion_to_c1e = true,
  1493. .c1_demotion_supported = true,
  1494. .use_acpi = true,
  1495. };
  1496. static const struct idle_cpu idle_cpu_avn __initconst = {
  1497. .state_table = avn_cstates,
  1498. .disable_promotion_to_c1e = true,
  1499. .use_acpi = true,
  1500. };
  1501. static const struct idle_cpu idle_cpu_knl __initconst = {
  1502. .state_table = knl_cstates,
  1503. .use_acpi = true,
  1504. };
  1505. static const struct idle_cpu idle_cpu_bxt __initconst = {
  1506. .state_table = bxt_cstates,
  1507. .disable_promotion_to_c1e = true,
  1508. };
  1509. static const struct idle_cpu idle_cpu_dnv __initconst = {
  1510. .state_table = dnv_cstates,
  1511. .disable_promotion_to_c1e = true,
  1512. .use_acpi = true,
  1513. };
  1514. static const struct idle_cpu idle_cpu_tmt __initconst = {
  1515. .disable_promotion_to_c1e = true,
  1516. };
  1517. static const struct idle_cpu idle_cpu_snr __initconst = {
  1518. .state_table = snr_cstates,
  1519. .disable_promotion_to_c1e = true,
  1520. .use_acpi = true,
  1521. };
  1522. static const struct idle_cpu idle_cpu_grr __initconst = {
  1523. .state_table = grr_cstates,
  1524. .disable_promotion_to_c1e = true,
  1525. .c1_demotion_supported = true,
  1526. .use_acpi = true,
  1527. };
  1528. static const struct idle_cpu idle_cpu_srf __initconst = {
  1529. .state_table = srf_cstates,
  1530. .disable_promotion_to_c1e = true,
  1531. .c1_demotion_supported = true,
  1532. .use_acpi = true,
  1533. };
  1534. static const struct x86_cpu_id intel_idle_ids[] __initconst = {
  1535. X86_MATCH_VFM(INTEL_NEHALEM_EP, &idle_cpu_nhx),
  1536. X86_MATCH_VFM(INTEL_NEHALEM, &idle_cpu_nehalem),
  1537. X86_MATCH_VFM(INTEL_NEHALEM_G, &idle_cpu_nehalem),
  1538. X86_MATCH_VFM(INTEL_WESTMERE, &idle_cpu_nehalem),
  1539. X86_MATCH_VFM(INTEL_WESTMERE_EP, &idle_cpu_nhx),
  1540. X86_MATCH_VFM(INTEL_NEHALEM_EX, &idle_cpu_nhx),
  1541. X86_MATCH_VFM(INTEL_ATOM_BONNELL, &idle_cpu_atom),
  1542. X86_MATCH_VFM(INTEL_ATOM_BONNELL_MID, &idle_cpu_lincroft),
  1543. X86_MATCH_VFM(INTEL_WESTMERE_EX, &idle_cpu_nhx),
  1544. X86_MATCH_VFM(INTEL_SANDYBRIDGE, &idle_cpu_snb),
  1545. X86_MATCH_VFM(INTEL_SANDYBRIDGE_X, &idle_cpu_snx),
  1546. X86_MATCH_VFM(INTEL_ATOM_SALTWELL, &idle_cpu_atom),
  1547. X86_MATCH_VFM(INTEL_ATOM_SILVERMONT, &idle_cpu_byt),
  1548. X86_MATCH_VFM(INTEL_ATOM_SILVERMONT_MID, &idle_cpu_tangier),
  1549. X86_MATCH_VFM(INTEL_ATOM_AIRMONT, &idle_cpu_cht),
  1550. X86_MATCH_VFM(INTEL_IVYBRIDGE, &idle_cpu_ivb),
  1551. X86_MATCH_VFM(INTEL_IVYBRIDGE_X, &idle_cpu_ivt),
  1552. X86_MATCH_VFM(INTEL_HASWELL, &idle_cpu_hsw),
  1553. X86_MATCH_VFM(INTEL_HASWELL_X, &idle_cpu_hsx),
  1554. X86_MATCH_VFM(INTEL_HASWELL_L, &idle_cpu_hsw),
  1555. X86_MATCH_VFM(INTEL_HASWELL_G, &idle_cpu_hsw),
  1556. X86_MATCH_VFM(INTEL_ATOM_SILVERMONT_D, &idle_cpu_avn),
  1557. X86_MATCH_VFM(INTEL_BROADWELL, &idle_cpu_bdw),
  1558. X86_MATCH_VFM(INTEL_BROADWELL_G, &idle_cpu_bdw),
  1559. X86_MATCH_VFM(INTEL_BROADWELL_X, &idle_cpu_bdx),
  1560. X86_MATCH_VFM(INTEL_BROADWELL_D, &idle_cpu_bdx),
  1561. X86_MATCH_VFM(INTEL_SKYLAKE_L, &idle_cpu_skl),
  1562. X86_MATCH_VFM(INTEL_SKYLAKE, &idle_cpu_skl),
  1563. X86_MATCH_VFM(INTEL_KABYLAKE_L, &idle_cpu_skl),
  1564. X86_MATCH_VFM(INTEL_KABYLAKE, &idle_cpu_skl),
  1565. X86_MATCH_VFM(INTEL_SKYLAKE_X, &idle_cpu_skx),
  1566. X86_MATCH_VFM(INTEL_ICELAKE_X, &idle_cpu_icx),
  1567. X86_MATCH_VFM(INTEL_ICELAKE_D, &idle_cpu_icx),
  1568. X86_MATCH_VFM(INTEL_ALDERLAKE, &idle_cpu_adl),
  1569. X86_MATCH_VFM(INTEL_ALDERLAKE_L, &idle_cpu_adl_l),
  1570. X86_MATCH_VFM(INTEL_METEORLAKE_L, &idle_cpu_mtl_l),
  1571. X86_MATCH_VFM(INTEL_ATOM_GRACEMONT, &idle_cpu_gmt),
  1572. X86_MATCH_VFM(INTEL_SAPPHIRERAPIDS_X, &idle_cpu_spr),
  1573. X86_MATCH_VFM(INTEL_EMERALDRAPIDS_X, &idle_cpu_spr),
  1574. X86_MATCH_VFM(INTEL_GRANITERAPIDS_X, &idle_cpu_gnr),
  1575. X86_MATCH_VFM(INTEL_GRANITERAPIDS_D, &idle_cpu_gnrd),
  1576. X86_MATCH_VFM(INTEL_XEON_PHI_KNL, &idle_cpu_knl),
  1577. X86_MATCH_VFM(INTEL_XEON_PHI_KNM, &idle_cpu_knl),
  1578. X86_MATCH_VFM(INTEL_ATOM_GOLDMONT, &idle_cpu_bxt),
  1579. X86_MATCH_VFM(INTEL_ATOM_GOLDMONT_PLUS, &idle_cpu_bxt),
  1580. X86_MATCH_VFM(INTEL_ATOM_GOLDMONT_D, &idle_cpu_dnv),
  1581. X86_MATCH_VFM(INTEL_ATOM_TREMONT, &idle_cpu_tmt),
  1582. X86_MATCH_VFM(INTEL_ATOM_TREMONT_L, &idle_cpu_tmt),
  1583. X86_MATCH_VFM(INTEL_ATOM_TREMONT_D, &idle_cpu_snr),
  1584. X86_MATCH_VFM(INTEL_ATOM_CRESTMONT, &idle_cpu_grr),
  1585. X86_MATCH_VFM(INTEL_ATOM_CRESTMONT_X, &idle_cpu_srf),
  1586. X86_MATCH_VFM(INTEL_ATOM_DARKMONT_X, &idle_cpu_srf),
  1587. {}
  1588. };
  1589. static const struct x86_cpu_id intel_mwait_ids[] __initconst = {
  1590. X86_MATCH_VENDOR_FAM_FEATURE(INTEL, X86_FAMILY_ANY, X86_FEATURE_MWAIT, NULL),
  1591. {}
  1592. };
  1593. static bool __init intel_idle_max_cstate_reached(int cstate)
  1594. {
  1595. if (cstate + 1 > max_cstate) {
  1596. pr_info("max_cstate %d reached\n", max_cstate);
  1597. return true;
  1598. }
  1599. return false;
  1600. }
  1601. static bool __init intel_idle_state_needs_timer_stop(struct cpuidle_state *state)
  1602. {
  1603. unsigned long eax = flg2MWAIT(state->flags);
  1604. if (boot_cpu_has(X86_FEATURE_ARAT))
  1605. return false;
  1606. /*
  1607. * Switch over to one-shot tick broadcast if the target C-state
  1608. * is deeper than C1.
  1609. */
  1610. return !!((eax >> MWAIT_SUBSTATE_SIZE) & MWAIT_CSTATE_MASK);
  1611. }
  1612. #ifdef CONFIG_ACPI_PROCESSOR_CSTATE
  1613. #include <acpi/processor.h>
  1614. static bool no_acpi __read_mostly;
  1615. module_param(no_acpi, bool, 0444);
  1616. MODULE_PARM_DESC(no_acpi, "Do not use ACPI _CST for building the idle states list");
  1617. static bool force_use_acpi __read_mostly; /* No effect if no_acpi is set. */
  1618. module_param_named(use_acpi, force_use_acpi, bool, 0444);
  1619. MODULE_PARM_DESC(use_acpi, "Use ACPI _CST for building the idle states list");
  1620. static bool no_native __read_mostly; /* No effect if no_acpi is set. */
  1621. module_param_named(no_native, no_native, bool, 0444);
  1622. MODULE_PARM_DESC(no_native, "Ignore cpu specific (native) idle states in lieu of ACPI idle states");
  1623. static struct acpi_processor_power acpi_state_table __initdata;
  1624. /**
  1625. * intel_idle_cst_usable - Check if the _CST information can be used.
  1626. *
  1627. * Check if all of the C-states listed by _CST in the max_cstate range are
  1628. * ACPI_CSTATE_FFH, which means that they should be entered via MWAIT.
  1629. */
  1630. static bool __init intel_idle_cst_usable(void)
  1631. {
  1632. int cstate, limit;
  1633. limit = min_t(int, min_t(int, CPUIDLE_STATE_MAX, max_cstate + 1),
  1634. acpi_state_table.count);
  1635. for (cstate = 1; cstate < limit; cstate++) {
  1636. struct acpi_processor_cx *cx = &acpi_state_table.states[cstate];
  1637. if (cx->entry_method != ACPI_CSTATE_FFH)
  1638. return false;
  1639. }
  1640. return true;
  1641. }
  1642. static bool __init intel_idle_acpi_cst_extract(void)
  1643. {
  1644. unsigned int cpu;
  1645. if (no_acpi) {
  1646. pr_debug("Not allowed to use ACPI _CST\n");
  1647. return false;
  1648. }
  1649. for_each_possible_cpu(cpu) {
  1650. struct acpi_processor *pr = per_cpu(processors, cpu);
  1651. if (!pr)
  1652. continue;
  1653. if (acpi_processor_evaluate_cst(pr->handle, cpu, &acpi_state_table))
  1654. continue;
  1655. acpi_state_table.count++;
  1656. if (!intel_idle_cst_usable())
  1657. continue;
  1658. if (!acpi_processor_claim_cst_control())
  1659. break;
  1660. return true;
  1661. }
  1662. acpi_state_table.count = 0;
  1663. pr_debug("ACPI _CST not found or not usable\n");
  1664. return false;
  1665. }
  1666. static void __init intel_idle_init_cstates_acpi(struct cpuidle_driver *drv)
  1667. {
  1668. int cstate, limit = min_t(int, CPUIDLE_STATE_MAX, acpi_state_table.count);
  1669. /*
  1670. * If limit > 0, intel_idle_cst_usable() has returned 'true', so all of
  1671. * the interesting states are ACPI_CSTATE_FFH.
  1672. */
  1673. for (cstate = 1; cstate < limit; cstate++) {
  1674. struct acpi_processor_cx *cx;
  1675. struct cpuidle_state *state;
  1676. if (intel_idle_max_cstate_reached(cstate - 1))
  1677. break;
  1678. cx = &acpi_state_table.states[cstate];
  1679. state = &drv->states[drv->state_count++];
  1680. snprintf(state->name, CPUIDLE_NAME_LEN, "C%d_ACPI", cstate);
  1681. strscpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);
  1682. state->exit_latency = cx->latency;
  1683. /*
  1684. * For C1-type C-states use the same number for both the exit
  1685. * latency and target residency, because that is the case for
  1686. * C1 in the majority of the static C-states tables above.
  1687. * For the other types of C-states, however, set the target
  1688. * residency to 3 times the exit latency which should lead to
  1689. * a reasonable balance between energy-efficiency and
  1690. * performance in the majority of interesting cases.
  1691. */
  1692. state->target_residency = cx->latency;
  1693. if (cx->type > ACPI_STATE_C1)
  1694. state->target_residency *= 3;
  1695. state->flags = MWAIT2flg(cx->address);
  1696. if (cx->type > ACPI_STATE_C2)
  1697. state->flags |= CPUIDLE_FLAG_TLB_FLUSHED;
  1698. if (disabled_states_mask & BIT(cstate))
  1699. state->flags |= CPUIDLE_FLAG_OFF;
  1700. if (intel_idle_state_needs_timer_stop(state))
  1701. state->flags |= CPUIDLE_FLAG_TIMER_STOP;
  1702. if (cx->type > ACPI_STATE_C1 && !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
  1703. mark_tsc_unstable("TSC halts in idle");
  1704. state->enter = intel_idle;
  1705. state->enter_dead = intel_idle_enter_dead;
  1706. state->enter_s2idle = intel_idle_s2idle;
  1707. }
  1708. }
  1709. static bool __init intel_idle_off_by_default(unsigned int flags, u32 mwait_hint)
  1710. {
  1711. int cstate, limit;
  1712. /*
  1713. * If there are no _CST C-states, do not disable any C-states by
  1714. * default.
  1715. */
  1716. if (!acpi_state_table.count)
  1717. return false;
  1718. limit = min_t(int, CPUIDLE_STATE_MAX, acpi_state_table.count);
  1719. /*
  1720. * If limit > 0, intel_idle_cst_usable() has returned 'true', so all of
  1721. * the interesting states are ACPI_CSTATE_FFH.
  1722. */
  1723. for (cstate = 1; cstate < limit; cstate++) {
  1724. u32 acpi_hint = acpi_state_table.states[cstate].address;
  1725. u32 table_hint = mwait_hint;
  1726. if (flags & CPUIDLE_FLAG_PARTIAL_HINT_MATCH) {
  1727. acpi_hint &= ~MWAIT_SUBSTATE_MASK;
  1728. table_hint &= ~MWAIT_SUBSTATE_MASK;
  1729. }
  1730. if (acpi_hint == table_hint)
  1731. return false;
  1732. }
  1733. return true;
  1734. }
  1735. static inline bool ignore_native(void)
  1736. {
  1737. return no_native && !no_acpi;
  1738. }
  1739. #else /* !CONFIG_ACPI_PROCESSOR_CSTATE */
  1740. #define force_use_acpi (false)
  1741. static inline bool intel_idle_acpi_cst_extract(void) { return false; }
  1742. static inline void intel_idle_init_cstates_acpi(struct cpuidle_driver *drv) { }
  1743. static inline bool intel_idle_off_by_default(unsigned int flags, u32 mwait_hint)
  1744. {
  1745. return false;
  1746. }
  1747. static inline bool ignore_native(void) { return false; }
  1748. #endif /* !CONFIG_ACPI_PROCESSOR_CSTATE */
  1749. /**
  1750. * ivt_idle_state_table_update - Tune the idle states table for Ivy Town.
  1751. *
  1752. * Tune IVT multi-socket targets.
  1753. * Assumption: num_sockets == (max_package_num + 1).
  1754. */
  1755. static void __init ivt_idle_state_table_update(void)
  1756. {
  1757. /* IVT uses a different table for 1-2, 3-4, and > 4 sockets */
  1758. int cpu, package_num, num_sockets = 1;
  1759. for_each_online_cpu(cpu) {
  1760. package_num = topology_physical_package_id(cpu);
  1761. if (package_num + 1 > num_sockets) {
  1762. num_sockets = package_num + 1;
  1763. if (num_sockets > 4) {
  1764. cpuidle_state_table = ivt_cstates_8s;
  1765. return;
  1766. }
  1767. }
  1768. }
  1769. if (num_sockets > 2)
  1770. cpuidle_state_table = ivt_cstates_4s;
  1771. /* else, 1 and 2 socket systems use default ivt_cstates */
  1772. }
  1773. /**
  1774. * irtl_2_usec - IRTL to microseconds conversion.
  1775. * @irtl: IRTL MSR value.
  1776. *
  1777. * Translate the IRTL (Interrupt Response Time Limit) MSR value to microseconds.
  1778. */
  1779. static unsigned long long __init irtl_2_usec(unsigned long long irtl)
  1780. {
  1781. static const unsigned int irtl_ns_units[] __initconst = {
  1782. 1, 32, 1024, 32768, 1048576, 33554432, 0, 0
  1783. };
  1784. unsigned long long ns;
  1785. if (!irtl)
  1786. return 0;
  1787. ns = irtl_ns_units[(irtl >> 10) & 0x7];
  1788. return div_u64((irtl & 0x3FF) * ns, NSEC_PER_USEC);
  1789. }
  1790. /**
  1791. * bxt_idle_state_table_update - Fix up the Broxton idle states table.
  1792. *
  1793. * On BXT, trust the IRTL (Interrupt Response Time Limit) MSR to show the
  1794. * definitive maximum latency and use the same value for target_residency.
  1795. */
  1796. static void __init bxt_idle_state_table_update(void)
  1797. {
  1798. unsigned long long msr;
  1799. unsigned int usec;
  1800. rdmsrq(MSR_PKGC6_IRTL, msr);
  1801. usec = irtl_2_usec(msr);
  1802. if (usec) {
  1803. bxt_cstates[2].exit_latency = usec;
  1804. bxt_cstates[2].target_residency = usec;
  1805. }
  1806. rdmsrq(MSR_PKGC7_IRTL, msr);
  1807. usec = irtl_2_usec(msr);
  1808. if (usec) {
  1809. bxt_cstates[3].exit_latency = usec;
  1810. bxt_cstates[3].target_residency = usec;
  1811. }
  1812. rdmsrq(MSR_PKGC8_IRTL, msr);
  1813. usec = irtl_2_usec(msr);
  1814. if (usec) {
  1815. bxt_cstates[4].exit_latency = usec;
  1816. bxt_cstates[4].target_residency = usec;
  1817. }
  1818. rdmsrq(MSR_PKGC9_IRTL, msr);
  1819. usec = irtl_2_usec(msr);
  1820. if (usec) {
  1821. bxt_cstates[5].exit_latency = usec;
  1822. bxt_cstates[5].target_residency = usec;
  1823. }
  1824. rdmsrq(MSR_PKGC10_IRTL, msr);
  1825. usec = irtl_2_usec(msr);
  1826. if (usec) {
  1827. bxt_cstates[6].exit_latency = usec;
  1828. bxt_cstates[6].target_residency = usec;
  1829. }
  1830. }
  1831. /**
  1832. * sklh_idle_state_table_update - Fix up the Sky Lake idle states table.
  1833. *
  1834. * On SKL-H (model 0x5e) skip C8 and C9 if C10 is enabled and SGX disabled.
  1835. */
  1836. static void __init sklh_idle_state_table_update(void)
  1837. {
  1838. unsigned long long msr;
  1839. unsigned int eax, ebx, ecx, edx;
  1840. /* if PC10 disabled via cmdline intel_idle.max_cstate=7 or shallower */
  1841. if (max_cstate <= 7)
  1842. return;
  1843. /* if PC10 not present in CPUID.MWAIT.EDX */
  1844. if ((mwait_substates & (0xF << 28)) == 0)
  1845. return;
  1846. rdmsrq(MSR_PKG_CST_CONFIG_CONTROL, msr);
  1847. /* PC10 is not enabled in PKG C-state limit */
  1848. if ((msr & 0xF) != 8)
  1849. return;
  1850. ecx = 0;
  1851. cpuid(7, &eax, &ebx, &ecx, &edx);
  1852. /* if SGX is present */
  1853. if (ebx & (1 << 2)) {
  1854. rdmsrq(MSR_IA32_FEAT_CTL, msr);
  1855. /* if SGX is enabled */
  1856. if (msr & (1 << 18))
  1857. return;
  1858. }
  1859. skl_cstates[5].flags |= CPUIDLE_FLAG_UNUSABLE; /* C8-SKL */
  1860. skl_cstates[6].flags |= CPUIDLE_FLAG_UNUSABLE; /* C9-SKL */
  1861. }
  1862. /**
  1863. * skx_idle_state_table_update - Adjust the Sky Lake/Cascade Lake
  1864. * idle states table.
  1865. */
  1866. static void __init skx_idle_state_table_update(void)
  1867. {
  1868. unsigned long long msr;
  1869. rdmsrq(MSR_PKG_CST_CONFIG_CONTROL, msr);
  1870. /*
  1871. * 000b: C0/C1 (no package C-state support)
  1872. * 001b: C2
  1873. * 010b: C6 (non-retention)
  1874. * 011b: C6 (retention)
  1875. * 111b: No Package C state limits.
  1876. */
  1877. if ((msr & 0x7) < 2) {
  1878. /*
  1879. * Uses the CC6 + PC0 latency and 3 times of
  1880. * latency for target_residency if the PC6
  1881. * is disabled in BIOS. This is consistent
  1882. * with how intel_idle driver uses _CST
  1883. * to set the target_residency.
  1884. */
  1885. skx_cstates[2].exit_latency = 92;
  1886. skx_cstates[2].target_residency = 276;
  1887. }
  1888. }
  1889. /**
  1890. * spr_idle_state_table_update - Adjust Sapphire Rapids idle states table.
  1891. */
  1892. static void __init spr_idle_state_table_update(void)
  1893. {
  1894. unsigned long long msr;
  1895. /*
  1896. * By default, the C6 state assumes the worst-case scenario of package
  1897. * C6. However, if PC6 is disabled, we update the numbers to match
  1898. * core C6.
  1899. */
  1900. rdmsrq(MSR_PKG_CST_CONFIG_CONTROL, msr);
  1901. /* Limit value 2 and above allow for PC6. */
  1902. if ((msr & 0x7) < 2) {
  1903. spr_cstates[2].exit_latency = 190;
  1904. spr_cstates[2].target_residency = 600;
  1905. }
  1906. }
  1907. /**
  1908. * byt_cht_auto_demotion_disable - Disable Bay/Cherry Trail auto-demotion.
  1909. */
  1910. static void __init byt_cht_auto_demotion_disable(void)
  1911. {
  1912. wrmsrq(MSR_CC6_DEMOTION_POLICY_CONFIG, 0);
  1913. wrmsrq(MSR_MC6_DEMOTION_POLICY_CONFIG, 0);
  1914. }
  1915. static bool __init intel_idle_verify_cstate(unsigned int mwait_hint)
  1916. {
  1917. unsigned int mwait_cstate = (MWAIT_HINT2CSTATE(mwait_hint) + 1) &
  1918. MWAIT_CSTATE_MASK;
  1919. unsigned int num_substates = (mwait_substates >> mwait_cstate * 4) &
  1920. MWAIT_SUBSTATE_MASK;
  1921. /* Ignore the C-state if there are NO sub-states in CPUID for it. */
  1922. if (num_substates == 0)
  1923. return false;
  1924. if (mwait_cstate > 2 && !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
  1925. mark_tsc_unstable("TSC halts in idle states deeper than C2");
  1926. return true;
  1927. }
  1928. static void state_update_enter_method(struct cpuidle_state *state, int cstate)
  1929. {
  1930. if (state->flags & CPUIDLE_FLAG_INIT_XSTATE) {
  1931. /*
  1932. * Combining with XSTATE with IBRS or IRQ_ENABLE flags
  1933. * is not currently supported but this driver.
  1934. */
  1935. WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IBRS);
  1936. WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IRQ_ENABLE);
  1937. state->enter = intel_idle_xstate;
  1938. return;
  1939. }
  1940. if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS) &&
  1941. ((state->flags & CPUIDLE_FLAG_IBRS) || ibrs_off)) {
  1942. /*
  1943. * IBRS mitigation requires that C-states are entered
  1944. * with interrupts disabled.
  1945. */
  1946. if (ibrs_off && (state->flags & CPUIDLE_FLAG_IRQ_ENABLE))
  1947. state->flags &= ~CPUIDLE_FLAG_IRQ_ENABLE;
  1948. WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IRQ_ENABLE);
  1949. state->enter = intel_idle_ibrs;
  1950. return;
  1951. }
  1952. if (state->flags & CPUIDLE_FLAG_IRQ_ENABLE) {
  1953. state->enter = intel_idle_irq;
  1954. return;
  1955. }
  1956. if (force_irq_on) {
  1957. pr_info("forced intel_idle_irq for state %d\n", cstate);
  1958. state->enter = intel_idle_irq;
  1959. }
  1960. }
  1961. static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
  1962. {
  1963. int cstate;
  1964. switch (boot_cpu_data.x86_vfm) {
  1965. case INTEL_IVYBRIDGE_X:
  1966. ivt_idle_state_table_update();
  1967. break;
  1968. case INTEL_ATOM_GOLDMONT:
  1969. case INTEL_ATOM_GOLDMONT_PLUS:
  1970. bxt_idle_state_table_update();
  1971. break;
  1972. case INTEL_SKYLAKE:
  1973. sklh_idle_state_table_update();
  1974. break;
  1975. case INTEL_SKYLAKE_X:
  1976. skx_idle_state_table_update();
  1977. break;
  1978. case INTEL_SAPPHIRERAPIDS_X:
  1979. case INTEL_EMERALDRAPIDS_X:
  1980. spr_idle_state_table_update();
  1981. break;
  1982. case INTEL_ATOM_SILVERMONT:
  1983. case INTEL_ATOM_AIRMONT:
  1984. byt_cht_auto_demotion_disable();
  1985. break;
  1986. }
  1987. for (cstate = 0; cstate < CPUIDLE_STATE_MAX; ++cstate) {
  1988. struct cpuidle_state *state;
  1989. unsigned int mwait_hint;
  1990. if (intel_idle_max_cstate_reached(cstate))
  1991. break;
  1992. if (!cpuidle_state_table[cstate].enter &&
  1993. !cpuidle_state_table[cstate].enter_s2idle)
  1994. break;
  1995. if (!cpuidle_state_table[cstate].enter_dead)
  1996. cpuidle_state_table[cstate].enter_dead = intel_idle_enter_dead;
  1997. /* If marked as unusable, skip this state. */
  1998. if (cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_UNUSABLE) {
  1999. pr_debug("state %s is disabled\n",
  2000. cpuidle_state_table[cstate].name);
  2001. continue;
  2002. }
  2003. mwait_hint = flg2MWAIT(cpuidle_state_table[cstate].flags);
  2004. if (!intel_idle_verify_cstate(mwait_hint))
  2005. continue;
  2006. /* Structure copy. */
  2007. drv->states[drv->state_count] = cpuidle_state_table[cstate];
  2008. state = &drv->states[drv->state_count];
  2009. state_update_enter_method(state, cstate);
  2010. if ((disabled_states_mask & BIT(drv->state_count)) ||
  2011. ((icpu->use_acpi || force_use_acpi) &&
  2012. intel_idle_off_by_default(state->flags, mwait_hint) &&
  2013. !(state->flags & CPUIDLE_FLAG_ALWAYS_ENABLE)))
  2014. state->flags |= CPUIDLE_FLAG_OFF;
  2015. if (intel_idle_state_needs_timer_stop(state))
  2016. state->flags |= CPUIDLE_FLAG_TIMER_STOP;
  2017. drv->state_count++;
  2018. }
  2019. }
  2020. /**
  2021. * intel_idle_cpuidle_driver_init - Create the list of available idle states.
  2022. * @drv: cpuidle driver structure to initialize.
  2023. */
  2024. static void __init intel_idle_cpuidle_driver_init(struct cpuidle_driver *drv)
  2025. {
  2026. cpuidle_poll_state_init(drv);
  2027. if (disabled_states_mask & BIT(0))
  2028. drv->states[0].flags |= CPUIDLE_FLAG_OFF;
  2029. drv->state_count = 1;
  2030. if (icpu && icpu->state_table)
  2031. intel_idle_init_cstates_icpu(drv);
  2032. else
  2033. intel_idle_init_cstates_acpi(drv);
  2034. }
  2035. static void auto_demotion_disable(void)
  2036. {
  2037. unsigned long long msr_bits;
  2038. rdmsrq(MSR_PKG_CST_CONFIG_CONTROL, msr_bits);
  2039. msr_bits &= ~auto_demotion_disable_flags;
  2040. wrmsrq(MSR_PKG_CST_CONFIG_CONTROL, msr_bits);
  2041. }
  2042. static void c1e_promotion_enable(void)
  2043. {
  2044. unsigned long long msr_bits;
  2045. rdmsrq(MSR_IA32_POWER_CTL, msr_bits);
  2046. msr_bits |= 0x2;
  2047. wrmsrq(MSR_IA32_POWER_CTL, msr_bits);
  2048. }
  2049. static void c1e_promotion_disable(void)
  2050. {
  2051. unsigned long long msr_bits;
  2052. rdmsrq(MSR_IA32_POWER_CTL, msr_bits);
  2053. msr_bits &= ~0x2;
  2054. wrmsrq(MSR_IA32_POWER_CTL, msr_bits);
  2055. }
  2056. /**
  2057. * intel_idle_cpu_init - Register the target CPU with the cpuidle core.
  2058. * @cpu: CPU to initialize.
  2059. *
  2060. * Register a cpuidle device object for @cpu and update its MSRs in accordance
  2061. * with the processor model flags.
  2062. */
  2063. static int intel_idle_cpu_init(unsigned int cpu)
  2064. {
  2065. struct cpuidle_device *dev;
  2066. dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
  2067. dev->cpu = cpu;
  2068. if (cpuidle_register_device(dev)) {
  2069. pr_debug("cpuidle_register_device %d failed!\n", cpu);
  2070. return -EIO;
  2071. }
  2072. if (auto_demotion_disable_flags)
  2073. auto_demotion_disable();
  2074. if (c1e_promotion == C1E_PROMOTION_ENABLE)
  2075. c1e_promotion_enable();
  2076. else if (c1e_promotion == C1E_PROMOTION_DISABLE)
  2077. c1e_promotion_disable();
  2078. return 0;
  2079. }
  2080. static int intel_idle_cpu_online(unsigned int cpu)
  2081. {
  2082. struct cpuidle_device *dev;
  2083. if (!boot_cpu_has(X86_FEATURE_ARAT))
  2084. tick_broadcast_enable();
  2085. /*
  2086. * Some systems can hotplug a cpu at runtime after
  2087. * the kernel has booted, we have to initialize the
  2088. * driver in this case
  2089. */
  2090. dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
  2091. if (!dev->registered)
  2092. return intel_idle_cpu_init(cpu);
  2093. return 0;
  2094. }
  2095. /**
  2096. * intel_idle_cpuidle_devices_uninit - Unregister all cpuidle devices.
  2097. */
  2098. static void __init intel_idle_cpuidle_devices_uninit(void)
  2099. {
  2100. int i;
  2101. for_each_online_cpu(i)
  2102. cpuidle_unregister_device(per_cpu_ptr(intel_idle_cpuidle_devices, i));
  2103. }
  2104. static void intel_c1_demotion_toggle(void *enable)
  2105. {
  2106. unsigned long long msr_val;
  2107. rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr_val);
  2108. /*
  2109. * Enable/disable C1 undemotion along with C1 demotion, as this is the
  2110. * most sensible configuration in general.
  2111. */
  2112. if (enable)
  2113. msr_val |= NHM_C1_AUTO_DEMOTE | SNB_C1_AUTO_UNDEMOTE;
  2114. else
  2115. msr_val &= ~(NHM_C1_AUTO_DEMOTE | SNB_C1_AUTO_UNDEMOTE);
  2116. wrmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr_val);
  2117. }
  2118. static ssize_t intel_c1_demotion_store(struct device *dev,
  2119. struct device_attribute *attr,
  2120. const char *buf, size_t count)
  2121. {
  2122. bool enable;
  2123. int err;
  2124. err = kstrtobool(buf, &enable);
  2125. if (err)
  2126. return err;
  2127. mutex_lock(&c1_demotion_mutex);
  2128. /* Enable/disable C1 demotion on all CPUs */
  2129. on_each_cpu(intel_c1_demotion_toggle, (void *)enable, 1);
  2130. mutex_unlock(&c1_demotion_mutex);
  2131. return count;
  2132. }
  2133. static ssize_t intel_c1_demotion_show(struct device *dev,
  2134. struct device_attribute *attr, char *buf)
  2135. {
  2136. unsigned long long msr_val;
  2137. /*
  2138. * Read the MSR value for a CPU and assume it is the same for all CPUs. Any other
  2139. * configuration would be a BIOS bug.
  2140. */
  2141. rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr_val);
  2142. return sysfs_emit(buf, "%d\n", !!(msr_val & NHM_C1_AUTO_DEMOTE));
  2143. }
  2144. static DEVICE_ATTR_RW(intel_c1_demotion);
  2145. static int __init intel_idle_sysfs_init(void)
  2146. {
  2147. int err;
  2148. if (!c1_demotion_supported)
  2149. return 0;
  2150. sysfs_root = bus_get_dev_root(&cpu_subsys);
  2151. if (!sysfs_root)
  2152. return 0;
  2153. err = sysfs_add_file_to_group(&sysfs_root->kobj,
  2154. &dev_attr_intel_c1_demotion.attr,
  2155. "cpuidle");
  2156. if (err) {
  2157. put_device(sysfs_root);
  2158. return err;
  2159. }
  2160. return 0;
  2161. }
  2162. static void __init intel_idle_sysfs_uninit(void)
  2163. {
  2164. if (!sysfs_root)
  2165. return;
  2166. sysfs_remove_file_from_group(&sysfs_root->kobj,
  2167. &dev_attr_intel_c1_demotion.attr,
  2168. "cpuidle");
  2169. put_device(sysfs_root);
  2170. }
  2171. /**
  2172. * get_cmdline_field - Get the current field from a cmdline string.
  2173. * @args: The cmdline string to get the current field from.
  2174. * @field: Pointer to the current field upon return.
  2175. * @sep: The fields separator character.
  2176. *
  2177. * Examples:
  2178. * Input: args="C1:1:1,C1E:2:10", sep=':'
  2179. * Output: field="C1", return "1:1,C1E:2:10"
  2180. * Input: args="C1:1:1,C1E:2:10", sep=','
  2181. * Output: field="C1:1:1", return "C1E:2:10"
  2182. * Ipnut: args="::", sep=':'
  2183. * Output: field="", return ":"
  2184. *
  2185. * Return: The continuation of the cmdline string after the field or NULL.
  2186. */
  2187. static char *get_cmdline_field(char *args, char **field, char sep)
  2188. {
  2189. unsigned int i;
  2190. for (i = 0; args[i] && !isspace(args[i]); i++) {
  2191. if (args[i] == sep)
  2192. break;
  2193. }
  2194. *field = args;
  2195. if (args[i] != sep)
  2196. return NULL;
  2197. args[i] = '\0';
  2198. return args + i + 1;
  2199. }
  2200. /**
  2201. * validate_cmdline_cstate - Validate a C-state from cmdline.
  2202. * @state: The C-state to validate.
  2203. * @prev_state: The previous C-state in the table or NULL.
  2204. *
  2205. * Return: 0 if the C-state is valid or -EINVAL otherwise.
  2206. */
  2207. static int validate_cmdline_cstate(struct cpuidle_state *state,
  2208. struct cpuidle_state *prev_state)
  2209. {
  2210. if (state->exit_latency == 0)
  2211. /* Exit latency 0 can only be used for the POLL state */
  2212. return -EINVAL;
  2213. if (state->exit_latency > MAX_CMDLINE_LATENCY_US)
  2214. return -EINVAL;
  2215. if (state->target_residency > MAX_CMDLINE_RESIDENCY_US)
  2216. return -EINVAL;
  2217. if (state->target_residency < state->exit_latency)
  2218. return -EINVAL;
  2219. if (!prev_state)
  2220. return 0;
  2221. if (state->exit_latency <= prev_state->exit_latency)
  2222. return -EINVAL;
  2223. if (state->target_residency <= prev_state->target_residency)
  2224. return -EINVAL;
  2225. return 0;
  2226. }
  2227. /**
  2228. * cmdline_table_adjust - Adjust the C-states table with data from cmdline.
  2229. * @drv: cpuidle driver (assumed to point to intel_idle_driver).
  2230. *
  2231. * Adjust the C-states table with data from the 'intel_idle.table' module
  2232. * parameter (if specified).
  2233. */
  2234. static void __init cmdline_table_adjust(struct cpuidle_driver *drv)
  2235. {
  2236. char *args = cmdline_table_str;
  2237. struct cpuidle_state *state;
  2238. int i;
  2239. if (args[0] == '\0')
  2240. /* The 'intel_idle.table' module parameter was not specified */
  2241. return;
  2242. /* Create a copy of the C-states table */
  2243. for (i = 0; i < drv->state_count; i++)
  2244. cmdline_states[i] = drv->states[i];
  2245. /*
  2246. * Adjust the C-states table copy with data from the 'intel_idle.table'
  2247. * module parameter.
  2248. */
  2249. while (args) {
  2250. char *fields, *name, *val;
  2251. /*
  2252. * Get the next C-state definition, which is expected to be
  2253. * '<name>:<latency_us>:<target_residency_us>'. Treat "empty"
  2254. * fields as unchanged. For example,
  2255. * '<name>::<target_residency_us>' leaves the latency unchanged.
  2256. */
  2257. args = get_cmdline_field(args, &fields, ',');
  2258. /* name */
  2259. fields = get_cmdline_field(fields, &name, ':');
  2260. if (!fields)
  2261. goto error;
  2262. if (!strcmp(name, "POLL")) {
  2263. pr_err("Cannot adjust POLL\n");
  2264. continue;
  2265. }
  2266. /* Find the C-state by its name */
  2267. state = NULL;
  2268. for (i = 0; i < drv->state_count; i++) {
  2269. if (!strcmp(name, drv->states[i].name)) {
  2270. state = &cmdline_states[i];
  2271. break;
  2272. }
  2273. }
  2274. if (!state) {
  2275. pr_err("C-state '%s' was not found\n", name);
  2276. continue;
  2277. }
  2278. /* Latency */
  2279. fields = get_cmdline_field(fields, &val, ':');
  2280. if (!fields)
  2281. goto error;
  2282. if (*val) {
  2283. if (kstrtouint(val, 0, &state->exit_latency))
  2284. goto error;
  2285. }
  2286. /* Target residency */
  2287. fields = get_cmdline_field(fields, &val, ':');
  2288. if (*val) {
  2289. if (kstrtouint(val, 0, &state->target_residency))
  2290. goto error;
  2291. }
  2292. /*
  2293. * Allow for 3 more fields, but ignore them. Helps to make
  2294. * possible future extensions of the cmdline format backward
  2295. * compatible.
  2296. */
  2297. for (i = 0; fields && i < 3; i++) {
  2298. fields = get_cmdline_field(fields, &val, ':');
  2299. if (!fields)
  2300. break;
  2301. }
  2302. if (fields) {
  2303. pr_err("Too many fields for C-state '%s'\n", state->name);
  2304. goto error;
  2305. }
  2306. pr_info("C-state from cmdline: name=%s, latency=%u, residency=%u\n",
  2307. state->name, state->exit_latency, state->target_residency);
  2308. }
  2309. /* Validate the adjusted C-states, start with index 1 to skip POLL */
  2310. for (i = 1; i < drv->state_count; i++) {
  2311. struct cpuidle_state *prev_state;
  2312. state = &cmdline_states[i];
  2313. prev_state = &cmdline_states[i - 1];
  2314. if (validate_cmdline_cstate(state, prev_state)) {
  2315. pr_err("C-state '%s' validation failed\n", state->name);
  2316. goto error;
  2317. }
  2318. }
  2319. /* Copy the adjusted C-states table back */
  2320. for (i = 1; i < drv->state_count; i++)
  2321. drv->states[i] = cmdline_states[i];
  2322. pr_info("Adjusted C-states with data from 'intel_idle.table'\n");
  2323. return;
  2324. error:
  2325. pr_info("Failed to adjust C-states with data from 'intel_idle.table'\n");
  2326. }
  2327. static int __init intel_idle_init(void)
  2328. {
  2329. const struct x86_cpu_id *id;
  2330. unsigned int eax, ebx, ecx;
  2331. int retval;
  2332. /* Do not load intel_idle at all for now if idle= is passed */
  2333. if (boot_option_idle_override != IDLE_NO_OVERRIDE)
  2334. return -ENODEV;
  2335. if (max_cstate == 0) {
  2336. pr_debug("disabled\n");
  2337. return -EPERM;
  2338. }
  2339. id = x86_match_cpu(intel_idle_ids);
  2340. if (id) {
  2341. if (!boot_cpu_has(X86_FEATURE_MWAIT)) {
  2342. pr_debug("Please enable MWAIT in BIOS SETUP\n");
  2343. return -ENODEV;
  2344. }
  2345. } else {
  2346. id = x86_match_cpu(intel_mwait_ids);
  2347. if (!id)
  2348. return -ENODEV;
  2349. }
  2350. cpuid(CPUID_LEAF_MWAIT, &eax, &ebx, &ecx, &mwait_substates);
  2351. if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
  2352. !(ecx & CPUID5_ECX_INTERRUPT_BREAK) ||
  2353. !mwait_substates)
  2354. return -ENODEV;
  2355. pr_debug("MWAIT substates: 0x%x\n", mwait_substates);
  2356. icpu = (const struct idle_cpu *)id->driver_data;
  2357. if (icpu && ignore_native()) {
  2358. pr_debug("ignoring native CPU idle states\n");
  2359. icpu = NULL;
  2360. }
  2361. if (icpu) {
  2362. if (icpu->state_table)
  2363. cpuidle_state_table = icpu->state_table;
  2364. else if (!intel_idle_acpi_cst_extract())
  2365. return -ENODEV;
  2366. auto_demotion_disable_flags = icpu->auto_demotion_disable_flags;
  2367. if (icpu->disable_promotion_to_c1e)
  2368. c1e_promotion = C1E_PROMOTION_DISABLE;
  2369. if (icpu->c1_demotion_supported)
  2370. c1_demotion_supported = true;
  2371. if (icpu->use_acpi || force_use_acpi)
  2372. intel_idle_acpi_cst_extract();
  2373. } else if (!intel_idle_acpi_cst_extract()) {
  2374. return -ENODEV;
  2375. }
  2376. intel_idle_cpuidle_devices = alloc_percpu(struct cpuidle_device);
  2377. if (!intel_idle_cpuidle_devices)
  2378. return -ENOMEM;
  2379. intel_idle_cpuidle_driver_init(&intel_idle_driver);
  2380. cmdline_table_adjust(&intel_idle_driver);
  2381. retval = intel_idle_sysfs_init();
  2382. if (retval)
  2383. pr_warn("failed to initialized sysfs");
  2384. retval = cpuidle_register_driver(&intel_idle_driver);
  2385. if (retval) {
  2386. struct cpuidle_driver *drv = cpuidle_get_driver();
  2387. printk(KERN_DEBUG pr_fmt("intel_idle yielding to %s\n"),
  2388. drv ? drv->name : "none");
  2389. goto init_driver_fail;
  2390. }
  2391. retval = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "idle/intel:online",
  2392. intel_idle_cpu_online, NULL);
  2393. if (retval < 0)
  2394. goto hp_setup_fail;
  2395. pr_debug("Local APIC timer is reliable in %s\n",
  2396. boot_cpu_has(X86_FEATURE_ARAT) ? "all C-states" : "C1");
  2397. arch_cpu_rescan_dead_smt_siblings();
  2398. return 0;
  2399. hp_setup_fail:
  2400. intel_idle_cpuidle_devices_uninit();
  2401. cpuidle_unregister_driver(&intel_idle_driver);
  2402. init_driver_fail:
  2403. intel_idle_sysfs_uninit();
  2404. free_percpu(intel_idle_cpuidle_devices);
  2405. return retval;
  2406. }
  2407. subsys_initcall_sync(intel_idle_init);
  2408. /*
  2409. * We are not really modular, but we used to support that. Meaning we also
  2410. * support "intel_idle.max_cstate=..." at boot and also a read-only export of
  2411. * it at /sys/module/intel_idle/parameters/max_cstate -- so using module_param
  2412. * is the easiest way (currently) to continue doing that.
  2413. */
  2414. module_param(max_cstate, int, 0444);
  2415. /*
  2416. * The positions of the bits that are set in this number are the indices of the
  2417. * idle states to be disabled by default (as reflected by the names of the
  2418. * corresponding idle state directories in sysfs, "state0", "state1" ...
  2419. * "state<i>" ..., where <i> is the index of the given state).
  2420. */
  2421. module_param_named(states_off, disabled_states_mask, uint, 0444);
  2422. MODULE_PARM_DESC(states_off, "Mask of disabled idle states");
  2423. /*
  2424. * Debugging option that forces the driver to enter all C-states with
  2425. * interrupts enabled. Does not apply to C-states with
  2426. * 'CPUIDLE_FLAG_INIT_XSTATE' and 'CPUIDLE_FLAG_IBRS' flags.
  2427. */
  2428. module_param(force_irq_on, bool, 0444);
  2429. /*
  2430. * Force the disabling of IBRS when X86_FEATURE_KERNEL_IBRS is on and
  2431. * CPUIDLE_FLAG_IRQ_ENABLE isn't set.
  2432. */
  2433. module_param(ibrs_off, bool, 0444);
  2434. MODULE_PARM_DESC(ibrs_off, "Disable IBRS when idle");
  2435. /*
  2436. * Define the C-states table from a user input string. Expected format is
  2437. * 'name:latency:residency', where:
  2438. * - name: The C-state name.
  2439. * - latency: The C-state exit latency in us.
  2440. * - residency: The C-state target residency in us.
  2441. *
  2442. * Multiple C-states can be defined by separating them with commas:
  2443. * 'name1:latency1:residency1,name2:latency2:residency2'
  2444. *
  2445. * Example: intel_idle.table=C1:1:1,C1E:5:10,C6:100:600
  2446. *
  2447. * To leave latency or residency unchanged, use an empty field, for example:
  2448. * 'C1:1:1,C1E::10' - leaves C1E latency unchanged.
  2449. */
  2450. module_param_string(table, cmdline_table_str, MAX_CMDLINE_TABLE_LEN, 0444);
  2451. MODULE_PARM_DESC(table, "Build the C-states table from a user input string");