i810_driver.c

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

C
2,368
字号
      b = colors[index].blue;      index = indices[i];      g = colors[index].green;      hwp->writeDacWriteAddr(hwp, index << 2);      hwp->writeDacData(hwp, r);      hwp->writeDacData(hwp, g);      hwp->writeDacData(hwp, b);      hwp->writeDacWriteAddr(hwp, (index << 2) + 1);      hwp->writeDacData(hwp, r);      hwp->writeDacData(hwp, g);      hwp->writeDacData(hwp, b);      hwp->writeDacWriteAddr(hwp, (index << 2) + 2);      hwp->writeDacData(hwp, r);      hwp->writeDacData(hwp, g);      hwp->writeDacData(hwp, b);      hwp->writeDacWriteAddr(hwp, (index << 2) + 3);      hwp->writeDacData(hwp, r);      hwp->writeDacData(hwp, g);      hwp->writeDacData(hwp, b);      i++;      index = indices[i];      g = colors[index].green;      hwp->writeDacWriteAddr(hwp, index << 2);      hwp->writeDacData(hwp, r);      hwp->writeDacData(hwp, g);      hwp->writeDacData(hwp, b);      hwp->writeDacWriteAddr(hwp, (index << 2) + 1);      hwp->writeDacData(hwp, r);      hwp->writeDacData(hwp, g);      hwp->writeDacData(hwp, b);      hwp->writeDacWriteAddr(hwp, (index << 2) + 2);      hwp->writeDacData(hwp, r);      hwp->writeDacData(hwp, g);      hwp->writeDacData(hwp, b);      hwp->writeDacWriteAddr(hwp, (index << 2) + 3);      hwp->writeDacData(hwp, r);      hwp->writeDacData(hwp, g);      hwp->writeDacData(hwp, b);   }}static voidI810LoadPalette24(ScrnInfoPtr pScrn, int numColors, int *indices,		  LOCO * colors, VisualPtr pVisual){   I810Ptr pI810;   vgaHWPtr hwp;   int i, index;   unsigned char r, g, b;   pI810 = I810PTR(pScrn);   hwp = VGAHWPTR(pScrn);   for (i = 0; i < numColors; i++) {      index = indices[i];      r = colors[index].red;      g = colors[index].green;      b = colors[index].blue;      hwp->writeDacWriteAddr(hwp, index);      hwp->writeDacData(hwp, r);      hwp->writeDacData(hwp, g);      hwp->writeDacData(hwp, b);   }}BoolI810AllocateFront(ScrnInfoPtr pScrn){   I810Ptr pI810 = I810PTR(pScrn);   int cache_lines = -1;   if (pI810->DoneFrontAlloc)      return TRUE;   memset(&(pI810->FbMemBox), 0, sizeof(BoxRec));   /* Alloc FrontBuffer/Ring/Accel memory */   pI810->FbMemBox.x1 = 0;   pI810->FbMemBox.x2 = pScrn->displayWidth;   pI810->FbMemBox.y1 = 0;   pI810->FbMemBox.y2 = pScrn->virtualY;   xf86GetOptValInteger(pI810->Options, OPTION_CACHE_LINES, &cache_lines);   if (cache_lines < 0) {      /* make sure there is enough for two DVD sized YUV buffers */      cache_lines = (pScrn->depth == 24) ? 256 : 384;      if (pScrn->displayWidth <= 1024)	 cache_lines *= 2;   }   /* Make sure there's enough space for cache_lines.    *    * Had a bug here where maxCacheLines was computed to be less than 0.    * Not sure why 256 was initially subtracted from videoRam in the    * maxCacheLines calculation, but that was causing a problem    * for configurations that have exactly enough Ram for the framebuffer.    * Common code should catch the case where there isn't enough space for    * framebuffer, we'll just check for no space for cache_lines.  -jens    *    */   {      int maxCacheLines;      maxCacheLines = (pScrn->videoRam * 1024 /		       (pScrn->bitsPerPixel / 8) /		       pScrn->displayWidth) - pScrn->virtualY;      if (maxCacheLines < 0)	 maxCacheLines = 0;      if (cache_lines > maxCacheLines)	 cache_lines = maxCacheLines;   }   pI810->FbMemBox.y2 += cache_lines;   xf86DrvMsg(pScrn->scrnIndex, X_INFO,	      "Adding %i scanlines for pixmap caching\n", cache_lines);   /* Reserve room for the framebuffer and pixcache.  Put at the top    * of memory so we can have nice alignment for the tiled regions at    * the start of memory.    */   if (!I810AllocLow(&(pI810->FrontBuffer),		     &(pI810->SysMem),		     ((pI810->FbMemBox.x2 *		       pI810->FbMemBox.y2 * pI810->cpp) + 4095) & ~4095)) {      xf86DrvMsg(pScrn->scrnIndex,		 X_WARNING, "Framebuffer allocation failed\n");      return FALSE;   } else      DPRINTF(PFX,	      "Frame buffer at 0x%.8x (%luk, %lu bytes)\n",	      pI810->FrontBuffer.Start,	      pI810->FrontBuffer.Size / 1024, pI810->FrontBuffer.Size);   memset(pI810->LpRing, 0, sizeof(I810RingBuffer));   if (I810AllocLow(&(pI810->LpRing->mem), &(pI810->SysMem), 16 * 4096)) {      DPRINTF(PFX,	      "Ring buffer at 0x%.8x (%luk, %lu bytes)\n",	      pI810->LpRing->mem.Start,	      pI810->LpRing->mem.Size / 1024, pI810->LpRing->mem.Size);      pI810->LpRing->tail_mask = pI810->LpRing->mem.Size - 1;      pI810->LpRing->virtual_start = pI810->FbBase + pI810->LpRing->mem.Start;      pI810->LpRing->head = 0;      pI810->LpRing->tail = 0;      pI810->LpRing->space = 0;   } else {      xf86DrvMsg(pScrn->scrnIndex, X_ERROR,		 "Ring buffer allocation failed\n");      return (FALSE);   }   if (I810AllocLow(&pI810->Scratch, &(pI810->SysMem), 64 * 1024) ||       I810AllocLow(&pI810->Scratch, &(pI810->SysMem), 16 * 1024)) {      DPRINTF(PFX,	      "Scratch memory at 0x%.8x (%luk, %lu bytes)\n",	      pI810->Scratch.Start,	      pI810->Scratch.Size / 1024, pI810->Scratch.Size);      xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Allocated Scratch Memory\n");   } else {      xf86DrvMsg(pScrn->scrnIndex, X_ERROR,		 "Scratch memory allocation failed\n");      return (FALSE);   }   pI810->DoneFrontAlloc = TRUE;   return TRUE;}static BoolI810ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv){   ScrnInfoPtr pScrn;   vgaHWPtr hwp;   I810Ptr pI810;   VisualPtr visual;   MessageType driFrom = X_DEFAULT;   pScrn = xf86Screens[pScreen->myNum];   pI810 = I810PTR(pScrn);   hwp = VGAHWPTR(pScrn);   pI810->LpRing = xcalloc(sizeof(I810RingBuffer),1);   if (!pI810->LpRing) {     xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 		"Could not allocate lpring data structure.\n");     return FALSE;   }      miClearVisualTypes();   /* Re-implemented Direct Color support, -jens */   if (!miSetVisualTypes(pScrn->depth, miGetDefaultVisualMask(pScrn->depth),			 pScrn->rgbBits, pScrn->defaultVisual))      return FALSE;   if (!miSetPixmapDepths())      return FALSE;   {      I810RegPtr i810Reg = &pI810->ModeReg;      int i;      for (i = 0; i < 8; i++)	 i810Reg->Fence[i] = 0;   }   /* Have to init the DRM earlier than in other drivers to get agp    * memory.  Wonder if this is going to be a problem...    */#ifdef XF86DRI   /*    * Setup DRI after visuals have been established, but before fbScreenInit    * is called.   fbScreenInit will eventually call into the drivers    * InitGLXVisuals call back.    */   /*    * pI810->directRenderingDisabled is set once in PreInit.  Reinitialise    * pI810->directRenderingEnabled based on it each generation.    */   pI810->directRenderingEnabled = !pI810->directRenderingDisabled;      if (pI810->directRenderingEnabled==TRUE)     pI810->directRenderingEnabled = I810DRIScreenInit(pScreen);   else     driFrom = X_CONFIG;#else   pI810->directRenderingEnabled = FALSE;   if (!I810AllocateGARTMemory(pScrn))      return FALSE;   if (!I810AllocateFront(pScrn))      return FALSE;#endif   if (!I810MapMem(pScrn))      return FALSE;   pScrn->memPhysBase = (unsigned long)pI810->LinearAddr;   pScrn->fbOffset = 0;   vgaHWSetMmioFuncs(hwp, pI810->MMIOBase, 0);   vgaHWGetIOBase(hwp);   if (!vgaHWMapMem(pScrn))      return FALSE;   I810Save(pScrn);   if (!I810ModeInit(pScrn, pScrn->currentMode))      return FALSE;   I810SaveScreen(pScreen, FALSE);   I810AdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);   if (!fbScreenInit(pScreen, pI810->FbBase + pScrn->fbOffset,		     pScrn->virtualX, pScrn->virtualY,		     pScrn->xDpi, pScrn->yDpi,		     pScrn->displayWidth, pScrn->bitsPerPixel))      return FALSE;   if (pScrn->bitsPerPixel > 8) {      /* Fixup RGB ordering */      visual = pScreen->visuals + pScreen->numVisuals;      while (--visual >= pScreen->visuals) {	 if ((visual->class | DynamicClass) == DirectColor) {	    visual->offsetRed = pScrn->offset.red;	    visual->offsetGreen = pScrn->offset.green;	    visual->offsetBlue = pScrn->offset.blue;	    visual->redMask = pScrn->mask.red;	    visual->greenMask = pScrn->mask.green;	    visual->blueMask = pScrn->mask.blue;	 }      }   }   fbPictureInit(pScreen, 0, 0);   xf86SetBlackWhitePixels(pScreen);#ifdef XF86DRI   if (pI810->LpRing->mem.Start == 0 && pI810->directRenderingEnabled) {      pI810->directRenderingEnabled = FALSE;      driFrom = X_PROBED;      I810DRICloseScreen(pScreen);   }   if (!pI810->directRenderingEnabled) {      pI810->DoneFrontAlloc = FALSE;      if (!I810AllocateGARTMemory(pScrn))	 return FALSE;      if (!I810AllocateFront(pScrn))	 return FALSE;   }#endif   I810DGAInit(pScreen);   if (!xf86InitFBManager(pScreen, &(pI810->FbMemBox))) {      xf86DrvMsg(pScrn->scrnIndex, X_ERROR,		 "Failed to init memory manager\n");      return FALSE;   }   if (!xf86ReturnOptValBool(pI810->Options, OPTION_NOACCEL, FALSE)) {      if (pI810->LpRing->mem.Size != 0) {	 I810SetRingRegs(pScrn);	 if (!I810AccelInit(pScreen)) {	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,		       "Hardware acceleration initialization failed\n");	 }  else /* PK added 16.02.2004 */	     I810EmitFlush(pScrn);      }   }   miInitializeBackingStore(pScreen);   xf86SetBackingStore(pScreen);   xf86SetSilkenMouse(pScreen);   miDCInitialize(pScreen, xf86GetPointerScreenFuncs());   if (!xf86ReturnOptValBool(pI810->Options, OPTION_SW_CURSOR, FALSE)) {      if (!I810CursorInit(pScreen)) {	 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,		    "Hardware cursor initialization failed\n");      }   }   if (!miCreateDefColormap(pScreen))      return FALSE;   /* Use driver specific palette load routines for Direct Color support. -jens */   if (pScrn->bitsPerPixel == 16) {      if (pScrn->depth == 15) {	 if (!xf86HandleColormaps(pScreen, 256, 8, I810LoadPalette15, 0,				  CMAP_PALETTED_TRUECOLOR |				  CMAP_RELOAD_ON_MODE_SWITCH))	    return FALSE;      } else {	 if (!xf86HandleColormaps(pScreen, 256, 8, I810LoadPalette16, 0,				  CMAP_PALETTED_TRUECOLOR |				  CMAP_RELOAD_ON_MODE_SWITCH))	    return FALSE;      }   } else {      if (!xf86HandleColormaps(pScreen, 256, 8, I810LoadPalette24, 0,			       CMAP_PALETTED_TRUECOLOR |			       CMAP_RELOAD_ON_MODE_SWITCH))	 return FALSE;   }   xf86DPMSInit(pScreen, I810DisplayPowerManagementSet, 0);   I810InitVideo(pScreen);#ifdef XF86DRI   if (pI810->directRenderingEnabled) {      /* Now that mi, fb, drm and others have done their thing,       * complete the DRI setup.       */      pI810->directRenderingEnabled = I810DRIFinishScreenInit(pScreen);   }#ifdef XvMCExtension   if ((pI810->directRenderingEnabled) && (pI810->numSurfaces)) {      /* Initialize the hardware motion compensation code */      I810InitMC(pScreen);   }#endif#endif   if (pI810->directRenderingEnabled) {      xf86DrvMsg(pScrn->scrnIndex, driFrom, "Direct rendering enabled\n");   } else {      xf86DrvMsg(pScrn->scrnIndex, driFrom, "Direct rendering disabled\n");   }   pScreen->SaveScreen = I810SaveScreen;   pI810->CloseScreen = pScreen->CloseScreen;   pScreen->CloseScreen = I810CloseScreen;   if (serverGeneration == 1)      xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);   return TRUE;}BoolI810SwitchMode(int scrnIndex, DisplayModePtr mode, int flags){   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];#if 0   I810Ptr pI810 = I810PTR(pScrn);#endif   if (I810_DEBUG & DEBUG_VERBOSE_CURSOR)      ErrorF("I810SwitchMode %p %x\n", (void *)mode, flags);#if 0/*  * This has been added to prevent lockups on mode switch by modeling * it after I810Leave()/I810Enter() but the call to I810DRILeave()  * was missing so it caused the opposite.  * The version below works but it is doubtful it does any good. * If lockups on mode switch are still seen revisit this code. (EE) */# ifdef XF86DRI   if (pI810->directRenderingEnabled) {      if (I810_DEBUG & DEBUG_VERBOSE_DRI)	 ErrorF("calling dri lock\n");      DRILock(screenInfo.screens[scrnIndex], 0);      pI810->LockHeld = 1;   }# endif   if (pI810->AccelInfoRec != NULL) {      I810RefreshRing(pScrn);      I810Sync(pScrn);      pI810->AccelInfoRec->NeedToSync = FALSE;   }   I810Restore(pScrn);# ifdef XF86DRI   if (pI810->directRenderingEnabled) {       if (!I810DRILeave(pScrn))	   return FALSE;       if (!I810DRIEnter(pScrn))	   return FALSE;       if (I810_DEBUG & DEBUG_VERBOSE_DRI)	   ErrorF("calling dri unlock\n");       DRIUnlock(screenInfo.screens[scrnIndex]);       pI810->LockHeld = 0;   }# endif#endif   return I810ModeInit(pScrn, mode);}voidI810AdjustFrame(int scrnIndex, int x, int y, int flags){   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];   I810Ptr pI810 = I810PTR(pScrn);   vgaHWPtr hwp = VGAHWPTR(pScrn);   int Base;#if 1   if (pI810->showCache) {     int lastline = pI810->FbMapSize /        ((pScrn->displayWidth * pScrn->bitsPerPixel) / 8);     lastline -= pScrn->currentMode->VDisplay;     if (y > 0)       y += pScrn->currentMode->VDisplay;     if (y > lastline) y = lastline;   }#endif   Base = (y * pScrn->displayWidth + x) >> 2;   if (I810_DEBUG & DEBUG_VERBOSE_CURSOR)      ErrorF("I810AdjustFrame %d,%d %x\n", x, y, flags);   switch (pScrn->bitsPerPixel) {   case 8:   

⌨️ 快捷键说明

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