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
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
|
/* $xfree86: xc/programs/Xserver/hw/xfree86/drivers/i810/i830_dri.c,v 1.15 2003/06/18 13:14:17 dawes Exp $ */
/**************************************************************************
Copyright 2001 VA Linux Systems Inc., Fremont, California.
Copyright © 2002 by David Dawes
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
on the rights to use, copy, modify, merge, publish, distribute, sub
license, 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 NON-INFRINGEMENT. IN NO EVENT SHALL
ATI, VA LINUX SYSTEMS AND/OR THEIR 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.
**************************************************************************/
/*
* Reformatted with GNU indent (2.2.8), using the following options:
*
* -bad -bap -c41 -cd0 -ncdb -ci6 -cli0 -cp0 -ncs -d0 -di3 -i3 -ip3 -l78
* -lp -npcs -psl -sob -ss -br -ce -sc -hnl
*
* This provides a good match with the original i810 code and preferred
* XFree86 formatting conventions.
*
* When editing this driver, please follow the existing formatting, and edit
* with <TAB> characters expanded at 8-column intervals.
*/
/*
* Authors: Jeff Hartmann <jhartmann@valinux.com>
* David Dawes <dawes@xfree86.org>
* Keith Whitwell <keith@tungstengraphics.com>
*/
/*
* This driver does AGP memory allocation a little differently from most
* others. The 2D and 3D allocations have been unified (see i830_memory.c).
* The driver does the AGP allocations and binding directly, then passes
* on the mappings to the DRM module. The DRM's AGP interfaces are not used.
* The main difference with this is that the offsets need to include
* the AGP aperture base address because that won't be known or added on
* by the DRM module.
*
* DHD 07/2002
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include "xf86.h"
#include "xf86_OSproc.h"
#include "xf86Priv.h"
#include "xf86PciInfo.h"
#include "xf86Pci.h"
#include "windowstr.h"
#include "shadow.h"
#include "GL/glxtokens.h"
#include "i830.h"
#include "i830_dri.h"
#include "i915_drm.h"
#include "dristruct.h"
#ifdef DRI2
#include "dri2.h"
#if DRI2INFOREC_VERSION >= 1
#define USE_DRI2_1_1_0
#endif
extern XF86ModuleData dri2ModuleData;
#endif
static Bool I830InitVisualConfigs(ScreenPtr pScreen);
static Bool I830CreateContext(ScreenPtr pScreen, VisualPtr visual,
drm_context_t hwContext, void *pVisualConfigPriv,
DRIContextType contextStore);
static void I830DestroyContext(ScreenPtr pScreen, drm_context_t hwContext,
DRIContextType contextStore);
static void I830DRISwapContext(ScreenPtr pScreen, DRISyncType syncType,
DRIContextType readContextType,
void *readContextStore,
DRIContextType writeContextType,
void *writeContextStore);
static void I830DRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index);
static void I830DRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg,
RegionPtr prgnSrc, CARD32 index);
static void I830DRITransitionTo2d(ScreenPtr pScreen);
static void I830DRITransitionTo3d(ScreenPtr pScreen);
#if (DRIINFO_MAJOR_VERSION > 5 || \
(DRIINFO_MAJOR_VERSION == 5 && DRIINFO_MINOR_VERSION >= 4))
#define DRI_DRIVER_FRAMEBUFFER_MAP 1
#else
#define DRI_DRIVER_FRAMEBUFFER_MAP 0
#endif
extern void GlxSetVisualConfigs(int nconfigs,
__GLXvisualConfig * configs,
void **configprivs);
static Bool
I830CleanupDma(ScrnInfoPtr pScrn)
{
I830Ptr pI830 = I830PTR(pScrn);
drmI830Init info;
memset(&info, 0, sizeof(drmI830Init));
info.func = I830_CLEANUP_DMA;
if (drmCommandWrite(pI830->drmSubFD, DRM_I830_INIT,
&info, sizeof(drmI830Init))) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "I830 Dma Cleanup Failed\n");
return FALSE;
}
return TRUE;
}
static Bool
I830InitDma(ScrnInfoPtr pScrn)
{
I830Ptr pI830 = I830PTR(pScrn);
I830RingBuffer *ring = &pI830->ring;
I830DRIPtr pI830DRI = (I830DRIPtr) pI830->pDRIInfo->devPrivate;
drmI830Init info;
memset(&info, 0, sizeof(drmI830Init));
info.func = I830_INIT_DMA;
/* Initialize fields that are used in the absence of GEM */
if (!pI830->memory_manager && !pI830->use_drm_mode) {
info.ring_start = ring->mem->offset + pI830->LinearAddr;
info.ring_end = ring->mem->end + pI830->LinearAddr;
info.ring_size = ring->mem->size;
/* Not used as of the middle of GEM development. */
info.mmio_offset = (unsigned int)pI830DRI->regs;
/* Not used as of before GEM development */
info.front_offset = pI830->front_buffer->offset;
info.back_offset = pI830->back_buffer->offset;
info.depth_offset = pI830->depth_buffer->offset;
info.pitch = pScrn->displayWidth;
info.back_pitch = pScrn->displayWidth;
info.depth_pitch = pScrn->displayWidth;
info.w = pScrn->virtualX;
info.h = pScrn->virtualY;
}
info.sarea_priv_offset = sizeof(XF86DRISAREARec);
/* This should probably have been moved alongside offset/pitch in the sarea.
*/
info.cpp = pI830->cpp;
if (drmCommandWrite(pI830->drmSubFD, DRM_I830_INIT,
&info, sizeof(drmI830Init))) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"I830 Dma Initialization Failed\n");
return FALSE;
}
return TRUE;
}
static Bool
I830ResumeDma(ScrnInfoPtr pScrn)
{
I830Ptr pI830 = I830PTR(pScrn);
drmI830Init info;
memset(&info, 0, sizeof(drmI830Init));
info.func = I830_RESUME_DMA;
if (drmCommandWrite(pI830->drmSubFD, DRM_I830_INIT,
&info, sizeof(drmI830Init))) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "I830 Dma Resume Failed\n");
return FALSE;
}
return TRUE;
}
static Bool
I830SetParam(ScrnInfoPtr pScrn, int param, int value)
{
I830Ptr pI830 = I830PTR(pScrn);
drmI830SetParam sp;
memset(&sp, 0, sizeof(sp));
sp.param = param;
sp.value = value;
if (drmCommandWrite(pI830->drmSubFD, DRM_I830_SETPARAM, &sp, sizeof(sp))) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "I830 SetParam Failed\n");
return FALSE;
}
return TRUE;
}
Bool
I830DRISetHWS(ScrnInfoPtr pScrn)
{
I830Ptr pI830 = I830PTR(pScrn);
drmI830HWS hws;
hws.addr = pI830->hw_status->offset;
if (drmCommandWrite(pI830->drmSubFD, DRM_I830_HWS_PAGE_ADDR,
&hws, sizeof(drmI830HWS))) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"hw status page initialization Failed\n");
return FALSE;
}
return TRUE;
}
static Bool
I830InitVisualConfigs(ScreenPtr pScreen)
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
I830Ptr pI830 = I830PTR(pScrn);
int numConfigs = 0;
__GLXvisualConfig *pConfigs = NULL;
I830ConfigPrivPtr pI830Configs = NULL;
I830ConfigPrivPtr *pI830ConfigPtrs = NULL;
int accum, stencil, db, depth;
int i;
switch (pScrn->bitsPerPixel) {
case 8:
case 24:
break;
case 16:
numConfigs = 8;
pConfigs =
(__GLXvisualConfig *) xcalloc(sizeof(__GLXvisualConfig),
numConfigs);
if (!pConfigs)
return FALSE;
pI830Configs =
(I830ConfigPrivPtr) xcalloc(sizeof(I830ConfigPrivRec),
numConfigs);
if (!pI830Configs) {
xfree(pConfigs);
return FALSE;
}
pI830ConfigPtrs =
(I830ConfigPrivPtr *) xcalloc(sizeof(I830ConfigPrivPtr),
numConfigs);
if (!pI830ConfigPtrs) {
xfree(pConfigs);
xfree(pI830Configs);
return FALSE;
}
for (i = 0; i < numConfigs; i++)
pI830ConfigPtrs[i] = &pI830Configs[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;
}
pConfigs[i].doubleBuffer = db ? TRUE : 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 (stencil || accum)
pConfigs[i].visualRating = GLX_SLOW_VISUAL_EXT;
else
pConfigs[i].visualRating = GLX_NONE_EXT;
pConfigs[i].transparentPixel = GLX_NONE_EXT;
pConfigs[i].transparentRed = 0;
pConfigs[i].transparentGreen = 0;
pConfigs[i].transparentBlue = 0;
pConfigs[i].transparentAlpha = 0;
pConfigs[i].transparentIndex = 0;
i++;
}
}
}
assert(i == numConfigs);
break;
case 32:
numConfigs = 8;
pConfigs = (__GLXvisualConfig *) xcalloc(sizeof(__GLXvisualConfig),
numConfigs);
if (!pConfigs) {
return FALSE;
}
pI830Configs = (I830ConfigPrivPtr) xcalloc(sizeof(I830ConfigPrivRec),
numConfigs);
if (!pI830Configs) {
xfree(pConfigs);
return FALSE;
}
pI830ConfigPtrs = (I830ConfigPrivPtr *)
xcalloc(sizeof(I830ConfigPrivPtr), numConfigs);
if (!pI830ConfigPtrs) {
xfree(pConfigs);
xfree(pI830Configs);
return FALSE;
}
for (i = 0; i < numConfigs; i++) {
pI830ConfigPtrs[i] = &pI830Configs[i];
}
i = 0;
for (accum = 0; accum <= 1; accum++) {
for (depth = 1; depth >= 0; 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 = 0xFF000000;
if (accum) {
pConfigs[i].accumRedSize = 16;
pConfigs[i].accumGreenSize = 16;
pConfigs[i].accumBlueSize = 16;
pConfigs[i].accumAlphaSize = 16;
} 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 = GLX_NONE_EXT;
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;
}
pI830->numVisualConfigs = numConfigs;
pI830->pVisualConfigs = pConfigs;
pI830->pVisualConfigsPriv = pI830Configs;
GlxSetVisualConfigs(numConfigs, pConfigs, (void **)pI830ConfigPtrs);
return TRUE;
}
Bool
I830CheckDRIAvailable(ScrnInfoPtr pScrn)
{
/* Hardware 3D rendering only implemented for 16bpp and 32 bpp */
if (((pScrn->bitsPerPixel / 8) != 2 && pScrn->depth != 16) &&
(pScrn->bitsPerPixel / 8) != 4) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"[drm] Direct rendering only supported in 16 and 32 bpp modes\n");
return FALSE;
}
/* Check that the GLX, DRI, and DRM modules have been loaded by testing
* for known symbols in each module. */
if (!xf86LoaderCheckSymbol("GlxSetVisualConfigs")) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"[dri] %s failed: glx not loaded\n", __FUNCTION__);
return FALSE;
}
if (!xf86LoaderCheckSymbol("DRIScreenInit")) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"[dri] %s failed: dri not loaded\n", __FUNCTION__);
return FALSE;
}
if (!xf86LoaderCheckSymbol("drmAvailable")) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"[dri] %s failed: libdrm not loaded\n", __FUNCTION__);
return FALSE;
}
if (!xf86LoaderCheckSymbol("DRIQueryVersion")) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"[dri] %s failed (libdri.a too old)\n", __FUNCTION__);
return FALSE;
}
/* Check the DRI version */
{
int major, minor, patch;
DRIQueryVersion(&major, &minor, &patch);
if (major != DRIINFO_MAJOR_VERSION || minor < DRIINFO_MINOR_VERSION ||
major < 5) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"[dri] %s failed because of a version mismatch.\n"
"[dri] libDRI version is %d.%d.%d but version %d.%d.x is needed.\n"
"[dri] Disabling DRI.\n",
"I830CheckDRIAvailable", major, minor, patch,
DRIINFO_MAJOR_VERSION, DRIINFO_MINOR_VERSION);
return FALSE;
}
}
return TRUE;
}
Bool
I830DRIScreenInit(ScreenPtr pScreen)
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
I830Ptr pI830 = I830PTR(pScrn);
DRIInfoPtr pDRIInfo;
I830DRIPtr pI830DRI;
DPRINTF(PFX, "I830DRIScreenInit\n");
if (!I830CheckDRIAvailable(pScrn))
return FALSE;
pDRIInfo = DRICreateInfoRec();
if (!pDRIInfo) {
xf86DrvMsg(pScreen->myNum, X_ERROR,
"[dri] DRICreateInfoRec failed. Disabling DRI.\n");
return FALSE;
}
pI830->pDRIInfo = pDRIInfo;
pI830->LockHeld = 0;
pDRIInfo->drmDriverName = "i915";
if (IS_I965G(pI830))
pDRIInfo->clientDriverName = "i965";
else
pDRIInfo->clientDriverName = "i915";
if (xf86LoaderCheckSymbol("DRICreatePCIBusID")) {
pDRIInfo->busIdString = DRICreatePCIBusID(pI830->PciInfo);
} else {
pDRIInfo->busIdString = xalloc(64);
sprintf(pDRIInfo->busIdString, "PCI:%d:%d:%d",
#if XSERVER_LIBPCIACCESS
((pI830->PciInfo->domain << 8) | pI830->PciInfo->bus),
pI830->PciInfo->dev, pI830->PciInfo->func
#else
((pciConfigPtr) pI830->PciInfo->thisCard)->busnum,
((pciConfigPtr) pI830->PciInfo->thisCard)->devnum,
((pciConfigPtr) pI830->PciInfo->thisCard)->funcnum
#endif
);
}
pDRIInfo->ddxDriverMajorVersion = I830_MAJOR_VERSION;
pDRIInfo->ddxDriverMinorVersion = I830_MINOR_VERSION;
pDRIInfo->ddxDriverPatchVersion = I830_PATCHLEVEL;
pDRIInfo->ddxDrawableTableEntry = I830_MAX_DRAWABLES;
if (SAREA_MAX_DRAWABLES < I830_MAX_DRAWABLES)
pDRIInfo->maxDrawableTableEntry = SAREA_MAX_DRAWABLES;
else
pDRIInfo->maxDrawableTableEntry = I830_MAX_DRAWABLES;
if (sizeof(XF86DRISAREARec) + sizeof(drmI830Sarea) > SAREA_MAX) {
xf86DrvMsg(pScreen->myNum, X_ERROR,
"[dri] Data does not fit in SAREA\n");
return FALSE;
}
/* This is a hack for now. We have to have more than a 4k page here
* because of the size of the state. However, the state should be
* in a per-context mapping. This will be added in the Mesa 3.5 port
* of the I830 driver.
*/
pDRIInfo->SAREASize = SAREA_MAX;
if (!(pI830DRI = (I830DRIPtr) xcalloc(sizeof(I830DRIRec), 1))) {
DRIDestroyInfoRec(pI830->pDRIInfo);
pI830->pDRIInfo = NULL;
return FALSE;
}
pDRIInfo->devPrivate = pI830DRI;
pDRIInfo->devPrivateSize = sizeof(I830DRIRec);
pDRIInfo->contextSize = sizeof(I830DRIContextRec);
pDRIInfo->CreateContext = I830CreateContext;
pDRIInfo->DestroyContext = I830DestroyContext;
pDRIInfo->SwapContext = I830DRISwapContext;
pDRIInfo->InitBuffers = I830DRIInitBuffers;
pDRIInfo->MoveBuffers = I830DRIMoveBuffers;
pDRIInfo->bufferRequests = DRI_ALL_WINDOWS;
#if DRIINFO_MAJOR_VERSION > 5 || \
(DRIINFO_MAJOR_VERSION == 5 && DRIINFO_MINOR_VERSION >= 3)
if (pI830->accel == ACCEL_EXA)
pDRIInfo->texOffsetStart = I830TexOffsetStart;
#endif
#if DRI_DRIVER_FRAMEBUFFER_MAP
/* DRI version is high enough that we can get the DRI code to not
* try to manage the framebuffer.
*/
pDRIInfo->frameBufferPhysicalAddress = 0;
pDRIInfo->frameBufferSize = 0;
pDRIInfo->frameBufferStride = 0;
pDRIInfo->dontMapFrameBuffer = TRUE;
#else
/* Supply a dummy mapping info required by DRI setup.
*/
pDRIInfo->frameBufferPhysicalAddress = (char *) pI830->LinearAddr;
pDRIInfo->frameBufferSize = GTT_PAGE_SIZE;
pDRIInfo->frameBufferStride = 1;
#endif
pDRIInfo->TransitionTo2d = I830DRITransitionTo2d;
pDRIInfo->TransitionTo3d = I830DRITransitionTo3d;
/* do driver-independent DRI screen initialization here */
if (!DRIScreenInit(pScreen, pDRIInfo, &pI830->drmSubFD)) {
xf86DrvMsg(pScreen->myNum, X_ERROR,
"[dri] DRIScreenInit failed. Disabling DRI.\n");
xfree(pDRIInfo->devPrivate);
pDRIInfo->devPrivate = NULL;
DRIDestroyInfoRec(pI830->pDRIInfo);
pI830->pDRIInfo = NULL;
return FALSE;
}
/* Now, nuke dri.c's dummy frontbuffer map setup if we did that. */
if (pDRIInfo->frameBufferSize != 0) {
int tmp;
drm_handle_t fb_handle;
void *ptmp;
/* With the compat method, it will continue to report
* the wrong map out of GetDeviceInfo, which will break AIGLX.
*/
DRIGetDeviceInfo(pScreen, &fb_handle, &tmp, &tmp, &tmp, &tmp, &ptmp);
drmRmMap(pI830->drmSubFD, fb_handle);
xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
"Removed DRI frontbuffer mapping in compatibility mode.\n");
xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
"DRIGetDeviceInfo will report incorrect frontbuffer "
"handle.\n");
}
/* Check the i915 DRM versioning */
{
drmVersionPtr version;
/* Check the DRM lib version.
* drmGetLibVersion was not supported in version 1.0, so check for
* symbol first to avoid possible crash or hang.
*/
if (xf86LoaderCheckSymbol("drmGetLibVersion")) {
version = drmGetLibVersion(pI830->drmSubFD);
} else
{
/* drmlib version 1.0.0 didn't have the drmGetLibVersion
* entry point. Fake it by allocating a version record
* via drmGetVersion and changing it to version 1.0.0
*/
version = drmGetVersion(pI830->drmSubFD);
version->version_major = 1;
version->version_minor = 0;
version->version_patchlevel = 0;
}
#define REQ_MAJ 1
#define REQ_MIN 1
if (version) {
if (version->version_major != REQ_MAJ ||
version->version_minor < REQ_MIN) {
/* incompatible drm library version */
xf86DrvMsg(pScreen->myNum, X_ERROR,
"[dri] I830DRIScreenInit failed because of a version mismatch.\n"
"[dri] libdrm.a module version is %d.%d.%d but version %d.%d.x is needed.\n"
"[dri] Disabling DRI.\n",
version->version_major,
version->version_minor, version->version_patchlevel,
REQ_MAJ, REQ_MIN);
drmFreeVersion(version);
I830DRICloseScreen(pScreen);
return FALSE;
}
drmFreeVersion(version);
}
/* Check the i915 DRM version */
version = drmGetVersion(pI830->drmSubFD);
if (version) {
if (version->version_major != 1 || version->version_minor < 3) {
/* incompatible drm version */
xf86DrvMsg(pScreen->myNum, X_ERROR,
"[dri] %s failed because of a version mismatch.\n"
"[dri] i915 kernel module version is %d.%d.%d but version 1.3 or greater is needed.\n"
"[dri] Disabling DRI.\n",
"I830DRIScreenInit",
version->version_major,
version->version_minor, version->version_patchlevel);
I830DRICloseScreen(pScreen);
drmFreeVersion(version);
return FALSE;
}
/* Check whether the kernel module attached to the device isn't the
* one we expected (meaning it's the old i830 module).
*/
if (strncmp(version->name, pDRIInfo->drmDriverName,
strlen(pDRIInfo->drmDriverName)))
{
xf86DrvMsg(pScreen->myNum, X_WARNING,
"Detected i830 kernel module. The i915 kernel module "
"is required for DRI. Aborting.\n");
I830DRICloseScreen(pScreen);
drmFreeVersion(version);
return FALSE;
}
pI830->drmMinor = version->version_minor;
drmFreeVersion(version);
}
}
return TRUE;
}
static void
I830InitTextureHeap(ScrnInfoPtr pScrn)
{
I830Ptr pI830 = I830PTR(pScrn);
drmI830MemInitHeap drmHeap;
if (pI830->textures == NULL)
return;
/* Start up the simple memory manager for agp space */
drmHeap.region = I830_MEM_REGION_AGP;
drmHeap.start = 0;
drmHeap.size = pI830->textures->size;
if (drmCommandWrite(pI830->drmSubFD, DRM_I830_INIT_HEAP,
&drmHeap, sizeof(drmHeap))) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"[drm] Failed to initialized agp heap manager\n");
} else {
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"[drm] Initialized kernel agp heap manager, %ld\n",
pI830->textures->size);
I830SetParam(pScrn, I830_SETPARAM_TEX_LRU_LOG_GRANULARITY,
pI830->TexGranularity);
}
}
/*
* Map registers & ring buffer
*/
static Bool
I830DRIMapHW(ScreenPtr pScreen)
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
I830Ptr pI830 = I830PTR(pScrn);
DRIInfoPtr pDRIInfo = pI830->pDRIInfo;
I830DRIPtr pI830DRI = pDRIInfo->devPrivate;
/* Kernel deals with direct hw access in this case */
if (pI830->use_drm_mode)
return TRUE;
DPRINTF(PFX, "I830DRIMapHW\n");
pI830DRI->regsSize = I830_REG_SIZE;
if (drmAddMap(pI830->drmSubFD, (drm_handle_t)pI830->MMIOAddr,
pI830DRI->regsSize, DRM_REGISTERS, 0,
(drmAddress) &pI830DRI->regs) < 0) {
xf86DrvMsg(pScreen->myNum, X_ERROR, "[drm] drmAddMap(regs) failed\n");
DRICloseScreen(pScreen);
return FALSE;
}
xf86DrvMsg(pScreen->myNum, X_INFO, "[drm] Registers = 0x%08x\n",
(int)pI830DRI->regs);
if (!pI830->memory_manager) {
if (drmAddMap(pI830->drmSubFD,
(drm_handle_t)pI830->ring.mem->offset +
pI830->LinearAddr,
pI830->ring.mem->size, DRM_AGP, 0,
(drmAddress) &pI830->ring_map) < 0) {
xf86DrvMsg(pScreen->myNum, X_ERROR,
"[drm] drmAddMap(ring_map) failed. Disabling DRI\n");
DRICloseScreen(pScreen);
return FALSE;
}
xf86DrvMsg(pScreen->myNum, X_INFO, "[drm] ring buffer = 0x%08x\n",
(int)pI830->ring_map);
}
return TRUE;
}
/**
* Sets up mappings for static, lifetime-fixed allocations, and inital SAREA
* setup.
*/
Bool
I830DRIDoMappings(ScreenPtr pScreen)
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
I830Ptr pI830 = I830PTR(pScrn);
DRIInfoPtr pDRIInfo = pI830->pDRIInfo;
I830DRIPtr pI830DRI = pDRIInfo->devPrivate;
drmI830Sarea *sarea = (drmI830Sarea *) DRIGetSAREAPrivate(pScreen);
if (!I830DRIMapHW(pScreen)) {
DRICloseScreen(pScreen);
return FALSE;
}
if (!I830InitDma(pScrn)) {
DRICloseScreen(pScreen);
return FALSE;
}
if (pI830->memory_manager == NULL)
intel_bufmgr_fake_set_last_dispatch(pI830->bufmgr,
(volatile unsigned int *)
&sarea->last_dispatch);
/* init to zero to be safe */
sarea->front_handle = 0;
sarea->back_handle = 0;
sarea->depth_handle = 0;
sarea->tex_handle = 0;
/* Assign pScreen */
pScrn->pScreen = pScreen;
/* Need to initialize pScreen now to let RandR know. */
pScrn->pScreen->width = pScrn->virtualX;
pScrn->pScreen->height = pScrn->virtualY;
/* If we are using the kernel memory manager, we have to delay SAREA and
* mapping setup until our buffers are pinned at EnterVT, losing the
* opportunity to fail cleanly early on.
*/
if (pI830->memory_manager == NULL) {
if (!i830_update_dri_buffers(pScrn)) {
/* screen mappings probably failed */
xf86DrvMsg(pScreen->myNum, X_ERROR,
"[drm] drmAddMap(screen mappings) failed. "
"Disabling DRI\n");
DRICloseScreen(pScreen);
return FALSE;
}
}
if (pI830->allocate_classic_textures)
I830InitTextureHeap(pScrn);
if (DEVICE_ID(pI830->PciInfo) != PCI_CHIP_845_G &&
DEVICE_ID(pI830->PciInfo) != PCI_CHIP_I830_M) {
I830SetParam(pScrn, I830_SETPARAM_USE_MI_BATCHBUFFER_START, 1 );
}
pI830DRI = (I830DRIPtr) pI830->pDRIInfo->devPrivate;
pI830DRI->deviceID = DEVICE_ID(pI830->PciInfo);
pI830DRI->width = pScrn->virtualX;
pI830DRI->height = pScrn->virtualY;
pI830DRI->mem = pScrn->videoRam * 1024;
pI830DRI->cpp = pI830->cpp;
pI830DRI->bitsPerPixel = pScrn->bitsPerPixel;
pI830DRI->sarea_priv_offset = sizeof(XF86DRISAREARec);
if (!(I830InitVisualConfigs(pScreen))) {
xf86DrvMsg(pScreen->myNum, X_ERROR,
"[dri] I830InitVisualConfigs failed. Disabling DRI\n");
DRICloseScreen(pScreen);
return FALSE;
}
xf86DrvMsg(pScrn->scrnIndex, X_INFO, "[dri] visual configs initialized\n");
pI830->pDRIInfo->driverSwapMethod = DRI_HIDE_X_CONTEXT;
return TRUE;
}
Bool
I830DRIInstIrqHandler(ScrnInfoPtr pScrn)
{
I830Ptr pI830 = I830PTR(pScrn);
I830DRIPtr pI830DRI = (I830DRIPtr) pI830->pDRIInfo->devPrivate;
pI830DRI->irq = drmGetInterruptFromBusID(pI830->drmSubFD,
#if XSERVER_LIBPCIACCESS
((pI830->PciInfo->domain << 8) |
pI830->PciInfo->bus),
pI830->PciInfo->dev,
pI830->PciInfo->func
#else
((pciConfigPtr) pI830->
PciInfo->thisCard)->busnum,
((pciConfigPtr) pI830->
PciInfo->thisCard)->devnum,
((pciConfigPtr) pI830->
PciInfo->thisCard)->funcnum
#endif
);
if (drmCtlInstHandler(pI830->drmSubFD, pI830DRI->irq)) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"[drm] failure adding irq handler\n");
pI830DRI->irq = 0;
return FALSE;
} else
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"[drm] dma control initialized, using IRQ %d\n",
pI830DRI->irq);
return TRUE;
}
Bool
I830DRIResume(ScreenPtr pScreen)
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
I830Ptr pI830 = I830PTR(pScrn);
DPRINTF(PFX, "I830DRIResume\n");
I830ResumeDma(pScrn);
if (!pI830->memory_manager)
I830DRIInstIrqHandler(pScrn);
return TRUE;
}
void
I830DRICloseScreen(ScreenPtr pScreen)
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
I830Ptr pI830 = I830PTR(pScrn);
I830DRIPtr pI830DRI = (I830DRIPtr) pI830->pDRIInfo->devPrivate;
DPRINTF(PFX, "I830DRICloseScreen\n");
if (!pI830->memory_manager && pI830DRI->irq) {
drmCtlUninstHandler(pI830->drmSubFD);
pI830DRI->irq = 0;
}
I830CleanupDma(pScrn);
DRICloseScreen(pScreen);
if (pI830->pDRIInfo) {
if (pI830->pDRIInfo->devPrivate) {
xfree(pI830->pDRIInfo->devPrivate);
pI830->pDRIInfo->devPrivate = NULL;
}
DRIDestroyInfoRec(pI830->pDRIInfo);
pI830->pDRIInfo = NULL;
}
if (pI830->pVisualConfigs)
xfree(pI830->pVisualConfigs);
if (pI830->pVisualConfigsPriv)
xfree(pI830->pVisualConfigsPriv);
pI830->directRenderingType = DRI_NONE;
}
static Bool
I830CreateContext(ScreenPtr pScreen, VisualPtr visual,
drm_context_t hwContext, void *pVisualConfigPriv,
DRIContextType contextStore)
{
return TRUE;
}
static void
I830DestroyContext(ScreenPtr pScreen, drm_context_t hwContext,
DRIContextType contextStore)
{
}
Bool
I830DRIFinishScreenInit(ScreenPtr pScreen)
{
DPRINTF(PFX, "I830DRIFinishScreenInit\n");
if (!DRIFinishScreenInit(pScreen))
return FALSE;
/* move irq initialize later in EnterVT, as then we
* would finish binding possible hw status page, which
* requires irq ctrl ioctl not be called that early.
*/
return TRUE;
}
static void
I830DRISwapContext(ScreenPtr pScreen, DRISyncType syncType,
DRIContextType oldContextType, void *oldContext,
DRIContextType newContextType, void *newContext)
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
I830Ptr pI830 = I830PTR(pScrn);
if (syncType == DRI_3D_SYNC &&
oldContextType == DRI_2D_CONTEXT && newContextType == DRI_2D_CONTEXT) {
if (I810_DEBUG & DEBUG_VERBOSE_DRI)
ErrorF("i830DRISwapContext (in)\n");
pI830->last_3d = LAST_3D_OTHER;
if (!pScrn->vtSema)
return;
pI830->LockHeld = 1;
if (!pI830->memory_manager)
i830_refresh_ring(pScrn);
} else if (syncType == DRI_2D_SYNC &&
oldContextType == DRI_NO_CONTEXT &&
newContextType == DRI_2D_CONTEXT) {
if (I810_DEBUG & DEBUG_VERBOSE_DRI)
ErrorF("i830DRISwapContext (out)\n");
if (!pScrn->vtSema)
return;
pI830->LockHeld = 0;
} else if (I810_DEBUG & DEBUG_VERBOSE_DRI)
ErrorF("i830DRISwapContext (other)\n");
}
static void
I830DRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index)
{
ScreenPtr pScreen = pWin->drawable.pScreen;
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
BoxPtr pbox;
int nbox;
int buffer, first_buffer, last_buffer;
if (I810_DEBUG & DEBUG_VERBOSE_DRI)
ErrorF("I830DRIInitBuffers\n");
first_buffer = I830_SELECT_BACK;
last_buffer = I830_SELECT_DEPTH;
for (buffer = first_buffer; buffer <= last_buffer; buffer++) {
pbox = REGION_RECTS(prgn);
nbox = REGION_NUM_RECTS(prgn);
if (!I830SelectBuffer(pScrn, buffer))
continue;
if (buffer == I830_SELECT_DEPTH) {
switch (pScrn->bitsPerPixel) {
case 16:
I830SetupForSolidFill(pScrn, 0xffff, GXcopy, -1);
break;
case 32:
I830SetupForSolidFill(pScrn, 0xffffff, GXcopy, -1);
break;
}
} else
I830SetupForSolidFill(pScrn, 0, GXcopy, -1);
while (nbox--) {
I830SubsequentSolidFillRect(pScrn, pbox->x1, pbox->y1,
pbox->x2 - pbox->x1, pbox->y2 - pbox->y1);
pbox++;
}
}
I830SelectBuffer(pScrn, I830_SELECT_FRONT);
i830MarkSync(pScrn);
}
/* This routine is a modified form of XAADoBitBlt with the calls to
* ScreenToScreenBitBlt built in. My routine has the prgnSrc as source
* instead of destination. My origin is upside down so the ydir cases
* are reversed.
*/
static void
I830DRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg,
RegionPtr prgnSrc, CARD32 index)
{
ScreenPtr pScreen = pParent->drawable.pScreen;
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
BoxPtr pboxTmp, pboxNext, pboxBase;
DDXPointPtr pptTmp, pptNew2 = NULL;
int xdir, ydir;
#if 0
int screenwidth = pScrn->virtualX;
int screenheight = pScrn->virtualY;
#else
int screenwidth = pScreen->width;
int screenheight = pScreen->height;
#endif
BoxPtr pbox = REGION_RECTS(prgnSrc);
int nbox = REGION_NUM_RECTS(prgnSrc);
BoxPtr pboxNew1 = NULL;
BoxPtr pboxNew2 = NULL;
DDXPointPtr pptNew1 = NULL;
DDXPointPtr pptSrc = &ptOldOrg;
int dx = pParent->drawable.x - ptOldOrg.x;
int dy = pParent->drawable.y - ptOldOrg.y;
int buffer, first_buffer, last_buffer;
/* If the copy will overlap in Y, reverse the order */
if (dy > 0) {
ydir = -1;
if (nbox > 1) {
/* Keep ordering in each band, reverse order of bands */
pboxNew1 = (BoxPtr) xalloc(sizeof(BoxRec) * nbox);
if (!pboxNew1)
return;
pptNew1 = (DDXPointPtr) xalloc(sizeof(DDXPointRec) * nbox);
if (!pptNew1) {
xfree(pboxNew1);
return;
}
pboxBase = pboxNext = pbox + nbox - 1;
while (pboxBase >= pbox) {
while ((pboxNext >= pbox) && (pboxBase->y1 == pboxNext->y1))
pboxNext--;
pboxTmp = pboxNext + 1;
pptTmp = pptSrc + (pboxTmp - pbox);
while (pboxTmp <= pboxBase) {
*pboxNew1++ = *pboxTmp++;
*pptNew1++ = *pptTmp++;
}
pboxBase = pboxNext;
}
pboxNew1 -= nbox;
pbox = pboxNew1;
pptNew1 -= nbox;
pptSrc = pptNew1;
}
} else {
/* No changes required */
ydir = 1;
}
/* If the regions will overlap in X, reverse the order */
if (dx > 0) {
xdir = -1;
if (nbox > 1) {
/*reverse orderof rects in each band */
pboxNew2 = (BoxPtr) xalloc(sizeof(BoxRec) * nbox);
pptNew2 = (DDXPointPtr) xalloc(sizeof(DDXPointRec) * nbox);
if (!pboxNew2 || !pptNew2) {
if (pptNew2)
xfree(pptNew2);
if (pboxNew2)
xfree(pboxNew2);
if (pboxNew1) {
xfree(pptNew1);
xfree(pboxNew1);
}
return;
}
pboxBase = pboxNext = pbox;
while (pboxBase < pbox + nbox) {
while ((pboxNext < pbox + nbox) && (pboxNext->y1 == pboxBase->y1))
pboxNext++;
pboxTmp = pboxNext;
pptTmp = pptSrc + (pboxTmp - pbox);
while (pboxTmp != pboxBase) {
*pboxNew2++ = *--pboxTmp;
*pptNew2++ = *--pptTmp;
}
pboxBase = pboxNext;
}
pboxNew2 -= nbox;
pbox = pboxNew2;
pptNew2 -= nbox;
pptSrc = pptNew2;
}
} else {
/* No changes are needed */
xdir = 1;
}
/* SelectBuffer isn't really a good concept for the i810.
*/
I830EmitFlush(pScrn);
first_buffer = I830_SELECT_BACK;
last_buffer = I830_SELECT_DEPTH;
for (buffer = first_buffer; buffer <= last_buffer; buffer++) {
if (!I830SelectBuffer(pScrn, buffer))
continue;
I830SetupForScreenToScreenCopy(pScrn, xdir, ydir, GXcopy, -1, -1);
pbox = REGION_RECTS(prgnSrc);
nbox = REGION_NUM_RECTS(prgnSrc);
for (; nbox--; pbox++) {
int x1 = pbox->x1;
int y1 = pbox->y1;
int destx = x1 + dx;
int desty = y1 + dy;
int w = pbox->x2 - x1 + 1;
int h = pbox->y2 - y1 + 1;
if (destx < 0)
x1 -= destx, w += destx, destx = 0;
if (desty < 0)
y1 -= desty, h += desty, desty = 0;
if (destx + w > screenwidth)
w = screenwidth - destx;
if (desty + h > screenheight)
h = screenheight - desty;
if (w <= 0)
continue;
if (h <= 0)
continue;
if (I810_DEBUG & DEBUG_VERBOSE_DRI)
ErrorF("MoveBuffers %d,%d %dx%d dx: %d dy: %d\n",
x1, y1, w, h, dx, dy);
I830SubsequentScreenToScreenCopy(pScrn, x1, y1, destx, desty, w, h);
}
}
I830SelectBuffer(pScrn, I830_SELECT_FRONT);
I830EmitFlush(pScrn);
if (pboxNew2) {
xfree(pptNew2);
xfree(pboxNew2);
}
if (pboxNew1) {
xfree(pptNew1);
xfree(pboxNew1);
}
i830MarkSync(pScrn);
}
static void
I830DRITransitionTo3d(ScreenPtr pScreen)
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
I830Ptr pI830 = I830PTR(pScrn);
pI830->want_vblank_interrupts = TRUE;
I830DRISetVBlankInterrupt(pScrn, TRUE);
}
static void
I830DRITransitionTo2d(ScreenPtr pScreen)
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
I830Ptr pI830 = I830PTR(pScrn);
pI830->want_vblank_interrupts = FALSE;
I830DRISetVBlankInterrupt(pScrn, FALSE);
}
static int
i830_name_buffer (ScrnInfoPtr pScrn, i830_memory *mem)
{
if (mem && mem->bo)
{
if (!mem->gem_name)
{
int ret;
ret = dri_bo_flink(mem->bo, &mem->gem_name);
if (ret != 0)
{
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"[drm] failed to name buffer %d\n", -errno);
return -1;
}
}
return mem->gem_name;
}
return -1;
}
/**
* Update the SAREA fields with current buffer information.
*
* Most of the SAREA fields are already updated by i830_do_addmap().
*
* This does include other SAREA initialization which will actually be constant
* over the lifetime of the server.
*/
static void
i830_update_sarea(ScrnInfoPtr pScrn, drmI830Sarea *sarea)
{
ScreenPtr pScreen = pScrn->pScreen;
I830Ptr pI830 = I830PTR(pScrn);
if (pI830->directRenderingType == DRI_DRI2)
return;
sarea->width = pScreen->width;
sarea->height = pScreen->height;
sarea->pitch = pScrn->displayWidth;
sarea->virtualX = pScrn->virtualX;
sarea->virtualY = pScrn->virtualY;
sarea->front_tiled = (pI830->front_buffer->tiling != TILE_NONE);
sarea->back_tiled = (pI830->back_buffer->tiling != TILE_NONE);
sarea->depth_tiled = (pI830->depth_buffer->tiling != TILE_NONE);
sarea->rotated_tiled = FALSE;
sarea->log_tex_granularity = pI830->TexGranularity;
sarea->front_bo_handle = i830_name_buffer (pScrn, pI830->front_buffer);
sarea->back_bo_handle = i830_name_buffer (pScrn, pI830->back_buffer);
sarea->depth_bo_handle = i830_name_buffer (pScrn, pI830->depth_buffer);
/* The rotation is now handled entirely by the X Server, so just leave the
* DRI unaware.
*/
sarea->rotation = 0;
sarea->rotated_offset = -1;
sarea->rotated_size = 0;
sarea->rotated_pitch = pScrn->displayWidth;
}
/**
* Updates the DRI mapping for the given i830_memory struct, with the given
* flags.
*/
static int
i830_do_addmap(ScrnInfoPtr pScrn, i830_memory *mem,
drm_handle_t *sarea_handle, int *sarea_size, int *sarea_offset)
{
I830Ptr pI830 = I830PTR(pScrn);
int size = mem->size;
if (mem == pI830->front_buffer) {
/* Workaround for XAA pixmap cache: Don't use front_buffer->size
* and instead, calculate the visible frontbuffer size and round to
* avoid irritating the assertions of older DRI drivers.
*/
size = ROUND_TO_PAGE(pScrn->displayWidth * pScrn->virtualY *
pI830->cpp);
}
if (*sarea_handle != 0 &&
(*sarea_size != size || *sarea_offset != mem->offset))
{
drmRmMap(pI830->drmSubFD, *sarea_handle);
*sarea_handle = 0;
*sarea_size = 0;
*sarea_offset = 0;
}
if (*sarea_handle == 0) {
int ret;
ret = drmAddMap(pI830->drmSubFD,
(drm_handle_t)(mem->offset + pI830->LinearAddr),
size, DRM_AGP, 0,
(drmAddress) sarea_handle);
if (ret == 0) {
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"[drm] mapped %s at 0x%08lx, handle = 0x%08x\n",
mem->name, mem->offset + pI830->LinearAddr,
(int)*sarea_handle);
*sarea_size = size;
*sarea_offset = mem->offset;
} else {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"[drm] failed to map %s at 0x%08lx\n",
mem->name, mem->offset + pI830->LinearAddr);
return FALSE;
}
}
return TRUE;
}
/**
* Updates the DRM mappings with the current buffer information.
*
* Some old DRI drivers may be unprepared for buffers actually moving at
* runtime, which would likely result in bus errors on software fallbacks or
* hangs or misrendering on hardware rendering.
*/
static Bool
i830_update_dri_mappings(ScrnInfoPtr pScrn, drmI830Sarea *sarea)
{
I830Ptr pI830 = I830PTR(pScrn);
if (!i830_do_addmap(pScrn, pI830->front_buffer, &sarea->front_handle,
&sarea->front_size, &sarea->front_offset)) {
xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Disabling DRI.\n");
return FALSE;
}
if (!i830_do_addmap(pScrn, pI830->back_buffer, &sarea->back_handle,
&sarea->back_size, &sarea->back_offset)) {
xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Disabling DRI.\n");
return FALSE;
}
sarea->third_handle = 0;
sarea->third_offset = 0;
sarea->third_size = 0;
if (!i830_do_addmap(pScrn, pI830->depth_buffer, &sarea->depth_handle,
&sarea->depth_size, &sarea->depth_offset)) {
xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Disabling DRI.\n");
return FALSE;
}
if (pI830->allocate_classic_textures) {
if (!i830_do_addmap(pScrn, pI830->textures, &sarea->tex_handle,
&sarea->tex_size, &sarea->tex_offset)) {
xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Disabling DRI.\n");
return FALSE;
}
}
return TRUE;
}
static void
i830_update_screen_private(ScrnInfoPtr pScrn, drmI830Sarea *sarea)
{
I830Ptr pI830 = I830PTR(pScrn);
pI830->pDRIInfo->frameBufferPhysicalAddress = (char *) pI830->LinearAddr;
pI830->pDRIInfo->frameBufferStride = pScrn->displayWidth * pI830->cpp;
pI830->pDRIInfo->frameBufferSize = sarea->front_size;
#if DRI_DRIVER_FRAMEBUFFER_MAP
pI830->pDRIInfo->hFrameBuffer = sarea->front_handle;
#endif
}
/**
* Update the SAREA fields, DRI mappings, and screen info passed through the
* protocol.
*
* This gets called both at startup and after any of the buffers might have
* been relocated.
*/
Bool
i830_update_dri_buffers(ScrnInfoPtr pScrn)
{
ScreenPtr pScreen = pScrn->pScreen;
I830Ptr pI830 = I830PTR(pScrn);
drmI830Sarea *sarea;
Bool success;
if (pI830->directRenderingType != DRI_XF86DRI)
return TRUE;
sarea = (drmI830Sarea *) DRIGetSAREAPrivate(pScreen);
success = i830_update_dri_mappings(pScrn, sarea);
if (!success)
return FALSE;
i830_update_sarea(pScrn, sarea);
i830_update_screen_private(pScrn, sarea);
return TRUE;
}
Bool
I830DRISetVBlankInterrupt (ScrnInfoPtr pScrn, Bool on)
{
I830Ptr pI830 = I830PTR(pScrn);
xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
drmI830VBlankPipe pipe;
/* If we have no 3d running, then don't bother enabling the vblank
* interrupt.
*/
if (!pI830->want_vblank_interrupts)
on = FALSE;
if (pI830->directRenderingType == DRI_XF86DRI && pI830->drmMinor >= 5) {
if (on) {
if (xf86_config->num_crtc > 1 && xf86_config->crtc[1]->enabled)
if (pI830->drmMinor >= 6)
pipe.pipe = DRM_I830_VBLANK_PIPE_A | DRM_I830_VBLANK_PIPE_B;
else
pipe.pipe = DRM_I830_VBLANK_PIPE_B;
else
pipe.pipe = DRM_I830_VBLANK_PIPE_A;
} else {
pipe.pipe = 0;
}
if (drmCommandWrite(pI830->drmSubFD, DRM_I830_SET_VBLANK_PIPE,
&pipe, sizeof (pipe))) {
return FALSE;
}
}
return TRUE;
}
Bool
I830DRILock(ScrnInfoPtr pScrn)
{
I830Ptr pI830 = I830PTR(pScrn);
if (pI830->directRenderingType == DRI_XF86DRI && !pI830->LockHeld) {
DRILock(screenInfo.screens[pScrn->scrnIndex], 0);
pI830->LockHeld = 1;
if (!pI830->memory_manager)
i830_refresh_ring(pScrn);
return TRUE;
}
else
return FALSE;
}
void
I830DRIUnlock(ScrnInfoPtr pScrn)
{
I830Ptr pI830 = I830PTR(pScrn);
if (pI830->directRenderingType == DRI_XF86DRI && pI830->LockHeld) {
DRIUnlock(screenInfo.screens[pScrn->scrnIndex]);
pI830->LockHeld = 0;
}
}
#ifdef DRI2
typedef struct {
PixmapPtr pPixmap;
unsigned int attachment;
} I830DRI2BufferPrivateRec, *I830DRI2BufferPrivatePtr;
#ifndef USE_DRI2_1_1_0
static DRI2BufferPtr
I830DRI2CreateBuffers(DrawablePtr pDraw, unsigned int *attachments, int count)
{
ScreenPtr pScreen = pDraw->pScreen;
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
I830Ptr pI830 = I830PTR(pScrn);
DRI2BufferPtr buffers;
dri_bo *bo;
int i;
I830DRI2BufferPrivatePtr privates;
PixmapPtr pPixmap, pDepthPixmap;
buffers = xcalloc(count, sizeof *buffers);
if (buffers == NULL)
return NULL;
privates = xcalloc(count, sizeof *privates);
if (privates == NULL) {
xfree(buffers);
return NULL;
}
pDepthPixmap = NULL;
for (i = 0; i < count; i++) {
if (attachments[i] == DRI2BufferFrontLeft) {
if (pDraw->type == DRAWABLE_PIXMAP)
pPixmap = (PixmapPtr) pDraw;
else
pPixmap = (*pScreen->GetWindowPixmap)((WindowPtr) pDraw);
pPixmap->refcnt++;
} else if (attachments[i] == DRI2BufferStencil && pDepthPixmap) {
pPixmap = pDepthPixmap;
pPixmap->refcnt++;
} else {
unsigned int hint = 0;
switch (attachments[i]) {
case DRI2BufferDepth:
if (SUPPORTS_YTILING(pI830))
hint = INTEL_CREATE_PIXMAP_TILING_Y;
else
hint = INTEL_CREATE_PIXMAP_TILING_X;
break;
case DRI2BufferFakeFrontLeft:
case DRI2BufferFakeFrontRight:
case DRI2BufferBackLeft:
case DRI2BufferBackRight:
hint = INTEL_CREATE_PIXMAP_TILING_X;
break;
}
if (!pI830->tiling ||
(!IS_I965G(pI830) && !pI830->kernel_exec_fencing))
hint = 0;
pPixmap = (*pScreen->CreatePixmap)(pScreen,
pDraw->width,
pDraw->height,
pDraw->depth,
hint);
}
if (attachments[i] == DRI2BufferDepth)
pDepthPixmap = pPixmap;
buffers[i].attachment = attachments[i];
buffers[i].pitch = pPixmap->devKind;
buffers[i].cpp = pPixmap->drawable.bitsPerPixel / 8;
buffers[i].driverPrivate = &privates[i];
buffers[i].flags = 0; /* not tiled */
privates[i].pPixmap = pPixmap;
privates[i].attachment = attachments[i];
bo = i830_get_pixmap_bo (pPixmap);
if (dri_bo_flink(bo, &buffers[i].name) != 0) {
/* failed to name buffer */
}
}
return buffers;
}
#else
static DRI2BufferPtr
I830DRI2CreateBuffer(DrawablePtr pDraw, unsigned int attachment,
unsigned int format)
{
ScreenPtr pScreen = pDraw->pScreen;
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
I830Ptr pI830 = I830PTR(pScrn);
DRI2BufferPtr buffers;
dri_bo *bo;
I830DRI2BufferPrivatePtr privates;
PixmapPtr pPixmap;
buffers = xcalloc(1, sizeof *buffers);
if (buffers == NULL)
return NULL;
privates = xcalloc(1, sizeof *privates);
if (privates == NULL) {
xfree(buffers);
return NULL;
}
if (attachment == DRI2BufferFrontLeft) {
if (pDraw->type == DRAWABLE_PIXMAP)
pPixmap = (PixmapPtr) pDraw;
else
pPixmap = (*pScreen->GetWindowPixmap)((WindowPtr) pDraw);
pPixmap->refcnt++;
} else {
unsigned int hint = 0;
switch (attachment) {
case DRI2BufferDepth:
case DRI2BufferDepthStencil:
if (SUPPORTS_YTILING(pI830))
hint = INTEL_CREATE_PIXMAP_TILING_Y;
else
hint = INTEL_CREATE_PIXMAP_TILING_X;
break;
case DRI2BufferFakeFrontLeft:
case DRI2BufferFakeFrontRight:
case DRI2BufferBackLeft:
case DRI2BufferBackRight:
hint = INTEL_CREATE_PIXMAP_TILING_X;
break;
}
if (!pI830->tiling ||
(!IS_I965G(pI830) && !pI830->kernel_exec_fencing))
hint = 0;
pPixmap = (*pScreen->CreatePixmap)(pScreen,
pDraw->width,
pDraw->height,
format,
hint);
}
buffers->attachment = attachment;
buffers->pitch = pPixmap->devKind;
buffers->cpp = pPixmap->drawable.bitsPerPixel / 8;
buffers->driverPrivate = privates;
buffers->format = format;
buffers->flags = 0; /* not tiled */
privates->pPixmap = pPixmap;
privates->attachment = attachment;
bo = i830_get_pixmap_bo (pPixmap);
if (dri_bo_flink(bo, &buffers->name) != 0) {
/* failed to name buffer */
}
return buffers;
}
#endif
#ifndef USE_DRI2_1_1_0
static void
I830DRI2DestroyBuffers(DrawablePtr pDraw, DRI2BufferPtr buffers, int count)
{
ScreenPtr pScreen = pDraw->pScreen;
I830DRI2BufferPrivatePtr private;
int i;
for (i = 0; i < count; i++)
{
private = buffers[i].driverPrivate;
(*pScreen->DestroyPixmap)(private->pPixmap);
}
if (buffers)
{
xfree(buffers[0].driverPrivate);
xfree(buffers);
}
}
#else
static void
I830DRI2DestroyBuffer(DrawablePtr pDraw, DRI2BufferPtr buffer)
{
if (buffer) {
I830DRI2BufferPrivatePtr private = buffer->driverPrivate;
ScreenPtr pScreen = pDraw->pScreen;
(*pScreen->DestroyPixmap)(private->pPixmap);
xfree(private);
xfree(buffer);
}
}
#endif
static void
I830DRI2CopyRegion(DrawablePtr pDraw, RegionPtr pRegion,
DRI2BufferPtr pDstBuffer, DRI2BufferPtr pSrcBuffer)
{
I830DRI2BufferPrivatePtr srcPrivate = pSrcBuffer->driverPrivate;
I830DRI2BufferPrivatePtr dstPrivate = pDstBuffer->driverPrivate;
ScreenPtr pScreen = pDraw->pScreen;
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
I830Ptr pI830 = I830PTR(pScrn);
PixmapPtr pSrcPixmap = (srcPrivate->attachment == DRI2BufferFrontLeft)
? (PixmapPtr) pDraw : srcPrivate->pPixmap;
PixmapPtr pDstPixmap = (dstPrivate->attachment == DRI2BufferFrontLeft)
? (PixmapPtr) pDraw : dstPrivate->pPixmap;
RegionPtr pCopyClip;
GCPtr pGC;
pGC = GetScratchGC(pDraw->depth, pScreen);
pCopyClip = REGION_CREATE(pScreen, NULL, 0);
REGION_COPY(pScreen, pCopyClip, pRegion);
(*pGC->funcs->ChangeClip) (pGC, CT_REGION, pCopyClip, 0);
ValidateGC(&pDstPixmap->drawable, pGC);
(*pGC->ops->CopyArea)(&pSrcPixmap->drawable, &pDstPixmap->drawable,
pGC, 0, 0, pDraw->width, pDraw->height, 0, 0);
FreeScratchGC(pGC);
/* Emit a flush of the rendering cache, or on the 965 and beyond
* rendering results may not hit the framebuffer until significantly
* later.
*/
I830EmitFlush(pScrn);
pI830->need_mi_flush = FALSE;
/* We can't rely on getting into the block handler before the DRI
* client gets to run again so flush now. */
intel_batch_flush(pScrn, TRUE);
#if ALWAYS_SYNC
I830Sync(pScrn);
#endif
drmCommandNone(pI830->drmSubFD, DRM_I915_GEM_THROTTLE);
}
Bool I830DRI2ScreenInit(ScreenPtr pScreen)
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
I830Ptr pI830 = I830PTR(pScrn);
DRI2InfoRec info;
char *p, buf[64];
int i;
struct stat sbuf;
dev_t d;
#ifdef USE_DRI2_1_1_0
int dri2_major = 1;
int dri2_minor = 0;
#endif
if (pI830->accel != ACCEL_UXA) {
xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "DRI2 requires UXA\n");
return FALSE;
}
#ifdef USE_DRI2_1_1_0
if (xf86LoaderCheckSymbol("DRI2Version")) {
DRI2Version(& dri2_major, & dri2_minor);
}
if (dri2_minor < 1) {
xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
"DRI2 requires DRI2 module version 1.1.0 or later\n");
return FALSE;
}
#endif
sprintf(buf, "pci:%04x:%02x:%02x.%d",
pI830->PciInfo->domain,
pI830->PciInfo->bus,
pI830->PciInfo->dev,
pI830->PciInfo->func);
info.fd = -1;
#ifdef XF86DRM_MODE
/* Use the already opened (master) fd from modesetting */
if (pI830->use_drm_mode)
info.fd = pI830->drmSubFD;
#endif
if (info.fd < 0)
info.fd = drmOpen("i915", buf);
if (info.fd < 0) {
xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Failed to open DRM device\n");
return FALSE;
}
/* The whole drmOpen thing is a fiasco and we need to find a way
* back to just using open(2). For now, however, lets just make
* things worse with even more ad hoc directory walking code to
* discover the device file name. */
fstat(info.fd, &sbuf);
d = sbuf.st_rdev;
p = pI830->deviceName;
for (i = 0; i < DRM_MAX_MINOR; i++) {
sprintf(p, DRM_DEV_NAME, DRM_DIR_NAME, i);
if (stat(p, &sbuf) == 0 && sbuf.st_rdev == d)
break;
}
if (i == DRM_MAX_MINOR) {
xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
"DRI2: failed to open drm device\n");
return FALSE;
}
info.driverName = IS_I965G(pI830) ? "i965" : "i915";
info.deviceName = p;
#ifdef USE_DRI2_1_1_0
info.version = 2;
info.CreateBuffers = NULL;
info.DestroyBuffers = NULL;
info.CreateBuffer = I830DRI2CreateBuffer;
info.DestroyBuffer = I830DRI2DestroyBuffer;
#else
info.version = 1;
info.CreateBuffers = I830DRI2CreateBuffers;
info.DestroyBuffers = I830DRI2DestroyBuffers;
#endif
info.CopyRegion = I830DRI2CopyRegion;
pI830->drmSubFD = info.fd;
return DRI2ScreenInit(pScreen, &info);
}
void I830DRI2CloseScreen(ScreenPtr pScreen)
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
I830Ptr pI830 = I830PTR(pScrn);
DRI2CloseScreen(pScreen);
pI830->directRenderingType = DRI_NONE;
}
#endif
|