Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 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 | |
| 20 | #include <asm/ppc_asm.h> |
| 21 | #include <asm/kvm_asm.h> |
| 22 | #include <asm/reg.h> |
Paul Mackerras | 177339d | 2011-07-23 17:41:11 +1000 | [diff] [blame] | 23 | #include <asm/mmu.h> |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 24 | #include <asm/page.h> |
Paul Mackerras | 177339d | 2011-07-23 17:41:11 +1000 | [diff] [blame] | 25 | #include <asm/ptrace.h> |
| 26 | #include <asm/hvcall.h> |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 27 | #include <asm/asm-offsets.h> |
| 28 | #include <asm/exception-64s.h> |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame] | 29 | #include <asm/kvm_book3s_asm.h> |
Aneesh Kumar K.V | f64e808 | 2016-03-01 12:59:20 +0530 | [diff] [blame] | 30 | #include <asm/book3s/64/mmu-hash.h> |
Michael Neuling | e4e3812 | 2014-03-25 10:47:02 +1100 | [diff] [blame] | 31 | #include <asm/tm.h> |
Mahesh Salgaonkar | fd7bacb | 2016-05-15 09:44:26 +0530 | [diff] [blame] | 32 | #include <asm/opal.h> |
Michael Neuling | e4e3812 | 2014-03-25 10:47:02 +1100 | [diff] [blame] | 33 | |
| 34 | #define VCPU_GPRS_TM(reg) (((reg) * ULONG_SIZE) + VCPU_GPR_TM) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 35 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 36 | /* Values in HSTATE_NAPPING(r13) */ |
| 37 | #define NAPPING_CEDE 1 |
| 38 | #define NAPPING_NOVCPU 2 |
| 39 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 40 | /* |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 41 | * Call kvmppc_hv_entry in real mode. |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 42 | * Must be called with interrupts hard-disabled. |
| 43 | * |
| 44 | * Input Registers: |
| 45 | * |
| 46 | * LR = return address to continue at after eventually re-enabling MMU |
| 47 | */ |
Anton Blanchard | 6ed179b | 2014-06-12 18:16:53 +1000 | [diff] [blame] | 48 | _GLOBAL_TOC(kvmppc_hv_entry_trampoline) |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 49 | mflr r0 |
| 50 | std r0, PPC_LR_STKOFF(r1) |
| 51 | stdu r1, -112(r1) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 52 | mfmsr r10 |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 53 | LOAD_REG_ADDR(r5, kvmppc_call_hv_entry) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 54 | li r0,MSR_RI |
| 55 | andc r0,r10,r0 |
| 56 | li r6,MSR_IR | MSR_DR |
| 57 | andc r6,r10,r6 |
| 58 | mtmsrd r0,1 /* clear RI in MSR */ |
| 59 | mtsrr0 r5 |
| 60 | mtsrr1 r6 |
| 61 | RFI |
| 62 | |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 63 | kvmppc_call_hv_entry: |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 64 | ld r4, HSTATE_KVM_VCPU(r13) |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 65 | bl kvmppc_hv_entry |
| 66 | |
| 67 | /* Back from guest - restore host state and return to caller */ |
| 68 | |
Michael Neuling | eee7ff9 | 2014-01-08 21:25:19 +1100 | [diff] [blame] | 69 | BEGIN_FTR_SECTION |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 70 | /* Restore host DABR and DABRX */ |
| 71 | ld r5,HSTATE_DABR(r13) |
| 72 | li r6,7 |
| 73 | mtspr SPRN_DABR,r5 |
| 74 | mtspr SPRN_DABRX,r6 |
Michael Neuling | eee7ff9 | 2014-01-08 21:25:19 +1100 | [diff] [blame] | 75 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 76 | |
| 77 | /* Restore SPRG3 */ |
Scott Wood | 9d378df | 2014-03-10 17:29:38 -0500 | [diff] [blame] | 78 | ld r3,PACA_SPRG_VDSO(r13) |
| 79 | mtspr SPRN_SPRG_VDSO_WRITE,r3 |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 80 | |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 81 | /* Reload the host's PMU registers */ |
| 82 | ld r3, PACALPPACAPTR(r13) /* is the host using the PMU? */ |
| 83 | lbz r4, LPPACA_PMCINUSE(r3) |
| 84 | cmpwi r4, 0 |
| 85 | beq 23f /* skip if not */ |
Paul Mackerras | 9bc01a9 | 2014-05-26 19:48:40 +1000 | [diff] [blame] | 86 | BEGIN_FTR_SECTION |
Michael Ellerman | 9a4fc4e | 2014-07-10 19:34:31 +1000 | [diff] [blame] | 87 | ld r3, HSTATE_MMCR0(r13) |
Paul Mackerras | 9bc01a9 | 2014-05-26 19:48:40 +1000 | [diff] [blame] | 88 | andi. r4, r3, MMCR0_PMAO_SYNC | MMCR0_PMAO |
| 89 | cmpwi r4, MMCR0_PMAO |
| 90 | beql kvmppc_fix_pmao |
| 91 | END_FTR_SECTION_IFSET(CPU_FTR_PMAO_BUG) |
Michael Ellerman | 9a4fc4e | 2014-07-10 19:34:31 +1000 | [diff] [blame] | 92 | lwz r3, HSTATE_PMC1(r13) |
| 93 | lwz r4, HSTATE_PMC2(r13) |
| 94 | lwz r5, HSTATE_PMC3(r13) |
| 95 | lwz r6, HSTATE_PMC4(r13) |
| 96 | lwz r8, HSTATE_PMC5(r13) |
| 97 | lwz r9, HSTATE_PMC6(r13) |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 98 | mtspr SPRN_PMC1, r3 |
| 99 | mtspr SPRN_PMC2, r4 |
| 100 | mtspr SPRN_PMC3, r5 |
| 101 | mtspr SPRN_PMC4, r6 |
| 102 | mtspr SPRN_PMC5, r8 |
| 103 | mtspr SPRN_PMC6, r9 |
Michael Ellerman | 9a4fc4e | 2014-07-10 19:34:31 +1000 | [diff] [blame] | 104 | ld r3, HSTATE_MMCR0(r13) |
| 105 | ld r4, HSTATE_MMCR1(r13) |
| 106 | ld r5, HSTATE_MMCRA(r13) |
| 107 | ld r6, HSTATE_SIAR(r13) |
| 108 | ld r7, HSTATE_SDAR(r13) |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 109 | mtspr SPRN_MMCR1, r4 |
| 110 | mtspr SPRN_MMCRA, r5 |
Paul Mackerras | 72cde5a | 2014-03-25 10:47:08 +1100 | [diff] [blame] | 111 | mtspr SPRN_SIAR, r6 |
| 112 | mtspr SPRN_SDAR, r7 |
| 113 | BEGIN_FTR_SECTION |
Michael Ellerman | 9a4fc4e | 2014-07-10 19:34:31 +1000 | [diff] [blame] | 114 | ld r8, HSTATE_MMCR2(r13) |
| 115 | ld r9, HSTATE_SIER(r13) |
Paul Mackerras | 72cde5a | 2014-03-25 10:47:08 +1100 | [diff] [blame] | 116 | mtspr SPRN_MMCR2, r8 |
| 117 | mtspr SPRN_SIER, r9 |
| 118 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 119 | mtspr SPRN_MMCR0, r3 |
| 120 | isync |
| 121 | 23: |
| 122 | |
| 123 | /* |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 124 | * Reload DEC. HDEC interrupts were disabled when |
| 125 | * we reloaded the host's LPCR value. |
| 126 | */ |
| 127 | ld r3, HSTATE_DECEXP(r13) |
| 128 | mftb r4 |
| 129 | subf r4, r4, r3 |
| 130 | mtspr SPRN_DEC, r4 |
| 131 | |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 132 | /* hwthread_req may have got set by cede or no vcpu, so clear it */ |
| 133 | li r0, 0 |
| 134 | stb r0, HSTATE_HWTHREAD_REQ(r13) |
| 135 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 136 | /* |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 137 | * For external and machine check interrupts, we need |
| 138 | * to call the Linux handler to process the interrupt. |
| 139 | * We do that by jumping to absolute address 0x500 for |
| 140 | * external interrupts, or the machine_check_fwnmi label |
| 141 | * for machine checks (since firmware might have patched |
| 142 | * the vector area at 0x200). The [h]rfid at the end of the |
| 143 | * handler will return to the book3s_hv_interrupts.S code. |
| 144 | * For other interrupts we do the rfid to get back |
| 145 | * to the book3s_hv_interrupts.S code here. |
| 146 | */ |
| 147 | ld r8, 112+PPC_LR_STKOFF(r1) |
| 148 | addi r1, r1, 112 |
| 149 | ld r7, HSTATE_HOST_MSR(r13) |
| 150 | |
Paul Mackerras | 53af3ba | 2017-01-30 21:21:51 +1100 | [diff] [blame^] | 151 | /* |
| 152 | * If we came back from the guest via a relocation-on interrupt, |
| 153 | * we will be in virtual mode at this point, which makes it a |
| 154 | * little easier to get back to the caller. |
| 155 | */ |
| 156 | mfmsr r0 |
| 157 | andi. r0, r0, MSR_IR /* in real mode? */ |
| 158 | bne .Lvirt_return |
| 159 | |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 160 | cmpwi cr1, r12, BOOK3S_INTERRUPT_MACHINE_CHECK |
| 161 | cmpwi r12, BOOK3S_INTERRUPT_EXTERNAL |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 162 | beq 11f |
Gautham R. Shenoy | 70aa396 | 2015-10-15 11:29:58 +0530 | [diff] [blame] | 163 | cmpwi r12, BOOK3S_INTERRUPT_H_DOORBELL |
| 164 | beq 15f /* Invoke the H_DOORBELL handler */ |
Mahesh Salgaonkar | 0869b6f | 2014-07-29 18:40:01 +0530 | [diff] [blame] | 165 | cmpwi cr2, r12, BOOK3S_INTERRUPT_HMI |
| 166 | beq cr2, 14f /* HMI check */ |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 167 | |
| 168 | /* RFI into the highmem handler, or branch to interrupt handler */ |
| 169 | mfmsr r6 |
| 170 | li r0, MSR_RI |
| 171 | andc r6, r6, r0 |
| 172 | mtmsrd r6, 1 /* Clear RI in MSR */ |
| 173 | mtsrr0 r8 |
| 174 | mtsrr1 r7 |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 175 | beq cr1, 13f /* machine check */ |
| 176 | RFI |
| 177 | |
| 178 | /* On POWER7, we have external interrupts set to use HSRR0/1 */ |
| 179 | 11: mtspr SPRN_HSRR0, r8 |
| 180 | mtspr SPRN_HSRR1, r7 |
| 181 | ba 0x500 |
| 182 | |
| 183 | 13: b machine_check_fwnmi |
| 184 | |
Mahesh Salgaonkar | 0869b6f | 2014-07-29 18:40:01 +0530 | [diff] [blame] | 185 | 14: mtspr SPRN_HSRR0, r8 |
| 186 | mtspr SPRN_HSRR1, r7 |
| 187 | b hmi_exception_after_realmode |
| 188 | |
Gautham R. Shenoy | 70aa396 | 2015-10-15 11:29:58 +0530 | [diff] [blame] | 189 | 15: mtspr SPRN_HSRR0, r8 |
| 190 | mtspr SPRN_HSRR1, r7 |
| 191 | ba 0xe80 |
| 192 | |
Paul Mackerras | 53af3ba | 2017-01-30 21:21:51 +1100 | [diff] [blame^] | 193 | /* Virtual-mode return - can't get here for HMI or machine check */ |
| 194 | .Lvirt_return: |
| 195 | cmpwi r12, BOOK3S_INTERRUPT_EXTERNAL |
| 196 | beq 16f |
| 197 | cmpwi r12, BOOK3S_INTERRUPT_H_DOORBELL |
| 198 | beq 17f |
| 199 | andi. r0, r7, MSR_EE /* were interrupts hard-enabled? */ |
| 200 | beq 18f |
| 201 | mtmsrd r7, 1 /* if so then re-enable them */ |
| 202 | 18: mtlr r8 |
| 203 | blr |
| 204 | |
| 205 | 16: mtspr SPRN_HSRR0, r8 /* jump to reloc-on external vector */ |
| 206 | mtspr SPRN_HSRR1, r7 |
| 207 | b exc_virt_0x4500_hardware_interrupt |
| 208 | |
| 209 | 17: mtspr SPRN_HSRR0, r8 |
| 210 | mtspr SPRN_HSRR1, r7 |
| 211 | b exc_virt_0x4e80_h_doorbell |
| 212 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 213 | kvmppc_primary_no_guest: |
| 214 | /* We handle this much like a ceded vcpu */ |
Paul Mackerras | fd6d53b | 2015-03-28 14:21:08 +1100 | [diff] [blame] | 215 | /* put the HDEC into the DEC, since HDEC interrupts don't wake us */ |
| 216 | mfspr r3, SPRN_HDEC |
| 217 | mtspr SPRN_DEC, r3 |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 218 | /* |
| 219 | * Make sure the primary has finished the MMU switch. |
| 220 | * We should never get here on a secondary thread, but |
| 221 | * check it for robustness' sake. |
| 222 | */ |
| 223 | ld r5, HSTATE_KVM_VCORE(r13) |
| 224 | 65: lbz r0, VCORE_IN_GUEST(r5) |
| 225 | cmpwi r0, 0 |
| 226 | beq 65b |
| 227 | /* Set LPCR. */ |
| 228 | ld r8,VCORE_LPCR(r5) |
| 229 | mtspr SPRN_LPCR,r8 |
| 230 | isync |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 231 | /* set our bit in napping_threads */ |
| 232 | ld r5, HSTATE_KVM_VCORE(r13) |
| 233 | lbz r7, HSTATE_PTID(r13) |
| 234 | li r0, 1 |
| 235 | sld r0, r0, r7 |
| 236 | addi r6, r5, VCORE_NAPPING_THREADS |
| 237 | 1: lwarx r3, 0, r6 |
| 238 | or r3, r3, r0 |
| 239 | stwcx. r3, 0, r6 |
| 240 | bne 1b |
Paul Mackerras | 7d6c40d | 2015-03-28 14:21:09 +1100 | [diff] [blame] | 241 | /* order napping_threads update vs testing entry_exit_map */ |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 242 | isync |
| 243 | li r12, 0 |
| 244 | lwz r7, VCORE_ENTRY_EXIT(r5) |
| 245 | cmpwi r7, 0x100 |
| 246 | bge kvm_novcpu_exit /* another thread already exiting */ |
| 247 | li r3, NAPPING_NOVCPU |
| 248 | stb r3, HSTATE_NAPPING(r13) |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 249 | |
Paul Mackerras | ccc0777 | 2015-03-28 14:21:07 +1100 | [diff] [blame] | 250 | li r3, 0 /* Don't wake on privileged (OS) doorbell */ |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 251 | b kvm_do_nap |
| 252 | |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 253 | /* |
| 254 | * kvm_novcpu_wakeup |
| 255 | * Entered from kvm_start_guest if kvm_hstate.napping is set |
| 256 | * to NAPPING_NOVCPU |
| 257 | * r2 = kernel TOC |
| 258 | * r13 = paca |
| 259 | */ |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 260 | kvm_novcpu_wakeup: |
| 261 | ld r1, HSTATE_HOST_R1(r13) |
| 262 | ld r5, HSTATE_KVM_VCORE(r13) |
| 263 | li r0, 0 |
| 264 | stb r0, HSTATE_NAPPING(r13) |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 265 | |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 266 | /* check the wake reason */ |
| 267 | bl kvmppc_check_wake_reason |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 268 | |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 269 | /* |
| 270 | * Restore volatile registers since we could have called |
| 271 | * a C routine in kvmppc_check_wake_reason. |
| 272 | * r5 = VCORE |
| 273 | */ |
| 274 | ld r5, HSTATE_KVM_VCORE(r13) |
| 275 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 276 | /* see if any other thread is already exiting */ |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 277 | lwz r0, VCORE_ENTRY_EXIT(r5) |
| 278 | cmpwi r0, 0x100 |
| 279 | bge kvm_novcpu_exit |
| 280 | |
| 281 | /* clear our bit in napping_threads */ |
| 282 | lbz r7, HSTATE_PTID(r13) |
| 283 | li r0, 1 |
| 284 | sld r0, r0, r7 |
| 285 | addi r6, r5, VCORE_NAPPING_THREADS |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 286 | 4: lwarx r7, 0, r6 |
| 287 | andc r7, r7, r0 |
| 288 | stwcx. r7, 0, r6 |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 289 | bne 4b |
| 290 | |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 291 | /* See if the wake reason means we need to exit */ |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 292 | cmpdi r3, 0 |
| 293 | bge kvm_novcpu_exit |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 294 | |
Paul Mackerras | fd6d53b | 2015-03-28 14:21:08 +1100 | [diff] [blame] | 295 | /* See if our timeslice has expired (HDEC is negative) */ |
| 296 | mfspr r0, SPRN_HDEC |
| 297 | li r12, BOOK3S_INTERRUPT_HV_DECREMENTER |
| 298 | cmpwi r0, 0 |
| 299 | blt kvm_novcpu_exit |
| 300 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 301 | /* Got an IPI but other vcpus aren't yet exiting, must be a latecomer */ |
| 302 | ld r4, HSTATE_KVM_VCPU(r13) |
| 303 | cmpdi r4, 0 |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 304 | beq kvmppc_primary_no_guest |
| 305 | |
| 306 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
| 307 | addi r3, r4, VCPU_TB_RMENTRY |
| 308 | bl kvmhv_start_timing |
| 309 | #endif |
| 310 | b kvmppc_got_guest |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 311 | |
| 312 | kvm_novcpu_exit: |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 313 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
| 314 | ld r4, HSTATE_KVM_VCPU(r13) |
| 315 | cmpdi r4, 0 |
| 316 | beq 13f |
| 317 | addi r3, r4, VCPU_TB_RMEXIT |
| 318 | bl kvmhv_accumulate_time |
| 319 | #endif |
Paul Mackerras | eddb60f | 2015-03-28 14:21:11 +1100 | [diff] [blame] | 320 | 13: mr r3, r12 |
| 321 | stw r12, 112-4(r1) |
| 322 | bl kvmhv_commence_exit |
| 323 | nop |
| 324 | lwz r12, 112-4(r1) |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 325 | b kvmhv_switch_to_host |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 326 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 327 | /* |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 328 | * We come in here when wakened from nap mode. |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 329 | * Relocation is off and most register values are lost. |
| 330 | * r13 points to the PACA. |
| 331 | */ |
| 332 | .globl kvm_start_guest |
| 333 | kvm_start_guest: |
Preeti U Murthy | fd17dc7 | 2014-04-11 16:01:58 +0530 | [diff] [blame] | 334 | |
| 335 | /* Set runlatch bit the minute you wake up from nap */ |
Paul Mackerras | 1f09c3e | 2015-03-28 14:21:04 +1100 | [diff] [blame] | 336 | mfspr r0, SPRN_CTRLF |
| 337 | ori r0, r0, 1 |
| 338 | mtspr SPRN_CTRLT, r0 |
Preeti U Murthy | fd17dc7 | 2014-04-11 16:01:58 +0530 | [diff] [blame] | 339 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 340 | ld r2,PACATOC(r13) |
| 341 | |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame] | 342 | li r0,KVM_HWTHREAD_IN_KVM |
| 343 | stb r0,HSTATE_HWTHREAD_STATE(r13) |
| 344 | |
| 345 | /* NV GPR values from power7_idle() will no longer be valid */ |
| 346 | li r0,1 |
| 347 | stb r0,PACA_NAPSTATELOST(r13) |
| 348 | |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 349 | /* were we napping due to cede? */ |
| 350 | lbz r0,HSTATE_NAPPING(r13) |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 351 | cmpwi r0,NAPPING_CEDE |
| 352 | beq kvm_end_cede |
| 353 | cmpwi r0,NAPPING_NOVCPU |
| 354 | beq kvm_novcpu_wakeup |
| 355 | |
| 356 | ld r1,PACAEMERGSP(r13) |
| 357 | subi r1,r1,STACK_FRAME_OVERHEAD |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 358 | |
| 359 | /* |
| 360 | * We weren't napping due to cede, so this must be a secondary |
| 361 | * thread being woken up to run a guest, or being woken up due |
| 362 | * to a stray IPI. (Or due to some machine check or hypervisor |
| 363 | * maintenance interrupt while the core is in KVM.) |
| 364 | */ |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame] | 365 | |
| 366 | /* Check the wake reason in SRR1 to see why we got here */ |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 367 | bl kvmppc_check_wake_reason |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 368 | /* |
| 369 | * kvmppc_check_wake_reason could invoke a C routine, but we |
| 370 | * have no volatile registers to restore when we return. |
| 371 | */ |
| 372 | |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 373 | cmpdi r3, 0 |
| 374 | bge kvm_no_guest |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame] | 375 | |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 376 | /* get vcore pointer, NULL if we have nothing to run */ |
| 377 | ld r5,HSTATE_KVM_VCORE(r13) |
| 378 | cmpdi r5,0 |
| 379 | /* if we have no vcore to run, go back to sleep */ |
Paul Mackerras | 7b444c6 | 2012-10-15 01:16:14 +0000 | [diff] [blame] | 380 | beq kvm_no_guest |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame] | 381 | |
Paul Mackerras | 56548fc | 2014-12-03 14:48:40 +1100 | [diff] [blame] | 382 | kvm_secondary_got_guest: |
| 383 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 384 | /* Set HSTATE_DSCR(r13) to something sensible */ |
Anshuman Khandual | 1db3652 | 2015-05-21 12:13:03 +0530 | [diff] [blame] | 385 | ld r6, PACA_DSCR_DEFAULT(r13) |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 386 | std r6, HSTATE_DSCR(r13) |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 387 | |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 388 | /* On thread 0 of a subcore, set HDEC to max */ |
| 389 | lbz r4, HSTATE_PTID(r13) |
| 390 | cmpwi r4, 0 |
| 391 | bne 63f |
| 392 | lis r6, 0x7fff |
| 393 | ori r6, r6, 0xffff |
| 394 | mtspr SPRN_HDEC, r6 |
| 395 | /* and set per-LPAR registers, if doing dynamic micro-threading */ |
| 396 | ld r6, HSTATE_SPLIT_MODE(r13) |
| 397 | cmpdi r6, 0 |
| 398 | beq 63f |
| 399 | ld r0, KVM_SPLIT_RPR(r6) |
| 400 | mtspr SPRN_RPR, r0 |
| 401 | ld r0, KVM_SPLIT_PMMAR(r6) |
| 402 | mtspr SPRN_PMMAR, r0 |
| 403 | ld r0, KVM_SPLIT_LDBAR(r6) |
| 404 | mtspr SPRN_LDBAR, r0 |
| 405 | isync |
| 406 | 63: |
| 407 | /* Order load of vcpu after load of vcore */ |
Paul Mackerras | 5d5b99c | 2015-03-28 14:21:06 +1100 | [diff] [blame] | 408 | lwsync |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 409 | ld r4, HSTATE_KVM_VCPU(r13) |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 410 | bl kvmppc_hv_entry |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 411 | |
| 412 | /* Back from the guest, go back to nap */ |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 413 | /* Clear our vcpu and vcore pointers so we don't come back in early */ |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 414 | li r0, 0 |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 415 | std r0, HSTATE_KVM_VCPU(r13) |
Paul Mackerras | f019b7a | 2013-11-16 17:46:03 +1100 | [diff] [blame] | 416 | /* |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 417 | * Once we clear HSTATE_KVM_VCORE(r13), the code in |
Paul Mackerras | 5d5b99c | 2015-03-28 14:21:06 +1100 | [diff] [blame] | 418 | * kvmppc_run_core() is going to assume that all our vcpu |
| 419 | * state is visible in memory. This lwsync makes sure |
| 420 | * that that is true. |
Paul Mackerras | f019b7a | 2013-11-16 17:46:03 +1100 | [diff] [blame] | 421 | */ |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 422 | lwsync |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 423 | std r0, HSTATE_KVM_VCORE(r13) |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 424 | |
Mahesh Salgaonkar | fd7bacb | 2016-05-15 09:44:26 +0530 | [diff] [blame] | 425 | /* |
| 426 | * All secondaries exiting guest will fall through this path. |
| 427 | * Before proceeding, just check for HMI interrupt and |
| 428 | * invoke opal hmi handler. By now we are sure that the |
| 429 | * primary thread on this core/subcore has already made partition |
| 430 | * switch/TB resync and we are good to call opal hmi handler. |
| 431 | */ |
| 432 | cmpwi r12, BOOK3S_INTERRUPT_HMI |
| 433 | bne kvm_no_guest |
| 434 | |
| 435 | li r3,0 /* NULL argument */ |
| 436 | bl hmi_exception_realmode |
Paul Mackerras | 56548fc | 2014-12-03 14:48:40 +1100 | [diff] [blame] | 437 | /* |
| 438 | * At this point we have finished executing in the guest. |
| 439 | * We need to wait for hwthread_req to become zero, since |
| 440 | * we may not turn on the MMU while hwthread_req is non-zero. |
| 441 | * While waiting we also need to check if we get given a vcpu to run. |
| 442 | */ |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 443 | kvm_no_guest: |
Paul Mackerras | 56548fc | 2014-12-03 14:48:40 +1100 | [diff] [blame] | 444 | lbz r3, HSTATE_HWTHREAD_REQ(r13) |
| 445 | cmpwi r3, 0 |
| 446 | bne 53f |
| 447 | HMT_MEDIUM |
| 448 | li r0, KVM_HWTHREAD_IN_KERNEL |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 449 | stb r0, HSTATE_HWTHREAD_STATE(r13) |
Paul Mackerras | 56548fc | 2014-12-03 14:48:40 +1100 | [diff] [blame] | 450 | /* need to recheck hwthread_req after a barrier, to avoid race */ |
| 451 | sync |
| 452 | lbz r3, HSTATE_HWTHREAD_REQ(r13) |
| 453 | cmpwi r3, 0 |
| 454 | bne 54f |
| 455 | /* |
Shreyas B. Prabhu | 5fa6b6b | 2016-07-08 11:50:46 +0530 | [diff] [blame] | 456 | * We jump to pnv_wakeup_loss, which will return to the caller |
Paul Mackerras | 56548fc | 2014-12-03 14:48:40 +1100 | [diff] [blame] | 457 | * of power7_nap in the powernv cpu offline loop. The value we |
| 458 | * put in r3 becomes the return value for power7_nap. |
| 459 | */ |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 460 | li r3, LPCR_PECE0 |
| 461 | mfspr r4, SPRN_LPCR |
| 462 | rlwimi r4, r3, 0, LPCR_PECE0 | LPCR_PECE1 |
| 463 | mtspr SPRN_LPCR, r4 |
Paul Mackerras | 56548fc | 2014-12-03 14:48:40 +1100 | [diff] [blame] | 464 | li r3, 0 |
Shreyas B. Prabhu | 5fa6b6b | 2016-07-08 11:50:46 +0530 | [diff] [blame] | 465 | b pnv_wakeup_loss |
Paul Mackerras | 56548fc | 2014-12-03 14:48:40 +1100 | [diff] [blame] | 466 | |
| 467 | 53: HMT_LOW |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 468 | ld r5, HSTATE_KVM_VCORE(r13) |
| 469 | cmpdi r5, 0 |
| 470 | bne 60f |
| 471 | ld r3, HSTATE_SPLIT_MODE(r13) |
| 472 | cmpdi r3, 0 |
| 473 | beq kvm_no_guest |
| 474 | lbz r0, KVM_SPLIT_DO_NAP(r3) |
| 475 | cmpwi r0, 0 |
Paul Mackerras | 56548fc | 2014-12-03 14:48:40 +1100 | [diff] [blame] | 476 | beq kvm_no_guest |
| 477 | HMT_MEDIUM |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 478 | b kvm_unsplit_nap |
| 479 | 60: HMT_MEDIUM |
Paul Mackerras | 56548fc | 2014-12-03 14:48:40 +1100 | [diff] [blame] | 480 | b kvm_secondary_got_guest |
| 481 | |
| 482 | 54: li r0, KVM_HWTHREAD_IN_KVM |
| 483 | stb r0, HSTATE_HWTHREAD_STATE(r13) |
| 484 | b kvm_no_guest |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 485 | |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 486 | /* |
| 487 | * Here the primary thread is trying to return the core to |
| 488 | * whole-core mode, so we need to nap. |
| 489 | */ |
| 490 | kvm_unsplit_nap: |
Gautham R. Shenoy | 7f23532 | 2015-09-02 21:48:58 +0530 | [diff] [blame] | 491 | /* |
Mahesh Salgaonkar | fd7bacb | 2016-05-15 09:44:26 +0530 | [diff] [blame] | 492 | * When secondaries are napping in kvm_unsplit_nap() with |
| 493 | * hwthread_req = 1, HMI goes ignored even though subcores are |
| 494 | * already exited the guest. Hence HMI keeps waking up secondaries |
| 495 | * from nap in a loop and secondaries always go back to nap since |
| 496 | * no vcore is assigned to them. This makes impossible for primary |
| 497 | * thread to get hold of secondary threads resulting into a soft |
| 498 | * lockup in KVM path. |
| 499 | * |
| 500 | * Let us check if HMI is pending and handle it before we go to nap. |
| 501 | */ |
| 502 | cmpwi r12, BOOK3S_INTERRUPT_HMI |
| 503 | bne 55f |
| 504 | li r3, 0 /* NULL argument */ |
| 505 | bl hmi_exception_realmode |
| 506 | 55: |
| 507 | /* |
Gautham R. Shenoy | 7f23532 | 2015-09-02 21:48:58 +0530 | [diff] [blame] | 508 | * Ensure that secondary doesn't nap when it has |
| 509 | * its vcore pointer set. |
| 510 | */ |
| 511 | sync /* matches smp_mb() before setting split_info.do_nap */ |
| 512 | ld r0, HSTATE_KVM_VCORE(r13) |
| 513 | cmpdi r0, 0 |
| 514 | bne kvm_no_guest |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 515 | /* clear any pending message */ |
| 516 | BEGIN_FTR_SECTION |
| 517 | lis r6, (PPC_DBELL_SERVER << (63-36))@h |
| 518 | PPC_MSGCLR(6) |
| 519 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
| 520 | /* Set kvm_split_mode.napped[tid] = 1 */ |
| 521 | ld r3, HSTATE_SPLIT_MODE(r13) |
| 522 | li r0, 1 |
| 523 | lhz r4, PACAPACAINDEX(r13) |
| 524 | clrldi r4, r4, 61 /* micro-threading => P8 => 8 threads/core */ |
| 525 | addi r4, r4, KVM_SPLIT_NAPPED |
| 526 | stbx r0, r3, r4 |
| 527 | /* Check the do_nap flag again after setting napped[] */ |
| 528 | sync |
| 529 | lbz r0, KVM_SPLIT_DO_NAP(r3) |
| 530 | cmpwi r0, 0 |
| 531 | beq 57f |
| 532 | li r3, (LPCR_PECEDH | LPCR_PECE0) >> 4 |
Paul Mackerras | bf53c88 | 2016-11-18 14:34:07 +1100 | [diff] [blame] | 533 | mfspr r5, SPRN_LPCR |
| 534 | rlwimi r5, r3, 4, (LPCR_PECEDP | LPCR_PECEDH | LPCR_PECE0 | LPCR_PECE1) |
| 535 | b kvm_nap_sequence |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 536 | |
| 537 | 57: li r0, 0 |
| 538 | stbx r0, r3, r4 |
| 539 | b kvm_no_guest |
| 540 | |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 541 | /****************************************************************************** |
| 542 | * * |
| 543 | * Entry code * |
| 544 | * * |
| 545 | *****************************************************************************/ |
| 546 | |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 547 | /* Stack frame offsets */ |
| 548 | #define STACK_SLOT_TID (112-16) |
| 549 | #define STACK_SLOT_PSSCR (112-24) |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 550 | #define STACK_SLOT_PID (112-32) |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 551 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 552 | .global kvmppc_hv_entry |
| 553 | kvmppc_hv_entry: |
| 554 | |
| 555 | /* Required state: |
| 556 | * |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 557 | * R4 = vcpu pointer (or NULL) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 558 | * MSR = ~IR|DR |
| 559 | * R13 = PACA |
| 560 | * R1 = host R1 |
Michael Neuling | 06a29e4 | 2014-08-19 14:59:30 +1000 | [diff] [blame] | 561 | * R2 = TOC |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 562 | * all other volatile GPRS = free |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 563 | * Does not preserve non-volatile GPRs or CR fields |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 564 | */ |
| 565 | mflr r0 |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 566 | std r0, PPC_LR_STKOFF(r1) |
| 567 | stdu r1, -112(r1) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 568 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 569 | /* Save R1 in the PACA */ |
| 570 | std r1, HSTATE_HOST_R1(r13) |
| 571 | |
Paul Mackerras | 44a3add | 2013-10-04 21:45:04 +1000 | [diff] [blame] | 572 | li r6, KVM_GUEST_MODE_HOST_HV |
| 573 | stb r6, HSTATE_IN_GUEST(r13) |
| 574 | |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 575 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
| 576 | /* Store initial timestamp */ |
| 577 | cmpdi r4, 0 |
| 578 | beq 1f |
| 579 | addi r3, r4, VCPU_TB_RMENTRY |
| 580 | bl kvmhv_start_timing |
| 581 | 1: |
| 582 | #endif |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 583 | |
| 584 | /* Use cr7 as an indication of radix mode */ |
| 585 | ld r5, HSTATE_KVM_VCORE(r13) |
| 586 | ld r9, VCORE_KVM(r5) /* pointer to struct kvm */ |
| 587 | lbz r0, KVM_RADIX(r9) |
| 588 | cmpwi cr7, r0, 0 |
| 589 | |
| 590 | /* Clear out SLB if hash */ |
| 591 | bne cr7, 2f |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 592 | li r6,0 |
| 593 | slbmte r6,r6 |
| 594 | slbia |
| 595 | ptesync |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 596 | 2: |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 597 | /* |
Paul Mackerras | c17b98c | 2014-12-03 13:30:38 +1100 | [diff] [blame] | 598 | * POWER7/POWER8 host -> guest partition switch code. |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 599 | * We don't have to lock against concurrent tlbies, |
| 600 | * but we do have to coordinate across hardware threads. |
| 601 | */ |
Paul Mackerras | 7d6c40d | 2015-03-28 14:21:09 +1100 | [diff] [blame] | 602 | /* Set bit in entry map iff exit map is zero. */ |
Paul Mackerras | 7d6c40d | 2015-03-28 14:21:09 +1100 | [diff] [blame] | 603 | li r7, 1 |
| 604 | lbz r6, HSTATE_PTID(r13) |
| 605 | sld r7, r7, r6 |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 606 | addi r8, r5, VCORE_ENTRY_EXIT |
| 607 | 21: lwarx r3, 0, r8 |
Paul Mackerras | 7d6c40d | 2015-03-28 14:21:09 +1100 | [diff] [blame] | 608 | cmpwi r3, 0x100 /* any threads starting to exit? */ |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 609 | bge secondary_too_late /* if so we're too late to the party */ |
Paul Mackerras | 7d6c40d | 2015-03-28 14:21:09 +1100 | [diff] [blame] | 610 | or r3, r3, r7 |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 611 | stwcx. r3, 0, r8 |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 612 | bne 21b |
| 613 | |
| 614 | /* Primary thread switches to guest partition. */ |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 615 | cmpwi r6,0 |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 616 | bne 10f |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 617 | lwz r7,KVM_LPID(r9) |
Paul Mackerras | 7a84084 | 2016-11-16 22:25:20 +1100 | [diff] [blame] | 618 | BEGIN_FTR_SECTION |
| 619 | ld r6,KVM_SDR1(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 620 | li r0,LPID_RSVD /* switch to reserved LPID */ |
| 621 | mtspr SPRN_LPID,r0 |
| 622 | ptesync |
| 623 | mtspr SPRN_SDR1,r6 /* switch to partition page table */ |
Paul Mackerras | 7a84084 | 2016-11-16 22:25:20 +1100 | [diff] [blame] | 624 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 625 | mtspr SPRN_LPID,r7 |
| 626 | isync |
Paul Mackerras | 1b400ba | 2012-11-21 23:28:08 +0000 | [diff] [blame] | 627 | |
| 628 | /* See if we need to flush the TLB */ |
| 629 | lhz r6,PACAPACAINDEX(r13) /* test_bit(cpu, need_tlb_flush) */ |
Paul Mackerras | a29ebea | 2017-01-30 21:21:50 +1100 | [diff] [blame] | 630 | BEGIN_FTR_SECTION |
| 631 | /* |
| 632 | * On POWER9, individual threads can come in here, but the |
| 633 | * TLB is shared between the 4 threads in a core, hence |
| 634 | * invalidating on one thread invalidates for all. |
| 635 | * Thus we make all 4 threads use the same bit here. |
| 636 | */ |
| 637 | clrrdi r6,r6,2 |
| 638 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300) |
Paul Mackerras | 1b400ba | 2012-11-21 23:28:08 +0000 | [diff] [blame] | 639 | clrldi r7,r6,64-6 /* extract bit number (6 bits) */ |
| 640 | srdi r6,r6,6 /* doubleword number */ |
| 641 | sldi r6,r6,3 /* address offset */ |
| 642 | add r6,r6,r9 |
| 643 | addi r6,r6,KVM_NEED_FLUSH /* dword in kvm->arch.need_tlb_flush */ |
Paul Mackerras | a29ebea | 2017-01-30 21:21:50 +1100 | [diff] [blame] | 644 | li r8,1 |
| 645 | sld r8,r8,r7 |
Paul Mackerras | 1b400ba | 2012-11-21 23:28:08 +0000 | [diff] [blame] | 646 | ld r7,0(r6) |
Paul Mackerras | a29ebea | 2017-01-30 21:21:50 +1100 | [diff] [blame] | 647 | and. r7,r7,r8 |
Paul Mackerras | 1b400ba | 2012-11-21 23:28:08 +0000 | [diff] [blame] | 648 | beq 22f |
Paul Mackerras | ca25205 | 2014-01-08 21:25:22 +1100 | [diff] [blame] | 649 | /* Flush the TLB of any entries for this LPID */ |
Paul Mackerras | a29ebea | 2017-01-30 21:21:50 +1100 | [diff] [blame] | 650 | lwz r0,KVM_TLB_SETS(r9) |
| 651 | mtctr r0 |
Paul Mackerras | 1b400ba | 2012-11-21 23:28:08 +0000 | [diff] [blame] | 652 | li r7,0x800 /* IS field = 0b10 */ |
| 653 | ptesync |
Paul Mackerras | a29ebea | 2017-01-30 21:21:50 +1100 | [diff] [blame] | 654 | li r0,0 /* RS for P9 version of tlbiel */ |
| 655 | bne cr7, 29f |
| 656 | 28: tlbiel r7 /* On P9, rs=0, RIC=0, PRS=0, R=0 */ |
Paul Mackerras | 1b400ba | 2012-11-21 23:28:08 +0000 | [diff] [blame] | 657 | addi r7,r7,0x1000 |
| 658 | bdnz 28b |
Paul Mackerras | a29ebea | 2017-01-30 21:21:50 +1100 | [diff] [blame] | 659 | b 30f |
| 660 | 29: PPC_TLBIEL(7,0,2,1,1) /* for radix, RIC=2, PRS=1, R=1 */ |
| 661 | addi r7,r7,0x1000 |
| 662 | bdnz 29b |
| 663 | 30: ptesync |
| 664 | 23: ldarx r7,0,r6 /* clear the bit after TLB flushed */ |
| 665 | andc r7,r7,r8 |
| 666 | stdcx. r7,0,r6 |
| 667 | bne 23b |
Paul Mackerras | 1b400ba | 2012-11-21 23:28:08 +0000 | [diff] [blame] | 668 | |
Paul Mackerras | 93b0f4d | 2013-09-06 13:17:46 +1000 | [diff] [blame] | 669 | /* Add timebase offset onto timebase */ |
| 670 | 22: ld r8,VCORE_TB_OFFSET(r5) |
| 671 | cmpdi r8,0 |
| 672 | beq 37f |
| 673 | mftb r6 /* current host timebase */ |
| 674 | add r8,r8,r6 |
| 675 | mtspr SPRN_TBU40,r8 /* update upper 40 bits */ |
| 676 | mftb r7 /* check if lower 24 bits overflowed */ |
| 677 | clrldi r6,r6,40 |
| 678 | clrldi r7,r7,40 |
| 679 | cmpld r7,r6 |
| 680 | bge 37f |
| 681 | addis r8,r8,0x100 /* if so, increment upper 40 bits */ |
| 682 | mtspr SPRN_TBU40,r8 |
| 683 | |
Paul Mackerras | 388cc6e | 2013-09-21 14:35:02 +1000 | [diff] [blame] | 684 | /* Load guest PCR value to select appropriate compat mode */ |
| 685 | 37: ld r7, VCORE_PCR(r5) |
| 686 | cmpdi r7, 0 |
| 687 | beq 38f |
| 688 | mtspr SPRN_PCR, r7 |
| 689 | 38: |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 690 | |
| 691 | BEGIN_FTR_SECTION |
Paul Mackerras | 88b02cf9 | 2016-09-15 13:42:52 +1000 | [diff] [blame] | 692 | /* DPDES and VTB are shared between threads */ |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 693 | ld r8, VCORE_DPDES(r5) |
Paul Mackerras | 88b02cf9 | 2016-09-15 13:42:52 +1000 | [diff] [blame] | 694 | ld r7, VCORE_VTB(r5) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 695 | mtspr SPRN_DPDES, r8 |
Paul Mackerras | 88b02cf9 | 2016-09-15 13:42:52 +1000 | [diff] [blame] | 696 | mtspr SPRN_VTB, r7 |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 697 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
| 698 | |
Mahesh Salgaonkar | fd7bacb | 2016-05-15 09:44:26 +0530 | [diff] [blame] | 699 | /* Mark the subcore state as inside guest */ |
| 700 | bl kvmppc_subcore_enter_guest |
| 701 | nop |
| 702 | ld r5, HSTATE_KVM_VCORE(r13) |
| 703 | ld r4, HSTATE_KVM_VCPU(r13) |
Paul Mackerras | 388cc6e | 2013-09-21 14:35:02 +1000 | [diff] [blame] | 704 | li r0,1 |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 705 | stb r0,VCORE_IN_GUEST(r5) /* signal secondaries to continue */ |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 706 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 707 | /* Do we have a guest vcpu to run? */ |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 708 | 10: cmpdi r4, 0 |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 709 | beq kvmppc_primary_no_guest |
| 710 | kvmppc_got_guest: |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 711 | |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 712 | /* Load up guest SLB entries (N.B. slb_max will be 0 for radix) */ |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 713 | lwz r5,VCPU_SLB_MAX(r4) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 714 | cmpwi r5,0 |
| 715 | beq 9f |
| 716 | mtctr r5 |
| 717 | addi r6,r4,VCPU_SLB |
| 718 | 1: ld r8,VCPU_SLB_E(r6) |
| 719 | ld r9,VCPU_SLB_V(r6) |
| 720 | slbmte r9,r8 |
| 721 | addi r6,r6,VCPU_SLB_SIZE |
| 722 | bdnz 1b |
| 723 | 9: |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 724 | /* Increment yield count if they have a VPA */ |
| 725 | ld r3, VCPU_VPA(r4) |
| 726 | cmpdi r3, 0 |
| 727 | beq 25f |
Alexander Graf | 0865a58 | 2014-06-11 10:36:17 +0200 | [diff] [blame] | 728 | li r6, LPPACA_YIELDCOUNT |
| 729 | LWZX_BE r5, r3, r6 |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 730 | addi r5, r5, 1 |
Alexander Graf | 0865a58 | 2014-06-11 10:36:17 +0200 | [diff] [blame] | 731 | STWX_BE r5, r3, r6 |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 732 | li r6, 1 |
| 733 | stb r6, VCPU_VPA_DIRTY(r4) |
| 734 | 25: |
| 735 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 736 | /* Save purr/spurr */ |
| 737 | mfspr r5,SPRN_PURR |
| 738 | mfspr r6,SPRN_SPURR |
| 739 | std r5,HSTATE_PURR(r13) |
| 740 | std r6,HSTATE_SPURR(r13) |
| 741 | ld r7,VCPU_PURR(r4) |
| 742 | ld r8,VCPU_SPURR(r4) |
| 743 | mtspr SPRN_PURR,r7 |
| 744 | mtspr SPRN_SPURR,r8 |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 745 | |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 746 | /* Save host values of some registers */ |
| 747 | BEGIN_FTR_SECTION |
| 748 | mfspr r5, SPRN_TIDR |
| 749 | mfspr r6, SPRN_PSSCR |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 750 | mfspr r7, SPRN_PID |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 751 | std r5, STACK_SLOT_TID(r1) |
| 752 | std r6, STACK_SLOT_PSSCR(r1) |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 753 | std r7, STACK_SLOT_PID(r1) |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 754 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300) |
| 755 | |
Michael Neuling | eee7ff9 | 2014-01-08 21:25:19 +1100 | [diff] [blame] | 756 | BEGIN_FTR_SECTION |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 757 | /* Set partition DABR */ |
| 758 | /* Do this before re-enabling PMU to avoid P7 DABR corruption bug */ |
Paul Mackerras | 8563bf5 | 2014-01-08 21:25:29 +1100 | [diff] [blame] | 759 | lwz r5,VCPU_DABRX(r4) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 760 | ld r6,VCPU_DABR(r4) |
| 761 | mtspr SPRN_DABRX,r5 |
| 762 | mtspr SPRN_DABR,r6 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 763 | isync |
Michael Neuling | eee7ff9 | 2014-01-08 21:25:19 +1100 | [diff] [blame] | 764 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 765 | |
Michael Neuling | e4e3812 | 2014-03-25 10:47:02 +1100 | [diff] [blame] | 766 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
| 767 | BEGIN_FTR_SECTION |
Paul Mackerras | f024ee0 | 2016-06-22 14:21:59 +1000 | [diff] [blame] | 768 | bl kvmppc_restore_tm |
| 769 | END_FTR_SECTION_IFSET(CPU_FTR_TM) |
Michael Neuling | e4e3812 | 2014-03-25 10:47:02 +1100 | [diff] [blame] | 770 | #endif |
| 771 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 772 | /* Load guest PMU registers */ |
| 773 | /* R4 is live here (vcpu pointer) */ |
| 774 | li r3, 1 |
| 775 | sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */ |
| 776 | mtspr SPRN_MMCR0, r3 /* freeze all counters, disable ints */ |
| 777 | isync |
Paul Mackerras | 9bc01a9 | 2014-05-26 19:48:40 +1000 | [diff] [blame] | 778 | BEGIN_FTR_SECTION |
| 779 | ld r3, VCPU_MMCR(r4) |
| 780 | andi. r5, r3, MMCR0_PMAO_SYNC | MMCR0_PMAO |
| 781 | cmpwi r5, MMCR0_PMAO |
| 782 | beql kvmppc_fix_pmao |
| 783 | END_FTR_SECTION_IFSET(CPU_FTR_PMAO_BUG) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 784 | lwz r3, VCPU_PMC(r4) /* always load up guest PMU registers */ |
| 785 | lwz r5, VCPU_PMC + 4(r4) /* to prevent information leak */ |
| 786 | lwz r6, VCPU_PMC + 8(r4) |
| 787 | lwz r7, VCPU_PMC + 12(r4) |
| 788 | lwz r8, VCPU_PMC + 16(r4) |
| 789 | lwz r9, VCPU_PMC + 20(r4) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 790 | mtspr SPRN_PMC1, r3 |
| 791 | mtspr SPRN_PMC2, r5 |
| 792 | mtspr SPRN_PMC3, r6 |
| 793 | mtspr SPRN_PMC4, r7 |
| 794 | mtspr SPRN_PMC5, r8 |
| 795 | mtspr SPRN_PMC6, r9 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 796 | ld r3, VCPU_MMCR(r4) |
| 797 | ld r5, VCPU_MMCR + 8(r4) |
| 798 | ld r6, VCPU_MMCR + 16(r4) |
| 799 | ld r7, VCPU_SIAR(r4) |
| 800 | ld r8, VCPU_SDAR(r4) |
| 801 | mtspr SPRN_MMCR1, r5 |
| 802 | mtspr SPRN_MMCRA, r6 |
| 803 | mtspr SPRN_SIAR, r7 |
| 804 | mtspr SPRN_SDAR, r8 |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 805 | BEGIN_FTR_SECTION |
| 806 | ld r5, VCPU_MMCR + 24(r4) |
| 807 | ld r6, VCPU_SIER(r4) |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 808 | mtspr SPRN_MMCR2, r5 |
| 809 | mtspr SPRN_SIER, r6 |
| 810 | BEGIN_FTR_SECTION_NESTED(96) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 811 | lwz r7, VCPU_PMC + 24(r4) |
| 812 | lwz r8, VCPU_PMC + 28(r4) |
| 813 | ld r9, VCPU_MMCR + 32(r4) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 814 | mtspr SPRN_SPMC1, r7 |
| 815 | mtspr SPRN_SPMC2, r8 |
| 816 | mtspr SPRN_MMCRS, r9 |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 817 | END_FTR_SECTION_NESTED(CPU_FTR_ARCH_300, 0, 96) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 818 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 819 | mtspr SPRN_MMCR0, r3 |
| 820 | isync |
| 821 | |
| 822 | /* Load up FP, VMX and VSX registers */ |
| 823 | bl kvmppc_load_fp |
| 824 | |
| 825 | ld r14, VCPU_GPR(R14)(r4) |
| 826 | ld r15, VCPU_GPR(R15)(r4) |
| 827 | ld r16, VCPU_GPR(R16)(r4) |
| 828 | ld r17, VCPU_GPR(R17)(r4) |
| 829 | ld r18, VCPU_GPR(R18)(r4) |
| 830 | ld r19, VCPU_GPR(R19)(r4) |
| 831 | ld r20, VCPU_GPR(R20)(r4) |
| 832 | ld r21, VCPU_GPR(R21)(r4) |
| 833 | ld r22, VCPU_GPR(R22)(r4) |
| 834 | ld r23, VCPU_GPR(R23)(r4) |
| 835 | ld r24, VCPU_GPR(R24)(r4) |
| 836 | ld r25, VCPU_GPR(R25)(r4) |
| 837 | ld r26, VCPU_GPR(R26)(r4) |
| 838 | ld r27, VCPU_GPR(R27)(r4) |
| 839 | ld r28, VCPU_GPR(R28)(r4) |
| 840 | ld r29, VCPU_GPR(R29)(r4) |
| 841 | ld r30, VCPU_GPR(R30)(r4) |
| 842 | ld r31, VCPU_GPR(R31)(r4) |
| 843 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 844 | /* Switch DSCR to guest value */ |
| 845 | ld r5, VCPU_DSCR(r4) |
| 846 | mtspr SPRN_DSCR, r5 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 847 | |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 848 | BEGIN_FTR_SECTION |
Paul Mackerras | c17b98c | 2014-12-03 13:30:38 +1100 | [diff] [blame] | 849 | /* Skip next section on POWER7 */ |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 850 | b 8f |
| 851 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 852 | /* Load up POWER8-specific registers */ |
| 853 | ld r5, VCPU_IAMR(r4) |
| 854 | lwz r6, VCPU_PSPB(r4) |
| 855 | ld r7, VCPU_FSCR(r4) |
| 856 | mtspr SPRN_IAMR, r5 |
| 857 | mtspr SPRN_PSPB, r6 |
| 858 | mtspr SPRN_FSCR, r7 |
| 859 | ld r5, VCPU_DAWR(r4) |
| 860 | ld r6, VCPU_DAWRX(r4) |
| 861 | ld r7, VCPU_CIABR(r4) |
| 862 | ld r8, VCPU_TAR(r4) |
| 863 | mtspr SPRN_DAWR, r5 |
| 864 | mtspr SPRN_DAWRX, r6 |
| 865 | mtspr SPRN_CIABR, r7 |
| 866 | mtspr SPRN_TAR, r8 |
| 867 | ld r5, VCPU_IC(r4) |
Michael Neuling | 7b49041 | 2014-01-08 21:25:32 +1100 | [diff] [blame] | 868 | ld r8, VCPU_EBBHR(r4) |
Paul Mackerras | 88b02cf9 | 2016-09-15 13:42:52 +1000 | [diff] [blame] | 869 | mtspr SPRN_IC, r5 |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 870 | mtspr SPRN_EBBHR, r8 |
| 871 | ld r5, VCPU_EBBRR(r4) |
| 872 | ld r6, VCPU_BESCR(r4) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 873 | lwz r7, VCPU_GUEST_PID(r4) |
| 874 | ld r8, VCPU_WORT(r4) |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 875 | mtspr SPRN_EBBRR, r5 |
| 876 | mtspr SPRN_BESCR, r6 |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 877 | mtspr SPRN_PID, r7 |
| 878 | mtspr SPRN_WORT, r8 |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 879 | BEGIN_FTR_SECTION |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 880 | /* POWER8-only registers */ |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 881 | ld r5, VCPU_TCSCR(r4) |
| 882 | ld r6, VCPU_ACOP(r4) |
| 883 | ld r7, VCPU_CSIGR(r4) |
| 884 | ld r8, VCPU_TACR(r4) |
| 885 | mtspr SPRN_TCSCR, r5 |
| 886 | mtspr SPRN_ACOP, r6 |
| 887 | mtspr SPRN_CSIGR, r7 |
| 888 | mtspr SPRN_TACR, r8 |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 889 | FTR_SECTION_ELSE |
| 890 | /* POWER9-only registers */ |
| 891 | ld r5, VCPU_TID(r4) |
| 892 | ld r6, VCPU_PSSCR(r4) |
| 893 | oris r6, r6, PSSCR_EC@h /* This makes stop trap to HV */ |
| 894 | mtspr SPRN_TIDR, r5 |
| 895 | mtspr SPRN_PSSCR, r6 |
| 896 | ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_300) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 897 | 8: |
| 898 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 899 | /* |
| 900 | * Set the decrementer to the guest decrementer. |
| 901 | */ |
| 902 | ld r8,VCPU_DEC_EXPIRES(r4) |
Paul Mackerras | c5fb80d | 2014-03-25 10:47:07 +1100 | [diff] [blame] | 903 | /* r8 is a host timebase value here, convert to guest TB */ |
| 904 | ld r5,HSTATE_KVM_VCORE(r13) |
| 905 | ld r6,VCORE_TB_OFFSET(r5) |
| 906 | add r8,r8,r6 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 907 | mftb r7 |
| 908 | subf r3,r7,r8 |
| 909 | mtspr SPRN_DEC,r3 |
| 910 | stw r3,VCPU_DEC(r4) |
| 911 | |
| 912 | ld r5, VCPU_SPRG0(r4) |
| 913 | ld r6, VCPU_SPRG1(r4) |
| 914 | ld r7, VCPU_SPRG2(r4) |
| 915 | ld r8, VCPU_SPRG3(r4) |
| 916 | mtspr SPRN_SPRG0, r5 |
| 917 | mtspr SPRN_SPRG1, r6 |
| 918 | mtspr SPRN_SPRG2, r7 |
| 919 | mtspr SPRN_SPRG3, r8 |
| 920 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 921 | /* Load up DAR and DSISR */ |
| 922 | ld r5, VCPU_DAR(r4) |
| 923 | lwz r6, VCPU_DSISR(r4) |
| 924 | mtspr SPRN_DAR, r5 |
| 925 | mtspr SPRN_DSISR, r6 |
| 926 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 927 | /* Restore AMR and UAMOR, set AMOR to all 1s */ |
| 928 | ld r5,VCPU_AMR(r4) |
| 929 | ld r6,VCPU_UAMOR(r4) |
| 930 | li r7,-1 |
| 931 | mtspr SPRN_AMR,r5 |
| 932 | mtspr SPRN_UAMOR,r6 |
| 933 | mtspr SPRN_AMOR,r7 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 934 | |
| 935 | /* Restore state of CTRL run bit; assume 1 on entry */ |
| 936 | lwz r5,VCPU_CTRL(r4) |
| 937 | andi. r5,r5,1 |
| 938 | bne 4f |
| 939 | mfspr r6,SPRN_CTRLF |
| 940 | clrrdi r6,r6,1 |
| 941 | mtspr SPRN_CTRLT,r6 |
| 942 | 4: |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 943 | /* Secondary threads wait for primary to have done partition switch */ |
| 944 | ld r5, HSTATE_KVM_VCORE(r13) |
| 945 | lbz r6, HSTATE_PTID(r13) |
| 946 | cmpwi r6, 0 |
| 947 | beq 21f |
| 948 | lbz r0, VCORE_IN_GUEST(r5) |
| 949 | cmpwi r0, 0 |
| 950 | bne 21f |
| 951 | HMT_LOW |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 952 | 20: lwz r3, VCORE_ENTRY_EXIT(r5) |
| 953 | cmpwi r3, 0x100 |
| 954 | bge no_switch_exit |
| 955 | lbz r0, VCORE_IN_GUEST(r5) |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 956 | cmpwi r0, 0 |
| 957 | beq 20b |
| 958 | HMT_MEDIUM |
| 959 | 21: |
| 960 | /* Set LPCR. */ |
| 961 | ld r8,VCORE_LPCR(r5) |
| 962 | mtspr SPRN_LPCR,r8 |
| 963 | isync |
| 964 | |
| 965 | /* Check if HDEC expires soon */ |
| 966 | mfspr r3, SPRN_HDEC |
| 967 | cmpwi r3, 512 /* 1 microsecond */ |
| 968 | blt hdec_soon |
| 969 | |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 970 | deliver_guest_interrupt: |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 971 | ld r6, VCPU_CTR(r4) |
Sam bobroff | c63517c | 2015-05-27 09:56:57 +1000 | [diff] [blame] | 972 | ld r7, VCPU_XER(r4) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 973 | |
| 974 | mtctr r6 |
| 975 | mtxer r7 |
| 976 | |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 977 | kvmppc_cede_reentry: /* r4 = vcpu, r13 = paca */ |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 978 | ld r10, VCPU_PC(r4) |
| 979 | ld r11, VCPU_MSR(r4) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 980 | ld r6, VCPU_SRR0(r4) |
| 981 | ld r7, VCPU_SRR1(r4) |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 982 | mtspr SPRN_SRR0, r6 |
| 983 | mtspr SPRN_SRR1, r7 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 984 | |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 985 | /* r11 = vcpu->arch.msr & ~MSR_HV */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 986 | rldicl r11, r11, 63 - MSR_HV_LG, 1 |
| 987 | rotldi r11, r11, 1 + MSR_HV_LG |
| 988 | ori r11, r11, MSR_ME |
| 989 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 990 | /* Check if we can deliver an external or decrementer interrupt now */ |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 991 | ld r0, VCPU_PENDING_EXC(r4) |
| 992 | rldicl r0, r0, 64 - BOOK3S_IRQPRIO_EXTERNAL_LEVEL, 63 |
| 993 | cmpdi cr1, r0, 0 |
| 994 | andi. r8, r11, MSR_EE |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 995 | mfspr r8, SPRN_LPCR |
| 996 | /* Insert EXTERNAL_LEVEL bit into LPCR at the MER bit position */ |
| 997 | rldimi r8, r0, LPCR_MER_SH, 63 - LPCR_MER_SH |
| 998 | mtspr SPRN_LPCR, r8 |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 999 | isync |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1000 | beq 5f |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 1001 | li r0, BOOK3S_INTERRUPT_EXTERNAL |
| 1002 | bne cr1, 12f |
| 1003 | mfspr r0, SPRN_DEC |
| 1004 | cmpwi r0, 0 |
| 1005 | li r0, BOOK3S_INTERRUPT_DECREMENTER |
| 1006 | bge 5f |
| 1007 | |
| 1008 | 12: mtspr SPRN_SRR0, r10 |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1009 | mr r10,r0 |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 1010 | mtspr SPRN_SRR1, r11 |
Michael Neuling | e4e3812 | 2014-03-25 10:47:02 +1100 | [diff] [blame] | 1011 | mr r9, r4 |
| 1012 | bl kvmppc_msr_interrupt |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 1013 | 5: |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1014 | |
Liu Ping Fan | 27025a6 | 2013-11-19 14:12:48 +0800 | [diff] [blame] | 1015 | /* |
| 1016 | * Required state: |
| 1017 | * R4 = vcpu |
| 1018 | * R10: value for HSRR0 |
| 1019 | * R11: value for HSRR1 |
| 1020 | * R13 = PACA |
| 1021 | */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1022 | fast_guest_return: |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 1023 | li r0,0 |
| 1024 | stb r0,VCPU_CEDED(r4) /* cancel cede */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1025 | mtspr SPRN_HSRR0,r10 |
| 1026 | mtspr SPRN_HSRR1,r11 |
| 1027 | |
| 1028 | /* Activate guest mode, so faults get handled by KVM */ |
Paul Mackerras | 44a3add | 2013-10-04 21:45:04 +1000 | [diff] [blame] | 1029 | li r9, KVM_GUEST_MODE_GUEST_HV |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1030 | stb r9, HSTATE_IN_GUEST(r13) |
| 1031 | |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1032 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
| 1033 | /* Accumulate timing */ |
| 1034 | addi r3, r4, VCPU_TB_GUEST |
| 1035 | bl kvmhv_accumulate_time |
| 1036 | #endif |
| 1037 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1038 | /* Enter guest */ |
| 1039 | |
Paul Mackerras | 0acb911 | 2013-02-04 18:10:51 +0000 | [diff] [blame] | 1040 | BEGIN_FTR_SECTION |
| 1041 | ld r5, VCPU_CFAR(r4) |
| 1042 | mtspr SPRN_CFAR, r5 |
| 1043 | END_FTR_SECTION_IFSET(CPU_FTR_CFAR) |
Paul Mackerras | 4b8473c | 2013-09-20 14:52:39 +1000 | [diff] [blame] | 1044 | BEGIN_FTR_SECTION |
| 1045 | ld r0, VCPU_PPR(r4) |
| 1046 | END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) |
Paul Mackerras | 0acb911 | 2013-02-04 18:10:51 +0000 | [diff] [blame] | 1047 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1048 | ld r5, VCPU_LR(r4) |
| 1049 | lwz r6, VCPU_CR(r4) |
| 1050 | mtlr r5 |
| 1051 | mtcr r6 |
| 1052 | |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1053 | ld r1, VCPU_GPR(R1)(r4) |
| 1054 | ld r2, VCPU_GPR(R2)(r4) |
| 1055 | ld r3, VCPU_GPR(R3)(r4) |
| 1056 | ld r5, VCPU_GPR(R5)(r4) |
| 1057 | ld r6, VCPU_GPR(R6)(r4) |
| 1058 | ld r7, VCPU_GPR(R7)(r4) |
| 1059 | ld r8, VCPU_GPR(R8)(r4) |
| 1060 | ld r9, VCPU_GPR(R9)(r4) |
| 1061 | ld r10, VCPU_GPR(R10)(r4) |
| 1062 | ld r11, VCPU_GPR(R11)(r4) |
| 1063 | ld r12, VCPU_GPR(R12)(r4) |
| 1064 | ld r13, VCPU_GPR(R13)(r4) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1065 | |
Paul Mackerras | 4b8473c | 2013-09-20 14:52:39 +1000 | [diff] [blame] | 1066 | BEGIN_FTR_SECTION |
| 1067 | mtspr SPRN_PPR, r0 |
| 1068 | END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) |
| 1069 | ld r0, VCPU_GPR(R0)(r4) |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1070 | ld r4, VCPU_GPR(R4)(r4) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1071 | |
| 1072 | hrfid |
| 1073 | b . |
| 1074 | |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1075 | secondary_too_late: |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1076 | li r12, 0 |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1077 | cmpdi r4, 0 |
| 1078 | beq 11f |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1079 | stw r12, VCPU_TRAP(r4) |
| 1080 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1081 | addi r3, r4, VCPU_TB_RMEXIT |
| 1082 | bl kvmhv_accumulate_time |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1083 | #endif |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1084 | 11: b kvmhv_switch_to_host |
| 1085 | |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 1086 | no_switch_exit: |
| 1087 | HMT_MEDIUM |
| 1088 | li r12, 0 |
| 1089 | b 12f |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1090 | hdec_soon: |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1091 | li r12, BOOK3S_INTERRUPT_HV_DECREMENTER |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 1092 | 12: stw r12, VCPU_TRAP(r4) |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1093 | mr r9, r4 |
| 1094 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1095 | addi r3, r4, VCPU_TB_RMEXIT |
| 1096 | bl kvmhv_accumulate_time |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1097 | #endif |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1098 | b guest_exit_cont |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1099 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1100 | /****************************************************************************** |
| 1101 | * * |
| 1102 | * Exit code * |
| 1103 | * * |
| 1104 | *****************************************************************************/ |
| 1105 | |
| 1106 | /* |
| 1107 | * We come here from the first-level interrupt handlers. |
| 1108 | */ |
Aneesh Kumar K.V | dd96b2c | 2013-10-07 22:17:55 +0530 | [diff] [blame] | 1109 | .globl kvmppc_interrupt_hv |
| 1110 | kvmppc_interrupt_hv: |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1111 | /* |
| 1112 | * Register contents: |
Nicholas Piggin | d3918e7 | 2016-12-22 04:29:25 +1000 | [diff] [blame] | 1113 | * R12 = (guest CR << 32) | interrupt vector |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1114 | * R13 = PACA |
Nicholas Piggin | d3918e7 | 2016-12-22 04:29:25 +1000 | [diff] [blame] | 1115 | * guest R12 saved in shadow VCPU SCRATCH0 |
Nicholas Piggin | a97a65d | 2017-01-27 14:00:34 +1000 | [diff] [blame] | 1116 | * guest CTR saved in shadow VCPU SCRATCH1 if RELOCATABLE |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1117 | * guest R13 saved in SPRN_SCRATCH0 |
| 1118 | */ |
Nicholas Piggin | a97a65d | 2017-01-27 14:00:34 +1000 | [diff] [blame] | 1119 | std r9, HSTATE_SCRATCH2(r13) |
Paul Mackerras | 44a3add | 2013-10-04 21:45:04 +1000 | [diff] [blame] | 1120 | lbz r9, HSTATE_IN_GUEST(r13) |
| 1121 | cmpwi r9, KVM_GUEST_MODE_HOST_HV |
| 1122 | beq kvmppc_bad_host_intr |
Aneesh Kumar K.V | dd96b2c | 2013-10-07 22:17:55 +0530 | [diff] [blame] | 1123 | #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE |
| 1124 | cmpwi r9, KVM_GUEST_MODE_GUEST |
Nicholas Piggin | a97a65d | 2017-01-27 14:00:34 +1000 | [diff] [blame] | 1125 | ld r9, HSTATE_SCRATCH2(r13) |
Aneesh Kumar K.V | dd96b2c | 2013-10-07 22:17:55 +0530 | [diff] [blame] | 1126 | beq kvmppc_interrupt_pr |
| 1127 | #endif |
Paul Mackerras | 44a3add | 2013-10-04 21:45:04 +1000 | [diff] [blame] | 1128 | /* We're now back in the host but in guest MMU context */ |
| 1129 | li r9, KVM_GUEST_MODE_HOST_HV |
| 1130 | stb r9, HSTATE_IN_GUEST(r13) |
| 1131 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1132 | ld r9, HSTATE_KVM_VCPU(r13) |
| 1133 | |
| 1134 | /* Save registers */ |
| 1135 | |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1136 | std r0, VCPU_GPR(R0)(r9) |
| 1137 | std r1, VCPU_GPR(R1)(r9) |
| 1138 | std r2, VCPU_GPR(R2)(r9) |
| 1139 | std r3, VCPU_GPR(R3)(r9) |
| 1140 | std r4, VCPU_GPR(R4)(r9) |
| 1141 | std r5, VCPU_GPR(R5)(r9) |
| 1142 | std r6, VCPU_GPR(R6)(r9) |
| 1143 | std r7, VCPU_GPR(R7)(r9) |
| 1144 | std r8, VCPU_GPR(R8)(r9) |
Nicholas Piggin | a97a65d | 2017-01-27 14:00:34 +1000 | [diff] [blame] | 1145 | ld r0, HSTATE_SCRATCH2(r13) |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1146 | std r0, VCPU_GPR(R9)(r9) |
| 1147 | std r10, VCPU_GPR(R10)(r9) |
| 1148 | std r11, VCPU_GPR(R11)(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1149 | ld r3, HSTATE_SCRATCH0(r13) |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1150 | std r3, VCPU_GPR(R12)(r9) |
Nicholas Piggin | d3918e7 | 2016-12-22 04:29:25 +1000 | [diff] [blame] | 1151 | /* CR is in the high half of r12 */ |
| 1152 | srdi r4, r12, 32 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1153 | stw r4, VCPU_CR(r9) |
Paul Mackerras | 0acb911 | 2013-02-04 18:10:51 +0000 | [diff] [blame] | 1154 | BEGIN_FTR_SECTION |
| 1155 | ld r3, HSTATE_CFAR(r13) |
| 1156 | std r3, VCPU_CFAR(r9) |
| 1157 | END_FTR_SECTION_IFSET(CPU_FTR_CFAR) |
Paul Mackerras | 4b8473c | 2013-09-20 14:52:39 +1000 | [diff] [blame] | 1158 | BEGIN_FTR_SECTION |
| 1159 | ld r4, HSTATE_PPR(r13) |
| 1160 | std r4, VCPU_PPR(r9) |
| 1161 | END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1162 | |
| 1163 | /* Restore R1/R2 so we can handle faults */ |
| 1164 | ld r1, HSTATE_HOST_R1(r13) |
| 1165 | ld r2, PACATOC(r13) |
| 1166 | |
| 1167 | mfspr r10, SPRN_SRR0 |
| 1168 | mfspr r11, SPRN_SRR1 |
| 1169 | std r10, VCPU_SRR0(r9) |
| 1170 | std r11, VCPU_SRR1(r9) |
Nicholas Piggin | d3918e7 | 2016-12-22 04:29:25 +1000 | [diff] [blame] | 1171 | /* trap is in the low half of r12, clear CR from the high half */ |
| 1172 | clrldi r12, r12, 32 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1173 | andi. r0, r12, 2 /* need to read HSRR0/1? */ |
| 1174 | beq 1f |
| 1175 | mfspr r10, SPRN_HSRR0 |
| 1176 | mfspr r11, SPRN_HSRR1 |
| 1177 | clrrdi r12, r12, 2 |
| 1178 | 1: std r10, VCPU_PC(r9) |
| 1179 | std r11, VCPU_MSR(r9) |
| 1180 | |
| 1181 | GET_SCRATCH0(r3) |
| 1182 | mflr r4 |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1183 | std r3, VCPU_GPR(R13)(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1184 | std r4, VCPU_LR(r9) |
| 1185 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1186 | stw r12,VCPU_TRAP(r9) |
| 1187 | |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1188 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
| 1189 | addi r3, r9, VCPU_TB_RMINTR |
| 1190 | mr r4, r9 |
| 1191 | bl kvmhv_accumulate_time |
| 1192 | ld r5, VCPU_GPR(R5)(r9) |
| 1193 | ld r6, VCPU_GPR(R6)(r9) |
| 1194 | ld r7, VCPU_GPR(R7)(r9) |
| 1195 | ld r8, VCPU_GPR(R8)(r9) |
| 1196 | #endif |
| 1197 | |
Paul Mackerras | 4a157d6 | 2014-12-03 13:30:39 +1100 | [diff] [blame] | 1198 | /* Save HEIR (HV emulation assist reg) in emul_inst |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1199 | if this is an HEI (HV emulation interrupt, e40) */ |
| 1200 | li r3,KVM_INST_FETCH_FAILED |
Paul Mackerras | 2bf2760 | 2015-03-20 20:39:40 +1100 | [diff] [blame] | 1201 | stw r3,VCPU_LAST_INST(r9) |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1202 | cmpwi r12,BOOK3S_INTERRUPT_H_EMUL_ASSIST |
| 1203 | bne 11f |
| 1204 | mfspr r3,SPRN_HEIR |
Paul Mackerras | 4a157d6 | 2014-12-03 13:30:39 +1100 | [diff] [blame] | 1205 | 11: stw r3,VCPU_HEIR(r9) |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1206 | |
| 1207 | /* these are volatile across C function calls */ |
Nicholas Piggin | a97a65d | 2017-01-27 14:00:34 +1000 | [diff] [blame] | 1208 | #ifdef CONFIG_RELOCATABLE |
| 1209 | ld r3, HSTATE_SCRATCH1(r13) |
| 1210 | mtctr r3 |
| 1211 | #else |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1212 | mfctr r3 |
Nicholas Piggin | a97a65d | 2017-01-27 14:00:34 +1000 | [diff] [blame] | 1213 | #endif |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1214 | mfxer r4 |
| 1215 | std r3, VCPU_CTR(r9) |
Sam bobroff | c63517c | 2015-05-27 09:56:57 +1000 | [diff] [blame] | 1216 | std r4, VCPU_XER(r9) |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1217 | |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1218 | /* If this is a page table miss then see if it's theirs or ours */ |
| 1219 | cmpwi r12, BOOK3S_INTERRUPT_H_DATA_STORAGE |
| 1220 | beq kvmppc_hdsi |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1221 | cmpwi r12, BOOK3S_INTERRUPT_H_INST_STORAGE |
| 1222 | beq kvmppc_hisi |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1223 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1224 | /* See if this is a leftover HDEC interrupt */ |
| 1225 | cmpwi r12,BOOK3S_INTERRUPT_HV_DECREMENTER |
| 1226 | bne 2f |
| 1227 | mfspr r3,SPRN_HDEC |
| 1228 | cmpwi r3,0 |
Paul Mackerras | 1f09c3e | 2015-03-28 14:21:04 +1100 | [diff] [blame] | 1229 | mr r4,r9 |
| 1230 | bge fast_guest_return |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1231 | 2: |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1232 | /* See if this is an hcall we can handle in real mode */ |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1233 | cmpwi r12,BOOK3S_INTERRUPT_SYSCALL |
| 1234 | beq hcall_try_real_mode |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1235 | |
Paul Mackerras | 66feed6 | 2015-03-28 14:21:12 +1100 | [diff] [blame] | 1236 | /* Hypervisor doorbell - exit only if host IPI flag set */ |
| 1237 | cmpwi r12, BOOK3S_INTERRUPT_H_DOORBELL |
| 1238 | bne 3f |
| 1239 | lbz r0, HSTATE_HOST_IPI(r13) |
Gautham R. Shenoy | 06554d9 | 2015-08-07 17:41:20 +0530 | [diff] [blame] | 1240 | cmpwi r0, 0 |
Paul Mackerras | 66feed6 | 2015-03-28 14:21:12 +1100 | [diff] [blame] | 1241 | beq 4f |
| 1242 | b guest_exit_cont |
| 1243 | 3: |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 1244 | /* External interrupt ? */ |
| 1245 | cmpwi r12, BOOK3S_INTERRUPT_EXTERNAL |
Paul Mackerras | 1f09c3e | 2015-03-28 14:21:04 +1100 | [diff] [blame] | 1246 | bne+ guest_exit_cont |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 1247 | |
| 1248 | /* External interrupt, first check for host_ipi. If this is |
| 1249 | * set, we know the host wants us out so let's do it now |
| 1250 | */ |
Paul Mackerras | c934243 | 2013-09-06 13:24:13 +1000 | [diff] [blame] | 1251 | bl kvmppc_read_intr |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 1252 | |
| 1253 | /* |
| 1254 | * Restore the active volatile registers after returning from |
| 1255 | * a C function. |
| 1256 | */ |
| 1257 | ld r9, HSTATE_KVM_VCPU(r13) |
| 1258 | li r12, BOOK3S_INTERRUPT_EXTERNAL |
| 1259 | |
| 1260 | /* |
| 1261 | * kvmppc_read_intr return codes: |
| 1262 | * |
| 1263 | * Exit to host (r3 > 0) |
| 1264 | * 1 An interrupt is pending that needs to be handled by the host |
| 1265 | * Exit guest and return to host by branching to guest_exit_cont |
| 1266 | * |
Suresh Warrier | f7af520 | 2016-08-19 15:35:52 +1000 | [diff] [blame] | 1267 | * 2 Passthrough that needs completion in the host |
| 1268 | * Exit guest and return to host by branching to guest_exit_cont |
| 1269 | * However, we also set r12 to BOOK3S_INTERRUPT_HV_RM_HARD |
| 1270 | * to indicate to the host to complete handling the interrupt |
| 1271 | * |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 1272 | * Before returning to guest, we check if any CPU is heading out |
| 1273 | * to the host and if so, we head out also. If no CPUs are heading |
| 1274 | * check return values <= 0. |
| 1275 | * |
| 1276 | * Return to guest (r3 <= 0) |
| 1277 | * 0 No external interrupt is pending |
| 1278 | * -1 A guest wakeup IPI (which has now been cleared) |
| 1279 | * In either case, we return to guest to deliver any pending |
| 1280 | * guest interrupts. |
Suresh Warrier | e3c13e5 | 2016-08-19 15:35:51 +1000 | [diff] [blame] | 1281 | * |
| 1282 | * -2 A PCI passthrough external interrupt was handled |
| 1283 | * (interrupt was delivered directly to guest) |
| 1284 | * Return to guest to deliver any pending guest interrupts. |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 1285 | */ |
| 1286 | |
Suresh Warrier | f7af520 | 2016-08-19 15:35:52 +1000 | [diff] [blame] | 1287 | cmpdi r3, 1 |
| 1288 | ble 1f |
| 1289 | |
| 1290 | /* Return code = 2 */ |
| 1291 | li r12, BOOK3S_INTERRUPT_HV_RM_HARD |
| 1292 | stw r12, VCPU_TRAP(r9) |
| 1293 | b guest_exit_cont |
| 1294 | |
| 1295 | 1: /* Return code <= 1 */ |
Paul Mackerras | c934243 | 2013-09-06 13:24:13 +1000 | [diff] [blame] | 1296 | cmpdi r3, 0 |
Paul Mackerras | 1f09c3e | 2015-03-28 14:21:04 +1100 | [diff] [blame] | 1297 | bgt guest_exit_cont |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 1298 | |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 1299 | /* Return code <= 0 */ |
Paul Mackerras | 66feed6 | 2015-03-28 14:21:12 +1100 | [diff] [blame] | 1300 | 4: ld r5, HSTATE_KVM_VCORE(r13) |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 1301 | lwz r0, VCORE_ENTRY_EXIT(r5) |
| 1302 | cmpwi r0, 0x100 |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 1303 | mr r4, r9 |
Paul Mackerras | 1f09c3e | 2015-03-28 14:21:04 +1100 | [diff] [blame] | 1304 | blt deliver_guest_interrupt |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1305 | |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1306 | guest_exit_cont: /* r9 = vcpu, r12 = trap, r13 = paca */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1307 | /* Save more register state */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1308 | mfdar r6 |
| 1309 | mfdsisr r7 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1310 | std r6, VCPU_DAR(r9) |
| 1311 | stw r7, VCPU_DSISR(r9) |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1312 | /* don't overwrite fault_dar/fault_dsisr if HDSI */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1313 | cmpwi r12,BOOK3S_INTERRUPT_H_DATA_STORAGE |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1314 | beq mc_cont |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1315 | std r6, VCPU_FAULT_DAR(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1316 | stw r7, VCPU_FAULT_DSISR(r9) |
| 1317 | |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1318 | /* See if it is a machine check */ |
| 1319 | cmpwi r12, BOOK3S_INTERRUPT_MACHINE_CHECK |
| 1320 | beq machine_check_realmode |
| 1321 | mc_cont: |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1322 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
| 1323 | addi r3, r9, VCPU_TB_RMEXIT |
| 1324 | mr r4, r9 |
| 1325 | bl kvmhv_accumulate_time |
| 1326 | #endif |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1327 | |
Gautham R. Shenoy | 7e022e7 | 2015-05-21 13:57:04 +0530 | [diff] [blame] | 1328 | mr r3, r12 |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1329 | /* Increment exit count, poke other threads to exit */ |
| 1330 | bl kvmhv_commence_exit |
Paul Mackerras | eddb60f | 2015-03-28 14:21:11 +1100 | [diff] [blame] | 1331 | nop |
| 1332 | ld r9, HSTATE_KVM_VCPU(r13) |
| 1333 | lwz r12, VCPU_TRAP(r9) |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1334 | |
Paul Mackerras | ec25716 | 2015-06-24 21:18:03 +1000 | [diff] [blame] | 1335 | /* Stop others sending VCPU interrupts to this physical CPU */ |
| 1336 | li r0, -1 |
| 1337 | stw r0, VCPU_CPU(r9) |
| 1338 | stw r0, VCPU_THREAD_CPU(r9) |
| 1339 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1340 | /* Save guest CTRL register, set runlatch to 1 */ |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1341 | mfspr r6,SPRN_CTRLF |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1342 | stw r6,VCPU_CTRL(r9) |
| 1343 | andi. r0,r6,1 |
| 1344 | bne 4f |
| 1345 | ori r6,r6,1 |
| 1346 | mtspr SPRN_CTRLT,r6 |
| 1347 | 4: |
| 1348 | /* Read the guest SLB and save it away */ |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 1349 | ld r5, VCPU_KVM(r9) |
| 1350 | lbz r0, KVM_RADIX(r5) |
| 1351 | cmpwi r0, 0 |
| 1352 | li r5, 0 |
| 1353 | bne 3f /* for radix, save 0 entries */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1354 | lwz r0,VCPU_SLB_NR(r9) /* number of entries in SLB */ |
| 1355 | mtctr r0 |
| 1356 | li r6,0 |
| 1357 | addi r7,r9,VCPU_SLB |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1358 | 1: slbmfee r8,r6 |
| 1359 | andis. r0,r8,SLB_ESID_V@h |
| 1360 | beq 2f |
| 1361 | add r8,r8,r6 /* put index in */ |
| 1362 | slbmfev r3,r6 |
| 1363 | std r8,VCPU_SLB_E(r7) |
| 1364 | std r3,VCPU_SLB_V(r7) |
| 1365 | addi r7,r7,VCPU_SLB_SIZE |
| 1366 | addi r5,r5,1 |
| 1367 | 2: addi r6,r6,1 |
| 1368 | bdnz 1b |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 1369 | 3: stw r5,VCPU_SLB_MAX(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1370 | |
| 1371 | /* |
| 1372 | * Save the guest PURR/SPURR |
| 1373 | */ |
| 1374 | mfspr r5,SPRN_PURR |
| 1375 | mfspr r6,SPRN_SPURR |
| 1376 | ld r7,VCPU_PURR(r9) |
| 1377 | ld r8,VCPU_SPURR(r9) |
| 1378 | std r5,VCPU_PURR(r9) |
| 1379 | std r6,VCPU_SPURR(r9) |
| 1380 | subf r5,r7,r5 |
| 1381 | subf r6,r8,r6 |
| 1382 | |
| 1383 | /* |
| 1384 | * Restore host PURR/SPURR and add guest times |
| 1385 | * so that the time in the guest gets accounted. |
| 1386 | */ |
| 1387 | ld r3,HSTATE_PURR(r13) |
| 1388 | ld r4,HSTATE_SPURR(r13) |
| 1389 | add r3,r3,r5 |
| 1390 | add r4,r4,r6 |
| 1391 | mtspr SPRN_PURR,r3 |
| 1392 | mtspr SPRN_SPURR,r4 |
| 1393 | |
Paul Mackerras | 93b0f4d | 2013-09-06 13:17:46 +1000 | [diff] [blame] | 1394 | /* Save DEC */ |
| 1395 | mfspr r5,SPRN_DEC |
| 1396 | mftb r6 |
| 1397 | extsw r5,r5 |
| 1398 | add r5,r5,r6 |
Paul Mackerras | c5fb80d | 2014-03-25 10:47:07 +1100 | [diff] [blame] | 1399 | /* r5 is a guest timebase value here, convert to host TB */ |
| 1400 | ld r3,HSTATE_KVM_VCORE(r13) |
| 1401 | ld r4,VCORE_TB_OFFSET(r3) |
| 1402 | subf r5,r4,r5 |
Paul Mackerras | 93b0f4d | 2013-09-06 13:17:46 +1000 | [diff] [blame] | 1403 | std r5,VCPU_DEC_EXPIRES(r9) |
| 1404 | |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1405 | BEGIN_FTR_SECTION |
| 1406 | b 8f |
| 1407 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1408 | /* Save POWER8-specific registers */ |
| 1409 | mfspr r5, SPRN_IAMR |
| 1410 | mfspr r6, SPRN_PSPB |
| 1411 | mfspr r7, SPRN_FSCR |
| 1412 | std r5, VCPU_IAMR(r9) |
| 1413 | stw r6, VCPU_PSPB(r9) |
| 1414 | std r7, VCPU_FSCR(r9) |
| 1415 | mfspr r5, SPRN_IC |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1416 | mfspr r7, SPRN_TAR |
| 1417 | std r5, VCPU_IC(r9) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1418 | std r7, VCPU_TAR(r9) |
Michael Neuling | 7b49041 | 2014-01-08 21:25:32 +1100 | [diff] [blame] | 1419 | mfspr r8, SPRN_EBBHR |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1420 | std r8, VCPU_EBBHR(r9) |
| 1421 | mfspr r5, SPRN_EBBRR |
| 1422 | mfspr r6, SPRN_BESCR |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1423 | mfspr r7, SPRN_PID |
| 1424 | mfspr r8, SPRN_WORT |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 1425 | std r5, VCPU_EBBRR(r9) |
| 1426 | std r6, VCPU_BESCR(r9) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1427 | stw r7, VCPU_GUEST_PID(r9) |
| 1428 | std r8, VCPU_WORT(r9) |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 1429 | BEGIN_FTR_SECTION |
| 1430 | mfspr r5, SPRN_TCSCR |
| 1431 | mfspr r6, SPRN_ACOP |
| 1432 | mfspr r7, SPRN_CSIGR |
| 1433 | mfspr r8, SPRN_TACR |
| 1434 | std r5, VCPU_TCSCR(r9) |
| 1435 | std r6, VCPU_ACOP(r9) |
| 1436 | std r7, VCPU_CSIGR(r9) |
| 1437 | std r8, VCPU_TACR(r9) |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 1438 | FTR_SECTION_ELSE |
| 1439 | mfspr r5, SPRN_TIDR |
| 1440 | mfspr r6, SPRN_PSSCR |
| 1441 | std r5, VCPU_TID(r9) |
| 1442 | rldicl r6, r6, 4, 50 /* r6 &= PSSCR_GUEST_VIS */ |
| 1443 | rotldi r6, r6, 60 |
| 1444 | std r6, VCPU_PSSCR(r9) |
| 1445 | ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_300) |
Paul Mackerras | ccec445 | 2016-03-05 19:34:39 +1100 | [diff] [blame] | 1446 | /* |
| 1447 | * Restore various registers to 0, where non-zero values |
| 1448 | * set by the guest could disrupt the host. |
| 1449 | */ |
| 1450 | li r0, 0 |
| 1451 | mtspr SPRN_IAMR, r0 |
| 1452 | mtspr SPRN_CIABR, r0 |
| 1453 | mtspr SPRN_DAWRX, r0 |
Paul Mackerras | ccec445 | 2016-03-05 19:34:39 +1100 | [diff] [blame] | 1454 | mtspr SPRN_WORT, r0 |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 1455 | BEGIN_FTR_SECTION |
| 1456 | mtspr SPRN_TCSCR, r0 |
Paul Mackerras | ccec445 | 2016-03-05 19:34:39 +1100 | [diff] [blame] | 1457 | /* Set MMCRS to 1<<31 to freeze and disable the SPMC counters */ |
| 1458 | li r0, 1 |
| 1459 | sldi r0, r0, 31 |
| 1460 | mtspr SPRN_MMCRS, r0 |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 1461 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1462 | 8: |
| 1463 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1464 | /* Save and reset AMR and UAMOR before turning on the MMU */ |
| 1465 | mfspr r5,SPRN_AMR |
| 1466 | mfspr r6,SPRN_UAMOR |
| 1467 | std r5,VCPU_AMR(r9) |
| 1468 | std r6,VCPU_UAMOR(r9) |
| 1469 | li r6,0 |
| 1470 | mtspr SPRN_AMR,r6 |
| 1471 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1472 | /* Switch DSCR back to host value */ |
| 1473 | mfspr r8, SPRN_DSCR |
| 1474 | ld r7, HSTATE_DSCR(r13) |
Paul Mackerras | cfc8602 | 2013-09-21 09:53:28 +1000 | [diff] [blame] | 1475 | std r8, VCPU_DSCR(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1476 | mtspr SPRN_DSCR, r7 |
| 1477 | |
| 1478 | /* Save non-volatile GPRs */ |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1479 | std r14, VCPU_GPR(R14)(r9) |
| 1480 | std r15, VCPU_GPR(R15)(r9) |
| 1481 | std r16, VCPU_GPR(R16)(r9) |
| 1482 | std r17, VCPU_GPR(R17)(r9) |
| 1483 | std r18, VCPU_GPR(R18)(r9) |
| 1484 | std r19, VCPU_GPR(R19)(r9) |
| 1485 | std r20, VCPU_GPR(R20)(r9) |
| 1486 | std r21, VCPU_GPR(R21)(r9) |
| 1487 | std r22, VCPU_GPR(R22)(r9) |
| 1488 | std r23, VCPU_GPR(R23)(r9) |
| 1489 | std r24, VCPU_GPR(R24)(r9) |
| 1490 | std r25, VCPU_GPR(R25)(r9) |
| 1491 | std r26, VCPU_GPR(R26)(r9) |
| 1492 | std r27, VCPU_GPR(R27)(r9) |
| 1493 | std r28, VCPU_GPR(R28)(r9) |
| 1494 | std r29, VCPU_GPR(R29)(r9) |
| 1495 | std r30, VCPU_GPR(R30)(r9) |
| 1496 | std r31, VCPU_GPR(R31)(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1497 | |
| 1498 | /* Save SPRGs */ |
| 1499 | mfspr r3, SPRN_SPRG0 |
| 1500 | mfspr r4, SPRN_SPRG1 |
| 1501 | mfspr r5, SPRN_SPRG2 |
| 1502 | mfspr r6, SPRN_SPRG3 |
| 1503 | std r3, VCPU_SPRG0(r9) |
| 1504 | std r4, VCPU_SPRG1(r9) |
| 1505 | std r5, VCPU_SPRG2(r9) |
| 1506 | std r6, VCPU_SPRG3(r9) |
| 1507 | |
Paul Mackerras | 8943633 | 2012-03-02 01:38:23 +0000 | [diff] [blame] | 1508 | /* save FP state */ |
| 1509 | mr r3, r9 |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 1510 | bl kvmppc_save_fp |
Paul Mackerras | 8943633 | 2012-03-02 01:38:23 +0000 | [diff] [blame] | 1511 | |
Paul Mackerras | 0a8ecce | 2014-04-14 08:56:26 +1000 | [diff] [blame] | 1512 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
| 1513 | BEGIN_FTR_SECTION |
Paul Mackerras | f024ee0 | 2016-06-22 14:21:59 +1000 | [diff] [blame] | 1514 | bl kvmppc_save_tm |
| 1515 | END_FTR_SECTION_IFSET(CPU_FTR_TM) |
Paul Mackerras | 0a8ecce | 2014-04-14 08:56:26 +1000 | [diff] [blame] | 1516 | #endif |
| 1517 | |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1518 | /* Increment yield count if they have a VPA */ |
| 1519 | ld r8, VCPU_VPA(r9) /* do they have a VPA? */ |
| 1520 | cmpdi r8, 0 |
| 1521 | beq 25f |
Alexander Graf | 0865a58 | 2014-06-11 10:36:17 +0200 | [diff] [blame] | 1522 | li r4, LPPACA_YIELDCOUNT |
| 1523 | LWZX_BE r3, r8, r4 |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1524 | addi r3, r3, 1 |
Alexander Graf | 0865a58 | 2014-06-11 10:36:17 +0200 | [diff] [blame] | 1525 | STWX_BE r3, r8, r4 |
Paul Mackerras | c35635e | 2013-04-18 19:51:04 +0000 | [diff] [blame] | 1526 | li r3, 1 |
| 1527 | stb r3, VCPU_VPA_DIRTY(r9) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1528 | 25: |
| 1529 | /* Save PMU registers if requested */ |
| 1530 | /* r8 and cr0.eq are live here */ |
Paul Mackerras | 9bc01a9 | 2014-05-26 19:48:40 +1000 | [diff] [blame] | 1531 | BEGIN_FTR_SECTION |
| 1532 | /* |
| 1533 | * POWER8 seems to have a hardware bug where setting |
| 1534 | * MMCR0[PMAE] along with MMCR0[PMC1CE] and/or MMCR0[PMCjCE] |
| 1535 | * when some counters are already negative doesn't seem |
| 1536 | * to cause a performance monitor alert (and hence interrupt). |
| 1537 | * The effect of this is that when saving the PMU state, |
| 1538 | * if there is no PMU alert pending when we read MMCR0 |
| 1539 | * before freezing the counters, but one becomes pending |
| 1540 | * before we read the counters, we lose it. |
| 1541 | * To work around this, we need a way to freeze the counters |
| 1542 | * before reading MMCR0. Normally, freezing the counters |
| 1543 | * is done by writing MMCR0 (to set MMCR0[FC]) which |
| 1544 | * unavoidably writes MMCR0[PMA0] as well. On POWER8, |
| 1545 | * we can also freeze the counters using MMCR2, by writing |
| 1546 | * 1s to all the counter freeze condition bits (there are |
| 1547 | * 9 bits each for 6 counters). |
| 1548 | */ |
| 1549 | li r3, -1 /* set all freeze bits */ |
| 1550 | clrrdi r3, r3, 10 |
| 1551 | mfspr r10, SPRN_MMCR2 |
| 1552 | mtspr SPRN_MMCR2, r3 |
| 1553 | isync |
| 1554 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1555 | li r3, 1 |
| 1556 | sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */ |
| 1557 | mfspr r4, SPRN_MMCR0 /* save MMCR0 */ |
| 1558 | mtspr SPRN_MMCR0, r3 /* freeze all counters, disable ints */ |
Paul Mackerras | 8943633 | 2012-03-02 01:38:23 +0000 | [diff] [blame] | 1559 | mfspr r6, SPRN_MMCRA |
Paul Mackerras | c17b98c | 2014-12-03 13:30:38 +1100 | [diff] [blame] | 1560 | /* Clear MMCRA in order to disable SDAR updates */ |
Paul Mackerras | 8943633 | 2012-03-02 01:38:23 +0000 | [diff] [blame] | 1561 | li r7, 0 |
| 1562 | mtspr SPRN_MMCRA, r7 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1563 | isync |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1564 | beq 21f /* if no VPA, save PMU stuff anyway */ |
| 1565 | lbz r7, LPPACA_PMCINUSE(r8) |
| 1566 | cmpwi r7, 0 /* did they ask for PMU stuff to be saved? */ |
| 1567 | bne 21f |
| 1568 | std r3, VCPU_MMCR(r9) /* if not, set saved MMCR0 to FC */ |
| 1569 | b 22f |
| 1570 | 21: mfspr r5, SPRN_MMCR1 |
Paul Mackerras | 1494178 | 2013-09-06 13:11:18 +1000 | [diff] [blame] | 1571 | mfspr r7, SPRN_SIAR |
| 1572 | mfspr r8, SPRN_SDAR |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1573 | std r4, VCPU_MMCR(r9) |
| 1574 | std r5, VCPU_MMCR + 8(r9) |
| 1575 | std r6, VCPU_MMCR + 16(r9) |
Paul Mackerras | 9bc01a9 | 2014-05-26 19:48:40 +1000 | [diff] [blame] | 1576 | BEGIN_FTR_SECTION |
| 1577 | std r10, VCPU_MMCR + 24(r9) |
| 1578 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
Paul Mackerras | 1494178 | 2013-09-06 13:11:18 +1000 | [diff] [blame] | 1579 | std r7, VCPU_SIAR(r9) |
| 1580 | std r8, VCPU_SDAR(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1581 | mfspr r3, SPRN_PMC1 |
| 1582 | mfspr r4, SPRN_PMC2 |
| 1583 | mfspr r5, SPRN_PMC3 |
| 1584 | mfspr r6, SPRN_PMC4 |
| 1585 | mfspr r7, SPRN_PMC5 |
| 1586 | mfspr r8, SPRN_PMC6 |
| 1587 | stw r3, VCPU_PMC(r9) |
| 1588 | stw r4, VCPU_PMC + 4(r9) |
| 1589 | stw r5, VCPU_PMC + 8(r9) |
| 1590 | stw r6, VCPU_PMC + 12(r9) |
| 1591 | stw r7, VCPU_PMC + 16(r9) |
| 1592 | stw r8, VCPU_PMC + 20(r9) |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1593 | BEGIN_FTR_SECTION |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1594 | mfspr r5, SPRN_SIER |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 1595 | std r5, VCPU_SIER(r9) |
| 1596 | BEGIN_FTR_SECTION_NESTED(96) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1597 | mfspr r6, SPRN_SPMC1 |
| 1598 | mfspr r7, SPRN_SPMC2 |
| 1599 | mfspr r8, SPRN_MMCRS |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1600 | stw r6, VCPU_PMC + 24(r9) |
| 1601 | stw r7, VCPU_PMC + 28(r9) |
| 1602 | std r8, VCPU_MMCR + 32(r9) |
| 1603 | lis r4, 0x8000 |
| 1604 | mtspr SPRN_MMCRS, r4 |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 1605 | END_FTR_SECTION_NESTED(CPU_FTR_ARCH_300, 0, 96) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1606 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1607 | 22: |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1608 | /* Clear out SLB */ |
| 1609 | li r5,0 |
| 1610 | slbmte r5,r5 |
| 1611 | slbia |
| 1612 | ptesync |
| 1613 | |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 1614 | /* Restore host values of some registers */ |
| 1615 | BEGIN_FTR_SECTION |
| 1616 | ld r5, STACK_SLOT_TID(r1) |
| 1617 | ld r6, STACK_SLOT_PSSCR(r1) |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 1618 | ld r7, STACK_SLOT_PID(r1) |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 1619 | mtspr SPRN_TIDR, r5 |
| 1620 | mtspr SPRN_PSSCR, r6 |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 1621 | mtspr SPRN_PID, r7 |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 1622 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300) |
| 1623 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1624 | /* |
Paul Mackerras | c17b98c | 2014-12-03 13:30:38 +1100 | [diff] [blame] | 1625 | * POWER7/POWER8 guest -> host partition switch code. |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1626 | * We don't have to lock against tlbies but we do |
| 1627 | * have to coordinate the hardware threads. |
| 1628 | */ |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1629 | kvmhv_switch_to_host: |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1630 | /* Secondary threads wait for primary to do partition switch */ |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1631 | ld r5,HSTATE_KVM_VCORE(r13) |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1632 | ld r4,VCORE_KVM(r5) /* pointer to struct kvm */ |
| 1633 | lbz r3,HSTATE_PTID(r13) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1634 | cmpwi r3,0 |
| 1635 | beq 15f |
| 1636 | HMT_LOW |
| 1637 | 13: lbz r3,VCORE_IN_GUEST(r5) |
| 1638 | cmpwi r3,0 |
| 1639 | bne 13b |
| 1640 | HMT_MEDIUM |
| 1641 | b 16f |
| 1642 | |
| 1643 | /* Primary thread waits for all the secondaries to exit guest */ |
| 1644 | 15: lwz r3,VCORE_ENTRY_EXIT(r5) |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 1645 | rlwinm r0,r3,32-8,0xff |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1646 | clrldi r3,r3,56 |
| 1647 | cmpw r3,r0 |
| 1648 | bne 15b |
| 1649 | isync |
| 1650 | |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 1651 | /* Did we actually switch to the guest at all? */ |
| 1652 | lbz r6, VCORE_IN_GUEST(r5) |
| 1653 | cmpwi r6, 0 |
| 1654 | beq 19f |
| 1655 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1656 | /* Primary thread switches back to host partition */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1657 | lwz r7,KVM_HOST_LPID(r4) |
Paul Mackerras | 7a84084 | 2016-11-16 22:25:20 +1100 | [diff] [blame] | 1658 | BEGIN_FTR_SECTION |
| 1659 | ld r6,KVM_HOST_SDR1(r4) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1660 | li r8,LPID_RSVD /* switch to reserved LPID */ |
| 1661 | mtspr SPRN_LPID,r8 |
| 1662 | ptesync |
Paul Mackerras | 7a84084 | 2016-11-16 22:25:20 +1100 | [diff] [blame] | 1663 | mtspr SPRN_SDR1,r6 /* switch to host page table */ |
| 1664 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1665 | mtspr SPRN_LPID,r7 |
| 1666 | isync |
| 1667 | |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1668 | BEGIN_FTR_SECTION |
Paul Mackerras | 88b02cf9 | 2016-09-15 13:42:52 +1000 | [diff] [blame] | 1669 | /* DPDES and VTB are shared between threads */ |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1670 | mfspr r7, SPRN_DPDES |
Paul Mackerras | 88b02cf9 | 2016-09-15 13:42:52 +1000 | [diff] [blame] | 1671 | mfspr r8, SPRN_VTB |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1672 | std r7, VCORE_DPDES(r5) |
Paul Mackerras | 88b02cf9 | 2016-09-15 13:42:52 +1000 | [diff] [blame] | 1673 | std r8, VCORE_VTB(r5) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1674 | /* clear DPDES so we don't get guest doorbells in the host */ |
| 1675 | li r8, 0 |
| 1676 | mtspr SPRN_DPDES, r8 |
| 1677 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
| 1678 | |
Mahesh Salgaonkar | fd7bacb | 2016-05-15 09:44:26 +0530 | [diff] [blame] | 1679 | /* If HMI, call kvmppc_realmode_hmi_handler() */ |
| 1680 | cmpwi r12, BOOK3S_INTERRUPT_HMI |
| 1681 | bne 27f |
| 1682 | bl kvmppc_realmode_hmi_handler |
| 1683 | nop |
| 1684 | li r12, BOOK3S_INTERRUPT_HMI |
| 1685 | /* |
| 1686 | * At this point kvmppc_realmode_hmi_handler would have resync-ed |
| 1687 | * the TB. Hence it is not required to subtract guest timebase |
| 1688 | * offset from timebase. So, skip it. |
| 1689 | * |
| 1690 | * Also, do not call kvmppc_subcore_exit_guest() because it has |
| 1691 | * been invoked as part of kvmppc_realmode_hmi_handler(). |
| 1692 | */ |
| 1693 | b 30f |
| 1694 | |
| 1695 | 27: |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1696 | /* Subtract timebase offset from timebase */ |
| 1697 | ld r8,VCORE_TB_OFFSET(r5) |
| 1698 | cmpdi r8,0 |
| 1699 | beq 17f |
Paul Mackerras | c5fb80d | 2014-03-25 10:47:07 +1100 | [diff] [blame] | 1700 | mftb r6 /* current guest timebase */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1701 | subf r8,r8,r6 |
| 1702 | mtspr SPRN_TBU40,r8 /* update upper 40 bits */ |
| 1703 | mftb r7 /* check if lower 24 bits overflowed */ |
| 1704 | clrldi r6,r6,40 |
| 1705 | clrldi r7,r7,40 |
| 1706 | cmpld r7,r6 |
| 1707 | bge 17f |
| 1708 | addis r8,r8,0x100 /* if so, increment upper 40 bits */ |
| 1709 | mtspr SPRN_TBU40,r8 |
| 1710 | |
Mahesh Salgaonkar | fd7bacb | 2016-05-15 09:44:26 +0530 | [diff] [blame] | 1711 | 17: bl kvmppc_subcore_exit_guest |
| 1712 | nop |
| 1713 | 30: ld r5,HSTATE_KVM_VCORE(r13) |
| 1714 | ld r4,VCORE_KVM(r5) /* pointer to struct kvm */ |
| 1715 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1716 | /* Reset PCR */ |
Mahesh Salgaonkar | fd7bacb | 2016-05-15 09:44:26 +0530 | [diff] [blame] | 1717 | ld r0, VCORE_PCR(r5) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1718 | cmpdi r0, 0 |
| 1719 | beq 18f |
| 1720 | li r0, 0 |
| 1721 | mtspr SPRN_PCR, r0 |
| 1722 | 18: |
| 1723 | /* Signal secondary CPUs to continue */ |
| 1724 | stb r0,VCORE_IN_GUEST(r5) |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 1725 | 19: lis r8,0x7fff /* MAX_INT@h */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1726 | mtspr SPRN_HDEC,r8 |
| 1727 | |
| 1728 | 16: ld r8,KVM_HOST_LPCR(r4) |
| 1729 | mtspr SPRN_LPCR,r8 |
| 1730 | isync |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1731 | |
| 1732 | /* load host SLB entries */ |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 1733 | BEGIN_MMU_FTR_SECTION |
| 1734 | b 0f |
| 1735 | END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_RADIX) |
Paul Mackerras | c17b98c | 2014-12-03 13:30:38 +1100 | [diff] [blame] | 1736 | ld r8,PACA_SLBSHADOWPTR(r13) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1737 | |
| 1738 | .rept SLB_NUM_BOLTED |
Alexander Graf | 0865a58 | 2014-06-11 10:36:17 +0200 | [diff] [blame] | 1739 | li r3, SLBSHADOW_SAVEAREA |
| 1740 | LDX_BE r5, r8, r3 |
| 1741 | addi r3, r3, 8 |
| 1742 | LDX_BE r6, r8, r3 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1743 | andis. r7,r5,SLB_ESID_V@h |
| 1744 | beq 1f |
| 1745 | slbmte r6,r5 |
| 1746 | 1: addi r8,r8,16 |
| 1747 | .endr |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 1748 | 0: |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1749 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
| 1750 | /* Finish timing, if we have a vcpu */ |
| 1751 | ld r4, HSTATE_KVM_VCPU(r13) |
| 1752 | cmpdi r4, 0 |
| 1753 | li r3, 0 |
| 1754 | beq 2f |
| 1755 | bl kvmhv_accumulate_time |
| 1756 | 2: |
| 1757 | #endif |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1758 | /* Unset guest mode */ |
| 1759 | li r0, KVM_GUEST_MODE_NONE |
| 1760 | stb r0, HSTATE_IN_GUEST(r13) |
| 1761 | |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 1762 | ld r0, 112+PPC_LR_STKOFF(r1) |
| 1763 | addi r1, r1, 112 |
| 1764 | mtlr r0 |
| 1765 | blr |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1766 | |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1767 | /* |
| 1768 | * Check whether an HDSI is an HPTE not found fault or something else. |
| 1769 | * If it is an HPTE not found fault that is due to the guest accessing |
| 1770 | * a page that they have mapped but which we have paged out, then |
| 1771 | * we continue on with the guest exit path. In all other cases, |
| 1772 | * reflect the HDSI to the guest as a DSI. |
| 1773 | */ |
| 1774 | kvmppc_hdsi: |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 1775 | ld r3, VCPU_KVM(r9) |
| 1776 | lbz r0, KVM_RADIX(r3) |
| 1777 | cmpwi r0, 0 |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1778 | mfspr r4, SPRN_HDAR |
| 1779 | mfspr r6, SPRN_HDSISR |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 1780 | bne .Lradix_hdsi /* on radix, just save DAR/DSISR/ASDR */ |
Paul Mackerras | 4cf302b | 2011-12-12 12:38:51 +0000 | [diff] [blame] | 1781 | /* HPTE not found fault or protection fault? */ |
| 1782 | andis. r0, r6, (DSISR_NOHPTE | DSISR_PROTFAULT)@h |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1783 | beq 1f /* if not, send it to the guest */ |
Paul Mackerras | ef8c640 | 2017-01-30 21:21:43 +1100 | [diff] [blame] | 1784 | BEGIN_FTR_SECTION |
| 1785 | mfspr r5, SPRN_ASDR /* on POWER9, use ASDR to get VSID */ |
| 1786 | b 4f |
| 1787 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300) |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1788 | andi. r0, r11, MSR_DR /* data relocation enabled? */ |
| 1789 | beq 3f |
| 1790 | clrrdi r0, r4, 28 |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1791 | PPC_SLBFEE_DOT(R5, R0) /* if so, look up SLB */ |
Paul Mackerras | cf29b21 | 2015-10-27 16:10:20 +1100 | [diff] [blame] | 1792 | li r0, BOOK3S_INTERRUPT_DATA_SEGMENT |
| 1793 | bne 7f /* if no SLB entry found */ |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1794 | 4: std r4, VCPU_FAULT_DAR(r9) |
| 1795 | stw r6, VCPU_FAULT_DSISR(r9) |
| 1796 | |
| 1797 | /* Search the hash table. */ |
| 1798 | mr r3, r9 /* vcpu pointer */ |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1799 | li r7, 1 /* data fault */ |
Anton Blanchard | b1576fe | 2014-02-04 16:04:35 +1100 | [diff] [blame] | 1800 | bl kvmppc_hpte_hv_fault |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1801 | ld r9, HSTATE_KVM_VCPU(r13) |
| 1802 | ld r10, VCPU_PC(r9) |
| 1803 | ld r11, VCPU_MSR(r9) |
| 1804 | li r12, BOOK3S_INTERRUPT_H_DATA_STORAGE |
| 1805 | cmpdi r3, 0 /* retry the instruction */ |
| 1806 | beq 6f |
| 1807 | cmpdi r3, -1 /* handle in kernel mode */ |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1808 | beq guest_exit_cont |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1809 | cmpdi r3, -2 /* MMIO emulation; need instr word */ |
| 1810 | beq 2f |
| 1811 | |
Paul Mackerras | cf29b21 | 2015-10-27 16:10:20 +1100 | [diff] [blame] | 1812 | /* Synthesize a DSI (or DSegI) for the guest */ |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1813 | ld r4, VCPU_FAULT_DAR(r9) |
| 1814 | mr r6, r3 |
Paul Mackerras | cf29b21 | 2015-10-27 16:10:20 +1100 | [diff] [blame] | 1815 | 1: li r0, BOOK3S_INTERRUPT_DATA_STORAGE |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1816 | mtspr SPRN_DSISR, r6 |
Paul Mackerras | cf29b21 | 2015-10-27 16:10:20 +1100 | [diff] [blame] | 1817 | 7: mtspr SPRN_DAR, r4 |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1818 | mtspr SPRN_SRR0, r10 |
| 1819 | mtspr SPRN_SRR1, r11 |
Paul Mackerras | cf29b21 | 2015-10-27 16:10:20 +1100 | [diff] [blame] | 1820 | mr r10, r0 |
Michael Neuling | e4e3812 | 2014-03-25 10:47:02 +1100 | [diff] [blame] | 1821 | bl kvmppc_msr_interrupt |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1822 | fast_interrupt_c_return: |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1823 | 6: ld r7, VCPU_CTR(r9) |
Sam bobroff | c63517c | 2015-05-27 09:56:57 +1000 | [diff] [blame] | 1824 | ld r8, VCPU_XER(r9) |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1825 | mtctr r7 |
| 1826 | mtxer r8 |
| 1827 | mr r4, r9 |
| 1828 | b fast_guest_return |
| 1829 | |
| 1830 | 3: ld r5, VCPU_KVM(r9) /* not relocated, use VRMA */ |
| 1831 | ld r5, KVM_VRMA_SLB_V(r5) |
| 1832 | b 4b |
| 1833 | |
| 1834 | /* If this is for emulated MMIO, load the instruction word */ |
| 1835 | 2: li r8, KVM_INST_FETCH_FAILED /* In case lwz faults */ |
| 1836 | |
| 1837 | /* Set guest mode to 'jump over instruction' so if lwz faults |
| 1838 | * we'll just continue at the next IP. */ |
| 1839 | li r0, KVM_GUEST_MODE_SKIP |
| 1840 | stb r0, HSTATE_IN_GUEST(r13) |
| 1841 | |
| 1842 | /* Do the access with MSR:DR enabled */ |
| 1843 | mfmsr r3 |
| 1844 | ori r4, r3, MSR_DR /* Enable paging for data */ |
| 1845 | mtmsrd r4 |
| 1846 | lwz r8, 0(r10) |
| 1847 | mtmsrd r3 |
| 1848 | |
| 1849 | /* Store the result */ |
| 1850 | stw r8, VCPU_LAST_INST(r9) |
| 1851 | |
| 1852 | /* Unset guest mode. */ |
Paul Mackerras | 44a3add | 2013-10-04 21:45:04 +1000 | [diff] [blame] | 1853 | li r0, KVM_GUEST_MODE_HOST_HV |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1854 | stb r0, HSTATE_IN_GUEST(r13) |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1855 | b guest_exit_cont |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1856 | |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 1857 | .Lradix_hdsi: |
| 1858 | std r4, VCPU_FAULT_DAR(r9) |
| 1859 | stw r6, VCPU_FAULT_DSISR(r9) |
| 1860 | .Lradix_hisi: |
| 1861 | mfspr r5, SPRN_ASDR |
| 1862 | std r5, VCPU_FAULT_GPA(r9) |
| 1863 | b guest_exit_cont |
| 1864 | |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1865 | /* |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1866 | * Similarly for an HISI, reflect it to the guest as an ISI unless |
| 1867 | * it is an HPTE not found fault for a page that we have paged out. |
| 1868 | */ |
| 1869 | kvmppc_hisi: |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 1870 | ld r3, VCPU_KVM(r9) |
| 1871 | lbz r0, KVM_RADIX(r3) |
| 1872 | cmpwi r0, 0 |
| 1873 | bne .Lradix_hisi /* for radix, just save ASDR */ |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1874 | andis. r0, r11, SRR1_ISI_NOPT@h |
| 1875 | beq 1f |
Paul Mackerras | ef8c640 | 2017-01-30 21:21:43 +1100 | [diff] [blame] | 1876 | BEGIN_FTR_SECTION |
| 1877 | mfspr r5, SPRN_ASDR /* on POWER9, use ASDR to get VSID */ |
| 1878 | b 4f |
| 1879 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300) |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1880 | andi. r0, r11, MSR_IR /* instruction relocation enabled? */ |
| 1881 | beq 3f |
| 1882 | clrrdi r0, r10, 28 |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1883 | PPC_SLBFEE_DOT(R5, R0) /* if so, look up SLB */ |
Paul Mackerras | cf29b21 | 2015-10-27 16:10:20 +1100 | [diff] [blame] | 1884 | li r0, BOOK3S_INTERRUPT_INST_SEGMENT |
| 1885 | bne 7f /* if no SLB entry found */ |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1886 | 4: |
| 1887 | /* Search the hash table. */ |
| 1888 | mr r3, r9 /* vcpu pointer */ |
| 1889 | mr r4, r10 |
| 1890 | mr r6, r11 |
| 1891 | li r7, 0 /* instruction fault */ |
Anton Blanchard | b1576fe | 2014-02-04 16:04:35 +1100 | [diff] [blame] | 1892 | bl kvmppc_hpte_hv_fault |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1893 | ld r9, HSTATE_KVM_VCPU(r13) |
| 1894 | ld r10, VCPU_PC(r9) |
| 1895 | ld r11, VCPU_MSR(r9) |
| 1896 | li r12, BOOK3S_INTERRUPT_H_INST_STORAGE |
| 1897 | cmpdi r3, 0 /* retry the instruction */ |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1898 | beq fast_interrupt_c_return |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1899 | cmpdi r3, -1 /* handle in kernel mode */ |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1900 | beq guest_exit_cont |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1901 | |
Paul Mackerras | cf29b21 | 2015-10-27 16:10:20 +1100 | [diff] [blame] | 1902 | /* Synthesize an ISI (or ISegI) for the guest */ |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1903 | mr r11, r3 |
Paul Mackerras | cf29b21 | 2015-10-27 16:10:20 +1100 | [diff] [blame] | 1904 | 1: li r0, BOOK3S_INTERRUPT_INST_STORAGE |
| 1905 | 7: mtspr SPRN_SRR0, r10 |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1906 | mtspr SPRN_SRR1, r11 |
Paul Mackerras | cf29b21 | 2015-10-27 16:10:20 +1100 | [diff] [blame] | 1907 | mr r10, r0 |
Michael Neuling | e4e3812 | 2014-03-25 10:47:02 +1100 | [diff] [blame] | 1908 | bl kvmppc_msr_interrupt |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1909 | b fast_interrupt_c_return |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1910 | |
| 1911 | 3: ld r6, VCPU_KVM(r9) /* not relocated, use VRMA */ |
| 1912 | ld r5, KVM_VRMA_SLB_V(r6) |
| 1913 | b 4b |
| 1914 | |
| 1915 | /* |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1916 | * Try to handle an hcall in real mode. |
| 1917 | * Returns to the guest if we handle it, or continues on up to |
| 1918 | * the kernel if we can't (i.e. if we don't have a handler for |
| 1919 | * it, or if the handler returns H_TOO_HARD). |
Paul Mackerras | 1f09c3e | 2015-03-28 14:21:04 +1100 | [diff] [blame] | 1920 | * |
| 1921 | * r5 - r8 contain hcall args, |
| 1922 | * r9 = vcpu, r10 = pc, r11 = msr, r12 = trap, r13 = paca |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1923 | */ |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1924 | hcall_try_real_mode: |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1925 | ld r3,VCPU_GPR(R3)(r9) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1926 | andi. r0,r11,MSR_PR |
Liu Ping Fan | 27025a6 | 2013-11-19 14:12:48 +0800 | [diff] [blame] | 1927 | /* sc 1 from userspace - reflect to guest syscall */ |
| 1928 | bne sc_1_fast_return |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1929 | clrrdi r3,r3,2 |
| 1930 | cmpldi r3,hcall_real_table_end - hcall_real_table |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1931 | bge guest_exit_cont |
Paul Mackerras | 699a0ea | 2014-06-02 11:02:59 +1000 | [diff] [blame] | 1932 | /* See if this hcall is enabled for in-kernel handling */ |
| 1933 | ld r4, VCPU_KVM(r9) |
| 1934 | srdi r0, r3, 8 /* r0 = (r3 / 4) >> 6 */ |
| 1935 | sldi r0, r0, 3 /* index into kvm->arch.enabled_hcalls[] */ |
| 1936 | add r4, r4, r0 |
| 1937 | ld r0, KVM_ENABLED_HCALLS(r4) |
| 1938 | rlwinm r4, r3, 32-2, 0x3f /* r4 = (r3 / 4) & 0x3f */ |
| 1939 | srd r0, r0, r4 |
| 1940 | andi. r0, r0, 1 |
| 1941 | beq guest_exit_cont |
| 1942 | /* Get pointer to handler, if any, and call it */ |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1943 | LOAD_REG_ADDR(r4, hcall_real_table) |
Paul Mackerras | 4baa1d8 | 2013-07-08 20:09:53 +1000 | [diff] [blame] | 1944 | lwax r3,r3,r4 |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1945 | cmpwi r3,0 |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1946 | beq guest_exit_cont |
Anton Blanchard | 05a308c | 2014-06-12 18:16:10 +1000 | [diff] [blame] | 1947 | add r12,r3,r4 |
| 1948 | mtctr r12 |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1949 | mr r3,r9 /* get vcpu pointer */ |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1950 | ld r4,VCPU_GPR(R4)(r9) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1951 | bctrl |
| 1952 | cmpdi r3,H_TOO_HARD |
| 1953 | beq hcall_real_fallback |
| 1954 | ld r4,HSTATE_KVM_VCPU(r13) |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1955 | std r3,VCPU_GPR(R3)(r4) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1956 | ld r10,VCPU_PC(r4) |
| 1957 | ld r11,VCPU_MSR(r4) |
| 1958 | b fast_guest_return |
| 1959 | |
Liu Ping Fan | 27025a6 | 2013-11-19 14:12:48 +0800 | [diff] [blame] | 1960 | sc_1_fast_return: |
| 1961 | mtspr SPRN_SRR0,r10 |
| 1962 | mtspr SPRN_SRR1,r11 |
| 1963 | li r10, BOOK3S_INTERRUPT_SYSCALL |
Michael Neuling | e4e3812 | 2014-03-25 10:47:02 +1100 | [diff] [blame] | 1964 | bl kvmppc_msr_interrupt |
Liu Ping Fan | 27025a6 | 2013-11-19 14:12:48 +0800 | [diff] [blame] | 1965 | mr r4,r9 |
| 1966 | b fast_guest_return |
| 1967 | |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1968 | /* We've attempted a real mode hcall, but it's punted it back |
| 1969 | * to userspace. We need to restore some clobbered volatiles |
| 1970 | * before resuming the pass-it-to-qemu path */ |
| 1971 | hcall_real_fallback: |
| 1972 | li r12,BOOK3S_INTERRUPT_SYSCALL |
| 1973 | ld r9, HSTATE_KVM_VCPU(r13) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1974 | |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1975 | b guest_exit_cont |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1976 | |
| 1977 | .globl hcall_real_table |
| 1978 | hcall_real_table: |
| 1979 | .long 0 /* 0 - unused */ |
Anton Blanchard | c1fb019 | 2014-02-04 16:07:01 +1100 | [diff] [blame] | 1980 | .long DOTSYM(kvmppc_h_remove) - hcall_real_table |
| 1981 | .long DOTSYM(kvmppc_h_enter) - hcall_real_table |
| 1982 | .long DOTSYM(kvmppc_h_read) - hcall_real_table |
Paul Mackerras | cdeee51 | 2015-06-24 21:18:07 +1000 | [diff] [blame] | 1983 | .long DOTSYM(kvmppc_h_clear_mod) - hcall_real_table |
| 1984 | .long DOTSYM(kvmppc_h_clear_ref) - hcall_real_table |
Anton Blanchard | c1fb019 | 2014-02-04 16:07:01 +1100 | [diff] [blame] | 1985 | .long DOTSYM(kvmppc_h_protect) - hcall_real_table |
| 1986 | .long DOTSYM(kvmppc_h_get_tce) - hcall_real_table |
Alexey Kardashevskiy | 31217db | 2016-03-18 13:50:42 +1100 | [diff] [blame] | 1987 | .long DOTSYM(kvmppc_rm_h_put_tce) - hcall_real_table |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1988 | .long 0 /* 0x24 - H_SET_SPRG0 */ |
Anton Blanchard | c1fb019 | 2014-02-04 16:07:01 +1100 | [diff] [blame] | 1989 | .long DOTSYM(kvmppc_h_set_dabr) - hcall_real_table |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1990 | .long 0 /* 0x2c */ |
| 1991 | .long 0 /* 0x30 */ |
| 1992 | .long 0 /* 0x34 */ |
| 1993 | .long 0 /* 0x38 */ |
| 1994 | .long 0 /* 0x3c */ |
| 1995 | .long 0 /* 0x40 */ |
| 1996 | .long 0 /* 0x44 */ |
| 1997 | .long 0 /* 0x48 */ |
| 1998 | .long 0 /* 0x4c */ |
| 1999 | .long 0 /* 0x50 */ |
| 2000 | .long 0 /* 0x54 */ |
| 2001 | .long 0 /* 0x58 */ |
| 2002 | .long 0 /* 0x5c */ |
| 2003 | .long 0 /* 0x60 */ |
Benjamin Herrenschmidt | e7d26f2 | 2013-04-17 20:31:15 +0000 | [diff] [blame] | 2004 | #ifdef CONFIG_KVM_XICS |
Anton Blanchard | c1fb019 | 2014-02-04 16:07:01 +1100 | [diff] [blame] | 2005 | .long DOTSYM(kvmppc_rm_h_eoi) - hcall_real_table |
| 2006 | .long DOTSYM(kvmppc_rm_h_cppr) - hcall_real_table |
| 2007 | .long DOTSYM(kvmppc_rm_h_ipi) - hcall_real_table |
Benjamin Herrenschmidt | e7d26f2 | 2013-04-17 20:31:15 +0000 | [diff] [blame] | 2008 | .long 0 /* 0x70 - H_IPOLL */ |
Anton Blanchard | c1fb019 | 2014-02-04 16:07:01 +1100 | [diff] [blame] | 2009 | .long DOTSYM(kvmppc_rm_h_xirr) - hcall_real_table |
Benjamin Herrenschmidt | e7d26f2 | 2013-04-17 20:31:15 +0000 | [diff] [blame] | 2010 | #else |
| 2011 | .long 0 /* 0x64 - H_EOI */ |
| 2012 | .long 0 /* 0x68 - H_CPPR */ |
| 2013 | .long 0 /* 0x6c - H_IPI */ |
| 2014 | .long 0 /* 0x70 - H_IPOLL */ |
| 2015 | .long 0 /* 0x74 - H_XIRR */ |
| 2016 | #endif |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2017 | .long 0 /* 0x78 */ |
| 2018 | .long 0 /* 0x7c */ |
| 2019 | .long 0 /* 0x80 */ |
| 2020 | .long 0 /* 0x84 */ |
| 2021 | .long 0 /* 0x88 */ |
| 2022 | .long 0 /* 0x8c */ |
| 2023 | .long 0 /* 0x90 */ |
| 2024 | .long 0 /* 0x94 */ |
| 2025 | .long 0 /* 0x98 */ |
| 2026 | .long 0 /* 0x9c */ |
| 2027 | .long 0 /* 0xa0 */ |
| 2028 | .long 0 /* 0xa4 */ |
| 2029 | .long 0 /* 0xa8 */ |
| 2030 | .long 0 /* 0xac */ |
| 2031 | .long 0 /* 0xb0 */ |
| 2032 | .long 0 /* 0xb4 */ |
| 2033 | .long 0 /* 0xb8 */ |
| 2034 | .long 0 /* 0xbc */ |
| 2035 | .long 0 /* 0xc0 */ |
| 2036 | .long 0 /* 0xc4 */ |
| 2037 | .long 0 /* 0xc8 */ |
| 2038 | .long 0 /* 0xcc */ |
| 2039 | .long 0 /* 0xd0 */ |
| 2040 | .long 0 /* 0xd4 */ |
| 2041 | .long 0 /* 0xd8 */ |
| 2042 | .long 0 /* 0xdc */ |
Anton Blanchard | c1fb019 | 2014-02-04 16:07:01 +1100 | [diff] [blame] | 2043 | .long DOTSYM(kvmppc_h_cede) - hcall_real_table |
Sam Bobroff | 90fd09f | 2014-12-03 13:30:40 +1100 | [diff] [blame] | 2044 | .long DOTSYM(kvmppc_rm_h_confer) - hcall_real_table |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2045 | .long 0 /* 0xe8 */ |
| 2046 | .long 0 /* 0xec */ |
| 2047 | .long 0 /* 0xf0 */ |
| 2048 | .long 0 /* 0xf4 */ |
| 2049 | .long 0 /* 0xf8 */ |
| 2050 | .long 0 /* 0xfc */ |
| 2051 | .long 0 /* 0x100 */ |
| 2052 | .long 0 /* 0x104 */ |
| 2053 | .long 0 /* 0x108 */ |
| 2054 | .long 0 /* 0x10c */ |
| 2055 | .long 0 /* 0x110 */ |
| 2056 | .long 0 /* 0x114 */ |
| 2057 | .long 0 /* 0x118 */ |
| 2058 | .long 0 /* 0x11c */ |
| 2059 | .long 0 /* 0x120 */ |
Anton Blanchard | c1fb019 | 2014-02-04 16:07:01 +1100 | [diff] [blame] | 2060 | .long DOTSYM(kvmppc_h_bulk_remove) - hcall_real_table |
Paul Mackerras | 8563bf5 | 2014-01-08 21:25:29 +1100 | [diff] [blame] | 2061 | .long 0 /* 0x128 */ |
| 2062 | .long 0 /* 0x12c */ |
| 2063 | .long 0 /* 0x130 */ |
Anton Blanchard | c1fb019 | 2014-02-04 16:07:01 +1100 | [diff] [blame] | 2064 | .long DOTSYM(kvmppc_h_set_xdabr) - hcall_real_table |
Alexey Kardashevskiy | 31217db | 2016-03-18 13:50:42 +1100 | [diff] [blame] | 2065 | .long DOTSYM(kvmppc_rm_h_stuff_tce) - hcall_real_table |
Alexey Kardashevskiy | d3695aa | 2016-02-15 12:55:09 +1100 | [diff] [blame] | 2066 | .long DOTSYM(kvmppc_rm_h_put_tce_indirect) - hcall_real_table |
Michael Ellerman | e928e9c | 2015-03-20 20:39:41 +1100 | [diff] [blame] | 2067 | .long 0 /* 0x140 */ |
| 2068 | .long 0 /* 0x144 */ |
| 2069 | .long 0 /* 0x148 */ |
| 2070 | .long 0 /* 0x14c */ |
| 2071 | .long 0 /* 0x150 */ |
| 2072 | .long 0 /* 0x154 */ |
| 2073 | .long 0 /* 0x158 */ |
| 2074 | .long 0 /* 0x15c */ |
| 2075 | .long 0 /* 0x160 */ |
| 2076 | .long 0 /* 0x164 */ |
| 2077 | .long 0 /* 0x168 */ |
| 2078 | .long 0 /* 0x16c */ |
| 2079 | .long 0 /* 0x170 */ |
| 2080 | .long 0 /* 0x174 */ |
| 2081 | .long 0 /* 0x178 */ |
| 2082 | .long 0 /* 0x17c */ |
| 2083 | .long 0 /* 0x180 */ |
| 2084 | .long 0 /* 0x184 */ |
| 2085 | .long 0 /* 0x188 */ |
| 2086 | .long 0 /* 0x18c */ |
| 2087 | .long 0 /* 0x190 */ |
| 2088 | .long 0 /* 0x194 */ |
| 2089 | .long 0 /* 0x198 */ |
| 2090 | .long 0 /* 0x19c */ |
| 2091 | .long 0 /* 0x1a0 */ |
| 2092 | .long 0 /* 0x1a4 */ |
| 2093 | .long 0 /* 0x1a8 */ |
| 2094 | .long 0 /* 0x1ac */ |
| 2095 | .long 0 /* 0x1b0 */ |
| 2096 | .long 0 /* 0x1b4 */ |
| 2097 | .long 0 /* 0x1b8 */ |
| 2098 | .long 0 /* 0x1bc */ |
| 2099 | .long 0 /* 0x1c0 */ |
| 2100 | .long 0 /* 0x1c4 */ |
| 2101 | .long 0 /* 0x1c8 */ |
| 2102 | .long 0 /* 0x1cc */ |
| 2103 | .long 0 /* 0x1d0 */ |
| 2104 | .long 0 /* 0x1d4 */ |
| 2105 | .long 0 /* 0x1d8 */ |
| 2106 | .long 0 /* 0x1dc */ |
| 2107 | .long 0 /* 0x1e0 */ |
| 2108 | .long 0 /* 0x1e4 */ |
| 2109 | .long 0 /* 0x1e8 */ |
| 2110 | .long 0 /* 0x1ec */ |
| 2111 | .long 0 /* 0x1f0 */ |
| 2112 | .long 0 /* 0x1f4 */ |
| 2113 | .long 0 /* 0x1f8 */ |
| 2114 | .long 0 /* 0x1fc */ |
| 2115 | .long 0 /* 0x200 */ |
| 2116 | .long 0 /* 0x204 */ |
| 2117 | .long 0 /* 0x208 */ |
| 2118 | .long 0 /* 0x20c */ |
| 2119 | .long 0 /* 0x210 */ |
| 2120 | .long 0 /* 0x214 */ |
| 2121 | .long 0 /* 0x218 */ |
| 2122 | .long 0 /* 0x21c */ |
| 2123 | .long 0 /* 0x220 */ |
| 2124 | .long 0 /* 0x224 */ |
| 2125 | .long 0 /* 0x228 */ |
| 2126 | .long 0 /* 0x22c */ |
| 2127 | .long 0 /* 0x230 */ |
| 2128 | .long 0 /* 0x234 */ |
| 2129 | .long 0 /* 0x238 */ |
| 2130 | .long 0 /* 0x23c */ |
| 2131 | .long 0 /* 0x240 */ |
| 2132 | .long 0 /* 0x244 */ |
| 2133 | .long 0 /* 0x248 */ |
| 2134 | .long 0 /* 0x24c */ |
| 2135 | .long 0 /* 0x250 */ |
| 2136 | .long 0 /* 0x254 */ |
| 2137 | .long 0 /* 0x258 */ |
| 2138 | .long 0 /* 0x25c */ |
| 2139 | .long 0 /* 0x260 */ |
| 2140 | .long 0 /* 0x264 */ |
| 2141 | .long 0 /* 0x268 */ |
| 2142 | .long 0 /* 0x26c */ |
| 2143 | .long 0 /* 0x270 */ |
| 2144 | .long 0 /* 0x274 */ |
| 2145 | .long 0 /* 0x278 */ |
| 2146 | .long 0 /* 0x27c */ |
| 2147 | .long 0 /* 0x280 */ |
| 2148 | .long 0 /* 0x284 */ |
| 2149 | .long 0 /* 0x288 */ |
| 2150 | .long 0 /* 0x28c */ |
| 2151 | .long 0 /* 0x290 */ |
| 2152 | .long 0 /* 0x294 */ |
| 2153 | .long 0 /* 0x298 */ |
| 2154 | .long 0 /* 0x29c */ |
| 2155 | .long 0 /* 0x2a0 */ |
| 2156 | .long 0 /* 0x2a4 */ |
| 2157 | .long 0 /* 0x2a8 */ |
| 2158 | .long 0 /* 0x2ac */ |
| 2159 | .long 0 /* 0x2b0 */ |
| 2160 | .long 0 /* 0x2b4 */ |
| 2161 | .long 0 /* 0x2b8 */ |
| 2162 | .long 0 /* 0x2bc */ |
| 2163 | .long 0 /* 0x2c0 */ |
| 2164 | .long 0 /* 0x2c4 */ |
| 2165 | .long 0 /* 0x2c8 */ |
| 2166 | .long 0 /* 0x2cc */ |
| 2167 | .long 0 /* 0x2d0 */ |
| 2168 | .long 0 /* 0x2d4 */ |
| 2169 | .long 0 /* 0x2d8 */ |
| 2170 | .long 0 /* 0x2dc */ |
| 2171 | .long 0 /* 0x2e0 */ |
| 2172 | .long 0 /* 0x2e4 */ |
| 2173 | .long 0 /* 0x2e8 */ |
| 2174 | .long 0 /* 0x2ec */ |
| 2175 | .long 0 /* 0x2f0 */ |
| 2176 | .long 0 /* 0x2f4 */ |
| 2177 | .long 0 /* 0x2f8 */ |
| 2178 | .long 0 /* 0x2fc */ |
| 2179 | .long DOTSYM(kvmppc_h_random) - hcall_real_table |
Paul Mackerras | ae2113a | 2014-06-02 11:03:00 +1000 | [diff] [blame] | 2180 | .globl hcall_real_table_end |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2181 | hcall_real_table_end: |
| 2182 | |
Paul Mackerras | 8563bf5 | 2014-01-08 21:25:29 +1100 | [diff] [blame] | 2183 | _GLOBAL(kvmppc_h_set_xdabr) |
| 2184 | andi. r0, r5, DABRX_USER | DABRX_KERNEL |
| 2185 | beq 6f |
| 2186 | li r0, DABRX_USER | DABRX_KERNEL | DABRX_BTI |
| 2187 | andc. r0, r5, r0 |
| 2188 | beq 3f |
| 2189 | 6: li r3, H_PARAMETER |
| 2190 | blr |
| 2191 | |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2192 | _GLOBAL(kvmppc_h_set_dabr) |
Paul Mackerras | 8563bf5 | 2014-01-08 21:25:29 +1100 | [diff] [blame] | 2193 | li r5, DABRX_USER | DABRX_KERNEL |
| 2194 | 3: |
Michael Neuling | eee7ff9 | 2014-01-08 21:25:19 +1100 | [diff] [blame] | 2195 | BEGIN_FTR_SECTION |
| 2196 | b 2f |
| 2197 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2198 | std r4,VCPU_DABR(r3) |
Paul Mackerras | 8563bf5 | 2014-01-08 21:25:29 +1100 | [diff] [blame] | 2199 | stw r5, VCPU_DABRX(r3) |
| 2200 | mtspr SPRN_DABRX, r5 |
Paul Mackerras | 8943633 | 2012-03-02 01:38:23 +0000 | [diff] [blame] | 2201 | /* Work around P7 bug where DABR can get corrupted on mtspr */ |
| 2202 | 1: mtspr SPRN_DABR,r4 |
| 2203 | mfspr r5, SPRN_DABR |
| 2204 | cmpd r4, r5 |
| 2205 | bne 1b |
| 2206 | isync |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2207 | li r3,0 |
| 2208 | blr |
| 2209 | |
Paul Mackerras | 8563bf5 | 2014-01-08 21:25:29 +1100 | [diff] [blame] | 2210 | /* Emulate H_SET_DABR/X on P8 for the sake of compat mode guests */ |
| 2211 | 2: rlwimi r5, r4, 5, DAWRX_DR | DAWRX_DW |
Thomas Huth | 760a736 | 2015-11-20 09:11:45 +0100 | [diff] [blame] | 2212 | rlwimi r5, r4, 2, DAWRX_WT |
Paul Mackerras | 8563bf5 | 2014-01-08 21:25:29 +1100 | [diff] [blame] | 2213 | clrrdi r4, r4, 3 |
| 2214 | std r4, VCPU_DAWR(r3) |
| 2215 | std r5, VCPU_DAWRX(r3) |
| 2216 | mtspr SPRN_DAWR, r4 |
| 2217 | mtspr SPRN_DAWRX, r5 |
| 2218 | li r3, 0 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2219 | blr |
| 2220 | |
Paul Mackerras | 1f09c3e | 2015-03-28 14:21:04 +1100 | [diff] [blame] | 2221 | _GLOBAL(kvmppc_h_cede) /* r3 = vcpu pointer, r11 = msr, r13 = paca */ |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2222 | ori r11,r11,MSR_EE |
| 2223 | std r11,VCPU_MSR(r3) |
| 2224 | li r0,1 |
| 2225 | stb r0,VCPU_CEDED(r3) |
| 2226 | sync /* order setting ceded vs. testing prodded */ |
| 2227 | lbz r5,VCPU_PRODDED(r3) |
| 2228 | cmpwi r5,0 |
Paul Mackerras | 04f995a | 2012-08-06 00:03:28 +0000 | [diff] [blame] | 2229 | bne kvm_cede_prodded |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 2230 | li r12,0 /* set trap to 0 to say hcall is handled */ |
| 2231 | stw r12,VCPU_TRAP(r3) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2232 | li r0,H_SUCCESS |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 2233 | std r0,VCPU_GPR(R3)(r3) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2234 | |
| 2235 | /* |
| 2236 | * Set our bit in the bitmask of napping threads unless all the |
| 2237 | * other threads are already napping, in which case we send this |
| 2238 | * up to the host. |
| 2239 | */ |
| 2240 | ld r5,HSTATE_KVM_VCORE(r13) |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 2241 | lbz r6,HSTATE_PTID(r13) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2242 | lwz r8,VCORE_ENTRY_EXIT(r5) |
| 2243 | clrldi r8,r8,56 |
| 2244 | li r0,1 |
| 2245 | sld r0,r0,r6 |
| 2246 | addi r6,r5,VCORE_NAPPING_THREADS |
| 2247 | 31: lwarx r4,0,r6 |
| 2248 | or r4,r4,r0 |
Paul Mackerras | 7d6c40d | 2015-03-28 14:21:09 +1100 | [diff] [blame] | 2249 | cmpw r4,r8 |
| 2250 | beq kvm_cede_exit |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2251 | stwcx. r4,0,r6 |
| 2252 | bne 31b |
Paul Mackerras | 7d6c40d | 2015-03-28 14:21:09 +1100 | [diff] [blame] | 2253 | /* order napping_threads update vs testing entry_exit_map */ |
Paul Mackerras | f019b7a | 2013-11-16 17:46:03 +1100 | [diff] [blame] | 2254 | isync |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 2255 | li r0,NAPPING_CEDE |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2256 | stb r0,HSTATE_NAPPING(r13) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2257 | lwz r7,VCORE_ENTRY_EXIT(r5) |
| 2258 | cmpwi r7,0x100 |
| 2259 | bge 33f /* another thread already exiting */ |
| 2260 | |
| 2261 | /* |
| 2262 | * Although not specifically required by the architecture, POWER7 |
| 2263 | * preserves the following registers in nap mode, even if an SMT mode |
| 2264 | * switch occurs: SLB entries, PURR, SPURR, AMOR, UAMOR, AMR, SPRG0-3, |
| 2265 | * DAR, DSISR, DABR, DABRX, DSCR, PMCx, MMCRx, SIAR, SDAR. |
| 2266 | */ |
| 2267 | /* Save non-volatile GPRs */ |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 2268 | std r14, VCPU_GPR(R14)(r3) |
| 2269 | std r15, VCPU_GPR(R15)(r3) |
| 2270 | std r16, VCPU_GPR(R16)(r3) |
| 2271 | std r17, VCPU_GPR(R17)(r3) |
| 2272 | std r18, VCPU_GPR(R18)(r3) |
| 2273 | std r19, VCPU_GPR(R19)(r3) |
| 2274 | std r20, VCPU_GPR(R20)(r3) |
| 2275 | std r21, VCPU_GPR(R21)(r3) |
| 2276 | std r22, VCPU_GPR(R22)(r3) |
| 2277 | std r23, VCPU_GPR(R23)(r3) |
| 2278 | std r24, VCPU_GPR(R24)(r3) |
| 2279 | std r25, VCPU_GPR(R25)(r3) |
| 2280 | std r26, VCPU_GPR(R26)(r3) |
| 2281 | std r27, VCPU_GPR(R27)(r3) |
| 2282 | std r28, VCPU_GPR(R28)(r3) |
| 2283 | std r29, VCPU_GPR(R29)(r3) |
| 2284 | std r30, VCPU_GPR(R30)(r3) |
| 2285 | std r31, VCPU_GPR(R31)(r3) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2286 | |
| 2287 | /* save FP state */ |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2288 | bl kvmppc_save_fp |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2289 | |
Paul Mackerras | 93d1739 | 2016-06-22 15:52:55 +1000 | [diff] [blame] | 2290 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
| 2291 | BEGIN_FTR_SECTION |
| 2292 | ld r9, HSTATE_KVM_VCPU(r13) |
| 2293 | bl kvmppc_save_tm |
| 2294 | END_FTR_SECTION_IFSET(CPU_FTR_TM) |
| 2295 | #endif |
| 2296 | |
Paul Mackerras | fd6d53b | 2015-03-28 14:21:08 +1100 | [diff] [blame] | 2297 | /* |
| 2298 | * Set DEC to the smaller of DEC and HDEC, so that we wake |
| 2299 | * no later than the end of our timeslice (HDEC interrupts |
| 2300 | * don't wake us from nap). |
| 2301 | */ |
| 2302 | mfspr r3, SPRN_DEC |
| 2303 | mfspr r4, SPRN_HDEC |
| 2304 | mftb r5 |
| 2305 | cmpw r3, r4 |
| 2306 | ble 67f |
| 2307 | mtspr SPRN_DEC, r4 |
| 2308 | 67: |
| 2309 | /* save expiry time of guest decrementer */ |
| 2310 | extsw r3, r3 |
| 2311 | add r3, r3, r5 |
| 2312 | ld r4, HSTATE_KVM_VCPU(r13) |
| 2313 | ld r5, HSTATE_KVM_VCORE(r13) |
| 2314 | ld r6, VCORE_TB_OFFSET(r5) |
| 2315 | subf r3, r6, r3 /* convert to host TB value */ |
| 2316 | std r3, VCPU_DEC_EXPIRES(r4) |
| 2317 | |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 2318 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
| 2319 | ld r4, HSTATE_KVM_VCPU(r13) |
| 2320 | addi r3, r4, VCPU_TB_CEDE |
| 2321 | bl kvmhv_accumulate_time |
| 2322 | #endif |
| 2323 | |
Paul Mackerras | ccc0777 | 2015-03-28 14:21:07 +1100 | [diff] [blame] | 2324 | lis r3, LPCR_PECEDP@h /* Do wake on privileged doorbell */ |
| 2325 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2326 | /* |
Paul Mackerras | aa31e84 | 2014-01-08 21:25:26 +1100 | [diff] [blame] | 2327 | * Take a nap until a decrementer or external or doobell interrupt |
Paul Mackerras | ccc0777 | 2015-03-28 14:21:07 +1100 | [diff] [blame] | 2328 | * occurs, with PECE1 and PECE0 set in LPCR. |
Paul Mackerras | 66feed6 | 2015-03-28 14:21:12 +1100 | [diff] [blame] | 2329 | * On POWER8, set PECEDH, and if we are ceding, also set PECEDP. |
Paul Mackerras | ccc0777 | 2015-03-28 14:21:07 +1100 | [diff] [blame] | 2330 | * Also clear the runlatch bit before napping. |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2331 | */ |
Paul Mackerras | 56548fc | 2014-12-03 14:48:40 +1100 | [diff] [blame] | 2332 | kvm_do_nap: |
Paul Mackerras | 1f09c3e | 2015-03-28 14:21:04 +1100 | [diff] [blame] | 2333 | mfspr r0, SPRN_CTRLF |
| 2334 | clrrdi r0, r0, 1 |
| 2335 | mtspr SPRN_CTRLT, r0 |
Preeti U Murthy | 582b910 | 2014-04-11 16:02:08 +0530 | [diff] [blame] | 2336 | |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame] | 2337 | li r0,1 |
| 2338 | stb r0,HSTATE_HWTHREAD_REQ(r13) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2339 | mfspr r5,SPRN_LPCR |
| 2340 | ori r5,r5,LPCR_PECE0 | LPCR_PECE1 |
Paul Mackerras | aa31e84 | 2014-01-08 21:25:26 +1100 | [diff] [blame] | 2341 | BEGIN_FTR_SECTION |
Paul Mackerras | 66feed6 | 2015-03-28 14:21:12 +1100 | [diff] [blame] | 2342 | ori r5, r5, LPCR_PECEDH |
Paul Mackerras | ccc0777 | 2015-03-28 14:21:07 +1100 | [diff] [blame] | 2343 | rlwimi r5, r3, 0, LPCR_PECEDP |
Paul Mackerras | aa31e84 | 2014-01-08 21:25:26 +1100 | [diff] [blame] | 2344 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
Paul Mackerras | bf53c88 | 2016-11-18 14:34:07 +1100 | [diff] [blame] | 2345 | |
| 2346 | kvm_nap_sequence: /* desired LPCR value in r5 */ |
| 2347 | BEGIN_FTR_SECTION |
| 2348 | /* |
| 2349 | * PSSCR bits: exit criterion = 1 (wakeup based on LPCR at sreset) |
| 2350 | * enable state loss = 1 (allow SMT mode switch) |
| 2351 | * requested level = 0 (just stop dispatching) |
| 2352 | */ |
| 2353 | lis r3, (PSSCR_EC | PSSCR_ESL)@h |
| 2354 | mtspr SPRN_PSSCR, r3 |
| 2355 | /* Set LPCR_PECE_HVEE bit to enable wakeup by HV interrupts */ |
| 2356 | li r4, LPCR_PECE_HVEE@higher |
| 2357 | sldi r4, r4, 32 |
| 2358 | or r5, r5, r4 |
| 2359 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2360 | mtspr SPRN_LPCR,r5 |
| 2361 | isync |
| 2362 | li r0, 0 |
| 2363 | std r0, HSTATE_SCRATCH0(r13) |
| 2364 | ptesync |
| 2365 | ld r0, HSTATE_SCRATCH0(r13) |
| 2366 | 1: cmpd r0, r0 |
| 2367 | bne 1b |
Paul Mackerras | bf53c88 | 2016-11-18 14:34:07 +1100 | [diff] [blame] | 2368 | BEGIN_FTR_SECTION |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2369 | nap |
Paul Mackerras | bf53c88 | 2016-11-18 14:34:07 +1100 | [diff] [blame] | 2370 | FTR_SECTION_ELSE |
| 2371 | PPC_STOP |
| 2372 | ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_300) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2373 | b . |
| 2374 | |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2375 | 33: mr r4, r3 |
| 2376 | li r3, 0 |
| 2377 | li r12, 0 |
| 2378 | b 34f |
| 2379 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2380 | kvm_end_cede: |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 2381 | /* get vcpu pointer */ |
| 2382 | ld r4, HSTATE_KVM_VCPU(r13) |
| 2383 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2384 | /* Woken by external or decrementer interrupt */ |
| 2385 | ld r1, HSTATE_HOST_R1(r13) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2386 | |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 2387 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
| 2388 | addi r3, r4, VCPU_TB_RMINTR |
| 2389 | bl kvmhv_accumulate_time |
| 2390 | #endif |
| 2391 | |
Paul Mackerras | 93d1739 | 2016-06-22 15:52:55 +1000 | [diff] [blame] | 2392 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
| 2393 | BEGIN_FTR_SECTION |
| 2394 | bl kvmppc_restore_tm |
| 2395 | END_FTR_SECTION_IFSET(CPU_FTR_TM) |
| 2396 | #endif |
| 2397 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2398 | /* load up FP state */ |
| 2399 | bl kvmppc_load_fp |
| 2400 | |
Paul Mackerras | fd6d53b | 2015-03-28 14:21:08 +1100 | [diff] [blame] | 2401 | /* Restore guest decrementer */ |
| 2402 | ld r3, VCPU_DEC_EXPIRES(r4) |
| 2403 | ld r5, HSTATE_KVM_VCORE(r13) |
| 2404 | ld r6, VCORE_TB_OFFSET(r5) |
| 2405 | add r3, r3, r6 /* convert host TB to guest TB value */ |
| 2406 | mftb r7 |
| 2407 | subf r3, r7, r3 |
| 2408 | mtspr SPRN_DEC, r3 |
| 2409 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2410 | /* Load NV GPRS */ |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 2411 | ld r14, VCPU_GPR(R14)(r4) |
| 2412 | ld r15, VCPU_GPR(R15)(r4) |
| 2413 | ld r16, VCPU_GPR(R16)(r4) |
| 2414 | ld r17, VCPU_GPR(R17)(r4) |
| 2415 | ld r18, VCPU_GPR(R18)(r4) |
| 2416 | ld r19, VCPU_GPR(R19)(r4) |
| 2417 | ld r20, VCPU_GPR(R20)(r4) |
| 2418 | ld r21, VCPU_GPR(R21)(r4) |
| 2419 | ld r22, VCPU_GPR(R22)(r4) |
| 2420 | ld r23, VCPU_GPR(R23)(r4) |
| 2421 | ld r24, VCPU_GPR(R24)(r4) |
| 2422 | ld r25, VCPU_GPR(R25)(r4) |
| 2423 | ld r26, VCPU_GPR(R26)(r4) |
| 2424 | ld r27, VCPU_GPR(R27)(r4) |
| 2425 | ld r28, VCPU_GPR(R28)(r4) |
| 2426 | ld r29, VCPU_GPR(R29)(r4) |
| 2427 | ld r30, VCPU_GPR(R30)(r4) |
| 2428 | ld r31, VCPU_GPR(R31)(r4) |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 2429 | |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2430 | /* Check the wake reason in SRR1 to see why we got here */ |
| 2431 | bl kvmppc_check_wake_reason |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2432 | |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 2433 | /* |
| 2434 | * Restore volatile registers since we could have called a |
| 2435 | * C routine in kvmppc_check_wake_reason |
| 2436 | * r4 = VCPU |
| 2437 | * r3 tells us whether we need to return to host or not |
| 2438 | * WARNING: it gets checked further down: |
| 2439 | * should not modify r3 until this check is done. |
| 2440 | */ |
| 2441 | ld r4, HSTATE_KVM_VCPU(r13) |
| 2442 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2443 | /* clear our bit in vcore->napping_threads */ |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2444 | 34: ld r5,HSTATE_KVM_VCORE(r13) |
| 2445 | lbz r7,HSTATE_PTID(r13) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2446 | li r0,1 |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2447 | sld r0,r0,r7 |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2448 | addi r6,r5,VCORE_NAPPING_THREADS |
| 2449 | 32: lwarx r7,0,r6 |
| 2450 | andc r7,r7,r0 |
| 2451 | stwcx. r7,0,r6 |
| 2452 | bne 32b |
| 2453 | li r0,0 |
| 2454 | stb r0,HSTATE_NAPPING(r13) |
| 2455 | |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 2456 | /* See if the wake reason saved in r3 means we need to exit */ |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2457 | stw r12, VCPU_TRAP(r4) |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 2458 | mr r9, r4 |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2459 | cmpdi r3, 0 |
| 2460 | bgt guest_exit_cont |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 2461 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2462 | /* see if any other thread is already exiting */ |
| 2463 | lwz r0,VCORE_ENTRY_EXIT(r5) |
| 2464 | cmpwi r0,0x100 |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2465 | bge guest_exit_cont |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2466 | |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2467 | b kvmppc_cede_reentry /* if not go back to guest */ |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2468 | |
| 2469 | /* cede when already previously prodded case */ |
Paul Mackerras | 04f995a | 2012-08-06 00:03:28 +0000 | [diff] [blame] | 2470 | kvm_cede_prodded: |
| 2471 | li r0,0 |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2472 | stb r0,VCPU_PRODDED(r3) |
| 2473 | sync /* order testing prodded vs. clearing ceded */ |
| 2474 | stb r0,VCPU_CEDED(r3) |
| 2475 | li r3,H_SUCCESS |
| 2476 | blr |
| 2477 | |
| 2478 | /* we've ceded but we want to give control to the host */ |
Paul Mackerras | 04f995a | 2012-08-06 00:03:28 +0000 | [diff] [blame] | 2479 | kvm_cede_exit: |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 2480 | ld r9, HSTATE_KVM_VCPU(r13) |
| 2481 | b guest_exit_cont |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2482 | |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 2483 | /* Try to handle a machine check in real mode */ |
| 2484 | machine_check_realmode: |
| 2485 | mr r3, r9 /* get vcpu pointer */ |
Anton Blanchard | b1576fe | 2014-02-04 16:04:35 +1100 | [diff] [blame] | 2486 | bl kvmppc_realmode_machine_check |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 2487 | nop |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 2488 | ld r9, HSTATE_KVM_VCPU(r13) |
| 2489 | li r12, BOOK3S_INTERRUPT_MACHINE_CHECK |
Mahesh Salgaonkar | 74845bc | 2014-06-11 14:18:21 +0530 | [diff] [blame] | 2490 | /* |
| 2491 | * Deliver unhandled/fatal (e.g. UE) MCE errors to guest through |
| 2492 | * machine check interrupt (set HSRR0 to 0x200). And for handled |
| 2493 | * errors (no-fatal), just go back to guest execution with current |
| 2494 | * HSRR0 instead of exiting guest. This new approach will inject |
| 2495 | * machine check to guest for fatal error causing guest to crash. |
| 2496 | * |
| 2497 | * The old code used to return to host for unhandled errors which |
| 2498 | * was causing guest to hang with soft lockups inside guest and |
| 2499 | * makes it difficult to recover guest instance. |
Mahesh Salgaonkar | 966d713 | 2015-03-23 22:24:45 +0530 | [diff] [blame] | 2500 | * |
| 2501 | * if we receive machine check with MSR(RI=0) then deliver it to |
| 2502 | * guest as machine check causing guest to crash. |
Mahesh Salgaonkar | 74845bc | 2014-06-11 14:18:21 +0530 | [diff] [blame] | 2503 | */ |
Mahesh Salgaonkar | 74845bc | 2014-06-11 14:18:21 +0530 | [diff] [blame] | 2504 | ld r11, VCPU_MSR(r9) |
Paul Mackerras | 1c9e3d5 | 2015-11-12 16:43:48 +1100 | [diff] [blame] | 2505 | rldicl. r0, r11, 64-MSR_HV_LG, 63 /* check if it happened in HV mode */ |
| 2506 | bne mc_cont /* if so, exit to host */ |
Mahesh Salgaonkar | 966d713 | 2015-03-23 22:24:45 +0530 | [diff] [blame] | 2507 | andi. r10, r11, MSR_RI /* check for unrecoverable exception */ |
| 2508 | beq 1f /* Deliver a machine check to guest */ |
| 2509 | ld r10, VCPU_PC(r9) |
| 2510 | cmpdi r3, 0 /* Did we handle MCE ? */ |
Mahesh Salgaonkar | 74845bc | 2014-06-11 14:18:21 +0530 | [diff] [blame] | 2511 | bne 2f /* Continue guest execution. */ |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 2512 | /* If not, deliver a machine check. SRR0/1 are already set */ |
Mahesh Salgaonkar | 966d713 | 2015-03-23 22:24:45 +0530 | [diff] [blame] | 2513 | 1: li r10, BOOK3S_INTERRUPT_MACHINE_CHECK |
Michael Neuling | e4e3812 | 2014-03-25 10:47:02 +1100 | [diff] [blame] | 2514 | bl kvmppc_msr_interrupt |
Mahesh Salgaonkar | 74845bc | 2014-06-11 14:18:21 +0530 | [diff] [blame] | 2515 | 2: b fast_interrupt_c_return |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 2516 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2517 | /* |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2518 | * Check the reason we woke from nap, and take appropriate action. |
Paul Mackerras | 1f09c3e | 2015-03-28 14:21:04 +1100 | [diff] [blame] | 2519 | * Returns (in r3): |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2520 | * 0 if nothing needs to be done |
| 2521 | * 1 if something happened that needs to be handled by the host |
Paul Mackerras | 66feed6 | 2015-03-28 14:21:12 +1100 | [diff] [blame] | 2522 | * -1 if there was a guest wakeup (IPI or msgsnd) |
Suresh Warrier | e3c13e5 | 2016-08-19 15:35:51 +1000 | [diff] [blame] | 2523 | * -2 if we handled a PCI passthrough interrupt (returned by |
| 2524 | * kvmppc_read_intr only) |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2525 | * |
| 2526 | * Also sets r12 to the interrupt vector for any interrupt that needs |
| 2527 | * to be handled now by the host (0x500 for external interrupt), or zero. |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 2528 | * Modifies all volatile registers (since it may call a C function). |
| 2529 | * This routine calls kvmppc_read_intr, a C function, if an external |
| 2530 | * interrupt is pending. |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2531 | */ |
| 2532 | kvmppc_check_wake_reason: |
| 2533 | mfspr r6, SPRN_SRR1 |
Paul Mackerras | aa31e84 | 2014-01-08 21:25:26 +1100 | [diff] [blame] | 2534 | BEGIN_FTR_SECTION |
| 2535 | rlwinm r6, r6, 45-31, 0xf /* extract wake reason field (P8) */ |
| 2536 | FTR_SECTION_ELSE |
| 2537 | rlwinm r6, r6, 45-31, 0xe /* P7 wake reason field is 3 bits */ |
| 2538 | ALT_FTR_SECTION_END_IFSET(CPU_FTR_ARCH_207S) |
| 2539 | cmpwi r6, 8 /* was it an external interrupt? */ |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 2540 | beq 7f /* if so, see what it was */ |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2541 | li r3, 0 |
| 2542 | li r12, 0 |
| 2543 | cmpwi r6, 6 /* was it the decrementer? */ |
| 2544 | beq 0f |
Paul Mackerras | aa31e84 | 2014-01-08 21:25:26 +1100 | [diff] [blame] | 2545 | BEGIN_FTR_SECTION |
| 2546 | cmpwi r6, 5 /* privileged doorbell? */ |
| 2547 | beq 0f |
Paul Mackerras | 5d00f66 | 2014-01-08 21:25:28 +1100 | [diff] [blame] | 2548 | cmpwi r6, 3 /* hypervisor doorbell? */ |
| 2549 | beq 3f |
Paul Mackerras | aa31e84 | 2014-01-08 21:25:26 +1100 | [diff] [blame] | 2550 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
Mahesh Salgaonkar | fd7bacb | 2016-05-15 09:44:26 +0530 | [diff] [blame] | 2551 | cmpwi r6, 0xa /* Hypervisor maintenance ? */ |
| 2552 | beq 4f |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2553 | li r3, 1 /* anything else, return 1 */ |
| 2554 | 0: blr |
| 2555 | |
Paul Mackerras | 5d00f66 | 2014-01-08 21:25:28 +1100 | [diff] [blame] | 2556 | /* hypervisor doorbell */ |
| 2557 | 3: li r12, BOOK3S_INTERRUPT_H_DOORBELL |
Gautham R. Shenoy | 70aa396 | 2015-10-15 11:29:58 +0530 | [diff] [blame] | 2558 | |
| 2559 | /* |
| 2560 | * Clear the doorbell as we will invoke the handler |
| 2561 | * explicitly in the guest exit path. |
| 2562 | */ |
| 2563 | lis r6, (PPC_DBELL_SERVER << (63-36))@h |
| 2564 | PPC_MSGCLR(6) |
Paul Mackerras | 66feed6 | 2015-03-28 14:21:12 +1100 | [diff] [blame] | 2565 | /* see if it's a host IPI */ |
Paul Mackerras | 5d00f66 | 2014-01-08 21:25:28 +1100 | [diff] [blame] | 2566 | li r3, 1 |
Paul Mackerras | 66feed6 | 2015-03-28 14:21:12 +1100 | [diff] [blame] | 2567 | lbz r0, HSTATE_HOST_IPI(r13) |
| 2568 | cmpwi r0, 0 |
| 2569 | bnelr |
Gautham R. Shenoy | 70aa396 | 2015-10-15 11:29:58 +0530 | [diff] [blame] | 2570 | /* if not, return -1 */ |
Paul Mackerras | 66feed6 | 2015-03-28 14:21:12 +1100 | [diff] [blame] | 2571 | li r3, -1 |
Paul Mackerras | 5d00f66 | 2014-01-08 21:25:28 +1100 | [diff] [blame] | 2572 | blr |
| 2573 | |
Mahesh Salgaonkar | fd7bacb | 2016-05-15 09:44:26 +0530 | [diff] [blame] | 2574 | /* Woken up due to Hypervisor maintenance interrupt */ |
| 2575 | 4: li r12, BOOK3S_INTERRUPT_HMI |
| 2576 | li r3, 1 |
| 2577 | blr |
| 2578 | |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 2579 | /* external interrupt - create a stack frame so we can call C */ |
| 2580 | 7: mflr r0 |
| 2581 | std r0, PPC_LR_STKOFF(r1) |
| 2582 | stdu r1, -PPC_MIN_STKFRM(r1) |
| 2583 | bl kvmppc_read_intr |
| 2584 | nop |
| 2585 | li r12, BOOK3S_INTERRUPT_EXTERNAL |
Suresh Warrier | f7af520 | 2016-08-19 15:35:52 +1000 | [diff] [blame] | 2586 | cmpdi r3, 1 |
| 2587 | ble 1f |
| 2588 | |
| 2589 | /* |
| 2590 | * Return code of 2 means PCI passthrough interrupt, but |
| 2591 | * we need to return back to host to complete handling the |
| 2592 | * interrupt. Trap reason is expected in r12 by guest |
| 2593 | * exit code. |
| 2594 | */ |
| 2595 | li r12, BOOK3S_INTERRUPT_HV_RM_HARD |
| 2596 | 1: |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 2597 | ld r0, PPC_MIN_STKFRM+PPC_LR_STKOFF(r1) |
| 2598 | addi r1, r1, PPC_MIN_STKFRM |
| 2599 | mtlr r0 |
| 2600 | blr |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2601 | |
| 2602 | /* |
| 2603 | * Save away FP, VMX and VSX registers. |
| 2604 | * r3 = vcpu pointer |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2605 | * N.B. r30 and r31 are volatile across this function, |
| 2606 | * thus it is not callable from C. |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2607 | */ |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2608 | kvmppc_save_fp: |
| 2609 | mflr r30 |
| 2610 | mr r31,r3 |
Paul Mackerras | 8943633 | 2012-03-02 01:38:23 +0000 | [diff] [blame] | 2611 | mfmsr r5 |
| 2612 | ori r8,r5,MSR_FP |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2613 | #ifdef CONFIG_ALTIVEC |
| 2614 | BEGIN_FTR_SECTION |
| 2615 | oris r8,r8,MSR_VEC@h |
| 2616 | END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) |
| 2617 | #endif |
| 2618 | #ifdef CONFIG_VSX |
| 2619 | BEGIN_FTR_SECTION |
| 2620 | oris r8,r8,MSR_VSX@h |
| 2621 | END_FTR_SECTION_IFSET(CPU_FTR_VSX) |
| 2622 | #endif |
| 2623 | mtmsrd r8 |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2624 | addi r3,r3,VCPU_FPRS |
Alexander Graf | 9bf163f | 2014-06-16 14:41:15 +0200 | [diff] [blame] | 2625 | bl store_fp_state |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2626 | #ifdef CONFIG_ALTIVEC |
| 2627 | BEGIN_FTR_SECTION |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2628 | addi r3,r31,VCPU_VRS |
Alexander Graf | 9bf163f | 2014-06-16 14:41:15 +0200 | [diff] [blame] | 2629 | bl store_vr_state |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2630 | END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) |
| 2631 | #endif |
| 2632 | mfspr r6,SPRN_VRSAVE |
Paul Mackerras | e724f08 | 2014-03-13 20:02:48 +1100 | [diff] [blame] | 2633 | stw r6,VCPU_VRSAVE(r31) |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2634 | mtlr r30 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2635 | blr |
| 2636 | |
| 2637 | /* |
| 2638 | * Load up FP, VMX and VSX registers |
| 2639 | * r4 = vcpu pointer |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2640 | * N.B. r30 and r31 are volatile across this function, |
| 2641 | * thus it is not callable from C. |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2642 | */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2643 | kvmppc_load_fp: |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2644 | mflr r30 |
| 2645 | mr r31,r4 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2646 | mfmsr r9 |
| 2647 | ori r8,r9,MSR_FP |
| 2648 | #ifdef CONFIG_ALTIVEC |
| 2649 | BEGIN_FTR_SECTION |
| 2650 | oris r8,r8,MSR_VEC@h |
| 2651 | END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) |
| 2652 | #endif |
| 2653 | #ifdef CONFIG_VSX |
| 2654 | BEGIN_FTR_SECTION |
| 2655 | oris r8,r8,MSR_VSX@h |
| 2656 | END_FTR_SECTION_IFSET(CPU_FTR_VSX) |
| 2657 | #endif |
| 2658 | mtmsrd r8 |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2659 | addi r3,r4,VCPU_FPRS |
Alexander Graf | 9bf163f | 2014-06-16 14:41:15 +0200 | [diff] [blame] | 2660 | bl load_fp_state |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2661 | #ifdef CONFIG_ALTIVEC |
| 2662 | BEGIN_FTR_SECTION |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2663 | addi r3,r31,VCPU_VRS |
Alexander Graf | 9bf163f | 2014-06-16 14:41:15 +0200 | [diff] [blame] | 2664 | bl load_vr_state |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2665 | END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) |
| 2666 | #endif |
Paul Mackerras | e724f08 | 2014-03-13 20:02:48 +1100 | [diff] [blame] | 2667 | lwz r7,VCPU_VRSAVE(r31) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2668 | mtspr SPRN_VRSAVE,r7 |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2669 | mtlr r30 |
| 2670 | mr r4,r31 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2671 | blr |
Paul Mackerras | 44a3add | 2013-10-04 21:45:04 +1000 | [diff] [blame] | 2672 | |
Paul Mackerras | f024ee0 | 2016-06-22 14:21:59 +1000 | [diff] [blame] | 2673 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
| 2674 | /* |
| 2675 | * Save transactional state and TM-related registers. |
| 2676 | * Called with r9 pointing to the vcpu struct. |
| 2677 | * This can modify all checkpointed registers, but |
| 2678 | * restores r1, r2 and r9 (vcpu pointer) before exit. |
| 2679 | */ |
| 2680 | kvmppc_save_tm: |
| 2681 | mflr r0 |
| 2682 | std r0, PPC_LR_STKOFF(r1) |
| 2683 | |
| 2684 | /* Turn on TM. */ |
| 2685 | mfmsr r8 |
| 2686 | li r0, 1 |
| 2687 | rldimi r8, r0, MSR_TM_LG, 63-MSR_TM_LG |
| 2688 | mtmsrd r8 |
| 2689 | |
| 2690 | ld r5, VCPU_MSR(r9) |
| 2691 | rldicl. r5, r5, 64 - MSR_TS_S_LG, 62 |
| 2692 | beq 1f /* TM not active in guest. */ |
| 2693 | |
| 2694 | std r1, HSTATE_HOST_R1(r13) |
| 2695 | li r3, TM_CAUSE_KVM_RESCHED |
| 2696 | |
| 2697 | /* Clear the MSR RI since r1, r13 are all going to be foobar. */ |
| 2698 | li r5, 0 |
| 2699 | mtmsrd r5, 1 |
| 2700 | |
| 2701 | /* All GPRs are volatile at this point. */ |
| 2702 | TRECLAIM(R3) |
| 2703 | |
| 2704 | /* Temporarily store r13 and r9 so we have some regs to play with */ |
| 2705 | SET_SCRATCH0(r13) |
| 2706 | GET_PACA(r13) |
| 2707 | std r9, PACATMSCRATCH(r13) |
| 2708 | ld r9, HSTATE_KVM_VCPU(r13) |
| 2709 | |
| 2710 | /* Get a few more GPRs free. */ |
| 2711 | std r29, VCPU_GPRS_TM(29)(r9) |
| 2712 | std r30, VCPU_GPRS_TM(30)(r9) |
| 2713 | std r31, VCPU_GPRS_TM(31)(r9) |
| 2714 | |
| 2715 | /* Save away PPR and DSCR soon so don't run with user values. */ |
| 2716 | mfspr r31, SPRN_PPR |
| 2717 | HMT_MEDIUM |
| 2718 | mfspr r30, SPRN_DSCR |
| 2719 | ld r29, HSTATE_DSCR(r13) |
| 2720 | mtspr SPRN_DSCR, r29 |
| 2721 | |
| 2722 | /* Save all but r9, r13 & r29-r31 */ |
| 2723 | reg = 0 |
| 2724 | .rept 29 |
| 2725 | .if (reg != 9) && (reg != 13) |
| 2726 | std reg, VCPU_GPRS_TM(reg)(r9) |
| 2727 | .endif |
| 2728 | reg = reg + 1 |
| 2729 | .endr |
| 2730 | /* ... now save r13 */ |
| 2731 | GET_SCRATCH0(r4) |
| 2732 | std r4, VCPU_GPRS_TM(13)(r9) |
| 2733 | /* ... and save r9 */ |
| 2734 | ld r4, PACATMSCRATCH(r13) |
| 2735 | std r4, VCPU_GPRS_TM(9)(r9) |
| 2736 | |
| 2737 | /* Reload stack pointer and TOC. */ |
| 2738 | ld r1, HSTATE_HOST_R1(r13) |
| 2739 | ld r2, PACATOC(r13) |
| 2740 | |
| 2741 | /* Set MSR RI now we have r1 and r13 back. */ |
| 2742 | li r5, MSR_RI |
| 2743 | mtmsrd r5, 1 |
| 2744 | |
| 2745 | /* Save away checkpinted SPRs. */ |
| 2746 | std r31, VCPU_PPR_TM(r9) |
| 2747 | std r30, VCPU_DSCR_TM(r9) |
| 2748 | mflr r5 |
| 2749 | mfcr r6 |
| 2750 | mfctr r7 |
| 2751 | mfspr r8, SPRN_AMR |
| 2752 | mfspr r10, SPRN_TAR |
Paul Mackerras | 0d808df | 2016-11-07 15:09:58 +1100 | [diff] [blame] | 2753 | mfxer r11 |
Paul Mackerras | f024ee0 | 2016-06-22 14:21:59 +1000 | [diff] [blame] | 2754 | std r5, VCPU_LR_TM(r9) |
| 2755 | stw r6, VCPU_CR_TM(r9) |
| 2756 | std r7, VCPU_CTR_TM(r9) |
| 2757 | std r8, VCPU_AMR_TM(r9) |
| 2758 | std r10, VCPU_TAR_TM(r9) |
Paul Mackerras | 0d808df | 2016-11-07 15:09:58 +1100 | [diff] [blame] | 2759 | std r11, VCPU_XER_TM(r9) |
Paul Mackerras | f024ee0 | 2016-06-22 14:21:59 +1000 | [diff] [blame] | 2760 | |
| 2761 | /* Restore r12 as trap number. */ |
| 2762 | lwz r12, VCPU_TRAP(r9) |
| 2763 | |
| 2764 | /* Save FP/VSX. */ |
| 2765 | addi r3, r9, VCPU_FPRS_TM |
| 2766 | bl store_fp_state |
| 2767 | addi r3, r9, VCPU_VRS_TM |
| 2768 | bl store_vr_state |
| 2769 | mfspr r6, SPRN_VRSAVE |
| 2770 | stw r6, VCPU_VRSAVE_TM(r9) |
| 2771 | 1: |
| 2772 | /* |
| 2773 | * We need to save these SPRs after the treclaim so that the software |
| 2774 | * error code is recorded correctly in the TEXASR. Also the user may |
| 2775 | * change these outside of a transaction, so they must always be |
| 2776 | * context switched. |
| 2777 | */ |
| 2778 | mfspr r5, SPRN_TFHAR |
| 2779 | mfspr r6, SPRN_TFIAR |
| 2780 | mfspr r7, SPRN_TEXASR |
| 2781 | std r5, VCPU_TFHAR(r9) |
| 2782 | std r6, VCPU_TFIAR(r9) |
| 2783 | std r7, VCPU_TEXASR(r9) |
| 2784 | |
| 2785 | ld r0, PPC_LR_STKOFF(r1) |
| 2786 | mtlr r0 |
| 2787 | blr |
| 2788 | |
| 2789 | /* |
| 2790 | * Restore transactional state and TM-related registers. |
| 2791 | * Called with r4 pointing to the vcpu struct. |
| 2792 | * This potentially modifies all checkpointed registers. |
| 2793 | * It restores r1, r2, r4 from the PACA. |
| 2794 | */ |
| 2795 | kvmppc_restore_tm: |
| 2796 | mflr r0 |
| 2797 | std r0, PPC_LR_STKOFF(r1) |
| 2798 | |
| 2799 | /* Turn on TM/FP/VSX/VMX so we can restore them. */ |
| 2800 | mfmsr r5 |
| 2801 | li r6, MSR_TM >> 32 |
| 2802 | sldi r6, r6, 32 |
| 2803 | or r5, r5, r6 |
| 2804 | ori r5, r5, MSR_FP |
| 2805 | oris r5, r5, (MSR_VEC | MSR_VSX)@h |
| 2806 | mtmsrd r5 |
| 2807 | |
| 2808 | /* |
| 2809 | * The user may change these outside of a transaction, so they must |
| 2810 | * always be context switched. |
| 2811 | */ |
| 2812 | ld r5, VCPU_TFHAR(r4) |
| 2813 | ld r6, VCPU_TFIAR(r4) |
| 2814 | ld r7, VCPU_TEXASR(r4) |
| 2815 | mtspr SPRN_TFHAR, r5 |
| 2816 | mtspr SPRN_TFIAR, r6 |
| 2817 | mtspr SPRN_TEXASR, r7 |
| 2818 | |
| 2819 | ld r5, VCPU_MSR(r4) |
| 2820 | rldicl. r5, r5, 64 - MSR_TS_S_LG, 62 |
| 2821 | beqlr /* TM not active in guest */ |
| 2822 | std r1, HSTATE_HOST_R1(r13) |
| 2823 | |
| 2824 | /* Make sure the failure summary is set, otherwise we'll program check |
| 2825 | * when we trechkpt. It's possible that this might have been not set |
| 2826 | * on a kvmppc_set_one_reg() call but we shouldn't let this crash the |
| 2827 | * host. |
| 2828 | */ |
| 2829 | oris r7, r7, (TEXASR_FS)@h |
| 2830 | mtspr SPRN_TEXASR, r7 |
| 2831 | |
| 2832 | /* |
| 2833 | * We need to load up the checkpointed state for the guest. |
| 2834 | * We need to do this early as it will blow away any GPRs, VSRs and |
| 2835 | * some SPRs. |
| 2836 | */ |
| 2837 | |
| 2838 | mr r31, r4 |
| 2839 | addi r3, r31, VCPU_FPRS_TM |
| 2840 | bl load_fp_state |
| 2841 | addi r3, r31, VCPU_VRS_TM |
| 2842 | bl load_vr_state |
| 2843 | mr r4, r31 |
| 2844 | lwz r7, VCPU_VRSAVE_TM(r4) |
| 2845 | mtspr SPRN_VRSAVE, r7 |
| 2846 | |
| 2847 | ld r5, VCPU_LR_TM(r4) |
| 2848 | lwz r6, VCPU_CR_TM(r4) |
| 2849 | ld r7, VCPU_CTR_TM(r4) |
| 2850 | ld r8, VCPU_AMR_TM(r4) |
| 2851 | ld r9, VCPU_TAR_TM(r4) |
Paul Mackerras | 0d808df | 2016-11-07 15:09:58 +1100 | [diff] [blame] | 2852 | ld r10, VCPU_XER_TM(r4) |
Paul Mackerras | f024ee0 | 2016-06-22 14:21:59 +1000 | [diff] [blame] | 2853 | mtlr r5 |
| 2854 | mtcr r6 |
| 2855 | mtctr r7 |
| 2856 | mtspr SPRN_AMR, r8 |
| 2857 | mtspr SPRN_TAR, r9 |
Paul Mackerras | 0d808df | 2016-11-07 15:09:58 +1100 | [diff] [blame] | 2858 | mtxer r10 |
Paul Mackerras | f024ee0 | 2016-06-22 14:21:59 +1000 | [diff] [blame] | 2859 | |
| 2860 | /* |
| 2861 | * Load up PPR and DSCR values but don't put them in the actual SPRs |
| 2862 | * till the last moment to avoid running with userspace PPR and DSCR for |
| 2863 | * too long. |
| 2864 | */ |
| 2865 | ld r29, VCPU_DSCR_TM(r4) |
| 2866 | ld r30, VCPU_PPR_TM(r4) |
| 2867 | |
| 2868 | std r2, PACATMSCRATCH(r13) /* Save TOC */ |
| 2869 | |
| 2870 | /* Clear the MSR RI since r1, r13 are all going to be foobar. */ |
| 2871 | li r5, 0 |
| 2872 | mtmsrd r5, 1 |
| 2873 | |
| 2874 | /* Load GPRs r0-r28 */ |
| 2875 | reg = 0 |
| 2876 | .rept 29 |
| 2877 | ld reg, VCPU_GPRS_TM(reg)(r31) |
| 2878 | reg = reg + 1 |
| 2879 | .endr |
| 2880 | |
| 2881 | mtspr SPRN_DSCR, r29 |
| 2882 | mtspr SPRN_PPR, r30 |
| 2883 | |
| 2884 | /* Load final GPRs */ |
| 2885 | ld 29, VCPU_GPRS_TM(29)(r31) |
| 2886 | ld 30, VCPU_GPRS_TM(30)(r31) |
| 2887 | ld 31, VCPU_GPRS_TM(31)(r31) |
| 2888 | |
| 2889 | /* TM checkpointed state is now setup. All GPRs are now volatile. */ |
| 2890 | TRECHKPT |
| 2891 | |
| 2892 | /* Now let's get back the state we need. */ |
| 2893 | HMT_MEDIUM |
| 2894 | GET_PACA(r13) |
| 2895 | ld r29, HSTATE_DSCR(r13) |
| 2896 | mtspr SPRN_DSCR, r29 |
| 2897 | ld r4, HSTATE_KVM_VCPU(r13) |
| 2898 | ld r1, HSTATE_HOST_R1(r13) |
| 2899 | ld r2, PACATMSCRATCH(r13) |
| 2900 | |
| 2901 | /* Set the MSR RI since we have our registers back. */ |
| 2902 | li r5, MSR_RI |
| 2903 | mtmsrd r5, 1 |
| 2904 | |
| 2905 | ld r0, PPC_LR_STKOFF(r1) |
| 2906 | mtlr r0 |
| 2907 | blr |
| 2908 | #endif |
| 2909 | |
Paul Mackerras | 44a3add | 2013-10-04 21:45:04 +1000 | [diff] [blame] | 2910 | /* |
| 2911 | * We come here if we get any exception or interrupt while we are |
| 2912 | * executing host real mode code while in guest MMU context. |
| 2913 | * For now just spin, but we should do something better. |
| 2914 | */ |
| 2915 | kvmppc_bad_host_intr: |
| 2916 | b . |
Michael Neuling | e4e3812 | 2014-03-25 10:47:02 +1100 | [diff] [blame] | 2917 | |
| 2918 | /* |
| 2919 | * This mimics the MSR transition on IRQ delivery. The new guest MSR is taken |
| 2920 | * from VCPU_INTR_MSR and is modified based on the required TM state changes. |
| 2921 | * r11 has the guest MSR value (in/out) |
| 2922 | * r9 has a vcpu pointer (in) |
| 2923 | * r0 is used as a scratch register |
| 2924 | */ |
| 2925 | kvmppc_msr_interrupt: |
| 2926 | rldicl r0, r11, 64 - MSR_TS_S_LG, 62 |
| 2927 | cmpwi r0, 2 /* Check if we are in transactional state.. */ |
| 2928 | ld r11, VCPU_INTR_MSR(r9) |
| 2929 | bne 1f |
| 2930 | /* ... if transactional, change to suspended */ |
| 2931 | li r0, 1 |
| 2932 | 1: rldimi r11, r0, MSR_TS_S_LG, 63 - MSR_TS_T_LG |
| 2933 | blr |
Paul Mackerras | 9bc01a9 | 2014-05-26 19:48:40 +1000 | [diff] [blame] | 2934 | |
| 2935 | /* |
| 2936 | * This works around a hardware bug on POWER8E processors, where |
| 2937 | * writing a 1 to the MMCR0[PMAO] bit doesn't generate a |
| 2938 | * performance monitor interrupt. Instead, when we need to have |
| 2939 | * an interrupt pending, we have to arrange for a counter to overflow. |
| 2940 | */ |
| 2941 | kvmppc_fix_pmao: |
| 2942 | li r3, 0 |
| 2943 | mtspr SPRN_MMCR2, r3 |
| 2944 | lis r3, (MMCR0_PMXE | MMCR0_FCECE)@h |
| 2945 | ori r3, r3, MMCR0_PMCjCE | MMCR0_C56RUN |
| 2946 | mtspr SPRN_MMCR0, r3 |
| 2947 | lis r3, 0x7fff |
| 2948 | ori r3, r3, 0xffff |
| 2949 | mtspr SPRN_PMC6, r3 |
| 2950 | isync |
| 2951 | blr |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 2952 | |
| 2953 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
| 2954 | /* |
| 2955 | * Start timing an activity |
| 2956 | * r3 = pointer to time accumulation struct, r4 = vcpu |
| 2957 | */ |
| 2958 | kvmhv_start_timing: |
| 2959 | ld r5, HSTATE_KVM_VCORE(r13) |
| 2960 | lbz r6, VCORE_IN_GUEST(r5) |
| 2961 | cmpwi r6, 0 |
| 2962 | beq 5f /* if in guest, need to */ |
| 2963 | ld r6, VCORE_TB_OFFSET(r5) /* subtract timebase offset */ |
| 2964 | 5: mftb r5 |
| 2965 | subf r5, r6, r5 |
| 2966 | std r3, VCPU_CUR_ACTIVITY(r4) |
| 2967 | std r5, VCPU_ACTIVITY_START(r4) |
| 2968 | blr |
| 2969 | |
| 2970 | /* |
| 2971 | * Accumulate time to one activity and start another. |
| 2972 | * r3 = pointer to new time accumulation struct, r4 = vcpu |
| 2973 | */ |
| 2974 | kvmhv_accumulate_time: |
| 2975 | ld r5, HSTATE_KVM_VCORE(r13) |
| 2976 | lbz r8, VCORE_IN_GUEST(r5) |
| 2977 | cmpwi r8, 0 |
| 2978 | beq 4f /* if in guest, need to */ |
| 2979 | ld r8, VCORE_TB_OFFSET(r5) /* subtract timebase offset */ |
| 2980 | 4: ld r5, VCPU_CUR_ACTIVITY(r4) |
| 2981 | ld r6, VCPU_ACTIVITY_START(r4) |
| 2982 | std r3, VCPU_CUR_ACTIVITY(r4) |
| 2983 | mftb r7 |
| 2984 | subf r7, r8, r7 |
| 2985 | std r7, VCPU_ACTIVITY_START(r4) |
| 2986 | cmpdi r5, 0 |
| 2987 | beqlr |
| 2988 | subf r3, r6, r7 |
| 2989 | ld r8, TAS_SEQCOUNT(r5) |
| 2990 | cmpdi r8, 0 |
| 2991 | addi r8, r8, 1 |
| 2992 | std r8, TAS_SEQCOUNT(r5) |
| 2993 | lwsync |
| 2994 | ld r7, TAS_TOTAL(r5) |
| 2995 | add r7, r7, r3 |
| 2996 | std r7, TAS_TOTAL(r5) |
| 2997 | ld r6, TAS_MIN(r5) |
| 2998 | ld r7, TAS_MAX(r5) |
| 2999 | beq 3f |
| 3000 | cmpd r3, r6 |
| 3001 | bge 1f |
| 3002 | 3: std r3, TAS_MIN(r5) |
| 3003 | 1: cmpd r3, r7 |
| 3004 | ble 2f |
| 3005 | std r3, TAS_MAX(r5) |
| 3006 | 2: lwsync |
| 3007 | addi r8, r8, 1 |
| 3008 | std r8, TAS_SEQCOUNT(r5) |
| 3009 | blr |
| 3010 | #endif |