/* SPDX-License-Identifier: GPL-2.0-or-later */1/*2* Copyright (C) 2001,2002,2003 Broadcom Corporation3*/45#include <asm/asm.h>6#include <asm/regdef.h>7#include <asm/mipsregs.h>8#include <asm/stackframe.h>9#include <asm/cacheops.h>10#include <asm/sibyte/board.h>1112#define C0_ERRCTL $26 /* CP0: Error info */13#define C0_CERR_I $27 /* CP0: Icache error */14#define C0_CERR_D $27,1 /* CP0: Dcache error */1516/*17* Based on SiByte sample software cache-err/cerr.S18* CVS revision 1.8. Only the 'unrecoverable' case19* is changed.20*/2122.set mips6423.set noreorder24.set noat2526/*27* sb1_cerr_vec: code to be copied to the Cache Error28* Exception vector. The code must be pushed out to memory29* (either by copying to Kseg0 and Kseg1 both, or by flushing30* the L1 and L2) since it is fetched as 0xa0000100.31*32* NOTE: Be sure this handler is at most 28 instructions long33* since the final 16 bytes of the exception vector memory34* (0x170-0x17f) are used to preserve k0, k1, and ra.35*/3637LEAF(except_vec2_sb1)38/*39* If this error is recoverable, we need to exit the handler40* without having dirtied any registers. To do this,41* save/restore k0 and k1 from low memory (Useg is direct42* mapped while ERL=1). Note that we can't save to a43* CPU-specific location without ruining a register in the44* process. This means we are vulnerable to data corruption45* whenever the handler is reentered by a second CPU.46*/47sd k0,0x170($0)48sd k1,0x178($0)4950#ifdef CONFIG_SB1_CEX_ALWAYS_FATAL51j handle_vec2_sb152nop53#else54/*55* M_ERRCTL_RECOVERABLE is bit 31, which makes it easy to tell56* if we can fast-path out of here for a h/w-recovered error.57*/58mfc0 k1,C0_ERRCTL59bgtz k1,attempt_recovery60sll k0,k1,16162recovered_dcache:63/*64* Unlock CacheErr-D (which in turn unlocks CacheErr-DPA).65* Ought to log the occurrence of this recovered dcache error.66*/67b recovered68mtc0 $0,C0_CERR_D6970attempt_recovery:71/*72* k0 has C0_ERRCTL << 1, which puts 'DC' at bit 31. Any73* Dcache errors we can recover from will take more extensive74* processing. For now, they are considered "unrecoverable".75* Note that 'DC' becoming set (outside of ERL mode) will76* cause 'IC' to clear; so if there's an Icache error, we'll77* only find out about it if we recover from this error and78* continue executing.79*/80bltz k0,unrecoverable81sll k0,18283/*84* k0 has C0_ERRCTL << 2, which puts 'IC' at bit 31. If an85* Icache error isn't indicated, I'm not sure why we got here.86* Consider that case "unrecoverable" for now.87*/88bgez k0,unrecoverable8990attempt_icache_recovery:91/*92* External icache errors are due to uncorrectable ECC errors93* in the L2 cache or Memory Controller and cannot be94* recovered here.95*/96mfc0 k0,C0_CERR_I /* delay slot */97li k1,1 << 26 /* ICACHE_EXTERNAL */98and k1,k099bnez k1,unrecoverable100andi k0,0x1fe0101102/*103* Since the error is internal, the 'IDX' field from104* CacheErr-I is valid and we can just invalidate all blocks105* in that set.106*/107cache Index_Invalidate_I,(0<<13)(k0)108cache Index_Invalidate_I,(1<<13)(k0)109cache Index_Invalidate_I,(2<<13)(k0)110cache Index_Invalidate_I,(3<<13)(k0)111112/* Ought to log this recovered icache error */113114recovered:115/* Restore the saved registers */116ld k0,0x170($0)117ld k1,0x178($0)118eret119120unrecoverable:121/* Unrecoverable Icache or Dcache error; log it and/or fail */122j handle_vec2_sb1123nop124#endif125126END(except_vec2_sb1)127128LEAF(handle_vec2_sb1)129mfc0 k0,CP0_CONFIG130li k1,~CONF_CM_CMASK131and k0,k0,k1132ori k0,k0,CONF_CM_UNCACHED133mtc0 k0,CP0_CONFIG134135SSNOP136SSNOP137SSNOP138SSNOP139bnezl $0, 1f1401:141mfc0 k0, CP0_STATUS142sll k0, k0, 3 # check CU0 (kernel?)143bltz k0, 2f144nop145146/* Get a valid Kseg0 stack pointer. Any task's stack pointer147* will do, although if we ever want to resume execution we148* better not have corrupted any state. */149get_saved_sp150move sp, k11511522:153j sb1_cache_error154nop155156END(handle_vec2_sb1)157158159