Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 31 May 2010 13:39:29 -0700
From:      Brian Somers <brian@FreeBSD.org>
To:        gljennjohn@googlemail.com
Cc:        x11@FreeBSD.org
Subject:   Re: xf86-video-mga patch
Message-ID:  <20100531133929.0f035c0c@FreeBSD.org>
In-Reply-To: <20100531115939.06d6eea5@ernst.jennejohn.org>
References:  <20100531011111.22064479@dev.lan.Awfulhak.org> <20100531115939.06d6eea5@ernst.jennejohn.org>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
On Mon, 31 May 2010 11:59:39 +0200, Gary Jennejohn <gljennjohn@googlemail.com> wrote:
> On Mon, 31 May 2010 01:11:11 -0700
> Brian Somers <brian@FreeBSD.org> wrote:
> 
> > Hi,
> > 
> > Since upgrading to xorg-7.5 (on -current) my dual-head matrox g450 configuration
> > has broken with the following error:
> > 
> >     "MGA(0): Unable to map BAR 0.  Invalid argument (22)"
> > 
> > This is talked about on various forums and can be fixed with the attached patch.
> > 
> 
> ENPOATCH
> 
> --
> Gary Jennejohn

Oops, what a moron.  I've attached it this time!

-- 
Brian Somers                                       <brian@Awfulhak.org>
Don't _EVER_ lose your sense of humour !            <brian@FreeBSD.org>

[-- Attachment #2 --]
diff -urN old-src/mga_driver.c src/mga_driver.c
--- old-src/mga_driver.c	2008-11-13 15:11:35.000000000 +0000
+++ src/mga_driver.c	2008-11-13 15:17:24.000000000 +0000
@@ -2990,30 +2994,57 @@
 #ifdef XSERVER_LIBPCIACCESS
     struct pci_device *const dev = pMga->PciInfo;
     struct pci_mem_region *region;
-    void **memory[2];
     int i, err;
 #endif
 
 
     if (!pMga->FBDev) {
 #ifdef XSERVER_LIBPCIACCESS
-        memory[pMga->io_bar] = &pMga->IOBase;
-        memory[pMga->framebuffer_bar] = &pMga->FbBase;
 
-        for (i = 0; i < 2; i++) {
-            region = &dev->regions[i];
-            err = pci_device_map_range(dev,
-                                       region->base_addr, region->size,
-                                       PCI_DEV_MAP_FLAG_WRITABLE,
-                                       memory[i]);
+	    pciaddr_t fbaddr = pMga->FbAddress;
+	    pciaddr_t fbsize = pMga->FbMapSize;
+	err = pci_device_map_range(dev,
+				   fbaddr, fbsize,
+				   PCI_DEV_MAP_FLAG_WRITABLE,
+				   (void **)&pMga->FbBase);
 
-            if (err) {
+	if (err) {
                 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-                           "Unable to map BAR %i.  %s (%d)\n",
-                           i, strerror(err), err);
+                           "Unable to map Framebuffer %08llX %llx.  %s (%d)\n", (long long)fbaddr, (long long)fbsize,
+                           strerror(err), err);
                 return FALSE;
-            }
-        }
+	}
+	else
+                xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+                           "MAPPED Framebuffer %08llX %llx to %08llX.\n", (long long)fbaddr, (long long)fbsize, (long long)pMga->FbBase);
+
+	
+	if(pMga->entityPrivate == NULL || pMga->entityPrivate->mappedIOUsage == 0)
+	{
+		region = &dev->regions[pMga->io_bar];
+		err = pci_device_map_range(dev,
+				   region->base_addr, region->size,
+				   PCI_DEV_MAP_FLAG_WRITABLE,
+				   &pMga->IOBase);
+
+		if (err) {
+			xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+				   "Unable to map IO Region %i.  %s (%d)\n",
+				   pMga->io_bar, strerror(err), err);
+			return FALSE;
+		}
+
+		if(pMga->entityPrivate != NULL)
+		{
+			pMga->entityPrivate->mappedIOBase = pMga->IOBase;
+		}
+	}
+	else
+		pMga->IOBase = pMga->entityPrivate->mappedIOBase;
+
+	if(pMga->entityPrivate != NULL)		
+		pMga->entityPrivate->mappedIOUsage ++;
+
 #else
 	/*
 	 * For Alpha, we need to map SPARSE memory, since we need
@@ -3055,16 +3086,28 @@
     if (pMga->iload_bar != -1) {
 #ifdef XSERVER_LIBPCIACCESS
         region = &dev->regions[pMga->iload_bar];
-        err = pci_device_map_range(dev,
+
+	if(pMga->entityPrivate == NULL || pMga->entityPrivate->mappedILOADUsage == 0)
+	{
+		err = pci_device_map_range(dev,
                                    region->base_addr, region->size,
                                    PCI_DEV_MAP_FLAG_WRITABLE,
                                    (void *) &pMga->ILOADBase);
-	if (err) {
-	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-		       "Unable to map BAR 2 (ILOAD region).  %s (%d)\n",
-		       strerror(err), err);
-	    return FALSE;
+		if (err) {
+			xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+				   "Unable to map BAR 2 (ILOAD region).  %s (%d)\n",
+				   strerror(err), err);
+			return FALSE;
+		}
+
+		if(pMga->entityPrivate != NULL)
+			pMga->entityPrivate->mappedILOADBase = pMga->ILOADBase;
 	}
+	else
+		pMga->ILOADBase = pMga->entityPrivate->mappedILOADBase;
+
+	if(pMga->entityPrivate != NULL)
+		pMga->entityPrivate->mappedILOADUsage ++;
 #else
 	pMga->ILOADBase = xf86MapPciMem(pScrn->scrnIndex,
 					VIDMEM_MMIO | VIDMEM_MMIO_32BIT |
@@ -3094,10 +3137,21 @@
     
     if (!pMga->FBDev) {
 #ifdef XSERVER_LIBPCIACCESS
-        pci_device_unmap_range(dev, pMga->IOBase, 
-			       dev->regions[pMga->io_bar].size);
+	    if(pMga->entityPrivate != NULL)
+		    pMga->entityPrivate->mappedIOUsage --;
+
+	    if(pMga->entityPrivate == NULL || pMga->entityPrivate->mappedIOUsage == 0)
+	    {
+		    pci_device_unmap_range(dev, pMga->IOBase, 
+					   dev->regions[pMga->io_bar].size);
+
+		    if(pMga->entityPrivate != NULL)
+			    pMga->entityPrivate->mappedIOBase = NULL;
+	    }
+
+	    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "UNMAPPING framebuffer 0x%08llX, 0x%llX.\n", (long long)pMga->FbBase, (long long)pMga->FbMapSize);
         pci_device_unmap_range(dev, pMga->FbBase, 
-			       dev->regions[pMga->framebuffer_bar].size);
+			       pMga->FbMapSize);
 #else
 	xf86UnMapVidMem(pScrn->scrnIndex, (pointer)pMga->IOBase, 0x4000);
 	xf86UnMapVidMem(pScrn->scrnIndex, (pointer)pMga->FbBase, pMga->FbMapSize);
@@ -3110,8 +3164,18 @@
 
     if ((pMga->iload_bar != -1) && (pMga->ILOADBase != NULL)) {
 #ifdef XSERVER_LIBPCIACCESS
-        pci_device_unmap_range(dev, pMga->ILOADBase,
+	    if(pMga->entityPrivate != NULL)
+		    pMga->entityPrivate->mappedILOADUsage --;
+
+	    if(pMga->entityPrivate == NULL || pMga->entityPrivate->mappedILOADUsage == 0)
+	    {
+		    pci_device_unmap_range(dev, pMga->ILOADBase,
 			       dev->regions[pMga->iload_bar].size);
+
+		    if(pMga->entityPrivate != NULL)
+			    pMga->entityPrivate->mappedILOADBase = NULL;
+	    }
+
 #else
 	xf86UnMapVidMem(pScrn->scrnIndex, (pointer)pMga->ILOADBase, 0x800000);
 #endif
diff -urN old-src/mga.h src/mga.h
--- old-src/mga.h	2008-11-13 15:11:35.000000000 +0000
+++ src/mga.h	2008-11-13 15:17:13.000000000 +0000
@@ -333,6 +333,13 @@
     int			mastervideoRam;
     int			slavevideoRam;
     Bool		directRenderingEnabled;
+
+    void  *		mappedIOBase;
+    int			mappedIOUsage;
+
+    void  *		mappedILOADBase;
+    int			mappedILOADUsage;
+
     ScrnInfoPtr 	pScrn_1;
     ScrnInfoPtr 	pScrn_2;
 } MGAEntRec, *MGAEntPtr;

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100531133929.0f035c0c>