summaryrefslogtreecommitdiff
path: root/src/sis.h
blob: df595ae20f3c8a4d85c659051d98436af0694581 (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
/* $XFree86$ */
/* $XdotOrg: xc/programs/Xserver/hw/xfree86/drivers/sis/sis.h,v 1.18 2004/08/20 18:57:06 kem Exp $ */
/*
 * Main global data and definitions
 *
 * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1) Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2) Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3) The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Authors:   Thomas Winischhofer <thomas@winischhofer.net>
 *            others (old code base)
 *
 */

#ifndef _SIS_H
#define _SIS_H_

/* Always unlock the registers (should be set!) */
#define UNLOCK_ALWAYS

#define SISDRIVERVERSIONYEAR    4
#define SISDRIVERVERSIONMONTH   8
#define SISDRIVERVERSIONDAY     20
#define SISDRIVERREVISION       1

#define SISDRIVERIVERSION (SISDRIVERVERSIONYEAR << 16) |  \
			  (SISDRIVERVERSIONMONTH << 8) |  \
                          SISDRIVERVERSIONDAY 	       |  \
			  (SISDRIVERREVISION << 24)

#if 0
#define TWDEBUG    /* for debugging */
#endif

#if 0
#include "siscp.H"
#else
#undef SIS_CP
#endif

#include "xf86Pci.h"
#include "xf86Cursor.h"
#include "xf86_ansic.h"
#include "xf86xv.h"
#include "compiler.h"
#include "xaa.h"
#include "vgaHW.h"
#include "vbe.h"

#include "osdef.h"
#include "vgatypes.h"
#include "vstruct.h"

#ifdef XORG_VERSION_CURRENT
#include "xorgVersion.h"
#endif

#ifdef XORG_VERSION_CURRENT
#define SISMYSERVERNAME "X.org"
#else
#define SISMYSERVERNAME "XFree86"
#endif

#undef SISHAVEDRMWRITE
#undef SISNEWDRI
#ifdef XF86DRI
#if XF86_VERSION_CURRENT >= XF86_VERSION_NUMERIC(4,2,99,3,0)
#define SISHAVEDRMWRITE
#endif
#if XF86_VERSION_CURRENT >= XF86_VERSION_NUMERIC(4,3,99,14,0)
#define SISNEWDRI
#endif
#include "xf86drm.h"
#include "sarea.h"
#define _XF86DRI_SERVER_
#include "xf86dri.h"
#include "dri.h"
#include "GL/glxint.h"
#include "sis_dri.h"
#endif /* XF86DRI */

#if 1
#define SISDUALHEAD  		/* Include Dual Head code  */
#endif

#if 1
#define SISMERGED		/* Include Merged-FB mode */
#endif

#ifdef SISMERGED
#if 1
#define SISXINERAMA		/* Include SiS Pseudo-Xinerama for MergedFB mode */
#define SIS_XINERAMA_MAJOR_VERSION  1
#define SIS_XINERAMA_MINOR_VERSION  1
#endif
#endif

#if 1				/* Include code for gamma correction */
#define SISGAMMA		
#endif

#if 1				/* Include code for color hardware cursors */
#define SIS_ARGB_CURSOR
#endif

#if 1				/* Include YPbPr support on SiS bridges (315 series and 661/741/760) */
#define ENABLE_YPBPR
#endif

#ifdef SISMERGED
#ifdef SISXINERAMA
#define NEED_REPLIES  		/* ? */
#define EXTENSION_PROC_ARGS void *
#include "extnsionst.h"  	/* required */
#include "panoramiXproto.h"  	/* required */
#endif
#endif

#if 1
#define SISVRAMQ		/* Use VRAM queue mode on 315 series */
#endif

/* Include support for YUV->RGB blit adaptors (VRAM queue mode only) */
#undef INCL_YUV_BLIT_ADAPTOR
#ifdef SISVRAMQ
#if 1
#define INCL_YUV_BLIT_ADAPTOR
#endif
#endif

#undef SIS315DRI		/* define this if dri is adapted for 315/330 series */

/* For SiS315/550/650/740/330/660 - these should be moved elsewhere! */
#ifndef PCI_CHIP_SIS315H
#define PCI_CHIP_SIS315H	0x0310
#endif
#ifndef PCI_CHIP_SIS315
#define PCI_CHIP_SIS315		0x0315
#endif
#ifndef PCI_CHIP_SIS315PRO
#define PCI_CHIP_SIS315PRO	0x0325
#endif
#ifndef PCI_CHIP_SIS550
#define PCI_CHIP_SIS550		0x5315	/* 550_VGA */
#endif
#ifndef PCI_CHIP_SIS650
#define PCI_CHIP_SIS650 	0x6325  /* 650_VGA and 740_VGA */
#endif
#ifndef PCI_CHIP_SIS330
#define PCI_CHIP_SIS330 	0x0330
#endif
#ifndef PCI_CHIP_SIS660
#define PCI_CHIP_SIS660 	0x6330	/* 661_VGA, 741_VGA, 760_VGA */
#endif
#ifndef PCI_CHIP_SIS340
#define PCI_CHIP_SIS340 	0x0340
#endif

#define SIS_NAME                "SIS"
#define SIS_DRIVER_NAME         "sis"
#define SIS_MAJOR_VERSION       0
#define SIS_MINOR_VERSION       7
#define SIS_PATCHLEVEL          0
#define SIS_CURRENT_VERSION     ((SIS_MAJOR_VERSION << 16) | \
                                 (SIS_MINOR_VERSION << 8) | SIS_PATCHLEVEL )

/* pSiS->Flags (old series only) */
#define SYNCDRAM                0x00000001
#define RAMFLAG                 0x00000002
#define ESS137xPRESENT          0x00000004
#define SECRETFLAG              0x00000008
#define A6326REVAB              0x00000010
#define MMIOMODE                0x00010000
#define LFBQMODE                0x00020000
#define AGPQMODE                0x00040000
#define UMA                     0x80000000

#define BIOS_BASE               0xC0000
#define BIOS_SIZE               0x10000

#define SR_BUFFER_SIZE          5
#define CR_BUFFER_SIZE          5

#define SIS_VBFlagsVersion	1

/* VBFlags - if anything is changed here, increase VBFlagsVersion! */
#define CRT2_DEFAULT            0x00000001
#define CRT2_LCD                0x00000002  /* Never change the order of the CRT2_XXX entries */
#define CRT2_TV                 0x00000004  
#define CRT2_VGA                0x00000008
#define TV_NTSC                 0x00000010
#define TV_PAL                  0x00000020
#define TV_HIVISION             0x00000040
#define TV_YPBPR                0x00000080
#define TV_AVIDEO               0x00000100
#define TV_SVIDEO               0x00000200
#define TV_SCART                0x00000400
#define VB_CONEXANT		0x00000800   /* 661 series only */
#define VB_TRUMPION		VB_CONEXANT  /* 300 series only */
#define TV_PALM                 0x00001000
#define TV_PALN                 0x00002000
#define TV_NTSCJ		0x00001000
#define VB_302ELV		0x00004000
#define TV_CHSCART              0x00008000
#define TV_CHYPBPR525I          0x00010000
#define CRT1_VGA		0x00000000
#define CRT1_LCDA		0x00020000
#define VGA2_CONNECTED          0x00040000
#define DISPTYPE_CRT1		0x00080000  	/* CRT1 connected and used */
#define VB_301                  0x00100000	/* Video bridge type */
#define VB_301B                 0x00200000
#define VB_302B                 0x00400000
#define VB_30xBDH		0x00800000      /* 30xB DH version (w/o LCD support) */
#define VB_LVDS                 0x01000000
#define VB_CHRONTEL             0x02000000
#define VB_301LV                0x04000000
#define VB_302LV                0x08000000
#define VB_301C			0x10000000
#define SINGLE_MODE             0x20000000   	/* CRT1 or CRT2; determined by DISPTYPE_CRTx */
#define MIRROR_MODE		0x40000000   	/* CRT1 + CRT2 identical (mirror mode) */
#define DUALVIEW_MODE		0x80000000   	/* CRT1 + CRT2 independent (dual head mode) */

