18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Bus error event handling code for 5000-series systems equipped 48c2ecf20Sopenharmony_ci * with parity error detection logic, i.e. DECstation/DECsystem 58c2ecf20Sopenharmony_ci * 5000/120, /125, /133 (KN02-BA), 5000/150 (KN04-BA) and Personal 68c2ecf20Sopenharmony_ci * DECstation/DECsystem 5000/20, /25, /33 (KN02-CA), 5000/50 78c2ecf20Sopenharmony_ci * (KN04-CA) systems. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Copyright (c) 2005 Maciej W. Rozycki 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/init.h> 138c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 148c2ecf20Sopenharmony_ci#include <linux/kernel.h> 158c2ecf20Sopenharmony_ci#include <linux/types.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <asm/addrspace.h> 188c2ecf20Sopenharmony_ci#include <asm/cpu-type.h> 198c2ecf20Sopenharmony_ci#include <asm/irq_regs.h> 208c2ecf20Sopenharmony_ci#include <asm/ptrace.h> 218c2ecf20Sopenharmony_ci#include <asm/traps.h> 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#include <asm/dec/kn02ca.h> 248c2ecf20Sopenharmony_ci#include <asm/dec/kn02xa.h> 258c2ecf20Sopenharmony_ci#include <asm/dec/kn05.h> 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_cistatic inline void dec_kn02xa_be_ack(void) 288c2ecf20Sopenharmony_ci{ 298c2ecf20Sopenharmony_ci volatile u32 *mer = (void *)CKSEG1ADDR(KN02XA_MER); 308c2ecf20Sopenharmony_ci volatile u32 *mem_intr = (void *)CKSEG1ADDR(KN02XA_MEM_INTR); 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci *mer = KN02CA_MER_INTR; /* Clear errors; keep the ARC IRQ. */ 338c2ecf20Sopenharmony_ci *mem_intr = 0; /* Any write clears the bus IRQ. */ 348c2ecf20Sopenharmony_ci iob(); 358c2ecf20Sopenharmony_ci} 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistatic int dec_kn02xa_be_backend(struct pt_regs *regs, int is_fixup, 388c2ecf20Sopenharmony_ci int invoker) 398c2ecf20Sopenharmony_ci{ 408c2ecf20Sopenharmony_ci volatile u32 *kn02xa_mer = (void *)CKSEG1ADDR(KN02XA_MER); 418c2ecf20Sopenharmony_ci volatile u32 *kn02xa_ear = (void *)CKSEG1ADDR(KN02XA_EAR); 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci static const char excstr[] = "exception"; 448c2ecf20Sopenharmony_ci static const char intstr[] = "interrupt"; 458c2ecf20Sopenharmony_ci static const char cpustr[] = "CPU"; 468c2ecf20Sopenharmony_ci static const char mreadstr[] = "memory read"; 478c2ecf20Sopenharmony_ci static const char readstr[] = "read"; 488c2ecf20Sopenharmony_ci static const char writestr[] = "write"; 498c2ecf20Sopenharmony_ci static const char timestr[] = "timeout"; 508c2ecf20Sopenharmony_ci static const char paritystr[] = "parity error"; 518c2ecf20Sopenharmony_ci static const char lanestat[][4] = { " OK", "BAD" }; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci const char *kind, *agent, *cycle, *event; 548c2ecf20Sopenharmony_ci unsigned long address; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci u32 mer = *kn02xa_mer; 578c2ecf20Sopenharmony_ci u32 ear = *kn02xa_ear; 588c2ecf20Sopenharmony_ci int action = MIPS_BE_FATAL; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci /* Ack ASAP, so that any subsequent errors get caught. */ 618c2ecf20Sopenharmony_ci dec_kn02xa_be_ack(); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci kind = invoker ? intstr : excstr; 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci /* No DMA errors? */ 668c2ecf20Sopenharmony_ci agent = cpustr; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci address = ear & KN02XA_EAR_ADDRESS; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci /* Low 256MB is decoded as memory, high -- as TC. */ 718c2ecf20Sopenharmony_ci if (address < 0x10000000) { 728c2ecf20Sopenharmony_ci cycle = mreadstr; 738c2ecf20Sopenharmony_ci event = paritystr; 748c2ecf20Sopenharmony_ci } else { 758c2ecf20Sopenharmony_ci cycle = invoker ? writestr : readstr; 768c2ecf20Sopenharmony_ci event = timestr; 778c2ecf20Sopenharmony_ci } 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci if (is_fixup) 808c2ecf20Sopenharmony_ci action = MIPS_BE_FIXUP; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci if (action != MIPS_BE_FIXUP) 838c2ecf20Sopenharmony_ci printk(KERN_ALERT "Bus error %s: %s %s %s at %#010lx\n", 848c2ecf20Sopenharmony_ci kind, agent, cycle, event, address); 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci if (action != MIPS_BE_FIXUP && address < 0x10000000) 878c2ecf20Sopenharmony_ci printk(KERN_ALERT " Byte lane status %#3x -- " 888c2ecf20Sopenharmony_ci "#3: %s, #2: %s, #1: %s, #0: %s\n", 898c2ecf20Sopenharmony_ci (mer & KN02XA_MER_BYTERR) >> 8, 908c2ecf20Sopenharmony_ci lanestat[(mer & KN02XA_MER_BYTERR_3) != 0], 918c2ecf20Sopenharmony_ci lanestat[(mer & KN02XA_MER_BYTERR_2) != 0], 928c2ecf20Sopenharmony_ci lanestat[(mer & KN02XA_MER_BYTERR_1) != 0], 938c2ecf20Sopenharmony_ci lanestat[(mer & KN02XA_MER_BYTERR_0) != 0]); 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci return action; 968c2ecf20Sopenharmony_ci} 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ciint dec_kn02xa_be_handler(struct pt_regs *regs, int is_fixup) 998c2ecf20Sopenharmony_ci{ 1008c2ecf20Sopenharmony_ci return dec_kn02xa_be_backend(regs, is_fixup, 0); 1018c2ecf20Sopenharmony_ci} 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ciirqreturn_t dec_kn02xa_be_interrupt(int irq, void *dev_id) 1048c2ecf20Sopenharmony_ci{ 1058c2ecf20Sopenharmony_ci struct pt_regs *regs = get_irq_regs(); 1068c2ecf20Sopenharmony_ci int action = dec_kn02xa_be_backend(regs, 0, 1); 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci if (action == MIPS_BE_DISCARD) 1098c2ecf20Sopenharmony_ci return IRQ_HANDLED; 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci /* 1128c2ecf20Sopenharmony_ci * FIXME: Find the affected processes and kill them, otherwise 1138c2ecf20Sopenharmony_ci * we must die. 1148c2ecf20Sopenharmony_ci * 1158c2ecf20Sopenharmony_ci * The interrupt is asynchronously delivered thus EPC and RA 1168c2ecf20Sopenharmony_ci * may be irrelevant, but are printed for a reference. 1178c2ecf20Sopenharmony_ci */ 1188c2ecf20Sopenharmony_ci printk(KERN_ALERT "Fatal bus interrupt, epc == %08lx, ra == %08lx\n", 1198c2ecf20Sopenharmony_ci regs->cp0_epc, regs->regs[31]); 1208c2ecf20Sopenharmony_ci die("Unrecoverable bus error", regs); 1218c2ecf20Sopenharmony_ci} 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_civoid __init dec_kn02xa_be_init(void) 1258c2ecf20Sopenharmony_ci{ 1268c2ecf20Sopenharmony_ci volatile u32 *mbcs = (void *)CKSEG1ADDR(KN4K_SLOT_BASE + KN4K_MB_CSR); 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci /* For KN04 we need to make sure EE (?) is enabled in the MB. */ 1298c2ecf20Sopenharmony_ci if (current_cpu_type() == CPU_R4000SC) 1308c2ecf20Sopenharmony_ci *mbcs |= KN4K_MB_CSR_EE; 1318c2ecf20Sopenharmony_ci fast_iob(); 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci /* Clear any leftover errors from the firmware. */ 1348c2ecf20Sopenharmony_ci dec_kn02xa_be_ack(); 1358c2ecf20Sopenharmony_ci} 136