summaryrefslogtreecommitdiffstats
path: root/private/ntos/nthals/halr98mp/mips/xxinitnt.c
blob: ad3750771301aeaa130ff77131ff8d02b104565f (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
#ident	"@(#) NEC xxinitnt.c 1.18 95/03/17 11:59:37"
/*++

Copyright (c) 1991-1994  Microsoft Corporation

Module Name:

    xxinitnt.c

Abstract:


    This module implements the interrupt initialization for a MIPS R3000
    or R4000 system.

--*/

/*
 *	Original source: Build Number 1.612
 *
 *	Modify for R98(MIPS/R4400)
 *
 ***********************************************************************
 *
 * L001		94.03/22-5/13	T.Samezima
 *
 *	add	control of Eif interrupt.
 *		make table of change from iRRE bit number to NABus code.
 *		make table of arbitration table and arbitration pointer.
 *		make variable for access of registers.
 *		connect the timer interrupt service routine.
 *              clear unknown interrupt counter
 *
 *	del	only '#if defined(_DUO_)'
 *		'#if defined(_JAZZ_)' with content
 *		HalpCountInterrupt()
 *
 *	change	interrupt control
 *		various vector of interrupt service routine
 *
 ***********************************************************************
 *
 * S002		94.5/17		T.Samezima
 *
 *	del	Arbitration table
 *
 ***********************************************************************
 *
 * S003		94.6/10-14	T.Samezima
 *
 *	del	Compile err
 *
 ***********************************************************************
 *
 * S004		94.7/7		T.Samezima
 *
 *	Chg	Use UNKNOWN_COUNT_BUF_LEN to max 
 *		for HalpUnknownInterruptCount
 *
 ***********************************************************************
 *
 * S005		94.7/7		T.Samezima
 *
 *	Del	move interrupt arbitration pointer to r98dspt.c
 *
 ***********************************************************************
 *
 * S006		94.7/23		T.Samezima
 *
 *	Add	Enable EIF interrupt on SIC.
 *
 ***********************************************************************
 *
 * S007		94.8/22		T.Samezima on SNES
 *
 *	Chg	Register buffer size from USHORT to ULONG
 *		Value of set to MKSR register
 *		Condition change
 *
 *	Add	Clear interrupt pending bit on edge level interrupt
 *
 *	Del	Move EISA NMI enable logic to HalpCreateEisaStructure()
 *
 ***********************************************************************
 *
 * S008		94.9/5		T.Samezima
 *
 *	Add	Institute number of repeat for interrupt clear loop
 *
 ***********************************************************************
 *
 * S009		94.9/16		T.Samezima
 *
 *	Chg	Only CPU#0 on I/O Initerrupt clear
 *
 ***********************************************************************
 *
 * S00a		94.10/14		T.Samezima
 *
 *	Fix	Version Up at build807
 *		 -Move Int1 interrupt enable to allstart.c
 *
 * S00b		94.10/18		T.Samezima
 *	Chg	Enable interrupt on MKR register only exist device,
 *
 * S00c		94.12/06		T.Samezima
 *	Bug	Disable ECC 1bit error interrupt.
 *
 * S00d		94.12/06		T.Samezima
 *	Add	Disable NMI
 *
 * S00e		95.01/10		T.Samezima
 *	Add	Enable ECC 1bit error interrupt 
 *		Rewrite cycle start on ecc 1bit error
 *
 * S00f		95.01/24		T.Samezima
 *	Add	Disable rewrite cycle on ecc 1bit error
 *
 * S010		95.03/13		T.Samezima
 *	Add	Enable HW cache flush.
 *
 */

#include "halp.h"
#include "eisa.h" // S003


//
// Put all code for HAL initialization in the INIT section. It will be
// deallocated by memory management when phase 1 initialization is
// completed.
//

#if defined(ALLOC_PRAGMA)

#pragma alloc_text(INIT, HalpInitializeInterrupts)

#endif

//
// Define global data for builtin device interrupt enables.
//

ULONG HalpBuiltinInterruptEnable;	// S007

//
// Define the IRQL mask and level mapping table.
//
// These tables are transfered to the PCR and determine the priority of
// interrupts.
//
// N.B. The two software interrupt levels MUST be the lowest levels.
//

UCHAR HalpIrqlMask[] = {4, 5, 6, 6, 7, 7, 7, 7,  // 0000 - 0111 high 4-bits
                        8, 8, 8, 8, 8, 8, 8, 8,  // 1000 - 1111 high 4-bits
                        0, 1, 2, 2, 3, 3, 3, 3,  // 0000 - 0111 low 4-bits
                        4, 4, 4, 4, 4, 4, 4, 4}; // 1000 - 1111 low 4-bits

UCHAR HalpIrqlTable[] = {0xff,                   // IRQL 0
                         0xfe,                   // IRQL 1
                         0xfc,                   // IRQL 2
                         0xf8,                   // IRQL 3
                         0xf0,                   // IRQL 4
                         0xe0,                   // IRQL 5
                         0xc0,                   // IRQL 6
                         0x80,                   // IRQL 7
                         0x00};                  // IRQL 8

/* Start L001 */
//
// Define table of change from iRRE bit number to NABus code
//
ULONG HalpNaBusCodeTable[] = {0x8000, 0x0010,    // iRRE bit0,1
                              0x0006, 0x0000,    // iRRE bit2,3
                              0x0002, 0x0002,    // iRRE bit4,5
                              0x000a, 0x000a,    // iRRE bit6,7
                              0x0008, 0x000c,    // iRRE bit8,9
                              0x8000, 0x8000,    // iRRE bit10,11
                              0x8000, 0x8000,    // iRRE bit12,13
                              0x8000, 0x8000,    // iRRE bit14,15
                              0x8000, 0x0004,    // iRRE bit16,17
                              0x8000, 0x8000,    // iRRE bit18,19
                              0x8000, 0x8000,    // iRRE bit20,21
                              0x000c, 0x8000,    // iRRE bit22,23
                              0x8000, 0x8000,    // iRRE bit24,25
                              0x8000, 0x8000,    // iRRE bit26,27
                              0x8000, 0x8000,    // iRRE bit28,29
                              0x8000, 0x8000 };  // iRRE bit30,31

//
// Define table of order of interrupt arbitration
//

ULONG HalpUnknownInterruptCount[UNKNOWN_COUNT_BUF_LEN];	// S004

/* End L001*/


BOOLEAN
HalpInitializeInterrupts (
    VOID
    )

/*++

Routine Description:

    This function initializes interrupts for a Jazz or Duo MIPS system.

    N.B. This function is only called during phase 0 initialization.

Arguments:

    None.

Return Value:

    A value of TRUE is returned if the initialization is successfully
    completed. Otherwise a value of FALSE is returned.

--*/

{

    USHORT DataShort;
    ULONG DataLong;
    ULONG Index;
    PKPRCB Prcb;
    /* Start L001 */
    ULONG pmcRegisterAddr;
    ULONG pmcRegisterUpperPart;
    ULONG pmcRegisterLowerPart;
    ULONG bitCount;
    ULONG buffer;
    ULONG buffer2;	// S006
    UCHAR charBuffer;
    LONG repeatCounter;	// S008
    /* End L001 */

    //
    // Get the address of the processor control block for the current
    // processor.
    //

    Prcb = PCR->Prcb;

    //
    // Initialize the IRQL translation tables in the PCR. These tables are
    // used by the interrupt dispatcher to determine the new IRQL and the
    // mask value that is to be loaded into the PSR. They are also used by
    // the routines that raise and lower IRQL to load a new mask value into
    // the PSR.
    //

    for (Index = 0; Index < sizeof(HalpIrqlMask); Index += 1) {
        PCR->IrqlMask[Index] = HalpIrqlMask[Index];
    }

    for (Index = 0; Index < sizeof(HalpIrqlTable); Index += 1) {
        PCR->IrqlTable[Index] = HalpIrqlTable[Index];
    }

    /* Start L001 */
    //
    // All interrupt disables.
    //

    pmcRegisterAddr = (ULONG)( &(PMC_CONTROL1)->MKR );	// S003
    pmcRegisterUpperPart = MKR_DISABLE_ALL_INTERRUPT_HIGH;
    pmcRegisterLowerPart = MKR_DISABLE_ALL_INTERRUPT_LOW;
    HalpWriteLargeRegister( pmcRegisterAddr,
                            &pmcRegisterUpperPart,
                            &pmcRegisterLowerPart );

    //
    // If processor 0 is being initialized, then set all device
    // interrupt disables.
    //

    if (Prcb->Number == 0) {
        HalpBuiltinInterruptEnable = iREN_DISABLE_ALL_INTERRUPT;

        for (Index = 0; Index < UNKNOWN_COUNT_BUF_LEN; Index += 1) {	// S004
            HalpUnknownInterruptCount[Index] = 0;
        }
//    }	// S009
    /* End L001 */

        //
        // Disable individual device interrupts and make sure no device interrupts
        // are pending.
        //

        /* Start L001 */
        WRITE_REGISTER_ULONG( &( LR_CONTROL2 )->iREN,
                              HalpBuiltinInterruptEnable );

        WRITE_REGISTER_ULONG( &( IOB_CONTROL )->EIMR.Long,
                              EIMR_DISABLE_ALL_EIF );

        repeatCounter = 0;	// S008

        while( ((DataLong = READ_REGISTER_ULONG( &( LR_CONTROL2 )->iRRE) & iRRE_MASK) != 0) &&
	       (++repeatCounter < 16) ) { // S008
            for( bitCount = 0 ; bitCount <= 31 ; bitCount++ ) {
		if( (DataLong & ( 1 << bitCount )) != 0) {
    		    // Start S007
                    if( bitCount < 15 ){
                        WRITE_REGISTER_ULONG( &( LR_CONTROL2 )->iRSF,
                                             ( 1 << bitCount ) );
                    }
		    // End S007
		    WRITE_REGISTER_ULONG( &( IOB_CONTROL )->AIMR.Long,
    				      HalpNaBusCodeTable[bitCount] );
		}
	    }
	    WRITE_REGISTER_ULONG( &( LR_CONTROL2 )->iRSF,
			         iRSF_CLEAR_INTERRUPT );
	    pmcRegisterAddr = (ULONG)( &(PMC_CONTROL1)->IPRR );	// S003
	    pmcRegisterUpperPart = 0x0;
	    pmcRegisterLowerPart = 0xffffffff;
	    HalpWriteLargeRegister( pmcRegisterAddr,
			           &pmcRegisterUpperPart,
			           &pmcRegisterLowerPart );
        }
        /* End L001 */

        HalpBuiltinInterruptEnable |= 0x10; // S010
    
        //
        // If processor 0 is being initialized, then enable device interrupts.
        //

//    if (Prcb->Number == 0) { // S009
	/* Start L001 */
	//
	//  Enable INT0-1 interrupt on PMC
	//

        /* Start S003 */
	WRITE_REGISTER_ULONG( &( IOB_CONTROL )->AII0.Long,
			     AII_INIT_DATA );
	WRITE_REGISTER_ULONG( &( IOB_CONTROL )->AII1.Long,
			     AII_INIT_DATA );
	WRITE_REGISTER_ULONG( &( IOB_CONTROL )->AII2.Long,
			     AII_INIT_DATA );
	WRITE_REGISTER_ULONG( &( IOB_CONTROL )->AII3.Long,
			     AII_INIT_DATA );
        /* End S003 */

	pmcRegisterAddr = (ULONG)( &(PMC_CONTROL1)->MKR );	// S003
	HalpReadLargeRegister( pmcRegisterAddr,
			      &pmcRegisterUpperPart,
			      &pmcRegisterLowerPart );
	pmcRegisterLowerPart = ( pmcRegisterLowerPart
                                | MKR_INT0_DEVICE_ENABLE_LOW	// S00b
//				| MKR_INT1_DEVICE_ENABLE_LOW	// S00a, S00b
				| MKR_INT2_DEVICE_ENABLE_LOW	// S00b
				);	// S003
	HalpWriteLargeRegister( pmcRegisterAddr,
                               &pmcRegisterUpperPart,
                               &pmcRegisterLowerPart );

//        DataLong = READ_REGISTER_ULONG(&((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->InterruptEnable.Long);
//        DataLong |= ENABLE_DEVICE_INTERRUPTS;
//        WRITE_REGISTER_ULONG(&((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->InterruptEnable.Long,
//                             DataLong);
	/* End L001 */
    }

    /* Start L001 */
    //
    // Connect the eif interrupt to the eif interrupt routine
    //

    PCR->InterruptRoutine[EIF_LEVEL] = HalpEifDispatch;

    //
    // Enable the eif interrupt
    //

    pmcRegisterAddr = (ULONG)( &(PMC_CONTROL1)->MKR );	// S003
    HalpReadLargeRegister( pmcRegisterAddr,
			  &pmcRegisterUpperPart,
			  &pmcRegisterLowerPart );
    pmcRegisterUpperPart = ( pmcRegisterUpperPart | MKR_INT5_ENABLE_HIGH );
    pmcRegisterLowerPart = ( pmcRegisterLowerPart | MKR_INT5_ENABLE_LOW );
    HalpWriteLargeRegister( pmcRegisterAddr,
			   &pmcRegisterUpperPart,
			   &pmcRegisterLowerPart );

    buffer = READ_REGISTER_ULONG( &( PMC_CONTROL1 )->STSR.Long);
    buffer = (buffer | STSR_EIF_ENABLE);
#if defined(DISABLE_NMI) // S00d
    buffer = (buffer | STSR_NMI_DISABLE);
#endif
    WRITE_REGISTER_ULONG( &( PMC_CONTROL1 )->STSR.Long, buffer);

    WRITE_REGISTER_ULONG( &( PMC_CONTROL1 )->ERRMK.Long, ERRMK_EIF_ENABLE);

    WRITE_REGISTER_ULONG( &( IOB_CONTROL )->IEMR.Long, IEMR_ENABLE_ALL_EIF);

    WRITE_REGISTER_ULONG( &( IOB_CONTROL )->EIMR.Long, EIMR_ENABLE_ALL_EIF);

    /* Start S006 */
    buffer = READ_REGISTER_ULONG( &( IOB_CONTROL )->SCFR.Long );
    IOB_DUMMY_READ;

    if( (buffer & SCFR_SIC_SET0_CONNECT) == 0 ) {	// S007
	buffer2 = READ_REGISTER_ULONG( &(SIC_ERR_CONTROL_OR(SIC_NO0_OFFSET))->CKE0.Long );
	buffer2 &= CKE0_DISABLE_SBE;	// S00c
	buffer2 |= CKE0_ENABLE_ALL_EIF;
	WRITE_REGISTER_ULONG( &( SIC_ERR_CONTROL_OR(SIC_SET0_OFFSET) )->CKE0.Long,
			     buffer2
			     );
	// S00e vvv
	buffer2 = READ_REGISTER_ULONG( &(SIC_DATA_CONTROL_OR(SIC_NO0_OFFSET))->DPCM.Long );
	buffer2 &= DPCM_ENABLE_MASK;	// S00c
	WRITE_REGISTER_ULONG( &( SIC_DATA_CONTROL_OR(SIC_SET0_OFFSET) )->DPCM.Long,
			     buffer2
			     );

#if 0 // S00f
	WRITE_REGISTER_ULONG( &( SIC_ERR_CONTROL_OR(SIC_SET0_OFFSET) )->SECT.Long,
			     SECT_REWRITE_ENABLE
			     );
#endif
	// S00e ^^^

	WRITE_REGISTER_ULONG( &( SIC_ERR_CONTROL_OR(SIC_SET0_OFFSET) )->CKE1.Long,
			     CKE1_ENABLE_ALL_EIF
			     );
    }

    if( (buffer & SCFR_SIC_SET1_CONNECT) == 0 ) {	// S007
	buffer2 = READ_REGISTER_ULONG( &(SIC_ERR_CONTROL_OR(SIC_NO2_OFFSET))->CKE0.Long );
	buffer2 &= CKE0_DISABLE_SBE;	// S00c
	buffer2 |= CKE0_ENABLE_ALL_EIF;
	WRITE_REGISTER_ULONG( &( SIC_ERR_CONTROL_OR(SIC_SET1_OFFSET) )->CKE0.Long,
			     buffer2
			     );
	// S00e vvv
	buffer2 = READ_REGISTER_ULONG( &(SIC_DATA_CONTROL_OR(SIC_NO2_OFFSET))->DPCM.Long );
	buffer2 &= DPCM_ENABLE_MASK;	// S00c
	WRITE_REGISTER_ULONG( &( SIC_DATA_CONTROL_OR(SIC_SET1_OFFSET) )->DPCM.Long,
			     buffer2
			     );
#if 0 // S00f
	WRITE_REGISTER_ULONG( &( SIC_ERR_CONTROL_OR(SIC_SET1_OFFSET) )->SECT.Long,
			     SECT_REWRITE_ENABLE
			     );
#endif
	// S00e ^^^

	WRITE_REGISTER_ULONG( &( SIC_ERR_CONTROL_OR(SIC_SET1_OFFSET) )->CKE1.Long,
			     CKE1_ENABLE_ALL_EIF
			     );
    }
    /* End S006 */

    // S007

    //
    // If processor 0 is being initialized, then connect the interval timer
    // interrupt to the stall interrupt routine so the stall execution count
    // can be computed during phase 1 initialization. Otherwise, connect the
    // interval timer interrupt to the appropriate interrupt service routine
    // and set stall execution count from the computation made on processor
    // 0.
    //

    PCR->InterruptRoutine[TIMER_LEVEL] = HalpTimerDispatch;	// S003

    if (Prcb->Number == 0) {
        /* Start L001 */
        PCR->InterruptRoutine[CLOCK_VECTOR] = HalpStallInterrupt;
        /* End L001 */
    } else {
        /* Start L001 */
        PCR->InterruptRoutine[CLOCK_VECTOR] = HalpClockInterrupt1;
        /* End L001 */
        PCR->StallScaleFactor = HalpStallScaleFactor;
    }

    //
    // Initialize the interval timer to interrupt at the specified interval.
    //

    /* Start L001 */
    WRITE_REGISTER_ULONG( &( PMC_CONTROL1 )->TMSR1.Long, CLOCK_INTERVAL);

    //
    // Initialize the profile timer to interrupt at the default interval.
    //

    WRITE_REGISTER_ULONG( &( PMC_CONTROL1 )->TMSR2.Long,
			 DEFAULT_PROFILETIMER_COUNT);
    /* End L001 */

    //
    // Enable the interval timer interrupt on the current processor.
    //

    /* Start L001 */
    WRITE_REGISTER_ULONG( &( PMC_CONTROL1 )->MKSR.Long, 0x3f-IPR_CLOCK_BIT_NO);	// S007
    WRITE_REGISTER_ULONG( &( PMC_CONTROL1 )->TMCR1.Long, 0x3);
    /* End L001 */

    //
    // If processor 0 is being initialized, then connect the count/compare
    // interrupt to the count interrupt routine to handle early count/compare
    // interrupts during phase 1 initialization. Otherwise, connect the
    // count\comapre interrupt to the appropriate interrupt service routine.
    //

    /* Start L001 */
    if (Prcb->Number != 0) {
        PCR->InterruptRoutine[PROFILE_VECTOR] = HalpProfileInterrupt;
	WRITE_REGISTER_ULONG( &( PMC_CONTROL1 )->MKSR.Long, 0x3f-IPR_PROFILE_BIT_NO);	// S007
	WRITE_REGISTER_ULONG( &( PMC_CONTROL1 )->TMCR2.Long, 0x3);
    }
    /* End L001 */

    //
    // Connect the interprocessor interrupt service routine and enable
    // interprocessor interrupts.
    //

    PCR->InterruptRoutine[IPI_LEVEL] = HalpIpiInterrupt;

    /*Start L001 */
    pmcRegisterAddr = (ULONG)( &(PMC_CONTROL1)->MKR );	// S003
    HalpReadLargeRegister( pmcRegisterAddr,
			  &pmcRegisterUpperPart,
			  &pmcRegisterLowerPart );
    pmcRegisterUpperPart = ( pmcRegisterUpperPart | MKR_INT4_ENABLE_HIGH );
    pmcRegisterLowerPart = ( pmcRegisterLowerPart | MKR_INT4_ENABLE_LOW );
    HalpWriteLargeRegister( pmcRegisterAddr,
			   &pmcRegisterUpperPart,
			   &pmcRegisterLowerPart );
    /*End L001 */

    //
    // Reserve the local device interrupt vector for exclusive use by the HAL.
    //


    /* Start L001 */
//    PCR->ReservedVectors |= (1 << DEVICE_LEVEL);
//    PCR->ReservedVectors |= (1 << INT1_LEVEL);	// S00a
    PCR->ReservedVectors |= (1 << INT2_LEVEL);
    /* End L001 */

    return TRUE;
}