/* The screen is being closed, so clean up any state and free any resources used by the DRI. */ void R128DRICloseScreen(const DRIDriverContext *ctx) { R128InfoPtr info = ctx->driverPrivate; drm_r128_init_t drmInfo; /* Stop the CCE if it is still in use */ R128CCE_STOP(ctx, info); if (info->irq) { drmCtlUninstHandler(ctx->drmFD); info->irq = 0; } /* De-allocate vertex buffers */ if (info->buffers) { drmUnmapBufs(info->buffers); info->buffers = NULL; } /* De-allocate all kernel resources */ memset(&drmInfo, 0, sizeof(drmInfo)); drmInfo.func = R128_CLEANUP_CCE; drmCommandWrite(ctx->drmFD, DRM_R128_INIT, &drmInfo, sizeof(drmInfo)); /* De-allocate all AGP resources */ if (info->agpTex) { drmUnmap(info->agpTex, info->agpTexMapSize); info->agpTex = NULL; } if (info->buf) { drmUnmap(info->buf, info->bufMapSize); info->buf = NULL; } if (info->ringReadPtr) { drmUnmap(info->ringReadPtr, info->ringReadMapSize); info->ringReadPtr = NULL; } if (info->ring) { drmUnmap(info->ring, info->ringMapSize); info->ring = NULL; } if (info->agpMemHandle != DRM_AGP_NO_HANDLE) { drmAgpUnbind(ctx->drmFD, info->agpMemHandle); drmAgpFree(ctx->drmFD, info->agpMemHandle); info->agpMemHandle = 0; drmAgpRelease(ctx->drmFD); } if (info->pciMemHandle) { drmScatterGatherFree(ctx->drmFD, info->pciMemHandle); info->pciMemHandle = 0; } }
void I810DRICloseScreen(ScreenPtr pScreen) { ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); I810Ptr pI810 = I810PTR(pScrn); if (pI810->pDRIInfo) { I810DRIPtr pI810DRI = (I810DRIPtr) pI810->pDRIInfo->devPrivate; if (pI810DRI) { if (pI810DRI->irq) { drmCtlUninstHandler(pI810->drmSubFD); pI810DRI->irq = 0; } free(pI810->pDRIInfo->devPrivate); pI810->pDRIInfo->devPrivate = NULL; } I810CleanupDma(pScrn); DRICloseScreen(pScreen); DRIDestroyInfoRec(pI810->pDRIInfo); pI810->pDRIInfo = NULL; } if (pI810->dcacheHandle!=DRM_AGP_NO_HANDLE) drmAgpFree(pI810->drmSubFD, pI810->dcacheHandle); if (pI810->backHandle!=DRM_AGP_NO_HANDLE) drmAgpFree(pI810->drmSubFD, pI810->backHandle); if (pI810->zHandle!=DRM_AGP_NO_HANDLE) drmAgpFree(pI810->drmSubFD, pI810->zHandle); if (pI810->cursorHandle!=DRM_AGP_NO_HANDLE) drmAgpFree(pI810->drmSubFD, pI810->cursorHandle); if (pI810->xvmcHandle!=DRM_AGP_NO_HANDLE) drmAgpFree(pI810->drmSubFD, pI810->xvmcHandle); if (pI810->sysmemHandle!=DRM_AGP_NO_HANDLE) drmAgpFree(pI810->drmSubFD, pI810->sysmemHandle); if (pI810->agpAcquired == TRUE) drmAgpRelease(pI810->drmSubFD); pI810->backHandle = DRM_AGP_NO_HANDLE; pI810->zHandle = DRM_AGP_NO_HANDLE; pI810->cursorHandle = DRM_AGP_NO_HANDLE; pI810->xvmcHandle = DRM_AGP_NO_HANDLE; pI810->sysmemHandle = DRM_AGP_NO_HANDLE; pI810->agpAcquired = FALSE; pI810->dcacheHandle = DRM_AGP_NO_HANDLE; }
Bool I810DRILeave(ScrnInfoPtr pScrn) { I810Ptr pI810 = I810PTR(pScrn); if (pI810->directRenderingEnabled) { if (pI810->dcacheHandle != 0) if (drmAgpUnbind(pI810->drmSubFD, pI810->dcacheHandle) != 0) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR,"%s\n",strerror(errno)); return FALSE; } if (pI810->backHandle != 0) if (drmAgpUnbind(pI810->drmSubFD, pI810->backHandle) != 0) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR,"%s\n",strerror(errno)); return FALSE; } if (pI810->zHandle != 0) if (drmAgpUnbind(pI810->drmSubFD, pI810->zHandle) != 0) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR,"%s\n",strerror(errno)); return FALSE; } if (pI810->sysmemHandle != 0) if (drmAgpUnbind(pI810->drmSubFD, pI810->sysmemHandle) != 0) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR,"%s\n",strerror(errno)); return FALSE; } if (pI810->xvmcHandle != 0) if (drmAgpUnbind(pI810->drmSubFD, pI810->xvmcHandle) != 0) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR,"%s\n",strerror(errno)); return FALSE; } if (pI810->cursorHandle != 0) if (drmAgpUnbind(pI810->drmSubFD, pI810->cursorHandle) != 0) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR,"%s\n",strerror(errno)); return FALSE; } if (pI810->cursorARGBHandle != 0) if (drmAgpUnbind(pI810->drmSubFD, pI810->cursorARGBHandle) != 0) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR,"%s\n",strerror(errno)); return FALSE; } if (pI810->agpAcquired == TRUE) drmAgpRelease(pI810->drmSubFD); pI810->agpAcquired = FALSE; } return TRUE; }
/* Initialize the AGP state. Request memory for use in AGP space, and initialize the Rage 128 registers to point to that memory. */ static GLboolean R128DRIAgpInit(const DRIDriverContext *ctx) { unsigned char *R128MMIO = ctx->MMIOAddress; R128InfoPtr info = ctx->driverPrivate; unsigned long mode; unsigned int vendor, device; int ret; unsigned long cntl, chunk; int s, l; int flags; unsigned long agpBase; if (drmAgpAcquire(ctx->drmFD) < 0) { fprintf(stderr, "[agp] AGP not available\n"); return GL_FALSE; } /* Modify the mode if the default mode is not appropriate for this particular combination of graphics card and AGP chipset. */ mode = drmAgpGetMode(ctx->drmFD); /* Default mode */ vendor = drmAgpVendorId(ctx->drmFD); device = drmAgpDeviceId(ctx->drmFD); mode &= ~R128_AGP_MODE_MASK; switch (info->agpMode) { case 4: mode |= R128_AGP_4X_MODE; case 2: mode |= R128_AGP_2X_MODE; case 1: default: mode |= R128_AGP_1X_MODE; } fprintf(stderr, "[agp] Mode 0x%08lx [AGP 0x%04x/0x%04x; Card 0x%04x/0x%04x]\n", mode, vendor, device, 0x1002, info->Chipset); if (drmAgpEnable(ctx->drmFD, mode) < 0) { fprintf(stderr, "[agp] AGP not enabled\n"); drmAgpRelease(ctx->drmFD); return GL_FALSE; } info->agpOffset = 0; if ((ret = drmAgpAlloc(ctx->drmFD, info->agpSize*1024*1024, 0, NULL, &info->agpMemHandle)) < 0) { fprintf(stderr, "[agp] Out of memory (%d)\n", ret); drmAgpRelease(ctx->drmFD); return GL_FALSE; } fprintf(stderr, "[agp] %d kB allocated with handle 0x%08x\n", info->agpSize*1024, info->agpMemHandle); if (drmAgpBind(ctx->drmFD, info->agpMemHandle, info->agpOffset) < 0) { fprintf(stderr, "[agp] Could not bind\n"); drmAgpFree(ctx->drmFD, info->agpMemHandle); drmAgpRelease(ctx->drmFD); return GL_FALSE; } /* Initialize the CCE ring buffer data */ info->ringStart = info->agpOffset; info->ringMapSize = info->ringSize*1024*1024 + r128_drm_page_size; info->ringSizeLog2QW = R128MinBits(info->ringSize*1024*1024/8) - 1; info->ringReadOffset = info->ringStart + info->ringMapSize; info->ringReadMapSize = r128_drm_page_size; /* Reserve space for vertex/indirect buffers */ info->bufStart = info->ringReadOffset + info->ringReadMapSize; info->bufMapSize = info->bufSize*1024*1024; /* Reserve the rest for AGP textures */ info->agpTexStart = info->bufStart + info->bufMapSize; s = (info->agpSize*1024*1024 - info->agpTexStart); l = R128MinBits((s-1) / R128_NR_TEX_REGIONS); if (l < R128_LOG_TEX_GRANULARITY) l = R128_LOG_TEX_GRANULARITY; info->agpTexMapSize = (s >> l) << l; info->log2AGPTexGran = l; if (info->CCESecure) flags = DRM_READ_ONLY; else flags = 0; if (drmAddMap(ctx->drmFD, info->ringStart, info->ringMapSize, DRM_AGP, flags, &info->ringHandle) < 0) { fprintf(stderr, "[agp] Could not add ring mapping\n"); return GL_FALSE; } fprintf(stderr, "[agp] ring handle = 0x%08x\n", info->ringHandle); if (drmMap(ctx->drmFD, info->ringHandle, info->ringMapSize, (drmAddressPtr)&info->ring) < 0) { fprintf(stderr, "[agp] Could not map ring\n"); return GL_FALSE; } fprintf(stderr, "[agp] Ring mapped at 0x%08lx\n", (unsigned long)info->ring); if (drmAddMap(ctx->drmFD, info->ringReadOffset, info->ringReadMapSize, DRM_AGP, flags, &info->ringReadPtrHandle) < 0) { fprintf(stderr, "[agp] Could not add ring read ptr mapping\n"); return GL_FALSE; } fprintf(stderr, "[agp] ring read ptr handle = 0x%08x\n", info->ringReadPtrHandle); if (drmMap(ctx->drmFD, info->ringReadPtrHandle, info->ringReadMapSize, (drmAddressPtr)&info->ringReadPtr) < 0) { fprintf(stderr, "[agp] Could not map ring read ptr\n"); return GL_FALSE; } fprintf(stderr, "[agp] Ring read ptr mapped at 0x%08lx\n", (unsigned long)info->ringReadPtr); if (drmAddMap(ctx->drmFD, info->bufStart, info->bufMapSize, DRM_AGP, 0, &info->bufHandle) < 0) { fprintf(stderr, "[agp] Could not add vertex/indirect buffers mapping\n"); return GL_FALSE; } fprintf(stderr, "[agp] vertex/indirect buffers handle = 0x%08lx\n", info->bufHandle); if (drmMap(ctx->drmFD, info->bufHandle, info->bufMapSize, (drmAddressPtr)&info->buf) < 0) { fprintf(stderr, "[agp] Could not map vertex/indirect buffers\n"); return GL_FALSE; } fprintf(stderr, "[agp] Vertex/indirect buffers mapped at 0x%08lx\n", (unsigned long)info->buf); if (drmAddMap(ctx->drmFD, info->agpTexStart, info->agpTexMapSize, DRM_AGP, 0, &info->agpTexHandle) < 0) { fprintf(stderr, "[agp] Could not add AGP texture map mapping\n"); return GL_FALSE; } fprintf(stderr, "[agp] AGP texture map handle = 0x%08lx\n", info->agpTexHandle); if (drmMap(ctx->drmFD, info->agpTexHandle, info->agpTexMapSize, (drmAddressPtr)&info->agpTex) < 0) { fprintf(stderr, "[agp] Could not map AGP texture map\n"); return GL_FALSE; } fprintf(stderr, "[agp] AGP Texture map mapped at 0x%08lx\n", (unsigned long)info->agpTex); /* Initialize Rage 128's AGP registers */ cntl = INREG(R128_AGP_CNTL); cntl &= ~R128_AGP_APER_SIZE_MASK; switch (info->agpSize) { case 256: cntl |= R128_AGP_APER_SIZE_256MB; break; case 128: cntl |= R128_AGP_APER_SIZE_128MB; break; case 64: cntl |= R128_AGP_APER_SIZE_64MB; break; case 32: cntl |= R128_AGP_APER_SIZE_32MB; break; case 16: cntl |= R128_AGP_APER_SIZE_16MB; break; case 8: cntl |= R128_AGP_APER_SIZE_8MB; break; case 4: cntl |= R128_AGP_APER_SIZE_4MB; break; default: fprintf(stderr, "[agp] Illegal aperture size %d kB\n", info->agpSize*1024); return GL_FALSE; } agpBase = drmAgpBase(ctx->drmFD); OUTREG(R128_AGP_BASE, agpBase); OUTREG(R128_AGP_CNTL, cntl); /* Disable Rage 128's PCIGART registers */ chunk = INREG(R128_BM_CHUNK_0_VAL); chunk &= ~(R128_BM_PTR_FORCE_TO_PCI | R128_BM_PM4_RD_FORCE_TO_PCI | R128_BM_GLOBAL_FORCE_TO_PCI); OUTREG(R128_BM_CHUNK_0_VAL, chunk); OUTREG(R128_PCI_GART_PAGE, 1); /* Ensure AGP GART is used (for now) */ return GL_TRUE; }