summaryrefslogtreecommitdiffstats
path: root/private/ntos/nthals/halalpha/ev4mchk.c
blob: 57fe29312e7a371293d6e7493c54e1e69274065a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
/*++

Copyright (c) 1994  Digital Equipment Corporation

Module Name:

    ev4mchk.c

Abstract:

    This module implements generalized machine check handling for
    platforms based on the DECchip 21064 (EV4) microprocessor.

Author:

    Joe Notarangelo 14-Feb-1994

Environment:

    Kernel mode only.

Revision History:

--*/

#include "halp.h"
#include "axp21064.h"
#include "stdio.h"


// 
// Declare the extern variable UncorrectableError declared in 
// inithal.c.
//
extern PERROR_FRAME PUncorrectableError;

VOID
HalpDisplayLogout21064( 
    IN PLOGOUT_FRAME_21064 LogoutFrame );

BOOLEAN
HalpPlatformMachineCheck( 
    IN PEXCEPTION_RECORD ExceptionRecord,
    IN PKEXCEPTION_FRAME ExceptionFrame,
    IN PKTRAP_FRAME      TrapFrame
    );

VOID
HalpUpdateMces(
    IN BOOLEAN ClearMachineCheck,
    IN BOOLEAN ClearCorrectableError
    ); 

//
// MAX_RETRYABLE_ERRORS is the number of times to retry machine checks before
// just giving up.
//

#define MAX_RETRYABLE_ERRORS    32

//
// System-wide controls for machine check reporting.
//

ProcessorCorrectableDisable = FALSE;
SystemCorrectableDisable = FALSE;
MachineCheckDisable = FALSE;

//
//jnfix - temporary counts
//

ULONG CorrectableErrors = 0;
ULONG RetryableErrors = 0;

VOID
HalpSetMachineCheckEnables(
    IN BOOLEAN DisableMachineChecks,
    IN BOOLEAN DisableProcessorCorrectables,
    IN BOOLEAN DisableSystemCorrectables
    )
/*++

Routine Description:

    This function sets the enables that define which machine check
    errors will be signaled by the processor.

    N.B. - The system has the capability to ignore all machine checks
           by indicating DisableMachineChecks = TRUE.  This is intended
           for debugging purposes on broken hardware.  If you disable
           this you will get no machine check no matter what error the
           system/processor detects.  Consider the consequences.

Arguments:

    DisableMachineChecks - Supplies a boolean which indicates if all
                           machine checks should be disabled and not
                           reported.  (see note above).

    DisableProcessorCorrectables - Supplies a boolean which indicates if
                                   processor correctable error reporting
                                   should be disabled.
    DisableSystemCorrectables - Supplies a boolean which indicates if
                                system correctable error reporting
                                should be disabled.

Return Value:

    None.

--*/
{


    ProcessorCorrectableDisable = DisableProcessorCorrectables;
    SystemCorrectableDisable = DisableSystemCorrectables;
    MachineCheckDisable = DisableMachineChecks;

    HalpUpdateMces( FALSE, FALSE );

    return;
}

VOID
HalpUpdateMces(
    IN BOOLEAN ClearMachineCheck,
    IN BOOLEAN ClearCorrectableError
    ) 
/*++

Routine Description:

    This function updates the state of the MCES internal processor
    register.

Arguments:

    ClearMachineCheck - Supplies a boolean that indicates if the machine
                        check indicator in the MCES should be cleared.

    ClearCorrectableError - Supplies a boolean that indicates if the 
                            correctable error indicators in the MCES should
                            be cleared.

Return Value:

    None.

--*/
{
    MCES Mces;

    Mces.MachineCheck = ClearMachineCheck;
    Mces.SystemCorrectable = ClearCorrectableError;
    Mces.ProcessorCorrectable = ClearCorrectableError;
    Mces.DisableProcessorCorrectable = ProcessorCorrectableDisable;
    Mces.DisableSystemCorrectable = SystemCorrectableDisable;
    Mces.DisableMachineChecks = MachineCheckDisable;

    HalpWriteMces( Mces );

}


BOOLEAN
HalMachineCheck (
    IN PEXCEPTION_RECORD ExceptionRecord,
    IN PKEXCEPTION_FRAME ExceptionFrame,
    IN PKTRAP_FRAME      TrapFrame
    )
