kn01-berr.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Bus error event handling code for DECstation/DECsystem 3100
  3. * and 2100 (KN01) systems equipped with parity error detection
  4. * logic.
  5. *
  6. * Copyright (c) 2005 Maciej W. Rozycki
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the License, or (at your option) any later version.
  12. */
  13. #include <linux/init.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/kernel.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/types.h>
  18. #include <asm/inst.h>
  19. #include <asm/irq_regs.h>
  20. #include <asm/mipsregs.h>
  21. #include <asm/page.h>
  22. #include <asm/ptrace.h>
  23. #include <asm/traps.h>
  24. #include <asm/uaccess.h>
  25. #include <asm/dec/kn01.h>
  26. /* CP0 hazard avoidance. */
  27. #define BARRIER \
  28. __asm__ __volatile__( \
  29. ".set push\n\t" \
  30. ".set noreorder\n\t" \
  31. "nop\n\t" \
  32. ".set pop\n\t")
  33. /*
  34. * Bits 7:0 of the Control Register are write-only -- the
  35. * corresponding bits of the Status Register have a different
  36. * meaning. Hence we use a cache. It speeds up things a bit
  37. * as well.
  38. *
  39. * There is no default value -- it has to be initialized.
  40. */
  41. u16 cached_kn01_csr;
  42. static DEFINE_RAW_SPINLOCK(kn01_lock);
  43. static inline void dec_kn01_be_ack(void)
  44. {
  45. volatile u16 *csr = (void *)CKSEG1ADDR(KN01_SLOT_BASE + KN01_CSR);
  46. unsigned long flags;
  47. raw_spin_lock_irqsave(&kn01_lock, flags);
  48. *csr = cached_kn01_csr | KN01_CSR_MEMERR; /* Clear bus IRQ. */
  49. iob();
  50. raw_spin_unlock_irqrestore(&kn01_lock, flags);
  51. }
  52. static int dec_kn01_be_backend(struct pt_regs *regs, int is_fixup, int invoker)
  53. {
  54. volatile u32 *kn01_erraddr = (void *)CKSEG1ADDR(KN01_SLOT_BASE +
  55. KN01_ERRADDR);
  56. static const char excstr[] = "exception";
  57. static const char intstr[] = "interrupt";
  58. static const char cpustr[] = "CPU";
  59. static const char mreadstr[] = "memory read";
  60. static const char readstr[] = "read";
  61. static const char writestr[] = "write";
  62. static const char timestr[] = "timeout";
  63. static const char paritystr[] = "parity error";
  64. int data = regs->cp0_cause & 4;
  65. unsigned int __user *pc = (unsigned int __user *)regs->cp0_epc +
  66. ((regs->cp0_cause & CAUSEF_BD) != 0);
  67. union mips_instruction insn;
  68. unsigned long entrylo, offset;
  69. long asid, entryhi, vaddr;
  70. const char *kind, *agent, *cycle, *event;
  71. unsigned long address;
  72. u32 erraddr = *kn01_erraddr;
  73. int action = MIPS_BE_FATAL;
  74. /* Ack ASAP, so that any subsequent errors get caught. */
  75. dec_kn01_be_ack();
  76. kind = invoker ? intstr : excstr;
  77. agent = cpustr;
  78. if (invoker)
  79. address = erraddr;
  80. else {
  81. /* Bloody hardware doesn't record the address for reads... */
  82. if (data) {
  83. /* This never faults. */
  84. __get_user(insn.word, pc);
  85. vaddr = regs->regs[insn.i_format.rs] +
  86. insn.i_format.simmediate;
  87. } else
  88. vaddr = (long)pc;
  89. if (KSEGX(vaddr) == CKSEG0 || KSEGX(vaddr) == CKSEG1)
  90. address = CPHYSADDR(vaddr);
  91. else {
  92. /* Peek at what physical address the CPU used. */
  93. asid = read_c0_entryhi();
  94. entryhi = asid & (PAGE_SIZE - 1);
  95. entryhi |= vaddr & ~(PAGE_SIZE - 1);
  96. write_c0_entryhi(entryhi);
  97. BARRIER;
  98. tlb_probe();
  99. /* No need to check for presence. */
  100. tlb_read();
  101. entrylo = read_c0_entrylo0();
  102. write_c0_entryhi(asid);
  103. offset = vaddr & (PAGE_SIZE - 1);
  104. address = (entrylo & ~(PAGE_SIZE - 1)) | offset;
  105. }
  106. }
  107. /* Treat low 256MB as memory, high -- as I/O. */
  108. if (address < 0x10000000) {
  109. cycle = mreadstr;
  110. event = paritystr;
  111. } else {
  112. cycle = invoker ? writestr : readstr;
  113. event = timestr;
  114. }
  115. if (is_fixup)
  116. action = MIPS_BE_FIXUP;
  117. if (action != MIPS_BE_FIXUP)
  118. printk(KERN_ALERT "Bus error %s: %s %s %s at %#010lx\n",
  119. kind, agent, cycle, event, address);
  120. return action;
  121. }
  122. int dec_kn01_be_handler(struct pt_regs *regs, int is_fixup)
  123. {
  124. return dec_kn01_be_backend(regs, is_fixup, 0);
  125. }
  126. irqreturn_t dec_kn01_be_interrupt(int irq, void *dev_id)
  127. {
  128. volatile u16 *csr = (void *)CKSEG1ADDR(KN01_SLOT_BASE + KN01_CSR);
  129. struct pt_regs *regs = get_irq_regs();
  130. int action;
  131. if (!(*csr & KN01_CSR_MEMERR))
  132. return IRQ_NONE; /* Must have been video. */
  133. action = dec_kn01_be_backend(regs, 0, 1);
  134. if (action == MIPS_BE_DISCARD)
  135. return IRQ_HANDLED;
  136. /*
  137. * FIXME: Find the affected processes and kill them, otherwise
  138. * we must die.
  139. *
  140. * The interrupt is asynchronously delivered thus EPC and RA
  141. * may be irrelevant, but are printed for a reference.
  142. */
  143. printk(KERN_ALERT "Fatal bus interrupt, epc == %08lx, ra == %08lx\n",
  144. regs->cp0_epc, regs->regs[31]);
  145. die("Unrecoverable bus error", regs);
  146. }
  147. void __init dec_kn01_be_init(void)
  148. {
  149. volatile u16 *csr = (void *)CKSEG1ADDR(KN01_SLOT_BASE + KN01_CSR);
  150. unsigned long flags;
  151. raw_spin_lock_irqsave(&kn01_lock, flags);
  152. /* Preset write-only bits of the Control Register cache. */
  153. cached_kn01_csr = *csr;
  154. cached_kn01_csr &= KN01_CSR_STATUS | KN01_CSR_PARDIS | KN01_CSR_TXDIS;
  155. cached_kn01_csr |= KN01_CSR_LEDS;
  156. /* Enable parity error detection. */
  157. cached_kn01_csr &= ~KN01_CSR_PARDIS;
  158. *csr = cached_kn01_csr;
  159. iob();
  160. raw_spin_unlock_irqrestore(&kn01_lock, flags);
  161. /* Clear any leftover errors from the firmware. */
  162. dec_kn01_be_ack();
  163. }