/* Aliases: */
#define CRT2_ENABLE		(CRT2_LCD | CRT2_TV | CRT2_VGA)
#define TV_STANDARD             (TV_NTSC | TV_PAL | TV_PALM | TV_PALN | TV_NTSCJ)
#define TV_INTERFACE            (TV_AVIDEO|TV_SVIDEO|TV_SCART|TV_HIVISION|TV_YPBPR)

/* Only if TV_YPBPR is set: */
#define TV_YPBPR525I		TV_NTSC
#define TV_YPBPR525P		TV_PAL
#define TV_YPBPR750P		TV_PALM
#define TV_YPBPR1080I	        TV_PALN
#define TV_YPBPRALL 		(TV_YPBPR525I | TV_YPBPR525P | TV_YPBPR750P | TV_YPBPR1080I)

#define TV_YPBPR43LB		TV_CHSCART
#define TV_YPBPR43		TV_CHYPBPR525I
#define TV_YPBPR169 		(TV_CHSCART | TV_CHYPBPR525I)
#define TV_YPBPRAR              (TV_CHSCART | TV_CHYPBPR525I)

#define VB_SISBRIDGE            (VB_301|VB_301B|VB_301C|VB_302B|VB_301LV|VB_302LV|VB_302ELV)
#define VB_SISTVBRIDGE          (VB_301|VB_301B|VB_301C|VB_302B|VB_301LV|VB_302LV)
#define VB_VIDEOBRIDGE		(VB_SISBRIDGE | VB_LVDS | VB_CHRONTEL | VB_CONEXANT)
#define VB_SISLVDSBRIDGE        (VB_301LV|VB_302LV|VB_302ELV)
#define VB_SISTMDSBRIDGE	(VB_301|VB_301B|VB_301C|VB_302B)
#define VB_SISTMDSLCDABRIDGE	(VB_301C)
#define VB_SISVGA2BRIDGE  	(VB_301|VB_301B|VB_301C|VB_302B)
#define VB_SISLCDABRIDGE 	(VB_301C|VB_302B|VB_301LV|VB_302LV|VB_302ELV)
#define VB_SISHIVISIONBRIDGE	(VB_301|VB_301B|VB_302B)
#define VB_SISYPBPRBRIDGE	(VB_301C|VB_301LV|VB_302LV|VB_302ELV)
#define VB_SISYPBPRARBRIDGE	(VB_301C)
#define VB_SISTAP4SCALER	(VB_301C|VB_302ELV)

#define DISPTYPE_DISP2		CRT2_ENABLE
#define DISPTYPE_DISP1		DISPTYPE_CRT1
#define VB_DISPMODE_SINGLE	SINGLE_MODE  	/* alias */
#define VB_DISPMODE_MIRROR	MIRROR_MODE  	/* alias */
#define VB_DISPMODE_DUAL	DUALVIEW_MODE 	/* alias */
#define DISPLAY_MODE            (SINGLE_MODE | MIRROR_MODE | DUALVIEW_MODE)

/* pSiS->VBFlags2 (static stuff only!) */
#define VB_SISUMC		0x00000001

/* pSiS->VBLCDFlags */
#define VB_LCD_320x480		0x00000001	/* DSTN/FSTN for 550 */
#define VB_LCD_640x480          0x00000002
#define VB_LCD_800x600          0x00000004
#define VB_LCD_1024x768         0x00000008
#define VB_LCD_1280x1024        0x00000010
#define VB_LCD_1280x960    	0x00000020
#define VB_LCD_1600x1200	0x00000040
#define VB_LCD_2048x1536	0x00000080
#define VB_LCD_1400x1050        0x00000100
#define VB_LCD_1152x864         0x00000200
#define VB_LCD_1152x768         0x00000400
#define VB_LCD_1280x768         0x00000800
#define VB_LCD_1024x600         0x00001000
#define VB_LCD_640x480_2	0x00002000  	/* DSTN/FSTN */
#define VB_LCD_640x480_3	0x00004000  	/* DSTN/FSTN */
#define VB_LCD_848x480		0x00008000	/* LVDS only, otherwise handled as custom */
#define VB_LCD_1280x800		0x00010000
#define VB_LCD_1680x1050	0x00020000
#define VB_LCD_1280x720         0x00040000
#define VB_LCD_BARCO1366        0x20000000
#define VB_LCD_CUSTOM  		0x40000000
#define VB_LCD_EXPANDING	0x80000000

#define VB_FORBID_CRT2LCD_OVER_1600		/* CRT2/LCD supports only up to 1600 pixels */

/* PresetMode argument */
#define SIS_MODE_SIMU 		0
#define SIS_MODE_CRT1 		1
#define SIS_MODE_CRT2 		2

/* pSiS->MiscFlags */
#define MISC_CRT1OVERLAY	0x00000001  /* Current display mode supports overlay */
#define MISC_PANELLINKSCALER    0x00000002  /* Panel link is currently scaling */
#define MISC_CRT1OVERLAYGAMMA	0x00000004  /* Current display mode supports overlay gamma corr on CRT1 */
#define MISC_TVNTSC1024		0x00000008  /* Current display mode is TV NTSC/PALM/YPBPR525I 1024x768  */

/* SiS6326Flags */
#define SIS6326_HASTV		0x00000001
#define SIS6326_TVSVIDEO        0x00000002
#define SIS6326_TVCVBS          0x00000004
#define SIS6326_TVPAL		0x00000008
#define SIS6326_TVDETECTED      0x00000010
#define SIS6326_TVON            0x80000000

#define HW_DEVICE_EXTENSION	SIS_HW_INFO

#ifdef  DEBUG
#define PDEBUG(p)       p
#else
#define PDEBUG(p)
#endif

#define BITMASK(h,l)             (((unsigned)(1U << ((h)-(l)+1))-1)<<(l))
#define GENMASK(mask)            BITMASK(1?mask,0?mask)

typedef unsigned long ULong;
typedef unsigned short UShort;
typedef unsigned char UChar;

/* VGA engine types */
#define UNKNOWN_VGA 0
#define SIS_530_VGA 1
#define SIS_OLD_VGA 2
#define SIS_300_VGA 3
#define SIS_315_VGA 4   /* Includes 330/660/661/741/760 and M versions thereof */

/* oldChipset */
#define OC_UNKNOWN   0
#define OC_SIS86201  1
#define OC_SIS86202  2
#define OC_SIS6205A  3
#define OC_SIS6205B  4
#define OC_SIS82204  5
#define OC_SIS6205C  6
#define OC_SIS6225   7
#define OC_SIS5597   8
#define OC_SIS6326   9
#define OC_SIS530A  11
#define OC_SIS530B  12
#define OC_SIS620   13

/* Chrontel type */
#define CHRONTEL_700x 0
#define CHRONTEL_701x 1

