summaryrefslogtreecommitdiff
path: root/src/gfx/disp_gu2.c
blob: 381b4ef40aabaef9ba646f7ade5cb397874c8fb5 (plain)
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
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
/* Copyright (c) 2005 Advanced Micro Devices, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 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.
 *
 * Neither the name of the Advanced Micro Devices, Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from this
 * software without specific prior written permission.
 */

/* 
 * This file contains routines for the second generation display controller.
 * */

void gu2_enable_compression(void);      /* private routine definition */
void gu2_disable_compression(void);     /* private routine definition */
int gu2_set_specified_mode(DISPLAYMODE * pMode, int bpp);

 /*---------------------------------------------------------------------------
 * WARNING!!!! INACCURATE DELAY MECHANISM
 *
 * In an effort to keep the code self contained and operating system 
 * independent, the delay loop just performs reads of a display controller
 * register.  This time will vary for faster processors.  The delay can always
 * be longer than intended, only effecting the time of the mode switch 
 * (obviously want it to still be under a second).  Problems with the hardware
 * only arise if the delay is not long enough.  
 *----------------------------------------------------------------------------
 */
#define RC_READS_PER_MILLISECOND 15000L

#if GFX_DISPLAY_DYNAMIC
void
gu2_delay_milliseconds(unsigned long milliseconds)
#else
void
gfx_delay_milliseconds(unsigned long milliseconds)
#endif
{
    /* ASSUME 300 MHZ 20 CLOCKS PER READ */
    unsigned long loop;

    loop = milliseconds * RC_READS_PER_MILLISECOND;
    while (loop-- > 0) {
        READ_REG32(MDC_UNLOCK);
    }
}

#if GFX_DISPLAY_DYNAMIC
void
gu2_delay_microseconds(unsigned long microseconds)
#else
void
gfx_delay_microseconds(unsigned long microseconds)
#endif
{
    /* ASSUME 400 MHz, 2 CLOCKS PER INCREMENT */
    unsigned long loop_count = microseconds * 15;

    while (loop_count-- > 0) {
        READ_REG32(MDC_UNLOCK);
    }
}

/*----------------------------------------------------------------------------
 * GFX_SET_DISPLAY_BPP
 *
 * This routine programs the bpp in the display controller.
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_set_display_bpp(unsigned short bpp)
#else
int
gfx_set_display_bpp(unsigned short bpp)
#endif
{
    unsigned long dcfg, lock;

    dcfg =
        READ_REG32(MDC_DISPLAY_CFG) & ~(MDC_DCFG_DISP_MODE_MASK |
                                        MDC_DCFG_16BPP_MODE_MASK);
    lock = READ_REG32(MDC_UNLOCK);

    switch (bpp) {
    case 12:
        dcfg |= (MDC_DCFG_DISP_MODE_16BPP | MDC_DCFG_12BPP);
        break;
    case 15:
        dcfg |= (MDC_DCFG_DISP_MODE_16BPP | MDC_DCFG_15BPP);
        break;
    case 16:
        dcfg |= (MDC_DCFG_DISP_MODE_16BPP | MDC_DCFG_16BPP);
        break;
    case 32:
        dcfg |= (MDC_DCFG_DISP_MODE_24BPP);
        break;
    case 8:
        dcfg |= (MDC_DCFG_DISP_MODE_8BPP);
        break;
    default:
        return GFX_STATUS_BAD_PARAMETER;
    }

    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);
    WRITE_REG32(MDC_DISPLAY_CFG, dcfg);
    WRITE_REG32(MDC_UNLOCK, lock);

    /* SET BPP IN GRAPHICS PIPELINE */
    gfx_set_bpp(bpp);

    return 0;
}

/*----------------------------------------------------------------------------
 * gu2_set_specified_mode (private routine)
 * This routine uses the parameters in the specified display mode structure
 * to program the display controller hardware.  
 *----------------------------------------------------------------------------
 */
int
gu2_set_specified_mode(DISPLAYMODE * pMode, int bpp)
{
    unsigned long unlock, value;
    unsigned long gcfg, dcfg;
    unsigned long size, pitch;
    unsigned long vid_buf_size;
    unsigned long bpp_mask, temp, dv_size;

    /* CHECK WHETHER TIMING CHANGE IS ALLOWED */
    /* Flag used for locking also overrides timing change restriction */
    if (gfx_timing_lock && !(pMode->flags & GFX_MODE_LOCK_TIMING))
        return GFX_STATUS_ERROR;

    /* CLEAR PANNING OFFSETS */
    DeltaX = 0;
    DeltaY = 0;
    panelLeft = 0;
    panelTop = 0;

    /* SET GLOBAL FLAG */

    if (pMode->flags & GFX_MODE_LOCK_TIMING)
        gfx_timing_lock = 1;

    /* CHECK FOR VALID BPP                          */
    /* As this function can be called directly from */
    /* gfx_set_display_timings, we must correct any */
    /* invalid bpp settings.                        */
    switch (bpp) {
    case 12:
        bpp_mask = 0x00000900;
        break;
    case 15:
        bpp_mask = 0x00000500;
        break;
    case 16:
        bpp_mask = 0x00000100;
        break;
    case 32:
        bpp_mask = 0x00000200;
        break;
    default:
        bpp_mask = 0x00000000;
        bpp = 8;
        break;
    }

    gbpp = bpp;

    /* DISABLE COMPRESSION */
    gu2_disable_compression();

    /* ALSO DISABLE VIDEO */
    /* Use private "reset video" routine to do all that is needed. */
    /* SC1200, for example, also disables the alpha blending regions. */
    gfx_reset_video();

    /* UNLOCK THE DISPLAY CONTROLLER REGISTERS */
    unlock = READ_REG32(MDC_UNLOCK);
    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);

    /* READ THE CURRENT REGISTER VALUES */
    gcfg = READ_REG32(MDC_GENERAL_CFG);
    dcfg = READ_REG32(MDC_DISPLAY_CFG);

    /* BLANK THE DISPLAY IN THE DISPLAY FILTER */
    gfx_set_crt_enable(0);

    /* DISABLE THE TIMING GENERATOR */
    dcfg &= ~(unsigned long) MDC_DCFG_TGEN;
    WRITE_REG32(MDC_DISPLAY_CFG, dcfg);

    /* DELAY: WAIT FOR PENDING MEMORY REQUESTS                            */
    /* This delay is used to make sure that all pending requests to the   */
    /* memory controller have completed before disabling the FIFO load.   */
    gfx_delay_milliseconds(5);

    /* DISABLE DISPLAY FIFO LOAD */
    gcfg &= ~(unsigned long) MDC_GCFG_DFLE;
    WRITE_REG32(MDC_GENERAL_CFG, gcfg);

    /* PRESERVE VIDEO INFORMATION */
    gcfg &= (unsigned long) (MDC_GCFG_YUVM | MDC_GCFG_VDSE);
    dcfg = 0;

    /* SET THE DOT CLOCK FREQUENCY             */
    /* Mask off the divide by two bit (bit 31) */
    if (!(pMode->flags & GFX_MODE_EXCLUDE_PLL))
        gfx_set_clock_frequency(pMode->frequency & 0x7FFFFFFF);

    /* DELAY: WAIT FOR THE PLL TO SETTLE */
    /* This allows the dot clock frequency that was just set to settle. */
    gfx_delay_milliseconds(10);

    /* SET THE GX DISPLAY CONTROLLER PARAMETERS */
    WRITE_REG32(MDC_FB_ST_OFFSET, 0);
    WRITE_REG32(MDC_CB_ST_OFFSET, 0);
    WRITE_REG32(MDC_CURS_ST_OFFSET, 0);
    WRITE_REG32(MDC_ICON_ST_OFFSET, 0);

    /* SET LINE SIZE AND PITCH */
    /* 1. Flat Panels must use the mode width and not  */
    /*    the timing width to set the pitch.           */
    /* 2. Mode sets will use a pitch that is aligned   */
    /*    on a 1K boundary to preserve legacy.  The    */
    /*    pitch can be overridden by a subsequent call */
    /*    to gfx_set_display_pitch.                    */
    if (PanelEnable)
        size = ModeWidth;
    else
        size = pMode->hactive;

    if (bpp > 8)
        size <<= 1;

    if (bpp > 16)
        size <<= 1;

    pitch = 1024;
    dv_size = MDC_DV_LINE_SIZE_1024;

    if (size > 1024) {
        pitch = 2048;
        dv_size = MDC_DV_LINE_SIZE_2048;
    }

    if (size > 2048) {
        pitch = 4096;
        dv_size = MDC_DV_LINE_SIZE_4096;
    }

    if (size > 4096) {
        pitch = 8192;
        dv_size = MDC_DV_LINE_SIZE_8192;
    }

    WRITE_REG32(MDC_GFX_PITCH, pitch >> 3);

    /* WRITE DIRTY/VALID CONTROL WITH LINE LENGTH */
    temp = READ_REG32(MDC_DV_CTL);
    WRITE_REG32(MDC_DV_CTL, (temp & ~MDC_DV_LINE_SIZE_MASK) | dv_size);

    if (PanelEnable) {
        size = pMode->hactive;
        if (bpp > 8)
            size <<= 1;
        if (bpp > 16)
            size <<= 1;
    }

    /* SAVE PREVIOUSLY STORED VIDEO LINE SIZE */
    vid_buf_size = READ_REG32(MDC_LINE_SIZE) & 0xFF000000;

    /* ADD 2 TO SIZE FOR POSSIBLE START ADDRESS ALIGNMENTS */
    WRITE_REG32(MDC_LINE_SIZE, ((size >> 3) + 2) | vid_buf_size);

    /* ALWAYS ENABLE VIDEO AND GRAPHICS DATA            */
    /* These bits are relics from a previous design and */
    /* should always be enabled.                        */
    dcfg |= (unsigned long) (MDC_DCFG_VDEN | MDC_DCFG_GDEN);

    /* SET PIXEL FORMAT */
    dcfg |= bpp_mask;

    /* ENABLE TIMING GENERATOR, TIM. REG. UPDATES, PALETTE BYPASS */
    /* AND VERT. INT. SELECT                                      */
    dcfg |=
        (unsigned long) (MDC_DCFG_TGEN | MDC_DCFG_TRUP | MDC_DCFG_PALB |
                         MDC_DCFG_VISL);

    /* DISABLE ADDRESS MASKS */
    dcfg |= MDC_DCFG_A20M;
    dcfg |= MDC_DCFG_A18M;

    /* SET FIFO PRIORITIES AND DISPLAY FIFO LOAD ENABLE     */
    /* Set the priorities higher for high resolution modes. */
    if (pMode->hactive > 1024 || bpp == 32)
        gcfg |= 0x000A901;
    else
        gcfg |= 0x0006501;

    /* ENABLE FLAT PANEL CENTERING                          */
    /* For panel modes having a resolution smaller than the */
    /* panel resolution, turn on data centering.            */
    if (PanelEnable && ModeWidth < PanelWidth)
        dcfg |= MDC_DCFG_DCEN;

    /* COMBINE AND SET TIMING VALUES */
    value = (unsigned long) (pMode->hactive - 1) |
        (((unsigned long) (pMode->htotal - 1)) << 16);
    WRITE_REG32(MDC_H_ACTIVE_TIMING, value);
    value = (unsigned long) (pMode->hblankstart - 1) |
        (((unsigned long) (pMode->hblankend - 1)) << 16);
    WRITE_REG32(MDC_H_BLANK_TIMING, value);
    value = (unsigned long) (pMode->hsyncstart - 1) |
        (((unsigned long) (pMode->hsyncend - 1)) << 16);
    WRITE_REG32(MDC_H_SYNC_TIMING, value);
    value = (unsigned long) (pMode->vactive - 1) |
        (((unsigned long) (pMode->vtotal - 1)) << 16);
    WRITE_REG32(MDC_V_ACTIVE_TIMING, value);
    value = (unsigned long) (pMode->vblankstart - 1) |
        (((unsigned long) (pMode->vblankend - 1)) << 16);
    WRITE_REG32(MDC_V_BLANK_TIMING, value);
    value = (unsigned long) (pMode->vsyncstart - 1) |
        (((unsigned long) (pMode->vsyncend - 1)) << 16);
    WRITE_REG32(MDC_V_SYNC_TIMING, value);

    WRITE_REG32(MDC_DISPLAY_CFG, dcfg);
    WRITE_REG32(MDC_GENERAL_CFG, gcfg);

    /* CONFIGURE DISPLAY OUTPUT FROM VIDEO PROCESSOR */
    gfx_set_display_control(((pMode->flags & GFX_MODE_NEG_HSYNC) ? 1 : 0) |
                            ((pMode->flags & GFX_MODE_NEG_VSYNC) ? 2 : 0));

    /* RESTORE VALUE OF MDC_UNLOCK */
    WRITE_REG32(MDC_UNLOCK, unlock);

    /* RESET THE PITCH VALUES IN THE GP */
    gfx_reset_pitch((unsigned short) pitch);

    gfx_set_bpp((unsigned short) bpp);

    return GFX_STATUS_OK;
}

