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
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
|
/*
* Copyright 2004-2005 The Unichrome Project [unichrome.sf.net]
* Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
* Copyright 2001-2003 S3 Graphics, Inc. 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, sub license,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "xf86.h"
#include "xf86_OSproc.h"
#include "xf86fbman.h"
#include "via.h"
#ifdef OPENCHROMEDRI
#include "xf86drm.h"
#endif
#include "via_driver.h"
#include "via_priv.h"
#include "via_swov.h"
#ifdef OPENCHROMEDRI
#include "via_drm.h"
#endif
#include "via_vgahw.h"
#include "via_id.h"
#include <math.h>
#include <unistd.h>
/*
* Warning: this file contains revision checks which are CLE266-specific.
* There seems to be no checking present for KM400 or more recent devices.
*
* TODO:
* - pVia->Chipset checking, of course
* - move content of pVia->HWDiff into pVia->swov
* - merge with CLEXF40040
*/
/*
* Old via_regrec code.
*/
#define VIDREG_BUFFER_SIZE 100 /* Number of entries in the VidRegBuffer. */
#define IN_VIDEO_DISPLAY (*((unsigned long volatile *)(pVia->VidMapBase+V_FLAGS))&VBI_STATUS)
#define VIA_FIRETIMEOUT 40000
enum HQV_CME_Regs {
HQV_SDO_CTRL1,
HQV_SDO_CTRL2,
HQV_SDO_CTRL3,
HQV_SDO_CTRL4
};
/* register offsets for VT3553/VX800 */
static const unsigned hqv_cme_regs[] = {
[HQV_SDO_CTRL1] = HQV_SRC_DATA_OFFSET_CONTROL1,
[HQV_SDO_CTRL2] = HQV_SRC_DATA_OFFSET_CONTROL2,
[HQV_SDO_CTRL3] = HQV_SRC_DATA_OFFSET_CONTROL3,
[HQV_SDO_CTRL4] = HQV_SRC_DATA_OFFSET_CONTROL4
};
/* register hqv offsets for new VT3409/VX855 */
static const unsigned hqv_cme_regs_409[] = {
[HQV_SDO_CTRL1] = HQV_SRC_DATA_OFFSET_CTRL1_409,
[HQV_SDO_CTRL2] = HQV_SRC_DATA_OFFSET_CTRL2_409,
[HQV_SDO_CTRL3] = HQV_SRC_DATA_OFFSET_CTRL3_409,
[HQV_SDO_CTRL4] = HQV_SRC_DATA_OFFSET_CTRL4_409
};
#define HQV_CME_REG(HWDiff, name) (HWDiff)->HQVCmeRegs[name]
static void
viaWaitVideoCommandFire(VIAPtr pVia)
{
/*
* Uncached PCI reading throughput is about 9 MB/s; so 8 bytes/loop means about
* 1M loops/second. We want to time out after 50 ms, which means 50000 loops.
*/
unsigned count = 50000;
CARD32 volatile *pdwState =
(CARD32 volatile *)(pVia->VidMapBase + V_COMPOSE_MODE);
while (--count && ((*pdwState & V1_COMMAND_FIRE)
|| (*pdwState & V3_COMMAND_FIRE))) ;
if (!count) {
ErrorF("viaWaitVideoCommandFire: Timeout.\n");
}
}
static void
viaWaitHQVFlip(VIAPtr pVia)
{
unsigned long proReg = 0;
CARD32 volatile *pdwState;
unsigned count = 50000;
if (pVia->ChipId == PCI_CHIP_VT3259
&& !(pVia->swov.gdwVideoFlagSW & VIDEO_1_INUSE))
proReg = PRO_HQV1_OFFSET;
pdwState = (CARD32 volatile *)(pVia->VidMapBase + (HQV_CONTROL + proReg));
if (pVia->VideoEngine == VIDEO_ENGINE_CME) {
while (--count && (*pdwState & HQV_SUBPIC_FLIP));
} else {
while (--count && !(*pdwState & HQV_FLIP_STATUS)) ;
}
}
static void
viaWaitHQVFlipClear(VIAPtr pVia, unsigned long dwData)
{
CARD32 volatile *pdwState =
(CARD32 volatile *)(pVia->VidMapBase + HQV_CONTROL);
*pdwState = dwData;
unsigned count = 50000;
while (--count && (*pdwState & HQV_FLIP_STATUS)) {
VIDOutD(HQV_CONTROL, *pdwState | HQV_FLIP_STATUS);
}
}
static void
viaWaitVBI(VIAPtr pVia)
{
while (IN_VIDEO_DISPLAY) ;
}
static void
viaWaitHQVDone(VIAPtr pVia)
{
CARD32 volatile *pdwState;
unsigned long proReg = 0;
unsigned count = 50000;
if (pVia->ChipId == PCI_CHIP_VT3259
&& !(pVia->swov.gdwVideoFlagSW & VIDEO_1_INUSE))
proReg = PRO_HQV1_OFFSET;
pdwState = (CARD32 volatile *)(pVia->VidMapBase + (HQV_CONTROL + proReg));
if (pVia->swov.MPEG_ON) {
while (--count && (*pdwState & HQV_SW_FLIP)) ;
}
}
/*
* Send all data in VidRegBuffer to the hardware.
*/
static void
FlushVidRegBuffer(VIAPtr pVia)
{
unsigned int i;
viaWaitVideoCommandFire(pVia);
for (i = 0; i < pVia->VidRegCursor; i += 2) {
VIDOutD(pVia->VidRegBuffer[i], pVia->VidRegBuffer[i + 1]);
DBG_DD(ErrorF("FlushVideoRegs: [%i] %08lx %08lx\n",
i >> 1, pVia->VidRegBuffer[i] + 0x200,
pVia->VidRegBuffer[i + 1]));
}
/* BUG: (?) VIA never resets the cursor.
* My fix is commented out for now, in case they had a reason for that. /A
*/
/* pVia->VidRegCursor = 0; */
}
/*
* Initialize and clear VidRegBuffer.
*/
static void
ResetVidRegBuffer(VIAPtr pVia)
{
/* BUG: (Memory leak) This allocation may need have a corresponding free somewhere... /A */
if (!pVia->VidRegBuffer)
pVia->VidRegBuffer =
xnfcalloc(VIDREG_BUFFER_SIZE, sizeof(CARD32) * 2);
pVia->VidRegCursor = 0;
}
/*
* Save a video register and data in VidRegBuffer.
*/
static void
SaveVideoRegister(VIAPtr pVia, CARD32 index, CARD32 data)
{
if (pVia->VidRegCursor >= VIDREG_BUFFER_SIZE) {
DBG_DD(ErrorF("SaveVideoRegister: Out of video register space flushing"));
FlushVidRegBuffer(pVia);
ResetVidRegBuffer(pVia);
}
pVia->VidRegBuffer[pVia->VidRegCursor++] = index;
pVia->VidRegBuffer[pVia->VidRegCursor++] = data;
}
/*
* HW Difference Flag (moved here from via_hwdiff.c)
*
* These are the entries of HWDiff used in our code (currently):
* CLE266Ax CLE266Cx KM400 K8M800 PM800
* ThreeHQVBuffer FALSE TRUE TRUE TRUE TRUE
* HQVFetchByteUnit FALSE TRUE TRUE TRUE TRUE
* SupportTwoColorKey FALSE TRUE FALSE FALSE TRUE
* HQVInitPatch TRUE FALSE FALSE FALSE FALSE
* HQVDisablePatch FALSE TRUE TRUE TRUE FALSE
*
* This is now up to date with CLEXF40040. All unused entries were removed.
* The functions depending on this struct are untouched.
*/
void
VIAVidHWDiffInit(ScrnInfoPtr pScrn)
{
VIAPtr pVia = VIAPTR(pScrn);
VIAHWDiff *HWDiff = &pVia->HWDiff;
switch (pVia->Chipset) {
case VIA_CLE266:
if (CLE266_REV_IS_AX(pVia->ChipRev)) {
HWDiff->dwThreeHQVBuffer = VID_HWDIFF_FALSE;
HWDiff->dwHQVFetchByteUnit = VID_HWDIFF_FALSE;
HWDiff->dwSupportTwoColorKey = VID_HWDIFF_FALSE;
HWDiff->dwHQVInitPatch = VID_HWDIFF_TRUE;
HWDiff->dwHQVDisablePatch = VID_HWDIFF_FALSE;
HWDiff->dwNeedV1Prefetch = VID_HWDIFF_FALSE;
} else {
HWDiff->dwThreeHQVBuffer = VID_HWDIFF_TRUE;
HWDiff->dwHQVFetchByteUnit = VID_HWDIFF_TRUE;
HWDiff->dwSupportTwoColorKey = VID_HWDIFF_TRUE;
HWDiff->dwHQVInitPatch = VID_HWDIFF_FALSE;
HWDiff->dwHQVDisablePatch = VID_HWDIFF_TRUE;
HWDiff->dwNeedV1Prefetch = VID_HWDIFF_FALSE;
}
HWDiff->dwNewScaleCtl = VID_HWDIFF_FALSE;
break;
case VIA_KM400:
HWDiff->dwThreeHQVBuffer = VID_HWDIFF_TRUE;
HWDiff->dwHQVFetchByteUnit = VID_HWDIFF_TRUE;
HWDiff->dwSupportTwoColorKey = VID_HWDIFF_FALSE;
HWDiff->dwHQVInitPatch = VID_HWDIFF_FALSE;
HWDiff->dwHQVDisablePatch = VID_HWDIFF_TRUE;
HWDiff->dwNeedV1Prefetch = VID_HWDIFF_FALSE;
HWDiff->dwNewScaleCtl = VID_HWDIFF_FALSE;
break;
case VIA_K8M800:
HWDiff->dwThreeHQVBuffer = VID_HWDIFF_TRUE;
HWDiff->dwHQVFetchByteUnit = VID_HWDIFF_TRUE;
HWDiff->dwSupportTwoColorKey = VID_HWDIFF_FALSE;
HWDiff->dwHQVInitPatch = VID_HWDIFF_FALSE;
HWDiff->dwHQVDisablePatch = VID_HWDIFF_TRUE;
HWDiff->dwNeedV1Prefetch = VID_HWDIFF_FALSE;
HWDiff->dwNewScaleCtl = VID_HWDIFF_FALSE;
break;
case VIA_PM800:
HWDiff->dwThreeHQVBuffer = VID_HWDIFF_TRUE;
HWDiff->dwHQVFetchByteUnit = VID_HWDIFF_TRUE;
HWDiff->dwSupportTwoColorKey = VID_HWDIFF_TRUE;
HWDiff->dwHQVInitPatch = VID_HWDIFF_FALSE;
HWDiff->dwHQVDisablePatch = VID_HWDIFF_FALSE;
HWDiff->dwNeedV1Prefetch = VID_HWDIFF_FALSE;
HWDiff->dwNewScaleCtl = VID_HWDIFF_FALSE;
HWDiff->HQVCmeRegs = hqv_cme_regs;
break;
case VIA_VM800:
case VIA_P4M900:
HWDiff->dwThreeHQVBuffer = VID_HWDIFF_TRUE;
HWDiff->dwHQVFetchByteUnit = VID_HWDIFF_TRUE;
HWDiff->dwSupportTwoColorKey = VID_HWDIFF_FALSE;
HWDiff->dwHQVInitPatch = VID_HWDIFF_FALSE;
HWDiff->dwHQVDisablePatch = VID_HWDIFF_TRUE;
HWDiff->dwNeedV1Prefetch = VID_HWDIFF_FALSE;
HWDiff->dwNewScaleCtl = VID_HWDIFF_FALSE;
HWDiff->HQVCmeRegs = hqv_cme_regs;
break;
case VIA_K8M890:
HWDiff->dwThreeHQVBuffer = VID_HWDIFF_TRUE;
HWDiff->dwHQVFetchByteUnit = VID_HWDIFF_TRUE;
HWDiff->dwSupportTwoColorKey = VID_HWDIFF_FALSE;
HWDiff->dwHQVInitPatch = VID_HWDIFF_FALSE;
HWDiff->dwHQVDisablePatch = VID_HWDIFF_TRUE;
HWDiff->dwNeedV1Prefetch = VID_HWDIFF_TRUE;
HWDiff->dwNewScaleCtl = VID_HWDIFF_FALSE;
HWDiff->HQVCmeRegs = hqv_cme_regs;
break;
case VIA_P4M890:
HWDiff->dwThreeHQVBuffer = VID_HWDIFF_TRUE;
HWDiff->dwHQVFetchByteUnit = VID_HWDIFF_TRUE;
HWDiff->dwSupportTwoColorKey = VID_HWDIFF_FALSE;
HWDiff->dwHQVInitPatch = VID_HWDIFF_FALSE;
HWDiff->dwHQVDisablePatch = VID_HWDIFF_TRUE;
HWDiff->dwNeedV1Prefetch = VID_HWDIFF_FALSE;
HWDiff->dwNewScaleCtl = VID_HWDIFF_FALSE;
HWDiff->HQVCmeRegs = hqv_cme_regs;
break;
case VIA_CX700:
HWDiff->dwThreeHQVBuffer = VID_HWDIFF_TRUE;
HWDiff->dwHQVFetchByteUnit = VID_HWDIFF_TRUE;
HWDiff->dwSupportTwoColorKey = VID_HWDIFF_TRUE;
HWDiff->dwHQVInitPatch = VID_HWDIFF_FALSE;
HWDiff->dwHQVDisablePatch = VID_HWDIFF_FALSE;
HWDiff->dwNeedV1Prefetch = VID_HWDIFF_FALSE;
HWDiff->dwNewScaleCtl = VID_HWDIFF_FALSE;
HWDiff->HQVCmeRegs = hqv_cme_regs;
break;
case VIA_VX800:
HWDiff->dwThreeHQVBuffer = VID_HWDIFF_TRUE;
HWDiff->dwHQVFetchByteUnit = VID_HWDIFF_TRUE;
HWDiff->dwSupportTwoColorKey = VID_HWDIFF_TRUE;
HWDiff->dwHQVInitPatch = VID_HWDIFF_FALSE;
HWDiff->dwHQVDisablePatch = VID_HWDIFF_FALSE;
HWDiff->dwNeedV1Prefetch = VID_HWDIFF_FALSE;
HWDiff->dwNewScaleCtl = VID_HWDIFF_TRUE;
HWDiff->HQVCmeRegs = hqv_cme_regs;
break;
case VIA_VX855:
case VIA_VX900:
HWDiff->dwThreeHQVBuffer = VID_HWDIFF_TRUE;
HWDiff->dwHQVFetchByteUnit = VID_HWDIFF_TRUE;
HWDiff->dwSupportTwoColorKey = VID_HWDIFF_TRUE;
HWDiff->dwHQVInitPatch = VID_HWDIFF_FALSE;
HWDiff->dwHQVDisablePatch = VID_HWDIFF_FALSE;
HWDiff->dwNeedV1Prefetch = VID_HWDIFF_FALSE;
HWDiff->dwNewScaleCtl = VID_HWDIFF_TRUE;
HWDiff->HQVCmeRegs = hqv_cme_regs_409;
break;
default:
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"VIAVidHWDiffInit: Unhandled ChipSet.\n");
}
}
/*
* Old via_overlay code.
*/
typedef struct _YCBCRREC
{
CARD32 dwY;
CARD32 dwCB;
CARD32 dwCR;
} YCBCRREC;
/*
* Verify that using V1 bit definitions on V3
* is not broken in OverlayGetV1V3Format().
*/
#if V1_COLORSPACE_SIGN != V3_COLORSPACE_SIGN
#error "V1_COLORSPACE_SIGN != V3_COLORSPACE_SIGN"
#endif
#if V1_YUV422 != V3_YUV422
#error "V1_YUV422 != V3_YUV422"
#endif
#if V1_SWAP_HW_HQV != V3_SWAP_HW_HQV
#error "V1_SWAP_HW_HQV != V3_SWAP_HW_HQV"
#endif
#if V1_RGB15 != V3_RGB15
#error "V1_RGB15 != V3_RGB15"
#endif
#if V1_RGB16 != V3_RGB16
#error "V1_RGB16 != V3_RGB16"
#endif
#if V1_RGB32 != V3_RGB32
#error "V1_RGB32 != V3_RGB32"
#endif
static BOOL
viaOverlayGetV1V3Format(VIAPtr pVia, int vport, /* 1 or 3, as in V1 or V3 */
unsigned long videoFlag, unsigned long *pVidCtl,
unsigned long *pHQVCtl)
{
if (videoFlag & VIDEO_HQV_INUSE) {
switch (pVia->swov.SrcFourCC) {
case FOURCC_YV12:
case FOURCC_I420:
case FOURCC_XVMC:
*pHQVCtl |= HQV_YUV420;
break;
case FOURCC_YUY2:
*pHQVCtl |= HQV_YUV422;
break;
case FOURCC_RV32:
*pVidCtl |= V1_RGB32;
*pHQVCtl |= HQV_RGB32;
break;
case FOURCC_RV15:
*pVidCtl |= V1_RGB15;
*pHQVCtl |= HQV_RGB15;
break;
case FOURCC_RV16:
*pVidCtl |= V1_RGB16;
*pHQVCtl |= HQV_RGB16;
break;
default:
DBG_DD(ErrorF("viaOverlayGetV1V3Format: "
"Invalid FOURCC format (0x%lx).\n",
pVia->swov.SrcFourCC));
return FALSE;
}
*pVidCtl |= V1_SWAP_HW_HQV;
*pHQVCtl |= HQV_SRC_SW | HQV_ENABLE | HQV_SW_FLIP;
} else {
switch (pVia->swov.SrcFourCC) {
case FOURCC_YV12:
case FOURCC_I420:
case FOURCC_XVMC:
if (vport == 1) {
*pVidCtl |= V1_YCbCr420;
} else {
DBG_DD(ErrorF("viaOverlayGetV1V3Format: "
"V3 does not support planar YUV.\n"));
return FALSE;
}
break;
case FOURCC_YUY2:
*pVidCtl |= V1_YUV422;
break;
case FOURCC_RV32:
case FOURCC_RV15:
case FOURCC_RV16:
ErrorF("viaOverlayGetV1V3Format: "
"Can't display RGB video in this configuration.\n");
return FALSE;
default:
DBG_DD(ErrorF("viaOverlayGetV1V3Format: "
"Invalid FOURCC format (0x%lx).\n",
pVia->swov.SrcFourCC));
return FALSE;
}
}
*pVidCtl |= V1_COLORSPACE_SIGN;
return TRUE;
}
static unsigned long
viaOverlayGetSrcStartAddress(VIAPtr pVia,
unsigned long videoFlag,
LPDDUPDATEOVERLAY pUpdate,
unsigned long srcPitch,
unsigned long *pHQVoffset)
{
unsigned long srcWidth =
(unsigned long)(pUpdate->SrcRight - pUpdate->SrcLeft);
unsigned long dstWidth =
(unsigned long)(pUpdate->DstRight - pUpdate->DstLeft);
unsigned long srcHeight =
(unsigned long)(pUpdate->SrcBottom - pUpdate->SrcTop);
unsigned long dstHeight =
(unsigned long)(pUpdate->DstBottom - pUpdate->DstTop);
unsigned long offset = 0;
unsigned long srcTopOffset = 0;
unsigned long srcLeftOffset = 0;
int n = 1;
if ((pUpdate->SrcLeft != 0) || (pUpdate->SrcTop != 0)) {
switch (pVia->swov.SrcFourCC) {
case FOURCC_RV32:
n = 2;
case FOURCC_YUY2:
case FOURCC_UYVY:
case FOURCC_RV15:
case FOURCC_RV16:
if (videoFlag & VIDEO_HQV_INUSE) {
offset = (((pUpdate->SrcTop & ~3) * srcPitch)
+ ((pUpdate->SrcLeft << n) & ~31));
if (srcHeight > dstHeight)
srcTopOffset = ((pUpdate->SrcTop & ~3)
* dstHeight / srcHeight) * srcPitch;
else
srcTopOffset = (pUpdate->SrcTop & ~3) * srcPitch;
if (srcWidth > dstWidth)
srcLeftOffset = (((pUpdate->SrcLeft << n) & ~31)
* dstWidth / srcWidth);
else
srcLeftOffset = (pUpdate->SrcLeft << n) & ~31;
*pHQVoffset = srcTopOffset + srcLeftOffset;
} else
offset = ((pUpdate->SrcTop * srcPitch)
+ ((pUpdate->SrcLeft << n) & ~15));
break;
case FOURCC_YV12:
case FOURCC_I420:
case FOURCC_XVMC:
if (videoFlag & VIDEO_HQV_INUSE)
offset = (((pUpdate->SrcTop & ~3) * (srcPitch << 1))
+ ((pUpdate->SrcLeft << 1) & ~31));
else {
offset = ((((pUpdate->SrcTop & ~3) * srcPitch)
+ pUpdate->SrcLeft) & ~31);
if (pUpdate->SrcTop > 0)
pVia->swov.overlayRecordV1.dwUVoffset
= (((((pUpdate->SrcTop & ~3) >> 1) * srcPitch)
+ pUpdate->SrcLeft) & ~31) >> 1;
else
pVia->swov.overlayRecordV1.dwUVoffset = offset >> 1;
}
break;
default:
DBG_DD(ErrorF("viaGetSrcStartAddress: "
"Invalid FOURCC format (0x%lx).\n",
pVia->swov.SrcFourCC));
break;
}
} else {
pVia->swov.overlayRecordV1.dwUVoffset = offset = 0;
}
return offset;
}
static YCBCRREC
viaOverlayGetYCbCrStartAddress(unsigned long videoFlag,
unsigned long startAddr, unsigned long offset,
unsigned long UVoffset, unsigned long srcPitch,
unsigned long srcHeight)
{
YCBCRREC YCbCr;
if (videoFlag & VIDEO_HQV_INUSE) {
YCbCr.dwY = startAddr;
YCbCr.dwCB = startAddr + srcPitch * srcHeight;
YCbCr.dwCR = (startAddr + srcPitch * srcHeight
+ srcPitch * (srcHeight >> 2));
} else {
YCbCr.dwY = startAddr + offset;
YCbCr.dwCB = startAddr + srcPitch * srcHeight + UVoffset;
YCbCr.dwCR = (startAddr + srcPitch * srcHeight + UVoffset
+ srcPitch * (srcHeight >> 2));
}
return YCbCr;
}
static unsigned long
viaOverlayHQVCalcZoomWidth(VIAPtr pVia,
unsigned long videoFlag, unsigned long srcWidth,
unsigned long dstWidth, unsigned long *pZoomCtl,
unsigned long *pMiniCtl,
unsigned long *pHQVfilterCtl,
unsigned long *pHQVminiCtl,
unsigned long *pHQVscaleCtlH,
unsigned long *pHQVzoomflag)
{
unsigned long tmp, sw1, d, falign, mdiv;
Bool zoom_ok = TRUE;
VIAHWDiff *hwDiff = &pVia->HWDiff;
CARD32 HQVfilter[5] = { HQV_H_FILTER_DEFAULT, HQV_H_TAP4_121,
HQV_H_TAP4_121, HQV_H_TAP8_12221, HQV_H_TAP8_12221
};
/* CARD HQVmini[5] = { 0, 0xc00, 0xa00, 0x900, 0x8800 }; */
falign = 0;
mdiv = 1;
if (srcWidth == dstWidth) { /* No zoom */
*pHQVfilterCtl |= HQV_H_FILTER_DEFAULT;
} else if (srcWidth < dstWidth) { /* Zoom in */
*pZoomCtl &= 0x0000FFFF;
tmp = srcWidth * 0x800 / dstWidth;
*pZoomCtl |= ((tmp & 0x7ff) << 16) | V1_X_ZOOM_ENABLE;
*pMiniCtl |= V1_X_INTERPOLY;
zoom_ok = !(tmp > 0x7ff);
*pHQVzoomflag = 1;
*pHQVfilterCtl |= HQV_H_FILTER_DEFAULT;
} else { /* srcWidth > dstWidth - Zoom out */
if (hwDiff->dwNewScaleCtl) {
if (srcWidth > (dstWidth << 3)) {
/*<1/8*/
/*FIXME!*/
if (dstWidth <= 32) {
dstWidth = 33;
}
if (srcWidth > (dstWidth << 5)) {
tmp = 1 * 0x1000 / 31;
} else {
tmp = (dstWidth * 0x1000) / srcWidth;
}
*pHQVscaleCtlH = HQV_H_SCALE_DOWN_UNDER_EIGHTH;
} else if (srcWidth == (dstWidth << 3)) {
/*1/8*/
tmp = ((dstWidth - 1) * 0x1000) / srcWidth;
*pHQVscaleCtlH = HQV_H_SCALE_DOWN_UNDER_EIGHTH;
} else if (srcWidth > (dstWidth << 2)) {
/*1/4 -1/8 zoom-out*/
tmp = (srcWidth * 0x1000) / dstWidth;
*pHQVscaleCtlH = HQV_H_SCALE_DOWN_FOURTH_TO_EIGHTH;
} else {
/*1-1/4 zoom-out*/
/*setting :src/(destination+0.5)*/
tmp = (srcWidth * 0x2000) / ((dstWidth << 1) + 1);
*pHQVscaleCtlH = HQV_H_SCALE_DOWN_FOURTH_TO_1;
}
/*rounding to nearest interger*/
tmp += (((tmp * 0x1000) & 0xfff) > 1) ? 1 : 0;
*pHQVscaleCtlH |= (tmp & 0x7fff) | HQV_H_SCALE_ENABLE;
} else {
/* HQV rounding patch, instead of:
* //tmp = dstWidth*0x0800 / srcWidth; */
tmp = dstWidth * 0x800 * 0x400 / srcWidth;
tmp = tmp / 0x400 + ((tmp & 0x3ff) ? 1 : 0);
*pHQVminiCtl = (tmp & 0x7ff) | HQV_H_MINIFY_ENABLE | HQV_H_MINIFY_DOWN;
*pHQVminiCtl |= HQV_HDEBLOCK_FILTER;
}
/* Scale down the picture by a factor mdiv = (1 << d) = {2, 4, 8 or 16} */
sw1 = srcWidth;
for (d = 1; d < 5; d++) {
sw1 >>= 1;
if (sw1 <= dstWidth)
break;
}
if (d == 5) { /* Too small. */
d = 4;
zoom_ok = FALSE;
}
mdiv = 1 << d; /* <= {2,4,8,16} */
falign = ((mdiv << 1) - 1) & 0xf; /* <= {3,7,15,15} */
*pMiniCtl |= V1_X_INTERPOLY;
*pMiniCtl |= ((d << 1) - 1) << 24; /* <= {1,3,5,7} << 24 */
*pHQVfilterCtl |= HQVfilter[d];
/* Scale to arbitrary size, on top of previous scaling by (1 << d). */
if (sw1 < dstWidth) {
/* CLE bug
*pZoomCtl = sw1 * 0x0800 / dstWidth;*/
*pZoomCtl = (sw1 - 2) * 0x0800 / dstWidth;
*pZoomCtl = ((*pZoomCtl & 0x7ff) << 16) | V1_X_ZOOM_ENABLE;
}
if (videoFlag & VIDEO_1_INUSE) {
pVia->swov.overlayRecordV1.dwFetchAlignment = falign;
pVia->swov.overlayRecordV1.dwminifyH = mdiv;
} else {
pVia->swov.overlayRecordV3.dwFetchAlignment = falign;
pVia->swov.overlayRecordV3.dwminifyH = mdiv;
}
}
return zoom_ok;
}
static unsigned long
viaOverlayHQVCalcZoomHeight(VIAPtr pVia,
unsigned long srcHeight, unsigned long dstHeight,
unsigned long *pZoomCtl, unsigned long *pMiniCtl,
unsigned long *pHQVfilterCtl,
unsigned long *pHQVminiCtl,
unsigned long *pHQVscaleCtlV,
unsigned long *pHQVzoomflag)
{
unsigned long tmp, sh1, d;
Bool zoom_ok = TRUE;
VIAHWDiff *hwDiff = &pVia->HWDiff;
CARD32 HQVfilter[5] = { HQV_V_TAP4_121, HQV_V_TAP4_121, HQV_V_TAP4_121,
HQV_V_TAP8_12221, HQV_V_TAP8_12221 };
/* CARD32 HQVmini[5] = { 0, 0x0c000000, 0x0a000000, 0x09000000, 0x08800000 }; */
/*if (pVia->pBIOSInfo->scaleY)
* {
* dstHeight = dstHeight + 1;
* } */
if (srcHeight == dstHeight) { /* No zoom */
*pHQVfilterCtl |= HQV_V_TAP4_121;
} else if (srcHeight < dstHeight) { /* Zoom in */
*pZoomCtl &= 0xFFFF0000;
tmp = srcHeight * 0x400 / dstHeight - 1;
*pZoomCtl |= ((tmp & 0x3ff) | V1_Y_ZOOM_ENABLE);
*pMiniCtl |= (V1_Y_INTERPOLY | V1_YCBCR_INTERPOLY);
*pHQVzoomflag = 1;
*pHQVfilterCtl |= HQV_V_TAP4_121;
} else { /* srcHeight > dstHeight - Zoom out */
if (hwDiff->dwNewScaleCtl) {
/*setting :src/(destination+0.5)*/
tmp = srcHeight * 0x2000 / ((dstHeight << 1) + 1);
tmp += (((tmp * 0x1000) & 0xfff) > 1) ? 1 : 0;
if ((tmp & 0x1ffff) == 0) {
tmp = 0x1ffff;
}
*pHQVscaleCtlV = (tmp & 0x1ffff) | HQV_V_SCALE_ENABLE| HQV_V_SCALE_DOWN;
} else {
/* HQV rounding patch, instead of:
* //tmp = dstHeight*0x0800 / srcHeight; */
tmp = dstHeight * 0x0800 * 0x400 / srcHeight;
tmp = tmp / 0x400 + ((tmp & 0x3ff) ? 1 : 0);
*pHQVminiCtl |= (((tmp & 0x7ff) << 16) | HQV_V_MINIFY_ENABLE
| HQV_V_MINIFY_DOWN);
/* Scale down the picture by a factor (1 << d) = {2, 4, 8 or 16} */
sh1 = srcHeight;
for (d = 1; d < 5; d++) {
sh1 >>= 1;
if (sh1 <= dstHeight)
break;
}
if (d == 5) { /* Too small. */
d = 4;
zoom_ok = FALSE;
}
*pMiniCtl |= ((d << 1) - 1) << 16; /* <= {1,3,5,7} << 16 */
*pHQVfilterCtl |= HQVfilter[d];
/* *pHQVminiCtl |= HQVmini[d]; */
*pHQVminiCtl |= HQV_VDEBLOCK_FILTER;
/* Scale to arbitrary size, on top of previous scaling by (1 << d). */
if (sh1 < dstHeight) {
tmp = sh1 * 0x0400 / dstHeight;
*pZoomCtl |= ((tmp & 0x3ff) | V1_Y_ZOOM_ENABLE);
*pMiniCtl |= V1_Y_INTERPOLY | V1_YCBCR_INTERPOLY;
}
}
}
return zoom_ok;
}
static unsigned long
viaOverlayGetFetch(VIAPtr pVia, unsigned long videoFlag,
unsigned long srcWidth, unsigned long dstWidth,
unsigned long oriSrcWidth, unsigned long *pHQVsrcFetch)
{
unsigned long fetch = 0;
int n = 2; /* 2^n bytes per pixel. */
switch (pVia->swov.SrcFourCC) {
case FOURCC_YV12:
case FOURCC_I420:
case FOURCC_XVMC:
n = 0; /* 2^n = 1 byte per pixel (Y channel in planar YUV) */
break;
case FOURCC_UYVY:
case FOURCC_YUY2:
case FOURCC_RV15:
case FOURCC_RV16:
n = 1; /* 2^n = 2 bytes per pixel (packed YUV) */
break;
case FOURCC_RV32:
n = 2;
break;
default:
DBG_DD(ErrorF("viaOverlayGetFetch: "
"Invalid FOURCC format (0x%lx).\n",
pVia->swov.SrcFourCC));
break;
}
if (videoFlag & VIDEO_HQV_INUSE) {
*pHQVsrcFetch = oriSrcWidth << n;
if (n == 0) {
/* Assume n == 0 <=> Planar YUV.
* The V1/V3 pixelformat is always packed YUV when we use HQV,
* so we switch from 8-bit to 16-bit pixels here.
*/
n = 1;
}
if (dstWidth >= srcWidth)
fetch = (ALIGN_TO(srcWidth << n, 16) >> 4) + 1;
else
fetch = (ALIGN_TO(dstWidth << n, 16) >> 4) + 1;
} else {
if (n == 0)
fetch = (ALIGN_TO(srcWidth, 32) >> 4);
else
fetch = (ALIGN_TO(srcWidth << n, 16) >> 4) + 1;
}
/* Fix planar mode problem. */
if (fetch < 4)
fetch = 4;
return fetch;
}
/*
* This function uses quadratic mapping to adjust the midpoint of the scaling.
*/
static float
rangeEqualize(float inLow, float inHigh, float outLow, float outHigh,
float outMid, float inValue)
{
float inRange = inHigh - inLow,
outRange = outHigh - outLow,
normIn = ((inValue - inLow) / inRange) * 2. - 1.,
delta = outMid - outRange * 0.5 - outLow;
return ((inValue - inLow) * outRange / inRange + outLow
+ (1. - normIn * normIn) * delta);
}
static unsigned
vPackFloat(float val, float hiLimit, float loLimit, float mult, int shift,
Bool doSign)
{
unsigned packed, mask, sign;
val = (val > hiLimit) ? hiLimit : val;
val = (val < loLimit) ? loLimit : val;
sign = (val < 0) ? 1 : 0;
val = (sign) ? -val : val;
packed = ((unsigned)(val * mult + 1.)) >> 1;
mask = (1 << shift) - 1;
return (((packed >= mask) ? mask : packed)
| ((doSign) ? (sign << shift) : 0));
}
typedef float colorCoeff[5];
static colorCoeff colorCTable[] = {
{1.1875, 1.625, 0.875, 0.375, 2.0},
{1.164, 1.596, 0.54, 0.45, 2.2}
};
/*
* This function is a partial rewrite of the overlay.c file of the original VIA
* drivers, which was extremely nasty and difficult to follow. Coefficients for
* new chipset models should be added in the table above and, if needed,
* implemented in the model switch below.
*/
static void
viaCalculateVideoColor(VIAPtr pVia, int hue, int saturation,
int brightness, int contrast, Bool reset,
CARD32 * col1, CARD32 * col2)
{
float fA, fB1, fC1, fD, fB2, fC2, fB3, fC3;
float fPI, fContrast, fSaturation, fHue, fBrightness;
const float *mCoeff;
unsigned long dwA, dwB1, dwC1, dwD, dwB2, dwC2, dwB3, dwC3, dwS;
unsigned long dwD_Int, dwD_Dec;
int intD;
int model;
fPI = (float)(M_PI / 180.);
if (reset) {
saturation = 10000;
brightness = 5000;
contrast = 10000;
}
switch (pVia->ChipId) {
case PCI_CHIP_VT3205:
case PCI_CHIP_VT3204:
case PCI_CHIP_VT3259:
case PCI_CHIP_VT3314:
case PCI_CHIP_VT3336:
case PCI_CHIP_VT3364:
case PCI_CHIP_VT3324:
case PCI_CHIP_VT3327:
case PCI_CHIP_VT3353:
case PCI_CHIP_VT3409:
case PCI_CHIP_VT3410:
model = 0;
break;
case PCI_CHIP_CLE3122:
model = (CLE266_REV_IS_CX(pVia->ChipRev) ? 0 : 1);
break;
default:
ErrorF("Unknown Chip ID\n");
model = 0;
}
switch (model) {
case 0:
fBrightness = rangeEqualize(0., 10000., -128., 128., -16.,
(float)brightness);
fContrast = rangeEqualize(0., 20000., 0., 1.6645, 1.0,
(float)contrast);
fSaturation = rangeEqualize(0., 20000, 0., 2., 1.,
(float)saturation);
break;
default:
fBrightness = rangeEqualize(0., 10000., -128., 128., -12.,
(float)brightness);
fContrast = rangeEqualize(0., 20000., 0., 1.6645, 1.1,
(float)contrast);
fSaturation = rangeEqualize(0., 20000, 0., 2., 1.15,
(float)saturation);
break;
}
fHue = (float)hue;
mCoeff = colorCTable[model];
fA = (float)(mCoeff[0] * fContrast);
fB1 = (float)(-mCoeff[1] * fContrast * fSaturation * sin(fHue * fPI));
fC1 = (float)(mCoeff[1] * fContrast * fSaturation * cos(fHue * fPI));
fD = (float)(mCoeff[0] * (fBrightness));
fB2 = (float)((mCoeff[2] * sin(fHue * fPI) - mCoeff[3] * cos(fHue * fPI))
* fContrast * fSaturation);
fC2 = (float)(-(mCoeff[2] * cos(fHue * fPI) + mCoeff[3] * sin(fHue * fPI))
* fContrast * fSaturation);
fB3 = (float)(mCoeff[4] * fContrast * fSaturation * cos(fHue * fPI));
fC3 = (float)(mCoeff[4] * fContrast * fSaturation * sin(fHue * fPI));
switch (model) {
case 0:
dwA = vPackFloat(fA, 1.9375, 0., 32., 5, 0);
dwB1 = vPackFloat(fB1, 2.125, -2.125, 16., 5, 1);
dwC1 = vPackFloat(fC1, 2.125, -2.125, 16., 5, 1);
if (fD >= 0) {
intD = (int)fD;
if (intD > 127)
intD = 127;
dwD_Int = ((unsigned long)intD) & 0xff;
dwD = ((unsigned long)(fD * 16 + 1)) >> 1;
dwD_Dec = dwD & 0x7;
} else {
intD = (int)fD;
if (intD < -128)
intD = -128;
intD = intD + 256;
dwD_Int = ((unsigned long)intD) & 0xff;
fD = -fD;
dwD = ((unsigned long)(fD * 16 + 1)) >> 1;
dwD_Dec = dwD & 0x7;
}
dwB2 = vPackFloat(fB2, 1.875, -1.875, 16, 4, 1);
dwC2 = vPackFloat(fC2, 1.875, -1.875, 16, 4, 1);
dwB3 = vPackFloat(fB3, 3.875, -3.875, 16, 5, 1);
dwC3 = vPackFloat(fC3, 3.875, -3.875, 16, 5, 1);
*col1 = (dwA << 24) | (dwB1 << 16) | (dwC1 << 8) | dwD_Int;
*col2 = (dwD_Dec << 29 | dwB2 << 24) | (dwC2 << 16) | (dwB3 << 8)
| (dwC3);
break;
default:
dwA = vPackFloat(fA, 1.9375, -0., 32, 5, 0);
dwB1 = vPackFloat(fB1, 0.75, -0.75, 8., 2, 1);
dwC1 = vPackFloat(fC1, 2.875, 1., 16., 5, 0);
if (fD >= 127)
fD = 127;
if (fD <= -128)
fD = -128;
if (fD >= 0) {
dwS = 0;
} else {
dwS = 1;
fD = fD + 128;
}
dwD = ((unsigned long)(fD * 2 + 1)) >> 1;
if (dwD >= 0x7f) {
dwD = 0x7f | (dwS << 7);
} else {
dwD = (dwD & 0x7f) | (dwS << 7);
}
dwB2 = vPackFloat(fB2, 0., -0.875, 16., 3, 0);
dwC2 = vPackFloat(fC2, 0., -1.875, 16., 4, 0);
dwB3 = vPackFloat(fB3, 3.75, 0., 8., 4, 0);
dwC3 = vPackFloat(fC3, 1.25, -1.25, 8., 3, 1);
*col1 = (dwA << 24) | (dwB1 << 18) | (dwC1 << 9) | dwD;
*col2 = (dwB2 << 25) | (dwC2 << 17) | (dwB3 << 10) | (dwC3 << 2);
break;
}
}
/*
*
*
*/
void
viaSetColorSpace(VIAPtr pVia, int hue, int saturation, int brightness,
int contrast, Bool reset)
{
CARD32 col1, col2;
viaCalculateVideoColor(pVia, hue, saturation, brightness, contrast, reset,
&col1, &col2);
switch (pVia->ChipId) {
case PCI_CHIP_VT3205:
case PCI_CHIP_VT3204:
case PCI_CHIP_VT3259:
case PCI_CHIP_VT3314:
VIDOutD(V3_ColorSpaceReg_1, col1);
VIDOutD(V3_ColorSpaceReg_2, col2);
DBG_DD(ErrorF("000002C4 %08lx\n", col1));
DBG_DD(ErrorF("000002C8 %08lx\n", col2));
break;
case PCI_CHIP_VT3327:
case PCI_CHIP_VT3336:
case PCI_CHIP_VT3324:
case PCI_CHIP_VT3364:
case PCI_CHIP_VT3353:
case PCI_CHIP_VT3409:
case PCI_CHIP_VT3410:
case PCI_CHIP_CLE3122:
VIDOutD(V1_ColorSpaceReg_2, col2);
VIDOutD(V1_ColorSpaceReg_1, col1);
VIDOutD(V3_ColorSpaceReg_2, col2);
VIDOutD(V3_ColorSpaceReg_1, col1);
DBG_DD(ErrorF("00000288 %08lx\n", col2));
DBG_DD(ErrorF("00000284 %08lx\n", col1));
break;
default:
DBG_DD(ErrorF("Unknown DeviceID\n"));
break;
}
}
static unsigned long
ViaInitVideoStatusFlag(VIAPtr pVia)
{
switch (pVia->ChipId) {
case PCI_CHIP_VT3205:
case PCI_CHIP_VT3204:
case PCI_CHIP_VT3259:
case PCI_CHIP_VT3314:
return VIDEO_HQV_INUSE | SW_USE_HQV | VIDEO_3_INUSE;
case PCI_CHIP_VT3327:
case PCI_CHIP_VT3336:
case PCI_CHIP_VT3324:
case PCI_CHIP_VT3364:
case PCI_CHIP_VT3353:
case PCI_CHIP_VT3409:
case PCI_CHIP_VT3410:
return (VIDEO_HQV_INUSE | SW_USE_HQV | VIDEO_1_INUSE
| VIDEO_ACTIVE | VIDEO_SHOW);
case PCI_CHIP_CLE3122:
return VIDEO_HQV_INUSE | SW_USE_HQV | VIDEO_1_INUSE;
default:
DBG_DD(ErrorF("Unknown DeviceID\n"));
break;
}
return 0UL;
}
static unsigned long
ViaSetVidCtl(VIAPtr pVia, unsigned int videoFlag)
{
if (videoFlag & VIDEO_1_INUSE) {
/*=* Modify for C1 FIFO *=*/
/* WARNING: not checking Chipset! */
if (CLE266_REV_IS_CX(pVia->ChipRev))
return V1_ENABLE | V1_EXPIRE_NUM_F;
else {
/* Overlay source format for V1 */
if (pVia->swov.gdwUseExtendedFIFO)
return V1_ENABLE | V1_EXPIRE_NUM_A | V1_FIFO_EXTENDED;
else
return V1_ENABLE | V1_EXPIRE_NUM;
}
} else {
switch (pVia->ChipId) {
case PCI_CHIP_VT3205:
case PCI_CHIP_VT3204:
case PCI_CHIP_VT3259:
case PCI_CHIP_VT3314:
return V3_ENABLE | V3_EXPIRE_NUM_3205;
case PCI_CHIP_VT3327:
case PCI_CHIP_VT3336:
case PCI_CHIP_VT3324:
case PCI_CHIP_VT3364:
case PCI_CHIP_VT3353:
return V3_ENABLE | VIDEO_EXPIRE_NUM_VT3336;
case PCI_CHIP_VT3409:
case PCI_CHIP_VT3410:
return V3_ENABLE | VIDEO_EXPIRE_NUM_VT3409;
case PCI_CHIP_CLE3122:
if (CLE266_REV_IS_CX(pVia->ChipRev))
return V3_ENABLE | V3_EXPIRE_NUM_F;
else
return V3_ENABLE | V3_EXPIRE_NUM;
break;
default:
DBG_DD(ErrorF("Unknown DeviceID\n"));
break;
}
}
return 0;
}
/*
* Fill the buffer with 0x8000 (YUV2 black).
*/
static void
ViaYUVFillBlack(VIAPtr pVia, int offset, int num)
{
CARD16 *ptr = (CARD16 *) (pVia->FBBase + offset);
while (num-- > 0)
#if X_BYTE_ORDER == X_LITTLE_ENDIAN
*ptr++ = 0x0080;
#else
*ptr++ = 0x8000;
#endif
}
/*
* Add an HQV surface to an existing FOURCC surface.
* numbuf: number of buffers, 1, 2 or 3
* fourcc: FOURCC code of the current (already existing) surface
*/
static long
AddHQVSurface(ScrnInfoPtr pScrn, unsigned int numbuf, CARD32 fourcc)
{
unsigned int i, width, height, pitch, fbsize, addr;
unsigned long retCode;
BOOL isplanar;
VIAPtr pVia = VIAPTR(pScrn);
CARD32 AddrReg[3] = { HQV_DST_STARTADDR0, HQV_DST_STARTADDR1,
HQV_DST_STARTADDR2 };
unsigned long proReg = 0;
if (pVia->ChipId == PCI_CHIP_VT3259 &&
!(pVia->swov.gdwVideoFlagSW & VIDEO_1_INUSE))
proReg = PRO_HQV1_OFFSET;
isplanar = ((fourcc == FOURCC_YV12) || (fourcc == FOURCC_I420) ||
(fourcc == FOURCC_XVMC));
width = pVia->swov.SWDevice.gdwSWSrcWidth;
height = pVia->swov.SWDevice.gdwSWSrcHeight;
pitch = pVia->swov.SWDevice.dwPitch;
fbsize = pitch * height * (isplanar ? 2 : 1);
VIAFreeLinear(&pVia->swov.HQVMem);
retCode = VIAAllocLinear(&pVia->swov.HQVMem, pScrn, fbsize * numbuf);
if (retCode != Success)
return retCode;
addr = pVia->swov.HQVMem.base;
ViaYUVFillBlack(pVia, addr, fbsize);
for (i = 0; i < numbuf; i++) {
pVia->swov.overlayRecordV1.dwHQVAddr[i] = addr;
VIDOutD(AddrReg[i] + proReg, addr);
addr += fbsize;
}
return Success;
}
/*
* Create a FOURCC surface.
* doalloc: set true to actually allocate memory for the framebuffers
*/
static long
CreateSurface(ScrnInfoPtr pScrn, CARD32 FourCC, CARD16 Width,
CARD16 Height, BOOL doalloc)
{
VIAPtr pVia = VIAPTR(pScrn);
unsigned long pitch, fbsize, addr;
unsigned long retCode;
BOOL isplanar;
pVia->swov.SrcFourCC = FourCC;
pVia->swov.gdwVideoFlagSW = ViaInitVideoStatusFlag(pVia);
isplanar = FALSE;
switch (FourCC) {
case FOURCC_YV12:
case FOURCC_I420:
case FOURCC_XVMC:
isplanar = TRUE;
pitch = ALIGN_TO(Width, 32);
fbsize = pitch * Height * 1.5;
break;
case FOURCC_RV32:
pitch = ALIGN_TO(Width << 2, 32);
fbsize = pitch * Height;
break;
default:
pitch = ALIGN_TO(Width << 1, 32);
fbsize = pitch * Height;
break;
}
if (doalloc) {
VIAFreeLinear(&pVia->swov.SWfbMem);
retCode = VIAAllocLinear(&pVia->swov.SWfbMem, pScrn, fbsize * 2);
if (retCode != Success)
return retCode;
addr = pVia->swov.SWfbMem.base;
ViaYUVFillBlack(pVia, addr, fbsize);
pVia->swov.SWDevice.dwSWPhysicalAddr[0] = addr;
pVia->swov.SWDevice.dwSWPhysicalAddr[1] = addr + fbsize;
pVia->swov.SWDevice.lpSWOverlaySurface[0] = pVia->FBBase + addr;
pVia->swov.SWDevice.lpSWOverlaySurface[1] =
pVia->swov.SWDevice.lpSWOverlaySurface[0] + fbsize;
if (isplanar) {
pVia->swov.SWDevice.dwSWCrPhysicalAddr[0] =
pVia->swov.SWDevice.dwSWPhysicalAddr[0] +
(pitch * Height);
pVia->swov.SWDevice.dwSWCrPhysicalAddr[1] =
pVia->swov.SWDevice.dwSWPhysicalAddr[1] +
(pitch * Height);
pVia->swov.SWDevice.dwSWCbPhysicalAddr[0] =
pVia->swov.SWDevice.dwSWCrPhysicalAddr[0] +
((pitch >> 1) * (Height >> 1));
pVia->swov.SWDevice.dwSWCbPhysicalAddr[1] =
pVia->swov.SWDevice.dwSWCrPhysicalAddr[1] +
((pitch >> 1) * (Height >> 1));
}
}
pVia->swov.SWDevice.gdwSWSrcWidth = Width;
pVia->swov.SWDevice.gdwSWSrcHeight = Height;
pVia->swov.SWDevice.dwPitch = pitch;
pVia->swov.overlayRecordV1.dwV1OriWidth = Width;
pVia->swov.overlayRecordV1.dwV1OriHeight = Height;
pVia->swov.overlayRecordV1.dwV1OriPitch = pitch;
return Success;
}
/*
*
*/
int
ViaSwovSurfaceCreate(ScrnInfoPtr pScrn, viaPortPrivPtr pPriv,
CARD32 FourCC, CARD16 Width, CARD16 Height)
{
VIAPtr pVia = VIAPTR(pScrn);
unsigned long retCode = Success;
int numbuf = pVia->HWDiff.dwThreeHQVBuffer ? 3 : 2;
DBG_DD(ErrorF("ViaSwovSurfaceCreate: FourCC =0x%08lx\n", FourCC));
if ((pVia->VideoStatus & VIDEO_SWOV_SURFACE_CREATED)
&& (FourCC == pPriv->FourCC))
return Success;
pPriv->FourCC = FourCC;
switch (FourCC) {
case FOURCC_YUY2:
case FOURCC_RV15:
case FOURCC_RV16:
case FOURCC_RV32:
retCode = CreateSurface(pScrn, FourCC, Width, Height, TRUE);
if (retCode != Success)
break;
if ((pVia->swov.gdwVideoFlagSW & SW_USE_HQV))
retCode = AddHQVSurface(pScrn, numbuf, FourCC);
break;
case FOURCC_HQVSW:
retCode = AddHQVSurface(pScrn, numbuf, FOURCC_YUY2);
break;
case FOURCC_YV12:
case FOURCC_I420:
retCode = CreateSurface(pScrn, FourCC, Width, Height, TRUE);
if (retCode == Success)
retCode = AddHQVSurface(pScrn, numbuf, FourCC);
break;
case FOURCC_XVMC:
retCode = CreateSurface(pScrn, FourCC, Width, Height, FALSE);
if (retCode == Success)
retCode = AddHQVSurface(pScrn, numbuf, FOURCC_XVMC);
break;
default:
break;
}
if (retCode == Success) {
pVia->swov.SWDevice.lpSWOverlaySurface[0] = pVia->FBBase
+ pVia->swov.SWDevice.dwSWPhysicalAddr[0];
pVia->swov.SWDevice.lpSWOverlaySurface[1] = pVia->FBBase
+ pVia->swov.SWDevice.dwSWPhysicalAddr[1];
DBG_DD(ErrorF(" lpSWOverlaySurface[0]: %p\n",
pVia->swov.SWDevice.lpSWOverlaySurface[0]));
DBG_DD(ErrorF(" lpSWOverlaySurface[1]: %p\n",
pVia->swov.SWDevice.lpSWOverlaySurface[1]));
pVia->VideoStatus |= VIDEO_SWOV_SURFACE_CREATED | VIDEO_SWOV_ON;
}
return retCode;
}
/*
* Destroy Surface
*/
void
ViaSwovSurfaceDestroy(ScrnInfoPtr pScrn, viaPortPrivPtr pPriv)
{
VIAPtr pVia = VIAPTR(pScrn);
DBG_DD(ErrorF("ViaSwovSurfaceDestroy: FourCC =0x%08lx\n", pPriv->FourCC));
if (pVia->VideoStatus & VIDEO_SWOV_SURFACE_CREATED) {
DBG_DD(ErrorF("ViaSwovSurfaceDestroy: VideoStatus =0x%08lx\n",
pVia->VideoStatus));
switch (pPriv->FourCC) {
case FOURCC_YUY2:
case FOURCC_RV16:
case FOURCC_RV32:
case FOURCC_RV15:
pVia->swov.SrcFourCC = 0;
VIAFreeLinear(&pVia->swov.SWfbMem);
if ((pVia->swov.gdwVideoFlagSW & SW_USE_HQV))
VIAFreeLinear(&pVia->swov.HQVMem);
pVia->swov.gdwVideoFlagSW = 0;
break;
case FOURCC_HQVSW:
VIAFreeLinear(&pVia->swov.HQVMem);
pVia->swov.gdwVideoFlagSW = 0;
break;
case FOURCC_YV12:
case FOURCC_I420:
VIAFreeLinear(&pVia->swov.SWfbMem);
case FOURCC_XVMC:
pVia->swov.SrcFourCC = 0;
VIAFreeLinear(&pVia->swov.HQVMem);
pVia->swov.gdwVideoFlagSW = 0;
break;
}
pPriv->FourCC = 0;
pVia->VideoStatus &= ~VIDEO_SWOV_SURFACE_CREATED;
} else
DBG_DD(ErrorF("ViaSwovSurfaceDestroy: No SW Surface Destroyed, "
"VideoStatus =0x%08lx\n", pVia->VideoStatus));
}
static void
SetFIFO_V1(VIAPtr pVia, CARD8 depth, CARD8 prethreshold, CARD8 threshold)
{
SaveVideoRegister(pVia, V_FIFO_CONTROL,
((depth - 1) & 0x7f) |
((prethreshold & 0x7f) << 24) |
((threshold & 0x7f) << 8));
}
static void
SetFIFO_V3(VIAPtr pVia, CARD8 depth, CARD8 prethreshold, CARD8 threshold)
{
switch (pVia->ChipId) {
case PCI_CHIP_VT3314:
case PCI_CHIP_VT3324:
case PCI_CHIP_VT3327:
case PCI_CHIP_VT3353:
case PCI_CHIP_VT3409:
case PCI_CHIP_VT3410:
SaveVideoRegister(pVia, ALPHA_V3_FIFO_CONTROL,
(VIDInD(ALPHA_V3_FIFO_CONTROL) & ALPHA_FIFO_MASK)
| ((depth - 1) & 0xff) | ((threshold & 0xff) << 8));
SaveVideoRegister(pVia, ALPHA_V3_PREFIFO_CONTROL,
(VIDInD(ALPHA_V3_PREFIFO_CONTROL)
& ~V3_FIFO_MASK_3314) | (prethreshold & 0xff));
break;
default :
SaveVideoRegister(pVia, ALPHA_V3_FIFO_CONTROL,
(VIDInD(ALPHA_V3_FIFO_CONTROL) & ALPHA_FIFO_MASK)
| ((depth - 1) & 0xff) | ((threshold & 0xff) << 8));
SaveVideoRegister(pVia, ALPHA_V3_PREFIFO_CONTROL,
(VIDInD(ALPHA_V3_PREFIFO_CONTROL) & ~V3_FIFO_MASK)
| (prethreshold & 0x7f));
break;
}
}
static void
SetFIFO_64or32(VIAPtr pVia)
{
/*=* Modify for C1 FIFO *=*/
/* WARNING: not checking Chipset! */
if (CLE266_REV_IS_CX(pVia->ChipRev))
SetFIFO_V1(pVia, 64, 56, 56);
else
SetFIFO_V1(pVia, 32, 29, 16);
}
static void
SetFIFO_64or16(VIAPtr pVia)
{
/*=* Modify for C1 FIFO *=*/
/* WARNING: not checking Chipset! */
if (CLE266_REV_IS_CX(pVia->ChipRev))
SetFIFO_V1(pVia, 64, 56, 56);
else
SetFIFO_V1(pVia, 16, 12, 8);
}
static void
SetFIFO_64or48or32(VIAPtr pVia)
{
/*=* Modify for C1 FIFO *=*/
/* WARNING: not checking Chipset! */
if (CLE266_REV_IS_CX(pVia->ChipRev))
SetFIFO_V1(pVia, 64, 56, 56);
else {
if (pVia->swov.gdwUseExtendedFIFO)
SetFIFO_V1(pVia, 48, 40, 40);
else
SetFIFO_V1(pVia, 32, 29, 16);
}
}
static void
SetFIFO_V3_64or32or32(VIAPtr pVia)
{
switch (pVia->ChipId) {
case PCI_CHIP_VT3327:
case PCI_CHIP_VT3336:
case PCI_CHIP_VT3324:
case PCI_CHIP_VT3364:
case PCI_CHIP_VT3353:
case PCI_CHIP_VT3409:
case PCI_CHIP_VT3410:
SetFIFO_V3(pVia, 225, 200, 250);
break;
case PCI_CHIP_VT3204:
SetFIFO_V3(pVia, 100, 89, 89);
break;
case PCI_CHIP_VT3314:
SetFIFO_V3(pVia, 64, 61, 61);
break;
case PCI_CHIP_VT3205:
case PCI_CHIP_VT3259:
SetFIFO_V3(pVia, 32, 29, 29);
break;
case PCI_CHIP_CLE3122:
if (CLE266_REV_IS_CX(pVia->ChipRev))
SetFIFO_V3(pVia, 64, 56, 56);
else
SetFIFO_V3(pVia, 32, 16, 16);
break;
default:
break;
}
}
static void
SetFIFO_V3_64or32or16(VIAPtr pVia)
{
switch (pVia->ChipId) {
case PCI_CHIP_VT3327:
case PCI_CHIP_VT3336:
case PCI_CHIP_VT3324:
case PCI_CHIP_VT3364:
case PCI_CHIP_VT3353:
case PCI_CHIP_VT3409:
case PCI_CHIP_VT3410:
SetFIFO_V3(pVia, 225, 200, 250);
break;
case PCI_CHIP_VT3204:
SetFIFO_V3(pVia, 100, 89, 89);
break;
case PCI_CHIP_VT3314:
SetFIFO_V3(pVia, 64, 61, 61);
break;
case PCI_CHIP_VT3205:
case PCI_CHIP_VT3259:
SetFIFO_V3(pVia, 32, 29, 29);
break;
case PCI_CHIP_CLE3122:
if (CLE266_REV_IS_CX(pVia->ChipRev))
SetFIFO_V3(pVia, 64, 56, 56);
else
SetFIFO_V3(pVia, 16, 16, 8);
break;
default:
break;
}
}
static void
SetupFIFOs(VIAPtr pVia, unsigned long videoFlag,
unsigned long miniCtl, unsigned long srcWidth)
{
if (miniCtl & V1_Y_INTERPOLY) {
if (pVia->swov.SrcFourCC == FOURCC_YV12
|| pVia->swov.SrcFourCC == FOURCC_I420
|| pVia->swov.SrcFourCC == FOURCC_XVMC) {
if (videoFlag & VIDEO_HQV_INUSE) {
if (videoFlag & VIDEO_1_INUSE)
SetFIFO_64or32(pVia);
else
SetFIFO_V3_64or32or16(pVia);
} else {
/* Minified video will be skewed without this workaround. */
if (srcWidth <= 80) { /* Fetch count <= 5 */
if (videoFlag & VIDEO_1_INUSE)
SetFIFO_V1(pVia, 16, 0, 0);
else
SetFIFO_V3(pVia, 16, 16, 0);
} else {
if (videoFlag & VIDEO_1_INUSE)
SetFIFO_64or16(pVia);
else
SetFIFO_V3_64or32or16(pVia);
}
}
} else {
if (videoFlag & VIDEO_1_INUSE)
SetFIFO_64or48or32(pVia);
else {
/* Fix V3 bug. */
if (srcWidth <= 8)
SetFIFO_V3(pVia, 1, 0, 0);
else
SetFIFO_V3_64or32or32(pVia);
}
}
} else {
if (pVia->swov.SrcFourCC == FOURCC_YV12
|| pVia->swov.SrcFourCC == FOURCC_I420
|| pVia->swov.SrcFourCC == FOURCC_XVMC) {
if (videoFlag & VIDEO_HQV_INUSE) {
if (videoFlag & VIDEO_1_INUSE)
SetFIFO_64or32(pVia);
else
SetFIFO_V3_64or32or16(pVia);
} else {
/* Minified video will be skewed without this workaround. */
if (srcWidth <= 80) { /* Fetch count <= 5 */
if (videoFlag & VIDEO_1_INUSE)
SetFIFO_V1(pVia, 16, 0, 0);
else
SetFIFO_V3(pVia, 16, 16, 0);
} else {
if (videoFlag & VIDEO_1_INUSE)
SetFIFO_64or16(pVia);
else
SetFIFO_V3_64or32or16(pVia);
}
}
} else {
if (videoFlag & VIDEO_1_INUSE)
SetFIFO_64or48or32(pVia);
else {
/* Fix V3 bug. */
if (srcWidth <= 8)
SetFIFO_V3(pVia, 1, 0, 0);
else
SetFIFO_V3_64or32or32(pVia);
}
}
}
}
static CARD32
SetColorKey(VIAPtr pVia, unsigned long videoFlag,
CARD32 keyLow, CARD32 keyHigh, CARD32 compose)
{
keyLow &= 0x00FFFFFF;
if (pVia->VideoEngine == VIDEO_ENGINE_CME)
keyLow |= 0x40000000;
if (videoFlag & VIDEO_1_INUSE) {
SaveVideoRegister(pVia, V_COLOR_KEY, keyLow);
SaveVideoRegister(pVia, SND_COLOR_KEY, keyLow);
} else {
if (pVia->HWDiff.dwSupportTwoColorKey) /*CLE_C0 */
SaveVideoRegister(pVia, V3_COLOR_KEY, keyLow);
}
/*CLE_C0 */
compose = ((compose & ~0x0f) | SELECT_VIDEO_IF_COLOR_KEY |
SELECT_VIDEO3_IF_COLOR_KEY);
return compose;
}
static CARD32
SetChromaKey(VIAPtr pVia, unsigned long videoFlag,
CARD32 chromaLow, CARD32 chromaHigh,
CARD32 miniCtl, CARD32 compose)
{
chromaLow &= CHROMA_KEY_LOW;
chromaHigh &= CHROMA_KEY_HIGH;
chromaLow |= (VIDInD(V_CHROMAKEY_LOW) & ~CHROMA_KEY_LOW);
chromaHigh |= (VIDInD(V_CHROMAKEY_HIGH) & ~CHROMA_KEY_HIGH);
if (pVia->VideoEngine == VIDEO_ENGINE_CME)
chromaLow |= 0x40000000;
SaveVideoRegister(pVia, V_CHROMAKEY_HIGH, chromaHigh);
if (videoFlag & VIDEO_1_INUSE) {
SaveVideoRegister(pVia, V_CHROMAKEY_LOW, chromaLow & ~V_CHROMAKEY_V3);
/* Temporarily solve the HW interpolation error when using Chroma key */
SaveVideoRegister(pVia, V1_MINI_CONTROL, miniCtl & 0xFFFFFFF8);
} else {
SaveVideoRegister(pVia, V_CHROMAKEY_LOW, chromaLow | V_CHROMAKEY_V3);
SaveVideoRegister(pVia, V3_MINI_CONTROL, miniCtl & 0xFFFFFFF8);
}
/* Modified by Scottie[2001.12.5] for select video if (Color key & Chroma key) */
if (compose == SELECT_VIDEO_IF_COLOR_KEY)
compose = SELECT_VIDEO_IF_COLOR_KEY | SELECT_VIDEO_IF_CHROMA_KEY;
else
compose = (compose & ~0x0f) | SELECT_VIDEO_IF_CHROMA_KEY;
return compose;
}
static void
SetVideoStart(VIAPtr pVia, unsigned long videoFlag,
unsigned int numbufs, CARD32 a1, CARD32 a2, CARD32 a3)
{
CARD32 V1Addr[3] = { V1_STARTADDR_0, V1_STARTADDR_1, V1_STARTADDR_2 };
CARD32 V3Addr[3] = { V3_STARTADDR_0, V3_STARTADDR_1, V3_STARTADDR_2 };
CARD32 *VideoAddr = (videoFlag & VIDEO_1_INUSE) ? V1Addr : V3Addr;
SaveVideoRegister(pVia, VideoAddr[0], a1);
if (numbufs > 1)
SaveVideoRegister(pVia, VideoAddr[1], a2);
if (numbufs > 2)
SaveVideoRegister(pVia, VideoAddr[2], a3);
}
static void
SetHQVFetch(VIAPtr pVia, CARD32 srcFetch, unsigned long srcHeight)
{
unsigned long proReg = 0;
if (pVia->ChipId == PCI_CHIP_VT3259
&& !(pVia->swov.gdwVideoFlagSW & VIDEO_1_INUSE))
proReg = PRO_HQV1_OFFSET;
if (!pVia->HWDiff.dwHQVFetchByteUnit) { /* CLE_C0 */
srcFetch >>= 3; /* fetch unit is 8 bytes */
}
if ((pVia->ChipId != PCI_CHIP_VT3409) && (pVia->ChipId != PCI_CHIP_VT3410))
SaveVideoRegister(pVia, HQV_SRC_FETCH_LINE + proReg,
((srcFetch - 1) << 16) | (srcHeight - 1));
}
static void
SetFetch(VIAPtr pVia, unsigned long videoFlag, CARD32 fetch)
{
fetch <<= 20;
if (videoFlag & VIDEO_1_INUSE) {
SaveVideoRegister(pVia, V12_QWORD_PER_LINE, fetch);
} else {
fetch |= VIDInD(V3_ALPHA_QWORD_PER_LINE) & ~V3_FETCH_COUNT;
SaveVideoRegister(pVia, V3_ALPHA_QWORD_PER_LINE, fetch);
}
}
static void
SetDisplayCount(VIAPtr pVia, unsigned long videoFlag,
unsigned long srcWidth, unsigned long srcHeight)
{
unsigned long DisplayCount;
/* Removed VIA's large pixelformat switch/case.
* All formats (YV12, UYVY, YUY2, VIA, RGB16 and RGB32)
* seem to use the same count. /A
*/
if (videoFlag & VIDEO_HQV_INUSE)
DisplayCount = srcWidth - 1;
else
DisplayCount = srcWidth - pVia->swov.overlayRecordV1.dwminifyH;
if (videoFlag & VIDEO_1_INUSE)
SaveVideoRegister(pVia, V1_SOURCE_HEIGHT,
(srcHeight << 16) | DisplayCount);
else
SaveVideoRegister(pVia, V3_SOURCE_WIDTH, DisplayCount);
}
static void
SetMiniAndZoom(VIAPtr pVia, unsigned long videoFlag,
CARD32 miniCtl, CARD32 zoomCtl)
{
if (videoFlag & VIDEO_1_INUSE) {
SaveVideoRegister(pVia, V1_MINI_CONTROL, miniCtl);
SaveVideoRegister(pVia, V1_ZOOM_CONTROL, zoomCtl);
} else {
SaveVideoRegister(pVia, V3_MINI_CONTROL, miniCtl);
SaveVideoRegister(pVia, V3_ZOOM_CONTROL, zoomCtl);
}
}
static void
SetVideoControl(VIAPtr pVia, unsigned long videoFlag, CARD32 vidCtl)
{
if (videoFlag & VIDEO_1_INUSE)
SaveVideoRegister(pVia, V1_CONTROL, vidCtl);
else
SaveVideoRegister(pVia, V3_CONTROL, vidCtl);
}
static void
FireVideoCommand(VIAPtr pVia, unsigned long videoFlag, CARD32 compose)
{
if (videoFlag & VIDEO_1_INUSE)
SaveVideoRegister(pVia, V_COMPOSE_MODE, compose | V1_COMMAND_FIRE);
else
SaveVideoRegister(pVia, V_COMPOSE_MODE, compose | V3_COMMAND_FIRE);
}
static void
SetVideoWindow(ScrnInfoPtr pScrn, unsigned long videoFlag,
LPDDUPDATEOVERLAY pUpdate)
{
VIAPtr pVia = VIAPTR(pScrn);
VIABIOSInfoPtr pBIOSInfo = pVia->pBIOSInfo;
CARD32 left = pUpdate->DstLeft;
CARD32 top = pUpdate->DstTop;
CARD32 right = pUpdate->DstRight - 1;
CARD32 bottom = pUpdate->DstBottom - 1;
DBG_DD(ErrorF("SetVideoWindow: X (%ld,%ld) Y (%ld,%ld)\n",
left, right, top, bottom));
/* Modify for HW DVI limitation.
* When we enable both the CRT and DVI, then change resolution.
* If the resolution is smaller than the panel's physical size,
* the video display in Y direction will be cut.
* So, we need to adjust the Y top and bottom position.
*/
if (videoFlag & VIDEO_1_INUSE) {
if (pBIOSInfo->SetDVI && pBIOSInfo->scaleY) {
top = (pUpdate->DstTop * pBIOSInfo->Panel->NativeMode->Height
/ pScrn->currentMode->VDisplay);
bottom = (pUpdate->DstBottom * pBIOSInfo->Panel->NativeMode->Height
/ pScrn->currentMode->VDisplay);
}
}
if (top < 0)
top = 0;
else if (top > 2047)
top = 2047;
if (bottom < 0)
bottom = 0;
else if (bottom > 2047)
bottom = 2047;
if (left < 0)
left = 0;
else if (left > 2047)
left = 2047;
if (right < 0)
right = 0;
else if (right > 2047)
right = 2047;
if (videoFlag & VIDEO_1_INUSE) {
SaveVideoRegister(pVia, V1_WIN_END_Y, (right << 16) | bottom);
SaveVideoRegister(pVia, V1_WIN_START_Y, (left << 16) | top);
} else {
SaveVideoRegister(pVia, V3_WIN_END_Y, (right << 16) | bottom);
SaveVideoRegister(pVia, V3_WIN_START_Y, (left << 16) | top);
}
}
/*
* Upd_Video()
*/
static Bool
Upd_Video(ScrnInfoPtr pScrn, unsigned long videoFlag,
unsigned long startAddr, LPDDUPDATEOVERLAY pUpdate,
unsigned long srcPitch,
unsigned long oriSrcWidth, unsigned long oriSrcHeight,
unsigned long deinterlaceMode,
unsigned long haveColorKey, unsigned long haveChromaKey,
unsigned long colorKeyLow, unsigned long colorKeyHigh,
unsigned long chromaKeyLow, unsigned long chromaKeyHigh)
{
VIAPtr pVia = VIAPTR(pScrn);
VIABIOSInfoPtr pBIOSInfo = pVia->pBIOSInfo;
vgaHWPtr hwp = VGAHWPTR(pScrn);
VIAHWDiff *hwDiff = &pVia->HWDiff;
int i;
unsigned long vidCtl = 0, compose;
unsigned long srcWidth, srcHeight, dstWidth, dstHeight;
unsigned long zoomCtl = 0, miniCtl = 0;
unsigned long hqvCtl = 0;
unsigned long hqvFilterCtl = 0, hqvMiniCtl = 0;
unsigned long hqvScaleCtlH = 0, hqvScaleCtlV = 0;
unsigned long haveHQVzoomH = 0, haveHQVzoomV = 0;
unsigned long hqvSrcWidth = 0, hqvDstWidth = 0;
unsigned long hqvSrcFetch = 0, hqvOffset = 0;
unsigned long dwOffset = 0, fetch = 0, tmp = 0;
unsigned long proReg = 0;
DBG_DD(ErrorF("videoflag=%ld\n", videoFlag));
if (pVia->ChipId == PCI_CHIP_VT3259 && !(videoFlag & VIDEO_1_INUSE))
proReg = PRO_HQV1_OFFSET;
compose = ((VIDInD(V_COMPOSE_MODE)
& ~(SELECT_VIDEO_IF_COLOR_KEY
| V1_COMMAND_FIRE | V3_COMMAND_FIRE))
| V_COMMAND_LOAD_VBI);
DBG_DD(ErrorF("// Upd_Video:\n"));
DBG_DD(ErrorF("Modified rSrc X (%ld,%ld) Y (%ld,%ld)\n",
pUpdate->SrcLeft, pUpdate->SrcRight,
pUpdate->SrcTop, pUpdate->SrcBottom));
DBG_DD(ErrorF("Modified rDest X (%ld,%ld) Y (%ld,%ld)\n",
pUpdate->DstLeft, pUpdate->DstRight,
pUpdate->DstTop, pUpdate->DstBottom));
dstWidth = pUpdate->DstRight - pUpdate->DstLeft;
if (pBIOSInfo->Panel->IsActive && pBIOSInfo->Panel->Scale) {
/* FIXME: We need to determine if the panel is using V1 or V3 */
float hfactor = (float)pBIOSInfo->Panel->NativeMode->Width
/ pScrn->currentMode->HDisplay;
dstWidth *= hfactor;
}
pVia->swov.overlayRecordV1.dwWidth = dstWidth;
pVia->swov.overlayRecordV1.dwHeight = dstHeight =
pUpdate->DstBottom - pUpdate->DstTop;
srcWidth = (unsigned long)pUpdate->SrcRight - pUpdate->SrcLeft;
srcHeight = (unsigned long)pUpdate->SrcBottom - pUpdate->SrcTop;
DBG_DD(ErrorF("===srcWidth= %ld \n", srcWidth));
DBG_DD(ErrorF("===srcHeight= %ld \n", srcHeight));
vidCtl = ViaSetVidCtl(pVia, videoFlag);
if (hwDiff->dwNeedV1Prefetch) {
DBG_DD(ErrorF("NEEDV1PREFETCH\n"));
vidCtl |= V1_PREFETCH_ON_3336;
}
/*
* FIXME:
* Enable video on secondary (change Panel to SecondCRTC?)
*/
if ((pVia->VideoEngine == VIDEO_ENGINE_CME
|| pVia->Chipset == VIA_VM800)
&& (pBIOSInfo->SecondCRTC->IsActive==TRUE)) {
/* VAL_VIDEO_ON_SND_DISPLAY */
vidCtl |= V1_ON_SND_DISPLAY;
/* SECOND_DISPLAY_COLOR_KEY_ENABLE */
compose |= SECOND_DISPLAY_COLOR_KEY_ENABLE | 0x1;
}
viaOverlayGetV1V3Format(pVia, (videoFlag & VIDEO_1_INUSE) ? 1 : 3,
videoFlag, &vidCtl, &hqvCtl);
if (hwDiff->dwThreeHQVBuffer) { /* CLE_C0: HQV supports triple-buffering */
hqvCtl &= ~HQV_SW_FLIP;
hqvCtl |= HQV_TRIPLE_BUFF | HQV_FLIP_STATUS;
}
/* Starting address of source and Source offset */
dwOffset = viaOverlayGetSrcStartAddress(pVia, videoFlag, pUpdate,
srcPitch, &hqvOffset);
DBG_DD(ErrorF("===dwOffset= 0x%lx \n", dwOffset));
pVia->swov.overlayRecordV1.dwOffset = dwOffset;
if (pVia->swov.SrcFourCC == FOURCC_YV12
|| pVia->swov.SrcFourCC == FOURCC_I420
|| pVia->swov.SrcFourCC == FOURCC_XVMC) {
YCBCRREC YCbCr;
if (videoFlag & VIDEO_HQV_INUSE) {
SetVideoStart(pVia, videoFlag, hwDiff->dwThreeHQVBuffer ? 3 : 2,
pVia->swov.overlayRecordV1.dwHQVAddr[0] + dwOffset,
pVia->swov.overlayRecordV1.dwHQVAddr[1] + dwOffset,
pVia->swov.overlayRecordV1.dwHQVAddr[2] + dwOffset);
if (pVia->swov.SrcFourCC != FOURCC_XVMC) {
YCbCr = viaOverlayGetYCbCrStartAddress(videoFlag, startAddr,
pVia->swov.overlayRecordV1.dwOffset,
pVia->swov.overlayRecordV1.dwUVoffset,
srcPitch, oriSrcHeight);
if (pVia->VideoEngine == VIDEO_ENGINE_CME) {
SaveVideoRegister(pVia, HQV_SRC_STARTADDR_Y + proReg,
YCbCr.dwY);
SaveVideoRegister(pVia, HQV_SRC_STARTADDR_U + proReg,
YCbCr.dwCB);
} else {
SaveVideoRegister(pVia, HQV_SRC_STARTADDR_Y, YCbCr.dwY);
SaveVideoRegister(pVia, HQV_SRC_STARTADDR_U, YCbCr.dwCR);
SaveVideoRegister(pVia, HQV_SRC_STARTADDR_V, YCbCr.dwCB);
}
}
} else {
YCbCr = viaOverlayGetYCbCrStartAddress(videoFlag, startAddr,
pVia->swov.overlayRecordV1.dwOffset,
pVia->swov.overlayRecordV1.dwUVoffset,
srcPitch, oriSrcHeight);
if (videoFlag & VIDEO_1_INUSE) {
SaveVideoRegister(pVia, V1_STARTADDR_0, YCbCr.dwY);
SaveVideoRegister(pVia, V1_STARTADDR_CB0, YCbCr.dwCR);
SaveVideoRegister(pVia, V1_STARTADDR_CR0, YCbCr.dwCB);
} else
DBG_DD(ErrorF("Upd_Video(): "
"We do not support YV12 with V3!\n"));
}
} else {
if (videoFlag & VIDEO_HQV_INUSE) {
hqvSrcWidth = (unsigned long)pUpdate->SrcRight - pUpdate->SrcLeft;
hqvDstWidth = (unsigned long)pUpdate->DstRight - pUpdate->DstLeft;
if (hqvSrcWidth > hqvDstWidth)
dwOffset = dwOffset * hqvDstWidth / hqvSrcWidth;
SetVideoStart(pVia, videoFlag, hwDiff->dwThreeHQVBuffer ? 3 : 2,
pVia->swov.overlayRecordV1.dwHQVAddr[0] + hqvOffset,
pVia->swov.overlayRecordV1.dwHQVAddr[1] + hqvOffset,
pVia->swov.overlayRecordV1.dwHQVAddr[2] + hqvOffset);
if (pVia->VideoEngine == VIDEO_ENGINE_CME)
SaveVideoRegister(pVia, 0x1cc + proReg, dwOffset);
SaveVideoRegister(pVia, HQV_SRC_STARTADDR_Y + proReg, startAddr);
} else {
startAddr += dwOffset;
SetVideoStart(pVia, videoFlag, 1, startAddr, 0, 0);
}
}
fetch = viaOverlayGetFetch(pVia, videoFlag,
srcWidth, dstWidth, oriSrcWidth, &hqvSrcFetch);
DBG_DD(ErrorF("===fetch= 0x%lx\n", fetch));
#if 0
/* For DCT450 test-BOB INTERLEAVE */
if ((deinterlaceMode & DDOVER_INTERLEAVED)
&& (deinterlaceMode & DDOVER_BOB)) {
if (videoFlag & VIDEO_HQV_INUSE)
hqvCtl |= HQV_FIELD_2_FRAME | HQV_FRAME_2_FIELD | HQV_DEINTERLACE;
else
vidCtl |= V1_BOB_ENABLE | V1_FRAME_BASE;
} else if (deinterlaceMode & DDOVER_BOB) {
if (videoFlag & VIDEO_HQV_INUSE)
/* The HQV source data line count should be two times of the original line count */
hqvCtl |= HQV_FIELD_2_FRAME | HQV_DEINTERLACE;
else
vidCtl |= V1_BOB_ENABLE;
}
#endif
if (videoFlag & VIDEO_HQV_INUSE) {
if (!(deinterlaceMode & DDOVER_INTERLEAVED)
&& (deinterlaceMode & DDOVER_BOB))
SetHQVFetch(pVia, hqvSrcFetch, oriSrcHeight << 1);
else
SetHQVFetch(pVia, hqvSrcFetch, oriSrcHeight);
if (pVia->swov.SrcFourCC == FOURCC_YV12
|| pVia->swov.SrcFourCC == FOURCC_I420
|| pVia->swov.SrcFourCC == FOURCC_XVMC) {
if (videoFlag & VIDEO_1_INUSE)
SaveVideoRegister(pVia, V1_STRIDE, srcPitch << 1);
else
SaveVideoRegister(pVia, V3_STRIDE, srcPitch << 1);
if (pVia->HWDiff.dwHQVFetchByteUnit)
SaveVideoRegister(pVia, HQV_SRC_STRIDE + proReg,
((srcPitch >> 1) << 16) | srcPitch |
HQV_FIFO_DEPTH_1);
else
SaveVideoRegister(pVia, HQV_SRC_STRIDE + proReg,
((srcPitch >> 1) << 16) | srcPitch);
SaveVideoRegister(pVia, HQV_DST_STRIDE + proReg, (srcPitch << 1));
} else {
if (videoFlag & VIDEO_1_INUSE)
SaveVideoRegister(pVia, V1_STRIDE, srcPitch);
else
SaveVideoRegister(pVia, V3_STRIDE, srcPitch);
SaveVideoRegister(pVia, HQV_SRC_STRIDE + proReg, srcPitch);
SaveVideoRegister(pVia, HQV_DST_STRIDE + proReg, srcPitch);
}
} else {
if (videoFlag & VIDEO_1_INUSE)
SaveVideoRegister(pVia, V1_STRIDE, srcPitch | (srcPitch << 15));
else
SaveVideoRegister(pVia, V3_STRIDE, srcPitch | (srcPitch << 15));
}
/* Set destination window */
SetVideoWindow(pScrn, videoFlag, pUpdate);
compose |= ALWAYS_SELECT_VIDEO;
/* Set up X zoom factor */
pVia->swov.overlayRecordV1.dwFetchAlignment = 0;
if (!viaOverlayHQVCalcZoomWidth(pVia, videoFlag, srcWidth, dstWidth,
&zoomCtl, &miniCtl, &hqvFilterCtl,
&hqvMiniCtl, &hqvScaleCtlH, &haveHQVzoomH)) {
/* Need to scale (minify) too much - can't handle it. */
SetFetch(pVia, videoFlag, fetch);
FireVideoCommand(pVia, videoFlag, compose);
FlushVidRegBuffer(pVia);
return FALSE;
}
SetFetch(pVia, videoFlag, fetch);
/* Set up Y zoom factor */
/* For DCT450 test-BOB INTERLEAVE */
if ((deinterlaceMode & DDOVER_INTERLEAVED)
&& (deinterlaceMode & DDOVER_BOB)) {
if (!(videoFlag & VIDEO_HQV_INUSE)) {
srcHeight /= 2;
if (videoFlag & VIDEO_1_INUSE)
vidCtl |= V1_BOB_ENABLE | V1_FRAME_BASE;
else
vidCtl |= V3_BOB_ENABLE | V3_FRAME_BASE;
} else
hqvCtl |= HQV_FIELD_2_FRAME | HQV_FRAME_2_FIELD | HQV_DEINTERLACE;
} else if (deinterlaceMode & DDOVER_BOB) {
if (videoFlag & VIDEO_HQV_INUSE) {
srcHeight <<= 1;
hqvCtl |= HQV_FIELD_2_FRAME | HQV_DEINTERLACE;
} else {
if (videoFlag & VIDEO_1_INUSE)
vidCtl |= V1_BOB_ENABLE;
else
vidCtl |= V3_BOB_ENABLE;
}
}
SetDisplayCount(pVia, videoFlag, srcWidth, srcHeight);
if (!viaOverlayHQVCalcZoomHeight(pVia, srcHeight, dstHeight, &zoomCtl,
&miniCtl, &hqvFilterCtl, &hqvMiniCtl,
&hqvScaleCtlV, &haveHQVzoomV)) {
/* Need to scale (minify) too much - can't handle it. */
FireVideoCommand(pVia, videoFlag, compose);
FlushVidRegBuffer(pVia);
return FALSE;
}
SetupFIFOs(pVia, videoFlag, miniCtl, srcWidth);
if (videoFlag & VIDEO_HQV_INUSE) {
miniCtl = 0;
if (haveHQVzoomH || haveHQVzoomV) {
tmp = 0;
if (haveHQVzoomH) {
miniCtl = V1_X_INTERPOLY;
/* Disable X interpolation if the height exceeds
* the maximum supported by the hardware */
if (srcHeight >= pVia->swov.maxHInterp)
miniCtl &= ~V1_X_INTERPOLY;
tmp = zoomCtl & 0xffff0000;
}
if (haveHQVzoomV) {
miniCtl |= V1_Y_INTERPOLY | V1_YCBCR_INTERPOLY;
/* Disable Y interpolation if the width exceeds
* the maximum supported by the hardware */
if (srcWidth >= pVia->swov.maxWInterp)
miniCtl &= ~V1_Y_INTERPOLY;
tmp |= zoomCtl & 0x0000ffff;
hqvFilterCtl &= 0xfffdffff;
}
/* Temporary fix for 2D bandwidth problem. 2002/08/01 */
if (pVia->swov.gdwUseExtendedFIFO)
miniCtl &= ~V1_Y_INTERPOLY;
SetMiniAndZoom(pVia, videoFlag, miniCtl, tmp);
} else {
if (srcHeight == dstHeight)
hqvFilterCtl &= 0xfffdffff;
SetMiniAndZoom(pVia, videoFlag, 0, 0);
}
if (hwDiff->dwNewScaleCtl) {
SaveVideoRegister(pVia, HQV_H_SCALE_CONTROL + proReg, hqvScaleCtlH);
SaveVideoRegister(pVia, HQV_V_SCALE_CONTROL + proReg, hqvScaleCtlV);
} else {
SaveVideoRegister(pVia, HQV_MINIFY_CONTROL + proReg, hqvMiniCtl);
}
SaveVideoRegister(pVia, HQV_FILTER_CONTROL + proReg, hqvFilterCtl);
} else
SetMiniAndZoom(pVia, videoFlag, miniCtl, zoomCtl);
if (haveColorKey)
compose = SetColorKey(pVia, videoFlag, colorKeyLow, colorKeyHigh,
compose);
if (haveChromaKey)
compose = SetChromaKey(pVia, videoFlag, chromaKeyLow, chromaKeyHigh,
miniCtl, compose);
if (pVia->VideoEngine == VIDEO_ENGINE_CME) {
SaveVideoRegister(pVia, HQV_CME_REG(hwDiff, HQV_SDO_CTRL1),0);
SaveVideoRegister(pVia, HQV_CME_REG(hwDiff, HQV_SDO_CTRL3),((pUpdate->SrcRight - 1 ) << 16) | (pUpdate->SrcBottom - 1));
if ((pVia->Chipset == VIA_VX800) ||
(pVia->Chipset == VIA_VX855) ||
(pVia->Chipset == VIA_VX900)) {
SaveVideoRegister(pVia, HQV_CME_REG(hwDiff, HQV_SDO_CTRL2),0);
SaveVideoRegister(pVia, HQV_CME_REG(hwDiff, HQV_SDO_CTRL4),((pUpdate->SrcRight - 1 ) << 16) | (pUpdate->SrcBottom - 1));
if ((pVia->Chipset == VIA_VX855) ||
(pVia->Chipset == VIA_VX900)) {
SaveVideoRegister(pVia, HQV_DST_DATA_OFFSET_CTRL1,0);
SaveVideoRegister(pVia, HQV_DST_DATA_OFFSET_CTRL3,((pUpdate->SrcRight - 1 ) << 16) | (pUpdate->SrcBottom - 1));
SaveVideoRegister(pVia, HQV_DST_DATA_OFFSET_CTRL2,0);
SaveVideoRegister(pVia, HQV_DST_DATA_OFFSET_CTRL4,((pUpdate->SrcRight - 1 ) << 16) | (pUpdate->SrcBottom - 1));
SaveVideoRegister(pVia, HQV_BACKGROUND_DATA_OFFSET,((pUpdate->SrcRight - 1 ) << 16) | (pUpdate->SrcBottom - 1));
SaveVideoRegister(pVia, HQV_EXTENDED_CONTROL,0);
/*0x3e0*/
SaveVideoRegister(pVia, HQV_SUBP_HSCALE_CTRL,0);
/*0x3e8*/
SaveVideoRegister(pVia, HQV_SUBP_VSCALE_CTRL,0);
}
if (pVia->Chipset == VIA_VX900) {
SaveVideoRegister(pVia, HQV_SHARPNESS_DECODER_HANDSHAKE_CTRL_410, 0);
}
// TODO Need to be tested on VX800
/* 0x3B8 */
SaveVideoRegister(pVia, HQV_DEFAULT_VIDEO_COLOR, HQV_FIX_COLOR);
}
}
/* Set up video control */
if (videoFlag & VIDEO_HQV_INUSE) {
if (!pVia->swov.SWVideo_ON) {
DBG_DD(ErrorF(" First HQV\n"));
FlushVidRegBuffer(pVia);
DBG_DD(ErrorF(" Wait flips"));
if (hwDiff->dwHQVInitPatch) {
DBG_DD(ErrorF(" Initializing HQV twice ..."));
for (i = 0; i < 2; i++) {
viaWaitHQVFlipClear(pVia,
((hqvCtl & ~HQV_SW_FLIP) |
HQV_FLIP_STATUS) & ~HQV_ENABLE);
VIDOutD(HQV_CONTROL + proReg, hqvCtl);
viaWaitHQVFlip(pVia);
}
DBG_DD(ErrorF(" done.\n"));
} else { /* CLE_C0 */
CARD32 volatile *HQVCtrl =
(CARD32 volatile *)(pVia->VidMapBase + HQV_CONTROL +
proReg);
/* Check that HQV is idle */
DBG_DD(ErrorF("HQV control wf - %08lx\n", *HQVCtrl));
while (!(*HQVCtrl & HQV_IDLE)) {
DBG_DD(ErrorF("HQV control busy - %08lx\n", *HQVCtrl));
usleep(1);
}
VIDOutD(HQV_CONTROL + proReg, hqvCtl & ~HQV_SW_FLIP);
VIDOutD(HQV_CONTROL + proReg, hqvCtl | HQV_SW_FLIP);
DBG_DD(ErrorF("HQV control wf5 - %08lx\n", *HQVCtrl));
DBG_DD(ErrorF(" Wait flips5"));
if (pVia->VideoEngine != VIDEO_ENGINE_CME) {
for (i = 0; (i < 50) && !(*HQVCtrl & HQV_FLIP_STATUS);
i++) {
DBG_DD(ErrorF(" HQV wait %d %08lx\n", i, *HQVCtrl));
*HQVCtrl |= HQV_SW_FLIP | HQV_FLIP_STATUS;
usleep(1);
}
} else {
viaWaitHQVFlip(pVia);
}
DBG_DD(ErrorF(" Wait flips6"));
}
if (videoFlag & VIDEO_1_INUSE) {
VIDOutD(V1_CONTROL, vidCtl);
VIDOutD(V_COMPOSE_MODE, compose | V1_COMMAND_FIRE);
if (pVia->swov.gdwUseExtendedFIFO) {
/* Set Display FIFO */
DBG_DD(ErrorF(" Wait flips7"));
viaWaitVBI(pVia);
DBG_DD(ErrorF(" Wait flips 8"));
hwp->writeSeq(hwp, 0x17, 0x2F);
ViaSeqMask(hwp, 0x16, 0x14, 0x1F);
hwp->writeSeq(hwp, 0x18, 0x56);
DBG_DD(ErrorF(" Wait flips 9"));
}
} else {
DBG_DD(ErrorF(" Wait flips 10"));
VIDOutD(V3_CONTROL, vidCtl);
VIDOutD(V_COMPOSE_MODE, compose | V3_COMMAND_FIRE);
}
DBG_DD(ErrorF(" Done flips"));
} else {
DBG_DD(ErrorF(" Normal called\n"));
SaveVideoRegister(pVia, HQV_CONTROL + proReg,
hqvCtl | HQV_FLIP_STATUS);
SetVideoControl(pVia, videoFlag, vidCtl);
FireVideoCommand(pVia, videoFlag, compose);
viaWaitHQVDone(pVia);
FlushVidRegBuffer(pVia);
}
} else {
SetVideoControl(pVia, videoFlag, vidCtl);
FireVideoCommand(pVia, videoFlag, compose);
viaWaitHQVDone(pVia);
FlushVidRegBuffer(pVia);
}
pVia->swov.SWVideo_ON = TRUE;
DBG_DD(ErrorF(" Done Upd_Video"));
return TRUE;
} /* Upd_Video */
/*
* VIAVidUpdateOverlay()
* Parameters: src rectangle, dst rectangle, colorkey...
* Return value: unsigned long of state
* Note: updates the overlay image parameter.
*/
Bool
VIAVidUpdateOverlay(ScrnInfoPtr pScrn, LPDDUPDATEOVERLAY pUpdate)
{
VIAPtr pVia = VIAPTR(pScrn);
OVERLAYRECORD *ovlV1 = &pVia->swov.overlayRecordV1;
unsigned long flags = pUpdate->dwFlags;
unsigned long videoFlag = 0;
unsigned long startAddr = 0;
unsigned long deinterlaceMode = 0;
unsigned long haveColorKey = 0, haveChromaKey = 0;
unsigned long colorKeyLow = 0, colorKeyHigh = 0;
unsigned long chromaKeyLow = 0, chromaKeyHigh = 0;
unsigned long scrnWidth, scrnHeight;
int dstTop, dstBottom, dstLeft, dstRight;
int panDX, panDY; /* Panning delta */
unsigned long proReg = 0;
panDX = pVia->swov.panning_x;
panDY = pVia->swov.panning_y;
pVia->swov.oldPanningX = pVia->swov.panning_x;
pVia->swov.oldPanningY = pVia->swov.panning_y;
pUpdate->DstLeft -= panDX;
pUpdate->DstTop -= panDY;
pUpdate->DstRight -= panDX;
pUpdate->DstBottom -= panDY;
DBG_DD(ErrorF("Raw rSrc X (%ld,%ld) Y (%ld,%ld)\n",
pUpdate->SrcLeft, pUpdate->SrcRight,
pUpdate->SrcTop, pUpdate->SrcBottom));
DBG_DD(ErrorF("Raw rDest X (%ld,%ld) Y (%ld,%ld)\n",
pUpdate->DstLeft, pUpdate->DstRight,
pUpdate->DstTop, pUpdate->DstBottom));
if ((pVia->swov.SrcFourCC == FOURCC_YUY2) ||
(pVia->swov.SrcFourCC == FOURCC_RV15) ||
(pVia->swov.SrcFourCC == FOURCC_RV16) ||
(pVia->swov.SrcFourCC == FOURCC_RV32) ||
(pVia->swov.SrcFourCC == FOURCC_YV12) ||
(pVia->swov.SrcFourCC == FOURCC_I420) ||
(pVia->swov.SrcFourCC == FOURCC_XVMC)) {
videoFlag = pVia->swov.gdwVideoFlagSW;
}
if (pVia->ChipId == PCI_CHIP_VT3259 && !(videoFlag & VIDEO_1_INUSE))
proReg = PRO_HQV1_OFFSET;
flags |= DDOVER_INTERLEAVED;
/* Disable destination color keying if the alpha window is in use. */
if (pVia->swov.gdwAlphaEnabled)
flags &= ~DDOVER_KEYDEST;
ResetVidRegBuffer(pVia);
/* For SW decode HW overlay use */
startAddr = VIDInD(HQV_SRC_STARTADDR_Y + proReg);
if (flags & DDOVER_KEYDEST) {
haveColorKey = 1;
colorKeyLow = pUpdate->dwColorSpaceLowValue;
}
if (flags & DDOVER_INTERLEAVED)
deinterlaceMode |= DDOVER_INTERLEAVED;
if (flags & DDOVER_BOB)
deinterlaceMode |= DDOVER_BOB;
if ((pVia->ChipId == PCI_CHIP_CLE3122)
&& (pScrn->currentMode->HDisplay > 1024)) {
DBG_DD(ErrorF("UseExtendedFIFO\n"));
pVia->swov.gdwUseExtendedFIFO = 1;
} else
pVia->swov.gdwUseExtendedFIFO = 0;
/* Figure out actual rSrc rectangle */
dstLeft = pUpdate->DstLeft;
dstTop = pUpdate->DstTop;
dstRight = pUpdate->DstRight;
dstBottom = pUpdate->DstBottom;
scrnWidth = pScrn->currentMode->HDisplay;
scrnHeight = pScrn->currentMode->VDisplay;
if (dstLeft < 0) {
pUpdate->SrcLeft = ((((-dstLeft) * ovlV1->dwV1OriWidth) +
((dstRight - dstLeft) >> 1))
/ (dstRight - dstLeft));
}
if (dstRight > scrnWidth) {
pUpdate->SrcRight = ((((scrnWidth - dstLeft) * ovlV1->dwV1OriWidth) +
((dstRight - dstLeft) >> 1))
/ (dstRight - dstLeft));
}
if (dstTop < 0) {
pUpdate->SrcTop = ((((-dstTop) * ovlV1->dwV1OriHeight) +
((dstBottom - dstTop) >> 1))
/ (dstBottom - dstTop));
}
if (dstBottom > scrnHeight) {
pUpdate->SrcBottom = ((((scrnHeight - dstTop) * ovlV1->dwV1OriHeight) +
((dstBottom - dstTop) >> 1))
/ (dstBottom - dstTop));
}
/* Save modified src & original dest rectangle parameters */
if ((pVia->swov.SrcFourCC == FOURCC_YUY2) ||
(pVia->swov.SrcFourCC == FOURCC_RV15) ||
(pVia->swov.SrcFourCC == FOURCC_RV16) ||
(pVia->swov.SrcFourCC == FOURCC_RV32) ||
(pVia->swov.SrcFourCC == FOURCC_YV12) ||
(pVia->swov.SrcFourCC == FOURCC_I420) ||
(pVia->swov.SrcFourCC == FOURCC_XVMC)) {
pVia->swov.SWDevice.gdwSWDstLeft = pUpdate->DstLeft + panDX;
pVia->swov.SWDevice.gdwSWDstTop = pUpdate->DstTop + panDY;
pVia->swov.SWDevice.gdwSWDstWidth =
pUpdate->DstRight - pUpdate->DstLeft;
pVia->swov.SWDevice.gdwSWDstHeight =
pUpdate->DstBottom - pUpdate->DstTop;
pVia->swov.SWDevice.gdwSWSrcWidth = ovlV1->dwV1SrcWidth =
pUpdate->SrcRight - pUpdate->SrcLeft;
pVia->swov.SWDevice.gdwSWSrcHeight = ovlV1->dwV1SrcHeight =
pUpdate->SrcBottom - pUpdate->SrcTop;
}
ovlV1->dwV1SrcLeft = pUpdate->SrcLeft;
ovlV1->dwV1SrcRight = pUpdate->SrcRight;
ovlV1->dwV1SrcTop = pUpdate->SrcTop;
ovlV1->dwV1SrcBot = pUpdate->SrcBottom;
/* Figure out actual rDest rectangle */
pUpdate->DstLeft = (dstLeft < 0) ? 0 : dstLeft;
pUpdate->DstTop = (dstTop < 0) ? 0 : dstTop;
if (pUpdate->DstTop >= scrnHeight)
pUpdate->DstTop = scrnHeight - 1;
pUpdate->DstRight = (dstRight > scrnWidth) ? scrnWidth : dstRight;
pUpdate->DstBottom = (dstBottom > scrnHeight) ? scrnHeight : dstBottom;
/* Update the overlay */
if (!Upd_Video(pScrn, videoFlag, startAddr, pUpdate,
pVia->swov.SWDevice.dwPitch, ovlV1->dwV1OriWidth,
ovlV1->dwV1OriHeight, deinterlaceMode, haveColorKey,
haveChromaKey, colorKeyLow, colorKeyHigh, chromaKeyLow,
chromaKeyHigh))
return FALSE;
pVia->swov.SWVideo_ON = FALSE;
return TRUE;
} /* VIAVidUpdateOverlay */
/*
*
*/
void
ViaOverlayHide(ScrnInfoPtr pScrn)
{
VIAPtr pVia = VIAPTR(pScrn);
vgaHWPtr hwp = VGAHWPTR(pScrn);
CARD32 videoFlag = 0;
unsigned long proReg = 0;
if ((pVia->swov.SrcFourCC == FOURCC_YUY2) ||
(pVia->swov.SrcFourCC == FOURCC_RV15) ||
(pVia->swov.SrcFourCC == FOURCC_RV16) ||
(pVia->swov.SrcFourCC == FOURCC_RV32) ||
(pVia->swov.SrcFourCC == FOURCC_YV12) ||
(pVia->swov.SrcFourCC == FOURCC_I420) ||
(pVia->swov.SrcFourCC == FOURCC_XVMC))
videoFlag = pVia->swov.gdwVideoFlagSW;
if (pVia->ChipId == PCI_CHIP_VT3259 && !(videoFlag & VIDEO_1_INUSE))
proReg = PRO_HQV1_OFFSET;
ResetVidRegBuffer(pVia);
if (pVia->HWDiff.dwHQVDisablePatch)
ViaSeqMask(hwp, 0x2E, 0x00, 0x10);
SaveVideoRegister(pVia, V_FIFO_CONTROL, V1_FIFO_PRETHRESHOLD12 |
V1_FIFO_THRESHOLD8 | V1_FIFO_DEPTH16);
SaveVideoRegister(pVia, ALPHA_V3_FIFO_CONTROL,
ALPHA_FIFO_THRESHOLD4 | ALPHA_FIFO_DEPTH8 |
V3_FIFO_THRESHOLD24 | V3_FIFO_DEPTH32);
if (videoFlag & VIDEO_HQV_INUSE)
SaveVideoRegister(pVia, HQV_CONTROL + proReg,
VIDInD(HQV_CONTROL + proReg) & ~HQV_ENABLE);
if (videoFlag & VIDEO_1_INUSE)
SaveVideoRegister(pVia, V1_CONTROL, VIDInD(V1_CONTROL) & ~V1_ENABLE);
else
SaveVideoRegister(pVia, V3_CONTROL, VIDInD(V3_CONTROL) & ~V3_ENABLE);
FireVideoCommand(pVia, videoFlag, VIDInD(V_COMPOSE_MODE));
FlushVidRegBuffer(pVia);
if (pVia->HWDiff.dwHQVDisablePatch)
ViaSeqMask(hwp, 0x2E, 0x10, 0x10);
pVia->swov.SWVideo_ON = FALSE;
pVia->VideoStatus &= ~VIDEO_SWOV_ON;
}
|