kn01-berr.c 5.1 KB

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