162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2001,2002,2003 Broadcom Corporation 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#include <asm/asm.h> 762306a36Sopenharmony_ci#include <asm/regdef.h> 862306a36Sopenharmony_ci#include <asm/mipsregs.h> 962306a36Sopenharmony_ci#include <asm/stackframe.h> 1062306a36Sopenharmony_ci#include <asm/cacheops.h> 1162306a36Sopenharmony_ci#include <asm/sibyte/board.h> 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#define C0_ERRCTL $26 /* CP0: Error info */ 1462306a36Sopenharmony_ci#define C0_CERR_I $27 /* CP0: Icache error */ 1562306a36Sopenharmony_ci#define C0_CERR_D $27,1 /* CP0: Dcache error */ 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci /* 1862306a36Sopenharmony_ci * Based on SiByte sample software cache-err/cerr.S 1962306a36Sopenharmony_ci * CVS revision 1.8. Only the 'unrecoverable' case 2062306a36Sopenharmony_ci * is changed. 2162306a36Sopenharmony_ci */ 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci .set mips64 2462306a36Sopenharmony_ci .set noreorder 2562306a36Sopenharmony_ci .set noat 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci /* 2862306a36Sopenharmony_ci * sb1_cerr_vec: code to be copied to the Cache Error 2962306a36Sopenharmony_ci * Exception vector. The code must be pushed out to memory 3062306a36Sopenharmony_ci * (either by copying to Kseg0 and Kseg1 both, or by flushing 3162306a36Sopenharmony_ci * the L1 and L2) since it is fetched as 0xa0000100. 3262306a36Sopenharmony_ci * 3362306a36Sopenharmony_ci * NOTE: Be sure this handler is at most 28 instructions long 3462306a36Sopenharmony_ci * since the final 16 bytes of the exception vector memory 3562306a36Sopenharmony_ci * (0x170-0x17f) are used to preserve k0, k1, and ra. 3662306a36Sopenharmony_ci */ 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ciLEAF(except_vec2_sb1) 3962306a36Sopenharmony_ci /* 4062306a36Sopenharmony_ci * If this error is recoverable, we need to exit the handler 4162306a36Sopenharmony_ci * without having dirtied any registers. To do this, 4262306a36Sopenharmony_ci * save/restore k0 and k1 from low memory (Useg is direct 4362306a36Sopenharmony_ci * mapped while ERL=1). Note that we can't save to a 4462306a36Sopenharmony_ci * CPU-specific location without ruining a register in the 4562306a36Sopenharmony_ci * process. This means we are vulnerable to data corruption 4662306a36Sopenharmony_ci * whenever the handler is reentered by a second CPU. 4762306a36Sopenharmony_ci */ 4862306a36Sopenharmony_ci sd k0,0x170($0) 4962306a36Sopenharmony_ci sd k1,0x178($0) 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci#ifdef CONFIG_SB1_CEX_ALWAYS_FATAL 5262306a36Sopenharmony_ci j handle_vec2_sb1 5362306a36Sopenharmony_ci nop 5462306a36Sopenharmony_ci#else 5562306a36Sopenharmony_ci /* 5662306a36Sopenharmony_ci * M_ERRCTL_RECOVERABLE is bit 31, which makes it easy to tell 5762306a36Sopenharmony_ci * if we can fast-path out of here for a h/w-recovered error. 5862306a36Sopenharmony_ci */ 5962306a36Sopenharmony_ci mfc0 k1,C0_ERRCTL 6062306a36Sopenharmony_ci bgtz k1,attempt_recovery 6162306a36Sopenharmony_ci sll k0,k1,1 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_cirecovered_dcache: 6462306a36Sopenharmony_ci /* 6562306a36Sopenharmony_ci * Unlock CacheErr-D (which in turn unlocks CacheErr-DPA). 6662306a36Sopenharmony_ci * Ought to log the occurrence of this recovered dcache error. 6762306a36Sopenharmony_ci */ 6862306a36Sopenharmony_ci b recovered 6962306a36Sopenharmony_ci mtc0 $0,C0_CERR_D 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ciattempt_recovery: 7262306a36Sopenharmony_ci /* 7362306a36Sopenharmony_ci * k0 has C0_ERRCTL << 1, which puts 'DC' at bit 31. Any 7462306a36Sopenharmony_ci * Dcache errors we can recover from will take more extensive 7562306a36Sopenharmony_ci * processing. For now, they are considered "unrecoverable". 7662306a36Sopenharmony_ci * Note that 'DC' becoming set (outside of ERL mode) will 7762306a36Sopenharmony_ci * cause 'IC' to clear; so if there's an Icache error, we'll 7862306a36Sopenharmony_ci * only find out about it if we recover from this error and 7962306a36Sopenharmony_ci * continue executing. 8062306a36Sopenharmony_ci */ 8162306a36Sopenharmony_ci bltz k0,unrecoverable 8262306a36Sopenharmony_ci sll k0,1 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci /* 8562306a36Sopenharmony_ci * k0 has C0_ERRCTL << 2, which puts 'IC' at bit 31. If an 8662306a36Sopenharmony_ci * Icache error isn't indicated, I'm not sure why we got here. 8762306a36Sopenharmony_ci * Consider that case "unrecoverable" for now. 8862306a36Sopenharmony_ci */ 8962306a36Sopenharmony_ci bgez k0,unrecoverable 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ciattempt_icache_recovery: 9262306a36Sopenharmony_ci /* 9362306a36Sopenharmony_ci * External icache errors are due to uncorrectable ECC errors 9462306a36Sopenharmony_ci * in the L2 cache or Memory Controller and cannot be 9562306a36Sopenharmony_ci * recovered here. 9662306a36Sopenharmony_ci */ 9762306a36Sopenharmony_ci mfc0 k0,C0_CERR_I /* delay slot */ 9862306a36Sopenharmony_ci li k1,1 << 26 /* ICACHE_EXTERNAL */ 9962306a36Sopenharmony_ci and k1,k0 10062306a36Sopenharmony_ci bnez k1,unrecoverable 10162306a36Sopenharmony_ci andi k0,0x1fe0 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci /* 10462306a36Sopenharmony_ci * Since the error is internal, the 'IDX' field from 10562306a36Sopenharmony_ci * CacheErr-I is valid and we can just invalidate all blocks 10662306a36Sopenharmony_ci * in that set. 10762306a36Sopenharmony_ci */ 10862306a36Sopenharmony_ci cache Index_Invalidate_I,(0<<13)(k0) 10962306a36Sopenharmony_ci cache Index_Invalidate_I,(1<<13)(k0) 11062306a36Sopenharmony_ci cache Index_Invalidate_I,(2<<13)(k0) 11162306a36Sopenharmony_ci cache Index_Invalidate_I,(3<<13)(k0) 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci /* Ought to log this recovered icache error */ 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_cirecovered: 11662306a36Sopenharmony_ci /* Restore the saved registers */ 11762306a36Sopenharmony_ci ld k0,0x170($0) 11862306a36Sopenharmony_ci ld k1,0x178($0) 11962306a36Sopenharmony_ci eret 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ciunrecoverable: 12262306a36Sopenharmony_ci /* Unrecoverable Icache or Dcache error; log it and/or fail */ 12362306a36Sopenharmony_ci j handle_vec2_sb1 12462306a36Sopenharmony_ci nop 12562306a36Sopenharmony_ci#endif 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ciEND(except_vec2_sb1) 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci LEAF(handle_vec2_sb1) 13062306a36Sopenharmony_ci mfc0 k0,CP0_CONFIG 13162306a36Sopenharmony_ci li k1,~CONF_CM_CMASK 13262306a36Sopenharmony_ci and k0,k0,k1 13362306a36Sopenharmony_ci ori k0,k0,CONF_CM_UNCACHED 13462306a36Sopenharmony_ci mtc0 k0,CP0_CONFIG 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci SSNOP 13762306a36Sopenharmony_ci SSNOP 13862306a36Sopenharmony_ci SSNOP 13962306a36Sopenharmony_ci SSNOP 14062306a36Sopenharmony_ci bnezl $0, 1f 14162306a36Sopenharmony_ci1: 14262306a36Sopenharmony_ci mfc0 k0, CP0_STATUS 14362306a36Sopenharmony_ci sll k0, k0, 3 # check CU0 (kernel?) 14462306a36Sopenharmony_ci bltz k0, 2f 14562306a36Sopenharmony_ci nop 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ci /* Get a valid Kseg0 stack pointer. Any task's stack pointer 14862306a36Sopenharmony_ci * will do, although if we ever want to resume execution we 14962306a36Sopenharmony_ci * better not have corrupted any state. */ 15062306a36Sopenharmony_ci get_saved_sp 15162306a36Sopenharmony_ci move sp, k1 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_ci2: 15462306a36Sopenharmony_ci j sb1_cache_error 15562306a36Sopenharmony_ci nop 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ci END(handle_vec2_sb1) 158