/*1* Copyright (C) 2001,2002,2003 Broadcom Corporation2*3* This program is free software; you can redistribute it and/or4* modify it under the terms of the GNU General Public License5* as published by the Free Software Foundation; either version 26* of the License, or (at your option) any later version.7*8* This program is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11* GNU General Public License for more details.12*13* You should have received a copy of the GNU General Public License14* along with this program; if not, write to the Free Software15* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.16*/17#include <linux/init.h>1819#include <asm/asm.h>20#include <asm/regdef.h>21#include <asm/mipsregs.h>22#include <asm/stackframe.h>23#include <asm/cacheops.h>24#include <asm/sibyte/board.h>2526#define C0_ERRCTL $26 /* CP0: Error info */27#define C0_CERR_I $27 /* CP0: Icache error */28#define C0_CERR_D $27,1 /* CP0: Dcache error */2930/*31* Based on SiByte sample software cache-err/cerr.S32* CVS revision 1.8. Only the 'unrecoverable' case33* is changed.34*/3536.set mips6437.set noreorder38.set noat3940/*41* sb1_cerr_vec: code to be copied to the Cache Error42* Exception vector. The code must be pushed out to memory43* (either by copying to Kseg0 and Kseg1 both, or by flushing44* the L1 and L2) since it is fetched as 0xa0000100.45*46* NOTE: Be sure this handler is at most 28 instructions long47* since the final 16 bytes of the exception vector memory48* (0x170-0x17f) are used to preserve k0, k1, and ra.49*/5051__CPUINIT5253LEAF(except_vec2_sb1)54/*55* If this error is recoverable, we need to exit the handler56* without having dirtied any registers. To do this,57* save/restore k0 and k1 from low memory (Useg is direct58* mapped while ERL=1). Note that we can't save to a59* CPU-specific location without ruining a register in the60* process. This means we are vulnerable to data corruption61* whenever the handler is reentered by a second CPU.62*/63sd k0,0x170($0)64sd k1,0x178($0)6566#ifdef CONFIG_SB1_CEX_ALWAYS_FATAL67j handle_vec2_sb168nop69#else70/*71* M_ERRCTL_RECOVERABLE is bit 31, which makes it easy to tell72* if we can fast-path out of here for a h/w-recovered error.73*/74mfc0 k1,C0_ERRCTL75bgtz k1,attempt_recovery76sll k0,k1,17778recovered_dcache:79/*80* Unlock CacheErr-D (which in turn unlocks CacheErr-DPA).81* Ought to log the occurrence of this recovered dcache error.82*/83b recovered84mtc0 $0,C0_CERR_D8586attempt_recovery:87/*88* k0 has C0_ERRCTL << 1, which puts 'DC' at bit 31. Any89* Dcache errors we can recover from will take more extensive90* processing. For now, they are considered "unrecoverable".91* Note that 'DC' becoming set (outside of ERL mode) will92* cause 'IC' to clear; so if there's an Icache error, we'll93* only find out about it if we recover from this error and94* continue executing.95*/96bltz k0,unrecoverable97sll k0,19899/*100* k0 has C0_ERRCTL << 2, which puts 'IC' at bit 31. If an101* Icache error isn't indicated, I'm not sure why we got here.102* Consider that case "unrecoverable" for now.103*/104bgez k0,unrecoverable105106attempt_icache_recovery:107/*108* External icache errors are due to uncorrectable ECC errors109* in the L2 cache or Memory Controller and cannot be110* recovered here.111*/112mfc0 k0,C0_CERR_I /* delay slot */113li k1,1 << 26 /* ICACHE_EXTERNAL */114and k1,k0115bnez k1,unrecoverable116andi k0,0x1fe0117118/*119* Since the error is internal, the 'IDX' field from120* CacheErr-I is valid and we can just invalidate all blocks121* in that set.122*/123cache Index_Invalidate_I,(0<<13)(k0)124cache Index_Invalidate_I,(1<<13)(k0)125cache Index_Invalidate_I,(2<<13)(k0)126cache Index_Invalidate_I,(3<<13)(k0)127128/* Ought to log this recovered icache error */129130recovered:131/* Restore the saved registers */132ld k0,0x170($0)133ld k1,0x178($0)134eret135136unrecoverable:137/* Unrecoverable Icache or Dcache error; log it and/or fail */138j handle_vec2_sb1139nop140#endif141142END(except_vec2_sb1)143144__FINIT145146LEAF(handle_vec2_sb1)147mfc0 k0,CP0_CONFIG148li k1,~CONF_CM_CMASK149and k0,k0,k1150ori k0,k0,CONF_CM_UNCACHED151mtc0 k0,CP0_CONFIG152153SSNOP154SSNOP155SSNOP156SSNOP157bnezl $0, 1f1581:159mfc0 k0, CP0_STATUS160sll k0, k0, 3 # check CU0 (kernel?)161bltz k0, 2f162nop163164/* Get a valid Kseg0 stack pointer. Any task's stack pointer165* will do, although if we ever want to resume execution we166* better not have corrupted any state. */167get_saved_sp168move sp, k11691702:171j sb1_cache_error172nop173174END(handle_vec2_sb1)175176177