/* ChipFlags */
/* Use only lower 16 bit for chip id! (sisctrl) */
#define SiSCF_LARGEOVERLAY  0x00000001
#define SiSCF_Is651         0x00000002
#define SiSCF_IsM650        0x00000004
#define SiSCF_IsM652        0x00000008
#define SiSCF_IsM653        0x00000010
#define SiSCF_Is652         0x00000020
#define SiSCF_Is65x         (SiSCF_Is651|SiSCF_IsM650|SiSCF_IsM652|SiSCF_IsM653|SiSCF_Is652)
#define SiSCF_IsM661        0x00000100  /* M661FX */
#define SiSCF_IsM741        0x00000200
#define SiSCF_IsM760        0x00000400
#define SiSCF_IsM661M       0x00000800  /* M661MX */
#define SiSCF_IsM66x        (SiSCF_IsM661 | SiSCF_IsM741 | SiSCF_IsM760 | SiSCF_IsM661M)
#define SiSCF_315Core       0x00010000  /* 3D: Real 315 */
#define SiSCF_Real256ECore  0x00020000  /* 3D: Similar to 315 core, no T&L? (65x, 661, 740, 741) */
#define SiSCF_XabreCore     0x00040000  /* 3D: Real Xabre */
#define SiSCF_Ultra256Core  0x00080000  /* 3D: aka "Mirage 2"; similar to Xabre, no T&L?, no P:Shader? (760) */
#define SiSCF_UseLCDA       0x01000000  
#define SiSCF_760LFB        0x08000000  /* 760: LFB active (if not set, UMA only) */
#define SiSCF_760UMA        0x10000000  /* 760: UMA active (if not set, LFB only) */
#define SiSCF_CRT2HWCKaputt 0x20000000  /* CRT2 Mono HWCursor engine buggy (SiS 330) */
#define SiSCF_Glamour3      0x40000000
#define SiSCF_Integrated    0x80000000

/* SiS Direct Xv-API */
#define SiS_SD_IS300SERIES     0x00000001
#define SiS_SD_IS315SERIES     0x00000002
#define SiS_SD_IS330SERIES     0x00000004
#define SiS_SD_SUPPORTPALMN    0x00000008   /* tv chip supports pal-m, pal-n */
#define SiS_SD_SUPPORT2OVL     0x00000010   /* set = 2 overlays, clear = support SWITCHCRT xv prop */
#define SiS_SD_SUPPORTTVPOS    0x00000020   /* supports changing tv position */
#define SiS_SD_ISDUALHEAD      0x00000040   /* Driver is in dual head mode */
#define SiS_SD_ISMERGEDFB      0x00000080   /* Driver is in merged fb mode */
#define SiS_SD_ISDHSECONDHEAD  0x00000100   /* Dual head: This is CRT1 (=second head) */
#define SiS_SD_ISDHXINERAMA    0x00000200   /* Dual head: We are running Xinerama */
#define SiS_SD_VBHASSCART      0x00000400   /* videobridge has SCART instead of VGA2 */
#define SiS_SD_ISDEPTH8        0x00000800   /* Depth is 8, no independent gamma correction */
#define SiS_SD_SUPPORTSOVER    0x00001000   /* Support for Chrontel Super Overscan */
#define SiS_SD_ENABLED         0x00002000   /* sisctrl is enabled (by option) */
#define SiS_SD_PSEUDOXINERAMA  0x00004000   /* pseudo xinerama is active */
#define SiS_SD_SUPPORTLCDA     0x00008000   /* Support LCD Channel A */
#define SiS_SD_SUPPORTNTSCJ    0x00010000   /* tv chip supports ntsc-j */
#define SiS_SD_ADDLSUPFLAG     0x00020000   /* 1 = the following flags are valid */
#define SiS_SD_SUPPORTVGA2     0x00040000   /* CRT2=VGA supported */
#define SiS_SD_SUPPORTSCART    0x00080000   /* CRT2=SCART supported */
#define SiS_SD_SUPPORTOVERSCAN 0x00100000   /* Overscan flag supported */
#define SiS_SD_SUPPORTXVGAMMA1 0x00200000   /* Xv Gamma correction for CRT1 supported */
#define SiS_SD_SUPPORTTV       0x00400000   /* CRT2=TV supported */
#define SiS_SD_SUPPORTYPBPR    0x00800000   /* CRT2=YPbPr (525i, 525p, 750p, 1080i) is supported */
#define SiS_SD_SUPPORTHIVISION 0x01000000   /* CRT2=HiVision is supported */
#define SiS_SD_SUPPORTYPBPRAR  0x02000000   /* YPbPr aspect ratio is supported */
#define SiS_SD_SUPPORTSCALE    0x04000000   /* Scaling of LCD panel supported */
#define SiS_SD_SUPPORTCENTER   0x08000000   /* If scaling supported: Centering of screen [NOT] supported (TMDS only) */
#define SiS_SD_SUPPORTREDETECT 0x10000000   /* Support re-detection of CRT2 devices */
#define SiS_SD_IS340SERIES     0x20000000

#define SIS_DIRECTKEY         0x03145792

/* SiSCtrl: Check mode for CRT2 */
#define SiS_CF2_LCD          0x01
#define SiS_CF2_TV           0x02
#define SiS_CF2_VGA2         0x04
#define SiS_CF2_TVPAL        0x08
#define SiS_CF2_TVNTSC       0x10  /* + NTSC-J */
#define SiS_CF2_TVPALM       0x20
#define SiS_CF2_TVPALN       0x40
#define SiS_CF2_CRT1LCDA     0x80
#define SiS_CF2_TYPEMASK     (SiS_CF2_LCD | SiS_CF2_TV | SiS_CF2_VGA2 | SiS_CF2_CRT1LCDA)
#define SiS_CF2_TVSPECIAL    (SiS_CF2_LCD | SiS_CF2_TV)
#define SiS_CF2_TVSPECMASK   (SiS_CF2_TVPAL | SiS_CF2_TVNTSC | SiS_CF2_TVPALM | SiS_CF2_TVPALN)
#define SiS_CF2_TVHIVISION   SiS_CF2_TVPAL
#define SiS_CF2_TVYPBPR525I  SiS_CF2_TVNTSC
#define SiS_CF2_TVYPBPR525P  (SiS_CF2_TVPAL | SiS_CF2_TVNTSC)
#define SiS_CF2_TVYPBPR750P  SiS_CF2_TVPALM
#define SiS_CF2_TVYPBPR1080I (SiS_CF2_TVPALM | SiS_CF2_TVPAL)

/* AGP stuff for DRI */
#define AGP_PAGE_SIZE 4096
#define AGP_PAGES     2048	 /* Default: 2048 pages @ 4096 = 8MB */
/* 300 */
#define AGP_CMDBUF_PAGES 256
#define AGP_CMDBUF_SIZE (AGP_PAGE_SIZE * AGP_CMDBUF_PAGES)
/* 315/330 */
#define AGP_VTXBUF_PAGES 512
#define AGP_VTXBUF_SIZE (AGP_PAGE_SIZE * AGP_VTXBUF_PAGES)

/* Used for mapping a0000 and saving/restoring fonts (or not doing so) */
/* List of architectures likely to be incomplete */
#define SIS_PC_PLATFORM
#if defined(__powerpc__) || defined(__mips__) || defined(__arm32__)
#undef SIS_PC_PLATFORM
#endif

#if 0
/* Used for mapping i/o port area to virtual memory (or not doing so) */
/* List of architectures likely to be incomplete */
/* BROKEN, see comment in sis_driver.c */
#undef SIS_NEED_MAP_IOP
#if defined(__arm32__) || defined(__mips__) 
#define SIS_NEED_MAP_IOP
#endif
#endif

/* Used for makeing use of the BIOS scratch area (save/restore mode number) */
#undef SIS_USE_BIOS_SCRATCH
#if (defined(i386) || defined(__i386) || defined(__i386__) || defined(__AMD64__))
#define SIS_USE_BIOS_SCRATCH
#endif

/* For backup of register contents */
typedef struct {
    unsigned char sisRegs3C4[0x50];
    unsigned char sisRegs3D4[0x90];
    unsigned char sisRegs3C2;
    unsigned char sisCapt[0x60];
    unsigned char sisVid[0x50];
    unsigned char VBPart1[0x50];
    unsigned char VBPart2[0x100];
    unsigned char VBPart3[0x50];
    unsigned char VBPart4[0x50];
    unsigned short ch70xx[64];
    unsigned long sisMMIO85C0;
    unsigned char sis6326tv[0x46];
    unsigned long sisRegsPCI50, sisRegsPCIA0;
    unsigned char BIOSModeSave;
} SISRegRec, *SISRegPtr;

typedef struct _sisModeInfoPtr {
    int width;
    int height;
    int bpp;
    int n;
    struct _sisModeInfoPtr *next;
} sisModeInfoRec, *sisModeInfoPtr;

/* SISFBLayout is mainly there because of DGA. It holds the
 * current layout parameters needed for acceleration and other
 * stuff. When switching mode using DGA, these are set up
 * accordingly and not necessarily match pScrn's. Therefore,
 * driver modules should read these values instead of pScrn's.
 */
typedef struct {
    int                bitsPerPixel;   	/* = pScrn->bitsPerPixel */
    int                depth;		/* = pScrn->depth */
    int                displayWidth;	/* = pScrn->displayWidth */
    DisplayModePtr     mode;		/* = pScrn->currentMode */
} SISFBLayout;

/* Dual head private entity structure */
#ifdef SISDUALHEAD
typedef struct {
    ScrnInfoPtr         pScrn_1;
    ScrnInfoPtr         pScrn_2;
    unsigned char *     BIOS;
    SiS_Private   *     SiS_Pr;
    unsigned long 	agpHandle;
    unsigned long	agpAddr;
    unsigned char 	*agpBase;
    unsigned int 	agpSize;
    unsigned int        agpWantedSize;
    unsigned int        agpWantedPages;
    unsigned long	agpCmdBufAddr;  /* 300 series */
    unsigned char 	*agpCmdBufBase;
    unsigned int 	agpCmdBufSize;
    unsigned int 	agpCmdBufFree;
    unsigned long	agpVtxBufAddr;	/* 315 series */
    unsigned char       *agpVtxBufBase;
    unsigned int        agpVtxBufSize;
    unsigned int        agpVtxBufFree;
#ifdef XF86DRI
    sisRegion 		agp;
    int 		drmSubFD;
#endif
    Bool		AGPInitOK;
    int			CRT1ModeNo;		/* Current display mode for CRT1 */
    DisplayModePtr	CRT1DMode;		/* Current display mode for CRT1 */
    int 		CRT2ModeNo;		/* Current display mode for CRT2 */
    DisplayModePtr	CRT2DMode;		/* Current display mode for CRT2 */
    Bool		CRT2ModeSet;		/* CRT2 mode has been set */
    Bool		CRT2IsCustom;
    unsigned char	CRT2CR30, CRT2CR31, CRT2CR35, CRT2CR38;
    int			refCount;
    int 		lastInstance;		/* number of entities */
    Bool		DisableDual;		/* Emergency flag */
    Bool		ErrorAfterFirst;	/* Emergency flag: Error after first init -> Abort second */
    Bool		HWCursor;		/* Backup master settings for use on slave */
    Bool                TurboQueue;
    int                 ForceCRT1Type;
    int                 ForceCRT2Type;
    int                 OptTVStand;
    int                 OptTVOver;
    int			OptTVSOver;
    int                 OptROMUsage;
    int			OptUseOEM;
    Bool                NoAccel;
    int			forceCRT1;
    int			DSTN, FSTN;
    Bool		XvOnCRT2;
    int                 maxUsedClock;  		/* Max used pixelclock on master head */
    unsigned long       masterFbAddress;	/* Framebuffer addresses and sizes */
    unsigned long	masterFbSize;
    unsigned long       slaveFbAddress;
    unsigned long	slaveFbSize;
    unsigned char *     FbBase;         	/* VRAM linear address */
    unsigned char *     IOBase;         	/* MMIO linear address */
    unsigned short      MapCountIOBase;		/* map/unmap queue counter */
    unsigned short      MapCountFbBase;		/* map/unmap queue counter */
    Bool 		forceUnmapIOBase;	/* ignore counter and unmap */
    Bool		forceUnmapFbBase;	/* ignore counter and unmap */
#ifdef __alpha__
    unsigned char *     IOBaseDense;    	/* MMIO for Alpha platform */
    unsigned short      MapCountIOBaseDense;
    Bool		forceUnmapIOBaseDense;  /* ignore counter and unmap */
#endif
    int			chtvlumabandwidthcvbs;  /* TV settings for Chrontel TV encoder */
    int			chtvlumabandwidthsvideo;
    int			chtvlumaflickerfilter;
    int			chtvchromabandwidth;
    int			chtvchromaflickerfilter;
    int			chtvcvbscolor;
    int			chtvtextenhance;
    int			chtvcontrast;
    int			sistvedgeenhance;	/* TV settings for SiS bridge */
    int			sistvantiflicker;
    int			sistvsaturation;
    int       		sistvcolcalibc;
    int       		sistvcolcalibf;
    int			sistvcfilter;
    int			sistvyfilter;
    int			tvxpos, tvypos;
    int		      	tvxscale, tvyscale;
    int			ForceTVType, SenseYPbPr;
    unsigned long	ForceYPbPrType, ForceYPbPrAR;
    int			chtvtype;
    int                 NonDefaultPAL, NonDefaultNTSC;
    unsigned short	tvx, tvy;
    unsigned char	p2_01, p2_02, p2_1f, p2_20, p2_43, p2_42, p2_2b;
    unsigned char	p2_44, p2_45, p2_46;
    unsigned long       sistvccbase;
    unsigned char       p2_35, p2_36, p2_37, p2_38, p2_48, p2_49, p2_4a;
    unsigned char	p2_0a, p2_2f, p2_30, p2_47;
    unsigned char       scalingp1[9], scalingp4[9], scalingp2[64];
    unsigned short      cursorBufferNum;
    BOOLEAN		restorebyset;
    BOOLEAN		CRT1gamma, CRT1gammaGiven, CRT2gamma, XvGamma, XvGammaGiven, XvDefAdaptorBlit;
    int			XvGammaRed, XvGammaGreen, XvGammaBlue;
    int			GammaBriR, GammaBriG, GammaBriB;	/* strictly for Xinerama */
    int			GammaPBriR, GammaPBriG, GammaPBriB;	/* strictly for Xinerama */
    int			curxvcrtnum;
    int			UsePanelScaler, CenterLCD;
    int			AllowHotkey;
    BOOLEAN		enablesisctrl;
    unsigned long	cmdQ_SharedWritePort_2D;
    unsigned char       *RenderAccelArray;
    unsigned char *	FbBase1;
    unsigned long	OnScreenSize1;
    unsigned char       OldMode;
    int			HWCursorMBufNum, HWCursorCBufNum;
    BOOLEAN		ROM661New;
#ifdef SIS_NEED_MAP_IOP   
    CARD32              IOPAddress;      	/* I/O port physical address */
    unsigned char *     IOPBase;         	/* I/O port linear address */
    unsigned short      MapCountIOPBase;	/* map/unmap queue counter */
    Bool 		forceUnmapIOPBase;	/* ignore counter and unmap */   
#endif    
#ifdef SIS_CP
    SIS_CP_H_ENT
#endif
} SISEntRec, *SISEntPtr;
#endif

