mga.h revision 0bb88ba4
1/*
2 * MGA Millennium (MGA2064W) functions
3 *
4 * Copyright 1996 The XFree86 Project, Inc.
5 *
6 * Authors
7 *		Dirk Hohndel
8 *			hohndel@XFree86.Org
9 *		David Dawes
10 *			dawes@XFree86.Org
11 */
12
13#ifndef MGA_H
14#define MGA_H
15
16#ifdef XSERVER_LIBPCIACCESS
17#include <pciaccess.h>
18#endif
19#include <string.h>
20#include <stdio.h>
21
22#include "compiler.h"
23#ifdef HAVE_XAA_H
24#include "xaa.h"
25#endif
26#include "xf86fbman.h"
27#include "exa.h"
28#include "xf86Cursor.h"
29#include "vgaHW.h"
30#include "colormapst.h"
31#include "xf86DDC.h"
32#include "xf86xv.h"
33
34#ifndef XF86DRI
35#undef MGADRI
36#endif
37
38#ifdef MGADRI
39#include "xf86drm.h"
40
41#define _XF86DRI_SERVER_
42#include "mga_dripriv.h"
43#include "dri.h"
44#include "GL/glxint.h"
45
46#include "dri.h"
47
48#include "GL/glxint.h"
49#include "mga_dri.h"
50#endif
51
52#include "compat-api.h"
53
54typedef enum {
55    OPTION_SW_CURSOR,
56    OPTION_HW_CURSOR,
57    OPTION_PCI_RETRY,
58    OPTION_SYNC_ON_GREEN,
59    OPTION_NOACCEL,
60    OPTION_SHOWCACHE,
61    OPTION_OVERLAY,
62    OPTION_MGA_SDRAM,
63    OPTION_SHADOW_FB,
64    OPTION_FBDEV,
65    OPTION_COLOR_KEY,
66    OPTION_SET_MCLK,
67    OPTION_OVERCLOCK_MEM,
68    OPTION_VIDEO_KEY,
69    OPTION_ROTATE,
70    OPTION_TEXTURED_VIDEO,
71    OPTION_CRTC2HALF,
72    OPTION_CRTC2RAM,
73    OPTION_INT10,
74    OPTION_AGP_MODE,
75    OPTION_AGP_SIZE,
76    OPTION_DIGITAL1,
77    OPTION_DIGITAL2,
78    OPTION_TV,
79    OPTION_TVSTANDARD,
80    OPTION_CABLETYPE,
81    OPTION_USEIRQZERO,
82    OPTION_NOHAL,
83    OPTION_SWAPPED_HEAD,
84    OPTION_DRI,
85    OPTION_MERGEDFB,
86    OPTION_HSYNC2,
87    OPTION_VREFRESH2,
88    OPTION_MONITOR2POS,
89    OPTION_METAMODES,
90    OPTION_OLDDMA,
91    OPTION_PCIDMA,
92    OPTION_ACCELMETHOD,
93    OPTION_KVM
94} MGAOpts;
95
96
97#if !defined(EXTRADEBUG)
98#define INREG8(addr) MMIO_IN8(pMga->IOBase, addr)
99#define INREG16(addr) MMIO_IN16(pMga->IOBase, addr)
100#define INREG(addr) MMIO_IN32(pMga->IOBase, addr)
101#define OUTREG8(addr, val) MMIO_OUT8(pMga->IOBase, addr, val)
102#define OUTREG16(addr, val) MMIO_OUT16(pMga->IOBase, addr, val)
103#define OUTREG(addr, val) MMIO_OUT32(pMga->IOBase, addr, val)
104#else /* !EXTRADEBUG */
105CARD8 MGAdbg_inreg8(ScrnInfoPtr, int, int, char*);
106CARD16 MGAdbg_inreg16(ScrnInfoPtr, int, int, char*);
107CARD32 MGAdbg_inreg32(ScrnInfoPtr, int, int, char*);
108void MGAdbg_outreg8(ScrnInfoPtr, int, int, char*);
109void MGAdbg_outreg16(ScrnInfoPtr, int,int, char*);
110void MGAdbg_outreg32(ScrnInfoPtr, int,int, char*);
111#ifndef __GNUC__
112# define MGA_STRINGIZE(x) #x
113# define MGA_STRINGIFY(x) MGA_STRINGIZE(x)
114# define __FUNCTION__ MGA_STRINGIFY(__FILE__) ", line " MGA_STRINGIFY(__LINE__)
115#endif
116#define INREG8(addr) MGAdbg_inreg8(pScrn, addr, 1, __FUNCTION__)
117#define INREG16(addr) MGAdbg_inreg16(pScrn, addr, 1, __FUNCTION__)
118#define INREG(addr) MGAdbg_inreg32(pScrn, addr, 1, __FUNCTION__)
119#define OUTREG8(addr,val) MGAdbg_outreg8(pScrn, addr, val, __FUNCTION__)
120#define OUTREG16(addr,val) MGAdbg_outreg16(pScrn, addr, val, __FUNCTION__)
121#define OUTREG(addr,val) MGAdbg_outreg32(pScrn, addr, val, __FUNCTION__)
122#endif /* EXTRADEBUG */
123
124/*
125 * PCI vendor/device ids, formerly in xf86PciInfo.h
126 */
127
128#define PCI_VENDOR_MATROX               0x102B
129
130#define PCI_CHIP_MGA2085                0x0518
131#define PCI_CHIP_MGA2064                0x0519
132#define PCI_CHIP_MGA1064                0x051A
133#define PCI_CHIP_MGA2164                0x051B
134#define PCI_CHIP_MGA2164_AGP            0x051F
135
136#define PCI_CHIP_MGAG100_PCI            0x1000
137#define PCI_CHIP_MGAG100                0x1001
138#define PCI_CHIP_MGAG200_PCI            0x0520
139#define PCI_CHIP_MGAG200                0x0521
140#define PCI_CHIP_MGAG200_SE_A_PCI       0x0522
141#define PCI_CHIP_MGAG200_SE_B_PCI       0x0524
142#define PCI_CHIP_MGAG200_WINBOND_PCI    0x0532
143#define PCI_CHIP_MGAG200_EV_PCI         0x0530
144#define PCI_CHIP_MGAG200_EH_PCI         0x0533
145#define PCI_CHIP_MGAG200_ER_PCI         0x0534
146#define PCI_CHIP_MGAG400                0x0525
147#define PCI_CHIP_MGAG550                0x2527
148
149/*
150 * Read/write to the DAC via MMIO
151 */
152
153/*
154 * These were functions.  Use macros instead to avoid the need to
155 * pass pMga to them.
156 */
157
158#define inMGAdreg(reg) INREG8(RAMDAC_OFFSET + (reg))
159
160#define outMGAdreg(reg, val) OUTREG8(RAMDAC_OFFSET + (reg), val)
161
162#define inMGAdac(reg) \
163	(outMGAdreg(MGA1064_INDEX, reg), inMGAdreg(MGA1064_DATA))
164
165#define outMGAdac(reg, val) \
166	(outMGAdreg(MGA1064_INDEX, reg), outMGAdreg(MGA1064_DATA, val))
167
168#define outMGAdacmsk(reg, mask, val) \
169	do { /* note: mask and reg may get evaluated twice */ \
170	    unsigned char tmp = (mask) ? (inMGAdac(reg) & (mask)) : 0; \
171	    outMGAdreg(MGA1064_INDEX, reg); \
172	    outMGAdreg(MGA1064_DATA, tmp | (val)); \
173	} while (0)
174
175#define MGAWAITVSYNC() \
176    do { \
177	unsigned int count = 0; \
178    	unsigned int status = 0; \
179	do { \
180	    status = INREG( MGAREG_Status ); \
181	    count++; \
182    	} while( ( status & 0x08 ) && (count < 250000) );\
183	count = 0; \
184    	status = 0; \
185	do { \
186	    status = INREG( MGAREG_Status ); \
187	    count++; \
188    	} while( !( status & 0x08 ) && (count < 250000) );\
189    } while (0)
190
191#define MGAWAITBUSY() \
192    do { \
193    	unsigned int count = 0; \
194	unsigned int status = 0; \
195    	do { \
196    	    status = INREG8( MGAREG_Status + 2 ); \
197	    count++; \
198    	} while( ( status & 0x01 ) && (count < 500000) ); \
199    } while (0)
200
201#define PORT_OFFSET 	(0x1F00 - 0x300)
202
203#define MGA_VERSION 4000
204#define MGA_NAME "MGA"
205#define MGA_C_NAME MGA
206#define MGA_MODULE_DATA mgaModuleData
207#define MGA_DRIVER_NAME "mga"
208
209typedef struct {
210    unsigned char	ExtVga[6];
211    unsigned char 	DacClk[6];
212    unsigned char	ExtVga_Index24;
213    unsigned char	Dac_Index90;
214    unsigned char * DacRegs;
215    unsigned long	crtc2[0x58];
216    unsigned char	dac2[0x21];
217    CARD32		Option;
218    CARD32		Option2;
219    CARD32		Option3;
220    long                Clock;
221    Bool                PIXPLLCSaved;
222    unsigned char       PllM;
223    unsigned char       PllN;
224    unsigned char       PllP;
225} MGARegRec, *MGARegPtr;
226
227/* For programming the second CRTC */
228typedef struct {
229   CARD32   ulDispWidth;        /* Display Width in pixels*/
230   CARD32   ulDispHeight;       /* Display Height in pixels*/
231   CARD32   ulBpp;              /* Bits Per Pixels / input format*/
232   CARD32   ulPixClock;         /* Pixel Clock in kHz*/
233   CARD32   ulHFPorch;          /* Horizontal front porch in pixels*/
234   CARD32   ulHSync;            /* Horizontal Sync in pixels*/
235   CARD32   ulHBPorch;          /* Horizontal back porch in pixels*/
236   CARD32   ulVFPorch;          /* Vertical front porch in lines*/
237   CARD32   ulVSync;            /* Vertical Sync in lines*/
238   CARD32   ulVBPorch;          /* Vertical back Porch in lines*/
239   CARD32   ulFBPitch;          /* Pitch*/
240   CARD32   flSignalMode;       /* Signal Mode*/
241} xMODEINFO;
242
243
244typedef struct {
245   int          brightness;
246   int          contrast;
247   Bool         doubleBuffer;
248   unsigned char currentBuffer;
249   RegionRec	clip;
250   CARD32	colorKey;
251   CARD32	videoStatus;
252   Time		offTime;
253   Time		freeTime;
254   int		lastPort;
255
256#ifdef USE_EXA
257   int              size;
258   ExaOffscreenArea *off_screen;
259#endif
260
261   void         *video_memory;
262   int           video_offset;
263} MGAPortPrivRec, *MGAPortPrivPtr;
264
265typedef struct {
266    Bool	isHwCursor;
267    int		CursorMaxWidth;
268    int 	CursorMaxHeight;
269    int		CursorFlags;
270    int		CursorOffscreenMemSize;
271    Bool	(*UseHWCursor)(ScreenPtr, CursorPtr);
272    void	(*LoadCursorImage)(ScrnInfoPtr, unsigned char*);
273    void	(*ShowCursor)(ScrnInfoPtr);
274    void	(*HideCursor)(ScrnInfoPtr);
275    void	(*SetCursorPosition)(ScrnInfoPtr, int, int);
276    void	(*SetCursorColors)(ScrnInfoPtr, int, int);
277    long	maxPixelClock;
278    long	MemoryClock;
279    MessageType ClockFrom;
280    MessageType MemClkFrom;
281    Bool	SetMemClk;
282    void	(*LoadPalette)(ScrnInfoPtr, int, int*, LOCO*, VisualPtr);
283    void	(*RestorePalette)(ScrnInfoPtr, unsigned char *);
284    void	(*PreInit)(ScrnInfoPtr);
285    void	(*Save)(ScrnInfoPtr, vgaRegPtr, MGARegPtr, Bool);
286    void	(*Restore)(ScrnInfoPtr, vgaRegPtr, MGARegPtr, Bool);
287    Bool	(*ModeInit)(ScrnInfoPtr, DisplayModePtr);
288} MGARamdacRec, *MGARamdacPtr;
289
290
291typedef struct {
292    int bitsPerPixel;
293    int depth;
294    int displayWidth;
295    rgb weight;
296    DisplayModePtr mode;
297} MGAFBLayout;
298
299/* Card-specific driver information */
300
301typedef struct {
302    Bool update;
303    unsigned char red;
304    unsigned char green;
305    unsigned char blue;
306} MGAPaletteInfo;
307
308#define MGAPTR(p) ((MGAPtr)((p)->driverPrivate))
309
310/*avoids segfault by returning false if pMgaHwInfo not defined*/
311#define ISDIGITAL1(p) (p->pMgaHwInfo && ((p->pMgaHwInfo->ulCapsFirstOutput) & MGAHWINFOCAPS_OUTPUT_DIGITAL))
312#define ISDIGITAL2(p) (p->pMgaHwInfo && ((p->pMgaHwInfo->ulCapsSecondOutput) & MGAHWINFOCAPS_OUTPUT_DIGITAL))
313#define ISTV1(p) (p->pMgaHwInfo && ((p->pMgaHwInfo->ulCapsFirstOutput) & MGAHWINFOCAPS_OUTPUT_TV))
314#define ISTV2(p) (p->pMgaHwInfo && ((p->pMgaHwInfo->ulCapsSecondOutput) & MGAHWINFOCAPS_OUTPUT_TV))
315
316#ifdef DISABLE_VGA_IO
317typedef struct mgaSave {
318#ifdef XSERVER_LIBPCIACCESS
319    struct pci_device * pvp;
320#else
321    pciVideoPtr pvp;
322#endif
323    Bool enable;
324} MgaSave, *MgaSavePtr;
325#endif
326
327
328typedef enum {
329    mgaLeftOf,
330    mgaRightOf,
331    mgaAbove,
332    mgaBelow,
333    mgaClone
334} MgaScrn2Rel;
335
336typedef struct {
337    int			lastInstance;
338    int			refCount;
339    CARD32		masterFbAddress;
340    long		masterFbMapSize;
341    CARD32		slaveFbAddress;
342    long		slaveFbMapSize;
343    int			mastervideoRam;
344    int			slavevideoRam;
345    Bool		directRenderingEnabled;
346    ScrnInfoPtr 	pScrn_1;
347    ScrnInfoPtr 	pScrn_2;
348} MGAEntRec, *MGAEntPtr;
349
350/**
351 * Track the range of a voltage controlled osciliator (VCO).
352 */
353struct mga_VCO {
354    /**
355     * Minimum selectable frequency for this VCO, measured in kHz.
356     */
357    unsigned min_freq;
358
359    /**
360     * Maximum selectable frequency for this VCO, measured in kHz.
361     *
362     * If this value is zero, then the VCO is not available.
363     */
364    unsigned max_freq;
365};
366
367/**
368 * Host interface types that can be set by the card's BIOS.
369 */
370typedef enum {
371    MGA_HOST_UNKNOWN0 = 0,  /**< Meaning unknown. */
372    MGA_HOST_UNKNOWN1 = 1,  /**< Meaning unknown. */
373    MGA_HOST_UNKNOWN2 = 2,  /**< Meaning unknown. */
374    MGA_HOST_HYBRID = 3,    /**< AGP 4x for data xfers only. */
375
376    /**
377     * PCI interface.  Either native or via a universal PCI-to-PCI bridge
378     * chip.  The PCI G450 and PCI G550 cards are examples.
379     */
380    MGA_HOST_PCI = 4,
381
382    MGA_HOST_AGP_1x = 5,    /**< AGP 1x capable. */
383    MGA_HOST_AGP_2x = 6,    /**< AGP 2x capable. */
384    MGA_HOST_AGP_4x = 7     /**< AGP 4x capable. */
385} mga_host_t;
386
387/**
388 * Card information derrived from BIOS PInS data.
389 */
390struct mga_bios_values {
391    /**
392     * \name Voltage Controlled Oscilators
393     * \brief Track information about the various VCOs.
394     *
395     * MGA cards have between one and three VCOs that can be used to drive the
396     * various clocks.  On older cards, only \c mga_bios_values::pixel VCO is
397     * available.  On newer cards, such as the G450 and G550, all three are
398     * available.  If \c mga_VCO::max_freq is zero, the VCO is not available.
399     */
400    /*@{*/
401    struct mga_VCO   system;    /**< System VCO. */
402    struct mga_VCO   pixel;     /**< Pixel VCO. */
403    struct mga_VCO   video;     /**< Video VCO. */
404    /*@}*/
405
406    /**
407     * Memory clock speed, measured in kHz.
408     */
409    unsigned mem_clock;
410
411    /**
412     * PLL reference frequency value.  On older cards this is ~14MHz, and on
413     * newer cards it is ~27MHz.
414     */
415    unsigned pll_ref_freq;
416
417    /**
418     * Some older MGA cards have a "fast bitblt" mode.  This is determined
419     * by a capability bit stored in the PInS data.
420     */
421    Bool fast_bitblt;
422
423    /**
424     * Type of physical interface used for the card.
425     */
426    mga_host_t host_interface;
427};
428
429
430/**
431 * Attributes that of an MGA device that can be derrived purely from its
432 * PCI ID.
433 */
434struct mga_device_attributes {
435    unsigned has_sdram:1;
436    unsigned probe_for_sdram:1;
437    unsigned dual_head_possible:1;
438    unsigned fb_4mb_quirk:1;
439    unsigned hwcursor_1064:1;
440
441    unsigned dri_capable:1;
442    unsigned dri_chipset:3;
443
444    unsigned HAL_chipset:1;
445
446    enum {
447	old_BARs = 0,
448	probe_BARs,
449	new_BARs
450    } BARs:2;
451
452    uint32_t accel_flags;
453
454    /** Default BIOS values. */
455    struct mga_bios_values default_bios_values;
456
457    /** Default memory probe offset / size values. */
458    unsigned probe_size;
459    unsigned probe_offset;
460};
461
462typedef struct {
463    EntityInfoPtr	pEnt;
464    struct mga_bios_values bios;
465    CARD8               BiosOutputMode;
466#ifdef XSERVER_LIBPCIACCESS
467    struct pci_device *	PciInfo;
468#else
469    pciVideoPtr		PciInfo;
470    PCITAG		PciTag;
471    xf86AccessRec	Access;
472#endif
473    const struct mga_device_attributes * chip_attribs;
474    int			Chipset;
475    int                 ChipRev;
476
477    int is_Gx50:1;
478    int is_G200SE:1;
479    int is_G200WB:1;
480    int is_G200EV:1;
481    int is_G200EH:1;
482    int is_G200ER:1;
483
484    int KVM;
485
486    CARD32		reg_1e24;   /* model revision on g200se */
487
488    Bool		Primary;
489    Bool		Interleave;
490    int			HwBpp;
491    int			Roundings[4];
492    int			BppShifts[4];
493    Bool		HasFBitBlt;
494    Bool		OverclockMem;
495    int			YDstOrg;
496    int			DstOrg;
497    int			SrcOrg;
498
499    /**
500     * Which BAR corresponds to the framebuffer on this chip?
501     */
502    unsigned            framebuffer_bar;
503
504    /**
505     * Which BAR corresponds to IO space on this chip?
506     */
507    unsigned            io_bar;
508
509    /**
510     * Which BAR corresponds to ILOAD space on this chip?  If the value is
511     * -1, then this chip does not have an ILOAD region.
512     */
513    int                 iload_bar;
514
515#ifndef XSERVER_LIBPCIACCESS
516    unsigned long	IOAddress;
517    unsigned long	ILOADAddress;
518    unsigned long	BiosAddress;
519    MessageType		BiosFrom;
520#endif
521    unsigned long	FbAddress;
522    unsigned char *     IOBase;
523    unsigned char *	FbBase;
524    unsigned char *	ILOADBase;
525    unsigned char *	FbStart;
526    long		FbMapSize;
527    long		FbUsableSize;
528    long		FbCursorOffset;
529    MGARamdacRec	Dac;
530    Bool		HasSDRAM;
531    Bool		NoAccel;
532    Bool		Exa;
533    ExaDriverPtr 	ExaDriver;
534    Bool		SyncOnGreen;
535    Bool		HWCursor;
536    Bool		UsePCIRetry;
537    Bool		ShowCache;
538    Bool		ShadowFB;
539    unsigned char *	ShadowPtr;
540    int			ShadowPitch;
541    int			MemClk;
542    int			MinClock;
543    int			MaxClock;
544    MGARegRec		SavedReg;
545    MGARegRec		ModeReg;
546    int			MaxFastBlitY;
547    CARD32		BltScanDirection;
548    CARD32		FilledRectCMD;
549    CARD32		SolidLineCMD;
550    CARD32		PatternRectCMD;
551    CARD32		DashCMD;
552    CARD32		NiceDashCMD;
553    CARD32		AccelFlags;
554    CARD32		PlaneMask;
555    CARD32		FgColor;
556    CARD32		BgColor;
557    CARD32		MAccess;
558    int			FifoSize;
559    int			StyleLen;
560#ifdef HAVE_XAA_H
561    XAAInfoRecPtr	AccelInfoRec;
562#endif
563    xf86CursorInfoPtr	CursorInfoRec;
564    DGAModePtr		DGAModes;
565    int			numDGAModes;
566    Bool		DGAactive;
567    int			DGAViewportStatus;
568    CARD32		*Atype;
569    CARD32		*AtypeNoBLK;
570    void		(*PreInit)(ScrnInfoPtr pScrn);
571    void		(*Save)(ScrnInfoPtr, vgaRegPtr, MGARegPtr, Bool);
572    void		(*Restore)(ScrnInfoPtr, vgaRegPtr, MGARegPtr, Bool);
573    Bool		(*ModeInit)(ScrnInfoPtr, DisplayModePtr);
574    void		(*PointerMoved)(SCRN_ARG_TYPE arg, int x, int y);
575    CloseScreenProcPtr	CloseScreen;
576    ScreenBlockHandlerProcPtr BlockHandler;
577    unsigned int	(*ddc1Read)(ScrnInfoPtr);
578    void (*DDC1SetSpeed)(ScrnInfoPtr, xf86ddcSpeed);
579    Bool		(*i2cInit)(ScrnInfoPtr);
580    I2CBusPtr		DDC_Bus1;
581    I2CBusPtr		DDC_Bus2;
582    I2CBusPtr		Maven_Bus;
583    I2CDevPtr		Maven;
584    char		Maven_Version;
585    Bool		UseMaven;
586    Bool		UseMavenPM;
587    Bool		FBDev;
588    int			colorKey;
589    int			videoKey;
590    int			fifoCount;
591    int			Rotate;
592    MGAFBLayout		CurrentLayout;
593    Bool		DrawTransparent;
594    int			MaxBlitDWORDS;
595    Bool		TexturedVideo;
596    MGAPortPrivPtr	portPrivate;
597    unsigned char	*ScratchBuffer;
598    unsigned char	*ColorExpandBase;
599    int			expandRows;
600    int			expandDWORDs;
601    int			expandRemaining;
602    int			expandHeight;
603    int			expandY;
604#ifdef MGADRI
605    Bool 		directRenderingEnabled;
606    DRIInfoPtr 		pDRIInfo;
607    int 		drmFD;
608    int 		numVisualConfigs;
609    __GLXvisualConfig*	pVisualConfigs;
610    MGAConfigPrivPtr 	pVisualConfigsPriv;
611    MGADRIServerPrivatePtr DRIServerInfo;
612
613    MGARegRec		DRContextRegs;
614
615    Bool		haveQuiescense;
616    void		(*GetQuiescence)(ScrnInfoPtr pScrn);
617
618    int 		agpMode;
619    int                 agpSize;
620
621    int                 irq;
622    CARD32              reg_ien;
623
624    Bool                useOldDmaInit;
625    Bool                forcePciDma;
626#endif
627    XF86VideoAdaptorPtr adaptor;
628    Bool		DualHeadEnabled;
629    Bool		Crtc2IsTV;
630    Bool		SecondCrtc;
631    Bool                SecondOutput;
632
633    GDevPtr		device;
634    /* The hardware's real SrcOrg */
635    int			realSrcOrg;
636    MGAEntPtr		entityPrivate;
637    void		(*SetupForSolidFill)(ScrnInfoPtr pScrn, int color,
638					     int rop, unsigned int planemask);
639    void		(*SubsequentSolidFillRect)(ScrnInfoPtr pScrn,
640					     int x, int y, int w, int h);
641    void		(*RestoreAccelState)(ScrnInfoPtr pScrn);
642    int			allowedWidth;
643    void		(*VideoTimerCallback)(ScrnInfoPtr, Time);
644    void		(*PaletteLoadCallback)(ScrnInfoPtr);
645    void		(*RenderCallback)(ScrnInfoPtr);
646    Time		RenderTime;
647    MGAPaletteInfo	palinfo[256];  /* G400 hardware bug workaround */
648    FBLinearPtr		LinearScratch;
649    Bool                softbooted;
650    OptionInfoPtr	Options;
651
652    /* Exa */
653    PicturePtr currentSrcPicture;
654    PicturePtr currentMaskPicture;
655    PixmapPtr currentSrc;
656    PixmapPtr currentMask;
657    int src_w2;
658    int src_h2;
659    int mask_w2;
660    int mask_h2;
661    CARD32 src_pitch; /* FIXME kill me */
662
663/* Merged Framebuffer data */
664    Bool                MergedFB;
665
666    /* Real values specific to monitor1, since the original ones are replaced */
667    DisplayModePtr	M1modes;	 /* list of actual modes */
668    DisplayModePtr	M1currentMode; /* current mode */
669    int			M1frameX0;	/* viewport position */
670    int			M1frameY0;
671    int			M1frameX1;
672    int			M1frameY1;
673
674    ScrnInfoPtr       pScrn2; /*pointer to second CRTC screeninforec,
675                                       if in merged mode */
676/* End of Merged Framebuffer Data */
677  int			HALGranularityOffX, HALGranularityOffY;
678} MGARec, *MGAPtr;
679
680extern CARD32 MGAAtype[16];
681extern CARD32 MGAAtypeNoBLK[16];
682
683#define USE_RECTS_FOR_LINES	0x00000001
684#define FASTBLT_BUG		0x00000002
685#define CLIPPER_ON		0x00000004
686#define BLK_OPAQUE_EXPANSION	0x00000008
687#define TRANSC_SOLID_FILL	0x00000010
688#define	NICE_DASH_PATTERN	0x00000020
689#define	TWO_PASS_COLOR_EXPAND	0x00000040
690#define	MGA_NO_PLANEMASK	0x00000080
691#define USE_LINEAR_EXPANSION	0x00000100
692#define LARGE_ADDRESSES		0x00000200
693
694#define MGAIOMAPSIZE		0x00004000
695#define MGAILOADMAPSIZE		0x00400000
696
697#define TRANSPARENCY_KEY	255
698#define KEY_COLOR		0
699
700
701/* Prototypes */
702
703void MGAAdjustFrame(ADJUST_FRAME_ARGS_DECL);
704Bool MGASwitchMode(SWITCH_MODE_ARGS_DECL);
705void MGAFillModeInfoStruct(ScrnInfoPtr pScrn, DisplayModePtr mode);
706Bool MGAGetRec(ScrnInfoPtr pScrn);
707void MGAProbeDDC(ScrnInfoPtr pScrn, int index);
708void MGASoftReset(ScrnInfoPtr pScrn);
709void MGAFreeRec(ScrnInfoPtr pScrn);
710Bool mga_read_and_process_bios(ScrnInfoPtr pScrn);
711void MGADisplayPowerManagementSet(ScrnInfoPtr pScrn, int PowerManagementMode,
712				  int flags);
713void MGAAdjustFrameCrtc2(ADJUST_FRAME_ARGS_DECL);
714void MGADisplayPowerManagementSetCrtc2(ScrnInfoPtr pScrn,
715					     int PowerManagementMode,
716					     int flags);
717void MGAAdjustGranularity(ScrnInfoPtr pScrn, int* x, int* y);
718
719
720void MGA2064SetupFuncs(ScrnInfoPtr pScrn);
721void MGAGSetupFuncs(ScrnInfoPtr pScrn);
722
723/*#ifdef USE_XAA */
724void MGAStormSync(ScrnInfoPtr pScrn);
725void MGAStormEngineInit(ScrnInfoPtr pScrn);
726Bool MGAStormAccelInit(ScreenPtr pScreen);
727Bool mgaAccelInit(ScreenPtr pScreen);
728/* #endif */
729
730#ifdef USE_EXA
731Bool mgaExaInit(ScreenPtr pScreen);
732#endif
733
734Bool MGAHWCursorInit(ScreenPtr pScreen);
735
736
737void MGAPolyArcThinSolid(DrawablePtr, GCPtr, int, xArc*);
738
739Bool MGADGAInit(ScreenPtr pScreen);
740
741void MGARefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
742void MGARefreshArea8(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
743void MGARefreshArea16(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
744void MGARefreshArea24(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
745void MGARefreshArea32(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
746
747void mgaDoSetupForScreenToScreenCopy( ScrnInfoPtr pScrn, int xdir,
748    int ydir, int rop, unsigned int planemask, int trans, unsigned int bpp );
749
750void mgaDoSetupForSolidFill( ScrnInfoPtr pScrn, int color, int rop,
751    unsigned int planemask, unsigned int bpp );
752
753void MGAPointerMoved(SCRN_ARG_TYPE arg, int x, int y);
754
755void MGAInitVideo(ScreenPtr pScreen);
756void MGAResetVideo(ScrnInfoPtr pScrn);
757
758#ifdef MGADRI
759
760#define MGA_FRONT	0x1
761#define MGA_BACK	0x2
762#define MGA_DEPTH	0x4
763
764Bool MGADRIScreenInit( ScreenPtr pScreen );
765void MGADRICloseScreen( ScreenPtr pScreen );
766Bool MGADRIFinishScreenInit( ScreenPtr pScreen );
767
768Bool MGALockUpdate( ScrnInfoPtr pScrn, drmLockFlags flags );
769
770void MGAGetQuiescence( ScrnInfoPtr pScrn );
771void MGAGetQuiescenceShared( ScrnInfoPtr pScrn );
772
773void MGASelectBuffer(ScrnInfoPtr pScrn, int which);
774Bool MgaCleanupDma(ScrnInfoPtr pScrn);
775Bool MgaInitDma(ScrnInfoPtr pScrn, int prim_size);
776
777#define MGA_AGP_1X_MODE		0x01
778#define MGA_AGP_2X_MODE		0x02
779#define MGA_AGP_4X_MODE		0x04
780#define MGA_AGP_MODE_MASK	0x07
781
782#endif
783
784Bool MGAMavenRead(ScrnInfoPtr pScrn, I2CByte reg, I2CByte *val);
785
786void MGACRTC2Set(ScrnInfoPtr pScrn, xMODEINFO *pModeInfo);
787void MGAEnableSecondOutPut(ScrnInfoPtr pScrn, xMODEINFO *pModeInfo);
788void MGACRTC2SetPitch(ScrnInfoPtr pSrcn, xMODEINFO *pModeInfo);
789void MGACRTC2SetDisplayStart(ScrnInfoPtr pScrn, xMODEINFO *pModeInfo, CARD32 base, CARD32 ulX, CARD32 ulY);
790
791void MGACRTC2Get(ScrnInfoPtr pScrn, xMODEINFO *pModeInfo);
792void MGACRTC2GetPitch(ScrnInfoPtr pSrcn, xMODEINFO *pModeInfo);
793void MGACRTC2GetDisplayStart(ScrnInfoPtr pScrn, xMODEINFO *pModeInfo, CARD32 base, CARD32 ulX, CARD32 ulY);
794
795double MGAG450SetPLLFreq(ScrnInfoPtr pScrn, long f_out);
796#ifdef DEBUG
797void MGAG450PrintPLL(ScrnInfoPtr pScrn);
798#endif
799long MGAG450SavePLLFreq(ScrnInfoPtr pScrn);
800void MGAprintDac(ScrnInfoPtr pScrn);
801void MGAG200SESaveFonts(ScrnInfoPtr, vgaRegPtr);
802void MGAG200SERestoreFonts(ScrnInfoPtr, vgaRegPtr);
803void MGAG200SESaveMode(ScrnInfoPtr, vgaRegPtr);
804void MGAG200SERestoreMode(ScrnInfoPtr, vgaRegPtr);
805void MGAG200SEHWProtect(ScrnInfoPtr, Bool);
806
807static __inline__ void
808MGA_MARK_SYNC(MGAPtr pMga, ScrnInfoPtr pScrn)
809{
810#ifdef USE_EXA
811    if (pMga->Exa)
812        exaMarkSync(pScrn->pScreen);
813#endif
814#ifdef USE_XAA
815    if (!pMga->Exa)
816        SET_SYNC_FLAG(pMga->AccelInfoRec);
817#endif
818}
819
820static __inline__ void
821MGA_SYNC(MGAPtr pMga, ScrnInfoPtr pScrn)
822{
823#ifdef USE_EXA
824    if (pMga->Exa)
825        exaWaitSync(pScrn->pScreen);
826#endif
827#ifdef USE_XAA
828    if (!pMga->Exa && pMga->AccelInfoRec && pMga->AccelInfoRec->NeedToSync)
829        pMga->AccelInfoRec->Sync(pScrn);
830#endif
831}
832
833#endif
834