book3s_hv_rmhandlers.S 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License, version 2, as
  4. * published by the Free Software Foundation.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. * GNU General Public License for more details.
  10. *
  11. * Copyright 2011 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com>
  12. *
  13. * Derived from book3s_rmhandlers.S and other files, which are:
  14. *
  15. * Copyright SUSE Linux Products GmbH 2009
  16. *
  17. * Authors: Alexander Graf <agraf@suse.de>
  18. */
  19. #include <asm/ppc_asm.h>
  20. #include <asm/kvm_asm.h>
  21. #include <asm/reg.h>
  22. #include <asm/mmu.h>
  23. #include <asm/page.h>
  24. #include <asm/ptrace.h>
  25. #include <asm/hvcall.h>
  26. #include <asm/asm-offsets.h>
  27. #include <asm/exception-64s.h>
  28. /*****************************************************************************
  29. * *
  30. * Real Mode handlers that need to be in the linear mapping *
  31. * *
  32. ****************************************************************************/
  33. .globl kvmppc_skip_interrupt
  34. kvmppc_skip_interrupt:
  35. mfspr r13,SPRN_SRR0
  36. addi r13,r13,4
  37. mtspr SPRN_SRR0,r13
  38. GET_SCRATCH0(r13)
  39. rfid
  40. b .
  41. .globl kvmppc_skip_Hinterrupt
  42. kvmppc_skip_Hinterrupt:
  43. mfspr r13,SPRN_HSRR0
  44. addi r13,r13,4
  45. mtspr SPRN_HSRR0,r13
  46. GET_SCRATCH0(r13)
  47. hrfid
  48. b .
  49. /*
  50. * Call kvmppc_hv_entry in real mode.
  51. * Must be called with interrupts hard-disabled.
  52. *
  53. * Input Registers:
  54. *
  55. * LR = return address to continue at after eventually re-enabling MMU
  56. */
  57. _GLOBAL(kvmppc_hv_entry_trampoline)
  58. mfmsr r10
  59. LOAD_REG_ADDR(r5, kvmppc_hv_entry)
  60. li r0,MSR_RI
  61. andc r0,r10,r0
  62. li r6,MSR_IR | MSR_DR
  63. andc r6,r10,r6
  64. mtmsrd r0,1 /* clear RI in MSR */
  65. mtsrr0 r5
  66. mtsrr1 r6
  67. RFI
  68. #define ULONG_SIZE 8
  69. #define VCPU_GPR(n) (VCPU_GPRS + (n * ULONG_SIZE))
  70. /******************************************************************************
  71. * *
  72. * Entry code *
  73. * *
  74. *****************************************************************************/
  75. #define XICS_XIRR 4
  76. #define XICS_QIRR 0xc
  77. /*
  78. * We come in here when wakened from nap mode on a secondary hw thread.
  79. * Relocation is off and most register values are lost.
  80. * r13 points to the PACA.
  81. */
  82. .globl kvm_start_guest
  83. kvm_start_guest:
  84. ld r1,PACAEMERGSP(r13)
  85. subi r1,r1,STACK_FRAME_OVERHEAD
  86. ld r2,PACATOC(r13)
  87. /* were we napping due to cede? */
  88. lbz r0,HSTATE_NAPPING(r13)
  89. cmpwi r0,0
  90. bne kvm_end_cede
  91. /* get vcpu pointer */
  92. ld r4, HSTATE_KVM_VCPU(r13)
  93. /* We got here with an IPI; clear it */
  94. ld r5, HSTATE_XICS_PHYS(r13)
  95. li r0, 0xff
  96. li r6, XICS_QIRR
  97. li r7, XICS_XIRR
  98. lwzcix r8, r5, r7 /* ack the interrupt */
  99. sync
  100. stbcix r0, r5, r6 /* clear it */
  101. stwcix r8, r5, r7 /* EOI it */
  102. /* NV GPR values from power7_idle() will no longer be valid */
  103. stb r0, PACA_NAPSTATELOST(r13)
  104. .global kvmppc_hv_entry
  105. kvmppc_hv_entry:
  106. /* Required state:
  107. *
  108. * R4 = vcpu pointer
  109. * MSR = ~IR|DR
  110. * R13 = PACA
  111. * R1 = host R1
  112. * all other volatile GPRS = free
  113. */
  114. mflr r0
  115. std r0, HSTATE_VMHANDLER(r13)
  116. ld r14, VCPU_GPR(r14)(r4)
  117. ld r15, VCPU_GPR(r15)(r4)
  118. ld r16, VCPU_GPR(r16)(r4)
  119. ld r17, VCPU_GPR(r17)(r4)
  120. ld r18, VCPU_GPR(r18)(r4)
  121. ld r19, VCPU_GPR(r19)(r4)
  122. ld r20, VCPU_GPR(r20)(r4)
  123. ld r21, VCPU_GPR(r21)(r4)
  124. ld r22, VCPU_GPR(r22)(r4)
  125. ld r23, VCPU_GPR(r23)(r4)
  126. ld r24, VCPU_GPR(r24)(r4)
  127. ld r25, VCPU_GPR(r25)(r4)
  128. ld r26, VCPU_GPR(r26)(r4)
  129. ld r27, VCPU_GPR(r27)(r4)
  130. ld r28, VCPU_GPR(r28)(r4)
  131. ld r29, VCPU_GPR(r29)(r4)
  132. ld r30, VCPU_GPR(r30)(r4)
  133. ld r31, VCPU_GPR(r31)(r4)
  134. /* Load guest PMU registers */
  135. /* R4 is live here (vcpu pointer) */
  136. li r3, 1
  137. sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */
  138. mtspr SPRN_MMCR0, r3 /* freeze all counters, disable ints */
  139. isync
  140. lwz r3, VCPU_PMC(r4) /* always load up guest PMU registers */
  141. lwz r5, VCPU_PMC + 4(r4) /* to prevent information leak */
  142. lwz r6, VCPU_PMC + 8(r4)
  143. lwz r7, VCPU_PMC + 12(r4)
  144. lwz r8, VCPU_PMC + 16(r4)
  145. lwz r9, VCPU_PMC + 20(r4)
  146. BEGIN_FTR_SECTION
  147. lwz r10, VCPU_PMC + 24(r4)
  148. lwz r11, VCPU_PMC + 28(r4)
  149. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
  150. mtspr SPRN_PMC1, r3
  151. mtspr SPRN_PMC2, r5
  152. mtspr SPRN_PMC3, r6
  153. mtspr SPRN_PMC4, r7
  154. mtspr SPRN_PMC5, r8
  155. mtspr SPRN_PMC6, r9
  156. BEGIN_FTR_SECTION
  157. mtspr SPRN_PMC7, r10
  158. mtspr SPRN_PMC8, r11
  159. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
  160. ld r3, VCPU_MMCR(r4)
  161. ld r5, VCPU_MMCR + 8(r4)
  162. ld r6, VCPU_MMCR + 16(r4)
  163. mtspr SPRN_MMCR1, r5
  164. mtspr SPRN_MMCRA, r6
  165. mtspr SPRN_MMCR0, r3
  166. isync
  167. /* Load up FP, VMX and VSX registers */
  168. bl kvmppc_load_fp
  169. BEGIN_FTR_SECTION
  170. /* Switch DSCR to guest value */
  171. ld r5, VCPU_DSCR(r4)
  172. mtspr SPRN_DSCR, r5
  173. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
  174. /*
  175. * Set the decrementer to the guest decrementer.
  176. */
  177. ld r8,VCPU_DEC_EXPIRES(r4)
  178. mftb r7
  179. subf r3,r7,r8
  180. mtspr SPRN_DEC,r3
  181. stw r3,VCPU_DEC(r4)
  182. ld r5, VCPU_SPRG0(r4)
  183. ld r6, VCPU_SPRG1(r4)
  184. ld r7, VCPU_SPRG2(r4)
  185. ld r8, VCPU_SPRG3(r4)
  186. mtspr SPRN_SPRG0, r5
  187. mtspr SPRN_SPRG1, r6
  188. mtspr SPRN_SPRG2, r7
  189. mtspr SPRN_SPRG3, r8
  190. /* Save R1 in the PACA */
  191. std r1, HSTATE_HOST_R1(r13)
  192. /* Increment yield count if they have a VPA */
  193. ld r3, VCPU_VPA(r4)
  194. cmpdi r3, 0
  195. beq 25f
  196. lwz r5, LPPACA_YIELDCOUNT(r3)
  197. addi r5, r5, 1
  198. stw r5, LPPACA_YIELDCOUNT(r3)
  199. 25:
  200. /* Load up DAR and DSISR */
  201. ld r5, VCPU_DAR(r4)
  202. lwz r6, VCPU_DSISR(r4)
  203. mtspr SPRN_DAR, r5
  204. mtspr SPRN_DSISR, r6
  205. /* Set partition DABR */
  206. li r5,3
  207. ld r6,VCPU_DABR(r4)
  208. mtspr SPRN_DABRX,r5
  209. mtspr SPRN_DABR,r6
  210. BEGIN_FTR_SECTION
  211. /* Restore AMR and UAMOR, set AMOR to all 1s */
  212. ld r5,VCPU_AMR(r4)
  213. ld r6,VCPU_UAMOR(r4)
  214. li r7,-1
  215. mtspr SPRN_AMR,r5
  216. mtspr SPRN_UAMOR,r6
  217. mtspr SPRN_AMOR,r7
  218. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
  219. /* Clear out SLB */
  220. li r6,0
  221. slbmte r6,r6
  222. slbia
  223. ptesync
  224. BEGIN_FTR_SECTION
  225. b 30f
  226. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
  227. /*
  228. * POWER7 host -> guest partition switch code.
  229. * We don't have to lock against concurrent tlbies,
  230. * but we do have to coordinate across hardware threads.
  231. */
  232. /* Increment entry count iff exit count is zero. */
  233. ld r5,HSTATE_KVM_VCORE(r13)
  234. addi r9,r5,VCORE_ENTRY_EXIT
  235. 21: lwarx r3,0,r9
  236. cmpwi r3,0x100 /* any threads starting to exit? */
  237. bge secondary_too_late /* if so we're too late to the party */
  238. addi r3,r3,1
  239. stwcx. r3,0,r9
  240. bne 21b
  241. /* Primary thread switches to guest partition. */
  242. ld r9,VCPU_KVM(r4) /* pointer to struct kvm */
  243. lwz r6,VCPU_PTID(r4)
  244. cmpwi r6,0
  245. bne 20f
  246. ld r6,KVM_SDR1(r9)
  247. lwz r7,KVM_LPID(r9)
  248. li r0,LPID_RSVD /* switch to reserved LPID */
  249. mtspr SPRN_LPID,r0
  250. ptesync
  251. mtspr SPRN_SDR1,r6 /* switch to partition page table */
  252. mtspr SPRN_LPID,r7
  253. isync
  254. li r0,1
  255. stb r0,VCORE_IN_GUEST(r5) /* signal secondaries to continue */
  256. b 10f
  257. /* Secondary threads wait for primary to have done partition switch */
  258. 20: lbz r0,VCORE_IN_GUEST(r5)
  259. cmpwi r0,0
  260. beq 20b
  261. /* Set LPCR and RMOR. */
  262. 10: ld r8,KVM_LPCR(r9)
  263. mtspr SPRN_LPCR,r8
  264. ld r8,KVM_RMOR(r9)
  265. mtspr SPRN_RMOR,r8
  266. isync
  267. /* Check if HDEC expires soon */
  268. mfspr r3,SPRN_HDEC
  269. cmpwi r3,10
  270. li r12,BOOK3S_INTERRUPT_HV_DECREMENTER
  271. mr r9,r4
  272. blt hdec_soon
  273. /*
  274. * Invalidate the TLB if we could possibly have stale TLB
  275. * entries for this partition on this core due to the use
  276. * of tlbiel.
  277. * XXX maybe only need this on primary thread?
  278. */
  279. ld r9,VCPU_KVM(r4) /* pointer to struct kvm */
  280. lwz r5,VCPU_VCPUID(r4)
  281. lhz r6,PACAPACAINDEX(r13)
  282. rldimi r6,r5,0,62 /* XXX map as if threads 1:1 p:v */
  283. lhz r8,VCPU_LAST_CPU(r4)
  284. sldi r7,r6,1 /* see if this is the same vcpu */
  285. add r7,r7,r9 /* as last ran on this pcpu */
  286. lhz r0,KVM_LAST_VCPU(r7)
  287. cmpw r6,r8 /* on the same cpu core as last time? */
  288. bne 3f
  289. cmpw r0,r5 /* same vcpu as this core last ran? */
  290. beq 1f
  291. 3: sth r6,VCPU_LAST_CPU(r4) /* if not, invalidate partition TLB */
  292. sth r5,KVM_LAST_VCPU(r7)
  293. li r6,128
  294. mtctr r6
  295. li r7,0x800 /* IS field = 0b10 */
  296. ptesync
  297. 2: tlbiel r7
  298. addi r7,r7,0x1000
  299. bdnz 2b
  300. ptesync
  301. 1:
  302. /* Save purr/spurr */
  303. mfspr r5,SPRN_PURR
  304. mfspr r6,SPRN_SPURR
  305. std r5,HSTATE_PURR(r13)
  306. std r6,HSTATE_SPURR(r13)
  307. ld r7,VCPU_PURR(r4)
  308. ld r8,VCPU_SPURR(r4)
  309. mtspr SPRN_PURR,r7
  310. mtspr SPRN_SPURR,r8
  311. b 31f
  312. /*
  313. * PPC970 host -> guest partition switch code.
  314. * We have to lock against concurrent tlbies,
  315. * using native_tlbie_lock to lock against host tlbies
  316. * and kvm->arch.tlbie_lock to lock against guest tlbies.
  317. * We also have to invalidate the TLB since its
  318. * entries aren't tagged with the LPID.
  319. */
  320. 30: ld r9,VCPU_KVM(r4) /* pointer to struct kvm */
  321. /* first take native_tlbie_lock */
  322. .section ".toc","aw"
  323. toc_tlbie_lock:
  324. .tc native_tlbie_lock[TC],native_tlbie_lock
  325. .previous
  326. ld r3,toc_tlbie_lock@toc(2)
  327. lwz r8,PACA_LOCK_TOKEN(r13)
  328. 24: lwarx r0,0,r3
  329. cmpwi r0,0
  330. bne 24b
  331. stwcx. r8,0,r3
  332. bne 24b
  333. isync
  334. ld r7,KVM_LPCR(r9) /* use kvm->arch.lpcr to store HID4 */
  335. li r0,0x18f
  336. rotldi r0,r0,HID4_LPID5_SH /* all lpid bits in HID4 = 1 */
  337. or r0,r7,r0
  338. ptesync
  339. sync
  340. mtspr SPRN_HID4,r0 /* switch to reserved LPID */
  341. isync
  342. li r0,0
  343. stw r0,0(r3) /* drop native_tlbie_lock */
  344. /* invalidate the whole TLB */
  345. li r0,256
  346. mtctr r0
  347. li r6,0
  348. 25: tlbiel r6
  349. addi r6,r6,0x1000
  350. bdnz 25b
  351. ptesync
  352. /* Take the guest's tlbie_lock */
  353. addi r3,r9,KVM_TLBIE_LOCK
  354. 24: lwarx r0,0,r3
  355. cmpwi r0,0
  356. bne 24b
  357. stwcx. r8,0,r3
  358. bne 24b
  359. isync
  360. ld r6,KVM_SDR1(r9)
  361. mtspr SPRN_SDR1,r6 /* switch to partition page table */
  362. /* Set up HID4 with the guest's LPID etc. */
  363. sync
  364. mtspr SPRN_HID4,r7
  365. isync
  366. /* drop the guest's tlbie_lock */
  367. li r0,0
  368. stw r0,0(r3)
  369. /* Check if HDEC expires soon */
  370. mfspr r3,SPRN_HDEC
  371. cmpwi r3,10
  372. li r12,BOOK3S_INTERRUPT_HV_DECREMENTER
  373. mr r9,r4
  374. blt hdec_soon
  375. /* Enable HDEC interrupts */
  376. mfspr r0,SPRN_HID0
  377. li r3,1
  378. rldimi r0,r3, HID0_HDICE_SH, 64-HID0_HDICE_SH-1
  379. sync
  380. mtspr SPRN_HID0,r0
  381. mfspr r0,SPRN_HID0
  382. mfspr r0,SPRN_HID0
  383. mfspr r0,SPRN_HID0
  384. mfspr r0,SPRN_HID0
  385. mfspr r0,SPRN_HID0
  386. mfspr r0,SPRN_HID0
  387. /* Load up guest SLB entries */
  388. 31: lwz r5,VCPU_SLB_MAX(r4)
  389. cmpwi r5,0
  390. beq 9f
  391. mtctr r5
  392. addi r6,r4,VCPU_SLB
  393. 1: ld r8,VCPU_SLB_E(r6)
  394. ld r9,VCPU_SLB_V(r6)
  395. slbmte r9,r8
  396. addi r6,r6,VCPU_SLB_SIZE
  397. bdnz 1b
  398. 9:
  399. /* Restore state of CTRL run bit; assume 1 on entry */
  400. lwz r5,VCPU_CTRL(r4)
  401. andi. r5,r5,1
  402. bne 4f
  403. mfspr r6,SPRN_CTRLF
  404. clrrdi r6,r6,1
  405. mtspr SPRN_CTRLT,r6
  406. 4:
  407. ld r6, VCPU_CTR(r4)
  408. lwz r7, VCPU_XER(r4)
  409. mtctr r6
  410. mtxer r7
  411. kvmppc_cede_reentry: /* r4 = vcpu, r13 = paca */
  412. ld r6, VCPU_SRR0(r4)
  413. ld r7, VCPU_SRR1(r4)
  414. ld r10, VCPU_PC(r4)
  415. ld r11, VCPU_MSR(r4) /* r11 = vcpu->arch.msr & ~MSR_HV */
  416. rldicl r11, r11, 63 - MSR_HV_LG, 1
  417. rotldi r11, r11, 1 + MSR_HV_LG
  418. ori r11, r11, MSR_ME
  419. /* Check if we can deliver an external or decrementer interrupt now */
  420. ld r0,VCPU_PENDING_EXC(r4)
  421. li r8,(1 << BOOK3S_IRQPRIO_EXTERNAL)
  422. oris r8,r8,(1 << BOOK3S_IRQPRIO_EXTERNAL_LEVEL)@h
  423. and r0,r0,r8
  424. cmpdi cr1,r0,0
  425. andi. r0,r11,MSR_EE
  426. beq cr1,11f
  427. BEGIN_FTR_SECTION
  428. mfspr r8,SPRN_LPCR
  429. ori r8,r8,LPCR_MER
  430. mtspr SPRN_LPCR,r8
  431. isync
  432. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
  433. beq 5f
  434. li r0,BOOK3S_INTERRUPT_EXTERNAL
  435. 12: mr r6,r10
  436. mr r10,r0
  437. mr r7,r11
  438. li r11,(MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */
  439. rotldi r11,r11,63
  440. b 5f
  441. 11: beq 5f
  442. mfspr r0,SPRN_DEC
  443. cmpwi r0,0
  444. li r0,BOOK3S_INTERRUPT_DECREMENTER
  445. blt 12b
  446. /* Move SRR0 and SRR1 into the respective regs */
  447. 5: mtspr SPRN_SRR0, r6
  448. mtspr SPRN_SRR1, r7
  449. li r0,0
  450. stb r0,VCPU_CEDED(r4) /* cancel cede */
  451. fast_guest_return:
  452. mtspr SPRN_HSRR0,r10
  453. mtspr SPRN_HSRR1,r11
  454. /* Activate guest mode, so faults get handled by KVM */
  455. li r9, KVM_GUEST_MODE_GUEST
  456. stb r9, HSTATE_IN_GUEST(r13)
  457. /* Enter guest */
  458. ld r5, VCPU_LR(r4)
  459. lwz r6, VCPU_CR(r4)
  460. mtlr r5
  461. mtcr r6
  462. ld r0, VCPU_GPR(r0)(r4)
  463. ld r1, VCPU_GPR(r1)(r4)
  464. ld r2, VCPU_GPR(r2)(r4)
  465. ld r3, VCPU_GPR(r3)(r4)
  466. ld r5, VCPU_GPR(r5)(r4)
  467. ld r6, VCPU_GPR(r6)(r4)
  468. ld r7, VCPU_GPR(r7)(r4)
  469. ld r8, VCPU_GPR(r8)(r4)
  470. ld r9, VCPU_GPR(r9)(r4)
  471. ld r10, VCPU_GPR(r10)(r4)
  472. ld r11, VCPU_GPR(r11)(r4)
  473. ld r12, VCPU_GPR(r12)(r4)
  474. ld r13, VCPU_GPR(r13)(r4)
  475. ld r4, VCPU_GPR(r4)(r4)
  476. hrfid
  477. b .
  478. /******************************************************************************
  479. * *
  480. * Exit code *
  481. * *
  482. *****************************************************************************/
  483. /*
  484. * We come here from the first-level interrupt handlers.
  485. */
  486. .globl kvmppc_interrupt
  487. kvmppc_interrupt:
  488. /*
  489. * Register contents:
  490. * R12 = interrupt vector
  491. * R13 = PACA
  492. * guest CR, R12 saved in shadow VCPU SCRATCH1/0
  493. * guest R13 saved in SPRN_SCRATCH0
  494. */
  495. /* abuse host_r2 as third scratch area; we get r2 from PACATOC(r13) */
  496. std r9, HSTATE_HOST_R2(r13)
  497. ld r9, HSTATE_KVM_VCPU(r13)
  498. /* Save registers */
  499. std r0, VCPU_GPR(r0)(r9)
  500. std r1, VCPU_GPR(r1)(r9)
  501. std r2, VCPU_GPR(r2)(r9)
  502. std r3, VCPU_GPR(r3)(r9)
  503. std r4, VCPU_GPR(r4)(r9)
  504. std r5, VCPU_GPR(r5)(r9)
  505. std r6, VCPU_GPR(r6)(r9)
  506. std r7, VCPU_GPR(r7)(r9)
  507. std r8, VCPU_GPR(r8)(r9)
  508. ld r0, HSTATE_HOST_R2(r13)
  509. std r0, VCPU_GPR(r9)(r9)
  510. std r10, VCPU_GPR(r10)(r9)
  511. std r11, VCPU_GPR(r11)(r9)
  512. ld r3, HSTATE_SCRATCH0(r13)
  513. lwz r4, HSTATE_SCRATCH1(r13)
  514. std r3, VCPU_GPR(r12)(r9)
  515. stw r4, VCPU_CR(r9)
  516. /* Restore R1/R2 so we can handle faults */
  517. ld r1, HSTATE_HOST_R1(r13)
  518. ld r2, PACATOC(r13)
  519. mfspr r10, SPRN_SRR0
  520. mfspr r11, SPRN_SRR1
  521. std r10, VCPU_SRR0(r9)
  522. std r11, VCPU_SRR1(r9)
  523. andi. r0, r12, 2 /* need to read HSRR0/1? */
  524. beq 1f
  525. mfspr r10, SPRN_HSRR0
  526. mfspr r11, SPRN_HSRR1
  527. clrrdi r12, r12, 2
  528. 1: std r10, VCPU_PC(r9)
  529. std r11, VCPU_MSR(r9)
  530. GET_SCRATCH0(r3)
  531. mflr r4
  532. std r3, VCPU_GPR(r13)(r9)
  533. std r4, VCPU_LR(r9)
  534. /* Unset guest mode */
  535. li r0, KVM_GUEST_MODE_NONE
  536. stb r0, HSTATE_IN_GUEST(r13)
  537. stw r12,VCPU_TRAP(r9)
  538. /* Save HEIR (HV emulation assist reg) in last_inst
  539. if this is an HEI (HV emulation interrupt, e40) */
  540. li r3,KVM_INST_FETCH_FAILED
  541. BEGIN_FTR_SECTION
  542. cmpwi r12,BOOK3S_INTERRUPT_H_EMUL_ASSIST
  543. bne 11f
  544. mfspr r3,SPRN_HEIR
  545. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
  546. 11: stw r3,VCPU_LAST_INST(r9)
  547. /* these are volatile across C function calls */
  548. mfctr r3
  549. mfxer r4
  550. std r3, VCPU_CTR(r9)
  551. stw r4, VCPU_XER(r9)
  552. BEGIN_FTR_SECTION
  553. /* If this is a page table miss then see if it's theirs or ours */
  554. cmpwi r12, BOOK3S_INTERRUPT_H_DATA_STORAGE
  555. beq kvmppc_hdsi
  556. cmpwi r12, BOOK3S_INTERRUPT_H_INST_STORAGE
  557. beq kvmppc_hisi
  558. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
  559. /* See if this is a leftover HDEC interrupt */
  560. cmpwi r12,BOOK3S_INTERRUPT_HV_DECREMENTER
  561. bne 2f
  562. mfspr r3,SPRN_HDEC
  563. cmpwi r3,0
  564. bge ignore_hdec
  565. 2:
  566. /* See if this is an hcall we can handle in real mode */
  567. cmpwi r12,BOOK3S_INTERRUPT_SYSCALL
  568. beq hcall_try_real_mode
  569. /* Check for mediated interrupts (could be done earlier really ...) */
  570. BEGIN_FTR_SECTION
  571. cmpwi r12,BOOK3S_INTERRUPT_EXTERNAL
  572. bne+ 1f
  573. andi. r0,r11,MSR_EE
  574. beq 1f
  575. mfspr r5,SPRN_LPCR
  576. andi. r0,r5,LPCR_MER
  577. bne bounce_ext_interrupt
  578. 1:
  579. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
  580. nohpte_cont:
  581. hcall_real_cont: /* r9 = vcpu, r12 = trap, r13 = paca */
  582. /* Save DEC */
  583. mfspr r5,SPRN_DEC
  584. mftb r6
  585. extsw r5,r5
  586. add r5,r5,r6
  587. std r5,VCPU_DEC_EXPIRES(r9)
  588. /* Save more register state */
  589. mfdar r6
  590. mfdsisr r7
  591. std r6, VCPU_DAR(r9)
  592. stw r7, VCPU_DSISR(r9)
  593. BEGIN_FTR_SECTION
  594. /* don't overwrite fault_dar/fault_dsisr if HDSI */
  595. cmpwi r12,BOOK3S_INTERRUPT_H_DATA_STORAGE
  596. beq 6f
  597. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
  598. std r6, VCPU_FAULT_DAR(r9)
  599. stw r7, VCPU_FAULT_DSISR(r9)
  600. /* Save guest CTRL register, set runlatch to 1 */
  601. 6: mfspr r6,SPRN_CTRLF
  602. stw r6,VCPU_CTRL(r9)
  603. andi. r0,r6,1
  604. bne 4f
  605. ori r6,r6,1
  606. mtspr SPRN_CTRLT,r6
  607. 4:
  608. /* Read the guest SLB and save it away */
  609. lwz r0,VCPU_SLB_NR(r9) /* number of entries in SLB */
  610. mtctr r0
  611. li r6,0
  612. addi r7,r9,VCPU_SLB
  613. li r5,0
  614. 1: slbmfee r8,r6
  615. andis. r0,r8,SLB_ESID_V@h
  616. beq 2f
  617. add r8,r8,r6 /* put index in */
  618. slbmfev r3,r6
  619. std r8,VCPU_SLB_E(r7)
  620. std r3,VCPU_SLB_V(r7)
  621. addi r7,r7,VCPU_SLB_SIZE
  622. addi r5,r5,1
  623. 2: addi r6,r6,1
  624. bdnz 1b
  625. stw r5,VCPU_SLB_MAX(r9)
  626. /*
  627. * Save the guest PURR/SPURR
  628. */
  629. BEGIN_FTR_SECTION
  630. mfspr r5,SPRN_PURR
  631. mfspr r6,SPRN_SPURR
  632. ld r7,VCPU_PURR(r9)
  633. ld r8,VCPU_SPURR(r9)
  634. std r5,VCPU_PURR(r9)
  635. std r6,VCPU_SPURR(r9)
  636. subf r5,r7,r5
  637. subf r6,r8,r6
  638. /*
  639. * Restore host PURR/SPURR and add guest times
  640. * so that the time in the guest gets accounted.
  641. */
  642. ld r3,HSTATE_PURR(r13)
  643. ld r4,HSTATE_SPURR(r13)
  644. add r3,r3,r5
  645. add r4,r4,r6
  646. mtspr SPRN_PURR,r3
  647. mtspr SPRN_SPURR,r4
  648. END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_201)
  649. /* Clear out SLB */
  650. li r5,0
  651. slbmte r5,r5
  652. slbia
  653. ptesync
  654. hdec_soon: /* r9 = vcpu, r12 = trap, r13 = paca */
  655. BEGIN_FTR_SECTION
  656. b 32f
  657. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
  658. /*
  659. * POWER7 guest -> host partition switch code.
  660. * We don't have to lock against tlbies but we do
  661. * have to coordinate the hardware threads.
  662. */
  663. /* Increment the threads-exiting-guest count in the 0xff00
  664. bits of vcore->entry_exit_count */
  665. lwsync
  666. ld r5,HSTATE_KVM_VCORE(r13)
  667. addi r6,r5,VCORE_ENTRY_EXIT
  668. 41: lwarx r3,0,r6
  669. addi r0,r3,0x100
  670. stwcx. r0,0,r6
  671. bne 41b
  672. lwsync
  673. /*
  674. * At this point we have an interrupt that we have to pass
  675. * up to the kernel or qemu; we can't handle it in real mode.
  676. * Thus we have to do a partition switch, so we have to
  677. * collect the other threads, if we are the first thread
  678. * to take an interrupt. To do this, we set the HDEC to 0,
  679. * which causes an HDEC interrupt in all threads within 2ns
  680. * because the HDEC register is shared between all 4 threads.
  681. * However, we don't need to bother if this is an HDEC
  682. * interrupt, since the other threads will already be on their
  683. * way here in that case.
  684. */
  685. cmpwi r3,0x100 /* Are we the first here? */
  686. bge 43f
  687. cmpwi r3,1 /* Are any other threads in the guest? */
  688. ble 43f
  689. cmpwi r12,BOOK3S_INTERRUPT_HV_DECREMENTER
  690. beq 40f
  691. li r0,0
  692. mtspr SPRN_HDEC,r0
  693. 40:
  694. /*
  695. * Send an IPI to any napping threads, since an HDEC interrupt
  696. * doesn't wake CPUs up from nap.
  697. */
  698. lwz r3,VCORE_NAPPING_THREADS(r5)
  699. lwz r4,VCPU_PTID(r9)
  700. li r0,1
  701. sld r0,r0,r4
  702. andc. r3,r3,r0 /* no sense IPI'ing ourselves */
  703. beq 43f
  704. mulli r4,r4,PACA_SIZE /* get paca for thread 0 */
  705. subf r6,r4,r13
  706. 42: andi. r0,r3,1
  707. beq 44f
  708. ld r8,HSTATE_XICS_PHYS(r6) /* get thread's XICS reg addr */
  709. li r0,IPI_PRIORITY
  710. li r7,XICS_QIRR
  711. stbcix r0,r7,r8 /* trigger the IPI */
  712. 44: srdi. r3,r3,1
  713. addi r6,r6,PACA_SIZE
  714. bne 42b
  715. /* Secondary threads wait for primary to do partition switch */
  716. 43: ld r4,VCPU_KVM(r9) /* pointer to struct kvm */
  717. ld r5,HSTATE_KVM_VCORE(r13)
  718. lwz r3,VCPU_PTID(r9)
  719. cmpwi r3,0
  720. beq 15f
  721. HMT_LOW
  722. 13: lbz r3,VCORE_IN_GUEST(r5)
  723. cmpwi r3,0
  724. bne 13b
  725. HMT_MEDIUM
  726. b 16f
  727. /* Primary thread waits for all the secondaries to exit guest */
  728. 15: lwz r3,VCORE_ENTRY_EXIT(r5)
  729. srwi r0,r3,8
  730. clrldi r3,r3,56
  731. cmpw r3,r0
  732. bne 15b
  733. isync
  734. /* Primary thread switches back to host partition */
  735. ld r6,KVM_HOST_SDR1(r4)
  736. lwz r7,KVM_HOST_LPID(r4)
  737. li r8,LPID_RSVD /* switch to reserved LPID */
  738. mtspr SPRN_LPID,r8
  739. ptesync
  740. mtspr SPRN_SDR1,r6 /* switch to partition page table */
  741. mtspr SPRN_LPID,r7
  742. isync
  743. li r0,0
  744. stb r0,VCORE_IN_GUEST(r5)
  745. lis r8,0x7fff /* MAX_INT@h */
  746. mtspr SPRN_HDEC,r8
  747. 16: ld r8,KVM_HOST_LPCR(r4)
  748. mtspr SPRN_LPCR,r8
  749. isync
  750. b 33f
  751. /*
  752. * PPC970 guest -> host partition switch code.
  753. * We have to lock against concurrent tlbies, and
  754. * we have to flush the whole TLB.
  755. */
  756. 32: ld r4,VCPU_KVM(r9) /* pointer to struct kvm */
  757. /* Take the guest's tlbie_lock */
  758. lwz r8,PACA_LOCK_TOKEN(r13)
  759. addi r3,r4,KVM_TLBIE_LOCK
  760. 24: lwarx r0,0,r3
  761. cmpwi r0,0
  762. bne 24b
  763. stwcx. r8,0,r3
  764. bne 24b
  765. isync
  766. ld r7,KVM_HOST_LPCR(r4) /* use kvm->arch.host_lpcr for HID4 */
  767. li r0,0x18f
  768. rotldi r0,r0,HID4_LPID5_SH /* all lpid bits in HID4 = 1 */
  769. or r0,r7,r0
  770. ptesync
  771. sync
  772. mtspr SPRN_HID4,r0 /* switch to reserved LPID */
  773. isync
  774. li r0,0
  775. stw r0,0(r3) /* drop guest tlbie_lock */
  776. /* invalidate the whole TLB */
  777. li r0,256
  778. mtctr r0
  779. li r6,0
  780. 25: tlbiel r6
  781. addi r6,r6,0x1000
  782. bdnz 25b
  783. ptesync
  784. /* take native_tlbie_lock */
  785. ld r3,toc_tlbie_lock@toc(2)
  786. 24: lwarx r0,0,r3
  787. cmpwi r0,0
  788. bne 24b
  789. stwcx. r8,0,r3
  790. bne 24b
  791. isync
  792. ld r6,KVM_HOST_SDR1(r4)
  793. mtspr SPRN_SDR1,r6 /* switch to host page table */
  794. /* Set up host HID4 value */
  795. sync
  796. mtspr SPRN_HID4,r7
  797. isync
  798. li r0,0
  799. stw r0,0(r3) /* drop native_tlbie_lock */
  800. lis r8,0x7fff /* MAX_INT@h */
  801. mtspr SPRN_HDEC,r8
  802. /* Disable HDEC interrupts */
  803. mfspr r0,SPRN_HID0
  804. li r3,0
  805. rldimi r0,r3, HID0_HDICE_SH, 64-HID0_HDICE_SH-1
  806. sync
  807. mtspr SPRN_HID0,r0
  808. mfspr r0,SPRN_HID0
  809. mfspr r0,SPRN_HID0
  810. mfspr r0,SPRN_HID0
  811. mfspr r0,SPRN_HID0
  812. mfspr r0,SPRN_HID0
  813. mfspr r0,SPRN_HID0
  814. /* load host SLB entries */
  815. 33: ld r8,PACA_SLBSHADOWPTR(r13)
  816. .rept SLB_NUM_BOLTED
  817. ld r5,SLBSHADOW_SAVEAREA(r8)
  818. ld r6,SLBSHADOW_SAVEAREA+8(r8)
  819. andis. r7,r5,SLB_ESID_V@h
  820. beq 1f
  821. slbmte r6,r5
  822. 1: addi r8,r8,16
  823. .endr
  824. /* Save and reset AMR and UAMOR before turning on the MMU */
  825. BEGIN_FTR_SECTION
  826. mfspr r5,SPRN_AMR
  827. mfspr r6,SPRN_UAMOR
  828. std r5,VCPU_AMR(r9)
  829. std r6,VCPU_UAMOR(r9)
  830. li r6,0
  831. mtspr SPRN_AMR,r6
  832. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
  833. /* Restore host DABR and DABRX */
  834. ld r5,HSTATE_DABR(r13)
  835. li r6,7
  836. mtspr SPRN_DABR,r5
  837. mtspr SPRN_DABRX,r6
  838. /* Switch DSCR back to host value */
  839. BEGIN_FTR_SECTION
  840. mfspr r8, SPRN_DSCR
  841. ld r7, HSTATE_DSCR(r13)
  842. std r8, VCPU_DSCR(r9)
  843. mtspr SPRN_DSCR, r7
  844. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
  845. /* Save non-volatile GPRs */
  846. std r14, VCPU_GPR(r14)(r9)
  847. std r15, VCPU_GPR(r15)(r9)
  848. std r16, VCPU_GPR(r16)(r9)
  849. std r17, VCPU_GPR(r17)(r9)
  850. std r18, VCPU_GPR(r18)(r9)
  851. std r19, VCPU_GPR(r19)(r9)
  852. std r20, VCPU_GPR(r20)(r9)
  853. std r21, VCPU_GPR(r21)(r9)
  854. std r22, VCPU_GPR(r22)(r9)
  855. std r23, VCPU_GPR(r23)(r9)
  856. std r24, VCPU_GPR(r24)(r9)
  857. std r25, VCPU_GPR(r25)(r9)
  858. std r26, VCPU_GPR(r26)(r9)
  859. std r27, VCPU_GPR(r27)(r9)
  860. std r28, VCPU_GPR(r28)(r9)
  861. std r29, VCPU_GPR(r29)(r9)
  862. std r30, VCPU_GPR(r30)(r9)
  863. std r31, VCPU_GPR(r31)(r9)
  864. /* Save SPRGs */
  865. mfspr r3, SPRN_SPRG0
  866. mfspr r4, SPRN_SPRG1
  867. mfspr r5, SPRN_SPRG2
  868. mfspr r6, SPRN_SPRG3
  869. std r3, VCPU_SPRG0(r9)
  870. std r4, VCPU_SPRG1(r9)
  871. std r5, VCPU_SPRG2(r9)
  872. std r6, VCPU_SPRG3(r9)
  873. /* Increment yield count if they have a VPA */
  874. ld r8, VCPU_VPA(r9) /* do they have a VPA? */
  875. cmpdi r8, 0
  876. beq 25f
  877. lwz r3, LPPACA_YIELDCOUNT(r8)
  878. addi r3, r3, 1
  879. stw r3, LPPACA_YIELDCOUNT(r8)
  880. 25:
  881. /* Save PMU registers if requested */
  882. /* r8 and cr0.eq are live here */
  883. li r3, 1
  884. sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */
  885. mfspr r4, SPRN_MMCR0 /* save MMCR0 */
  886. mtspr SPRN_MMCR0, r3 /* freeze all counters, disable ints */
  887. isync
  888. beq 21f /* if no VPA, save PMU stuff anyway */
  889. lbz r7, LPPACA_PMCINUSE(r8)
  890. cmpwi r7, 0 /* did they ask for PMU stuff to be saved? */
  891. bne 21f
  892. std r3, VCPU_MMCR(r9) /* if not, set saved MMCR0 to FC */
  893. b 22f
  894. 21: mfspr r5, SPRN_MMCR1
  895. mfspr r6, SPRN_MMCRA
  896. std r4, VCPU_MMCR(r9)
  897. std r5, VCPU_MMCR + 8(r9)
  898. std r6, VCPU_MMCR + 16(r9)
  899. mfspr r3, SPRN_PMC1
  900. mfspr r4, SPRN_PMC2
  901. mfspr r5, SPRN_PMC3
  902. mfspr r6, SPRN_PMC4
  903. mfspr r7, SPRN_PMC5
  904. mfspr r8, SPRN_PMC6
  905. BEGIN_FTR_SECTION
  906. mfspr r10, SPRN_PMC7
  907. mfspr r11, SPRN_PMC8
  908. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
  909. stw r3, VCPU_PMC(r9)
  910. stw r4, VCPU_PMC + 4(r9)
  911. stw r5, VCPU_PMC + 8(r9)
  912. stw r6, VCPU_PMC + 12(r9)
  913. stw r7, VCPU_PMC + 16(r9)
  914. stw r8, VCPU_PMC + 20(r9)
  915. BEGIN_FTR_SECTION
  916. stw r10, VCPU_PMC + 24(r9)
  917. stw r11, VCPU_PMC + 28(r9)
  918. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
  919. 22:
  920. /* save FP state */
  921. mr r3, r9
  922. bl .kvmppc_save_fp
  923. /* Secondary threads go off to take a nap on POWER7 */
  924. BEGIN_FTR_SECTION
  925. lwz r0,VCPU_PTID(r3)
  926. cmpwi r0,0
  927. bne secondary_nap
  928. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
  929. /*
  930. * Reload DEC. HDEC interrupts were disabled when
  931. * we reloaded the host's LPCR value.
  932. */
  933. ld r3, HSTATE_DECEXP(r13)
  934. mftb r4
  935. subf r4, r4, r3
  936. mtspr SPRN_DEC, r4
  937. /* Reload the host's PMU registers */
  938. ld r3, PACALPPACAPTR(r13) /* is the host using the PMU? */
  939. lbz r4, LPPACA_PMCINUSE(r3)
  940. cmpwi r4, 0
  941. beq 23f /* skip if not */
  942. lwz r3, HSTATE_PMC(r13)
  943. lwz r4, HSTATE_PMC + 4(r13)
  944. lwz r5, HSTATE_PMC + 8(r13)
  945. lwz r6, HSTATE_PMC + 12(r13)
  946. lwz r8, HSTATE_PMC + 16(r13)
  947. lwz r9, HSTATE_PMC + 20(r13)
  948. BEGIN_FTR_SECTION
  949. lwz r10, HSTATE_PMC + 24(r13)
  950. lwz r11, HSTATE_PMC + 28(r13)
  951. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
  952. mtspr SPRN_PMC1, r3
  953. mtspr SPRN_PMC2, r4
  954. mtspr SPRN_PMC3, r5
  955. mtspr SPRN_PMC4, r6
  956. mtspr SPRN_PMC5, r8
  957. mtspr SPRN_PMC6, r9
  958. BEGIN_FTR_SECTION
  959. mtspr SPRN_PMC7, r10
  960. mtspr SPRN_PMC8, r11
  961. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
  962. ld r3, HSTATE_MMCR(r13)
  963. ld r4, HSTATE_MMCR + 8(r13)
  964. ld r5, HSTATE_MMCR + 16(r13)
  965. mtspr SPRN_MMCR1, r4
  966. mtspr SPRN_MMCRA, r5
  967. mtspr SPRN_MMCR0, r3
  968. isync
  969. 23:
  970. /*
  971. * For external and machine check interrupts, we need
  972. * to call the Linux handler to process the interrupt.
  973. * We do that by jumping to the interrupt vector address
  974. * which we have in r12. The [h]rfid at the end of the
  975. * handler will return to the book3s_hv_interrupts.S code.
  976. * For other interrupts we do the rfid to get back
  977. * to the book3s_interrupts.S code here.
  978. */
  979. ld r8, HSTATE_VMHANDLER(r13)
  980. ld r7, HSTATE_HOST_MSR(r13)
  981. cmpwi r12, BOOK3S_INTERRUPT_EXTERNAL
  982. beq 11f
  983. cmpwi r12, BOOK3S_INTERRUPT_MACHINE_CHECK
  984. /* RFI into the highmem handler, or branch to interrupt handler */
  985. 12: mfmsr r6
  986. mtctr r12
  987. li r0, MSR_RI
  988. andc r6, r6, r0
  989. mtmsrd r6, 1 /* Clear RI in MSR */
  990. mtsrr0 r8
  991. mtsrr1 r7
  992. beqctr
  993. RFI
  994. 11:
  995. BEGIN_FTR_SECTION
  996. b 12b
  997. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
  998. mtspr SPRN_HSRR0, r8
  999. mtspr SPRN_HSRR1, r7
  1000. ba 0x500
  1001. /*
  1002. * Check whether an HDSI is an HPTE not found fault or something else.
  1003. * If it is an HPTE not found fault that is due to the guest accessing
  1004. * a page that they have mapped but which we have paged out, then
  1005. * we continue on with the guest exit path. In all other cases,
  1006. * reflect the HDSI to the guest as a DSI.
  1007. */
  1008. kvmppc_hdsi:
  1009. mfspr r4, SPRN_HDAR
  1010. mfspr r6, SPRN_HDSISR
  1011. /* HPTE not found fault or protection fault? */
  1012. andis. r0, r6, (DSISR_NOHPTE | DSISR_PROTFAULT)@h
  1013. beq 1f /* if not, send it to the guest */
  1014. andi. r0, r11, MSR_DR /* data relocation enabled? */
  1015. beq 3f
  1016. clrrdi r0, r4, 28
  1017. PPC_SLBFEE_DOT(r5, r0) /* if so, look up SLB */
  1018. bne 1f /* if no SLB entry found */
  1019. 4: std r4, VCPU_FAULT_DAR(r9)
  1020. stw r6, VCPU_FAULT_DSISR(r9)
  1021. /* Search the hash table. */
  1022. mr r3, r9 /* vcpu pointer */
  1023. li r7, 1 /* data fault */
  1024. bl .kvmppc_hpte_hv_fault
  1025. ld r9, HSTATE_KVM_VCPU(r13)
  1026. ld r10, VCPU_PC(r9)
  1027. ld r11, VCPU_MSR(r9)
  1028. li r12, BOOK3S_INTERRUPT_H_DATA_STORAGE
  1029. cmpdi r3, 0 /* retry the instruction */
  1030. beq 6f
  1031. cmpdi r3, -1 /* handle in kernel mode */
  1032. beq nohpte_cont
  1033. cmpdi r3, -2 /* MMIO emulation; need instr word */
  1034. beq 2f
  1035. /* Synthesize a DSI for the guest */
  1036. ld r4, VCPU_FAULT_DAR(r9)
  1037. mr r6, r3
  1038. 1: mtspr SPRN_DAR, r4
  1039. mtspr SPRN_DSISR, r6
  1040. mtspr SPRN_SRR0, r10
  1041. mtspr SPRN_SRR1, r11
  1042. li r10, BOOK3S_INTERRUPT_DATA_STORAGE
  1043. li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */
  1044. rotldi r11, r11, 63
  1045. 6: ld r7, VCPU_CTR(r9)
  1046. lwz r8, VCPU_XER(r9)
  1047. mtctr r7
  1048. mtxer r8
  1049. mr r4, r9
  1050. b fast_guest_return
  1051. 3: ld r5, VCPU_KVM(r9) /* not relocated, use VRMA */
  1052. ld r5, KVM_VRMA_SLB_V(r5)
  1053. b 4b
  1054. /* If this is for emulated MMIO, load the instruction word */
  1055. 2: li r8, KVM_INST_FETCH_FAILED /* In case lwz faults */
  1056. /* Set guest mode to 'jump over instruction' so if lwz faults
  1057. * we'll just continue at the next IP. */
  1058. li r0, KVM_GUEST_MODE_SKIP
  1059. stb r0, HSTATE_IN_GUEST(r13)
  1060. /* Do the access with MSR:DR enabled */
  1061. mfmsr r3
  1062. ori r4, r3, MSR_DR /* Enable paging for data */
  1063. mtmsrd r4
  1064. lwz r8, 0(r10)
  1065. mtmsrd r3
  1066. /* Store the result */
  1067. stw r8, VCPU_LAST_INST(r9)
  1068. /* Unset guest mode. */
  1069. li r0, KVM_GUEST_MODE_NONE
  1070. stb r0, HSTATE_IN_GUEST(r13)
  1071. b nohpte_cont
  1072. /*
  1073. * Similarly for an HISI, reflect it to the guest as an ISI unless
  1074. * it is an HPTE not found fault for a page that we have paged out.
  1075. */
  1076. kvmppc_hisi:
  1077. andis. r0, r11, SRR1_ISI_NOPT@h
  1078. beq 1f
  1079. andi. r0, r11, MSR_IR /* instruction relocation enabled? */
  1080. beq 3f
  1081. clrrdi r0, r10, 28
  1082. PPC_SLBFEE_DOT(r5, r0) /* if so, look up SLB */
  1083. bne 1f /* if no SLB entry found */
  1084. 4:
  1085. /* Search the hash table. */
  1086. mr r3, r9 /* vcpu pointer */
  1087. mr r4, r10
  1088. mr r6, r11
  1089. li r7, 0 /* instruction fault */
  1090. bl .kvmppc_hpte_hv_fault
  1091. ld r9, HSTATE_KVM_VCPU(r13)
  1092. ld r10, VCPU_PC(r9)
  1093. ld r11, VCPU_MSR(r9)
  1094. li r12, BOOK3S_INTERRUPT_H_INST_STORAGE
  1095. cmpdi r3, 0 /* retry the instruction */
  1096. beq 6f
  1097. cmpdi r3, -1 /* handle in kernel mode */
  1098. beq nohpte_cont
  1099. /* Synthesize an ISI for the guest */
  1100. mr r11, r3
  1101. 1: mtspr SPRN_SRR0, r10
  1102. mtspr SPRN_SRR1, r11
  1103. li r10, BOOK3S_INTERRUPT_INST_STORAGE
  1104. li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */
  1105. rotldi r11, r11, 63
  1106. 6: ld r7, VCPU_CTR(r9)
  1107. lwz r8, VCPU_XER(r9)
  1108. mtctr r7
  1109. mtxer r8
  1110. mr r4, r9
  1111. b fast_guest_return
  1112. 3: ld r6, VCPU_KVM(r9) /* not relocated, use VRMA */
  1113. ld r5, KVM_VRMA_SLB_V(r6)
  1114. b 4b
  1115. /*
  1116. * Try to handle an hcall in real mode.
  1117. * Returns to the guest if we handle it, or continues on up to
  1118. * the kernel if we can't (i.e. if we don't have a handler for
  1119. * it, or if the handler returns H_TOO_HARD).
  1120. */
  1121. .globl hcall_try_real_mode
  1122. hcall_try_real_mode:
  1123. ld r3,VCPU_GPR(r3)(r9)
  1124. andi. r0,r11,MSR_PR
  1125. bne hcall_real_cont
  1126. clrrdi r3,r3,2
  1127. cmpldi r3,hcall_real_table_end - hcall_real_table
  1128. bge hcall_real_cont
  1129. LOAD_REG_ADDR(r4, hcall_real_table)
  1130. lwzx r3,r3,r4
  1131. cmpwi r3,0
  1132. beq hcall_real_cont
  1133. add r3,r3,r4
  1134. mtctr r3
  1135. mr r3,r9 /* get vcpu pointer */
  1136. ld r4,VCPU_GPR(r4)(r9)
  1137. bctrl
  1138. cmpdi r3,H_TOO_HARD
  1139. beq hcall_real_fallback
  1140. ld r4,HSTATE_KVM_VCPU(r13)
  1141. std r3,VCPU_GPR(r3)(r4)
  1142. ld r10,VCPU_PC(r4)
  1143. ld r11,VCPU_MSR(r4)
  1144. b fast_guest_return
  1145. /* We've attempted a real mode hcall, but it's punted it back
  1146. * to userspace. We need to restore some clobbered volatiles
  1147. * before resuming the pass-it-to-qemu path */
  1148. hcall_real_fallback:
  1149. li r12,BOOK3S_INTERRUPT_SYSCALL
  1150. ld r9, HSTATE_KVM_VCPU(r13)
  1151. b hcall_real_cont
  1152. .globl hcall_real_table
  1153. hcall_real_table:
  1154. .long 0 /* 0 - unused */
  1155. .long .kvmppc_h_remove - hcall_real_table
  1156. .long .kvmppc_h_enter - hcall_real_table
  1157. .long .kvmppc_h_read - hcall_real_table
  1158. .long 0 /* 0x10 - H_CLEAR_MOD */
  1159. .long 0 /* 0x14 - H_CLEAR_REF */
  1160. .long .kvmppc_h_protect - hcall_real_table
  1161. .long 0 /* 0x1c - H_GET_TCE */
  1162. .long .kvmppc_h_put_tce - hcall_real_table
  1163. .long 0 /* 0x24 - H_SET_SPRG0 */
  1164. .long .kvmppc_h_set_dabr - hcall_real_table
  1165. .long 0 /* 0x2c */
  1166. .long 0 /* 0x30 */
  1167. .long 0 /* 0x34 */
  1168. .long 0 /* 0x38 */
  1169. .long 0 /* 0x3c */
  1170. .long 0 /* 0x40 */
  1171. .long 0 /* 0x44 */
  1172. .long 0 /* 0x48 */
  1173. .long 0 /* 0x4c */
  1174. .long 0 /* 0x50 */
  1175. .long 0 /* 0x54 */
  1176. .long 0 /* 0x58 */
  1177. .long 0 /* 0x5c */
  1178. .long 0 /* 0x60 */
  1179. .long 0 /* 0x64 */
  1180. .long 0 /* 0x68 */
  1181. .long 0 /* 0x6c */
  1182. .long 0 /* 0x70 */
  1183. .long 0 /* 0x74 */
  1184. .long 0 /* 0x78 */
  1185. .long 0 /* 0x7c */
  1186. .long 0 /* 0x80 */
  1187. .long 0 /* 0x84 */
  1188. .long 0 /* 0x88 */
  1189. .long 0 /* 0x8c */
  1190. .long 0 /* 0x90 */
  1191. .long 0 /* 0x94 */
  1192. .long 0 /* 0x98 */
  1193. .long 0 /* 0x9c */
  1194. .long 0 /* 0xa0 */
  1195. .long 0 /* 0xa4 */
  1196. .long 0 /* 0xa8 */
  1197. .long 0 /* 0xac */
  1198. .long 0 /* 0xb0 */
  1199. .long 0 /* 0xb4 */
  1200. .long 0 /* 0xb8 */
  1201. .long 0 /* 0xbc */
  1202. .long 0 /* 0xc0 */
  1203. .long 0 /* 0xc4 */
  1204. .long 0 /* 0xc8 */
  1205. .long 0 /* 0xcc */
  1206. .long 0 /* 0xd0 */
  1207. .long 0 /* 0xd4 */
  1208. .long 0 /* 0xd8 */
  1209. .long 0 /* 0xdc */
  1210. .long .kvmppc_h_cede - hcall_real_table
  1211. .long 0 /* 0xe4 */
  1212. .long 0 /* 0xe8 */
  1213. .long 0 /* 0xec */
  1214. .long 0 /* 0xf0 */
  1215. .long 0 /* 0xf4 */
  1216. .long 0 /* 0xf8 */
  1217. .long 0 /* 0xfc */
  1218. .long 0 /* 0x100 */
  1219. .long 0 /* 0x104 */
  1220. .long 0 /* 0x108 */
  1221. .long 0 /* 0x10c */
  1222. .long 0 /* 0x110 */
  1223. .long 0 /* 0x114 */
  1224. .long 0 /* 0x118 */
  1225. .long 0 /* 0x11c */
  1226. .long 0 /* 0x120 */
  1227. .long .kvmppc_h_bulk_remove - hcall_real_table
  1228. hcall_real_table_end:
  1229. ignore_hdec:
  1230. mr r4,r9
  1231. b fast_guest_return
  1232. bounce_ext_interrupt:
  1233. mr r4,r9
  1234. mtspr SPRN_SRR0,r10
  1235. mtspr SPRN_SRR1,r11
  1236. li r10,BOOK3S_INTERRUPT_EXTERNAL
  1237. li r11,(MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */
  1238. rotldi r11,r11,63
  1239. b fast_guest_return
  1240. _GLOBAL(kvmppc_h_set_dabr)
  1241. std r4,VCPU_DABR(r3)
  1242. mtspr SPRN_DABR,r4
  1243. li r3,0
  1244. blr
  1245. _GLOBAL(kvmppc_h_cede)
  1246. ori r11,r11,MSR_EE
  1247. std r11,VCPU_MSR(r3)
  1248. li r0,1
  1249. stb r0,VCPU_CEDED(r3)
  1250. sync /* order setting ceded vs. testing prodded */
  1251. lbz r5,VCPU_PRODDED(r3)
  1252. cmpwi r5,0
  1253. bne 1f
  1254. li r0,0 /* set trap to 0 to say hcall is handled */
  1255. stw r0,VCPU_TRAP(r3)
  1256. li r0,H_SUCCESS
  1257. std r0,VCPU_GPR(r3)(r3)
  1258. BEGIN_FTR_SECTION
  1259. b 2f /* just send it up to host on 970 */
  1260. END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_206)
  1261. /*
  1262. * Set our bit in the bitmask of napping threads unless all the
  1263. * other threads are already napping, in which case we send this
  1264. * up to the host.
  1265. */
  1266. ld r5,HSTATE_KVM_VCORE(r13)
  1267. lwz r6,VCPU_PTID(r3)
  1268. lwz r8,VCORE_ENTRY_EXIT(r5)
  1269. clrldi r8,r8,56
  1270. li r0,1
  1271. sld r0,r0,r6
  1272. addi r6,r5,VCORE_NAPPING_THREADS
  1273. 31: lwarx r4,0,r6
  1274. or r4,r4,r0
  1275. PPC_POPCNTW(r7,r4)
  1276. cmpw r7,r8
  1277. bge 2f
  1278. stwcx. r4,0,r6
  1279. bne 31b
  1280. li r0,1
  1281. stb r0,HSTATE_NAPPING(r13)
  1282. /* order napping_threads update vs testing entry_exit_count */
  1283. lwsync
  1284. mr r4,r3
  1285. lwz r7,VCORE_ENTRY_EXIT(r5)
  1286. cmpwi r7,0x100
  1287. bge 33f /* another thread already exiting */
  1288. /*
  1289. * Although not specifically required by the architecture, POWER7
  1290. * preserves the following registers in nap mode, even if an SMT mode
  1291. * switch occurs: SLB entries, PURR, SPURR, AMOR, UAMOR, AMR, SPRG0-3,
  1292. * DAR, DSISR, DABR, DABRX, DSCR, PMCx, MMCRx, SIAR, SDAR.
  1293. */
  1294. /* Save non-volatile GPRs */
  1295. std r14, VCPU_GPR(r14)(r3)
  1296. std r15, VCPU_GPR(r15)(r3)
  1297. std r16, VCPU_GPR(r16)(r3)
  1298. std r17, VCPU_GPR(r17)(r3)
  1299. std r18, VCPU_GPR(r18)(r3)
  1300. std r19, VCPU_GPR(r19)(r3)
  1301. std r20, VCPU_GPR(r20)(r3)
  1302. std r21, VCPU_GPR(r21)(r3)
  1303. std r22, VCPU_GPR(r22)(r3)
  1304. std r23, VCPU_GPR(r23)(r3)
  1305. std r24, VCPU_GPR(r24)(r3)
  1306. std r25, VCPU_GPR(r25)(r3)
  1307. std r26, VCPU_GPR(r26)(r3)
  1308. std r27, VCPU_GPR(r27)(r3)
  1309. std r28, VCPU_GPR(r28)(r3)
  1310. std r29, VCPU_GPR(r29)(r3)
  1311. std r30, VCPU_GPR(r30)(r3)
  1312. std r31, VCPU_GPR(r31)(r3)
  1313. /* save FP state */
  1314. bl .kvmppc_save_fp
  1315. /*
  1316. * Take a nap until a decrementer or external interrupt occurs,
  1317. * with PECE1 (wake on decr) and PECE0 (wake on external) set in LPCR
  1318. */
  1319. li r0,0x80
  1320. stb r0,PACAPROCSTART(r13)
  1321. mfspr r5,SPRN_LPCR
  1322. ori r5,r5,LPCR_PECE0 | LPCR_PECE1
  1323. mtspr SPRN_LPCR,r5
  1324. isync
  1325. li r0, 0
  1326. std r0, HSTATE_SCRATCH0(r13)
  1327. ptesync
  1328. ld r0, HSTATE_SCRATCH0(r13)
  1329. 1: cmpd r0, r0
  1330. bne 1b
  1331. nap
  1332. b .
  1333. kvm_end_cede:
  1334. /* Woken by external or decrementer interrupt */
  1335. ld r1, HSTATE_HOST_R1(r13)
  1336. ld r2, PACATOC(r13)
  1337. /* If we're a secondary thread and we got here by an IPI, ack it */
  1338. ld r4,HSTATE_KVM_VCPU(r13)
  1339. lwz r3,VCPU_PTID(r4)
  1340. cmpwi r3,0
  1341. beq 27f
  1342. mfspr r3,SPRN_SRR1
  1343. rlwinm r3,r3,44-31,0x7 /* extract wake reason field */
  1344. cmpwi r3,4 /* was it an external interrupt? */
  1345. bne 27f
  1346. ld r5, HSTATE_XICS_PHYS(r13)
  1347. li r0,0xff
  1348. li r6,XICS_QIRR
  1349. li r7,XICS_XIRR
  1350. lwzcix r8,r5,r7 /* ack the interrupt */
  1351. sync
  1352. stbcix r0,r5,r6 /* clear it */
  1353. stwcix r8,r5,r7 /* EOI it */
  1354. 27:
  1355. /* load up FP state */
  1356. bl kvmppc_load_fp
  1357. /* Load NV GPRS */
  1358. ld r14, VCPU_GPR(r14)(r4)
  1359. ld r15, VCPU_GPR(r15)(r4)
  1360. ld r16, VCPU_GPR(r16)(r4)
  1361. ld r17, VCPU_GPR(r17)(r4)
  1362. ld r18, VCPU_GPR(r18)(r4)
  1363. ld r19, VCPU_GPR(r19)(r4)
  1364. ld r20, VCPU_GPR(r20)(r4)
  1365. ld r21, VCPU_GPR(r21)(r4)
  1366. ld r22, VCPU_GPR(r22)(r4)
  1367. ld r23, VCPU_GPR(r23)(r4)
  1368. ld r24, VCPU_GPR(r24)(r4)
  1369. ld r25, VCPU_GPR(r25)(r4)
  1370. ld r26, VCPU_GPR(r26)(r4)
  1371. ld r27, VCPU_GPR(r27)(r4)
  1372. ld r28, VCPU_GPR(r28)(r4)
  1373. ld r29, VCPU_GPR(r29)(r4)
  1374. ld r30, VCPU_GPR(r30)(r4)
  1375. ld r31, VCPU_GPR(r31)(r4)
  1376. /* clear our bit in vcore->napping_threads */
  1377. 33: ld r5,HSTATE_KVM_VCORE(r13)
  1378. lwz r3,VCPU_PTID(r4)
  1379. li r0,1
  1380. sld r0,r0,r3
  1381. addi r6,r5,VCORE_NAPPING_THREADS
  1382. 32: lwarx r7,0,r6
  1383. andc r7,r7,r0
  1384. stwcx. r7,0,r6
  1385. bne 32b
  1386. li r0,0
  1387. stb r0,HSTATE_NAPPING(r13)
  1388. /* see if any other thread is already exiting */
  1389. lwz r0,VCORE_ENTRY_EXIT(r5)
  1390. cmpwi r0,0x100
  1391. blt kvmppc_cede_reentry /* if not go back to guest */
  1392. /* some threads are exiting, so go to the guest exit path */
  1393. b hcall_real_fallback
  1394. /* cede when already previously prodded case */
  1395. 1: li r0,0
  1396. stb r0,VCPU_PRODDED(r3)
  1397. sync /* order testing prodded vs. clearing ceded */
  1398. stb r0,VCPU_CEDED(r3)
  1399. li r3,H_SUCCESS
  1400. blr
  1401. /* we've ceded but we want to give control to the host */
  1402. 2: li r3,H_TOO_HARD
  1403. blr
  1404. secondary_too_late:
  1405. ld r5,HSTATE_KVM_VCORE(r13)
  1406. HMT_LOW
  1407. 13: lbz r3,VCORE_IN_GUEST(r5)
  1408. cmpwi r3,0
  1409. bne 13b
  1410. HMT_MEDIUM
  1411. ld r11,PACA_SLBSHADOWPTR(r13)
  1412. .rept SLB_NUM_BOLTED
  1413. ld r5,SLBSHADOW_SAVEAREA(r11)
  1414. ld r6,SLBSHADOW_SAVEAREA+8(r11)
  1415. andis. r7,r5,SLB_ESID_V@h
  1416. beq 1f
  1417. slbmte r6,r5
  1418. 1: addi r11,r11,16
  1419. .endr
  1420. secondary_nap:
  1421. /* Clear any pending IPI - assume we're a secondary thread */
  1422. ld r5, HSTATE_XICS_PHYS(r13)
  1423. li r7, XICS_XIRR
  1424. lwzcix r3, r5, r7 /* ack any pending interrupt */
  1425. rlwinm. r0, r3, 0, 0xffffff /* any pending? */
  1426. beq 37f
  1427. sync
  1428. li r0, 0xff
  1429. li r6, XICS_QIRR
  1430. stbcix r0, r5, r6 /* clear the IPI */
  1431. stwcix r3, r5, r7 /* EOI it */
  1432. 37: sync
  1433. /* increment the nap count and then go to nap mode */
  1434. ld r4, HSTATE_KVM_VCORE(r13)
  1435. addi r4, r4, VCORE_NAP_COUNT
  1436. lwsync /* make previous updates visible */
  1437. 51: lwarx r3, 0, r4
  1438. addi r3, r3, 1
  1439. stwcx. r3, 0, r4
  1440. bne 51b
  1441. li r3, LPCR_PECE0
  1442. mfspr r4, SPRN_LPCR
  1443. rlwimi r4, r3, 0, LPCR_PECE0 | LPCR_PECE1
  1444. mtspr SPRN_LPCR, r4
  1445. isync
  1446. li r0, 0
  1447. std r0, HSTATE_SCRATCH0(r13)
  1448. ptesync
  1449. ld r0, HSTATE_SCRATCH0(r13)
  1450. 1: cmpd r0, r0
  1451. bne 1b
  1452. nap
  1453. b .
  1454. /*
  1455. * Save away FP, VMX and VSX registers.
  1456. * r3 = vcpu pointer
  1457. */
  1458. _GLOBAL(kvmppc_save_fp)
  1459. mfmsr r9
  1460. ori r8,r9,MSR_FP
  1461. #ifdef CONFIG_ALTIVEC
  1462. BEGIN_FTR_SECTION
  1463. oris r8,r8,MSR_VEC@h
  1464. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  1465. #endif
  1466. #ifdef CONFIG_VSX
  1467. BEGIN_FTR_SECTION
  1468. oris r8,r8,MSR_VSX@h
  1469. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  1470. #endif
  1471. mtmsrd r8
  1472. isync
  1473. #ifdef CONFIG_VSX
  1474. BEGIN_FTR_SECTION
  1475. reg = 0
  1476. .rept 32
  1477. li r6,reg*16+VCPU_VSRS
  1478. STXVD2X(reg,r6,r3)
  1479. reg = reg + 1
  1480. .endr
  1481. FTR_SECTION_ELSE
  1482. #endif
  1483. reg = 0
  1484. .rept 32
  1485. stfd reg,reg*8+VCPU_FPRS(r3)
  1486. reg = reg + 1
  1487. .endr
  1488. #ifdef CONFIG_VSX
  1489. ALT_FTR_SECTION_END_IFSET(CPU_FTR_VSX)
  1490. #endif
  1491. mffs fr0
  1492. stfd fr0,VCPU_FPSCR(r3)
  1493. #ifdef CONFIG_ALTIVEC
  1494. BEGIN_FTR_SECTION
  1495. reg = 0
  1496. .rept 32
  1497. li r6,reg*16+VCPU_VRS
  1498. stvx reg,r6,r3
  1499. reg = reg + 1
  1500. .endr
  1501. mfvscr vr0
  1502. li r6,VCPU_VSCR
  1503. stvx vr0,r6,r3
  1504. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  1505. #endif
  1506. mfspr r6,SPRN_VRSAVE
  1507. stw r6,VCPU_VRSAVE(r3)
  1508. mtmsrd r9
  1509. isync
  1510. blr
  1511. /*
  1512. * Load up FP, VMX and VSX registers
  1513. * r4 = vcpu pointer
  1514. */
  1515. .globl kvmppc_load_fp
  1516. kvmppc_load_fp:
  1517. mfmsr r9
  1518. ori r8,r9,MSR_FP
  1519. #ifdef CONFIG_ALTIVEC
  1520. BEGIN_FTR_SECTION
  1521. oris r8,r8,MSR_VEC@h
  1522. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  1523. #endif
  1524. #ifdef CONFIG_VSX
  1525. BEGIN_FTR_SECTION
  1526. oris r8,r8,MSR_VSX@h
  1527. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  1528. #endif
  1529. mtmsrd r8
  1530. isync
  1531. lfd fr0,VCPU_FPSCR(r4)
  1532. MTFSF_L(fr0)
  1533. #ifdef CONFIG_VSX
  1534. BEGIN_FTR_SECTION
  1535. reg = 0
  1536. .rept 32
  1537. li r7,reg*16+VCPU_VSRS
  1538. LXVD2X(reg,r7,r4)
  1539. reg = reg + 1
  1540. .endr
  1541. FTR_SECTION_ELSE
  1542. #endif
  1543. reg = 0
  1544. .rept 32
  1545. lfd reg,reg*8+VCPU_FPRS(r4)
  1546. reg = reg + 1
  1547. .endr
  1548. #ifdef CONFIG_VSX
  1549. ALT_FTR_SECTION_END_IFSET(CPU_FTR_VSX)
  1550. #endif
  1551. #ifdef CONFIG_ALTIVEC
  1552. BEGIN_FTR_SECTION
  1553. li r7,VCPU_VSCR
  1554. lvx vr0,r7,r4
  1555. mtvscr vr0
  1556. reg = 0
  1557. .rept 32
  1558. li r7,reg*16+VCPU_VRS
  1559. lvx reg,r7,r4
  1560. reg = reg + 1
  1561. .endr
  1562. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  1563. #endif
  1564. lwz r7,VCPU_VRSAVE(r4)
  1565. mtspr SPRN_VRSAVE,r7
  1566. blr