i830_memory.c
来自「是由intel提供的针对intel显卡915以上系列的linux驱动」· C语言 代码 · 共 1,966 行 · 第 1/4 页
C
1,966 行
topOfMem = pI830->StolenPool.Total.End; if (pI830->entityPrivate && pI830->entityPrivate->pScrn_2) I830FixOffset(pScrn, &(pI830->FrontBuffer2)); I830FixOffset(pScrn, &(pI830->FrontBuffer)); I830FixOffset(pScrn, pI830->CursorMem); I830FixOffset(pScrn, pI830->CursorMemARGB); I830FixOffset(pScrn, &(pI830->LpRing->mem)); I830FixOffset(pScrn, &(pI830->Scratch)); if (pI830->entityPrivate && pI830->entityPrivate->pScrn_2) I830FixOffset(pScrn, &(pI830->Scratch2));#ifdef I830_XV if (pI830->XvEnabled) { I830FixOffset(pScrn, pI830->OverlayMem); }#endif#ifdef XF86DRI if (pI830->directRenderingEnabled) { I830FixOffset(pScrn, &(pI830->ContextMem)); I830FixOffset(pScrn, &(pI830->BackBuffer)); I830FixOffset(pScrn, &(pI830->DepthBuffer)); I830FixOffset(pScrn, &(pI830->TexMem)); }#endif return TRUE;}#ifdef XF86DRI/* Tiled memory is good... really, really good... * * Need to make it less likely that we miss out on this - probably * need to move the frontbuffer away from the 'guarenteed' alignment * of the first memory segment, or perhaps allocate a discontigous * framebuffer to get more alignment 'sweet spots'. */static voidSetFence(ScrnInfoPtr pScrn, int nr, unsigned int start, unsigned int pitch, unsigned int size){ I830Ptr pI830 = I830PTR(pScrn); I830RegPtr i830Reg = &pI830->ModeReg; CARD32 val; CARD32 fence_mask = 0; unsigned int fence_pitch; DPRINTF(PFX, "SetFence: %d, 0x%08x, %d, %d kByte\n", nr, start, pitch, size / 1024); if (nr < 0 || nr > 7) { xf86DrvMsg(X_WARNING, pScrn->scrnIndex, "SetFence: fence %d out of range\n",nr); return; } i830Reg->Fence[nr] = 0; if (IS_I9XX(pI830)) fence_mask = ~I915G_FENCE_START_MASK; else fence_mask = ~I830_FENCE_START_MASK; if (start & fence_mask) { xf86DrvMsg(X_WARNING, pScrn->scrnIndex, "SetFence: %d: start (0x%08x) is not %s aligned\n", nr, start, (IS_I9XX(pI830)) ? "1MB" : "512k"); return; } if (start % size) { xf86DrvMsg(X_WARNING, pScrn->scrnIndex, "SetFence: %d: start (0x%08x) is not size (%dk) aligned\n", nr, start, size / 1024); return; } if (pitch & 127) { xf86DrvMsg(X_WARNING, pScrn->scrnIndex, "SetFence: %d: pitch (%d) not a multiple of 128 bytes\n", nr, pitch); return; } val = (start | FENCE_X_MAJOR | FENCE_VALID); if (IS_I9XX(pI830)) { switch (size) { case MB(1): val |= I915G_FENCE_SIZE_1M; break; case MB(2): val |= I915G_FENCE_SIZE_2M; break; case MB(4): val |= I915G_FENCE_SIZE_4M; break; case MB(8): val |= I915G_FENCE_SIZE_8M; break; case MB(16): val |= I915G_FENCE_SIZE_16M; break; case MB(32): val |= I915G_FENCE_SIZE_32M; break; case MB(64): val |= I915G_FENCE_SIZE_64M; break; default: xf86DrvMsg(X_WARNING, pScrn->scrnIndex, "SetFence: %d: illegal size (%d kByte)\n", nr, size / 1024); return; } } else { switch (size) { case KB(512): val |= FENCE_SIZE_512K; break; case MB(1): val |= FENCE_SIZE_1M; break; case MB(2): val |= FENCE_SIZE_2M; break; case MB(4): val |= FENCE_SIZE_4M; break; case MB(8): val |= FENCE_SIZE_8M; break; case MB(16): val |= FENCE_SIZE_16M; break; case MB(32): val |= FENCE_SIZE_32M; break; case MB(64): val |= FENCE_SIZE_64M; break; default: xf86DrvMsg(X_WARNING, pScrn->scrnIndex, "SetFence: %d: illegal size (%d kByte)\n", nr, size / 1024); return; } } if (IS_I9XX(pI830)) fence_pitch = pitch / 512; else fence_pitch = pitch / 128; switch (fence_pitch) { case 1: val |= FENCE_PITCH_1; break; case 2: val |= FENCE_PITCH_2; break; case 4: val |= FENCE_PITCH_4; break; case 8: val |= FENCE_PITCH_8; break; case 16: val |= FENCE_PITCH_16; break; case 32: val |= FENCE_PITCH_32; break; case 64: val |= FENCE_PITCH_64; break; default: xf86DrvMsg(X_WARNING, pScrn->scrnIndex, "SetFence: %d: illegal pitch (%d)\n", nr, pitch); return; } i830Reg->Fence[nr] = val;}static BoolMakeTiles(ScrnInfoPtr pScrn, I830MemRange *pMem){ I830Ptr pI830 = I830PTR(pScrn); int pitch, ntiles, i;#if 0 /* Hack to "improve" the alignment of the front buffer. */ while (!(pMem->Start & ~pMem->Alignment) && pMem->Alignment < 0x00400000 ) pMem->Alignment <<= 1;#endif if (tileGeneration != serverGeneration) { tileGeneration = serverGeneration; nextTile = 0; } pitch = pScrn->displayWidth * pI830->cpp; /* * Simply try to break the region up into at most four pieces of size * equal to the alignment. */ ntiles = ROUND_TO(pMem->Size, pMem->Alignment) / pMem->Alignment; if (ntiles >= 4) { return FALSE; } for (i = 0; i < ntiles; i++, nextTile++) { SetFence(pScrn, nextTile, pMem->Start + i * pMem->Alignment, pitch, pMem->Alignment); } return TRUE;}voidI830SetupMemoryTiling(ScrnInfoPtr pScrn){ I830Ptr pI830 = I830PTR(pScrn); int i; /* Clear out */ for (i = 0; i < 8; i++) pI830->ModeReg.Fence[i] = 0; nextTile = 0; tileGeneration = -1; /* We currently only attempt to tile the back and depth buffers. */ if (!pI830->directRenderingEnabled) return; if (!IsTileable(pScrn->displayWidth * pI830->cpp)) { xf86DrvMsg(pScrn->scrnIndex, X_INFO, "I830SetupMemoryTiling: Not tileable 0x%x\n", pScrn->displayWidth * pI830->cpp); pI830->allowPageFlip = FALSE; return; } if (pI830->allowPageFlip) { if (pI830->allowPageFlip && pI830->FrontBuffer.Alignment >= KB(512)) { if (MakeTiles(pScrn, &(pI830->FrontBuffer))) { xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Activating tiled memory for the FRONT buffer\n"); } else { pI830->allowPageFlip = FALSE; xf86DrvMsg(pScrn->scrnIndex, X_INFO, "MakeTiles failed for the FRONT buffer\n"); } } else { pI830->allowPageFlip = FALSE; xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Alignment bad for the FRONT buffer\n"); } } /* * We tried to get the best alignment during the allocation. Check * the alignment values to tell. If well-aligned allocations were * successful, the address range reserved is a multiple of the align * value. */ if (pI830->BackBuffer.Alignment >= KB(512)) { if (MakeTiles(pScrn, &(pI830->BackBuffer))) { xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Activating tiled memory for the back buffer.\n"); } else { xf86DrvMsg(pScrn->scrnIndex, X_INFO, "MakeTiles failed for the back buffer.\n"); pI830->allowPageFlip = FALSE; } } if (pI830->DepthBuffer.Alignment >= KB(512)) { if (MakeTiles(pScrn, &(pI830->DepthBuffer))) { xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Activating tiled memory for the depth buffer.\n"); } else { xf86DrvMsg(pScrn->scrnIndex, X_INFO, "MakeTiles failed for the depth buffer.\n"); } } if (pI830->RotatedMem.Alignment >= KB(512)) { if (MakeTiles(pScrn, &(pI830->RotatedMem))) { xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Activating tiled memory for the rotated buffer.\n"); } else { xf86DrvMsg(pScrn->scrnIndex, X_INFO, "MakeTiles failed for the rotated buffer.\n"); } }#if 0 if (pI830->RotatedMem2.Alignment >= KB(512)) { if (MakeTiles(pScrn, &(pI830->RotatedMem2))) { xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Activating tiled memory for the rotated2 buffer.\n"); } else { xf86DrvMsg(pScrn->scrnIndex, X_INFO, "MakeTiles failed for the rotated buffer.\n"); } }#endif}#endif /* XF86DRI */static BoolBindMemRange(ScrnInfoPtr pScrn, I830MemRange *mem){ if (!mem) return FALSE; if (mem->Key == -1) return TRUE; return I830BindGARTMemory(pScrn->scrnIndex, mem->Key, mem->Offset);}BoolI830BindAGPMemory(ScrnInfoPtr pScrn){ I830Ptr pI830 = I830PTR(pScrn); DPRINTF(PFX, "I830BindAGPMemory: StolenOnly is %s, pI830->GttBound is %s\n", BOOLTOSTRING(pI830->StolenOnly), BOOLTOSTRING(pI830->GttBound)); if (pI830->StolenOnly == TRUE) return TRUE; if (I830AgpGARTSupported() && !pI830->GttBound) { if (!I830AcquireGART(pScrn->scrnIndex)) return FALSE;#if REMAP_RESERVED /* Rebind the pre-allocated region. */ BindMemRange(pScrn, &(pI830->Dummy));#endif if (!BindMemRange(pScrn, &(pI830->StolenPool.Allocated))) return FALSE; if (pI830->entityPrivate && pI830->entityPrivate->pScrn_2) if (!BindMemRange(pScrn, &(pI830->FrontBuffer2))) return FALSE; if (!BindMemRange(pScrn, &(pI830->FrontBuffer))) return FALSE; if (!BindMemRange(pScrn, pI830->CursorMem)) return FALSE; if (!BindMemRange(pScrn, pI830->CursorMemARGB)) return FALSE; if (!BindMemRange(pScrn, &(pI830->LpRing->mem))) return FALSE; if (!BindMemRange(pScrn, &(pI830->Scratch))) return FALSE; if (pI830->entityPrivate && pI830->entityPrivate->pScrn_2) if (!BindMemRange(pScrn, &(pI830->Scratch2))) return FALSE;#ifdef I830_XV if (!BindMemRange(pScrn, pI830->OverlayMem)) return FALSE;#endif if (pI830->RotatedMem.Start) if (!BindMemRange(pScrn, &(pI830->RotatedMem))) return FALSE; if (pI830->entityPrivate && pI830->entityPrivate->pScrn_2 && pI830->RotatedMem2.Start) if (!BindMemRange(pScrn, &(pI830->RotatedMem2))) return FALSE;#ifdef XF86DRI if (pI830->directRenderingEnabled) { if (!BindMemRange(pScrn, &(pI830->ContextMem))) return FALSE; if (!BindMemRange(pScrn, &(pI830->BackBuffer))) return FALSE; if (!BindMemRange(pScrn, &(pI830->DepthBuffer))) return FALSE; if (!BindMemRange(pScrn, &(pI830->TexMem))) return FALSE; }#endif pI830->GttBound = 1; } return TRUE;}static BoolUnbindMemRange(ScrnInfoPtr pScrn, I830MemRange *mem){ if (!mem) return FALSE; if (mem->Key == -1) return TRUE; return I830UnbindGARTMemory(pScrn->scrnIndex, mem->Key);}BoolI830UnbindAGPMemory(ScrnInfoPtr pScrn){ I830Ptr pI830 = I830PTR(pScrn); DPRINTF(PFX, "I830UnbindAGPMemory: StolenOnly is %s, pI830->GttBound is %s\n", BOOLTOSTRING(pI830->StolenOnly), BOOLTOSTRING(pI830->GttBound)); if (pI830->StolenOnly == TRUE) return TRUE; if (I830AgpGARTSupported() && pI830->GttBound) {#if REMAP_RESERVED /* "unbind" the pre-allocated region. */ UnbindMemRange(pScrn, &(pI830->Dummy));#endif if (!UnbindMemRange(pScrn, &(pI830->StolenPool.Allocated))) return FALSE; if (pI830->entityPrivate && pI830->entityPrivate->pScrn_2) if (!UnbindMemRange(pScrn, &(pI830->FrontBuffer2))) return FALSE; if (!UnbindMemRange(pScrn, &(pI830->FrontBuffer))) return FALSE; if (!UnbindMemRange(pScrn, pI830->CursorMem)) return FALSE; if (!UnbindMemRange(pScrn, pI830->CursorMemARGB)) return FALSE; if (!UnbindMemRange(pScrn, &(pI830->LpRing->mem))) return FALSE; if (!UnbindMemRange(pScrn, &(pI830->Scratch))) return FALSE; if (pI830->entityPrivate && pI830->entityPrivate->pScrn_2) if (!UnbindMemRange(pScrn, &(pI830->Scratch2))) return FALSE;#ifdef I830_XV if (!UnbindMemRange(pScrn, pI830->OverlayMem)) return FALSE;#endif if (pI830->RotatedMem.Start) if (!UnbindMemRange(pScrn, &(pI830->RotatedMem))) return FALSE; if (pI830->entityPrivate && pI830->entityPrivate->pScrn_2 && pI830->RotatedMem2.Start) if (!UnbindMemRange(pScrn, &(pI830->RotatedMem2))) return FALSE;#ifdef XF86DRI if (pI830->directRenderingEnabled) { if (!UnbindMemRange(pScrn, &(pI830->ContextMem))) return FALSE; if (!UnbindMemRange(pScrn, &(pI830->BackBuffer))) return FALSE; if (!UnbindMemRange(pScrn, &(pI830->DepthBuffer))) return FALSE; if (!UnbindMemRange(pScrn, &(pI830->TexMem))) return FALSE; }#endif if (!I830ReleaseGART(pScrn->scrnIndex)) return FALSE; pI830->GttBound = 0; } return TRUE;}longI830CheckAvailableMemory(ScrnInfoPtr pScrn){ AgpInfoPtr agpinf; int maxPages; if (!I830AgpGARTSupported() || !I830AcquireGART(pScrn->scrnIndex) || (agpinf = I830GetAGPInfo(pScrn->scrnIndex)) == NULL || !I830ReleaseGART(pScrn->scrnIndex)) return -1; maxPages = agpinf->totalPages - agpinf->usedPages; xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 2, "%s: %d kB available\n", "I830CheckAvailableMemory", maxPages * 4); return maxPages * 4;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?