0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include <linux/errno.h>
0018 #include <linux/err.h>
0019 #include <asm/cache.h>
0020 #include <asm/unistd.h>
0021 #include <asm/processor.h>
0022 #include <asm/page.h>
0023 #include <asm/mmu.h>
0024 #include <asm/thread_info.h>
0025 #include <asm/code-patching-asm.h>
0026 #include <asm/ppc_asm.h>
0027 #include <asm/asm-offsets.h>
0028 #include <asm/cputable.h>
0029 #include <asm/firmware.h>
0030 #include <asm/bug.h>
0031 #include <asm/ptrace.h>
0032 #include <asm/irqflags.h>
0033 #include <asm/hw_irq.h>
0034 #include <asm/context_tracking.h>
0035 #include <asm/ppc-opcode.h>
0036 #include <asm/barrier.h>
0037 #include <asm/export.h>
0038 #include <asm/asm-compat.h>
0039 #ifdef CONFIG_PPC_BOOK3S
0040 #include <asm/exception-64s.h>
0041 #else
0042 #include <asm/exception-64e.h>
0043 #endif
0044 #include <asm/feature-fixups.h>
0045 #include <asm/kup.h>
0046
0047
0048
0049
0050 .section ".text"
0051
0052 #ifdef CONFIG_PPC_BOOK3S_64
0053
0054 #define FLUSH_COUNT_CACHE \
0055 1: nop; \
0056 patch_site 1b, patch__call_flush_branch_caches1; \
0057 1: nop; \
0058 patch_site 1b, patch__call_flush_branch_caches2; \
0059 1: nop; \
0060 patch_site 1b, patch__call_flush_branch_caches3
0061
0062 .macro nops number
0063 .rept \number
0064 nop
0065 .endr
0066 .endm
0067
0068 .balign 32
0069 .global flush_branch_caches
0070 flush_branch_caches:
0071
0072 mflr r9
0073
0074 // Flush the link stack
0075 .rept 64
0076 bl .+4
0077 .endr
0078 b 1f
0079 nops 6
0080
0081 .balign 32
0082
0083 1: mtlr r9
0084
0085 // If we're just flushing the link stack, return here
0086 3: nop
0087 patch_site 3b patch__flush_link_stack_return
0088
0089 li r9,0x7fff
0090 mtctr r9
0091
0092 PPC_BCCTR_FLUSH
0093
0094 2: nop
0095 patch_site 2b patch__flush_count_cache_return
0096
0097 nops 3
0098
0099 .rept 278
0100 .balign 32
0101 PPC_BCCTR_FLUSH
0102 nops 7
0103 .endr
0104
0105 blr
0106 #else
0107 #define FLUSH_COUNT_CACHE
0108 #endif
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128 .align 7
0129 _GLOBAL(_switch)
0130 mflr r0
0131 std r0,16(r1)
0132 stdu r1,-SWITCH_FRAME_SIZE(r1)
0133
0134 SAVE_NVGPRS(r1)
0135 std r0,_NIP(r1)
0136 mfcr r23
0137 std r23,_CCR(r1)
0138 std r1,KSP(r3)
0139
0140 kuap_check_amr r9, r10
0141
0142 FLUSH_COUNT_CACHE
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168 #ifdef CONFIG_PPC_BOOK3S
0169
0170
0171
0172 DCBT_BOOK3S_STOP_ALL_STREAM_IDS(r6)
0173 #endif
0174
0175 addi r6,r4,-THREAD
0176 std r6,PACACURRENT(r13)
0177 #if defined(CONFIG_STACKPROTECTOR)
0178 ld r6, TASK_CANARY(r6)
0179 std r6, PACA_CANARY(r13)
0180 #endif
0181
0182 ld r8,KSP(r4)
0183 #ifdef CONFIG_PPC_64S_HASH_MMU
0184 BEGIN_MMU_FTR_SECTION
0185 b 2f
0186 END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_RADIX)
0187 BEGIN_FTR_SECTION
0188 clrrdi r6,r8,28
0189 clrrdi r9,r1,28
0190 FTR_SECTION_ELSE
0191 clrrdi r6,r8,40
0192 clrrdi r9,r1,40
0193 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_1T_SEGMENT)
0194 clrldi. r0,r6,2
0195 cmpd cr1,r6,r9
0196 cror eq,4*cr1+eq,eq
0197 beq 2f
0198
0199
0200 ld r7,KSP_VSID(r4)
0201 oris r0,r6,(SLB_ESID_V)@h
0202 ori r0,r0,(SLB_NUM_BOLTED-1)@l
0203 BEGIN_FTR_SECTION
0204 li r9,MMU_SEGSIZE_1T
0205 oris r6,r6,(MMU_SEGSIZE_1T << SLBIE_SSIZE_SHIFT)@h
0206 rldimi r7,r9,SLB_VSID_SSIZE_SHIFT,0
0207 END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
0208
0209
0210
0211
0212
0213 ld r9,PACA_SLBSHADOWPTR(r13)
0214 li r12,0
0215 std r12,SLBSHADOW_STACKESID(r9)
0216 li r12,SLBSHADOW_STACKVSID
0217 STDX_BE r7,r12,r9
0218 li r12,SLBSHADOW_STACKESID
0219 STDX_BE r0,r12,r9
0220
0221
0222
0223
0224
0225
0226
0227 isync
0228 slbie r6
0229 BEGIN_FTR_SECTION
0230 slbie r6
0231 END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
0232 slbmte r7,r0
0233 isync
0234 2:
0235 #endif
0236
0237 clrrdi r7, r8, THREAD_SHIFT
0238
0239
0240
0241 addi r7,r7,THREAD_SIZE-SWITCH_FRAME_SIZE
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251 mr r1,r8
0252 std r7,PACAKSAVE(r13)
0253
0254 ld r6,_CCR(r1)
0255 mtcrf 0xFF,r6
0256
0257
0258 REST_NVGPRS(r1)
0259
0260
0261 addi r3,r3,-THREAD
0262 ld r7,_NIP(r1)
0263 mtlr r7
0264 addi r1,r1,SWITCH_FRAME_SIZE
0265 blr
0266
0267 _GLOBAL(enter_prom)
0268 mflr r0
0269 std r0,16(r1)
0270 stdu r1,-SWITCH_FRAME_SIZE(r1)
0271
0272
0273
0274
0275
0276 SAVE_GPR(2, r1)
0277 SAVE_GPR(13, r1)
0278 SAVE_NVGPRS(r1)
0279 mfcr r10
0280 mfmsr r11
0281 std r10,_CCR(r1)
0282 std r11,_MSR(r1)
0283
0284
0285 mtsrr0 r4
0286
0287
0288 bcl 20,31,$+4
0289 0: mflr r4
0290 addi r4,r4,(1f - 0b)
0291 mtlr r4
0292
0293
0294
0295 #ifdef CONFIG_PPC_BOOK3E
0296 rlwinm r11,r11,0,1,31
0297 mtsrr1 r11
0298 rfi
0299 #else
0300 LOAD_REG_IMMEDIATE(r12, MSR_SF | MSR_LE)
0301 andc r11,r11,r12
0302 mtsrr1 r11
0303 RFI_TO_KERNEL
0304 #endif
0305
0306 1:
0307 FIXUP_ENDIAN
0308
0309
0310
0311
0312 rldicl r1,r1,0,32
0313
0314
0315 ld r0,_MSR(r1)
0316 MTMSRD(r0)
0317 isync
0318
0319
0320 REST_GPR(2, r1)
0321 REST_GPR(13, r1)
0322 REST_NVGPRS(r1)
0323 ld r4,_CCR(r1)
0324 mtcr r4
0325
0326 addi r1,r1,SWITCH_FRAME_SIZE
0327 ld r0,16(r1)
0328 mtlr r0
0329 blr