sis_video.h revision 72b676d7
1/* $XFree86$ */
2/* $XdotOrg: driver/xf86-video-sis/src/sis_video.h,v 1.4 2005/07/04 10:57:08 twini Exp $ */
3/*
4 * Xv driver for SiS 300, 315 and 330 series.
5 *
6 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1) Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2) Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3) The name of the author may not be used to endorse or promote products
17 *    derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * Author:    Thomas Winischhofer <thomas@winischhofer.net>
31 *
32 * Formerly based on a mostly non-working code fragment for the 630 by
33 * Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan which is
34 * Copyright (C) 2000 Silicon Integrated Systems Corp, Inc.
35 *
36 * Basic structure based on the mga Xv driver by Mark Vojkovich
37 * and i810 Xv driver by Jonathan Bian <jonathan.bian@intel.com>.
38 *
39 * All comments in this file are by Thomas Winischhofer.
40 *
41 * The overlay adaptor supports the following chipsets:
42 *  SiS300: No registers >0x65, two overlays (one used for CRT1, one for CRT2)
43 *  SiS630/730: No registers >0x6b, two overlays (one used for CRT1, one for CRT2)
44 *  SiS550: Full register range, two overlays (one used for CRT1, one for CRT2)
45 *  SiS315: Full register range, one overlay (used for both CRT1 and CRT2 alt.)
46 *  SiS650/740: Full register range, one overlay (used for both CRT1 and CRT2 alt.)
47 *  SiSM650/651: Full register range, two overlays (one used for CRT1, one for CRT2)
48 *  SiS330: Full register range, one overlay (used for both CRT1 and CRT2 alt.)
49 *  SiS661/741/760: Full register range, two overlays (one used for CRT1, one for CRT2)
50 *  SiS340: - ? overlay(s)? Extended registers for DDA?
51 *  SiS761: - ? overlay(s)? Extended registers for DDA.
52 *  XGI V5/V8/Z7 - 1 overlay, extended registers for DDA.
53 *
54 * Help for reading the code:
55 * 315/550/650/740/M650/651/330/661/741/76x/340/XGI = SIS_315_VGA
56 * 300/630/730                                      = SIS_300_VGA
57 * For chipsets with 2 overlays, hasTwoOverlays will be true
58 *
59 * Notes on display modes:
60 *
61 * -) dual head mode:
62 *    DISPMODE is either SINGLE1 or SINGLE2, hence you need to check dualHeadMode flag
63 *    DISPMODE is _never_ MIRROR.
64 *    a) Chipsets with 2 overlays:
65 *       315/330 series: Only half sized overlays available (width 960), 660: 1536
66 *       Overlay 1 is used on CRT1, overlay 2 for CRT2.
67 *    b) Chipsets with 1 overlay:
68 *       Full size overlays available.
69 *       Overlay is used for either CRT1 or CRT2
70 * -) merged fb mode:
71 *    a) Chipsets with 2 overlays:
72 *       315/330 series: Only half sized overlays available (width 960), 660: 1536
73 *       DISPMODE is always MIRROR. Overlay 1 is used for CRT1, overlay 2 for CRT2.
74 *    b) Chipsets with 1 overlay:
75 *       Full size overlays available.
76 *       DISPMODE is either SINGLE1 or SINGLE2. Overlay is used accordingly on either
77 *       CRT1 or CRT2 (automatically, where it is located)
78 * -) mirror mode (without dualhead or mergedfb)
79 *    a) Chipsets with 2 overlays:
80 *       315/330 series: Only half sized overlays available (width 960), 660: 1536
81 *       DISPMODE is MIRROR. Overlay 1 is used for CRT1, overlay 2 for CRT2.
82 *    b) Chipsets with 1 overlay:
83 *       Full size overlays available.
84 *       DISPMODE is either SINGLE1 or SINGLE2. Overlay is used depending on
85 * 	 XvOnCRT2 flag.
86 *
87 * About the video blitter:
88 * The video blitter adaptor supports 16 ports. By default, adaptor 0 will
89 * be the overlay adaptor, adaptor 1 the video blitter. The option XvDefaultAdaptor
90 * allows reversing this.
91 * Since SiS does not provide information on the 3D engine, I could not
92 * implement scaling. Instead, the driver paints a black border around the unscaled
93 * video if the destination area is bigger than the video.
94 *
95 */
96
97#ifndef _SIS_VIDEO_H_
98#define _SIS_VIDEO_H_
99
100#include "sis_videostr.h"
101
102static		XF86VideoAdaptorPtr SISSetupImageVideo(ScreenPtr);
103static void 	SISStopVideo(ScrnInfoPtr, pointer, Bool);
104static int 	SISSetPortAttribute(ScrnInfoPtr, Atom, INT32, pointer);
105static int 	SISGetPortAttribute(ScrnInfoPtr, Atom ,INT32 *, pointer);
106static void 	SISQueryBestSize(ScrnInfoPtr, Bool, short, short, short,
107			short, unsigned int *,unsigned int *, pointer);
108static int 	SISPutImage( ScrnInfoPtr,
109			short, short, short, short, short, short, short, short,
110			int, UChar *, short, short, Bool, RegionPtr, pointer,
111			DrawablePtr);
112static int 	SISQueryImageAttributes(ScrnInfoPtr,
113			int, UShort *, UShort *, int *, int *);
114static void 	SISVideoTimerCallback(ScrnInfoPtr pScrn, Time now);
115static void     SISInitOffscreenImages(ScreenPtr pScrn);
116static void	set_dda_regs(SISPtr pSiS, float scale);
117unsigned int	SISAllocateFBMemory(ScrnInfoPtr pScrn, void **handle, int bytesize);
118void		SISFreeFBMemory(ScrnInfoPtr pScrn, void **handle);
119void 		SISSetPortDefaults(ScrnInfoPtr pScrn, SISPortPrivPtr pPriv);
120void		SISUpdateVideoParms(SISPtr pSiS, SISPortPrivPtr pPriv);
121void		SiSUpdateXvGamma(SISPtr pSiS, SISPortPrivPtr pPriv);
122extern Bool     SiSBridgeIsInSlaveMode(ScrnInfoPtr pScrn);
123
124#ifdef INCL_YUV_BLIT_ADAPTOR
125static 		XF86VideoAdaptorPtr SISSetupBlitVideo(ScreenPtr);
126static void 	SISStopVideoBlit(ScrnInfoPtr, ULong, Bool);
127static int 	SISSetPortAttributeBlit(ScrnInfoPtr, Atom, INT32, ULong);
128static int 	SISGetPortAttributeBlit(ScrnInfoPtr, Atom ,INT32 *, ULong);
129static void 	SISQueryBestSizeBlit(ScrnInfoPtr, Bool, short, short, short,
130			short, unsigned int *,unsigned int *, ULong);
131static int 	SISPutImageBlit( ScrnInfoPtr,
132			short, short, short, short, short, short, short, short,
133			int, UChar *, short, short, Bool, RegionPtr, ULong,
134			DrawablePtr);
135static int 	SISQueryImageAttributesBlit(ScrnInfoPtr,
136			int, UShort *, UShort *, int *, int *);
137extern void     SISWriteBlitPacket(SISPtr pSiS, CARD32 *packet);
138#endif
139
140#ifdef XV_SD_DEPRECATED
141extern int	SISSetPortUtilAttribute(ScrnInfoPtr pScrn, Atom attribute,
142					INT32 value, SISPortPrivPtr pPriv);
143extern int	SISGetPortUtilAttribute(ScrnInfoPtr pScrn,  Atom attribute,
144					INT32 *value, SISPortPrivPtr pPriv);
145#endif
146
147#define OFF_DELAY   	200    /* milliseconds */
148#define FREE_DELAY  	30000
149#define OFF_TIMER   	0x01
150#define FREE_TIMER  	0x02
151#define CLIENT_VIDEO_ON 0x04
152
153#define TIMER_MASK      (OFF_TIMER | FREE_TIMER)
154
155#define WATCHDOG_DELAY  200000 /* Watchdog counter for Vertical Restrace waiting */
156
157#define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE)
158
159#define IMAGE_MIN_WIDTH         32  	/* Minimum and maximum source image sizes */
160#define IMAGE_MIN_HEIGHT        24
161#define IMAGE_MAX_WIDTH_300    768	/* was 720, wrong */
162#define IMAGE_MAX_HEIGHT_300   576
163#define IMAGE_MAX_WIDTH_315   1920
164#define IMAGE_MAX_WIDTH_340   1920	/* ? */
165#define IMAGE_MAX_WIDTH_761   1920	/* ? */
166#define IMAGE_MAX_HEIGHT_315  1080
167
168#define OVERLAY_MIN_WIDTH       32  	/* Minimum overlay sizes */
169#define OVERLAY_MIN_HEIGHT      24
170
171#define DISPMODE_SINGLE1 0x1		/* CRT1 only */
172#define DISPMODE_SINGLE2 0x2		/* CRT2 only */
173#define DISPMODE_MIRROR  0x4		/* CRT1 + CRT2 MIRROR (see note below) */
174
175#define SISPRIVLINID 0x53495337		/* Private ID for private linears */
176
177#define FBOFFSET (pSiS->dhmOffset)
178
179/* Note on "MIRROR":
180 * When using VESA on machines with an enabled video bridge, this means
181 * a real mirror. CRT1 and CRT2 have the exact same resolution and
182 * refresh rate. The same applies to modes which require the bridge to
183 * operate in slave mode.
184 * When not using VESA and the bridge is not in slave mode otherwise,
185 * CRT1 and CRT2 have the same resolution but possibly a different
186 * refresh rate.
187 */
188
189#define NUM_FORMATS 3
190
191static XF86VideoFormatRec SISFormats[NUM_FORMATS] =
192{
193   { 8, PseudoColor},
194   {16, TrueColor},
195   {24, TrueColor}
196};
197
198static char sisxvcolorkey[] 				= "XV_COLORKEY";
199static char sisxvbrightness[] 				= "XV_BRIGHTNESS";
200static char sisxvcontrast[] 				= "XV_CONTRAST";
201static char sisxvsaturation[] 				= "XV_SATURATION";
202static char sisxvhue[] 					= "XV_HUE";
203static char sisxvautopaintcolorkey[] 			= "XV_AUTOPAINT_COLORKEY";
204static char sisxvsetdefaults[] 				= "XV_SET_DEFAULTS";
205static char sisxvswitchcrt[] 				= "XV_SWITCHCRT";
206static char sisxvtvxposition[] 				= "XV_TVXPOSITION";
207static char sisxvtvyposition[] 				= "XV_TVYPOSITION";
208static char sisxvgammared[] 				= "XV_GAMMA_RED";
209static char sisxvgammagreen[] 				= "XV_GAMMA_GREEN";
210static char sisxvgammablue[] 				= "XV_GAMMA_BLUE";
211static char sisxvdisablegfx[] 				= "XV_DISABLE_GRAPHICS";
212static char sisxvdisablegfxlr[] 			= "XV_DISABLE_GRAPHICS_LR";
213static char sisxvdisablecolorkey[] 			= "XV_DISABLE_COLORKEY";
214static char sisxvusechromakey[] 			= "XV_USE_CHROMAKEY";
215static char sisxvinsidechromakey[] 			= "XV_INSIDE_CHROMAKEY";
216static char sisxvyuvchromakey[] 			= "XV_YUV_CHROMAKEY";
217static char sisxvchromamin[] 				= "XV_CHROMAMIN";
218static char sisxvchromamax[] 				= "XV_CHROMAMAX";
219#ifdef SISDEINT
220static char sisxvdeinterlace[]				= "XV_OVERLAY_DEINTERLACING_METHOD";
221#endif
222#ifdef XV_SD_DEPRECATED
223static char sisxvqueryvbflags[] 			= "XV_QUERYVBFLAGS";
224static char sisxvsdgetdriverversion[] 			= "XV_SD_GETDRIVERVERSION";
225static char sisxvsdgethardwareinfo[]			= "XV_SD_GETHARDWAREINFO";
226static char sisxvsdgetbusid[] 				= "XV_SD_GETBUSID";
227static char sisxvsdqueryvbflagsversion[] 		= "XV_SD_QUERYVBFLAGSVERSION";
228static char sisxvsdgetsdflags[] 			= "XV_SD_GETSDFLAGS";
229static char sisxvsdgetsdflags2[] 			= "XV_SD_GETSDFLAGS2";
230static char sisxvsdunlocksisdirect[] 			= "XV_SD_UNLOCKSISDIRECT";
231static char sisxvsdsetvbflags[] 			= "XV_SD_SETVBFLAGS";
232static char sisxvsdquerydetecteddevices[] 		= "XV_SD_QUERYDETECTEDDEVICES";
233static char sisxvsdcrt1status[] 			= "XV_SD_CRT1STATUS";
234static char sisxvsdcheckmodeindexforcrt2[] 		= "XV_SD_CHECKMODEINDEXFORCRT2";
235static char sisxvsdresultcheckmodeindexforcrt2[] 	= "XV_SD_RESULTCHECKMODEINDEXFORCRT2";
236static char sisxvsdredetectcrt2[]			= "XV_SD_REDETECTCRT2DEVICES";
237static char sisxvsdsisantiflicker[] 			= "XV_SD_SISANTIFLICKER";
238static char sisxvsdsissaturation[] 			= "XV_SD_SISSATURATION";
239static char sisxvsdsisedgeenhance[] 			= "XV_SD_SISEDGEENHANCE";
240static char sisxvsdsiscolcalibf[] 			= "XV_SD_SISCOLCALIBF";
241static char sisxvsdsiscolcalibc[] 			= "XV_SD_SISCOLCALIBC";
242static char sisxvsdsiscfilter[] 			= "XV_SD_SISCFILTER";
243static char sisxvsdsisyfilter[] 			= "XV_SD_SISYFILTER";
244static char sisxvsdchcontrast[] 			= "XV_SD_CHCONTRAST";
245static char sisxvsdchtextenhance[] 			= "XV_SD_CHTEXTENHANCE";
246static char sisxvsdchchromaflickerfilter[] 		= "XV_SD_CHCHROMAFLICKERFILTER";
247static char sisxvsdchlumaflickerfilter[] 		= "XV_SD_CHLUMAFLICKERFILTER";
248static char sisxvsdchcvbscolor[] 			= "XV_SD_CHCVBSCOLOR";
249static char sisxvsdchoverscan[]				= "XV_SD_CHOVERSCAN";
250static char sisxvsdenablegamma[]			= "XV_SD_ENABLEGAMMA";
251static char sisxvsdtvxscale[] 				= "XV_SD_TVXSCALE";
252static char sisxvsdtvyscale[] 				= "XV_SD_TVYSCALE";
253static char sisxvsdgetscreensize[] 			= "XV_SD_GETSCREENSIZE";
254static char sisxvsdstorebrir[] 				= "XV_SD_STOREDGAMMABRIR";
255static char sisxvsdstorebrig[] 				= "XV_SD_STOREDGAMMABRIG";
256static char sisxvsdstorebrib[] 				= "XV_SD_STOREDGAMMABRIB";
257static char sisxvsdstorepbrir[] 			= "XV_SD_STOREDGAMMAPBRIR";
258static char sisxvsdstorepbrig[] 			= "XV_SD_STOREDGAMMAPBRIG";
259static char sisxvsdstorepbrib[] 			= "XV_SD_STOREDGAMMAPBRIB";
260static char sisxvsdstorebrir2[]				= "XV_SD_STOREDGAMMABRIR2";
261static char sisxvsdstorebrig2[]				= "XV_SD_STOREDGAMMABRIG2";
262static char sisxvsdstorebrib2[]				= "XV_SD_STOREDGAMMABRIB2";
263static char sisxvsdstorepbrir2[] 			= "XV_SD_STOREDGAMMAPBRIR2";
264static char sisxvsdstorepbrig2[] 			= "XV_SD_STOREDGAMMAPBRIG2";
265static char sisxvsdstorepbrib2[] 			= "XV_SD_STOREDGAMMAPBRIB2";
266static char sisxvsdstoregarc2[]				= "XV_SD_GAMMACRT2R";
267static char sisxvsdstoregagc2[]				= "XV_SD_GAMMACRT2G";
268static char sisxvsdstoregabc2[]				= "XV_SD_GAMMACRT2B";
269static char sisxvsdstorebrirc2[]			= "XV_SD_STOREDGAMMABRIRC2";
270static char sisxvsdstorebrigc2[]			= "XV_SD_STOREDGAMMABRIGC2";
271static char sisxvsdstorebribc2[]			= "XV_SD_STOREDGAMMABRIBC2";
272static char sisxvsdstorepbrirc2[] 			= "XV_SD_STOREDGAMMAPBRIRC2";
273static char sisxvsdstorepbrigc2[] 			= "XV_SD_STOREDGAMMAPBRIGC2";
274static char sisxvsdstorepbribc2[] 			= "XV_SD_STOREDGAMMAPBRIBC2";
275static char sisxvsdhidehwcursor[] 			= "XV_SD_HIDEHWCURSOR";
276static char sisxvsdpanelmode[] 				= "XV_SD_PANELMODE";
277#ifdef TWDEBUG
278static char sisxvsetreg[]				= "XV_SD_SETREG";
279#endif
280#endif /* XV_SD_DEPRECATED */
281
282#ifdef INCL_YUV_BLIT_ADAPTOR
283static char sisxvvsync[]				= "XV_SYNC_TO_VBLANK";
284#endif
285
286/***********************************************/
287/*               OVERLAY ADAPTOR               */
288/***********************************************/
289
290/* client libraries expect an encoding */
291static XF86VideoEncodingRec DummyEncoding =
292{
293   0,
294   "XV_IMAGE",
295   0, 0,		/* Will be filled in */
296   {1, 1}
297};
298
299static XF86AttributeRec SISAttributes_300[] =
300{
301   {XvSettable | XvGettable, 0, (1 << 24) - 1, sisxvcolorkey},
302   {XvSettable | XvGettable, -128, 127,        sisxvbrightness},
303   {XvSettable | XvGettable, 0, 7,             sisxvcontrast},
304   {XvSettable | XvGettable, 0, 1,             sisxvautopaintcolorkey},
305   {XvSettable             , 0, 0,             sisxvsetdefaults},
306   {XvSettable | XvGettable, -32, 32,          sisxvtvxposition},
307   {XvSettable | XvGettable, -32, 32,          sisxvtvyposition},
308   {XvSettable | XvGettable, 0, 1,             sisxvdisablegfx},
309   {XvSettable | XvGettable, 0, 1,             sisxvdisablegfxlr},
310   {XvSettable | XvGettable, 0, 1,             sisxvdisablecolorkey},
311   {XvSettable | XvGettable, 0, 1,             sisxvusechromakey},
312   {XvSettable | XvGettable, 0, 1,             sisxvinsidechromakey},
313   {XvSettable | XvGettable, 0, 1,             sisxvyuvchromakey},
314   {XvSettable | XvGettable, 0, (1 << 24) - 1, sisxvchromamin},
315   {XvSettable | XvGettable, 0, (1 << 24) - 1, sisxvchromamax},
316#ifdef SISDEINT
317   {XvSettable | XvGettable, 0, 4,             sisxvdeinterlace},
318#endif
319#ifdef XV_SD_DEPRECATED
320   {             XvGettable, 0, -1,    	       sisxvqueryvbflags},
321   {             XvGettable, 0, -1,	       sisxvsdgetdriverversion},
322   {             XvGettable, 0, -1,    	       sisxvsdgethardwareinfo},
323   {             XvGettable, 0, -1,    	       sisxvsdgetbusid},
324   {             XvGettable, 0, -1,    	       sisxvsdqueryvbflagsversion},
325   {             XvGettable, 0, -1,    	       sisxvsdgetsdflags},
326   {             XvGettable, 0, -1,    	       sisxvsdgetsdflags2},
327   {XvSettable | XvGettable, 0, -1,    	       sisxvsdunlocksisdirect},
328   {XvSettable             , 0, -1,    	       sisxvsdsetvbflags},
329   {             XvGettable, 0, -1,    	       sisxvsdquerydetecteddevices},
330   {XvSettable | XvGettable, 0, 1,    	       sisxvsdcrt1status},
331   {XvSettable             , 0, -1,    	       sisxvsdcheckmodeindexforcrt2},
332   {             XvGettable, 0, -1,    	       sisxvsdresultcheckmodeindexforcrt2},
333   {XvSettable             , 0, 0,             sisxvsdredetectcrt2},
334   {XvSettable | XvGettable, 0, 4,             sisxvsdsisantiflicker},
335   {XvSettable | XvGettable, 0, 15,            sisxvsdsissaturation},
336   {XvSettable | XvGettable, 0, 15,            sisxvsdsisedgeenhance},
337   {XvSettable | XvGettable, -128, 127,        sisxvsdsiscolcalibf},
338   {XvSettable | XvGettable, -120, 120,        sisxvsdsiscolcalibc},
339   {XvSettable | XvGettable, 0, 1,             sisxvsdsiscfilter},
340   {XvSettable | XvGettable, 0, 8,             sisxvsdsisyfilter},
341   {XvSettable | XvGettable, 0, 15,            sisxvsdchcontrast},
342   {XvSettable | XvGettable, 0, 15,            sisxvsdchtextenhance},
343   {XvSettable | XvGettable, 0, 15,            sisxvsdchchromaflickerfilter},
344   {XvSettable | XvGettable, 0, 15,            sisxvsdchlumaflickerfilter},
345   {XvSettable | XvGettable, 0, 1,             sisxvsdchcvbscolor},
346   {XvSettable | XvGettable, 0, 3,             sisxvsdchoverscan},
347   {XvSettable | XvGettable, 0, 3,             sisxvsdenablegamma},
348   {XvSettable | XvGettable, -16, 16,          sisxvsdtvxscale},
349   {XvSettable | XvGettable, -4, 3,            sisxvsdtvyscale},
350   {             XvGettable, 0, -1,    	       sisxvsdgetscreensize},
351   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorebrir},
352   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorebrig},
353   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorebrib},
354   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorepbrir},
355   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorepbrig},
356   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorepbrib},
357   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorebrir2},
358   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorebrig2},
359   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorebrib2},
360   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorepbrir2},
361   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorepbrig2},
362   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorepbrib2},
363   {XvSettable | XvGettable, 100, 10000,       sisxvsdstoregarc2},
364   {XvSettable | XvGettable, 100, 10000,       sisxvsdstoregagc2},
365   {XvSettable | XvGettable, 100, 10000,       sisxvsdstoregabc2},
366   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorebrirc2},
367   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorebrigc2},
368   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorebribc2},
369   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorepbrirc2},
370   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorepbrigc2},
371   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorepbribc2},
372   {XvSettable | XvGettable, 0, 15,            sisxvsdpanelmode},
373#endif
374#ifdef SIS_CP
375   SIS_CP_VIDEO_ATTRIBUTES
376#endif
377   {0                      , 0, 0,             NULL}
378};
379
380static XF86AttributeRec SISAttributes_315[] =
381{
382   {XvSettable | XvGettable, 0, (1 << 24) - 1, sisxvcolorkey},
383   {XvSettable | XvGettable, -128, 127,        sisxvbrightness},
384   {XvSettable | XvGettable, 0, 7,             sisxvcontrast},
385   {XvSettable | XvGettable, -7, 7,            sisxvsaturation},
386   {XvSettable | XvGettable, -8, 7,            sisxvhue},
387   {XvSettable | XvGettable, 0, 1,             sisxvautopaintcolorkey},
388   {XvSettable             , 0, 0,             sisxvsetdefaults},
389   {XvSettable | XvGettable, -32, 32,          sisxvtvxposition},
390   {XvSettable | XvGettable, -32, 32,          sisxvtvyposition},
391   {XvSettable | XvGettable, 100, 10000,       sisxvgammared},
392   {XvSettable | XvGettable, 100, 10000,       sisxvgammagreen},
393   {XvSettable | XvGettable, 100, 10000,       sisxvgammablue},
394   {XvSettable | XvGettable, 0, 1,             sisxvdisablegfx},
395   {XvSettable | XvGettable, 0, 1,             sisxvdisablegfxlr},
396   {XvSettable | XvGettable, 0, 1,             sisxvdisablecolorkey},
397   {XvSettable | XvGettable, 0, 1,             sisxvusechromakey},
398   {XvSettable | XvGettable, 0, 1,             sisxvinsidechromakey},
399   {XvSettable | XvGettable, 0, (1 << 24) - 1, sisxvchromamin},
400   {XvSettable | XvGettable, 0, (1 << 24) - 1, sisxvchromamax},
401#ifdef SISDEINT
402   {XvSettable | XvGettable, 0, 4,             sisxvdeinterlace},
403#endif
404#ifdef XV_SD_DEPRECATED
405   {             XvGettable, 0, -1,    	       sisxvqueryvbflags},
406   {             XvGettable, 0, -1,    	       sisxvsdgetdriverversion},
407   {             XvGettable, 0, -1,    	       sisxvsdgethardwareinfo},
408   {             XvGettable, 0, -1,    	       sisxvsdgetbusid},
409   {             XvGettable, 0, -1,    	       sisxvsdqueryvbflagsversion},
410   {             XvGettable, 0, -1,   	       sisxvsdgetsdflags},
411   {             XvGettable, 0, -1,   	       sisxvsdgetsdflags2},
412   {XvSettable | XvGettable, 0, -1,   	       sisxvsdunlocksisdirect},
413   {XvSettable             , 0, -1,   	       sisxvsdsetvbflags},
414   {             XvGettable, 0, -1,    	       sisxvsdquerydetecteddevices},
415   {XvSettable | XvGettable, 0, 1,    	       sisxvsdcrt1status},
416   {XvSettable             , 0, -1,    	       sisxvsdcheckmodeindexforcrt2},
417   {             XvGettable, 0, -1,   	       sisxvsdresultcheckmodeindexforcrt2},
418   {XvSettable             , 0, 0,             sisxvsdredetectcrt2},
419   {XvSettable | XvGettable, 0, 4,             sisxvsdsisantiflicker},
420   {XvSettable | XvGettable, 0, 15,            sisxvsdsissaturation},
421   {XvSettable | XvGettable, 0, 15,            sisxvsdsisedgeenhance},
422   {XvSettable | XvGettable, -128, 127,        sisxvsdsiscolcalibf},
423   {XvSettable | XvGettable, -120, 120,        sisxvsdsiscolcalibc},
424   {XvSettable | XvGettable, 0, 1,             sisxvsdsiscfilter},
425   {XvSettable | XvGettable, 0, 8,             sisxvsdsisyfilter},
426   {XvSettable | XvGettable, 0, 15,            sisxvsdchcontrast},
427   {XvSettable | XvGettable, 0, 15,            sisxvsdchtextenhance},
428   {XvSettable | XvGettable, 0, 15,            sisxvsdchchromaflickerfilter},
429   {XvSettable | XvGettable, 0, 15,            sisxvsdchlumaflickerfilter},
430   {XvSettable | XvGettable, 0, 1,             sisxvsdchcvbscolor},
431   {XvSettable | XvGettable, 0, 3,             sisxvsdchoverscan},
432   {XvSettable | XvGettable, 0, 7,             sisxvsdenablegamma},
433   {XvSettable | XvGettable, -16, 16,          sisxvsdtvxscale},
434   {XvSettable | XvGettable, -4, 3,            sisxvsdtvyscale},
435   {             XvGettable, 0, -1,   	       sisxvsdgetscreensize},
436   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorebrir},
437   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorebrig},
438   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorebrib},
439   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorepbrir},
440   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorepbrig},
441   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorepbrib},
442   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorebrir2},
443   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorebrig2},
444   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorebrib2},
445   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorepbrir2},
446   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorepbrig2},
447   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorepbrib2},
448   {XvSettable | XvGettable, 100, 10000,       sisxvsdstoregarc2},
449   {XvSettable | XvGettable, 100, 10000,       sisxvsdstoregagc2},
450   {XvSettable | XvGettable, 100, 10000,       sisxvsdstoregabc2},
451   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorebrirc2},
452   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorebrigc2},
453   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorebribc2},
454   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorepbrirc2},
455   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorepbrigc2},
456   {XvSettable | XvGettable, 100, 10000,       sisxvsdstorepbribc2},
457   {XvSettable | XvGettable, 0, 1,             sisxvsdhidehwcursor},
458   {XvSettable | XvGettable, 0, 15,            sisxvsdpanelmode},
459#ifdef TWDEBUG
460   {XvSettable             , 0, -1,   	       sisxvsetreg},
461#endif
462#endif  /* XV_SD_DEPRECATED */
463#ifdef SIS_CP
464   SIS_CP_VIDEO_ATTRIBUTES
465#endif
466   {XvSettable | XvGettable, 0, 1,             sisxvswitchcrt},
467   {0                      , 0, 0,             NULL}
468};
469
470#define NUM_IMAGES_300 6
471#define NUM_IMAGES_315 7	    /* basically NV12 only - but does not work */
472#define NUM_IMAGES_330 9  	    /* NV12 and NV21 */
473
474#define PIXEL_FMT_YV12 FOURCC_YV12  /* 0x32315659 */
475#define PIXEL_FMT_UYVY FOURCC_UYVY  /* 0x59565955 */
476#define PIXEL_FMT_YUY2 FOURCC_YUY2  /* 0x32595559 */
477#define PIXEL_FMT_I420 FOURCC_I420  /* 0x30323449 */
478#define PIXEL_FMT_RGB5 0x35315652
479#define PIXEL_FMT_RGB6 0x36315652
480#define PIXEL_FMT_YVYU 0x55595659   /* 315/330+ only */
481#define PIXEL_FMT_NV12 0x3231564e   /* 330+ only */
482#define PIXEL_FMT_NV21 0x3132564e   /* 330+ only */
483
484/* TODO: */
485#define PIXEL_FMT_RAW8 0x38574152
486
487static XF86ImageRec SISImages[NUM_IMAGES_330] =
488{
489    XVIMAGE_YUY2, /* If order is changed, SISOffscreenImages must be adapted */
490    XVIMAGE_YV12,
491    XVIMAGE_UYVY,
492    XVIMAGE_I420
493    ,
494    { /* RGB 555 */
495      PIXEL_FMT_RGB5,
496      XvRGB,
497      LSBFirst,
498      {'R','V','1','5',
499       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
500      16,
501      XvPacked,
502      1,
503      15, 0x7C00, 0x03E0, 0x001F,
504      0, 0, 0,
505      0, 0, 0,
506      0, 0, 0,
507      {'R', 'V', 'B',0,
508       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
509      XvTopToBottom
510    },
511    { /* RGB 565 */
512      PIXEL_FMT_RGB6,
513      XvRGB,
514      LSBFirst,
515      {'R','V','1','6',
516       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
517      16,
518      XvPacked,
519      1,
520      16, 0xF800, 0x07E0, 0x001F,
521      0, 0, 0,
522      0, 0, 0,
523      0, 0, 0,
524      {'R', 'V', 'B',0,
525       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
526      XvTopToBottom
527    },
528    {  /* YVYU */
529      PIXEL_FMT_YVYU, \
530      XvYUV, \
531      LSBFirst, \
532      {'Y','V','Y','U',
533	0x00,0x00,0x00,0x10,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71},
534      16,
535      XvPacked,
536      1,
537      0, 0, 0, 0,
538      8, 8, 8,
539      1, 2, 2,
540      1, 1, 1,
541      {'Y','V','Y','U',
542       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
543      XvTopToBottom
544   },
545   {   /* NV12 */
546      PIXEL_FMT_NV12,
547      XvYUV,
548      LSBFirst,
549      {'N','V','1','2',
550       0x00,0x00,0x00,0x10,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71},
551      12,
552      XvPlanar,
553      2,
554      0, 0, 0, 0,
555      8, 8, 8,
556      1, 2, 2,
557      1, 2, 2,
558      {'Y','U','V',0,
559       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
560      XvTopToBottom
561   },
562   {   /* NV21 */
563      PIXEL_FMT_NV21,
564      XvYUV,
565      LSBFirst,
566      {'N','V','2','1',
567       0x00,0x00,0x00,0x10,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71},
568      12,
569      XvPlanar,
570      2,
571      0, 0, 0, 0,
572      8, 8, 8,
573      1, 2, 2,
574      1, 2, 2,
575      {'Y','V','U',0,
576       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
577      XvTopToBottom
578   },
579};
580
581typedef struct {
582    int pixelFormat;
583
584    CARD16  pitch;
585    CARD16  origPitch;
586
587    CARD8   keyOP;
588    CARD16  HUSF;
589    CARD16  VUSF;
590    CARD8   IntBit;
591    CARD8   wHPre;
592
593    float   tap_scale, tap_scale_old;
594
595    CARD16  srcW;
596    CARD16  srcH;
597
598    BoxRec  dstBox;
599
600    CARD32  PSY;
601    CARD32  PSV;
602    CARD32  PSU;
603
604    CARD16  SCREENheight;
605
606    CARD16  lineBufSize;
607
608    DisplayModePtr  currentmode;
609
610#ifdef SISMERGED
611    CARD16  pitch2;
612    CARD16  HUSF2;
613    CARD16  VUSF2;
614    CARD8   IntBit2;
615    CARD8   wHPre2;
616
617    float   tap_scale2, tap_scale2_old;
618
619    CARD16  srcW2;
620    CARD16  srcH2;
621    BoxRec  dstBox2;
622    CARD32  PSY2;
623    CARD32  PSV2;
624    CARD32  PSU2;
625    CARD16  SCREENheight2;
626    CARD16  lineBufSize2;
627
628    DisplayModePtr  currentmode2;
629
630    Bool    DoFirst, DoSecond;
631#endif
632
633    CARD8   bobEnable;
634
635    CARD8   planar;
636    CARD8   planar_shiftpitch;
637
638    CARD8   contrastCtrl;
639    CARD8   contrastFactor;
640
641    CARD16  oldLine, oldtop;
642
643    CARD8   (*VBlankActiveFunc)(SISPtr, SISPortPrivPtr);
644#if 0
645    CARD32  (*GetScanLineFunc)(SISPtr pSiS);
646#endif
647
648} SISOverlayRec, *SISOverlayPtr;
649
650/***********************************************/
651/*               BLITTER ADAPTOR               */
652/***********************************************/
653
654#ifdef INCL_YUV_BLIT_ADAPTOR
655
656#define NUM_BLIT_PORTS 16
657
658static XF86VideoEncodingRec DummyEncodingBlit =
659{
660   0,
661   "XV_IMAGE",
662   2046, 2046,
663   {1, 1}
664};
665
666#define NUM_ATTRIBUTES_BLIT 1
667
668static XF86AttributeRec SISAttributes_Blit[NUM_ATTRIBUTES_BLIT] =
669{
670#if 0
671   {XvSettable | XvGettable, 0, 1,             sisxvvsync},
672#endif
673   {XvSettable             , 0, 0,             sisxvsetdefaults}
674};
675
676#define NUM_IMAGES_BLIT 7
677
678static XF86ImageRec SISImagesBlit[NUM_IMAGES_BLIT] =
679{
680
681   XVIMAGE_YUY2,
682   XVIMAGE_YV12,
683   XVIMAGE_UYVY,
684   XVIMAGE_I420,
685   {  /* YVYU */
686      PIXEL_FMT_YVYU, \
687      XvYUV, \
688      LSBFirst, \
689      {'Y','V','Y','U',
690	0x00,0x00,0x00,0x10,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71},
691      16,
692      XvPacked,
693      1,
694      0, 0, 0, 0,
695      8, 8, 8,
696      1, 2, 2,
697      1, 1, 1,
698      {'Y','V','Y','U',
699       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
700      XvTopToBottom
701   },
702   {   /* NV12 */
703      PIXEL_FMT_NV12,
704      XvYUV,
705      LSBFirst,
706      {'N','V','1','2',
707       0x00,0x00,0x00,0x10,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71},
708      12,
709      XvPlanar,
710      2,
711      0, 0, 0, 0,
712      8, 8, 8,
713      1, 2, 2,
714      1, 2, 2,
715      {'Y','U','V',0,
716       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
717      XvTopToBottom
718   },
719   {   /* NV21 */
720      PIXEL_FMT_NV21,
721      XvYUV,
722      LSBFirst,
723      {'N','V','2','1',
724       0x00,0x00,0x00,0x10,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71},
725      12,
726      XvPlanar,
727      2,
728      0, 0, 0, 0,
729      8, 8, 8,
730      1, 2, 2,
731      1, 2, 2,
732      {'Y','V','U',0,
733       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
734      XvTopToBottom
735   }
736};
737
738typedef struct {
739    void *	 handle[NUM_BLIT_PORTS];
740    CARD32       bufAddr[NUM_BLIT_PORTS][2];
741
742    UChar        currentBuf[NUM_BLIT_PORTS];
743
744    RegionRec    blitClip[NUM_BLIT_PORTS];
745
746    CARD32       videoStatus[NUM_BLIT_PORTS];
747    Time         freeTime[NUM_BLIT_PORTS];
748
749    Bool	 vsync;
750    CARD32	 AccelCmd;
751    CARD32       VBlankTriggerCRT1, VBlankTriggerCRT2;
752} SISBPortPrivRec, *SISBPortPrivPtr;
753
754#endif /* INCL_BLIT */
755
756#endif
757
758
759