diff options
author | Thomas Hellström <thomas@shipmail.org> | 2008-10-29 10:51:09 +0000 |
---|---|---|
committer | Thomas Hellström <thomas@shipmail.org> | 2008-10-29 10:51:09 +0000 |
commit | 5e33fc7b92b4e9315668eee39edf3aaa7c622595 (patch) | |
tree | a7a53bc74853bc2c07999e57868b588744b7c0c7 | |
parent | 69d4183f926fc9913de7c3351f54eccd3bb01a02 (diff) |
Restructure the VIA DRI interface
-rw-r--r-- | src/ochr_ioctl.c | 47 | ||||
-rw-r--r-- | src/ochr_ws_driver.c | 16 | ||||
-rw-r--r-- | src/via_accel.c | 108 | ||||
-rw-r--r-- | src/via_dri.c | 32 | ||||
-rw-r--r-- | src/via_dri.h | 30 | ||||
-rw-r--r-- | src/via_driver.c | 37 | ||||
-rw-r--r-- | src/via_driver.h | 1 |
7 files changed, 114 insertions, 157 deletions
diff --git a/src/ochr_ioctl.c b/src/ochr_ioctl.c index 3dc524a..e5ebb7b 100644 --- a/src/ochr_ioctl.c +++ b/src/ochr_ioctl.c @@ -483,6 +483,8 @@ int ochr_execbuf(int fd, struct _ViaCommandBuffer *cBuf) struct _ViaDrmValidateNode *viaNode; struct via_validate_arg *val_arg; struct via_validate_req *req; + struct via_validate_rep *rep; + uint64_t first = 0ULL; uint64_t *prevNext = NULL; void *iterator; @@ -490,16 +492,18 @@ int ochr_execbuf(int fd, struct _ViaCommandBuffer *cBuf) int ret; /* - * Build the validate list chain. + * Prepare arguments for all buffers that need validation + * prior to the command submission. */ valList = driGetDRMValidateList(cBuf->validate_list); iterator = validateListIterator(valList); - while (iterator) { node = validateListNode(iterator); viaNode = containerOf(node, struct _ViaDrmValidateNode, base); val_arg = &viaNode->val_arg; + val_arg->handled = 0; + val_arg->ret = 0; req = &val_arg->d.req; if (!first) @@ -508,13 +512,18 @@ int ochr_execbuf(int fd, struct _ViaCommandBuffer *cBuf) *prevNext = (uint64_t) (unsigned long) val_arg; prevNext = &req->next; - req->buffer_handle = *(uint32_t *)node->buf; + req->buffer_handle = wsDriKbufHandle((struct _DriKernelBuf *) + node->buf); req->group = 0; iterator = validateListNext(valList, iterator); ++count; } + /* + * Fill in the execbuf arg itself. + */ + exec_req->buffer_list = first; exec_req->num_buffers = count; exec_req->reloc_list = (uint64_t) (unsigned long) @@ -525,12 +534,42 @@ int ochr_execbuf(int fd, struct _ViaCommandBuffer *cBuf) exec_req->engine = 0; exec_req->exec_flags = 0x00000000; exec_req->cliprect_offset = 0; + exec_req->num_cliprects = 0; do { ret = drmCommandWriteRead(fd, DRM_VIA_TTM_EXECBUF, &arg, sizeof(arg)); }while(ret == EAGAIN || ret == EINTR); + iterator = validateListIterator(valList); - return 0; + /* + * Update all user-space cached offsets and flags for kernel + * buffers involved in this commands. + */ + + while (iterator) { + node = validateListNode(iterator); + viaNode = containerOf(node, struct _ViaDrmValidateNode, base); + val_arg = &viaNode->val_arg; + + if (!val_arg->handled) + break; + + if (val_arg->ret != 0) { + xf86DrvMsg(cBuf->pScrn->scrnIndex, X_ERROR, + "Failed a buffer validation: \"%s\".\n", + strerror(-val_arg->ret)); + iterator = validateListNext(valList, iterator); + continue; + } + + rep = &val_arg->d.rep; + wsDriUpdateKbuf((struct _DriKernelBuf *) node->buf, + rep->gpu_offset, rep->flags); + + iterator = validateListNext(valList, iterator); + } + + return ret; } diff --git a/src/ochr_ws_driver.c b/src/ochr_ws_driver.c index b8bcb8f..843f482 100644 --- a/src/ochr_ws_driver.c +++ b/src/ochr_ws_driver.c @@ -9,25 +9,25 @@ /* * Allocate a validate list node. On the list of drm buffers, which is - * identified by driver_private == 0, we allocate a derived item which + * identified by type_id == 0, we allocate a derived item which * also contains a drm validate arg, which means we can start to fill * this in immediately. */ static struct _ValidateNode *vn_alloc(struct _WSDriVNodeFuncs *func, - int driver_private) + int type_id) { - if (driver_private == 0) { + if (type_id == 0) { struct _ViaDrmValidateNode *vNode = malloc(sizeof(*vNode)); vNode->base.func = func; - vNode->base.driver_private = 0; + vNode->base.type_id = 0; return &vNode->base; } else { struct _ValidateNode *node = malloc(sizeof(*node)); node->func = func; - node->driver_private = 1; + node->type_id = 1; return node; } } @@ -38,7 +38,7 @@ static struct _ValidateNode *vn_alloc(struct _WSDriVNodeFuncs *func, static void vn_free(struct _ValidateNode *node) { - if (node->driver_private == 0) + if (node->type_id == 0) free(containerOf(node, struct _ViaDrmValidateNode, base)); else free(node); @@ -47,12 +47,12 @@ static void vn_free(struct _ValidateNode *node) /* * Clear the private part of the validate list node. This happens when * the list node is newly allocated or is being reused. Since we only have - * a private part when node->driver_private == 0 we only care to clear in that + * a private part when node->type_id == 0 we only care to clear in that * case. We want to clear the drm ioctl argument. */ static void vn_clear(struct _ValidateNode *node) { - if (node->driver_private == 0) { + if (node->type_id == 0) { struct _ViaDrmValidateNode *vNode = containerOf(node, struct _ViaDrmValidateNode, base); diff --git a/src/via_accel.c b/src/via_accel.c index 60044f3..01d7600 100644 --- a/src/via_accel.c +++ b/src/via_accel.c @@ -74,71 +74,6 @@ viaDumpDMA(ViaCommandBuffer * buf) ErrorF("\n"); } -void -viaFlushPCI(ViaCommandBuffer * buf) -{ - register CARD32 *bp = buf->buf; - CARD32 transSetting; - CARD32 *endp = bp + buf->pos; - unsigned loop = 0; - register CARD32 offset = 0; - register CARD32 value; - VIAPtr pVia = VIAPTR(buf->pScrn); - int ret; - - while (bp < endp) { - if (*bp == HALCYON_HEADER2) { - if (++bp == endp) - return; - VIASETREG(VIA_REG_TRANSET, transSetting = *bp++); - while (bp < endp) { - if ((transSetting != HC_ParaType_CmdVdata) - && ((*bp == HALCYON_HEADER2) - || (*bp & HALCYON_HEADER1MASK) == HALCYON_HEADER1)) - break; - VIASETREG(VIA_REG_TRANSPACE, *bp++); - } - } else if ((*bp & HALCYON_HEADER1MASK) == HALCYON_HEADER1) { - - while (bp < endp) { - if (*bp == HALCYON_HEADER2) - break; - if (offset == 0) { - /* - * Not doing this wait will probably stall the processor - * for an unacceptable amount of time in VIASETREG while - * other high priority interrupts may be pending. - */ - if (pVia->Chipset != VIA_P4M890 && - pVia->Chipset != VIA_K8M890 && - pVia->Chipset != VIA_P4M900) { - while (!(VIAGETREG(VIA_REG_STATUS) & VIA_VR_QUEUE_BUSY) - && (loop++ < MAXLOOP)) ; - } - while ((VIAGETREG(VIA_REG_STATUS) & - (VIA_CMD_RGTR_BUSY | VIA_2D_ENG_BUSY)) - && (loop++ < MAXLOOP)) ; - } - offset = (*bp++ & 0x0FFFFFFF) << 2; - value = *bp++; - VIASETREG(offset, value); - } - } else { - ErrorF("Command stream parser error.\n"); - } - } - buf->pos = 0; - buf->mode = 0; - buf->has3dState = FALSE; - buf->srcPixmap = NULL; - buf->dstPixmap = NULL; - ret = ochr_reset_cmdlists(buf); - if (ret) { - FatalError("Failed trying to reset command buffer: \"%s\".\n", - strerror(-ret)); - } -} - #ifdef XF86DRI /* * Flush the command buffer using DRM. If in PCI mode, we can bypass DRM, @@ -150,9 +85,7 @@ viaFlushDRIEnabled(ViaCommandBuffer * cb) { ScrnInfoPtr pScrn = cb->pScrn; VIAPtr pVia = VIAPTR(pScrn); - char *tmp = (char *)cb->buf; int tmpSize; - struct drm_via_cmdbuffer b; int ret; /* Align end of command buffer for AGP DMA. */ @@ -162,30 +95,16 @@ viaFlushDRIEnabled(ViaCommandBuffer * cb) } tmpSize = cb->pos * sizeof(CARD32); - if (pVia->agpDMA || (pVia->directRenderingEnabled && cb->has3dState)) { - cb->mode = 0; - cb->has3dState = FALSE; - ochr_execbuf(pVia->drmFD, cb); -#if 0 - while (tmpSize > 0) { - b.size = (tmpSize > VIA_DMASIZE) ? VIA_DMASIZE : tmpSize; - tmpSize -= b.size; - b.buf = tmp; - tmp += b.size; - if (drmCommandWrite(pVia->drmFD, ((pVia->agpDMA) - ? DRM_VIA_CMDBUFFER : - DRM_VIA_PCICMD), &b, sizeof(b))) { - ErrorF("DRM command buffer submission failed.\n"); - viaDumpDMA(cb); - return; - } - } -#endif - - cb->pos = 0; - } else { - viaFlushPCI(cb); - } + cb->mode = 0; + cb->has3dState = FALSE; + ret = ochr_execbuf(pVia->drmFD, cb); + if (ret) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Command buffer submission failed: \"%s\".\n", + strerror(-ret)); + viaDumpDMA(cb); + } + cb->pos = 0; cb->srcPixmap = NULL; cb->dstPixmap = NULL; ret = ochr_reset_cmdlists(cb); @@ -218,7 +137,7 @@ viaSetupCBuffer(ScrnInfoPtr pScrn, ViaCommandBuffer * buf, unsigned size) buf->header_start = 0; buf->rindex = 0; buf->has3dState = FALSE; - buf->flushFunc = viaFlushPCI; + buf->flushFunc = NULL; #ifdef XF86DRI if (pVia->directRenderingEnabled) { buf->flushFunc = viaFlushDRIEnabled; @@ -953,6 +872,8 @@ viaExpandablePixel(int format) #ifdef XF86DRI +#if 0 + static int viaAccelDMADownload(ScrnInfoPtr pScrn, unsigned long fbOffset, unsigned srcPitch, unsigned char *dst, @@ -1093,6 +1014,7 @@ viaExaDownloadFromScreen(PixmapPtr pSrc, int x, int y, int w, int h, return TRUE; } +#endif #endif #if 0 @@ -1446,7 +1368,7 @@ viaInitExa(ScreenPtr pScreen) #ifdef XF86DRI if (pVia->directRenderingEnabled) - pExa->DownloadFromScreen = viaExaDownloadFromScreen; + pExa->DownloadFromScreen = NULL; /*viaExaDownloadFromScreen;*/ #endif /* XF86DRI */ diff --git a/src/via_dri.c b/src/via_dri.c index e8d0ad5..b478384 100644 --- a/src/via_dri.c +++ b/src/via_dri.c @@ -374,12 +374,6 @@ VIADRIScreenInit(ScreenPtr pScreen) VIADRICloseScreen(pScreen); return FALSE; } - pVIADRI->regs.size = VIA_MMIO_REGSIZE; - pVIADRI->regs.handle = pVia->registerHandle; - xf86DrvMsg(pScreen->myNum, X_INFO, "[drm] mmio Registers = 0x%08lx\n", - (unsigned long)pVIADRI->regs.handle); - - pVIADRI->drixinerama = FALSE; xf86DrvMsg(pScrn->scrnIndex, X_INFO, "[dri] mmio mapped.\n"); @@ -465,16 +459,11 @@ VIADRIFinishScreenInit(ScreenPtr pScreen) memset(saPriv, 0, sizeof(*saPriv)); saPriv->ctxOwner = -1; } + pVIADRI = (VIADRIPtr) pVia->pDRIInfo->devPrivate; pVIADRI->deviceID = pVia->Chipset; - pVIADRI->width = pScrn->virtualX; - pVIADRI->height = pScrn->virtualY; - pVIADRI->mem = pScrn->videoRam * 1024; - pVIADRI->bytesPerPixel = (pScrn->bitsPerPixel + 7) / 8; pVIADRI->sarea_priv_offset = sizeof(XF86DRISAREARec); - /* TODO */ - pVIADRI->scrnX = pVIADRI->width; - pVIADRI->scrnY = pVIADRI->height; + pVIADRI->bpp = pScrn->bitsPerPixel; return TRUE; } @@ -527,3 +516,20 @@ VIADRIMapInit(ScreenPtr pScreen, VIAPtr pVia) return TRUE; } +void +viaDRIUpdateFront(ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + volatile struct drm_via_sarea *saPriv = (struct drm_via_sarea *) + DRIGetSAREAPrivate(pScrn->pScreen); + volatile struct drm_via_scanout *front = &saPriv->scanouts[0]; + VIAPtr pVia = VIAPTR(pScrn); + struct _DriKernelBuf *buf = wsDriKBuf(pVia->scanout.bufs[VIA_SCANOUT_DISPLAY]); + + ++front->stamp; + front->handle = wsDriKbufHandle(buf); + front->width = pScrn->virtualX; + front->height = pScrn->virtualY; + front->stride = pVia->Bpl; + front->depth = pScrn->depth; +} diff --git a/src/via_dri.h b/src/via_dri.h index 5ea9d7c..65f2706 100644 --- a/src/via_dri.h +++ b/src/via_dri.h @@ -29,40 +29,16 @@ #ifndef _VIA_DRI_H_ #define _VIA_DRI_H_ 1 -#define VIA_MAX_DRAWABLES 256 - -#define VIA_DRIDDX_VERSION_MAJOR 5 +#define VIA_DRIDDX_VERSION_MAJOR 6 #define VIA_DRIDDX_VERSION_MINOR 0 #define VIA_DRIDDX_VERSION_PATCH 0 -#if !defined(XFree86Server) && !defined(_XDEFS_H) -typedef int Bool; -#endif - -typedef struct { - drm_handle_t handle; - drmSize size; -} viaRegion, *viaRegionPtr; +#define VIA_MAX_DRAWABLES 256 typedef struct { - viaRegion regs, agp; int deviceID; - int width; - int height; - int mem; - int bytesPerPixel; - int priv1; - int priv2; - int fbOffset; - int fbSize; - Bool drixinerama; - int backOffset; - int depthOffset; - int textureOffset; - int textureSize; - int irqEnabled; - unsigned int scrnX, scrnY; int sarea_priv_offset; + int bpp; } VIADRIRec, *VIADRIPtr; typedef struct { diff --git a/src/via_driver.c b/src/via_driver.c index d7d963c..d7fb35b 100644 --- a/src/via_driver.c +++ b/src/via_driver.c @@ -1794,7 +1794,12 @@ VIAEnterVT(int scrnIndex, int flags) #endif retVal = driBOData(pVia->scanout.bufs[VIA_SCANOUT_DISPLAY], - pVia->Bpl * pScrn->virtualY , NULL, NULL, 0); + pVia->Bpl * pScrn->virtualY , NULL, NULL, + DRM_BO_FLAG_MEM_VRAM | + DRM_BO_FLAG_READ | + DRM_BO_FLAG_WRITE | + DRM_BO_FLAG_NO_EVICT | + DRM_BO_FLAG_SHAREABLE); if (retVal) { xf86DrvMsg(scrnIndex, X_ERROR, "Failed reallocating the display buffer."); @@ -1855,6 +1860,7 @@ VIAEnterVT(int scrnIndex, int flags) #ifdef XF86DRI if (pVia->directRenderingEnabled) { + viaDRIUpdateFront(pScrn->pScreen); DRIUnlock(screenInfo.screens[scrnIndex]); } #endif @@ -2498,7 +2504,8 @@ VIAScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) pVia->scanout.bufs, 0, DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_READ | - DRM_BO_FLAG_NO_EVICT , 0); + DRM_BO_FLAG_WRITE | + DRM_BO_FLAG_NO_EVICT, 0); if (ret) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Failed allocating scanout buffers.\n"); @@ -2519,7 +2526,12 @@ VIAScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) displaySize = pVia->Bpl*pScrn->virtualY; ret = driBOData(pVia->scanout.bufs[VIA_SCANOUT_DISPLAY], - displaySize, NULL, NULL, 0); + displaySize, NULL, NULL, + DRM_BO_FLAG_MEM_VRAM | + DRM_BO_FLAG_WRITE | + DRM_BO_FLAG_READ | + DRM_BO_FLAG_NO_EVICT | + DRM_BO_FLAG_SHAREABLE); if (ret) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Failed allocating display video RAM: \"%s\".\n", @@ -2655,20 +2667,12 @@ VIAScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) if (!pVia->NoAccel) viaFinishInitAccel(pScreen); - if (1) { + if (!pVia->NoAccel) { memset(pVia->displayMap, 0x00, pVia->Bpl * pScrn->virtualY); } else { -#ifdef XF86DRI - if (pVia->directRenderingEnabled) - DRILock(screenInfo.screens[scrnIndex], 0); -#endif viaAccelFillRect(pScrn, pScrn->frameX0, pScrn->frameY0, pScrn->displayWidth, pScrn->virtualY, 0x00000000); viaAccelSyncMarker(pScrn); -#ifdef XF86DRI - if (pVia->directRenderingEnabled) - DRIUnlock(screenInfo.screens[scrnIndex]); -#endif } vgaHWBlankScreen(pScrn, TRUE); @@ -2691,6 +2695,15 @@ VIAScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) } #endif +#ifdef XF86DRI + if (pVia->directRenderingEnabled) { + DRILock(screenInfo.screens[scrnIndex], 0); + viaDRIUpdateFront(pScreen); + DRIUnlock(screenInfo.screens[scrnIndex]); + } +#endif + + DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_INFO, "- Done\n")); return TRUE; } diff --git a/src/via_driver.h b/src/via_driver.h index 70ef365..533fed1 100644 --- a/src/via_driver.h +++ b/src/via_driver.h @@ -497,6 +497,7 @@ void ViaI2CInit(ScrnInfoPtr pScrn); Bool VIADRIScreenInit(ScreenPtr pScreen); void VIADRICloseScreen(ScreenPtr pScreen); Bool VIADRIFinishScreenInit(ScreenPtr pScreen); +void viaDRIUpdateFront(ScreenPtr pScreen); #endif /* XF86DRI */ |