i830_dri.c

来自「是由intel提供的针对intel显卡915以上系列的linux驱动」· C语言 代码 · 共 1,519 行 · 第 1/3 页

C
1,519
字号
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/i810/i830_dri.c,v 1.15 2003/06/18 13:14:17 dawes Exp $ *//**************************************************************************Copyright 2001 VA Linux Systems Inc., Fremont, California.Copyright © 2002 by David DawesAll Rights Reserved.Permission is hereby granted, free of charge, to any person obtaining acopy of this software and associated documentation files (the "Software"),to deal in the Software without restriction, including without limitationon the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whomthe Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice (including the nextparagraph) shall be included in all copies or substantial portions of theSoftware.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALLATI, VA LINUX SYSTEMS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OROTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THEUSE OR OTHER DEALINGS IN THE SOFTWARE.**************************************************************************//* * 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. *//* * Authors: Jeff Hartmann <jhartmann@valinux.com> *          David Dawes <dawes@xfree86.org> *          Keith Whitwell <keith@tungstengraphics.com> *//* * This driver does AGP memory allocation a little differently from most * others.  The 2D and 3D allocations have been unified (see i830_memory.c). * The driver does the AGP allocations and binding directly, then passes * on the mappings to the DRM module.  The DRM's AGP interfaces are not used. * The main difference with this is that the offsets need to include * the AGP aperture base address because that won't be known or added on * by the DRM module. * * DHD 07/2002 */#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 "GL/glxtokens.h"#include "i830.h"#include "i830_dri.h"#include "dristruct.h"static char I830KernelDriverName[] = "i915";static char I830ClientDriverName[] = "i915";static Bool I830InitVisualConfigs(ScreenPtr pScreen);static Bool I830CreateContext(ScreenPtr pScreen, VisualPtr visual,			      drm_context_t hwContext, void *pVisualConfigPriv,			      DRIContextType contextStore);static void I830DestroyContext(ScreenPtr pScreen, drm_context_t hwContext,			       DRIContextType contextStore);static void I830DRISwapContext(ScreenPtr pScreen, DRISyncType syncType,			       DRIContextType readContextType,			       void *readContextStore,			       DRIContextType writeContextType,			       void *writeContextStore);static void I830DRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index);static void I830DRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg,			       RegionPtr prgnSrc, CARD32 index);static Bool I830DRICloseFullScreen(ScreenPtr pScreen);static Bool I830DRIOpenFullScreen(ScreenPtr pScreen);static void I830DRITransitionTo2d(ScreenPtr pScreen);static void I830DRITransitionTo3d(ScreenPtr pScreen);static void I830DRITransitionMultiToSingle3d(ScreenPtr pScreen);static void I830DRITransitionSingleToMulti3d(ScreenPtr pScreen);#if 0static void I830DRIShadowUpdate (ScreenPtr pScreen, shadowBufPtr pBuf);#endifextern void GlxSetVisualConfigs(int nconfigs,				__GLXvisualConfig * configs,				void **configprivs);static BoolI830CleanupDma(ScrnInfoPtr pScrn){   I830Ptr pI830 = I830PTR(pScrn);   drmI830Init info;   memset(&info, 0, sizeof(drmI830Init));   info.func = I830_CLEANUP_DMA;   if (drmCommandWrite(pI830->drmSubFD, DRM_I830_INIT,		       &info, sizeof(drmI830Init))) {      xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "I830 Dma Cleanup Failed\n");      return FALSE;   }   return TRUE;}static BoolI830InitDma(ScrnInfoPtr pScrn){   I830Ptr pI830 = I830PTR(pScrn);   I830RingBuffer *ring = pI830->LpRing;   I830DRIPtr pI830DRI = (I830DRIPtr) pI830->pDRIInfo->devPrivate;   drmI830Init info;   memset(&info, 0, sizeof(drmI830Init));   info.func = I830_INIT_DMA;   info.ring_start = ring->mem.Start + pI830->LinearAddr;   info.ring_end = ring->mem.End + pI830->LinearAddr;   info.ring_size = ring->mem.Size;   info.mmio_offset = (unsigned int)pI830DRI->regs;   info.sarea_priv_offset = sizeof(XF86DRISAREARec);   info.front_offset = pI830->FrontBuffer.Start;   info.back_offset = pI830->BackBuffer.Start;   info.depth_offset = pI830->DepthBuffer.Start;   info.w = pScrn->virtualX;   info.h = pScrn->virtualY;   info.pitch = pI830->displayWidth;   info.back_pitch = pI830->displayWidth;   info.depth_pitch = pI830->displayWidth;   info.cpp = pI830->cpp;   if (drmCommandWrite(pI830->drmSubFD, DRM_I830_INIT,		       &info, sizeof(drmI830Init))) {      xf86DrvMsg(pScrn->scrnIndex, X_ERROR,		 "I830 Dma Initialization Failed\n");      return FALSE;   }   return TRUE;}static BoolI830ResumeDma(ScrnInfoPtr pScrn){   I830Ptr pI830 = I830PTR(pScrn);   drmI830Init info;   memset(&info, 0, sizeof(drmI830Init));   info.func = I830_RESUME_DMA;   if (drmCommandWrite(pI830->drmSubFD, DRM_I830_INIT,		       &info, sizeof(drmI830Init))) {      xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "I830 Dma Resume Failed\n");      return FALSE;   }   return TRUE;}static BoolI830SetParam(ScrnInfoPtr pScrn, int param, int value){   I830Ptr pI830 = I830PTR(pScrn);   drmI830SetParam sp;   memset(&sp, 0, sizeof(sp));   sp.param = param;   sp.value = value;   if (drmCommandWrite(pI830->drmSubFD, DRM_I830_SETPARAM, &sp, sizeof(sp))) {      xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "I830 SetParam Failed\n");      return FALSE;   }   return TRUE;}static BoolI830InitVisualConfigs(ScreenPtr pScreen){   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];   I830Ptr pI830 = I830PTR(pScrn);   int numConfigs = 0;   __GLXvisualConfig *pConfigs = 0;   I830ConfigPrivPtr pI830Configs = 0;   I830ConfigPrivPtr *pI830ConfigPtrs = 0;   int accum, stencil, db, depth;   int i;   switch (pScrn->bitsPerPixel) {   case 8:   case 24:      break;   case 16:      numConfigs = 8;      pConfigs =	    (__GLXvisualConfig *) xcalloc(sizeof(__GLXvisualConfig),					  numConfigs);      if (!pConfigs)	 return FALSE;      pI830Configs =	    (I830ConfigPrivPtr) xcalloc(sizeof(I830ConfigPrivRec),					numConfigs);      if (!pI830Configs) {	 xfree(pConfigs);	 return FALSE;      }      pI830ConfigPtrs =	    (I830ConfigPrivPtr *) xcalloc(sizeof(I830ConfigPrivPtr),					  numConfigs);      if (!pI830ConfigPtrs) {	 xfree(pConfigs);	 xfree(pI830Configs);	 return FALSE;      }      for (i = 0; i < numConfigs; i++)	 pI830ConfigPtrs[i] = &pI830Configs[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].alphaSize = 0;	       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_VISUAL_EXT;	       else		  pConfigs[i].visualRating = GLX_NONE_EXT;	       pConfigs[i].transparentPixel = GLX_NONE_EXT;	       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;   case 32:      numConfigs = 8;      pConfigs = (__GLXvisualConfig *) xcalloc(sizeof(__GLXvisualConfig),					       numConfigs);      if (!pConfigs) {	 return FALSE;      }      pI830Configs = (I830ConfigPrivPtr) xcalloc(sizeof(I830ConfigPrivRec),						 numConfigs);      if (!pI830Configs) {	 xfree(pConfigs);	 return FALSE;      }      pI830ConfigPtrs = (I830ConfigPrivPtr *)	    xcalloc(sizeof(I830ConfigPrivPtr), numConfigs);      if (!pI830ConfigPtrs) {	 xfree(pConfigs);	 xfree(pI830Configs);	 return FALSE;      }      for (i = 0; i < numConfigs; i++) {	 pI830ConfigPtrs[i] = &pI830Configs[i];      }      i = 0;      for (accum = 0; accum <= 1; accum++) {	 for (depth = 0; depth <= 1; depth++) {	/* and stencil */	    for (db = 1; db >= 0; db--) {	       pConfigs[i].vid = -1;	       pConfigs[i].class = -1;	       pConfigs[i].rgba = TRUE;	       pConfigs[i].redSize = 8;	       pConfigs[i].greenSize = 8;	       pConfigs[i].blueSize = 8;	       pConfigs[i].alphaSize = 8;	       pConfigs[i].redMask = 0x00FF0000;	       pConfigs[i].greenMask = 0x0000FF00;	       pConfigs[i].blueMask = 0x000000FF;	       pConfigs[i].alphaMask = 0xFF000000;	       if (accum) {		  pConfigs[i].accumRedSize = 16;		  pConfigs[i].accumGreenSize = 16;		  pConfigs[i].accumBlueSize = 16;		  pConfigs[i].accumAlphaSize = 16;	       } else {		  pConfigs[i].accumRedSize = 0;		  pConfigs[i].accumGreenSize = 0;		  pConfigs[i].accumBlueSize = 0;		  pConfigs[i].accumAlphaSize = 0;	       }	       if (db) {		  pConfigs[i].doubleBuffer = TRUE;	       } else {		  pConfigs[i].doubleBuffer = FALSE;	       }	       pConfigs[i].stereo = FALSE;	       pConfigs[i].bufferSize = 32;	       if (depth) {		  pConfigs[i].depthSize = 24;		  pConfigs[i].stencilSize = 8;	       } else {		  pConfigs[i].depthSize = 0;		  pConfigs[i].stencilSize = 0;	       }	       pConfigs[i].auxBuffers = 0;	       pConfigs[i].level = 0;	       if (accum) {		  pConfigs[i].visualRating = GLX_SLOW_VISUAL_EXT;	       } else {		  pConfigs[i].visualRating = GLX_NONE_EXT;	       }	       pConfigs[i].transparentPixel = GLX_NONE_EXT;	       pConfigs[i].transparentRed = 0;	       pConfigs[i].transparentGreen = 0;	       pConfigs[i].transparentBlue = 0;	       pConfigs[i].transparentAlpha = 0;	       pConfigs[i].transparentIndex = 0;	       i++;	    }	 }      }      if (i != numConfigs) {	 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,		    "[drm] Incorrect initialization of visuals\n");	 return FALSE;      }      break;   }   pI830->numVisualConfigs = numConfigs;   pI830->pVisualConfigs = pConfigs;   pI830->pVisualConfigsPriv = pI830Configs;   GlxSetVisualConfigs(numConfigs, pConfigs, (void **)pI830ConfigPtrs);   return TRUE;}BoolI830CheckDRIAvailable(ScrnInfoPtr pScrn){   /* Hardware 3D rendering only implemented for 16bpp and 32 bpp */   if (((pScrn->bitsPerPixel / 8) != 2 && pScrn->depth != 16) &&       (pScrn->bitsPerPixel / 8) != 4) {      xf86DrvMsg(pScrn->scrnIndex, X_ERROR,		 "[drm] Direct rendering only supported in 16 and 32 bpp modes\n");      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(pScrn->scrnIndex, X_ERROR,		 "[dri] %s failed (libdri.a too old)\n", "I830CheckDRIAvailable");      return FALSE;   }   /* Check the DRI version */   {      int major, minor, patch;      DRIQueryVersion(&major, &minor, &patch);      if (major != 4 || minor < 0) {	 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,		    "[dri] %s 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",		    "I830CheckDRIAvailable", major, minor, patch);	 return FALSE;      }   }   return TRUE;}BoolI830DRIScreenInit(ScreenPtr pScreen){   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];   I830Ptr pI830 = I830PTR(pScrn);   DRIInfoPtr pDRIInfo;   I830DRIPtr pI830DRI;   DPRINTF(PFX, "I830DRIScreenInit\n");   if (!I830CheckDRIAvailable(pScrn))      return FALSE;   pDRIInfo = DRICreateInfoRec();   if (!pDRIInfo) {      xf86DrvMsg(pScreen->myNum, X_ERROR,		 "[dri] DRICreateInfoRec failed. Disabling DRI.\n");      return FALSE;   }   pI830->pDRIInfo = pDRIInfo;   pI830->LockHeld = 0;   pDRIInfo->drmDriverName = I830KernelDriverName;   pDRIInfo->clientDriverName = I830ClientDriverName;   if (xf86LoaderCheckSymbol("DRICreatePCIBusID")) {      pDRIInfo->busIdString = DRICreatePCIBusID(pI830->PciInfo);   } else {      pDRIInfo->busIdString = xalloc(64);      sprintf(pDRIInfo->busIdString, "PCI:%d:%d:%d",	      ((pciConfigPtr) pI830->PciInfo->thisCard)->busnum,	      ((pciConfigPtr) pI830->PciInfo->thisCard)->devnum,	      ((pciConfigPtr) pI830->PciInfo->thisCard)->funcnum);   }   pDRIInfo->ddxDriverMajorVersion = INTEL_MAJOR_VERSION;   pDRIInfo->ddxDriverMinorVersion = INTEL_MINOR_VERSION;   pDRIInfo->ddxDriverPatchVersion = INTEL_PATCHLEVEL;   pDRIInfo->frameBufferPhysicalAddress = pI830->LinearAddr +					  pI830->FrontBuffer.Start;#if 0   pDRIInfo->frameBufferSize = ROUND_TO_PAGE(pScrn->displayWidth *					     pScrn->virtualY * pI830->cpp);#else   /* For rotation we map a 0 length framebuffer as we remap ourselves later */   pDRIInfo->frameBufferSize = 0;#endif   pDRIInfo->frameBufferStride = pScrn->displayWidth * pI830->cpp;   pDRIInfo->ddxDrawableTableEntry = I830_MAX_DRAWABLES;   if (SAREA_MAX_DRAWABLES < I830_MAX_DRAWABLES)      pDRIInfo->maxDrawableTableEntry = SAREA_MAX_DRAWABLES;   else      pDRIInfo->maxDrawableTableEntry = I830_MAX_DRAWABLES;   if (sizeof(XF86DRISAREARec) + sizeof(drmI830Sarea) > SAREA_MAX) {      xf86DrvMsg(pScreen->myNum, X_ERROR,

⌨️ 快捷键说明

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