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
|
/*
*
* Copyright 1991-1999 by The XFree86 Project, Inc.
*
* Loosely based on code bearing the following copyright:
*
* Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
*
*/
#define _NEED_SYSI86
#ifdef HAVE_XORG_CONFIG_H
#include <xorg-config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <X11/X.h>
#include "misc.h"
#include "xf86.h"
#include "xf86_OSproc.h"
#include "vgaHW.h"
#include "compiler.h"
#include "xf86cmap.h"
#ifndef SAVE_FONT1
#define SAVE_FONT1 1
#endif
/*
* These used to be OS-specific, which made this module have an undesirable
* OS dependency. Define them by default for all platforms.
*/
#ifndef NEED_SAVED_CMAP
#define NEED_SAVED_CMAP
#endif
#ifndef SAVE_TEXT
#define SAVE_TEXT 1
#endif
#ifndef SAVE_FONT2
#define SAVE_FONT2 1
#endif
/* bytes per plane to save for text */
#define TEXT_AMOUNT 16384
/* bytes per plane to save for font data */
#define FONT_AMOUNT (8*8192)
#if 0
/* Override all of these for now */
#undef SAVE_FONT1
#define SAVE_FONT1 1
#undef SAVE_FONT2
#define SAVE_FONT2 1
#undef SAVE_TEST
#define SAVE_TEST 1
#undef FONT_AMOUNT
#define FONT_AMOUNT 65536
#undef TEXT_AMOUNT
#define TEXT_AMOUNT 65536
#endif
/* DAC indices for white and black */
#define WHITE_VALUE 0x3F
#define BLACK_VALUE 0x00
#define OVERSCAN_VALUE 0x01
/* Use a private definition of this here */
#undef VGAHWPTR
#define VGAHWPTRLVAL(p) (p)->privates[vgaHWPrivateIndex].ptr
#define VGAHWPTR(p) ((vgaHWPtr)(VGAHWPTRLVAL(p)))
static int vgaHWPrivateIndex = -1;
#define DAC_TEST_MASK 0x3F
#ifdef NEED_SAVED_CMAP
/* This default colourmap is used only when it can't be read from the VGA */
static CARD8 defaultDAC[768] =
{
0, 0, 0, 0, 0, 42, 0, 42, 0, 0, 42, 42,
42, 0, 0, 42, 0, 42, 42, 21, 0, 42, 42, 42,
21, 21, 21, 21, 21, 63, 21, 63, 21, 21, 63, 63,
63, 21, 21, 63, 21, 63, 63, 63, 21, 63, 63, 63,
0, 0, 0, 5, 5, 5, 8, 8, 8, 11, 11, 11,
14, 14, 14, 17, 17, 17, 20, 20, 20, 24, 24, 24,
28, 28, 28, 32, 32, 32, 36, 36, 36, 40, 40, 40,
45, 45, 45, 50, 50, 50, 56, 56, 56, 63, 63, 63,
0, 0, 63, 16, 0, 63, 31, 0, 63, 47, 0, 63,
63, 0, 63, 63, 0, 47, 63, 0, 31, 63, 0, 16,
63, 0, 0, 63, 16, 0, 63, 31, 0, 63, 47, 0,
63, 63, 0, 47, 63, 0, 31, 63, 0, 16, 63, 0,
0, 63, 0, 0, 63, 16, 0, 63, 31, 0, 63, 47,
0, 63, 63, 0, 47, 63, 0, 31, 63, 0, 16, 63,
31, 31, 63, 39, 31, 63, 47, 31, 63, 55, 31, 63,
63, 31, 63, 63, 31, 55, 63, 31, 47, 63, 31, 39,
63, 31, 31, 63, 39, 31, 63, 47, 31, 63, 55, 31,
63, 63, 31, 55, 63, 31, 47, 63, 31, 39, 63, 31,
31, 63, 31, 31, 63, 39, 31, 63, 47, 31, 63, 55,
31, 63, 63, 31, 55, 63, 31, 47, 63, 31, 39, 63,
45, 45, 63, 49, 45, 63, 54, 45, 63, 58, 45, 63,
63, 45, 63, 63, 45, 58, 63, 45, 54, 63, 45, 49,
63, 45, 45, 63, 49, 45, 63, 54, 45, 63, 58, 45,
63, 63, 45, 58, 63, 45, 54, 63, 45, 49, 63, 45,
45, 63, 45, 45, 63, 49, 45, 63, 54, 45, 63, 58,
45, 63, 63, 45, 58, 63, 45, 54, 63, 45, 49, 63,
0, 0, 28, 7, 0, 28, 14, 0, 28, 21, 0, 28,
28, 0, 28, 28, 0, 21, 28, 0, 14, 28, 0, 7,
28, 0, 0, 28, 7, 0, 28, 14, 0, 28, 21, 0,
28, 28, 0, 21, 28, 0, 14, 28, 0, 7, 28, 0,
0, 28, 0, 0, 28, 7, 0, 28, 14, 0, 28, 21,
0, 28, 28, 0, 21, 28, 0, 14, 28, 0, 7, 28,
14, 14, 28, 17, 14, 28, 21, 14, 28, 24, 14, 28,
28, 14, 28, 28, 14, 24, 28, 14, 21, 28, 14, 17,
28, 14, 14, 28, 17, 14, 28, 21, 14, 28, 24, 14,
28, 28, 14, 24, 28, 14, 21, 28, 14, 17, 28, 14,
14, 28, 14, 14, 28, 17, 14, 28, 21, 14, 28, 24,
14, 28, 28, 14, 24, 28, 14, 21, 28, 14, 17, 28,
20, 20, 28, 22, 20, 28, 24, 20, 28, 26, 20, 28,
28, 20, 28, 28, 20, 26, 28, 20, 24, 28, 20, 22,
28, 20, 20, 28, 22, 20, 28, 24, 20, 28, 26, 20,
28, 28, 20, 26, 28, 20, 24, 28, 20, 22, 28, 20,
20, 28, 20, 20, 28, 22, 20, 28, 24, 20, 28, 26,
20, 28, 28, 20, 26, 28, 20, 24, 28, 20, 22, 28,
0, 0, 16, 4, 0, 16, 8, 0, 16, 12, 0, 16,
16, 0, 16, 16, 0, 12, 16, 0, 8, 16, 0, 4,
16, 0, 0, 16, 4, 0, 16, 8, 0, 16, 12, 0,
16, 16, 0, 12, 16, 0, 8, 16, 0, 4, 16, 0,
0, 16, 0, 0, 16, 4, 0, 16, 8, 0, 16, 12,
0, 16, 16, 0, 12, 16, 0, 8, 16, 0, 4, 16,
8, 8, 16, 10, 8, 16, 12, 8, 16, 14, 8, 16,
16, 8, 16, 16, 8, 14, 16, 8, 12, 16, 8, 10,
16, 8, 8, 16, 10, 8, 16, 12, 8, 16, 14, 8,
16, 16, 8, 14, 16, 8, 12, 16, 8, 10, 16, 8,
8, 16, 8, 8, 16, 10, 8, 16, 12, 8, 16, 14,
8, 16, 16, 8, 14, 16, 8, 12, 16, 8, 10, 16,
11, 11, 16, 12, 11, 16, 13, 11, 16, 15, 11, 16,
16, 11, 16, 16, 11, 15, 16, 11, 13, 16, 11, 12,
16, 11, 11, 16, 12, 11, 16, 13, 11, 16, 15, 11,
16, 16, 11, 15, 16, 11, 13, 16, 11, 12, 16, 11,
11, 16, 11, 11, 16, 12, 11, 16, 13, 11, 16, 15,
11, 16, 16, 11, 15, 16, 11, 13, 16, 11, 12, 16,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
#endif /* NEED_SAVED_CMAP */
/*
* Standard VGA versions of the register access functions.
*/
static void
stdWriteCrtc(vgaHWPtr hwp, CARD8 index, CARD8 value)
{
outb(hwp->IOBase + hwp->PIOOffset + VGA_CRTC_INDEX_OFFSET, index);
outb(hwp->IOBase + hwp->PIOOffset + VGA_CRTC_DATA_OFFSET, value);
}
static CARD8
stdReadCrtc(vgaHWPtr hwp, CARD8 index)
{
outb(hwp->IOBase + hwp->PIOOffset + VGA_CRTC_INDEX_OFFSET, index);
return inb(hwp->IOBase + hwp->PIOOffset + VGA_CRTC_DATA_OFFSET);
}
static void
stdWriteGr(vgaHWPtr hwp, CARD8 index, CARD8 value)
{
outb(hwp->PIOOffset + VGA_GRAPH_INDEX, index);
outb(hwp->PIOOffset + VGA_GRAPH_DATA, value);
}
static CARD8
stdReadGr(vgaHWPtr hwp, CARD8 index)
{
outb(hwp->PIOOffset + VGA_GRAPH_INDEX, index);
return inb(hwp->PIOOffset + VGA_GRAPH_DATA);
}
static void
stdWriteSeq(vgaHWPtr hwp, CARD8 index, CARD8 value)
{
outb(hwp->PIOOffset + VGA_SEQ_INDEX, index);
outb(hwp->PIOOffset + VGA_SEQ_DATA, value);
}
static CARD8
stdReadSeq(vgaHWPtr hwp, CARD8 index)
{
outb(hwp->PIOOffset + VGA_SEQ_INDEX, index);
return inb(hwp->PIOOffset + VGA_SEQ_DATA);
}
static CARD8
stdReadST00(vgaHWPtr hwp)
{
return inb(hwp->PIOOffset + VGA_IN_STAT_0);
}
static CARD8
stdReadST01(vgaHWPtr hwp)
{
return inb(hwp->IOBase + hwp->PIOOffset + VGA_IN_STAT_1_OFFSET);
}
static CARD8
stdReadFCR(vgaHWPtr hwp)
{
return inb(hwp->PIOOffset + VGA_FEATURE_R);
}
static void
stdWriteFCR(vgaHWPtr hwp, CARD8 value)
{
outb(hwp->IOBase + hwp->PIOOffset + VGA_FEATURE_W_OFFSET,value);
}
static void
stdWriteAttr(vgaHWPtr hwp, CARD8 index, CARD8 value)
{
if (hwp->paletteEnabled)
index &= ~0x20;
else
index |= 0x20;
(void) inb(hwp->IOBase + hwp->PIOOffset + VGA_IN_STAT_1_OFFSET);
outb(hwp->PIOOffset + VGA_ATTR_INDEX, index);
outb(hwp->PIOOffset + VGA_ATTR_DATA_W, value);
}
static CARD8
stdReadAttr(vgaHWPtr hwp, CARD8 index)
{
if (hwp->paletteEnabled)
index &= ~0x20;
else
index |= 0x20;
(void) inb(hwp->IOBase + hwp->PIOOffset + VGA_IN_STAT_1_OFFSET);
outb(hwp->PIOOffset + VGA_ATTR_INDEX, index);
return inb(hwp->PIOOffset + VGA_ATTR_DATA_R);
}
static void
stdWriteMiscOut(vgaHWPtr hwp, CARD8 value)
{
outb(hwp->PIOOffset + VGA_MISC_OUT_W, value);
}
static CARD8
stdReadMiscOut(vgaHWPtr hwp)
{
return inb(hwp->PIOOffset + VGA_MISC_OUT_R);
}
static void
stdEnablePalette(vgaHWPtr hwp)
{
(void) inb(hwp->IOBase + hwp->PIOOffset + VGA_IN_STAT_1_OFFSET);
outb(hwp->PIOOffset + VGA_ATTR_INDEX, 0x00);
hwp->paletteEnabled = TRUE;
}
static void
stdDisablePalette(vgaHWPtr hwp)
{
(void) inb(hwp->IOBase + hwp->PIOOffset + VGA_IN_STAT_1_OFFSET);
outb(hwp->PIOOffset + VGA_ATTR_INDEX, 0x20);
hwp->paletteEnabled = FALSE;
}
static void
stdWriteDacMask(vgaHWPtr hwp, CARD8 value)
{
outb(hwp->PIOOffset + VGA_DAC_MASK, value);
}
static CARD8
stdReadDacMask(vgaHWPtr hwp)
{
return inb(hwp->PIOOffset + VGA_DAC_MASK);
}
static void
stdWriteDacReadAddr(vgaHWPtr hwp, CARD8 value)
{
outb(hwp->PIOOffset + VGA_DAC_READ_ADDR, value);
}
static void
stdWriteDacWriteAddr(vgaHWPtr hwp, CARD8 value)
{
outb(hwp->PIOOffset + VGA_DAC_WRITE_ADDR, value);
}
static void
stdWriteDacData(vgaHWPtr hwp, CARD8 value)
{
outb(hwp->PIOOffset + VGA_DAC_DATA, value);
}
static CARD8
stdReadDacData(vgaHWPtr hwp)
{
return inb(hwp->PIOOffset + VGA_DAC_DATA);
}
static CARD8
stdReadEnable(vgaHWPtr hwp)
{
return inb(hwp->PIOOffset + VGA_ENABLE);
}
static void
stdWriteEnable(vgaHWPtr hwp, CARD8 value)
{
outb(hwp->PIOOffset + VGA_ENABLE, value);
}
void
vgaHWSetStdFuncs(vgaHWPtr hwp)
{
hwp->writeCrtc = stdWriteCrtc;
hwp->readCrtc = stdReadCrtc;
hwp->writeGr = stdWriteGr;
hwp->readGr = stdReadGr;
hwp->readST00 = stdReadST00;
hwp->readST01 = stdReadST01;
hwp->readFCR = stdReadFCR;
hwp->writeFCR = stdWriteFCR;
hwp->writeAttr = stdWriteAttr;
hwp->readAttr = stdReadAttr;
hwp->writeSeq = stdWriteSeq;
hwp->readSeq = stdReadSeq;
hwp->writeMiscOut = stdWriteMiscOut;
hwp->readMiscOut = stdReadMiscOut;
hwp->enablePalette = stdEnablePalette;
hwp->disablePalette = stdDisablePalette;
hwp->writeDacMask = stdWriteDacMask;
hwp->readDacMask = stdReadDacMask;
hwp->writeDacWriteAddr = stdWriteDacWriteAddr;
hwp->writeDacReadAddr = stdWriteDacReadAddr;
hwp->writeDacData = stdWriteDacData;
hwp->readDacData = stdReadDacData;
hwp->PIOOffset = 0;
hwp->readEnable = stdReadEnable;
hwp->writeEnable = stdWriteEnable;
}
/*
* MMIO versions of the register access functions. These require
* hwp->MemBase to be set in such a way that when the standard VGA port
* adderss is added the correct memory address results.
*/
#define minb(p) MMIO_IN8(hwp->MMIOBase, (hwp->MMIOOffset + (p)))
#define moutb(p,v) MMIO_OUT8(hwp->MMIOBase, (hwp->MMIOOffset + (p)),(v))
static void
mmioWriteCrtc(vgaHWPtr hwp, CARD8 index, CARD8 value)
{
moutb(hwp->IOBase + VGA_CRTC_INDEX_OFFSET, index);
moutb(hwp->IOBase + VGA_CRTC_DATA_OFFSET, value);
}
static CARD8
mmioReadCrtc(vgaHWPtr hwp, CARD8 index)
{
moutb(hwp->IOBase + VGA_CRTC_INDEX_OFFSET, index);
return minb(hwp->IOBase + VGA_CRTC_DATA_OFFSET);
}
static void
mmioWriteGr(vgaHWPtr hwp, CARD8 index, CARD8 value)
{
moutb(VGA_GRAPH_INDEX, index);
moutb(VGA_GRAPH_DATA, value);
}
static CARD8
mmioReadGr(vgaHWPtr hwp, CARD8 index)
{
moutb(VGA_GRAPH_INDEX, index);
return minb(VGA_GRAPH_DATA);
}
static void
mmioWriteSeq(vgaHWPtr hwp, CARD8 index, CARD8 value)
{
moutb(VGA_SEQ_INDEX, index);
moutb(VGA_SEQ_DATA, value);
}
static CARD8
mmioReadSeq(vgaHWPtr hwp, CARD8 index)
{
moutb(VGA_SEQ_INDEX, index);
return minb(VGA_SEQ_DATA);
}
static CARD8
mmioReadST00(vgaHWPtr hwp)
{
return minb(VGA_IN_STAT_0);
}
static CARD8
mmioReadST01(vgaHWPtr hwp)
{
return minb(hwp->IOBase + VGA_IN_STAT_1_OFFSET);
}
static CARD8
mmioReadFCR(vgaHWPtr hwp)
{
return minb(VGA_FEATURE_R);
}
static void
mmioWriteFCR(vgaHWPtr hwp, CARD8 value)
{
moutb(hwp->IOBase + VGA_FEATURE_W_OFFSET,value);
}
static void
mmioWriteAttr(vgaHWPtr hwp, CARD8 index, CARD8 value)
{
if (hwp->paletteEnabled)
index &= ~0x20;
else
index |= 0x20;
(void) minb(hwp->IOBase + VGA_IN_STAT_1_OFFSET);
moutb(VGA_ATTR_INDEX, index);
moutb(VGA_ATTR_DATA_W, value);
}
static CARD8
mmioReadAttr(vgaHWPtr hwp, CARD8 index)
{
if (hwp->paletteEnabled)
index &= ~0x20;
else
index |= 0x20;
(void) minb(hwp->IOBase + VGA_IN_STAT_1_OFFSET);
moutb(VGA_ATTR_INDEX, index);
return minb(VGA_ATTR_DATA_R);
}
static void
mmioWriteMiscOut(vgaHWPtr hwp, CARD8 value)
{
moutb(VGA_MISC_OUT_W, value);
}
static CARD8
mmioReadMiscOut(vgaHWPtr hwp)
{
return minb(VGA_MISC_OUT_R);
}
static void
mmioEnablePalette(vgaHWPtr hwp)
{
(void) minb(hwp->IOBase + VGA_IN_STAT_1_OFFSET);
moutb(VGA_ATTR_INDEX, 0x00);
hwp->paletteEnabled = TRUE;
}
static void
mmioDisablePalette(vgaHWPtr hwp)
{
(void) minb(hwp->IOBase + VGA_IN_STAT_1_OFFSET);
moutb(VGA_ATTR_INDEX, 0x20);
hwp->paletteEnabled = FALSE;
}
static void
mmioWriteDacMask(vgaHWPtr hwp, CARD8 value)
{
moutb(VGA_DAC_MASK, value);
}
static CARD8
mmioReadDacMask(vgaHWPtr hwp)
{
return minb(VGA_DAC_MASK);
}
static void
mmioWriteDacReadAddr(vgaHWPtr hwp, CARD8 value)
{
moutb(VGA_DAC_READ_ADDR, value);
}
static void
mmioWriteDacWriteAddr(vgaHWPtr hwp, CARD8 value)
{
moutb(VGA_DAC_WRITE_ADDR, value);
}
static void
mmioWriteDacData(vgaHWPtr hwp, CARD8 value)
{
moutb(VGA_DAC_DATA, value);
}
static CARD8
mmioReadDacData(vgaHWPtr hwp)
{
return minb(VGA_DAC_DATA);
}
static CARD8
mmioReadEnable(vgaHWPtr hwp)
{
return minb(VGA_ENABLE);
}
static void
mmioWriteEnable(vgaHWPtr hwp, CARD8 value)
{
moutb(VGA_ENABLE, value);
}
void
vgaHWSetMmioFuncs(vgaHWPtr hwp, CARD8 *base, int offset)
{
hwp->writeCrtc = mmioWriteCrtc;
hwp->readCrtc = mmioReadCrtc;
hwp->writeGr = mmioWriteGr;
hwp->readGr = mmioReadGr;
hwp->readST00 = mmioReadST00;
hwp->readST01 = mmioReadST01;
hwp->readFCR = mmioReadFCR;
hwp->writeFCR = mmioWriteFCR;
hwp->writeAttr = mmioWriteAttr;
hwp->readAttr = mmioReadAttr;
hwp->writeSeq = mmioWriteSeq;
hwp->readSeq = mmioReadSeq;
hwp->writeMiscOut = mmioWriteMiscOut;
hwp->readMiscOut = mmioReadMiscOut;
hwp->enablePalette = mmioEnablePalette;
hwp->disablePalette = mmioDisablePalette;
hwp->writeDacMask = mmioWriteDacMask;
hwp->readDacMask = mmioReadDacMask;
hwp->writeDacWriteAddr = mmioWriteDacWriteAddr;
hwp->writeDacReadAddr = mmioWriteDacReadAddr;
hwp->writeDacData = mmioWriteDacData;
hwp->readDacData = mmioReadDacData;
hwp->MMIOBase = base;
hwp->MMIOOffset = offset;
hwp->readEnable = mmioReadEnable;
hwp->writeEnable = mmioWriteEnable;
}
/*
* vgaHWProtect --
* Protect VGA registers and memory from corruption during loads.
*/
void
vgaHWProtect(ScrnInfoPtr pScrn, Bool on)
{
vgaHWPtr hwp = VGAHWPTR(pScrn);
unsigned char tmp;
if (pScrn->vtSema) {
if (on) {
/*
* Turn off screen and disable sequencer.
*/
tmp = hwp->readSeq(hwp, 0x01);
vgaHWSeqReset(hwp, TRUE); /* start synchronous reset */
hwp->writeSeq(hwp, 0x01, tmp | 0x20); /* disable the display */
hwp->enablePalette(hwp);
} else {
/*
* Reenable sequencer, then turn on screen.
*/
tmp = hwp->readSeq(hwp, 0x01);
hwp->writeSeq(hwp, 0x01, tmp & ~0x20); /* reenable display */
vgaHWSeqReset(hwp, FALSE); /* clear synchronousreset */
hwp->disablePalette(hwp);
}
}
}
vgaHWProtectProc *vgaHWProtectWeak(void) {
return vgaHWProtect;
}
/*
* vgaHWBlankScreen -- blank the screen.
*/
void
vgaHWBlankScreen(ScrnInfoPtr pScrn, Bool on)
{
vgaHWPtr hwp = VGAHWPTR(pScrn);
unsigned char scrn;
scrn = hwp->readSeq(hwp, 0x01);
if (on) {
scrn &= ~0x20; /* enable screen */
} else {
scrn |= 0x20; /* blank screen */
}
vgaHWSeqReset(hwp, TRUE);
hwp->writeSeq(hwp, 0x01, scrn); /* change mode */
vgaHWSeqReset(hwp, FALSE);
}
vgaHWBlankScreenProc *vgaHWBlankScreenWeak(void) {
return vgaHWBlankScreen;
}
/*
* vgaHWSaveScreen -- blank the screen.
*/
Bool
vgaHWSaveScreen(ScreenPtr pScreen, int mode)
{
ScrnInfoPtr pScrn = NULL;
Bool on;
if (pScreen != NULL)
pScrn = xf86Screens[pScreen->myNum];
on = xf86IsUnblank(mode);
#if 0
if (on)
SetTimeSinceLastInputEvent();
#endif
if ((pScrn != NULL) && pScrn->vtSema) {
vgaHWBlankScreen(pScrn, on);
}
return (TRUE);
}
/*
* vgaHWDPMSSet -- Sets VESA Display Power Management Signaling (DPMS) Mode
*
* This generic VGA function can only set the Off and On modes. If the
* Standby and Suspend modes are to be supported, a chip specific replacement
* for this function must be written.
*/
void
vgaHWDPMSSet(ScrnInfoPtr pScrn, int PowerManagementMode, int flags)
{
unsigned char seq1 = 0, crtc17 = 0;
vgaHWPtr hwp = VGAHWPTR(pScrn);
if (!pScrn->vtSema) return;
switch (PowerManagementMode) {
case DPMSModeOn:
/* Screen: On; HSync: On, VSync: On */
seq1 = 0x00;
crtc17 = 0x80;
break;
case DPMSModeStandby:
/* Screen: Off; HSync: Off, VSync: On -- Not Supported */
seq1 = 0x20;
crtc17 = 0x80;
break;
case DPMSModeSuspend:
/* Screen: Off; HSync: On, VSync: Off -- Not Supported */
seq1 = 0x20;
crtc17 = 0x80;
break;
case DPMSModeOff:
/* Screen: Off; HSync: Off, VSync: Off */
seq1 = 0x20;
crtc17 = 0x00;
break;
}
hwp->writeSeq(hwp, 0x00, 0x01); /* Synchronous Reset */
seq1 |= hwp->readSeq(hwp, 0x01) & ~0x20;
hwp->writeSeq(hwp, 0x01, seq1);
crtc17 |= hwp->readCrtc(hwp, 0x17) & ~0x80;
usleep(10000);
hwp->writeCrtc(hwp, 0x17, crtc17);
hwp->writeSeq(hwp, 0x00, 0x03); /* End Reset */
}
/*
* vgaHWSeqReset
* perform a sequencer reset.
*/
void
vgaHWSeqReset(vgaHWPtr hwp, Bool start)
{
if (start)
hwp->writeSeq(hwp, 0x00, 0x01); /* Synchronous Reset */
else
hwp->writeSeq(hwp, 0x00, 0x03); /* End Reset */
}
void
vgaHWRestoreFonts(ScrnInfoPtr scrninfp, vgaRegPtr restore)
{
#if SAVE_TEXT || SAVE_FONT1 || SAVE_FONT2
vgaHWPtr hwp = VGAHWPTR(scrninfp);
int savedIOBase;
unsigned char miscOut, attr10, gr1, gr3, gr4, gr5, gr6, gr8, seq2, seq4;
Bool doMap = FALSE;
/* If nothing to do, return now */
if (!hwp->FontInfo1 && !hwp->FontInfo2 && !hwp->TextInfo)
return;
if (hwp->Base == NULL) {
doMap = TRUE;
if (!vgaHWMapMem(scrninfp)) {
xf86DrvMsg(scrninfp->scrnIndex, X_ERROR,
"vgaHWRestoreFonts: vgaHWMapMem() failed\n");
return;
}
}
/* save the registers that are needed here */
miscOut = hwp->readMiscOut(hwp);
attr10 = hwp->readAttr(hwp, 0x10);
gr1 = hwp->readGr(hwp, 0x01);
gr3 = hwp->readGr(hwp, 0x03);
gr4 = hwp->readGr(hwp, 0x04);
gr5 = hwp->readGr(hwp, 0x05);
gr6 = hwp->readGr(hwp, 0x06);
gr8 = hwp->readGr(hwp, 0x08);
seq2 = hwp->readSeq(hwp, 0x02);
seq4 = hwp->readSeq(hwp, 0x04);
/* save hwp->IOBase and temporarily set it for colour mode */
savedIOBase = hwp->IOBase;
hwp->IOBase = VGA_IOBASE_COLOR;
/* Force into colour mode */
hwp->writeMiscOut(hwp, miscOut | 0x01);
vgaHWBlankScreen(scrninfp, FALSE);
/*
* here we temporarily switch to 16 colour planar mode, to simply
* copy the font-info and saved text.
*
* BUG ALERT: The (S)VGA's segment-select register MUST be set correctly!
*/
#if 0
hwp->writeAttr(hwp, 0x10, 0x01); /* graphics mode */
#endif
hwp->writeSeq(hwp, 0x04, 0x06); /* enable plane graphics */
hwp->writeGr(hwp, 0x05, 0x00); /* write mode 0, read mode 0 */
hwp->writeGr(hwp, 0x06, 0x05); /* set graphics */
if (scrninfp->depth == 4) {
/* GJA */
hwp->writeGr(hwp, 0x03, 0x00); /* don't rotate, write unmodified */
hwp->writeGr(hwp, 0x08, 0xFF); /* write all bits in a byte */
hwp->writeGr(hwp, 0x01, 0x00); /* all planes come from CPU */
}
#if SAVE_FONT1
if (hwp->FontInfo1) {
hwp->writeSeq(hwp, 0x02, 0x04); /* write to plane 2 */
hwp->writeGr(hwp, 0x04, 0x02); /* read plane 2 */
slowbcopy_tobus(hwp->FontInfo1, hwp->Base, FONT_AMOUNT);
}
#endif
#if SAVE_FONT2
if (hwp->FontInfo2) {
hwp->writeSeq(hwp, 0x02, 0x08); /* write to plane 3 */
hwp->writeGr(hwp, 0x04, 0x03); /* read plane 3 */
slowbcopy_tobus(hwp->FontInfo2, hwp->Base, FONT_AMOUNT);
}
#endif
#if SAVE_TEXT
if (hwp->TextInfo) {
hwp->writeSeq(hwp, 0x02, 0x01); /* write to plane 0 */
hwp->writeGr(hwp, 0x04, 0x00); /* read plane 0 */
slowbcopy_tobus(hwp->TextInfo, hwp->Base, TEXT_AMOUNT);
hwp->writeSeq(hwp, 0x02, 0x02); /* write to plane 1 */
hwp->writeGr(hwp, 0x04, 0x01); /* read plane 1 */
slowbcopy_tobus((unsigned char *)hwp->TextInfo + TEXT_AMOUNT,
hwp->Base, TEXT_AMOUNT);
}
#endif
vgaHWBlankScreen(scrninfp, TRUE);
/* restore the registers that were changed */
hwp->writeMiscOut(hwp, miscOut);
hwp->writeAttr(hwp, 0x10, attr10);
hwp->writeGr(hwp, 0x01, gr1);
hwp->writeGr(hwp, 0x03, gr3);
hwp->writeGr(hwp, 0x04, gr4);
hwp->writeGr(hwp, 0x05, gr5);
hwp->writeGr(hwp, 0x06, gr6);
hwp->writeGr(hwp, 0x08, gr8);
hwp->writeSeq(hwp, 0x02, seq2);
hwp->writeSeq(hwp, 0x04, seq4);
hwp->IOBase = savedIOBase;
if (doMap)
vgaHWUnmapMem(scrninfp);
#endif /* SAVE_TEXT || SAVE_FONT1 || SAVE_FONT2 */
}
void
vgaHWRestoreMode(ScrnInfoPtr scrninfp, vgaRegPtr restore)
{
vgaHWPtr hwp = VGAHWPTR(scrninfp);
int i;
if (restore->MiscOutReg & 0x01)
hwp->IOBase = VGA_IOBASE_COLOR;
else
hwp->IOBase = VGA_IOBASE_MONO;
hwp->writeMiscOut(hwp, restore->MiscOutReg);
for (i = 1; i < restore->numSequencer; i++)
hwp->writeSeq(hwp, i, restore->Sequencer[i]);
/* Ensure CRTC registers 0-7 are unlocked by clearing bit 7 of CRTC[17] */
hwp->writeCrtc(hwp, 17, restore->CRTC[17] & ~0x80);
for (i = 0; i < restore->numCRTC; i++)
hwp->writeCrtc(hwp, i, restore->CRTC[i]);
for (i = 0; i < restore->numGraphics; i++)
hwp->writeGr(hwp, i, restore->Graphics[i]);
hwp->enablePalette(hwp);
for (i = 0; i < restore->numAttribute; i++)
hwp->writeAttr(hwp, i, restore->Attribute[i]);
hwp->disablePalette(hwp);
}
void
vgaHWRestoreColormap(ScrnInfoPtr scrninfp, vgaRegPtr restore)
{
vgaHWPtr hwp = VGAHWPTR(scrninfp);
int i;
#if 0
hwp->enablePalette(hwp);
#endif
hwp->writeDacMask(hwp, 0xFF);
hwp->writeDacWriteAddr(hwp, 0x00);
for (i = 0; i < 768; i++) {
hwp->writeDacData(hwp, restore->DAC[i]);
DACDelay(hwp);
}
hwp->disablePalette(hwp);
}
/*
* vgaHWRestore --
* restore the VGA state
*/
void
vgaHWRestore(ScrnInfoPtr scrninfp, vgaRegPtr restore, int flags)
{
if (flags & VGA_SR_MODE)
vgaHWRestoreMode(scrninfp, restore);
if (flags & VGA_SR_FONTS)
vgaHWRestoreFonts(scrninfp, restore);
if (flags & VGA_SR_CMAP)
vgaHWRestoreColormap(scrninfp, restore);
}
void
vgaHWSaveFonts(ScrnInfoPtr scrninfp, vgaRegPtr save)
{
#if SAVE_TEXT || SAVE_FONT1 || SAVE_FONT2
vgaHWPtr hwp = VGAHWPTR(scrninfp);
int savedIOBase;
unsigned char miscOut, attr10, gr4, gr5, gr6, seq2, seq4;
Bool doMap = FALSE;
if (hwp->Base == NULL) {
doMap = TRUE;
if (!vgaHWMapMem(scrninfp)) {
xf86DrvMsg(scrninfp->scrnIndex, X_ERROR,
"vgaHWSaveFonts: vgaHWMapMem() failed\n");
return;
}
}
/* If in graphics mode, don't save anything */
attr10 = hwp->readAttr(hwp, 0x10);
if (attr10 & 0x01)
return;
/* save the registers that are needed here */
miscOut = hwp->readMiscOut(hwp);
gr4 = hwp->readGr(hwp, 0x04);
gr5 = hwp->readGr(hwp, 0x05);
gr6 = hwp->readGr(hwp, 0x06);
seq2 = hwp->readSeq(hwp, 0x02);
seq4 = hwp->readSeq(hwp, 0x04);
/* save hwp->IOBase and temporarily set it for colour mode */
savedIOBase = hwp->IOBase;
hwp->IOBase = VGA_IOBASE_COLOR;
/* Force into colour mode */
hwp->writeMiscOut(hwp, miscOut | 0x01);
vgaHWBlankScreen(scrninfp, FALSE);
/*
* get the character sets, and text screen if required
*/
/*
* Here we temporarily switch to 16 colour planar mode, to simply
* copy the font-info
*
* BUG ALERT: The (S)VGA's segment-select register MUST be set correctly!
*/
#if 0
hwp->writeAttr(hwp, 0x10, 0x01); /* graphics mode */
#endif
hwp->writeSeq(hwp, 0x04, 0x06); /* enable plane graphics */
hwp->writeGr(hwp, 0x05, 0x00); /* write mode 0, read mode 0 */
hwp->writeGr(hwp, 0x06, 0x05); /* set graphics */
#if SAVE_FONT1
if (hwp->FontInfo1 || (hwp->FontInfo1 = xalloc(FONT_AMOUNT))) {
hwp->writeSeq(hwp, 0x02, 0x04); /* write to plane 2 */
hwp->writeGr(hwp, 0x04, 0x02); /* read plane 2 */
slowbcopy_frombus(hwp->Base, hwp->FontInfo1, FONT_AMOUNT);
}
#endif /* SAVE_FONT1 */
#if SAVE_FONT2
if (hwp->FontInfo2 || (hwp->FontInfo2 = xalloc(FONT_AMOUNT))) {
hwp->writeSeq(hwp, 0x02, 0x08); /* write to plane 3 */
hwp->writeGr(hwp, 0x04, 0x03); /* read plane 3 */
slowbcopy_frombus(hwp->Base, hwp->FontInfo2, FONT_AMOUNT);
}
#endif /* SAVE_FONT2 */
#if SAVE_TEXT
if (hwp->TextInfo || (hwp->TextInfo = xalloc(2 * TEXT_AMOUNT))) {
hwp->writeSeq(hwp, 0x02, 0x01); /* write to plane 0 */
hwp->writeGr(hwp, 0x04, 0x00); /* read plane 0 */
slowbcopy_frombus(hwp->Base, hwp->TextInfo, TEXT_AMOUNT);
hwp->writeSeq(hwp, 0x02, 0x02); /* write to plane 1 */
hwp->writeGr(hwp, 0x04, 0x01); /* read plane 1 */
slowbcopy_frombus(hwp->Base,
(unsigned char *)hwp->TextInfo + TEXT_AMOUNT, TEXT_AMOUNT);
}
#endif /* SAVE_TEXT */
/* Restore clobbered registers */
hwp->writeAttr(hwp, 0x10, attr10);
hwp->writeSeq(hwp, 0x02, seq2);
hwp->writeSeq(hwp, 0x04, seq4);
hwp->writeGr(hwp, 0x04, gr4);
hwp->writeGr(hwp, 0x05, gr5);
hwp->writeGr(hwp, 0x06, gr6);
hwp->writeMiscOut(hwp, miscOut);
hwp->IOBase = savedIOBase;
vgaHWBlankScreen(scrninfp, TRUE);
if (doMap)
vgaHWUnmapMem(scrninfp);
#endif /* SAVE_TEXT || SAVE_FONT1 || SAVE_FONT2 */
}
void
vgaHWSaveMode(ScrnInfoPtr scrninfp, vgaRegPtr save)
{
vgaHWPtr hwp = VGAHWPTR(scrninfp);
int i;
save->MiscOutReg = hwp->readMiscOut(hwp);
if (save->MiscOutReg & 0x01)
hwp->IOBase = VGA_IOBASE_COLOR;
else
hwp->IOBase = VGA_IOBASE_MONO;
for (i = 0; i < save->numCRTC; i++) {
save->CRTC[i] = hwp->readCrtc(hwp, i);
#ifdef DEBUG
ErrorF("CRTC[0x%02x] = 0x%02x\n", i, save->CRTC[i]);
#endif
}
hwp->enablePalette(hwp);
for (i = 0; i < save->numAttribute; i++) {
save->Attribute[i] = hwp->readAttr(hwp, i);
#ifdef DEBUG
ErrorF("Attribute[0x%02x] = 0x%02x\n", i, save->Attribute[i]);
#endif
}
hwp->disablePalette(hwp);
for (i = 0; i < save->numGraphics; i++) {
save->Graphics[i] = hwp->readGr(hwp, i);
#ifdef DEBUG
ErrorF("Graphics[0x%02x] = 0x%02x\n", i, save->Graphics[i]);
#endif
}
for (i = 1; i < save->numSequencer; i++) {
save->Sequencer[i] = hwp->readSeq(hwp, i);
#ifdef DEBUG
ErrorF("Sequencer[0x%02x] = 0x%02x\n", i, save->Sequencer[i]);
#endif
}
}
void
vgaHWSaveColormap(ScrnInfoPtr scrninfp, vgaRegPtr save)
{
vgaHWPtr hwp = VGAHWPTR(scrninfp);
Bool readError = FALSE;
int i;
#ifdef NEED_SAVED_CMAP
/*
* Some ET4000 chips from 1991 have a HW bug that prevents the reading
* of the color lookup table. Mask rev 9042EAI is known to have this bug.
*
* If the colourmap is not readable, we set the saved map to a default
* map (taken from Ferraro's "Programmer's Guide to the EGA and VGA
* Cards" 2nd ed).
*/
/* Only save it once */
if (hwp->cmapSaved)
return;
#if 0
hwp->enablePalette(hwp);
#endif
hwp->writeDacMask(hwp, 0xFF);
/*
* check if we can read the lookup table
*/
hwp->writeDacReadAddr(hwp, 0x00);
for (i = 0; i < 6; i++) {
save->DAC[i] = hwp->readDacData(hwp);
#ifdef DEBUG
switch (i % 3) {
case 0:
ErrorF("DAC[0x%02x] = 0x%02x, ", i / 3, save->DAC[i]);
break;
case 1:
ErrorF("0x%02x, ", save->DAC[i]);
break;
case 2:
ErrorF("0x%02x\n", save->DAC[i]);
}
#endif
}
/*
* Check if we can read the palette -
* use foreground color to prevent flashing.
*/
hwp->writeDacWriteAddr(hwp, 0x01);
for (i = 3; i < 6; i++)
hwp->writeDacData(hwp, ~save->DAC[i] & DAC_TEST_MASK);
hwp->writeDacReadAddr(hwp, 0x01);
for (i = 3; i < 6; i++) {
if (hwp->readDacData(hwp) != (~save->DAC[i] & DAC_TEST_MASK))
readError = TRUE;
}
hwp->writeDacWriteAddr(hwp, 0x01);
for (i = 3; i < 6; i++)
hwp->writeDacData(hwp, save->DAC[i]);
if (readError) {
/*
* save the default lookup table
*/
memmove(save->DAC, defaultDAC, 768);
xf86DrvMsg(scrninfp->scrnIndex, X_WARNING,
"Cannot read colourmap from VGA. Will restore with default\n");
} else {
/* save the colourmap */
hwp->writeDacReadAddr(hwp, 0x02);
for (i = 6; i < 768; i++) {
save->DAC[i] = hwp->readDacData(hwp);
DACDelay(hwp);
#ifdef DEBUG
switch (i % 3) {
case 0:
ErrorF("DAC[0x%02x] = 0x%02x, ", i / 3, save->DAC[i]);
break;
case 1:
ErrorF("0x%02x, ", save->DAC[i]);
break;
case 2:
ErrorF("0x%02x\n", save->DAC[i]);
}
#endif
}
}
hwp->disablePalette(hwp);
hwp->cmapSaved = TRUE;
#endif
}
/*
* vgaHWSave --
* save the current VGA state
*/
void
vgaHWSave(ScrnInfoPtr scrninfp, vgaRegPtr save, int flags)
{
if (save == NULL)
return;
if (flags & VGA_SR_CMAP)
vgaHWSaveColormap(scrninfp, save);
if (flags & VGA_SR_MODE)
vgaHWSaveMode(scrninfp, save);
if (flags & VGA_SR_FONTS)
vgaHWSaveFonts(scrninfp, save);
}
/*
* vgaHWInit --
* Handle the initialization, etc. of a screen.
* Return FALSE on failure.
*/
Bool
vgaHWInit(ScrnInfoPtr scrninfp, DisplayModePtr mode)
{
unsigned int i;
vgaHWPtr hwp;
vgaRegPtr regp;
int depth = scrninfp->depth;
/*
* make sure the vgaHWRec is allocated
*/
if (!vgaHWGetHWRec(scrninfp))
return FALSE;
hwp = VGAHWPTR(scrninfp);
regp = &hwp->ModeReg;
/*
* compute correct Hsync & Vsync polarity
*/
if ((mode->Flags & (V_PHSYNC | V_NHSYNC))
&& (mode->Flags & (V_PVSYNC | V_NVSYNC)))
{
regp->MiscOutReg = 0x23;
if (mode->Flags & V_NHSYNC) regp->MiscOutReg |= 0x40;
if (mode->Flags & V_NVSYNC) regp->MiscOutReg |= 0x80;
}
else
{
int VDisplay = mode->VDisplay;
if (mode->Flags & V_DBLSCAN)
VDisplay *= 2;
if (mode->VScan > 1)
VDisplay *= mode->VScan;
if (VDisplay < 400)
regp->MiscOutReg = 0xA3; /* +hsync -vsync */
else if (VDisplay < 480)
regp->MiscOutReg = 0x63; /* -hsync +vsync */
else if (VDisplay < 768)
regp->MiscOutReg = 0xE3; /* -hsync -vsync */
else
regp->MiscOutReg = 0x23; /* +hsync +vsync */
}
regp->MiscOutReg |= (mode->ClockIndex & 0x03) << 2;
/*
* Time Sequencer
*/
if (depth == 4)
regp->Sequencer[0] = 0x02;
else
regp->Sequencer[0] = 0x00;
if (mode->Flags & V_CLKDIV2)
regp->Sequencer[1] = 0x09;
else
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 */
/*
* CRTC Controller
*/
regp->CRTC[0] = (mode->CrtcHTotal >> 3) - 5;
regp->CRTC[1] = (mode->CrtcHDisplay >> 3) - 1;
regp->CRTC[2] = (mode->CrtcHBlankStart >> 3) - 1;
regp->CRTC[3] = (((mode->CrtcHBlankEnd >> 3) - 1) & 0x1F) | 0x80;
i = (((mode->CrtcHSkew << 2) + 0x10) & ~0x1F);
if (i < 0x80)
regp->CRTC[3] |= i;
regp->CRTC[4] = (mode->CrtcHSyncStart >> 3);
regp->CRTC[5] = ((((mode->CrtcHBlankEnd >> 3) - 1) & 0x20) << 2)
| (((mode->CrtcHSyncEnd >> 3)) & 0x1F);
regp->CRTC[6] = (mode->CrtcVTotal - 2) & 0xFF;
regp->CRTC[7] = (((mode->CrtcVTotal - 2) & 0x100) >> 8)
| (((mode->CrtcVDisplay - 1) & 0x100) >> 7)
| ((mode->CrtcVSyncStart & 0x100) >> 6)
| (((mode->CrtcVBlankStart - 1) & 0x100) >> 5)
| 0x10
| (((mode->CrtcVTotal - 2) & 0x200) >> 4)
| (((mode->CrtcVDisplay - 1) & 0x200) >> 3)
| ((mode->CrtcVSyncStart & 0x200) >> 2);
regp->CRTC[8] = 0x00;
regp->CRTC[9] = (((mode->CrtcVBlankStart - 1) & 0x200) >> 4) | 0x40;
if (mode->Flags & V_DBLSCAN)
regp->CRTC[9] |= 0x80;
if (mode->VScan >= 32)
regp->CRTC[9] |= 0x1F;
else if (mode->VScan > 1)
regp->CRTC[9] |= mode->VScan - 1;
regp->CRTC[10] = 0x00;
regp->CRTC[11] = 0x00;
regp->CRTC[12] = 0x00;
regp->CRTC[13] = 0x00;
regp->CRTC[14] = 0x00;
regp->CRTC[15] = 0x00;
regp->CRTC[16] = mode->CrtcVSyncStart & 0xFF;
regp->CRTC[17] = (mode->CrtcVSyncEnd & 0x0F) | 0x20;
regp->CRTC[18] = (mode->CrtcVDisplay - 1) & 0xFF;
regp->CRTC[19] = scrninfp->displayWidth >> 4; /* just a guess */
regp->CRTC[20] = 0x00;
regp->CRTC[21] = (mode->CrtcVBlankStart - 1) & 0xFF;
regp->CRTC[22] = (mode->CrtcVBlankEnd - 1) & 0xFF;
if (depth < 8)
regp->CRTC[23] = 0xE3;
else
regp->CRTC[23] = 0xC3;
regp->CRTC[24] = 0xFF;
vgaHWHBlankKGA(mode, regp, 0, KGA_FIX_OVERSCAN | KGA_ENABLE_ON_ZERO);
vgaHWVBlankKGA(mode, regp, 0, KGA_FIX_OVERSCAN | KGA_ENABLE_ON_ZERO);
/*
* Theory resumes here....
*/
/*
* 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; /* only map 64k VGA memory !!!! */
regp->Graphics[7] = 0x0F;
regp->Graphics[8] = 0xFF;
if (depth == 1) {
/* Initialise the Mono map according to which bit-plane gets used */
Bool flipPixels = xf86GetFlipPixels();
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- */ /* wrong for the ET4000 */
if (!hwp->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; /* wrong for the ET4000 */
else
regp->Attribute[16] = 0x41; /* wrong for the ET4000 */
/* Attribute[17] (overscan) initialised in vgaHWGetHWRec() */
}
regp->Attribute[18] = 0x0F;
regp->Attribute[19] = 0x00;
regp->Attribute[20] = 0x00;
return(TRUE);
}
/*
* OK, so much for theory. Now, let's deal with the >real< world...
*
* The above CRTC settings are precise in theory, except that many, if not
* most, VGA clones fail to reset the blanking signal when the character or
* line counter reaches [HV]Total. In this case, the signal is only
* unblanked when the counter reaches [HV]BlankEnd (mod 64, 128 or 256 as
* the case may be) at the start of the >next< scanline or frame, which
* means only part of the screen shows. This affects how null overscans
* are to be implemented on such adapters.
*
* Henceforth, VGA cores that implement this broken, but unfortunately
* common, behaviour are to be designated as KGA's, in honour of Koen
* Gadeyne, whose zeal to eliminate overscans (read: fury) set in motion
* a series of events that led to the discovery of this problem.
*
* Some VGA's are KGA's only in the horizontal, or only in the vertical,
* some in both, others in neither. Don't let anyone tell you there is
* such a thing as a VGA "standard"... And, thank the Creator for the fact
* that Hilbert spaces are not yet implemented in this industry.
*
* The following implements a trick suggested by David Dawes. This sets
* [HV]BlankEnd to zero if the blanking interval does not already contain a
* 0-point, and decrements it by one otherwise. In the latter case, this
* will produce a left and/or top overscan which the colourmap code will
* (still) need to ensure is as close to black as possible. This will make
* the behaviour consistent across all chipsets, while allowing all
* chipsets to display the entire screen. Non-KGA drivers can ignore the
* following in their own copy of this code.
*
* -- TSI @ UQV, 1998.08.21
*/
CARD32
vgaHWHBlankKGA(DisplayModePtr mode, vgaRegPtr regp, int nBits,
unsigned int Flags)
{
int nExtBits = (nBits < 6) ? 0 : nBits - 6;
CARD32 ExtBits;
CARD32 ExtBitMask = ((1 << nExtBits) - 1) << 6;
regp->CRTC[3] = (regp->CRTC[3] & ~0x1F)
| (((mode->CrtcHBlankEnd >> 3) - 1) & 0x1F);
regp->CRTC[5] = (regp->CRTC[5] & ~0x80)
| ((((mode->CrtcHBlankEnd >> 3) - 1) & 0x20) << 2);
ExtBits = ((mode->CrtcHBlankEnd >> 3) - 1) & ExtBitMask;
/* First the horizontal case */
if ((Flags & KGA_FIX_OVERSCAN)
&& ((mode->CrtcHBlankEnd >> 3) == (mode->CrtcHTotal >> 3)))
{
int i = (regp->CRTC[3] & 0x1F)
| ((regp->CRTC[5] & 0x80) >> 2)
| ExtBits;
if (Flags & KGA_ENABLE_ON_ZERO) {
if ((i-- > (((mode->CrtcHBlankStart >> 3) - 1)
& (0x3F | ExtBitMask)))
&& (mode->CrtcHBlankEnd == mode->CrtcHTotal))
i = 0;
} else if (Flags & KGA_BE_TOT_DEC)
i--;
regp->CRTC[3] = (regp->CRTC[3] & ~0x1F) | (i & 0x1F);
regp->CRTC[5] = (regp->CRTC[5] & ~0x80) | ((i << 2) & 0x80);
ExtBits = i & ExtBitMask;
}
return ExtBits >> 6;
}
/*
* The vertical case is a little trickier. Some VGA's ignore bit 0x80 of
* CRTC[22]. Also, in some cases, a zero CRTC[22] will still blank the
* very first scanline in a double- or multi-scanned mode. This last case
* needs further investigation.
*/
CARD32
vgaHWVBlankKGA(DisplayModePtr mode, vgaRegPtr regp, int nBits,
unsigned int Flags)
{
CARD32 ExtBits;
CARD32 nExtBits = (nBits < 8) ? 0 : (nBits - 8);
CARD32 ExtBitMask = ((1 << nExtBits) - 1) << 8;
/* If width is not known nBits should be 0. In this
* case BitMask is set to 0 so we can check for it. */
CARD32 BitMask = (nBits < 7) ? 0 : ((1 << nExtBits) - 1);
int VBlankStart = (mode->CrtcVBlankStart - 1) & 0xFF;
regp->CRTC[22] = (mode->CrtcVBlankEnd - 1) & 0xFF;
ExtBits = (mode->CrtcVBlankEnd - 1) & ExtBitMask;
if ((Flags & KGA_FIX_OVERSCAN)
&& (mode->CrtcVBlankEnd == mode->CrtcVTotal))
/* Null top overscan */
{
int i = regp->CRTC[22] | ExtBits;
if (Flags & KGA_ENABLE_ON_ZERO) {
if (((BitMask && ((i & BitMask) > (VBlankStart & BitMask)))
|| ((i > VBlankStart) && /* 8-bit case */
((i & 0x7F) > (VBlankStart & 0x7F)))) && /* 7-bit case */
!(regp->CRTC[9] & 0x9F)) /* 1 scanline/row */
i = 0;
else
i = (i - 1);
} else if (Flags & KGA_BE_TOT_DEC)
i = (i - 1);
regp->CRTC[22] = i & 0xFF;
ExtBits = i & 0xFF00;
}
return ExtBits >> 8;
}
/*
* these are some more hardware specific helpers, formerly in vga.c
*/
static void
vgaHWGetHWRecPrivate(void)
{
if (vgaHWPrivateIndex < 0)
vgaHWPrivateIndex = xf86AllocateScrnInfoPrivateIndex();
return;
}
static void
vgaHWFreeRegs(vgaRegPtr regp)
{
if (regp->CRTC)
xfree (regp->CRTC);
regp->CRTC =
regp->Sequencer =
regp->Graphics =
regp->Attribute = NULL;
regp->numCRTC =
regp->numSequencer =
regp->numGraphics =
regp->numAttribute = 0;
}
static Bool
vgaHWAllocRegs(vgaRegPtr regp)
{
unsigned char *buf;
if ((regp->numCRTC + regp->numSequencer + regp->numGraphics +
regp->numAttribute) == 0)
return FALSE;
buf = xcalloc(regp->numCRTC +
regp->numSequencer +
regp->numGraphics +
regp->numAttribute, 1);
if (!buf)
return FALSE;
regp->CRTC = buf;
regp->Sequencer = regp->CRTC + regp->numCRTC;
regp->Graphics = regp->Sequencer + regp->numSequencer;
regp->Attribute = regp->Graphics + regp->numGraphics;
return TRUE;
}
Bool
vgaHWAllocDefaultRegs(vgaRegPtr regp)
{
regp->numCRTC = VGA_NUM_CRTC;
regp->numSequencer = VGA_NUM_SEQ;
regp->numGraphics = VGA_NUM_GFX;
regp->numAttribute = VGA_NUM_ATTR;
return vgaHWAllocRegs(regp);
}
Bool
vgaHWSetRegCounts(ScrnInfoPtr scrp, int numCRTC, int numSequencer,
int numGraphics, int numAttribute)
{
#define VGAHWMINNUM(regtype) \
((newMode.num##regtype < regp->num##regtype) ? \
(newMode.num##regtype) : (regp->num##regtype))
#define VGAHWCOPYREGSET(regtype) \
memcpy (newMode.regtype, regp->regtype, VGAHWMINNUM(regtype))
vgaRegRec newMode, newSaved;
vgaRegPtr regp;
regp = &VGAHWPTR(scrp)->ModeReg;
memcpy (&newMode, regp, sizeof(vgaRegRec));
/* allocate space for new registers */
regp = &newMode;
regp->numCRTC = numCRTC;
regp->numSequencer = numSequencer;
regp->numGraphics = numGraphics;
regp->numAttribute = numAttribute;
if (!vgaHWAllocRegs(regp))
return FALSE;
regp = &VGAHWPTR(scrp)->SavedReg;
memcpy (&newSaved, regp, sizeof(vgaRegRec));
regp = &newSaved;
regp->numCRTC = numCRTC;
regp->numSequencer = numSequencer;
regp->numGraphics = numGraphics;
regp->numAttribute = numAttribute;
if (!vgaHWAllocRegs(regp)) {
vgaHWFreeRegs(&newMode);
return FALSE;
}
/* allocations succeeded, copy register data into new space */
regp = &VGAHWPTR(scrp)->ModeReg;
VGAHWCOPYREGSET(CRTC);
VGAHWCOPYREGSET(Sequencer);
VGAHWCOPYREGSET(Graphics);
VGAHWCOPYREGSET(Attribute);
regp = &VGAHWPTR(scrp)->SavedReg;
VGAHWCOPYREGSET(CRTC);
VGAHWCOPYREGSET(Sequencer);
VGAHWCOPYREGSET(Graphics);
VGAHWCOPYREGSET(Attribute);
/* free old register arrays */
regp = &VGAHWPTR(scrp)->ModeReg;
vgaHWFreeRegs(regp);
memcpy(regp, &newMode, sizeof(vgaRegRec));
regp = &VGAHWPTR(scrp)->SavedReg;
vgaHWFreeRegs(regp);
memcpy(regp, &newSaved, sizeof(vgaRegRec));
return TRUE;
#undef VGAHWMINNUM
#undef VGAHWCOPYREGSET
}
Bool
vgaHWCopyReg(vgaRegPtr dst, vgaRegPtr src)
{
vgaHWFreeRegs(dst);
memcpy(dst, src, sizeof(vgaRegRec));
if (!vgaHWAllocRegs(dst))
return FALSE;
memcpy(dst->CRTC, src->CRTC, src->numCRTC);
memcpy(dst->Sequencer, src->Sequencer, src->numSequencer);
memcpy(dst->Graphics, src->Graphics, src->numGraphics);
memcpy(dst->Attribute, src->Attribute, src->numAttribute);
return TRUE;
}
Bool
vgaHWGetHWRec(ScrnInfoPtr scrp)
{
vgaRegPtr regp;
vgaHWPtr hwp;
pciVideoPtr pvp;
int i;
/*
* Let's make sure that the private exists and allocate one.
*/
vgaHWGetHWRecPrivate();
/*
* New privates are always set to NULL, so we can check if the allocation
* has already been done.
*/
if (VGAHWPTR(scrp))
return TRUE;
hwp = VGAHWPTRLVAL(scrp) = xnfcalloc(sizeof(vgaHWRec), 1);
regp = &VGAHWPTR(scrp)->ModeReg;
if ((!vgaHWAllocDefaultRegs(&VGAHWPTR(scrp)->SavedReg)) ||
(!vgaHWAllocDefaultRegs(&VGAHWPTR(scrp)->ModeReg))) {
xfree(hwp);
return FALSE;
}
if (scrp->bitsPerPixel == 1) {
rgb blackColour = scrp->display->blackColour,
whiteColour = scrp->display->whiteColour;
if (blackColour.red > 0x3F) blackColour.red = 0x3F;
if (blackColour.green > 0x3F) blackColour.green = 0x3F;
if (blackColour.blue > 0x3F) blackColour.blue = 0x3F;
if (whiteColour.red > 0x3F) whiteColour.red = 0x3F;
if (whiteColour.green > 0x3F) whiteColour.green = 0x3F;
if (whiteColour.blue > 0x3F) whiteColour.blue = 0x3F;
if ((blackColour.red == whiteColour.red ) &&
(blackColour.green == whiteColour.green) &&
(blackColour.blue == whiteColour.blue )) {
blackColour.red ^= 0x3F;
blackColour.green ^= 0x3F;
blackColour.blue ^= 0x3F;
}
/*
* initialize default colormap for monochrome
*/
for (i=0; i<3; i++) regp->DAC[i] = 0x00;
for (i=3; i<768; i++) regp->DAC[i] = 0x3F;
i = BLACK_VALUE * 3;
regp->DAC[i++] = blackColour.red;
regp->DAC[i++] = blackColour.green;
regp->DAC[i] = blackColour.blue;
i = WHITE_VALUE * 3;
regp->DAC[i++] = whiteColour.red;
regp->DAC[i++] = whiteColour.green;
regp->DAC[i] = whiteColour.blue;
i = OVERSCAN_VALUE * 3;
regp->DAC[i++] = 0x00;
regp->DAC[i++] = 0x00;
regp->DAC[i] = 0x00;
} else {
/* Set all colours to black */
for (i=0; i<768; i++) regp->DAC[i] = 0x00;
/* ... and the overscan */
if (scrp->depth >= 4)
regp->Attribute[OVERSCAN] = 0xFF;
}
if (xf86FindOption(scrp->confScreen->options, "ShowOverscan")) {
xf86MarkOptionUsedByName(scrp->confScreen->options, "ShowOverscan");
xf86DrvMsg(scrp->scrnIndex, X_CONFIG, "Showing overscan area\n");
regp->DAC[765] = 0x3F;
regp->DAC[766] = 0x00;
regp->DAC[767] = 0x3F;
regp->Attribute[OVERSCAN] = 0xFF;
hwp->ShowOverscan = TRUE;
} else
hwp->ShowOverscan = FALSE;
hwp->paletteEnabled = FALSE;
hwp->cmapSaved = FALSE;
hwp->MapSize = 0;
hwp->pScrn = scrp;
/* Initialise the function pointers with the standard VGA versions */
vgaHWSetStdFuncs(hwp);
hwp->PIOOffset = scrp->domainIOBase;
if ((pvp = xf86GetPciInfoForEntity(scrp->entityList[0])))
hwp->Tag = pciTag(pvp->bus, pvp->device, pvp->func);
return TRUE;
}
void
vgaHWFreeHWRec(ScrnInfoPtr scrp)
{
if (vgaHWPrivateIndex >= 0) {
vgaHWPtr hwp = VGAHWPTR(scrp);
if (!hwp)
return;
xfree(hwp->FontInfo1);
xfree(hwp->FontInfo2);
xfree(hwp->TextInfo);
vgaHWFreeRegs (&hwp->ModeReg);
vgaHWFreeRegs (&hwp->SavedReg);
xfree(hwp);
VGAHWPTRLVAL(scrp) = NULL;
}
}
Bool
vgaHWMapMem(ScrnInfoPtr scrp)
{
vgaHWPtr hwp = VGAHWPTR(scrp);
int scr_index = scrp->scrnIndex;
if (hwp->Base)
return TRUE;
/* If not set, initialise with the defaults */
if (hwp->MapSize == 0)
hwp->MapSize = VGA_DEFAULT_MEM_SIZE;
if (hwp->MapPhys == 0)
hwp->MapPhys = VGA_DEFAULT_PHYS_ADDR;
/*
* Map as VIDMEM_MMIO_32BIT because WC
* is bad when there is page flipping.
* XXX This is not correct but we do it
* for now.
*/
#ifdef DEBUG
ErrorF("Mapping VGAMem\n");
#endif
hwp->Base = xf86MapDomainMemory(scr_index, VIDMEM_MMIO_32BIT, hwp->Tag,
hwp->MapPhys, hwp->MapSize);
return hwp->Base != NULL;
}
void
vgaHWUnmapMem(ScrnInfoPtr scrp)
{
vgaHWPtr hwp = VGAHWPTR(scrp);
int scr_index = scrp->scrnIndex;
if (hwp->Base == NULL)
return;
#ifdef DEBUG
ErrorF("Unmapping VGAMem\n");
#endif
xf86UnMapVidMem(scr_index, hwp->Base, hwp->MapSize);
hwp->Base = NULL;
}
int
vgaHWGetIndex()
{
return vgaHWPrivateIndex;
}
void
vgaHWGetIOBase(vgaHWPtr hwp)
{
hwp->IOBase = (hwp->readMiscOut(hwp) & 0x01) ?
VGA_IOBASE_COLOR : VGA_IOBASE_MONO;
xf86DrvMsgVerb(hwp->pScrn->scrnIndex, X_INFO, 3,
"vgaHWGetIOBase: hwp->IOBase is 0x%04x, hwp->PIOOffset is 0x%04lx\n",
hwp->IOBase, hwp->PIOOffset);
}
void
vgaHWLock(vgaHWPtr hwp)
{
/* Protect CRTC[0-7] */
hwp->writeCrtc(hwp, 0x11, hwp->readCrtc(hwp, 0x11) | 0x80);
}
void
vgaHWUnlock(vgaHWPtr hwp)
{
/* Unprotect CRTC[0-7] */
hwp->writeCrtc(hwp, 0x11, hwp->readCrtc(hwp, 0x11) & ~0x80);
}
void
vgaHWEnable(vgaHWPtr hwp)
{
hwp->writeEnable(hwp, hwp->readEnable(hwp) | 0x01);
}
void
vgaHWDisable(vgaHWPtr hwp)
{
hwp->writeEnable(hwp, hwp->readEnable(hwp) & ~0x01);
}
static void
vgaHWLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, LOCO *colors,
VisualPtr pVisual)
{
vgaHWPtr hwp = VGAHWPTR(pScrn);
int i, index;
for (i = 0; i < numColors; i++) {
index = indices[i];
hwp->writeDacWriteAddr(hwp, index);
DACDelay(hwp);
hwp->writeDacData(hwp, colors[index].red);
DACDelay(hwp);
hwp->writeDacData(hwp, colors[index].green);
DACDelay(hwp);
hwp->writeDacData(hwp, colors[index].blue);
DACDelay(hwp);
}
/* This shouldn't be necessary, but we'll play safe. */
hwp->disablePalette(hwp);
}
static void
vgaHWSetOverscan(ScrnInfoPtr pScrn, int overscan)
{
vgaHWPtr hwp = VGAHWPTR(pScrn);
if (overscan < 0 || overscan > 255)
return;
hwp->enablePalette(hwp);
hwp->writeAttr(hwp, OVERSCAN, overscan);
#ifdef DEBUGOVERSCAN
{
int ov = hwp->readAttr(hwp, OVERSCAN);
int red, green, blue;
hwp->writeDacReadAddr(hwp, ov);
red = hwp->readDacData(hwp);
green = hwp->readDacData(hwp);
blue = hwp->readDacData(hwp);
ErrorF("Overscan index is 0x%02x, colours are #%02x%02x%02x\n",
ov, red, green, blue);
}
#endif
hwp->disablePalette(hwp);
}
Bool
vgaHWHandleColormaps(ScreenPtr pScreen)
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
if (pScrn->depth > 1 && pScrn->depth <= 8) {
return xf86HandleColormaps(pScreen, 1 << pScrn->depth,
pScrn->rgbBits, vgaHWLoadPalette,
pScrn->depth > 4 ? vgaHWSetOverscan : NULL,
CMAP_RELOAD_ON_MODE_SWITCH);
}
return TRUE;
}
/* ----------------------- DDC support ------------------------*/
/*
* Adjust v_active, v_blank, v_sync, v_sync_end, v_blank_end, v_total
* to read out EDID at a faster rate. Allowed maximum is 25kHz with
* 20 usec v_sync active. Set positive v_sync polarity, turn off lightpen
* readback, enable access to cr00-cr07.
*/
/* vertical timings */
#define DISPLAY_END 0x04
#define BLANK_START DISPLAY_END
#define SYNC_START BLANK_START
#define SYNC_END 0x09
#define BLANK_END SYNC_END
#define V_TOTAL BLANK_END
/* this function doesn't have to be reentrant for our purposes */
struct _vgaDdcSave {
unsigned char cr03;
unsigned char cr06;
unsigned char cr07;
unsigned char cr09;
unsigned char cr10;
unsigned char cr11;
unsigned char cr12;
unsigned char cr15;
unsigned char cr16;
unsigned char msr;
};
void
vgaHWddc1SetSpeed(ScrnInfoPtr pScrn, xf86ddcSpeed speed)
{
vgaHWPtr hwp = VGAHWPTR(pScrn);
unsigned char tmp;
struct _vgaDdcSave* save;
switch (speed) {
case DDC_FAST:
if (hwp->ddc != NULL) break;
hwp->ddc = xnfcalloc(sizeof(struct _vgaDdcSave),1);
save = (struct _vgaDdcSave *)hwp->ddc;
/* Lightpen register disable - allow access to cr10 & 11; just in case */
save->cr03 = hwp->readCrtc(hwp, 0x03);
hwp->writeCrtc(hwp,0x03,(save->cr03 |0x80));
save->cr12 = hwp->readCrtc(hwp, 0x12);
hwp->writeCrtc(hwp,0x12,DISPLAY_END);
save->cr15 = hwp->readCrtc(hwp, 0x15);
hwp->writeCrtc(hwp,0x15,BLANK_START);
save->cr10 = hwp->readCrtc(hwp, 0x10);
hwp->writeCrtc(hwp,0x10,SYNC_START);
save->cr11 = hwp->readCrtc(hwp, 0x11);
/* unprotect group 1 registers; just in case ...*/
hwp->writeCrtc(hwp,0x11,((save->cr11 & 0x70) | SYNC_END));
save->cr16 = hwp->readCrtc(hwp, 0x16);
hwp->writeCrtc(hwp,0x16,BLANK_END);
save->cr06 = hwp->readCrtc(hwp, 0x06);
hwp->writeCrtc(hwp,0x06,V_TOTAL);
/* all values have less than 8 bit - mask out 9th and 10th bits */
save->cr09 = hwp->readCrtc(hwp, 0x09);
hwp->writeCrtc(hwp,0x09,(save->cr09 &0xDF));
save->cr07 = hwp->readCrtc(hwp, 0x07);
hwp->writeCrtc(hwp,0x07,(save->cr07 &0x10));
/* vsync polarity negativ & ensure a 25MHz clock */
save->msr = hwp->readMiscOut(hwp);
hwp->writeMiscOut(hwp,((save->msr & 0xF3) | 0x80));
break;
case DDC_SLOW:
if (hwp->ddc == NULL) break;
save = (struct _vgaDdcSave *)hwp->ddc;
hwp->writeMiscOut(hwp,save->msr);
hwp->writeCrtc(hwp,0x07,save->cr07);
tmp = hwp->readCrtc(hwp, 0x09);
hwp->writeCrtc(hwp,0x09,((save->cr09 & 0x20) | (tmp & 0xDF)));
hwp->writeCrtc(hwp,0x06,save->cr06);
hwp->writeCrtc(hwp,0x16,save->cr16);
hwp->writeCrtc(hwp,0x11,save->cr11);
hwp->writeCrtc(hwp,0x10,save->cr10);
hwp->writeCrtc(hwp,0x15,save->cr15);
hwp->writeCrtc(hwp,0x12,save->cr12);
hwp->writeCrtc(hwp,0x03,save->cr03);
xfree(save);
hwp->ddc = NULL;
break;
default:
break;
}
}
DDC1SetSpeedProc vgaHWddc1SetSpeedWeak(void) { return vgaHWddc1SetSpeed; }
SaveScreenProcPtr vgaHWSaveScreenWeak(void) { return vgaHWSaveScreen; }
|