Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 26 Aug 2005 21:30:59 GMT
From:      Eric Anholt <anholt@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 82648 for review
Message-ID:  <200508262130.j7QLUxpR087311@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=82648

Change 82648 by anholt@anholt_leguin on 2005/08/26 21:30:43

	MF DRI vendor branch 2005-08-26 (resource allocation fix, 1 compile fix)

Affected files ...

.. //depot/projects/drm-merge/sys/dev/drm/drmP.h#8 integrate
.. //depot/projects/drm-merge/sys/dev/drm/drm_bufs.c#7 integrate
.. //depot/projects/drm-merge/sys/dev/drm/drm_drv.c#6 integrate

Differences ...

==== //depot/projects/drm-merge/sys/dev/drm/drmP.h#8 (text+ko) ====

@@ -687,6 +687,9 @@
 	unsigned use_mtrr :1;
 };
 
+/* Length for the array of resource pointers for drm_get_resource_*. */
+#define DRM_MAX_PCI_RESOURCE	3
+
 /** 
  * DRM device functions structure
  */
@@ -749,6 +752,10 @@
 #endif
 	void		  *irqh;	/* Handle from bus_setup_intr      */
 
+	/* Storage of resource pointers for drm_get_resource_* */
+	struct resource   *pcir[DRM_MAX_PCI_RESOURCE];
+	int		  pcirid[DRM_MAX_PCI_RESOURCE];
+
 	int		  pci_domain;
 	int		  pci_bus;
 	int		  pci_slot;

==== //depot/projects/drm-merge/sys/dev/drm/drm_bufs.c#7 (text+ko) ====

@@ -32,6 +32,8 @@
  * $FreeBSD$
  */
 
+#include "dev/pci/pcireg.h"
+
 #include "dev/drm/drmP.h"
 
 /*
@@ -50,46 +52,45 @@
 	return order;
 }
 
-unsigned long drm_get_resource_start(drm_device_t *dev, unsigned int resource)
+/* Allocation of PCI memory resources (framebuffer, registers, etc.) for
+ * drm_get_resource_*.  Note that they are not RF_ACTIVE, so there's no virtual
+ * address for accessing them.  Cleaned up at lastclose.
+ */
+static int drm_alloc_resource(drm_device_t *dev, int resource)
 {
-	struct resource *bsr;
-	unsigned long offset;
+	if (resource >= DRM_MAX_PCI_RESOURCE) {
+		DRM_ERROR("Resource %d too large\n", resource);
+		return 1;
+	}
+	if (dev->pcir[resource] != NULL)
+		return 0;
 
-	resource = resource * 4 + 0x10;
+	dev->pcirid[resource] = PCIR_BAR(resource);
+	dev->pcir[resource] = bus_alloc_resource_any(dev->device,
+	    SYS_RES_MEMORY, &dev->pcirid[resource], RF_SHAREABLE);
 
-	bsr = bus_alloc_resource_any(dev->device, SYS_RES_MEMORY, &resource,
-	    RF_ACTIVE | RF_SHAREABLE);
-	if (bsr == NULL) {
+	if (dev->pcir[resource] == NULL) {
 		DRM_ERROR("Couldn't find resource 0x%x\n", resource);
-		return 0;
+		return 1;
 	}
 
-	offset = rman_get_start(bsr);
+	return 0;
+}
 
-	bus_release_resource(dev->device, SYS_RES_MEMORY, resource, bsr);
+unsigned long drm_get_resource_start(drm_device_t *dev, unsigned int resource)
+{
+	if (drm_alloc_resource(dev, resource) != 0)
+		return 0;
 
-	return offset;
+	return rman_get_start(dev->pcir[resource]);
 }
 
 unsigned long drm_get_resource_len(drm_device_t *dev, unsigned int resource)
 {
-	struct resource *bsr;
-	unsigned long len;
+	if (drm_alloc_resource(dev, resource) != 0)
+		return 0;
 
-	resource = resource * 4 + 0x10;
-
-	bsr = bus_alloc_resource_any(dev->device, SYS_RES_MEMORY, &resource,
-	    RF_ACTIVE | RF_SHAREABLE);
-	if (bsr == NULL) {
-		DRM_ERROR("Couldn't find resource 0x%x\n", resource);
-		return ENOMEM;
-	}
-
-	len = rman_get_size(bsr);
-
-	bus_release_resource(dev->device, SYS_RES_MEMORY, resource, bsr);
-
-	return len;
+	return rman_get_size(dev->pcir[resource]);
 }
 
 int drm_addmap(drm_device_t * dev, unsigned long offset, unsigned long size,

==== //depot/projects/drm-merge/sys/dev/drm/drm_drv.c#6 (text+ko) ====

@@ -34,7 +34,7 @@
 
 #include "dev/drm/drmP.h"
 #include "dev/drm/drm.h"
-#include "drm_sarea.h"
+#include "dev/drm/drm_sarea.h"
 
 int drm_debug_flag = 0;
 
@@ -475,6 +475,13 @@
 	TAILQ_FOREACH_SAFE(map, &dev->maplist, link, mapsave) {
 		drm_rmmap(dev, map);
 	}
+	for (i = 0; i < DRM_MAX_PCI_RESOURCE; i++) {
+		if (dev->pcir[i] == NULL)
+			continue;
+		bus_release_resource(dev->device, SYS_RES_MEMORY,
+		    dev->pcirid[i], dev->pcir[i]);
+		dev->pcir[i] = NULL;
+	}
 
 	drm_dma_takedown(dev);
 	if ( dev->lock.hw_lock ) {



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