/*----------------------------------------------------------------------------
 * GFX_IS_DISPLAY_MODE_SUPPORTED
 *
 * This routine sets the specified display mode.
 *
 * Returns 1 if successful, 0 if mode could not be set.
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_is_display_mode_supported(int xres, int yres, int bpp, int hz)
#else
int
gfx_is_display_mode_supported(int xres, int yres, int bpp, int hz)
#endif
{
    unsigned int mode;
    unsigned long hz_flag = 0, bpp_flag = 0;

    /* SET FLAGS TO MATCH REFRESH RATE */
    gfx_mode_hz_conversion
        /* SET BPP FLAGS TO LIMIT MODE SELECTION */
        gfx_mode_bpp_conversion
        /* LOOP THROUGH THE AVAILABLE MODES TO FIND A MATCH */
        for (mode = 0; mode < NUM_RC_DISPLAY_MODES; mode++) {
        if ((DisplayParams[mode].hactive == (unsigned short) xres) &&
            (DisplayParams[mode].vactive == (unsigned short) yres) &&
            (DisplayParams[mode].flags & hz_flag) &&
            (DisplayParams[mode].flags & bpp_flag)) {

            /* REDCLOUD DOES NOT SUPPORT EMULATED VGA MODES */
            if ((DisplayParams[mode].flags & GFX_MODE_PIXEL_DOUBLE) ||
                (DisplayParams[mode].flags & GFX_MODE_LINE_DOUBLE))
                continue;

            /* SET THE DISPLAY CONTROLLER FOR THE SELECTED MODE */
            return (mode);
        }
    }
    return (-1);
}

/*----------------------------------------------------------------------------
 * gfx_set_display_mode
 *
 * This routine sets the specified display mode.
 *
 * Returns 1 if successful, 0 if mode could not be set.
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_set_display_mode(int xres, int yres, int bpp, int hz)
#else
int
gfx_set_display_mode(int xres, int yres, int bpp, int hz)
#endif
{
    int mode;

    /* DISABLE FLAT PANEL */
    /* Flat Panel settings are enabled by the function gfx_set_fixed_timings 
     * and disabled by gfx_set_display_mode.
     * */
    PanelEnable = 0;

    mode = gfx_is_display_mode_supported(xres, yres, bpp, hz);
    if (mode >= 0) {
        if (gu2_set_specified_mode(&DisplayParams[mode], bpp) == GFX_STATUS_OK)
            return (1);
    }
    return (0);
}

/*----------------------------------------------------------------------------
 * GFX_SET_DISPLAY_TIMINGS
 *
 * This routine sets the display controller mode using the specified timing
 * values (as opposed to using the tables internal to Durango).
 *
 * Returns GFX_STATUS_OK ON SUCCESS, GFX_STATUS_ERROR otherwise.
 *----------------------------------------------------------------------------  
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_set_display_timings(unsigned short bpp, unsigned short flags,
                        unsigned short hactive, unsigned short hblankstart,
                        unsigned short hsyncstart, unsigned short hsyncend,
                        unsigned short hblankend, unsigned short htotal,
                        unsigned short vactive, unsigned short vblankstart,
                        unsigned short vsyncstart, unsigned short vsyncend,
                        unsigned short vblankend, unsigned short vtotal,
                        unsigned long frequency)
#else
int
gfx_set_display_timings(unsigned short bpp, unsigned short flags,
                        unsigned short hactive, unsigned short hblankstart,
                        unsigned short hsyncstart, unsigned short hsyncend,
                        unsigned short hblankend, unsigned short htotal,
                        unsigned short vactive, unsigned short vblankstart,
                        unsigned short vsyncstart, unsigned short vsyncend,
                        unsigned short vblankend, unsigned short vtotal,
                        unsigned long frequency)
#endif
{
    /* SET MODE STRUCTURE WITH SPECIFIED VALUES */

    gfx_display_mode.flags = 0;
    if (flags & 1)
        gfx_display_mode.flags |= GFX_MODE_NEG_HSYNC;
    if (flags & 2)
        gfx_display_mode.flags |= GFX_MODE_NEG_VSYNC;
    if (flags & 4)
        gfx_display_mode.flags |= GFX_MODE_EXCLUDE_PLL;
    if (flags & 0x1000)
        gfx_display_mode.flags |= GFX_MODE_LOCK_TIMING;
    gfx_display_mode.hactive = hactive;
    gfx_display_mode.hblankstart = hblankstart;
    gfx_display_mode.hsyncstart = hsyncstart;
    gfx_display_mode.hsyncend = hsyncend;
    gfx_display_mode.hblankend = hblankend;
    gfx_display_mode.htotal = htotal;
    gfx_display_mode.vactive = vactive;
    gfx_display_mode.vblankstart = vblankstart;
    gfx_display_mode.vsyncstart = vsyncstart;
    gfx_display_mode.vsyncend = vsyncend;
    gfx_display_mode.vblankend = vblankend;
    gfx_display_mode.vtotal = vtotal;
    gfx_display_mode.frequency = frequency;

    /* CALL ROUTINE TO SET MODE */
    return (gu2_set_specified_mode(&gfx_display_mode, bpp));
}

/*----------------------------------------------------------------------------
 * GFX_SET_VTOTAL
 *
 * This routine sets the display controller vertical total to
 * "vtotal". As a side effect it also sets vertical blank end.
 * It should be used when only this value needs to be changed,
 * due to speed considerations.
 *
 * Note: it is the caller's responsibility to make sure that
 * a legal vtotal is used, i.e. that "vtotal" is greater than or
 * equal to vsync end.
 *
 * Always returns 0.
 *----------------------------------------------------------------------------  
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_set_vtotal(unsigned short vtotal)
#else
int
gfx_set_vtotal(unsigned short vtotal)
#endif
{
    unsigned long unlock, dcfg, vactive, vblank;

    /* UNLOCK THE DISPLAY CONTROLLER REGISTERS */
    unlock = READ_REG32(MDC_UNLOCK);
    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);

    /* READ THE CURRENT RC VALUES */
    dcfg = READ_REG32(MDC_DISPLAY_CFG);
    vactive = READ_REG32(MDC_V_ACTIVE_TIMING);
    vblank = READ_REG32(MDC_V_BLANK_TIMING);

    /* DISABLE TIMING REGISTER UPDATES */
    WRITE_REG32(MDC_DISPLAY_CFG, dcfg & ~(unsigned long) MDC_DCFG_TRUP);

    /* WRITE NEW TIMING VALUES */
    WRITE_REG32(MDC_V_ACTIVE_TIMING,
                (vactive & MDC_VAT_VA_MASK) | (unsigned long) (vtotal -
                                                               1) << 16);
    WRITE_REG32(MDC_V_BLANK_TIMING,
                (vblank & MDC_VBT_VBS_MASK) | (unsigned long) (vtotal -
                                                               1) << 16);

    /* RESTORE OLD RC VALUES */
    WRITE_REG32(MDC_DISPLAY_CFG, dcfg);
    WRITE_REG32(MDC_UNLOCK, unlock);

    return (0);
}

/*---------------------------------------------------------------------------
 * gfx_set_display_pitch
 *
 * This routine sets the pitch of the frame buffer to the specified value.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
void
gu2_set_display_pitch(unsigned short pitch)
#else
void
gfx_set_display_pitch(unsigned short pitch)
#endif
{
    unsigned long value = 0;
    unsigned long lock = READ_REG32(MDC_UNLOCK);

    value = READ_REG32(MDC_GFX_PITCH) & 0xFFFF0000;
    value |= (pitch >> 3);
    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);
    WRITE_REG32(MDC_GFX_PITCH, value);

    /* SET RENDERING PITCHES TO MATCH */
    gfx_reset_pitch(pitch);

    /* SET THE FRAME DIRTY MODE                  */
    /* Non-standard pitches, i.e. pitches that   */
    /* are not 1K, 2K or 4K must mark the entire */
    /* frame as dirty when writing to the frame  */
    /* buffer.                                   */
    value = READ_REG32(MDC_GENERAL_CFG);

    if (pitch == 1024 || pitch == 2048 || pitch == 4096 || pitch == 8192)
        value &= ~(unsigned long) (MDC_GCFG_FDTY);
    else
        value |= (unsigned long) (MDC_GCFG_FDTY);

    WRITE_REG32(MDC_GENERAL_CFG, value);
    WRITE_REG32(MDC_UNLOCK, lock);
}

/*---------------------------------------------------------------------------
 * gfx_set_display_offset
 *
 * This routine sets the start address of the frame buffer.  It is 
 * typically used to pan across a virtual desktop (frame buffer larger than 
 * the displayed screen) or to flip the display between multiple buffers.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
void
gu2_set_display_offset(unsigned long offset)
#else
void
gfx_set_display_offset(unsigned long offset)
#endif
{
    /* UPDATE FRAME BUFFER OFFSET */
    unsigned long lock;

    lock = READ_REG32(MDC_UNLOCK);
    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);

    /* START ADDRESS EFFECTS DISPLAY COMPRESSION */
    /* Disable compression for non-zero start address values.              */
    /* Enable compression if offset is zero and compression is intended to */
    /* be enabled from a previous call to "gfx_set_compression_enable".    */
    /* Compression should be disabled BEFORE the offset is changed         */
    /* and enabled AFTER the offset is changed.                            */
    if (offset == 0) {
        WRITE_REG32(MDC_FB_ST_OFFSET, offset);
        if (gfx_compression_enabled) {
            /* WAIT FOR THE OFFSET TO BE LATCHED */
            gfx_wait_vertical_blank();
            gu2_enable_compression();
        }
    }
    else {
        /* ONLY DISABLE COMPRESSION ONCE */
        if (gfx_compression_active)
            gu2_disable_compression();

        WRITE_REG32(MDC_FB_ST_OFFSET, offset);
    }

    WRITE_REG32(MDC_UNLOCK, lock);
}

/*---------------------------------------------------------------------------
 * gfx_set_display_palette_entry
 *
 * This routine sets an palette entry in the display controller.
 * A 32-bit X:R:G:B value.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_set_display_palette_entry(unsigned long index, unsigned long palette)
#else
int
gfx_set_display_palette_entry(unsigned long index, unsigned long palette)
#endif
{
    unsigned long dcfg, unlock;

    if (index > 0xFF)
        return GFX_STATUS_BAD_PARAMETER;

    unlock = READ_REG32(MDC_UNLOCK);
    dcfg = READ_REG32(MDC_DISPLAY_CFG);

    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);
    WRITE_REG32(MDC_DISPLAY_CFG, dcfg & ~MDC_DCFG_PALB);
    WRITE_REG32(MDC_UNLOCK, unlock);

    WRITE_REG32(MDC_PAL_ADDRESS, index);
    WRITE_REG32(MDC_PAL_DATA, palette);

    return GFX_STATUS_OK;
}

/*---------------------------------------------------------------------------
 * gfx_set_display_palette
 *
 * This routine sets the entire palette in the display controller.
 * A pointer is provided to a 256 entry table of 32-bit X:R:G:B values.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_set_display_palette(unsigned long *palette)
#else
int
gfx_set_display_palette(unsigned long *palette)
#endif
{
    unsigned long unlock, dcfg, i;

    WRITE_REG32(MDC_PAL_ADDRESS, 0);

    if (palette) {
        unlock = READ_REG32(MDC_UNLOCK);
        dcfg = READ_REG32(MDC_DISPLAY_CFG);

        WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);
        WRITE_REG32(MDC_DISPLAY_CFG, dcfg & ~MDC_DCFG_PALB);
        WRITE_REG32(MDC_UNLOCK, unlock);

        for (i = 0; i < 256; i++)
            WRITE_REG32(MDC_PAL_DATA, palette[i]);

        return GFX_STATUS_OK;
    }
    return GFX_STATUS_BAD_PARAMETER;
}

/*---------------------------------------------------------------------------
 * gfx_set_cursor_enable
 *
 * This routine enables or disables the hardware cursor.  
 *
 * WARNING: The cursor start offset must be set by setting the cursor 
 * position before calling this routine to assure that memory reads do not
 * go past the end of graphics memory (this can hang GXm).
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
void
gu2_set_cursor_enable(int enable)
#else
void
gfx_set_cursor_enable(int enable)
#endif
{
    unsigned long unlock, gcfg;

    /* SET OR CLEAR CURSOR ENABLE BIT */
    unlock = READ_REG32(MDC_UNLOCK);
    gcfg = READ_REG32(MDC_GENERAL_CFG);
    if (enable)
        gcfg |= MDC_GCFG_CURE;
    else
        gcfg &= ~(MDC_GCFG_CURE);

    /* WRITE NEW REGISTER VALUE */
    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);
    WRITE_REG32(MDC_GENERAL_CFG, gcfg);
    WRITE_REG32(MDC_UNLOCK, unlock);
}

/*---------------------------------------------------------------------------
 * gfx_set_cursor_colors
 *
 * This routine sets the colors of the hardware cursor.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
void
gu2_set_cursor_colors(unsigned long bkcolor, unsigned long fgcolor)
#else
void
gfx_set_cursor_colors(unsigned long bkcolor, unsigned long fgcolor)
#endif
{
    /* SET CURSOR COLORS */
    WRITE_REG32(MDC_PAL_ADDRESS, 0x100);
    WRITE_REG32(MDC_PAL_DATA, bkcolor);
    WRITE_REG32(MDC_PAL_DATA, fgcolor);
}

/*---------------------------------------------------------------------------
 * gfx_set_cursor_position
 *
 * This routine sets the position of the hardware cusror.  The starting
 * offset of the cursor buffer must be specified so that the routine can 
 * properly clip scanlines if the cursor is off the top of the screen.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
void
gu2_set_cursor_position(unsigned long memoffset,
                        unsigned short xpos, unsigned short ypos,
                        unsigned short xhotspot, unsigned short yhotspot)
#else
void
gfx_set_cursor_position(unsigned long memoffset,
                        unsigned short xpos, unsigned short ypos,
                        unsigned short xhotspot, unsigned short yhotspot)
#endif
{
    unsigned long unlock;

    short x = (short) xpos - (short) xhotspot;
    short y = (short) ypos - (short) yhotspot;
    short xoffset = 0;
    short yoffset = 0;

    if (x < -63)
        return;
    if (y < -63)
        return;

    if (PanelEnable) {
        if ((ModeWidth > PanelWidth) || (ModeHeight > PanelHeight)) {
            gfx_enable_panning(xpos, ypos);
            x = x - (unsigned short) panelLeft;
            y = y - (unsigned short) panelTop;
        }
    }

    /* ADJUST OFFSETS */
    /* Cursor movement and panning work as follows:  The cursor position   */
    /* refers to where the hotspot of the cursor is located.  However, for */
    /* non-zero hotspots, the cursor buffer actually begins before the     */
    /* specified position.                                                 */
    if (x < 0) {
        xoffset = -x;
        x = 0;
    }

    if (y < 0) {
        yoffset = -y;
        y = 0;
    }
    memoffset += (unsigned long) yoffset << 4;

    /* SET CURSOR POSITION */
    unlock = READ_REG32(MDC_UNLOCK);
    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);
    WRITE_REG32(MDC_CURS_ST_OFFSET, memoffset);
    WRITE_REG32(MDC_CURSOR_X, (unsigned long) x |
                (((unsigned long) xoffset) << 11));
    WRITE_REG32(MDC_CURSOR_Y, (unsigned long) y |
                (((unsigned long) yoffset) << 11));
    WRITE_REG32(MDC_UNLOCK, unlock);
}

/*---------------------------------------------------------------------------
 * gfx_set_cursor_shape32
 *
 * This routine loads 32x32 cursor data into the cursor buffer in graphics 
 * memory.
 * As the Redcloud cursor is actually 64x64, we must pad the outside of the 
 * cursor data with transparent pixels.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
void
gu2_set_cursor_shape32(unsigned long memoffset,
                       unsigned long *andmask, unsigned long *xormask)
#else
void
gfx_set_cursor_shape32(unsigned long memoffset,
                       unsigned long *andmask, unsigned long *xormask)
#endif
{
    int i;

    for (i = 0; i < 32; i++) {
        /* EVEN QWORDS CONTAIN THE AND MASK */
        WRITE_FB32(memoffset, 0xFFFFFFFF);
        WRITE_FB32(memoffset + 4, andmask[i]);

        /* ODD QWORDS CONTAIN THE XOR MASK  */
        WRITE_FB32(memoffset + 8, 0x00000000);
        WRITE_FB32(memoffset + 12, xormask[i]);

        memoffset += 16;
    }

    /* FILL THE LOWER HALF OF THE BUFFER WITH TRANSPARENT PIXELS */
    for (i = 0; i < 32; i++) {
        WRITE_FB32(memoffset, 0xFFFFFFFF);
        WRITE_FB32(memoffset + 4, 0xFFFFFFFF);
        WRITE_FB32(memoffset + 8, 0x00000000);
        WRITE_FB32(memoffset + 12, 0x00000000);

        memoffset += 16;
    }
}

/*---------------------------------------------------------------------------
 * gfx_set_cursor_shape64
 *
 * This routine loads 64x64 cursor data into the cursor buffer in graphics 
 * memory.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
void
gu2_set_cursor_shape64(unsigned long memoffset,
                       unsigned long *andmask, unsigned long *xormask)
#else
void
gfx_set_cursor_shape64(unsigned long memoffset,
                       unsigned long *andmask, unsigned long *xormask)
#endif
{
    int i;

    for (i = 0; i < 128; i += 2) {
        /* EVEN QWORDS CONTAIN THE AND MASK */
        /* We invert the dwords to prevent the calling            */
        /* application from having to think in terms of Qwords.   */
        /* The hardware data order is actually 63:0, or 31:0 of   */
        /* the second dword followed by 31:0 of the first dword.  */
        WRITE_FB32(memoffset, andmask[i + 1]);
        WRITE_FB32(memoffset + 4, andmask[i]);

        /* ODD QWORDS CONTAIN THE XOR MASK  */
        WRITE_FB32(memoffset + 8, xormask[i + 1]);
        WRITE_FB32(memoffset + 12, xormask[i]);

        memoffset += 16;
    }
}

