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