1 /* arch/sparc64/kernel/traps.c
3 * Copyright (C) 1995,1997,2008 David S. Miller (davem@davemloft.net)
4 * Copyright (C) 1997,1999,2000 Jakub Jelinek (jakub@redhat.com)
8 * I like traps on v9, :))))
11 #include <linux/module.h>
12 #include <linux/sched.h>
13 #include <linux/linkage.h>
14 #include <linux/kernel.h>
15 #include <linux/signal.h>
16 #include <linux/smp.h>
18 #include <linux/init.h>
19 #include <linux/kdebug.h>
22 #include <asm/delay.h>
23 #include <asm/system.h>
24 #include <asm/ptrace.h>
25 #include <asm/oplib.h>
27 #include <asm/pgtable.h>
28 #include <asm/unistd.h>
29 #include <asm/uaccess.h>
30 #include <asm/fpumacro.h>
33 #include <asm/estate.h>
34 #include <asm/chafsr.h>
35 #include <asm/sfafsr.h>
36 #include <asm/psrcompat.h>
37 #include <asm/processor.h>
38 #include <asm/timer.h>
45 /* When an irrecoverable trap occurs at tl > 0, the trap entry
46 * code logs the trap state registers at every level in the trap
47 * stack. It is found at (pt_regs + sizeof(pt_regs)) and the layout
60 static void dump_tl1_traplog(struct tl1_traplog *p)
64 printk(KERN_EMERG "TRAPLOG: Error at trap level 0x%lx, "
65 "dumping track stack.\n", p->tl);
67 limit = (tlb_type == hypervisor) ? 2 : 4;
68 for (i = 0; i < limit; i++) {
70 "TRAPLOG: Trap level %d TSTATE[%016lx] TPC[%016lx] "
71 "TNPC[%016lx] TT[%lx]\n",
73 p->trapstack[i].tstate, p->trapstack[i].tpc,
74 p->trapstack[i].tnpc, p->trapstack[i].tt);
75 printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
79 void bad_trap(struct pt_regs *regs, long lvl)
84 if (notify_die(DIE_TRAP, "bad trap", regs,
85 0, lvl, SIGTRAP) == NOTIFY_STOP)
89 sprintf(buffer, "Bad hw trap %lx at tl0\n", lvl);
90 die_if_kernel(buffer, regs);
94 if (regs->tstate & TSTATE_PRIV) {
95 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
96 die_if_kernel(buffer, regs);
98 if (test_thread_flag(TIF_32BIT)) {
99 regs->tpc &= 0xffffffff;
100 regs->tnpc &= 0xffffffff;
102 info.si_signo = SIGILL;
104 info.si_code = ILL_ILLTRP;
105 info.si_addr = (void __user *)regs->tpc;
106 info.si_trapno = lvl;
107 force_sig_info(SIGILL, &info, current);
110 void bad_trap_tl1(struct pt_regs *regs, long lvl)
114 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
115 0, lvl, SIGTRAP) == NOTIFY_STOP)
118 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
120 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
121 die_if_kernel (buffer, regs);
124 #ifdef CONFIG_DEBUG_BUGVERBOSE
125 void do_BUG(const char *file, int line)
128 printk("kernel BUG at %s:%d!\n", file, line);
132 void spitfire_insn_access_exception(struct pt_regs *regs, unsigned long sfsr, unsigned long sfar)
136 if (notify_die(DIE_TRAP, "instruction access exception", regs,
137 0, 0x8, SIGTRAP) == NOTIFY_STOP)
140 if (regs->tstate & TSTATE_PRIV) {
141 printk("spitfire_insn_access_exception: SFSR[%016lx] "
142 "SFAR[%016lx], going.\n", sfsr, sfar);
143 die_if_kernel("Iax", regs);
145 if (test_thread_flag(TIF_32BIT)) {
146 regs->tpc &= 0xffffffff;
147 regs->tnpc &= 0xffffffff;
149 info.si_signo = SIGSEGV;
151 info.si_code = SEGV_MAPERR;
152 info.si_addr = (void __user *)regs->tpc;
154 force_sig_info(SIGSEGV, &info, current);
157 void spitfire_insn_access_exception_tl1(struct pt_regs *regs, unsigned long sfsr, unsigned long sfar)
159 if (notify_die(DIE_TRAP_TL1, "instruction access exception tl1", regs,
160 0, 0x8, SIGTRAP) == NOTIFY_STOP)
163 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
164 spitfire_insn_access_exception(regs, sfsr, sfar);
167 void sun4v_insn_access_exception(struct pt_regs *regs, unsigned long addr, unsigned long type_ctx)
169 unsigned short type = (type_ctx >> 16);
170 unsigned short ctx = (type_ctx & 0xffff);
173 if (notify_die(DIE_TRAP, "instruction access exception", regs,
174 0, 0x8, SIGTRAP) == NOTIFY_STOP)
177 if (regs->tstate & TSTATE_PRIV) {
178 printk("sun4v_insn_access_exception: ADDR[%016lx] "
179 "CTX[%04x] TYPE[%04x], going.\n",
181 die_if_kernel("Iax", regs);
184 if (test_thread_flag(TIF_32BIT)) {
185 regs->tpc &= 0xffffffff;
186 regs->tnpc &= 0xffffffff;
188 info.si_signo = SIGSEGV;
190 info.si_code = SEGV_MAPERR;
191 info.si_addr = (void __user *) addr;
193 force_sig_info(SIGSEGV, &info, current);
196 void sun4v_insn_access_exception_tl1(struct pt_regs *regs, unsigned long addr, unsigned long type_ctx)
198 if (notify_die(DIE_TRAP_TL1, "instruction access exception tl1", regs,
199 0, 0x8, SIGTRAP) == NOTIFY_STOP)
202 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
203 sun4v_insn_access_exception(regs, addr, type_ctx);
206 void spitfire_data_access_exception(struct pt_regs *regs, unsigned long sfsr, unsigned long sfar)
210 if (notify_die(DIE_TRAP, "data access exception", regs,
211 0, 0x30, SIGTRAP) == NOTIFY_STOP)
214 if (regs->tstate & TSTATE_PRIV) {
215 /* Test if this comes from uaccess places. */
216 const struct exception_table_entry *entry;
218 entry = search_exception_tables(regs->tpc);
220 /* Ouch, somebody is trying VM hole tricks on us... */
221 #ifdef DEBUG_EXCEPTIONS
222 printk("Exception: PC<%016lx> faddr<UNKNOWN>\n", regs->tpc);
223 printk("EX_TABLE: insn<%016lx> fixup<%016lx>\n",
224 regs->tpc, entry->fixup);
226 regs->tpc = entry->fixup;
227 regs->tnpc = regs->tpc + 4;
231 printk("spitfire_data_access_exception: SFSR[%016lx] "
232 "SFAR[%016lx], going.\n", sfsr, sfar);
233 die_if_kernel("Dax", regs);
236 info.si_signo = SIGSEGV;
238 info.si_code = SEGV_MAPERR;
239 info.si_addr = (void __user *)sfar;
241 force_sig_info(SIGSEGV, &info, current);
244 void spitfire_data_access_exception_tl1(struct pt_regs *regs, unsigned long sfsr, unsigned long sfar)
246 if (notify_die(DIE_TRAP_TL1, "data access exception tl1", regs,
247 0, 0x30, SIGTRAP) == NOTIFY_STOP)
250 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
251 spitfire_data_access_exception(regs, sfsr, sfar);
254 void sun4v_data_access_exception(struct pt_regs *regs, unsigned long addr, unsigned long type_ctx)
256 unsigned short type = (type_ctx >> 16);
257 unsigned short ctx = (type_ctx & 0xffff);
260 if (notify_die(DIE_TRAP, "data access exception", regs,
261 0, 0x8, SIGTRAP) == NOTIFY_STOP)
264 if (regs->tstate & TSTATE_PRIV) {
265 printk("sun4v_data_access_exception: ADDR[%016lx] "
266 "CTX[%04x] TYPE[%04x], going.\n",
268 die_if_kernel("Dax", regs);
271 if (test_thread_flag(TIF_32BIT)) {
272 regs->tpc &= 0xffffffff;
273 regs->tnpc &= 0xffffffff;
275 info.si_signo = SIGSEGV;
277 info.si_code = SEGV_MAPERR;
278 info.si_addr = (void __user *) addr;
280 force_sig_info(SIGSEGV, &info, current);
283 void sun4v_data_access_exception_tl1(struct pt_regs *regs, unsigned long addr, unsigned long type_ctx)
285 if (notify_die(DIE_TRAP_TL1, "data access exception tl1", regs,
286 0, 0x8, SIGTRAP) == NOTIFY_STOP)
289 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
290 sun4v_data_access_exception(regs, addr, type_ctx);
294 /* This is really pathetic... */
295 extern volatile int pci_poke_in_progress;
296 extern volatile int pci_poke_cpu;
297 extern volatile int pci_poke_faulted;
300 /* When access exceptions happen, we must do this. */
301 static void spitfire_clean_and_reenable_l1_caches(void)
305 if (tlb_type != spitfire)
309 for (va = 0; va < (PAGE_SIZE << 1); va += 32) {
310 spitfire_put_icache_tag(va, 0x0);
311 spitfire_put_dcache_tag(va, 0x0);
314 /* Re-enable in LSU. */
315 __asm__ __volatile__("flush %%g6\n\t"
317 "stxa %0, [%%g0] %1\n\t"
320 : "r" (LSU_CONTROL_IC | LSU_CONTROL_DC |
321 LSU_CONTROL_IM | LSU_CONTROL_DM),
322 "i" (ASI_LSU_CONTROL)
326 static void spitfire_enable_estate_errors(void)
328 __asm__ __volatile__("stxa %0, [%%g0] %1\n\t"
331 : "r" (ESTATE_ERR_ALL),
332 "i" (ASI_ESTATE_ERROR_EN));
335 static char ecc_syndrome_table[] = {
336 0x4c, 0x40, 0x41, 0x48, 0x42, 0x48, 0x48, 0x49,
337 0x43, 0x48, 0x48, 0x49, 0x48, 0x49, 0x49, 0x4a,
338 0x44, 0x48, 0x48, 0x20, 0x48, 0x39, 0x4b, 0x48,
339 0x48, 0x25, 0x31, 0x48, 0x28, 0x48, 0x48, 0x2c,
340 0x45, 0x48, 0x48, 0x21, 0x48, 0x3d, 0x04, 0x48,
341 0x48, 0x4b, 0x35, 0x48, 0x2d, 0x48, 0x48, 0x29,
342 0x48, 0x00, 0x01, 0x48, 0x0a, 0x48, 0x48, 0x4b,
343 0x0f, 0x48, 0x48, 0x4b, 0x48, 0x49, 0x49, 0x48,
344 0x46, 0x48, 0x48, 0x2a, 0x48, 0x3b, 0x27, 0x48,
345 0x48, 0x4b, 0x33, 0x48, 0x22, 0x48, 0x48, 0x2e,
346 0x48, 0x19, 0x1d, 0x48, 0x1b, 0x4a, 0x48, 0x4b,
347 0x1f, 0x48, 0x4a, 0x4b, 0x48, 0x4b, 0x4b, 0x48,
348 0x48, 0x4b, 0x24, 0x48, 0x07, 0x48, 0x48, 0x36,
349 0x4b, 0x48, 0x48, 0x3e, 0x48, 0x30, 0x38, 0x48,
350 0x49, 0x48, 0x48, 0x4b, 0x48, 0x4b, 0x16, 0x48,
351 0x48, 0x12, 0x4b, 0x48, 0x49, 0x48, 0x48, 0x4b,
352 0x47, 0x48, 0x48, 0x2f, 0x48, 0x3f, 0x4b, 0x48,
353 0x48, 0x06, 0x37, 0x48, 0x23, 0x48, 0x48, 0x2b,
354 0x48, 0x05, 0x4b, 0x48, 0x4b, 0x48, 0x48, 0x32,
355 0x26, 0x48, 0x48, 0x3a, 0x48, 0x34, 0x3c, 0x48,
356 0x48, 0x11, 0x15, 0x48, 0x13, 0x4a, 0x48, 0x4b,
357 0x17, 0x48, 0x4a, 0x4b, 0x48, 0x4b, 0x4b, 0x48,
358 0x49, 0x48, 0x48, 0x4b, 0x48, 0x4b, 0x1e, 0x48,
359 0x48, 0x1a, 0x4b, 0x48, 0x49, 0x48, 0x48, 0x4b,
360 0x48, 0x08, 0x0d, 0x48, 0x02, 0x48, 0x48, 0x49,
361 0x03, 0x48, 0x48, 0x49, 0x48, 0x4b, 0x4b, 0x48,
362 0x49, 0x48, 0x48, 0x49, 0x48, 0x4b, 0x10, 0x48,
363 0x48, 0x14, 0x4b, 0x48, 0x4b, 0x48, 0x48, 0x4b,
364 0x49, 0x48, 0x48, 0x49, 0x48, 0x4b, 0x18, 0x48,
365 0x48, 0x1c, 0x4b, 0x48, 0x4b, 0x48, 0x48, 0x4b,
366 0x4a, 0x0c, 0x09, 0x48, 0x0e, 0x48, 0x48, 0x4b,
367 0x0b, 0x48, 0x48, 0x4b, 0x48, 0x4b, 0x4b, 0x4a
370 static char *syndrome_unknown = "<Unknown>";
372 static void spitfire_log_udb_syndrome(unsigned long afar, unsigned long udbh, unsigned long udbl, unsigned long bit)
374 unsigned short scode;
375 char memmod_str[64], *p;
378 scode = ecc_syndrome_table[udbl & 0xff];
379 if (prom_getunumber(scode, afar,
380 memmod_str, sizeof(memmod_str)) == -1)
381 p = syndrome_unknown;
384 printk(KERN_WARNING "CPU[%d]: UDBL Syndrome[%x] "
385 "Memory Module \"%s\"\n",
386 smp_processor_id(), scode, p);
390 scode = ecc_syndrome_table[udbh & 0xff];
391 if (prom_getunumber(scode, afar,
392 memmod_str, sizeof(memmod_str)) == -1)
393 p = syndrome_unknown;
396 printk(KERN_WARNING "CPU[%d]: UDBH Syndrome[%x] "
397 "Memory Module \"%s\"\n",
398 smp_processor_id(), scode, p);
403 static void spitfire_cee_log(unsigned long afsr, unsigned long afar, unsigned long udbh, unsigned long udbl, int tl1, struct pt_regs *regs)
406 printk(KERN_WARNING "CPU[%d]: Correctable ECC Error "
407 "AFSR[%lx] AFAR[%016lx] UDBL[%lx] UDBH[%lx] TL>1[%d]\n",
408 smp_processor_id(), afsr, afar, udbl, udbh, tl1);
410 spitfire_log_udb_syndrome(afar, udbh, udbl, UDBE_CE);
412 /* We always log it, even if someone is listening for this
415 notify_die(DIE_TRAP, "Correctable ECC Error", regs,
416 0, TRAP_TYPE_CEE, SIGTRAP);
418 /* The Correctable ECC Error trap does not disable I/D caches. So
419 * we only have to restore the ESTATE Error Enable register.
421 spitfire_enable_estate_errors();
424 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)
428 printk(KERN_WARNING "CPU[%d]: Uncorrectable Error AFSR[%lx] "
429 "AFAR[%lx] UDBL[%lx] UDBH[%ld] TT[%lx] TL>1[%d]\n",
430 smp_processor_id(), afsr, afar, udbl, udbh, tt, tl1);
432 /* XXX add more human friendly logging of the error status
433 * XXX as is implemented for cheetah
436 spitfire_log_udb_syndrome(afar, udbh, udbl, UDBE_UE);
438 /* We always log it, even if someone is listening for this
441 notify_die(DIE_TRAP, "Uncorrectable Error", regs,
444 if (regs->tstate & TSTATE_PRIV) {
446 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
447 die_if_kernel("UE", regs);
450 /* XXX need more intelligent processing here, such as is implemented
451 * XXX for cheetah errors, in fact if the E-cache still holds the
452 * XXX line with bad parity this will loop
455 spitfire_clean_and_reenable_l1_caches();
456 spitfire_enable_estate_errors();
458 if (test_thread_flag(TIF_32BIT)) {
459 regs->tpc &= 0xffffffff;
460 regs->tnpc &= 0xffffffff;
462 info.si_signo = SIGBUS;
464 info.si_code = BUS_OBJERR;
465 info.si_addr = (void *)0;
467 force_sig_info(SIGBUS, &info, current);
470 void spitfire_access_error(struct pt_regs *regs, unsigned long status_encoded, unsigned long afar)
472 unsigned long afsr, tt, udbh, udbl;
475 afsr = (status_encoded & SFSTAT_AFSR_MASK) >> SFSTAT_AFSR_SHIFT;
476 tt = (status_encoded & SFSTAT_TRAP_TYPE) >> SFSTAT_TRAP_TYPE_SHIFT;
477 tl1 = (status_encoded & SFSTAT_TL_GT_ONE) ? 1 : 0;
478 udbl = (status_encoded & SFSTAT_UDBL_MASK) >> SFSTAT_UDBL_SHIFT;
479 udbh = (status_encoded & SFSTAT_UDBH_MASK) >> SFSTAT_UDBH_SHIFT;
482 if (tt == TRAP_TYPE_DAE &&
483 pci_poke_in_progress && pci_poke_cpu == smp_processor_id()) {
484 spitfire_clean_and_reenable_l1_caches();
485 spitfire_enable_estate_errors();
487 pci_poke_faulted = 1;
488 regs->tnpc = regs->tpc + 4;
493 if (afsr & SFAFSR_UE)
494 spitfire_ue_log(afsr, afar, udbh, udbl, tt, tl1, regs);
496 if (tt == TRAP_TYPE_CEE) {
497 /* Handle the case where we took a CEE trap, but ACK'd
498 * only the UE state in the UDB error registers.
500 if (afsr & SFAFSR_UE) {
501 if (udbh & UDBE_CE) {
502 __asm__ __volatile__(
503 "stxa %0, [%1] %2\n\t"
506 : "r" (udbh & UDBE_CE),
507 "r" (0x0), "i" (ASI_UDB_ERROR_W));
509 if (udbl & UDBE_CE) {
510 __asm__ __volatile__(
511 "stxa %0, [%1] %2\n\t"
514 : "r" (udbl & UDBE_CE),
515 "r" (0x18), "i" (ASI_UDB_ERROR_W));
519 spitfire_cee_log(afsr, afar, udbh, udbl, tl1, regs);
523 int cheetah_pcache_forced_on;
525 void cheetah_enable_pcache(void)
529 printk("CHEETAH: Enabling P-Cache on cpu %d.\n",
532 __asm__ __volatile__("ldxa [%%g0] %1, %0"
534 : "i" (ASI_DCU_CONTROL_REG));
535 dcr |= (DCU_PE | DCU_HPE | DCU_SPE | DCU_SL);
536 __asm__ __volatile__("stxa %0, [%%g0] %1\n\t"
539 : "r" (dcr), "i" (ASI_DCU_CONTROL_REG));
542 /* Cheetah error trap handling. */
543 static unsigned long ecache_flush_physbase;
544 static unsigned long ecache_flush_linesize;
545 static unsigned long ecache_flush_size;
547 /* This table is ordered in priority of errors and matches the
548 * AFAR overwrite policy as well.
551 struct afsr_error_table {
556 static const char CHAFSR_PERR_msg[] =
557 "System interface protocol error";
558 static const char CHAFSR_IERR_msg[] =
559 "Internal processor error";
560 static const char CHAFSR_ISAP_msg[] =
561 "System request parity error on incoming addresss";
562 static const char CHAFSR_UCU_msg[] =
563 "Uncorrectable E-cache ECC error for ifetch/data";
564 static const char CHAFSR_UCC_msg[] =
565 "SW Correctable E-cache ECC error for ifetch/data";
566 static const char CHAFSR_UE_msg[] =
567 "Uncorrectable system bus data ECC error for read";
568 static const char CHAFSR_EDU_msg[] =
569 "Uncorrectable E-cache ECC error for stmerge/blkld";
570 static const char CHAFSR_EMU_msg[] =
571 "Uncorrectable system bus MTAG error";
572 static const char CHAFSR_WDU_msg[] =
573 "Uncorrectable E-cache ECC error for writeback";
574 static const char CHAFSR_CPU_msg[] =
575 "Uncorrectable ECC error for copyout";
576 static const char CHAFSR_CE_msg[] =
577 "HW corrected system bus data ECC error for read";
578 static const char CHAFSR_EDC_msg[] =
579 "HW corrected E-cache ECC error for stmerge/blkld";
580 static const char CHAFSR_EMC_msg[] =
581 "HW corrected system bus MTAG ECC error";
582 static const char CHAFSR_WDC_msg[] =
583 "HW corrected E-cache ECC error for writeback";
584 static const char CHAFSR_CPC_msg[] =
585 "HW corrected ECC error for copyout";
586 static const char CHAFSR_TO_msg[] =
587 "Unmapped error from system bus";
588 static const char CHAFSR_BERR_msg[] =
589 "Bus error response from system bus";
590 static const char CHAFSR_IVC_msg[] =
591 "HW corrected system bus data ECC error for ivec read";
592 static const char CHAFSR_IVU_msg[] =
593 "Uncorrectable system bus data ECC error for ivec read";
594 static struct afsr_error_table __cheetah_error_table[] = {
595 { CHAFSR_PERR, CHAFSR_PERR_msg },
596 { CHAFSR_IERR, CHAFSR_IERR_msg },
597 { CHAFSR_ISAP, CHAFSR_ISAP_msg },
598 { CHAFSR_UCU, CHAFSR_UCU_msg },
599 { CHAFSR_UCC, CHAFSR_UCC_msg },
600 { CHAFSR_UE, CHAFSR_UE_msg },
601 { CHAFSR_EDU, CHAFSR_EDU_msg },
602 { CHAFSR_EMU, CHAFSR_EMU_msg },
603 { CHAFSR_WDU, CHAFSR_WDU_msg },
604 { CHAFSR_CPU, CHAFSR_CPU_msg },
605 { CHAFSR_CE, CHAFSR_CE_msg },
606 { CHAFSR_EDC, CHAFSR_EDC_msg },
607 { CHAFSR_EMC, CHAFSR_EMC_msg },
608 { CHAFSR_WDC, CHAFSR_WDC_msg },
609 { CHAFSR_CPC, CHAFSR_CPC_msg },
610 { CHAFSR_TO, CHAFSR_TO_msg },
611 { CHAFSR_BERR, CHAFSR_BERR_msg },
612 /* These two do not update the AFAR. */
613 { CHAFSR_IVC, CHAFSR_IVC_msg },
614 { CHAFSR_IVU, CHAFSR_IVU_msg },
617 static const char CHPAFSR_DTO_msg[] =
618 "System bus unmapped error for prefetch/storequeue-read";
619 static const char CHPAFSR_DBERR_msg[] =
620 "System bus error for prefetch/storequeue-read";
621 static const char CHPAFSR_THCE_msg[] =
622 "Hardware corrected E-cache Tag ECC error";
623 static const char CHPAFSR_TSCE_msg[] =
624 "SW handled correctable E-cache Tag ECC error";
625 static const char CHPAFSR_TUE_msg[] =
626 "Uncorrectable E-cache Tag ECC error";
627 static const char CHPAFSR_DUE_msg[] =
628 "System bus uncorrectable data ECC error due to prefetch/store-fill";
629 static struct afsr_error_table __cheetah_plus_error_table[] = {
630 { CHAFSR_PERR, CHAFSR_PERR_msg },
631 { CHAFSR_IERR, CHAFSR_IERR_msg },
632 { CHAFSR_ISAP, CHAFSR_ISAP_msg },
633 { CHAFSR_UCU, CHAFSR_UCU_msg },
634 { CHAFSR_UCC, CHAFSR_UCC_msg },
635 { CHAFSR_UE, CHAFSR_UE_msg },
636 { CHAFSR_EDU, CHAFSR_EDU_msg },
637 { CHAFSR_EMU, CHAFSR_EMU_msg },
638 { CHAFSR_WDU, CHAFSR_WDU_msg },
639 { CHAFSR_CPU, CHAFSR_CPU_msg },
640 { CHAFSR_CE, CHAFSR_CE_msg },
641 { CHAFSR_EDC, CHAFSR_EDC_msg },
642 { CHAFSR_EMC, CHAFSR_EMC_msg },
643 { CHAFSR_WDC, CHAFSR_WDC_msg },
644 { CHAFSR_CPC, CHAFSR_CPC_msg },
645 { CHAFSR_TO, CHAFSR_TO_msg },
646 { CHAFSR_BERR, CHAFSR_BERR_msg },
647 { CHPAFSR_DTO, CHPAFSR_DTO_msg },
648 { CHPAFSR_DBERR, CHPAFSR_DBERR_msg },
649 { CHPAFSR_THCE, CHPAFSR_THCE_msg },
650 { CHPAFSR_TSCE, CHPAFSR_TSCE_msg },
651 { CHPAFSR_TUE, CHPAFSR_TUE_msg },
652 { CHPAFSR_DUE, CHPAFSR_DUE_msg },
653 /* These two do not update the AFAR. */
654 { CHAFSR_IVC, CHAFSR_IVC_msg },
655 { CHAFSR_IVU, CHAFSR_IVU_msg },
658 static const char JPAFSR_JETO_msg[] =
659 "System interface protocol error, hw timeout caused";
660 static const char JPAFSR_SCE_msg[] =
661 "Parity error on system snoop results";
662 static const char JPAFSR_JEIC_msg[] =
663 "System interface protocol error, illegal command detected";
664 static const char JPAFSR_JEIT_msg[] =
665 "System interface protocol error, illegal ADTYPE detected";
666 static const char JPAFSR_OM_msg[] =
667 "Out of range memory error has occurred";
668 static const char JPAFSR_ETP_msg[] =
669 "Parity error on L2 cache tag SRAM";
670 static const char JPAFSR_UMS_msg[] =
671 "Error due to unsupported store";
672 static const char JPAFSR_RUE_msg[] =
673 "Uncorrectable ECC error from remote cache/memory";
674 static const char JPAFSR_RCE_msg[] =
675 "Correctable ECC error from remote cache/memory";
676 static const char JPAFSR_BP_msg[] =
677 "JBUS parity error on returned read data";
678 static const char JPAFSR_WBP_msg[] =
679 "JBUS parity error on data for writeback or block store";
680 static const char JPAFSR_FRC_msg[] =
681 "Foreign read to DRAM incurring correctable ECC error";
682 static const char JPAFSR_FRU_msg[] =
683 "Foreign read to DRAM incurring uncorrectable ECC error";
684 static struct afsr_error_table __jalapeno_error_table[] = {
685 { JPAFSR_JETO, JPAFSR_JETO_msg },
686 { JPAFSR_SCE, JPAFSR_SCE_msg },
687 { JPAFSR_JEIC, JPAFSR_JEIC_msg },
688 { JPAFSR_JEIT, JPAFSR_JEIT_msg },
689 { CHAFSR_PERR, CHAFSR_PERR_msg },
690 { CHAFSR_IERR, CHAFSR_IERR_msg },
691 { CHAFSR_ISAP, CHAFSR_ISAP_msg },
692 { CHAFSR_UCU, CHAFSR_UCU_msg },
693 { CHAFSR_UCC, CHAFSR_UCC_msg },
694 { CHAFSR_UE, CHAFSR_UE_msg },
695 { CHAFSR_EDU, CHAFSR_EDU_msg },
696 { JPAFSR_OM, JPAFSR_OM_msg },
697 { CHAFSR_WDU, CHAFSR_WDU_msg },
698 { CHAFSR_CPU, CHAFSR_CPU_msg },
699 { CHAFSR_CE, CHAFSR_CE_msg },
700 { CHAFSR_EDC, CHAFSR_EDC_msg },
701 { JPAFSR_ETP, JPAFSR_ETP_msg },
702 { CHAFSR_WDC, CHAFSR_WDC_msg },
703 { CHAFSR_CPC, CHAFSR_CPC_msg },
704 { CHAFSR_TO, CHAFSR_TO_msg },
705 { CHAFSR_BERR, CHAFSR_BERR_msg },
706 { JPAFSR_UMS, JPAFSR_UMS_msg },
707 { JPAFSR_RUE, JPAFSR_RUE_msg },
708 { JPAFSR_RCE, JPAFSR_RCE_msg },
709 { JPAFSR_BP, JPAFSR_BP_msg },
710 { JPAFSR_WBP, JPAFSR_WBP_msg },
711 { JPAFSR_FRC, JPAFSR_FRC_msg },
712 { JPAFSR_FRU, JPAFSR_FRU_msg },
713 /* These two do not update the AFAR. */
714 { CHAFSR_IVU, CHAFSR_IVU_msg },
717 static struct afsr_error_table *cheetah_error_table;
718 static unsigned long cheetah_afsr_errors;
720 struct cheetah_err_info *cheetah_error_log;
722 static inline struct cheetah_err_info *cheetah_get_error_log(unsigned long afsr)
724 struct cheetah_err_info *p;
725 int cpu = smp_processor_id();
727 if (!cheetah_error_log)
730 p = cheetah_error_log + (cpu * 2);
731 if ((afsr & CHAFSR_TL1) != 0UL)
737 extern unsigned int tl0_icpe[], tl1_icpe[];
738 extern unsigned int tl0_dcpe[], tl1_dcpe[];
739 extern unsigned int tl0_fecc[], tl1_fecc[];
740 extern unsigned int tl0_cee[], tl1_cee[];
741 extern unsigned int tl0_iae[], tl1_iae[];
742 extern unsigned int tl0_dae[], tl1_dae[];
743 extern unsigned int cheetah_plus_icpe_trap_vector[], cheetah_plus_icpe_trap_vector_tl1[];
744 extern unsigned int cheetah_plus_dcpe_trap_vector[], cheetah_plus_dcpe_trap_vector_tl1[];
745 extern unsigned int cheetah_fecc_trap_vector[], cheetah_fecc_trap_vector_tl1[];
746 extern unsigned int cheetah_cee_trap_vector[], cheetah_cee_trap_vector_tl1[];
747 extern unsigned int cheetah_deferred_trap_vector[], cheetah_deferred_trap_vector_tl1[];
749 void __init cheetah_ecache_flush_init(void)
751 unsigned long largest_size, smallest_linesize, order, ver;
754 /* Scan all cpu device tree nodes, note two values:
755 * 1) largest E-cache size
756 * 2) smallest E-cache line size
759 smallest_linesize = ~0UL;
761 for (i = 0; i < NR_CPUS; i++) {
764 val = cpu_data(i).ecache_size;
768 if (val > largest_size)
771 val = cpu_data(i).ecache_line_size;
772 if (val < smallest_linesize)
773 smallest_linesize = val;
777 if (largest_size == 0UL || smallest_linesize == ~0UL) {
778 prom_printf("cheetah_ecache_flush_init: Cannot probe cpu E-cache "
783 ecache_flush_size = (2 * largest_size);
784 ecache_flush_linesize = smallest_linesize;
786 ecache_flush_physbase = find_ecache_flush_span(ecache_flush_size);
788 if (ecache_flush_physbase == ~0UL) {
789 prom_printf("cheetah_ecache_flush_init: Cannot find %d byte "
790 "contiguous physical memory.\n",
795 /* Now allocate error trap reporting scoreboard. */
796 sz = NR_CPUS * (2 * sizeof(struct cheetah_err_info));
797 for (order = 0; order < MAX_ORDER; order++) {
798 if ((PAGE_SIZE << order) >= sz)
801 cheetah_error_log = (struct cheetah_err_info *)
802 __get_free_pages(GFP_KERNEL, order);
803 if (!cheetah_error_log) {
804 prom_printf("cheetah_ecache_flush_init: Failed to allocate "
805 "error logging scoreboard (%d bytes).\n", sz);
808 memset(cheetah_error_log, 0, PAGE_SIZE << order);
810 /* Mark all AFSRs as invalid so that the trap handler will
811 * log new new information there.
813 for (i = 0; i < 2 * NR_CPUS; i++)
814 cheetah_error_log[i].afsr = CHAFSR_INVALID;
816 __asm__ ("rdpr %%ver, %0" : "=r" (ver));
817 if ((ver >> 32) == __JALAPENO_ID ||
818 (ver >> 32) == __SERRANO_ID) {
819 cheetah_error_table = &__jalapeno_error_table[0];
820 cheetah_afsr_errors = JPAFSR_ERRORS;
821 } else if ((ver >> 32) == 0x003e0015) {
822 cheetah_error_table = &__cheetah_plus_error_table[0];
823 cheetah_afsr_errors = CHPAFSR_ERRORS;
825 cheetah_error_table = &__cheetah_error_table[0];
826 cheetah_afsr_errors = CHAFSR_ERRORS;
829 /* Now patch trap tables. */
830 memcpy(tl0_fecc, cheetah_fecc_trap_vector, (8 * 4));
831 memcpy(tl1_fecc, cheetah_fecc_trap_vector_tl1, (8 * 4));
832 memcpy(tl0_cee, cheetah_cee_trap_vector, (8 * 4));
833 memcpy(tl1_cee, cheetah_cee_trap_vector_tl1, (8 * 4));
834 memcpy(tl0_iae, cheetah_deferred_trap_vector, (8 * 4));
835 memcpy(tl1_iae, cheetah_deferred_trap_vector_tl1, (8 * 4));
836 memcpy(tl0_dae, cheetah_deferred_trap_vector, (8 * 4));
837 memcpy(tl1_dae, cheetah_deferred_trap_vector_tl1, (8 * 4));
838 if (tlb_type == cheetah_plus) {
839 memcpy(tl0_dcpe, cheetah_plus_dcpe_trap_vector, (8 * 4));
840 memcpy(tl1_dcpe, cheetah_plus_dcpe_trap_vector_tl1, (8 * 4));
841 memcpy(tl0_icpe, cheetah_plus_icpe_trap_vector, (8 * 4));
842 memcpy(tl1_icpe, cheetah_plus_icpe_trap_vector_tl1, (8 * 4));
847 static void cheetah_flush_ecache(void)
849 unsigned long flush_base = ecache_flush_physbase;
850 unsigned long flush_linesize = ecache_flush_linesize;
851 unsigned long flush_size = ecache_flush_size;
853 __asm__ __volatile__("1: subcc %0, %4, %0\n\t"
854 " bne,pt %%xcc, 1b\n\t"
855 " ldxa [%2 + %0] %3, %%g0\n\t"
857 : "0" (flush_size), "r" (flush_base),
858 "i" (ASI_PHYS_USE_EC), "r" (flush_linesize));
861 static void cheetah_flush_ecache_line(unsigned long physaddr)
865 physaddr &= ~(8UL - 1UL);
866 physaddr = (ecache_flush_physbase +
867 (physaddr & ((ecache_flush_size>>1UL) - 1UL)));
868 alias = physaddr + (ecache_flush_size >> 1UL);
869 __asm__ __volatile__("ldxa [%0] %2, %%g0\n\t"
870 "ldxa [%1] %2, %%g0\n\t"
873 : "r" (physaddr), "r" (alias),
874 "i" (ASI_PHYS_USE_EC));
877 /* Unfortunately, the diagnostic access to the I-cache tags we need to
878 * use to clear the thing interferes with I-cache coherency transactions.
880 * So we must only flush the I-cache when it is disabled.
882 static void __cheetah_flush_icache(void)
884 unsigned int icache_size, icache_line_size;
887 icache_size = local_cpu_data().icache_size;
888 icache_line_size = local_cpu_data().icache_line_size;
890 /* Clear the valid bits in all the tags. */
891 for (addr = 0; addr < icache_size; addr += icache_line_size) {
892 __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
895 : "r" (addr | (2 << 3)),
900 static void cheetah_flush_icache(void)
902 unsigned long dcu_save;
904 /* Save current DCU, disable I-cache. */
905 __asm__ __volatile__("ldxa [%%g0] %1, %0\n\t"
906 "or %0, %2, %%g1\n\t"
907 "stxa %%g1, [%%g0] %1\n\t"
910 : "i" (ASI_DCU_CONTROL_REG), "i" (DCU_IC)
913 __cheetah_flush_icache();
915 /* Restore DCU register */
916 __asm__ __volatile__("stxa %0, [%%g0] %1\n\t"
919 : "r" (dcu_save), "i" (ASI_DCU_CONTROL_REG));
922 static void cheetah_flush_dcache(void)
924 unsigned int dcache_size, dcache_line_size;
927 dcache_size = local_cpu_data().dcache_size;
928 dcache_line_size = local_cpu_data().dcache_line_size;
930 for (addr = 0; addr < dcache_size; addr += dcache_line_size) {
931 __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
934 : "r" (addr), "i" (ASI_DCACHE_TAG));
938 /* In order to make the even parity correct we must do two things.
939 * First, we clear DC_data_parity and set DC_utag to an appropriate value.
940 * Next, we clear out all 32-bytes of data for that line. Data of
941 * all-zero + tag parity value of zero == correct parity.
943 static void cheetah_plus_zap_dcache_parity(void)
945 unsigned int dcache_size, dcache_line_size;
948 dcache_size = local_cpu_data().dcache_size;
949 dcache_line_size = local_cpu_data().dcache_line_size;
951 for (addr = 0; addr < dcache_size; addr += dcache_line_size) {
952 unsigned long tag = (addr >> 14);
955 __asm__ __volatile__("membar #Sync\n\t"
956 "stxa %0, [%1] %2\n\t"
959 : "r" (tag), "r" (addr),
960 "i" (ASI_DCACHE_UTAG));
961 for (line = addr; line < addr + dcache_line_size; line += 8)
962 __asm__ __volatile__("membar #Sync\n\t"
963 "stxa %%g0, [%0] %1\n\t"
967 "i" (ASI_DCACHE_DATA));
971 /* Conversion tables used to frob Cheetah AFSR syndrome values into
972 * something palatable to the memory controller driver get_unumber
996 static unsigned char cheetah_ecc_syntab[] = {
997 /*00*/NONE, C0, C1, M2, C2, M2, M3, 47, C3, M2, M2, 53, M2, 41, 29, M,
998 /*01*/C4, M, M, 50, M2, 38, 25, M2, M2, 33, 24, M2, 11, M, M2, 16,
999 /*02*/C5, M, M, 46, M2, 37, 19, M2, M, 31, 32, M, 7, M2, M2, 10,
1000 /*03*/M2, 40, 13, M2, 59, M, M2, 66, M, M2, M2, 0, M2, 67, 71, M,
1001 /*04*/C6, M, M, 43, M, 36, 18, M, M2, 49, 15, M, 63, M2, M2, 6,
1002 /*05*/M2, 44, 28, M2, M, M2, M2, 52, 68, M2, M2, 62, M2, M3, M3, M4,
1003 /*06*/M2, 26, 106, M2, 64, M, M2, 2, 120, M, M2, M3, M, M3, M3, M4,
1004 /*07*/116, M2, M2, M3, M2, M3, M, M4, M2, 58, 54, M2, M, M4, M4, M3,
1005 /*08*/C7, M2, M, 42, M, 35, 17, M2, M, 45, 14, M2, 21, M2, M2, 5,
1006 /*09*/M, 27, M, M, 99, M, M, 3, 114, M2, M2, 20, M2, M3, M3, M,
1007 /*0a*/M2, 23, 113, M2, 112, M2, M, 51, 95, M, M2, M3, M2, M3, M3, M2,
1008 /*0b*/103, M, M2, M3, M2, M3, M3, M4, M2, 48, M, M, 73, M2, M, M3,
1009 /*0c*/M2, 22, 110, M2, 109, M2, M, 9, 108, M2, M, M3, M2, M3, M3, M,
1010 /*0d*/102, M2, M, M, M2, M3, M3, M, M2, M3, M3, M2, M, M4, M, M3,
1011 /*0e*/98, M, M2, M3, M2, M, M3, M4, M2, M3, M3, M4, M3, M, M, M,
1012 /*0f*/M2, M3, M3, M, M3, M, M, M, 56, M4, M, M3, M4, M, M, M,
1013 /*10*/C8, M, M2, 39, M, 34, 105, M2, M, 30, 104, M, 101, M, M, 4,
1014 /*11*/M, M, 100, M, 83, M, M2, 12, 87, M, M, 57, M2, M, M3, M,
1015 /*12*/M2, 97, 82, M2, 78, M2, M2, 1, 96, M, M, M, M, M, M3, M2,
1016 /*13*/94, M, M2, M3, M2, M, M3, M, M2, M, 79, M, 69, M, M4, M,
1017 /*14*/M2, 93, 92, M, 91, M, M2, 8, 90, M2, M2, M, M, M, M, M4,
1018 /*15*/89, M, M, M3, M2, M3, M3, M, M, M, M3, M2, M3, M2, M, M3,
1019 /*16*/86, M, M2, M3, M2, M, M3, M, M2, M, M3, M, M3, M, M, M3,
1020 /*17*/M, M, M3, M2, M3, M2, M4, M, 60, M, M2, M3, M4, M, M, M2,
1021 /*18*/M2, 88, 85, M2, 84, M, M2, 55, 81, M2, M2, M3, M2, M3, M3, M4,
1022 /*19*/77, M, M, M, M2, M3, M, M, M2, M3, M3, M4, M3, M2, M, M,
1023 /*1a*/74, M, M2, M3, M, M, M3, M, M, M, M3, M, M3, M, M4, M3,
1024 /*1b*/M2, 70, 107, M4, 65, M2, M2, M, 127, M, M, M, M2, M3, M3, M,
1025 /*1c*/80, M2, M2, 72, M, 119, 118, M, M2, 126, 76, M, 125, M, M4, M3,
1026 /*1d*/M2, 115, 124, M, 75, M, M, M3, 61, M, M4, M, M4, M, M, M,
1027 /*1e*/M, 123, 122, M4, 121, M4, M, M3, 117, M2, M2, M3, M4, M3, M, M,
1028 /*1f*/111, M, M, M, M4, M3, M3, M, M, M, M3, M, M3, M2, M, M
1030 static unsigned char cheetah_mtag_syntab[] = {
1041 /* Return the highest priority error conditon mentioned. */
1042 static inline unsigned long cheetah_get_hipri(unsigned long afsr)
1044 unsigned long tmp = 0;
1047 for (i = 0; cheetah_error_table[i].mask; i++) {
1048 if ((tmp = (afsr & cheetah_error_table[i].mask)) != 0UL)
1054 static const char *cheetah_get_string(unsigned long bit)
1058 for (i = 0; cheetah_error_table[i].mask; i++) {
1059 if ((bit & cheetah_error_table[i].mask) != 0UL)
1060 return cheetah_error_table[i].name;
1065 extern int chmc_getunumber(int, unsigned long, char *, int);
1067 static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *info,
1068 unsigned long afsr, unsigned long afar, int recoverable)
1070 unsigned long hipri;
1073 printk("%s" "ERROR(%d): Cheetah error trap taken afsr[%016lx] afar[%016lx] TL1(%d)\n",
1074 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1076 (afsr & CHAFSR_TL1) ? 1 : 0);
1077 printk("%s" "ERROR(%d): TPC[%lx] TNPC[%lx] O7[%lx] TSTATE[%lx]\n",
1078 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1079 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
1080 printk("%s" "ERROR(%d): ",
1081 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
1082 printk("TPC<%pS>\n", (void *) regs->tpc);
1083 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
1084 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1085 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
1086 (afsr & CHAFSR_E_SYNDROME) >> CHAFSR_E_SYNDROME_SHIFT,
1087 (afsr & CHAFSR_ME) ? ", Multiple Errors" : "",
1088 (afsr & CHAFSR_PRIV) ? ", Privileged" : "");
1089 hipri = cheetah_get_hipri(afsr);
1090 printk("%s" "ERROR(%d): Highest priority error (%016lx) \"%s\"\n",
1091 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1092 hipri, cheetah_get_string(hipri));
1094 /* Try to get unumber if relevant. */
1095 #define ESYND_ERRORS (CHAFSR_IVC | CHAFSR_IVU | \
1096 CHAFSR_CPC | CHAFSR_CPU | \
1097 CHAFSR_UE | CHAFSR_CE | \
1098 CHAFSR_EDC | CHAFSR_EDU | \
1099 CHAFSR_UCC | CHAFSR_UCU | \
1100 CHAFSR_WDU | CHAFSR_WDC)
1101 #define MSYND_ERRORS (CHAFSR_EMC | CHAFSR_EMU)
1102 if (afsr & ESYND_ERRORS) {
1106 syndrome = (afsr & CHAFSR_E_SYNDROME) >> CHAFSR_E_SYNDROME_SHIFT;
1107 syndrome = cheetah_ecc_syntab[syndrome];
1108 ret = chmc_getunumber(syndrome, afar, unum, sizeof(unum));
1110 printk("%s" "ERROR(%d): AFAR E-syndrome [%s]\n",
1111 (recoverable ? KERN_WARNING : KERN_CRIT),
1112 smp_processor_id(), unum);
1113 } else if (afsr & MSYND_ERRORS) {
1117 syndrome = (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT;
1118 syndrome = cheetah_mtag_syntab[syndrome];
1119 ret = chmc_getunumber(syndrome, afar, unum, sizeof(unum));
1121 printk("%s" "ERROR(%d): AFAR M-syndrome [%s]\n",
1122 (recoverable ? KERN_WARNING : KERN_CRIT),
1123 smp_processor_id(), unum);
1126 /* Now dump the cache snapshots. */
1127 printk("%s" "ERROR(%d): D-cache idx[%x] tag[%016lx] utag[%016lx] stag[%016lx]\n",
1128 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1129 (int) info->dcache_index,
1133 printk("%s" "ERROR(%d): D-cache data0[%016lx] data1[%016lx] data2[%016lx] data3[%016lx]\n",
1134 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1135 info->dcache_data[0],
1136 info->dcache_data[1],
1137 info->dcache_data[2],
1138 info->dcache_data[3]);
1139 printk("%s" "ERROR(%d): I-cache idx[%x] tag[%016lx] utag[%016lx] stag[%016lx] "
1140 "u[%016lx] l[%016lx]\n",
1141 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1142 (int) info->icache_index,
1147 info->icache_lower);
1148 printk("%s" "ERROR(%d): I-cache INSN0[%016lx] INSN1[%016lx] INSN2[%016lx] INSN3[%016lx]\n",
1149 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1150 info->icache_data[0],
1151 info->icache_data[1],
1152 info->icache_data[2],
1153 info->icache_data[3]);
1154 printk("%s" "ERROR(%d): I-cache INSN4[%016lx] INSN5[%016lx] INSN6[%016lx] INSN7[%016lx]\n",
1155 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1156 info->icache_data[4],
1157 info->icache_data[5],
1158 info->icache_data[6],
1159 info->icache_data[7]);
1160 printk("%s" "ERROR(%d): E-cache idx[%x] tag[%016lx]\n",
1161 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1162 (int) info->ecache_index, info->ecache_tag);
1163 printk("%s" "ERROR(%d): E-cache data0[%016lx] data1[%016lx] data2[%016lx] data3[%016lx]\n",
1164 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
1165 info->ecache_data[0],
1166 info->ecache_data[1],
1167 info->ecache_data[2],
1168 info->ecache_data[3]);
1170 afsr = (afsr & ~hipri) & cheetah_afsr_errors;
1171 while (afsr != 0UL) {
1172 unsigned long bit = cheetah_get_hipri(afsr);
1174 printk("%s" "ERROR: Multiple-error (%016lx) \"%s\"\n",
1175 (recoverable ? KERN_WARNING : KERN_CRIT),
1176 bit, cheetah_get_string(bit));
1182 printk(KERN_CRIT "ERROR: This condition is not recoverable.\n");
1185 static int cheetah_recheck_errors(struct cheetah_err_info *logp)
1187 unsigned long afsr, afar;
1190 __asm__ __volatile__("ldxa [%%g0] %1, %0\n\t"
1193 if ((afsr & cheetah_afsr_errors) != 0) {
1195 __asm__ __volatile__("ldxa [%%g0] %1, %0\n\t"
1203 __asm__ __volatile__("stxa %0, [%%g0] %1\n\t"
1205 : : "r" (afsr), "i" (ASI_AFSR));
1210 void cheetah_fecc_handler(struct pt_regs *regs, unsigned long afsr, unsigned long afar)
1212 struct cheetah_err_info local_snapshot, *p;
1216 cheetah_flush_ecache();
1218 p = cheetah_get_error_log(afsr);
1220 prom_printf("ERROR: Early Fast-ECC error afsr[%016lx] afar[%016lx]\n",
1222 prom_printf("ERROR: CPU(%d) TPC[%016lx] TNPC[%016lx] TSTATE[%016lx]\n",
1223 smp_processor_id(), regs->tpc, regs->tnpc, regs->tstate);
1227 /* Grab snapshot of logged error. */
1228 memcpy(&local_snapshot, p, sizeof(local_snapshot));
1230 /* If the current trap snapshot does not match what the
1231 * trap handler passed along into our args, big trouble.
1232 * In such a case, mark the local copy as invalid.
1234 * Else, it matches and we mark the afsr in the non-local
1235 * copy as invalid so we may log new error traps there.
1237 if (p->afsr != afsr || p->afar != afar)
1238 local_snapshot.afsr = CHAFSR_INVALID;
1240 p->afsr = CHAFSR_INVALID;
1242 cheetah_flush_icache();
1243 cheetah_flush_dcache();
1245 /* Re-enable I-cache/D-cache */
1246 __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
1247 "or %%g1, %1, %%g1\n\t"
1248 "stxa %%g1, [%%g0] %0\n\t"
1251 : "i" (ASI_DCU_CONTROL_REG),
1252 "i" (DCU_DC | DCU_IC)
1255 /* Re-enable error reporting */
1256 __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
1257 "or %%g1, %1, %%g1\n\t"
1258 "stxa %%g1, [%%g0] %0\n\t"
1261 : "i" (ASI_ESTATE_ERROR_EN),
1262 "i" (ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN)
1265 /* Decide if we can continue after handling this trap and
1266 * logging the error.
1269 if (afsr & (CHAFSR_PERR | CHAFSR_IERR | CHAFSR_ISAP))
1272 /* Re-check AFSR/AFAR. What we are looking for here is whether a new
1273 * error was logged while we had error reporting traps disabled.
1275 if (cheetah_recheck_errors(&local_snapshot)) {
1276 unsigned long new_afsr = local_snapshot.afsr;
1278 /* If we got a new asynchronous error, die... */
1279 if (new_afsr & (CHAFSR_EMU | CHAFSR_EDU |
1280 CHAFSR_WDU | CHAFSR_CPU |
1281 CHAFSR_IVU | CHAFSR_UE |
1282 CHAFSR_BERR | CHAFSR_TO))
1287 cheetah_log_errors(regs, &local_snapshot, afsr, afar, recoverable);
1290 panic("Irrecoverable Fast-ECC error trap.\n");
1292 /* Flush E-cache to kick the error trap handlers out. */
1293 cheetah_flush_ecache();
1296 /* Try to fix a correctable error by pushing the line out from
1297 * the E-cache. Recheck error reporting registers to see if the
1298 * problem is intermittent.
1300 static int cheetah_fix_ce(unsigned long physaddr)
1302 unsigned long orig_estate;
1303 unsigned long alias1, alias2;
1306 /* Make sure correctable error traps are disabled. */
1307 __asm__ __volatile__("ldxa [%%g0] %2, %0\n\t"
1308 "andn %0, %1, %%g1\n\t"
1309 "stxa %%g1, [%%g0] %2\n\t"
1311 : "=&r" (orig_estate)
1312 : "i" (ESTATE_ERROR_CEEN),
1313 "i" (ASI_ESTATE_ERROR_EN)
1316 /* We calculate alias addresses that will force the
1317 * cache line in question out of the E-cache. Then
1318 * we bring it back in with an atomic instruction so
1319 * that we get it in some modified/exclusive state,
1320 * then we displace it again to try and get proper ECC
1321 * pushed back into the system.
1323 physaddr &= ~(8UL - 1UL);
1324 alias1 = (ecache_flush_physbase +
1325 (physaddr & ((ecache_flush_size >> 1) - 1)));
1326 alias2 = alias1 + (ecache_flush_size >> 1);
1327 __asm__ __volatile__("ldxa [%0] %3, %%g0\n\t"
1328 "ldxa [%1] %3, %%g0\n\t"
1329 "casxa [%2] %3, %%g0, %%g0\n\t"
1330 "membar #StoreLoad | #StoreStore\n\t"
1331 "ldxa [%0] %3, %%g0\n\t"
1332 "ldxa [%1] %3, %%g0\n\t"
1335 : "r" (alias1), "r" (alias2),
1336 "r" (physaddr), "i" (ASI_PHYS_USE_EC));
1338 /* Did that trigger another error? */
1339 if (cheetah_recheck_errors(NULL)) {
1340 /* Try one more time. */
1341 __asm__ __volatile__("ldxa [%0] %1, %%g0\n\t"
1343 : : "r" (physaddr), "i" (ASI_PHYS_USE_EC));
1344 if (cheetah_recheck_errors(NULL))
1349 /* No new error, intermittent problem. */
1353 /* Restore error enables. */
1354 __asm__ __volatile__("stxa %0, [%%g0] %1\n\t"
1356 : : "r" (orig_estate), "i" (ASI_ESTATE_ERROR_EN));
1361 /* Return non-zero if PADDR is a valid physical memory address. */
1362 static int cheetah_check_main_memory(unsigned long paddr)
1364 unsigned long vaddr = PAGE_OFFSET + paddr;
1366 if (vaddr > (unsigned long) high_memory)
1369 return kern_addr_valid(vaddr);
1372 void cheetah_cee_handler(struct pt_regs *regs, unsigned long afsr, unsigned long afar)
1374 struct cheetah_err_info local_snapshot, *p;
1375 int recoverable, is_memory;
1377 p = cheetah_get_error_log(afsr);
1379 prom_printf("ERROR: Early CEE error afsr[%016lx] afar[%016lx]\n",
1381 prom_printf("ERROR: CPU(%d) TPC[%016lx] TNPC[%016lx] TSTATE[%016lx]\n",
1382 smp_processor_id(), regs->tpc, regs->tnpc, regs->tstate);
1386 /* Grab snapshot of logged error. */
1387 memcpy(&local_snapshot, p, sizeof(local_snapshot));
1389 /* If the current trap snapshot does not match what the
1390 * trap handler passed along into our args, big trouble.
1391 * In such a case, mark the local copy as invalid.
1393 * Else, it matches and we mark the afsr in the non-local
1394 * copy as invalid so we may log new error traps there.
1396 if (p->afsr != afsr || p->afar != afar)
1397 local_snapshot.afsr = CHAFSR_INVALID;
1399 p->afsr = CHAFSR_INVALID;
1401 is_memory = cheetah_check_main_memory(afar);
1403 if (is_memory && (afsr & CHAFSR_CE) != 0UL) {
1404 /* XXX Might want to log the results of this operation
1405 * XXX somewhere... -DaveM
1407 cheetah_fix_ce(afar);
1411 int flush_all, flush_line;
1413 flush_all = flush_line = 0;
1414 if ((afsr & CHAFSR_EDC) != 0UL) {
1415 if ((afsr & cheetah_afsr_errors) == CHAFSR_EDC)
1419 } else if ((afsr & CHAFSR_CPC) != 0UL) {
1420 if ((afsr & cheetah_afsr_errors) == CHAFSR_CPC)
1426 /* Trap handler only disabled I-cache, flush it. */
1427 cheetah_flush_icache();
1429 /* Re-enable I-cache */
1430 __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
1431 "or %%g1, %1, %%g1\n\t"
1432 "stxa %%g1, [%%g0] %0\n\t"
1435 : "i" (ASI_DCU_CONTROL_REG),
1440 cheetah_flush_ecache();
1441 else if (flush_line)
1442 cheetah_flush_ecache_line(afar);
1445 /* Re-enable error reporting */
1446 __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
1447 "or %%g1, %1, %%g1\n\t"
1448 "stxa %%g1, [%%g0] %0\n\t"
1451 : "i" (ASI_ESTATE_ERROR_EN),
1452 "i" (ESTATE_ERROR_CEEN)
1455 /* Decide if we can continue after handling this trap and
1456 * logging the error.
1459 if (afsr & (CHAFSR_PERR | CHAFSR_IERR | CHAFSR_ISAP))
1462 /* Re-check AFSR/AFAR */
1463 (void) cheetah_recheck_errors(&local_snapshot);
1466 cheetah_log_errors(regs, &local_snapshot, afsr, afar, recoverable);
1469 panic("Irrecoverable Correctable-ECC error trap.\n");
1472 void cheetah_deferred_handler(struct pt_regs *regs, unsigned long afsr, unsigned long afar)
1474 struct cheetah_err_info local_snapshot, *p;
1475 int recoverable, is_memory;
1478 /* Check for the special PCI poke sequence. */
1479 if (pci_poke_in_progress && pci_poke_cpu == smp_processor_id()) {
1480 cheetah_flush_icache();
1481 cheetah_flush_dcache();
1483 /* Re-enable I-cache/D-cache */
1484 __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
1485 "or %%g1, %1, %%g1\n\t"
1486 "stxa %%g1, [%%g0] %0\n\t"
1489 : "i" (ASI_DCU_CONTROL_REG),
1490 "i" (DCU_DC | DCU_IC)
1493 /* Re-enable error reporting */
1494 __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
1495 "or %%g1, %1, %%g1\n\t"
1496 "stxa %%g1, [%%g0] %0\n\t"
1499 : "i" (ASI_ESTATE_ERROR_EN),
1500 "i" (ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN)
1503 (void) cheetah_recheck_errors(NULL);
1505 pci_poke_faulted = 1;
1507 regs->tnpc = regs->tpc + 4;
1512 p = cheetah_get_error_log(afsr);
1514 prom_printf("ERROR: Early deferred error afsr[%016lx] afar[%016lx]\n",
1516 prom_printf("ERROR: CPU(%d) TPC[%016lx] TNPC[%016lx] TSTATE[%016lx]\n",
1517 smp_processor_id(), regs->tpc, regs->tnpc, regs->tstate);
1521 /* Grab snapshot of logged error. */
1522 memcpy(&local_snapshot, p, sizeof(local_snapshot));
1524 /* If the current trap snapshot does not match what the
1525 * trap handler passed along into our args, big trouble.
1526 * In such a case, mark the local copy as invalid.
1528 * Else, it matches and we mark the afsr in the non-local
1529 * copy as invalid so we may log new error traps there.
1531 if (p->afsr != afsr || p->afar != afar)
1532 local_snapshot.afsr = CHAFSR_INVALID;
1534 p->afsr = CHAFSR_INVALID;
1536 is_memory = cheetah_check_main_memory(afar);
1539 int flush_all, flush_line;
1541 flush_all = flush_line = 0;
1542 if ((afsr & CHAFSR_EDU) != 0UL) {
1543 if ((afsr & cheetah_afsr_errors) == CHAFSR_EDU)
1547 } else if ((afsr & CHAFSR_BERR) != 0UL) {
1548 if ((afsr & cheetah_afsr_errors) == CHAFSR_BERR)
1554 cheetah_flush_icache();
1555 cheetah_flush_dcache();
1557 /* Re-enable I/D caches */
1558 __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
1559 "or %%g1, %1, %%g1\n\t"
1560 "stxa %%g1, [%%g0] %0\n\t"
1563 : "i" (ASI_DCU_CONTROL_REG),
1564 "i" (DCU_IC | DCU_DC)
1568 cheetah_flush_ecache();
1569 else if (flush_line)
1570 cheetah_flush_ecache_line(afar);
1573 /* Re-enable error reporting */
1574 __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
1575 "or %%g1, %1, %%g1\n\t"
1576 "stxa %%g1, [%%g0] %0\n\t"
1579 : "i" (ASI_ESTATE_ERROR_EN),
1580 "i" (ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN)
1583 /* Decide if we can continue after handling this trap and
1584 * logging the error.
1587 if (afsr & (CHAFSR_PERR | CHAFSR_IERR | CHAFSR_ISAP))
1590 /* Re-check AFSR/AFAR. What we are looking for here is whether a new
1591 * error was logged while we had error reporting traps disabled.
1593 if (cheetah_recheck_errors(&local_snapshot)) {
1594 unsigned long new_afsr = local_snapshot.afsr;
1596 /* If we got a new asynchronous error, die... */
1597 if (new_afsr & (CHAFSR_EMU | CHAFSR_EDU |
1598 CHAFSR_WDU | CHAFSR_CPU |
1599 CHAFSR_IVU | CHAFSR_UE |
1600 CHAFSR_BERR | CHAFSR_TO))
1605 cheetah_log_errors(regs, &local_snapshot, afsr, afar, recoverable);
1607 /* "Recoverable" here means we try to yank the page from ever
1608 * being newly used again. This depends upon a few things:
1609 * 1) Must be main memory, and AFAR must be valid.
1610 * 2) If we trapped from user, OK.
1611 * 3) Else, if we trapped from kernel we must find exception
1612 * table entry (ie. we have to have been accessing user
1615 * If AFAR is not in main memory, or we trapped from kernel
1616 * and cannot find an exception table entry, it is unacceptable
1617 * to try and continue.
1619 if (recoverable && is_memory) {
1620 if ((regs->tstate & TSTATE_PRIV) == 0UL) {
1621 /* OK, usermode access. */
1624 const struct exception_table_entry *entry;
1626 entry = search_exception_tables(regs->tpc);
1628 /* OK, kernel access to userspace. */
1632 /* BAD, privileged state is corrupted. */
1637 if (pfn_valid(afar >> PAGE_SHIFT))
1638 get_page(pfn_to_page(afar >> PAGE_SHIFT));
1642 /* Only perform fixup if we still have a
1643 * recoverable condition.
1646 regs->tpc = entry->fixup;
1647 regs->tnpc = regs->tpc + 4;
1656 panic("Irrecoverable deferred error trap.\n");
1659 /* Handle a D/I cache parity error trap. TYPE is encoded as:
1661 * Bit0: 0=dcache,1=icache
1662 * Bit1: 0=recoverable,1=unrecoverable
1664 * The hardware has disabled both the I-cache and D-cache in
1665 * the %dcr register.
1667 void cheetah_plus_parity_error(int type, struct pt_regs *regs)
1670 __cheetah_flush_icache();
1672 cheetah_plus_zap_dcache_parity();
1673 cheetah_flush_dcache();
1675 /* Re-enable I-cache/D-cache */
1676 __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
1677 "or %%g1, %1, %%g1\n\t"
1678 "stxa %%g1, [%%g0] %0\n\t"
1681 : "i" (ASI_DCU_CONTROL_REG),
1682 "i" (DCU_DC | DCU_IC)
1686 printk(KERN_EMERG "CPU[%d]: Cheetah+ %c-cache parity error at TPC[%016lx]\n",
1688 (type & 0x1) ? 'I' : 'D',
1690 printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
1691 panic("Irrecoverable Cheetah+ parity error.");
1694 printk(KERN_WARNING "CPU[%d]: Cheetah+ %c-cache parity error at TPC[%016lx]\n",
1696 (type & 0x1) ? 'I' : 'D',
1698 printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
1701 struct sun4v_error_entry {
1706 #define SUN4V_ERR_TYPE_UNDEFINED 0
1707 #define SUN4V_ERR_TYPE_UNCORRECTED_RES 1
1708 #define SUN4V_ERR_TYPE_PRECISE_NONRES 2
1709 #define SUN4V_ERR_TYPE_DEFERRED_NONRES 3
1710 #define SUN4V_ERR_TYPE_WARNING_RES 4
1713 #define SUN4V_ERR_ATTRS_PROCESSOR 0x00000001
1714 #define SUN4V_ERR_ATTRS_MEMORY 0x00000002
1715 #define SUN4V_ERR_ATTRS_PIO 0x00000004
1716 #define SUN4V_ERR_ATTRS_INT_REGISTERS 0x00000008
1717 #define SUN4V_ERR_ATTRS_FPU_REGISTERS 0x00000010
1718 #define SUN4V_ERR_ATTRS_USER_MODE 0x01000000
1719 #define SUN4V_ERR_ATTRS_PRIV_MODE 0x02000000
1720 #define SUN4V_ERR_ATTRS_RES_QUEUE_FULL 0x80000000
1728 static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
1729 static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
1731 static const char *sun4v_err_type_to_str(u32 type)
1734 case SUN4V_ERR_TYPE_UNDEFINED:
1736 case SUN4V_ERR_TYPE_UNCORRECTED_RES:
1737 return "uncorrected resumable";
1738 case SUN4V_ERR_TYPE_PRECISE_NONRES:
1739 return "precise nonresumable";
1740 case SUN4V_ERR_TYPE_DEFERRED_NONRES:
1741 return "deferred nonresumable";
1742 case SUN4V_ERR_TYPE_WARNING_RES:
1743 return "warning resumable";
1749 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent, int cpu, const char *pfx, atomic_t *ocnt)
1753 printk("%s: Reporting on cpu %d\n", pfx, cpu);
1754 printk("%s: err_handle[%lx] err_stick[%lx] err_type[%08x:%s]\n",
1756 ent->err_handle, ent->err_stick,
1758 sun4v_err_type_to_str(ent->err_type));
1759 printk("%s: err_attrs[%08x:%s %s %s %s %s %s %s %s]\n",
1762 ((ent->err_attrs & SUN4V_ERR_ATTRS_PROCESSOR) ?
1764 ((ent->err_attrs & SUN4V_ERR_ATTRS_MEMORY) ?
1766 ((ent->err_attrs & SUN4V_ERR_ATTRS_PIO) ?
1768 ((ent->err_attrs & SUN4V_ERR_ATTRS_INT_REGISTERS) ?
1769 "integer-regs" : ""),
1770 ((ent->err_attrs & SUN4V_ERR_ATTRS_FPU_REGISTERS) ?
1772 ((ent->err_attrs & SUN4V_ERR_ATTRS_USER_MODE) ?
1774 ((ent->err_attrs & SUN4V_ERR_ATTRS_PRIV_MODE) ?
1776 ((ent->err_attrs & SUN4V_ERR_ATTRS_RES_QUEUE_FULL) ?
1777 "queue-full" : ""));
1778 printk("%s: err_raddr[%016lx] err_size[%u] err_cpu[%u]\n",
1780 ent->err_raddr, ent->err_size, ent->err_cpu);
1784 if ((cnt = atomic_read(ocnt)) != 0) {
1785 atomic_set(ocnt, 0);
1787 printk("%s: Queue overflowed %d times.\n",
1792 /* We run with %pil set to 15 and PSTATE_IE enabled in %pstate.
1793 * Log the event and clear the first word of the entry.
1795 void sun4v_resum_error(struct pt_regs *regs, unsigned long offset)
1797 struct sun4v_error_entry *ent, local_copy;
1798 struct trap_per_cpu *tb;
1799 unsigned long paddr;
1804 tb = &trap_block[cpu];
1805 paddr = tb->resum_kernel_buf_pa + offset;
1808 memcpy(&local_copy, ent, sizeof(struct sun4v_error_entry));
1810 /* We have a local copy now, so release the entry. */
1811 ent->err_handle = 0;
1816 if (ent->err_type == SUN4V_ERR_TYPE_WARNING_RES) {
1817 /* If err_type is 0x4, it's a powerdown request. Do
1818 * not do the usual resumable error log because that
1819 * makes it look like some abnormal error.
1821 printk(KERN_INFO "Power down request...\n");
1822 kill_cad_pid(SIGINT, 1);
1826 sun4v_log_error(regs, &local_copy, cpu,
1827 KERN_ERR "RESUMABLE ERROR",
1828 &sun4v_resum_oflow_cnt);
1831 /* If we try to printk() we'll probably make matters worse, by trying
1832 * to retake locks this cpu already holds or causing more errors. So
1833 * just bump a counter, and we'll report these counter bumps above.
1835 void sun4v_resum_overflow(struct pt_regs *regs)
1837 atomic_inc(&sun4v_resum_oflow_cnt);
1840 /* We run with %pil set to 15 and PSTATE_IE enabled in %pstate.
1841 * Log the event, clear the first word of the entry, and die.
1843 void sun4v_nonresum_error(struct pt_regs *regs, unsigned long offset)
1845 struct sun4v_error_entry *ent, local_copy;
1846 struct trap_per_cpu *tb;
1847 unsigned long paddr;
1852 tb = &trap_block[cpu];
1853 paddr = tb->nonresum_kernel_buf_pa + offset;
1856 memcpy(&local_copy, ent, sizeof(struct sun4v_error_entry));
1858 /* We have a local copy now, so release the entry. */
1859 ent->err_handle = 0;
1865 /* Check for the special PCI poke sequence. */
1866 if (pci_poke_in_progress && pci_poke_cpu == cpu) {
1867 pci_poke_faulted = 1;
1869 regs->tnpc = regs->tpc + 4;
1874 sun4v_log_error(regs, &local_copy, cpu,
1875 KERN_EMERG "NON-RESUMABLE ERROR",
1876 &sun4v_nonresum_oflow_cnt);
1878 panic("Non-resumable error.");
1881 /* If we try to printk() we'll probably make matters worse, by trying
1882 * to retake locks this cpu already holds or causing more errors. So
1883 * just bump a counter, and we'll report these counter bumps above.
1885 void sun4v_nonresum_overflow(struct pt_regs *regs)
1887 /* XXX Actually even this can make not that much sense. Perhaps
1888 * XXX we should just pull the plug and panic directly from here?
1890 atomic_inc(&sun4v_nonresum_oflow_cnt);
1893 unsigned long sun4v_err_itlb_vaddr;
1894 unsigned long sun4v_err_itlb_ctx;
1895 unsigned long sun4v_err_itlb_pte;
1896 unsigned long sun4v_err_itlb_error;
1898 void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
1901 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
1903 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
1905 printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
1906 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
1907 printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
1908 (void *) regs->u_regs[UREG_I7]);
1909 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
1910 "pte[%lx] error[%lx]\n",
1911 sun4v_err_itlb_vaddr, sun4v_err_itlb_ctx,
1912 sun4v_err_itlb_pte, sun4v_err_itlb_error);
1917 unsigned long sun4v_err_dtlb_vaddr;
1918 unsigned long sun4v_err_dtlb_ctx;
1919 unsigned long sun4v_err_dtlb_pte;
1920 unsigned long sun4v_err_dtlb_error;
1922 void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
1925 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
1927 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
1929 printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
1930 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
1931 printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
1932 (void *) regs->u_regs[UREG_I7]);
1933 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
1934 "pte[%lx] error[%lx]\n",
1935 sun4v_err_dtlb_vaddr, sun4v_err_dtlb_ctx,
1936 sun4v_err_dtlb_pte, sun4v_err_dtlb_error);
1941 void hypervisor_tlbop_error(unsigned long err, unsigned long op)
1943 printk(KERN_CRIT "SUN4V: TLB hv call error %lu for op %lu\n",
1947 void hypervisor_tlbop_error_xcall(unsigned long err, unsigned long op)
1949 printk(KERN_CRIT "SUN4V: XCALL TLB hv call error %lu for op %lu\n",
1953 void do_fpe_common(struct pt_regs *regs)
1955 if (regs->tstate & TSTATE_PRIV) {
1956 regs->tpc = regs->tnpc;
1959 unsigned long fsr = current_thread_info()->xfsr[0];
1962 if (test_thread_flag(TIF_32BIT)) {
1963 regs->tpc &= 0xffffffff;
1964 regs->tnpc &= 0xffffffff;
1966 info.si_signo = SIGFPE;
1968 info.si_addr = (void __user *)regs->tpc;
1970 info.si_code = __SI_FAULT;
1971 if ((fsr & 0x1c000) == (1 << 14)) {
1973 info.si_code = FPE_FLTINV;
1974 else if (fsr & 0x08)
1975 info.si_code = FPE_FLTOVF;
1976 else if (fsr & 0x04)
1977 info.si_code = FPE_FLTUND;
1978 else if (fsr & 0x02)
1979 info.si_code = FPE_FLTDIV;
1980 else if (fsr & 0x01)
1981 info.si_code = FPE_FLTRES;
1983 force_sig_info(SIGFPE, &info, current);
1987 void do_fpieee(struct pt_regs *regs)
1989 if (notify_die(DIE_TRAP, "fpu exception ieee", regs,
1990 0, 0x24, SIGFPE) == NOTIFY_STOP)
1993 do_fpe_common(regs);
1996 extern int do_mathemu(struct pt_regs *, struct fpustate *);
1998 void do_fpother(struct pt_regs *regs)
2000 struct fpustate *f = FPUSTATE;
2003 if (notify_die(DIE_TRAP, "fpu exception other", regs,
2004 0, 0x25, SIGFPE) == NOTIFY_STOP)
2007 switch ((current_thread_info()->xfsr[0] & 0x1c000)) {
2008 case (2 << 14): /* unfinished_FPop */
2009 case (3 << 14): /* unimplemented_FPop */
2010 ret = do_mathemu(regs, f);
2015 do_fpe_common(regs);
2018 void do_tof(struct pt_regs *regs)
2022 if (notify_die(DIE_TRAP, "tagged arithmetic overflow", regs,
2023 0, 0x26, SIGEMT) == NOTIFY_STOP)
2026 if (regs->tstate & TSTATE_PRIV)
2027 die_if_kernel("Penguin overflow trap from kernel mode", regs);
2028 if (test_thread_flag(TIF_32BIT)) {
2029 regs->tpc &= 0xffffffff;
2030 regs->tnpc &= 0xffffffff;
2032 info.si_signo = SIGEMT;
2034 info.si_code = EMT_TAGOVF;
2035 info.si_addr = (void __user *)regs->tpc;
2037 force_sig_info(SIGEMT, &info, current);
2040 void do_div0(struct pt_regs *regs)
2044 if (notify_die(DIE_TRAP, "integer division by zero", regs,
2045 0, 0x28, SIGFPE) == NOTIFY_STOP)
2048 if (regs->tstate & TSTATE_PRIV)
2049 die_if_kernel("TL0: Kernel divide by zero.", regs);
2050 if (test_thread_flag(TIF_32BIT)) {
2051 regs->tpc &= 0xffffffff;
2052 regs->tnpc &= 0xffffffff;
2054 info.si_signo = SIGFPE;
2056 info.si_code = FPE_INTDIV;
2057 info.si_addr = (void __user *)regs->tpc;
2059 force_sig_info(SIGFPE, &info, current);
2062 static void instruction_dump(unsigned int *pc)
2066 if ((((unsigned long) pc) & 3))
2069 printk("Instruction DUMP:");
2070 for (i = -3; i < 6; i++)
2071 printk("%c%08x%c",i?' ':'<',pc[i],i?' ':'>');
2075 static void user_instruction_dump(unsigned int __user *pc)
2078 unsigned int buf[9];
2080 if ((((unsigned long) pc) & 3))
2083 if (copy_from_user(buf, pc - 3, sizeof(buf)))
2086 printk("Instruction DUMP:");
2087 for (i = 0; i < 9; i++)
2088 printk("%c%08x%c",i==3?' ':'<',buf[i],i==3?' ':'>');
2092 void show_stack(struct task_struct *tsk, unsigned long *_ksp)
2094 unsigned long fp, thread_base, ksp;
2095 struct thread_info *tp;
2098 ksp = (unsigned long) _ksp;
2101 tp = task_thread_info(tsk);
2104 asm("mov %%fp, %0" : "=r" (ksp));
2108 if (tp == current_thread_info())
2111 fp = ksp + STACK_BIAS;
2112 thread_base = (unsigned long) tp;
2114 printk("Call Trace:\n");
2116 struct sparc_stackf *sf;
2117 struct pt_regs *regs;
2120 if (!kstack_valid(tp, fp))
2122 sf = (struct sparc_stackf *) fp;
2123 regs = (struct pt_regs *) (sf + 1);
2125 if (kstack_is_trap_frame(tp, regs)) {
2126 if (!(regs->tstate & TSTATE_PRIV))
2129 fp = regs->u_regs[UREG_I6] + STACK_BIAS;
2131 pc = sf->callers_pc;
2132 fp = (unsigned long)sf->fp + STACK_BIAS;
2135 printk(" [%016lx] %pS\n", pc, (void *) pc);
2136 } while (++count < 16);
2139 void dump_stack(void)
2141 show_stack(current, NULL);
2144 EXPORT_SYMBOL(dump_stack);
2146 static inline int is_kernel_stack(struct task_struct *task,
2147 struct reg_window *rw)
2149 unsigned long rw_addr = (unsigned long) rw;
2150 unsigned long thread_base, thread_end;
2152 if (rw_addr < PAGE_OFFSET) {
2153 if (task != &init_task)
2157 thread_base = (unsigned long) task_stack_page(task);
2158 thread_end = thread_base + sizeof(union thread_union);
2159 if (rw_addr >= thread_base &&
2160 rw_addr < thread_end &&
2167 static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
2169 unsigned long fp = rw->ins[6];
2174 return (struct reg_window *) (fp + STACK_BIAS);
2177 void die_if_kernel(char *str, struct pt_regs *regs)
2179 static int die_counter;
2182 /* Amuse the user. */
2185 " \"@'/ .. \\`@\"\n"
2189 printk("%s(%d): %s [#%d]\n", current->comm, task_pid_nr(current), str, ++die_counter);
2190 notify_die(DIE_OOPS, str, regs, 0, 255, SIGSEGV);
2191 __asm__ __volatile__("flushw");
2193 add_taint(TAINT_DIE);
2194 if (regs->tstate & TSTATE_PRIV) {
2195 struct reg_window *rw = (struct reg_window *)
2196 (regs->u_regs[UREG_FP] + STACK_BIAS);
2198 /* Stop the back trace when we hit userland or we
2199 * find some badly aligned kernel stack.
2203 is_kernel_stack(current, rw)) {
2204 printk("Caller[%016lx]: %pS\n", rw->ins[7],
2205 (void *) rw->ins[7]);
2207 rw = kernel_stack_up(rw);
2209 instruction_dump ((unsigned int *) regs->tpc);
2211 if (test_thread_flag(TIF_32BIT)) {
2212 regs->tpc &= 0xffffffff;
2213 regs->tnpc &= 0xffffffff;
2215 user_instruction_dump ((unsigned int __user *) regs->tpc);
2217 if (regs->tstate & TSTATE_PRIV)
2222 #define VIS_OPCODE_MASK ((0x3 << 30) | (0x3f << 19))
2223 #define VIS_OPCODE_VAL ((0x2 << 30) | (0x36 << 19))
2225 extern int handle_popc(u32 insn, struct pt_regs *regs);
2226 extern int handle_ldf_stq(u32 insn, struct pt_regs *regs);
2227 extern int vis_emul(struct pt_regs *, unsigned int);
2229 void do_illegal_instruction(struct pt_regs *regs)
2231 unsigned long pc = regs->tpc;
2232 unsigned long tstate = regs->tstate;
2236 if (notify_die(DIE_TRAP, "illegal instruction", regs,
2237 0, 0x10, SIGILL) == NOTIFY_STOP)
2240 if (tstate & TSTATE_PRIV)
2241 die_if_kernel("Kernel illegal instruction", regs);
2242 if (test_thread_flag(TIF_32BIT))
2244 if (get_user(insn, (u32 __user *) pc) != -EFAULT) {
2245 if ((insn & 0xc1ffc000) == 0x81700000) /* POPC */ {
2246 if (handle_popc(insn, regs))
2248 } else if ((insn & 0xc1580000) == 0xc1100000) /* LDQ/STQ */ {
2249 if (handle_ldf_stq(insn, regs))
2251 } else if (tlb_type == hypervisor) {
2252 if ((insn & VIS_OPCODE_MASK) == VIS_OPCODE_VAL) {
2253 if (!vis_emul(regs, insn))
2256 struct fpustate *f = FPUSTATE;
2258 /* XXX maybe verify XFSR bits like
2259 * XXX do_fpother() does?
2261 if (do_mathemu(regs, f))
2266 info.si_signo = SIGILL;
2268 info.si_code = ILL_ILLOPC;
2269 info.si_addr = (void __user *)pc;
2271 force_sig_info(SIGILL, &info, current);
2274 extern void kernel_unaligned_trap(struct pt_regs *regs, unsigned int insn);
2276 void mem_address_unaligned(struct pt_regs *regs, unsigned long sfar, unsigned long sfsr)
2280 if (notify_die(DIE_TRAP, "memory address unaligned", regs,
2281 0, 0x34, SIGSEGV) == NOTIFY_STOP)
2284 if (regs->tstate & TSTATE_PRIV) {
2285 kernel_unaligned_trap(regs, *((unsigned int *)regs->tpc));
2288 info.si_signo = SIGBUS;
2290 info.si_code = BUS_ADRALN;
2291 info.si_addr = (void __user *)sfar;
2293 force_sig_info(SIGBUS, &info, current);
2296 void sun4v_do_mna(struct pt_regs *regs, unsigned long addr, unsigned long type_ctx)
2300 if (notify_die(DIE_TRAP, "memory address unaligned", regs,
2301 0, 0x34, SIGSEGV) == NOTIFY_STOP)
2304 if (regs->tstate & TSTATE_PRIV) {
2305 kernel_unaligned_trap(regs, *((unsigned int *)regs->tpc));
2308 info.si_signo = SIGBUS;
2310 info.si_code = BUS_ADRALN;
2311 info.si_addr = (void __user *) addr;
2313 force_sig_info(SIGBUS, &info, current);
2316 void do_privop(struct pt_regs *regs)
2320 if (notify_die(DIE_TRAP, "privileged operation", regs,
2321 0, 0x11, SIGILL) == NOTIFY_STOP)
2324 if (test_thread_flag(TIF_32BIT)) {
2325 regs->tpc &= 0xffffffff;
2326 regs->tnpc &= 0xffffffff;
2328 info.si_signo = SIGILL;
2330 info.si_code = ILL_PRVOPC;
2331 info.si_addr = (void __user *)regs->tpc;
2333 force_sig_info(SIGILL, &info, current);
2336 void do_privact(struct pt_regs *regs)
2341 /* Trap level 1 stuff or other traps we should never see... */
2342 void do_cee(struct pt_regs *regs)
2344 die_if_kernel("TL0: Cache Error Exception", regs);
2347 void do_cee_tl1(struct pt_regs *regs)
2349 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2350 die_if_kernel("TL1: Cache Error Exception", regs);
2353 void do_dae_tl1(struct pt_regs *regs)
2355 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2356 die_if_kernel("TL1: Data Access Exception", regs);
2359 void do_iae_tl1(struct pt_regs *regs)
2361 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2362 die_if_kernel("TL1: Instruction Access Exception", regs);
2365 void do_div0_tl1(struct pt_regs *regs)
2367 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2368 die_if_kernel("TL1: DIV0 Exception", regs);
2371 void do_fpdis_tl1(struct pt_regs *regs)
2373 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2374 die_if_kernel("TL1: FPU Disabled", regs);
2377 void do_fpieee_tl1(struct pt_regs *regs)
2379 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2380 die_if_kernel("TL1: FPU IEEE Exception", regs);
2383 void do_fpother_tl1(struct pt_regs *regs)
2385 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2386 die_if_kernel("TL1: FPU Other Exception", regs);
2389 void do_ill_tl1(struct pt_regs *regs)
2391 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2392 die_if_kernel("TL1: Illegal Instruction Exception", regs);
2395 void do_irq_tl1(struct pt_regs *regs)
2397 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2398 die_if_kernel("TL1: IRQ Exception", regs);
2401 void do_lddfmna_tl1(struct pt_regs *regs)
2403 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2404 die_if_kernel("TL1: LDDF Exception", regs);
2407 void do_stdfmna_tl1(struct pt_regs *regs)
2409 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2410 die_if_kernel("TL1: STDF Exception", regs);
2413 void do_paw(struct pt_regs *regs)
2415 die_if_kernel("TL0: Phys Watchpoint Exception", regs);
2418 void do_paw_tl1(struct pt_regs *regs)
2420 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2421 die_if_kernel("TL1: Phys Watchpoint Exception", regs);
2424 void do_vaw(struct pt_regs *regs)
2426 die_if_kernel("TL0: Virt Watchpoint Exception", regs);
2429 void do_vaw_tl1(struct pt_regs *regs)
2431 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2432 die_if_kernel("TL1: Virt Watchpoint Exception", regs);
2435 void do_tof_tl1(struct pt_regs *regs)
2437 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
2438 die_if_kernel("TL1: Tag Overflow Exception", regs);
2441 void do_getpsr(struct pt_regs *regs)
2443 regs->u_regs[UREG_I0] = tstate_to_psr(regs->tstate);
2444 regs->tpc = regs->tnpc;
2446 if (test_thread_flag(TIF_32BIT)) {
2447 regs->tpc &= 0xffffffff;
2448 regs->tnpc &= 0xffffffff;
2452 struct trap_per_cpu trap_block[NR_CPUS];
2454 /* This can get invoked before sched_init() so play it super safe
2455 * and use hard_smp_processor_id().
2457 void notrace init_cur_cpu_trap(struct thread_info *t)
2459 int cpu = hard_smp_processor_id();
2460 struct trap_per_cpu *p = &trap_block[cpu];
2466 extern void thread_info_offsets_are_bolixed_dave(void);
2467 extern void trap_per_cpu_offsets_are_bolixed_dave(void);
2468 extern void tsb_config_offsets_are_bolixed_dave(void);
2470 /* Only invoked on boot processor. */
2471 void __init trap_init(void)
2473 /* Compile time sanity check. */
2474 if (TI_TASK != offsetof(struct thread_info, task) ||
2475 TI_FLAGS != offsetof(struct thread_info, flags) ||
2476 TI_CPU != offsetof(struct thread_info, cpu) ||
2477 TI_FPSAVED != offsetof(struct thread_info, fpsaved) ||
2478 TI_KSP != offsetof(struct thread_info, ksp) ||
2479 TI_FAULT_ADDR != offsetof(struct thread_info, fault_address) ||
2480 TI_KREGS != offsetof(struct thread_info, kregs) ||
2481 TI_UTRAPS != offsetof(struct thread_info, utraps) ||
2482 TI_EXEC_DOMAIN != offsetof(struct thread_info, exec_domain) ||
2483 TI_REG_WINDOW != offsetof(struct thread_info, reg_window) ||
2484 TI_RWIN_SPTRS != offsetof(struct thread_info, rwbuf_stkptrs) ||
2485 TI_GSR != offsetof(struct thread_info, gsr) ||
2486 TI_XFSR != offsetof(struct thread_info, xfsr) ||
2487 TI_USER_CNTD0 != offsetof(struct thread_info, user_cntd0) ||
2488 TI_USER_CNTD1 != offsetof(struct thread_info, user_cntd1) ||
2489 TI_KERN_CNTD0 != offsetof(struct thread_info, kernel_cntd0) ||
2490 TI_KERN_CNTD1 != offsetof(struct thread_info, kernel_cntd1) ||
2491 TI_PCR != offsetof(struct thread_info, pcr_reg) ||
2492 TI_PRE_COUNT != offsetof(struct thread_info, preempt_count) ||
2493 TI_NEW_CHILD != offsetof(struct thread_info, new_child) ||
2494 TI_SYS_NOERROR != offsetof(struct thread_info, syscall_noerror) ||
2495 TI_RESTART_BLOCK != offsetof(struct thread_info, restart_block) ||
2496 TI_KUNA_REGS != offsetof(struct thread_info, kern_una_regs) ||
2497 TI_KUNA_INSN != offsetof(struct thread_info, kern_una_insn) ||
2498 TI_FPREGS != offsetof(struct thread_info, fpregs) ||
2499 (TI_FPREGS & (64 - 1)))
2500 thread_info_offsets_are_bolixed_dave();
2502 if (TRAP_PER_CPU_THREAD != offsetof(struct trap_per_cpu, thread) ||
2503 (TRAP_PER_CPU_PGD_PADDR !=
2504 offsetof(struct trap_per_cpu, pgd_paddr)) ||
2505 (TRAP_PER_CPU_CPU_MONDO_PA !=
2506 offsetof(struct trap_per_cpu, cpu_mondo_pa)) ||
2507 (TRAP_PER_CPU_DEV_MONDO_PA !=
2508 offsetof(struct trap_per_cpu, dev_mondo_pa)) ||
2509 (TRAP_PER_CPU_RESUM_MONDO_PA !=
2510 offsetof(struct trap_per_cpu, resum_mondo_pa)) ||
2511 (TRAP_PER_CPU_RESUM_KBUF_PA !=
2512 offsetof(struct trap_per_cpu, resum_kernel_buf_pa)) ||
2513 (TRAP_PER_CPU_NONRESUM_MONDO_PA !=
2514 offsetof(struct trap_per_cpu, nonresum_mondo_pa)) ||
2515 (TRAP_PER_CPU_NONRESUM_KBUF_PA !=
2516 offsetof(struct trap_per_cpu, nonresum_kernel_buf_pa)) ||
2517 (TRAP_PER_CPU_FAULT_INFO !=
2518 offsetof(struct trap_per_cpu, fault_info)) ||
2519 (TRAP_PER_CPU_CPU_MONDO_BLOCK_PA !=
2520 offsetof(struct trap_per_cpu, cpu_mondo_block_pa)) ||
2521 (TRAP_PER_CPU_CPU_LIST_PA !=
2522 offsetof(struct trap_per_cpu, cpu_list_pa)) ||
2523 (TRAP_PER_CPU_TSB_HUGE !=
2524 offsetof(struct trap_per_cpu, tsb_huge)) ||
2525 (TRAP_PER_CPU_TSB_HUGE_TEMP !=
2526 offsetof(struct trap_per_cpu, tsb_huge_temp)) ||
2527 (TRAP_PER_CPU_IRQ_WORKLIST_PA !=
2528 offsetof(struct trap_per_cpu, irq_worklist_pa)) ||
2529 (TRAP_PER_CPU_CPU_MONDO_QMASK !=
2530 offsetof(struct trap_per_cpu, cpu_mondo_qmask)) ||
2531 (TRAP_PER_CPU_DEV_MONDO_QMASK !=
2532 offsetof(struct trap_per_cpu, dev_mondo_qmask)) ||
2533 (TRAP_PER_CPU_RESUM_QMASK !=
2534 offsetof(struct trap_per_cpu, resum_qmask)) ||
2535 (TRAP_PER_CPU_NONRESUM_QMASK !=
2536 offsetof(struct trap_per_cpu, nonresum_qmask)))
2537 trap_per_cpu_offsets_are_bolixed_dave();
2539 if ((TSB_CONFIG_TSB !=
2540 offsetof(struct tsb_config, tsb)) ||
2541 (TSB_CONFIG_RSS_LIMIT !=
2542 offsetof(struct tsb_config, tsb_rss_limit)) ||
2543 (TSB_CONFIG_NENTRIES !=
2544 offsetof(struct tsb_config, tsb_nentries)) ||
2545 (TSB_CONFIG_REG_VAL !=
2546 offsetof(struct tsb_config, tsb_reg_val)) ||
2547 (TSB_CONFIG_MAP_VADDR !=
2548 offsetof(struct tsb_config, tsb_map_vaddr)) ||
2549 (TSB_CONFIG_MAP_PTE !=
2550 offsetof(struct tsb_config, tsb_map_pte)))
2551 tsb_config_offsets_are_bolixed_dave();
2553 /* Attach to the address space of init_task. On SMP we
2554 * do this in smp.c:smp_callin for other cpus.
2556 atomic_inc(&init_mm.mm_count);
2557 current->active_mm = &init_mm;