idle_book3s.S 17 KB

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