1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * HPMC (High Priority Machine Check) handler.
5 * Copyright (C) 1999 Philipp Rumpf <prumpf@tux.org>
6 * Copyright (C) 1999 Hewlett-Packard (Frank Rowand)
7 * Copyright (C) 2000 Hewlett-Packard (John Marvin)
12 * This HPMC handler retrieves the HPMC pim data, resets IO and
13 * returns to the default trap handler with code set to 1 (HPMC).
14 * The default trap handler calls handle interruption, which
15 * does a stack and register dump. This at least allows kernel
16 * developers to get back to C code in virtual mode, where they
17 * have the option to examine and print values from memory that
18 * would help in debugging an HPMC caused by a software bug.
20 * There is more to do here:
22 * 1) On MP systems we need to synchronize processors
23 * before calling pdc/iodc.
24 * 2) We should be checking the system state and not
25 * returning to the fault handler if things are really
32 #include <asm/assembly.h>
36 #include <linux/linkage.h>
37 #include <linux/init.h>
40 * stack for os_hpmc, the HPMC handler.
41 * buffer for IODC procedures (for the HPMC handler).
43 * IODC requires 7K byte stack. That leaves 1K byte for os_hpmc.
51 #define HPMC_IODC_BUF_SIZE 0x8000
56 .block HPMC_IODC_BUF_SIZE
63 #define HPMC_PIM_DATA_SIZE 896 /* Enough to hold all architected 2.0 state */
68 .block HPMC_PIM_DATA_SIZE
73 .import intr_save, code
81 * Using callee saves registers without saving them. The
82 * original values are in the pim dump if we need them.
84 * r2 (rp) return pointer
85 * r3 address of PDCE_PROC
88 * r23 (arg3) procedure arg
89 * r24 (arg2) procedure arg
90 * r25 (arg1) procedure arg
91 * r26 (arg0) procedure arg
92 * r30 (sp) stack pointer
96 * r26 contains address of PDCE_PROC on entry
97 * r28 (ret0) return value from procedure
100 copy arg0, %r3 /* save address of PDCE_PROC */
103 * disable nested HPMCs
105 * Increment os_hpmc checksum to invalidate it.
106 * Do this before turning the PSW M bit off.
114 /* MP_FIXME: synchronize all processors. */
116 /* Setup stack pointer. */
118 load32 PA(hpmc_stack),sp
120 ldo 128(sp),sp /* leave room for arguments */
123 * Most PDC routines require that the M bit be off.
124 * So turn on the Q bit and turn off the M bit.
127 ldi PSW_SM_Q,%r4 /* PSW Q on, PSW M off */
131 load32 PA(os_hpmc_1),%r4
140 /* Call PDC_PIM to get HPMC pim info */
143 * Note that on some newer boxes, PDC_PIM must be called
144 * before PDC_IO if you want IO to be reset. PDC_PIM sets
145 * a flag that PDC_IO examines.
148 ldo PDC_PIM(%r0), arg0
149 ldo PDC_PIM_HPMC(%r0),arg1 /* Transfer HPMC data */
150 load32 PA(hpmc_raddr),arg2
151 load32 PA(hpmc_pim_data),arg3
152 load32 HPMC_PIM_DATA_SIZE,%r4
155 ldil L%PA(os_hpmc_2), rp
156 bv (r3) /* call pdce_proc */
157 ldo R%PA(os_hpmc_2)(rp), rp
160 comib,<> 0,ret0, os_hpmc_fail
162 /* Reset IO by calling the hversion dependent PDC_IO routine */
165 ldo 0(%r0),arg1 /* log IO errors */
166 ldo 0(%r0),arg2 /* reserved */
167 ldo 0(%r0),arg3 /* reserved */
168 stw %r0,-52(sp) /* reserved */
170 ldil L%PA(os_hpmc_3),rp
171 bv (%r3) /* call pdce_proc */
172 ldo R%PA(os_hpmc_3)(rp),rp
176 /* FIXME? Check for errors from PDC_IO (-1 might be OK) */
179 * Initialize the IODC console device (HPA,SPA, path etc.
180 * are stored on page 0.
184 * Load IODC into hpmc_iodc_buf by calling PDC_IODC.
185 * Note that PDC_IODC handles flushing the appropriate
186 * data and instruction cache lines.
189 ldo PDC_IODC(%r0),arg0
190 ldo PDC_IODC_READ(%r0),arg1
191 load32 PA(hpmc_raddr),arg2
192 ldw BOOT_CONSOLE_HPA_OFFSET(%r0),arg3 /* console hpa */
193 ldo PDC_IODC_RI_INIT(%r0),%r4
195 load32 PA(hpmc_iodc_buf),%r4
197 load32 HPMC_IODC_BUF_SIZE,%r4
200 ldil L%PA(os_hpmc_4),rp
201 bv (%r3) /* call pdce_proc */
202 ldo R%PA(os_hpmc_4)(rp),rp
205 comib,<> 0,ret0,os_hpmc_fail
207 /* Call the entry init (just loaded by PDC_IODC) */
209 ldw BOOT_CONSOLE_HPA_OFFSET(%r0),arg0 /* console hpa */
210 ldo ENTRY_INIT_MOD_DEV(%r0), arg1
211 ldw BOOT_CONSOLE_SPA_OFFSET(%r0),arg2 /* console spa */
212 depi 0,31,11,arg2 /* clear bits 21-31 */
213 ldo BOOT_CONSOLE_PATH_OFFSET(%r0),arg3 /* console path */
214 load32 PA(hpmc_raddr),%r4
216 stw %r0, -56(sp) /* HV */
217 stw %r0, -60(sp) /* HV */
218 stw %r0, -64(sp) /* HV */
219 stw %r0, -68(sp) /* lang, must be zero */
221 load32 PA(hpmc_iodc_buf),%r5
222 ldil L%PA(os_hpmc_5),rp
224 ldo R%PA(os_hpmc_5)(rp),rp
227 comib,<> 0,ret0,os_hpmc_fail
229 /* Prepare to call intr_save */
232 * Load kernel page directory (load into user also, since
233 * we don't intend to ever return to user land anyway)
236 load32 PA(swapper_pg_dir),%r4
237 mtctl %r4,%cr24 /* Initialize kernel root pointer */
238 mtctl %r4,%cr25 /* Initialize user root pointer */
247 tovirt_r1 %r30 /* make sp virtual */
249 rsm PSW_SM_Q,%r0 /* Clear Q bit */
250 ldi 1,%r8 /* Set trap code to "1" for HPMC */
251 load32 PA(intr_save),%r1
260 * Some systems may lockup from a broadcast reset, so try the
261 * hversion PDC_BROADCAST_RESET() first.
262 * MP_FIXME: reset all processors if more than one central bus.
265 /* PDC_BROADCAST_RESET() */
267 ldo PDC_BROADCAST_RESET(%r0),arg0
268 ldo 0(%r0),arg1 /* do reset */
270 ldil L%PA(os_hpmc_6),rp
271 bv (%r3) /* call pdce_proc */
272 ldo R%PA(os_hpmc_6)(rp),rp
277 * possible return values:
278 * -1 non-existent procedure
279 * -2 non-existent option
280 * -16 unaligned stack
282 * If call returned, do a broadcast reset.
285 ldil L%0xfffc0000,%r4 /* IO_BROADCAST */
287 stw %r5,48(%r4) /* CMD_RESET to IO_COMMAND offset */
291 .align 16 /* make function length multiple of 16 bytes */
298 .type os_hpmc_size, @object
299 .size os_hpmc_size, 4
301 .word .os_hpmc_end-.os_hpmc