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