^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * ip22-berr.c: Bus error handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2002, 2003 Ladislav Michl (ladis@linux-mips.org)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <asm/addrspace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/traps.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/branch.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <asm/irq_regs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <asm/sgi/mc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <asm/sgi/hpc3.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <asm/sgi/ioc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <asm/sgi/ip22.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static unsigned int cpu_err_stat; /* Status reg for CPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static unsigned int gio_err_stat; /* Status reg for GIO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static unsigned int cpu_err_addr; /* Error address reg for CPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static unsigned int gio_err_addr; /* Error address reg for GIO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static unsigned int extio_stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static unsigned int hpc3_berr_stat; /* Bus error interrupt status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static void save_and_clear_buserr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /* save status registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) cpu_err_addr = sgimc->cerr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) cpu_err_stat = sgimc->cstat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) gio_err_addr = sgimc->gerr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) gio_err_stat = sgimc->gstat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) extio_stat = ip22_is_fullhouse() ? sgioc->extio : (sgint->errstat << 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) hpc3_berr_stat = hpc3c0->bestat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) sgimc->cstat = sgimc->gstat = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define GIO_ERRMASK 0xff00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define CPU_ERRMASK 0x3f00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static void print_buserr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (extio_stat & EXTIO_MC_BUSERR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) printk(KERN_ERR "MC Bus Error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if (extio_stat & EXTIO_HPC3_BUSERR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) printk(KERN_ERR "HPC3 Bus Error 0x%x:<id=0x%x,%s,lane=0x%x>\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) hpc3_berr_stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) (hpc3_berr_stat & HPC3_BESTAT_PIDMASK) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) HPC3_BESTAT_PIDSHIFT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) (hpc3_berr_stat & HPC3_BESTAT_CTYPE) ? "PIO" : "DMA",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) hpc3_berr_stat & HPC3_BESTAT_BLMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) if (extio_stat & EXTIO_EISA_BUSERR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) printk(KERN_ERR "EISA Bus Error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (cpu_err_stat & CPU_ERRMASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) printk(KERN_ERR "CPU error 0x%x<%s%s%s%s%s%s> @ 0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) cpu_err_stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) cpu_err_stat & SGIMC_CSTAT_RD ? "RD " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) cpu_err_stat & SGIMC_CSTAT_PAR ? "PAR " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) cpu_err_stat & SGIMC_CSTAT_ADDR ? "ADDR " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) cpu_err_stat & SGIMC_CSTAT_SYSAD_PAR ? "SYSAD " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) cpu_err_stat & SGIMC_CSTAT_SYSCMD_PAR ? "SYSCMD " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) cpu_err_stat & SGIMC_CSTAT_BAD_DATA ? "BAD_DATA " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) cpu_err_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (gio_err_stat & GIO_ERRMASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) printk(KERN_ERR "GIO error 0x%x:<%s%s%s%s%s%s%s%s> @ 0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) gio_err_stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) gio_err_stat & SGIMC_GSTAT_RD ? "RD " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) gio_err_stat & SGIMC_GSTAT_WR ? "WR " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) gio_err_stat & SGIMC_GSTAT_TIME ? "TIME " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) gio_err_stat & SGIMC_GSTAT_PROM ? "PROM " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) gio_err_stat & SGIMC_GSTAT_ADDR ? "ADDR " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) gio_err_stat & SGIMC_GSTAT_BC ? "BC " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) gio_err_stat & SGIMC_GSTAT_PIO_RD ? "PIO_RD " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) gio_err_stat & SGIMC_GSTAT_PIO_WR ? "PIO_WR " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) gio_err_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * MC sends an interrupt whenever bus or parity errors occur. In addition,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * if the error happened during a CPU read, it also asserts the bus error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * pin on the R4K. Code in bus error handler save the MC bus error registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * and then clear the interrupt when this happens.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) void ip22_be_interrupt(int irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) const int field = 2 * sizeof(unsigned long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct pt_regs *regs = get_irq_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) save_and_clear_buserr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) print_buserr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) printk(KERN_ALERT "%s bus error, epc == %0*lx, ra == %0*lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) (regs->cp0_cause & 4) ? "Data" : "Instruction",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) field, regs->cp0_epc, field, regs->regs[31]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /* Assume it would be too dangerous to continue ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) die_if_kernel("Oops", regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) force_sig(SIGBUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static int ip22_be_handler(struct pt_regs *regs, int is_fixup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) save_and_clear_buserr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (is_fixup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return MIPS_BE_FIXUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) print_buserr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return MIPS_BE_FATAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) void __init ip22_be_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) board_be_handler = ip22_be_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }