⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 i810_dri.c

📁 是由intel提供的针对intel显卡915以上系列的linux驱动
💻 C
📖 第 1 页 / 共 4 页
字号:
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/i810/i810_dri.c,v 1.41 2003/09/24 02:43:23 dawes Exp $ *//* * Reformatted with GNU indent (2.2.8), using the following options: * *    -bad -bap -c41 -cd0 -ncdb -ci6 -cli0 -cp0 -ncs -d0 -di3 -i3 -ip3 -l78 *    -lp -npcs -psl -sob -ss -br -ce -sc -hnl * * This provides a good match with the original i810 code and preferred * XFree86 formatting conventions. * * When editing this driver, please follow the existing formatting, and edit * with <TAB> characters expanded at 8-column intervals. */#include "xf86.h"#include "xf86_OSproc.h"#include "xf86_ansic.h"#include "xf86Priv.h"#include "xf86PciInfo.h"#include "xf86Pci.h"#include "windowstr.h"#include "shadow.h"#include "shadowfb.h"#include "GL/glxtokens.h"#include "i810.h"#include "i810_dri.h"#include "i830.h"static char I810KernelDriverName[] = "i810";static char I810ClientDriverName[] = "i810";static Bool I810InitVisualConfigs(ScreenPtr pScreen);static Bool I810CreateContext(ScreenPtr pScreen, VisualPtr visual,			      drm_context_t hwContext, void *pVisualConfigPriv,			      DRIContextType contextStore);static void I810DestroyContext(ScreenPtr pScreen, drm_context_t hwContext,			       DRIContextType contextStore);static void I810DRISwapContext(ScreenPtr pScreen, DRISyncType syncType,			       DRIContextType readContextType,			       void *readContextStore,			       DRIContextType writeContextType,			       void *writeContextStore);static void I810DRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index);static void I810DRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg,			       RegionPtr prgnSrc, CARD32 index);static Bool I810DRIOpenFullScreen(ScreenPtr pScreen);static Bool I810DRICloseFullScreen(ScreenPtr pScreen);static void I810EnablePageFlip(ScreenPtr pScreen);static void I810DisablePageFlip(ScreenPtr pScreen);static void I810DRITransitionSingleToMulti3d(ScreenPtr pScreen);static void I810DRITransitionMultiToSingle3d(ScreenPtr pScreen);static void I810DRITransitionTo3d(ScreenPtr pScreen);static void I810DRITransitionTo2d(ScreenPtr pScreen);static void I810DRIRefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox);extern void GlxSetVisualConfigs(int nconfigs,				__GLXvisualConfig * configs,				void **configprivs);static int i810_pitches[] = {   512,   1024,   2048,   4096,   0};static int i810_pitch_flags[] = {   0x0,   0x1,   0x2,   0x3,   0};static unsigned int i810_drm_version = 0;BoolI810CleanupDma(ScrnInfoPtr pScrn){   I810Ptr pI810 = I810PTR(pScrn);   drmI810Init info;   memset(&info, 0, sizeof(drmI810Init));   info.func = I810_CLEANUP_DMA;   if (drmCommandWrite(pI810->drmSubFD, DRM_I810_INIT,		       &info, sizeof(drmI810Init))) {      xf86DrvMsg(pScrn->scrnIndex, X_ERROR,		 "[dri] I810 Dma Cleanup Failed\n");      return FALSE;   }   return TRUE;}BoolI810InitDma(ScrnInfoPtr pScrn){   I810Ptr pI810 = I810PTR(pScrn);   I810RingBuffer *ring = pI810->LpRing;   I810DRIPtr pI810DRI = (I810DRIPtr) pI810->pDRIInfo->devPrivate;   drmI810Init info;   memset(&info, 0, sizeof(drmI810Init));   info.ring_start = ring->mem.Start;   info.ring_end = ring->mem.End;   info.ring_size = ring->mem.Size;   info.mmio_offset = (unsigned int)pI810DRI->regs;   info.buffers_offset = (unsigned int)pI810->buffer_map;   info.sarea_priv_offset = sizeof(XF86DRISAREARec);   info.front_offset = 0;   info.back_offset = pI810->BackBuffer.Start;   info.depth_offset = pI810->DepthBuffer.Start;   info.overlay_offset = pI810->OverlayStart;   info.overlay_physical = pI810->OverlayPhysical;   info.w = pScrn->virtualX;   info.h = pScrn->virtualY;   info.pitch = pI810->auxPitch;   info.pitch_bits = pI810->auxPitchBits;   /* We require DRM v1.2 or greater. Since DRM v1.2 broke compatibility    * we created a new v1.4 that supports a new init function. Eventually the    * old init function will go away. If you change the drm interface, make a    * new init type too so that we can detect the new client.    */   switch(i810_drm_version) {   case ((1<<16) | 0):   case ((1<<16) | 1):   case ((1<<16) | 2):   case ((1<<16) | 3):      /* Use OLD drm < 1.4 init */      info.func = I810_INIT_DMA;      xf86DrvMsg(pScrn->scrnIndex, X_INFO, "[drm] Init PRE v1.4 interface.\n");      break;   default:   case ((1<<16) | 4):      /*  DRM version 1.3 or greater init */      info.func = I810_INIT_DMA_1_4;      xf86DrvMsg(pScrn->scrnIndex, X_INFO, "[drm] Init v1.4 interface.\n");      break;   }   if (drmCommandWrite(pI810->drmSubFD, DRM_I810_INIT,		       &info, sizeof(drmI810Init))) {      xf86DrvMsg(pScrn->scrnIndex, X_ERROR,		 "[drm] I810 Dma Initialization failed.\n");      return FALSE;   }   return TRUE;}static BoolI810InitVisualConfigs(ScreenPtr pScreen){   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];   I810Ptr pI810 = I810PTR(pScrn);   int numConfigs = 0;   __GLXvisualConfig *pConfigs = 0;   I810ConfigPrivPtr pI810Configs = 0;   I810ConfigPrivPtr *pI810ConfigPtrs = 0;   int accum, stencil, db, depth;   int i;   switch (pScrn->bitsPerPixel) {   case 8:   case 24:   case 32:      break;   case 16:      numConfigs = 8;      pConfigs =	    (__GLXvisualConfig *) xcalloc(sizeof(__GLXvisualConfig),					  numConfigs);      if (!pConfigs)	 return FALSE;      pI810Configs =	    (I810ConfigPrivPtr) xcalloc(sizeof(I810ConfigPrivRec),					numConfigs);      if (!pI810Configs) {	 xfree(pConfigs);	 return FALSE;      }      pI810ConfigPtrs =	    (I810ConfigPrivPtr *) xcalloc(sizeof(I810ConfigPrivPtr),					  numConfigs);      if (!pI810ConfigPtrs) {	 xfree(pConfigs);	 xfree(pI810Configs);	 return FALSE;      }      for (i = 0; i < numConfigs; i++)	 pI810ConfigPtrs[i] = &pI810Configs[i];      i = 0;      depth = 1;      for (accum = 0; accum <= 1; accum++) {	 for (stencil = 0; stencil <= 1; stencil++) {	    for (db = 1; db >= 0; db--) {	       pConfigs[i].vid = -1;	       pConfigs[i].class = -1;	       pConfigs[i].rgba = TRUE;	       pConfigs[i].redSize = 5;	       pConfigs[i].greenSize = 6;	       pConfigs[i].blueSize = 5;	       pConfigs[i].redMask = 0x0000F800;	       pConfigs[i].greenMask = 0x000007E0;	       pConfigs[i].blueMask = 0x0000001F;	       pConfigs[i].alphaMask = 0;	       if (accum) {		  pConfigs[i].accumRedSize = 16;		  pConfigs[i].accumGreenSize = 16;		  pConfigs[i].accumBlueSize = 16;		  pConfigs[i].accumAlphaSize = 0;	       } else {		  pConfigs[i].accumRedSize = 0;		  pConfigs[i].accumGreenSize = 0;		  pConfigs[i].accumBlueSize = 0;		  pConfigs[i].accumAlphaSize = 0;	       }	       pConfigs[i].doubleBuffer = db ? TRUE : FALSE;	       pConfigs[i].stereo = FALSE;	       pConfigs[i].bufferSize = 16;	       if (depth)		  pConfigs[i].depthSize = 16;	       else		  pConfigs[i].depthSize = 0;	       if (stencil)		  pConfigs[i].stencilSize = 8;	       else		  pConfigs[i].stencilSize = 0;	       pConfigs[i].auxBuffers = 0;	       pConfigs[i].level = 0;	       if (stencil || accum)		  pConfigs[i].visualRating = GLX_SLOW_CONFIG;	       else		  pConfigs[i].visualRating = GLX_NONE;	       pConfigs[i].transparentPixel = GLX_NONE;	       pConfigs[i].transparentRed = 0;	       pConfigs[i].transparentGreen = 0;	       pConfigs[i].transparentBlue = 0;	       pConfigs[i].transparentAlpha = 0;	       pConfigs[i].transparentIndex = 0;	       i++;	    }	 }      }      assert(i == numConfigs);      break;   }   pI810->numVisualConfigs = numConfigs;   pI810->pVisualConfigs = pConfigs;   pI810->pVisualConfigsPriv = pI810Configs;   GlxSetVisualConfigs(numConfigs, pConfigs, (void **)pI810ConfigPtrs);   return TRUE;}static unsigned intmylog2(unsigned int n){   unsigned int log2 = 1;   while (n > 1)      n >>= 1, log2++;   return log2;}BoolI810DRIScreenInit(ScreenPtr pScreen){   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];   I810Ptr pI810 = I810PTR(pScrn);   DRIInfoPtr pDRIInfo;   I810DRIPtr pI810DRI;   unsigned long tom;   unsigned long agpHandle;   unsigned long dcacheHandle;   int sysmem_size = 0;   int back_size = 0;   unsigned int pitch_idx = 0;   int bufs;   int width = pScrn->displayWidth * pI810->cpp;   int i;   /* Hardware 3D rendering only implemented for 16bpp */   /* And it only works for 5:6:5 (Mark) */   if (pScrn->depth != 16)      return FALSE;   /* Check that the GLX, DRI, and DRM modules have been loaded by testing    * for known symbols in each module. */   if (!xf86LoaderCheckSymbol("GlxSetVisualConfigs"))      return FALSE;   if (!xf86LoaderCheckSymbol("DRIScreenInit"))      return FALSE;   if (!xf86LoaderCheckSymbol("drmAvailable"))      return FALSE;   if (!xf86LoaderCheckSymbol("DRIQueryVersion")) {      xf86DrvMsg(pScreen->myNum, X_ERROR,		 "[dri] I810DRIScreenInit failed (libdri.a too old)\n");      return FALSE;   }   /* Check the DRI version */   {      int major, minor, patch;      DRIQueryVersion(&major, &minor, &patch);      if (major != 4 || minor < 0) {	 xf86DrvMsg(pScreen->myNum, X_ERROR,		    "[dri] I810DRIScreenInit failed because of a version mismatch.\n"		    "[dri] libDRI version is %d.%d.%d but version 4.0.x is needed.\n"		    "[dri] Disabling DRI.\n", major, minor, patch);	 return FALSE;      }   }   pDRIInfo = DRICreateInfoRec();   if (!pDRIInfo) {      xf86DrvMsg(pScreen->myNum, X_ERROR,		 "[dri] DRICreateInfoRec failed.  Disabling DRI.\n");      return FALSE;   }/*     pDRIInfo->wrap.ValidateTree = 0;    *//*     pDRIInfo->wrap.PostValidateTree = 0;    */   pI810->pDRIInfo = pDRIInfo;   pI810->LockHeld = 0;   pDRIInfo->drmDriverName = I810KernelDriverName;   pDRIInfo->clientDriverName = I810ClientDriverName;   if (xf86LoaderCheckSymbol("DRICreatePCIBusID")) {      pDRIInfo->busIdString = DRICreatePCIBusID(pI810->PciInfo);   } else {      pDRIInfo->busIdString = xalloc(64);      sprintf(pDRIInfo->busIdString, "PCI:%d:%d:%d",	      ((pciConfigPtr) pI810->PciInfo->thisCard)->busnum,	      ((pciConfigPtr) pI810->PciInfo->thisCard)->devnum,	      ((pciConfigPtr) pI810->PciInfo->thisCard)->funcnum);   }   pDRIInfo->ddxDriverMajorVersion = INTEL_MAJOR_VERSION;   pDRIInfo->ddxDriverMinorVersion = INTEL_MINOR_VERSION;   pDRIInfo->ddxDriverPatchVersion = INTEL_PATCHLEVEL;   pDRIInfo->frameBufferPhysicalAddress = pI810->LinearAddr;   pDRIInfo->frameBufferSize = (((pScrn->displayWidth *				  pScrn->virtualY * pI810->cpp) +				 4096 - 1) / 4096) * 4096;   pDRIInfo->frameBufferStride = pScrn->displayWidth * pI810->cpp;   pDRIInfo->ddxDrawableTableEntry = I810_MAX_DRAWABLES;   if (SAREA_MAX_DRAWABLES < I810_MAX_DRAWABLES)      pDRIInfo->maxDrawableTableEntry = SAREA_MAX_DRAWABLES;   else      pDRIInfo->maxDrawableTableEntry = I810_MAX_DRAWABLES;   /* For now the mapping works by using a fixed size defined    * in the SAREA header    */   if (sizeof(XF86DRISAREARec) + sizeof(I810SAREARec) > SAREA_MAX) {      xf86DrvMsg(pScreen->myNum, X_ERROR,		 "[dri] Data does not fit in SAREA\n");      return FALSE;   }   pDRIInfo->SAREASize = SAREA_MAX;   if (!(pI810DRI = (I810DRIPtr) xcalloc(sizeof(I810DRIRec), 1))) {      DRIDestroyInfoRec(pI810->pDRIInfo);      pI810->pDRIInfo = 0;      return FALSE;   }   pDRIInfo->devPrivate = pI810DRI;   pDRIInfo->devPrivateSize = sizeof(I810DRIRec);   pDRIInfo->contextSize = sizeof(I810DRIContextRec);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -