xref: /linux/arch/parisc/kernel/hpmc.S (revision 03ab8e6297acd1bc0eedaa050e2a1635c576fd11)
1660662f8SThomas Gleixner/* SPDX-License-Identifier: GPL-2.0-or-later */
21da177e4SLinus Torvalds/*
31da177e4SLinus Torvalds * HPMC (High Priority Machine Check) handler.
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds * Copyright (C) 1999 Philipp Rumpf <prumpf@tux.org>
61da177e4SLinus Torvalds * Copyright (C) 1999 Hewlett-Packard (Frank Rowand)
71da177e4SLinus Torvalds * Copyright (C) 2000 Hewlett-Packard (John Marvin)
81da177e4SLinus Torvalds */
91da177e4SLinus Torvalds
101da177e4SLinus Torvalds
111da177e4SLinus Torvalds/*
121da177e4SLinus Torvalds * This HPMC handler retrieves the HPMC pim data, resets IO and
131da177e4SLinus Torvalds * returns to the default trap handler with code set to 1 (HPMC).
141da177e4SLinus Torvalds * The default trap handler calls handle interruption, which
151da177e4SLinus Torvalds * does a stack and register dump. This at least allows kernel
161da177e4SLinus Torvalds * developers to get back to C code in virtual mode, where they
171da177e4SLinus Torvalds * have the option to examine and print values from memory that
181da177e4SLinus Torvalds * would help in debugging an HPMC caused by a software bug.
191da177e4SLinus Torvalds *
201da177e4SLinus Torvalds * There is more to do here:
211da177e4SLinus Torvalds *
221da177e4SLinus Torvalds *      1) On MP systems we need to synchronize processors
231da177e4SLinus Torvalds *         before calling pdc/iodc.
241da177e4SLinus Torvalds *      2) We should be checking the system state and not
251da177e4SLinus Torvalds *         returning to the fault handler if things are really
261da177e4SLinus Torvalds *         bad.
271da177e4SLinus Torvalds *
281da177e4SLinus Torvalds */
291da177e4SLinus Torvalds
301da177e4SLinus Torvalds	.level		1.1
311da177e4SLinus Torvalds
321da177e4SLinus Torvalds#include <asm/assembly.h>
331da177e4SLinus Torvalds#include <asm/pdc.h>
34f02e6c61SHelge Deller#include <asm/psw.h>
351da177e4SLinus Torvalds
368e9e9844SHelge Deller#include <linux/linkage.h>
372929e738SHelge Deller#include <linux/init.h>
388e9e9844SHelge Deller
391da177e4SLinus Torvalds	/*
401da177e4SLinus Torvalds	 * stack for os_hpmc, the HPMC handler.
411da177e4SLinus Torvalds	 * buffer for IODC procedures (for the HPMC handler).
421da177e4SLinus Torvalds	 *
431da177e4SLinus Torvalds	 * IODC requires 7K byte stack.  That leaves 1K byte for os_hpmc.
441da177e4SLinus Torvalds	 */
451da177e4SLinus Torvalds
46*e486288dSHelge Deller	.import toc_stack,data
47*e486288dSHelge Deller#define hpmc_stack	toc_stack	/* re-use the TOC stack */
481da177e4SLinus Torvalds
491da177e4SLinus Torvalds#define HPMC_IODC_BUF_SIZE 0x8000
501da177e4SLinus Torvalds
512929e738SHelge Deller	__PAGE_ALIGNED_BSS
526a45716aSHelge Deller	.align 4096
531da177e4SLinus Torvaldshpmc_iodc_buf:
541da177e4SLinus Torvalds	.block HPMC_IODC_BUF_SIZE
551da177e4SLinus Torvalds
562929e738SHelge Deller	.section .bss
571da177e4SLinus Torvalds	.align 8
581da177e4SLinus Torvaldshpmc_raddr:
591da177e4SLinus Torvalds	.block 128
601da177e4SLinus Torvalds
611da177e4SLinus Torvalds#define HPMC_PIM_DATA_SIZE 896 /* Enough to hold all architected 2.0 state */
621da177e4SLinus Torvalds
632929e738SHelge Deller	.section .bss
641da177e4SLinus Torvalds	.align 8
658e9e9844SHelge DellerENTRY(hpmc_pim_data)
661da177e4SLinus Torvalds	.block HPMC_PIM_DATA_SIZE
678e9e9844SHelge DellerEND(hpmc_pim_data)
681da177e4SLinus Torvalds
69dfcf753bSKyle McMartin	.text
701da177e4SLinus Torvalds
711da177e4SLinus Torvalds	.import intr_save, code
72d5654e15SHelge Deller	.align 16
7399a3ae51SHelge DellerENTRY(os_hpmc)
74ae16489eSKyle McMartin.os_hpmc:
751da177e4SLinus Torvalds
761da177e4SLinus Torvalds	/*
771da177e4SLinus Torvalds	 * registers modified:
781da177e4SLinus Torvalds	 *
791da177e4SLinus Torvalds	 *   Using callee saves registers without saving them.  The
801da177e4SLinus Torvalds	 *   original values are in the pim dump if we need them.
811da177e4SLinus Torvalds	 *
821da177e4SLinus Torvalds	 *   r2   (rp)  return pointer
831da177e4SLinus Torvalds	 *   r3   address of PDCE_PROC
841da177e4SLinus Torvalds	 *   r4   scratch
851da177e4SLinus Torvalds	 *   r5   scratch
861da177e4SLinus Torvalds	 *   r23  (arg3) procedure arg
871da177e4SLinus Torvalds	 *   r24  (arg2) procedure arg
881da177e4SLinus Torvalds	 *   r25  (arg1) procedure arg
891da177e4SLinus Torvalds	 *   r26  (arg0) procedure arg
901da177e4SLinus Torvalds	 *   r30  (sp)   stack pointer
911da177e4SLinus Torvalds	 *
921da177e4SLinus Torvalds	 * registers read:
931da177e4SLinus Torvalds	 *
941da177e4SLinus Torvalds	 *   r26  contains address of PDCE_PROC on entry
951da177e4SLinus Torvalds	 *   r28  (ret0) return value from procedure
961da177e4SLinus Torvalds	 */
971da177e4SLinus Torvalds
981da177e4SLinus Torvalds	copy    arg0, %r3       /* save address of PDCE_PROC */
991da177e4SLinus Torvalds
1001da177e4SLinus Torvalds	/*
1011da177e4SLinus Torvalds	 *  disable nested HPMCs
1021da177e4SLinus Torvalds	 *
1031da177e4SLinus Torvalds	 * Increment os_hpmc checksum to invalidate it.
1041da177e4SLinus Torvalds	 * Do this before turning the PSW M bit off.
1051da177e4SLinus Torvalds	 */
1061da177e4SLinus Torvalds
1071da177e4SLinus Torvalds	mfctl   %cr14, %r4
1081da177e4SLinus Torvalds	ldw     52(%r4),%r5
1091da177e4SLinus Torvalds	addi    1,%r5,%r5
1101da177e4SLinus Torvalds	stw     %r5,52(%r4)
1111da177e4SLinus Torvalds
1121da177e4SLinus Torvalds	/* MP_FIXME: synchronize all processors. */
1131da177e4SLinus Torvalds
1141da177e4SLinus Torvalds	/* Setup stack pointer. */
1151da177e4SLinus Torvalds
1161da177e4SLinus Torvalds	load32	PA(hpmc_stack),sp
1171da177e4SLinus Torvalds
1181da177e4SLinus Torvalds	ldo     128(sp),sp /* leave room for arguments */
1191da177e4SLinus Torvalds
1201da177e4SLinus Torvalds	/*
1211da177e4SLinus Torvalds	 * Most PDC routines require that the M bit be off.
1221da177e4SLinus Torvalds	 * So turn on the Q bit and turn off the M bit.
1231da177e4SLinus Torvalds	 */
1241da177e4SLinus Torvalds
125f02e6c61SHelge Deller	ldi     PSW_SM_Q,%r4                   /* PSW Q on, PSW M off */
1261da177e4SLinus Torvalds	mtctl   %r4,ipsw
1271da177e4SLinus Torvalds	mtctl   %r0,pcsq
1281da177e4SLinus Torvalds	mtctl   %r0,pcsq
1291da177e4SLinus Torvalds	load32	PA(os_hpmc_1),%r4
1301da177e4SLinus Torvalds	mtctl   %r4,pcoq
1311da177e4SLinus Torvalds	ldo     4(%r4),%r4
1321da177e4SLinus Torvalds	mtctl   %r4,pcoq
1331da177e4SLinus Torvalds	rfi
1341da177e4SLinus Torvalds	nop
1351da177e4SLinus Torvalds
1361da177e4SLinus Torvaldsos_hpmc_1:
1371da177e4SLinus Torvalds
1381da177e4SLinus Torvalds	/* Call PDC_PIM to get HPMC pim info */
1391da177e4SLinus Torvalds
1401da177e4SLinus Torvalds	/*
1411da177e4SLinus Torvalds	 * Note that on some newer boxes, PDC_PIM must be called
1421da177e4SLinus Torvalds	 * before PDC_IO if you want IO to be reset. PDC_PIM sets
1431da177e4SLinus Torvalds	 * a flag that PDC_IO examines.
1441da177e4SLinus Torvalds	 */
1451da177e4SLinus Torvalds
1461da177e4SLinus Torvalds	ldo     PDC_PIM(%r0), arg0
1471da177e4SLinus Torvalds	ldo     PDC_PIM_HPMC(%r0),arg1          /* Transfer HPMC data */
1481da177e4SLinus Torvalds	load32	PA(hpmc_raddr),arg2
1491da177e4SLinus Torvalds	load32	PA(hpmc_pim_data),arg3
1501da177e4SLinus Torvalds	load32	HPMC_PIM_DATA_SIZE,%r4
1511da177e4SLinus Torvalds	stw     %r4,-52(sp)
1521da177e4SLinus Torvalds
1531da177e4SLinus Torvalds	ldil    L%PA(os_hpmc_2), rp
1541da177e4SLinus Torvalds	bv      (r3)                            /* call pdce_proc */
1551da177e4SLinus Torvalds	ldo     R%PA(os_hpmc_2)(rp), rp
1561da177e4SLinus Torvalds
1571da177e4SLinus Torvaldsos_hpmc_2:
1581da177e4SLinus Torvalds	comib,<>  0,ret0, os_hpmc_fail
1591da177e4SLinus Torvalds
1601da177e4SLinus Torvalds	/* Reset IO by calling the hversion dependent PDC_IO routine */
1611da177e4SLinus Torvalds
1621da177e4SLinus Torvalds	ldo     PDC_IO(%r0),arg0
1631da177e4SLinus Torvalds	ldo     0(%r0),arg1                     /* log IO errors */
1641da177e4SLinus Torvalds	ldo     0(%r0),arg2                     /* reserved */
1651da177e4SLinus Torvalds	ldo     0(%r0),arg3                     /* reserved */
1661da177e4SLinus Torvalds	stw     %r0,-52(sp)                     /* reserved */
1671da177e4SLinus Torvalds
1681da177e4SLinus Torvalds	ldil    L%PA(os_hpmc_3),rp
1691da177e4SLinus Torvalds	bv      (%r3)                           /* call pdce_proc */
1701da177e4SLinus Torvalds	ldo     R%PA(os_hpmc_3)(rp),rp
1711da177e4SLinus Torvalds
1721da177e4SLinus Torvaldsos_hpmc_3:
1731da177e4SLinus Torvalds
1741da177e4SLinus Torvalds	/* FIXME? Check for errors from PDC_IO (-1 might be OK) */
1751da177e4SLinus Torvalds
1761da177e4SLinus Torvalds	/*
1771da177e4SLinus Torvalds	 * Initialize the IODC console device (HPA,SPA, path etc.
1781da177e4SLinus Torvalds	 * are stored on page 0.
1791da177e4SLinus Torvalds	 */
1801da177e4SLinus Torvalds
1811da177e4SLinus Torvalds	/*
1821da177e4SLinus Torvalds	 * Load IODC into hpmc_iodc_buf by calling PDC_IODC.
1831da177e4SLinus Torvalds	 * Note that PDC_IODC handles flushing the appropriate
1841da177e4SLinus Torvalds	 * data and instruction cache lines.
1851da177e4SLinus Torvalds	 */
1861da177e4SLinus Torvalds
1871da177e4SLinus Torvalds	ldo     PDC_IODC(%r0),arg0
1881da177e4SLinus Torvalds	ldo     PDC_IODC_READ(%r0),arg1
1891da177e4SLinus Torvalds	load32	PA(hpmc_raddr),arg2
1901da177e4SLinus Torvalds	ldw     BOOT_CONSOLE_HPA_OFFSET(%r0),arg3 /* console hpa */
1911da177e4SLinus Torvalds	ldo     PDC_IODC_RI_INIT(%r0),%r4
1921da177e4SLinus Torvalds	stw     %r4,-52(sp)
1931da177e4SLinus Torvalds	load32	PA(hpmc_iodc_buf),%r4
1941da177e4SLinus Torvalds	stw     %r4,-56(sp)
1951da177e4SLinus Torvalds	load32	HPMC_IODC_BUF_SIZE,%r4
1961da177e4SLinus Torvalds	stw     %r4,-60(sp)
1971da177e4SLinus Torvalds
1981da177e4SLinus Torvalds	ldil    L%PA(os_hpmc_4),rp
1991da177e4SLinus Torvalds	bv      (%r3)                            /* call pdce_proc */
2001da177e4SLinus Torvalds	ldo     R%PA(os_hpmc_4)(rp),rp
2011da177e4SLinus Torvalds
2021da177e4SLinus Torvaldsos_hpmc_4:
2031da177e4SLinus Torvalds	comib,<>  0,ret0,os_hpmc_fail
2041da177e4SLinus Torvalds
2051da177e4SLinus Torvalds	/* Call the entry init (just loaded by PDC_IODC) */
2061da177e4SLinus Torvalds
2071da177e4SLinus Torvalds	ldw     BOOT_CONSOLE_HPA_OFFSET(%r0),arg0  /* console hpa */
2081da177e4SLinus Torvalds	ldo     ENTRY_INIT_MOD_DEV(%r0), arg1
2091da177e4SLinus Torvalds	ldw     BOOT_CONSOLE_SPA_OFFSET(%r0),arg2  /* console spa */
2101da177e4SLinus Torvalds	depi    0,31,11,arg2                       /* clear bits 21-31    */
2111da177e4SLinus Torvalds	ldo     BOOT_CONSOLE_PATH_OFFSET(%r0),arg3 /* console path */
2121da177e4SLinus Torvalds	load32	PA(hpmc_raddr),%r4
2131da177e4SLinus Torvalds	stw     %r4, -52(sp)
2141da177e4SLinus Torvalds	stw     %r0, -56(sp)                    /* HV                  */
2151da177e4SLinus Torvalds	stw     %r0, -60(sp)                    /* HV                  */
2161da177e4SLinus Torvalds	stw     %r0, -64(sp)                    /* HV                  */
2171da177e4SLinus Torvalds	stw     %r0, -68(sp)                    /* lang, must be zero  */
2181da177e4SLinus Torvalds
2191da177e4SLinus Torvalds	load32	PA(hpmc_iodc_buf),%r5
2201da177e4SLinus Torvalds	ldil    L%PA(os_hpmc_5),rp
2211da177e4SLinus Torvalds	bv      (%r5)
2221da177e4SLinus Torvalds	ldo     R%PA(os_hpmc_5)(rp),rp
2231da177e4SLinus Torvalds
2241da177e4SLinus Torvaldsos_hpmc_5:
2251da177e4SLinus Torvalds	comib,<>  0,ret0,os_hpmc_fail
2261da177e4SLinus Torvalds
2271da177e4SLinus Torvalds	/* Prepare to call intr_save */
2281da177e4SLinus Torvalds
2291da177e4SLinus Torvalds	/*
2301da177e4SLinus Torvalds	 * Load kernel page directory (load into user also, since
2311da177e4SLinus Torvalds	 * we don't intend to ever return to user land anyway)
2321da177e4SLinus Torvalds	 */
2331da177e4SLinus Torvalds
2341da177e4SLinus Torvalds	load32		PA(swapper_pg_dir),%r4
2351da177e4SLinus Torvalds	mtctl		%r4,%cr24	/* Initialize kernel root pointer */
2361da177e4SLinus Torvalds	mtctl		%r4,%cr25	/* Initialize user root pointer */
2371da177e4SLinus Torvalds
2381da177e4SLinus Torvalds	/* Clear sr4-sr7 */
2391da177e4SLinus Torvalds
2401da177e4SLinus Torvalds	mtsp	%r0, %sr4
2411da177e4SLinus Torvalds	mtsp	%r0, %sr5
2421da177e4SLinus Torvalds	mtsp	%r0, %sr6
2431da177e4SLinus Torvalds	mtsp	%r0, %sr7
2441da177e4SLinus Torvalds
2451da177e4SLinus Torvalds	tovirt_r1 %r30      /* make sp virtual */
2461da177e4SLinus Torvalds
247f02e6c61SHelge Deller	rsm     PSW_SM_Q,%r0           /* Clear Q bit */
2481da177e4SLinus Torvalds	ldi     1,%r8       /* Set trap code to "1" for HPMC */
2491da177e4SLinus Torvalds	load32	PA(intr_save),%r1
2501da177e4SLinus Torvalds	be      0(%sr7,%r1)
2511da177e4SLinus Torvalds	nop
2521da177e4SLinus Torvalds
2531da177e4SLinus Torvaldsos_hpmc_fail:
2541da177e4SLinus Torvalds
2551da177e4SLinus Torvalds	/*
2561da177e4SLinus Torvalds	 * Reset the system
2571da177e4SLinus Torvalds	 *
2581da177e4SLinus Torvalds	 * Some systems may lockup from a broadcast reset, so try the
2591da177e4SLinus Torvalds	 * hversion PDC_BROADCAST_RESET() first.
2601da177e4SLinus Torvalds	 * MP_FIXME: reset all processors if more than one central bus.
2611da177e4SLinus Torvalds	 */
2621da177e4SLinus Torvalds
2631da177e4SLinus Torvalds	/* PDC_BROADCAST_RESET() */
2641da177e4SLinus Torvalds
2651da177e4SLinus Torvalds	ldo     PDC_BROADCAST_RESET(%r0),arg0
2661da177e4SLinus Torvalds	ldo     0(%r0),arg1                     /* do reset */
2671da177e4SLinus Torvalds
2681da177e4SLinus Torvalds	ldil    L%PA(os_hpmc_6),rp
2691da177e4SLinus Torvalds	bv      (%r3)                           /* call pdce_proc */
2701da177e4SLinus Torvalds	ldo     R%PA(os_hpmc_6)(rp),rp
2711da177e4SLinus Torvalds
2721da177e4SLinus Torvaldsos_hpmc_6:
2731da177e4SLinus Torvalds
2741da177e4SLinus Torvalds	/*
2751da177e4SLinus Torvalds	 * possible return values:
2761da177e4SLinus Torvalds	 *  -1  non-existent procedure
2771da177e4SLinus Torvalds	 *  -2  non-existent option
2781da177e4SLinus Torvalds	 *  -16 unaligned stack
2791da177e4SLinus Torvalds	 *
2801da177e4SLinus Torvalds	 * If call returned, do a broadcast reset.
2811da177e4SLinus Torvalds	 */
2821da177e4SLinus Torvalds
2831da177e4SLinus Torvalds	ldil    L%0xfffc0000,%r4        /* IO_BROADCAST */
2841da177e4SLinus Torvalds	ldo     5(%r0),%r5
2851da177e4SLinus Torvalds	stw     %r5,48(%r4)             /*  CMD_RESET to IO_COMMAND offset */
2861da177e4SLinus Torvalds
2871da177e4SLinus Torvalds	b .
2881da177e4SLinus Torvalds	nop
289d5654e15SHelge Deller	.align 16	/* make function length multiple of 16 bytes */
290