Thomas Gleixner | d94d71c | 2019-05-29 07:12:40 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 2 | /* |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright SUSE Linux Products GmbH 2009 |
| 5 | * |
| 6 | * Authors: Alexander Graf <agraf@suse.de> |
| 7 | */ |
| 8 | |
Christophe Leroy | ec0c464 | 2018-07-05 16:24:57 +0000 | [diff] [blame] | 9 | #include <asm/asm-compat.h> |
Christophe Leroy | 2c86cd1 | 2018-07-05 16:25:01 +0000 | [diff] [blame] | 10 | #include <asm/feature-fixups.h> |
Christophe Leroy | ec0c464 | 2018-07-05 16:24:57 +0000 | [diff] [blame] | 11 | |
Alexander Graf | d8d164a9 | 2014-05-15 14:38:03 +0200 | [diff] [blame] | 12 | #define SHADOW_SLB_ENTRY_LEN 0x10 |
| 13 | #define OFFSET_ESID(x) (SHADOW_SLB_ENTRY_LEN * x) |
| 14 | #define OFFSET_VSID(x) ((SHADOW_SLB_ENTRY_LEN * x) + 8) |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 15 | |
| 16 | /****************************************************************************** |
| 17 | * * |
| 18 | * Entry code * |
| 19 | * * |
| 20 | *****************************************************************************/ |
| 21 | |
Alexander Graf | 53e5b8b | 2010-04-16 00:11:48 +0200 | [diff] [blame] | 22 | .macro LOAD_GUEST_SEGMENTS |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 23 | |
| 24 | /* Required state: |
| 25 | * |
| 26 | * MSR = ~IR|DR |
| 27 | * R13 = PACA |
Alexander Graf | 7e57cba | 2010-01-08 02:58:03 +0100 | [diff] [blame] | 28 | * R1 = host R1 |
| 29 | * R2 = host R2 |
Alexander Graf | 53e5b8b | 2010-04-16 00:11:48 +0200 | [diff] [blame] | 30 | * R3 = shadow vcpu |
Paul Mackerras | 0214394 | 2011-07-23 17:41:44 +1000 | [diff] [blame] | 31 | * all other volatile GPRS = free except R4, R6 |
Alexander Graf | 53e5b8b | 2010-04-16 00:11:48 +0200 | [diff] [blame] | 32 | * SVCPU[CR] = guest CR |
| 33 | * SVCPU[XER] = guest XER |
| 34 | * SVCPU[CTR] = guest CTR |
| 35 | * SVCPU[LR] = guest LR |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 36 | */ |
| 37 | |
Alexander Graf | d8d164a9 | 2014-05-15 14:38:03 +0200 | [diff] [blame] | 38 | BEGIN_FW_FTR_SECTION |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 39 | |
Alexander Graf | d8d164a9 | 2014-05-15 14:38:03 +0200 | [diff] [blame] | 40 | /* Declare SLB shadow as 0 entries big */ |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 41 | |
Alexander Graf | d8d164a9 | 2014-05-15 14:38:03 +0200 | [diff] [blame] | 42 | ld r11, PACA_SLBSHADOWPTR(r13) |
| 43 | li r8, 0 |
| 44 | stb r8, 3(r11) |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 45 | |
Alexander Graf | d8d164a9 | 2014-05-15 14:38:03 +0200 | [diff] [blame] | 46 | END_FW_FTR_SECTION_IFSET(FW_FEATURE_LPAR) |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 47 | |
| 48 | /* Flush SLB */ |
| 49 | |
Paul Mackerras | bc1bc4e | 2013-06-22 17:14:11 +1000 | [diff] [blame] | 50 | li r10, 0 |
| 51 | slbmte r10, r10 |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 52 | slbia |
| 53 | |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 54 | /* Fill SLB with our shadow */ |
| 55 | |
Alexander Graf | 53e5b8b | 2010-04-16 00:11:48 +0200 | [diff] [blame] | 56 | lbz r12, SVCPU_SLB_MAX(r3) |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 57 | mulli r12, r12, 16 |
Alexander Graf | 53e5b8b | 2010-04-16 00:11:48 +0200 | [diff] [blame] | 58 | addi r12, r12, SVCPU_SLB |
| 59 | add r12, r12, r3 |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 60 | |
| 61 | /* for (r11 = kvm_slb; r11 < kvm_slb + kvm_slb_size; r11+=slb_entry) */ |
Alexander Graf | 53e5b8b | 2010-04-16 00:11:48 +0200 | [diff] [blame] | 62 | li r11, SVCPU_SLB |
| 63 | add r11, r11, r3 |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 64 | |
| 65 | slb_loop_enter: |
| 66 | |
| 67 | ld r10, 0(r11) |
| 68 | |
Alexander Graf | d8d164a9 | 2014-05-15 14:38:03 +0200 | [diff] [blame] | 69 | andis. r9, r10, SLB_ESID_V@h |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 70 | beq slb_loop_enter_skip |
| 71 | |
| 72 | ld r9, 8(r11) |
| 73 | slbmte r9, r10 |
| 74 | |
| 75 | slb_loop_enter_skip: |
| 76 | addi r11, r11, 16 |
| 77 | cmpd cr0, r11, r12 |
| 78 | blt slb_loop_enter |
| 79 | |
| 80 | slb_do_enter: |
| 81 | |
Alexander Graf | 53e5b8b | 2010-04-16 00:11:48 +0200 | [diff] [blame] | 82 | .endm |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 83 | |
| 84 | /****************************************************************************** |
| 85 | * * |
| 86 | * Exit code * |
| 87 | * * |
| 88 | *****************************************************************************/ |
| 89 | |
Alexander Graf | 53e5b8b | 2010-04-16 00:11:48 +0200 | [diff] [blame] | 90 | .macro LOAD_HOST_SEGMENTS |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 91 | |
| 92 | /* Register usage at this point: |
| 93 | * |
Alexander Graf | 53e5b8b | 2010-04-16 00:11:48 +0200 | [diff] [blame] | 94 | * R1 = host R1 |
| 95 | * R2 = host R2 |
| 96 | * R12 = exit handler id |
| 97 | * R13 = shadow vcpu - SHADOW_VCPU_OFF [=PACA on PPC64] |
| 98 | * SVCPU.* = guest * |
| 99 | * SVCPU[CR] = guest CR |
| 100 | * SVCPU[XER] = guest XER |
| 101 | * SVCPU[CTR] = guest CTR |
| 102 | * SVCPU[LR] = guest LR |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 103 | * |
| 104 | */ |
| 105 | |
Alexander Graf | d8d164a9 | 2014-05-15 14:38:03 +0200 | [diff] [blame] | 106 | /* Remove all SLB entries that are in use. */ |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 107 | |
Nicholas Piggin | 93897a1 | 2017-10-21 14:32:30 +1000 | [diff] [blame] | 108 | li r0, 0 |
Alexander Graf | 207438d | 2014-05-15 14:36:05 +0200 | [diff] [blame] | 109 | slbmte r0, r0 |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 110 | slbia |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 111 | |
Alexander Graf | d8d164a9 | 2014-05-15 14:38:03 +0200 | [diff] [blame] | 112 | /* Restore bolted entries from the shadow */ |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 113 | |
| 114 | ld r11, PACA_SLBSHADOWPTR(r13) |
| 115 | |
Alexander Graf | d8d164a9 | 2014-05-15 14:38:03 +0200 | [diff] [blame] | 116 | BEGIN_FW_FTR_SECTION |
| 117 | |
| 118 | /* Declare SLB shadow as SLB_NUM_BOLTED entries big */ |
| 119 | |
| 120 | li r8, SLB_NUM_BOLTED |
| 121 | stb r8, 3(r11) |
| 122 | |
| 123 | END_FW_FTR_SECTION_IFSET(FW_FEATURE_LPAR) |
| 124 | |
| 125 | /* Manually load all entries from shadow SLB */ |
| 126 | |
| 127 | li r8, SLBSHADOW_SAVEAREA |
| 128 | li r7, SLBSHADOW_SAVEAREA + 8 |
| 129 | |
| 130 | .rept SLB_NUM_BOLTED |
| 131 | LDX_BE r10, r11, r8 |
| 132 | cmpdi r10, 0 |
| 133 | beq 1f |
| 134 | LDX_BE r9, r11, r7 |
| 135 | slbmte r9, r10 |
| 136 | 1: addi r7, r7, SHADOW_SLB_ENTRY_LEN |
| 137 | addi r8, r8, SHADOW_SLB_ENTRY_LEN |
| 138 | .endr |
| 139 | |
| 140 | isync |
| 141 | sync |
Alexander Graf | 5126ed3 | 2009-11-02 12:02:29 +0000 | [diff] [blame] | 142 | |
| 143 | slb_do_exit: |
| 144 | |
Alexander Graf | 53e5b8b | 2010-04-16 00:11:48 +0200 | [diff] [blame] | 145 | .endm |