sis.h revision 74c14cd6
1/*
2 * Main global data and definitions
3 *
4 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1) Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2) Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3) The name of the author may not be used to endorse or promote products
15 *    derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors:   Thomas Winischhofer <thomas@winischhofer.net>
29 *            others (old code base)
30 *
31 */
32
33#ifndef _SIS_H_
34#define _SIS_H_
35
36#include <stdio.h>
37#include <string.h>
38#include <math.h>
39#include <setjmp.h>
40#include <unistd.h>
41#include <fcntl.h>
42#include <sys/ioctl.h>
43
44#include <sispcirename.h>
45
46#define SISDRIVERVERSIONYEAR    5
47#define SISDRIVERVERSIONMONTH   9
48#define SISDRIVERVERSIONDAY     20
49#define SISDRIVERREVISION       1
50
51#define SISDRIVERIVERSION ((SISDRIVERVERSIONYEAR << 16) |  \
52			   (SISDRIVERVERSIONMONTH << 8) |  \
53			   SISDRIVERVERSIONDAY 	       |  \
54			   (SISDRIVERREVISION << 24))
55
56#undef SIS_LINUX		/* Try to find out whether platform is Linux */
57#if defined(__GNUC__) && (__GNUC__ >= 4)
58#ifdef __linux__
59#define SIS_LINUX
60#endif
61#else
62#ifdef linux
63#define SIS_LINUX
64#endif
65#endif
66
67#if 0
68#define TWDEBUG    /* for debugging */
69#endif
70
71#undef SIS_CP
72#if 0
73#include "siscp.H"
74#endif
75
76#include "compiler.h"
77#include "xf86Pci.h"
78#include "xf86Priv.h"
79#include "xf86_OSproc.h"
80#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 6
81#include "xf86Resources.h"
82#endif
83#include "xf86.h"
84#include "xf86Cursor.h"
85#include "xf86cmap.h"
86#include "vbe.h"
87
88#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 12
89#define _swapl(x, n) swapl(x,n)
90#define _swaps(x, n) swaps(x,n)
91#else
92#define _swapl(x, n) swapl(x)
93#define _swaps(x, n) swaps(x)
94#endif
95
96#define SIS_HaveDriverFuncs 0
97
98#undef SISISXORG6899900
99#ifdef XORG_VERSION_CURRENT
100#include "xorgVersion.h"
101#define SISMYSERVERNAME "X.org"
102#ifndef XF86_VERSION_NUMERIC
103#define XF86_VERSION_NUMERIC(major,minor,patch,snap,dummy) \
104	(((major) * 10000000) + ((minor) * 100000) + ((patch) * 1000) + snap)
105#define XF86_VERSION_CURRENT XF86_VERSION_NUMERIC(4,3,99,902,0)
106#endif
107#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(6,8,99,900,0) || XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(4,0,0,0,0)
108#define SISISXORG6899900
109#endif
110#if 0
111#ifdef HaveDriverFuncs
112#define SIS_HAVE_DRIVER_FUNC
113#undef  SIS_HaveDriverFuncs
114#define SIS_HaveDriverFuncs HaveDriverFuncs
115#endif
116#endif
117#else
118#include "xf86Version.h"
119#define SISMYSERVERNAME "XFree86"
120#endif
121
122#define SIS_NAME                "SIS"
123#define SIS_DRIVER_NAME         "sis"
124#define SIS_MAJOR_VERSION	PACKAGE_VERSION_MAJOR
125#ifdef SISISXORG6899900
126#define SIS_MINOR_VERSION	PACKAGE_VERSION_MINOR	/* DRI changes */
127#define SIS_PATCHLEVEL		PACKAGE_VERSION_PATCHLEVEL
128#else
129#define SIS_MINOR_VERSION       7
130#define SIS_PATCHLEVEL          1
131#endif
132#define SIS_CURRENT_VERSION     ((SIS_MAJOR_VERSION << 16) | \
133                                 (SIS_MINOR_VERSION << 8) | SIS_PATCHLEVEL )
134
135#if (XF86_VERSION_CURRENT >= XF86_VERSION_NUMERIC(4,3,99,0,0)) || (defined(XvExtension))
136#include "xf86xv.h"
137#include <X11/extensions/Xv.h>
138#endif
139
140/* Platform/architecture related definitions: */
141
142/* SIS_PC_PLATFORM: Map VGA memory at a0000 and save/restore fonts? */
143/* List of architectures likely to be incomplete */
144#define SIS_PC_PLATFORM
145#if defined(__powerpc__) || defined(__mips__) || defined(__arm32__)
146#undef SIS_PC_PLATFORM
147#endif
148
149/* SIS_USE_BIOS_SCRATCH: Save/restore mode number in BIOS scratch area? */
150#undef SIS_USE_BIOS_SCRATCH
151#if defined(i386) || defined(__i386) || defined(__i386__) || defined(__AMD64__) || defined(__amd64__) || defined(__x86_64__)
152#define SIS_USE_BIOS_SCRATCH
153#endif
154
155/* SIS_NEED_MAP_IOP: Map i/o port area to virtual memory? */
156/* List of architectures likely to be incomplete */
157/* This is BROKEN, see comment in sis_driver.c */
158#undef SIS_NEED_MAP_IOP
159#if 0
160#if defined(__arm32__) || defined(__mips__)
161#define SIS_NEED_MAP_IOP
162#endif
163#endif
164
165/* SISUSEDEVPORT: Used on architectures without direct inX/outX access. In this case,
166 * we use read()/write() to /dev/port. LINUX ONLY! (How can this be done on *BSD?)
167 */
168#undef SISUSEDEVPORT
169#if defined(SIS_LINUX) && (defined(__arm32__) || defined(__mips__))
170#ifndef SIS_NEED_MAP_IOP
171#define SISUSEDEVPORT
172#endif
173#endif
174
175/* Our #includes: Require the arch/platform dependent #defines above */
176
177#include "osdef.h"
178#include "vgatypes.h"
179#include "vstruct.h"
180
181#undef SISHAVEDRMWRITE
182#undef SISNEWDRI
183
184/* if the server was built without DRI support, force-disable DRI */
185#ifndef XF86DRI
186#undef SISDRI
187#endif
188
189#ifdef SISDRI
190#if XF86_VERSION_CURRENT >= XF86_VERSION_NUMERIC(4,2,99,3,0)
191#define SISHAVEDRMWRITE
192#endif
193#if XF86_VERSION_CURRENT >= XF86_VERSION_NUMERIC(4,3,99,14,0)
194#define SISNEWDRI
195#endif
196#undef SIS315DRI		/* define this if dri is adapted for 315/330 series */
197#include "xf86drm.h"
198#include "sarea.h"
199#define _XF86DRI_SERVER_
200#include "dri.h"
201#include "GL/glxint.h"
202#include "sis_dri.h"
203#endif /* SISDRI */
204
205/* Configurable stuff: ------------------------------------- */
206
207#define SISDUALHEAD		/* Include Dual Head code  */
208
209#define SISMERGED		/* Include Merged-FB code */
210
211#undef SISXINERAMA
212#ifdef SISMERGED
213#define SISXINERAMA		/* Include SiS Pseudo-Xinerama for MergedFB mode */
214#define SIS_XINERAMA_MAJOR_VERSION  1
215#define SIS_XINERAMA_MINOR_VERSION  1
216#endif
217
218#define SIS_ARGB_CURSOR		/* Include code for color hardware cursors */
219
220#define ENABLE_YPBPR		/* Include YPbPr support on SiS bridges (315 series and 661/741/760) */
221
222#define SISVRAMQ		/* Use VRAM queue mode on 315/330/340/XGI series */
223
224#undef INCL_YUV_BLIT_ADAPTOR
225#ifdef SISVRAMQ
226#define INCL_YUV_BLIT_ADAPTOR	/* Include support for YUV->RGB blit adaptors (VRAM queue mode only) */
227#endif
228
229#ifdef HAVE_XAA_H
230#define SIS_USE_XAA		/* Include code for XAA */
231#endif
232
233#ifdef SISVRAMQ
234#ifdef XORG_VERSION_CURRENT
235#if defined(SIS_HAVE_EXA) || (defined(XF86EXA) && (XF86EXA != 0))
236#if 1
237#define SIS_USE_EXA		/* Include code for EXA */
238#endif
239#endif
240#endif
241#endif
242
243#if 0
244#define SISDEINT		/* Include Xv deinterlacer code (not functional yet!) */
245#endif
246
247#if 0
248#define XV_SD_DEPRECATED	/* Include deprecated XV SD interface for SiSCtrl */
249#endif
250
251/* End of configurable stuff --------------------------------- */
252
253#define UNLOCK_ALWAYS		/* Always unlock the registers (should be set!) */
254
255#if !defined(SIS_USE_XAA) && !defined(SIS_USE_EXA)
256#define SIS_USE_XAA
257#endif
258
259#ifdef SIS_USE_XAA
260#include "xaa.h"
261#endif
262#ifdef SIS_USE_EXA
263#include "exa.h"
264#endif
265
266/* Need that for SiSCtrl and Pseudo-Xinerama */
267#define EXTENSION_PROC_ARGS void *
268#include "extnsionst.h" 			/* required */
269#include <X11/extensions/panoramiXproto.h> 	/* required */
270
271#include "compat-api.h"
272
273#undef SISCHECKOSSSE
274#ifdef XORG_VERSION_CURRENT
275#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(6,8,99,13,0)
276#define SISCHECKOSSSE		/* Automatic check OS for SSE; requires SigIll facility */
277#endif
278#endif
279
280#undef SISGAMMARAMP
281#ifdef XORG_VERSION_CURRENT
282#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(6,8,99,13,0)
283#define SISGAMMARAMP		/* Driver can set gamma ramp; requires additional symbols in xf86sym.h */
284#endif
285#endif
286
287#if 0	/* Perhaps for future use */
288#if 1
289#define SIS_PCI_BUS(a) (a)->bus
290#define SIS_PCI_DEVICE(a) (a)->device
291#define SIS_PCI_FUNC(a) (a)->func
292#define SIS_PCI_TAG(a) pciTag((a)->bus, (a)->device, (a)->func);
293#else
294#define SIS_PCI_BUS(a) (a)->pciid.bus
295#define SIS_PCI_DEVICE(a) (a)->pciid.device
296#define SIS_PCI_FUNC(a) (a)->pciid.func
297#define SIS_PCI_TAG(a) pciTag(&((a)->pciid));
298#endif
299#endif
300
301#ifdef TWDEBUG
302#define SISVERBLEVEL 3
303#else
304#define SISVERBLEVEL 4
305#endif
306
307#ifndef _XF86_PCIINFO_H
308#define PCI_VENDOR_SIS			0x1039
309/* SiS */
310#define PCI_CHIP_SG86C201		0x0001
311#define PCI_CHIP_SG86C202		0x0002
312#define PCI_CHIP_SG85C503		0x0008
313#define PCI_CHIP_SIS5597		0x0200
314/* Agregado por Carlos Duclos & Manuel Jander */
315#define PCI_CHIP_SIS82C204		0x0204
316#define PCI_CHIP_SG86C205		0x0205
317#define PCI_CHIP_SG86C215		0x0215
318#define PCI_CHIP_SG86C225		0x0225
319#define PCI_CHIP_85C501			0x0406
320#define PCI_CHIP_85C496			0x0496
321#define PCI_CHIP_85C601			0x0601
322#define PCI_CHIP_85C5107		0x5107
323#define PCI_CHIP_85C5511		0x5511
324#define PCI_CHIP_85C5513		0x5513
325#define PCI_CHIP_SIS5571		0x5571
326#define PCI_CHIP_SIS5597_2		0x5597
327#define PCI_CHIP_SIS530			0x6306
328#define PCI_CHIP_SIS6326		0x6326
329#define PCI_CHIP_SIS7001		0x7001
330#define PCI_CHIP_SIS300			0x0300
331#define PCI_CHIP_SIS315H		0x0310
332#define PCI_CHIP_SIS315PRO		0x0325
333#define PCI_CHIP_SIS330			0x0330
334#define PCI_CHIP_SIS630			0x6300
335#define PCI_CHIP_SIS540			0x5300
336#define PCI_CHIP_SIS550			0x5315
337#define PCI_CHIP_SIS650			0x6325
338#define PCI_CHIP_SIS730			0x7300
339
340#endif
341
342/* For SiS315/550/650/740/330/660 - these should be moved elsewhere! */
343#ifndef PCI_CHIP_SIS315H
344#define PCI_CHIP_SIS315H	0x0310
345#endif
346#ifndef PCI_CHIP_SIS315
347#define PCI_CHIP_SIS315		0x0315
348#endif
349#ifndef PCI_CHIP_SIS315PRO
350#define PCI_CHIP_SIS315PRO	0x0325
351#endif
352#ifndef PCI_CHIP_SIS550
353#define PCI_CHIP_SIS550		0x5315	/* 550_VGA */
354#endif
355#ifndef PCI_CHIP_SIS650
356#define PCI_CHIP_SIS650		0x6325  /* 650_VGA and 740_VGA */
357#endif
358#ifndef PCI_CHIP_SIS330
359#define PCI_CHIP_SIS330		0x0330
360#endif
361#ifndef PCI_CHIP_SIS660
362#define PCI_CHIP_SIS660		0x6330	/* 661_VGA, 741_VGA, 760_VGA, 761_VGA */
363#endif
364#ifndef PCI_CHIP_SIS340
365#define PCI_CHIP_SIS340		0x0340
366#endif
367
368#ifndef PCI_VENDOR_XGI
369#define PCI_VENDOR_XGI		0x18ca
370#endif
371
372#ifndef PCI_CHIP_XGIXG20
373#define PCI_CHIP_XGIXG20	0x0020
374#endif
375
376#ifndef PCI_CHIP_XGIXG40
377#define PCI_CHIP_XGIXG40	0x0040
378#endif
379
380/* pSiS->Flags (old series only) */
381#define SYNCDRAM		0x00000001
382#define RAMFLAG			0x00000002
383#define ESS137xPRESENT		0x00000004
384#define SECRETFLAG		0x00000008
385#define A6326REVAB		0x00000010
386#define MMIOMODE		0x00010000
387#define LFBQMODE		0x00020000
388#define AGPQMODE		0x00040000
389#define UMA			0x80000000
390
391#define BIOS_BASE		0xC0000
392#define BIOS_SIZE		0x10000
393
394#define SIS_VBFlagsVersion	1
395
396/* pSiS->VBFlags - if anything is changed here, increase VBFlagsVersion! */
397#define CRT2_DEFAULT		0x00000001
398#define CRT2_LCD		0x00000002  /* Never change the order of the CRT2_XXX entries */
399#define CRT2_TV			0x00000004
400#define CRT2_VGA		0x00000008
401#define TV_NTSC			0x00000010
402#define TV_PAL			0x00000020
403#define TV_HIVISION		0x00000040
404#define TV_YPBPR		0x00000080
405#define TV_AVIDEO		0x00000100
406#define TV_SVIDEO		0x00000200
407#define TV_SCART		0x00000400
408#define OLDVB_CONEXANT		0x00000800	/* Definition deprecated (now VBFlags2) */
409#define OLDVB_TRUMPION		OLDVB_CONEXANT	/* Definition deprecated (now VBFlags2) */
410#define TV_PALM			0x00001000
411#define TV_PALN			0x00002000
412#define TV_NTSCJ		TV_PALM
413#define OLDVB_302ELV		0x00004000	/* Definition deprecated (now VBFlags2) */
414#define TV_CHSCART		0x00008000
415#define TV_CHYPBPR525I		0x00010000
416#define CRT1_VGA		0x00000000	/* ZERO - no mask! */
417#define CRT1_LCDA		0x00020000
418#define VGA2_CONNECTED		0x00040000
419#define DISPTYPE_CRT1		0x00080000  	/* CRT1 connected and used */
420#define TV_YPBPR625I		0x00100000
421#define TV_YPBPR625P		0x00200000
422#define OLDVB_302B		0x00400000	/* Definition deprecated (now VBFlags2) */
423#define OLDVB_30xBDH		0x00800000      /* Definition deprecated (now VBFlags2) */
424#define OLDVB_LVDS		0x01000000	/* Definition deprecated (now VBFlags2) */
425#define OLDVB_CHRONTEL		0x02000000	/* Definition deprecated (now VBFlags2) */
426#define OLDVB_301LV		0x04000000	/* Definition deprecated (now VBFlags2) */
427#define OLDVB_302LV		0x08000000	/* Definition deprecated (now VBFlags2) */
428#define OLDVB_301C		0x10000000	/* Definition deprecated (now VBFlags2) */
429#define SINGLE_MODE		0x20000000   	/* CRT1 or CRT2; determined by DISPTYPE_CRTx */
430#define MIRROR_MODE		0x40000000   	/* CRT1 + CRT2 identical (mirror mode) */
431#define DUALVIEW_MODE		0x80000000   	/* CRT1 + CRT2 independent (dual head mode) */
432
433/* Aliases: */
434#define CRT2_ENABLE		(CRT2_LCD | CRT2_TV | CRT2_VGA)
435#define TV_STANDARD		(TV_NTSC | TV_PAL | TV_PALM | TV_PALN | TV_NTSCJ)
436#define TV_INTERFACE		(TV_AVIDEO|TV_SVIDEO|TV_SCART|TV_HIVISION|TV_YPBPR)
437
438/* Only if TV_YPBPR is set: */
439#define TV_YPBPR525I		TV_NTSC
440#define TV_YPBPR525P		TV_PAL
441#define TV_YPBPR750P		TV_PALM
442#define TV_YPBPR1080I		TV_PALN
443#define TV_YPBPRALL 		(TV_YPBPR525I | TV_YPBPR525P | \
444				 TV_YPBPR625I | TV_YPBPR625P | \
445				 TV_YPBPR750P | TV_YPBPR1080I)
446
447#define TV_YPBPR43LB		TV_CHSCART
448#define TV_YPBPR43		TV_CHYPBPR525I
449#define TV_YPBPR169 		(TV_CHSCART | TV_CHYPBPR525I)
450#define TV_YPBPRAR		(TV_CHSCART | TV_CHYPBPR525I)
451
452#define DISPTYPE_DISP2		CRT2_ENABLE
453#define DISPTYPE_DISP1		DISPTYPE_CRT1
454#define VB_DISPMODE_SINGLE	SINGLE_MODE  	/* alias */
455#define VB_DISPMODE_MIRROR	MIRROR_MODE  	/* alias */
456#define VB_DISPMODE_DUAL	DUALVIEW_MODE 	/* alias */
457#define DISPLAY_MODE		(SINGLE_MODE | MIRROR_MODE | DUALVIEW_MODE)
458
459/* pSiS->VBFlags2 (static stuff only!) */
460#define VB2_SISUMC		0x00000001
461#define VB2_301			0x00000002	/* Video bridge type */
462#define VB2_301B		0x00000004
463#define VB2_301C		0x00000008
464#define VB2_307T		0x00000010
465#define VB2_302B		0x00000800
466#define VB2_301LV		0x00001000
467#define VB2_302LV		0x00002000
468#define VB2_302ELV		0x00004000
469#define VB2_307LV		0x00008000
470#define VB2_30xBDH		0x08000000      /* 30xB DH version (w/o LCD support) */
471#define VB2_CONEXANT		0x10000000	/* >=661 series only */
472#define VB2_TRUMPION		0x20000000	/* 300 series only */
473#define VB2_LVDS		0x40000000
474#define VB2_CHRONTEL		0x80000000
475
476#define VB2_SISLVDSBRIDGE	(VB2_301LV | VB2_302LV | VB2_302ELV | VB2_307LV)
477#define VB2_SISTMDSBRIDGE	(VB2_301   | VB2_301B  | VB2_301C   | VB2_302B | VB2_307T)
478#define VB2_SISBRIDGE		(VB2_SISLVDSBRIDGE | VB2_SISTMDSBRIDGE)
479
480#define VB2_SISTMDSLCDABRIDGE	(VB2_301C | VB2_307T)
481#define VB2_SISLCDABRIDGE	(VB2_SISTMDSLCDABRIDGE | VB2_301LV | VB2_302LV | VB2_302ELV | VB2_307LV)
482
483#define VB2_SISHIVISIONBRIDGE	(VB2_301  | VB2_301B | VB2_302B)
484#define VB2_SISYPBPRBRIDGE	(VB2_301C | VB2_307T | VB2_SISLVDSBRIDGE)
485#define VB2_SISYPBPRARBRIDGE	(VB2_301C | VB2_307T | VB2_307LV)
486#define VB2_SISTAP4SCALER	(VB2_301C | VB2_307T | VB2_302ELV | VB2_307LV)
487#define VB2_SISTVBRIDGE		(VB2_SISHIVISIONBRIDGE | VB2_SISYPBPRBRIDGE)
488
489#define VB2_SISVGA2BRIDGE	(VB2_301 | VB2_301B | VB2_301C | VB2_302B | VB2_307T)
490
491#define VB2_VIDEOBRIDGE		(VB2_SISBRIDGE | VB2_LVDS | VB2_CHRONTEL | VB2_CONEXANT)
492
493#define VB2_30xB		(VB2_301B  | VB2_301C   | VB2_302B  | VB2_307T)
494#define VB2_30xBLV		(VB2_30xB  | VB2_SISLVDSBRIDGE)
495#define VB2_30xC		(VB2_301C  | VB2_307T)
496#define VB2_30xCLV		(VB2_301C  | VB2_307T   | VB2_302ELV| VB2_307LV)
497#define VB2_SISEMIBRIDGE	(VB2_302LV | VB2_302ELV | VB2_307LV)
498#define VB2_LCD162MHZBRIDGE	(VB2_301C  | VB2_307T)
499/* CRT2/LCD over 1280 (overflow bits in Part4) */
500#define VB2_LCDOVER1280BRIDGE	(VB2_301C  | VB2_307T   | VB2_302LV | VB2_302ELV | VB2_307LV)
501/* CRT2/LCD over 1600? Is this really gonna happen, or will there be LCDA only for large panels? */
502#define VB2_LCDOVER1600BRIDGE	(VB2_307T  | VB2_307LV)
503/* VGA2 up to 202MHz (1600x1200@75) */
504#define VB2_RAMDAC202MHZBRIDGE	(VB2_301C  | VB2_307T)
505
506/* pSiS->VBFlags3 (for future use) */
507#define VB3_CRT1_TV		0x00000001
508#define VB3_CRT1_LCD		0x00000002
509#define VB3_CRT1_VGA		0x00000004
510#define TV1_AVIDEO		0x00000100
511#define TV1_SVIDEO		0x00000200
512#define TV1_SCART		0x00000400
513#define TV1_NTSC		0x00000800
514#define TV1_PAL			0x00001000
515#define TV1_YPBPR		0x00002000
516#define TV1_PALM		0x00004000
517#define TV1_PALN		0x00008000
518#define TV1_NTSCJ		0x00010000
519#define TV1_YPBPR525I		0x00020000
520#define TV1_YPBPR525P		0x00040000
521#define TV1_YPBPR625I		0x00080000
522#define TV1_YPBPR625P		0x00100000
523#define TV1_YPBPR750P		0x00200000
524#define TV1_YPBPR1080I		0x00400000
525
526/* pSiS->VBLCDFlags */
527#define VB_LCD_320x480		0x00000001	/* DSTN/FSTN for 550 */
528#define VB_LCD_640x480		0x00000002
529#define VB_LCD_800x600		0x00000004
530#define VB_LCD_1024x768		0x00000008
531#define VB_LCD_1280x1024	0x00000010
532#define VB_LCD_1280x960		0x00000020
533#define VB_LCD_1600x1200	0x00000040
534#define VB_LCD_2048x1536	0x00000080
535#define VB_LCD_1400x1050	0x00000100
536#define VB_LCD_1152x864		0x00000200
537#define VB_LCD_1152x768		0x00000400
538#define VB_LCD_1280x768		0x00000800
539#define VB_LCD_1024x600		0x00001000
540#define VB_LCD_640x480_2	0x00002000  	/* DSTN/FSTN */
541#define VB_LCD_640x480_3	0x00004000  	/* DSTN/FSTN */
542#define VB_LCD_848x480		0x00008000	/* LVDS only, otherwise handled as custom */
543#define VB_LCD_1280x800		0x00010000
544#define VB_LCD_1680x1050	0x00020000
545#define VB_LCD_1280x720		0x00040000
546#define VB_LCD_320x240		0x00080000
547#define VB_LCD_856x480		0x00100000
548#define VB_LCD_1280x854		0x00200000
549#define VB_LCD_1920x1200	0x00400000
550#define VB_LCD_UNKNOWN		0x10000000
551#define VB_LCD_BARCO1366	0x20000000
552#define VB_LCD_CUSTOM		0x40000000
553#define VB_LCD_EXPANDING	0x80000000
554
555#define VB_FORBID_CRT2LCD_OVER_1600		/* CRT2/LCD supports only up to 1600 pixels */
556
557/* PresetMode argument */
558#define SIS_MODE_SIMU		0
559#define SIS_MODE_CRT1		1
560#define SIS_MODE_CRT2		2
561
562/* pSiS->MiscFlags */
563#define MISC_CRT1OVERLAY	0x00000001  /* Current display mode supports overlay (CRT1) */
564#define MISC_PANELLINKSCALER	0x00000002  /* Panel link is currently scaling */
565#define MISC_CRT1OVERLAYGAMMA	0x00000004  /* Current display mode supports overlay gamma corr on CRT1 */
566#define MISC_TVNTSC1024		0x00000008  /* Current display mode is TV NTSC/PALM/YPBPR525I 1024x768  */
567#define MISC_CRT2OVERLAY	0x00000010  /* Current display mode supports overlay (CRT2) */
568#define MISC_SIS760ONEOVERLAY	0x00000020  /* SiS760/761: Only one overlay available currently */
569#define MISC_STNMODE		0x00000040  /* SiS550: xSTN active */
570
571/* pSiS->SiS6326Flags */
572#define SIS6326_HASTV		0x00000001
573#define SIS6326_TVSVIDEO        0x00000002
574#define SIS6326_TVCVBS		0x00000004
575#define SIS6326_TVPAL		0x00000008
576#define SIS6326_TVDETECTED	0x00000010
577#define SIS6326_TVON		0x80000000
578
579#ifdef  DEBUG
580#define PDEBUG(p)       p
581#else
582#define PDEBUG(p)
583#endif
584
585#define BITMASK(h,l)		(((unsigned)(1U << ((h) - (l) + 1)) - 1) << (l))
586#define GENMASK(mask)		BITMASK(1 ? mask, 0 ? mask)
587
588#define GETBITS(var,mask)	(((var) & GENMASK(mask)) >> (0 ? mask))
589#define SETBITS(val,mask)	((val) << (0 ? mask))
590#define SETBIT(n)		(1 << (n))
591
592#define GETBITSTR(val,from,to)       ((GETBITS(val, from)) << (0 ? to))
593#define SETVARBITS(var,val,from,to)  (((var) & (~(GENMASK(to)))) | GETBITSTR(val,from,to))
594#define GETVAR8(var)		((var) & 0xFF)
595#define SETVAR8(var,val)	(var) =  GETVAR8(val)
596
597typedef unsigned long  ULong;
598typedef unsigned short UShort;
599typedef unsigned char  UChar;
600
601/* pSiS->VGAEngine - VGA engine types */
602#define UNKNOWN_VGA 0
603#define SIS_530_VGA 1
604#define SIS_OLD_VGA 2
605#define SIS_300_VGA 3
606#define SIS_315_VGA 4   /* Includes 330/660/661/741/760/340/761 and M versions thereof, XGI */
607
608/* pSiS->oldChipset */
609#define OC_UNKNOWN   0
610#define OC_SIS86201  1
611#define OC_SIS86202  2
612#define OC_SIS6205A  3
613#define OC_SIS6205B  4
614#define OC_SIS82204  5
615#define OC_SIS6205C  6
616#define OC_SIS6225   7
617#define OC_SIS5597   8
618#define OC_SIS6326   9
619#define OC_SIS530A  11
620#define OC_SIS530B  12 /* 620 in 620-WDR */
621#define OC_SIS620   13
622
623/* Chrontel type */
624#define CHRONTEL_700x 0
625#define CHRONTEL_701x 1
626
627/* pSiS->ChipFlags */
628/* Use only lower 16 bit for chip id! (sisctrl) */
629#define SiSCF_LARGEOVERLAY  0x00000001
630#define SiSCF_Is651         0x00000002
631#define SiSCF_IsM650        0x00000004
632#define SiSCF_IsM652        0x00000008
633#define SiSCF_IsM653        0x00000010
634#define SiSCF_Is652         0x00000020
635#define SiSCF_Is65x         (SiSCF_Is651|SiSCF_IsM650|SiSCF_IsM652|SiSCF_IsM653|SiSCF_Is652)
636#define SiSCF_IsM661        0x00000100  /* M661FX */
637#define SiSCF_IsM741        0x00000200
638#define SiSCF_IsM760        0x00000400
639#define SiSCF_IsM661M       0x00000800  /* M661MX */
640#define SiSCF_IsM66x        (SiSCF_IsM661 | SiSCF_IsM741 | SiSCF_IsM760 | SiSCF_IsM661M)
641#define SiSCF_Is315USB      0x00001000  /* USB2VGA dongle */
642#define SiSCF_Is315E	    0x00002000  /* 315E (lower clocks) */
643#define SiSCF_IsXGIV3	    SiSCF_Is651 /* Volari V3(XT)  (If neither XGI... set, is V8) */
644#define SiSCF_IsXGIV5	    SiSCF_IsM650/* Volari V5 */
645#define SiSCF_IsXGIDUO	    SiSCF_IsM652/* Volari Duo */
646/* ... */
647#define SiSCF_315Core       0x00010000  /* 3D: Real 315 */
648#define SiSCF_Real256ECore  0x00020000  /* 3D: Similar to 315 core, no T&L? (65x, 661, 740, 741) */
649#define SiSCF_XabreCore     0x00040000  /* 3D: Real Xabre */
650#define SiSCF_Ultra256Core  0x00080000  /* 3D: aka "Mirage 2"; similar to Xabre, no T&L?, no P:Shader? (760) */
651#define SiSCF_MMIOPalette   0x00100000  /* HW supports MMIO palette writing/reading */
652#define SiSCF_IsXGI	    0x00200000  /* Is XGI chip (Z7, V3, V5, V8) */
653#define SiSCF_UseLCDA       0x01000000
654#define SiSCF_760LFB        0x08000000  /* 76x: LFB active (if not set, UMA only) */
655#define SiSCF_760UMA        0x10000000  /* 76x: UMA active (if not set, LFB only) */
656#define SiSCF_CRT2HWCKaputt 0x20000000  /* CRT2 Mono HWCursor engine buggy (SiS 330) */
657#define SiSCF_Glamour3      0x40000000
658#define SiSCF_Integrated    0x80000000
659
660/* SiS Direct Xv-API */
661#define SiS_SD_IS300SERIES     0x00000001
662#define SiS_SD_IS315SERIES     0x00000002
663#define SiS_SD_IS330SERIES     0x00000004
664#define SiS_SD_SUPPORTPALMN    0x00000008   /* tv chip supports pal-m, pal-n */
665#define SiS_SD_SUPPORT2OVL     0x00000010   /* set = 2 overlays, clear = support SWITCHCRT xv prop */
666#define SiS_SD_SUPPORTTVPOS    0x00000020   /* supports changing tv position */
667#define SiS_SD_ISDUALHEAD      0x00000040   /* Driver is in dual head mode */
668#define SiS_SD_ISMERGEDFB      0x00000080   /* Driver is in merged fb mode */
669#define SiS_SD_ISDHSECONDHEAD  0x00000100   /* Dual head: This is CRT1 (=second head) */
670#define SiS_SD_ISDHXINERAMA    0x00000200   /* Dual head: We are running Xinerama */
671#define SiS_SD_VBHASSCART      0x00000400   /* videobridge has SCART instead of VGA2 */
672#define SiS_SD_ISDEPTH8        0x00000800   /* Depth is 8, no independent gamma correction */
673#define SiS_SD_SUPPORTSOVER    0x00001000   /* Support for Chrontel Super Overscan */
674#define SiS_SD_ENABLED         0x00002000   /* sisctrl is enabled (by option) */
675#define SiS_SD_PSEUDOXINERAMA  0x00004000   /* pseudo xinerama is active */
676#define SiS_SD_SUPPORTLCDA     0x00008000   /* Support LCD Channel A */
677#define SiS_SD_SUPPORTNTSCJ    0x00010000   /* tv chip supports ntsc-j */
678#define SiS_SD_ADDLSUPFLAG     0x00020000   /* 1 = the following flags are valid */
679#define SiS_SD_SUPPORTVGA2     0x00040000   /* CRT2=VGA supported */
680#define SiS_SD_SUPPORTSCART    0x00080000   /* CRT2=SCART supported */
681#define SiS_SD_SUPPORTOVERSCAN 0x00100000   /* Overscan flag supported */
682#define SiS_SD_SUPPORTXVGAMMA1 0x00200000   /* Xv Gamma correction for CRT1 supported */
683#define SiS_SD_SUPPORTTV       0x00400000   /* CRT2=TV supported */
684#define SiS_SD_SUPPORTYPBPR    0x00800000   /* CRT2=YPbPr (525i, 525p, 750p, 1080i) is supported */
685#define SiS_SD_SUPPORTHIVISION 0x01000000   /* CRT2=HiVision is supported */
686#define SiS_SD_SUPPORTYPBPRAR  0x02000000   /* YPbPr aspect ratio is supported */
687#define SiS_SD_SUPPORTSCALE    0x04000000   /* Scaling of LCD panel supported */
688#define SiS_SD_SUPPORTCENTER   0x08000000   /* If scaling supported: Centering of screen [NOT] supported (TMDS only) */
689#define SiS_SD_SUPPORTREDETECT 0x10000000   /* Support re-detection of CRT2 devices */
690#define SiS_SD_IS340SERIES     0x20000000
691#define SiS_SD_SUPPORTSGRCRT2  0x40000000   /* Separate CRT2 gamma correction supported */
692#define SiS_SD_CANSETGAMMA     0x80000000   /* Driver can set gamma ramp; otherwise: App needs to reset palette */
693					    /* after disabling sep CRT2 gamma corr */
694
695#define SiS_SD2_LCDTMDS	       0x00000001   /* SiS Bridge supports TMDS (DVI-D) */
696#define SiS_SD2_LCDLVDS	       0x00000002   /* SiS Bridge supports LVDS */
697#define SiS_SD2_SUPPORTLCD     0x00000004   /* Bridge supports LCD (LVDS or TMDS, SiS+3rd party) */
698#define SiS_SD2_SUPPORTTVSIZE  0x00000008   /* TV resizing supported (SiS bridges) */
699#define SiS_SD2_SUPPORTTVTYPE  0x00000010   /* TV type selection supported (SiS bridges) */
700#define SiS_SD2_SUPPORTGAMMA2  0x00000020   /* Gamma corr for CRT2 supported (SiS bridges) */
701#define SiS_SD2_SISBRIDGE      0x00000040   /* SiS bridge */
702#define SiS_SD2_SUPPTVSAT      0x00000080   /* TV saturation supported */
703#define SiS_SD2_SUPPTVEDGE     0x00000100   /* TV edge enhancement supported */
704#define SiS_SD2_CHRONTEL       0x00000200   /* Chrontel TV encoder present */
705#define SiS_SD2_VIDEOBRIDGE    0x00000400   /* Any type of video bridge present */
706#define SiS_SD2_THIRDPARTYLVDS 0x00000800   /* Third party LVDS (non-SiS) */
707#define SiS_SD2_ADDLFLAGS      0x00001000   /* Following flags valid */
708#define SiS_SD2_SUPPORT760OO   0x00002000   /* Support dynamic one/two overlay configuration changes         */
709					    /*    (If set, utility must re-read SD2 flags after mode change) */
710#define SiS_SD2_SIS760ONEOVL   0x00004000   /* (76x:) Only one overlay currently */
711#define SiS_SD2_MERGEDUCLOCK   0x00008000   /* Provide VRefresh in mode->Clock field in MergedFB mode */
712#define SiS_SD2_SUPPORTXVHUESAT 0x00010000  /* Xv: Support hue & saturation */
713#define SiS_SD2_NEEDUSESSE     0x00020000   /* Need "UseSSE" option to use SSE (otherwise auto) */
714#define SiS_SD2_NODDCSUPPORT   0x00040000   /* No hardware DDC support (USB) */
715#define SiS_SD2_SUPPORTXVDEINT 0x00080000   /* Xv deinterlacing supported (n/a, for future use) */
716#define SiS_SD2_ISXGI	       0x00100000   /* Is XGI chip */
717#define SiS_SD2_USEVBFLAGS2    0x00200000   /* Use VBFlags2 for bridge ID */
718#define SiS_SD2_SUPPLTFLAG     0x00400000   /* Driver supports the following 3 flags */
719#define SiS_SD2_ISLAPTOP       0x00800000   /* This machine is (very probably) a laptop */
720#define SiS_SD2_MACHINETYPE2   0x01000000   /* Machine type 2 (for future use) */
721#define SiS_SD2_MACHINETYPE3   0x02000000   /* Machine type 3 (for future use) */
722#define SiS_SD2_SUPPORT625I    0x04000000   /* Support YPbPr 625i */
723#define SiS_SD2_SUPPORT625P    0x08000000   /* Support YPbPr 625p */
724#define SiS_SD2_VBINVB2ONLY    0x10000000   /* VB_* bits in vbflags no longer used for vb type */
725#define SiS_SD2_NEWGAMMABRICON 0x20000000   /* Support new gamma brightness/contrast */
726#define SiS_SD2_HAVESD34       0x40000000   /* Support SD3 and SD4 flags */
727#define SiS_SD2_NOOVERLAY      0x80000000   /* No video overlay */
728
729#define SiS_SD3_OLDGAMMAINUSE  0x00000001   /* Old gamma brightness is currently in use */
730#define SiS_SD3_MFBALLOWOFFCL  0x00000002   /* Supports off'ing CRTx in MFB if a clone mode is active */
731#define SiS_SD3_SUPPORTVBF34   0x00000004   /* Supports VBFlags3 and VBFlags4 */
732#define SiS_SD3_SUPPORTDUALDVI 0x00000008   /* Supports dual dvi-d (for future use) */
733#define SiS_SD3_SUPPORTDUALTV  0x00000010   /* Supports dual tv (for future use) */
734#define SiS_SD3_NEWOUTPUTSW    0x00000020   /* Supports NEWSETVBFLAGS (for future use) */
735#define SiS_SD3_CRT1SATGAIN    0x00000040   /* Supports CRT1 saturation gain */
736#define SiS_SD3_CRT2SATGAIN    0x00000080   /* Supports CRT2 saturation gain (apart from TV, see SiS_SD2_SUPPTVSAT) */
737
738#define SIS_DIRECTKEY          0x03145792
739
740/* SiSCtrl: Check mode for CRT2 */
741#define SiS_CF2_LCD          0x01
742#define SiS_CF2_TV           0x02
743#define SiS_CF2_VGA2         0x04
744#define SiS_CF2_TVPAL        0x08
745#define SiS_CF2_TVNTSC       0x10  /* + NTSC-J */
746#define SiS_CF2_TVPALM       0x20
747#define SiS_CF2_TVPALN       0x40
748#define SiS_CF2_CRT1LCDA     0x80
749#define SiS_CF2_TYPEMASK     (SiS_CF2_LCD | SiS_CF2_TV | SiS_CF2_VGA2 | SiS_CF2_CRT1LCDA)
750#define SiS_CF2_TVSPECIAL    (SiS_CF2_LCD | SiS_CF2_TV)
751#define SiS_CF2_TVSPECMASK   (SiS_CF2_TVPAL | SiS_CF2_TVNTSC | SiS_CF2_TVPALM | SiS_CF2_TVPALN)
752#define SiS_CF2_TVHIVISION   SiS_CF2_TVPAL
753#define SiS_CF2_TVYPBPR525I  SiS_CF2_TVNTSC
754#define SiS_CF2_TVYPBPR525P  (SiS_CF2_TVPAL | SiS_CF2_TVNTSC)
755#define SiS_CF2_TVYPBPR625I  SiS_CF2_TVPALN
756#define SiS_CF2_TVYPBPR625P  (SiS_CF2_TVPALN | SiS_CF2_TVPAL)
757#define SiS_CF2_TVYPBPR750P  SiS_CF2_TVPALM
758#define SiS_CF2_TVYPBPR1080I (SiS_CF2_TVPALM | SiS_CF2_TVPAL)
759
760/* AGP stuff for DRI */
761#define AGP_PAGE_SIZE 4096
762#define AGP_PAGES     2048	 /* Default: 2048 pages @ 4096 = 8MB */
763/* 300 */
764#define AGP_CMDBUF_PAGES 256
765#define AGP_CMDBUF_SIZE (AGP_PAGE_SIZE * AGP_CMDBUF_PAGES)
766/* 315/330 */
767#define AGP_VTXBUF_PAGES 512
768#define AGP_VTXBUF_SIZE (AGP_PAGE_SIZE * AGP_VTXBUF_PAGES)
769
770/* Defines for our own vgaHW functions */
771#define SISVGA_SR_MODE	 0x01
772#define SISVGA_SR_FONTS	 0x02
773#define SISVGA_SR_CMAP	 0x04
774#define SISVGA_SR_ALL	 (SISVGA_SR_MODE | SISVGA_SR_FONTS | SISVGA_SR_CMAP)
775
776#define SISKGA_FIX_OVERSCAN   1 /* overcan correction required */
777#define SISKGA_ENABLE_ON_ZERO 2 /* if possible enable display at beginning of next scanline/frame */
778#define SISKGA_BE_TOT_DEC     4 /* always fix problem by setting blank end */
779
780/* CPU flags (for memcpy() etc.) */
781#define SIS_CPUFL_LIBC  0x0001
782#define SIS_CPUFL_BI    0x0002
783#define SIS_CPUFL_SSE   0x0004
784#define SIS_CPUFL_MMX   0x0008
785#define SIS_CPUFL_3DNOW 0x0010
786#define SIS_CPUFL_MMX2  0x0020
787#define SIS_CPUFL_BI2   0x0040
788#define SIS_CPUFL_SSE2  0x0080
789#define SIS_CPUFL_FLAG  0x8000
790
791/* Convenience macro for sisfb version checks */
792#define SISFB_VERSION(a,b,c) ((a << 16) | (b << 8) | c)
793
794/* For backup of register contents */
795typedef struct {
796    UChar  sisRegMiscOut;
797    UChar  sisRegsATTR[22];
798    UChar  sisRegsGR[10];
799    UChar  sisDAC[768];
800    UChar  sisRegs3C4[0x80];
801    UChar  sisRegs3D4[0x100];
802    UChar  sisRegs3C2;
803    UChar  sisCapt[0x60];
804    UChar  sisVid[0x50];
805    UChar  VBPart1[0x80];
806    UChar  VBPart2[0x100];
807    UChar  VBPart3[0x50];
808    UChar  VBPart4[0x50];
809    UShort ch70xx[64];
810    unsigned int sisMMIO85C0;
811    UChar  sis6326tv[0x46];
812    unsigned int sisRegsPCI50, sisRegsPCIA0;
813    UChar  BIOSModeSave;
814} SISRegRec, *SISRegPtr;
815
816typedef struct _sisModeInfoPtr {
817    int width;
818    int height;
819    int bpp;
820    int n;
821    struct _sisModeInfoPtr *next;
822} sisModeInfoRec, *sisModeInfoPtr;
823
824/* SISFBLayout (which has nothing to do with sisfb, actually)
825 * is mainly there because of DGA. It holds the current layout
826 * parameters needed for acceleration and other stuff. When
827 * switching mode using DGA, these are set up accordingly and
828 * not necessarily match pScrn's. Therefore, driver modules
829 * should read these values instead of pScrn's.
830 */
831typedef struct {
832    int		    bitsPerPixel;    /* = pScrn->bitsPerPixel */
833    int		    depth;	     /* = pScrn->depth */
834    int		    displayWidth;    /* = pScrn->displayWidth */
835    int		    displayHeight;   /* = imageHeight from DGA mode; ONLY WHEN DGA IS ACTIVE!!! */
836    int		    DGAViewportX;
837    int		    DGAViewportY;
838    DisplayModePtr  mode;	     /* = pScrn->currentMode */
839} SISFBLayout;
840
841/* For extended memcpy() */
842typedef void (*vidCopyFunc)(UChar *, const UChar *, int);
843
844#ifdef SISISXORG6899900
845#define SISAGPHTYPE drm_handle_t
846#else
847#define SISAGPHTYPE ULong
848#endif
849
850/* Dual head private entity structure */
851#ifdef SISDUALHEAD
852typedef struct {
853    ScrnInfoPtr		pScrn_1;
854    ScrnInfoPtr		pScrn_2;
855    UChar		*BIOS;
856    struct SiS_Private	*SiS_Pr;
857#ifdef SISDRI
858    SISAGPHTYPE		agpHandle;
859    ULong		agpAddr;
860    UChar		*agpBase;
861    unsigned int	agpSize;
862    unsigned int	agpWantedSize;
863    unsigned int	agpWantedPages;
864    ULong		agpCmdBufAddr;		/* 300 series */
865    UChar		*agpCmdBufBase;
866    unsigned int	agpCmdBufSize;
867    unsigned int	agpCmdBufFree;
868    ULong		agpVtxBufAddr;		/* 315/330 series */
869    UChar       	*agpVtxBufBase;
870    unsigned int	agpVtxBufSize;
871    unsigned int	agpVtxBufFree;
872    sisRegion		agp;
873    int			drmSubFD;
874#endif
875    Bool		AGPInitOK;
876    int			CRT1ModeNo;		/* Current display mode for CRT1 */
877    DisplayModePtr	CRT1DMode;		/* Current display mode for CRT1 */
878    int 		CRT2ModeNo;		/* Current display mode for CRT2 */
879    DisplayModePtr	CRT2DMode;		/* Current display mode for CRT2 */
880    Bool		CRT2ModeSet;		/* CRT2 mode has been set */
881    Bool		CRT2IsCustom;
882    UChar		CRT2CR30, CRT2CR31, CRT2CR35, CRT2CR38;
883    int			refCount;
884    int			lastInstance;		/* number of entities */
885    Bool		DisableDual;		/* Emergency flag */
886    Bool		ErrorAfterFirst;	/* Emergency flag: Error after first init -> Abort second */
887    Bool		HWCursor;		/* Backup master settings for use on slave */
888    Bool		TurboQueue;
889    int			ForceCRT1Type;
890    Bool		CRT1TypeForced;
891    int			ForceCRT2Type;
892    int			OptTVStand;
893    int			OptTVOver;
894    int			OptTVSOver;
895    int			OptROMUsage;
896    int			OptUseOEM;
897    Bool		NoAccel;
898    Bool		useEXA;
899    int			forceCRT1;
900    int			DSTN, FSTN;
901    Bool		XvOnCRT2;
902    int			maxUsedClock;		/* Max used pixelclock on master head */
903    ULong		masterFbAddress;	/* Framebuffer addresses and sizes */
904    ULong		masterFbSize;
905    ULong		slaveFbAddress;
906    ULong		slaveFbSize;
907    void		*FbBase;         	/* VRAM linear address */
908    UChar		*RealFbBase;         	/* Real VRAM linear address (for DHM, SiS76x UMA skipping) */
909    void		*IOBase;         	/* MMIO linear address */
910    UShort		MapCountIOBase;		/* map/unmap queue counter */
911    UShort		MapCountFbBase;		/* map/unmap queue counter */
912    Bool		forceUnmapIOBase;	/* ignore counter and unmap */
913    Bool		forceUnmapFbBase;	/* ignore counter and unmap */
914#ifdef __alpha__
915    void		*IOBaseDense;    	/* MMIO for Alpha platform */
916    UShort		MapCountIOBaseDense;
917    Bool		forceUnmapIOBaseDense;  /* ignore counter and unmap */
918#endif
919    int			chtvlumabandwidthcvbs;  /* TV settings for Chrontel TV encoder */
920    int			chtvlumabandwidthsvideo;
921    int			chtvlumaflickerfilter;
922    int			chtvchromabandwidth;
923    int			chtvchromaflickerfilter;
924    int			chtvcvbscolor;
925    int			chtvtextenhance;
926    int			chtvcontrast;
927    int			sistvedgeenhance;	/* TV settings for SiS bridge */
928    int			sistvantiflicker;
929    int			sistvsaturation;
930    int			sistvcolcalibc;
931    int			sistvcolcalibf;
932    int			sistvcfilter;
933    int			sistvyfilter;
934    int			tvxpos, tvypos;
935    int			tvxscale, tvyscale;
936    int			siscrt1satgain;
937    Bool		crt1satgaingiven;
938    int			ForceTVType, SenseYPbPr;
939    unsigned int	ForceYPbPrType, ForceYPbPrAR;
940    int			chtvtype;
941    int			NonDefaultPAL, NonDefaultNTSC;
942    UShort		tvx, tvy;
943    UChar		p2_01, p2_02, p2_1f, p2_20, p2_43, p2_42, p2_2b;
944    UChar		p2_44, p2_45, p2_46;
945    unsigned int	sistvccbase;
946    UChar		p2_35, p2_36, p2_37, p2_38, p2_48, p2_49, p2_4a;
947    UChar		p2_0a, p2_2f, p2_30, p2_47;
948    UChar		scalingp1[9], scalingp4[9], scalingp2[64];
949    UShort		cursorBufferNum;
950    Bool		restorebyset;
951    Bool		CRT1gamma, CRT1gammaGiven, CRT2gamma, XvGamma, XvGammaGiven, XvDefAdaptorBlit;
952    int			XvGammaRed, XvGammaGreen, XvGammaBlue;
953    int			GammaBriR, GammaBriG, GammaBriB;		/* strictly for Xinerama */
954    float		NewGammaBriR, NewGammaBriG, NewGammaBriB;	/* strictly for Xinerama */
955    float		NewGammaConR, NewGammaConG, NewGammaConB;	/* strictly for Xinerama */
956    unsigned int	CRT1MonGamma, CRT2MonGamma;
957    unsigned int	CRT1VGAMonitorGamma, CRT2LCDMonitorGamma, CRT2VGAMonitorGamma;
958    int			curxvcrtnum;
959    int			UsePanelScaler, CenterLCD;
960    int			AllowHotkey;
961    Bool		enablesisctrl;
962    unsigned int	cmdQ_SharedWritePort_2D;
963    UChar		*RenderAccelArray;
964    UChar		*FbBase1;
965    ULong		OnScreenSize1;
966    UChar		OldMode;
967    int			HWCursorMBufNum, HWCursorCBufNum;
968    Bool		ROM661New;
969    Bool		HaveXGIBIOS;
970    Bool		XvUseMemcpy;
971    Bool		BenchMemCpy;
972    Bool		HaveFastVidCpy;
973    vidCopyFunc		SiSFastVidCopy, SiSFastMemCopy;
974    vidCopyFunc		SiSFastVidCopyFrom, SiSFastMemCopyFrom;
975    unsigned int	CPUFlags;
976#ifdef SIS_NEED_MAP_IOP
977    CARD32		IOPAddress;		/* I/O port physical address */
978    void		*IOPBase;		/* I/O port linear address */
979    UShort		MapCountIOPBase;	/* map/unmap queue counter */
980    Bool		forceUnmapIOPBase;	/* ignore counter and unmap */
981#endif
982#ifdef SIS_CP
983    SIS_CP_H_ENT
984#endif
985} SISEntRec, *SISEntPtr;
986#endif
987
988#define SISPTR(p)       ((SISPtr)((p)->driverPrivate))
989#define XAAPTR(p)       ((XAAInfoRecPtr)(SISPTR(p)->AccelInfoPtr))
990
991/* MergedFB: Relative position */
992typedef enum {
993   sisLeftOf,
994   sisRightOf,
995   sisAbove,
996   sisBelow,
997   sisClone
998} SiSScrn2Rel;
999
1000typedef struct _region {
1001    int x0,x1,y0,y1;
1002} region;
1003
1004typedef struct {
1005    ScrnInfoPtr		pScrn;
1006    pciVideoPtr		PciInfo;
1007    int			PciBus, PciDevice, PciFunc;
1008    PCITAG		PciTag;
1009    EntityInfoPtr	pEnt;
1010    int			Chipset;
1011    unsigned char	ChipType;
1012    int			ChipRev;
1013    int			VGAEngine;	/* see above */
1014    int			hasTwoOverlays;	/* Chipset supports two video overlays? */
1015    struct SiS_Private	*SiS_Pr;	/* For mode switching code */
1016    int			DSTN;		/* For 550 FSTN/DSTN; set by option, no detection */
1017    ULong		FbAddress;	/* VRAM physical address (in DHM: for each Fb!) */
1018    ULong		realFbAddress;	/* For DHM/PCI mem mapping: store global FBAddress */
1019    void 		*FbBase;	/* VRAM virtual linear address */
1020    void 		*RealFbBase;	/* Real VRAM virtual linear address (for DHM and SiS76x UMA skipping) */
1021    CARD32		IOAddress;	/* MMIO physical address */
1022    void		*IOBase;	/* MMIO linear address */
1023    unsigned long	IODBase;	/* Base of PIO memory area */
1024#ifdef __alpha__
1025    void		*IOBaseDense;	/* MMIO for Alpha platform */
1026#endif
1027    SISIOADDRESS        RelIO;		/* Relocated IO Ports baseaddress */
1028    UChar		*BIOS;
1029    int			MemClock;
1030    int			BusWidth;
1031    int			MinClock;
1032    int			MaxClock;
1033    int			Flags;		/* HW config flags */
1034    long		FbMapSize;	/* Used for Mem Mapping - DON'T CHANGE THIS */
1035    long		availMem;	/* Really available Fb mem (minus TQ, HWCursor) */
1036    unsigned int	maxxfbmem;	/* limit fb memory X is to use to this (KB) */
1037    unsigned int	sisfbHeapStart;	/* heapstart of sisfb (if running) */
1038    unsigned int	dhmOffset;	/* Offset to memory for each head (0 or ..); also used on SiS76x/UMA+LFB */
1039    unsigned int	FbBaseOffset;
1040    DGAModePtr		DGAModes;
1041    int			numDGAModes;
1042    Bool		DGAactive;
1043    int			DGAViewportStatus;
1044    UChar       	OldMode;	/* Back old modeNo (if available) */
1045    Bool		NoAccel;
1046    Bool		NoXvideo;
1047    Bool		XvOnCRT2;	/* see sis_opt.c */
1048    Bool		HWCursor;
1049    Bool		UsePCIRetry;
1050    Bool		TurboQueue;
1051    int			VESA;
1052    int			ForceCRT1Type;
1053    Bool		CRT1Detected, CRT1TypeForced;
1054    int			ForceCRT2Type;
1055    int			OptTVStand;
1056    int			OptTVOver;
1057    int			OptROMUsage;
1058    int			UseCHOverScan;
1059    Bool		ValidWidth;
1060    Bool		FastVram;		/* now unused */
1061    int			forceCRT1;
1062    Bool		CRT1changed;
1063    UChar		oldCR17, oldCR63, oldSR1F;
1064    UChar		oldCR32, oldCR36, oldCR37;
1065    UChar		myCR32, myCR36, myCR37, myCR63;
1066    UChar		newCR32;
1067    unsigned int	VBFlags;		/* Video bridge configuration (dynamic) */
1068    unsigned int	VBFlags2;		/* Video bridge configuration 2 (static flags only) */
1069    unsigned int	VBFlags3, VBFlags4;	/* Video bridge configuration 3, 4 (dynamic) */
1070    unsigned int	VBFlags_backup;		/* Backup for SlaveMode-modes */
1071    unsigned int	VBFlags_backup3;	/* Backup for SlaveMode-modes */
1072    unsigned int	VBFlags_backup4;	/* Backup for SlaveMode-modes */
1073    unsigned int	VBLCDFlags, VBLCDFlags2;
1074    int			ChrontelType;		/* CHRONTEL_700x or CHRONTEL_701x */
1075    unsigned int	PDC, PDCA;		/* PanelDelayCompensation */
1076    short		scrnOffset;		/* Screen pitch (data) */
1077    short		scrnPitch;		/* Screen pitch (display; regarding interlace) */
1078    short		DstColor;
1079    unsigned int	SiS310_AccelDepth;	/* used in accel for 315 series */
1080    int			MaxCMDQueueLen;
1081    int			CurCMDQueueLen;
1082    int			MinCMDQueueLen;
1083    CARD16		CursorSize;		/* Size of HWCursor area (bytes) */
1084    CARD32		cursorOffset;		/* see sis_driver.c and sis_cursor.c */
1085    Bool		useEXA;
1086    void 		(*InitAccel)(ScrnInfoPtr pScrn);
1087    void 		(*SyncAccel)(ScrnInfoPtr pScrn);
1088    void		(*FillRect)(ScrnInfoPtr pScrn, int x, int y, int w, int h, int color);
1089    void		(*BlitRect)(ScrnInfoPtr pScrn, int srcx, int srcy, int dstx, int dsty,
1090					int w, int h, int color);
1091    int			CommandReg;
1092    Bool		ClipEnabled;
1093    int			Xdirection;		/* for temp use in accel */
1094    int			Ydirection;		/* for temp use in accel */
1095#ifdef SIS_USE_XAA
1096    XAAInfoRecPtr	AccelInfoPtr;
1097    UChar 		*XAAScanlineColorExpandBuffers[2];
1098    Bool		DoColorExpand;
1099    Bool		ColorExpandBusy;
1100    int			xcurrent;		/* for temp use in accel */
1101    int			ycurrent;		/* for temp use in accel */
1102    int			sisPatternReg[4];
1103    int			ROPReg;
1104#endif
1105#ifdef SIS_USE_EXA
1106    ExaDriverPtr	EXADriverPtr;
1107    int			fillPitch, fillBpp;
1108    CARD32		fillDstBase;
1109    int			copyBpp;
1110    int			copySPitch, copyDPitch;
1111    CARD32		copySrcBase, copyDstBase;
1112    int			copyXdir, copyYdir;
1113    ExaOffscreenArea *	exa_scratch;
1114    unsigned int 	exa_scratch_next;
1115#endif
1116    Bool		alphaBlitBusy;
1117    SISRegRec		SavedReg;
1118    SISRegRec		ModeReg;
1119    xf86CursorInfoPtr	CursorInfoPtr;
1120    CloseScreenProcPtr	CloseScreen;
1121    Bool		(*ModeInit)(ScrnInfoPtr pScrn, DisplayModePtr mode);
1122    void		(*SiSSave)(ScrnInfoPtr pScrn, SISRegPtr sisreg);
1123    void		(*SiSRestore)(ScrnInfoPtr pScrn, SISRegPtr sisreg);
1124    int			cmdQueueLen;		/* Current cmdQueueLength (for 2D and 3D) */
1125    unsigned int	*cmdQueueBase;
1126    int			*cmdQueueLenPtr;	/* Ptr to variable holding the current queue length */
1127    int			*cmdQueueLenPtrBackup;	/* Backup for DRI init/restore */
1128    unsigned int	cmdQueueOffset;
1129    unsigned int	cmdQueueSize;
1130    unsigned int	cmdQueueSizeMask;
1131    unsigned int	cmdQ_SharedWritePort_2D;
1132    unsigned int	*cmdQ_SharedWritePort;
1133    unsigned int	*cmdQ_SharedWritePortBackup;
1134    unsigned int	cmdQueueSize_div2;
1135    unsigned int	cmdQueueSize_div4;
1136    unsigned int	cmdQueueSize_4_3;
1137#ifdef SISDRI
1138    SISAGPHTYPE		agpHandle;
1139    ULong		agpAddr;
1140    UChar 		*agpBase;
1141    unsigned int	agpSize;
1142    unsigned int	agpWantedSize;
1143    unsigned int	agpWantedPages;
1144    ULong		agpCmdBufAddr;	/* 300 series */
1145    UChar		*agpCmdBufBase;
1146    unsigned int	agpCmdBufSize;
1147    unsigned int	agpCmdBufFree;
1148    ULong		agpVtxBufAddr;	/* 315 series */
1149    UChar		*agpVtxBufBase;
1150    unsigned int	agpVtxBufSize;
1151    unsigned int	agpVtxBufFree;
1152    sisRegion		agp;
1153#endif
1154    Bool		AGPInitOK;
1155    Bool		irqEnabled;
1156    int			irq;
1157    Bool		IsAGPCard, IsPCIExpress;
1158    unsigned int	DRIheapstart, DRIheapend;
1159    Bool		NeedFlush;	/* Need to flush cmd buf mem (760) */
1160
1161#ifdef SIS_USE_XAA
1162    void		(*RenderCallback)(ScrnInfoPtr);
1163    Time		RenderTime;
1164    FBLinearPtr		AccelLinearScratch;
1165#endif
1166#ifdef SIS_USE_EXA
1167    void		(*ExaRenderCallback)(ScrnInfoPtr);
1168    Time		ExaRenderTime;
1169#endif
1170    UChar		*RenderAccelArray;
1171    Bool		doRender;
1172
1173    int			ColorExpandRingHead;
1174    int			ColorExpandRingTail;
1175    int			PerColorExpandBufferSize;
1176    int			ColorExpandBufferNumber;
1177    int			ColorExpandBufferCountMask;
1178    UChar		*ColorExpandBufferAddr[32];
1179    CARD32		ColorExpandBufferScreenOffset[32];
1180    CARD32		ColorExpandBase;
1181
1182    int			Rotate, Reflect;
1183    void		(*PointerMoved)(SCRN_ARG_TYPE arg, int x, int y);
1184
1185    /* ShadowFB support */
1186    Bool		ShadowFB;
1187    UChar		*ShadowPtr;
1188    int			ShadowPitch;
1189
1190#ifdef SISUSEDEVPORT
1191    Bool		sisdevportopen;
1192#endif
1193
1194    /* DRI */
1195    Bool		loadDRI;
1196#ifdef SISDRI
1197    Bool		directRenderingEnabled;
1198    DRIInfoPtr 		pDRIInfo;
1199    int			drmSubFD;
1200    int			numVisualConfigs;
1201    __GLXvisualConfig*	pVisualConfigs;
1202    SISConfigPrivPtr	pVisualConfigsPriv;
1203    SISRegRec		DRContextRegs;
1204#endif
1205
1206    /* Xv */
1207    XF86VideoAdaptorPtr adaptor;
1208    XF86VideoAdaptorPtr blitadaptor;
1209    void		*blitPriv;
1210    ScreenBlockHandlerProcPtr BlockHandler;
1211    void		(*VideoTimerCallback)(ScrnInfoPtr, Time);
1212    void		(*ResetXv)(ScrnInfoPtr);
1213    void		(*ResetXvDisplay)(ScrnInfoPtr);
1214    void		(*ResetXvGamma)(ScrnInfoPtr);
1215
1216    /* misc */
1217    OptionInfoPtr	Options;
1218    UChar		BIOSModeSave;
1219    int			CRT1off;		/* 1=CRT1 off, 0=CRT1 on */
1220    CARD16		LCDheight;		/* Vertical resolution of LCD panel */
1221    CARD16		LCDwidth;		/* Horizontal resolution of LCD panel */
1222    vbeInfoPtr 		pVbe;			/* For VESA mode switching */
1223    CARD16		vesamajor;
1224    CARD16		vesaminor;
1225    int			UseVESA;
1226    sisModeInfoPtr      SISVESAModeList;
1227    xf86MonPtr		monitor;
1228    CARD16		maxBytesPerScanline;
1229    CARD32		*pal, *savedPal;
1230    int			mapPhys, mapOff, mapSize;
1231    int			statePage, stateSize, stateMode;
1232    CARD8		*fonts;
1233    CARD8		*state, *pstate;
1234    void		*base, *VGAbase;
1235#ifdef SISDUALHEAD
1236    Bool		DualHeadMode;		/* TRUE if we use dual head mode */
1237    Bool		SecondHead;		/* TRUE is this is the second head */
1238    SISEntPtr		entityPrivate;		/* Ptr to private entity (see above) */
1239    Bool		SiSXinerama;		/* Do we use Xinerama mode? */
1240#endif
1241    SISFBLayout		CurrentLayout;		/* Current framebuffer layout */
1242    UShort		SiS_DDC2_Index;
1243    UShort		SiS_DDC2_Data;
1244    UShort		SiS_DDC2_Clk;
1245    Bool		Primary;		/* Display adapter is primary */
1246    Bool		VGADecodingEnabled;	/* a0000 memory adress decoding is enabled */
1247    xf86Int10InfoPtr	pInt;			/* Our int10 */
1248    int			oldChipset;		/* Type of old chipset */
1249    int			RealVideoRam;		/* 6326 can only address 4MB, but TQ can be above */
1250    CARD32		CmdQueLenMask;		/* Mask of queue length in MMIO register */
1251    CARD32		CmdQueLenFix;           /* Fix value to subtract from QueLen (530/620) */
1252    CARD32		CmdQueMaxLen;           /* (6326/5597/5598) Amount of cmds the queue can hold */
1253    CARD32		TurboQueueLen;		/* For future use */
1254    CARD32		detectedCRT2Devices;	/* detected CRT2 devices before mask-out */
1255    Bool		HostBus;		/* Enable/disable 5597/5598 host bus */
1256    Bool		noInternalModes;	/* Use our own default modes? */
1257    int			OptUseOEM;		/* Use internal OEM data? */
1258    int			chtvlumabandwidthcvbs;  /* TV settings for Chrontel TV encoder */
1259    int			chtvlumabandwidthsvideo;
1260    int			chtvlumaflickerfilter;
1261    int			chtvchromabandwidth;
1262    int			chtvchromaflickerfilter;
1263    int			chtvcvbscolor;
1264    int			chtvtextenhance;
1265    int			chtvcontrast;
1266    int			sistvedgeenhance;	/* TV settings for SiS bridges */
1267    int			sistvantiflicker;
1268    int			sistvsaturation;
1269    int			sistvcolcalibc;
1270    int			sistvcolcalibf;
1271    int			sistvcfilter;
1272    int			sistvyfilter;
1273    int			OptTVSOver;		/* Chrontel 7005: Superoverscan */
1274    int			tvxpos, tvypos;
1275    int			tvxscale, tvyscale;
1276    int			SiS6326Flags;		/* SiS6326 TV settings */
1277    int			sis6326enableyfilter;
1278    int			sis6326yfilterstrong;
1279    int			sis6326tvplug;
1280    int			sis6326fscadjust;
1281    Bool		sisfbfound;
1282    Bool		donttrustpdc;		/* Don't trust the detected PDC */
1283    UChar		sisfbpdc, sisfbpdca;
1284    UChar       	sisfblcda;
1285    int			sisfbscalelcd;
1286    unsigned int	sisfbspecialtiming;
1287    Bool		sisfb_haveemi, sisfb_haveemilcd, sisfb_tvposvalid, sisfb_havelock;
1288    UChar		sisfb_emi30,sisfb_emi31,sisfb_emi32,sisfb_emi33;
1289    int			sisfb_tvxpos, sisfb_tvypos;
1290    int			siscrt1satgain;
1291    Bool		crt1satgaingiven;
1292    Bool		sisfbHaveNewHeapDef;
1293    unsigned int	sisfbHeapSize, sisfbVideoOffset;
1294    Bool		sisfbxSTN;
1295    unsigned int	sisfbDSTN, sisfbFSTN;
1296    Bool		sisfbcanpost, sisfbcardposted, sisfbprimary;
1297    char		sisfbdevname[16];
1298    int			EMI;
1299    int			PRGB;
1300    int			NoYV12;			/* Disable Xv YV12 support (old series) */
1301    UChar       	postVBCR32;
1302    int			newFastVram;		/* Replaces FastVram */
1303    int			ForceTVType, SenseYPbPr;
1304    int			NonDefaultPAL, NonDefaultNTSC;
1305    unsigned int	ForceYPbPrType, ForceYPbPrAR;
1306    ULong		lockcalls;		/* Count unlock calls for debug */
1307    UShort		tvx, tvy;		/* Backup TV position registers */
1308    UChar		p2_01, p2_02, p2_1f, p2_20, p2_43, p2_42, p2_2b; /* Backup TV position registers */
1309    UShort      	tvx1, tvx2, tvx3, tvy1;	/* Backup TV position registers */
1310    UChar		p2_44, p2_45, p2_46;
1311    unsigned int	sistvccbase;
1312    UChar		p2_35, p2_36, p2_37, p2_38, p2_48, p2_49, p2_4a;
1313    UChar		p2_0a, p2_2f, p2_30, p2_47;
1314    UChar		scalingp1[9], scalingp4[9], scalingp2[64];
1315    Bool		ForceCursorOff;
1316    Bool		HaveCustomModes;
1317    Bool		IsCustom;
1318    DisplayModePtr	backupmodelist;
1319    int			chtvtype;
1320    Atom		xvBrightness, xvContrast, xvColorKey, xvHue, xvSaturation;
1321    Atom		xvAutopaintColorKey, xvSetDefaults, xvSwitchCRT;
1322    Atom		xvDisableGfx, xvDisableGfxLR, xvTVXPosition, xvTVYPosition;
1323    Atom		xvDisableColorkey, xvUseChromakey, xvChromaMin, xvChromaMax;
1324    Atom		xvInsideChromakey, xvYUVChromakey, xvVSync;
1325#ifdef SISDEINT
1326    Atom		xvdeintmeth;
1327#endif
1328    Atom		xvGammaRed, xvGammaGreen, xvGammaBlue;
1329#ifdef XV_SD_DEPRECATED
1330    Atom		xv_QVF, xv_QVV, xv_USD, xv_SVF, xv_QDD, xv_TAF, xv_TSA, xv_TEE, xv_GSF;
1331    Atom		xv_TTE, xv_TCO, xv_TCC, xv_TCF, xv_TLF, xv_CMD, xv_CMDR, xv_CT1, xv_SGA;
1332    Atom		xv_GDV, xv_GHI, xv_OVR, xv_GBI, xv_TXS, xv_TYS, xv_CFI, xv_COC, xv_COF;
1333    Atom		xv_YFI, xv_GSS, xv_BRR, xv_BRG, xv_BRB, xv_PBR, xv_PBG, xv_PBB, xv_SHC;
1334    Atom		xv_BRR2, xv_BRG2, xv_BRB2, xv_PBR2, xv_PBG2, xv_PBB2, xv_PMD, xv_RDT;
1335    Atom		xv_GARC2,xv_GAGC2,xv_GABC2, xv_GSF2;
1336    Atom		xv_BRRC2, xv_BRGC2, xv_BRBC2, xv_PBRC2, xv_PBGC2, xv_PBBC2;
1337#ifdef TWDEBUG
1338    Atom		xv_STR;
1339#endif
1340    unsigned int	xv_sd_result;
1341#endif /* XV_SD_DEPRECATED */
1342    int			xv_sisdirectunlocked;
1343    int			SiS76xLFBSize;
1344    int			SiS76xUMASize;
1345    int			CRT1isoff;
1346    ULong		UMAsize, LFBsize;	/* For SiSCtrl extension info only */
1347#ifdef SIS_CP
1348    SIS_CP_H
1349#endif
1350    ULong		ChipFlags;
1351    ULong		SiS_SD_Flags, SiS_SD2_Flags, SiS_SD3_Flags, SiS_SD4_Flags;
1352    Bool		UseHWARGBCursor;
1353    int			OptUseColorCursor;
1354    int			OptUseColorCursorBlend;
1355    CARD32		OptColorCursorBlendThreshold;
1356    UShort		cursorBufferNum;
1357    int			vb;
1358    Bool		restorebyset;
1359    Bool		nocrt2ddcdetection;
1360    Bool		forcecrt2redetection;
1361    Bool		CRT1gamma, CRT1gammaGiven, CRT2gamma, XvGamma, XvGammaGiven;
1362    int			XvDefCon, XvDefBri, XvDefHue, XvDefSat;
1363    Bool		XvDefDisableGfx, XvDefDisableGfxLR, XvDefAdaptorBlit;
1364    Bool		XvUseMemcpy;
1365    Bool		XvUseChromaKey, XvDisableColorKey;
1366    Bool		XvInsideChromaKey, XvYUVChromaKey;
1367    int			XvChromaMin, XvChromaMax;
1368    int			XvGammaRed, XvGammaGreen, XvGammaBlue;
1369    int			XvGammaRedDef, XvGammaGreenDef, XvGammaBlueDef;
1370    CARD8		XvGammaRampRed[256], XvGammaRampGreen[256], XvGammaRampBlue[256];
1371    Bool		disablecolorkeycurrent;
1372    CARD32		colorKey;
1373    CARD32		MiscFlags;
1374    int			UsePanelScaler, CenterLCD;
1375    float		zClearVal;
1376    ULong		bClrColor, dwColor;
1377    int			AllowHotkey;
1378    Bool		enablesisctrl;
1379    short		Video_MaxWidth, Video_MaxHeight;
1380    int			FSTN;
1381    Bool		AddedPlasmaModes;
1382    short		scrnPitch2;
1383    CARD32		CurFGCol, CurBGCol;
1384    UChar		*CurMonoSrc;
1385    CARD32		*CurARGBDest;
1386    int			GammaBriR, GammaBriG, GammaBriB;
1387    unsigned int	CRT1MonGamma, CRT2MonGamma;
1388    unsigned int	CRT1VGAMonitorGamma, CRT2LCDMonitorGamma, CRT2VGAMonitorGamma;
1389    Bool		HideHWCursor;  /* Custom application */
1390    Bool		HWCursorIsVisible;
1391    unsigned int	HWCursorBackup[16];
1392    int			HWCursorMBufNum, HWCursorCBufNum;
1393    ULong		mmioSize;
1394    Bool		ROM661New;
1395    Bool		HaveXGIBIOS;
1396    Bool		NewCRLayout;
1397    Bool		skipswitchcheck;
1398    unsigned int	VBFlagsInit;
1399    DisplayModePtr	currentModeLast;
1400    unsigned long	MyPIOOffset;
1401    Bool		OverruleRanges;
1402    Bool		BenchMemCpy;
1403    Bool		NeedCopyFastVidCpy;
1404    Bool		SiSFastVidCopyDone;
1405    vidCopyFunc		SiSFastVidCopy, SiSFastMemCopy;
1406    vidCopyFunc		SiSFastVidCopyFrom, SiSFastMemCopyFrom;
1407    unsigned int	CPUFlags;
1408#ifndef SISCHECKOSSSE
1409    Bool		XvSSEMemcpy;
1410#endif
1411    char		messagebuffer[64];
1412    unsigned int	VGAMapSize;		/* SiSVGA stuff */
1413    ULong		VGAMapPhys;
1414    void 		*VGAMemBase; /* mapped */
1415    Bool		VGAPaletteEnabled;
1416    Bool		VGACMapSaved;
1417    Bool		CRT2SepGamma;		/* CRT2 separate gamma stuff */
1418    int			*crt2cindices;
1419    LOCO		*crt2gcolortable, *crt2colors;
1420    int			CRT2ColNum;
1421    float		GammaR2, GammaG2, GammaB2;
1422    int			GammaR2i, GammaG2i, GammaB2i;
1423    int			GammaBriR2, GammaBriG2, GammaBriB2;
1424    float		NewGammaBriR, NewGammaBriG, NewGammaBriB;
1425    float		NewGammaConR, NewGammaConG, NewGammaConB;
1426    float		NewGammaBriR2, NewGammaBriG2, NewGammaBriB2;
1427    float		NewGammaConR2, NewGammaConG2, NewGammaConB2;
1428    ExtensionEntry	*SiSCtrlExtEntry;
1429    char		devsectname[32];
1430    Bool		SCLogQuiet;
1431#ifdef SIS_NEED_MAP_IOP
1432    CARD32		IOPAddress;		/* I/O port physical address */
1433    void 		*IOPBase;		/* I/O port linear address */
1434#endif
1435#ifdef SISMERGED
1436    Bool		MergedFB, MergedFBAuto;
1437    SiSScrn2Rel		CRT2Position;
1438    char		*CRT2HSync;
1439    char		*CRT2VRefresh;
1440    char		*MetaModes;
1441    ScrnInfoPtr		CRT2pScrn;
1442    DisplayModePtr	CRT1Modes;
1443    DisplayModePtr	CRT1CurrentMode;
1444    int			CRT1frameX0;
1445    int			CRT1frameY0;
1446    int			CRT1frameX1;
1447    int			CRT1frameY1;
1448    Bool		CheckForCRT2;
1449    Bool		IsCustomCRT2;
1450    Bool		HaveCustomModes2;
1451    int			maxCRT1_X1, maxCRT1_X2, maxCRT1_Y1, maxCRT1_Y2;
1452    int			maxCRT2_X1, maxCRT2_X2, maxCRT2_Y1, maxCRT2_Y2;
1453    int			maxClone_X1, maxClone_X2, maxClone_Y1, maxClone_Y2;
1454    int			MergedFBXDPI, MergedFBYDPI;
1455    int			CRT1XOffs, CRT1YOffs, CRT2XOffs, CRT2YOffs;
1456    int			MBXNR1XMAX, MBXNR1YMAX, MBXNR2XMAX, MBXNR2YMAX;
1457    Bool		NonRect, HaveNonRect, HaveOffsRegions, MouseRestrictions;
1458    region		NonRectDead, OffDead1, OffDead2;
1459#ifdef SISXINERAMA
1460    Bool		UseSiSXinerama;
1461    Bool		CRT2IsScrn0;
1462    ExtensionEntry	*XineramaExtEntry;
1463    int			SiSXineramaVX, SiSXineramaVY;
1464    Bool		AtLeastOneNonClone;
1465#endif
1466#endif
1467} SISRec, *SISPtr;
1468
1469typedef struct _ModeInfoData {
1470    int mode;
1471    VbeModeInfoBlock *data;
1472    VbeCRTCInfoBlock *block;
1473} ModeInfoData;
1474
1475#define SDMPTR(x) ((SiSMergedDisplayModePtr)(x->currentMode->Private))
1476#define CDMPTR    ((SiSMergedDisplayModePtr)(pSiS->CurrentLayout.mode->Private))
1477
1478#define BOUND(test,low,hi) 			\
1479    {						\
1480	if((test) < (low)) (test) = (low);	\
1481	if((test) > (hi))  (test) = (hi);	\
1482    }
1483
1484#define REBOUND(low,hi,test)		\
1485    {					\
1486	if((test) < (low)) {		\
1487		(hi) += (test)-(low);	\
1488		(low) = (test); 	\
1489	}				\
1490	if((test) > (hi)) {		\
1491		(low) += (test)-(hi);	\
1492		(hi) = (test); 		\
1493	}				\
1494    }
1495
1496typedef struct _MergedDisplayModeRec {
1497    DisplayModePtr CRT1;
1498    DisplayModePtr CRT2;
1499    SiSScrn2Rel    CRT2Position;
1500} SiSMergedDisplayModeRec, *SiSMergedDisplayModePtr;
1501
1502typedef struct _myhddctiming {
1503    int    whichone;
1504    UChar  mask;
1505    float  rate;
1506} myhddctiming;
1507
1508typedef struct _myvddctiming {
1509    int    whichone;
1510    UChar  mask;
1511    int    rate;
1512} myvddctiming;
1513
1514typedef struct _pdctable {
1515    int  subsysVendor;
1516    int  subsysCard;
1517    int  pdc;
1518    char *vendorName;
1519    char *cardName;
1520} pdctable;
1521
1522typedef struct _chswtable {
1523    int  subsysVendor;
1524    int  subsysCard;
1525    char *vendorName;
1526    char *cardName;
1527} chswtable;
1528
1529typedef struct _customttable {
1530    UShort chipID;
1531    char   *biosversion;
1532    char   *biosdate;
1533    CARD32 bioschksum;
1534    UShort biosFootprintAddr[5];
1535    UChar  biosFootprintData[5];
1536    UShort pcisubsysvendor;
1537    UShort pcisubsyscard;
1538    char   *vendorName;
1539    char   *cardName;
1540    ULong  SpecialID;
1541    char   *optionName;
1542} customttable;
1543
1544#ifdef SISMERGED
1545#ifdef SISXINERAMA
1546typedef struct _SiSXineramaData {
1547    int x;
1548    int y;
1549    int width;
1550    int height;
1551} SiSXineramaData;
1552#endif
1553#endif
1554
1555extern const customttable SiS_customttable[];
1556
1557/* prototypes */
1558
1559extern void  sisSaveUnlockExtRegisterLock(SISPtr pSiS, UChar *reg1, UChar *reg2);
1560extern void  sisRestoreExtRegisterLock(SISPtr pSiS, UChar reg1, UChar reg2);
1561extern void  SiSOptions(ScrnInfoPtr pScrn);
1562extern const OptionInfoRec * SISAvailableOptions(int chipid, int busid);
1563extern void  SiSSetup(ScrnInfoPtr pScrn);
1564extern void  SISVGAPreInit(ScrnInfoPtr pScrn);
1565extern Bool  SiSHWCursorInit(ScreenPtr pScreen);
1566extern Bool  SiSAccelInit(ScreenPtr pScreen);
1567extern Bool  SiS300AccelInit(ScreenPtr pScreen);
1568extern Bool  SiS530AccelInit(ScreenPtr pScreen);
1569extern Bool  SiS315AccelInit(ScreenPtr pScreen);
1570extern void  SISInitVideo(ScreenPtr pScreen);
1571extern void  SIS6326InitVideo(ScreenPtr pScreen);
1572extern Bool  SISDGAInit(ScreenPtr pScreen);
1573
1574/* For extended mempy() support */
1575extern unsigned int SiSGetCPUFlags(ScrnInfoPtr pScrn);
1576extern vidCopyFunc SiSVidCopyInit(ScreenPtr pScreen, vidCopyFunc *UMemCpy, Bool from);
1577extern vidCopyFunc SiSVidCopyGetDefault(void);
1578
1579extern void  SiSMemCopyToVideoRam(SISPtr pSiS, UChar *to, UChar *from, int size);
1580extern void  SiSMemCopyFromVideoRam(SISPtr pSiS, UChar *to, UChar *from, int size);
1581
1582extern void  SiS_SetCHTVlumabandwidthcvbs(ScrnInfoPtr pScrn, int val);
1583extern void  SiS_SetCHTVlumabandwidthsvideo(ScrnInfoPtr pScrn, int val);
1584extern void  SiS_SetCHTVlumaflickerfilter(ScrnInfoPtr pScrn, int val);
1585extern void  SiS_SetCHTVchromabandwidth(ScrnInfoPtr pScrn, int val);
1586extern void  SiS_SetCHTVchromaflickerfilter(ScrnInfoPtr pScrn, int val);
1587extern void  SiS_SetCHTVcvbscolor(ScrnInfoPtr pScrn, int val);
1588extern void  SiS_SetCHTVtextenhance(ScrnInfoPtr pScrn, int val);
1589extern void  SiS_SetCHTVcontrast(ScrnInfoPtr pScrn, int val);
1590extern void  SiS_SetSISTVedgeenhance(ScrnInfoPtr pScrn, int val);
1591extern void  SiS_SetSISTVantiflicker(ScrnInfoPtr pScrn, int val);
1592extern void  SiS_SetSISTVsaturation(ScrnInfoPtr pScrn, int val);
1593extern void  SiS_SetSISTVcfilter(ScrnInfoPtr pScrn, int val);
1594extern void  SiS_SetSISTVyfilter(ScrnInfoPtr pScrn, int val);
1595extern void  SiS_SetSISTVcolcalib(ScrnInfoPtr pScrn, int val, Bool coarse);
1596extern void  SiS_SetSIS6326TVantiflicker(ScrnInfoPtr pScrn, int val);
1597extern void  SiS_SetSIS6326TVenableyfilter(ScrnInfoPtr pScrn, int val);
1598extern void  SiS_SetSIS6326TVyfilterstrong(ScrnInfoPtr pScrn, int val);
1599extern void  SiS_SetTVxposoffset(ScrnInfoPtr pScrn, int val);
1600extern void  SiS_SetTVyposoffset(ScrnInfoPtr pScrn, int val);
1601extern void  SiS_SetTVxscale(ScrnInfoPtr pScrn, int val);
1602extern void  SiS_SetTVyscale(ScrnInfoPtr pScrn, int val);
1603extern int   SiS_GetCHTVlumabandwidthcvbs(ScrnInfoPtr pScrn);
1604extern int   SiS_GetCHTVlumabandwidthsvideo(ScrnInfoPtr pScrn);
1605extern int   SiS_GetCHTVlumaflickerfilter(ScrnInfoPtr pScrn);
1606extern int   SiS_GetCHTVchromabandwidth(ScrnInfoPtr pScrn);
1607extern int   SiS_GetCHTVchromaflickerfilter(ScrnInfoPtr pScrn);
1608extern int   SiS_GetCHTVcvbscolor(ScrnInfoPtr pScrn);
1609extern int   SiS_GetCHTVtextenhance(ScrnInfoPtr pScrn);
1610extern int   SiS_GetCHTVcontrast(ScrnInfoPtr pScrn);
1611extern int   SiS_GetSISTVedgeenhance(ScrnInfoPtr pScrn);
1612extern int   SiS_GetSISTVantiflicker(ScrnInfoPtr pScrn);
1613extern int   SiS_GetSISTVsaturation(ScrnInfoPtr pScrn);
1614extern int   SiS_GetSISTVcfilter(ScrnInfoPtr pScrn);
1615extern int   SiS_GetSISTVyfilter(ScrnInfoPtr pScrn);
1616extern int   SiS_GetSISTVcolcalib(ScrnInfoPtr pScrn, Bool coarse);
1617extern int   SiS_GetSIS6326TVantiflicker(ScrnInfoPtr pScrn);
1618extern int   SiS_GetSIS6326TVenableyfilter(ScrnInfoPtr pScrn);
1619extern int   SiS_GetSIS6326TVyfilterstrong(ScrnInfoPtr pScrn);
1620extern int   SiS_GetTVxposoffset(ScrnInfoPtr pScrn);
1621extern int   SiS_GetTVyposoffset(ScrnInfoPtr pScrn);
1622extern int   SiS_GetTVxscale(ScrnInfoPtr pScrn);
1623extern int   SiS_GetTVyscale(ScrnInfoPtr pScrn);
1624extern int   SiS_GetSISCRT1SaturationGain(ScrnInfoPtr pScrn);
1625extern void  SiS_SetSISCRT1SaturationGain(ScrnInfoPtr pScrn, int val);
1626
1627extern unsigned int sis_pci_read_device_u32(int device, int offset);
1628extern unsigned char sis_pci_read_device_u8(int device, int offset);
1629extern unsigned int sis_pci_read_host_bridge_u32(int offset);
1630extern unsigned char sis_pci_read_host_bridge_u8(int offset);
1631extern void sis_pci_write_host_bridge_u8(int offset, unsigned char value);
1632extern void sis_pci_write_host_bridge_u32(int offset, unsigned int value);
1633#endif  /* _SIS_H_ */
1634
1635
1636
1637