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