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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
|
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/mga/mga_dri.c,v 1.19 2001/03/21 19:46:27 dawes Exp $ */
/*
* Copyright 2000 VA Linux Systems Inc., Fremont, California.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Authors:
* Keith WHitwell <keithw@valinux.com>
* Gareth Hughes <gareth@valinux.com>
*/
#include "xf86.h"
#include "xf86_OSproc.h"
#include "xf86_ansic.h"
#include "xf86Priv.h"
#include "xf86PciInfo.h"
#include "xf86Pci.h"
#define PSZ 8
#include "cfb.h"
#undef PSZ
#include "cfb16.h"
#include "cfb32.h"
#include "miline.h"
#include "mga_bios.h"
#include "mga_reg.h"
#include "mga.h"
#include "mga_macros.h"
#include "mga_dri.h"
#include "mga_sarea.h"
#define _XF86DRI_SERVER_
#include "GL/glxtokens.h"
#include "sarea.h"
#include "GL/glxtokens.h"
#include "mga_bios.h"
#include "mga_reg.h"
#include "mga.h"
#include "mga_macros.h"
#include "mga_dri.h"
#include "mga_sarea.h"
static char MGAKernelDriverName[] = "mga";
static char MGAClientDriverName[] = "mga";
/* DRI buffer management
*/
extern void Mga8DRIInitBuffers( WindowPtr pWin, RegionPtr prgn,
CARD32 index );
extern void Mga8DRIMoveBuffers( WindowPtr pParent, DDXPointRec ptOldOrg,
RegionPtr prgnSrc, CARD32 index );
extern void Mga16DRIInitBuffers( WindowPtr pWin, RegionPtr prgn,
CARD32 index );
extern void Mga16DRIMoveBuffers( WindowPtr pParent, DDXPointRec ptOldOrg,
RegionPtr prgnSrc, CARD32 index );
extern void Mga24DRIInitBuffers( WindowPtr pWin, RegionPtr prgn,
CARD32 index );
extern void Mga24DRIMoveBuffers( WindowPtr pParent, DDXPointRec ptOldOrg,
RegionPtr prgnSrc, CARD32 index );
extern void Mga32DRIInitBuffers( WindowPtr pWin, RegionPtr prgn,
CARD32 index );
extern void Mga32DRIMoveBuffers( WindowPtr pParent, DDXPointRec ptOldOrg,
RegionPtr prgnSrc, CARD32 index );
/* Initialize the visual configs that are supported by the hardware.
* These are combined with the visual configs that the indirect
* rendering core supports, and the intersection is exported to the
* client.
*/
static Bool MGAInitVisualConfigs( ScreenPtr pScreen )
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
MGAPtr pMga = MGAPTR(pScrn);
int numConfigs = 0;
__GLXvisualConfig *pConfigs = 0;
MGAConfigPrivPtr pMGAConfigs = 0;
MGAConfigPrivPtr *pMGAConfigPtrs = 0;
int i, db, depth, stencil, accum;
switch ( pScrn->bitsPerPixel ) {
case 8:
case 24:
break;
case 16:
numConfigs = 8;
pConfigs = (__GLXvisualConfig*)xnfcalloc( sizeof(__GLXvisualConfig),
numConfigs );
if ( !pConfigs ) {
return FALSE;
}
pMGAConfigs = (MGAConfigPrivPtr)xnfcalloc( sizeof(MGAConfigPrivRec),
numConfigs );
if ( !pMGAConfigs ) {
xfree( pConfigs );
return FALSE;
}
pMGAConfigPtrs = (MGAConfigPrivPtr*)xnfcalloc( sizeof(MGAConfigPrivPtr),
numConfigs );
if ( !pMGAConfigPtrs ) {
xfree( pConfigs );
xfree( pMGAConfigs );
return FALSE;
}
for ( i = 0 ; i < numConfigs ; i++ ) {
pMGAConfigPtrs[i] = &pMGAConfigs[i];
}
i = 0;
depth = 1;
for ( accum = 0 ; accum <= 1 ; accum++ ) {
for ( stencil = 0 ; stencil <= 1 ; stencil++ ) {
for ( db = 1 ; db >= 0 ; db-- ) {
pConfigs[i].vid = -1;
pConfigs[i].class = -1;
pConfigs[i].rgba = TRUE;
pConfigs[i].redSize = 5;
pConfigs[i].greenSize = 6;
pConfigs[i].blueSize = 5;
pConfigs[i].alphaSize = 0;
pConfigs[i].redMask = 0x0000F800;
pConfigs[i].greenMask = 0x000007E0;
pConfigs[i].blueMask = 0x0000001F;
pConfigs[i].alphaMask = 0;
if ( accum ) {
pConfigs[i].accumRedSize = 16;
pConfigs[i].accumGreenSize = 16;
pConfigs[i].accumBlueSize = 16;
pConfigs[i].accumAlphaSize = 0;
} else {
pConfigs[i].accumRedSize = 0;
pConfigs[i].accumGreenSize = 0;
pConfigs[i].accumBlueSize = 0;
pConfigs[i].accumAlphaSize = 0;
}
if ( db ) {
pConfigs[i].doubleBuffer = TRUE;
} else {
pConfigs[i].doubleBuffer = FALSE;
}
pConfigs[i].stereo = FALSE;
pConfigs[i].bufferSize = 16;
if ( depth ) {
pConfigs[i].depthSize = 16;
} else {
pConfigs[i].depthSize = 0;
}
if ( stencil ) {
pConfigs[i].stencilSize = 8;
} else {
pConfigs[i].stencilSize = 0;
}
pConfigs[i].auxBuffers = 0;
pConfigs[i].level = 0;
if ( accum || stencil ) {
pConfigs[i].visualRating = GLX_SLOW_VISUAL_EXT;
} else {
pConfigs[i].visualRating = GLX_NONE_EXT;
}
pConfigs[i].transparentPixel = 0;
pConfigs[i].transparentRed = 0;
pConfigs[i].transparentGreen = 0;
pConfigs[i].transparentBlue = 0;
pConfigs[i].transparentAlpha = 0;
pConfigs[i].transparentIndex = 0;
i++;
}
}
}
if ( i != numConfigs ) {
xf86DrvMsg( pScrn->scrnIndex, X_ERROR,
"[drm] Incorrect initialization of visuals\n" );
return FALSE;
}
break;
case 32:
numConfigs = 8;
pConfigs = (__GLXvisualConfig*)xnfcalloc( sizeof(__GLXvisualConfig),
numConfigs );
if ( !pConfigs ) {
return FALSE;
}
pMGAConfigs = (MGAConfigPrivPtr)xnfcalloc( sizeof(MGAConfigPrivRec),
numConfigs );
if ( !pMGAConfigs ) {
xfree( pConfigs );
return FALSE;
}
pMGAConfigPtrs = (MGAConfigPrivPtr*)xnfcalloc( sizeof(MGAConfigPrivPtr),
numConfigs );
if ( !pMGAConfigPtrs ) {
xfree( pConfigs );
xfree( pMGAConfigs );
return FALSE;
}
for ( i = 0 ; i < numConfigs ; i++ ) {
pMGAConfigPtrs[i] = &pMGAConfigs[i];
}
i = 0;
for ( accum = 0 ; accum <= 1 ; accum++ ) {
for ( depth = 0 ; depth <= 1 ; depth++ ) { /* and stencil */
for ( db = 1 ; db >= 0 ; db-- ) {
pConfigs[i].vid = -1;
pConfigs[i].class = -1;
pConfigs[i].rgba = TRUE;
pConfigs[i].redSize = 8;
pConfigs[i].greenSize = 8;
pConfigs[i].blueSize = 8;
pConfigs[i].alphaSize = 8;
pConfigs[i].redMask = 0x00FF0000;
pConfigs[i].greenMask = 0x0000FF00;
pConfigs[i].blueMask = 0x000000FF;
pConfigs[i].alphaMask = 0;
if ( accum ) {
pConfigs[i].accumRedSize = 16;
pConfigs[i].accumGreenSize = 16;
pConfigs[i].accumBlueSize = 16;
pConfigs[i].accumAlphaSize = 0;
} else {
pConfigs[i].accumRedSize = 0;
pConfigs[i].accumGreenSize = 0;
pConfigs[i].accumBlueSize = 0;
pConfigs[i].accumAlphaSize = 0;
}
if ( db ) {
pConfigs[i].doubleBuffer = TRUE;
} else {
pConfigs[i].doubleBuffer = FALSE;
}
pConfigs[i].stereo = FALSE;
pConfigs[i].bufferSize = 32;
if ( depth ) {
pConfigs[i].depthSize = 24;
pConfigs[i].stencilSize = 8;
}
else {
pConfigs[i].depthSize = 0;
pConfigs[i].stencilSize = 0;
}
pConfigs[i].auxBuffers = 0;
pConfigs[i].level = 0;
if ( accum ) {
pConfigs[i].visualRating = GLX_SLOW_VISUAL_EXT;
} else {
pConfigs[i].visualRating = GLX_NONE_EXT;
}
pConfigs[i].transparentPixel = 0;
pConfigs[i].transparentRed = 0;
pConfigs[i].transparentGreen = 0;
pConfigs[i].transparentBlue = 0;
pConfigs[i].transparentAlpha = 0;
pConfigs[i].transparentIndex = 0;
i++;
}
}
}
if ( i != numConfigs ) {
xf86DrvMsg( pScrn->scrnIndex, X_ERROR,
"[drm] Incorrect initialization of visuals\n" );
return FALSE;
}
break;
default:
/* Unexpected bits/pixels */
break;
}
pMga->numVisualConfigs = numConfigs;
pMga->pVisualConfigs = pConfigs;
pMga->pVisualConfigsPriv = pMGAConfigs;
GlxSetVisualConfigs( numConfigs, pConfigs, (void **)pMGAConfigPtrs );
return TRUE;
}
static Bool MGACreateContext( ScreenPtr pScreen, VisualPtr visual,
drmContext hwContext, void *pVisualConfigPriv,
DRIContextType contextStore )
{
/* Nothing yet */
return TRUE;
}
static void MGADestroyContext( ScreenPtr pScreen, drmContext hwContext,
DRIContextType contextStore )
{
/* Nothing yet */
}
/* Quiescence, locking
*/
#define MGA_TIMEOUT 2048
static void MGAWaitForIdleDMA( ScrnInfoPtr pScrn )
{
MGAPtr pMga = MGAPTR(pScrn);
int ret;
int i = 0;
for (;;) {
do {
ret = drmMGAFlushDMA( pMga->drmFD,
DRM_LOCK_QUIESCENT | DRM_LOCK_FLUSH );
} while ( ( ret == -EBUSY ) && ( i++ < MGA_TIMEOUT ) );
if ( ret == 0 )
return;
xf86DrvMsg( pScrn->scrnIndex, X_ERROR,
"Idle timed out, resetting engine...\n" );
drmMGAEngineReset( pMga->drmFD );
}
}
void MGAGetQuiescence( ScrnInfoPtr pScrn )
{
MGAPtr pMga = MGAPTR(pScrn);
DRILock( screenInfo.screens[pScrn->scrnIndex], 0 );
pMga->haveQuiescense = 1;
if ( pMga->directRenderingEnabled ) {
MGAFBLayout *pLayout = &pMga->CurrentLayout;
MGAWaitForIdleDMA( pScrn );
WAITFIFO( 11 );
OUTREG( MGAREG_MACCESS, pMga->MAccess );
OUTREG( MGAREG_PITCH, pLayout->displayWidth );
pMga->PlaneMask = ~0;
OUTREG( MGAREG_PLNWT, pMga->PlaneMask );
pMga->BgColor = 0;
pMga->FgColor = 0;
OUTREG( MGAREG_BCOL, pMga->BgColor );
OUTREG( MGAREG_FCOL, pMga->FgColor );
OUTREG( MGAREG_SRCORG, pMga->realSrcOrg );
pMga->SrcOrg = 0;
OUTREG( MGAREG_DSTORG, pMga->DstOrg );
OUTREG( MGAREG_OPMODE, MGAOPM_DMA_BLIT );
OUTREG( MGAREG_CXBNDRY, 0xFFFF0000 ); /* (maxX << 16) | minX */
OUTREG( MGAREG_YTOP, 0x00000000 ); /* minPixelPointer */
OUTREG( MGAREG_YBOT, 0x007FFFFF ); /* maxPixelPointer */
pMga->AccelFlags &= ~CLIPPER_ON;
}
}
void MGAGetQuiescenceShared( ScrnInfoPtr pScrn )
{
MGAPtr pMga = MGAPTR(pScrn);
MGAEntPtr pMGAEnt = pMga->entityPrivate;
MGAPtr pMGA2 = MGAPTR(pMGAEnt->pScrn_2);
DRILock( screenInfo.screens[pMGAEnt->pScrn_1->scrnIndex], 0 );
pMga = MGAPTR(pMGAEnt->pScrn_1);
pMga->haveQuiescense = 1;
pMGA2->haveQuiescense = 1;
if ( pMGAEnt->directRenderingEnabled ) {
MGAWaitForIdleDMA( pMGAEnt->pScrn_1 );
pMga->RestoreAccelState( pScrn );
xf86SetLastScrnFlag( pScrn->entityList[0], pScrn->scrnIndex );
}
}
static void MGASwapContext( ScreenPtr pScreen )
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
MGAPtr pMga = MGAPTR(pScrn);
/* Arrange for dma_quiescence and xaa sync to be called as
* appropriate.
*/
pMga->haveQuiescense = 0;
pMga->AccelInfoRec->NeedToSync = TRUE;
}
static void MGASwapContextShared( ScreenPtr pScreen )
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
MGAPtr pMga = MGAPTR(pScrn);
MGAEntPtr pMGAEnt = pMga->entityPrivate;
MGAPtr pMGA2 = MGAPTR(pMGAEnt->pScrn_2);
pMga = MGAPTR(pMGAEnt->pScrn_1);
pMga->haveQuiescense = 0;
pMga->AccelInfoRec->NeedToSync = TRUE;
pMGA2->haveQuiescense = 0;
pMGA2->AccelInfoRec->NeedToSync = TRUE;
}
/* This is really only called from validate/postvalidate as we
* override the dri lock/unlock. Want to remove validate/postvalidate
* processing, but need to remove all client-side use of drawable lock
* first (otherwise there is noone recover when a client dies holding
* the drawable lock).
*
* What does this mean?
*
* - The above code gets executed every time a
* window changes shape or the focus changes, which isn't really
* optimal.
* - The X server therefore believes it needs to do an XAA sync
* *and* a dma quiescense ioctl each time that happens.
*
* We don't wrap wakeuphandler any longer, so at least we can say that
* this doesn't happen *every time the mouse moves*...
*/
static void
MGADRISwapContext( ScreenPtr pScreen, DRISyncType syncType,
DRIContextType oldContextType, void *oldContext,
DRIContextType newContextType, void *newContext )
{
#if 0
if ( syncType == DRI_3D_SYNC &&
oldContextType == DRI_2D_CONTEXT &&
newContextType == DRI_2D_CONTEXT )
{
MGASwapContext( pScreen );
}
#endif
}
static void
MGADRISwapContextShared( ScreenPtr pScreen, DRISyncType syncType,
DRIContextType oldContextType, void *oldContext,
DRIContextType newContextType, void *newContext )
{
#if 0
if ( syncType == DRI_3D_SYNC &&
oldContextType == DRI_2D_CONTEXT &&
newContextType == DRI_2D_CONTEXT )
{
MGASwapContextShared( pScreen );
}
#endif
}
static void MGAWakeupHandler( int screenNum, pointer wakeupData,
unsigned long result, pointer pReadmask )
{
ScreenPtr pScreen = screenInfo.screens[screenNum];
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
if ( xf86IsEntityShared( pScrn->entityList[0] ) ) {
MGASwapContextShared( pScreen );
} else {
MGASwapContext( pScreen );
}
}
static void MGABlockHandler( int screenNum, pointer blockData,
pointer pTimeout, pointer pReadmask )
{
ScreenPtr pScreen = screenInfo.screens[screenNum];
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
MGAPtr pMga = MGAPTR(pScrn);
MGAEntPtr pMGAEnt;
if ( pMga->haveQuiescense ) {
if ( xf86IsEntityShared( pScrn->entityList[0] ) ) {
/* Restore to first screen */
pMga->RestoreAccelState( pScrn );
xf86SetLastScrnFlag( pScrn->entityList[0], pScrn->scrnIndex );
pMGAEnt = pMga->entityPrivate;
if ( pMGAEnt->directRenderingEnabled ) {
DRIUnlock( screenInfo.screens[pMGAEnt->pScrn_1->scrnIndex] );
}
} else {
if ( pMga->directRenderingEnabled ) {
DRIUnlock( pScreen );
}
}
pMga->haveQuiescense = 0;
}
}
void MGASelectBuffer( ScrnInfoPtr pScrn, int which )
{
MGAPtr pMga = MGAPTR(pScrn);
MGADRIPtr pMGADRI = (MGADRIPtr)pMga->pDRIInfo->devPrivate;
switch ( which ) {
case MGA_BACK:
OUTREG( MGAREG_DSTORG, pMGADRI->backOffset );
OUTREG( MGAREG_SRCORG, pMGADRI->backOffset );
break;
case MGA_DEPTH:
OUTREG( MGAREG_DSTORG, pMGADRI->depthOffset );
OUTREG( MGAREG_SRCORG, pMGADRI->depthOffset );
break;
default:
case MGA_FRONT:
OUTREG( MGAREG_DSTORG, pMGADRI->frontOffset );
OUTREG( MGAREG_SRCORG, pMGADRI->frontOffset );
break;
}
}
static unsigned int mylog2( unsigned int n )
{
unsigned int log2 = 1;
while ( n > 1 ) n >>= 1, log2++;
return log2;
}
static Bool MGADRIAgpInit(ScreenPtr pScreen)
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
MGAPtr pMga = MGAPTR(pScrn);
MGADRIServerPrivatePtr pMGADRIServer = pMga->DRIServerInfo;
unsigned long mode;
unsigned int vendor, device;
int ret, count;
/* FIXME: Make these configurable...
*/
pMGADRIServer->agp.size = 12 * 1024 * 1024;
pMGADRIServer->warp.offset = 0;
pMGADRIServer->warp.size = MGA_WARP_UCODE_SIZE;
pMGADRIServer->primary.offset = (pMGADRIServer->warp.offset +
pMGADRIServer->warp.size);
pMGADRIServer->primary.size = 1024 * 1024;
pMGADRIServer->buffers.offset = (pMGADRIServer->primary.offset +
pMGADRIServer->primary.size);
pMGADRIServer->buffers.size = MGA_NUM_BUFFERS * MGA_BUFFER_SIZE;
if ( drmAgpAcquire( pMga->drmFD ) < 0 ) {
xf86DrvMsg( pScreen->myNum, X_ERROR, "[agp] AGP not available\n" );
return FALSE;
}
mode = drmAgpGetMode( pMga->drmFD ); /* Default mode */
vendor = drmAgpVendorId( pMga->drmFD );
device = drmAgpDeviceId( pMga->drmFD );
mode &= ~MGA_AGP_MODE_MASK;
switch ( pMga->agpMode ) {
case 4:
mode |= MGA_AGP_4X_MODE;
case 2:
mode |= MGA_AGP_2X_MODE;
case 1:
default:
mode |= MGA_AGP_1X_MODE;
}
xf86DrvMsg( pScreen->myNum, X_INFO,
"[agp] Mode 0x%08lx [AGP 0x%04x/0x%04x; Card 0x%04x/0x%04x]\n",
mode, vendor, device,
pMga->PciInfo->vendor,
pMga->PciInfo->chipType );
if ( drmAgpEnable( pMga->drmFD, mode ) < 0 ) {
xf86DrvMsg( pScreen->myNum, X_ERROR, "[agp] AGP not enabled\n" );
drmAgpRelease( pMga->drmFD );
return FALSE;
}
if ( pMga->Chipset == PCI_CHIP_MGAG200 ) {
switch ( pMga->agpMode ) {
case 2:
xf86DrvMsg( pScreen->myNum, X_INFO,
"[drm] Enabling AGP 2x PLL encoding\n" );
OUTREG( MGAREG_AGP_PLL, MGA_AGP2XPLL_ENABLE );
break;
case 1:
default:
xf86DrvMsg( pScreen->myNum, X_INFO,
"[drm] Disabling AGP 2x PLL encoding\n" );
OUTREG( MGAREG_AGP_PLL, MGA_AGP2XPLL_DISABLE );
pMga->agpMode = 1;
break;
}
}
ret = drmAgpAlloc( pMga->drmFD, pMGADRIServer->agp.size,
0, NULL, &pMGADRIServer->agp.handle );
if ( ret < 0 ) {
xf86DrvMsg( pScreen->myNum, X_ERROR, "[agp] Out of memory (%d)\n", ret );
drmAgpRelease( pMga->drmFD );
return FALSE;
}
xf86DrvMsg( pScreen->myNum, X_INFO,
"[agp] %d kB allocated with handle 0x%08x\n",
pMGADRIServer->agp.size/1024, pMGADRIServer->agp.handle );
if ( drmAgpBind( pMga->drmFD, pMGADRIServer->agp.handle, 0 ) < 0 ) {
xf86DrvMsg( pScreen->myNum, X_ERROR, "[agp] Could not bind memory\n" );
drmAgpFree( pMga->drmFD, pMGADRIServer->agp.handle );
drmAgpRelease( pMga->drmFD );
return FALSE;
}
/* WARP microcode space
*/
if ( drmAddMap( pMga->drmFD,
pMGADRIServer->warp.offset,
pMGADRIServer->warp.size,
DRM_AGP, DRM_READ_ONLY,
&pMGADRIServer->warp.handle ) < 0 ) {
xf86DrvMsg( pScreen->myNum, X_ERROR,
"[agp] Could not add WARP microcode mapping\n" );
return FALSE;
}
xf86DrvMsg( pScreen->myNum, X_INFO,
"[agp] WARP microcode handle = 0x%08lx\n",
pMGADRIServer->warp.handle );
if ( drmMap( pMga->drmFD,
pMGADRIServer->warp.handle,
pMGADRIServer->warp.size,
&pMGADRIServer->warp.map ) < 0 ) {
xf86DrvMsg( pScreen->myNum, X_ERROR,
"[agp] Could not map WARP microcode\n" );
return FALSE;
}
xf86DrvMsg( pScreen->myNum, X_INFO,
"[agp] WARP microcode mapped at 0x%08lx\n",
(unsigned long)pMGADRIServer->warp.map );
/* Primary DMA space
*/
if ( drmAddMap( pMga->drmFD,
pMGADRIServer->primary.offset,
pMGADRIServer->primary.size,
DRM_AGP, DRM_READ_ONLY,
&pMGADRIServer->primary.handle ) < 0 ) {
xf86DrvMsg( pScreen->myNum, X_ERROR,
"[agp] Could not add primary DMA mapping\n" );
return FALSE;
}
xf86DrvMsg( pScreen->myNum, X_INFO,
"[agp] Primary DMA handle = 0x%08lx\n",
pMGADRIServer->primary.handle );
if ( drmMap( pMga->drmFD,
pMGADRIServer->primary.handle,
pMGADRIServer->primary.size,
&pMGADRIServer->primary.map ) < 0 ) {
xf86DrvMsg( pScreen->myNum, X_ERROR,
"[agp] Could not map primary DMA\n" );
return FALSE;
}
xf86DrvMsg( pScreen->myNum, X_INFO,
"[agp] Primary DMA mapped at 0x%08lx\n",
(unsigned long)pMGADRIServer->primary.map );
/* DMA buffers
*/
if ( drmAddMap( pMga->drmFD,
pMGADRIServer->buffers.offset,
pMGADRIServer->buffers.size,
DRM_AGP, 0,
&pMGADRIServer->buffers.handle ) < 0 ) {
xf86DrvMsg( pScreen->myNum, X_ERROR,
"[agp] Could not add DMA buffers mapping\n" );
return FALSE;
}
xf86DrvMsg( pScreen->myNum, X_INFO,
"[agp] DMA buffers handle = 0x%08lx\n",
pMGADRIServer->buffers.handle );
if ( drmMap( pMga->drmFD,
pMGADRIServer->buffers.handle,
pMGADRIServer->buffers.size,
&pMGADRIServer->buffers.map ) < 0 ) {
xf86DrvMsg( pScreen->myNum, X_ERROR,
"[agp] Could not map DMA buffers\n" );
return FALSE;
}
xf86DrvMsg( pScreen->myNum, X_INFO,
"[agp] DMA buffers mapped at 0x%08lx\n",
(unsigned long)pMGADRIServer->buffers.map );
count = drmAddBufs( pMga->drmFD,
MGA_NUM_BUFFERS, MGA_BUFFER_SIZE,
DRM_AGP_BUFFER, pMGADRIServer->buffers.offset );
if ( count <= 0 ) {
xf86DrvMsg( pScrn->scrnIndex, X_INFO,
"[drm] failure adding %d %d byte DMA buffers\n",
MGA_NUM_BUFFERS, MGA_BUFFER_SIZE );
return FALSE;
}
xf86DrvMsg( pScreen->myNum, X_INFO,
"[drm] Added %d %d byte DMA buffers\n",
count, MGA_BUFFER_SIZE );
xf86EnablePciBusMaster( pMga->PciInfo, TRUE );
return TRUE;
}
static Bool MGADRIMapInit( ScreenPtr pScreen )
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
MGAPtr pMga = MGAPTR(pScrn);
MGADRIServerPrivatePtr pMGADRIServer = pMga->DRIServerInfo;
pMGADRIServer->registers.size = MGAIOMAPSIZE;
if ( drmAddMap( pMga->drmFD,
(drmHandle)pMga->IOAddress,
pMGADRIServer->registers.size,
DRM_REGISTERS, DRM_READ_ONLY,
&pMGADRIServer->registers.handle ) < 0 ) {
xf86DrvMsg( pScreen->myNum, X_ERROR,
"[drm] Could not add MMIO registers mapping\n" );
return FALSE;
}
xf86DrvMsg( pScreen->myNum, X_INFO,
"[drm] Registers handle = 0x%08lx\n",
pMGADRIServer->registers.handle );
pMGADRIServer->status.size = SAREA_MAX;
if ( drmAddMap( pMga->drmFD, 0, pMGADRIServer->status.size,
DRM_SHM, DRM_READ_ONLY | DRM_LOCKED | DRM_KERNEL,
&pMGADRIServer->status.handle ) < 0 ) {
xf86DrvMsg( pScreen->myNum, X_ERROR,
"[drm] Could not add status page mapping\n" );
return FALSE;
}
xf86DrvMsg( pScreen->myNum, X_INFO,
"[drm] Status handle = 0x%08lx\n",
pMGADRIServer->status.handle );
if ( drmMap( pMga->drmFD,
pMGADRIServer->status.handle,
pMGADRIServer->status.size,
&pMGADRIServer->status.map ) < 0 ) {
xf86DrvMsg( pScreen->myNum, X_ERROR,
"[agp] Could not map status page\n" );
return FALSE;
}
xf86DrvMsg( pScreen->myNum, X_INFO,
"[agp] Status page mapped at 0x%08lx\n",
(unsigned long)pMGADRIServer->status.map );
return TRUE;
}
static Bool MGADRIKernelInit( ScreenPtr pScreen )
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
MGAPtr pMga = MGAPTR(pScrn);
MGADRIServerPrivatePtr pMGADRIServer = pMga->DRIServerInfo;
drmMGAInit init;
int ret;
memset( &init, 0, sizeof(drmMGAInit) );
init.sarea_priv_offset = sizeof(XF86DRISAREARec);
switch ( pMga->Chipset ) {
case PCI_CHIP_MGAG400:
init.chipset = MGA_CARD_TYPE_G400;
break;
case PCI_CHIP_MGAG200:
case PCI_CHIP_MGAG200_PCI:
init.chipset = MGA_CARD_TYPE_G200;
break;
default:
return FALSE;
}
init.sgram = !pMga->HasSDRAM;
init.maccess = pMga->MAccess;
init.fb_cpp = pScrn->bitsPerPixel / 8;
init.front_offset = pMGADRIServer->frontOffset;
init.front_pitch = pMGADRIServer->frontPitch / init.fb_cpp;
init.back_offset = pMGADRIServer->backOffset;
init.back_pitch = pMGADRIServer->backPitch / init.fb_cpp;
init.depth_cpp = pScrn->bitsPerPixel / 8;
init.depth_offset = pMGADRIServer->depthOffset;
init.depth_pitch = pMGADRIServer->depthPitch / init.depth_cpp;
init.texture_offset[0] = pMGADRIServer->textureOffset;
init.texture_size[0] = pMGADRIServer->textureSize;
init.fb_offset = pMga->FbAddress;
init.mmio_offset = pMGADRIServer->registers.handle;
init.status_offset = pMGADRIServer->status.handle;
init.warp_offset = pMGADRIServer->warp.handle;
init.primary_offset = pMGADRIServer->primary.handle;
init.buffers_offset = pMGADRIServer->buffers.handle;
ret = drmMGAInitDMA( pMga->drmFD, &init );
if ( ret < 0 ) {
xf86DrvMsg( pScrn->scrnIndex, X_ERROR,
"[drm] Failed to initialize DMA! (%d)\n", ret );
return FALSE;
}
#if 0
/* FIXME: This is just here to clean up after the engine reset test
* in the kernel module. Please remove it later...
*/
pMga->GetQuiescence( pScrn );
#endif
return TRUE;
}
static Bool MGADRIBuffersInit( ScreenPtr pScreen )
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
MGAPtr pMga = MGAPTR(pScrn);
MGADRIServerPrivatePtr pMGADRIServer = pMga->DRIServerInfo;
pMGADRIServer->drmBuffers = drmMapBufs( pMga->drmFD );
if ( !pMGADRIServer->drmBuffers ) {
xf86DrvMsg( pScreen->myNum, X_ERROR,
"[drm] Failed to map DMA buffers list\n" );
return FALSE;
}
xf86DrvMsg( pScreen->myNum, X_INFO,
"[drm] Mapped %d DMA buffers\n",
pMGADRIServer->drmBuffers->count );
return TRUE;
}
Bool MGADRIScreenInit( ScreenPtr pScreen )
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
MGAPtr pMga = MGAPTR(pScrn);
DRIInfoPtr pDRIInfo;
MGADRIPtr pMGADRI;
MGADRIServerPrivatePtr pMGADRIServer;
switch ( pMga->Chipset ) {
case PCI_CHIP_MGAG400:
case PCI_CHIP_MGAG200:
#if 0
case PCI_CHIP_MGAG200_PCI:
#endif
break;
default:
xf86DrvMsg( pScrn->scrnIndex, X_ERROR,
"[drm] Direct rendering only supported with AGP G200/G400 cards!\n" );
return FALSE;
}
/* Check that the GLX, DRI, and DRM modules have been loaded by testing
* for canonical symbols in each module.
*/
if ( !xf86LoaderCheckSymbol( "GlxSetVisualConfigs" ) ) return FALSE;
if ( !xf86LoaderCheckSymbol( "DRIScreenInit" ) ) return FALSE;
if ( !xf86LoaderCheckSymbol( "drmAvailable" ) ) return FALSE;
if ( !xf86LoaderCheckSymbol( "DRIQueryVersion" ) ) {
xf86DrvMsg( pScreen->myNum, X_ERROR,
"MGADRIScreenInit failed (libdri.a too old)\n" );
return FALSE;
}
/* Check the DRI version */
{
int major, minor, patch;
DRIQueryVersion( &major, &minor, &patch );
if ( major != 4 || minor < 0) {
xf86DrvMsg( pScreen->myNum, X_ERROR,
"[drm] MGADRIScreenInit failed "
"(DRI version = %d.%d.%d, expected 4.0.x). "
"Disabling DRI.\n",
major, minor, patch );
return FALSE;
}
}
xf86DrvMsg( pScreen->myNum, X_INFO,
"[drm] bpp: %d depth: %d\n",
pScrn->bitsPerPixel, pScrn->depth );
if ( (pScrn->bitsPerPixel / 8) != 2 &&
(pScrn->bitsPerPixel / 8) != 4 ) {
xf86DrvMsg( pScreen->myNum, X_INFO,
"[drm] Direct rendering only supported in 16 and 32 bpp modes\n" );
return FALSE;
}
pDRIInfo = DRICreateInfoRec();
if ( !pDRIInfo )
return FALSE;
pMga->pDRIInfo = pDRIInfo;
pDRIInfo->drmDriverName = MGAKernelDriverName;
pDRIInfo->clientDriverName = MGAClientDriverName;
pDRIInfo->busIdString = xalloc(64);
sprintf( pDRIInfo->busIdString, "PCI:%d:%d:%d",
((pciConfigPtr)pMga->PciInfo->thisCard)->busnum,
((pciConfigPtr)pMga->PciInfo->thisCard)->devnum,
((pciConfigPtr)pMga->PciInfo->thisCard)->funcnum );
pDRIInfo->ddxDriverMajorVersion = MGA_MAJOR_VERSION;
pDRIInfo->ddxDriverMinorVersion = MGA_MINOR_VERSION;
pDRIInfo->ddxDriverPatchVersion = MGA_PATCHLEVEL;
pDRIInfo->frameBufferPhysicalAddress = pMga->FbAddress;
pDRIInfo->frameBufferSize = pMga->FbMapSize;
pDRIInfo->frameBufferStride = pScrn->displayWidth*(pScrn->bitsPerPixel/8);
pDRIInfo->ddxDrawableTableEntry = MGA_MAX_DRAWABLES;
pDRIInfo->wrap.BlockHandler = MGABlockHandler;
pDRIInfo->wrap.WakeupHandler = MGAWakeupHandler;
pDRIInfo->wrap.ValidateTree = NULL;
pDRIInfo->wrap.PostValidateTree = NULL;
pDRIInfo->createDummyCtx = TRUE;
pDRIInfo->createDummyCtxPriv = FALSE;
if ( SAREA_MAX_DRAWABLES < MGA_MAX_DRAWABLES ) {
pDRIInfo->maxDrawableTableEntry = SAREA_MAX_DRAWABLES;
} else {
pDRIInfo->maxDrawableTableEntry = MGA_MAX_DRAWABLES;
}
/* For now the mapping works by using a fixed size defined
* in the SAREA header.
*/
if ( sizeof(XF86DRISAREARec) + sizeof(MGASAREAPrivRec) > SAREA_MAX ) {
xf86DrvMsg( pScrn->scrnIndex, X_ERROR,
"[drm] Data does not fit in SAREA\n" );
return FALSE;
}
xf86DrvMsg( pScrn->scrnIndex, X_INFO,
"[drm] Sarea %d+%d: %d\n",
sizeof(XF86DRISAREARec), sizeof(MGASAREAPrivRec),
sizeof(XF86DRISAREARec) + sizeof(MGASAREAPrivRec) );
pDRIInfo->SAREASize = SAREA_MAX;
pMGADRI = (MGADRIPtr)xnfcalloc( sizeof(MGADRIRec), 1 );
if ( !pMGADRI ) {
DRIDestroyInfoRec( pMga->pDRIInfo );
pMga->pDRIInfo = 0;
xf86DrvMsg( pScrn->scrnIndex, X_ERROR,
"[drm] Failed to allocate memory for private record\n" );
return FALSE;
}
pMGADRIServer = (MGADRIServerPrivatePtr)
xnfcalloc( sizeof(MGADRIServerPrivateRec), 1 );
if ( !pMGADRIServer ) {
xfree( pMGADRI );
DRIDestroyInfoRec( pMga->pDRIInfo );
pMga->pDRIInfo = 0;
xf86DrvMsg( pScrn->scrnIndex, X_ERROR,
"[drm] Failed to allocate memory for private record\n" );
return FALSE;
}
pMga->DRIServerInfo = pMGADRIServer;
pDRIInfo->devPrivate = pMGADRI;
pDRIInfo->devPrivateSize = sizeof(MGADRIRec);
pDRIInfo->contextSize = sizeof(MGADRIContextRec);
pDRIInfo->CreateContext = MGACreateContext;
pDRIInfo->DestroyContext = MGADestroyContext;
if ( xf86IsEntityShared( pScrn->entityList[0] ) ) {
pDRIInfo->SwapContext = MGADRISwapContextShared;
} else {
pDRIInfo->SwapContext = MGADRISwapContext;
}
switch( pScrn->bitsPerPixel ) {
case 8:
pDRIInfo->InitBuffers = Mga8DRIInitBuffers;
pDRIInfo->MoveBuffers = Mga8DRIMoveBuffers;
case 16:
pDRIInfo->InitBuffers = Mga16DRIInitBuffers;
pDRIInfo->MoveBuffers = Mga16DRIMoveBuffers;
case 24:
pDRIInfo->InitBuffers = Mga24DRIInitBuffers;
pDRIInfo->MoveBuffers = Mga24DRIMoveBuffers;
case 32:
pDRIInfo->InitBuffers = Mga32DRIInitBuffers;
pDRIInfo->MoveBuffers = Mga32DRIMoveBuffers;
}
pDRIInfo->bufferRequests = DRI_ALL_WINDOWS;
if ( !DRIScreenInit( pScreen, pDRIInfo, &pMga->drmFD ) ) {
xfree( pMGADRIServer );
pMga->DRIServerInfo = 0;
xfree( pDRIInfo->devPrivate );
pDRIInfo->devPrivate = 0;
DRIDestroyInfoRec( pMga->pDRIInfo );
pMga->pDRIInfo = 0;
xf86DrvMsg( pScreen->myNum, X_ERROR,
"[drm] DRIScreenInit Failed\n" );
return FALSE;
}
/* Check the MGA DRM version */
{
drmVersionPtr version = drmGetVersion(pMga->drmFD);
if ( version ) {
if ( version->version_major != 3 ||
version->version_minor < 0) {
/* incompatible drm version */
xf86DrvMsg( pScreen->myNum, X_ERROR,
"[drm] MGADRIScreenInit failed "
"(DRM version = %d.%d.%d, expected 3.0.x). "
"Disabling DRI.\n",
version->version_major,
version->version_minor,
version->version_patchlevel );
drmFreeVersion( version );
MGADRICloseScreen( pScreen ); /* FIXME: ??? */
return FALSE;
}
drmFreeVersion( version );
}
}
#if 0
/* Calculate texture constants for AGP texture space.
* FIXME: move!
*/
{
CARD32 agpTextureOffset = MGA_DMA_BUF_SZ * MGA_DMA_BUF_NR;
CARD32 agpTextureSize = pMGADRI->agp.size - agpTextureOffset;
i = mylog2(agpTextureSize / MGA_NR_TEX_REGIONS);
if (i < MGA_LOG_MIN_TEX_REGION_SIZE)
i = MGA_LOG_MIN_TEX_REGION_SIZE;
pMGADRI->logAgpTextureGranularity = i;
pMGADRI->agpTextureSize = (agpTextureSize >> i) << i;
pMGADRI->agpTextureOffset = agpTextureOffset;
}
#endif
if ( !MGADRIAgpInit( pScreen ) ) {
DRICloseScreen( pScreen );
return FALSE;
}
if ( !MGADRIMapInit( pScreen ) ) {
DRICloseScreen( pScreen );
return FALSE;
}
if ( !MGAInitVisualConfigs( pScreen ) ) {
DRICloseScreen( pScreen );
return FALSE;
}
xf86DrvMsg( pScrn->scrnIndex, X_INFO, "visual configs initialized\n" );
return TRUE;
}
Bool MGADRIFinishScreenInit( ScreenPtr pScreen )
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
MGAPtr pMga = MGAPTR(pScrn);
MGADRIServerPrivatePtr pMGADRIServer = pMga->DRIServerInfo;
MGADRIPtr pMGADRI = (MGADRIPtr)pMga->pDRIInfo->devPrivate;
int i;
if ( !pMga->pDRIInfo )
return FALSE;
pMga->pDRIInfo->driverSwapMethod = DRI_HIDE_X_CONTEXT;
/* NOTE: DRIFinishScreenInit must be called before *DRIKernelInit
* because *DRIKernelInit requires that the hardware lock is held by
* the X server, and the first time the hardware lock is grabbed is
* in DRIFinishScreenInit.
*/
if ( !DRIFinishScreenInit( pScreen ) ) {
MGADRICloseScreen( pScreen );
return FALSE;
}
if ( !MGADRIKernelInit( pScreen ) ) {
MGADRICloseScreen( pScreen );
return FALSE;
}
if ( !MGADRIBuffersInit( pScreen ) ) {
MGADRICloseScreen( pScreen );
return FALSE;
}
switch ( pMga->Chipset ) {
case PCI_CHIP_MGAG400:
pMGADRI->chipset = MGA_CARD_TYPE_G400;
break;
case PCI_CHIP_MGAG200:
case PCI_CHIP_MGAG200_PCI:
pMGADRI->chipset = MGA_CARD_TYPE_G200;
break;
default:
return FALSE;
}
pMGADRI->width = pScrn->virtualX;
pMGADRI->height = pScrn->virtualY;
pMGADRI->mem = pScrn->videoRam * 1024;
pMGADRI->cpp = pScrn->bitsPerPixel / 8;
pMGADRI->agpMode = pMga->agpMode;
pMGADRI->frontOffset = pMGADRIServer->frontOffset;
pMGADRI->frontPitch = pMGADRIServer->frontPitch;
pMGADRI->backOffset = pMGADRIServer->backOffset;
pMGADRI->backPitch = pMGADRIServer->backPitch;
pMGADRI->depthOffset = pMGADRIServer->depthOffset;
pMGADRI->depthPitch = pMGADRIServer->depthPitch;
pMGADRI->textureOffset = pMGADRIServer->textureOffset;
pMGADRI->textureSize = pMGADRIServer->textureSize;
i = mylog2( pMGADRI->textureSize / MGA_NR_TEX_REGIONS );
if ( i < MGA_LOG_MIN_TEX_REGION_SIZE )
i = MGA_LOG_MIN_TEX_REGION_SIZE;
pMGADRI->logTextureGranularity = i;
pMGADRI->textureSize = (pMGADRI->textureSize >> i) << i; /* truncate */
pMGADRI->registers.handle = pMGADRIServer->registers.handle;
pMGADRI->registers.size = pMGADRIServer->registers.size;
pMGADRI->status.handle = pMGADRIServer->status.handle;
pMGADRI->status.size = pMGADRIServer->status.size;
pMGADRI->primary.handle = pMGADRIServer->primary.handle;
pMGADRI->primary.size = pMGADRIServer->primary.size;
pMGADRI->buffers.handle = pMGADRIServer->buffers.handle;
pMGADRI->buffers.size = pMGADRIServer->buffers.size;
pMGADRI->sarea_priv_offset = sizeof(XF86DRISAREARec);
return TRUE;
}
void MGADRICloseScreen( ScreenPtr pScreen )
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
MGAPtr pMga = MGAPTR(pScrn);
MGADRIServerPrivatePtr pMGADRIServer = pMga->DRIServerInfo;
if ( pMGADRIServer->drmBuffers ) {
drmUnmapBufs( pMGADRIServer->drmBuffers );
pMGADRIServer->drmBuffers = NULL;
}
drmMGACleanupDMA( pMga->drmFD );
if ( pMGADRIServer->status.map ) {
drmUnmap( pMGADRIServer->status.map, pMGADRIServer->status.size );
pMGADRIServer->status.map = NULL;
}
if ( pMGADRIServer->buffers.map ) {
drmUnmap( pMGADRIServer->buffers.map, pMGADRIServer->buffers.size );
pMGADRIServer->buffers.map = NULL;
}
if ( pMGADRIServer->primary.map ) {
drmUnmap( pMGADRIServer->primary.map, pMGADRIServer->primary.size );
pMGADRIServer->primary.map = NULL;
}
if ( pMGADRIServer->warp.map ) {
drmUnmap( pMGADRIServer->warp.map, pMGADRIServer->warp.size );
pMGADRIServer->warp.map = NULL;
}
if ( pMGADRIServer->agp.handle ) {
drmAgpUnbind( pMga->drmFD, pMGADRIServer->agp.handle );
drmAgpFree( pMga->drmFD, pMGADRIServer->agp.handle );
pMGADRIServer->agp.handle = 0;
drmAgpRelease( pMga->drmFD );
}
DRICloseScreen( pScreen );
if ( pMga->pDRIInfo ) {
if ( pMga->pDRIInfo->devPrivate ) {
xfree( pMga->pDRIInfo->devPrivate );
pMga->pDRIInfo->devPrivate = 0;
}
DRIDestroyInfoRec( pMga->pDRIInfo );
pMga->pDRIInfo = 0;
}
if ( pMga->DRIServerInfo ) {
xfree( pMga->DRIServerInfo );
pMga->DRIServerInfo = 0;
}
if ( pMga->pVisualConfigs ) {
xfree( pMga->pVisualConfigs );
}
if ( pMga->pVisualConfigsPriv ) {
xfree( pMga->pVisualConfigsPriv );
}
}
|