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