Intel driver and Tiling

Zhenyu Wang zhen78 at gmail.com
Sun Aug 12 01:14:07 PDT 2007


On 2007.08.11 12:20:12 +0000, Lukas Hejtmanek wrote:
> Hello,
> 
> I noticed that you disabled Tiling of the framebuffer if XAA and I965G chip 
> is used. I think, we should disable tiling of the framebuffer for all I9XX
> chips if XAA is used (textured video is corrupted). 

No, xv issue is seperate. I've tried to handle it like attached patch as Eric
suggested, we can get out of xfree86 linear allocator, and alloc it by ourself
which seems much clean for me.

> Moreover, tiling
> framebuffer with legacy XV overlay freezes the chip. (At least on i915G).

With this patch overlay works fine on my 945GM.
-------------- next part --------------
From d66aee303f8ed15e198df51a096c20df70611748 Mon Sep 17 00:00:00 2001
From: Zhenyu Wang <zhenyu.z.wang at intel.com>
Date: Sun, 12 Aug 2007 16:02:18 +0800
Subject: [PATCH] Use new memory for Xv buffer

Remove xfree86 linear allocator for Xv buffer, but use a new memory
for Xv instead.
---
 src/i830.h        |    6 ++
 src/i830_memory.c |   65 +++++++++-------------
 src/i830_video.c  |  159 +++++++++++++----------------------------------------
 src/i830_video.h  |   19 +------
 4 files changed, 71 insertions(+), 178 deletions(-)

diff --git a/src/i830.h b/src/i830.h
index ca48b52..008d25f 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -306,6 +306,7 @@ typedef struct _I830Rec {
    i830_memory *cursor_mem_argb[2];
    i830_memory *xaa_scratch;
    i830_memory *xaa_scratch_2;
+   i830_memory *xv_linear;
 #ifdef I830_USE_EXA
    i830_memory *exa_offscreen;
    i830_memory *exa_965_state;
@@ -595,6 +596,11 @@ extern void I830EmitFlush(ScrnInfoPtr pScrn);
 #ifdef I830_XV
 extern void I830InitVideo(ScreenPtr pScreen);
 extern void i830_crtc_dpms_video(xf86CrtcPtr crtc, Bool on);
+/*
+ * Broadwater requires a bit of extra video memory for state information
+ */
+#define BRW_LINEAR_EXTRA	(36*1024)
+extern Bool i830_allocate_xv_memory(ScrnInfoPtr, int, int);
 #endif
 
 int
diff --git a/src/i830_memory.c b/src/i830_memory.c
index 15d3a48..dc0dddc 100644
--- a/src/i830_memory.c
+++ b/src/i830_memory.c
@@ -741,6 +741,28 @@ i830_allocate_overlay(ScrnInfoPtr pScrn)
 
     return TRUE;
 }
+
+Bool i830_allocate_xv_memory (ScrnInfoPtr pScrn, int size, int align)
+{
+    I830Ptr pI830 = I830PTR(pScrn);
+
+    /* size should be enough for video files */
+    if (size <= 0)
+	size = 1920 * 1088 * 2 * 2;
+    if (align <= 0)
+	align = 16;
+    if (IS_I965G(pI830))
+	size += BRW_LINEAR_EXTRA;
+
+    pI830->xv_linear = i830_allocate_memory(pScrn, "Xv linear", size,
+	    align, 0);
+    if (!pI830->xv_linear) {
+	xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
+		"alloc Xv linear mem failed\n");
+	return FALSE;
+    }
+    return TRUE;
+}
 #endif
 
 static Bool
@@ -1117,8 +1139,11 @@ i830_allocate_2d_memory(ScrnInfoPtr pScrn)
     /* Allocate overlay register space and optional XAA linear allocator
      * space.  The second head in zaphod mode will share the space.
      */
-    if (I830IsPrimary(pScrn))
+    if (I830IsPrimary(pScrn)) {
 	i830_allocate_overlay(pScrn);
+	if (!i830_allocate_xv_memory(pScrn, 0, 0))
+	    return FALSE;
+    }
 #endif
 
     if (pI830->entityPrivate && pI830->entityPrivate->pScrn_2) {
@@ -1684,41 +1709,3 @@ I830CheckAvailableMemory(ScrnInfoPtr pScrn)
 
     return maxPages * 4;
 }
