1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Bus error event handling code for DECstation/DECsystem 3100
4 * and 2100 (KN01) systems equipped with parity error detection
7 * Copyright (c) 2005 Maciej W. Rozycki
10 #include <linux/init.h>
11 #include <linux/interrupt.h>
12 #include <linux/kernel.h>
13 #include <linux/spinlock.h>
14 #include <linux/types.h>
17 #include <asm/irq_regs.h>
18 #include <asm/mipsregs.h>
20 #include <asm/ptrace.h>
21 #include <asm/traps.h>
22 #include <linux/uaccess.h>
24 #include <asm/dec/kn01.h>
27 /* CP0 hazard avoidance. */
29 __asm__ __volatile__( \
31 ".set noreorder\n\t" \
36 * Bits 7:0 of the Control Register are write-only -- the
37 * corresponding bits of the Status Register have a different
38 * meaning. Hence we use a cache. It speeds up things a bit
41 * There is no default value -- it has to be initialized.
44 static DEFINE_RAW_SPINLOCK(kn01_lock
);
47 static inline void dec_kn01_be_ack(void)
49 volatile u16
*csr
= (void *)CKSEG1ADDR(KN01_SLOT_BASE
+ KN01_CSR
);
52 raw_spin_lock_irqsave(&kn01_lock
, flags
);
54 *csr
= cached_kn01_csr
| KN01_CSR_MEMERR
; /* Clear bus IRQ. */
57 raw_spin_unlock_irqrestore(&kn01_lock
, flags
);
60 static int dec_kn01_be_backend(struct pt_regs
*regs
, int is_fixup
, int invoker
)
62 volatile u32
*kn01_erraddr
= (void *)CKSEG1ADDR(KN01_SLOT_BASE
+
65 static const char excstr
[] = "exception";
66 static const char intstr
[] = "interrupt";
67 static const char cpustr
[] = "CPU";
68 static const char mreadstr
[] = "memory read";
69 static const char readstr
[] = "read";
70 static const char writestr
[] = "write";
71 static const char timestr
[] = "timeout";
72 static const char paritystr
[] = "parity error";
74 int data
= regs
->cp0_cause
& 4;
75 unsigned int __user
*pc
= (unsigned int __user
*)regs
->cp0_epc
+
76 ((regs
->cp0_cause
& CAUSEF_BD
) != 0);
77 union mips_instruction insn
;
78 unsigned long entrylo
, offset
;
79 long asid
, entryhi
, vaddr
;
81 const char *kind
, *agent
, *cycle
, *event
;
82 unsigned long address
;
84 u32 erraddr
= *kn01_erraddr
;
85 int action
= MIPS_BE_FATAL
;
87 /* Ack ASAP, so that any subsequent errors get caught. */
90 kind
= invoker
? intstr
: excstr
;
97 /* Bloody hardware doesn't record the address for reads... */
99 /* This never faults. */
100 __get_user(insn
.word
, pc
);
101 vaddr
= regs
->regs
[insn
.i_format
.rs
] +
102 insn
.i_format
.simmediate
;
105 if (KSEGX(vaddr
) == CKSEG0
|| KSEGX(vaddr
) == CKSEG1
)
106 address
= CPHYSADDR(vaddr
);
108 /* Peek at what physical address the CPU used. */
109 asid
= read_c0_entryhi();
110 entryhi
= asid
& (PAGE_SIZE
- 1);
111 entryhi
|= vaddr
& ~(PAGE_SIZE
- 1);
112 write_c0_entryhi(entryhi
);
115 /* No need to check for presence. */
117 entrylo
= read_c0_entrylo0();
118 write_c0_entryhi(asid
);
119 offset
= vaddr
& (PAGE_SIZE
- 1);
120 address
= (entrylo
& ~(PAGE_SIZE
- 1)) | offset
;
124 /* Treat low 256MB as memory, high -- as I/O. */
125 if (address
< 0x10000000) {
129 cycle
= invoker
? writestr
: readstr
;
134 action
= MIPS_BE_FIXUP
;
136 if (action
!= MIPS_BE_FIXUP
)
137 printk(KERN_ALERT
"Bus error %s: %s %s %s at %#010lx\n",
138 kind
, agent
, cycle
, event
, address
);
143 int dec_kn01_be_handler(struct pt_regs
*regs
, int is_fixup
)
145 return dec_kn01_be_backend(regs
, is_fixup
, 0);
148 irqreturn_t
dec_kn01_be_interrupt(int irq
, void *dev_id
)
150 volatile u16
*csr
= (void *)CKSEG1ADDR(KN01_SLOT_BASE
+ KN01_CSR
);
151 struct pt_regs
*regs
= get_irq_regs();
154 if (!(*csr
& KN01_CSR_MEMERR
))
155 return IRQ_NONE
; /* Must have been video. */
157 action
= dec_kn01_be_backend(regs
, 0, 1);
159 if (action
== MIPS_BE_DISCARD
)
163 * FIXME: Find the affected processes and kill them, otherwise
166 * The interrupt is asynchronously delivered thus EPC and RA
167 * may be irrelevant, but are printed for a reference.
169 printk(KERN_ALERT
"Fatal bus interrupt, epc == %08lx, ra == %08lx\n",
170 regs
->cp0_epc
, regs
->regs
[31]);
171 die("Unrecoverable bus error", regs
);
175 void __init
dec_kn01_be_init(void)
177 volatile u16
*csr
= (void *)CKSEG1ADDR(KN01_SLOT_BASE
+ KN01_CSR
);
180 raw_spin_lock_irqsave(&kn01_lock
, flags
);
182 /* Preset write-only bits of the Control Register cache. */
183 cached_kn01_csr
= *csr
;
184 cached_kn01_csr
&= KN01_CSR_STATUS
| KN01_CSR_PARDIS
| KN01_CSR_TXDIS
;
185 cached_kn01_csr
|= KN01_CSR_LEDS
;
187 /* Enable parity error detection. */
188 cached_kn01_csr
&= ~KN01_CSR_PARDIS
;
189 *csr
= cached_kn01_csr
;
192 raw_spin_unlock_irqrestore(&kn01_lock
, flags
);
194 /* Clear any leftover errors from the firmware. */