kn02xa-berr.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Bus error event handling code for 5000-series systems equipped
  4. * with parity error detection logic, i.e. DECstation/DECsystem
  5. * 5000/120, /125, /133 (KN02-BA), 5000/150 (KN04-BA) and Personal
  6. * DECstation/DECsystem 5000/20, /25, /33 (KN02-CA), 5000/50
  7. * (KN04-CA) systems.
  8. *
  9. * Copyright (c) 2005 Maciej W. Rozycki
  10. */
  11. #include <linux/init.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/kernel.h>
  14. #include <linux/types.h>
  15. #include <asm/addrspace.h>
  16. #include <asm/cpu-type.h>
  17. #include <asm/irq_regs.h>
  18. #include <asm/ptrace.h>
  19. #include <asm/traps.h>
  20. #include <asm/dec/kn02ca.h>
  21. #include <asm/dec/kn02xa.h>
  22. #include <asm/dec/kn05.h>
  23. static inline void dec_kn02xa_be_ack(void)
  24. {
  25. volatile u32 *mer = (void *)CKSEG1ADDR(KN02XA_MER);
  26. volatile u32 *mem_intr = (void *)CKSEG1ADDR(KN02XA_MEM_INTR);
  27. *mer = KN02CA_MER_INTR; /* Clear errors; keep the ARC IRQ. */
  28. *mem_intr = 0; /* Any write clears the bus IRQ. */
  29. iob();
  30. }
  31. static int dec_kn02xa_be_backend(struct pt_regs *regs, int is_fixup,
  32. int invoker)
  33. {
  34. volatile u32 *kn02xa_mer = (void *)CKSEG1ADDR(KN02XA_MER);
  35. volatile u32 *kn02xa_ear = (void *)CKSEG1ADDR(KN02XA_EAR);
  36. static const char excstr[] = "exception";
  37. static const char intstr[] = "interrupt";
  38. static const char cpustr[] = "CPU";
  39. static const char mreadstr[] = "memory read";
  40. static const char readstr[] = "read";
  41. static const char writestr[] = "write";
  42. static const char timestr[] = "timeout";
  43. static const char paritystr[] = "parity error";
  44. static const char lanestat[][4] = { " OK", "BAD" };
  45. const char *kind, *agent, *cycle, *event;
  46. unsigned long address;
  47. u32 mer = *kn02xa_mer;
  48. u32 ear = *kn02xa_ear;
  49. int action = MIPS_BE_FATAL;
  50. /* Ack ASAP, so that any subsequent errors get caught. */
  51. dec_kn02xa_be_ack();
  52. kind = invoker ? intstr : excstr;
  53. /* No DMA errors? */
  54. agent = cpustr;
  55. address = ear & KN02XA_EAR_ADDRESS;
  56. /* Low 256MB is decoded as memory, high -- as TC. */
  57. if (address < 0x10000000) {
  58. cycle = mreadstr;
  59. event = paritystr;
  60. } else {
  61. cycle = invoker ? writestr : readstr;
  62. event = timestr;
  63. }
  64. if (is_fixup)
  65. action = MIPS_BE_FIXUP;
  66. if (action != MIPS_BE_FIXUP)
  67. printk(KERN_ALERT "Bus error %s: %s %s %s at %#010lx\n",
  68. kind, agent, cycle, event, address);
  69. if (action != MIPS_BE_FIXUP && address < 0x10000000)
  70. printk(KERN_ALERT " Byte lane status %#3x -- "
  71. "#3: %s, #2: %s, #1: %s, #0: %s\n",
  72. (mer & KN02XA_MER_BYTERR) >> 8,
  73. lanestat[(mer & KN02XA_MER_BYTERR_3) != 0],
  74. lanestat[(mer & KN02XA_MER_BYTERR_2) != 0],
  75. lanestat[(mer & KN02XA_MER_BYTERR_1) != 0],
  76. lanestat[(mer & KN02XA_MER_BYTERR_0) != 0]);
  77. return action;
  78. }
  79. int dec_kn02xa_be_handler(struct pt_regs *regs, int is_fixup)
  80. {
  81. return dec_kn02xa_be_backend(regs, is_fixup, 0);
  82. }
  83. irqreturn_t dec_kn02xa_be_interrupt(int irq, void *dev_id)
  84. {
  85. struct pt_regs *regs = get_irq_regs();
  86. int action = dec_kn02xa_be_backend(regs, 0, 1);
  87. if (action == MIPS_BE_DISCARD)
  88. return IRQ_HANDLED;
  89. /*
  90. * FIXME: Find the affected processes and kill them, otherwise
  91. * we must die.
  92. *
  93. * The interrupt is asynchronously delivered thus EPC and RA
  94. * may be irrelevant, but are printed for a reference.
  95. */
  96. printk(KERN_ALERT "Fatal bus interrupt, epc == %08lx, ra == %08lx\n",
  97. regs->cp0_epc, regs->regs[31]);
  98. die("Unrecoverable bus error", regs);
  99. }
  100. void __init dec_kn02xa_be_init(void)
  101. {
  102. volatile u32 *mbcs = (void *)CKSEG1ADDR(KN4K_SLOT_BASE + KN4K_MB_CSR);
  103. /* For KN04 we need to make sure EE (?) is enabled in the MB. */
  104. if (current_cpu_type() == CPU_R4000SC)
  105. *mbcs |= KN4K_MB_CSR_EE;
  106. fast_iob();
  107. /* Clear any leftover errors from the firmware. */
  108. dec_kn02xa_be_ack();
  109. }