apm.h revision 17a48c7c
117a48c7cSmrg/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/apm/apm.h,v 1.19tsi Exp $ */
217a48c7cSmrg
317a48c7cSmrg#include <string.h>
417a48c7cSmrg
517a48c7cSmrg/* All drivers should typically include these */
617a48c7cSmrg#include "xf86.h"
717a48c7cSmrg#include "xf86_OSproc.h"
817a48c7cSmrg
917a48c7cSmrg/* All drivers need this */
1017a48c7cSmrg
1117a48c7cSmrg/* Everything using inb/outb, etc needs "compiler.h" */
1217a48c7cSmrg#include "compiler.h"
1317a48c7cSmrg
1417a48c7cSmrg/* This is used for module versioning */
1517a48c7cSmrg#include "xf86Version.h"
1617a48c7cSmrg
1717a48c7cSmrg/* Drivers for PCI hardware need this */
1817a48c7cSmrg#include "xf86PciInfo.h"
1917a48c7cSmrg
2017a48c7cSmrg/* Drivers that need to access the PCI config space directly need this */
2117a48c7cSmrg#include "xf86Pci.h"
2217a48c7cSmrg
2317a48c7cSmrg/* All drivers using the vgahw module need this */
2417a48c7cSmrg#include "vgaHW.h"
2517a48c7cSmrg
2617a48c7cSmrg/* Drivers using the mi banking wrapper need this */
2717a48c7cSmrg#include "mibank.h"
2817a48c7cSmrg
2917a48c7cSmrg/* All drivers using the mi colormap manipulation need this */
3017a48c7cSmrg#include "micmap.h"
3117a48c7cSmrg
3217a48c7cSmrg/* Needed for the 1 and 4 bpp framebuffers */
3317a48c7cSmrg#include "xf1bpp.h"
3417a48c7cSmrg#include "xf4bpp.h"
3517a48c7cSmrg
3617a48c7cSmrg#include "fb.h"
3717a48c7cSmrg
3817a48c7cSmrg/* Drivers using the XAA interface ... */
3917a48c7cSmrg#include "xaa.h"
4017a48c7cSmrg#include "xaalocal.h"
4117a48c7cSmrg#include "xf86Cursor.h"
4217a48c7cSmrg#include "xf86fbman.h"
4317a48c7cSmrg
4417a48c7cSmrg/* All drivers initialising the SW cursor need this */
4517a48c7cSmrg#include "mipointer.h"
4617a48c7cSmrg
4717a48c7cSmrg/* All drivers implementing backing store need this */
4817a48c7cSmrg#include "mibstore.h"
4917a48c7cSmrg
5017a48c7cSmrg/* I2C support */
5117a48c7cSmrg#include "xf86i2c.h"
5217a48c7cSmrg
5317a48c7cSmrg/* DDC support */
5417a48c7cSmrg#include "xf86DDC.h"
5517a48c7cSmrg
5617a48c7cSmrg#include "xf86xv.h"
5717a48c7cSmrg#include <X11/extensions/Xv.h>
5817a48c7cSmrg
5917a48c7cSmrg#ifdef TRUE
6017a48c7cSmrg#undef TRUE
6117a48c7cSmrg#endif
6217a48c7cSmrg#define TRUE	(1)
6317a48c7cSmrg
6417a48c7cSmrg#define rdinx(port, ind)	(outb((port), (ind)), inb((port) + 1))
6517a48c7cSmrg#define wrinx(port, ind, val)	outb((port), (ind)),  outb((port) + 1, (val))
6617a48c7cSmrg#define modinx(port, ind, mask, bits)					\
6717a48c7cSmrg    do {								\
6817a48c7cSmrg	unsigned char tmp;						\
6917a48c7cSmrg	tmp = (rdinx((port), (ind)) & ~(mask)) | ((bits) & (mask));	\
7017a48c7cSmrg	wrinx((port), (ind), tmp);					\
7117a48c7cSmrg    } while(0)
7217a48c7cSmrg
7317a48c7cSmrgtypedef unsigned char	u8;
7417a48c7cSmrgtypedef unsigned short	u16;
7517a48c7cSmrgtypedef unsigned long	u32;
7617a48c7cSmrg
7717a48c7cSmrg#define NoSEQRegs	0x20
7817a48c7cSmrg#define NoCRTRegs	0x1F
7917a48c7cSmrg#define NoGRCRegs	0x09
8017a48c7cSmrg#define	NoATCRegs	0x15
8117a48c7cSmrg
8217a48c7cSmrgenum {
8317a48c7cSmrg    XR80, XRC0, XRD0, XRE0, XRE8, XREC, XR140, XR144, XR148, XR14C, NoEXRegs
8417a48c7cSmrg};
8517a48c7cSmrg
8617a48c7cSmrgtypedef struct {
8717a48c7cSmrg	unsigned char	SEQ[NoSEQRegs];
8817a48c7cSmrg	unsigned char	CRT[NoCRTRegs];
8917a48c7cSmrg	unsigned char	GRC[NoGRCRegs];
9017a48c7cSmrg	unsigned char	ATC[NoATCRegs];
9117a48c7cSmrg	unsigned int	EX[NoEXRegs];
9217a48c7cSmrg} ApmRegStr, *ApmRegPtr;
9317a48c7cSmrg
9417a48c7cSmrgtypedef struct {
9517a48c7cSmrg    int			displayWidth, displayHeight;
9617a48c7cSmrg    int			bitsPerPixel, bytesPerScanline;
9717a48c7cSmrg    int			depth, Scanlines;
9817a48c7cSmrg    CARD32		mask32;		/* Mask to have 32bit aligned data */
9917a48c7cSmrg    unsigned int	Setup_DEC;
10017a48c7cSmrg    DisplayModePtr	pMode;
10117a48c7cSmrg} ApmFBLayout;
10217a48c7cSmrg
10317a48c7cSmrg#define APM_CACHE_NUMBER	32
10417a48c7cSmrg
10517a48c7cSmrgtypedef struct {
10617a48c7cSmrg    pciVideoPtr		PciInfo;
10717a48c7cSmrg    PCITAG		PciTag;
10817a48c7cSmrg    int			scrnIndex;
10917a48c7cSmrg    int			Chipset;
11017a48c7cSmrg    int			ChipRev;
11117a48c7cSmrg    CARD32		LinAddress;
11217a48c7cSmrg    unsigned long	LinMapSize;
11317a48c7cSmrg    CARD32		FbMapSize;
11417a48c7cSmrg    pointer		LinMap;
11517a48c7cSmrg    pointer		FbBase;
11617a48c7cSmrg    char		*VGAMap;
11717a48c7cSmrg    char		*MemMap;
11817a48c7cSmrg    pointer		BltMap;
11917a48c7cSmrg    Bool		UnlockCalled;
12017a48c7cSmrg    IOADDRESS		iobase, xport, xbase;
12117a48c7cSmrg    unsigned char	savedSR10;
12217a48c7cSmrg    CARD8		MiscOut;
12317a48c7cSmrg    CARD8		c9, d9, db, Rush;
12417a48c7cSmrg    unsigned long	saveCmd;
12517a48c7cSmrg    pointer		FontInfo;
12617a48c7cSmrg    Bool		hwCursor;
12717a48c7cSmrg    Bool		noLinear;
12817a48c7cSmrg    ApmRegStr		ModeReg, SavedReg;
12917a48c7cSmrg    CloseScreenProcPtr	CloseScreen;
13017a48c7cSmrg    Bool		UsePCIRetry;  /* Do we use PCI-retry or busy-waiting */
13117a48c7cSmrg    Bool		NoAccel;  /* Do we use XAA acceleration architecture */
13217a48c7cSmrg    int			MinClock;                        /* Min ramdac clock */
13317a48c7cSmrg    int			MaxClock;                        /* Max ramdac clock */
13417a48c7cSmrg    ApmFBLayout		CurrentLayout, SavedLayout;
13517a48c7cSmrg    EntityInfoPtr	pEnt;
13617a48c7cSmrg    XAAInfoRecPtr	AccelInfoRec, DGAXAAInfo;
13717a48c7cSmrg    xf86CursorInfoPtr	CursorInfoRec;
13817a48c7cSmrg    int			DGAactive, numDGAModes;
13917a48c7cSmrg    DGAModePtr		DGAModes;
14017a48c7cSmrg    int			BaseCursorAddress,CursorAddress,DisplayedCursorAddress;
14117a48c7cSmrg    int			OffscreenReserved;
14217a48c7cSmrg    int			blitxdir, blitydir;
14317a48c7cSmrg    Bool		apmTransparency, apmClip, ShadowFB, I2C;
14417a48c7cSmrg    int			rop, Bg8x8, Fg8x8;
14517a48c7cSmrg    I2CBusPtr		I2CPtr;
14617a48c7cSmrg    struct ApmStippleCacheRec {
14717a48c7cSmrg	XAACacheInfoRec		apmStippleCache;
14817a48c7cSmrg	FBAreaPtr		area;
14917a48c7cSmrg	unsigned int		apmStippleCached:1;
15017a48c7cSmrg    }			apmCache[APM_CACHE_NUMBER];
15117a48c7cSmrg    int			apmCachePtr;
15217a48c7cSmrg    unsigned char	regcurr[0x54];
15317a48c7cSmrg    ScreenPtr		pScreen;
15417a48c7cSmrg    int			Generation;
15517a48c7cSmrg    int			apmLock, pixelStride, RushY[7], CopyMode;
15617a48c7cSmrg    int			PutImageStride;
15717a48c7cSmrg    Bool		(*DestroyPixmap)(PixmapPtr);
15817a48c7cSmrg    PixmapPtr		(*CreatePixmap)(ScreenPtr, int, int, int);
15917a48c7cSmrg    void (*SetupForSolidFill)(ScrnInfoPtr pScrn, int color, int rop,
16017a48c7cSmrg					unsigned int planemask);
16117a48c7cSmrg    void (*SubsequentSolidFillRect)(ScrnInfoPtr pScrn, int x, int y,
16217a48c7cSmrg				       int w, int h);
16317a48c7cSmrg    void (*SetupForSolidFill24)(ScrnInfoPtr pScrn, int color, int rop,
16417a48c7cSmrg					unsigned int planemask);
16517a48c7cSmrg    void (*SubsequentSolidFillRect24)(ScrnInfoPtr pScrn, int x, int y,
16617a48c7cSmrg				       int w, int h);
16717a48c7cSmrg    void (*SetupForScreenToScreenCopy)(ScrnInfoPtr pScrn, int xdir, int ydir,
16817a48c7cSmrg					  int rop, unsigned int planemask,
16917a48c7cSmrg                                          int transparency_color);
17017a48c7cSmrg    void (*SubsequentScreenToScreenCopy)(ScrnInfoPtr pScrn, int x1, int y1,
17117a48c7cSmrg					    int x2, int y2, int w, int h);
17217a48c7cSmrg    void (*SetupForScreenToScreenCopy24)(ScrnInfoPtr pScrn, int xdir, int ydir,
17317a48c7cSmrg					  int rop, unsigned int planemask,
17417a48c7cSmrg                                          int transparency_color);
17517a48c7cSmrg    void (*SubsequentScreenToScreenCopy24)(ScrnInfoPtr pScrn, int x1, int y1,
17617a48c7cSmrg					    int x2, int y2, int w, int h);
17717a48c7cSmrg    int			MemClk;
17817a48c7cSmrg    unsigned char	*ShadowPtr;
17917a48c7cSmrg    int			ShadowPitch;
18017a48c7cSmrg    memType		ScratchMem, ScratchMemSize, ScratchMemOffset;
18117a48c7cSmrg    memType		ScratchMemPtr, ScratchMemEnd;
18217a48c7cSmrg    int			ScratchMemWidth;
18317a48c7cSmrg    CARD32		color;
18417a48c7cSmrg    XF86VideoAdaptorPtr	adaptor;
18517a48c7cSmrg    int			timerIsOn;
18617a48c7cSmrg    Time		offTime;
18717a48c7cSmrg    OptionInfoPtr	Options;
18817a48c7cSmrg    char		DPMSMask[4];
18917a48c7cSmrg} ApmRec, *ApmPtr;
19017a48c7cSmrg
19117a48c7cSmrg#define curr		((unsigned char *)pApm->regcurr)
19217a48c7cSmrg
19317a48c7cSmrgtypedef struct {
19417a48c7cSmrg    u16		ca;
19517a48c7cSmrg    u8		font;
19617a48c7cSmrg    u8		pad;
19717a48c7cSmrg} ApmFontBuf;
19817a48c7cSmrg
19917a48c7cSmrgtypedef struct {
20017a48c7cSmrg    u16		ca;
20117a48c7cSmrg    u8		font;
20217a48c7cSmrg    u8		pad;
20317a48c7cSmrg    u16		ca2;
20417a48c7cSmrg    u8		font2;
20517a48c7cSmrg    u8		pad2;
20617a48c7cSmrg} ApmTextBuf;
20717a48c7cSmrg
20817a48c7cSmrgenum ApmChipId {
20917a48c7cSmrg    AP6422	= 0x6422,
21017a48c7cSmrg    AT24	= 0x6424,
21117a48c7cSmrg    AT3D	= 0x643D
21217a48c7cSmrg};
21317a48c7cSmrg
21417a48c7cSmrgtypedef struct {
21517a48c7cSmrg    BoxRec			box;
21617a48c7cSmrg    int				num;
21717a48c7cSmrg    MoveAreaCallbackProcPtr	MoveAreaCallback;
21817a48c7cSmrg    RemoveAreaCallbackProcPtr	RemoveAreaCallback;
21917a48c7cSmrg    void			*devPriv;
22017a48c7cSmrg} ApmPixmapRec, *ApmPixmapPtr;
22117a48c7cSmrg
22217a48c7cSmrg#define APMDECL(p)	ApmPtr pApm = ((ApmPtr)(((ScrnInfoPtr)(p))->driverPrivate))
22317a48c7cSmrg#define APMPTR(p)	((ApmPtr)(((ScrnInfoPtr)(p))->driverPrivate))
22417a48c7cSmrg
22517a48c7cSmrgextern int	ApmHWCursorInit(ScreenPtr pScreen);
22617a48c7cSmrgextern int	ApmDGAInit(ScreenPtr pScreen);
22717a48c7cSmrgextern int	ApmAccelInit(ScreenPtr pScreen);
22817a48c7cSmrgextern Bool	ApmI2CInit(ScrnInfoPtr pScrn);
22917a48c7cSmrgextern void	XFree86RushExtensionInit(ScreenPtr pScreen);
23017a48c7cSmrgextern void	ApmInitVideo(ScreenPtr pScreen);
23117a48c7cSmrgextern void	ApmInitVideo_IOP(ScreenPtr pScreen);
23217a48c7cSmrgextern void	ApmSetupXAAInfo(ApmPtr pApm, XAAInfoRecPtr pXAAinfo);
23317a48c7cSmrgextern Bool     ApmSwitchMode(int scrnIndex, DisplayModePtr mode,
23417a48c7cSmrg                                  int flags);
23517a48c7cSmrgextern void     ApmAdjustFrame(int scrnIndex, int x, int y, int flags);
23617a48c7cSmrgextern void	ApmHWCursorReserveSpace(ApmPtr pApm);
23717a48c7cSmrgextern void	ApmAccelReserveSpace(ApmPtr pApm);
23817a48c7cSmrg
23917a48c7cSmrgextern int	ApmPixmapIndex;
24017a48c7cSmrg#define APM_GET_PIXMAP_PRIVATE(pix)\
24117a48c7cSmrg	((ApmPixmapPtr)(((PixmapPtr)(pix))->devPrivates[ApmPixmapIndex].ptr))
24217a48c7cSmrg
24317a48c7cSmrg#include "apm_regs.h"
244