/*---------------------------------------------------------------------------
 * gfx_set_icon_enable
 *
 * This routine enables or disables the hardware icon.  The icon position
 * and colors should be programmed prior to calling this routine for the
 * first time.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
void
gu2_set_icon_enable(int enable)
#else
void
gfx_set_icon_enable(int enable)
#endif
{
    unsigned long unlock, gcfg;

    /* SET OR CLEAR ICON ENABLE BIT */
    unlock = READ_REG32(MDC_UNLOCK);
    gcfg = READ_REG32(MDC_GENERAL_CFG);
    if (enable)
        gcfg |= MDC_GCFG_ICNE;
    else
        gcfg &= ~(MDC_GCFG_ICNE);

    /* WRITE NEW REGISTER VALUE */
    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);
    WRITE_REG32(MDC_GENERAL_CFG, gcfg);
    WRITE_REG32(MDC_UNLOCK, unlock);
}

/*---------------------------------------------------------------------------
 * gfx_set_icon_colors
 *
 * This routine sets the three icon colors.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
void
gu2_set_icon_colors(unsigned long color0, unsigned long color1,
                    unsigned long color2)
#else
void
gfx_set_icon_colors(unsigned long color0, unsigned long color1,
                    unsigned long color2)
#endif
{
    /* ICON COLORS LOCATED AT PALETTE INDEXES 102-104h */
    WRITE_REG32(MDC_PAL_ADDRESS, 0x102);

    WRITE_REG32(MDC_PAL_DATA, color0);
    WRITE_REG32(MDC_PAL_DATA, color1);
    WRITE_REG32(MDC_PAL_DATA, color2);
}

/*---------------------------------------------------------------------------
 * gfx_set_icon_position
 *
 * This routine sets the starting X coordinate for the hardware icon and the 
 * memory offset for the icon buffer.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
void
gu2_set_icon_position(unsigned long memoffset, unsigned short xpos)
#else
void
gfx_set_icon_position(unsigned long memoffset, unsigned short xpos)
#endif
{
    unsigned long lock = READ_REG32(MDC_UNLOCK);

    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);

    /* PROGRAM THE MEMORY OFFSET */
    WRITE_REG32(MDC_ICON_ST_OFFSET, memoffset & 0x0FFFFFFF);

    /* PROGRAM THE XCOORDINATE */
    WRITE_REG32(MDC_ICON_X, (unsigned long) (xpos & 0x07FF));

    WRITE_REG32(MDC_UNLOCK, lock);
}

/*---------------------------------------------------------------------------
 * gfx_set_icon_shape64
 *
 * This routine initializes the icon buffer according to the current mode.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
void
gu2_set_icon_shape64(unsigned long memoffset, unsigned long *andmask,
                     unsigned long *xormask, unsigned int lines)
#else
void
gfx_set_icon_shape64(unsigned long memoffset, unsigned long *andmask,
                     unsigned long *xormask, unsigned int lines)
#endif
{
    unsigned short i, height;

    height = lines << 1;

    for (i = 0; i < height; i += 2) {
        /* EVEN QWORDS CONTAIN THE AND MASK     */
        /* Swap dwords to hide qword constraint */
        WRITE_FB32(memoffset, andmask[i + 1]);
        WRITE_FB32(memoffset + 4, andmask[i]);

        /* ODD QWORDS CONTAIN THE XOR MASK */
        WRITE_FB32(memoffset + 8, xormask[i + 1]);
        WRITE_FB32(memoffset + 12, xormask[i]);

        memoffset += 16;
    }
}

/*---------------------------------------------------------------------------
 * gu2_enable_compression
 *
 * This is a private routine to this module (not exposed in the Durango API).
 * It enables display compression.
 *---------------------------------------------------------------------------
 */
void
gu2_enable_compression(void)
{
    unsigned long unlock, gcfg, temp;

    /* DO NOT ENABLE IF START ADDRESS IS NOT ZERO */
    if (READ_REG32(MDC_FB_ST_OFFSET) & 0x0FFFFFFF)
        return;

    /* SET GLOBAL INDICATOR */
    gfx_compression_active = 1;

    /* CLEAR DIRTY/VALID BITS IN MEMORY CONTROLLER */
    /* Software is required to do this before enabling compression.   */
    /* Don't want controller to think that old lines are still valid. */
    /* Writing a 1 to bit 0 of the DV Control register will force the */
    /* hardware to clear all the valid bits.                          */
    temp = READ_REG32(MDC_DV_CTL);
    WRITE_REG32(MDC_DV_CTL, temp | 0x00000001);

    /* TURN ON COMPRESSION CONTROL BITS */
    unlock = READ_REG32(MDC_UNLOCK);
    gcfg = READ_REG32(MDC_GENERAL_CFG);
    gcfg |= MDC_GCFG_CMPE | MDC_GCFG_DECE;
    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);
    WRITE_REG32(MDC_GENERAL_CFG, gcfg);
    WRITE_REG32(MDC_UNLOCK, unlock);
}

/*---------------------------------------------------------------------------
 * gu2_disable_compression
 *
 * This is a private routine to this module (not exposed in the Durango API).
 * It disables display compression.
 *---------------------------------------------------------------------------
 */
void
gu2_disable_compression(void)
{
    unsigned long unlock, gcfg;

    /* SET GLOBAL INDICATOR */

    gfx_compression_active = 0;

    /* TURN OFF COMPRESSION CONTROL BITS */

    unlock = READ_REG32(MDC_UNLOCK);
    gcfg = READ_REG32(MDC_GENERAL_CFG);
    gcfg &= ~(MDC_GCFG_CMPE | MDC_GCFG_DECE);
    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);
    WRITE_REG32(MDC_GENERAL_CFG, gcfg);
    WRITE_REG32(MDC_UNLOCK, unlock);
}

/*---------------------------------------------------------------------------
 * gfx_set_compression_enable
 *
 * This routine enables or disables display compression.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_set_compression_enable(int enable)
#else
int
gfx_set_compression_enable(int enable)
#endif
{
    /* SET GLOBAL VARIABLE FOR INTENDED STATE */
    /* Compression can only be enabled for non-zero start address values. */
    /* Keep state to enable compression on start address changes. */

    gfx_compression_enabled = enable;
    if (enable)
        gu2_enable_compression();
    else
        gu2_disable_compression();
    return (0);
}

/*---------------------------------------------------------------------------
 * gfx_set_compression_offset
 *
 * This routine sets the base offset for the compression buffer.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_set_compression_offset(unsigned long offset)
#else
int
gfx_set_compression_offset(unsigned long offset)
#endif
{
    unsigned long lock;

    /* MUST BE 16-BYTE ALIGNED FOR REDCLOUD */

    if (offset & 0x0F)
        return (1);

    /* SET REGISTER VALUE */

    lock = READ_REG32(MDC_UNLOCK);
    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);
    WRITE_REG32(MDC_CB_ST_OFFSET, offset & 0x0FFFFFFF);
    WRITE_REG32(MDC_UNLOCK, lock);

    return (0);
}

/*---------------------------------------------------------------------------
 * gfx_set_compression_pitch
 *
 * This routine sets the pitch, in bytes, of the compression buffer. 
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_set_compression_pitch(unsigned short pitch)
#else
int
gfx_set_compression_pitch(unsigned short pitch)
#endif
{
    unsigned long lock, line_delta;

    lock = READ_REG32(MDC_UNLOCK);

    /* SET REGISTER VALUE */

    line_delta = READ_REG32(MDC_GFX_PITCH) & 0x0000FFFF;
    line_delta |= (((unsigned long) pitch << 13) & 0xFFFF0000);
    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);
    WRITE_REG32(MDC_GFX_PITCH, line_delta);
    WRITE_REG32(MDC_UNLOCK, lock);
    return (0);
}

/*---------------------------------------------------------------------------
 * gfx_set_compression_size
 *
 * This routine sets the line size of the compression buffer, which is the
 * maximum number of bytes allowed to store a compressed line.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_set_compression_size(unsigned short size)
#else
int
gfx_set_compression_size(unsigned short size)
#endif
{
    unsigned long lock, buf_size;

    /* SUBTRACT 32 FROM SIZE                          */
    /* The display controller will actually write     */
    /* 4 extra QWords.  So, if we assume that "size"  */
    /* refers to the allocated size, we must subtract */
    /* 32 bytes.                                      */

    size -= 32;

    /* SET REGISTER VALUE */

    lock = READ_REG32(MDC_UNLOCK);
    buf_size = READ_REG32(MDC_LINE_SIZE) & 0xFF80FFFF;
    buf_size |= ((((unsigned long) size >> 3) + 1) & 0x7F) << 16;
    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);
    WRITE_REG32(MDC_LINE_SIZE, buf_size);
    WRITE_REG32(MDC_UNLOCK, lock);
    return (0);
}

/*---------------------------------------------------------------------------
 * gfx_set_display_video_format (PRIVATE ROUTINE - NOT PART OF API)
 *
 * This routine is called by "gfx_set_video_format".  It abstracts the 
 * version of the display controller from the video overlay routines.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
void
gu2_set_display_video_format(unsigned long format)
#else
void
gfx_set_display_video_format(unsigned long format)
#endif
{
    unsigned long gcfg, lock;

    lock = READ_REG32(MDC_UNLOCK);
    gcfg = READ_REG32(MDC_GENERAL_CFG);

    switch (format) {
    case VIDEO_FORMAT_Y0Y1Y2Y3:
    case VIDEO_FORMAT_Y3Y2Y1Y0:
    case VIDEO_FORMAT_Y1Y0Y3Y2:
    case VIDEO_FORMAT_Y1Y2Y3Y0:
        gcfg |= MDC_GCFG_YUVM;
        break;

    default:
        gcfg &= ~MDC_GCFG_YUVM;
        break;
    }

    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);
    WRITE_REG32(MDC_GENERAL_CFG, gcfg);
    WRITE_REG32(MDC_UNLOCK, lock);
}

/*---------------------------------------------------------------------------
 * gfx_set_display_video_enable (PRIVATE ROUTINE - NOT PART OF API)
 *
 * This routine is called by "gfx_set_video_enable".  It abstracts the 
 * version of the display controller from the video overlay routines.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
void
gu2_set_display_video_enable(int enable)
#else
void
gfx_set_display_video_enable(int enable)
#endif
{
    unsigned long lock, gcfg, dcfg;

    /* READ CURRENT VALUES */

    lock = READ_REG32(MDC_UNLOCK);
    gcfg = READ_REG32(MDC_GENERAL_CFG);
    dcfg = READ_REG32(MDC_DISPLAY_CFG);

    /* SET OR CLEAR VIDEO ENABLE IN GENERAL_CFG */

    if (enable)
        gcfg |= MDC_GCFG_VIDE;
    else
        gcfg &= ~MDC_GCFG_VIDE;

    /* WRITE REGISTER */

    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);
    WRITE_REG32(MDC_GENERAL_CFG, gcfg);
    WRITE_REG32(MDC_UNLOCK, lock);
}

