/kern_2.6.32/arch/mips/dec/kn01-berr.c

http://omnia2droid.googlecode.com/ · C · 201 lines · 127 code · 37 blank · 37 comment · 17 complexity · cb2a892bfbd60596162ef933acfacc93 MD5 · raw file

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