Rick,

Attached is the patch against the current svn for the ivtv_xdriver, but
it needs some autofoo in the configure.ac and Makefile.in to properly
locate the kernel source.  I'm not sure if there is a better place to
find it, but the code needs PAGE_MASK defined, and currently it gets it
from asm/page.h in the kernel source (this required a __KERNEL__ define
to find it).  I imagine there is a better way.

Regards,
Henry

On Fri, 2007-04-20 at 00:58 -0400, Ricardo Lugo wrote:
> Congrats, Henry!
> 
> Any change you could post the patches you had to make to the modular  
> X source? It would be great if the big-endian code could be included  
> in the official Xdriver code.
> 
> - Rick
> 

Index: Makefile.in
===================================================================
--- Makefile.in	(revision 3912)
+++ Makefile.in	(working copy)
@@ -55,7 +55,7 @@
 POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
-DIST_COMMON = $(am__configure_deps) $(srcdir)/Makefile.am \
+DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
 	$(srcdir)/Makefile.in $(srcdir)/config.h.in \
 	$(top_srcdir)/configure config.guess config.sub depcomp \
 	install-sh ltmain.sh missing
Index: src/Makefile.in
===================================================================
--- src/Makefile.in	(revision 3912)
+++ src/Makefile.in	(working copy)
@@ -217,7 +217,8 @@
 # -avoid-version prevents gratuitous .0.0.0 version numbers on the end
 # _ladir passes a dummy rpath to libtool so the thing will actually link
 # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
-AM_CFLAGS = @XORG_CFLAGS@
+AM_CFLAGS = @XORG_CFLAGS@ \
+	-I/lib/modules/2.6.19-1.2911.fc6/build/include
 ivtvdev_drv_la_LTLIBRARIES = ivtvdev_drv.la
 ivtvdev_drv_la_LDFLAGS = -module -avoid-version
 ivtvdev_drv_ladir = @moduledir@/drivers
Index: src/ivtv_xv.c
===================================================================
--- src/ivtv_xv.c	(revision 3912)
+++ src/ivtv_xv.c	(working copy)
@@ -59,14 +59,7 @@
 #include <X11/extensions/Xv.h>
 #include "fourcc.h"
 #include "regionstr.h"
-typedef struct ivtv_xv_portData
-{
-    unsigned int colorKey;
-    RegionRec    clip;
-    int		 autopaintColorKey;
-}Ivtv_Xv_PortData;
 
-
 #define IVTV_MAX_PORTS 1
 #define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE)
 
@@ -171,12 +164,8 @@
 {
    {XvSettable | XvGettable, 0, (1 << 24) - 1, "XV_COLORKEY"},
    {XvSettable | XvGettable, 0, 1, "XV_AUTOPAINT_COLORKEY"},
-
-#if 0
-   {XvSettable | XvGettable, -128, 127, "XV_BRIGHTNESS"},
-   {XvSettable | XvGettable, 0, 255, "XV_CONTRAST"}
-#endif
 };
+
 static Atom  xvColorKey, xvAutopaintColorKey;
 
 static int