/*---------------------------------------------------------------------------
 * gfx_set_display_video_size (PRIVATE ROUTINE - NOT PART OF API)
 *
 * This routine is called by "gfx_set_video_size".  It abstracts the 
 * version of the display controller from the video overlay routines.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
void
gu2_set_display_video_size(unsigned short width, unsigned short height)
#else
void
gfx_set_display_video_size(unsigned short width, unsigned short height)
#endif
{
    unsigned long lock, value, yuv_420;

    /* READ CURRENT VALUES */

    lock = READ_REG32(MDC_UNLOCK);
    value = READ_REG32(MDC_LINE_SIZE) & 0x00FFFFFF;
    yuv_420 = READ_REG32(MDC_GENERAL_CFG) & MDC_GCFG_YUVM;

    /* LINE WIDTH IS 1/4 FOR 4:2:0 VIDEO */
    /* All data must be 32-byte aligned. */

    if (yuv_420) {
        width >>= 1;
        width = (width + 7) & 0xFFF8;
    }
    else {
        width <<= 1;
        width = (width + 31) & 0xFFE0;
    }

    /* ONLY THE LINE SIZE IS PROGRAMMED IN THE DISPLAY CONTROLLER */

    value |= ((unsigned long) width << 21);

    /* WRITE THE REGISTER */

    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);
    WRITE_REG32(MDC_LINE_SIZE, value);
    WRITE_REG32(MDC_UNLOCK, lock);
}

/*---------------------------------------------------------------------------
 * gfx_set_display_video_offset (PRIVATE ROUTINE - NOT PART OF API)
 *
 * This routine is called by "gfx_set_video_offset".  It abstracts the 
 * version of the display controller from the video overlay routines.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
void
gu2_set_display_video_offset(unsigned long offset)
#else
void
gfx_set_display_video_offset(unsigned long offset)
#endif
{
    unsigned long lock;

    lock = READ_REG32(MDC_UNLOCK);
    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);
    offset &= 0x0FFFFFF0;
    WRITE_REG32(MDC_VID_Y_ST_OFFSET, offset);
    WRITE_REG32(MDC_UNLOCK, lock);
}

/*---------------------------------------------------------------------------
 * gfx_set_display_video_yuv_offsets (PRIVATE ROUTINE - NOT PART OF API)
 *
 * This routine is called by gfx_set_video_yuv_offsets.  It abstracts the 
 * version of the display controller from the video overlay routines.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
void
gu2_set_display_video_yuv_offsets(unsigned long yoffset,
                                  unsigned long uoffset, unsigned long voffset)
#else
void
gfx_set_display_video_yuv_offsets(unsigned long yoffset,
                                  unsigned long uoffset, unsigned long voffset)
#endif
{
    unsigned long lock;

    lock = READ_REG32(MDC_UNLOCK);

    yoffset &= 0x0FFFFFF0;
    uoffset &= 0x0FFFFFF8;
    voffset &= 0x0FFFFFF8;

    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);
    WRITE_REG32(MDC_VID_Y_ST_OFFSET, yoffset);
    WRITE_REG32(MDC_VID_U_ST_OFFSET, uoffset);
    WRITE_REG32(MDC_VID_V_ST_OFFSET, voffset);
    WRITE_REG32(MDC_UNLOCK, lock);
}

/*---------------------------------------------------------------------------
 * gfx_set_display_video_yuv_pitch (PRIVATE ROUTINE - NOT PART OF API)
 *
 * This routine is called by gfx_set_video_yuv_pitch.  It abstracts the
 * version of the display controller from the video overlay routines.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
void
gu2_set_display_video_yuv_pitch(unsigned long ypitch, unsigned long uvpitch)
#else
void
gfx_set_display_video_yuv_pitch(unsigned long ypitch, unsigned long uvpitch)
#endif
{
    unsigned long lock, pitch;

    lock = READ_REG32(MDC_UNLOCK);

    pitch = ((uvpitch << 13) & 0xFFFF0000) | ((ypitch >> 3) & 0xFFFF);

    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);
    WRITE_REG32(MDC_VID_YUV_PITCH, pitch);
    WRITE_REG32(MDC_UNLOCK, lock);
}

/*---------------------------------------------------------------------------
 * gfx_set_display_video_downscale (PRIVATE ROUTINE - NOT PART OF API)
 *
 * This routine is called by gfx_set_video_vertical_downscale.  It abstracts
 * the version of the display controller from the video overlay routines.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
void
gu2_set_display_video_downscale(unsigned short srch, unsigned short dsth)
#else
void
gfx_set_display_video_downscale(unsigned short srch, unsigned short dsth)
#endif
{
    unsigned long lock, delta;

    lock = READ_REG32(MDC_UNLOCK);

    /* CLIP SCALING LIMITS */
    /* Upscaling is performed in a separate function. */
    /* Maximum scale ratio is 1/2.                    */

    if (dsth > srch || dsth <= (srch >> 1))
        delta = 0;
    else
        delta = (((unsigned long) srch << 14) / (unsigned long) dsth) << 18;

    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);
    WRITE_REG32(MDC_VID_DS_DELTA, delta);
    WRITE_REG32(MDC_UNLOCK, lock);
}

/*---------------------------------------------------------------------------
 * gfx_set_display_video_downscale_enable (PRIVATE ROUTINE - NOT PART OF API)
 *
 * This routine is called by "gfx_set_video_vertical_downscale_enable".  
 * It abstracts the version of the display controller from the video overlay
 * routines.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
void
gu2_set_display_video_vertical_downscale_enable(int enable)
#else
void
gfx_set_display_video_vertical_downscale_enable(int enable)
#endif
{
    unsigned long gcfg, unlock;

    unlock = READ_REG32(MDC_UNLOCK);
    gcfg = READ_REG32(MDC_GENERAL_CFG);

    if (enable)
        gcfg |= MDC_GCFG_VDSE;
    else
        gcfg &= ~MDC_GCFG_VDSE;

    WRITE_REG32(MDC_UNLOCK, MDC_UNLOCK_VALUE);
    WRITE_REG32(MDC_GENERAL_CFG, gcfg);
    WRITE_REG32(MDC_UNLOCK, unlock);
}

/*---------------------------------------------------------------------------
 * gfx_test_timing_active
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_test_timing_active(void)
#else
int
gfx_test_timing_active(void)
#endif
{
    if (READ_REG32(MDC_DISPLAY_CFG) & MDC_DCFG_TGEN)
        return (1);
    else
        return (0);
}

/*---------------------------------------------------------------------------
 * gfx_test_vertical_active
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_test_vertical_active(void)
#else
int
gfx_test_vertical_active(void)
#endif
{
    if (READ_REG32(MDC_LINE_CNT_STATUS) & MDC_LNCNT_VNA)
        return (0);

    return (1);
}

/*---------------------------------------------------------------------------
 * gfx_wait_vertical_blank
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_wait_vertical_blank(void)
#else
int
gfx_wait_vertical_blank(void)
#endif
{
    if (gfx_test_timing_active()) {
        while (!gfx_test_vertical_active());
        while (gfx_test_vertical_active());
    }
    return (0);
}

/*---------------------------------------------------------------------------
 * gfx_enable_panning 
 *
 * This routine  enables the panning when the Mode is bigger than the panel
 * size.
 *---------------------------------------------------------------------------
 */

#if GFX_DISPLAY_DYNAMIC
void
gu2_enable_panning(int x, int y)
#else
void
gfx_enable_panning(int x, int y)
#endif
{
    unsigned long modeBytesPerPixel;
    unsigned long modeBytesPerScanline = 0;
    unsigned long startAddress = 0;

    modeBytesPerPixel = (gbpp + 7) / 8;
    modeBytesPerScanline = (READ_REG32(MDC_GFX_PITCH) & 0x0000FFFF) << 3;

    /* TEST FOR NO-WORK */

    if (x >= DeltaX && x < ((int) PanelWidth + DeltaX) &&
        y >= DeltaY && y < ((int) PanelHeight + DeltaY))
        return;

    /* ADJUST PANNING VARIABLES WHEN CURSOR EXCEEDS BOUNDARY       */
    /* Test the boundary conditions for each coordinate and update */
    /* all variables and the starting offset accordingly.          */

    if (x < DeltaX)
        DeltaX = x;

    else if (x >= (DeltaX + (int) PanelWidth))
        DeltaX = x - (int) PanelWidth + 1;

    if (y < DeltaY)
        DeltaY = y;

    else if (y >= (DeltaY + (int) PanelHeight))
        DeltaY = y - (int) PanelHeight + 1;

    /* CALCULATE THE START OFFSET */

    startAddress =
        (DeltaX * modeBytesPerPixel) + (DeltaY * modeBytesPerScanline);

    gfx_set_display_offset(startAddress);

    /* SET PANEL COORDINATES                    */
    /* Panel's x position must be DWORD aligned */

    panelTop = DeltaY;
    panelLeft = DeltaX * modeBytesPerPixel;

    if (panelLeft & 3)
        panelLeft = (panelLeft & 0xFFFFFFFC) + 4;

    panelLeft /= modeBytesPerPixel;
}

/*---------------------------------------------------------------------------
 * gfx_is_panel_mode_supported
 *---------------------------------------------------------------------------
 */

#if GFX_DISPLAY_DYNAMIC
int
gu2_is_panel_mode_supported(int panelResX, int panelResY,
                            unsigned short width, unsigned short height,
                            unsigned short bpp)
#else
int
gfx_is_panel_mode_supported(int panelResX, int panelResY,
                            unsigned short width, unsigned short height,
                            unsigned short bpp)
#endif
{
    unsigned int mode;

    /* LOOP THROUGH THE AVAILABLE MODES TO FIND A MATCH */
    for (mode = 0; mode < NUM_FIXED_TIMINGS_MODES; mode++) {
        if ((FixedParams[mode].xres == width) &&
            (FixedParams[mode].yres == height) &&
            (FixedParams[mode].panelresx == panelResX) &&
            (FixedParams[mode].panelresy == panelResY)) {
            return ((int) mode);
        }
    }

    return -1;
}

/*---------------------------------------------------------------------------
 * gfx_set_fixed_timings
 *---------------------------------------------------------------------------
 */

#if GFX_DISPLAY_DYNAMIC
int
gu2_set_fixed_timings(int panelResX, int panelResY, unsigned short width,
                      unsigned short height, unsigned short bpp)
#else
int
gfx_set_fixed_timings(int panelResX, int panelResY, unsigned short width,
                      unsigned short height, unsigned short bpp)
#endif
{
    unsigned int mode;

    ModeWidth = width;
    ModeHeight = height;
    PanelWidth = (unsigned short) panelResX;
    PanelHeight = (unsigned short) panelResY;
    PanelEnable = 1;

    /* LOOP THROUGH THE AVAILABLE MODES TO FIND A MATCH */
    for (mode = 0; mode < NUM_FIXED_TIMINGS_MODES; mode++) {
        if ((FixedParams[mode].xres == width) &&
            (FixedParams[mode].yres == height) &&
            (FixedParams[mode].panelresx == panelResX) &&
            (FixedParams[mode].panelresy == panelResY)) {

            /* SET THE 92xx FOR THE SELECTED MODE */
            FIXEDTIMINGS *fmode = &FixedParams[mode];

            gfx_set_display_timings(bpp, 3, fmode->hactive,
                                    fmode->hblankstart, fmode->hsyncstart,
                                    fmode->hsyncend, fmode->hblankend,
                                    fmode->htotal, fmode->vactive,
                                    fmode->vblankstart, fmode->vsyncstart,
                                    fmode->vsyncend, fmode->vblankend,
                                    fmode->vtotal, fmode->frequency);

            return (1);
        }                       /* end if() */
    }                           /* end for() */

    return (-1);
}

/*---------------------------------------------------------------------------
 * gfx_set_panel_present
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_set_panel_present(int panelResX, int panelResY, unsigned short width,
                      unsigned short height, unsigned short bpp)
#else
int
gfx_set_panel_present(int panelResX, int panelResY, unsigned short width,
                      unsigned short height, unsigned short bpp)
#endif
{
    /* SET VALID BPP         */
    /* 16BPP is the default. */

    if (bpp != 8 && bpp != 12 && bpp != 15 && bpp != 16 && bpp != 32)
        bpp = 16;

    /* RECORD PANEL PARAMETERS */
    /* This routine does not touch any panel timings.  It is used when custom
     * panel settings are set up in advance by the BIOS or an application, but
     * the application still requires access to other panel functionality
     * provided by Durango (i.e. panning).
     * */

    ModeWidth = width;
    ModeHeight = height;
    PanelWidth = (unsigned short) panelResX;
    PanelHeight = (unsigned short) panelResY;
    PanelEnable = 1;
    gbpp = bpp;

    /* PROGRAM THE BPP IN THE DISPLAY CONTROLLER */

    gfx_set_display_bpp(bpp);

    return (GFX_STATUS_OK);
}

/* THE FOLLOWING READ ROUTINES ARE ALWAYS INCLUDED: */

/*---------------------------------------------------------------------------
 * gfx_get_display_pitch
 *
 * This routine returns the current pitch of the frame buffer, in bytes.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned short
gu2_get_display_pitch(void)
#else
unsigned short
gfx_get_display_pitch(void)
#endif
{
    return ((unsigned short) (READ_REG32(MDC_GFX_PITCH) & 0x0000FFFF) << 3);
}

/*----------------------------------------------------------------------------
 * gfx_mode_frequency_supported
 *
 * This routine examines if the requested mode with pixel frequency is 
 * supported.
 *
 * Returns >0 if successful , <0 if freq. could not be found and matched.
 *----------------------------------------------------------------------------  
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_mode_frequency_supported(int xres, int yres, int bpp,
                             unsigned long frequency)
#else
int
gfx_mode_frequency_supported(int xres, int yres, int bpp,
                             unsigned long frequency)
#endif
{
    unsigned int index;
    unsigned long value;
    unsigned long bpp_flag = 0;

    gfx_mode_bpp_conversion_def(bpp)

        for (index = 0; index < NUM_RC_DISPLAY_MODES; index++) {
        if ((DisplayParams[index].hactive == (unsigned int) xres) &&
            (DisplayParams[index].vactive == (unsigned int) yres) &&
            (DisplayParams[index].flags & bpp_flag) &&
            (DisplayParams[index].frequency == frequency)) {
            int hz = 0;

            value = DisplayParams[index].flags;

            if (value & GFX_MODE_56HZ)
                hz = 56;
            else if (value & GFX_MODE_60HZ)
                hz = 60;
            else if (value & GFX_MODE_70HZ)
                hz = 70;
            else if (value & GFX_MODE_72HZ)
                hz = 72;
            else if (value & GFX_MODE_75HZ)
                hz = 75;
            else if (value & GFX_MODE_85HZ)
                hz = 85;
            else if (value & GFX_MODE_90HZ)
                hz = 90;
            else if (value & GFX_MODE_100HZ)
                hz = 100;
            return (hz);
        }
    }

    return (-1);
}

/*----------------------------------------------------------------------------
 * gfx_refreshrate_from_frequency
 *
 * This routine maps the frequency to close match refresh rate
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_get_refreshrate_from_frequency(int xres, int yres, int bpp, int *hz,
                                   unsigned long frequency)
#else
int
gfx_get_refreshrate_from_frequency(int xres, int yres, int bpp, int *hz,
                                   unsigned long frequency)
#endif
{
    unsigned int index, closematch = 0;
    unsigned long value;
    unsigned long bpp_flag = 0;
    long min, diff;

    *hz = 60;

    gfx_mode_bpp_conversion_def(bpp)

        /* FIND THE REGISTER VALUES FOR THE DESIRED FREQUENCY */
        /* Search the table for the closest frequency (16.16 format). */
        min = 0x7fffffff;
    for (index = 0; index < NUM_RC_DISPLAY_MODES; index++) {
        if ((DisplayParams[index].htotal == (unsigned int) xres) &&
            (DisplayParams[index].vtotal == (unsigned int) yres) &&
            (DisplayParams[index].flags & bpp_flag)) {
            diff = (long) frequency - (long) DisplayParams[index].frequency;
            if (diff < 0)
                diff = -diff;

            if (diff < min) {
                min = diff;
                closematch = index;
            }
        }
    }

    value = DisplayParams[closematch].flags;

    if (value & GFX_MODE_56HZ)
        *hz = 56;
    else if (value & GFX_MODE_60HZ)
        *hz = 60;
    else if (value & GFX_MODE_70HZ)
        *hz = 70;
    else if (value & GFX_MODE_72HZ)
        *hz = 72;
    else if (value & GFX_MODE_75HZ)
        *hz = 75;
    else if (value & GFX_MODE_85HZ)
        *hz = 85;
    else if (value & GFX_MODE_90HZ)
        *hz = 90;
    else if (value & GFX_MODE_100HZ)
        *hz = 100;

    return (1);
}

/*----------------------------------------------------------------------------
 * gfx_refreshrate_from_mode
 *
 * This routine is identical to the gfx_get_refreshrate_from_frequency,
 * except that the active timing values are compared instead of the total
 * values.  Some modes (such as 70Hz and 72Hz) may be confused in this routine
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_get_refreshrate_from_mode(int xres, int yres, int bpp, int *hz,
                              unsigned long frequency)
#else
int
gfx_get_refreshrate_from_mode(int xres, int yres, int bpp, int *hz,
                              unsigned long frequency)
#endif
{
    unsigned int index, closematch = 0;
    unsigned long value;
    unsigned long bpp_flag = 0;
    long min, diff;

    *hz = 60;

    gfx_mode_bpp_conversion_def(bpp)

        /* FIND THE REGISTER VALUES FOR THE DESIRED FREQUENCY */
        /* Search the table for the closest frequency (16.16 format). */
        min = 0x7fffffff;
    for (index = 0; index < NUM_RC_DISPLAY_MODES; index++) {
        if ((DisplayParams[index].hactive == (unsigned int) xres) &&
            (DisplayParams[index].vactive == (unsigned int) yres) &&
            (DisplayParams[index].flags & bpp_flag)) {
            diff = (long) frequency - (long) DisplayParams[index].frequency;
            if (diff < 0)
                diff = -diff;

            if (diff < min) {
                min = diff;
                closematch = index;
            }
        }
    }

    value = DisplayParams[closematch].flags;

    if (value & GFX_MODE_56HZ)
        *hz = 56;
    else if (value & GFX_MODE_60HZ)
        *hz = 60;
    else if (value & GFX_MODE_70HZ)
        *hz = 70;
    else if (value & GFX_MODE_72HZ)
        *hz = 72;
    else if (value & GFX_MODE_75HZ)
        *hz = 75;
    else if (value & GFX_MODE_85HZ)
        *hz = 85;
    else if (value & GFX_MODE_90HZ)
        *hz = 90;
    else if (value & GFX_MODE_100HZ)
        *hz = 100;

    return (1);
}

/*----------------------------------------------------------------------------
 * gfx_get_frequency_from_refreshrate
 *
 * This routine maps the refresh rate to the closest matching PLL frequency.
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_get_frequency_from_refreshrate(int xres, int yres, int bpp, int hz,
                                   int *frequency)
#else
int
gfx_get_frequency_from_refreshrate(int xres, int yres, int bpp, int hz,
                                   int *frequency)
#endif
{
    unsigned int index;
    int retval = -1;
    unsigned long hz_flag = 0;
    unsigned long bpp_flag = 0;

    *frequency = 0;

    gfx_mode_hz_conversion gfx_mode_bpp_conversion_def(bpp)

        /* FIND THE REGISTER VALUES FOR THE DESIRED FREQUENCY */
        /* Search the table for the closest frequency (16.16 format). */
    for (index = 0; index < NUM_RC_DISPLAY_MODES; index++) {
        if ((DisplayParams[index].hactive == (unsigned short) xres) &&
            (DisplayParams[index].vactive == (unsigned short) yres) &&
            (DisplayParams[index].flags & bpp_flag) &&
            (DisplayParams[index].flags & hz_flag)) {
            *frequency = DisplayParams[index].frequency;
            retval = 1;
        }
    }
    return retval;
}

