RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / arch / mips / mm / cex-sb1.S
blobb6892864b909265de766dc1d9ac00911fe60b02e
1 /*
2  * Copyright (C) 2001,2002,2003 Broadcom Corporation
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  */
18 #include <linux/init.h>
20 #include <asm/asm.h>
21 #include <asm/regdef.h>
22 #include <asm/mipsregs.h>
23 #include <asm/stackframe.h>
24 #include <asm/cacheops.h>
25 #include <asm/sibyte/board.h>
27 #define C0_ERRCTL     $26             /* CP0: Error info */
28 #define C0_CERR_I     $27             /* CP0: Icache error */
29 #define C0_CERR_D     $27,1           /* CP0: Dcache error */
31         /*
32          * Based on SiByte sample software cache-err/cerr.S
33          * CVS revision 1.8.  Only the 'unrecoverable' case
34          * is changed.
35          */
37         .set    mips64
38         .set    noreorder
39         .set    noat
41         /*
42          * sb1_cerr_vec: code to be copied to the Cache Error
43          * Exception vector.  The code must be pushed out to memory
44          * (either by copying to Kseg0 and Kseg1 both, or by flushing
45          * the L1 and L2) since it is fetched as 0xa0000100.
46          *
47          * NOTE: Be sure this handler is at most 28 instructions long
48          * since the final 16 bytes of the exception vector memory
49          * (0x170-0x17f) are used to preserve k0, k1, and ra.
50          */
52 #ifndef CONFIG_HOTPLUG_CPU
53         __INIT                  /* no __CPUINIT; it's a 2.6.25 thing  */
54 #endif
56 LEAF(except_vec2_sb1)
57         /*
58          * If this error is recoverable, we need to exit the handler
59          * without having dirtied any registers.  To do this,
60          * save/restore k0 and k1 from low memory (Useg is direct
61          * mapped while ERL=1). Note that we can't save to a
62          * CPU-specific location without ruining a register in the
63          * process.  This means we are vulnerable to data corruption
64          * whenever the handler is reentered by a second CPU.
65          */
66         sd      k0,0x170($0)
67         sd      k1,0x178($0)
69 #ifdef CONFIG_SB1_CEX_ALWAYS_FATAL
70         j       handle_vec2_sb1
71          nop
72 #else
73         /*
74          * M_ERRCTL_RECOVERABLE is bit 31, which makes it easy to tell
75          * if we can fast-path out of here for a h/w-recovered error.
76          */
77         mfc0    k1,C0_ERRCTL
78         bgtz    k1,attempt_recovery
79          sll    k0,k1,1
81 recovered_dcache:
82         /*
83          * Unlock CacheErr-D (which in turn unlocks CacheErr-DPA).
84          * Ought to log the occurence of this recovered dcache error.
85          */
86         b       recovered
87          mtc0   $0,C0_CERR_D
89 attempt_recovery:
90         /*
91          * k0 has C0_ERRCTL << 1, which puts 'DC' at bit 31.  Any
92          * Dcache errors we can recover from will take more extensive
93          * processing.  For now, they are considered "unrecoverable".
94          * Note that 'DC' becoming set (outside of ERL mode) will
95          * cause 'IC' to clear; so if there's an Icache error, we'll
96          * only find out about it if we recover from this error and
97          * continue executing.
98          */
99         bltz    k0,unrecoverable
100          sll    k0,1
102         /*
103          * k0 has C0_ERRCTL << 2, which puts 'IC' at bit 31.  If an
104          * Icache error isn't indicated, I'm not sure why we got here.
105          * Consider that case "unrecoverable" for now.
106          */
107         bgez    k0,unrecoverable
109 attempt_icache_recovery:
110         /*
111          * External icache errors are due to uncorrectable ECC errors
112          * in the L2 cache or Memory Controller and cannot be
113          * recovered here.
114          */
115          mfc0   k0,C0_CERR_I            /* delay slot */
116         li      k1,1 << 26              /* ICACHE_EXTERNAL */
117         and     k1,k0
118         bnez    k1,unrecoverable
119          andi   k0,0x1fe0
121         /*
122          * Since the error is internal, the 'IDX' field from
123          * CacheErr-I is valid and we can just invalidate all blocks
124          * in that set.
125          */
126         cache   Index_Invalidate_I,(0<<13)(k0)
127         cache   Index_Invalidate_I,(1<<13)(k0)
128         cache   Index_Invalidate_I,(2<<13)(k0)
129         cache   Index_Invalidate_I,(3<<13)(k0)
131         /* Ought to log this recovered icache error */
133 recovered:
134         /* Restore the saved registers */
135         ld      k0,0x170($0)
136         ld      k1,0x178($0)
137         eret
139 unrecoverable:
140         /* Unrecoverable Icache or Dcache error; log it and/or fail */
141         j       handle_vec2_sb1
142          nop
143 #endif
145 END(except_vec2_sb1)
147 #ifndef CONFIG_HOTPLUG_CPU
148         __FINIT
149 #endif
151         LEAF(handle_vec2_sb1)
152         mfc0    k0,CP0_CONFIG
153         li      k1,~CONF_CM_CMASK
154         and     k0,k0,k1
155         ori     k0,k0,CONF_CM_UNCACHED
156         mtc0    k0,CP0_CONFIG
158         SSNOP
159         SSNOP
160         SSNOP
161         SSNOP
162         bnezl   $0, 1f
164         mfc0    k0, CP0_STATUS
165         sll     k0, k0, 3                       # check CU0 (kernel?)
166         bltz    k0, 2f
167          nop
169         /* Get a valid Kseg0 stack pointer.  Any task's stack pointer
170          * will do, although if we ever want to resume execution we
171          * better not have corrupted any state. */
172         get_saved_sp
173         move    sp, k1
176         j       sb1_cache_error
177          nop
179         END(handle_vec2_sb1)