summaryrefslogtreecommitdiffstats
path: root/private/ntos/nthals/halr98mp/mips/r98dspt.c
blob: 3c89949ecdb7cf467ae0f0194b0b307810caa1bf (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
#ident	"@(#) NEC r98dspt.c 1.14 95/03/17 11:55:28"
/*++

Copyright (c) 1994 Kobe NEC Software

Module Name:

    r98dspt.c

Abstract:

    This module implements the interrupt dispatch routines for R98

Author:



Environment:

    Kernel mode

Revision History:


--*/

/*
 ***********************************************************************
 *
 *      S001    7/7            T.Samezima
 *
 *      Chg	all alteration Int0-2 dispach routine
 *
 *	Del	move some define in r98def.h
 *
 ***********************************************************************
 *
 *      S002    8/22            T.Samezima on SNES
 *
 *	Add	Buffer for register save when unknown interrupt 
 *		Count up at loop counter
 *
 *	Chg	Modify loop logic
 *
 ***********************************************************************
 *
 *      S003    9/30            T.Samezima
 *
 *	Bug	define miss on Int1 dispatch table.
 *
 *      S004    '94.10/14            T.Samezima
 *	Chg	Display IPR and iRSF register on bugcheck
 *
 *      S005    '94.11/8            T.Samezima
 *	Del	Delete call of KeBugCheck. because of wrong interrupt ocure 
 *		of LR4360 bug
 *
 *	S006	'94.11/21	T.Samezima
 *	Chg	Change size of dummy read
 *
 *	S007	'94.12/28	T.Samezima
 *	Add	interrupt clear Broadcast in Unknown interrupt
 *
 *	S009	'95.01/11	T.Samezima
 *	Add	Dummy single read on EIF interrupt.
 *
 *	S00a	'95.03/13	T.Samezima
 *	Del	PIO interrupt check.
 *	Add	LR4360 error check.
 *		check dummy single read
 *
 */

#include "halp.h"
//#include "halmips.h"
#include "bugcodes.h"

/* Start S001 */
//
// Define table in use interrupt dispatch routine
//
#define INT2_DATA_TABLE_SIZE 5
#define INT1_DATA_TABLE_SIZE 6

enum _INT_DISP_TABLE {
    iRSF_BIT=0,
    IPR_BIT,
    IDT_VECTOR,
    DUMMY_READ_ADDR,
    DUMMY_READ_SIZE,
    NA_CODE
    };

typedef struct _DISPATCH_DATA_TABLE {
    ULONG IrsfMask;
    ULONG IprMask;
    ULONG IdtVector;
    ULONG DummyReadAddr;
    ULONG DummyReadSize;
    ULONG NaCode;
} DISPATCH_DATA_TABLE, *PDISPATCH_DATA_TABLE;

DISPATCH_DATA_TABLE HalpInt2DispatchDataTable[] = {
    {iRSF_KBMS_BIT,  IPR_KB_MS_BIT_LOW,   KBMS_VECTOR,
	KBMS_DUMMY_READ_ADDR,  1, NACODE_KB_MS},
//    {iRSF_PIO_BIT,   IPR_FDC_PIO_BIT_LOW, PIO_VECTOR,
//	PIO_DUMMY_READ_ADDR,   1, NACODE_FDC_PIO},	// S00a
    {iRSF_LR_ERR_BIT,IPR_DMA_BIT_LOW,     LR_ERR_VECTOR,
	DMA_DUMMY_READ_ADDR,   4, NACODE_DMA},		// S00a
    {iRSF_FDC_BIT,   IPR_FDC_PIO_BIT_LOW, FDC_VECTOR,
	FDC_DUMMY_READ_ADDR,   1, NACODE_FDC_PIO},	// S00a
    {iRSF_SIO_BIT,   IPR_SIO_BIT_LOW,     SIO_VECTOR,
	SIO_DUMMY_READ_ADDR,   1, NACODE_SIO},
    {iRSF_DMA_BIT,   IPR_DMA_BIT_LOW,     DMA_VECTOR,
        DMA_DUMMY_READ_ADDR,   4, NACODE_DMA}
};

DISPATCH_DATA_TABLE HalpInt1DispatchDataTable[] = {
    {iRSF_EISA_BIT,  IPR_EISA_BIT_LOW,    EISA_DEVICE_VECTOR,
	EISA_DUMMY_READ_ADDR,  1, NACODE_EISA},
    {iRSF_SCSI1_BIT, IPR_SCSI_BIT_LOW,    SCSI1_VECTOR,
	SCSI1_DUMMY_READ_ADDR, 4, NACODE_SCSI},			// S006
    {iRSF_ETHER_BIT, IPR_ETHER_BIT_LOW,   ETHER_VECTOR,
	ETHER_DUMMY_READ_ADDR, 2, NACODE_ETHER},
    {iRSF_PCI_BIT,   IPR_PCI_BIT_LOW,     PCI_DEVICE_VECTOR,
	PCI_DUMMY_READ_ADDR,   4, NACODE_PCI},			// S003
    {iRSF_SCSI0_BIT, IPR_SCSI_BIT_LOW,    SCSI0_VECTOR,
	SCSI0_DUMMY_READ_ADDR, 4, NACODE_SCSI},			// S006, S00a
    {iRSF_ERRPCI_BIT,IPR_PCI_BIT_LOW,     PCI_ERR_VECTOR,
	PCI_DUMMY_READ_ADDR,   4, NACODE_PCI}			// S003
};

// DISPATCH_DATA_TABLE HalpInt0DispatchDataTable[];

enum _INT_TABLE_DATA{
    TABLE_SIZE=0,
    MKR_MASK,
    INT_LEVEL
    };

ULONG HalpIntData[3][3] = {
    {0,                    MKR_INT0_ENABLE_LOW, INT0_LEVEL},
    {INT1_DATA_TABLE_SIZE, MKR_INT1_ENABLE_LOW, INT1_LEVEL},
    {INT2_DATA_TABLE_SIZE, MKR_INT2_ENABLE_LOW, INT2_LEVEL}
};

//
// Define pointer of interrupt arbitration
//
ULONG HalpInt2ArbitrationPoint = 0;
ULONG HalpInt1ArbitrationPoint = 0;
ULONG HalpInt0ArbitrationPoint = 0;
/* End S001 */

#if DBG
//
// Register buffer
//

ULONG HalpUnknownCause = 0;	// S002
ULONG HalpUnknownIPRUpper = 0;
ULONG HalpUnknownIPRLower = 0;
ULONG HalpUnknownMKRUpper = 0;
ULONG HalpUnknownMKRLower = 0;
ULONG HalpUnknowniRRE = 0;	// S002
ULONG HalpUnknowniREN = 0;	// S002
ULONG HalpUnknowniRSF = 0;	// S002
ULONG HalpUnknownIprUpperBuf = 0;	// S002
ULONG HalpUnknownIprLowerBuf = 0;	// S002
ULONG HalpIoIntLoopCounter;	// S002

#endif

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

typedef BOOLEAN  (*PSECONDARY_DISPATCH)(
    PVOID InterruptRoutine
    );

typedef BOOLEAN  (*PTIMER_DISPATCH)(
    ULONG TrapFrame
    );


VOID
HalpUnknownInterrupt(
    IN ULONG IprUpper,
    IN ULONG IprLower
    )
/*++

Routine Description:

    This function is reset of unknown interrupt.

Argments:

    IprUpper (a0) - Supplies upper 32bit of result of "IPR & MKR" in present INT level.

    IprLower (a1) - Supplies lower 32bit of result of "IPR & MKR" in present INT level.


Return Value:

    None.

--*/
{
    ULONG i;

// Start S002
#if DBG
    HalpUnknownCause = HalpGetCause();

    HalpReadLargeRegister( (ULONG)( &(PMC_CONTROL1)->IPR ),
                          &HalpUnknownIPRUpper,
                          &HalpUnknownIPRLower
                         );

    HalpReadLargeRegister( (ULONG)( &(PMC_CONTROL1)->MKR ),
                          &HalpUnknownMKRUpper,
                          &HalpUnknownMKRLower
                         );

    HalpUnknownIprUpperBuf = IprUpper;
    HalpUnknownIprLowerBuf = IprLower;

    HalpUnknowniRRE = READ_REGISTER_ULONG( &( LR_CONTROL2 )->iRRE );
    HalpUnknowniREN = READ_REGISTER_ULONG( &( LR_CONTROL2 )->iREN );
    HalpUnknowniRSF = READ_REGISTER_ULONG( &( LR_CONTROL2 )->iRSF );

#if 0	// S005 vvv
    KeBugCheckEx(INTERRUPT_EXCEPTION_NOT_HANDLED,
		 IprUpper,
		 IprLower,
		 HalpUnknowniRSF,
		 HalpUnknowniRRE
		 ); // S004
#endif	// S005 ^^^

#endif
// End S002

    //
    // clear interrupt pending bit
    //

    HalpWriteLargeRegister( (ULONG)( &(PMC_CONTROL1)->IPRR ),
                           &IprUpper,
                           &IprLower
                          );
    // S007 vvv
    //
    // issue broadcast of unknown interrupt clear
    //

    if( IprLower != 0 ) {
	PDISPATCH_DATA_TABLE dataTable;
	ULONG tableSize;

	if( IprLower & MKR_INT2_ENABLE_LOW ) {
	    dataTable = HalpInt2DispatchDataTable;
	    tableSize = INT2_DATA_TABLE_SIZE;
	} else if( IprLower & MKR_INT1_ENABLE_LOW ) {	
	    dataTable = HalpInt1DispatchDataTable;
	    tableSize = INT1_DATA_TABLE_SIZE;
	}

	for( i=0; i<tableSize; i++) {
	    if( i == 1 )
		continue;
	    if( (IprLower & dataTable[i].IprMask) != 0 ) {
		WRITE_REGISTER_ULONG( (ULONG)( &(IOB_CONTROL)->AIMR ),
				     dataTable[i].NaCode );
	    }
	}
    }
    // S007 ^^^

    //
    // count up unknown interrupt 
    //

    for ( i=0 ; i < 32 ; i++ ) {
        HalpUnknownInterruptCount[i] += (IprUpper >> i) & 1;
        HalpUnknownInterruptCount[i+32] += (IprLower >> i) & 1;
    }
}

VOID
HalpEifDispatch(
    VOID
    )
/*++

Routine Description:

    This routine is enterd as the result of an eif interrupt.

Argments:

    None.

Return Value:

    None.

--*/
{
    ULONG pmcRegisterUpperPart;
    ULONG pmcRegisterLowerPart;
    ULONG pmcIPRRegisterUpperPart;
    ULONG pmcIPRRegisterLowerPart;
    ULONG zero=0;
    ULONG buffer;

    //
    // Get interrpt pending bit
    //

    HalpReadLargeRegister( (ULONG)( &(PMC_CONTROL1)->IPR ),
                          &pmcIPRRegisterUpperPart,
                          &pmcIPRRegisterLowerPart );
Loop:
    HalpReadLargeRegister( (ULONG)( &(PMC_CONTROL1)->MKR ),
                          &pmcRegisterUpperPart,
                          &pmcRegisterLowerPart );

    pmcRegisterUpperPart &= pmcIPRRegisterUpperPart;

    //
    // Check eif interrupt
    //

    buffer=pmcRegisterUpperPart & IPR_EIF_BIT_HIGH;

    if( buffer ){
	//
	// issue dummy single read
	//

	READ_REGISTER_ULONG( &( IOB_CONTROL )->EIFR.Long );
	READ_REGISTER_ULONG( &( IOB_CONTROL )->EIFR.Long );

	HalpHandleEif();

        HalpWriteLargeRegister( (ULONG)( &(PMC_CONTROL1)->IPRR ),
                               &buffer,
                               &zero );
    } else {
	HalpUnknownInterrupt( pmcIPRRegisterUpperPart & MKR_INT5_ENABLE_HIGH,
			     0 );
    }

    //
    // Check new interrupt
    //

    do {
	HalpReadLargeRegister( (ULONG)( &(PMC_CONTROL1)->IPR ),
			      &pmcIPRRegisterUpperPart,
			      &pmcIPRRegisterLowerPart );

        if( pmcIPRRegisterUpperPart & MKR_INT5_ENABLE_HIGH ){
            goto Loop;
        }
    } while( HalpGetCause() & (1 << (CAUSE_INT_PEND_BIT + EIF_LEVEL - 1)) );

    return;
}


VOID
HalpTimerScDispatch(
    IN ULONG TrapFrame
    )
/*++

Routine Description:

    This routine is enterd as the result of an timer interrupt.

Argments:

    TrapFrame - Supplies a pointer to a trap frame.

Return Value:

    None.

--*/
{
    ULONG pmcRegisterUpperPart;
    ULONG pmcRegisterLowerPart;
    ULONG pmcIPRRegisterUpperPart;
    ULONG pmcIPRRegisterLowerPart;
    ULONG zero=0;
    ULONG buffer;

    //
    // read IPR register
    //

    HalpReadLargeRegister( (ULONG)( &(PMC_CONTROL1)->IPR ),
                          &pmcIPRRegisterUpperPart,
                          &pmcIPRRegisterLowerPart );

    //
    // read MKR register
    //

Loop:
    HalpReadLargeRegister( (ULONG)( &(PMC_CONTROL1)->MKR ),
                          &pmcRegisterUpperPart,
                          &pmcRegisterLowerPart );

    pmcRegisterUpperPart &= pmcIPRRegisterUpperPart;
    
    //
    // check profile and clock interrupt
    //

    buffer=pmcRegisterUpperPart & IPR_PROFILE_BIT_HIGH;
    
    if( buffer ){
        HalpWriteLargeRegister( (ULONG)( &(PMC_CONTROL1)->IPRR ),
                               &buffer,
                               &zero );
        WRITE_REGISTER_ULONG( (ULONG)( &(PMC_CONTROL1)->TOVCT2.Long), 0x0 ); // S002

        ((PTIMER_DISPATCH) PCR->InterruptRoutine[PROFILE_VECTOR])(TrapFrame);
    } else {
        buffer=pmcRegisterUpperPart & IPR_CLOCK_BIT_HIGH;

        HalpWriteLargeRegister( (ULONG)( &(PMC_CONTROL1)->IPRR ),
                               &buffer,
                               &zero );
        WRITE_REGISTER_ULONG( (ULONG)( &(PMC_CONTROL1)->TOVCT1.Long), 0x0 ); // S002

        ((PTIMER_DISPATCH) PCR->InterruptRoutine[CLOCK_VECTOR])(TrapFrame);
    }
    
    //
    // Check new interrupt
    //

    do {
	HalpReadLargeRegister( (ULONG)( &(PMC_CONTROL1)->IPR ),
			      &pmcIPRRegisterUpperPart,
			      &pmcIPRRegisterLowerPart );

        if( pmcIPRRegisterUpperPart & MKR_INT3_ENABLE_HIGH ){
            goto Loop;
        }
    } while( HalpGetCause() & (1 << (CAUSE_INT_PEND_BIT + TIMER_LEVEL - 1)) );

    return;
}


/* Start S001 */
VOID
HalpIoIntDispatch(
    IN PDISPATCH_DATA_TABLE DataTable,
    IN OUT PULONG ArbitrationPoint,
    IN ULONG IntNo
    )
/*++

Routine Description:

    This routine is enterd as the result of an int0, int1, and int2 interrupt.

Argments:

    DataTable - Supplies a table useing judge interrupt factor.

    ArbitrationPoint - Supplies a start point of checking interrupt.

    IntNo - Supplies interrupt level.

Return Value:

    None.

--*/
{
    ULONG pmcRegisterUpperPart;
    ULONG pmcRegisterLowerPart;
    ULONG pmcIPRRegisterUpperPart;
    ULONG pmcIPRRegisterLowerPart;
    ULONG buffer;
    ULONG counter;
    ULONG position;
    ULONG zero=0;
    ULONG flag;

    // Start S002
#if DBG
    HalpIoIntLoopCounter = 0;
#endif
    // End S002

    //
    // Get interrpt pending bit
    //

    HalpReadLargeRegister( (ULONG)( &(PMC_CONTROL1)->IPR ),
                          &pmcIPRRegisterUpperPart,
                          &pmcIPRRegisterLowerPart );
//Loop:	// S002
    HalpReadLargeRegister( (ULONG)( &(PMC_CONTROL1)->MKR ),
                          &pmcRegisterUpperPart,
                          &pmcRegisterLowerPart );

    pmcRegisterLowerPart &= pmcIPRRegisterLowerPart;

Loop:	// S002
    buffer = READ_REGISTER_ULONG( (ULONG)(&(LR_CONTROL2)->iRSF) );

    (*ArbitrationPoint)++;

    flag = FALSE;

    for(counter = 0; counter < HalpIntData[IntNo][TABLE_SIZE] ; counter++){

	position = ( (*ArbitrationPoint + counter) % HalpIntData[IntNo][TABLE_SIZE]);

	//
	// check interrupt
	//

	if( ((buffer & DataTable[position].IrsfMask) == 0) ||
	   ((pmcRegisterLowerPart & DataTable[position].IprMask) == 0) ) {
	    continue;
	}

	flag = TRUE;

	HalpWriteLargeRegister( (ULONG)( &(PMC_CONTROL1)->IPRR ),
			       &zero,
			       &(DataTable[position].IprMask)
			       );
	((PSECONDARY_DISPATCH)PCR->InterruptRoutine[DataTable[position].IdtVector])(
		PCR->InterruptRoutine[DataTable[position].IdtVector]
                );

	// Start S002
        //
	// Clear Interrupt pending bit in iRSF register
        //

        WRITE_REGISTER_ULONG( (ULONG)(&(LR_CONTROL2)->iRSF),
                             DataTable[position].IrsfMask );
	// End  S002

	//
	// issue dummy single read
	//

	switch(DataTable[position].DummyReadSize){
	case 1:
	    READ_REGISTER_UCHAR( DataTable[position].DummyReadAddr );
	    READ_REGISTER_UCHAR( DataTable[position].DummyReadAddr );
	    break;
	case 2:
	    READ_REGISTER_USHORT( DataTable[position].DummyReadAddr );
	    READ_REGISTER_USHORT( DataTable[position].DummyReadAddr );
	    break;
	case 4:
	    READ_REGISTER_ULONG( DataTable[position].DummyReadAddr );
	    READ_REGISTER_ULONG( DataTable[position].DummyReadAddr );
	    break;
	}

	//
	// issue broadcast of interrupt clear
	//

        WRITE_REGISTER_ULONG( (ULONG)( &(IOB_CONTROL)->AIMR ),
                             DataTable[position].NaCode );

	break;	// S006
    }

    if (flag == FALSE){
	HalpUnknownInterrupt( 0,
		             pmcIPRRegisterLowerPart & HalpIntData[IntNo][MKR_MASK]
			     );
    }

    //
    // check new interrupt
    //

    do {
	HalpReadLargeRegister( (ULONG)( &(PMC_CONTROL1)->IPR ),
			      &pmcIPRRegisterUpperPart,
			      &pmcIPRRegisterLowerPart );

        // Start S002
        HalpReadLargeRegister( (ULONG)( &(PMC_CONTROL1)->MKR ),
                              &pmcRegisterUpperPart,
                              &pmcRegisterLowerPart );

        pmcRegisterLowerPart &= pmcIPRRegisterLowerPart;
        // end S002

        if( pmcIPRRegisterLowerPart & HalpIntData[IntNo][MKR_MASK] ){
            // Start S002
#if DBG
            HalpIoIntLoopCounter++;
#endif
            // End S002
            goto Loop;
        }
    } while(HalpGetCause() & (1 << CAUSE_INT_PEND_BIT+HalpIntData[IntNo][INT_LEVEL]-1));

    return;
}


VOID
HalpInt2Dispatch(
    VOID
    )
/*++

Routine Description:

    This routine is enterd as the result of an int2 interrupt.

Argments:

    None.

Return Value:

    None.

--*/
{
    HalpIoIntDispatch( HalpInt2DispatchDataTable,
		      &HalpInt2ArbitrationPoint,
		      2
		      );
}


VOID
HalpInt1Dispatch(
    VOID
    )
/*++

Routine Description:

    This routine is enterd as the result of an int1 interrupt.

Argments:

    None.

Return Value:

    None.

--*/
{
    HalpIoIntDispatch( HalpInt1DispatchDataTable,
		      &HalpInt1ArbitrationPoint,
		      1
		      );
}


VOID
HalpInt0Dispatch(
    VOID
    )
/*++

Routine Description:

    This routine is enterd as the result of an int0 interrupt.

Argments:

    None.

Return Value:

    None.

--*/
{
    HalpIoIntDispatch( (PDISPATCH_DATA_TABLE)NULL,
		      &HalpInt0ArbitrationPoint,
		      0
		      );
}
/* End S001 */