@@ -184,42 +173,17 @@
 			    Atom attribute, INT32 value, pointer data)
 {
 	IVTVDevPtr devPtr = IVTVDEVPTR(pScrn);
-        Ivtv_Xv_PortData *pPriv = (Ivtv_Xv_PortData *)data;
-#ifdef JOHN
-	if (attribute == xvBrightness) {
-		if ((value < -128) || (value > 127))
-			return BadValue;
-		pPriv->brightness = value;
-		OUTREG(MGAREG_BESLUMACTL, ((pPriv->brightness & 0xff) << 16) |
-		       (pPriv->contrast & 0xff));
-	} else if (attribute == xvContrast) {
-		if ((value < 0) || (value > 255))
-			return BadValue;
-		pPriv->contrast = value;
-		OUTREG(MGAREG_BESLUMACTL, ((pPriv->brightness & 0xff) << 16) |
-		       (pPriv->contrast & 0xff));
-	} else 
-#endif
-            if (attribute == xvColorKey) {
-		pPriv->colorKey = value;
-#ifdef JOHN
-		outMGAdac(0x55, (pPriv->colorKey & pScrn->mask.red) >>
-			  pScrn->offset.red);
-		outMGAdac(0x56, (pPriv->colorKey & pScrn->mask.green) >>
-			  pScrn->offset.green);
-		outMGAdac(0x57, (pPriv->colorKey & pScrn->mask.blue) >>
-			  pScrn->offset.blue);
-#endif
-		REGION_EMPTY(pScrn->pScreen, &pPriv->clip);
-	}else if (attribute == xvAutopaintColorKey) {
-		pPriv->autopaintColorKey = value;
-        } else
-        {
-            ErrorF("IvtvSetPortAttributeOverlay bad attribute\n");
-
+	if (attribute == xvColorKey) {
+		devPtr->xv_colorKey = value;
+		REGION_EMPTY(pScrn->pScreen, &devPtr->xv_clip);
+	}
+	else if (attribute == xvAutopaintColorKey) {
+		devPtr->xv_autopaintColorKey = value;
+	}
+	else {
+		ErrorF("IvtvSetPortAttributeOverlay bad attribute\n");
 		return BadMatch;
-        }
-
+	}
 	return Success;
 }
 
@@ -228,25 +192,15 @@
 			    Atom attribute, INT32 * value, pointer data)
 {
 	IVTVDevPtr devPtr = IVTVDEVPTR(pScrn);
-        Ivtv_Xv_PortData *pPriv = (Ivtv_Xv_PortData *)data;
-
-#ifdef JOHN
-	if (attribute == xvBrightness) {
-		*value = pPriv->brightness;
-	} else if (attribute == xvContrast) {
-		*value = pPriv->contrast;
-	} else
-#endif
-            if (attribute == xvColorKey) {
-		*value = pPriv->colorKey;
+	if (attribute == xvColorKey) {
+		*value = devPtr->xv_colorKey;
 	} else if (attribute == xvAutopaintColorKey) {
-		*value = pPriv->autopaintColorKey;
-	} else
-        {
-            ErrorF("IvtvGetPortAttributeOverlay bad attribute\n");
+		*value = devPtr->xv_autopaintColorKey;
+	}
+	else {
+		ErrorF("IvtvGetPortAttributeOverlay bad attribute\n");
 		return BadMatch;
-        }
-
+	}
 	return Success;
 }
 
@@ -281,26 +235,19 @@
 
 	adapt->pPortPrivates = pPriv;
 
-	for (i = 0; i < IVTV_MAX_PORTS; i++)
-        {
-            Ivtv_Xv_PortData *portData =  (Ivtv_Xv_PortData *)xcalloc(1,sizeof(Ivtv_Xv_PortData));
-            portData->colorKey = 101;
-            portData->autopaintColorKey = 0;
+	devPtr->xv_colorKey = 101;
+	devPtr->xv_autopaintColorKey = 0;
+
 #ifdef X_USE_REGION_NULL
-            REGION_NULL(pScreen, &portData->clip);
+	REGION_NULL(pScreen, &devPtr->xv_clip);
 #else
-            REGION_INIT(pScreen, &portData->clip, NullBox, 0); 
+	REGION_INIT(pScreen, &devPtr->xv_clip, NullBox, 0); 
 #endif
-            adapt->pPortPrivates[i].ptr =portData;
-        }
-            
+//FIXME
+	adapt->pPortPrivates[0].ptr = 0;
 
-#if 0
-	xvBrightness = MAKE_ATOM("XV_BRIGHTNESS");
-	xvContrast = MAKE_ATOM("XV_CONTRAST");
-#endif
 	xvColorKey 		= MAKE_ATOM("XV_COLORKEY");
-        xvAutopaintColorKey 	= MAKE_ATOM("XV_AUTOPAINT_COLORKEY");
+	xvAutopaintColorKey 	= MAKE_ATOM("XV_AUTOPAINT_COLORKEY");
 
 	return adapt;
 }
