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