/
permedia.c
3005 lines (2238 loc) · 89 KB
/
permedia.c
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
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//***************************************************************************
//
// Module Name:
//
// permedia.c
//
// Abstract:
//
// This module contains the code that implements the Permedia2 miniport driver
//
// Environment:
//
// Kernel mode
//
//
// Copyright (c) 1994-1998 3Dlabs Inc. Ltd. All rights reserved.
// Copyright (c) 1995-1999 Microsoft Corporation. All Rights Reserved.
//
//***************************************************************************
#include "permedia.h"
#include "string.h"
#define USE_SINGLE_CYCLE_BLOCK_WRITES 0
#if defined(ALLOC_PRAGMA)
#pragma alloc_text(PAGE,DriverEntry)
#pragma alloc_text(PAGE,Permedia2FindAdapter)
#pragma alloc_text(PAGE,Permedia2RegistryCallback)
#pragma alloc_text(PAGE,Permedia2RetrieveGammaCallback)
#pragma alloc_text(PAGE,InitializeAndSizeRAM)
#pragma alloc_text(PAGE,ConstructValidModesList)
#pragma alloc_text(PAGE,Permedia2Initialize)
#pragma alloc_text(PAGE,Permedia2StartIO)
#pragma alloc_text(PAGE,Permedia2SetColorLookup)
#pragma alloc_text(PAGE,Permedia2GetClockSpeeds)
#pragma alloc_text(PAGE,ZeroMemAndDac)
#endif
//
// NtVersion: NT4 - This driver is working on NT4
// WIN2K - This driver is working on Windows 2000
//
short NtVersion;
ULONG
DriverEntry (
PVOID Context1,
PVOID Context2
)
/*++
Routine Description:
This routine is the initial entry point to the video miniport driver.
This routine is called by the I/O subsystem when the video miniport
is loaded. The miniport is responsible for initializing a
VIDEO_HW_INITIALIZATION_DATA structure to register the driver functions
called by the video port driver in response to requests from the display
driver, plug and play manager, power management, or other driver
components.
The following tasks MUST be completed by the video miniport in the
context of DriverEntry. Driver writers should consult the documentation
for full details on the exact initialization process.
1. Initialize VIDEO_HW_INITIALIZATION_DATA structure with all relevant
data structures.
2. Call VideoPortInitialize.
3. Return appropriate status value to the caller of DriverEntry.
Drivers can undertake other tasks as required and under the restrictions
outlined in the documentation.
Arguments:
Context1 - First context value passed by the operating system. This is
the value with which the miniport driver calls VideoPortInitialize().
Context2 - Second context value passed by the operating system. This is
the value with which the miniport driver calls VideoPortInitialize().
Return Value:
Status from VideoPortInitialize()
--*/
{
VIDEO_HW_INITIALIZATION_DATA hwInitData;
VP_STATUS initializationStatus;
//
// Zero out structure.
//
VideoPortZeroMemory(&hwInitData, sizeof(VIDEO_HW_INITIALIZATION_DATA));
//
// Specify sizes of structure and extension.
//
hwInitData.HwInitDataSize = sizeof(VIDEO_HW_INITIALIZATION_DATA);
//
// Set entry points.
//
hwInitData.HwFindAdapter = Permedia2FindAdapter;
hwInitData.HwInitialize = Permedia2Initialize;
hwInitData.HwStartIO = Permedia2StartIO;
hwInitData.HwResetHw = Permedia2ResetHW;
hwInitData.HwInterrupt = Permedia2VidInterrupt;
hwInitData.HwGetPowerState = Permedia2GetPowerState;
hwInitData.HwSetPowerState = Permedia2SetPowerState;
hwInitData.HwGetVideoChildDescriptor = Permedia2GetChildDescriptor;
//
// Declare the legacy resources
//
hwInitData.HwLegacyResourceList = P2LegacyResourceList;
hwInitData.HwLegacyResourceCount = P2LegacyResourceEntries;
//
// Determine the size we require for the device extension.
//
hwInitData.HwDeviceExtensionSize = sizeof(HW_DEVICE_EXTENSION);
//
// This device only supports the PCI bus.
//
hwInitData.AdapterInterfaceType = PCIBus;
NtVersion = WIN2K;
initializationStatus = VideoPortInitialize(Context1,
Context2,
&hwInitData,
NULL);
if( initializationStatus != NO_ERROR)
{
hwInitData.HwInitDataSize = SIZE_OF_W2K_VIDEO_HW_INITIALIZATION_DATA;
initializationStatus = VideoPortInitialize(Context1,
Context2,
&hwInitData,
NULL);
}
if( initializationStatus != NO_ERROR)
{
NtVersion = NT4;
hwInitData.HwInterrupt = NULL;
hwInitData.HwInitDataSize = SIZE_OF_NT4_VIDEO_HW_INITIALIZATION_DATA;
initializationStatus = VideoPortInitialize(Context1,
Context2,
&hwInitData,
NULL);
}
DEBUG_PRINT((2, "PERM2: VideoPortInitialize returned status 0x%x\n", initializationStatus));
return initializationStatus;
} // end DriverEntry()
VP_STATUS
Permedia2FindAdapter(
PVOID HwDeviceExtension,
PVOID pReserved,
PWSTR ArgumentString,
PVIDEO_PORT_CONFIG_INFO ConfigInfo,
PUCHAR Again
)
/*++
Routine Description:
This routine gets the access ranges for a device on an enumerable
bus and, if necessary, determines the device type
Arguments:
HwDeviceExtension -
System supplied device extension supplied to the miniport for
a per-device storage area.
pReserved -
NULL on Windows 2000 and should be ignored by the miniport.
ArgumentString -
Suuplies a NULL terminated ASCII string. This string originates
from the user. This pointer can be NULL.
ConfigInfo -
Points to a VIDEO_PORT_CONFIG_INFO structure allocated and initialized
by the port driver. This structure will contain as much information
as could be obtained by the port driver. This routine is responsible
for filling in any relevant missing information.
Again - Is not used on Windows 2000.
We set this to FALSE on NT 4, since we only support one adapter on NT4.
Return Value:
This routine must return:
NO_ERROR -
Indicates that the routine completed without error.
ERROR_INVALID_PARAMETER -
Indicates that the adapter could not be properly configured or
information was inconsistent. (NOTE: This does not mean that the
adapter could not be initialized. Miniports must not attempt to
initialize the adapter until HwVidInitialize.)
ERROR_DEV_NOT_EXIST - Indicates no host adapter was found for the
supplied configuration information.
--*/
{
PHW_DEVICE_EXTENSION hwDeviceExtension = HwDeviceExtension;
P2_DECL_VARS;
WCHAR StringBuffer[60];
ULONG StringLength;
VP_STATUS vpStatus;
ULONG UseSoftwareCursor;
ULONG ulValue;
ULONG i;
VIDEO_ACCESS_RANGE *pciAccessRange = hwDeviceExtension->PciAccessRange;
PWSTR pwszChip, pwszDAC, pwszAdapterString;
ULONG cbChip, cbDAC, cbAdapterString, cbBiosString;
ULONG pointerCaps;
USHORT usData;
//
// 3 (major number) + 1 (dot) + 3 (minor number) + 1 (L'\0') = 8 digtis
// is enough for bios verions string
//
WCHAR pwszBiosString[8];
//
// save current NT version obtained at DriverEntry
//
hwDeviceExtension->NtVersion = NtVersion;
//
// Make sure the size of the structure is at least as large as what we
// are expecting (check version of the config info structure).
//
if ( (NtVersion == WIN2K) &&
(ConfigInfo->Length < sizeof(VIDEO_PORT_CONFIG_INFO)) )
{
DEBUG_PRINT((1, "bad size for VIDEO_PORT_CONFIG_INFO\n"));
return (ERROR_INVALID_PARAMETER);
}
else if ( (NtVersion == NT4) &&
(ConfigInfo->Length < SIZE_OF_NT4_VIDEO_PORT_CONFIG_INFO) )
{
DEBUG_PRINT((1, "bad size for VIDEO_PORT_CONFIG_INFO\n"));
return (ERROR_INVALID_PARAMETER);
}
//
// we must be a PCI device
//
if (ConfigInfo->AdapterInterfaceType != PCIBus)
{
DEBUG_PRINT((1, "not a PCI device\n"));
return (ERROR_DEV_NOT_EXIST);
}
//
// Retrieve pointers of those new video port functions in Win2k.
// If you don't want to support NT4, you don't need to do this. You
// can just call these functions by their name.
//
if ( NtVersion == WIN2K )
{
if(!(hwDeviceExtension->Win2kVideoPortGetRomImage =
ConfigInfo->VideoPortGetProcAddress( hwDeviceExtension,
"VideoPortGetRomImage")))
{
return (ERROR_DEV_NOT_EXIST);
}
if(!(hwDeviceExtension->Win2kVideoPortGetCommonBuffer =
ConfigInfo->VideoPortGetProcAddress( hwDeviceExtension,
"VideoPortGetCommonBuffer")))
{
return (ERROR_DEV_NOT_EXIST);
}
if(!(hwDeviceExtension->Win2kVideoPortFreeCommonBuffer =
ConfigInfo->VideoPortGetProcAddress( hwDeviceExtension,
"VideoPortFreeCommonBuffer")))
{
return (ERROR_DEV_NOT_EXIST);
}
if(!(hwDeviceExtension->Win2kVideoPortDDCMonitorHelper =
ConfigInfo->VideoPortGetProcAddress( hwDeviceExtension,
"VideoPortDDCMonitorHelper")))
{
return (ERROR_DEV_NOT_EXIST);
}
if(!(hwDeviceExtension->Win2kVideoPortInterlockedExchange =
ConfigInfo->VideoPortGetProcAddress( hwDeviceExtension,
"VideoPortInterlockedExchange")))
{
return (ERROR_DEV_NOT_EXIST);
}
if(!(hwDeviceExtension->Win2kVideoPortGetVgaStatus =
ConfigInfo->VideoPortGetProcAddress( hwDeviceExtension,
"VideoPortGetVgaStatus")))
{
return (ERROR_DEV_NOT_EXIST);
}
}
else
{
//
// We only support one adapter on NT 4
//
Again = FALSE;
}
//
// will be initialized in CopyROMInitializationTable
//
hwDeviceExtension->culTableEntries = 0;
//
// will be initialized in ConstructValidModesList
//
hwDeviceExtension->pFrequencyDefault = NULL;
//
// We'll set this TRUE when in InitializeVideo after programming the VTG
//
hwDeviceExtension->bVTGRunning = FALSE;
hwDeviceExtension->bMonitorPoweredOn = TRUE;
hwDeviceExtension->ChipClockSpeed = 0;
hwDeviceExtension->RefClockSpeed = 0;
hwDeviceExtension->P28bppRGB = 0;
hwDeviceExtension->ExportNon3DModes = 0;
hwDeviceExtension->PreviousPowerState = VideoPowerOn;
//
// pick up capabilities on the way.
//
hwDeviceExtension->Capabilities = CAPS_GLYPH_EXPAND;
//
// We'll use a software pointer in all modes if the user sets
// the correct entry in the registry.
//
UseSoftwareCursor = 0;
vpStatus = VideoPortGetRegistryParameters( HwDeviceExtension,
L"UseSoftwareCursor",
FALSE,
Permedia2RegistryCallback,
&UseSoftwareCursor);
if ( ( vpStatus == NO_ERROR ) && UseSoftwareCursor)
{
hwDeviceExtension->Capabilities |= CAPS_SW_POINTER;
}
//
// Query the PCI to see if any of our supported chip devices exist.
//
if ( NtVersion == WIN2K )
{
if (!Permedia2AssignResources( HwDeviceExtension,
ConfigInfo,
PCI_TYPE0_ADDRESSES + 1,
pciAccessRange ))
{
DEBUG_PRINT((1, "Permedia2AssignResources failed\n"));
return (ERROR_DEV_NOT_EXIST);
}
}
else
{
if (!Permedia2AssignResourcesNT4( HwDeviceExtension,
ConfigInfo,
PCI_TYPE0_ADDRESSES + 1,
pciAccessRange ))
{
DEBUG_PRINT((1, "Permedia2AssignResources failed\n"));
return (ERROR_DEV_NOT_EXIST);
}
}
//
// construct the identifier string including the revision id
//
StringLength = sizeof(L"3Dlabs PERMEDIA2");
VideoPortMoveMemory((PVOID)StringBuffer,
(PVOID)(L"3Dlabs PERMEDIA2"),
StringLength);
pwszChip = (PWSTR)StringBuffer;
cbChip = StringLength;
//
// Set the defaults for the board type.
//
hwDeviceExtension->deviceInfo.BoardId = PERMEDIA2_BOARD;
pwszAdapterString = L"Permedia 2";
cbAdapterString = sizeof(L"Permedia 2");
//
// Get the mapped addresses for the control registers and the
// framebuffer. Must use local variable pCtrlRegs so macro
// declarations further down will work.
//
pCtrlRegs = VideoPortGetDeviceBase(
HwDeviceExtension,
pciAccessRange[PCI_CTRL_BASE_INDEX].RangeStart,
pciAccessRange[PCI_CTRL_BASE_INDEX].RangeLength,
pciAccessRange[PCI_CTRL_BASE_INDEX].RangeInIoSpace
);
if (pCtrlRegs == NULL)
{
DEBUG_PRINT((1, "CTRL DeviceBase mapping failed\n"));
return ERROR_INVALID_PARAMETER;
}
hwDeviceExtension->ctrlRegBase = pCtrlRegs;
//
// Some boards have a ROM which we can use to identify them.
//
CopyROMInitializationTable(hwDeviceExtension);
if(hwDeviceExtension->culTableEntries == 0)
{
//
// No initialization table, but P2 really needs one in order to come
// out of sleep mode correctly. Generate initialization table by
// default values
//
GenerateInitializationTable(hwDeviceExtension);
}
//
// Find out what type of RAMDAC we have.
//
vpStatus = NO_ERROR;
hwDeviceExtension->pRamdac = &(pCtrlRegs->ExternalVideo);
//
// some RAMDACs may not support a cursor so a software cursor is the default
//
pointerCaps = CAPS_SW_POINTER;
//
// Check for a TI TVP4020
//
if(DEVICE_FAMILY_ID(hwDeviceExtension->deviceInfo.DeviceId) == PERMEDIA_P2S_ID)
{
//
// P2 with 3Dlabs RAMDAC, check for a rev 2 chip
//
i = VideoPortReadRegisterUlong(CHIP_CONFIG);
if(i & 0x40000000)
{
DEBUG_PRINT((2, "PERM2: Permedia2 is rev 2\n"));
hwDeviceExtension->deviceInfo.RevisionId = 2;
}
else
{
DEBUG_PRINT((2, "PERM2: Permedia2 is rev 1\n"));
}
hwDeviceExtension->DacId = P2RD_RAMDAC;
pointerCaps = (ULONG)CAPS_P2RD_POINTER;
hwDeviceExtension->deviceInfo.ActualDacId = P2RD_RAMDAC;
pwszDAC = L"3Dlabs P2RD";
cbDAC = sizeof(L"3Dlabs P2RD");
DEBUG_PRINT((1, "PERM2: using P2RD RAMDAC\n"));
}
else
{
hwDeviceExtension->DacId = TVP4020_RAMDAC;
pointerCaps = CAPS_TVP4020_POINTER;
hwDeviceExtension->deviceInfo.ActualDacId = TVP4020_RAMDAC;
if(hwDeviceExtension->deviceInfo.RevisionId == PERMEDIA2A_REV_ID)
{
pwszDAC = L"TI TVP4020A";
cbDAC = sizeof(L"TI TVP4020A");
DEBUG_PRINT((1, "PERM2: using TVP4020A RAMDAC\n"));
}
else
{
pwszDAC = L"TI TVP4020C";
cbDAC = sizeof(L"TI TVP4020C");
DEBUG_PRINT((1, "PERM2: using TVP4020C RAMDAC\n"));
}
}
//
// use the RAMDAC cursor capability only if the user didn't specify
// a software cursor
//
if (!(hwDeviceExtension->Capabilities & CAPS_SW_POINTER))
{
hwDeviceExtension->Capabilities |= pointerCaps;
}
hwDeviceExtension->PhysicalFrameIoSpace =
pciAccessRange[PCI_FB_BASE_INDEX].RangeInIoSpace |
VIDEO_MEMORY_SPACE_P6CACHE;
if ( (hwDeviceExtension->pFramebuffer =
VideoPortGetDeviceBase(
HwDeviceExtension,
pciAccessRange[PCI_FB_BASE_INDEX].RangeStart,
pciAccessRange[PCI_FB_BASE_INDEX].RangeLength,
(UCHAR) hwDeviceExtension->PhysicalFrameIoSpace
) ) == NULL)
{
//
// Some machines have limitations on how much PCI address space they
// can map in so try again, reducing the amount we map till we succeed
// or the size gets to zero in which case we really have failed.
//
ULONG sz;
DEBUG_PRINT((1, "PERM2: FB DeviceBase mapping failed\n"));
for ( sz = pciAccessRange[PCI_FB_BASE_INDEX].RangeLength;
sz > 0;
sz -= 1024*1024 )
{
if ( (hwDeviceExtension->pFramebuffer =
VideoPortGetDeviceBase(
HwDeviceExtension,
pciAccessRange[PCI_FB_BASE_INDEX].RangeStart,
sz,
(UCHAR) hwDeviceExtension->PhysicalFrameIoSpace
) ) != NULL)
{
//
// store the modified size
//
pciAccessRange[PCI_FB_BASE_INDEX].RangeLength = sz;
break;
}
}
//
// if sz is zero, well we tried ...
//
if (sz == 0)
return ERROR_INVALID_PARAMETER;
}
DEBUG_PRINT((1, "PERM2: FB mapped at 0x%x for length 0x%x (%s)\n",
hwDeviceExtension->pFramebuffer,
pciAccessRange[PCI_FB_BASE_INDEX].RangeLength,
pciAccessRange[PCI_FB_BASE_INDEX].RangeInIoSpace ?
"I/O Ports" : "MemMapped"));
//
// Initialize the RAM registers and dynamically size the framebuffer
//
if (!InitializeAndSizeRAM(hwDeviceExtension, pciAccessRange))
{
DEBUG_PRINT((0, "InitializeAndSizeRAM failed\n"));
return ERROR_DEV_NOT_EXIST;
}
//
// Record the size of the video memory.
//
hwDeviceExtension->AdapterMemorySize =
pciAccessRange[PCI_FB_BASE_INDEX].RangeLength;
#if defined(_ALPHA_)
//
// We want to use a dense space mapping of the frame buffer
// whenever we can on the Alpha.
//
hwDeviceExtension->PhysicalFrameIoSpace = 4;
//
// The new DeskStation Alpha machines don't always support
// dense space. Therefore, we should try to map the memory
// at this point as a test. If the mapping succeeds then
// we can use dense space, otherwise we'll use sparse space.
//
{
PULONG MappedSpace=0;
VP_STATUS status;
DEBUG_PRINT((1, "PERM2: Checking to see if we can use dense space...\n"));
//
// We want to try to map the dense memory where it will ultimately
// be mapped anyway.
//
MappedSpace = (PULONG)VideoPortGetDeviceBase (
hwDeviceExtension,
pciAccessRange[PCI_FB_BASE_INDEX].RangeStart,
pciAccessRange[PCI_FB_BASE_INDEX].RangeLength,
(UCHAR) hwDeviceExtension->PhysicalFrameIoSpace
);
if (MappedSpace == NULL)
{
//
// Well, looks like we can't use dense space to map the
// range. Lets use sparse space, and let the display
// driver know.
//
DEBUG_PRINT((1, "PERM2: Can't use dense space!\n"));
hwDeviceExtension->PhysicalFrameIoSpace = 0;
hwDeviceExtension->Capabilities |= CAPS_SPARSE_SPACE;
}
else
{
//
// The mapping worked. However, we were only mapping to
// see if dense space was supported. Free the memory.
//
DEBUG_PRINT((1, "PERM2: We can use dense space.\n"));
VideoPortFreeDeviceBase(hwDeviceExtension,
MappedSpace);
}
}
#endif // defined(_ALPHA_)
//
// We now have a complete hardware description of the hardware.
// Save the information to the registry so it can be used by
// configuration programs - such as the display applet.
//
VideoPortSetRegistryParameters(HwDeviceExtension,
L"HardwareInformation.ChipType",
pwszChip,
cbChip);
VideoPortSetRegistryParameters(HwDeviceExtension,
L"HardwareInformation.DacType",
pwszDAC,
cbDAC);
VideoPortSetRegistryParameters(HwDeviceExtension,
L"HardwareInformation.MemorySize",
&hwDeviceExtension->AdapterMemorySize,
sizeof(ULONG));
VideoPortSetRegistryParameters(HwDeviceExtension,
L"HardwareInformation.AdapterString",
pwszAdapterString,
cbAdapterString);
cbBiosString = GetBiosVersion(HwDeviceExtension, (PWSTR) pwszBiosString);
VideoPortSetRegistryParameters(HwDeviceExtension,
L"HardwareInformation.BiosString",
pwszBiosString,
cbBiosString);
ConstructValidModesList(HwDeviceExtension, hwDeviceExtension);
if (hwDeviceExtension->NumAvailableModes == 0)
{
DEBUG_PRINT((1, "No video modes available\n"));
return(ERROR_DEV_NOT_EXIST);
}
//
// Frame buffer information
//
hwDeviceExtension->PhysicalFrameAddress =
pciAccessRange[PCI_FB_BASE_INDEX].RangeStart;
hwDeviceExtension->FrameLength =
pciAccessRange[PCI_FB_BASE_INDEX].RangeLength;
//
// Control Register information
// Get the base address, starting at zero and map all registers
//
hwDeviceExtension->PhysicalRegisterAddress =
pciAccessRange[PCI_CTRL_BASE_INDEX].RangeStart;
hwDeviceExtension->RegisterLength =
pciAccessRange[PCI_CTRL_BASE_INDEX].RangeLength;
hwDeviceExtension->RegisterSpace =
pciAccessRange[PCI_CTRL_BASE_INDEX].RangeInIoSpace;
ConfigInfo->VdmPhysicalVideoMemoryAddress.LowPart = 0x000A0000;
ConfigInfo->VdmPhysicalVideoMemoryAddress.HighPart = 0x00000000;
ConfigInfo->VdmPhysicalVideoMemoryLength = 0x00020000;
//
// Clear out the Emulator entries and the state size since this driver
// does not support them.
//
ConfigInfo->NumEmulatorAccessEntries = 0;
ConfigInfo->EmulatorAccessEntries = NULL;
ConfigInfo->EmulatorAccessEntriesContext = 0;
//
// This driver does not do SAVE/RESTORE of hardware state.
//
ConfigInfo->HardwareStateSize = 0;
//
// in a multi-adapter system we'll need to disable VGA for the
// secondary adapters
//
if(!hwDeviceExtension->bVGAEnabled)
{
DEBUG_PRINT((1, "PERM2: disabling VGA for the secondary card\n"));
//
// Enable graphics mode, disable VGA
//
VideoPortWriteRegisterUchar(PERMEDIA_MMVGA_INDEX_REG,
PERMEDIA_VGA_CTRL_INDEX);
usData = (USHORT)VideoPortReadRegisterUchar(PERMEDIA_MMVGA_DATA_REG);
usData &= ~PERMEDIA_VGA_ENABLE;
usData = (usData << 8) | PERMEDIA_VGA_CTRL_INDEX;
VideoPortWriteRegisterUshort(PERMEDIA_MMVGA_INDEX_REG, usData);
#define INTERNAL_VGA_ENABLE (1 << 1)
#define VGA_FIXED_ADD_DECODE (1 << 2)
ulValue = VideoPortReadRegisterUlong(CHIP_CONFIG);
ulValue &= ~INTERNAL_VGA_ENABLE;
ulValue &= ~VGA_FIXED_ADD_DECODE;
VideoPortWriteRegisterUlong(CHIP_CONFIG, ulValue);
}
//
// Indicate a successful completion status.
//
return NO_ERROR;
} // end Permedia2FindAdapter()
VOID
ConstructValidModesList(
PVOID HwDeviceExtension,
PHW_DEVICE_EXTENSION hwDeviceExtension
)
/*++
Routine Description:
Here we prune valid modes, based on rules according to the chip
capabilities and memory requirements.
We prune modes so that we will not annoy the user by presenting
modes in the 'Video Applet' which we know the user can't use.
Look up the registry to see if we want to export modes which can only
be used as single buffered by 3D applications. If we only want double
buffered modes then, effectively, we have only half the memory in
which to display the standard 2D resolution. This is only not true at 12bpp
where we can double buffer at any resolution.
--*/
{
PP2_VIDEO_FREQUENCIES FrequencyEntry;
PP2_VIDEO_MODES ModeEntry;
LONG AdapterMemorySize;
ULONG ModeIndex;
ULONG i;
hwDeviceExtension->NumAvailableModes = 0;
//
// Since there are a number of frequencies possible for each
// distinct resolution/colour depth, we cycle through the
// frequency table and find the appropriate mode entry for that
// frequency entry.
//
if (!BuildFrequencyList(hwDeviceExtension))
return;
for (FrequencyEntry = hwDeviceExtension->FrequencyTable, ModeIndex = 0;
FrequencyEntry->BitsPerPel != 0;
FrequencyEntry++, ModeIndex++)
{
//
// Find the mode for this entry. First, assume we won't find one.
//
FrequencyEntry->ModeValid = FALSE;
FrequencyEntry->ModeIndex = ModeIndex;
for (ModeEntry = P2Modes, i = 0; i < NumP2VideoModes; ModeEntry++, i++)
{
if ((FrequencyEntry->BitsPerPel ==
ModeEntry->ModeInformation.BitsPerPlane) &&
(FrequencyEntry->ScreenWidth ==
ModeEntry->ModeInformation.VisScreenWidth) &&
(FrequencyEntry->ScreenHeight ==
ModeEntry->ModeInformation.VisScreenHeight))
{
AdapterMemorySize = (LONG)hwDeviceExtension->AdapterMemorySize;
//
// We've found a mode table entry that matches this frequency
// table entry. Now we'll figure out if we can actually do
// this mode/frequency combination. For now, assume we'll
// succeed.
//
FrequencyEntry->ModeEntry = ModeEntry;
FrequencyEntry->ModeValid = TRUE;
ModeEntry->ModeInformation.ScreenStride =
ModeEntry->ScreenStrideContiguous;
//
// Rule: use true color at 8bpp if we've enabled that
// capability above.
//
if ((FrequencyEntry->BitsPerPel == 8) &&
(hwDeviceExtension->Capabilities & CAPS_8BPP_RGB))
{
ModeEntry->ModeInformation.AttributeFlags &=
~(VIDEO_MODE_PALETTE_DRIVEN | VIDEO_MODE_MANAGED_PALETTE);
//
// NB. These must match the way the palette is loaded in
// InitializeVideo.
//
ModeEntry->ModeInformation.RedMask = 0x07;
ModeEntry->ModeInformation.GreenMask = 0x38;
ModeEntry->ModeInformation.BlueMask = 0xc0;
}
//
// Rule: We have to have enough memory to handle the mode.
//
if ((LONG)(ModeEntry->ModeInformation.VisScreenHeight *
ModeEntry->ModeInformation.ScreenStride) >
AdapterMemorySize)
{
FrequencyEntry->ModeValid = FALSE;
}
{
ULONG pixelData;
ULONG DacDepth = FrequencyEntry->BitsPerPel;
//
// We need the proper pixel size to calculate timing values
//
if (DacDepth == 15)
{
DacDepth = 16;
}
else if (DacDepth == 12)
{
DacDepth = 32;
}
pixelData = FrequencyEntry->PixelClock * (DacDepth / 8);
if (((FrequencyEntry->PixelClock > P2_MAX_PIXELCLOCK ||
pixelData > P2_MAX_PIXELDATA)))
{
FrequencyEntry->ModeValid = FALSE;
}
//
// Don't supports 24bpp
//
if(FrequencyEntry->BitsPerPel == 24)
{
FrequencyEntry->ModeValid = FALSE;
}
}
//
// Don't forget to count it if it's still a valid mode after
// applying all those rules.
//
if (FrequencyEntry->ModeValid)
{
if(hwDeviceExtension->pFrequencyDefault == NULL &&