i = mylog2(pMGADRIServer->agpTextures.size / MGA_NR_TEX_REGIONS); if(i < MGA_LOG_MIN_TEX_REGION_SIZE) i = MGA_LOG_MIN_TEX_REGION_SIZE; pMGADRIServer->agpTextures.size = (pMGADRIServer->agpTextures.size >> i) << i;  if ( drmAddMap( pMga->drmFD, pMGADRIServer->agpTextures.offset, pMGADRIServer->agpTextures.size, DRM_AGP, 0, &pMGADRIServer->agpTextures.handle ) < 0 ) { xf86DrvMsg( pScreen->myNum, X_ERROR, "[agp] Could not add agpTexture mapping\n" ); return FALSE; }  xf86DrvMsg( pScreen->myNum, X_INFO, "[agp] agpTexture handle = 0x%08lx\n", pMGADRIServer->agpTextures.handle ); xf86DrvMsg( pScreen->myNum, X_INFO, "[agp] agpTexture size: %d kb\n", pMGADRIServer->agpTextures.size/1024 );
static Bool MGADRIAgpInit(ScreenPtr pScreen){   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];   MGAPtr pMga = MGAPTR(pScrn);   MGADRIServerPrivatePtr pMGADRIServer = pMga->DRIServerInfo;   unsigned long mode;   unsigned int vendor, device;   int ret, count;   /* FIXME: Make these configurable...    */   pMGADRIServer->agp.size = 12 * 1024 * 1024;   pMGADRIServer->warp.offset = 0;   pMGADRIServer->warp.size = MGA_WARP_UCODE_SIZE;   pMGADRIServer->primary.offset = (pMGADRIServer->warp.offset +				    pMGADRIServer->warp.size);   pMGADRIServer->primary.size = 1024 * 1024;   pMGADRIServer->buffers.offset = (pMGADRIServer->primary.offset +				    pMGADRIServer->primary.size);   pMGADRIServer->buffers.size = MGA_NUM_BUFFERS * MGA_BUFFER_SIZE;   if ( drmAgpAcquire( pMga->drmFD ) < 0 ) {      xf86DrvMsg( pScreen->myNum, X_ERROR, "[agp] AGP not available\n" );      return FALSE;   }   mode   = drmAgpGetMode( pMga->drmFD );        /* Default mode */   vendor = drmAgpVendorId( pMga->drmFD );   device = drmAgpDeviceId( pMga->drmFD );   mode &= ~MGA_AGP_MODE_MASK;   switch ( pMga->agpMode ) {   case 4:      mode |= MGA_AGP_4X_MODE;   case 2:      mode |= MGA_AGP_2X_MODE;   case 1:   default:      mode |= MGA_AGP_1X_MODE;   }   xf86DrvMsg( pScreen->myNum, X_INFO,	       "[agp] Mode 0x%08lx [AGP 0x%04x/0x%04x; Card 0x%04x/0x%04x]\n",	       mode, vendor, device,	       pMga->PciInfo->vendor,	       pMga->PciInfo->chipType );   if ( drmAgpEnable( pMga->drmFD, mode ) < 0 ) {      xf86DrvMsg( pScreen->myNum, X_ERROR, "[agp] AGP not enabled\n" );      drmAgpRelease( pMga->drmFD );      return FALSE;   }   if ( pMga->Chipset == PCI_CHIP_MGAG200 ) {      switch ( pMga->agpMode ) {      case 2:	 xf86DrvMsg( pScreen->myNum, X_INFO,		     "[drm] Enabling AGP 2x PLL encoding\n" );	 OUTREG( MGAREG_AGP_PLL, MGA_AGP2XPLL_ENABLE );	 break;      case 1:      default:	 xf86DrvMsg( pScreen->myNum, X_INFO,		     "[drm] Disabling AGP 2x PLL encoding\n" );	 OUTREG( MGAREG_AGP_PLL, MGA_AGP2XPLL_DISABLE );	 pMga->agpMode = 1;	 break;      }   }   ret = drmAgpAlloc( pMga->drmFD, pMGADRIServer->agp.size,		      0, NULL, &pMGADRIServer->agp.handle );   if ( ret < 0 ) {      xf86DrvMsg( pScreen->myNum, X_ERROR, "[agp] Out of memory (%d)\n", ret );      drmAgpRelease( pMga->drmFD );      return FALSE;   }   xf86DrvMsg( pScreen->myNum, X_INFO,	       "[agp] %d kB allocated with handle 0x%08x\n",	       pMGADRIServer->agp.size/1024, pMGADRIServer->agp.handle );   if ( drmAgpBind( pMga->drmFD, pMGADRIServer->agp.handle, 0 ) < 0 ) {      xf86DrvMsg( pScreen->myNum, X_ERROR, "[agp] Could not bind memory\n" );      drmAgpFree( pMga->drmFD, pMGADRIServer->agp.handle );      drmAgpRelease( pMga->drmFD );      return FALSE;   }   /* WARP microcode space    */   if ( drmAddMap( pMga->drmFD,		   pMGADRIServer->warp.offset,		   pMGADRIServer->warp.size,		   DRM_AGP, DRM_READ_ONLY,		   &pMGADRIServer->warp.handle ) < 0 ) {      xf86DrvMsg( pScreen->myNum, X_ERROR,		  "[agp] Could not add WARP microcode mapping\n" );      return FALSE;   }   xf86DrvMsg( pScreen->myNum, X_INFO,	       "[agp] WARP microcode handle = 0x%08lx\n",	       pMGADRIServer->warp.handle );   if ( drmMap( pMga->drmFD,		pMGADRIServer->warp.handle,		pMGADRIServer->warp.size,		&pMGADRIServer->warp.map ) < 0 ) {      xf86DrvMsg( pScreen->myNum, X_ERROR,		  "[agp] Could not map WARP microcode\n" );      return FALSE;   }   xf86DrvMsg( pScreen->myNum, X_INFO,	       "[agp] WARP microcode mapped at 0x%08lx\n",	       (unsigned long)pMGADRIServer->warp.map );   /* Primary DMA space    */   if ( drmAddMap( pMga->drmFD,		   pMGADRIServer->primary.offset,		   pMGADRIServer->primary.size,		   DRM_AGP, DRM_READ_ONLY,		   &pMGADRIServer->primary.handle ) < 0 ) {      xf86DrvMsg( pScreen->myNum, X_ERROR,		  "[agp] Could not add primary DMA mapping\n" );      return FALSE;   }   xf86DrvMsg( pScreen->myNum, X_INFO,	       "[agp] Primary DMA handle = 0x%08lx\n",	       pMGADRIServer->primary.handle );   if ( drmMap( pMga->drmFD,		pMGADRIServer->primary.handle,		pMGADRIServer->primary.size,		&pMGADRIServer->primary.map ) < 0 ) {      xf86DrvMsg( pScreen->myNum, X_ERROR,		  "[agp] Could not map primary DMA\n" );      return FALSE;   }   xf86DrvMsg( pScreen->myNum, X_INFO,	       "[agp] Primary DMA mapped at 0x%08lx\n",	       (unsigned long)pMGADRIServer->primary.map );   /* DMA buffers    */   if ( drmAddMap( pMga->drmFD,		   pMGADRIServer->buffers.offset,		   pMGADRIServer->buffers.size,		   DRM_AGP, 0,		   &pMGADRIServer->buffers.handle ) < 0 ) {      xf86DrvMsg( pScreen->myNum, X_ERROR,		  "[agp] Could not add DMA buffers mapping\n" );      return FALSE;   }   xf86DrvMsg( pScreen->myNum, X_INFO,	       "[agp] DMA buffers handle = 0x%08lx\n",	       pMGADRIServer->buffers.handle );   if ( drmMap( pMga->drmFD,		pMGADRIServer->buffers.handle,		pMGADRIServer->buffers.size,		&pMGADRIServer->buffers.map ) < 0 ) {      xf86DrvMsg( pScreen->myNum, X_ERROR,		  "[agp] Could not map DMA buffers\n" );      return FALSE;   }   xf86DrvMsg( pScreen->myNum, X_INFO,	       "[agp] DMA buffers mapped at 0x%08lx\n",	       (unsigned long)pMGADRIServer->buffers.map );   count = drmAddBufs( pMga->drmFD,		       MGA_NUM_BUFFERS, MGA_BUFFER_SIZE,		       DRM_AGP_BUFFER, pMGADRIServer->buffers.offset );   if ( count <= 0 ) {      xf86DrvMsg( pScrn->scrnIndex, X_INFO,		  "[drm] failure adding %d %d byte DMA buffers\n",		  MGA_NUM_BUFFERS, MGA_BUFFER_SIZE );      return FALSE;   }   xf86DrvMsg( pScreen->myNum, X_INFO,	       "[drm] Added %d %d byte DMA buffers\n",	       count, MGA_BUFFER_SIZE );   xf86EnablePciBusMaster( pMga->PciInfo, TRUE );   return TRUE;}