-
-#ifdef I830_USE_XAA
-/**
- * Allocates memory from the XF86 linear allocator, but also purges
- * memory if possible to cause the allocation to succeed.
- */
-FBLinearPtr
-i830_xf86AllocateOffscreenLinear(ScreenPtr pScreen, int length,
-				 int granularity,
-				 MoveLinearCallbackProcPtr moveCB,
-				 RemoveLinearCallbackProcPtr removeCB,
-				 pointer privData)
-{
-    FBLinearPtr linear;
-    int max_size;
-
-    linear = xf86AllocateOffscreenLinear(pScreen, length, granularity, moveCB,
-					 removeCB, privData);
-    if (linear != NULL)
-	return linear;
-
-    /* The above allocation didn't succeed, so purge unlocked stuff and try
-     * again.
-     */
-    xf86QueryLargestOffscreenLinear(pScreen, &max_size, granularity,
-				    PRIORITY_EXTREME);
-
-    if (max_size < length)
-	return NULL;
-
-    xf86PurgeUnlockedOffscreenAreas(pScreen);
-
-    linear = xf86AllocateOffscreenLinear(pScreen, length, granularity, moveCB,
-					 removeCB, privData);
-
-    return linear;
-}
-#endif
diff --git a/src/i830_video.c b/src/i830_video.c
index b4f9e74..e63cb26 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -107,8 +107,8 @@ static int I830QueryImageAttributesTextured(ScrnInfoPtr, int, unsigned short *,
 
 static void I830BlockHandler(int, pointer, pointer, pointer);
 
-static void
-I830FreeMemory(ScrnInfoPtr pScrn, struct linear_alloc *linear);
+static void i830_xv_get_memory(ScrnInfoPtr, unsigned int*, int, int);
+static void i830_xv_put_memory(ScrnInfoPtr, unsigned int*);
 
 #define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE)
 
@@ -841,7 +841,7 @@ I830SetupImageVideoOverlay(ScreenPtr pScreen)
     pPriv->saturation = 128;
     pPriv->current_crtc = NULL;
     pPriv->desired_crtc = NULL;
-    memset(&pPriv->linear, 0, sizeof(pPriv->linear));
+    pPriv->linear = 0;
     pPriv->currentBuf = 0;
     pPriv->gamma5 = 0xc0c0c0;
     pPriv->gamma4 = 0x808080;
@@ -955,7 +955,7 @@ I830SetupImageVideoTextured(ScreenPtr pScreen)
 
 	pPriv->textured = TRUE;
 	pPriv->videoStatus = 0;
-	memset(&pPriv->linear, 0, sizeof(pPriv->linear));
+	pPriv->linear = 0;
 	pPriv->currentBuf = 0;
 	pPriv->doubleBuffer = 0;
 
@@ -1015,7 +1015,7 @@ I830StopVideo(ScrnInfoPtr pScrn, pointer data, Bool shutdown)
 	    if (pI830->entityPrivate)
 		pI830->entityPrivate->XvInUse = -1;
 	}