#define SISPTR(p)       ((SISPtr)((p)->driverPrivate))
#define XAAPTR(p)       ((XAAInfoRecPtr)(SISPTR(p)->AccelInfoPtr))

/* Relative merge position */
typedef enum {
   sisLeftOf,
   sisRightOf,
   sisAbove,
   sisBelow,
   sisClone
} SiSScrn2Rel;

typedef struct {
    ScrnInfoPtr         pScrn;		/* -------------- DON'T INSERT ANYTHING HERE --------------- */
    pciVideoPtr         PciInfo;	/* -------- OTHERWISE sis_dri.so MUST BE RECOMPILED -------- */
    PCITAG              PciTag;
    EntityInfoPtr       pEnt;
    int                 Chipset;
    int                 ChipRev;
    int			VGAEngine;      /* see above */
    int	                hasTwoOverlays; /* Chipset supports two video overlays? */
    HW_DEVICE_EXTENSION sishw_ext;      /* For new mode switching code */
    SiS_Private   *     SiS_Pr;         /* For new mode switching code */
    int			DSTN; 		/* For 550 FSTN/DSTN; set by option, no detection */
    unsigned long       FbAddress;      /* VRAM physical address (in DHM: for each Fb!) */
    unsigned long       realFbAddress;  /* For DHM/PCI mem mapping: store global FBAddress */
    unsigned char *     FbBase;         /* VRAM virtual linear address */
    CARD32              IOAddress;      /* MMIO physical address */
    unsigned char *     IOBase;         /* MMIO linear address */
    IOADDRESS           IODBase;        /* Base of PIO memory area */
#ifdef __alpha__
    unsigned char *     IOBaseDense;    /* MMIO for Alpha platform */
#endif
    SISIOADDRESS        RelIO;          /* Relocated IO Ports baseaddress */
    unsigned char *     BIOS;
    int                 MemClock;
    int                 BusWidth;
    int                 MinClock;
    int                 MaxClock;
    int                 Flags;          /* HW config flags */
    long                FbMapSize;	/* Used for Mem Mapping - DON'T CHANGE THIS */
    long                availMem;       /* Really available Fb mem (minus TQ, HWCursor) */
    unsigned long	maxxfbmem;      /* limit fb memory X is to use to this (KB) */
    unsigned long       sisfbMem;       /* heapstart of sisfb (if running) */
#ifdef SISDUALHEAD
    unsigned long	dhmOffset;	/* Offset to memory for each head (0 or ..) */
#endif
    DGAModePtr          DGAModes;
    int                 numDGAModes;
    Bool                DGAactive;
    int                 DGAViewportStatus;
    unsigned char       OldMode;        /* Back old modeNo (if available) */
    Bool                NoAccel;
    Bool                NoXvideo;
    Bool		XvOnCRT2;       /* see sis_opt.c */
    Bool                HWCursor;
    Bool                UsePCIRetry;
    Bool                TurboQueue;
    int			VESA;
    int                 ForceCRT1Type;
    int                 ForceCRT2Type;
    int                 OptTVStand;
    int                 OptTVOver;
    int                 OptROMUsage;
    int                 UseCHOverScan;
    Bool                ValidWidth;
    Bool                FastVram;		/* now unused */
    int			forceCRT1;
    Bool		CRT1changed;
    unsigned char       oldCR17, oldCR63, oldSR1F;
    unsigned char       oldCR32, oldCR36, oldCR37;
    unsigned char       myCR32, myCR36, myCR37, myCR63;
    unsigned char       newCR32;
    unsigned long   	VBFlags;		/* Video bridge configuration */
    unsigned long	VBFlags2;		/* Video bridge configuration 2 (static flags only) */
    unsigned long       VBFlags_backup;         /* Backup for SlaveMode-modes */
    unsigned long	VBLCDFlags;             /* Moved LCD panel size bits here */
    int                 ChrontelType;           /* CHRONTEL_700x or CHRONTEL_701x */
    unsigned int        PDC, PDCA;		/* PanelDelayCompensation */
    short               scrnOffset;		/* Screen pitch (data) */
    short               scrnPitch;		/* Screen pitch (display; regarding interlace) */
    short               DstColor;
    int                 xcurrent;               /* for temp use in accel */
    int                 ycurrent;               /* for temp use in accel */
    long		SiS310_AccelDepth; 	/* used in accel for 315 series */
    int                 Xdirection;  		/* for temp use in accel */
    int                 Ydirection;  		/* for temp use in accel */
    int                 sisPatternReg[4];
    int                 ROPReg;
    int                 CommandReg;
    int                 MaxCMDQueueLen;
    int                 CurCMDQueueLen;
    int                 MinCMDQueueLen;
    CARD16		CursorSize;  		/* Size of HWCursor area (bytes) */
    CARD32		cursorOffset;		/* see sis_driver.c and sis_cursor.c */
    int                 DstX;
    int                 DstY;
    unsigned char *     XAAScanlineColorExpandBuffers[2];
    CARD32              AccelFlags;
    Bool                ClipEnabled;
    Bool                DoColorExpand;
    Bool                ColorExpandBusy;
    Bool                alphaBlitBusy;
    SISRegRec           SavedReg;
    SISRegRec           ModeReg;
    xf86CursorInfoPtr   CursorInfoPtr;
    XAAInfoRecPtr       AccelInfoPtr;
    CloseScreenProcPtr  CloseScreen;
    Bool        	(*ModeInit)(ScrnInfoPtr pScrn, DisplayModePtr mode);
    void        	(*SiSSave)(ScrnInfoPtr pScrn, SISRegPtr sisreg);
    void        	(*SiSSave2)(ScrnInfoPtr pScrn, SISRegPtr sisreg);
    void        	(*SiSSave3)(ScrnInfoPtr pScrn, SISRegPtr sisreg);
    void        	(*SiSSaveLVDSChrontel)(ScrnInfoPtr pScrn, SISRegPtr sisreg);
    void        	(*SiSRestore)(ScrnInfoPtr pScrn, SISRegPtr sisreg);
    void        	(*SiSRestore2)(ScrnInfoPtr pScrn, SISRegPtr sisreg);
    void        	(*SiSRestore3)(ScrnInfoPtr pScrn, SISRegPtr sisreg);
    void        	(*SiSRestoreLVDSChrontel)(ScrnInfoPtr pScrn, SISRegPtr sisreg);
    void        	(*LoadCRT2Palette)(ScrnInfoPtr pScrn, int numColors,
                		int *indicies, LOCO *colors, VisualPtr pVisual);

    int       		cmdQueueLen;		/* Current cmdQueueLength (for 2D and 3D) */
    unsigned long	cmdQueueLenMax;
    unsigned long	cmdQueueLenMin;
    unsigned long	*cmdQueueBase;
    int			*cmdQueueLenPtr;	/* Ptr to variable holding the current queue length */
    int			*cmdQueueLenPtrBackup;	/* Backup for DRI init/restore */
    unsigned int        cmdQueueOffset;
    unsigned int        cmdQueueSize;
    unsigned long       cmdQueueSizeMask;
    unsigned long	cmdQ_SharedWritePort_2D;
    unsigned long	*cmdQ_SharedWritePort;
    unsigned long	*cmdQ_SharedWritePortBackup;
    unsigned int        cmdQueueSize_div2;
    unsigned int        cmdQueueSize_div4;
    unsigned int        cmdQueueSize_4_3;
    unsigned long 	agpHandle;
    unsigned long	agpAddr;
    unsigned char 	*agpBase;
    unsigned int 	agpSize;
    unsigned int        agpWantedSize;
    unsigned int        agpWantedPages;
    unsigned long	agpCmdBufAddr;  /* 300 series */
    unsigned char 	*agpCmdBufBase;
    unsigned int 	agpCmdBufSize;
    unsigned int 	agpCmdBufFree;
    unsigned long	agpVtxBufAddr;	/* 315 series */
    unsigned char       *agpVtxBufBase;
    unsigned int        agpVtxBufSize;
    unsigned int        agpVtxBufFree;
#ifdef XF86DRI
    sisRegion 		agp;
#endif
    Bool		AGPInitOK;
    Bool 		irqEnabled;
    int 		irq;
    Bool		IsAGPCard;
    unsigned long	DRIheapstart, DRIheapend;
    Bool		NeedFlush;  /* Need to flush cmd buf mem (760) */

    void		(*RenderCallback)(ScrnInfoPtr);
    Time		RenderTime;
    unsigned char       *RenderAccelArray;
    Bool		doRender;

    int 		ColorExpandRingHead;
    int 		ColorExpandRingTail;
    int 		PerColorExpandBufferSize;
    int 		ColorExpandBufferNumber;
    int 		ColorExpandBufferCountMask;
    unsigned char 	*ColorExpandBufferAddr[32];
    CARD32 		ColorExpandBufferScreenOffset[32];
    CARD32     		ColorExpandBase;
    int 		ImageWriteBufferSize;
    unsigned char 	*ImageWriteBufferAddr;

    int 		Rotate;
    void        	(*PointerMoved)(int index, int x, int y);

    /* ShadowFB support */
    Bool 		ShadowFB;
    unsigned char 	*ShadowPtr;
    int  		ShadowPitch;

    Bool		loadDRI;

#ifdef XF86DRI
    Bool 		directRenderingEnabled;
    DRIInfoPtr 		pDRIInfo;
    int 		drmSubFD;
    int 		numVisualConfigs;
    __GLXvisualConfig* 	pVisualConfigs;
    SISConfigPrivPtr 	pVisualConfigsPriv;
    SISRegRec 		DRContextRegs;
#endif

    XF86VideoAdaptorPtr adaptor;
    XF86VideoAdaptorPtr blitadaptor;
    void *              blitPriv;
    ScreenBlockHandlerProcPtr BlockHandler;
    void                (*VideoTimerCallback)(ScrnInfoPtr, Time);
    void		(*ResetXv)(ScrnInfoPtr);
    void		(*ResetXvGamma)(ScrnInfoPtr);

    OptionInfoPtr 	Options;
    unsigned char 	LCDon;
#ifdef SISDUALHEAD
    Bool		BlankCRT1, BlankCRT2;
#endif
    Bool 		Blank;
    unsigned char 	BIOSModeSave;
    int 		CRT1off;		/* 1=CRT1 off, 0=CRT1 on */
    CARD16 		LCDheight;		/* Vertical resolution of LCD panel */
    CARD16 		LCDwidth;		/* Horizontal resolution of LCD panel */
    vbeInfoPtr 		pVbe;			/* For VESA mode switching */
    CARD16 		vesamajor;
    CARD16 		vesaminor;
    VbeInfoBlock 	*vbeInfo;
    int 		UseVESA;
    sisModeInfoPtr      SISVESAModeList;
    xf86MonPtr 		monitor;
    CARD16 		maxBytesPerScanline;
    CARD32 		*pal, *savedPal;
    int 		mapPhys, mapOff, mapSize;
    int 		statePage, stateSize, stateMode;
    CARD8 		*fonts;
    CARD8 		*state, *pstate;
    void 		*base, *VGAbase;
#ifdef SISDUALHEAD
    BOOL 		DualHeadMode;		/* TRUE if we use dual head mode */
    BOOL 		SecondHead;		/* TRUE is this is the second head */
    SISEntPtr 		entityPrivate;		/* Ptr to private entity (see above) */
    BOOL		SiSXinerama;		/* Do we use Xinerama mode? */
#endif
    SISFBLayout         CurrentLayout;		/* Current framebuffer layout */
    USHORT              SiS_DDC2_Index;
    USHORT              SiS_DDC2_Data;
    USHORT              SiS_DDC2_Clk;
    BOOL		Primary;		/* Display adapter is primary */
    xf86Int10InfoPtr    pInt;			/* Our int10 */
    int                 oldChipset;		/* Type of old chipset */
    int              	RealVideoRam;		/* 6326 can only address 4MB, but TQ can be above */
    CARD32              CmdQueLenMask;		/* Mask of queue length in MMIO register */
    CARD32              CmdQueLenFix;           /* Fix value to subtract from QueLen (530/620) */
    CARD32              CmdQueMaxLen;           /* (6326/5597/5598) Amount of cmds the queue can hold */
    CARD32              TurboQueueLen;		/* For future use */
    CARD32              detectedCRT2Devices;	/* detected CRT2 devices before mask-out */
    Bool                NoHostBus;		/* Enable/disable 5597/5598 host bus */
    Bool		noInternalModes;	/* Use our own default modes? */
    int			OptUseOEM;		/* Use internal OEM data? */
    int			chtvlumabandwidthcvbs;  /* TV settings for Chrontel TV encoder */
    int			chtvlumabandwidthsvideo;
    int			chtvlumaflickerfilter;
    int			chtvchromabandwidth;
    int			chtvchromaflickerfilter;
    int			chtvcvbscolor;
    int			chtvtextenhance;
    int			chtvcontrast;
    int			sistvedgeenhance;	/* TV settings for SiS bridges */
    int			sistvantiflicker;
    int			sistvsaturation;
    int       		sistvcolcalibc;
    int       		sistvcolcalibf;
    int			sistvcfilter;
    int			sistvyfilter;
    int			OptTVSOver;		/* Chrontel 7005: Superoverscan */
    int			tvxpos, tvypos;
    int		      	tvxscale, tvyscale;
    int			SiS6326Flags;		/* SiS6326 TV settings */
    int			sis6326enableyfilter;
    int			sis6326yfilterstrong;
    int			sis6326tvplug;
    int			sis6326fscadjust;
    BOOL		sisfbfound;
    BOOL		donttrustpdc;		/* Don't trust the detected PDC */
    unsigned char	sisfbpdc, sisfbpdca;
    unsigned char       sisfblcda;
    int			sisfbscalelcd;
    unsigned long	sisfbspecialtiming;
    BOOL		sisfb_haveemi, sisfb_haveemilcd, sisfb_tvposvalid, sisfb_havelock;
    unsigned char	sisfb_emi30,sisfb_emi31,sisfb_emi32,sisfb_emi33;
    int 		sisfb_tvxpos, sisfb_tvypos;
    char		sisfbdevname[16];
    int			EMI;
    int			NoYV12;			/* Disable Xv YV12 support (old series) */
    unsigned char       postVBCR32;
    int			newFastVram;		/* Replaces FastVram */
    int			ForceTVType, SenseYPbPr;
    int                 NonDefaultPAL, NonDefaultNTSC;
    unsigned long	ForceYPbPrType, ForceYPbPrAR;
    unsigned long       lockcalls;		/* Count unlock calls for debug */
    unsigned short	tvx, tvy;		/* Backup TV position registers */
    unsigned char	p2_01, p2_02, p2_1f, p2_20, p2_43, p2_42, p2_2b; /* Backup TV position registers */
    unsigned short      tvx1, tvx2, tvx3, tvy1; /* Backup TV position registers */
    unsigned char	p2_44, p2_45, p2_46;
    unsigned long       sistvccbase;
    unsigned char       p2_35, p2_36, p2_37, p2_38, p2_48, p2_49, p2_4a;
    unsigned char	p2_0a, p2_2f, p2_30, p2_47;
    unsigned char       scalingp1[9], scalingp4[9], scalingp2[64];
    BOOLEAN		ForceCursorOff;
    BOOLEAN		HaveCustomModes;
    BOOLEAN		IsCustom;
    DisplayModePtr	backupmodelist;
    int			chtvtype;
    Atom                xvBrightness, xvContrast, xvColorKey, xvHue, xvSaturation;
    Atom                xvAutopaintColorKey, xvSetDefaults, xvSwitchCRT;
    Atom		xvDisableGfx, xvDisableGfxLR, xvTVXPosition, xvTVYPosition;
    Atom		xvDisableColorkey, xvUseChromakey, xvChromaMin, xvChromaMax;
    Atom		xvInsideChromakey, xvYUVChromakey, xvVSync;
    Atom		xvGammaRed, xvGammaGreen, xvGammaBlue;
    Atom		xv_QVF, xv_QVV, xv_USD, xv_SVF, xv_QDD, xv_TAF, xv_TSA, xv_TEE, xv_GSF;
    Atom		xv_TTE, xv_TCO, xv_TCC, xv_TCF, xv_TLF, xv_CMD, xv_CMDR, xv_CT1, xv_SGA;
    Atom		xv_GDV, xv_GHI, xv_OVR, xv_GBI, xv_TXS, xv_TYS, xv_CFI, xv_COC, xv_COF;
    Atom		xv_YFI, xv_GSS, xv_BRR, xv_BRG, xv_BRB, xv_PBR, xv_PBG, xv_PBB, xv_SHC;
    Atom		xv_BRR2, xv_BRG2, xv_BRB2, xv_PBR2, xv_PBG2, xv_PBB2, xv_PMD, xv_RDT;
#ifdef TWDEBUG
    Atom		xv_STR;
#endif        
    int			xv_sisdirectunlocked;
    unsigned long	xv_sd_result;
    int			CRT1isoff;
#ifdef SIS_CP
    SIS_CP_H
#endif
    unsigned long       ChipFlags;
    unsigned long       SiS_SD_Flags;
    BOOLEAN		UseHWARGBCursor;
    int			OptUseColorCursor;
    int			OptUseColorCursorBlend;
    CARD32		OptColorCursorBlendThreshold;
    unsigned short      cursorBufferNum;
    int                 vb;
    BOOLEAN		restorebyset;
    BOOLEAN		nocrt2ddcdetection;
    BOOLEAN		forcecrt2redetection;
    BOOLEAN		CRT1gamma, CRT1gammaGiven, CRT2gamma, XvGamma, XvGammaGiven;
    int			XvDefCon, XvDefBri, XvDefHue, XvDefSat;
    BOOLEAN		XvDefDisableGfx, XvDefDisableGfxLR, XvDefAdaptorBlit;
    BOOLEAN		XvUseMemcpy;
    BOOLEAN		XvUseChromaKey, XvDisableColorKey;
    BOOLEAN		XvInsideChromaKey, XvYUVChromaKey;
    int			XvChromaMin, XvChromaMax;
    int			XvGammaRed, XvGammaGreen, XvGammaBlue;
    int			XvGammaRedDef, XvGammaGreenDef, XvGammaBlueDef;
    CARD8		XvGammaRampRed[256], XvGammaRampGreen[256], XvGammaRampBlue[256];
    BOOLEAN		disablecolorkeycurrent;
    CARD32		colorKey;
    CARD32		MiscFlags;
    int			UsePanelScaler, CenterLCD;
    FBLinearPtr		AccelLinearScratch;
    void		(*AccelRenderCallback)(ScrnInfoPtr);
    float		zClearVal;
    unsigned long	bClrColor, dwColor;
    int			AllowHotkey;
    BOOLEAN		enablesisctrl;
    short		Video_MaxWidth, Video_MaxHeight;
    int			FSTN;
    BOOLEAN		AddedPlasmaModes;
    short               scrnPitch2;
    CARD32		CurFGCol, CurBGCol;
    unsigned char *	CurMonoSrc;
    CARD32 *            CurARGBDest;
    int			GammaBriR, GammaBriG, GammaBriB;
    int			GammaPBriR, GammaPBriG, GammaPBriB;
    Bool		HideHWCursor;  /* Custom application */
    Bool		HWCursorIsVisible;
    unsigned long       HWCursorBackup[16];
    int			HWCursorMBufNum, HWCursorCBufNum;
    unsigned long	mmioSize;
    BOOLEAN		ROM661New;
    BOOLEAN		NewCRLayout;
    BOOLEAN		skipswitchcheck;
    unsigned long	VBFlagsInit;
    DisplayModePtr	currentModeLast;
#ifdef SISMERGED
    Bool		MergedFB, MergedFBAuto;
    SiSScrn2Rel		CRT2Position;
    char *		CRT2HSync;
    char *		CRT2VRefresh;
    char *		MetaModes;
    ScrnInfoPtr		CRT2pScrn;
    DisplayModePtr	CRT1Modes;
    DisplayModePtr	CRT1CurrentMode;
    int			CRT1frameX0;
    int			CRT1frameY0;
    int			CRT1frameX1;
    int			CRT1frameY1;
    Bool		CheckForCRT2;
    Bool		IsCustomCRT2;
    BOOLEAN 		HaveCustomModes2;
    int			maxCRT1_X1, maxCRT1_X2, maxCRT1_Y1, maxCRT1_Y2;
    int			maxCRT2_X1, maxCRT2_X2, maxCRT2_Y1, maxCRT2_Y2;
    int			maxClone_X1, maxClone_X2, maxClone_Y1, maxClone_Y2;
    int			MergedFBXDPI, MergedFBYDPI;
    IOADDRESS		MyPIOOffset;
    Bool		OverruleRanges;
#ifdef SIS_NEED_MAP_IOP   
    CARD32              IOPAddress;      	/* I/O port physical address */
    unsigned char *     IOPBase;         	/* I/O port linear address */   
#endif    
#ifdef SISXINERAMA
    Bool		UseSiSXinerama;
    Bool		CRT2IsScrn0;
    ExtensionEntry 	*XineramaExtEntry;
    int			SiSXineramaVX, SiSXineramaVY;
    Bool		AtLeastOneNonClone;
#endif
#endif
} SISRec, *SISPtr;

typedef struct _ModeInfoData {
    int mode;
    VbeModeInfoBlock *data;
    VbeCRTCInfoBlock *block;
} ModeInfoData;

#define SDMPTR(x) ((SiSMergedDisplayModePtr)(x->currentMode->Private))
#define CDMPTR    ((SiSMergedDisplayModePtr)(pSiS->CurrentLayout.mode->Private))

#define BOUND(test,low,hi) { \
    if(test < low) test = low; \
    if(test > hi) test = hi; }

#define REBOUND(low,hi,test) { \
    if(test < low) { \
        hi += test-low; \
        low = test; } \
    if(test > hi) { \
        low += test-hi; \
        hi = test; } }

typedef struct _MergedDisplayModeRec {
    DisplayModePtr CRT1;
    DisplayModePtr CRT2;
    SiSScrn2Rel    CRT2Position;
} SiSMergedDisplayModeRec, *SiSMergedDisplayModePtr;


typedef struct _region {
    int x0,x1,y0,y1;
} region;

typedef struct _myhddctiming {
    int           whichone;
    unsigned char mask;
    float         rate;
} myhddctiming;

typedef struct _myvddctiming {
    int           whichone;
    unsigned char mask;
    int           rate;
} myvddctiming;

typedef struct _myddcstdmodes {
    int hsize;
    int vsize;
    int refresh;
    float hsync;
} myddcstdmodes;

typedef struct _pdctable {
    int subsysVendor;
    int subsysCard;
    int pdc;
    char *vendorName;
    char *cardName;
} pdctable;

typedef struct _chswtable {
    int subsysVendor;
    int subsysCard;
    char *vendorName;
    char *cardName;
} chswtable;

typedef struct _customttable {
    unsigned short chipID;
    char *biosversion;
    char *biosdate;
    CARD32 bioschksum;
    unsigned short biosFootprintAddr[5];
    unsigned char biosFootprintData[5];
    unsigned short pcisubsysvendor;
    unsigned short pcisubsyscard;
    char *vendorName;
    char *cardName;
    unsigned long SpecialID;
    char *optionName;
} customttable;

#ifdef SISMERGED
#ifdef SISXINERAMA
typedef struct _SiSXineramaData {
    int x;
    int y;
    int width;
    int height;
} SiSXineramaData;
#endif
#endif

#if 0
/* SiS Direct access for config utility */

#define SDC_ID 0x53495321

#define SDC_VERSION 1

#define SDC_NUM_PARM 20
typedef struct _sisdirectcommand {
    unsigned long sdc_id;
    unsigned long sdc_chksum;
    unsigned long sdc_header;
    unsigned long sdc_command;
    unsigned long sdc_parm[SDC_NUM_PARM];
} sisdirectcommand;

#define SDC_RESULT_OK  		0x66670000
#define SDC_RESULT_UNDEFCMD	0x66670001

#define SDC_CMD_GETVERSION 		0x98980001
#define SDC_CMD_CHECKMODEFORCRT2 	0x98980002
/* more to come */
#endif

extern void  sisSaveUnlockExtRegisterLock(SISPtr pSiS, unsigned char *reg1, unsigned char *reg2);
extern void  sisRestoreExtRegisterLock(SISPtr pSiS, unsigned char reg1, unsigned char reg2);
extern void  SiSOptions(ScrnInfoPtr pScrn);
extern const OptionInfoRec * SISAvailableOptions(int chipid, int busid);
extern void  SiSSetup(ScrnInfoPtr pScrn);
extern void  SISVGAPreInit(ScrnInfoPtr pScrn);
extern Bool  SiSAccelInit(ScreenPtr pScreen);
extern Bool  SiS300AccelInit(ScreenPtr pScreen);
extern Bool  SiS315AccelInit(ScreenPtr pScreen);
extern Bool  SiS530AccelInit(ScreenPtr pScreen);
extern Bool  SiSHWCursorInit(ScreenPtr pScreen);
extern Bool  SISDGAInit(ScreenPtr pScreen);
extern void  SISInitVideo(ScreenPtr pScreen);
extern void  SIS6326InitVideo(ScreenPtr pScreen);

extern void  SiS_SetCHTVlumabandwidthcvbs(ScrnInfoPtr pScrn, int val);
extern void  SiS_SetCHTVlumabandwidthsvideo(ScrnInfoPtr pScrn, int val);
extern void  SiS_SetCHTVlumaflickerfilter(ScrnInfoPtr pScrn, int val);
extern void  SiS_SetCHTVchromabandwidth(ScrnInfoPtr pScrn, int val);
extern void  SiS_SetCHTVchromaflickerfilter(ScrnInfoPtr pScrn, int val);
extern void  SiS_SetCHTVcvbscolor(ScrnInfoPtr pScrn, int val);
extern void  SiS_SetCHTVtextenhance(ScrnInfoPtr pScrn, int val);
extern void  SiS_SetCHTVcontrast(ScrnInfoPtr pScrn, int val);
extern void  SiS_SetSISTVedgeenhance(ScrnInfoPtr pScrn, int val);
extern void  SiS_SetSISTVantiflicker(ScrnInfoPtr pScrn, int val);
extern void  SiS_SetSISTVsaturation(ScrnInfoPtr pScrn, int val);
extern void  SiS_SetSISTVcfilter(ScrnInfoPtr pScrn, int val);
extern void  SiS_SetSISTVyfilter(ScrnInfoPtr pScrn, int val);
extern void  SiS_SetSISTVcolcalib(ScrnInfoPtr pScrn, int val, Bool coarse);
extern void  SiS_SetSIS6326TVantiflicker(ScrnInfoPtr pScrn, int val);
extern void  SiS_SetSIS6326TVenableyfilter(ScrnInfoPtr pScrn, int val);
extern void  SiS_SetSIS6326TVyfilterstrong(ScrnInfoPtr pScrn, int val);
extern void  SiS_SetTVxposoffset(ScrnInfoPtr pScrn, int val);
extern void  SiS_SetTVyposoffset(ScrnInfoPtr pScrn, int val);
extern void  SiS_SetTVxscale(ScrnInfoPtr pScrn, int val);
extern void  SiS_SetTVyscale(ScrnInfoPtr pScrn, int val);
extern Bool  SISSwitchCRT2Type(ScrnInfoPtr pScrn, unsigned long newvbflags);
extern int   SISCheckModeIndexForCRT2Type(ScrnInfoPtr pScrn, unsigned short cond,
					  unsigned short index, Bool quiet);
extern Bool  SISSwitchCRT1Status(ScrnInfoPtr pScrn, int onoff);
extern Bool  SISRedetectCRT2Devices(ScrnInfoPtr pScrn);
extern int   SiS_GetCHTVlumabandwidthcvbs(ScrnInfoPtr pScrn);
extern int   SiS_GetCHTVlumabandwidthsvideo(ScrnInfoPtr pScrn);
extern int   SiS_GetCHTVlumaflickerfilter(ScrnInfoPtr pScrn);
extern int   SiS_GetCHTVchromabandwidth(ScrnInfoPtr pScrn);
extern int   SiS_GetCHTVchromaflickerfilter(ScrnInfoPtr pScrn);
extern int   SiS_GetCHTVcvbscolor(ScrnInfoPtr pScrn);
extern int   SiS_GetCHTVtextenhance(ScrnInfoPtr pScrn);
extern int   SiS_GetCHTVcontrast(ScrnInfoPtr pScrn);
extern int   SiS_GetSISTVedgeenhance(ScrnInfoPtr pScrn);
extern int   SiS_GetSISTVantiflicker(ScrnInfoPtr pScrn);
extern int   SiS_GetSISTVsaturation(ScrnInfoPtr pScrn);
extern int   SiS_GetSISTVcfilter(ScrnInfoPtr pScrn);
extern int   SiS_GetSISTVyfilter(ScrnInfoPtr pScrn);
extern int   SiS_GetSISTVcolcalib(ScrnInfoPtr pScrn, Bool coarse);
extern int   SiS_GetSIS6326TVantiflicker(ScrnInfoPtr pScrn);
extern int   SiS_GetSIS6326TVenableyfilter(ScrnInfoPtr pScrn);
extern int   SiS_GetSIS6326TVyfilterstrong(ScrnInfoPtr pScrn);
extern int   SiS_GetTVxposoffset(ScrnInfoPtr pScrn);
extern int   SiS_GetTVyposoffset(ScrnInfoPtr pScrn);
extern int   SiS_GetTVxscale(ScrnInfoPtr pScrn);
extern int   SiS_GetTVyscale(ScrnInfoPtr pScrn);
#endif