@@ -308,10 +255,10 @@
 static XF86VideoAdaptorPtr IVTVSetupImageVideoOverlay(ScreenPtr pScreen)
 {
 	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-#ifdef JOHN
-	IVTVPtr ps3v = IVTVPTR(pScrn);
-#endif
 	XF86VideoAdaptorPtr adapt;
+	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
+	IVTVDevPtr devPtr = IVTVDEVPTR(pScrn);
+
 	adapt = IVTVAllocAdaptor(pScreen);
 
 	adapt->type = XvWindowMask | XvInputMask | XvImageMask;
@@ -463,19 +410,18 @@
 static void IVTVStopVideo(ScrnInfoPtr pScrn, pointer data, Bool shutdown)
 {
 	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
-        Ivtv_Xv_PortData *pPriv = (Ivtv_Xv_PortData *)data;
+	IVTVDevPtr devPtr = IVTVDEVPTR(pScrn);
 
-	REGION_EMPTY(pScrn->pScreen, &pPriv->clip);
+	REGION_EMPTY(pScrn->pScreen, &devPtr->xv_clip);
 
 	if (shutdown) {
 		if (fPtr->fd_yuv != -1) {
-                        IVTVDevPtr devPtr = IVTVDEVPTR(pScrn);
 			struct ivtvfb_ioctl_state_info state;
 			close(fPtr->fd_yuv);
 			fPtr->fd_yuv = -1;
                         struct ivtvfb_ioctl_colorkey colorKey;
                         colorKey.state = 0;
-                        colorKey.colorKey = pPriv->colorKey;
+                        colorKey.colorKey = devPtr->xv_colorKey;
                         if (ioctl(fPtr->fd,IVTVFB_IOCTL_SET_COLORKEY, &colorKey) < 0) {
                             ErrorF
                                 ("IVTVFB_IOCTL_SET_COLORKEY failed (error: %s)\n",
@@ -495,6 +441,10 @@
 	unsigned int h_size, w_size;
 	unsigned int h_lead, w_lead;
 
+	// No negative coords for conversion
+	if (src_x < 0) src_x = 0;
+	if (src_y < 0) src_y = 0;
+	
 	// Always round the origin, but compensate by increasing the size
 	if (src_x & 15) {
 		w += src_x & 15;
@@ -545,6 +495,10 @@
 	unsigned int h_size, w_size;
 	unsigned int h_lead, w_lead;
 
+	// No negative coords for conversion
+	if (src_x < 0) src_x = 0;
+	if (src_y < 0) src_y = 0;
+
 	// The uv plane is half the size of the y plane, so 'correct' all dimensions.
 	w /= 2;
 	h /= 2;
@@ -644,6 +598,10 @@
 	int xweight, xweight_m, xweight_skip, xskip, xskip_count;
 	int yweight, yweight_m, yweight_skip, yskip, yskip_count;
 
+	// No negative coords for conversion
+	if (src_x < 0) src_x = 0;
+	if (src_y < 0) src_y = 0;
+
 	// Work out the skip. We don't need to be exact as the hardware will scale anyway.
 	// Aliasing is done via 'weight' Calc the weight stepping as well
 	if ( src_w > 720 ) {
@@ -839,9 +797,10 @@
 #endif
 {
 	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
-        Ivtv_Xv_PortData *pPriv = (Ivtv_Xv_PortData *)data;
+	IVTVDevPtr devPtr = IVTVDEVPTR(pScrn);
 
 	struct ivtvyuv_ioctl_dma_host_to_ivtv_args args;
+
 #ifdef JOHN
         ErrorF("src_w %d src_h %d drw_w %d drw_h %d width %d height %d\n",
                src_w, src_h, drw_w, drw_h, width, height);
@@ -849,21 +808,6 @@
                src_x, src_y, drw_x, drw_y, width, height);
 #endif
 
-	// Negative src coords are not yet supported
-	if (src_y < 0) src_y = 0;
-	if (src_x < 0) src_x = 0;
-
-	// FIXME - Is this the correct place for this ?
-
-	// Source coordinates must be even
-	// For origin, round down
-	src_x &= ~1;
-	src_y &= ~1;
-
-	// For size, round up
-	src_w += src_w & 1;
-	src_h += src_h & 1;
-
 #ifdef JOHN
 	INT32 x1, x2, y1, y2;
 	unsigned char *dst_start;
@@ -908,7 +852,7 @@
 		{
 			if ((width > 720) || (height > 576)) {
 				// Source video is too large for the PVR350 so reduce it
-				unsigned long newsize = scale_yv12(buf, outbuf, src_w, src_h, src_x, src_y, height, width);
+				unsigned long newsize = scale_yv12(buf, devPtr->xv_buffer, src_w, src_h, src_x, src_y, height, width);
 				// We only get the portion to be displayed
 				// so set the coords & dimensions to match the new image
 				src_x = 0;
@@ -951,30 +895,32 @@
 				       fPtr->yuvDevName, strerror(errno));
 			return BadAccess;
 		}
-                struct ivtvfb_ioctl_colorkey colorKey;
-                colorKey.state = 1;
-                colorKey.colorKey = pPriv->colorKey;
-                if (ioctl(fPtr->fd,IVTVFB_IOCTL_SET_COLORKEY, &colorKey) < 0) {
-                    ErrorF
-                        ("IVTVFB_IOCTL_SET_COLORKEY failed (error: %s)\n",
-                         strerror(errno));
-                }
+		struct ivtvfb_ioctl_colorkey colorKey;
+		colorKey.state = 1;
+		colorKey.colorKey = devPtr->xv_colorKey;
+		if (ioctl(fPtr->fd,IVTVFB_IOCTL_SET_COLORKEY, &colorKey) < 0) {
+			ErrorF ("IVTVFB_IOCTL_SET_COLORKEY failed (error: %s)\n",
+			strerror(errno));
+		}
 	}
+
 	int ret = ioctl(fPtr->fd_yuv, IVTV_IOC_PREP_FRAME_YUV, &args);
-	if (ret == -1) {
+
+	// Some software aborts playback on error
+	// Ignore EWOULDBLOCK (a dropped frame)
+	if (ret == -1 && errno != EWOULDBLOCK) {
 		ErrorF
 		    ("Ioctl IVTV_IOC_PREP_FRAME_YUV returned failed Error %s\n",
 		     strerror(errno));
 		return BadImplementation;
 	}
-                                                                          
-        if(pPriv->autopaintColorKey && 
-           !RegionsEqual( &pPriv->clip, clipBoxes))
-        {
-            /* we always paint V4L's color key */
-            REGION_COPY(pScrn->pScreen, &pPriv->clip, clipBoxes);
-            xf86XVFillKeyHelper(pScrn->pScreen, pPriv->colorKey, clipBoxes);
-        }
+
+	if(devPtr->xv_autopaintColorKey && !RegionsEqual( &devPtr->xv_clip, clipBoxes)) {
+		/* we always paint V4L's color key */
+		REGION_COPY(pScrn->pScreen, &devPtr->xv_clip, clipBoxes);
+		xf86XVFillKeyHelper(pScrn->pScreen, devPtr->xv_colorKey, clipBoxes);
+	}
+
 	return Success;
 }
 
Index: src/ivtvdev.c
===================================================================
--- src/ivtvdev.c	(revision 3912)
+++ src/ivtvdev.c	(working copy)
@@ -45,7 +45,7 @@
 
 /* This table maps a PCI device ID to a chipset family identifier. */
 static PciChipsets IVTVPciChipsets[] = {
-	{PVR_350, PCI_CHIP_PVR350, RES_SHARED_VGA},
+	{PVR_350, PCI_CHIP_PVR350, RES_UNDEFINED},
 	{-1, -1, RES_UNDEFINED}
 };
 
@@ -176,7 +176,51 @@
 	BoxPtr pbox = REGION_RECTS(damage);
 
 	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-	IVTVDevPtr fPtr = IVTVDEVPTR(pScrn);
+	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
+	IVTVDevPtr iPtr = IVTVDEVPTR(pScrn);
+	
+	int x, y, shadow_offset;
+
+#if X_BYTE_ORDER==X_BIG_ENDIAN
+	switch (pScrn->bitsPerPixel) {
+		case 32: {
+			unsigned long *display;
+			while (nbox --) {
+				for (y = pbox->y1; y < pbox->y2; y++) {
+					shadow_offset = (y * iPtr->shadow_width) + (pbox->x1 * 4);
+					display = fPtr->fbmem + shadow_offset;
+					for (x = 0; x < (pbox->x2 - pbox->x1); x ++) {
+						display[x] = (iPtr->shadowmem[shadow_offset+0]) |
+							     (iPtr->shadowmem[shadow_offset+1] << 8) |
+							     (iPtr->shadowmem[shadow_offset+2] << 16) |
+							     (iPtr->shadowmem[shadow_offset+3] << 24);
+						shadow_offset += 4;
+					}
+				}
+				pbox ++;
+			}
+			return;
+		}
+
+		case 16: {
+			unsigned short *display;
+			while (nbox --) {
+				for (y = pbox->y1; y < pbox->y2; y++) {
+					shadow_offset = (y * iPtr->shadow_width) + (pbox->x1 * 2);
+					display = fPtr->fbmem + shadow_offset;
+					for (x = 0; x < (pbox->x2 - pbox->x1); x ++) {
+						display[x] = (iPtr->shadowmem[shadow_offset+0]) |
+							     (iPtr->shadowmem[shadow_offset+1] << 8);
+						shadow_offset += 2;
+					}
+				}
+				pbox ++;
+			}
+			return;
+		}
+	}
+#endif
+	
 	int x1 = pScrn->virtualX;
 	int x2 = 0;
 	int y1 = pScrn->virtualY;
@@ -195,7 +239,7 @@
 		pbox++;
 	};
 
-	ivtvHWSendDMA(pScrn, fPtr->shadowmem, x1, x2, y1, y2);
+	ivtvHWSendDMA(pScrn, iPtr->shadowmem, x1, x2, y1, y2);
         //ivtvHWSendDMA(pScrn, fPtr->shadowmem, 0, pScrn->virtualX, 0, pScrn->virtualY);
 }
 
@@ -515,6 +559,9 @@
 
 	TRACE_ENTER("IVTVDevScreenInit");
 
+	if (ivtvHWMapVidmem(pScrn) == NULL)
+		return FALSE;
+
 	ErrorF("\tbitsPerPixel=%d, depth=%d, defaultVisual=%s\n"
 	       "\tmask: %x,%x,%x, offset: %d,%d,%d\n",
 	       pScrn->bitsPerPixel,
@@ -640,6 +687,13 @@
 		IvtvInitVideo(pScreen);
 	}
 
+	// Allocate buffer for yuv conversion
+	fPtr->xv_buffer = xalloc (622080);
+	if (!fPtr->xv_buffer) {
+		ErrorF ("Failed to allocate xv conversion buffer\n");
+		return 0;
+	}
+	
 	TRACE_EXIT("IVTVDevScreenInit");
 
 	return TRUE;
@@ -649,11 +703,16 @@
 {
 	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
 	IVTVDevPtr fPtr = IVTVDEVPTR(pScrn);
-
+	ivtvHWUnmapVidmem(pScrn);
 	ivtvHWRestore(pScrn);
 	xfree(fPtr->shadowmem);
 	pScrn->vtSema = FALSE;
 
+	if (fPtr->xv_buffer) {
+		xfree(fPtr->xv_buffer);
+		fPtr->xv_buffer = 0;
+	}
+	
 	pScreen->CloseScreen = fPtr->CloseScreen;
 	return (*pScreen->CloseScreen) (scrnIndex, pScreen);
 }
Index: src/ivtvhw.c
===================================================================
--- src/ivtvhw.c	(revision 3912)
+++ src/ivtvhw.c	(working copy)
@@ -1,6 +1,7 @@
 /* $XFree86: xc/programs/Xserver/hw/xfree86/ivtvhw/ivtvhw.c,v 1.30 2002/11/25 14:05:00 eich Exp $ */
 
 #include "ivtvhw.h"
+#include "ivtvdev.h"
 
 /* all driver need this */
 #include "xf86.h"
@@ -12,9 +13,10 @@
 #include "xf86Pci.h"
 
 #include "xf86cmap.h"
+#define __KERNEL__
+#include <asm/page.h>		/* #define for PAGE_* */
+#undef __KERNEL__
 
-
-#include "asm/page.h"		/* #define for PAGE_* */
 #include "globals.h"
 #define DPMS_SERVER
 #include <X11/extensions/dpms.h>
@@ -133,8 +135,10 @@
 static void
 xfree2ivtv_fblayout(ScrnInfoPtr pScrn, struct fb_var_screeninfo *var)
 {
-	var->xres_virtual = pScrn->virtualX;
-	var->yres_virtual = pScrn->virtualY;
+	IVTVDevPtr iPtr = IVTVDEVPTR(pScrn);
+	
+	var->xres_virtual = iPtr->shadow_width / (pScrn->bitsPerPixel / 8);
+	var->yres_virtual = iPtr->shadow_height;
 	var->bits_per_pixel = pScrn->bitsPerPixel;
 	var->red.length = pScrn->weight.red;
 	var->green.length = pScrn->weight.green;
@@ -435,6 +439,7 @@
 void ivtvHWSetVideoModes(ScrnInfoPtr pScrn)
 {
 	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
+	IVTVDevPtr iPtr = IVTVDEVPTR(pScrn);
 	int virtX = pScrn->display->virtualX;
 	int virtY = pScrn->display->virtualY;
 	struct fb_var_screeninfo var;
@@ -457,6 +462,7 @@
 		}
 		memset(&var, 0, sizeof(var));
 		xfree2ivtv_timing(mode, &var);
+		xfree2ivtv_fblayout(pScrn, &fPtr->var);
 		var.xres_virtual = virtX;
 		var.yres_virtual = virtY;
 		var.bits_per_pixel = pScrn->bitsPerPixel;
@@ -498,6 +504,10 @@
 	}
 	pScrn->virtualX = virtX;
 	pScrn->virtualY = virtY;
+	
+	// The allocated shadow buffer will be this big
+	iPtr->shadow_width = virtX * (pScrn->bitsPerPixel / 8);
+	iPtr->shadow_height = virtY;
 }
 
 DisplayModePtr ivtvHWGetBuildinMode(ScrnInfoPtr pScrn)
@@ -529,6 +539,31 @@
 	    PAGE_MASK;
 }
 
+void* ivtvHWMapVidmem(ScrnInfoPtr pScrn)
+{
+	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
+
+	TRACE_ENTER("MapVidmem");
+	if (NULL == fPtr->fbmem) {
+		ivtvcalculateFbmem_len(fPtr);
+		fPtr->fbmem = mmap(NULL, fPtr->fbmem_len, PROT_READ | PROT_WRITE,
+				   MAP_SHARED, fPtr->fd, 0);
+		if (-1 == (long)fPtr->fbmem) {
+			xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+				   "mmap fbmem: %s\n", strerror(errno));
+			fPtr->fbmem = NULL;
+		} else {
+		    /* Perhaps we'd better add fboff to fbmem and return 0 in
+			fbdevHWLinearOffset()? Of course we then need to mask
+			fPtr->fbmem with PAGE_MASK in fbdevHWUnmapVidmem() as
+			well. [geert] */
+		}
+	}
+	pScrn->memPhysBase = (unsigned long)fPtr->fix.smem_start & (unsigned long)(PAGE_MASK);
+	pScrn->fbOffset = (unsigned long)fPtr->fix.smem_start & (unsigned long)(~PAGE_MASK);
+	return fPtr->fbmem;
+}
+
 int ivtvHWLinearOffset(ScrnInfoPtr pScrn)
 {
 	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
@@ -537,6 +572,20 @@
 	return fPtr->fboff;
 }
 
+Bool ivtvHWUnmapVidmem(ScrnInfoPtr pScrn)
+{
+	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
+
+	TRACE_ENTER("UnmapVidmem");
+	if (NULL != fPtr->fbmem) {
+		if (-1 == munmap(fPtr->fbmem, fPtr->fbmem_len))
+			xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+				   "munmap fbmem: %s\n", strerror(errno));
+		fPtr->fbmem = NULL;
+	}
+	return TRUE;
+}
+
 /* -------------------------------------------------------------------- */
 
 Bool ivtvHWModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
@@ -544,8 +593,8 @@
 	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
 
 	TRACE_ENTER("ModeInit");
+	xfree2ivtv_timing(mode, &fPtr->var);
 	xfree2ivtv_fblayout(pScrn, &fPtr->var);
-	xfree2ivtv_timing(mode, &fPtr->var);
 #if DEBUG
 	print_xfree_mode("init", mode);
 	print_ivtv_mode("init", &fPtr->var);
@@ -610,7 +659,7 @@
 	unsigned short red, green, blue;
 	int i;
 
-	TRACE_ENTER("ModeInit");
+	TRACE_ENTER("Load Palette");
 	cmap.len = 1;
 	cmap.red = &red;
 	cmap.green = &green;
@@ -640,6 +689,7 @@
 	TRACE_ENTER("ValidMode");
 	memcpy(&var, &fPtr->var, sizeof(var));
 	xfree2ivtv_timing(mode, &var);
+	xfree2ivtv_fblayout(pScrn, &fPtr->var);
 	var.activate = FB_ACTIVATE_TEST;
 	if (0 != ioctl(fPtr->fd, FBIOPUT_VSCREENINFO, (void *)(&fPtr->var))) {
 		xf86DrvMsg(scrnIndex, X_ERROR,
@@ -656,6 +706,7 @@
 
 	TRACE_ENTER("SwitchMode");
 	xfree2ivtv_timing(mode, &fPtr->var);
+	xfree2ivtv_fblayout(pScrn, &fPtr->var);
 	if (0 != ioctl(fPtr->fd, FBIOPUT_VSCREENINFO, (void *)(&fPtr->var))) {
 		xf86DrvMsg(scrnIndex, X_ERROR,
 			   "FBIOPUT_VSCREENINFO: %s\n", strerror(errno));
@@ -669,14 +720,16 @@
 	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
 	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
 
-	TRACE_ENTER("AdjustFrame");
-#ifdef JOHN
+//	Floods log...
+//	TRACE_ENTER("AdjustFrame");
 	fPtr->var.xoffset = x;
 	fPtr->var.yoffset = y;
 	if (-1 == ioctl(fPtr->fd, FBIOPAN_DISPLAY, (void *)&fPtr->var))
+	{
 		xf86DrvMsgVerb(scrnIndex, 5, X_WARNING,
 			       "FBIOPAN_DISPLAY: %s\n", strerror(errno));
-#endif
+		ErrorF("FBIOPAN failed: X %d Y %d\n",fPtr->var.xoffset, fPtr->var.yoffset);
+	}
 }
 
 Bool ivtvHWEnterVT(int scrnIndex, int flags)
@@ -756,19 +809,33 @@
 
 Bool ivtvHWSendDMA(ScrnInfoPtr pScrn, void *ptr, int x1, int x2, int y1, int y2)
 {
-	int totalScreenSize =
-	    pScrn->virtualX * pScrn->virtualY * pScrn->bitsPerPixel / 8;
-	int secondOffset = 0;
 
+	int totalScreenSize = 0, secondOffset = 0;
+	
 	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
+	IVTVDevPtr iPtr = IVTVDEVPTR(pScrn);
+
+	totalScreenSize = iPtr->shadow_width * iPtr->shadow_height;
+
 	struct ivtvfb_ioctl_dma_host_to_ivtv_args args;
 	int cpt = MAX_RETRY_DMA;
 
-	int startOffset =
-	    (((y1) * pScrn->virtualX) + x1) * pScrn->bitsPerPixel / 8;
-	int endOffset =
-	    (((y2 - 1) * pScrn->virtualX) + x2) * pScrn->bitsPerPixel / 8;
+	int startOffset = ((y1) * iPtr->shadow_width) + (x1 * pScrn->bitsPerPixel / 8);
+	int endOffset = ((y2 - 1) * iPtr->shadow_width) + (x2 * pScrn->bitsPerPixel / 8);
+	
+	if (pScrn->bitsPerPixel != 32) {
+		// Must align start & end addresses
+		startOffset &= ~3;
 
+		if (endOffset & 3) {
+			endOffset = (endOffset + 4) & ~3;
+		
+			// If end of buffer, alignment not critical
+			if (endOffset > totalScreenSize)
+				endOffset = totalScreenSize;
+		}
+	}
+
 	unsigned long totalData = endOffset - startOffset;
 
 	if (totalData > 64 * 1024 * 4) {
Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(revision 3912)
+++ src/Makefile.am	(working copy)
@@ -24,6 +24,7 @@
 # _ladir passes a dummy rpath to libtool so the thing will actually link
 # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
 AM_CFLAGS = @XORG_CFLAGS@
+AM_CFLAGS += -I/lib/modules/2.6.19-1.2911.fc6/build/include
 ivtvdev_drv_la_LTLIBRARIES = ivtvdev_drv.la
 ivtvdev_drv_la_LDFLAGS = -module -avoid-version
 ivtvdev_drv_ladir = @moduledir@/drivers
Index: src/ivtvdev.h
===================================================================
--- src/ivtvdev.h	(revision 3912)
+++ src/ivtvdev.h	(working copy)
@@ -10,9 +10,18 @@
 	void (*PointerMoved) (int index, int x, int y);
 	EntityInfoPtr pEnt;
 	OptionInfoPtr Options;
+        int shadow_width;
+        int shadow_height;
+       
+        unsigned int xv_colorKey;
+        RegionRec xv_clip;
+        int xv_autopaintColorKey;
+        unsigned char *xv_buffer;
 	CreateScreenResourcesProcPtr	CreateScreenResources;
-} IVTVDevRec, *IVTVDevPtr;
+} IVTVDevRec;
 
+typedef IVTVDevRec *IVTVDevPtr;
+
 #define IVTVDEVPTR(p) ((IVTVDevPtr)((p)->driverPrivate))
 
 Bool IVTVDGAInit(ScreenPtr pScreen);
Index: src/ivtvhw.h
===================================================================
--- src/ivtvhw.h	(revision 3912)
+++ src/ivtvhw.h	(working copy)
@@ -22,6 +22,7 @@
 	int fd;
 	char *yuvDevName;
 	int fd_yuv;
+	void *fbmem;
 	unsigned int fbmem_len;
 	unsigned int fboff;
 	char *mmio;
@@ -59,8 +60,9 @@
 int ivtvHWGetType(ScrnInfoPtr pScrn);
 int ivtvHWGetVidmem(ScrnInfoPtr pScrn);
 
-/*void* ivtvHWMapVidmem(ScrnInfoPtr pScrn);*/
+void* ivtvHWMapVidmem(ScrnInfoPtr pScrn);
 int ivtvHWLinearOffset(ScrnInfoPtr pScrn);
+Bool  ivtvHWUnmapVidmem(ScrnInfoPtr pScrn);
 
 void ivtvHWSetVideoModes(ScrnInfoPtr pScrn);
 DisplayModePtr ivtvHWGetBuildinMode(ScrnInfoPtr pScrn);
_______________________________________________
ivtv-users mailing list
[email protected]
http://ivtvdriver.org/mailman/listinfo/ivtv-users

Reply via email to