📄 intel_dri.c
字号:
pool->Free.Start += needed; result->End = pool->Free.Start; pool->Free.Size = pool->Free.End - pool->Free.Start; result->Size = result->End - result->Start; result->Pool = pool; result->Alignment = alignment; return needed;}static unsigned long AllocFromAGP(const DRIDriverContext *ctx, I830Rec *pI830, long size, unsigned long alignment, I830MemRange *result){ unsigned long start, end; unsigned long newApStart, newApEnd; int ret; if (!result || !size) return 0; if (!alignment) alignment = 4; start = ROUND_TO(pI830->MemoryAperture.Start, alignment); end = ROUND_TO(start + size, alignment); newApStart = end; newApEnd = pI830->MemoryAperture.End; ret=drmAgpAlloc(ctx->drmFD, size, 0, &(result->Physical), (drm_handle_t *)&(result->Key)); if (ret) { fprintf(stderr,"drmAgpAlloc failed %d\n", ret); return 0; } pI830->allocatedMemory += size; pI830->MemoryAperture.Start = newApStart; pI830->MemoryAperture.End = newApEnd; pI830->MemoryAperture.Size = newApEnd - newApStart; // pI830->FreeMemory -= size; result->Start = start; result->End = start + size; result->Size = size; result->Offset = start; result->Alignment = alignment; result->Pool = NULL; return size;}unsigned longI830AllocVidMem(const DRIDriverContext *ctx, I830Rec *pI830, I830MemRange *result, I830MemPool *pool, long size, unsigned long alignment, int flags){ unsigned long ret; if (!result) return 0; /* Make sure these are initialised. */ result->Size = 0; result->Key = -1; if (!size) { return 0; } if (pool->Free.Size < size) { ret = AllocFromAGP(ctx, pI830, size, alignment, result); } else { ret = AllocFromPool(ctx, pI830, result, pool, size, alignment, flags); if (ret == 0) ret = AllocFromAGP(ctx, pI830, size, alignment, result); } return ret;}static Bool BindAgpRange(const DRIDriverContext *ctx, I830MemRange *mem){ if (!mem) return FALSE; if (mem->Key == -1) return TRUE; return !drmAgpBind(ctx->drmFD, mem->Key, mem->Offset);}/* simple memory allocation routines needed *//* put ring buffer in low memory *//* need to allocate front, back, depth buffers aligned correctly, allocate ring buffer, *//* */static BoolI830AllocateMemory(const DRIDriverContext *ctx, I830Rec *pI830){ unsigned long size, ret; unsigned long lines, lineSize, align; /* allocate ring buffer */ memset(pI830->LpRing, 0, sizeof(I830RingBuffer)); pI830->LpRing->mem.Key = -1; size = PRIMARY_RINGBUFFER_SIZE; ret = I830AllocVidMem(ctx, pI830, &pI830->LpRing->mem, &pI830->StolenPool, size, 0x1000, 0); if (ret != size) { fprintf(stderr,"unable to allocate ring buffer %ld\n", ret); return FALSE; } pI830->LpRing->tail_mask = pI830->LpRing->mem.Size - 1; /* allocate front buffer */ memset(&(pI830->FrontBuffer), 0, sizeof(pI830->FrontBuffer)); pI830->FrontBuffer.Key = -1; pI830->FrontBuffer.Pitch = ctx->shared.virtualWidth; align = KB(512); lineSize = ctx->shared.virtualWidth * ctx->cpp; lines = (ctx->shared.virtualHeight + 15) / 16 * 16; size = lineSize * lines; size = ROUND_TO_PAGE(size); align = GetBestTileAlignment(size); ret = I830AllocVidMem(ctx, pI830, &pI830->FrontBuffer, &pI830->StolenPool, size, align, 0); if (ret < size) { fprintf(stderr,"unable to allocate front buffer %ld\n", ret); return FALSE; } memset(&(pI830->BackBuffer), 0, sizeof(pI830->BackBuffer)); pI830->BackBuffer.Key = -1; pI830->BackBuffer.Pitch = ctx->shared.virtualWidth; ret = I830AllocVidMem(ctx, pI830, &pI830->BackBuffer, &pI830->StolenPool, size, align, 0); if (ret < size) { fprintf(stderr,"unable to allocate back buffer %ld\n", ret); return FALSE; } memset(&(pI830->DepthBuffer), 0, sizeof(pI830->DepthBuffer)); pI830->DepthBuffer.Key = -1; pI830->DepthBuffer.Pitch = ctx->shared.virtualWidth; ret = I830AllocVidMem(ctx, pI830, &pI830->DepthBuffer, &pI830->StolenPool, size, align, 0); if (ret < size) { fprintf(stderr,"unable to allocate depth buffer %ld\n", ret); return FALSE; } memset(&(pI830->ContextMem), 0, sizeof(pI830->ContextMem)); pI830->ContextMem.Key = -1; size = KB(32); ret = I830AllocVidMem(ctx, pI830, &pI830->ContextMem, &pI830->StolenPool, size, align, 0); if (ret < size) { fprintf(stderr,"unable to allocate context buffer %ld\n", ret); return FALSE; }#if 0 memset(&(pI830->TexMem), 0, sizeof(pI830->TexMem)); pI830->TexMem.Key = -1; size = 32768 * 1024; ret = AllocFromAGP(ctx, pI830, size, align, &pI830->TexMem); if (ret < size) { fprintf(stderr,"unable to allocate texture memory %ld\n", ret); return FALSE; }#endif return TRUE;}static BoolI830BindMemory(const DRIDriverContext *ctx, I830Rec *pI830){ if (!BindAgpRange(ctx, &pI830->LpRing->mem)) return FALSE; if (!BindAgpRange(ctx, &pI830->FrontBuffer)) return FALSE; if (!BindAgpRange(ctx, &pI830->BackBuffer)) return FALSE; if (!BindAgpRange(ctx, &pI830->DepthBuffer)) return FALSE; if (!BindAgpRange(ctx, &pI830->ContextMem)) return FALSE;#if 0 if (!BindAgpRange(ctx, &pI830->TexMem)) return FALSE;#endif return TRUE;}static void SetupDRIMM(const DRIDriverContext *ctx, I830Rec *pI830){ unsigned long aperEnd = ROUND_DOWN_TO(pI830->aper_size, GTT_PAGE_SIZE) / GTT_PAGE_SIZE; unsigned long aperStart = ROUND_TO(pI830->aper_size - KB(32768), GTT_PAGE_SIZE) / GTT_PAGE_SIZE; fprintf(stderr, "aper size is %08X\n", ctx->shared.fbSize); if (drmMMInit(ctx->drmFD, aperStart, aperEnd - aperStart, DRM_BO_MEM_TT)) { fprintf(stderr, "DRM MM Initialization Failed\n"); } else { fprintf(stderr, "DRM MM Initialized at offset 0x%lx length %d page\n", aperStart, aperEnd-aperStart); }}static BoolI830CleanupDma(const DRIDriverContext *ctx){ drmI830Init info; memset(&info, 0, sizeof(drmI830Init)); info.func = I830_CLEANUP_DMA; if (drmCommandWrite(ctx->drmFD, DRM_I830_INIT, &info, sizeof(drmI830Init))) { fprintf(stderr, "I830 Dma Cleanup Failed\n"); return FALSE; } return TRUE;}static BoolI830InitDma(const DRIDriverContext *ctx, I830Rec *pI830){ I830RingBuffer *ring = pI830->LpRing; drmI830Init info; memset(&info, 0, sizeof(drmI830Init)); info.func = I830_INIT_DMA; info.ring_start = ring->mem.Start + pI830->LinearAddr; info.ring_end = ring->mem.End + pI830->LinearAddr; info.ring_size = ring->mem.Size; info.mmio_offset = (unsigned int)ctx->MMIOStart; info.sarea_priv_offset = sizeof(drm_sarea_t); info.front_offset = pI830->FrontBuffer.Start; info.back_offset = pI830->BackBuffer.Start; info.depth_offset = pI830->DepthBuffer.Start; info.w = ctx->shared.virtualWidth; info.h = ctx->shared.virtualHeight; info.pitch = ctx->shared.virtualWidth; info.back_pitch = pI830->BackBuffer.Pitch; info.depth_pitch = pI830->DepthBuffer.Pitch; info.cpp = ctx->cpp; if (drmCommandWrite(ctx->drmFD, DRM_I830_INIT, &info, sizeof(drmI830Init))) { fprintf(stderr, "I830 Dma Initialization Failed\n"); return FALSE; } return TRUE;}static int I830CheckDRMVersion( const DRIDriverContext *ctx, I830Rec *pI830 ){ drmVersionPtr version; version = drmGetVersion(ctx->drmFD); if (version) { int req_minor, req_patch; req_minor = 4; req_patch = 0; if (version->version_major != 1 || version->version_minor < req_minor || (version->version_minor == req_minor && version->version_patchlevel < req_patch)) { /* Incompatible drm version */ fprintf(stderr, "[dri] I830DRIScreenInit failed because of a version " "mismatch.\n" "[dri] i915.o kernel module version is %d.%d.%d " "but version 1.%d.%d or newer is needed.\n" "[dri] Disabling DRI.\n", version->version_major, version->version_minor, version->version_patchlevel, req_minor, req_patch); drmFreeVersion(version); return 0; } pI830->drmMinor = version->version_minor; drmFreeVersion(version); } return 1;}static voidI830SetRingRegs(const DRIDriverContext *ctx, I830Rec *pI830){ unsigned int itemp; unsigned char *MMIO = ctx->MMIOAddress; OUTREG(LP_RING + RING_LEN, 0); OUTREG(LP_RING + RING_TAIL, 0); OUTREG(LP_RING + RING_HEAD, 0); if ((long)(pI830->LpRing->mem.Start & I830_RING_START_MASK) != pI830->LpRing->mem.Start) { fprintf(stderr, "I830SetRingRegs: Ring buffer start (%lx) violates its " "mask (%x)\n", pI830->LpRing->mem.Start, I830_RING_START_MASK); } /* Don't care about the old value. Reserved bits must be zero anyway. */ itemp = pI830->LpRing->mem.Start & I830_RING_START_MASK; OUTREG(LP_RING + RING_START, itemp); if (((pI830->LpRing->mem.Size - 4096) & I830_RING_NR_PAGES) != pI830->LpRing->mem.Size - 4096) { fprintf(stderr, "I830SetRingRegs: Ring buffer size - 4096 (%lx) violates its " "mask (%x)\n", pI830->LpRing->mem.Size - 4096, I830_RING_NR_PAGES); } /* Don't care about the old value. Reserved bits must be zero anyway. */ itemp = (pI830->LpRing->mem.Size - 4096) & I830_RING_NR_PAGES; itemp |= (RING_NO_REPORT | RING_VALID); OUTREG(LP_RING + RING_LEN, itemp); pI830->LpRing->head = INREG(LP_RING + RING_HEAD) & I830_HEAD_MASK; pI830->LpRing->tail = INREG(LP_RING + RING_TAIL); pI830->LpRing->space = pI830->LpRing->head - (pI830->LpRing->tail + 8); if (pI830->LpRing->space < 0) pI830->LpRing->space += pI830->LpRing->mem.Size; SetFenceRegs(ctx, pI830); /* RESET THE DISPLAY PIPE TO POINT TO THE FRONTBUFFER - hacky hacky hacky */ OUTREG(DSPABASE, pI830->FrontBuffer.Start + pI830->LinearAddr);}static BoolI830SetParam(const DRIDriverContext *ctx, int param, int value){ drmI830SetParam sp; memset(&sp, 0, sizeof(sp)); sp.param = param; sp.value = value; if (drmCommandWrite(ctx->drmFD, DRM_I830_SETPARAM, &sp, sizeof(sp))) { fprintf(stderr, "I830 SetParam Failed\n"); return FALSE; } return TRUE;}static BoolI830DRIMapScreenRegions(DRIDriverContext *ctx, I830Rec *pI830, drmI830Sarea *sarea){ fprintf(stderr, "[drm] Mapping front buffer\n"); if (drmAddMap(ctx->drmFD, (drm_handle_t)(sarea->front_offset + pI830->LinearAddr), sarea->front_size, DRM_FRAME_BUFFER, /*DRM_AGP,*/ 0, &sarea->front_handle) < 0) { fprintf(stderr, "[drm] drmAddMap(front_handle) failed. Disabling DRI\n"); return FALSE; } ctx->shared.hFrameBuffer = sarea->front_handle; ctx->shared.fbSize = sarea->front_size; fprintf(stderr, "[drm] Front Buffer = 0x%08x\n", sarea->front_handle); if (drmAddMap(ctx->drmFD, (drm_handle_t)(sarea->back_offset), sarea->back_size, DRM_AGP, 0, &sarea->back_handle) < 0) { fprintf(stderr, "[drm] drmAddMap(back_handle) failed. Disabling DRI\n"); return FALSE; } fprintf(stderr, "[drm] Back Buffer = 0x%08x\n", sarea->back_handle); if (drmAddMap(ctx->drmFD, (drm_handle_t)sarea->depth_offset, sarea->depth_size, DRM_AGP, 0, &sarea->depth_handle) < 0) { fprintf(stderr, "[drm] drmAddMap(depth_handle) failed. Disabling DRI\n"); return FALSE; } fprintf(stderr, "[drm] Depth Buffer = 0x%08x\n", sarea->depth_handle);#if 0 if (drmAddMap(ctx->drmFD, (drm_handle_t)sarea->tex_offset, sarea->tex_size, DRM_AGP, 0, &sarea->tex_handle) < 0) { fprintf(stderr, "[drm] drmAddMap(tex_handle) failed. Disabling DRI\n"); return FALSE; } fprintf(stderr, "[drm] textures = 0x%08x\n", sarea->tex_handle);#endif return TRUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -