[SPARC64]: Verify all trap_per_cpu assembler offsets in trap_init()
[pandora-kernel.git] / arch / sparc64 / kernel / traps.c
1 /* $Id: traps.c,v 1.85 2002/02/09 19:49:31 davem Exp $
2  * arch/sparc64/kernel/traps.c
3  *
4  * Copyright (C) 1995,1997 David S. Miller (davem@caip.rutgers.edu)
5  * Copyright (C) 1997,1999,2000 Jakub Jelinek (jakub@redhat.com)
6  */
7
8 /*
9  * I like traps on v9, :))))
10  */
11
12 #include <linux/config.h>
13 #include <linux/module.h>
14 #include <linux/sched.h>  /* for jiffies */
15 #include <linux/kernel.h>
16 #include <linux/kallsyms.h>
17 #include <linux/signal.h>
18 #include <linux/smp.h>
19 #include <linux/smp_lock.h>
20 #include <linux/mm.h>
21 #include <linux/init.h>
22
23 #include <asm/delay.h>
24 #include <asm/system.h>
25 #include <asm/ptrace.h>
26 #include <asm/oplib.h>
27 #include <asm/page.h>
28 #include <asm/pgtable.h>
29 #include <asm/unistd.h>
30 #include <asm/uaccess.h>
31 #include <asm/fpumacro.h>
32 #include <asm/lsu.h>
33 #include <asm/dcu.h>
34 #include <asm/estate.h>
35 #include <asm/chafsr.h>
36 #include <asm/sfafsr.h>
37 #include <asm/psrcompat.h>
38 #include <asm/processor.h>
39 #include <asm/timer.h>
40 #include <asm/kdebug.h>
41 #include <asm/head.h>
42 #ifdef CONFIG_KMOD
43 #include <linux/kmod.h>
44 #endif
45
46 struct notifier_block *sparc64die_chain;
47 static DEFINE_SPINLOCK(die_notifier_lock);
48
49 int register_die_notifier(struct notifier_block *nb)
50 {
51         int err = 0;
52         unsigned long flags;
53         spin_lock_irqsave(&die_notifier_lock, flags);
54         err = notifier_chain_register(&sparc64die_chain, nb);
55         spin_unlock_irqrestore(&die_notifier_lock, flags);
56         return err;
57 }
58
59 /* When an irrecoverable trap occurs at tl > 0, the trap entry
60  * code logs the trap state registers at every level in the trap
61  * stack.  It is found at (pt_regs + sizeof(pt_regs)) and the layout
62  * is as follows:
63  */
64 struct tl1_traplog {
65         struct {
66                 unsigned long tstate;
67                 unsigned long tpc;
68                 unsigned long tnpc;
69                 unsigned long tt;
70         } trapstack[4];
71         unsigned long tl;
72 };
73
74 static void dump_tl1_traplog(struct tl1_traplog *p)
75 {
76         int i;
77
78         printk("TRAPLOG: Error at trap level 0x%lx, dumping track stack.\n",
79                p->tl);
80         for (i = 0; i < 4; i++) {
81                 printk(KERN_CRIT
82                        "TRAPLOG: Trap level %d TSTATE[%016lx] TPC[%016lx] "
83                        "TNPC[%016lx] TT[%lx]\n",
84                        i + 1,
85                        p->trapstack[i].tstate, p->trapstack[i].tpc,
86                        p->trapstack[i].tnpc, p->trapstack[i].tt);
87         }
88 }
89
90 void do_call_debug(struct pt_regs *regs) 
91
92         notify_die(DIE_CALL, "debug call", regs, 0, 255, SIGINT); 
93 }
94
95 void bad_trap(struct pt_regs *regs, long lvl)
96 {
97         char buffer[32];
98         siginfo_t info;
99
100         if (notify_die(DIE_TRAP, "bad trap", regs,
101                        0, lvl, SIGTRAP) == NOTIFY_STOP)
102                 return;
103
104         if (lvl < 0x100) {
105                 sprintf(buffer, "Bad hw trap %lx at tl0\n", lvl);
106                 die_if_kernel(buffer, regs);
107         }
108
109         lvl -= 0x100;
110         if (regs->tstate & TSTATE_PRIV) {
111                 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
112                 die_if_kernel(buffer, regs);
113         }
114         if (test_thread_flag(TIF_32BIT)) {
115                 regs->tpc &= 0xffffffff;
116                 regs->tnpc &= 0xffffffff;
117         }
118         info.si_signo = SIGILL;
119         info.si_errno = 0;
120         info.si_code = ILL_ILLTRP;
121         info.si_addr = (void __user *)regs->tpc;
122         info.si_trapno = lvl;
123         force_sig_info(SIGILL, &info, current);
124 }
125
126 void bad_trap_tl1(struct pt_regs *regs, long lvl)
127 {
128         char buffer[32];
129         
130         if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
131                        0, lvl, SIGTRAP) == NOTIFY_STOP)
132                 return;
133
134         dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
135
136         sprintf (buffer, "Bad trap %lx at tl>0", lvl);
137         die_if_kernel (buffer, regs);
138 }
139
140 #ifdef CONFIG_DEBUG_BUGVERBOSE
141 void do_BUG(const char *file, int line)
142 {
143         bust_spinlocks(1);
144         printk("kernel BUG at %s:%d!\n", file, line);
145 }
146 #endif
147
148 void spitfire_insn_access_exception(struct pt_regs *regs, unsigned long sfsr, unsigned long sfar)
149 {
150         siginfo_t info;
151
152         if (notify_die(DIE_TRAP, "instruction access exception", regs,
153                        0, 0x8, SIGTRAP) == NOTIFY_STOP)
154                 return;
155
156         if (regs->tstate & TSTATE_PRIV) {
157                 printk("spitfire_insn_access_exception: SFSR[%016lx] "
158                        "SFAR[%016lx], going.\n", sfsr, sfar);
159                 die_if_kernel("Iax", regs);
160         }
161         if (test_thread_flag(TIF_32BIT)) {
162                 regs->tpc &= 0xffffffff;
163                 regs->tnpc &= 0xffffffff;
164         }
165         info.si_signo = SIGSEGV;
166         info.si_errno = 0;
167         info.si_code = SEGV_MAPERR;
168         info.si_addr = (void __user *)regs->tpc;
169         info.si_trapno = 0;
170         force_sig_info(SIGSEGV, &info, current);
171 }
172
173 void spitfire_insn_access_exception_tl1(struct pt_regs *regs, unsigned long sfsr, unsigned long sfar)
174 {
175         if (notify_die(DIE_TRAP_TL1, "instruction access exception tl1", regs,
176                        0, 0x8, SIGTRAP) == NOTIFY_STOP)
177                 return;
178
179         dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
180         spitfire_insn_access_exception(regs, sfsr, sfar);
181 }
182
183 void spitfire_data_access_exception(struct pt_regs *regs, unsigned long sfsr, unsigned long sfar)
184 {
185         siginfo_t info;
186
187         if (notify_die(DIE_TRAP, "data access exception", regs,
188                        0, 0x30, SIGTRAP) == NOTIFY_STOP)
189                 return;
190
191         if (regs->tstate & TSTATE_PRIV) {
192                 /* Test if this comes from uaccess places. */
193                 const struct exception_table_entry *entry;
194
195                 entry = search_exception_tables(regs->tpc);
196                 if (entry) {
197                         /* Ouch, somebody is trying VM hole tricks on us... */
198 #ifdef DEBUG_EXCEPTIONS
199                         printk("Exception: PC<%016lx> faddr<UNKNOWN>\n", regs->tpc);
200                         printk("EX_TABLE: insn<%016lx> fixup<%016lx>\n",
201                                regs->tpc, entry->fixup);
202 #endif
203                         regs->tpc = entry->fixup;
204                         regs->tnpc = regs->tpc + 4;
205                         return;
206                 }
207                 /* Shit... */
208                 printk("spitfire_data_access_exception: SFSR[%016lx] "
209                        "SFAR[%016lx], going.\n", sfsr, sfar);
210                 die_if_kernel("Dax", regs);
211         }
212
213         info.si_signo = SIGSEGV;
214         info.si_errno = 0;
215         info.si_code = SEGV_MAPERR;
216         info.si_addr = (void __user *)sfar;
217         info.si_trapno = 0;
218         force_sig_info(SIGSEGV, &info, current);
219 }
220
221 void spitfire_data_access_exception_tl1(struct pt_regs *regs, unsigned long sfsr, unsigned long sfar)
222 {
223         if (notify_die(DIE_TRAP_TL1, "data access exception tl1", regs,
224                        0, 0x30, SIGTRAP) == NOTIFY_STOP)
225                 return;
226
227         dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
228         spitfire_data_access_exception(regs, sfsr, sfar);
229 }
230
231 #ifdef CONFIG_PCI
232 /* This is really pathetic... */
233 extern volatile int pci_poke_in_progress;
234 extern volatile int pci_poke_cpu;
235 extern volatile int pci_poke_faulted;
236 #endif
237
238 /* When access exceptions happen, we must do this. */
239 static void spitfire_clean_and_reenable_l1_caches(void)
240 {
241         unsigned long va;
242
243         if (tlb_type != spitfire)
244                 BUG();
245
246         /* Clean 'em. */
247         for (va =  0; va < (PAGE_SIZE << 1); va += 32) {
248                 spitfire_put_icache_tag(va, 0x0);
249                 spitfire_put_dcache_tag(va, 0x0);
250         }
251
252         /* Re-enable in LSU. */
253         __asm__ __volatile__("flush %%g6\n\t"
254                              "membar #Sync\n\t"
255                              "stxa %0, [%%g0] %1\n\t"
256                              "membar #Sync"
257                              : /* no outputs */
258                              : "r" (LSU_CONTROL_IC | LSU_CONTROL_DC |
259                                     LSU_CONTROL_IM | LSU_CONTROL_DM),
260                              "i" (ASI_LSU_CONTROL)
261                              : "memory");
262 }
263
264 static void spitfire_enable_estate_errors(void)
265 {
266         __asm__ __volatile__("stxa      %0, [%%g0] %1\n\t"
267                              "membar    #Sync"
268                              : /* no outputs */
269                              : "r" (ESTATE_ERR_ALL),
270                                "i" (ASI_ESTATE_ERROR_EN));
271 }
272
273 static char ecc_syndrome_table[] = {
274         0x4c, 0x40, 0x41, 0x48, 0x42, 0x48, 0x48, 0x49,
275         0x43, 0x48, 0x48, 0x49, 0x48, 0x49, 0x49, 0x4a,
276         0x44, 0x48, 0x48, 0x20, 0x48, 0x39, 0x4b, 0x48,
277         0x48, 0x25, 0x31, 0x48, 0x28, 0x48, 0x48, 0x2c,
278         0x45, 0x48, 0x48, 0x21, 0x48, 0x3d, 0x04, 0x48,
279         0x48, 0x4b, 0x35, 0x48, 0x2d, 0x48, 0x48, 0x29,
280         0x48, 0x00, 0x01, 0x48, 0x0a, 0x48, 0x48, 0x4b,
281         0x0f, 0x48, 0x48, 0x4b, 0x48, 0x49, 0x49, 0x48,
282         0x46, 0x48, 0x48, 0x2a, 0x48, 0x3b, 0x27, 0x48,
283         0x48, 0x4b, 0x33, 0x48, 0x22, 0x48, 0x48, 0x2e,
284         0x48, 0x19, 0x1d, 0x48, 0x1b, 0x4a, 0x48, 0x4b,
285         0x1f, 0x48, 0x4a, 0x4b, 0x48, 0x4b, 0x4b, 0x48,
286         0x48, 0x4b, 0x24, 0x48, 0x07, 0x48, 0x48, 0x36,
287         0x4b, 0x48, 0x48, 0x3e, 0x48, 0x30, 0x38, 0x48,
288         0x49, 0x48, 0x48, 0x4b, 0x48, 0x4b, 0x16, 0x48,
289         0x48, 0x12, 0x4b, 0x48, 0x49, 0x48, 0x48, 0x4b,
290         0x47, 0x48, 0x48, 0x2f, 0x48, 0x3f, 0x4b, 0x48,
291         0x48, 0x06, 0x37, 0x48, 0x23, 0x48, 0x48, 0x2b,
292         0x48, 0x05, 0x4b, 0x48, 0x4b, 0x48, 0x48, 0x32,
293         0x26, 0x48, 0x48, 0x3a, 0x48, 0x34, 0x3c, 0x48,
294         0x48, 0x11, 0x15, 0x48, 0x13, 0x4a, 0x48, 0x4b,
295         0x17, 0x48, 0x4a, 0x4b, 0x48, 0x4b, 0x4b, 0x48,
296         0x49, 0x48, 0x48, 0x4b, 0x48, 0x4b, 0x1e, 0x48,
297         0x48, 0x1a, 0x4b, 0x48, 0x49, 0x48, 0x48, 0x4b,
298         0x48, 0x08, 0x0d, 0x48, 0x02, 0x48, 0x48, 0x49,
299         0x03, 0x48, 0x48, 0x49, 0x48, 0x4b, 0x4b, 0x48,
300         0x49, 0x48, 0x48, 0x49, 0x48, 0x4b, 0x10, 0x48,
301         0x48, 0x14, 0x4b, 0x48, 0x4b, 0x48, 0x48, 0x4b,
302         0x49, 0x48, 0x48, 0x49, 0x48, 0x4b, 0x18, 0x48,
303         0x48, 0x1c, 0x4b, 0x48, 0x4b, 0x48, 0x48, 0x4b,
304         0x4a, 0x0c, 0x09, 0x48, 0x0e, 0x48, 0x48, 0x4b,
305         0x0b, 0x48, 0x48, 0x4b, 0x48, 0x4b, 0x4b, 0x4a
306 };
307
308 static char *syndrome_unknown = "<Unknown>";
309
310 static void spitfire_log_udb_syndrome(unsigned long afar, unsigned long udbh, unsigned long udbl, unsigned long bit)
311 {
312         unsigned short scode;
313         char memmod_str[64], *p;
314
315         if (udbl & bit) {
316                 scode = ecc_syndrome_table[udbl & 0xff];
317                 if (prom_getunumber(scode, afar,
318                                     memmod_str, sizeof(memmod_str)) == -1)
319                         p = syndrome_unknown;
320                 else
321                         p = memmod_str;
322                 printk(KERN_WARNING "CPU[%d]: UDBL Syndrome[%x] "
323                        "Memory Module \"%s\"\n",
324                        smp_processor_id(), scode, p);
325         }
326
327         if (udbh & bit) {
328                 scode = ecc_syndrome_table[udbh & 0xff];
329                 if (prom_getunumber(scode, afar,
330                                     memmod_str, sizeof(memmod_str)) == -1)
331                         p = syndrome_unknown;
332                 else
333                         p = memmod_str;
334                 printk(KERN_WARNING "CPU[%d]: UDBH Syndrome[%x] "
335                        "Memory Module \"%s\"\n",
336                        smp_processor_id(), scode, p);
337         }
338
339 }
340
341 static void spitfire_cee_log(unsigned long afsr, unsigned long afar, unsigned long udbh, unsigned long udbl, int tl1, struct pt_regs *regs)
342 {
343
344         printk(KERN_WARNING "CPU[%d]: Correctable ECC Error "
345                "AFSR[%lx] AFAR[%016lx] UDBL[%lx] UDBH[%lx] TL>1[%d]\n",
346                smp_processor_id(), afsr, afar, udbl, udbh, tl1);
347
348         spitfire_log_udb_syndrome(afar, udbh, udbl, UDBE_CE);
349
350         /* We always log it, even if someone is listening for this
351          * trap.
352          */
353         notify_die(DIE_TRAP, "Correctable ECC Error", regs,
354                    0, TRAP_TYPE_CEE, SIGTRAP);
355
356         /* The Correctable ECC Error trap does not disable I/D caches.  So
357          * we only have to restore the ESTATE Error Enable register.
358          */
359         spitfire_enable_estate_errors();
360 }
361
362 static void spitfire_ue_log(unsigned long afsr, unsigned long afar, unsigned long udbh, unsigned long udbl, unsigned long tt, int tl1, struct pt_regs *regs)
363 {
364         siginfo_t info;
365
366         printk(KERN_WARNING "CPU[%d]: Uncorrectable Error AFSR[%lx] "
367                "AFAR[%lx] UDBL[%lx] UDBH[%ld] TT[%lx] TL>1[%d]\n",
368                smp_processor_id(), afsr, afar, udbl, udbh, tt, tl1);
369
370         /* XXX add more human friendly logging of the error status
371          * XXX as is implemented for cheetah
372          */
373
374         spitfire_log_udb_syndrome(afar, udbh, udbl, UDBE_UE);
375
376         /* We always log it, even if someone is listening for this
377          * trap.
378          */
379         notify_die(DIE_TRAP, "Uncorrectable Error", regs,
380                    0, tt, SIGTRAP);
381
382         if (regs->tstate & TSTATE_PRIV) {
383                 if (tl1)
384                         dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
385                 die_if_kernel("UE", regs);
386         }
387
388         /* XXX need more intelligent processing here, such as is implemented
389          * XXX for cheetah errors, in fact if the E-cache still holds the
390          * XXX line with bad parity this will loop
391          */
392
393         spitfire_clean_and_reenable_l1_caches();
394         spitfire_enable_estate_errors();
395
396         if (test_thread_flag(TIF_32BIT)) {
397                 regs->tpc &= 0xffffffff;
398                 regs->tnpc &= 0xffffffff;
399         }
400         info.si_signo = SIGBUS;
401         info.si_errno = 0;
402         info.si_code = BUS_OBJERR;
403         info.si_addr = (void *)0;
404         info.si_trapno = 0;
405         force_sig_info(SIGBUS, &info, current);
406 }
407
408 void spitfire_access_error(struct pt_regs *regs, unsigned long status_encoded, unsigned long afar)
409 {
410         unsigned long afsr, tt, udbh, udbl;
411         int tl1;
412
413         afsr = (status_encoded & SFSTAT_AFSR_MASK) >> SFSTAT_AFSR_SHIFT;
414         tt = (status_encoded & SFSTAT_TRAP_TYPE) >> SFSTAT_TRAP_TYPE_SHIFT;
415         tl1 = (status_encoded & SFSTAT_TL_GT_ONE) ? 1 : 0;
416         udbl = (status_encoded & SFSTAT_UDBL_MASK) >> SFSTAT_UDBL_SHIFT;
417         udbh = (status_encoded & SFSTAT_UDBH_MASK) >> SFSTAT_UDBH_SHIFT;
418
419 #ifdef CONFIG_PCI
420         if (tt == TRAP_TYPE_DAE &&
421             pci_poke_in_progress && pci_poke_cpu == smp_processor_id()) {
422                 spitfire_clean_and_reenable_l1_caches();
423                 spitfire_enable_estate_errors();
424
425                 pci_poke_faulted = 1;
426                 regs->tnpc = regs->tpc + 4;
427                 return;
428         }
429 #endif
430
431         if (afsr & SFAFSR_UE)
432                 spitfire_ue_log(afsr, afar, udbh, udbl, tt, tl1, regs);
433
434         if (tt == TRAP_TYPE_CEE) {
435                 /* Handle the case where we took a CEE trap, but ACK'd
436                  * only the UE state in the UDB error registers.
437                  */
438                 if (afsr & SFAFSR_UE) {
439                         if (udbh & UDBE_CE) {
440                                 __asm__ __volatile__(
441                                         "stxa   %0, [%1] %2\n\t"
442                                         "membar #Sync"
443                                         : /* no outputs */
444                                         : "r" (udbh & UDBE_CE),
445                                           "r" (0x0), "i" (ASI_UDB_ERROR_W));
446                         }
447                         if (udbl & UDBE_CE) {
448                                 __asm__ __volatile__(
449                                         "stxa   %0, [%1] %2\n\t"
450                                         "membar #Sync"
451                                         : /* no outputs */
452                                         : "r" (udbl & UDBE_CE),
453                                           "r" (0x18), "i" (ASI_UDB_ERROR_W));
454                         }
455                 }
456
457                 spitfire_cee_log(afsr, afar, udbh, udbl, tl1, regs);
458         }
459 }
460
461 int cheetah_pcache_forced_on;
462
463 void cheetah_enable_pcache(void)
464 {
465         unsigned long dcr;
466
467         printk("CHEETAH: Enabling P-Cache on cpu %d.\n",
468                smp_processor_id());
469
470         __asm__ __volatile__("ldxa [%%g0] %1, %0"
471                              : "=r" (dcr)
472                              : "i" (ASI_DCU_CONTROL_REG));
473         dcr |= (DCU_PE | DCU_HPE | DCU_SPE | DCU_SL);
474         __asm__ __volatile__("stxa %0, [%%g0] %1\n\t"
475                              "membar #Sync"
476                              : /* no outputs */
477                              : "r" (dcr), "i" (ASI_DCU_CONTROL_REG));
478 }
479
480 /* Cheetah error trap handling. */
481 static unsigned long ecache_flush_physbase;
482 static unsigned long ecache_flush_linesize;
483 static unsigned long ecache_flush_size;
484
485 /* WARNING: The error trap handlers in assembly know the precise
486  *          layout of the following structure.
487  *
488  * C-level handlers below use this information to log the error
489  * and then determine how to recover (if possible).
490  */
491 struct cheetah_err_info {
492 /*0x00*/u64 afsr;
493 /*0x08*/u64 afar;
494
495         /* D-cache state */
496 /*0x10*/u64 dcache_data[4];     /* The actual data      */
497 /*0x30*/u64 dcache_index;       /* D-cache index        */
498 /*0x38*/u64 dcache_tag;         /* D-cache tag/valid    */
499 /*0x40*/u64 dcache_utag;        /* D-cache microtag     */
500 /*0x48*/u64 dcache_stag;        /* D-cache snooptag     */
501
502         /* I-cache state */
503 /*0x50*/u64 icache_data[8];     /* The actual insns + predecode */
504 /*0x90*/u64 icache_index;       /* I-cache index        */
505 /*0x98*/u64 icache_tag;         /* I-cache phys tag     */
506 /*0xa0*/u64 icache_utag;        /* I-cache microtag     */
507 /*0xa8*/u64 icache_stag;        /* I-cache snooptag     */
508 /*0xb0*/u64 icache_upper;       /* I-cache upper-tag    */
509 /*0xb8*/u64 icache_lower;       /* I-cache lower-tag    */
510
511         /* E-cache state */
512 /*0xc0*/u64 ecache_data[4];     /* 32 bytes from staging registers */
513 /*0xe0*/u64 ecache_index;       /* E-cache index        */
514 /*0xe8*/u64 ecache_tag;         /* E-cache tag/state    */
515
516 /*0xf0*/u64 __pad[32 - 30];
517 };
518 #define CHAFSR_INVALID          ((u64)-1L)
519
520 /* This table is ordered in priority of errors and matches the
521  * AFAR overwrite policy as well.
522  */
523
524 struct afsr_error_table {
525         unsigned long mask;
526         const char *name;
527 };
528
529 static const char CHAFSR_PERR_msg[] =
530         "System interface protocol error";
531 static const char CHAFSR_IERR_msg[] =
532         "Internal processor error";
533 static const char CHAFSR_ISAP_msg[] =
534         "System request parity error on incoming addresss";
535 static const char CHAFSR_UCU_msg[] =
536         "Uncorrectable E-cache ECC error for ifetch/data";
537 static const char CHAFSR_UCC_msg[] =
538         "SW Correctable E-cache ECC error for ifetch/data";
539 static const char CHAFSR_UE_msg[] =
540         "Uncorrectable system bus data ECC error for read";
541 static const char CHAFSR_EDU_msg[] =
542         "Uncorrectable E-cache ECC error for stmerge/blkld";
543 static const char CHAFSR_EMU_msg[] =
544         "Uncorrectable system bus MTAG error";
545 static const char CHAFSR_WDU_msg[] =
546         "Uncorrectable E-cache ECC error for writeback";
547 static const char CHAFSR_CPU_msg[] =
548         "Uncorrectable ECC error for copyout";
549 static const char CHAFSR_CE_msg[] =
550         "HW corrected system bus data ECC error for read";
551 static const char CHAFSR_EDC_msg[] =
552         "HW corrected E-cache ECC error for stmerge/blkld";
553 static const char CHAFSR_EMC_msg[] =
554         "HW corrected system bus MTAG ECC error";
555 static const char CHAFSR_WDC_msg[] =
556         "HW corrected E-cache ECC error for writeback";
557 static const char CHAFSR_CPC_msg[] =
558         "HW corrected ECC error for copyout";
559 static const char CHAFSR_TO_msg[] =
560         "Unmapped error from system bus";
561 static const char CHAFSR_BERR_msg[] =
562         "Bus error response from system bus";
563 static const char CHAFSR_IVC_msg[] =
564         "HW corrected system bus data ECC error for ivec read";
565 static const char CHAFSR_IVU_msg[] =
566         "Uncorrectable system bus data ECC error for ivec read";
567 static struct afsr_error_table __cheetah_error_table[] = {
568         {       CHAFSR_PERR,    CHAFSR_PERR_msg         },
569         {       CHAFSR_IERR,    CHAFSR_IERR_msg         },
570         {       CHAFSR_ISAP,    CHAFSR_ISAP_msg         },
571         {       CHAFSR_UCU,     CHAFSR_UCU_msg          },
572         {       CHAFSR_UCC,     CHAFSR_UCC_msg          },
573         {       CHAFSR_UE,      CHAFSR_UE_msg           },
574         {       CHAFSR_EDU,     CHAFSR_EDU_msg          },
575         {       CHAFSR_EMU,     CHAFSR_EMU_msg          },
576         {       CHAFSR_WDU,     CHAFSR_WDU_msg          },
577         {       CHAFSR_CPU,     CHAFSR_CPU_msg          },
578         {       CHAFSR_CE,      CHAFSR_CE_msg           },
579         {       CHAFSR_EDC,     CHAFSR_EDC_msg          },
580         {       CHAFSR_EMC,     CHAFSR_EMC_msg          },
581         {       CHAFSR_WDC,     CHAFSR_WDC_msg          },
582         {       CHAFSR_CPC,     CHAFSR_CPC_msg          },
583         {       CHAFSR_TO,      CHAFSR_TO_msg           },
584         {       CHAFSR_BERR,    CHAFSR_BERR_msg         },
585         /* These two do not update the AFAR. */
586         {       CHAFSR_IVC,     CHAFSR_IVC_msg          },
587         {       CHAFSR_IVU,     CHAFSR_IVU_msg          },
588         {       0,              NULL                    },
589 };
590 static const char CHPAFSR_DTO_msg[] =
591         "System bus unmapped error for prefetch/storequeue-read";
592 static const char CHPAFSR_DBERR_msg[] =
593         "System bus error for prefetch/storequeue-read";
594 static const char CHPAFSR_THCE_msg[] =
595         "Hardware corrected E-cache Tag ECC error";
596 static const char CHPAFSR_TSCE_msg[] =
597         "SW handled correctable E-cache Tag ECC error";
598 static const char CHPAFSR_TUE_msg[] =
599         "Uncorrectable E-cache Tag ECC error";
600 static const char CHPAFSR_DUE_msg[] =
601         "System bus uncorrectable data ECC error due to prefetch/store-fill";
602 static struct afsr_error_table __cheetah_plus_error_table[] = {
603         {       CHAFSR_PERR,    CHAFSR_PERR_msg         },
604         {       CHAFSR_IERR,    CHAFSR_IERR_msg         },
605         {       CHAFSR_ISAP,    CHAFSR_ISAP_msg         },
606         {       CHAFSR_UCU,     CHAFSR_UCU_msg          },
607         {       CHAFSR_UCC,     CHAFSR_UCC_msg          },
608         {       CHAFSR_UE,      CHAFSR_UE_msg           },
609         {       CHAFSR_EDU,     CHAFSR_EDU_msg          },
610         {       CHAFSR_EMU,     CHAFSR_EMU_msg          },
611         {       CHAFSR_WDU,     CHAFSR_WDU_msg          },
612         {       CHAFSR_CPU,     CHAFSR_CPU_msg          },
613         {       CHAFSR_CE,      CHAFSR_CE_msg           },
614         {       CHAFSR_EDC,     CHAFSR_EDC_msg          },
615         {       CHAFSR_EMC,     CHAFSR_EMC_msg          },
616         {       CHAFSR_WDC,     CHAFSR_WDC_msg          },
617         {       CHAFSR_CPC,     CHAFSR_CPC_msg          },
618         {       CHAFSR_TO,      CHAFSR_TO_msg           },
619         {       CHAFSR_BERR,    CHAFSR_BERR_msg         },
620         {       CHPAFSR_DTO,    CHPAFSR_DTO_msg         },
621         {       CHPAFSR_DBERR,  CHPAFSR_DBERR_msg       },
622         {       CHPAFSR_THCE,   CHPAFSR_THCE_msg        },
623         {       CHPAFSR_TSCE,   CHPAFSR_TSCE_msg        },
624         {       CHPAFSR_TUE,    CHPAFSR_TUE_msg         },
625         {       CHPAFSR_DUE,    CHPAFSR_DUE_msg         },
626         /* These two do not update the AFAR. */
627         {       CHAFSR_IVC,     CHAFSR_IVC_msg          },
628         {       CHAFSR_IVU,     CHAFSR_IVU_msg          },
629         {       0,              NULL                    },
630 };
631 static const char JPAFSR_JETO_msg[] =
632         "System interface protocol error, hw timeout caused";
633 static const char JPAFSR_SCE_msg[] =
634         "Parity error on system snoop results";
635 static const char JPAFSR_JEIC_msg[] =
636         "System interface protocol error, illegal command detected";
637 static const char JPAFSR_JEIT_msg[] =
638         "System interface protocol error, illegal ADTYPE detected";
639 static const char JPAFSR_OM_msg[] =
640         "Out of range memory error has occurred";
641 static const char JPAFSR_ETP_msg[] =
642         "Parity error on L2 cache tag SRAM";
643 static const char JPAFSR_UMS_msg[] =
644         "Error due to unsupported store";
645 static const char JPAFSR_RUE_msg[] =
646         "Uncorrectable ECC error from remote cache/memory";
647 static const char JPAFSR_RCE_msg[] =
648         "Correctable ECC error from remote cache/memory";
649 static const char JPAFSR_BP_msg[] =
650         "JBUS parity error on returned read data";
651 static const char JPAFSR_WBP_msg[] =
652         "JBUS parity error on data for writeback or block store";
653 static const char JPAFSR_FRC_msg[] =
654         "Foreign read to DRAM incurring correctable ECC error";
655 static const char JPAFSR_FRU_msg[] =
656         "Foreign read to DRAM incurring uncorrectable ECC error";
657 static struct afsr_error_table __jalapeno_error_table[] = {
658         {       JPAFSR_JETO,    JPAFSR_JETO_msg         },
659         {       JPAFSR_SCE,     JPAFSR_SCE_msg          },
660         {       JPAFSR_JEIC,    JPAFSR_JEIC_msg         },
661         {       JPAFSR_JEIT,    JPAFSR_JEIT_msg         },
662         {       CHAFSR_PERR,    CHAFSR_PERR_msg         },
663         {       CHAFSR_IERR,    CHAFSR_IERR_msg         },
664         {       CHAFSR_ISAP,    CHAFSR_ISAP_msg         },
665         {       CHAFSR_UCU,     CHAFSR_UCU_msg          },
666         {       CHAFSR_UCC,     CHAFSR_UCC_msg          },
667         {       CHAFSR_UE,      CHAFSR_UE_msg           },
668         {       CHAFSR_EDU,     CHAFSR_EDU_msg          },
669         {       JPAFSR_OM,      JPAFSR_OM_msg           },
670         {       CHAFSR_WDU,     CHAFSR_WDU_msg          },
671         {       CHAFSR_CPU,     CHAFSR_CPU_msg          },
672         {       CHAFSR_CE,      CHAFSR_CE_msg           },
673         {       CHAFSR_EDC,     CHAFSR_EDC_msg          },
674         {       JPAFSR_ETP,     JPAFSR_ETP_msg          },
675         {       CHAFSR_WDC,     CHAFSR_WDC_msg          },
676         {       CHAFSR_CPC,     CHAFSR_CPC_msg          },
677         {       CHAFSR_TO,      CHAFSR_TO_msg           },
678         {       CHAFSR_BERR,    CHAFSR_BERR_msg         },
679         {       JPAFSR_UMS,     JPAFSR_UMS_msg          },
680         {       JPAFSR_RUE,     JPAFSR_RUE_msg          },
681         {       JPAFSR_RCE,     JPAFSR_RCE_msg          },
682         {       JPAFSR_BP,      JPAFSR_BP_msg           },
683         {       JPAFSR_WBP,     JPAFSR_WBP_msg          },
684         {       JPAFSR_FRC,     JPAFSR_FRC_msg          },
685         {       JPAFSR_FRU,     JPAFSR_FRU_msg          },
686         /* These two do not update the AFAR. */
687         {       CHAFSR_IVU,     CHAFSR_IVU_msg          },
688         {       0,              NULL                    },
689 };
690 static struct afsr_error_table *cheetah_error_table;
691 static unsigned long cheetah_afsr_errors;
692
693 /* This is allocated at boot time based upon the largest hardware
694  * cpu ID in the system.  We allocate two entries per cpu, one for
695  * TL==0 logging and one for TL >= 1 logging.
696  */
697 struct cheetah_err_info *cheetah_error_log;
698
699 static __inline__ struct cheetah_err_info *cheetah_get_error_log(unsigned long afsr)
700 {
701         struct cheetah_err_info *p;
702         int cpu = smp_processor_id();
703
704         if (!cheetah_error_log)
705                 return NULL;
706
707         p = cheetah_error_log + (cpu * 2);
708         if ((afsr & CHAFSR_TL1) != 0UL)
709                 p++;
710
711         return p;
712 }
713
714 extern unsigned int tl0_icpe[], tl1_icpe[];
715 extern unsigned int tl0_dcpe[], tl1_dcpe[];
716 extern unsigned int tl0_fecc[], tl1_fecc[];
717 extern unsigned int tl0_cee[], tl1_cee[];
718 extern unsigned int tl0_iae[], tl1_iae[];
719 extern unsigned int tl0_dae[], tl1_dae[];
720 extern unsigned int cheetah_plus_icpe_trap_vector[], cheetah_plus_icpe_trap_vector_tl1[];
721 extern unsigned int cheetah_plus_dcpe_trap_vector[], cheetah_plus_dcpe_trap_vector_tl1[];
722 extern unsigned int cheetah_fecc_trap_vector[], cheetah_fecc_trap_vector_tl1[];
723 extern unsigned int cheetah_cee_trap_vector[], cheetah_cee_trap_vector_tl1[];
724 extern unsigned int cheetah_deferred_trap_vector[], cheetah_deferred_trap_vector_tl1[];
725
726 void __init cheetah_ecache_flush_init(void)
727 {
728         unsigned long largest_size, smallest_linesize, order, ver;
729         int node, i, instance;
730
731         /* Scan all cpu device tree nodes, note two values:
732          * 1) largest E-cache size
733          * 2) smallest E-cache line size
734          */
735         largest_size = 0UL;
736         smallest_linesize = ~0UL;
737
738         instance = 0;
739         while (!cpu_find_by_instance(instance, &node, NULL)) {
740                 unsigned long val;
741
742                 val = prom_getintdefault(node, "ecache-size",
743                                          (2 * 1024 * 1024));
744                 if (val > largest_size)
745                         largest_size = val;
746                 val = prom_getintdefault(node, "ecache-line-size", 64);
747                 if (val < smallest_linesize)
748                         smallest_linesize = val;
749                 instance++;
750         }
751
752         if (largest_size == 0UL || smallest_linesize == ~0UL) {
753                 prom_printf("cheetah_ecache_flush_init: Cannot probe cpu E-cache "
754                             "parameters.\n");
755                 prom_halt();
756         }
757
758         ecache_flush_size = (2 * largest_size);
759         ecache_flush_linesize = smallest_linesize;
760
761         ecache_flush_physbase = find_ecache_flush_span(ecache_flush_size);
762
763         if (ecache_flush_physbase == ~0UL) {
764                 prom_printf("cheetah_ecache_flush_init: Cannot find %d byte "
765                             "contiguous physical memory.\n",
766                             ecache_flush_size);
767                 prom_halt();
768         }
769
770         /* Now allocate error trap reporting scoreboard. */
771         node = NR_CPUS * (2 * sizeof(struct cheetah_err_info));
772         for (order = 0; order < MAX_ORDER; order++) {
773                 if ((PAGE_SIZE << order) >= node)
774                         break;
775         }
776         cheetah_error_log = (struct cheetah_err_info *)
777                 __get_free_pages(GFP_KERNEL, order);
778         if (!cheetah_error_log) {
779                 prom_printf("cheetah_ecache_flush_init: Failed to allocate "
780                             "error logging scoreboard (%d bytes).\n", node);
781                 prom_halt();
782         }
783         memset(cheetah_error_log, 0, PAGE_SIZE << order);
784
785         /* Mark all AFSRs as invalid so that the trap handler will
786          * log new new information there.
787          */
788         for (i = 0; i < 2 * NR_CPUS; i++)
789                 cheetah_error_log[i].afsr = CHAFSR_INVALID;
790
791         __asm__ ("rdpr %%ver, %0" : "=r" (ver));
792         if ((ver >> 32) == __JALAPENO_ID ||
793             (ver >> 32) == __SERRANO_ID) {
794                 cheetah_error_table = &__jalapeno_error_table[0];
795                 cheetah_afsr_errors = JPAFSR_ERRORS;
796         } else if ((ver >> 32) == 0x003e0015) {
797                 cheetah_error_table = &__cheetah_plus_error_table[0];
798                 cheetah_afsr_errors = CHPAFSR_ERRORS;
799         } else {
800                 cheetah_error_table = &__cheetah_error_table[0];
801                 cheetah_afsr_errors = CHAFSR_ERRORS;
802         }
803
804         /* Now patch trap tables. */
805         memcpy(tl0_fecc, cheetah_fecc_trap_vector, (8 * 4));
806         memcpy(tl1_fecc, cheetah_fecc_trap_vector_tl1, (8 * 4));
807         memcpy(tl0_cee, cheetah_cee_trap_vector, (8 * 4));
808         memcpy(tl1_cee, cheetah_cee_trap_vector_tl1, (8 * 4));
809         memcpy(tl0_iae, cheetah_deferred_trap_vector, (8 * 4));
810         memcpy(tl1_iae, cheetah_deferred_trap_vector_tl1, (8 * 4));
811         memcpy(tl0_dae, cheetah_deferred_trap_vector, (8 * 4));
812         memcpy(tl1_dae, cheetah_deferred_trap_vector_tl1, (8 * 4));
813         if (tlb_type == cheetah_plus) {
814                 memcpy(tl0_dcpe, cheetah_plus_dcpe_trap_vector, (8 * 4));
815                 memcpy(tl1_dcpe, cheetah_plus_dcpe_trap_vector_tl1, (8 * 4));
816                 memcpy(tl0_icpe, cheetah_plus_icpe_trap_vector, (8 * 4));
817                 memcpy(tl1_icpe, cheetah_plus_icpe_trap_vector_tl1, (8 * 4));
818         }
819         flushi(PAGE_OFFSET);
820 }
821
822 static void cheetah_flush_ecache(void)
823 {
824         unsigned long flush_base = ecache_flush_physbase;
825         unsigned long flush_linesize = ecache_flush_linesize;
826         unsigned long flush_size = ecache_flush_size;
827
828         __asm__ __volatile__("1: subcc  %0, %4, %0\n\t"
829                              "   bne,pt %%xcc, 1b\n\t"
830                              "    ldxa  [%2 + %0] %3, %%g0\n\t"
831                              : "=&r" (flush_size)
832                              : "0" (flush_size), "r" (flush_base),
833                                "i" (ASI_PHYS_USE_EC), "r" (flush_linesize));
834 }
835
836 static void cheetah_flush_ecache_line(unsigned long physaddr)
837 {
838         unsigned long alias;
839
840         physaddr &= ~(8UL - 1UL);
841         physaddr = (ecache_flush_physbase +
842                     (physaddr & ((ecache_flush_size>>1UL) - 1UL)));
843         alias = physaddr + (ecache_flush_size >> 1UL);
844         __asm__ __volatile__("ldxa [%0] %2, %%g0\n\t"
845                              "ldxa [%1] %2, %%g0\n\t"
846                              "membar #Sync"
847                              : /* no outputs */
848                              : "r" (physaddr), "r" (alias),
849                                "i" (ASI_PHYS_USE_EC));
850 }
851
852 /* Unfortunately, the diagnostic access to the I-cache tags we need to
853  * use to clear the thing interferes with I-cache coherency transactions.
854  *
855  * So we must only flush the I-cache when it is disabled.
856  */
857 static void __cheetah_flush_icache(void)
858 {
859         unsigned int icache_size, icache_line_size;
860         unsigned long addr;
861
862         icache_size = local_cpu_data().icache_size;
863         icache_line_size = local_cpu_data().icache_line_size;
864
865         /* Clear the valid bits in all the tags. */
866         for (addr = 0; addr < icache_size; addr += icache_line_size) {
867                 __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
868                                      "membar #Sync"
869                                      : /* no outputs */
870                                      : "r" (addr | (2 << 3)),
871                                        "i" (ASI_IC_TAG));
872         }
873 }
874
875 static void cheetah_flush_icache(void)
876 {
877         unsigned long dcu_save;
878
879         /* Save current DCU, disable I-cache. */
880         __asm__ __volatile__("ldxa [%%g0] %1, %0\n\t"
881                              "or %0, %2, %%g1\n\t"
882                              "stxa %%g1, [%%g0] %1\n\t"
883                              "membar #Sync"
884                              : "=r" (dcu_save)
885                              : "i" (ASI_DCU_CONTROL_REG), "i" (DCU_IC)
886                              : "g1");
887
888         __cheetah_flush_icache();
889
890         /* Restore DCU register */
891         __asm__ __volatile__("stxa %0, [%%g0] %1\n\t"
892                              "membar #Sync"
893                              : /* no outputs */
894                              : "r" (dcu_save), "i" (ASI_DCU_CONTROL_REG));
895 }
896
897 static void cheetah_flush_dcache(void)
898 {
899         unsigned int dcache_size, dcache_line_size;
900         unsigned long addr;
901
902         dcache_size = local_cpu_data().dcache_size;
903         dcache_line_size = local_cpu_data().dcache_line_size;
904
905         for (addr = 0; addr < dcache_size; addr += dcache_line_size) {
906                 __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
907                                      "membar #Sync"
908                                      : /* no outputs */
909                                      : "r" (addr), "i" (ASI_DCACHE_TAG));
910         }
911 }
912
913 /* In order to make the even parity correct we must do two things.
914  * First, we clear DC_data_parity and set DC_utag to an appropriate value.
915  * Next, we clear out all 32-bytes of data for that line.  Data of
916  * all-zero + tag parity value of zero == correct parity.
917  */
918 static void cheetah_plus_zap_dcache_parity(void)
919 {
920         unsigned int dcache_size, dcache_line_size;
921         unsigned long addr;
922
923         dcache_size = local_cpu_data().dcache_size;
924         dcache_line_size = local_cpu_data().dcache_line_size;
925
926         for (addr = 0; addr < dcache_size; addr += dcache_line_size) {
927                 unsigned long tag = (addr >> 14);
928                 unsigned long line;
929
930                 __asm__ __volatile__("membar    #Sync\n\t"
931                                      "stxa      %0, [%1] %2\n\t"
932                                      "membar    #Sync"
933                                      : /* no outputs */
934                                      : "r" (tag), "r" (addr),
935                                        "i" (ASI_DCACHE_UTAG));
936                 for (line = addr; line < addr + dcache_line_size; line += 8)
937                         __asm__ __volatile__("membar    #Sync\n\t"
938                                              "stxa      %%g0, [%0] %1\n\t"
939                                              "membar    #Sync"
940                                              : /* no outputs */
941                                              : "r" (line),
942                                                "i" (ASI_DCACHE_DATA));
943         }
944 }
945
946 /* Conversion tables used to frob Cheetah AFSR syndrome values into
947  * something palatable to the memory controller driver get_unumber
948  * routine.
949  */
950 #define MT0     137
951 #define MT1     138
952 #define MT2     139
953 #define NONE    254
954 #define MTC0    140
955 #define MTC1    141
956 #define MTC2    142
957 #define MTC3    143
958 #define C0      128
959 #define C1      129
960 #define C2      130
961 #define C3      131
962 #define C4      132
963 #define C5      133
964 #define C6      134
965 #define C7      135
966 #define C8      136
967 #define M2      144
968 #define M3      145
969 #define M4      146
970 #define M       147
971 static unsigned char cheetah_ecc_syntab[] = {
972 /*00*/NONE, C0, C1, M2, C2, M2, M3, 47, C3, M2, M2, 53, M2, 41, 29, M,
973 /*01*/C4, M, M, 50, M2, 38, 25, M2, M2, 33, 24, M2, 11, M, M2, 16,
974 /*02*/C5, M, M, 46, M2, 37, 19, M2, M, 31, 32, M, 7, M2, M2, 10,
975 /*03*/M2, 40, 13, M2, 59, M, M2, 66, M, M2, M2, 0, M2, 67, 71, M,
976 /*04*/C6, M, M, 43, M, 36, 18, M, M2, 49, 15, M, 63, M2, M2, 6,
977 /*05*/M2, 44, 28, M2, M, M2, M2, 52, 68, M2, M2, 62, M2, M3, M3, M4,
978 /*06*/M2, 26, 106, M2, 64, M, M2, 2, 120, M, M2, M3, M, M3, M3, M4,
979 /*07*/116, M2, M2, M3, M2, M3, M, M4, M2, 58, 54, M2, M, M4, M4, M3,
980 /*08*/C7, M2, M, 42, M, 35, 17, M2, M, 45, 14, M2, 21, M2, M2, 5,
981 /*09*/M, 27, M, M, 99, M, M, 3, 114, M2, M2, 20, M2, M3, M3, M,
982 /*0a*/M2, 23, 113, M2, 112, M2, M, 51, 95, M, M2, M3, M2, M3, M3, M2,
983 /*0b*/103, M, M2, M3, M2, M3, M3, M4, M2, 48, M, M, 73, M2, M, M3,
984 /*0c*/M2, 22, 110, M2, 109, M2, M, 9, 108, M2, M, M3, M2, M3, M3, M,
985 /*0d*/102, M2, M, M, M2, M3, M3, M, M2, M3, M3, M2, M, M4, M, M3,
986 /*0e*/98, M, M2, M3, M2, M, M3, M4, M2, M3, M3, M4, M3, M, M, M,
987 /*0f*/M2, M3, M3, M, M3, M, M, M, 56, M4, M, M3, M4, M, M, M,
988 /*10*/C8, M, M2, 39, M, 34, 105, M2, M, 30, 104, M, 101, M, M, 4,
989 /*11*/M, M, 100, M, 83, M, M2, 12, 87, M, M, 57, M2, M, M3, M,
990 /*12*/M2, 97, 82, M2, 78, M2, M2, 1, 96, M, M, M, M, M, M3, M2,
991 /*13*/94, M, M2, M3, M2, M, M3, M, M2, M, 79, M, 69, M, M4, M,
992 /*14*/M2, 93, 92, M, 91, M, M2, 8, 90, M2, M2, M, M, M, M, M4,
993 /*15*/89, M, M, M3, M2, M3, M3, M, M, M, M3, M2, M3, M2, M, M3,
994 /*16*/86, M, M2, M3, M2, M, M3, M, M2, M, M3, M, M3, M, M, M3,
995 /*17*/M, M, M3, M2, M3, M2, M4, M, 60, M, M2, M3, M4, M, M, M2,
996 /*18*/M2, 88, 85, M2, 84, M, M2, 55, 81, M2, M2, M3, M2, M3, M3, M4,
997 /*19*/77, M, M, M, M2, M3, M, M, M2, M3, M3, M4, M3, M2, M, M,
998 /*1a*/74, M, M2, M3, M, M, M3, M, M, M, M3, M, M3, M, M4, M3,
999 /*1b*/M2, 70, 107, M4, 65, M2, M2, M, 127, M, M, M, M2, M3, M3, M,
1000 /*1c*/80, M2, M2, 72, M, 119, 118, M, M2, 126, 76, M, 125, M, M4, M3,
1001 /*1d*/M2, 115, 124, M, 75, M, M, M3, 61, M, M4, M, M4, M, M, M,
1002 /*1e*/M, 123, 122, M4, 121, M4, M, M3, 117, M2, M2, M3, M4, M3, M, M,
1003 /*1f*/111, M, M, M, M4, M3, M3, M, M, M, M3, M, M3, M2, M, M
1004 };
1005 static unsigned char cheetah_mtag_syntab[] = {
1006        NONE, MTC0,
1007        MTC1, NONE,
1008        MTC2, NONE,
1009        NONE, MT0,
1010        MTC3, NONE,
1011        NONE, MT1,
1012        NONE, MT2,
1013        NONE, NONE
1014 };
1015
1016 /* Return the highest priority error conditon mentioned. */
1017 static __inline__ unsigned long cheetah_get_hipri(unsigned long afsr)
1018 {
1019         unsigned long tmp = 0;
1020         int i;
1021
1022         for (i = 0; cheetah_error_table[i].mask; i++) {
1023                 if ((tmp = (afsr & cheetah_error_table[i].mask)) != 0UL)
1024                         return tmp;
1025         }
1026         return tmp;
1027 }
1028
1029 static const char *cheetah_get_string(unsigned long bit)
1030 {
1031         int i;
1032
1033         for (i = 0; cheetah_error_table[i].mask; i++) {
1034                 if ((bit & cheetah_error_table[i].mask) != 0UL)
1035                         return cheetah_error_table[i].name;
1036         }
1037         return "???";
1038 }
1039
1040 extern int chmc_getunumber(int, unsigned long, char *, int);
1041
1042 static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *info,
1043                                unsigned long afsr, unsigned long afar, int recoverable)
1044 {
1045         unsigned long hipri;
1046         char unum[256];
1047
1048         printk("%s" "ERROR(%d): Cheetah error trap taken afsr[%016lx] afar[%016lx] TL1(%d)\n",
1049                (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1050                afsr, afar,
1051                (afsr & CHAFSR_TL1) ? 1 : 0);
1052         printk("%s" "ERROR(%d): TPC[%016lx] TNPC[%016lx] TSTATE[%016lx]\n",
1053                (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1054                regs->tpc, regs->tnpc, regs->tstate);
1055         printk("%s" "ERROR(%d): M_SYND(%lx),  E_SYND(%lx)%s%s\n",
1056                (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1057                (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
1058                (afsr & CHAFSR_E_SYNDROME) >> CHAFSR_E_SYNDROME_SHIFT,
1059                (afsr & CHAFSR_ME) ? ", Multiple Errors" : "",
1060                (afsr & CHAFSR_PRIV) ? ", Privileged" : "");
1061         hipri = cheetah_get_hipri(afsr);
1062         printk("%s" "ERROR(%d): Highest priority error (%016lx) \"%s\"\n",
1063                (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1064                hipri, cheetah_get_string(hipri));
1065
1066         /* Try to get unumber if relevant. */
1067 #define ESYND_ERRORS    (CHAFSR_IVC | CHAFSR_IVU | \
1068                          CHAFSR_CPC | CHAFSR_CPU | \
1069                          CHAFSR_UE  | CHAFSR_CE  | \
1070                          CHAFSR_EDC | CHAFSR_EDU  | \
1071                          CHAFSR_UCC | CHAFSR_UCU  | \
1072                          CHAFSR_WDU | CHAFSR_WDC)
1073 #define MSYND_ERRORS    (CHAFSR_EMC | CHAFSR_EMU)
1074         if (afsr & ESYND_ERRORS) {
1075                 int syndrome;
1076                 int ret;
1077
1078                 syndrome = (afsr & CHAFSR_E_SYNDROME) >> CHAFSR_E_SYNDROME_SHIFT;
1079                 syndrome = cheetah_ecc_syntab[syndrome];
1080                 ret = chmc_getunumber(syndrome, afar, unum, sizeof(unum));
1081                 if (ret != -1)
1082                         printk("%s" "ERROR(%d): AFAR E-syndrome [%s]\n",
1083                                (recoverable ? KERN_WARNING : KERN_CRIT),
1084                                smp_processor_id(), unum);
1085         } else if (afsr & MSYND_ERRORS) {
1086                 int syndrome;
1087                 int ret;
1088
1089                 syndrome = (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT;
1090                 syndrome = cheetah_mtag_syntab[syndrome];
1091                 ret = chmc_getunumber(syndrome, afar, unum, sizeof(unum));
1092                 if (ret != -1)
1093                         printk("%s" "ERROR(%d): AFAR M-syndrome [%s]\n",
1094                                (recoverable ? KERN_WARNING : KERN_CRIT),
1095                                smp_processor_id(), unum);
1096         }
1097
1098         /* Now dump the cache snapshots. */
1099         printk("%s" "ERROR(%d): D-cache idx[%x] tag[%016lx] utag[%016lx] stag[%016lx]\n",
1100                (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1101                (int) info->dcache_index,
1102                info->dcache_tag,
1103                info->dcache_utag,
1104                info->dcache_stag);
1105         printk("%s" "ERROR(%d): D-cache data0[%016lx] data1[%016lx] data2[%016lx] data3[%016lx]\n",
1106                (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1107                info->dcache_data[0],
1108                info->dcache_data[1],
1109                info->dcache_data[2],
1110                info->dcache_data[3]);
1111         printk("%s" "ERROR(%d): I-cache idx[%x] tag[%016lx] utag[%016lx] stag[%016lx] "
1112                "u[%016lx] l[%016lx]\n",
1113                (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1114                (int) info->icache_index,
1115                info->icache_tag,
1116                info->icache_utag,
1117                info->icache_stag,
1118                info->icache_upper,
1119                info->icache_lower);
1120         printk("%s" "ERROR(%d): I-cache INSN0[%016lx] INSN1[%016lx] INSN2[%016lx] INSN3[%016lx]\n",
1121                (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1122                info->icache_data[0],
1123                info->icache_data[1],
1124                info->icache_data[2],
1125                info->icache_data[3]);
1126         printk("%s" "ERROR(%d): I-cache INSN4[%016lx] INSN5[%016lx] INSN6[%016lx] INSN7[%016lx]\n",
1127                (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1128                info->icache_data[4],
1129                info->icache_data[5],
1130                info->icache_data[6],
1131                info->icache_data[7]);
1132         printk("%s" "ERROR(%d): E-cache idx[%x] tag[%016lx]\n",
1133                (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1134                (int) info->ecache_index, info->ecache_tag);
1135         printk("%s" "ERROR(%d): E-cache data0[%016lx] data1[%016lx] data2[%016lx] data3[%016lx]\n",
1136                (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1137                info->ecache_data[0],
1138                info->ecache_data[1],
1139                info->ecache_data[2],
1140                info->ecache_data[3]);
1141
1142         afsr = (afsr & ~hipri) & cheetah_afsr_errors;
1143         while (afsr != 0UL) {
1144                 unsigned long bit = cheetah_get_hipri(afsr);
1145
1146                 printk("%s" "ERROR: Multiple-error (%016lx) \"%s\"\n",
1147                        (recoverable ? KERN_WARNING : KERN_CRIT),
1148                        bit, cheetah_get_string(bit));
1149
1150                 afsr &= ~bit;
1151         }
1152
1153         if (!recoverable)
1154                 printk(KERN_CRIT "ERROR: This condition is not recoverable.\n");
1155 }
1156
1157 static int cheetah_recheck_errors(struct cheetah_err_info *logp)
1158 {
1159         unsigned long afsr, afar;
1160         int ret = 0;
1161
1162         __asm__ __volatile__("ldxa [%%g0] %1, %0\n\t"
1163                              : "=r" (afsr)
1164                              : "i" (ASI_AFSR));
1165         if ((afsr & cheetah_afsr_errors) != 0) {
1166                 if (logp != NULL) {
1167                         __asm__ __volatile__("ldxa [%%g0] %1, %0\n\t"
1168                                              : "=r" (afar)
1169                                              : "i" (ASI_AFAR));
1170                         logp->afsr = afsr;
1171                         logp->afar = afar;
1172                 }
1173                 ret = 1;
1174         }
1175         __asm__ __volatile__("stxa %0, [%%g0] %1\n\t"
1176                              "membar #Sync\n\t"
1177                              : : "r" (afsr), "i" (ASI_AFSR));
1178
1179         return ret;
1180 }
1181
1182 void cheetah_fecc_handler(struct pt_regs *regs, unsigned long afsr, unsigned long afar)
1183 {
1184         struct cheetah_err_info local_snapshot, *p;
1185         int recoverable;
1186
1187         /* Flush E-cache */
1188         cheetah_flush_ecache();
1189
1190         p = cheetah_get_error_log(afsr);
1191         if (!p) {
1192                 prom_printf("ERROR: Early Fast-ECC error afsr[%016lx] afar[%016lx]\n",
1193                             afsr, afar);
1194                 prom_printf("ERROR: CPU(%d) TPC[%016lx] TNPC[%016lx] TSTATE[%016lx]\n",
1195                             smp_processor_id(), regs->tpc, regs->tnpc, regs->tstate);
1196                 prom_halt();
1197         }
1198
1199         /* Grab snapshot of logged error. */
1200         memcpy(&local_snapshot, p, sizeof(local_snapshot));
1201
1202         /* If the current trap snapshot does not match what the
1203          * trap handler passed along into our args, big trouble.
1204          * In such a case, mark the local copy as invalid.
1205          *
1206          * Else, it matches and we mark the afsr in the non-local
1207          * copy as invalid so we may log new error traps there.
1208          */
1209         if (p->afsr != afsr || p->afar != afar)
1210                 local_snapshot.afsr = CHAFSR_INVALID;
1211         else
1212                 p->afsr = CHAFSR_INVALID;
1213
1214         cheetah_flush_icache();
1215         cheetah_flush_dcache();
1216
1217         /* Re-enable I-cache/D-cache */
1218         __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
1219                              "or %%g1, %1, %%g1\n\t"
1220                              "stxa %%g1, [%%g0] %0\n\t"
1221                              "membar #Sync"
1222                              : /* no outputs */
1223                              : "i" (ASI_DCU_CONTROL_REG),
1224                                "i" (DCU_DC | DCU_IC)
1225                              : "g1");
1226
1227         /* Re-enable error reporting */
1228         __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
1229                              "or %%g1, %1, %%g1\n\t"
1230                              "stxa %%g1, [%%g0] %0\n\t"
1231                              "membar #Sync"
1232                              : /* no outputs */
1233                              : "i" (ASI_ESTATE_ERROR_EN),
1234                                "i" (ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN)
1235                              : "g1");
1236
1237         /* Decide if we can continue after handling this trap and
1238          * logging the error.
1239          */
1240         recoverable = 1;
1241         if (afsr & (CHAFSR_PERR | CHAFSR_IERR | CHAFSR_ISAP))
1242                 recoverable = 0;
1243
1244         /* Re-check AFSR/AFAR.  What we are looking for here is whether a new
1245          * error was logged while we had error reporting traps disabled.
1246          */
1247         if (cheetah_recheck_errors(&local_snapshot)) {
1248                 unsigned long new_afsr = local_snapshot.afsr;
1249
1250                 /* If we got a new asynchronous error, die... */
1251                 if (new_afsr & (CHAFSR_EMU | CHAFSR_EDU |
1252                                 CHAFSR_WDU | CHAFSR_CPU |
1253                                 CHAFSR_IVU | CHAFSR_UE |
1254                                 CHAFSR_BERR | CHAFSR_TO))
1255                         recoverable = 0;
1256         }
1257
1258         /* Log errors. */
1259         cheetah_log_errors(regs, &local_snapshot, afsr, afar, recoverable);
1260
1261         if (!recoverable)
1262                 panic("Irrecoverable Fast-ECC error trap.\n");
1263
1264         /* Flush E-cache to kick the error trap handlers out. */
1265         cheetah_flush_ecache();
1266 }
1267
1268 /* Try to fix a correctable error by pushing the line out from
1269  * the E-cache.  Recheck error reporting registers to see if the
1270  * problem is intermittent.
1271  */
1272 static int cheetah_fix_ce(unsigned long physaddr)
1273 {
1274         unsigned long orig_estate;
1275         unsigned long alias1, alias2;
1276         int ret;
1277
1278         /* Make sure correctable error traps are disabled. */
1279         __asm__ __volatile__("ldxa      [%%g0] %2, %0\n\t"
1280                              "andn      %0, %1, %%g1\n\t"
1281                              "stxa      %%g1, [%%g0] %2\n\t"
1282                              "membar    #Sync"
1283                              : "=&r" (orig_estate)
1284                              : "i" (ESTATE_ERROR_CEEN),
1285                                "i" (ASI_ESTATE_ERROR_EN)
1286                              : "g1");
1287
1288         /* We calculate alias addresses that will force the
1289          * cache line in question out of the E-cache.  Then
1290          * we bring it back in with an atomic instruction so
1291          * that we get it in some modified/exclusive state,
1292          * then we displace it again to try and get proper ECC
1293          * pushed back into the system.
1294          */
1295         physaddr &= ~(8UL - 1UL);
1296         alias1 = (ecache_flush_physbase +
1297                   (physaddr & ((ecache_flush_size >> 1) - 1)));
1298         alias2 = alias1 + (ecache_flush_size >> 1);
1299         __asm__ __volatile__("ldxa      [%0] %3, %%g0\n\t"
1300                              "ldxa      [%1] %3, %%g0\n\t"
1301                              "casxa     [%2] %3, %%g0, %%g0\n\t"
1302                              "membar    #StoreLoad | #StoreStore\n\t"
1303                              "ldxa      [%0] %3, %%g0\n\t"
1304                              "ldxa      [%1] %3, %%g0\n\t"
1305                              "membar    #Sync"
1306                              : /* no outputs */
1307                              : "r" (alias1), "r" (alias2),
1308                                "r" (physaddr), "i" (ASI_PHYS_USE_EC));
1309
1310         /* Did that trigger another error? */
1311         if (cheetah_recheck_errors(NULL)) {
1312                 /* Try one more time. */
1313                 __asm__ __volatile__("ldxa [%0] %1, %%g0\n\t"
1314                                      "membar #Sync"
1315                                      : : "r" (physaddr), "i" (ASI_PHYS_USE_EC));
1316                 if (cheetah_recheck_errors(NULL))
1317                         ret = 2;
1318                 else
1319                         ret = 1;
1320         } else {
1321                 /* No new error, intermittent problem. */
1322                 ret = 0;
1323         }
1324
1325         /* Restore error enables. */
1326         __asm__ __volatile__("stxa      %0, [%%g0] %1\n\t"
1327                              "membar    #Sync"
1328                              : : "r" (orig_estate), "i" (ASI_ESTATE_ERROR_EN));
1329
1330         return ret;
1331 }
1332
1333 /* Return non-zero if PADDR is a valid physical memory address. */
1334 static int cheetah_check_main_memory(unsigned long paddr)
1335 {
1336         unsigned long vaddr = PAGE_OFFSET + paddr;
1337
1338         if (vaddr > (unsigned long) high_memory)
1339                 return 0;
1340
1341         return kern_addr_valid(vaddr);
1342 }
1343
1344 void cheetah_cee_handler(struct pt_regs *regs, unsigned long afsr, unsigned long afar)
1345 {
1346         struct cheetah_err_info local_snapshot, *p;
1347         int recoverable, is_memory;
1348
1349         p = cheetah_get_error_log(afsr);
1350         if (!p) {
1351                 prom_printf("ERROR: Early CEE error afsr[%016lx] afar[%016lx]\n",
1352                             afsr, afar);
1353                 prom_printf("ERROR: CPU(%d) TPC[%016lx] TNPC[%016lx] TSTATE[%016lx]\n",
1354                             smp_processor_id(), regs->tpc, regs->tnpc, regs->tstate);
1355                 prom_halt();
1356         }
1357
1358         /* Grab snapshot of logged error. */
1359         memcpy(&local_snapshot, p, sizeof(local_snapshot));
1360
1361         /* If the current trap snapshot does not match what the
1362          * trap handler passed along into our args, big trouble.
1363          * In such a case, mark the local copy as invalid.
1364          *
1365          * Else, it matches and we mark the afsr in the non-local
1366          * copy as invalid so we may log new error traps there.
1367          */
1368         if (p->afsr != afsr || p->afar != afar)
1369                 local_snapshot.afsr = CHAFSR_INVALID;
1370         else
1371                 p->afsr = CHAFSR_INVALID;
1372
1373         is_memory = cheetah_check_main_memory(afar);
1374
1375         if (is_memory && (afsr & CHAFSR_CE) != 0UL) {
1376                 /* XXX Might want to log the results of this operation
1377                  * XXX somewhere... -DaveM
1378                  */
1379                 cheetah_fix_ce(afar);
1380         }
1381
1382         {
1383                 int flush_all, flush_line;
1384
1385                 flush_all = flush_line = 0;
1386                 if ((afsr & CHAFSR_EDC) != 0UL) {
1387                         if ((afsr & cheetah_afsr_errors) == CHAFSR_EDC)
1388                                 flush_line = 1;
1389                         else
1390                                 flush_all = 1;
1391                 } else if ((afsr & CHAFSR_CPC) != 0UL) {
1392                         if ((afsr & cheetah_afsr_errors) == CHAFSR_CPC)
1393                                 flush_line = 1;
1394                         else
1395                                 flush_all = 1;
1396                 }
1397
1398                 /* Trap handler only disabled I-cache, flush it. */
1399                 cheetah_flush_icache();
1400
1401                 /* Re-enable I-cache */
1402                 __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
1403                                      "or %%g1, %1, %%g1\n\t"
1404                                      "stxa %%g1, [%%g0] %0\n\t"
1405                                      "membar #Sync"
1406                                      : /* no outputs */
1407                                      : "i" (ASI_DCU_CONTROL_REG),
1408                                      "i" (DCU_IC)
1409                                      : "g1");
1410
1411                 if (flush_all)
1412                         cheetah_flush_ecache();
1413                 else if (flush_line)
1414                         cheetah_flush_ecache_line(afar);
1415         }
1416
1417         /* Re-enable error reporting */
1418         __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
1419                              "or %%g1, %1, %%g1\n\t"
1420                              "stxa %%g1, [%%g0] %0\n\t"
1421                              "membar #Sync"
1422                              : /* no outputs */
1423                              : "i" (ASI_ESTATE_ERROR_EN),
1424                                "i" (ESTATE_ERROR_CEEN)
1425                              : "g1");
1426
1427         /* Decide if we can continue after handling this trap and
1428          * logging the error.
1429          */
1430         recoverable = 1;
1431         if (afsr & (CHAFSR_PERR | CHAFSR_IERR | CHAFSR_ISAP))
1432                 recoverable = 0;
1433
1434         /* Re-check AFSR/AFAR */
1435         (void) cheetah_recheck_errors(&local_snapshot);
1436
1437         /* Log errors. */
1438         cheetah_log_errors(regs, &local_snapshot, afsr, afar, recoverable);
1439
1440         if (!recoverable)
1441                 panic("Irrecoverable Correctable-ECC error trap.\n");
1442 }
1443
1444 void cheetah_deferred_handler(struct pt_regs *regs, unsigned long afsr, unsigned long afar)
1445 {
1446         struct cheetah_err_info local_snapshot, *p;
1447         int recoverable, is_memory;
1448
1449 #ifdef CONFIG_PCI
1450         /* Check for the special PCI poke sequence. */
1451         if (pci_poke_in_progress && pci_poke_cpu == smp_processor_id()) {
1452                 cheetah_flush_icache();
1453                 cheetah_flush_dcache();
1454
1455                 /* Re-enable I-cache/D-cache */
1456                 __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
1457                                      "or %%g1, %1, %%g1\n\t"
1458                                      "stxa %%g1, [%%g0] %0\n\t"
1459                                      "membar #Sync"
1460                                      : /* no outputs */
1461                                      : "i" (ASI_DCU_CONTROL_REG),
1462                                        "i" (DCU_DC | DCU_IC)
1463                                      : "g1");
1464
1465                 /* Re-enable error reporting */
1466                 __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
1467                                      "or %%g1, %1, %%g1\n\t"
1468                                      "stxa %%g1, [%%g0] %0\n\t"
1469                                      "membar #Sync"
1470                                      : /* no outputs */
1471                                      : "i" (ASI_ESTATE_ERROR_EN),
1472                                        "i" (ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN)
1473                                      : "g1");
1474
1475                 (void) cheetah_recheck_errors(NULL);
1476
1477                 pci_poke_faulted = 1;
1478                 regs->tpc += 4;
1479                 regs->tnpc = regs->tpc + 4;
1480                 return;
1481         }
1482 #endif
1483
1484         p = cheetah_get_error_log(afsr);
1485         if (!p) {
1486                 prom_printf("ERROR: Early deferred error afsr[%016lx] afar[%016lx]\n",
1487                             afsr, afar);
1488                 prom_printf("ERROR: CPU(%d) TPC[%016lx] TNPC[%016lx] TSTATE[%016lx]\n",
1489                             smp_processor_id(), regs->tpc, regs->tnpc, regs->tstate);
1490                 prom_halt();
1491         }
1492
1493         /* Grab snapshot of logged error. */
1494         memcpy(&local_snapshot, p, sizeof(local_snapshot));
1495
1496         /* If the current trap snapshot does not match what the
1497          * trap handler passed along into our args, big trouble.
1498          * In such a case, mark the local copy as invalid.
1499          *
1500          * Else, it matches and we mark the afsr in the non-local
1501          * copy as invalid so we may log new error traps there.
1502          */
1503         if (p->afsr != afsr || p->afar != afar)
1504                 local_snapshot.afsr = CHAFSR_INVALID;
1505         else
1506                 p->afsr = CHAFSR_INVALID;
1507
1508         is_memory = cheetah_check_main_memory(afar);
1509
1510         {
1511                 int flush_all, flush_line;
1512
1513                 flush_all = flush_line = 0;
1514                 if ((afsr & CHAFSR_EDU) != 0UL) {
1515                         if ((afsr & cheetah_afsr_errors) == CHAFSR_EDU)
1516                                 flush_line = 1;
1517                         else
1518                                 flush_all = 1;
1519                 } else if ((afsr & CHAFSR_BERR) != 0UL) {
1520                         if ((afsr & cheetah_afsr_errors) == CHAFSR_BERR)
1521                                 flush_line = 1;
1522                         else
1523                                 flush_all = 1;
1524                 }
1525
1526                 cheetah_flush_icache();
1527                 cheetah_flush_dcache();
1528
1529                 /* Re-enable I/D caches */
1530                 __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
1531                                      "or %%g1, %1, %%g1\n\t"
1532                                      "stxa %%g1, [%%g0] %0\n\t"
1533                                      "membar #Sync"
1534                                      : /* no outputs */
1535                                      : "i" (ASI_DCU_CONTROL_REG),
1536                                      "i" (DCU_IC | DCU_DC)
1537                                      : "g1");
1538
1539                 if (flush_all)
1540                         cheetah_flush_ecache();
1541                 else if (flush_line)
1542                         cheetah_flush_ecache_line(afar);
1543         }
1544
1545         /* Re-enable error reporting */
1546         __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
1547                              "or %%g1, %1, %%g1\n\t"
1548                              "stxa %%g1, [%%g0] %0\n\t"
1549                              "membar #Sync"
1550                              : /* no outputs */
1551                              : "i" (ASI_ESTATE_ERROR_EN),
1552                              "i" (ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN)
1553                              : "g1");
1554
1555         /* Decide if we can continue after handling this trap and
1556          * logging the error.
1557          */
1558         recoverable = 1;
1559         if (afsr & (CHAFSR_PERR | CHAFSR_IERR | CHAFSR_ISAP))
1560                 recoverable = 0;
1561
1562         /* Re-check AFSR/AFAR.  What we are looking for here is whether a new
1563          * error was logged while we had error reporting traps disabled.
1564          */
1565         if (cheetah_recheck_errors(&local_snapshot)) {
1566                 unsigned long new_afsr = local_snapshot.afsr;
1567
1568                 /* If we got a new asynchronous error, die... */
1569                 if (new_afsr & (CHAFSR_EMU | CHAFSR_EDU |
1570                                 CHAFSR_WDU | CHAFSR_CPU |
1571                                 CHAFSR_IVU | CHAFSR_UE |
1572                                 CHAFSR_BERR | CHAFSR_TO))
1573                         recoverable = 0;
1574         }
1575
1576         /* Log errors. */
1577         cheetah_log_errors(regs, &local_snapshot, afsr, afar, recoverable);
1578
1579         /* "Recoverable" here means we try to yank the page from ever
1580          * being newly used again.  This depends upon a few things:
1581          * 1) Must be main memory, and AFAR must be valid.
1582          * 2) If we trapped from user, OK.
1583          * 3) Else, if we trapped from kernel we must find exception
1584          *    table entry (ie. we have to have been accessing user
1585          *    space).
1586          *
1587          * If AFAR is not in main memory, or we trapped from kernel
1588          * and cannot find an exception table entry, it is unacceptable
1589          * to try and continue.
1590          */
1591         if (recoverable && is_memory) {
1592                 if ((regs->tstate & TSTATE_PRIV) == 0UL) {
1593                         /* OK, usermode access. */
1594                         recoverable = 1;
1595                 } else {
1596                         const struct exception_table_entry *entry;
1597
1598                         entry = search_exception_tables(regs->tpc);
1599                         if (entry) {
1600                                 /* OK, kernel access to userspace. */
1601                                 recoverable = 1;
1602
1603                         } else {
1604                                 /* BAD, privileged state is corrupted. */
1605                                 recoverable = 0;
1606                         }
1607
1608                         if (recoverable) {
1609                                 if (pfn_valid(afar >> PAGE_SHIFT))
1610                                         get_page(pfn_to_page(afar >> PAGE_SHIFT));
1611                                 else
1612                                         recoverable = 0;
1613
1614                                 /* Only perform fixup if we still have a
1615                                  * recoverable condition.
1616                                  */
1617                                 if (recoverable) {
1618                                         regs->tpc = entry->fixup;
1619                                         regs->tnpc = regs->tpc + 4;
1620                                 }
1621                         }
1622                 }
1623         } else {
1624                 recoverable = 0;
1625         }
1626
1627         if (!recoverable)
1628                 panic("Irrecoverable deferred error trap.\n");
1629 }
1630
1631 /* Handle a D/I cache parity error trap.  TYPE is encoded as:
1632  *
1633  * Bit0:        0=dcache,1=icache
1634  * Bit1:        0=recoverable,1=unrecoverable
1635  *
1636  * The hardware has disabled both the I-cache and D-cache in
1637  * the %dcr register.  
1638  */
1639 void cheetah_plus_parity_error(int type, struct pt_regs *regs)
1640 {
1641         if (type & 0x1)
1642                 __cheetah_flush_icache();
1643         else
1644                 cheetah_plus_zap_dcache_parity();
1645         cheetah_flush_dcache();
1646
1647         /* Re-enable I-cache/D-cache */
1648         __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
1649                              "or %%g1, %1, %%g1\n\t"
1650                              "stxa %%g1, [%%g0] %0\n\t"
1651                              "membar #Sync"
1652                              : /* no outputs */
1653                              : "i" (ASI_DCU_CONTROL_REG),
1654                                "i" (DCU_DC | DCU_IC)
1655                              : "g1");
1656
1657         if (type & 0x2) {
1658                 printk(KERN_EMERG "CPU[%d]: Cheetah+ %c-cache parity error at TPC[%016lx]\n",
1659                        smp_processor_id(),
1660                        (type & 0x1) ? 'I' : 'D',
1661                        regs->tpc);
1662                 panic("Irrecoverable Cheetah+ parity error.");
1663         }
1664
1665         printk(KERN_WARNING "CPU[%d]: Cheetah+ %c-cache parity error at TPC[%016lx]\n",
1666                smp_processor_id(),
1667                (type & 0x1) ? 'I' : 'D',
1668                regs->tpc);
1669 }
1670
1671 void do_fpe_common(struct pt_regs *regs)
1672 {
1673         if (regs->tstate & TSTATE_PRIV) {
1674                 regs->tpc = regs->tnpc;
1675                 regs->tnpc += 4;
1676         } else {
1677                 unsigned long fsr = current_thread_info()->xfsr[0];
1678                 siginfo_t info;
1679
1680                 if (test_thread_flag(TIF_32BIT)) {
1681                         regs->tpc &= 0xffffffff;
1682                         regs->tnpc &= 0xffffffff;
1683                 }
1684                 info.si_signo = SIGFPE;
1685                 info.si_errno = 0;
1686                 info.si_addr = (void __user *)regs->tpc;
1687                 info.si_trapno = 0;
1688                 info.si_code = __SI_FAULT;
1689                 if ((fsr & 0x1c000) == (1 << 14)) {
1690                         if (fsr & 0x10)
1691                                 info.si_code = FPE_FLTINV;
1692                         else if (fsr & 0x08)
1693                                 info.si_code = FPE_FLTOVF;
1694                         else if (fsr & 0x04)
1695                                 info.si_code = FPE_FLTUND;
1696                         else if (fsr & 0x02)
1697                                 info.si_code = FPE_FLTDIV;
1698                         else if (fsr & 0x01)
1699                                 info.si_code = FPE_FLTRES;
1700                 }
1701                 force_sig_info(SIGFPE, &info, current);
1702         }
1703 }
1704
1705 void do_fpieee(struct pt_regs *regs)
1706 {
1707         if (notify_die(DIE_TRAP, "fpu exception ieee", regs,
1708                        0, 0x24, SIGFPE) == NOTIFY_STOP)
1709                 return;
1710
1711         do_fpe_common(regs);
1712 }
1713
1714 extern int do_mathemu(struct pt_regs *, struct fpustate *);
1715
1716 void do_fpother(struct pt_regs *regs)
1717 {
1718         struct fpustate *f = FPUSTATE;
1719         int ret = 0;
1720
1721         if (notify_die(DIE_TRAP, "fpu exception other", regs,
1722                        0, 0x25, SIGFPE) == NOTIFY_STOP)
1723                 return;
1724
1725         switch ((current_thread_info()->xfsr[0] & 0x1c000)) {
1726         case (2 << 14): /* unfinished_FPop */
1727         case (3 << 14): /* unimplemented_FPop */
1728                 ret = do_mathemu(regs, f);
1729                 break;
1730         }
1731         if (ret)
1732                 return;
1733         do_fpe_common(regs);
1734 }
1735
1736 void do_tof(struct pt_regs *regs)
1737 {
1738         siginfo_t info;
1739
1740         if (notify_die(DIE_TRAP, "tagged arithmetic overflow", regs,
1741                        0, 0x26, SIGEMT) == NOTIFY_STOP)
1742                 return;
1743
1744         if (regs->tstate & TSTATE_PRIV)
1745                 die_if_kernel("Penguin overflow trap from kernel mode", regs);
1746         if (test_thread_flag(TIF_32BIT)) {
1747                 regs->tpc &= 0xffffffff;
1748                 regs->tnpc &= 0xffffffff;
1749         }
1750         info.si_signo = SIGEMT;
1751         info.si_errno = 0;
1752         info.si_code = EMT_TAGOVF;
1753         info.si_addr = (void __user *)regs->tpc;
1754         info.si_trapno = 0;
1755         force_sig_info(SIGEMT, &info, current);
1756 }
1757
1758 void do_div0(struct pt_regs *regs)
1759 {
1760         siginfo_t info;
1761
1762         if (notify_die(DIE_TRAP, "integer division by zero", regs,
1763                        0, 0x28, SIGFPE) == NOTIFY_STOP)
1764                 return;
1765
1766         if (regs->tstate & TSTATE_PRIV)
1767                 die_if_kernel("TL0: Kernel divide by zero.", regs);
1768         if (test_thread_flag(TIF_32BIT)) {
1769                 regs->tpc &= 0xffffffff;
1770                 regs->tnpc &= 0xffffffff;
1771         }
1772         info.si_signo = SIGFPE;
1773         info.si_errno = 0;
1774         info.si_code = FPE_INTDIV;
1775         info.si_addr = (void __user *)regs->tpc;
1776         info.si_trapno = 0;
1777         force_sig_info(SIGFPE, &info, current);
1778 }
1779
1780 void instruction_dump (unsigned int *pc)
1781 {
1782         int i;
1783
1784         if ((((unsigned long) pc) & 3))
1785                 return;
1786
1787         printk("Instruction DUMP:");
1788         for (i = -3; i < 6; i++)
1789                 printk("%c%08x%c",i?' ':'<',pc[i],i?' ':'>');
1790         printk("\n");
1791 }
1792
1793 static void user_instruction_dump (unsigned int __user *pc)
1794 {
1795         int i;
1796         unsigned int buf[9];
1797         
1798         if ((((unsigned long) pc) & 3))
1799                 return;
1800                 
1801         if (copy_from_user(buf, pc - 3, sizeof(buf)))
1802                 return;
1803
1804         printk("Instruction DUMP:");
1805         for (i = 0; i < 9; i++)
1806                 printk("%c%08x%c",i==3?' ':'<',buf[i],i==3?' ':'>');
1807         printk("\n");
1808 }
1809
1810 void show_stack(struct task_struct *tsk, unsigned long *_ksp)
1811 {
1812         unsigned long pc, fp, thread_base, ksp;
1813         void *tp = task_stack_page(tsk);
1814         struct reg_window *rw;
1815         int count = 0;
1816
1817         ksp = (unsigned long) _ksp;
1818
1819         if (tp == current_thread_info())
1820                 flushw_all();
1821
1822         fp = ksp + STACK_BIAS;
1823         thread_base = (unsigned long) tp;
1824
1825         printk("Call Trace:");
1826 #ifdef CONFIG_KALLSYMS
1827         printk("\n");
1828 #endif
1829         do {
1830                 /* Bogus frame pointer? */
1831                 if (fp < (thread_base + sizeof(struct thread_info)) ||
1832                     fp >= (thread_base + THREAD_SIZE))
1833                         break;
1834                 rw = (struct reg_window *)fp;
1835                 pc = rw->ins[7];
1836                 printk(" [%016lx] ", pc);
1837                 print_symbol("%s\n", pc);
1838                 fp = rw->ins[6] + STACK_BIAS;
1839         } while (++count < 16);
1840 #ifndef CONFIG_KALLSYMS
1841         printk("\n");
1842 #endif
1843 }
1844
1845 void dump_stack(void)
1846 {
1847         unsigned long *ksp;
1848
1849         __asm__ __volatile__("mov       %%fp, %0"
1850                              : "=r" (ksp));
1851         show_stack(current, ksp);
1852 }
1853
1854 EXPORT_SYMBOL(dump_stack);
1855
1856 static inline int is_kernel_stack(struct task_struct *task,
1857                                   struct reg_window *rw)
1858 {
1859         unsigned long rw_addr = (unsigned long) rw;
1860         unsigned long thread_base, thread_end;
1861
1862         if (rw_addr < PAGE_OFFSET) {
1863                 if (task != &init_task)
1864                         return 0;
1865         }
1866
1867         thread_base = (unsigned long) task_stack_page(task);
1868         thread_end = thread_base + sizeof(union thread_union);
1869         if (rw_addr >= thread_base &&
1870             rw_addr < thread_end &&
1871             !(rw_addr & 0x7UL))
1872                 return 1;
1873
1874         return 0;
1875 }
1876
1877 static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
1878 {
1879         unsigned long fp = rw->ins[6];
1880
1881         if (!fp)
1882                 return NULL;
1883
1884         return (struct reg_window *) (fp + STACK_BIAS);
1885 }
1886
1887 void die_if_kernel(char *str, struct pt_regs *regs)
1888 {
1889         static int die_counter;
1890         extern void __show_regs(struct pt_regs * regs);
1891         extern void smp_report_regs(void);
1892         int count = 0;
1893         
1894         /* Amuse the user. */
1895         printk(
1896 "              \\|/ ____ \\|/\n"
1897 "              \"@'/ .. \\`@\"\n"
1898 "              /_| \\__/ |_\\\n"
1899 "                 \\__U_/\n");
1900
1901         printk("%s(%d): %s [#%d]\n", current->comm, current->pid, str, ++die_counter);
1902         notify_die(DIE_OOPS, str, regs, 0, 255, SIGSEGV);
1903         __asm__ __volatile__("flushw");
1904         __show_regs(regs);
1905         if (regs->tstate & TSTATE_PRIV) {
1906                 struct reg_window *rw = (struct reg_window *)
1907                         (regs->u_regs[UREG_FP] + STACK_BIAS);
1908
1909                 /* Stop the back trace when we hit userland or we
1910                  * find some badly aligned kernel stack.
1911                  */
1912                 while (rw &&
1913                        count++ < 30&&
1914                        is_kernel_stack(current, rw)) {
1915                         printk("Caller[%016lx]", rw->ins[7]);
1916                         print_symbol(": %s", rw->ins[7]);
1917                         printk("\n");
1918
1919                         rw = kernel_stack_up(rw);
1920                 }
1921                 instruction_dump ((unsigned int *) regs->tpc);
1922         } else {
1923                 if (test_thread_flag(TIF_32BIT)) {
1924                         regs->tpc &= 0xffffffff;
1925                         regs->tnpc &= 0xffffffff;
1926                 }
1927                 user_instruction_dump ((unsigned int __user *) regs->tpc);
1928         }
1929 #ifdef CONFIG_SMP
1930         smp_report_regs();
1931 #endif
1932                                                         
1933         if (regs->tstate & TSTATE_PRIV)
1934                 do_exit(SIGKILL);
1935         do_exit(SIGSEGV);
1936 }
1937
1938 extern int handle_popc(u32 insn, struct pt_regs *regs);
1939 extern int handle_ldf_stq(u32 insn, struct pt_regs *regs);
1940
1941 void do_illegal_instruction(struct pt_regs *regs)
1942 {
1943         unsigned long pc = regs->tpc;
1944         unsigned long tstate = regs->tstate;
1945         u32 insn;
1946         siginfo_t info;
1947
1948         if (notify_die(DIE_TRAP, "illegal instruction", regs,
1949                        0, 0x10, SIGILL) == NOTIFY_STOP)
1950                 return;
1951
1952         if (tstate & TSTATE_PRIV)
1953                 die_if_kernel("Kernel illegal instruction", regs);
1954         if (test_thread_flag(TIF_32BIT))
1955                 pc = (u32)pc;
1956         if (get_user(insn, (u32 __user *) pc) != -EFAULT) {
1957                 if ((insn & 0xc1ffc000) == 0x81700000) /* POPC */ {
1958                         if (handle_popc(insn, regs))
1959                                 return;
1960                 } else if ((insn & 0xc1580000) == 0xc1100000) /* LDQ/STQ */ {
1961                         if (handle_ldf_stq(insn, regs))
1962                                 return;
1963                 }
1964         }
1965         info.si_signo = SIGILL;
1966         info.si_errno = 0;
1967         info.si_code = ILL_ILLOPC;
1968         info.si_addr = (void __user *)pc;
1969         info.si_trapno = 0;
1970         force_sig_info(SIGILL, &info, current);
1971 }
1972
1973 void mem_address_unaligned(struct pt_regs *regs, unsigned long sfar, unsigned long sfsr)
1974 {
1975         siginfo_t info;
1976
1977         if (notify_die(DIE_TRAP, "memory address unaligned", regs,
1978                        0, 0x34, SIGSEGV) == NOTIFY_STOP)
1979                 return;
1980
1981         if (regs->tstate & TSTATE_PRIV) {
1982                 extern void kernel_unaligned_trap(struct pt_regs *regs,
1983                                                   unsigned int insn, 
1984                                                   unsigned long sfar,
1985                                                   unsigned long sfsr);
1986
1987                 kernel_unaligned_trap(regs, *((unsigned int *)regs->tpc),
1988                                       sfar, sfsr);
1989                 return;
1990         }
1991         info.si_signo = SIGBUS;
1992         info.si_errno = 0;
1993         info.si_code = BUS_ADRALN;
1994         info.si_addr = (void __user *)sfar;
1995         info.si_trapno = 0;
1996         force_sig_info(SIGBUS, &info, current);
1997 }
1998
1999 void do_privop(struct pt_regs *regs)
2000 {
2001         siginfo_t info;
2002
2003         if (notify_die(DIE_TRAP, "privileged operation", regs,
2004                        0, 0x11, SIGILL) == NOTIFY_STOP)
2005                 return;
2006
2007         if (test_thread_flag(TIF_32BIT)) {
2008                 regs->tpc &= 0xffffffff;
2009                 regs->tnpc &= 0xffffffff;
2010         }
2011         info.si_signo = SIGILL;
2012         info.si_errno = 0;
2013         info.si_code = ILL_PRVOPC;
2014         info.si_addr = (void __user *)regs->tpc;
2015         info.si_trapno = 0;
2016         force_sig_info(SIGILL, &info, current);
2017 }
2018
2019 void do_privact(struct pt_regs *regs)
2020 {
2021         do_privop(regs);
2022 }
2023
2024 /* Trap level 1 stuff or other traps we should never see... */
2025 void do_cee(struct pt_regs *regs)
2026 {
2027         die_if_kernel("TL0: Cache Error Exception", regs);
2028 }
2029
2030 void do_cee_tl1(struct pt_regs *regs)
2031 {
2032         dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2033         die_if_kernel("TL1: Cache Error Exception", regs);
2034 }
2035
2036 void do_dae_tl1(struct pt_regs *regs)
2037 {
2038         dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2039         die_if_kernel("TL1: Data Access Exception", regs);
2040 }
2041
2042 void do_iae_tl1(struct pt_regs *regs)
2043 {
2044         dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2045         die_if_kernel("TL1: Instruction Access Exception", regs);
2046 }
2047
2048 void do_div0_tl1(struct pt_regs *regs)
2049 {
2050         dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2051         die_if_kernel("TL1: DIV0 Exception", regs);
2052 }
2053
2054 void do_fpdis_tl1(struct pt_regs *regs)
2055 {
2056         dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2057         die_if_kernel("TL1: FPU Disabled", regs);
2058 }
2059
2060 void do_fpieee_tl1(struct pt_regs *regs)
2061 {
2062         dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2063         die_if_kernel("TL1: FPU IEEE Exception", regs);
2064 }
2065
2066 void do_fpother_tl1(struct pt_regs *regs)
2067 {
2068         dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2069         die_if_kernel("TL1: FPU Other Exception", regs);
2070 }
2071
2072 void do_ill_tl1(struct pt_regs *regs)
2073 {
2074         dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2075         die_if_kernel("TL1: Illegal Instruction Exception", regs);
2076 }
2077
2078 void do_irq_tl1(struct pt_regs *regs)
2079 {
2080         dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2081         die_if_kernel("TL1: IRQ Exception", regs);
2082 }
2083
2084 void do_lddfmna_tl1(struct pt_regs *regs)
2085 {
2086         dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2087         die_if_kernel("TL1: LDDF Exception", regs);
2088 }
2089
2090 void do_stdfmna_tl1(struct pt_regs *regs)
2091 {
2092         dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2093         die_if_kernel("TL1: STDF Exception", regs);
2094 }
2095
2096 void do_paw(struct pt_regs *regs)
2097 {
2098         die_if_kernel("TL0: Phys Watchpoint Exception", regs);
2099 }
2100
2101 void do_paw_tl1(struct pt_regs *regs)
2102 {
2103         dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2104         die_if_kernel("TL1: Phys Watchpoint Exception", regs);
2105 }
2106
2107 void do_vaw(struct pt_regs *regs)
2108 {
2109         die_if_kernel("TL0: Virt Watchpoint Exception", regs);
2110 }
2111
2112 void do_vaw_tl1(struct pt_regs *regs)
2113 {
2114         dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2115         die_if_kernel("TL1: Virt Watchpoint Exception", regs);
2116 }
2117
2118 void do_tof_tl1(struct pt_regs *regs)
2119 {
2120         dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2121         die_if_kernel("TL1: Tag Overflow Exception", regs);
2122 }
2123
2124 void do_getpsr(struct pt_regs *regs)
2125 {
2126         regs->u_regs[UREG_I0] = tstate_to_psr(regs->tstate);
2127         regs->tpc   = regs->tnpc;
2128         regs->tnpc += 4;
2129         if (test_thread_flag(TIF_32BIT)) {
2130                 regs->tpc &= 0xffffffff;
2131                 regs->tnpc &= 0xffffffff;
2132         }
2133 }
2134
2135 struct trap_per_cpu trap_block[NR_CPUS];
2136
2137 /* This can get invoked before sched_init() so play it super safe
2138  * and use hard_smp_processor_id().
2139  */
2140 void init_cur_cpu_trap(void)
2141 {
2142         int cpu = hard_smp_processor_id();
2143         struct trap_per_cpu *p = &trap_block[cpu];
2144
2145         p->thread = current_thread_info();
2146         p->pgd_paddr = 0;
2147 }
2148
2149 extern void thread_info_offsets_are_bolixed_dave(void);
2150 extern void trap_per_cpu_offsets_are_bolixed_dave(void);
2151
2152 /* Only invoked on boot processor. */
2153 void __init trap_init(void)
2154 {
2155         /* Compile time sanity check. */
2156         if (TI_TASK != offsetof(struct thread_info, task) ||
2157             TI_FLAGS != offsetof(struct thread_info, flags) ||
2158             TI_CPU != offsetof(struct thread_info, cpu) ||
2159             TI_FPSAVED != offsetof(struct thread_info, fpsaved) ||
2160             TI_KSP != offsetof(struct thread_info, ksp) ||
2161             TI_FAULT_ADDR != offsetof(struct thread_info, fault_address) ||
2162             TI_KREGS != offsetof(struct thread_info, kregs) ||
2163             TI_UTRAPS != offsetof(struct thread_info, utraps) ||
2164             TI_EXEC_DOMAIN != offsetof(struct thread_info, exec_domain) ||
2165             TI_REG_WINDOW != offsetof(struct thread_info, reg_window) ||
2166             TI_RWIN_SPTRS != offsetof(struct thread_info, rwbuf_stkptrs) ||
2167             TI_GSR != offsetof(struct thread_info, gsr) ||
2168             TI_XFSR != offsetof(struct thread_info, xfsr) ||
2169             TI_USER_CNTD0 != offsetof(struct thread_info, user_cntd0) ||
2170             TI_USER_CNTD1 != offsetof(struct thread_info, user_cntd1) ||
2171             TI_KERN_CNTD0 != offsetof(struct thread_info, kernel_cntd0) ||
2172             TI_KERN_CNTD1 != offsetof(struct thread_info, kernel_cntd1) ||
2173             TI_PCR != offsetof(struct thread_info, pcr_reg) ||
2174             TI_PRE_COUNT != offsetof(struct thread_info, preempt_count) ||
2175             TI_NEW_CHILD != offsetof(struct thread_info, new_child) ||
2176             TI_SYS_NOERROR != offsetof(struct thread_info, syscall_noerror) ||
2177             TI_RESTART_BLOCK != offsetof(struct thread_info, restart_block) ||
2178             TI_KUNA_REGS != offsetof(struct thread_info, kern_una_regs) ||
2179             TI_KUNA_INSN != offsetof(struct thread_info, kern_una_insn) ||
2180             TI_FPREGS != offsetof(struct thread_info, fpregs) ||
2181             (TI_FPREGS & (64 - 1)))
2182                 thread_info_offsets_are_bolixed_dave();
2183
2184         if (TRAP_PER_CPU_THREAD != offsetof(struct trap_per_cpu, thread) ||
2185             (TRAP_PER_CPU_PGD_PADDR !=
2186              offsetof(struct trap_per_cpu, pgd_paddr)) ||
2187             (TRAP_PER_CPU_CPU_MONDO_PA !=
2188              offsetof(struct trap_per_cpu, cpu_mondo_pa)) ||
2189             (TRAP_PER_CPU_DEV_MONDO_PA !=
2190              offsetof(struct trap_per_cpu, dev_mondo_pa)) ||
2191             (TRAP_PER_CPU_RESUM_MONDO_PA !=
2192              offsetof(struct trap_per_cpu, resum_mondo_pa)) ||
2193             (TRAP_PER_CPU_NONRESUM_MONDO_PA !=
2194              offsetof(struct trap_per_cpu, nonresum_mondo_pa)) ||
2195             (TRAP_PER_CPU_FAULT_INFO !=
2196              offsetof(struct trap_per_cpu, fault_info)))
2197                 trap_per_cpu_offsets_are_bolixed_dave();
2198
2199         /* Attach to the address space of init_task.  On SMP we
2200          * do this in smp.c:smp_callin for other cpus.
2201          */
2202         atomic_inc(&init_mm.mm_count);
2203         current->active_mm = &init_mm;
2204 }