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
|
/*++
Copyright (c) 1993 NCR Corporation
Module Name:
ncrsus.c
Abstract:
Provides the interface to the NCR SUS.
Author:
Rick Ulmer (rick.ulmer@columbiasc.ncr.com) 8-Sep-1993
Revision History:
--*/
#include "halp.h"
#include "ncr.h"
#include "ncrcat.h"
#include "ncrsus.h"
#include "ncrarb.h"
PNST_SUS_LOG SUSErrorLogHeader;
PUCHAR SUSErrorLogData;
PUCHAR CurrentSUSErrorEntryPosition;
USHORT CurrentSUSErrorEntryBytesRemaining;
PKERNEL_SUS_MAILBOX SUSMailbox;
PPROCESSOR_BOARD_INFO SUSBoardInfo;
PCPU_INFO SUSCpuInfo;
extern ULONG NCRExistingProcessorMask;
extern ULONG NCRExistingDyadicProcessorMask;
extern ULONG NCRExistingQuadProcessorMask;
ULONG HalpGetCmosData (ULONG SourceLocation, ULONG SourceAddress,
PUCHAR Buffer, ULONG Length);
ULONG HalpSetCmosData (ULONG SourceLocation, ULONG SourceAddress,
PUCHAR Buffer, ULONG Length);
BOOLEAN HalpCheckSUSLogSanity();
VOID HalpWriteCheckSum(
PUCHAR CheckSumStart,
PUCHAR CheckSumEnd,
PUCHAR CheckSumLowByte,
PUCHAR CheckSumHighByte
);
ULONG NCRTranslateCMOSMask(ULONG);
VOID
HalpInitializeSUSInterface (
)
{
PHYSICAL_ADDRESS physical_log_address;
ULONG LowPart;
UCHAR data;
ULONG i;
//
// Get pointers to SUS Error Log
//
SUSErrorLogHeader = NULL;
SUSErrorLogData = NULL;
LowPart = 0;
HalpGetCmosData(1,SUS_LOG_PTR,
(PUCHAR)&LowPart,NST_LOG_PTR_SIZE);
SUSErrorLogHeader = (PNST_SUS_LOG)HalpMapPhysicalMemory(LowPart,
COMPUTE_PAGES_SPANNED(LowPart,sizeof(NST_SUS_LOG)));
if (SUSErrorLogHeader != NULL) {
LowPart += SUSErrorLogHeader->PhysicalLogBegin;
SUSErrorLogData = (PUCHAR)HalpMapPhysicalMemory(LowPart,
COMPUTE_PAGES_SPANNED(LowPart,SUSErrorLogHeader->PhysicalLogEnd));
if (SUSErrorLogData == NULL) {
// MmUnmapIoSpace(SUSErrorLogHeader,sizeof(NST_SUS_LOG));
SUSErrorLogHeader = NULL;
}
}
//
// Make sure SUS error log is OK
//
/*RMU
This is just during debug.......
if (SUSErrorLogHeader) {
SUSErrorLogHeader->FirstUnreadRecord = SUSErrorLogHeader->FirstValidRecord;
SUSErrorLogHeader->UnreadBytesInLog = SUSErrorLogHeader->ValidBytesInLog;
}
*/
if (!HalpCheckSUSLogSanity()) {
DBGMSG(("SUS Error log is corrputed......................\n"));
SUSErrorLogHeader = NULL;
SUSErrorLogData = NULL;
}
/*RMU debug phase */
//
// Get Pointer to SUS/Kernel mailbox
//
LowPart = 0;
HalpGetCmosData(1,SUS_MAILBOX_PTR,
(PUCHAR)&LowPart,4);
SUSMailbox = (PKERNEL_SUS_MAILBOX)HalpMapPhysicalMemory(LowPart,
COMPUTE_PAGES_SPANNED(LowPart,sizeof(KERNEL_SUS_MAILBOX)));
SUSMailbox->OSMailboxVersion = FIRST_PASS_INTERFACE;
SUSMailbox->OSFlags = OS_KNOWS_SYSINT;
//
// Get Pointer to the SUS board info struct.
//
LowPart = (ULONG)SUSMailbox->BoardData;
SUSBoardInfo = (PPROCESSOR_BOARD_INFO)HalpMapPhysicalMemory(LowPart,
COMPUTE_PAGES_SPANNED(LowPart,sizeof(PROCESSOR_BOARD_INFO)));
DBGMSG(("HalpInitializeSUSInterface: SUSMailbox = 0x%x\n", SUSMailbox));
DBGMSG(("HalpInitializeSUSInterface: SUSBoardInfo = 0x%x\n", SUSBoardInfo));
//
// Get Pointer to the SUS cpu info struct.
//
LowPart = (ULONG)SUSMailbox->Cpu_Data;
SUSCpuInfo = (PCPU_INFO)HalpMapPhysicalMemory(LowPart,
COMPUTE_PAGES_SPANNED(LowPart,sizeof(CPU_INFO)));
DBGMSG(("HalpInitializeSUSInterface: SUSCpuInfo = 0x%x\n", SUSCpuInfo));
//
// Now lets go look for all the processor in the system and fill in
// NCRExistingDyadicProcessorMask and NCRExistingQuadProcessorMask
//
for (i = 0; i < SUSCpuInfo->NumberOfCpus; i++ ) {
data = SUSCpuInfo->CpuData[i].CPU_HardwareId;
if ((data & 0xc0) == 0xc0) {
//
// this is a Quad processor
//
// convert the who_am_i into the proper mask
//
// format:
//
// 1100ccss
//
// cc = processor bits
// ss = slot bits
//
NCRExistingQuadProcessorMask |= (1<<((data & 0xf)>>2))<<(((data&3)<<2));
} else {
//
// this is a Dyadic processor
//
NCRExistingDyadicProcessorMask |= NCRTranslateCMOSMask(data);
}
}
DBGMSG(("HalpInitializeSUSInterface: Dyadic Mask = 0x%x, Quad Mask = 0x%x\n",
NCRExistingDyadicProcessorMask, NCRExistingQuadProcessorMask));
//
// Set firmware to perform a cold reset and not take a dump.
//
HalpGetCmosData(1,SUS_RESET_PTR,
(PUCHAR)&data,1);
data |= 0x01;
HalpSetCmosData(1,SUS_RESET_PTR,
(PUCHAR)&data,1);
HalpWriteCheckSum((PUCHAR)SUS_HIGH_AVAIL_XSUM_START,
(PUCHAR)SUS_HIGH_AVAIL_XSUM_END,
(PUCHAR)SUS_HIGH_AVAIL_XSUM_LOW,
(PUCHAR)SUS_HIGH_AVAIL_XSUM_HIGH);
}
VOID
HalpSUSLogError (
)
{
//
// This routine tells SUS to go do FRU analysis. After the FRU
// analysis the system will reboot
//
DBGMSG(("HalpSUSLogError has been called......\n"));
SUSMailbox->OSFlags |= OS_IN_PROGRESS;
SUSMailbox->MailboxOS = SYSINT_HANDSHAKE;
//
// Send interrupt from SP to DP
//
WRITE_PORT_UCHAR((PUCHAR)0xf820,(UCHAR)0x11);
}
BOOLEAN
HalpSUSSwNmi (
)
{
DBGMSG(("HalpSUSSwNmi has been called......\n"));
if (SUSMailbox->MailboxSUS == DUMP_BUTTON_INTERRUPT) {
SUSMailbox->MailboxOS = NO_COMMAND;
SUSMailbox->OSFlags |= OS_IN_PROGRESS;
KeStallExecutionProcessor(1000000); // give DP a chance 1 sec
SUSMailbox->MailboxOS = IGNORE_DUMP_BUTTON;
SUSMailbox->OSFlags &= ~OS_IN_PROGRESS;
while (SUSMailbox->MailboxSUS == DUMP_BUTTON_INTERRUPT) {
KeStallExecutionProcessor(1);
};
return TRUE;
}
return FALSE;
}
BOOLEAN
HalpCheckSUSLogSanity (
)
{
USHORT bytes_in_log;
PSUS_ERROR_RECORD_HEADER SUS_header;
PUCHAR next_write_record;
PUCHAR logical_log_end;
if (SUSErrorLogHeader == NULL) {
return FALSE;
}
next_write_record = ADDRESS_OF(NEXT_WRITE_RECORD);
logical_log_end = ADDRESS_OF(LOGICAL_LOG_END);
if( (FIRST_VALID_RECORD >= PHYS_LOG_END) ||
(FIRST_UNREAD_RECORD > PHYS_LOG_END) ||
(LOGICAL_LOG_END > PHYS_LOG_END) ||
(NEXT_WRITE_RECORD > PHYS_LOG_END) ||
(VALID_BYTES_IN_LOG > PHYS_LOG_END) ||
(UNREAD_BYTES_IN_LOG > PHYS_LOG_END) ||
(UNREAD_BYTES_IN_LOG > VALID_BYTES_IN_LOG) ||
(VALID_BYTES_IN_LOG > LOGICAL_LOG_END) ) {
return FALSE;
}
if (VALID_BYTES_IN_LOG == 0)
return TRUE;
//
// Make sure the VALID_BYTES_IN_LOG is correct and that the log can be
// traversed starting with the FIRST_VALID_RECORD.
//
for (bytes_in_log = 0,
SUS_header = (PSUS_ERROR_RECORD_HEADER)ADDRESS_OF(FIRST_VALID_RECORD);
bytes_in_log < VALID_BYTES_IN_LOG; ) {
if (SUS_header > (PSUS_ERROR_RECORD_HEADER)logical_log_end)
return FALSE;
if ((SUS_header == (PSUS_ERROR_RECORD_HEADER)logical_log_end))
SUS_header = (PSUS_ERROR_RECORD_HEADER)SUSErrorLogData;
if (SUS_header->RecordLength <= 0)
return FALSE;
if ((bytes_in_log += SUS_header->RecordLength) > VALID_BYTES_IN_LOG)
return FALSE;
SUS_header = (PSUS_ERROR_RECORD_HEADER)((ULONG)SUS_header +
(ULONG)SUS_header->RecordLength);
}
if( bytes_in_log != VALID_BYTES_IN_LOG )
return FALSE;
if (UNREAD_BYTES_IN_LOG == 0)
return TRUE;
//
// Make sure the UNREAD_BYTES_IN_LOG is correct and that the log can be
// traversed starting with the FIRST_UNREAD_RECORD.
//
for (bytes_in_log = 0,
SUS_header = (PSUS_ERROR_RECORD_HEADER)ADDRESS_OF(FIRST_UNREAD_RECORD);
bytes_in_log < UNREAD_BYTES_IN_LOG; ) {
if (SUS_header > (PSUS_ERROR_RECORD_HEADER)logical_log_end)
return FALSE;
if ((SUS_header == (PSUS_ERROR_RECORD_HEADER)logical_log_end))
SUS_header = (PSUS_ERROR_RECORD_HEADER)SUSErrorLogData;
if (SUS_header->RecordLength <= 0)
return FALSE;
if ((bytes_in_log += SUS_header->RecordLength) > UNREAD_BYTES_IN_LOG)
return FALSE;
SUS_header = (PSUS_ERROR_RECORD_HEADER)((ULONG)SUS_header +
(ULONG)SUS_header->RecordLength);
}
if( bytes_in_log != UNREAD_BYTES_IN_LOG )
return FALSE;
return TRUE;
}
LONG
HalGetSUSErrorLogEntry (
PUCHAR ErrorEntry
)
{
PSUS_ERROR_RECORD_HEADER SUS_header;
USHORT entry_length;
if ((SUSErrorLogHeader == NULL) || (SUSErrorLogData == NULL)) {
return -1;
}
if (UNREAD_BYTES_IN_LOG) {
SUS_header = (PSUS_ERROR_RECORD_HEADER)ADDRESS_OF(FIRST_UNREAD_RECORD);
entry_length = SUS_header->RecordLength;
if (entry_length > HAL_MAX_SUS_ENTRY_SIZE) {
entry_length = HAL_MAX_SUS_ENTRY_SIZE;
}
RtlMoveMemory(ErrorEntry,SUS_header,entry_length);
UNREAD_BYTES_IN_LOG -= SUS_header->RecordLength;
FIRST_UNREAD_RECORD += SUS_header->RecordLength;
if ((FIRST_UNREAD_RECORD == LOGICAL_LOG_END) &&
(UNREAD_BYTES_IN_LOG)) {
FIRST_UNREAD_RECORD = 0;
}
} else {
entry_length = 0;
}
return entry_length;
}
VOID
HalSetWatchDogPeriod (
ULONG Period
)
{
if (SUSMailbox) {
SUSMailbox->OSFlags |= UPDATING_WDPERIOD;
SUSMailbox->WatchDogPeriod = Period;
SUSMailbox->WatchDogCount = 0;
SUSMailbox->OSFlags &= ~UPDATING_WDPERIOD;
}
}
VOID
HalBumpWatchDogCount (
)
{
if (SUSMailbox) {
SUSMailbox->WatchDogCount++;
}
}
VOID
HalpBeginSUSErrorEntry (
ULONG EntryType,
ULONG EntrySize
)
{
USHORT record_length;
PSUS_ERROR_RECORD_HEADER SUS_header;
USHORT i;
//
// Make sure the log is in a good state.
//
if (!HalpCheckSUSLogSanity()) {
CurrentSUSErrorEntryPosition = NULL;
CurrentSUSErrorEntryBytesRemaining = 0;
return;
}
//
// Make sure the Error Entry is valid
//
if ((EntryType != NST_ErrorType) && (EntryType != ASCII_ErrorType)) {
return;
}
record_length = EntrySize + sizeof(SUS_ERROR_RECORD_HEADER);
//
// increate by 1 for the null terminator
//
record_length++;
//
// is it too big to fit?
//
if (record_length > PHYS_LOG_END)
return;
/* Check for fit before physical end of log */
/*
* if this record will NOT fit within physical end of log,
* it causes a wrap of the error log
* if the log is in a wrapped state, valid records at end of log will
* be lost
* Delete the valid bytes that are at the end of the log
* Point first valid to top of log
* if first unread will be lost in the wrap, unread records at the
* end of the log will be lost
* Delete the unread bytes that are at the end of the log
* Point first unread to top of log
* Set new logical end to where next record was to write
* Set next write record to the top of the log
*/
if ((record_length + NEXT_WRITE_RECORD) > PHYS_LOG_END) {
if (FIRST_VALID_RECORD >= NEXT_WRITE_RECORD) {
VALID_BYTES_IN_LOG -= LOGICAL_LOG_END - FIRST_VALID_RECORD;
FIRST_VALID_RECORD = 0;
}
if (FIRST_UNREAD_RECORD >= NEXT_WRITE_RECORD) {
UNREAD_BYTES_IN_LOG -= LOGICAL_LOG_END - FIRST_UNREAD_RECORD;
FIRST_UNREAD_RECORD = 0;
}
LOGICAL_LOG_END = NEXT_WRITE_RECORD;
NEXT_WRITE_RECORD = 0;
}
/* Check for overwriting currently unread records */
while(UNREAD_BYTES_IN_LOG && (NEXT_WRITE_RECORD <= FIRST_UNREAD_RECORD) &&
((record_length + NEXT_WRITE_RECORD) > FIRST_UNREAD_RECORD)) {
UNREAD_BYTES_IN_LOG -= RECORDLENGTH(ADDRESS_OF(FIRST_UNREAD_RECORD));
FIRST_UNREAD_RECORD += RECORDLENGTH(ADDRESS_OF(FIRST_UNREAD_RECORD));
if (FIRST_UNREAD_RECORD >= LOGICAL_LOG_END) {
FIRST_UNREAD_RECORD = 0;
}
}
/* Check for overwriting currently valid records */
while (VALID_BYTES_IN_LOG && (NEXT_WRITE_RECORD <= FIRST_VALID_RECORD)&&
((record_length + NEXT_WRITE_RECORD) > FIRST_VALID_RECORD)) {
VALID_BYTES_IN_LOG -= RECORDLENGTH(ADDRESS_OF(FIRST_VALID_RECORD));
FIRST_VALID_RECORD += RECORDLENGTH(ADDRESS_OF(FIRST_VALID_RECORD));
if (FIRST_VALID_RECORD >= LOGICAL_LOG_END) {
FIRST_VALID_RECORD = 0;
LOGICAL_LOG_END = VALID_BYTES_IN_LOG;
}
}
UNREAD_BYTES_IN_LOG += record_length;
VALID_BYTES_IN_LOG += record_length;
SUS_header = (PSUS_ERROR_RECORD_HEADER)ADDRESS_OF(NEXT_WRITE_RECORD);
RtlZeroMemory((PVOID)SUS_header, (ULONG)record_length);
SUS_header->RecordType = EntryType;
SUS_header->RecordLength = record_length;
CurrentSUSErrorEntryPosition = (PUCHAR)ADDRESS_OF(NEXT_WRITE_RECORD) +
sizeof(SUS_ERROR_RECORD_HEADER);
CurrentSUSErrorEntryBytesRemaining = EntrySize;
/*
* Adjust all of the offsets to include the new record.
*/
NEXT_WRITE_RECORD += record_length;
if (NEXT_WRITE_RECORD > LOGICAL_LOG_END)
LOGICAL_LOG_END = NEXT_WRITE_RECORD;
}
VOID
HalpWriteToSUSErrorEntry (
PUCHAR EntryData
)
{
USHORT entry_length;
USHORT i;
PUCHAR char_pointer;
if (CurrentSUSErrorEntryBytesRemaining == 0) {
return;
}
entry_length = 0;
char_pointer = EntryData;
while (*char_pointer) {
char_pointer++;
entry_length++;
}
if (entry_length == 0)
return;
if (entry_length > CurrentSUSErrorEntryBytesRemaining) {
entry_length = CurrentSUSErrorEntryBytesRemaining;
}
//
// Copy Entry segment into the Error Log
//
RtlMoveMemory(CurrentSUSErrorEntryPosition,EntryData,entry_length);
CurrentSUSErrorEntryBytesRemaining -= entry_length;
CurrentSUSErrorEntryPosition += entry_length;
}
VOID HalpWriteCheckSum(
PUCHAR CheckSumStart,
PUCHAR CheckSumEnd,
PUCHAR CheckSumLowByte,
PUCHAR CheckSumHighByte
)
{
USHORT check_sum = 0;
USHORT zero_sum;
PUCHAR address;
UCHAR data;
for (address = CheckSumStart; address <= CheckSumEnd; address++) {
HalpGetCmosData(1,(ULONG)address,
(PUCHAR)&data,1);
check_sum = check_sum + data;
}
zero_sum = 0 - check_sum;
HalpSetCmosData(1,SUS_HIGH_AVAIL_XSUM_LOW,
(PUCHAR)&zero_sum,2);
}
|