📄 radeon_dri.c
字号:
*/void RADEONDRIResume(ScreenPtr pScreen){ int _ret; ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; RADEONInfoPtr info = RADEONPTR(pScrn); if (info->pKernelDRMVersion->version_minor >= 9) { xf86DrvMsg(pScreen->myNum, X_INFO, "[RESUME] Attempting to re-init Radeon hardware.\n"); } else { xf86DrvMsg(pScreen->myNum, X_WARNING, "[RESUME] Cannot re-init Radeon hardware, DRM too old\n" "(need 1.9.0 or newer)\n"); return; } if (info->cardType==CARD_AGP) { if (!RADEONSetAgpMode(info, pScreen)) return; RADEONSetAgpBase(info); } _ret = drmCommandNone(info->drmFD, DRM_RADEON_CP_RESUME); if (_ret) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "%s: CP resume %d\n", __FUNCTION__, _ret); /* FIXME: return? */ } RADEONEngineRestore(pScrn); RADEONDRICPInit(pScrn);}void RADEONDRIStop(ScreenPtr pScreen){ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; RADEONInfoPtr info = RADEONPTR(pScrn); RING_LOCALS; RADEONTRACE(("RADEONDRIStop\n")); /* Stop the CP */ if (info->directRenderingInited) { /* If we've generated any CP commands, we must flush them to the * kernel module now. */ if (info->CPInUse) { RADEON_FLUSH_CACHE(); RADEON_WAIT_UNTIL_IDLE(); RADEONCPReleaseIndirect(pScrn); info->CPInUse = FALSE; } RADEONCP_STOP(pScrn, info); } info->directRenderingInited = FALSE;}/* The screen is being closed, so clean up any state and free any * resources used by the DRI. */void RADEONDRICloseScreen(ScreenPtr pScreen){ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; RADEONInfoPtr info = RADEONPTR(pScrn); drmRadeonInit drmInfo; RADEONTRACE(("RADEONDRICloseScreen\n")); if (info->irq) { drmCtlUninstHandler(info->drmFD); info->irq = 0; info->ModeReg.gen_int_cntl = 0; } /* De-allocate vertex buffers */ if (info->buffers) { drmUnmapBufs(info->buffers); info->buffers = NULL; } /* De-allocate all kernel resources */ memset(&drmInfo, 0, sizeof(drmRadeonInit)); drmInfo.func = DRM_RADEON_CLEANUP_CP; drmCommandWrite(info->drmFD, DRM_RADEON_CP_INIT, &drmInfo, sizeof(drmRadeonInit)); /* De-allocate all GART resources */ if (info->gartTex) { drmUnmap(info->gartTex, info->gartTexMapSize); info->gartTex = 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(info->drmFD, info->agpMemHandle); drmAgpFree(info->drmFD, info->agpMemHandle); info->agpMemHandle = DRM_AGP_NO_HANDLE; drmAgpRelease(info->drmFD); } if (info->pciMemHandle) { drmScatterGatherFree(info->drmFD, info->pciMemHandle); info->pciMemHandle = 0; } if (info->pciGartBackup) { xfree(info->pciGartBackup); info->pciGartBackup = NULL; } /* De-allocate all DRI resources */ DRICloseScreen(pScreen); /* De-allocate all DRI data structures */ if (info->pDRIInfo) { if (info->pDRIInfo->devPrivate) { xfree(info->pDRIInfo->devPrivate); info->pDRIInfo->devPrivate = NULL; } DRIDestroyInfoRec(info->pDRIInfo); info->pDRIInfo = NULL; } if (info->pVisualConfigs) { xfree(info->pVisualConfigs); info->pVisualConfigs = NULL; } if (info->pVisualConfigsPriv) { xfree(info->pVisualConfigsPriv); info->pVisualConfigsPriv = NULL; }}#ifdef USE_XAA/* Use callbacks from dri.c to support pageflipping mode for a single * 3d context without need for any specific full-screen extension. * * Also use these callbacks to allocate and free 3d-specific memory on * demand. *//* Use the shadowfb module to maintain a list of dirty rectangles. * These are blitted to the back buffer to keep both buffers clean * during page-flipping when the 3d application isn't fullscreen. * * Unlike most use of the shadowfb code, both buffers are in video memory. * * An alternative to this would be to organize for all on-screen drawing * operations to be duplicated for the two buffers. That might be * faster, but seems like a lot more work... */static void RADEONDRIRefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox){ RADEONInfoPtr info = RADEONPTR(pScrn); int i; RADEONSAREAPrivPtr pSAREAPriv = DRIGetSAREAPrivate(pScrn->pScreen); if (!info->directRenderingInited) return; /* Don't want to do this when no 3d is active and pages are * right-way-round */ if (!pSAREAPriv->pfAllowPageFlip && pSAREAPriv->pfCurrentPage == 0) return; /* XXX: implement for EXA */ /* pretty much a hack. */ /* Make sure accel has been properly inited */ if (info->accel == NULL || info->accel->SetupForScreenToScreenCopy == NULL) return; if (info->tilingEnabled) info->dst_pitch_offset |= RADEON_DST_TILE_MACRO; (*info->accel->SetupForScreenToScreenCopy)(pScrn, 1, 1, GXcopy, (CARD32)(-1), -1); for (i = 0 ; i < num ; i++, pbox++) { int xa = max(pbox->x1, 0), xb = min(pbox->x2, pScrn->virtualX-1); int ya = max(pbox->y1, 0), yb = min(pbox->y2, pScrn->virtualY-1); if (xa <= xb && ya <= yb) { (*info->accel->SubsequentScreenToScreenCopy)(pScrn, xa, ya, xa + info->backX, ya + info->backY, xb - xa + 1, yb - ya + 1); } } info->dst_pitch_offset &= ~RADEON_DST_TILE_MACRO;}#endif /* USE_XAA */static void RADEONEnablePageFlip(ScreenPtr pScreen){#ifdef USE_XAA ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; RADEONInfoPtr info = RADEONPTR(pScrn); RADEONSAREAPrivPtr pSAREAPriv = DRIGetSAREAPrivate(pScreen); /* XXX: Fix in EXA case */ if (info->allowPageFlip) { /* pretty much a hack. */ if (info->tilingEnabled) info->dst_pitch_offset |= RADEON_DST_TILE_MACRO; /* Duplicate the frontbuffer to the backbuffer */ (*info->accel->SetupForScreenToScreenCopy)(pScrn, 1, 1, GXcopy, (CARD32)(-1), -1); (*info->accel->SubsequentScreenToScreenCopy)(pScrn, 0, 0, info->backX, info->backY, pScrn->virtualX, pScrn->virtualY); info->dst_pitch_offset &= ~RADEON_DST_TILE_MACRO; pSAREAPriv->pfAllowPageFlip = 1; }#endif /* USE_XAA */}static void RADEONDisablePageFlip(ScreenPtr pScreen){ /* Tell the clients not to pageflip. How? * -- Field in sarea, plus bumping the window counters. * -- DRM needs to cope with Front-to-Back swapbuffers. */ RADEONSAREAPrivPtr pSAREAPriv = DRIGetSAREAPrivate(pScreen); pSAREAPriv->pfAllowPageFlip = 0;}static void RADEONDRITransitionSingleToMulti3d(ScreenPtr pScreen){ RADEONDisablePageFlip(pScreen);}static void RADEONDRITransitionMultiToSingle3d(ScreenPtr pScreen){ /* Let the remaining 3d app start page flipping again */ RADEONEnablePageFlip(pScreen);}static void RADEONDRITransitionTo3d(ScreenPtr pScreen){ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; RADEONInfoPtr info = RADEONPTR(pScrn);#ifdef USE_XAA FBAreaPtr fbarea; int width, height; /* EXA allocates these areas up front, so it doesn't do the following * stuff. */ if (!info->useEXA) { /* reserve offscreen area for back and depth buffers and textures */ /* If we still have an area for the back buffer reserved, free it * first so we always start with all free offscreen memory, except * maybe for Xv */ if (info->backArea) { xf86FreeOffscreenArea(info->backArea); info->backArea = NULL; } xf86PurgeUnlockedOffscreenAreas(pScreen); xf86QueryLargestOffscreenArea(pScreen, &width, &height, 0, 0, 0); /* Free Xv linear offscreen memory if necessary * FIXME: This is hideous. What about telling xv "oh btw you have no memory * any more?" -- anholt */ if (height < (info->depthTexLines + info->backLines)) { RADEONPortPrivPtr portPriv = info->adaptor->pPortPrivates[0].ptr; xf86FreeOffscreenLinear((FBLinearPtr)portPriv->video_memory); portPriv->video_memory = NULL; xf86QueryLargestOffscreenArea(pScreen, &width, &height, 0, 0, 0); } /* Reserve placeholder area so the other areas will match the * pre-calculated offsets * FIXME: We may have other locked allocations and thus this would allocate * in the wrong place. The XV surface allocations seem likely. -- anholt */ fbarea = xf86AllocateOffscreenArea(pScreen, pScrn->displayWidth, height - info->depthTexLines - info->backLines, pScrn->displayWidth, NULL, NULL, NULL); if (!fbarea) xf86DrvMsg(pScreen->myNum, X_ERROR, "Unable to reserve placeholder " "offscreen area, you might experience screen corruption\n"); info->backArea = xf86AllocateOffscreenArea(pScreen, pScrn->displayWidth, info->backLines, pScrn->displayWidth, NULL, NULL, NULL); if (!info->backArea) xf86DrvMsg(pScreen->myNum, X_ERROR, "Unable to reserve offscreen " "area for back buffer, you might experience screen " "corruption\n"); info->depthTexArea = xf86AllocateOffscreenArea(pScreen, pScrn->displayWidth, info->depthTexLines, pScrn->displayWidth, NULL, NULL, NULL); if (!info->depthTexArea) xf86DrvMsg(pScreen->myNum, X_ERROR, "Unable to reserve offscreen " "area for depth buffer and textures, you might " "experience screen corruption\n"); xf86FreeOffscreenArea(fbarea); }#endif /* USE_XAA */ info->have3DWindows = 1; RADEONChangeSurfaces(pScrn); RADEONEnablePageFlip(pScreen); if (info->cursor) xf86ForceHWCursor (pScreen, TRUE);}static void RADEONDRITransitionTo2d(ScreenPtr pScreen){ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; RADEONInfoPtr info = RADEONPTR(pScrn); RADEONSAREAPrivPtr pSAREAPriv = DRIGetSAREAPrivate(pScreen); /* Try flipping back to the front page if necessary */ if (pSAREAPriv->pfCurrentPage == 1) drmCommandNone(info->drmFD, DRM_RADEON_FLIP); /* Shut down shadowing if we've made it back to the front page */ if (pSAREAPriv->pfCurrentPage == 0) { RADEONDisablePageFlip(pScreen);#ifdef USE_XAA if (!info->useEXA) { xf86FreeOffscreenArea(info->backArea); info->backArea = NULL; }#endif } else { xf86DrvMsg(pScreen->myNum, X_WARNING, "[dri] RADEONDRITransitionTo2d: " "kernel failed to unflip buffers.\n"); }#ifdef USE_XAA if (!info->useEXA) xf86FreeOffscreenArea(info->depthTexArea);#endif info->have3DWindows = 0; RADEONChangeSurfaces(pScrn); if (info->cursor) xf86ForceHWCursor (pScreen, FALSE);}void RADEONDRIAllocatePCIGARTTable(ScreenPtr pScreen){ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; RADEONInfoPtr info = RADEONPTR(pScrn); if (info->cardType != CARD_PCIE || info->pKernelDRMVersion->version_minor < 19) return; if (info->FbSecureSize==0) return; info->pciGartSize = RADEON_PCIGART_TABLE_SIZE; /* allocate space to back up PCIEGART table */ info->pciGartBackup = xnfcalloc(1, info->pciGartSize); if (info->pciGartBackup == NULL) return; info->pciGartOffset = (info->FbMapSize - info->FbSecureSize);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -