xref: /linux/arch/parisc/kernel/hpmc.S (revision d5654e156bc4d68a87bbaa6d7e020baceddf6e68)
11da177e4SLinus Torvalds/*
21da177e4SLinus Torvalds * HPMC (High Priority Machine Check) handler.
31da177e4SLinus Torvalds *
41da177e4SLinus Torvalds * Copyright (C) 1999 Philipp Rumpf <prumpf@tux.org>
51da177e4SLinus Torvalds * Copyright (C) 1999 Hewlett-Packard (Frank Rowand)
61da177e4SLinus Torvalds * Copyright (C) 2000 Hewlett-Packard (John Marvin)
71da177e4SLinus Torvalds *
81da177e4SLinus Torvalds *    This program is free software; you can redistribute it and/or modify
91da177e4SLinus Torvalds *    it under the terms of the GNU General Public License as published by
101da177e4SLinus Torvalds *    the Free Software Foundation; either version 2, or (at your option)
111da177e4SLinus Torvalds *    any later version.
121da177e4SLinus Torvalds *
131da177e4SLinus Torvalds *    This program is distributed in the hope that it will be useful,
141da177e4SLinus Torvalds *    but WITHOUT ANY WARRANTY; without even the implied warranty of
151da177e4SLinus Torvalds *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
161da177e4SLinus Torvalds *    GNU General Public License for more details.
171da177e4SLinus Torvalds *
181da177e4SLinus Torvalds *    You should have received a copy of the GNU General Public License
191da177e4SLinus Torvalds *    along with this program; if not, write to the Free Software
201da177e4SLinus Torvalds *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
211da177e4SLinus Torvalds */
221da177e4SLinus Torvalds
231da177e4SLinus Torvalds
241da177e4SLinus Torvalds/*
251da177e4SLinus Torvalds * This HPMC handler retrieves the HPMC pim data, resets IO and
261da177e4SLinus Torvalds * returns to the default trap handler with code set to 1 (HPMC).
271da177e4SLinus Torvalds * The default trap handler calls handle interruption, which
281da177e4SLinus Torvalds * does a stack and register dump. This at least allows kernel
291da177e4SLinus Torvalds * developers to get back to C code in virtual mode, where they
301da177e4SLinus Torvalds * have the option to examine and print values from memory that
311da177e4SLinus Torvalds * would help in debugging an HPMC caused by a software bug.
321da177e4SLinus Torvalds *
331da177e4SLinus Torvalds * There is more to do here:
341da177e4SLinus Torvalds *
351da177e4SLinus Torvalds *      1) On MP systems we need to synchronize processors
361da177e4SLinus Torvalds *         before calling pdc/iodc.
371da177e4SLinus Torvalds *      2) We should be checking the system state and not
381da177e4SLinus Torvalds *         returning to the fault handler if things are really
391da177e4SLinus Torvalds *         bad.
401da177e4SLinus Torvalds *
411da177e4SLinus Torvalds */
421da177e4SLinus Torvalds
431da177e4SLinus Torvalds	.level		1.1
441da177e4SLinus Torvalds
451da177e4SLinus Torvalds#include <asm/assembly.h>
461da177e4SLinus Torvalds#include <asm/pdc.h>
47f02e6c61SHelge Deller#include <asm/psw.h>
481da177e4SLinus Torvalds
498e9e9844SHelge Deller#include <linux/linkage.h>
502929e738SHelge Deller#include <linux/init.h>
518e9e9844SHelge Deller
521da177e4SLinus Torvalds	/*
531da177e4SLinus Torvalds	 * stack for os_hpmc, the HPMC handler.
541da177e4SLinus Torvalds	 * buffer for IODC procedures (for the HPMC handler).
551da177e4SLinus Torvalds	 *
561da177e4SLinus Torvalds	 * IODC requires 7K byte stack.  That leaves 1K byte for os_hpmc.
571da177e4SLinus Torvalds	 */
581da177e4SLinus Torvalds
592929e738SHelge Deller	__PAGE_ALIGNED_BSS
606a45716aSHelge Deller	.align 4096
611da177e4SLinus Torvaldshpmc_stack:
621da177e4SLinus Torvalds	.block 16384
631da177e4SLinus Torvalds
641da177e4SLinus Torvalds#define HPMC_IODC_BUF_SIZE 0x8000
651da177e4SLinus Torvalds
662929e738SHelge Deller	__PAGE_ALIGNED_BSS
676a45716aSHelge Deller	.align 4096
681da177e4SLinus Torvaldshpmc_iodc_buf:
691da177e4SLinus Torvalds	.block HPMC_IODC_BUF_SIZE
701da177e4SLinus Torvalds
712929e738SHelge Deller	.section .bss
721da177e4SLinus Torvalds	.align 8
731da177e4SLinus Torvaldshpmc_raddr:
741da177e4SLinus Torvalds	.block 128
751da177e4SLinus Torvalds
761da177e4SLinus Torvalds#define HPMC_PIM_DATA_SIZE 896 /* Enough to hold all architected 2.0 state */
771da177e4SLinus Torvalds
782929e738SHelge Deller	.section .bss
791da177e4SLinus Torvalds	.align 8
808e9e9844SHelge DellerENTRY(hpmc_pim_data)
811da177e4SLinus Torvalds	.block HPMC_PIM_DATA_SIZE
828e9e9844SHelge DellerEND(hpmc_pim_data)
831da177e4SLinus Torvalds
84dfcf753bSKyle McMartin	.text
851da177e4SLinus Torvalds
861da177e4SLinus Torvalds	.import intr_save, code
87*d5654e15SHelge Deller	.align 16
88f39cce65SHelge DellerENTRY_CFI(os_hpmc)
89ae16489eSKyle McMartin.os_hpmc:
901da177e4SLinus Torvalds
911da177e4SLinus Torvalds	/*
921da177e4SLinus Torvalds	 * registers modified:
931da177e4SLinus Torvalds	 *
941da177e4SLinus Torvalds	 *   Using callee saves registers without saving them.  The
951da177e4SLinus Torvalds	 *   original values are in the pim dump if we need them.
961da177e4SLinus Torvalds	 *
971da177e4SLinus Torvalds	 *   r2   (rp)  return pointer
981da177e4SLinus Torvalds	 *   r3   address of PDCE_PROC
991da177e4SLinus Torvalds	 *   r4   scratch
1001da177e4SLinus Torvalds	 *   r5   scratch
1011da177e4SLinus Torvalds	 *   r23  (arg3) procedure arg
1021da177e4SLinus Torvalds	 *   r24  (arg2) procedure arg
1031da177e4SLinus Torvalds	 *   r25  (arg1) procedure arg
1041da177e4SLinus Torvalds	 *   r26  (arg0) procedure arg
1051da177e4SLinus Torvalds	 *   r30  (sp)   stack pointer
1061da177e4SLinus Torvalds	 *
1071da177e4SLinus Torvalds	 * registers read:
1081da177e4SLinus Torvalds	 *
1091da177e4SLinus Torvalds	 *   r26  contains address of PDCE_PROC on entry
1101da177e4SLinus Torvalds	 *   r28  (ret0) return value from procedure
1111da177e4SLinus Torvalds	 */
1121da177e4SLinus Torvalds
1131da177e4SLinus Torvalds	copy    arg0, %r3       /* save address of PDCE_PROC */
1141da177e4SLinus Torvalds
1151da177e4SLinus Torvalds	/*
1161da177e4SLinus Torvalds	 *  disable nested HPMCs
1171da177e4SLinus Torvalds	 *
1181da177e4SLinus Torvalds	 * Increment os_hpmc checksum to invalidate it.
1191da177e4SLinus Torvalds	 * Do this before turning the PSW M bit off.
1201da177e4SLinus Torvalds	 */
1211da177e4SLinus Torvalds
1221da177e4SLinus Torvalds	mfctl   %cr14, %r4
1231da177e4SLinus Torvalds	ldw     52(%r4),%r5
1241da177e4SLinus Torvalds	addi    1,%r5,%r5
1251da177e4SLinus Torvalds	stw     %r5,52(%r4)
1261da177e4SLinus Torvalds
1271da177e4SLinus Torvalds	/* MP_FIXME: synchronize all processors. */
1281da177e4SLinus Torvalds
1291da177e4SLinus Torvalds	/* Setup stack pointer. */
1301da177e4SLinus Torvalds
1311da177e4SLinus Torvalds	load32	PA(hpmc_stack),sp
1321da177e4SLinus Torvalds
1331da177e4SLinus Torvalds	ldo     128(sp),sp /* leave room for arguments */
1341da177e4SLinus Torvalds
1351da177e4SLinus Torvalds	/*
1361da177e4SLinus Torvalds	 * Most PDC routines require that the M bit be off.
1371da177e4SLinus Torvalds	 * So turn on the Q bit and turn off the M bit.
1381da177e4SLinus Torvalds	 */
1391da177e4SLinus Torvalds
140f02e6c61SHelge Deller	ldi     PSW_SM_Q,%r4                   /* PSW Q on, PSW M off */
1411da177e4SLinus Torvalds	mtctl   %r4,ipsw
1421da177e4SLinus Torvalds	mtctl   %r0,pcsq
1431da177e4SLinus Torvalds	mtctl   %r0,pcsq
1441da177e4SLinus Torvalds	load32	PA(os_hpmc_1),%r4
1451da177e4SLinus Torvalds	mtctl   %r4,pcoq
1461da177e4SLinus Torvalds	ldo     4(%r4),%r4
1471da177e4SLinus Torvalds	mtctl   %r4,pcoq
1481da177e4SLinus Torvalds	rfi
1491da177e4SLinus Torvalds	nop
1501da177e4SLinus Torvalds
1511da177e4SLinus Torvaldsos_hpmc_1:
1521da177e4SLinus Torvalds
1531da177e4SLinus Torvalds	/* Call PDC_PIM to get HPMC pim info */
1541da177e4SLinus Torvalds
1551da177e4SLinus Torvalds	/*
1561da177e4SLinus Torvalds	 * Note that on some newer boxes, PDC_PIM must be called
1571da177e4SLinus Torvalds	 * before PDC_IO if you want IO to be reset. PDC_PIM sets
1581da177e4SLinus Torvalds	 * a flag that PDC_IO examines.
1591da177e4SLinus Torvalds	 */
1601da177e4SLinus Torvalds
1611da177e4SLinus Torvalds	ldo     PDC_PIM(%r0), arg0
1621da177e4SLinus Torvalds	ldo     PDC_PIM_HPMC(%r0),arg1          /* Transfer HPMC data */
1631da177e4SLinus Torvalds	load32	PA(hpmc_raddr),arg2
1641da177e4SLinus Torvalds	load32	PA(hpmc_pim_data),arg3
1651da177e4SLinus Torvalds	load32	HPMC_PIM_DATA_SIZE,%r4
1661da177e4SLinus Torvalds	stw     %r4,-52(sp)
1671da177e4SLinus Torvalds
1681da177e4SLinus Torvalds	ldil    L%PA(os_hpmc_2), rp
1691da177e4SLinus Torvalds	bv      (r3)                            /* call pdce_proc */
1701da177e4SLinus Torvalds	ldo     R%PA(os_hpmc_2)(rp), rp
1711da177e4SLinus Torvalds
1721da177e4SLinus Torvaldsos_hpmc_2:
1731da177e4SLinus Torvalds	comib,<>  0,ret0, os_hpmc_fail
1741da177e4SLinus Torvalds
1751da177e4SLinus Torvalds	/* Reset IO by calling the hversion dependent PDC_IO routine */
1761da177e4SLinus Torvalds
1771da177e4SLinus Torvalds	ldo     PDC_IO(%r0),arg0
1781da177e4SLinus Torvalds	ldo     0(%r0),arg1                     /* log IO errors */
1791da177e4SLinus Torvalds	ldo     0(%r0),arg2                     /* reserved */
1801da177e4SLinus Torvalds	ldo     0(%r0),arg3                     /* reserved */
1811da177e4SLinus Torvalds	stw     %r0,-52(sp)                     /* reserved */
1821da177e4SLinus Torvalds
1831da177e4SLinus Torvalds	ldil    L%PA(os_hpmc_3),rp
1841da177e4SLinus Torvalds	bv      (%r3)                           /* call pdce_proc */
1851da177e4SLinus Torvalds	ldo     R%PA(os_hpmc_3)(rp),rp
1861da177e4SLinus Torvalds
1871da177e4SLinus Torvaldsos_hpmc_3:
1881da177e4SLinus Torvalds
1891da177e4SLinus Torvalds	/* FIXME? Check for errors from PDC_IO (-1 might be OK) */
1901da177e4SLinus Torvalds
1911da177e4SLinus Torvalds	/*
1921da177e4SLinus Torvalds	 * Initialize the IODC console device (HPA,SPA, path etc.
1931da177e4SLinus Torvalds	 * are stored on page 0.
1941da177e4SLinus Torvalds	 */
1951da177e4SLinus Torvalds
1961da177e4SLinus Torvalds	/*
1971da177e4SLinus Torvalds	 * Load IODC into hpmc_iodc_buf by calling PDC_IODC.
1981da177e4SLinus Torvalds	 * Note that PDC_IODC handles flushing the appropriate
1991da177e4SLinus Torvalds	 * data and instruction cache lines.
2001da177e4SLinus Torvalds	 */
2011da177e4SLinus Torvalds
2021da177e4SLinus Torvalds	ldo     PDC_IODC(%r0),arg0
2031da177e4SLinus Torvalds	ldo     PDC_IODC_READ(%r0),arg1
2041da177e4SLinus Torvalds	load32	PA(hpmc_raddr),arg2
2051da177e4SLinus Torvalds	ldw     BOOT_CONSOLE_HPA_OFFSET(%r0),arg3 /* console hpa */
2061da177e4SLinus Torvalds	ldo     PDC_IODC_RI_INIT(%r0),%r4
2071da177e4SLinus Torvalds	stw     %r4,-52(sp)
2081da177e4SLinus Torvalds	load32	PA(hpmc_iodc_buf),%r4
2091da177e4SLinus Torvalds	stw     %r4,-56(sp)
2101da177e4SLinus Torvalds	load32	HPMC_IODC_BUF_SIZE,%r4
2111da177e4SLinus Torvalds	stw     %r4,-60(sp)
2121da177e4SLinus Torvalds
2131da177e4SLinus Torvalds	ldil    L%PA(os_hpmc_4),rp
2141da177e4SLinus Torvalds	bv      (%r3)                            /* call pdce_proc */
2151da177e4SLinus Torvalds	ldo     R%PA(os_hpmc_4)(rp),rp
2161da177e4SLinus Torvalds
2171da177e4SLinus Torvaldsos_hpmc_4:
2181da177e4SLinus Torvalds	comib,<>  0,ret0,os_hpmc_fail
2191da177e4SLinus Torvalds
2201da177e4SLinus Torvalds	/* Call the entry init (just loaded by PDC_IODC) */
2211da177e4SLinus Torvalds
2221da177e4SLinus Torvalds	ldw     BOOT_CONSOLE_HPA_OFFSET(%r0),arg0  /* console hpa */
2231da177e4SLinus Torvalds	ldo     ENTRY_INIT_MOD_DEV(%r0), arg1
2241da177e4SLinus Torvalds	ldw     BOOT_CONSOLE_SPA_OFFSET(%r0),arg2  /* console spa */
2251da177e4SLinus Torvalds	depi    0,31,11,arg2                       /* clear bits 21-31    */
2261da177e4SLinus Torvalds	ldo     BOOT_CONSOLE_PATH_OFFSET(%r0),arg3 /* console path */
2271da177e4SLinus Torvalds	load32	PA(hpmc_raddr),%r4
2281da177e4SLinus Torvalds	stw     %r4, -52(sp)
2291da177e4SLinus Torvalds	stw     %r0, -56(sp)                    /* HV                  */
2301da177e4SLinus Torvalds	stw     %r0, -60(sp)                    /* HV                  */
2311da177e4SLinus Torvalds	stw     %r0, -64(sp)                    /* HV                  */
2321da177e4SLinus Torvalds	stw     %r0, -68(sp)                    /* lang, must be zero  */
2331da177e4SLinus Torvalds
2341da177e4SLinus Torvalds	load32	PA(hpmc_iodc_buf),%r5
2351da177e4SLinus Torvalds	ldil    L%PA(os_hpmc_5),rp
2361da177e4SLinus Torvalds	bv      (%r5)
2371da177e4SLinus Torvalds	ldo     R%PA(os_hpmc_5)(rp),rp
2381da177e4SLinus Torvalds
2391da177e4SLinus Torvaldsos_hpmc_5:
2401da177e4SLinus Torvalds	comib,<>  0,ret0,os_hpmc_fail
2411da177e4SLinus Torvalds
2421da177e4SLinus Torvalds	/* Prepare to call intr_save */
2431da177e4SLinus Torvalds
2441da177e4SLinus Torvalds	/*
2451da177e4SLinus Torvalds	 * Load kernel page directory (load into user also, since
2461da177e4SLinus Torvalds	 * we don't intend to ever return to user land anyway)
2471da177e4SLinus Torvalds	 */
2481da177e4SLinus Torvalds
2491da177e4SLinus Torvalds	load32		PA(swapper_pg_dir),%r4
2501da177e4SLinus Torvalds	mtctl		%r4,%cr24	/* Initialize kernel root pointer */
2511da177e4SLinus Torvalds	mtctl		%r4,%cr25	/* Initialize user root pointer */
2521da177e4SLinus Torvalds
2531da177e4SLinus Torvalds	/* Clear sr4-sr7 */
2541da177e4SLinus Torvalds
2551da177e4SLinus Torvalds	mtsp	%r0, %sr4
2561da177e4SLinus Torvalds	mtsp	%r0, %sr5
2571da177e4SLinus Torvalds	mtsp	%r0, %sr6
2581da177e4SLinus Torvalds	mtsp	%r0, %sr7
2591da177e4SLinus Torvalds
2601da177e4SLinus Torvalds	tovirt_r1 %r30      /* make sp virtual */
2611da177e4SLinus Torvalds
262f02e6c61SHelge Deller	rsm     PSW_SM_Q,%r0           /* Clear Q bit */
2631da177e4SLinus Torvalds	ldi     1,%r8       /* Set trap code to "1" for HPMC */
2641da177e4SLinus Torvalds	load32	PA(intr_save),%r1
2651da177e4SLinus Torvalds	be      0(%sr7,%r1)
2661da177e4SLinus Torvalds	nop
2671da177e4SLinus Torvalds
2681da177e4SLinus Torvaldsos_hpmc_fail:
2691da177e4SLinus Torvalds
2701da177e4SLinus Torvalds	/*
2711da177e4SLinus Torvalds	 * Reset the system
2721da177e4SLinus Torvalds	 *
2731da177e4SLinus Torvalds	 * Some systems may lockup from a broadcast reset, so try the
2741da177e4SLinus Torvalds	 * hversion PDC_BROADCAST_RESET() first.
2751da177e4SLinus Torvalds	 * MP_FIXME: reset all processors if more than one central bus.
2761da177e4SLinus Torvalds	 */
2771da177e4SLinus Torvalds
2781da177e4SLinus Torvalds	/* PDC_BROADCAST_RESET() */
2791da177e4SLinus Torvalds
2801da177e4SLinus Torvalds	ldo     PDC_BROADCAST_RESET(%r0),arg0
2811da177e4SLinus Torvalds	ldo     0(%r0),arg1                     /* do reset */
2821da177e4SLinus Torvalds
2831da177e4SLinus Torvalds	ldil    L%PA(os_hpmc_6),rp
2841da177e4SLinus Torvalds	bv      (%r3)                           /* call pdce_proc */
2851da177e4SLinus Torvalds	ldo     R%PA(os_hpmc_6)(rp),rp
2861da177e4SLinus Torvalds
2871da177e4SLinus Torvaldsos_hpmc_6:
2881da177e4SLinus Torvalds
2891da177e4SLinus Torvalds	/*
2901da177e4SLinus Torvalds	 * possible return values:
2911da177e4SLinus Torvalds	 *  -1  non-existent procedure
2921da177e4SLinus Torvalds	 *  -2  non-existent option
2931da177e4SLinus Torvalds	 *  -16 unaligned stack
2941da177e4SLinus Torvalds	 *
2951da177e4SLinus Torvalds	 * If call returned, do a broadcast reset.
2961da177e4SLinus Torvalds	 */
2971da177e4SLinus Torvalds
2981da177e4SLinus Torvalds	ldil    L%0xfffc0000,%r4        /* IO_BROADCAST */
2991da177e4SLinus Torvalds	ldo     5(%r0),%r5
3001da177e4SLinus Torvalds	stw     %r5,48(%r4)             /*  CMD_RESET to IO_COMMAND offset */
3011da177e4SLinus Torvalds
3021da177e4SLinus Torvalds	b .
3031da177e4SLinus Torvalds	nop
304*d5654e15SHelge Deller	.align 16	/* make function length multiple of 16 bytes */
305f39cce65SHelge DellerENDPROC_CFI(os_hpmc)
306ae16489eSKyle McMartin.os_hpmc_end:
3072929e738SHelge Deller
3082929e738SHelge Deller
3092929e738SHelge Deller	__INITRODATA
310*d5654e15SHelge Deller.globl os_hpmc_size
3110ed9d3deSHelge Deller	.align 4
312*d5654e15SHelge Deller	.type   os_hpmc_size, @object
313*d5654e15SHelge Deller	.size   os_hpmc_size, 4
314ae16489eSKyle McMartinos_hpmc_size:
315ae16489eSKyle McMartin	.word .os_hpmc_end-.os_hpmc
316