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