PageRenderTime 62ms CodeModel.GetById 18ms app.highlight 35ms RepoModel.GetById 1ms app.codeStats 1ms

/src/xgi.h

#
C++ Header | 1038 lines | 736 code | 153 blank | 149 comment | 7 complexity | f813e9e1dc1d5fca5525938d99153898 MD5 | raw file
   1/*
   2 * Main global data and definitions
   3 *
   4 * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria
   5 *
   6 * Redistribution and use in source and binary forms, with or without
   7 * modification, are permitted provided that the following conditions
   8 * are met:
   9 * 1) Redistributions of source code must retain the above copyright
  10 *    notice, this list of conditions and the following disclaimer.
  11 * 2) Redistributions in binary form must reproduce the above copyright
  12 *    notice, this list of conditions and the following disclaimer in the
  13 *    documentation and/or other materials provided with the distribution.
  14 * 3) The name of the author may not be used to endorse or promote products
  15 *    derived from this software without specific prior written permission.
  16 *
  17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESSED OR
  18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27 *
  28 * Authors:   Thomas Winischhofer <thomas@winischhofer.net>
  29 *            others (old code base)
  30 *
  31 */
  32#ifndef _XGI_H_
  33#define _XGI_H_
  34
  35#define DEBUG 
  36#define DEBUG1
  37#define DEBUG2
  38#define DEBUG3
  39#define DEBUG4
  40#define DEBUG5
  41
  42/***************
  43#define DEBUG 
  44#define DEBUG1
  45#define DEBUG2
  46#define DEBUG3
  47#define DEBUG4
  48#define DEBUG5
  49#define DEBUGI2C
  50*****************/
  51
  52#ifndef XGI_VIDEO_HW /* avoid compile error in xgi_videohw.c; weird!  */
  53/* Jong 07/27/2009; use run-time debug instead except for HW acceleration routines */
  54extern BOOL g_bRunTimeDebug;
  55#define RUNTIMEDEBUG(p)		if(g_bRunTimeDebug)p;
  56
  57/* Jong@08052009 */
  58#ifdef  DEBUGI2C
  59#define PDEBUGI2C(p)       p
  60#else
  61#define PDEBUGI2C(p)
  62#endif
  63
  64#ifdef  DEBUG
  65#define PDEBUG(p)       RUNTIMEDEBUG(p)
  66#else
  67#define PDEBUG(p)
  68#endif
  69
  70#ifdef DEBUG1
  71#define PDEBUG1(p)		RUNTIMEDEBUG(p)
  72#else
  73#define PDEBUG1(p)
  74#endif
  75
  76#ifdef DEBUG2
  77#define PDEBUG2(p)		RUNTIMEDEBUG(p)
  78#else
  79#define PDEBUG2(p)
  80#endif
  81
  82#ifdef DEBUG3
  83#define PDEBUG3(p)		RUNTIMEDEBUG(p)
  84#else
  85#define PDEBUG3(p)
  86#endif
  87
  88#ifdef DEBUG4
  89#define PDEBUG4(p)		RUNTIMEDEBUG(p)
  90#else
  91#define PDEBUG4(p)
  92#endif
  93
  94#ifdef  DEBUG5
  95#define PDEBUG5(p)		RUNTIMEDEBUG(p)
  96#else
  97#define PDEBUG5(p)
  98#endif
  99
 100#ifdef  CDEBUG
 101#define CPDEBUG(p)       p
 102#else
 103#define CPDEBUG(p)
 104#endif
 105
 106#ifdef CDEBUG1
 107#define CPDEBUG1(p) p
 108#else
 109#define CPDEBUG1(p)
 110#endif
 111
 112#ifdef CDEBUG2
 113#define CPDEBUG2(p) p
 114#else
 115#define CPDEBUG2(p)
 116#endif
 117
 118#ifdef CDEBUG3
 119#define CPDEBUG3(p) p
 120#else
 121#define CPDEBUG3(p)
 122#endif
 123
 124#ifdef CDEBUG4
 125#define CPDEBUG4(p) p
 126#else
 127#define CPDEBUG4(p)
 128#endif
 129
 130#ifdef  CDEBUG5
 131#define CPDEBUG5(p)       p
 132#else
 133#define CPDEBUG5(p)
 134#endif
 135
 136#ifdef  ACCELDEBUG
 137#define PACCELDEBUG(p)       p
 138#else
 139#define PACCELDEBUG(p)
 140#endif
 141#endif
 142
 143/* Always unlock the registers (should be set!) */
 144#define UNLOCK_ALWAYS
 145
 146#undef XGI_CP
 147
 148#ifdef XSERVER_LIBPCIACCESS
 149#include <pciaccess.h>
 150#else
 151#include "xf86Pci.h"
 152#endif
 153#include "xf86Cursor.h"
 154#include "xf86xv.h"
 155#include "compiler.h"
 156
 157#ifdef XORG_VERSION_CURRENT
 158#include "xorgVersion.h"
 159
 160/* #if XORG_VERSION_CURRENT > XORG_VERSION_NUMERIC(7,0,0,0,0) */
 161#if ((XORG_VERSION_CURRENT > XORG_VERSION_NUMERIC(7,0,0,0,0)) || (XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(2,0,0,0,0)) )
 162#define XGIISXORGPOST70
 163#endif
 164
 165#if (XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(6,9,0,0,0) )
 166#define XGI_USE_EXA
 167#endif
 168
 169#endif
 170
 171/* Jong 01/13/2009; support EXA */
 172#define XGI_USE_XAA 
 173/* #define XGI_USE_EXA */
 174
 175#ifdef XGI_USE_XAA
 176#include "xaa.h"
 177#endif
 178#ifdef XGI_USE_EXA
 179#include "exa.h"
 180#endif
 181
 182#include "vgaHW.h"
 183#include "vbe.h"
 184
 185/*
 186#ifdef XORG_VERSION_CURRENT
 187#include "xorgVersion.h"
 188#endif */
 189
 190/* #define XGIISXORGPOST70 */
 191
 192#include "xgi_pci.h"
 193#include "osdef.h"
 194#include "vgatypes.h"
 195#include "vb_struct.h"
 196
 197#ifdef XF86DRI
 198#define XGINEWDRI
 199#undef XGINEWDRI2
 200
 201#ifdef XF86_VERSION_CURRENT
 202#if XF86_VERSION_CURRENT >= XF86_VERSION_NUMERIC(4,4,99,99,0)	/* Adapt this when the time has come */
 203#define XGINEWDRI2
 204#endif
 205#endif /* XF86_VERSION_CURRENT */
 206
 207#include "xf86drm.h"
 208#include "sarea.h"
 209#define _XF86DRI_SERVER_
 210
 211/* Jong@09032009 */
 212#ifdef XORG_VERSION_CURRENT
 213#if ( (XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(6,9,0,0,0)) || (XORG_VERSION_CURRENT <= XORG_VERSION_NUMERIC(2,0,0,0,0)) )
 214#include "X11/dri/xf86dri.h"
 215#else
 216#include "xf86dri.h"
 217#endif
 218#endif
 219
 220#include "dri.h"
 221#include "GL/glxint.h"
 222#include "xgi_dri.h"
 223#endif
 224
 225#ifdef XSERVER_LIBPCIACCESS
 226#define VENDOR_ID(p)      (p)->vendor_id
 227#define DEVICE_ID(p)      (p)->device_id
 228#define SUBSYS_ID(p)      (p)->subdevice_id
 229#define CHIP_REVISION(p)  (p)->revision
 230#else
 231#define VENDOR_ID(p)      (p)->vendor
 232#define DEVICE_ID(p)      (p)->chipType
 233#define SUBSYS_ID(p)      (p)->subsysCard
 234#define CHIP_REVISION(p)  (p)->chipRev
 235#endif
 236
 237#if 1 
 238#define XGIDUALHEAD  		/* Include Dual Head code  */
 239#endif
 240
 241#if 1 
 242#define XGIMERGED		/* Include Merged-FB mode */
 243#endif
 244
 245#ifdef XGIMERGED
 246#if 1
 247#define XGIXINERAMA		/* Include Pseudo-Xinerama for MergedFB mode */
 248#define XGI_XINERAMA_MAJOR_VERSION  1
 249#define XGI_XINERAMA_MINOR_VERSION  1
 250#endif
 251#endif
 252
 253#if 1
 254#define XGIGAMMA		/* Include code for gamma correction */
 255#endif
 256
 257/* Jong 09/28/2007; disable this because it causes cursor drawing incorrectly */
 258#if 0				/* Include code for color hardware cursors */
 259#define XGI_ARGB_CURSOR
 260#endif
 261
 262#if 0				/* Include YPbPr support on VB  */
 263#define ENABLE_YPBPR
 264#endif
 265
 266#ifdef XGIMERGED
 267#ifdef XGIXINERAMA
 268#define EXTENSION_PROC_ARGS void *
 269#include "extnsionst.h"  	/* required */
 270#include <X11/extensions/panoramiXproto.h>  	/* required */
 271#endif
 272#endif
 273
 274#if 1
 275#define XGIVRAMQ		/* Use VRAM queue mode on 315 series */
 276#endif
 277
 278#undef XGI315DRI		/* define this if dri is adapted for 315/330 series */
 279
 280#ifndef PCI_VENDOR_XGI
 281#define PCI_VENDOR_XGI 		    0x18CA
 282#endif
 283#ifndef PCI_CHIP_XGIXG40
 284#define PCI_CHIP_XGIXG40 		0x0040
 285#endif
 286#ifndef PCI_CHIP_XGIXG20
 287#define PCI_CHIP_XGIXG20 		0x0020
 288#endif
 289
 290/* Jong 09/18/2007; patch to GIT */
 291#ifndef PCI_CHIP_XGIXG27
 292#define PCI_CHIP_XGIXG27 		0x0027
 293#endif
 294
 295/* Jong 01/07/2008; support New XG21 */
 296#ifndef PCI_CHIP_XGIXG21
 297#define PCI_CHIP_XGIXG21 		0x0021
 298#endif
 299
 300#define CONFIG_DRM_XGI
 301
 302#define XGI_NAME                "XGI"
 303#define XGI_DRIVER_NAME         "xgi"
 304#define XGI_CURRENT_VERSION     ((PACKAGE_VERSION_MAJOR << 16) | \
 305                                 (PACKAGE_VERSION_MINOR << 8) | \
 306				 PACKAGE_VERSION_PATCHLEVEL)
 307
 308/* pXGI->Flags (old series only) */
 309#define SYNCDRAM                0x00000001
 310#define RAMFLAG                 0x00000002
 311#define ESS137xPRESENT          0x00000004
 312#define SECRETFLAG              0x00000008
 313#define A6326REVAB              0x00000010
 314#define MMIOMODE                0x00010000
 315#define LFBQMODE                0x00020000
 316#define AGPQMODE                0x00040000
 317#define UMA                     0x80000000
 318
 319#define BIOS_BASE               0xC0000
 320#define BIOS_SIZE               0x10000
 321
 322#define SR_BUFFER_SIZE          5
 323#define CR_BUFFER_SIZE          5
 324
 325#define XGI_VBFlagsVersion	1
 326
 327/* VBFlags - if anything is changed here, increase VBFlagsVersion! */
 328#define CRT2_DEFAULT            0x00000001
 329#define CRT2_LCD                0x00000002  /* Never change the order of the CRT2_XXX entries */
 330#define CRT2_TV                 0x00000004
 331#define CRT2_VGA                0x00000008
 332#define TV_NTSC                 0x00000010
 333#define TV_PAL                  0x00000020
 334#define TV_HIVISION             0x00000040
 335#define TV_YPBPR                0x00000080
 336#define TV_AVIDEO               0x00000100
 337#define TV_SVIDEO               0x00000200
 338#define TV_SCART                0x00000400
 339#define VB_CONEXANT		0x00000800   /* 661 series only */
 340#define VB_TRUMPION		VB_CONEXANT  /* 300 series only */
 341#define TV_PALM                 0x00001000
 342#define TV_PALN                 0x00002000
 343#define TV_NTSCJ		0x00001000
 344#define VB_302ELV		0x00004000
 345#define TV_CHSCART              0x00008000
 346#define TV_CHYPBPR525I          0x00010000
 347#define CRT1_VGA		0x00000000
 348#define CRT1_LCDA		0x00020000
 349#define VGA2_CONNECTED          0x00040000
 350#define DISPTYPE_CRT1		0x00080000  	/* CRT1 connected and used */
 351
 352#define SINGLE_MODE             0x20000000   	/* CRT1 or CRT2; determined by DISPTYPE_CRTx */
 353#define MIRROR_MODE		0x40000000   	/* CRT1 + CRT2 identical (mirror mode) */
 354#define DUALVIEW_MODE		0x80000000   	/* CRT1 + CRT2 independent (dual head mode) */
 355
 356/* Aliases: */
 357#define CRT2_ENABLE		(CRT2_LCD | CRT2_TV | CRT2_VGA)
 358#define TV_STANDARD             (TV_NTSC | TV_PAL | TV_PALM | TV_PALN | TV_NTSCJ)
 359#define TV_INTERFACE            (TV_AVIDEO|TV_SVIDEO|TV_SCART|TV_HIVISION|TV_YPBPR)
 360
 361/* Only if TV_YPBPR is set: */
 362#define TV_YPBPR525I		TV_NTSC
 363#define TV_YPBPR525P		TV_PAL
 364#define TV_YPBPR750P		TV_PALM
 365#define TV_YPBPR1080I	        TV_PALN
 366#define TV_YPBPRALL 		(TV_YPBPR525I | TV_YPBPR525P | TV_YPBPR750P | TV_YPBPR1080I)
 367
 368#define TV_YPBPR43LB		TV_CHSCART
 369#define TV_YPBPR43		TV_CHYPBPR525I
 370#define TV_YPBPR169 		(TV_CHSCART | TV_CHYPBPR525I)
 371#define TV_YPBPRAR              (TV_CHSCART | TV_CHYPBPR525I)
 372
 373
 374#define DISPTYPE_DISP2		CRT2_ENABLE
 375#define DISPTYPE_DISP1		DISPTYPE_CRT1
 376#define VB_DISPMODE_SINGLE	SINGLE_MODE  	/* alias */
 377#define VB_DISPMODE_MIRROR	MIRROR_MODE  	/* alias */
 378#define VB_DISPMODE_DUAL	DUALVIEW_MODE 	/* alias */
 379#define DISPLAY_MODE            (SINGLE_MODE | MIRROR_MODE | DUALVIEW_MODE)
 380
 381/* PresetMode argument */
 382#define XGI_MODE_SIMU 		0
 383#define XGI_MODE_CRT1 		1
 384#define XGI_MODE_CRT2 		2
 385
 386/* pXGI->MiscFlags */
 387#define MISC_CRT1OVERLAY	0x00000001  /* Current display mode supports overlay */
 388#define MISC_PANELLINKSCALER    0x00000002  /* Panel link is currently scaling */
 389#define MISC_CRT1OVERLAYGAMMA	0x00000004  /* Current display mode supports overlay gamma corr on CRT1 */
 390#define MISC_TVNTSC1024		0x00000008  /* Current display mode is TV NTSC/PALM/YPBPR525I 1024x768  */
 391
 392
 393#define HW_DEVICE_EXTENSION	XGI_HW_DEVICE_INFO
 394
 395#define BITMASK(h,l)             (((unsigned)(1U << ((h)-(l)+1))-1)<<(l))
 396#define GENMASK(mask)            BITMASK(1?mask,0?mask)
 397
 398typedef unsigned long ULong;
 399typedef unsigned short UShort;
 400typedef unsigned char UChar;
 401
 402
 403/* ChipFlags */
 404/* Use only lower 16 bit for chip id! (xgictrl) */
 405#define XGICF_LARGEOVERLAY  0x00000001
 406#define XGICF_Is651         0x00000002
 407#define XGICF_IsM650        0x00000004
 408#define XGICF_IsM652        0x00000008
 409#define XGICF_IsM653        0x00000010
 410#define XGICF_Is652         0x00000020
 411#define XGICF_Is65x         (XGICF_Is651|XGICF_IsM650|XGICF_IsM652|XGICF_IsM653|XGICF_Is652)
 412#define XGICF_IsM661        0x00000100  /* M661FX */
 413#define XGICF_IsM741        0x00000200
 414#define XGICF_IsM760        0x00000400
 415#define XGICF_IsM661M       0x00000800  /* M661MX */
 416#define XGICF_IsM66x        (XGICF_IsM661 | XGICF_IsM741 | XGICF_IsM760 | XGICF_IsM661M)
 417#define XGICF_315Core       0x00010000  /* 3D: Real 315 */
 418#define XGICF_Real256ECore  0x00020000  /* 3D: Similar to 315 core, no T&L? (65x, 661, 740, 741) */
 419#define XGICF_XabreCore     0x00040000  /* 3D: Real Xabre */
 420#define XGICF_Ultra256Core  0x00080000  /* 3D: Similar to Xabre, no T&L?, no P:Shader? (660, 760) */
 421#define XGICF_UseLCDA       0x01000000
 422#define XGICF_760UMA        0x10000000  /* 760: UMA active */
 423#define XGICF_CRT2HWCKaputt 0x20000000  /* CRT2 Mono HWCursor engine buggy */
 424#define XGICF_Glamour3      0x40000000
 425#define XGICF_Integrated    0x80000000
 426
 427/* Direct Xv-API */
 428#define XGI_SD_IS300SERIES     0x00000001
 429#define XGI_SD_IS315SERIES     0x00000002
 430#define XGI_SD_IS330SERIES     0x00000004
 431#define XGI_SD_SUPPORTPALMN    0x00000008   /* tv chip supports pal-m, pal-n */
 432#define XGI_SD_SUPPORT2OVL     0x00000010   /* set = 2 overlays, clear = support SWITCHCRT xv prop */
 433#define XGI_SD_SUPPORTTVPOS    0x00000020   /* supports changing tv position */
 434#define XGI_SD_ISDUALHEAD      0x00000040   /* Driver is in dual head mode */
 435#define XGI_SD_ISMERGEDFB      0x00000080   /* Driver is in merged fb mode */
 436#define XGI_SD_ISDHSECONDHEAD  0x00000100   /* Dual head: This is CRT1 (=second head) */
 437#define XGI_SD_ISDHXINERAMA    0x00000200   /* Dual head: We are running Xinerama */
 438#define XGI_SD_VBHASSCART      0x00000400   /* videobridge has SCART instead of VGA2 */
 439#define XGI_SD_ISDEPTH8        0x00000800   /* Depth is 8, no independent gamma correction */
 440#define XGI_SD_ENABLED         0x00002000   /* xgictrl is enabled (by option) */
 441#define XGI_SD_PSEUDOXINERAMA  0x00004000   /* pseudo xinerama is active */
 442#define XGI_SD_SUPPORTLCDA     0x00008000   /* Support LCD Channel A */
 443#define XGI_SD_SUPPORTNTSCJ    0x00010000   /* tv chip supports ntsc-j */
 444#define XGI_SD_ADDLSUPFLAG     0x00020000   /* 1 = the following flags are valid */
 445#define XGI_SD_SUPPORTVGA2     0x00040000   /* CRT2=VGA supported */
 446#define XGI_SD_SUPPORTSCART    0x00080000   /* CRT2=SCART supported */
 447#define XGI_SD_SUPPORTOVERSCAN 0x00100000   /* Overscan flag supported */
 448#define XGI_SD_SUPPORTXVGAMMA1 0x00200000   /* Xv Gamma correction for CRT1 supported */
 449#define XGI_SD_SUPPORTTV       0x00400000   /* CRT2=TV supported */
 450#define XGI_SD_SUPPORTYPBPR    0x00800000   /* CRT2=YPbPr (525i, 525p, 750p, 1080i) is supported */
 451#define XGI_SD_SUPPORTHIVISION 0x01000000   /* CRT2=HiVision is supported */
 452#define XGI_SD_SUPPORTYPBPRAR  0x02000000   /* YPbPr aspect ratio is supported */
 453#define XGI_SD_SUPPORTSCALE    0x04000000   /* Scaling of LCD panel supported */
 454#define XGI_SD_SUPPORTCENTER   0x08000000   /* If scaling supported: Centering of screen [NOT] supported (TMDS only) */
 455
 456#define XGI_DIRECTKEY         0x03145792
 457
 458/* XGICtrl: Check mode for CRT2 */
 459#define XGI_CF2_LCD          0x01
 460#define XGI_CF2_TV           0x02
 461#define XGI_CF2_VGA2         0x04
 462#define XGI_CF2_TVPAL        0x08
 463#define XGI_CF2_TVNTSC       0x10  /* + NTSC-J */
 464#define XGI_CF2_TVPALM       0x20
 465#define XGI_CF2_TVPALN       0x40
 466#define XGI_CF2_CRT1LCDA     0x80
 467#define XGI_CF2_TYPEMASK     (XGI_CF2_LCD | XGI_CF2_TV | XGI_CF2_VGA2 | XGI_CF2_CRT1LCDA)
 468#define XGI_CF2_TVSPECIAL    (XGI_CF2_LCD | XGI_CF2_TV)
 469#define XGI_CF2_TVSPECMASK   (XGI_CF2_TVPAL | XGI_CF2_TVNTSC | XGI_CF2_TVPALM | XGI_CF2_TVPALN)
 470#define XGI_CF2_TVHIVISION   XGI_CF2_TVPAL
 471#define XGI_CF2_TVYPBPR525I  XGI_CF2_TVNTSC
 472#define XGI_CF2_TVYPBPR525P  (XGI_CF2_TVPAL | XGI_CF2_TVNTSC)
 473#define XGI_CF2_TVYPBPR750P  XGI_CF2_TVPALM
 474#define XGI_CF2_TVYPBPR1080I (XGI_CF2_TVPALM | XGI_CF2_TVPAL)
 475
 476/* AGP stuff for DRI */
 477#define AGP_PAGE_SIZE 4096
 478#define AGP_PAGES     2048	 /* Default: 2048 pages @ 4096 = 8MB */
 479/* 300 */
 480#define AGP_CMDBUF_PAGES 256
 481#define AGP_CMDBUF_SIZE (AGP_PAGE_SIZE * AGP_CMDBUF_PAGES)
 482/* 315/330 */
 483#define AGP_VTXBUF_PAGES 512
 484#define AGP_VTXBUF_SIZE (AGP_PAGE_SIZE * AGP_VTXBUF_PAGES)
 485
 486#define VOLARI_CQSIZE   (1024*1024)
 487#define VOLARI_CQSIZEXG20   (128*1024)
 488#define VOLARI_CURSOR_SHAPE_SIZE   (64*64*4)
 489
 490/* For backup of register contents */
 491typedef struct {
 492    unsigned char xgiRegs3C4[0x50];
 493    unsigned char xgiRegs3D4[0x90];
 494    unsigned char xgiRegs3C2;
 495    unsigned char xgiCapt[0x60];
 496    unsigned char xgiVid[0x50];
 497    unsigned char VBPart1[0x50];
 498    unsigned char VBPart2[0x100];
 499    unsigned char VBPart3[0x50];
 500    unsigned char VBPart4[0x50];
 501    unsigned short ch70xx[64];
 502    unsigned long xgiMMIO85C0;
 503    unsigned char xgi6326tv[0x46];
 504    unsigned long xgiRegsPCI50, xgiRegsPCIA0;
 505} XGIRegRec, *XGIRegPtr;
 506
 507
 508/* XGIFBLayout is mainly there because of DGA. It holds the
 509 * current layout parameters needed for acceleration and other
 510 * stuff. When switching mode using DGA, these are set up
 511 * accordingly and not necessarily match pScrn's. Therefore,
 512 * driver modules should read these values instead of pScrn's.
 513 */
 514typedef struct {
 515    int                bitsPerPixel;   	/* = pScrn->bitsPerPixel */
 516    int                depth;		/* = pScrn->depth */
 517    int                displayWidth;	/* = pScrn->displayWidth */
 518    DisplayModePtr     mode;		/* = pScrn->currentMode */
 519} XGIFBLayout;
 520
 521/* Dual head private entity structure */
 522typedef struct {
 523    ScrnInfoPtr         pScrn_1;
 524    ScrnInfoPtr         pScrn_2;
 525    unsigned char *     BIOS;
 526    VB_DEVICE_INFO     *XGI_Pr;
 527    int 		CRT2ModeNo;		/* Current display mode for CRT2 */
 528    Bool		CRT2ModeSet;		/* CRT2 mode has been set */
 529    unsigned char	CRT2CR30, CRT2CR31, CRT2CR35, CRT2CR38;
 530    int			refCount;
 531    
 532    /**
 533     * Number of entities
 534     *
 535     * \bug
 536     * This field is tested in one place, but it doesn't appear to ever be
 537     * set or modified.
 538     */
 539    int 		lastInstance;
 540
 541    Bool		DisableDual;		/* Emergency flag */
 542    Bool		ErrorAfterFirst;	/* Emergency flag: Error after first init -> Abort second */
 543    int                 maxUsedClock;  		/* Max used pixelclock on master head */
 544    
 545    /**
 546     * Framebuffer addresses and sizes
 547     *
 548     * \bug
 549     * These 4 fields are set, but the stored values don't appear to be used.
 550     */
 551    unsigned long       masterFbAddress;
 552    unsigned long	masterFbSize;
 553    unsigned long       slaveFbAddress;
 554    unsigned long	slaveFbSize;
 555
 556    unsigned char *     FbBase;         	/* VRAM linear address */
 557    unsigned char *     IOBase;         	/* MMIO linear address */
 558
 559    /**
 560     * Map / unmap queue counter.
 561     *
 562     * \bug
 563     * These vales are tested, set to zero, or decremented.  However, I don't
 564     * see anywhere in the code where they are incremented.
 565     */
 566    unsigned short      MapCountIOBase;
 567    unsigned short      MapCountFbBase;
 568
 569    Bool 		forceUnmapIOBase;	/* ignore counter and unmap */
 570    Bool		forceUnmapFbBase;	/* ignore counter and unmap */
 571#ifdef __alpha__
 572    unsigned char *     IOBaseDense;    	/* MMIO for Alpha platform */
 573    unsigned short      MapCountIOBaseDense;
 574    Bool		forceUnmapIOBaseDense;  /* ignore counter and unmap */
 575#endif
 576    BOOLEAN		CRT1gamma;
 577    
 578    /**
 579     * \bug This field is tested and set to \c NULL but never used.
 580     */
 581    unsigned char       *RenderAccelArray;
 582    unsigned char *	FbBase1;
 583    unsigned long	OnScreenSize1;
 584
 585#ifdef XGI_CP
 586    XGI_CP_H_ENT
 587#endif
 588} XGIEntRec, *XGIEntPtr;
 589
 590#define XGIPTR(p)       ((XGIPtr)((p)->driverPrivate))
 591#define XAAPTR(p)       ((XAAInfoRecPtr)(XGIPTR(p)->AccelInfoPtr))
 592
 593#define ExtRegSize    0x40
 594
 595
 596/* Relative merge position */
 597typedef enum {
 598   xgiLeftOf,
 599   xgiRightOf,
 600   xgiAbove,
 601   xgiBelow,
 602   xgiClone
 603} XGIScrn2Rel;
 604
 605typedef struct MonitorRange {
 606	float loH,hiH,loV,hiV ;
 607}MonitorRangeRec,*MonitorRangePtr ; 
 608
 609typedef struct {
 610    ScrnInfoPtr         pScrn;		/* -------------- DON'T INSERT ANYTHING HERE --------------- */
 611#ifdef XSERVER_LIBPCIACCESS
 612    struct pci_device * PciInfo;
 613#else 
 614    pciVideoPtr         PciInfo;	/* -------- OTHERWISE xgi_dri.so MUST BE RECOMPILED -------- */
 615    PCITAG              PciTag;
 616#endif
 617    EntityInfoPtr       pEnt;
 618    int                 Chipset;
 619    int                 ChipRev;
 620    VB_DEVICE_INFO     *XGI_Pr;         /* For new mode switching code */
 621    unsigned long       FbAddress;      /* VRAM physical address (in DHM: for each Fb!) */
 622    unsigned long       realFbAddress;  /* For DHM/PCI mem mapping: store global FBAddress */
 623    unsigned char *     FbBase;         /* VRAM virtual linear address */
 624    CARD32              IOAddress;      /* MMIO physical address */
 625    unsigned char *     IOBase;         /* MMIO linear address */
 626    unsigned long           IODBase;        /* Base of PIO memory area */
 627#ifdef __alpha__
 628    unsigned char *     IOBaseDense;    /* MMIO for Alpha platform */
 629#endif
 630    XGIIOADDRESS        RelIO;          /* Relocated IO Ports baseaddress */
 631    unsigned char *     BIOS;
 632    int                 MemClock;
 633    int                 BusWidth;
 634    int                 MinClock;
 635    int                 MaxClock;
 636    int                 Flags;          /* HW config flags */
 637    long                FbMapSize;	/* Used for Mem Mapping - DON'T CHANGE THIS */
 638    long                availMem;       /* Really available Fb mem (minus TQ, HWCursor) */
 639    unsigned long	maxxfbmem;      /* limit fb memory X is to use to this (KB) */
 640    unsigned long       xgifbMem;       /* heapstart of xgifb (if running) */
 641    unsigned long	dhmOffset;	/* Offset to memory for each head (0 or ..) */
 642    DGAModePtr          DGAModes;
 643    int                 numDGAModes;
 644    Bool                DGAactive;
 645    Bool                NoAccel;
 646    Bool				useEXA;  /* Jong 01/13/2009; support EXA */
 647    Bool                NoXvideo;
 648    Bool                TurboQueue;
 649    int                 ForceCRT1Type;
 650    int                 ForceCRT2Type;
 651    int                 OptROMUsage;
 652    Bool                ValidWidth;
 653    unsigned char       myCR63;
 654    unsigned long   	VBFlags;		/* Video bridge configuration */
 655    unsigned long       VBFlags_backup;         /* Backup for SlaveMode-modes */
 656    
 657    short               scrnOffset;		/* Screen pitch (data) */
 658    short               scrnPitch;		/* Screen pitch (display; regarding interlace) */
 659    unsigned long       DstColor;
 660    int                 xcurrent;               /* for temp use in accel */
 661    int                 ycurrent;               /* for temp use in accel */
 662    int                 CommandReg;
 663
 664    Bool                HWCursor;
 665    CARD16		        CursorSize;  		/* Size of HWCursor area (bytes) */
 666    xf86CursorInfoPtr   CursorInfoPtr;
 667    unsigned            CursorOffset;
 668
 669    /**
 670     * \bug This field is set to \c FALSE but never used.
 671     */
 672    Bool                DoColorExpand;
 673
 674    XGIRegRec           SavedReg;
 675    XGIRegRec           ModeReg;
 676
 677#ifdef XGI_USE_XAA
 678    XAAInfoRecPtr       AccelInfoPtr;
 679#endif
 680#ifdef XGI_USE_EXA /* Jong 01/13/2009; support EXA */
 681    ExaDriverPtr		EXADriverPtr;
 682    int			fillPitch, fillBpp;
 683    CARD32		fillDstBase;
 684    int			copyBpp;
 685    int			copySPitch, copyDPitch;
 686    CARD32		copySrcBase, copyDstBase;
 687    int			copyXdir, copyYdir;
 688    ExaOffscreenArea*	exa_scratch;
 689    unsigned int 		exa_scratch_next;
 690#endif
 691
 692    CloseScreenProcPtr  CloseScreen;
 693    Bool        	(*ModeInit)(ScrnInfoPtr pScrn, DisplayModePtr mode);
 694    void        	(*XGISave)(ScrnInfoPtr pScrn, XGIRegPtr xgireg);
 695    void        	(*XGISave2)(ScrnInfoPtr pScrn, XGIRegPtr xgireg);
 696    void        	(*XGISave3)(ScrnInfoPtr pScrn, XGIRegPtr xgireg);
 697    void        	(*XGIRestore)(ScrnInfoPtr pScrn, XGIRegPtr xgireg);
 698    void        	(*XGIRestore2)(ScrnInfoPtr pScrn, XGIRegPtr xgireg);
 699    void        	(*XGIRestore3)(ScrnInfoPtr pScrn, XGIRegPtr xgireg);
 700    void        	(*LoadCRT2Palette)(ScrnInfoPtr pScrn, int numColors,
 701                		int *indicies, LOCO *colors, VisualPtr pVisual);
 702
 703    int       		cmdQueueLen;		/* Current cmdQueueLength (for 2D and 3D) */
 704    unsigned long	cmdQueueLenMax;
 705    unsigned long	cmdQueueLenMin;
 706    unsigned char	*cmdQueueBase;
 707    int			*cmdQueueLenPtr;	/* Ptr to variable holding the current queue length */
 708    unsigned int        cmdQueueOffset;
 709    unsigned int        cmdQueueSize;
 710    unsigned long       cmdQueueSizeMask;
 711
 712    /**
 713     * \bug This field is set but never used.
 714     */
 715    unsigned int        agpWantedPages;
 716
 717#ifdef XF86DRI
 718    unsigned long 	agpHandle;
 719    unsigned long	agpAddr;
 720    unsigned char 	*agpBase;
 721    unsigned int 	agpSize;
 722    unsigned long	agpVtxBufAddr;	/* 315 series */
 723    unsigned char       *agpVtxBufBase;
 724    unsigned int        agpVtxBufSize;
 725    unsigned int        agpVtxBufFree;
 726    xgiRegion 		agp;
 727    Bool 		irqEnabled;
 728    int 		irq;
 729#endif
 730    unsigned long	DRIheapstart, DRIheapend;
 731
 732    void		(*RenderCallback)(ScrnInfoPtr);
 733
 734    /**
 735     * \bug This field is tested and set to \c NULL but never used.
 736     */
 737    unsigned char       *RenderAccelArray;
 738
 739    /**
 740     * \bug This field is to \c TRUE but never used.
 741     */
 742    Bool		doRender;
 743
 744    int 		PerColorExpandBufferSize;
 745    int 		ColorExpandBufferNumber;
 746    unsigned char 	*ColorExpandBufferAddr[32];
 747    int 		ColorExpandBufferScreenOffset[32];
 748
 749    /**
 750     * \bug This field is read but never initialized.
 751     */
 752    int 		ImageWriteBufferSize;
 753
 754    unsigned char 	*ImageWriteBufferAddr;
 755
 756    int 		Rotate;
 757
 758    BOOLEAN		HaveCustomModes; /* Jong 07/27/2009; support customer modes */
 759
 760    /* ShadowFB support */
 761    Bool 		ShadowFB;
 762    unsigned char 	*ShadowPtr;
 763    int  		ShadowPitch;
 764
 765    /**
 766     * \bug This field is set but never used.
 767     */
 768    Bool		loadDRI;
 769
 770#ifdef XF86DRI
 771    Bool 		directRenderingEnabled;
 772    DRIInfoPtr 		pDRIInfo;
 773    int 		drmSubFD;
 774    int 		numVisualConfigs;
 775    __GLXvisualConfig* 	pVisualConfigs;
 776    XGIConfigPrivPtr 	pVisualConfigsPriv;
 777#endif
 778
 779    HW_DEVICE_EXTENSION xgi_HwDevExt;      /* For new mode switching code */
 780    XF86VideoAdaptorPtr adaptor;
 781    ScreenBlockHandlerProcPtr BlockHandler;
 782
 783    /**
 784     * \bug This field is tested and used but never set.
 785     */
 786    void                (*VideoTimerCallback)(ScrnInfoPtr, Time);
 787
 788    void		(*ResetXv)(ScrnInfoPtr);
 789    void		(*ResetXvGamma)(ScrnInfoPtr);
 790
 791    OptionInfoPtr 	Options;
 792
 793    /**
 794     * \bug This field is used but never initialized.
 795     */
 796    unsigned char 	LCDon;
 797    Bool 		Blank;
 798    int 		CRT1off;		/* 1=CRT1 off, 0=CRT1 on */
 799    CARD16 		LCDheight;		/* Vertical resolution of LCD panel */
 800    CARD16 		LCDwidth;		/* Horizontal resolution of LCD panel */
 801    vbeInfoPtr 		pVbe;			/* For VESA mode switching */
 802    UCHAR ScratchSet[16];
 803    MonitorRangeRec CRT1Range,CRT2Range;
 804
 805#ifdef XGIDUALHEAD
 806    BOOL 		DualHeadMode;		/* TRUE if we use dual head mode */
 807    BOOL 		SecondHead;		/* TRUE is this is the second head */
 808    XGIEntPtr 		entityPrivate;		/* Ptr to private entity (see above) */
 809#endif
 810    XGIFBLayout         CurrentLayout;		/* Current framebuffer layout */
 811    BOOL		Primary;		/* Display adapter is primary */
 812    xf86Int10InfoPtr    pInt;			/* Our int10 */
 813    
 814    /**
 815     * Use our own default modes? 
 816     *
 817     * \bug This field is set but never used.
 818     */
 819    Bool		noInternalModes;
 820
 821    int			ForceTVType, SenseYPbPr;
 822    int                 NonDefaultPAL, NonDefaultNTSC;
 823    unsigned long	ForceYPbPrType, ForceYPbPrAR;
 824    unsigned long       lockcalls;		/* Count unlock calls for debug */
 825
 826    Atom                xvBrightness, xvContrast, xvColorKey, xvHue, xvSaturation;
 827    Atom                xvAutopaintColorKey, xvSetDefaults, xvSwitchCRT;
 828    Atom		xvDisableGfx, xvDisableGfxLR, xvTVXPosition, xvTVYPosition;
 829    Atom		xvDisableColorkey, xvUseChromakey, xvChromaMin, xvChromaMax;
 830    Atom		xvInsideChromakey, xvYUVChromakey;
 831    Atom		xvGammaRed, xvGammaGreen, xvGammaBlue;
 832#ifdef XGI_CP
 833    XGI_CP_H
 834#endif
 835    unsigned long       ChipFlags;
 836    unsigned long       XGI_SD_Flags;
 837    BOOLEAN		UseHWARGBCursor;
 838    BOOLEAN		HWARGBCursor;
 839    int                 vb;
 840    BOOLEAN		restorebyset;
 841    BOOLEAN		nocrt2ddcdetection;
 842    BOOLEAN		forcecrt2redetection;
 843    BOOLEAN		CRT1gamma, CRT1gammaGiven, CRT2gamma, XvGamma, XvGammaGiven;
 844    int			XvDefCon, XvDefBri, XvDefHue, XvDefSat;
 845    BOOLEAN		XvDefDisableGfx, XvDefDisableGfxLR;
 846    BOOLEAN		XvUseMemcpy;
 847    int			XvGammaRed, XvGammaGreen, XvGammaBlue;
 848    CARD8		XvGammaRampRed[256], XvGammaRampGreen[256], XvGammaRampBlue[256];
 849    BOOLEAN		disablecolorkeycurrent;
 850    CARD32		colorKey;
 851    CARD32		MiscFlags;
 852
 853#ifdef XGI_USE_XAA
 854    FBLinearPtr		AccelLinearScratch;
 855#endif
 856
 857    float		zClearVal;
 858    unsigned long	bClrColor, dwColor;
 859    int			AllowHotkey;
 860    BOOLEAN		enablexgictrl;
 861    short		Video_MaxWidth, Video_MaxHeight;
 862    short               scrnPitch2;
 863    int	                CurXPreset ;
 864    int                 CurYPreset ;
 865    unsigned long	mmioSize;
 866#ifdef XGIMERGED
 867    Bool		MergedFB, MergedFBAuto;
 868    XGIScrn2Rel		CRT2Position;
 869    char *		CRT2HSync;
 870    char *		CRT2VRefresh;
 871    char *		MetaModes;
 872    ScrnInfoPtr		CRT2pScrn;
 873    DisplayModePtr	CRT1Modes;
 874    DisplayModePtr	CRT1CurrentMode;
 875    int			CRT1frameX0;
 876    int			CRT1frameY0;
 877    int			CRT1frameX1;
 878    int			CRT1frameY1;
 879    Bool		CheckForCRT2;
 880    int			MergedFBXDPI, MergedFBYDPI;
 881#ifdef XGIXINERAMA
 882    Bool		UsexgiXinerama;
 883    Bool		CRT2IsScrn0;
 884    ExtensionEntry 	*XineramaExtEntry;
 885    int			xgiXineramaVX, xgiXineramaVY;
 886    Bool		AtLeastOneNonClone;
 887#endif
 888#endif
 889
 890    /* Added for 3D */
 891    unsigned long        cmdQueue_shareWP_only2D;
 892    unsigned long        *pCQ_shareWritePort;
 893    void                (*SetThreshold)(ScrnInfoPtr pScrn, DisplayModePtr mode,
 894                                        unsigned short *Low, unsigned short *High);
 895
 896    XGI_DSReg           SRList[ExtRegSize] ;
 897    XGI_DSReg           CRList[ExtRegSize] ;
 898    
 899    /**
 900     * Total number of iterations to wait in \c Volari_Idle.
 901     */
 902    unsigned int        idle_wait_count;
 903
 904//:::: for capture
 905    Bool		v4l_videoin;
 906    int			v4l_devnum;	/* v4l device number, 0,1,2....*/
 907//~::::    
 908
 909	int			TargetRefreshRate; 
 910	Bool		IgnoreDDC; 
 911
 912	Bool		Non_DDC_DefaultMode;
 913	int			Non_DDC_DefaultResolutionX ;
 914	int			Non_DDC_DefaultResolutionY ;
 915	int			Non_DDC_DefaultRefreshRate ;
 916} XGIRec, *XGIPtr;
 917
 918#ifdef XGIDUALHEAD
 919# define IS_DUAL_HEAD(x)      ((x)->DualHeadMode)
 920# define IS_SECOND_HEAD(x)    ((x)->SecondHead)
 921# define ENTITY_PRIVATE(x)    ((x)->entityPrivate)
 922#else
 923# define IS_DUAL_HEAD(x)      FALSE
 924# define IS_SECOND_HEAD(x)    FALSE
 925# define ENTITY_PRIVATE(x)    NULL
 926#endif
 927
 928
 929#define SEQ_ADDRESS_PORT  0x0014
 930#define MISC_OUTPUT_REG_WRITE_PORT  0x0012
 931#define MISC_OUTPUT_REG_READ_PORT   0x001C
 932#define GRAPH_ADDRESS_PORT  0x001E
 933#define VIDEO_SUBSYSTEM_ENABLE_PORT 0x0013
 934#define CRTC_ADDRESS_PORT_COLOR  0x0024
 935#define PCI_COMMAND  0x04
 936
 937#define SDMPTR(x) ((XGIMergedDisplayModePtr)(x->currentMode->Private))
 938#define CDMPTR    ((XGIMergedDisplayModePtr)(pXGI->CurrentLayout.mode->Private))
 939
 940#define BOUND(test,low,hi) { \
 941    if(test < low) test = low; \
 942    if(test > hi) test = hi; }
 943
 944#define REBOUND(low,hi,test) { \
 945    if(test < low) { \
 946        hi += test-low; \
 947        low = test; } \
 948    if(test > hi) { \
 949        low += test-hi; \
 950        hi = test; } }
 951
 952typedef struct _MergedDisplayModeRec {
 953    DisplayModePtr CRT1;
 954    DisplayModePtr CRT2;
 955    XGIScrn2Rel    CRT2Position;
 956} XGIMergedDisplayModeRec, *XGIMergedDisplayModePtr;
 957
 958
 959typedef struct _region {
 960    int x0,x1,y0,y1;
 961} region;
 962
 963
 964extern void  xgiOptions(ScrnInfoPtr pScrn);
 965extern const OptionInfoRec * XGIAvailableOptions(int chipid, int busid);
 966extern void  XGISetup(ScrnInfoPtr pScrn);
 967extern void  XGIVGAPreInit(ScrnInfoPtr pScrn);
 968extern Bool  XGIAccelInit(ScreenPtr pScreen);
 969extern Bool  XGIHWCursorInit(ScreenPtr pScreen);
 970extern Bool  XGIDGAInit(ScreenPtr pScreen);
 971extern void  XGIInitVideo(ScreenPtr pScreen);
 972
 973extern int   XGI_GetCHTVlumabandwidthcvbs(ScrnInfoPtr pScrn);
 974
 975int    XG40Mclk(XGIPtr pXGI);
 976
 977void XGINew_InitVBIOSData(PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo) ;
 978int compute_vclk(int Clock, int *out_n, int *out_dn, int *out_div,
 979                 int *out_sbit, int *out_scale);
 980
 981void XGI_WaitBeginRetrace(XGIIOADDRESS RelIO);
 982void XGI_WaitEndRetrace(XGIIOADDRESS RelIO);
 983
 984#include <unistd.h>
 985/* 2005/11/21 added by jjtseng */
 986#define DelayS(sec) usleep((sec)*1000000)
 987#define DelayMS(millisec) usleep((millisec)*1000)
 988#define DelayUS(microsec) usleep((microsec))
 989/*~jjtseng 2005/11/21 */
 990
 991Bool Volari_AccelInit(ScreenPtr pScreen) ;
 992/* void XGI_UnLockCRT2(PXGI_HW_DEVICE_INFO,USHORT BaseAddr); */
 993/* void XGI_LockCRT2(PXGI_HW_DEVICE_INFO,USHORT BaseAddr); */
 994/* void XGI_DisableBridge(PXGI_HW_DEVICE_INFO,USHORT BaseAddr); */
 995/* void XGI_EnableBridge(PXGI_HW_DEVICE_INFO,USHORT BaseAddr); */
 996#endif
 997
 998extern USHORT XGI_GetModeID(ULONG VBFlags, int HDisplay, int VDisplay,
 999    int Depth, int LCDwith, int LCDheight);