/*++

Routine Description:

    This function fields machine check for 21064-based machines with
    parity memory protection.

Arguments:

    ExceptionRecord - Supplies a pointer to the exception record for the
                      machine check.  Included in the exception information
                      is the pointer to the logout frame.

    ExceptionFrame - Supplies a pointer to the kernel exception frame.

    TrapFrame - Supplies a pointer to the kernel trap frame.

Return Value:

    A value of TRUE is returned if the machine check has been
    handled by the HAL.  If it has been handled then execution may
    resume at the faulting address.  Otherwise, a value of FALSE
    is returned.

    N.B. - under some circumstances this routine may not return at
           all.

--*/

{

    PBIU_STAT_21064 BiuStat;
    BOOLEAN Handled;
    PLOGOUT_FRAME_21064 LogoutFrame;
    PMCHK_STATUS MachineCheckStatus;
    MCES Mces;
    BOOLEAN UnhandledPlatformError = FALSE;

    PUNCORRECTABLE_ERROR  uncorrerr = NULL;
    PPROCESSOR_EV4_UNCORRECTABLE  ev4uncorr = NULL;


    //
    // This is a parity machine.  If we receive a machine check it
    // is uncorrectable.  We will print the logout frame and then we
    // will bugcheck.
    //
    // However, we will first check that the machine check is not
    // marked as correctable.  If the machine check is correctable it uses
    // a differently formatted logout frame.  We will ignore the frame
    // for any machine check marked as correctable since it is an impossible
    // condition on a parity machine.
    // 

    MachineCheckStatus = 
                   (PMCHK_STATUS)&ExceptionRecord->ExceptionInformation[0];

    //
    // Handle any processor correctable errors.
    //

    if( MachineCheckStatus->Correctable == 1 ){

        //
        // Log the error.  
        //
        //jnfix - temporary code
        // simply assume this was a fill ecc correctable for now, print
        // a debug message periodically

        CORRECTABLE_FRAME_21064 *CorrectableFrame; 

        CorrectableFrame = 
            (CORRECTABLE_FRAME_21064 *)ExceptionRecord->ExceptionInformation[1];

        CorrectableErrors += 1;

#if (DBG) || (HALDBG)

        if( (CorrectableErrors % 32) == 0 ){
            DbgPrint( "Correctable errors = %d, Error Address = 0x%016Lx\n",
                      CorrectableFrame->FillAddr );
        }

#endif //DBG || HALDBG

        //
        // Acknowledge receipt of the correctable error by clearing
        // the error in the MCES register.
        //

        HalpUpdateMces( FALSE, TRUE );

        return TRUE;
    }

    //
    // Handle any retryable errors.
    //

    if( MachineCheckStatus->Retryable == 1 ){

        //
        // Increment the number of retryable machine checks.
        //

        RetryableErrors += 1;

#if (DBG) || (HALDBG)

        DbgPrint( "HAL Retryable Errors = %d\n", RetryableErrors );

#endif //DBG || HALDBG

        //
        // We'll retry MAX_RETRYABLE_ERRORS times and then give up.  We
        // do this to avoid infinite retry loops.
        //

        if( RetryableErrors <= MAX_RETRYABLE_ERRORS ){

            //
            // Acknowledge receipt of the retryable machine check.
            //

            HalpUpdateMces( TRUE, TRUE );

            return TRUE;
        }
    }

    //
    // Capture the logout frame pointer.
    //

    LogoutFrame = 
        (PLOGOUT_FRAME_21064)ExceptionRecord->ExceptionInformation[1];

    if(PUncorrectableError) {

        // 
        // Fill in the processor specific uncorrectable error frame
        //
        uncorrerr = (PUNCORRECTABLE_ERROR)
                        &PUncorrectableError->UncorrectableFrame;

        // 
        // first fill in some generic processor Information.
        // For the Current (Reporting) Processor.
        //
        HalpGetProcessorInfo(&uncorrerr->ReportingProcessor);
        uncorrerr->Flags.ProcessorInformationValid = 1;

        ev4uncorr = (PPROCESSOR_EV4_UNCORRECTABLE)
                        uncorrerr->RawProcessorInformation;
    }
    if(ev4uncorr) {
    
        ev4uncorr->BiuStat = ((ULONGLONG)LogoutFrame->BiuStat.all.HighPart << 
                                    32) | LogoutFrame->BiuStat.all.LowPart;

        ev4uncorr->BiuAddr = ((ULONGLONG)LogoutFrame->BiuAddr.HighPart << 32) | 
                                LogoutFrame->BiuAddr.LowPart;

        ev4uncorr->AboxCtl = ((ULONGLONG)LogoutFrame->AboxCtl.all.HighPart << 
                                    32) | LogoutFrame->AboxCtl.all.LowPart;

        ev4uncorr->BiuCtl = ((ULONGLONG)LogoutFrame->BiuCtl.HighPart << 32) |
                                LogoutFrame->BiuCtl.LowPart;

        ev4uncorr->CStat = ((ULONGLONG)LogoutFrame->DcStat.all.HighPart << 
                                    32) | LogoutFrame->DcStat.all.LowPart;

        ev4uncorr->BcTag = ((ULONGLONG)LogoutFrame->BcTag.all.HighPart << 
                                    32 ) | LogoutFrame->BcTag.all.LowPart;

        ev4uncorr->FillAddr = ((ULONGLONG)LogoutFrame->FillAddr.HighPart << 
                                    32) | LogoutFrame->FillAddr.LowPart;

        ev4uncorr->FillSyndrome = 
                    ((ULONGLONG)LogoutFrame->FillSyndrome.all.HighPart << 32) | 
                        LogoutFrame->FillSyndrome.all.LowPart;
    }

    //
    // Check for any hard errors that cannot be dismissed.
    // They are:
    //     Tag parity error
    //     Tag control parity error
    //     Multiple external errors
    //     Fill ECC error
    //     Fill parity error
    //     Multiple fill errors
    //

    BiuStat = (PBIU_STAT_21064)&LogoutFrame->BiuStat;

    if( (BiuStat->bits.BcTperr == 1)   ||
        (BiuStat->bits.BcTcperr == 1)  ||
        (BiuStat->bits.Fatal1 == 1)    ||
        (BiuStat->bits.FillEcc == 1)   ||
        (BiuStat->bits.FillDperr == 1) ||
        (BiuStat->bits.Fatal2 == 1) )     { 

        //
        // set the flag to indicate that the processor information is valid.
        //
        uncorrerr->Flags.ProcessorInformationValid =  1;
        uncorrerr->Flags.ErrorStringValid =  1;
        sprintf(uncorrerr->ErrorString,"Uncorrectable Error From " 
                                       "Processor Detected");

        //
        // A serious, uncorrectable error has occured, under no circumstances
        // can it be simply dismissed.
        //

        goto FatalError;

    }

//jnfix - dcache parity error checking for EV45?

    //
    // It is possible that the system has experienced a hard error and
    // that nonetheless the error is recoverable.  This is a system-specific
    // decision - allow it to be handled as such.
    //

    UnhandledPlatformError = TRUE;
    if( (Handled = HalpPlatformMachineCheck( 
                              ExceptionRecord, 
                              ExceptionFrame, 
                              TrapFrame )) == TRUE ){

        //
        // The system-specific code has handled the error.  Dismiss
        // the error and continue execution.
        //

        HalpUpdateMces( TRUE, TRUE );

        return TRUE;

    }

//
// The system has experienced a fatal error that cannot be corrected.
// Print any possible relevant information and crash the system.
//
// N.B. - In the future some of these fatal errors could be potential
//        recovered.  Example, a user process gets a fatal error on one
//        of its pages - we kill the user process, mark the page as bad
//        and continue executing.
//

FatalError:

    //
    // Begin the error output if this is a processor error.  If this is
    // an unhandled platform error than that code is responsible for
    // beginning the error output.
    //

    if( UnhandledPlatformError == FALSE ){

        //
        // Acquire ownership of the display.  This is done here in case we take
        // a machine check before the display has been taken away from the HAL.
        // When the HAL begins displaying strings after it has lost the
        // display ownership then the HAL will be careful not to scroll 
        // information off of the screen.
        //

        HalAcquireDisplayOwnership(NULL);

        //
        // Display the dreaded banner.
        //

        HalDisplayString( "\nFatal system hardware error.\n\n" );

    }

    //
    // Display the EV4 logout frame.
    //

    HalpDisplayLogout21064( LogoutFrame );

    //
    // Bugcheck to dump the rest of the machine state, this will help
    // if the machine check is software-related.
    //

    KeBugCheckEx( DATA_BUS_ERROR, 
                  (ULONG)MachineCheckStatus->Correctable,
                  (ULONG)MachineCheckStatus->Retryable,
                  (ULONG)0,
                  (ULONG)PUncorrectableError );

}