/*---------------------------------------------------------------------------
 * gfx_get_max_supported_pixel_clock
 *
 * This routine returns the maximum recommended speed for the pixel clock. The
 * return value is an integer of the format xxxyyy, where xxx.yyy is the
 * maximum floating point pixel clock speed.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned long
gu2_get_max_supported_pixel_clock(void)
#else
unsigned long
gfx_get_max_supported_pixel_clock(void)
#endif
{
    return 229500;
}

/*----------------------------------------------------------------------------
 * gfx_get_display_mode
 *
 * This routine gets the specified display mode.
 *
 * Returns >0 if successful and mode returned, <0 if mode could not be found.
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_get_display_mode(int *xres, int *yres, int *bpp, int *hz)
#else
int
gfx_get_display_mode(int *xres, int *yres, int *bpp, int *hz)
#endif
{
    unsigned int mode = 0;
    unsigned long pll_freq = 0, bpp_flag = 0;

    *xres = gfx_get_hactive();
    *yres = gfx_get_vactive();
    *bpp = gfx_get_display_bpp();
    pll_freq = gfx_get_clock_frequency();

    /* SET BPP FLAGS TO LIMIT MODE SELECTION */
    gfx_mode_bpp_conversion_def(*bpp)

        for (mode = 0; mode < NUM_RC_DISPLAY_MODES; mode++) {
        if ((DisplayParams[mode].hactive == (unsigned int) *xres) &&
            (DisplayParams[mode].vactive == (unsigned int) *yres) &&
            (DisplayParams[mode].frequency == pll_freq) &&
            (DisplayParams[mode].flags & bpp_flag)) {

            pll_freq = DisplayParams[mode].flags;

            if (pll_freq & GFX_MODE_56HZ)
                *hz = 56;
            else if (pll_freq & GFX_MODE_60HZ)
                *hz = 60;
            else if (pll_freq & GFX_MODE_70HZ)
                *hz = 70;
            else if (pll_freq & GFX_MODE_72HZ)
                *hz = 72;
            else if (pll_freq & GFX_MODE_75HZ)
                *hz = 75;
            else if (pll_freq & GFX_MODE_85HZ)
                *hz = 85;
            else if (pll_freq & GFX_MODE_90HZ)
                *hz = 90;
            else if (pll_freq & GFX_MODE_100HZ)
                *hz = 100;

            return (1);
        }
    }
    return (-1);
}

/*----------------------------------------------------------------------------
 * GFX_GET_DISPLAY_DETAILS
 *
 * This routine gets the specified display mode.
 *
 * Returns 1 if successful, 0 if mode could not be get.
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_get_display_details(unsigned int mode, int *xres, int *yres, int *hz)
#else
int
gfx_get_display_details(unsigned int mode, int *xres, int *yres, int *hz)
#endif
{
    if (mode < NUM_RC_DISPLAY_MODES) {
        if (DisplayParams[mode].flags & GFX_MODE_56HZ)
            *hz = 56;
        else if (DisplayParams[mode].flags & GFX_MODE_60HZ)
            *hz = 60;
        else if (DisplayParams[mode].flags & GFX_MODE_70HZ)
            *hz = 70;
        else if (DisplayParams[mode].flags & GFX_MODE_72HZ)
            *hz = 72;
        else if (DisplayParams[mode].flags & GFX_MODE_75HZ)
            *hz = 75;
        else if (DisplayParams[mode].flags & GFX_MODE_85HZ)
            *hz = 85;
        else if (DisplayParams[mode].flags & GFX_MODE_90HZ)
            *hz = 90;
        else if (DisplayParams[mode].flags & GFX_MODE_100HZ)
            *hz = 100;

        *xres = DisplayParams[mode].hactive;
        *yres = DisplayParams[mode].vactive;

        if (DisplayParams[mode].flags & GFX_MODE_PIXEL_DOUBLE)
            *xres >>= 1;
        if (DisplayParams[mode].flags & GFX_MODE_LINE_DOUBLE)
            *yres >>= 1;

        return (1);
    }
    return (0);
}

/*----------------------------------------------------------------------------
 * GFX_GET_DISPLAY_MODE_COUNT
 *
 * This routine gets the number of available display modes.
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_get_display_mode_count(void)
#else
int
gfx_get_display_mode_count(void)
#endif
{
    return (NUM_RC_DISPLAY_MODES);
}

/*----------------------------------------------------------------------------
 * gfx_get_frame_buffer_line_size
 *
 * Returns the current frame buffer line size, in bytes
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned long
gu2_get_frame_buffer_line_size(void)
#else
unsigned long
gfx_get_frame_buffer_line_size(void)
#endif
{
    return ((READ_REG32(MDC_LINE_SIZE) & 0x7FF) << 3);
}

/*---------------------------------------------------------------------------
 * gfx_get_hactive
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned short
gu2_get_hactive(void)
#else
unsigned short
gfx_get_hactive(void)
#endif
{
    return ((unsigned short) ((READ_REG32(MDC_H_ACTIVE_TIMING) & 0x0FF8) + 8));
}

/*---------------------------------------------------------------------------
 * gfx_get_hsync_start
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned short
gu2_get_hsync_start(void)
#else
unsigned short
gfx_get_hsync_start(void)
#endif
{
    return ((unsigned short) ((READ_REG32(MDC_H_SYNC_TIMING) & 0x0FF8) + 8));
}

/*---------------------------------------------------------------------------
 * gfx_get_hsync_end
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned short
gu2_get_hsync_end(void)
#else
unsigned short
gfx_get_hsync_end(void)
#endif
{
    return ((unsigned short) (((READ_REG32(MDC_H_SYNC_TIMING) >> 16) & 0x0FF8)
                              + 8));
}

/*---------------------------------------------------------------------------
 * gfx_get_htotal
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned short
gu2_get_htotal(void)
#else
unsigned short
gfx_get_htotal(void)
#endif
{
    return ((unsigned short) (((READ_REG32(MDC_H_ACTIVE_TIMING) >> 16) &
                               0x0FF8) + 8));
}

/*---------------------------------------------------------------------------
 * gfx_get_vactive
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned short
gu2_get_vactive(void)
#else
unsigned short
gfx_get_vactive(void)
#endif
{
    return ((unsigned short) ((READ_REG32(MDC_V_ACTIVE_TIMING) & 0x07FF) + 1));
}

/*---------------------------------------------------------------------------
 * gfx_get_vsync_end
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned short
gu2_get_vsync_end(void)
#else
unsigned short
gfx_get_vsync_end(void)
#endif
{
    return ((unsigned short) (((READ_REG32(MDC_V_SYNC_TIMING) >> 16) & 0x07FF)
                              + 1));
}

/*---------------------------------------------------------------------------
 * gfx_get_vtotal
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned short
gu2_get_vtotal(void)
#else
unsigned short
gfx_get_vtotal(void)
#endif
{
    return ((unsigned short) (((READ_REG32(MDC_V_ACTIVE_TIMING) >> 16) &
                               0x07FF) + 1));
}

/*----------------------------------------------------------------------------
 * gfx_get_display_bpp
 *
 * This routine returns the current color depth of the active display.
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned short
gu2_get_display_bpp(void)
#else
unsigned short
gfx_get_display_bpp(void)
#endif
{
    unsigned long dcfg = READ_REG32(MDC_DISPLAY_CFG);

    switch ((dcfg & MDC_DCFG_DISP_MODE_MASK) >> 8) {
    case 0:
        return (8);
    case 2:
        return (32);
    case 1:
        switch ((dcfg & MDC_DCFG_16BPP_MODE_MASK) >> 10) {
        case 0:
            return (16);
        case 1:
            return (15);
        case 2:
            return (12);
        default:
            return (0);
        }
    }

    /* INVALID SETTING */
    return (0);
}

/*---------------------------------------------------------------------------
 * gfx_get_vline
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned short
gu2_get_vline(void)
#else
unsigned short
gfx_get_vline(void)
#endif
{
    unsigned short current_scan_line;

    /* Read similar value twice to ensure that the value is not 
     * transitioning */
    do
        current_scan_line =
            (unsigned short) (READ_REG32(MDC_LINE_CNT_STATUS) &
                              MDC_LNCNT_V_LINE_CNT);
    while (current_scan_line !=
           (unsigned short) (READ_REG32(MDC_LINE_CNT_STATUS) &
                             MDC_LNCNT_V_LINE_CNT));

    return (current_scan_line >> 16);
}

/*-----------------------------------------------------------------------------
 * gfx_get_display_offset
 *-----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned long
gu2_get_display_offset(void)
#else
unsigned long
gfx_get_display_offset(void)
#endif
{
    return (READ_REG32(MDC_FB_ST_OFFSET) & 0x0FFFFFFF);
}

/*-----------------------------------------------------------------------------
 * gfx_get_cursor_offset
 *-----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned long
gu2_get_cursor_offset(void)
#else
unsigned long
gfx_get_cursor_offset(void)
#endif
{
    return (READ_REG32(MDC_CURS_ST_OFFSET) & 0x0FFFFFFF);
}

#if GFX_READ_ROUTINES

/*************************************************************/
/*  READ ROUTINES  |  INCLUDED FOR DIAGNOSTIC PURPOSES ONLY  */
/*************************************************************/

