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