Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / arch / mips / mm / cex-sb1.S
blob93176268ddc94c53a5bf835c0f647edcdb8361f3
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 <<<<<<< HEAD:arch/mips/mm/cex-sb1.S
38         __INIT
40 =======
41 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/mips/mm/cex-sb1.S
42         .set    mips64
43         .set    noreorder
44         .set    noat
46         /*
47          * sb1_cerr_vec: code to be copied to the Cache Error
48          * Exception vector.  The code must be pushed out to memory
49          * (either by copying to Kseg0 and Kseg1 both, or by flushing
50          * the L1 and L2) since it is fetched as 0xa0000100.
51          *
52          * NOTE: Be sure this handler is at most 28 instructions long
53          * since the final 16 bytes of the exception vector memory
54          * (0x170-0x17f) are used to preserve k0, k1, and ra.
55          */
57 <<<<<<< HEAD:arch/mips/mm/cex-sb1.S
58 =======
59         __CPUINIT
61 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/mips/mm/cex-sb1.S
62 LEAF(except_vec2_sb1)
63         /*
64          * If this error is recoverable, we need to exit the handler
65          * without having dirtied any registers.  To do this,
66          * save/restore k0 and k1 from low memory (Useg is direct
67          * mapped while ERL=1). Note that we can't save to a
68          * CPU-specific location without ruining a register in the
69          * process.  This means we are vulnerable to data corruption
70          * whenever the handler is reentered by a second CPU.
71          */
72         sd      k0,0x170($0)
73         sd      k1,0x178($0)
75 #ifdef CONFIG_SB1_CEX_ALWAYS_FATAL
76         j       handle_vec2_sb1
77          nop
78 #else
79         /*
80          * M_ERRCTL_RECOVERABLE is bit 31, which makes it easy to tell
81          * if we can fast-path out of here for a h/w-recovered error.
82          */
83         mfc0    k1,C0_ERRCTL
84         bgtz    k1,attempt_recovery
85          sll    k0,k1,1
87 recovered_dcache:
88         /*
89          * Unlock CacheErr-D (which in turn unlocks CacheErr-DPA).
90          * Ought to log the occurence of this recovered dcache error.
91          */
92         b       recovered
93          mtc0   $0,C0_CERR_D
95 attempt_recovery:
96         /*
97          * k0 has C0_ERRCTL << 1, which puts 'DC' at bit 31.  Any
98          * Dcache errors we can recover from will take more extensive
99          * processing.  For now, they are considered "unrecoverable".
100          * Note that 'DC' becoming set (outside of ERL mode) will
101          * cause 'IC' to clear; so if there's an Icache error, we'll
102          * only find out about it if we recover from this error and
103          * continue executing.
104          */
105         bltz    k0,unrecoverable
106          sll    k0,1
108         /*
109          * k0 has C0_ERRCTL << 2, which puts 'IC' at bit 31.  If an
110          * Icache error isn't indicated, I'm not sure why we got here.
111          * Consider that case "unrecoverable" for now.
112          */
113         bgez    k0,unrecoverable
115 attempt_icache_recovery:
116         /*
117          * External icache errors are due to uncorrectable ECC errors
118          * in the L2 cache or Memory Controller and cannot be
119          * recovered here.
120          */
121          mfc0   k0,C0_CERR_I            /* delay slot */
122         li      k1,1 << 26              /* ICACHE_EXTERNAL */
123         and     k1,k0
124         bnez    k1,unrecoverable
125          andi   k0,0x1fe0
127         /*
128          * Since the error is internal, the 'IDX' field from
129          * CacheErr-I is valid and we can just invalidate all blocks
130          * in that set.
131          */
132         cache   Index_Invalidate_I,(0<<13)(k0)
133         cache   Index_Invalidate_I,(1<<13)(k0)
134         cache   Index_Invalidate_I,(2<<13)(k0)
135         cache   Index_Invalidate_I,(3<<13)(k0)
137         /* Ought to log this recovered icache error */
139 recovered:
140         /* Restore the saved registers */
141         ld      k0,0x170($0)
142         ld      k1,0x178($0)
143         eret
145 unrecoverable:
146         /* Unrecoverable Icache or Dcache error; log it and/or fail */
147         j       handle_vec2_sb1
148          nop
149 #endif
151 END(except_vec2_sb1)
153         __FINIT
155         LEAF(handle_vec2_sb1)
156         mfc0    k0,CP0_CONFIG
157         li      k1,~CONF_CM_CMASK
158         and     k0,k0,k1
159         ori     k0,k0,CONF_CM_UNCACHED
160         mtc0    k0,CP0_CONFIG
162         SSNOP
163         SSNOP
164         SSNOP
165         SSNOP
166         bnezl   $0, 1f
168         mfc0    k0, CP0_STATUS
169         sll     k0, k0, 3                       # check CU0 (kernel?)
170         bltz    k0, 2f
171          nop
173         /* Get a valid Kseg0 stack pointer.  Any task's stack pointer
174          * will do, although if we ever want to resume execution we
175          * better not have corrupted any state. */
176         get_saved_sp
177         move    sp, k1
180         j       sb1_cache_error
181          nop
183         END(handle_vec2_sb1)