/*---------------------------------------------------------------------------
 * gfx_get_hblank_start
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned short
gu2_get_hblank_start(void)
#else
unsigned short
gfx_get_hblank_start(void)
#endif
{
    return ((unsigned short) ((READ_REG32(MDC_H_BLANK_TIMING) & 0x0FF8) + 8));
}

/*---------------------------------------------------------------------------
 * gfx_get_hblank_end
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned short
gu2_get_hblank_end(void)
#else
unsigned short
gfx_get_hblank_end(void)
#endif
{
    return ((unsigned short) (((READ_REG32(MDC_H_BLANK_TIMING) >> 16) & 0x0FF8)
                              + 8));
}

/*---------------------------------------------------------------------------
 * gfx_get_vblank_start
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned short
gu2_get_vblank_start(void)
#else
unsigned short
gfx_get_vblank_start(void)
#endif
{
    return ((unsigned short) ((READ_REG32(MDC_V_BLANK_TIMING) & 0x07FF) + 1));
}

/*---------------------------------------------------------------------------
 * gfx_get_vsync_start
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned short
gu2_get_vsync_start(void)
#else
unsigned short
gfx_get_vsync_start(void)
#endif
{
    return ((unsigned short) ((READ_REG32(MDC_V_SYNC_TIMING) & 0x07FF) + 1));
}

/*---------------------------------------------------------------------------
 * gfx_get_vblank_end
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned short
gu2_get_vblank_end(void)
#else
unsigned short
gfx_get_vblank_end(void)
#endif
{
    return ((unsigned short) (((READ_REG32(MDC_V_BLANK_TIMING) >> 16) & 0x07FF)
                              + 1));
}

/*----------------------------------------------------------------------------
 * gfx_get_display_palette_entry
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_get_display_palette_entry(unsigned long index, unsigned long *palette)
#else
int
gfx_get_display_palette_entry(unsigned long index, unsigned long *palette)
#endif
{
    if (index > 0xFF)
        return GFX_STATUS_BAD_PARAMETER;

    WRITE_REG32(MDC_PAL_ADDRESS, index);
    *palette = READ_REG32(MDC_PAL_DATA);

    return 0;
}

/*----------------------------------------------------------------------------
 * gfx_get_display_palette
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
void
gu2_get_display_palette(unsigned long *palette)
#else
void
gfx_get_display_palette(unsigned long *palette)
#endif
{
    unsigned long i;

    WRITE_REG32(MDC_PAL_ADDRESS, 0);
    for (i = 0; i < 256; i++) {
        palette[i] = READ_REG32(MDC_PAL_DATA);
    }
}

/*----------------------------------------------------------------------------
 * gfx_get_cursor_enable
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned long
gu2_get_cursor_enable(void)
#else
unsigned long
gfx_get_cursor_enable(void)
#endif
{
    return (READ_REG32(MDC_GENERAL_CFG) & MDC_GCFG_CURE);
}

/*----------------------------------------------------------------------------
 * gfx_get_cursor_position
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned long
gu2_get_cursor_position(void)
#else
unsigned long
gfx_get_cursor_position(void)
#endif
{
    return ((READ_REG32(MDC_CURSOR_X) & 0x07FF) |
            ((READ_REG32(MDC_CURSOR_Y) << 16) & 0x07FF0000));
}

/*----------------------------------------------------------------------------
 * gfx_get_cursor_offset
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned long
gu2_get_cursor_clip(void)
#else
unsigned long
gfx_get_cursor_clip(void)
#endif
{
    return (((READ_REG32(MDC_CURSOR_X) >> 11) & 0x03F) |
            ((READ_REG32(MDC_CURSOR_Y) << 5) & 0x3F0000));
}

/*----------------------------------------------------------------------------
 * gfx_get_cursor_color
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned long
gu2_get_cursor_color(int color)
#else
unsigned long
gfx_get_cursor_color(int color)
#endif
{
    if (color) {
        WRITE_REG32(MDC_PAL_ADDRESS, 0x101);
    }
    else {
        WRITE_REG32(MDC_PAL_ADDRESS, 0x100);
    }
    return READ_REG32(MDC_PAL_DATA);
}

/*----------------------------------------------------------------------------
 * gfx_get_icon_enable
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned long
gu2_get_icon_enable(void)
#else
unsigned long
gfx_get_icon_enable(void)
#endif
{
    return (READ_REG32(MDC_GENERAL_CFG) & MDC_GCFG_ICNE);
}

/*----------------------------------------------------------------------------
 * gfx_get_icon_offset
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned long
gu2_get_icon_offset(void)
#else
unsigned long
gfx_get_icon_offset(void)
#endif
{
    return (READ_REG32(MDC_ICON_ST_OFFSET) & 0x0FFFFFFF);
}

/*----------------------------------------------------------------------------
 * gfx_get_icon_position
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned long
gu2_get_icon_position(void)
#else
unsigned long
gfx_get_icon_position(void)
#endif
{
    return (READ_REG32(MDC_ICON_X) & 0x07FF);
}

/*----------------------------------------------------------------------------
 * gfx_get_icon_color
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned long
gu2_get_icon_color(int color)
#else
unsigned long
gfx_get_icon_color(int color)
#endif
{
    if (color >= 3)
        return 0;

    WRITE_REG32(MDC_PAL_ADDRESS, 0x102 + color);

    return READ_REG32(MDC_PAL_DATA);
}

/*----------------------------------------------------------------------------
 * gfx_get_compression_enable
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_get_compression_enable(void)
#else
int
gfx_get_compression_enable(void)
#endif
{
    if (READ_REG32(MDC_GENERAL_CFG) & MDC_GCFG_CMPE)
        return (1);

    return (0);
}

/*----------------------------------------------------------------------------
 * gfx_get_compression_offset
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned long
gu2_get_compression_offset(void)
#else
unsigned long
gfx_get_compression_offset(void)
#endif
{
    return (READ_REG32(MDC_CB_ST_OFFSET) & 0x007FFFFF);
}

/*----------------------------------------------------------------------------
 * gfx_get_compression_pitch
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned short
gu2_get_compression_pitch(void)
#else
unsigned short
gfx_get_compression_pitch(void)
#endif
{
    unsigned short pitch;

    pitch = (unsigned short) (READ_REG32(MDC_GFX_PITCH) >> 16);
    return (pitch << 3);
}

/*----------------------------------------------------------------------------
 * gfx_get_compression_size
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned short
gu2_get_compression_size(void)
#else
unsigned short
gfx_get_compression_size(void)
#endif
{
    unsigned short size;

    size = (unsigned short) ((READ_REG32(MDC_LINE_SIZE) >> 16) & 0x7F) - 1;
    return ((size << 3) + 32);
}

/*----------------------------------------------------------------------------
 * gfx_get_valid_bit
 *----------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_get_valid_bit(int line)
#else
int
gfx_get_valid_bit(int line)
#endif
{
    unsigned long offset;
    int valid;

    offset = READ_REG32(MDC_PHY_MEM_OFFSET) & 0xFF000000;
    offset |= line;

    WRITE_REG32(MDC_PHY_MEM_OFFSET, offset);
    valid = (int) READ_REG32(MDC_DV_ACC) & 2;

    if (valid)
        return 1;
    return 0;
}

/*---------------------------------------------------------------------------
 * gfx_get_display_video_offset (PRIVATE ROUTINE - NOT PART OF API)
 *
 * This routine is called by "gfx_get_video_offset".  It abstracts the 
 * version of the display controller from the video overlay routines.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned long
gu2_get_display_video_offset(void)
#else
unsigned long
gfx_get_display_video_offset(void)
#endif
{
    return (READ_REG32(MDC_VID_Y_ST_OFFSET) & 0x0FFFFFFF);
}

/*---------------------------------------------------------------------------
 * gfx_get_display_video_yuv_offsets (PRIVATE ROUTINE - NOT PART OF API)
 *
 * This routine is called by "gfx_get_video_yuv_offsets".  It abstracts the 
 * version of the display controller from the video overlay routines.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
void
gu2_get_display_video_yuv_offsets(unsigned long *yoffset,
                                  unsigned long *uoffset,
                                  unsigned long *voffset)
#else
void
gfx_get_display_video_yuv_offsets(unsigned long *yoffset,
                                  unsigned long *uoffset,
                                  unsigned long *voffset)
#endif
{
    *yoffset = (READ_REG32(MDC_VID_Y_ST_OFFSET) & 0x0FFFFFFF);
    *uoffset = (READ_REG32(MDC_VID_U_ST_OFFSET) & 0x0FFFFFFF);
    *voffset = (READ_REG32(MDC_VID_V_ST_OFFSET) & 0x0FFFFFFF);
}

/*---------------------------------------------------------------------------
 * gfx_get_display_video_yuv_pitch (PRIVATE ROUTINE - NOT PART OF API)
 *
 * This routine is called by "gfx_get_video_yuv_pitch".  It abstracts the 
 * version of the display controller from the video overlay routines.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
void
gu2_get_display_video_yuv_pitch(unsigned long *ypitch, unsigned long *uvpitch)
#else
void
gfx_get_display_video_yuv_pitch(unsigned long *ypitch, unsigned long *uvpitch)
#endif
{
    unsigned long pitch = READ_REG32(MDC_VID_YUV_PITCH);

    *ypitch = ((pitch & 0xFFFF) << 3);
    *uvpitch = (pitch >> 13) & 0x7FFF8;
}

/*---------------------------------------------------------------------------
 * gfx_get_display_video_downscale_delta (PRIVATE ROUTINE - NOT PART OF API)
 *
 * This routine is called by "gfx_get_video_downscale_delta". It abstracts the
 * version of the display controller from the video overlay routines.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned long
gu2_get_display_video_downscale_delta(void)
#else
unsigned long
gfx_get_display_video_downscale_delta(void)
#endif
{
    return (READ_REG32(MDC_VID_DS_DELTA) >> 18);
}

/*---------------------------------------------------------------------------
 * gfx_get_display_video_downscale_enable (PRIVATE ROUTINE - NOT PART OF API)
 *
 * This routine is called by "gfx_get_video_vertical_downscale_enable". 
 * It abstracts the version of the display controller from the video overlay
 * routines.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
int
gu2_get_display_video_downscale_enable(void)
#else
int
gfx_get_display_video_downscale_enable(void)
#endif
{
    return ((int) ((READ_REG32(MDC_GENERAL_CFG) >> 19) & 1));
}

/*---------------------------------------------------------------------------
 * gfx_get_display_video_size (PRIVATE ROUTINE - NOT PART OF API)
 *
 * This routine is called by "gfx_get_video_size".  It abstracts the 
 * version of the display controller from the video overlay routines.
 *---------------------------------------------------------------------------
 */
#if GFX_DISPLAY_DYNAMIC
unsigned long
gu2_get_display_video_size(void)
#else
unsigned long
gfx_get_display_video_size(void)
#endif
{
    /* RETURN THE LINE SIZE, AS THIS IS ALL THAT IS AVAILABLE */

    return ((READ_REG32(MDC_LINE_SIZE) >> 21) & 0x000007FF);
}

#endif                          /* GFX_READ_ROUTINES */

/* END OF FILE */