smi.h revision 479f40c1
1/* Header:   //Mercury/Projects/archives/XFree86/4.0/smi.h-arc   1.51   29 Nov 2000 17:45:16   Frido  $ */
2
3/*
4Copyright (C) 1994-1999 The XFree86 Project, Inc.  All Rights Reserved.
5Copyright (C) 2000 Silicon Motion, Inc.  All Rights Reserved.
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of
8this software and associated documentation files (the "Software"), to deal in
9the Software without restriction, including without limitation the rights to
10use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
11of the Software, and to permit persons to whom the Software is furnished to do
12so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
19NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
20XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24Except as contained in this notice, the names of the XFree86 Project and
25Silicon Motion shall not be used in advertising or otherwise to promote the
26sale, use or other dealings in this Software without prior written
27authorization from the XFree86 Project and Silicon Motion.
28*/
29
30#ifndef _SMI_H
31#define _SMI_H
32
33#include "smi_pcirename.h"
34
35#include <string.h>
36#include <stdio.h>
37
38#include "xorg-server.h"
39#include "xf86.h"
40#include "xf86_OSproc.h"
41#include "xf86Pci.h"
42#include "xf86Cursor.h"
43#include "vgaHW.h"
44
45#include "compiler.h"
46
47#include "mipointer.h"
48#include "micmap.h"
49
50#include "fb.h"
51
52#ifdef HAVE_XAA_H
53#include "xaa.h"
54#endif
55#include "xf86fbman.h"
56#include "exa.h"
57#include "xf86cmap.h"
58#include "xf86i2c.h"
59
60#include "xf86int10.h"
61#include "vbe.h"
62
63#include "xf86xv.h"
64#include <X11/extensions/Xv.h>
65
66#include "compat-api.h"
67/******************************************************************************/
68/*			D E F I N I T I O N S				      */
69/******************************************************************************/
70
71#ifdef __NetBSD__
72#define __BYTE_ORDER BYTE_ORDER
73#define __LITTLE_ENDIAN LITTLE_ENDIAN
74#define __BIG_ENDIAN BIG_ENDIAN
75#endif
76
77#define PCI_VENDOR_SMI		0x126F
78#define PCI_CHIP_SMI910		0x0910
79#define PCI_CHIP_SMI810		0x0810
80#define PCI_CHIP_SMI820		0x0820
81#define PCI_CHIP_SMI710		0x0710
82#define PCI_CHIP_SMI712		0x0712
83#define PCI_CHIP_SMI720		0x0720
84#define PCI_CHIP_SMI731		0x0730
85
86#ifndef SMI_DEBUG
87#define SMI_DEBUG		0
88#endif
89
90#define SMI_USE_IMAGE_WRITES	0
91#define SMI_USE_VIDEO		1
92#define SMI_USE_CAPTURE		0
93#define SMI501_CLI_DEBUG	0
94
95/*
96 *   Leaving attempt implementation of an argb cursor using alpha plane
97 * for the smi 501/502 under this ifdef for now. Maybe it will be fixed
98 * in a subsequent hardware revision.
99 *   The problem is that the alpha plane will only work (that is, become
100 * visible) if alpha_plane_tl is set to top:=0 and left:=0.
101 *   Also, if alpha_plane_br does not match panel dimensions, the alpha
102 * plane will be displayed tilled in the "first" row, with corruption on
103 * on all odd columns.
104 *   Since setting the alpha fb_address works, to implement an argb cursor
105 * using the alpha plane, with the current hardware bugs, it would be
106 * required to:
107 *	o allocate an offscreen area of pSmi->lcdWidth * pSmi->lcdHeight * 2
108 *	o set statically tl/tr to 0,0,pSmi->lcdWidth-1,pSmi->lcdHeight-1
109 *	o use alpha format 3 (argb 4:4:4:4), or alternatively format 1
110 *	  (rgb 5:6:5), and in the last case, a global 50% alpha is the
111 *	  best bet, and for the argb cursors being used at the time of this
112 *	  writing, they look correct, while 100% opaque looks wrong.
113 *	o when positioning the pointer, first erase it from the offscreen
114 *	  area, then repaint it at the proper offset in the alpha offscreen
115 *	  area.
116 *  .... argb software cursor works way better
117 *   (There are some other alternatives, like using 8 bits indexed mode,
118 * but when using a global alpha value, instead of per pixel, most argb
119 * cursors will not look correctly, regardless of the alpha value, that
120 * should be from 50 to 100% transparency).
121 *   But still there would be the problem of memory requiring a 128 bit
122 * alignment, what would require either moving the image in the memory,
123 * and/or some trick with the vsync pixel panning.
124 *
125 *   Until the alpha layer is corrected in some newer revision (or removed?),
126 * it could be used as something like an alternate crt, that happens to be
127 * on top of the panel (and has 16 transparency levels).
128 */
129#define SMI_CURSOR_ALPHA_PLANE	0
130
131/******************************************************************************/
132/*			S T R U C T U R E S				      */
133/******************************************************************************/
134
135/* Driver data structure; this should contain all needed info for a mode */
136typedef struct
137{
138    CARD16 mode;
139
140    CARD8 SR17, SR18;
141    CARD8 SR20, SR21, SR22, SR23, SR24;
142    CARD8 SR30, SR31, SR32, SR34;
143    CARD8 SR40, SR41, SR42, SR43, SR44, SR45, SR48, SR49, SR4A, SR4B, SR4C;
144    CARD8 SR50, SR51, SR52, SR53, SR54, SR55, SR56, SR57, SR5A;
145    CARD8 SR66, SR68, SR69, SR6A, SR6B, SR6C, SR6D, SR6E, SR6F;
146    CARD8 SR81, SRA0;
147
148    CARD8 CR30, CR33, CR33_2, CR3A;
149    CARD8 CR40[14], CR40_2[14];
150    CARD8 CR90[15], CR9F, CR9F_2;
151    CARD8 CRA0[14];
152
153    CARD8	smiDACMask, smiDacRegs[256][3];
154    CARD8	smiFont[8192];
155
156    CARD32	DPR10, DPR1C, DPR20, DPR24, DPR28, DPR2C, DPR30, DPR3C, DPR40,
157		DPR44;
158    CARD32	VPR00, VPR0C, VPR10;
159    CARD32	CPR00;
160    CARD32	FPR00_, FPR0C_, FPR10_;
161} SMIRegRec, *SMIRegPtr;
162
163/* Global PDEV structure. */
164typedef struct
165{
166    int			Bpp;		/* Bytes per pixel */
167    int			MCLK;		/* Memory Clock  */
168    int			MXCLK;		/* MSOC Clock for local sdram */
169    ClockRange		clockRange;	/* Allowed pixel clock range */
170    CloseScreenProcPtr	CloseScreen;	/* Pointer used to save wrapped
171					   CloseScreen function */
172
173    I2CBusPtr		I2C;		/* Pointer into I2C module */
174    xf86Int10InfoPtr	pInt10;		/* Pointer to INT10 module */
175    vbeInfoPtr          pVbe;           /* Pointer to VBE module */
176
177    pciVideoPtr		PciInfo;	/* PCI info vars */
178#ifndef XSERVER_LIBPCIACCESS
179    PCITAG		PciTag;
180#endif
181    int			Chipset;	/* Chip info, set using PCI
182					   above */
183    int			ChipRev;
184
185    OptionInfoPtr	Options;
186    Bool		Dualhead;
187
188    /* Don't attempt to program a video mode. Use kernel framebuffer
189     * mode instead. */
190    Bool		UseFBDev;
191
192    /* CSC video uses color space conversion to render video directly to
193     * the framebuffer, without using an overlay. */
194    Bool		CSCVideo;
195
196    Bool		PCIBurst;	/* Enable PCI burst mode for
197					   reads? */
198    Bool		PCIRetry;	/* Enable PCI retries */
199    Bool		HwCursor;	/* hardware cursor enabled */
200
201    CARD8		DACmask;
202    int			vgaCRIndex, vgaCRReg;
203    Bool		PrimaryVidMapped;	/* Flag indicating if
204						   vgaHWMapMem was used
205						   successfully for
206						   this screen */
207    Bool		ModeStructInit;	/* Flag indicating ModeReg has
208					   been duped from console
209					   state */
210
211    /* Hardware state */
212    void		(*Save)(ScrnInfoPtr pScrn); /* Function used to save the
213						       current register state */
214    CARD8		SR18Value;	/* PDR#521: original SR18
215					   value */
216    CARD8		SR21Value;	/* PDR#521: original SR21
217					   value */
218    void		*save;		/* console saved mode
219					   registers */
220    void		*mode;		/* XServer video state mode
221					   registers */
222
223    /* Memory layout */
224    int			videoRAMBytes;	/* In units as noted, set in
225					   PreInit  */
226    int			videoRAMKBytes;	/* In units as noted, set in
227					   PreInit */
228    unsigned char *	MapBase;	/* Base of mapped memory */
229    int			MapSize;	/* Size of mapped memory */
230    CARD8 *		DPRBase;	/* Base of DPR registers */
231    CARD8 *		VPRBase;	/* Base of VPR registers */
232    CARD8 *		CPRBase;	/* Base of CPR registers */
233    CARD8 *		FPRBase;    /* Base of FPR registers - for 0730 chipset */
234    CARD8 *		DCRBase;		/* Base of DCR registers - for 0501 chipset */
235    CARD8 *		SCRBase;        /* Base of SCR registers - for 0501 chipset */
236    CARD8 *		DataPortBase;	/* Base of data port */
237    int			DataPortSize;	/* Size of data port */
238    CARD8 *		IOBase;		/* Base of MMIO VGA ports */
239    unsigned int	PIOBase;	/* Base of I/O ports */
240    unsigned char *	FBBase;		/* Base of FB */
241    CARD32		fbMapOffset;    /* offset for fb mapping */
242    CARD32		FBOffset;	/* Current visual FB starting
243					   location */
244    CARD32		FBCursorOffset;	/* Cursor storage location */
245    CARD32		FBReserved;	/* Reserved memory in frame
246					   buffer */
247
248    /* accel additions */
249    CARD32		AccelCmd;	/* Value for DPR0C */
250    Bool		NoAccel;	/* Disable Acceleration */
251    CARD32		ScissorsLeft;	/* Left/top of current
252					   scissors */
253    CARD32		ScissorsRight;	/* Right/bottom of current
254					   scissors */
255    Bool		ClipTurnedOn;	/* Clipping was turned on by
256					   the previous command */
257    int			GEResetCnt;	/* Limit the number of errors
258					   printed using a counter */
259
260    Bool		useBIOS;	/* Use BIOS for mode sets */
261#ifdef HAVE_XAA_H
262    XAAInfoRecPtr	XAAInfoRec;	/* XAA info Rec */
263#endif
264
265    /* EXA */
266    ExaDriverPtr	EXADriverPtr;
267    Bool		useEXA;		/* enable exa acceleration */
268    ExaOffscreenArea*	fbArea;		/* EXA offscreen area used
269					   as framebuffer */
270    PictTransformPtr	renderTransform;
271
272    /* DPMS */
273    int			CurrentDPMS;	/* Current DPMS state */
274
275    /* Panel information */
276    Bool		lcd;		/* LCD active, 1=DSTN, 2=TFT */
277    int			lcdWidth;	/* LCD width */
278    int			lcdHeight;	/* LCD height */
279
280    /* XvExtension */
281    int			videoKey;	/* Video chroma key */
282    Bool		ByteSwap;	/* Byte swap for ZV port */
283    Bool		interlaced;	/* True: Interlaced Video */
284    XF86VideoAdaptorPtr	ptrAdaptor;	/* Pointer to VideoAdapter
285					   structure */
286    void (*BlockHandler)(BLOCKHANDLER_ARGS_DECL);
287#if SMI501_CLI_DEBUG
288    /* SMI 501/502 Command List Interpreter */
289    Bool		 batch_active;
290    int64_t		*batch_handle;	/* Virtual address */
291    int			 batch_offset;	/* Physical smi 501 address */
292    int			 batch_length;	/* Length in 8 byte units */
293    int			 batch_finish;	/* Last finish command offset */
294    int			 batch_index;
295#endif
296} SMIRec, *SMIPtr;
297
298#define SMIPTR(p) ((SMIPtr)((p)->driverPrivate))
299
300/******************************************************************************/
301/*			M A C R O S					      */
302/******************************************************************************/
303
304#if SMI_DEBUG
305extern int smi_indent;
306# define VERBLEV	1
307# define ENTER()	xf86ErrorFVerb(VERBLEV, "%*c %s\n",\
308				       smi_indent++, '>', __FUNCTION__)
309# define LEAVE(...)							\
310    do {								\
311	xf86ErrorFVerb(VERBLEV, "%*c %s\n",				\
312		       --smi_indent, '<', __FUNCTION__);		\
313	return __VA_ARGS__;						\
314    } while (0)
315# define DEBUG(...)	xf86ErrorFVerb(VERBLEV, __VA_ARGS__)
316#else
317# define VERBLEV	4
318# define ENTER()	/**/
319# define LEAVE(...)	return __VA_ARGS__
320# define DEBUG(...)	/**/
321#endif
322
323/* Some Silicon Motion structs & registers */
324#include "regsmi.h"
325
326#if !defined (MetroLink) && !defined (VertDebug)
327#define VerticalRetraceWait()						\
328do									\
329{									\
330    if (VGAIN8_INDEX(pSmi, vgaCRIndex, vgaCRData, 0x17) & 0x80)		\
331    {									\
332	while ((VGAIN8(pSmi, vgaIOBase + 0x0A) & 0x08) == 0x00);	\
333	while ((VGAIN8(pSmi, vgaIOBase + 0x0A) & 0x08) == 0x08);	\
334	while ((VGAIN8(pSmi, vgaIOBase + 0x0A) & 0x08) == 0x00);	\
335    }									\
336} while (0)
337#else
338#define SPIN_LIMIT 1000000
339#define VerticalRetraceWait()						\
340do									\
341{									\
342    if (VGAIN8_INDEX(pSmi, vgaCRIndex, vgaCRData, 0x17) & 0x80)		\
343    {									\
344	volatile unsigned long _spin_me;				\
345	for (_spin_me = SPIN_LIMIT;					\
346	     ((VGAIN8(pSmi, vgaIOBase + 0x0A) & 0x08) == 0x00) && 	\
347	     _spin_me;							\
348	     _spin_me--);						\
349	if (!_spin_me)							\
350	    ErrorF("smi: warning: VerticalRetraceWait timed out.\n");	\
351	for (_spin_me = SPIN_LIMIT;					\
352	     ((VGAIN8(pSmi, vgaIOBase + 0x0A) & 0x08) == 0x08) && 	\
353	     _spin_me;							\
354	     _spin_me--);						\
355	if (!_spin_me)							\
356	    ErrorF("smi: warning: VerticalRetraceWait timed out.\n");	\
357	for (_spin_me = SPIN_LIMIT;					\
358	     ((VGAIN8(pSmi, vgaIOBase + 0x0A) & 0x08) == 0x00) && 	\
359	     _spin_me;							\
360	     _spin_me--);						\
361	if (!_spin_me)							\
362	    ErrorF("smi: warning: VerticalRetraceWait timed out.\n");	\
363	}								\
364} while (0)
365#endif
366
367/******************************************************************************/
368/*			F U N C T I O N   P R O T O T Y P E S		      */
369/******************************************************************************/
370
371/* smi_dac.c */
372void SMI_CommonCalcClock(int scrnIndex, long freq, int min_m, int min_n1,
373			 int max_n1, int min_n2, int max_n2, long freq_min,
374			 long freq_max, unsigned char * mdiv,
375			 unsigned char * ndiv);
376
377/* smi_i2c */
378Bool SMI_I2CInit(ScrnInfoPtr pScrn);
379
380/* smi_accel.c */
381void SMI_AccelSync(ScrnInfoPtr pScrn);
382void SMI_GEReset(ScrnInfoPtr pScrn, int from_timeout, int line, const char *file);
383void SMI_EngineReset(ScrnInfoPtr);
384void SMI_SetClippingRectangle(ScrnInfoPtr, int, int, int, int);
385void SMI_DisableClipping(ScrnInfoPtr);
386CARD32 SMI_DEDataFormat(int bpp);
387
388/* smi_xaa.c */
389Bool SMI_XAAInit(ScreenPtr pScrn);
390
391/* smi_exa.c */
392Bool SMI_EXAInit(ScreenPtr pScrn);
393
394/* smi_hwcurs.c */
395Bool SMI_HWCursorInit(ScreenPtr pScrn);
396
397/* smi_driver.c */
398Bool SMI_MapMem(ScrnInfoPtr pScrn);
399void SMI_UnmapMem(ScrnInfoPtr pScrn);
400void SMI_AdjustFrame(ADJUST_FRAME_ARGS_DECL);
401Bool SMI_SwitchMode(SWITCH_MODE_ARGS_DECL);
402void SMI_LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indicies,
403		     LOCO *colors, VisualPtr pVisual);
404xf86MonPtr SMI_ddc1(ScrnInfoPtr pScrn);
405void SMI_PrintRegs(ScrnInfoPtr pScrn);
406
407/* smi_video.c */
408void SMI_InitVideo(ScreenPtr pScreen);
409CARD32 SMI_AllocateMemory(ScrnInfoPtr pScrn, void **mem_struct, int size);
410void SMI_FreeMemory(ScrnInfoPtr pScrn, void *mem_struct);
411
412
413#endif  /*_SMI_H*/
414