smi.h revision 09885543
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/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/siliconmotion/smi.h,v 1.12tsi Exp $ */ 30 31#ifndef _SMI_H 32#define _SMI_H 33 34#include <string.h> 35#include <stdio.h> 36 37#include "xf86.h" 38#include "xf86_OSproc.h" 39#include "xf86PciInfo.h" 40#include "xf86Pci.h" 41#include "xf86Cursor.h" 42#include "vgaHW.h" 43 44#include "compiler.h" 45 46#include "mipointer.h" 47#include "micmap.h" 48 49#include "fb.h" 50 51#include "xaa.h" 52#include "exa.h" 53#include "xf86cmap.h" 54#include "xf86i2c.h" 55 56#include "xf86int10.h" 57#include "vbe.h" 58 59#include "xf86xv.h" 60#include <X11/extensions/Xv.h> 61 62/******************************************************************************/ 63/* D E F I N I T I O N S */ 64/******************************************************************************/ 65 66#ifndef SMI_DEBUG 67# define SMI_DEBUG 0 68#endif 69 70#define SMI_USE_IMAGE_WRITES 0 71#define SMI_USE_VIDEO 1 72#define SMI_USE_CAPTURE 1 73 74/******************************************************************************/ 75/* S T R U C T U R E S */ 76/******************************************************************************/ 77 78/* Driver data structure; this should contain all needed info for a mode */ 79typedef struct 80{ 81 Bool modeInit; 82 CARD16 mode; 83 CARD8 SR17, SR18, SR21, SR31, SR32, SR6A, SR6B, SR81, SRA0; 84 CARD8 CR33, CR33_2, CR3A; 85 CARD8 CR40[14], CR40_2[14]; 86 CARD8 CR90[16], CR9F_2; 87 CARD8 CRA0[14]; 88 CARD8 smiDACMask, smiDacRegs[256][3]; 89 /* CZ 2.11.2001: for gamma correction */ 90 CARD8 CCR66; 91 /* end CZ */ 92 CARD8 smiFont[8192]; 93 CARD32 DPR10, DPR1C, DPR20, DPR24, DPR28, DPR2C, DPR30, DPR3C, DPR40, 94 DPR44; 95 CARD32 VPR00, VPR0C, VPR10; 96 CARD32 CPR00; 97 CARD32 FPR00_, FPR0C_, FPR10_; 98 /* LCD FIFO regs, etc. - dualhead */ 99 CARD8 SR22, SR40, SR41, SR42, SR43, SR44, SR45, SR48, SR49, 100 SR4A, SR4B, SR4C; 101 /* PLL controls */ 102 CARD8 SR68, SR69, SR6C, SR6D, SR6E, SR6F; 103 104} SMIRegRec, *SMIRegPtr; 105 106/* Global PDEV structure. */ 107typedef struct 108{ 109 /* accel additions */ 110 CARD32 AccelCmd; /* Value for DPR0C */ 111 CARD32 Stride; /* Stride of frame buffer */ 112 CARD32 ScissorsLeft; /* Left/top of current 113 scissors */ 114 CARD32 ScissorsRight; /* Right/bottom of current 115 scissors */ 116 Bool ClipTurnedOn; /* Clipping was turned on by 117 the previous command */ 118 CARD8 SR18Value; /* PDR#521: original SR18 119 value */ 120 CARD8 SR21Value; /* PDR#521: original SR21 121 value */ 122 SMIRegRec SavedReg; /* console saved mode 123 registers */ 124 SMIRegRec ModeReg; /* XServer video state mode 125 registers */ 126 xf86CursorInfoPtr CursorInfoRec; /* HW Cursor info */ 127 128 Bool ModeStructInit; /* Flag indicating ModeReg has 129 been duped from console 130 state */ 131 int vgaCRIndex, vgaCRReg; 132 int width, height; /* Width and height of the 133 screen */ 134 int Bpp; /* Bytes per pixel */ 135 136 /* XAA */ 137 int videoRAMBytes; /* In units as noted, set in 138 PreInit */ 139 int videoRAMKBytes; /* In units as noted, set in 140 PreInit */ 141 unsigned char * MapBase; /* Base of mapped memory */ 142 int MapSize; /* Size of mapped memory */ 143 CARD8 * DPRBase; /* Base of DPR registers */ 144 CARD8 * VPRBase; /* Base of VPR registers */ 145 CARD8 * CPRBase; /* Base of CPR registers */ 146 CARD8 * FPRBase; /* Base of FPR registers - for 0730 chipset */ 147 CARD8 * DataPortBase; /* Base of data port */ 148 int DataPortSize; /* Size of data port */ 149 CARD8 * IOBase; /* Base of MMIO VGA ports */ 150 IOADDRESS PIOBase; /* Base of I/O ports */ 151 unsigned char * FBBase; /* Base of FB */ 152 CARD32 FBOffset; /* Current visual FB starting 153 location */ 154 CARD32 FBCursorOffset; /* Cursor storage location */ 155 CARD32 FBReserved; /* Reserved memory in frame 156 buffer */ 157 158 Bool PrimaryVidMapped; /* Flag indicating if 159 vgaHWMapMem was used 160 successfully for 161 this screen */ 162 int MCLK; /* Memory Clock */ 163 int GEResetCnt; /* Limit the number of errors 164 printed using a counter */ 165 166 Bool pci_burst; /* Enable PCI burst mode for 167 reads? */ 168 Bool NoPCIRetry; /* Disable PCI retries */ 169 Bool fifo_conservative; /* Adjust fifo for 170 acceleration? */ 171 Bool fifo_moderate; /* Adjust fifo for 172 acceleration? */ 173 Bool fifo_aggressive; /* Adjust fifo for 174 acceleration? */ 175 Bool NoAccel; /* Disable Acceleration */ 176 Bool hwcursor; /* hardware cursor enabled */ 177 Bool ShowCache; /* Debugging option */ 178 Bool useBIOS; /* Use BIOS for mode sets */ 179 Bool zoomOnLCD; /* Zoom on LCD */ 180 181 CloseScreenProcPtr CloseScreen; /* Pointer used to save wrapped 182 CloseScreen function */ 183 XAAInfoRecPtr XAAInfoRec; /* XAA info Rec */ 184 185 /* EXA */ 186 ExaDriverPtr EXADriverPtr; 187 Bool useEXA; /* enable exa acceleration */ 188 189 pciVideoPtr PciInfo; /* PCI info vars */ 190 PCITAG PciTag; 191 int Chipset; /* Chip info, set using PCI 192 above */ 193 int ChipRev; 194 195 /* DGA */ 196 DGAModePtr DGAModes; /* Pointer to DGA modes */ 197 int numDGAModes; /* Number of DGA modes */ 198 Bool DGAactive; /* Flag if DGA is active */ 199 int DGAViewportStatus; 200 201 /* DPMS */ 202 int CurrentDPMS; /* Current DPMS state */ 203 unsigned char DPMS_SR20; /* Saved DPMS SR20 register */ 204 unsigned char DPMS_SR21; /* Saved DPMS SR21 register */ 205 unsigned char DPMS_SR31; /* Saved DPMS SR31 register */ 206 unsigned char DPMS_SR34; /* Saved DPMS SR34 register */ 207 208 /* Panel information */ 209 Bool lcd; /* LCD active, 1=DSTN, 2=TFT */ 210 int lcdWidth; /* LCD width */ 211 int lcdHeight; /* LCD height */ 212 213 I2CBusPtr I2C; /* Pointer into I2C module */ 214 xf86Int10InfoPtr pInt10; /* Pointer to INT10 module */ 215 216 /* Shadow frame buffer (rotation) */ 217 Bool shadowFB; /* Flag if shadow buffer is 218 used */ 219 int rotate; /* Rotation flags */ 220 int ShadowPitch; /* Pitch of shadow buffer */ 221 int ShadowWidthBytes; /* Width of shadow 222 buffer in bytes */ 223 int ShadowWidth; /* Width of shadow buffer in 224 pixels */ 225 int ShadowHeight; /* Height of shadow buffer in 226 pixels */ 227 CARD32 saveBufferSize; /* #670 - FB save buffer size */ 228 void * pSaveBuffer; /* #670 - FB save buffer */ 229 CARD32 fbMapOffset; /* offset for fb mapping */ 230 CARD32 savedFBOffset; /* #670 - Saved FBOffset value */ 231 CARD32 savedFBReserved; /* #670 - Saved 232 FBReserved value */ 233 CARD8 * paletteBuffer; /* #920 - Palette save buffer */ 234 235 /* Polylines - #671 */ 236 ValidateGCProcPtr ValidatePolylines; /* Org. 237 ValidatePolylines 238 function */ 239 Bool polyLines; /* Our polylines patch is 240 active */ 241 242 void (*PointerMoved)(int index, int x, int y); 243 244 int videoKey; /* Video chroma key */ 245 Bool ByteSwap; /* Byte swap for ZV port */ 246 Bool interlaced; /* True: Interlaced Video */ 247 /* XvExtension */ 248 XF86VideoAdaptorPtr ptrAdaptor; /* Pointer to VideoAdapter 249 structure */ 250 void (*BlockHandler)(int i, pointer blockData, pointer pTimeout, 251 pointer pReadMask); 252 GCPtr videoGC; 253 OptionInfoPtr Options; 254 CARD8 DACmask; 255 256 Bool Dualhead; 257 258 Bool IsSwitching; /* when switching modes */ 259 260} SMIRec, *SMIPtr; 261 262#define SMIPTR(p) ((SMIPtr)((p)->driverPrivate)) 263 264/******************************************************************************/ 265/* M A C R O S */ 266/******************************************************************************/ 267 268#if SMI_DEBUG 269# define VERBLEV 1 270# define ENTER_PROC(PROCNAME) xf86ErrorFVerb(VERBLEV, "ENTER\t" PROCNAME \ 271 "(%d)\n", __LINE__); xf86Break1() 272# define DEBUG_PROC(PROCNAME) xf86ErrorFVerb(VERBLEV, "DEBUG\t" PROCNAME \ 273 "(%d)\n", __LINE__); xf86Break2() 274# define LEAVE_PROC(PROCNAME) xf86ErrorFVerb(VERBLEV, "LEAVE\t" PROCNAME \ 275 "(%d)\n", __LINE__); xf86Break1() 276# define DEBUG(arg) xf86ErrorFVerb arg 277#else 278# define VERBLEV 4 279# define ENTER_PROC(PROCNAME) 280# define DEBUG_PROC(PROCNAME) 281# define LEAVE_PROC(PROCNAME) 282# define DEBUG(arg) 283#endif 284 285/* Some Silicon Motion structs & registers */ 286#include "regsmi.h" 287 288#if !defined (MetroLink) && !defined (VertDebug) 289#define VerticalRetraceWait() \ 290do \ 291{ \ 292 if (VGAIN8_INDEX(pSmi, vgaCRIndex, vgaCRData, 0x17) & 0x80) \ 293 { \ 294 while ((VGAIN8(pSmi, vgaIOBase + 0x0A) & 0x08) == 0x00); \ 295 while ((VGAIN8(pSmi, vgaIOBase + 0x0A) & 0x08) == 0x08); \ 296 while ((VGAIN8(pSmi, vgaIOBase + 0x0A) & 0x08) == 0x00); \ 297 } \ 298} while (0) 299#else 300#define SPIN_LIMIT 1000000 301#define VerticalRetraceWait() \ 302do \ 303{ \ 304 if (VGAIN8_INDEX(pSmi, vgaCRIndex, vgaCRData, 0x17) & 0x80) \ 305 { \ 306 volatile unsigned long _spin_me; \ 307 for (_spin_me = SPIN_LIMIT; \ 308 ((VGAIN8(pSmi, vgaIOBase + 0x0A) & 0x08) == 0x00) && \ 309 _spin_me; \ 310 _spin_me--); \ 311 if (!_spin_me) \ 312 ErrorF("smi: warning: VerticalRetraceWait timed out.\n"); \ 313 for (_spin_me = SPIN_LIMIT; \ 314 ((VGAIN8(pSmi, vgaIOBase + 0x0A) & 0x08) == 0x08) && \ 315 _spin_me; \ 316 _spin_me--); \ 317 if (!_spin_me) \ 318 ErrorF("smi: warning: VerticalRetraceWait timed out.\n"); \ 319 for (_spin_me = SPIN_LIMIT; \ 320 ((VGAIN8(pSmi, vgaIOBase + 0x0A) & 0x08) == 0x00) && \ 321 _spin_me; \ 322 _spin_me--); \ 323 if (!_spin_me) \ 324 ErrorF("smi: warning: VerticalRetraceWait timed out.\n"); \ 325 } \ 326} while (0) 327#endif 328 329/******************************************************************************/ 330/* F U N C T I O N P R O T O T Y P E S */ 331/******************************************************************************/ 332 333/* smi_dac.c */ 334void SMI_CommonCalcClock(int scrnIndex, long freq, int min_m, int min_n1, 335 int max_n1, int min_n2, int max_n2, long freq_min, 336 long freq_max, unsigned char * mdiv, 337 unsigned char * ndiv); 338 339/* smi_i2c */ 340Bool SMI_I2CInit(ScrnInfoPtr pScrn); 341 342/* smi_accel.c */ 343Bool SMI_XAAInit(ScreenPtr pScrn); 344Bool SMI_EXAInit(ScreenPtr pScrn); 345void SMI_AccelSync(ScrnInfoPtr pScrn); 346void SMI_GEReset(ScrnInfoPtr pScrn, int from_timeout, int line, char *file); 347void SMI_EngineReset(ScrnInfoPtr); 348void SMI_SetClippingRectangle(ScrnInfoPtr, int, int, int, int); 349void SMI_DisableClipping(ScrnInfoPtr); 350 351/* smi_hwcurs.c */ 352Bool SMI_HWCursorInit(ScreenPtr pScrn); 353 354/* smi_driver.c */ 355void SMI_AdjustFrame(int scrnIndex, int x, int y, int flags); 356Bool SMI_SwitchMode(int scrnIndex, DisplayModePtr mode, int flags); 357 358/* smi_dga.c */ 359Bool SMI_DGAInit(ScreenPtr pScrn); 360 361/* smi_shadow.c */ 362void SMI_PointerMoved(int index, int x, int y); 363void SMI_RefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox); 364void SMI_RefreshArea730(ScrnInfoPtr pScrn, int num, BoxPtr pbox); 365 366/* smi_video.c */ 367void SMI_InitVideo(ScreenPtr pScreen); 368 369#endif /*_SMI_H*/ 370