#define MAX_ERROR_STRING 100

VOID
HalpDisplayLogout21064 ( 
    IN PLOGOUT_FRAME_21064 LogoutFrame 
    )

/*++

Routine Description:

    This function displays the logout frame for a 21064.

Arguments:

    LogoutFrame - Supplies a pointer to the logout frame generated
                  by the 21064.
Return Value:

    None.

--*/

{
    UCHAR OutBuffer[ MAX_ERROR_STRING ];
    ULONG Index;
    PKPRCB Prcb;
    extern HalpLogicalToPhysicalProcessor[HAL_MAXIMUM_PROCESSOR+1];

    sprintf( OutBuffer, "BIU_STAT : %016Lx BIU_ADDR: %016Lx\n",
                       BIUSTAT_ALL_21064( LogoutFrame->BiuStat ),
                       LogoutFrame->BiuAddr.QuadPart );

    HalDisplayString( OutBuffer );

    sprintf( OutBuffer, "FILL_ADDR: %016Lx FILL_SYN: %016Lx\n",
                       LogoutFrame->FillAddr.QuadPart,
                       FILLSYNDROME_ALL_21064(LogoutFrame->FillSyndrome) );

    HalDisplayString( OutBuffer );

    sprintf( OutBuffer, "DC_STAT  : %016Lx BC_TAG  : %016Lx\n",
                       DCSTAT_ALL_21064(LogoutFrame->DcStat),
                       BCTAG_ALL_21064(LogoutFrame->BcTag) );

    HalDisplayString( OutBuffer );

    sprintf( OutBuffer, "ICCSR    : %016Lx ABOX_CTL: %016Lx EXC_SUM: %016Lx\n",
                       ICCSR_ALL_21064(LogoutFrame->Iccsr),
                       ABOXCTL_ALL_21064(LogoutFrame->AboxCtl),
                       EXCSUM_ALL_21064(LogoutFrame->ExcSum) );

    HalDisplayString( OutBuffer );

    sprintf( OutBuffer, "EXC_ADDR : %016Lx VA      : %016Lx MM_CSR : %016Lx\n",
                       LogoutFrame->ExcAddr.QuadPart,
                       LogoutFrame->Va.QuadPart,
                       MMCSR_ALL_21064(LogoutFrame->MmCsr) );

    HalDisplayString( OutBuffer );

    sprintf( OutBuffer, "HIRR     : %016Lx HIER    : %016Lx PS     : %016Lx\n",
                       IRR_ALL_21064(LogoutFrame->Hirr),
                       IER_ALL_21064(LogoutFrame->Hier),
                       PS_ALL_21064(LogoutFrame->Ps) );

    HalDisplayString( OutBuffer );

    sprintf( OutBuffer, "Waiting 15 seconds...\n");
    HalDisplayString( OutBuffer );

    for( Index=0; Index<1500; Index++)
        KeStallExecutionProcessor( 10000 ); // ~15 second delay

    sprintf( OutBuffer, "PAL_BASE : %016Lx  \n",
                       LogoutFrame->PalBase.QuadPart );
    HalDisplayString( OutBuffer );

    //
    // Print out interpretation of the error.
    //

    //
    // First print the processor on which we saw the error
    //

    Prcb = PCR->Prcb;
    sprintf( OutBuffer, "Error on processor number: %d\n", 
                    HalpLogicalToPhysicalProcessor[Prcb->Number] );
    HalDisplayString( OutBuffer );

    //
    // If we got a Data Cache Parity Error print a message on screen.
    //

    if( DCSTAT_DCPARITY_ERROR_21064(LogoutFrame->DcStat) ){
        sprintf( OutBuffer, "Data Cache Parity Error.\n" );
        HalDisplayString( OutBuffer );
    }

    //
    // Check for tag control parity error.
    //

    if( BIUSTAT_TCPERR_21064(LogoutFrame->BiuStat) == 1 ){

        sprintf( OutBuffer, 
        "Tag control parity error, Tag control: P: %1x D: %1x S: %1x V: %1x\n", 
            BCTAG_TAGCTLP_21064( LogoutFrame->BcTag ),
            BCTAG_TAGCTLD_21064( LogoutFrame->BcTag ),
            BCTAG_TAGCTLS_21064( LogoutFrame->BcTag ),
            BCTAG_TAGCTLV_21064( LogoutFrame->BcTag ) );

        HalDisplayString( OutBuffer );

    }

    //
    // Check for tag parity error.
    //

    if( BIUSTAT_TPERR_21064(LogoutFrame->BiuStat) == 1 ){

        sprintf( OutBuffer, 
            "Tag parity error, Tag: %x  Parity: %1x\n",
            BCTAG_TAG_21064(LogoutFrame->BcTag),
            BCTAG_TAGP_21064(LogoutFrame->BcTag) );

        HalDisplayString( OutBuffer );

    }

    //
    // Check for hard error.
    //

    if( BIUSTAT_HERR_21064(LogoutFrame->BiuStat) == 1 ){
    
        sprintf( OutBuffer, "Hard error acknowledge: BIU CMD: %x PA: %16Lx\n",
            BIUSTAT_CMD_21064(LogoutFrame->BiuStat), 
            LogoutFrame->BiuAddr.QuadPart );

        HalDisplayString( OutBuffer );

    }

    //
    // Check for soft error.
    //

    if( BIUSTAT_SERR_21064(LogoutFrame->BiuStat) == 1 ){
    
        sprintf( OutBuffer, "Soft error acknowledge: BIU CMD: %x PA: %16Lx\n",
            BIUSTAT_CMD_21064(LogoutFrame->BiuStat), 
            LogoutFrame->BiuAddr.QuadPart );

        HalDisplayString( OutBuffer );

    }


    //
    // Check for fill ECC errors.
    //

    if( BIUSTAT_FILLECC_21064(LogoutFrame->BiuStat) == 1 ){

        sprintf( OutBuffer, "ECC error: %s\n",
            (BIUSTAT_FILLIRD_21064(LogoutFrame->BiuStat) ? 
                "Icache Fill" : "Dcache Fill") ); 

        HalDisplayString( OutBuffer );

        sprintf( OutBuffer, 
            "PA: %16Lx Quadword: %x Longword0: %x  Longword1: %x\n",
            LogoutFrame->FillAddr.QuadPart,
            BIUSTAT_FILLQW_21064(LogoutFrame->BiuStat),
            FILLSYNDROME_LO_21064(LogoutFrame->FillSyndrome),
            FILLSYNDROME_HI_21064(LogoutFrame->FillSyndrome) );

        HalDisplayString( OutBuffer );

    }

    //
    // Check for fill Parity errors.
    //

    if( BIUSTAT_FILLDPERR_21064(LogoutFrame->BiuStat) == 1 ){

        sprintf( OutBuffer, "Parity error: %s\n",
            (BIUSTAT_FILLIRD_21064(LogoutFrame->BiuStat) ? 
                "Icache Fill" : "Dcache Fill") ); 

        HalDisplayString( OutBuffer );

        sprintf( OutBuffer,
            "PA: %16Lx Quadword: %x Longword0: %x  Longword1: %x\n",
            LogoutFrame->FillAddr.QuadPart,
            BIUSTAT_FILLQW_21064(LogoutFrame->BiuStat),
            FILLSYNDROME_LO_21064(LogoutFrame->FillSyndrome),
            FILLSYNDROME_HI_21064(LogoutFrame->FillSyndrome) );

        HalDisplayString( OutBuffer );

    }

    //
    // Check for multiple hard errors.
    //

    if( BIUSTAT_FATAL1_21064(LogoutFrame->BiuStat) == 1 ){

        HalDisplayString( "Multiple external/tag errors detected.\n" );

    }

    //
    // Check for multiple fill errors.
    //

    if( BIUSTAT_FATAL2_21064(LogoutFrame->BiuStat) == 1 ){

        HalDisplayString( "Multiple fill errors detected.\n" );

    }
    

    //
    // return to caller
    //

    return;
}