-	I830FreeMemory(pScrn, &pPriv->linear);
+	i830_xv_put_memory(pScrn, &pPriv->linear);
 	pPriv->videoStatus = 0;
     } else {
 	if (pPriv->videoStatus & CLIENT_VIDEO_ON) {
@@ -2075,112 +2075,6 @@ i830_display_video(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
     i830_overlay_continue (pScrn, scaleChanged);
 }
 
-#ifdef I830_USE_EXA
-static void
-I830VideoSave(ScreenPtr pScreen, ExaOffscreenArea *area)
-{
-    struct linear_alloc *linear = area->privData;
-
-    linear->exa = NULL;
-    linear->offset = 0;
-}
-#endif /* I830_USE_EXA */
-
-/**
- * Allocates linear memory using the XFree86 (XAA) or EXA allocator.
- *
- * \param pPriv adaptor the memory is being allocated for.
- * \param size size of the allocation, in bytes.
- * \param alignment offset alignment of the allocation, in bytes.
- *
- * \return byte offset of the allocated memory from the start of framebuffer.
- */
-static void
-I830AllocateMemory(ScrnInfoPtr pScrn, struct linear_alloc *linear, int size,
-		   int align)
-{
-    ScreenPtr pScreen = pScrn->pScreen;
-    I830Ptr pI830 = I830PTR(pScrn);
-
-#ifdef I830_USE_EXA
-    if (pI830->useEXA) {
-	if (linear->exa != NULL) {
-	    if (linear->exa->size >= size)
-		return;
-
-	    exaOffscreenFree(pScreen, linear->exa);
-	    linear->offset = 0;
-	}
-
-	linear->exa = exaOffscreenAlloc(pScreen, size, align, TRUE,
-					I830VideoSave, linear);
-	if (linear->exa == NULL)
-	    return;
-	linear->offset = linear->exa->offset;
-    }
-#endif /* I830_USE_EXA */
-#ifdef I830_USE_XAA
-    if (!pI830->useEXA) {
-	/* Converts an offset from XAA's linear allocator to an offset from the
-	 * start of fb.
-	 */
-#define XAA_OFFSET_TO_OFFSET(x) \
-	(pI830->front_buffer->offset + (x * pI830->cpp))
-
-	/* The XFree86 linear allocator operates in units of screen pixels,
-	 * sadly.
-	 */
-	size = (size + pI830->cpp - 1) / pI830->cpp;
-	align = (align + pI830->cpp - 1) / pI830->cpp;
-
-	if (linear->xaa != NULL) {
-	    if (linear->xaa->size >= size) {
-		linear->offset = XAA_OFFSET_TO_OFFSET(linear->xaa->offset);
-		return;
-	    }
-
-	    if (xf86ResizeOffscreenLinear(linear->xaa, size)) {
-		linear->offset = XAA_OFFSET_TO_OFFSET(linear->xaa->offset);
-		return;
-	    }
-
-	    xf86FreeOffscreenLinear(linear->xaa);
-	}
-
-	linear->xaa = i830_xf86AllocateOffscreenLinear(pScreen, size, align,
-						       NULL, NULL, NULL);
-	if (linear->xaa == NULL)
-	    return;
-
-	linear->offset = XAA_OFFSET_TO_OFFSET(linear->xaa->offset);
-    }
-#endif /* I830_USE_XAA */
-}
-
-static void
-I830FreeMemory(ScrnInfoPtr pScrn, struct linear_alloc *linear)
-{
-    I830Ptr pI830 = I830PTR(pScrn);
-
-#ifdef I830_USE_EXA
-    if (pI830->useEXA) {
-	if (linear->exa != NULL) {
-	    exaOffscreenFree(pScrn->pScreen, linear->exa);
-	    linear->exa = NULL;
-	}
-    }
-#endif /* I830_USE_EXA */
-#ifdef I830_USE_XAA
-    if (!pI830->useEXA) {
-	if (linear->xaa != NULL) {
-	    xf86FreeOffscreenLinear(linear->xaa);
-	    linear->xaa = NULL;
-	}
-    }
-#endif /* I830_USE_XAA */
-    linear->offset = 0;
-}
-
 static Bool
 i830_clip_video_helper (ScrnInfoPtr pScrn,
 			xf86CrtcPtr *crtc_ret,
@@ -2259,6 +2153,29 @@ i830_fill_colorkey (ScreenPtr pScreen, CARD32 key, RegionPtr clipboxes)
    FreeScratchGC (gc);
 }
 
+void
+i830_xv_get_memory(ScrnInfoPtr pScrn, unsigned int *linear,
+	int size, int align)
+{
+    I830Ptr pI830 = I830PTR(pScrn);
+    if (size > pI830->xv_linear->size) {
+	i830_free_memory(pScrn, pI830->xv_linear);
+	if (!i830_allocate_xv_memory(pScrn, size, align)) {
+	    xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
+		    "realloc Xv linear mem size %d kB failed\n", size/1024);
+	    *linear = 0;
+	    return;
+	}
+    }
+    *linear = pI830->xv_linear->offset;
+}
+
+void
+i830_xv_put_memory(ScrnInfoPtr pScrn, unsigned int *linear)
+{
+    *linear = 0;
+}
+
 /*
  * The source rectangle of the video is defined by (src_x, src_y, src_w, src_h).
  * The dest rectangle of the video is defined by (drw_x, drw_y, drw_w, drw_h).
@@ -2411,18 +2328,18 @@ I830PutImage(ScrnInfoPtr pScrn,
 	extraLinear = 0;
 
     /* size is multiplied by 2 because we have two buffers that are flipping */
-    I830AllocateMemory(pScrn, &pPriv->linear,
+    i830_xv_get_memory(pScrn, &pPriv->linear,
 		       extraLinear + (pPriv->doubleBuffer ? size * 2 : size),
 		       16);
 
-    if (pPriv->linear.offset == 0)
+    if (pPriv->linear == 0)
 	return BadAlloc;
 
-    pPriv->extra_offset = pPriv->linear.offset +
+    pPriv->extra_offset = pPriv->linear +
     (pPriv->doubleBuffer ? size * 2 : size);
 
     /* fixup pointers */
-    pPriv->YBuf0offset = pPriv->linear.offset;
+    pPriv->YBuf0offset = pPriv->linear;
     if (pI830->rotation & (RR_Rotate_90 | RR_Rotate_270)) {
 	pPriv->UBuf0offset = pPriv->YBuf0offset + (dstPitch * 2 * width);
 	pPriv->VBuf0offset = pPriv->UBuf0offset + (dstPitch * width / 2);
@@ -2654,7 +2571,7 @@ I830BlockHandler(int i,
 	    }
 	} else {				/* FREE_TIMER */
 	    if (pPriv->freeTime < now) {
-		I830FreeMemory(pScrn, &pPriv->linear);
+		i830_xv_put_memory(pScrn, &pPriv->linear);
 		pPriv->videoStatus = 0;
 	    }
 	}
@@ -2666,7 +2583,7 @@ I830BlockHandler(int i,
  ***************************************************************************/
 
 typedef struct {
-    struct linear_alloc linear;
+    unsigned int linear;
     Bool isOn;
 } OffscreenPrivRec, *OffscreenPrivPtr;
 
@@ -2711,8 +2628,8 @@ I830AllocateSurface(ScrnInfoPtr pScrn,
     fbpitch = pI830->cpp * pScrn->displayWidth;
     size = pitch * h;
 
-    I830AllocateMemory(pScrn, &pPriv->linear, size, 16);
-    if (pPriv->linear.offset == 0) {
+    i830_xv_get_memory(pScrn, &pPriv->linear, size, 16);
+    if (pPriv->linear == 0) {
 	xfree(surface->pitches);
 	xfree(surface->offsets);
 	xfree(pPriv);
@@ -2727,7 +2644,7 @@ I830AllocateSurface(ScrnInfoPtr pScrn,
     surface->pScrn = pScrn;
     surface->id = id;
     surface->pitches[0] = pitch;
-    surface->offsets[0] = pPriv->linear.offset;
+    surface->offsets[0] = pPriv->linear;
     surface->devPrivate.ptr = (pointer) pPriv;
 
     memset(pI830->FbBase + surface->offsets[0], 0, size);
@@ -2763,7 +2680,7 @@ I830FreeSurface(XF86SurfacePtr surface)
     OffscreenPrivPtr pPriv = (OffscreenPrivPtr) surface->devPrivate.ptr;
 
     I830StopSurface(surface);
-    I830FreeMemory(surface->pScrn, &pPriv->linear);
+    i830_xv_put_memory(surface->pScrn, &pPriv->linear);
     xfree(surface->pitches);
     xfree(surface->offsets);
     xfree(surface->devPrivate.ptr);
diff --git a/src/i830_video.h b/src/i830_video.h
index 7e2d149..b3da2aa 100644
--- a/src/i830_video.h
+++ b/src/i830_video.h
@@ -27,18 +27,6 @@ THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "xf86.h"
 #include "xf86_OSproc.h"
 
-/* Ugly mess to support the old XF86 allocator or EXA using the same code.
- */
-struct linear_alloc {
-#ifdef I830_USE_XAA
-   FBLinearPtr xaa;
-#endif
-#ifdef I830_USE_EXA
-   ExaOffscreenArea *exa;
-#endif
-   unsigned int offset;
-};
-
 typedef struct {
    CARD32 YBuf0offset;
    CARD32 UBuf0offset;
@@ -70,7 +58,7 @@ typedef struct {
    CARD32 videoStatus;
    Time offTime;
    Time freeTime;
-   struct linear_alloc linear;
+   unsigned int linear;
    unsigned int extra_offset;
 
    Bool overlayOK;
@@ -82,11 +70,6 @@ typedef struct {
 #define GET_PORT_PRIVATE(pScrn) \
    (I830PortPrivPtr)((I830PTR(pScrn))->adaptor->pPortPrivates[0].ptr)
 
-/*
- * Broadwater requires a bit of extra video memory for state information
- */
-#define BRW_LINEAR_EXTRA	(36*1024)
-
 void I915DisplayVideoTextured(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
 			      int id, RegionPtr dstRegion, short width,
 			      short height, int video_pitch,
-- 
1.5.2.4



More information about the xorg mailing list