Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 1 | #ifndef _ASM_POWERPC_EXCEPTION_H |
| 2 | #define _ASM_POWERPC_EXCEPTION_H |
| 3 | /* |
| 4 | * Extracted from head_64.S |
| 5 | * |
| 6 | * PowerPC version |
| 7 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
| 8 | * |
| 9 | * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP |
| 10 | * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu> |
| 11 | * Adapted for Power Macintosh by Paul Mackerras. |
| 12 | * Low-level exception handlers and MMU support |
| 13 | * rewritten by Paul Mackerras. |
| 14 | * Copyright (C) 1996 Paul Mackerras. |
| 15 | * |
| 16 | * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and |
| 17 | * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com |
| 18 | * |
| 19 | * This file contains the low-level support and setup for the |
| 20 | * PowerPC-64 platform, including trap and interrupt dispatch. |
| 21 | * |
| 22 | * This program is free software; you can redistribute it and/or |
| 23 | * modify it under the terms of the GNU General Public License |
| 24 | * as published by the Free Software Foundation; either version |
| 25 | * 2 of the License, or (at your option) any later version. |
| 26 | */ |
| 27 | /* |
| 28 | * The following macros define the code that appears as |
| 29 | * the prologue to each of the exception handlers. They |
| 30 | * are split into two parts to allow a single kernel binary |
| 31 | * to be used for pSeries and iSeries. |
| 32 | * |
| 33 | * We make as much of the exception code common between native |
| 34 | * exception handlers (including pSeries LPAR) and iSeries LPAR |
| 35 | * implementations as possible. |
| 36 | */ |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 37 | #include <asm/head-64.h> |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 38 | |
Nicholas Piggin | 8c38851 | 2017-05-21 23:15:46 +1000 | [diff] [blame] | 39 | /* PACA save area offsets (exgen, exmc, etc) */ |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 40 | #define EX_R9 0 |
| 41 | #define EX_R10 8 |
| 42 | #define EX_R11 16 |
| 43 | #define EX_R12 24 |
| 44 | #define EX_R13 32 |
Nicholas Piggin | 36670fc | 2017-05-21 23:15:47 +1000 | [diff] [blame] | 45 | #define EX_DAR 40 |
| 46 | #define EX_DSISR 48 |
| 47 | #define EX_CCR 52 |
Nicholas Piggin | 635942a | 2017-05-21 23:15:49 +1000 | [diff] [blame] | 48 | #define EX_CFAR 56 |
| 49 | #define EX_PPR 64 |
Nicholas Piggin | 8568f1e0 | 2017-05-21 23:15:50 +1000 | [diff] [blame] | 50 | #if defined(CONFIG_RELOCATABLE) |
Nicholas Piggin | 635942a | 2017-05-21 23:15:49 +1000 | [diff] [blame] | 51 | #define EX_CTR 72 |
Nicholas Piggin | 635942a | 2017-05-21 23:15:49 +1000 | [diff] [blame] | 52 | #define EX_SIZE 10 /* size in u64 units */ |
Nicholas Piggin | 8568f1e0 | 2017-05-21 23:15:50 +1000 | [diff] [blame] | 53 | #else |
| 54 | #define EX_SIZE 9 /* size in u64 units */ |
| 55 | #endif |
Nicholas Piggin | dbeea1d | 2017-05-21 23:15:48 +1000 | [diff] [blame] | 56 | |
| 57 | /* |
Balbir Singh | ba41e1e | 2017-09-29 14:26:53 +1000 | [diff] [blame] | 58 | * maximum recursive depth of MCE exceptions |
| 59 | */ |
| 60 | #define MAX_MCE_DEPTH 4 |
| 61 | |
| 62 | /* |
Nicholas Piggin | dbeea1d | 2017-05-21 23:15:48 +1000 | [diff] [blame] | 63 | * EX_LR is only used in EXSLB and where it does not overlap with EX_DAR |
| 64 | * EX_CCR similarly with DSISR, but being 4 byte registers there is a hole |
| 65 | * in the save area so it's not necessary to overlap them. Could be used |
| 66 | * for future savings though if another 4 byte register was to be saved. |
| 67 | */ |
| 68 | #define EX_LR EX_DAR |
Nicholas Piggin | 8c38851 | 2017-05-21 23:15:46 +1000 | [diff] [blame] | 69 | |
Nicholas Piggin | 635942a | 2017-05-21 23:15:49 +1000 | [diff] [blame] | 70 | /* |
| 71 | * EX_R3 is only used by the bad_stack handler. bad_stack reloads and |
| 72 | * saves DAR from SPRN_DAR, and EX_DAR is not used. So EX_R3 can overlap |
| 73 | * with EX_DAR. |
| 74 | */ |
| 75 | #define EX_R3 EX_DAR |
| 76 | |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 77 | #ifdef CONFIG_RELOCATABLE |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 78 | #define __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \ |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 79 | mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ |
| 80 | LOAD_HANDLER(r12,label); \ |
Michael Neuling | bc2e6c6 | 2013-08-13 15:54:52 +1000 | [diff] [blame] | 81 | mtctr r12; \ |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 82 | mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ |
| 83 | li r10,MSR_RI; \ |
| 84 | mtmsrd r10,1; /* Set RI (EE=0) */ \ |
Michael Neuling | bc2e6c6 | 2013-08-13 15:54:52 +1000 | [diff] [blame] | 85 | bctr; |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 86 | #else |
| 87 | /* If not relocatable, we can jump directly -- and save messing with LR */ |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 88 | #define __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \ |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 89 | mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ |
| 90 | mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ |
| 91 | li r10,MSR_RI; \ |
| 92 | mtmsrd r10,1; /* Set RI (EE=0) */ \ |
| 93 | b label; |
| 94 | #endif |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 95 | #define EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \ |
| 96 | __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \ |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 97 | |
| 98 | /* |
| 99 | * As EXCEPTION_PROLOG_PSERIES(), except we've already got relocation on |
| 100 | * so no need to rfid. Save lr in case we're CONFIG_RELOCATABLE, in which |
| 101 | * case EXCEPTION_RELON_PROLOG_PSERIES_1 will be using lr. |
| 102 | */ |
| 103 | #define EXCEPTION_RELON_PROLOG_PSERIES(area, label, h, extra, vec) \ |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 104 | EXCEPTION_PROLOG_0(area); \ |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 105 | EXCEPTION_PROLOG_1(area, extra, vec); \ |
| 106 | EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) |
| 107 | |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 108 | /* |
| 109 | * We're short on space and time in the exception prolog, so we can't |
Michael Ellerman | 2751023 | 2016-07-26 15:29:29 +1000 | [diff] [blame] | 110 | * use the normal LOAD_REG_IMMEDIATE macro to load the address of label. |
| 111 | * Instead we get the base of the kernel from paca->kernelbase and or in the low |
| 112 | * part of label. This requires that the label be within 64KB of kernelbase, and |
| 113 | * that kernelbase be 64K aligned. |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 114 | */ |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 115 | #define LOAD_HANDLER(reg, label) \ |
Michael Ellerman | d8d42b0 | 2016-07-26 15:29:30 +1000 | [diff] [blame] | 116 | ld reg,PACAKBASE(r13); /* get high part of &label */ \ |
Hugh Dickins | e6740ae | 2016-11-07 22:28:21 -0800 | [diff] [blame] | 117 | ori reg,reg,FIXED_SYMBOL_ABS_ADDR(label); |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 118 | |
Nicholas Piggin | fb479e4 | 2016-10-13 13:17:14 +1100 | [diff] [blame] | 119 | #define __LOAD_HANDLER(reg, label) \ |
| 120 | ld reg,PACAKBASE(r13); \ |
| 121 | ori reg,reg,(ABS_ADDR(label))@l; |
| 122 | |
Nicholas Piggin | a97a65d | 2017-01-27 14:00:34 +1000 | [diff] [blame] | 123 | /* |
| 124 | * Branches from unrelocated code (e.g., interrupts) to labels outside |
| 125 | * head-y require >64K offsets. |
| 126 | */ |
| 127 | #define __LOAD_FAR_HANDLER(reg, label) \ |
| 128 | ld reg,PACAKBASE(r13); \ |
| 129 | ori reg,reg,(ABS_ADDR(label))@l; \ |
| 130 | addis reg,reg,(ABS_ADDR(label))@h; |
| 131 | |
Benjamin Herrenschmidt | a5d4f3a | 2011-04-05 14:20:31 +1000 | [diff] [blame] | 132 | /* Exception register prefixes */ |
| 133 | #define EXC_HV H |
| 134 | #define EXC_STD |
| 135 | |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 136 | #if defined(CONFIG_RELOCATABLE) |
| 137 | /* |
Michael Neuling | bc2e6c6 | 2013-08-13 15:54:52 +1000 | [diff] [blame] | 138 | * If we support interrupts with relocation on AND we're a relocatable kernel, |
| 139 | * we need to use CTR to get to the 2nd level handler. So, save/restore it |
| 140 | * when required. |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 141 | */ |
Michael Neuling | bc2e6c6 | 2013-08-13 15:54:52 +1000 | [diff] [blame] | 142 | #define SAVE_CTR(reg, area) mfctr reg ; std reg,area+EX_CTR(r13) |
| 143 | #define GET_CTR(reg, area) ld reg,area+EX_CTR(r13) |
| 144 | #define RESTORE_CTR(reg, area) ld reg,area+EX_CTR(r13) ; mtctr reg |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 145 | #else |
Michael Neuling | bc2e6c6 | 2013-08-13 15:54:52 +1000 | [diff] [blame] | 146 | /* ...else CTR is unused and in register. */ |
| 147 | #define SAVE_CTR(reg, area) |
| 148 | #define GET_CTR(reg, area) mfctr reg |
| 149 | #define RESTORE_CTR(reg, area) |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 150 | #endif |
| 151 | |
Haren Myneni | 13e7a8e | 2012-12-06 21:50:32 +0000 | [diff] [blame] | 152 | /* |
| 153 | * PPR save/restore macros used in exceptions_64s.S |
| 154 | * Used for P7 or later processors |
| 155 | */ |
| 156 | #define SAVE_PPR(area, ra, rb) \ |
| 157 | BEGIN_FTR_SECTION_NESTED(940) \ |
| 158 | ld ra,PACACURRENT(r13); \ |
| 159 | ld rb,area+EX_PPR(r13); /* Read PPR from paca */ \ |
| 160 | std rb,TASKTHREADPPR(ra); \ |
| 161 | END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,940) |
| 162 | |
| 163 | #define RESTORE_PPR_PACA(area, ra) \ |
| 164 | BEGIN_FTR_SECTION_NESTED(941) \ |
| 165 | ld ra,area+EX_PPR(r13); \ |
| 166 | mtspr SPRN_PPR,ra; \ |
| 167 | END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,941) |
| 168 | |
| 169 | /* |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 170 | * Get an SPR into a register if the CPU has the given feature |
Haren Myneni | 13e7a8e | 2012-12-06 21:50:32 +0000 | [diff] [blame] | 171 | */ |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 172 | #define OPT_GET_SPR(ra, spr, ftr) \ |
Haren Myneni | 13e7a8e | 2012-12-06 21:50:32 +0000 | [diff] [blame] | 173 | BEGIN_FTR_SECTION_NESTED(943) \ |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 174 | mfspr ra,spr; \ |
| 175 | END_FTR_SECTION_NESTED(ftr,ftr,943) |
Haren Myneni | 13e7a8e | 2012-12-06 21:50:32 +0000 | [diff] [blame] | 176 | |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 177 | /* |
Mahesh Salgaonkar | d410ae2 | 2014-03-11 10:56:18 +0530 | [diff] [blame] | 178 | * Set an SPR from a register if the CPU has the given feature |
| 179 | */ |
| 180 | #define OPT_SET_SPR(ra, spr, ftr) \ |
| 181 | BEGIN_FTR_SECTION_NESTED(943) \ |
| 182 | mtspr spr,ra; \ |
| 183 | END_FTR_SECTION_NESTED(ftr,ftr,943) |
| 184 | |
| 185 | /* |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 186 | * Save a register to the PACA if the CPU has the given feature |
| 187 | */ |
| 188 | #define OPT_SAVE_REG_TO_PACA(offset, ra, ftr) \ |
| 189 | BEGIN_FTR_SECTION_NESTED(943) \ |
| 190 | std ra,offset(r13); \ |
| 191 | END_FTR_SECTION_NESTED(ftr,ftr,943) |
| 192 | |
Nicholas Piggin | 544686c | 2017-04-19 23:05:45 +1000 | [diff] [blame] | 193 | #define EXCEPTION_PROLOG_0(area) \ |
| 194 | GET_PACA(r13); \ |
Haren Myneni | 44e9309 | 2012-12-06 21:51:04 +0000 | [diff] [blame] | 195 | std r9,area+EX_R9(r13); /* save r9 */ \ |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 196 | OPT_GET_SPR(r9, SPRN_PPR, CPU_FTR_HAS_PPR); \ |
| 197 | HMT_MEDIUM; \ |
Haren Myneni | 44e9309 | 2012-12-06 21:51:04 +0000 | [diff] [blame] | 198 | std r10,area+EX_R10(r13); /* save r10 - r12 */ \ |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 199 | OPT_GET_SPR(r10, SPRN_CFAR, CPU_FTR_CFAR) |
| 200 | |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 201 | #define __EXCEPTION_PROLOG_1_PRE(area) \ |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 202 | OPT_SAVE_REG_TO_PACA(area+EX_PPR, r9, CPU_FTR_HAS_PPR); \ |
| 203 | OPT_SAVE_REG_TO_PACA(area+EX_CFAR, r10, CPU_FTR_CFAR); \ |
Michael Neuling | bc2e6c6 | 2013-08-13 15:54:52 +1000 | [diff] [blame] | 204 | SAVE_CTR(r10, area); \ |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 205 | mfcr r9; |
| 206 | |
| 207 | #define __EXCEPTION_PROLOG_1_POST(area) \ |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 208 | std r11,area+EX_R11(r13); \ |
| 209 | std r12,area+EX_R12(r13); \ |
| 210 | GET_SCRATCH0(r10); \ |
| 211 | std r10,area+EX_R13(r13) |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 212 | |
| 213 | /* |
| 214 | * This version of the EXCEPTION_PROLOG_1 will carry |
| 215 | * addition parameter called "bitmask" to support |
| 216 | * checking of the interrupt maskable level in the SOFTEN_TEST. |
| 217 | * Intended to be used in MASKABLE_EXCPETION_* macros. |
| 218 | */ |
| 219 | #define MASKABLE_EXCEPTION_PROLOG_1(area, extra, vec, bitmask) \ |
| 220 | __EXCEPTION_PROLOG_1_PRE(area); \ |
| 221 | extra(vec, bitmask); \ |
| 222 | __EXCEPTION_PROLOG_1_POST(area); |
| 223 | |
| 224 | /* |
| 225 | * This version of the EXCEPTION_PROLOG_1 is intended |
| 226 | * to be used in STD_EXCEPTION* macros |
| 227 | */ |
| 228 | #define _EXCEPTION_PROLOG_1(area, extra, vec) \ |
| 229 | __EXCEPTION_PROLOG_1_PRE(area); \ |
| 230 | extra(vec); \ |
| 231 | __EXCEPTION_PROLOG_1_POST(area); |
| 232 | |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 233 | #define EXCEPTION_PROLOG_1(area, extra, vec) \ |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 234 | _EXCEPTION_PROLOG_1(area, extra, vec) |
Stephen Rothwell | 7180e3e | 2007-08-22 13:48:37 +1000 | [diff] [blame] | 235 | |
Benjamin Herrenschmidt | a5d4f3a | 2011-04-05 14:20:31 +1000 | [diff] [blame] | 236 | #define __EXCEPTION_PROLOG_PSERIES_1(label, h) \ |
Paul Mackerras | 1f6a93e | 2008-08-30 11:40:24 +1000 | [diff] [blame] | 237 | ld r10,PACAKMSR(r13); /* get MSR value for kernel */ \ |
Benjamin Herrenschmidt | a5d4f3a | 2011-04-05 14:20:31 +1000 | [diff] [blame] | 238 | mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 239 | LOAD_HANDLER(r12,label) \ |
Benjamin Herrenschmidt | a5d4f3a | 2011-04-05 14:20:31 +1000 | [diff] [blame] | 240 | mtspr SPRN_##h##SRR0,r12; \ |
| 241 | mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ |
| 242 | mtspr SPRN_##h##SRR1,r10; \ |
| 243 | h##rfid; \ |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 244 | b . /* prevent speculative execution */ |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 245 | #define EXCEPTION_PROLOG_PSERIES_1(label, h) \ |
Benjamin Herrenschmidt | a5d4f3a | 2011-04-05 14:20:31 +1000 | [diff] [blame] | 246 | __EXCEPTION_PROLOG_PSERIES_1(label, h) |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 247 | |
Nicholas Piggin | 83a980f | 2016-12-20 04:30:02 +1000 | [diff] [blame] | 248 | /* _NORI variant keeps MSR_RI clear */ |
| 249 | #define __EXCEPTION_PROLOG_PSERIES_1_NORI(label, h) \ |
| 250 | ld r10,PACAKMSR(r13); /* get MSR value for kernel */ \ |
| 251 | xori r10,r10,MSR_RI; /* Clear MSR_RI */ \ |
| 252 | mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ |
| 253 | LOAD_HANDLER(r12,label) \ |
| 254 | mtspr SPRN_##h##SRR0,r12; \ |
| 255 | mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ |
| 256 | mtspr SPRN_##h##SRR1,r10; \ |
| 257 | h##rfid; \ |
| 258 | b . /* prevent speculative execution */ |
| 259 | |
| 260 | #define EXCEPTION_PROLOG_PSERIES_1_NORI(label, h) \ |
| 261 | __EXCEPTION_PROLOG_PSERIES_1_NORI(label, h) |
| 262 | |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 263 | #define EXCEPTION_PROLOG_PSERIES(area, label, h, extra, vec) \ |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 264 | EXCEPTION_PROLOG_0(area); \ |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 265 | EXCEPTION_PROLOG_1(area, extra, vec); \ |
Benjamin Herrenschmidt | a5d4f3a | 2011-04-05 14:20:31 +1000 | [diff] [blame] | 266 | EXCEPTION_PROLOG_PSERIES_1(label, h); |
Benjamin Herrenschmidt | c5a8c0c | 2009-07-16 19:36:57 +0000 | [diff] [blame] | 267 | |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 268 | #define __KVMTEST(h, n) \ |
| 269 | lbz r10,HSTATE_IN_GUEST(r13); \ |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 270 | cmpwi r10,0; \ |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 271 | bne do_kvm_##h##n |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 272 | |
Aneesh Kumar K.V | dd96b2c | 2013-10-07 22:17:55 +0530 | [diff] [blame] | 273 | #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE |
| 274 | /* |
| 275 | * If hv is possible, interrupts come into to the hv version |
| 276 | * of the kvmppc_interrupt code, which then jumps to the PR handler, |
| 277 | * kvmppc_interrupt_pr, if the guest is a PR guest. |
| 278 | */ |
| 279 | #define kvmppc_interrupt kvmppc_interrupt_hv |
| 280 | #else |
| 281 | #define kvmppc_interrupt kvmppc_interrupt_pr |
| 282 | #endif |
| 283 | |
Nicholas Piggin | b51351e | 2017-06-13 23:05:50 +1000 | [diff] [blame] | 284 | /* |
| 285 | * Branch to label using its 0xC000 address. This results in instruction |
| 286 | * address suitable for MSR[IR]=0 or 1, which allows relocation to be turned |
| 287 | * on using mtmsr rather than rfid. |
| 288 | * |
| 289 | * This could set the 0xc bits for !RELOCATABLE as an immediate, rather than |
| 290 | * load KBASE for a slight optimisation. |
| 291 | */ |
| 292 | #define BRANCH_TO_C000(reg, label) \ |
| 293 | __LOAD_HANDLER(reg, label); \ |
| 294 | mtctr reg; \ |
| 295 | bctr |
| 296 | |
Nicholas Piggin | fb479e4 | 2016-10-13 13:17:14 +1100 | [diff] [blame] | 297 | #ifdef CONFIG_RELOCATABLE |
| 298 | #define BRANCH_TO_COMMON(reg, label) \ |
| 299 | __LOAD_HANDLER(reg, label); \ |
| 300 | mtctr reg; \ |
| 301 | bctr |
| 302 | |
Michael Ellerman | be5c5e8 | 2017-04-18 14:08:15 +1000 | [diff] [blame] | 303 | #define BRANCH_LINK_TO_FAR(label) \ |
| 304 | __LOAD_FAR_HANDLER(r12, label); \ |
| 305 | mtctr r12; \ |
Nicholas Piggin | 2337d20 | 2017-01-27 14:24:33 +1000 | [diff] [blame] | 306 | bctrl |
| 307 | |
Nicholas Piggin | a97a65d | 2017-01-27 14:00:34 +1000 | [diff] [blame] | 308 | /* |
| 309 | * KVM requires __LOAD_FAR_HANDLER. |
| 310 | * |
| 311 | * __BRANCH_TO_KVM_EXIT branches are also a special case because they |
| 312 | * explicitly use r9 then reload it from PACA before branching. Hence |
| 313 | * the double-underscore. |
| 314 | */ |
| 315 | #define __BRANCH_TO_KVM_EXIT(area, label) \ |
| 316 | mfctr r9; \ |
| 317 | std r9,HSTATE_SCRATCH1(r13); \ |
| 318 | __LOAD_FAR_HANDLER(r9, label); \ |
| 319 | mtctr r9; \ |
| 320 | ld r9,area+EX_R9(r13); \ |
| 321 | bctr |
| 322 | |
Nicholas Piggin | fb479e4 | 2016-10-13 13:17:14 +1100 | [diff] [blame] | 323 | #else |
| 324 | #define BRANCH_TO_COMMON(reg, label) \ |
| 325 | b label |
| 326 | |
Michael Ellerman | be5c5e8 | 2017-04-18 14:08:15 +1000 | [diff] [blame] | 327 | #define BRANCH_LINK_TO_FAR(label) \ |
Nicholas Piggin | 2337d20 | 2017-01-27 14:24:33 +1000 | [diff] [blame] | 328 | bl label |
| 329 | |
Nicholas Piggin | a97a65d | 2017-01-27 14:00:34 +1000 | [diff] [blame] | 330 | #define __BRANCH_TO_KVM_EXIT(area, label) \ |
| 331 | ld r9,area+EX_R9(r13); \ |
| 332 | b label |
| 333 | |
Nicholas Piggin | fb479e4 | 2016-10-13 13:17:14 +1100 | [diff] [blame] | 334 | #endif |
| 335 | |
Nicholas Piggin | c4f3b52 | 2016-12-20 04:30:05 +1000 | [diff] [blame] | 336 | /* Do not enable RI */ |
| 337 | #define EXCEPTION_PROLOG_PSERIES_NORI(area, label, h, extra, vec) \ |
| 338 | EXCEPTION_PROLOG_0(area); \ |
| 339 | EXCEPTION_PROLOG_1(area, extra, vec); \ |
| 340 | EXCEPTION_PROLOG_PSERIES_1_NORI(label, h); |
| 341 | |
Nicholas Piggin | a97a65d | 2017-01-27 14:00:34 +1000 | [diff] [blame] | 342 | |
Nicholas Piggin | d3918e7 | 2016-12-22 04:29:25 +1000 | [diff] [blame] | 343 | #define __KVM_HANDLER(area, h, n) \ |
Paul Mackerras | 0acb911 | 2013-02-04 18:10:51 +0000 | [diff] [blame] | 344 | BEGIN_FTR_SECTION_NESTED(947) \ |
| 345 | ld r10,area+EX_CFAR(r13); \ |
| 346 | std r10,HSTATE_CFAR(r13); \ |
| 347 | END_FTR_SECTION_NESTED(CPU_FTR_CFAR,CPU_FTR_CFAR,947); \ |
Paul Mackerras | 4b8473c | 2013-09-20 14:52:39 +1000 | [diff] [blame] | 348 | BEGIN_FTR_SECTION_NESTED(948) \ |
| 349 | ld r10,area+EX_PPR(r13); \ |
| 350 | std r10,HSTATE_PPR(r13); \ |
| 351 | END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948); \ |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 352 | ld r10,area+EX_R10(r13); \ |
Paul Mackerras | 0acb911 | 2013-02-04 18:10:51 +0000 | [diff] [blame] | 353 | std r12,HSTATE_SCRATCH0(r13); \ |
Nicholas Piggin | d3918e7 | 2016-12-22 04:29:25 +1000 | [diff] [blame] | 354 | sldi r12,r9,32; \ |
| 355 | ori r12,r12,(n); \ |
Nicholas Piggin | a97a65d | 2017-01-27 14:00:34 +1000 | [diff] [blame] | 356 | /* This reloads r9 before branching to kvmppc_interrupt */ \ |
| 357 | __BRANCH_TO_KVM_EXIT(area, kvmppc_interrupt) |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 358 | |
| 359 | #define __KVM_HANDLER_SKIP(area, h, n) \ |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 360 | cmpwi r10,KVM_GUEST_MODE_SKIP; \ |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 361 | beq 89f; \ |
Paul Mackerras | 4b8473c | 2013-09-20 14:52:39 +1000 | [diff] [blame] | 362 | BEGIN_FTR_SECTION_NESTED(948) \ |
Nicholas Piggin | d3918e7 | 2016-12-22 04:29:25 +1000 | [diff] [blame] | 363 | ld r10,area+EX_PPR(r13); \ |
| 364 | std r10,HSTATE_PPR(r13); \ |
Paul Mackerras | 4b8473c | 2013-09-20 14:52:39 +1000 | [diff] [blame] | 365 | END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948); \ |
Nicholas Piggin | d3918e7 | 2016-12-22 04:29:25 +1000 | [diff] [blame] | 366 | ld r10,area+EX_R10(r13); \ |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 367 | std r12,HSTATE_SCRATCH0(r13); \ |
Nicholas Piggin | d3918e7 | 2016-12-22 04:29:25 +1000 | [diff] [blame] | 368 | sldi r12,r9,32; \ |
| 369 | ori r12,r12,(n); \ |
Nicholas Piggin | a97a65d | 2017-01-27 14:00:34 +1000 | [diff] [blame] | 370 | /* This reloads r9 before branching to kvmppc_interrupt */ \ |
| 371 | __BRANCH_TO_KVM_EXIT(area, kvmppc_interrupt); \ |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 372 | 89: mtocrf 0x80,r9; \ |
| 373 | ld r9,area+EX_R9(r13); \ |
Nicholas Piggin | d3918e7 | 2016-12-22 04:29:25 +1000 | [diff] [blame] | 374 | ld r10,area+EX_R10(r13); \ |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 375 | b kvmppc_skip_##h##interrupt |
| 376 | |
| 377 | #ifdef CONFIG_KVM_BOOK3S_64_HANDLER |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 378 | #define KVMTEST(h, n) __KVMTEST(h, n) |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 379 | #define KVM_HANDLER(area, h, n) __KVM_HANDLER(area, h, n) |
| 380 | #define KVM_HANDLER_SKIP(area, h, n) __KVM_HANDLER_SKIP(area, h, n) |
| 381 | |
| 382 | #else |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 383 | #define KVMTEST(h, n) |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 384 | #define KVM_HANDLER(area, h, n) |
| 385 | #define KVM_HANDLER_SKIP(area, h, n) |
| 386 | #endif |
| 387 | |
| 388 | #define NOTEST(n) |
| 389 | |
Nicholas Piggin | a4087a4 | 2016-12-20 04:30:03 +1000 | [diff] [blame] | 390 | #define EXCEPTION_PROLOG_COMMON_1() \ |
| 391 | std r9,_CCR(r1); /* save CR in stackframe */ \ |
| 392 | std r11,_NIP(r1); /* save SRR0 in stackframe */ \ |
| 393 | std r12,_MSR(r1); /* save SRR1 in stackframe */ \ |
| 394 | std r10,0(r1); /* make stack chain pointer */ \ |
| 395 | std r0,GPR0(r1); /* save r0 in stackframe */ \ |
| 396 | std r10,GPR1(r1); /* save r1 in stackframe */ \ |
| 397 | |
| 398 | |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 399 | /* |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 400 | * The common exception prolog is used for all except a few exceptions |
| 401 | * such as a segment miss on a kernel address. We have to be prepared |
| 402 | * to take another exception from the point where we first touch the |
| 403 | * kernel stack onwards. |
| 404 | * |
| 405 | * On entry r13 points to the paca, r9-r13 are saved in the paca, |
| 406 | * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and |
| 407 | * SRR1, and relocation is on. |
| 408 | */ |
| 409 | #define EXCEPTION_PROLOG_COMMON(n, area) \ |
| 410 | andi. r10,r12,MSR_PR; /* See if coming from user */ \ |
| 411 | mr r10,r1; /* Save r1 */ \ |
| 412 | subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \ |
| 413 | beq- 1f; \ |
| 414 | ld r1,PACAKSAVE(r13); /* kernel stack to use */ \ |
Michael Neuling | 90ff5d6 | 2013-12-16 15:12:43 +1100 | [diff] [blame] | 415 | 1: cmpdi cr1,r1,-INT_FRAME_SIZE; /* check if r1 is in userspace */ \ |
Paul Mackerras | 1977b50 | 2011-05-01 19:46:44 +0000 | [diff] [blame] | 416 | blt+ cr1,3f; /* abort if it is */ \ |
| 417 | li r1,(n); /* will be reloaded later */ \ |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 418 | sth r1,PACA_TRAP_SAVE(r13); \ |
Paul Mackerras | 1977b50 | 2011-05-01 19:46:44 +0000 | [diff] [blame] | 419 | std r3,area+EX_R3(r13); \ |
| 420 | addi r3,r13,area; /* r3 -> where regs are saved*/ \ |
Michael Neuling | bc2e6c6 | 2013-08-13 15:54:52 +1000 | [diff] [blame] | 421 | RESTORE_CTR(r1, area); \ |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 422 | b bad_stack; \ |
Nicholas Piggin | a4087a4 | 2016-12-20 04:30:03 +1000 | [diff] [blame] | 423 | 3: EXCEPTION_PROLOG_COMMON_1(); \ |
Haren Myneni | 5d75b26 | 2012-12-06 21:46:37 +0000 | [diff] [blame] | 424 | beq 4f; /* if from kernel mode */ \ |
Christophe Leroy | c223c90 | 2016-05-17 08:33:46 +0200 | [diff] [blame] | 425 | ACCOUNT_CPU_USER_ENTRY(r13, r9, r10); \ |
Haren Myneni | 44e9309 | 2012-12-06 21:51:04 +0000 | [diff] [blame] | 426 | SAVE_PPR(area, r9, r10); \ |
Mahesh Salgaonkar | b14a7253 | 2013-10-30 20:03:51 +0530 | [diff] [blame] | 427 | 4: EXCEPTION_PROLOG_COMMON_2(area) \ |
| 428 | EXCEPTION_PROLOG_COMMON_3(n) \ |
| 429 | ACCOUNT_STOLEN_TIME |
| 430 | |
| 431 | /* Save original regs values from save area to stack frame. */ |
| 432 | #define EXCEPTION_PROLOG_COMMON_2(area) \ |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 433 | ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \ |
| 434 | ld r10,area+EX_R10(r13); \ |
| 435 | std r9,GPR9(r1); \ |
| 436 | std r10,GPR10(r1); \ |
| 437 | ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \ |
| 438 | ld r10,area+EX_R12(r13); \ |
| 439 | ld r11,area+EX_R13(r13); \ |
| 440 | std r9,GPR11(r1); \ |
| 441 | std r10,GPR12(r1); \ |
| 442 | std r11,GPR13(r1); \ |
Paul Mackerras | 48404f2 | 2011-05-01 19:48:20 +0000 | [diff] [blame] | 443 | BEGIN_FTR_SECTION_NESTED(66); \ |
| 444 | ld r10,area+EX_CFAR(r13); \ |
| 445 | std r10,ORIG_GPR3(r1); \ |
| 446 | END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66); \ |
Mahesh Salgaonkar | b14a7253 | 2013-10-30 20:03:51 +0530 | [diff] [blame] | 447 | GET_CTR(r10, area); \ |
| 448 | std r10,_CTR(r1); |
| 449 | |
| 450 | #define EXCEPTION_PROLOG_COMMON_3(n) \ |
| 451 | std r2,GPR2(r1); /* save r2 in stackframe */ \ |
| 452 | SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \ |
| 453 | SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \ |
Michael Neuling | bc2e6c6 | 2013-08-13 15:54:52 +1000 | [diff] [blame] | 454 | mflr r9; /* Get LR, later save to stack */ \ |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 455 | ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \ |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 456 | std r9,_LINK(r1); \ |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 457 | lbz r10,PACAIRQSOFTMASK(r13); \ |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 458 | mfspr r11,SPRN_XER; /* save XER in stackframe */ \ |
| 459 | std r10,SOFTE(r1); \ |
| 460 | std r11,_XER(r1); \ |
| 461 | li r9,(n)+1; \ |
| 462 | std r9,_TRAP(r1); /* set trap number */ \ |
| 463 | li r10,0; \ |
| 464 | ld r11,exception_marker@toc(r2); \ |
| 465 | std r10,RESULT(r1); /* clear regs->result */ \ |
Mahesh Salgaonkar | b14a7253 | 2013-10-30 20:03:51 +0530 | [diff] [blame] | 466 | std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */ |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 467 | |
| 468 | /* |
| 469 | * Exception vectors. |
| 470 | */ |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 471 | #define STD_EXCEPTION_PSERIES(vec, label) \ |
Paul Mackerras | 673b189 | 2011-04-05 13:59:58 +1000 | [diff] [blame] | 472 | SET_SCRATCH0(r13); /* save r13 */ \ |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 473 | EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label, \ |
| 474 | EXC_STD, KVMTEST_PR, vec); \ |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 475 | |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 476 | /* Version of above for when we have to branch out-of-line */ |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 477 | #define __OOL_EXCEPTION(vec, label, hdlr) \ |
| 478 | SET_SCRATCH0(r13) \ |
| 479 | EXCEPTION_PROLOG_0(PACA_EXGEN) \ |
| 480 | b hdlr; |
| 481 | |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 482 | #define STD_EXCEPTION_PSERIES_OOL(vec, label) \ |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 483 | EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_PR, vec); \ |
| 484 | EXCEPTION_PROLOG_PSERIES_1(label, EXC_STD) |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 485 | |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 486 | #define STD_EXCEPTION_HV(loc, vec, label) \ |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 487 | SET_SCRATCH0(r13); /* save r13 */ \ |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 488 | EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label, \ |
| 489 | EXC_HV, KVMTEST_HV, vec); |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 490 | |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 491 | #define STD_EXCEPTION_HV_OOL(vec, label) \ |
| 492 | EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, vec); \ |
| 493 | EXCEPTION_PROLOG_PSERIES_1(label, EXC_HV) |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 494 | |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 495 | #define STD_RELON_EXCEPTION_PSERIES(loc, vec, label) \ |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 496 | /* No guest interrupts come through here */ \ |
| 497 | SET_SCRATCH0(r13); /* save r13 */ \ |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 498 | EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label, EXC_STD, NOTEST, vec); |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 499 | |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 500 | #define STD_RELON_EXCEPTION_PSERIES_OOL(vec, label) \ |
Michael Ellerman | c9f6951 | 2013-06-25 17:47:55 +1000 | [diff] [blame] | 501 | EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, vec); \ |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 502 | EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_STD) |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 503 | |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 504 | #define STD_RELON_EXCEPTION_HV(loc, vec, label) \ |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 505 | SET_SCRATCH0(r13); /* save r13 */ \ |
Paul Mackerras | bc35512 | 2017-01-30 21:21:40 +1100 | [diff] [blame] | 506 | EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label, \ |
| 507 | EXC_HV, KVMTEST_HV, vec); |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 508 | |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 509 | #define STD_RELON_EXCEPTION_HV_OOL(vec, label) \ |
Paul Mackerras | bc35512 | 2017-01-30 21:21:40 +1100 | [diff] [blame] | 510 | EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, vec); \ |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 511 | EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_HV) |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 512 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 513 | /* This associate vector numbers with bits in paca->irq_happened */ |
| 514 | #define SOFTEN_VALUE_0x500 PACA_IRQ_EE |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 515 | #define SOFTEN_VALUE_0x900 PACA_IRQ_DEC |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 516 | #define SOFTEN_VALUE_0x980 PACA_IRQ_DEC |
Ian Munsie | 1dbdafe | 2012-11-14 18:49:46 +0000 | [diff] [blame] | 517 | #define SOFTEN_VALUE_0xa00 PACA_IRQ_DBELL |
Ian Munsie | 655bb3f | 2012-11-14 18:49:45 +0000 | [diff] [blame] | 518 | #define SOFTEN_VALUE_0xe80 PACA_IRQ_DBELL |
Mahesh Salgaonkar | 0869b6f | 2014-07-29 18:40:01 +0530 | [diff] [blame] | 519 | #define SOFTEN_VALUE_0xe60 PACA_IRQ_HMI |
Benjamin Herrenschmidt | 9baaef0a | 2016-07-08 16:37:06 +1000 | [diff] [blame] | 520 | #define SOFTEN_VALUE_0xea0 PACA_IRQ_EE |
Madhavan Srinivasan | f442d00 | 2017-12-20 09:25:53 +0530 | [diff] [blame^] | 521 | #define SOFTEN_VALUE_0xf00 PACA_IRQ_PMI |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 522 | |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 523 | #define __SOFTEN_TEST(h, vec, bitmask) \ |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 524 | lbz r10,PACAIRQSOFTMASK(r13); \ |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 525 | andi. r10,r10,bitmask; \ |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 526 | li r10,SOFTEN_VALUE_##vec; \ |
Madhavan Srinivasan | 01417c6 | 2017-12-20 09:25:49 +0530 | [diff] [blame] | 527 | bne masked_##h##interrupt |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 528 | |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 529 | #define _SOFTEN_TEST(h, vec, bitmask) __SOFTEN_TEST(h, vec, bitmask) |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 530 | |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 531 | #define SOFTEN_TEST_PR(vec, bitmask) \ |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 532 | KVMTEST(EXC_STD, vec); \ |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 533 | _SOFTEN_TEST(EXC_STD, vec, bitmask) |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 534 | |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 535 | #define SOFTEN_TEST_HV(vec, bitmask) \ |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 536 | KVMTEST(EXC_HV, vec); \ |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 537 | _SOFTEN_TEST(EXC_HV, vec, bitmask) |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 538 | |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 539 | #define KVMTEST_PR(vec) \ |
| 540 | KVMTEST(EXC_STD, vec) |
| 541 | |
| 542 | #define KVMTEST_HV(vec) \ |
| 543 | KVMTEST(EXC_HV, vec) |
| 544 | |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 545 | #define SOFTEN_NOTEST_PR(vec, bitmask) _SOFTEN_TEST(EXC_STD, vec, bitmask) |
| 546 | #define SOFTEN_NOTEST_HV(vec, bitmask) _SOFTEN_TEST(EXC_HV, vec, bitmask) |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 547 | |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 548 | #define __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra, bitmask) \ |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 549 | SET_SCRATCH0(r13); /* save r13 */ \ |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 550 | EXCEPTION_PROLOG_0(PACA_EXGEN); \ |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 551 | MASKABLE_EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec, bitmask); \ |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 552 | EXCEPTION_PROLOG_PSERIES_1(label, h); |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 553 | |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 554 | #define _MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra, bitmask) \ |
| 555 | __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra, bitmask) |
Benjamin Herrenschmidt | b3e6b5df | 2011-04-05 14:27:11 +1000 | [diff] [blame] | 556 | |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 557 | #define MASKABLE_EXCEPTION_PSERIES(loc, vec, label, bitmask) \ |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 558 | _MASKABLE_EXCEPTION_PSERIES(vec, label, \ |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 559 | EXC_STD, SOFTEN_TEST_PR, bitmask) |
Benjamin Herrenschmidt | b3e6b5df | 2011-04-05 14:27:11 +1000 | [diff] [blame] | 560 | |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 561 | #define MASKABLE_EXCEPTION_PSERIES_OOL(vec, label, bitmask) \ |
| 562 | MASKABLE_EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_PR, vec, bitmask);\ |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 563 | EXCEPTION_PROLOG_PSERIES_1(label, EXC_STD) |
| 564 | |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 565 | #define MASKABLE_EXCEPTION_HV(loc, vec, label, bitmask) \ |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 566 | _MASKABLE_EXCEPTION_PSERIES(vec, label, \ |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 567 | EXC_HV, SOFTEN_TEST_HV, bitmask) |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 568 | |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 569 | #define MASKABLE_EXCEPTION_HV_OOL(vec, label, bitmask) \ |
| 570 | MASKABLE_EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_HV, vec, bitmask);\ |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 571 | EXCEPTION_PROLOG_PSERIES_1(label, EXC_HV) |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 572 | |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 573 | #define __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra, bitmask) \ |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 574 | SET_SCRATCH0(r13); /* save r13 */ \ |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 575 | EXCEPTION_PROLOG_0(PACA_EXGEN); \ |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 576 | MASKABLE_EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec, bitmask); \ |
Michael Ellerman | da2bc46 | 2016-09-30 19:43:18 +1000 | [diff] [blame] | 577 | EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) |
| 578 | |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 579 | #define _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra, bitmask)\ |
| 580 | __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra, bitmask) |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 581 | |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 582 | #define MASKABLE_RELON_EXCEPTION_PSERIES(loc, vec, label, bitmask) \ |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 583 | _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \ |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 584 | EXC_STD, SOFTEN_NOTEST_PR, bitmask) |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 585 | |
Madhavan Srinivasan | f442d00 | 2017-12-20 09:25:53 +0530 | [diff] [blame^] | 586 | #define MASKABLE_RELON_EXCEPTION_PSERIES_OOL(vec, label, bitmask) \ |
| 587 | MASKABLE_EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_NOTEST_PR, vec, bitmask);\ |
| 588 | EXCEPTION_PROLOG_PSERIES_1(label, EXC_STD); |
| 589 | |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 590 | #define MASKABLE_RELON_EXCEPTION_HV(loc, vec, label, bitmask) \ |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 591 | _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \ |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 592 | EXC_HV, SOFTEN_TEST_HV, bitmask) |
Michael Neuling | 4700dfa | 2012-11-02 17:21:28 +1100 | [diff] [blame] | 593 | |
Madhavan Srinivasan | f14e953 | 2017-12-20 09:25:52 +0530 | [diff] [blame] | 594 | #define MASKABLE_RELON_EXCEPTION_HV_OOL(vec, label, bitmask) \ |
| 595 | MASKABLE_EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_NOTEST_HV, vec, bitmask);\ |
Nicholas Piggin | a050d20 | 2017-04-13 19:45:48 +1000 | [diff] [blame] | 596 | EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_HV) |
Paul Mackerras | 1707dd1 | 2013-02-04 18:10:15 +0000 | [diff] [blame] | 597 | |
Benjamin Herrenschmidt | 1b70117 | 2012-03-01 15:42:56 +1100 | [diff] [blame] | 598 | /* |
| 599 | * Our exception common code can be passed various "additions" |
| 600 | * to specify the behaviour of interrupts, whether to kick the |
| 601 | * runlatch, etc... |
| 602 | */ |
| 603 | |
Michael Ellerman | 9daf112 | 2014-07-15 21:15:38 +1000 | [diff] [blame] | 604 | /* |
| 605 | * This addition reconciles our actual IRQ state with the various software |
| 606 | * flags that track it. This may call C code. |
| 607 | */ |
| 608 | #define ADD_RECONCILE RECONCILE_IRQ_STATE(r10,r11) |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 609 | |
Benjamin Herrenschmidt | fe1952f | 2012-03-01 12:45:27 +1100 | [diff] [blame] | 610 | #define ADD_NVGPRS \ |
Anton Blanchard | b1576fe | 2014-02-04 16:04:35 +1100 | [diff] [blame] | 611 | bl save_nvgprs |
Benjamin Herrenschmidt | fe1952f | 2012-03-01 12:45:27 +1100 | [diff] [blame] | 612 | |
| 613 | #define RUNLATCH_ON \ |
| 614 | BEGIN_FTR_SECTION \ |
Stuart Yoder | 9778b69 | 2012-07-05 04:41:35 +0000 | [diff] [blame] | 615 | CURRENT_THREAD_INFO(r3, r1); \ |
Benjamin Herrenschmidt | fe1952f | 2012-03-01 12:45:27 +1100 | [diff] [blame] | 616 | ld r4,TI_LOCAL_FLAGS(r3); \ |
| 617 | andi. r0,r4,_TLF_RUNLATCH; \ |
| 618 | beql ppc64_runlatch_on_trampoline; \ |
| 619 | END_FTR_SECTION_IFSET(CPU_FTR_CTRL) |
| 620 | |
Nicholas Piggin | a3d96f7 | 2016-12-20 04:30:04 +1000 | [diff] [blame] | 621 | #define EXCEPTION_COMMON(area, trap, label, hdlr, ret, additions) \ |
| 622 | EXCEPTION_PROLOG_COMMON(trap, area); \ |
Michael Ellerman | a1d711c | 2014-07-15 21:15:37 +1000 | [diff] [blame] | 623 | /* Volatile regs are potentially clobbered here */ \ |
Benjamin Herrenschmidt | fe1952f | 2012-03-01 12:45:27 +1100 | [diff] [blame] | 624 | additions; \ |
| 625 | addi r3,r1,STACK_FRAME_OVERHEAD; \ |
| 626 | bl hdlr; \ |
| 627 | b ret |
| 628 | |
Nicholas Piggin | b1ee8a3 | 2016-12-20 04:30:06 +1000 | [diff] [blame] | 629 | /* |
| 630 | * Exception where stack is already set in r1, r1 is saved in r10, and it |
| 631 | * continues rather than returns. |
| 632 | */ |
| 633 | #define EXCEPTION_COMMON_NORET_STACK(area, trap, label, hdlr, additions) \ |
| 634 | EXCEPTION_PROLOG_COMMON_1(); \ |
| 635 | EXCEPTION_PROLOG_COMMON_2(area); \ |
| 636 | EXCEPTION_PROLOG_COMMON_3(trap); \ |
| 637 | /* Volatile regs are potentially clobbered here */ \ |
| 638 | additions; \ |
| 639 | addi r3,r1,STACK_FRAME_OVERHEAD; \ |
| 640 | bl hdlr |
| 641 | |
Benjamin Herrenschmidt | fe1952f | 2012-03-01 12:45:27 +1100 | [diff] [blame] | 642 | #define STD_EXCEPTION_COMMON(trap, label, hdlr) \ |
Nicholas Piggin | a3d96f7 | 2016-12-20 04:30:04 +1000 | [diff] [blame] | 643 | EXCEPTION_COMMON(PACA_EXGEN, trap, label, hdlr, \ |
| 644 | ret_from_except, ADD_NVGPRS;ADD_RECONCILE) |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 645 | |
| 646 | /* |
| 647 | * Like STD_EXCEPTION_COMMON, but for exceptions that can occur |
Benjamin Herrenschmidt | 7450f6f | 2012-03-01 10:52:01 +1100 | [diff] [blame] | 648 | * in the idle task and therefore need the special idle handling |
| 649 | * (finish nap and runlatch) |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 650 | */ |
Nicholas Piggin | a3d96f7 | 2016-12-20 04:30:04 +1000 | [diff] [blame] | 651 | #define STD_EXCEPTION_COMMON_ASYNC(trap, label, hdlr) \ |
| 652 | EXCEPTION_COMMON(PACA_EXGEN, trap, label, hdlr, \ |
| 653 | ret_from_except_lite, FINISH_NAP;ADD_RECONCILE;RUNLATCH_ON) |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 654 | |
| 655 | /* |
| 656 | * When the idle code in power4_idle puts the CPU into NAP mode, |
| 657 | * it has to do so in a loop, and relies on the external interrupt |
| 658 | * and decrementer interrupt entry code to get it out of the loop. |
| 659 | * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags |
| 660 | * to signal that it is in the loop and needs help to get out. |
| 661 | */ |
| 662 | #ifdef CONFIG_PPC_970_NAP |
| 663 | #define FINISH_NAP \ |
| 664 | BEGIN_FTR_SECTION \ |
Stuart Yoder | 9778b69 | 2012-07-05 04:41:35 +0000 | [diff] [blame] | 665 | CURRENT_THREAD_INFO(r11, r1); \ |
Stephen Rothwell | f9ff0f3 | 2007-08-22 13:46:44 +1000 | [diff] [blame] | 666 | ld r9,TI_LOCAL_FLAGS(r11); \ |
| 667 | andi. r10,r9,_TLF_NAPPING; \ |
| 668 | bnel power4_fixup_nap; \ |
| 669 | END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP) |
| 670 | #else |
| 671 | #define FINISH_NAP |
| 672 | #endif |
| 673 | |
| 674 | #endif /* _ASM_POWERPC_EXCEPTION_H */ |