idle_book3s.S 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. /*
  2. * This file contains idle entry/exit functions for POWER7,
  3. * POWER8 and POWER9 CPUs.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version
  8. * 2 of the License, or (at your option) any later version.
  9. */
  10. #include <linux/threads.h>
  11. #include <asm/exception-64s.h>
  12. #include <asm/processor.h>
  13. #include <asm/page.h>
  14. #include <asm/cputable.h>
  15. #include <asm/thread_info.h>
  16. #include <asm/ppc_asm.h>
  17. #include <asm/asm-offsets.h>
  18. #include <asm/ppc-opcode.h>
  19. #include <asm/hw_irq.h>
  20. #include <asm/kvm_book3s_asm.h>
  21. #include <asm/opal.h>
  22. #include <asm/cpuidle.h>
  23. #include <asm/book3s/64/mmu-hash.h>
  24. #include <asm/mmu.h>
  25. #undef DEBUG
  26. /*
  27. * Use unused space in the interrupt stack to save and restore
  28. * registers for winkle support.
  29. */
  30. #define _SDR1 GPR3
  31. #define _RPR GPR4
  32. #define _SPURR GPR5
  33. #define _PURR GPR6
  34. #define _TSCR GPR7
  35. #define _DSCR GPR8
  36. #define _AMOR GPR9
  37. #define _WORT GPR10
  38. #define _WORC GPR11
  39. #define _PTCR GPR12
  40. #define PSSCR_HV_TEMPLATE PSSCR_ESL | PSSCR_EC | \
  41. PSSCR_PSLL_MASK | PSSCR_TR_MASK | \
  42. PSSCR_MTL_MASK
  43. .text
  44. /*
  45. * Used by threads before entering deep idle states. Saves SPRs
  46. * in interrupt stack frame
  47. */
  48. save_sprs_to_stack:
  49. /*
  50. * Note all register i.e per-core, per-subcore or per-thread is saved
  51. * here since any thread in the core might wake up first
  52. */
  53. BEGIN_FTR_SECTION
  54. mfspr r3,SPRN_PTCR
  55. std r3,_PTCR(r1)
  56. /*
  57. * Note - SDR1 is dropped in Power ISA v3. Hence not restoring
  58. * SDR1 here
  59. */
  60. FTR_SECTION_ELSE
  61. mfspr r3,SPRN_SDR1
  62. std r3,_SDR1(r1)
  63. ALT_FTR_SECTION_END_IFSET(CPU_FTR_ARCH_300)
  64. mfspr r3,SPRN_RPR
  65. std r3,_RPR(r1)
  66. mfspr r3,SPRN_SPURR
  67. std r3,_SPURR(r1)
  68. mfspr r3,SPRN_PURR
  69. std r3,_PURR(r1)
  70. mfspr r3,SPRN_TSCR
  71. std r3,_TSCR(r1)
  72. mfspr r3,SPRN_DSCR
  73. std r3,_DSCR(r1)
  74. mfspr r3,SPRN_AMOR
  75. std r3,_AMOR(r1)
  76. mfspr r3,SPRN_WORT
  77. std r3,_WORT(r1)
  78. mfspr r3,SPRN_WORC
  79. std r3,_WORC(r1)
  80. blr
  81. /*
  82. * Used by threads when the lock bit of core_idle_state is set.
  83. * Threads will spin in HMT_LOW until the lock bit is cleared.
  84. * r14 - pointer to core_idle_state
  85. * r15 - used to load contents of core_idle_state
  86. * r9 - used as a temporary variable
  87. */
  88. core_idle_lock_held:
  89. HMT_LOW
  90. 3: lwz r15,0(r14)
  91. andi. r15,r15,PNV_CORE_IDLE_LOCK_BIT
  92. bne 3b
  93. HMT_MEDIUM
  94. lwarx r15,0,r14
  95. andi. r9,r15,PNV_CORE_IDLE_LOCK_BIT
  96. bne core_idle_lock_held
  97. blr
  98. /*
  99. * Pass requested state in r3:
  100. * r3 - PNV_THREAD_NAP/SLEEP/WINKLE in POWER8
  101. * - Requested STOP state in POWER9
  102. *
  103. * To check IRQ_HAPPENED in r4
  104. * 0 - don't check
  105. * 1 - check
  106. *
  107. * Address to 'rfid' to in r5
  108. */
  109. _GLOBAL(pnv_powersave_common)
  110. /* Use r3 to pass state nap/sleep/winkle */
  111. /* NAP is a state loss, we create a regs frame on the
  112. * stack, fill it up with the state we care about and
  113. * stick a pointer to it in PACAR1. We really only
  114. * need to save PC, some CR bits and the NV GPRs,
  115. * but for now an interrupt frame will do.
  116. */
  117. mflr r0
  118. std r0,16(r1)
  119. stdu r1,-INT_FRAME_SIZE(r1)
  120. std r0,_LINK(r1)
  121. std r0,_NIP(r1)
  122. /* Hard disable interrupts */
  123. mfmsr r9
  124. rldicl r9,r9,48,1
  125. rotldi r9,r9,16
  126. mtmsrd r9,1 /* hard-disable interrupts */
  127. /* Check if something happened while soft-disabled */
  128. lbz r0,PACAIRQHAPPENED(r13)
  129. andi. r0,r0,~PACA_IRQ_HARD_DIS@l
  130. beq 1f
  131. cmpwi cr0,r4,0
  132. beq 1f
  133. addi r1,r1,INT_FRAME_SIZE
  134. ld r0,16(r1)
  135. li r3,0 /* Return 0 (no nap) */
  136. mtlr r0
  137. blr
  138. 1: /* We mark irqs hard disabled as this is the state we'll
  139. * be in when returning and we need to tell arch_local_irq_restore()
  140. * about it
  141. */
  142. li r0,PACA_IRQ_HARD_DIS
  143. stb r0,PACAIRQHAPPENED(r13)
  144. /* We haven't lost state ... yet */
  145. li r0,0
  146. stb r0,PACA_NAPSTATELOST(r13)
  147. /* Continue saving state */
  148. SAVE_GPR(2, r1)
  149. SAVE_NVGPRS(r1)
  150. mfcr r4
  151. std r4,_CCR(r1)
  152. std r9,_MSR(r1)
  153. std r1,PACAR1(r13)
  154. /*
  155. * Go to real mode to do the nap, as required by the architecture.
  156. * Also, we need to be in real mode before setting hwthread_state,
  157. * because as soon as we do that, another thread can switch
  158. * the MMU context to the guest.
  159. */
  160. LOAD_REG_IMMEDIATE(r7, MSR_IDLE)
  161. li r6, MSR_RI
  162. andc r6, r9, r6
  163. mtmsrd r6, 1 /* clear RI before setting SRR0/1 */
  164. mtspr SPRN_SRR0, r5
  165. mtspr SPRN_SRR1, r7
  166. RFI_TO_KERNEL
  167. .globl pnv_enter_arch207_idle_mode
  168. pnv_enter_arch207_idle_mode:
  169. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  170. /* Tell KVM we're entering idle */
  171. li r4,KVM_HWTHREAD_IN_IDLE
  172. /******************************************************/
  173. /* N O T E W E L L ! ! ! N O T E W E L L */
  174. /* The following store to HSTATE_HWTHREAD_STATE(r13) */
  175. /* MUST occur in real mode, i.e. with the MMU off, */
  176. /* and the MMU must stay off until we clear this flag */
  177. /* and test HSTATE_HWTHREAD_REQ(r13) in the system */
  178. /* reset interrupt vector in exceptions-64s.S. */
  179. /* The reason is that another thread can switch the */
  180. /* MMU to a guest context whenever this flag is set */
  181. /* to KVM_HWTHREAD_IN_IDLE, and if the MMU was on, */
  182. /* that would potentially cause this thread to start */
  183. /* executing instructions from guest memory in */
  184. /* hypervisor mode, leading to a host crash or data */
  185. /* corruption, or worse. */
  186. /******************************************************/
  187. stb r4,HSTATE_HWTHREAD_STATE(r13)
  188. #endif
  189. stb r3,PACA_THREAD_IDLE_STATE(r13)
  190. cmpwi cr3,r3,PNV_THREAD_SLEEP
  191. bge cr3,2f
  192. IDLE_STATE_ENTER_SEQ(PPC_NAP)
  193. /* No return */
  194. 2:
  195. /* Sleep or winkle */
  196. lbz r7,PACA_THREAD_MASK(r13)
  197. ld r14,PACA_CORE_IDLE_STATE_PTR(r13)
  198. lwarx_loop1:
  199. lwarx r15,0,r14
  200. andi. r9,r15,PNV_CORE_IDLE_LOCK_BIT
  201. bnel core_idle_lock_held
  202. andc r15,r15,r7 /* Clear thread bit */
  203. andi. r15,r15,PNV_CORE_IDLE_THREAD_BITS
  204. /*
  205. * If cr0 = 0, then current thread is the last thread of the core entering
  206. * sleep. Last thread needs to execute the hardware bug workaround code if
  207. * required by the platform.
  208. * Make the workaround call unconditionally here. The below branch call is
  209. * patched out when the idle states are discovered if the platform does not
  210. * require it.
  211. */
  212. .global pnv_fastsleep_workaround_at_entry
  213. pnv_fastsleep_workaround_at_entry:
  214. beq fastsleep_workaround_at_entry
  215. stwcx. r15,0,r14
  216. bne- lwarx_loop1
  217. isync
  218. common_enter: /* common code for all the threads entering sleep or winkle */
  219. bgt cr3,enter_winkle
  220. IDLE_STATE_ENTER_SEQ(PPC_SLEEP)
  221. fastsleep_workaround_at_entry:
  222. ori r15,r15,PNV_CORE_IDLE_LOCK_BIT
  223. stwcx. r15,0,r14
  224. bne- lwarx_loop1
  225. isync
  226. /* Fast sleep workaround */
  227. li r3,1
  228. li r4,1
  229. bl opal_rm_config_cpu_idle_state
  230. /* Clear Lock bit */
  231. li r0,0
  232. lwsync
  233. stw r0,0(r14)
  234. b common_enter
  235. enter_winkle:
  236. bl save_sprs_to_stack
  237. IDLE_STATE_ENTER_SEQ(PPC_WINKLE)
  238. /*
  239. * r3 - requested stop state
  240. */
  241. power_enter_stop:
  242. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  243. /* Tell KVM we're entering idle */
  244. li r4,KVM_HWTHREAD_IN_IDLE
  245. /* DO THIS IN REAL MODE! See comment above. */
  246. stb r4,HSTATE_HWTHREAD_STATE(r13)
  247. #endif
  248. /*
  249. * Check if the requested state is a deep idle state.
  250. */
  251. LOAD_REG_ADDRBASE(r5,pnv_first_deep_stop_state)
  252. ld r4,ADDROFF(pnv_first_deep_stop_state)(r5)
  253. cmpd r3,r4
  254. bge 2f
  255. IDLE_STATE_ENTER_SEQ(PPC_STOP)
  256. 2:
  257. /*
  258. * Entering deep idle state.
  259. * Clear thread bit in PACA_CORE_IDLE_STATE, save SPRs to
  260. * stack and enter stop
  261. */
  262. lbz r7,PACA_THREAD_MASK(r13)
  263. ld r14,PACA_CORE_IDLE_STATE_PTR(r13)
  264. lwarx_loop_stop:
  265. lwarx r15,0,r14
  266. andi. r9,r15,PNV_CORE_IDLE_LOCK_BIT
  267. bnel core_idle_lock_held
  268. andc r15,r15,r7 /* Clear thread bit */
  269. stwcx. r15,0,r14
  270. bne- lwarx_loop_stop
  271. isync
  272. bl save_sprs_to_stack
  273. IDLE_STATE_ENTER_SEQ(PPC_STOP)
  274. _GLOBAL(power7_idle)
  275. /* Now check if user or arch enabled NAP mode */
  276. LOAD_REG_ADDRBASE(r3,powersave_nap)
  277. lwz r4,ADDROFF(powersave_nap)(r3)
  278. cmpwi 0,r4,0
  279. beqlr
  280. li r3, 1
  281. /* fall through */
  282. _GLOBAL(power7_nap)
  283. mr r4,r3
  284. li r3,PNV_THREAD_NAP
  285. LOAD_REG_ADDR(r5, pnv_enter_arch207_idle_mode)
  286. b pnv_powersave_common
  287. /* No return */
  288. _GLOBAL(power7_sleep)
  289. li r3,PNV_THREAD_SLEEP
  290. li r4,1
  291. LOAD_REG_ADDR(r5, pnv_enter_arch207_idle_mode)
  292. b pnv_powersave_common
  293. /* No return */
  294. _GLOBAL(power7_winkle)
  295. li r3,PNV_THREAD_WINKLE
  296. li r4,1
  297. LOAD_REG_ADDR(r5, pnv_enter_arch207_idle_mode)
  298. b pnv_powersave_common
  299. /* No return */
  300. #define CHECK_HMI_INTERRUPT \
  301. mfspr r0,SPRN_SRR1; \
  302. BEGIN_FTR_SECTION_NESTED(66); \
  303. rlwinm r0,r0,45-31,0xf; /* extract wake reason field (P8) */ \
  304. FTR_SECTION_ELSE_NESTED(66); \
  305. rlwinm r0,r0,45-31,0xe; /* P7 wake reason field is 3 bits */ \
  306. ALT_FTR_SECTION_END_NESTED_IFSET(CPU_FTR_ARCH_207S, 66); \
  307. cmpwi r0,0xa; /* Hypervisor maintenance ? */ \
  308. bne 20f; \
  309. /* Invoke opal call to handle hmi */ \
  310. ld r2,PACATOC(r13); \
  311. ld r1,PACAR1(r13); \
  312. std r3,ORIG_GPR3(r1); /* Save original r3 */ \
  313. li r3,0; /* NULL argument */ \
  314. bl hmi_exception_realmode; \
  315. nop; \
  316. ld r3,ORIG_GPR3(r1); /* Restore original r3 */ \
  317. 20: nop;
  318. /*
  319. * r3 - requested stop state
  320. */
  321. _GLOBAL(power9_idle_stop)
  322. LOAD_REG_IMMEDIATE(r4, PSSCR_HV_TEMPLATE)
  323. or r4,r4,r3
  324. mtspr SPRN_PSSCR, r4
  325. li r4, 1
  326. LOAD_REG_ADDR(r5,power_enter_stop)
  327. b pnv_powersave_common
  328. /* No return */
  329. /*
  330. * Called from reset vector. Check whether we have woken up with
  331. * hypervisor state loss. If yes, restore hypervisor state and return
  332. * back to reset vector.
  333. *
  334. * r13 - Contents of HSPRG0
  335. * cr3 - set to gt if waking up with partial/complete hypervisor state loss
  336. */
  337. _GLOBAL(pnv_restore_hyp_resource)
  338. BEGIN_FTR_SECTION
  339. ld r2,PACATOC(r13);
  340. /*
  341. * POWER ISA 3. Use PSSCR to determine if we
  342. * are waking up from deep idle state
  343. */
  344. LOAD_REG_ADDRBASE(r5,pnv_first_deep_stop_state)
  345. ld r4,ADDROFF(pnv_first_deep_stop_state)(r5)
  346. mfspr r5,SPRN_PSSCR
  347. /*
  348. * 0-3 bits correspond to Power-Saving Level Status
  349. * which indicates the idle state we are waking up from
  350. */
  351. rldicl r5,r5,4,60
  352. cmpd cr4,r5,r4
  353. bge cr4,pnv_wakeup_tb_loss
  354. /*
  355. * Waking up without hypervisor state loss. Return to
  356. * reset vector
  357. */
  358. blr
  359. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
  360. /*
  361. * POWER ISA 2.07 or less.
  362. * Check if last bit of HSPGR0 is set. This indicates whether we are
  363. * waking up from winkle.
  364. */
  365. clrldi r5,r13,63
  366. clrrdi r13,r13,1
  367. /* Now that we are sure r13 is corrected, load TOC */
  368. ld r2,PACATOC(r13);
  369. cmpwi cr4,r5,1
  370. mtspr SPRN_HSPRG0,r13
  371. lbz r0,PACA_THREAD_IDLE_STATE(r13)
  372. cmpwi cr2,r0,PNV_THREAD_NAP
  373. bgt cr2,pnv_wakeup_tb_loss /* Either sleep or Winkle */
  374. /*
  375. * We fall through here if PACA_THREAD_IDLE_STATE shows we are waking
  376. * up from nap. At this stage CR3 shouldn't contains 'gt' since that
  377. * indicates we are waking with hypervisor state loss from nap.
  378. */
  379. bgt cr3,.
  380. blr /* Return back to System Reset vector from where
  381. pnv_restore_hyp_resource was invoked */
  382. /*
  383. * Called if waking up from idle state which can cause either partial or
  384. * complete hyp state loss.
  385. * In POWER8, called if waking up from fastsleep or winkle
  386. * In POWER9, called if waking up from stop state >= pnv_first_deep_stop_state
  387. *
  388. * r13 - PACA
  389. * cr3 - gt if waking up with partial/complete hypervisor state loss
  390. * cr4 - gt or eq if waking up from complete hypervisor state loss.
  391. */
  392. _GLOBAL(pnv_wakeup_tb_loss)
  393. ld r1,PACAR1(r13)
  394. /*
  395. * Before entering any idle state, the NVGPRs are saved in the stack.
  396. * If there was a state loss, or PACA_NAPSTATELOST was set, then the
  397. * NVGPRs are restored. If we are here, it is likely that state is lost,
  398. * but not guaranteed -- neither ISA207 nor ISA300 tests to reach
  399. * here are the same as the test to restore NVGPRS:
  400. * PACA_THREAD_IDLE_STATE test for ISA207, PSSCR test for ISA300,
  401. * and SRR1 test for restoring NVGPRs.
  402. *
  403. * We are about to clobber NVGPRs now, so set NAPSTATELOST to
  404. * guarantee they will always be restored. This might be tightened
  405. * with careful reading of specs (particularly for ISA300) but this
  406. * is already a slow wakeup path and it's simpler to be safe.
  407. */
  408. li r0,1
  409. stb r0,PACA_NAPSTATELOST(r13)
  410. /*
  411. *
  412. * Save SRR1 and LR in NVGPRs as they might be clobbered in
  413. * opal_call() (called in CHECK_HMI_INTERRUPT). SRR1 is required
  414. * to determine the wakeup reason if we branch to kvm_start_guest. LR
  415. * is required to return back to reset vector after hypervisor state
  416. * restore is complete.
  417. */
  418. mflr r17
  419. mfspr r16,SPRN_SRR1
  420. BEGIN_FTR_SECTION
  421. CHECK_HMI_INTERRUPT
  422. END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
  423. lbz r7,PACA_THREAD_MASK(r13)
  424. ld r14,PACA_CORE_IDLE_STATE_PTR(r13)
  425. lwarx_loop2:
  426. lwarx r15,0,r14
  427. andi. r9,r15,PNV_CORE_IDLE_LOCK_BIT
  428. /*
  429. * Lock bit is set in one of the 2 cases-
  430. * a. In the sleep/winkle enter path, the last thread is executing
  431. * fastsleep workaround code.
  432. * b. In the wake up path, another thread is executing fastsleep
  433. * workaround undo code or resyncing timebase or restoring context
  434. * In either case loop until the lock bit is cleared.
  435. */
  436. bnel core_idle_lock_held
  437. cmpwi cr2,r15,0
  438. /*
  439. * At this stage
  440. * cr2 - eq if first thread to wakeup in core
  441. * cr3- gt if waking up with partial/complete hypervisor state loss
  442. * cr4 - gt or eq if waking up from complete hypervisor state loss.
  443. */
  444. ori r15,r15,PNV_CORE_IDLE_LOCK_BIT
  445. stwcx. r15,0,r14
  446. bne- lwarx_loop2
  447. isync
  448. BEGIN_FTR_SECTION
  449. lbz r4,PACA_SUBCORE_SIBLING_MASK(r13)
  450. and r4,r4,r15
  451. cmpwi r4,0 /* Check if first in subcore */
  452. or r15,r15,r7 /* Set thread bit */
  453. beq first_thread_in_subcore
  454. END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300)
  455. or r15,r15,r7 /* Set thread bit */
  456. beq cr2,first_thread_in_core
  457. /* Not first thread in core or subcore to wake up */
  458. b clear_lock
  459. first_thread_in_subcore:
  460. /*
  461. * If waking up from sleep, subcore state is not lost. Hence
  462. * skip subcore state restore
  463. */
  464. blt cr4,subcore_state_restored
  465. /* Restore per-subcore state */
  466. ld r4,_SDR1(r1)
  467. mtspr SPRN_SDR1,r4
  468. ld r4,_RPR(r1)
  469. mtspr SPRN_RPR,r4
  470. ld r4,_AMOR(r1)
  471. mtspr SPRN_AMOR,r4
  472. subcore_state_restored:
  473. /*
  474. * Check if the thread is also the first thread in the core. If not,
  475. * skip to clear_lock.
  476. */
  477. bne cr2,clear_lock
  478. first_thread_in_core:
  479. /*
  480. * First thread in the core waking up from any state which can cause
  481. * partial or complete hypervisor state loss. It needs to
  482. * call the fastsleep workaround code if the platform requires it.
  483. * Call it unconditionally here. The below branch instruction will
  484. * be patched out if the platform does not have fastsleep or does not
  485. * require the workaround. Patching will be performed during the
  486. * discovery of idle-states.
  487. */
  488. .global pnv_fastsleep_workaround_at_exit
  489. pnv_fastsleep_workaround_at_exit:
  490. b fastsleep_workaround_at_exit
  491. timebase_resync:
  492. /*
  493. * Use cr3 which indicates that we are waking up with atleast partial
  494. * hypervisor state loss to determine if TIMEBASE RESYNC is needed.
  495. */
  496. ble cr3,clear_lock
  497. /* Time base re-sync */
  498. bl opal_rm_resync_timebase;
  499. /*
  500. * If waking up from sleep, per core state is not lost, skip to
  501. * clear_lock.
  502. */
  503. blt cr4,clear_lock
  504. /*
  505. * First thread in the core to wake up and its waking up with
  506. * complete hypervisor state loss. Restore per core hypervisor
  507. * state.
  508. */
  509. BEGIN_FTR_SECTION
  510. ld r4,_PTCR(r1)
  511. mtspr SPRN_PTCR,r4
  512. ld r4,_RPR(r1)
  513. mtspr SPRN_RPR,r4
  514. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
  515. ld r4,_TSCR(r1)
  516. mtspr SPRN_TSCR,r4
  517. ld r4,_WORC(r1)
  518. mtspr SPRN_WORC,r4
  519. clear_lock:
  520. andi. r15,r15,PNV_CORE_IDLE_THREAD_BITS
  521. lwsync
  522. stw r15,0(r14)
  523. common_exit:
  524. /*
  525. * Common to all threads.
  526. *
  527. * If waking up from sleep, hypervisor state is not lost. Hence
  528. * skip hypervisor state restore.
  529. */
  530. blt cr4,hypervisor_state_restored
  531. /* Waking up from winkle */
  532. BEGIN_MMU_FTR_SECTION
  533. b no_segments
  534. END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_RADIX)
  535. /* Restore SLB from PACA */
  536. ld r8,PACA_SLBSHADOWPTR(r13)
  537. .rept SLB_NUM_BOLTED
  538. li r3, SLBSHADOW_SAVEAREA
  539. LDX_BE r5, r8, r3
  540. addi r3, r3, 8
  541. LDX_BE r6, r8, r3
  542. andis. r7,r5,SLB_ESID_V@h
  543. beq 1f
  544. slbmte r6,r5
  545. 1: addi r8,r8,16
  546. .endr
  547. no_segments:
  548. /* Restore per thread state */
  549. ld r4,_SPURR(r1)
  550. mtspr SPRN_SPURR,r4
  551. ld r4,_PURR(r1)
  552. mtspr SPRN_PURR,r4
  553. ld r4,_DSCR(r1)
  554. mtspr SPRN_DSCR,r4
  555. ld r4,_WORT(r1)
  556. mtspr SPRN_WORT,r4
  557. /* Call cur_cpu_spec->cpu_restore() */
  558. LOAD_REG_ADDR(r4, cur_cpu_spec)
  559. ld r4,0(r4)
  560. ld r12,CPU_SPEC_RESTORE(r4)
  561. #ifdef PPC64_ELF_ABI_v1
  562. ld r12,0(r12)
  563. #endif
  564. mtctr r12
  565. bctrl
  566. hypervisor_state_restored:
  567. mtspr SPRN_SRR1,r16
  568. mtlr r17
  569. blr /* Return back to System Reset vector from where
  570. pnv_restore_hyp_resource was invoked */
  571. fastsleep_workaround_at_exit:
  572. li r3,1
  573. li r4,0
  574. bl opal_rm_config_cpu_idle_state
  575. b timebase_resync
  576. /*
  577. * R3 here contains the value that will be returned to the caller
  578. * of power7_nap.
  579. */
  580. _GLOBAL(pnv_wakeup_loss)
  581. ld r1,PACAR1(r13)
  582. BEGIN_FTR_SECTION
  583. CHECK_HMI_INTERRUPT
  584. END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
  585. REST_NVGPRS(r1)
  586. REST_GPR(2, r1)
  587. ld r6,_CCR(r1)
  588. ld r4,_MSR(r1)
  589. ld r5,_NIP(r1)
  590. addi r1,r1,INT_FRAME_SIZE
  591. mtcr r6
  592. mtspr SPRN_SRR1,r4
  593. mtspr SPRN_SRR0,r5
  594. RFI_TO_KERNEL
  595. /*
  596. * R3 here contains the value that will be returned to the caller
  597. * of power7_nap.
  598. */
  599. _GLOBAL(pnv_wakeup_noloss)
  600. lbz r0,PACA_NAPSTATELOST(r13)
  601. cmpwi r0,0
  602. bne pnv_wakeup_loss
  603. BEGIN_FTR_SECTION
  604. CHECK_HMI_INTERRUPT
  605. END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
  606. ld r1,PACAR1(r13)
  607. ld r6,_CCR(r1)
  608. ld r4,_MSR(r1)
  609. ld r5,_NIP(r1)
  610. addi r1,r1,INT_FRAME_SIZE
  611. mtcr r6
  612. mtspr SPRN_SRR1,r4
  613. mtspr SPRN_SRR0,r5
  614. RFI_TO_KERNEL