1000
1001extern BOOLEAN XGI_SearchModeID(const XGI_StStruct *SModeIDTable, 
1002    const XGI_ExtStruct *EModeIDTable, unsigned char VGAINFO,
1003    USHORT *ModeNo, USHORT *ModeIdIndex);
1004
1005extern UCHAR XGI_GetModePtr(const XGI_StStruct *SModeIDTable,
1006    unsigned ModeType, USHORT ModeNo, USHORT ModeIdIndex);
1007
1008extern void XGI_SetReg(XGIIOADDRESS port, USHORT index, USHORT data);
1009extern void XGI_SetRegByte(XGIIOADDRESS port, USHORT data);
1010extern void XGI_SetRegShort(XGIIOADDRESS port, USHORT data);
1011extern void XGI_SetRegLong(XGIIOADDRESS port, ULONG data);
1012extern UCHAR XGI_GetReg(XGIIOADDRESS port, USHORT index);
1013extern UCHAR XGI_GetRegByte(XGIIOADDRESS port);
1014extern USHORT XGI_GetRegShort(XGIIOADDRESS port);
1015extern ULONG XGI_GetRegLong(XGIIOADDRESS port);
1016extern void XGI_SetRegANDOR(XGIIOADDRESS Port, USHORT Index, USHORT DataAND,
1017			    USHORT DataOR);
1018extern void XGI_SetRegAND(XGIIOADDRESS Port, USHORT Index, USHORT DataAND);
1019extern void XGI_SetRegOR(XGIIOADDRESS Port, USHORT Index, USHORT DataOR);
1020
1021#define uint8_t	CARD8
1022extern void XGI_WriteDAC(XGIIOADDRESS dac_data, unsigned shift,
1023    unsigned ordering, uint8_t red, uint8_t green, uint8_t blue);
1024
1025#ifdef DEBUG
1026void XGIDumpRegs(ScrnInfoPtr pScrn);
1027
1028/**
1029 * Write value to the PC's 0x80 debug port.
1030 * 
1031 * \bug
1032 * I'm pretty sure the debug 0x80 only exists on PCs.  Should this routine
1033 * be a no-op on non-x86 and non-x86-64 architectures?
1034 */
1035#define Newdebugcode(dbg_code) outb(0x80, dbg_code)
1036#else
1037#define Newdebugcode(dbg_code)
1038#endif