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
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
|
/* COPYRIGHT AND PERMISSION NOTICE
Copyright (c) 2000, 2001 Nokia Home Communications
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, and/or sell copies of the Software, and to permit persons
to whom the Software is furnished to do so, provided that the above
copyright notice(s) and this permission notice appear in all copies of
the Software and that both the above copyright notice(s) and this
permission notice appear in supporting documentation.
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
OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY
SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Except as contained in this notice, the name of a copyright holder
shall not be used in advertising or otherwise to promote the sale, use
or other dealings in this Software without prior written authorization
of the copyright holder.
X Window System is a trademark of The Open Group */
/*
* i810.c - KDrive driver for the i810 chipset
*
* Authors:
* Pontus Lidman <pontus.lidman@nokia.com>
*
*/
#ifdef HAVE_CONFIG_H
#include <kdrive-config.h>
#endif
#include "kdrive.h"
#include "kxv.h"
#include "klinux.h"
#include "i810.h"
#include "agp.h"
#include "i810draw.h"
#ifndef I810_DEBUG
int I810_DEBUG = (0
/* | DEBUG_ALWAYS_SYNC */
/* | DEBUG_VERBOSE_ACCEL */
/* | DEBUG_VERBOSE_SYNC */
/* | DEBUG_VERBOSE_VGA */
/* | DEBUG_VERBOSE_RING */
/* | DEBUG_VERBOSE_OUTREG */
/* | DEBUG_VERBOSE_MEMORY */
/* | DEBUG_VERBOSE_CURSOR */
);
#endif
static Bool
i810ModeInit(KdScreenInfo *screen, const KdMonitorTiming *t);
static void
i810PrintMode( vgaRegPtr vgaReg, I810RegPtr mode );
Bool
i810CardInit (KdCardInfo *card)
{
int i;
I810CardInfo *i810c;
/* fprintf(stderr,"i810CardInit\n"); */
i810c = (I810CardInfo *) xalloc (sizeof (I810CardInfo));
if (!i810c)
return FALSE;
/* 2MB Video RAM */
i810c->videoRam=2048;
/* Find FB address */
if (card->attr.address[1] != 0) {
i810c->LinearAddr = card->attr.address[0] & 0xFF000000;
if (!i810c->LinearAddr) {
fprintf(stderr,"No valid FB address in PCI config space(1)\n");
xfree(i810c);
return FALSE;
} else {
/* fprintf(stderr,"Linear framebuffer at %lx\n",i810c->LinearAddr); */
}
} else {
fprintf(stderr,"No valid FB address in PCI config space(2)\n");
xfree(i810c);
return FALSE;
}
if (card->attr.address[1]) {
i810c->MMIOAddr = card->attr.address[1] & 0xFFF80000;
i810c->MMIOBase =
KdMapDevice (i810c->MMIOAddr, I810_REG_SIZE);
if (!i810c->MMIOBase) {
fprintf(stderr,"No valid MMIO address in PCI config space(1)\n");
xfree(i810c);
return FALSE;
} else {
}
} else {
fprintf(stderr,"No valid MMIO address in PCI config space(2)\n");
xfree(i810c);
return FALSE;
}
/* fprintf(stderr,"Mapped 0x%x bytes of MMIO regs at phys 0x%lx virt %p\n", */
/* I810_REG_SIZE,i810c->MMIOAddr,i810c->MMIOBase); */
/* Find out memory bus frequency.
*/
{
unsigned long *p;
if (!(p= (unsigned long *) LinuxGetPciCfg(&card->attr)))
return FALSE;
/* fprintf(stderr,"Frequency long %lx\n",p[WHTCFG_PAMR_DRP]); */
if ( (p[WHTCFG_PAMR_DRP] & LM_FREQ_MASK) == LM_FREQ_133 )
i810c->LmFreqSel = 133;
else
i810c->LmFreqSel = 100;
xfree(p);
/* fprintf(stderr,"Selected frequency %d\n",i810c->LmFreqSel); */
}
/* fprintf(stderr,"Will alloc AGP framebuffer: %d kByte\n",i810c->videoRam); */
/* Since we always want write combining on first 32 mb of framebuffer
* we pass a mapsize of 32 mb */
i810c->FbMapSize = 32*1024*1024;
for (i = 2 ; i < i810c->FbMapSize ; i <<= 1);
i810c->FbMapSize = i;
i810c->FbBase =
KdMapDevice (i810c->LinearAddr, i810c->FbMapSize);
if (!i810c->FbBase) return FALSE;
/* fprintf(stderr,"Mapped 0x%lx bytes of framebuffer at %p\n", */
/* i810c->FbMapSize,i810c->FbBase); */
card->driver=i810c;
return TRUE;
}
static void
i810ScreenFini (KdScreenInfo *screen)
{
I810ScreenInfo *i810s = (I810ScreenInfo *) screen->driver;
xfree (i810s);
screen->driver = 0;
}
static Bool
i810InitScreen (ScreenPtr pScreen) {
#ifdef XV
i810InitVideo(pScreen);
#endif
return TRUE;
}
static Bool
i810FinishInitScreen(ScreenPtr pScreen)
{
/* XXX: RandR init */
return TRUE;
}
static void
i810CardFini (KdCardInfo *card)
{
I810CardInfo *i810c = (I810CardInfo *) card->driver;
KdUnmapDevice (i810c->FbBase, i810c->FbMapSize);
KdUnmapDevice (i810c->MMIOBase, I810_REG_SIZE);
xfree (i810c);
card->driver = 0;
}
struct wm_info {
double freq;
unsigned int wm;
};
struct wm_info i810_wm_8_100[] = {
{ 0, 0x22003000 },
{ 25.2, 0x22003000 },
{ 28.0, 0x22003000 },
{ 31.5, 0x22003000 },
{ 36.0, 0x22007000 },
{ 40.0, 0x22007000 },
{ 45.0, 0x22007000 },
{ 49.5, 0x22008000 },
{ 50.0, 0x22008000 },
{ 56.3, 0x22008000 },
{ 65.0, 0x22008000 },
{ 75.0, 0x22008000 },
{ 78.8, 0x22008000 },
{ 80.0, 0x22008000 },
{ 94.0, 0x22008000 },
{ 96.0, 0x22107000 },
{ 99.0, 0x22107000 },
{ 108.0, 0x22107000 },
{ 121.0, 0x22107000 },
{ 128.9, 0x22107000 },
{ 132.0, 0x22109000 },
{ 135.0, 0x22109000 },
{ 157.5, 0x2210b000 },
{ 162.0, 0x2210b000 },
{ 175.5, 0x2210b000 },
{ 189.0, 0x2220e000 },
{ 202.5, 0x2220e000 }
};
struct wm_info i810_wm_16_100[] = {
{ 0, 0x22004000 },
{ 25.2, 0x22006000 },
{ 28.0, 0x22006000 },
{ 31.5, 0x22007000 },
{ 36.0, 0x22007000 },
{ 40.0, 0x22007000 },
{ 45.0, 0x22007000 },
{ 49.5, 0x22009000 },
{ 50.0, 0x22009000 },
{ 56.3, 0x22108000 },
{ 65.0, 0x2210e000 },
{ 75.0, 0x2210e000 },
{ 78.8, 0x2210e000 },
{ 80.0, 0x22210000 },
{ 94.5, 0x22210000 },
{ 96.0, 0x22210000 },
{ 99.0, 0x22210000 },
{ 108.0, 0x22210000 },
{ 121.0, 0x22210000 },
{ 128.9, 0x22210000 },
{ 132.0, 0x22314000 },
{ 135.0, 0x22314000 },
{ 157.5, 0x22415000 },
{ 162.0, 0x22416000 },
{ 175.5, 0x22416000 },
{ 189.0, 0x22416000 },
{ 195.0, 0x22416000 },
{ 202.5, 0x22416000 }
};
struct wm_info i810_wm_24_100[] = {
{ 0, 0x22006000 },
{ 25.2, 0x22009000 },
{ 28.0, 0x22009000 },
{ 31.5, 0x2200a000 },
{ 36.0, 0x2210c000 },
{ 40.0, 0x2210c000 },
{ 45.0, 0x2210c000 },
{ 49.5, 0x22111000 },
{ 50.0, 0x22111000 },
{ 56.3, 0x22111000 },
{ 65.0, 0x22214000 },
{ 75.0, 0x22214000 },
{ 78.8, 0x22215000 },
{ 80.0, 0x22216000 },
{ 94.5, 0x22218000 },
{ 96.0, 0x22418000 },
{ 99.0, 0x22418000 },
{ 108.0, 0x22418000 },
{ 121.0, 0x22418000 },
{ 128.9, 0x22419000 },
{ 132.0, 0x22519000 },
{ 135.0, 0x4441d000 },
{ 157.5, 0x44419000 },
{ 162.0, 0x44419000 },
{ 175.5, 0x44419000 },
{ 189.0, 0x44419000 },
{ 195.0, 0x44419000 },
{ 202.5, 0x44419000 }
};
struct wm_info i810_wm_32_100[] = {
{ 0, 0x2210b000 },
{ 60, 0x22415000 }, /* 0x314000 works too */
{ 80, 0x22419000 } /* 0x518000 works too */
};
struct wm_info i810_wm_8_133[] = {
{ 0, 0x22003000 },
{ 25.2, 0x22003000 },
{ 28.0, 0x22003000 },
{ 31.5, 0x22003000 },
{ 36.0, 0x22007000 },
{ 40.0, 0x22007000 },
{ 45.0, 0x22007000 },
{ 49.5, 0x22008000 },
{ 50.0, 0x22008000 },
{ 56.3, 0x22008000 },
{ 65.0, 0x22008000 },
{ 75.0, 0x22008000 },
{ 78.8, 0x22008000 },
{ 80.0, 0x22008000 },
{ 94.0, 0x22008000 },
{ 96.0, 0x22107000 },
{ 99.0, 0x22107000 },
{ 108.0, 0x22107000 },
{ 121.0, 0x22107000 },
{ 128.9, 0x22107000 },
{ 132.0, 0x22109000 },
{ 135.0, 0x22109000 },
{ 157.5, 0x2210b000 },
{ 162.0, 0x2210b000 },
{ 175.5, 0x2210b000 },
{ 189.0, 0x2220e000 },
{ 202.5, 0x2220e000 }
};
struct wm_info i810_wm_16_133[] = {
{ 0, 0x22004000 },
{ 25.2, 0x22006000 },
{ 28.0, 0x22006000 },
{ 31.5, 0x22007000 },
{ 36.0, 0x22007000 },
{ 40.0, 0x22007000 },
{ 45.0, 0x22007000 },
{ 49.5, 0x22009000 },
{ 50.0, 0x22009000 },
{ 56.3, 0x22108000 },
{ 65.0, 0x2210e000 },
{ 75.0, 0x2210e000 },
{ 78.8, 0x2210e000 },
{ 80.0, 0x22210000 },
{ 94.5, 0x22210000 },
{ 96.0, 0x22210000 },
{ 99.0, 0x22210000 },
{ 108.0, 0x22210000 },
{ 121.0, 0x22210000 },
{ 128.9, 0x22210000 },
{ 132.0, 0x22314000 },
{ 135.0, 0x22314000 },
{ 157.5, 0x22415000 },
{ 162.0, 0x22416000 },
{ 175.5, 0x22416000 },
{ 189.0, 0x22416000 },
{ 195.0, 0x22416000 },
{ 202.5, 0x22416000 }
};
struct wm_info i810_wm_24_133[] = {
{ 0, 0x22006000 },
{ 25.2, 0x22009000 },
{ 28.0, 0x22009000 },
{ 31.5, 0x2200a000 },
{ 36.0, 0x2210c000 },
{ 40.0, 0x2210c000 },
{ 45.0, 0x2210c000 },
{ 49.5, 0x22111000 },
{ 50.0, 0x22111000 },
{ 56.3, 0x22111000 },
{ 65.0, 0x22214000 },
{ 75.0, 0x22214000 },
{ 78.8, 0x22215000 },
{ 80.0, 0x22216000 },
{ 94.5, 0x22218000 },
{ 96.0, 0x22418000 },
{ 99.0, 0x22418000 },
{ 108.0, 0x22418000 },
{ 121.0, 0x22418000 },
{ 128.9, 0x22419000 },
{ 132.0, 0x22519000 },
{ 135.0, 0x4441d000 },
{ 157.5, 0x44419000 },
{ 162.0, 0x44419000 },
{ 175.5, 0x44419000 },
{ 189.0, 0x44419000 },
{ 195.0, 0x44419000 },
{ 202.5, 0x44419000 }
};
static void
i810WriteControlMMIO(I810CardInfo *i810c, int addr, CARD8 index, CARD8 val) {
moutb(addr, index);
moutb(addr+1, val);
}
static CARD8
i810ReadControlMMIO(I810CardInfo *i810c, int addr, CARD8 index) {
moutb(addr, index);
return minb(addr+1);
}
static Bool
i810ModeSupported (KdScreenInfo *screen, const KdMonitorTiming *t)
{
/* This is just a guess. */
if (t->horizontal > 1600 || t->horizontal < 640) return FALSE;
if (t->vertical > 1200 || t->horizontal < 350) return FALSE;
return TRUE;
}
static Bool
i810ModeUsable (KdScreenInfo *screen)
{
KdCardInfo *card = screen->card;
I810CardInfo *i810c = (I810CardInfo *) card->driver;
int byte_width, pixel_width, screen_size;
/* fprintf(stderr,"i810ModeUsable\n"); */
if (screen->fb[0].depth >= 24)
{
screen->fb[0].depth = 24;
screen->fb[0].bitsPerPixel = 24;
screen->dumb = TRUE;
}
else if (screen->fb[0].depth >= 16)
{
screen->fb[0].depth = 16;
screen->fb[0].bitsPerPixel = 16;
}
else if (screen->fb[0].depth >= 15)
{
screen->fb[0].depth = 15;
screen->fb[0].bitsPerPixel = 16;
}
else
{
screen->fb[0].depth = 8;
screen->fb[0].bitsPerPixel = 8;
}
byte_width = screen->width * (screen->fb[0].bitsPerPixel >> 3);
pixel_width = screen->width;
screen->fb[0].pixelStride = pixel_width;
screen->fb[0].byteStride = byte_width;
screen_size = byte_width * screen->height;
return screen_size <= (i810c->videoRam * 1024);
}
static int i810AllocateGARTMemory( KdScreenInfo *screen )
{
KdCardInfo *card = screen->card;
I810CardInfo *i810c = (I810CardInfo *) card->driver;
unsigned long size = i810c->videoRam * 1024;
int key;
long tom = 0;
unsigned long physical;
if (!KdAgpGARTSupported())
return FALSE;
if (!KdAcquireGART(screen->mynum))
return FALSE;
/* This allows the 2d only Xserver to regen */
i810c->agpAcquired2d = TRUE;
/* Treat the gart like video memory - we assume we own all that is
* there, so ignore EBUSY errors. Don't try to remove it on
* failure, either, as other X server may be using it.
*/
if ((key = KdAllocateGARTMemory(screen->mynum, size, 0, NULL)) == -1)
return FALSE;
i810c->VramOffset = 0;
i810c->VramKey = key;
if (!KdBindGARTMemory(screen->mynum, key, 0))
return FALSE;
i810c->SysMem.Start = 0;
i810c->SysMem.Size = size;
i810c->SysMem.End = size;
i810c->SavedSysMem = i810c->SysMem;
tom = i810c->SysMem.End;
i810c->DcacheMem.Start = 0;
i810c->DcacheMem.End = 0;
i810c->DcacheMem.Size = 0;
i810c->CursorPhysical = 0;
/* Dcache - half the speed of normal ram, so not really useful for
* a 2d server. Don't bother reporting its presence. This is
* mapped in addition to the requested amount of system ram.
*/
size = 1024 * 4096;
/* Keep it 512K aligned for the sake of tiled regions.
*/
tom += 0x7ffff;
tom &= ~0x7ffff;
if ((key = KdAllocateGARTMemory(screen->mynum, size, AGP_DCACHE_MEMORY, NULL)) != -1) {
i810c->DcacheOffset= tom;
i810c->DcacheKey = key;
if (!KdBindGARTMemory(screen->mynum, key, tom)) {
fprintf(stderr,"Allocation of %ld bytes for DCACHE failed\n", size);
i810c->DcacheKey = -1;
} else {
i810c->DcacheMem.Start = tom;
i810c->DcacheMem.Size = size;
i810c->DcacheMem.End = i810c->DcacheMem.Start + i810c->DcacheMem.Size;
tom = i810c->DcacheMem.End;
}
} else {
fprintf(stderr,
"No physical memory available for %ld bytes of DCACHE\n",
size);
i810c->DcacheKey = -1;
}
/* Mouse cursor -- The i810 (crazy) needs a physical address in
* system memory from which to upload the cursor. We get this from
* the agpgart module using a special memory type.
*/
/* 4k for the cursor is excessive, I'm going to steal 3k for
* overlay registers later
*/
size = 4096;
if ((key = KdAllocateGARTMemory(screen->mynum, size, AGP_PHYS_MEMORY,
&physical)) == -1) {
fprintf(stderr,
"No physical memory available for HW cursor\n");
i810c->HwcursKey = -1;
} else {
i810c->HwcursOffset= tom;
i810c->HwcursKey = key;
if (!KdBindGARTMemory(screen->mynum, key, tom)) {
fprintf(stderr,
"Allocation of %ld bytes for HW cursor failed\n",
size);
i810c->HwcursKey = -1;
} else {
i810c->CursorPhysical = physical;
i810c->CursorStart = tom;
tom += size;
}
}
/* Overlay register buffer -- Just like the cursor, the i810 needs a
* physical address in system memory from which to upload the overlay
* registers.
*/
if (i810c->CursorStart != 0) {
i810c->OverlayPhysical = i810c->CursorPhysical + 1024;
i810c->OverlayStart = i810c->CursorStart + 1024;
}
i810c->GttBound = 1;
return TRUE;
}
/* Allocate from a memrange, returns success */
static int i810AllocLow( I810MemRange *result, I810MemRange *pool, int size )
{
if (size > pool->Size) return FALSE;
pool->Size -= size;
result->Size = size;
result->Start = pool->Start;
result->End = pool->Start += size;
return TRUE;
}
static int i810AllocHigh( I810MemRange *result, I810MemRange *pool, int size )
{
if (size > pool->Size) return 0;
pool->Size -= size;
result->Size = size;
result->End = pool->End;
result->Start = pool->End -= size;
return 1;
}
static Bool
i810AllocateFront(KdScreenInfo *screen) {
KdCardInfo *card = screen->card;
I810CardInfo *i810c = (I810CardInfo *) card->driver;
int cache_lines = -1;
if(i810c->DoneFrontAlloc)
return TRUE;
memset(&(i810c->FbMemBox), 0, sizeof(BoxRec));
/* Alloc FrontBuffer/Ring/Accel memory */
i810c->FbMemBox.x1=0;
i810c->FbMemBox.x2=screen->width;
i810c->FbMemBox.y1=0;
i810c->FbMemBox.y2=screen->height;
/* This could be made a command line option */
cache_lines = 0;
if(cache_lines >= 0)
i810c->FbMemBox.y2 += cache_lines;
else {
/* make sure there is enough for two DVD sized YUV buffers */
i810c->FbMemBox.y2 += (screen->fb[0].depth == 24) ? 256 : 384;
if (screen->width <= 1024)
i810c->FbMemBox.y2 += (screen->fb[0].depth == 24) ? 256 : 384;
cache_lines = i810c->FbMemBox.y2 - screen->height;
}
if (I810_DEBUG)
ErrorF("Adding %i scanlines for pixmap caching\n", cache_lines);
/* Reserve room for the framebuffer and pixcache. Put at the top
* of memory so we can have nice alignment for the tiled regions at
* the start of memory.
*/
i810AllocLow( &(i810c->FrontBuffer),
&(i810c->SysMem),
((i810c->FbMemBox.x2 *
i810c->FbMemBox.y2 *
i810c->cpp) + 4095) & ~4095);
memset( &(i810c->LpRing), 0, sizeof( I810RingBuffer ) );
if(i810AllocLow( &(i810c->LpRing.mem), &(i810c->SysMem), 16*4096 )) {
if (I810_DEBUG & DEBUG_VERBOSE_MEMORY)
ErrorF( "ring buffer at local %lx\n",
i810c->LpRing.mem.Start);
i810c->LpRing.tail_mask = i810c->LpRing.mem.Size - 1;
i810c->LpRing.virtual_start = i810c->FbBase + i810c->LpRing.mem.Start;
i810c->LpRing.head = 0;
i810c->LpRing.tail = 0;
i810c->LpRing.space = 0;
}
if ( i810AllocLow( &i810c->Scratch, &(i810c->SysMem), 64*1024 ) ||
i810AllocLow( &i810c->Scratch, &(i810c->SysMem), 16*1024 ) ) {
if (I810_DEBUG & DEBUG_VERBOSE_MEMORY)
ErrorF("Allocated Scratch Memory\n");
}
#ifdef XV
/* 720x720 is just how much memory the mpeg player needs for overlays */
if ( i810AllocHigh( &i810c->XvMem, &(i810c->SysMem), 720*720*2 )) {
if (I810_DEBUG & DEBUG_VERBOSE_MEMORY)
ErrorF("Allocated overlay Memory\n");
}
#endif
i810c->DoneFrontAlloc = TRUE;
return TRUE;
}
static Bool
i810MapMem(KdScreenInfo *screen)
{
KdCardInfo *card = screen->card;
I810CardInfo *i810c = (I810CardInfo *) card->driver;
i810c->LpRing.virtual_start = i810c->FbBase + i810c->LpRing.mem.Start;
return TRUE;
}
Bool
i810ScreenInit (KdScreenInfo *screen)
{
KdCardInfo *card = screen->card;
I810CardInfo *i810c = (I810CardInfo *) card->driver;
I810ScreenInfo *i810s;
int i;
const KdMonitorTiming *t;
/* fprintf(stderr,"i810ScreenInit\n"); */
i810s = (I810ScreenInfo *) xalloc (sizeof (I810ScreenInfo));
if (!i810s)
return FALSE;
memset (i810s, '\0', sizeof (I810ScreenInfo));
i810s->i810c = i810c;
/* Default dimensions */
if (!screen->width || !screen->height)
{
screen->width = 720;
screen->height = 576;
screen->rate = 52;
#if 0
screen->width = 1024;
screen->height = 768;
screen->rate = 72;
#endif
}
if (!screen->fb[0].depth)
screen->fb[0].depth = 16;
t = KdFindMode (screen, i810ModeSupported);
screen->rate = t->rate;
screen->width = t->horizontal;
screen->height = t->vertical;
if (!KdTuneMode (screen, i810ModeUsable, i810ModeSupported))
{
xfree (i810c);
return FALSE;
}
/* fprintf(stderr,"Screen rate %d horiz %d vert %d\n",t->rate,t->horizontal,t->vertical); */
switch (screen->fb[0].depth) {
case 8:
screen->fb[0].visuals = ((1 << StaticGray) |
(1 << GrayScale) |
(1 << StaticColor) |
(1 << PseudoColor) |
(1 << TrueColor) |
(1 << DirectColor));
screen->fb[0].blueMask = 0x00;
screen->fb[0].greenMask = 0x00;
screen->fb[0].redMask = 0x00;
break;
case 15:
screen->fb[0].visuals = (1 << TrueColor);
screen->fb[0].blueMask = 0x001f;
screen->fb[0].greenMask = 0x03e0;
screen->fb[0].redMask = 0x7c00;
i810c->colorKey = 0x043f;
break;
case 16:
screen->fb[0].visuals = (1 << TrueColor);
screen->fb[0].blueMask = 0x001f;
screen->fb[0].greenMask = 0x07e0;
screen->fb[0].redMask = 0xf800;
i810c->colorKey = 0x083f;
break;
case 24:
screen->fb[0].visuals = (1 << TrueColor);
screen->fb[0].blueMask = 0x0000ff;
screen->fb[0].greenMask = 0x00ff00;
screen->fb[0].redMask = 0xff0000;
i810c->colorKey = 0x0101ff;
break;
default:
fprintf(stderr,"Unsupported depth %d\n",screen->fb[0].depth);
return FALSE;
}
/* Set all colours to black */
for (i=0; i<768; i++) i810c->vga.ModeReg.DAC[i] = 0x00;
/* ... and the overscan */
if (screen->fb[0].depth >= 4)
i810c->vga.ModeReg.Attribute[OVERSCAN] = 0xFF;
/* Could be made a command-line option */
#ifdef I810CFG_SHOW_OVERSCAN
i810c->vga.ModeReg.DAC[765] = 0x3F;
i810c->vga.ModeReg.DAC[766] = 0x00;
i810c->vga.ModeReg.DAC[767] = 0x3F;
i810c->vga.ModeReg.Attribute[OVERSCAN] = 0xFF;
i810c->vga.ShowOverscan = TRUE;
#else
i810c->vga.ShowOverscan = FALSE;
#endif
i810c->vga.paletteEnabled = FALSE;
i810c->vga.cmapSaved = FALSE;
i810c->vga.MMIOBase = i810c->MMIOBase;
i810c->cpp = screen->fb[0].bitsPerPixel/8;
/* move to initscreen? */
switch (screen->fb[0].bitsPerPixel) {
case 8:
i810c->MaxClock = 203000;
break;
case 16:
i810c->MaxClock = 163000;
break;
case 24:
i810c->MaxClock = 136000;
break;
case 32: /* not supported */
i810c->MaxClock = 86000;
default:
fprintf(stderr,"Unsupported bpp %d\n",screen->fb[0].bitsPerPixel);
return FALSE;
}
if (!i810AllocateGARTMemory( screen )) {
return FALSE;
}
i810AllocateFront(screen);
/* Map LpRing memory */
if (!i810MapMem(screen)) return FALSE;
screen->fb[0].frameBuffer = i810c->FbBase;
screen->driver = i810s;
return TRUE;
}
/*
* I810Save --
*
* This function saves the video state. It reads all of the SVGA registers
* into the vgaI810Rec data structure. There is in general no need to
* mask out bits here - just read the registers.
*/
static void
DoSave(KdCardInfo *card, vgaRegPtr vgaReg, I810RegPtr i810Reg, Bool saveFonts)
{
I810CardInfo *i810c = card->driver;
i810VGAPtr vgap = &i810c->vga;
int i;
/* Save VGA registers */
vgaReg->MiscOutReg = mmioReadMiscOut(vgap);
if (vgaReg->MiscOutReg & 0x01)
vgap->IOBase = VGA_IOBASE_COLOR;
else
vgap->IOBase = VGA_IOBASE_MONO;
for (i = 0; i < VGA_NUM_CRTC; i++) {
vgaReg->CRTC[i] = mmioReadCrtc(vgap, i);
}
mmioEnablePalette(vgap);
for (i = 0; i < VGA_NUM_ATTR; i++) {
vgaReg->Attribute[i] = mmioReadAttr(vgap, i);
}
mmioDisablePalette(vgap);
for (i = 0; i < VGA_NUM_GFX; i++) {
vgaReg->Graphics[i] = mmioReadGr(vgap, i);
}
for (i = 1; i < VGA_NUM_SEQ; i++) {
vgaReg->Sequencer[i] = mmioReadSeq(vgap, i);
}
/*
* The port I/O code necessary to read in the extended registers
* into the fields of the I810Rec structure goes here.
*/
i810Reg->IOControl = mmioReadCrtc(vgap, IO_CTNL);
i810Reg->AddressMapping = i810ReadControlMMIO(i810c, GRX, ADDRESS_MAPPING);
i810Reg->BitBLTControl = INREG8(BITBLT_CNTL);
i810Reg->VideoClk2_M = INREG16(VCLK2_VCO_M);
i810Reg->VideoClk2_N = INREG16(VCLK2_VCO_N);
i810Reg->VideoClk2_DivisorSel = INREG8(VCLK2_VCO_DIV_SEL);
i810Reg->ExtVertTotal=mmioReadCrtc(vgap, EXT_VERT_TOTAL);
i810Reg->ExtVertDispEnd=mmioReadCrtc(vgap, EXT_VERT_DISPLAY);
i810Reg->ExtVertSyncStart=mmioReadCrtc(vgap, EXT_VERT_SYNC_START);
i810Reg->ExtVertBlankStart=mmioReadCrtc(vgap, EXT_VERT_BLANK_START);
i810Reg->ExtHorizTotal=mmioReadCrtc(vgap, EXT_HORIZ_TOTAL);
i810Reg->ExtHorizBlank=mmioReadCrtc(vgap, EXT_HORIZ_BLANK);
i810Reg->ExtOffset=mmioReadCrtc(vgap, EXT_OFFSET);
i810Reg->InterlaceControl=mmioReadCrtc(vgap, INTERLACE_CNTL);
i810Reg->PixelPipeCfg0 = INREG8(PIXPIPE_CONFIG_0);
i810Reg->PixelPipeCfg1 = INREG8(PIXPIPE_CONFIG_1);
i810Reg->PixelPipeCfg2 = INREG8(PIXPIPE_CONFIG_2);
i810Reg->DisplayControl = INREG8(DISPLAY_CNTL);
i810Reg->LMI_FIFO_Watermark = INREG(FWATER_BLC);
for (i = 0 ; i < 8 ; i++)
i810Reg->Fence[i] = INREG(FENCE+i*4);
i810Reg->LprbTail = INREG(LP_RING + RING_TAIL);
i810Reg->LprbHead = INREG(LP_RING + RING_HEAD);
i810Reg->LprbStart = INREG(LP_RING + RING_START);
i810Reg->LprbLen = INREG(LP_RING + RING_LEN);
if ((i810Reg->LprbTail & TAIL_ADDR) != (i810Reg->LprbHead & HEAD_ADDR) &&
i810Reg->LprbLen & RING_VALID) {
i810PrintErrorState( i810c );
FatalError( "Active ring not flushed\n");
}
if (I810_DEBUG) {
fprintf(stderr,"Got mode in I810Save:\n");
i810PrintMode( vgaReg, i810Reg );
}
}
static void
i810Preserve(KdCardInfo *card)
{
I810CardInfo *i810c = card->driver;
i810VGAPtr vgap = &i810c->vga;
/* fprintf(stderr,"i810Preserve\n"); */
DoSave(card, &vgap->SavedReg, &i810c->SavedReg, TRUE);
}
/* Famous last words
*/
void
i810PrintErrorState(i810CardInfo *i810c)
{
fprintf(stderr, "pgetbl_ctl: 0x%lx pgetbl_err: 0x%lx\n",
INREG(PGETBL_CTL),
INREG(PGE_ERR));
fprintf(stderr, "ipeir: %lx iphdr: %lx\n",
INREG(IPEIR),
INREG(IPEHR));
fprintf(stderr, "LP ring tail: %lx head: %lx len: %lx start %lx\n",
INREG(LP_RING + RING_TAIL),
INREG(LP_RING + RING_HEAD) & HEAD_ADDR,
INREG(LP_RING + RING_LEN),
INREG(LP_RING + RING_START));
fprintf(stderr, "eir: %x esr: %x emr: %x\n",
INREG16(EIR),
INREG16(ESR),
INREG16(EMR));
fprintf(stderr, "instdone: %x instpm: %x\n",
INREG16(INST_DONE),
INREG8(INST_PM));
fprintf(stderr, "memmode: %lx instps: %lx\n",
INREG(MEMMODE),
INREG(INST_PS));
fprintf(stderr, "hwstam: %x ier: %x imr: %x iir: %x\n",
INREG16(HWSTAM),
INREG16(IER),
INREG16(IMR),
INREG16(IIR));
}
static Bool
i810BindGARTMemory( KdScreenInfo *screen )
{
KdCardInfo *card = screen->card;
I810CardInfo *i810c = card->driver;
if (!i810c->GttBound) {
if (!KdAcquireGART(screen->mynum))
return FALSE;
if (!KdBindGARTMemory(screen->mynum, i810c->VramKey,
i810c->VramOffset))
return FALSE;
if (i810c->DcacheKey != -1) {
if (!KdBindGARTMemory(screen->mynum, i810c->DcacheKey,
i810c->DcacheOffset))
return FALSE;
}
if (i810c->HwcursKey != -1) {
if (!KdBindGARTMemory(screen->mynum, i810c->HwcursKey,
i810c->HwcursOffset))
return FALSE;
}
i810c->GttBound = 1;
}
return TRUE;
}
static Bool
i810UnbindGARTMemory(KdScreenInfo *screen)
{
KdCardInfo *card = screen->card;
I810CardInfo *i810c = card->driver;
if (KdAgpGARTSupported() && i810c->GttBound) {
if (!KdUnbindGARTMemory(screen->mynum, i810c->VramKey))
return FALSE;
if (i810c->DcacheKey != -1) {
if (!KdUnbindGARTMemory(screen->mynum, i810c->DcacheKey))
return FALSE;
}
if (i810c->HwcursKey != -1) {
if (!KdUnbindGARTMemory(screen->mynum, i810c->HwcursKey))
return FALSE;
}
if (!KdReleaseGART(screen->mynum))
return FALSE;
i810c->GttBound = 0;
}
return TRUE;
}
/*
* I810CalcVCLK --
*
* Determine the closest clock frequency to the one requested.
*/
#define MAX_VCO_FREQ 600.0
#define TARGET_MAX_N 30
#define REF_FREQ 24.0
#define CALC_VCLK(m,n,p) \
(double)m / ((double)n * (1 << p)) * 4 * REF_FREQ
static void
i810CalcVCLK( KdScreenInfo *screen, double freq )
{
KdCardInfo *card = screen->card;
I810CardInfo *i810c = card->driver;
I810RegPtr i810Reg = &i810c->ModeReg;
int m, n, p;
double f_out, f_best;
double f_err;
double f_vco;
int m_best = 0, n_best = 0, p_best = 0;
double f_target = freq;
double err_max = 0.005;
double err_target = 0.001;
double err_best = 999999.0;
p_best = p = log(MAX_VCO_FREQ/f_target)/log((double)2);
f_vco = f_target * (1 << p);
n = 2;
do {
n++;
m = f_vco / (REF_FREQ / (double)n) / (double)4.0 + 0.5;
if (m < 3) m = 3;
f_out = CALC_VCLK(m,n,p);
f_err = 1.0 - (f_target/f_out);
if (fabs(f_err) < err_max) {
m_best = m;
n_best = n;
f_best = f_out;
err_best = f_err;
}
} while ((fabs(f_err) >= err_target) &&
((n <= TARGET_MAX_N) || (fabs(err_best) > err_max)));
if (fabs(f_err) < err_target) {
m_best = m;
n_best = n;
}
i810Reg->VideoClk2_M = (m_best-2) & 0x3FF;
i810Reg->VideoClk2_N = (n_best-2) & 0x3FF;
i810Reg->VideoClk2_DivisorSel = (p_best << 4);
/* fprintf(stderr, "Setting dot clock to %.1f MHz " */
/* "[ 0x%x 0x%x 0x%x ] " */
/* "[ %d %d %d ]\n", */
/* CALC_VCLK(m_best,n_best,p_best), */
/* i810Reg->VideoClk2_M, */
/* i810Reg->VideoClk2_N, */
/* i810Reg->VideoClk2_DivisorSel, */
/* m_best, n_best, p_best); */
}
/*
* I810CalcFIFO --
*
* Calculate burst length and FIFO watermark.
*/
#define Elements(x) (sizeof(x)/sizeof(*x))
static unsigned int
i810CalcWatermark( KdScreenInfo *screen, double freq, Bool dcache )
{
KdCardInfo *card = screen->card;
I810CardInfo *i810c = card->driver;
struct wm_info *tab;
int nr;
int i;
if (i810c->LmFreqSel == 100) {
switch(screen->fb[0].bitsPerPixel) {
case 8:
tab = i810_wm_8_100;
nr = Elements(i810_wm_8_100);
break;
case 16:
tab = i810_wm_16_100;
nr = Elements(i810_wm_16_100);
break;
case 24:
tab = i810_wm_24_100;
nr = Elements(i810_wm_24_100);
break;
default:
return 0;
}
} else {
switch(screen->fb[0].bitsPerPixel) {
case 8:
tab = i810_wm_8_133;
nr = Elements(i810_wm_8_133);
break;
case 16:
tab = i810_wm_16_133;
nr = Elements(i810_wm_16_133);
break;
case 24:
tab = i810_wm_24_133;
nr = Elements(i810_wm_24_133);
break;
default:
return 0;
}
}
for (i = 0 ; i < nr && tab[i].freq < freq ; i++);
if (i == nr)
i--;
/* fprintf(stderr,"chose watermark 0x%x: (tab.freq %.1f)\n", */
/* tab[i].wm, tab[i].freq); */
/* None of these values (sourced from intel) have watermarks for
* the dcache memory. Fake it for now by using the same watermark
* for both...
*
* Update: this is probably because dcache isn't real useful as
* framebuffer memory, so intel's drivers don't need watermarks
* for that memory because they never use it to feed the ramdacs.
* We do use it in the fallback mode, so keep the watermarks for
* now.
*/
if (dcache)
return (tab[i].wm & ~0xffffff) | ((tab[i].wm>>12) & 0xfff);
else
return tab[i].wm;
}
static void i810PrintMode( vgaRegPtr vgaReg, I810RegPtr mode )
{
int i;
fprintf(stderr," MiscOut: %x\n", vgaReg->MiscOutReg);
fprintf(stderr,"SEQ: ");
for (i = 0 ; i < VGA_NUM_SEQ ; i++) {
if ((i&7)==0) fprintf(stderr,"\n");
fprintf(stderr," %d: %x", i, vgaReg->Sequencer[i]);
}
fprintf(stderr,"\n");
fprintf(stderr,"CRTC: ");
for (i = 0 ; i < VGA_NUM_CRTC ; i++) {
if ((i&3)==0) fprintf(stderr,"\n");
fprintf(stderr," CR%02x: %2x", i, vgaReg->CRTC[i]);
}
fprintf(stderr,"\n");
fprintf(stderr,"GFX: ");
for (i = 0 ; i < VGA_NUM_GFX ; i++) {
if ((i&3)==0) fprintf(stderr,"\n");
fprintf(stderr," GR%02x: %02x", i, vgaReg->Graphics[i]);
}
fprintf(stderr,"\n");
fprintf(stderr,"ATTR: ");
for (i = 0 ; i < VGA_NUM_ATTR ; i++) {
if ((i&7)==0) fprintf(stderr,"\n");
fprintf(stderr," %d: %x", i, vgaReg->Attribute[i]);
}
fprintf(stderr,"\n");
fprintf(stderr," DisplayControl: %x\n", mode->DisplayControl);
fprintf(stderr," PixelPipeCfg0: %x\n", mode->PixelPipeCfg0);
fprintf(stderr," PixelPipeCfg1: %x\n", mode->PixelPipeCfg1);
fprintf(stderr," PixelPipeCfg2: %x\n", mode->PixelPipeCfg2);
fprintf(stderr," VideoClk2_M: %x\n", mode->VideoClk2_M);
fprintf(stderr," VideoClk2_N: %x\n", mode->VideoClk2_N);
fprintf(stderr," VideoClk2_DivisorSel: %x\n", mode->VideoClk2_DivisorSel);
fprintf(stderr," AddressMapping: %x\n", mode->AddressMapping);
fprintf(stderr," IOControl: %x\n", mode->IOControl);
fprintf(stderr," BitBLTControl: %x\n", mode->BitBLTControl);
fprintf(stderr," ExtVertTotal: %x\n", mode->ExtVertTotal);
fprintf(stderr," ExtVertDispEnd: %x\n", mode->ExtVertDispEnd);
fprintf(stderr," ExtVertSyncStart: %x\n", mode->ExtVertSyncStart);
fprintf(stderr," ExtVertBlankStart: %x\n", mode->ExtVertBlankStart);
fprintf(stderr," ExtHorizTotal: %x\n", mode->ExtHorizTotal);
fprintf(stderr," ExtHorizBlank: %x\n", mode->ExtHorizBlank);
fprintf(stderr," ExtOffset: %x\n", mode->ExtOffset);
fprintf(stderr," InterlaceControl: %x\n", mode->InterlaceControl);
fprintf(stderr," LMI_FIFO_Watermark: %x\n", mode->LMI_FIFO_Watermark);
fprintf(stderr," LprbTail: %x\n", mode->LprbTail);
fprintf(stderr," LprbHead: %x\n", mode->LprbHead);
fprintf(stderr," LprbStart: %x\n", mode->LprbStart);
fprintf(stderr," LprbLen: %x\n", mode->LprbLen);
fprintf(stderr," OverlayActiveStart: %x\n", mode->OverlayActiveStart);
fprintf(stderr," OverlayActiveEnd: %x\n", mode->OverlayActiveEnd);
}
/*
* i810VGASeqReset
* perform a sequencer reset.
*
* The i815 documentation states that these bits are not used by the
* HW, but still warns about not programming them...
*/
static void
i810VGASeqReset(i810VGAPtr vgap, Bool start)
{
if (start)
{
mmioWriteSeq(vgap, 0x00, 0x01); /* Synchronous Reset */
}
else
{
mmioWriteSeq(vgap, 0x00, 0x03); /* End Reset */
}
}
static void
i810VGAProtect(KdCardInfo *card, Bool on)
{
I810CardInfo *i810c = card->driver;
i810VGAPtr vgap = &i810c->vga;
unsigned char tmp;
if (on) {
/*
* Turn off screen and disable sequencer.
*/
tmp = mmioReadSeq(vgap, 0x01);
i810VGASeqReset(vgap, TRUE); /* start synchronous reset */
mmioWriteSeq(vgap, 0x01, tmp | 0x20); /* disable the display */
mmioEnablePalette(vgap);
} else {
/*
* Reenable sequencer, then turn on screen.
*/
tmp = mmioReadSeq(vgap, 0x01);
mmioWriteSeq(vgap, 0x01, tmp & ~0x20); /* reenable display */
i810VGASeqReset(vgap, FALSE); /* clear synchronousreset */
mmioDisablePalette(vgap);
}
}
/*
* i810VGABlankScreen -- blank the screen.
*/
void
i810VGABlankScreen(KdCardInfo *card, Bool on)
{
I810CardInfo *i810c = card->driver;
i810VGAPtr vgap = &i810c->vga;
unsigned char scrn;
scrn = mmioReadSeq(vgap, 0x01);
if (on) {
scrn &= ~0x20; /* enable screen */
} else {
scrn |= 0x20; /* blank screen */
}
mmioWriteSeq(vgap,0x00,0x01);
mmioWriteSeq(vgap, 0x01, scrn); /* change mode */
mmioWriteSeq(vgap,0x00,0x03);
}
/* Restore hardware state */
static void
DoRestore(KdCardInfo *card, vgaRegPtr vgaReg, I810RegPtr i810Reg,
Bool restoreFonts) {
I810CardInfo *i810c = card->driver;
i810VGAPtr vgap = &i810c->vga;
unsigned char temp;
unsigned int itemp;
int i;
if (I810_DEBUG & DEBUG_VERBOSE_VGA) {
fprintf(stderr,"Setting mode in DoRestore:\n");
i810PrintMode( vgaReg, i810Reg );
}
/* Blank screen (i810vgaprotect) */
i810VGAProtect(card, TRUE);
/* Should wait for at least two hsync and no more than two vsync
before writing PIXCONF and turning the display on (?) */
usleep(50000);
/* Turn off DRAM Refresh */
temp = INREG8( DRAM_ROW_CNTL_HI );
temp &= ~DRAM_REFRESH_RATE;
temp |= DRAM_REFRESH_DISABLE;
OUTREG8( DRAM_ROW_CNTL_HI, temp );
usleep(1000); /* Wait 1 ms */
/* Write the M, N and P values */
OUTREG16( VCLK2_VCO_M, i810Reg->VideoClk2_M);
OUTREG16( VCLK2_VCO_N, i810Reg->VideoClk2_N);
OUTREG8( VCLK2_VCO_DIV_SEL, i810Reg->VideoClk2_DivisorSel);
/*
* Turn on 8 bit dac mode, if requested. This is needed to make
* sure that vgaHWRestore writes the values into the DAC properly.
* The problem occurs if 8 bit dac mode is requested and the HW is
* in 6 bit dac mode. If this happens, all the values are
* automatically shifted left twice by the HW and incorrect colors
* will be displayed on the screen. The only time this can happen
* is at server startup time and when switching back from a VT.
*/
temp = INREG8(PIXPIPE_CONFIG_0);
temp &= 0x7F; /* Save all but the 8 bit dac mode bit */
temp |= (i810Reg->PixelPipeCfg0 & DAC_8_BIT);
OUTREG8( PIXPIPE_CONFIG_0, temp );
/*
* Code to restore any SVGA registers that have been saved/modified
* goes here. Note that it is allowable, and often correct, to
* only modify certain bits in a register by a read/modify/write cycle.
*
* A special case - when using an external clock-setting program,
* this function must not change bits associated with the clock
* selection. This condition can be checked by the condition:
*
* if (i810Reg->std.NoClock >= 0)
* restore clock-select bits.
*/
/* VGA restore */
if (vgaReg->MiscOutReg & 0x01)
vgap->IOBase = VGA_IOBASE_COLOR;
else
vgap->IOBase = VGA_IOBASE_MONO;
mmioWriteMiscOut(vgap, vgaReg->MiscOutReg);
for (i = 1; i < VGA_NUM_SEQ; i++)
mmioWriteSeq(vgap, i, vgaReg->Sequencer[i]);
/* Ensure CRTC registers 0-7 are unlocked by clearing bit 7 or CRTC[17] */
/* = CR11 */
mmioWriteCrtc(vgap, 17, vgaReg->CRTC[17] & ~0x80);
for (i = 0; i < VGA_NUM_CRTC; i++) {
mmioWriteCrtc(vgap, i, vgaReg->CRTC[i]);
}
for (i = 0; i < VGA_NUM_GFX; i++)
mmioWriteGr(vgap, i, vgaReg->Graphics[i]);
mmioEnablePalette(vgap);
for (i = 0; i < VGA_NUM_ATTR; i++)
mmioWriteAttr(vgap, i, vgaReg->Attribute[i]);
mmioDisablePalette(vgap);
mmioWriteCrtc(vgap, EXT_VERT_TOTAL, i810Reg->ExtVertTotal);
mmioWriteCrtc(vgap, EXT_VERT_DISPLAY, i810Reg->ExtVertDispEnd);
mmioWriteCrtc(vgap, EXT_VERT_SYNC_START, i810Reg->ExtVertSyncStart);
mmioWriteCrtc(vgap, EXT_VERT_BLANK_START, i810Reg->ExtVertBlankStart);
mmioWriteCrtc(vgap, EXT_HORIZ_TOTAL, i810Reg->ExtHorizTotal);
mmioWriteCrtc(vgap, EXT_HORIZ_BLANK, i810Reg->ExtHorizBlank);
/* write CR40, CR42 first etc to get CR13 written as described in PRM */
mmioWriteCrtc(vgap, EXT_START_ADDR_HI, 0);
mmioWriteCrtc(vgap, EXT_START_ADDR, EXT_START_ADDR_ENABLE);
mmioWriteCrtc(vgap, EXT_OFFSET, i810Reg->ExtOffset);
mmioWriteCrtc(vgap, 0x13, vgaReg->CRTC[0x13]);
temp=mmioReadCrtc(vgap, INTERLACE_CNTL);
temp &= ~INTERLACE_ENABLE;
temp |= i810Reg->InterlaceControl;
mmioWriteCrtc(vgap, INTERLACE_CNTL, temp);
temp=i810ReadControlMMIO(i810c, GRX, ADDRESS_MAPPING);
temp &= 0xE0; /* Save reserved bits 7:5 */
temp |= i810Reg->AddressMapping;
i810WriteControlMMIO(i810c, GRX, ADDRESS_MAPPING, temp);
/* Setting the OVRACT Register for video overlay*/
OUTREG(0x6001C, (i810Reg->OverlayActiveEnd << 16) | i810Reg->OverlayActiveStart);
/* Turn on DRAM Refresh */
temp = INREG8( DRAM_ROW_CNTL_HI );
temp &= ~DRAM_REFRESH_RATE;
temp |= DRAM_REFRESH_60HZ;
OUTREG8( DRAM_ROW_CNTL_HI, temp );
temp = INREG8( BITBLT_CNTL );
temp &= ~COLEXP_MODE;
temp |= i810Reg->BitBLTControl;
OUTREG8( BITBLT_CNTL, temp );
temp = INREG8( DISPLAY_CNTL );
temp &= ~(VGA_WRAP_MODE | GUI_MODE);
temp |= i810Reg->DisplayControl;
OUTREG8( DISPLAY_CNTL, temp );
temp = INREG8( PIXPIPE_CONFIG_0 );
temp &= 0x64; /* Save reserved bits 6:5,2 */
temp |= i810Reg->PixelPipeCfg0;
OUTREG8( PIXPIPE_CONFIG_0, temp );
temp = INREG8( PIXPIPE_CONFIG_2 );
temp &= 0xF3; /* Save reserved bits 7:4,1:0 */
temp |= i810Reg->PixelPipeCfg2;
OUTREG8( PIXPIPE_CONFIG_2, temp );
temp = INREG8( PIXPIPE_CONFIG_1 );
temp &= ~DISPLAY_COLOR_MODE;
temp &= 0xEF; /* Restore the CRT control bit */
temp |= i810Reg->PixelPipeCfg1;
OUTREG8( PIXPIPE_CONFIG_1, temp );
OUTREG16(EIR, 0);
itemp = INREG(FWATER_BLC);
itemp &= ~(LM_BURST_LENGTH | LM_FIFO_WATERMARK |
MM_BURST_LENGTH | MM_FIFO_WATERMARK );
itemp |= i810Reg->LMI_FIFO_Watermark;
OUTREG(FWATER_BLC, itemp);
for (i = 0 ; i < 8 ; i++) {
OUTREG( FENCE+i*4, i810Reg->Fence[i] );
if (I810_DEBUG & DEBUG_VERBOSE_VGA)
fprintf(stderr,"Fence Register : %x\n", i810Reg->Fence[i]);
}
/* First disable the ring buffer (Need to wait for empty first?, if so
* should probably do it before entering this section)
*/
itemp = INREG(LP_RING + RING_LEN);
itemp &= ~RING_VALID_MASK;
OUTREG(LP_RING + RING_LEN, itemp );
/* Set up the low priority ring buffer.
*/
OUTREG(LP_RING + RING_TAIL, 0 );
OUTREG(LP_RING + RING_HEAD, 0 );
i810c->LpRing.head = 0;
i810c->LpRing.tail = 0;
itemp = INREG(LP_RING + RING_START);
itemp &= ~(START_ADDR);
itemp |= i810Reg->LprbStart;
OUTREG(LP_RING + RING_START, itemp );
itemp = INREG(LP_RING + RING_LEN);
itemp &= ~(RING_NR_PAGES | RING_REPORT_MASK | RING_VALID_MASK);
itemp |= i810Reg->LprbLen;
OUTREG(LP_RING + RING_LEN, itemp );
i810VGAProtect(card, FALSE);
temp=mmioReadCrtc(vgap, IO_CTNL);
temp &= ~(EXTENDED_ATTR_CNTL | EXTENDED_CRTC_CNTL);
temp |= i810Reg->IOControl;
mmioWriteCrtc(vgap, IO_CTNL, temp);
/* Protect CRTC[0-7] */
mmioWriteCrtc(vgap, 0x11, mmioReadCrtc(vgap, 0x11) | 0x80);
}
static Bool
i810SetMode(KdScreenInfo *screen, const KdMonitorTiming *t)
{
KdCardInfo *card = screen->card;
I810CardInfo *i810c = card->driver;
i810VGAPtr vgap = &i810c->vga;
I810RegPtr i810Reg = &i810c->ModeReg;
vgaRegPtr pVga = &vgap->ModeReg;
double dclk = t->clock/1000.0;
switch (screen->fb[0].bitsPerPixel) {
case 8:
pVga->CRTC[0x13] = screen->width >> 3;
i810Reg->ExtOffset = screen->width >> 11;
i810Reg->PixelPipeCfg1 = DISPLAY_8BPP_MODE;
i810Reg->BitBLTControl = COLEXP_8BPP;
break;
case 16:
i810Reg->PixelPipeCfg1 = DISPLAY_16BPP_MODE;
pVga->CRTC[0x13] = screen->width >> 2;
i810Reg->ExtOffset = screen->width >> 10;
i810Reg->BitBLTControl = COLEXP_16BPP;
break;
case 24:
pVga->CRTC[0x13] = (screen->width * 3) >> 3;
i810Reg->ExtOffset = (screen->width * 3) >> 11;
i810Reg->PixelPipeCfg1 = DISPLAY_24BPP_MODE;
i810Reg->BitBLTControl = COLEXP_24BPP;
break;
default:
break;
}
i810Reg->PixelPipeCfg0 = DAC_8_BIT;
/* Do not delay CRT Blank: needed for video overlay */
i810Reg->PixelPipeCfg1 |= 0x10;
/* Turn on Extended VGA Interpretation */
i810Reg->IOControl = EXTENDED_CRTC_CNTL;
/* Turn on linear and page mapping */
i810Reg->AddressMapping = (LINEAR_MODE_ENABLE |
GTT_MEM_MAP_ENABLE);
/* Turn on GUI mode */
i810Reg->DisplayControl = HIRES_MODE;
i810Reg->OverlayActiveStart = t->horizontal + t->hblank - 32;
i810Reg->OverlayActiveEnd = t->horizontal - 32;
/* Turn on interlaced mode if necessary (it's not) */
i810Reg->InterlaceControl = INTERLACE_DISABLE;
/*
* Set the overscan color to 0.
* NOTE: This only affects >8bpp mode.
*/
pVga->Attribute[0x11] = 0;
/*
* Calculate the VCLK that most closely matches the requested dot
* clock.
*/
i810CalcVCLK(screen, dclk);
/* Since we program the clocks ourselves, always use VCLK2. */
pVga->MiscOutReg |= 0x0C;
/* Calculate the FIFO Watermark and Burst Length. */
i810Reg->LMI_FIFO_Watermark = i810CalcWatermark(screen, dclk, FALSE);
/* Setup the ring buffer */
i810Reg->LprbTail = 0;
i810Reg->LprbHead = 0;
i810Reg->LprbStart = i810c->LpRing.mem.Start;
if (i810Reg->LprbStart)
i810Reg->LprbLen = ((i810c->LpRing.mem.Size-4096) |
RING_NO_REPORT | RING_VALID);
else
i810Reg->LprbLen = RING_INVALID;
return TRUE;
}
static Bool
i810ModeInit(KdScreenInfo *screen, const KdMonitorTiming *t)
{
KdCardInfo *card = screen->card;
I810CardInfo *i810c = card->driver;
i810VGAPtr vgap = &i810c->vga;
vgaRegPtr pVga;
/* fprintf(stderr,"i810ModeInit\n"); */
i810VGAUnlock(vgap);
if (!i810VGAInit(screen, t)) return FALSE;
pVga = &vgap->ModeReg;
if (!i810SetMode(screen, t)) return FALSE;
DoRestore(screen->card, &vgap->ModeReg, &i810c->ModeReg, FALSE);
return TRUE;
}
Bool
i810VGAInit(KdScreenInfo *screen, const KdMonitorTiming *t)
{
unsigned int i;
int hactive, hblank, hbp, hfp;
int vactive, vblank, vbp, vfp;
int h_screen_off = 0, h_adjust = 0, h_total, h_display_end, h_blank_start;
int h_blank_end, h_sync_start, h_sync_end, v_total, v_retrace_start;
int v_retrace_end, v_display_end, v_blank_start, v_blank_end;
KdCardInfo *card = screen->card;
I810CardInfo *i810c = card->driver;
i810VGAPtr vgap = &i810c->vga;
I810RegPtr ireg = &i810c->ModeReg;
vgaRegPtr regp;
int depth = screen->fb[0].depth;
regp = &vgap->ModeReg;
/*
* compute correct Hsync & Vsync polarity
*/
regp->MiscOutReg = 0x23;
if (t->vpol == KdSyncNegative) regp->MiscOutReg |= 0x40;
if (t->hpol == KdSyncNegative) regp->MiscOutReg |= 0x80;
/*
* Time Sequencer
*/
if (depth == 4)
regp->Sequencer[0] = 0x02;
else
regp->Sequencer[0] = 0x00;
/* No support for 320 or 360 x resolution */
regp->Sequencer[1] = 0x01;
if (depth == 1)
regp->Sequencer[2] = 1 << BIT_PLANE;
else
regp->Sequencer[2] = 0x0F;
regp->Sequencer[3] = 0x00; /* Font select */
if (depth < 8)
regp->Sequencer[4] = 0x06; /* Misc */
else
regp->Sequencer[4] = 0x0E; /* Misc */
hactive = t->horizontal;
hblank = t->hblank;
hbp = t->hbp;
hfp = t->hfp;
vactive = t->vertical;
vblank = t->vblank;
vbp = t->vbp;
vfp = t->vfp;
switch (screen->fb[0].bitsPerPixel) {
case 8:
hactive /= 8;
hblank /= 8;
hfp /= 8;
hbp /= 8;
h_screen_off = hactive;
h_adjust = 1;
break;
case 16:
hactive /= 8;
hblank /= 8;
hfp /= 8;
hbp /= 8;
h_screen_off = hactive * 2;
h_adjust = 1;
break;
case 24:
hactive /= 8;
hblank /= 8;
hfp /= 8;
hbp /= 8;
h_screen_off = hactive * 3;
h_adjust = 1;
break;
case 32:
hactive /= 8;
hblank /= 8;
hfp /= 8;
hbp /= 8;
h_screen_off = hactive * 4;
h_adjust = 1;
break;
}
/*
* Compute horizontal register values from timings
*/
h_total = hactive + hblank - 5;
h_display_end = hactive - 1;
h_blank_start = h_display_end;
h_blank_end = h_blank_start + hblank;
h_sync_start = hactive + hfp + h_adjust;
h_sync_end = h_sync_start + hblank - hbp - hfp;
/* Set CRTC regs for horizontal timings */
regp->CRTC[0x0] = h_total;
ireg->ExtHorizTotal=(h_total & 0x100) >> 8;
regp->CRTC[0x1] = h_display_end;
regp->CRTC[0x2] = h_blank_start;
regp->CRTC[0x3] = 0x80 | (h_blank_end & 0x1f);
regp->CRTC[0x5] = (h_blank_end & 0x20) << 2;
regp->CRTC[0x4] = h_sync_start;
regp->CRTC[0x5] |= h_sync_end & 0x1f;
regp->CRTC[0x13] = h_screen_off;
ireg->ExtOffset = h_screen_off >> 8;
/* Compute vertical timings */
v_total = vactive + vblank - 2;
v_retrace_start = vactive + vfp - 1;
v_retrace_end = v_retrace_start + vblank - vbp - vfp;
v_display_end = vactive - 1;
v_blank_start = vactive - 1;
v_blank_end = v_blank_start + vblank /* - 1 */;
regp->CRTC[0x6] = v_total;
ireg->ExtVertTotal = v_total >> 8;
regp->CRTC[0x10] = v_retrace_start;
ireg->ExtVertSyncStart = v_retrace_start >> 8;
regp->CRTC[0x11] = v_retrace_end;
regp->CRTC[0x12] = v_display_end;
ireg->ExtVertDispEnd = v_display_end >> 8;
regp->CRTC[0x15] = v_blank_start;
ireg->ExtVertBlankStart = v_blank_start >> 8;
regp->CRTC[0x16] = v_blank_end;
if (depth < 8)
regp->CRTC[23] = 0xE3;
else
regp->CRTC[23] = 0xC3;
regp->CRTC[24] = 0xFF;
/*
* Graphics Display Controller
*/
regp->Graphics[0] = 0x00;
regp->Graphics[1] = 0x00;
regp->Graphics[2] = 0x00;
regp->Graphics[3] = 0x00;
if (depth == 1) {
regp->Graphics[4] = BIT_PLANE;
regp->Graphics[5] = 0x00;
} else {
regp->Graphics[4] = 0x00;
if (depth == 4)
regp->Graphics[5] = 0x02;
else
regp->Graphics[5] = 0x40;
}
regp->Graphics[6] = 0x05;
regp->Graphics[7] = 0x0F;
regp->Graphics[8] = 0xFF;
if (depth == 1) {
/* Initialise the Mono map according to which bit-plane gets used */
Bool flipPixels = FALSE; /* maybe support this in the future? */
for (i=0; i<16; i++)
if (((i & (1 << BIT_PLANE)) != 0) != flipPixels)
regp->Attribute[i] = WHITE_VALUE;
else
regp->Attribute[i] = BLACK_VALUE;
regp->Attribute[16] = 0x01; /* -VGA2- */
if (!vgap->ShowOverscan)
regp->Attribute[OVERSCAN] = OVERSCAN_VALUE; /* -VGA2- */
} else {
regp->Attribute[0] = 0x00; /* standard colormap translation */
regp->Attribute[1] = 0x01;
regp->Attribute[2] = 0x02;
regp->Attribute[3] = 0x03;
regp->Attribute[4] = 0x04;
regp->Attribute[5] = 0x05;
regp->Attribute[6] = 0x06;
regp->Attribute[7] = 0x07;
regp->Attribute[8] = 0x08;
regp->Attribute[9] = 0x09;
regp->Attribute[10] = 0x0A;
regp->Attribute[11] = 0x0B;
regp->Attribute[12] = 0x0C;
regp->Attribute[13] = 0x0D;
regp->Attribute[14] = 0x0E;
regp->Attribute[15] = 0x0F;
if (depth == 4)
regp->Attribute[16] = 0x81;
else
regp->Attribute[16] = 0x41;
/* Attribute[17] (overscan) was initialised earlier */
}
regp->Attribute[18] = 0x0F;
regp->Attribute[19] = 0x00;
regp->Attribute[20] = 0x00;
return(TRUE);
}
void
i810VGALock(i810VGAPtr vgap)
{
/* Protect CRTC[0-7] */
mmioWriteCrtc(vgap, 0x11, mmioReadCrtc(vgap, 0x11) & ~0x80);
}
void
i810VGAUnlock(i810VGAPtr vgap)
{
/* Unprotect CRTC[0-7] */
mmioWriteCrtc(vgap, 0x11, mmioReadCrtc(vgap, 0x11) | 0x80);
}
static void
i810Restore(KdCardInfo *card) {
I810CardInfo *i810c = card->driver;
i810VGAPtr vgap = &i810c->vga;
if (I810_DEBUG)
fprintf(stderr,"i810Restore\n");
DoRestore(card, &vgap->SavedReg, &i810c->SavedReg, TRUE);
}
static Bool
i810Enable (ScreenPtr pScreen)
{
KdScreenPriv(pScreen);
KdScreenInfo *screen = pScreenPriv->screen;
KdCardInfo *card = pScreenPriv->card;
I810CardInfo *i810c = card->driver;
i810VGAPtr vgap = &i810c->vga;
const KdMonitorTiming *t;
if (I810_DEBUG)
fprintf(stderr,"i810Enable\n");
vgap->IOBase = (mmioReadMiscOut(vgap) & 0x01) ?
VGA_IOBASE_COLOR : VGA_IOBASE_MONO;
{
I810RegPtr i810Reg = &i810c->ModeReg;
int i;
for (i = 0 ; i < 8 ; i++)
i810Reg->Fence[i] = 0;
}
t = KdFindMode (screen, i810ModeSupported);
if (!i810BindGARTMemory(screen))
return FALSE;
if (!i810ModeInit(screen, t)) return FALSE;
{
/* DPMS power on state */
unsigned char SEQ01=0;
int DPMSSyncSelect=0;
SEQ01 = 0x00;
DPMSSyncSelect = HSYNC_ON | VSYNC_ON;
SEQ01 |= i810ReadControlMMIO(i810c, SRX, 0x01) & ~0x20;
i810WriteControlMMIO(i810c, SRX, 0x01, SEQ01);
/* Set the DPMS mode */
OUTREG8(DPMS_SYNC_SELECT, DPMSSyncSelect);
}
#ifdef XV
KdXVEnable (pScreen);
#endif
return TRUE;
}
static void
i810Disable(ScreenPtr pScreen) {
KdScreenPriv(pScreen);
KdScreenInfo *screen = pScreenPriv->screen;
KdCardInfo *card = pScreenPriv->card;
I810CardInfo *i810c = card->driver;
i810VGAPtr vgap = &i810c->vga;
if (I810_DEBUG)
fprintf(stderr,"i810Disable\n");
#ifdef XV
KdXVDisable (pScreen);
#endif
i810Restore(screen->card);
if (!i810UnbindGARTMemory(screen))
return;
i810VGALock(vgap);
}
static Bool
i810DPMS(ScreenPtr pScreen, int mode)
{
KdScreenPriv(pScreen);
KdCardInfo *card = pScreenPriv->card;
I810CardInfo *i810c = card->driver;
unsigned char SEQ01=0;
int DPMSSyncSelect=0;
if (I810_DEBUG)
fprintf(stderr,"i810DPMS: %d\n",mode);
switch (mode) {
case KD_DPMS_NORMAL:
/* Screen: On; HSync: On, VSync: On */
SEQ01 = 0x00;
DPMSSyncSelect = HSYNC_ON | VSYNC_ON;
break;
case KD_DPMS_STANDBY:
/* Screen: Off; HSync: Off, VSync: On */
SEQ01 = 0x20;
DPMSSyncSelect = HSYNC_OFF | VSYNC_ON;
break;
case KD_DPMS_SUSPEND:
/* Screen: Off; HSync: On, VSync: Off */
SEQ01 = 0x20;
DPMSSyncSelect = HSYNC_ON | VSYNC_OFF;
break;
case KD_DPMS_POWERDOWN:
/* Screen: Off; HSync: Off, VSync: Off */
SEQ01 = 0x20;
DPMSSyncSelect = HSYNC_OFF | VSYNC_OFF;
break;
}
/* Turn the screen on/off */
SEQ01 |= i810ReadControlMMIO(i810c, SRX, 0x01) & ~0x20;
i810WriteControlMMIO(i810c, SRX, 0x01, SEQ01);
/* Set the DPMS mode */
OUTREG8(DPMS_SYNC_SELECT, DPMSSyncSelect);
return TRUE;
}
static void
i810GetColors (ScreenPtr pScreen, int fb, int ndefs, xColorItem *c)
{
if (I810_DEBUG)
fprintf(stderr,"i810GetColors (NOT IMPLEMENTED)\n");
}
#define DACDelay(hw) \
do { \
unsigned char temp = Vminb((hw)->IOBase + VGA_IN_STAT_1_OFFSET); \
temp = Vminb((hw)->IOBase + VGA_IN_STAT_1_OFFSET); \
} while (0)
static void
i810PutColors (ScreenPtr pScreen, int fb, int ndef, xColorItem *pdefs)
{
KdScreenPriv(pScreen);
KdScreenInfo *screen = pScreenPriv->screen;
KdCardInfo *card = screen->card;
I810CardInfo *i810c = (I810CardInfo *) card->driver;
i810VGAPtr vgap = &i810c->vga;
if (I810_DEBUG)
fprintf(stderr,"i810PutColors\n");
while (ndef--)
{
mmioWriteDacWriteAddr(vgap, pdefs->pixel);
DACDelay(vgap);
mmioWriteDacData(vgap, pdefs->red);
DACDelay(vgap);
mmioWriteDacData(vgap, pdefs->green);
DACDelay(vgap);
mmioWriteDacData(vgap, pdefs->blue);
DACDelay(vgap);
pdefs++;
}
}
KdCardFuncs i810Funcs = {
i810CardInit, /* cardinit */
i810ScreenInit, /* scrinit */
i810InitScreen, /* initScreen */
i810FinishInitScreen, /* finishInitScreen */
NULL, /* createResources */
i810Preserve, /* preserve */
i810Enable, /* enable */
i810DPMS, /* dpms */
i810Disable, /* disable */
i810Restore, /* restore */
i810ScreenFini, /* scrfini */
i810CardFini, /* cardfini */
i810CursorInit, /* initCursor */
i810CursorEnable, /* enableCursor */
i810CursorDisable, /* disableCursor */
i810CursorFini, /* finiCursor */
NULL, /* recolorCursor */
i810InitAccel, /* initAccel */
i810EnableAccel, /* enableAccel */
i810DisableAccel, /* disableAccel */
i810FiniAccel, /* finiAccel */
i810GetColors, /* getColors */
i810PutColors, /* putColors */
};
|