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