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> |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 30 | #include <asm/mmu-hash64.h> |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 31 | |
Anton Blanchard | 7ffcf8e | 2013-08-07 02:01:46 +1000 | [diff] [blame] | 32 | #ifdef __LITTLE_ENDIAN__ |
| 33 | #error Need to fix lppaca and SLB shadow accesses in little endian mode |
| 34 | #endif |
| 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 | */ |
| 48 | _GLOBAL(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 */ |
| 78 | ld r3,PACA_SPRG3(r13) |
| 79 | mtspr SPRN_SPRG3,r3 |
| 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 */ |
| 86 | lwz r3, HSTATE_PMC(r13) |
| 87 | lwz r4, HSTATE_PMC + 4(r13) |
| 88 | lwz r5, HSTATE_PMC + 8(r13) |
| 89 | lwz r6, HSTATE_PMC + 12(r13) |
| 90 | lwz r8, HSTATE_PMC + 16(r13) |
| 91 | lwz r9, HSTATE_PMC + 20(r13) |
| 92 | BEGIN_FTR_SECTION |
| 93 | lwz r10, HSTATE_PMC + 24(r13) |
| 94 | lwz r11, HSTATE_PMC + 28(r13) |
| 95 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) |
| 96 | mtspr SPRN_PMC1, r3 |
| 97 | mtspr SPRN_PMC2, r4 |
| 98 | mtspr SPRN_PMC3, r5 |
| 99 | mtspr SPRN_PMC4, r6 |
| 100 | mtspr SPRN_PMC5, r8 |
| 101 | mtspr SPRN_PMC6, r9 |
| 102 | BEGIN_FTR_SECTION |
| 103 | mtspr SPRN_PMC7, r10 |
| 104 | mtspr SPRN_PMC8, r11 |
| 105 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) |
| 106 | ld r3, HSTATE_MMCR(r13) |
| 107 | ld r4, HSTATE_MMCR + 8(r13) |
| 108 | ld r5, HSTATE_MMCR + 16(r13) |
| 109 | mtspr SPRN_MMCR1, r4 |
| 110 | mtspr SPRN_MMCRA, r5 |
| 111 | mtspr SPRN_MMCR0, r3 |
| 112 | isync |
| 113 | 23: |
| 114 | |
| 115 | /* |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 116 | * Reload DEC. HDEC interrupts were disabled when |
| 117 | * we reloaded the host's LPCR value. |
| 118 | */ |
| 119 | ld r3, HSTATE_DECEXP(r13) |
| 120 | mftb r4 |
| 121 | subf r4, r4, r3 |
| 122 | mtspr SPRN_DEC, r4 |
| 123 | |
| 124 | /* |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 125 | * For external and machine check interrupts, we need |
| 126 | * to call the Linux handler to process the interrupt. |
| 127 | * We do that by jumping to absolute address 0x500 for |
| 128 | * external interrupts, or the machine_check_fwnmi label |
| 129 | * for machine checks (since firmware might have patched |
| 130 | * the vector area at 0x200). The [h]rfid at the end of the |
| 131 | * handler will return to the book3s_hv_interrupts.S code. |
| 132 | * For other interrupts we do the rfid to get back |
| 133 | * to the book3s_hv_interrupts.S code here. |
| 134 | */ |
| 135 | ld r8, 112+PPC_LR_STKOFF(r1) |
| 136 | addi r1, r1, 112 |
| 137 | ld r7, HSTATE_HOST_MSR(r13) |
| 138 | |
| 139 | cmpwi cr1, r12, BOOK3S_INTERRUPT_MACHINE_CHECK |
| 140 | cmpwi r12, BOOK3S_INTERRUPT_EXTERNAL |
| 141 | BEGIN_FTR_SECTION |
| 142 | beq 11f |
| 143 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) |
| 144 | |
| 145 | /* RFI into the highmem handler, or branch to interrupt handler */ |
| 146 | mfmsr r6 |
| 147 | li r0, MSR_RI |
| 148 | andc r6, r6, r0 |
| 149 | mtmsrd r6, 1 /* Clear RI in MSR */ |
| 150 | mtsrr0 r8 |
| 151 | mtsrr1 r7 |
| 152 | beqa 0x500 /* external interrupt (PPC970) */ |
| 153 | beq cr1, 13f /* machine check */ |
| 154 | RFI |
| 155 | |
| 156 | /* On POWER7, we have external interrupts set to use HSRR0/1 */ |
| 157 | 11: mtspr SPRN_HSRR0, r8 |
| 158 | mtspr SPRN_HSRR1, r7 |
| 159 | ba 0x500 |
| 160 | |
| 161 | 13: b machine_check_fwnmi |
| 162 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 163 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 164 | kvmppc_primary_no_guest: |
| 165 | /* We handle this much like a ceded vcpu */ |
| 166 | /* set our bit in napping_threads */ |
| 167 | ld r5, HSTATE_KVM_VCORE(r13) |
| 168 | lbz r7, HSTATE_PTID(r13) |
| 169 | li r0, 1 |
| 170 | sld r0, r0, r7 |
| 171 | addi r6, r5, VCORE_NAPPING_THREADS |
| 172 | 1: lwarx r3, 0, r6 |
| 173 | or r3, r3, r0 |
| 174 | stwcx. r3, 0, r6 |
| 175 | bne 1b |
| 176 | /* order napping_threads update vs testing entry_exit_count */ |
| 177 | isync |
| 178 | li r12, 0 |
| 179 | lwz r7, VCORE_ENTRY_EXIT(r5) |
| 180 | cmpwi r7, 0x100 |
| 181 | bge kvm_novcpu_exit /* another thread already exiting */ |
| 182 | li r3, NAPPING_NOVCPU |
| 183 | stb r3, HSTATE_NAPPING(r13) |
| 184 | li r3, 1 |
| 185 | stb r3, HSTATE_HWTHREAD_REQ(r13) |
| 186 | |
| 187 | b kvm_do_nap |
| 188 | |
| 189 | kvm_novcpu_wakeup: |
| 190 | ld r1, HSTATE_HOST_R1(r13) |
| 191 | ld r5, HSTATE_KVM_VCORE(r13) |
| 192 | li r0, 0 |
| 193 | stb r0, HSTATE_NAPPING(r13) |
| 194 | stb r0, HSTATE_HWTHREAD_REQ(r13) |
| 195 | |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 196 | /* check the wake reason */ |
| 197 | bl kvmppc_check_wake_reason |
| 198 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 199 | /* see if any other thread is already exiting */ |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 200 | lwz r0, VCORE_ENTRY_EXIT(r5) |
| 201 | cmpwi r0, 0x100 |
| 202 | bge kvm_novcpu_exit |
| 203 | |
| 204 | /* clear our bit in napping_threads */ |
| 205 | lbz r7, HSTATE_PTID(r13) |
| 206 | li r0, 1 |
| 207 | sld r0, r0, r7 |
| 208 | addi r6, r5, VCORE_NAPPING_THREADS |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 209 | 4: lwarx r7, 0, r6 |
| 210 | andc r7, r7, r0 |
| 211 | stwcx. r7, 0, r6 |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 212 | bne 4b |
| 213 | |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 214 | /* See if the wake reason means we need to exit */ |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 215 | cmpdi r3, 0 |
| 216 | bge kvm_novcpu_exit |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 217 | |
| 218 | /* Got an IPI but other vcpus aren't yet exiting, must be a latecomer */ |
| 219 | ld r4, HSTATE_KVM_VCPU(r13) |
| 220 | cmpdi r4, 0 |
| 221 | bne kvmppc_got_guest |
| 222 | |
| 223 | kvm_novcpu_exit: |
| 224 | b hdec_soon |
| 225 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 226 | /* |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 227 | * We come in here when wakened from nap mode. |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 228 | * Relocation is off and most register values are lost. |
| 229 | * r13 points to the PACA. |
| 230 | */ |
| 231 | .globl kvm_start_guest |
| 232 | kvm_start_guest: |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 233 | ld r2,PACATOC(r13) |
| 234 | |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame] | 235 | li r0,KVM_HWTHREAD_IN_KVM |
| 236 | stb r0,HSTATE_HWTHREAD_STATE(r13) |
| 237 | |
| 238 | /* NV GPR values from power7_idle() will no longer be valid */ |
| 239 | li r0,1 |
| 240 | stb r0,PACA_NAPSTATELOST(r13) |
| 241 | |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 242 | /* were we napping due to cede? */ |
| 243 | lbz r0,HSTATE_NAPPING(r13) |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 244 | cmpwi r0,NAPPING_CEDE |
| 245 | beq kvm_end_cede |
| 246 | cmpwi r0,NAPPING_NOVCPU |
| 247 | beq kvm_novcpu_wakeup |
| 248 | |
| 249 | ld r1,PACAEMERGSP(r13) |
| 250 | subi r1,r1,STACK_FRAME_OVERHEAD |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 251 | |
| 252 | /* |
| 253 | * We weren't napping due to cede, so this must be a secondary |
| 254 | * thread being woken up to run a guest, or being woken up due |
| 255 | * to a stray IPI. (Or due to some machine check or hypervisor |
| 256 | * maintenance interrupt while the core is in KVM.) |
| 257 | */ |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame] | 258 | |
| 259 | /* Check the wake reason in SRR1 to see why we got here */ |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 260 | bl kvmppc_check_wake_reason |
| 261 | cmpdi r3, 0 |
| 262 | bge kvm_no_guest |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame] | 263 | |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 264 | /* get vcpu pointer, NULL if we have no vcpu to run */ |
Paul Mackerras | 7b444c6 | 2012-10-15 01:16:14 +0000 | [diff] [blame] | 265 | ld r4,HSTATE_KVM_VCPU(r13) |
| 266 | cmpdi r4,0 |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame] | 267 | /* if we have no vcpu to run, go back to sleep */ |
Paul Mackerras | 7b444c6 | 2012-10-15 01:16:14 +0000 | [diff] [blame] | 268 | beq kvm_no_guest |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame] | 269 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 270 | /* Set HSTATE_DSCR(r13) to something sensible */ |
| 271 | LOAD_REG_ADDR(r6, dscr_default) |
| 272 | ld r6, 0(r6) |
| 273 | std r6, HSTATE_DSCR(r13) |
| 274 | |
| 275 | bl kvmppc_hv_entry |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 276 | |
| 277 | /* Back from the guest, go back to nap */ |
| 278 | /* Clear our vcpu pointer so we don't come back in early */ |
| 279 | li r0, 0 |
| 280 | std r0, HSTATE_KVM_VCPU(r13) |
| 281 | lwsync |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 282 | |
| 283 | /* increment the nap count and then go to nap mode */ |
| 284 | ld r4, HSTATE_KVM_VCORE(r13) |
| 285 | addi r4, r4, VCORE_NAP_COUNT |
| 286 | lwsync /* make previous updates visible */ |
| 287 | 51: lwarx r3, 0, r4 |
| 288 | addi r3, r3, 1 |
| 289 | stwcx. r3, 0, r4 |
| 290 | bne 51b |
| 291 | |
| 292 | kvm_no_guest: |
| 293 | li r0, KVM_HWTHREAD_IN_NAP |
| 294 | stb r0, HSTATE_HWTHREAD_STATE(r13) |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 295 | kvm_do_nap: |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 296 | li r3, LPCR_PECE0 |
| 297 | mfspr r4, SPRN_LPCR |
| 298 | rlwimi r4, r3, 0, LPCR_PECE0 | LPCR_PECE1 |
| 299 | mtspr SPRN_LPCR, r4 |
| 300 | isync |
| 301 | std r0, HSTATE_SCRATCH0(r13) |
| 302 | ptesync |
| 303 | ld r0, HSTATE_SCRATCH0(r13) |
| 304 | 1: cmpd r0, r0 |
| 305 | bne 1b |
| 306 | nap |
| 307 | b . |
| 308 | |
| 309 | /****************************************************************************** |
| 310 | * * |
| 311 | * Entry code * |
| 312 | * * |
| 313 | *****************************************************************************/ |
| 314 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 315 | .global kvmppc_hv_entry |
| 316 | kvmppc_hv_entry: |
| 317 | |
| 318 | /* Required state: |
| 319 | * |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 320 | * R4 = vcpu pointer (or NULL) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 321 | * MSR = ~IR|DR |
| 322 | * R13 = PACA |
| 323 | * R1 = host R1 |
| 324 | * all other volatile GPRS = free |
| 325 | */ |
| 326 | mflr r0 |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 327 | std r0, PPC_LR_STKOFF(r1) |
| 328 | stdu r1, -112(r1) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 329 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 330 | /* Save R1 in the PACA */ |
| 331 | std r1, HSTATE_HOST_R1(r13) |
| 332 | |
| 333 | li r6, KVM_GUEST_MODE_HOST_HV |
| 334 | stb r6, HSTATE_IN_GUEST(r13) |
| 335 | |
| 336 | /* Clear out SLB */ |
| 337 | li r6,0 |
| 338 | slbmte r6,r6 |
| 339 | slbia |
| 340 | ptesync |
| 341 | |
| 342 | BEGIN_FTR_SECTION |
| 343 | b 30f |
| 344 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) |
| 345 | /* |
| 346 | * POWER7 host -> guest partition switch code. |
| 347 | * We don't have to lock against concurrent tlbies, |
| 348 | * but we do have to coordinate across hardware threads. |
| 349 | */ |
| 350 | /* Increment entry count iff exit count is zero. */ |
| 351 | ld r5,HSTATE_KVM_VCORE(r13) |
| 352 | addi r9,r5,VCORE_ENTRY_EXIT |
| 353 | 21: lwarx r3,0,r9 |
| 354 | cmpwi r3,0x100 /* any threads starting to exit? */ |
| 355 | bge secondary_too_late /* if so we're too late to the party */ |
| 356 | addi r3,r3,1 |
| 357 | stwcx. r3,0,r9 |
| 358 | bne 21b |
| 359 | |
| 360 | /* Primary thread switches to guest partition. */ |
| 361 | ld r9,VCORE_KVM(r5) /* pointer to struct kvm */ |
| 362 | lbz r6,HSTATE_PTID(r13) |
| 363 | cmpwi r6,0 |
| 364 | bne 20f |
| 365 | ld r6,KVM_SDR1(r9) |
| 366 | lwz r7,KVM_LPID(r9) |
| 367 | li r0,LPID_RSVD /* switch to reserved LPID */ |
| 368 | mtspr SPRN_LPID,r0 |
| 369 | ptesync |
| 370 | mtspr SPRN_SDR1,r6 /* switch to partition page table */ |
| 371 | mtspr SPRN_LPID,r7 |
| 372 | isync |
| 373 | |
| 374 | /* See if we need to flush the TLB */ |
| 375 | lhz r6,PACAPACAINDEX(r13) /* test_bit(cpu, need_tlb_flush) */ |
| 376 | clrldi r7,r6,64-6 /* extract bit number (6 bits) */ |
| 377 | srdi r6,r6,6 /* doubleword number */ |
| 378 | sldi r6,r6,3 /* address offset */ |
| 379 | add r6,r6,r9 |
| 380 | addi r6,r6,KVM_NEED_FLUSH /* dword in kvm->arch.need_tlb_flush */ |
| 381 | li r0,1 |
| 382 | sld r0,r0,r7 |
| 383 | ld r7,0(r6) |
| 384 | and. r7,r7,r0 |
| 385 | beq 22f |
| 386 | 23: ldarx r7,0,r6 /* if set, clear the bit */ |
| 387 | andc r7,r7,r0 |
| 388 | stdcx. r7,0,r6 |
| 389 | bne 23b |
Paul Mackerras | ca25205 | 2014-01-08 21:25:22 +1100 | [diff] [blame] | 390 | /* Flush the TLB of any entries for this LPID */ |
| 391 | /* use arch 2.07S as a proxy for POWER8 */ |
| 392 | BEGIN_FTR_SECTION |
| 393 | li r6,512 /* POWER8 has 512 sets */ |
| 394 | FTR_SECTION_ELSE |
| 395 | li r6,128 /* POWER7 has 128 sets */ |
| 396 | ALT_FTR_SECTION_END_IFSET(CPU_FTR_ARCH_207S) |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 397 | mtctr r6 |
| 398 | li r7,0x800 /* IS field = 0b10 */ |
| 399 | ptesync |
| 400 | 28: tlbiel r7 |
| 401 | addi r7,r7,0x1000 |
| 402 | bdnz 28b |
| 403 | ptesync |
| 404 | |
| 405 | /* Add timebase offset onto timebase */ |
| 406 | 22: ld r8,VCORE_TB_OFFSET(r5) |
| 407 | cmpdi r8,0 |
| 408 | beq 37f |
| 409 | mftb r6 /* current host timebase */ |
| 410 | add r8,r8,r6 |
| 411 | mtspr SPRN_TBU40,r8 /* update upper 40 bits */ |
| 412 | mftb r7 /* check if lower 24 bits overflowed */ |
| 413 | clrldi r6,r6,40 |
| 414 | clrldi r7,r7,40 |
| 415 | cmpld r7,r6 |
| 416 | bge 37f |
| 417 | addis r8,r8,0x100 /* if so, increment upper 40 bits */ |
| 418 | mtspr SPRN_TBU40,r8 |
| 419 | |
| 420 | /* Load guest PCR value to select appropriate compat mode */ |
| 421 | 37: ld r7, VCORE_PCR(r5) |
| 422 | cmpdi r7, 0 |
| 423 | beq 38f |
| 424 | mtspr SPRN_PCR, r7 |
| 425 | 38: |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 426 | |
| 427 | BEGIN_FTR_SECTION |
| 428 | /* DPDES is shared between threads */ |
| 429 | ld r8, VCORE_DPDES(r5) |
| 430 | mtspr SPRN_DPDES, r8 |
| 431 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
| 432 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 433 | li r0,1 |
| 434 | stb r0,VCORE_IN_GUEST(r5) /* signal secondaries to continue */ |
| 435 | b 10f |
| 436 | |
| 437 | /* Secondary threads wait for primary to have done partition switch */ |
| 438 | 20: lbz r0,VCORE_IN_GUEST(r5) |
| 439 | cmpwi r0,0 |
| 440 | beq 20b |
| 441 | |
| 442 | /* Set LPCR and RMOR. */ |
| 443 | 10: ld r8,VCORE_LPCR(r5) |
| 444 | mtspr SPRN_LPCR,r8 |
| 445 | ld r8,KVM_RMOR(r9) |
| 446 | mtspr SPRN_RMOR,r8 |
| 447 | isync |
| 448 | |
| 449 | /* Check if HDEC expires soon */ |
| 450 | mfspr r3,SPRN_HDEC |
| 451 | cmpwi r3,512 /* 1 microsecond */ |
| 452 | li r12,BOOK3S_INTERRUPT_HV_DECREMENTER |
| 453 | blt hdec_soon |
| 454 | b 31f |
| 455 | |
| 456 | /* |
| 457 | * PPC970 host -> guest partition switch code. |
| 458 | * We have to lock against concurrent tlbies, |
| 459 | * using native_tlbie_lock to lock against host tlbies |
| 460 | * and kvm->arch.tlbie_lock to lock against guest tlbies. |
| 461 | * We also have to invalidate the TLB since its |
| 462 | * entries aren't tagged with the LPID. |
| 463 | */ |
| 464 | 30: ld r5,HSTATE_KVM_VCORE(r13) |
| 465 | ld r9,VCORE_KVM(r5) /* pointer to struct kvm */ |
| 466 | |
| 467 | /* first take native_tlbie_lock */ |
| 468 | .section ".toc","aw" |
| 469 | toc_tlbie_lock: |
| 470 | .tc native_tlbie_lock[TC],native_tlbie_lock |
| 471 | .previous |
| 472 | ld r3,toc_tlbie_lock@toc(2) |
| 473 | #ifdef __BIG_ENDIAN__ |
| 474 | lwz r8,PACA_LOCK_TOKEN(r13) |
| 475 | #else |
| 476 | lwz r8,PACAPACAINDEX(r13) |
| 477 | #endif |
| 478 | 24: lwarx r0,0,r3 |
| 479 | cmpwi r0,0 |
| 480 | bne 24b |
| 481 | stwcx. r8,0,r3 |
| 482 | bne 24b |
| 483 | isync |
| 484 | |
| 485 | ld r5,HSTATE_KVM_VCORE(r13) |
| 486 | ld r7,VCORE_LPCR(r5) /* use vcore->lpcr to store HID4 */ |
| 487 | li r0,0x18f |
| 488 | rotldi r0,r0,HID4_LPID5_SH /* all lpid bits in HID4 = 1 */ |
| 489 | or r0,r7,r0 |
| 490 | ptesync |
| 491 | sync |
| 492 | mtspr SPRN_HID4,r0 /* switch to reserved LPID */ |
| 493 | isync |
| 494 | li r0,0 |
| 495 | stw r0,0(r3) /* drop native_tlbie_lock */ |
| 496 | |
| 497 | /* invalidate the whole TLB */ |
| 498 | li r0,256 |
| 499 | mtctr r0 |
| 500 | li r6,0 |
| 501 | 25: tlbiel r6 |
| 502 | addi r6,r6,0x1000 |
| 503 | bdnz 25b |
| 504 | ptesync |
| 505 | |
| 506 | /* Take the guest's tlbie_lock */ |
| 507 | addi r3,r9,KVM_TLBIE_LOCK |
| 508 | 24: lwarx r0,0,r3 |
| 509 | cmpwi r0,0 |
| 510 | bne 24b |
| 511 | stwcx. r8,0,r3 |
| 512 | bne 24b |
| 513 | isync |
| 514 | ld r6,KVM_SDR1(r9) |
| 515 | mtspr SPRN_SDR1,r6 /* switch to partition page table */ |
| 516 | |
| 517 | /* Set up HID4 with the guest's LPID etc. */ |
| 518 | sync |
| 519 | mtspr SPRN_HID4,r7 |
| 520 | isync |
| 521 | |
| 522 | /* drop the guest's tlbie_lock */ |
| 523 | li r0,0 |
| 524 | stw r0,0(r3) |
| 525 | |
| 526 | /* Check if HDEC expires soon */ |
| 527 | mfspr r3,SPRN_HDEC |
| 528 | cmpwi r3,10 |
| 529 | li r12,BOOK3S_INTERRUPT_HV_DECREMENTER |
| 530 | blt hdec_soon |
| 531 | |
| 532 | /* Enable HDEC interrupts */ |
| 533 | mfspr r0,SPRN_HID0 |
| 534 | li r3,1 |
| 535 | rldimi r0,r3, HID0_HDICE_SH, 64-HID0_HDICE_SH-1 |
| 536 | sync |
| 537 | mtspr SPRN_HID0,r0 |
| 538 | mfspr r0,SPRN_HID0 |
| 539 | mfspr r0,SPRN_HID0 |
| 540 | mfspr r0,SPRN_HID0 |
| 541 | mfspr r0,SPRN_HID0 |
| 542 | mfspr r0,SPRN_HID0 |
| 543 | mfspr r0,SPRN_HID0 |
| 544 | 31: |
| 545 | /* Do we have a guest vcpu to run? */ |
| 546 | cmpdi r4, 0 |
| 547 | beq kvmppc_primary_no_guest |
| 548 | kvmppc_got_guest: |
| 549 | |
| 550 | /* Load up guest SLB entries */ |
| 551 | lwz r5,VCPU_SLB_MAX(r4) |
| 552 | cmpwi r5,0 |
| 553 | beq 9f |
| 554 | mtctr r5 |
| 555 | addi r6,r4,VCPU_SLB |
| 556 | 1: ld r8,VCPU_SLB_E(r6) |
| 557 | ld r9,VCPU_SLB_V(r6) |
| 558 | slbmte r9,r8 |
| 559 | addi r6,r6,VCPU_SLB_SIZE |
| 560 | bdnz 1b |
| 561 | 9: |
| 562 | /* Increment yield count if they have a VPA */ |
| 563 | ld r3, VCPU_VPA(r4) |
| 564 | cmpdi r3, 0 |
| 565 | beq 25f |
| 566 | lwz r5, LPPACA_YIELDCOUNT(r3) |
| 567 | addi r5, r5, 1 |
| 568 | stw r5, LPPACA_YIELDCOUNT(r3) |
| 569 | li r6, 1 |
| 570 | stb r6, VCPU_VPA_DIRTY(r4) |
| 571 | 25: |
| 572 | |
| 573 | BEGIN_FTR_SECTION |
| 574 | /* Save purr/spurr */ |
| 575 | mfspr r5,SPRN_PURR |
| 576 | mfspr r6,SPRN_SPURR |
| 577 | std r5,HSTATE_PURR(r13) |
| 578 | std r6,HSTATE_SPURR(r13) |
| 579 | ld r7,VCPU_PURR(r4) |
| 580 | ld r8,VCPU_SPURR(r4) |
| 581 | mtspr SPRN_PURR,r7 |
| 582 | mtspr SPRN_SPURR,r8 |
| 583 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) |
| 584 | |
Michael Neuling | eee7ff9 | 2014-01-08 21:25:19 +1100 | [diff] [blame] | 585 | BEGIN_FTR_SECTION |
Paul Mackerras | 8943633 | 2012-03-02 01:38:23 +0000 | [diff] [blame] | 586 | /* Set partition DABR */ |
| 587 | /* Do this before re-enabling PMU to avoid P7 DABR corruption bug */ |
| 588 | li r5,3 |
| 589 | ld r6,VCPU_DABR(r4) |
| 590 | mtspr SPRN_DABRX,r5 |
| 591 | mtspr SPRN_DABR,r6 |
Michael Neuling | eee7ff9 | 2014-01-08 21:25:19 +1100 | [diff] [blame] | 592 | BEGIN_FTR_SECTION_NESTED(89) |
Paul Mackerras | 8943633 | 2012-03-02 01:38:23 +0000 | [diff] [blame] | 593 | isync |
Michael Neuling | eee7ff9 | 2014-01-08 21:25:19 +1100 | [diff] [blame] | 594 | END_FTR_SECTION_NESTED(CPU_FTR_ARCH_206, CPU_FTR_ARCH_206, 89) |
| 595 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 596 | |
| 597 | /* Load guest PMU registers */ |
| 598 | /* R4 is live here (vcpu pointer) */ |
| 599 | li r3, 1 |
| 600 | sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */ |
| 601 | mtspr SPRN_MMCR0, r3 /* freeze all counters, disable ints */ |
| 602 | isync |
| 603 | lwz r3, VCPU_PMC(r4) /* always load up guest PMU registers */ |
| 604 | lwz r5, VCPU_PMC + 4(r4) /* to prevent information leak */ |
| 605 | lwz r6, VCPU_PMC + 8(r4) |
| 606 | lwz r7, VCPU_PMC + 12(r4) |
| 607 | lwz r8, VCPU_PMC + 16(r4) |
| 608 | lwz r9, VCPU_PMC + 20(r4) |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 609 | BEGIN_FTR_SECTION |
| 610 | lwz r10, VCPU_PMC + 24(r4) |
| 611 | lwz r11, VCPU_PMC + 28(r4) |
| 612 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 613 | mtspr SPRN_PMC1, r3 |
| 614 | mtspr SPRN_PMC2, r5 |
| 615 | mtspr SPRN_PMC3, r6 |
| 616 | mtspr SPRN_PMC4, r7 |
| 617 | mtspr SPRN_PMC5, r8 |
| 618 | mtspr SPRN_PMC6, r9 |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 619 | BEGIN_FTR_SECTION |
| 620 | mtspr SPRN_PMC7, r10 |
| 621 | mtspr SPRN_PMC8, r11 |
| 622 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 623 | ld r3, VCPU_MMCR(r4) |
| 624 | ld r5, VCPU_MMCR + 8(r4) |
| 625 | ld r6, VCPU_MMCR + 16(r4) |
Paul Mackerras | 1494178 | 2013-09-06 13:11:18 +1000 | [diff] [blame] | 626 | ld r7, VCPU_SIAR(r4) |
| 627 | ld r8, VCPU_SDAR(r4) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 628 | mtspr SPRN_MMCR1, r5 |
| 629 | mtspr SPRN_MMCRA, r6 |
Paul Mackerras | 1494178 | 2013-09-06 13:11:18 +1000 | [diff] [blame] | 630 | mtspr SPRN_SIAR, r7 |
| 631 | mtspr SPRN_SDAR, r8 |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 632 | BEGIN_FTR_SECTION |
| 633 | ld r5, VCPU_MMCR + 24(r4) |
| 634 | ld r6, VCPU_SIER(r4) |
| 635 | lwz r7, VCPU_PMC + 24(r4) |
| 636 | lwz r8, VCPU_PMC + 28(r4) |
| 637 | ld r9, VCPU_MMCR + 32(r4) |
| 638 | mtspr SPRN_MMCR2, r5 |
| 639 | mtspr SPRN_SIER, r6 |
| 640 | mtspr SPRN_SPMC1, r7 |
| 641 | mtspr SPRN_SPMC2, r8 |
| 642 | mtspr SPRN_MMCRS, r9 |
| 643 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 644 | mtspr SPRN_MMCR0, r3 |
| 645 | isync |
| 646 | |
| 647 | /* Load up FP, VMX and VSX registers */ |
| 648 | bl kvmppc_load_fp |
| 649 | |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 650 | ld r14, VCPU_GPR(R14)(r4) |
| 651 | ld r15, VCPU_GPR(R15)(r4) |
| 652 | ld r16, VCPU_GPR(R16)(r4) |
| 653 | ld r17, VCPU_GPR(R17)(r4) |
| 654 | ld r18, VCPU_GPR(R18)(r4) |
| 655 | ld r19, VCPU_GPR(R19)(r4) |
| 656 | ld r20, VCPU_GPR(R20)(r4) |
| 657 | ld r21, VCPU_GPR(R21)(r4) |
| 658 | ld r22, VCPU_GPR(R22)(r4) |
| 659 | ld r23, VCPU_GPR(R23)(r4) |
| 660 | ld r24, VCPU_GPR(R24)(r4) |
| 661 | ld r25, VCPU_GPR(R25)(r4) |
| 662 | ld r26, VCPU_GPR(R26)(r4) |
| 663 | ld r27, VCPU_GPR(R27)(r4) |
| 664 | ld r28, VCPU_GPR(R28)(r4) |
| 665 | ld r29, VCPU_GPR(R29)(r4) |
| 666 | ld r30, VCPU_GPR(R30)(r4) |
| 667 | ld r31, VCPU_GPR(R31)(r4) |
Paul Mackerras | 8943633 | 2012-03-02 01:38:23 +0000 | [diff] [blame] | 668 | |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 669 | BEGIN_FTR_SECTION |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 670 | /* Switch DSCR to guest value */ |
| 671 | ld r5, VCPU_DSCR(r4) |
| 672 | mtspr SPRN_DSCR, r5 |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 673 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 674 | |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 675 | BEGIN_FTR_SECTION |
| 676 | /* Skip next section on POWER7 or PPC970 */ |
| 677 | b 8f |
| 678 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) |
| 679 | /* Turn on TM so we can access TFHAR/TFIAR/TEXASR */ |
| 680 | mfmsr r8 |
| 681 | li r0, 1 |
| 682 | rldimi r8, r0, MSR_TM_LG, 63-MSR_TM_LG |
| 683 | mtmsrd r8 |
| 684 | |
| 685 | /* Load up POWER8-specific registers */ |
| 686 | ld r5, VCPU_IAMR(r4) |
| 687 | lwz r6, VCPU_PSPB(r4) |
| 688 | ld r7, VCPU_FSCR(r4) |
| 689 | mtspr SPRN_IAMR, r5 |
| 690 | mtspr SPRN_PSPB, r6 |
| 691 | mtspr SPRN_FSCR, r7 |
| 692 | ld r5, VCPU_DAWR(r4) |
| 693 | ld r6, VCPU_DAWRX(r4) |
| 694 | ld r7, VCPU_CIABR(r4) |
| 695 | ld r8, VCPU_TAR(r4) |
| 696 | mtspr SPRN_DAWR, r5 |
| 697 | mtspr SPRN_DAWRX, r6 |
| 698 | mtspr SPRN_CIABR, r7 |
| 699 | mtspr SPRN_TAR, r8 |
| 700 | ld r5, VCPU_IC(r4) |
| 701 | ld r6, VCPU_VTB(r4) |
| 702 | mtspr SPRN_IC, r5 |
| 703 | mtspr SPRN_VTB, r6 |
| 704 | ld r5, VCPU_TFHAR(r4) |
| 705 | ld r6, VCPU_TFIAR(r4) |
| 706 | ld r7, VCPU_TEXASR(r4) |
| 707 | ld r8, VCPU_EBBHR(r4) |
| 708 | mtspr SPRN_TFHAR, r5 |
| 709 | mtspr SPRN_TFIAR, r6 |
| 710 | mtspr SPRN_TEXASR, r7 |
| 711 | mtspr SPRN_EBBHR, r8 |
| 712 | ld r5, VCPU_EBBRR(r4) |
| 713 | ld r6, VCPU_BESCR(r4) |
| 714 | ld r7, VCPU_CSIGR(r4) |
| 715 | ld r8, VCPU_TACR(r4) |
| 716 | mtspr SPRN_EBBRR, r5 |
| 717 | mtspr SPRN_BESCR, r6 |
| 718 | mtspr SPRN_CSIGR, r7 |
| 719 | mtspr SPRN_TACR, r8 |
| 720 | ld r5, VCPU_TCSCR(r4) |
| 721 | ld r6, VCPU_ACOP(r4) |
| 722 | lwz r7, VCPU_GUEST_PID(r4) |
| 723 | ld r8, VCPU_WORT(r4) |
| 724 | mtspr SPRN_TCSCR, r5 |
| 725 | mtspr SPRN_ACOP, r6 |
| 726 | mtspr SPRN_PID, r7 |
| 727 | mtspr SPRN_WORT, r8 |
| 728 | 8: |
| 729 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 730 | /* |
| 731 | * Set the decrementer to the guest decrementer. |
| 732 | */ |
| 733 | ld r8,VCPU_DEC_EXPIRES(r4) |
| 734 | mftb r7 |
| 735 | subf r3,r7,r8 |
| 736 | mtspr SPRN_DEC,r3 |
| 737 | stw r3,VCPU_DEC(r4) |
| 738 | |
| 739 | ld r5, VCPU_SPRG0(r4) |
| 740 | ld r6, VCPU_SPRG1(r4) |
| 741 | ld r7, VCPU_SPRG2(r4) |
| 742 | ld r8, VCPU_SPRG3(r4) |
| 743 | mtspr SPRN_SPRG0, r5 |
| 744 | mtspr SPRN_SPRG1, r6 |
| 745 | mtspr SPRN_SPRG2, r7 |
| 746 | mtspr SPRN_SPRG3, r8 |
| 747 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 748 | /* Load up DAR and DSISR */ |
| 749 | ld r5, VCPU_DAR(r4) |
| 750 | lwz r6, VCPU_DSISR(r4) |
| 751 | mtspr SPRN_DAR, r5 |
| 752 | mtspr SPRN_DSISR, r6 |
| 753 | |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 754 | BEGIN_FTR_SECTION |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 755 | /* Restore AMR and UAMOR, set AMOR to all 1s */ |
| 756 | ld r5,VCPU_AMR(r4) |
| 757 | ld r6,VCPU_UAMOR(r4) |
| 758 | li r7,-1 |
| 759 | mtspr SPRN_AMR,r5 |
| 760 | mtspr SPRN_UAMOR,r6 |
| 761 | mtspr SPRN_AMOR,r7 |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 762 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 763 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 764 | /* Restore state of CTRL run bit; assume 1 on entry */ |
| 765 | lwz r5,VCPU_CTRL(r4) |
| 766 | andi. r5,r5,1 |
| 767 | bne 4f |
| 768 | mfspr r6,SPRN_CTRLF |
| 769 | clrrdi r6,r6,1 |
| 770 | mtspr SPRN_CTRLT,r6 |
| 771 | 4: |
| 772 | ld r6, VCPU_CTR(r4) |
| 773 | lwz r7, VCPU_XER(r4) |
| 774 | |
| 775 | mtctr r6 |
| 776 | mtxer r7 |
| 777 | |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 778 | kvmppc_cede_reentry: /* r4 = vcpu, r13 = paca */ |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 779 | ld r10, VCPU_PC(r4) |
| 780 | ld r11, VCPU_MSR(r4) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 781 | ld r6, VCPU_SRR0(r4) |
| 782 | ld r7, VCPU_SRR1(r4) |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 783 | mtspr SPRN_SRR0, r6 |
| 784 | mtspr SPRN_SRR1, r7 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 785 | |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 786 | deliver_guest_interrupt: |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 787 | /* r11 = vcpu->arch.msr & ~MSR_HV */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 788 | rldicl r11, r11, 63 - MSR_HV_LG, 1 |
| 789 | rotldi r11, r11, 1 + MSR_HV_LG |
| 790 | ori r11, r11, MSR_ME |
| 791 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 792 | /* Check if we can deliver an external or decrementer interrupt now */ |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 793 | ld r0, VCPU_PENDING_EXC(r4) |
| 794 | rldicl r0, r0, 64 - BOOK3S_IRQPRIO_EXTERNAL_LEVEL, 63 |
| 795 | cmpdi cr1, r0, 0 |
| 796 | andi. r8, r11, MSR_EE |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 797 | BEGIN_FTR_SECTION |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 798 | mfspr r8, SPRN_LPCR |
| 799 | /* Insert EXTERNAL_LEVEL bit into LPCR at the MER bit position */ |
| 800 | rldimi r8, r0, LPCR_MER_SH, 63 - LPCR_MER_SH |
| 801 | mtspr SPRN_LPCR, r8 |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 802 | isync |
| 803 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) |
| 804 | beq 5f |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 805 | li r0, BOOK3S_INTERRUPT_EXTERNAL |
| 806 | bne cr1, 12f |
| 807 | mfspr r0, SPRN_DEC |
| 808 | cmpwi r0, 0 |
| 809 | li r0, BOOK3S_INTERRUPT_DECREMENTER |
| 810 | bge 5f |
| 811 | |
| 812 | 12: mtspr SPRN_SRR0, r10 |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 813 | mr r10,r0 |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 814 | mtspr SPRN_SRR1, r11 |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 815 | li r11,(MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */ |
| 816 | rotldi r11,r11,63 |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 817 | 5: |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 818 | |
Liu Ping Fan | 27025a6 | 2013-11-19 14:12:48 +0800 | [diff] [blame] | 819 | /* |
| 820 | * Required state: |
| 821 | * R4 = vcpu |
| 822 | * R10: value for HSRR0 |
| 823 | * R11: value for HSRR1 |
| 824 | * R13 = PACA |
| 825 | */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 826 | fast_guest_return: |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 827 | li r0,0 |
| 828 | stb r0,VCPU_CEDED(r4) /* cancel cede */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 829 | mtspr SPRN_HSRR0,r10 |
| 830 | mtspr SPRN_HSRR1,r11 |
| 831 | |
| 832 | /* Activate guest mode, so faults get handled by KVM */ |
Paul Mackerras | 44a3add | 2013-10-04 21:45:04 +1000 | [diff] [blame] | 833 | li r9, KVM_GUEST_MODE_GUEST_HV |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 834 | stb r9, HSTATE_IN_GUEST(r13) |
| 835 | |
| 836 | /* Enter guest */ |
| 837 | |
Paul Mackerras | 0acb911 | 2013-02-04 18:10:51 +0000 | [diff] [blame] | 838 | BEGIN_FTR_SECTION |
| 839 | ld r5, VCPU_CFAR(r4) |
| 840 | mtspr SPRN_CFAR, r5 |
| 841 | END_FTR_SECTION_IFSET(CPU_FTR_CFAR) |
Paul Mackerras | 4b8473c | 2013-09-20 14:52:39 +1000 | [diff] [blame] | 842 | BEGIN_FTR_SECTION |
| 843 | ld r0, VCPU_PPR(r4) |
| 844 | END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) |
Paul Mackerras | 0acb911 | 2013-02-04 18:10:51 +0000 | [diff] [blame] | 845 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 846 | ld r5, VCPU_LR(r4) |
| 847 | lwz r6, VCPU_CR(r4) |
| 848 | mtlr r5 |
| 849 | mtcr r6 |
| 850 | |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 851 | ld r1, VCPU_GPR(R1)(r4) |
| 852 | ld r2, VCPU_GPR(R2)(r4) |
| 853 | ld r3, VCPU_GPR(R3)(r4) |
| 854 | ld r5, VCPU_GPR(R5)(r4) |
| 855 | ld r6, VCPU_GPR(R6)(r4) |
| 856 | ld r7, VCPU_GPR(R7)(r4) |
| 857 | ld r8, VCPU_GPR(R8)(r4) |
| 858 | ld r9, VCPU_GPR(R9)(r4) |
| 859 | ld r10, VCPU_GPR(R10)(r4) |
| 860 | ld r11, VCPU_GPR(R11)(r4) |
| 861 | ld r12, VCPU_GPR(R12)(r4) |
| 862 | ld r13, VCPU_GPR(R13)(r4) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 863 | |
Paul Mackerras | 4b8473c | 2013-09-20 14:52:39 +1000 | [diff] [blame] | 864 | BEGIN_FTR_SECTION |
| 865 | mtspr SPRN_PPR, r0 |
| 866 | END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) |
| 867 | ld r0, VCPU_GPR(R0)(r4) |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 868 | ld r4, VCPU_GPR(R4)(r4) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 869 | |
| 870 | hrfid |
| 871 | b . |
| 872 | |
| 873 | /****************************************************************************** |
| 874 | * * |
| 875 | * Exit code * |
| 876 | * * |
| 877 | *****************************************************************************/ |
| 878 | |
| 879 | /* |
| 880 | * We come here from the first-level interrupt handlers. |
| 881 | */ |
Aneesh Kumar K.V | dd96b2c | 2013-10-07 22:17:55 +0530 | [diff] [blame] | 882 | .globl kvmppc_interrupt_hv |
| 883 | kvmppc_interrupt_hv: |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 884 | /* |
| 885 | * Register contents: |
| 886 | * R12 = interrupt vector |
| 887 | * R13 = PACA |
| 888 | * guest CR, R12 saved in shadow VCPU SCRATCH1/0 |
| 889 | * guest R13 saved in SPRN_SCRATCH0 |
| 890 | */ |
| 891 | /* abuse host_r2 as third scratch area; we get r2 from PACATOC(r13) */ |
| 892 | std r9, HSTATE_HOST_R2(r13) |
Paul Mackerras | 44a3add | 2013-10-04 21:45:04 +1000 | [diff] [blame] | 893 | |
| 894 | lbz r9, HSTATE_IN_GUEST(r13) |
| 895 | cmpwi r9, KVM_GUEST_MODE_HOST_HV |
| 896 | beq kvmppc_bad_host_intr |
Aneesh Kumar K.V | dd96b2c | 2013-10-07 22:17:55 +0530 | [diff] [blame] | 897 | #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE |
| 898 | cmpwi r9, KVM_GUEST_MODE_GUEST |
| 899 | ld r9, HSTATE_HOST_R2(r13) |
| 900 | beq kvmppc_interrupt_pr |
| 901 | #endif |
Paul Mackerras | 44a3add | 2013-10-04 21:45:04 +1000 | [diff] [blame] | 902 | /* We're now back in the host but in guest MMU context */ |
| 903 | li r9, KVM_GUEST_MODE_HOST_HV |
| 904 | stb r9, HSTATE_IN_GUEST(r13) |
| 905 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 906 | ld r9, HSTATE_KVM_VCPU(r13) |
| 907 | |
| 908 | /* Save registers */ |
| 909 | |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 910 | std r0, VCPU_GPR(R0)(r9) |
| 911 | std r1, VCPU_GPR(R1)(r9) |
| 912 | std r2, VCPU_GPR(R2)(r9) |
| 913 | std r3, VCPU_GPR(R3)(r9) |
| 914 | std r4, VCPU_GPR(R4)(r9) |
| 915 | std r5, VCPU_GPR(R5)(r9) |
| 916 | std r6, VCPU_GPR(R6)(r9) |
| 917 | std r7, VCPU_GPR(R7)(r9) |
| 918 | std r8, VCPU_GPR(R8)(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 919 | ld r0, HSTATE_HOST_R2(r13) |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 920 | std r0, VCPU_GPR(R9)(r9) |
| 921 | std r10, VCPU_GPR(R10)(r9) |
| 922 | std r11, VCPU_GPR(R11)(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 923 | ld r3, HSTATE_SCRATCH0(r13) |
| 924 | lwz r4, HSTATE_SCRATCH1(r13) |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 925 | std r3, VCPU_GPR(R12)(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 926 | stw r4, VCPU_CR(r9) |
Paul Mackerras | 0acb911 | 2013-02-04 18:10:51 +0000 | [diff] [blame] | 927 | BEGIN_FTR_SECTION |
| 928 | ld r3, HSTATE_CFAR(r13) |
| 929 | std r3, VCPU_CFAR(r9) |
| 930 | END_FTR_SECTION_IFSET(CPU_FTR_CFAR) |
Paul Mackerras | 4b8473c | 2013-09-20 14:52:39 +1000 | [diff] [blame] | 931 | BEGIN_FTR_SECTION |
| 932 | ld r4, HSTATE_PPR(r13) |
| 933 | std r4, VCPU_PPR(r9) |
| 934 | END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 935 | |
| 936 | /* Restore R1/R2 so we can handle faults */ |
| 937 | ld r1, HSTATE_HOST_R1(r13) |
| 938 | ld r2, PACATOC(r13) |
| 939 | |
| 940 | mfspr r10, SPRN_SRR0 |
| 941 | mfspr r11, SPRN_SRR1 |
| 942 | std r10, VCPU_SRR0(r9) |
| 943 | std r11, VCPU_SRR1(r9) |
| 944 | andi. r0, r12, 2 /* need to read HSRR0/1? */ |
| 945 | beq 1f |
| 946 | mfspr r10, SPRN_HSRR0 |
| 947 | mfspr r11, SPRN_HSRR1 |
| 948 | clrrdi r12, r12, 2 |
| 949 | 1: std r10, VCPU_PC(r9) |
| 950 | std r11, VCPU_MSR(r9) |
| 951 | |
| 952 | GET_SCRATCH0(r3) |
| 953 | mflr r4 |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 954 | std r3, VCPU_GPR(R13)(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 955 | std r4, VCPU_LR(r9) |
| 956 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 957 | stw r12,VCPU_TRAP(r9) |
| 958 | |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 959 | /* Save HEIR (HV emulation assist reg) in last_inst |
| 960 | if this is an HEI (HV emulation interrupt, e40) */ |
| 961 | li r3,KVM_INST_FETCH_FAILED |
| 962 | BEGIN_FTR_SECTION |
| 963 | cmpwi r12,BOOK3S_INTERRUPT_H_EMUL_ASSIST |
| 964 | bne 11f |
| 965 | mfspr r3,SPRN_HEIR |
| 966 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) |
| 967 | 11: stw r3,VCPU_LAST_INST(r9) |
| 968 | |
| 969 | /* these are volatile across C function calls */ |
| 970 | mfctr r3 |
| 971 | mfxer r4 |
| 972 | std r3, VCPU_CTR(r9) |
| 973 | stw r4, VCPU_XER(r9) |
| 974 | |
| 975 | BEGIN_FTR_SECTION |
| 976 | /* If this is a page table miss then see if it's theirs or ours */ |
| 977 | cmpwi r12, BOOK3S_INTERRUPT_H_DATA_STORAGE |
| 978 | beq kvmppc_hdsi |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 979 | cmpwi r12, BOOK3S_INTERRUPT_H_INST_STORAGE |
| 980 | beq kvmppc_hisi |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 981 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) |
| 982 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 983 | /* See if this is a leftover HDEC interrupt */ |
| 984 | cmpwi r12,BOOK3S_INTERRUPT_HV_DECREMENTER |
| 985 | bne 2f |
| 986 | mfspr r3,SPRN_HDEC |
| 987 | cmpwi r3,0 |
| 988 | bge ignore_hdec |
| 989 | 2: |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 990 | /* See if this is an hcall we can handle in real mode */ |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 991 | cmpwi r12,BOOK3S_INTERRUPT_SYSCALL |
| 992 | beq hcall_try_real_mode |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 993 | |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 994 | /* Only handle external interrupts here on arch 206 and later */ |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 995 | BEGIN_FTR_SECTION |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 996 | b ext_interrupt_to_host |
| 997 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_206) |
| 998 | |
| 999 | /* External interrupt ? */ |
| 1000 | cmpwi r12, BOOK3S_INTERRUPT_EXTERNAL |
| 1001 | bne+ ext_interrupt_to_host |
| 1002 | |
| 1003 | /* External interrupt, first check for host_ipi. If this is |
| 1004 | * set, we know the host wants us out so let's do it now |
| 1005 | */ |
Paul Mackerras | c934243 | 2013-09-06 13:24:13 +1000 | [diff] [blame] | 1006 | bl kvmppc_read_intr |
| 1007 | cmpdi r3, 0 |
| 1008 | bgt ext_interrupt_to_host |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 1009 | |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 1010 | /* Check if any CPU is heading out to the host, if so head out too */ |
| 1011 | ld r5, HSTATE_KVM_VCORE(r13) |
| 1012 | lwz r0, VCORE_ENTRY_EXIT(r5) |
| 1013 | cmpwi r0, 0x100 |
| 1014 | bge ext_interrupt_to_host |
| 1015 | |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 1016 | /* Return to guest after delivering any pending interrupt */ |
| 1017 | mr r4, r9 |
| 1018 | b deliver_guest_interrupt |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 1019 | |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 1020 | ext_interrupt_to_host: |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1021 | |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1022 | guest_exit_cont: /* r9 = vcpu, r12 = trap, r13 = paca */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1023 | /* Save more register state */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1024 | mfdar r6 |
| 1025 | mfdsisr r7 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1026 | std r6, VCPU_DAR(r9) |
| 1027 | stw r7, VCPU_DSISR(r9) |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1028 | BEGIN_FTR_SECTION |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1029 | /* don't overwrite fault_dar/fault_dsisr if HDSI */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1030 | cmpwi r12,BOOK3S_INTERRUPT_H_DATA_STORAGE |
| 1031 | beq 6f |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1032 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1033 | std r6, VCPU_FAULT_DAR(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1034 | stw r7, VCPU_FAULT_DSISR(r9) |
| 1035 | |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1036 | /* See if it is a machine check */ |
| 1037 | cmpwi r12, BOOK3S_INTERRUPT_MACHINE_CHECK |
| 1038 | beq machine_check_realmode |
| 1039 | mc_cont: |
| 1040 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1041 | /* Save guest CTRL register, set runlatch to 1 */ |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1042 | 6: mfspr r6,SPRN_CTRLF |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1043 | stw r6,VCPU_CTRL(r9) |
| 1044 | andi. r0,r6,1 |
| 1045 | bne 4f |
| 1046 | ori r6,r6,1 |
| 1047 | mtspr SPRN_CTRLT,r6 |
| 1048 | 4: |
| 1049 | /* Read the guest SLB and save it away */ |
| 1050 | lwz r0,VCPU_SLB_NR(r9) /* number of entries in SLB */ |
| 1051 | mtctr r0 |
| 1052 | li r6,0 |
| 1053 | addi r7,r9,VCPU_SLB |
| 1054 | li r5,0 |
| 1055 | 1: slbmfee r8,r6 |
| 1056 | andis. r0,r8,SLB_ESID_V@h |
| 1057 | beq 2f |
| 1058 | add r8,r8,r6 /* put index in */ |
| 1059 | slbmfev r3,r6 |
| 1060 | std r8,VCPU_SLB_E(r7) |
| 1061 | std r3,VCPU_SLB_V(r7) |
| 1062 | addi r7,r7,VCPU_SLB_SIZE |
| 1063 | addi r5,r5,1 |
| 1064 | 2: addi r6,r6,1 |
| 1065 | bdnz 1b |
| 1066 | stw r5,VCPU_SLB_MAX(r9) |
| 1067 | |
| 1068 | /* |
| 1069 | * Save the guest PURR/SPURR |
| 1070 | */ |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1071 | BEGIN_FTR_SECTION |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1072 | mfspr r5,SPRN_PURR |
| 1073 | mfspr r6,SPRN_SPURR |
| 1074 | ld r7,VCPU_PURR(r9) |
| 1075 | ld r8,VCPU_SPURR(r9) |
| 1076 | std r5,VCPU_PURR(r9) |
| 1077 | std r6,VCPU_SPURR(r9) |
| 1078 | subf r5,r7,r5 |
| 1079 | subf r6,r8,r6 |
| 1080 | |
| 1081 | /* |
| 1082 | * Restore host PURR/SPURR and add guest times |
| 1083 | * so that the time in the guest gets accounted. |
| 1084 | */ |
| 1085 | ld r3,HSTATE_PURR(r13) |
| 1086 | ld r4,HSTATE_SPURR(r13) |
| 1087 | add r3,r3,r5 |
| 1088 | add r4,r4,r6 |
| 1089 | mtspr SPRN_PURR,r3 |
| 1090 | mtspr SPRN_SPURR,r4 |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1091 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_201) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1092 | |
Paul Mackerras | 93b0f4d | 2013-09-06 13:17:46 +1000 | [diff] [blame] | 1093 | /* Save DEC */ |
| 1094 | mfspr r5,SPRN_DEC |
| 1095 | mftb r6 |
| 1096 | extsw r5,r5 |
| 1097 | add r5,r5,r6 |
| 1098 | std r5,VCPU_DEC_EXPIRES(r9) |
| 1099 | |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1100 | BEGIN_FTR_SECTION |
| 1101 | b 8f |
| 1102 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) |
| 1103 | /* Turn on TM so we can access TFHAR/TFIAR/TEXASR */ |
| 1104 | mfmsr r8 |
| 1105 | li r0, 1 |
| 1106 | rldimi r8, r0, MSR_TM_LG, 63-MSR_TM_LG |
| 1107 | mtmsrd r8 |
| 1108 | |
| 1109 | /* Save POWER8-specific registers */ |
| 1110 | mfspr r5, SPRN_IAMR |
| 1111 | mfspr r6, SPRN_PSPB |
| 1112 | mfspr r7, SPRN_FSCR |
| 1113 | std r5, VCPU_IAMR(r9) |
| 1114 | stw r6, VCPU_PSPB(r9) |
| 1115 | std r7, VCPU_FSCR(r9) |
| 1116 | mfspr r5, SPRN_IC |
| 1117 | mfspr r6, SPRN_VTB |
| 1118 | mfspr r7, SPRN_TAR |
| 1119 | std r5, VCPU_IC(r9) |
| 1120 | std r6, VCPU_VTB(r9) |
| 1121 | std r7, VCPU_TAR(r9) |
| 1122 | mfspr r5, SPRN_TFHAR |
| 1123 | mfspr r6, SPRN_TFIAR |
| 1124 | mfspr r7, SPRN_TEXASR |
| 1125 | mfspr r8, SPRN_EBBHR |
| 1126 | std r5, VCPU_TFHAR(r9) |
| 1127 | std r6, VCPU_TFIAR(r9) |
| 1128 | std r7, VCPU_TEXASR(r9) |
| 1129 | std r8, VCPU_EBBHR(r9) |
| 1130 | mfspr r5, SPRN_EBBRR |
| 1131 | mfspr r6, SPRN_BESCR |
| 1132 | mfspr r7, SPRN_CSIGR |
| 1133 | mfspr r8, SPRN_TACR |
| 1134 | std r5, VCPU_EBBRR(r9) |
| 1135 | std r6, VCPU_BESCR(r9) |
| 1136 | std r7, VCPU_CSIGR(r9) |
| 1137 | std r8, VCPU_TACR(r9) |
| 1138 | mfspr r5, SPRN_TCSCR |
| 1139 | mfspr r6, SPRN_ACOP |
| 1140 | mfspr r7, SPRN_PID |
| 1141 | mfspr r8, SPRN_WORT |
| 1142 | std r5, VCPU_TCSCR(r9) |
| 1143 | std r6, VCPU_ACOP(r9) |
| 1144 | stw r7, VCPU_GUEST_PID(r9) |
| 1145 | std r8, VCPU_WORT(r9) |
| 1146 | 8: |
| 1147 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1148 | /* Save and reset AMR and UAMOR before turning on the MMU */ |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1149 | BEGIN_FTR_SECTION |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1150 | mfspr r5,SPRN_AMR |
| 1151 | mfspr r6,SPRN_UAMOR |
| 1152 | std r5,VCPU_AMR(r9) |
| 1153 | std r6,VCPU_UAMOR(r9) |
| 1154 | li r6,0 |
| 1155 | mtspr SPRN_AMR,r6 |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1156 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1157 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1158 | /* Switch DSCR back to host value */ |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1159 | BEGIN_FTR_SECTION |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1160 | mfspr r8, SPRN_DSCR |
| 1161 | ld r7, HSTATE_DSCR(r13) |
Paul Mackerras | cfc8602 | 2013-09-21 09:53:28 +1000 | [diff] [blame] | 1162 | std r8, VCPU_DSCR(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1163 | mtspr SPRN_DSCR, r7 |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1164 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1165 | |
| 1166 | /* Save non-volatile GPRs */ |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1167 | std r14, VCPU_GPR(R14)(r9) |
| 1168 | std r15, VCPU_GPR(R15)(r9) |
| 1169 | std r16, VCPU_GPR(R16)(r9) |
| 1170 | std r17, VCPU_GPR(R17)(r9) |
| 1171 | std r18, VCPU_GPR(R18)(r9) |
| 1172 | std r19, VCPU_GPR(R19)(r9) |
| 1173 | std r20, VCPU_GPR(R20)(r9) |
| 1174 | std r21, VCPU_GPR(R21)(r9) |
| 1175 | std r22, VCPU_GPR(R22)(r9) |
| 1176 | std r23, VCPU_GPR(R23)(r9) |
| 1177 | std r24, VCPU_GPR(R24)(r9) |
| 1178 | std r25, VCPU_GPR(R25)(r9) |
| 1179 | std r26, VCPU_GPR(R26)(r9) |
| 1180 | std r27, VCPU_GPR(R27)(r9) |
| 1181 | std r28, VCPU_GPR(R28)(r9) |
| 1182 | std r29, VCPU_GPR(R29)(r9) |
| 1183 | std r30, VCPU_GPR(R30)(r9) |
| 1184 | std r31, VCPU_GPR(R31)(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1185 | |
| 1186 | /* Save SPRGs */ |
| 1187 | mfspr r3, SPRN_SPRG0 |
| 1188 | mfspr r4, SPRN_SPRG1 |
| 1189 | mfspr r5, SPRN_SPRG2 |
| 1190 | mfspr r6, SPRN_SPRG3 |
| 1191 | std r3, VCPU_SPRG0(r9) |
| 1192 | std r4, VCPU_SPRG1(r9) |
| 1193 | std r5, VCPU_SPRG2(r9) |
| 1194 | std r6, VCPU_SPRG3(r9) |
| 1195 | |
Paul Mackerras | 8943633 | 2012-03-02 01:38:23 +0000 | [diff] [blame] | 1196 | /* save FP state */ |
| 1197 | mr r3, r9 |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 1198 | bl kvmppc_save_fp |
Paul Mackerras | 8943633 | 2012-03-02 01:38:23 +0000 | [diff] [blame] | 1199 | |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1200 | /* Increment yield count if they have a VPA */ |
| 1201 | ld r8, VCPU_VPA(r9) /* do they have a VPA? */ |
| 1202 | cmpdi r8, 0 |
| 1203 | beq 25f |
| 1204 | lwz r3, LPPACA_YIELDCOUNT(r8) |
| 1205 | addi r3, r3, 1 |
| 1206 | stw r3, LPPACA_YIELDCOUNT(r8) |
Paul Mackerras | c35635e | 2013-04-18 19:51:04 +0000 | [diff] [blame] | 1207 | li r3, 1 |
| 1208 | stb r3, VCPU_VPA_DIRTY(r9) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1209 | 25: |
| 1210 | /* Save PMU registers if requested */ |
| 1211 | /* r8 and cr0.eq are live here */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1212 | li r3, 1 |
| 1213 | sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */ |
| 1214 | mfspr r4, SPRN_MMCR0 /* save MMCR0 */ |
| 1215 | mtspr SPRN_MMCR0, r3 /* freeze all counters, disable ints */ |
Paul Mackerras | 8943633 | 2012-03-02 01:38:23 +0000 | [diff] [blame] | 1216 | mfspr r6, SPRN_MMCRA |
| 1217 | BEGIN_FTR_SECTION |
| 1218 | /* On P7, clear MMCRA in order to disable SDAR updates */ |
| 1219 | li r7, 0 |
| 1220 | mtspr SPRN_MMCRA, r7 |
| 1221 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1222 | isync |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1223 | beq 21f /* if no VPA, save PMU stuff anyway */ |
| 1224 | lbz r7, LPPACA_PMCINUSE(r8) |
| 1225 | cmpwi r7, 0 /* did they ask for PMU stuff to be saved? */ |
| 1226 | bne 21f |
| 1227 | std r3, VCPU_MMCR(r9) /* if not, set saved MMCR0 to FC */ |
| 1228 | b 22f |
| 1229 | 21: mfspr r5, SPRN_MMCR1 |
Paul Mackerras | 1494178 | 2013-09-06 13:11:18 +1000 | [diff] [blame] | 1230 | mfspr r7, SPRN_SIAR |
| 1231 | mfspr r8, SPRN_SDAR |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1232 | std r4, VCPU_MMCR(r9) |
| 1233 | std r5, VCPU_MMCR + 8(r9) |
| 1234 | std r6, VCPU_MMCR + 16(r9) |
Paul Mackerras | 1494178 | 2013-09-06 13:11:18 +1000 | [diff] [blame] | 1235 | std r7, VCPU_SIAR(r9) |
| 1236 | std r8, VCPU_SDAR(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1237 | mfspr r3, SPRN_PMC1 |
| 1238 | mfspr r4, SPRN_PMC2 |
| 1239 | mfspr r5, SPRN_PMC3 |
| 1240 | mfspr r6, SPRN_PMC4 |
| 1241 | mfspr r7, SPRN_PMC5 |
| 1242 | mfspr r8, SPRN_PMC6 |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1243 | BEGIN_FTR_SECTION |
| 1244 | mfspr r10, SPRN_PMC7 |
| 1245 | mfspr r11, SPRN_PMC8 |
| 1246 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1247 | stw r3, VCPU_PMC(r9) |
| 1248 | stw r4, VCPU_PMC + 4(r9) |
| 1249 | stw r5, VCPU_PMC + 8(r9) |
| 1250 | stw r6, VCPU_PMC + 12(r9) |
| 1251 | stw r7, VCPU_PMC + 16(r9) |
| 1252 | stw r8, VCPU_PMC + 20(r9) |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1253 | BEGIN_FTR_SECTION |
| 1254 | stw r10, VCPU_PMC + 24(r9) |
| 1255 | stw r11, VCPU_PMC + 28(r9) |
| 1256 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1257 | BEGIN_FTR_SECTION |
| 1258 | mfspr r4, SPRN_MMCR2 |
| 1259 | mfspr r5, SPRN_SIER |
| 1260 | mfspr r6, SPRN_SPMC1 |
| 1261 | mfspr r7, SPRN_SPMC2 |
| 1262 | mfspr r8, SPRN_MMCRS |
| 1263 | std r4, VCPU_MMCR + 24(r9) |
| 1264 | std r5, VCPU_SIER(r9) |
| 1265 | stw r6, VCPU_PMC + 24(r9) |
| 1266 | stw r7, VCPU_PMC + 28(r9) |
| 1267 | std r8, VCPU_MMCR + 32(r9) |
| 1268 | lis r4, 0x8000 |
| 1269 | mtspr SPRN_MMCRS, r4 |
| 1270 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1271 | 22: |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1272 | /* Clear out SLB */ |
| 1273 | li r5,0 |
| 1274 | slbmte r5,r5 |
| 1275 | slbia |
| 1276 | ptesync |
| 1277 | |
| 1278 | hdec_soon: /* r12 = trap, r13 = paca */ |
| 1279 | BEGIN_FTR_SECTION |
| 1280 | b 32f |
| 1281 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) |
| 1282 | /* |
| 1283 | * POWER7 guest -> host partition switch code. |
| 1284 | * We don't have to lock against tlbies but we do |
| 1285 | * have to coordinate the hardware threads. |
| 1286 | */ |
| 1287 | /* Increment the threads-exiting-guest count in the 0xff00 |
| 1288 | bits of vcore->entry_exit_count */ |
| 1289 | lwsync |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 1290 | ld r5,HSTATE_KVM_VCORE(r13) |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1291 | addi r6,r5,VCORE_ENTRY_EXIT |
| 1292 | 41: lwarx r3,0,r6 |
| 1293 | addi r0,r3,0x100 |
| 1294 | stwcx. r0,0,r6 |
| 1295 | bne 41b |
| 1296 | lwsync |
| 1297 | |
| 1298 | /* |
| 1299 | * At this point we have an interrupt that we have to pass |
| 1300 | * up to the kernel or qemu; we can't handle it in real mode. |
| 1301 | * Thus we have to do a partition switch, so we have to |
| 1302 | * collect the other threads, if we are the first thread |
| 1303 | * to take an interrupt. To do this, we set the HDEC to 0, |
| 1304 | * which causes an HDEC interrupt in all threads within 2ns |
| 1305 | * because the HDEC register is shared between all 4 threads. |
| 1306 | * However, we don't need to bother if this is an HDEC |
| 1307 | * interrupt, since the other threads will already be on their |
| 1308 | * way here in that case. |
| 1309 | */ |
| 1310 | cmpwi r3,0x100 /* Are we the first here? */ |
| 1311 | bge 43f |
| 1312 | cmpwi r12,BOOK3S_INTERRUPT_HV_DECREMENTER |
| 1313 | beq 40f |
| 1314 | li r0,0 |
| 1315 | mtspr SPRN_HDEC,r0 |
| 1316 | 40: |
| 1317 | /* |
| 1318 | * Send an IPI to any napping threads, since an HDEC interrupt |
| 1319 | * doesn't wake CPUs up from nap. |
| 1320 | */ |
| 1321 | lwz r3,VCORE_NAPPING_THREADS(r5) |
| 1322 | lbz r4,HSTATE_PTID(r13) |
| 1323 | li r0,1 |
| 1324 | sld r0,r0,r4 |
| 1325 | andc. r3,r3,r0 /* no sense IPI'ing ourselves */ |
| 1326 | beq 43f |
| 1327 | mulli r4,r4,PACA_SIZE /* get paca for thread 0 */ |
| 1328 | subf r6,r4,r13 |
| 1329 | 42: andi. r0,r3,1 |
| 1330 | beq 44f |
| 1331 | ld r8,HSTATE_XICS_PHYS(r6) /* get thread's XICS reg addr */ |
| 1332 | li r0,IPI_PRIORITY |
| 1333 | li r7,XICS_MFRR |
| 1334 | stbcix r0,r7,r8 /* trigger the IPI */ |
| 1335 | 44: srdi. r3,r3,1 |
| 1336 | addi r6,r6,PACA_SIZE |
| 1337 | bne 42b |
| 1338 | |
| 1339 | secondary_too_late: |
| 1340 | /* Secondary threads wait for primary to do partition switch */ |
| 1341 | 43: ld r5,HSTATE_KVM_VCORE(r13) |
| 1342 | ld r4,VCORE_KVM(r5) /* pointer to struct kvm */ |
| 1343 | lbz r3,HSTATE_PTID(r13) |
| 1344 | cmpwi r3,0 |
| 1345 | beq 15f |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 1346 | HMT_LOW |
| 1347 | 13: lbz r3,VCORE_IN_GUEST(r5) |
| 1348 | cmpwi r3,0 |
| 1349 | bne 13b |
| 1350 | HMT_MEDIUM |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1351 | b 16f |
| 1352 | |
| 1353 | /* Primary thread waits for all the secondaries to exit guest */ |
| 1354 | 15: lwz r3,VCORE_ENTRY_EXIT(r5) |
| 1355 | srwi r0,r3,8 |
| 1356 | clrldi r3,r3,56 |
| 1357 | cmpw r3,r0 |
| 1358 | bne 15b |
| 1359 | isync |
| 1360 | |
| 1361 | /* Primary thread switches back to host partition */ |
| 1362 | ld r6,KVM_HOST_SDR1(r4) |
| 1363 | lwz r7,KVM_HOST_LPID(r4) |
| 1364 | li r8,LPID_RSVD /* switch to reserved LPID */ |
| 1365 | mtspr SPRN_LPID,r8 |
| 1366 | ptesync |
| 1367 | mtspr SPRN_SDR1,r6 /* switch to partition page table */ |
| 1368 | mtspr SPRN_LPID,r7 |
| 1369 | isync |
| 1370 | |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1371 | BEGIN_FTR_SECTION |
| 1372 | /* DPDES is shared between threads */ |
| 1373 | mfspr r7, SPRN_DPDES |
| 1374 | std r7, VCORE_DPDES(r5) |
| 1375 | /* clear DPDES so we don't get guest doorbells in the host */ |
| 1376 | li r8, 0 |
| 1377 | mtspr SPRN_DPDES, r8 |
| 1378 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
| 1379 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1380 | /* Subtract timebase offset from timebase */ |
| 1381 | ld r8,VCORE_TB_OFFSET(r5) |
| 1382 | cmpdi r8,0 |
| 1383 | beq 17f |
| 1384 | mftb r6 /* current host timebase */ |
| 1385 | subf r8,r8,r6 |
| 1386 | mtspr SPRN_TBU40,r8 /* update upper 40 bits */ |
| 1387 | mftb r7 /* check if lower 24 bits overflowed */ |
| 1388 | clrldi r6,r6,40 |
| 1389 | clrldi r7,r7,40 |
| 1390 | cmpld r7,r6 |
| 1391 | bge 17f |
| 1392 | addis r8,r8,0x100 /* if so, increment upper 40 bits */ |
| 1393 | mtspr SPRN_TBU40,r8 |
| 1394 | |
| 1395 | /* Reset PCR */ |
| 1396 | 17: ld r0, VCORE_PCR(r5) |
| 1397 | cmpdi r0, 0 |
| 1398 | beq 18f |
| 1399 | li r0, 0 |
| 1400 | mtspr SPRN_PCR, r0 |
| 1401 | 18: |
| 1402 | /* Signal secondary CPUs to continue */ |
| 1403 | stb r0,VCORE_IN_GUEST(r5) |
| 1404 | lis r8,0x7fff /* MAX_INT@h */ |
| 1405 | mtspr SPRN_HDEC,r8 |
| 1406 | |
| 1407 | 16: ld r8,KVM_HOST_LPCR(r4) |
| 1408 | mtspr SPRN_LPCR,r8 |
| 1409 | isync |
| 1410 | b 33f |
| 1411 | |
| 1412 | /* |
| 1413 | * PPC970 guest -> host partition switch code. |
| 1414 | * We have to lock against concurrent tlbies, and |
| 1415 | * we have to flush the whole TLB. |
| 1416 | */ |
| 1417 | 32: ld r5,HSTATE_KVM_VCORE(r13) |
| 1418 | ld r4,VCORE_KVM(r5) /* pointer to struct kvm */ |
| 1419 | |
| 1420 | /* Take the guest's tlbie_lock */ |
| 1421 | #ifdef __BIG_ENDIAN__ |
| 1422 | lwz r8,PACA_LOCK_TOKEN(r13) |
| 1423 | #else |
| 1424 | lwz r8,PACAPACAINDEX(r13) |
| 1425 | #endif |
| 1426 | addi r3,r4,KVM_TLBIE_LOCK |
| 1427 | 24: lwarx r0,0,r3 |
| 1428 | cmpwi r0,0 |
| 1429 | bne 24b |
| 1430 | stwcx. r8,0,r3 |
| 1431 | bne 24b |
| 1432 | isync |
| 1433 | |
| 1434 | ld r7,KVM_HOST_LPCR(r4) /* use kvm->arch.host_lpcr for HID4 */ |
| 1435 | li r0,0x18f |
| 1436 | rotldi r0,r0,HID4_LPID5_SH /* all lpid bits in HID4 = 1 */ |
| 1437 | or r0,r7,r0 |
| 1438 | ptesync |
| 1439 | sync |
| 1440 | mtspr SPRN_HID4,r0 /* switch to reserved LPID */ |
| 1441 | isync |
| 1442 | li r0,0 |
| 1443 | stw r0,0(r3) /* drop guest tlbie_lock */ |
| 1444 | |
| 1445 | /* invalidate the whole TLB */ |
| 1446 | li r0,256 |
| 1447 | mtctr r0 |
| 1448 | li r6,0 |
| 1449 | 25: tlbiel r6 |
| 1450 | addi r6,r6,0x1000 |
| 1451 | bdnz 25b |
| 1452 | ptesync |
| 1453 | |
| 1454 | /* take native_tlbie_lock */ |
| 1455 | ld r3,toc_tlbie_lock@toc(2) |
| 1456 | 24: lwarx r0,0,r3 |
| 1457 | cmpwi r0,0 |
| 1458 | bne 24b |
| 1459 | stwcx. r8,0,r3 |
| 1460 | bne 24b |
| 1461 | isync |
| 1462 | |
| 1463 | ld r6,KVM_HOST_SDR1(r4) |
| 1464 | mtspr SPRN_SDR1,r6 /* switch to host page table */ |
| 1465 | |
| 1466 | /* Set up host HID4 value */ |
| 1467 | sync |
| 1468 | mtspr SPRN_HID4,r7 |
| 1469 | isync |
| 1470 | li r0,0 |
| 1471 | stw r0,0(r3) /* drop native_tlbie_lock */ |
| 1472 | |
| 1473 | lis r8,0x7fff /* MAX_INT@h */ |
| 1474 | mtspr SPRN_HDEC,r8 |
| 1475 | |
| 1476 | /* Disable HDEC interrupts */ |
| 1477 | mfspr r0,SPRN_HID0 |
| 1478 | li r3,0 |
| 1479 | rldimi r0,r3, HID0_HDICE_SH, 64-HID0_HDICE_SH-1 |
| 1480 | sync |
| 1481 | mtspr SPRN_HID0,r0 |
| 1482 | mfspr r0,SPRN_HID0 |
| 1483 | mfspr r0,SPRN_HID0 |
| 1484 | mfspr r0,SPRN_HID0 |
| 1485 | mfspr r0,SPRN_HID0 |
| 1486 | mfspr r0,SPRN_HID0 |
| 1487 | mfspr r0,SPRN_HID0 |
| 1488 | |
| 1489 | /* load host SLB entries */ |
| 1490 | 33: ld r8,PACA_SLBSHADOWPTR(r13) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1491 | |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 1492 | .rept SLB_NUM_BOLTED |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1493 | ld r5,SLBSHADOW_SAVEAREA(r8) |
| 1494 | ld r6,SLBSHADOW_SAVEAREA+8(r8) |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 1495 | andis. r7,r5,SLB_ESID_V@h |
| 1496 | beq 1f |
| 1497 | slbmte r6,r5 |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1498 | 1: addi r8,r8,16 |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 1499 | .endr |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1500 | |
| 1501 | /* Unset guest mode */ |
| 1502 | li r0, KVM_GUEST_MODE_NONE |
| 1503 | stb r0, HSTATE_IN_GUEST(r13) |
| 1504 | |
| 1505 | ld r0, 112+PPC_LR_STKOFF(r1) |
| 1506 | addi r1, r1, 112 |
| 1507 | mtlr r0 |
| 1508 | blr |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1509 | |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1510 | /* |
| 1511 | * Check whether an HDSI is an HPTE not found fault or something else. |
| 1512 | * If it is an HPTE not found fault that is due to the guest accessing |
| 1513 | * a page that they have mapped but which we have paged out, then |
| 1514 | * we continue on with the guest exit path. In all other cases, |
| 1515 | * reflect the HDSI to the guest as a DSI. |
| 1516 | */ |
| 1517 | kvmppc_hdsi: |
| 1518 | mfspr r4, SPRN_HDAR |
| 1519 | mfspr r6, SPRN_HDSISR |
Paul Mackerras | 4cf302b | 2011-12-12 12:38:51 +0000 | [diff] [blame] | 1520 | /* HPTE not found fault or protection fault? */ |
| 1521 | andis. r0, r6, (DSISR_NOHPTE | DSISR_PROTFAULT)@h |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1522 | beq 1f /* if not, send it to the guest */ |
| 1523 | andi. r0, r11, MSR_DR /* data relocation enabled? */ |
| 1524 | beq 3f |
| 1525 | clrrdi r0, r4, 28 |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1526 | PPC_SLBFEE_DOT(R5, R0) /* if so, look up SLB */ |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1527 | bne 1f /* if no SLB entry found */ |
| 1528 | 4: std r4, VCPU_FAULT_DAR(r9) |
| 1529 | stw r6, VCPU_FAULT_DSISR(r9) |
| 1530 | |
| 1531 | /* Search the hash table. */ |
| 1532 | mr r3, r9 /* vcpu pointer */ |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1533 | li r7, 1 /* data fault */ |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1534 | bl .kvmppc_hpte_hv_fault |
| 1535 | ld r9, HSTATE_KVM_VCPU(r13) |
| 1536 | ld r10, VCPU_PC(r9) |
| 1537 | ld r11, VCPU_MSR(r9) |
| 1538 | li r12, BOOK3S_INTERRUPT_H_DATA_STORAGE |
| 1539 | cmpdi r3, 0 /* retry the instruction */ |
| 1540 | beq 6f |
| 1541 | cmpdi r3, -1 /* handle in kernel mode */ |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1542 | beq guest_exit_cont |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1543 | cmpdi r3, -2 /* MMIO emulation; need instr word */ |
| 1544 | beq 2f |
| 1545 | |
| 1546 | /* Synthesize a DSI for the guest */ |
| 1547 | ld r4, VCPU_FAULT_DAR(r9) |
| 1548 | mr r6, r3 |
| 1549 | 1: mtspr SPRN_DAR, r4 |
| 1550 | mtspr SPRN_DSISR, r6 |
| 1551 | mtspr SPRN_SRR0, r10 |
| 1552 | mtspr SPRN_SRR1, r11 |
| 1553 | li r10, BOOK3S_INTERRUPT_DATA_STORAGE |
| 1554 | li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */ |
| 1555 | rotldi r11, r11, 63 |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1556 | fast_interrupt_c_return: |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1557 | 6: ld r7, VCPU_CTR(r9) |
| 1558 | lwz r8, VCPU_XER(r9) |
| 1559 | mtctr r7 |
| 1560 | mtxer r8 |
| 1561 | mr r4, r9 |
| 1562 | b fast_guest_return |
| 1563 | |
| 1564 | 3: ld r5, VCPU_KVM(r9) /* not relocated, use VRMA */ |
| 1565 | ld r5, KVM_VRMA_SLB_V(r5) |
| 1566 | b 4b |
| 1567 | |
| 1568 | /* If this is for emulated MMIO, load the instruction word */ |
| 1569 | 2: li r8, KVM_INST_FETCH_FAILED /* In case lwz faults */ |
| 1570 | |
| 1571 | /* Set guest mode to 'jump over instruction' so if lwz faults |
| 1572 | * we'll just continue at the next IP. */ |
| 1573 | li r0, KVM_GUEST_MODE_SKIP |
| 1574 | stb r0, HSTATE_IN_GUEST(r13) |
| 1575 | |
| 1576 | /* Do the access with MSR:DR enabled */ |
| 1577 | mfmsr r3 |
| 1578 | ori r4, r3, MSR_DR /* Enable paging for data */ |
| 1579 | mtmsrd r4 |
| 1580 | lwz r8, 0(r10) |
| 1581 | mtmsrd r3 |
| 1582 | |
| 1583 | /* Store the result */ |
| 1584 | stw r8, VCPU_LAST_INST(r9) |
| 1585 | |
| 1586 | /* Unset guest mode. */ |
Paul Mackerras | 44a3add | 2013-10-04 21:45:04 +1000 | [diff] [blame] | 1587 | li r0, KVM_GUEST_MODE_HOST_HV |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1588 | stb r0, HSTATE_IN_GUEST(r13) |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1589 | b guest_exit_cont |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1590 | |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1591 | /* |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1592 | * Similarly for an HISI, reflect it to the guest as an ISI unless |
| 1593 | * it is an HPTE not found fault for a page that we have paged out. |
| 1594 | */ |
| 1595 | kvmppc_hisi: |
| 1596 | andis. r0, r11, SRR1_ISI_NOPT@h |
| 1597 | beq 1f |
| 1598 | andi. r0, r11, MSR_IR /* instruction relocation enabled? */ |
| 1599 | beq 3f |
| 1600 | clrrdi r0, r10, 28 |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1601 | PPC_SLBFEE_DOT(R5, R0) /* if so, look up SLB */ |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1602 | bne 1f /* if no SLB entry found */ |
| 1603 | 4: |
| 1604 | /* Search the hash table. */ |
| 1605 | mr r3, r9 /* vcpu pointer */ |
| 1606 | mr r4, r10 |
| 1607 | mr r6, r11 |
| 1608 | li r7, 0 /* instruction fault */ |
| 1609 | bl .kvmppc_hpte_hv_fault |
| 1610 | ld r9, HSTATE_KVM_VCPU(r13) |
| 1611 | ld r10, VCPU_PC(r9) |
| 1612 | ld r11, VCPU_MSR(r9) |
| 1613 | li r12, BOOK3S_INTERRUPT_H_INST_STORAGE |
| 1614 | cmpdi r3, 0 /* retry the instruction */ |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1615 | beq fast_interrupt_c_return |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1616 | cmpdi r3, -1 /* handle in kernel mode */ |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1617 | beq guest_exit_cont |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1618 | |
| 1619 | /* Synthesize an ISI for the guest */ |
| 1620 | mr r11, r3 |
| 1621 | 1: mtspr SPRN_SRR0, r10 |
| 1622 | mtspr SPRN_SRR1, r11 |
| 1623 | li r10, BOOK3S_INTERRUPT_INST_STORAGE |
| 1624 | li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */ |
| 1625 | rotldi r11, r11, 63 |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1626 | b fast_interrupt_c_return |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1627 | |
| 1628 | 3: ld r6, VCPU_KVM(r9) /* not relocated, use VRMA */ |
| 1629 | ld r5, KVM_VRMA_SLB_V(r6) |
| 1630 | b 4b |
| 1631 | |
| 1632 | /* |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1633 | * Try to handle an hcall in real mode. |
| 1634 | * Returns to the guest if we handle it, or continues on up to |
| 1635 | * the kernel if we can't (i.e. if we don't have a handler for |
| 1636 | * it, or if the handler returns H_TOO_HARD). |
| 1637 | */ |
| 1638 | .globl hcall_try_real_mode |
| 1639 | hcall_try_real_mode: |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1640 | ld r3,VCPU_GPR(R3)(r9) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1641 | andi. r0,r11,MSR_PR |
Liu Ping Fan | 27025a6 | 2013-11-19 14:12:48 +0800 | [diff] [blame] | 1642 | /* sc 1 from userspace - reflect to guest syscall */ |
| 1643 | bne sc_1_fast_return |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1644 | clrrdi r3,r3,2 |
| 1645 | cmpldi r3,hcall_real_table_end - hcall_real_table |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1646 | bge guest_exit_cont |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1647 | LOAD_REG_ADDR(r4, hcall_real_table) |
Paul Mackerras | 4baa1d8 | 2013-07-08 20:09:53 +1000 | [diff] [blame] | 1648 | lwax r3,r3,r4 |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1649 | cmpwi r3,0 |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1650 | beq guest_exit_cont |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1651 | add r3,r3,r4 |
| 1652 | mtctr r3 |
| 1653 | mr r3,r9 /* get vcpu pointer */ |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1654 | ld r4,VCPU_GPR(R4)(r9) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1655 | bctrl |
| 1656 | cmpdi r3,H_TOO_HARD |
| 1657 | beq hcall_real_fallback |
| 1658 | ld r4,HSTATE_KVM_VCPU(r13) |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1659 | std r3,VCPU_GPR(R3)(r4) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1660 | ld r10,VCPU_PC(r4) |
| 1661 | ld r11,VCPU_MSR(r4) |
| 1662 | b fast_guest_return |
| 1663 | |
Liu Ping Fan | 27025a6 | 2013-11-19 14:12:48 +0800 | [diff] [blame] | 1664 | sc_1_fast_return: |
| 1665 | mtspr SPRN_SRR0,r10 |
| 1666 | mtspr SPRN_SRR1,r11 |
| 1667 | li r10, BOOK3S_INTERRUPT_SYSCALL |
| 1668 | li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */ |
| 1669 | rotldi r11, r11, 63 |
| 1670 | mr r4,r9 |
| 1671 | b fast_guest_return |
| 1672 | |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1673 | /* We've attempted a real mode hcall, but it's punted it back |
| 1674 | * to userspace. We need to restore some clobbered volatiles |
| 1675 | * before resuming the pass-it-to-qemu path */ |
| 1676 | hcall_real_fallback: |
| 1677 | li r12,BOOK3S_INTERRUPT_SYSCALL |
| 1678 | ld r9, HSTATE_KVM_VCPU(r13) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1679 | |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1680 | b guest_exit_cont |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1681 | |
| 1682 | .globl hcall_real_table |
| 1683 | hcall_real_table: |
| 1684 | .long 0 /* 0 - unused */ |
| 1685 | .long .kvmppc_h_remove - hcall_real_table |
| 1686 | .long .kvmppc_h_enter - hcall_real_table |
| 1687 | .long .kvmppc_h_read - hcall_real_table |
| 1688 | .long 0 /* 0x10 - H_CLEAR_MOD */ |
| 1689 | .long 0 /* 0x14 - H_CLEAR_REF */ |
| 1690 | .long .kvmppc_h_protect - hcall_real_table |
| 1691 | .long 0 /* 0x1c - H_GET_TCE */ |
David Gibson | 54738c0 | 2011-06-29 00:22:41 +0000 | [diff] [blame] | 1692 | .long .kvmppc_h_put_tce - hcall_real_table |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1693 | .long 0 /* 0x24 - H_SET_SPRG0 */ |
| 1694 | .long .kvmppc_h_set_dabr - hcall_real_table |
| 1695 | .long 0 /* 0x2c */ |
| 1696 | .long 0 /* 0x30 */ |
| 1697 | .long 0 /* 0x34 */ |
| 1698 | .long 0 /* 0x38 */ |
| 1699 | .long 0 /* 0x3c */ |
| 1700 | .long 0 /* 0x40 */ |
| 1701 | .long 0 /* 0x44 */ |
| 1702 | .long 0 /* 0x48 */ |
| 1703 | .long 0 /* 0x4c */ |
| 1704 | .long 0 /* 0x50 */ |
| 1705 | .long 0 /* 0x54 */ |
| 1706 | .long 0 /* 0x58 */ |
| 1707 | .long 0 /* 0x5c */ |
| 1708 | .long 0 /* 0x60 */ |
Benjamin Herrenschmidt | e7d26f2 | 2013-04-17 20:31:15 +0000 | [diff] [blame] | 1709 | #ifdef CONFIG_KVM_XICS |
| 1710 | .long .kvmppc_rm_h_eoi - hcall_real_table |
| 1711 | .long .kvmppc_rm_h_cppr - hcall_real_table |
| 1712 | .long .kvmppc_rm_h_ipi - hcall_real_table |
| 1713 | .long 0 /* 0x70 - H_IPOLL */ |
| 1714 | .long .kvmppc_rm_h_xirr - hcall_real_table |
| 1715 | #else |
| 1716 | .long 0 /* 0x64 - H_EOI */ |
| 1717 | .long 0 /* 0x68 - H_CPPR */ |
| 1718 | .long 0 /* 0x6c - H_IPI */ |
| 1719 | .long 0 /* 0x70 - H_IPOLL */ |
| 1720 | .long 0 /* 0x74 - H_XIRR */ |
| 1721 | #endif |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1722 | .long 0 /* 0x78 */ |
| 1723 | .long 0 /* 0x7c */ |
| 1724 | .long 0 /* 0x80 */ |
| 1725 | .long 0 /* 0x84 */ |
| 1726 | .long 0 /* 0x88 */ |
| 1727 | .long 0 /* 0x8c */ |
| 1728 | .long 0 /* 0x90 */ |
| 1729 | .long 0 /* 0x94 */ |
| 1730 | .long 0 /* 0x98 */ |
| 1731 | .long 0 /* 0x9c */ |
| 1732 | .long 0 /* 0xa0 */ |
| 1733 | .long 0 /* 0xa4 */ |
| 1734 | .long 0 /* 0xa8 */ |
| 1735 | .long 0 /* 0xac */ |
| 1736 | .long 0 /* 0xb0 */ |
| 1737 | .long 0 /* 0xb4 */ |
| 1738 | .long 0 /* 0xb8 */ |
| 1739 | .long 0 /* 0xbc */ |
| 1740 | .long 0 /* 0xc0 */ |
| 1741 | .long 0 /* 0xc4 */ |
| 1742 | .long 0 /* 0xc8 */ |
| 1743 | .long 0 /* 0xcc */ |
| 1744 | .long 0 /* 0xd0 */ |
| 1745 | .long 0 /* 0xd4 */ |
| 1746 | .long 0 /* 0xd8 */ |
| 1747 | .long 0 /* 0xdc */ |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1748 | .long .kvmppc_h_cede - hcall_real_table |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1749 | .long 0 /* 0xe4 */ |
| 1750 | .long 0 /* 0xe8 */ |
| 1751 | .long 0 /* 0xec */ |
| 1752 | .long 0 /* 0xf0 */ |
| 1753 | .long 0 /* 0xf4 */ |
| 1754 | .long 0 /* 0xf8 */ |
| 1755 | .long 0 /* 0xfc */ |
| 1756 | .long 0 /* 0x100 */ |
| 1757 | .long 0 /* 0x104 */ |
| 1758 | .long 0 /* 0x108 */ |
| 1759 | .long 0 /* 0x10c */ |
| 1760 | .long 0 /* 0x110 */ |
| 1761 | .long 0 /* 0x114 */ |
| 1762 | .long 0 /* 0x118 */ |
| 1763 | .long 0 /* 0x11c */ |
| 1764 | .long 0 /* 0x120 */ |
| 1765 | .long .kvmppc_h_bulk_remove - hcall_real_table |
| 1766 | hcall_real_table_end: |
| 1767 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1768 | ignore_hdec: |
| 1769 | mr r4,r9 |
| 1770 | b fast_guest_return |
| 1771 | |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1772 | _GLOBAL(kvmppc_h_set_dabr) |
Michael Neuling | eee7ff9 | 2014-01-08 21:25:19 +1100 | [diff] [blame] | 1773 | BEGIN_FTR_SECTION |
| 1774 | b 2f |
| 1775 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1776 | std r4,VCPU_DABR(r3) |
Paul Mackerras | 8943633 | 2012-03-02 01:38:23 +0000 | [diff] [blame] | 1777 | /* Work around P7 bug where DABR can get corrupted on mtspr */ |
| 1778 | 1: mtspr SPRN_DABR,r4 |
| 1779 | mfspr r5, SPRN_DABR |
| 1780 | cmpd r4, r5 |
| 1781 | bne 1b |
| 1782 | isync |
Michael Neuling | eee7ff9 | 2014-01-08 21:25:19 +1100 | [diff] [blame] | 1783 | 2: li r3,0 |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1784 | blr |
| 1785 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1786 | _GLOBAL(kvmppc_h_cede) |
| 1787 | ori r11,r11,MSR_EE |
| 1788 | std r11,VCPU_MSR(r3) |
| 1789 | li r0,1 |
| 1790 | stb r0,VCPU_CEDED(r3) |
| 1791 | sync /* order setting ceded vs. testing prodded */ |
| 1792 | lbz r5,VCPU_PRODDED(r3) |
| 1793 | cmpwi r5,0 |
Paul Mackerras | 04f995a | 2012-08-06 00:03:28 +0000 | [diff] [blame] | 1794 | bne kvm_cede_prodded |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1795 | li r0,0 /* set trap to 0 to say hcall is handled */ |
| 1796 | stw r0,VCPU_TRAP(r3) |
| 1797 | li r0,H_SUCCESS |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1798 | std r0,VCPU_GPR(R3)(r3) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1799 | BEGIN_FTR_SECTION |
Paul Mackerras | 04f995a | 2012-08-06 00:03:28 +0000 | [diff] [blame] | 1800 | b kvm_cede_exit /* just send it up to host on 970 */ |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1801 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_206) |
| 1802 | |
| 1803 | /* |
| 1804 | * Set our bit in the bitmask of napping threads unless all the |
| 1805 | * other threads are already napping, in which case we send this |
| 1806 | * up to the host. |
| 1807 | */ |
| 1808 | ld r5,HSTATE_KVM_VCORE(r13) |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1809 | lbz r6,HSTATE_PTID(r13) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1810 | lwz r8,VCORE_ENTRY_EXIT(r5) |
| 1811 | clrldi r8,r8,56 |
| 1812 | li r0,1 |
| 1813 | sld r0,r0,r6 |
| 1814 | addi r6,r5,VCORE_NAPPING_THREADS |
| 1815 | 31: lwarx r4,0,r6 |
| 1816 | or r4,r4,r0 |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1817 | PPC_POPCNTW(R7,R4) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1818 | cmpw r7,r8 |
Paul Mackerras | 04f995a | 2012-08-06 00:03:28 +0000 | [diff] [blame] | 1819 | bge kvm_cede_exit |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1820 | stwcx. r4,0,r6 |
| 1821 | bne 31b |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1822 | li r0,NAPPING_CEDE |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1823 | stb r0,HSTATE_NAPPING(r13) |
| 1824 | /* order napping_threads update vs testing entry_exit_count */ |
| 1825 | lwsync |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1826 | lwz r7,VCORE_ENTRY_EXIT(r5) |
| 1827 | cmpwi r7,0x100 |
| 1828 | bge 33f /* another thread already exiting */ |
| 1829 | |
| 1830 | /* |
| 1831 | * Although not specifically required by the architecture, POWER7 |
| 1832 | * preserves the following registers in nap mode, even if an SMT mode |
| 1833 | * switch occurs: SLB entries, PURR, SPURR, AMOR, UAMOR, AMR, SPRG0-3, |
| 1834 | * DAR, DSISR, DABR, DABRX, DSCR, PMCx, MMCRx, SIAR, SDAR. |
| 1835 | */ |
| 1836 | /* Save non-volatile GPRs */ |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1837 | std r14, VCPU_GPR(R14)(r3) |
| 1838 | std r15, VCPU_GPR(R15)(r3) |
| 1839 | std r16, VCPU_GPR(R16)(r3) |
| 1840 | std r17, VCPU_GPR(R17)(r3) |
| 1841 | std r18, VCPU_GPR(R18)(r3) |
| 1842 | std r19, VCPU_GPR(R19)(r3) |
| 1843 | std r20, VCPU_GPR(R20)(r3) |
| 1844 | std r21, VCPU_GPR(R21)(r3) |
| 1845 | std r22, VCPU_GPR(R22)(r3) |
| 1846 | std r23, VCPU_GPR(R23)(r3) |
| 1847 | std r24, VCPU_GPR(R24)(r3) |
| 1848 | std r25, VCPU_GPR(R25)(r3) |
| 1849 | std r26, VCPU_GPR(R26)(r3) |
| 1850 | std r27, VCPU_GPR(R27)(r3) |
| 1851 | std r28, VCPU_GPR(R28)(r3) |
| 1852 | std r29, VCPU_GPR(R29)(r3) |
| 1853 | std r30, VCPU_GPR(R30)(r3) |
| 1854 | std r31, VCPU_GPR(R31)(r3) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1855 | |
| 1856 | /* save FP state */ |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 1857 | bl kvmppc_save_fp |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1858 | |
| 1859 | /* |
| 1860 | * Take a nap until a decrementer or external interrupt occurs, |
| 1861 | * with PECE1 (wake on decr) and PECE0 (wake on external) set in LPCR |
| 1862 | */ |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame] | 1863 | li r0,1 |
| 1864 | stb r0,HSTATE_HWTHREAD_REQ(r13) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1865 | mfspr r5,SPRN_LPCR |
| 1866 | ori r5,r5,LPCR_PECE0 | LPCR_PECE1 |
| 1867 | mtspr SPRN_LPCR,r5 |
| 1868 | isync |
| 1869 | li r0, 0 |
| 1870 | std r0, HSTATE_SCRATCH0(r13) |
| 1871 | ptesync |
| 1872 | ld r0, HSTATE_SCRATCH0(r13) |
| 1873 | 1: cmpd r0, r0 |
| 1874 | bne 1b |
| 1875 | nap |
| 1876 | b . |
| 1877 | |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 1878 | 33: mr r4, r3 |
| 1879 | li r3, 0 |
| 1880 | li r12, 0 |
| 1881 | b 34f |
| 1882 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1883 | kvm_end_cede: |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 1884 | /* get vcpu pointer */ |
| 1885 | ld r4, HSTATE_KVM_VCPU(r13) |
| 1886 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1887 | /* Woken by external or decrementer interrupt */ |
| 1888 | ld r1, HSTATE_HOST_R1(r13) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1889 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1890 | /* load up FP state */ |
| 1891 | bl kvmppc_load_fp |
| 1892 | |
| 1893 | /* Load NV GPRS */ |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1894 | ld r14, VCPU_GPR(R14)(r4) |
| 1895 | ld r15, VCPU_GPR(R15)(r4) |
| 1896 | ld r16, VCPU_GPR(R16)(r4) |
| 1897 | ld r17, VCPU_GPR(R17)(r4) |
| 1898 | ld r18, VCPU_GPR(R18)(r4) |
| 1899 | ld r19, VCPU_GPR(R19)(r4) |
| 1900 | ld r20, VCPU_GPR(R20)(r4) |
| 1901 | ld r21, VCPU_GPR(R21)(r4) |
| 1902 | ld r22, VCPU_GPR(R22)(r4) |
| 1903 | ld r23, VCPU_GPR(R23)(r4) |
| 1904 | ld r24, VCPU_GPR(R24)(r4) |
| 1905 | ld r25, VCPU_GPR(R25)(r4) |
| 1906 | ld r26, VCPU_GPR(R26)(r4) |
| 1907 | ld r27, VCPU_GPR(R27)(r4) |
| 1908 | ld r28, VCPU_GPR(R28)(r4) |
| 1909 | ld r29, VCPU_GPR(R29)(r4) |
| 1910 | ld r30, VCPU_GPR(R30)(r4) |
| 1911 | ld r31, VCPU_GPR(R31)(r4) |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 1912 | |
| 1913 | /* Check the wake reason in SRR1 to see why we got here */ |
| 1914 | bl kvmppc_check_wake_reason |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1915 | |
| 1916 | /* clear our bit in vcore->napping_threads */ |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 1917 | 34: ld r5,HSTATE_KVM_VCORE(r13) |
| 1918 | lbz r7,HSTATE_PTID(r13) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1919 | li r0,1 |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 1920 | sld r0,r0,r7 |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1921 | addi r6,r5,VCORE_NAPPING_THREADS |
| 1922 | 32: lwarx r7,0,r6 |
| 1923 | andc r7,r7,r0 |
| 1924 | stwcx. r7,0,r6 |
| 1925 | bne 32b |
| 1926 | li r0,0 |
| 1927 | stb r0,HSTATE_NAPPING(r13) |
| 1928 | |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 1929 | /* See if the wake reason means we need to exit */ |
| 1930 | stw r12, VCPU_TRAP(r4) |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 1931 | mr r9, r4 |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 1932 | cmpdi r3, 0 |
| 1933 | bgt guest_exit_cont |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 1934 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1935 | /* see if any other thread is already exiting */ |
| 1936 | lwz r0,VCORE_ENTRY_EXIT(r5) |
| 1937 | cmpwi r0,0x100 |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 1938 | bge guest_exit_cont |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1939 | |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 1940 | b kvmppc_cede_reentry /* if not go back to guest */ |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1941 | |
| 1942 | /* cede when already previously prodded case */ |
Paul Mackerras | 04f995a | 2012-08-06 00:03:28 +0000 | [diff] [blame] | 1943 | kvm_cede_prodded: |
| 1944 | li r0,0 |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1945 | stb r0,VCPU_PRODDED(r3) |
| 1946 | sync /* order testing prodded vs. clearing ceded */ |
| 1947 | stb r0,VCPU_CEDED(r3) |
| 1948 | li r3,H_SUCCESS |
| 1949 | blr |
| 1950 | |
| 1951 | /* we've ceded but we want to give control to the host */ |
Paul Mackerras | 04f995a | 2012-08-06 00:03:28 +0000 | [diff] [blame] | 1952 | kvm_cede_exit: |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 1953 | b hcall_real_fallback |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1954 | |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1955 | /* Try to handle a machine check in real mode */ |
| 1956 | machine_check_realmode: |
| 1957 | mr r3, r9 /* get vcpu pointer */ |
| 1958 | bl .kvmppc_realmode_machine_check |
| 1959 | nop |
| 1960 | cmpdi r3, 0 /* continue exiting from guest? */ |
| 1961 | ld r9, HSTATE_KVM_VCPU(r13) |
| 1962 | li r12, BOOK3S_INTERRUPT_MACHINE_CHECK |
| 1963 | beq mc_cont |
| 1964 | /* If not, deliver a machine check. SRR0/1 are already set */ |
| 1965 | li r10, BOOK3S_INTERRUPT_MACHINE_CHECK |
| 1966 | li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */ |
| 1967 | rotldi r11, r11, 63 |
| 1968 | b fast_interrupt_c_return |
| 1969 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1970 | /* |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 1971 | * Check the reason we woke from nap, and take appropriate action. |
| 1972 | * Returns: |
| 1973 | * 0 if nothing needs to be done |
| 1974 | * 1 if something happened that needs to be handled by the host |
| 1975 | * -1 if there was a guest wakeup (IPI) |
| 1976 | * |
| 1977 | * Also sets r12 to the interrupt vector for any interrupt that needs |
| 1978 | * to be handled now by the host (0x500 for external interrupt), or zero. |
| 1979 | */ |
| 1980 | kvmppc_check_wake_reason: |
| 1981 | mfspr r6, SPRN_SRR1 |
| 1982 | rlwinm r6, r6, 44-31, 0x7 /* extract wake reason field */ |
| 1983 | cmpwi r6, 4 /* was it an external interrupt? */ |
| 1984 | li r12, BOOK3S_INTERRUPT_EXTERNAL |
| 1985 | beq kvmppc_read_intr /* if so, see what it was */ |
| 1986 | li r3, 0 |
| 1987 | li r12, 0 |
| 1988 | cmpwi r6, 6 /* was it the decrementer? */ |
| 1989 | beq 0f |
| 1990 | li r3, 1 /* anything else, return 1 */ |
| 1991 | 0: blr |
| 1992 | |
| 1993 | /* |
Paul Mackerras | c934243 | 2013-09-06 13:24:13 +1000 | [diff] [blame] | 1994 | * Determine what sort of external interrupt is pending (if any). |
| 1995 | * Returns: |
| 1996 | * 0 if no interrupt is pending |
| 1997 | * 1 if an interrupt is pending that needs to be handled by the host |
| 1998 | * -1 if there was a guest wakeup IPI (which has now been cleared) |
| 1999 | */ |
| 2000 | kvmppc_read_intr: |
| 2001 | /* see if a host IPI is pending */ |
| 2002 | li r3, 1 |
| 2003 | lbz r0, HSTATE_HOST_IPI(r13) |
| 2004 | cmpwi r0, 0 |
| 2005 | bne 1f |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2006 | |
Paul Mackerras | c934243 | 2013-09-06 13:24:13 +1000 | [diff] [blame] | 2007 | /* Now read the interrupt from the ICP */ |
| 2008 | ld r6, HSTATE_XICS_PHYS(r13) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2009 | li r7, XICS_XIRR |
Paul Mackerras | c934243 | 2013-09-06 13:24:13 +1000 | [diff] [blame] | 2010 | cmpdi r6, 0 |
| 2011 | beq- 1f |
| 2012 | lwzcix r0, r6, r7 |
| 2013 | rlwinm. r3, r0, 0, 0xffffff |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2014 | sync |
Paul Mackerras | c934243 | 2013-09-06 13:24:13 +1000 | [diff] [blame] | 2015 | beq 1f /* if nothing pending in the ICP */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2016 | |
Paul Mackerras | c934243 | 2013-09-06 13:24:13 +1000 | [diff] [blame] | 2017 | /* We found something in the ICP... |
| 2018 | * |
| 2019 | * If it's not an IPI, stash it in the PACA and return to |
| 2020 | * the host, we don't (yet) handle directing real external |
| 2021 | * interrupts directly to the guest |
| 2022 | */ |
| 2023 | cmpwi r3, XICS_IPI /* if there is, is it an IPI? */ |
Paul Mackerras | c934243 | 2013-09-06 13:24:13 +1000 | [diff] [blame] | 2024 | bne 42f |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2025 | |
Paul Mackerras | c934243 | 2013-09-06 13:24:13 +1000 | [diff] [blame] | 2026 | /* It's an IPI, clear the MFRR and EOI it */ |
| 2027 | li r3, 0xff |
| 2028 | li r8, XICS_MFRR |
| 2029 | stbcix r3, r6, r8 /* clear the IPI */ |
| 2030 | stwcix r0, r6, r7 /* EOI it */ |
| 2031 | sync |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2032 | |
Paul Mackerras | c934243 | 2013-09-06 13:24:13 +1000 | [diff] [blame] | 2033 | /* We need to re-check host IPI now in case it got set in the |
| 2034 | * meantime. If it's clear, we bounce the interrupt to the |
| 2035 | * guest |
| 2036 | */ |
| 2037 | lbz r0, HSTATE_HOST_IPI(r13) |
| 2038 | cmpwi r0, 0 |
| 2039 | bne- 43f |
| 2040 | |
| 2041 | /* OK, it's an IPI for us */ |
| 2042 | li r3, -1 |
| 2043 | 1: blr |
| 2044 | |
| 2045 | 42: /* It's not an IPI and it's for the host, stash it in the PACA |
| 2046 | * before exit, it will be picked up by the host ICP driver |
| 2047 | */ |
| 2048 | stw r0, HSTATE_SAVED_XIRR(r13) |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 2049 | li r3, 1 |
Paul Mackerras | c934243 | 2013-09-06 13:24:13 +1000 | [diff] [blame] | 2050 | b 1b |
| 2051 | |
| 2052 | 43: /* We raced with the host, we need to resend that IPI, bummer */ |
| 2053 | li r0, IPI_PRIORITY |
| 2054 | stbcix r0, r6, r8 /* set the IPI */ |
| 2055 | sync |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame^] | 2056 | li r3, 1 |
Paul Mackerras | c934243 | 2013-09-06 13:24:13 +1000 | [diff] [blame] | 2057 | b 1b |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2058 | |
| 2059 | /* |
| 2060 | * Save away FP, VMX and VSX registers. |
| 2061 | * r3 = vcpu pointer |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2062 | * N.B. r30 and r31 are volatile across this function, |
| 2063 | * thus it is not callable from C. |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2064 | */ |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2065 | kvmppc_save_fp: |
| 2066 | mflr r30 |
| 2067 | mr r31,r3 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2068 | mfmsr r5 |
| 2069 | ori r8,r5,MSR_FP |
| 2070 | #ifdef CONFIG_ALTIVEC |
| 2071 | BEGIN_FTR_SECTION |
| 2072 | oris r8,r8,MSR_VEC@h |
| 2073 | END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) |
| 2074 | #endif |
| 2075 | #ifdef CONFIG_VSX |
| 2076 | BEGIN_FTR_SECTION |
| 2077 | oris r8,r8,MSR_VSX@h |
| 2078 | END_FTR_SECTION_IFSET(CPU_FTR_VSX) |
| 2079 | #endif |
| 2080 | mtmsrd r8 |
| 2081 | isync |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2082 | addi r3,r3,VCPU_FPRS |
| 2083 | bl .store_fp_state |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2084 | #ifdef CONFIG_ALTIVEC |
| 2085 | BEGIN_FTR_SECTION |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2086 | addi r3,r31,VCPU_VRS |
| 2087 | bl .store_vr_state |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2088 | END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) |
| 2089 | #endif |
| 2090 | mfspr r6,SPRN_VRSAVE |
| 2091 | stw r6,VCPU_VRSAVE(r3) |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2092 | mtlr r30 |
Paul Mackerras | 8943633 | 2012-03-02 01:38:23 +0000 | [diff] [blame] | 2093 | mtmsrd r5 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2094 | isync |
| 2095 | blr |
| 2096 | |
| 2097 | /* |
| 2098 | * Load up FP, VMX and VSX registers |
| 2099 | * r4 = vcpu pointer |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2100 | * N.B. r30 and r31 are volatile across this function, |
| 2101 | * thus it is not callable from C. |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2102 | */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2103 | kvmppc_load_fp: |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2104 | mflr r30 |
| 2105 | mr r31,r4 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2106 | mfmsr r9 |
| 2107 | ori r8,r9,MSR_FP |
| 2108 | #ifdef CONFIG_ALTIVEC |
| 2109 | BEGIN_FTR_SECTION |
| 2110 | oris r8,r8,MSR_VEC@h |
| 2111 | END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) |
| 2112 | #endif |
| 2113 | #ifdef CONFIG_VSX |
| 2114 | BEGIN_FTR_SECTION |
| 2115 | oris r8,r8,MSR_VSX@h |
| 2116 | END_FTR_SECTION_IFSET(CPU_FTR_VSX) |
| 2117 | #endif |
| 2118 | mtmsrd r8 |
| 2119 | isync |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2120 | addi r3,r4,VCPU_FPRS |
| 2121 | bl .load_fp_state |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2122 | #ifdef CONFIG_ALTIVEC |
| 2123 | BEGIN_FTR_SECTION |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2124 | addi r3,r31,VCPU_VRS |
| 2125 | bl .load_vr_state |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2126 | END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) |
| 2127 | #endif |
| 2128 | lwz r7,VCPU_VRSAVE(r4) |
| 2129 | mtspr SPRN_VRSAVE,r7 |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2130 | mtlr r30 |
| 2131 | mr r4,r31 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2132 | blr |
Paul Mackerras | 44a3add | 2013-10-04 21:45:04 +1000 | [diff] [blame] | 2133 | |
| 2134 | /* |
| 2135 | * We come here if we get any exception or interrupt while we are |
| 2136 | * executing host real mode code while in guest MMU context. |
| 2137 | * For now just spin, but we should do something better. |
| 2138 | */ |
| 2139 | kvmppc_bad_host_intr: |
| 2140 | b . |