📄 intel_dri.c
字号:
}static voidI830DRIUnmapScreenRegions(const DRIDriverContext *ctx, I830Rec *pI830, drmI830Sarea *sarea){#if 1 if (sarea->front_handle) { drmRmMap(ctx->drmFD, sarea->front_handle); sarea->front_handle = 0; }#endif if (sarea->back_handle) { drmRmMap(ctx->drmFD, sarea->back_handle); sarea->back_handle = 0; } if (sarea->depth_handle) { drmRmMap(ctx->drmFD, sarea->depth_handle); sarea->depth_handle = 0; } if (sarea->tex_handle) { drmRmMap(ctx->drmFD, sarea->tex_handle); sarea->tex_handle = 0; }}static BoolI830DRIDoMappings(DRIDriverContext *ctx, I830Rec *pI830, drmI830Sarea *sarea){ if (drmAddMap(ctx->drmFD, (drm_handle_t)pI830->LpRing->mem.Start, pI830->LpRing->mem.Size, DRM_AGP, 0, &pI830->ring_map) < 0) { fprintf(stderr, "[drm] drmAddMap(ring_map) failed. Disabling DRI\n"); return FALSE; } fprintf(stderr, "[drm] ring buffer = 0x%08x\n", pI830->ring_map); if (I830InitDma(ctx, pI830) == FALSE) { return FALSE; } /* init to zero to be safe */ I830DRIMapScreenRegions(ctx, pI830, sarea); SetupDRIMM(ctx, pI830); if (ctx->pciDevice != PCI_CHIP_845_G && ctx->pciDevice != PCI_CHIP_I830_M) { I830SetParam(ctx, I830_SETPARAM_USE_MI_BATCHBUFFER_START, 1 ); } /* Okay now initialize the dma engine */ { pI830->irq = drmGetInterruptFromBusID(ctx->drmFD, ctx->pciBus, ctx->pciDevice, ctx->pciFunc); if (drmCtlInstHandler(ctx->drmFD, pI830->irq)) { fprintf(stderr, "[drm] failure adding irq handler\n"); pI830->irq = 0; return FALSE; } else fprintf(stderr, "[drm] dma control initialized, using IRQ %d\n", pI830->irq); } fprintf(stderr, "[dri] visual configs initialized\n"); return TRUE;}static BoolI830ClearScreen(DRIDriverContext *ctx, I830Rec *pI830, drmI830Sarea *sarea){ /* need to drmMap front and back buffers and zero them */ drmAddress map_addr; int ret; ret = drmMap(ctx->drmFD, sarea->front_handle, sarea->front_size, &map_addr); if (ret) { fprintf(stderr, "Unable to map front buffer\n"); return FALSE; } drimemsetio((char *)map_addr, 0, sarea->front_size); drmUnmap(map_addr, sarea->front_size); ret = drmMap(ctx->drmFD, sarea->back_handle, sarea->back_size, &map_addr); if (ret) { fprintf(stderr, "Unable to map back buffer\n"); return FALSE; } drimemsetio((char *)map_addr, 0, sarea->back_size); drmUnmap(map_addr, sarea->back_size); return TRUE;}static BoolI830ScreenInit(DRIDriverContext *ctx, I830Rec *pI830) { I830DRIPtr pI830DRI; drmI830Sarea *pSAREAPriv; int err; drm_page_size = getpagesize(); pI830->registerSize = ctx->MMIOSize; /* This is a hack for now. We have to have more than a 4k page here * because of the size of the state. However, the state should be * in a per-context mapping. This will be added in the Mesa 3.5 port * of the I830 driver. */ ctx->shared.SAREASize = SAREA_MAX; /* Note that drmOpen will try to load the kernel module, if needed. */ ctx->drmFD = drmOpen("i915", NULL ); if (ctx->drmFD < 0) { fprintf(stderr, "[drm] drmOpen failed\n"); return 0; } if ((err = drmSetBusid(ctx->drmFD, ctx->pciBusID)) < 0) { fprintf(stderr, "[drm] drmSetBusid failed (%d, %s), %s\n", ctx->drmFD, ctx->pciBusID, strerror(-err)); return 0; } if (drmAddMap( ctx->drmFD, 0, ctx->shared.SAREASize, DRM_SHM, DRM_CONTAINS_LOCK, &ctx->shared.hSAREA) < 0) { fprintf(stderr, "[drm] drmAddMap failed\n"); return 0; } fprintf(stderr, "[drm] added %d byte SAREA at 0x%08x\n", ctx->shared.SAREASize, ctx->shared.hSAREA); if (drmMap( ctx->drmFD, ctx->shared.hSAREA, ctx->shared.SAREASize, (drmAddressPtr)(&ctx->pSAREA)) < 0) { fprintf(stderr, "[drm] drmMap failed\n"); return 0; } memset(ctx->pSAREA, 0, ctx->shared.SAREASize); fprintf(stderr, "[drm] mapped SAREA 0x%08x to %p, size %d\n", ctx->shared.hSAREA, ctx->pSAREA, ctx->shared.SAREASize); if (drmAddMap(ctx->drmFD, ctx->MMIOStart, ctx->MMIOSize, DRM_REGISTERS, DRM_READ_ONLY, &pI830->registerHandle) < 0) { fprintf(stderr, "[drm] drmAddMap mmio failed\n"); return 0; } fprintf(stderr, "[drm] register handle = 0x%08x\n", pI830->registerHandle); if (!I830CheckDRMVersion(ctx, pI830)) { return FALSE; } /* Create a 'server' context so we can grab the lock for * initialization ioctls. */ if ((err = drmCreateContext(ctx->drmFD, &ctx->serverContext)) != 0) { fprintf(stderr, "%s: drmCreateContext failed %d\n", __FUNCTION__, err); return 0; } DRM_LOCK(ctx->drmFD, ctx->pSAREA, ctx->serverContext, 0); /* Initialize the SAREA private data structure */ pSAREAPriv = (drmI830Sarea *)(((char*)ctx->pSAREA) + sizeof(drm_sarea_t)); memset(pSAREAPriv, 0, sizeof(*pSAREAPriv)); pI830->StolenMemory.Size = I830DetectMemory(ctx, pI830); pI830->StolenMemory.Start = 0; pI830->StolenMemory.End = pI830->StolenMemory.Size; pI830->MemoryAperture.Start = pI830->StolenMemory.End; pI830->MemoryAperture.End = KB(40000); pI830->MemoryAperture.Size = pI830->MemoryAperture.End - pI830->MemoryAperture.Start; pI830->StolenPool.Fixed = pI830->StolenMemory; pI830->StolenPool.Total = pI830->StolenMemory; pI830->StolenPool.Free = pI830->StolenPool.Total; pI830->FreeMemory = pI830->StolenPool.Total.Size; if (!AgpInit(ctx, pI830)) return FALSE; if (I830AllocateMemory(ctx, pI830) == FALSE) { return FALSE; } if (I830BindMemory(ctx, pI830) == FALSE) { return FALSE; } pSAREAPriv->rotated_offset = -1; pSAREAPriv->rotated_size = 0; pSAREAPriv->rotated_pitch = ctx->shared.virtualWidth; pSAREAPriv->front_offset = pI830->FrontBuffer.Start; pSAREAPriv->front_size = pI830->FrontBuffer.Size; pSAREAPriv->width = ctx->shared.virtualWidth; pSAREAPriv->height = ctx->shared.virtualHeight; pSAREAPriv->pitch = ctx->shared.virtualWidth; pSAREAPriv->virtualX = ctx->shared.virtualWidth; pSAREAPriv->virtualY = ctx->shared.virtualHeight; pSAREAPriv->back_offset = pI830->BackBuffer.Start; pSAREAPriv->back_size = pI830->BackBuffer.Size; pSAREAPriv->depth_offset = pI830->DepthBuffer.Start; pSAREAPriv->depth_size = pI830->DepthBuffer.Size;#if 0 pSAREAPriv->tex_offset = pI830->TexMem.Start; pSAREAPriv->tex_size = pI830->TexMem.Size;#endif pSAREAPriv->log_tex_granularity = pI830->TexGranularity; ctx->driverClientMsg = malloc(sizeof(I830DRIRec)); ctx->driverClientMsgSize = sizeof(I830DRIRec); pI830DRI = (I830DRIPtr)ctx->driverClientMsg; pI830DRI->deviceID = pI830->Chipset; pI830DRI->regsSize = I830_REG_SIZE; pI830DRI->width = ctx->shared.virtualWidth; pI830DRI->height = ctx->shared.virtualHeight; pI830DRI->mem = ctx->shared.fbSize; pI830DRI->cpp = ctx->cpp; pI830DRI->bitsPerPixel = ctx->bpp; pI830DRI->sarea_priv_offset = sizeof(drm_sarea_t); err = I830DRIDoMappings(ctx, pI830, pSAREAPriv); if (err == FALSE) return FALSE; I830SetupMemoryTiling(ctx, pI830); /* Quick hack to clear the front & back buffers. Could also use * the clear ioctl to do this, but would need to setup hw state * first. */ I830ClearScreen(ctx, pI830, pSAREAPriv); I830SetRingRegs(ctx, pI830); return TRUE;}/** * \brief Validate the fbdev mode. * * \param ctx display handle. * * \return one on success, or zero on failure. * * Saves some registers and returns 1. * * \sa radeonValidateMode(). */static int i830ValidateMode( const DRIDriverContext *ctx ){ return 1;}/** * \brief Examine mode returned by fbdev. * * \param ctx display handle. * * \return one on success, or zero on failure. * * Restores registers that fbdev has clobbered and returns 1. * * \sa i810ValidateMode(). */static int i830PostValidateMode( const DRIDriverContext *ctx ){ I830Rec *pI830 = ctx->driverPrivate; I830SetRingRegs(ctx, pI830); return 1;}/** * \brief Initialize the framebuffer device mode * * \param ctx display handle. * * \return one on success, or zero on failure. * * Fills in \p info with some default values and some information from \p ctx * and then calls I810ScreenInit() for the screen initialization. * * Before exiting clears the framebuffer memory accessing it directly. */static int i830InitFBDev( DRIDriverContext *ctx ){ I830Rec *pI830 = calloc(1, sizeof(I830Rec)); int i; { int dummy = ctx->shared.virtualWidth; switch (ctx->bpp / 8) { case 1: dummy = (ctx->shared.virtualWidth + 127) & ~127; break; case 2: dummy = (ctx->shared.virtualWidth + 31) & ~31; break; case 3: case 4: dummy = (ctx->shared.virtualWidth + 15) & ~15; break; } ctx->shared.virtualWidth = dummy; ctx->shared.Width = ctx->shared.virtualWidth; } for (i = 0; pitches[i] != 0; i++) { if (pitches[i] >= ctx->shared.virtualWidth) { ctx->shared.virtualWidth = pitches[i]; break; } } ctx->driverPrivate = (void *)pI830; pI830->LpRing = calloc(1, sizeof(I830RingBuffer)); pI830->Chipset = ctx->chipset; pI830->LinearAddr = ctx->FBStart; if (!I830ScreenInit( ctx, pI830 )) return 0; return 1;}/** * \brief The screen is being closed, so clean up any state and free any * resources used by the DRI. * * \param ctx display handle. * * Unmaps the SAREA, closes the DRM device file descriptor and frees the driver * private data. */static void i830HaltFBDev( DRIDriverContext *ctx ){ drmI830Sarea *pSAREAPriv; I830Rec *pI830 = ctx->driverPrivate; if (pI830->irq) { drmCtlUninstHandler(ctx->drmFD); pI830->irq = 0; } I830CleanupDma(ctx); pSAREAPriv = (drmI830Sarea *)(((char*)ctx->pSAREA) + sizeof(drm_sarea_t)); I830DRIUnmapScreenRegions(ctx, pI830, pSAREAPriv); drmUnmap( ctx->pSAREA, ctx->shared.SAREASize ); drmClose(ctx->drmFD); if (ctx->driverPrivate) { free(ctx->driverPrivate); ctx->driverPrivate = 0; }}extern void i810NotifyFocus( int );/** * \brief Exported driver interface for Mini GLX. * * \sa DRIDriverRec. */const struct DRIDriverRec __driDriver = { i830ValidateMode, i830PostValidateMode, i830InitFBDev, i830HaltFBDev, NULL,//I830EngineShutdown, NULL, //I830EngineRestore, #ifndef _EMBEDDED 0,#else i810NotifyFocus, #endif};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -