i810_driver.c

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

C
2,368
字号
#endif}/* * I810Probe -- * * Look through the PCI bus to find cards that are I810 boards. * Setup the dispatch table for the rest of the driver functions. * */static BoolI810Probe(DriverPtr drv, int flags){   int i, numUsed, numDevSections, *usedChips;   I830EntPtr pI830Ent = NULL;					   DevUnion *pPriv;						   GDevPtr *devSections;   Bool foundScreen = FALSE;   pciVideoPtr *VideoInfo;   pciVideoPtr *ppPci;   PciChipsets *id;   /*    * Find the config file Device sections that match this    * driver, and return if there are none.    */   if ((numDevSections =	xf86MatchDevice(I810_DRIVER_NAME, &devSections)) <= 0) {      return FALSE;   }   /*    * This probing is just checking the PCI data the server already    * collected.    */   if (!(VideoInfo = xf86GetPciVideoInfo()))      return FALSE;   /*    * Mobile platforms may have both function 0 and 1 active, but they    * are handled as a single entity.  To make sure that the function 1    * entity isn't assigned to a screen, check for and claim it here    * first.    *    * XXX If function 1's resources are ever needed, they'll need to be    * added to the screen and marked active.    */   for (ppPci = VideoInfo; ppPci != NULL && *ppPci != NULL; ppPci++) {      if ((*ppPci)->vendor == PCI_VENDOR_INTEL &&	  (*ppPci)->func == 1) {	 for (id = I810PciChipsets; id->PCIid != -1; id++) {	    if (id->PCIid == (*ppPci)->chipType) {	       /* Claim slot */	       if (xf86CheckPciSlot((*ppPci)->bus, (*ppPci)->device,				    (*ppPci)->func)) {	  	  xf86ClaimPciSlot((*ppPci)->bus, (*ppPci)->device,				   (*ppPci)->func, drv, id->PCIid,				   NULL, FALSE);	       }	       break;	    }	 }      }   }   /* Look for Intel i8xx devices. */   numUsed = xf86MatchPciInstances(I810_NAME, PCI_VENDOR_INTEL,				   I810Chipsets, I810PciChipsets,				   devSections, numDevSections,				   drv, &usedChips);   if (flags & PROBE_DETECT) {      if (numUsed > 0)	 foundScreen = TRUE;   } else {      for (i = 0; i < numUsed; i++) {	 ScrnInfoPtr pScrn = NULL;	 /* Allocate new ScrnInfoRec and claim the slot */	 if ((pScrn = xf86ConfigPciEntity(pScrn, 0, usedChips[i],					  I810PciChipsets, 0, 0, 0, 0, 0))) {	    EntityInfoPtr pEnt;	    pEnt = xf86GetEntityInfo(usedChips[i]);	    pScrn->driverVersion = I810_VERSION;	    pScrn->driverName = I810_DRIVER_NAME;	    pScrn->name = I810_NAME;	    pScrn->Probe = I810Probe;	    foundScreen = TRUE;	    switch (pEnt->chipset) {	    case PCI_CHIP_845_G:	    case PCI_CHIP_I865_G:	       I830InitpScrn(pScrn);               break;	    case PCI_CHIP_I830_M:	    case PCI_CHIP_I855_GM:	    case PCI_CHIP_I915_G:	    case PCI_CHIP_E7221_G:	    case PCI_CHIP_I915_GM:	    case PCI_CHIP_I945_G:	    case PCI_CHIP_I945_GM:    	       xf86SetEntitySharable(usedChips[i]);    	       /* Allocate an entity private if necessary */		    	       if (I830EntityIndex < 0)							  I830EntityIndex = xf86AllocateEntityPrivateIndex();	    	       pPriv = xf86GetEntityPrivate(pScrn->entityList[0],								I830EntityIndex);	    	       if (!pPriv->ptr) {								  pPriv->ptr = xnfcalloc(sizeof(I830EntRec), 1);				  pI830Ent = pPriv->ptr;							  pI830Ent->lastInstance = -1;				    	       } else {									  pI830Ent = pPriv->ptr;					    	       }								    	       /*								     	        * Set the entity instance for this instance of the driver.	     	        * For dual head per card, instance 0 is the "master" 	     	        * instance, driving the primary head, and instance 1 is 	     	        * the "slave".						     	        */								    	       pI830Ent->lastInstance++;					               xf86SetEntityInstanceForScreen(pScrn,						pScrn->entityList[0], pI830Ent->lastInstance);		       I830InitpScrn(pScrn);	       break;#ifndef I830_ONLY	    default:	       pScrn->PreInit = I810PreInit;	       pScrn->ScreenInit = I810ScreenInit;	       pScrn->SwitchMode = I810SwitchMode;	       pScrn->AdjustFrame = I810AdjustFrame;	       pScrn->EnterVT = I810EnterVT;	       pScrn->LeaveVT = I810LeaveVT;	       pScrn->FreeScreen = I810FreeScreen;	       pScrn->ValidMode = I810ValidMode;	       break;#endif	    }	 }      }   }   xfree(usedChips);   xfree(devSections);   return foundScreen;}#ifndef I830_ONLYstatic voidI810ProbeDDC(ScrnInfoPtr pScrn, int index){   vbeInfoPtr pVbe;   if (xf86LoadSubModule(pScrn, "vbe")) {      pVbe = VBEInit(NULL, index);      ConfiguredMonitor = vbeDoEDID(pVbe, NULL);      vbeFree(pVbe);   }}static xf86MonPtrI810DoDDC(ScrnInfoPtr pScrn, int index){   vbeInfoPtr pVbe;   xf86MonPtr MonInfo = NULL;   I810Ptr pI810 = I810PTR(pScrn);   /* Honour Option "noDDC" */   if (xf86ReturnOptValBool(pI810->Options, OPTION_NO_DDC, FALSE)) {      return MonInfo;   }   if (xf86LoadSubModule(pScrn, "vbe") && (pVbe = VBEInit(NULL, index))) {      xf86LoaderReqSymLists(I810vbeSymbols, NULL);      MonInfo = vbeDoEDID(pVbe, NULL);      xf86PrintEDID(MonInfo);      xf86SetDDCproperties(pScrn, MonInfo);      vbeFree(pVbe);   } else {      xf86DrvMsg(pScrn->scrnIndex, X_INFO,		 "this driver cannot do DDC without VBE\n");   }   return MonInfo;}/* * I810PreInit -- * * Do initial setup of the board before we know what resolution we will * be running at. * */static BoolI810PreInit(ScrnInfoPtr pScrn, int flags){   vgaHWPtr hwp;   I810Ptr pI810;   ClockRangePtr clockRanges;   int i;   MessageType from;   int flags24;   rgb defaultWeight = { 0, 0, 0 };   int mem;   Bool enable;   if (pScrn->numEntities != 1)      return FALSE;   /* Allocate driverPrivate */   if (!I810GetRec(pScrn))      return FALSE;   pI810 = I810PTR(pScrn);   pI810->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);   if (pI810->pEnt->location.type != BUS_PCI)      return FALSE;   if (flags & PROBE_DETECT) {      I810ProbeDDC(pScrn, pI810->pEnt->index);      return TRUE;   }   /* The vgahw module should be loaded here when needed */   if (!xf86LoadSubModule(pScrn, "vgahw"))      return FALSE;   xf86LoaderReqSymLists(I810vgahwSymbols, NULL);   /* Allocate a vgaHWRec */   if (!vgaHWGetHWRec(pScrn))      return FALSE;   hwp = VGAHWPTR(pScrn);   pI810->ioBase = hwp->PIOOffset;   pI810->PciInfo = xf86GetPciInfoForEntity(pI810->pEnt->index);   pI810->PciTag = pciTag(pI810->PciInfo->bus, pI810->PciInfo->device,			  pI810->PciInfo->func);   if (xf86RegisterResources(pI810->pEnt->index, 0, ResNone))      return FALSE;   pScrn->racMemFlags = RAC_FB | RAC_COLORMAP;   /* Set pScrn->monitor */   pScrn->monitor = pScrn->confScreen->monitor;   flags24 = Support24bppFb | PreferConvert32to24 | SupportConvert32to24;   if (!xf86SetDepthBpp(pScrn, 0, 0, 0, flags24)) {      return FALSE;   } else {      switch (pScrn->depth) {      case 8:      case 15:      case 16:      case 24:	 break;      default:	 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,		    "Given depth (%d) is not supported by i810 driver\n",		    pScrn->depth);	 return FALSE;      }   }   xf86PrintDepthBpp(pScrn);   switch (pScrn->bitsPerPixel) {   case 8:   case 16:   case 24:      break;   default:      xf86DrvMsg(pScrn->scrnIndex, X_ERROR,		 "Given bpp (%d) is not supported by i810 driver\n",		 pScrn->bitsPerPixel);      return FALSE;   }   if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight))      return FALSE;   if (!xf86SetDefaultVisual(pScrn, -1))      return FALSE;   /* We use a programmable clock */   pScrn->progClock = TRUE;   pI810->cpp = pScrn->bitsPerPixel / 8;   /* Process the options */   xf86CollectOptions(pScrn, NULL);   if (!(pI810->Options = xalloc(sizeof(I810Options))))      return FALSE;   memcpy(pI810->Options, I810Options, sizeof(I810Options));   xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pI810->Options);   pScrn->rgbBits = 8;   if (xf86ReturnOptValBool(pI810->Options, OPTION_DAC_6BIT, FALSE))      pScrn->rgbBits = 6;   if (xf86ReturnOptValBool(pI810->Options, OPTION_SHOW_CACHE, FALSE))     pI810->showCache = TRUE;   else     pI810->showCache = FALSE;   /* 6-BIT dac isn't reasonable for modes with > 8bpp */   if (xf86ReturnOptValBool(pI810->Options, OPTION_DAC_6BIT, FALSE) &&       pScrn->bitsPerPixel > 8) {      OptionInfoPtr ptr;      ptr = xf86TokenToOptinfo(pI810->Options, OPTION_DAC_6BIT);      ptr->found = FALSE;   }   if (xf86ReturnOptValBool(pI810->Options, OPTION_NOACCEL, FALSE))      pI810->noAccel = TRUE;   if (!pI810->noAccel) {      if (!xf86LoadSubModule(pScrn, "xaa")) {	 I810FreeRec(pScrn);	 return FALSE;      }      xf86LoaderReqSymLists(I810xaaSymbols, NULL);   }   #ifdef XF86DRI   pI810->directRenderingDisabled =     !xf86ReturnOptValBool(pI810->Options, OPTION_DRI, TRUE);   if (!pI810->directRenderingDisabled) {     if (pI810->noAccel) {       xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "DRI is disabled because it "		  "needs 2D acceleration.\n");       pI810->directRenderingDisabled=TRUE;     } else if (pScrn->depth!=16) {       xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "DRI is disabled because it "		  "runs only at 16-bit depth.\n");       pI810->directRenderingDisabled=TRUE;     }   }#endif   /* Get DDC info from monitor */   /* after xf86ProcessOptions,    * because it is controlled by options [no]vbe and [no]ddc    */   pScrn->monitor->DDC = I810DoDDC(pScrn, pI810->pEnt->index);   /* We have to use PIO to probe, because we haven't mapped yet */   I810SetPIOAccess(pI810);   /*    * Set the Chipset and ChipRev, allowing config file entries to    * override.    */   if (pI810->pEnt->device->chipset && *pI810->pEnt->device->chipset) {      pScrn->chipset = pI810->pEnt->device->chipset;      from = X_CONFIG;   } else if (pI810->pEnt->device->chipID >= 0) {      pScrn->chipset = (char *)xf86TokenToString(I810Chipsets,						 pI810->pEnt->device->chipID);      from = X_CONFIG;      xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ChipID override: 0x%04X\n",		 pI810->pEnt->device->chipID);   } else {      from = X_PROBED;      pScrn->chipset = (char *)xf86TokenToString(I810Chipsets,						 pI810->PciInfo->chipType);   }   if (pI810->pEnt->device->chipRev >= 0) {      xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ChipRev override: %d\n",		 pI810->pEnt->device->chipRev);   }   xf86DrvMsg(pScrn->scrnIndex, from, "Chipset: \"%s\"\n",	      (pScrn->chipset != NULL) ? pScrn->chipset : "Unknown i810");   if (pI810->pEnt->device->MemBase != 0) {      pI810->LinearAddr = pI810->pEnt->device->MemBase;      from = X_CONFIG;   } else {      if (pI810->PciInfo->memBase[1] != 0) {	 pI810->LinearAddr = pI810->PciInfo->memBase[0] & 0xFF000000;	 from = X_PROBED;      } else {	 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,		    "No valid FB address in PCI config space\n");	 I810FreeRec(pScrn);	 return FALSE;      }   }   xf86DrvMsg(pScrn->scrnIndex, from, "Linear framebuffer at 0x%lX\n",	      (unsigned long)pI810->LinearAddr);   if (pI810->pEnt->device->IOBase != 0) {      pI810->MMIOAddr = pI810->pEnt->device->IOBase;      from = X_CONFIG;   } else {      if (pI810->PciInfo->memBase[1]) {	 pI810->MMIOAddr = pI810->PciInfo->memBase[1] & 0xFFF80000;	 from = X_PROBED;      } else {	 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,		    "No valid MMIO address in PCI config space\n");	 I810FreeRec(pScrn);	 return FALSE;      }   }   xf86DrvMsg(pScrn->scrnIndex, from, "IO registers at addr 0x%lX\n",	      (unsigned long)pI810->MMIOAddr);   /* AGP GART support is required.  Don't proceed any further if it isn't    * present.    */   if (!xf86AgpGARTSupported()) {      xf86DrvMsg(pScrn->scrnIndex, X_ERROR,		 "AGP GART support is not available.  Make sure your kernel has\n"		 "\tagpgart support or that the agpgart kernel module is loaded.\n");      return FALSE;   }   /* Find out memory bus frequency.    */   {      unsigned long whtcfg_pamr_drp = pciReadLong(pI810->PciTag,						  WHTCFG_PAMR_DRP);      /* Need this for choosing watermarks.       */      if ((whtcfg_pamr_drp & LM_FREQ_MASK) == LM_FREQ_133)	 pI810->LmFreqSel = 133;      else	 pI810->LmFreqSel = 100;   }   /* Default to 4MB framebuffer, which is sufficient for all    * supported 2d resolutions.  If the user has specified a different    * size in the XF86Config, use that amount instead.    *    *  Changed to 8 Meg so we can have acceleration by default (Mark).    */   mem = I810CheckAvailableMemory(pScrn);   if (pI810->directRenderingDisabled || mem < 131072)  /* < 128 MB */       pScrn->videoRam = 8192;   else if (mem < 196608)       pScrn->videoRam = 16384;  /* < 192 MB */   else       pScrn->videoRam = 24576;      from = X_DEFAULT;      if (pI810->pEnt->device->videoRam) {      pScrn->videoRam = pI810->pEnt->device->videoRam;      from = X_CONFIG;   }   if (mem > 0 && mem < pScrn->videoRam) {      xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "%dk of memory was requested,"		 " but the\n\t maximum AGP memory available is %dk.\n",		 pScrn->videoRam, mem);      from = X_PROBED;      if (mem > (6 * 1024)) {	 xf86DrvMsg(pScrn->scrnIndex, X_INFO,		    "Reducing video memory to 4MB\n");	 pScrn->videoRam = 4096;      } else {	 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Less than 6MB of AGP memory"		    " is available. Cannot proceed.\n");	 I810FreeRec(pScrn);

⌨️ 快捷键说明

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