1*1da177e4SLinus Torvalds/* 2*1da177e4SLinus Torvalds * HPMC (High Priority Machine Check) handler. 3*1da177e4SLinus Torvalds * 4*1da177e4SLinus Torvalds * Copyright (C) 1999 Philipp Rumpf <prumpf@tux.org> 5*1da177e4SLinus Torvalds * Copyright (C) 1999 Hewlett-Packard (Frank Rowand) 6*1da177e4SLinus Torvalds * Copyright (C) 2000 Hewlett-Packard (John Marvin) 7*1da177e4SLinus Torvalds * 8*1da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 9*1da177e4SLinus Torvalds * it under the terms of the GNU General Public License as published by 10*1da177e4SLinus Torvalds * the Free Software Foundation; either version 2, or (at your option) 11*1da177e4SLinus Torvalds * any later version. 12*1da177e4SLinus Torvalds * 13*1da177e4SLinus Torvalds * This program is distributed in the hope that it will be useful, 14*1da177e4SLinus Torvalds * but WITHOUT ANY WARRANTY; without even the implied warranty of 15*1da177e4SLinus Torvalds * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*1da177e4SLinus Torvalds * GNU General Public License for more details. 17*1da177e4SLinus Torvalds * 18*1da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License 19*1da177e4SLinus Torvalds * along with this program; if not, write to the Free Software 20*1da177e4SLinus Torvalds * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21*1da177e4SLinus Torvalds */ 22*1da177e4SLinus Torvalds 23*1da177e4SLinus Torvalds 24*1da177e4SLinus Torvalds/* 25*1da177e4SLinus Torvalds * This HPMC handler retrieves the HPMC pim data, resets IO and 26*1da177e4SLinus Torvalds * returns to the default trap handler with code set to 1 (HPMC). 27*1da177e4SLinus Torvalds * The default trap handler calls handle interruption, which 28*1da177e4SLinus Torvalds * does a stack and register dump. This at least allows kernel 29*1da177e4SLinus Torvalds * developers to get back to C code in virtual mode, where they 30*1da177e4SLinus Torvalds * have the option to examine and print values from memory that 31*1da177e4SLinus Torvalds * would help in debugging an HPMC caused by a software bug. 32*1da177e4SLinus Torvalds * 33*1da177e4SLinus Torvalds * There is more to do here: 34*1da177e4SLinus Torvalds * 35*1da177e4SLinus Torvalds * 1) On MP systems we need to synchronize processors 36*1da177e4SLinus Torvalds * before calling pdc/iodc. 37*1da177e4SLinus Torvalds * 2) We should be checking the system state and not 38*1da177e4SLinus Torvalds * returning to the fault handler if things are really 39*1da177e4SLinus Torvalds * bad. 40*1da177e4SLinus Torvalds * 41*1da177e4SLinus Torvalds */ 42*1da177e4SLinus Torvalds 43*1da177e4SLinus Torvalds .level 1.1 44*1da177e4SLinus Torvalds .data 45*1da177e4SLinus Torvalds 46*1da177e4SLinus Torvalds#include <asm/assembly.h> 47*1da177e4SLinus Torvalds#include <asm/pdc.h> 48*1da177e4SLinus Torvalds 49*1da177e4SLinus Torvalds /* 50*1da177e4SLinus Torvalds * stack for os_hpmc, the HPMC handler. 51*1da177e4SLinus Torvalds * buffer for IODC procedures (for the HPMC handler). 52*1da177e4SLinus Torvalds * 53*1da177e4SLinus Torvalds * IODC requires 7K byte stack. That leaves 1K byte for os_hpmc. 54*1da177e4SLinus Torvalds */ 55*1da177e4SLinus Torvalds 56*1da177e4SLinus Torvalds .align 4096 57*1da177e4SLinus Torvaldshpmc_stack: 58*1da177e4SLinus Torvalds .block 16384 59*1da177e4SLinus Torvalds 60*1da177e4SLinus Torvalds#define HPMC_IODC_BUF_SIZE 0x8000 61*1da177e4SLinus Torvalds 62*1da177e4SLinus Torvalds .align 4096 63*1da177e4SLinus Torvaldshpmc_iodc_buf: 64*1da177e4SLinus Torvalds .block HPMC_IODC_BUF_SIZE 65*1da177e4SLinus Torvalds 66*1da177e4SLinus Torvalds .align 8 67*1da177e4SLinus Torvaldshpmc_raddr: 68*1da177e4SLinus Torvalds .block 128 69*1da177e4SLinus Torvalds 70*1da177e4SLinus Torvalds#define HPMC_PIM_DATA_SIZE 896 /* Enough to hold all architected 2.0 state */ 71*1da177e4SLinus Torvalds 72*1da177e4SLinus Torvalds .export hpmc_pim_data, data 73*1da177e4SLinus Torvalds .align 8 74*1da177e4SLinus Torvaldshpmc_pim_data: 75*1da177e4SLinus Torvalds .block HPMC_PIM_DATA_SIZE 76*1da177e4SLinus Torvalds 77*1da177e4SLinus Torvalds .text 78*1da177e4SLinus Torvalds 79*1da177e4SLinus Torvalds .export os_hpmc, code 80*1da177e4SLinus Torvalds .import intr_save, code 81*1da177e4SLinus Torvalds 82*1da177e4SLinus Torvaldsos_hpmc: 83*1da177e4SLinus Torvalds 84*1da177e4SLinus Torvalds /* 85*1da177e4SLinus Torvalds * registers modified: 86*1da177e4SLinus Torvalds * 87*1da177e4SLinus Torvalds * Using callee saves registers without saving them. The 88*1da177e4SLinus Torvalds * original values are in the pim dump if we need them. 89*1da177e4SLinus Torvalds * 90*1da177e4SLinus Torvalds * r2 (rp) return pointer 91*1da177e4SLinus Torvalds * r3 address of PDCE_PROC 92*1da177e4SLinus Torvalds * r4 scratch 93*1da177e4SLinus Torvalds * r5 scratch 94*1da177e4SLinus Torvalds * r23 (arg3) procedure arg 95*1da177e4SLinus Torvalds * r24 (arg2) procedure arg 96*1da177e4SLinus Torvalds * r25 (arg1) procedure arg 97*1da177e4SLinus Torvalds * r26 (arg0) procedure arg 98*1da177e4SLinus Torvalds * r30 (sp) stack pointer 99*1da177e4SLinus Torvalds * 100*1da177e4SLinus Torvalds * registers read: 101*1da177e4SLinus Torvalds * 102*1da177e4SLinus Torvalds * r26 contains address of PDCE_PROC on entry 103*1da177e4SLinus Torvalds * r28 (ret0) return value from procedure 104*1da177e4SLinus Torvalds */ 105*1da177e4SLinus Torvalds 106*1da177e4SLinus Torvalds copy arg0, %r3 /* save address of PDCE_PROC */ 107*1da177e4SLinus Torvalds 108*1da177e4SLinus Torvalds /* 109*1da177e4SLinus Torvalds * disable nested HPMCs 110*1da177e4SLinus Torvalds * 111*1da177e4SLinus Torvalds * Increment os_hpmc checksum to invalidate it. 112*1da177e4SLinus Torvalds * Do this before turning the PSW M bit off. 113*1da177e4SLinus Torvalds */ 114*1da177e4SLinus Torvalds 115*1da177e4SLinus Torvalds mfctl %cr14, %r4 116*1da177e4SLinus Torvalds ldw 52(%r4),%r5 117*1da177e4SLinus Torvalds addi 1,%r5,%r5 118*1da177e4SLinus Torvalds stw %r5,52(%r4) 119*1da177e4SLinus Torvalds 120*1da177e4SLinus Torvalds /* MP_FIXME: synchronize all processors. */ 121*1da177e4SLinus Torvalds 122*1da177e4SLinus Torvalds /* Setup stack pointer. */ 123*1da177e4SLinus Torvalds 124*1da177e4SLinus Torvalds load32 PA(hpmc_stack),sp 125*1da177e4SLinus Torvalds 126*1da177e4SLinus Torvalds ldo 128(sp),sp /* leave room for arguments */ 127*1da177e4SLinus Torvalds 128*1da177e4SLinus Torvalds /* 129*1da177e4SLinus Torvalds * Most PDC routines require that the M bit be off. 130*1da177e4SLinus Torvalds * So turn on the Q bit and turn off the M bit. 131*1da177e4SLinus Torvalds */ 132*1da177e4SLinus Torvalds 133*1da177e4SLinus Torvalds ldo 8(%r0),%r4 /* PSW Q on, PSW M off */ 134*1da177e4SLinus Torvalds mtctl %r4,ipsw 135*1da177e4SLinus Torvalds mtctl %r0,pcsq 136*1da177e4SLinus Torvalds mtctl %r0,pcsq 137*1da177e4SLinus Torvalds load32 PA(os_hpmc_1),%r4 138*1da177e4SLinus Torvalds mtctl %r4,pcoq 139*1da177e4SLinus Torvalds ldo 4(%r4),%r4 140*1da177e4SLinus Torvalds mtctl %r4,pcoq 141*1da177e4SLinus Torvalds rfi 142*1da177e4SLinus Torvalds nop 143*1da177e4SLinus Torvalds 144*1da177e4SLinus Torvaldsos_hpmc_1: 145*1da177e4SLinus Torvalds 146*1da177e4SLinus Torvalds /* Call PDC_PIM to get HPMC pim info */ 147*1da177e4SLinus Torvalds 148*1da177e4SLinus Torvalds /* 149*1da177e4SLinus Torvalds * Note that on some newer boxes, PDC_PIM must be called 150*1da177e4SLinus Torvalds * before PDC_IO if you want IO to be reset. PDC_PIM sets 151*1da177e4SLinus Torvalds * a flag that PDC_IO examines. 152*1da177e4SLinus Torvalds */ 153*1da177e4SLinus Torvalds 154*1da177e4SLinus Torvalds ldo PDC_PIM(%r0), arg0 155*1da177e4SLinus Torvalds ldo PDC_PIM_HPMC(%r0),arg1 /* Transfer HPMC data */ 156*1da177e4SLinus Torvalds load32 PA(hpmc_raddr),arg2 157*1da177e4SLinus Torvalds load32 PA(hpmc_pim_data),arg3 158*1da177e4SLinus Torvalds load32 HPMC_PIM_DATA_SIZE,%r4 159*1da177e4SLinus Torvalds stw %r4,-52(sp) 160*1da177e4SLinus Torvalds 161*1da177e4SLinus Torvalds ldil L%PA(os_hpmc_2), rp 162*1da177e4SLinus Torvalds bv (r3) /* call pdce_proc */ 163*1da177e4SLinus Torvalds ldo R%PA(os_hpmc_2)(rp), rp 164*1da177e4SLinus Torvalds 165*1da177e4SLinus Torvaldsos_hpmc_2: 166*1da177e4SLinus Torvalds comib,<> 0,ret0, os_hpmc_fail 167*1da177e4SLinus Torvalds 168*1da177e4SLinus Torvalds /* Reset IO by calling the hversion dependent PDC_IO routine */ 169*1da177e4SLinus Torvalds 170*1da177e4SLinus Torvalds ldo PDC_IO(%r0),arg0 171*1da177e4SLinus Torvalds ldo 0(%r0),arg1 /* log IO errors */ 172*1da177e4SLinus Torvalds ldo 0(%r0),arg2 /* reserved */ 173*1da177e4SLinus Torvalds ldo 0(%r0),arg3 /* reserved */ 174*1da177e4SLinus Torvalds stw %r0,-52(sp) /* reserved */ 175*1da177e4SLinus Torvalds 176*1da177e4SLinus Torvalds ldil L%PA(os_hpmc_3),rp 177*1da177e4SLinus Torvalds bv (%r3) /* call pdce_proc */ 178*1da177e4SLinus Torvalds ldo R%PA(os_hpmc_3)(rp),rp 179*1da177e4SLinus Torvalds 180*1da177e4SLinus Torvaldsos_hpmc_3: 181*1da177e4SLinus Torvalds 182*1da177e4SLinus Torvalds /* FIXME? Check for errors from PDC_IO (-1 might be OK) */ 183*1da177e4SLinus Torvalds 184*1da177e4SLinus Torvalds /* 185*1da177e4SLinus Torvalds * Initialize the IODC console device (HPA,SPA, path etc. 186*1da177e4SLinus Torvalds * are stored on page 0. 187*1da177e4SLinus Torvalds */ 188*1da177e4SLinus Torvalds 189*1da177e4SLinus Torvalds /* 190*1da177e4SLinus Torvalds * Load IODC into hpmc_iodc_buf by calling PDC_IODC. 191*1da177e4SLinus Torvalds * Note that PDC_IODC handles flushing the appropriate 192*1da177e4SLinus Torvalds * data and instruction cache lines. 193*1da177e4SLinus Torvalds */ 194*1da177e4SLinus Torvalds 195*1da177e4SLinus Torvalds ldo PDC_IODC(%r0),arg0 196*1da177e4SLinus Torvalds ldo PDC_IODC_READ(%r0),arg1 197*1da177e4SLinus Torvalds load32 PA(hpmc_raddr),arg2 198*1da177e4SLinus Torvalds ldw BOOT_CONSOLE_HPA_OFFSET(%r0),arg3 /* console hpa */ 199*1da177e4SLinus Torvalds ldo PDC_IODC_RI_INIT(%r0),%r4 200*1da177e4SLinus Torvalds stw %r4,-52(sp) 201*1da177e4SLinus Torvalds load32 PA(hpmc_iodc_buf),%r4 202*1da177e4SLinus Torvalds stw %r4,-56(sp) 203*1da177e4SLinus Torvalds load32 HPMC_IODC_BUF_SIZE,%r4 204*1da177e4SLinus Torvalds stw %r4,-60(sp) 205*1da177e4SLinus Torvalds 206*1da177e4SLinus Torvalds ldil L%PA(os_hpmc_4),rp 207*1da177e4SLinus Torvalds bv (%r3) /* call pdce_proc */ 208*1da177e4SLinus Torvalds ldo R%PA(os_hpmc_4)(rp),rp 209*1da177e4SLinus Torvalds 210*1da177e4SLinus Torvaldsos_hpmc_4: 211*1da177e4SLinus Torvalds comib,<> 0,ret0,os_hpmc_fail 212*1da177e4SLinus Torvalds 213*1da177e4SLinus Torvalds /* Call the entry init (just loaded by PDC_IODC) */ 214*1da177e4SLinus Torvalds 215*1da177e4SLinus Torvalds ldw BOOT_CONSOLE_HPA_OFFSET(%r0),arg0 /* console hpa */ 216*1da177e4SLinus Torvalds ldo ENTRY_INIT_MOD_DEV(%r0), arg1 217*1da177e4SLinus Torvalds ldw BOOT_CONSOLE_SPA_OFFSET(%r0),arg2 /* console spa */ 218*1da177e4SLinus Torvalds depi 0,31,11,arg2 /* clear bits 21-31 */ 219*1da177e4SLinus Torvalds ldo BOOT_CONSOLE_PATH_OFFSET(%r0),arg3 /* console path */ 220*1da177e4SLinus Torvalds load32 PA(hpmc_raddr),%r4 221*1da177e4SLinus Torvalds stw %r4, -52(sp) 222*1da177e4SLinus Torvalds stw %r0, -56(sp) /* HV */ 223*1da177e4SLinus Torvalds stw %r0, -60(sp) /* HV */ 224*1da177e4SLinus Torvalds stw %r0, -64(sp) /* HV */ 225*1da177e4SLinus Torvalds stw %r0, -68(sp) /* lang, must be zero */ 226*1da177e4SLinus Torvalds 227*1da177e4SLinus Torvalds load32 PA(hpmc_iodc_buf),%r5 228*1da177e4SLinus Torvalds ldil L%PA(os_hpmc_5),rp 229*1da177e4SLinus Torvalds bv (%r5) 230*1da177e4SLinus Torvalds ldo R%PA(os_hpmc_5)(rp),rp 231*1da177e4SLinus Torvalds 232*1da177e4SLinus Torvaldsos_hpmc_5: 233*1da177e4SLinus Torvalds comib,<> 0,ret0,os_hpmc_fail 234*1da177e4SLinus Torvalds 235*1da177e4SLinus Torvalds /* Prepare to call intr_save */ 236*1da177e4SLinus Torvalds 237*1da177e4SLinus Torvalds /* 238*1da177e4SLinus Torvalds * Load kernel page directory (load into user also, since 239*1da177e4SLinus Torvalds * we don't intend to ever return to user land anyway) 240*1da177e4SLinus Torvalds */ 241*1da177e4SLinus Torvalds 242*1da177e4SLinus Torvalds load32 PA(swapper_pg_dir),%r4 243*1da177e4SLinus Torvalds mtctl %r4,%cr24 /* Initialize kernel root pointer */ 244*1da177e4SLinus Torvalds mtctl %r4,%cr25 /* Initialize user root pointer */ 245*1da177e4SLinus Torvalds 246*1da177e4SLinus Torvalds /* Clear sr4-sr7 */ 247*1da177e4SLinus Torvalds 248*1da177e4SLinus Torvalds mtsp %r0, %sr4 249*1da177e4SLinus Torvalds mtsp %r0, %sr5 250*1da177e4SLinus Torvalds mtsp %r0, %sr6 251*1da177e4SLinus Torvalds mtsp %r0, %sr7 252*1da177e4SLinus Torvalds 253*1da177e4SLinus Torvalds tovirt_r1 %r30 /* make sp virtual */ 254*1da177e4SLinus Torvalds 255*1da177e4SLinus Torvalds rsm 8,%r0 /* Clear Q bit */ 256*1da177e4SLinus Torvalds ldi 1,%r8 /* Set trap code to "1" for HPMC */ 257*1da177e4SLinus Torvalds load32 PA(intr_save),%r1 258*1da177e4SLinus Torvalds be 0(%sr7,%r1) 259*1da177e4SLinus Torvalds nop 260*1da177e4SLinus Torvalds 261*1da177e4SLinus Torvaldsos_hpmc_fail: 262*1da177e4SLinus Torvalds 263*1da177e4SLinus Torvalds /* 264*1da177e4SLinus Torvalds * Reset the system 265*1da177e4SLinus Torvalds * 266*1da177e4SLinus Torvalds * Some systems may lockup from a broadcast reset, so try the 267*1da177e4SLinus Torvalds * hversion PDC_BROADCAST_RESET() first. 268*1da177e4SLinus Torvalds * MP_FIXME: reset all processors if more than one central bus. 269*1da177e4SLinus Torvalds */ 270*1da177e4SLinus Torvalds 271*1da177e4SLinus Torvalds /* PDC_BROADCAST_RESET() */ 272*1da177e4SLinus Torvalds 273*1da177e4SLinus Torvalds ldo PDC_BROADCAST_RESET(%r0),arg0 274*1da177e4SLinus Torvalds ldo 0(%r0),arg1 /* do reset */ 275*1da177e4SLinus Torvalds 276*1da177e4SLinus Torvalds ldil L%PA(os_hpmc_6),rp 277*1da177e4SLinus Torvalds bv (%r3) /* call pdce_proc */ 278*1da177e4SLinus Torvalds ldo R%PA(os_hpmc_6)(rp),rp 279*1da177e4SLinus Torvalds 280*1da177e4SLinus Torvaldsos_hpmc_6: 281*1da177e4SLinus Torvalds 282*1da177e4SLinus Torvalds /* 283*1da177e4SLinus Torvalds * possible return values: 284*1da177e4SLinus Torvalds * -1 non-existent procedure 285*1da177e4SLinus Torvalds * -2 non-existent option 286*1da177e4SLinus Torvalds * -16 unaligned stack 287*1da177e4SLinus Torvalds * 288*1da177e4SLinus Torvalds * If call returned, do a broadcast reset. 289*1da177e4SLinus Torvalds */ 290*1da177e4SLinus Torvalds 291*1da177e4SLinus Torvalds ldil L%0xfffc0000,%r4 /* IO_BROADCAST */ 292*1da177e4SLinus Torvalds ldo 5(%r0),%r5 293*1da177e4SLinus Torvalds stw %r5,48(%r4) /* CMD_RESET to IO_COMMAND offset */ 294*1da177e4SLinus Torvalds 295*1da177e4SLinus Torvalds b . 296*1da177e4SLinus Torvalds nop 297*1da177e4SLinus Torvalds 298*1da177e4SLinus Torvalds /* this label used to compute os_hpmc checksum */ 299*1da177e4SLinus Torvalds 300*1da177e4SLinus Torvalds .export os_hpmc_end, code 301*1da177e4SLinus Torvalds 302*1da177e4SLinus Torvaldsos_hpmc_end: 303*1da177e4SLinus Torvalds 304*1da177e4SLinus Torvalds nop 305