Home | History | Annotate | Line # | Download | only in src
      1 /*
      2  * Copyright 1992-2003 by Alan Hourihane, North Wales, UK.
      3  *
      4  * Permission to use, copy, modify, distribute, and sell this software and its
      5  * documentation for any purpose is hereby granted without fee, provided that
      6  * the above copyright notice appear in all copies and that both that
      7  * copyright notice and this permission notice appear in supporting
      8  * documentation, and that the name of Alan Hourihane not be used in
      9  * advertising or publicity pertaining to distribution of the software without
     10  * specific, written prior permission.  Alan Hourihane makes no representations
     11  * about the suitability of this software for any purpose.  It is provided
     12  * "as is" without express or implied warranty.
     13  *
     14  * ALAN HOURIHANE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
     15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
     16  * EVENT SHALL ALAN HOURIHANE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
     17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
     18  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
     19  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
     20  * PERFORMANCE OF THIS SOFTWARE.
     21  *
     22  * Authors:  Alan Hourihane, <alanh (at) fairlite.demon.co.uk>
     23  */
     24 /*#define VBE_INFO*/
     25 
     26 #ifndef _TRIDENT_H_
     27 #define _TRIDENT_H_
     28 
     29 #include <stdio.h>
     30 #include <string.h>
     31 #include <math.h>
     32 
     33 #include "pci_rename.h"
     34 
     35 #include "exa.h"
     36 #include "xf86Cursor.h"
     37 #ifdef HAVE_XAA_H
     38 #include "xaa.h"
     39 #endif
     40 #include "xf86fbman.h"
     41 #include "compiler.h"
     42 #include "vgaHW.h"
     43 #include "xf86i2c.h"
     44 #include "xf86int10.h"
     45 #include "shadowfb.h"
     46 #include "shadow.h"
     47 #include "xf86xv.h"
     48 #include "xf86Pci.h"
     49 #include "vbe.h"
     50 
     51 #include "compat-api.h"
     52 /* Banked framebuffer only supported on ISA */
     53 #ifdef HAVE_ISA
     54 #define LINEAR() (pTrident->Linear)
     55 #else
     56 #define LINEAR() (1)
     57 #endif
     58 
     59 #define PCI_VENDOR_TRIDENT		0x1023
     60 #define PCI_CHIP_2100			0x2100
     61 #define PCI_CHIP_2200			0x2200
     62 #define PCI_CHIP_8400			0x8400
     63 #define PCI_CHIP_8420			0x8420
     64 #define PCI_CHIP_8500			0x8500
     65 #define PCI_CHIP_8520			0x8520
     66 #define PCI_CHIP_8600			0x8600
     67 #define PCI_CHIP_8620			0x8620
     68 #define PCI_CHIP_8820			0x8820
     69 #define PCI_CHIP_9320			0x9320
     70 #define PCI_CHIP_9388			0x9388
     71 #define PCI_CHIP_9397			0x9397
     72 #define PCI_CHIP_939A			0x939A
     73 #define PCI_CHIP_9420			0x9420
     74 #define PCI_CHIP_9440			0x9440
     75 #define PCI_CHIP_9520			0x9520
     76 #define PCI_CHIP_9525			0x9525
     77 #define PCI_CHIP_9540			0x9540
     78 #define PCI_CHIP_9660			0x9660
     79 #define PCI_CHIP_9750			0x9750
     80 #define PCI_CHIP_9850			0x9850
     81 #define PCI_CHIP_9880			0x9880
     82 #define PCI_CHIP_9910			0x9910
     83 
     84 typedef struct {
     85 	unsigned char tridentRegs3x4[0x100];
     86 	unsigned char tridentRegs3CE[0x100];
     87 	unsigned char tridentRegs3C4[0x100];
     88 	unsigned char tridentRegsDAC[0x01];
     89         unsigned char tridentRegsClock[0x05];
     90 	unsigned char DacRegs[0x300];
     91 } TRIDENTRegRec, *TRIDENTRegPtr;
     92 
     93 #define VGA_REGNUM_ABOUT_TV 19
     94 #define TRIDENTPTR(p)	((TRIDENTPtr)((p)->driverPrivate))
     95 
     96 typedef struct {
     97     ScrnInfoPtr		pScrn;
     98     pciVideoPtr		PciInfo;
     99     uint32_t		PciTag;
    100     EntityInfoPtr	pEnt;
    101     ExaDriverPtr	EXADriverPtr;
    102     int			useEXA;
    103     int			Chipset;
    104     int			DACtype;
    105     int                 ChipRev;
    106     int			HwBpp;
    107     int			BppShift;
    108     CARD32		IOAddress;
    109     unsigned long	FbAddress;
    110     unsigned char *     IOBase;
    111     unsigned char *	FbBase;
    112     long		FbMapSize;
    113     unsigned long		PIOBase;
    114     Bool		NoAccel;
    115     Bool		HWCursor;
    116     Bool		UsePCIRetry;
    117     Bool		UsePCIBurst;
    118     Bool		NewClockCode;
    119     Bool		Clipping;
    120     Bool		DstEnable;
    121     Bool		ROP;
    122     Bool		HasSGRAM;
    123     Bool		MUX;
    124     Bool		IsCyber;
    125     Bool		CyberShadow;
    126     Bool		CyberStretch;
    127     Bool		NoMMIO;
    128     Bool                MMIOonly;
    129     Bool		ShadowFB;
    130     Bool		Linear;
    131     DGAModePtr		DGAModes;
    132     int			numDGAModes;
    133     Bool		DGAactive;
    134     int			DGAViewportStatus;
    135     unsigned char *	ShadowPtr;
    136     int			ShadowPitch;
    137     RefreshAreaFuncPtr  RefreshArea;
    138     void	        (*PointerMoved)(SCRN_ARG_TYPE arg, int x, int y);
    139     int                 Rotate;
    140     float		frequency;
    141     unsigned char	REGPCIReg;
    142     unsigned char	REGNewMode1;
    143     CARD8		SaveClock1;
    144     CARD8		SaveClock2;
    145     CARD8		SaveClock3;
    146     int			MinClock;
    147     int			MaxClock;
    148     int			MUXThreshold;
    149     int                 currentClock;
    150     int			MCLK;
    151     int			dwords;
    152     int			h;
    153     int			x;
    154     int			w;
    155     int			y;
    156     int                 lcdMode;
    157     Bool                lcdActive;
    158     Bool                doInit;
    159 #ifdef READOUT
    160     Bool                DontSetClock;
    161 #endif
    162     TRIDENTRegRec	SavedReg;
    163     TRIDENTRegRec	ModeReg;
    164     I2CBusPtr		DDC;
    165     CARD16		EngineOperation;
    166     CARD32		PatternLocation;
    167     CARD32		BltScanDirection;
    168     CARD32		DrawFlag;
    169     CARD16		LinePattern;
    170     int			CursorOffset;
    171     xf86CursorInfoPtr	CursorInfoRec;
    172     xf86Int10InfoPtr	Int10;
    173     vbeInfoPtr		pVbe;
    174 #ifdef VBE_INFO
    175     vbeModeInfoPtr	vbeModes;
    176 #endif
    177 #ifdef HAVE_XAA_H
    178     XAAInfoRecPtr	AccelInfoRec;
    179 #endif
    180     CloseScreenProcPtr	CloseScreen;
    181     ScreenBlockHandlerProcPtr BlockHandler;
    182     CreateScreenResourcesProcPtr CreateScreenResources;
    183     int                 panelWidth;
    184     int                 panelHeight;
    185     unsigned int	(*ddc1Read)(ScrnInfoPtr);
    186     CARD8*		XAAScanlineColorExpandBuffers[2];
    187     CARD8*		XAAImageScanlineBuffer[1];
    188     void                (*InitializeAccelerator)(ScrnInfoPtr);
    189     void		(*VideoTimerCallback)(ScrnInfoPtr, Time);
    190     XF86VideoAdaptorPtr adaptor;
    191     int                 videoKey;
    192     int			hsync;
    193     int			hsync_rskew;
    194     int			vsync;
    195     int			vsync_bskew;
    196     CARD32              videoFlags;
    197     int			keyOffset;
    198     int                 OverrideHsync;
    199     int                 OverrideVsync;
    200     int                 OverrideBskew;
    201     int                 OverrideRskew;
    202     OptionInfoPtr	Options;
    203     Bool		shadowNew;
    204     int			displaySize;
    205     int			dspOverride;
    206     Bool		GammaBrightnessOn;
    207     int			brightness;
    208     double		gamma;
    209     int			FPDelay;	/* just for debugging - will go away */
    210     int                 TVChipset;    /* 0: None 1: VT1621 2: CH7005C*/
    211     int                 TVSignalMode; /* 0: NTSC 1: PAL */
    212     Bool                TVRegSet;     /* 0: User not customer TV Reg, 1: User customer TV Reg */
    213     unsigned char       TVRegUserSet[2][128]; /*[0][128] for Reg Index, [1][128] for Reg Value */
    214     unsigned char       DefaultTVDependVGASetting[VGA_REGNUM_ABOUT_TV+0x62]; /* VGA_REGNUM_ABOUT_TV: VGA Reg, 0x62: TV Reg */
    215 } TRIDENTRec, *TRIDENTPtr;
    216 
    217 typedef struct {
    218     CARD8 mode;
    219     int display_x;
    220     int display_y;
    221     int clock;
    222     int shadow_0;
    223     int shadow_3;
    224     int shadow_4;
    225     int shadow_5;
    226     int shadow_6;
    227     int shadow_7;
    228     int shadow_10;
    229     int shadow_11;
    230     int shadow_16;
    231     int shadow_HiOrd;
    232 } tridentLCD;
    233 
    234 #define LCD_ACTIVE 0x01
    235 #define CRT_ACTIVE 0x02
    236 
    237 extern tridentLCD LCD[];
    238 
    239 typedef struct {
    240     int x_res;
    241     int y_res;
    242     int mode;
    243 } biosMode;
    244 
    245 typedef struct {
    246   int x_res;
    247   int y_res;
    248   CARD8 GR5a;
    249   CARD8 GR5c;
    250 } newModes;
    251 
    252 /* Prototypes */
    253 
    254 Bool TRIDENTClockSelect(ScrnInfoPtr pScrn, int no);
    255 Bool TRIDENTSwitchMode(SWITCH_MODE_ARGS_DECL);
    256 void TRIDENTAdjustFrame(ADJUST_FRAME_ARGS_DECL);
    257 Bool TRIDENTDGAInit(ScreenPtr pScreen);
    258 Bool TRIDENTI2CInit(ScreenPtr pScreen);
    259 void TRIDENTInitVideo(ScreenPtr pScreen);
    260 void TRIDENTResetVideo(ScrnInfoPtr pScrn);
    261 unsigned int Tridentddc1Read(ScrnInfoPtr pScrn);
    262 void TVGARestore(ScrnInfoPtr pScrn, TRIDENTRegPtr tridentReg);
    263 void TVGASave(ScrnInfoPtr pScrn, TRIDENTRegPtr tridentReg);
    264 Bool TVGAInit(ScrnInfoPtr pScrn, DisplayModePtr mode);
    265 void TridentRestore(ScrnInfoPtr pScrn, TRIDENTRegPtr tridentReg);
    266 void TridentSave(ScrnInfoPtr pScrn, TRIDENTRegPtr tridentReg);
    267 Bool TridentInit(ScrnInfoPtr pScrn, DisplayModePtr mode);
    268 Bool TridentAccelInit(ScreenPtr pScreen);
    269 Bool XPAccelInit(ScreenPtr pScreen);
    270 Bool XP4XaaInit(ScreenPtr pScreen);
    271 Bool XP4ExaInit(ScreenPtr pScreen);
    272 Bool ImageAccelInit(ScreenPtr pScreen);
    273 Bool BladeXaaInit(ScreenPtr pScreen);
    274 Bool BladeExaInit(ScreenPtr pScreen);
    275 Bool TridentHWCursorInit(ScreenPtr pScreen);
    276 int TridentFindMode(int xres, int yres, int depth);
    277 void TGUISetClock(ScrnInfoPtr pScrn, int clock, unsigned char *a, unsigned char *b);
    278 void TGUISetMCLK(ScrnInfoPtr pScrn, int clock, unsigned char *a, unsigned char *b);
    279 void tridentSetModeBIOS(ScrnInfoPtr pScrn, DisplayModePtr mode);
    280 void TridentOutIndReg(ScrnInfoPtr pScrn,
    281 		     CARD32 reg, unsigned char mask, unsigned char data);
    282 unsigned char TridentInIndReg(ScrnInfoPtr pScrn, CARD32 reg);
    283 void TridentLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, LOCO *colors, VisualPtr pVisual);
    284 void TridentSetOverscan(ScrnInfoPtr pScrn, int overscan);
    285 int TGUISetRead(ScreenPtr pScreen, int bank);
    286 int TGUISetWrite(ScreenPtr pScreen, int bank);
    287 int TGUISetReadWrite(ScreenPtr pScreen, int bank);
    288 int TVGA8900SetRead(ScreenPtr pScreen, int bank);
    289 int TVGA8900SetWrite(ScreenPtr pScreen, int bank);
    290 int TVGA8900SetReadWrite(ScreenPtr pScreen, int bank);
    291 void TridentFindClock(ScrnInfoPtr pScrn, int clock);
    292 float CalculateMCLK(ScrnInfoPtr pScrn);
    293 void TRIDENTRefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
    294 void TRIDENTShadowUpdate (ScreenPtr pScreen, shadowBufPtr pBuf);
    295 void TRIDENTPointerMoved(SCRN_ARG_TYPE arg, int x, int y);
    296 void TRIDENTRefreshArea8(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
    297 void TRIDENTRefreshArea16(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
    298 void TRIDENTRefreshArea24(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
    299 void TRIDENTRefreshArea32(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
    300 
    301 void VIA_TVInit(ScrnInfoPtr pScrn);
    302 void VIA_SaveTVDepentVGAReg(ScrnInfoPtr pScrn);
    303 void VIA_RestoreTVDependVGAReg(ScrnInfoPtr pScrn);
    304 void VIA_DumpReg(ScrnInfoPtr pScrn);
    305 
    306 /*
    307  * Trident Chipset Definitions
    308  */
    309 
    310 /* Supported chipsets */
    311 typedef enum {
    312     TVGA8200LX,
    313     TVGA8800BR,
    314     TVGA8800CS,
    315     TVGA8900B,
    316     TVGA8900C,
    317     TVGA8900CL,
    318     TVGA8900D,
    319     TVGA9000,
    320     TVGA9000i,
    321     TVGA9100B,
    322     TVGA9200CXr,
    323     TGUI9400CXi,
    324     TGUI9420DGi,
    325     TGUI9430DGi,
    326     TGUI9440AGi,
    327     CYBER9320,
    328     TGUI9660,
    329     TGUI9680,
    330     PROVIDIA9682,
    331     CYBER9382,
    332     CYBER9385,
    333     PROVIDIA9685,
    334     CYBER9388,
    335     CYBER9397,
    336     CYBER9397DVD,
    337     CYBER9520,
    338     CYBER9525DVD,
    339     IMAGE975,
    340     IMAGE985,
    341     BLADE3D,
    342     CYBERBLADEI7,
    343     CYBERBLADEI7D,
    344     CYBERBLADEI1,
    345     CYBERBLADEI1D,
    346     CYBERBLADEAI1,
    347     CYBERBLADEAI1D,
    348     CYBERBLADEE4,
    349     BLADEXP,
    350     CYBERBLADEXPAI1,
    351     CYBERBLADEXP4,
    352     XP5
    353 } TRIDENTType;
    354 
    355 #define UseMMIO		(pTrident->NoMMIO == FALSE)
    356 
    357 #define IsPciCard	(pTrident->pEnt->location.type == BUS_PCI)
    358 
    359 #ifdef HAVE_ISA
    360 # define IsPrimaryCard	((xf86IsPrimaryPci(pTrident->PciInfo)) || \
    361 			 (xf86IsPrimaryIsa()))
    362 #else
    363 # define IsPrimaryCard	(xf86IsPrimaryPci(pTrident->PciInfo))
    364 #endif
    365 
    366 #define HAS_DST_TRANS	((pTrident->Chipset == PROVIDIA9682) || \
    367 			 (pTrident->Chipset == PROVIDIA9685) || \
    368 			 (pTrident->Chipset == BLADEXP) || \
    369 			 (pTrident->Chipset == CYBERBLADEXPAI1))
    370 
    371 #define Is3Dchip	((pTrident->Chipset == CYBER9397) || \
    372 			 (pTrident->Chipset == CYBER9397DVD) || \
    373 			 (pTrident->Chipset == CYBER9520) || \
    374 			 (pTrident->Chipset == CYBER9525DVD) || \
    375 			 (pTrident->Chipset == CYBERBLADEE4)  || \
    376 			 (pTrident->Chipset == IMAGE975)  || \
    377 			 (pTrident->Chipset == IMAGE985)  || \
    378 			 (pTrident->Chipset == CYBERBLADEI7)  || \
    379 			 (pTrident->Chipset == CYBERBLADEI7D)  || \
    380 			 (pTrident->Chipset == CYBERBLADEI1)  || \
    381 			 (pTrident->Chipset == CYBERBLADEI1D)  || \
    382 			 (pTrident->Chipset == CYBERBLADEAI1)  || \
    383 			 (pTrident->Chipset == CYBERBLADEAI1D)  || \
    384 			 (pTrident->Chipset == BLADE3D) || \
    385 			 (pTrident->Chipset == CYBERBLADEXPAI1) || \
    386 			 (pTrident->Chipset == CYBERBLADEXP4) || \
    387 			 (pTrident->Chipset == XP5) || \
    388 			 (pTrident->Chipset == BLADEXP))
    389 
    390 /*
    391  * Trident DAC's
    392  */
    393 
    394 #define TKD8001		0
    395 #define TGUIDAC		1
    396 
    397 /*
    398  * Video Flags
    399  */
    400 
    401 #define VID_ZOOM_INV 0x1
    402 #define VID_ZOOM_MINI 0x2
    403 #define VID_OFF_SHIFT_4 0x4
    404 #define VID_ZOOM_NOMINI 0x8
    405 #define VID_DOUBLE_LINEBUFFER_FOR_WIDE_SRC 0x10
    406 #endif /* _TRIDENT_H_ */
    407 
    408