summaryrefslogtreecommitdiffstats
path: root/private/ntos/nthals/halalpha/lca4.c
blob: 64e28dba42effd09c64148a2f15af3c7318ecce3 (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
/*++

Copyright (c) 1993  Digital Equipment Corporation

Module Name:

    lca4.c

Abstract:

    This module implements functions that are specific to the LCA4
    microprocessor.

Author:

    Joe Notarangelo  20-Oct-1993

Environment:

    Kernel mode

Revision History:


--*/

#include "halp.h"
#include "lca4.h"
#include "axp21066.h"

#ifndef AXP_FIRMWARE
VOID
DumpIoc(
    VOID
    );
#endif

//
// Globals
//

//
// Parity checking is a tri-state variable, unknown == all f's. Which means
// Keep checking disabled until we can determine what we want to set it to,
// which then means 1 or 0.
//

extern ULONG HalDisablePCIParityChecking;

#ifdef AXP_FIRMWARE

//
// Put these functions in the discardable text section.
//

//
// Local function prototypes
//

ULONG
HalpDetermineLca4Revision(
    VOID
    );

VOID
HalpLca4MapAddressSpaces(
    VOID
    );

ULONG 
HalpLca4Revision(
    VOID
    );

ULONGLONG 
HalpLca4IocTbTagPhysical(
    VOID
    );

ULONGLONG 
HalpLca4PciIntAckPhysical(
    VOID
    );

ULONGLONG 
HalpLca4PciIoPhysical(
    VOID
    );

ULONGLONG 
HalpLca4PciDensePhysical(
    VOID
    );

#pragma alloc_text(DISTEXT, HalpDetermineLca4Revision)
#pragma alloc_text(DISTEXT, HalpLca4MapAddressSpaces)
#pragma alloc_text(DISTEXT, HalpLca4Revision)
#pragma alloc_text(DISTEXT, HalpLca4IocTbTagPhysical)
#pragma alloc_text(DISTEXT, HalpLca4PciIntAckPhysical)
#pragma alloc_text(DISTEXT, HalpLca4PciIoPhysical)
#pragma alloc_text(DISTEXT, HalpLca4PciDensePhysical)

#endif // AXP_FIRMWARE


ULONG
HalpDetermineLca4Revision(
    VOID
    )
/*++

Routine Description:

    Determine the revision of the LCA4 processor we are currently executing.

Arguments:

    None.

Return Value:

    Return the recognized revision of the LCA4 processor executing.

--*/
{
    CAR_21066 Car;
    ULONG Revision;

    //
    // Pass 1 and Pass 2 LCA processors can be distinguished by the
    // PWR bit of the Cache Register (CAR).  For Pass 1 the bit is RAZ
    // while for Pass 2 the bit is read/write.
    //
    // Read the current value of the CAR. If it is 1, then we know that
    // it is Pass 2.  Else, set the PWR bit and write it back.
    // Then read CAR again.  If PWR is still set then we are executing on
    // Pass 2.  Don't forget to reset the PWR bit before finishing.
    //

    Car.all.QuadPart = READ_MEMC_REGISTER( 
                           &((PLCA4_MEMC_CSRS)(0))->CacheControl );

    if( Car.Pwr == 1 ) {

        Revision = Lca4Pass2;

    } else {

        Car.Pwr = 1;

        WRITE_MEMC_REGISTER( &((PLCA4_MEMC_CSRS)(0))->CacheControl,
                             Car.all.QuadPart );

        Car.all.QuadPart = READ_MEMC_REGISTER( 
                           &((PLCA4_MEMC_CSRS)(0))->CacheControl );

        if( Car.Pwr == 1 ){
            Revision = Lca4Pass2;
        } else {
            Revision = Lca4Pass1;
        }

        Car.Pwr = 0;

        WRITE_MEMC_REGISTER( &((PLCA4_MEMC_CSRS)(0))->CacheControl,
                             Car.all.QuadPart );

    }


    return Revision; 

}

//
// Define the Revision variable for LCA4.
//

ULONG Lca4Revision;

//
// Define the Physical Address space variables for LCA4.
//

ULONGLONG Lca4IocTbTagPhysical;
ULONGLONG Lca4PciIntAckPhysical;
ULONGLONG Lca4PciIoPhysical;
ULONGLONG Lca4PciDensePhysical;


VOID
HalpLca4MapAddressSpaces(
    VOID
    )
/*++

Routine Description:

    Map the address spaces of the LCA4 dependent upon which revision
    of the chip is executing.

Arguments:

    None.

Return Value:

    None.

--*/
{
    Lca4Revision = HalpDetermineLca4Revision();

    switch (Lca4Revision){

    //
    // Pass 1 LCA4
    //

    case Lca4Pass1:

        Lca4IocTbTagPhysical = LCA4_PASS1_IOC_TBTAG_PHYSICAL;
        Lca4PciIntAckPhysical = LCA4_PASS1_PCI_INTACK_BASE_PHYSICAL;
        Lca4PciIoPhysical = LCA4_PASS1_PCI_IO_BASE_PHYSICAL;
        Lca4PciDensePhysical = 0;

        break;

    //
    // Pass 2 LCA4
    //

    case Lca4Pass2:

        Lca4IocTbTagPhysical = LCA4_PASS2_IOC_TBTAG_PHYSICAL;
        Lca4PciIntAckPhysical = LCA4_PASS2_PCI_INTACK_BASE_PHYSICAL;
        Lca4PciIoPhysical = LCA4_PASS2_PCI_IO_BASE_PHYSICAL;
        Lca4PciDensePhysical = LCA4_PASS2_PCI_DENSE_BASE_PHYSICAL;

        break;

#if (DBG) || (HALDBG)

    default:

        DbgPrint( "Unrecognized LCA4 Revision = %x (execution is hopeless)\n",
                  Lca4Revision );
        DbgBreakPoint();

#endif //DBG || HALDBG

    }

    return;

}

//
// The following routines could be in-lined (it that were supported) or
// made into macros to save space (time isn't any issue with these values).
// To do so the variables above would have to be exported.
//

ULONG 
HalpLca4Revision(
    VOID
    )
/*++

Routine Description:

    Return the version of the LCA4 processor.

Arguments:

    None.

Return Value:

    The version of the LCA4 processor.

--*/
{

    return Lca4Revision;

}

ULONGLONG 
HalpLca4IocTbTagPhysical(
    VOID
    )
/*++

Routine Description:

    Return the base address of the IOC TB Tag registers on the currently
    executing LCA4 processor.

Arguments:

    None.

Return Value:

    The base physical address of the IOC TB Tag registers.

--*/
{

    return Lca4IocTbTagPhysical;

}


ULONGLONG 
HalpLca4PciIntAckPhysical(
    VOID
    )
/*++

Routine Description:

    Return the base physical address of PCI Interrupt Acknowledge space
    on the currently executing LCA4 processor.

Arguments:

    None.

Return Value:

    The base physical address of PCI Interrupt Acknowledge.

--*/
{

    return Lca4PciIntAckPhysical;

}

ULONGLONG 
HalpLca4PciIoPhysical(
    VOID
    )
/*++

Routine Description:

    Return the base physical address of PCI I/O space on the currently
    executing LCA4 processor.

Arguments:

    None.

Return Value:

    The base physical address of PCI I/O space.

--*/
{

    return Lca4PciIoPhysical;

}

ULONGLONG 
HalpLca4PciDensePhysical(
    VOID
    )
/*++

Routine Description:

    Return the base physical address of PCI Dense Memory space on the
    currently executing LCA4 processor.

Arguments:

    None.

Return Value:

    The base physical address of PCI Dense Memory space.

--*/
{

    return Lca4PciDensePhysical;

}

#if !defined(AXP_FIRMWARE)


VOID
HalpLca4InitializeSfwWindow(
    PWINDOW_CONTROL_REGISTERS WindowRegisters,
    LCA4_WINDOW_NUMBER WindowNumber
    )
/*++

Routine Description:

    Initialize the DMA Control software window registers for the specified
    DMA Window.

Arguments:

    WindowRegisters - Supplies a pointer to the software window control.

    WindowNumber - Supplies the window number initialized.  (0 = Isa Dma
                   Window, 1 = Master Dma Window).

Return Value:

    None.

--*/
{

    switch( WindowNumber ){

    //
    // The ISA DMA Window.
    //

    case Lca4IsaWindow:

        WindowRegisters->WindowBase = (PVOID)ISA_DMA_WINDOW_BASE;
        WindowRegisters->WindowSize = ISA_DMA_WINDOW_SIZE;
        WindowRegisters->TranslatedBaseRegister =
            &((PLCA4_IOC_CSRS)(LCA4_IOC_BASE_QVA))->TranslatedBase0;
        WindowRegisters->WindowBaseRegister =
            &((PLCA4_IOC_CSRS)(LCA4_IOC_BASE_QVA))->WindowBase0;
        WindowRegisters->WindowMaskRegister =
            &((PLCA4_IOC_CSRS)(LCA4_IOC_BASE_QVA))->WindowMask0;
        WindowRegisters->WindowTbiaRegister =
            &((PLCA4_IOC_CSRS)(LCA4_IOC_BASE_QVA))->Tbia;

        break;

    //
    // The Master DMA Window.
    //

    case Lca4MasterWindow:

        WindowRegisters->WindowBase = (PVOID)MASTER_DMA_WINDOW_BASE;
        WindowRegisters->WindowSize = MASTER_DMA_WINDOW_SIZE;
        WindowRegisters->TranslatedBaseRegister =
            &((PLCA4_IOC_CSRS)(LCA4_IOC_BASE_QVA))->TranslatedBase1;
        WindowRegisters->WindowBaseRegister =
            &((PLCA4_IOC_CSRS)(LCA4_IOC_BASE_QVA))->WindowBase1;
        WindowRegisters->WindowMaskRegister =
            &((PLCA4_IOC_CSRS)(LCA4_IOC_BASE_QVA))->WindowMask1;
        WindowRegisters->WindowTbiaRegister =
            &((PLCA4_IOC_CSRS)(LCA4_IOC_BASE_QVA))->Tbia;

        break;

    default:

#if DBG

        DbgPrint( "Lca4InitializeSfwWindow: Bad Window Number = %x\n",
                  WindowNumber );

#endif //DBG

        break;

    }

    return;
}


VOID
HalpLca4ProgramDmaWindow(
    PWINDOW_CONTROL_REGISTERS WindowRegisters,
    PVOID MapRegisterBase
    )
/*++

Routine Description:

    Program the control windows in the hardware so that DMA can be started
    to the DMA window.

Arguments:

    WindowRegisters - Supplies a pointer to the software window register
                      control structure.

    MapRegisterBase - Supplies the logical address of the scatter/gather
                      array in system memory.


Return Value:

    None.

--*/
{
    LCA4_IOC_WMASK WindowMask;
    LCA4_IOC_WBASE WindowBase;
    LCA4_IOC_TBEN  TbEnable;
    LCA4_IOC_PCIPD PciPD;
    LCA4_IOC_TBASE TranslatedBase;

    PVOID RegisterQva;

    WindowBase.Reserved1 = 0;
    WindowBase.Reserved2 = 0;
    WindowBase.Sg = 1;
    WindowBase.Wen = 1;
    WindowBase.BaseValue = (ULONG)(WindowRegisters->WindowBase) >> 20;

    WindowMask.Reserved1 = 0;
    WindowMask.Reserved = 0;
    WindowMask.MaskValue = (WindowRegisters->WindowSize >> 20) - 1;

    TranslatedBase.Reserved1 = 0;
    TranslatedBase.Reserved = 0;
    TranslatedBase.TBase = (ULONG)(MapRegisterBase) >> 10;

#if DBG

    //
    // Dump the EPIC registers.
    //

    DumpIoc();

#endif //DBG

    //
    // Clear the window base, temporarily disabling transactions to this
    // DMA window.
    //

    WRITE_IOC_REGISTER( WindowRegisters->WindowBaseRegister, (ULONGLONG)0 );

    //
    // Now program the window by writing the translated base, then the size
    // of the window in the mask register and finally the window base,
    // enabling both the window and scatter gather.
    //

    WRITE_IOC_REGISTER( WindowRegisters->TranslatedBaseRegister, 
                         *(PULONGLONG)&TranslatedBase );

    WRITE_IOC_REGISTER( WindowRegisters->WindowMaskRegister,
                         *(PULONGLONG)&WindowMask );

    WRITE_IOC_REGISTER( WindowRegisters->WindowBaseRegister,
                         *(PULONGLONG)&WindowBase );

    //
    // Invalidate any translations that might have existed for this window.
    //

    WRITE_IOC_REGISTER( WindowRegisters->WindowTbiaRegister, (ULONGLONG)0 );

    //
    // Enable the translation buffer inside of the IOC.
    //

    RtlZeroMemory( &TbEnable, sizeof(LCA4_IOC_TBEN) );
    TbEnable.Ten = 1;
        
    WRITE_IOC_REGISTER( &((PLCA4_IOC_CSRS)(LCA4_IOC_BASE_QVA))->TbEnable,
                        *(PULONGLONG)&TbEnable );

    //
    // Tri state parity checking - keep disabled if not determined 
    // yet. otherwise, Whack the PCI parity disable bit with the stored
    // value
    //

    RtlZeroMemory( &PciPD, sizeof(LCA4_IOC_PCIPD) );

    if (HalDisablePCIParityChecking == 0xffffffff) {
       PciPD.Par = 1;
    } else {
       PciPD.Par = HalDisablePCIParityChecking;
    }

    WRITE_IOC_REGISTER( &((PLCA4_IOC_CSRS)(LCA4_IOC_BASE_QVA))->PciParityDisable,
                        *(PULONGLONG)&PciPD );
 
#if DBG

    //
    // Dump the IOC registers.
    //

    DumpIoc();

#endif //DBG

    return;
}

ULONGLONG
READ_IOC_REGISTER(
    PVOID
    );

#if DBG

VOID
DumpIoc(
    VOID
    )
/*++

Routine Description:

    Read the interesting IOC registers and print them to the debug port.

Arguments:

    None.

Return Value:

    None.

--*/
{
    PVOID RegisterQva;
    ULONGLONG Value;

    DbgPrint( "Dumping the IOC registers\n" );

    RegisterQva = 
        &((PLCA4_IOC_CSRS)(LCA4_IOC_BASE_QVA))->IocStat0;
    Value = READ_IOC_REGISTER( RegisterQva );
    DbgPrint( "IOSTAT[0] = %Lx\n", Value );
      
    RegisterQva = 
        &((PLCA4_IOC_CSRS)(LCA4_IOC_BASE_QVA))->IocStat1;
    Value = READ_IOC_REGISTER( RegisterQva );
    DbgPrint( "IOSTAT[1] = %Lx\n", Value );
      
    DbgPrint( "--end IOC dump\n\n" );

    return;

}

#endif //DBG

#endif //!AXP_FIRMWARE