summaryrefslogtreecommitdiffstats
path: root/private/ntos/nthals/halr96b/mips/pcisup.c
blob: d46cc00e4e5ae0d89b0c692a0518cd0847414fdb (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
// #pragma comment(exestr, "@(#) r94apcisup.c 1.1 95/09/28 18:37:11 nec")
/*++

Copyright (c) 1990  Microsoft Corporation

Module Name:

    r94apisup.c

Abstract:

    The module provides the PCI bus support for R94A systems.

Author:


Revision History:

    L0001	1994.9.20	kbnes!kuriyama(A)
                -New module for R94A R4400 system
                -add	HalpAllocaltePCIAdapter()

    H0001	Tue Sep 20 22:58:03 JST 1994	kbnes!kishimoto
		-add	HalpEnablePCIInterrupt()
		-add	HalpDisablePCIInterrupt()
		-add	HalpPCIDispatch()
		-add	HalpPCIFatalError()

    H0002	Tue Oct  4 12:47:58 JST 1994	kbnes!kishimoto
		-modify	HalpPCIFatalError()
			display the appropriate PCI errors

    L0002	1994.10.13	kbnes!kuriyama(A)
                -add	HalpAllocaltePCIAdapter()
		        -add AdapterBaseVa set routine

    H0003	Fri Oct 14 14:54:40 JST 1994	kbnes!kishimoto
		-chg	use READ_REGISTER_DWORD to read 64-bit I/O register

    H0003	Mon Oct 17 14:36:57 JST 1994	kbnes!kishimoto
                -chg	Hal(p)EisaPCIXXX() rename to Hal(p)EisaXXX()
			XXX_EISA_PCI_XXX rename to XXX_EISA_XXX
			MAXIMUM_PCI_SLOT rename to R94A_PCI_SLOT

    H0004	Wed Oct 19 13:24:51 JST 1994	kbnes!kishimoto
                -chg	HalpPCIDispatch()
			The PCI-error check change up the order.

    H0005	Wed Oct 19 20:17:09 JST 1994	kbnes!kishimoto
		-add	substitute READ_REGISTER_BUFFER_UCHAR for
			READ_REGISTER_DWORD because of storm alpha-
			version cannot 64-bit access.

    L0006	Wed Oct 19 22:01:27 JST 1994	kbnes!kuriyama(A)
		-chg	HalpAllocatePCIAdapter()
		        del useChannel 
    			del channelNumber
    			del controllerNumber
    			del eisaSystem
			chg AdapterBaseVa value

    H0006	Tue Nov 22 22:10:00 1994	kbnes!kishimoto
		-del	delete _R94ABBM32_
			The limitation of 32bit bus-access is only applied
			under PCI-bus. I make a wrong application.

    H0007	Fri Jul 21 18:02:55 1995	kbnes!kishimoto
                -merge  source with J94C

--*/

#include "halp.h"
#include "eisa.h"

#if defined(_R94A_)

#include <stdio.h>

/* start H0000 */

//
// Define the context structure for use by the interrupt routine.
//

typedef BOOLEAN  (*PSECONDARY_DISPATCH)(
    PVOID InterruptRoutine
    );

VOID
HalpPCIFatalError(
    STORM_PCI_INTRRUPT_STATUS InterruptStatus
    );

/* end H0000 */

// start L0001
PADAPTER_OBJECT
HalpAllocatePCIAdapter(
    IN PDEVICE_DESCRIPTION DeviceDescriptor
    )
/*++

Routine Description:

    This function allocates an PCI adapter object according to the
    specification supplied in the device description.  The necessary device
    descriptor information is saved. If there is
    no existing adapter object for this channel then a new one is allocated.
    The saved information in the adapter object is used to set the various DMA
    modes when the channel is allocated or a map transfer is done.

Arguments:

    DeviceDescription - Supplies the description of the device which want to
        use the DMA adapter.

Return Value:

    Returns a pointer to the newly created adapter object or NULL if one
    cannot be created.

--*/

{
    PADAPTER_OBJECT adapterObject;
    PVOID adapterBaseVa;
    UCHAR adapterMode;

    //
    // All PCI Cards is Master card.
    //

    if (DeviceDescriptor->InterfaceType == PCIBus &&
        DeviceDescriptor->Master) {

    } else {

        return(NULL);
    }


/* start L0002 */
    //
    // Set the adapter base address to the Base address register and controller
    // number.
    //

    adapterBaseVa = ~0; /* L0006 */
/* end L0002 */

    //
    // Allocate an adapter object.
    //
		
        adapterObject = (PADAPTER_OBJECT) HalpAllocateAdapter(
	    0,
            adapterBaseVa,
            NULL
            );

    if (adapterObject == NULL) {
	
	return(NULL);
	
    }

    //
    // If the channel is not used then indicate the this is an PCI bus
    // master by setting the page port  and mode to cascade even though
    // it is not used.
    //

    adapterObject->PagePort = (PVOID) (~0x0);
    ((PDMA_EISA_MODE) &adapterMode)->RequestMode = CASCADE_REQUEST_MODE;
    return(adapterObject);

}
// end L0001

/* start H0001 */
VOID
HalpEnablePCIInterrupt (
    IN ULONG Vector
    )

/*++

Routine Description:

    This function enables the PCI bus specified PCI bus interrupt.
    PCI interrupts must be LevelSensitve. (PCI Spec. 2.2.6)

Arguments:

    Vector - Supplies the vector of the  interrupt that is enabled.

Return Value:

     None.

--*/

{

    ULONG    i;

    //
    // enable specified PCI bus interrupt.
    //

    i = READ_REGISTER_ULONG(
	&((PDMA_REGISTERS) DMA_VIRTUAL_BASE)->PCIInterruptEnable
        );

    WRITE_REGISTER_ULONG(
        &((PDMA_REGISTERS) DMA_VIRTUAL_BASE)->PCIInterruptEnable,
        (ULONG)( i | 1 << (Vector - PCI_VECTORS))
	);

    return;

}

VOID
HalpDisablePCIInterrupt (
    IN ULONG Vector
    )

/*++

Routine Description:

    This function Disables the PCI bus specified PCI bus interrupt.
    PCI interrupts must be LevelSensitve. (PCI Spec. 2.2.6)

Arguments:

    Vector - Supplies the vector of the PCI interrupt that is Disabled.

Return Value:

     None.

--*/

{

    ULONG    i;

    //
    // disable specified PCI bus interrupt.
    //

    i = READ_REGISTER_ULONG(
        &((PDMA_REGISTERS) DMA_VIRTUAL_BASE)->PCIInterruptEnable
        );

    WRITE_REGISTER_ULONG(
        &((PDMA_REGISTERS) DMA_VIRTUAL_BASE)->PCIInterruptEnable,
        (ULONG)( i & ~(1 << (Vector - PCI_VECTORS)))
        );

    return;

}


BOOLEAN
HalpPCIDispatch(
    IN PKINTERRUPT Interrupt,
    IN PVOID ServiceContext
    )
/*++

Routine Description:

    This routine is entered as the result of an interrupt being generated
    via the vector that is connected to an interrupt object that describes
    the PCI device interrupts. Its function is to call the third
    level interrupt dispatch routine and acknowledge the interrupt at the PCI
    controller.

    This service routine should be connected as follows:

       KeInitializeInterrupt(&Interrupt, HalpEisaDispatch,
                             EISA_VIRTUAL_BASE,
                             (PKSPIN_LOCK)NULL, EISA_DEVICE_LEVEL, EISA_DEVICE_LEVEL,
                             EISA_DEVICE_LEVEL, LevelSensitive, TRUE, 0, FALSE);
       KeConnectInterrupt(&Interrupt);

Arguments:

    Interrupt - Supplies a pointer to the interrupt object.

    ServiceContext - Supplies a pointer to the EISA interrupt acknowledge
        register.

Return Value:

    Returns the value returned from the third level routine.

--*/

{
    STORM_PCI_INTRRUPT_STATUS InterruptStatus;
    PKINTERRUPT interruptObject;
    PULONG dispatchCode;
    BOOLEAN returnValue;
    LONG Index;

    //
    // Read the interrupt vector.
    //

    *((PULONG) &InterruptStatus) = READ_REGISTER_ULONG(&((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->PCIInterruptStatus);

    //
    // BUGBUG
    //

    if (*((PULONG)&InterruptStatus) == 0) {

        //
        // There is not PCI interrupt.
        //
        
        return(FALSE);

    }

    //
    // Check if there are any non-recoverable PCI errors.
    // R94A has the following PCI error interrupts.
    //     Target abort interrupt
    //     Master abort interrupt
    //     Retry overflow interrupt
    //     SERR interrupt
    //     PERR interrupt
    //

    if (InterruptStatus.Perr == 1 ||
	InterruptStatus.Serr == 1 ||
	InterruptStatus.RetryOverflow == 1 ||
	InterruptStatus.MasterAbort == 1 ||
	InterruptStatus.TargetAbort == 1) {

	//
	// Display the appropriate PCI errors and bugcheck to dump the machine state.
	//

	HalpPCIFatalError(InterruptStatus);
	KeBugCheck(DATA_BUS_ERROR);

	//
	// The following code is never executed.
	//

	return(FALSE);
    }

    //
    // if INT[A.B.C.D] is active, then call the appropriate PCI drivers.
    //

    if ((*((PULONG)&InterruptStatus) & 0xf) != 0x0) {

	//
	// Dispatch to the secondary interrupt service routine.
	//      
	// N.B. R94A PCI interrupts flow :
	//
	//     system           slot1   slot2   slot3
	//      INT A  <----------+       +       +
	//      INT B  <------+   +       +       +
	//      INT C  <---+  |   +       +       +
	//    Reserved     |  |   +       +       +
	//                 |  +-----------+       |
	//                 +----------------------+
	//
	//
	//     PCI Interrupt Status Register Bit Definitions are:
	//
	//      [31:09]	Reserved
	//      [08]	Target abort interrupt status
	//      [07]	Master abort interrupt status
	//      [06]	Retry overflow interrupt status
	//      [05]	SERR interrupt status
	//      [04]	PERR interrupt status
	//      [03]	INTA interrupt status
	//      [02]	INTB interrupt status
	//      [01]	INTC interrupt status
	//      [00]	INTD interrupt status
	//

	for (Index = 3; Index > (3 - R94A_PCI_SLOT); Index--) {

	    //
	    // Check if the PCI interrupt occur.
	    //

	    if (((*((PULONG)&InterruptStatus) & 0xf) & ((ULONG)1 << Index)) != 0x0) {

                dispatchCode = (PULONG)(PCR->InterruptRoutine[PCI_VECTORS + Index]);
                interruptObject = CONTAINING_RECORD(dispatchCode,
                                                    KINTERRUPT,
                                                    DispatchCode);

                returnValue = ((PSECONDARY_DISPATCH)interruptObject->DispatchAddress)(interruptObject);

	    }

	}

    }

    return(returnValue);

}


VOID
HalpPCIFatalError(
    STORM_PCI_INTRRUPT_STATUS InterruptStatus
    )
/*++

Routine Description:

    This routine is entered as the result of an PCI fatal interrupt.
    This function displays appropriate PCI error information.

Arguments:

    InterruptStatus - PCI Interrupt Status value.

Return Value:

    None.

--*/

{

    UCHAR Buffer[100];
    UCHAR registerChar;
    ULONG registerLong;
    LARGE_INTEGER registerLarge;
    LARGE_INTEGER InvalidAddressValue;
    LARGE_INTEGER EccDiagnosticValue;

    HalpChangePanicFlag(16, 0x01, 0x10); // H0007

    HalDisplayString("\nFatal system error occured\n\n");

    //
    // Display the following register value.
    //
    //         register name            address    
    //
    //     Remode Failed Address      0x80000010  32bit
    //     Memory Failed Address      0x80000018  32bit
    //     Processor Invalid Address  0x80000020  33bit
    //     ECC Diagnostic             0x800001c8  64bit
    //     PCI Status                 0x80000606  16bit
    //     PCI Master Retry Timer     0x80000668  32bit
    //     

    //
    // Display the PCI fatal error information
    //

    if (InterruptStatus.Perr){
	HalDisplayString("PCI: Data parity error\n");
    }

    if (InterruptStatus.Serr){
	HalDisplayString("PCI: Address parity error\n");
    }

    if (InterruptStatus.RetryOverflow){
	HalDisplayString("PCI: Retry overflow\n");
    }

    if (InterruptStatus.MasterAbort){
	HalDisplayString("PCI: Master abort\n");
    }

    if (InterruptStatus.TargetAbort){
	HalDisplayString("PCI: Target abort\n");
    }

    // ! start
    // test test test : dump the  hardware registers of R94A
    // <cording memo>
    //     dump R94A all hardware-registers to buffer instead of display console
    //     registers that is only important for analasis dump are display to console
    //
    //     registers which display to console are:
    //         0x80000000 Configuration
    //         0x80000010 RemoteFailedAddress
    //         0x80000018 MemoryFailedAddress
    //         0x80000020 InvalidAddress
    //         0x80000078 NmiSource
    //         0x800000f8 InterruptEnable
    //         0x80000188 Errortype
    //         0x800001c8 EccDiagnostic
    //         0x80000530 PCIInterruptEnable
    //         0x80000538 PCIInterruptStatus
    //         0x80000606 PCIStatus
    //         0x800005bc TyphoonErrorStatus
    //         0x80000668 PCIMasterRetryTimer
    //         
    //         0x8000f000 I/O Device Interrupt Enable
    //

    READ_REGISTER_DWORD((PVOID)&((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->InvalidAddress, &InvalidAddressValue);
    READ_REGISTER_DWORD((PVOID)&((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->EccDiagnostic, &EccDiagnosticValue);

    sprintf(Buffer,
	    "Configuration       : %08x  RemoteFailedAddress : %08x\n",
	    READ_REGISTER_ULONG(&((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->Configuration.Long),
	    READ_REGISTER_ULONG(&((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->RemoteFailedAddress.Long));

    HalDisplayString((UCHAR *)Buffer);

    sprintf(Buffer,
	    "MemoryFailedAddress : %08x  InvalidAddress      :%01x%08x\n",
	    READ_REGISTER_ULONG(&((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->MemoryFailedAddress.Long),
	    (InvalidAddressValue.HighPart & 0x1), InvalidAddressValue.LowPart);

    HalDisplayString((UCHAR *)Buffer);

    sprintf(Buffer,
	    "NmiSource           : %08x  InterruptEnable     : %08x\n",
	    READ_REGISTER_ULONG(&((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->NmiSource.Long),
	    READ_REGISTER_ULONG(&((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->InterruptEnable.Long));

    HalDisplayString((UCHAR *)Buffer);

    sprintf(Buffer,
	    "Errortype           : %08x  EccDiagnostic(High) : %08x\n",
	    READ_REGISTER_ULONG(&((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->NmiSource.Long),
	    EccDiagnosticValue.HighPart);

    HalDisplayString((UCHAR *)Buffer);

    sprintf(Buffer,
	    "EccDiagnostic(Low)  : %08x  PCIInterruptEnable  : %08x\n",
	    EccDiagnosticValue.LowPart,
	    READ_REGISTER_ULONG(&((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->PCIInterruptEnable.Long));

    HalDisplayString((UCHAR *)Buffer);

    sprintf(Buffer,
	    "PCIInterruptStatus  : %08x  PCIStatus           : %08x\n",
	    READ_REGISTER_ULONG(&((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->PCIInterruptStatus.Long),
	    READ_REGISTER_USHORT(&((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->PCIStatus));

    HalDisplayString((UCHAR *)Buffer);

    sprintf(Buffer,
	    "TyphoonErrorStatus  : %08x  PCIMasterRetryTimer : %08x\n",
	    READ_REGISTER_ULONG(&((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->TyphoonErrorStatus),
	    READ_REGISTER_ULONG(&((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->PCIMasterRetryTimer));

    HalDisplayString((UCHAR *)Buffer);

    HalpGetStatusRegister(&registerLong);

    sprintf(Buffer,
	    "I/O DevIntEnable    : %08x  (CPU)StatusRegister : %08x\n",
	    READ_REGISTER_ULONG((PINTERRUPT_REGISTERS)INTERRUPT_VIRTUAL_BASE),
	    registerLong);

    HalDisplayString((UCHAR *)Buffer);


    //
    // ! end
    //

//    registerLong = READ_REGISTER_ULONG(&((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->RemoteFailedAddress.Long);
//    sprintf ((UCHAR *)Buffer, "RemodeFailedAddress = 0x%08x\n", registerLong);
//    HalDisplayString((UCHAR *)Buffer);

//    registerLong = READ_REGISTER_ULONG(&((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->MemoryFailedAddress.Long);
//    sprintf ((UCHAR *)Buffer, "MemoryFailedAddress = 0x%08x\n", registerLong);
//    HalDisplayString((UCHAR *)Buffer);

    //
    // memo
    //
    // (./ntos/inc/mips.h)
    // #define READ_REGISTER_BUFFER_UCHAR(x, y, z) {
    //     PUCHAR registerBuffer = x;
    //     PUCHAR readBuffer = y;
    //     ULONG readCount;
    //     for (readCount = z; readCount--; readBuffer++, registerBuffer++) {
    //         *readBuffer = *(volatile UCHAR * const)(registerBuffer);
    //         }
    //     }
    //

/* start H0003 */

//    READ_REGISTER_DWORD((PVOID)&((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->InvalidAddress, &registerLarge);
//    sprintf ((UCHAR *)Buffer, "InvalidAddress      =0x%01x%08x\n", registerLarge.HighPart & 0x1, registerLarge.LowPart);
//    HalDisplayString((UCHAR *)Buffer);

//    READ_REGISTER_DWORD((PVOID)&((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->EccDiagnostic, &registerLarge);
//    sprintf ((UCHAR *)Buffer, "EccDiagnostic(High) = 0x%08x\n", registerLarge.HighPart);
//    HalDisplayString((UCHAR *)Buffer);

//    sprintf ((UCHAR *)Buffer, "EccDiagnostic(Low)  = 0x%08x\n", registerLarge.LowPart);
//    HalDisplayString((UCHAR *)Buffer);

/* end H0003 */

//    registerChar = READ_REGISTER_UCHAR(&((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->PCIStatus);
//    sprintf ((UCHAR *)Buffer, "PCIStatus           = 0x%08x\n", registerChar);
//    HalDisplayString((UCHAR *)Buffer);

//    registerLong = READ_REGISTER_ULONG(&((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->PCIMasterRetryTimer);
//    sprintf ((UCHAR *)Buffer, "PCIMasterRetryTimer = 0x%08x\n", registerLong);
//    HalDisplayString((UCHAR *)Buffer);

    return;

}

/* end H0001 */
#endif // _R94A_