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