18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2001,2002,2003 Broadcom Corporation 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#include <asm/asm.h> 78c2ecf20Sopenharmony_ci#include <asm/regdef.h> 88c2ecf20Sopenharmony_ci#include <asm/mipsregs.h> 98c2ecf20Sopenharmony_ci#include <asm/stackframe.h> 108c2ecf20Sopenharmony_ci#include <asm/cacheops.h> 118c2ecf20Sopenharmony_ci#include <asm/sibyte/board.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#define C0_ERRCTL $26 /* CP0: Error info */ 148c2ecf20Sopenharmony_ci#define C0_CERR_I $27 /* CP0: Icache error */ 158c2ecf20Sopenharmony_ci#define C0_CERR_D $27,1 /* CP0: Dcache error */ 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci /* 188c2ecf20Sopenharmony_ci * Based on SiByte sample software cache-err/cerr.S 198c2ecf20Sopenharmony_ci * CVS revision 1.8. Only the 'unrecoverable' case 208c2ecf20Sopenharmony_ci * is changed. 218c2ecf20Sopenharmony_ci */ 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci .set mips64 248c2ecf20Sopenharmony_ci .set noreorder 258c2ecf20Sopenharmony_ci .set noat 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci /* 288c2ecf20Sopenharmony_ci * sb1_cerr_vec: code to be copied to the Cache Error 298c2ecf20Sopenharmony_ci * Exception vector. The code must be pushed out to memory 308c2ecf20Sopenharmony_ci * (either by copying to Kseg0 and Kseg1 both, or by flushing 318c2ecf20Sopenharmony_ci * the L1 and L2) since it is fetched as 0xa0000100. 328c2ecf20Sopenharmony_ci * 338c2ecf20Sopenharmony_ci * NOTE: Be sure this handler is at most 28 instructions long 348c2ecf20Sopenharmony_ci * since the final 16 bytes of the exception vector memory 358c2ecf20Sopenharmony_ci * (0x170-0x17f) are used to preserve k0, k1, and ra. 368c2ecf20Sopenharmony_ci */ 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ciLEAF(except_vec2_sb1) 398c2ecf20Sopenharmony_ci /* 408c2ecf20Sopenharmony_ci * If this error is recoverable, we need to exit the handler 418c2ecf20Sopenharmony_ci * without having dirtied any registers. To do this, 428c2ecf20Sopenharmony_ci * save/restore k0 and k1 from low memory (Useg is direct 438c2ecf20Sopenharmony_ci * mapped while ERL=1). Note that we can't save to a 448c2ecf20Sopenharmony_ci * CPU-specific location without ruining a register in the 458c2ecf20Sopenharmony_ci * process. This means we are vulnerable to data corruption 468c2ecf20Sopenharmony_ci * whenever the handler is reentered by a second CPU. 478c2ecf20Sopenharmony_ci */ 488c2ecf20Sopenharmony_ci sd k0,0x170($0) 498c2ecf20Sopenharmony_ci sd k1,0x178($0) 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci#ifdef CONFIG_SB1_CEX_ALWAYS_FATAL 528c2ecf20Sopenharmony_ci j handle_vec2_sb1 538c2ecf20Sopenharmony_ci nop 548c2ecf20Sopenharmony_ci#else 558c2ecf20Sopenharmony_ci /* 568c2ecf20Sopenharmony_ci * M_ERRCTL_RECOVERABLE is bit 31, which makes it easy to tell 578c2ecf20Sopenharmony_ci * if we can fast-path out of here for a h/w-recovered error. 588c2ecf20Sopenharmony_ci */ 598c2ecf20Sopenharmony_ci mfc0 k1,C0_ERRCTL 608c2ecf20Sopenharmony_ci bgtz k1,attempt_recovery 618c2ecf20Sopenharmony_ci sll k0,k1,1 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_cirecovered_dcache: 648c2ecf20Sopenharmony_ci /* 658c2ecf20Sopenharmony_ci * Unlock CacheErr-D (which in turn unlocks CacheErr-DPA). 668c2ecf20Sopenharmony_ci * Ought to log the occurrence of this recovered dcache error. 678c2ecf20Sopenharmony_ci */ 688c2ecf20Sopenharmony_ci b recovered 698c2ecf20Sopenharmony_ci mtc0 $0,C0_CERR_D 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ciattempt_recovery: 728c2ecf20Sopenharmony_ci /* 738c2ecf20Sopenharmony_ci * k0 has C0_ERRCTL << 1, which puts 'DC' at bit 31. Any 748c2ecf20Sopenharmony_ci * Dcache errors we can recover from will take more extensive 758c2ecf20Sopenharmony_ci * processing. For now, they are considered "unrecoverable". 768c2ecf20Sopenharmony_ci * Note that 'DC' becoming set (outside of ERL mode) will 778c2ecf20Sopenharmony_ci * cause 'IC' to clear; so if there's an Icache error, we'll 788c2ecf20Sopenharmony_ci * only find out about it if we recover from this error and 798c2ecf20Sopenharmony_ci * continue executing. 808c2ecf20Sopenharmony_ci */ 818c2ecf20Sopenharmony_ci bltz k0,unrecoverable 828c2ecf20Sopenharmony_ci sll k0,1 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci /* 858c2ecf20Sopenharmony_ci * k0 has C0_ERRCTL << 2, which puts 'IC' at bit 31. If an 868c2ecf20Sopenharmony_ci * Icache error isn't indicated, I'm not sure why we got here. 878c2ecf20Sopenharmony_ci * Consider that case "unrecoverable" for now. 888c2ecf20Sopenharmony_ci */ 898c2ecf20Sopenharmony_ci bgez k0,unrecoverable 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ciattempt_icache_recovery: 928c2ecf20Sopenharmony_ci /* 938c2ecf20Sopenharmony_ci * External icache errors are due to uncorrectable ECC errors 948c2ecf20Sopenharmony_ci * in the L2 cache or Memory Controller and cannot be 958c2ecf20Sopenharmony_ci * recovered here. 968c2ecf20Sopenharmony_ci */ 978c2ecf20Sopenharmony_ci mfc0 k0,C0_CERR_I /* delay slot */ 988c2ecf20Sopenharmony_ci li k1,1 << 26 /* ICACHE_EXTERNAL */ 998c2ecf20Sopenharmony_ci and k1,k0 1008c2ecf20Sopenharmony_ci bnez k1,unrecoverable 1018c2ecf20Sopenharmony_ci andi k0,0x1fe0 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci /* 1048c2ecf20Sopenharmony_ci * Since the error is internal, the 'IDX' field from 1058c2ecf20Sopenharmony_ci * CacheErr-I is valid and we can just invalidate all blocks 1068c2ecf20Sopenharmony_ci * in that set. 1078c2ecf20Sopenharmony_ci */ 1088c2ecf20Sopenharmony_ci cache Index_Invalidate_I,(0<<13)(k0) 1098c2ecf20Sopenharmony_ci cache Index_Invalidate_I,(1<<13)(k0) 1108c2ecf20Sopenharmony_ci cache Index_Invalidate_I,(2<<13)(k0) 1118c2ecf20Sopenharmony_ci cache Index_Invalidate_I,(3<<13)(k0) 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci /* Ought to log this recovered icache error */ 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_cirecovered: 1168c2ecf20Sopenharmony_ci /* Restore the saved registers */ 1178c2ecf20Sopenharmony_ci ld k0,0x170($0) 1188c2ecf20Sopenharmony_ci ld k1,0x178($0) 1198c2ecf20Sopenharmony_ci eret 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ciunrecoverable: 1228c2ecf20Sopenharmony_ci /* Unrecoverable Icache or Dcache error; log it and/or fail */ 1238c2ecf20Sopenharmony_ci j handle_vec2_sb1 1248c2ecf20Sopenharmony_ci nop 1258c2ecf20Sopenharmony_ci#endif 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ciEND(except_vec2_sb1) 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci LEAF(handle_vec2_sb1) 1308c2ecf20Sopenharmony_ci mfc0 k0,CP0_CONFIG 1318c2ecf20Sopenharmony_ci li k1,~CONF_CM_CMASK 1328c2ecf20Sopenharmony_ci and k0,k0,k1 1338c2ecf20Sopenharmony_ci ori k0,k0,CONF_CM_UNCACHED 1348c2ecf20Sopenharmony_ci mtc0 k0,CP0_CONFIG 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci SSNOP 1378c2ecf20Sopenharmony_ci SSNOP 1388c2ecf20Sopenharmony_ci SSNOP 1398c2ecf20Sopenharmony_ci SSNOP 1408c2ecf20Sopenharmony_ci bnezl $0, 1f 1418c2ecf20Sopenharmony_ci1: 1428c2ecf20Sopenharmony_ci mfc0 k0, CP0_STATUS 1438c2ecf20Sopenharmony_ci sll k0, k0, 3 # check CU0 (kernel?) 1448c2ecf20Sopenharmony_ci bltz k0, 2f 1458c2ecf20Sopenharmony_ci nop 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci /* Get a valid Kseg0 stack pointer. Any task's stack pointer 1488c2ecf20Sopenharmony_ci * will do, although if we ever want to resume execution we 1498c2ecf20Sopenharmony_ci * better not have corrupted any state. */ 1508c2ecf20Sopenharmony_ci get_saved_sp 1518c2ecf20Sopenharmony_ci move sp, k1 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci2: 1548c2ecf20Sopenharmony_ci j sb1_cache_error 1558c2ecf20Sopenharmony_ci nop 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci END(handle_vec2_sb1) 158